diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 8f896969c8b..f51a2994c60 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -524,6 +524,7 @@ if ($id == 11) 'propal' => $langs->trans('Proposal'), 'commande' => $langs->trans('Order'), 'facture' => $langs->trans('Bill'), + 'resource' => $langs->trans('Resource'), // 'facture_fourn' => $langs->trans('SupplierBill'), 'fichinter' => $langs->trans('InterventionCard') ); diff --git a/htdocs/core/lib/fichinter.lib.php b/htdocs/core/lib/fichinter.lib.php index 162aca37c8a..25f8c2c98aa 100644 --- a/htdocs/core/lib/fichinter.lib.php +++ b/htdocs/core/lib/fichinter.lib.php @@ -2,6 +2,8 @@ /* Copyright (C) 2006-2007 Laurent Destailleur * Copyright (C) 2007 Rodolphe Quiedeville * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2016 Gilles Poirier + * * 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 @@ -67,6 +69,15 @@ function fichinter_prepare_head($object) // $this->tabs = array('entity:-tabname); to remove a tab complete_head_from_modules($conf,$langs,$object,$head,$h,'intervention'); + // Tab to link resources + if ($conf->resource->enabled) + { + $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=fichinter&element_id='.$object->id; + $head[$h][1] = $langs->trans("Resources"); + $head[$h][2] = 'resource'; + $h++; + } + if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) { $nbNote = 0; diff --git a/htdocs/core/lib/resource.lib.php b/htdocs/core/lib/resource.lib.php index e92d59dcac7..621cf800d99 100644 --- a/htdocs/core/lib/resource.lib.php +++ b/htdocs/core/lib/resource.lib.php @@ -1,6 +1,7 @@ + * Copyright (C) 2016 Gilles Poirier * * 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 @@ -28,7 +29,7 @@ * @param Object $object Object * @return array Array of head entries */ -function resourcePrepareHead($object) +function resource_prepare_head($object) { global $langs, $conf, $user; $h = 0; @@ -36,15 +37,50 @@ function resourcePrepareHead($object) $head[$h][0] = dol_buildpath('/resource/card.php',1).'?id='.$object->id; $head[$h][1] = $langs->trans("ResourceCard"); - $head[$h][2] = 'resource'; + $head[$h][2] = 'resource'; $h++; + if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) + { + $head[$h][0] = DOL_URL_ROOT.'/resource/contact.php?id='.$object->id; + $head[$h][1] = $langs->trans('Contact'); + $head[$h][2] = 'contact'; + $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'); + if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) + { + $nbNote = 0; + if(!empty($object->note_private)) $nbNote++; + if(!empty($object->note_public)) $nbNote++; + $head[$h][0] = DOL_URL_ROOT.'/resource/note.php?id='.$object->id; + $head[$h][1] = $langs->trans('Notes'); + if ($nbNote > 0) $head[$h][1].= ' '.$nbNote.''; + $head[$h][2] = 'note'; + $h++; + } + + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $upload_dir = $conf->resource->dir_output . "/" . dol_sanitizeFileName($object->ref); + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); + $head[$h][0] = DOL_URL_ROOT.'/resource/document.php?id='.$object->id; + $head[$h][1] = $langs->trans("Documents"); + if($nbFiles > 0) $head[$h][1].= ' '.$nbFiles.''; + $head[$h][2] = 'documents'; + $h++; + + /*$head[$h][0] = DOL_URL_ROOT.'/resource/info.php?id='.$object->id; + $head[$h][1] = $langs->trans('Info'); + $head[$h][2] = 'info'; + $h++;*/ + + complete_head_from_modules($conf,$langs,$object,$head,$h,'resource', 'remove'); return $head; } diff --git a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql index df9b7aa3450..a429ef5c7cf 100644 --- a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql +++ b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql @@ -396,3 +396,18 @@ ALTER TABLE llx_product ADD COLUMN default_vat_code varchar(10) after cost_price -- Delete old deprecated field ALTER TABLE llx_product_stock DROP COLUMN pmp; + +-- VMYSQL4.1 ALTER TABLE llx_c_type_resource CHANGE COLUMN rowid rowid integer NOT NULL AUTO_INCREMENT; + +ALTER TABLE llx_resource ADD COLUMN asset_number varchar(255) after ref; +ALTER TABLE llx_resource ADD COLUMN datec datetime DEFAULT NULL; +ALTER TABLE llx_resource ADD COLUMN date_valid datetime DEFAULT NULL; +ALTER TABLE llx_resource ADD COLUMN fk_user_author integer DEFAULT NULL; +ALTER TABLE llx_resource ADD COLUMN fk_user_modif integer DEFAULT NULL; +ALTER TABLE llx_resource ADD COLUMN fk_user_valid integer DEFAULT NULL; +ALTER TABLE llx_resource ADD COLUMN fk_statut smallint NOT NULL DEFAULT '0'; +ALTER TABLE llx_resource ADD COLUMN import_key varchar(14); +ALTER TABLE llx_resource ADD COLUMN extraparams varchar(255); + +ALTER TABLE llx_element_resources ADD COLUMN duree real; -- total duration of using ressource + diff --git a/htdocs/install/mysql/tables/llx_element_resources.sql b/htdocs/install/mysql/tables/llx_element_resources.sql index 9c67a0d52af..d619626d3d7 100644 --- a/htdocs/install/mysql/tables/llx_element_resources.sql +++ b/htdocs/install/mysql/tables/llx_element_resources.sql @@ -26,6 +26,7 @@ CREATE TABLE llx_element_resources resource_type varchar(64), -- resource or user busy integer, mandatory integer, + duree real, -- total duration of using ressource fk_user_create integer, tms timestamp )ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_resource.sql b/htdocs/install/mysql/tables/llx_resource.sql index 0d67075f1ea..afb73e9fd5f 100755 --- a/htdocs/install/mysql/tables/llx_resource.sql +++ b/htdocs/install/mysql/tables/llx_resource.sql @@ -1,5 +1,6 @@ -- Module to manage resources into Dolibarr ERP/CRM --- Copyright (C) 2013 Jean-François Ferry +-- Copyright (C) 2013 Jean-François Ferry +-- Copyright (C) 2016 Gilles Poirier -- -- 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 @@ -16,12 +17,21 @@ CREATE TABLE llx_resource ( - rowid integer AUTO_INCREMENT PRIMARY KEY, - entity integer DEFAULT 1 NOT NULL, - ref varchar(255), - description text, + rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1 NOT NULL, + ref varchar(255), + asset_number varchar(255), + description text, fk_code_type_resource varchar(32), - note_public text, - note_private text, - tms timestamp -)ENGINE=innodb; \ No newline at end of file + datec datetime DEFAULT NULL, + date_valid datetime DEFAULT NULL, + fk_user_author integer DEFAULT NULL, + fk_user_modif integer DEFAULT NULL, + fk_user_valid integer DEFAULT NULL, + fk_statut smallint NOT NULL DEFAULT '0', + note_public text, + note_private text, + import_key varchar(14), + extraparams varchar(255), -- for stock other parameters with json format + tms timestamp +)ENGINE=innodb; diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index 206c2eea644..163eeab13ce 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -152,7 +152,7 @@ $formresource = new FormResource($db); if ( $object->fetch($id) > 0 ) { - $head=resourcePrepareHead($object); + $head=resource_prepare_head($object); if ($action == 'edit' ) diff --git a/htdocs/resource/contact.php b/htdocs/resource/contact.php new file mode 100644 index 00000000000..d635ee2e1e6 --- /dev/null +++ b/htdocs/resource/contact.php @@ -0,0 +1,159 @@ + + * Copyright (C) 2007-2009 Laurent Destailleur + * Copyright (C) 2012 Juanjo Menent + * Copyright (C) 2016 Gilles Poirier + + * + * 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 htdocs/resource/contact.php + * \ingroup resource + * \brief Onglet de gestion des contacts des resources + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php'; +require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; + +$langs->load("resource"); +$langs->load("sendings"); +$langs->load("companies"); + +$id = GETPOST('id','int'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action','alpha'); + +// Security check +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'resource', $id, 'resource'); + +$object = new DolResource($db); +$result = $object->fetch($id,$ref); + + +/* + * Ajout d'un nouveau contact + */ + +if ($action == 'addcontact' && $user->rights->resource->write) +{ + if ($result > 0 && $id > 0) + { + $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int')); + $result = $object->add_contact($contactid, GETPOST('type','int'), GETPOST('source','alpha')); + } + + if ($result >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else + { + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + $langs->load("errors"); + $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"); + } else { + $mesg = $object->error; + } + + setEventMessage($mesg, 'errors'); + } +} + +// bascule du statut d'un contact +else if ($action == 'swapstatut' && $user->rights->resource->write) +{ + $result=$object->swapContactStatus(GETPOST('ligne','int')); +} + +// Efface un contact +else if ($action == 'deletecontact' && $user->rights->resource->write) +{ + $result = $object->delete_contact(GETPOST('lineid','int')); + + if ($result >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else { + dol_print_error($db); + } +} + + +/* + * View + */ + +$form = new Form($db); +$formcompany = new FormCompany($db); +$contactstatic=new Contact($db); +$userstatic=new User($db); + +llxHeader('',$langs->trans("Resource")); + +// Mode vue et edition + +if ($id > 0 || ! empty($ref)) +{ + $soc = new Societe($db); + $soc->fetch($object->socid); + + + $head = resource_prepare_head($object); + dol_fiche_head($head, 'contact', $langs->trans("ResourceSingular"), 0, 'resource@resource'); + + + /* + * Resource synthese pour rappel + */ + print ''; + + print ''; + print ''; + + // Resource type + print ''; + print ''; + print ''; + print ''; + + print '
'.$langs->trans("ResourceFormLabel_ref").''; + $linkback = $objet->ref.' '.$langs->trans("BackToList").''; + print $form->showrefnav($object, 'id', $linkback,1,"rowid"); + print '
' . $langs->trans("ResourceType") . ''; + print $object->type_label; + print '
'; + print ''; + + print '
'; + + if (! empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_USER)) $hideaddcontactforuser=1; + if (! empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_THIPARTY)) $hideaddcontactforthirdparty=1; + + $permission=1; + // Contacts lines + include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php'; +} + + +llxFooter(); +$db->close(); diff --git a/htdocs/resource/document.php b/htdocs/resource/document.php new file mode 100644 index 00000000000..a21bc88c319 --- /dev/null +++ b/htdocs/resource/document.php @@ -0,0 +1,141 @@ + + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005 Simon TOSSER + * Copyright (C) 2011-2012 Juanjo Menent + * Copyright (C) 2013 Cédric Salvador + * Copyright (C) 2016 Gilles Poirier + * + * 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 htdocs/resource/document.php + * \ingroup resource + * \brief Page des documents joints sur les resources + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; + +$langs->load("other"); +$langs->load("resource"); +$langs->load("companies"); + +$id = GETPOST('id','int'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action','alpha'); +$confirm = GETPOST('confirm','alpha'); + +// Security check +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'resource', $id, 'resource'); + + +// Get parameters +$sortfield = GETPOST('sortfield','alpha'); +$sortorder = GETPOST('sortorder','alpha'); +$page = GETPOST('page','int'); +if ($page == -1) { $page = 0; } +$offset = $conf->liste_limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if (! $sortorder) $sortorder="ASC"; +if (! $sortfield) $sortfield="name"; + + +$object = new DolResource($db); +$object->fetch($id, $ref); + +$upload_dir = $conf->resource->dir_output.'/'.dol_sanitizeFileName($object->ref); +$modulepart='resource'; + + +/* + * Actions + */ + +include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php'; + + +/* + * View + */ + +$form = new Form($db); + +llxHeader('',$langs->trans("Resource")); + +if ($object->id) +{ + $object->fetch_thirdparty(); + + $head=resource_prepare_head($object); + + dol_fiche_head($head, 'documents', $langs->trans("ResourceSingular"), 0, 'resource'); + + + // Construit liste des fichiers + $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); + $totalsize=0; + foreach($filearray as $key => $file) + { + $totalsize+=$file['size']; + } + + + print ''; + + + print ''; + print ''; + + // Resource type + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print '
'.$langs->trans("ResourceFormLabel_ref").''; + $linkback = $objet->ref.' '.$langs->trans("BackToList").''; + print $form->showrefnav($object, 'id', $linkback,1,"rowid"); + print '
' . $langs->trans("ResourceType") . ''; + print $object->type_label; + print '
'.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
'.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").'
'; + + print ''; + + $modulepart = 'dolresource'; + $permission = $user->rights->resource->write; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; + +} +else +{ + print $langs->trans("ErrorUnknown"); +} + + +llxFooter(); + +$db->close(); diff --git a/htdocs/resource/element_resource.php b/htdocs/resource/element_resource.php index 62caa43f428..59a95f6f57a 100644 --- a/htdocs/resource/element_resource.php +++ b/htdocs/resource/element_resource.php @@ -1,5 +1,6 @@ +/* Copyright (C) 2013 Jean-François Ferry + * Copyright (C) 2016 Gilles Poirier * * 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 @@ -17,8 +18,8 @@ /** * \file resource/element_resource.php - * \ingroup resource - * \brief Page to show and manage linked resources to an element + * \ingroup resource + * \brief Page to show and manage linked resources to an element */ @@ -257,6 +258,47 @@ else } } + /* + * Specific to fichinter module + */ + if ($element_id && $element == 'fichinter') + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php'; + + $fichinter = fetchObjectByElement($element_id, $element); + if (is_object($fichinter)) + { + $head=fichinter_prepare_head($fichinter); + dol_fiche_head($head, 'resource', $langs->trans("InterventionCard"),0,'intervention'); + + // Affichage fiche action en mode visu + print ''; + + $linkback = ''.$langs->trans("BackToList").''; + + // Ref + print ''; + + + // Customer + if ( is_null($fichinter->client) ) + $fichinter->fetch_thirdparty(); + + print ""; + print ''; + print "
'.$langs->trans("Ref").''; + print $form->showrefnav($fichinter, 'id', $linkback, ($user->societe_id?0:1), 'ref', 'ref', ''); + print '
".$langs->trans("Company")."'.$fichinter->client->getNomUrl(1).'
"; + + dol_fiche_end(); + } + } + + + // hook for other elements linked + $parameters=array('element'=>$element, 'element_id'=>$element_id ); + $reshook=$hookmanager->executeHooks('printElementTab',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); //print load_fiche_titre($langs->trans('ResourcesLinkedToElement'),'',''); diff --git a/htdocs/resource/list.php b/htdocs/resource/list.php index d5b56cc9781..b33bbec259e 100644 --- a/htdocs/resource/list.php +++ b/htdocs/resource/list.php @@ -149,28 +149,6 @@ else } -/* - * 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('AddResource').''; - print '
'; - } - } -} -print '
'; - llxFooter(); $db->close(); diff --git a/htdocs/resource/note.php b/htdocs/resource/note.php new file mode 100644 index 00000000000..e404a3bdef8 --- /dev/null +++ b/htdocs/resource/note.php @@ -0,0 +1,91 @@ + + * Copyright (C) 2011-2012 Juanjo Menent + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2016 Gilles Poirier + * + * 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 htdocs/resource/note.php + * \ingroup fichinter + * \brief Fiche d'information sur une resource + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php'; + +$langs->load('companies'); +$langs->load("interventions"); + +$id = GETPOST('id','int'); +$ref = GETPOST('ref', 'alpha'); +$action=GETPOST('action','alpha'); + +// Security check +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'resource', $id, 'resource'); + +$object = new DolResource($db); +$object->fetch($id,$ref); + +$permissionnote=$user->rights->resource->write; // Used by the include of actions_setnotes.inc.php + +/* + * Actions + */ + +include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once + + +/* + * View + */ + +llxHeader(); + +$form = new Form($db); + +if ($id > 0 || ! empty($ref)) +{ + $head = resource_prepare_head($object); + dol_fiche_head($head, 'note', $langs->trans('ResourceSingular'), 0, 'resource@resource'); + + print ''; + print ''; + print ''; + + // Resource type + print ''; + print ''; + print ''; + print ''; print "
'.$langs->trans("ResourceFormLabel_ref").''; + $linkback = $objet->ref.' '.$langs->trans("BackToList").''; + print $form->showrefnav($object, 'id', $linkback,1,"rowid"); + print '
' . $langs->trans("ResourceType") . ''; + print $object->type_label; + print '
"; + + print '
'; + $permission=$user->rights->resource->write; + $cssclass='titlefield'; + include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php'; + + dol_fiche_end(); +} + +llxFooter(); +$db->close();