query("SELECT id, user_preferences, user_name FROM users"); $execute = false; // loop through user preferences and check for "bad" elements; rebuild preferences array and update database if(isset($_POST['execute'])){ $execute = true; } $serverTimeZone = lookupTimezone(0); while ($row = $db->fetchByAssoc($result)) { $adjustment = 'none'; if(isset($_POST[$row['id'].'adjust'])){ $adjustment = $_POST[$row['id'].'adjust']; } $string = "Preview"; if($execute)$string = "Updating"; echo ""; $the_old_prefs[] = $prefs; $the_new_prefs[] = $newprefs; unset($prefs); unset($newprefs); unset($newstr); } echo "
$string timezone preferences for user {$row['user_name']}..."; $prefs = array(); $newprefs = array(); $prefs = unserialize(base64_decode($row['user_preferences'])); $setTo = ''; $alreadySet = ''; if(!empty($prefs)){ foreach ($prefs as $key => $val) { if ($key == 'timez') { if(empty($prefs['timezone']) && $val != ''){ $hourAdjust = $adjustment; if($hourAdjust == 'none'){ $hourAdjust = 0; } $selectedZone = lookupTimezone($prefs['timez'] + $hourAdjust); if(!empty($selectedZone)){ $newprefs['timezone'] = $selectedZone; $newprefs['timez'] = $val; $setTo = $selectedZone; if(empty($prompt_users)){ $newprefs['ut']=1; }else{ $newprefs['ut']=0; } }else{ $newprefs['timezone'] = $serverTimeZone; $newprefs['timez'] = $val; $setTo = $serverTimeZone; if(empty($prompt_users)){ $newprefs['ut']=1; }else{ $newprefs['ut']=0; } } }else{ $newprefs[$key] = $val; if(!empty($prefs['timezone'])){ $alreadySet = 'Previously Set - '. $prefs['timezone']; } } }else{ $newprefs[$key] = $val; } } if($execute){ $newstr = mysql_real_escape_string(base64_encode(serialize($newprefs))); $db->query("UPDATE users SET user_preferences = '{$newstr}' WHERE id = '{$row['id']}'"); } } if(!empty($setTo)){ echo $setTo; }else{ if(!empty($alreadySet)){ echo $alreadySet; }else{ echo $serverTimeZone; $prefs['timezone'] = $serverTimeZone; } } echo ""; if(!empty($setTo)){ echo "Adjust: "; if($execute){ if(isset($_POST[$row['id'].'adjust'])){ echo $adjustment; } }else{ echo "'; } echo ' hour'; } echo ' '; echo "
"; if($execute){ echo "
All timezone preferences updated!

"; }else{ echo "Prompt users on login to confirm:
"; echo "  "; } echo " "; ?>