PDA

View Full Version : Update options outside of the settings menu?


DetroitYES
07-27-2012, 04:01 PM
I found this thread:

https://vborg.vbsupport.ru/showthread.php?t=157223

Which lead me to develop this code in my admincp for the product:


//...
$db->query_first("UPDATE " . TABLE_PREFIX . "setting SET " . TABLE_PREFIX . "setting.value = ".$_REQUEST['userid']." WHERE " . TABLE_PREFIX . "setting.varname = 'atdisg_featured_feed'");
print_cp_message('Featured user was updated successfully.', 'atdisg_admin.php?do=user_tracker');
//...


This executes correctly, and if I go to the option under the settings menu, displays the updated value correctly. However, I also have this code that generates a diffrent button if the id of the user being displayed for the row matches the setting. It only works correctly when I update the option via the settings menu, not via the query. In other words, $vbulletin->options['atdisg_featured_feed'] does not seem to be pulling from the database...



if ($row['userid'] == $vbulletin->options['atdisg_featured_feed']) {
$set_unset_featured = "<input style='border:2px solid #FF0000; cursor:pointer;' type=\"button\" class=\"button\" onclick=\"window.location.href = 'atdisg_admin.php?do=set_featured_user&userid=".$row['userid']."';\" value=\"Stop Featuring\">";
} else {
$set_unset_featured = "<input style='border:2px solid #00AA00; cursor:pointer;' type=\"button\" class=\"button\" onclick=\"window.location.href = 'atdisg_admin.php?do=set_featured_user&userid=".$row['userid']."';\" value=\"Set As Feature\">";
}



I have to assume this is due to the datastore Paul mentioned in the related thread:

They are stored as a serialized array in the datastore for general access, and ultimately, in the settings table.

Is there a way to update the datastore as well when I run the query?.. Or is there some reason that I should not update the options outside of settings?

--------------- Added 1343410605 at 1343410605 ---------------

#############UPDATE

i found the save_settings() function, on line ~430 of adminfunctions_options.php


/**
* Updates the setting table based on data passed in then rebuilds the datastore.
* Only entries in the array are updated (allows partial updates).
*@param array Array of settings. Format: [setting_name] = new_value
*/
function save_settings($settings)
{
//...

Sarteck
07-28-2012, 01:27 AM
Dude! Thanks for this! I've been using a "Daily Stuff" type of thing on my forum for a while now, and using the settings to save stuff like "Last Time Updated" so on and so forth, but I've always been doing it "manually." I never knew there was a built-in function, and sometimes some of my users get their "Daily Stuff" twice n a row.

I assume that was because of the datastore? I dunno, tbh, but I assume that using this function will change that if so. :3

DetroitYES
08-01-2012, 04:00 PM
Dude! Thanks for this! I've been using a "Daily Stuff" type of thing on my forum for a while now, and using the settings to save stuff like "Last Time Updated" so on and so forth, but I've always been doing it "manually." I never knew there was a built-in function, and sometimes some of my users get their "Daily Stuff" twice n a row.

I assume that was because of the datastore? I dunno, tbh, but I assume that using this function will change that if so. :3

Glad to help, and yes, it was due to the datastore which save_settings() updates along with the actual database column...