Merge pull request #1589 from aternatik/resource_core

Core integration of resource module
This commit is contained in:
Laurent Destailleur 2014-05-14 11:25:25 +02:00
commit 757d92a318
25 changed files with 3178 additions and 7 deletions

View File

@ -70,7 +70,7 @@ $hookmanager->initHooks(array('admin'));
// Put here declaration of dictionaries properties
// Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
$taborder=array(9,0,4,3,2,0,1,8,19,16,0,5,11,0,6,0,10,25,12,13,0,14,0,7,17,0,22,20,18,21,0,15,0,24,23);
$taborder=array(9,0,4,3,2,0,1,8,19,16,0,5,11,0,6,0,10,25,12,13,0,14,0,7,17,0,22,20,18,21,0,15,0,24,23,0,26);
// Name of SQL tables of dictionaries
$tabname=array();
@ -99,6 +99,7 @@ $tabname[22]= MAIN_DB_PREFIX."c_input_reason";
$tabname[23]= MAIN_DB_PREFIX."accountingaccount";
$tabname[24]= MAIN_DB_PREFIX."accounting_system";
$tabname[25]= MAIN_DB_PREFIX."c_revenuestamp";
$tabname[26]= MAIN_DB_PREFIX."c_type_resource";
// Dictionary labels
$tablib=array();
@ -127,6 +128,7 @@ $tablib[22]= "DictionarySource";
$tablib[23]= "DictionaryAccountancyplan";
$tablib[24]= "DictionaryAccountancysystem";
$tablib[25]= "DictionaryRevenueStamp";
$tablib[26]= "DictionaryResourceType";
// Requete pour extraction des donnees des dictionnaires
$tabsql=array();
@ -155,6 +157,7 @@ $tabsql[22]= "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX
$tabsql[23]= "SELECT rowid as rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number as accountancy_code, account_parent, label, active FROM ".MAIN_DB_PREFIX."accountingaccount";
$tabsql[24]= "SELECT s.rowid as rowid, pcg_version, s.fk_pays as country_id, p.code as country_code, p.libelle as pays, s.label, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s, ".MAIN_DB_PREFIX."c_pays as p WHERE s.fk_pays=p.rowid and p.active=1";
$tabsql[25]= "SELECT t.rowid, t.taux, p.libelle as country, p.code as country_code, t.fk_pays as country_id, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_revenuestamp as t, ".MAIN_DB_PREFIX."c_pays as p WHERE t.fk_pays=p.rowid";
$tabsql[26]= "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_type_resource";
// Critere de tri du dictionnaire
$tabsqlsort=array();
@ -183,6 +186,7 @@ $tabsqlsort[22]="code ASC, label ASC";
$tabsqlsort[23]="fk_pcg_version ASC, accountancy_code ASC";
$tabsqlsort[24]="pcg_version ASC";
$tabsqlsort[25]="country ASC, taux ASC";
$tabsqlsort[26]="code ASC,label ASC";
// Nom des champs en resultat de select pour affichage du dictionnaire
$tabfield=array();
@ -211,6 +215,7 @@ $tabfield[22]= "code,label";
$tabfield[23]= "fk_pcg_version,accountancy_code,account_parent,pcg_type,pcg_subtype,label";
$tabfield[24]= "pcg_version,country_id,country,label";
$tabfield[25]= "country_id,country,taux,accountancy_code_sell,accountancy_code_buy,note";
$tabfield[26]= "code,label";
// Nom des champs d'edition pour modification d'un enregistrement
$tabfieldvalue=array();
@ -239,6 +244,7 @@ $tabfieldvalue[22]= "code,label";
$tabfieldvalue[23]= "fk_pcg_version,accountancy_code,account_parent,pcg_type,pcg_subtype,label";
$tabfieldvalue[24]= "pcg_version,country,label";
$tabfieldvalue[25]= "country,taux,accountancy_code_sell,accountancy_code_buy,note";
$tabfieldvalue[26]= "code,label";
// Nom des champs dans la table pour insertion d'un enregistrement
$tabfieldinsert=array();
@ -267,6 +273,7 @@ $tabfieldinsert[22]= "code,label";
$tabfieldinsert[23]= "fk_pcg_version,account_number,account_parent,pcg_type,pcg_subtype,label";
$tabfieldinsert[24]= "pcg_version,fk_pays,label";
$tabfieldinsert[25]= "fk_pays,taux,accountancy_code_sell,accountancy_code_buy,note";
$tabfieldinsert[26]= "code,label";
// Nom du rowid si le champ n'est pas de type autoincrement
// Example: "" if id field is "rowid" and has autoincrement on
@ -297,6 +304,7 @@ $tabrowid[22]= "rowid";
$tabrowid[23]= "";
$tabrowid[24]= "";
$tabrowid[25]= "";
$tabrowid[25]= "";
// Condition to show dictionary in setup page
$tabcond=array();
@ -325,6 +333,7 @@ $tabcond[22]= (! empty($conf->commande->enabled) || ! empty($conf->propal->enabl
$tabcond[23]= (! empty($conf->global->ACCOUNTING_USEDICTTOEDIT) && ! empty($conf->accounting->enabled)); // The accountancy plan should be edited with specific pages. You can set ACCOUNTING_USEDICTTOEDIT to 1 if you want to use dictionary editor.
$tabcond[24]= (! empty($conf->global->ACCOUNTING_USEDICTTOEDIT) && ! empty($conf->accounting->enabled)); // The accountancy system should be edited with specific pages. You can set ACCOUNTING_USEDICTTOEDIT to 1 if you want to use dictionary editor.
$tabcond[25]= true;
$tabcond[26]= ! empty($conf->resource->enabled);
// List of help for fields
$tabhelp=array();
@ -353,6 +362,7 @@ $tabhelp[22] = array();
$tabhelp[23] = array();
$tabhelp[24] = array();
$tabhelp[25] = array();
$tabhelp[26] = array();
// Complete all arrays with entries found into modules
complete_dictionary_with_modules($taborder,$tabname,$tablib,$tabsql,$tabsqlsort,$tabfield,$tabfieldvalue,$tabfieldinsert,$tabrowid,$tabcond,$tabhelp);

View File

@ -3285,6 +3285,92 @@ abstract class CommonObject
print '</table>';
}
/**
* Add resources to the current object : add entry into llx_element_resources
*Need $this->element & $this->id
*
* @param int $resource_id Resource id
* @param string $resource_element Resource element
* @return int <=0 if KO, >0 if OK
*/
function add_element_resource($resource_id,$resource_element,$busy=0,$mandatory=0)
{
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources (";
$sql.= "resource_id";
$sql.= ", resource_type";
$sql.= ", element_id";
$sql.= ", element_type";
$sql.= ", busy";
$sql.= ", mandatory";
$sql.= ") VALUES (";
$sql.= $resource_id;
$sql.= ", '".$resource_element."'";
$sql.= ", '".$this->id."'";
$sql.= ", '".$this->element."'";
$sql.= ", '".$busy."'";
$sql.= ", '".$mandatory."'";
$sql.= ")";
dol_syslog(get_class($this)."::add_element_resource sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql))
{
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->lasterror();
$this->db->rollback();
return 0;
}
}
/**
* Delete a link to resource line
*
* @param int $rowid Id of resource line to delete
* @param int $element element name (for trigger) TODO: use $this->element into commonobject class
* @param int $notrigger Disable all triggers
* @return int >0 if OK, <0 if KO
*/
function delete_resource($rowid, $element, $notrigger=0)
{
global $user,$langs,$conf;
$error=0;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources";
$sql.= " WHERE rowid =".$rowid;
dol_syslog(get_class($this)."::delete_resource sql=".$sql);
if ($this->db->query($sql))
{
if (! $notrigger)
{
// Call triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers(strtoupper($element).'_DELETE_RESOURCE',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// End call triggers
}
return 1;
}
else
{
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::delete_resource error=".$this->error, LOG_ERR);
return -1;
}
}
/**
* Overwrite magic function to solve problem of cloning object that are kept as references
*

View File

@ -1656,3 +1656,125 @@ function cleanCorruptedTree($db, $tabletocleantree, $fieldfkparent)
return $totalnb;
}
}
/**
* Get an array with properties of an element
*
* @param string $element_type Element type. ex : project_task or object@modulext or object_under@module
* @return array (module, classpath, element, subelement, classfile, classname)
*/
function getElementProperties($element_type)
{
// Parse element/subelement (ex: project_task)
$module = $element = $subelement = $element_type;
// If we ask an resource form external module (instead of default path)
if (preg_match('/^([^@]+)@([^@]+)$/i',$element_type,$regs))
{
$element = $subelement = $regs[1];
$module = $regs[2];
}
//print '<br />1. element : '.$element.' - module : '.$module .'<br />';
if ( preg_match('/^([^_]+)_([^_]+)/i',$element,$regs))
{
$module = $element = $regs[1];
$subelement = $regs[2];
}
$classfile = strtolower($subelement);
$classname = ucfirst($subelement);
$classpath = $module.'/class';
// For compat
if($element_type == "action") {
$classpath = 'comm/action/class';
$subelement = 'Actioncomm';
$module = 'agenda';
}
// To work with non standard path
if ($element_type == 'facture' || $element_type == 'invoice') {
$classpath = 'compta/facture/class';
$module='facture';
$subelement='facture';
}
if ($element_type == 'commande' || $element_type == 'order') {
$classpath = 'commande/class';
$module='commande';
$subelement='commande';
}
if ($element_type == 'propal') {
$classpath = 'comm/propal/class';
}
if ($element_type == 'shipping') {
$classpath = 'expedition/class';
$subelement = 'expedition';
$module = 'expedition_bon';
}
if ($element_type == 'delivery') {
$classpath = 'livraison/class';
$subelement = 'livraison';
$module = 'livraison_bon';
}
if ($element_type == 'contract') {
$classpath = 'contrat/class';
$module='contrat';
$subelement='contrat';
}
if ($element_type == 'member') {
$classpath = 'adherents/class';
$module='adherent';
$subelement='adherent';
}
if ($element_type == 'cabinetmed_cons') {
$classpath = 'cabinetmed/class';
$module='cabinetmed';
$subelement='cabinetmedcons';
}
if ($element_type == 'fichinter') {
$classpath = 'fichinter/class';
$module='ficheinter';
$subelement='fichinter';
}
$classfile = strtolower($subelement);
$classname = ucfirst($subelement);
$element_properties = array(
'module' => $module,
'classpath' => $classpath,
'element' => $element,
'subelement' => $subelement,
'classfile' => $classfile,
'classname' => $classname
);
return $element_properties;
}
/**
* Fetch an object with element_type and its id
* Inclusion classes is automatic
*
* @param int $element_id Element id
* @param string $element_type Element type
* @return object || 0 || -1 if error
*/
function fetchObjectByElement($element_id,$element_type) {
global $conf;
global $db,$conf;
$element_prop = getElementProperties($element_type);
if (is_array($element_prop) && $conf->$element_prop['module']->enabled)
{
dol_include_once('/'.$element_prop['classpath'].'/'.$element_prop['classfile'].'.class.php');
$objectstat = new $element_prop['classname']($db);
$ret = $objectstat->fetch($element_id);
if ($ret >= 0)
{
return $objectstat;
}
}
return 0;
}

View File

@ -0,0 +1,44 @@
<?php
/* Module to manage locations, buildings, floors and rooms into Dolibarr ERP/CRM
* Copyright (C) 2013 Jean-François Ferry <jfefe@aternatik.fr>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \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;
}

View File

@ -0,0 +1,391 @@
<?php
/* Module to manage resources into Dolibarr ERP/CRM
* Copyright (C) 2013-2014 Jean-François Ferry <jfefe@aternatik.fr>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \defgroup resource Resource module
* \brief Resource module descriptor.
* \file core/modules/modResource.class.php
* \ingroup resource
* \brief Description and activation file for module Resource
*/
include_once DOL_DOCUMENT_ROOT . "/core/modules/DolibarrModules.class.php";
/**
* Description and activation class for module Resource
*/
class modResource extends DolibarrModules
{
/**
* Constructor. Define names, constants, directories, boxes, permissions
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
global $langs, $conf;
$this->db = $db;
// Id for module (must be unique).
// Use a free id here
// (See in Home -> System information -> Dolibarr for list of used modules id).
$this->numero = 110111;
// Key text used to identify module (for permissions, menus, etc...)
$this->rights_class = 'resource';
// Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
// It is used to group modules in module setup page
$this->family = "hr";
// Module label (no space allowed)
// used if translation string 'ModuleXXXName' not found
// (where XXX is value of numeric property 'numero' of module)
$this->name = preg_replace('/^mod/i', '', get_class($this));
// Module description
// used if translation string 'ModuleXXXDesc' not found
// (where XXX is value of numeric property 'numero' of module)
$this->description = "Description of module Resource";
// Possible values for version are: 'development', 'experimental' or version
$this->version = 'experimental';
// Key used in llx_const table to save module status enabled/disabled
// (where MYMODULE is value of property name of module in uppercase)
$this->const_name = 'MAIN_MODULE_' . strtoupper($this->name);
// Where to store the module in setup page
// (0=common,1=interface,2=others,3=very specific)
$this->special = 0;
// Name of image file used for this module.
// If file is in theme/yourtheme/img directory under name object_pictovalue.png
// use this->picto='pictovalue'
// If file is in module/img directory under name object_pictovalue.png
// use this->picto='pictovalue@module'
$this->picto = 'resource'; // mypicto@resource
// Defined all module parts (triggers, login, substitutions, menus, css, etc...)
// for default path (eg: /resource/core/xxxxx) (0=disable, 1=enable)
// for specific path of parts (eg: /resource/core/modules/barcode)
// for specific css file (eg: /resource/css/resource.css.php)
$this->module_parts = array(
// Set this to 1 if module has its own trigger directory
//'triggers' => 1,
// Set this to 1 if module has its own login method directory
//'login' => 0,
// Set this to 1 if module has its own substitution function file
//'substitutions' => 0,
// Set this to 1 if module has its own menus handler directory
//'menus' => 0,
// Set this to 1 if module has its own barcode directory
//'barcode' => 0,
// Set this to 1 if module has its own models directory
//'models' => 0,
// Set this to relative path of css if module has its own css file
//'css' => '/resource/css/resource.css.php',
// Set here all hooks context managed by module
'hooks' => array('actioncard','actioncommdao','resource_card','element_resource')
// Set here all workflow context managed by module
//'workflow' => array('order' => array('WORKFLOW_ORDER_AUTOCREATE_INVOICE'))
);
// Data directories to create when module is enabled.
// Example: this->dirs = array("/resource/temp");
//$this->dirs = array("/resource");
// Config pages. Put here list of php pages
// stored into resource/admin directory, used to setup module.
//$this->config_page_url = array("admin_resource.php@resource");
// Dependencies
// List of modules id that must be enabled if this module is enabled
$this->depends = array();
// List of modules id to disable if this one is disabled
$this->requiredby = array('modPlace');
// Minimum version of PHP required by module
$this->phpmin = array(5, 3);
// Minimum version of Dolibarr required by module
$this->need_dolibarr_version = array(3, 5);
$this->langfiles = array("resource@resource"); // langfiles@resource
// Constants
// List of particular constants to add when module is enabled
// (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
// Example:
$this->const = array();
// Array to add new pages in new tabs
// Example:
$this->tabs = array(
// // To add a new tab identified by code tabname1
// 'objecttype:+tabname1:Title1:langfile@resource:$user->rights->resource->read:/resource/mynewtab1.php?id=__ID__',
// // To add another new tab identified by code tabname2
// 'objecttype:+tabname2:Title2:langfile@resource:$user->rights->othermodule->read:/resource/mynewtab2.php?id=__ID__',
// // To remove an existing tab identified by code tabname
// 'objecttype:-tabname'
);
// where objecttype can be
// 'thirdparty' to add a tab in third party view
// 'intervention' to add a tab in intervention view
// 'order_supplier' to add a tab in supplier order view
// 'invoice_supplier' to add a tab in supplier invoice view
// 'invoice' to add a tab in customer invoice view
// 'order' to add a tab in customer order view
// 'product' to add a tab in product view
// 'stock' to add a tab in stock view
// 'propal' to add a tab in propal view
// 'member' to add a tab in fundation member view
// 'contract' to add a tab in contract view
// 'user' to add a tab in user view
// 'group' to add a tab in group view
// 'contact' to add a tab in contact view
// 'categories_x' to add a tab in category view
// (reresource 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
$this->tabs = array(
'action:+resources:Resources:resource:$user->rights->resource->read:/resource/element_resource.php?element=action&element_id=__ID__',
'thirdparty:+resources:Resources:resource:$user->rights->resource->read:/resource/element_resource.php?element=societe&element_id=__ID__'
);
// Boxes
// Add here list of php file(s) stored in core/boxes that contains class to show a box.
$this->boxes = array(); // Boxes list
$r = 0;
// Example:
//$this->boxes[$r][1] = "MyBox@resource";
//$r ++;
/*
$this->boxes[$r][1] = "myboxb.php";
$r++;
*/
// Permissions
$this->rights = array(); // Permission array used by this module
$r = 0;
$this->rights[$r][0] = 1101201;
$this->rights[$r][1] = 'See resources';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'read';
$r++;
$this->rights[$r][0] = 1101202;
$this->rights[$r][1] = 'Modify resources';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'write';
$r++;
$this->rights[$r][0] = 1101203;
$this->rights[$r][1] = 'Delete resources';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'delete';
$r++;
$this->rights[$r][0] = 1101204;
$this->rights[$r][1] = 'Link resources';
$this->rights[$r][3] = 0;
$this->rights[$r][4] = 'link';
$r++;
// Add here list of permission defined by
// an id, a label, a boolean and two constant strings.
// Example:
//// Permission id (must not be already used)
//$this->rights[$r][0] = 2000;
//// Permission label
//$this->rights[$r][1] = 'Permision label';
//// Permission by default for new user (0/1)
//$this->rights[$r][3] = 1;
//// In php code, permission will be checked by test
//// if ($user->rights->permkey->level1->level2)
//$this->rights[$r][4] = 'level1';
//// In php code, permission will be checked by test
//// if ($user->rights->permkey->level1->level2)
//$this->rights[$r][5] = 'level2';
//$r++;
// Main menu entries
$this->menu = array(); // List of menus to add
$r = 0;
// Menus declaration
$this->menu[$r]=array(
'fk_menu'=>'fk_mainmenu=tools',
'type'=>'left',
'titre'=> 'MenuResourceIndex',
'mainmenu'=>'tools',
'leftmenu'=> 'resource',
'url'=> '/resource/list.php',
'langs'=> 'resource',
'position'=> 100,
'enabled'=> '1',
'perms'=> '$user->rights->resource->read',
'user'=> 0
);
$r++;
$this->menu[$r++]=array(
'fk_menu'=>'fk_mainmenu=tools,fk_leftmenu=resource', //On utilise les ancres définis dans le menu parent déclaré au dessus
'type'=> 'left', // Toujours un menu gauche
'titre'=> 'MenuResourceAdd',
'mainmenu'=> 'tools',
'leftmenu'=> '', // On n'indique rien ici car on ne souhaite pas intégrer de sous-menus à ce menu
'url'=> '/resource/add.php',
'langs'=> 'resource',
'position'=> 101,
'enabled'=> '1',
'perms'=> '$user->rights->resource->read',
'target'=> '',
'user'=> 0
);
// Exports
$r = 1;
// Example:
//$this->export_code[$r]=$this->rights_class.'_'.$r;
//// Translation key (used only if key ExportDataset_xxx_z not found)
//$this->export_label[$r]='CustomersInvoicesAndInvoiceLines';
//// Condition to show export in list (ie: '$user->id==3').
//// Set to 1 to always show when module is enabled.
//$this->export_enabled[$r]='1';
//$this->export_permission[$r]=array(array("facture","facture","export"));
//$this->export_fields_array[$r]=array(
// 's.rowid'=>"IdCompany",
// 's.nom'=>'CompanyName',
// 's.address'=>'Address',
// 's.cp'=>'Zip',
// 's.ville'=>'Town',
// 's.fk_pays'=>'Country',
// 's.tel'=>'Phone',
// 's.siren'=>'ProfId1',
// 's.siret'=>'ProfId2',
// 's.ape'=>'ProfId3',
// 's.idprof4'=>'ProfId4',
// 's.code_compta'=>'CustomerAccountancyCode',
// 's.code_compta_fournisseur'=>'SupplierAccountancyCode',
// 'f.rowid'=>"InvoiceId",
// 'f.facnumber'=>"InvoiceRef",
// 'f.datec'=>"InvoiceDateCreation",
// 'f.datef'=>"DateInvoice",
// 'f.total'=>"TotalHT",
// 'f.total_ttc'=>"TotalTTC",
// 'f.tva'=>"TotalVAT",
// 'f.paye'=>"InvoicePaid",
// 'f.fk_statut'=>'InvoiceStatus',
// 'f.note'=>"InvoiceNote",
// 'fd.rowid'=>'LineId',
// 'fd.description'=>"LineDescription",
// 'fd.price'=>"LineUnitPrice",
// 'fd.tva_tx'=>"LineVATRate",
// 'fd.qty'=>"LineQty",
// 'fd.total_ht'=>"LineTotalHT",
// 'fd.total_tva'=>"LineTotalTVA",
// 'fd.total_ttc'=>"LineTotalTTC",
// 'fd.date_start'=>"DateStart",
// 'fd.date_end'=>"DateEnd",
// 'fd.fk_product'=>'ProductId',
// 'p.ref'=>'ProductRef'
//);
//$this->export_entities_array[$r]=array('s.rowid'=>"company",
// 's.nom'=>'company',
// 's.address'=>'company',
// 's.cp'=>'company',
// 's.ville'=>'company',
// 's.fk_pays'=>'company',
// 's.tel'=>'company',
// 's.siren'=>'company',
// 's.siret'=>'company',
// 's.ape'=>'company',
// 's.idprof4'=>'company',
// 's.code_compta'=>'company',
// 's.code_compta_fournisseur'=>'company',
// 'f.rowid'=>"invoice",
// 'f.facnumber'=>"invoice",
// 'f.datec'=>"invoice",
// 'f.datef'=>"invoice",
// 'f.total'=>"invoice",
// 'f.total_ttc'=>"invoice",
// 'f.tva'=>"invoice",
// 'f.paye'=>"invoice",
// 'f.fk_statut'=>'invoice',
// 'f.note'=>"invoice",
// 'fd.rowid'=>'invoice_line',
// 'fd.description'=>"invoice_line",
// 'fd.price'=>"invoice_line",
// 'fd.total_ht'=>"invoice_line",
// 'fd.total_tva'=>"invoice_line",
// 'fd.total_ttc'=>"invoice_line",
// 'fd.tva_tx'=>"invoice_line",
// 'fd.qty'=>"invoice_line",
// 'fd.date_start'=>"invoice_line",
// 'fd.date_end'=>"invoice_line",
// 'fd.fk_product'=>'product',
// 'p.ref'=>'product'
//);
//$this->export_sql_start[$r] = 'SELECT DISTINCT ';
//$this->export_sql_end[$r] = ' FROM (' . MAIN_DB_PREFIX . 'facture as f, '
// . MAIN_DB_PREFIX . 'facturedet as fd, ' . MAIN_DB_PREFIX . 'societe as s)';
//$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX
// . 'product as p on (fd.fk_product = p.rowid)';
//$this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid '
// . 'AND f.rowid = fd.fk_facture';
//$r++;
}
/**
* Function called when module is enabled.
* The init function add constants, boxes, permissions and menus
* (defined in constructor) into Dolibarr database.
* It also creates data directories
*
* @param string $options Options when enabling module ('', 'noboxes')
* @return int 1 if OK, 0 if KO
*/
public function init($options = '')
{
$sql = array();
$result = $this->loadTables();
return $this->_init($sql, $options);
}
/**
* Function called when module is disabled.
* Remove from database constants, boxes and permissions from Dolibarr database.
* Data directories are not deleted
*
* @param string $options Options when enabling module ('', 'noboxes')
* @return int 1 if OK, 0 if KO
*/
public function remove($options = '')
{
$sql = array();
return $this->_remove($sql, $options);
}
/**
* Create tables, keys and data required by module
* Files llx_table1.sql, llx_table1.key.sql llx_data.sql with create table, create keys
* and create data commands must be stored in directory /resource/sql/
* This function is called by this->init
*
* @return int <=0 if KO, >0 if OK
*/
private function loadTables()
{
return $this->_load_tables('/resource/sql/');
}
}

View File

@ -0,0 +1,45 @@
<?php
//$langs->load($resource_type);
$form = new Form($db);
if(!class_exists('FormResource'))
require_once(DOL_DOCUMENT_ROOT.'/resource/class/html.formresource.class.php');
$formresources = new FormResource($db);
$out .= '<div class="tagtable centpercent border allwidth">';
$out .= '<form class="tagtr '.($var==true?'pair':'impair').'" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$out .= '<input type="hidden" name="action" value="add_element_resource">';
$out .= '<input type="hidden" name="element" value="'.$element.'">';
$out .= '<input type="hidden" name="element_id" value="'.$element_id.'">';
$out .= '<input type="hidden" name="resource_type" value="'.$resource_type.'">';
// Place
$out .= '<div class="tagtd">'.$langs->trans("SelectResource").'</div><div>';
$events=array();
$out .= $formresources->select_resource_list('','fk_resource','',1,1,0,$events,'',2);
$out .= '</div>';
$out .= '<div class="tagtd"><label>'.$langs->trans('Busy').'</label> '.$form->selectyesno('busy',$linked_resource['busy']?1:0,1).'</div>';
$out .= '<div class="tagtd"><label>'.$langs->trans('Mandatory').'</label> '.$form->selectyesno('mandatory',$linked_resource['mandatory']?1:0,1).'</div>';
$out .= '<div class="tagtd">';
$out .='<input type="submit" id="add-resource-place" class="button" value="'.$langs->trans("Add").'"';
$out .=' />';
$out .='<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'" />';
$out .= '</div>';
$out .='</form>';
$out .= '</div>';
$out .= '<br />';
print $out;
// FIN DU TPL

View File

@ -0,0 +1,108 @@
<?php
//var_dump($linked_resources);
$form= new Form($db);
if( (array) $linked_resources && count($linked_resources) > 0)
{
$var=false;
// TODO: DEBUT DU TPL
if($mode == 'edit' )
{
print '<div class="tagtable centpercent noborder allwidth">';
print '<form class="tagtr liste_titre">';
print '<div class="tagtd">'.$langs->trans('Type').'</div>';
print '<div class="tagtd">'.$langs->trans('Resource').'</div>';
print '<div class="tagtd">'.$langs->trans('Busy').'</div>';
print '<div class="tagtd">'.$langs->trans('Mandatory').'</div>';
print '<div class="tagtd">'.$langs->trans('Edit').'</div>';
print '</form>';
//print '</div>';
}
else
{
print '<div class="tagtable centpercent noborder allwidth">';
print '<form class="tagtr liste_titre">';
print '<div class="tagtd">'.$langs->trans('Type').'</div>';
print '<div class="tagtd">'.$langs->trans('Resource').'</div>';
print '<div class="tagtd">'.$langs->trans('Busy').'</div>';
print '<div class="tagtd">'.$langs->trans('Mandatory').'</div>';
print '<div class="tagtd">'.$langs->trans('Edit').'</div>';
print '</form>';
//print '</div>';
}
foreach ($linked_resources as $linked_resource)
{
$var=!$var;
$object_resource = fetchObjectByElement($linked_resource['resource_id'],$linked_resource['resource_type']);
if($mode == 'edit' && $linked_resource['rowid'] == GETPOST('lineid'))
{
print '<form class="tagtr '.($var==true?'pair':'impair').'" action="'.$_SERVER["PHP_SELF"].'?element='.$element.'&element_id='.$element_id.'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
print '<input type="hidden" name="id" value="'.$object->id.'" />';
print '<input type="hidden" name="action" value="update_linked_resource" />';
print '<input type="hidden" name="resource_type" value="'.$resource_type.'" />';
print '<input type="hidden" name="lineid" value="'.$linked_resource['rowid'].'" />';
print '<div class="tagtd">'.$object_resource->type_label.'</div>';
print '<div class="tagtd">'.$object_resource->getNomUrl(1).'</div>';
print '<div class="tagtd">'.$form->selectyesno('busy',$linked_resource['busy']?1:0,1).'</div>';
print '<div class="tagtd">'.$form->selectyesno('mandatory',$linked_resource['mandatory']?1:0,1).'</div>';
print '<div class="tagtd"><input type="submit" class="button" value="'.$langs->trans("Update").'"></div>';
print '</form>';
}
else
{
$style='';
if($linked_resource['rowid'] == GETPOST('lineid'))
$style='style="background: orange;"';
print '<div class="tagtr '.($var==true?"pair":"impair").'" '.$style.'>';
print '<div class="tagtd">';
print $object_resource->type_label;
print '</div>';
print '<div class="tagtd">';
print $object_resource->getNomUrl(1);
print '</div class="tagtd">';
print '<div class="tagtd">';
print $linked_resource['busy']?1:0;
print '</div>';
print '<div class="tagtd">';
print $linked_resource['mandatory']?1:0;
print '</div>';
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'].'">'.$langs->trans('Edit').'</a>';
print '</div>';
print '</div>';
}
}
print '</div>';
}
else {
print '<div class="warning">'.$langs->trans('NoResourceLinked').'</div>';
}
// FIN DU TPL

View File

@ -1003,7 +1003,7 @@ create table llx_product_customer_price
datec datetime,
tms timestamp,
fk_product integer NOT NULL,
fk_soc integer NOT NULL,
fk_soc integer NOT NULL,
price double(24,8) DEFAULT 0,
price_ttc double(24,8) DEFAULT 0,
price_min double(24,8) DEFAULT 0,
@ -1011,7 +1011,7 @@ create table llx_product_customer_price
price_base_type varchar(3) DEFAULT 'HT',
tva_tx double(6,3),
recuperableonly integer NOT NULL DEFAULT '0', -- Other NPR VAT
localtax1_tx double(6,3) DEFAULT 0, -- Other local VAT 1
localtax1_tx double(6,3) DEFAULT 0, -- Other local VAT 1
localtax2_tx double(6,3) DEFAULT 0, -- Other local VAT 2
fk_user integer,
import_key varchar(14) -- Import key
@ -1038,7 +1038,7 @@ create table llx_product_customer_price_log
entity integer DEFAULT 1 NOT NULL, -- multi company id
datec datetime,
fk_product integer NOT NULL,
fk_soc integer NOT NULL,
fk_soc integer NOT NULL,
price double(24,8) DEFAULT 0,
price_ttc double(24,8) DEFAULT 0,
price_min double(24,8) DEFAULT 0,
@ -1046,7 +1046,7 @@ create table llx_product_customer_price_log
price_base_type varchar(3) DEFAULT 'HT',
tva_tx double(6,3),
recuperableonly integer NOT NULL DEFAULT 0, -- Other NPR VAT
localtax1_tx double(6,3) DEFAULT 0, -- Other local VAT 1
localtax1_tx double(6,3) DEFAULT 0, -- Other local VAT 1
localtax2_tx double(6,3) DEFAULT 0, -- Other local VAT 2
fk_user integer,
import_key varchar(14) -- Import key
@ -1091,10 +1091,10 @@ CREATE TABLE llx_payment_salary (
num_payment varchar(50),
label varchar(255),
datesp date, -- date de début de la période
dateep date, -- date de fin de la période
dateep date, -- date de fin de la période
entity integer DEFAULT 1 NOT NULL, -- multi company id
note text,
fk_bank integer,
fk_bank integer,
fk_user_creat integer,
fk_user_modif integer
)ENGINE=innodb;
@ -1155,3 +1155,45 @@ create table llx_categorie_lang
ALTER TABLE llx_categorie_lang ADD UNIQUE INDEX uk_category_lang (fk_category, lang);
ALTER TABLE llx_categorie_lang ADD CONSTRAINT fk_category_lang_fk_category FOREIGN KEY (fk_category) REFERENCES llx_categorie (rowid);
-- Resource module
CREATE TABLE llx_resource
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
entity integer,
ref varchar(255),
description text,
fk_code_type_resource varchar(32),
note_public text,
note_private text,
tms timestamp
)ENGINE=innodb;
ALTER TABLE llx_resource ADD INDEX fk_code_type_resource_idx (fk_code_type_resource);
CREATE TABLE llx_element_resources
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
resource_id integer,
resource_type varchar(64),
element_id integer,
element_type varchar(64),
busy integer,
mandatory integer,
fk_user_create integer,
tms timestamp
)ENGINE=innodb;
ALTER TABLE llx_element_resources ADD UNIQUE INDEX idx_element_resources_idx1 (resource_id, resource_type, element_id, element_type);
ALTER TABLE llx_element_resources ADD INDEX idx_element_element_element_id (element_id);
-- Pas de contraite sur resource_id et element_id car pointe sur differentes tables
create table llx_c_type_resource
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
code varchar(32) NOT NULL,
label varchar(64) NOT NULL,
active tinyint DEFAULT 1 NOT NULL
)ENGINE=innodb;
ALTER TABLE llx_c_type_resource ADD UNIQUE INDEX uk_c_type_resource_id (label, code);

View File

@ -0,0 +1,21 @@
-- ========================================================================
-- Copyright (C) 2014 Laurent Destailleur <eldy@users.sourceforge.net>
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- ========================================================================
ALTER TABLE llx_c_type_contact ADD UNIQUE INDEX uk_c_type_contact_id (element, source, code);

View File

@ -0,0 +1,34 @@
-- ========================================================================
-- Copyright (C) 2014 Jean-François Ferry <jfefe@aternatik.fr>
--
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- Defini les types de contact d'un element sert de reference pour
-- la table llx_element_contact
--
-- element est le nom de la table utilisant le type de contact.
-- i.e. contact, facture, projet, societe (sans le llx_ devant).
-- Libelle est un texte decrivant le type de contact.
-- active precise si cette valeur est 'active' ou 'archive'.
--
-- ========================================================================
create table llx_c_type_resource
(
rowid integer PRIMARY KEY,
code varchar(32) NOT NULL,
libelle varchar(64) NOT NULL,
active tinyint DEFAULT 1 NOT NULL
)ENGINE=innodb;

View File

@ -0,0 +1,23 @@
-- ============================================================================
-- Copyright (C) 2014 Jean-François Ferry <jfefe@aternatik.fr>
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- ============================================================================
ALTER TABLE llx_element_resources ADD UNIQUE INDEX idx_element_resources_idx1 (resource_id, resource_type, element_id, element_type);
ALTER TABLE llx_element_resources ADD INDEX idx_element_element_element_id (element_id);
-- Pas de contraite sur resource_id et element_id car pointe sur differentes tables

View File

@ -0,0 +1,28 @@
--
-- Copyright (C) 2013 Jean-François Ferry <jfefe@aternatik.fr>
--
-- 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 <http://www.gnu.org/licenses/>.
CREATE TABLE llx_element_resources
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
resource_id integer,
resource_type varchar(64),
element_id integer,
element_type varchar(64),
busy integer,
mandatory integer,
fk_user_create integer,
tms timestamp
)ENGINE=innodb;

View File

@ -0,0 +1,18 @@
-- Module to manage resources into Dolibarr ERP/CRM
-- Copyright (C) 2013 Jean-François Ferry <jfefe@aternatik.fr>
--
-- 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 <http://www.gnu.org/licenses/>.
ALTER TABLE llx_resource ADD INDEX fk_code_type_resource_idx (fk_code_type_resource);

View File

@ -0,0 +1,27 @@
-- Module to manage resources into Dolibarr ERP/CRM
-- Copyright (C) 2013 Jean-François Ferry <jfefe@aternatik.fr>
--
-- 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 <http://www.gnu.org/licenses/>.
CREATE TABLE llx_resource
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
entity integer,
ref varchar(255),
description text,
fk_code_type_resource varchar(32),
note_public text,
note_private text,
tms timestamp
)ENGINE=innodb;

View File

@ -0,0 +1,33 @@
MenuResourceIndex=Resources
MenuResourceAdd=New resource
MenuResourcePlanning=Resource planning
DeleteResource=Delete resource
ConfirmDeleteResourceElement=Confirm delete the resource for this element
NoResourceInDatabase=No resource in database.
NoResourceLinked=No resource linked
ResourcePageIndex=Resources list
ResourceSingular=Resource
ResourceCard=Resource card
AddResource=Add a resource
ResourceFormLabel_ref=Resource name
ResourceType=Resource type
ResourceFormLabel_description=Resource description
ResourcesLinkedToElement=Resources linked to element
RessourceLineSuccessfullyUpdated=Resource successfully updated
RessourceLineSuccessfullyDeleted=Resource successfully deleted
ShowResourcePlanning=Show resource planning
NoResourceInDatabase=No resource in database
GotoDate=Go to date
ResourceCreatedWithSuccess=Resource successfully created
RessourceLineSuccessfullyDeleted=Resource line successfully deleted
RessourceLineSuccessfullyUpdated=Resource line successfully updated
TitleResourceCard=Resource card
ConfirmDeleteResource=Confirm to delete this resource
RessourceSuccessfullyDeleted=Resource successfully deleted
DictionaryResourceType=Type of resources

View File

@ -0,0 +1,33 @@
MenuResourceIndex=Ressources
MenuResourceAdd=Nouvelle ressource
MenuResourcePlanning=Planning des Ressources
DeleteResource=Effacer resource
ConfirmDeleteResourceElement=Confirmer la suppression de la ressource pour cet élément
NoResourceInDatabase=Aucune ressource en base de données.
NoResourceLinked=Aucune ressource liée
ResourcePageIndex=Liste des Ressources
ResourceSingular=Ressource
ResourceCard=Fiche ressource
AddResource=Ajouter une ressource
ResourceFormLabel_ref=Nom de la ressource
ResourceType=Type de la ressource
ResourceFormLabel_description=Description de la ressource
ResourcesLinkedToElement=Ressources liées à l'élément
RessourceLineSuccessfullyUpdated=Ressource mise à jour
RessourceLineSuccessfullyDeleted=Resource supprimée
ShowResourcePlanning=Montrer le planning des ressources
PlanningOfAffectedResources=Planning des ressources affectées aux évènements
GotoDate=Afficher la date
ResourceCreatedWithSuccess=Ressource créee avec succès
RessourceLineSuccessfullyDeleted=Ressource supprimée avec succès
RessourceLineSuccessfullyUpdated=Ressource mise à jour
TitleResourceCard=Fiche resource
ConfirmDeleteResource=Confirmer la suppression de cette ressource?
RessourceSuccessfullyDeleted=Ressource effacée avec succès
DictionaryResourceType=Type de ressources

175
htdocs/resource/add.php Executable file
View File

@ -0,0 +1,175 @@
<?php
/* Copyright (C) 2013 Jean-François Ferry <jfefe@aternatik.fr>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file resource/add.php
* \ingroup resource
* \brief Page to manage resource object
* Initialy built by build_class_from_table on 2013-07-24 16:03
*/
// 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 'class/resource.class.php';
require_once 'class/html.formresource.class.php';
// Load traductions files requiredby by page
$langs->load("resource");
$langs->load("companies");
$langs->load("other");
$langs->load("resource@resource");
// Get parameters
$id = GETPOST('id','int');
$action = GETPOST('action','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 Resource($db);
if ($action == 'confirm_add_resource')
{
$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"));
setEventMessage($mesg, 'errors');
$error++;
}
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
{
$action = '';
}
}
/***************************************************
* VIEW
*
****************************************************/
$form=new Form($db);
$formresource = new FormResource($db);
if ( !$action )
{
$pagetitle=$langs->trans('AddResource');
llxHeader('',$pagetitle,'');
print_fiche_titre($pagetitle,'','resource.png@resource');
print '<form method="post" action="'.$_SERVER['PHP_SELF'].'" name="add_resource">';
print '<input type="hidden" name="action" value="confirm_add_resource" />';
print '<table class="border" width="100%">';
// Ref / label
$field = 'ref';
print '<tr>';
print '<td>';
print '<label for="'.$field.'" class="fieldrequired">';
print $langs->trans('ResourceFormLabel_'.$field);
print '</td>';
print '<td>';
print '<input type="text" name="'.$field.'" value="'.$$field.'" />';
print '</td>';
print '</tr>';
// Type
print '<tr><td width="20%">'.$langs->trans("ResourceType").'</td>';
print '<td>';
$ret = $formresource->select_types_resource($object->fk_code_type_resource,'fk_code_type_resource','',2);
print '</td></tr>';
// Description
$field = 'description';
print '<tr>';
print '<td>';
print '<label for="'.$field.'">';
print $langs->trans('ResourceFormLabel_'.$field);
print '</label>';
print '</td>';
print '<td>';
require_once (DOL_DOCUMENT_ROOT . "/core/class/doleditor.class.php");
$doleditor = new DolEditor($field, $$field, 160, '', '', false);
$doleditor->Create();
print '</td>';
print '</tr>';
print '</table>';
echo '<div style="text-align: center">',
' <input type="submit" class="button" name="" value="'.$langs->trans('Save').'" />',
'</div>';
print '</form>';
}
// End of page
llxFooter();
$db->close();
?>

252
htdocs/resource/card.php Executable file
View File

@ -0,0 +1,252 @@
<?php
/* Copyright (C) 2013-2014 Jean-François Ferry <jfefe@aternatik.fr>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \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');
$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'));
$parameters=array('resource_id'=>$id);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
/*******************************************************************
* 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='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'</div>';
}
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('<div class="error">'.$object->error.'</div>');
$action='edit';
}
}
else
{
setEventMessage($object->error,'errors');
$action='edit';
}
}
else
{
$action='edit';
}
}
/***************************************************
* 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);
dol_fiche_head($head, 'resource', $langs->trans("ResourceSingular"),0,'resource@resource');
if ($action == 'edit' )
{
if ( ! $user->rights->resource->write )
accessforbidden('',0);
/*---------------------------------------
* Edit object
*/
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="20%">'.$langs->trans("ResourceFormLabel_ref").'</td>';
print '<td><input size="12" name="ref" value="'.(GETPOST('ref') ? GETPOST('ref') : $object->ref).'"></td></tr>';
// Type
print '<tr><td width="20%">'.$langs->trans("ResourceType").'</td>';
print '<td>';
$ret = $formresource->select_types_resource($object->fk_code_type_resource,'fk_code_type_resource','',2);
print '</td></tr>';
// Description
print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
print '<td>';
print '<textarea name="description" cols="80" rows="'.ROWS_3.'">'.($_POST['description'] ? GETPOST('description','alpha') : $object->description).'</textarea>';
print '</td></tr>';
print '<tr><td align="center" colspan="2">';
print '<input name="update" class="button" type="submit" value="'.$langs->trans("Modify").'"> &nbsp; ';
print '<input type="submit" class="button" name="cancel" Value="'.$langs->trans("Cancel").'"></td></tr>';
print '</table>';
print '</form>';
}
else
{
// Confirmation suppression 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 '<table width="100%" class="border">';
print '<tr><td style="width:35%">'.$langs->trans("ResourceFormLabel_ref").'</td><td>';
$linkback = $objet->ref.' <a href="list.php">'.$langs->trans("BackToList").'</a>';
print $form->showrefnav($object, 'id', $linkback,1,"rowid");
print '</td>';
print '</tr>';
// Resource type
print '<tr>';
print '<td>' . $langs->trans("ResourceType") . '</td>';
print '<td>';
print $object->type_label;
print '</td>';
print '</tr>';
// Description
print '<tr>';
print '<td>' . $langs->trans("ResourceFormLabel_description") . '</td>';
print '<td>';
print $object->description;
print '</td>';
print '</tr>';
print '</table>';
}
print '</div>';
/*
* Boutons actions
*/
print '<div class="tabsAction">';
$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 '<div class="inline-block divButAction">';
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=edit" class="butAction">'.$langs->trans('Edit').'</a>';
print '</div>';
}
}
if ($action != "delete" )
{
// Edit resource
if($user->rights->resource->delete)
{
print '<div class="inline-block divButAction">';
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=delete" class="butActionDelete">'.$langs->trans('Delete').'</a>';
print '</div>';
}
}
}
print '</div>';
}
else {
dol_print_error();
}
// End of page
llxFooter();
$db->close();
?>

View File

@ -0,0 +1,167 @@
<?php
/* Copyright (C) 2013 Jean-François FERRY <jfefe@aternatik.fr>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file resource/class/actions_resource.class.php
* \brief Place module actions
*/
/**
* Actions class file for resources
*
*/
class ActionsResource
{
var $db;
var $error;
var $errors=array();
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
$this->db = $db;
}
/**
* doActions for resource module
*
* @param array $parameters parameters
* @param Object $object object
* @param string $action action
*/
function doActions($parameters, &$object, &$action)
{
global $langs,$user;
$langs->load('resource');
if (in_array('resource_card',explode(':',$parameters['context'])))
{
if($action == 'confirm_delete_resource' && !GETPOST('cancel'))
{
$res = $object->fetch(GETPOST('id'));
if($res)
{
$result = $object->delete(GETPOST('id'));
if ($result >= 0)
{
setEventMessage($langs->trans('RessourceSuccessfullyDeleted'));
Header("Location: list.php");
exit;
}
else {
setEventMessage($object->error,'errors');
}
}
else
{
setEventMessage($object->error,'errors');
}
}
}
if (in_array('element_resource',explode(':',$parameters['context'])))
{
$element_id = GETPOST('element_id','int');
$element = GETPOST('element','alpha');
$resource_type = GETPOST('resource_type');
$fk_resource = GETPOST('fk_resource');
$busy = GETPOST('busy','int');
$mandatory = GETPOST('mandatory','int');
if($action == 'add_element_resource' && !GETPOST('cancel'))
{
$objstat = fetchObjectByElement($element_id,$element);
$res = $objstat->add_element_resource($fk_resource,$resource_type,$busy,$mandatory);
if($res > 0)
{
setEventMessage($langs->trans('ResourceLinkedWithSuccess'),'mesgs');
header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$element_id);
exit;
}
else
{
setEventMessage($langs->trans('ErrorWhenLinkingResource'),'errors');
header("Location: ".$_SERVER['PHP_SELF'].'?mode=add&resource_type='.$resource_type.'&element='.$element.'&element_id='.$element_id);
exit;
}
}
// Delete a resource linked to an element
if ($action == 'confirm_delete_linked_resource' && $user->rights->resource->delete && GETPOST('confirm') == 'yes')
{
$res = $object->fetch(GETPOST('id'));
if($res)
{
$result = $object->delete_resource(GETPOST('lineid'),GETPOST('element'));
if ($result >= 0)
{
setEventMessage($langs->trans('RessourceLineSuccessfullyDeleted'));
Header("Location: ".$_SERVER['PHP_SELF']."?element=".GETPOST('element')."&element_id=".GETPOST('element_id'));
exit;
}
else {
setEventMessage($object->error,'errors');
}
}
else
{
setEventMessage($object->error,'errors');
}
}
// Update ressource
if ($action == 'update_linked_resource' && $user->rights->resource->write && !GETPOST('cancel') )
{
$res = $object->fetch_element_resource(GETPOST('lineid'));
if($res)
{
$object->busy = GETPOST('busy');
$object->mandatory = GETPOST('mandatory');
$result = $object->update_element_resource($user);
if ($result >= 0)
{
setEventMessage($langs->trans('RessourceLineSuccessfullyUpdated'));
Header("Location: ".$_SERVER['PHP_SELF']."?element=".GETPOST('element')."&element_id=".GETPOST('element_id'));
exit;
}
else {
setEventMessage($object->error,'errors');
}
}
}
}
}
}

View File

@ -0,0 +1,204 @@
<?php
/* Copyright (C) - 2013 Jean-François FERRY <jfefe@aternatik.fr>
*
* 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 2 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file place/class/html.place.class.php
* \ingroup core
* \brief Class file to manage forms into resource module
*/
require_once(DOL_DOCUMENT_ROOT ."/core/class/html.form.class.php");
/**
* Classe permettant la gestion des formulaire du module resource
*
* \remarks Utilisation: $formresource = new FormResource($db)
* \remarks $formplace->proprietes=1 ou chaine ou tableau de valeurs
*/
class FormResource
{
var $db;
var $substit=array();
var $param=array();
var $error;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
$this->db = $db;
return 1;
}
/**
* Output html form to select a resource
*
* @param string $selected Preselected type
* @param string $htmlname Name of field in form
* @param string $filter Optionnal filters criteras (example: 's.rowid <> x')
* @param int $showempty Add an empty field
* @param int $showtype Show third party type in combolist (customer, prospect or supplier)
* @param int $forcecombo Force to use combo box
* @param array $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
* @param string $filterkey Filter on key value
* @param int $outputmode 0=HTML select string, 1=Array, 2=without form tag
* @param int $limit Limit number of answers
* @return string HTML string with
*/
function select_resource_list($selected='',$htmlname='fk_resource',$filter='',$showempty=0, $showtype=0, $forcecombo=0, $event=array(), $filterkey='', $outputmode=0, $limit=20)
{
global $conf,$user,$langs;
$out='';
$outarray=array();
$resourcestat = new Resource($this->db);
$resources_used = $resourcestat->fetch_all('ASC', 't.rowid', $limit, $offset, $filter='');
if ($outputmode != 2)
{
$out = '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
}
//$out.= '<input type="hidden" name="action" value="search">';
//$out.= '<input type="hidden" name="id" value="'.$theme->id.'">';
if ($resourcestat)
{
if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo)
{
//$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
$out.= ajax_combobox($htmlname, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
}
// Construct $out and $outarray
$out.= '<select id="'.$htmlname.'" class="flat" name="'.$htmlname.'">'."\n";
if ($showempty) $out.= '<option value="-1"></option>'."\n";
$num = count($resourcestat->lines);
//var_dump($resourcestat->lines);
$i = 0;
if ($num)
{
while ( $i < $num)
{
$label=$langs->trans(ucfirst($resourcestat->lines[$i]->element)).' : ';
$label.=$resourcestat->lines[$i]->ref?$resourcestat->lines[$i]->ref:''.$resourcestat->lines[$i]->label;
if ($selected > 0 && $selected == $resourcestat->lines[$i]->id)
{
$out.= '<option value="'.$resourcestat->lines[$i]->id.'" selected="selected">'.$label.'</option>';
}
else
{
$out.= '<option value="'.$resourcestat->lines[$i]->id.'">'.$label.'</option>';
}
array_push($outarray, array('key'=>$resourcestat->lines[$i]->id, 'value'=>$resourcestat->lines[$i]->label, 'label'=>$resourcestat->lines[$i]->label));
$i++;
if (($i % 10) == 0) $out.="\n";
}
}
$out.= '</select>'."\n";
if ($outputmode != 2)
{
$out.= '<input type="submit" class="button" value="'.$langs->trans("Search").'"> &nbsp; &nbsp; ';
$out.= '</form>';
}
}
else
{
dol_print_error($this->db);
}
if ($outputmode && $outputmode != 2) return $outarray;
return $out;
}
/**
* Return html list of tickets type
*
* @param string $selected Id du type pre-selectionne
* @param string $htmlname Nom de la zone select
* @param string $filtertype To filter on field type in llx_c_ticketsup_type (array('code'=>xx,'label'=>zz))
* @param int $format 0=id+libelle, 1=code+code, 2=code+libelle, 3=id+code
* @param int $empty 1=peut etre vide, 0 sinon
* @param int $noadmininfo 0=Add admin info, 1=Disable admin info
* @param int $maxlength Max length of label
* @return void
*/
function select_types_resource($selected='',$htmlname='type_resource',$filtertype='',$format=0, $empty=0, $noadmininfo=0,$maxlength=0)
{
global $langs,$user;
$resourcestat = new Resource($this->db);
dol_syslog(get_class($this)."::select_types_resource ".$selected.", ".$htmlname.", ".$filtertype.", ".$format,LOG_DEBUG);
$filterarray=array();
if ($filtertype != '' && $filtertype != '-1') $filterarray=explode(',',$filtertype);
$resourcestat->load_cache_code_type_resource();
print '<select id="select'.$htmlname.'" class="flat select_'.$htmlname.'" name="'.$htmlname.'">';
if ($empty) print '<option value="">&nbsp;</option>';
if (is_array($resourcestat->cache_code_type_resource) && count($resourcestat->cache_code_type_resource))
{
foreach($resourcestat->cache_code_type_resource as $id => $arraytypes)
{
// We discard empty line if showempty is on because an empty line has already been output.
if ($empty && empty($arraytypes['code'])) continue;
if ($format == 0) print '<option value="'.$id.'"';
if ($format == 1) print '<option value="'.$arraytypes['code'].'"';
if ($format == 2) print '<option value="'.$arraytypes['code'].'"';
if ($format == 3) print '<option value="'.$id.'"';
// Si selected est text, on compare avec code, sinon avec id
if (preg_match('/[a-z]/i', $selected) && $selected == $arraytypes['code']) print ' selected="selected"';
elseif ($selected == $id) print ' selected="selected"';
print '>';
if ($format == 0) $value=($maxlength?dol_trunc($arraytypes['label'],$maxlength):$arraytypes['label']);
if ($format == 1) $value=$arraytypes['code'];
if ($format == 2) $value=($maxlength?dol_trunc($arraytypes['label'],$maxlength):$arraytypes['label']);
if ($format == 3) $value=$arraytypes['code'];
print $value?$value:'&nbsp;';
print '</option>';
}
}
print '</select>';
if ($user->admin && ! $noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
}
}
?>

View File

@ -0,0 +1,897 @@
<?php
/* Copyright (C) 2013 Jean-François Ferry <jfefe@aternatik.fr>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file resource/class/resource.class.php
* \ingroup resource
* \brief Class file for resource object
*/
// Put here all includes required by your class file
require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
/**
* DAO Resource object
*/
class Resource extends CommonObject
{
var $db; //!< To store db handler
var $error; //!< To return error code (or message)
var $errors=array(); //!< To return several error codes (or messages)
var $element='resource'; //!< Id that identify managed objects
var $table_element='resource'; //!< Name of table without prefix where object is stored
var $id;
var $resource_id;
var $resource_type;
var $element_id;
var $element_type;
var $busy;
var $mandatory;
var $fk_user_create;
var $type_label;
var $tms='';
/**
* Constructor
*
* @param DoliDb $db Database handler
*/
function __construct($db)
{
$this->db = $db;
return 1;
}
/**
* Create object into database
*
* @param User $user User that creates
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, Id of created object if OK
*/
function create($user, $notrigger=0)
{
global $conf, $langs;
$error=0;
// Clean parameters
if (isset($this->ref)) $this->ref=trim($this->ref);
if (isset($this->description)) $this->description=trim($this->description);
if (isset($this->fk_code_type_resource)) $this->fk_code_type_resource=trim($this->fk_code_type_resource);
if (isset($this->note_public)) $this->note_public=trim($this->note_public);
if (isset($this->note_private)) $this->note_private=trim($this->note_private);
// Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."resource(";
$sql.= " entity,";
$sql.= "ref,";
$sql.= "description,";
$sql.= "fk_code_type_resource,";
$sql.= "note_public,";
$sql.= "note_private";
$sql.= ") VALUES (";
$sql.= $conf->entity.", ";
$sql.= " ".(! isset($this->ref)?'NULL':"'".$this->db->escape($this->ref)."'").",";
$sql.= " ".(! isset($this->description)?'NULL':"'".$this->db->escape($this->description)."'").",";
$sql.= " ".(! isset($this->fk_code_type_resource)?'NULL':"'".$this->db->escape($this->fk_code_type_resource)."'").",";
$sql.= " ".(! isset($this->note_public)?'NULL':"'".$this->db->escape($this->note_public)."'").",";
$sql.= " ".(! isset($this->note_private)?'NULL':"'".$this->db->escape($this->note_private)."'");
$sql.= ")";
$this->db->begin();
dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if (! $resql) {
$error++; $this->errors[]="Error ".$this->db->lasterror();
}
if (! $error)
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."place");
if (! $notrigger)
{
//// Call triggers
//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
//$interface=new Interfaces($this->db);
//$result=$interface->run_triggers('RESOURCE_CREATE',$this,$user,$langs,$conf);
//if ($result < 0) { $error++; $this->errors=$interface->errors; }
//// End call triggers
}
}
// Commit or rollback
if ($error)
{
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg);
}
$this->db->rollback();
return -1*$error;
}
else
{
$this->db->commit();
return $this->id;
}
}
/**
* Load object in memory from database
*
* @param int $id id object
* @return int <0 if KO, >0 if OK
*/
function fetch($id)
{
global $langs;
$sql = "SELECT";
$sql.= " t.rowid,";
$sql.= " t.entity,";
$sql.= " t.ref,";
$sql.= " t.description,";
$sql.= " t.fk_code_type_resource,";
$sql.= " t.note_public,";
$sql.= " t.note_private,";
$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);
$resql=$this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->entity = $obj->entity;
$this->ref = $obj->ref;
$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->type_label = $obj->type_label;
}
$this->db->free($resql);
return $this->id;
}
else
{
$this->error="Error ".$this->db->lasterror();
dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
return -1;
}
}
/**
* Update object into database
*
* @param User $user User that modifies
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
function update($user=0, $notrigger=0)
{
global $conf, $langs;
$error=0;
// Clean parameters
if (isset($this->ref)) $this->ref=trim($this->ref);
if (isset($this->fk_code_type_resource)) $this->fk_code_type_resource=trim($this->fk_code_type_resource);
if (isset($this->description)) $this->description=trim($this->description);
// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."resource SET";
$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
$sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").",";
$sql.= " fk_code_type_resource=".(isset($this->fk_code_type_resource)?"'".$this->db->escape($this->fk_code_type_resource)."'":"null").",";
$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null')."";
$sql.= " WHERE rowid=".$this->id;
$this->db->begin();
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
if (! $error)
{
if (! $notrigger)
{
// Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger.
//// Call triggers
//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
//$interface=new Interfaces($this->db);
//$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
//if ($result < 0) { $error++; $this->errors=$interface->errors; }
//// End call triggers
}
}
// Commit or rollback
if ($error)
{
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg);
}
$this->db->rollback();
return -1*$error;
}
else
{
$this->db->commit();
return 1;
}
}
/**
* Load object in memory from database
*
* @param int $id id object
* @return int <0 if KO, >0 if OK
*/
function fetch_element_resource($id)
{
global $langs;
$sql = "SELECT";
$sql.= " t.rowid,";
$sql.= " t.resource_id,";
$sql.= " t.resource_type,";
$sql.= " t.element_id,";
$sql.= " t.element_type,";
$sql.= " t.busy,";
$sql.= " t.mandatory,";
$sql.= " t.fk_user_create,";
$sql.= " t.tms";
$sql.= " FROM ".MAIN_DB_PREFIX."element_resources as t";
$sql.= " WHERE t.rowid = ".$this->db->escape($id);
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->resource_id = $obj->resource_id;
$this->resource_type = $obj->resource_type;
$this->element_id = $obj->element_id;
$this->element_type = $obj->element_type;
$this->busy = $obj->busy;
$this->mandatory = $obj->mandatory;
$this->fk_user_create = $obj->fk_user_create;
if($obj->resource_id && $obj->resource_type)
$this->objresource = fetchObjectByElement($obj->resource_id,$obj->resource_type);
if($obj->element_id && $obj->element_type)
$this->objelement = fetchObjectByElement($obj->element_id,$obj->element_type);
}
$this->db->free($resql);
return $this->id;
}
else
{
$this->error="Error ".$this->db->lasterror();
dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
return -1;
}
}
/**
* Delete a resource object
*
* @param int $rowid Id of resource line to delete
* @param int $notrigger Disable all triggers
* @return int >0 if OK, <0 if KO
*/
function delete($rowid, $notrigger=0)
{
global $user,$langs,$conf;
$error=0;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."resource";
$sql.= " WHERE rowid =".$rowid;
dol_syslog(get_class($this)."::delete sql=".$sql);
if ($this->db->query($sql))
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources";
$sql.= " WHERE element_type='resource' AND resource_id ='".$this->db->escape($rowid)."'";
dol_syslog(get_class($this)."::delete sql=".$sql);
if ($this->db->query($sql))
{
if (! $notrigger)
{
// Call triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('RESOURCE_DELETE',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// End call triggers
}
return 1;
}
else {
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::delete_resource error=".$this->error, LOG_ERR);
return -1;
}
}
else
{
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::delete_resource error=".$this->error, LOG_ERR);
return -1;
}
}
/**
* Load resource objects into $this->lines
*
* @param string $sortorder sort order
* @param string $sortfield sort field
* @param int $limit limit page
* @param int $offset page
* @param array $filter filter output
* @return int <0 if KO, >0 if OK
*/
function fetch_all($sortorder, $sortfield, $limit, $offset, $filter='')
{
global $conf;
$sql="SELECT ";
$sql.= " t.rowid,";
$sql.= " t.entity,";
$sql.= " t.ref,";
$sql.= " t.description,";
$sql.= " t.fk_code_type_resource,";
$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.entity IN (".getEntity('resource').")";
//Manage filter
if (!empty($filter)){
foreach($filter as $key => $value) {
if (strpos($key,'date')) {
$sql.= ' AND '.$key.' = \''.$this->db->idate($value).'\'';
}
else {
$sql.= ' AND '.$key.' LIKE \'%'.$value.'%\'';
}
}
}
$sql.= " GROUP BY t.rowid";
$sql.= " ORDER BY $sortfield $sortorder ";
if ($limit) $sql.= $this->db->plimit($limit+1,$offset);
dol_syslog(get_class($this)."::fetch_all sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
if ($num)
{
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$line = new Resource($this->db);
$line->id = $obj->rowid;
$line->ref = $obj->ref;
$line->description = $obj->description;
$line->fk_code_type_resource = $obj->fk_code_type_resource;
$line->type_label = $obj->type_label;
$this->lines[$i] = $line;
$i++;
}
$this->db->free($resql);
}
return $num;
}
else
{
$this->error = $this->db->lasterror();
return -1;
}
}
/**
* Load all objects into $this->lines
*
* @param string $sortorder sort order
* @param string $sortfield sort field
* @param int $limit limit page
* @param int $offset page
* @param array $filter filter output
* @return int <0 if KO, >0 if OK
*/
function fetch_all_resources($sortorder, $sortfield, $limit, $offset, $filter='')
{
global $conf;
$sql="SELECT ";
$sql.= " t.rowid,";
$sql.= " t.resource_id,";
$sql.= " t.resource_type,";
$sql.= " t.element_id,";
$sql.= " t.element_type,";
$sql.= " t.busy,";
$sql.= " t.mandatory,";
$sql.= " t.fk_user_create,";
$sql.= " t.tms";
$sql.= ' FROM '.MAIN_DB_PREFIX .'element_resources as t ';
//$sql.= " WHERE t.entity IN (".getEntity('resource').")";
//Manage filter
if (!empty($filter)){
foreach($filter as $key => $value) {
if (strpos($key,'date')) {
$sql.= ' AND '.$key.' = \''.$this->db->idate($value).'\'';
}
else {
$sql.= ' AND '.$key.' LIKE \'%'.$value.'%\'';
}
}
}
$sql.= " GROUP BY t.rowid";
$sql.= " ORDER BY $sortfield $sortorder " . $this->db->plimit($limit+1,$offset);
dol_syslog(get_class($this)."::fetch_all sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
if ($num)
{
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$line = new Resource($this->db);
$line->id = $obj->rowid;
$line->resource_id = $obj->resource_id;
$line->resource_type = $obj->resource_type;
$line->element_id = $obj->element_id;
$line->element_type = $obj->element_type;
$line->busy = $obj->busy;
$line->mandatory = $obj->mandatory;
$line->fk_user_create = $obj->fk_user_create;
if($obj->resource_id && $obj->resource_type)
$line->objresource = $this->fetchObjectByElement($obj->resource_id,$obj->resource_type);
if($obj->element_id && $obj->element_type)
$line->objelement = $this->fetchObjectByElement($obj->element_id,$obj->element_type);
$this->lines[$i] = $line;
$i++;
}
$this->db->free($resql);
}
return $num;
}
else
{
$this->error = $this->db->lasterror();
return -1;
}
}
/**
* Load all objects into $this->lines
*
* @param string $sortorder sort order
* @param string $sortfield sort field
* @param int $limit limit page
* @param int $offset page
* @param array $filter filter output
* @return int <0 if KO, >0 if OK
*/
function fetch_all_used($sortorder, $sortfield, $limit, $offset=1, $filter='')
{
global $conf;
if ( ! $sortorder) $sortorder="ASC";
if ( ! $sortfield) $sortfield="t.rowid";
$sql="SELECT ";
$sql.= " t.rowid,";
$sql.= " t.resource_id,";
$sql.= " t.resource_type,";
$sql.= " t.element_id,";
$sql.= " t.element_type,";
$sql.= " t.busy,";
$sql.= " t.mandatory,";
$sql.= " t.fk_user_create,";
$sql.= " t.tms";
$sql.= ' FROM '.MAIN_DB_PREFIX .'element_resources as t ';
//$sql.= " WHERE t.entity IN (".getEntity('resource').")";
//Manage filter
if (!empty($filter)){
foreach($filter as $key => $value) {
if (strpos($key,'date')) {
$sql.= ' AND '.$key.' = \''.$this->db->idate($value).'\'';
}
else {
$sql.= ' AND '.$key.' LIKE \'%'.$value.'%\'';
}
}
}
$sql.= " GROUP BY t.resource_id";
$sql.= " ORDER BY " . $sortfield . " " . $sortorder . " " . $this->db->plimit($limit+1,$offset);
dol_syslog(get_class($this)."::fetch_all sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
if ($num)
{
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$line = new Resource($this->db);
$line->id = $obj->rowid;
$line->resource_id = $obj->resource_id;
$line->resource_type = $obj->resource_type;
$line->element_id = $obj->element_id;
$line->element_type = $obj->element_type;
$line->busy = $obj->busy;
$line->mandatory = $obj->mandatory;
$line->fk_user_create = $obj->fk_user_create;
$this->lines[$i] = $this->fetchObjectByElement($obj->resource_id,$obj->resource_type);
$i++;
}
$this->db->free($resql);
}
return $num;
}
else
{
$this->error = $this->db->lasterror();
return -1;
}
}
/**
* Fetch all resources available, declared by modules
* Load available resource in array $this->available_resources
*
* note : deprecated, remplaced by hook getElementResources
*
* @return int number of available resources declared by modules
*/
function fetch_all_available() {
global $conf;
if (! empty($conf->modules_parts['resources']))
{
$this->available_resources=(array) $conf->modules_parts['resources'];
return count($this->available_resources);
}
return 0;
}
/**
* Load properties id_previous and id_next
*
* @param string $filter Optional filter
* @param int $fieldid Name of field to use for the select MAX and MIN
* @return int <0 if KO, >0 if OK
*/
function load_previous_next_ref($filter,$fieldid)
{
global $conf, $user;
if (! $this->table_element)
{
dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined", LOG_ERR);
return -1;
}
// this->ismultientitymanaged contains
// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
$alias = 's';
$sql = "SELECT MAX(te.".$fieldid.")";
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as te";
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2 || ($this->element != 'societe' && empty($this->isnolinkedbythird) && empty($user->rights->societe->client->voir))) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to entity
if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc";
$sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->id)."'";
if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " AND sc.fk_user = " .$user->id;
if (! empty($filter)) $sql.=" AND ".$filter;
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2 || ($this->element != 'societe' && empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir)) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN ('.getEntity($this->element, 1).')';
//print $sql."<br>";
$result = $this->db->query($sql);
if (! $result)
{
$this->error=$this->db->error();
return -1;
}
$row = $this->db->fetch_row($result);
$this->ref_previous = $row[0];
$sql = "SELECT MIN(te.".$fieldid.")";
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as te";
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2 || ($this->element != 'societe' && empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir)) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to entity
if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc";
$sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->id)."'";
if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " AND sc.fk_user = " .$user->id;
if (! empty($filter)) $sql.=" AND ".$filter;
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2 || ($this->element != 'societe' && empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir)) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN ('.getEntity($this->element, 1).')';
// Rem: Bug in some mysql version: SELECT MIN(rowid) FROM llx_socpeople WHERE rowid > 1 when one row in database with rowid=1, returns 1 instead of null
//print $sql."<br>";
$result = $this->db->query($sql);
if (! $result)
{
$this->error=$this->db->error();
return -2;
}
$row = $this->db->fetch_row($result);
$this->ref_next = $row[0];
return 1;
}
/**
* Update element resource into database
*
* @param User $user User that modifies
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
function update_element_resource($user=0, $notrigger=0)
{
global $conf, $langs;
$error=0;
// Clean parameters
if (isset($this->resource_id)) $this->resource_id=trim($this->resource_id);
if (isset($this->resource_type)) $this->resource_type=trim($this->resource_type);
if (isset($this->element_id)) $this->element_id=trim($this->element_id);
if (isset($this->element_type)) $this->element_type=trim($this->element_type);
if (isset($this->busy)) $this->busy=trim($this->busy);
if (isset($this->mandatory)) $this->mandatory=trim($this->mandatory);
// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."element_resources SET";
$sql.= " resource_id=".(isset($this->resource_id)?"'".$this->db->escape($this->resource_id)."'":"null").",";
$sql.= " resource_type=".(isset($this->resource_type)?"'".$this->resource_type."'":"null").",";
$sql.= " element_id=".(isset($this->element_id)?$this->element_id:"null").",";
$sql.= " element_type=".(isset($this->element_type)?"'".$this->db->escape($this->element_type)."'":"null").",";
$sql.= " busy=".(isset($this->busy)?$this->busy:"null").",";
$sql.= " mandatory=".(isset($this->mandatory)?$this->mandatory:"null").",";
$sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null')."";
$sql.= " WHERE rowid=".$this->id;
$this->db->begin();
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
if (! $error)
{
if (! $notrigger)
{
// Uncomment this and change MYOBJECT to your own tag if you
// want this action calls a trigger.
// Call triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('RESOURCE_MODIFY',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// End call triggers
}
}
// Commit or rollback
if ($error)
{
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg);
}
$this->db->rollback();
return -1*$error;
}
else
{
$this->db->commit();
return 1;
}
}
/*
* Return an array with resources linked to the element
*
*
*/
function getElementResources($element,$element_id,$resource_type='')
{
// Links beetween objects are stored in this table
$sql = 'SELECT rowid, resource_id, resource_type, busy, mandatory';
$sql.= ' FROM '.MAIN_DB_PREFIX.'element_resources';
$sql.= " WHERE element_id='".$element_id."' AND resource_type='".$this->element."'";
if($resource_type)
$sql.=" AND resource_type LIKE '%".$resource_type."%'";
$sql .= ' ORDER BY resource_type';
dol_syslog(get_class($this)."::getElementResources sql=".$sql);
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$resources[$i] = array(
'rowid' => $obj->rowid,
'resource_id' => $obj->resource_id,
'resource_type'=>$obj->resource_type,
'busy'=>$obj->busy,
'mandatory'=>$obj->mandatory
);
$i++;
}
}
return $resources;
}
function fetchElementResources($element,$element_id)
{
$resources = $this->getElementResources($element,$element_id);
$i=0;
foreach($resources as $nb => $resource)
{
$this->lines[$i] = $this->fetchObjectByElement($resource['resource_id'],$resource['resource_type']);
$i++;
}
return $i;
}
/**
* Load in cache resource type code (setup in dictionary)
*
* @return int Nb lignes chargees, 0 si deja chargees, <0 si ko
*/
function load_cache_code_type_resource()
{
global $langs;
if (count($this->cache_code_type_resource)) return 0; // Cache deja charge
$sql = "SELECT rowid, code, label, active";
$sql.= " FROM ".MAIN_DB_PREFIX."c_type_resource";
$sql.= " WHERE active > 0";
$sql.= " ORDER BY rowid";
dol_syslog(get_class($this)."::load_cache_code_type_resource sql=".$sql,LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
$label=($langs->trans("ResourceTypeShort".$obj->code)!=("ResourceTypeShort".$obj->code)?$langs->trans("ResourceTypeShort".$obj->code):($obj->label!='-'?$obj->label:''));
$this->cache_code_type_resource[$obj->rowid]['code'] = $obj->code;
$this->cache_code_type_resource[$obj->rowid]['label'] = $label;
$this->cache_code_type_resource[$obj->rowid]['active'] = $obj->active;
$i++;
}
return $num;
}
else
{
dol_print_error($this->db);
return -1;
}
}
/**
* Return clicable link of object (with eventually picto)
*
* @param int $withpicto Add picto into link
* @param string $option Where point the link ('compta', 'expedition', 'document', ...)
* @param string $get_params Parametres added to url
* @return string String with URL
*/
function getNomUrl($withpicto=0,$option='', $get_params='')
{
global $langs;
$result='';
if ($option == '')
{
$lien = '<a href="'.dol_buildpath('/resource/card.php',1).'?id='.$this->id. $get_params .'">';
$picto='resource@resource';
$label=$langs->trans("ShowResource").': '.$this->ref;
}
$lienfin='</a>';
$label=$langs->trans("ShowResource").': '.$this->ref;
if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin);
if ($withpicto && $withpicto != 2) $result.=' ';
$result.=$lien.$this->ref.$lienfin;
return $result;
}
}
?>

View File

@ -0,0 +1,236 @@
<?php
/* Module to manage locations, buildings, floors and rooms into Dolibarr ERP/CRM
* Copyright (C) 2013 Jean-François Ferry <jfefe@aternatik.fr>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file resource/element_resource.php
* \ingroup resource
* \brief Page to show and manage linked resources to an element
*/
$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 'class/resource.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
// Load traductions files requiredby by page
$langs->load("resource@resource");
$langs->load("other");
// Get parameters
$id = GETPOST('id','int');
$action = GETPOST('action','alpha');
$mode = GETPOST('mode','alpha');
$lineid = GETPOST('lineid','int');
$element = GETPOST('element','alpha');
$element_id = GETPOST('element_id','int');
$resource_id = GETPOST('resource_id','int');
$resource_type = GETPOST('resource_type','alpha');
/*
$sortorder = GETPOST('sortorder','alpha');
$sortfield = GETPOST('sortfield','alpha');
$page = GETPOST('page','int');
*/
if( ! $user->rights->resource->read)
accessforbidden();
$object=new Resource($db);
$hookmanager->initHooks(array('element_resource'));
$object->available_resources = array('resource');
$parameters=array('resource_id'=>$available_resources);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
$parameters=array('resource_id'=>$resource_id);
$reshook=$hookmanager->executeHooks('getElementResources',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
/***************************************************
* VIEW
*
* Put here all code to build page
****************************************************/
$pagetitle=$langs->trans('ResourceElementPage');
llxHeader('',$pagetitle,'');
$form=new Form($db);
// Load available resource, declared by modules
$ret = count($object->available_resources);
if($ret == -1) {
dol_print_error($db,$object->error);
exit;
}
if(!$ret) {
print '<div class="warning">'.$langs->trans('NoResourceInDatabase').'</div>';
}
else
{
// Confirmation suppression resource line
if ($action == 'delete_resource')
{
print $form->formconfirm("element_resource.php?element=".$element."&element_id=".$element_id."&lineid=".$lineid,$langs->trans("DeleteResource"),$langs->trans("ConfirmDeleteResourceElement"),"confirm_delete_linked_resource",'','',1);
}
/*
* Specific to agenda module
*/
if($element_id && $element == 'action')
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
$act = fetchObjectByElement($element_id,$element);
if(is_object($act)) {
$head=actions_prepare_head($act);
dol_fiche_head($head, 'resources', $langs->trans("Action"),0,'action');
// Affichage fiche action en mode visu
print '<table class="border" width="100%">';
$linkback = '<a href="'.DOL_URL_ROOT.'/comm/action/listactions.php">'.$langs->trans("BackToList").'</a>';
// Ref
print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
print $form->showrefnav($act, 'id', $linkback, ($user->societe_id?0:1), 'id', 'ref', '');
print '</td></tr>';
// Type
if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
{
print '<tr><td>'.$langs->trans("Type").'</td><td colspan="3">'.$act->type.'</td></tr>';
}
// Title
print '<tr><td>'.$langs->trans("Title").'</td><td colspan="3">'.$act->label.'</td></tr>';
print '</table>';
print '</div>';
}
}
/*
* Specific to thirdparty module
*/
if($element_id && $element == 'societe')
{
$socstatic = fetchObjectByElement($element_id,$element);
if(is_object($socstatic)) {
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
$head = societe_prepare_head($socstatic);
dol_fiche_head($head, 'resources', $langs->trans("ThirdParty"),0,'company');
// Affichage fiche action en mode visu
print '<table class="border" width="100%">';
//$linkback = '<a href="'.DOL_URL_ROOT.'/comm/action/listactions.php">'.$langs->trans("BackToList").'</a>';
// Name
print '<tr><td width="25%">'.$langs->trans('ThirdPartyName').'</td>';
print '<td colspan="3">';
print $form->showrefnav($socstatic, 'socid', '', ($user->societe_id?0:1), 'rowid', 'nom');
print '</td>';
print '</tr>';
print '</table>';
print '</div>';
}
}
print_fiche_titre($langs->trans('ResourcesLinkedToElement'),'','resource.png@resource');
foreach ($object->available_resources as $modresources => $resources)
{
$langs->load($resources);
//print '<h2>'.$modresources.'</h2>';
$resources=(array) $resources; // To be sure $resources is an array
foreach($resources as $resource_obj)
{
$element_prop = getElementProperties($resource_obj);
print_titre($langs->trans(ucfirst($element_prop['element']).'Singular'));
//print '/'.$modresources.'/class/'.$resource_obj.'.class.php<br />';
$path = '';
if(strpos($resource_obj,'@'))
$path .= '/'.$element_prop['module'];
$linked_resources = $object->getElementResources($element,$element_id,$resource_obj);
if ( $mode == 'add' && $resource_obj == $resource_type)
{
// If we have a specific template we use it
if(file_exists(dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_'.$mode.'.tpl.php')))
{
$res=include dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_'.$mode.'.tpl.php');
}
else
{
$res=include DOL_DOCUMENT_ROOT . '/core/tpl/resource_add.tpl.php';
}
}
else
{
//print '/'.$element_prop['module'].'/core/tpl/resource_'.$element_prop['element'].'_view.tpl.php';
// If we have a specific template we use it
if(file_exists(dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_view.tpl.php')))
{
$res=@include dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_view.tpl.php');
}
else
{
$res=include DOL_DOCUMENT_ROOT . '/core/tpl/resource_view.tpl.php';
}
}
if($resource_obj!=$resource_type )
{
print '<div class="tabsAction">';
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 '</div>';
print '</div>';
}
}
}
}
llxFooter();
$db->close();

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

175
htdocs/resource/list.php Normal file
View File

@ -0,0 +1,175 @@
<?php
/* Module to manage resources into Dolibarr ERP/CRM
* Copyright (C) 2013-2014 Jean-François Ferry <jfefe@aternatik.fr>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \file resource/index.php
* \ingroup resource
* \brief Page to manage resource objects
*/
// 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 'class/resource.class.php';
// Load traductions files requiredby by page
$langs->load("resource");
$langs->load("companies");
$langs->load("other");
// Get parameters
$id = GETPOST('id','int');
$action = GETPOST('action','alpha');
$lineid = GETPOST('lineid','int');
$element = GETPOST('element','alpha');
$element_id = GETPOST('element_id','int');
$resource_id = GETPOST('resource_id','int');
$sortorder = GETPOST('sortorder','alpha');
$sortfield = GETPOST('sortfield','alpha');
$page = GETPOST('page','int');
$object = new Resource($db);
$hookmanager->initHooks(array('resource_list'));
$parameters=array();
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if (empty($sortorder)) $sortorder="DESC";
if (empty($sortfield)) $sortfield="t.rowid";
if (empty($arch)) $arch = 0;
if ($page == -1) {
$page = 0 ;
}
$limit = $conf->liste_limit;
$offset = $limit * $page ;
$pageprev = $page - 1;
$pagenext = $page + 1;
if( ! $user->rights->resource->read)
accessforbidden();
/***************************************************
* VIEW
*
* Put here all code to build page
****************************************************/
$pagetitle=$langs->trans('ResourcePageIndex');
llxHeader('',$pagetitle,'');
$form=new Form($db);
print_fiche_titre($pagetitle,'','resource.png@resource');
// Confirmation suppression resource line
if ($action == 'delete_resource')
{
print $form->formconfirm($_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id."&lineid=".$lineid,$langs->trans("DeleteResource"),$langs->trans("ConfirmDeleteResourceElement"),"confirm_delete_resource",'','',1);
}
// Load object list
$ret = $object->fetch_all($sortorder, $sortfield, $limit, $offset);
if($ret == -1) {
dol_print_error($db,$object->error);
exit;
}
if(!$ret) {
print '<div class="warning">'.$langs->trans('NoResourceInDatabase').'</div>';
}
else
{
$var=false;
print '<table class="noborder" width="100%">'."\n";
print '<tr class="liste_titre">';
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('ResourceType'),$_SERVER['PHP_SELF'],'ty.code','',$param,'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans('Edit'));
print '</tr>';
foreach ($object->lines as $resource)
{
$var=!$var;
$style='';
if($resource->id == GETPOST('lineid'))
$style='style="background: orange;"';
print '<tr '.$bc[$var].' '.$style.'><td>';
print $resource->id;
print '</td>';
print '<td>';
print $resource->ref;
print '</td>';
print '<td>';
print $resource->type_label;
print '</td>';
print '<td>';
print '<a href="card.php?id='.$resource->id.'">'.$langs->trans('View').'</a> ';
print '<a href="card.php?action=edit&id='.$resource->id.'">'.$langs->trans('Edit').'</a>';
print '</td>';
print '</tr>';
}
print '</table>';
}
/*
* Boutons actions
*/
print '<div class="tabsAction">';
$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 '<div class="inline-block divButAction">';
print '<a href="add.php" class="butAction">'.$langs->trans('AddResource').'</a>';
print '</div>';
}
}
}
print '</div>';
llxFooter();
$db->close();