/* GET request for all current forum topics * * Parameters: * none * * Returns: array with fields: * post_id * title * text * author * latest * replyamount */ $getTopics = function ($sql) { $expected = array(); $params = fetchGetParams($expected); /* Check all parameters were included and set */ foreach ($expected as $expect) { if (!isset($params[$expect])) { die("Error: {$expect} parameter was not set."); } } $cookie = validateCookie(); if (!$cookie) { header('HTTP/1.1 401 Unauthorized'); die("Invalid cookie"); } /* Specify query */ $query = "select forum_topics.id as post_id, title, " . "users.name as author, " . "case when " . "max(forum_posts.last_modified) is null then forum_topics.last_modified " . "else max(forum_posts.last_modified) " . "end as latest, " . "count(forum_posts.id) as replyamount " . "from forum_topics " . "inner join users " . "on users.id = posted_by " . "left join forum_posts " . "on post_id = forum_topics.id " . "group by forum_topics.id " . "order by forum_topics.last_modified asc;"; /* Perform query */ $result = db_query($query, $sql);
1 => string 'practice_date' (length=13) 2 => string 'start_time' (length=10) 3 => string 'end_time' (length=8) 4 => string 'reported' (length=8) 5 => string 'reported_start_time' (length=19) 6 => string 'reported_end_time' (length=17) 7 => string 'has_sub_name' (length=12) 8 => string 'sub_for_name' (length=12) 9 => string 'instructor_name' */ $fetchCalendarEvents = function ($sql) { /* Parameters */ $expected = array(); $optional = array("date"); $params = fetchGetParams($expected); $optional_params = fetchGetParams($optional); /* Check all parameters were included and set */ foreach ($expected as $expect) { if (!isset($params[$expect])) { die("Error: {$expect} parameter was not set."); } } $cookie = validateCookie(); if (!$cookie) { header('HTTP/1.1 401 Unauthorized'); die("Invalid cookie"); } $userid = $cookie["id"]; /* Sql escaping */ db_escape($userid, $sql); /* Specify query */