Skip to content

Commit

Permalink
Work on management of default values
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Apr 28, 2017
1 parent cfde278 commit defce63
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
9 changes: 5 additions & 4 deletions htdocs/admin/defaultvalues.php
Expand Up @@ -187,29 +187,30 @@
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";
Expand Down
43 changes: 33 additions & 10 deletions htdocs/core/lib/functions.lib.php
Expand Up @@ -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 (! empty($_GET['action']) && $_GET['action'] == 'create' && ! empty($paramname) && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
if (! isset($_GET['sortfield'])) // If we did a click on a field so sort, we do no appl default values
{
$relativepathstring = preg_replace('/\.[a-z]+$/', '', $_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;
if (! empty($_GET['action']) && $_GET['action'] == 'create' && ! 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]['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]:'';
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion htdocs/langs/en_US/admin.lang
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion htdocs/master.inc.php
Expand Up @@ -180,7 +180,7 @@

//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);
}

Expand Down
4 changes: 2 additions & 2 deletions htdocs/user/class/user.class.php
Expand Up @@ -376,7 +376,7 @@ function fetch($id='', $login='', $sid='', $loadpersonalconf=0, $entity=-1)
{
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);
Expand All @@ -387,7 +387,7 @@ function fetch($id='', $login='', $sid='', $loadpersonalconf=0, $entity=-1)
return -3;
}
}

return 1;
}

Expand Down

0 comments on commit defce63

Please sign in to comment.