function prepare() { $parameters = null; $object = null; // All requests point at a specific Foodle if (self::route(false, '^/api/f/([^/]+)(/|$)', $parameters, $object)) { // print_r($parameters); Data_Foodle::requireValidIdentifier($parameters[1]); $this->foodleid = $parameters[1]; $this->foodle = $this->fdb->readFoodle($this->foodleid); if (self::route('get', '^/api/f/([^/]+)$', $parameters, $object)) { return $this->foodle->getView(); } else { if (self::route('get', '^/api/f/([^/]+)/responders$', $parameters, $object)) { $this->responses = $this->fdb->readResponses($this->foodle, NULL, FALSE); $respobj = array(); foreach ($this->responses as $key => $r) { $respobj[$key] = $r->getView(); } return $respobj; } else { if (self::route('get', '^/api/f/([^/]+)/discussion$', $parameters, $object)) { $discussion = $this->fdb->readDiscussion($this->foodle); return $discussion; } } } } throw new Exception('Invalid request parameters'); }
function __construct($config, $parameters) { parent::__construct($config, $parameters); if (count($parameters) < 1) { throw new Exception('Missing [foodleid] parameter in URL.'); } Data_Foodle::requireValidIdentifier($parameters[0]); $this->foodleid = $parameters[0]; $this->foodlepath = '/foodle/' . $this->foodleid; $this->foodle = $this->fdb->readFoodle($this->foodleid); }
function __construct($config, $parameters) { parent::__construct($config, $parameters); if (count($parameters) < 1) { throw new Exception('Missing [foodleid] parameter in URL.'); } $this->template = new SimpleSAML_XHTML_Template($this->config, 'foodleresponse.php', 'foodle_foodle'); $this->setLocale(); Data_Foodle::requireValidIdentifier($parameters[0]); $this->foodleid = $parameters[0]; $this->foodlepath = '/foodle/' . $this->foodleid; #Timer::tick('Preparation started'); $this->foodle = $this->fdb->readFoodle($this->foodleid); #Timer::tick('Foodle read'); // $this->foodle->getColumnDates(); // $this->calendarEnabled = $this->foodle->calendarEnabled(); // $this->timezoneEnable = $this->foodle->timeZoneEnabled(); // $this->datesonly = $this->foodle->datesOnly(); #Timer::tick('Timezone preparations'); $this->auth(); }
function prepare() { self::optionalAuth(); // All requests point at a specific Foodle if (self::route(false, '^/api/foodle/([^/]+)(/|$)', $parameters, $object)) { Data_Foodle::requireValidIdentifier($parameters[1]); $this->foodleid = $parameters[1]; $this->foodle = $this->fdb->readFoodle($this->foodleid); if (self::route('get', '^/api/foodle/([^/]+)$', $parameters, $object)) { return $this->foodle->getView($this->user); // Update existing foodle } else { if (self::route('post', '^/api/foodle/([^/]+)$', $parameters, $object)) { // $newFoodle = new Data_Foodle($this->fdb); $this->foodle->acl($this->user, 'write'); $this->foodle->updateFromPostAPI($this->user, $object); $this->fdb->saveFoodle($this->foodle); $this->foodle = $this->fdb->readFoodle($this->foodle->identifier); return $this->foodle; // Update existing foodle } else { if (self::route('delete', '^/api/foodle/([^/]+)$', $parameters, $object)) { // $newFoodle = new Data_Foodle($this->fdb); $this->foodle->acl($this->user, 'write'); $this->fdb->deleteFoodle($this->foodle); return true; } else { if (self::route('get', '^/api/foodle/([^/]+)/responders$', $parameters, $object)) { $this->responses = $this->fdb->readResponses($this->foodle, NULL, FALSE); $respobj = array(); foreach ($this->responses as $key => $r) { $respobj[$key] = $r->getView(); } return $respobj; } else { if (self::route('get', '^/api/foodle/([^/]+)/discussion$', $parameters, $object)) { $discussion = $this->fdb->readDiscussion($this->foodle); return $discussion; } else { if (self::route('post', '^/api/foodle/([^/]+)/discussion$', $parameters, $object)) { $comment = strip_tags($object); // addDiscussionEntry(Data_Foodle $foodle, Data_User $user, $message) { $this->fdb->addDiscussionEntry($this->foodle, $this->user, $comment); return $comment; // $currentResponse = $this->foodle->getMyResponse($this->user); // if (isset($object['response']) && isset($object['response']['data'])) { // $currentResponse->response = $object['response']; // } // $this->fdb->saveFoodleResponse($currentResponse); // return true; } else { if (self::route('post', '^/api/foodle/([^\\/]+)/myresponse$', $parameters, $object)) { // echo 'about to update response. User is'; print_r($this->user); exit; $currentResponse = $this->foodle->getMyResponse($this->user); if (isset($object['response']) && isset($object['response']['data'])) { $currentResponse->response = $object['response']; } if (isset($object['notes'])) { // $tz = filter_var($object, FILTER_SANITIZE_EMAIL); $currentResponse->notes = filter_var($object['notes'], FILTER_SANITIZE_SPECIAL_CHARS); } else { $currentResponse->notes = null; } $this->fdb->saveFoodleResponse($currentResponse); return true; } else { throw new Exception('Invalid request'); } } } } } } } } else { if (self::route('post', '^/api/foodle$', $parameters, $object)) { // header('Content-type: text/plain; charset=utf-8'); //print_r($object); $newFoodle = new Data_Foodle($this->fdb); $newFoodle->updateFromPostAPI($this->user, $object); $this->fdb->saveFoodle($newFoodle); $this->foodle = $this->fdb->readFoodle($newFoodle->identifier); //print_r($newFoodle); //exit; return $this->foodle; // if ($subrequest === 'discussion') { } } throw new Exception('Invalid request parameters'); }
public function readFoodle($id) { Data_Foodle::requireValidIdentifier($id); $sql = "\n\t\t\tSELECT *,\n\t\t\tIF(expire=0,null,UNIX_TIMESTAMP(expire)) AS expire_unix, \n\t\t\tIF(created=0,null,UNIX_TIMESTAMP(created)) AS createdu, \n\t\t\tIF(updated=0,null,UNIX_TIMESTAMP(updated)) AS updatedu \n\t\t\tFROM def WHERE id = '" . mysql_real_escape_string($id) . "'"; try { $row = $this->q1($sql); } catch (Exception $e) { throw new Exception('Could not lookup Foodle with id [' . $id . ']. May be it was deleted?'); } $foodle = new Data_Foodle($this); $foodle->identifier = $id; $foodle->name = $row['name']; $foodle->descr = stripslashes($row['descr']); $foodle->location = json_decode($row['location'], TRUE); $foodle->expire = $row['expire_unix']; $foodle->owner = $row['owner']; $foodle->allowanonymous = (bool) ($row['anon'] == '1'); $foodle->columntype = isset($row['columntype']) ? $row['columntype'] : null; $foodle->responsetype = isset($row['responsetype']) ? $row['responsetype'] : 'default'; $foodle->extrafields = Data_Foodle::decode($row['extrafields']); if (!empty($row['feed'])) { $foodle->feed = $row['feed']; } $foodle->created = $row['createdu']; $foodle->updated = $row['updatedu']; $foodle->datetime = Data_Foodle::decode($row['datetime']); if (!empty($row['timezone'])) { $foodle->timezone = $row['timezone']; } if (!empty($row['groupid'])) { $foodle->groupid = $row['groupid']; } if (self::isJSON($row['columns'][0])) { #echo 'Use new encoding format'; $foodle->columns = json_decode($row['columns'], TRUE); } else { #echo 'Using old decoding.'; $foodle->columns = FoodleUtils::parseOldColDef($row['columns']); } $maxdef = self::parseMaxDef($row['maxdef']); if (isset($row['restrictions'])) { $foodle->restrictions = json_decode($row['restrictions'], TRUE); } else { if ($maxdef[0]) { $foodle->maxentries = $maxdef[0]; $foodle->maxcolumn = $maxdef[1]; if ($foodle->maxcolumn === 0) { $foodle->restrictions = array('rows' => $maxdef[0]); } else { $foodle->restrictions = array('col' => array('col' => $maxdef[1] - 1, 'limit' => $maxdef[0])); } } } $foodle->loadedFromDB = TRUE; return $foodle; }