예제 #1
0
    function displayBody()
    {
        parent::displayBody();
        $translator = new Translator();
        $course = new Course();
        $data = $course->get(array('id' => $this->id));
        foreach ($data as $key => $val) {
            $data[$key] = htmlspecialchars($val, ENT_QUOTES);
        }
        echo <<<EOF
<h2  class="page-header">{$data[name]}</h2>
<h4>{$data[category_name]}</h4>
<div class="col-lg-8">
    <ul class="list-group category-list" index="{$this->id}/">

EOF;
        $root = $_SERVER['DOCUMENT_ROOT'] . '/../files/courses/' . $this->id;
        $this->put_list($root);
        echo <<<EOF
    </ul>
    <div class="row">
\t
\t<a href="#"  data-toggle="toggler" parent-id="{$this->id}/" title="{$translator->addfile}" type="file">
\t\t\t<span class="glyphicon glyphicon-file"></span> </a>
\t\t\t<a href="#"  data-toggle="toggler" parent-id="{$this->id}/" title="{$translator->addfolder}" type="folder">
\t\t\t<span class="glyphicon glyphicon-folder-open"></span> </a>
\t
    </div>

</div>
EOF;
    }
예제 #2
0
 function approve($id, $data = null)
 {
     $training = new Training();
     $course_obj = new Course();
     $request = $this->get(array('id' => $id));
     $course = $course_obj->get(array('id' => $request['course_id']));
     $data['course_id'] = $request['course_id'];
     $data['start'] = $request['planned_date'];
     $date = new DateTime($data['start']);
     if ($course['duration'] > 8) {
         $date->add(new DateInterval('P' . ceil($course['duration'] / 8) . 'DT' . $course['duration'] % 8 . 'H'));
     } else {
         $date->add(new DateInterval('PT' . $course['duration'] . 'H'));
     }
     $data['finish'] = $date->format('Y-m-d H:i');
     $data['user_id'] = $request['user_id'];
     $data['status_id'] = Training::CREATED;
     if ($course['format_id'] == Course::ONLINE || $course['format_id'] == Course::WEBCAST) {
         $data['course_hash'] = md5($data['user_id'] . $data['course_id'] . $data['start']);
     }
     $data['tries'] = 0;
     if ($course['exam'] == 't') {
         $data['exam_hash'] = md5($data['user_id'] . $data['course_id'] . $data['start'] . $data['tries']);
     }
     $data['request_id'] = $id;
     $data['active'] = 'true';
     $training->add($data);
     $this->disable($id);
 }
예제 #3
0
 public function index()
 {
     $this->_initialize_student_menu();
     $this->_select_student_menu_pagetag('groups');
     $this->parser->add_css_file('frontend_groups.css');
     $cache_id = $this->usermanager->get_student_cache_id();
     if (!$this->_is_cache_enabled() || !$this->parser->isCached($this->parser->find_view('frontend/groups/index.tpl'), $cache_id)) {
         $student = new Student();
         $student->get_by_id($this->usermanager->get_student_id());
         $course = new Course();
         $course->where_related_active_for_student($student);
         $course->where_related('participant/student', $student);
         $course->where_related_participant('allowed', 1);
         $course->get();
         $can_change_group = FALSE;
         if ($course->exists()) {
             if (is_null($course->groups_change_deadline) || date('U', strtotime($course->groups_change_deadline)) >= time()) {
                 $can_change_group = TRUE;
             }
         }
         smarty_inject_days();
         $this->parser->assign(array('course' => $course, 'can_change_group' => $can_change_group));
     }
     $this->parser->parse('frontend/groups/index.tpl', array(), FALSE, $this->_is_cache_enabled(), $cache_id);
 }
예제 #4
0
파일: Home_.php 프로젝트: bennyty/suggestr
 public function process($get, $post)
 {
     $this->pageData["Title"] = "Home";
     // Select all of the courses that this user is already added or ignored
     $query = new Query('action');
     $result = $query->select('*', array(array('session_id', '=', $_COOKIE['sessionId'])));
     $idsAlreadyAdded = array();
     foreach ($result as $action) {
         array_push($idsAlreadyAdded, $action->get('course_id'));
     }
     // Generate all of the courses (for testing)
     $allCourses = array();
     $query = new Query('courses');
     $result = $query->select('*', '', array('number', 'ASC'), 20, false);
     while ($row = mysqli_fetch_array($result)) {
         try {
             $course = new Course();
             $course->findById($row['id']);
             if (!in_array($course->get('id'), $idsAlreadyAdded)) {
                 // Check that this course has not been added by the user yet
                 array_push($allCourses, array('id' => $course->get('id'), 'name' => ucwords(strtolower($course->get('name'))), 'department_id' => $course->get('department_id'), 'number' => $course->get('number'), 'description' => strlen($course->get('description')) == 0 ? 'No description' : $course->get('description')));
             }
         } catch (Exception $e) {
         }
     }
     $this->pageData['allCourses'] = $allCourses;
     // Select all of the courses that this user is already added
     $query = new Query('action');
     $result = $query->select('*', array(array('session_id', '=', $_COOKIE['sessionId']), array('choice', '=', 0)));
     $idsAlreadyAdded = array();
     foreach ($result as $action) {
         array_push($idsAlreadyAdded, $action->get('course_id'));
     }
     // Get all of the courses in this user's session
     $usersCourses = array();
     foreach ($idsAlreadyAdded as $courseId) {
         try {
             $course = new Course();
             $course->findById($courseId);
             array_push($usersCourses, array('id' => $course->get('id'), 'name' => ucwords(strtolower($course->get('name'))), 'department_id' => $course->get('department_id'), 'number' => $course->get('number')));
         } catch (Exception $e) {
         }
     }
     $this->pageData['usersCourses'] = $usersCourses;
 }
예제 #5
0
    function displayBody()
    {
        parent::displayBody();
        $translator = new Translator();
        $request = new Request();
        try {
            $id = array_shift($this->param);
            $course = new Course();
            $c_data = $course->get(array('id' => $id));
            $data['course_id'] = $id;
            $data['user_id'] = $_SESSION['user_id'];
            $data['active'] = true;
            $data['planned_date'] = $_GET['planned_date'] != '' ? $_GET['planned_date'] : date('Y-m-d H:i:s', time());
            $r_id = $request->add($data);
            if ($c_data['need_approve'] == 'f') {
                $request->approve($r_id);
                echo <<<EOF
<div class="container">
   <div class="page-header">
        <h1>{$translator->Request_updated}</h1>
      </div>
   <p class="lead">{$translator->Request_updated_Desc}</p>
      <p >{$translator->Error_Backcourses}</p>
</div>
<script type="text/javascript">
window.location.href='/mycourses';
</script>

EOF;
            } else {
                echo <<<EOF
<div class="container">
   <div class="page-header">
        <h1>{$translator->Request_updated}</h1>
      </div>
   <p class="lead">{$translator->Request_need_approve_Desc}</p>
      <p >{$translator->Error_Backcourses}</p>
</div>

EOF;
            }
        } catch (Exception $e) {
            echo <<<EOF
<div class="container">
   <div class="page-header">
        <h1>{$translator->Request_error}</h1>
      </div>
   <p class="lead">{$translator->Request_error_Desc}</p>
      <p >{$translator->Error_Backcourses}</p>
</div>

EOF;
        }
    }
예제 #6
0
 public function showExportDataCourse()
 {
     $listCourse = Course::get();
     $listCourseSort = [];
     $size = count($listCourse);
     for ($i = 0; $i < $size; $i++) {
         $course = array('id' => $listCourse[$i]->id, 'name' => $listCourse[$i]->name, 'desc' => $listCourse[$i]->desc, 'subject' => Subject::where('id_course', $listCourse[$i]->id)->count(), 'word' => Word::where('id_course', $listCourse[$i]->id)->count());
         array_push($listCourseSort, $course);
     }
     $list['listCourse'] = $listCourse;
     $list['listCourseSort'] = $listCourseSort;
     return View::make('data.list-course', $list);
 }
예제 #7
0
 function checkEditor($id)
 {
     if ((User::EDITOR & intval($_SESSION['role_id'])) > 0) {
         // check permision
         return;
     }
     try {
         $course = new Course();
         $result = @$course->get(array('id' => $id, 'author_id' => $_SESSION['user_id']));
         if (isset($result) && (User::EDITOR_SIMPLE & intval($_SESSION['role_id'])) > 0) {
             return;
         }
     } catch (Exception $e) {
         throw new NoAccessException('No access');
         // return authorization error
     }
 }
예제 #8
0
 public function search()
 {
     $query = $this->input->get('q', TRUE);
     $courses = new Course();
     $courses->limit(10);
     $courses->like('number', $query);
     $courses->get();
     $arr = array();
     foreach ($courses as $course) {
         $arr_course = array();
         $arr_course['value'] = $course->number . ': ' . $course->title;
         $arr_course['data'] = $course->id;
         array_push($arr, $arr_course);
     }
     $arr_wrapper = array();
     $arr_wrapper['suggestions'] = $arr;
     echo json_encode($arr_wrapper);
 }
예제 #9
0
파일: plan.php 프로젝트: jedaika/Trainings
 function adduser($id, $user_id)
 {
     $training = new Training();
     $course_obj = new Course();
     $plan = $this->get(array('id' => $id));
     $course = $course_obj->get(array('id' => $plan['course_id']));
     $data['course_id'] = $plan['course_id'];
     $data['start'] = $plan['start'];
     $data['finish'] = $plan['finish'];
     $data['user_id'] = $user_id;
     $data['status_id'] = Training::CREATED;
     if ($course['format_id'] == Course::ONLINE) {
         $data['course_hash'] = md5($data['user_id'] . $data['course_id'] . $data['start']);
     }
     $data['tries'] = 0;
     if ($course['exam'] == 't') {
         $data['exam_hash'] = md5($data['user_id'] . $data['course_id'] . $data['start'] . $data['tries']);
     }
     $data['plan_id'] = $id;
     $training->add($data);
 }
예제 #10
0
파일: learn.php 프로젝트: jedaika/Trainings
    function displayBody()
    {
        parent::displayBody();
        $translator = new Translator();
        $course = new Course();
        $training = new Training();
        $t_data = $training->get(array('course_hash' => $this->course_hash, 'user_id' => $_SESSION['user_id']));
        $c_data = $course->get(array('id' => $t_data['course_id']));
        foreach ($c_data as $key => $val) {
            $c_data[$key] = htmlspecialchars($val, ENT_QUOTES);
        }
        echo <<<EOF
<div class="container-fluid">
<div class="col-lg-10 col-lg-offset-1" id="window">
\t<div class="row" >
\t<div class="col-xs-10">
\t    <h4>{$c_data[category_name]}</h4>
\t    <h2>{$c_data[name]}</h2>
\t</div>
\t<div class="col-xs-2 text-right" id="top_buttons">
\t    <a href="#" id="fullscreen"><span class="glyphicon glyphicon-fullscreen"></span></a>
\t    <a href="#" id="inscreen" class="collapse"><span class="glyphicon glyphicon-remove"></span></a>
\t</div>
\t</div>
\t<div class="embed-responsive embed-responsive-16by9" id="fullscreen_media">
\t  <iframe class="embed-responsive-item" src="/learn/{$this->course_hash}/index.html" id="iframe"></iframe>
\t</div>
\t<nav id="bottom_buttons">
\t  <ul class="pager">
\t    <li class="previous"><a href="#" id="back"><span aria-hidden="true">&larr;</span> {$translator->Back}</a></li>
\t    <li class="top"><a href="#" id="top">{$translator->Top}</a>|
\t\t<a href="/mycourses/finish/{$t_data[id]}" onclick='return confirm("{$translator->AreYouSure}");'>{$translator->Finish}</a></li>
\t    <li class="next"><a href="#" id="next">{$translator->Next} <span aria-hidden="true">&rarr;</span></a></li>
\t  </ul>
\t</nav>
</div>
</div> <!-- /container -->

EOF;
    }
예제 #11
0
 function getClassNameById($id)
 {
     $result = new Course();
     $result->findById($id);
     return $result->get('name');
 }
예제 #12
0
 function end_course($id)
 {
     $training = new Training();
     $course = new Course();
     try {
         $t_data = $training->get(array('id' => $id, 'user_id' => $_SESSION['user_id']));
         $c_data = $course->get(array('id' => $t_data['course_id']));
         if ($c_data['exam'] == 't') {
             $status = Training::EXAM;
         } else {
             $status = Training::FINISHED;
         }
         $training->update($id, array('status_id' => $status, 'finished' => date('Y-m-d H:i', time())));
         header('Location: /mycourses');
         exit;
     } catch (Exception $e) {
         echo $e;
     }
 }
예제 #13
0
    function edit($create = null)
    {
        $translator = new Translator();
        $course = new Course();
        if ($create) {
            $func = 'add';
            $category_id = array_shift($this->param);
        } else {
            $func = 'save';
            $data = $course->get(array('id' => array_shift($this->param)));
            foreach ($data as $key => $val) {
                $data[$key] = htmlspecialchars($val, ENT_QUOTES);
            }
            $category_id = $data['category_id'];
        }
        $categories = Course::getCategoriesForSelect($category_id);
        foreach ($course->formats as $key => $val) {
            $formats .= "<option value=\"{$key}\"" . ($data['format_id'] == $key ? ' selected' : '') . ">" . htmlspecialchars($val, ENT_QUOTES) . "</option>" . NL;
        }
        foreach ($course->languages as $key => $val) {
            $languages .= "<option value=\"{$key}\"" . ($data['language'] == $key ? ' selected' : '') . ">" . htmlspecialchars($val, ENT_QUOTES) . "</option>" . NL;
        }
        if ($data['active'] == 't') {
            $active = 'checked';
        }
        if ($data['exam'] == 't') {
            $exam = 'checked';
        }
        if ($data['need_approve'] == 't') {
            $need_approve = 'checked';
        }
        $maxsize = ini_get('post_max_size');
        if (!isset($create) && file_exists(__DIR__ . '/../../../files/courses/' . $id)) {
            $download = "<a href=\"/admin_course/download/{$data[id]}\" target=\"_blank\">{$translator->Download_Archive}</a>\n\t\t<a href=\"/admin_manager/list/{$data[id]}\">{$translator->File_Manager}</a>";
            $question = new Question();
            $q_cnt = $question->getCount(array('course_id' => $data['id']));
            if ($q_cnt) {
                $q_cnt = "<span class=\"badge\">{$q_cnt}</span>";
            } else {
                $q_cnt = '';
            }
            $questions = "<div><a href=\"/admin_questions/{$data[id]}\">{$translator->Questions_Link} {$q_cnt}</a></div>";
        }
        echo <<<EOF
<div class="container">
<div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
    <form role="form" action="/admin_course/{$func}/{$data[id]}" method="post" enctype="multipart/form-data">
\t<h2>{$translator->edit}</h2>
\t    <div class="form-group">
\t\t<input type="text" name="name" id="name" class="form-control input-lg" 
\t\tplaceholder="{$translator->Name}" tabindex="1" required value="{$data[name]}">
\t    </div>
\t    <div class="form-group">
\t\t<label for="category_id">{$translator->Category}:</label>
\t\t    <select class="form-control" id="category_id" name="category_id">
\t\t    {$categories}
\t\t</select>
\t    </div>
\t    <div class="form-group">
\t\t<label for="format_id">{$translator->Format}:</label>
\t\t    <select class="form-control" id="format_id" name="format_id">
\t\t    {$formats}
\t\t</select>
\t    </div>
\t    <div class="form-group">
\t\t<label for="data">{$translator->Prerequisites}:</label> {$translator->Prerequisites_Desc}
\t\t<textarea  name="prerequisites" id="prerequisites" class="form-control" rows="4">{$data[prerequisites]}</textarea>
\t    </div>
<!-- TODO>
 Add needed courses select-box
\t    <div class="form-group">Courses</div>
<!-->
\t    <div class="form-group">
\t\t<label for="language">{$translator->Language}:</label>
\t\t    <select class="form-control" id="language" name="language">
\t\t    {$languages}
\t\t</select>
\t    </div>
\t    <div class="form-group">
\t\t<label for="describe">{$translator->Describe}:</label> {$translator->Describe_Desc}
\t\t<textarea  name="describe" id="describe" class="form-control" rows="5">{$data[describe]}</textarea>
\t    </div>
\t    <div class="form-group">
\t\t<label for="skills">{$translator->Skills}:</label> {$translator->Skills_Desc}
\t\t<textarea  name="skills" id="skills" class="form-control" rows="5">{$data[skills]}</textarea>
\t    </div>
\t    <div class="form-group">
\t\t<input type="number" name="duration" id="duration" class="form-control" min="1"
\t\tplaceholder="{$translator->Duration}" tabindex="1" required value="{$data[duration]}">
\t\t<span class="help-block">{$translator->Duration_Desc}</span>
\t    </div>
\t    <div class="form-group">
\t\t<label for="equipment">{$translator->Equipment}:</label> {$translator->Equipment_Desc}
\t\t<textarea  name="equipment" id="equipment" class="form-control" rows="5">{$data[equipment]}</textarea>
\t    </div>
\t    <div class="form-group">
\t\t<input type="number" name="min" id="min" class="form-control" min="1"
\t\tplaceholder="{$translator->Min}" tabindex="1" value="{$data[min]}">
\t\t<span class="help-block">{$translator->Min_Desc}</span>
\t    </div>
\t    <div class="form-group">
\t\t<input type="number" name="max" id="max" class="form-control" min="1"
\t\tplaceholder="{$translator->Max}" tabindex="1" value="{$data[max]}">
\t\t<span class="help-block">{$translator->Max_Desc}</span>
\t    </div>
\t    <div class="form-group">
\t\t<input type="text" name="author" id="author" class="form-control" 
\t\tplaceholder="{$translator->Author}" tabindex="1" value="{$data[author]}">
\t    </div>
\t    <div class="form-group">
\t\t<input type="number" name="questions" id="questions" class="form-control" min="0"
\t\tplaceholder="{$translator->Questions}" tabindex="1" value="{$data[questions]}">
\t\t<span class="help-block">{$translator->Questions_Desc}</span>
\t    </div>
\t    <div class="checkbox">
\t\t  <label><input type="checkbox" value="true" name="active" id="active" {$active}> {$translator->Active}</label>
\t    </div>
\t    <div class="checkbox">
\t\t  <label><input type="checkbox" value="true" name="need_approve" id="need_approve" {$need_approve}> {$translator->Need_approve}</label>
\t    </div>
\t    <div class="checkbox">
\t\t<label><input type="checkbox" value="true" name="exam" id="exam" {$exam}> {$translator->Exam}</label>
\t\t {$questions}
\t    </div>
\t    <div class="form-group">
\t\t<input type="number" name="exam_duration" id="exam_duration" class="form-control" min="1"
\t\tplaceholder="{$translator->Exam_Duration}" tabindex="1" required value="{$data[exam_duration]}">
\t\t<span class="help-block">{$translator->Exam_Duration_Desc}</span>
\t    </div>

\t    <div class="form-group">
\t\t<span class="btn btn-default btn-file"><input type="file" name="file" value="file"> </span>
\t\t{$download}
\t    </div>

\t    <div class="row">
\t\t<div class="col-xs-12 col-md-6"><input type="submit" value="{$translator->Save}" class="btn btn-primary" tabindex="13"></div>
\t    </div>
    </form>
</div>
</div> <!-- /container -->

EOF;
    }
예제 #14
0
 private function get_task_set_by_id(&$course, &$group, &$student, $task_set_id)
 {
     $student = new Student();
     $student->get_by_id($this->usermanager->get_student_id());
     $course = new Course();
     $course->where_related('active_for_student', 'id', $student->id);
     $course->where_related('participant', 'student_id', $student->id);
     $course->where_related('participant', 'allowed', 1);
     $course->include_related('period', 'name');
     $course->get();
     $task_set = new Task_set();
     $task_set2 = new Task_set();
     $group = new Group();
     if ($course->exists()) {
         $group->where_related_participant('student_id', $student->id);
         $group->where_related_participant('course_id', $course->id);
         $group->get();
         $task_set->select('`task_sets`.*, `rooms`.`time_day` AS `pb_time_day`, `rooms`.`time_begin` AS `pb_time_begin`, `rooms`.`id` AS `pb_room_id`, `task_sets`.`publish_start_time` AS `pb_publish_start_time`, `task_sets`.`upload_end_time` AS `pb_upload_end_time`');
         $task_set->where('published', 1);
         $task_set->where_related_course($course);
         $task_set->include_related('solution');
         $task_set->add_join_condition('`solutions`.`student_id` = ?', array($student->id));
         $task_set->where_subquery(0, '(SELECT COUNT(`tsp`.`id`) AS `count` FROM `task_set_permissions` tsp WHERE `tsp`.`task_set_id` = `task_sets`.`id` AND `tsp`.`enabled` = 1)');
         $task_set->group_start();
         $task_set->or_where('group_id', NULL);
         $task_set->or_where('group_id', $group->id);
         $task_set->group_end();
         $task_set->include_related('room', '*', TRUE, TRUE);
         $task_set->include_related_count('task', 'total_tasks');
         $task_set->include_related('task_set_type');
         $task_set->select_subquery('(SELECT SUM(`points_total`) AS `points` FROM `task_task_set_rel` WHERE `task_set_id` = `${parent}`.`id` AND `task_task_set_rel`.`bonus_task` = 0)', 'total_points');
         $task_set->where('id', $task_set_id);
         $task_set->include_related('course', 'test_scoring_deadline');
         $task_set->where('content_type', 'task_set');
         $task_set2->select('`task_sets`.*, `task_set_permission_rooms`.`time_day` AS `pb_time_day`, `task_set_permission_rooms`.`time_begin` AS `pb_time_begin`, `task_set_permission_rooms`.`id` AS `pb_room_id`, `task_set_permissions`.`publish_start_time` AS `pb_publish_start_time`, `task_set_permissions`.`upload_end_time` AS `pb_upload_end_time`');
         $task_set2->where('published', 1);
         $task_set2->where_related_course($course);
         $task_set2->where_related('task_set_permission', 'group_id', $group->id);
         $task_set2->where_related('task_set_permission', 'enabled', 1);
         $task_set2->include_related('solution');
         $task_set2->add_join_condition('`solutions`.`student_id` = ?', array($student->id));
         $task_set2->include_related('task_set_permission/room', '*', 'room', TRUE);
         $task_set2->include_related_count('task', 'total_tasks');
         $task_set2->include_related('task_set_type');
         $task_set2->select_subquery('(SELECT SUM(`points_total`) AS `points` FROM `task_task_set_rel` WHERE `task_set_id` = `${parent}`.`id` AND `task_task_set_rel`.`bonus_task` = 0)', 'total_points');
         $task_set2->where('id', $task_set_id);
         $task_set2->include_related('course', 'test_scoring_deadline');
         $task_set2->where('content_type', 'task_set');
         $task_set3 = new Task_set();
         $task_set3->select('`task_sets`.*, NULL AS `pb_time_day`, NULL AS `pb_time_begin`, NULL AS `pb_room_id`, NULL AS `pb_publish_start_time`, "0000-00-00 00:00:00" AS `pb_upload_end_time`', FALSE);
         $task_set3->where('published', 1);
         $task_set3->where_related_course($course);
         $task_set3->include_related('solution');
         $task_set3->add_join_condition('`solutions`.`student_id` = ?', array($student->id));
         $task_set3->where_related('solution', 'student_id', $student->id);
         $task_set3->include_related('room', '*', TRUE, TRUE);
         $task_set3->include_related_count('task', 'total_tasks');
         $task_set3->include_related('task_set_type');
         $task_set3->select_subquery('(SELECT SUM(`points_total`) AS `points` FROM `task_task_set_rel` WHERE `task_set_id` = `${parent}`.`id` AND `task_task_set_rel`.`bonus_task` = 0)', 'total_points');
         $task_set3->where('id', $task_set_id);
         $task_set3->include_related('course', 'test_scoring_deadline');
         $task_set3->where('content_type', 'task_set');
         $task_set2->union(array($task_set, $task_set3), FALSE, '', 1, 0, 'id');
     }
     return $task_set2;
 }
예제 #15
0
/**
 * Returns null if $value is not a valid or existent course_id; returns the $value otheriwse. XXX NOTE, a bug prior to php 5.2.6 causes epic php failure if callbacks return false. null returned as workaround
 * @param unknown_type $value
 * @return mixed
 */
function validate_course_id($value)
{
    $course_id = filter_var($value, FILTER_VALIDATE_INT, array('min_range' => 1));
    if (false === $course_id || !Course::get($course_id)) {
        return;
    } else {
        return $course_id;
    }
}
예제 #16
0
    function edit($create = null)
    {
        $translator = new Translator();
        $category = new Category();
        $course = new Course();
        $trainer = new Trainer();
        if ($create) {
            $func = 'add';
        } else {
            $func = 'save';
            $plan = new Plan();
            $this->id = array_shift($this->param);
            $data = $plan->get(array('id' => $this->id));
            foreach ($data as $key => $val) {
                $data[$key] = htmlspecialchars($val, ENT_QUOTES);
            }
        }
        try {
            $c_data = $course->get(array('id' => $data['course_id']));
            $category_id = $c_data['category_id'];
            $enum = $course->enumerate(array('category_id' => intval($category_id)));
            foreach ($enum as $val) {
                $courses .= "<option value=\"{$val[id]}\"" . ($val['id'] == $data['course_id'] ? ' selected' : '') . ">" . htmlspecialchars($val['name'], ENT_QUOTES) . "</option>" . NL;
            }
        } catch (Exception $e) {
        }
        $categories = Course::getCategoriesForSelect($category_id);
        $enum = $trainer->enumerate();
        foreach ($enum as $val) {
            $trainers .= "<option value=\"{$val[id]}\"" . ($val['id'] == $data['trainer_id'] ? ' selected' : '') . ">" . htmlspecialchars($val['name'], ENT_QUOTES) . "</option>" . NL;
        }
        if ($data['active'] == 't') {
            $active = 'checked';
        }
        echo <<<EOF
<div class="container">
<div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
    <form role="form" action="/admin_training/{$func}/{$data[id]}" method="post">
\t<h2>{$translator->Plan_edit}</h2>
\t    <div class="form-group">
                <label for="category_id">{$translator->Category}:</label>
        \t<select class="form-control" id="category_id" name="category_id">
                {$categories}
                </select>
            </div>
\t    <div class="form-group">
                <label for="course_id">{$translator->Course}:</label>
        \t<select class="form-control" id="course_id" name="course_id">
                {$courses}
                </select>
            </div>

\t    <div class="form-group">
\t\t<label for="start">{$translator->Start}:</label> <span class="text-muted">{$translator->Start_Desc}</span>
\t\t<input name="start" id="start" class="form-control datetimepicker" value="{$data[start]}">
\t    </div>
\t    <div class="form-group">
\t\t<label for="finish">{$translator->Finish}:</label> <span class="text-muted">{$translator->Finish_Desc}</span>
\t\t<input name="finish" id="finish" class="form-control datetimepicker" value="{$data[finish]}">
\t    </div>
\t    <div class="form-group">
\t\t<input type="text" name="contact" id="contact" class="form-control input-lg" 
\t\tplaceholder="{$translator->Contact}" tabindex="5" required value="{$data[contact]}">
\t    </div>
\t    <div class="form-group">
\t\t<input type="text" name="place" id="place" class="form-control input-lg" 
\t\tplaceholder="{$translator->Place}" tabindex="6" required value="{$data[place]}">
\t    </div>
\t    <div class="form-group">
                <label for="trainer_id">{$translator->Trainer}:</label>
        \t<select class="form-control" id="trainer_id" name="trainer_id">
                {$trainers}
                </select>
            </div>
\t    <div class="checkbox">
\t\t<label><input type="checkbox" value="true" name="active" id="active" {$active}> {$translator->Active}</label>
\t    </div>

EOF;
        if (!$create) {
            // let add people to plan, because plan_ID is known
            $user = new User();
            $training = new Training();
            $enum = $training->enumerate(array('plan_id' => $data['id']));
            if (is_object($enum)) {
                foreach ($enum as $val) {
                    $u_data = $user->get(array('id' => $val['user_id']));
                    $json = array('id' => $data['id'], 'name' => $data['name'], 'email' => $data['email'], 'company' => $data['company'], 'city' => $data['city']);
                    $users .= "<tr id=\"row{$u_data[id]}\"><td>{$u_data[name]}</td><td>" . "{$u_data[email]}</td><td>{$u_data[company]} / {$u_data[city]}</td><td>" . "<a href=\"#\" onclick=\"return removeuser({$u_data[id]});\">" . '<span class="glyphicon glyphicon-trash"></span></a></td></tr>' . NL;
                }
            }
            echo <<<EOF
<div class="form-group totop-relative">
<small>
<table id="users"  class="table table-striped">
<tbody>
{$users}
</tbody>
</table>
</small>
<div class="list-group totop" id="usermenu" >
</div>
<input type="text" name="searchuser" id="searchuser" class="form-control input-md" placeholder="{$translator->Search_user}">
</div>

EOF;
        }
        echo <<<EOF
\t    <div class="row">
\t\t<div class="col-xs-12 col-md-6"><input type="submit" value="{$translator->Save}" class="btn btn-primary" tabindex="13"></div>
\t    </div>
    </form>
</div>
</div> <!-- /container -->

EOF;
    }
예제 #17
0
 private function get_task_set_overview($task_set_id, &$course)
 {
     $task_set = new Task_set();
     $task_set->where('published', 1);
     $task_set->include_related_count('task', 'total_tasks');
     $task_set->where('content_type', 'project');
     $task_set->order_by('publish_start_time', 'asc');
     $task_set->order_by('upload_end_time', 'asc');
     $task_set->order_by_with_overlay('name', 'asc');
     $task_set->get_by_id((int) $task_set_id);
     $course = new Course();
     $course->where_related('task_set', 'id', (int) $task_set->id);
     $course->include_related('period');
     $course->get();
     return $task_set;
 }
예제 #18
0
    function displayBody()
    {
        parent::displayBody();
        $translator = new Translator();
        $course = new Course();
        $category = new Category();
        $training = new Training();
        $t_data = $training->get(array('id' => $this->id, 'user_id' => $_SESSION['user_id']));
        $c_data = $course->get(array('id' => $t_data['course_id']));
        foreach ($c_data as $key => $val) {
            $c_data[$key] = htmlspecialchars($val, ENT_QUOTES);
        }
        $category_id = $c_data['category_id'];
        $enum = $category->enumerate();
        if ($enum) {
            foreach ($enum as $key => $val) {
                if ($val['id'] != 0) {
                    $items[$val['id']] = $val;
                }
            }
            $categories = $this->makeCategoryList($items, $category_id);
        }
        if ($t_data['status_id'] == Training::FINISHED) {
            $result = $translator->Congratulations;
            $result_class = "alert-success";
        } else {
            $result = $translator->Sorry;
            $result_class = "alert-danger";
        }
        echo <<<EOF
<div class="container-fluid">
    <div class="col-lg-10 col-lg-offset-1" id="window">
\t<h4>{$categories}</h4>
\t<h2>{$c_data[name]}</h2>
\t<h3 class="alert {$result_class}" role="alert">{$result}</h3>
\t<h4>{$translator->Result}: {$t_data[result]}% ({$t_data['answers']} / {$t_data[questions]})</h4>
\t<table class="table">
\t    <tr>
\t\t<th>#</th>
\t\t<th>{$translator->Question}</th>
\t\t<th>{$translator->Result}</th>
\t    </tr>

EOF;
        $exam = new Exam();
        $enum = $exam->enumerateResult($t_data['id']);
        $i = 1;
        foreach ($enum as $key => $e_data) {
            $answer = $e_data['result'] == 't' ? $translator->Right : $translator->Wrong;
            $class = $e_data['result'] == 't' ? "success" : "danger";
            echo <<<EOF
\t    <tr class="alert alert-{$class}" role="alert">
\t\t<td>{$i}</td>
\t\t<td>{$e_data[question]}</td>
\t\t<td >{$answer}</td>
\t    </tr>
EOF;
            $i++;
        }
        echo <<<EOF
\t</table>
    </div>
</div> <!-- /container -->

EOF;
    }
예제 #19
0
 public function evaluate_test_result($task_set_id, $student_id, $version, $test_type, $token)
 {
     $task_set = new Task_set();
     $task_set->include_related('course', 'test_scoring_deadline');
     $task_set->get_by_id((int) $task_set_id);
     $student = new Student();
     $student->get_by_id((int) $student_id);
     $output = new stdClass();
     $output->result = FALSE;
     $output->message = '';
     $output->points_new = 0;
     $output->points_before = 0;
     $this->load->model('test_score');
     if ($task_set->exists() && $student->exists()) {
         if ($task_set->course_test_scoring_deadline >= date('Y-m-d H:i:s') && $task_set->enable_tests_scoring > 0) {
             $results = $this->test_score->get_data_for_student($student->id, $token, $test_type);
             $this->_transaction_isolation();
             $this->db->trans_start();
             $tests = new Test();
             $tests->where_related('task/task_set', 'id', $task_set->id);
             $tests->where('type', $test_type);
             $tests->where('enable_scoring >', 0);
             $tests->group_by('task_id');
             $tests->where('task_task_task_set_rel.bonus_task', 0);
             $tests->get_iterated();
             //$output->debug = $tests->check_last_query(array('', ''), TRUE);
             $test_count = $tests->result_count();
             $min_results = $task_set->test_min_needed > $test_count ? $test_count : $task_set->test_min_needed;
             $course = new Course();
             $course->where_related_task_set('id', $task_set->id);
             $course->get();
             $min_points_limit = -$course->default_points_to_remove;
             if ($test_count > 0) {
                 $total_score = 0;
                 $score_array = array();
                 $bonus_tasks_array = array();
                 $score_percentage = array();
                 $bonus_tasks_percentage = array();
                 if (count($results)) {
                     foreach ($results as $task_id => $score) {
                         $this->db->select('*');
                         $this->db->where('task_set_id', $task_set->id);
                         $this->db->where('task_id', (int) $task_id);
                         $query = $this->db->get('task_task_set_rel');
                         if ($query->num_rows() > 0) {
                             $task_rel = $query->row_object();
                             $min = $task_rel->test_min_points;
                             $max = $task_rel->test_max_points;
                             $diff = abs($max - $min);
                             $score_percent = (double) $score / 100;
                             $sub_score = round(10 * ($min + $diff * $score_percent)) / 10;
                             if ($task_rel->bonus_task == 0) {
                                 $score_array[$task_id] = $sub_score;
                                 $score_percentage[$task_id] = $score;
                             } else {
                                 $bonus_tasks_array[$task_id] = $sub_score;
                                 $bonus_tasks_percentage[$task_id] = $score;
                             }
                         }
                         $query->free_result();
                     }
                 }
                 $max_results = $task_set->test_max_allowed < count($score_array) ? $task_set->test_max_allowed : count($score_array);
                 arsort($score_array, SORT_NUMERIC);
                 $i = 0;
                 foreach ($score_array as $task_id => $points) {
                     if ($i < $max_results) {
                         $total_score += $points;
                         $i++;
                     } else {
                         break;
                     }
                 }
                 $total_score = $total_score < $min_points_limit ? $min_points_limit : $total_score;
                 arsort($bonus_tasks_array, SORT_NUMERIC);
                 $total_score += array_sum($bonus_tasks_array);
                 if (count($score_array) >= $min_results) {
                     $tasks = new Task();
                     $tasks->where_related_task_set('id', $task_set_id);
                     $tasks->order_by('`task_task_set_rel`.`sorting`', 'asc');
                     $tasks->get_iterated();
                     //$output->debug = $tasks->check_last_query(array('', ''), TRUE);
                     $output->evaluation = $this->parser->parse('backend/tests/evaluation_table.tpl', array('tasks' => $tasks, 'real_points' => $score_array, 'bonus_points' => $bonus_tasks_array, 'real_percentage' => $score_percentage, 'bonus_percentage' => $bonus_tasks_percentage, 'max_results' => $max_results), TRUE);
                     $solution = new Solution();
                     $solution->where('task_set_id', $task_set->id);
                     $solution->where('student_id', $student->id);
                     $solution->get();
                     $save_solution = FALSE;
                     $solution_not_considered = FALSE;
                     $output->points_new = $total_score;
                     if ($solution->exists()) {
                         if ($solution->not_considered == 0) {
                             $output->points_before = $solution->points;
                             if ($solution->points < $total_score || is_null($solution->points)) {
                                 $solution->points = $total_score;
                                 $solution->comment = '';
                                 $solution->teacher_id = NULL;
                                 $solution->best_version = (int) $version;
                                 $solution->revalidate = 0;
                                 $save_solution = TRUE;
                             }
                         } else {
                             $solution_not_considered = TRUE;
                         }
                     } else {
                         $solution->points = $total_score;
                         $solution->comment = '';
                         $solution->teacher_id = NULL;
                         $solution->best_version = (int) $version;
                         $solution->task_set_id = $task_set->id;
                         $solution->student_id = $student->id;
                         $solution->revalidate = 0;
                         $save_solution = TRUE;
                     }
                     if ($save_solution) {
                         $solution->save();
                         $output->result = TRUE;
                         $this->_action_success();
                     } else {
                         if (!$solution_not_considered) {
                             $output->message = sprintf($this->lang->line('admin_tests_test_result_nothing_to_update'), $output->points_new, $output->points_before);
                         } else {
                             $output->message = $this->lang->line('admin_tests_test_result_solution_not_considered');
                         }
                     }
                 } else {
                     $output->message = sprintf($this->lang->line('admin_tests_test_result_minimum_number_of_test_not_selected'), $min_results);
                 }
             } else {
                 $output->message = $this->lang->line('admin_tests_test_result_no_evaluationg_tests');
             }
             $this->db->trans_complete();
         } else {
             $output->message = $this->lang->line('admin_tests_test_result_disabled');
         }
     } else {
         $output->message = $this->lang->line('admin_tests_test_result_input_error');
     }
     $this->test_score->delete_token($token);
     $this->output->set_content_type('application/json');
     $this->output->set_output(json_encode($output));
 }
예제 #20
0
 /**
  * @return Course
  */
 public function getCourse()
 {
     return Course::get($course_id);
 }
예제 #21
0
파일: exam.php 프로젝트: jedaika/Trainings
    function displayBody()
    {
        parent::displayBody();
        $translator = new Translator();
        $course = new Course();
        $training = new Training();
        $t_data = $training->get(array('exam_hash' => $this->exam_hash, 'user_id' => $_SESSION['user_id']));
        $c_data = $course->get(array('id' => $t_data['course_id']));
        foreach ($c_data as $key => $val) {
            $c_data[$key] = htmlspecialchars($val, ENT_QUOTES);
        }
        echo <<<EOF
<div class="container-fluid">
<div class="col-lg-10 col-lg-offset-1" id="window">
\t<div class="row" >
\t<div class="col-xs-10">
\t    <h4>{$c_data[category_name]}</h4>
\t    <h2>{$c_data[name]}</h2>
\t</div>
\t<div class="col-xs-2 text-right" id="top_buttons">
\t    <a href="#" id="fullscreen"><span class="glyphicon glyphicon-fullscreen"></span></a>
\t    <a href="#" id="inscreen" class="collapse"><span class="glyphicon glyphicon-remove"></span></a>
\t</div>
\t</div>

EOF;
        try {
            $d2 = new DateTime('now');
            $diff = $d2->diff(new DateTime($t_data['finished']));
            $diff = $diff->format('%r%i');
            if ($diff < 0) {
                throw new Exception("Time out", self::TIMEOUT);
            }
            $exam = new Exam();
            $enum = $exam->enumerate(array('training_id' => $t_data['id']), intval($this->page), 1, 'id');
            $cnt = $exam->getCount(array('training_id' => $t_data['id']));
            $current = $this->page + 1;
            $back = $this->page > 0 ? $this->page - 1 : 0;
            $next = $this->page + 1;
            if (!$enum) {
                throw new Exception("Not found", self::NOTFOUND);
            }
            $e_data = $enum->current();
            $question = new Question();
            $q_data = $question->get(array('id' => $e_data['question_id']));
            echo <<<EOF
\t<div class="embed-responsive embed-responsive-16by9" id="fullscreen_media">
\t<p>{$translator->Question}: {$current} / {$cnt}</p>
\t<p> {$translator->Time_remain}: {$diff}</p>
\t{$q_data[data]}
\t<hr>
\t{$translator->Answer}: 
\t    <form action="?" method="post">
\t    <input type="hidden" name="id" value="{$e_data[id]}">
EOF;
            switch ($q_data['type_id']) {
                case Question::SINGLE:
                    echo "<ol>";
                    for ($i = 1; $i <= $q_data['count']; $i++) {
                        echo "<li><input type=\"radio\" name=\"answer\" value=\"{$i}\" " . ($i == $e_data['answer'] ? 'checked' : '') . "></li>" . NL;
                    }
                    echo "</ol>";
                    break;
                case Question::MULTI:
                    echo "<ol>";
                    $e_data['answer'] = explode(',', $e_data['answer']);
                    for ($i = 1; $i <= $q_data['count']; $i++) {
                        echo "<li><input type=\"checkbox\" name=\"answer[]\" value=\"{$i}\" " . (in_array($i, $e_data['answer']) ? 'checked' : '') . "></li>" . NL;
                    }
                    echo "</ol>";
                    break;
                case Question::TEXT:
                    echo "<input type=\"text\" name=\"answer\" value=\"{$e_data['answer']}\">" . NL;
                    break;
                default:
            }
            $back = $this->page > 0 ? $this->page - 1 : 0;
            $next = $this->page + 1;
            echo <<<EOF
\t    <input type="submit" class="btn btn-primary">
\t    </form>
\t</div>

EOF;
        } catch (Exception $e) {
            switch ($e->getCode()) {
                case self::TIMEOUT:
                    echo <<<EOF
    <div class="bs-callout bs-callout-danger" id="callout-type-b-i-elems">
    <h4>{$translator->Timeout}</h4>
    <p>{$translator->Timeout_Desc}</p>
    <p class="text-muted">{$translator->BackCourses}</p>
    </div>

EOF;
                    $training->update($t_data['id'], array('status_id' => Training::FAILED));
                    break;
                case self::NOTFOUND:
                    echo <<<EOF
    <div class="embed-responsive embed-responsive-16by9" id="fullscreen_media">
    <div class="bs-callout bs-callout-info" id="callout-type-b-i-elems">
    <h4>{$translator->Not_found}</h4>
    <p>{$translator->Not_found_Desc}</p>
    <p class="text-muted">{$translator->BackExam}</p>
    </div>
    </div>

EOF;
                    break;
                default:
                    echo $e;
                    echo <<<EOF
    <div class="bs-callout bs-callout-danger" id="callout-type-b-i-elems">
    <h4>{$translator->Error}</h4>
    <p>{$translator->Error_Desc}</p>
    <p class="text-muted">{$translator->BackExam}</p>
    </div>

EOF;
            }
            // echo "<script>window.history.back();</script>";
        }
        echo <<<EOF
\t<nav id="bottom_buttons">
\t  <ul class="pager">
\t    <li class="previous"><a href="{$back}" id="back"><span aria-hidden="true">&larr;</span> {$translator->Back}</a></li>
\t    <li class="top"><a href="0" id="top">{$translator->Top}</a>|
\t\t<a href="/result/{$t_data[id]}" onclick='return confirm("{$translator->AreYouSure}");'>{$translator->Finish}</a></li>
\t    <li class="next"><a href="{$next}" id="next">{$translator->Next} <span aria-hidden="true">&rarr;</span></a></li>
\t  </ul>
\t</nav>
</div>
</div> <!-- /container -->

EOF;
    }
예제 #22
0
 public function select_project($task_set_id, $task_id, $student_id)
 {
     $output = new stdClass();
     $output->message = '';
     $output->status = FALSE;
     $this->_transaction_isolation();
     $this->db->trans_begin();
     $task_set = new Task_set();
     $task_set->where('content_type', 'project');
     $task_set->get_by_id((int) $task_set_id);
     $task = new Task();
     $task->get_by_id((int) $task_id);
     $student = new Student();
     $student->get_by_id((int) $student_id);
     $course = new Course();
     $course->where_related_task_set($task_set);
     $course->get();
     $participant = new Participant();
     $participant->where_related_course($course);
     $participant->where_related($student);
     $participant->where('allowed', 1);
     $participant->get();
     $project_selection = new Project_selection();
     $project_selection->where_related_student($student);
     $project_selection->where_related_task_set($task_set);
     $project_selection->get();
     if ($task_set->exists() && $task->exists() && $task_set->is_related_to($task) && $student->exists() && $course->exists() && $participant->exists()) {
         if ($task_set->get_student_files_count($student->id) == 0) {
             $all_project_selections = new Project_selection();
             $all_project_selections->where_related_task_set($task_set);
             $all_project_selections->where_related_task($task);
             $currently_selected = $all_project_selections->count();
             $jf_task = $task_set->task->include_join_fields()->get_by_id($task_id);
             $maximum_selections = (int) $jf_task->join_max_projects_selections;
             if ($project_selection->exists()) {
                 if (!$project_selection->is_related_to($task)) {
                     if ($currently_selected < $maximum_selections) {
                         $project_selection->save($task);
                         $output->status = TRUE;
                         $output->message = $this->lang->line('admin_task_sets_project_selection_success');
                     } else {
                         $output->message = $this->lang->line('admin_task_sets_project_selection_no_room');
                     }
                 } else {
                     $output->message = $this->lang->line('admin_task_sets_project_selection_already_selected');
                 }
             } else {
                 if ($currently_selected < $maximum_selections) {
                     $project_selection->save(array('student' => $student, 'task_set' => $task_set, 'task' => $task));
                     $output->status = TRUE;
                     $output->message = $this->lang->line('admin_task_sets_project_selection_success');
                 } else {
                     $output->message = $this->lang->line('admin_task_sets_project_selection_no_room');
                 }
             }
         } else {
             $output->message = $this->lang->line('admin_task_sets_project_selection_already_submited_solutions');
         }
     } else {
         $output->message = $this->lang->line('admin_task_sets_project_selection_cant_find_data');
     }
     if ($output->status) {
         $this->db->trans_commit();
         $this->_action_success();
     } else {
         $this->db->trans_rollback();
     }
     $this->output->set_content_type('application/json');
     $this->output->set_output(json_encode($output));
 }
예제 #23
0
 public function getCourse($course_id = NULL)
 {
     if (is_null($course_id)) {
         if (isset($this->course_id)) {
             $course_id = $this->course_id;
         } else {
             return false;
         }
     }
     return Course::get($course_id);
 }
예제 #24
0
파일: home.php 프로젝트: bennyty/suggestr
 public function process($get, $post)
 {
     $this->pageData["Title"] = "Home";
     //Generate the data from mysql.
     //NEED TO FIGURE OUT WHY COOKIE IS NOT WORKING. HERE I SET IT manually.
     $_COOKIE['sessionId'] = rand(880, 925);
     //Something wrong when no classes are taken by a given session.
     //I'll try to fix that someday.
     $Data = new Database();
     //Setting up student
     //Replace with $session_id. The cookie doesn't work for me(Lucien) though...
     //$session = 912;//intval($_COOKIE['sessionId']);
     //echo "num: ".$session;
     $student = $Data->getStudent($_COOKIE['sessionId']);
     $studentCourses = $student->getTaken();
     //echo " Session: ".$student->getId()." major: ".$student->getMajor()." year: ".$student->getYear();
     foreach ($studentCourses as $course) {
         $result = new Course();
         $result->findById($course);
         //echo "<h4>".$result->get('name')."<h4>";
     }
     //Here's the array of courses generated by the Jaccard index.
     $JaccardCourses = $Data->getSuggestedCourses($studentCourses);
     // Select all of the courses that this user is already added or ignored
     $query = new Query('action');
     $result = $query->select('*', array(array('session_id', '=', $_COOKIE['sessionId'])));
     $idsAlreadyAdded = array();
     foreach ($result as $action) {
         array_push($idsAlreadyAdded, $action->get('course_id'));
     }
     // Generate all of the courses (for testing)
     //Get list of predicted courses from Python.
     $predClasses = $this->predictClasses();
     $allCourses = array();
     $query = new Query('courses');
     //Adding predicted courses to the $allCourses array.
     /*foreach($predClasses as $class){
     			$result = new Course();
     			$result->findById($class['id']);
     			array_push($allCourses,$result);
     		}*/
     //Grabs the Id's from the Jaccard Array and
     foreach ($JaccardCourses as $class => $score) {
         $result = new Course();
         $result->findById($class);
         array_push($allCourses, $result);
     }
     //$allcourses only contains the course id's
     //Create new array containing all the course details based on what is in Allcourses.
     $allNewCourses = array();
     foreach ($allCourses as $course) {
         try {
             if (!in_array($course->get('id'), $idsAlreadyAdded)) {
                 // Check that this course has not been added by the user yet
                 array_push($allNewCourses, array('id' => $course->get('id'), 'name' => ucwords(strtolower($course->get('name'))), 'department_id' => $course->get('department_id'), 'number' => $course->get('number'), 'description' => strlen($course->get('description')) == 0 ? 'No description' : $course->get('description')));
             }
         } catch (Exception $e) {
         }
     }
     //Populate webpage with all the different courses that were predicted.
     $this->pageData['allCourses'] = $allNewCourses;
     /*
     		IMPORTANT NODE
     */
     //////////
     // Select all of the courses that this user is already added
     $query = new Query('action');
     $result = $query->select('*', array(array('session_id', '=', $_COOKIE['sessionId']), array('choice', '=', 1)));
     ///is 0 in leo's version, 1 in my old database. we need to sort that shit.
     $idsAlreadyAdded = array();
     foreach ($result as $action) {
         array_push($idsAlreadyAdded, $action->get('course_id'));
     }
     // Get all of the courses in this user's session
     $usersCourses = array();
     foreach ($idsAlreadyAdded as $courseId) {
         try {
             $course = new Course();
             $course->findById($courseId);
             array_push($usersCourses, array('id' => $course->get('id'), 'name' => ucwords(strtolower($course->get('name'))), 'department_id' => $course->get('department_id'), 'number' => $course->get('number')));
         } catch (Exception $e) {
         }
     }
     $this->pageData['usersCourses'] = $usersCourses;
     //Pushes all the new courses to the view.
 }
예제 #25
0
    function displayBody()
    {
        parent::displayBody();
        $translator = new Translator();
        $course = new Course();
        $training = new Training();
        $id = array_shift($this->param);
        try {
            $t_exists = $training->checkFinish($_SESSION['user_id'], $id);
        } catch (Exception $e) {
        }
        $data = $course->get(array('id' => $id));
        foreach ($data as $key => $val) {
            $data[$key] = htmlspecialchars($val, ENT_QUOTES);
        }
        foreach ($course->formats as $key => $val) {
            if ($key == $data['format_id']) {
                $format = htmlspecialchars($val, ENT_QUOTES);
            }
        }
        foreach ($course->languages as $key => $val) {
            if ($key == $data['language']) {
                $language = htmlspecialchars($val, ENT_QUOTES);
            }
        }
        if ($data['active'] == 't') {
            $active = 'checked';
        }
        if ($data['exam'] == 't') {
            $exam = 'checked';
        }
        if ($data[duration] > 8) {
            $duration = floor($data['duration'] / 8) . " {$translator->days}" . ($data['duration'] % 8 > 0 ? " + " . $data['duration'] % 8 . " {$translator->hours}" : '');
        } else {
            $duration = $data['duration'] . " {$translator->hours}";
        }
        if ($t_exists) {
            $disabled = 'disabled';
        }
        echo <<<EOF
<div class="container-fluid">
<div class="col-md-10 col-lg-8 col-lg-offset-2 ">
\t<h4>{$data[category_name]}</h4>
\t<h2>{$data[name]}</h2>
\t<div class="row">
\t    <div class="col-sm-6"><small>{$translator->Duration}: {$duration}</small></div>
\t    <div class="col-sm-6 text-right"><small>{$translator->Format}: {$format}</small></div>
\t</div>
\t<hr/>
\t<label for="describe">{$translator->Describe}:</label> 
\t<p class="describe">{$data[describe]}</p>
\t<label for="data">{$translator->Prerequisites}:</label> 
\t<p class="describe">{$data[prerequisites]}</p>
\t<label for="skills">{$translator->Skills}:</label>
\t<p class="describe">{$data[skills]}</p>
\t<label for="equipment">{$translator->Equipment}:</label>
\t<p class="describe">{$data[equipment]}</p>

<!-- TODO>
 Add needed courses select-box
\t    <div class="form-group">Courses</div>
<!-->
\t<div>
\t    <label for="language">{$translator->Language}:</label> {$language}
\t</div>
\t<div>
\t    <label for="language">{$translator->Author}:</label> {$data[author]}
\t</div>
\t<hr/>
\t<div>
\t\t<a href="/enroll/{$data['id']}" class="btn btn-primary btn-lg {$disabled}" >{$translator->Register}</a>
\t</div>
\t</div>
</div> <!-- /container -->

EOF;
    }
예제 #26
0
    function displayBody()
    {
        parent::displayBody();
        $translator = new Translator();
        $course = new Course();
        $data = $course->get(array('id' => $this->id));
        foreach ($data as $key => $val) {
            $data[$key] = htmlspecialchars($val, ENT_QUOTES);
        }
        $path = preg_replace('/\\//', '</li><li>', $this->path);
        echo <<<EOF
<h4>{$data[category_name]}</h4>
<h2  class="page-header">{$data[name]}</h2>
<ol class="breadcrumb">
\t<li><a href="/admin_manager/list/{$this->id}"><span class="glyphicon glyphicon-home"></span> {$translator->Back}</a>
\t<li>{$path}
</ol>

EOF;
        if (preg_match('/.*(jpe?g|png|gif|svg)$/i', $this->path)) {
            $type = "image";
        }
        if (preg_match('/.*(txt|htm|html)$/i', $this->path)) {
            $type = "text";
        }
        if (preg_match('/.*(swf|pdf)$/i', $this->path)) {
            $type = "embed";
        }
        if (preg_match('/.*(mov|mp4|wmv|avi)$/i', $this->path)) {
            $type = "video";
        }
        if (preg_match('/.*(mp3)$/i', $this->path)) {
            $type = "audio";
        }
        switch ($type) {
            case 'text':
                echo <<<EOF
<div class="col-lg-8">
    <form action="/admin_editor/save/{$this->id}/{$this->path}" method="post">
\t\t<textarea name="data" id="data" rows=5 class="form-control">

EOF;
                echo htmlspecialchars(file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/../files/courses/' . $this->id . '/' . $this->path));
                echo <<<EOF
    \t\t</textarea>
<button type="submit" class="btn btn-md btn-primary">{$translator->Save}</button>\t\t
    </form>
</div>
EOF;
                break;
            case 'image':
                echo <<<EOF
\t\t<img src="/admin_editor/get_image/{$this->id}/{$this->path}" class="img-responsive">
\t\t
EOF;
                break;
            case 'video':
                echo <<<EOF
\t\t<div class="embed-responsive embed-responsive-16by9">
\t\t  <video class="embed-responsive-item" controls>
\t\t  <source src="/admin_editor/get_image/{$this->id}/{$this->path}" ></source>
\t\t  </video>
\t\t</div>
EOF;
                break;
            case 'audio':
                echo <<<EOF
\t\t<div class="">
\t\t  <audio class="embed-responsive-item" controls>
\t\t  <source src="/admin_editor/get_image/{$this->id}/{$this->path}" >
\t\t  </audio>
\t\t</div>
EOF;
                break;
            case 'embed':
                echo <<<EOF
\t\t<div class="embed-responsive embed-responsive-16by9">
\t\t  <object data="/admin_editor/get_image/{$this->id}/{$this->path}" class="embed-responsive-item"></object>
\t\t</div>
EOF;
                break;
        }
    }
예제 #27
0
    function displayBody()
    {
        parent::displayBody();
        $translator = new Translator();
        $plan = new Plan();
        $page = $_GET['page'];
        $offset = intval($page) * ITEMS_IN_PAGE;
        if (isset($_GET['search'])) {
            unset($_GET['search']);
            unset($_GET['page']);
            $search = $_GET;
        } else {
            $search = array('active' => 'true');
        }
        $search['not_finish'] = 'true';
        $cnt = $plan->getCount($search);
        if (sizeof($_GET) > 0) {
            foreach ($_GET as $key => $val) {
                $values[$key] = htmlspecialchars($val, ENT_QUOTES);
            }
        }
        $categories = Course::getCategoriesForSelect(0);
        if ($cnt > ITEMS_IN_PAGE) {
            $pagination = $this->addPaginator($cnt, $page);
        }
        echo <<<EOF
<h2  class="page-header">{$translator->Plans_header} <span class="badge">{$cnt}</span></h2>
    <!-- disable filter temporary
    <div class="row">
\t<div class="btn-group">
\t<button class="btn btn-sm btn-default"  data-toggle="collapse" data-target="#filter">
\t    <span class="glyphicon glyphicon-filter"></span> {$translator->Filter}
\t</button>
\t</div>
    </div>

    <div class="row">
        <div class="col-md-5 collapse" id="filter">
\t    <form role="form" class="form-horizontal" action="?" method="get">
\t\t<div class="form-group">
\t\t    <div class="form-group">
\t\t    <label for="category" class="control-label col-sm-3">{$translator->Category}:</label>
\t\t    <div class="col-sm-8">
\t\t    <select name="category_id" class="form-control" >
\t\t\t{$categories}
\t\t    </select>
\t\t    </div>
\t\t    </div>
\t\t    <div class="form-group">
\t\t    <label for="start" class="control-label col-sm-3">{$translator->Start}:</label>
\t\t    <div class="col-sm-8">
\t\t    <input type="text" class="form-control datetimepicker" id="start" name="start" value="{$values[start]}">
\t\t    </div>
\t\t    </div>
\t\t    <div class="form-group">
\t\t    <label for="finish" class="control-label col-sm-3">{$translator->Finish}:</label>
\t\t    <div class="col-sm-8">
\t\t    <input type="text" class="form-control datetimepicker" id="finish" name="finish" value="{$values[finish]}">
\t\t    </div>
\t\t    </div>
\t\t    <div class="form-group">
\t\t    <div class="col-sm-offset-3 col-md-10">
\t\t    <input class="sr-only" name="search" value="1">
\t\t    <button type="submit" class="btn btn-sm btn-default">{$translator->Apply}</button>
\t\t    </div>
\t\t    </div>
\t\t</div>
\t    </form>
\t</div>
    </div> -->

EOF;
        $course = new Course();
        $training = new Training();
        $enum = $plan->enumerate($search, $offset, ITEMS_IN_PAGE);
        if (is_object($enum)) {
            echo <<<EOF
{$pagination}
          <div class="table-responsive">
            <table class="table table-striped">
              <thead>
                <tr>
                  <th>#</th>
                  <th>{$translator->Course}</th>
                  <th>{$translator->Start}</th>
                  <th>{$translator->Finish}</th>
                  <th>{$translator->Users}</th>
                </tr>
              </thead>
              <tbody>

EOF;
            $i = 1 + $offset;
            foreach ($enum as $key => $data) {
                $c_data = $course->get(array('id' => $data['course_id']));
                $participants = $training->getCount(array('plan_id' => $data['id']));
                echo "                <tr>\n                  <td>{$i}</td>\n                  <td>" . ($data['active'] == 'f' ? '<del>' : '') . "<p class=\"text-muted\">{$data[category_name]}</p>\n\t\t\t<a href=\"/course/{$c_data[id]}\">{$c_data[name]}</a></td>\n                  <td>{$data[start]}</td>\n                  <td>{$data[finish]}</td>\n                  <td>{$participants}</td>\n                </tr>" . NL;
                $i++;
            }
            echo <<<EOF
\t    </table>
\t</div>

EOF;
        } else {
            echo $translator->No_trainings;
        }
    }
예제 #28
0
 public function index($worker_id = 0)
 {
     $test_queue = new Test_queue();
     $execute_tests = FALSE;
     try {
         $this->db->query('SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;');
         $this->db->trans_begin();
         $test_queue->where('worker', NULL);
         $test_queue->where('status', 0);
         $test_queue->where('version >', 0);
         $test_queue->group_start(' NOT ');
         $test_queue->where('task_set_id', NULL);
         $test_queue->group_end();
         $test_queue->group_start(' NOT ');
         $test_queue->where('student_id', NULL);
         $test_queue->group_end();
         $test_queue->order_by('priority', 'asc');
         $test_queue->order_by('start', 'asc');
         $test_queue->limit(1);
         $sql_query = $test_queue->get_sql();
         $sql_query = rtrim($sql_query, '; ' . "\n\r") . ' FOR UPDATE;';
         $test_queue->query($sql_query);
         if ($test_queue->exists()) {
             $test_queue->worker = (int) $worker_id;
             $test_queue->status = 1;
             $test_queue->exec_start = date('Y-m-d H:i:s');
             $test_queue->where('worker', NULL);
             $test_queue->where('status', 0);
             if ($test_queue->save()) {
                 $this->db->trans_commit();
                 $execute_tests = TRUE;
             } else {
                 $this->db->trans_rollback();
             }
         } else {
             $this->db->trans_rollback();
         }
     } catch (Exception $e) {
     }
     if ($test_queue->exists() && $execute_tests) {
         //$this->db->query('SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;');
         //$this->db->trans_begin();
         $this->lang->reinitialize_for_idiom($test_queue->system_language);
         $this->lang->load('admin/tests');
         $task_set = new Task_set();
         $task_set->include_related('course', 'test_scoring_deadline');
         $task_set->get_by_id($test_queue->task_set_id);
         $student = new Student();
         $student->get_by_id($test_queue->student_id);
         $tests = new Test();
         $tests->where_related($test_queue);
         $tests->get_iterated();
         try {
             if ($task_set->exists() && $student->exists() && $tests->exists()) {
                 $version = $test_queue->version;
                 $run_evaluation = $task_set->enable_tests_scoring > 0 && $task_set->course_test_scoring_deadline >= date('Y-m-d H:i:s') ? TRUE : FALSE;
                 $score_percent = array();
                 $score_points = array();
                 $bonus_percent = array();
                 $bonus_points = array();
                 $total_tests_count = $tests->result_count();
                 foreach ($tests as $test) {
                     $test_queue->single_test_exec_start = date('Y-m-d H:i:s');
                     $test_queue->save();
                     $files = $task_set->get_student_files($student->id, (int) $version);
                     if (isset($files[(int) $version]['filepath']) && file_exists($files[(int) $version]['filepath'])) {
                         $test_object = $this->load->test($test->type);
                         $test_object->initialize($test);
                         $token = '';
                         //echo 'Test queue ' . $test_queue->id . ' is running test ' . $test->id . ' ... ' . PHP_EOL;
                         try {
                             $test_output = $test_object->run($files[(int) $version]['filepath'], $run_evaluation && $test->enable_scoring > 0, $student->id, $token);
                             $test_score = $test_object->get_last_test_score();
                         } catch (Exception $e) {
                             $test_output = $e->getMessage();
                             $test_score = 0;
                         }
                         $test_queue->set_join_field($test, 'result_text', $test_output);
                         $test_queue->set_join_field($test, 'evaluation_table', $test_object->get_last_test_scoring());
                         $test_queue->set_join_field($test, 'result', $test_object->get_last_exit_code());
                         //echo 'Test queue ' . $test_queue->id . ' is done with test ' . $test->id . ' ... ' . PHP_EOL;
                         if ($run_evaluation && $test->enable_scoring > 0) {
                             $this->db->select('*');
                             $task_id = $test->task_id;
                             $this->db->where('task_set_id', $task_set->id);
                             $this->db->where('task_id', (int) $task_id);
                             $query = $this->db->get('task_task_set_rel');
                             if ($query->num_rows() > 0) {
                                 $task_rel = $query->row_object();
                                 $min = (double) $task_rel->test_min_points;
                                 $max = (double) $task_rel->test_max_points;
                                 $percent = (double) $test_score / 100.0;
                                 $points = (1.0 - $percent) * $min + $percent * $max;
                                 if ($task_rel->bonus_task == 0) {
                                     $test_queue->set_join_field($test, 'percent_points', $test_score);
                                     $test_queue->set_join_field($test, 'points', $points);
                                     $score_percent[$task_id] = isset($score_percent[$task_id]) ? $score_percent[$task_id] + $percent : $percent;
                                     $percent = (double) $score_percent[$task_id];
                                     $points = (1.0 - $percent) * $min + $percent * $max;
                                     $score_points[$task_id] = $points;
                                 } else {
                                     $test_queue->set_join_field($test, 'percent_bonus', $test_score);
                                     $test_queue->set_join_field($test, 'bonus', $points);
                                     $bonus_percent[$task_id] = isset($bonus_percent[$task_id]) ? $bonus_percent[$task_id] + $percent : $percent;
                                     $percent = (double) $bonus_percent[$task_id];
                                     $points = (1.0 - $percent) * $min + $percent * $max;
                                     $bonus_points[$task_id] = $points;
                                 }
                             }
                             $query->free_result();
                         }
                     } else {
                         //$this->db->trans_rollback();
                         $test_queue->worker = NULL;
                         $test_queue->status = 3;
                         $test_queue->finish = date('Y-m-d H:i:s');
                         $test_queue->save();
                         die;
                     }
                 }
                 $tests = new Test();
                 $tests->where_related('task/task_set', 'id', $task_set->id);
                 $tests->where('type', $test_queue->test_type);
                 $tests->where('enable_scoring >', 0);
                 $tests->group_by('task_id');
                 $tests->where('task_task_task_set_rel.bonus_task', 0);
                 $tests->get_iterated();
                 $test_count = $tests->result_count();
                 $min_results = $task_set->test_min_needed > $test_count ? $test_count : $task_set->test_min_needed;
                 $course = new Course();
                 $course->where_related_task_set('id', $task_set->id);
                 $course->get();
                 $min_points_limit = -$course->default_points_to_remove;
                 if ($test_count > 0 && $run_evaluation) {
                     $max_results = $task_set->test_max_allowed < count($score_points) ? $task_set->test_max_allowed : count($score_points);
                     arsort($score_points, SORT_NUMERIC);
                     $i = 0;
                     $total_score = 0;
                     foreach ($score_points as $task_id => $points) {
                         if ($i < $max_results) {
                             $total_score += $points;
                             $i++;
                         } else {
                             break;
                         }
                     }
                     $total_score = $total_score < $min_points_limit ? $min_points_limit : $total_score;
                     $total_bonus = array_sum($bonus_points);
                     $total_score += $total_bonus;
                     if (count($score_points) >= $min_results) {
                         $solution = new Solution();
                         $solution->where('task_set_id', $task_set->id);
                         $solution->where('student_id', $student->id);
                         $solution->get();
                         $save_solution = FALSE;
                         $solution_not_considered = FALSE;
                         $solution_disable_evaluation = FALSE;
                         $best_old_score = $min_points_limit;
                         if ($solution->exists()) {
                             if ($solution->not_considered == 0) {
                                 if ($solution->disable_evaluation_by_tests == 0) {
                                     if ($solution->tests_points < $total_score || is_null($solution->tests_points)) {
                                         $solution->tests_points = $total_score;
                                         $solution->teacher_id = NULL;
                                         $solution->best_version = (int) $version;
                                         $solution->revalidate = 0;
                                         $save_solution = TRUE;
                                     } else {
                                         $best_old_score = $solution->tests_points;
                                     }
                                 } else {
                                     $solution_disable_evaluation = TRUE;
                                 }
                             } else {
                                 $solution_not_considered = TRUE;
                             }
                         } else {
                             $solution->tests_points = $total_score;
                             $solution->comment = '';
                             $solution->teacher_id = NULL;
                             $solution->best_version = (int) $version;
                             $solution->task_set_id = $task_set->id;
                             $solution->student_id = $student->id;
                             $solution->revalidate = 0;
                             $save_solution = TRUE;
                         }
                         if ($save_solution) {
                             $solution->save();
                             $this->parser->clearCache('frontend/tasks/index.tpl');
                             $test_queue->result_message = $this->lang->line('admin_tests_test_result_new_points_added');
                         } else {
                             if (!$solution_disable_evaluation) {
                                 if (!$solution_not_considered) {
                                     $test_queue->result_message = sprintf($this->lang->line('admin_tests_test_result_nothing_to_update'), $total_score, $best_old_score);
                                 } else {
                                     $test_queue->result_message = $this->lang->line('admin_tests_test_result_solution_not_considered');
                                 }
                             } else {
                                 $test_queue->result_message = $this->lang->line('admin_tests_test_result_solution_disable_evaluation');
                             }
                         }
                         $test_queue->points = $total_score - $total_bonus;
                         $test_queue->bonus = $total_bonus;
                     } else {
                         $test_queue->result_message = sprintf($this->lang->line('admin_tests_test_result_minimum_number_of_test_not_selected'), $min_results);
                     }
                     $result_table_tasks = new Task();
                     $result_table_tasks->where_related_task_set('id', $task_set->id);
                     $result_table_tasks->order_by('`task_task_set_rel`.`sorting`', 'asc');
                     $result_table_tasks->get_iterated();
                     $test_queue->result_html = $this->parser->parse('backend/tests/evaluation_table.tpl', array('tasks' => $result_table_tasks, 'real_points' => $score_points, 'bonus_points' => $bonus_points, 'real_percentage' => $score_percent, 'bonus_percentage' => $bonus_percent, 'max_results' => $max_results), TRUE);
                     $test_queue->worker = NULL;
                     $test_queue->status = 2;
                     $test_queue->finish = date('Y-m-d H:i:s');
                     $test_queue->save();
                     //$this->db->trans_commit();
                 } else {
                     if ($total_tests_count && !$run_evaluation) {
                         $test_queue->worker = NULL;
                         $test_queue->status = 2;
                         $test_queue->finish = date('Y-m-d H:i:s');
                         $test_queue->result_message = $this->lang->line('admin_tests_test_result_testing_finished');
                         $test_queue->save();
                         //$this->db->trans_commit();
                     } else {
                         //$this->db->trans_rollback();
                         $test_queue->worker = NULL;
                         $test_queue->status = 3;
                         $test_queue->finish = date('Y-m-d H:i:s');
                         $test_queue->result_message = $this->lang->line('admin_tests_test_result_no_test_selected');
                         $test_queue->save();
                     }
                 }
             } else {
                 //$this->db->trans_rollback();
                 $test_queue->worker = NULL;
                 $test_queue->status = 3;
                 $test_queue->finish = date('Y-m-d H:i:s');
                 $test_queue->result_message = $this->lang->line('admin_tests_test_result_configuration_error');
                 $test_queue->save();
             }
         } catch (Exception $e) {
             //$this->db->trans_rollback();
             $test_queue->worker = NULL;
             $test_queue->status = 3;
             $test_queue->finish = date('Y-m-d H:i:s');
             $test_queue->result_message = $this->lang->line('admin_tests_test_result_execution_error');
             $test_queue->result_html = '<pre>' . $e->getMessage() . '</pre>';
             $test_queue->save();
         }
     }
     //@unlink($test_locks_path . 'worker_' . (int)$worker_id . '_lock.txt');
 }