<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
//v1.9 www.exoops.info 2006/05
//v1.8 www.exoops.info 2006/03
// 
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Pascal Le Boustouller
// Author Website : http://www.perso-search.com/e-xoopsien/
// Licence Type   : GPL
// ------------------------------------------------------------------------- //
include("header.php");
include(XOOPS_ROOT_PATH."/modules/MyAnnonces/cache/config.php");
include(XOOPS_ROOT_PATH."/modules/MyAnnonces/include/functions.php");
include_once(XOOPS_ROOT_PATH."/modules/MyAnnonces/class/arbre.php");
$mytree = new XoopsArbre($db->prefix("ann_categories"),"cid","pid");
function headerindex($title) {
global $bcoosConfig,$xoopsOption;
$bcoosConfig['title'] = $title;
if($bcoosConfig['startpage'] == "MyAnnonces"){
	$xoopsOption['show_rblock'] =1;
	include(XOOPS_ROOT_PATH."/header.php");
	make_cblock();
	echo "<br />";
}else{
	$xoopsOption['show_rblock'] =0;
	include(XOOPS_ROOT_PATH."/header.php");
}
echo "<script language=\"javascript\">\nfunction CLA(CLA) { var MainWindow = window.open (CLA, \"_blank\",\"width=500,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no\");}\n</script>";
}
#  function index
#####################################################
function index() {
global $db, $bcoosConfig, $xoopsUser, $moderated, $myts, $mytree, $souscat, $classm, $nbsouscat, $newann, $affichnbann;
    headerindex($bcoosConfig['title']." - "._MI_CLA_NAME);
    OpenTable();
	
echo "<B>"._CLA_ADDFROM." ".$bcoosConfig['title']."</B><P>";
if ($moderated == '1') {
list($propo) = $db->fetchRow($db->query("SELECT  COUNT(*)  FROM ".$db->prefix("ann_annonces")." WHERE valid='No'"));
    if ( $xoopsUser ) {
	if ( $xoopsUser->isAdmin() ) {
echo "<P>";
OpenTable();
echo "<B>"._CLA_ADMINCADRE."</B><BR>\n";
if($propo == 0)
{
  echo "<P><CENTER>"._CLA_NO_CLA."</FONT><BR><A HREF=\"admin/index.php\">"._CLA_ACCESADMIN."</A></CENTER>";
} else {
  echo "<P><CENTER><FONT COLOR=\"#FF0000\">"._CLA_THEREIS." $propo  "._CLA_WAIT."</FONT><BR><A HREF=\"admin/index.php\">"._CLA_SEEIT."</A></CENTER>";
}
CloseTable();
echo "<P>";
}
}
}
$result=$db->query("SELECT cid, title, img FROM ".$db->prefix("ann_categories")." WHERE pid = 0 ORDER BY $classm") or die("Error");
list($ncatp) = $db->fetchRow($db->query("SELECT  COUNT(*)  FROM ".$db->prefix("ann_categories")." WHERE pid=0"));
echo "<center><A HREF=\"recherche.php\">"._CLA_SEARCHANN."</A><BR /><BR />\n";
echo "<TABLE BORDER=0>
    <TR>
      <TD valign=\"top\">";
echo "<table border=0 cellspacing=10 cellpadding=0>\n";
$count = 1;
while($myrow = $db->fetchArray($result)) {
$cid = $myrow['cid'];
	$title = $myts->makeTboxData4Show($myrow['title']);
    	echo "<tr><td valign=\"top\">&nbsp;</td><td valign=\"top\"><IMG SRC=\"".XOOPS_URL."/modules/MyAnnonces/images/cat/".$myrow['img']."\" BORDER=0 ALIGN=\"absmiddle\"> <a href=\"index.php?pa=view&cid=".$myrow['cid']."\"><b>$title</b></a>";
if ($affichnbann == "1") {
	$totallink = getTotalItems($myrow['cid'], Yes);
echo "&nbsp;($totallink)";
}
		 echo "<br>";
	 
	 
if ($souscat == 1) {
	// get child category objects
	$arr=array();
	$arr=$mytree->getFirstChild($myrow['cid'], "$classm");
	$space = 0;
	$chcount = 1;
	foreach($arr as $ele){
		$chtitle=$myts->makeTboxData4Show($ele['title']);
		if ($chcount>$nbsouscat){
			echo ",&nbsp;...";
			break;
		}
		if ($space>0) {
        		echo ",&nbsp;";
        	}
        	echo "<a href=\"index.php?pa=view&cid=".$ele['cid']."\">".$chtitle."</a>";
        	$space++;
		$chcount++;
	}
	}
	
	$bis = ($ncatp+1)/2;
	$bis = (int)$bis;
	
    	if ($count==$bis) {
        	echo "</td></tr></table></TD><TD valign=\"top\"><table border=0 cellspacing=10 cellpadding=0>";
    	}
		$count++;
}
echo "</table>";
echo "</TD>
    </TR>
</TABLE>";
	list($ann) = $db->fetchRow($db->query("SELECT  COUNT(*)  FROM ".$db->prefix("ann_annonces")." WHERE valid='Yes'"));
	list($catt) = $db->fetchRow($db->query("SELECT  COUNT(*)  FROM ".$db->prefix("ann_categories").""));
		echo "<BR /><CENTER>"._CLA_ACTUALY." $ann "._CLA_ANNONCES." "._CLA_INCAT." $catt "._CLA_CAT3."";
		if ($moderated == '1') {
		echo "<BR>"._CLA_AND." $propo "._CLA_WAIT3."";
		}
		echo ".</CENTER>";
	echo "<BR>";
    CloseTable();
	
	if ($newann == 1) {
	echo "<P>";
	OpenTable();
showNew();
    CloseTable();
	}
	
copyright();
SupprClaDay();
	}
	
	
#  function view (categories)
#####################################################
function view($cid, $debut, $ord, $class) {
    global $db, $bcoosConfig, $nb_affichage, $myts, $mytree, $imagecat, $classm;
headerindex($bcoosConfig['title']." - "._MI_CLA_NAME);
include_once(XOOPS_ROOT_PATH.'/class/xoopspagenav.php');
    OpenTable();
	
$pathstring  = "<B><A HREF=\"index.php\">"._CLA_MAIN."</A> ";
$nicepath    = $mytree->getNicePathFromId($cid, "title", "index.php?pa=view");
$pathstring .= $nicepath;
list($nbe) = $db->fetchRow($db->query("SELECT COUNT(*) FROM ".$db->prefix("ann_annonces")." where valid='Yes' AND cid='$cid'"));
echo $pathstring."</B> ($nbe)<BR /><BR />";
	
	
	
	echo "<CENTER>[ <A HREF=\"addannonces.php?cid=$cid\">"._CLA_ADDANNONCE2."</A> | <A HREF=\"recherche.php\">"._CLA_SEARCHANN."</A> ]</CENTER><P>";
	
	$count = 0;
if ($debut=="") { $debut=0; }
$pagenav = new XoopsPageNav($nbe, $nb_affichage, $debut, "pa=view&cid=$cid&class=$class&ord=$ord&debut", "");
    $subresult=$db->query("select cid, title, img from ".$db->prefix("ann_categories")." where pid=$cid ORDER BY $classm");
    $numrows = $db->getRowsNum($subresult);
    if ($numrows != 0) {
	$scount = 0;
	echo "<P><center>"._CLA_AVAILAB."</center><br>"
    	    ."<table align=\"center\" border=\"0\"><tr>";
    	while(list($ccid, $title, $img) = $db->fetchRow($subresult)) {
		
$title = $myts->makeTboxData4Show($title);
		
	    $numrows = getTotalItems($ccid, Yes);
    	    echo "<td>&nbsp;<IMG SRC=\"".XOOPS_URL."/modules/MyAnnonces/images/cat/$img\" BORDER=0 ALIGN=\"absmiddle\"> <a href=\"index.php?pa=view&cid=$ccid\">$title</a> ($numrows)";
 	categorynewgraphic($ccid);
	echo "&nbsp;&nbsp;</td>";
    	    $scount++;
    	    if ($scount==4) { 
    	    	echo "</tr><tr>";
    	    	$scount = 0;
    	    }
    	}
    	if ($count != 0) {
	    echo "</tr></table>";
	} else {
	$cols = 4-$scount;
	    echo "<td colspan=$cols>&nbsp;</td></tr></table>";
	}
    }
	
	showViewAnnonces($debut, $cid, $nb_affichage, $nbe, $ord, $class);
	
	echo "<BR />";
	
if(!isset($debut)) $debut=0;
// Show navigation bar
echo "<div align=\"center\">".$pagenav->renderNav(3, 3)."</div>";
	
    CloseTable();
copyright();
}
	
	
#  function viewannonces
#####################################################
function viewannonces($lid) {
    global $db, $bcoosConfig, $xoopsUser, $monnaie, $claday, $ynprice, $myts;
   
    $result=$db->query("SELECT lid, cid, title, type, description, tel, price, typeprix, date, email, submitter, usid, town, country, valid, photo, view FROM ".$db->prefix("ann_annonces")." WHERE lid = '$lid'");
    $recordexist = $db->getRowsNum($result);
    list($lid, $cid, $title, $type, $description, $tel, $price, $typeprix, $date, $email, $submitter, $usid, $town, $country, $valid, $photo, $view)= $db->fetchRow($result);
 headerindex($title);
    OpenTable();
	echo "<B><A HREF=\"index.php\">"._CLA_MAIN."</A> &raquo; "._CLA_DETAIL."</B><BR /><BR />";
    if ($recordexist) {     
	$db->query("UPDATE ".$db->prefix("ann_annonces")." SET view=view+1 WHERE lid = '$lid'");
	
	$date2 = $date + ($claday*86400);
	$date = formatTimestamp($date,"s");
	$date2 = formatTimestamp($date2,"s");
	
	$title = $myts->makeTboxData4Show($title);
	$type = $myts->makeTboxData4Show($type);
	$description = $myts->makeTboxData4Show($description);
	$tel = $myts->makeTboxData4Show($tel);
	$price = $myts->makeTboxData4Show($price);
	$typeprix = $myts->makeTboxData4Show($typeprix);
	$submitter = $myts->makeTboxData4Show($submitter);	
	$town = $myts->makeTboxData4Show($town);
	$country = $myts->makeTboxData4Show($country);
	
$imprD = "<a href=\"annonces-p-f.php?op=ImprAnn&lid=$lid\><img src=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."print.gif\" border=0 Alt=\""._CLA_PRINT."\" width=15 height=11></a>&nbsp;";
$envD = "<a href=\"annonces-p-f.php?op=EnvAnn&lid=$lid\"><img src=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."email.gif\" border=0 Alt=\""._CLA_FRIENDSEND."\" width=15 height=11></a>";
	
	echo "<TABLE WIDTH=100% BORDER=0>
	    <TR>
      <TD>"._CLA_ANNFROM." ";
		if ($usid > 0) {
		echo "<A HREF=\"".XOOPS_URL."/userinfo.php?uid=$usid\"><B>$submitter</B></A>";
		} else {
		echo "<B>$submitter</B>";
		}	  
	  echo " nº $lid ("._READS." $view)";
	  
	  if ($xoopsUser) {
		 $calusern = $xoopsUser->getVar("uid", "E");
		if ($usid == $calusern) {
		echo " &nbsp;&nbsp; <A HREF=\"supprann.php?op=ModAnnonce&lid=$lid\"><IMG SRC=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."edit.gif\" BORDER=0 ALT=\""._CLA_MODIFANN."\"></A>&nbsp;<A HREF=\"supprann.php?op=AnnoncesDel&lid=$lid\"><IMG SRC=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."delete.gif\" BORDER=0 ALT=\""._CAL_SUPPRANN."\"></A>";
} 
}
	  
	 echo"<BR><BR>";	  	 
	 
	 			if ( $xoopsUser ) {
			if ( $xoopsUser->isAdmin() ) {
			echo "<A HREF=\"admin/index.php?op=AnnoncesModAnnonce&lid=$lid\"><IMG SRC=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."edit.gif\" BORDER=0 ALT=\""._CLA_MODADMIN."\"></A>";
			}
			}
	  
	  echo " <b>$type :</b> <I>$title</I></TD>
	      </TR>
    <TR>
      <TD>$description<P>";
	  if ($ynprice == 1) {
	if ($price > 0) { echo"<B>"._CLA_PRICE2."</B> $price $monnaie - $typeprix<BR>";  }
	}
    echo ""._CLA_CONTACT." <A HREF=\"contact.php?lid=$lid\">"._CLA_BYMAIL2."</A>";
	  if ($tel) {  echo "<BR>"._CLA_TEL." $tel";   }
	  if ($town) {  echo "<BR>"._CLA_TOWN." $town";   }
	  if ($country) {  echo "<BR>"._CLA_COUNTRY." $country";   }
	  if ($photo) {     
echo "<P><CENTER><IMG SRC=\"images_ann/$photo\" BORDER=0></CENTER><P>";
	} else {
echo "<BR /><BR />";
	}
    
	
	$result8 = $db->query("select title from ".$db->prefix("ann_categories")." where cid='$cid'");
    list($ctitle) = $db->fetchRow($result8);
		echo ""._CLA_CAT2." <A HREF=\"index.php?pa=view&cid=$cid\">$ctitle</A>";
		echo "<BR />"._CLA_DATE2." $date "._CLA_DISPO." $date2 &nbsp;&nbsp; $imprD $envD";
	  
	  echo "</TD>
    </TR>
</TABLE>";
    } else {
    	echo "<br><br><center><font class=\"option\"><b>"._CLA_NOCLAS."</b></font></center>";
    }
	
    CloseTable();
copyright();
}
#  function categorynewgraphic
#####################################################
function categorynewgraphic($cat) {
    global $db,$bcoosConfig;
	
    $newresult = $db->query("select date from ".$db->prefix("ann_annonces")." where cid=$cat and valid = 'Yes' order by date desc limit 1");
    list($timeann)= $db->fetchRow($newresult);
    echo "&nbsp;";
	
    	$count = 1;
	$startdate = (time()-(86400 * $count));
    	if ($startdate < $timeann) {
			echo "<img src=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."newred.gif\" />";
		}
}
switch($pa) {
    case "viewannonces":
     viewannonces($lid);
    break;
    case "view":
    view($cid, $debut, $ord, $class);
    break;
    case "views":
    views($sid, $debut);
    break;
	
    default:
     index();
    break;
}
include(XOOPS_ROOT_PATH."/footer.php");
?>
