public function send_group_mail($group_id) { $group = new Group(); $group->get_by_id($group_id); if ($group->exists()) { $this->load->library('form_validation'); $this->form_validation->set_rules('group_mail[subject]', 'lang:admin_groups_group_email_form_field_subject', 'required'); $this->form_validation->set_rules('group_mail[body]', 'lang:admin_groups_group_email_form_field_body', 'required_no_html'); $this->form_validation->set_rules('group_mail[from]', 'lang:admin_groups_group_email_form_field_from', 'required'); $this->form_validation->set_rules('group_mail[student][]', 'lang:admin_groups_group_email_form_field_students', 'required'); if ($this->form_validation->run()) { $data = $this->input->post('group_mail'); $students = new Student(); $students->where_related('participant/group', 'id', $group->id); $students->where_related('participant/course', 'id', $group->course_id); $students->where_related('participant', 'allowed', 1); $students->where_in('id', $data['student']); $students->get(); if ($students->exists()) { $from = NULL; $from_name = ''; $teacher = new Teacher(); $teacher->get_by_id($this->usermanager->get_teacher_id()); if ($data['from'] == 'me') { $from = $teacher->email; $from_name = $teacher->fullname; } $sender_copy = isset($data['sender_copy']) && $data['sender_copy'] == 1 ? TRUE : FALSE; $sender_email = $teacher->email; if ($this->_send_multiple_emails($students, $data['subject'], '{$data.body|add_base_url}', array('data' => $data), $from, $from_name, $sender_copy, $sender_email)) { $this->messages->add_message('lang:admin_groups_group_email_success_sent', Messages::MESSAGE_TYPE_SUCCESS); } else { $this->messages->add_message('lang:admin_groups_group_email_error_send_failed', Messages::MESSAGE_TYPE_ERROR); } } else { $this->messages->add_message('lang:admin_groups_group_email_error_no_students_selected', Messages::MESSAGE_TYPE_ERROR); } redirect(create_internal_url('admin_groups/group_mail/' . $group_id)); } else { $this->group_mail($group_id); } } else { $this->messages->add_message('lang:admin_groups_group_email_error_group_not_found', Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('admin_groups/group_mail/' . $group_id)); } }
/** * Performs student account authentification and returns boolean information about success. * @param string $eamil student account e-mail address. * @param string $password student account password in plain text form. * @return boolean TRUE, if student authentification is successful, FALSE otherwise (i.e. bad e-mail of password). */ public function authenticate_student_login($email, $password) { $student = new Student(); $student->where('email', $email); $student->where('password', sha1($password)); $student->get(); if ($student->exists()) { $userdata = $student->to_array(); unset($userdata['password']); unset($userdata['created']); unset($userdata['updated']); $this->CI->session->set_userdata(SESSION_AUTH_LOGIN_STUDENT, $userdata); $this->validate_student_login_verification(TRUE); $log = new Log(); $log->add_student_login_log($this->CI->lang->line('students_login_successful_log_message'), NULL, $this->get_student_id()); return TRUE; } else { $this->validate_student_login_verification(FALSE); $this->add_login_failed_record($email, self::ACCOUNT_TYPE_STUDENT); return FALSE; } }
public function do_change_password($token, $encoded_email) { if ($this->usermanager->is_student_session_valid()) { $this->messages->add_message('lang:students_change_password_student_loged_in', Messages::MESSAGE_TYPE_ERROR); redirect('/'); } $this->load->library('form_validation'); $email = decode_from_url($encoded_email); if ($this->form_validation->valid_email($email) && preg_match('/^[0-9a-f]{40}$/', $token)) { $this->_transaction_isolation(); $this->db->trans_begin(); $student = new Student(); $student->where('password_token', $token); $student->where('email', $email); $student->get(); if ($student->exists()) { $this->_init_language_for_student($student); } else { $this->db->trans_rollback(); $this->messages->add_message('lang:students_change_password_invalid_token_email', Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('students/login')); } $this->form_validation->set_rules('student[password]', 'lang:students_change_password_form_field_password', 'required|min_length[6]|max_length[20]'); $this->form_validation->set_rules('student[verify]', 'lang:students_change_password_form_field_verify', 'required|matches[student[password]]'); if ($this->form_validation->run()) { $student_post = $this->input->post('student'); $student->password = sha1($student_post['password']); $student->password_token = NULL; if ($student->save()) { $this->db->trans_commit(); $this->messages->add_message('lang:students_change_password_success', Messages::MESSAGE_TYPE_SUCCESS); redirect(create_internal_url('students/login')); } else { $this->db->trans_rollback(); $this->messages->add_message('lang:students_change_password_failed', Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('students/login')); } } else { $this->db->trans_rollback(); $this->change_password($token, $encoded_email); } } else { $this->messages->add_message('lang:students_change_password_invalid_token_email', Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('students/login')); } }
private function remove_points_iteration($task_set, $points_to_remove, $task_set_id, $task_set_course_id, $task_set_group_id, &$error_code = 0, &$students = NULL) { $this->_transaction_isolation(); $this->db->trans_begin(); if (!is_null($task_set->upload_end_time)) { $timestamp_end = strtotime($task_set->upload_end_time); if (time() > $timestamp_end) { $participants = new Participant(); $participants->select('*'); $participants->select_subquery('(SELECT `solutions`.`id` FROM `solutions` WHERE `solutions`.`task_set_id` = ' . $task_set_id . ' AND `solutions`.`student_id` = `${parent}`.`student_id`)', 'solution_id'); $participants->where_related_course('id', $task_set_course_id); if ($task_set->group->exists() && !is_null($task_set_group_id)) { $participants->where_related_group('id', $task_set_group_id); } $participants->where('allowed', 1); $participants->get_iterated(); $notify_students = array(0); foreach ($participants as $participant) { if (is_null($participant->solution_id) && !is_null($participant->student_id)) { $solution = new Solution(); $solution->task_set_id = $task_set_id; $solution->student_id = $participant->student_id; $solution->teacher_id = $this->usermanager->get_teacher_id(); $solution->points = -$points_to_remove; $solution->revalidate = 0; if ($solution->save()) { $notify_students[] = $participant->student_id; } } } if ($this->db->trans_status()) { $this->db->trans_commit(); $students = new Student(); $students->where_in('id', $notify_students); $students->get(); //$result->mail_sent = $this->_send_multiple_emails($students, 'lang:admin_solutions_remove_points_notification_subject', 'file:emails/backend/solutions/remove_points_notify.tpl', array('task_set' => $task_set, 'points_to_remove' => $points_to_remove)); return TRUE; } else { $this->db->trans_rollback(); //$result->message = $this->lang->line('admin_solutions_remove_points_error_unknown'); $error_code = 1; return FALSE; } } else { $this->db->trans_rollback(); //$result->message = $this->lang->line('admin_solutions_remove_points_error_task_set_upload_limit_not_reached'); $error_code = 2; return FALSE; } } else { $this->db->trans_rollback(); //$result->message = $this->lang->line('admin_solutions_remove_points_error_task_set_upload_not_limited'); $error_code = 3; return FALSE; } }
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 edit() { $this->_select_teacher_menu_pagetag('task_sets'); $url = $this->uri->ruri_to_assoc(3); $task_set_id = isset($url['task_set_id']) ? intval($url['task_set_id']) : intval($this->input->post('task_set_id')); $task_set = new Task_set(); $task_set->get_by_id($task_set_id); $ps_data = array(); $nps_data = array(); if ($task_set->exists() && $task_set->content_type == 'project') { $project_selections = new Project_selection(); $project_selections->select('*'); $project_selections->include_related('student', array('fullname', 'email')); $project_selections->where_related($task_set); $project_selections->include_related('task', 'name'); $project_selections->include_related('task/task_set', 'id'); $project_selections->where_related('task/task_set', 'id', $task_set->id); $project_selections->order_by('task_task_task_set_rel.sorting', 'ASC'); $project_selections->order_by_related_as_fullname('student', 'fullname', 'asc'); $project_selections->get(); if ($project_selections->exists()) { foreach ($project_selections->all as $project_selection) { $ps_data[$project_selection->task_id][] = $project_selection; } } $project_selections->select_func('COUNT', '@id', 'count'); $project_selections->where('task_set_id', 'participant_course_task_sets.id', false); $project_selections->where_related('student', 'id', '${parent}.id'); $students = new Student(); $students->where_related('participant/course/task_set', $task_set); $students->where_related('participant', 'allowed', 1); $students->where_subquery(0, $project_selections); $students->order_by_as_fullname('fullname', 'asc'); $students->get(); if ($students->exists()) { $nps_data = $students->all; } } $this->_add_tinymce4(); $this->parser->add_js_file('jquery.activeform.js'); $this->parser->add_js_file('admin_task_sets/edit.js'); $this->parser->add_js_file('admin_task_sets/form.js'); $this->parser->add_css_file('admin_task_sets.css'); $this->inject_courses(); $this->inject_languages(); $this->inject_test_types(); $this->inject_course_groups(); $this->inject_course_group_rooms(); $this->inject_course_task_set_types(); $this->parser->parse('backend/task_sets/edit.tpl', array('task_set' => $task_set, 'project_selections' => $ps_data, 'not_project_selections' => $nps_data)); }