170 global $langs, $conf;
172 dol_syslog(get_class($this).
"::load_arrays user=".$user->id.
" filter=".$filter);
176 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
180 foreach ($modulesdir as $dir) {
182 if (!is_resource($handle)) {
187 while (($file = readdir($handle)) !==
false) {
188 if (!preg_match(
"/^(mod.*)\.class\.php/i", $file, $reg)) {
192 $modulename = $reg[1];
196 $part = strtolower(preg_replace(
'/^mod/i',
'', $modulename));
198 if ($part ===
'propale') {
201 if (empty($conf->$part->enabled)) {
205 if (empty($enabled)) {
210 $file = $dir.
"/".$modulename.
".class.php";
211 $classname = $modulename;
213 $module =
new $classname($this->db);
215 if (isset($module->import_code) && is_array($module->import_code)) {
216 foreach ($module->import_code as $r => $value) {
217 if ($filter && ($filter != $module->import_code[$r])) {
237 $langtoload = $module->getLangFilesArray();
238 if (is_array($langtoload)) {
239 foreach ($langtoload as $key) {
245 $this->array_import_perms[$i] = $user->hasRight(
'import',
'run');
247 $this->array_import_icon[$i] = (isset($module->import_icon[$r]) ? $module->import_icon[$r] : $module->picto);
249 $this->array_import_code[$i] = $module->import_code[$r];
251 $this->array_import_label[$i] = $module->getImportDatasetLabel($r);
253 $this->array_import_tables[$i] = $module->import_tables_array[$r];
255 $this->array_import_tables_creator[$i] = (isset($module->import_tables_creator_array[$r]) ? $module->import_tables_creator_array[$r] :
'');
257 $this->array_import_fields[$i] = $module->import_fields_array[$r];
259 $this->array_import_fieldshidden[$i] = (isset($module->import_fieldshidden_array[$r]) ? $module->import_fieldshidden_array[$r] :
'');
261 $this->array_import_entities[$i] = $module->import_entities_array[$r];
263 $this->array_import_regex[$i] = (isset($module->import_regex_array[$r]) ? $module->import_regex_array[$r] :
'');
265 $this->array_import_updatekeys[$i] = (isset($module->import_updatekeys_array[$r]) ? $module->import_updatekeys_array[$r] :
'');
267 $this->array_import_preselected_updatekeys[$i] = (isset($module->import_preselected_updatekeys_array[$r]) ? $module->import_preselected_updatekeys_array[$r] :
'');
269 $this->array_import_examplevalues[$i] = (isset($module->import_examplevalues_array[$r]) ? $module->import_examplevalues_array[$r] :
'');
271 $this->array_import_convertvalue[$i] = (isset($module->import_convertvalue_array[$r]) ? $module->import_convertvalue_array[$r] :
'');
273 $this->array_import_run_sql_after[$i] = (isset($module->import_run_sql_after_array[$r]) ? $module->import_run_sql_after_array[$r] :
'');
275 $this->array_import_module[$i] = array(
'position_of_profile'=>($module->module_position.
'-'.$module->import_code[$r]),
'module'=>$module);
277 dol_syslog(
"Import loaded for module ".$modulename.
" with index ".$i.
", dataset=".$module->import_code[$r].
", nb of fields=".count($module->import_fields_array[$r]));
303 global $conf, $langs;
307 dol_syslog(get_class($this).
"::build_example_file ".$model);
310 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
311 $file =
"import_".$model.
".modules.php";
312 $classname =
"Import".$model;
313 require_once $dir.$file;
314 $objmodel =
new $classname($this->db, $datatoimport);
316 $outputlangs = $langs;
320 $s .= $objmodel->write_header_example($outputlangs);
323 $s .= $objmodel->write_title_example($outputlangs, $headerlinefields);
326 $s .= $objmodel->write_record_example($outputlangs, $contentlinevalues);
329 $s .= $objmodel->write_footer_example($outputlangs);
347 if (empty($this->model_name)) {
348 $this->error =
'ErrorWrongParameters';
351 if (empty($this->datatoimport)) {
352 $this->error =
'ErrorWrongParameters';
355 if (empty($this->hexa)) {
356 $this->error =
'ErrorWrongParameters';
362 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'import_model (';
369 $sql .= (isset($this->fk_user) ? (int) $this->fk_user :
'null').
",";
370 $sql .=
" '".$this->db->escape($this->model_name).
"',";
371 $sql .=
" '".$this->db->escape($this->datatoimport).
"',";
372 $sql .=
" '".$this->db->escape($this->hexa).
"'";
375 $resql = $this->db->query($sql);
380 $this->error = $this->db->lasterror();
381 $this->errno = $this->db->lasterrno();
382 $this->db->rollback();
395 $sql =
'SELECT em.rowid, em.field, em.label, em.type';
396 $sql .=
' FROM '.MAIN_DB_PREFIX.
'import_model as em';
397 $sql .=
' WHERE em.rowid = '.((int) $id);
399 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
400 $result = $this->db->query($sql);
402 $obj = $this->db->fetch_object($result);
404 $this->
id = $obj->rowid;
405 $this->hexa = $obj->field;
406 $this->model_name = $obj->label;
407 $this->datatoimport = $obj->type;
408 $this->fk_user = $obj->fk_user;
411 $this->error =
"Model not found";