101 dol_syslog(get_class($this).
"::load_arrays user=".$user->id.
" filter=".$filter);
105 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
109 foreach ($modulesdir as $dir) {
111 if (!is_resource($handle)) {
116 while (($file = readdir($handle)) !==
false) {
117 if (!preg_match(
"/^(mod.*)\.class\.php/i", $file, $reg)) {
121 $modulename = $reg[1];
125 $part = strtolower(preg_replace(
'/^mod/i',
'', $modulename));
127 if ($part ===
'propale') {
130 if (empty($conf->$part->enabled)) {
134 if (empty($enabled)) {
139 $file = $dir.
"/".$modulename.
".class.php";
140 $classname = $modulename;
142 $module =
new $classname($this->db);
144 if (isset($module->import_code) && is_array($module->import_code)) {
145 foreach ($module->import_code as $r => $value) {
146 if ($filter && ($filter != $module->import_code[$r])) {
166 $langtoload = $module->getLangFilesArray();
167 if (is_array($langtoload)) {
168 foreach ($langtoload as $key) {
174 $this->array_import_perms[$i] = $user->rights->import->run;
176 $this->array_import_icon[$i] = (isset($module->import_icon[$r]) ? $module->import_icon[$r] : $module->picto);
178 $this->array_import_code[$i] = $module->import_code[$r];
180 $this->array_import_label[$i] = $module->getImportDatasetLabel($r);
182 $this->array_import_tables[$i] = $module->import_tables_array[$r];
184 $this->array_import_tables_creator[$i] = (isset($module->import_tables_creator_array[$r]) ? $module->import_tables_creator_array[$r] :
'');
186 $this->array_import_fields[$i] = $module->import_fields_array[$r];
188 $this->array_import_fieldshidden[$i] = (isset($module->import_fieldshidden_array[$r]) ? $module->import_fieldshidden_array[$r] :
'');
190 $this->array_import_entities[$i] = $module->import_entities_array[$r];
192 $this->array_import_regex[$i] = (isset($module->import_regex_array[$r]) ? $module->import_regex_array[$r] :
'');
194 $this->array_import_updatekeys[$i] = (isset($module->import_updatekeys_array[$r]) ? $module->import_updatekeys_array[$r] :
'');
196 $this->array_import_preselected_updatekeys[$i] = (isset($module->import_preselected_updatekeys_array[$r]) ? $module->import_preselected_updatekeys_array[$r] :
'');
198 $this->array_import_examplevalues[$i] = (isset($module->import_examplevalues_array[$r]) ? $module->import_examplevalues_array[$r] :
'');
200 $this->array_import_convertvalue[$i] = (isset($module->import_convertvalue_array[$r]) ? $module->import_convertvalue_array[$r] :
'');
202 $this->array_import_run_sql_after[$i] = (isset($module->import_run_sql_after_array[$r]) ? $module->import_run_sql_after_array[$r] :
'');
204 $this->array_import_module[$i] = array(
'position_of_profile'=>($module->module_position.
'-'.$module->import_code[$r]),
'module'=>$module);
206 dol_syslog(
"Import loaded for module ".$modulename.
" with index ".$i.
", dataset=".$module->import_code[$r].
", nb of fields=".count($module->import_fields_array[$r]));
232 global $conf, $langs;
236 dol_syslog(get_class($this).
"::build_example_file ".$model);
239 $dir = DOL_DOCUMENT_ROOT.
"/core/modules/import/";
240 $file =
"import_".$model.
".modules.php";
241 $classname =
"Import".$model;
242 require_once $dir.$file;
243 $objmodel =
new $classname($this->db, $datatoimport);
245 $outputlangs = $langs;
249 $s .= $objmodel->write_header_example($outputlangs);
252 $s .= $objmodel->write_title_example($outputlangs, $headerlinefields);
255 $s .= $objmodel->write_record_example($outputlangs, $contentlinevalues);
258 $s .= $objmodel->write_footer_example($outputlangs);
276 if (empty($this->model_name)) {
277 $this->error =
'ErrorWrongParameters';
280 if (empty($this->datatoimport)) {
281 $this->error =
'ErrorWrongParameters';
284 if (empty($this->hexa)) {
285 $this->error =
'ErrorWrongParameters';
291 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'import_model (';
298 $sql .= (isset($this->fk_user) ? (int) $this->fk_user :
'null').
",";
299 $sql .=
" '".$this->db->escape($this->model_name).
"',";
300 $sql .=
" '".$this->db->escape($this->datatoimport).
"',";
301 $sql .=
" '".$this->db->escape($this->hexa).
"'";
304 $resql = $this->db->query($sql);
309 $this->error = $this->db->lasterror();
310 $this->errno = $this->db->lasterrno();
311 $this->db->rollback();
324 $sql =
'SELECT em.rowid, em.field, em.label, em.type';
325 $sql .=
' FROM '.MAIN_DB_PREFIX.
'import_model as em';
326 $sql .=
' WHERE em.rowid = '.((int) $id);
328 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
329 $result = $this->db->query($sql);
331 $obj = $this->db->fetch_object($result);
333 $this->
id = $obj->rowid;
334 $this->hexa = $obj->field;
335 $this->model_name = $obj->label;
336 $this->datatoimport = $obj->type;
337 $this->fk_user = $obj->fk_user;
340 $this->error =
"Model not found";