/** * Returns true if given datetime string is within this week. * * @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 bool True if datetime string is within current week * @see CakeTime::isThisWeek() * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time */ public function isThisWeek($dateString, $timezone = NULL) { return $this->_engine->isThisWeek($dateString, $timezone); }
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')); }