Example #1
0
 function addEntry()
 {
     $foodle = new Data_Foodle($this->fdb);
     $foodle->updateFromPost($this->user);
     #echo '<pre>'; print_r($foodle); exit;
     $foodle->save();
     if (isset($this->user->email)) {
         $this->sendMail($foodle);
     }
     $newurl = FoodleUtils::getUrl() . 'foodle/' . $foodle->identifier . '#distribute';
     SimpleSAML_Utilities::redirect($newurl);
     exit;
 }
Example #2
0
 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');
 }
Example #3
0
 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);
 }
Example #4
0
 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();
 }
Example #5
0
    public function getHTML($body = NULL)
    {
        if (empty($body)) {
            $body = $this->body;
        }
        $body = Data_Foodle::cleanMarkdownInput($body);
        return '<!DOCTYPE html>
		<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
		<head xml:lang="en">

			<meta charset="utf-8" />	

		<style type="text/css">


		/* ------ Buttons  ----- */



		/* --- links --- */

		a, a:link, a:visited, a:active {
		    color: #633;
		    text-decoration: none;
		}
		a:hover{
		    text-decoration: underline;
		}
		a.lesmer {
		    float: right;
		    margin: 1em;
		}

		span.grey {
			color: #aaa;
		}


		html{
		    height: 100%;

		/*    font-family: Arial, Verdana, sans-serif;*/
		}
		body{
		    height: 100%;
		}
		p {
		    margin-top:     10px;
		    margin-bottom:  10px;
		}


		table {
			border-collapse:collapse;
			border-spacing:0;
			margin: .6em;
		}

		td {
			border: 1px solid #ccc;
		}
		td,th {
			border: 1px solid #aaa;
		/*	text-align: center; */
		}
		th {
			background: #dda;
			padding: .1em 1em .1em 1em;

		}

		dt {
			font-size: 105%;
			color: #600;
			font-weight: bold;
		}
		dd p {
			margin: 0px 1em .1em 0px;
		}


		/* --- General --- */


		body {
			margin: 0px;
			padding: 0px;
			font-family: Helvetica, Arial, sans-serif;
		}
		p {
		/*	margin: 0px;
			padding: 0px;*/
		}

		div#content {
			padding: 1em;
		}
		div#content h1 {
			margin-top: 0px;
		}
		
		hr {
			height: 0px; color: #ccc; 
		}


		/*  --- Header ---  */


		#header {
		    z-index: 0;
		    background-color: #f00;
		}

		#header #logo {
			color: #fff;
			font-family: "Verdana", "sans-serif";
			font-weight: bold;
			letter-spacing: -0.12em;
			text-shadow: 0px 2px 0px #900;
			font-size: 30px;
		/*	position: absolute;
			top: 2px; left: 2px; */
			z-index: 10;
		}
		#header #version {
			font-weight: normal;
			letter-spacing: 0.1em;
			font-size: x-small;
			text-shadow: 0px 1px 0px #900;
		}
		#header #logo #news, #header #logo #mailinglist {
			font-weight: normal;
			letter-spacing: 0em;
		}


		/* --- headerbar --- */

		#headerbar {
		/*	position: absolute;
			top: 42px;
			width: 100%;

			*/
			background: #eee;
			border-top: 1px solid #ccc;
			border-bottom: 1px solid #ccc;
			margin: 3px 0px 0px 0px; 
			padding: 0px 0px 0px 0px;
			z-index: 3;
		}
		#headerbar #breadcrumb {
			float: left; 
			margin: 9px 1em;

		}




		/*  --- Footer ---  */

		#footer {
		/*	width: 100%;*/
			clear: both;
			border-top: 1px solid #ccc;
			text-align: center;
			margin-top: 1em; 
			padding: 0px 0px 0px 0px;
			z-index: 1;
			color: #888;
		}




		</style>


			<title>' . $this->subject . '</title> 



		</head>
		<body>





		<!-- Grey header bar below -->
		<div id="headerbar" style="clear: both">
		<p id="breadcrumb">' . $this->subject . '</p>
		<p style="height: 0px; clear: both"></p>
		</div><!-- /#headerbar -->



		<div id="content">


				' . $body . '

		</div><!-- /#content -->

		<div id="footer">
			This mail was sent via <a href="https://foodl.org">foodl.org</a>. Please report misuse &mdash; <a href="https://foodl.org/support">Foodle Support</a>.
		</div><!-- /#footer -->


		</body>
		</html>';
    }
Example #6
0
 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');
 }
Example #7
0
 public function readResponses(Data_Foodle $foodle, $maxago = NULL, $includeInvites = TRUE)
 {
     $maxclause = '';
     if ($maxago !== null) {
         $maxclause = ' AND UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(entries.updated) < ' . mysql_real_escape_string($maxago);
     }
     if (!$includeInvites) {
         $maxclause .= ' AND invitation = false ';
     }
     $sql = "\n\t\t\tSELECT entries.*, \n\t\t\t\tUNIX_TIMESTAMP(entries.created) AS createdu,\n\t\t\t\tUNIX_TIMESTAMP(entries.updated) AS updatedu,\n\t\t\t\tuser.userid AS profile\n\t\t\t\tFROM entries LEFT JOIN user ON (entries.userid = user.userid)\n\t\t\tWHERE foodleid='" . $foodle->identifier . "' " . $maxclause . "\n\t\t\tORDER BY entries.invitation, entries.updated desc, entries.created desc";
     $rows = $this->q($sql);
     $responses = array();
     if (!empty($rows)) {
         foreach ($rows as $row) {
             $newResponse = new Data_FoodleResponse($this, $foodle);
             $newResponse->loadedFromDB = TRUE;
             $newResponse->userid = $row['userid'];
             $newResponse->username = $row['username'];
             $newResponse->email = $row['email'];
             $newResponse->notes = $row['notes'];
             $newResponse->updated = $row['updatedu'];
             $newResponse->created = $row['createdu'];
             $newResponse->hasprofile = !empty($row['profile']);
             $ruser = $this->readUser($row['userid']);
             if ($ruser !== false) {
                 $newResponse->user = $ruser;
             }
             #				echo '<pre>'; print_r($row); #exit;
             $newResponse->invitation = !empty($row['invitation']);
             if (empty($row['response'])) {
                 $newResponse->response = NULL;
             } else {
                 if (self::isJSON($row['response'][0])) {
                     #echo 'Decoded resposne as json: <pre>' . $row['response'] . '</pre>';
                     $newResponse->response = json_decode($row['response'], TRUE);
                 } else {
                     #echo 'Decoded resposne not as json: <pre>' . $row['response'] . '';
                     #print_r($newResponse);
                     #echo '</pre>';
                     $newResponse->response = self::parseOldResponse($row['response']);
                 }
             }
             #$newResponse->icalfill();
             $nof = $foodle->getNofColumns();
             // echo "nof" . $nof; exit;
             if ($newResponse->response['type'] == 'manual' && count($newResponse->response['data']) !== $nof) {
                 $newResponse->invalid = TRUE;
                 if (count($newResponse->response['data']) < $nof) {
                     $remaining = $nof - count($newResponse->response['data']);
                     for ($i = 0; $i < $remaining; $i++) {
                         $newResponse->response['data'][] = NULL;
                     }
                 }
                 if (count($newResponse->response['data']) > $nof) {
                     $newResponse->response['data'] = array_slice($newResponse->response['data'], 0, $nof);
                 }
                 //	echo '<pre>'; print_r($newResponse); exit;
             }
             $responses[$row['userid']] = $newResponse;
         }
     }
     return $responses;
 }