<?PHP
/************************************************************************/
/* NPDS V : Net Portal Dynamic System .                                 */
/* ===========================                                          */
/*                                                                      */
/* Original Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)   */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* 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(); }
include ("publication.php");
global $pdst; $pdst="0";

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

function puthome($ihome) {
    echo "<br /><b>".adm_translate("Publier dans la racine ?")."</b>&nbsp;&nbsp;";
    $sel1 = "checked";
    $sel2 = "";
    if ($ihome == 1) {
        $sel1 = "";
        $sel2 = "checked";
    }
    echo "<input type=\"radio\" name=\"ihome\" value=\"0\" $sel1>".adm_translate("Oui")."&nbsp;";
    echo "<input type=\"radio\" name=\"ihome\" value=\"1\" $sel2>".adm_translate("Non");
    echo "&nbsp;&nbsp; <span class=\"NOIR\">[ ".adm_translate("Ne s'applique que si la catégorie : <b>'Articles'</b> n'est pas sélectionnée.")." ]</span><br /><br />";

    $sel1 = "";
    $sel2 = "checked";
    echo "<span class=\"ROUGE\"><b>".adm_translate("Seulement aux membres")."</b></span> :";
    if ($ihome<0) {
       $sel1 = "checked";
       $sel2 = "";
    }
    if (($ihome>1) and ($ihome<=127)) {
       $Mmembers=$ihome;
       $sel1 = "checked";
       $sel2 = "";
    }
    echo "<input type=\"radio\" name=\"members\" value=\"1\" $sel1>".adm_translate("Oui")."&nbsp; /
    ".adm_translate("Groupe")." : ";
    // ---- Groupes
    $mX=liste_group();
    $tmp_groupe="";
    while (list($groupe_id, $groupe_name)=each($mX)) {
       if ($groupe_id=="0") {$groupe_id="";}
       if ($Mmembers==$groupe_id) {$sel3="selected";} else {$sel3="";}
       $tmp_groupe.="<option value=\"$groupe_id\" $sel3>$groupe_name</option>\n";
      $nbg++;
    }
    echo "<select class=\"TEXTBOX_STANDARD\" name=\"Mmembers\">".$tmp_groupe."</select>&nbsp;";
    // ---- Groupes
    echo "<input type=\"radio\" name=\"members\" value=\"0\" $sel2>".adm_translate("Non")."<br />";
}

function SelectCategory($cat) {
    $selcat = mysql_query("select catid, title from stories_cat");
    echo " <b>".adm_translate("Catégorie")."</b> ";
    echo "<select class=\"TEXTBOX_STANDARD\" name=\"catid\">";
    if ($cat == 0) {
       $sel = "selected";
    } else {
       $sel = "";
    }
    echo "<option name=\"catid\" value=\"0\" $sel>".adm_translate("Articles")."</option>";
    while(list($catidX, $title) = mysql_fetch_row($selcat)) {
       if ($catidX==$cat) {
          $sel = "selected";
       } else {
          $sel = "";
       }
       echo "<option name=\"catid\" value=\"$catidX\" $sel>".aff_langue($title)."</option>";
    }
    echo "</select> [ <a href=\"admin.php?op=AddCategory\" class=\"NOIR\">".adm_translate("Ajouter")."</a> | <a href=\"admin.php?op=EditCategory\" class=\"NOIR\">".adm_translate("Editer")."</a> | <a href=\"admin.php?op=DelCategory\" class=\"ROUGE\">".adm_translate("Effacer")."</a> ]";
}

function autoStory() {
    global $hlpfile, $aid, $radminsuper, $gmt;
    include ("header.php");
    GraphicAdmin($hlpfile);
    OpenTable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo adm_translate("Articles programmés");
    echo "</td></tr></table>\n";
    echo "<br /><table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">";
    $result = mysql_query("select anid, title, date_debval, topic from autonews order by date_debval ASC");
    while(list($anid, $title, $time, $topic) = mysql_fetch_row($result)) {
        if ($anid != "") {
           $affiche=false;
           $result2=mysql_query("select topicadmin, topicname from topics where topicid='$topic'");
           list ($topicadmin, $topicname)=mysql_fetch_row($result2);
           if ($radminsuper) {
              $affiche=true;
           } else {
              $topicadminX=explode(",",$topicadmin);
              for ($i = 0; $i < count($topicadminX); $i++) {
                 if (trim($topicadminX[$i])==$aid) $affiche=true;
              }
           }
           $rowcolor = tablos();
           if ($title=="") {$title=adm_translate("Aucun Sujet");}
           if ($affiche) {
              echo "<tr $rowcolor><td width=\"75%\"><a href=\"admin.php?op=autoEdit&amp;anid=$anid\" class=\"NOIR\">".aff_langue($title)."</a></td><td><b>=&gt;</b></td><td nowrap=\"nowrap\" align=\"right\">".formatTimestamp("nogmt".$time)."</td><td nowrap=\"nowrap\"><a href=\"admin.php?op=autoDelete&amp;anid=$anid\" class=\"ROUGE\">".adm_translate("Effacer")."</a></td></tr>";
           } else {
              echo "<tr $rowcolor><td width=\"75%\"><i>".aff_langue($title)."</i></td><td><b>=&gt;</b></td><td nowrap=\"nowrap\" align=\"right\">".formatTimestamp("nogmt".$time)."</td><td nowrap=\"nowrap\">&nbsp;</td></tr>";
           }
        }
    }
    echo "</table>";
    CloseTable();
    include("footer.php");
}

function autoDelete($anid) {
    mysql_query("delete from autonews where anid='$anid'");
    Header("Location: admin.php?op=autoStory");
}
function autoEdit($anid) {
    global $aid, $hlpfile, $tipath, $radminsuper;
    $result = mysql_query("select catid, title, time, hometext, bodytext, topic, informant, notes, ihome, date_debval,date_finval,auto_epur from autonews where anid='$anid'");
    list($catid, $title, $time, $hometext, $bodytext, $topic, $informant, $notes, $ihome, $date_debval,$date_finval,$epur) = mysql_fetch_row($result);
    mysql_free_result($result);
    $titre = stripslashes($title);
    $hometext = stripslashes($hometext);
    $bodytext = stripslashes($bodytext);
    $notes = stripslashes($notes);

    if ($topic<1) {$topic = 1;}
    $affiche=false;
    $result2=mysql_query("select topictext, topicimage, topicadmin from topics where topicid='$topic'");
    list ($topictext, $topicimage, $topicadmin)=mysql_fetch_row($result2);
    if ($radminsuper) {
       $affiche=true;
    } else {
       $topicadminX=explode(",",$topicadmin);
       for ($i = 0; $i < count($topicadminX); $i++) {
          if (trim($topicadminX[$i])==$aid) $affiche=true;
       }
    }
    if (!$affiche) { header("location: admin.php?op=autoStory");}

    include ('header.php');
    GraphicAdmin($hlpfile);
    OpenTable();
    echo "<table width=100% cellspacing=2 cellpadding=2 border=0><tr><td class=\"HEADER\">\n";
    echo adm_translate("Editer l'Article Automatique");
    echo "</td></tr></table><br />";
    echo "<p align=\"center\">";
    $rowcolor = tablos();
    echo "<table border=\"0\" width=\"85%\" cellpadding=\"0\" cellspacing=\"1\"><tr $rowcolor><td>";
    $rowcolor = tablos();
    echo "<table width=\"100%\" border=\"0\" cellpadding=\"8\" cellspacing=\"1\"><tr $rowcolor>";
    echo "<td valign=\"top\">".aff_local_langue("<b>".adm_translate("Langue de Prévisualisation")."</b> : ","","local_user_language");
    $no_img=false;
    if ((file_exists("$tipath$topicimage")) and ($topicimage!="")) {
      echo "<img src=\"$tipath$topicimage\" border=\"0\" align=\"right\" alt=\"\" />";
    } else {
      $no_img=true;
    }
    code_aff($titre, $hometext, $bodytext, $notes);
    if ($no_img) {
       echo "</td><td width=\"10%\" align=\"center\" valign=\"center\"><b>".aff_langue($topictext)."</b>";
    }
    echo "</td></tr></table></td></tr></table></p><br />";

    echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\">";
    opentable2();
    echo "<b>".adm_translate("Utilisateur")."</b> : $informant<br /><br />
    <b>".adm_translate("Titre")."</b>&nbsp;&nbsp;:
    <input class=\"textbox\" type=\"text\" name=\"title\" size=\"50\" value=\"$titre\"><br />";
    echo "<b>".adm_translate("Sujet")."</b> : <select class=\"TEXTBOX_STANDARD\" name=\"topic\">";
    $toplist = mysql_query("select topicid, topictext, topicadmin from topics order by topictext");
    if ($radminsuper) echo "<option value=\"\">".adm_translate("Tous les Sujets")."</option>\n";
    while(list($topicid, $topics, $topicadmin) = mysql_fetch_row($toplist)) {
       $affiche=false;
       if ($radminsuper) {
          $affiche=true;
       } else {
          $topicadminX=explode(",",$topicadmin);
          for ($i = 0; $i < count($topicadminX); $i++) {
             if (trim($topicadminX[$i])==$aid) $affiche=true;
          }
       }
       if ($affiche) {
          if ($topicid==$topic) { $sel = "selected "; }
          echo "<option $sel value=\"$topicid\">".aff_langue($topics)."</option>\n";
          $sel = "";
       }
    }
    echo "</select>";
    SelectCategory($catid);
    echo "<br />";
    puthome($ihome);
    closetable2();
    echo "<br /><b>".adm_translate("Texte d'introduction")."</b> :<br />
    <textarea class=\"textbox\" wrap=\"virtual\" cols=\"70\" rows=\"25\" name=\"hometext\" style=\"width: 100%;\">$hometext</textarea>";
    echo aff_editeur("hometext", "true");
    echo "<br /><b>".adm_translate("Texte étendu")."</b> :<br />
    <textarea class=\"textbox\" wrap=\"virtual\" cols=\"70\" rows=\"25\" name=\"bodytext\" style=\"width: 100%;\">$bodytext</textarea>";
    echo aff_editeur("bodytext", "true");
    if ($aid != $informant) {
       echo "<br /><b>".adm_translate("Notes")."</b> :<br />
       <textarea class=\"textbox\" wrap=\"virtual\" cols=\"70\" rows=\"7\" name=\"notes\" style=\"width: 100%;\">$notes</textarea>";
       echo aff_editeur("notes", "true");
    }
    $deb_day=substr($date_debval,8,2);
    $deb_month=substr($date_debval,5,2);
    $deb_year=substr($date_debval,0,4);
    $deb_hour=substr($date_debval,11,2);
    $deb_min=substr($date_debval,14,2);
    //
    $fin_day=substr($date_finval,8,2);
    $fin_month=substr($date_finval,5,2);
    $fin_year=substr($date_finval,0,4);
    $fin_hour=substr($date_finval,11,2);
    $fin_min=substr($date_finval,14,2);
    //
    publication($deb_day,$deb_month,$deb_year,$deb_hour,$deb_min, $fin_day,$fin_month,$fin_year,$fin_hour,$fin_min, $epur);
    echo "<input type=\"hidden\" name=\"anid\" value=\"$anid\">
    <input type=\"hidden\" name=\"op\" value=\"autoSaveEdit\">
    <br /><input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".adm_translate("Sauver les modifications")."\">
    </form>";
    closetable();
    include ('footer.php');
}

function autoSaveEdit($anid, $title, $hometext, $bodytext, $topic, $notes, $catid, $ihome, $informant, $members, $Mmembers, $date_debval,$date_finval,$epur) {
    global $aid, $ultramode;
    $title = stripslashes(FixQuotes(str_replace("\"","&quot;",$title)));
    $hometext = stripslashes(FixQuotes($hometext));
    $bodytext = stripslashes(FixQuotes($bodytext));
    $notes = stripslashes(FixQuotes($notes));
    if (($members==1) and ($Mmembers=="")) {$ihome="-127";}
    if (($members==1) and (($Mmembers>1) and ($Mmembers<=127))) {$ihome=$Mmembers;}
    $upload=false;
    include("modules/upload/upload_f.php");
    if ($Xstring=prepa_upload("",$hometext)) {$hometext=$Xstring[0];$Xname=$Xstring[1];$upload=true;}
    if ($Xstring=prepa_upload($Xname,$bodytext)) {$bodytext=$Xstring[0];$Xname=$Xstring[1];$upload=true;}
    if ($Xstring=prepa_upload($Xname,$notes)) {$notes=$Xstring[0];$Xname=$Xstring[1];$upload=true;}
    if ($upload) {
       global $pdst; $pdst="1";
       include ('header.php');
       win_upload($Xname);
       opentable();
       $title="!urlencode!".urlencode($title);
       $hometext=urlencode($hometext);
       $bodytext=urlencode($bodytext);
       $notes=urlencode($notes);
       echo "<br /><form action=\"admin.php\" method=\"post\" name=\"adminForm\">";
       echo "<b>".translate("Submission in progress. After Uploading your files, please click on the OK button to finish.")."</b>";
       echo "<input type=\"hidden\" name=\"anid\" value=\"$anid\">";
       echo "<input type=\"hidden\" name=\"title\" value=\"$title\">";
       echo "<input type=\"hidden\" name=\"hometext\" value=\"$hometext\">";
       echo "<input type=\"hidden\" name=\"bodytext\" value=\"$bodytext\">";
       echo "<input type=\"hidden\" name=\"topic\" value=\"$topic\">";
       echo "<input type=\"hidden\" name=\"notes\" value=\"$notes\">";
       echo "<input type=\"hidden\" name=\"catid\" value=\"$catid\">";
       echo "<input type=\"hidden\" name=\"ihome\" value=\"$ihome\">";
       echo "<input type=\"hidden\" name=\"informant\" value=\"$informant\">";
       echo "<input type=\"hidden\" name=\"members\" value=\"$members\">";
       echo "<input type=\"hidden\" name=\"Mmembers\" value=\"$Mmembers\">";
       echo "<input type=\"hidden\" name=\"date_debval\" value=\"$date_debval\">";
       echo "<input type=\"hidden\" name=\"date_finval\" value=\"$date_finval\">";
       echo "<input type=\"hidden\" name=\"epur\" value=\"$epur\">";
       echo "<input type=\"hidden\" name=\"op\" value=\"autoSaveEdit\">";
       echo "<br /><br /><p align=\"center\"><input class=\"BOUTON_STANDARD\" type=\"submit\" name=\"xop\" value=\"Ok\">&nbsp;&nbsp;<a href=\"javascript: history.go(-1)\" class=\"NOIR\">[ ".translate("Go Back")." ]</a></p>";
       echo "</form>";
       closetable();
       include ('footer.php');
    } else {
       if (substr($title,0,11)=="!urlencode!") {
          $title=str_replace("!urlencode!","",urldecode($title));
          $hometext=urldecode($hometext);
          $bodytext=urldecode($bodytext);
          $notes=urldecode($notes);
       }
       $result = mysql_query("update autonews set catid='$catid', title='$title', time=now(), hometext='$hometext', bodytext='$bodytext', topic='$topic', notes='$notes', ihome='$ihome', date_debval='$date_debval', date_finval='$date_finval', auto_epur='$epur' where anid='$anid'");
       if ($ultramode) {
          ultramode();
       }
       Header("Location: admin.php?op=autoEdit&anid=$anid");
    }
}

switch($op) {
    case "autoStory":
         autoStory();
         break;
    case "autoDelete":
         autodelete($anid);
         break;
    case "autoEdit":
         autoEdit($anid);
         break;
    case "autoSaveEdit":
         if (!$date_debval) {
            if (strlen($deb_day)==1) {
               $deb_day = "0$deb_day";
            }
            if (strlen($deb_month)==1) {
               $deb_month = "0$deb_month";
            }
            $date_debval = "$deb_year-$deb_month-$deb_day $deb_hour:$deb_min:00";
         }
         if (!$date_finval) {
            if (strlen($fin_day)==1) {
               $fin_day = "0$fin_day";
            }
            if (strlen($fin_month)==1) {
               $fin_month = "0$fin_month";
            }
            $date_finval = "$fin_year-$fin_month-$fin_day $fin_hour:$fin_min:00";
         }
         if ($date_finval<$date_debval) {
            $date_finval = $date_debval;
         }
         autoSaveEdit($anid, $title, $hometext, $bodytext, $topic, $notes, $catid, $ihome, $informant, $members, $Mmembers, $date_debval,$date_finval,$epur);
         break;
}
?>