From 3ee92a0de31e43843d364c23be858a2907fba108 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 22 Apr 2010 18:37:42 +0000 Subject: [PATCH] Fix: mutualize code and template Works on workflow management --- htdocs/admin/triggers.php | 133 ++--------------------------- htdocs/core/interfaces.class.php | 110 ++++++++++++++++++++++++ htdocs/core/tpl/triggers.tpl.php | 52 +++++++++++ htdocs/workflow/admin/workflow.php | 14 +-- 4 files changed, 176 insertions(+), 133 deletions(-) create mode 100644 htdocs/core/tpl/triggers.tpl.php diff --git a/htdocs/admin/triggers.php b/htdocs/admin/triggers.php index e2572420197..60d663f891e 100644 --- a/htdocs/admin/triggers.php +++ b/htdocs/admin/triggers.php @@ -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")."
"; print "
\n"; -print "\n"; -print "\n"; -print " \n"; -//print " \n"; -print " \n"; -print " \n"; -print " \n"; -print "\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 '
'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/includes/triggers/").'
'; - $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 "\n"; - - print ''; - print '\n"; - //print '\n"; - print "\n"; - - // Etat trigger - print "\n"; - - print '\n"; - - print "\n"; - -} -print "
".$langs->trans("File")."".$langs->trans("Description")."".$langs->trans("Version")."".$langs->trans("Active")." 
'; - print $objMod->picto?img_object('',$objMod->picto):img_object('','generic'); - print ''.$files[$key]."'.$objMod->getDesc()."".$objMod->getVersion().""; - if ($disabledbyname > 0 || $disabledbymodule > 1) - { - print " "; - } - else - { - print img_tick(); - } - print "'; - $text =''.$langs->trans("Description").':
'; - $text.=$objMod->getDesc().'
'; - $text.='
'.$langs->trans("Status").':
'; - if ($disabledbyname == 1) - { - $text.=$langs->trans("TriggerDisabledByName").'
'; - if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'
'; - } - else - { - if ($disabledbymodule == 0) $text.=$langs->trans("TriggerAlwaysActive").'
'; - if ($disabledbymodule == 1) $text.=$langs->trans("TriggerActiveAsModuleActive",$module).'
'; - if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'
'; - } - print $html->textwithpicto('',$text); - print "
\n"; - +include($template_dir.'triggers.tpl.php'); llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/core/interfaces.class.php b/htdocs/core/interfaces.class.php index 342c6885ca9..8968a552534 100644 --- a/htdocs/core/interfaces.class.php +++ b/htdocs/core/interfaces.class.php @@ -155,6 +155,116 @@ class Interfaces return $nbok; } } + + /** + * \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 '
'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/includes/triggers/").'
'; + $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'] = " "; + + $text =''.$langs->trans("Description").':
'; + $text.=$objMod->getDesc().'
'; + $text.='
'.$langs->trans("Status").':
'; + if ($disabledbyname == 1) + { + $text.=$langs->trans("TriggerDisabledByName").'
'; + if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'
'; + } + else + { + if ($disabledbymodule == 0) $text.=$langs->trans("TriggerAlwaysActive").'
'; + if ($disabledbymodule == 1) $text.=$langs->trans("TriggerActiveAsModuleActive",$module).'
'; + if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'
'; + } + + $triggers[$j]['info'] = $html->textwithpicto('',$text); + $j++; + } + return $triggers; + } } ?> diff --git a/htdocs/core/tpl/triggers.tpl.php b/htdocs/core/tpl/triggers.tpl.php new file mode 100644 index 00000000000..58d91487976 --- /dev/null +++ b/htdocs/core/tpl/triggers.tpl.php @@ -0,0 +1,52 @@ + + * + * 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$ + */ +?> + + + + + + + + + + + + + +> + + + + + + + + + + + +
trans("File"); ?>trans("Version"); ?>trans("Active"); ?> 
+ + \ No newline at end of file diff --git a/htdocs/workflow/admin/workflow.php b/htdocs/workflow/admin/workflow.php index 0ccf0bf6a62..6058a4f3add 100644 --- a/htdocs/workflow/admin/workflow.php +++ b/htdocs/workflow/admin/workflow.php @@ -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=''.$langs->trans("BackToModuleList").''; print_fiche_titre($langs->trans("WorkflowSetup"),$linkback,'setup'); -print '
'; +print $langs->trans("TriggersDesc")."
"; +print "
\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