diff --git a/htdocs/core/ajax/constantonoff.php b/htdocs/core/ajax/constantonoff.php index c4d57726ea5..dccc5ddb009 100644 --- a/htdocs/core/ajax/constantonoff.php +++ b/htdocs/core/ajax/constantonoff.php @@ -51,9 +51,11 @@ $action = GETPOST('action', 'aZ09'); // set or del $name = GETPOST('name', 'alpha'); $entity = GETPOSTINT('entity'); $value = (GETPOST('value', 'aZ09') != '' ? GETPOST('value', 'aZ09') : 1); +$userconst = GETPOSTINT('userconst'); + // Security check -if (empty($user->admin)) { +if (empty($user->admin) && empty($userconst)) { httponly_accessforbidden('This ajax component can be called by admin user only'); } @@ -64,12 +66,24 @@ if (empty($user->admin)) { // Registering the new value of constant if (!empty($action) && !empty($name)) { - if ($action == 'set') { // Test on permission not required here. Already done into test on user->admin in header. - dolibarr_set_const($db, $name, $value, 'chaine', 0, '', $entity); - } elseif ($action == 'del') { // Test on permission not required here. Already done into test on user->admin in header. - dolibarr_del_const($db, $name, $entity); - if ($entity == 1) { // Sometimes the param was saved in both entity 0 and 1. When we work on master entity, we should clean also if entity is 0 - dolibarr_del_const($db, $name, 0); + if ($userconst) { + $tmpuser = new User($db); + $tmpuser->id = $userconst; + if ($tmpuser->id == $user->id || $user->hasRight('user', 'user', 'lire')) { + if ($action == 'set') { // Test on permission not required here. Already done into test on user->admin in header. + dol_set_user_param($db, $conf, $tmpuser, array($name => $value)); + } elseif ($action == 'del') { // Test on permission not required here. Already done into test on user->admin in header. + dol_set_user_param($db, $conf, $tmpuser, array($name => '')); + } + } + } else { + if ($action == 'set') { // Test on permission not required here. Already done into test on user->admin in header. + dolibarr_set_const($db, $name, $value, 'chaine', 0, '', $entity); + } elseif ($action == 'del') { // Test on permission not required here. Already done into test on user->admin in header. + dolibarr_del_const($db, $name, $entity); + if ($entity == 1) { // Sometimes the param was saved in both entity 0 and 1. When we work on master entity, we should clean also if entity is 0 + dolibarr_del_const($db, $name, 0); + } } } } else { diff --git a/htdocs/core/js/lib_head.js.php b/htdocs/core/js/lib_head.js.php index 4e36e049832..e4777781938 100644 --- a/htdocs/core/js/lib_head.js.php +++ b/htdocs/core/js/lib_head.js.php @@ -566,18 +566,21 @@ function hideMessage(fieldId,message) { * @param int strict Strict (0=?, 1=?) * @param int forcereload Force reload * @param int userid User id - * @param int value Value to set * @param string token Token + * @param int value Value to set + * @param int userconst 1=On/Off of user constant instead of global const * @return boolean */ -function setConstant(url, code, input, entity, strict, forcereload, userid, token, value) { +function setConstant(url, code, input, entity, strict, forcereload, userid, token, value, userconst) { var saved_url = url; /* avoid undefined url */ + $.post( url, { action: "set", name: code, entity: entity, token: token, - value: value + value: value, + userconst: userconst }, function() { /* handler for success of post */ console.log("Ajax url request to set constant is a success. Make complementary actions and then forcereload="+forcereload+" value="+value); @@ -666,23 +669,26 @@ function setConstant(url, code, input, entity, strict, forcereload, userid, toke * Used by button to set on/off * Call url then make complementary action (like show/hide, enable/disable or set another option). * - * @param {string} url Url (warning: as any url called in ajax mode, the url called here must not renew the token) - * @param {string} code Code - * @param {string} input Array of complementary actions to do if success - * @param {int} entity Entity - * @param {int} strict Strict - * @param {int} forcereload Force reload - * @param {int} userid User id - * @param {string} token Token + * @param string url Url (warning: as any url called in ajax mode, the url called here must not renew the token) + * @param string code Code + * @param string input Array of complementary actions to do if success + * @param int entity Entity + * @param int strict Strict + * @param int forcereload Force reload + * @param int userid User id + * @param string token Token + * @param int userconst 1=On/Off of user constant instead of global const * @return boolean */ -function delConstant(url, code, input, entity, strict, forcereload, userid, token) { +function delConstant(url, code, input, entity, strict, forcereload, userid, token, userconst) { var saved_url = url; /* avoid undefined url */ + $.post( url, { action: "del", name: code, entity: entity, - token: token + token: token, + userconst: userconst }, function() { console.log("Ajax url request to delete constant is success. Make complementary actions and then forcereload="+forcereload); diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index f3eeb22e30c..f0c04ffa7b8 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -637,10 +637,11 @@ function ajax_event($htmlname, $events) * @param string $suffix Suffix to use on the name of the switch picto when option is on. Example: '', '_red' * @param string $mode Add parameter &mode= to the href link (Used for href link) * @param string $morecss More CSS + * @param int $userconst 1=OnOff for user constant of user $userconst * @return string * @see ajax_object_onoff() to update the status of an object */ -function ajax_constantonoff($code, $input = array(), $entity = null, $revertonoff = 0, $strict = 0, $forcereload = 0, $marginleftonlyshort = 2, $forcenoajax = 0, $setzeroinsteadofdel = 0, $suffix = '', $mode = '', $morecss = 'inline-block') +function ajax_constantonoff($code, $input = array(), $entity = null, $revertonoff = 0, $strict = 0, $forcereload = 0, $marginleftonlyshort = 2, $forcenoajax = 0, $setzeroinsteadofdel = 0, $suffix = '', $mode = '', $morecss = 'inline-block', $userconst = 0) { global $conf, $langs, $user; @@ -665,6 +666,7 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof var entity = \''.dol_escape_js($entity).'\'; var strict = \''.dol_escape_js((string) $strict).'\'; var userid = \''.dol_escape_js((string) $user->id).'\'; + var userconst = '.((int) $userconst).'; var yesButton = \''.dol_escape_js($langs->transnoentities("Yes")).'\'; var noButton = \''.dol_escape_js($langs->transnoentities("No")).'\'; var token = \''.currentToken().'\'; @@ -676,7 +678,7 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof if (input.alert.set.noButton) noButton = input.alert.set.noButton; confirmConstantAction("set", url, code, input, input.alert.set, entity, yesButton, noButton, strict, userid, token); } else { - setConstant(url, code, input, entity, 0, '.((int) $forcereload).', userid, token); + setConstant(url, code, input, entity, 0, '.((int) $forcereload).', userid, token, 1, userconst); } }); @@ -688,18 +690,23 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof confirmConstantAction("del", url, code, input, input.alert.del, entity, yesButton, noButton, strict, userid, token); } else {'; if (empty($setzeroinsteadofdel)) { - $out .= ' delConstant(url, code, input, entity, 0, '.((int) $forcereload).', userid, token);'; + $out .= ' delConstant(url, code, input, entity, 0, '.((int) $forcereload).', userid, token, userconst);'; } else { - $out .= ' setConstant(url, code, input, entity, 0, '.((int) $forcereload).', userid, token, 0);'; + $out .= ' setConstant(url, code, input, entity, 0, '.((int) $forcereload).', userid, token, 0, userconst);'; } $out .= ' } }); }); '."\n"; + if ($userconst) { + $value = getDolUserString($code); + } else { + $value = getDolGlobalString($code); + } $out .= ''; - $out .= ''.($revertonoff ? img_picto($langs->trans("Enabled"), 'switch_on', '', 0, 0, 0, '', '', $marginleftonlyshort) : img_picto($langs->trans("Disabled"), 'switch_off', '', 0, 0, 0, '', '', $marginleftonlyshort)).''; - $out .= ''.($revertonoff ? img_picto($langs->trans("Disabled"), 'switch_off'.$suffix, '', 0, 0, 0, '', '', $marginleftonlyshort) : img_picto($langs->trans("Enabled"), 'switch_on'.$suffix, '', 0, 0, 0, '', '', $marginleftonlyshort)).''; + $out .= ''.($revertonoff ? img_picto($langs->trans("Enabled"), 'switch_on', '', 0, 0, 0, '', '', $marginleftonlyshort) : img_picto($langs->trans("Disabled"), 'switch_off', '', 0, 0, 0, '', '', $marginleftonlyshort)).''; + $out .= ''.($revertonoff ? img_picto($langs->trans("Disabled"), 'switch_off'.$suffix, '', 0, 0, 0, '', '', $marginleftonlyshort) : img_picto($langs->trans("Enabled"), 'switch_on'.$suffix, '', 0, 0, 0, '', '', $marginleftonlyshort)).''; $out .= "\n"; } diff --git a/htdocs/user/virtualcard.php b/htdocs/user/virtualcard.php index e788d821625..93fb7b22530 100644 --- a/htdocs/user/virtualcard.php +++ b/htdocs/user/virtualcard.php @@ -73,9 +73,9 @@ $permissiontoedit = ((($object->id == $user->id) && $user->hasRight('user', 'sel if ($action == 'update' && $permissiontoedit) { $tmparray = array(); - $tmparray['USER_PUBLIC_MORE'] = (GETPOST('USER_PUBLIC_MORE') ? GETPOST('USER_PUBLIC_MORE') : ''); + $tmparray['USER_PUBLIC_MORE'] = GETPOST('USER_PUBLIC_MORE', 'alphanohtml'); - dolibarr_set_const($db, 'USER_PUBLIC_MORE', $tmparray['USER_PUBLIC_MORE'], 'chaine', 0, '', $conf->entity); + dol_set_user_param($db, $conf, $object, array('USER_PUBLIC_MORE' => $tmparray['USER_PUBLIC_MORE'])); } if ($action == 'setUSER_ENABLE_PUBLIC' && $permissiontoedit) { @@ -97,6 +97,7 @@ $form = new Form($db); $person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname; $title = $person_name." - ".$langs->trans('Info'); $help_url = ''; + llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-user page-virtualcard'); @@ -145,8 +146,8 @@ if (getDolUserInt('USER_ENABLE_PUBLIC', 0, $object)) { $fullexternaleurltovirtualcard = $object->getOnlineVirtualCardUrl('', 'external'); $fullinternalurltovirtualcard = $object->getOnlineVirtualCardUrl('', 'internal'); - $showUserSocialNetworks = getDolGlobalString('USER_PUBLIC_HIDE_SOCIALNETWORKS'); - $showSocieteSocialNetworks = getDolGlobalString('USER_PUBLIC_HIDE_SOCIALNETWORKS_BUSINESS'); + $showUserSocialNetworks = !getDolUserString('USER_PUBLIC_HIDE_SOCIALNETWORKS', '', $object); + $showSocieteSocialNetworks = !getDolUserString('USER_PUBLIC_HIDE_SOCIALNETWORKS_BUSINESS', '', $object); print '