From 02a26104321593b14b61fc4ff83fa6d2205d52b7 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 16 Feb 2021 19:22:36 +0100 Subject: [PATCH 01/11] NEW: Conf for default actiomm status when created from card --- htdocs/admin/agenda_other.php | 8 ++++++++ htdocs/comm/action/card.php | 2 +- htdocs/langs/en_US/admin.lang | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/admin/agenda_other.php b/htdocs/admin/agenda_other.php index a072869be8c..32fd289eff7 100644 --- a/htdocs/admin/agenda_other.php +++ b/htdocs/admin/agenda_other.php @@ -84,6 +84,7 @@ if ($action == 'set') dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_TYPE', $defaultfilter, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_STATUS', GETPOST('AGENDA_DEFAULT_FILTER_STATUS'), 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'AGENDA_DEFAULT_VIEW', GETPOST('AGENDA_DEFAULT_VIEW'), 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, 'AGENDA_EVENT_DEFAULT_STATUS', GETPOST('AGENDA_EVENT_DEFAULT_STATUS'), 'chaine', 0, '', $conf->entity); } elseif ($action == 'specimen') // For orders { $modele = GETPOST('module', 'alpha'); @@ -352,6 +353,13 @@ if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) $formactions->select_type_actions($conf->global->AGENDA_USE_EVENT_TYPE_DEFAULT, "AGENDA_USE_EVENT_TYPE_DEFAULT", 'systemauto', 0, 1); print ''."\n"; } +// AGENDA_EVENT_DEFAULT_STATUS +print ''."\n"; +print ''.$langs->trans("AGENDA_EVENT_DEFAULT_STATUS").''."\n"; +print ' '."\n"; +print ''."\n"; +$formactions->form_select_status_action('formaction', $conf->global->AGENDA_EVENT_DEFAULT_STATUS, 1, "AGENDA_EVENT_DEFAULT_STATUS", 0, 1, 'maxwidth200'); +print ''."\n"; // AGENDA_DEFAULT_FILTER_TYPE print ''."\n"; diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index e34dffd6223..fd9849e3420 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -1050,12 +1050,12 @@ if ($action == 'create') // Status print ''.$langs->trans("Status").' / '.$langs->trans("Percentage").''; print ''; - $percent = -1; if (GETPOSTISSET('status')) $percent = GETPOST('status'); elseif (GETPOSTISSET('percentage')) $percent = GETPOST('percentage'); else { if (GETPOST('complete') == '0' || GETPOST("afaire") == 1) $percent = '0'; elseif (GETPOST('complete') == 100 || GETPOST("afaire") == 2) $percent = 100; + elseif ($conf->global->AGENDA_EVENT_DEFAULT_STATUS!=='na') $percent = $conf->global->AGENDA_EVENT_DEFAULT_STATUS; } $formactions->form_select_status_action('formaction', $percent, 1, 'complete', 0, 0, 'maxwidth200'); print ''; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 641cb8fb0af..78e38973caa 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -2104,3 +2104,4 @@ AskThisIDToYourBank=Contact your bank to get this ID AdvancedModeOnly=Permision available in Advanced permission mode only ConfFileIsReadableOrWritableByAnyUsers=The conf file is reabable or writable by any users. Give permission to web server user and group only. MailToSendEventOrganization=Event Organization +AGENDA_EVENT_DEFAULT_STATUS=Default event status when event created manually From 8b5ac45e34c33777af31a6e8bb85b0d6e6cdc34d Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 16 Feb 2021 19:29:45 +0100 Subject: [PATCH 02/11] fix typo --- htdocs/admin/agenda_other.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/admin/agenda_other.php b/htdocs/admin/agenda_other.php index 32fd289eff7..f48298f2d53 100644 --- a/htdocs/admin/agenda_other.php +++ b/htdocs/admin/agenda_other.php @@ -358,7 +358,7 @@ print ''."\n"; print ''.$langs->trans("AGENDA_EVENT_DEFAULT_STATUS").''."\n"; print ' '."\n"; print ''."\n"; -$formactions->form_select_status_action('formaction', $conf->global->AGENDA_EVENT_DEFAULT_STATUS, 1, "AGENDA_EVENT_DEFAULT_STATUS", 0, 1, 'maxwidth200'); +$formactions->form_select_status_action('agenda', $conf->global->AGENDA_EVENT_DEFAULT_STATUS, 1, "AGENDA_EVENT_DEFAULT_STATUS", 0, 1, 'maxwidth200'); print ''."\n"; // AGENDA_DEFAULT_FILTER_TYPE From a5736345e39fb1506a7334766d7689a27dadf5b2 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Wed, 17 Feb 2021 07:30:53 +0100 Subject: [PATCH 03/11] fix typo --- htdocs/comm/action/card.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index fd9849e3420..62175f882f9 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -1050,6 +1050,7 @@ if ($action == 'create') // Status print ''.$langs->trans("Status").' / '.$langs->trans("Percentage").''; print ''; + $percent = -1; if (GETPOSTISSET('status')) $percent = GETPOST('status'); elseif (GETPOSTISSET('percentage')) $percent = GETPOST('percentage'); else { From e2b469dee436177abeff0ae29d5f286def2aa36b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 19 Feb 2021 15:54:30 +0100 Subject: [PATCH 04/11] Update admin.lang --- htdocs/langs/en_US/admin.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 78e38973caa..c418987f74a 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -2104,4 +2104,4 @@ AskThisIDToYourBank=Contact your bank to get this ID AdvancedModeOnly=Permision available in Advanced permission mode only ConfFileIsReadableOrWritableByAnyUsers=The conf file is reabable or writable by any users. Give permission to web server user and group only. MailToSendEventOrganization=Event Organization -AGENDA_EVENT_DEFAULT_STATUS=Default event status when event created manually +AGENDA_EVENT_DEFAULT_STATUS=Default event status when creating a event from the form From aab4f8e02878e217e185180a7c31afee4ba50c43 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 19 Feb 2021 15:56:10 +0100 Subject: [PATCH 05/11] Update card.php --- htdocs/comm/action/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 62175f882f9..f3ad41eb7f2 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -1056,7 +1056,7 @@ if ($action == 'create') else { if (GETPOST('complete') == '0' || GETPOST("afaire") == 1) $percent = '0'; elseif (GETPOST('complete') == 100 || GETPOST("afaire") == 2) $percent = 100; - elseif ($conf->global->AGENDA_EVENT_DEFAULT_STATUS!=='na') $percent = $conf->global->AGENDA_EVENT_DEFAULT_STATUS; + elseif (isset($conf->global->AGENDA_EVENT_DEFAULT_STATUS) && $conf->global->AGENDA_EVENT_DEFAULT_STATUS!=='na') $percent = $conf->global->AGENDA_EVENT_DEFAULT_STATUS; } $formactions->form_select_status_action('formaction', $percent, 1, 'complete', 0, 0, 'maxwidth200'); print ''; From 0edae6e19a95b346f6dee0ba1e502b07d8cd2e3e Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Mon, 1 Mar 2021 18:25:23 +0100 Subject: [PATCH 06/11] add class default values --- htdocs/admin/defaultvalues.php | 110 +++---- htdocs/core/class/defaultvalues.class.php | 359 ++++++++++++++++++++++ 2 files changed, 414 insertions(+), 55 deletions(-) create mode 100644 htdocs/core/class/defaultvalues.class.php diff --git a/htdocs/admin/defaultvalues.php b/htdocs/admin/defaultvalues.php index ae9427d70e0..f9aa063c953 100644 --- a/htdocs/admin/defaultvalues.php +++ b/htdocs/admin/defaultvalues.php @@ -30,6 +30,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/defaultvalues.class.php'; // Load translation files required by the page $langs->loadLangs(array('companies', 'products', 'admin', 'sms', 'other', 'errors')); @@ -67,6 +68,7 @@ $value = GETPOST('value', 'restricthtml'); $hookmanager->initHooks(array('admindefaultvalues', 'globaladmin')); +$object = new DefaultValues($db); /* * Actions */ @@ -133,27 +135,41 @@ if (($action == 'add' || (GETPOST('add') && $action != 'update')) || GETPOST('ac if ($action == 'add' || (GETPOST('add') && $action != 'update')) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."default_values(type, user_id, page, param, value, entity) VALUES ('".$db->escape($mode)."', 0, '".$db->escape($defaulturl)."','".$db->escape($defaultkey)."','".$db->escape($defaultvalue)."', ".$db->escape($conf->entity).")"; + $object->type=$mode; + $object->user_id=0; + $object->page=$defaulturl; + $object->param=$defaulturl; + $object->value=$defaultvalue; + $object->entity=$conf->entity; + $result=$object->create($user); + if ($result<0) { + $action = ''; + setEventMessages($object->error,$object->errors,'errors'); + } else { + setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); + $action = ""; + $defaulturl = ''; + $defaultkey = ''; + $defaultvalue = ''; + } } if (GETPOST('actionmodify')) { - $sql = "UPDATE ".MAIN_DB_PREFIX."default_values SET page = '".$db->escape($urlpage)."', param = '".$db->escape($key)."', value = '".$db->escape($value)."'"; - $sql .= " WHERE rowid = ".$id; - } - - $result = $db->query($sql); - if ($result > 0) - { - $db->commit(); - setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); - $action = ""; - $defaulturl = ''; - $defaultkey = ''; - $defaultvalue = ''; - } else { - $db->rollback(); - setEventMessages($db->lasterror(), null, 'errors'); - $action = ''; + $object->id=$id; + $object->page=$defaulturl; + $object->param=$key; + $object->value=$defaultvalue; + $result=$object->update($user); + if ($result<0) { + $action = ''; + setEventMessages($object->error,$object->errors,'errors'); + } else { + setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); + $action = ""; + $defaulturl = ''; + $defaultkey = ''; + $defaultvalue = ''; + } } } } @@ -161,14 +177,12 @@ if (($action == 'add' || (GETPOST('add') && $action != 'update')) || GETPOST('ac // Delete line from delete picto if ($action == 'delete') { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."default_values WHERE rowid = ".$db->escape($id); - // Delete const - $result = $db->query($sql); - if ($result >= 0) - { - setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs'); - } else { - dol_print_error($db); + $object->id=$id; + $result=$object->delete($user); + $result=$object->update($user); + if ($result<0) { + $action = ''; + setEventMessages($object->error,$object->errors,'errors'); } } @@ -323,39 +337,27 @@ print '\n"; print ''; +$result=$object->fetchAll( $sortorder, $sortfield, 0, 0, array('t.type'=>$mode,'t.entity'=>array($user->entity,$conf->entity))); -// Show constants -$sql = "SELECT rowid, entity, type, page, param, value"; -$sql .= " FROM ".MAIN_DB_PREFIX."default_values"; -$sql .= " WHERE type = '".$db->escape($mode)."'"; -$sql .= " AND entity IN (".$user->entity.",".$conf->entity.")"; -$sql .= $db->order($sortfield, $sortorder); - -dol_syslog("translation::select from table", LOG_DEBUG); -$result = $db->query($sql); -if ($result) -{ - $num = $db->num_rows($result); - $i = 0; - - while ($i < $num) +if (!is_array($result) && $result<0) { + setEventMessages($object->error, $object->errors,'errors'); +} else { + foreach($result as $key=>$defaultvalue) { - $obj = $db->fetch_object($result); - print "\n"; print ''; // Page print ''; - if ($action != 'edit' || GETPOST('rowid', 'int') != $obj->rowid) print $obj->page; - else print ''; + if ($action != 'edit' || GETPOST('rowid', 'int') != $defaultvalue->rowid) print $defaultvalue->page; + else print ''; print ''."\n"; // Field print ''; - if ($action != 'edit' || GETPOST('rowid') != $obj->rowid) print $obj->param; - else print ''; + if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->rowid) print $defaultvalue->param; + else print ''; print ''."\n"; // Value @@ -367,8 +369,8 @@ if ($result) print ''; print ''; */ - if ($action != 'edit' || GETPOST('rowid') != $obj->rowid) print dol_escape_htmltag($obj->value); - else print ''; + if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->rowid) print dol_escape_htmltag($defaultvalue->value); + else print ''; print ''; } @@ -376,14 +378,14 @@ if ($result) // Actions print ''; - if ($action != 'edit' || GETPOST('rowid') != $obj->rowid) + if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->id) { - print ''.img_edit().''; - print ''.img_delete().''; + print ''.img_edit().''; + print ''.img_delete().''; } else { print ''; print ''; - print '
'; + print '
'; print ''; print ''; } @@ -393,8 +395,6 @@ if ($result) print "\n"; $i++; } -} else { - dol_print_error($db); } print ''; diff --git a/htdocs/core/class/defaultvalues.class.php b/htdocs/core/class/defaultvalues.class.php new file mode 100644 index 00000000000..0552a2ed90e --- /dev/null +++ b/htdocs/core/class/defaultvalues.class.php @@ -0,0 +1,359 @@ + + * Copyright (C) 2021 Florian HENRY + * + * 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 3 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, see . + */ + +/** + * \file htdocs/code/class/defaultvalues.class.php + * \brief This file is a CRUD class file for DefaultValues (Create/Read/Update/Delete) + */ + +// Put here all includes required by your class file +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; +//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; +//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; + +/** + * Class for MyObject + */ +class DefaultValues extends CommonObject +{ + /** + * @var string ID to identify managed object. + */ + public $element = 'defaultvalues'; + + /** + * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management. + */ + public $table_element = 'default_values'; + + /** + * @var int Does this object support multicompany module ? + * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table + */ + public $ismultientitymanaged = 1; + + /** + * @var int Does object support extrafields ? 0=No, 1=Yes + */ + public $isextrafieldmanaged = 0; + + /** + * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png + */ + public $picto = ''; + + /** + * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password') + * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)" + * 'label' the translation key. + * 'picto' is code of a picto to show before value in forms + * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM) + * 'position' is the sort order of field. + * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). + * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing) + * 'noteditable' says if field is not editable (1 or 0) + * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created. + * 'index' if we want an index in database. + * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...). + * 'searchall' is 1 if we want to search in this field when making a search from the quick search button. + * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8). + * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'maxwidth200', 'wordbreak', 'tdoverflowmax200' + * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click. + * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record + * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code. + * 'arraykeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel") + * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1. + * 'comment' is not used. You can store here any text of your choice. It is not used by application. + * + * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor. + */ + + // BEGIN MODULEBUILDER PROPERTIES + /** + * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. + */ + public $fields=array( + 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10), + 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15, 'index'=>1), + 'type' =>array('type'=>'varchar(10)', 'label'=>'Type', 'enabled'=>1, 'visible'=>-1, 'position'=>20), + 'user_id' =>array('type'=>'integer', 'label'=>'Userid', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>25), + 'page' =>array('type'=>'varchar(255)', 'label'=>'RelativeURL', 'enabled'=>1, 'visible'=>-1, 'position'=>30), + 'param' =>array('type'=>'varchar(255)', 'label'=>'Field', 'enabled'=>1, 'visible'=>-1, 'position'=>35), + 'value' =>array('type'=>'varchar(128)', 'label'=>'Value', 'enabled'=>1, 'visible'=>-1, 'position'=>40), + ); + + /** + * @var int ID + */ + public $rowid; + + /** + * @var int Entity + */ + public $entity; + + /** + * @var string Type + */ + public $type; + + /** + * @var int User Id + */ + public $user_id; + + /** + * @var string Page + */ + public $page; + + /** + * @var string Param + */ + public $param; + + /** + * @var string Value + */ + public $value; + // END MODULEBUILDER PROPERTIES + + /** + * Constructor + * + * @param DoliDb $db Database handler + */ + public function __construct(DoliDB $db) + { + global $conf, $langs; + + $this->db = $db; + + if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible'] = 0; + if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled'] = 0; + + // Unset fields that are disabled + foreach ($this->fields as $key => $val) + { + if (isset($val['enabled']) && empty($val['enabled'])) + { + unset($this->fields[$key]); + } + } + + // Translate some data of arrayofkeyval + if (is_object($langs)) + { + foreach ($this->fields as $key => $val) + { + if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) + { + foreach ($val['arrayofkeyval'] as $key2 => $val2) + { + $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2); + } + } + } + } + } + + /** + * Create object into database + * + * @param User $user User that creates + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, Id of created object if OK + */ + public function create(User $user, $notrigger = false) + { + return $this->createCommon($user, $notrigger); + } + + /** + * Clone an object into another one + * + * @param User $user User that creates + * @param int $fromid Id of object to clone + * @return mixed New object created, <0 if KO + */ + public function createFromClone(User $user, $fromid) + { + global $langs, $extrafields; + $error = 0; + + dol_syslog(__METHOD__, LOG_DEBUG); + + $object = new self($this->db); + + $this->db->begin(); + + // Load source object + $result = $object->fetchCommon($fromid); + if ($result > 0 && !empty($object->table_element_line)) $object->fetchLines(); + + + // Reset some properties + unset($object->id); + + // Create clone + $object->context['createfromclone'] = 'createfromclone'; + $result = $object->createCommon($user); + if ($result < 0) { + $error++; + $this->error = $object->error; + $this->errors = $object->errors; + } + + unset($object->context['createfromclone']); + + // End + if (!$error) { + $this->db->commit(); + return $object; + } else { + $this->db->rollback(); + return -1; + } + } + + /** + * Load object in memory from the database + * + * @param int $id Id object + * @param string $ref Ref + * @return int <0 if KO, 0 if not found, >0 if OK + */ + public function fetch($id, $ref = null) + { + $result = $this->fetchCommon($id, $ref); + return $result; + } + + /** + * Load list of objects in memory from the database. + * + * @param string $sortorder Sort Order + * @param string $sortfield Sort field + * @param int $limit limit + * @param int $offset Offset + * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...) + * @param string $filtermode Filter mode (AND or OR) + * @return array|int int <0 if KO, array of pages if OK + */ + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') + { + global $conf; + + dol_syslog(__METHOD__, LOG_DEBUG); + + $records = array(); + + $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'; + // Manage filter + $sqlwhere = array(); + if (count($filter) > 0) { + foreach ($filter as $key => $value) { + if ($key == 't.rowid') { + $sqlwhere[] = $key.'='.$value; + } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) { + $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\''; + } elseif ($key == 'customsql') { + $sqlwhere[] = $value; + } elseif (is_array($value)) { + $sqlwhere[] = $key.' IN ('.implode(',',$value).')'; + } else { + $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; + } + } + } + if (count($sqlwhere) > 0) { + $sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')'; + } + + if (!empty($sortfield)) { + $sql .= $this->db->order($sortfield, $sortorder); + } + if (!empty($limit)) { + $sql .= ' '.$this->db->plimit($limit, $offset); + } + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < ($limit ? min($limit, $num) : $num)) + { + $obj = $this->db->fetch_object($resql); + + $record = new self($this->db); + $record->setVarsFromFetchObj($obj); + + $records[$record->id] = $record; + + $i++; + } + $this->db->free($resql); + + return $records; + } else { + $this->errors[] = 'Error '.$this->db->lasterror(); + dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR); + + return -1; + } + } + + /** + * Update object into database + * + * @param User $user User that modifies + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, >0 if OK + */ + public function update(User $user, $notrigger = false) + { + return $this->updateCommon($user, $notrigger); + } + + /** + * Delete object in database + * + * @param User $user User that deletes + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, >0 if OK + */ + public function delete(User $user, $notrigger = false) + { + return $this->deleteCommon($user, $notrigger); + } + + /** + * Initialise object with example values + * Id must be 0 if object instance is a specimen + * + * @return void + */ + public function initAsSpecimen() + { + $this->initAsSpecimenCommon(); + } +} From 7d3bd131abc8a98bb2b6fcfe06fbace16f434694 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Mon, 1 Mar 2021 19:54:30 +0100 Subject: [PATCH 07/11] default envent status --- htdocs/admin/agenda_other.php | 38 +++++++++++++++++++++-- htdocs/comm/action/card.php | 2 -- htdocs/core/class/defaultvalues.class.php | 11 ++++--- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/htdocs/admin/agenda_other.php b/htdocs/admin/agenda_other.php index f48298f2d53..edcffb00e71 100644 --- a/htdocs/admin/agenda_other.php +++ b/htdocs/admin/agenda_other.php @@ -30,6 +30,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/defaultvalues.class.php'; if (!$user->admin) accessforbidden(); @@ -84,7 +85,31 @@ if ($action == 'set') dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_TYPE', $defaultfilter, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'AGENDA_DEFAULT_FILTER_STATUS', GETPOST('AGENDA_DEFAULT_FILTER_STATUS'), 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'AGENDA_DEFAULT_VIEW', GETPOST('AGENDA_DEFAULT_VIEW'), 'chaine', 0, '', $conf->entity); - dolibarr_set_const($db, 'AGENDA_EVENT_DEFAULT_STATUS', GETPOST('AGENDA_EVENT_DEFAULT_STATUS'), '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)); + if (!is_array($result) && $result<0) { + setEventMessages($defaultValues->error,$defaultValues->errors,'errors'); + } elseif(count($result)>0) { + foreach($result as $defval) { + $defaultValues->id=$defval->id; + $resultDel = $defaultValues->delete($user); + if ($resultDel<0) { + setEventMessages($defaultValues->error,$defaultValues->errors,'errors'); + } + } + } + $defaultValues->type='createform'; + $defaultValues->entity=$conf->entity; + $defaultValues->user_id=0; + $defaultValues->page='comm/action/card.php'; + $defaultValues->param='complete'; + $defaultValues->value=GETPOST('AGENDA_EVENT_DEFAULT_STATUS'); + $resultCreat=$defaultValues->create($user); + if ($resultCreat<0) { + setEventMessages($defaultValues->error,$defaultValues->errors,'errors'); + } + } elseif ($action == 'specimen') // For orders { $modele = GETPOST('module', 'alpha'); @@ -353,12 +378,21 @@ if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) $formactions->select_type_actions($conf->global->AGENDA_USE_EVENT_TYPE_DEFAULT, "AGENDA_USE_EVENT_TYPE_DEFAULT", 'systemauto', 0, 1); print ''."\n"; } + // AGENDA_EVENT_DEFAULT_STATUS print ''."\n"; print ''.$langs->trans("AGENDA_EVENT_DEFAULT_STATUS").''."\n"; print ' '."\n"; print ''."\n"; -$formactions->form_select_status_action('agenda', $conf->global->AGENDA_EVENT_DEFAULT_STATUS, 1, "AGENDA_EVENT_DEFAULT_STATUS", 0, 1, 'maxwidth200'); +$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)); +if (!is_array($result) && $result<0) { + setEventMessages($defaultValues->error,$defaultValues->errors,'errors'); +} elseif(count($result)>0) { + $defval=reset($result)->value; +} +$formactions->form_select_status_action('agenda', $defval, 1, "AGENDA_EVENT_DEFAULT_STATUS", 0, 1, 'maxwidth200'); print ''."\n"; // AGENDA_DEFAULT_FILTER_TYPE diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index f3ad41eb7f2..a44747b0d7a 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -1050,13 +1050,11 @@ if ($action == 'create') // Status print ''.$langs->trans("Status").' / '.$langs->trans("Percentage").''; print ''; - $percent = -1; if (GETPOSTISSET('status')) $percent = GETPOST('status'); elseif (GETPOSTISSET('percentage')) $percent = GETPOST('percentage'); else { if (GETPOST('complete') == '0' || GETPOST("afaire") == 1) $percent = '0'; elseif (GETPOST('complete') == 100 || GETPOST("afaire") == 2) $percent = 100; - elseif (isset($conf->global->AGENDA_EVENT_DEFAULT_STATUS) && $conf->global->AGENDA_EVENT_DEFAULT_STATUS!=='na') $percent = $conf->global->AGENDA_EVENT_DEFAULT_STATUS; } $formactions->form_select_status_action('formaction', $percent, 1, 'complete', 0, 0, 'maxwidth200'); print ''; diff --git a/htdocs/core/class/defaultvalues.class.php b/htdocs/core/class/defaultvalues.class.php index 0552a2ed90e..c43d3ae121c 100644 --- a/htdocs/core/class/defaultvalues.class.php +++ b/htdocs/core/class/defaultvalues.class.php @@ -235,12 +235,11 @@ class DefaultValues extends CommonObject * Load object in memory from the database * * @param int $id Id object - * @param string $ref Ref * @return int <0 if KO, 0 if not found, >0 if OK */ - public function fetch($id, $ref = null) + public function fetch($id) { - $result = $this->fetchCommon($id, $ref); + $result = $this->fetchCommon($id, null); return $result; } @@ -272,11 +271,13 @@ class DefaultValues extends CommonObject $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { - if ($key == 't.rowid') { + if ($key == 't.rowid' || ($key == 't.entity' && !is_array($value)) || $key == 't.user_id') { $sqlwhere[] = $key.'='.$value; } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) { $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\''; - } elseif ($key == 'customsql') { + } elseif ($key == 't.page' || $key == 't.param' || $key == 't.type'){ + $sqlwhere[] = $key.' = \''.$this->db->escape($value).'\''; + } elseif ($key == 'customsql') { $sqlwhere[] = $value; } elseif (is_array($value)) { $sqlwhere[] = $key.' IN ('.implode(',',$value).')'; From f62386a6a57a2f429a8caf503d2b27488e320f7b Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Mon, 1 Mar 2021 20:36:42 +0100 Subject: [PATCH 08/11] set Default values as CURD classes --- htdocs/admin/agenda_other.php | 4 +- htdocs/admin/defaultvalues.php | 22 +++++----- htdocs/core/class/defaultvalues.class.php | 9 ++-- htdocs/user/class/user.class.php | 50 +++++++++++------------ 4 files changed, 42 insertions(+), 43 deletions(-) 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; } /** From 32ef55cd9e227db6cf32ab1cfe11c65da9cf949b Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Mon, 1 Mar 2021 20:58:02 +0100 Subject: [PATCH 09/11] working default status/percent for event actioncomm --- htdocs/comm/action/card.php | 2 +- htdocs/core/class/defaultvalues.class.php | 4 +--- htdocs/core/lib/functions.lib.php | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 3b539895348..f572379d42e 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -1072,7 +1072,7 @@ if ($action == 'create') { // Status print ''.$langs->trans("Status").' / '.$langs->trans("Percentage").''; print ''; - $percent = -1; + $percent = GETPOST('complete')!=='' ? GETPOST('complete') : -1; if (GETPOSTISSET('status')) { $percent = GETPOST('status'); } elseif (GETPOSTISSET('percentage')) { diff --git a/htdocs/core/class/defaultvalues.class.php b/htdocs/core/class/defaultvalues.class.php index ae5ed6e92fb..2f70dda34e5 100644 --- a/htdocs/core/class/defaultvalues.class.php +++ b/htdocs/core/class/defaultvalues.class.php @@ -295,12 +295,10 @@ 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/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index e296fa5874e..9b35d8a2eda 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -311,7 +311,7 @@ function GETPOSTISSET($paramname) /** * Return value of a param into GET or POST supervariable. - * Use the property $user->default_values[path]['creatform'] and/or $user->default_values[path]['filters'] and/or $user->default_values[path]['sortorder'] + * Use the property $user->default_values[path]['createform'] and/or $user->default_values[path]['filters'] and/or $user->default_values[path]['sortorder'] * Note: The property $user->default_values is loaded by main.php when loading the user. * * @param string $paramname Name of parameter to found From 54d35fa59fe2ff680cbfe7fa8aae95838fcde599 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 1 Mar 2021 20:00:32 +0000 Subject: [PATCH 10/11] Fixing style errors. --- htdocs/admin/agenda_other.php | 19 ++++++++-------- htdocs/admin/defaultvalues.php | 27 ++++++++++------------- htdocs/core/class/defaultvalues.class.php | 25 ++++++++------------- htdocs/user/class/user.class.php | 9 ++++---- 4 files changed, 34 insertions(+), 46 deletions(-) diff --git a/htdocs/admin/agenda_other.php b/htdocs/admin/agenda_other.php index 9e2f6acaebb..c355131b48b 100644 --- a/htdocs/admin/agenda_other.php +++ b/htdocs/admin/agenda_other.php @@ -83,15 +83,15 @@ 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', 't.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) { - foreach($result as $defval) { + setEventMessages($defaultValues->error, $defaultValues->errors, 'errors'); + } elseif (count($result)>0) { + foreach ($result as $defval) { $defaultValues->id=$defval->id; $resultDel = $defaultValues->delete($user); if ($resultDel<0) { - setEventMessages($defaultValues->error,$defaultValues->errors,'errors'); + setEventMessages($defaultValues->error, $defaultValues->errors, 'errors'); } } } @@ -103,9 +103,8 @@ if ($action == 'set') { $defaultValues->value=GETPOST('AGENDA_EVENT_DEFAULT_STATUS'); $resultCreat=$defaultValues->create($user); if ($resultCreat<0) { - setEventMessages($defaultValues->error,$defaultValues->errors,'errors'); + setEventMessages($defaultValues->error, $defaultValues->errors, 'errors'); } - } elseif ($action == 'specimen') { // For orders $modele = GETPOST('module', 'alpha'); @@ -358,10 +357,10 @@ 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', 't.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) { + setEventMessages($defaultValues->error, $defaultValues->errors, 'errors'); +} elseif (count($result)>0) { $defval=reset($result)->value; } $formactions->form_select_status_action('agenda', $defval, 1, "AGENDA_EVENT_DEFAULT_STATUS", 0, 1, 'maxwidth200'); diff --git a/htdocs/admin/defaultvalues.php b/htdocs/admin/defaultvalues.php index a6780df7b6e..14bccefcbd3 100644 --- a/htdocs/admin/defaultvalues.php +++ b/htdocs/admin/defaultvalues.php @@ -149,7 +149,7 @@ if (($action == 'add' || (GETPOST('add') && $action != 'update')) || GETPOST('ac $result=$object->create($user); if ($result<0) { $action = ''; - setEventMessages($object->error,$object->errors,'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } else { setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); $action = ""; @@ -158,8 +158,7 @@ if (($action == 'add' || (GETPOST('add') && $action != 'update')) || GETPOST('ac $defaultvalue = ''; } } - if (GETPOST('actionmodify')) - { + if (GETPOST('actionmodify')) { $object->id=$id; $object->type=$mode; $object->page=$urlpage; @@ -169,7 +168,7 @@ if (($action == 'add' || (GETPOST('add') && $action != 'update')) || GETPOST('ac $result=$object->update($user); if ($result<0) { $action = ''; - setEventMessages($object->error,$object->errors,'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } else { setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); $action = ""; @@ -182,13 +181,12 @@ if (($action == 'add' || (GETPOST('add') && $action != 'update')) || GETPOST('ac } // Delete line from delete picto -if ($action == 'delete') -{ +if ($action == 'delete') { $object->id=$id; $result=$object->delete($user); if ($result<0) { $action = ''; - setEventMessages($object->error,$object->errors,'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } @@ -356,13 +354,12 @@ print '\n"; print ''; -$result=$object->fetchAll( $sortorder, $sortfield, 0, 0, array('t.type'=>$mode,'t.entity'=>array($user->entity,$conf->entity))); +$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'); + setEventMessages($object->error, $object->errors, 'errors'); } elseif (count($result)>0) { - foreach($result as $key=>$defaultvalue) { + foreach ($result as $key=>$defaultvalue) { print "\n"; print ''; @@ -383,10 +380,10 @@ if (!is_array($result) && $result<0) { if ($mode != 'focus' && $mode != 'mandatory') { print ''; /*print ''; - print ''; - print ''; - print ''; - */ + print ''; + print ''; + print ''; + */ if ($action != 'edit' || GETPOST('rowid') != $defaultvalue->id) print dol_escape_htmltag($defaultvalue->value); else print ''; print ''; diff --git a/htdocs/core/class/defaultvalues.class.php b/htdocs/core/class/defaultvalues.class.php index 2f70dda34e5..4c399bbd5e5 100644 --- a/htdocs/core/class/defaultvalues.class.php +++ b/htdocs/core/class/defaultvalues.class.php @@ -148,23 +148,17 @@ class DefaultValues extends CommonObject if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled'] = 0; // Unset fields that are disabled - foreach ($this->fields as $key => $val) - { - if (isset($val['enabled']) && empty($val['enabled'])) - { + foreach ($this->fields as $key => $val) { + if (isset($val['enabled']) && empty($val['enabled'])) { unset($this->fields[$key]); } } // Translate some data of arrayofkeyval - if (is_object($langs)) - { - foreach ($this->fields as $key => $val) - { - if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) - { - foreach ($val['arrayofkeyval'] as $key2 => $val2) - { + if (is_object($langs)) { + foreach ($this->fields as $key => $val) { + if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) { + foreach ($val['arrayofkeyval'] as $key2 => $val2) { $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2); } } @@ -274,12 +268,12 @@ class DefaultValues extends CommonObject $sqlwhere[] = $key.'='.$value; } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) { $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\''; - } elseif ($key == 't.page' || $key == 't.param' || $key == 't.type'){ + } elseif ($key == 't.page' || $key == 't.param' || $key == 't.type') { $sqlwhere[] = $key.' = \''.$this->db->escape($value).'\''; } elseif ($key == 'customsql') { $sqlwhere[] = $value; } elseif (is_array($value)) { - $sqlwhere[] = $key.' IN ('.implode(',',$value).')'; + $sqlwhere[] = $key.' IN ('.implode(',', $value).')'; } else { $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; } @@ -300,8 +294,7 @@ class DefaultValues extends CommonObject if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - while ($i < ($limit ? min($limit, $num) : $num)) - { + while ($i < ($limit ? min($limit, $num) : $num)) { $obj = $this->db->fetch_object($resql); $record = new self($this->db); diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index bacbfa32f67..6e79e5763b6 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -612,19 +612,18 @@ class User extends CommonObject { global $conf; if (!empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) { - // 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))); + $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'); + setEventMessages($defaultValues->error, $defaultValues->errors, 'errors'); dol_print_error($this->db); return -1; - } elseif(count($result)>0) { - foreach($result as $defval) { + } elseif (count($result)>0) { + foreach ($result as $defval) { if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) { $pagewithoutquerystring = $defval->page; $pagequeries = ''; From 3a00952cd1005dee192e3e0873235857600910da Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 2 Mar 2021 14:44:31 +0100 Subject: [PATCH 11/11] Update user.class.php --- htdocs/user/class/user.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 6e79e5763b6..d0ef0c03adc 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -616,13 +616,13 @@ class User extends CommonObject 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))); + $result = $defaultValues->fetchAll('', '', 0, 0, array('t.user_id'=>array(0, $this->id), 'entity'=>array($this->entity, $conf->entity))); // User 0 (all) + me (if defined) - if (!is_array($result) && $result<0) { + if (!is_array($result) && $result < 0) { setEventMessages($defaultValues->error, $defaultValues->errors, 'errors'); dol_print_error($this->db); return -1; - } elseif (count($result)>0) { + } elseif (count($result) > 0) { foreach ($result as $defval) { if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) { $pagewithoutquerystring = $defval->page;