<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2005 by Philippe Brunier   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
function Access_Error () {
  if (file_exists("meta/meta.php"))
     include ("meta/meta.php");
  echo "<title>NPDS</title></head><body bgcolor=\"white\"><br /><p align=\"center\"><span style=\"font-size: 14px; font-family: Arial; font-weight: bold; color: red;\">";
  echo "Access Denied / Acc&egrave;s Refus&eacute;";
  if (cur_charset=="utf-8") echo" / &#x901A;&#x5165;&#x88AB;&#x5426;&#x8BA4;";
  echo "</span>";
  echo "<br /><br /><span style=\"font-size: 12px; font-family: Arial; font-weight: bold; color: black;\">NPDS - Portal System";
  echo "</span></p></body></html>";
  die();
}
if (!eregi("admin.php", $PHP_SELF)) { Access_Error(); }
global $pdst; $pdst="0";

global $language;
$hlpfile = "manuels/$language/lnl.html";
$result = mysql_query("select radminlnl, radminsuper from authors where aid='$aid'");
list($radminlnl, $radminsuper) = mysql_fetch_row($result);
if (($radminlnl!=1) AND ($radminsuper!=1)) {
   Access_Error();
}

function error_handler($ibid) {
   echo "<p align=\"center\"><span class=\"ROUGE\">".adm_translate("Merci d'entrer l'information en fonction des spécifications")."<br /><br />";
   echo "$ibid</span><br /><a href=\"index.php\" class=\"NOIR\">".adm_translate("Retour en arrière")."</a></p>";
}

function opentableL() {
   echo "<table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" border=\"1\">";
}

function ShowHeader() {
   $result = mysql_query("select ref, text, html from lnl_head_foot where type='HED' ORDER BY ref ");
   echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">";
   while (list($ref, $text, $html) = mysql_fetch_row($result)) {
      $text=nl2br(htmlspecialchars($text));
      $rowcolor = tablos();
      if (strlen($text)>100) {$text=substr($text,0,100)."<span class=\"ROUGE\"> .....</span>";};
      if ($html==1) {$html="htm";} else {$html="txt";}
      echo "<tr $rowcolor><td width=\"5%\" align=\"center\">$ref</td><td width=\"85%\">$text&nbsp;</td><td align=\"center\" nowrap=\"nowrap\">[ $html ]</td>";
      echo "<td nowrap=\"nowrap\"><a href=\"admin.php?op=lnl_Shw_Header&amp;Headerid=$ref\" class=\"NOIR\">".adm_translate("Editer")."</a> | <a href=\"admin.php?op=lnl_Sup_Header&amp;Headerid=$ref\" class=\"ROUGE\">".adm_translate("Effacer")."</a></td></tr>";
   }
   echo "</table>";
}

function Detail_Header_Footer($ibid, $type) {
   global $hlpfile;
   include ("header.php");
   GraphicAdmin($hlpfile);
   opentable();
   // $type = HED or FOT
   $result = mysql_query("select text, html from lnl_head_foot where type='$type' and ref='$ibid'");
   $tmp=mysql_fetch_row($result);
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
   if ($type=="HED") {
      echo adm_translate("Message d'entête");
   } else {
      echo adm_translate("Message de pied de page");
   }
   echo " - ";
   if ($tmp[1]==1) {
      echo adm_translate("Prévisualiser")." HTML<hr noshade>";
      echo $tmp[0];
   } else {
      echo adm_translate("Prévisualiser")." ".adm_translate("TEXTE")."<hr noshade>";
      echo nl2br($tmp[0]);
   }
   echo "</td></tr></table>\n";
   echo "<br />\n";
   echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\">";
   echo "<b>Code Detail</b><br />";
   echo "<textarea class=\"textbox\" wrap=\"virtual\" cols=\"70\" rows=\"20\" name=\"xtext\" style=\"width: 100%;\">".htmlspecialchars($tmp[0])."</textarea>";
   if ($tmp[1]==1) {
      echo aff_editeur("xtext", "false");
      echo "<br />";
   }
   echo "<br />";
   if ($type=="HED") {
      echo "<input type=\"hidden\" name=\"op\" value=\"lnl_Add_Header_Mod\">";
   } else {
      echo "<input type=\"hidden\" name=\"op\" value=\"lnl_Add_Footer_Mod\">";
   }
   echo "<input type=\"hidden\" name=\"ref\" value=\"$ibid\">";
   echo "<input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".adm_translate("Valider")."\"> - ";
   echo "[ <a href=\"admin.php?op=lnl\" class=\"NOIR\">".adm_translate("Retour en arrière")."</a> ]";
   echo "</form>";
   closetable();
   include ("footer.php");
}
function ShowBody() {
   $result = mysql_query("select ref, text, html from lnl_body ORDER BY ref ");
   echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">";
   while (list($ref, $text, $html) = mysql_fetch_row($result)) {
      $rowcolor = tablos();
      $text=nl2br(htmlspecialchars($text));
      if (strlen($text)>200) {$text=substr($text,0,200)."<span class=\"ROUGE\"> .....</span>";};
      if ($html==1) {$html="htm";} else {$html="txt";}
      echo "<tr $rowcolor><td width=\"5%\" align=\"center\">$ref</td><td width=\"85%\">$text&nbsp;</td><td align=\"center\" nowrap=\"nowrap\">[ $html ]</td>";
      echo"<td nowrap=\"nowrap\"><a href=\"admin.php?op=lnl_Shw_Body&amp;Bodyid=$ref\" class=\"NOIR\">".adm_translate("Editer")."</a> | <a href=\"admin.php?op=lnl_Sup_Body&amp;Bodyid=$ref\" class=\"ROUGE\">".adm_translate("Effacer")."</a></td></tr>";
   }
   echo "</table>";
}

function Detail_Body($ibid) {
   global $hlpfile;
   include ("header.php");
   GraphicAdmin($hlpfile);
   opentable();
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
   echo adm_translate("Corps de message")." - ";

   $result = mysql_query("select text, html from lnl_body where ref='$ibid'");
   $tmp=mysql_fetch_row($result);
   if ($tmp[1]==1) {
      echo adm_translate("Prévisualiser")." HTML<hr noshade>";
      echo $tmp[0];
   } else {
      echo adm_translate("Prévisualiser")." ".adm_translate("TEXTE")."<hr noshade>";
      echo nl2br($tmp[0]);
   }

   echo "</td></tr></table>\n";
   echo "<br />\n";
   echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\">";
   echo "<b>Code Detail</b><br />";
   echo "<textarea class=\"textbox\" wrap=\"virtual\" cols=\"70\" rows=\"30\" name=\"xtext\" style=\"width: 100%;\">".htmlspecialchars($tmp[0])."</textarea>";
   if ($tmp[1]==1) {
      echo aff_editeur("xtext", "false");
      echo "<br />";
   }
   echo "<br />";
   echo "<input type=\"hidden\" name=\"op\" value=\"lnl_Add_Body_Mod\">";
   echo "<input type=\"hidden\" name=\"ref\" value=\"$ibid\">";
   echo "<input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".adm_translate("Valider")."\"> - ";
   echo "[ <a href=\"javascript:history.go(-1)\" class=\"NOIR\">".adm_translate("Retour en arrière")."</a> ]";
   echo "</form>";
   closetable();
   include ("footer.php");
}

Function Add_Body() {
   global $hlpfile;
   include ("header.php");
   GraphicAdmin($hlpfile);
   opentable();
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
   echo adm_translate("Ajouter")." ".adm_translate("Corps de message")." ";
   echo "</td></tr></table>\n";
   echo "<br />\n";
   echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\">";
   echo "HTML(1) / Texte(0) : <input class=\"TEXTBOX_STANDARD\" type=\"text\" size=\"2\" max=\"1\" value=\"1\" name=\"html\"><br />\n";
   echo "<textarea class=\"textbox\" wrap=\"virtual\" cols=\"70\" rows=\"30\" name=\"xtext\" style=\"width: 100%;\"></textarea>";
   echo aff_editeur("xtext", "false");
   echo "<br /><br />";
   echo "<input type=\"hidden\" name=\"op\" value=\"lnl_Add_Body_Submit\">";
   echo "<input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".adm_translate("Valider")."\"> - ";
   echo "[ <a href=\"admin.php?op=lnl\" class=\"NOIR\">".adm_translate("Retour en arrière")."</a> ]";
   echo "</form>";
   closetable();
   include("footer.php");
}

Function Add_Body_Submit($Ytext, $Yhtml) {
   mysql_query("insert into lnl_body values ('', '$Yhtml', '$Ytext', 'OK')");
}

function ShowFooter() {
   $result = mysql_query("select ref, text, html from lnl_head_foot where type='FOT' ORDER BY ref ");
   echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">";
   while (list($ref, $text, $html) = mysql_fetch_row($result)) {
      $rowcolor = tablos();
      $text=nl2br(htmlspecialchars($text));
      if (strlen($text)>100) {$text=substr($text,0,100)."<span class=\"ROUGE\"> .....</span>";};
      if ($html==1) {$html="htm";} else {$html="txt";}
      echo "<tr $rowcolor><td width=\"5%\" align=\"center\">$ref</td><td width=\"85%\">$text&nbsp;</td><td align=\"center\" nowrap=\"nowrap\">[ $html ]</td>";
      echo "<td nowrap=\"nowrap\"><a href=\"admin.php?op=lnl_Shw_Footer&amp;Footerid=$ref\" class=\"NOIR\">".adm_translate("Editer")."</a> | <a href=\"admin.php?op=lnl_Sup_Footer&amp;Footerid=$ref\" class=\"ROUGE\">".adm_translate("Effacer")."</a></td></tr>";
   }
   echo "</table>";
}

Function Add_Header_Footer($ibid) {
   global $hlpfile;
   include ("header.php");
   GraphicAdmin($hlpfile);
   opentable();
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
   echo adm_translate("Ajouter")." ";
   if ($ibid=="HED") {
      echo adm_translate("Message d'entête");
   } else {
      echo adm_translate("Message de pied de page");
   }
   echo "</td></tr></table>\n";
   echo "<br />\n";
   echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\">";
   echo "HTML(1) / Texte(0) : <input class=\"TEXTBOX_STANDARD\" type=\"text\" size=\"2\" max=\"1\" value=\"1\" name=\"html\"><br />\n";
   echo "<textarea class=\"textbox\" wrap=\"virtual\" cols=\"70\" rows=\"20\" name=\"xtext\" style=\"width: 100%;\"></textarea>";
   echo aff_editeur("xtext", "false");
   echo "<br /><br />";
   if ($ibid=="HED") {
      echo "<input type=\"hidden\" name=\"op\" value=\"lnl_Add_Header_Submit\">";
   } else {
      echo "<input type=\"hidden\" name=\"op\" value=\"lnl_Add_Footer_Submit\">";
   }
   echo "<input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".adm_translate("Valider")."\"> - ";
   echo "[ <a href=\"admin.php?op=lnl\" class=\"NOIR\">".adm_translate("Retour en arrière")."</a> ]";
   echo "</form>";
   closetable();
   include("footer.php");
}

Function Add_Header_Footer_Submit($ibid, $xtext, $xhtml) {
   if ($ibid=="HED") {
      mysql_query("insert into lnl_head_foot values ('', 'HED','$xhtml', '$xtext', 'OK')");
   } else {
      mysql_query("insert into lnl_head_foot values ('', 'FOT', '$xhtml', '$xtext', 'OK')");
   }
}

function main() {
   global $hlpfile;
   include ("header.php");
   GraphicAdmin($hlpfile);
   OpenTable();
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
   echo adm_translate("Petite Lettre D'information")." - Administration";
   echo "</td></tr></table>\n";
   echo "<br /><p align=\"center\">[ <a href=\"admin.php?op=lnl_List\" class=\"NOIR\">".adm_translate("Liste des LNL envoyées")."</a> ] [ <a href=\"admin.php?op=lnl_User_List\" class=\"NOIR\">".adm_translate("Afficher la liste des prospects")."</a> ]</p>";
   echo "<br /><table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">";
   echo "<tr>";
   echo "<td class=\"ONGL\"><br />".adm_translate("Message d'entête")." - [ <a href=\"admin.php?op=lnl_Add_Header\" class=\"NOIR\">".adm_translate("Ajouter un article")."</a> ]";
   echo "</td></tr>";
   echo "<tr>";
   echo "<td>";
      ShowHeader();
   echo "</td></tr>";
   echo "<tr>";
   echo "<td class=\"ONGL\"><br />".adm_translate("Corps de message")." - [ <a href=\"admin.php?op=lnl_Add_Body\" class=\"NOIR\">".adm_translate("Ajouter un article")."</a> ]";
   echo "</td></tr>";
   echo "<tr>";
   echo "<td>";
      ShowBody();
      echo "</td></tr>";
      echo "<tr>";
      echo "<td class=\"ONGL\"><br />".adm_translate("Message de pied de page")." - [ <a href=\"admin.php?op=lnl_Add_Footer\" class=\"NOIR\">".adm_translate("Ajouter un article")."</a> ]";
   echo "</td></tr>";
   echo "<tr>";
   echo "<td>";
      ShowFooter();
      echo "</td></tr>";
      echo "<tr>";
      echo "<td><br />";
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
   echo adm_translate("Assembler une lettre et la tester");
   echo "</td></tr></table>\n";
      echo "<form action=\"admin.php\" method=\"post\">";
      echo "<p align=\"center\">".adm_translate("Entête")." : <input class=\"TEXTBOX_STANDARD\" type=\"text\" name=\"Xheader\" size=\"12\" max=\"11\">&nbsp;".adm_translate("Corps")." : <input class=\"TEXTBOX_STANDARD\" type=\"text\" name=\"Xbody\" size=\"12\" max=\"11\">";
      echo "&nbsp;".adm_translate("Pied")." : <input class=\"TEXTBOX_STANDARD\" type=\"text\" name=\"Xfooter\" size=\"12\" max=\"11\">";
      echo "<input type=\"hidden\" name=\"op\" value=\"lnl_Test\">";
      echo " - <input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".adm_translate("Valider")."\"></p>";
      echo "</form></td></tr>";
      echo "<tr>";
      echo "<td>";
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
   echo adm_translate("Envoyer La Lettre");
   echo "</td></tr></table>\n";
      echo "<form action=\"admin.php\" method=\"post\">";
      echo adm_translate("Entête")." : <input class=\"TEXTBOX_STANDARD\" type=\"text\" name=\"Xheader\" size=\"12\" max=\"11\">&nbsp;".adm_translate("Corps")." : <input class=\"TEXTBOX_STANDARD\" type=\"text\" name=\"Xbody\" size=\"12\" max=\"11\">";
      echo "&nbsp;".adm_translate("Pied")." :&nbsp;&nbsp;<input class=\"TEXTBOX_STANDARD\" type=\"text\" name=\"Xfooter\" size=\"12\" max=\"11\"><br />";
      echo adm_translate("Sujet")." :&nbsp;&nbsp;&nbsp;<input class=\"TEXTBOX\" type=\"text\" size=\"60\" max=\"255\" name=\"Xsubject\"><hr noshade class=\"ONGL\">";
      echo "<p align=\"center\"><input type=\"radio\" value=\"All\" checked name=\"Xtype\"> ".adm_translate("Tous les Utilisateurs")." -";
      echo "<input type=\"radio\" value=\"Mbr\" name=\"Xtype\"> ".adm_translate("Seulement aux membres")." : ";
      // ---- Groupes
      $mX=liste_group();
      $tmp_groupe="";
      while (list($groupe_id, $groupe_name)=each($mX)) {
         if ($groupe_id=="0") {$groupe_id="";}
         $tmp_groupe.="<option value=\"$groupe_id\" $sel3>$groupe_name</option>\n";
      }
      echo "<select class=\"TEXTBOX_STANDARD\" name=\"Xgroupe\">".$tmp_groupe."</select>&nbsp;";
      // ---- Groupes
      echo "<input type=\"radio\" value=\"Out\" name=\"Xtype\"> ".adm_translate("Seulement aux prospects")." - ";
      echo "<input type=\"hidden\" name=\"op\" value=\"lnl_Send\">";
      echo "<input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".adm_translate("Valider")."\"></p>";
      echo "</form></td></tr>";
   echo "</table>\n";
   closetable();
   include("footer.php");
}

function Del_Question($retour,$param) {
   global $hlpfile;
   include ("header.php");
   GraphicAdmin($hlpfile);
   opentable();
   echo "<p align=\"center\"><span class=\"ROUGE\">".adm_translate("Etes-vous sûr de vouloir effacer cet Article ?")."</span><br /><br />";
   echo "[ <a href=\"admin.php?op=$retour&amp;$param\" class=\"ROUGE\">".adm_translate("Oui")."</a> | ";
   echo "<a href=\"javascript:history.go(-1)\" class=\"NOIR\">".adm_translate("Non")."</a> ]</p>";
   closetable();
   include("footer.php");
}

function Test($Yheader, $Ybody, $Yfooter) {
   global $hlpfile;
   include ("header.php");
   GraphicAdmin($hlpfile);
   opentable();
   // $type = HED or FOT
   $result = mysql_query("select text, html from lnl_head_foot where type='HED' and ref='$Yheader'");
   $Xheader=mysql_fetch_row($result);
   $result = mysql_query("select text, html from lnl_body where html='$Xheader[1]' and ref='$Ybody'");
   $Xbody=mysql_fetch_row($result);
   $result = mysql_query("select text, html from lnl_head_foot where type='FOT' and html='$Xheader[1]' and ref='$Yfooter'");
   $Xfooter=mysql_fetch_row($result);
   // For Meta-Lang
   global $cookie;
   $uid=$cookie[0];
   if ($Xheader[1]==1) {
      echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
      echo adm_translate("Prévisualiser")." HTML";
      echo "</td></tr></table>\n";
      echo "<br />\n";
      $Xmime="html";
      $message=meta_lang($Xheader[0].$Xbody[0].$Xfooter[0]);
   } else {
      echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
      echo adm_translate("Prévisualiser")." ".adm_translate("TEXTE")."";
      echo "</td></tr></table>\n";
      echo "<br />\n";
      $Xmime="text";
      $message=meta_lang(nl2br($Xheader[0]).nl2br($Xbody[0]).nl2br($Xfooter[0]));
   }
   echo $message;
   echo "<br /><br />\n";
   echo "[ <a href=\"javascript:history.go(-1)\" class=\"NOIR\">".adm_translate("Retour en arrière")."</a> ]";
   closetable();

   global $adminmail;
   send_email($adminmail,"LNL TEST",$message, "", true, "html");

   include ("footer.php");
}

function lnl_list() {
   global $hlpfile;
   include ("header.php");
   GraphicAdmin($hlpfile);
   opentable();
   $result = mysql_query("select ref, header , body, footer, number_send, type_send, date, status from lnl_send ORDER BY date");
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
   echo adm_translate("Liste des LNL envoyées");
   echo "</td></tr></table>\n";
   echo "<br /><table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">";
   echo "<tr>";
   echo "<td class=\"ONGL\">Num.</td>";
   echo "<td class=\"ONGL\">".adm_translate("Entête")."</td>";
   echo "<td class=\"ONGL\">".adm_translate("Corps")."</td>";
   echo "<td class=\"ONGL\">".adm_translate("Pied")."</td>";
   echo "<td class=\"ONGL\">".adm_translate("Nbre d'envois effectués")."</td>";
   echo "<td class=\"ONGL\">".adm_translate("Type")."</td>";
   echo "<td class=\"ONGL\">Date</td>";
   echo "<td class=\"ONGL\">Status</td>";
   echo "</tr>";
   while (list($ref, $header, $body, $footer, $number_send, $type_send, $date, $status) = mysql_fetch_row($result)) {
         $rowcolor = tablos();
         echo "<tr $rowcolor>";
         echo "<td>$ref</td>";
         echo "<td>$header</td>";
         echo "<td>$body</td>";
         echo "<td>$footer</td>";
         echo "<td>$number_send</td>";
         echo "<td>$type_send</td>";
         echo "<td>$date</td>";
         if ($status=="NOK") {
            echo "<td class=\"ROUGE\">$status</td>";
         } else {
            echo "<td>$status</td>";
         }
      echo "</tr>";
   }
   echo "</table><br />";
   echo "[ <a href=\"javascript:history.go(-1)\" class=\"NOIR\">".adm_translate("Retour en arrière")."</a> ]";
   closetable();
   include ("footer.php");
}

function lnl_user_list() {
   global $hlpfile;
   include ("header.php");
   GraphicAdmin($hlpfile);
   opentable();
   $result = mysql_query("select email, date, status from lnl_outside_users ORDER BY date");
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
   echo adm_translate("Afficher la liste des prospects");
   echo "</td></tr></table>\n";
   echo "<br /><table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">";
   echo "<tr>";
   echo "<td class=\"ONGL\">".adm_translate("E-mail")."</td>";
   echo "<td class=\"ONGL\">Date</td>";
   echo "<td class=\"ONGL\">Status</td>";
   echo "<td class=\"ONGL\" align=\"center\">".adm_translate("Effacer")."</td>";
   echo "</tr>";
   while (list($email, $date, $status) = mysql_fetch_row($result)) {
      $rowcolor = tablos();
      echo "<tr $rowcolor>";
      echo "<td>$email</td>";
      echo "<td>$date</td>";
      if ($status=="NOK") {
         echo "<td class=\"ROUGE\">$status</td>";
      } else {
         echo "<td>$status</td>";
      }
      echo "<td align=\"center\"><a href=\"admin.php?op=lnl_Sup_User&amp;lnl_user_email=$email\" class=\"ROUGE\">".adm_translate("Effacer")."</a></td>";
      echo "</tr>";
   }
   echo "</table><br />";
   echo "[ <a href=\"javascript:history.go(-1)\" class=\"NOIR\">".adm_translate("Retour en arrière")."</a> ]";
   closetable();
   include ("footer.php");
}

switch($op) {
   case "Sup_Header":
         Del_Question("lnl_Sup_HeaderOK","Headerid=$Headerid");
         break;
   case "Sup_Body":
         Del_Question("lnl_Sup_BodyOK","Bodyid=$Bodyid");
         break;
   case "Sup_Footer":
         Del_Question("lnl_Sup_FooterOK","Footerid=$Footerid");
         break;
   case "Sup_HeaderOK":
         mysql_query("delete FROM lnl_head_foot WHERE ref='$Headerid'");
         header("location: admin.php?op=lnl");
         break;
   case "Sup_BodyOK":
         mysql_query("delete FROM lnl_body WHERE ref='$Bodyid'");
         header("location: admin.php?op=lnl");
         break;
   case "Sup_FooterOK":
         mysql_query("delete FROM lnl_head_foot WHERE ref='$Footerid'");
         header("location: admin.php?op=lnl");
         break;

   case "Shw_Header":
         Detail_Header_Footer($Headerid, "HED");
         break;
   case "Shw_Body":
         Detail_Body($Bodyid);
         break;
   case "Shw_Footer":
         Detail_Header_Footer($Footerid, "FOT");
         break;

   case "Add_Header":
         Add_Header_Footer("HED");
         break;
         case "Add_Header_Submit":
            Add_Header_Footer_Submit("HED", $xtext, $html);
            header("location: admin.php?op=lnl");
            break;
         case "Add_Header_Mod":
            mysql_query("update lnl_head_foot set text='$xtext' WHERE ref='$ref'");
            header("location: admin.php?op=lnl_Shw_Header&Headerid=$ref");
            break;

   case "Add_Body":
         Add_Body();
         break;
         case "Add_Body_Submit":
            Add_Body_Submit($xtext, $html);
            header("location: admin.php?op=lnl");
            break;
         case "Add_Body_Mod":
            mysql_query("update lnl_body set text='$xtext' WHERE ref='$ref'");
            header("location: admin.php?op=lnl_Shw_Body&Bodyid=$ref");
            break;

   case "Add_Footer":
         Add_Header_Footer("FOT");
         break;
         case "Add_Footer_Submit":
           Add_Header_Footer_Submit("FOT", $xtext, $html);
           header("location: admin.php?op=lnl");
           break;
         case "Add_Footer_Mod":
            mysql_query("update lnl_head_foot set text='$xtext' WHERE ref='$ref'");
            header("location: admin.php?op=lnl_Shw_Footer&Footerid=$ref");
            break;

   case "Test":
         Test($Xheader, $Xbody, $Xfooter);
         break;

   case "List":
         lnl_list();
         break;

   case "User_List":
         lnl_user_list();
         break;
   case "Sup_User":
         mysql_query("delete FROM lnl_outside_users WHERE email='$lnl_user_email'");
         header("location: admin.php?op=lnl_User_List");
         break;

   case "Send":
         $deb=0;     
         $limit=50; // nombre de messages envoyé par boucle.
         if (!isset($debut)) $debut=0;
         if (!isset($number_send)) $number_send=0;

         global $nuke_url;
         $result = mysql_query("select text, html from lnl_head_foot where type='HED' and ref='$Xheader'");
         $Yheader=mysql_fetch_row($result);
         $result = mysql_query("select text, html from lnl_body where html='$Yheader[1]' and ref='$Xbody'");
         $Ybody=mysql_fetch_row($result);
         $result = mysql_query("select text, html from lnl_head_foot where type='FOT' and html='$Yheader[1]' and ref='$Xfooter'");
         $Yfooter=mysql_fetch_row($result);

         $subject=stripslashes($Xsubject);
         $message =$Yheader[0].$Ybody[0].$Yfooter[0];

         global $sitename;
         if ($Yheader[1]==1) {
            $Xmime="html";
         } else {
            $Xmime="text";
         }

         if ($Xtype=="All") {
            $Xtype="Out";
            $OXtype="All";
         }

         // Outside Users
         if ($Xtype=="Out") {
            $mysql_result=mysql_query("SELECT email from lnl_outside_users where status='OK'");
            $nrows=mysql_num_rows($mysql_result);
            $result = mysql_query("select email from lnl_outside_users where status='OK' ORDER BY email limit $debut,$limit");
            while (list($email) = mysql_fetch_row($result)) {
               if (($email!="Anonyme") or ($email!="Anonymous")) {
                  if ($email!="") {
                     if (($message!="") and ($subject!="")) {
                        if ($Xmime=="html") {
                           $Xmessage=$message."<br /><br /><hr noshade>";
                           $Xmessage.= adm_translate("Pour supprimer votre abonnement à notre Lettre, suivez ce lien")." : <a href=\"$nuke_url/lnl.php?op=unsubscribe&email=$email\">".adm_translate("Modifier")."</a>";
                        } else {
                           $Xmessage=$message."\n\n------------------------------------------------------------------\n";
                           $Xmessage.= adm_translate("Pour supprimer votre abonnement à notre Lettre, suivez ce lien")." : $nuke_url/lnl.php?op=unsubscribe&email=$email";
                        }
                        send_email($email, $subject, meta_lang($Xmessage), "", true, $Xmime);
                        $number_send++;
                     }
                  }
               }
            }
         }
         // NPDS Users
         if ($Xtype=="Mbr") {
            if ($Xgroupe!="") {
               $result="";
               $mysql_result=mysql_query("SELECT u.uid FROM users u, users_status s where s.open='1' and u.uid=s.uid and u.email!='' and (s.groupe LIKE '%$Xgroupe,%' OR s.groupe LIKE '%,$Xgroupe' OR s.groupe='$Xgroupe') and u.user_lnl='1'");
               $nrows=mysql_num_rows($mysql_result);
               $resultGP = mysql_query("SELECT u.email, u.uid, s.groupe FROM users u, users_status s where s.open='1' and u.uid=s.uid and u.email!='' and (s.groupe LIKE '%$Xgroupe,%' OR s.groupe LIKE '%,$Xgroupe' OR s.groupe='$Xgroupe') and u.user_lnl='1' ORDER BY u.email limit $debut,$limit");
               while(list($email, $uid, $groupe) = mysql_fetch_row($resultGP)) {
                  $tab_groupe=explode(",",$groupe);
                  if ($tab_groupe) {
                     foreach($tab_groupe as $groupevalue) {
                        if ($groupevalue==$Xgroupe) {
                           $result[]=$email;
                        }
                     }
                  }
               }
               $fonction="each";
               if (is_array($result)) {$boucle=true;} else {$boucle=false;}
            } else {
               $mysql_result=mysql_query("SELECT u.uid FROM users u, users_status s where s.open='1' and u.uid=s.uid and u.email!='' and u.user_lnl='1'");
               $nrows=mysql_num_rows($mysql_result);
               $result = mysql_query("select u.uid, u.email from users u, users_status s where s.open='1' and u.uid=s.uid and u.user_lnl='1' ORDER BY email limit $debut,$limit");
               $fonction="mysql_fetch_row";
               $boucle=true;
            }
            if ($boucle) {
               while (list($bidon, $email) = $fonction($result)) {
                  if (($email!="Anonyme") or ($email!="Anonymous")) {
                     if ($email!="") {
                        if (($message!="") and ($subject!="")) {
                           send_email($email, $subject, meta_lang($message), "", true, $Xmime);
                           $number_send++;
                        }
                     }
                  }
               }
            }
         }
         $deb=$debut+$limit;
         $chartmp="";
         if ($deb>=$nrows) {
            if ((($OXtype=="All") and ($Xtype=="Mbr")) OR ($OXtype=="")) {
               if (($message!="") and ($subject!="")) {
                  $timeX=strftime("%Y-%m-%d %T",time());
                  if ($OXtype=="All") {$Xtype="All";}
                  if (($Xtype=="Mbr") and ($Xgroupe!="")) {$Xtype=$Xgroupe;}
                  mysql_query("insert into lnl_send values ('', '$Xheader', '$Xbody', '$Xfooter', '$number_send', '$Xtype', '$timeX', 'OK')");
               }
               header("location: admin.php?op=lnl");
               break;
            } else {
              if ($OXtype=="All") {
                 $chartmp="$Xtype : $nrows / $nrows";
                 $deb=0;
                 $Xtype="Mbr";
                 $mysql_result=mysql_query("SELECT u.uid FROM users u, users_status s where s.open='1' and u.uid=s.uid and u.email!='' and u.user_lnl='1'");
                 $nrows=mysql_num_rows($mysql_result);
              }
            }
         }
         if ($chartmp=="") {$chartmp="$Xtype : $deb / $nrows";}
         include("meta/meta.php");
         echo "<script type=\"text/javascript\" language=\"JavaScript\">
               function redirect() {
                  window.location=\"admin.php?op=lnl_Send&debut=".$deb."&OXtype=$OXtype&Xtype=$Xtype&Xgroupe=$Xgroupe&Xheader=".$Xheader."&Xbody=".$Xbody."&Xfooter=".$Xfooter."&number_send=".$number_send."&Xsubject=".$Xsubject."\";
               }
               setTimeout(\"redirect()\",10000);
               </script>";
         echo "</head>\n<body bgcolor=\"white\"><br /><p align=\"center\" style=\"font-size: 12px; font-family: Arial; font-weight: bold; color: black;\">";
         echo adm_translate("Transmission LNL en cours")." => ".$chartmp;
         echo "<br /><br />NPDS - Portal System";
         echo "</p></body></html>";
         break;

   default:
         main();
         break;
}
?>
