Work on management of default values

This commit is contained in:
Laurent Destailleur
2017-04-28 14:05:28 +02:00
parent cfde27820e
commit defce63a24
5 changed files with 42 additions and 18 deletions

View File

@@ -187,29 +187,30 @@ $texthelp=$langs->trans("PageUrlForDefaultValues");
if ($mode == 'createform') $texthelp.=$langs->trans("PageUrlForDefaultValuesCreate", 'societe/card.php');
else $texthelp.=$langs->trans("PageUrlForDefaultValuesList", 'societe/list.php');
$texturl=$form->textwithpicto($langs->trans("Url"), $texthelp);
print_liste_field_titre($texturl,$_SERVER["PHP_SELF"],'defaulturl','',$param,'',$sortfield,$sortorder);
print_liste_field_titre($texturl,$_SERVER["PHP_SELF"],'page,param','',$param,'',$sortfield,$sortorder);
$texthelp=$langs->trans("TheKeyIsTheNameOfHtmlField");
if ($mode != 'sortorder') $textkey=$form->textwithpicto($langs->trans("Key"), $texthelp);
else $textkey=$form->textwithpicto($langs->trans("Key"), $texthelp);
print_liste_field_titre($textkey,$_SERVER["PHP_SELF"],'defaultkey','',$param,'',$sortfield,$sortorder);
print_liste_field_titre($textkey,$_SERVER["PHP_SELF"],'param','',$param,'',$sortfield,$sortorder);
if ($mode != 'sortorder')
{
$texthelp=$langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
// See list into GETPOST
$texthelp.='__USERID__<br>';
$texthelp.='__SUPERVISORID__<br>';
$texthelp.='__MYCOUNTRYID__<br>';
$texthelp.='__DAY__<br>';
$texthelp.='__MONTH__<br>';
$texthelp.='__YEAR__<br>';
if (! empty($conf->multicompany->enabled)) $texthelp.='__ENTITYID__<br>';
$textvalue=$form->textwithpicto($langs->trans("Value"), $texthelp);
$textvalue=$form->textwithpicto($langs->trans("Value"), $texthelp, 1, 'help', '', 0, 2, '');
}
else
{
$texthelp='ASC or DESC';
$textvalue=$form->textwithpicto($langs->trans("SortOrder"), $texthelp);
}
print_liste_field_titre($textvalue, $_SERVER["PHP_SELF"], 'defaultvalue', '', $param, '', $sortfield, $sortorder);
print_liste_field_titre($textvalue, $_SERVER["PHP_SELF"], 'value', '', $param, '', $sortfield, $sortorder);
if (! empty($conf->multicompany->enabled) && !$user->entity) print_liste_field_titre($langs->trans("Entity"),$_SERVER["PHP_SELF"],'entity,page','',$param,'',$sortfield,$sortorder);
print '<td align="center"></td>';
print "</tr>\n";

View File

@@ -253,17 +253,35 @@ function GETPOST($paramname,$check='',$method=0,$filter=NULL,$options=NULL)
$out = isset($_GET[$paramname])?$_GET[$paramname]:(isset($_POST[$paramname])?$_POST[$paramname]:'');
// Management of default values
if (! isset($_GET['sortfield'])) // If we did a click on a field so sort, we do no appl default values
{
if (! empty($_GET['action']) && $_GET['action'] == 'create' && ! empty($paramname) && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
{
$relativepathstring = preg_replace('/\.[a-z]+$/', '', $_SERVER["PHP_SELF"]);
$relativepathstring = $_SERVER["PHP_SELF"];
if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring);
$relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
$relativepathstring = preg_replace('/^\//', '', $relativepathstring);
$relativepathstring=dol_string_nospecial($relativepathstring, '-');
// $relativepathstring is now string that identify the page: '_societe_card', '_agenda_card', ...
$keyfordefaultvalue = 'MAIN_DEFAULT_FOR_'.$relativepathstring.'_'.$paramname;
global $conf;
if (isset($conf->global->$keyfordefaultvalue)) $out = $conf->global->$keyfordefaultvalue;
global $user;
if (! empty($user->default_values)) // $user->default_values defined from menu default values, and values loaded not at first
{
//var_dump($user->default_values[$relativepathstring]['createform']);
if (isset($user->default_values[$relativepathstring]['createform'][$paramname])) $out = $user->default_values[$relativepathstring]['createform'][$paramname];
}
}
// Management of default search_filters
elseif (preg_match('/list.php$/', $_SERVER["PHP_SELF"]) && ! empty($paramname) && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
{
$relativepathstring = $_SERVER["PHP_SELF"];
if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring);
$relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
$relativepathstring = preg_replace('/^\//', '', $relativepathstring);
global $user;
if (! empty($user->default_values)) // $user->default_values defined from menu default values, and values loaded not at first
{
//var_dump($user->default_values[$relativepathstring]);
if (isset($user->default_values[$relativepathstring]['filters'][$paramname])) $out = $user->default_values[$relativepathstring]['filters'][$paramname];
}
}
}
}
elseif ($method==1) $out = isset($_GET[$paramname])?$_GET[$paramname]:'';
@@ -303,6 +321,11 @@ function GETPOST($paramname,$check='',$method=0,$filter=NULL,$options=NULL)
global $user;
$out = $user->id;
}
elseif ($reg[1] == 'SUPERVISORID')
{
global $user;
$out = $user->fk_user;
}
elseif ($reg[1] == 'ENTITYID')
{
global $conf;

View File

@@ -428,7 +428,7 @@ ClickToShowDescription=Click to show description
DependsOn=This module need the module(s)
RequiredBy=This module is required by module(s)
TheKeyIsTheNameOfHtmlField=The key is the name of the html field. This need to have technical knowledges to read the content of the HTML page to get the key name of a field.
PageUrlForDefaultValues=You must enter here the relative url of the page. Examples:
PageUrlForDefaultValues=You must enter here the relative url of the page. If you include parameters in URL, the default values will be effective if all parameters are set to same value. Examples:
PageUrlForDefaultValuesCreate=<br>For form to create a new thirdparty, it is <strong>%s</strong>
PageUrlForDefaultValuesList=<br>For page that list thirdparties, it is <strong>%s</strong>
GoIntoTranslationMenuToChangeThis=A translation has been found for the key with this code, so to change this value, you must edit it fom Home-Setup-translation.

View File

@@ -180,7 +180,7 @@ if (! defined('NOREQUIREDB'))
//print "Will work with data into entity instance number '".$conf->entity."'";
// Here we read database (llx_const table and llx_default_values) and define $conf->global->XXX var.
// Here we read database (llx_const table) and define $conf->global->XXX var.
$conf->setValues($db);
}

View File

@@ -376,7 +376,7 @@ class User extends CommonObject
{
if (! empty($obj->page) && ! empty($obj->type) && ! empty($obj->param))
{
$user->default_values[$obj->page][$obj->type][$obj->param]=$obj->value;
$this->default_values[$obj->page][$obj->type][$obj->param]=$obj->value;
}
}
$this->db->free($resql);