/** * Calculates the current age of someone born on $birthdate. * Source: stackoverflow.com/questions/3776682/php-calculate-age * @param sing $birthdate The birthdate. * @return integer The calculated age. * @access public * @static */ public static function ageFromBirthdate($birthdate) { // convert to format: YYYY-MM-DD $clean_birthdate = date('Y-m-d', CakeTime::fromString($birthdate)); if (CakeTime::isFuture($clean_birthdate)) { throw new OutOfRangeException("Birthdate is in the future: {$clean_birthdate}", BedrockTime::EXCEPTION_CODE_FUTURE_BIRTHDATE); } //explode the date to get month, day and year $parts = explode('-', $clean_birthdate); //get age from date or birthdate $age = intval(date('md', date('U', mktime(0, 0, 0, $parts[1], $parts[2], $parts[0]))) > date('md') ? date('Y') - $parts[0] - 1 : date('Y') - $parts[0]); return $age; }
/** * checkFutureDate * Custom Validation Rule: Ensures a selected date is either the * present day or in the future. * * @param array $check Contains the value passed from the view to be validated * @return bool True if in the past or today, False otherwise */ public function checkFutureDate($check) { $value = array_values($check); return CakeTime::fromString($this->data[$this->alias]['document_date']) <= CakeTime::fromString($value[0]); }
protected function _validate() { $now = time(); $data = $this->request->data; $this->Provider->isOK = false; // Check consumer key if (empty($data['oauth_consumer_key'])) { return $this->Provider->reason = 'Missing consumer key.'; } // Check all required launch parameters if (empty($data['lti_message_type']) or !array_key_exists($data['lti_message_type'], $this->Provider->messageTypes)) { return $this->Provider->reason = 'Invalid or missing lti_message_type parameter.'; } if (empty($data['lti_version']) or !in_array($data['lti_version'], $this->Provider->LTI_VERSIONS)) { return $this->Provider->reason = 'Invalid or missing lti_version parameter.'; } switch ($data['lti_message_type']) { case 'ContentItemSelectionRequest': if (empty($data['content_item_return_url']) or !(strlen(trim($data['content_item_return_url'])) > 0)) { return $this->Provider->reason = 'Missing content_item_return_url parameter.'; } if (!empty($data['accept_media_types']) and strlen(trim($data['accept_media_types'])) > 0) { $mediaTypes = array_filter(explode(',', str_replace(' ', '', $data['accept_media_types'])), 'strlen'); $mediaTypes = array_unique($mediaTypes); } if (empty($mediaTypes)) { return $this->Provider->reason = 'No accept_media_types found.'; } $this->Provider->mediaTypes = $mediaTypes; if (!empty($data['accept_presentation_document_targets']) and strlen(trim($data['accept_presentation_document_targets'])) > 0) { $documentTargets = array_filter(explode(',', str_replace(' ', '', $data['accept_presentation_document_targets'])), 'strlen'); $documentTargets = array_unique($documentTargets); } if (empty($documentTargets)) { return $this->Provider->reason = 'Missing or empty accept_presentation_document_targets parameter.'; } foreach ($documentTargets as $documentTarget) { if (!in_array($documentTarget, ['embed', 'frame', 'iframe', 'window', 'popup', 'overlay', 'none'])) { return $this->Provider->reason = 'Invalid value in accept_presentation_document_targets parameter: ' . $documentTarget; } } $this->Provider->documentTargets = $documentTargets; if (!empty($data['accept_unsigned']) and !in_array($data['accept_unsigned'], ['true', 'false'])) { return $this->Provider->reason = 'Invalid value for accept_unsigned parameter: ' . $data['accept_unsigned']; } if (!empty($data['accept_multiple']) and !in_array($data['accept_multiple'], ['true', 'false'])) { return $this->Provider->reason = 'Invalid value for accept_multiple parameter: ' . $data['accept_multiple']; } if (!empty($data['accept_copy_advice']) and !in_array($data['accept_copy_advice'], ['true', 'false'])) { return $this->Provider->reason = 'Invalid value for accept_copy_advice parameter: ' . $data['accept_copy_advice']; } if (!empty($data['auto_create']) and !in_array($data['auto_create'], ['true', 'false'])) { return $this->Provider->reason = 'Invalid value for auto_create parameter: ' . $data['auto_create']; } if (!empty($data['can_confirm']) and !in_array($data['can_confirm'], ['true', 'false'])) { return $this->Provider->reason = 'Invalid value for can_confirm parameter: ' . $data['can_confirm']; } break; case 'basic-lti-launch-request': case 'DashboardRequest': if (empty($data['resource_link_id']) or !(strlen(trim($data['resource_link_id'])) > 0)) { return $this->Provider->reason = 'Missing resource link ID.'; } // fall through // fall through default: if (!empty($data['launch_presentation_document_target']) and !in_array($data['launch_presentation_document_target'], ['embed', 'frame', 'iframe', 'window', 'popup', 'overlay'])) { return $this->Provider->reason = 'Invalid value for launch_presentation_document_target parameter: ' . $data['launch_presentation_document_target']; } break; } # ### Get the consumer # $this->loadModel('Lti.Consumer'); $this->Consumer->id = $data['oauth_consumer_key']; $this->Consumer->read(); if (empty($this->Consumer->consumer_key)) { return $this->Provider->reason = 'Invalid consumer key.'; } if ($this->Consumer->protect) { if (empty($data['tool_consumer_instance_guid'])) { return $this->Provider->reason = 'A tool consumer GUID must be included in the launch request.'; } if (empty($this->Consumer->consumer_guid) or !($this->Consumer->consumer_guid == $data['tool_consumer_instance_guid'])) { return $this->Provider->reason = 'Request is from an invalid tool consumer.'; } } if (!$this->Consumer->enabled) { return $this->Provider->reason = 'Tool consumer has not been enabled by the tool provider.'; } if (!empty($this->Consumer->enable_from) and CakeTime::fromString($this->Consumer->enable_from) > $now) { return $this->Provider->reason = 'Tool consumer access is not yet available. It will be available from ' . $this->Consumer->enable_from; } if (!empty($this->Consumer->enable_until) and CakeTime::fromString($this->Consumer->enable_until) <= $now) { return $this->Provider->reason = 'Tool consumer access expired on ' . $this->Consumer->enable_until; } # ### Validate message parameter constraints # if (!empty($this->Provider->constraints)) { $invalid_parameters = array(); foreach ($this->Provider->constraints as $name => $constraint) { if (empty($constraint['messages']) || in_array($data['lti_message_type'], $constraint['messages'])) { if ($constraint['required']) { if (empty($data[$name]) or strlen(trim($data[$name])) <= 0) { $invalid_parameters[] = "{$name} (missing)"; continue; } } if (!empty($constraint['max_length'])) { if (strlen(trim($data[$name])) > $constraint['max_length']) { $invalid_parameters[] = "{$name} (too long)"; } } } } if (count($invalid_parameters) > 0) { return $this->Provider->reason = 'Invalid parameter(s): ' . implode(', ', $invalid_parameters) . '.'; } } $this->Provider->isOK = true; }
/** * checkPastDate * Custom Validation Rule: Ensures a selected date is either the * present day or in the past. * * @param array $check Contains the value passed from the view to be validated * @return bool True if in the past or today, False otherwise */ public function checkPastDate($check) { $value = array_values($check); return CakeTime::fromString($value[0]) <= CakeTime::fromString(date(Configure::read('databaseDateFormat'))); }
function compareDates($data) { return CakeTime::fromString($data['close_date']) > CakeTime::fromString($this->data[$this->alias]['open_date']); }
/** * checkPastDate * Custom Validation Rule: Ensures a selected date is either the * present day or in the past. * * @param array $check Contains the value passed from the view to be validated * @return bool True if in the past or today, False otherwise */ public function checkPastDate($check) { $value = array_values($check); return CakeTime::fromString($value['0']) <= CakeTime::fromString(date('Y-m-d')); }
/** * Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string. * * @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object * @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object * * @return string Parsed timestamp * @see CakeTime::fromString() * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting */ public function fromString($dateString, $timezone = NULL) { return $this->_engine->fromString($dateString, $timezone); }
/** * checkPastDate * Custom Validation Rule: Ensures a selected date is either the * present day or in the past. * * @param array $check Contains the value passed from the view to be validated * @return bool True if in the past or today, False otherwise */ public function checkPastDate($data, $key) { return CakeTime::fromString($data[$key]) <= CakeTime::fromString(date(Configure::read('databaseDateFormat'))); }
public function analysis() { $this->Cookie = $this->Components->load('Cookie'); $this->Cookie->type('rijndael'); $projects = array(); // $this->Cookie->time = '999 hours'; if ($this->request->is(array('post', 'put'))) { // debug($this->request->data); if (isset($this->request->data['Participant']['email'])) { $email = $this->request->data['Participant']['email']; } if (isset($this->request->data['Participant']['code'])) { $code = $this->request->data['Participant']['code']; } $project_id = -1; if (isset($this->request->data['Project']['Project'])) { $project_id = $this->request->data['Project']['Project']; } if ($this->data['Participant']['remember_me'] && isset($code) && isset($email)) { $cookie = array(); $cookie['email'] = $email; $cookie['code'] = $code; if (isset($project_id)) { $cookie['project_id'] = $project_id; } $this->Cookie->write('participantData', $cookie, true, '+2 weeks'); } else { if ($this->Cookie->check('participantData')) { $this->Cookie->destroy('participantData'); } } $projects = $this->getParticipantProjects($email, $code); App::uses('Folder', 'Utility'); App::uses('File', 'Utility'); if (isset($this->request->data['Participant']['analyze_File']) && $this->request->data['Participant']['analyze_File']['size'] > 0 && !empty($projects)) { /* ============================================= */ /* ==============Load analysis=================== */ /* ============================================= */ if ($this->request->data['Participant']['analyze_File']['size'] > $this->filesize2bytes(Configure::read('max_file_size'))) { $this->Session->setFlash("The file can not be more than " . Configure::read('max_file_size')); return $this->redirect(array('controller' => 'Participants', 'action' => 'analysis')); } $file = $this->request->data['Participant']['analyze_File']['name']; if (pathinfo($file, PATHINFO_EXTENSION) != 'tsv') { $this->Session->setFlash("The file must be in TSV format"); return $this->redirect(array('controller' => 'Participants', 'action' => 'analysis')); } $file = new File($this->request->data['Participant']['analyze_File']['tmp_name']); if ($file->readable()) { $content = $file->read(); $file->close(); $lines = explode("\n", $content); $incorrectFormat = empty($lines); $count = 0; $size = count($lines); for ($index = 0; $index < $size; $index++) { if (strlen(trim($lines[$index])) > 0) { if (!$incorrectFormat) { $columns = explode("\t", $lines[$index]); for ($i = 0; $i < count($columns); $i++) { if (strlen(trim($columns[$i])) == 0) { $incorrectFormat = true; } } $incorrectFormat = $incorrectFormat || sizeof($columns) != 5; $count++; } else { break; } } } // $correctFormat = $this->correctTsvFormat($file, 5); if ($incorrectFormat) { // $count=$this->incorrecLineTsvFormat($file); $this->Session->setFlash("Incorrect content file. Line {$count} is incorrect. " . "Content file must be in this format WO2009026621A1->A:12:24->1->0.99->paliperidone"); return $this->redirect(array('controller' => 'Participants', 'action' => 'analysis')); } $participantID = $this->Participant->find('first', array("recursive" => -1, "fields" => array("id"), "conditions" => array('Participant.email' => $email, 'Participant.code' => $code))); $participantID = $participantID["Participant"]["id"]; $this->request->data['Participant']['id'] = $participantID; $this->participantSaveConnection($this->request->data['Participant'], "uploadAnalysis"); // $this->Participant->UploadedAnnotation->deleteAll(array( // "participant_id" => $participantID)); // // $this->Participant->PredictionDocument->deleteAll(array( // "participant_id" => $participantID, // "project_id" => $project_id // )); $javaJarPath = Configure::read('javaJarPath'); $analyze_program = Configure::read('analyze_program'); $runJava = Configure::read('runJava'); $program = $javaJarPath . DS . $analyze_program; $path = $this->request->data['Participant']['analyze_File']['tmp_name']; $file = new File($path); if ($file->readable()) { $newPath = $file->Folder->path . DS . md5(date('Y-m-d H:i:s:u')) . $file->name() . "mtmp"; $file->copy($newPath); $path = $newPath; } else { throw new Exception("Ops! file could not be readed"); } $arguments = "{$project_id}\t{$participantID}\t{$email}\t{$path}"; // exec("nohup java -jar $program $arguments", $output); $javaLog = ".." . DS . 'java_jars' . DS . "java.log"; $date = date('Y-m-d H:i:s'); exec("echo \"{$date}:{$runJava} {$program} {$arguments}\" >> {$javaLog} 2>&1 &"); exec("{$runJava} {$program} {$arguments} >> {$javaLog} 2>&1 &"); $this->Session->setFlash("Your predictions are being processed, we will send you an email when the analysis finish", 'success'); return $this->redirect(array('controller' => 'Participants', 'action' => 'analysis')); } } else { if (isset($this->request->data['Participant']['results_File']['size']) && $this->request->data['Participant']['results_File']['size'] > 0) { if ($this->request->data['Participant']['results_File']['size'] > $this->filesize2bytes(Configure::read('max_file_size'))) { $this->Session->setFlash("The file can not be more than " . Configure::read('max_file_size')); return $this->redirect(array('controller' => 'Participants', 'action' => 'analysis')); } /* ============================================= */ /* =====================Results================= */ /* ============================================= */ $file = new File($this->request->data['Participant']['results_File']['tmp_name']); if ($file->readable()) { $content = $file->read(); $file->close(); $content = $this->decrypt($content); $results = json_decode(trim($content), true); // debug($results); if (!empty($results)) { $projects = $this->getParticipantProjects($email, $code, $results['project_id']); if (!empty($projects)) { $goldenSet = $this->Participant->GoldenProject->find('first', array('recursive' => -1, 'fields' => array('user_id', 'round_id'), 'conditions' => array('project_id' => $results['project_id']))); if (!empty($goldenSet)) { $isModified = !$this->Participant->PredictionFile->hasAny(array('participant_id' => $results['Participant']['id'], 'modified' => $results['date'])); $results['Participant']['isModified'] = $isModified; $results['Golden']['user_id'] = $goldenSet['GoldenProject']['user_id']; $results['Golden']['round_id'] = $goldenSet['GoldenProject']['round_id']; $this->Session->write("analysisResults", $results); $this->redirect(array('action' => 'results')); } else { $this->Session->setFlash("This golden set have been deleted"); } } else { $this->Session->setFlash("This file does not correspond to your credentials"); } } else { $this->Session->setFlash("This file is corrupted"); } } else { $this->Session->setFlash("This file is corrupted"); } } else { if (empty($projects)) { $this->Session->setFlash("You are not in any project"); } else { $this->Session->setFlash("One team prediction file or one result file is needed"); } } } } else { $cookie = $this->Cookie->read('participantData'); if (isset($cookie)) { if (isset($cookie['email']) && $cookie['code']) { $this->request->data['Participant']['email'] = $cookie['email']; $this->request->data['Participant']['code'] = $cookie['code']; $this->request->data['Participant']['remember_me'] = true; if (isset($cookie['project_id'])) { $this->request->data['Project']['Project'] = $cookie['project_id']; } $projects = $this->getParticipantProjects($cookie['email'], $cookie['code']); if (empty($projects)) { $this->Cookie->destroy('participantData'); } } else { $this->Cookie->destroy('participantData'); } } $this->loadModel('Post'); $this->Post->recursive = -1; $this->Post->contain(false, array('User' => array('username', 'surname', 'full_name', 'image', 'image_type', 'id'))); $this->Post->paginate = array('limit' => 5, 'order' => array('modified' => 'DESC')); $this->set("posts", $this->paginate($this->Post)); } $this->set('projects', $projects); App::uses('CakeTime', 'Utility'); $finalDate = Configure::read('final_date_to_upload_tasks'); $startDate = Configure::read('initial_date_to_upload_tasks'); $isEnd = CakeTime::isPast($finalDate); $isFuture = CakeTime::isFuture($startDate); $isThisWeek = CakeTime::isThisWeek($finalDate); $isToday = CakeTime::isTomorrow(CakeTime::fromString($finalDate)); $finalDate = CakeTime::format($finalDate, "%B %e, %Y"); $startDate = CakeTime::format($startDate, "%B %e, %Y"); $this->set('isEnd', $isEnd); $this->set('isFuture', $isFuture); $this->set('isThisWeek', $isThisWeek); $this->set('isToday', $isToday); $this->set('finalDate', $finalDate); $this->set('startDate', $startDate); //// $key = "xVO5JLSLOTpKX4YRyFpJXNYb1STQK26mHAzgNK6bwS697XzK8ZE5kEA8R7gajaI9fE6HfemeLhg28nqbGTmh5Dv5uKydSOoM4BHlQ43mvH4h0Jl3xFDcv95fRnY9wYAluS1WFi9QOLc2JDUOsN3ggNzypHuZcPaAjBklfsNH98qkX5brqEnfMUubPOUCtpTEUmtvVNq2oTGKSArEuSuuKRnMHtlbKvl4XbaAUvSfajF4DtHwLa2qaWU6pNXLHf16"; //// $key = "FFF3454D1E9CCDE00101010101010101"; // $value = "63612bb6b56ef964bc2a6add5e0697deadde735fd4ca966d7b762f61b2b4cb14a14500"; //// $value = base64_decode($value); //// debug($value); //// $result = Security::rijndael($value, $key, 'decrypt'); // $result = $this->decrypt($value); //// $resultE = Security::rijndael($value, $key, 'encrypt'); // $this->set(compact('result', 'resultE')); }