[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * $Id: boxes.php,v 1.33 2005/10/14 21:05:13 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/admin/boxes.php,v $ 21 */ 22 23 /** 24 \file htdocs/admin/boxes.php 25 \brief Page d'administration/configuration des boites 26 \version $Revision: 1.33 $ 27 */ 28 29 require ("./pre.inc.php"); 30 $langs->load("admin"); 31 32 if (!$user->admin) 33 accessforbidden(); 34 35 // Définition des positions possibles pour les boites 36 $pos_array = array(0); // Positions possibles pour une boite (0,1,2,...) 37 $pos_name = array($langs->trans("Home")); // Nom des positions 0=Homepage, 1=... 38 $boxes = array(); 39 40 /* 41 * Actions 42 */ 43 44 if ($_POST["action"] == 'add') 45 { 46 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."boxes WHERE box_id=".$_POST["boxid"]." AND position=".$_POST["pos"]; 47 $result = $db->query($sql); 48 49 $num = $db->num_rows($result); 50 if ($num == 0) 51 { 52 // Si la boite n'est pas deja active 53 $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes (box_id, position) values (".$_POST["boxid"].",".$_POST["pos"].");"; 54 $result = $db->query($sql); 55 } 56 57 Header("Location: boxes.php"); 58 exit; 59 } 60 61 if ($_GET["action"] == 'delete') 62 { 63 $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes WHERE rowid=".$_GET["rowid"]; 64 $result = $db->query($sql); 65 } 66 67 if ($_GET["action"] == 'switch') 68 { 69 // On permute les valeur du champ box_order des 2 lignes de la table boxes 70 $db->begin(); 71 72 $sql="SELECT box_order FROM ".MAIN_DB_PREFIX."boxes WHERE rowid=".$_GET["switchfrom"]; 73 $resultfrom = $db->query($sql); 74 if ($resultfrom) 75 { 76 $objfrom = $db->fetch_object($resultfrom); 77 } 78 else 79 { 80 dolibarr_print_error($db); 81 } 82 83 $sql="SELECT box_order FROM ".MAIN_DB_PREFIX."boxes WHERE rowid=".$_GET["switchto"]; 84 $resultto = $db->query($sql); 85 86 if ($resultto) 87 { 88 $objto = $db->fetch_object($resultto); 89 } 90 else 91 { 92 dolibarr_print_error($db); 93 } 94 95 if ($objfrom && $objto) { 96 $sql="UPDATE ".MAIN_DB_PREFIX."boxes set box_order=".$objto->box_order." WHERE rowid=".$_GET["switchfrom"]; 97 $resultupdatefrom = $db->query($sql); 98 if (! $resultupdatefrom) { dolibarr_print_error($db); } 99 $sql="UPDATE ".MAIN_DB_PREFIX."boxes set box_order=".$objfrom->box_order." WHERE rowid=".$_GET["switchto"]; 100 $resultupdateto = $db->query($sql); 101 if (! $resultupdateto) { dolibarr_print_error($db); } 102 } 103 104 if ($resultupdatefrom && $resultupdateto) 105 { 106 $db->commit(); 107 } 108 else 109 { 110 $db->rollback(); 111 } 112 113 } 114 115 116 llxHeader(); 117 118 print_fiche_titre($langs->trans("Boxes")); 119 120 print $langs->trans("BoxesDesc")."<br>\n"; 121 122 /* 123 * Recherche des boites actives par position possible 124 * On stocke les boites actives par $boxes[position][id_boite]=1 125 */ 126 127 $sql = "SELECT b.rowid, b.box_id, b.position, b.box_order, d.name, d.rowid as boxid"; 128 $sql .= " FROM ".MAIN_DB_PREFIX."boxes as b, ".MAIN_DB_PREFIX."boxes_def as d"; 129 $sql .= " where b.box_id = d.rowid"; 130 $sql .= " ORDER by position, box_order"; 131 132 $resql = $db->query($sql); 133 134 $actives = array(); 135 136 if ($resql) 137 { 138 $num = $db->num_rows($resql); 139 $i = 0; 140 $decalage=0; 141 while ($i < $num) 142 { 143 $var = ! $var; 144 $obj = $db->fetch_object($resql); 145 $boxes[$obj->position][$obj->box_id]=1; 146 $i++; 147 148 array_push($actives,$obj->boxid); 149 150 // On renumérote l'ordre des boites si l'une d'elle est à 0 (Ne doit arriver que sur des anciennes versions) 151 if ($obj->box_order==0) $decalage++; 152 if ($decalage) 153 { 154 $sql="UPDATE ".MAIN_DB_PREFIX."boxes set box_order=box_order+".$decalage." WHERE rowid=".$obj->rowid; 155 $db->query($sql); 156 } 157 } 158 159 $db->free($resql); 160 } 161 162 163 /* 164 * Boites disponibles 165 */ 166 print "<br>\n"; 167 print_titre($langs->trans("BoxesAvailable")); 168 169 print '<table class="noborder" width="100%">'; 170 print '<tr class="liste_titre">'; 171 print '<td>'.$langs->trans("Box").'</td>'; 172 print '<td>'.$langs->trans("SourceFile").'</td>'; 173 print '<td align="center" width="180">'.$langs->trans("ActivateOn").'</td>'; 174 print '<td align="center" width="80"> </td>'; 175 print "</tr>\n"; 176 177 $sql = "SELECT rowid, name, file FROM ".MAIN_DB_PREFIX."boxes_def"; 178 $resql = $db->query($sql); 179 $var=True; 180 181 if ($resql) 182 { 183 $html=new Form($db); 184 185 $num = $db->num_rows($resql); 186 $i = 0; 187 188 // Boucle sur toutes les boites 189 while ($i < $num) 190 { 191 $obj = $db->fetch_object($resql); 192 193 $module=eregi_replace('.php$','',$obj->file); 194 include_once(DOL_DOCUMENT_ROOT."/includes/boxes/".$module.".php"); 195 196 $box=new $module(); 197 198 if (in_array($obj->rowid, $actives) && $box->box_multiple <> 1) 199 { 200 // La boite est déjà activée 201 // \todo 202 // L'idéal serait de supprimer la valeur du tableau 203 } 204 else 205 { 206 $var = ! $var; 207 208 print '<form action="boxes.php" method="POST">'; 209 $logo=eregi_replace("^object_","",$box->boximg); 210 print '<tr '.$bc[$var].'><td>'.img_object("",$logo).' '.$box->boxlabel.'</td><td>' . $obj->file . '</td>'; 211 212 // Pour chaque position possible, on affiche un lien 213 // d'activation si boite non deja active pour cette position 214 print '<td align="center">'; 215 print $html->select_array("pos",$pos_name); 216 print '<input type="hidden" name="action" value="add">'; 217 print '<input type="hidden" name="boxid" value="'.$obj->rowid.'">'; 218 print ' <input type="submit" class="button" name="button" value="'.$langs->trans("Activate").'">'; 219 print '</td>'; 220 221 print '<td> </td>'; 222 print '</tr></form>'; 223 } 224 $i++; 225 } 226 227 $db->free($resql); 228 } 229 230 print '</table>'; 231 232 /* 233 * Boites activées 234 * 235 */ 236 237 print "<br>\n\n"; 238 print_titre($langs->trans("BoxesActivated")); 239 240 print '<table class="noborder" width="100%">'; 241 print '<tr class="liste_titre">'; 242 print '<td>'.$langs->trans("Box").'</td>'; 243 print '<td> </td>'; 244 print '<td align="center" width="180">'.$langs->trans("ActiveOn").'</td>'; 245 print '<td align="center" width="60" colspan="2">'.$langs->trans("Position").'</td>'; 246 print '<td align="center" width="80">'.$langs->trans("Disable").'</td>'; 247 print "</tr>\n"; 248 249 $sql = "SELECT b.rowid, b.box_id, b.position, d.name, d.file"; 250 $sql .= " FROM ".MAIN_DB_PREFIX."boxes as b, ".MAIN_DB_PREFIX."boxes_def as d"; 251 $sql .= " where b.box_id = d.rowid"; 252 $sql .= " ORDER by position, box_order"; 253 254 $resql = $db->query($sql); 255 256 if ($resql) 257 { 258 $num = $db->num_rows($resql); 259 $i = 0; 260 $var=true; 261 262 $box_order=1; 263 $foundrupture=1; 264 265 // On lit avec un coup d'avance 266 $obj = $db->fetch_object($resql); 267 268 while ($obj && $i < $num) 269 { 270 $var = ! $var; 271 $objnext = $db->fetch_object($resql); 272 273 $module=eregi_replace('.php$','',$obj->file); 274 include_once(DOL_DOCUMENT_ROOT."/includes/boxes/".$module.".php"); 275 $box=new $module(); 276 277 $logo=eregi_replace("^object_","",$box->boximg); 278 print '<tr '.$bc[$var].'><td>'.img_object("",$logo).' '.$box->boxlabel.'</td>'; 279 print '<td> </td>'; 280 print '<td align="center">' . $pos_name[$obj->position] . '</td>'; 281 $hasnext=true; 282 $hasprevious=true; 283 if ($foundrupture) { $hasprevious=false; $foundrupture=0; } 284 if (! $objnext || $obj->position != $objnext->position) { $hasnext=false; $foundrupture=1; } 285 print '<td align="center" width="10">'.$box_order.'</td>'; 286 print '<td align="center" width="50">'; 287 print ($hasnext?'<a href="boxes.php?action=switch&switchfrom='.$obj->rowid.'&switchto='.$objnext->rowid.'">'.img_down().'</a> ':''); 288 print ($hasprevious?'<a href="boxes.php?action=switch&switchfrom='.$obj->rowid.'&switchto='.$objprevious->rowid.'">'.img_up().'</a>':''); 289 print '</td>'; 290 print '<td align="center">'; 291 print '<a href="boxes.php?rowid='.$obj->rowid.'&action=delete">'.img_delete().'</a>'; 292 print '</td>'; 293 294 print "</tr>\n"; 295 $i++; 296 297 $box_order++; 298 299 if (! $foundrupture) $objprevious = $obj; 300 else $box_order=1; 301 $obj=$objnext; 302 } 303 304 $db->free($resql); 305 } 306 307 print '</table><br>'; 308 309 $db->close(); 310 311 llxFooter('$Date: 2005/10/14 21:05:13 $ - $Revision: 1.33 $'); 312 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |