2
0
forked from Wavyzz/dolibarr

Work on mandatory form fields

This commit is contained in:
Laurent Destailleur
2018-09-27 16:38:18 +02:00
parent e252a5f046
commit a623d80830
4 changed files with 28 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2017-2018 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2017-2018 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2017-2018 Regis Houssin <regis.houssin@capnetworks.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@@ -19,6 +19,11 @@
/** /**
* \file htdocs/admin/defaultvalues.php * \file htdocs/admin/defaultvalues.php
* \brief Page to set default values used used in a create form * \brief Page to set default values used used in a create form
* Default values are stored into $user->default_values[url]['createform']['querystring'|'_noquery_'][paramkey]=paramvalue
* Default filters are stored into $user->default_values[url]['filters']['querystring'|'_noquery_'][paramkey]=paramvalue
* Default sort order are stored into $user->default_values[url]['sortorder']['querystring'|'_noquery_'][paramkey]=paramvalue
* Default focus are stored into $user->default_values[url]['focus']['querystring'|'_noquery_'][paramkey]=paramvalue
* Mandatory fields are stored into $user->default_values[url]['mandatory']['querystring'|'_noquery_'][paramkey]=paramvalue
*/ */
require '../main.inc.php'; require '../main.inc.php';
@@ -234,6 +239,10 @@ if ($mode == 'focus')
{ {
print info_admin($langs->trans("FeatureNotYetAvailable")).'<br>'; print info_admin($langs->trans("FeatureNotYetAvailable")).'<br>';
} }
if ($mode == 'mandatory')
{
print info_admin($langs->trans("FeatureNotYetAvailable")).'<br>';
}
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" id="action" name="action" value="">'; print '<input type="hidden" id="action" name="action" value="">';
@@ -261,7 +270,7 @@ else
} }
print_liste_field_titre($textkey,$_SERVER["PHP_SELF"],'param','',$param,'',$sortfield,$sortorder); print_liste_field_titre($textkey,$_SERVER["PHP_SELF"],'param','',$param,'',$sortfield,$sortorder);
// Value // Value
if ($mode != 'focus') if ($mode != 'focus' && $mode != 'mandatory')
{ {
if ($mode != 'sortorder') if ($mode != 'sortorder')
{ {
@@ -301,7 +310,7 @@ print '<td>';
print '<input type="text" class="flat maxwidth100onsmartphone" name="defaultkey" value="">'; print '<input type="text" class="flat maxwidth100onsmartphone" name="defaultkey" value="">';
print '</td>'; print '</td>';
// Value // Value
if ($mode != 'focus') if ($mode != 'focus' && $mode != 'mandatory')
{ {
print '<td>'; print '<td>';
print '<input type="text" class="flat maxwidth100onsmartphone" name="defaultvalue" value="">'; print '<input type="text" class="flat maxwidth100onsmartphone" name="defaultvalue" value="">';
@@ -313,13 +322,14 @@ if (! empty($conf->multicompany->enabled) && !$user->entity)
print '<td>'; print '<td>';
print '<input type="text" class="flat" size="1" name="entity" value="'.$conf->entity.'">'; print '<input type="text" class="flat" size="1" name="entity" value="'.$conf->entity.'">';
print '</td>'; print '</td>';
print '<td align="center">';
} }
else else
{ {
print '<td align="center">'; print '<td align="center">';
print '<input type="hidden" name="entity" value="'.$conf->entity.'">'; print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
print '</td>';
} }
print '<td align="center">';
$disabled=''; $disabled='';
if (empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) $disabled=' disabled="disabled"'; if (empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) $disabled=' disabled="disabled"';
print '<input type="submit" class="button"'.$disabled.' value="'.$langs->trans("Add").'" name="add">'; print '<input type="submit" class="button"'.$disabled.' value="'.$langs->trans("Add").'" name="add">';
@@ -363,7 +373,7 @@ if ($result)
print '</td>'."\n"; print '</td>'."\n";
// Value // Value
if ($mode != 'focus') if ($mode != 'focus' && $mode != 'mandatory')
{ {
print '<td>'; print '<td>';
/*print '<input type="hidden" name="const['.$i.'][rowid]" value="'.$obj->rowid.'">'; /*print '<input type="hidden" name="const['.$i.'][rowid]" value="'.$obj->rowid.'">';
@@ -376,6 +386,9 @@ if ($result)
print '</td>'; print '</td>';
} }
// Multicompany
print '<td></td>';
// Actions // Actions
print '<td align="center">'; print '<td align="center">';
if ($action != 'edit' || GETPOST('rowid') != $obj->rowid) if ($action != 'edit' || GETPOST('rowid') != $obj->rowid)

View File

@@ -729,6 +729,11 @@ function defaultvalues_prepare_head()
$head[$h][2] = 'focus'; $head[$h][2] = 'focus';
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT."/admin/defaultvalues.php?mode=mandatory";
$head[$h][1] = $langs->trans("DefaultMandatory");
$head[$h][2] = 'mandatory';
$h++;
/*$head[$h][0] = DOL_URL_ROOT."/admin/translation.php?mode=searchkey"; /*$head[$h][0] = DOL_URL_ROOT."/admin/translation.php?mode=searchkey";
$head[$h][1] = $langs->trans("TranslationKeySearch"); $head[$h][1] = $langs->trans("TranslationKeySearch");
$head[$h][2] = 'searchkey'; $head[$h][2] = 'searchkey';

View File

@@ -430,7 +430,7 @@ function GETPOST($paramname, $check='none', $method=0, $filter=null, $options=nu
} }
elseif (isset($user->default_values[$relativepathstring]['filters'])) elseif (isset($user->default_values[$relativepathstring]['filters']))
{ {
foreach($user->default_values[$relativepathstring]['filters'] as $defkey => $defval) foreach($user->default_values[$relativepathstring]['filters'] as $defkey => $defval) // $defkey is a querystring like 'a=b&c=d', $defval is key of user
{ {
$qualified = 0; $qualified = 0;
if ($defkey != '_noquery_') if ($defkey != '_noquery_')
@@ -586,7 +586,6 @@ function GETPOST($paramname, $check='none', $method=0, $filter=null, $options=nu
// Save data into session if key start with 'search_' or is 'smonth', 'syear', 'month', 'year' // Save data into session if key start with 'search_' or is 'smonth', 'syear', 'month', 'year'
if (empty($method) || $method == 3 || $method == 4) if (empty($method) || $method == 3 || $method == 4)
{ {
//if (preg_match('/^search_/', $paramname) || in_array($paramname, array('sortorder', 'sortfield", 'smonth', 'syear', 'month', 'year')))
if (preg_match('/^search_/', $paramname) || in_array($paramname, array('sortorder','sortfield'))) if (preg_match('/^search_/', $paramname) || in_array($paramname, array('sortorder','sortfield')))
{ {
//var_dump($paramname.' - '.$out.' '.$user->default_values[$relativepathstring]['filters'][$paramname]); //var_dump($paramname.' - '.$out.' '.$user->default_values[$relativepathstring]['filters'][$paramname]);
@@ -595,8 +594,7 @@ function GETPOST($paramname, $check='none', $method=0, $filter=null, $options=nu
// - posted value not empty, or // - posted value not empty, or
// - if posted value is empty and a default value exists that is not empty (it means we did a filter to an empty value when default was not). // - if posted value is empty and a default value exists that is not empty (it means we did a filter to an empty value when default was not).
//if (! empty($out) || ! empty($user->default_values[$relativepathstring]['filters'][$paramname])) if ($out != '') // $out = '0' or 'abc', it is a search criteria to keep
if ($out != '') // $out = '0' like 'abc' is a search criteria to keep
{ {
$user->lastsearch_values_tmp[$relativepathstring][$paramname]=$out; $user->lastsearch_values_tmp[$relativepathstring][$paramname]=$out;
} }

View File

@@ -1437,6 +1437,7 @@ DefaultCreateForm=Default values (on forms to create)
DefaultSearchFilters=Default search filters DefaultSearchFilters=Default search filters
DefaultSortOrder=Default sort orders DefaultSortOrder=Default sort orders
DefaultFocus=Default focus fields DefaultFocus=Default focus fields
DefaultMandatory=Mandatory form fields
##### Products ##### ##### Products #####
ProductSetup=Products module setup ProductSetup=Products module setup
ServiceSetup=Services module setup ServiceSetup=Services module setup