*
* 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 htdoc/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."/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");
// Load permissions
$user->getrights('ecm');
// Get parameters
$socid = isset($_GET["socid"])?$_GET["socid"]:'';
$section=$_GET["section"];
if (! $section) $section='misc';
$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="DESC";
if (! $sortfield) $sortfield="label";
$ecmdir = new ECMDirectory($db);
if (! empty($_GET["section"]))
{
$result=$ecmdir->fetch($_GET["section"]);
if (! $result > 0)
{
dolibarr_print_error($db,$ecmdir->error);
exit;
}
}
/*******************************************************************
* ACTIONS
*
* Put here all code to do according to value of "action" parameter
********************************************************************/
// 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);
if ($_GET["action"] == 'create')
{
//***********************
// Create
//***********************
print '';
}
if (! $_GET["action"] || $_GET["action"] == 'delete_section')
{
//***********************
// List
//***********************
print_fiche_titre($langs->trans("ECMSectionOfDocuments"));
$ecmdir->ref=$ecmdir->label;
print $langs->trans("ECMSection").': ';
print img_picto('','object_dir').' ';
print ''.$langs->trans("ECMRoot").'';
//print ' -> '.$ecmdir->getNomUrl(1).'
';
print "
";
/*
* Confirmation de la suppression d'une ligne categorie
*/
if ($_GET['action'] == 'delete_section')
{
$form->form_confirm($_SERVER["PHP_SELF"].'?section='.urldecode($_GET["section"]), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection');
print '
';
}
// Construit liste des répertoires
if ($mesg) { print $mesg."
"; }
print '';
print '';
$param='&socid='.$socid;
print_liste_field_titre($langs->trans("ECMSection"),$_SERVER["PHP_SELF"],"label","",$param,'align="left"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"","",$param,'align="left"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Description"),$_SERVER["PHP_SELF"],"description","",$param,'align="left"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("ECMCreationUser"),$_SERVER["PHP_SELF"],"fk_user_c","",$param,'align="left"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("ECMCreationDate"),$_SERVER["PHP_SELF"],"date_c","",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("ECMNbOfDocs"),$_SERVER["PHP_SELF"],"cachenbofdoc","",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Action"),$_SERVER["PHP_SELF"],"","",$param,'align="right"',$sortfield,$sortorder);
print '
';
$sql ="SELECT ed.rowid, ed.label, ed.description, ed.cachenbofdoc, ed.fk_user_c, ed.fk_user_m,";
$sql.=" ed.date_c,";
$sql.=" ed.date_m,";
$sql.=" ed.fk_parent,";
$sql.=" u.login";
$sql.=" FROM ".MAIN_DB_PREFIX."ecm_directories as ed";
$sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = ed.fk_user_c";
$sql.=" ORDER BY label";
$resql=$db->query($sql);
if ($resql)
{
$var=true;
$obj = $db->fetch_object($resql);
while ($obj)
{
$var=!$var;
$ecmdirstatic->id=$obj->rowid;
$ecmdirstatic->ref=$obj->label;
print '';
// Section
print '| ';
print $ecmdirstatic->getNomUrl(1);
print " | \n";
// Type
print '';
print $langs->trans("ECMTypeManual");
print " | \n";
// Description
print ''.dolibarr_trunc($obj->description,32).' | ';
$userstatic->id=$obj->fk_user_c;
$userstatic->nom=$obj->login;
print ''.$userstatic->getNomUrl(1).' | ';
print ''.dolibarr_print_date($obj->date_c,"dayhour").' | ';
// Nb of docs
//print ''.$obj->cachenbofdoc.' | ';
print '? | ';
print '';
echo 'rowid).'">'.img_delete().'';
print " |
\n";
$obj = $db->fetch_object($resql);
}
}
else
{
dolibarr_print_error($db);
}
// Ajout rubriques automatiques
$sectionauto=array( 0 => array('test'=>$conf->societe->enabled, 'label'=>$langs->trans("ThirdParties"), 'desc'=>$langs->trans("ECMDocsByThirdParties")),
1 => array('test'=>$conf->propal->enabled, 'label'=>$langs->trans("Proposals"), 'desc'=>$langs->trans("ECMDocsByProposals")),
2 => array('test'=>$conf->commande->enabled,'label'=>$langs->trans("Orders"), 'desc'=>$langs->trans("ECMDocsByOrders")),
3 => array('test'=>$conf->contrat->enabled, 'label'=>$langs->trans("Contracts"), 'desc'=>$langs->trans("ECMDocsByContracts")),
4 => array('test'=>$conf->facture->enabled, 'label'=>$langs->trans("Invoices"), 'desc'=>$langs->trans("ECMDocsByInvoices"))
);
foreach ($sectionauto as $key => $val)
{
if ($val['test'])
{
$var=! $var;
print '';
// Section
print '| ';
print img_picto('','object_dir').' ';
print '';
print $val['label'];
print '';
print " | \n";
// Type
print '';
print $langs->trans("ECMTypeAuto");
print " | \n";
// Description
print ''.$val['desc'].' | ';
print ' | ';
print ' | ';
print ' | ';
print ' ';
print " |
\n";
}
}
print "
";
// Fin de zone Ajax
// Actions buttons
print '';
}
// End of page
$db->close();
llxFooter('$Date$ - $Revision$');
?>