PDA

View Full Version : toggle admin option from frontend


Dr.CustUmz
03-17-2015, 06:11 AM
i have got this working using
build_options();
in my php code

but i have a major issue, when i toggle it, i get a fatal user error i cant solve. im not changing any other options so idk what would cause this.

product attached in 2nd post
im trying to create a simple toggle for turning a plugin on or off from the front end.

it looks a little like this.

the toggle:
<if condition="$vboptions[setting_name] == 1">
<a href="#" onclick="setting_off()">ON</a>
<else />
<a href="#" onclick="setting_on()">OFF</a>
</if>

the js: (requires jQuery)
function setting_off(){
$.ajax({
type: "GET", url: "?do=settingoff"
});
}
function setting_on(){
$.ajax({
type: "GET", url: "?do=settingon"
});
}

the php: (external, and i do include global)
if ($_GET['do'] == 'settingon'){
$vbulletin->db->query("
UPDATE `" . TABLE_PREFIX . "setting`
SET value='1'
WHERE value=0
");
}
// ##### Set Off #######
if ($_GET['do'] == 'settingoff'){
$vbulletin->db->query("
UPDATE `" . TABLE_PREFIX . "setting`
SET value='0'
WHERE value=1
");
}

this all works just fine and dandy, my issue is even though it switches the status of the product, i still have to go into the admincp options and hit save before it really applies (even though before i hit save its already switched) if that makes since...

the href just switches this
https://vborg.vbsupport.ru/attachment.php?attachmentid=152073&stc=1&d=1426576191

yet i actually have to come here and hit save before it really applies.

any ideas how to avoid that process so my href takes care of all of that


important addition!
when i hit save here it seems to be affecting something else also and i have to breakout the tools.php to fix it
Fatal User Error: The requested language does not exist, reset via tools.php. in ....\includes\functions.php on line 1417

Dr.CustUmz
03-17-2015, 07:02 AM
attached product, someone please help =(

DO NOT USE THIS ON A LIVE SITE YOU RISK THE CHANCE OF RUINING YOUR DB!!!!!!

kh99
03-20-2015, 10:27 AM
Are you still working on this? I think the problem is that your UPDATE query sets all options that had a setting of 0 to 1. What you want is something like
UPDATE setting SET value=0 WHERE varname='drc_fl'

Dr.CustUmz
03-20-2015, 03:40 PM
i got it all working already, went about it without ajax and i caught that mysql error, thanks though kev.