public function select_group() { $group_id = $this->input->post('group_id'); $this->_transaction_isolation(); $this->db->trans_begin(); $group = new Group(); $group->get_by_id($group_id); if ($group->exists()) { $course = $group->course->get(); if (is_null($course->groups_change_deadline) || date('U', strtotime($course->groups_change_deadline)) >= time()) { $student = new Student(); $student->get_by_id($this->usermanager->get_student_id()); if ($student->is_related_to('active_course', $course->id)) { $participant = new Participant(); $participant->where_related($student); $participant->where_related($course); $participant->where('allowed', 1); $participant->get(); if ($participant->exists()) { if (!$participant->is_related_to($group)) { $participant->save($group); $participant->where_related($course); $participant->where_related($group); $participant->where('allowed', 1); $participants_count = $participant->count(); $room = new Room(); $room->where_related($group)->order_by('capacity', 'asc')->limit(1)->get(); if ($participants_count > intval($room->capacity)) { $this->db->trans_rollback(); $this->messages->add_message('lang:groups_message_group_is_full', Messages::MESSAGE_TYPE_ERROR); } else { $this->db->trans_commit(); $this->messages->add_message(sprintf($this->lang->line('groups_message_group_changed'), $this->lang->text($group->name)), Messages::MESSAGE_TYPE_SUCCESS); $this->_action_success(); $this->output->set_internal_value('course_id', $participant->course_id); } } else { $this->db->trans_rollback(); $this->messages->add_message('lang:groups_message_you_are_in_group', Messages::MESSAGE_TYPE_ERROR); } } else { $this->db->trans_rollback(); $this->messages->add_message('lang:groups_message_cant_found_participant_record', Messages::MESSAGE_TYPE_ERROR); } } else { $this->db->trans_rollback(); $this->messages->add_message('lang:groups_message_cant_change_group_of_inactive_course', Messages::MESSAGE_TYPE_ERROR); } } else { $this->db->trans_rollback(); $this->messages->add_message('lang:groups_message_groups_switching_disabled', Messages::MESSAGE_TYPE_ERROR); } } else { $this->db->trans_rollback(); $this->messages->add_message('lang:groups_message_group_not_found', Messages::MESSAGE_TYPE_ERROR); } redirect(create_internal_url('groups')); }
public function import_single_line() { $this->output->set_content_type('application/json'); $firstname = $this->input->post('firstname'); $lastname = $this->input->post('lastname'); $fullname = $this->input->post('fullname'); $email = $this->input->post('email'); $options = $this->input->post('options'); $this->parser->assign('firstname', $firstname); $this->parser->assign('lastname', $lastname); $this->parser->assign('fullname', $fullname); $this->parser->assign('email', $email); if ((trim($firstname) != '' && trim($lastname) != '' || trim($fullname) != '') && trim($email) != '') { $student_fullname = trim($fullname) != '' ? trim($fullname) : trim($firstname) . ' ' . trim($lastname); $this->_transaction_isolation(); $this->db->trans_begin(); $student = new Student(); $student->where('email', trim($email)); $student->get(); if ($student->exists()) { if ($student->fullname != $student_fullname) { $student->fullname = $student_fullname; $student->save(); $this->db->trans_commit(); } else { $this->db->trans_rollback(); } $this->parser->assign('error_message', 'lang:admin_students_csv_import_error_message_student_exists'); } else { $this->load->library('form_validation'); if ($this->form_validation->valid_email(trim($email))) { $student->email = trim($email); $student->fullname = $student_fullname; $password = ''; if ($options['password_type'] == 'default') { $password = $this->config->item('student_import_default_password'); } elseif ($options['password_type'] == 'random') { $password = md5(base64_encode(rand(0, 99999999999) . time() . $student->fullname . $student->email) . $this->config->item('encryption_key')); $password = substr($password, 0, rand(6, 20)); } $student->password = $password != '' ? sha1($password) : ''; $student->language = $this->config->item('language'); if ($student->save()) { $this->parser->assign('password', $password); $this->db->trans_commit(); $this->parser->assign('success_message', 'lang:admin_students_csv_import_successfully_imported'); if ((bool) $options['send_mail']) { if ($password == '') { $this->_transaction_isolation(); $this->db->trans_begin(); $student->generate_random_password_token(); $this->db->trans_commit(); } $this->_init_language_for_student($student); $this->load->library('email'); $this->email->from_system(); $this->email->to($student->email); $this->email->subject($this->lang->line('admin_students_csv_import_email_subject')); $this->email->build_message_body('file:emails/backend/students/csv_import_email.tpl', array('student' => $student, 'password' => $password)); $sent = $this->email->send(); $this->_init_language_for_teacher(); if ($sent) { $this->parser->assign('email_success_message', 'lang:admin_students_csv_import_email_sent_successfully'); } else { $this->parser->assign('email_error_message', 'lang:admin_students_csv_import_email_sent_failed'); } } } else { $this->db->trans_rollback(); $this->parser->assign('error_message', 'lang:admin_students_csv_import_error_message_student_save_error'); } } else { $this->db->trans_rollback(); $this->parser->assign('error_message', 'lang:admin_students_csv_import_error_message_student_email_invalid'); } } if ($student->exists()) { $this->parser->assign('student_id', $student->id); if (intval($options['assign_to_course']) > 0) { $this->_transaction_isolation(); $this->db->trans_begin(); $course = new Course(); $course->get_by_id(intval($options['assign_to_course'])); if ($course->exists()) { $participant = new Participant(); $participant->where_related('student', 'id', $student->id); $participant->where_related('course', 'id', $course->id); $participant->get(); if (!$participant->exists()) { $participant->allowed = 0; if ($participant->save(array('student' => $student, 'course' => $course))) { $this->db->trans_commit(); $this->parser->assign('course_assignment_success_message', 'lang:admin_students_csv_import_successfully_added_course_participation'); $this->db->trans_begin(); $course = new Course(); $course->get_by_id(intval($options['assign_to_course'])); $participant->allowed = 1; $participant->save(); $participants = new Participant(); $participants->where_related($course); $participants->where('allowed', 1); $participants_count = $participants->count(); if ($participants_count <= $course->capacity) { $this->db->trans_commit(); $this->parser->assign('course_assignment_approwal_success_message', 'lang:admin_students_csv_import_successfully_added_course_participation_approwal'); } else { $this->db->trans_rollback(); $this->parser->assign('course_assignment_approwal_error_message', 'lang:admin_students_csv_import_error_message_added_course_participation_approwal'); } } else { $this->db->trans_rollback(); $this->parser->assign('course_assignment_error_message', 'lang:admin_students_csv_import_error_message_participation_save_failed'); } } else { $this->db->trans_rollback(); $this->parser->assign('course_assignment_error_message', 'lang:admin_students_csv_import_error_message_already_in_course'); } } else { $this->db->trans_rollback(); $this->parser->assign('course_assignment_error_message', 'lang:admin_students_csv_import_error_message_course_not_found'); } } } } else { $this->parser->assign('error_message', 'lang:admin_students_csv_import_error_message_nothing_to_import'); } $html = $this->parser->parse('backend/students/import_single_line.tpl', array(), TRUE); $this->output->set_output(json_encode($html)); }
public function delete_participation() { $this->output->set_content_type('application/json'); $output = array('status' => FALSE, 'message' => $this->lang->line('admin_participants_message_participant_not_found')); $url = $this->uri->ruri_to_assoc(3); $participant_id = isset($url['participant_id']) ? intval($url['participant_id']) : 0; if ($participant_id > 0) { $process_ok = TRUE; $this->_transaction_isolation(); $this->db->trans_begin(); $participant = new Participant(); $participant->get_by_id($participant_id); $student = $participant->student->get(); $course = $participant->course->get(); if (!$participant->exists()) { $output['message'] = $this->lang->line('admin_participants_message_participant_not_found'); $process_ok = FALSE; } if ($process_ok) { if ($participant->allowed != 0) { $participant->delete(); if ($student->is_related_to('active_course', $course->id)) { $student->delete($course, 'active_course'); } $output['message'] = $this->lang->line('admin_participants_message_participant_deleted'); } else { $output['message'] = $this->lang->line('admin_participants_message_participant_cant_be_deleted'); $process_ok = FALSE; } } $output['status'] = $process_ok; if ($output['status']) { $this->db->trans_commit(); $this->_action_success(); $this->output->set_internal_value('student_id', $student->id); } else { $this->db->trans_rollback(); } } $this->output->set_output(json_encode($output)); }
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)); }