Skip to content
Browse files

Fix: Save of box order

  • Loading branch information...
1 parent e7fa358 commit 1e1ee9d3383e51c12738c189f7508bd510f7d209 @eldy eldy committed Feb 11, 2009
Showing with 103 additions and 108 deletions.
  1. +5 −5 htdocs/ajaxbox.php
  2. +69 −69 htdocs/boxes.php
  3. +10 −9 htdocs/index.php
  4. +7 −13 htdocs/lib/functions2.lib.php
  5. +12 −12 htdocs/user/param_ihm.php
View
10 htdocs/ajaxbox.php
@@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
- * Copyright (C) 2007 Laurent Destailleur <eldy@users.sourceforge.net>
+ * Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
@@ -18,10 +18,10 @@
*/
/**
- \file htdocs/ajaxbox.php
- \brief Fichier de reponse sur evenement Ajax deplacement boxes
- \version $Id$
-*/
+ * \file htdocs/ajaxbox.php
+ * \brief Fichier de reponse sur evenement Ajax deplacement boxes
+ * \version $Id$
+ */
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
View
138 htdocs/boxes.php
@@ -1,5 +1,5 @@
<?php
-/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
+/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
@@ -21,44 +21,44 @@
*/
/**
- \file htdocs/boxes.php
- \brief Fichier de la classe boxes
- \author Rodolphe Qiedeville
- \author Laurent Destailleur
- \version $Revision$
-*/
+ \file htdocs/boxes.php
+ \brief Fichier de la classe boxes
+ \author Rodolphe Qiedeville
+ \author Laurent Destailleur
+ \version $Revision$
+ */
/**
- \class InfoBox
- \brief Classe permettant la gestion des boxes sur une page
-*/
+ \class InfoBox
+ \brief Classe permettant la gestion des boxes sur une page
+ */
-class InfoBox
+class InfoBox
{
- var $db;
+ var $db;
+
+ /**
+ * \brief Constructeur de la classe
+ * \param $DB Handler d'acc�s base
+ */
+ function InfoBox($DB)
+ {
+ $this->db=$DB;
+ }
- /**
- * \brief Constructeur de la classe
- * \param $DB Handler d'acc�s base
- */
- function InfoBox($DB)
- {
- $this->db=$DB;
- }
-
- /**
- * \brief Retourne tableau des boites elligibles pour la zone et le user
- * \param $zone ID de la zone (0 pour la Homepage, ...)
- * \param $user Objet user
- * \return array Tableau d'objet box
- */
+ /**
+ * \brief Retourne tableau des boites elligibles pour la zone et le user
+ * \param $zone ID de la zone (0 pour la Homepage, ...)
+ * \param $user Objet user
+ * \return array Tableau d'objet box
+ */
function listBoxes($zone,$user)
{
global $conf;
-
+
$boxes=array();
$confuserzone='MAIN_BOXES_'.$zone;
@@ -72,7 +72,7 @@ function listBoxes($zone,$user)
$sql.= " AND b.position = ".$zone;
$sql.= " AND b.fk_user = ".$user->id;
$sql.= " ORDER BY b.box_order";
-
+
dolibarr_syslog("InfoBox::listBoxes get user box list sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
@@ -95,8 +95,8 @@ function listBoxes($zone,$user)
{
foreach($box->depends as $module)
{
-// print $module.'<br>';
- if (empty($conf->$module->enabled)) $enabled=false;
+ // print $module.'<br>';
+ if (empty($conf->$module->enabled)) $enabled=false;
}
}
if ($enabled) $boxes[]=$box;
@@ -142,8 +142,8 @@ function listBoxes($zone,$user)
{
foreach($box->depends as $module)
{
-// print $module.'<br>';
- if (empty($conf->$module->enabled)) $enabled=false;
+ // print $module.'<br>';
+ if (empty($conf->$module->enabled)) $enabled=false;
}
}
if ($enabled) $boxes[]=$box;
@@ -156,46 +156,46 @@ function listBoxes($zone,$user)
return array();
}
}
-
+
return $boxes;
}
- /**
- * \brief Sauvegarde sequencement des boites pour la zone et le user
- * \param $zone ID de la zone (0 pour la Homepage, ...)
- * \param $boxorder Liste des boites dans le bon ordre 'A:123,456,...-B:789,321...'
- * \param $userid Id du user
- * \return int <0 si ko, >= 0 si ok
- */
+ /**
+ * \brief Sauvegarde sequencement des boites pour la zone et le user
+ * \param $zone ID de la zone (0 pour la Homepage, ...)
+ * \param $boxorder Liste des boites dans le bon ordre 'A:123,456,...-B:789,321...'
+ * \param $userid Id du user
+ * \return int <0 si ko, >= 0 si ok
+ */
function saveboxorder($zone,$boxorder,$userid=0)
{
require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
-
+
dolibarr_syslog("InfoBoxes::saveboxorder zone=".$zone." user=".$userid);
if (! $userid || $userid == 0) return 0;
-
+
$user = new User($this->db,$userid);
$this->db->begin();
- // Sauve parametre indiquant que le user a une
+ // Sauve parametre indiquant que le user a une
$confuserzone='MAIN_BOXES_'.$zone;
$tab[$confuserzone]=1;
- if (! dol_set_user_page_param($this->db, $user, '', $tab))
- {
- $this->error=$this->db->error();
+ if (dol_set_user_param($this->db, $user, $tab) < 0)
+ {
+ $this->error=$this->db->lasterror();
$this->db->rollback();
return -3;
- }
-
+ }
+
$sql ="DELETE FROM ".MAIN_DB_PREFIX."boxes";
$sql.=" WHERE fk_user = ".$userid;
$sql.=" AND position = ".$zone;
- $result = $this->db->query($sql);
-
+
dolibarr_syslog("InfoBox::saveboxorder sql=".$sql);
+ $result = $this->db->query($sql);
if ($result)
{
$colonnes=split('-',$boxorder);
@@ -205,7 +205,7 @@ function saveboxorder($zone,$boxorder,$userid=0)
$colonne=$part[0];
$list=$part[1];
dolibarr_syslog('InfoBox::saveboxorder colonne='.$colonne.' list='.$list);
-
+
$i=0;
$listarray=split(',',$list);
foreach ($listarray as $id)
@@ -216,22 +216,22 @@ function saveboxorder($zone,$boxorder,$userid=0)
$i++;
$ii=sprintf('%02d',$i);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes";
- $sql.= "(box_id, position, box_order, fk_user)";
- $sql.= " values (";
- $sql.= " ".$id.",";
- $sql.= " ".$zone.",";
- $sql.= " '".$colonne.$ii."',";
- $sql.= " ".$userid;
- $sql.= ")";
-
- dolibarr_syslog("InfoBox::saveboxorder sql=".$sql);
- $result = $this->db->query($sql);
- if ($result < 0)
- {
- $error++;
- break;
- }
- }
+ $sql.= "(box_id, position, box_order, fk_user)";
+ $sql.= " values (";
+ $sql.= " ".$id.",";
+ $sql.= " ".$zone.",";
+ $sql.= " '".$colonne.$ii."',";
+ $sql.= " ".$userid;
+ $sql.= ")";
+
+ dolibarr_syslog("InfoBox::saveboxorder sql=".$sql);
+ $result = $this->db->query($sql);
+ if ($result < 0)
+ {
+ $error++;
+ break;
+ }
+ }
}
}
if ($error)
@@ -252,6 +252,6 @@ function saveboxorder($zone,$boxorder,$userid=0)
$this->db->rollback();
return -1;
}
- }
+ }
}
?>
View
19 htdocs/index.php
@@ -611,10 +611,11 @@
// If no box on left, we add an invisible empty box
if ($ii==0)
{
- $box->box_id='A';
- $box->info_box_head=array();
- $box->info_box_contents=array();
- $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 "</div>\n";
@@ -628,7 +629,6 @@
print '<div id="right">'."\n";
$ii=0;
- $boxarray=$infobox->listboxes("0",$user); // on régénère la liste pour éviter les erreurs avec les empty box
foreach ($boxarray as $key => $box)
{
if (eregi('^B',$box->box_order)) // colonne B
@@ -646,10 +646,11 @@
// If no box on right, we show add an invisible empty box
if ($ii==0)
{
- $box->box_id='B';
- $box->info_box_head=array();
- $box->info_box_contents=array();
- $box->showBox();
+ $emptybox=new ModeleBoxes($db);
+ $emptybox->box_id='B';
+ $emptybox->info_box_head=array();
+ $emptybox->info_box_contents=array();
+ $emptybox->showBox(array(),array());
}
print "</div>\n";
View
20 htdocs/lib/functions2.lib.php
@@ -548,12 +548,10 @@ function weight_convert($weight,&$from_unit,$to_unit)
* \brief Save personnal parameter
* \param db Handler database
* \param user Object user
- * \param url Si defini, on sauve parametre du tableau tab dont cle = (url avec sortfield, sortorder, begin et page)
- * Si non defini on sauve tous parametres du tableau tab
* \param tab Tableau (cle=>valeur) des parametres a sauvegarder
- * \return int <0 si ko, >0 si ok
+ * \return int <0 if KO, >0 if OK
*/
-function dol_set_user_page_param($db, &$user, $url='', $tab)
+function dol_set_user_param($db, &$user, $tab)
{
// Verification parametres
if (sizeof($tab) < 1) return -1;
@@ -563,8 +561,6 @@ function dol_set_user_page_param($db, &$user, $url='', $tab)
// We remove old parameters for all keys in $tab
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_param";
$sql.= " WHERE fk_user = ".$user->id;
- if ($url) $sql.=" AND page='".$url."'";
- else $sql.=" AND page=''"; // Page ne peut etre null
$sql.= " AND param in (";
$i=0;
foreach ($tab as $key => $value)
@@ -574,34 +570,32 @@ function dol_set_user_page_param($db, &$user, $url='', $tab)
$i++;
}
$sql.= ")";
- dolibarr_syslog("functions2.lib::dol_set_user_page_param $sql");
+ dolibarr_syslog("functions2.lib::dol_set_user_param sql=".$sql, LOG_DEBUG);
$resql=$db->query($sql);
if (! $resql)
{
dolibarr_print_error($db);
$db->rollback();
- exit;
+ return -1;
}
foreach ($tab as $key => $value)
{
// Set new parameters
if ($value && (! $url || in_array($key,array('sortfield','sortorder','begin','page'))))
{
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."user_param(fk_user,page,param,value)";
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."user_param(fk_user,param,value)";
$sql.= " VALUES (".$user->id.",";
- if ($url) $sql.= " '".urlencode($url)."',";
- else $sql.= " '',";
$sql.= " '".$key."','".addslashes($value)."');";
- dolibarr_syslog("functions2.lib::dol_set_user_page_param $sql");
+ dolibarr_syslog("functions2.lib::dol_set_user_param sql=".$sql, LOG_DEBUG);
$result=$db->query($sql);
if (! $result)
{
dolibarr_print_error($db);
$db->rollback();
- exit;
+ return -1;
}
$user->page_param[$key] = $value;
View
24 htdocs/user/param_ihm.php
@@ -74,30 +74,30 @@
{
$_GET["id"]=$_POST["id"];
}
- else
+ else
{
$tabparam=array();
-
+
if ($_POST["check_MAIN_LANG_DEFAULT"]=="on") $tabparam["MAIN_LANG_DEFAULT"]=$_POST["main_lang_default"];
else $tabparam["MAIN_LANG_DEFAULT"]='';
-
+
$tabparam["MAIN_MENU_BARRETOP"]=$_POST["main_menu_barretop"];
$tabparam["MAIN_MENU_BARRELEFT"]=$_POST["main_menu_barreleft"];
-
+
if ($_POST["check_SIZE_LISTE_LIMIT"]=="on") $tabparam["MAIN_SIZE_LISTE_LIMIT"]=$_POST["main_size_liste_limit"];
else $tabparam["MAIN_SIZE_LISTE_LIMIT"]='';
-
+
if ($_POST["check_MAIN_THEME"]=="on") $tabparam["MAIN_THEME"]=$_POST["main_theme"];
else $tabparam["MAIN_THEME"]='';
$tabparam["MAIN_SEARCHFORM_CONTACT"]=$_POST["main_searchform_contact"];
$tabparam["MAIN_SEARCHFORM_SOCIETE"]=$_POST["main_searchform_societe"];
$tabparam["MAIN_SEARCHFORM_PRODUITSERVICE"]=$_POST["main_searchform_produitservice"];
-
- dol_set_user_page_param($db, $fuser, '', $tabparam);
+
+ $result=dol_set_user_param($db, $fuser, $tabparam);
$_SESSION["mainmenu"]=""; // Le gestionnaire de menu a pu changer
-
+
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$_POST["id"]);
exit;
}
@@ -146,7 +146,7 @@
clearstatcache();
$var=true;
-
+
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td width="25%">'.$langs->trans("Parameter").'</td><td width="25%">'.$langs->trans("DefaultValue").'</td><td>&nbsp;</td><td>'.$langs->trans("PersonalValue").'</td></tr>';
@@ -185,7 +185,7 @@
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</center>';
print '</form>';
-
+
}
else
{
@@ -228,9 +228,9 @@
else
{
print "<a class=\"butActionRefused\" title=\"".$langs->trans("NotEnoughPermissions")."\" href=\"#\">".$langs->trans("Modify")."</a>";
- }
+ }
}
-
+
print '</div>';
}

0 comments on commit 1e1ee9d

Please sign in to comment.
Something went wrong with that request. Please try again.