PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/ecm/index.php

https://bitbucket.org/speedealing/speedealing
PHP | 794 lines | 577 code | 117 blank | 100 comment | 122 complexity | fe067888e883b4cee118018f53a55a0d MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2008-2012 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");
  47. $section=GETPOST("section")?GETPOST("section","int"):GETPOST("section_id","int");
  48. $module=GETPOST("module");
  49. if (! $section) $section=0;
  50. $sortfield = GETPOST("sortfield",'alpha');
  51. $sortorder = GETPOST("sortorder",'alpha');
  52. $page = GETPOST("page",'int');
  53. if ($page == -1) { $page = 0; }
  54. $offset = $conf->liste_limit * $page;
  55. $pageprev = $page - 1;
  56. $pagenext = $page + 1;
  57. if (! $sortorder) $sortorder="ASC";
  58. if (! $sortfield) $sortfield="fullname";
  59. $ecmdir = new EcmDirectory($db);
  60. if ($section)
  61. {
  62. $result=$ecmdir->fetch($section);
  63. if (! $result > 0)
  64. {
  65. dol_print_error($db,$ecmdir->error);
  66. exit;
  67. }
  68. }
  69. $form=new Form($db);
  70. $ecmdirstatic = new EcmDirectory($db);
  71. $userstatic = new User($db);
  72. $error=0;
  73. /*
  74. * Actions
  75. */
  76. // Upload file
  77. if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
  78. {
  79. // Define relativepath and upload_dir
  80. $relativepath='';
  81. if ($ecmdir->id) $relativepath=$ecmdir->getRelativePath();
  82. else $relativepath=GETPOST('section_dir');
  83. $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
  84. if (empty($_FILES['userfile']['tmp_name']))
  85. {
  86. $error++;
  87. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("File")), 'errors');
  88. }
  89. if (! $error)
  90. {
  91. if (dol_mkdir($upload_dir) >= 0)
  92. {
  93. $resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0, 0, $_FILES['userfile']['error']);
  94. if (is_numeric($resupload) && $resupload > 0)
  95. {
  96. //$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
  97. //print_r($_FILES);
  98. $result=$ecmdir->changeNbOfFiles('+');
  99. }
  100. else
  101. {
  102. $langs->load("errors");
  103. if ($resupload < 0) // Unknown error
  104. {
  105. setEventMessage($langs->trans("ErrorFileNotUploaded"), 'errors');
  106. }
  107. else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
  108. {
  109. setEventMessage($langs->trans("ErrorFileIsInfectedWithAVirus"), 'errors');
  110. }
  111. else // Known error
  112. {
  113. setEventMessage($langs->trans($resupload), 'errors');
  114. }
  115. }
  116. }
  117. else
  118. {
  119. $langs->load("errors");
  120. $mesg = '<div class="error">'.$langs->trans("ErrorFailToCreateDir",$upload_dir).'</div>';
  121. }
  122. }
  123. }
  124. // Add directory
  125. if ($action == 'add' && $user->rights->ecm->setup)
  126. {
  127. $ecmdir->ref = 'NOTUSEDYET';
  128. $ecmdir->label = GETPOST("label");
  129. $ecmdir->description = GETPOST("desc");
  130. $id = $ecmdir->create($user);
  131. if ($id > 0)
  132. {
  133. header("Location: ".$_SERVER["PHP_SELF"]);
  134. exit;
  135. }
  136. else
  137. {
  138. $mesg='<div class="error">Error '.$langs->trans($ecmdir->error).'</div>';
  139. $action = "create";
  140. }
  141. clearstatcache();
  142. }
  143. // Remove file
  144. if ($action == 'confirm_deletefile')
  145. {
  146. if (GETPOST('confirm') == 'yes')
  147. {
  148. $langs->load("other");
  149. $result=$ecmdir->fetch($section);
  150. if (! $result > 0)
  151. {
  152. dol_print_error($db,$ecmdir->error);
  153. exit;
  154. }
  155. $relativepath=$ecmdir->getRelativePath();
  156. $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
  157. $file = $upload_dir . "/" . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  158. $ret=dol_delete_file($file);
  159. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  160. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  161. $result=$ecmdir->changeNbOfFiles('-');
  162. clearstatcache();
  163. }
  164. $action='file_manager';
  165. }
  166. // Remove directory
  167. if ($action == 'confirm_deletesection' && GETPOST('confirm') == 'yes')
  168. {
  169. $result=$ecmdir->delete($user);
  170. $mesg = '<div class="ok">'.$langs->trans("ECMSectionWasRemoved", $ecmdir->label).'</div>';
  171. clearstatcache();
  172. }
  173. // Refresh directory view
  174. if ($action == 'refreshmanual')
  175. {
  176. clearstatcache();
  177. $diroutputslash=str_replace('\\','/',$conf->ecm->dir_output);
  178. $diroutputslash.='/';
  179. // Scan directory tree on disk
  180. $disktree=dol_dir_list($conf->ecm->dir_output,'directories',1,'','^temp$','','',0);
  181. // Scan directory tree in database
  182. $sqltree=$ecmdirstatic->get_full_arbo(0);
  183. $adirwascreated=0;
  184. // Now we compare both trees to complete missing trees into database
  185. //var_dump($disktree);
  186. //var_dump($sqltree);
  187. foreach($disktree as $dirdesc) // Loop on tree onto disk
  188. {
  189. $dirisindatabase=0;
  190. foreach($sqltree as $dirsqldesc)
  191. {
  192. if ($conf->ecm->dir_output.'/'.$dirsqldesc['fullrelativename'] == $dirdesc['fullname'])
  193. {
  194. $dirisindatabase=1;
  195. break;
  196. }
  197. }
  198. if (! $dirisindatabase)
  199. {
  200. $txt="Directory found on disk ".$dirdesc['fullname'].", not found into database so we add it";
  201. dol_syslog($txt);
  202. //print $txt."<br>\n";
  203. // We must first find the fk_parent of directory to create $dirdesc['fullname']
  204. $fk_parent=-1;
  205. $relativepathmissing=str_replace($diroutputslash,'',$dirdesc['fullname']);
  206. $relativepathtosearchparent=$relativepathmissing;
  207. //dol_syslog("Try to find parent id for directory ".$relativepathtosearchparent);
  208. if (preg_match('/\//',$relativepathtosearchparent))
  209. //while (preg_match('/\//',$relativepathtosearchparent))
  210. {
  211. $relativepathtosearchparent=preg_replace('/\/[^\/]*$/','',$relativepathtosearchparent);
  212. $txt="Is relative parent path ".$relativepathtosearchparent." for ".$relativepathmissing." found in sql tree ?";
  213. dol_syslog($txt);
  214. //print $txt." -> ";
  215. $parentdirisindatabase=0;
  216. foreach($sqltree as $dirsqldesc)
  217. {
  218. if ($dirsqldesc['fullrelativename'] == $relativepathtosearchparent)
  219. {
  220. $parentdirisindatabase=$dirsqldesc['id'];
  221. break;
  222. }
  223. }
  224. if ($parentdirisindatabase > 0)
  225. {
  226. dol_syslog("Yes with id ".$parentdirisindatabase);
  227. //print "Yes with id ".$parentdirisindatabase."<br>\n";
  228. $fk_parent=$parentdirisindatabase;
  229. //break; // We found parent, we can stop the while loop
  230. }
  231. else
  232. {
  233. dol_syslog("No");
  234. //print "No<br>\n";
  235. }
  236. }
  237. else
  238. {
  239. dol_syslog("Parent is root");
  240. $fk_parent=0; // Parent is root
  241. }
  242. if ($fk_parent >= 0)
  243. {
  244. $ecmdirtmp=new EcmDirectory($db);
  245. $ecmdirtmp->ref = 'NOTUSEDYET';
  246. $ecmdirtmp->label = dol_basename($dirdesc['fullname']);
  247. $ecmdirtmp->description = '';
  248. $ecmdirtmp->fk_parent = $fk_parent;
  249. $txt="We create directory ".$ecmdirtmp->label." with parent ".$fk_parent;
  250. dol_syslog($txt);
  251. //print $ecmdirtmp->cachenbofdoc."<br>\n";exit;
  252. $id = $ecmdirtmp->create($user);
  253. if ($id > 0)
  254. {
  255. $newdirsql=array('id'=>$id,
  256. 'id_mere'=>$ecmdirtmp->fk_parent,
  257. 'label'=>$ecmdirtmp->label,
  258. 'description'=>$ecmdirtmp->description,
  259. 'fullrelativename'=>$relativepathmissing);
  260. $sqltree[]=$newdirsql; // We complete fulltree for following loops
  261. //var_dump($sqltree);
  262. $adirwascreated=1;
  263. }
  264. else
  265. {
  266. dol_syslog("Failed to create directory ".$ecmdirtmp->label, LOG_ERR);
  267. }
  268. }
  269. else {
  270. $txt="Parent of ".$dirdesc['fullname']." not found";
  271. dol_syslog($txt);
  272. //print $txt."<br>\n";
  273. }
  274. }
  275. }
  276. $sql="UPDATE ".MAIN_DB_PREFIX."ecm_directories set cachenbofdoc = -1 WHERE cachenbofdoc < 0"; // If pb into cahce counting, we set to value -1 = "unknown"
  277. dol_syslog("sql = ".$sql);
  278. $db->query($sql);
  279. // If a directory was added, the fulltree array is not correctly completed and sorted, so we clean
  280. // it to be sure that fulltree array is not used without reloading it.
  281. if ($adirwascreated) $sqltree=null;
  282. }
  283. /*
  284. * View
  285. */
  286. //print "xx".$_SESSION["dol_screenheight"];
  287. $maxheightwin=(isset($_SESSION["dol_screenheight"]) && $_SESSION["dol_screenheight"] > 500)?($_SESSION["dol_screenheight"]-166):660;
  288. $morejs=array();
  289. if (empty($conf->global->MAIN_ECM_DISABLE_JS)) $morejs=array("/includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js");
  290. $moreheadcss="
  291. <!-- dol_screenheight=".$_SESSION["dol_screenheight"]." -->
  292. <style type=\"text/css\">
  293. #containerlayout {
  294. height: ".$maxheightwin."px;
  295. margin: 0 auto;
  296. width: 100%;
  297. min-width: 700px;
  298. _width: 700px; /* min-width for IE6 */
  299. }
  300. </style>";
  301. $moreheadjs=empty($conf->use_javascript_ajax)?"":"
  302. <script type=\"text/javascript\">
  303. jQuery(document).ready(function () {
  304. jQuery('#containerlayout').layout({
  305. name: \"ecmlayout\"
  306. , paneClass: \"ecm-layout-pane\"
  307. , resizerClass: \"ecm-layout-resizer\"
  308. , togglerClass: \"ecm-layout-toggler\"
  309. , center__paneSelector: \"#ecm-layout-center\"
  310. , north__paneSelector: \"#ecm-layout-north\"
  311. , west__paneSelector: \"#ecm-layout-west\"
  312. , resizable: true
  313. , north__size: 32
  314. , north__resizable: false
  315. , north__closable: false
  316. , west__size: 340
  317. , west__minSize: 280
  318. , west__slidable: true
  319. , west__resizable: true
  320. , west__togglerLength_closed: '100%'
  321. , useStateCookie: true
  322. });
  323. jQuery('#ecm-layout-center').layout({
  324. center__paneSelector: \".ecm-in-layout-center\"
  325. , south__paneSelector: \".ecm-in-layout-south\"
  326. , resizable: false
  327. , south__minSize: 32
  328. , south__resizable: false
  329. , south__closable: false
  330. });
  331. });
  332. </script>";
  333. llxHeader($moreheadcss.$moreheadjs,$langs->trans("ECMArea"),'','','','',$morejs,'',0,0);
  334. // Add sections to manage
  335. $rowspan=0;
  336. $sectionauto=array();
  337. if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'product', 'test'=>(! empty($conf->product->enabled) || ! empty($conf->service->enabled)), 'label'=>$langs->trans("ProductsAndServices"), 'desc'=>$langs->trans("ECMDocsByProducts")); }
  338. if (! empty($conf->societe->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'company', 'test'=>$conf->societe->enabled, 'label'=>$langs->trans("ThirdParties"), 'desc'=>$langs->trans("ECMDocsByThirdParties")); }
  339. if (! empty($conf->propal->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'propal', 'test'=>$conf->propal->enabled, 'label'=>$langs->trans("Prop"), 'desc'=>$langs->trans("ECMDocsByProposals")); }
  340. if (! empty($conf->contrat->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'contract','test'=>$conf->contrat->enabled, 'label'=>$langs->trans("Contracts"), 'desc'=>$langs->trans("ECMDocsByContracts")); }
  341. if (! empty($conf->commande->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'order', 'test'=>$conf->commande->enabled,'label'=>$langs->trans("CustomersOrders"), 'desc'=>$langs->trans("ECMDocsByOrders")); }
  342. if (! empty($conf->facture->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'invoice', 'test'=>$conf->facture->enabled, 'label'=>$langs->trans("CustomersInvoices"), 'desc'=>$langs->trans("ECMDocsByInvoices")); }
  343. 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")); }
  344. 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")); }
  345. if (! empty($conf->tax->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'tax', 'test'=>$conf->tax->enabled, 'label'=>$langs->trans("SocialContributions"), 'desc'=>$langs->trans("ECMDocsBySocialContributions")); }
  346. print_fiche_titre($langs->trans("ECMArea").' - '.$langs->trans("ECMFileManager"));
  347. print $langs->trans("ECMAreaDesc")."<br>";
  348. print $langs->trans("ECMAreaDesc2")."<br>";
  349. print "<br>\n";
  350. // Confirm remove file
  351. if ($action == 'delete' && empty($conf->use_javascript_ajax))
  352. {
  353. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$section.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1);
  354. if ($ret == 'html') print '<br>';
  355. }
  356. dol_htmloutput_mesg($mesg);
  357. if (! empty($conf->use_javascript_ajax)) $classviewhide='hidden';
  358. else $classviewhide='visible';
  359. // Start container of all panels
  360. ?>
  361. <div id="containerlayout"> <!-- begin div id="containerlayout" -->
  362. <div id="ecm-layout-north" class="toolbar">
  363. <?php
  364. // Start top panel, toolbar
  365. print '<div class="toolbarbutton">';
  366. // Toolbar
  367. if ($user->rights->ecm->setup)
  368. {
  369. print '<a href="'.DOL_URL_ROOT.'/ecm/docdir.php?action=create" class="toolbarbutton" title="'.dol_escape_htmltag($langs->trans('ECMAddSection')).'">';
  370. print '<img class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
  371. print '</a>';
  372. }
  373. else
  374. {
  375. print '<a href="#" class="toolbarbutton" title="'.$langs->trans("NotAllowed").'">';
  376. print '<img class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
  377. print '</a>';
  378. }
  379. $url=((! 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:'')));
  380. print '<a href="'.$url.'" class="toolbarbutton" title="'.dol_escape_htmltag($langs->trans('Refresh')).'">';
  381. print '<img id="refreshbutton" class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/view-refresh.png">';
  382. print '</a>';
  383. print '</div>';
  384. // End top panel, toolbar
  385. ?>
  386. </div>
  387. <div id="ecm-layout-west" class="<?php echo $classviewhide; ?>">
  388. <?php
  389. // Start left area
  390. // Confirmation de la suppression d'une ligne categorie
  391. if ($action == 'delete_section')
  392. {
  393. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$section, $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection','','',1);
  394. if ($ret == 'html') print '<br>';
  395. }
  396. // End confirm
  397. if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$action) || $action == 'delete')
  398. {
  399. print '<table width="100%" class="nobordernopadding">';
  400. print '<tr class="liste_titre">';
  401. print '<td class="liste_titre" align="left" colspan="6">';
  402. print '&nbsp;'.$langs->trans("ECMSections");
  403. print '</td></tr>';
  404. $showonrightsize='';
  405. // Auto section
  406. if (count($sectionauto))
  407. {
  408. $htmltooltip=$langs->trans("ECMAreaDesc2");
  409. // Root title line (Automatic section)
  410. print '<tr>';
  411. print '<td>';
  412. print '<table class="nobordernopadding"><tr class="nobordernopadding">';
  413. print '<td align="left" width="24">';
  414. print img_picto_common('','treemenu/base.gif');
  415. print '</td><td align="left">';
  416. $txt=$langs->trans("ECMRoot").' ('.$langs->trans("ECMSectionsAuto").')';
  417. print $form->textwithpicto($txt, $htmltooltip, 1, 0);
  418. print '</td>';
  419. print '</tr></table>';
  420. print '</td>';
  421. print '<td align="right">&nbsp;</td>';
  422. print '<td align="right">&nbsp;</td>';
  423. print '<td align="right">&nbsp;</td>';
  424. print '<td align="right">&nbsp;</td>';
  425. print '<td align="center">';
  426. print '</td>';
  427. print '</tr>';
  428. $sectionauto=dol_sort_array($sectionauto,'label','ASC',true,false);
  429. print '<tr>';
  430. print '<td colspan="6" style="padding-left: 20px">';
  431. print '<div id="filetreeauto" class="ecmfiletree"><ul class="ecmjqft">';
  432. $nbofentries=0;
  433. $oldvallevel=0;
  434. foreach ($sectionauto as $key => $val)
  435. {
  436. if (empty($val['test'])) continue; // If condition to show is ok
  437. $var=false;
  438. print '<li class="directory collapsed">';
  439. if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))
  440. {
  441. print '<a class="fmdirlia jqft ecmjqft" href="'.DOL_URL_ROOT.'/ecm/index.php?module='.$val['module'].'">';
  442. print $val['label'];
  443. print '</a>';
  444. }
  445. else
  446. {
  447. print '<a class="fmdirlia jqft ecmjqft" href="'.DOL_URL_ROOT.'/ecm/index.php?module='.$val['module'].'">';
  448. print $val['label'];
  449. print '</a>';
  450. }
  451. print '<div class="ecmjqft">';
  452. // Info
  453. $htmltooltip='<b>'.$langs->trans("ECMSection").'</b>: '.$val['label'].'<br>';
  454. $htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMSectionAuto").'<br>';
  455. $htmltooltip.='<b>'.$langs->trans("ECMCreationUser").'</b>: '.$langs->trans("ECMTypeAuto").'<br>';
  456. $htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['desc'];
  457. print $form->textwithpicto('', $htmltooltip, 1, 'info');
  458. print '</div>';
  459. print '</li>';
  460. $nbofentries++;
  461. }
  462. print '</ul></div></td></tr>';
  463. }
  464. // Manual section
  465. $htmltooltip=$langs->trans("ECMAreaDesc2");
  466. // Root of manual section
  467. print '<tr><td>';
  468. print '<table class="nobordernopadding"><tr class="nobordernopadding">';
  469. print '<td align="left" width="24px">';
  470. print img_picto_common('','treemenu/base.gif');
  471. print '</td><td align="left">';
  472. $txt=$langs->trans("ECMRoot").' ('.$langs->trans("ECMSectionsManual").')';
  473. print $form->textwithpicto($txt, $htmltooltip, 1, 'info');
  474. print '</td>';
  475. print '</tr></table></td>';
  476. print '<td align="right">';
  477. print '</td>';
  478. print '<td align="right">&nbsp;</td>';
  479. //print '<td align="right"><a href="'.DOL_URL_ROOT.'/ecm/docdir.php?action=create">'.img_edit_add().'</a></td>';
  480. print '<td align="right">&nbsp;</td>';
  481. print '<td align="right">&nbsp;</td>';
  482. print '<td align="center">';
  483. //print $form->textwithpicto('',$htmltooltip,1,"info");
  484. print '</td>';
  485. print '</tr>';
  486. if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))
  487. {
  488. print '<tr><td colspan="6" style="padding-left: 20px">';
  489. // Show filemanager tree
  490. print '<div id="filetree" class="ecmfiletree"></div>';
  491. if ($action == 'deletefile') print $form->formconfirm('eeeee', $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', '', 'deletefile');
  492. print '</td></tr>';
  493. }
  494. else
  495. {
  496. print '<tr><td colspan="6" style="padding-left: 20px">';
  497. print '<div id="filetree" class="ecmfiletree">';
  498. print '<ul class="ecmjqft">';
  499. // Load full tree
  500. if (empty($sqltree)) $sqltree=$ecmdirstatic->get_full_arbo(0); // Slow
  501. // ----- This section will show a tree from a fulltree array -----
  502. // $section must also be defined
  503. // ----------------------------------------------------------------
  504. // Define fullpathselected ( _x_y_z ) of $section parameter
  505. $fullpathselected='';
  506. foreach($sqltree as $key => $val)
  507. {
  508. //print $val['id']."-".$section."<br>";
  509. if ($val['id'] == $section)
  510. {
  511. $fullpathselected=$val['fullpath'];
  512. break;
  513. }
  514. }
  515. //print "fullpathselected=".$fullpathselected."<br>";
  516. // Update expandedsectionarray in session
  517. $expandedsectionarray=array();
  518. if (isset($_SESSION['dol_ecmexpandedsectionarray'])) $expandedsectionarray=explode(',',$_SESSION['dol_ecmexpandedsectionarray']);
  519. if ($section && GETPOST('sectionexpand') == 'true')
  520. {
  521. // We add all sections that are parent of opened section
  522. $pathtosection=explode('_',$fullpathselected);
  523. foreach($pathtosection as $idcursor)
  524. {
  525. if ($idcursor && ! in_array($idcursor,$expandedsectionarray)) // Not already in array
  526. {
  527. $expandedsectionarray[]=$idcursor;
  528. }
  529. }
  530. $_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray);
  531. }
  532. if ($section && GETPOST('sectionexpand') == 'false')
  533. {
  534. // We removed all expanded sections that are child of the closed section
  535. $oldexpandedsectionarray=$expandedsectionarray;
  536. $expandedsectionarray=array(); // Reset
  537. foreach($oldexpandedsectionarray as $sectioncursor)
  538. {
  539. // is_in_subtree(fulltree,sectionparent,sectionchild)
  540. if ($sectioncursor && ! is_in_subtree($sqltree,$section,$sectioncursor)) $expandedsectionarray[]=$sectioncursor;
  541. }
  542. $_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray);
  543. }
  544. //print $_SESSION['dol_ecmexpandedsectionarray'].'<br>';
  545. $nbofentries=0;
  546. $oldvallevel=0;
  547. $var=true;
  548. foreach($sqltree as $key => $val)
  549. {
  550. $var=false;
  551. $ecmdirstatic->id=$val['id'];
  552. $ecmdirstatic->ref=$val['label'];
  553. // Refresh cache
  554. if (preg_match('/refresh/i',$action))
  555. {
  556. $result=$ecmdirstatic->fetch($val['id']);
  557. $ecmdirstatic->ref=$ecmdirstatic->label;
  558. $result=$ecmdirstatic->refreshcachenboffile(0);
  559. $val['cachenbofdoc']=$result;
  560. }
  561. //$fullpathparent=preg_replace('/(_[^_]+)$/i','',$val['fullpath']);
  562. // Define showline
  563. $showline=0;
  564. // If directory is son of expanded directory, we show line
  565. if (in_array($val['id_mere'],$expandedsectionarray)) $showline=4;
  566. // If directory is brother of selected directory, we show line
  567. elseif ($val['id'] != $section && $val['id_mere'] == $ecmdirstatic->motherof[$section]) $showline=3;
  568. // If directory is parent of selected directory or is selected directory, we show line
  569. elseif (preg_match('/'.$val['fullpath'].'_/i',$fullpathselected.'_')) $showline=2;
  570. // If we are level one we show line
  571. elseif ($val['level'] < 2) $showline=1;
  572. if ($showline)
  573. {
  574. if (in_array($val['id'],$expandedsectionarray)) $option='indexexpanded';
  575. else $option='indexnotexpanded';
  576. //print $option;
  577. print '<li class="directory collapsed">';
  578. // Show tree graph pictos
  579. $cpt=1;
  580. while ($cpt < $sqltree[$key]['level'])
  581. {
  582. print ' &nbsp; &nbsp;';
  583. $cpt++;
  584. }
  585. $resarray=tree_showpad($sqltree,$key,1);
  586. $a=$resarray[0];
  587. $nbofsubdir=$resarray[1];
  588. $nboffilesinsubdir=$resarray[2];
  589. // Show link
  590. print $ecmdirstatic->getNomUrl(0,$option,32,'class="fmdirlia jqft ecmjqft"');
  591. print '<div class="ecmjqft">';
  592. // Nb of docs
  593. print '<table class="nobordernopadding"><tr><td>';
  594. print $val['cachenbofdoc'];
  595. print '</td>';
  596. print '<td align="left">';
  597. if ($nbofsubdir && $nboffilesinsubdir) print '<font color="#AAAAAA">+'.$nboffilesinsubdir.'</font> ';
  598. print '</td>';
  599. // Info
  600. print '<td align="center">';
  601. $userstatic->id=$val['fk_user_c'];
  602. $userstatic->lastname=$val['login_c'];
  603. $htmltooltip='<b>'.$langs->trans("ECMSection").'</b>: '.$val['label'].'<br>';
  604. $htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMSectionManual").'<br>';
  605. $htmltooltip.='<b>'.$langs->trans("ECMCreationUser").'</b>: '.$userstatic->getNomUrl(1).'<br>';
  606. $htmltooltip.='<b>'.$langs->trans("ECMCreationDate").'</b>: '.dol_print_date($val['date_c'],"dayhour").'<br>';
  607. $htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['description'].'<br>';
  608. $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInDir").'</b>: '.$val['cachenbofdoc'].'<br>';
  609. if ($nbofsubdir) $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInSubDir").'</b>: '.$nboffilesinsubdir;
  610. else $htmltooltip.='<b>'.$langs->trans("ECMNbOfSubDir").'</b>: '.$nbofsubdir.'<br>';
  611. print $form->textwithpicto('', $htmltooltip, 1, 'info');
  612. print "</td>";
  613. print '</tr></table>';
  614. print '</div>';
  615. print "</li>\n";
  616. }
  617. $oldvallevel=$val['level'];
  618. $nbofentries++;
  619. }
  620. // If nothing to show
  621. if ($nbofentries == 0)
  622. {
  623. print '<li class="directory collapsed">';
  624. print '<div class="ecmjqft">';
  625. print $langs->trans("ECMNoDirectoryYet");
  626. print '</div>';
  627. print "</li>\n";
  628. }
  629. print '</ul>';
  630. print '</div>';
  631. print '</td></tr>';
  632. }
  633. print "</table>";
  634. }
  635. // End left banner
  636. ?>
  637. </div>
  638. <div id="ecm-layout-center" class="<?php echo $classviewhide; ?>">
  639. <div class="pane-in ecm-in-layout-center">
  640. <div id="ecmfileview" class="ecmfileview">
  641. <?php
  642. // Start right panel
  643. $mode='noajax';
  644. include_once DOL_DOCUMENT_ROOT.'/core/ajax/ajaxdirpreview.php';
  645. // End right panel
  646. ?>
  647. </div>
  648. </div>
  649. <div class="pane-in ecm-in-layout-south layout-padding valignmiddle">
  650. <?php
  651. // Start Add new file area
  652. // To attach new file
  653. if ((! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) || ! empty($section))
  654. {
  655. $formfile=new FormFile($db);
  656. $formfile->form_attach_new_file(DOL_URL_ROOT.'/ecm/index.php', 'none', 0, ($section?$section:-1), $user->rights->ecm->upload, 48);
  657. }
  658. else print '&nbsp;';
  659. // End Add new file area
  660. ?>
  661. </div>
  662. </div>
  663. </div> <!-- end div id="containerlayout" -->
  664. <?php
  665. // End of page
  666. if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) {
  667. include 'tpl/builddatabase.tpl.php';
  668. }
  669. llxFooter();
  670. $db->close();
  671. ?>