2
0
forked from Wavyzz/dolibarr

Debug v21

This commit is contained in:
Laurent Destailleur
2024-10-30 02:38:59 +01:00
parent 318148354b
commit c8c4bd4e7f
4 changed files with 91 additions and 73 deletions

View File

@@ -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,6 +66,17 @@ if (empty($user->admin)) {
// Registering the new value of constant
if (!empty($action) && !empty($name)) {
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.
@@ -72,6 +85,7 @@ if (!empty($action) && !empty($name)) {
dolibarr_del_const($db, $name, 0);
}
}
}
} else {
httponly_accessforbidden('Param action and name is required', 403);
}

View File

@@ -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);

View File

@@ -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 .= ' }
});
});
</script>'."\n";
if ($userconst) {
$value = getDolUserString($code);
} else {
$value = getDolGlobalString($code);
}
$out .= '<div id="confirm_'.$code.'" title="" style="display: none;"></div>';
$out .= '<span id="set_'.$code.'" class="valignmiddle inline-block linkobject '.(getDolGlobalString($code) ? 'hideobject' : '').($morecss ? ' '.$morecss : '').'">'.($revertonoff ? img_picto($langs->trans("Enabled"), 'switch_on', '', 0, 0, 0, '', '', $marginleftonlyshort) : img_picto($langs->trans("Disabled"), 'switch_off', '', 0, 0, 0, '', '', $marginleftonlyshort)).'</span>';
$out .= '<span id="del_'.$code.'" class="valignmiddle inline-block linkobject '.(getDolGlobalString($code) ? '' : 'hideobject').($morecss ? ' '.$morecss : '').'">'.($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)).'</span>';
$out .= '<span id="set_'.$code.'" class="valignmiddle inline-block linkobject '.($value ? 'hideobject' : '').($morecss ? ' '.$morecss : '').'">'.($revertonoff ? img_picto($langs->trans("Enabled"), 'switch_on', '', 0, 0, 0, '', '', $marginleftonlyshort) : img_picto($langs->trans("Disabled"), 'switch_off', '', 0, 0, 0, '', '', $marginleftonlyshort)).'</span>';
$out .= '<span id="del_'.$code.'" class="valignmiddle inline-block linkobject '.($value ? '' : 'hideobject').($morecss ? ' '.$morecss : '').'">'.($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)).'</span>';
$out .= "\n";
}

View File

@@ -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 '<div class="urllink">';
print '<input type="text" id="publicurluser" class="quatrevingtpercentminusx" value="'.$fullexternaleurltovirtualcard.'">';
@@ -205,85 +206,78 @@ if (getDolUserInt('USER_ENABLE_PUBLIC', 0, $object)) {
print '<tr class="oddeven" id="tredit"><td>';
print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("Photo"));
print '</td><td>';
print ajax_constantonoff("USER_PUBLIC_HIDE_PHOTO", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition');
print ajax_constantonoff("USER_PUBLIC_HIDE_PHOTO", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object->id);
print "</td></tr>\n";
// Job position
print '<tr class="oddeven" id="tredit"><td>';
print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("PostOrFunction"));
print '</td><td>';
print ajax_constantonoff("USER_PUBLIC_HIDE_JOBPOSITION", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition');
print ajax_constantonoff("USER_PUBLIC_HIDE_JOBPOSITION", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object->id);
print "</td></tr>\n";
// Email
print '<tr class="oddeven" id="tredit"><td>';
print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("Email"));
print '</td><td>';
print ajax_constantonoff("USER_PUBLIC_HIDE_EMAIL", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition');
print ajax_constantonoff("USER_PUBLIC_HIDE_EMAIL", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object->id);
print "</td></tr>\n";
// Office phone
print '<tr class="oddeven" id="tredit"><td>';
print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("PhonePro"));
print '</td><td>';
print ajax_constantonoff("USER_PUBLIC_HIDE_OFFICE_PHONE", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition');
print ajax_constantonoff("USER_PUBLIC_HIDE_OFFICE_PHONE", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object->id);
print "</td></tr>\n";
// Office fax
print '<tr class="oddeven" id="tredit"><td>';
print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("Fax"));
print '</td><td>';
print ajax_constantonoff("USER_PUBLIC_HIDE_OFFICE_FAX", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition');
print ajax_constantonoff("USER_PUBLIC_HIDE_OFFICE_FAX", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object->id);
print "</td></tr>\n";
// User mobile
print '<tr class="oddeven" id="tredit"><td>';
print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("PhoneMobile"));
print '</td><td>';
print ajax_constantonoff("USER_PUBLIC_HIDE_USER_MOBILE", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition');
print ajax_constantonoff("USER_PUBLIC_HIDE_USER_MOBILE", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object->id);
print "</td></tr>\n";
// Social networks
print '<tr class="oddeven" id="tredit"><td>';
print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("SocialNetworksInformation"));
print '</td><td>';
print ajax_constantonoff("USER_PUBLIC_HIDE_SOCIALNETWORKS", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition');
print ajax_constantonoff("USER_PUBLIC_HIDE_SOCIALNETWORKS", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object->id);
print "</td></tr>\n";
// Show list of socialnetworks for user
if (empty($showUserSocialNetworks)) {
print '<tr class="liste_titre" id="tramount">';
print '<td>'.$langs->trans("SocialNetworksUser").'</td>';
print '<td></td>';
print "</tr>\n";
if ($showUserSocialNetworks) {
$socialnetworks = $object->socialnetworks;
if (!empty($socialnetworks)) {
foreach ($socialnetworks as $key => $networkVal) {
print '<tr class="oddeven">';
print '<td>'.dol_escape_htmltag($key).'</td><td>';
print ajax_constantonoff('USER_SOCIALNETWORK_'.strtoupper($key));
print '<td> &nbsp; &nbsp; '.$langs->trans("Hide").' '.dol_escape_htmltag($key).'</td><td>';
print ajax_constantonoff('USER_SOCIALNETWORK_'.strtoupper($key), array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object->id);
print '</td>';
print "</tr>";
}
}
print '<tr class="liste_titre" id="tramount">';
print '<td></td>';
print '<td></td>';
print "</tr>\n";
}
// Birth date
print '<tr class="oddeven" id="tredit"><td>';
print $langs->trans("ShowOnVCard", $langs->transnoentitiesnoconv("Birthdate"));
print '</td><td>';
print ajax_constantonoff("USER_PUBLIC_SHOW_BIRTH", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition');
print ajax_constantonoff("USER_PUBLIC_SHOW_BIRTH", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object->id);
print "</td></tr>\n";
// Address
print '<tr class="oddeven" id="tredit"><td>';
print $langs->trans("ShowOnVCard", $langs->transnoentitiesnoconv("Address"));
print '</td><td>';
print ajax_constantonoff("USER_PUBLIC_SHOW_ADDRESS", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition');
print ajax_constantonoff("USER_PUBLIC_SHOW_ADDRESS", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object->id);
print "</td></tr>\n";
print '<tr class="liste_titre">';
@@ -295,35 +289,32 @@ if (getDolUserInt('USER_ENABLE_PUBLIC', 0, $object)) {
print '<tr class="oddeven" id="tramount"><td>';
print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("CompanySection"));
print '</td><td>';
print ajax_constantonoff("USER_PUBLIC_HIDE_COMPANY", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition');
print ajax_constantonoff("USER_PUBLIC_HIDE_COMPANY", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object->id);
print "</td></tr>\n";
if (!getDolUserString('USER_PUBLIC_HIDE_COMPANY', '', $object)) {
// Social networks
print '<tr class="oddeven" id="tredit"><td>';
print $langs->trans("HideOnVCard", $langs->transnoentitiesnoconv("SocialNetworksInformation"));
print '</td><td>';
print ajax_constantonoff("USER_PUBLIC_HIDE_SOCIALNETWORKS_BUSINESS", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition');
print ajax_constantonoff("USER_PUBLIC_HIDE_SOCIALNETWORKS_BUSINESS", array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object->id);
print "</td></tr>\n";
// show list of social networks for company
if (empty($showSocieteSocialNetworks)) {
print '<tr class="liste_titre" id="tramount">';
print '<td>'.$langs->trans("SocialNetworksBusiness").'</td>';
print '<td></td>';
print "</tr>\n";
if ($showSocieteSocialNetworks) {
$listofnetworks = $mysoc->socialnetworks;
if (!empty($listofnetworks)) {
foreach ($listofnetworks as $key => $networkVal) {
print '<tr class="oddeven">';
print '<td>'.dol_escape_htmltag($key).'</td><td>';
print ajax_constantonoff('SOCIETE_PUBLIC_SOCIALNETWORKS_'.strtoupper($key), array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition');
print '<td> &nbsp; &nbsp; '.$langs->trans("Hide").' '.dol_escape_htmltag($key).'</td><td>';
print ajax_constantonoff('SOCIETE_PUBLIC_SOCIALNETWORKS_'.strtoupper($key), array(), null, 0, 0, 1, 2, 0, 0, '', '', 'reposition', $object->id);
print '</td>';
print "</tr>";
}
}
}
}
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Other").'</td>';