diff --git a/htdocs/admin/agenda_other.php b/htdocs/admin/agenda_other.php index 57a1f74d530..9e2f6acaebb 100644 --- a/htdocs/admin/agenda_other.php +++ b/htdocs/admin/agenda_other.php @@ -83,7 +83,7 @@ if ($action == 'set') { dolibarr_set_const($db, 'AGENDA_DEFAULT_VIEW', GETPOST('AGENDA_DEFAULT_VIEW'), 'chaine', 0, '', $conf->entity); $defaultValues = new DefaultValues($db); - $result = $defaultValues->fetchAll('','',0,0,array('t.page'=>'comm/action/card.php', 't.param'=>'complete','t.user_id'=>'0', 't.type'=>'createform', 'entity'=>$conf->entity)); + $result = $defaultValues->fetchAll('','',0,0,array('t.page'=>'comm/action/card.php', 't.param'=>'complete','t.user_id'=>'0', 't.type'=>'createform', 't.entity'=>$conf->entity)); if (!is_array($result) && $result<0) { setEventMessages($defaultValues->error,$defaultValues->errors,'errors'); } elseif(count($result)>0) { @@ -358,7 +358,7 @@ print ' '."\n"; print ''."\n"; $defval='na'; $defaultValues = new DefaultValues($db); -$result = $defaultValues->fetchAll('','',0,0,array('t.page'=>'comm/action/card.php', 't.param'=>'complete','t.user_id'=>'0', 't.type'=>'createform', 'entity'=>$conf->entity)); +$result = $defaultValues->fetchAll('','',0,0,array('t.page'=>'comm/action/card.php', 't.param'=>'complete','t.user_id'=>'0', 't.type'=>'createform', 't.entity'=>$conf->entity)); if (!is_array($result) && $result<0) { setEventMessages($defaultValues->error,$defaultValues->errors,'errors'); } elseif(count($result)>0) { diff --git a/htdocs/admin/defaultvalues.php b/htdocs/admin/defaultvalues.php index 9904ff734c2..a6780df7b6e 100644 --- a/htdocs/admin/defaultvalues.php +++ b/htdocs/admin/defaultvalues.php @@ -43,7 +43,7 @@ $id = GETPOST('rowid', 'int'); $action = GETPOST('action', 'aZ09'); $optioncss = GETPOST('optionscss', 'alphanohtml'); -$mode = GETPOST('mode', 'aZ09') ?GETPOST('mode', 'aZ09') : 'createform'; // 'createform', 'filters', 'sortorder', 'focus' +$mode = GETPOST('mode', 'aZ09') ? GETPOST('mode', 'aZ09') : 'createform'; // 'createform', 'filters', 'sortorder', 'focus' $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); @@ -138,13 +138,12 @@ if (($action == 'add' || (GETPOST('add') && $action != 'update')) || GETPOST('ac } if (!$error) { - $db->begin(); if ($action == 'add' || (GETPOST('add') && $action != 'update')) { $object->type=$mode; $object->user_id=0; $object->page=$defaulturl; - $object->param=$defaulturl; + $object->param=$defaultkey; $object->value=$defaultvalue; $object->entity=$conf->entity; $result=$object->create($user); @@ -162,9 +161,11 @@ if (($action == 'add' || (GETPOST('add') && $action != 'update')) || GETPOST('ac if (GETPOST('actionmodify')) { $object->id=$id; - $object->page=$defaulturl; + $object->type=$mode; + $object->page=$urlpage; $object->param=$key; - $object->value=$defaultvalue; + $object->value=$value; + $object->entity=$conf->entity; $result=$object->update($user); if ($result<0) { $action = ''; @@ -358,8 +359,9 @@ print ''; $result=$object->fetchAll( $sortorder, $sortfield, 0, 0, array('t.type'=>$mode,'t.entity'=>array($user->entity,$conf->entity))); if (!is_array($result) && $result<0) { + setEventMessages($object->error, $object->errors,'errors'); -} else { +} elseif (count($result)>0) { foreach($result as $key=>$defaultvalue) { print "\n"; @@ -367,13 +369,13 @@ if (!is_array($result) && $result<0) { // Page print ''; - if ($action != 'edit' || GETPOST('rowid', 'int') != $defaultvalue->rowid) print $defaultvalue->page; + if ($action != 'edit' || GETPOST('rowid', 'int') != $defaultvalue->id) print $defaultvalue->page; else print ''; print ''."\n"; // Field print ''; - if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->rowid) print $defaultvalue->param; + if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->id) print $defaultvalue->param; else print ''; print ''."\n"; @@ -385,7 +387,7 @@ if (!is_array($result) && $result<0) { print ''; print ''; */ - if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->rowid) print dol_escape_htmltag($defaultvalue->value); + if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->id) print dol_escape_htmltag($defaultvalue->value); else print ''; print ''; } @@ -400,7 +402,7 @@ if (!is_array($result) && $result<0) { } else { print ''; print ''; - print '
'; + print '
'; print ''; print ''; } diff --git a/htdocs/core/class/defaultvalues.class.php b/htdocs/core/class/defaultvalues.class.php index c43d3ae121c..ae5ed6e92fb 100644 --- a/htdocs/core/class/defaultvalues.class.php +++ b/htdocs/core/class/defaultvalues.class.php @@ -265,13 +265,12 @@ class DefaultValues extends CommonObject $sql = 'SELECT '; $sql .= $this->getFieldList(); $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')'; - else $sql .= ' WHERE 1 = 1'; + $sql .= ' WHERE 1 = 1'; // Manage filter $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { - if ($key == 't.rowid' || ($key == 't.entity' && !is_array($value)) || $key == 't.user_id') { + if ($key == 't.rowid' || ($key == 't.entity' && !is_array($value)) || ($key == 't.user_id' && !is_array($value))) { $sqlwhere[] = $key.'='.$value; } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) { $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\''; @@ -296,10 +295,12 @@ class DefaultValues extends CommonObject if (!empty($limit)) { $sql .= ' '.$this->db->plimit($limit, $offset); } - +print $sql; $resql = $this->db->query($sql); if ($resql) { + $num = $this->db->num_rows($resql); + var_dump($num); $i = 0; while ($i < ($limit ? min($limit, $num) : $num)) { diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 8712bcc4615..bacbfa32f67 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -611,31 +611,32 @@ class User extends CommonObject public function loadDefaultValues() { global $conf; + if (!empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) { - // Load user->default_values for user. TODO Save this in memcached ? - $sql = "SELECT rowid, entity, type, page, param, value"; - $sql .= " FROM ".MAIN_DB_PREFIX."default_values"; - $sql .= " WHERE entity IN (".($this->entity > 0 ? $this->entity.", " : "").$conf->entity.")"; // Entity of user (if defined) + current entity - $sql .= " AND user_id IN (0".($this->id > 0 ? ", ".$this->id : "").")"; // User 0 (all) + me (if defined) - $resql = $this->db->query($sql); - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { - if (!empty($obj->page) && !empty($obj->type) && !empty($obj->param)) { - // $obj->page is relative URL with or without params - // $obj->type can be 'filters', 'sortorder', 'createform', ... - // $obj->param is key or param - $pagewithoutquerystring = $obj->page; - $pagequeries = ''; - $reg = array(); - if (preg_match('/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) { // There is query param - $pagewithoutquerystring = $reg[1]; - $pagequeries = $reg[2]; + // Load user->default_values for user. TODO Save this in memcached ? + require_once DOL_DOCUMENT_ROOT.'/core/class/defaultvalues.class.php'; + + $defaultValues = new DefaultValues($this->db); + $result = $defaultValues->fetchAll('','',0,0,array('t.user_id'=>array(0,$this->id), 'entity'=>array($this->entity,$conf->entity))); + + if (!is_array($result) && $result<0) { + setEventMessages($defaultValues->error,$defaultValues->errors,'errors'); + dol_print_error($this->db); + return -1; + } elseif(count($result)>0) { + foreach($result as $defval) { + if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) { + $pagewithoutquerystring = $defval->page; + $pagequeries = ''; + $reg = array(); + if (preg_match('/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) { // There is query param + $pagewithoutquerystring = $reg[1]; + $pagequeries = $reg[2]; + } + $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries : '_noquery_'][$defval->param] = $defval->value; } - $this->default_values[$pagewithoutquerystring][$obj->type][$pagequeries ? $pagequeries : '_noquery_'][$obj->param] = $obj->value; - //if ($pagequeries) $this->default_values[$pagewithoutquerystring][$obj->type.'_queries']=$pagequeries; } } - // Sort by key, so _noquery_ is last if (!empty($this->default_values)) { foreach ($this->default_values as $a => $b) { foreach ($b as $c => $d) { @@ -643,13 +644,8 @@ class User extends CommonObject } } } - $this->db->free($resql); - - return 1; - } else { - dol_print_error($this->db); - return -1; } + return 1; } /**