<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
//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");
function EnvAnn($lid) {
    global $bcoosConfig, $db, $xoopsUser, $myts, $xoopsModule;
	
include(XOOPS_ROOT_PATH."/header.php");
    OpenTable();
	
	$result = $db->query("SELECT lid, title, type FROM ".$db->prefix("ann_annonces")." where lid='$lid'");
    list($lid, $title, $type) = $db->fetchRow($result);
	
    echo "<B><A HREF=\"index.php\">"._CLA_MAIN."</A> &raquo; "._CLA_SENDTO." $lid \"<B>$type : $title</B>\" "._CLA_FRIEND."<br /><br />
    <form action=\"annonces-p-f.php\" method=post>
    <input type=hidden name=lid value=$lid>";
	
    if($xoopsUser) {
	$idd =$iddds =$xoopsUser->getVar("name", "E");
	$idde =$iddds =$xoopsUser->getVar("email", "E");
	}
	
    echo "
	<TABLE BORDER=0>
    <TR>
      <TD>"._CLA_NAME." </TD>
      <TD><input class=\"text\" type=text name=\"yname\" value=\"$idd\"></TD>
    </TR>
    <TR>
      <TD>"._CLA_MAIL." </TD>
      <TD><input class=\"text\" type=text name=\"ymail\" value=\"$idde\"></TD>
    </TR>
    <TR>
      <TD COLSPAN=2>&nbsp;</TD>
    </TR>
    <TR>
      <TD>"._CLA_NAMEFR." </TD>
      <TD><input class=\"text\" type=text name=\"fname\"></TD>
    </TR>
    <TR>
      <TD>"._CLA_MAILFR." </TD>
      <TD><input class=\"text\" type=text name=\"fmail\"></TD>
    </TR>
</TABLE>
    <input type=hidden name=op value=MailAnn>
    <input class=\"button\" type=submit value="._CLA_SENDFR.">
    </form>     ";
    CloseTable();
Copyright();
include(XOOPS_ROOT_PATH."/footer.php");
}
function MailAnn($lid, $yname, $ymail, $fname, $fmail) {
    global $bcoosConfig, $xoopsUser, $db, $monnaie, $ynprice, $myts;
	
$result = $db->query("SELECT lid, title, type, description, tel, price, typeprix, date, email, submitter, town, country, photo FROM ".$db->prefix("ann_annonces")." where lid=$lid");
    list($lid, $title, $type, $description, $tel, $price, $typeprix, $date, $email, $submitter, $town, $country, $photo) = $db->fetchRow($result);
	
	$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);
	
	
	$message = ""._CLA_HELLO." $fname,\n\n$yname "._CLA_MESSAGE."\n\n";
	$message .= "$type :  $title\n$description\n\n";
	if ($price && $ynprice == 1) { $message .= ""._CLA_PRICE2." $price $monnaie $typeprix\n";  }
	$message .= ""._CLA_BYMAIL." ".XOOPS_URL."/modules/MyAnnonces/contact.php?lid=$lid\n";
		if ($tel) {  $message .= ""._CLA_TEL2." $tel\n";  }
		if ($town) {  $message .= ""._CLA_TOWN." $town\n";   }
		if ($country) {  $message .= ""._CLA_COUNTRY." $country\n";  }
	$message .= "\n"._CLA_INTERESS." ".$bcoosConfig['title']."\n".XOOPS_URL."/modules/MyAnnonces/"; 
	
	$subject = ""._CLA_SUBJET." ".$bcoosConfig['title']."";
	$mail =& getMailer();
	$mail->useMail();
	$mail->setFromName($yname);
	$mail->setFromEmail($ymail);
	$mail->setToEmails($fmail);
	$mail->setSubject($subject);
	$mail->setBody($message);
	$mail->send();
	echo $mail->getErrors();
    
redirect_header("index.php",1,_CLA_ANNSEND);
exit();
}
function ImprAnn($lid) {
    global $bcoosConfig, $db, $monnaie, $useroffset, $claday, $ynprice, $myts;
	
	$currenttheme = getTheme();
	
$result = $db->query("SELECT lid, title, type, description, tel, price, typeprix, date, email, submitter, town, country, photo FROM ".$db->prefix("ann_annonces")." where lid=$lid");
    list($lid, $title, $type, $description, $tel, $price, $typeprix, $date, $email, $submitter, $town, $country, $photo) = $db->fetchRow($result);
	
	$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);
	
    echo "
    <html>
    <head><title>".$bcoosConfig['title']."</title>
	<LINK REL=\"StyleSheet\" HREF=\"../../themes/".$currenttheme."/style/style.css\" TYPE=\"text/css\">
	</head>
    <body bgcolor=\"#FFFFFF\" text=\"#000000\">
    <table border=0><tr><td>
    
    <table border=0 width=640 cellpadding=0 cellspacing=1 bgcolor=\"#000000\"><tr><td>
    <table border=0 width=100% cellpadding=15 cellspacing=1 bgcolor=\"#FFFFFF\"><tr><td>";
	$date2 = $date + ($claday*86400);
	$date = formatTimestamp($date,"s");
	$date2 = formatTimestamp($date2,"s");
	
	echo "<br><br><TABLE WIDTH=100% BORDER=0>
	    <TR>
      <TD>"._CLA_ANNFROM." $submitter nº $lid<BR><BR>";
	  	  
	  echo " <b>$type :</b> <I>$title</I> ";
	  echo "</TD>
	      </TR>
    <TR>
      <TD><DIV STYLE=\"text-align:justify;\">$description</DIV><P>";
	  
	if ($price && $ynprice == 1) { echo"<B>"._CLA_PRICE2."</B> $price $monnaie - $typeprix<BR>";  }
	
    echo ""._CLA_BYMAIL." <A HREF=\"".XOOPS_URL."/modules/MyAnnonces/contact.php?lid=$lid\">".XOOPS_URL."/modules/MyAnnonces/contact.php?lid=$lid</A>";
	  if ($tel) {  echo "<BR>"._CLA_TEL." $tel";   }
	  if ($town) {  echo "<BR>"._CLA_TOWN." $town";   }
	  if ($country) {  echo "<BR>"._CLA_COUNTRY." $country";   }
    
	  echo "<BR><BR>"._CLA_DATE2." $date "._CLA_DISPO." $date2<BR><BR>";
	  
    if ($photo) {     
		echo "<CENTER><IMG SRC=\"images_ann/$photo\" BORDER=0></CENTER>";
	}	
	  
	  echo "</TD>
    </TR>
</TABLE>";
	
	
	echo "<br><br></td></tr></table></td></tr></table>
    <br><br><center>
    "._CLA_EXTRANN." <B>".$bcoosConfig['title']."</B><br>
    <a href=\"".XOOPS_URL."/modules/MyAnnonces/\">".XOOPS_URL."/modules/MyAnnonces/</a>
    </td></tr></table>
    </body>
    </html>
    ";
}
switch($op) {
    case "EnvAnn":
	EnvAnn($lid);
	break;
	
    case "MailAnn":
	MailAnn($lid, $yname, $ymail, $fname, $fmail);
	break;
	
    case "ImprAnn":
	ImprAnn($lid);
	break;
    default:
	redirect_header("index.php",1,""._RETURNGLO."");
	break;
}
?>
