diff --git a/htdocs/core/class/cgenericdic.class.php b/htdocs/core/class/cgenericdic.class.php new file mode 100644 index 00000000000..deda1c1952b --- /dev/null +++ b/htdocs/core/class/cgenericdic.class.php @@ -0,0 +1,478 @@ + + * Copyright (C) 2014-2016 Juanjo Menent + * Copyright (C) 2016 Florian Henry + * Copyright (C) 2015 Raphaƫl Doursenaud + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/core/class/cgenericdic.class.php + * \ingroup resource + */ + +/** + * Class CGenericDic + * + * @see CommonObject + */ +class CGenericDic +{ + /** + * @var string Id to identify managed objects + */ + public $element = 'undefined'; // Will be defined into constructor + + /** + * @var string Name of table without prefix where object is stored + */ + public $table_element = 'undefined'; // Will be defined into constructor + + /** + * @var CtyperesourceLine[] Lines + */ + public $lines = array(); + + public $code; + + /** + * @var string Type resource label + */ + public $label; + + public $active; + + + /** + * Constructor + * + * @param DoliDb $db Database handler + */ + public function __construct(DoliDB $db) + { + $this->db = $db; + + // Don't forget to set this->element and this->table_element after the construction + } + + /** + * 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); + + $fieldlabel = 'label'; + if ($this->table_element == 'c_stcomm') { + $fieldlabel = 'libelle'; + } + + $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); + } + + // Insert request + $sql = 'INSERT INTO '.$this->db->prefix().$this->table_element.'('; + $sql .= 'code,'; + $sql .= $fieldlabel; + $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($this->db->prefix().$this->table_element); + + // Uncomment this and change CTYPERESOURCE to your own tag if you + // want this action to call a trigger. + //if (!$notrigger) { + + // // Call triggers + // $result=$this->call_trigger('CTYPERESOURCE_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 $code code + * @param string $label Label + * + * @return int <0 if KO, 0 if not found, >0 if OK + */ + public function fetch($id, $code = '', $label = '') + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $fieldrowid = 'rowid'; + $fieldlabel = 'label'; + if ($this->table_element == 'c_stcomm') { + $fieldrowid = 'id'; + $fieldlabel = 'libelle'; + } + + $sql = "SELECT"; + $sql .= " t.".$fieldrowid.","; + $sql .= " t.code,"; + $sql .= " t.".$fieldlabel." as label,"; + $sql .= " t.active"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; + if ($id) { + $sql .= " WHERE t.".$fieldrowid." = ".((int) $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->$fieldrowid; + + $this->code = $obj->code; + $this->label = $obj->label; + $this->active = $obj->active; + } + + // Retrieve all extrafields for invoice + // fetch optionals attributes and labels + // $this->fetch_optionals(); + + // $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); + + $fieldrowid = 'rowid'; + $fieldlabel = 'label'; + if ($this->table_element == 'c_stcomm') { + $fieldrowid = 'id'; + $fieldlabel = 'libelle'; + } + + $sql = "SELECT"; + $sql .= " t.".$fieldrowid.","; + $sql .= " t.code,"; + $sql .= " t.".$fieldlabel." as label,"; + $sql .= " t.active"; + $sql .= " FROM ".$this->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(' '.$this->db->escape($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->$fieldrowid; + + $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); + + $fieldrowid = 'rowid'; + $fieldlabel = 'label'; + if ($this->table_element == 'c_stcomm') { + $fieldrowid = 'id'; + $fieldlabel = 'libelle'; + } + + // 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 ".$this->db->prefix().$this->table_element.' SET'; + $sql .= " code = ".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").','; + $sql .= " ".$fieldlabel.' = '.(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").','; + $sql .= " active = ".(isset($this->active) ? $this->active : "null"); + $sql .= " WHERE ".$fieldrowid.' = '.((int) $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); + } + + // Uncomment this and change CTYPERESOURCE to your own tag if you + // want this action calls a trigger. + //if (!$error && !$notrigger) { + + // // Call triggers + // $result=$this->call_trigger('CTYPERESOURCE_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); + + $fieldrowid = 'rowid'; + + $error = 0; + + $this->db->begin(); + + // Uncomment this and change CTYPERESOURCE to your own tag if you + // want this action calls a trigger. + //if (!$error && !$notrigger) { + + // // Call triggers + // $result=$this->call_trigger('CTYPERESOURCE_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 '.$this->db->prefix().$this->table_element; + $sql .= ' WHERE '.$fieldrowid.' = '.((int) $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 User $user User making the clone + * @param int $fromid Id of object to clone + * @return int New id of clone + */ + public function createFromClone(User $user, $fromid) + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $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 + $object->context['createfromclone'] = 'createfromclone'; + $result = $object->create($user); + + // Other options + if ($result < 0) { + $error++; + $this->errors = $object->errors; + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); + } + + unset($object->context['createfromclone']); + + // 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 = 'CODE'; + $this->label = 'Label'; + $this->active = 1; + } +} diff --git a/htdocs/core/class/ctypent.class.php b/htdocs/core/class/ctypent.class.php index 6de7de7d5cb..324bfcb36a0 100644 --- a/htdocs/core/class/ctypent.class.php +++ b/htdocs/core/class/ctypent.class.php @@ -99,30 +99,22 @@ class Ctypent // extends CommonObject $this->module = trim($this->module); } - - // Check parameters // Put here code to add control on parameters values // Insert request $sql = "INSERT INTO ".$this->db->prefix()."c_typent("; - $sql .= "id,"; $sql .= "code,"; $sql .= "libelle,"; $sql .= "active,"; $sql .= "module"; - - $sql .= ") VALUES ("; - $sql .= " ".(!isset($this->id) ? 'NULL' : "'".$this->db->escape($this->id)."'").","; $sql .= " ".(!isset($this->code) ? 'NULL' : "'".$this->db->escape($this->code)."'").","; $sql .= " ".(!isset($this->libelle) ? 'NULL' : "'".$this->db->escape($this->libelle)."'").","; $sql .= " ".(!isset($this->active) ? 'NULL' : "'".$this->db->escape($this->active)."'").","; $sql .= " ".(!isset($this->module) ? 'NULL' : "'".$this->db->escape($this->module)."'").""; - - $sql .= ")"; $this->db->begin(); @@ -276,7 +268,7 @@ class Ctypent // extends CommonObject $error = 0; $sql = "DELETE FROM ".$this->db->prefix()."c_typent"; - $sql .= " WHERE id=".$this->id; + $sql .= " WHERE id = ".$this->id; $this->db->begin(); diff --git a/htdocs/core/class/ctyperesource.class.php b/htdocs/core/class/ctyperesource.class.php index 4a4e5c3d2cb..be83877098c 100644 --- a/htdocs/core/class/ctyperesource.class.php +++ b/htdocs/core/class/ctyperesource.class.php @@ -26,8 +26,6 @@ /** * Class Ctyperesource * - * Put here description of your class - * * @see CommonObject */ class Ctyperesource @@ -93,26 +91,15 @@ class Ctyperesource $this->active = trim($this->active); } - - - // Check parameters - // Put here code to add control on parameters values - // Insert request $sql = 'INSERT INTO '.$this->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(); @@ -177,7 +164,6 @@ class Ctyperesource $sql .= " WHERE t.label = '".$this->db->escape($label)."'"; } - $resql = $this->db->query($sql); if ($resql) { $numrows = $this->db->num_rows($resql); @@ -308,12 +294,9 @@ class Ctyperesource // Update request $sql = 'UPDATE '.$this->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='.((int) $this->id); $this->db->begin(); diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index 40b13da0599..16568288aa4 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -393,6 +393,9 @@ class ImportCsv extends ModeleImports $newval = $arrayrecord[($key - 1)]['val']; // If type of field into input file is not empty string (so defined into input file), we get value } + //var_dump($newval);var_dump($val); + //var_dump($objimport->array_import_convertvalue[0][$val]); + // Make some tests on $newval // Is it a required field ? @@ -417,7 +420,7 @@ class ImportCsv extends ModeleImports } $newval = preg_replace('/^(id|ref):/i', '', $newval); // Remove id: or ref: that was used to force if field is id or ref - //print 'Val is now '.$newval.' and is type '.$isidorref."
\n"; + //print 'Newval is now "'.$newval.'" and is type '.$isidorref."
\n"; if ($isidorref == 'ref') { // If value into input import file is a ref, we apply the function defined into descriptor $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']); @@ -432,6 +435,11 @@ class ImportCsv extends ModeleImports break; } $classinstance = new $class($this->db); + if ($class == 'CGenericDic') { + $classinstance->element = $objimport->array_import_convertvalue[0][$val]['element']; + $classinstance->table_element = $objimport->array_import_convertvalue[0][$val]['table_element']; + } + // Try the fetch from code or ref $param_array = array('', $newval); if ($class == 'AccountingAccount') { @@ -601,7 +609,7 @@ class ImportCsv extends ModeleImports $modForNumber = new $classModForNumber; $tmpobject = null; - // Set the object when we can + // Set the object with the date property when we can if (!empty($objimport->array_import_convertvalue[0][$val]['classobject'])) { $pathForObject = $objimport->array_import_convertvalue[0][$val]['pathobject']; require_once DOL_DOCUMENT_ROOT.$pathForObject; @@ -748,8 +756,9 @@ class ImportCsv extends ModeleImports $tmpsql = $listvalues[$socialkey]; $listvalues[$socialkey] = "'".$this->db->escape($tmpsql)."'"; } + // We add hidden fields (but only if there is at least one field to add into table) - // We process here all the fields that were declared into the array ->import_fieldshidden_array of the descriptor file. + // We process here all the fields that were declared into the array $this->import_fieldshidden_array of the descriptor file. // Previously we processed the ->import_fields_array. if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) { // Loop on each hidden fields to add them into listfields/listvalues @@ -858,7 +867,7 @@ class ImportCsv extends ModeleImports if (empty($keyfield)) { $keyfield = 'rowid'; } - $sqlSelect .= " WHERE ".$keyfield.' = '.((int) $lastinsertid); + $sqlSelect .= " WHERE ".$keyfield." = ".((int) $lastinsertid); $resql = $this->db->query($sqlSelect); if ($resql) { diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index 257a9a13c6a..d16a9a764eb 100644 --- a/htdocs/core/modules/import/import_xlsx.modules.php +++ b/htdocs/core/modules/import/import_xlsx.modules.php @@ -86,6 +86,10 @@ class ImportXlsx extends ModeleImports public $cachefieldtable = array(); // Array to cache list of value found into fields@tables + public $nbinsert = 0; // # of insert done during the import + + public $nbupdate = 0; // # of update done during the import + public $workbook; // temporary import file public $record; // current record @@ -111,20 +115,19 @@ class ImportXlsx extends ModeleImports $this->extension = 'xlsx'; // Extension for generated file by this driver $this->picto = 'mime/xls'; // Picto (This is not used by the example file code as Mime type, too bad ...) $this->version = '1.0'; // Driver version + // If driver use an external library, put its name here require_once DOL_DOCUMENT_ROOT.'/includes/phpoffice/phpspreadsheet/src/autoloader.php'; require_once DOL_DOCUMENT_ROOT.'/includes/Psr/autoloader.php'; require_once PHPEXCELNEW_PATH.'Spreadsheet.php'; $this->workbook = new Spreadsheet(); - //if ($this->id == 'excel2007new') - { + // If driver use an external library, put its name here if (!class_exists('ZipArchive')) { // For Excel2007 $langs->load("errors"); $this->error = $langs->trans('ErrorPHPNeedModule', 'zip'); return -1; } - } $this->label_lib = 'PhpSpreadSheet'; $this->version_lib = '1.8.0'; @@ -363,8 +366,6 @@ class ImportXlsx extends ModeleImports $warning = 0; $this->errors = array(); $this->warnings = array(); - $this->nbinsert = 0; - $this->nbupdate = 0; //dol_syslog("import_csv.modules maxfields=".$maxfields." importid=".$importid); @@ -438,6 +439,9 @@ class ImportXlsx extends ModeleImports $newval = $arrayrecord[($key)]['val']; // If type of field into input file is not empty string (so defined into input file), we get value } + //var_dump($newval);var_dump($val); + //var_dump($objimport->array_import_convertvalue[0][$val]); + // Make some tests on $newval // Is it a required field ? @@ -461,7 +465,7 @@ class ImportXlsx extends ModeleImports $isidorref = 'ref'; } $newval = preg_replace('/^(id|ref):/i', '', $newval); // Remove id: or ref: that was used to force if field is id or ref - //print 'Val is now '.$newval.' and is type '.$isidorref."
\n"; + //print 'Newval is now "'.$newval.'" and is type '.$isidorref."
\n"; if ($isidorref == 'ref') { // If value into input import file is a ref, we apply the function defined into descriptor $file = (empty($objimport->array_import_convertvalue[0][$val]['classfile']) ? $objimport->array_import_convertvalue[0][$val]['file'] : $objimport->array_import_convertvalue[0][$val]['classfile']); @@ -476,6 +480,11 @@ class ImportXlsx extends ModeleImports break; } $classinstance = new $class($this->db); + if ($class == 'CGenericDic') { + $classinstance->element = $objimport->array_import_convertvalue[0][$val]['element']; + $classinstance->table_element = $objimport->array_import_convertvalue[0][$val]['table_element']; + } + // Try the fetch from code or ref $param_array = array('', $newval); if ($class == 'AccountingAccount') { @@ -674,7 +683,7 @@ class ImportXlsx extends ModeleImports break; } $classinstance = new $class($this->db); - $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord)); + $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $listfields, $key)); $newval = $res; // We get new value computed. } elseif ($objimport->array_import_convertvalue[0][$val]['rule'] == 'numeric') { $newval = price2num($newval); @@ -758,19 +767,16 @@ class ImportXlsx extends ModeleImports } if (!empty($newval) && $arrayrecord[($key)]['type'] > 0) { $socialkey = array_search("socialnetworks", $listfields); + $socialnetwork = explode("_", $fieldname)[1]; if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] == "null") { - $socialnetwork = explode("_", $fieldname)[1]; $json = new stdClass(); $json->$socialnetwork = $newval; - $newvalue = json_encode($json); - $listvalues[$socialkey] = $newvalue; + $listvalues[$socialkey] = json_encode($json); } else { - $socialnetwork = explode("_", $fieldname)[1]; $jsondata = $listvalues[$socialkey]; - $jsondata = str_replace("'", "", $jsondata); $json = json_decode($jsondata); - $json->$socialnetwork = $this->db->escape($newval); - $listvalues[$socialkey] = "'".$this->db->escape(json_encode($json))."'"; + $json->$socialnetwork = $newval; + $listvalues[$socialkey] = json_encode($json); } } } else { @@ -789,6 +795,13 @@ class ImportXlsx extends ModeleImports $i++; } + // We db escape social network field because he isn't in field creation + if (in_array("socialnetworks", $listfields)) { + $socialkey = array_search("socialnetworks", $listfields); + $tmpsql = $listvalues[$socialkey]; + $listvalues[$socialkey] = "'".$this->db->escape($tmpsql)."'"; + } + // We add hidden fields (but only if there is at least one field to add into table) // We process here all the fields that were declared into the array $this->import_fieldshidden_array of the descriptor file. // Previously we processed the ->import_fields_array. @@ -825,7 +838,7 @@ class ImportXlsx extends ModeleImports break; } $classinstance = new $class($this->db); - $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $fieldname, &$listfields, &$listvalues)); + $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $listfields, $key)); $fieldArr = explode('.', $fieldname); if (count($fieldArr) > 0) { $fieldname = $fieldArr[1]; @@ -898,7 +911,7 @@ class ImportXlsx extends ModeleImports if (empty($keyfield)) { $keyfield = 'rowid'; } - $sqlSelect .= "WHERE " . $keyfield . " = " .((int) $lastinsertid); + $sqlSelect .= "WHERE ".$keyfield." = ".((int) $lastinsertid); $resql = $this->db->query($sqlSelect); if ($resql) { @@ -925,7 +938,7 @@ class ImportXlsx extends ModeleImports $data = array_combine($listfields, $listvalues); $set = array(); foreach ($data as $key => $val) { - $set[] = $key . ' = ' . $val; + $set[] = $key." = ".$val; } $sqlstart .= " SET " . implode(', ', $set); diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index a9eb5899fc8..a6d9b95d19c 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -586,7 +586,26 @@ class modSociete extends DolibarrModules 'class' => 'Account', 'method' => 'fetch', 'element' => 'BankAccount' - // ), + ), + 's.fk_stcomm' => array( + 'rule' => 'fetchidfromcodeid', + 'classfile' => '/core/class/cgenericdic.class.php', + 'class' => 'CGenericDic', + 'method' => 'fetch', + 'dict' => 'DictionaryProspectStatus', + 'element' => 'c_stcomm', + 'table_element' => 'c_stcomm' + ), + /* + 's.fk_prospectlevel' => array( + 'rule' => 'fetchidfromcodeid', + 'classfile' => '/core/class/cgenericdic.class.php', + 'class' => 'CGenericDic', + 'method' => 'fetch', + 'dict' => 'DictionaryProspectLevel', + 'element' => 'c_prospectlevel', + 'table_element' => 'c_prospectlevel' + ),*/ // TODO // 's.fk_incoterms' => array( // 'rule' => 'fetchidfromcodeid', @@ -594,7 +613,7 @@ class modSociete extends DolibarrModules // 'class' => 'Cincoterm', // 'method' => 'fetch', // 'dict' => 'IncotermLabel' - ) + // ) ); //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t'); $this->import_regex_array[$r] = array(//field order as per structure of table llx_societe