32 public $array_import_module;
33 public $array_import_perms;
34 public $array_import_icon;
35 public $array_import_code;
36 public $array_import_label;
37 public $array_import_tables;
38 public $array_import_tables_creator;
39 public $array_import_fields;
40 public $array_import_fieldshidden;
41 public $array_import_entities;
42 public $array_import_regex;
43 public $array_import_updatekeys;
44 public $array_import_examplevalues;
45 public $array_import_convertvalue;
46 public $array_import_run_sql_after;
56 public $errors = array();
89 dol_syslog(get_class($this).
"::load_arrays user=".$user->id.
" filter=".$filter);
93 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
97 foreach ($modulesdir as $dir) {
99 if (!is_resource($handle)) {
104 while (($file = readdir($handle)) !==
false) {
105 if (!preg_match(
"/^(mod.*)\.class\.php/i", $file, $reg)) {
109 $modulename = $reg[1];
113 $part = strtolower(preg_replace(
'/^mod/i',
'', $modulename));
115 if ($part ===
'propale') {
118 if (empty($conf->$part->enabled)) {
122 if (empty($enabled)) {
127 $file = $dir.
"/".$modulename.
".class.php";
128 $classname = $modulename;
130 $module =
new $classname($this->
db);
132 if (isset($module->import_code) && is_array($module->import_code)) {
133 foreach ($module->import_code as $r => $value) {
134 if ($filter && ($filter != $module->import_code[$r])) {
154 $langtoload = $module->getLangFilesArray();
155 if (is_array($langtoload)) {
156 foreach ($langtoload as $key) {
162 $this->array_import_perms[$i] = $user->rights->import->run;
164 $this->array_import_icon[$i] = (isset($module->import_icon[$r]) ? $module->import_icon[$r] : $module->picto);
166 $this->array_import_code[$i] = $module->import_code[$r];
168 $this->array_import_label[$i] = $module->getImportDatasetLabel($r);
170 $this->array_import_tables[$i] = $module->import_tables_array[$r];
172 $this->array_import_tables_creator[$i] = (isset($module->import_tables_creator_array[$r]) ? $module->import_tables_creator_array[$r] :
'');
174 $this->array_import_fields[$i] = $module->import_fields_array[$r];
176 $this->array_import_fieldshidden[$i] = (isset($module->import_fieldshidden_array[$r]) ? $module->import_fieldshidden_array[$r] :
'');
178 $this->array_import_entities[$i] = $module->import_entities_array[$r];
180 $this->array_import_regex[$i] = (isset($module->import_regex_array[$r]) ? $module->import_regex_array[$r] :
'');
182 $this->array_import_updatekeys[$i] = (isset($module->import_updatekeys_array[$r]) ? $module->import_updatekeys_array[$r] :
'');
184 $this->array_import_examplevalues[$i] = (isset($module->import_examplevalues_array[$r]) ? $module->import_examplevalues_array[$r] :
'');
186 $this->array_import_convertvalue[$i] = (isset($module->import_convertvalue_array[$r]) ? $module->import_convertvalue_array[$r] :
'');
188 $this->array_import_run_sql_after[$i] = (isset($module->import_run_sql_after_array[$r]) ? $module->import_run_sql_after_array[$r] :
'');
190 $this->array_import_module[$i] = array(
'position_of_profile'=>($module->module_position.
'-'.$module->import_code[$r]),
'module'=>$module);
192 dol_syslog(
"Import loaded for module ".$modulename.
" with index ".$i.
", dataset=".$module->import_code[$r].
", nb of fields=".count($module->import_fields_array[$r]));
218 global $conf, $langs;
222 dol_syslog(get_class($this).
"::build_example_file ".$model);
225 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
226 $file =
"import_".$model.
".modules.php";
227 $classname =
"Import".$model;
228 require_once $dir.$file;
229 $objmodel =
new $classname($this->
db, $datatoimport);
231 $outputlangs = $langs;
235 $s .= $objmodel->write_header_example($outputlangs);
238 $s .= $objmodel->write_title_example($outputlangs, $headerlinefields);
241 $s .= $objmodel->write_record_example($outputlangs, $contentlinevalues);
244 $s .= $objmodel->write_footer_example($outputlangs);
262 if (empty($this->model_name)) {
263 $this->error =
'ErrorWrongParameters';
return -1;
265 if (empty($this->datatoimport)) {
266 $this->error =
'ErrorWrongParameters';
return -1;
268 if (empty($this->hexa)) {
269 $this->error =
'ErrorWrongParameters';
return -1;
274 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'import_model (';
281 $sql .= (isset($this->fk_user) ? (int) $this->fk_user :
'null').
",";
282 $sql .=
" '".$this->db->escape($this->model_name).
"',";
283 $sql .=
" '".$this->db->escape($this->datatoimport).
"',";
284 $sql .=
" '".$this->db->escape($this->hexa).
"'";
292 $this->error = $this->
db->lasterror();
293 $this->errno = $this->
db->lasterrno();
294 $this->
db->rollback();
307 $sql =
'SELECT em.rowid, em.field, em.label, em.type';
308 $sql .=
' FROM '.MAIN_DB_PREFIX.
'import_model as em';
309 $sql .=
' WHERE em.rowid = '.((int) $id);
311 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
312 $result = $this->
db->query($sql);
314 $obj = $this->
db->fetch_object($result);
316 $this->
id = $obj->rowid;
317 $this->hexa = $obj->field;
318 $this->model_name = $obj->label;
319 $this->datatoimport = $obj->type;
320 $this->fk_user = $obj->fk_user;
323 $this->error =
"Model not found";
339 public function delete($user, $notrigger = 0)
341 global $conf, $langs;
344 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"import_model";
345 $sql .=
" WHERE rowid=".((int) $this->
id);
349 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
352 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
368 foreach ($this->errors as $errmsg) {
369 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
370 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
372 $this->
db->rollback();
__construct($db)
Constructor.
fetch($id)
Load an import profil from database.
build_example_file($model, $headerlinefields, $contentlinevalues, $datatoimport)
Build an import example file.
create($user)
Save an export model in database.
load_arrays($user, $filter='')
Load description int this->array_import_module, this->array_import_fields, ...
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dolGetModulesDirs($subdir='')
Return list of modules directories.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.