<?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 (!strstr($PHP_SELF,"admin.php")) { Access_Error(); }
include("lib/file.class.php");
global $pdst; $pdst="0";

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

function groupe($groupe) {
   $les_groupes=split(",",$groupe);
   $mX=liste_group();
   $nbg=0; $str="";
   while (list($groupe_id, $groupe_name)=each($mX)) {
      $selectionne=0;
      if ($les_groupes) {
         foreach ($les_groupes as $groupevalue) {
            if (($groupe_id==$groupevalue) and ($groupe_id!=0)) {$selectionne=1;}
         }
      }
      if ($selectionne==1) {
         $str.="<option value=\"$groupe_id\" selected>$groupe_name</option>";
      } else {
         $str.="<option value=\"$groupe_id\">$groupe_name</option>";
      }
      $nbg++;
   }
   if ($nbg>5) {$nbg=5;}
   return ("<select class=\"TEXTBOX_STANDARD\" name=\"Mprivs\" size=\"$nbg\" style=\"top: -4;\">".$str."</select>");
}
function droits($member) {
   echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr><td align=\"left\" valign=\"top\" width=\"10%\" nowrap=\"nowrap\">";
   echo "<span class=\"ROUGE\">".adm_translate("Administrateurs")."</span> :";
   if ($member==-127) {$checked=" checked";} else {$checked="";}
   echo "<input type=\"radio\" name=\"privs\" value=\"-127\"$checked></td><td align=\"center\" valign=\"top\" width=\"10%\" nowrap=\"nowrap\">";
   echo "<span class=\"ROUGE\">".adm_translate("Anonymes")."</span> :";
   if ($member==-1) {$checked=" checked";} else {$checked="";}
   echo "<input type=\"radio\" name=\"privs\" value=\"-1\"$checked></td><td align=\"right\" valign=\"top\" width=\"15%\" nowrap=\"nowrap\">";
   echo "<span class=\"ROUGE\">".adm_translate("Membres")."</span> :";
   if ($member>0) {
      echo "<input type=\"radio\" name=\"privs\" value=\"1\" checked>&nbsp;&nbsp;<b>=> ".adm_translate("Groupes")." :&nbsp;&nbsp;</b>";
      echo "</td><td align=\"left\" valign=\"top\" width=\"15%\">";
      echo groupe($member);
      echo "</td><td align=\"left\" valign=\"top\" width=\"10%\">";
      echo "<input type=\"radio\" name=\"privs\" value=\"0\"><b>".adm_translate("Tous")."</b></td></tr></table>";
   } else {
      if ($member==0) {$checked=" checked";} else {$checked="";}
      echo "<input type=\"radio\" name=\"privs\" value=\"1\">&nbsp;&nbsp;<b>=> ".adm_translate("Groupes")." :&nbsp;&nbsp;</b>";
      echo "</td><td align=\"left\" valign=\"top\" width=\"15%\">";
      echo groupe($member);
      echo "</td><td align=\"left\" valign=\"top\" width=\"10%\">";
      echo "<input type=\"radio\" name=\"privs\" value=\"0\"$checked><b>".adm_translate("Tous")."</b></td></tr></table>";
   }
}
function DownloadAdmin() {
    global $hlpfile;
    include ("header.php");
    include_once ("lib/togglediv.class.php");
    GraphicAdmin($hlpfile);
    OpenTable();

    echo "<form action=\"admin.php\" method=\"post\">";
    $resultX = mysql_query("select distinct dcategory from downloads order by dcategory");
    $num_row=mysql_num_rows($resultX);
    $toggle = new ToggleDiv($num_row);

    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo adm_translate("Téléchargement");
    echo "</td><td class=\"ONGL\">".$toggle->All()."</td>";
    echo "</td></tr></table>";

    while(list($dcategory) = mysql_fetch_row($resultX)) {
       echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">";
       echo "<tr><td class=\"ONGL\">";
       echo $toggle->Img();
       echo adm_translate("Catégorie")." : ".aff_langue(stripslashes($dcategory));
       echo $toggle->Begin();
       echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">
          <tr>
             <td class=\"ONGL\">".adm_translate("ID")."</td>
             <td class=\"ONGL\">".adm_translate("Compt.")."</td>
             <td class=\"ONGL\">Typ.</td>
             <td class=\"ONGL\">".adm_translate("URL")."</td>
             <td class=\"ONGL\">".adm_translate("Nom de fichier")."</td>
             <td class=\"ONGL\" align=center>".adm_translate("Ver.")."</td>
             <td class=\"ONGL\" align=center>".adm_translate("Taille de fichier")."</td>
             <td class=\"ONGL\" align=center>".adm_translate("Date")."</td>
             <td class=\"ONGL\" align=center>".adm_translate("Fonctions")."</td>
          </tr>";
       $result = mysql_query("select did, dcounter, durl, dfilename, dfilesize, ddate, dver, perms from downloads where dcategory='".addslashes($dcategory)."' order by did ASC");
       while(list($did, $dcounter, $durl, $dfilename, $dfilesize, $ddate, $dver, $dperm) = mysql_fetch_row($result)) {
          $rowcolor = tablos();
          echo "<tr $rowcolor>
                <td align=\"center\">$did</td>
                <td align=\"center\">$dcounter</td>";
          if ($dperm==0) {$dperm="Al";}
          if ($dperm>=1) {$dperm="Mb";}
          if ($dperm==-127) {$dperm="Ad";}
          if ($dperm==-1) {$dperm="An";}
          echo "<td align=\"left\">$dperm</td>
                <td><a href=\"$durl\" class=\"NOIR\">".adm_translate("Téléchargement")."</a></td>
                <td>$dfilename</td>
                <td align=\"center\">&nbsp;$dver</td>
                <td align=\"center\">";
                $Fichier = new File($durl);
                if ($dfilesize!=0) {
                   echo $Fichier->Pretty_Size($dfilesize);
                } else {
                   echo $Fichier->Affiche_Size();
                }
                echo "</td>
                <td align=\"center\">$ddate</td>
                <td align=\"center\"><a href=\"admin.php?op=DownloadEdit&amp;did=$did\" class=\"NOIR\">".adm_translate("Editer")."</a> |
                <a href=\"admin.php?op=DownloadDel&amp;did=$did&amp;ok=0\" class=\"ROUGE\">".adm_translate("Effacer")."</a></td>
               </tr>";
       }
       echo "</table>";
       echo $toggle->End();
       echo "</td></tr></table>";
    }
    echo "</form>";

    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo adm_translate("Ajouter un Téléchargement");
    echo "</td></tr></table>\n";
    echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\">
    <table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">
    <tr>
       <td width=\"150\">".adm_translate("Télécharger URL : ")."  (255 cars)</td>
       <td width=\"20%\"><input class=\"textbox\" type=\"text\" name=\"durl\" size=\"30\" maxlength=\"255\">
       &nbsp;<a href=\"javascript:void(0);\" onClick=\"window.open('admin.php?op=FileManagerDisplay', 'wdir', 'width=650, height=450, menubar=no, location=no, directories=no, status=no, copyhistory=no, toolbar=no, scrollbars=yes, resizable=yes');\">";
       echo "<span class=\"ROUGE\">[".adm_translate("Parcourir")."]</span></a></td>
    </tr>
    <tr>
       <td width=\"20%\">".adm_translate("Compteur : ")."</td>
       <td><input class=\"textbox_standard\" type=\"text\" name=\"dcounter\" size=\"10\" maxlength=\"30\"></td>
    </tr>
    <tr>
       <td width=\"20%\">".adm_translate("Nom de fichier : ")." (255 cars)</td>
       <td><input class=\"textbox\" type=\"text\" name=\"dfilename\" size=\"30\" maxlength=\"255\"></td>
    </tr>
    <tr>
       <td width=\"20%\">".adm_translate("Version : ")."</td>
       <td><input class=\"textbox_standard\" type=\"text\" name=\"dver\" size=\"5\" maxlength=\"6\"></td>
    </tr>
    <tr>
       <td width=\"20%\">".adm_translate("Taille de fichier : ")." (bytes)</td>
       <td><input class=\"textbox_standard\" type=\"text\" name=\"dfilesize\" size=\"30\" maxlength=\"31\"></td>
    </tr>
    <tr>
       <td width=\"20%\">".adm_translate("Propriétaire de la page Web : ")." (255 cars)</td>
       <td><input class=\"textbox\" type=\"text\" name=\"dweb\" size=\"30\" maxlength=\"255\"></td>
    </tr>
    <tr>
       <td width=\"20%\">".adm_translate("Propriétaire : ")."</td>
       <td><input class=\"textbox\" type=\"text\" name=\"duser\" size=\"30\" maxlength=\"31\"></td>
    </tr>
    <tr>
       <td width=\"20%\">".adm_translate("Categorie : ")."</td>
       <td><input class=\"textbox_standard\" type=\"text\" name=\"dcategory\" size=\"25\" maxlength=\"250\"> - ";
    echo "<select class=\"textbox_standard\" name=\"sdcategory\">";
    $result = mysql_query("select distinct dcategory from downloads order by dcategory");
    while (list($dcategory) = mysql_fetch_row($result)) {
       $dcategory=stripslashes($dcategory);
       echo "<option $sel value=\"$dcategory\">".aff_langue($dcategory)."</option>";
    }
    echo "</select></td></tr>
    <tr><td width=\"20%\">";
    echo adm_translate("Description:")."
    </td>
    <td><textarea class=\"textbox\" name=\"xtext\" cols=\"70\" rows=\"20\" style=\"width: 100%;\"></textarea>";
    echo aff_editeur("xtext","false");
    echo "</td></tr>";
    echo "<tr><td colspan=\"2\" align=\"left\" valign=\"top\">";
    droits("");
    echo "</td></tr>
    </table><br />
    <input type=\"hidden\" name=\"op\" value=\"DownloadAdd\">
    <input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".adm_translate("Ajouter")."\">
    </form>";

    closetable();
    include("footer.php");
}

function DownloadEdit($did) {
    global $hlpfile;
    include ("header.php");
    GraphicAdmin($hlpfile);
    $result = mysql_query("select did, dcounter, durl, dfilename, dfilesize, ddate, dweb, duser, dver, dcategory, ddescription, perms from downloads where did='$did'");
    list($did, $dcounter, $durl, $dfilename, $dfilesize, $ddate, $dweb, $duser, $dver, $dcategory, $ddescription, $privs) = mysql_fetch_row($result);
    OpenTable();
    echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"HEADER\">\n";
    echo adm_translate("Editer un Téléchargement");
    echo "</td></tr></table>\n";
    echo "<form action=\"admin.php\" method=\"post\" name=\"adminForm\">
       <input type=\"hidden\" name=\"did\" value=\"$did\">
       <input type=\"hidden\" name=\"dcounter\" value=\"$dcounter\">
       <table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">
       <tr>
          <td width=\"20%\">".adm_translate("Télécharger URL : ")." (255 cars)</td>
          <td><input class=\"textbox\" type=\"text\" name=\"durl\" size=\"30\" maxlenght=\"255\" value=\"$durl\"></td>
       </tr>
       <tr>
          <td width=\"20%\">".adm_translate("Nom de fichier : ")." (255 cars)</td>
          <td><input class=\"textbox\" type=\"text\" name=\"dfilename\" size=\"30\" maxlength=\"255\" value=\"$dfilename\"></td>
       </tr>
       <tr>
          <td width=\"20%\">".adm_translate("Version : ")."</td>
          <td><input class=\"textbox_standard\" type=\"text\" name=\"dver\" size=\"5\" maxlength=\"6\" value=\"$dver\"></td>
       </tr>
       <tr>
          <td width=\"20%\">".adm_translate("Taille de fichier : ")." (bytes)</td>
          <td><input class=\"textbox_standard\" type=\"text\" name=\"dfilesize\" size=\"30\" maxlength=\"31\" value=\"$dfilesize\"></td>
       </tr>
       <tr>
          <td width=\"20%\">".adm_translate("Propriétaire de la page Web : ")." (255 cars)</td>
          <td><input class=\"textbox\" type=\"text\" name=\"dweb\" size=\"30\" maxlenght=\"255\" value=\"$dweb\"></td>
       </tr>
       <tr>
          <td width=\"20%\">".adm_translate("Propriétaire : ")."</td>
          <td><input class=\"textbox\" type=\"text\" name=\"duser\" size=\"30\" maxlength=\"31\" value=\"$duser\"></td>
       </tr>
       <tr>
          <td width=\"20%\">".adm_translate("Categorie : ")."</td>
          <td><input class=\"textbox_standard\" type=\"text\" name=\"dcategory\" size=\"50\" maxlength=\"250\" value=\"".stripslashes($dcategory)."\"> - ";
               echo "<select class=\"textbox_standard\" name=\"sdcategory\">";
               $result = mysql_query("select distinct dcategory from downloads order by dcategory");
               while (list($dcategory) = mysql_fetch_row($result)) {
                 $dcategory=stripslashes($dcategory);
                  echo "<option $sel value=\"$dcategory\">".aff_langue($dcategory)."</option>";
               }
               echo "</select>
          </td>
       </tr>
       <tr><td width=\"20%\">".adm_translate("Description:")."</td>";
       $ddescription=stripslashes($ddescription);
       echo "<td><textarea class=\"textbox\" name=\"xtext\" cols=\"70\" rows=\"20\" style=\"width: 100%;\">$ddescription</textarea>";
       echo aff_editeur("xtext","false");
       echo "</td></tr>
       <tr>
          <td width=\"20%\">".adm_translate("Changer la date ? : ")."</td>
          <td>".adm_translate("Oui")." <input type=\"checkbox\" name=\"ddate\" value=\"yes\"></td>
       </tr>";
       echo "<tr><td colspan=\"2\" align=\"center\" valign=\"top\">";
       droits($privs);
       echo "</td>
       </tr>
      </table><br />
      <input type=\"hidden\" name=\"op\" value=\"DownloadSave\">
      <input class=\"BOUTON_STANDARD\" type=\"submit\" value=\"".adm_translate("Sauver les modifications")."\">
      </form>";
    closetable();
    include("footer.php");
}

function DownloadSave($did, $dcounter, $durl, $dfilename, $dfilesize, $dweb, $duser, $ddate, $dver, $dcategory, $sdcategory, $description, $privs, $Mprivs) {
    if ($privs==1) {
       if ($Mprivs>1 and $Mprivs<=127 and $Mprivs!="") {$privs=$Mprivs;}
    }
    $sdcategory=addslashes($sdcategory);
    if (!$dcategory) {
       $dcategory = $sdcategory;
    } else {
       $dcategory=addslashes($dcategory);
    }
    $description=addslashes($description);
    if ($ddate=="yes") {
       $time = date("Y-m-d");
       mysql_query("update downloads set dcounter='$dcounter', durl='$durl', dfilename='$dfilename', dfilesize='$dfilesize', ddate='$time', dweb='$dweb', duser='$duser', dver='$dver', dcategory='$dcategory', ddescription='$description', perms='$privs' where did='$did'");
    } else {
       mysql_query("update downloads set dcounter='$dcounter', durl='$durl', dfilename='$dfilename', dfilesize='$dfilesize', dweb='$dweb', duser='$duser', dver='$dver', dcategory='$dcategory', ddescription='$description', perms='$privs' where did='$did'");
    }
    Header("Location: admin.php?op=DownloadAdmin");
}

function DownloadAdd($dcounter, $durl, $dfilename, $dfilesize, $dweb, $duser, $dver, $dcategory, $sdcategory, $description, $privs, $Mprivs) {
    if ($privs==1) {
       if ($Mprivs>1 and $Mprivs<=127 and $Mprivs!="") {$privs=$Mprivs;}
    }
    $sdcategory=addslashes($sdcategory);
    if (!$dcategory) {
       $dcategory = $sdcategory;
    } else {
       $dcategory=addslashes($dcategory);
    }
    $description=addslashes($description);
    $time = date("Y-m-d");
    if (($durl) and ($dfilename))
       mysql_query("insert into downloads values (NULL, '$dcounter', '$durl', '$dfilename', '$dfilesize', '$time', '$dweb', '$duser', '$dver', '$dcategory', '$description', '$privs')");
    Header("Location: admin.php?op=DownloadAdmin");
}

function DownloadDel($did, $ok=0) {
    if ($ok==1) {
       mysql_query("delete from downloads where did='$did'");
       Header("Location: admin.php?op=DownloadAdmin");
    } else {
       global $hlpfile;
       include("header.php");
       GraphicAdmin($hlpfile);
       OpenTable();
       echo "<br /><p align=\"center\">";
       echo "<span class=\"ROUGE\">";
       echo "<b>".adm_translate("ATTENTION :  êtes-vous sûr de vouloir supprimer ce fichier téléchargeable ?")."</b></span><br /><br />";
       echo "[ <a href=\"admin.php?op=DownloadDel&amp;did=$did&amp;ok=1\" class=\"ROUGE\">".adm_translate("Oui")."</a> | <a href=\"admin.php?op=DownloadAdmin\" class=\"NOIR\">".adm_translate("Non")."</a> ]</p><br /><br />";
       closetable();
       include("footer.php");
    }
}
?>