180 global $langs,
$conf;
182 dol_syslog(get_class($this).
"::load_arrays user=".$user->id.
" filter=".$filter);
186 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
190 foreach ($modulesdir as $dir) {
192 if (!is_resource($handle)) {
197 while (($file = readdir($handle)) !==
false) {
198 if (!preg_match(
"/^(mod.*)\.class\.php/i", $file, $reg)) {
202 $modulename = $reg[1];
206 $part = strtolower(preg_replace(
'/^mod/i',
'', $modulename));
208 if ($part ===
'propale') {
211 if (empty(
$conf->$part->enabled)) {
215 if (empty($enabled)) {
220 $file = $dir.
"/".$modulename.
".class.php";
221 $classname = $modulename;
223 $module =
new $classname($this->db);
224 '@phan-var-force DolibarrModules $module';
226 if (isset($module->import_code) && is_array($module->import_code)) {
227 foreach ($module->import_code as $r => $value) {
228 if ($filter && ($filter != $module->import_code[$r])) {
248 $langtoload = $module->getLangFilesArray();
249 if (is_array($langtoload)) {
250 foreach ($langtoload as $key) {
256 $this->array_import_perms[$i] = $user->hasRight(
'import',
'run');
258 $this->array_import_icon[$i] = (isset($module->import_icon[$r]) ? $module->import_icon[$r] : $module->picto);
260 $this->array_import_code[$i] = $module->import_code[$r];
262 $this->array_import_label[$i] = $module->getImportDatasetLabel($r);
264 $this->array_import_tables[$i] = $module->import_tables_array[$r];
266 $this->array_import_tables_creator[$i] = (isset($module->import_tables_creator_array[$r]) ? $module->import_tables_creator_array[$r] :
'');
268 $this->array_import_fields[$i] = $module->import_fields_array[$r];
270 $this->array_import_fieldshidden[$i] = (isset($module->import_fieldshidden_array[$r]) ? $module->import_fieldshidden_array[$r] :
'');
272 $this->array_import_entities[$i] = $module->import_entities_array[$r];
274 $this->array_import_regex[$i] = (isset($module->import_regex_array[$r]) ? $module->import_regex_array[$r] :
'');
276 $this->array_import_updatekeys[$i] = (isset($module->import_updatekeys_array[$r]) ? $module->import_updatekeys_array[$r] :
'');
279 $this->array_import_preselected_updatekeys[$i] = (isset($module->import_preselected_updatekeys_array[$r]) ? $module->import_preselected_updatekeys_array[$r] :
'');
281 $this->array_import_examplevalues[$i] = (isset($module->import_examplevalues_array[$r]) ? $module->import_examplevalues_array[$r] :
'');
283 $this->array_import_convertvalue[$i] = (isset($module->import_convertvalue_array[$r]) ? $module->import_convertvalue_array[$r] :
'');
285 $this->array_import_run_sql_after[$i] = (isset($module->import_run_sql_after_array[$r]) ? $module->import_run_sql_after_array[$r] :
'');
287 $this->array_import_module[$i] = array(
'position_of_profile' => ($module->module_position.
'-'.$module->import_code[$r]),
'module' => $module);
289 dol_syslog(
"Import loaded for module ".$modulename.
" with index ".$i.
", dataset=".$module->import_code[$r].
", nb of fields=".count($module->import_fields_array[$r]));
315 global
$conf, $langs;
319 dol_syslog(get_class($this).
"::build_example_file ".$model);
322 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
323 $file =
"import_".$model.
".modules.php";
324 $classname =
"Import".$model;
325 require_once $dir.$file;
326 $objmodel =
new $classname($this->db, $datatoimport);
327 '@phan-var-force CommonObject $objmodel';
329 $outputlangs = $langs;
333 $s .= $objmodel->write_header_example($outputlangs);
336 $s .= $objmodel->write_title_example($outputlangs, $headerlinefields);
339 $s .= $objmodel->write_record_example($outputlangs, $contentlinevalues);
342 $s .= $objmodel->write_footer_example($outputlangs);
360 if (empty($this->model_name)) {
361 $this->error =
'ErrorWrongParameters';
364 if (empty($this->datatoimport)) {
365 $this->error =
'ErrorWrongParameters';
368 if (empty($this->hexa)) {
369 $this->error =
'ErrorWrongParameters';
375 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'import_model (';
382 $sql .= (isset($this->fk_user) ? (int) $this->fk_user :
'null').
",";
383 $sql .=
" '".$this->db->escape($this->model_name).
"',";
384 $sql .=
" '".$this->db->escape($this->datatoimport).
"',";
385 $sql .=
" '".$this->db->escape($this->hexa).
"'";
388 $resql = $this->db->query($sql);
393 $this->error = $this->db->lasterror();
394 $this->errno = $this->db->lasterrno();
395 $this->db->rollback();
408 $sql =
'SELECT em.rowid, em.field, em.label, em.type';
409 $sql .=
' FROM '.MAIN_DB_PREFIX.
'import_model as em';
410 $sql .=
' WHERE em.rowid = '.((int) $id);
412 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
413 $result = $this->db->query($sql);
415 $obj = $this->db->fetch_object($result);
417 $this->
id = $obj->rowid;
418 $this->hexa = $obj->field;
419 $this->model_name = $obj->label;
420 $this->datatoimport = $obj->type;
421 $this->fk_user = $obj->fk_user;
424 $this->error =
"Model not found";