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

/htdocs/ecm/index.php

https://github.com/asterix14/dolibarr
PHP | 894 lines | 635 code | 135 blank | 124 comment | 129 complexity | eb3e31e43eb8a822c3af7fe6a3c83435 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2008-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2008-2010 Regis Houssin <regis@dolibarr.fr>
  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 2 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. require("../main.inc.php");
  26. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  27. require_once(DOL_DOCUMENT_ROOT."/core/lib/ecm.lib.php");
  28. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  29. require_once(DOL_DOCUMENT_ROOT."/core/lib/treeview.lib.php");
  30. require_once(DOL_DOCUMENT_ROOT."/ecm/class/ecmdirectory.class.php");
  31. // Load traductions files
  32. $langs->load("ecm");
  33. $langs->load("companies");
  34. $langs->load("other");
  35. $langs->load("users");
  36. $langs->load("orders");
  37. $langs->load("propal");
  38. $langs->load("bills");
  39. $langs->load("contracts");
  40. // Security check
  41. if ($user->societe_id) $socid=$user->societe_id;
  42. $result = restrictedArea($user, 'ecm', 0);
  43. // Load permissions
  44. $user->getrights('ecm');
  45. // Get parameters
  46. $socid=GETPOST('socid');
  47. $action=GETPOST("action");
  48. $section=GETPOST("section");
  49. $module=GETPOST("module");
  50. if (! $section) $section=0;
  51. $upload_dir = $conf->ecm->dir_output.'/'.$section;
  52. $sortfield = GETPOST("sortfield",'alpha');
  53. $sortorder = GETPOST("sortorder",'alpha');
  54. $page = GETPOST("page",'int');
  55. if ($page == -1) { $page = 0; }
  56. $offset = $conf->liste_limit * $page;
  57. $pageprev = $page - 1;
  58. $pagenext = $page + 1;
  59. if (! $sortorder) $sortorder="ASC";
  60. if (! $sortfield) $sortfield="label";
  61. $ecmdir = new ECMDirectory($db);
  62. if (GETPOST("section"))
  63. {
  64. $result=$ecmdir->fetch(GETPOST("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. /*******************************************************************
  75. * ACTIONS
  76. *
  77. * Put here all code to do according to value of "action" parameter
  78. ********************************************************************/
  79. // Upload file
  80. if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
  81. {
  82. $relativepath=$ecmdir->getRelativePath();
  83. $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
  84. if (create_exdir($upload_dir) >= 0)
  85. {
  86. $resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0, 0, $_FILES['userfile']['error']);
  87. if (is_numeric($resupload) && $resupload > 0)
  88. {
  89. //$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
  90. //print_r($_FILES);
  91. $result=$ecmdir->changeNbOfFiles('+');
  92. }
  93. else
  94. {
  95. $langs->load("errors");
  96. if ($resupload < 0) // Unknown error
  97. {
  98. $mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
  99. }
  100. else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
  101. {
  102. $mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
  103. }
  104. else // Known error
  105. {
  106. $mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
  107. }
  108. }
  109. }
  110. else
  111. {
  112. $langs->load("errors");
  113. $mesg = '<div class="error">'.$langs->trans("ErrorFailToCreateDir",$upload_dir).'</div>';
  114. }
  115. }
  116. // Add directory
  117. if (GETPOST("action") == 'add' && $user->rights->ecm->setup)
  118. {
  119. $ecmdir->ref = 'NOTUSEDYET';
  120. $ecmdir->label = GETPOST("label");
  121. $ecmdir->description = GETPOST("desc");
  122. $id = $ecmdir->create($user);
  123. if ($id > 0)
  124. {
  125. Header("Location: ".$_SERVER["PHP_SELF"]);
  126. exit;
  127. }
  128. else
  129. {
  130. $mesg='<div class="error">Error '.$langs->trans($ecmdir->error).'</div>';
  131. $_GET["action"] = "create";
  132. }
  133. }
  134. // Remove file
  135. if (GETPOST('action') == 'confirm_deletefile' && GETPOST('confirm') == 'yes')
  136. {
  137. $result=$ecmdir->fetch(GETPOST("section"));
  138. if (! $result > 0)
  139. {
  140. dol_print_error($db,$ecmdir->error);
  141. exit;
  142. }
  143. $relativepath=$ecmdir->getRelativePath();
  144. $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
  145. $file = $upload_dir . "/" . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  146. $result=dol_delete_file($file);
  147. $mesg = '<div class="ok">'.$langs->trans("FileWasRemoved").'</div>';
  148. $result=$ecmdir->changeNbOfFiles('-');
  149. $action='file_manager';
  150. }
  151. // Remove directory
  152. if (GETPOST('action') == 'confirm_deletesection' && GETPOST('confirm') == 'yes')
  153. {
  154. $result=$ecmdir->delete($user);
  155. $mesg = '<div class="ok">'.$langs->trans("ECMSectionWasRemoved", $ecmdir->label).'</div>';
  156. }
  157. // Refresh directory view
  158. if (GETPOST("action") == 'refreshmanual')
  159. {
  160. $diroutputslash=str_replace('\\','/',$conf->ecm->dir_output);
  161. $diroutputslash.='/';
  162. // Scan directory tree on disk
  163. $disktree=dol_dir_list($conf->ecm->dir_output,'directories',1,'','','','',0);
  164. // Scan directory tree in database
  165. $sqltree=$ecmdirstatic->get_full_arbo(0);
  166. $adirwascreated=0;
  167. // Now we compare both trees to complete missing trees into database
  168. //var_dump($disktree);
  169. //var_dump($sqltree);
  170. foreach($disktree as $dirdesc)
  171. {
  172. $dirisindatabase=0;
  173. foreach($sqltree as $dirsqldesc)
  174. {
  175. if ($conf->ecm->dir_output.'/'.$dirsqldesc['fullrelativename'] == $dirdesc['fullname'])
  176. {
  177. $dirisindatabase=1;
  178. break;
  179. }
  180. }
  181. if (! $dirisindatabase)
  182. {
  183. $txt="Directory found on disk ".$dirdesc['fullname'].", not found into database so we add it";
  184. dol_syslog($txt);
  185. //print $txt."<br>\n";
  186. // We must first find the fk_parent of directory to create $dirdesc['fullname']
  187. $fk_parent=-1;
  188. $relativepathmissing=str_replace($diroutputslash,'',$dirdesc['fullname']);
  189. $relativepathtosearchparent=$relativepathmissing;
  190. //dol_syslog("Try to find parent id for directory ".$relativepathtosearchparent);
  191. if (preg_match('/\//',$relativepathtosearchparent))
  192. //while (preg_match('/\//',$relativepathtosearchparent))
  193. {
  194. $relativepathtosearchparent=preg_replace('/\/[^\/]*$/','',$relativepathtosearchparent);
  195. $txt="Is relative parent path ".$relativepathtosearchparent." for ".$relativepathmissing." found in sql tree ?";
  196. dol_syslog($txt);
  197. //print $txt." -> ";
  198. $parentdirisindatabase=0;
  199. foreach($sqltree as $dirsqldesc)
  200. {
  201. if ($dirsqldesc['fullrelativename'] == $relativepathtosearchparent)
  202. {
  203. $parentdirisindatabase=$dirsqldesc['id'];
  204. break;
  205. }
  206. }
  207. if ($parentdirisindatabase > 0)
  208. {
  209. dol_syslog("Yes with id ".$parentdirisindatabase);
  210. //print "Yes with id ".$parentdirisindatabase."<br>\n";
  211. $fk_parent=$parentdirisindatabase;
  212. //break; // We found parent, we can stop the while loop
  213. }
  214. else
  215. {
  216. dol_syslog("No");
  217. //print "No<br>\n";
  218. }
  219. }
  220. else
  221. {
  222. $fk_parent=0; // Parent is root
  223. }
  224. if ($fk_parent >= 0)
  225. {
  226. $ecmdirtmp=new ECMDirectory($db);
  227. $ecmdirtmp->ref = 'NOTUSEDYET';
  228. $ecmdirtmp->label = basename($dirdesc['fullname']);
  229. $ecmdirtmp->description = '';
  230. $ecmdirtmp->fk_parent = $fk_parent;
  231. $txt="We create directory ".$ecmdirtmp->label." with parent ".$fk_parent;
  232. dol_syslog($txt);
  233. //print $txt."<br>\n";
  234. $id = $ecmdirtmp->create($user);
  235. if ($id > 0)
  236. {
  237. $newdirsql=array('id'=>$id,
  238. 'id_mere'=>$ecmdirtmp->fk_parent,
  239. 'label'=>$ecmdirtmp->label,
  240. 'description'=>$ecmdirtmp->description,
  241. 'fullrelativename'=>$relativepathmissing);
  242. $sqltree[]=$newdirsql; // We complete fulltree for following loops
  243. //var_dump($sqltree);
  244. $adirwascreated=1;
  245. }
  246. }
  247. else {
  248. $txt="Parent of ".$dirdesc['fullname']." not found";
  249. dol_syslog($txt);
  250. //print $txt."<br>\n";
  251. }
  252. }
  253. }
  254. // If a directory was added, the fulltree array is not correctly completed and sorted, so we clean
  255. // it to be sure that fulltree array is not used without reloading it.
  256. if ($adirwascreated) $sqltree=null;
  257. }
  258. /*******************************************************************
  259. * View
  260. ********************************************************************/
  261. //print "xx".$_SESSION["dol_screenheight"];
  262. $maxheightwin=(isset($_SESSION["dol_screenheight"]) && $_SESSION["dol_screenheight"] > 500)?($_SESSION["dol_screenheight"]-166):660;
  263. $morecss="
  264. <!-- dol_screenheight=".$_SESSION["dol_screenheight"]." -->
  265. <style type=\"text/css\">
  266. #containerlayout {
  267. height: ".$maxheightwin."px;
  268. margin: 0 auto;
  269. width: 100%;
  270. min-width: 700px;
  271. _width: 700px; /* min-width for IE6 */
  272. }
  273. </style>";
  274. $morejs="
  275. <script type=\"text/javascript\">
  276. jQuery(document).ready(function () {
  277. jQuery('#containerlayout').layout({
  278. name: \"ecmlayout\"
  279. , paneClass: \"ecm-layout-pane\"
  280. , resizerClass: \"ecm-layout-resizer\"
  281. , togglerClass: \"ecm-layout-toggler\"
  282. , center__paneSelector: \"#ecm-layout-center\"
  283. , north__paneSelector: \"#ecm-layout-north\"
  284. , west__paneSelector: \"#ecm-layout-west\"
  285. , resizable: true
  286. , north__size: 34
  287. , north__resizable: false
  288. , north__closable: false
  289. , west__size: 340
  290. , west__minSize: 280
  291. , west__slidable: true
  292. , west__resizable: true
  293. , west__togglerLength_closed: '100%'
  294. , useStateCookie: true
  295. });
  296. jQuery('#ecm-layout-center').layout({
  297. center__paneSelector: \".ecm-in-layout-center\"
  298. , south__paneSelector: \".ecm-in-layout-south\"
  299. , resizable: false
  300. , south__minSize: 32
  301. , south__resizable: false
  302. , south__closable: false
  303. });
  304. });
  305. </script>";
  306. llxHeader($morecss.$morejs,$langs->trans("ECM"),'','','','','','',0,0);
  307. // Ajout rubriques automatiques
  308. $rowspan=0;
  309. $sectionauto=array();
  310. if ($conf->product->enabled || $conf->service->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'product', 'test'=>$conf->product->enabled, 'label'=>$langs->trans("ProductsAndServices"), 'desc'=>$langs->trans("ECMDocsByProducts")); }
  311. if ($conf->societe->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'company', 'test'=>$conf->societe->enabled, 'label'=>$langs->trans("ThirdParties"), 'desc'=>$langs->trans("ECMDocsByThirdParties")); }
  312. if ($conf->propal->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'propal', 'test'=>$conf->propal->enabled, 'label'=>$langs->trans("Prop"), 'desc'=>$langs->trans("ECMDocsByProposals")); }
  313. if ($conf->contrat->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'contract','test'=>$conf->contrat->enabled, 'label'=>$langs->trans("Contracts"), 'desc'=>$langs->trans("ECMDocsByContracts")); }
  314. if ($conf->commande->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'order', 'test'=>$conf->commande->enabled,'label'=>$langs->trans("CustomersOrders"), 'desc'=>$langs->trans("ECMDocsByOrders")); }
  315. if ($conf->fournisseur->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'order_supplier', 'test'=>$conf->fournisseur->enabled, 'label'=>$langs->trans("SuppliersOrders"), 'desc'=>$langs->trans("ECMDocsByOrders")); }
  316. if ($conf->facture->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'invoice', 'test'=>$conf->facture->enabled, 'label'=>$langs->trans("CustomersInvoices"), 'desc'=>$langs->trans("ECMDocsByInvoices")); }
  317. if ($conf->fournisseur->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'invoice_supplier', 'test'=>$conf->fournisseur->enabled, 'label'=>$langs->trans("SuppliersInvoices"), 'desc'=>$langs->trans("ECMDocsByInvoices")); }
  318. //***********************
  319. // List
  320. //***********************
  321. print_fiche_titre($langs->trans("ECMArea").' - '.$langs->trans("ECMFileManager"));
  322. print $langs->trans("ECMAreaDesc")."<br>";
  323. print $langs->trans("ECMAreaDesc2")."<br>";
  324. print "<br>\n";
  325. // Confirm remove file
  326. if (GETPOST('action') == 'delete')
  327. {
  328. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$_REQUEST["section"].'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1);
  329. if ($ret == 'html') print '<br>';
  330. }
  331. dol_htmloutput_mesg($mesg);
  332. // Toolbar
  333. //$head = ecm_prepare_head_fm($fac);
  334. //dol_fiche_head($head, 'file_manager', '', 1);
  335. //$conf->use_javascript_ajax=0;
  336. if ($conf->use_javascript_ajax)
  337. {
  338. ?>
  339. <div id="containerlayout"> <!-- begin div id="containerlayout" -->
  340. <div id="ecm-layout-north" class="toolbar">
  341. <?php
  342. }
  343. else
  344. {
  345. print '<table class="border" width="100%">';
  346. // Toolbar
  347. print '<tr><td colspan="2" style="background: #FFFFFF" style="height: 24px !important">';
  348. }
  349. // Show button to create a directory
  350. //if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$action))
  351. //{
  352. if ($user->rights->ecm->setup)
  353. {
  354. print '<a href="'.DOL_URL_ROOT.'/ecm/docdir.php?action=create" title="'.dol_escape_htmltag($langs->trans('ECMAddSection')).'">';
  355. //print $langs->trans('ECMAddSection');
  356. print '<img width="32" height="32" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
  357. print '</a>';
  358. }
  359. else
  360. {
  361. print '<a href="#" title="'.$langs->trans("NotAllowed").'">';
  362. //print $langs->trans('ECMAddSection');
  363. print '<img width="32" height="32" border="0" src="'.DOL_URL_ROOT.'/theme/common/folder-new.png">';
  364. print '</a>';
  365. }
  366. //}
  367. // Show button to refresh listing
  368. print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual'.($module?'&amp;module='.$module:'').($section?'&amp;section='.$section:'').'" title="'.dol_escape_htmltag($langs->trans('Refresh')).'">';
  369. print '<img width="32" height="32" border="0" src="'.DOL_URL_ROOT.'/theme/common/view-refresh.png">';
  370. print '</a>';
  371. if ($conf->use_javascript_ajax)
  372. {
  373. ?>
  374. </div>
  375. <div id="ecm-layout-west" class="hidden">
  376. <?php
  377. }
  378. else
  379. {
  380. print '</td></tr>';
  381. print '<tr>';
  382. print '<td width="40%" valign="top" style="background: #FFFFFF" rowspan="2">';
  383. }
  384. // Left area
  385. if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$action) || $action == 'delete')
  386. {
  387. $userstatic = new User($db);
  388. $ecmdirstatic = new ECMDirectory($db);
  389. // Confirmation de la suppression d'une ligne categorie
  390. if ($_GET['action'] == 'delete_section')
  391. {
  392. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.urlencode($_GET["section"]), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection','','',1);
  393. if ($ret == 'html') print '<br>';
  394. }
  395. print '<table width="100%" class="nobordernopadding">';
  396. print '<tr class="liste_titre">';
  397. print '<td class="liste_titre" align="left" colspan="6">';
  398. print '&nbsp;'.$langs->trans("ECMSections");
  399. print '</td></tr>';
  400. $showonrightsize='';
  401. if (count($sectionauto))
  402. {
  403. // Root title line (Automatic section)
  404. print '<tr>';
  405. print '<td>';
  406. print '<table class="nobordernopadding"><tr class="nobordernopadding">';
  407. print '<td align="left" width="24">';
  408. print img_picto_common('','treemenu/base.gif');
  409. print '</td><td align="left">'.$langs->trans("ECMRoot").' ('.$langs->trans("ECMSectionsAuto").')';
  410. print '</td>';
  411. print '</tr></table>';
  412. print '</td>';
  413. print '<td align="right">&nbsp;</td>';
  414. print '<td align="right">&nbsp;</td>';
  415. print '<td align="right">&nbsp;</td>';
  416. print '<td align="right">&nbsp;</td>';
  417. print '<td align="center">';
  418. $htmltooltip=$langs->trans("ECMAreaDesc2");
  419. print $form->textwithpicto('',$htmltooltip,1,0);
  420. print '</td>';
  421. //print '<td align="right">'.$langs->trans("ECMNbOfDocsSmall").' <a href="'.$_SERVER["PHP_SELF"].'?action=refreshauto">'.img_picto($langs->trans("Refresh"),'refresh').'</a></td>';
  422. print '</tr>';
  423. $sectionauto=dol_sort_array($sectionauto,'label','ASC',true,false);
  424. $nbofentries=0;
  425. $oldvallevel=0;
  426. foreach ($sectionauto as $key => $val)
  427. {
  428. if ($val['test'])
  429. {
  430. $var=false;
  431. print '<tr>';
  432. // Section
  433. print '<td align="left">';
  434. print '<table class="nobordernopadding"><tr class="nobordernopadding"><td>';
  435. tree_showpad($sectionauto,$key);
  436. print '</td>';
  437. print '<td valign="top">';
  438. if ($val['module'] == $_REQUEST["module"])
  439. {
  440. $n=3;
  441. $ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/minustop'.$n.'.gif','',1);
  442. }
  443. else
  444. {
  445. $n=3;
  446. $ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/plustop'.$n.'.gif','',1);
  447. }
  448. print '<a href="'.DOL_URL_ROOT.'/ecm/index.php?module='.$val['module'].'">';
  449. print $ref;
  450. print '</a>';
  451. print img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/folder.gif','',1);
  452. print '</td>';
  453. print '<td valign="middle">';
  454. print '<a href="'.DOL_URL_ROOT.'/ecm/index.php?module='.$val['module'].'">';
  455. print $val['label'];
  456. print '</a></td></tr></table>';
  457. print "</td>\n";
  458. // Nb of doc in dir
  459. print '<td align="right">&nbsp;</td>';
  460. // Nb of doc in subdir
  461. print '<td align="right">&nbsp;</td>';
  462. // Edit link
  463. print '<td align="right">&nbsp;</td>';
  464. // Add link
  465. print '<td align="right">&nbsp;</td>';
  466. // Info
  467. print '<td align="center">';
  468. $htmltooltip='<b>'.$langs->trans("ECMSection").'</b>: '.$val['label'].'<br>';
  469. $htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMSectionAuto").'<br>';
  470. $htmltooltip.='<b>'.$langs->trans("ECMCreationUser").'</b>: '.$langs->trans("ECMTypeAuto").'<br>';
  471. $htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['desc'];
  472. print $form->textwithpicto('',$htmltooltip,1,0);
  473. print '</td>';
  474. print "</tr>\n";
  475. // Show sublevel
  476. if ($val['module'] == $_REQUEST["module"])
  477. {
  478. if ($val['module'] == 'xxx')
  479. {
  480. }
  481. else
  482. {
  483. $showonrightsize='featurenotyetavailable';
  484. }
  485. }
  486. $oldvallevel=$val['level'];
  487. $nbofentries++;
  488. }
  489. }
  490. }
  491. // Root title line (Manual section)
  492. print '<tr><td>';
  493. print '<table class="nobordernopadding"><tr class="nobordernopadding">';
  494. print '<td align="left" width="24px">';
  495. print img_picto_common('','treemenu/base.gif');
  496. print '</td><td align="left">'.$langs->trans("ECMRoot").' ('.$langs->trans("ECMSectionsManual").')';
  497. print '</td>';
  498. print '</tr></table></td>';
  499. print '<td align="right">';
  500. print '</td>';
  501. print '<td align="right">&nbsp;</td>';
  502. //print '<td align="right"><a href="'.DOL_URL_ROOT.'/ecm/docdir.php?action=create">'.img_edit_add().'</a></td>';
  503. print '<td align="right">&nbsp;</td>';
  504. print '<td align="right">&nbsp;</td>';
  505. print '<td align="center">';
  506. $htmltooltip=$langs->trans("ECMAreaDesc2");
  507. print $form->textwithpicto('',$htmltooltip,1,0);
  508. print '</td>';
  509. print '</tr>';
  510. // Load full tree
  511. if (empty($sqltree)) $sqltree=$ecmdirstatic->get_full_arbo(0);
  512. // ----- This section will show a tree from a fulltree array -----
  513. // $section must also be defined
  514. // ----------------------------------------------------------------
  515. // Define fullpathselected ( _x_y_z ) of $section parameter
  516. $fullpathselected='';
  517. foreach($sqltree as $key => $val)
  518. {
  519. //print $val['id']."-".$section."<br>";
  520. if ($val['id'] == $section)
  521. {
  522. $fullpathselected=$val['fullpath'];
  523. break;
  524. }
  525. }
  526. //print "fullpathselected=".$fullpathselected."<br>";
  527. // Update expandedsectionarray in session
  528. $expandedsectionarray=array();
  529. if (isset($_SESSION['dol_ecmexpandedsectionarray'])) $expandedsectionarray=explode(',',$_SESSION['dol_ecmexpandedsectionarray']);
  530. if ($section && $_GET['sectionexpand'] == 'true')
  531. {
  532. // We add all sections that are parent of opened section
  533. $pathtosection=explode('_',$fullpathselected);
  534. foreach($pathtosection as $idcursor)
  535. {
  536. if ($idcursor && ! in_array($idcursor,$expandedsectionarray)) // Not already in array
  537. {
  538. $expandedsectionarray[]=$idcursor;
  539. }
  540. }
  541. $_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray);
  542. }
  543. if ($section && $_GET['sectionexpand'] == 'false')
  544. {
  545. // We removed all expanded sections that are child of the closed section
  546. $oldexpandedsectionarray=$expandedsectionarray;
  547. $expandedsectionarray=array(); // Reset
  548. foreach($oldexpandedsectionarray as $sectioncursor)
  549. {
  550. // is_in_subtree(fulltree,sectionparent,sectionchild)
  551. if ($sectioncursor && ! is_in_subtree($sqltree,$section,$sectioncursor)) $expandedsectionarray[]=$sectioncursor;
  552. }
  553. $_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray);
  554. }
  555. //print $_SESSION['dol_ecmexpandedsectionarray'].'<br>';
  556. $nbofentries=0;
  557. $oldvallevel=0;
  558. $var=true;
  559. foreach($sqltree as $key => $val)
  560. {
  561. $var=false;
  562. $ecmdirstatic->id=$val['id'];
  563. $ecmdirstatic->ref=$val['label'];
  564. // Refresh cache
  565. if (preg_match('/refresh/i',$_GET['action']))
  566. {
  567. $result=$ecmdirstatic->fetch($val['id']);
  568. $ecmdirstatic->ref=$ecmdirstatic->label;
  569. $result=$ecmdirstatic->refreshcachenboffile();
  570. $val['cachenbofdoc']=$result;
  571. }
  572. //$fullpathparent=preg_replace('/(_[^_]+)$/i','',$val['fullpath']);
  573. // Define showline
  574. $showline=0;
  575. // If directory is son of expanded directory, we show line
  576. if (in_array($val['id_mere'],$expandedsectionarray)) $showline=4;
  577. // If directory is brother of selected directory, we show line
  578. elseif ($val['id'] != $section && $val['id_mere'] == $ecmdirstatic->motherof[$section]) $showline=3;
  579. // If directory is parent of selected directory or is selected directory, we show line
  580. elseif (preg_match('/'.$val['fullpath'].'_/i',$fullpathselected.'_')) $showline=2;
  581. // If we are level one we show line
  582. elseif ($val['level'] < 2) $showline=1;
  583. if ($showline)
  584. {
  585. if (in_array($val['id'],$expandedsectionarray)) $option='indexexpanded';
  586. else $option='indexnotexpanded';
  587. //print $option;
  588. print '<tr>';
  589. // Show tree graph pictos
  590. print '<td align="left">';
  591. print '<table class="nobordernopadding"><tr class="nobordernopadding"><td>';
  592. $resarray=tree_showpad($sqltree,$key);
  593. $a=$resarray[0];
  594. $nbofsubdir=$resarray[1];
  595. $c=$resarray[2];
  596. $nboffilesinsubdir=$resarray[3];
  597. print '</td>';
  598. // Show picto
  599. print '<td valign="top">';
  600. //print $val['fullpath']."(".$showline.")";
  601. $n='2';
  602. if ($b == 0 || ! in_array($val['id'],$expandedsectionarray)) $n='3';
  603. if (! in_array($val['id'],$expandedsectionarray)) $ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/plustop'.$n.'.gif','',1);
  604. else $ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/minustop'.$n.'.gif','',1);
  605. if ($option == 'indexexpanded') $lien = '<a href="'.$_SERVER["PHP_SELF"].'?section='.$val['id'].'&amp;sectionexpand=false">';
  606. if ($option == 'indexnotexpanded') $lien = '<a href="'.$_SERVER["PHP_SELF"].'?section='.$val['id'].'&amp;sectionexpand=true">';
  607. //$newref=str_replace('_',' ',$ref);
  608. $newref=$ref;
  609. $lienfin='</a>';
  610. print $lien.$newref.$lienfin;
  611. if (! in_array($val['id'],$expandedsectionarray)) print img_picto($ecmdirstatic->ref,DOL_URL_ROOT.'/theme/common/treemenu/folder.gif','',1);
  612. else print img_picto($ecmdirstatic->ref,DOL_URL_ROOT.'/theme/common/treemenu/folder-expanded.gif','',1);
  613. print '</td>';
  614. // Show link
  615. print '<td valign="middle">';
  616. if ($section == $val['id']) print ' <u>';
  617. print $ecmdirstatic->getNomUrl(0,'index',32);
  618. if ($section == $val['id']) print '</u>';
  619. print '</td>';
  620. print '<td>&nbsp;</td>';
  621. print '</tr></table>';
  622. print "</td>\n";
  623. // Nb of docs
  624. print '<td align="right">';
  625. print $val['cachenbofdoc'];
  626. print '</td>';
  627. print '<td align="left">';
  628. if ($nbofsubdir && $nboffilesinsubdir) print '<font color="#AAAAAA">+'.$nboffilesinsubdir.'</font> ';
  629. print '</td>';
  630. // Edit link
  631. print '<td align="right"><a href="'.DOL_URL_ROOT.'/ecm/docmine.php?section='.$val['id'].'">'.img_view().'</a></td>';
  632. // Add link
  633. //print '<td align="right"><a href="'.DOL_URL_ROOT.'/ecm/docdir.php?action=create&amp;catParent='.$val['id'].'">'.img_edit_add().'</a></td>';
  634. print '<td align="right">&nbsp;</td>';
  635. // Info
  636. print '<td align="center">';
  637. $userstatic->id=$val['fk_user_c'];
  638. $userstatic->nom=$val['login_c'];
  639. $htmltooltip='<b>'.$langs->trans("ECMSection").'</b>: '.$val['label'].'<br>';
  640. $htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMSectionManual").'<br>';
  641. $htmltooltip.='<b>'.$langs->trans("ECMCreationUser").'</b>: '.$userstatic->getNomUrl(1).'<br>';
  642. $htmltooltip.='<b>'.$langs->trans("ECMCreationDate").'</b>: '.dol_print_date($val['date_c'],"dayhour").'<br>';
  643. $htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['description'].'<br>';
  644. $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInDir").'</b>: '.$val['cachenbofdoc'].'<br>';
  645. if ($nbofsubdir) $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInSubDir").'</b>: '.$nboffilesinsubdir;
  646. else $htmltooltip.='<b>'.$langs->trans("ECMNbOfSubDir").'</b>: '.$nbofsubdir.'<br>';
  647. print $form->textwithpicto('',$htmltooltip,1,0);
  648. print "</td>";
  649. print "</tr>\n";
  650. }
  651. $oldvallevel=$val['level'];
  652. $nbofentries++;
  653. }
  654. // If nothing to show
  655. if ($nbofentries == 0)
  656. {
  657. print '<tr>';
  658. print '<td class="left"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('','treemenu/branchbottom.gif').'</td>';
  659. print '<td>'.img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/minustop3.gif','',1).'</td>';
  660. print '<td valign="middle">';
  661. print $langs->trans("ECMNoDirecotyYet");
  662. print '</td>';
  663. print '<td>&nbsp;</td>';
  664. print '</table></td>';
  665. print '<td colspan="5">&nbsp;</td>';
  666. print '</tr>';
  667. }
  668. // ----- End of section -----
  669. // --------------------------
  670. print "</table>";
  671. // Fin de zone Ajax
  672. }
  673. if ($conf->use_javascript_ajax)
  674. {
  675. ?>
  676. </div>
  677. <div id="ecm-layout-center" class="hidden">
  678. <div class="pane-in ecm-in-layout-center">
  679. <?php
  680. }
  681. else
  682. {
  683. print '</td><td valign="top" style="background: #FFFFFF">';
  684. }
  685. $formfile=new FormFile($db);
  686. $param=($sortfield?'&sortfield='.$sortfield:'').($sortorder?'&sortorder='.$sortorder:'');
  687. // Right area
  688. if ($module == 'invoice_supplier') // Auto area for suppliers invoices
  689. {
  690. $relativepath='facture';
  691. $upload_dir = $conf->fournisseur->dir_output.'/'.$relativepath;
  692. $filearray=dol_dir_list($upload_dir,"files",1,'',array('^SPECIMEN\.pdf$','^\.','\.meta$','^temp$','^CVS$'),$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  693. $param.='&module='.$module;
  694. $textifempty=($section?$langs->trans("NoFileFound"):($showonrightsize=='featurenotyetavailable'?$langs->trans("FeatureNotYetAvailable"):$langs->trans("ECMSelectASection")));
  695. $formfile->list_of_autoecmfiles($upload_dir,$filearray,$module,$param,1,'',$user->rights->ecm->upload,1,$textifempty,40);
  696. }
  697. else if ($module == 'invoice') // Auto area for suppliers invoices
  698. {
  699. $upload_dir = $conf->facture->dir_output;
  700. $filearray=dol_dir_list($upload_dir,"files",1,'',array('^SPECIMEN\.pdf$','^\.','\.meta$','^temp$','^payments$','^CVS$'),$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  701. $param.='&module='.$module;
  702. $textifempty=($section?$langs->trans("NoFileFound"):($showonrightsize=='featurenotyetavailable'?$langs->trans("FeatureNotYetAvailable"):$langs->trans("ECMSelectASection")));
  703. $formfile->list_of_autoecmfiles($upload_dir,$filearray,$module,$param,1,'',$user->rights->ecm->upload,1,$textifempty,40);
  704. }
  705. else // Manual area
  706. {
  707. $relativepath=$ecmdir->getRelativePath();
  708. $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
  709. $filearray=dol_dir_list($upload_dir,"files",0,'',array('^\.','\.meta$'),$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
  710. $param.='&section='.$section;
  711. $textifempty=($section?$langs->trans("NoFileFound"):($showonrightsize=='featurenotyetavailable'?$langs->trans("FeatureNotYetAvailable"):$langs->trans("ECMSelectASection")));
  712. $formfile->list_of_documents($filearray,'','ecm',$param,1,$relativepath,$user->rights->ecm->upload,1,$textifempty,40);
  713. }
  714. // print '<table width="100%" class="border">';
  715. // print '<tr><td> </td></tr></table>';
  716. if ($conf->use_javascript_ajax)
  717. {
  718. ?>
  719. </div>
  720. <div class="pane-in ecm-in-layout-south layout-padding">
  721. <?php
  722. }
  723. else
  724. {
  725. print '</td></tr>';
  726. // Actions attach new file
  727. print '<tr height="22">';
  728. //print '<td align="center">';
  729. //print '</td>';
  730. print '<td>';
  731. }
  732. if (! empty($section))
  733. {
  734. $formfile->form_attach_new_file(DOL_URL_ROOT.'/ecm/index.php', 'none', 0, $section,$user->rights->ecm->upload, 48);
  735. }
  736. else print '&nbsp;';
  737. if ($conf->use_javascript_ajax)
  738. {
  739. ?>
  740. </div>
  741. </div>
  742. </div> <!-- end div id="containerlayout" -->
  743. <?php
  744. }
  745. else
  746. {
  747. print '</td></tr>';
  748. print '</table>';
  749. }
  750. // End of page
  751. $db->close();
  752. llxFooter();
  753. ?>