Merge pull request #2086 from aspangaro/3.7-patch1

Patch module resource
This commit is contained in:
Laurent Destailleur 2014-11-24 00:58:41 +01:00
commit ca1a21012e
6 changed files with 81 additions and 59 deletions

View File

@ -260,6 +260,12 @@ source_file = htdocs/langs/en_US/propal.lang
source_lang = en_US source_lang = en_US
type = MOZILLAPROPERTIES type = MOZILLAPROPERTIES
[dolibarr.resource]
file_filter = htdocs/langs/<lang>/resource.lang
source_file = htdocs/langs/en_US/resource.lang
source_lang = en_US
type = MOZILLAPROPERTIES
[dolibarr.salaries] [dolibarr.salaries]
file_filter = htdocs/langs/<lang>/salaries.lang file_filter = htdocs/langs/<lang>/salaries.lang
source_file = htdocs/langs/en_US/salaries.lang source_file = htdocs/langs/en_US/salaries.lang

View File

@ -32,7 +32,7 @@ if( (array) $linked_resources && count($linked_resources) > 0)
print '<div class="tagtd">'.$langs->trans('Resource').'</div>'; print '<div class="tagtd">'.$langs->trans('Resource').'</div>';
print '<div class="tagtd">'.$langs->trans('Busy').'</div>'; print '<div class="tagtd">'.$langs->trans('Busy').'</div>';
print '<div class="tagtd">'.$langs->trans('Mandatory').'</div>'; print '<div class="tagtd">'.$langs->trans('Mandatory').'</div>';
print '<div class="tagtd">'.$langs->trans('Edit').'</div>'; print '<div class="tagtd">'.$langs->trans('Action').'</div>';
print '</form>'; print '</form>';
//print '</div>'; //print '</div>';
@ -86,8 +86,13 @@ if( (array) $linked_resources && count($linked_resources) > 0)
print '</div>'; print '</div>';
print '<div class="tagtd">'; print '<div class="tagtd">';
print '<a href="'.$_SERVER['PHP_SELF'].'?action=delete_resource&element='.$element.'&element_id='.$element_id.'&lineid='.$linked_resource['rowid'].'">'.$langs->trans('Delete').'</a>'; print '<a href="'.$_SERVER['PHP_SELF'].'?mode=edit&resource_type='.$linked_resource['resource_type'].'&element='.$element.'&element_id='.$element_id.'&lineid='.$linked_resource['rowid'].'">';
print '<a href="'.$_SERVER['PHP_SELF'].'?mode=edit&resource_type='.$linked_resource['resource_type'].'&element='.$element.'&element_id='.$element_id.'&lineid='.$linked_resource['rowid'].'">'.$langs->trans('Edit').'</a>'; print img_edit();
print '</a>';
print '&nbsp;';
print '<a href="'.$_SERVER['PHP_SELF'].'?action=delete_resource&element='.$element.'&element_id='.$element_id.'&lineid='.$linked_resource['rowid'].'">';
print img_delete();
print '</a>';
print '</div>'; print '</div>';
print '</div>'; print '</div>';

View File

@ -32,7 +32,7 @@ if (! $res) die("Include of main fails");
require_once 'class/resource.class.php'; require_once 'class/resource.class.php';
require_once 'class/html.formresource.class.php'; require_once 'class/html.formresource.class.php';
// Load traductions files requiredby by page // Load traductions files required by page
$langs->load("resource"); $langs->load("resource");
$langs->load("companies"); $langs->load("companies");
$langs->load("other"); $langs->load("other");
@ -41,6 +41,7 @@ $langs->load("resource@resource");
// Get parameters // Get parameters
$id = GETPOST('id','int'); $id = GETPOST('id','int');
$action = GETPOST('action','alpha'); $action = GETPOST('action','alpha');
$cancel = GETPOST('cancel','alpha');
if (empty($sortorder)) $sortorder="DESC"; if (empty($sortorder)) $sortorder="DESC";
if (empty($sortfield)) $sortfield="t.rowid"; if (empty($sortfield)) $sortfield="t.rowid";
if (empty($arch)) $arch = 0; if (empty($arch)) $arch = 0;
@ -65,57 +66,64 @@ $object = new Resource($db);
if ($action == 'confirm_add_resource') if ($action == 'confirm_add_resource')
{ {
$error=''; if (! $cancel)
$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")); $error='';
setEventMessage($mesg, 'errors');
$error++;
}
if (! $error) $ref=GETPOST('ref','alpha');
{ $description=GETPOST('description','alpha');
$object=new Resource($db); $fk_code_type_resource=GETPOST('fk_code_type_resource','alpha');
$object->ref=$ref;
$object->description=$description;
$object->fk_code_type_resource=$fk_code_type_resource;
$result=$object->create($user); if (empty($ref))
if ($result > 0)
{ {
// Creation OK $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref"));
$db->commit(); setEventMessage($mesg, 'errors');
setEventMessage($langs->trans('ResourceCreatedWithSuccess')); $error++;
Header("Location: card.php?id=" . $object->id); }
return;
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 else
{ {
// Creation KO
setEventMessage($object->error, 'errors');
$action = ''; $action = '';
} }
} }
else else
{ {
$action = ''; Header("Location: list.php");
} }
} }
/*************************************************** /*
* VIEW * View
* *
****************************************************/ */
$form=new Form($db); $form=new Form($db);
$formresource = new FormResource($db); $formresource = new FormResource($db);
if ( !$action ) if (! $action)
{ {
$pagetitle=$langs->trans('AddResource'); $pagetitle=$langs->trans('AddResource');
llxHeader('',$pagetitle,''); llxHeader('',$pagetitle,'');
@ -161,8 +169,10 @@ if ( !$action )
print '</table>'; print '</table>';
echo '<div style="text-align: center">', echo '<br><div align="center">',
' <input type="submit" class="button" name="" value="'.$langs->trans('Save').'" />', '<input type="submit" class="button" name="add" value="'.$langs->trans('Save').'" />',
'&nbsp;',
'<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'" />',
'</div>'; '</div>';
print '</form>'; print '</form>';

View File

@ -139,7 +139,7 @@ if ( $object->fetch($id) > 0 )
/*--------------------------------------- /*---------------------------------------
* Edit object * Edit object
*/ */
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">'; print '<input type="hidden" name="action" value="update">';
@ -171,7 +171,7 @@ if ( $object->fetch($id) > 0 )
} }
else else
{ {
// Confirmation suppression resource line // Confirm deleting resource line
if ($action == 'delete') if ($action == 'delete')
{ {
print $form->formconfirm("card.php?&id=".$id,$langs->trans("DeleteResource"),$langs->trans("ConfirmDeleteResource"),"confirm_delete_resource",'','',1); print $form->formconfirm("card.php?&id=".$id,$langs->trans("DeleteResource"),$langs->trans("ConfirmDeleteResource"),"confirm_delete_resource",'','',1);
@ -228,9 +228,9 @@ if ( $object->fetch($id) > 0 )
print '</div>'; print '</div>';
} }
} }
if ($action != "delete" ) if ($action != "delete" && $action != "edit")
{ {
// Edit resource // Delete resource
if($user->rights->resource->delete) if($user->rights->resource->delete)
{ {
print '<div class="inline-block divButAction">'; print '<div class="inline-block divButAction">';

View File

@ -1,6 +1,5 @@
<?php <?php
/* Module to manage locations, buildings, floors and rooms into Dolibarr ERP/CRM /* Copyright (C) 2013 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2013 Jean-François Ferry <jfefe@aternatik.fr>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -32,7 +31,7 @@ require 'class/resource.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
// Load traductions files requiredby by page // Load traductions files requiredby by page
$langs->load("resource@resource"); $langs->load("resource");
$langs->load("other"); $langs->load("other");
// Get parameters // Get parameters
@ -70,8 +69,9 @@ $resource_id = GETPOST('fk_resource','int');
$resource_type = GETPOST('resource_type','alpha'); $resource_type = GETPOST('resource_type','alpha');
$busy = GETPOST('busy','int'); $busy = GETPOST('busy','int');
$mandatory = GETPOST('mandatory','int'); $mandatory = GETPOST('mandatory','int');
$cancel = GETPOST('cancel','alpha');
if($action == 'add_element_resource' && !GETPOST('cancel')) if($action == 'add_element_resource' && ! $cancel)
{ {
$objstat = fetchObjectByElement($element_id,$element); $objstat = fetchObjectByElement($element_id,$element);
$res = $objstat->add_element_resource($resource_id,$resource_type,$busy,$mandatory); $res = $objstat->add_element_resource($resource_id,$resource_type,$busy,$mandatory);
@ -251,9 +251,6 @@ else
foreach ($object->available_resources as $modresources => $resources) foreach ($object->available_resources as $modresources => $resources)
{ {
$langs->load($resources);
//print '<h2>'.$modresources.'</h2>';
$resources=(array) $resources; // To be sure $resources is an array $resources=(array) $resources; // To be sure $resources is an array
foreach($resources as $resource_obj) foreach($resources as $resource_obj)
{ {
@ -301,7 +298,7 @@ else
{ {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
print '<div class="inline-block divButAction">'; print '<div class="inline-block divButAction">';
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?mode=add&resource_type='.$resource_obj.'&element='.$element.'&element_id='.$element_id.'">Add resource</a>'; print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?mode=add&resource_type='.$resource_obj.'&element='.$element.'&element_id='.$element_id.'">'.$langs->trans('AddResource').'</a>';
print '</div>'; print '</div>';
print '</div>'; print '</div>';
} }

View File

@ -1,6 +1,5 @@
<?php <?php
/* Module to manage resources into Dolibarr ERP/CRM /* Copyright (C) 2013-2014 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2013-2014 Jean-François Ferry <jfefe@aternatik.fr>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -116,7 +115,7 @@ else
print_liste_field_titre($langs->trans('Id'),$_SERVER['PHP_SELF'],'t.rowid','',$param,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans('Id'),$_SERVER['PHP_SELF'],'t.rowid','',$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans('Ref'),$_SERVER['PHP_SELF'],'t.ref','',$param,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans('Ref'),$_SERVER['PHP_SELF'],'t.ref','',$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans('ResourceType'),$_SERVER['PHP_SELF'],'ty.code','',$param,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans('ResourceType'),$_SERVER['PHP_SELF'],'ty.code','',$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans('Edit')); print_liste_field_titre($langs->trans('Action'),"","","","",'width="60" align="center"',"","");
print '</tr>'; print '</tr>';
foreach ($object->lines as $resource) foreach ($object->lines as $resource)
@ -128,7 +127,7 @@ else
$style='style="background: orange;"'; $style='style="background: orange;"';
print '<tr '.$bc[$var].' '.$style.'><td>'; print '<tr '.$bc[$var].' '.$style.'><td>';
print $resource->id; print '<a href="./card.php?id='.$resource->id.'">'.$resource->id.'</a>';
print '</td>'; print '</td>';
print '<td>'; print '<td>';
@ -139,9 +138,14 @@ else
print $resource->type_label; print $resource->type_label;
print '</td>'; print '</td>';
print '<td>'; print '<td align="center">';
print '<a href="card.php?id='.$resource->id.'">'.$langs->trans('View').'</a> '; print '<a href="./card.php?action=update&id='.$resource->id.'">';
print '<a href="card.php?action=edit&id='.$resource->id.'">'.$langs->trans('Edit').'</a>'; print img_edit();
print '</a>';
print '&nbsp;';
print '<a href="./card.php?action=delete&id='.$resource->id.'">';
print img_delete();
print '</a>';
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';