From 02102cb66592a65cf8123d1a6deaec4050f099a8 Mon Sep 17 00:00:00 2001 From: TheMrNomis Date: Thu, 10 Dec 2015 13:57:43 +0100 Subject: [PATCH] saving categories preferences --- categoriesHandling.php | 63 ++++++++++++++++++++++++++++++++++++++++++ index.php | 6 +++- update-categories.php | 9 ++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 categoriesHandling.php create mode 100644 update-categories.php diff --git a/categoriesHandling.php b/categoriesHandling.php new file mode 100644 index 0000000..de1720c --- /dev/null +++ b/categoriesHandling.php @@ -0,0 +1,63 @@ + $cat_value) + { + $catPostName = 'cat_'.$cat_id; + if(isset($_POST[$catPostName])) + $_SESSION['categorieStatus'][$cat_id] = ($_POST[$catPostName] == 'on'); + else + $_SESSION['categorieStatus'][$cat_id] = false; + } +} + +/** + * @brief saves the categories preferences from $_SESSION to a cookie + */ +function saveCategoriesSessionToCookie() +{ + setcookie('categorieStatus', serialize($_SESSION['categorieStatus']), strtotime('+6 months'), null, null, false, true); +} +?> diff --git a/index.php b/index.php index e63bc14..18eb07e 100644 --- a/index.php +++ b/index.php @@ -2,8 +2,11 @@ session_start(); include_once('databaseOperations.php'); include_once('datetimeOperations.php'); +include_once('categoriesHandling.php'); $db = connect(); +initCategories($db); + if(isset($_GET['w'])&&is_numeric($_GET['w'])) $weekOffset = $_GET['w']; else @@ -61,7 +64,7 @@ else $cat_id = $categories[$cat_it]['cat_id']; $cat_title = $categories[$cat_it]['cat_title']; ?> - + />
+
diff --git a/update-categories.php b/update-categories.php new file mode 100644 index 0000000..1719de8 --- /dev/null +++ b/update-categories.php @@ -0,0 +1,9 @@ +