* Copyright (C) 2004-2006 Laurent Destailleur * * 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$ */ /** \file htdocs/admin/boxes.php \brief Page d'administration/configuration des boites \version $Revision$ */ require("./pre.inc.php"); include_once(DOL_DOCUMENT_ROOT."/includes/boxes/modules_boxes.php"); $langs->load("admin"); if (!$user->admin) accessforbidden(); // Définition des positions possibles pour les boites $pos_array = array(0); // Positions possibles pour une boite (0,1,2,...) $pos_name = array($langs->trans("Home")); // Nom des positions 0=Homepage, 1=... $boxes = array(); /* * Actions */ if ($_POST["action"] == 'add') { $sql = "SELECT rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."boxes"; $sql.= " WHERE fk_user=0 AND box_id=".$_POST["boxid"]." AND position=".$_POST["pos"]; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); if ($num == 0) { // Si la boite n'est pas deja active $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes (box_id, position, fk_user) values (".$_POST["boxid"].",".$_POST["pos"].", 0)"; $resql = $db->query($sql); } Header("Location: boxes.php"); exit; } else { dolibarr_print_error($db); } } if ($_GET["action"] == 'delete') { $db->begin(); $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes"; $sql.= " WHERE rowid=".$_GET["rowid"]; $resql = $db->query($sql); $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_param"; $sql.= " WHERE param like 'MAIN_BOXES_%'"; $resql = $db->query($sql); $db->commit(); } if ($_GET["action"] == 'switch') { // On permute les valeur du champ box_order des 2 lignes de la table boxes $db->begin(); $objfrom=new ModeleBoxes($db); $objfrom->fetch($_GET["switchfrom"]); $objto=new ModeleBoxes($db); $objto->fetch($_GET["switchto"]); if (is_object($objfrom) && is_object($objto)) { $sql="UPDATE ".MAIN_DB_PREFIX."boxes set box_order=".$objto->box_order." WHERE rowid=".$objfrom->rowid; //print "xx".$sql; $resultupdatefrom = $db->query($sql); if (! $resultupdatefrom) { dolibarr_print_error($db); } $sql="UPDATE ".MAIN_DB_PREFIX."boxes set box_order=".$objfrom->box_order." WHERE rowid=".$objto->rowid; //print "xx".$sql; $resultupdateto = $db->query($sql); if (! $resultupdateto) { dolibarr_print_error($db); } } if ($resultupdatefrom && $resultupdateto) { $db->commit(); } else { $db->rollback(); } } llxHeader(); print_fiche_titre($langs->trans("Boxes"),'','setup'); print $langs->trans("BoxesDesc")."
\n"; /* * Recherche des boites actives par position possible * On stocke les boites actives par $boxes[position][id_boite]=1 */ $sql = "SELECT b.rowid, b.box_id, b.position, b.box_order, d.name, d.rowid as boxid"; $sql .= " FROM ".MAIN_DB_PREFIX."boxes as b, ".MAIN_DB_PREFIX."boxes_def as d"; $sql .= " WHERE b.box_id = d.rowid AND fk_user=0"; $sql .= " ORDER by position, box_order"; $resql = $db->query($sql); $actives = array(); if ($resql) { $num = $db->num_rows($resql); $i = 0; $decalage=0; while ($i < $num) { $var = ! $var; $obj = $db->fetch_object($resql); $boxes[$obj->position][$obj->box_id]=1; $i++; array_push($actives,$obj->boxid); // On renumérote l'ordre des boites si l'une d'elle est à 0 (Ne doit arriver que sur des anciennes versions) if ($obj->box_order==0) $decalage++; if ($decalage) { $sql="UPDATE ".MAIN_DB_PREFIX."boxes set box_order=box_order+".$decalage." WHERE rowid=".$obj->rowid; $db->query($sql); } } $db->free($resql); } /* * Boites disponibles */ print "
\n"; print_titre($langs->trans("BoxesAvailable")); print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $sql = "SELECT rowid, name, file, note"; $sql.= " FROM ".MAIN_DB_PREFIX."boxes_def"; $resql = $db->query($sql); $var=True; if ($resql) { $html=new Form($db); $num = $db->num_rows($resql); $i = 0; // Boucle sur toutes les boites while ($i < $num) { $obj = $db->fetch_object($resql); $module=eregi_replace('.php$','',$obj->file); include_once(DOL_DOCUMENT_ROOT."/includes/boxes/".$module.".php"); $box=new $module($db,$obj->note); // if (in_array($obj->rowid, $actives) && $box->box_multiple <> 1) if (in_array($obj->rowid, $actives)) { // La boite est déjà activée } else { $var = ! $var; print ''; $logo=eregi_replace("^object_","",$box->boximg); print ''; print ''; print ''; print ''; // Pour chaque position possible, on affiche un lien // d'activation si boite non deja active pour cette position print ''; print ''; } $i++; } $db->free($resql); } print '
'.$langs->trans("Box").''.$langs->trans("Note").'/'.$langs->trans("Parameters").''.$langs->trans("SourceFile").''.$langs->trans("ActivateOn").'
'.img_object("",$logo).' '.$box->boxlabel.'' . ($obj->note?$obj->note:' ') . '' . $obj->file . ''; print $html->select_array("pos",$pos_name); print ''; print ''; print ' '; print '
'; /* * Boites activées * */ print "
\n\n"; print_titre($langs->trans("BoxesActivated")); print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $sql = "SELECT b.rowid, b.box_id, b.position,"; $sql.= " d.name, d.file, d.note"; $sql.= " FROM ".MAIN_DB_PREFIX."boxes as b, ".MAIN_DB_PREFIX."boxes_def as d"; $sql.= " WHERE b.box_id = d.rowid"; $sql.= " AND b.fk_user=0"; $sql.= " ORDER by position, box_order"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $var=true; $box_order=1; $foundrupture=1; // On lit avec un coup d'avance $obj = $db->fetch_object($resql); while ($obj && $i < $num) { $var = ! $var; $objnext = $db->fetch_object($resql); $module=eregi_replace('.php$','',$obj->file); include_once(DOL_DOCUMENT_ROOT."/includes/boxes/".$module.".php"); $box=new $module($db,$obj->note); $logo=eregi_replace("^object_","",$box->boximg); print ''; print ''; print ''; print ''; $hasnext=true; $hasprevious=true; if ($foundrupture) { $hasprevious=false; $foundrupture=0; } if (! $objnext || $obj->position != $objnext->position) { $hasnext=false; $foundrupture=1; } print ''; print ''; print ''; print "\n"; $i++; $box_order++; if (! $foundrupture) $objprevious = $obj; else $box_order=1; $obj=$objnext; } $db->free($resql); } print '
'.$langs->trans("Box").''.$langs->trans("Note").'/'.$langs->trans("Parameters").''.$langs->trans("ActiveOn").''.$langs->trans("PositionByDefault").''.$langs->trans("Disable").'
'.img_object("",$logo).' '.$box->boxlabel.'' . ($obj->note?$obj->note:' ') . '' . $pos_name[$obj->position] . ''.$box_order.''; print ($hasnext?''.img_down().' ':''); print ($hasprevious?''.img_up().'':''); print ''; print ''.img_delete().''; print '

'; $db->close(); llxFooter('$Date$ - $Revision$'); ?>