dolibarr/htdocs/admin/modules.php

311 lines
7.8 KiB
PHP
Raw Normal View History

<?php
/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 <EFBFBD>ric Seigne <eric.seigne@ryxeo.com>
2003-03-11 17:18:54 +01:00
*
* 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, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/
2004-10-23 00:42:10 +02:00
2005-04-07 00:36:44 +02:00
/**
\file htdocs/admin/modules.php
\brief Page de configuration et activation des modules
\version $Revision$
*/
2003-03-11 17:18:54 +01:00
require("./pre.inc.php");
if (!$user->admin)
2004-10-23 00:42:10 +02:00
accessforbidden();
2003-03-11 17:18:54 +01:00
if ($_GET["action"] == 'set' && $user->admin)
2003-03-11 17:18:54 +01:00
{
2004-10-23 00:42:10 +02:00
Activate($_GET["value"]);
2004-10-23 00:42:10 +02:00
Header("Location: modules.php?spe=".$_GET["spe"]);
}
if ($_GET["action"] == 'reset' && $user->admin)
{
2004-10-23 00:42:10 +02:00
UnActivate($_GET["value"]);
2004-10-23 00:42:10 +02:00
Header("Location: modules.php?spe=".$_GET["spe"]);
}
/** \brief Active un module
\param value Nom du module a activer
*/
function Activate($value)
{
2004-10-23 00:42:10 +02:00
global $db, $modules;
2004-10-23 00:42:10 +02:00
$modName = $value;
2003-03-11 17:18:54 +01:00
2004-10-23 00:42:10 +02:00
// Activation du module
if ($modName)
2003-03-11 17:18:54 +01:00
{
2004-10-23 00:42:10 +02:00
$file = $modName . ".class.php";
include_once("../includes/modules/$file");
$objMod = new $modName($db);
$objMod->init();
2003-03-11 17:18:54 +01:00
}
2004-10-23 00:42:10 +02:00
// Activation des modules dont le module d<>pend
for ($i = 0; $i < sizeof($objMod->depends); $i++)
{
2004-10-23 00:42:10 +02:00
Activate($objMod->depends[$i]);
}
2003-03-11 17:18:54 +01:00
}
/** \brief D<EFBFBD>sactive un module
\param value Nom du module a d<EFBFBD>sactiver
*/
function UnActivate($value)
2003-03-11 17:18:54 +01:00
{
2004-10-23 00:42:10 +02:00
global $db, $modules;
2004-10-23 00:42:10 +02:00
$modName = $value;
2003-03-11 17:18:54 +01:00
2004-10-23 00:42:10 +02:00
// Desactivation du module
if ($modName)
2003-03-11 17:18:54 +01:00
{
2004-10-23 00:42:10 +02:00
$file = $modName . ".class.php";
include_once("../includes/modules/$file");
$objMod = new $modName($db);
$objMod->remove();
2003-03-11 17:18:54 +01:00
}
2003-11-13 16:09:12 +01:00
2004-10-23 00:42:10 +02:00
// Desactivation des modules qui dependent de lui
for ($i = 0; $i < sizeof($objMod->requiredby); $i++)
{
2004-10-23 00:42:10 +02:00
UnActivate($objMod->requiredby[$i]);
}
2004-10-23 00:42:10 +02:00
Header("Location: modules.php");
2003-03-11 17:18:54 +01:00
}
2004-10-23 00:42:10 +02:00
2005-01-02 16:12:22 +01:00
llxHeader("","");
if (!$_GET["spe"])
{
$hselected = 0;
}
else
{
$hselected = 1;
}
$h = 0;
$head[$h][0] = DOL_URL_ROOT."/admin/modules.php?spe=0";
$head[$h][1] = $langs->trans("ModulesCommon");
$h++;
$head[$h][0] = DOL_URL_ROOT."/admin/modules.php?spe=1";
$head[$h][1] = $langs->trans("ModulesSpecial");
$h++;
dolibarr_fiche_head($head, $hselected, $langs->trans("Modules"));
if (!$_GET["spe"])
{
2004-11-23 18:49:52 +01:00
print $langs->trans("ModulesDesc")."<br>\n";
}
else
{
2004-11-23 18:49:52 +01:00
print $langs->trans("ModulesSpecialDesc")."<br>\n";
}
2003-03-11 17:18:54 +01:00
print "<br>\n";
print "<table class=\"noborder\" width=\"100%\">\n";
print "<tr class=\"liste_titre\">\n";
print " <td>".$langs->trans("Family")."</td>\n";
2005-03-06 01:15:34 +01:00
print " <td colspan=\"2\">".$langs->trans("Module")."</td>\n";
print " <td>".$langs->trans("Description")."</td>\n";
print " <td align=\"center\">".$langs->trans("Version")."</td>\n";
print " <td align=\"center\">".$langs->trans("Activated")."</td>\n";
print " <td align=\"center\">".$langs->trans("Action")."</td>\n";
print " <td>&nbsp;</td>\n";
2003-11-13 16:09:12 +01:00
print "</tr>\n";
$dir = DOL_DOCUMENT_ROOT . "/includes/modules/";
$handle=opendir($dir);
$modules = array();
$i = 0;
$j = 0;
while (($file = readdir($handle))!==false)
{
2004-10-23 00:42:10 +02:00
if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, strlen($file) - 10) == '.class.php')
2003-11-13 16:09:12 +01:00
{
2004-10-23 00:42:10 +02:00
$modName = substr($file, 0, strlen($file) - 10);
if ($modName)
{
include_once("../includes/modules/$file");
$objMod = new $modName($db);
if ($objMod->numero > 0)
{
$j = $objMod->numero;
}
else
{
$j = 1000 + $i;
}
$modules[$i] = $modName;
$numero[$i] = $j;
$orders[$i] = "$objMod->family"."_".$j; // Tri par famille puis numero module
$j++;
$i++;
}
2003-11-13 16:09:12 +01:00
}
}
2003-03-11 17:18:54 +01:00
asort($orders);
$var=True;
2003-11-13 16:09:12 +01:00
$familylib=array(
'crm'=>$langs->trans("ModuleFamilyCrm"),
'products'=>$langs->trans("ModuleFamilyProducts"),
'hr'=>$langs->trans("ModuleFamilyHr"),
'projects'=>$langs->trans("ModuleFamilyProjects"),
'other'=>$langs->trans("ModuleFamilyOther"),
'technic'=>$langs->trans("ModuleFamilyTechnic"),
2004-09-22 12:08:50 +02:00
'financial'=>$langs->trans("ModuleFamilyFinancial"),
'experimental'=>$langs->trans("ModuleFamilyExperimental")
);
2003-11-13 16:09:12 +01:00
foreach ($orders as $key => $value)
2003-03-11 17:18:54 +01:00
{
2004-10-23 00:42:10 +02:00
$tab=split('_',$value);
$family=$tab[0]; $numero=$tab[1];
2004-10-23 00:42:10 +02:00
$modName = $modules[$key];
if ($modName)
{
2004-10-23 00:42:10 +02:00
$objMod = new $modName($db);
}
2004-10-23 00:42:10 +02:00
$const_name = $objMod->const_name;
$const_value = $objMod->const_config;
2004-10-23 00:42:10 +02:00
if ($oldfamily && $family!=$oldfamily && $atleastoneforfamily) {
2005-03-06 01:15:34 +01:00
print "<tr class=\"liste_titre\">\n <td colspan=\"8\"></td>\n</tr>\n";
2004-10-23 00:42:10 +02:00
$atleastoneforfamily=0;
2003-03-11 17:18:54 +01:00
}
2004-10-23 00:42:10 +02:00
if((!$objMod->special && !$_GET["spe"] ) or ($objMod->special && $_GET["spe"]))
{
2004-10-23 00:42:10 +02:00
$atleastoneforfamily=1;
$var=!$var;
print "<tr $bc[$var]>\n";
2005-04-07 00:36:44 +02:00
print " <td class=\"body\" valign=\"top\">";
if ($family!=$oldfamily)
{
print "<div class=\"titre\">".$familylib[$family]."</div>";
$oldfamily=$family;
}
else
{
print '&nbsp;';
}
print "</td>\n";
2005-03-06 01:15:34 +01:00
print ' <td valign="top" width="14" align="center">';
print $objMod->picto?img_object('',$objMod->picto):img_object('','generic');
print '</td><td valign="top">'.$objMod->getName();
print "</td>\n <td valign=\"top\">";
print $objMod->getDesc();
print "</td>\n <td align=\"center\">";
print $objMod->getVersion();
print "</td>\n <td align=\"center\">";
2004-10-23 00:42:10 +02:00
if ($const_value == 1)
{
2005-03-06 16:39:32 +01:00
print img_tick();
}
2004-10-23 00:42:10 +02:00
else
{
2004-10-23 00:42:10 +02:00
print "&nbsp;";
}
print "</td>\n <td align=\"center\">";
2004-10-23 00:42:10 +02:00
if ($const_value == 1)
{
// Module actif
print "<a href=\"modules.php?id=".$objMod->numero."&amp;action=reset&amp;value=" . $modName . "&amp;spe=" . $_GET["spe"] . "\">" . $langs->trans("Disable") . "</a></td>\n";
2004-10-23 00:42:10 +02:00
if ($objMod->config_page_url)
{
if (is_array($objMod->config_page_url)) {
print " <td>";
2004-10-23 00:42:10 +02:00
$i=0;
foreach ($objMod->config_page_url as $page)
{
if ($i++)
{
print '<a href="'.$page.'">'.ucfirst($page).'</a>&nbsp;';
}
else
{
print '<a href="'.$page.'">'.$langs->trans("Setup").'</a>&nbsp;';
}
}
print "</td>\n";
2004-10-23 00:42:10 +02:00
}
else
{
print ' <td><a href="'.$objMod->config_page_url.'">'.$langs->trans("Setup").'</a></td>';
}
2004-10-23 00:42:10 +02:00
}
else
{
print " <td>&nbsp;</td>";
}
2004-10-23 00:42:10 +02:00
}
else
{
// Module non actif
print "<a href=\"modules.php?id=".$objMod->numero."&amp;action=set&amp;value=" . $modName . "&amp;spe=" . $_GET["spe"] . "\">" . $langs->trans("Activate") . "</a></td>\n <td>&nbsp;</td>\n";
}
print "</tr>\n";
}
2004-10-23 00:42:10 +02:00
}
print "</table></div>\n";
2004-10-23 00:42:10 +02:00
2003-03-11 17:18:54 +01:00
llxFooter();
?>