*
* 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 3 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 resource/add.php
* \ingroup resource
* \brief Page to manage resource object
* Initialy built by build_class_from_table on 2013-07-24 16:03
*/
// Change this following line to use the correct relative path (../, ../../, etc)
$res=0;
$res=@include("../main.inc.php"); // For root directory
if (! $res) $res=@include("../../main.inc.php"); // For "custom" directory
if (! $res) die("Include of main fails");
require_once 'class/resource.class.php';
require_once 'class/html.formresource.class.php';
// Load traductions files required by page
$langs->load("resource");
$langs->load("companies");
$langs->load("other");
$langs->load("resource@resource");
// Get parameters
$id = GETPOST('id','int');
$action = GETPOST('action','alpha');
$cancel = GETPOST('cancel','alpha');
if (empty($sortorder)) $sortorder="DESC";
if (empty($sortfield)) $sortfield="t.rowid";
if (empty($arch)) $arch = 0;
if ($page == -1) {
$page = 0 ;
}
$limit = $conf->global->limit;
$offset = $limit * $page ;
$pageprev = $page - 1;
$pagenext = $page + 1;
// Protection if external user
if ($user->societe_id > 0)
{
accessforbidden();
}
$object = new Resource($db);
if ($action == 'confirm_add_resource')
{
if (! $cancel)
{
$error='';
$ref=GETPOST('ref','alpha');
$description=GETPOST('description','alpha');
$fk_code_type_resource=GETPOST('fk_code_type_resource','alpha');
if (empty($ref))
{
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref"));
setEventMessage($mesg, 'errors');
$error++;
}
if (! $error)
{
$object=new Resource($db);
$object->ref=$ref;
$object->description=$description;
$object->fk_code_type_resource=$fk_code_type_resource;
$result=$object->create($user);
if ($result > 0)
{
// Creation OK
$db->commit();
setEventMessage($langs->trans('ResourceCreatedWithSuccess'));
Header("Location: card.php?id=" . $object->id);
return;
}
else
{
// Creation KO
setEventMessage($object->error, 'errors');
$action = '';
}
}
else
{
$action = '';
}
}
else
{
Header("Location: list.php");
}
}
/*
* View
*
*/
$form=new Form($db);
$formresource = new FormResource($db);
if (! $action)
{
$pagetitle=$langs->trans('AddResource');
llxHeader('',$pagetitle,'');
print_fiche_titre($pagetitle,'','resource.png@resource');
print '
';
}
// End of page
llxFooter();
$db->close();