100 dol_syslog(get_class($this).
"::load_arrays user=".$user->id.
" filter=".$filter);
104 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
108 foreach ($modulesdir as $dir) {
110 if (!is_resource($handle)) {
115 while (($file = readdir($handle)) !==
false) {
116 if (!preg_match(
"/^(mod.*)\.class\.php/i", $file, $reg)) {
120 $modulename = $reg[1];
124 $part = strtolower(preg_replace(
'/^mod/i',
'', $modulename));
126 if ($part ===
'propale') {
129 if (empty($conf->$part->enabled)) {
133 if (empty($enabled)) {
138 $file = $dir.
"/".$modulename.
".class.php";
139 $classname = $modulename;
141 $module =
new $classname($this->db);
143 if (isset($module->import_code) && is_array($module->import_code)) {
144 foreach ($module->import_code as $r => $value) {
145 if ($filter && ($filter != $module->import_code[$r])) {
165 $langtoload = $module->getLangFilesArray();
166 if (is_array($langtoload)) {
167 foreach ($langtoload as $key) {
173 $this->array_import_perms[$i] = $user->rights->import->run;
175 $this->array_import_icon[$i] = (isset($module->import_icon[$r]) ? $module->import_icon[$r] : $module->picto);
177 $this->array_import_code[$i] = $module->import_code[$r];
179 $this->array_import_label[$i] = $module->getImportDatasetLabel($r);
181 $this->array_import_tables[$i] = $module->import_tables_array[$r];
183 $this->array_import_tables_creator[$i] = (isset($module->import_tables_creator_array[$r]) ? $module->import_tables_creator_array[$r] :
'');
185 $this->array_import_fields[$i] = $module->import_fields_array[$r];
187 $this->array_import_fieldshidden[$i] = (isset($module->import_fieldshidden_array[$r]) ? $module->import_fieldshidden_array[$r] :
'');
189 $this->array_import_entities[$i] = $module->import_entities_array[$r];
191 $this->array_import_regex[$i] = (isset($module->import_regex_array[$r]) ? $module->import_regex_array[$r] :
'');
193 $this->array_import_updatekeys[$i] = (isset($module->import_updatekeys_array[$r]) ? $module->import_updatekeys_array[$r] :
'');
195 $this->array_import_examplevalues[$i] = (isset($module->import_examplevalues_array[$r]) ? $module->import_examplevalues_array[$r] :
'');
197 $this->array_import_convertvalue[$i] = (isset($module->import_convertvalue_array[$r]) ? $module->import_convertvalue_array[$r] :
'');
199 $this->array_import_run_sql_after[$i] = (isset($module->import_run_sql_after_array[$r]) ? $module->import_run_sql_after_array[$r] :
'');
201 $this->array_import_module[$i] = array(
'position_of_profile'=>($module->module_position.
'-'.$module->import_code[$r]),
'module'=>$module);
203 dol_syslog(
"Import loaded for module ".$modulename.
" with index ".$i.
", dataset=".$module->import_code[$r].
", nb of fields=".count($module->import_fields_array[$r]));
229 global $conf, $langs;
233 dol_syslog(get_class($this).
"::build_example_file ".$model);
236 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
237 $file =
"import_".$model.
".modules.php";
238 $classname =
"Import".$model;
239 require_once $dir.$file;
240 $objmodel =
new $classname($this->db, $datatoimport);
242 $outputlangs = $langs;
246 $s .= $objmodel->write_header_example($outputlangs);
249 $s .= $objmodel->write_title_example($outputlangs, $headerlinefields);
252 $s .= $objmodel->write_record_example($outputlangs, $contentlinevalues);
255 $s .= $objmodel->write_footer_example($outputlangs);
273 if (empty($this->model_name)) {
274 $this->error =
'ErrorWrongParameters';
return -1;
276 if (empty($this->datatoimport)) {
277 $this->error =
'ErrorWrongParameters';
return -1;
279 if (empty($this->hexa)) {
280 $this->error =
'ErrorWrongParameters';
return -1;
285 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'import_model (';
292 $sql .= (isset($this->fk_user) ? (int) $this->fk_user :
'null').
",";
293 $sql .=
" '".$this->db->escape($this->model_name).
"',";
294 $sql .=
" '".$this->db->escape($this->datatoimport).
"',";
295 $sql .=
" '".$this->db->escape($this->hexa).
"'";
298 $resql = $this->db->query($sql);
303 $this->error = $this->db->lasterror();
304 $this->errno = $this->db->lasterrno();
305 $this->db->rollback();
318 $sql =
'SELECT em.rowid, em.field, em.label, em.type';
319 $sql .=
' FROM '.MAIN_DB_PREFIX.
'import_model as em';
320 $sql .=
' WHERE em.rowid = '.((int) $id);
322 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
323 $result = $this->db->query($sql);
325 $obj = $this->db->fetch_object($result);
327 $this->
id = $obj->rowid;
328 $this->hexa = $obj->field;
329 $this->model_name = $obj->label;
330 $this->datatoimport = $obj->type;
331 $this->fk_user = $obj->fk_user;
334 $this->error =
"Model not found";