diff --git a/htdocs/core/lib/resource.lib.php b/htdocs/core/lib/resource.lib.php new file mode 100644 index 00000000000..c516485ed9d --- /dev/null +++ b/htdocs/core/lib/resource.lib.php @@ -0,0 +1,44 @@ + + * + * 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 lib/resource.lib.php + * \ingroup resource + * \brief This file is library for resource module + */ + +function resourcePrepareHead($object) +{ + global $langs, $conf, $user; + $h = 0; + $head = array(); + + $head[$h][0] = dol_buildpath('/resource/card.php',1).'?id='.$object->id; + $head[$h][1] = $langs->trans("ResourceCard"); + $head[$h][2] = 'resource'; + $h++; + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab + complete_head_from_modules($conf,$langs,$object,$head,$h,'resource'); + + + return $head; +} diff --git a/htdocs/langs/en_US/resource.lang b/htdocs/langs/en_US/resource.lang index f1712db18c7..ea2bdba1baa 100755 --- a/htdocs/langs/en_US/resource.lang +++ b/htdocs/langs/en_US/resource.lang @@ -31,4 +31,5 @@ ResourceSingular=Resource ResourceName=Resource name ResourceType=Type of resource -DictionaryResourceType=Type of resources \ No newline at end of file +DictionaryResourceType=Type of resources +ResourceCard=Card \ No newline at end of file diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php new file mode 100755 index 00000000000..65d00fd901b --- /dev/null +++ b/htdocs/resource/card.php @@ -0,0 +1,236 @@ + + * + * 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','alpha'); +$description = GETPOST('description','alpha'); +$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); + + +/******************************************************************* +* ACTIONS +* +* Put here all code to do according to value of "action" parameter +********************************************************************/ + +if ($action == 'update' && ! $_POST["cancel"] && $user->rights->resource->write ) +{ + $error=0; + + if (empty($ref)) + { + $error++; + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'
'; + } + + 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.'
'); + $action='edit'; + } + + } + else + { + setEventMessage($object->error,'errors'); + $action='edit'; + } + } + else + { + $action='edit'; + } +} + + +/*************************************************** +* VIEW +* +* Put here all code to build page +****************************************************/ +$pagetitle = $langs->trans('Card'); +llxHeader('',$pagetitle,''); + +$form = new Form($db); +$formresource = new FormResource($db); + +if ( $object->fetch($id) > 0 ) +{ + $head=resourcePrepareHead($object); + dol_fiche_head($head, 'resource', $langs->trans("ResourceSingular"),0,'resource@resource'); + + + if ($action == 'edit' ) + { + + if ( ! $user->rights->resource->write ) + accessforbidden('',0); + + /*--------------------------------------- + * Edit object + */ + print '
'; + print ''; + print ''; + print ''; + + print ''; + + // Ref + print ''; + print ''; + + // Type + print ''; + print ''; + + // Description + print ''; + print ''; + + print ''; + print '
'.$langs->trans("Ref").'
'.$langs->trans("ResourceType").''; + $ret = $formresource->select_types_resource($object->fk_code_type_resource,'fk_code_type_resource','',2); + print '
'.$langs->trans("Description").''; + print ''; + print '
'; + print '   '; + print '
'; + print '
'; + } + else + { + + /*--------------------------------------- + * View object + */ + print ''; + + // Ref + print ''; + print ''; + print ''; + print ''; + + // Resource type + print ''; + print ''; + print ''; + print ''; + + // Description + print ''; + print ''; + print ''; + print ''; + + print '
' . $langs->trans("ResourceName") . ''; + print $object->ref; + print '
' . $langs->trans("ResourceType") . ''; + print $object->type_label; + print '
' . $langs->trans("Description") . ''; + print $object->description; + 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 '
'; + print ''.$langs->trans('Edit').''; + print '
'; + } + } + } + print '
'; +} +else { + dol_print_error(); +} + + + +// End of page +llxFooter(); +$db->close(); +?> diff --git a/htdocs/resource/class/html.formresource.class.php b/htdocs/resource/class/html.formresource.class.php index bb507c98106..11a51340971 100644 --- a/htdocs/resource/class/html.formresource.class.php +++ b/htdocs/resource/class/html.formresource.class.php @@ -188,7 +188,7 @@ class FormResource } } print ''; - if ($user->admin && ! $noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); + if ($user->admin && ! $noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); } diff --git a/htdocs/resource/class/resource.class.php b/htdocs/resource/class/resource.class.php index 1ad1ead30a4..ee60393323e 100644 --- a/htdocs/resource/class/resource.class.php +++ b/htdocs/resource/class/resource.class.php @@ -46,6 +46,7 @@ class Resource extends CommonObject var $busy; var $mandatory; var $fk_user_create; + var $type_label; var $tms=''; @@ -160,8 +161,10 @@ class Resource extends CommonObject $sql.= " t.fk_code_type_resource,"; $sql.= " t.note_public,"; $sql.= " t.note_private,"; - $sql.= " t.tms"; + $sql.= " t.tms,"; + $sql.= " ty.label as type_label"; $sql.= " FROM ".MAIN_DB_PREFIX."resource as t"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_resource as ty ON ty.code=t.fk_code_type_resource"; $sql.= " WHERE t.rowid = ".$this->db->escape($id); dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); @@ -178,8 +181,8 @@ class Resource extends CommonObject $this->description = $obj->description; $this->fk_code_type_resource = $obj->fk_code_type_resource; $this->note_public = $obj->note_public; - $this->note_private = $obj->note_private; - $this->fk_user_create = $obj->fk_user_create; + $this->note_private = $obj->note_private; + $this->type_label = $obj->type_label; } $this->db->free($resql);