PageRenderTime 203ms CodeModel.GetById 71ms app.highlight 64ms RepoModel.GetById 56ms app.codeStats 1ms

/htdocs/ecm/index.php

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