forked from Wavyzz/dolibarr
New: add possibility to set and del anothers constants
This commit is contained in:
@@ -30,6 +30,8 @@ if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
|
||||
require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
|
||||
$action=GETPOST('action','alpha');
|
||||
$name=GETPOST('name','alpha');
|
||||
|
||||
/*
|
||||
* View
|
||||
@@ -45,17 +47,16 @@ top_httphead();
|
||||
print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
|
||||
|
||||
// Registering the location of boxes
|
||||
if ((isset($_GET['action']) && ! empty($_GET['action'])) && (isset($_GET['name']) && ! empty($_GET['name'])) )
|
||||
if (! empty($action) && ! empty($name))
|
||||
{
|
||||
$entity = GETPOST('entity','int');
|
||||
$action = GETPOST('action', 'alpha');
|
||||
$name = GETPOST('name', 'alpha');
|
||||
$value = (GETPOST('value')?GETPOST('value'):1);
|
||||
|
||||
if ($user->admin)
|
||||
{
|
||||
if ($action == 'set')
|
||||
{
|
||||
dolibarr_set_const($db, $name, 1, 'chaine', 0, '', $entity);
|
||||
dolibarr_set_const($db, $name, $value, 'chaine', 0, '', $entity);
|
||||
}
|
||||
else if ($action == 'del')
|
||||
{
|
||||
|
||||
@@ -346,7 +346,7 @@ function ajax_combobox($htmlname, $event=array())
|
||||
* On/off button for constant
|
||||
*
|
||||
* @param string $code Name of constant
|
||||
* @param array $input Input element
|
||||
* @param array $input Input element (enable/disable or show/hide another element, set/del another constant)
|
||||
* @param int $entity Entity to set
|
||||
* @return void
|
||||
*/
|
||||
@@ -359,10 +359,11 @@ function ajax_constantonoff($code,$input=array(),$entity=false)
|
||||
$out= '<script type="text/javascript">
|
||||
$(function() {
|
||||
var input = '.json_encode($input).';
|
||||
var url = \''.DOL_URL_ROOT.'/core/ajax/constantonoff.php\';
|
||||
|
||||
// Set constant
|
||||
$("#set_'.$code.'").click(function() {
|
||||
$.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", {
|
||||
$.get( url, {
|
||||
action: \'set\',
|
||||
name: \''.$code.'\',
|
||||
entity: \''.$entity.'\'
|
||||
@@ -370,9 +371,10 @@ function ajax_constantonoff($code,$input=array(),$entity=false)
|
||||
function() {
|
||||
$("#set_'.$code.'").hide();
|
||||
$("#del_'.$code.'").show();
|
||||
$.each(input, function(type, data) {
|
||||
// Enable another element
|
||||
if (input.disabled && input.disabled.length > 0) {
|
||||
$.each(input.disabled, function(key,value) {
|
||||
if (type == "disabled") {
|
||||
$.each(data, function(key, value) {
|
||||
$("#" + value).removeAttr("disabled");
|
||||
if ($("#" + value).hasClass("butActionRefused") == true) {
|
||||
$("#" + value).removeClass("butActionRefused");
|
||||
@@ -380,17 +382,30 @@ function ajax_constantonoff($code,$input=array(),$entity=false)
|
||||
}
|
||||
});
|
||||
// Show another element
|
||||
} else if (input.showhide && input.showhide.length > 0) {
|
||||
$.each(input.showhide, function(key,value) {
|
||||
} else if (type == "showhide" || type == "show") {
|
||||
$.each(data, function(key, value) {
|
||||
$("#" + value).show();
|
||||
});
|
||||
// Set another constant
|
||||
} else if (type == "set") {
|
||||
$.each(data, function(key, value) {
|
||||
$("#set_" + key).hide();
|
||||
$("#del_" + key).show();
|
||||
$.get( url, {
|
||||
action: \'set\',
|
||||
name: key,
|
||||
value: value,
|
||||
entity: \''.$entity.'\'
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Del constant
|
||||
$("#del_'.$code.'").click(function() {
|
||||
$.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", {
|
||||
$.get( url, {
|
||||
action: \'del\',
|
||||
name: \''.$code.'\',
|
||||
entity: \''.$entity.'\'
|
||||
@@ -398,9 +413,10 @@ function ajax_constantonoff($code,$input=array(),$entity=false)
|
||||
function() {
|
||||
$("#del_'.$code.'").hide();
|
||||
$("#set_'.$code.'").show();
|
||||
$.each(input, function(type, data) {
|
||||
// Disable another element
|
||||
if (input.disabled && input.disabled.length > 0) {
|
||||
$.each(input.disabled, function(key,value) {
|
||||
if (type == "disabled") {
|
||||
$.each(data, function(key, value) {
|
||||
$("#" + value).attr("disabled", true);
|
||||
if ($("#" + value).hasClass("butAction") == true) {
|
||||
$("#" + value).removeClass("butAction");
|
||||
@@ -408,14 +424,26 @@ function ajax_constantonoff($code,$input=array(),$entity=false)
|
||||
}
|
||||
});
|
||||
// Hide another element
|
||||
} else if (input.showhide && input.showhide.length > 0) {
|
||||
$.each(input.showhide, function(key,value) {
|
||||
} else if (type == "showhide" || type == "hide") {
|
||||
$.each(data, function(key, value) {
|
||||
$("#" + value).hide();
|
||||
});
|
||||
// Delete another constant
|
||||
} else if (type == "del") {
|
||||
$.each(data, function(key, value) {
|
||||
$("#del_" + value).hide();
|
||||
$("#set_" + value).show();
|
||||
$.get( url, {
|
||||
action: \'del\',
|
||||
name: value,
|
||||
entity: \''.$entity.'\'
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
$out.= '<span id="set_'.$code.'" class="linkobject '.(! empty($conf->global->$code)?'hideobject':'').'">'.img_picto($langs->trans("Disabled"),'switch_off').'</span>';
|
||||
|
||||
Reference in New Issue
Block a user