index.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. <?php
  2. /* Copyright (C) 2008-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2008-2010 Regis Houssin <regis.houssin@capnetworks.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/ecm/index.php
  20. * \ingroup ecm
  21. * \brief Main page for ECM section area
  22. * \author Laurent Destailleur
  23. */
  24. if (! defined('REQUIRE_JQUERY_LAYOUT')) define('REQUIRE_JQUERY_LAYOUT','1');
  25. if (! defined('REQUIRE_JQUERY_BLOCKUI')) define('REQUIRE_JQUERY_BLOCKUI', 1);
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/ecm.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
  32. // Load traductions files
  33. $langs->load("ecm");
  34. $langs->load("companies");
  35. $langs->load("other");
  36. $langs->load("users");
  37. $langs->load("orders");
  38. $langs->load("propal");
  39. $langs->load("bills");
  40. $langs->load("contracts");
  41. // Security check
  42. if ($user->societe_id) $socid=$user->societe_id;
  43. $result = restrictedArea($user, 'ecm', 0);
  44. // Get parameters
  45. $socid=GETPOST('socid','int');
  46. $action=GETPOST('action','aZ09');
  47. $section=GETPOST("section")?GETPOST("section","int"):GETPOST("section_id","int");
  48. $module=GETPOST("module");
  49. if (! $section) $section=0;
  50. $section_dir=GETPOST('section_dir');
  51. $sortfield = GETPOST("sortfield",'alpha');
  52. $sortorder = GETPOST("sortorder",'alpha');
  53. $page = GETPOST("page",'int');
  54. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  55. $offset = $conf->liste_limit * $page;
  56. $pageprev = $page - 1;
  57. $pagenext = $page + 1;
  58. if (! $sortorder) $sortorder="ASC";
  59. if (! $sortfield) $sortfield="fullname";
  60. if ($module == 'invoice_supplier' && $sortfield == "fullname") $sortfield="level1name";
  61. $ecmdir = new EcmDirectory($db);
  62. if ($section)
  63. {
  64. $result=$ecmdir->fetch($section);
  65. if (! $result > 0)
  66. {
  67. dol_print_error($db,$ecmdir->error);
  68. exit;
  69. }
  70. }
  71. $form=new Form($db);
  72. $ecmdirstatic = new EcmDirectory($db);
  73. $userstatic = new User($db);
  74. $error=0;
  75. /*
  76. * Actions
  77. */
  78. // Upload file
  79. if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
  80. {
  81. // Define relativepath and upload_dir
  82. $relativepath='';
  83. if ($ecmdir->id) $relativepath=$ecmdir->getRelativePath();
  84. else $relativepath=$section_dir;
  85. $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
  86. if (empty($_FILES['userfile']['tmp_name']))
  87. {
  88. $error++;
  89. if($_FILES['userfile']['error'] == 1 || $_FILES['userfile']['error'] == 2){
  90. setEventMessages($langs->trans('ErrorFileSizeTooLarge'),null, 'errors');
  91. }
  92. else {
  93. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
  94. }
  95. }
  96. if (! $error)
  97. {
  98. $res = dol_add_file_process($upload_dir, 0, 1, 'userfile', '', '', '');
  99. if ($res > 0)
  100. {
  101. $result=$ecmdir->changeNbOfFiles('+');
  102. }
  103. }
  104. }
  105. // Add directory
  106. if ($action == 'add' && $user->rights->ecm->setup)
  107. {
  108. $ecmdir->ref = 'NOTUSEDYET';
  109. $ecmdir->label = GETPOST("label");
  110. $ecmdir->description = GETPOST("desc");
  111. $id = $ecmdir->create($user);
  112. if ($id > 0)
  113. {
  114. header("Location: ".$_SERVER["PHP_SELF"]);
  115. exit;
  116. }
  117. else
  118. {
  119. setEventMessages('Error '.$langs->trans($ecmdir->error), null, 'errors');
  120. $action = "create";
  121. }
  122. clearstatcache();
  123. }
  124. // Remove file
  125. if ($action == 'confirm_deletefile')
  126. {
  127. if (GETPOST('confirm') == 'yes')
  128. {
  129. $langs->load("other");
  130. if ($section)
  131. {
  132. $result=$ecmdir->fetch($section);
  133. if (! ($result > 0))
  134. {
  135. dol_print_error($db,$ecmdir->error);
  136. exit;
  137. }
  138. }
  139. else $relativepath='';
  140. $upload_dir = $conf->ecm->dir_output;
  141. $file = $upload_dir . "/" . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_POST are already decoded by PHP).
  142. $ret=dol_delete_file($file);
  143. if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
  144. else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
  145. $result=$ecmdir->changeNbOfFiles('-');
  146. clearstatcache();
  147. }
  148. $action='file_manager';
  149. }
  150. // Remove directory
  151. if ($action == 'confirm_deletesection' && GETPOST('confirm') == 'yes')
  152. {
  153. $result=$ecmdir->delete($user);
  154. setEventMessages($langs->trans("ECMSectionWasRemoved", $ecmdir->label), null, 'mesgs');
  155. clearstatcache();
  156. }
  157. // Refresh directory view
  158. // This refresh list of dirs, not list of files (for preformance reason). List of files is refresh only if dir was not synchronized.
  159. // To refresh content of dir with cache, just open the dir in edit mode.
  160. if ($action == 'refreshmanual')
  161. {
  162. $ecmdirtmp = new EcmDirectory($db);
  163. // This part of code is same than into file ecm/ajax/ecmdatabase.php TODO Remove duplicate
  164. clearstatcache();
  165. $diroutputslash=str_replace('\\','/',$conf->ecm->dir_output);
  166. $diroutputslash.='/';
  167. // Scan directory tree on disk
  168. $disktree=dol_dir_list($conf->ecm->dir_output,'directories',1,'','^temp$','','',0);
  169. // Scan directory tree in database
  170. $sqltree=$ecmdirstatic->get_full_arbo(0);
  171. $adirwascreated=0;
  172. // Now we compare both trees to complete missing trees into database
  173. //var_dump($disktree);
  174. //var_dump($sqltree);
  175. foreach($disktree as $dirdesc) // Loop on tree onto disk
  176. {
  177. $dirisindatabase=0;
  178. foreach($sqltree as $dirsqldesc)
  179. {
  180. if ($conf->ecm->dir_output.'/'.$dirsqldesc['fullrelativename'] == $dirdesc['fullname'])
  181. {
  182. $dirisindatabase=1;
  183. break;
  184. }
  185. }
  186. if (! $dirisindatabase)
  187. {
  188. $txt="Directory found on disk ".$dirdesc['fullname'].", not found into database so we add it";
  189. dol_syslog($txt);
  190. //print $txt."<br>\n";
  191. // We must first find the fk_parent of directory to create $dirdesc['fullname']
  192. $fk_parent=-1;
  193. $relativepathmissing=str_replace($diroutputslash,'',$dirdesc['fullname']);
  194. $relativepathtosearchparent=$relativepathmissing;
  195. //dol_syslog("Try to find parent id for directory ".$relativepathtosearchparent);
  196. if (preg_match('/\//',$relativepathtosearchparent))
  197. //while (preg_match('/\//',$relativepathtosearchparent))
  198. {
  199. $relativepathtosearchparent=preg_replace('/\/[^\/]*$/','',$relativepathtosearchparent);
  200. $txt="Is relative parent path ".$relativepathtosearchparent." for ".$relativepathmissing." found in sql tree ?";
  201. dol_syslog($txt);
  202. //print $txt." -> ";
  203. $parentdirisindatabase=0;
  204. foreach($sqltree as $dirsqldesc)
  205. {
  206. if ($dirsqldesc['fullrelativename'] == $relativepathtosearchparent)
  207. {
  208. $parentdirisindatabase=$dirsqldesc['id'];
  209. break;
  210. }
  211. }
  212. if ($parentdirisindatabase > 0)
  213. {
  214. dol_syslog("Yes with id ".$parentdirisindatabase);
  215. //print "Yes with id ".$parentdirisindatabase."<br>\n";
  216. $fk_parent=$parentdirisindatabase;
  217. //break; // We found parent, we can stop the while loop
  218. }
  219. else
  220. {
  221. dol_syslog("No");
  222. //print "No<br>\n";
  223. }
  224. }
  225. else
  226. {
  227. dol_syslog("Parent is root");
  228. $fk_parent=0; // Parent is root
  229. }
  230. if ($fk_parent >= 0)
  231. {
  232. $ecmdirtmp->ref = 'NOTUSEDYET';
  233. $ecmdirtmp->label = dol_basename($dirdesc['fullname']);
  234. $ecmdirtmp->description = '';
  235. $ecmdirtmp->fk_parent = $fk_parent;
  236. $txt="We create directory ".$ecmdirtmp->label." with parent ".$fk_parent;
  237. dol_syslog($txt);
  238. //print $ecmdirtmp->cachenbofdoc."<br>\n";exit;
  239. $id = $ecmdirtmp->create($user);
  240. if ($id > 0)
  241. {
  242. $newdirsql=array('id'=>$id,
  243. 'id_mere'=>$ecmdirtmp->fk_parent,
  244. 'label'=>$ecmdirtmp->label,
  245. 'description'=>$ecmdirtmp->description,
  246. 'fullrelativename'=>$relativepathmissing);
  247. $sqltree[]=$newdirsql; // We complete fulltree for following loops
  248. //var_dump($sqltree);
  249. $adirwascreated=1;
  250. }
  251. else
  252. {
  253. dol_syslog("Failed to create directory ".$ecmdirtmp->label, LOG_ERR);
  254. }
  255. }
  256. else {
  257. $txt="Parent of ".$dirdesc['fullname']." not found";
  258. dol_syslog($txt);
  259. //print $txt."<br>\n";
  260. }
  261. }
  262. }
  263. // Loop now on each sql tree to check if dir exists
  264. foreach($sqltree as $dirdesc) // Loop on each sqltree to check dir is on disk
  265. {
  266. $dirtotest=$conf->ecm->dir_output.'/'.$dirdesc['fullrelativename'];
  267. if (! dol_is_dir($dirtotest))
  268. {
  269. $ecmdirtmp->id=$dirdesc['id'];
  270. $ecmdirtmp->delete($user,'databaseonly');
  271. //exit;
  272. }
  273. }
  274. $sql="UPDATE ".MAIN_DB_PREFIX."ecm_directories set cachenbofdoc = -1 WHERE cachenbofdoc < 0"; // If pb into cahce counting, we set to value -1 = "unknown"
  275. dol_syslog("sql = ".$sql);
  276. $db->query($sql);
  277. // If a directory was added, the fulltree array is not correctly completed and sorted, so we clean
  278. // it to be sure that fulltree array is not used without reloading it.
  279. if ($adirwascreated) $sqltree=null;
  280. }
  281. /*
  282. * View
  283. */
  284. // Define height of file area (depends on $_SESSION["dol_screenheight"])
  285. //print $_SESSION["dol_screenheight"];
  286. $maxheightwin=(isset($_SESSION["dol_screenheight"]) && $_SESSION["dol_screenheight"] > 466)?($_SESSION["dol_screenheight"]-136):660; // Also into index_auto.php file
  287. $morejs=array();
  288. if (empty($conf->global->MAIN_ECM_DISABLE_JS)) $morejs=array("/includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js");
  289. llxHeader($moreheadcss.$moreheadjs,$langs->trans("ECMArea"),'','','','',$morejs,'',0,0);
  290. // Add sections to manage
  291. $rowspan=0;
  292. $sectionauto=array();
  293. if (! empty($conf->global->ECM_AUTO_TREE_ENABLED))
  294. {
  295. if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) { $langs->load("products"); $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'product', 'test'=>(! empty($conf->product->enabled) || ! empty($conf->service->enabled)), 'label'=>$langs->trans("ProductsAndServices"), 'desc'=>$langs->trans("ECMDocsByProducts")); }
  296. if (! empty($conf->societe->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'company', 'test'=>$conf->societe->enabled, 'label'=>$langs->trans("ThirdParties"), 'desc'=>$langs->trans("ECMDocsByThirdParties")); }
  297. if (! empty($conf->propal->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'propal', 'test'=>$conf->propal->enabled, 'label'=>$langs->trans("Prop"), 'desc'=>$langs->trans("ECMDocsByProposals")); }
  298. if (! empty($conf->contrat->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'contract','test'=>$conf->contrat->enabled, 'label'=>$langs->trans("Contracts"), 'desc'=>$langs->trans("ECMDocsByContracts")); }
  299. if (! empty($conf->commande->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'order', 'test'=>$conf->commande->enabled,'label'=>$langs->trans("CustomersOrders"), 'desc'=>$langs->trans("ECMDocsByOrders")); }
  300. if (! empty($conf->facture->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'invoice', 'test'=>$conf->facture->enabled, 'label'=>$langs->trans("CustomersInvoices"), 'desc'=>$langs->trans("ECMDocsByInvoices")); }
  301. if (! empty($conf->fournisseur->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'order_supplier', 'test'=>$conf->fournisseur->enabled, 'label'=>$langs->trans("SuppliersOrders"), 'desc'=>$langs->trans("ECMDocsByOrders")); }
  302. if (! empty($conf->fournisseur->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'invoice_supplier', 'test'=>$conf->fournisseur->enabled, 'label'=>$langs->trans("SuppliersInvoices"), 'desc'=>$langs->trans("ECMDocsByInvoices")); }
  303. if (! empty($conf->tax->enabled)) { $langs->load("compta"); $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'tax', 'test'=>$conf->tax->enabled, 'label'=>$langs->trans("SocialContributions"), 'desc'=>$langs->trans("ECMDocsBySocialContributions")); }
  304. if (! empty($conf->projet->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'project', 'test'=>$conf->projet->enabled, 'label'=>$langs->trans("Projects"), 'desc'=>$langs->trans("ECMDocsByProjects")); }
  305. }
  306. // Confirm remove file (for non javascript users)
  307. if ($action == 'delete' && empty($conf->use_javascript_ajax))
  308. {
  309. print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.$section.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1);
  310. }
  311. //if (! empty($conf->use_javascript_ajax)) $classviewhide='hidden';
  312. //else $classviewhide='visible';
  313. $classviewhide='inline-block';
  314. $head = ecm_prepare_dasboard_head('');
  315. dol_fiche_head($head, 'index', $langs->trans("ECMArea").' - '.$langs->trans("ECMFileManager"), 1, '');
  316. // Start container of all panels
  317. ?>
  318. <!-- Begin div id="containerlayout" -->
  319. <div id="containerlayout">
  320. <div id="ecm-layout-north" class="toolbar largebutton">
  321. <?php
  322. // Start top panel, toolbar
  323. print '<div class="toolbarbutton">';
  324. // Toolbar
  325. if ($user->rights->ecm->setup)
  326. {
  327. print '<a href="'.DOL_URL_ROOT.'/ecm/docdir.php?action=create" class="toolbarbutton" title="'.dol_escape_htmltag($langs->trans('ECMAddSection')).'">';
  328. print '<img class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
  329. print '</a>';
  330. }
  331. else
  332. {
  333. print '<a href="#" class="toolbarbutton" title="'.$langs->trans("NotAllowed").'">';
  334. print '<img class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
  335. print '</a>';
  336. }
  337. $relativeurl=((! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))?'#':($_SERVER["PHP_SELF"].'?action=refreshmanual'.($module?'&amp;module='.$module:'').($section?'&amp;section='.$section:'')));
  338. print '<a href="'.$relativeurl.'" class="toolbarbutton" title="'.dol_escape_htmltag($langs->trans('Refresh')).'">';
  339. print '<img id="refreshbutton" class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/view-refresh.png">';
  340. print '</a>';
  341. print '</div>';
  342. // End top panel, toolbar
  343. ?>
  344. </div>
  345. <div id="ecm-layout-west" class="<?php echo $classviewhide; ?>">
  346. <?php
  347. // Start left area
  348. // Confirmation de la suppression d'une ligne categorie
  349. if ($action == 'delete_section')
  350. {
  351. print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.$section, $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection','','',1);
  352. }
  353. // End confirm
  354. if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$action) || $action == 'delete')
  355. {
  356. print '<table width="100%" class="liste noborderbottom">'."\n";
  357. print '<!-- Title for manual directories -->'."\n";
  358. print '<tr class="liste_titre">'."\n";
  359. print '<th class="liste_titre" align="left" colspan="6">';
  360. print '&nbsp;'.$langs->trans("ECMSections");
  361. print '</th></tr>';
  362. $showonrightsize='';
  363. // Manual section
  364. $htmltooltip=$langs->trans("ECMAreaDesc2");
  365. if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))
  366. {
  367. print '<tr><td colspan="6">';
  368. // Show filemanager tree
  369. print '<div id="filetree" class="ecmfiletree"></div>';
  370. if ($action == 'deletefile') print $form->formconfirm('eeeee', $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', '', 'deletefile');
  371. print '</td></tr>';
  372. }
  373. else
  374. {
  375. print '<tr><td colspan="6" style="padding-left: 20px">';
  376. print '<div id="filetree" class="ecmfiletree">';
  377. print '<ul class="ecmjqft">';
  378. // Load full tree
  379. if (empty($sqltree)) $sqltree=$ecmdirstatic->get_full_arbo(0); // Slow
  380. // ----- This section will show a tree from a fulltree array -----
  381. // $section must also be defined
  382. // ----------------------------------------------------------------
  383. // Define fullpathselected ( _x_y_z ) of $section parameter
  384. $fullpathselected='';
  385. foreach($sqltree as $key => $val)
  386. {
  387. //print $val['id']."-".$section."<br>";
  388. if ($val['id'] == $section)
  389. {
  390. $fullpathselected=$val['fullpath'];
  391. break;
  392. }
  393. }
  394. //print "fullpathselected=".$fullpathselected."<br>";
  395. // Update expandedsectionarray in session
  396. $expandedsectionarray=array();
  397. if (isset($_SESSION['dol_ecmexpandedsectionarray'])) $expandedsectionarray=explode(',',$_SESSION['dol_ecmexpandedsectionarray']);
  398. if ($section && GETPOST('sectionexpand') == 'true')
  399. {
  400. // We add all sections that are parent of opened section
  401. $pathtosection=explode('_',$fullpathselected);
  402. foreach($pathtosection as $idcursor)
  403. {
  404. if ($idcursor && ! in_array($idcursor,$expandedsectionarray)) // Not already in array
  405. {
  406. $expandedsectionarray[]=$idcursor;
  407. }
  408. }
  409. $_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray);
  410. }
  411. if ($section && GETPOST('sectionexpand') == 'false')
  412. {
  413. // We removed all expanded sections that are child of the closed section
  414. $oldexpandedsectionarray=$expandedsectionarray;
  415. $expandedsectionarray=array(); // Reset
  416. foreach($oldexpandedsectionarray as $sectioncursor)
  417. {
  418. // is_in_subtree(fulltree,sectionparent,sectionchild)
  419. if ($sectioncursor && ! is_in_subtree($sqltree,$section,$sectioncursor)) $expandedsectionarray[]=$sectioncursor;
  420. }
  421. $_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray);
  422. }
  423. //print $_SESSION['dol_ecmexpandedsectionarray'].'<br>';
  424. $nbofentries=0;
  425. $oldvallevel=0;
  426. $var=true;
  427. foreach($sqltree as $key => $val)
  428. {
  429. $var=false;
  430. $ecmdirstatic->id=$val['id'];
  431. $ecmdirstatic->ref=$val['label'];
  432. // Refresh cache
  433. if (preg_match('/refresh/i',$action))
  434. {
  435. $result=$ecmdirstatic->fetch($val['id']);
  436. $ecmdirstatic->ref=$ecmdirstatic->label;
  437. $result=$ecmdirstatic->refreshcachenboffile(0);
  438. $val['cachenbofdoc']=$result;
  439. }
  440. //$fullpathparent=preg_replace('/(_[^_]+)$/i','',$val['fullpath']);
  441. // Define showline
  442. $showline=0;
  443. // If directory is son of expanded directory, we show line
  444. if (in_array($val['id_mere'],$expandedsectionarray)) $showline=4;
  445. // If directory is brother of selected directory, we show line
  446. elseif ($val['id'] != $section && $val['id_mere'] == $ecmdirstatic->motherof[$section]) $showline=3;
  447. // If directory is parent of selected directory or is selected directory, we show line
  448. elseif (preg_match('/'.$val['fullpath'].'_/i',$fullpathselected.'_')) $showline=2;
  449. // If we are level one we show line
  450. elseif ($val['level'] < 2) $showline=1;
  451. if ($showline)
  452. {
  453. if (in_array($val['id'],$expandedsectionarray)) $option='indexexpanded';
  454. else $option='indexnotexpanded';
  455. //print $option;
  456. print '<li class="directory collapsed">';
  457. // Show tree graph pictos
  458. $cpt=1;
  459. while ($cpt < $sqltree[$key]['level'])
  460. {
  461. print ' &nbsp; &nbsp;';
  462. $cpt++;
  463. }
  464. $resarray=tree_showpad($sqltree,$key,1);
  465. $a=$resarray[0];
  466. $nbofsubdir=$resarray[1];
  467. $nboffilesinsubdir=$resarray[2];
  468. // Show link
  469. print $ecmdirstatic->getNomUrl(0,$option,32,'class="fmdirlia jqft ecmjqft"');
  470. print '<div class="ecmjqft">';
  471. // Nb of docs
  472. print '<table class="nobordernopadding"><tr><td>';
  473. print $val['cachenbofdoc'];
  474. print '</td>';
  475. print '<td align="left">';
  476. if ($nbofsubdir && $nboffilesinsubdir) print '<font color="#AAAAAA">+'.$nboffilesinsubdir.'</font> ';
  477. print '</td>';
  478. // Info
  479. print '<td align="center">';
  480. $userstatic->id=$val['fk_user_c'];
  481. $userstatic->lastname=$val['login_c'];
  482. $htmltooltip='<b>'.$langs->trans("ECMSection").'</b>: '.$val['label'].'<br>';
  483. $htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMSectionManual").'<br>';
  484. $htmltooltip.='<b>'.$langs->trans("ECMCreationUser").'</b>: '.$userstatic->getNomUrl(1, '', false, 1).'<br>';
  485. $htmltooltip.='<b>'.$langs->trans("ECMCreationDate").'</b>: '.dol_print_date($val['date_c'],"dayhour").'<br>';
  486. $htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['description'].'<br>';
  487. $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInDir").'</b>: '.$val['cachenbofdoc'].'<br>';
  488. if ($nbofsubdir) $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInSubDir").'</b>: '.$nboffilesinsubdir;
  489. else $htmltooltip.='<b>'.$langs->trans("ECMNbOfSubDir").'</b>: '.$nbofsubdir.'<br>';
  490. print $form->textwithpicto('', $htmltooltip, 1, 'info');
  491. print "</td>";
  492. print '</tr></table>';
  493. print '</div>';
  494. print "</li>\n";
  495. }
  496. $oldvallevel=$val['level'];
  497. $nbofentries++;
  498. }
  499. // If nothing to show
  500. if ($nbofentries == 0)
  501. {
  502. print '<li class="directory collapsed">';
  503. print '<div class="ecmjqft">';
  504. print $langs->trans("ECMNoDirectoryYet");
  505. print '</div>';
  506. print "</li>\n";
  507. }
  508. print '</ul>';
  509. print '</div>';
  510. print '</td></tr>';
  511. }
  512. print "</table>";
  513. }
  514. // End left panel
  515. ?>
  516. </div>
  517. <div id="ecm-layout-center" class="<?php echo $classviewhide; ?>">
  518. <div class="pane-in ecm-in-layout-center">
  519. <div id="ecmfileview" class="ecmfileview">
  520. <?php
  521. // Start right panel
  522. $mode='noajax';
  523. $url=DOL_URL_ROOT.'/ecm/index.php';
  524. include_once DOL_DOCUMENT_ROOT.'/core/ajax/ajaxdirpreview.php';
  525. // End right panel
  526. ?>
  527. </div>
  528. </div>
  529. <div class="pane-in ecm-in-layout-south layout-padding valignmiddle">
  530. <?php
  531. // Start Add new file area
  532. // To attach new file
  533. if ((! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) || ! empty($section))
  534. {
  535. if (empty($section) || $section == -1)
  536. {
  537. ?>
  538. <script type="text/javascript">
  539. jQuery(document).ready(function() {
  540. jQuery('#formuserfile').hide();
  541. });
  542. </script>
  543. <?php
  544. }
  545. $formfile=new FormFile($db);
  546. $formfile->form_attach_new_file($_SERVER["PHP_SELF"], 'none', 0, ($section?$section:-1), $user->rights->ecm->upload, 48, null, '', 0, '', 0, 'formuserfile');
  547. }
  548. else print '&nbsp;';
  549. // End Add new file area
  550. ?>
  551. </div>
  552. </div>
  553. </div> <!-- End div id="containerlayout" -->
  554. <?php
  555. // End of page
  556. dol_fiche_end(1);
  557. if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) {
  558. include DOL_DOCUMENT_ROOT.'/ecm/tpl/enablefiletreeajax.tpl.php';
  559. }
  560. llxFooter();
  561. $db->close();