From fb33dd6801be57c228d3a63c13c84ce68eea59aa Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 19 Mar 2012 15:51:55 +0100 Subject: [PATCH] Qual: Move class file into class dir Qual: Utility methods must be static. --- htdocs/admin/boxes.php | 8 +- htdocs/core/ajax/box.php | 6 +- htdocs/core/class/html.formother.class.php | 175 +++++++++++++- .../class/infobox.class.php} | 228 ++---------------- htdocs/index.php | 4 +- 5 files changed, 205 insertions(+), 216 deletions(-) rename htdocs/{boxes.php => core/class/infobox.class.php} (51%) diff --git a/htdocs/admin/boxes.php b/htdocs/admin/boxes.php index fff4bab9491..8b2a12a7217 100644 --- a/htdocs/admin/boxes.php +++ b/htdocs/admin/boxes.php @@ -24,8 +24,8 @@ require("../main.inc.php"); include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/infobox.class.php"); include_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"); -require_once(DOL_DOCUMENT_ROOT."/boxes.php"); $langs->load("admin"); @@ -198,7 +198,7 @@ if ($action == 'switch') $form=new Form($db); $emptyuser=new User($db); -$infobox=new InfoBox($db); +//$infobox=new InfoBox($db); llxHeader('',$langs->trans("Boxes")); @@ -301,7 +301,7 @@ if ($resql) // Available boxes -$boxtoadd=$infobox->listboxes('available',-1,$emptyuser,$actives); +$boxtoadd=InfoBox::listboxes($db,'available',-1,$emptyuser,$actives); print "
\n"; print_titre($langs->trans("BoxesAvailable")); @@ -351,7 +351,7 @@ print ''; // Activated boxes -$boxactivated=$infobox->listboxes('activated',-1,$emptyuser); +$boxactivated=InfoBox::listboxes($db,'activated',-1,$emptyuser); print "
\n\n"; print_titre($langs->trans("BoxesActivated")); diff --git a/htdocs/core/ajax/box.php b/htdocs/core/ajax/box.php index e4c5a86c338..1c8eaf513f0 100644 --- a/htdocs/core/ajax/box.php +++ b/htdocs/core/ajax/box.php @@ -29,7 +29,7 @@ if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); require('../../main.inc.php'); -require_once(DOL_DOCUMENT_ROOT."/boxes.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/infobox.class.php"); $boxid=GETPOST('boxid','int'); $boxorder=GETPOST('boxorder'); @@ -63,8 +63,8 @@ if ($boxorder && $zone != '' && $userid > 0) // boxorder value is the target order: "A:idboxA1,idboxA2,A-B:idboxB1,idboxB2,B" dol_syslog("AjaxBox boxorder=".$boxorder." zone=".$zone." userid=".$userid, LOG_DEBUG); - $infobox=new InfoBox($db); - $result=$infobox->saveboxorder($zone,$boxorder,$userid); + //$infobox=new InfoBox($db); + $result=InfoBox::saveboxorder($db,$zone,$boxorder,$userid); } ?> diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 5d53a352b68..e2d7ed35ea8 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -734,7 +734,7 @@ class FormOther { global $langs,$conf; global $form; - + if ($htmlname != "none") { print '
'; @@ -765,6 +765,179 @@ class FormOther } } + + + + /** + * Show a HTML Tab with boxes of a particular area including personalized choices of user + * + * @param User $user Object User + * @param String $areacode Code of area for pages (0=value for Home page) + * @return int <0 if KO, Nb of boxes shown of OK (0 to n) + */ + static function printBoxesArea($user,$areacode) + { + global $conf,$langs,$db; + + include_once(DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php'); + + //$infobox=new InfoBox($db); + $boxactivated=InfoBox::listboxes($db,'activated',$areacode,$user); + $arrayboxactivatedid=array(); + foreach($boxactivated as $box) $arrayboxactivatedid[$box->id]=$box->id; + + $selectboxlist=''; + if ($conf->use_javascript_ajax) + { + $emptyuser=new User($db); + $boxavailable=InfoBox::listboxes($db,'activated',$areacode,$emptyuser,$arrayboxactivatedid); // Available here is activated for empty user + + $arrayboxtoactivatelabel=array(); + foreach($boxavailable as $box) + { + $arrayboxtoactivatelabel[$box->id]=$box->boxlabel; + } + $form=new Form($db); + + $selectboxlist=$form->selectarray('boxcombo', $arrayboxtoactivatelabel,'',1); + } + + print ''; + + print load_fiche_titre((count($boxactivated)?$langs->trans("OtherInformationsBoxes"):''),$selectboxlist,'','','otherboxes'); + + if (count($boxactivated)) + { + print ''; + print '"; + print "
'."\n"; + + print '
'; + + print "\n\n"; + print '
'."\n"; + + // 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 ($boxactivated as $key => $box) + { + if (preg_match('/^A/i',$box->box_order)) // column A + { + $ii++; + //print 'box_id '.$boxactivated[$ii]->box_id.' '; + //print 'box_order '.$boxactivated[$ii]->box_order.'
'; + // Affichage boite key + $box->loadBox($box_max_lines); + $box->showBox(); + } + } + + $emptybox=new ModeleBoxes($db); + $emptybox->box_id='A'; + $emptybox->info_box_head=array(); + $emptybox->info_box_contents=array(); + $emptybox->showBox(array(),array()); + + print "
\n"; + print "\n"; + + print '
'; + + print "\n\n"; + print '\n"; + print "\n"; + + print '
'; + print "\n"; + + print "
"; + + if ($conf->use_javascript_ajax) + { + print "\n"; + print ''."\n"; + } + } + + return count($boxactivated); + } + + } ?> diff --git a/htdocs/boxes.php b/htdocs/core/class/infobox.class.php similarity index 51% rename from htdocs/boxes.php rename to htdocs/core/class/infobox.class.php index 4104448a25b..7baf404e808 100644 --- a/htdocs/boxes.php +++ b/htdocs/core/class/infobox.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2011 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -18,199 +18,15 @@ */ /** - * \file htdocs/boxes.php + * \file htdocs/core/class/infobox.php * \brief File of class to manage widget boxes */ - - -/** - * Show a HTML Tab with boxes of a particular area including personalized choices of user - * - * @param User $user Object User - * @param String $areacode Code of area for pages (0=value for Home page) - * @return int <0 if KO, Nb of boxes shown of OK (0 to n) - */ -function printBoxesArea($user,$areacode) -{ - global $conf,$langs,$db; - - $infobox=new InfoBox($db); - $boxactivated=$infobox->listboxes('activated',$areacode,$user); - $arrayboxactivatedid=array(); - foreach($boxactivated as $box) $arrayboxactivatedid[$box->id]=$box->id; - - $selectboxlist=''; - if ($conf->use_javascript_ajax) - { - $emptyuser=new User($db); - $boxavailable=$infobox->listboxes('activated',$areacode,$emptyuser,$arrayboxactivatedid); // Available here is activated for empty user - - $arrayboxtoactivatelabel=array(); - foreach($boxavailable as $box) - { - $arrayboxtoactivatelabel[$box->id]=$box->boxlabel; - } - $form=new Form($db); - - $selectboxlist=$form->selectarray('boxcombo', $arrayboxtoactivatelabel,'',1); - } - - print ''; - - print load_fiche_titre((count($boxactivated)?$langs->trans("OtherInformationsBoxes"):''),$selectboxlist,'','','otherboxes'); - - if (count($boxactivated)) - { - print ''; - print '"; - print "
'."\n"; - - print '
'; - - print "\n\n"; - print '
'."\n"; - - // 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 ($boxactivated as $key => $box) - { - if (preg_match('/^A/i',$box->box_order)) // column A - { - $ii++; - //print 'box_id '.$boxactivated[$ii]->box_id.' '; - //print 'box_order '.$boxactivated[$ii]->box_order.'
'; - // Affichage boite key - $box->loadBox($box_max_lines); - $box->showBox(); - } - } - - $emptybox=new ModeleBoxes($db); - $emptybox->box_id='A'; - $emptybox->info_box_head=array(); - $emptybox->info_box_contents=array(); - $emptybox->showBox(array(),array()); - - print "
\n"; - print "\n"; - - print '
'; - - print "\n\n"; - print '\n"; - print "\n"; - - print '
'; - print "\n"; - - print "
"; - - if ($conf->use_javascript_ajax) - { - print "\n"; - print ''."\n"; - } - } - - return count($boxactivated); -} - - - /** * Class to manage boxes on pages */ class InfoBox { - var $db; - - /** - * Constructor - * - * @param DoliDb $db Database handler - */ - function InfoBox($db) - { - $this->db=$db; - } - - /** * Return array of boxes qualified for area and user * @@ -220,7 +36,7 @@ class InfoBox * @param array $excludelist Array of box id (box.box_id = boxes_def.rowid) to exclude * @return array Array of boxes */ - function listBoxes($mode,$zone,$user,$excludelist=array()) + static function listBoxes($db, $mode,$zone,$user,$excludelist=array()) { global $conf; @@ -247,14 +63,14 @@ class InfoBox } dol_syslog(get_class($this)."::listBoxes get default box list sql=".$sql, LOG_DEBUG); - $resql = $this->db->query($sql); + $resql = $db->query($sql); if ($resql) { - $num = $this->db->num_rows($resql); + $num = $db->num_rows($resql); $j = 0; while ($j < $num) { - $obj = $this->db->fetch_object($resql); + $obj = $db->fetch_object($resql); if (! in_array($obj->box_id, $excludelist)) { @@ -273,7 +89,7 @@ class InfoBox dol_include_once($relsourcefile); if (class_exists($boxname)) { - $box=new $boxname($this->db,$obj->note); + $box=new $boxname($db,$obj->note); // box properties $box->rowid=$obj->rowid; @@ -311,8 +127,8 @@ class InfoBox } else { - //dol_print_error($this->db); - $this->error=$this->db->error(); + //dol_print_error($db); + $this->error=$db->error(); dol_syslog(get_class($this)."::listBoxes Error ".$this->error, LOG_ERR); return array(); } @@ -329,7 +145,7 @@ class InfoBox * @param int $userid Id of user * @return int <0 if KO, >= 0 if OK */ - function saveboxorder($zone,$boxorder,$userid=0) + static function saveboxorder($db, $zone,$boxorder,$userid=0) { global $conf; @@ -341,18 +157,18 @@ class InfoBox if (! $userid || $userid == 0) return 0; - $user = new User($this->db); + $user = new User($db); $user->id=$userid; - $this->db->begin(); + $db->begin(); // Sauve parametre indiquant que le user a une config dediee $confuserzone='MAIN_BOXES_'.$zone; $tab[$confuserzone]=1; - if (dol_set_user_param($this->db, $conf, $user, $tab) < 0) + if (dol_set_user_param($db, $conf, $user, $tab) < 0) { - $this->error=$this->db->lasterror(); - $this->db->rollback(); + $this->error=$db->lasterror(); + $db->rollback(); return -3; } @@ -365,7 +181,7 @@ class InfoBox $sql.= " AND ".MAIN_DB_PREFIX."boxes.position = ".$zone; dol_syslog(get_class($this)."::saveboxorder sql=".$sql); - $result = $this->db->query($sql); + $result = $db->query($sql); if ($result) { $colonnes=explode('-',$boxorder); @@ -395,7 +211,7 @@ class InfoBox $sql.= ")"; dol_syslog(get_class($this)."::saveboxorder sql=".$sql); - $result = $this->db->query($sql); + $result = $db->query($sql); if ($result < 0) { $error++; @@ -406,20 +222,20 @@ class InfoBox } if ($error) { - $this->error=$this->db->error(); - $this->db->rollback(); + $this->error=$db->error(); + $db->rollback(); return -2; } else { - $this->db->commit(); + $db->commit(); return 1; } } else { - $this->error=$this->db->lasterror(); - $this->db->rollback(); + $this->error=$db->lasterror(); + $db->rollback(); dol_syslog(get_class($this)."::saveboxorder ".$this->error); return -1; } diff --git a/htdocs/index.php b/htdocs/index.php index dbe0a74e7d3..1ae1f884f95 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -26,7 +26,7 @@ define('NOCSRFCHECK',1); // This is login page. We must be able to go on it from another web site. require("./main.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/boxes.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/html.formother.class.php"); // If not defined, we select menu "home" @@ -529,7 +529,7 @@ print '

'; * Show boxes */ -printBoxesArea($user,"0"); +FormOther::printBoxesArea($user,"0"); print '
';