* Copyright (C) 2008-2010 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, see . */ /** * \file htdocs/ecm/index.php * \ingroup ecm * \brief Main page for ECM section area * \author Laurent Destailleur */ if (! defined('REQUIRE_JQUERY_LAYOUT')) define('REQUIRE_JQUERY_LAYOUT','1'); require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/ecm.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/treeview.lib.php"); require_once(DOL_DOCUMENT_ROOT."/ecm/class/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', 0); // Load permissions $user->getrights('ecm'); // Get parameters $socid=GETPOST('socid'); $action=GETPOST("action"); $section=GETPOST("section"); $module=GETPOST("module"); if (! $section) $section=0; $upload_dir = $conf->ecm->dir_output.'/'.$section; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); if ($page == -1) { $page = 0; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="fullname"; $ecmdir = new EcmDirectory($db); if (GETPOST("section")) { $result=$ecmdir->fetch(GETPOST("section")); if (! $result > 0) { dol_print_error($db,$ecmdir->error); exit; } } $form=new Form($db); $ecmdirstatic = new EcmDirectory($db); $userstatic = new User($db); /******************************************************************* * ACTIONS * * Put here all code to do according to value of "action" parameter ********************************************************************/ // Upload file if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC)) { $relativepath=$ecmdir->getRelativePath(); $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; if (create_exdir($upload_dir) >= 0) { $resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0, 0, $_FILES['userfile']['error']); if (is_numeric($resupload) && $resupload > 0) { //$mesg = '
'.$langs->trans("FileTransferComplete").'
'; //print_r($_FILES); $result=$ecmdir->changeNbOfFiles('+'); } else { $langs->load("errors"); if ($resupload < 0) // Unknown error { $mesg = '
'.$langs->trans("ErrorFileNotUploaded").'
'; } else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus { $mesg = '
'.$langs->trans("ErrorFileIsInfectedWithAVirus").'
'; } else // Known error { $mesg = '
'.$langs->trans($resupload).'
'; } } } else { $langs->load("errors"); $mesg = '
'.$langs->trans("ErrorFailToCreateDir",$upload_dir).'
'; } } // Add directory if (GETPOST("action") == 'add' && $user->rights->ecm->setup) { $ecmdir->ref = 'NOTUSEDYET'; $ecmdir->label = GETPOST("label"); $ecmdir->description = GETPOST("desc"); $id = $ecmdir->create($user); if ($id > 0) { Header("Location: ".$_SERVER["PHP_SELF"]); exit; } else { $mesg='
Error '.$langs->trans($ecmdir->error).'
'; $action = "create"; } } // Remove file if (GETPOST('action') == 'confirm_deletefile' && GETPOST('confirm') == 'yes') { $result=$ecmdir->fetch(GETPOST("section")); if (! $result > 0) { dol_print_error($db,$ecmdir->error); exit; } $relativepath=$ecmdir->getRelativePath(); $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; $file = $upload_dir . "/" . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). $result=dol_delete_file($file); $mesg = '
'.$langs->trans("FileWasRemoved").'
'; $result=$ecmdir->changeNbOfFiles('-'); $action='file_manager'; } // Remove directory if ($action == 'confirm_deletesection' && GETPOST('confirm') == 'yes') { $result=$ecmdir->delete($user); $mesg = '
'.$langs->trans("ECMSectionWasRemoved", $ecmdir->label).'
'; } // Refresh directory view if ($action == 'refreshmanual') { $diroutputslash=str_replace('\\','/',$conf->ecm->dir_output); $diroutputslash.='/'; // Scan directory tree on disk $disktree=dol_dir_list($conf->ecm->dir_output,'directories',1,'','','','',0); // Scan directory tree in database $sqltree=$ecmdirstatic->get_full_arbo(0); $adirwascreated=0; // Now we compare both trees to complete missing trees into database //var_dump($disktree); //var_dump($sqltree); foreach($disktree as $dirdesc) { $dirisindatabase=0; foreach($sqltree as $dirsqldesc) { if ($conf->ecm->dir_output.'/'.$dirsqldesc['fullrelativename'] == $dirdesc['fullname']) { $dirisindatabase=1; break; } } if (! $dirisindatabase) { $txt="Directory found on disk ".$dirdesc['fullname'].", not found into database so we add it"; dol_syslog($txt); //print $txt."
\n"; // We must first find the fk_parent of directory to create $dirdesc['fullname'] $fk_parent=-1; $relativepathmissing=str_replace($diroutputslash,'',$dirdesc['fullname']); $relativepathtosearchparent=$relativepathmissing; //dol_syslog("Try to find parent id for directory ".$relativepathtosearchparent); if (preg_match('/\//',$relativepathtosearchparent)) //while (preg_match('/\//',$relativepathtosearchparent)) { $relativepathtosearchparent=preg_replace('/\/[^\/]*$/','',$relativepathtosearchparent); $txt="Is relative parent path ".$relativepathtosearchparent." for ".$relativepathmissing." found in sql tree ?"; dol_syslog($txt); //print $txt." -> "; $parentdirisindatabase=0; foreach($sqltree as $dirsqldesc) { if ($dirsqldesc['fullrelativename'] == $relativepathtosearchparent) { $parentdirisindatabase=$dirsqldesc['id']; break; } } if ($parentdirisindatabase > 0) { dol_syslog("Yes with id ".$parentdirisindatabase); //print "Yes with id ".$parentdirisindatabase."
\n"; $fk_parent=$parentdirisindatabase; //break; // We found parent, we can stop the while loop } else { dol_syslog("No"); //print "No
\n"; } } else { $fk_parent=0; // Parent is root } if ($fk_parent >= 0) { $ecmdirtmp=new EcmDirectory($db); $ecmdirtmp->ref = 'NOTUSEDYET'; $ecmdirtmp->label = basename($dirdesc['fullname']); $ecmdirtmp->description = ''; $ecmdirtmp->fk_parent = $fk_parent; $txt="We create directory ".$ecmdirtmp->label." with parent ".$fk_parent; dol_syslog($txt); //print $txt."
\n"; $id = $ecmdirtmp->create($user); if ($id > 0) { $newdirsql=array('id'=>$id, 'id_mere'=>$ecmdirtmp->fk_parent, 'label'=>$ecmdirtmp->label, 'description'=>$ecmdirtmp->description, 'fullrelativename'=>$relativepathmissing); $sqltree[]=$newdirsql; // We complete fulltree for following loops //var_dump($sqltree); $adirwascreated=1; } } else { $txt="Parent of ".$dirdesc['fullname']." not found"; dol_syslog($txt); //print $txt."
\n"; } } } // If a directory was added, the fulltree array is not correctly completed and sorted, so we clean // it to be sure that fulltree array is not used without reloading it. if ($adirwascreated) $sqltree=null; } /******************************************************************* * View ********************************************************************/ //print "xx".$_SESSION["dol_screenheight"]; $maxheightwin=(isset($_SESSION["dol_screenheight"]) && $_SESSION["dol_screenheight"] > 500)?($_SESSION["dol_screenheight"]-166):660; $morecss=" "; $morejs=" "; llxHeader($morecss.$morejs,$langs->trans("ECM"),'','','','','','',0,0); // Ajout rubriques automatiques $rowspan=0; $sectionauto=array(); 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")); } 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->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'=>'order_supplier', 'test'=>$conf->fournisseur->enabled, 'label'=>$langs->trans("SuppliersOrders"), 'desc'=>$langs->trans("ECMDocsByOrders")); } if ($conf->fournisseur->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'invoice_supplier', 'test'=>$conf->fournisseur->enabled, 'label'=>$langs->trans("SuppliersInvoices"), 'desc'=>$langs->trans("ECMDocsByInvoices")); } if ($conf->tax->enabled) { $rowspan++; $sectionauto[]=array('level'=>1, 'module'=>'tax', 'test'=>$conf->tax->enabled, 'label'=>$langs->trans("SocialContributions"), 'desc'=>$langs->trans("ECMDocsBySocialContributions")); } //*********************** // List //*********************** print_fiche_titre($langs->trans("ECMArea").' - '.$langs->trans("ECMFileManager")); print $langs->trans("ECMAreaDesc")."
"; print $langs->trans("ECMAreaDesc2")."
"; print "
\n"; // Confirm remove file if ($action == 'delete') { $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$_REQUEST["section"].'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1); if ($ret == 'html') print '
'; } dol_htmloutput_mesg($mesg); // Toolbar //$head = ecm_prepare_head_fm($fac); //dol_fiche_head($head, 'file_manager', '', 1); //$conf->use_javascript_ajax=0; if ($conf->use_javascript_ajax) { ?>
'; // Toolbar print ''; } // Show button to create a directory //if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$action)) //{ if ($user->rights->ecm->setup) { print ''; //print $langs->trans('ECMAddSection'); print ''; print ''; } else { print ''; //print $langs->trans('ECMAddSection'); print ''; print ''; } //} // Show button to refresh listing print ''; print ''; print ''; if ($conf->use_javascript_ajax) { ?>
'; print ''; } // End of page $db->close(); llxFooter(); ?>