From f68c408dbc528ce0381414c1c05f298467e6658c Mon Sep 17 00:00:00 2001 From: rassakali Date: Sat, 15 Apr 2017 08:35:23 +0200 Subject: [PATCH 01/22] Update subscription.php Fix issue #6694 --- htdocs/adherents/subscription.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/adherents/subscription.php b/htdocs/adherents/subscription.php index cc7fbef58f5..3d22ae336fb 100644 --- a/htdocs/adherents/subscription.php +++ b/htdocs/adherents/subscription.php @@ -89,14 +89,14 @@ if ($rowid) $caneditfieldmember=$user->rights->adherent->creer; } +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +$hookmanager->initHooks(array('subscription')); + // PDF $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0)); $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); - - - /* * Actions */ From a52db08cd6d0620b6069b8e89e04722874c48cb6 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Tue, 18 Apr 2017 15:25:04 +0200 Subject: [PATCH 02/22] NEW : Add module resources import/export --- htdocs/core/class/ctyperesource.class.php | 500 ++++++++++++++++++++++ htdocs/core/modules/modResource.class.php | 163 +++---- htdocs/langs/en_US/resource.lang | 5 + 3 files changed, 561 insertions(+), 107 deletions(-) create mode 100644 htdocs/core/class/ctyperesource.class.php diff --git a/htdocs/core/class/ctyperesource.class.php b/htdocs/core/class/ctyperesource.class.php new file mode 100644 index 00000000000..ee899ad6b86 --- /dev/null +++ b/htdocs/core/class/ctyperesource.class.php @@ -0,0 +1,500 @@ + + * Copyright (C) 2014-2016 Juanjo Menent + * Copyright (C) 2015 Florian Henry + * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) ---Put here your own copyright and developer email--- + * + * 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 resource/ctyperesource.class.php + * \ingroup resource + */ + +/** + * Class Ctyperesource + * + * Put here description of your class + * + * @see CommonObject + */ +class Ctyperesource +{ + /** + * @var string Id to identify managed objects + */ + public $element = 'ctyperesource'; + /** + * @var string Name of table without prefix where object is stored + */ + public $table_element = 'c_type_resource'; + + /** + * @var CtyperesourceLine[] Lines + */ + public $lines = array(); + + /** + */ + + public $code; + public $label; + public $active; + + /** + */ + + + /** + * Constructor + * + * @param DoliDb $db Database handler + */ + public function __construct(DoliDB $db) + { + $this->db = $db; + } + + /** + * 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) + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $error = 0; + + // Clean parameters + + if (isset($this->code)) { + $this->code = trim($this->code); + } + if (isset($this->label)) { + $this->label = trim($this->label); + } + if (isset($this->active)) { + $this->active = trim($this->active); + } + + + + // Check parameters + // Put here code to add control on parameters values + + // Insert request + $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; + + $sql.= 'code,'; + $sql.= 'label'; + $sql.= 'active'; + + + $sql .= ') VALUES ('; + + $sql .= ' '.(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").','; + $sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").','; + $sql .= ' '.(! isset($this->active)?'NULL':$this->active); + + + $sql .= ')'; + + $this->db->begin(); + + $resql = $this->db->query($sql); + if (!$resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); + } + + if (!$error) { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); + + if (!$notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action to call a trigger. + + //// Call triggers + //$result=$this->call_trigger('MYOBJECT_CREATE',$user); + //if ($result < 0) $error++; + //// End call triggers + } + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + + return - 1 * $error; + } else { + $this->db->commit(); + + return $this->id; + } + } + + /** + * 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,$code='',$label='') + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = 'SELECT'; + $sql .= ' t.rowid,'; + + $sql .= " t.code,"; + $sql .= " t.label,"; + $sql .= " t.active"; + + + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; + if ($id) $sql.= " WHERE t.id = ".$id; + elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; + elseif ($label) $sql.= " WHERE t.label = '".$this->db->escape($label)."'"; + + + $resql = $this->db->query($sql); + if ($resql) { + $numrows = $this->db->num_rows($resql); + if ($numrows) { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + + $this->code = $obj->code; + $this->label = $obj->label; + $this->active = $obj->active; + + + } + + // Retrieve all extrafields for invoice + // fetch optionals attributes and labels + /* + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + $extrafields=new ExtraFields($this->db); + $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true); + $this->fetch_optionals($this->id,$extralabels); + */ + + // $this->fetch_lines(); + + $this->db->free($resql); + + if ($numrows) { + return 1; + } else { + return 0; + } + } else { + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); + + return - 1; + } + } + + /** + * Load object in memory from the database + * + * @param string $sortorder Sort Order + * @param string $sortfield Sort field + * @param int $limit offset limit + * @param int $offset offset limit + * @param array $filter filter array + * @param string $filtermode filter mode (AND or OR) + * + * @return int <0 if KO, >0 if OK + */ + public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = 'SELECT'; + $sql .= ' t.rowid,'; + + $sql .= " t.code,"; + $sql .= " t.label,"; + $sql .= " t.active"; + + + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; + + // Manage filter + $sqlwhere = array(); + if (count($filter) > 0) { + foreach ($filter as $key => $value) { + $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; + } + } + + if (count($sqlwhere) > 0) { + $sql .= ' WHERE ' . 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); + + while ($obj = $this->db->fetch_object($resql)) { + $line = new self($this->db); + + $line->id = $obj->rowid; + + $line->code = $obj->code; + $line->label = $obj->label; + $line->active = $obj->active; + + + } + $this->db->free($resql); + + return $num; + } else { + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . implode(',', $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) + { + $error = 0; + + dol_syslog(__METHOD__, LOG_DEBUG); + + // Clean parameters + + if (isset($this->code)) { + $this->code = trim($this->code); + } + if (isset($this->label)) { + $this->label = trim($this->label); + } + if (isset($this->active)) { + $this->active = trim($this->active); + } + + // Check parameters + // Put here code to add a control on parameters values + + // Update request + $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; + + $sql .= ' code = '.(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").','; + $sql .= ' label = '.(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").','; + $sql .= ' active = '.(isset($this->active)?$this->active:"null"); + + + $sql .= ' WHERE rowid=' . $this->id; + + $this->db->begin(); + + $resql = $this->db->query($sql); + if (!$resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); + } + + if (!$error && !$notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //$result=$this->call_trigger('MYOBJECT_MODIFY',$user); + //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} + //// End call triggers + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + + return - 1 * $error; + } else { + $this->db->commit(); + + return 1; + } + } + + /** + * 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) + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $error = 0; + + $this->db->begin(); + + if (!$error) { + if (!$notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //$result=$this->call_trigger('MYOBJECT_DELETE',$user); + //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} + //// End call triggers + } + } + + // If you need to delete child tables to, you can insert them here + + if (!$error) { + $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; + $sql .= ' WHERE rowid=' . $this->id; + + $resql = $this->db->query($sql); + if (!$resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); + } + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + + return - 1 * $error; + } else { + $this->db->commit(); + + return 1; + } + } + + /** + * Load an object from its id and create a new one in database + * + * @param int $fromid Id of object to clone + * + * @return int New id of clone + */ + public function createFromClone($fromid) + { + dol_syslog(__METHOD__, LOG_DEBUG); + + global $user; + $error = 0; + $object = new Ctyperesource($this->db); + + $this->db->begin(); + + // Load source object + $object->fetch($fromid); + // Reset object + $object->id = 0; + + // Clear fields + // ... + + // Create clone + $result = $object->create($user); + + // Other options + if ($result < 0) { + $error ++; + $this->errors = $object->errors; + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); + } + + // End + if (!$error) { + $this->db->commit(); + + return $object->id; + } else { + $this->db->rollback(); + + return - 1; + } + } + + /** + * Initialise object with example values + * Id must be 0 if object instance is a specimen + * + * @return void + */ + public function initAsSpecimen() + { + $this->id = 0; + + $this->code = ''; + $this->label = ''; + $this->active = ''; + } + +} + +/** + * Class CtyperesourceLine + */ +class CtyperesourceLine +{ + /** + * @var int ID + */ + public $id; + /** + * @var mixed Sample line property 1 + */ + + public $code; + public $label; + public $active; + + /** + * @var mixed Sample line property 2 + */ + +} diff --git a/htdocs/core/modules/modResource.class.php b/htdocs/core/modules/modResource.class.php index d3aa3405d0b..f6674bdcfd7 100644 --- a/htdocs/core/modules/modResource.class.php +++ b/htdocs/core/modules/modResource.class.php @@ -201,22 +201,6 @@ class modResource extends DolibarrModules $this->menu = 1; // This module add menu entries. They are coded into menu manager. - // Add here list of permission defined by - // an id, a label, a boolean and two constant strings. - // Example: - //// Permission id (must not be already used) - //$this->rights[$r][0] = 2000; - //// Permission label - //$this->rights[$r][1] = 'Permision label'; - //// Permission by default for new user (0/1) - //$this->rights[$r][3] = 0; - //// In php code, permission will be checked by test - //// if ($user->rights->permkey->level1->level2) - //$this->rights[$r][4] = 'level1'; - //// In php code, permission will be checked by test - //// if ($user->rights->permkey->level1->level2) - //$this->rights[$r][5] = 'level2'; - //$r++; // Main menu entries $this->menu = array(); // List of menus to add $r = 0; @@ -267,98 +251,63 @@ class modResource extends DolibarrModules 'user'=> 0 ); - // Exports - $r = 1; - // Example: - //$this->export_code[$r]=$this->rights_class.'_'.$r; - //// Translation key (used only if key ExportDataset_xxx_z not found) - //$this->export_label[$r]='CustomersInvoicesAndInvoiceLines'; - //// Condition to show export in list (ie: '$user->id==3'). - //// Set to 1 to always show when module is enabled. - //$this->export_enabled[$r]='1'; - //$this->export_permission[$r]=array(array("facture","facture","export")); - //$this->export_fields_array[$r]=array( - // 's.rowid'=>"IdCompany", - // 's.nom'=>'CompanyName', - // 's.address'=>'Address', - // 's.cp'=>'Zip', - // 's.ville'=>'Town', - // 's.fk_pays'=>'Country', - // 's.tel'=>'Phone', - // 's.siren'=>'ProfId1', - // 's.siret'=>'ProfId2', - // 's.ape'=>'ProfId3', - // 's.idprof4'=>'ProfId4', - // 's.code_compta'=>'CustomerAccountancyCode', - // 's.code_compta_fournisseur'=>'SupplierAccountancyCode', - // 'f.rowid'=>"InvoiceId", - // 'f.facnumber'=>"InvoiceRef", - // 'f.datec'=>"InvoiceDateCreation", - // 'f.datef'=>"DateInvoice", - // 'f.total'=>"TotalHT", - // 'f.total_ttc'=>"TotalTTC", - // 'f.tva'=>"TotalVAT", - // 'f.paye'=>"InvoicePaid", - // 'f.fk_statut'=>'InvoiceStatus', - // 'f.note'=>"InvoiceNote", - // 'fd.rowid'=>'LineId', - // 'fd.description'=>"LineDescription", - // 'fd.price'=>"LineUnitPrice", - // 'fd.tva_tx'=>"LineVATRate", - // 'fd.qty'=>"LineQty", - // 'fd.total_ht'=>"LineTotalHT", - // 'fd.total_tva'=>"LineTotalTVA", - // 'fd.total_ttc'=>"LineTotalTTC", - // 'fd.date_start'=>"DateStart", - // 'fd.date_end'=>"DateEnd", - // 'fd.fk_product'=>'ProductId', - // 'p.ref'=>'ProductRef' - //); - //$this->export_entities_array[$r]=array('s.rowid'=>"company", - // 's.nom'=>'company', - // 's.address'=>'company', - // 's.cp'=>'company', - // 's.ville'=>'company', - // 's.fk_pays'=>'company', - // 's.tel'=>'company', - // 's.siren'=>'company', - // 's.siret'=>'company', - // 's.ape'=>'company', - // 's.idprof4'=>'company', - // 's.code_compta'=>'company', - // 's.code_compta_fournisseur'=>'company', - // 'f.rowid'=>"invoice", - // 'f.facnumber'=>"invoice", - // 'f.datec'=>"invoice", - // 'f.datef'=>"invoice", - // 'f.total'=>"invoice", - // 'f.total_ttc'=>"invoice", - // 'f.tva'=>"invoice", - // 'f.paye'=>"invoice", - // 'f.fk_statut'=>'invoice', - // 'f.note'=>"invoice", - // 'fd.rowid'=>'invoice_line', - // 'fd.description'=>"invoice_line", - // 'fd.price'=>"invoice_line", - // 'fd.total_ht'=>"invoice_line", - // 'fd.total_tva'=>"invoice_line", - // 'fd.total_ttc'=>"invoice_line", - // 'fd.tva_tx'=>"invoice_line", - // 'fd.qty'=>"invoice_line", - // 'fd.date_start'=>"invoice_line", - // 'fd.date_end'=>"invoice_line", - // 'fd.fk_product'=>'product', - // 'p.ref'=>'product' - //); - //$this->export_sql_start[$r] = 'SELECT DISTINCT '; - //$this->export_sql_end[$r] = ' FROM (' . MAIN_DB_PREFIX . 'facture as f, ' - // . MAIN_DB_PREFIX . 'facturedet as fd, ' . MAIN_DB_PREFIX . 'societe as s)'; - //$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX - // . 'product as p on (fd.fk_product = p.rowid)'; - //$this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid ' - // . 'AND f.rowid = fd.fk_facture'; - //$r++; + // Exports + //-------- + $r=0; + + $r++; + $this->export_code[$r]=$this->rights_class.'_'.$r; + $this->export_label[$r]="ResourceSingular"; // Translation key (used only if key ExportDataset_xxx_z not found) + $this->export_permission[$r]=array(array("resource","read")); + $this->export_fields_array[$r]=array('r.rowid'=>'IdResource','r.ref'=>'ResourceFormLabel_ref','c.code'=>'ResourceTypeCode','c.label'=>'ResourceType','r.description'=>'ResourceFormLabel_description','r.note_private'=>"NotePrivate",'r.note_public'=>"NotePublic",'r.asset_number'=>'AssetNumber','r.datec'=>"DateCreation",'r.tms'=>"DateLastModification"); + $this->export_TypeFields_array[$r]=array('r.rowid'=>'List:resource:ref','r.ref'=>'Text','r.asset_number'=>'Text','r.description'=>'Text','c.code'=>'Text','c.label'=>'List:c_type_resource:label','r.datec'=>'Date','r.tms'=>'Date','r.note_private'=>'Text','r.note_public'=>'Text'); + $this->export_entities_array[$r]=array('r.rowid'=>'resource','r.ref'=>'resource','c.code'=>'resource','c.label'=>'resource','r.description'=>'resource','r.note_private'=>"resource",'r.resource'=>"resource",'r.asset_number'=>'resource','r.datec'=>"resource",'r.tms'=>"resource"); + $keyforselect='resource'; $keyforelement='resource'; $keyforaliasextra='extra'; + include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; + + $this->export_dependencies_array[$r]=array('resource'=>array('r.rowid')); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them. + $this->export_sql_start[$r]='SELECT DISTINCT '; + $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'resource as r '; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_type_resource as c ON c.rowid=r.fk_code_type_resource'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'resource_extrafields as extra ON extra.fk_object = c.rowid'; + $this->export_sql_end[$r] .=' AND r.entity IN ('.getEntity('resource',1).')'; + + + // Imports + //-------- + $r=0; + + // Import list of third parties and attributes + $r++; + $this->import_code[$r]=$this->rights_class.'_'.$r; + $this->import_label[$r]='ImportDataset_resource_1'; + $this->import_icon[$r]='resource'; + $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon + $this->import_tables_array[$r]=array('r'=>MAIN_DB_PREFIX.'resource','extra'=>MAIN_DB_PREFIX.'resource_extrafields'); // List of tables to insert into (insert done in same order) + $this->import_fields_array[$r]=array('r.ref'=>"ResourceFormLabel_ref*",'r.fk_code_type_resource'=>'ResourceTypeCode','r.description'=>'ResourceFormLabel_description','r.note_private'=>"NotePrivate",'r.note_public'=>"NotePublic",'r.asset_number'=>'AssetNumber','r.datec'=>'DateCreation'); + // Add extra fields + $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'resource' AND entity = ".$conf->entity; + $resql=$this->db->query($sql); + if ($resql) // This can fail when class is used on old database (during migration for example) + { + while ($obj=$this->db->fetch_object($resql)) + { + $fieldname='extra.'.$obj->name; + $fieldlabel=ucfirst($obj->label); + $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':''); + } + } + // End add extra fields + $this->import_fieldshidden_array[$r]=array('r.fk_user_author'=>'user->id','extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'resource'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) + $this->import_convertvalue_array[$r]=array( + 'r.fk_code_type_resource'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/core/class/ctyperesource.class.php','class'=>'Ctyperesource','method'=>'fetch','dict'=>'DictionaryResourceType'), + ); + //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t'); + $this->import_regex_array[$r]=array('s.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$'); + $this->import_examplevalues_array[$r]=array('r.ref'=>"REF1",'r.fk_code_type_resource'=>"Code from dictionnary resource type",'r.datec'=>"2017-01-01 or 2017-01-01 12:30:00"); + $this->import_updatekeys_array[$r]=array('r.rf'=>'ResourceFormLabel_ref'); + } /** diff --git a/htdocs/langs/en_US/resource.lang b/htdocs/langs/en_US/resource.lang index f95121db351..5a907f6ba23 100644 --- a/htdocs/langs/en_US/resource.lang +++ b/htdocs/langs/en_US/resource.lang @@ -29,3 +29,8 @@ RessourceSuccessfullyDeleted=Resource successfully deleted DictionaryResourceType=Type of resources SelectResource=Select resource + +IdResource=Id resource +AssetNumber=Serial number +ResourceTypeCode=Resource type code +ImportDataset_resource_1=Resources From 4efb1ba23a2193df98529da643a8848d30ffbdf7 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Tue, 18 Apr 2017 15:27:18 +0200 Subject: [PATCH 03/22] update credentials --- htdocs/core/class/ctyperesource.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/core/class/ctyperesource.class.php b/htdocs/core/class/ctyperesource.class.php index ee899ad6b86..553c0f0d0cd 100644 --- a/htdocs/core/class/ctyperesource.class.php +++ b/htdocs/core/class/ctyperesource.class.php @@ -1,9 +1,8 @@ * Copyright (C) 2014-2016 Juanjo Menent - * Copyright (C) 2015 Florian Henry + * Copyright (C) 2016 Florian Henry * Copyright (C) 2015 Raphaël Doursenaud - * Copyright (C) ---Put here your own copyright and developer email--- * * 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 From 8bb7f858d96c7eca0ab038a760cac031732e22c7 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 18 Apr 2017 16:47:06 +0200 Subject: [PATCH 04/22] fix params order for tha addline() function please check to last param "$request_data->fk_remise_except", I couldn't find a corresponding parameter name in the addline() function --- htdocs/comm/propal/class/api_proposals.class.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index 0440793ceac..ec7ca53357a 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -260,12 +260,9 @@ class Proposals extends DolibarrApi $request_data->localtax2_tx, $request_data->fk_product, $request_data->remise_percent, - $request_data->info_bits, - $request_data->fk_remise_except, 'HT', 0, - $request_data->date_start, - $request_data->date_end, + $request_data->info_bits, $request_data->product_type, $request_data->rang, $request_data->special_code, @@ -273,10 +270,14 @@ class Proposals extends DolibarrApi $request_data->fk_fournprice, $request_data->pa_ht, $request_data->label, + $request_data->date_start, + $request_data->date_end, $request_data->array_options, $request_data->fk_unit, $this->element, $request_data->id + // not used anymore ? + // $request_data->fk_remise_except ); if ($updateRes > 0) { From 213e0d28708d7997e8eec1653dfc3a1db2fb27d6 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Wed, 19 Apr 2017 14:49:12 +0200 Subject: [PATCH 05/22] fix travis --- htdocs/core/class/ctyperesource.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/ctyperesource.class.php b/htdocs/core/class/ctyperesource.class.php index 553c0f0d0cd..1de616210e4 100644 --- a/htdocs/core/class/ctyperesource.class.php +++ b/htdocs/core/class/ctyperesource.class.php @@ -154,7 +154,8 @@ class Ctyperesource * Load object in memory from the database * * @param int $id Id object - * @param string $ref Ref + * @param string $code code + * @param string $label Label * * @return int <0 if KO, 0 if not found, >0 if OK */ From b7f1e74f6f347697bb4b1e7efe3723cf0701f7d4 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Thu, 20 Apr 2017 10:27:44 +0200 Subject: [PATCH 06/22] New SITUATION_DISPLAY_DIFF_ON_PDF feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit allow to display or the progress situation percent value the diférential situation percent value --- htdocs/core/lib/pdf.lib.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 282bdec690e..d1a5e64dce2 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1808,8 +1808,17 @@ function pdf_getlineprogress($object, $i, $outputlangs, $hidedetails = 0, $hookm } if (empty($reshook)) { - if ($object->lines[$i]->special_code == 3) return ''; - if (empty($hidedetails) || $hidedetails > 1) $result.=$object->lines[$i]->situation_percent . '%'; + if ($object->lines[$i]->special_code == 3) return ''; + if (empty($hidedetails) || $hidedetails > 1) + { + if($conf->global->SITUATION_DISPLAY_DIFF_ON_PDF) + { + $prev_progress = $object->lines[$i]->get_prev_progress($object->id); + $result = ($prev_progress - $object->lines[$i]->situation_percent) . '%'; + } + else + $result = $object->lines[$i]->situation_percent . '%'; + } } return $result; } From 1792ff2d3b77ef56e80fa23bb84a767dfb9b799a Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Fri, 21 Apr 2017 09:41:08 +0200 Subject: [PATCH 07/22] oups inverted value --- htdocs/core/lib/pdf.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index d1a5e64dce2..c490a2f66c5 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1814,7 +1814,7 @@ function pdf_getlineprogress($object, $i, $outputlangs, $hidedetails = 0, $hookm if($conf->global->SITUATION_DISPLAY_DIFF_ON_PDF) { $prev_progress = $object->lines[$i]->get_prev_progress($object->id); - $result = ($prev_progress - $object->lines[$i]->situation_percent) . '%'; + $result = ( $object->lines[$i]->situation_percent - $prev_progress) . '%'; } else $result = $object->lines[$i]->situation_percent . '%'; From 058b43f342e895edde8fb483ca8686371430b9ff Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Fri, 28 Apr 2017 16:50:30 +0200 Subject: [PATCH 08/22] display the good value on pdf --- htdocs/core/lib/pdf.lib.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index c490a2f66c5..2fc447daffd 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1853,7 +1853,7 @@ function pdf_getlinetotalexcltax($object,$i,$outputlangs,$hidedetails=0) if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint; } if (empty($reshook)) - { + { if ($object->lines[$i]->special_code == 3) { return $outputlangs->transnoentities("Option"); @@ -1861,9 +1861,16 @@ function pdf_getlinetotalexcltax($object,$i,$outputlangs,$hidedetails=0) if (empty($hidedetails) || $hidedetails > 1) { $total_ht = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_total_ht : $object->lines[$i]->total_ht); + if ($object->lines[$i]->situation_percent > 0 ) + { + $prev_progress = $object->lines[$i]->get_prev_progress($object->id); + $progress = ( $object->lines[$i]->situation_percent - $prev_progress) /100; + $result.=price($sign * ($total_ht/($object->lines[$i]->situation_percent/100)) * $progress, 0, $outputlangs); + } + else $result.=price($sign * $total_ht, 0, $outputlangs); - } } + } return $result; } From ad095d7fb24752c60085f54c44ce9604545970bd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 2 May 2017 14:26:51 +0200 Subject: [PATCH 09/22] NEW Can set margins of PDFs --- htdocs/admin/pdf.php | 45 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/htdocs/admin/pdf.php b/htdocs/admin/pdf.php index b0c32a344ff..2e650c75696 100644 --- a/htdocs/admin/pdf.php +++ b/htdocs/admin/pdf.php @@ -42,15 +42,25 @@ $langs->load("members"); if (! $user->admin) accessforbidden(); $action = GETPOST('action','alpha'); +$cancel = GETPOST('cancel','alpha'); + /* * Actions */ +if ($cancel) { + $action=''; +} + if ($action == 'update') { dolibarr_set_const($db, "MAIN_PDF_FORMAT", $_POST["MAIN_PDF_FORMAT"],'chaine',0,'',$conf->entity); - + + dolibarr_set_const($db, "MAIN_PDF_MARGIN_LEFT", $_POST["MAIN_PDF_MARGIN_LEFT"],'chaine',0,'',$conf->entity); + dolibarr_set_const($db, "MAIN_PDF_MARGIN_RIGHT", $_POST["MAIN_PDF_MARGIN_RIGHT"],'chaine',0,'',$conf->entity); + dolibarr_set_const($db, "MAIN_PDF_MARGIN_TOP", $_POST["MAIN_PDF_MARGIN_TOP"],'chaine',0,'',$conf->entity); + dolibarr_set_const($db, "MAIN_PDF_MARGIN_BOTTOM", $_POST["MAIN_PDF_MARGIN_BOTTOM"],'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_PROFID1_IN_ADDRESS", $_POST["MAIN_PROFID1_IN_ADDRESS"],'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_PROFID2_IN_ADDRESS", $_POST["MAIN_PROFID2_IN_ADDRESS"],'chaine',0,'',$conf->entity); @@ -133,7 +143,20 @@ if ($action == 'edit') // Edit print $formadmin->select_paper_format($selected,'MAIN_PDF_FORMAT'); print ''; - print ''; + print ''.$langs->trans("MAIN_PDF_MARGIN_LEFT").''; + print ''; + print ''; + print ''.$langs->trans("MAIN_PDF_MARGIN_RIGHT").''; + print ''; + print ''; + print ''.$langs->trans("MAIN_PDF_MARGIN_TOP").''; + print ''; + print ''; + print ''.$langs->trans("MAIN_PDF_MARGIN_BOTTOM").''; + print ''; + print ''; + + print ''; print '
'; @@ -270,7 +293,9 @@ if ($action == 'edit') // Edit print ''; print '
'; - print ''; + print ''; + print '   '; + print ''; print '
'; print ''; @@ -314,6 +339,20 @@ else // Show print $pdfformatlabel; print ''; + print ''.$langs->trans("MAIN_PDF_MARGIN_LEFT").''; + print empty($conf->global->MAIN_PDF_MARGIN_LEFT)?10:$conf->global->MAIN_PDF_MARGIN_LEFT; + print ''; + print ''.$langs->trans("MAIN_PDF_MARGIN_RIGHT").''; + print empty($conf->global->MAIN_PDF_MARGIN_RIGHT)?10:$conf->global->MAIN_PDF_MARGIN_RIGHT; + print ''; + print ''.$langs->trans("MAIN_PDF_MARGIN_TOP").''; + print empty($conf->global->MAIN_PDF_MARGIN_TOP)?10:$conf->global->MAIN_PDF_MARGIN_TOP; + print ''; + print ''.$langs->trans("MAIN_PDF_MARGIN_BOTTOM").''; + print empty($conf->global->MAIN_PDF_MARGIN_BOTTOM)?10:$conf->global->MAIN_PDF_MARGIN_BOTTOM; + print ''; + + print ''; print '
'; From 6138d197e4c7290e0a7a5ca3f5ecef45facff734 Mon Sep 17 00:00:00 2001 From: alexis Algoud Date: Tue, 2 May 2017 15:19:55 +0200 Subject: [PATCH 10/22] FIX major issues for inventory - Move all needed declaration from coreobject to commonobject for updateCommon, fetchCommon, deleteCommon, createCommon - Just leave method for child object into coreobject, check later if is useless - debug inventory card, PHP 7.0 compatibility - activate rights for inventory into stock module - add inventory options into stock admin module --- htdocs/admin/inventory.php | 152 -------- htdocs/admin/stock.php | 56 +++ htdocs/core/class/commonobject.class.php | 330 +++++++++++++++--- htdocs/core/class/coreobject.class.php | 255 +------------- htdocs/core/modules/modStock.class.php | 65 +--- .../product/inventory/ajax/ajax.inventory.php | 10 +- htdocs/product/inventory/card.php | 7 +- 7 files changed, 370 insertions(+), 505 deletions(-) delete mode 100644 htdocs/admin/inventory.php diff --git a/htdocs/admin/inventory.php b/htdocs/admin/inventory.php deleted file mode 100644 index 2548494fc79..00000000000 --- a/htdocs/admin/inventory.php +++ /dev/null @@ -1,152 +0,0 @@ - - * Copyright (C) 2015 ATM Consulting - * - * 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 admin/inventory.php - * \ingroup inventory - * \brief This file is an example module setup page - * Put some comments here - */ -// Dolibarr environment -require '../main.inc.php'; - - -// Libraries -require_once DOL_DOCUMENT_ROOT . "/core/lib/admin.lib.php"; -require_once DOL_DOCUMENT_ROOT .'/inventory/lib/inventory.lib.php'; - -// Translations -$langs->load("stock"); -$langs->load("inventory"); - -// Access control -if (! $user->admin) { - accessforbidden(); -} - -// Parameters -$action = GETPOST('action', 'alpha'); - -/* - * Actions - */ -if (preg_match('/set_(.*)/',$action,$reg)) -{ - $code=$reg[1]; - if (dolibarr_set_const($db, $code, GETPOST($code), 'chaine', 0, '', $conf->entity) > 0) - { - header("Location: ".$_SERVER["PHP_SELF"]); - exit; - } - else - { - dol_print_error($db); - } -} - -if (preg_match('/del_(.*)/',$action,$reg)) -{ - $code=$reg[1]; - if (dolibarr_del_const($db, $code, 0) > 0) - { - Header("Location: ".$_SERVER["PHP_SELF"]); - exit; - } - else - { - dol_print_error($db); - } -} - -/* - * View - */ -$page_name = "inventorySetup"; -llxHeader('', $langs->trans($page_name)); - -// Subheader -$linkback = '' - . $langs->trans("BackToModuleList") . ''; -print_fiche_titre($langs->trans($page_name), $linkback); - -// Configuration header -$head = inventoryAdminPrepareHead(); -dol_fiche_head( - $head, - 'settings', - $langs->trans("Module104420Name"), - 0, - "inventory@inventory" -); - -// Setup page goes here -$form=new Form($db); -$var=false; -print ''; -print ''; -print ''."\n"; -print ''; -print ''."\n"; - -// Example with a yes / no select -$var=!$var; -print ''; -print ''; -print ''; -print ''; - -// Example with a yes / no select -$var=!$var; -print ''; -print ''; -print ''; -print ''; - -// Example with a yes / no select -$var=!$var; -print ''; -print ''; -print ''; -print ''; - -print '
'.$langs->trans("Parameters").' '.$langs->trans("Value").'
'.$langs->trans("INVENTORY_DISABLE_VIRTUAL").' '; -print '
'; -print ''; -print ''; -print $form->selectyesno("INVENTORY_DISABLE_VIRTUAL",$conf->global->INVENTORY_DISABLE_VIRTUAL,1); -print ''; -print '
'; -print '
'.$langs->trans("INVENTORY_USE_MIN_PA_IF_NO_LAST_PA").' '; -print '
'; -print ''; -print ''; -print $form->selectyesno("INVENTORY_USE_MIN_PA_IF_NO_LAST_PA",$conf->global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA,1); -print ''; -print '
'; -print '
'.$langs->trans("INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT").' '; -print '
'; -print ''; -print ''; -print $form->selectyesno("INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT",$conf->global->INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT,1); -print ''; -print '
'; -print '
'; - -llxFooter(); - -$db->close(); \ No newline at end of file diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index 1c5a92fb0e8..c8204f213c2 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -432,6 +432,61 @@ if ($virtualdiffersfromphysical) } +print '
'; +if ($conf->global->MAIN_LEVEL_FEATURES >= 2) +{ + $var=false; + print ''; + print ''; + print ''."\n"; + print ''; + print ''."\n"; + + // Example with a yes / no select + $var=!$var; + print ''; + print ''; + print ''; + print ''; + + // Example with a yes / no select + $var=!$var; + print ''; + print ''; + print ''; + print ''; + + // Example with a yes / no select + $var=!$var; + print ''; + print ''; + print ''; + print ''; + + print '
'.$langs->trans("Inventory").'  
'.$langs->trans("INVENTORY_DISABLE_VIRTUAL").' '; + print '
'; + print ''; + print ''; + print $form->selectyesno("INVENTORY_DISABLE_VIRTUAL",$conf->global->INVENTORY_DISABLE_VIRTUAL,1); + print ''; + print '
'; + print '
'.$langs->trans("INVENTORY_USE_MIN_PA_IF_NO_LAST_PA").' '; + print '
'; + print ''; + print ''; + print $form->selectyesno("INVENTORY_USE_MIN_PA_IF_NO_LAST_PA",$conf->global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA,1); + print ''; + print '
'; + print '
'.$langs->trans("INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT").' '; + print '
'; + print ''; + print ''; + print $form->selectyesno("INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT",$conf->global->INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT,1); + print ''; + print '
'; + print '
'; +} + $var=true; print ''; @@ -508,6 +563,7 @@ if ($conf->global->PRODUIT_SOUSPRODUITS) print '
'; + llxFooter(); $db->close(); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 5e5c13056e7..582e00d29fa 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -11,6 +11,7 @@ * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2015 Alexandre Spangaro * Copyright (C) 2016 Bahfir abbes + * Copyright (C) 2017 ATM Consulting * * 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 @@ -4662,7 +4663,159 @@ abstract class CommonObject return $buyPrice; } + /** + * Function test if type is date + * + * @param array $info content informations of field + * @return bool + */ + protected function is_date($info) + { + if(isset($info['type']) && $info['type']=='date') return true; + else return false; + } + /** + * Function test if type is array + * + * @param array $info content informations of field + * @return bool + */ + protected function is_array($info) + { + if(is_array($info)) + { + if(isset($info['type']) && $info['type']=='array') return true; + else return false; + } + else return false; + } + + /** + * Function test if type is null + * + * @param array $info content informations of field + * @return bool + */ + protected function is_null($info) + { + if(is_array($info)) + { + if(isset($info['type']) && $info['type']=='null') return true; + else return false; + } + else return false; + } + + /** + * Function test if type is integer + * + * @param array $info content informations of field + * @return bool + */ + protected function is_int($info) + { + if(is_array($info)) + { + if(isset($info['type']) && ($info['type']=='int' || $info['type']=='integer' )) return true; + else return false; + } + else return false; + } + + /** + * Function test if type is float + * + * @param array $info content informations of field + * @return bool + */ + protected function is_float($info) + { + if(is_array($info)) + { + if(isset($info['type']) && $info['type']=='float') return true; + else return false; + } + else return false; + } + + /** + * Function test if type is text + * + * @param array $info content informations of field + * @return bool + */ + protected function is_text($info) + { + if(is_array($info)) + { + if(isset($info['type']) && $info['type']=='text') return true; + else return false; + } + else return false; + } + + /** + * Function test if is indexed + * + * @param array $info content informations of field + * @return bool + */ + protected function is_index($info) + { + if(is_array($info)) + { + if(isset($info['index']) && $info['index']==true) return true; + else return false; + } + else return false; + } + + /** + * Function to prepare the values to insert + * + * @return array + */ + private function set_save_query() + { + $query=array(); + foreach ($this->fields as $field=>$info) + { + if($this->is_date($info)) + { + if(empty($this->{$field})) + { + $query[$field] = NULL; + } + else + { + $query[$field] = $this->db->idate($this->{$field}); + } + } + else if($this->is_array($info)) + { + $query[$field] = serialize($this->{$field}); + } + else if($this->is_int($info)) + { + $query[$field] = (int) price2num($this->{$field}); + } + else if($this->is_float($info)) + { + $query[$field] = (double) price2num($this->{$field}); + } + elseif($this->is_null($info)) + { + $query[$field] = (is_null($this->{$field}) || (empty($this->{$field}) && $this->{$field}!==0 && $this->{$field}!=='0') ? null : $this->{$field}); + } + else + { + $query[$field] = $this->{$field}; + } + } + + return $query; + } /** * Create object into database @@ -4674,28 +4827,82 @@ abstract class CommonObject */ public function createCommon(User $user, $notrigger = false) { - foreach ($this->fields as $k => $v) { - $keys[] = $k; - $values[] = $this->quote($v); - + $fields = array_merge(array('datec'=>$this->db->idate(dol_now())), $this->set_save_query()); + + foreach ($fields as $k => $v) { + + $keys[] = $k; + $values[] = $this->quote($v); + } - - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$table.' + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.' ( '.implode( ",", $keys ).' ) VALUES ( '.implode( ",", $values ).' ) '; - - $res = $this->query($sql); + $res = $this->db->query( $sql ); if($res===false) { - - return false; + + return false; } // TODO Add triggers - - return true; + + return true; + } + /** + * Function to load data into current object this + * + * @param stdClass $obj Contain data of object from database + */ + private function set_vars_by_db(&$obj) + { + foreach ($this->fields as $field => $info) + { + if($this->is_date($info)) + { + if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; + else $this->{$field} = strtotime($obj->{$field}); + } + elseif($this->is_array($info)) + { + $this->{$field} = @unserialize($obj->{$field}); + // Hack for data not in UTF8 + if($this->{$field } === FALSE) @unserialize(utf8_decode($obj->{$field})); + } + elseif($this->is_int($info)) + { + $this->{$field} = (int) $obj->{$field}; + } + elseif($this->is_float($info)) + { + $this->{$field} = (double) $obj->{$field}; + } + elseif($this->is_null($info)) + { + $val = $obj->{$field}; + // zero is not null + $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val); + } + else + { + $this->{$field} = $obj->{$field}; + } + + } + } + + /** + * Function to concat keys of fields + * + * @return string + */ + private function get_field_list() + { + $keys = array_keys($this->fields); + return implode(',', $keys); + } /** * Load object in memory from the database @@ -4708,6 +4915,32 @@ abstract class CommonObject public function fetchCommon($id, $ref = null) { + if (empty($id) && empty($ref)) return false; + + $sql = 'SELECT '.$this->get_field_list().', datec, tms'; + $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; + + if(!empty($id)) $sql.= ' WHERE rowid = '.$id; + else $sql.= ' WHERE ref = \''.$this->quote($ref).'\''; + + $res = $this->db->query($sql); + if($obj = $this->db->fetch_object($res)) + { + $this->id = $id; + $this->set_vars_by_db($obj); + + $this->datec = $this->db->idate($obj->datec); + $this->tms = $this->db->idate($obj->tms); + + return $this->id; + } + else + { + $this->error = $this->db->lasterror(); + $this->errors[] = $this->error; + return -1; + } + } /** @@ -4720,34 +4953,36 @@ abstract class CommonObject */ public function updateCommon(User $user, $notrigger = false) { - foreach ($this->fields as $k => $v) { - - if (is_array($key)){ - $i=array_search($k, $key); - if ( $i !== false) { - $where[] = $key[$i].'=' . $this->quote( $v ) ; - continue; - } - } else { - if ( $k == $key) { - $where[] = $k.'=' .$this->quote( $v ) ; - continue; - } - } - - $tmp[] = $k.'='.$this->quote($v); - } - $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET '.implode( ',', $tmp ).' WHERE ' . implode(' AND ',$where) ; - $res = $this->query( $sql ); - - if($res===false) { - //error - return false; - } - - // TODO Add triggers - - return true; + $fields = $this->set_save_query(); + + foreach ($fields as $k => $v) { + + if (is_array($key)){ + $i=array_search($k , $key ); + if ( $i !== false) { + $where[] = $key[$i].'=' . $this->quote( $v ) ; + continue; + } + } else { + if ( $k == $key) { + $where[] = $k.'=' .$this->quote( $v ) ; + continue; + } + } + + $tmp[] = $k.'='.$this->quote($v); + } + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode( ',', $tmp ).' WHERE rowid='.$this->id ; + $res = $this->db->query( $sql ); + + if($res===false) { + //error + return false; + } + + // TODO Add triggers + + return true; } /** @@ -4760,7 +4995,16 @@ abstract class CommonObject */ public function deleteCommon(User $user, $notrigger = false) { - + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; + + $res = $this->db->query( $sql ); + if($res===false) { + return false; + } + + // TODO Add triggers + + return true; } /** @@ -4769,11 +5013,11 @@ abstract class CommonObject * @param string|int $value value to protect * @return string|int */ - function quote($value) { + protected function quote($value) { if(is_null($value)) return 'NULL'; else if(is_numeric($value)) return $value; - else return "'".$this->escape( $value )."'"; + else return "'".$this->db->escape( $value )."'"; } diff --git a/htdocs/core/class/coreobject.class.php b/htdocs/core/class/coreobject.class.php index 8aa0cfe2ad6..c86a1083519 100644 --- a/htdocs/core/class/coreobject.class.php +++ b/htdocs/core/class/coreobject.class.php @@ -97,216 +97,6 @@ class CoreObject extends CommonObject } } - /** - * Function test if type is date - * - * @param array $info content informations of field - * @return bool - */ - private function is_date($info) - { - if(isset($info['type']) && $info['type']=='date') return true; - else return false; - } - - /** - * Function test if type is array - * - * @param array $info content informations of field - * @return bool - */ - private function is_array($info) - { - if(is_array($info)) - { - if(isset($info['type']) && $info['type']=='array') return true; - else return false; - } - else return false; - } - - /** - * Function test if type is null - * - * @param array $info content informations of field - * @return bool - */ - private function is_null($info) - { - if(is_array($info)) - { - if(isset($info['type']) && $info['type']=='null') return true; - else return false; - } - else return false; - } - - /** - * Function test if type is integer - * - * @param array $info content informations of field - * @return bool - */ - private function is_int($info) - { - if(is_array($info)) - { - if(isset($info['type']) && ($info['type']=='int' || $info['type']=='integer' )) return true; - else return false; - } - else return false; - } - - /** - * Function test if type is float - * - * @param array $info content informations of field - * @return bool - */ - private function is_float($info) - { - if(is_array($info)) - { - if(isset($info['type']) && $info['type']=='float') return true; - else return false; - } - else return false; - } - - /** - * Function test if type is text - * - * @param array $info content informations of field - * @return bool - */ - private function is_text($info) - { - if(is_array($info)) - { - if(isset($info['type']) && $info['type']=='text') return true; - else return false; - } - else return false; - } - - /** - * Function test if is indexed - * - * @param array $info content informations of field - * @return bool - */ - private function is_index($info) - { - if(is_array($info)) - { - if(isset($info['index']) && $info['index']==true) return true; - else return false; - } - else return false; - } - - - /** - * Function to prepare the values to insert - * - * @return array - */ - private function set_save_query() - { - $query=array(); - foreach ($this->fields as $field=>$info) - { - if($this->is_date($info)) - { - if(empty($this->{$field})) - { - $query[$field] = NULL; - } - else - { - $query[$field] = $this->db->idate($this->{$field}); - } - } - else if($this->is_array($info)) - { - $query[$field] = serialize($this->{$field}); - } - else if($this->is_int($info)) - { - $query[$field] = (int) price2num($this->{$field}); - } - else if($this->is_float($info)) - { - $query[$field] = (double) price2num($this->{$field}); - } - elseif($this->is_null($info)) - { - $query[$field] = (is_null($this->{$field}) || (empty($this->{$field}) && $this->{$field}!==0 && $this->{$field}!=='0') ? null : $this->{$field}); - } - else - { - $query[$field] = $this->{$field}; - } - } - - return $query; - } - - - /** - * Function to concat keys of fields - * - * @return string - */ - private function get_field_list() - { - $keys = array_keys($this->fields); - return implode(',', $keys); - } - - - /** - * Function to load data into current object this - * - * @param stdClass $obj Contain data of object from database - */ - private function set_vars_by_db(&$obj) - { - foreach ($this->fields as $field => $info) - { - if($this->is_date($info)) - { - if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; - else $this->{$field} = strtotime($obj->{$field}); - } - elseif($this->is_array($info)) - { - $this->{$field} = @unserialize($obj->{$field}); - // Hack for data not in UTF8 - if($this->{$field } === FALSE) @unserialize(utf8_decode($obj->{$field})); - } - elseif($this->is_int($info)) - { - $this->{$field} = (int) $obj->{$field}; - } - elseif($this->is_float($info)) - { - $this->{$field} = (double) $obj->{$field}; - } - elseif($this->is_null($info)) - { - $val = $obj->{$field}; - // zero is not null - $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val); - } - else - { - $this->{$field} = $obj->{$field}; - } - - } - } - /** * Get object and children from database * @@ -316,31 +106,14 @@ class CoreObject extends CommonObject */ public function fetch($id, $loadChild = true) { - if (empty($id)) return false; - - $sql = 'SELECT '.$this->get_field_list().', datec, tms'; - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; - $sql.= ' WHERE rowid = '.$id; - $res = $this->db->query($sql); - if($obj = $this->db->fetch_object($res)) - { - $this->id = $id; - $this->set_vars_by_db($obj); - - $this->datec = $this->db->idate($obj->datec); - $this->tms = $this->db->idate($obj->tms); - - if ($loadChild) $this->fetchChild(); - - return $this->id; - } - else - { - $this->error = $this->db->lasterror(); - $this->errors[] = $this->error; - return -1; - } + $res = $this->fetchCommon($id); + if($res>0) { + if ($loadChild) $this->fetchChild(); + } + + return $res; + } @@ -473,10 +246,7 @@ class CoreObject extends CommonObject $error = 0; $this->db->begin(); - $query = $this->set_save_query(); - $query['rowid'] = $this->id; - - $res = $this->db->update($this->table_element, $query, array('rowid')); + $res = $this->updateCommon($user); if ($res) { $result = $this->call_trigger(strtoupper($this->element). '_UPDATE', $user); @@ -516,10 +286,7 @@ class CoreObject extends CommonObject $error = 0; $this->db->begin(); - $query = $this->set_save_query(); - $query['datec'] = date("Y-m-d H:i:s", dol_now()); - - $res = $this->db->insert($this->table_element, $query); + $res = $this->createCommon($user); if($res) { $this->id = $this->db->last_insert_id($this->table_element); @@ -565,7 +332,7 @@ class CoreObject extends CommonObject if (!$error) { - $this->db->delete($this->table_element, array('rowid' => $this->id), array('rowid')); + $this->deleteCommon($user); if($this->withChild && !empty($this->childtables)) { foreach($this->childtables as &$childTable) @@ -669,5 +436,5 @@ class CoreObject extends CommonObject return 1; } - + } diff --git a/htdocs/core/modules/modStock.class.php b/htdocs/core/modules/modStock.class.php index cfdc6db298c..ea181f72a41 100644 --- a/htdocs/core/modules/modStock.class.php +++ b/htdocs/core/modules/modStock.class.php @@ -117,91 +117,42 @@ class modStock extends DolibarrModules $this->rights[4][4] = 'mouvement'; $this->rights[4][5] = 'creer'; - /* - $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) + + $this->rights[$r][0] = 1006; $this->rights[$r][1] = 'inventoryReadPermission'; // Permission label - $this->rights[$r][3] = 1; // Permission by default for new user (0/1) + $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; - $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) + $this->rights[$r][0] = 1007; $this->rights[$r][1] = 'inventoryCreatePermission'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'create'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; - $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) + $this->rights[$r][0] = 1008; $this->rights[$r][1] = 'inventoryWritePermission'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; - $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) + $this->rights[$r][0] = 1009; $this->rights[$r][1] = 'inventoryValidatePermission'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'validate'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; - $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) + $this->rights[$r][0] = 1010; $this->rights[$r][1] = 'inventoryChangePMPPermission'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'changePMP'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; - */ + // Main menu entries $this->menu = array(); // List of menus to add $r=0; - /* - $this->menu[$r]=array( - 'fk_menu'=>'fk_mainmenu=products', // Put 0 if this is a top menu - 'type'=>'left', // This is a Top menu entry - 'titre'=>'Inventory', - 'mainmenu'=>'products', - 'leftmenu'=>'inventory_left', - 'url'=>'/inventory/list.php', - 'langs'=>'inventory', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - 'position'=>100+$r, - 'enabled'=>'$conf->inventory->enabled', // Define condition to show or hide menu entry. Use '$conf->inventory->enabled' if entry must be visible if module is enabled. - 'perms'=>'$user->rights->inventory->read', // Use 'perms'=>'$user->rights->inventory->level1->level2' if you want your menu with a permission rules - 'target'=>'', - 'user'=>2 - ); // 0=Menu for internal users, 1=external users, 2=both - $r++; - - $this->menu[$r]=array( - 'fk_menu'=>'fk_mainmenu=products,fk_leftmenu=inventory_left', // Put 0 if this is a top menu - 'type'=>'left', // This is a Top menu entry - 'titre'=>'NewInventory', - 'mainmenu'=>'products', - 'leftmenu'=>'inventory_left_create', - 'url'=>'/inventory/inventory.php?action=create', - 'position'=>100+$r, - 'enabled'=>'$conf->inventory->enabled', // Define condition to show or hide menu entry. Use '$conf->inventory->enabled' if entry must be visible if module is enabled. - 'perms'=>'$user->rights->inventory->create', // Use 'perms'=>'$user->rights->inventory->level1->level2' if you want your menu with a permission rules - 'target'=>'', - 'user'=>2 - ); // 0=Menu for internal users, 1=external users, 2=both - $r++; - - $this->menu[$r]=array( - 'fk_menu'=>'fk_mainmenu=products,fk_leftmenu=inventory_left', // Put 0 if this is a top menu - 'type'=>'left', // This is a Top menu entry - 'titre'=>'ListInventory', - 'mainmenu'=>'products', - 'leftmenu'=>'inventory_left_list', - 'url'=>'/inventory/list.php', - 'langs'=>'inventory', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory. - 'position'=>100+$r, - 'enabled'=>'$conf->inventory->enabled', // Define condition to show or hide menu entry. Use '$conf->inventory->enabled' if entry must be visible if module is enabled. - 'perms'=>'$user->rights->inventory->read', // Use 'perms'=>'$user->rights->inventory->level1->level2' if you want your menu with a permission rules - 'target'=>'', - 'user'=>2 - ); // 0=Menu for internal users, 1=external users, 2=both - $r++; - */ - // Menus //------- $this->menu = 1; // This module add menu entries. They are coded into menu manager. diff --git a/htdocs/product/inventory/ajax/ajax.inventory.php b/htdocs/product/inventory/ajax/ajax.inventory.php index c0d8443f433..4884d7ab065 100644 --- a/htdocs/product/inventory/ajax/ajax.inventory.php +++ b/htdocs/product/inventory/ajax/ajax.inventory.php @@ -2,14 +2,14 @@ require '../../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php'; - + $get = GETPOST('get'); $put = GETPOST('put'); switch ($put) { case 'qty': - if (empty($user->rights->stock->write)) { echo -1; exit; } + if (empty($user->rights->stock->creer)) { echo -1; exit; } $fk_det_inventory = GETPOST('fk_det_inventory'); @@ -17,7 +17,7 @@ if( $det->fetch( $fk_det_inventory)) { $det->qty_view+=GETPOST('qty'); - $det->update($user); + $res = $det->update($user); echo $det->qty_view; } @@ -25,11 +25,11 @@ { echo -2; } - + break; case 'pmp': - if (!$user->rights->stock->write || !$user->rights->stock->changePMP) { echo -1; exit; } + if (empty($user->rights->stock->creer) || empty($user->rights->stock->changePMP)) { echo -1; exit; } $fk_det_inventory = GETPOST('fk_det_inventory'); diff --git a/htdocs/product/inventory/card.php b/htdocs/product/inventory/card.php index dc279cc0929..ad539532901 100644 --- a/htdocs/product/inventory/card.php +++ b/htdocs/product/inventory/card.php @@ -66,7 +66,7 @@ $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals // Initialize technical object to manage hooks of modules. Note that conf->hooks_modules contains array array -$hookmanager->initHooks(array('inventory')); +$hookmanager->initHooks(array('inventorycard')); @@ -84,7 +84,7 @@ if (empty($reshook)) { if ($action != 'addlink') { - $urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1); + $urltogo=$backtopage?$backtopage:dol_buildpath('/product/inventory/list.php',1); header("Location: ".$urltogo); exit; } @@ -98,7 +98,7 @@ if (empty($reshook)) if ($cancel) { - $urltogo=$backtopage?$backtopage:dol_buildpath('/mymodule/list.php',1); + $urltogo=$backtopage?$backtopage:dol_buildpath('/product/inventory/list.php',1); header("Location: ".$urltogo); exit; } @@ -128,7 +128,6 @@ if (empty($reshook)) exit; } - break; } switch($action) { From 12e91f1c1b9f5c02f0e47f6c33ea0cce7b26fafa Mon Sep 17 00:00:00 2001 From: alexis Algoud Date: Tue, 2 May 2017 15:25:30 +0200 Subject: [PATCH 11/22] fix rights inventory only for MAIN_LEVEL_FEATURES = 2 --- htdocs/core/modules/modStock.class.php | 47 ++++++++++++-------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/htdocs/core/modules/modStock.class.php b/htdocs/core/modules/modStock.class.php index ea181f72a41..e80966afb81 100644 --- a/htdocs/core/modules/modStock.class.php +++ b/htdocs/core/modules/modStock.class.php @@ -117,37 +117,34 @@ class modStock extends DolibarrModules $this->rights[4][4] = 'mouvement'; $this->rights[4][5] = 'creer'; + if ($conf->global->MAIN_LEVEL_FEATURES >= 2) { - $this->rights[$r][0] = 1006; - $this->rights[$r][1] = 'inventoryReadPermission'; // Permission label - $this->rights[$r][3] = 0; // Permission by default for new user (0/1) - $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) - $r++; + $this->rights[5][0] = 1006; + $this->rights[5][1] = 'inventoryReadPermission'; // Permission label + $this->rights[5][3] = 0; // Permission by default for new user (0/1) + $this->rights[5][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) - $this->rights[$r][0] = 1007; - $this->rights[$r][1] = 'inventoryCreatePermission'; // Permission label - $this->rights[$r][3] = 0; // Permission by default for new user (0/1) - $this->rights[$r][4] = 'create'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) - $r++; + $this->rights[6][0] = 1007; + $this->rights[6][1] = 'inventoryCreatePermission'; // Permission label + $this->rights[6][3] = 0; // Permission by default for new user (0/1) + $this->rights[6][4] = 'create'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) - $this->rights[$r][0] = 1008; - $this->rights[$r][1] = 'inventoryWritePermission'; // Permission label - $this->rights[$r][3] = 0; // Permission by default for new user (0/1) - $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) - $r++; + $this->rights[7][0] = 1008; + $this->rights[7][1] = 'inventoryWritePermission'; // Permission label + $this->rights[7][3] = 0; // Permission by default for new user (0/1) + $this->rights[7][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) - $this->rights[$r][0] = 1009; - $this->rights[$r][1] = 'inventoryValidatePermission'; // Permission label - $this->rights[$r][3] = 0; // Permission by default for new user (0/1) - $this->rights[$r][4] = 'validate'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) - $r++; + $this->rights[7][0] = 1009; + $this->rights[7][1] = 'inventoryValidatePermission'; // Permission label + $this->rights[7][3] = 0; // Permission by default for new user (0/1) + $this->rights[7][4] = 'validate'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) - $this->rights[$r][0] = 1010; - $this->rights[$r][1] = 'inventoryChangePMPPermission'; // Permission label - $this->rights[$r][3] = 0; // Permission by default for new user (0/1) - $this->rights[$r][4] = 'changePMP'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) - $r++; + $this->rights[7][0] = 1010; + $this->rights[7][1] = 'inventoryChangePMPPermission'; // Permission label + $this->rights[7][3] = 0; // Permission by default for new user (0/1) + $this->rights[7][4] = 'changePMP'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + } // Main menu entries $this->menu = array(); // List of menus to add From c673d283e01e41a6292875dce4b9a8bb07bcf817 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 2 May 2017 18:21:50 +0200 Subject: [PATCH 12/22] Fix script to send emailings --- ...terface_50_modAgenda_ActionsAuto.class.php | 2 +- scripts/emailings/mailing-send.php | 41 ++++++++++++++----- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php index bce6d69b2fa..9da1ada59ad 100644 --- a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php +++ b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php @@ -48,7 +48,7 @@ class InterfaceActionsAuto extends DolibarrTriggers * $object->actionmsg (note, long text) * $object->actionmsg2 (label, short text) * $object->sendtoid (id of contact or array of ids) - * $object->socid + * $object->socid (id of thirdparty) * $object->fk_project * $object->fk_element * $object->elementtype diff --git a/scripts/emailings/mailing-send.php b/scripts/emailings/mailing-send.php index 27cc22448e6..6465e765cfe 100755 --- a/scripts/emailings/mailing-send.php +++ b/scripts/emailings/mailing-send.php @@ -41,11 +41,12 @@ if (! isset($argv[1]) || ! $argv[1]) { exit(-1); } $id=$argv[1]; -if (! isset($argv[2]) || !empty($argv[2])) $login = $argv[2]; +if (isset($argv[2]) || !empty($argv[2])) $login = $argv[2]; else $login = ''; require_once ($path."../../htdocs/master.inc.php"); require_once (DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php"); +require_once (DOL_DOCUMENT_ROOT."/comm/mailing/class/mailing.class.php"); // Global variables @@ -70,9 +71,8 @@ $user = new User($db); // for signature, we use user send as parameter if (! empty($login)) $user->fetch('',$login); -// We get list of emailing to process -$sql = "SELECT m.rowid, m.titre, m.sujet, m.body,"; -$sql.= " m.email_from, m.email_replyto, m.email_errorsto"; +// We get list of emailing id to process +$sql = "SELECT m.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m"; $sql.= " WHERE m.statut IN (1,2)"; if ($id != 'all') @@ -96,12 +96,15 @@ if ($resql) dol_syslog("Process mailing with id ".$obj->rowid); print "Process mailing with id ".$obj->rowid."\n"; - $id = $obj->rowid; - $subject = $obj->sujet; - $message = $obj->body; - $from = $obj->email_from; - $replyto = $obj->email_replyto; - $errorsto = $obj->email_errorsto; + $emailing = new Mailing($db); + $emailing->fetch($obj->rowid); + + $id = $emailing->id; + $subject = $emailing->sujet; + $message = $emailing->body; + $from = $emailing->email_from; + $replyto = $emailing->email_replyto; + $errorsto = $emailing->email_errorsto; // Le message est-il en html $msgishtml=-1; // Unknown by default if (preg_match('/[\s\t]*/i',$message)) $msgishtml=1; @@ -232,6 +235,24 @@ if ($resql) dol_syslog("ok for emailing id ".$id." #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG); + // Note: If emailing is 100 000 targets, 100 000 entries are added, so we don't enter events for each target here + // We must union table llx_mailing_taget for event tab OR enter 1 event with a special table link (id of email in event) + // Run trigger + /* + if ($obj2->source_type == 'contact') + { + $emailing->sendtoid = $obj2->source_id; + } + if ($obj2->source_type == 'thirdparty') + { + $emailing->socid = $obj2->source_id; + } + // Call trigger + $result=$emailing->call_trigger('EMAILING_SENTBYMAIL',$user); + if ($result < 0) $error++; + // End call triggers + */ + $sqlok ="UPDATE ".MAIN_DB_PREFIX."mailing_cibles"; $sqlok.=" SET statut=1, date_envoi='".$db->idate($now)."' WHERE rowid=".$obj2->rowid; $resqlok=$db->query($sqlok); From 0bc46facd75af8117780da5e4b30af9011645bd1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 2 May 2017 21:24:18 +0200 Subject: [PATCH 13/22] Add missing vat_src_code on recurring invoices --- htdocs/install/mysql/migration/5.0.0-6.0.0.sql | 2 ++ htdocs/install/mysql/tables/llx_facture_rec.sql | 1 + 2 files changed, 3 insertions(+) diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index 71f9a17273c..991381cb432 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -141,6 +141,8 @@ ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_soc_remise_fk_invoice_su ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_invoice_supplier FOREIGN KEY (fk_invoice_supplier) REFERENCES llx_facture_fourn (rowid); ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_invoice_supplier_source FOREIGN KEY (fk_invoice_supplier) REFERENCES llx_facture_fourn (rowid); +ALTER TABLE llx_facture_rec ADD COLUMN vat_src_code varchar(10) DEFAULT ''; + UPDATE llx_const set value='moono-lisa' where value = 'moono' AND name = 'FCKEDITOR_SKIN'; ALTER TABLE llx_product_price ADD COLUMN default_vat_code varchar(10) after tva_tx; diff --git a/htdocs/install/mysql/tables/llx_facture_rec.sql b/htdocs/install/mysql/tables/llx_facture_rec.sql index d0d79ef57dc..0e25100386b 100644 --- a/htdocs/install/mysql/tables/llx_facture_rec.sql +++ b/htdocs/install/mysql/tables/llx_facture_rec.sql @@ -32,6 +32,7 @@ create table llx_facture_rec remise_percent real DEFAULT 0, remise_absolue real DEFAULT 0, + vat_src_code varchar(10) DEFAULT '', -- Vat code used as source of vat fields. Not strict foreign key here. tva double(24,8) DEFAULT 0, localtax1 double(24,8) DEFAULT 0, -- amount localtax1 localtax2 double(24,8) DEFAULT 0, -- amount localtax2 From b8f5e93ab0b56157dbfa83d95da42df84ff57487 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 2 May 2017 21:40:18 +0200 Subject: [PATCH 14/22] Debug inventory data model --- htdocs/install/mysql/data/llx_c_tva.sql | 2 +- htdocs/install/mysql/migration/5.0.0-6.0.0.sql | 13 +++++++++---- htdocs/install/mysql/tables/llx_inventorydet.sql | 8 ++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/htdocs/install/mysql/data/llx_c_tva.sql b/htdocs/install/mysql/data/llx_c_tva.sql index 34842ed324e..3b401abd37d 100644 --- a/htdocs/install/mysql/data/llx_c_tva.sql +++ b/htdocs/install/mysql/data/llx_c_tva.sql @@ -96,11 +96,11 @@ insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (80 -- FRANCE (id country=1) insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 11, 1, '20','0','VAT standard rate (France hors DOM-TOM)',1); -insert into llx_c_tva(rowid,fk_pays,taux,code,recuperableonly,note,active) values ( 12, 1, '8.5', '8.5', '0','VAT standard rate (DOM sauf Guyane et Saint-Martin)',0); insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 14, 1, '5.5','0','VAT reduced rate (France hors DOM-TOM)',1); insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 15, 1, '0','0','VAT Rate 0 ou non applicable',1); insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 16, 1, '2.1','0','VAT super-reduced rate',1); insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 17, 1, '10','0','VAT reduced rate',1); +insert into llx_c_tva(fk_pays,taux,code,recuperableonly,note,active) values (1, '8.5', '85', '0','VAT standard rate (DOM sauf Guyane et Saint-Martin)',0); insert into llx_c_tva(fk_pays,taux,code,recuperableonly,note,active) values (1, '8.5', '85NPR', '1','VAT standard rate (DOM sauf Guyane et Saint-Martin), non perçu par le vendeur mais récupérable par acheteur',0); insert into llx_c_tva(fk_pays,taux,code,recuperableonly,localtax1,localtax1_type,note,active) values (1, '8.5', '85NPROM', '1', 2, 3, 'VAT standard rate (DOM sauf Guyane et Saint-Martin), NPR, Octroi de Mer',0); insert into llx_c_tva(fk_pays,taux,code,recuperableonly,localtax1,localtax1_type,localtax2,localtax2_type,note,active) values (1, '8.5', '85NPROMOMR', '1', 2, 3, 2.5, 3, 'VAT standard rate (DOM sauf Guyane et Saint-Martin), NPR, Octroi de Mer et Octroi de Mer Regional',0); diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index 991381cb432..1982ef6aff8 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -229,9 +229,9 @@ fk_inventory integer DEFAULT 0, fk_warehouse integer DEFAULT 0, fk_product integer DEFAULT 0, batch varchar(30) DEFAULT NULL, -qty_view double DEFAULT 0, -qty_stock double DEFAULT 0, -qty_regulated double DEFAULT 0, +qty_view double DEFAULT NULL, +qty_stock double DEFAULT NULL, +qty_regulated double DEFAULT NULL, pmp double DEFAULT 0, pa double DEFAULT 0, new_pmp double DEFAULT 0 @@ -242,4 +242,9 @@ ALTER TABLE llx_inventory ADD INDEX idx_inventory_tms (tms); ALTER TABLE llx_inventory ADD INDEX idx_inventory_datec (datec); ALTER TABLE llx_inventorydet ADD INDEX idx_inventorydet_tms (tms); ALTER TABLE llx_inventorydet ADD INDEX idx_inventorydet_datec (datec); -ALTER TABLE llx_inventorydet ADD INDEX idx_inventorydet_fk_inventory (fk_inventory); \ No newline at end of file +ALTER TABLE llx_inventorydet ADD INDEX idx_inventorydet_fk_inventory (fk_inventory); + +insert into llx_c_tva(fk_pays,taux,code,recuperableonly,note,active) values (1, '8.5', '85', '0','VAT standard rate (DOM sauf Guyane et Saint-Martin)',0); +insert into llx_c_tva(fk_pays,taux,code,recuperableonly,note,active) values (1, '8.5', '85NPR', '1','VAT standard rate (DOM sauf Guyane et Saint-Martin), non perçu par le vendeur mais récupérable par acheteur',0); +insert into llx_c_tva(fk_pays,taux,code,recuperableonly,localtax1,localtax1_type,note,active) values (1, '8.5', '85NPROM', '1', 2, 3, 'VAT standard rate (DOM sauf Guyane et Saint-Martin), NPR, Octroi de Mer',0); +insert into llx_c_tva(fk_pays,taux,code,recuperableonly,localtax1,localtax1_type,localtax2,localtax2_type,note,active) values (1, '8.5', '85NPROMOMR', '1', 2, 3, 2.5, 3, 'VAT standard rate (DOM sauf Guyane et Saint-Martin), NPR, Octroi de Mer et Octroi de Mer Regional',0); diff --git a/htdocs/install/mysql/tables/llx_inventorydet.sql b/htdocs/install/mysql/tables/llx_inventorydet.sql index 2b203e0c58b..ce40d03939c 100644 --- a/htdocs/install/mysql/tables/llx_inventorydet.sql +++ b/htdocs/install/mysql/tables/llx_inventorydet.sql @@ -25,10 +25,10 @@ tms timestamp, fk_inventory integer DEFAULT 0, fk_warehouse integer DEFAULT 0, fk_product integer DEFAULT 0, -batch varchar(30) DEFAULT NULL, -- Lot or serial number -qty_view double DEFAULT 0, -qty_stock double DEFAULT 0, -qty_regulated double DEFAULT 0, +batch varchar(30) DEFAULT NULL, -- Lot or serial number +qty_view double DEFAULT NULL, -- must be filled once regulation is done +qty_stock double DEFAULT NULL, -- can be filled during draft edition +qty_regulated double DEFAULT NULL, -- must be filled once regulation is done pmp double DEFAULT 0, pa double DEFAULT 0, new_pmp double DEFAULT 0 From a115d4877b9903dfb137e9ecb2d0cd2fb03db4c7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 2 May 2017 22:37:23 +0200 Subject: [PATCH 15/22] Fix for new property array fields --- htdocs/api/class/api.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php index 7aef2671c8d..9228c71ccbf 100644 --- a/htdocs/api/class/api.class.php +++ b/htdocs/api/class/api.class.php @@ -90,6 +90,8 @@ class DolibarrApi // Remove linkedObjects. We should already have linkedObjectIds that avoid huge responses unset($object->linkedObjects); + unset($object->fields); + unset($object->oldline); unset($object->error); From d1a443f0f042c939a491c9d7cdc30632bf9b64c8 Mon Sep 17 00:00:00 2001 From: alexis portable Date: Tue, 2 May 2017 23:11:05 +0200 Subject: [PATCH 16/22] fix camelcase for travis --- htdocs/core/class/commonobject.class.php | 34 ++++++++++++------------ htdocs/core/class/coreobject.class.php | 8 +++--- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 582e00d29fa..97c8da3f316 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4669,7 +4669,7 @@ abstract class CommonObject * @param array $info content informations of field * @return bool */ - protected function is_date($info) + protected function isDate($info) { if(isset($info['type']) && $info['type']=='date') return true; else return false; @@ -4681,7 +4681,7 @@ abstract class CommonObject * @param array $info content informations of field * @return bool */ - protected function is_array($info) + protected function isArray($info) { if(is_array($info)) { @@ -4697,7 +4697,7 @@ abstract class CommonObject * @param array $info content informations of field * @return bool */ - protected function is_null($info) + protected function isNull($info) { if(is_array($info)) { @@ -4713,7 +4713,7 @@ abstract class CommonObject * @param array $info content informations of field * @return bool */ - protected function is_int($info) + protected function isInt($info) { if(is_array($info)) { @@ -4729,7 +4729,7 @@ abstract class CommonObject * @param array $info content informations of field * @return bool */ - protected function is_float($info) + protected function isFloat($info) { if(is_array($info)) { @@ -4745,7 +4745,7 @@ abstract class CommonObject * @param array $info content informations of field * @return bool */ - protected function is_text($info) + protected function isText($info) { if(is_array($info)) { @@ -4761,7 +4761,7 @@ abstract class CommonObject * @param array $info content informations of field * @return bool */ - protected function is_index($info) + protected function isIndex($info) { if(is_array($info)) { @@ -4781,7 +4781,7 @@ abstract class CommonObject $query=array(); foreach ($this->fields as $field=>$info) { - if($this->is_date($info)) + if($this->isDate($info)) { if(empty($this->{$field})) { @@ -4792,19 +4792,19 @@ abstract class CommonObject $query[$field] = $this->db->idate($this->{$field}); } } - else if($this->is_array($info)) + else if($this->isArray($info)) { $query[$field] = serialize($this->{$field}); } - else if($this->is_int($info)) + else if($this->isInt($info)) { $query[$field] = (int) price2num($this->{$field}); } - else if($this->is_float($info)) + else if($this->isFloat($info)) { $query[$field] = (double) price2num($this->{$field}); } - elseif($this->is_null($info)) + elseif($this->isNull($info)) { $query[$field] = (is_null($this->{$field}) || (empty($this->{$field}) && $this->{$field}!==0 && $this->{$field}!=='0') ? null : $this->{$field}); } @@ -4860,26 +4860,26 @@ abstract class CommonObject { foreach ($this->fields as $field => $info) { - if($this->is_date($info)) + if($this->isDate($info)) { if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; else $this->{$field} = strtotime($obj->{$field}); } - elseif($this->is_array($info)) + elseif($this->isArray($info)) { $this->{$field} = @unserialize($obj->{$field}); // Hack for data not in UTF8 if($this->{$field } === FALSE) @unserialize(utf8_decode($obj->{$field})); } - elseif($this->is_int($info)) + elseif($this->isInt($info)) { $this->{$field} = (int) $obj->{$field}; } - elseif($this->is_float($info)) + elseif($this->isFloat($info)) { $this->{$field} = (double) $obj->{$field}; } - elseif($this->is_null($info)) + elseif($this->isNull($info)) { $val = $obj->{$field}; // zero is not null diff --git a/htdocs/core/class/coreobject.class.php b/htdocs/core/class/coreobject.class.php index c86a1083519..021213594f7 100644 --- a/htdocs/core/class/coreobject.class.php +++ b/htdocs/core/class/coreobject.class.php @@ -59,10 +59,10 @@ class CoreObject extends CommonObject { foreach ($this->fields as $field=>$info) { - if ($this->is_date($info)) $this->{$field} = time(); - elseif ($this->is_array($info)) $this->{$field} = array(); - elseif ($this->is_int($info)) $this->{$field} = (int) 0; - elseif ($this->is_float($info)) $this->{$field} = (double) 0; + if ($this->isDate($info)) $this->{$field} = time(); + elseif ($this->isArray($info)) $this->{$field} = array(); + elseif ($this->isInt($info)) $this->{$field} = (int) 0; + elseif ($this->isFloat($info)) $this->{$field} = (double) 0; else $this->{$field} = ''; } From da4d179d36789551eb31490f107f7abd3c6a0c92 Mon Sep 17 00:00:00 2001 From: alexis portable Date: Tue, 2 May 2017 23:20:23 +0200 Subject: [PATCH 17/22] fix travis --- htdocs/core/class/commonobject.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 97c8da3f316..16bff11b5fd 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4958,7 +4958,7 @@ abstract class CommonObject foreach ($fields as $k => $v) { if (is_array($key)){ - $i=array_search($k , $key ); + $i=array_search($k, $key); if ( $i !== false) { $where[] = $key[$i].'=' . $this->quote( $v ) ; continue; From f543461e9b084de70e84ba06a5ed15c4f2943394 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 4 May 2017 11:21:28 +0200 Subject: [PATCH 18/22] Complete the substitution array with substitution array with all possible keys --- htdocs/core/class/html.formmail.class.php | 3 +++ htdocs/core/lib/functions.lib.php | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index d7ab17e60c4..6c411b60e66 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1133,6 +1133,9 @@ class FormMail extends Form $vars['__SECUREKEYPAYPAL_MEMBER__']=''; } } + + $vars=complete_substitutions_array($vars, $langs, null, null); + return $vars; } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 857ddc6eec2..b6cf92aa81d 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4953,7 +4953,8 @@ function make_substitutions($text, $substitutionarray, $outputlangs=null) } /** - * Complete the $substitutionarray with more entries + * Complete the $substitutionarray with more entries. + * Can also add substitution keys coming from external module that had set the "substitutions=1" into module_part array. In this case, method completesubstitutionarray provided by module is called. * * @param array $substitutionarray Array substitution old value => new value value * @param Translate $outputlangs Output language From 7ec46b3bd6ace90a7e91e51198d874f484ff1e0b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 4 May 2017 12:35:45 +0200 Subject: [PATCH 19/22] Finished work to have substitution keys code mutualized. --- htdocs/accountancy/admin/accountmodel.php | 3 +-- htdocs/admin/mails_templates.php | 22 +++++++++++++++------- htdocs/core/class/html.formmail.class.php | 18 ++++++++++++------ 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/htdocs/accountancy/admin/accountmodel.php b/htdocs/accountancy/admin/accountmodel.php index 0b4aa70e548..55c194cd416 100644 --- a/htdocs/accountancy/admin/accountmodel.php +++ b/htdocs/accountancy/admin/accountmodel.php @@ -757,8 +757,7 @@ if ($id) { print '* '.$langs->trans("AvailableVariables").": "; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - $formmail=new FormMail($db); - $tmp=$formmail->getAvailableSubstitKey('form'); + $tmp=FormMail::getAvailableSubstitKey('formemail'); print implode(', ', $tmp); print ''; } diff --git a/htdocs/admin/mails_templates.php b/htdocs/admin/mails_templates.php index f0bf5609adf..08ba76dca99 100644 --- a/htdocs/admin/mails_templates.php +++ b/htdocs/admin/mails_templates.php @@ -118,17 +118,17 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail=new FormMail($db); if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) { - $tmp=$formmail->getAvailableSubstitKey('form'); + $tmp=FormMail::getAvailableSubstitKey('formemail'); $tmp['__(AnyTransKey)__']='__(AnyTransKey)__'; $helpsubstit = $langs->trans("AvailableVariables").':
'.implode('
', $tmp); $helpsubstitforlines = $langs->trans("AvailableVariables").':
'.implode('
', $tmp); } else { - $tmp=$formmail->getAvailableSubstitKey('formwithlines'); + $tmp=FormMail::getAvailableSubstitKey('formemailwithlines'); $tmp['__(AnyTransKey)__']='__(AnyTransKey)__'; $helpsubstit = $langs->trans("AvailableVariables").':
'.implode('
', $tmp); - $tmp=$formmail->getAvailableSubstitKey('formforlines'); + $tmp=FormMail::getAvailableSubstitKey('formemailforlines'); $helpsubstitforlines = $langs->trans("AvailableVariables").':
'.implode('
', $tmp); } @@ -484,7 +484,11 @@ if ($action != 'edit') { print ''; if (! empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i',$tabhelp[$id][$value])) print ''.$valuetoshow.' '.img_help(1,$valuetoshow).''; - else if (! empty($tabhelp[$id][$value])) print $form->textwithpicto($valuetoshow,$tabhelp[$id][$value]); + else if (! empty($tabhelp[$id][$value])) + { + if (in_array($value, array('topic'))) print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, $value); // Tooltip on click + else print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover + } else print $valuetoshow; print ''; } @@ -539,8 +543,8 @@ if ($action != 'edit') foreach ($fieldsforcontent as $tmpfieldlist) { print ''; - if ($tmpfieldlist == 'content') print ''.$form->textwithpicto($langs->trans("Content"),$tabhelp[$id][$tmpfieldlist]).'
'; - if ($tmpfieldlist == 'content_lines') print ''.$form->textwithpicto($langs->trans("ContentForLines"),$tabhelp[$id][$tmpfieldlist]).'
'; + if ($tmpfieldlist == 'content') print ''.$form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'
'; + if ($tmpfieldlist == 'content_lines') print ''.$form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'
'; if ($context != 'hide') { @@ -624,7 +628,11 @@ if ($resql) // Affiche nom du champ if ($showfield) { - if (! empty($tabhelp[$id][$value])) $valuetoshow = $form->textwithpicto($valuetoshow,$tabhelp[$id][$value]); + if (! empty($tabhelp[$id][$value])) + { + if (in_array($value, array('topic'))) $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover + else $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover + } print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable?$fieldlist[$field]:''), ($page?'page='.$page.'&':''), $param, "align=".$align, $sortfield, $sortorder); } } diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 6c411b60e66..6988fb4b992 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1059,18 +1059,18 @@ class FormMail extends Form } /** - * Set substit array from object + * Get list of substition keys available. * - * @param string $mode 'form', 'formwithlines', 'formforlines' or 'emailing' + * @param string $mode 'formemail', 'formemailwithlines', 'formemailforlines', 'emailing', ... * @return void */ - function getAvailableSubstitKey($mode='form') + static function getAvailableSubstitKey($mode='formemail') { - global $conf; + global $conf, $langs; $vars=array(); - if ($mode == 'form' || $mode == 'formwithlines' || $mode == 'formforlines') + if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') { $vars=array( '__REF__', @@ -1134,7 +1134,13 @@ class FormMail extends Form } } - $vars=complete_substitutions_array($vars, $langs, null, null); + $tmparray=array(); + $parameters=array('mode'=>$mode); + complete_substitutions_array($tmparray, $langs, null, $parameters); + foreach($tmparray as $key => $val) + { + $vars[]=$key; + } return $vars; } From 1a6c118a5dfa001a8dd5cda90402d543cd067902 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 4 May 2017 12:41:29 +0200 Subject: [PATCH 20/22] Fix travis warning --- htdocs/product/inventory/card.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/htdocs/product/inventory/card.php b/htdocs/product/inventory/card.php index dc279cc0929..827354b864c 100644 --- a/htdocs/product/inventory/card.php +++ b/htdocs/product/inventory/card.php @@ -127,8 +127,6 @@ if (empty($reshook)) header('Location: '.dol_buildpath('/product/inventory/card.php?action=create', 1)); exit; } - - break; } switch($action) { From 7d5b5cf86a1da58fad3a006cdee9f2ec079d2eb9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 4 May 2017 13:09:42 +0200 Subject: [PATCH 21/22] Better behavior for tooltip on click --- htdocs/core/class/html.form.class.php | 5 +++-- htdocs/langs/en_US/main.lang | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 3275ee0f303..cab420fe888 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -492,10 +492,11 @@ class Form */ function textwithpicto($text, $htmltext, $direction = 1, $type = 'help', $extracss = '', $noencodehtmltext = 0, $notabs = 2, $tooltiptrigger='') { - global $conf; + global $conf, $langs; $alt = ''; - + if ($tooltiptrigger) $alt=$langs->trans("ClickToShowHelp"); + //For backwards compatibility if ($type == '0') $type = 'info'; elseif ($type == '1') $type = 'help'; diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 1a3eea413df..c567890730a 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -766,6 +766,9 @@ Download=Download ActualizeCurrency=Update currency rate Fiscalyear=Fiscal year ModuleBuilder=Module Builder +SetMultiCurrencyCode=Set currency +BulkActions=Bulk actions +ClickToShowHelp=Click to show tooltip help # Week day Monday=Monday Tuesday=Tuesday @@ -822,6 +825,4 @@ SearchIntoInterventions=Interventions SearchIntoContracts=Contracts SearchIntoCustomerShipments=Customer shipments SearchIntoExpenseReports=Expense reports -SearchIntoLeaves=Leaves -SetMultiCurrencyCode=Set currency -BulkActions=Bulk actions \ No newline at end of file +SearchIntoLeaves=Leaves \ No newline at end of file From 0c76db7973ef2f410f08a4551e36bff48720b5dc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 4 May 2017 13:41:37 +0200 Subject: [PATCH 22/22] FIX #6698 #6742 --- htdocs/comm/mailing/cibles.php | 51 +++++++++++--------- htdocs/comm/mailing/class/mailing.class.php | 2 +- htdocs/core/class/html.formmail.class.php | 2 +- htdocs/core/class/html.formmailing.class.php | 14 +++--- 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php index d3642c50393..118cc336fb7 100644 --- a/htdocs/comm/mailing/cibles.php +++ b/htdocs/comm/mailing/cibles.php @@ -161,6 +161,7 @@ if ($_POST["button_removefilter"]) $search_lastname=''; $search_firstname=''; $search_email=''; + $search_dest_status=''; } @@ -399,7 +400,7 @@ if ($object->fetch($id) >= 0) if ($search_lastname) $sql.= " AND mc.lastname LIKE '%".$db->escape($search_lastname)."%'"; if ($search_firstname) $sql.= " AND mc.firstname LIKE '%".$db->escape($search_firstname)."%'"; if ($search_email) $sql.= " AND mc.email LIKE '%".$db->escape($search_email)."%'"; - if (!empty($search_dest_status)) $sql.= " AND mc.statut=".$db->escape($search_dest_status)." "; + if ($search_dest_status != '' && $search_dest_status >= -1) $sql.= " AND mc.statut=".$db->escape($search_dest_status)." "; $sql .= $db->order($sortfield,$sortorder); // Count total nb of records @@ -411,7 +412,7 @@ if ($object->fetch($id) >= 0) } //$nbtotalofrecords=$object->nbemail; // nbemail is a denormalized field storing nb of targets $sql .= $db->plimit($limit+1, $offset); - + $resql=$db->query($sql); if ($resql) { @@ -446,29 +447,12 @@ if ($object->fetch($id) >= 0) print ''; - if ($page) $param.= "&page=".$page; + if ($page) $param.= "&page=".$page; + print ''; - print ''; - print_liste_field_titre($langs->trans("EMail"),$_SERVER["PHP_SELF"],"mc.email",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Lastname"),$_SERVER["PHP_SELF"],"mc.lastname",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Firstname"),$_SERVER["PHP_SELF"],"mc.firstname",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("OtherInformations"),$_SERVER["PHP_SELF"],"",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Source"),$_SERVER["PHP_SELF"],"",$param,"",'align="center"',$sortfield,$sortorder); - // Date sending - if ($object->statut < 2) - { - print_liste_field_titre(''); - } - else - { - print_liste_field_titre($langs->trans("DateSending"),$_SERVER["PHP_SELF"],"mc.date_envoi",$param,'','align="center"',$sortfield,$sortorder); - } - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"mc.statut",$param,'','align="right"',$sortfield,$sortorder); - print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch '); - print ''; - + // Ligne des champs de filtres - print ''; + print ''; // EMail print ''; - + // Date sending print ''; print ''; + + print ''; + print_liste_field_titre($langs->trans("EMail"),$_SERVER["PHP_SELF"],"mc.email",$param,"","",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Lastname"),$_SERVER["PHP_SELF"],"mc.lastname",$param,"","",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Firstname"),$_SERVER["PHP_SELF"],"mc.firstname",$param,"","",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("OtherInformations"),$_SERVER["PHP_SELF"],"",$param,"","",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Source"),$_SERVER["PHP_SELF"],"",$param,"",'align="center"',$sortfield,$sortorder); + // Date sending + if ($object->statut < 2) + { + print_liste_field_titre(''); + } + else + { + print_liste_field_titre($langs->trans("DateSending"),$_SERVER["PHP_SELF"],"mc.date_envoi",$param,'','align="center"',$sortfield,$sortorder); + } + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"mc.statut",$param,'','align="right"',$sortfield,$sortorder); + print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch '); + print ''; $i = 0; diff --git a/htdocs/comm/mailing/class/mailing.class.php b/htdocs/comm/mailing/class/mailing.class.php index b0dff81332c..43a3cdcb78d 100644 --- a/htdocs/comm/mailing/class/mailing.class.php +++ b/htdocs/comm/mailing/class/mailing.class.php @@ -80,8 +80,8 @@ class Mailing extends CommonObject $this->statuts[2] = 'MailingStatusSentPartialy'; $this->statuts[3] = 'MailingStatusSentCompletely'; - $this->statut_dest[0] = 'MailingStatusNotSent'; $this->statut_dest[-1] = 'MailingStatusError'; + $this->statut_dest[0] = 'MailingStatusNotSent'; $this->statut_dest[1] = 'MailingStatusSent'; $this->statut_dest[2] = 'MailingStatusRead'; $this->statut_dest[3] = 'MailingStatusReadAndUnsubscribe'; // Read but ask to not be contacted anymore diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 6988fb4b992..ab58854f2c4 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1139,7 +1139,7 @@ class FormMail extends Form complete_substitutions_array($tmparray, $langs, null, $parameters); foreach($tmparray as $key => $val) { - $vars[]=$key; + $vars[$key]=$key; } return $vars; diff --git a/htdocs/core/class/html.formmailing.class.php b/htdocs/core/class/html.formmailing.class.php index 0c63049f9d8..9fb4e4eea86 100644 --- a/htdocs/core/class/html.formmailing.class.php +++ b/htdocs/core/class/html.formmailing.class.php @@ -32,9 +32,9 @@ class FormMailing extends Form /** * Output a select with destinaries status * - * @param string $selectedid the selected id - * @param string $htmlname name of controm - * @param integer $show_empty show empty option + * @param string $selectedid The selected id + * @param string $htmlname Name of controm + * @param integer $show_empty Show empty option * @return string HTML select */ public function selectDestinariesStatus($selectedid='',$htmlname='dest_status', $show_empty=0) { @@ -46,13 +46,13 @@ class FormMailing extends Form $mailing = new Mailing($this->db); $options = array(); - + if ($show_empty) { - $options[''] = ''; + $options[-2] = ''; // Note -1 is used for error } - $options = array_merge($options, $mailing->statut_dest); + $options = $options + $mailing->statut_dest; - return Form::selectarray($htmlname, $options, $selectedid, 0, 0, 0, '', 1); + return Form::selectarray($htmlname, $options, $selectedid, 0, 0, 0, '', 1); } }
'; print ''; @@ -489,7 +473,7 @@ if ($object->fetch($id) >= 0) print ''; print ' '; print ''; print ' '; @@ -504,6 +488,25 @@ if ($object->fetch($id) >= 0) print $searchpitco; print '