diff --git a/htdocs/core/modules/modResource.class.php b/htdocs/core/modules/modResource.class.php index dd09b148453..148dbece597 100644 --- a/htdocs/core/modules/modResource.class.php +++ b/htdocs/core/modules/modResource.class.php @@ -227,7 +227,7 @@ class modResource extends DolibarrModules 'titre'=> 'MenuResourceAdd', 'mainmenu'=> 'tools', 'leftmenu'=> 'resource_add', - 'url'=> '/resource/add.php', + 'url'=> '/resource/card.php?action=create', 'langs'=> 'resource', 'position'=> 101, 'enabled'=> '1', diff --git a/htdocs/resource/add.php b/htdocs/resource/add.php deleted file mode 100644 index a6cd75cccf8..00000000000 --- a/htdocs/resource/add.php +++ /dev/null @@ -1,211 +0,0 @@ - - * Copyright (C) 2015 Alexandre Spangaro - * Copyright (C) 2015 Laurent Destailleur - * - * 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 - */ - -require '../main.inc.php'; - -require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php'; -require_once DOL_DOCUMENT_ROOT.'/resource/class/html.formresource.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; - -// Load traductions files required by page -$langs->load("resource"); -$langs->load("companies"); -$langs->load("other"); -$langs->load("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 DolResource($db); - -$extrafields = new ExtraFields($db); - -// fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); - -$hookmanager->initHooks(array('resource_card_add','globalcard')); -$parameters=array(); -$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)) -{ - - 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")); - setEventMessages($mesg, null, 'errors'); - $error++; - } - - if (! $error) - { - $object=new Dolresource($db); - $object->ref=$ref; - $object->description=$description; - $object->fk_code_type_resource=$fk_code_type_resource; - - // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) { - $error ++; - } - - $result=$object->create($user); - if ($result > 0) - { - // Creation OK - $db->commit(); - setEventMessages($langs->trans('ResourceCreatedWithSuccess'), null, 'mesgs'); - Header("Location: card.php?id=" . $object->id); - return; - } - else - { - // Creation KO - setEventMessages($object->error, $object->errors, '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 load_fiche_titre($pagetitle,'','title_generic'); - - print '
'; - print ''; - - dol_fiche_head(''); - - print ''; - - // Ref / label - $field = 'ref'; - print ''; - print ''; - print ''; - print ''; - - // Type - print ''; - print ''; - - // Description - $field = 'description'; - print ''; - print ''; - print ''; - print ''; - - // Other attributes - $parameters=array('objectsrc' => $objectsrc); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) - { - print $object->showOptionals($extrafields,'edit'); - } - - - print '
'; - print $langs->trans('ResourceFormLabel_'.$field); - print ''; - print ''; - print '
'.$langs->trans("ResourceType").''; - $ret = $formresource->select_types_resource($object->fk_code_type_resource, 'fk_code_type_resource', '', 2, 1); - print '
'; - print $langs->trans('ResourceFormLabel_'.$field); - print ''; - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor('description', $description, '', '200', 'dolibarr_notes', false); - $doleditor->Create(); - print '
'; - - dol_fiche_end(''); - - print '
'; - print ''; - print '     '; - print ''; - print '
'; - - print '
'; -} - - -// End of page -llxFooter(); -$db->close(); diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index 211631e3dd5..ea314688dbe 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -43,32 +43,32 @@ $langs->load("main"); // Get parameters $id = GETPOST('id','int'); $action = GETPOST('action','alpha'); +$cancel = GETPOST('cancel','alpha'); $ref = GETPOST('ref','alpha'); $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) +if ($user->socid > 0) { accessforbidden(); } -if (! $user->rights->resource->read) +if( ! $user->rights->resource->read) +{ accessforbidden(); +} $object = new Dolresource($db); -$result = $object->fetch($id, $ref); -if (! ($result > 0)) dol_print_error($db, $object->error); - $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); -$hookmanager->initHooks(array('resource_card','globalcard')); -$parameters=array('resource_id'=>$object->id); +$hookmanager->initHooks(array('resource', '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'); @@ -77,15 +77,58 @@ if (empty($reshook)) /******************************************************************* * ACTIONS ********************************************************************/ + if ($action == 'add' && $user->rights->resource->write) + { + if (! $cancel) + { + $error=''; - if ($action == 'update' && ! $_POST["cancel"] && $user->rights->resource->write) + if (empty($ref)) + { + setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")), null, 'errors'); + $action = 'create'; + } + else + { + $object->ref = $ref; + $object->description = $description; + $object->fk_code_type_resource = $fk_code_type_resource; + + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; + + $result=$object->create($user); + if ($result > 0) + { + // Creation OK + setEventMessages($langs->trans('ResourceCreatedWithSuccess'), null, 'mesgs'); + Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else + { + // Creation KO + setEventMessages($object->error, $object->errors, 'errors'); + $action = 'create'; + } + } + } + else + { + Header("Location: list.php"); + exit; + } + } + + if ($action == 'update' && ! $cancel && $user->rights->resource->write) { $error=0; if (empty($ref)) { - $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors'); + $error++; } if (! $error) @@ -112,17 +155,18 @@ if (empty($reshook)) else { setEventMessages($object->error, $object->errors, 'errors'); - $action='edit'; + $error++; } } else { setEventMessages($object->error, $object->errors, 'errors'); - $action='edit'; + $error++; } } - else + + if ($error) { $action='edit'; } @@ -159,37 +203,42 @@ if (empty($reshook)) * * Put here all code to build page ****************************************************/ - -$pagetitle = $langs->trans('ResourceCard'); -llxHeader('',$pagetitle,''); +$title = $langs->trans($action == 'create' ? 'AddResource' : 'ResourceCard'); +llxHeader('',$title,''); $form = new Form($db); $formresource = new FormResource($db); -if ($object->id > 0) +if ($action == 'create' || $object->fetch($id) > 0) { - $head=resource_prepare_head($object); + if ($action == 'create') + { + print load_fiche_titre($title,'','title_generic'); + dol_fiche_head(''); + } + else + { + $head = resource_prepare_head($object); + dol_fiche_head($head, 'resource', $title, -1, 'resource'); + } - if ($action == 'edit' ) + if ($action == 'create' || $action == 'edit') { if ( ! $user->rights->resource->write ) accessforbidden('',0); /*--------------------------------------- - * Edit object + * Create/Edit object */ - print '
'; + print ''; print ''; - print ''; - print ''; - - dol_fiche_head($head, 'resource', $langs->trans("ResourceSingular"),0,'resource'); + print ''; print ''; // Ref print ''; - print ''; + print ''; // Type print ''; @@ -200,7 +249,9 @@ if ($object->id > 0) // Description print ''; print ''; // Other attributes @@ -217,16 +268,16 @@ if ($object->id > 0) dol_fiche_end(); print '
'; - print '   '; - print ''; + print ''; + print '     '; + print ''; + print '
'; print ''; print ''; } else { - dol_fiche_head($head, 'resource', $langs->trans("ResourceSingular"), -1, 'resource'); - $formconfirm = ''; // Confirm deleting resource line @@ -296,23 +347,23 @@ if ($object->id > 0) // modified by hook if (empty($reshook)) { - if ($action != "edit" ) + if ($action != "create" && $action != "edit" ) { // Edit resource if($user->rights->resource->write) { print ''; } } - if ($action != "delete" && $action != "edit") + if ($action != "delete" && $action != "create" && $action != "edit") { // Delete resource if($user->rights->resource->delete) { print ''; } }
'.$langs->trans("ResourceFormLabel_ref").'
'.$langs->trans("ResourceType").'
'.$langs->trans("Description").''; - print ''; + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $doleditor = new DolEditor('description', ($description ? $description : $object->description), '', '200', 'dolibarr_notes', false); + $doleditor->Create(); print '