28 require
'../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ecm.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/treeview.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmdirectory.class.php';
36 $langs->loadLangs(array(
'ecm',
'companies',
'other',
'users',
'orders',
'propal',
'bills',
'contracts'));
39 $socid =
GETPOST(
'socid',
'int');
40 $action =
GETPOST(
'action',
'aZ09');
45 $section_dir =
GETPOST(
'section_dir',
'alpha');
46 $overwritefile =
GETPOST(
'overwritefile',
'int');
48 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
49 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
50 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
52 if (empty($page) || $page == -1) {
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
67 $result = $ecmdir->fetch($section);
76 $userstatic =
new User($db);
82 $socid = $user->socid;
86 $permissiontoread = $user->hasRight(
'ecm',
'read');
87 $permissiontocreate = $user->hasRight(
'ecm',
'upload');
88 $permissiontocreatedir = $user->hasRight(
'ecm',
'setup');
89 $permissiontodelete = $user->hasRight(
'ecm',
'upload');
90 $permissiontodeletedir = $user->hasRight(
'ecm',
'setup');
102 if (
GETPOST(
"sendit",
'alphanohtml') && !empty($conf->global->MAIN_UPLOAD_DOC) && $permissiontocreate) {
106 $relativepath = $ecmdir->getRelativePath();
108 $relativepath = $section_dir;
110 $upload_dir = $conf->ecm->dir_output.
'/'.$relativepath;
113 if (is_array($_FILES[
'userfile'])) {
114 if (is_array($_FILES[
'userfile'][
'tmp_name'])) {
115 $userfiles = $_FILES[
'userfile'][
'tmp_name'];
117 $userfiles = array($_FILES[
'userfile'][
'tmp_name']);
121 foreach ($userfiles as $key => $userfile) {
122 if (empty($_FILES[
'userfile'][
'tmp_name'][$key])) {
124 if ($_FILES[
'userfile'][
'error'][$key] == 1 || $_FILES[
'userfile'][
'error'][$key] == 2) {
127 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")),
null,
'errors');
134 $res =
dol_add_file_process($upload_dir, $overwritefile, 1,
'userfile',
'',
null,
'', $generatethumbs);
136 $result = $ecmdir->changeNbOfFiles(
'+');
142 if ($action ==
'confirm_deletefile' && $permissiontodelete) {
143 if (
GETPOST(
'confirm') ==
'yes') {
146 $upload_dir = $conf->ecm->dir_output.($relativepath ?
'/'.$relativepath :
'');
147 $file = $upload_dir.
"/".
GETPOST(
'urlfile',
'alpha');
150 $urlfiletoshow =
GETPOST(
'urlfile',
'alpha');
151 $urlfiletoshow = preg_replace(
'/\.noexe$/',
'', $urlfiletoshow);
152 setEventMessages($langs->trans(
"FileWasRemoved", $urlfiletoshow),
null,
'mesgs');
153 $result = $ecmdir->changeNbOfFiles(
'-');
160 $action =
'file_manager';
164 if ($action ==
'add' && $permissiontocreatedir) {
165 $ecmdir->ref =
'NOTUSEDYET';
166 $ecmdir->label =
GETPOST(
"label");
167 $ecmdir->description =
GETPOST(
"desc");
169 $id = $ecmdir->create($user);
171 header(
"Location: ".$_SERVER[
"PHP_SELF"]);
182 if ($action ==
'confirm_deletesection' &&
GETPOST(
'confirm',
'alpha') ==
'yes' && $permissiontodeletedir) {
183 $result = $ecmdir->delete($user);
184 setEventMessages($langs->trans(
"ECMSectionWasRemoved", $ecmdir->label),
null,
'mesgs');
192 if ($action ==
'refreshmanual' && $permissiontoread) {
198 $diroutputslash = str_replace(
'\\',
'/', $conf->ecm->dir_output);
199 $diroutputslash .=
'/';
202 $disktree =
dol_dir_list($conf->ecm->dir_output,
'directories', 1,
'',
'^temp$',
'',
'', 0);
205 $sqltree = $ecmdirstatic->get_full_arbo(0);
212 foreach ($disktree as $dirdesc) {
213 $dirisindatabase = 0;
214 foreach ($sqltree as $dirsqldesc) {
215 if ($conf->ecm->dir_output.
'/'.$dirsqldesc[
'fullrelativename'] == $dirdesc[
'fullname']) {
216 $dirisindatabase = 1;
221 if (!$dirisindatabase) {
222 $txt =
"Directory found on disk ".$dirdesc[
'fullname'].
", not found into database so we add it";
228 $relativepathmissing = str_replace($diroutputslash,
'', $dirdesc[
'fullname']);
229 $relativepathtosearchparent = $relativepathmissing;
231 if (preg_match(
'/\//', $relativepathtosearchparent)) {
233 $relativepathtosearchparent = preg_replace(
'/\/[^\/]*$/',
'', $relativepathtosearchparent);
234 $txt =
"Is relative parent path ".$relativepathtosearchparent.
" for ".$relativepathmissing.
" found in sql tree ?";
237 $parentdirisindatabase = 0;
238 foreach ($sqltree as $dirsqldesc) {
239 if ($dirsqldesc[
'fullrelativename'] == $relativepathtosearchparent) {
240 $parentdirisindatabase = $dirsqldesc[
'id'];
244 if ($parentdirisindatabase > 0) {
245 dol_syslog(
"Yes with id ".$parentdirisindatabase);
247 $fk_parent = $parentdirisindatabase;
258 if ($fk_parent >= 0) {
259 $ecmdirtmp->ref =
'NOTUSEDYET';
261 $ecmdirtmp->description =
'';
262 $ecmdirtmp->fk_parent = $fk_parent;
264 $txt =
"We create directory ".$ecmdirtmp->label.
" with parent ".$fk_parent;
267 $id = $ecmdirtmp->create($user);
269 $newdirsql = array(
'id'=>$id,
270 'id_mere'=>$ecmdirtmp->fk_parent,
271 'label'=>$ecmdirtmp->label,
272 'description'=>$ecmdirtmp->description,
273 'fullrelativename'=>$relativepathmissing);
274 $sqltree[] = $newdirsql;
278 dol_syslog(
"Failed to create directory ".$ecmdirtmp->label, LOG_ERR);
281 $txt =
"Parent of ".$dirdesc[
'fullname'].
" not found";
289 foreach ($sqltree as $dirdesc) {
290 $dirtotest = $conf->ecm->dir_output.
'/'.$dirdesc[
'fullrelativename'];
292 $ecmdirtmp->id = $dirdesc[
'id'];
293 $ecmdirtmp->delete($user,
'databaseonly');
298 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ecm_directories set cachenbofdoc = -1 WHERE cachenbofdoc < 0";
304 if ($adirwascreated) {
317 $maxheightwin = (isset($_SESSION[
"dol_screenheight"]) && $_SESSION[
"dol_screenheight"] > 466) ? ($_SESSION[
"dol_screenheight"] - 136) : 660;
323 $morejs = array(
'includes/jquery/plugins/blockUI/jquery.blockUI.js',
'core/js/blockUI.js');
324 if (empty($conf->global->MAIN_ECM_DISABLE_JS)) {
325 $morejs[] =
"includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js";
328 $moreheadjs .=
'<script type="text/javascript">'.
"\n";
329 $moreheadjs .=
'var indicatorBlockUI = \''.DOL_URL_ROOT.
"/theme/".$conf->theme.
"/img/working.gif".
'\';
'."\n";
330 $moreheadjs .= '</script>
'."\n";
332 llxHeader($moreheadcss.$moreheadjs, $langs->trans("ECMArea"), '', '', '', '', $morejs, '', 0, 0);
334 $head = ecm_prepare_dasboard_head('');
335 print dol_get_fiche_head($head, 'index
', '', -1, '');
338 // Add filemanager component
341 $url = DOL_URL_ROOT.'/ecm/index.php
'; // Must be an url without param
343 include DOL_DOCUMENT_ROOT.'/core/tpl/filemanager.tpl.php
';
346 print dol_get_fiche_end();
Class to manage ECM directories.
Class to manage Dolibarr users.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
dol_basename($pathfile)
Make a basename working with all page code (default PHP basenamed fails with cyrillic).
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null)
Get and save an upload file (for example after submitting a new file a mail form).
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.