public function executeSubmitExam(sfWebRequest $request)
 {
     if ($request->isMethod(sfRequest::POST) && $request->hasParameter('security') && $request->hasParameter('year') && $request->hasParameter('descr')) {
         $files = $request->getFiles();
         $file = $files['file'];
         $descr = $request->getParameter('descr');
         if (isset($file) && strtoupper(substr($file['name'], -3, 3)) == 'PDF' && !helperFunctions::isMaliciousString($descr)) {
             if ($request->getParameter("security") != $_SESSION['securityImage']) {
                 echo "<input type='text' id='status' value='Security'/>";
                 exit;
             }
             $year = $request->getParameter("year") . $request->getParameter("term");
             // make directories if not exist
             if (!is_dir("exams/custom")) {
                 if (!mkdir("exams/custom")) {
                     echo "<input type='text' id='status' value='Moving'/>";
                     exit;
                 }
             }
             $tgt_path = "exams/custom/" . $year;
             if (!is_dir($tgt_path)) {
                 if (!mkdir($tgt_path)) {
                     echo "<input type='text' id='status' value='Moving'/>";
                     exit;
                 }
             }
             $fileName = time() . ".pdf";
             if (move_uploaded_file($file['tmp_name'], $tgt_path . "/" . $fileName)) {
                 // register in db
                 $conn = Propel::getConnection();
                 $exam = new Exam();
                 $exam->setCourseId($request->getParameter("course"));
                 $exam->setFilePath($tgt_path . "/" . $fileName);
                 $exam->setYear($year);
                 $exam->setType($request->getParameter("type"));
                 $exam->setDescr($descr);
                 $exam->save($conn);
                 // send notification email
                 $ip = $_SERVER['REMOTE_ADDR'];
                 $msg = "Submitted by " . $ip . " [id=" . $exam->getId() . "]";
                 helperFunctions::sendEmailNotice("Exam Submission", $msg);
                 echo "<input type='text' id='status' value='Success'/>";
             } else {
                 echo "<input type='text' id='status' value='Moving'/>";
             }
         } else {
             echo "<input type='text' id='status' value='PDF'/>";
         }
     }
     exit;
 }
 public function store()
 {
     $title = Input::get('title');
     $score = Input::get('minimunScore');
     $numberOfquestions = Input::get('numberQuestions');
     $Creator = Teacher::where('id_user', '=', Auth::id())->get()->first();
     $exam = new Exam();
     $exam->title = $title;
     $exam->creator = $Creator->id;
     $exam->score = $score;
     $exam->save();
     $ex = Exam::where('title', '=', $title)->get()->first();
     $id = $ex->id;
     return View::make('questions.create', compact('id', 'numberOfquestions'));
 }
 public function run()
 {
     //DB::table('exams')->delete();
     $teacher = Teacher::where('first_name', '=', 'Luis')->get()->first();
     $exam = new Exam();
     $exam->title = 'Sumas basicas';
     $exam->creator = $teacher->id;
     $exam->score = 2;
     $exam->save();
     $teacher2 = Teacher::where('first_name', '=', 'Luis')->get()->first();
     $exam2 = new Exam();
     $exam2->title = 'Restas basicas';
     $exam2->creator = $teacher2->id;
     $exam2->score = 2;
     $exam2->save();
 }
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aExam !== null) {
             if ($this->aExam->isModified() || $this->aExam->isNew()) {
                 $affectedRows += $this->aExam->save($con);
             }
             $this->setExam($this->aExam);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = ExamCommentPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = ExamCommentPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += ExamCommentPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         if ($this->collExamCommentDigs !== null) {
             foreach ($this->collExamCommentDigs as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Exemple #5
0
 /**
  * @before _secure, _school
  */
 public function create()
 {
     $this->setSEO(array("title" => "Create Exam | School"));
     $view = $this->getActionView();
     $grades = Grade::all(array("organization_id = ?" => $this->organization->id), array("id", "title"));
     if (RequestMethods::post("action") == "createExam") {
         $exams = $this->reArray($_POST);
         foreach ($exams as $e) {
             $course = $e["course"];
             if (Markup::checkValue($course)) {
                 $exam = new Exam(array("grade_id" => $e["grade"], "course_id" => $course, "user_id" => $this->user->id, "organization_id" => $this->organization->id, "type" => $e["type"], "start_date" => $e["start_date"], "start_time" => $e["start_time"] . ":00", "end_time" => $e["end_time"] . ":00"));
                 $exam->save();
             }
         }
         $view->set("success", "Exams created successfully!!");
     }
     $view->set("grades", $grades);
 }
 /**
  * Start browsing the directory and register files
  *
  * @return       Exception code = 400 if directory non-existent
  *               An array containing list of non-imported files if successful
  */
 public function doImport()
 {
     if (!file_exists($this->_dir)) {
         throw new Exception("directory non-existent", 400);
     }
     $errArr = array();
     $handler = opendir($this->_dir);
     // TODO: does not do recrusive listing, do we need that?
     while (false !== ($file = readdir($handler))) {
         if ($file != '.' && $file != '..') {
             $err = false;
             $pos = strrpos($file, '.');
             $fileName = strtoupper(substr($file, 0, $pos));
             $token = strtok($fileName, '_');
             $counter = 0;
             while (false !== $token) {
                 switch ($counter) {
                     case 0:
                         if (strlen($token) != 7) {
                             $err = true;
                         }
                         $rawCourseCode = $token;
                         break;
                     case 1:
                         if ($token != substr($this->_year, 0, 4)) {
                             $err = true;
                         }
                         break;
                     case 2:
                         if ($token != "EXAM") {
                             if (substr($token, 0, 5) == "EXAM(") {
                                 // name could have the following syntax: AER205S_2009_EXAM(2).pdf
                                 $count = strtok($token, '(');
                                 $count = strtok('(');
                                 $count = strtok($count, ')');
                                 if ($count === false || !is_numeric($count)) {
                                     $err = true;
                                 }
                             } else {
                                 $err = true;
                             }
                         }
                         break;
                 }
                 $token = strtok("_");
                 $counter++;
             }
             if ($counter != 3 || $err) {
                 $err = true;
             } else {
                 // assume course code is 7 chars in length with the last char being either S, F or Y
                 $part1 = substr($rawCourseCode, 0, 6);
                 //e.g. AER205
                 $part2 = substr($rawCourseCode, 6, 1);
                 //e.g. F
                 switch ($part2) {
                     case "F":
                     case "S":
                         $courseCode = $part1 . "H1";
                         $descr = $part1 . " " . $this->_year . " Official Exam" . (isset($count) ? ' (' . $count . ')' : '');
                         break;
                     case "Y":
                         $courseCode = $part1 . "Y1";
                         $descr = $part1 . " " . $this->_year . " Official Exam" . (isset($count) ? ' (' . $count . ')' : '');
                         break;
                     default:
                         $err = true;
                         break;
                 }
                 if (!$err) {
                     $conn = Propel::getConnection();
                     // check if we have exam of this descr already
                     $examArr = ExamPeer::getExamsForYearAndCourseId($courseCode, $this->_year, $conn);
                     foreach ($examArr as $ex) {
                         if ($ex->getType() == EnumItemPeer::EXAM && $ex->getDescr() == $descr) {
                             $err = true;
                             break;
                         }
                     }
                     if (!$err) {
                         // first check if course exists
                         $course = CoursePeer::retrieveByPK($courseCode, $conn);
                         if (!isset($course)) {
                             $course = new Course();
                             //$course->setDeptId(substr($courseCode, 0, 3));
                             $course->setDescr($courseCode);
                             $course->setIsEng(1);
                             $course->setId($courseCode);
                             $dept = DepartmentPeer::retrieveByPK(substr($courseCode, 0, 3), $conn);
                             if (!isset($dept)) {
                                 $dept = new Department();
                                 $dept->setId(substr($courseCode, 0, 3));
                                 $dept->setDescr(substr($courseCode, 0, 3));
                                 $dept->save($conn);
                             }
                             $course->setDepartment($dept);
                             $course->save($conn);
                         }
                         // register exam
                         $exam = new Exam();
                         $exam->setType(EnumItemPeer::EXAM);
                         $exam->setDescr($descr);
                         $exam->setCourseId($courseCode);
                         $exam->setFilePath($this->_dir . $file);
                         $exam->setYear($this->_year);
                         $exam->save();
                     }
                 }
             }
             if ($err) {
                 $errArr[] = $file;
             }
         }
     }
     closedir($handler);
     return $errArr;
 }
 /**
  * Add a like  
  */
 public function addAction()
 {
     if (isset($_SESSION['connected']) && $_SESSION['connected'] == TRUE) {
         $tableau = array();
         $tableau[0] = 'none';
         $tableau[1] = 'none';
         $tableau[2] = 'none';
         $tableau[3] = 'none';
         $this->activeBar = $tableau;
         if ($_SESSION['isAdmin'] == 1) {
             $this->result = TRUE;
             if (isset($_POST['idAdd']) && $_POST['idAdd'] > 0) {
                 $_SESSION['idAdd'] = $_POST['idAdd'];
             }
             // update: save
             if (isset($_POST['content']) && strlen($_POST['content']) > 0 && $_POST['service'] != "-" && $_SESSION['idAdd'] > 0) {
                 $update = new Exam();
                 $update->save($_POST['content'], $_POST['service'], $_SESSION['idAdd'], $_SESSION['idMember']);
                 unset($_POST);
                 unset($_SESSION['idAdd']);
                 $this->redirect('/profile/view');
             }
         } else {
             $this->result = FALSE;
             $this->redirect('/index/index');
         }
     } else {
         $this->redirect('/index/index');
     }
 }
 public function saveExam()
 {
     $total = Input::get('totalques');
     $towrite = "";
     $check = 0;
     $destinationPath = "/assets/images/admin";
     $destinationPath .= '/' . str_random(9) . '.txt';
     //return Input::all();
     for ($i = 1; $i <= $total; $i++) {
         $ques = "ques" . $i;
         $ans = "ans" . $i;
         $opt1 = $ques . "o1";
         $opt2 = $ques . "o2";
         $opt3 = $ques . "o3";
         $opt4 = $ques . "o4";
         if (Input::get($ques) != '' && Input::get($ques) != '' && Input::get($ques) != '' && Input::get($ques) != '') {
             $towrite = Input::get($ques) . "\n";
             $towrite .= Input::get($opt1) . ';' . Input::get($opt2) . ';' . Input::get($opt3) . ';' . Input::get($opt4) . ';' . Input::get($ans) . "\n";
             $check = File::append(public_path() . '' . $destinationPath, $towrite);
         }
     }
     if ($check) {
         $date = Input::get('examdate');
         $dt = \DateTime::createFromFormat('m/d/Y', $date);
         $exam = new Exam();
         $exam->examname = Input::get('examname');
         $exam->examdate = $dt->format('Y-m-d');
         $exam->starttime = Input::get('examstime');
         $exam->endtime = Input::get('exametime');
         $exam->note = Input::get('examnote');
         $exam->examfile = $destinationPath;
         $exam->classid = Input::get('classname');
         $exam->collegeid = Session::get('user')->collegeid;
         if ($exam->save()) {
             return Redirect::route('exams');
         }
     }
     return 'try again';
 }
Exemple #9
0
 /**
  * Take the exam submission request and save it into database
  * @param sfWebRequest $request
  */
 public function executeSubmitExam(sfWebRequest $request)
 {
     //TODO: set up uniform display name for each exam/test uploaded so things don't get messy.
     //i.e. instead of letting the user choose the display name, we'll appropriate it
     //requested by David
     set_time_limit(0);
     if ($request->isMethod(sfRequest::POST) && $request->hasParameter('security') && $request->hasParameter('year') && $request->hasParameter('descr')) {
         $files = $request->getFiles();
         $file = $files['file'];
         $descr = $request->getParameter('descr');
         if (isset($file) && strtoupper(substr($file['name'], -3, 3)) == 'PDF' && !helperFunctions::isMaliciousString($descr)) {
             if ($request->getParameter("security") != $_SESSION['securityImage']) {
                 echo "<input type='text' id='status' value='Security'/>";
                 return sfView::NONE;
             }
             $year = $request->getParameter("year") . $request->getParameter("term");
             // make directories if not exist
             if (!is_dir("exams/custom")) {
                 if (!mkdir("exams/custom")) {
                     echo "<input type='text' id='status' value='Moving'/>";
                     return sfView::NONE;
                 }
             }
             $tgt_path = "exams/custom/" . $year;
             if (!is_dir($tgt_path)) {
                 if (!mkdir($tgt_path)) {
                     echo "<input type='text' id='status' value='Moving'/>";
                     return sfView::NONE;
                 }
             }
             // unique filename
             $courseId = $request->getParameter("course");
             $examType = $request->getParameter("type");
             $examTypeAbbr = HelperFunctions::getExamTypeAbbr($examType);
             $fileName = substr($courseId, 0, 6) . '_' . substr($year, 0, 4) . '_' . $examTypeAbbr . '_' . time() . ".pdf";
             if (move_uploaded_file($file['tmp_name'], $tgt_path . "/" . $fileName)) {
                 try {
                     // register in db
                     $conn = Propel::getConnection();
                     $exam = new Exam();
                     $exam->setCourseId($courseId);
                     $exam->setFilePath($tgt_path . "/" . $fileName);
                     $exam->setYear($year);
                     $exam->setType($examType);
                     $exam->setDescr($descr);
                     $exam->save($conn);
                     // send notification email
                     $ip = $_SERVER['REMOTE_ADDR'];
                     $msg = "A new exam on [title=" . $exam->getDescr() . "; course=" . $exam->getCourseId() . "; year=" . $exam->getYear() . "; id=" . $exam->getId() . "] has been submitted by " . $ip . " on " . date('Y-m-d H:i:s') . ".";
                     helperFunctions::sendEmailNotice("Exam Submission", $msg);
                     echo "<input type='text' id='status' value='Success'/>";
                 } catch (Exception $e) {
                     echo "<input type='text' id='status' value='Saving'/>";
                     // send error email
                     helperFunctions::sendEmailNotice("Exam Submission Error", $e->getMessage());
                 }
             } else {
                 echo "<input type='text' id='status' value='Moving'/>";
             }
         } else {
             echo "<input type='text' id='status' value='PDF'/>";
         }
         return sfView::NONE;
     } else {
         $this->forward404();
     }
 }