2018-07-05 21:42:34 +02:00
< ? php
/* Copyright ( C ) 2014 Maxime Kohlhaas < support @ atm - consulting . fr >
* Copyright ( C ) 2014 Juanjo Menent < jmenent @ 2 byte . es >
*
* 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2018-07-05 21:42:34 +02:00
*
2019-10-06 14:41:52 +02:00
* Show extrafields . It also show fields from hook formObjectOptions . Need to have following variables defined :
2018-07-05 21:42:34 +02:00
* $object ( invoice , order , ... )
* $action
* $conf
* $langs
*
* $parameters
* $cols
*/
2019-10-06 14:41:52 +02:00
2018-07-05 21:42:34 +02:00
// Protection to avoid direct call of template
2019-11-13 19:35:39 +01:00
if ( empty ( $object ) || ! is_object ( $object ))
2018-07-05 21:42:34 +02:00
{
print " Error, template page can't be called as URL " ;
exit ;
}
2018-07-05 22:35:40 +02:00
2019-11-13 19:35:39 +01:00
if ( ! is_object ( $form )) $form = new Form ( $db );
2017-12-21 13:32:16 +01:00
2018-07-05 22:35:40 +02:00
2018-07-05 21:42:34 +02:00
?>
<!-- BEGIN PHP TEMPLATE extrafields_view . tpl . php -->
< ? php
2019-11-13 19:35:39 +01: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 ;
2018-07-05 21:42:34 +02:00
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action );
print $hookmanager -> resPrint ;
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2014-10-14 17:00:06 +02:00
2018-07-05 22:35:40 +02:00
2018-05-13 14:27:40 +02:00
//var_dump($extrafields->attributes[$object->table_element]);
2018-04-13 13:28:48 +02:00
if ( empty ( $reshook ) && is_array ( $extrafields -> attributes [ $object -> table_element ][ 'label' ]))
2018-07-05 21:42:34 +02:00
{
2019-08-21 03:38:57 +02:00
$lastseparatorkeyfound = '' ;
2019-05-03 16:14:44 +02:00
$extrafields_collapse_num = '' ;
2020-05-13 13:29:50 +02:00
$extrafields_collapse_num_old = '' ;
$i = 0 ;
2020-07-27 14:04:41 +02:00
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $tmpkeyextra => $tmplabelextra )
2018-07-05 21:42:34 +02:00
{
2020-05-13 13:29:50 +02:00
$i ++ ;
2018-07-05 21:42:34 +02:00
// Discard if extrafield is a hidden field on form
2018-07-05 22:35:40 +02:00
2018-04-12 23:16:23 +02:00
$enabled = 1 ;
2020-07-27 14:04:41 +02:00
if ( $enabled && isset ( $extrafields -> attributes [ $object -> table_element ][ 'enabled' ][ $tmpkeyextra ]))
2018-05-13 14:27:40 +02:00
{
2020-07-27 14:04:41 +02:00
$enabled = dol_eval ( $extrafields -> attributes [ $object -> table_element ][ 'enabled' ][ $tmpkeyextra ], 1 );
2018-05-13 14:27:40 +02:00
}
2020-07-27 14:04:41 +02:00
if ( $enabled && isset ( $extrafields -> attributes [ $object -> table_element ][ 'list' ][ $tmpkeyextra ]))
2018-04-12 23:16:23 +02:00
{
2020-07-27 14:04:41 +02:00
$enabled = dol_eval ( $extrafields -> attributes [ $object -> table_element ][ 'list' ][ $tmpkeyextra ], 1 );
2018-04-12 23:16:23 +02:00
}
2020-05-13 13:29:50 +02:00
2018-04-12 23:16:23 +02:00
$perms = 1 ;
2020-07-27 14:04:41 +02:00
if ( $perms && isset ( $extrafields -> attributes [ $object -> table_element ][ 'perms' ][ $tmpkeyextra ]))
2018-04-12 23:16:23 +02:00
{
2020-07-27 14:04:41 +02:00
$perms = dol_eval ( $extrafields -> attributes [ $object -> table_element ][ 'perms' ][ $tmpkeyextra ], 1 );
2018-04-12 23:16:23 +02:00
}
2020-07-27 14:04:41 +02:00
//print $tmpkeyextra.'-'.$enabled.'-'.$perms.'-'.$tmplabelextra.$_POST["options_" . $tmpkeyextra].'<br>'."\n";
2018-04-12 23:16:23 +02:00
2019-12-03 11:17:29 +01:00
if ( empty ( $enabled )) continue ; // 0 = Never visible field
2020-04-03 14:24:59 +02:00
if ( abs ( $enabled ) != 1 && abs ( $enabled ) != 3 && abs ( $enabled ) != 5 && abs ( $enabled ) != 4 ) continue ; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list <> 4 = not visible at the creation
2019-12-03 11:17:29 +01:00
if ( empty ( $perms )) continue ; // 0 = Not visible
2017-10-28 16:00:07 +02:00
2018-07-05 21:42:34 +02:00
// Load language if required
2020-07-27 14:04:41 +02:00
if ( ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'langfile' ][ $tmpkeyextra ])) $langs -> load ( $extrafields -> attributes [ $object -> table_element ][ 'langfile' ][ $tmpkeyextra ]);
2018-07-05 21:42:34 +02:00
if ( $action == 'edit_extras' )
{
2020-07-27 14:04:41 +02:00
$value = ( isset ( $_POST [ " options_ " . $tmpkeyextra ]) ? $_POST [ " options_ " . $tmpkeyextra ] : $object -> array_options [ " options_ " . $tmpkeyextra ]);
2020-05-21 15:05:19 +02:00
} else {
2020-07-27 14:04:41 +02:00
$value = $object -> array_options [ " options_ " . $tmpkeyextra ];
//var_dump($tmpkeyextra.' - '.$value);
2018-07-05 21:42:34 +02:00
}
2020-05-13 13:29:50 +02:00
// Print line tr of extra field
2020-07-27 14:04:41 +02:00
if ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $tmpkeyextra ] == 'separate' )
2018-07-05 21:42:34 +02:00
{
2019-05-03 16:14:44 +02:00
$extrafields_collapse_num = '' ;
2020-07-27 14:04:41 +02:00
$extrafield_param = $extrafields -> attributes [ $object -> table_element ][ 'param' ][ $tmpkeyextra ];
2019-05-03 16:14:44 +02:00
if ( ! empty ( $extrafield_param ) && is_array ( $extrafield_param )) {
$extrafield_param_list = array_keys ( $extrafield_param [ 'options' ]);
2019-11-13 19:35:39 +01:00
if ( count ( $extrafield_param_list ) > 0 ) {
2019-05-03 16:14:44 +02:00
$extrafield_collapse_display_value = intval ( $extrafield_param_list [ 0 ]);
2019-11-13 19:35:39 +01:00
if ( $extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2 ) {
2020-07-27 14:04:41 +02:00
$extrafields_collapse_num = $extrafields -> attributes [ $object -> table_element ][ 'pos' ][ $tmpkeyextra ];
2019-05-03 16:14:44 +02:00
}
}
}
2020-07-27 14:04:41 +02:00
print $extrafields -> showSeparator ( $tmpkeyextra , $object );
2019-08-21 03:38:57 +02:00
2020-07-27 14:04:41 +02:00
$lastseparatorkeyfound = $tmpkeyextra ;
2020-05-21 15:05:19 +02:00
} else {
2020-05-13 13:29:50 +02:00
print '<tr class="trextrafields_collapse' . $extrafields_collapse_num ;
/* if ( $extrafields_collapse_num && $extrafields_collapse_num_old && $extrafields_collapse_num != $extrafields_collapse_num_old ) {
print ' trextrafields_collapse_new' ;
} */
if ( $extrafields_collapse_num && $i == count ( $extrafields -> attributes [ $object -> table_element ][ 'label' ])) {
print ' trextrafields_collapse_last' ;
}
print '">' ;
$extrafields_collapse_num_old = $extrafields_collapse_num ;
2018-06-23 14:23:07 +02:00
print '<td class="titlefield">' ;
2019-10-03 19:02:29 +02:00
print '<table class="nobordernopadding centpercent">' ;
2018-07-05 21:42:34 +02:00
print '<tr>' ;
2018-07-05 22:35:40 +02:00
2020-05-13 13:29:50 +02:00
print '<td class="' ;
2020-07-27 14:04:41 +02:00
if (( ! empty ( $action ) && ( $action == 'create' || $action == 'edit' )) && ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'required' ][ $tmpkeyextra ])) print ' fieldrequired' ;
2018-06-13 13:36:40 +02:00
print '">' ;
2020-07-27 14:04:41 +02:00
if ( ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'help' ][ $tmpkeyextra ])) print $form -> textwithpicto ( $langs -> trans ( $tmplabelextra ), $langs -> trans ( $extrafields -> attributes [ $object -> table_element ][ 'help' ][ $tmpkeyextra ]));
else print $langs -> trans ( $tmplabelextra );
2018-06-13 13:36:40 +02:00
print '</td>' ;
2014-11-07 22:40:13 +01:00
2018-07-05 21:42:34 +02:00
//TODO Improve element and rights detection
//var_dump($user->rights);
2019-12-03 11:17:29 +01:00
$permok = false ;
$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 ;
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 ;
2020-07-04 16:14:53 +02:00
if ( $object -> element == 'facturerec' ) $permok = $user -> rights -> facture -> creer ;
if ( $object -> element == 'mo' ) $permok = $user -> rights -> mrp -> write ;
$isdraft = (( isset ( $object -> statut ) && $object -> statut == 0 ) || ( isset ( $object -> status ) && $object -> status == 0 ));
2020-07-27 14:04:41 +02:00
if (( $isdraft || ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'alwayseditable' ][ $tmpkeyextra ]))
&& $permok && $enabled != 5 && ( $action != 'edit_extras' || GETPOST ( 'attribute' ) != $tmpkeyextra )
&& empty ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ][ $tmpkeyextra ]))
2018-07-05 21:42:34 +02:00
{
2019-12-03 11:17:29 +01:00
$fieldid = 'id' ;
if ( $object -> table_element == 'societe' ) $fieldid = 'socid' ;
2020-07-27 14:04:41 +02:00
print '<td class="right"><a class="reposition editfielda" href="' . $_SERVER [ 'PHP_SELF' ] . '?' . $fieldid . '=' . $object -> id . '&action=edit_extras&attribute=' . $tmpkeyextra . '&ignorecollapsesetup=1">' . img_edit () . '</a></td>' ;
2018-07-05 21:42:34 +02:00
}
print '</tr></table>' ;
2018-06-13 13:00:08 +02:00
print '</td>' ;
2020-07-27 14:04:41 +02:00
$html_id = ! empty ( $object -> id ) ? $object -> element . '_extras_' . $tmpkeyextra . '_' . $object -> id : '' ;
2018-07-05 22:35:40 +02:00
2020-07-27 14:04:41 +02:00
print '<td id="' . $html_id . '" class="' . $object -> element . '_extras_' . $tmpkeyextra . ' wordbreak"' . ( $cols ? ' colspan="' . $cols . '"' : '' ) . '>' ;
2014-11-07 22:40:13 +01:00
2018-07-05 21:42:34 +02:00
// Convert date into timestamp format
2020-07-27 14:04:41 +02:00
if ( in_array ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $tmpkeyextra ], array ( 'date' , 'datetime' )))
2018-07-05 21:42:34 +02:00
{
2020-07-27 14:04:41 +02:00
$datenotinstring = $object -> array_options [ 'options_' . $tmpkeyextra ];
// print 'X'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.'x';
if ( ! is_numeric ( $object -> array_options [ 'options_' . $tmpkeyextra ])) // For backward compatibility
2018-07-05 21:42:34 +02:00
{
$datenotinstring = $db -> jdate ( $datenotinstring );
}
2020-07-27 14:04:41 +02:00
//print 'x'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.' - '.dol_print_date($datenotinstring, 'dayhour');
$value = isset ( $_POST [ " options_ " . $tmpkeyextra ]) ? dol_mktime ( $_POST [ " options_ " . $tmpkeyextra . " hour " ], $_POST [ " options_ " . $tmpkeyextra . " min " ], 0 , $_POST [ " options_ " . $tmpkeyextra . " month " ], $_POST [ " options_ " . $tmpkeyextra . " day " ], $_POST [ " options_ " . $tmpkeyextra . " year " ]) : $datenotinstring ;
2018-07-05 21:42:34 +02:00
}
2020-05-13 13:29:50 +02:00
2018-07-05 21:42:34 +02:00
//TODO Improve element and rights detection
2020-07-27 14:04:41 +02:00
if ( $action == 'edit_extras' && $permok && GETPOST ( 'attribute' , 'none' ) == $tmpkeyextra )
2018-07-05 21:42:34 +02:00
{
2019-12-03 11:17:29 +01:00
$fieldid = 'id' ;
if ( $object -> table_element == 'societe' ) $fieldid = 'socid' ;
print '<form enctype="multipart/form-data" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post" name="formextra">' ;
2018-07-05 21:42:34 +02:00
print '<input type="hidden" name="action" value="update_extras">' ;
2020-07-27 14:04:41 +02:00
print '<input type="hidden" name="attribute" value="' . $tmpkeyextra . '">' ;
2019-12-03 11:17:29 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="' . $fieldid . '" value="' . $object -> id . '">' ;
2020-07-27 14:04:41 +02:00
print $extrafields -> showInputField ( $tmpkeyextra , $value , '' , '' , '' , 0 , $object -> id , $object -> table_element );
2014-10-14 17:00:06 +02:00
2019-12-03 11:17:29 +01:00
print '<input type="submit" class="button" value="' . dol_escape_htmltag ( $langs -> trans ( 'Modify' )) . '">' ;
2014-10-14 17:00:06 +02:00
2018-07-05 21:42:34 +02:00
print '</form>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-07-27 14:04:41 +02:00
//var_dump($tmpkeyextra.'-'.$value.'-'.$object->table_element);
print $extrafields -> showOutputField ( $tmpkeyextra , $value , '' , $object -> table_element );
2018-07-05 21:42:34 +02:00
}
2018-07-05 22:35:40 +02:00
2018-06-13 13:00:08 +02:00
print '</td>' ;
2019-11-13 19:35:39 +01:00
print '</tr>' . " \n " ;
2018-06-13 13:00:08 +02:00
}
}
2017-06-07 16:44:04 +02:00
2018-06-13 13:00:08 +02:00
// Add code to manage list depending on others
// TODO Test/enhance this with a more generic solution
2019-11-13 19:35:39 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ))
2018-06-13 13:00:08 +02:00
{
print " \n " ;
print '
2020-08-16 22:03:11 +02:00
< script >
2018-07-05 21:42:34 +02:00
jQuery ( document ) . ready ( function () {
function showOptions ( child_list , parent_list )
{
2018-03-09 19:10:52 +01:00
var val = $ ( " select[name= " + parent_list + " ] " ) . val ();
2018-07-05 21:42:34 +02:00
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 " ;
}
}
?>
<!-- END PHP TEMPLATE extrafields_view . tpl . php -->