<?
//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
// ------------------------------------------------------------------------- //
function showNew(){
	global $myts, $db, $mf, $xoopsUser, $newclassifieds, $monnaie, $ynprice,$bcoosConfig;
	
include_once(XOOPS_ROOT_PATH."/modules/MyAnnonces/class/arbre.php");
$mytree = new XoopsArbre($db->prefix("ann_categories"),"cid","pid");
	
	 $result=$db->query("SELECT lid, title, type, price, date, town, country, valid, photo, view FROM ".$db->prefix("ann_annonces")." WHERE valid='Yes' ORDER BY date DESC LIMIT $newclassifieds");
if ($result =="") {
echo "";
} else {
	echo "<B>"._CLA_THE." $newclassifieds "._CLA_LASTADD."</B><BR><BR>";
	echo "<TABLE WIDTH=100% BORDER=0 class='bg2' CELLPADDING=2 CELLSPACING=1>
    <TR class='bg2'>";
	if ( $xoopsUser ) {
	if ( $xoopsUser->isAdmin() ) {
	  echo "<TD WIDTH=15>&nbsp;</TD>";
	  }
	  }
      echo "<TD>"._CLA_TYP."</TD>
	  <TD>"._TITLE."</TD>";
	  
	  if ($ynprice == 1) {
      echo "<TD align=right>"._CLA_PRICE."</TD>";
	  }
	  
      echo "<TD align=center>"._DATE."</TD>
	  <TD>"._LOCATION."</TD>
	  <TD align=center>"._CLA_PHOTO."</TD>
	  <TD align=center>"._CLA_VIEW."</TD>
    </TR>";
		$rank = 1;
	while(list($lid, $title, $type, $price, $date, $town, $country, $valid, $photo, $vu)=$db->fetchRow($result)){
	$title = $myts->makeTboxData4Show($title);
	$type = $myts->makeTboxData4Show($type);
	$price = $myts->makeTboxData4Show($price);
	$town = $myts->makeTboxData4Show($town);
	$country = $myts->makeTboxData4Show($country);
	$date = formatTimestamp($date,"s");
	if(is_integer($rank/2)) $color="bg1";
	else $color="bg3";
		echo "<TR class='$color'>";
			if ( $xoopsUser ) {
			if ( $xoopsUser->isAdmin() ) {
			echo "<TD align=center><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></TD>";
			}
			}
		echo "<TD><B>$type</B></TD><TD><a href=index.php?pa=viewannonces&lid=$lid>$title</a></TD>";
		
		if ($ynprice == 1) {
		echo "<TD align=right>";
		if ($price > 0) { echo "$price $monnaie"; }
		echo "</TD>";
		}
		
		echo "<TD align=center>$date</TD><TD>";
		if ($town) {  echo "$town";   }
		if ($country) {  echo " $country";   }
		echo "</TD>";
		echo "<TD align=center>";
		if ($photo) { echo "<A href=\"javascript:CLA('display-image.php?lid=$lid')\"><IMG SRC=\"images/photo.gif\" BORDER=0 WIDTH=15 HEIGHT=11 ALT=\""._CLA_IMGPISP."\"></A>"; } else { echo "&nbsp;"; }
		echo "</TD><TD align=center>$vu</TD>";
		
			$rank++;
	}	 
   echo "</TR></TABLE>";
}
}
function showViewAnnonces($debut, $cid, $nb_affichage, $nbe, $ord, $class){
    global $db, $bcoosConfig, $monnaie, $xoopsUser, $ynprice, $myts;
	
if (!$class) { $class='date'; }
if (!$ord) { $ord='DESC'; }
if (!$class || $class == 'date' && $ord == 'ASC') $texte = ""._DATE." "._CLA_ORDON1."";
if (!$class || $class == 'date' && $ord == 'DESC') $texte = ""._DATE." "._CLA_ORDON2."";
if ($class == 'title' && $ord == 'DESC') $texte = ""._TITLE." "._CLA_ORDON3."";
if ($class == 'title' && $ord == 'ASC') $texte = ""._TITLE." "._CLA_ORDON4."";
if ($class == 'view' && $ord == 'DESC') $texte = ""._CLA_VIEW." "._CLA_ORDON5."";
if ($class == 'view' && $ord == 'ASC') $texte = ""._CLA_VIEW." "._CLA_ORDON6."";
if ($class == 'price' && $ord == 'DESC') $texte = ""._CLA_PRICE." "._CLA_ORDON7."";
if ($class == 'price' && $ord == 'ASC') $texte = ""._CLA_PRICE." "._CLA_ORDON8."";
if ($class == 'type' && $ord == 'DESC') $texte = ""._CLA_TYP." "._CLA_ORDON3."";
if ($class == 'type' && $ord == 'ASC') $texte = ""._CLA_TYP." "._CLA_ORDON4."";
	
    $result3=$db->query("select lid, cid, title, type, price, date, town, country, valid, photo, view from ".$db->prefix("ann_annonces")." where valid='Yes' AND cid=$cid order by $class $ord LIMIT $debut,$nb_affichage");
if ($nbe =="0") {
echo "<P><CENTER>"._CLA_NOANNINCAT."</CENTER><P><BR>";
} else {
	echo "<P><CENTER>"._CLA_ANNCLASSBY." <B>$texte</B></CENTER>
	<TABLE WIDTH=100% BORDER=0 class='bg2' CELLPADDING=2 CELLSPACING=1>
    <TR class='bg2'>";
			if ( $xoopsUser ) {
			if ( $xoopsUser->isAdmin() ) {
			echo "<TD WIDTH=5%>&nbsp;</TD>";
			}
			}
      echo "<TD WIDTH=15%>
	  <A HREF=\"index.php?pa=view&cid=$cid&class=type&debut=$debut&ord=ASC\"><IMG SRC=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."down.gif\" BORDER=0 WIDTH=9 HEIGHT=7 ALT=\""._CLA_ORDON4."\"></A> "._CLA_TYP." 
<A HREF=\"index.php?pa=view&cid=$cid&class=type&debut=$debut&ord=DESC\"><IMG SRC=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."up.gif\" BORDER=0 WIDTH=9 HEIGHT=7 ALT=\""._CLA_ORDON3."\"></A></TD>
<TD WIDTH=40%>
<A HREF=\"index.php?pa=view&cid=$cid&class=title&debut=$debut&ord=ASC\"><IMG SRC=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."down.gif\" BORDER=0 WIDTH=9 HEIGHT=7 ALT=\""._CLA_ORDON4."\"></A> "._TITLE." 
<A HREF=\"index.php?pa=view&cid=$cid&class=title&debut=$debut&ord=DESC\"><IMG SRC=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."up.gif\" BORDER=0 WIDTH=9 HEIGHT=7 ALT=\""._CLA_ORDON3."\"></A></TD>";
	  
	  if ($ynprice == 1) {
      echo "<TD align=center WIDTH=10%><A HREF=\"index.php?pa=view&cid=$cid&class=price&debut=$debut&ord=DESC\"><IMG SRC=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."down.gif\" BORDER=0 WIDTH=9 HEIGHT=7 ALT=\""._CLA_ORDON7."\" ALIGN=\"absmiddle\"></A> "._CLA_PRICE." <A HREF=\"index.php?pa=view&cid=$cid&class=price&debut=$debut&ord=ASC\"><IMG SRC=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."up.gif\" BORDER=0 WIDTH=9 HEIGHT=7 ALT=\""._CLA_ORDON8."\" ALIGN=\"absmiddle\"></A></TD>";
	  }
	  
      echo "<TD align=center WIDTH=10%><A HREF=\"index.php?pa=view&cid=$cid&debut=$debut&ord=DESC\"><IMG SRC=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."down.gif\" BORDER=0 WIDTH=9 HEIGHT=7 ALT=\""._CLA_ORDON2."\" ALIGN=\"absmiddle\"></A> "._DATE." <A HREF=\"index.php?pa=view&cid=$cid&debut=$debut&ord=ASC\"><IMG SRC=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."up.gif\" BORDER=0 WIDTH=9 HEIGHT=7 ALT=\""._CLA_ORDON1."\" ALIGN=\"absmiddle\"></A></TD>
      <TD WIDTH=15%>"._LOCATION."</TD>
	  <TD align=center WIDTH=5%>"._CLA_PHOTO."</TD>
	  <TD align=center WIDTH=5% nowrap><A HREF=\"index.php?pa=view&cid=$cid&class=view&debut=$debut&ord=DESC\"><IMG SRC=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."down.gif\" BORDER=0 WIDTH=9 HEIGHT=7 ALT=\""._CLA_ORDON5."\" ALIGN=\"absmiddle\"></A> "._CLA_VIEW." <A HREF=\"index.php?pa=view&cid=$cid&class=view&debut=$debut&ord=ASC\"><IMG SRC=\"".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."up.gif\" BORDER=0 WIDTH=9 HEIGHT=7 ALT=\""._CLA_ORDON6."\" ALIGN=\"absmiddle\"></A></TD>
    </TR>";
	
			$rank = 1;
	while(list($lid, $cid, $title, $type, $price, $date, $town, $country, $valid, $photo, $vu)=$db->fetchRow($result3)){
	$title = $myts->makeTboxData4Show($title);
	$type = $myts->makeTboxData4Show($type);
	$price = $myts->makeTboxData4Show($price);
	$town = $myts->makeTboxData4Show($town);
	$country = $myts->makeTboxData4Show($country);
	$date = formatTimestamp($date,"s");
		
	if(is_integer($rank/2)) $color="bg1";
	else $color="bg3";
	
	
		echo "<TR class='$color'>";
		if ( $xoopsUser ) {
		if ( $xoopsUser->isAdmin() ) {
			echo "<TD align=center><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></TD>";
			}
			}
		echo "<TD><B>$type</B></TD><TD><a href=index.php?pa=viewannonces&lid=$lid>$title</a></TD><TD align=right>";
		
		if ($ynprice == 1) {
		if ($price > 0) { echo "$price $monnaie"; }
		}
		
		echo "</TD><TD align=center>$date</TD><TD>";
		if ($town) {  echo "$town";   }
		if ($country) {  echo " $country";   }
		echo "</TD>";
		echo "<TD align=center>";
		if ($photo) { echo "<A href=\"javascript:CLA('display-image.php?lid=$lid')\"><IMG SRC=\"images/photo.gif\" BORDER=0 WIDTH=15 HEIGHT=11 ALT=\""._CLA_IMGPISP."\"></A>"; } else { echo "&nbsp;"; }
		echo "</TD><TD align=center>$vu</TD>";
$rank++;
}	 
			
   echo "</TR></TABLE>";
}
}
function SupprClaDay() {
include("cache/config.php");
global $db, $claday, $bcoosConfig, $myts;
$datenow = time();
$result5 = $db->query("SELECT lid, title, type, description, date, email, submitter, photo, view FROM ".$db->prefix("ann_annonces")." WHERE valid='Yes'");
while(list($lids, $titre, $type, $description, $dateann, $email, $submitter, $photo, $lu) = $db->fetchRow($result5)) {
	$title = $myts->makeTboxData4Show($title);
	$type = $myts->makeTboxData4Show($type);
	$description = $myts->makeTboxData4Show($description);
	$submitter = $myts->makeTboxData4Show($submitter);	
$supprdate = $dateann + ($claday*86400);
if ($supprdate < $datenow) {
$db->query("delete from ".$db->prefix("ann_annonces")." where lid='$lids'");
$destination = XOOPS_ROOT_PATH."/modules/MyAnnonces/images_ann";
	
	if($photo){
	if (file_exists("$destination/$photo")) {
			 	 unlink("$destination/$photo");
				}
	}
if ($email) {
$message = ""._CLA_HELLO." $submitter,\n\n"._CLA_STOP2."\n $type : $titre\n $description\n"._CLA_STOP3."\n\n"._CLA_VU." $lu "._CLA_VU2."\n\n"._CLA_OTHER." ".XOOPS_URL."/modules/MyAnnonces\n\n"._CLA_THANK."\n\n"._CLA_TEAM." ".$bcoosConfig['title']."\n".XOOPS_URL."";
	$subject = ""._CLA_STOP."";
	$mail =& getMailer();
	$mail->useMail();
	$mail->setFromName($bcoosConfig['title']);
	$mail->setFromEmail($bcoosConfig['adminmail']);
	$mail->setToEmails($email);
	$mail->setSubject($subject);
	$mail->setBody($message);
	$mail->send();
	echo $mail->getErrors();
			}
}
}
}
function copyright() {
}
function getTotalItems($sel_id, $status=""){
	global $db, $mytree;
	
	include_once(XOOPS_ROOT_PATH."/modules/MyAnnonces/class/arbre.php");
$mytree = new XoopsArbre($db->prefix("ann_categories"),"cid","pid");
	
	$count = 0;
	$arr = array();
	$query = "select count(*) from ".$db->prefix("ann_annonces")." where cid=".$sel_id."";
	if($status!=""){
		$query .= " and valid='$status'";
	}
	$result = $db->query($query);
	list($thing) = $db->fetchRow($result);
	$count = $thing;
	$arr = $mytree->getAllChildId($sel_id);
	$size = sizeof($arr);
	for($i=0;$i<$size;$i++){
		$query2 = "select count(*) from ".$db->prefix("ann_annonces")." where cid=".$arr[$i]."";
		if($status!=""){
			$query2 .= " and valid='$status'";
		}
		$result2 = $db->query($query2);
		list($thing) = $db->fetchRow($result2);
		$count += $thing;
	}
	return $count;
}
function ShowImg() {
	echo "<SCRIPT type=\"text/javascript\">\n";
	echo "<!--\n\n";
	echo "function showimage() {\n";
	echo "if (!document.images)\n";
	echo "return\n";
	echo "document.images.avatar.src=\n";
	echo "'".XOOPS_URL."/modules/MyAnnonces/images/cat/' + document.imcat.img.options[document.imcat.img.selectedIndex].value\n";
	echo "}\n\n";
	echo "//-->\n";
	echo "</SCRIPT>\n";
}
?>
