/** * Retourne la liste des categories du type choisi * * @param int $selected Id categorie preselectionnee * @param string $select_name Nom formulaire HTML * @return string String with HTML select */ function select_all_sections($selected = 0, $select_name = '') { global $langs; $langs->load("ecm"); if ($select_name == "") { $select_name = "catParent"; } $cat = new EcmDirectory($this->db); $cate_arbo = $cat->get_full_arbo(); $output = '<select class="flat" name="' . $select_name . '">'; if (is_array($cate_arbo)) { if (!count($cate_arbo)) { $output .= '<option value="-1" disabled="disabled">' . $langs->trans("NoCategoriesDefined") . '</option>'; } else { $output .= '<option value="-1"> </option>'; foreach ($cate_arbo as $key => $value) { if ($cate_arbo[$key]['id'] == $selected) { $add = 'selected="selected" '; } else { $add = ''; } $output .= '<option ' . $add . 'value="' . $cate_arbo[$key]['id'] . '">' . $cate_arbo[$key]['fulllabel'] . '</option>'; } } } $output .= '</select>'; $output .= "\n"; return $output; }
if ($action == 'confirm_deletesection' && GETPOST('confirm') == 'yes') { $result = $ecmdir->delete($user); setEventMessage($langs->trans("ECMSectionWasRemoved", $ecmdir->label)); clearstatcache(); } // Refresh directory view if ($action == 'refreshmanual') { $ecmdirtmp = new EcmDirectory($db); // This part of code is same than into file ecm/ajax/ecmdatabase.php TODO Remove duplicate clearstatcache(); $diroutputslash = str_replace('\\', '/', $conf->ecm->dir_output); $diroutputslash .= '/'; // Scan directory tree on disk $disktree = dol_dir_list($conf->ecm->dir_output, 'directories', 1, '', '^temp$', '', '', 0); // Scan directory tree in database $sqltree = $ecmdirstatic->get_full_arbo(0); $adirwascreated = 0; // Now we compare both trees to complete missing trees into database //var_dump($disktree); //var_dump($sqltree); foreach ($disktree as $dirdesc) { $dirisindatabase = 0; foreach ($sqltree as $dirsqldesc) { if ($conf->ecm->dir_output . '/' . $dirsqldesc['fullrelativename'] == $dirdesc['fullname']) { $dirisindatabase = 1; break; } } if (!$dirisindatabase) { $txt = "Directory found on disk " . $dirdesc['fullname'] . ", not found into database so we add it"; dol_syslog($txt);
/** * Create record into database * * @param User $user User that create * @return int <0 if KO, >0 if OK */ function create($user) { global $conf, $langs; $error = 0; $now = dol_now(); // Clean parameters $this->label = dol_sanitizeFileName(trim($this->label)); $this->fk_parent = trim($this->fk_parent); $this->description = trim($this->description); $this->date_c = $now; $this->fk_user_c = $user->id; if ($this->fk_parent <= 0) { $this->fk_parent = 0; } // Check if same directory does not exists with this name $relativepath = $this->label; if ($this->fk_parent) { $parent = new EcmDirectory($this->db); $parent->fetch($this->fk_parent); $relativepath = $parent->getRelativePath() . $relativepath; } $relativepath = preg_replace('/([\\/])+/i', '/', $relativepath); // Avoid duplicate / or \ //print $relativepath.'<br>'; $cat = new EcmDirectory($this->db); $cate_arbo = $cat->get_full_arbo(1); $pathfound = 0; foreach ($cate_arbo as $key => $categ) { $path = str_replace($this->forbiddenchars, '_', $categ['fulllabel']); //print $path.'<br>'; if ($path == $relativepath) { $pathfound = 1; break; } } if ($pathfound) { $this->error = "ErrorDirAlreadyExists"; dol_syslog(get_class($this) . "::create " . $this->error, LOG_WARNING); return -1; } else { $this->db->begin(); // Insert request $sql = "INSERT INTO " . MAIN_DB_PREFIX . "ecm_directories("; $sql .= "label,"; $sql .= "entity,"; $sql .= "fk_parent,"; $sql .= "description,"; $sql .= "cachenbofdoc,"; $sql .= "date_c,"; $sql .= "fk_user_c"; $sql .= ") VALUES ("; $sql .= " '" . $this->db->escape($this->label) . "',"; $sql .= " '" . $conf->entity . "',"; $sql .= " '" . $this->fk_parent . "',"; $sql .= " '" . $this->db->escape($this->description) . "',"; $sql .= " " . $this->cachenbofdoc . ","; $sql .= " '" . $this->db->idate($this->date_c) . "',"; $sql .= " '" . $this->fk_user_c . "'"; $sql .= ")"; dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "ecm_directories"); $dir = $conf->ecm->dir_output . '/' . $this->getRelativePath(); $result = dol_mkdir($dir); if ($result < 0) { $error++; $this->error = "ErrorFailedToCreateDir"; } // Appel des triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface = new Interfaces($this->db); $result = $interface->run_triggers('MYECMDIR_CREATE', $this, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // Fin appel triggers if (!$error) { $this->db->commit(); return $this->id; } else { $this->db->rollback(); return -1; } } else { $this->error = "Error " . $this->db->lasterror(); dol_syslog(get_class($this) . "::create " . $this->error, LOG_ERR); $this->db->rollback(); return -1; } } }