diff options
author | Steve Dibb <beandog@gentoo.org> | 2010-02-11 20:17:46 -0700 |
---|---|---|
committer | Steve Dibb <beandog@gentoo.org> | 2010-02-11 20:17:46 -0700 |
commit | 32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b (patch) | |
tree | f9b8efa8def14998bc8f7a4fed123cc34c98f8db /preferences.php | |
parent | Zero (diff) | |
download | znurt-org-frontend-32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b.tar.gz znurt-org-frontend-32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b.tar.bz2 znurt-org-frontend-32a7a5f8d8b36ae6acb6e566ff3d371b7a145c4b.zip |
initial commit
Diffstat (limited to 'preferences.php')
-rw-r--r-- | preferences.php | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/preferences.php b/preferences.php new file mode 100644 index 0000000..4f0e3c2 --- /dev/null +++ b/preferences.php @@ -0,0 +1,87 @@ +<? + + /** + * A note about cookies + * + * Use the strict mode on in_array() since some funky stuff can go in there + * and be impossible to unset. For example, I accidentally, somehow, set + * the key name of an array to zero, and couldn't unset it. Whoops. + */ + + + $nocache = true; + + require_once 'inc.header1.php'; + + $section = $_GET['section']; + $submit = $_GET['submit']; + + switch($section) { + + case 'architectures': + + if($submit == 'Yay, cookies!') + $set = true; + elseif($submit == 'Reset Arches') + $reset = true; + + if($set) { + + if(!headers_sent() && count($_GET['arch'])) { + + $arr_keys = array_keys($_GET['arch']); + + // Check to see if the arches they selected aren't just + // the same ones as the default. + + $cookie = false; + + foreach($arr_keys as $name) { + if($cookie == false && in_array($name, $arr_arch, true) && !in_array($name, $arr_default_arch, true)) { + $cookie = true; + } + } + + // Add a cookie if their preferences are different + // and the arches selected are actually in there + if($cookie) { + + $expiration = time() + (86400 * 365); + + foreach($arr_arch as $name) { + if(in_array($name, $arr_keys, true)) { + setcookie("arch[$name]", 1, $expiration); + } + } + } + } + } + + if($reset || ($set && !$cookie)) { + + $time = time() - 86400; + + setcookie("arch[0]", "", $time); + + if(!headers_sent() && count($_COOKIE['arch'])) { + $arr_keys = array_keys($_COOKIE['arch']); + + foreach($arr_keys as $name) { + setcookie("arch[$name]", "", $time); + } + } + } + + break; + + } + + // Send them back to the homepage if they actually made changes + // Otherwise, let them play with the page some more. + + $url = $_SERVER['HTTP_REFERER']; + + if(!headers_sent() && $url) + header("Location: $url"); + +?>
\ No newline at end of file |