Reduce diplicate code
This commit is contained in:
parent
36ad17cc95
commit
285203ed0e
@ -270,7 +270,7 @@ if ($action == 'create')
|
||||
print '<table class="border centpercent">'."\n";
|
||||
foreach($object->fields as $key => $val)
|
||||
{
|
||||
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;
|
||||
if (in_array($key, array('rowid', 'entity', 'date_creation', 'date_validation', 'tms', 'fk_user_creat', 'fk_user_modif', 'fk_user_valid', 'import_key'))) continue;
|
||||
print '<tr id="field_'.$key.'">';
|
||||
print '<td';
|
||||
print ' class="titlefieldcreate';
|
||||
|
||||
@ -380,7 +380,6 @@ print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"")
|
||||
print '<tr class="liste_titre">';
|
||||
foreach($object->fields as $key => $val)
|
||||
{
|
||||
if (in_array($key, array('fk_user_creat', 'fk_user_valid', 'fk_user_modif', 'date_creation', 'date_validation', 'tms', 'import_key', 'status'))) continue;
|
||||
$align='';
|
||||
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
|
||||
if (in_array($val['type'], array('timestamp'))) $align.=' nowrap';
|
||||
@ -414,16 +413,6 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
|
||||
$parameters=array('arrayfields'=>$arrayfields);
|
||||
$reshook=$hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
|
||||
print $hookmanager->resPrint;
|
||||
// Rest of fields search
|
||||
foreach($object->fields as $key => $val)
|
||||
{
|
||||
if (! in_array($key, array('fk_user_creat', 'fk_user_valid', 'fk_user_modif', 'date_creation', 'date_validation', 'tms', 'import_key', 'status'))) continue;
|
||||
$align='';
|
||||
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
|
||||
if (in_array($val['type'], array('timestamp'))) $align.=' nowrap';
|
||||
if ($key == 'status') $align.=($align?' ':'').'center';
|
||||
if (! empty($arrayfields['t.'.$key]['checked'])) print '<td class="liste_titre'.($align?' '.$align:'').'"><input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'"></td>';
|
||||
}
|
||||
// Action column
|
||||
print '<td class="liste_titre" align="right">';
|
||||
$searchpicto=$form->showFilterButtons();
|
||||
@ -437,7 +426,6 @@ print '</tr>'."\n";
|
||||
print '<tr class="liste_titre">';
|
||||
foreach($object->fields as $key => $val)
|
||||
{
|
||||
if (in_array($key, array('fk_user_creat', 'fk_user_valid', 'fk_user_modif', 'date_creation', 'date_validation', 'tms', 'import_key', 'status'))) continue;
|
||||
$align='';
|
||||
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
|
||||
if (in_array($val['type'], array('timestamp'))) $align.='nowrap';
|
||||
@ -462,16 +450,6 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
|
||||
$parameters=array('arrayfields'=>$arrayfields);
|
||||
$reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
|
||||
print $hookmanager->resPrint;
|
||||
// Rest of fields title
|
||||
foreach($object->fields as $key => $val)
|
||||
{
|
||||
if (! in_array($key, array('fk_user_creat', 'fk_user_valid', 'fk_user_modif', 'date_creation', 'date_validation', 'tms', 'import_key', 'status'))) continue;
|
||||
$align='';
|
||||
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
|
||||
if (in_array($val['type'], array('timestamp'))) $align.=' nowrap';
|
||||
if ($key == 'status') $align.=($align?' ':'').'center';
|
||||
if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n";
|
||||
}
|
||||
print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ')."\n";
|
||||
print '</tr>'."\n";
|
||||
|
||||
@ -504,7 +482,6 @@ while ($i < min($num, $limit))
|
||||
print '<tr class="oddeven">';
|
||||
foreach($object->fields as $key => $val)
|
||||
{
|
||||
if (in_array($key, array('fk_user_creat', 'fk_user_valid', 'fk_user_modif', 'date_creation', 'date_validation', 'tms', 'import_key', 'status'))) continue; // Discard some field output at end
|
||||
$align='';
|
||||
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
|
||||
if (in_array($val['type'], array('timestamp'))) $align.='nowrap';
|
||||
@ -553,30 +530,6 @@ while ($i < min($num, $limit))
|
||||
$parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
|
||||
$reshook=$hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
|
||||
print $hookmanager->resPrint;
|
||||
// Rest of fields
|
||||
foreach($object->fields as $key => $val)
|
||||
{
|
||||
if (! in_array($key, array('fk_user_creat', 'fk_user_valid', 'fk_user_modif', 'date_creation', 'date_validation', 'tms', 'import_key', 'status'))) continue; // Keep only field not yet already output
|
||||
$align='';
|
||||
if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center';
|
||||
if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap';
|
||||
if ($key == 'status') $align.=($align?' ':'').'center';
|
||||
if (! empty($arrayfields['t.'.$key]['checked']))
|
||||
{
|
||||
print '<td'.($align?' class="'.$align.'"':'').'>';
|
||||
if (in_array($val['type'], array('date'))) print dol_print_date($db->jdate($obj->$key), 'day', 'tzuser');
|
||||
elseif (in_array($val['type'], array('datetime','timestamp'))) print dol_print_date($db->jdate($obj->$key), 'dayhour', 'tzuser');
|
||||
elseif ($key == 'status') print $object->getLibStatut(3);
|
||||
else print $obj->$key;
|
||||
print '</td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
if (! empty($val['isameasure']))
|
||||
{
|
||||
if (! $i) $totalarray['pos'][$totalarray['nbfield']]='t.'.$key;
|
||||
$totalarray['val']['t.'.$key] += $obj->$key;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Action column
|
||||
print '<td class="nowrap" align="center">';
|
||||
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
|
||||
|
||||
@ -97,7 +97,7 @@ if (empty($reshook))
|
||||
{
|
||||
foreach ($object->fields as $key => $val)
|
||||
{
|
||||
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'import_key'))) continue; // Ignore special fields
|
||||
if (in_array($key, array('rowid', 'entity', 'date_creation', 'date_validation', 'tms', 'fk_user_creat', 'fk_user_modif', 'fk_user_validation', 'import_key'))) continue; // Ignore special fields
|
||||
|
||||
$object->$key=GETPOST($key,'alpha');
|
||||
if ($val['notnull'] && $object->$key == '')
|
||||
@ -215,7 +215,7 @@ jQuery(document).ready(function() {
|
||||
// Part to create
|
||||
if ($action == 'create')
|
||||
{
|
||||
print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Inventory")));
|
||||
print load_fiche_titre($langs->trans("NewInventory", $langs->transnoentitiesnoconv("MyInventory")));
|
||||
|
||||
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
@ -227,18 +227,49 @@ if ($action == 'create')
|
||||
print '<table class="border centpercent">'."\n";
|
||||
foreach($object->fields as $key => $val)
|
||||
{
|
||||
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'import_key'))) continue;
|
||||
print '<tr><td';
|
||||
if (in_array($key, array('rowid', 'entity', 'date_creation', 'date_validation', 'tms', 'fk_user_creat', 'fk_user_modif', 'fk_user_valid', 'import_key'))) continue;
|
||||
print '<tr id="field_'.$key.'">';
|
||||
print '<td';
|
||||
print ' class="titlefieldcreate';
|
||||
if ($val['notnull']) print ' fieldrequired';
|
||||
print '"';
|
||||
print '>'.$langs->trans($val['label']).'</td><td><input class="flat" type="text" name="'.$key.'" value="'.(GETPOST($key,'alpha')?GETPOST($key,'alpha'):'').'"></td></tr>';
|
||||
if ($val['notnull'] > 0) print ' fieldrequired';
|
||||
if ($val['type'] == 'text') print ' tdtop';
|
||||
print '"';
|
||||
print '>';
|
||||
print $langs->trans($val['label']);
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
$defaultcss='minwidth100';
|
||||
if ($val['type'] == 'text')
|
||||
{
|
||||
print '<textarea class="flat quatrevingtpercent" rows="'.ROWS_4.'" name="'.$key.'">';
|
||||
print GETPOST($key,'none');
|
||||
print '</textarea>';
|
||||
}
|
||||
elseif (is_array($val['arrayofkeyval']))
|
||||
{
|
||||
print $form->selectarray($key, $val['arrayofkeyval'], GETPOST($key, 'int'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$cssforinput = empty($val['css'])?$defaultcss:$val['css'];
|
||||
print '<input class="flat'.($cssforinput?' '.$cssforinput:'').'" class="'.$cssforinput.'" type="text" name="'.$key.'" value="'.(GETPOST($key,'alpha')?GETPOST($key,'alpha'):'').'">';
|
||||
}
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
// Other attributes
|
||||
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
|
||||
|
||||
print '</table>'."\n";
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
print '<div class="center"><input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'"> <input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'"></div>';
|
||||
print '<div class="center">';
|
||||
print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">';
|
||||
print ' ';
|
||||
print '<input type="button" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" onclick="javascript:history.go(-1)">'; // Cancel for create doe not post form
|
||||
print '</div>';
|
||||
|
||||
print '</form>';
|
||||
}
|
||||
@ -258,8 +289,40 @@ if (($id || $ref) && $action == 'edit')
|
||||
dol_fiche_head();
|
||||
|
||||
print '<table class="border centpercent">'."\n";
|
||||
// print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input class="flat" type="text" size="36" name="label" value="'.$label.'"></td></tr>';
|
||||
// LIST_OF_TD_LABEL_FIELDS_EDIT
|
||||
foreach($object->fields as $key => $val)
|
||||
{
|
||||
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;
|
||||
|
||||
print '<tr><td';
|
||||
print ' class="titlefieldcreate';
|
||||
if ($val['notnull'] > 0) print ' fieldrequired';
|
||||
if ($val['type'] == 'text') print ' tdtop';
|
||||
print '"';
|
||||
print '>'.$langs->trans($val['label']).'</td>';
|
||||
print '<td>';
|
||||
$defaultcss='minwidth100';
|
||||
if ($val['type'] == 'text')
|
||||
{
|
||||
print '<textarea class="flat quatrevingtpercent" rows="'.ROWS_4.'" name="'.$key.'">';
|
||||
print GETPOST($key,'none')?GETPOST($key,'none'):$object->$key;
|
||||
print '</textarea>';
|
||||
}
|
||||
elseif (is_array($val['arrayofkeyval']))
|
||||
{
|
||||
print $form->selectarray($key, $val['arrayofkeyval'], GETPOST($key, 'int')!=''?GETPOST($key, 'int'):$object->$key);
|
||||
}
|
||||
else
|
||||
{
|
||||
$cssforinput = empty($val['css'])?$defaultcss:$val['css'];
|
||||
print '<input class="flat'.($cssforinput?' '.$cssforinput:'').'" type="text" name="'.$key.'" value="'.(GETPOST($key,'alpha')?GETPOST($key,'alpha'):$object->$key).'">';
|
||||
}
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
// Other attributes
|
||||
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
|
||||
|
||||
print '</table>';
|
||||
|
||||
dol_fiche_end();
|
||||
@ -273,6 +336,7 @@ if (($id || $ref) && $action == 'edit')
|
||||
|
||||
|
||||
|
||||
|
||||
// Part to show record
|
||||
if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create')))
|
||||
{
|
||||
|
||||
@ -73,9 +73,9 @@ class Inventory extends CommonObject
|
||||
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-1, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',),
|
||||
'ref' => array('type'=>'varchar(64)', 'label'=>'Ref', 'visible'=>1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>'Reference of object',),
|
||||
'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>20, 'notnull'=>1, 'index'=>1,),
|
||||
'title' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1, 'position'=>25, 'css'=>'minwidth300'),
|
||||
'fk_warehouse' => array('type'=>'integer', 'label'=>'Warehouse', 'visible'=>1, 'enabled'=>1, 'index'=>1,),
|
||||
'date_inventory' => array('type'=>'date', 'label'=>'DateValue', 'visible'=>1, 'enabled'=>1,),
|
||||
'title' => array('type'=>'varchar(255)', 'label'=>'Label', 'visible'=>1, 'enabled'=>1,),
|
||||
'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'index'=>1,),
|
||||
'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-1, 'enabled'=>1, 'position'=>500,),
|
||||
'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-1, 'enabled'=>1, 'position'=>501, 'notnull'=>1,),
|
||||
|
||||
@ -234,7 +234,7 @@ if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) &&
|
||||
{
|
||||
$obj = $db->fetch_object($resql);
|
||||
$id = $obj->rowid;
|
||||
header("Location: ".DOL_URL_ROOT.'/inventory/inventory_card.php?id='.$id);
|
||||
header("Location: ".DOL_URL_ROOT.'/inventory/card.php?id='.$id);
|
||||
exit;
|
||||
}
|
||||
|
||||
@ -333,7 +333,6 @@ print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"")
|
||||
print '<tr class="liste_titre">';
|
||||
foreach($object->fields as $key => $val)
|
||||
{
|
||||
if (in_array($key, array('fk_user_creat', 'fk_user_valid', 'fk_user_modif', 'date_creation', 'date_validation', 'tms', 'import_key', 'status'))) continue;
|
||||
$align='';
|
||||
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
|
||||
if (in_array($val['type'], array('timestamp'))) $align.=' nowrap';
|
||||
@ -366,15 +365,6 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
|
||||
$parameters=array('arrayfields'=>$arrayfields);
|
||||
$reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
|
||||
print $hookmanager->resPrint;
|
||||
// Rest of fields search
|
||||
foreach($object->fields as $key => $val)
|
||||
{
|
||||
if (! in_array($key, array('fk_user_creat', 'fk_user_valid', 'fk_user_modif', 'date_creation', 'date_validation', 'tms', 'import_key', 'status'))) continue;
|
||||
$align='';
|
||||
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
|
||||
if (in_array($val['type'], array('timestamp'))) $align.=' nowrap';
|
||||
if (! empty($arrayfields['t.'.$key]['checked'])) print '<td class="liste_titre'.($align?' '.$align:'').'"><input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'"></td>';
|
||||
}
|
||||
// Action column
|
||||
print '<td class="liste_titre" align="right">';
|
||||
$searchpicto=$form->showFilterButtons();
|
||||
@ -388,7 +378,6 @@ print '</tr>'."\n";
|
||||
print '<tr class="liste_titre">';
|
||||
foreach($object->fields as $key => $val)
|
||||
{
|
||||
if (in_array($key, array('fk_user_creat', 'fk_user_valid', 'fk_user_modif', 'date_creation', 'date_validation', 'tms', 'import_key', 'status'))) continue;
|
||||
$align='';
|
||||
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
|
||||
if (in_array($val['type'], array('timestamp'))) $align.='nowrap';
|
||||
@ -412,15 +401,6 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
|
||||
$parameters=array('arrayfields'=>$arrayfields);
|
||||
$reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
|
||||
print $hookmanager->resPrint;
|
||||
// Rest of fields title
|
||||
foreach($object->fields as $key => $val)
|
||||
{
|
||||
if (! in_array($key, array('fk_user_creat', 'fk_user_valid', 'fk_user_modif', 'date_creation', 'date_validation', 'tms', 'import_key', 'status'))) continue;
|
||||
$align='';
|
||||
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
|
||||
if (in_array($val['type'], array('timestamp'))) $align.=' nowrap';
|
||||
if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n";
|
||||
}
|
||||
print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ')."\n";
|
||||
print '</tr>'."\n";
|
||||
|
||||
@ -453,7 +433,6 @@ while ($i < min($num, $limit))
|
||||
print '<tr class="oddeven">';
|
||||
foreach($object->fields as $key => $val)
|
||||
{
|
||||
if (in_array($key, array('fk_user_creat', 'fk_user_valid', 'fk_user_modif', 'date_creation', 'date_validation', 'tms', 'import_key', 'status'))) continue;
|
||||
$align='';
|
||||
if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center';
|
||||
if (in_array($val['type'], array('timestamp'))) $align.='nowrap';
|
||||
@ -501,29 +480,6 @@ while ($i < min($num, $limit))
|
||||
$parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
|
||||
$reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
|
||||
print $hookmanager->resPrint;
|
||||
// Rest of fields
|
||||
foreach($object->fields as $key => $val)
|
||||
{
|
||||
if (! in_array($key, array('fk_user_creat', 'fk_user_valid', 'fk_user_modif', 'date_creation', 'date_validation', 'tms', 'import_key', 'status'))) continue;
|
||||
$align='';
|
||||
if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center';
|
||||
if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap';
|
||||
if ($key == 'status') $align.=($align?' ':'').'center';
|
||||
if (! empty($arrayfields['t.'.$key]['checked']))
|
||||
{
|
||||
print '<td'.($align?' class="'.$align.'"':'').'>';
|
||||
if (in_array($val['type'], array('date','datetime','timestamp'))) print dol_print_date($db->jdate($obj->$key), 'dayhour');
|
||||
elseif ($key == 'status') print $object->getLibStatut(3);
|
||||
else print $obj->$key;
|
||||
print '</td>';
|
||||
if (! $i) $totalarray['nbfield']++;
|
||||
if (! empty($val['isameasure']))
|
||||
{
|
||||
if (! $i) $totalarray['pos'][$totalarray['nbfield']]='t.'.$key;
|
||||
$totalarray['val']['t.'.$key] += $obj->$key;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Action column
|
||||
print '<td class="nowrap" align="center">';
|
||||
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
|
||||
|
||||
Loading…
Reference in New Issue
Block a user