From 75312655f13138abb39322dd43a273868899d05c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Sun, 19 Feb 2012 13:12:11 +0100 Subject: [PATCH] Qual: More robust error code management when a box is renamed. --- htdocs/admin/boxes.php | 160 +++++++++--------- htdocs/boxes.php | 82 ++++----- ..._vendus.php => box_services_contracts.php} | 6 +- htdocs/core/modules/modService.class.php | 2 +- 4 files changed, 131 insertions(+), 119 deletions(-) rename htdocs/core/boxes/{box_services_vendus.php => box_services_contracts.php} (97%) diff --git a/htdocs/admin/boxes.php b/htdocs/admin/boxes.php index aae56c0a444..2e7a4bdde0c 100644 --- a/htdocs/admin/boxes.php +++ b/htdocs/admin/boxes.php @@ -294,56 +294,59 @@ if ($resql) } dol_include_once($sourcefile); - $box=new $boxname($db,$obj->note); - - $enabled=true; - if ($box->depends && count($box->depends) > 0) + if (class_exists($boxname)) { - foreach($box->depends as $module) - { - if (empty($conf->$module->enabled)) $enabled=false; - } - } - - if ($enabled) - { - //if (in_array($obj->rowid, $actives) && $box->box_multiple <> 1) - if (in_array($obj->rowid, $actives)) - { - // La boite est deja activee - } - else - { - $var=!$var; - - if (preg_match('/^([^@]+)@([^@]+)$/i',$box->boximg)) - { - $logo = $box->boximg; - } - else - { - $logo=preg_replace("/^object_/i","",$box->boximg); - } - - print "\n".'<!-- Box '.$box->boxcode.' -->'."\n"; - print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; - print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; - print '<tr '.$bc[$var].'>'; - print '<td>'.img_object("",$logo).' '.$box->boxlabel.'</td>'; - print '<td>' . ($obj->note?$obj->note:' ') . '</td>'; - print '<td>' . $sourcefile . '</td>'; - - // Pour chaque position possible, on affiche un lien - // d'activation si boite non deja active pour cette position - print '<td>'; - print $form->selectarray("pos",$pos_name); - print '<input type="hidden" name="action" value="add">'; - print '<input type="hidden" name="boxid" value="'.$obj->rowid.'">'; - print ' <input type="submit" class="button" name="button" value="'.$langs->trans("Activate").'">'; - print '</td>'; - - print '</tr></form>'; - } + $box=new $boxname($db,$obj->note); + + $enabled=true; + if ($box->depends && count($box->depends) > 0) + { + foreach($box->depends as $module) + { + if (empty($conf->$module->enabled)) $enabled=false; + } + } + + if ($enabled) + { + //if (in_array($obj->rowid, $actives) && $box->box_multiple <> 1) + if (in_array($obj->rowid, $actives)) + { + // La boite est deja activee + } + else + { + $var=!$var; + + if (preg_match('/^([^@]+)@([^@]+)$/i',$box->boximg)) + { + $logo = $box->boximg; + } + else + { + $logo=preg_replace("/^object_/i","",$box->boximg); + } + + print "\n".'<!-- Box '.$box->boxcode.' -->'."\n"; + print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; + print '<tr '.$bc[$var].'>'; + print '<td>'.img_object("",$logo).' '.$box->boxlabel.'</td>'; + print '<td>' . ($obj->note?$obj->note:' ') . '</td>'; + print '<td>' . $sourcefile . '</td>'; + + // Pour chaque position possible, on affiche un lien + // d'activation si boite non deja active pour cette position + print '<td>'; + print $form->selectarray("pos",$pos_name); + print '<input type="hidden" name="action" value="add">'; + print '<input type="hidden" name="boxid" value="'.$obj->rowid.'">'; + print ' <input type="submit" class="button" name="button" value="'.$langs->trans("Activate").'">'; + print '</td>'; + + print '</tr></form>'; + } + } } $i++; @@ -409,36 +412,39 @@ if ($resql) } dol_include_once($sourcefile); - $box=new $boxname($db,$obj->note); - - if (preg_match('/^([^@]+)@([^@]+)$/i',$box->boximg)) + if (class_exists($boxname)) { - $logo = $box->boximg; + $box=new $boxname($db,$obj->note); + + if (preg_match('/^([^@]+)@([^@]+)$/i',$box->boximg)) + { + $logo = $box->boximg; + } + else + { + $logo=preg_replace("/^object_/i","",$box->boximg); + } + + print "\n".'<!-- Box '.$box->boxcode.' -->'."\n"; + print '<tr '.$bc[$var].'>'; + print '<td>'.img_object("",$logo).' '.$box->boxlabel.'</td>'; + print '<td>' . ($obj->note?$obj->note:' ') . '</td>'; + print '<td align="center">' . $pos_name[$obj->position] . '</td>'; + $hasnext=true; + $hasprevious=true; + if ($foundrupture) { $hasprevious=false; $foundrupture=0; } + if (! $objnext || $obj->position != $objnext->position) { $hasnext=false; $foundrupture=1; } + print '<td align="center">'.$box_order.'</td>'; + print '<td align="center">'; + print ($hasnext?'<a href="boxes.php?action=switch&switchfrom='.$obj->rowid.'&switchto='.$objnext->rowid.'">'.img_down().'</a> ':''); + print ($hasprevious?'<a href="boxes.php?action=switch&switchfrom='.$obj->rowid.'&switchto='.$objprevious->rowid.'">'.img_up().'</a>':''); + print '</td>'; + print '<td align="center">'; + print '<a href="boxes.php?rowid='.$obj->rowid.'&action=delete">'.img_delete().'</a>'; + print '</td>'; + + print '</tr>'."\n"; } - else - { - $logo=preg_replace("/^object_/i","",$box->boximg); - } - - print "\n".'<!-- Box '.$box->boxcode.' -->'."\n"; - print '<tr '.$bc[$var].'>'; - print '<td>'.img_object("",$logo).' '.$box->boxlabel.'</td>'; - print '<td>' . ($obj->note?$obj->note:' ') . '</td>'; - print '<td align="center">' . $pos_name[$obj->position] . '</td>'; - $hasnext=true; - $hasprevious=true; - if ($foundrupture) { $hasprevious=false; $foundrupture=0; } - if (! $objnext || $obj->position != $objnext->position) { $hasnext=false; $foundrupture=1; } - print '<td align="center">'.$box_order.'</td>'; - print '<td align="center">'; - print ($hasnext?'<a href="boxes.php?action=switch&switchfrom='.$obj->rowid.'&switchto='.$objnext->rowid.'">'.img_down().'</a> ':''); - print ($hasprevious?'<a href="boxes.php?action=switch&switchfrom='.$obj->rowid.'&switchto='.$objprevious->rowid.'">'.img_up().'</a>':''); - print '</td>'; - print '<td align="center">'; - print '<a href="boxes.php?rowid='.$obj->rowid.'&action=delete">'.img_delete().'</a>'; - print '</td>'; - - print '</tr>'."\n"; $i++; $box_order++; diff --git a/htdocs/boxes.php b/htdocs/boxes.php index 84e899f8290..77c63b8bce1 100644 --- a/htdocs/boxes.php +++ b/htdocs/boxes.php @@ -54,7 +54,7 @@ function printBoxesArea($user,$areacode) // Define $box_max_lines $box_max_lines=5; if (! empty($conf->global->MAIN_BOXES_MAXLINES)) $box_max_lines=$conf->global->MAIN_BOXES_MAXLINES; - + $ii=0; foreach ($boxarray as $key => $box) { @@ -214,24 +214,27 @@ class InfoBox $sourcefile = DOL_DOCUMENT_ROOT."/core/boxes/".$boxname.".php"; } - include_once($sourcefile); - $box=new $boxname($this->db,$obj->note); - - $box->rowid=$obj->rowid; - $box->box_id=$obj->box_id; - $box->position=$obj->position; - $box->box_order=$obj->box_order; - $box->fk_user=$obj->fk_user; - $enabled=true; - if ($box->depends && count($box->depends) > 0) + dol_include_once($sourcefile); + if (class_exists($boxname)) { - foreach($box->depends as $module) - { - //print $module.'<br>'; - if (empty($conf->$module->enabled)) $enabled=false; - } + $box=new $boxname($this->db,$obj->note); + + $box->rowid=$obj->rowid; + $box->box_id=$obj->box_id; + $box->position=$obj->position; + $box->box_order=$obj->box_order; + $box->fk_user=$obj->fk_user; + $enabled=true; + if ($box->depends && count($box->depends) > 0) + { + foreach($box->depends as $module) + { + //print $module.'<br>'; + if (empty($conf->$module->enabled)) $enabled=false; + } + } + if ($enabled) $boxes[]=$box; } - if ($enabled) $boxes[]=$box; $j++; } } @@ -277,28 +280,31 @@ class InfoBox } dol_include_once($sourcefile); - $box=new $boxname($this->db,$obj->note); - - $box->rowid=$obj->rowid; - $box->box_id=$obj->box_id; - $box->position=$obj->position; - $box->box_order=$obj->box_order; - if (is_numeric($box->box_order)) + if (class_exists($boxname)) { - if ($box->box_order % 2 == 1) $box->box_order='A'.$box->box_order; - elseif ($box->box_order % 2 == 0) $box->box_order='B'.$box->box_order; + $box=new $boxname($this->db,$obj->note); + + $box->rowid=$obj->rowid; + $box->box_id=$obj->box_id; + $box->position=$obj->position; + $box->box_order=$obj->box_order; + if (is_numeric($box->box_order)) + { + if ($box->box_order % 2 == 1) $box->box_order='A'.$box->box_order; + elseif ($box->box_order % 2 == 0) $box->box_order='B'.$box->box_order; + } + $box->fk_user=$obj->fk_user; + $enabled=true; + if ($box->depends && count($box->depends) > 0) + { + foreach($box->depends as $module) + { + //print $boxname.'-'.$module.'<br>'; + if (empty($conf->$module->enabled)) $enabled=false; + } + } + if ($enabled) $boxes[]=$box; } - $box->fk_user=$obj->fk_user; - $enabled=true; - if ($box->depends && count($box->depends) > 0) - { - foreach($box->depends as $module) - { - //print $boxname.'-'.$module.'<br>'; - if (empty($conf->$module->enabled)) $enabled=false; - } - } - if ($enabled) $boxes[]=$box; $j++; } } @@ -328,7 +334,7 @@ class InfoBox global $conf; $error=0; - + require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php"); dol_syslog("InfoBoxes::saveboxorder zone=".$zone." user=".$userid); diff --git a/htdocs/core/boxes/box_services_vendus.php b/htdocs/core/boxes/box_services_contracts.php similarity index 97% rename from htdocs/core/boxes/box_services_vendus.php rename to htdocs/core/boxes/box_services_contracts.php index 263b0fa360f..eccb1af797c 100644 --- a/htdocs/core/boxes/box_services_vendus.php +++ b/htdocs/core/boxes/box_services_contracts.php @@ -18,7 +18,7 @@ */ /** - * \file htdocs/core/boxes/box_services_vendus.php + * \file htdocs/core/boxes/box_services_contracts.php * \ingroup produits,services * \brief Module de generation de l'affichage de la box services_vendus */ @@ -29,7 +29,7 @@ include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"); /** * Class to manage the box to show last services lines */ - class box_services_vendus extends ModeleBoxes + class box_services_contracts extends ModeleBoxes { var $boxcode="lastproductsincontract"; @@ -46,7 +46,7 @@ include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"); /** * Constructor */ - function box_services_vendus() + function box_services_contracts() { global $langs; $langs->load("boxes"); diff --git a/htdocs/core/modules/modService.class.php b/htdocs/core/modules/modService.class.php index a3be276d64d..860de81b81f 100644 --- a/htdocs/core/modules/modService.class.php +++ b/htdocs/core/modules/modService.class.php @@ -77,7 +77,7 @@ class modService extends DolibarrModules // Boxes $this->boxes = array(); - $this->boxes[0][1] = "box_services_vendus.php"; + $this->boxes[0][1] = "box_services_contracts.php"; // Permissions $this->rights = array(); -- GitLab