* Copyright (C) 2008-2009 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * \file htdocs/ecm/index.php * \ingroup ecm * \brief Main page for ECM section area * \version $Id$ * \author Laurent Destailleur */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/ecm.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/treeview.lib.php"); require_once(DOL_DOCUMENT_ROOT."/ecm/ecmdirectory.class.php"); // Load traductions files $langs->load("ecm"); $langs->load("companies"); $langs->load("other"); $langs->load("users"); $langs->load("orders"); $langs->load("propal"); $langs->load("bills"); $langs->load("contracts"); // Security check if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'ecm',''); // Load permissions $user->getrights('ecm'); // Get parameters $socid = isset($_GET["socid"])?$_GET["socid"]:''; $action = isset($_GET["action"])?$_GET["action"]:$_POST['action']; $section=isset($_GET["section"])?$_GET["section"]:$_POST['section']; if (! $section) $section=0; $upload_dir = $conf->ecm->dir_output.'/'.$section; $page=$_GET["page"]; $sortorder=$_GET["sortorder"]; $sortfield=$_GET["sortfield"]; $limit = $conf->liste_limit; $offset = $limit * $page ; if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="label"; $ecmdir = new ECMDirectory($db); if (! empty($_REQUEST["section"])) { $result=$ecmdir->fetch($_REQUEST["section"]); if (! $result > 0) { dol_print_error($db,$ecmdir->error); exit; } } /******************************************************************* * ACTIONS * * Put here all code to do according to value of "action" parameter ********************************************************************/ // Envoie fichier if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) { $result=$ecmdir->fetch($_REQUEST["section"]); if (! $result > 0) { dol_print_error($db,$ecmdir->error); exit; } $relativepath=$ecmdir->getRelativePath(); $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; if (! is_dir($upload_dir)) { $result=create_exdir($upload_dir); } if (is_dir($upload_dir)) { $result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); if ($result > 0) { //$mesg = '
'.$langs->trans("FileTransferComplete").'
'; //print_r($_FILES); $result=$ecmdir->changeNbOfFiles('+'); } else if ($result < 0) { // Echec transfert (fichier depassant la limite ?) $langs->load("errors"); $mesg = '
'.$langs->trans("ErrorFileNotUploaded").'
'; // print_r($_FILES); } else { // File infected by a virus $langs->load("errors"); $mesg = '
'.$langs->trans("ErrorFileIsInfectedWith",$result).'
'; } } else { // Echec transfert (fichier depassant la limite ?) $langs->load("errors"); $mesg = '
'.$langs->trans("ErrorFailToCreateDir",$upload_dir).'
'; } } // Remove file if ($_POST['action'] == 'confirm_deletefile' && $_POST['confirm'] == 'yes') { $result=$ecmdir->fetch($_REQUEST["section"]); if (! $result > 0) { dol_print_error($db,$ecmdir->error); exit; } $relativepath=$ecmdir->getRelativePath(); $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; $file = $upload_dir . "/" . urldecode($_GET["urlfile"]); $result=dol_delete_file($file); $mesg = '
'.$langs->trans("FileWasRemoved").'
'; $result=$ecmdir->changeNbOfFiles('-'); $action='file_manager'; } // Action ajout d'un produit ou service if ($_POST["action"] == 'add' && $user->rights->ecm->setup) { $ecmdir->ref = $_POST["ref"]; $ecmdir->label = $_POST["label"]; $ecmdir->description = $_POST["desc"]; $id = $ecmdir->create($user); if ($id > 0) { Header("Location: ".$_SERVER["PHP_SELF"]); exit; } else { $mesg='
Error '.$langs->trans($ecmdir->error).'
'; $_GET["action"] = "create"; } } // Suppression fichier if ($_POST['action'] == 'confirm_deletesection' && $_POST['confirm'] == 'yes') { $result=$ecmdir->delete($user); $mesg = '
'.$langs->trans("ECMSectionWasRemoved", $ecmdir->label).'
'; } /******************************************************************* * PAGE * * Put here all code to do according to value of "action" parameter ********************************************************************/ llxHeader(); $form=new Form($db); $ecmdirstatic = new ECMDirectory($db); $userstatic = new User($db); // Ajout rubriques automatiques $rowspan=0; $sectionauto=array(); if ($conf->produit->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'product', 'test'=>$conf->produit->enabled, 'label'=>$langs->trans("ProductsAndServices"), 'desc'=>$langs->trans("ECMDocsByProducts")); } if ($conf->societe->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'company', 'test'=>$conf->societe->enabled, 'label'=>$langs->trans("ThirdParties"), 'desc'=>$langs->trans("ECMDocsByThirdParties")); } if ($conf->propal->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'propal', 'test'=>$conf->propal->enabled, 'label'=>$langs->trans("Prop"), 'desc'=>$langs->trans("ECMDocsByProposals")); } if ($conf->contrat->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'contract','test'=>$conf->contrat->enabled, 'label'=>$langs->trans("Contracts"), 'desc'=>$langs->trans("ECMDocsByContracts")); } if ($conf->commande->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'order', 'test'=>$conf->commande->enabled,'label'=>$langs->trans("CustomersOrders"), 'desc'=>$langs->trans("ECMDocsByOrders")); } if ($conf->fournisseur->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'supplier_order', 'test'=>$conf->fournisseur->enabled, 'label'=>$langs->trans("SuppliersInvoices"), 'desc'=>$langs->trans("ECMDocsByOrders")); } if ($conf->facture->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'invoice', 'test'=>$conf->facture->enabled, 'label'=>$langs->trans("CustomersInvoices"), 'desc'=>$langs->trans("ECMDocsByInvoices")); } if ($conf->fournisseur->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'supplier_invoice', 'test'=>$conf->fournisseur->enabled, 'label'=>$langs->trans("SuppliersOrders"), 'desc'=>$langs->trans("ECMDocsByOrders")); } //*********************** // List //*********************** print_fiche_titre($langs->trans("ECMArea")); print $langs->trans("ECMAreaDesc")."
"; print $langs->trans("ECMAreaDesc2")."
"; print "
\n"; // Confirm remove file if ($_GET['action'] == 'delete') { $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$_REQUEST["section"].'&urlfile='.urldecode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile'); if ($ret == 'html') print '
'; } if ($mesg) { print $mesg."
"; } // Tool bar $head = ecm_prepare_head_fm($fac); dol_fiche_head($head, 'file_manager', '', 1); print ''; // Actions buttons print ''; print '
'; // Left area print '
'; if (empty($action) || $action == 'file_manager' || eregi('refresh',$action) || $action == 'delete') { $userstatic = new User($db); $ecmdirstatic = new ECMDirectory($db); // Confirmation de la suppression d'une ligne categorie if ($_GET['action'] == 'delete_section') { $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.urldecode($_GET["section"]), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection'); if ($ret == 'html') print '
'; } // Construit liste des repertoires print ''; print ''; print ''; print ''; print ''; if (sizeof($sectionauto)) { // Root title line (Automatic section) print ''; print ''; print ''; print ''; print ''; print ''; print ''; //print ''; print ''; $sectionauto=dol_sort_array($sectionauto,'label','ASC',true,false); $nbofentries=0; $oldvallevel=0; foreach ($sectionauto as $key => $val) { if ($val['test']) { $var=false; print ''; // Section print '\n"; // Nb of doc in dir print ''; // Nb of doc in subdir print ''; // Edit link print ''; // Add link print ''; // Info print ''; print "\n"; // Show sublevel if ($val['module'] == $_REQUEST["module"]) { if ($val['module'] == 'xxx') { } else { print ''; } } $oldvallevel=$val['level']; $nbofentries++; } } } // Root title line (Manual section) print ''; print ''; print ''; //print ''; print ''; print ''; print ''; print ''; // Load full tree $fulltree=$ecmdirstatic->get_full_arbo(); // ----- This section will show a tree from a fulltree array ----- // $section must also be defined // ---------------------------------------------------------------- // Define fullpathselected ( _x_y_z ) of $section parameter $fullpathselected=''; foreach($fulltree as $key => $val) { //print $val['id']."-".$section."
"; if ($val['id'] == $section) { $fullpathselected=$val['fullpath']; break; } } //print "fullpathselected=".$fullpathselected."
"; // Update expandedsectionarray in session $expandedsectionarray=array(); if (isset($_SESSION['dol_ecmexpandedsectionarray'])) $expandedsectionarray=split(',',$_SESSION['dol_ecmexpandedsectionarray']); if ($section && $_GET['sectionexpand'] == 'true') { // We add all sections that are parent of opened section $pathtosection=split('_',$fullpathselected); foreach($pathtosection as $idcursor) { if ($idcursor && ! in_array($idcursor,$expandedsectionarray)) // Not already in array { $expandedsectionarray[]=$idcursor; } } $_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray); } if ($section && $_GET['sectionexpand'] == 'false') { // We removed all expanded sections that are child of the closed section $oldexpandedsectionarray=$expandedsectionarray; $expandedsectionarray=array(); // Reset foreach($oldexpandedsectionarray as $sectioncursor) { // is_in_subtree(fulltree,sectionparent,sectionchild) if ($sectioncursor && ! is_in_subtree($fulltree,$section,$sectioncursor)) $expandedsectionarray[]=$sectioncursor; } $_SESSION['dol_ecmexpandedsectionarray']=join(',',$expandedsectionarray); } //print $_SESSION['dol_ecmexpandedsectionarray'].'
'; $nbofentries=0; $oldvallevel=0; $var=true; foreach($fulltree as $key => $val) { $var=false; $ecmdirstatic->id=$val['id']; $ecmdirstatic->ref=$val['label']; // Refresh cache if (eregi('refresh',$_GET['action'])) { $result=$ecmdirstatic->fetch($val['id']); $ecmdirstatic->ref=$ecmdirstatic->label; $result=$ecmdirstatic->refreshcachenboffile(); $val['cachenbofdoc']=$result; } //$fullpathparent=eregi_replace('_[^_]+$','',$val['fullpath']); // Define showline $showline=0; // If directory is son of expanded directory, we show line if (in_array($val['id_mere'],$expandedsectionarray)) $showline=4; // If directory is brother of selected directory, we show line elseif ($val['id'] != $section && $val['id_mere'] == $ecmdirstatic->motherof[$section]) $showline=3; // If directory is parent of selected directory or is selected directory, we show line elseif (eregi($val['fullpath'].'_',$fullpathselected.'_')) $showline=2; // If we are level one we show line elseif ($val['level'] < 2) $showline=1; if ($showline) { if (in_array($val['id'],$expandedsectionarray)) $option='indexexpanded'; else $option='indexnotexpanded'; //print $option; print ''; // Show tree graph pictos print '\n"; // Nb of docs print ''; print ''; // Edit link print ''; // Add link //print ''; print ''; // Info print '"; print "\n"; } $oldvallevel=$val['level']; $nbofentries++; } // If nothing to show if ($nbofentries == 0) { print ''; print ''; print ''; print ''; } // ----- End of section ----- // -------------------------- print "
'.$langs->trans("ECMSections").''; print ''.img_picto($langs->trans("Refresh"),'refresh').' '; print '
'; print ''; print ''; print '
'; print img_picto_common('','treemenu/base.gif'); print ''.$langs->trans("ECMRoot").' ('.$langs->trans("ECMSectionsAuto").')'; print '
'; print '
    '; $htmltooltip=$langs->trans("ECMAreaDesc2"); print $form->textwithpicto('',$htmltooltip,1,0); print ''.$langs->trans("ECMNbOfDocsSmall").' '.img_picto($langs->trans("Refresh"),'refresh').'
'; print ''; print ''; print '
'; tree_showpad($sectionauto,$key); print ''; if ($val['module'] == $_REQUEST["module"]) { $n=3; $ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/minustop'.$n.'.gif','',1); } else { $n=3; $ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/plustop'.$n.'.gif','',1); } print ''; print $ref; print ''; print img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/folder.gif','',1); print ''; print ''; print $val['label']; print '
'; print "
    '; $htmltooltip=''.$langs->trans("ECMSection").': '.$val['label'].'
'; $htmltooltip=''.$langs->trans("Type").': '.$langs->trans("ECMSectionAuto").'
'; $htmltooltip.=''.$langs->trans("ECMCreationUser").': '.$langs->trans("ECMTypeAuto").'
'; $htmltooltip.=''.$langs->trans("Description").': '.$val['desc']; print $form->textwithpicto('',$htmltooltip,1,0); print '
'.$langs->trans("FeatureNotYetAvailable").'
'; print ''; print ''; print '
'; print img_picto_common('','treemenu/base.gif'); print ''.$langs->trans("ECMRoot").' ('.$langs->trans("ECMSectionsManual").')'; print '
'; print ' '.img_edit_add().'  '; $htmltooltip=$langs->trans("ECMAreaDesc2"); print $form->textwithpicto('',$htmltooltip,1,0); print '
'; print ''; // Show picto print ''; // Show link print ''; print ''; print '
'; $resarray=tree_showpad($fulltree,$key); $a=$resarray[0]; $nbofsubdir=$resarray[1]; $c=$resarray[2]; $nboffilesinsubdir=$resarray[3]; print ''; //print $val['fullpath']."(".$showline.")"; $n='2'; if ($b == 0 || ! in_array($val['id'],$expandedsectionarray)) $n='3'; if (! in_array($val['id'],$expandedsectionarray)) $ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/plustop'.$n.'.gif','',1); else $ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/minustop'.$n.'.gif','',1); if ($option == 'indexexpanded') $lien = ''; if ($option == 'indexnotexpanded') $lien = ''; $newref=eregi_replace('_',' ',$ref); $lienfin=''; print $lien.$newref.$lienfin; if (! in_array($val['id'],$expandedsectionarray)) print img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/folder.gif','',1); else print img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/folder-expanded.gif','',1); print ''; if ($section == $val['id']) print ' '; print $ecmdirstatic->getNomUrl(0,'index'); if ($section == $val['id']) print ''; print ' 
'; print "
'; print $val['cachenbofdoc']; print ''; if ($nbofsubdir && $nboffilesinsubdir) print '+'.$nboffilesinsubdir.' '; print ''.img_edit().''.img_edit_add().' '; $userstatic->id=$val['fk_user_c']; $userstatic->nom=$val['login_c']; $htmltooltip=''.$langs->trans("ECMSection").': '.$val['label'].'
'; $htmltooltip=''.$langs->trans("Type").': '.$langs->trans("ECMSectionManual").'
'; $htmltooltip.=''.$langs->trans("ECMCreationUser").': '.$userstatic->getNomUrl(1).'
'; $htmltooltip.=''.$langs->trans("ECMCreationDate").': '.dol_print_date($val['date_c'],"dayhour").'
'; $htmltooltip.=''.$langs->trans("Description").': '.$val['description'].'
'; $htmltooltip.=''.$langs->trans("ECMNbOfFilesInDir").': '.$val['cachenbofdoc'].'
'; if ($nbofsubdir) $htmltooltip.=''.$langs->trans("ECMNbOfFilesInSubDir").': '.$nboffilesinsubdir; else $htmltooltip.=''.$langs->trans("ECMNbOfSubDir").': '.$nbofsubdir.'
'; print $form->textwithpicto('',$htmltooltip,1,0); print "
'; print ''; print ''; print ''; print '
'.img_picto_common('','treemenu/branchbottom.gif').''.img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/minustop3.gif','',1).''; print $langs->trans("ECMNoDirecotyYet"); print ' 
 
"; // Fin de zone Ajax } print '
'; print '
'; // Right area $relativepath=$ecmdir->getRelativePath(); $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; $filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_ASC:SORT_DESC),1); $formfile=new FormFile($db); $param='&section='.$section; $textifempty=($section?$langs->trans("NoFileFound"):$langs->trans("ECMSelectASection")); $formfile->list_of_documents($filearray,'','ecm',$param,1,$relativepath,$user->rights->ecm->upload,1,$textifempty); // print ''; // print '
'; print '
'; if (empty($action) || $action == 'file_manager' || eregi('refresh',$action)) { if ($user->rights->ecm->setup) { print ''.$langs->trans('ECMAddSection').''; } else { print ''.$langs->trans('ECMAddSection').''; } } print ''; if ($user->rights->ecm->upload && ! empty($section)) { $formfile->form_attach_new_file(DOL_URL_ROOT.'/ecm/index.php','',0,$section,1); } else print ' '; print '
'; print '
'; // End of page $db->close(); llxFooter('$Date$ - $Revision$'); ?>