<?php
/************************************************************************/
/* DUNE by NPDS                                                         */
/* ===========================                                          */
/*                                                                      */
/* This version name NPDS Copyright (c) 2001-2011 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.       */
/************************************************************************/
/************************************************************************/
/* Module-Install Version 1.1 - Mai 2005                                */
/* --------------------------                                           */
/* Copyright (c) 2005 Boris L'Ordi-Dépanneur & Hotfirenet               */
/*                                                                      */
/* Version 1.2 - 22 Avril 2009                                          */
/* --------------------------                                           */
/*                                                                      */
/* Modifié par jpb et phr pour le rendre compatible avec Evolution      */
/*                                                                      */
/************************************************************************/
function Access_Error () {
  include("admin/die.php");
}
if (!stristr($_SERVER['PHP_SELF'],"admin.php")) { Access_Error(); }
global $language;

$result = sql_query("select radminsuper from ".$NPDS_Prefix."authors where aid='$aid'");
list($radminsuper) = sql_fetch_row($result);
if ($radminsuper!=1) {
   Access_Error();
}
   include("header.php");
   GraphicAdmin($hlpfile);
   opentable();
   $handle=opendir('modules');
   $modlist="";
   while (false!==($file=readdir($handle))) {
      if (!@file_exists("modules/$file/kernel")) {
        if (is_dir("modules/$file") and ($file!=".") and ($file!=".."))
           $modlist.="$file ";
      }
   }
   closedir($handle);
   $modlist=explode(" ",rtrim($modlist));
   sort($modlist);
   for ($i=0; $i<count($modlist); $i++) {
      $queryexiste=sql_query("select mnom from ".$NPDS_Prefix."modules where mnom='".$modlist[$i]."'");
      if ($queryexiste)
         $moexiste=sql_num_rows($queryexiste);
      if ((!empty($modlist[$i])) && ($moexiste!=1)) {
         sql_query("insert into ".$NPDS_Prefix."modules values (NULL, '".$modlist[$i]."', '0')");
      }
   }
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
   echo adm_translate("Gestion, Installation Modules");
   echo "</td></tr></table>\n";
   echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">";
   echo "<tr><td width=\"10%\" align=\"center\"><b>ID</b></td><td align=\"left\"><b>".adm_translate("Nom")."</b></td><td align=\"left\"><b>".adm_translate("Fonctions")."</b></td></tr>\n";
   $result = sql_query("SELECT * FROM ".$NPDS_Prefix."modules ORDER BY mid");
   while ($row = sql_fetch_assoc($result)) {
       if ($row["minstall"] == 0) {
          if (file_exists("modules/".$row["mnom"]."/install.conf.php")) {
             $status_chngac = "<a href=\"admin.php?op=Module-Install&amp;ModInstall=".$row["mnom"]."\" class=\"noir\">".adm_translate("Installer le module")."</a>";
          } else {
             $status_chngac = "<span class=\"noir\">".adm_translate("Pas d'installeur disponible")."</span>&nbsp;&nbsp;[&nbsp;<a href=\"admin.php?op=Module-Install&amp;ModInstall=".$row["mnom"]."&amp;subop=install\" class=\"noir\">".adm_translate("Marquer le module comme installé")."</a>&nbsp;]";
          }
       } else {
          $status_chngac = "<a href=\"admin.php?op=Module-Install&amp;ModDesinstall=".$row["mnom"]."\" class=\"rouge\">".adm_translate("Désinstaller le module")."</a>&nbsp;";
       }
       $rowcolor=tablos();
       echo "<tr $rowcolor>
       <td align=\"center\">".$row["mid"]."</td>
       <td align=\"left\">".$row["mnom"]."</td>
       <td align=\"left\">".$status_chngac."</td>
       </tr>\n";
   }
   echo "</table>\n";
   closetable();
   include("footer.php");
?>