2014-10-14 17:00:06 +02:00
< ? php
/* Copyright ( C ) 2014 Maxime Kohlhaas < support @ atm - consulting . fr >
2014-11-06 22:16:27 +01:00
* Copyright ( C ) 2014 Juanjo Menent < jmenent @ 2 byte . es >
2014-10-14 17:00:06 +02: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 />.
2014-11-07 22:40:13 +01:00
*
2014-10-14 17:00:06 +02:00
* Need to have following variables defined :
* $object ( invoice , order , ... )
2017-06-07 16:44:04 +02:00
* $action
2014-10-14 17:00:06 +02:00
* $conf
* $langs
*
2017-06-07 16:44:04 +02:00
* $parameters
2014-10-14 17:00:06 +02:00
* $cols
*/
2017-12-21 13:32:16 +01:00
// Protection to avoid direct call of template
if ( empty ( $object ) || ! is_object ( $object ))
{
print " Error, template page can't be called as URL " ;
exit ;
}
2016-12-23 13:04:46 +01:00
?>
2017-06-07 16:44:04 +02:00
<!-- BEGIN PHP TEMPLATE extrafields_view . tpl . php -->
2016-12-23 13:04:46 +01:00
< ? php
2014-10-14 17:00:06 +02:00
2017-06-07 16:44:04 +02:00
if ( ! is_array ( $parameters )) $parameters = array ();
if ( ! empty ( $cols )) $parameters [ 'colspan' ] = ' colspan="' . $cols . '"' ;
if ( ! empty ( $cols )) $parameters [ 'cols' ] = $cols ;
if ( ! empty ( $object -> fk_soc )) $parameters [ 'socid' ] = $object -> fk_soc ;
2014-10-14 17:00:06 +02:00
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action );
2017-06-11 10:37:58 +02:00
print $hookmanager -> resPrint ;
2017-06-07 16:44:04 +02:00
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2014-10-14 17:00:06 +02:00
2017-08-27 12:06:46 +02:00
//var_dump($extrafields->attributes);
2017-06-07 16:44:04 +02:00
if ( empty ( $reshook ) && ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'label' ]))
2014-10-14 17:00:06 +02:00
{
2017-06-07 16:44:04 +02:00
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $key => $label )
2014-10-14 17:00:06 +02:00
{
2017-11-03 15:56:16 +01:00
// Discard if extrafield is a hidden field on form
2017-11-10 16:51:37 +01:00
if ( empty ( $extrafields -> attributes [ $object -> table_element ][ 'list' ][ $key ])) continue ; // 0 = Never visible field
if ( abs ( $extrafields -> attributes [ $object -> table_element ][ 'list' ][ $key ]) != 1 && abs ( $extrafields -> attributes [ $object -> table_element ][ 'list' ][ $key ]) != 3 ) continue ; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list
2017-10-28 16:00:07 +02:00
2017-08-27 12:06:46 +02:00
// Load language if required
if ( ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'langfile' ][ $key ])) $langs -> load ( $extrafields -> attributes [ $object -> table_element ][ 'langfile' ][ $key ]);
2014-10-14 17:00:06 +02:00
if ( $action == 'edit_extras' )
{
2014-12-23 12:25:21 +01:00
$value = ( isset ( $_POST [ " options_ " . $key ]) ? $_POST [ " options_ " . $key ] : $object -> array_options [ " options_ " . $key ]);
2014-10-14 17:00:06 +02:00
}
else
{
2014-12-23 12:25:21 +01:00
$value = $object -> array_options [ " options_ " . $key ];
2014-10-14 17:00:06 +02:00
}
2017-06-07 16:44:04 +02:00
if ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $key ] == 'separate' )
2014-10-14 17:00:06 +02:00
{
print $extrafields -> showSeparator ( $key );
}
else
{
2017-10-25 11:42:14 +02:00
print '<tr><td>' ;
2016-12-23 13:04:46 +01:00
print '<table width="100%" class="nobordernopadding">' ;
print '<tr>' ;
print '<td' ;
2014-12-23 12:25:21 +01:00
//var_dump($action);exit;
2017-06-07 16:44:04 +02:00
if (( ! empty ( $action ) && ( $action == 'create' || $action == 'edit' )) && ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'required' ][ $key ])) print ' class="fieldrequired"' ;
2015-08-18 16:40:03 +02:00
print '>' . $langs -> trans ( $label ) . '</td>' ;
2014-11-07 22:40:13 +01:00
2014-11-06 22:16:27 +01:00
//TODO Improve element and rights detection
2014-11-07 22:40:13 +01:00
//var_dump($user->rights);
$permok = false ;
2017-06-07 16:44:04 +02:00
2014-11-07 22:40:13 +01:00
$keyforperm = $object -> element ;
if ( $object -> element == 'fichinter' ) $keyforperm = 'ficheinter' ;
if ( isset ( $user -> rights -> $keyforperm )) $permok = $user -> rights -> $keyforperm -> creer || $user -> rights -> $keyforperm -> create || $user -> rights -> $keyforperm -> write ;
2017-06-07 16:44:04 +02:00
if ( $object -> element == 'order_supplier' ) $permok = $user -> rights -> fournisseur -> commande -> creer ;
if ( $object -> element == 'invoice_supplier' ) $permok = $user -> rights -> fournisseur -> facture -> creer ;
if ( $object -> element == 'shipping' ) $permok = $user -> rights -> expedition -> creer ;
if ( $object -> element == 'delivery' ) $permok = $user -> rights -> expedition -> livraison -> creer ;
if ( $object -> element == 'productlot' ) $permok = $user -> rights -> stock -> creer ;
2017-07-11 09:26:25 +02:00
if ( $object -> element == 'facturerec' ) $permok = $user -> rights -> facture -> creer ;
2014-11-07 22:40:13 +01:00
2017-06-07 16:44:04 +02:00
if (( $object -> statut == 0 || ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'alwayseditable' ][ $key ]))
&& $permok && ( $action != 'edit_extras' || GETPOST ( 'attribute' ) != $key )
&& empty ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ][ $key ]))
{
$fieldid = 'id' ;
if ( $object -> table_element == 'societe' ) $fieldid = 'socid' ;
print '<td align="right"><a href="' . $_SERVER [ 'PHP_SELF' ] . '?' . $fieldid . '=' . $object -> id . '&action=edit_extras&attribute=' . $key . '">' . img_edit () . '</a></td>' ;
}
2014-10-14 17:00:06 +02:00
print '</tr></table>' ;
2016-02-04 21:05:19 +01:00
$html_id = ! empty ( $object -> id ) ? $object -> element . '_extras_' . $key . '_' . $object -> id : '' ;
print '<td id="' . $html_id . '" class="' . $object -> element . '_extras_' . $key . '" colspan="' . $cols . '">' ;
2014-11-07 22:40:13 +01:00
2014-10-14 17:00:06 +02:00
// Convert date into timestamp format
2017-06-07 16:44:04 +02:00
if ( in_array ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $key ], array ( 'date' , 'datetime' ))) {
2014-12-23 12:25:21 +01:00
$value = isset ( $_POST [ " options_ " . $key ]) ? dol_mktime ( $_POST [ " options_ " . $key . " hour " ], $_POST [ " options_ " . $key . " min " ], 0 , $_POST [ " options_ " . $key . " month " ], $_POST [ " options_ " . $key . " day " ], $_POST [ " options_ " . $key . " year " ]) : $db -> jdate ( $object -> array_options [ 'options_' . $key ]);
2014-10-14 17:00:06 +02:00
}
2014-11-07 22:40:13 +01:00
2014-11-06 22:16:27 +01:00
//TODO Improve element and rights detection
2014-11-07 22:40:13 +01:00
if ( $action == 'edit_extras' && $permok && GETPOST ( 'attribute' ) == $key )
2014-10-14 17:00:06 +02:00
{
2017-06-07 16:44:04 +02:00
$fieldid = 'id' ;
if ( $object -> table_element == 'societe' ) $fieldid = 'socid' ;
print '<form enctype="multipart/form-data" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post" name="formextra">' ;
2014-10-14 17:00:06 +02:00
print '<input type="hidden" name="action" value="update_extras">' ;
print '<input type="hidden" name="attribute" value="' . $key . '">' ;
2014-12-23 12:25:21 +01:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2017-06-07 16:44:04 +02:00
print '<input type="hidden" name="' . $fieldid . '" value="' . $object -> id . '">' ;
2014-10-14 17:00:06 +02:00
2017-10-26 02:55:43 +02:00
print $extrafields -> showInputField ( $key , $value , '' , '' , '' , 0 , $object -> id );
2014-10-14 17:00:06 +02:00
print '<input type="submit" class="button" value="' . $langs -> trans ( 'Modify' ) . '">' ;
print '</form>' ;
}
else
{
2018-02-01 19:03:21 +01:00
print $extrafields -> showOutputField ( $key , $value , '' , ( empty ( $extrafieldsobjectkey ) ? '' : $extrafieldsobjectkey ));
2014-10-14 17:00:06 +02:00
}
print '</td></tr>' . " \n " ;
2017-06-07 16:44:04 +02:00
print " \n " ;
// Add code to manage list depending on others
if ( ! empty ( $conf -> use_javascript_ajax ))
print '
< script type = " text/javascript " >
jQuery ( document ) . ready ( function () {
function showOptions ( child_list , parent_list )
{
var val = $ ( " select[name= \" options_ " + parent_list + " \" ] " ) . val ();
var parentVal = parent_list + " : " + val ;
if ( val > 0 ) {
$ ( " select[name= \" " + child_list + " \" ] option[parent] " ) . hide ();
$ ( " select[name= \" " + child_list + " \" ] option[parent= \" " + parentVal + " \" ] " ) . show ();
} else {
$ ( " select[name= \" " + child_list + " \" ] option " ) . show ();
}
}
function setListDependencies () {
jQuery ( " select option[parent] " ) . parent () . each ( function () {
var child_list = $ ( this ) . attr ( " name " );
var parent = $ ( this ) . find ( " option[parent]:first " ) . attr ( " parent " );
var infos = parent . split ( " : " );
var parent_list = infos [ 0 ];
$ ( " select[name= \" " + parent_list + " \" ] " ) . change ( function () {
showOptions ( child_list , parent_list );
});
});
}
setListDependencies ();
});
</ script > ' . " \n " ;
2014-10-14 17:00:06 +02:00
}
}
}
2016-12-23 13:04:46 +01:00
?>
2017-06-07 16:44:04 +02:00
<!-- END PHP TEMPLATE extrafields_view . tpl . php -->