*
* 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/card.php
* \ingroup resource
* \brief Page to manage resource object
*/
// 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 DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once 'class/resource.class.php';
require_once 'class/html.formresource.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php';
// Load traductions files requiredby by page
$langs->load("resource");
$langs->load("companies");
$langs->load("other");
$langs->load("main");
// Get parameters
$id = GETPOST('id','int');
$action = GETPOST('action','alpha');
$ref = GETPOST('ref');
$description = GETPOST('description');
$confirm = GETPOST('confirm');
$fk_code_type_resource = GETPOST('fk_code_type_resource','alpha');
// Protection if external user
if ($user->societe_id > 0)
{
accessforbidden();
}
if( ! $user->rights->resource->read)
accessforbidden();
$object = new Resource($db);
$hookmanager->initHooks(array('resource_card','globalcard'));
$parameters=array('resource_id'=>$id);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook))
{
/*******************************************************************
* ACTIONS
********************************************************************/
if ($action == 'update' && ! $_POST["cancel"] && $user->rights->resource->write)
{
$error=0;
if (empty($ref))
{
$error++;
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")), 'errors');
}
if (! $error)
{
$res = $object->fetch($id);
if ( $res > 0 )
{
$object->ref = $ref;
$object->description = $description;
$object->fk_code_type_resource = $fk_code_type_resource;
$result=$object->update($user);
if ($result > 0)
{
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
}
else
{
setEventMessage($object->error, 'errors');
$action='edit';
}
}
else
{
setEventMessage($object->error,'errors');
$action='edit';
}
}
else
{
$action='edit';
}
}
if ($action == 'confirm_delete_resource' && $user->rights->resource->delete && $confirm === 'yes')
{
$res = $object->fetch($id);
if($res > 0)
{
$result = $object->delete($id);
if ($result >= 0)
{
setEventMessage($langs->trans('RessourceSuccessfullyDeleted'));
Header('Location: '.DOL_URL_ROOT.'/resource/list.php');
exit;
}
else {
setEventMessage($object->error,'errors');
}
}
else
{
setEventMessage($object->error,'errors');
}
}
}
/***************************************************
* VIEW
*
* Put here all code to build page
****************************************************/
$pagetitle = $langs->trans('ResourceCard');
llxHeader('',$pagetitle,'');
$form = new Form($db);
$formresource = new FormResource($db);
if ( $object->fetch($id) > 0 )
{
$head=resourcePrepareHead($object);
if ($action == 'edit' )
{
if ( ! $user->rights->resource->write )
accessforbidden('',0);
/*---------------------------------------
* Edit object
*/
print '
';
}
else
{
dol_fiche_head($head, 'resource', $langs->trans("ResourceSingular"),0,'resource@resource');
// Confirm deleting resource line
if ($action == 'delete')
{
print $form->formconfirm("card.php?&id=".$id,$langs->trans("DeleteResource"),$langs->trans("ConfirmDeleteResource"),"confirm_delete_resource",'','',1);
}
/*---------------------------------------
* View object
*/
print '';
print ''.$langs->trans("ResourceFormLabel_ref").' | ';
$linkback = $objet->ref.' '.$langs->trans("BackToList").'';
print $form->showrefnav($object, 'id', $linkback,1,"rowid");
print ' | ';
print '
';
// Resource type
print '';
print '' . $langs->trans("ResourceType") . ' | ';
print '';
print $object->type_label;
print ' | ';
print '
';
// Description
print '';
print '' . $langs->trans("ResourceFormLabel_description") . ' | ';
print '';
print $object->description;
print ' | ';
print '
';
print '
';
}
print '';
/*
* Boutons actions
*/
print '';
$parameters = array();
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
// modified by hook
if (empty($reshook))
{
if ($action != "edit" )
{
// Edit resource
if($user->rights->resource->write)
{
print '
';
}
}
if ($action != "delete" && $action != "edit")
{
// Delete resource
if($user->rights->resource->delete)
{
print '
';
}
}
}
print '
';
}
else {
dol_print_error();
}
// End of page
llxFooter();
$db->close();