index_auto.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <?php
  2. /* Copyright (C) 2008-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2008-2010 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2016 Alexandre Spangaro <aspangaro@zendsi.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/ecm/index_auto.php
  21. * \ingroup ecm
  22. * \brief Main page for ECM section area
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/ecm.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array("ecm","companies","other","users","orders","propal","bills","contracts"));
  32. // Security check
  33. if ($user->societe_id) $socid=$user->societe_id;
  34. $result = restrictedArea($user, 'ecm', 0);
  35. // Get parameters
  36. $socid=GETPOST('socid','int');
  37. $action=GETPOST('action','aZ09');
  38. $section=GETPOST('section','int')?GETPOST('section','int'):GETPOST('section_id','int');
  39. $module=GETPOST('module','alpha');
  40. if (! $section) $section=0;
  41. $section_dir=GETPOST('section_dir','alpha');
  42. $search_doc_ref=GETPOST('search_doc_ref','alpha');
  43. $sortfield = GETPOST("sortfield",'alpha');
  44. $sortorder = GETPOST("sortorder",'alpha');
  45. $page = GETPOST("page",'int');
  46. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  47. $offset = $conf->liste_limit * $page;
  48. $pageprev = $page - 1;
  49. $pagenext = $page + 1;
  50. if (! $sortorder) $sortorder="ASC";
  51. if (! $sortfield) $sortfield="fullname";
  52. if ($module == 'invoice_supplier' && $sortfield == "fullname") $sortfield="level1name";
  53. $ecmdir = new EcmDirectory($db);
  54. if ($section)
  55. {
  56. $result=$ecmdir->fetch($section);
  57. if (! $result > 0)
  58. {
  59. dol_print_error($db,$ecmdir->error);
  60. exit;
  61. }
  62. }
  63. $form=new Form($db);
  64. $ecmdirstatic = new EcmDirectory($db);
  65. $userstatic = new User($db);
  66. $error=0;
  67. /*
  68. * Actions
  69. */
  70. // Purge search criteria
  71. if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
  72. {
  73. $search_doc_ref='';
  74. }
  75. // Add directory
  76. if ($action == 'add' && $user->rights->ecm->setup)
  77. {
  78. $ecmdir->ref = 'NOTUSEDYET';
  79. $ecmdir->label = GETPOST("label");
  80. $ecmdir->description = GETPOST("desc");
  81. $id = $ecmdir->create($user);
  82. if ($id > 0)
  83. {
  84. header("Location: ".$_SERVER["PHP_SELF"]);
  85. exit;
  86. }
  87. else
  88. {
  89. setEventMessages('Error '.$langs->trans($ecmdir->error), null, 'errors');
  90. $action = "create";
  91. }
  92. clearstatcache();
  93. }
  94. // Remove file
  95. if ($action == 'confirm_deletefile')
  96. {
  97. if (GETPOST('confirm') == 'yes')
  98. {
  99. $langs->load("other");
  100. if ($section)
  101. {
  102. $result=$ecmdir->fetch($section);
  103. if (! ($result > 0))
  104. {
  105. dol_print_error($db,$ecmdir->error);
  106. exit;
  107. }
  108. $relativepath=$ecmdir->getRelativePath();
  109. }
  110. else $relativepath='';
  111. $upload_dir = $conf->ecm->dir_output.($relativepath?'/'.$relativepath:'');
  112. $file = $upload_dir . "/" . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_POST are already decoded by PHP).
  113. $ret=dol_delete_file($file);
  114. if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
  115. else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
  116. $result=$ecmdir->changeNbOfFiles('-');
  117. clearstatcache();
  118. }
  119. $action='file_manager';
  120. }
  121. // Remove directory
  122. if ($action == 'confirm_deletesection' && GETPOST('confirm') == 'yes')
  123. {
  124. $result=$ecmdir->delete($user);
  125. setEventMessages($langs->trans("ECMSectionWasRemoved", $ecmdir->label), null, 'mesgs');
  126. clearstatcache();
  127. }
  128. // Refresh directory view
  129. // This refresh list of dirs, not list of files (for preformance reason). List of files is refresh only if dir was not synchronized.
  130. // To refresh content of dir with cache, just open the dir in edit mode.
  131. if ($action == 'refreshmanual')
  132. {
  133. $ecmdirtmp = new EcmDirectory($db);
  134. // This part of code is same than into file ecm/ajax/ecmdatabase.php TODO Remove duplicate
  135. clearstatcache();
  136. $diroutputslash=str_replace('\\','/',$conf->ecm->dir_output);
  137. $diroutputslash.='/';
  138. // Scan directory tree on disk
  139. $disktree=dol_dir_list($conf->ecm->dir_output,'directories',1,'','^temp$','','',0);
  140. // Scan directory tree in database
  141. $sqltree=$ecmdirstatic->get_full_arbo(0);
  142. $adirwascreated=0;
  143. // Now we compare both trees to complete missing trees into database
  144. //var_dump($disktree);
  145. //var_dump($sqltree);
  146. foreach($disktree as $dirdesc) // Loop on tree onto disk
  147. {
  148. $dirisindatabase=0;
  149. foreach($sqltree as $dirsqldesc)
  150. {
  151. if ($conf->ecm->dir_output.'/'.$dirsqldesc['fullrelativename'] == $dirdesc['fullname'])
  152. {
  153. $dirisindatabase=1;
  154. break;
  155. }
  156. }
  157. if (! $dirisindatabase)
  158. {
  159. $txt="Directory found on disk ".$dirdesc['fullname'].", not found into database so we add it";
  160. dol_syslog($txt);
  161. //print $txt."<br>\n";
  162. // We must first find the fk_parent of directory to create $dirdesc['fullname']
  163. $fk_parent=-1;
  164. $relativepathmissing=str_replace($diroutputslash,'',$dirdesc['fullname']);
  165. $relativepathtosearchparent=$relativepathmissing;
  166. //dol_syslog("Try to find parent id for directory ".$relativepathtosearchparent);
  167. if (preg_match('/\//',$relativepathtosearchparent))
  168. //while (preg_match('/\//',$relativepathtosearchparent))
  169. {
  170. $relativepathtosearchparent=preg_replace('/\/[^\/]*$/','',$relativepathtosearchparent);
  171. $txt="Is relative parent path ".$relativepathtosearchparent." for ".$relativepathmissing." found in sql tree ?";
  172. dol_syslog($txt);
  173. //print $txt." -> ";
  174. $parentdirisindatabase=0;
  175. foreach($sqltree as $dirsqldesc)
  176. {
  177. if ($dirsqldesc['fullrelativename'] == $relativepathtosearchparent)
  178. {
  179. $parentdirisindatabase=$dirsqldesc['id'];
  180. break;
  181. }
  182. }
  183. if ($parentdirisindatabase > 0)
  184. {
  185. dol_syslog("Yes with id ".$parentdirisindatabase);
  186. //print "Yes with id ".$parentdirisindatabase."<br>\n";
  187. $fk_parent=$parentdirisindatabase;
  188. //break; // We found parent, we can stop the while loop
  189. }
  190. else
  191. {
  192. dol_syslog("No");
  193. //print "No<br>\n";
  194. }
  195. }
  196. else
  197. {
  198. dol_syslog("Parent is root");
  199. $fk_parent=0; // Parent is root
  200. }
  201. if ($fk_parent >= 0)
  202. {
  203. $ecmdirtmp->ref = 'NOTUSEDYET';
  204. $ecmdirtmp->label = dol_basename($dirdesc['fullname']);
  205. $ecmdirtmp->description = '';
  206. $ecmdirtmp->fk_parent = $fk_parent;
  207. $txt="We create directory ".$ecmdirtmp->label." with parent ".$fk_parent;
  208. dol_syslog($txt);
  209. //print $ecmdirtmp->cachenbofdoc."<br>\n";exit;
  210. $id = $ecmdirtmp->create($user);
  211. if ($id > 0)
  212. {
  213. $newdirsql=array('id'=>$id,
  214. 'id_mere'=>$ecmdirtmp->fk_parent,
  215. 'label'=>$ecmdirtmp->label,
  216. 'description'=>$ecmdirtmp->description,
  217. 'fullrelativename'=>$relativepathmissing);
  218. $sqltree[]=$newdirsql; // We complete fulltree for following loops
  219. //var_dump($sqltree);
  220. $adirwascreated=1;
  221. }
  222. else
  223. {
  224. dol_syslog("Failed to create directory ".$ecmdirtmp->label, LOG_ERR);
  225. }
  226. }
  227. else {
  228. $txt="Parent of ".$dirdesc['fullname']." not found";
  229. dol_syslog($txt);
  230. //print $txt."<br>\n";
  231. }
  232. }
  233. }
  234. // Loop now on each sql tree to check if dir exists
  235. foreach($sqltree as $dirdesc) // Loop on each sqltree to check dir is on disk
  236. {
  237. $dirtotest=$conf->ecm->dir_output.'/'.$dirdesc['fullrelativename'];
  238. if (! dol_is_dir($dirtotest))
  239. {
  240. $ecmdirtmp->id=$dirdesc['id'];
  241. $ecmdirtmp->delete($user,'databaseonly');
  242. //exit;
  243. }
  244. }
  245. $sql="UPDATE ".MAIN_DB_PREFIX."ecm_directories set cachenbofdoc = -1 WHERE cachenbofdoc < 0"; // If pb into cahce counting, we set to value -1 = "unknown"
  246. dol_syslog("sql = ".$sql);
  247. $db->query($sql);
  248. // If a directory was added, the fulltree array is not correctly completed and sorted, so we clean
  249. // it to be sure that fulltree array is not used without reloading it.
  250. if ($adirwascreated) $sqltree=null;
  251. }
  252. /*
  253. * View
  254. */
  255. // Define height of file area (depends on $_SESSION["dol_screenheight"])
  256. //print $_SESSION["dol_screenheight"];
  257. $maxheightwin=(isset($_SESSION["dol_screenheight"]) && $_SESSION["dol_screenheight"] > 466)?($_SESSION["dol_screenheight"]-136):660; // Also into index.php file
  258. $moreheadcss='';
  259. $moreheadjs='';
  260. //$morejs=array();
  261. $morejs=array('includes/jquery/plugins/blockUI/jquery.blockUI.js','core/js/blockUI.js'); // Used by ecm/tpl/enabledfiletreeajax.tpl.pgp
  262. if (empty($conf->global->MAIN_ECM_DISABLE_JS)) $morejs[]="includes/jquery/plugins/jqueryFileTree/jqueryFileTree.js";
  263. $moreheadjs.='<script type="text/javascript">'."\n";
  264. $moreheadjs.='var indicatorBlockUI = \''.DOL_URL_ROOT."/theme/".$conf->theme."/img/working.gif".'\';'."\n";
  265. $moreheadjs.='</script>'."\n";
  266. llxHeader($moreheadcss.$moreheadjs,$langs->trans("ECMArea"),'','','','',$morejs,'',0,0);
  267. // Add sections to manage
  268. $rowspan=0;
  269. $sectionauto=array();
  270. if (! empty($conf->global->ECM_AUTO_TREE_ENABLED))
  271. {
  272. 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")); }
  273. if (! empty($conf->societe->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'company', 'test'=>$conf->societe->enabled, 'label'=>$langs->trans("ThirdParties"), 'desc'=>$langs->trans("ECMDocsByThirdParties")); }
  274. if (! empty($conf->propal->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'propal', 'test'=>$conf->propal->enabled, 'label'=>$langs->trans("Proposals"), 'desc'=>$langs->trans("ECMDocsByProposals")); }
  275. if (! empty($conf->contrat->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'contract','test'=>$conf->contrat->enabled, 'label'=>$langs->trans("Contracts"), 'desc'=>$langs->trans("ECMDocsByContracts")); }
  276. if (! empty($conf->commande->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'order', 'test'=>$conf->commande->enabled, 'label'=>$langs->trans("CustomersOrders"), 'desc'=>$langs->trans("ECMDocsByOrders")); }
  277. if (! empty($conf->facture->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'invoice', 'test'=>$conf->facture->enabled, 'label'=>$langs->trans("CustomersInvoices"), 'desc'=>$langs->trans("ECMDocsByInvoices")); }
  278. if (! empty($conf->supplier_proposal->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'supplier_proposal', 'test'=>$conf->supplier_proposal->enabled, 'label'=>$langs->trans("SupplierProposals"), 'desc'=>$langs->trans("ECMDocsBySupplierProposals")); }
  279. 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")); }
  280. 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")); }
  281. 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")); }
  282. if (! empty($conf->projet->enabled)) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'project', 'test'=>$conf->projet->enabled, 'label'=>$langs->trans("Projects"), 'desc'=>$langs->trans("ECMDocsByProjects")); }
  283. if (! empty($conf->ficheinter->enabled)) { $langs->load("interventions"); $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'fichinter', 'test'=>$conf->ficheinter->enabled, 'label'=>$langs->trans("Interventions"), 'desc'=>$langs->trans("ECMDocsByInterventions")); }
  284. if (! empty($conf->expensereport->enabled)) { $langs->load("trips"); $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'expensereport', 'test'=>$conf->expensereport->enabled, 'label'=>$langs->trans("ExpenseReports"), 'desc'=>$langs->trans("ECMDocsByExpenseReports")); }
  285. if (! empty($conf->holiday->enabled)) { $langs->load("holiday"); $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'holiday', 'test'=>$conf->holiday->enabled, 'label'=>$langs->trans("Holidays"), 'desc'=>$langs->trans("ECMDocsByHolidays")); }
  286. $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'user', 'test'=>1, 'label'=>$langs->trans("Users"), 'desc'=>$langs->trans("ECMDocsByUsers"));
  287. }
  288. $head = ecm_prepare_dasboard_head('');
  289. dol_fiche_head($head, 'index_auto', $langs->trans("ECMArea").' - '.$langs->trans("ECMFileManager"), -1, '');
  290. // Confirm remove file (for non javascript users)
  291. if ($action == 'delete' && empty($conf->use_javascript_ajax))
  292. {
  293. print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.$section.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1);
  294. }
  295. // Start container of all panels
  296. ?>
  297. <!-- Begin div id="containerlayout" -->
  298. <div id="containerlayout">
  299. <div id="ecm-layout-north" class="toolbar largebutton">
  300. <?php
  301. // Start top panel, toolbar
  302. print '<div class="inline-block toolbarbutton centpercent">';
  303. // Toolbar
  304. $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:'')));
  305. print '<a href="'.$url.'" class="inline-block valignmiddle toolbarbutton" title="'.dol_escape_htmltag($langs->trans('Refresh')).'">';
  306. print '<img id="refreshbutton" class="toolbarbutton" border="0" src="'.DOL_URL_ROOT.'/theme/common/view-refresh.png">';
  307. print '</a>';
  308. print '</div>';
  309. // End top panel, toolbar
  310. ?>
  311. </div>
  312. <div id="ecm-layout-west" class="inline-block">
  313. <?php
  314. // Start left area
  315. // Confirmation de la suppression d'une ligne categorie
  316. if ($action == 'delete_section')
  317. {
  318. print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.$section, $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection','','',1);
  319. }
  320. // End confirm
  321. if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$action) || $action == 'delete')
  322. {
  323. print '<table width="100%" class="liste noborderbottom">'."\n";
  324. print '<!-- Title for auto directories -->'."\n";
  325. print '<tr class="liste_titre">'."\n";
  326. print '<th class="liste_titre" align="left" colspan="6">';
  327. print '&nbsp;'.$langs->trans("ECMSections");
  328. print '</th></tr>';
  329. $showonrightsize='';
  330. // Auto section
  331. if (count($sectionauto))
  332. {
  333. $htmltooltip=$langs->trans("ECMAreaDesc2");
  334. $sectionauto=dol_sort_array($sectionauto,'label','ASC',true,false);
  335. print '<tr>';
  336. print '<td colspan="6">';
  337. print '<div id="filetreeauto" class="ecmfiletree"><ul class="ecmjqft">';
  338. $nbofentries=0;
  339. $oldvallevel=0;
  340. foreach ($sectionauto as $key => $val)
  341. {
  342. if (empty($val['test'])) continue; // If condition to show is ok
  343. $var=false;
  344. print '<li class="directory collapsed">';
  345. if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS))
  346. {
  347. print '<a class="fmdirlia jqft ecmjqft" href="'.$_SERVER["PHP_SELF"].'?module='.$val['module'].'">';
  348. print $val['label'];
  349. print '</a>';
  350. }
  351. else
  352. {
  353. print '<a class="fmdirlia jqft ecmjqft" href="'.$_SERVER["PHP_SELF"].'?module='.$val['module'].'">';
  354. print $val['label'];
  355. print '</a>';
  356. }
  357. print '<div class="ecmjqft">';
  358. // Info
  359. $htmltooltip='<b>'.$langs->trans("ECMSection").'</b>: '.$val['label'].'<br>';
  360. $htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMSectionAuto").'<br>';
  361. $htmltooltip.='<b>'.$langs->trans("ECMCreationUser").'</b>: '.$langs->trans("ECMTypeAuto").'<br>';
  362. $htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['desc'];
  363. print $form->textwithpicto('', $htmltooltip, 1, 'info');
  364. print '</div>';
  365. print '</li>';
  366. $nbofentries++;
  367. }
  368. print '</ul></div></td></tr>';
  369. }
  370. print "</table>";
  371. }
  372. // End left panel
  373. ?>
  374. </div>
  375. <div id="ecm-layout-center" class="inline-block">
  376. <div class="pane-in ecm-in-layout-center">
  377. <div id="ecmfileview" class="ecmfileview">
  378. <?php
  379. // Start right panel
  380. $mode='noajax';
  381. $url=DOL_URL_ROOT.'/ecm/index_auto.php';
  382. include_once DOL_DOCUMENT_ROOT.'/core/ajax/ajaxdirpreview.php';
  383. // End right panel
  384. ?>
  385. </div>
  386. </div>
  387. </div>
  388. </div> <!-- End div id="containerlayout" -->
  389. <?php
  390. // End of page
  391. if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) {
  392. include DOL_DOCUMENT_ROOT.'/ecm/tpl/enablefiletreeajax.tpl.php';
  393. }
  394. dol_fiche_end();
  395. llxFooter();
  396. $db->close();