Skip to content
Snippets Groups Projects
Commit 3ee92a0d authored by Regis Houssin's avatar Regis Houssin
Browse files

Fix: mutualize code and template

Works on workflow management
parent 13d8d996
Branches
Tags
No related merge requests found
......@@ -23,6 +23,7 @@
*/
require("../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/core/interfaces.class.php");
if (!$user->admin)
accessforbidden();
......@@ -46,136 +47,12 @@ print_fiche_titre($langs->trans("TriggersAvailable"),'','setup');
print $langs->trans("TriggersDesc")."<br>";
print "<br>\n";
print "<table class=\"noborder\" width=\"100%\">\n";
print "<tr class=\"liste_titre\">\n";
print " <td colspan=\"2\">".$langs->trans("File")."</td>\n";
//print " <td>".$langs->trans("Description")."</td>\n";
print " <td align=\"center\">".$langs->trans("Version")."</td>\n";
print " <td align=\"center\">".$langs->trans("Active")."</td>\n";
print " <td align=\"center\">&nbsp;</td>\n";
print "</tr>\n";
$template_dir = DOL_DOCUMENT_ROOT.'/core/tpl/';
$interfaces = new Interfaces($db);
$triggers = $interfaces->getTriggersList(0);
$files = array();
$modules = array();
$orders = array();
$i = 0;
foreach($conf->triggers_modules as $dir)
{
// Check if directory exists
if (!is_dir($dir)) continue;
$handle=opendir($dir);
while (($file = readdir($handle))!==false)
{
if (is_readable($dir.'/'.$file) && preg_match('/^interface_([^_]+)_(.+)\.class\.php/',$file,$reg))
{
$modName = 'Interface'.ucfirst($reg[2]);
//print "file=$file"; print "modName=$modName"; exit;
if (in_array($modName,$modules))
{
$langs->load("errors");
print '<div class="error">'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/includes/triggers/").'</div>';
$objMod = new $modName($db);
$modules[$i] = $modName;
$files[$i] = $file;
$orders[$i] = $objMod->family; // Tri par famille
$i++;
}
else
{
include_once($dir.'/'.$file);
$objMod = new $modName($db);
$modules[$i] = $modName;
$files[$i] = $file;
$orders[$i] = $objMod->family; // Tri par famille
$i++;
}
}
}
closedir($handle);
}
asort($orders);
$var=True;
// Loop on each trigger
foreach ($orders as $key => $value)
{
$tab=explode('_',$value);
$family=$tab[0]; $numero=$tab[1];
$modName = $modules[$key];
if ($modName)
{
$objMod = new $modName($db);
}
$var=!$var;
// Define disabledbyname and disabledbymodule
$disabledbyname=0;
$disabledbymodule=1;
$module='';
if (preg_match('/NORUN$/i',$files[$key])) $disabledbyname=1;
if (preg_match('/^interface_([^_]+)_(.+)\.class\.php/i',$files[$key],$reg))
{
// Check if trigger file is for a particular module
$module=preg_replace('/^mod/i','',$reg[1]);
$constparam='MAIN_MODULE_'.strtoupper($module);
if (strtolower($reg[1]) == 'all') $disabledbymodule=0;
else if (empty($conf->global->$constparam)) $disabledbymodule=2;
}
// Show line for trigger file
print "<tr $bc[$var]>\n";
print '<td valign="top" width="14" align="center">';
print $objMod->picto?img_object('',$objMod->picto):img_object('','generic');
print '</td>';
print '<td valign="top">'.$files[$key]."</td>\n";
//print '<td valign="top">'.$objMod->getDesc()."</td>\n";
print "<td valign=\"top\" align=\"center\">".$objMod->getVersion()."</td>\n";
// Etat trigger
print "<td valign=\"top\" align=\"center\">";
if ($disabledbyname > 0 || $disabledbymodule > 1)
{
print "&nbsp;";
}
else
{
print img_tick();
}
print "</td>\n";
print '<td valign="top">';
$text ='<b>'.$langs->trans("Description").':</b><br>';
$text.=$objMod->getDesc().'<br>';
$text.='<br><b>'.$langs->trans("Status").':</b><br>';
if ($disabledbyname == 1)
{
$text.=$langs->trans("TriggerDisabledByName").'<br>';
if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'<br>';
}
else
{
if ($disabledbymodule == 0) $text.=$langs->trans("TriggerAlwaysActive").'<br>';
if ($disabledbymodule == 1) $text.=$langs->trans("TriggerActiveAsModuleActive",$module).'<br>';
if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'<br>';
}
print $html->textwithpicto('',$text);
print "</td>\n";
print "</tr>\n";
}
print "</table>\n";
include($template_dir.'triggers.tpl.php');
llxFooter('$Date$ - $Revision$');
?>
......@@ -156,5 +156,115 @@ class Interfaces
}
}
/**
* \brief Return list of triggers.
*/
function getTriggersList($workflow=0)
{
global $conf, $langs;
$html = new Form($db);
$files = array();
$modules = array();
$orders = array();
$i = 0;
foreach($conf->triggers_modules as $dir)
{
// Check if directory exists
if (!is_dir($dir)) continue;
$handle=opendir($dir);
while (($file = readdir($handle))!==false)
{
if (is_readable($dir.'/'.$file) && preg_match('/^interface_([^_]+)_(.+)\.class\.php/',$file,$reg))
{
$modName = 'Interface'.ucfirst($reg[2]);
//print "file=$file"; print "modName=$modName"; exit;
if (in_array($modName,$modules))
{
$langs->load("errors");
print '<div class="error">'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/includes/triggers/").'</div>';
$objMod = new $modName($db);
$modules[$i] = $modName;
$files[$i] = $file;
$orders[$i] = $objMod->family; // Tri par famille
$i++;
}
else
{
include_once($dir.'/'.$file);
$objMod = new $modName($db);
$modules[$i] = $modName;
$files[$i] = $file;
$orders[$i] = $objMod->family; // Tri par famille
$i++;
}
}
}
closedir($handle);
}
asort($orders);
$triggers = array();
$j = 0;
// Loop on each trigger
foreach ($orders as $key => $value)
{
$modName = $modules[$key];
if ($modName)
{
$objMod = new $modName($db);
// Bypass if workflow module is enabled and if the trigger is compatible
if ($workflow && !$objMod->workflow) continue;
}
// Define disabledbyname and disabledbymodule
$disabledbyname=0;
$disabledbymodule=1;
$module='';
if (preg_match('/NORUN$/i',$files[$key])) $disabledbyname=1;
if (preg_match('/^interface_([^_]+)_(.+)\.class\.php/i',$files[$key],$reg))
{
// Check if trigger file is for a particular module
$module=preg_replace('/^mod/i','',$reg[1]);
$constparam='MAIN_MODULE_'.strtoupper($module);
if (strtolower($reg[1]) == 'all') $disabledbymodule=0;
else if (empty($conf->global->$constparam)) $disabledbymodule=2;
}
$triggers[$j]['picto'] = $objMod->picto?img_object('',$objMod->picto):img_object('','generic');
$triggers[$j]['file'] = $files[$key];
$triggers[$j]['version'] = $objMod->getVersion();
$triggers[$j]['status'] = img_tick();
if ($disabledbyname > 0 || $disabledbymodule > 1) $triggers[$j]['status'] = "&nbsp;";
$text ='<b>'.$langs->trans("Description").':</b><br>';
$text.=$objMod->getDesc().'<br>';
$text.='<br><b>'.$langs->trans("Status").':</b><br>';
if ($disabledbyname == 1)
{
$text.=$langs->trans("TriggerDisabledByName").'<br>';
if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'<br>';
}
else
{
if ($disabledbymodule == 0) $text.=$langs->trans("TriggerAlwaysActive").'<br>';
if ($disabledbymodule == 1) $text.=$langs->trans("TriggerActiveAsModuleActive",$module).'<br>';
if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'<br>';
}
$triggers[$j]['info'] = $html->textwithpicto('',$text);
$j++;
}
return $triggers;
}
}
?>
<?php
/* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
*
* 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$
*/
?>
<!-- BEGIN PHP TEMPLATE -->
<table class="noborder" width="100%">
<tr class="liste_titre">
<td colspan="2"><?php echo $langs->trans("File"); ?></td>
<td align="center"><?php echo $langs->trans("Version"); ?></td>
<td align="center"><?php echo $langs->trans("Active"); ?></td>
<td align="center">&nbsp;</td>
</tr>
<?php
$var=True;
foreach ($triggers as $trigger) {
$var=!$var;
?>
<tr <?php echo $bc[$var]; ?>>
<td valign="top" width="14" align="center"><?php echo $trigger['picto']; ?></td>
<td valign="top"><?php echo $trigger['file']; ?></td>
<td valign="top" align="center"><?php echo $trigger['version']; ?></td>
<td valign="top" align="center"><?php echo $trigger['status']; ?></td>
<td valign="top"><?php echo $trigger['info']; ?></td>
</tr>
<?php } ?>
</table>
<!-- END PHP TEMPLATE -->
\ No newline at end of file
......@@ -25,12 +25,11 @@
require("../../main.inc.php");
//require_once(DOL_DOCUMENT_ROOT."/workflow/class/workflow.class.php");
require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php");
require_once(DOL_DOCUMENT_ROOT."/core/interfaces.class.php");
$langs->load("admin");
if (!$user->admin || $user->entity)
if (!$user->admin)
accessforbidden();
//$wf = new Workflow($db);
......@@ -50,10 +49,15 @@ llxHeader('',$langs->trans("WorkflowSetup"));
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print_fiche_titre($langs->trans("WorkflowSetup"),$linkback,'setup');
print '<br>';
print $langs->trans("TriggersDesc")."<br>";
print "<br>\n";
$template_dir = DOL_DOCUMENT_ROOT.'/workflow/tpl/';
$template_dir = DOL_DOCUMENT_ROOT.'/core/tpl/';
$interfaces = new Interfaces($db);
$triggers = $interfaces->getTriggersList(1);
include($template_dir.'triggers.tpl.php');
llxFooter('$Date$ - $Revision$');
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment