dolibarr/htdocs/admin/boxes.php

191 lines
4.9 KiB
PHP
Raw Normal View History

2003-02-13 18:18:18 +01:00
<?PHP
/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2004-05-15 19:07:12 +02:00
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
2003-02-13 18:18:18 +01:00
*
* 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$
*/
require("./pre.inc.php");
if (!$user->admin)
accessforbidden();
2003-02-13 18:18:18 +01:00
llxHeader();
print_titre("Boites");
print "<br>";
2004-05-15 19:07:12 +02:00
print "Les boites sont des cartouches d'informations r<>duites qui s'affichent sur certaines pages. Vous pouvez choisir ou non d'activer ces cartouches en cliquant sur 'Ajouter' ou la poubelle pour les d<>sactiver. ";
2004-06-26 03:42:29 +02:00
print "Seules les boites en rapport avec un <a href=\"modules.php\">module</a> actif sont pr<70>sent<6E>es.<br>\n";
2003-02-13 18:18:18 +01:00
2004-06-26 03:42:29 +02:00
if ($_POST["action"] == 'add')
2003-02-13 18:18:18 +01:00
{
2004-06-26 03:42:29 +02:00
$sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes (box_id, position) values (".$_POST["rowid"].",".$_POST["constvalue"].");";
2003-02-13 18:18:18 +01:00
$result = $db->query($sql);
}
if ($_GET["action"] == 'add')
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes (box_id, position) values (".$_GET["rowid"].",0);";
$result = $db->query($sql);
}
if ($_GET["action"] == 'delete')
2003-02-13 18:18:18 +01:00
{
2004-07-25 01:27:25 +02:00
$sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes WHERE rowid=".$_GET["rowid"];
2003-02-13 18:18:18 +01:00
$result = $db->query($sql);
}
// D<>finition des positions possibles pour les boites
$pos_array = array(0); // Positions possibles pour une boite (0,1,2,...)
$pos_name = array(); // Nom des position 0=Homepage, 1=...
$pos_name[0]="Homepage";
2003-03-13 22:25:02 +01:00
$boxes = array();
2003-02-13 18:18:18 +01:00
/*
* Recherche des boites actives par position possible
* On stocke les boites actives par $boxes[position][id_boite]=1
*
*/
2003-02-13 18:18:18 +01:00
$sql = "SELECT b.rowid, b.box_id, b.position, d.name FROM ".MAIN_DB_PREFIX."boxes as b, ".MAIN_DB_PREFIX."boxes_def as d where b.box_id = d.rowid";
2003-02-13 18:18:18 +01:00
$result = $db->query($sql);
2003-02-13 18:18:18 +01:00
if ($result)
{
$num = $db->num_rows();
$i = 0;
2003-02-13 18:18:18 +01:00
while ($i < $num)
{
$var = ! $var;
2003-02-13 18:18:18 +01:00
$obj = $db->fetch_object( $i);
//print "pos ".$obj->position;
$boxes[$obj->position][$obj->box_id]=1;
2003-02-13 18:18:18 +01:00
$i++;
}
}
$db->free();
2003-02-13 18:18:18 +01:00
/*
* Boites disponibles
2003-02-13 18:18:18 +01:00
*
*/
print '<br>';
2003-02-13 18:18:18 +01:00
print_titre("Boites disponibles");
print '<table class="noborder" cellpadding="3" cellspacing="0" width="100%">';
print '<tr class="liste_titre">';
print '<td>Boites</td>';
print '<td>Fichier source</td>';
foreach ($pos_array as $position) {
print '<td align="center">Activation '.$pos_name[$position].'</td>';
}
print "</tr>\n";
2003-02-13 18:18:18 +01:00
$sql = "SELECT rowid, name, file FROM ".MAIN_DB_PREFIX."boxes_def";
2003-02-13 18:18:18 +01:00
$result = $db->query($sql);
$var=True;
if ($result)
{
$num = $db->num_rows();
$i = 0;
while ($i < $num)
{
$var = ! $var;
$obj = $db->fetch_object( $i);
print '<tr '.$bc[$var].'><td width="200">'.$obj->name.'</td><td width="200">' . $obj->file . '</td>';
// Pour chaque position possible, on affiche un lien
// d'activation si boite non deja active pour cette position
foreach ($pos_array as $position) {
print '<td width="50" align="center">';
if (! $boxes[$position][$obj->rowid])
{
2004-07-25 01:27:25 +02:00
print '<a href="boxes.php?rowid='.$obj->rowid.'&amp;action=add&pos='.$position.'">Ajouter</a>';
}
else
{
print "&nbsp;";
}
print '</td>';
}
print '</tr>';
$i++;
}
}
$db->free();
print '</table>';
print "<br>\n";
print_titre("Boites activ<69>es");
print '<table class="noborder" cellpadding="3" cellspacing="0" width="100%">';
print '<tr class="liste_titre">';
print '<td>Boites</td>';
print '<td>Active pour</td>';
print '<td align="center">D<>sactiver</td>';
print "</tr>\n";
$sql = "SELECT b.rowid, b.box_id, b.position, d.name FROM ".MAIN_DB_PREFIX."boxes as b, ".MAIN_DB_PREFIX."boxes_def as d where b.box_id = d.rowid";
$result = $db->query($sql);
2003-02-13 18:18:18 +01:00
if ($result)
{
$num = $db->num_rows();
$i = 0;
while ($i < $num)
{
$var = ! $var;
2003-02-13 18:18:18 +01:00
$obj = $db->fetch_object( $i);
print '<tr '.$bc[$var].'><td width="200">'.$obj->name.'</td><td width="200">' . $pos_name[$obj->position] . '</td><td width="50" align="center">';
2004-07-25 01:27:25 +02:00
print '<a href="boxes.php?rowid='.$obj->rowid.'&amp;action=delete">'.img_delete().'</a>';
2003-02-13 18:18:18 +01:00
print '</td></tr>';
$i++;
}
}
$db->free();
2003-02-13 18:18:18 +01:00
print '</table>';
2003-02-13 18:18:18 +01:00
$db->close();
llxFooter();
?>