2014-01-02 07:07:43 +01:00
< ? php
2014-11-23 21:03:34 +01:00
/* Copyright ( C ) 2013 Jean - François Ferry < jfefe @ aternatik . fr >
2014-01-02 07:07:43 +01:00
*
* 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' ;
2014-04-15 18:01:18 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2014-01-02 07:07:43 +01:00
// Load traductions files requiredby by page
2014-11-23 21:03:34 +01:00
$langs -> load ( " resource " );
2014-01-02 07:07:43 +01:00
$langs -> load ( " other " );
/*
$sortorder = GETPOST ( 'sortorder' , 'alpha' );
$sortfield = GETPOST ( 'sortfield' , 'alpha' );
$page = GETPOST ( 'page' , 'int' );
*/
2014-03-15 16:29:33 +01:00
if ( ! $user -> rights -> resource -> read )
2014-01-02 07:07:43 +01:00
accessforbidden ();
$object = new Resource ( $db );
$hookmanager -> initHooks ( array ( 'element_resource' ));
2014-09-07 12:22:04 +02:00
$object -> available_resources = array ( 'resource' );
2014-01-02 07:07:43 +01:00
2014-09-07 12:22:04 +02:00
// Get parameters
2015-12-05 19:20:39 +01:00
$id = GETPOST ( 'id' , 'int' );
2014-09-07 12:22:04 +02:00
$action = GETPOST ( 'action' , 'alpha' );
$mode = GETPOST ( 'mode' , 'alpha' );
$lineid = GETPOST ( 'lineid' , 'int' );
2015-08-14 17:35:05 +02:00
$element = GETPOST ( 'element' , 'alpha' ); // element_type
2014-09-07 12:22:04 +02:00
$element_id = GETPOST ( 'element_id' , 'int' );
$resource_id = GETPOST ( 'fk_resource' , 'int' );
$resource_type = GETPOST ( 'resource_type' , 'alpha' );
$busy = GETPOST ( 'busy' , 'int' );
$mandatory = GETPOST ( 'mandatory' , 'int' );
2014-11-23 21:03:34 +01:00
$cancel = GETPOST ( 'cancel' , 'alpha' );
2015-08-14 17:35:05 +02:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
2015-12-05 19:20:39 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2014-09-07 12:22:04 +02:00
2015-12-05 19:20:39 +01:00
if ( $socid > 0 )
{
$element_id = $socid ;
$element = 'societe' ;
}
2015-05-31 02:05:39 +02:00
2015-12-05 19:20:39 +01:00
2015-05-31 02:05:39 +02:00
/*
* Actions
*/
2015-08-14 17:35:05 +02:00
if ( $action == 'add_element_resource' && ! $cancel )
2014-09-07 12:22:04 +02:00
{
2015-12-05 19:20:39 +01:00
$error ++ ;
2015-08-12 21:48:00 +02:00
$res = 0 ;
2015-12-05 19:20:39 +01:00
if ( ! ( $resource_id > 0 ))
2015-08-12 21:48:00 +02:00
{
2015-12-05 19:20:39 +01:00
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Resource " )), null , 'errors' );
$action = '' ;
2015-08-12 21:48:00 +02:00
}
2015-12-05 19:20:39 +01:00
else
2014-09-07 12:22:04 +02:00
{
2015-12-05 19:20:39 +01:00
$objstat = fetchObjectByElement ( $element_id , $element );
$res = $objstat -> add_element_resource ( $resource_id , $resource_type , $busy , $mandatory );
2014-09-07 12:22:04 +02:00
}
2015-12-05 19:20:39 +01:00
if ( ! $error && $res > 0 )
2014-09-07 12:22:04 +02:00
{
2015-12-20 10:36:20 +01:00
setEventMessages ( $langs -> trans ( 'ResourceLinkedWithSuccess' ), null , 'mesgs' );
2015-12-05 19:20:39 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . '?element=' . $element . '&element_id=' . $element_id );
2014-09-07 12:22:04 +02:00
exit ;
}
}
2014-04-23 19:04:10 +02:00
2014-09-07 12:22:04 +02:00
// Update ressource
if ( $action == 'update_linked_resource' && $user -> rights -> resource -> write && ! GETPOST ( 'cancel' ) )
{
$res = $object -> fetch_element_resource ( $lineid );
if ( $res )
{
$object -> busy = $busy ;
$object -> mandatory = $mandatory ;
$result = $object -> update_element_resource ( $user );
if ( $result >= 0 )
{
2015-12-20 10:36:20 +01:00
setEventMessages ( $langs -> trans ( 'RessourceLineSuccessfullyUpdated' ), null , 'mesgs' );
2015-12-05 19:20:39 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?element= " . $element . " &element_id= " . $element_id );
2014-09-07 12:22:04 +02:00
exit ;
}
2015-12-20 10:36:20 +01:00
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2014-09-07 12:22:04 +02:00
}
}
}
// Delete a resource linked to an element
2015-04-18 18:07:59 +02:00
if ( $action == 'confirm_delete_linked_resource' && $user -> rights -> resource -> delete && $confirm === 'yes' )
2014-09-07 12:22:04 +02:00
{
2015-12-05 19:20:39 +01:00
$result = $object -> delete_resource ( $lineid , $element );
if ( $result >= 0 )
{
2015-12-21 14:43:21 +01:00
setEventMessages ( $langs -> trans ( 'RessourceLineSuccessfullyDeleted' ), null , 'mesgs' );
2015-12-05 19:20:39 +01:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?element= " . $element . " &element_id= " . $element_id );
exit ;
}
else
{
2015-12-21 14:43:21 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2015-12-05 19:20:39 +01:00
}
2014-09-07 12:22:04 +02:00
}
2014-04-23 19:04:10 +02:00
2015-08-12 21:48:00 +02:00
$parameters = array ( 'resource_id' => $resource_id );
2014-01-02 07:07:43 +01:00
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2014-09-28 03:41:32 +02:00
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2014-09-07 12:22:04 +02:00
2014-04-23 19:04:10 +02:00
$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
2014-09-28 03:41:32 +02:00
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2014-01-02 07:07:43 +01:00
2015-05-31 02:05:39 +02:00
/*
* View
*/
2014-01-02 07:07:43 +01:00
$form = new Form ( $db );
2015-05-31 02:05:39 +02:00
$pagetitle = $langs -> trans ( 'ResourceElementPage' );
llxHeader ( '' , $pagetitle , '' );
2014-01-02 07:07:43 +01:00
// Load available resource, declared by modules
2014-04-23 19:04:10 +02:00
$ret = count ( $object -> available_resources );
2014-01-02 07:07:43 +01:00
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' )
{
2016-03-25 15:53:44 +01:00
print $form -> formconfirm ( " element_resource.php?element= " . $element . " &element_id= " . $element_id . " &id= " . $id . " &lineid= " . $lineid , $langs -> trans ( " DeleteResource " ), $langs -> trans ( " ConfirmDeleteResourceElement " ), " confirm_delete_linked_resource " , '' , '' , 1 );
2014-01-02 07:07:43 +01:00
}
/*
* Specific to agenda module
*/
2015-12-05 19:20:39 +01:00
if ( $element_id && $element == 'action' )
2014-01-02 07:07:43 +01:00
{
require_once DOL_DOCUMENT_ROOT . '/core/lib/agenda.lib.php' ;
2014-03-15 16:29:33 +01:00
$act = fetchObjectByElement ( $element_id , $element );
2015-12-05 19:20:39 +01:00
if ( is_object ( $act ))
{
2014-01-02 07:07:43 +01:00
$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">' ;
2016-03-25 15:53:44 +01:00
print $form -> showrefnav ( $act , 'id' , $linkback , ( $user -> societe_id ? 0 : 1 ), 'id' , 'ref' , '' );
2014-01-02 07:07:43 +01:00
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>' ;
2015-05-31 02:05:39 +02:00
dol_fiche_end ();
2014-01-02 07:07:43 +01:00
}
}
2015-05-31 02:05:39 +02:00
2014-01-02 07:07:43 +01:00
/*
* Specific to thirdparty module
*/
2015-05-31 02:05:39 +02:00
if ( $element_id && $element == 'societe' )
2014-01-02 07:07:43 +01:00
{
2014-03-15 16:29:33 +01:00
$socstatic = fetchObjectByElement ( $element_id , $element );
2015-12-05 19:20:39 +01:00
if ( is_object ( $socstatic ))
{
$savobject = $object ;
$object = $socstatic ;
2014-01-02 07:07:43 +01:00
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' );
2015-12-05 19:20:39 +01:00
dol_banner_tab ( $socstatic , 'socid' , '' , ( $user -> societe_id ? 0 : 1 ), 'rowid' , 'nom' );
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border" width="100%">' ;
// Alias name (commercial, trademark or alias name)
print '<tr><td class="titelfield">' . $langs -> trans ( 'AliasNames' ) . '</td><td colspan="3">' ;
print $socstatic -> name_alias ;
print " </td></tr> " ;
2014-01-02 07:07:43 +01:00
print '</table>' ;
2015-12-05 19:20:39 +01:00
print '</div>' ;
2015-05-31 02:05:39 +02:00
dol_fiche_end ();
2015-12-05 19:20:39 +01:00
$object = $savobject ;
2014-01-02 07:07:43 +01:00
}
}
2015-09-24 18:33:48 +02:00
//print load_fiche_titre($langs->trans('ResourcesLinkedToElement'),'','');
2014-04-23 19:04:10 +02:00
2014-01-02 07:07:43 +01:00
2015-12-05 19:20:39 +01:00
foreach ( $object -> available_resources as $modresources => $resources )
2014-01-02 07:07:43 +01:00
{
$resources = ( array ) $resources ; // To be sure $resources is an array
foreach ( $resources as $resource_obj )
{
2014-03-15 16:29:33 +01:00
$element_prop = getElementProperties ( $resource_obj );
2014-01-02 07:07:43 +01:00
//print '/'.$modresources.'/class/'.$resource_obj.'.class.php<br />';
2014-03-15 03:22:21 +01:00
$path = '' ;
if ( strpos ( $resource_obj , '@' ))
$path .= '/' . $element_prop [ 'module' ];
2014-01-02 07:07:43 +01:00
$linked_resources = $object -> getElementResources ( $element , $element_id , $resource_obj );
2015-05-31 02:05:39 +02:00
// If we have a specific template we use it
if ( file_exists ( dol_buildpath ( $path . '/core/tpl/resource_' . $element_prop [ 'element' ] . '_add.tpl.php' )))
2014-01-02 07:07:43 +01:00
{
2015-05-31 02:05:39 +02:00
$res = include dol_buildpath ( $path . '/core/tpl/resource_' . $element_prop [ 'element' ] . '_add.tpl.php' );
2014-01-02 07:07:43 +01:00
}
else
{
2015-05-31 02:05:39 +02:00
$res = include DOL_DOCUMENT_ROOT . '/core/tpl/resource_add.tpl.php' ;
}
2015-12-05 19:20:39 +01:00
//var_dump($element_id);
2015-05-31 02:05:39 +02:00
if ( $mode != 'add' || $resource_obj != $resource_type )
{
2015-09-24 18:27:13 +02:00
//print load_fiche_titre($langs->trans(ucfirst($element_prop['element']).'Singular'));
2014-01-02 07:07:43 +01:00
// If we have a specific template we use it
2014-03-15 03:22:21 +01:00
if ( file_exists ( dol_buildpath ( $path . '/core/tpl/resource_' . $element_prop [ 'element' ] . '_view.tpl.php' )))
2014-01-02 07:07:43 +01:00
{
2014-03-15 03:22:21 +01:00
$res =@ include dol_buildpath ( $path . '/core/tpl/resource_' . $element_prop [ 'element' ] . '_view.tpl.php' );
2014-01-02 07:07:43 +01:00
}
else
{
2014-04-23 19:04:10 +02:00
$res = include DOL_DOCUMENT_ROOT . '/core/tpl/resource_view.tpl.php' ;
2014-01-02 07:07:43 +01:00
}
}
}
}
}
llxFooter ();
$db -> close ();