예제 #1
0
/**
 * Apply remove_base_url() to overlay array.
 * @param array<string> $overlay_array overlay array.
 * @param string|array<string> $column_name name of column with html or array of columns with html.
 * @return array<string> updated overlay array.
 */
function remove_base_url_from_overlay_array($overlay_array, $column_name)
{
    if (is_array($overlay_array) && count($overlay_array)) {
        foreach ($overlay_array as $idiom => $idiom_array) {
            if (is_array($idiom_array) && count($idiom_array)) {
                foreach ($idiom_array as $table => $table_array) {
                    if (is_array($table_array) && count($table_array)) {
                        foreach ($table_array as $table_id => $table_id_array) {
                            if (is_array($table_id_array) && count($table_id_array)) {
                                foreach ($table_id_array as $column => $content) {
                                    if (is_string($column_name) && $column == $column_name || is_array($column_name) && in_array($column, $column_name)) {
                                        if (!empty($content)) {
                                            $overlay_array[$idiom][$table][$table_id][$column] = remove_base_url($content);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $overlay_array;
}
예제 #2
0
 public function update()
 {
     $this->load->library('form_validation');
     $this->form_validation->set_rules('task[name]', 'lang:admin_tasks_form_field_name', 'required');
     $this->form_validation->set_rules('task[text]', 'lang:admin_tasks_form_field_text', 'required');
     $this->form_validation->set_rules('task[categories][]', 'lang:admin_tasks_form_field_categories', 'required');
     $this->form_validation->set_rules('task_id', 'id', 'required');
     if ($this->form_validation->run()) {
         $task_id = $this->input->post('task_id');
         $task = new Task();
         $task->get_by_id($task_id);
         if ($task->exists()) {
             $task_data = $this->input->post('task');
             $overlay = $this->input->post('overlay');
             $task->from_array($task_data, array('name', 'internal_comment'));
             $task->text = remove_base_url($task_data['text']);
             $author = new Teacher();
             if ((int) $task_data['author_id'] > 0) {
                 $author->get_by_id((int) $task_data['author_id']);
             }
             $this->_transaction_isolation();
             $this->db->trans_begin();
             $categories = new Category();
             $categories->where_in('id', $task_data['categories']);
             $categories->get();
             $task->category->get();
             $task->delete($task->category->all);
             if ($task->save(array('category' => $categories->all, 'author' => $author)) && $this->lang->save_overlay_array(remove_base_url_from_overlay_array($overlay, 'text')) && $this->db->trans_status()) {
                 $this->db->trans_commit();
                 $this->messages->add_message('lang:admin_tasks_flash_message_save_successful', Messages::MESSAGE_TYPE_SUCCESS);
                 $this->_action_success();
             } else {
                 $this->db->trans_rollback();
                 $this->messages->add_message('lang:admin_tasks_flash_message_save_failed', Messages::MESSAGE_TYPE_ERROR);
             }
         } else {
             $this->messages->add_message('lang:admin_tasks_error_message_task_not_found', Messages::MESSAGE_TYPE_ERROR);
         }
         redirect(create_internal_url('admin_tasks'));
     } else {
         $this->edit();
     }
 }
예제 #3
0
 public function update()
 {
     $this->load->library('form_validation');
     $task_set_data = $this->input->post('task_set');
     $this->_transaction_isolation();
     $this->db->trans_begin();
     $task_set_id = intval($this->input->post('task_set_id'));
     $task_set = new Task_set();
     $task_set->get_by_id($task_set_id);
     if ($task_set->exists()) {
         if (isset($task_set_data['content_type']) && $task_set_data['content_type'] == 'task_set') {
             $this->form_validation->set_rules('task_set[name]', 'lang:admin_task_sets_form_field_name', 'required');
             $this->form_validation->set_rules('task_set[course_id]', 'lang:admin_task_sets_form_field_course_id', 'required|exists_in_table[courses.id]');
             $this->form_validation->set_rules('task_set[task_set_type_id]', 'lang:admin_task_sets_form_field_task_set_type_id', 'required|exists_in_table[task_set_types.id]');
             $this->form_validation->set_rules('task_set[points_override]', 'lang:admin_task_sets_form_field_points_override', 'greater_than_equal[0]');
             if (isset($task_set_data['enable_tests_scoring'])) {
                 $this->form_validation->set_rules('task_set[test_min_needed]', 'lang:admin_task_sets_form_field_test_min_needed', 'greater_than_equal[0]');
                 $this->form_validation->set_rules('task_set[test_max_allowed]', 'lang:admin_task_sets_form_field_test_max_allowed', 'greater_than_field_or_equal[task_set[test_min_needed]]');
             }
             $this->form_validation->set_rules('task_set[deadline_notification_emails_handler]', 'lang:admin_task_sets_form_field_deadline_notification_emails_handler', 'required');
             if (isset($task_set_data['deadline_notification_emails_handler']) && $task_set_data['deadline_notification_emails_handler'] == 2) {
                 $this->form_validation->set_rules('task_set[deadline_notification_emails]', 'lang:admin_task_sets_form_field_deadline_notification_emails', 'required|valid_emails');
             } else {
                 $this->form_validation->set_rules('task_set[deadline_notification_emails]', 'lang:admin_task_sets_form_field_deadline_notification_emails', 'zero_or_more_valid_emails');
             }
             $this->form_validation->set_rules('task_set[publish_start_time]', 'lang:admin_task_sets_form_field_publish_start_time', 'datetime');
             $this->form_validation->set_rules('task_set[upload_end_time]', 'lang:admin_task_sets_form_field_upload_end_time', 'datetime');
         } else {
             $this->form_validation->set_rules('task_set[name]', 'lang:admin_task_sets_form_field_name', 'required');
             $this->form_validation->set_rules('task_set[course_id]', 'lang:admin_task_sets_form_field_course_id', 'required|exists_in_table[courses.id]');
             $this->form_validation->set_rules('task_set[points_override]', 'lang:admin_task_sets_form_field_points_override', 'required|numeric|greater_than_equal[0]');
             $this->form_validation->set_rules('task_set[deadline_notification_emails_handler]', 'lang:admin_task_sets_form_field_deadline_notification_emails_handler', 'required');
             if (isset($task_set_data['deadline_notification_emails_handler']) && $task_set_data['deadline_notification_emails_handler'] == 2) {
                 $this->form_validation->set_rules('task_set[deadline_notification_emails]', 'lang:admin_task_sets_form_field_deadline_notification_emails', 'required|valid_emails');
             } else {
                 $this->form_validation->set_rules('task_set[deadline_notification_emails]', 'lang:admin_task_sets_form_field_deadline_notification_emails', 'zero_or_more_valid_emails');
             }
             $this->form_validation->set_rules('task_set[publish_start_time]', 'lang:admin_task_sets_form_field_publish_start_time', 'datetime');
             $this->form_validation->set_rules('task_set[upload_end_time]', 'lang:admin_task_sets_form_field_upload_end_time', 'required|datetime');
             $this->form_validation->set_rules('task_set[project_selection_deadline]', 'lang:admin_task_sets_form_field_project_selection_deadline', 'required|datetime');
         }
         $tasks = $task_set->task->include_join_fields()->order_by('`task_task_set_rel`.`sorting`', 'asc')->get();
         $tasks_join_fields_data = $this->input->post('task_join_field');
         if ($tasks->exists()) {
             foreach ($tasks->all as $task) {
                 if (isset($tasks_join_fields_data[$task->id])) {
                     if (!isset($tasks_join_fields_data[$task->id]['delete'])) {
                         if ($task_set->content_type == 'task_set') {
                             $this->form_validation->set_rules('task_join_field[' . intval($task->id) . '][points_total]', 'lang:admin_task_sets_form_field_task_points_total', 'required|number|greater_than_equal[0]');
                             $this->form_validation->set_rules('task_join_field[' . intval($task->id) . '][test_max_points]', 'lang:admin_task_sets_form_field_task_test_max_points', 'required|number|greater_than_equal[0]');
                             $this->form_validation->set_rules('task_join_field[' . intval($task->id) . '][test_min_points]', 'lang:admin_task_sets_form_field_task_test_min_points', 'required|number|less_than_field_or_equal[task_join_field[' . intval($task->id) . '][test_max_points]]');
                         } else {
                             $this->form_validation->set_rules('task_join_field[' . intval($task->id) . '][max_projects_selections]', 'lang:admin_task_sets_form_field_task_max_projects_selections', 'required|integer|greater_than[0]');
                         }
                     }
                 }
             }
         }
     } else {
         $this->db->trans_rollback();
         $this->messages->add_message('lang:admin_task_sets_error_task_set_not_found', Messages::MESSAGE_TYPE_ERROR);
         redirect(create_internal_url('admin_task_sets'));
         die;
     }
     if ($this->form_validation->run()) {
         $task_set_upload_end_time = $task_set->upload_end_time;
         $task_set->from_array($task_set_data, array('name', 'course_id', 'task_set_type_id', 'published', 'allowed_file_types', 'internal_comment', 'test_priority'));
         $task_set->instructions = remove_base_url($task_set_data['instructions']);
         $task_set->group_id = intval($task_set_data['group_id']) > 0 ? intval($task_set_data['group_id']) : NULL;
         $task_set->room_id = intval($task_set_data['room_id']) > 0 ? intval($task_set_data['room_id']) : NULL;
         $task_set->publish_start_time = preg_match(self::REGEXP_PATTERN_DATETYME, $task_set_data['publish_start_time']) ? $task_set_data['publish_start_time'] : NULL;
         $task_set->upload_end_time = preg_match(self::REGEXP_PATTERN_DATETYME, $task_set_data['upload_end_time']) ? $task_set_data['upload_end_time'] : NULL;
         $task_set->project_selection_deadline = preg_match(self::REGEXP_PATTERN_DATETYME, $task_set_data['project_selection_deadline']) ? $task_set_data['project_selection_deadline'] : NULL;
         $task_set->comments_enabled = isset($task_set_data['comments_enabled']) ? (bool) intval($task_set_data['comments_enabled']) : FALSE;
         $task_set->comments_moderated = isset($task_set_data['comments_moderated']) ? (bool) intval($task_set_data['comments_moderated']) : FALSE;
         $task_set->points_override = isset($task_set_data['points_override_enabled']) && (bool) $task_set_data['points_override_enabled'] ? floatval($task_set_data['points_override']) : NULL;
         $task_set->allowed_test_types = isset($task_set_data['allowed_test_types']) && is_array($task_set_data['allowed_test_types']) ? implode(',', $task_set_data['allowed_test_types']) : '';
         $task_set->enable_tests_scoring = isset($task_set_data['enable_tests_scoring']) ? 1 : 0;
         $task_set->deadline_notification_emails = $task_set_data['deadline_notification_emails'];
         $task_set->deadline_notification_emails_handler = $task_set_data['deadline_notification_emails_handler'];
         if ($task_set->upload_end_time !== $task_set_upload_end_time) {
             $task_set->deadline_notified = 0;
         }
         if ($task_set->enable_tests_scoring == 1) {
             $task_set->test_min_needed = isset($task_set_data['test_min_needed']) ? intval($task_set_data['test_min_needed']) : 0;
             $task_set->test_max_allowed = isset($task_set_data['test_max_allowed']) ? intval($task_set_data['test_max_allowed']) : 0;
         }
         $overlay = $this->input->post('overlay');
         if ($tasks->exists()) {
             $tasks_sorting = array_flip(explode(',', $this->input->post('tasks_sorting')));
             foreach ($tasks->all as $task) {
                 if (isset($tasks_join_fields_data[$task->id])) {
                     if (!isset($tasks_join_fields_data[$task->id]['delete'])) {
                         $task->set_join_field($task_set, 'sorting', $tasks_sorting[$task->id] + 1);
                         $task->set_join_field($task_set, 'points_total', floatval(@$tasks_join_fields_data[$task->id]['points_total']));
                         $task->set_join_field($task_set, 'test_min_points', floatval(@$tasks_join_fields_data[$task->id]['test_min_points']));
                         $task->set_join_field($task_set, 'test_max_points', floatval(@$tasks_join_fields_data[$task->id]['test_max_points']));
                         $task->set_join_field($task_set, 'bonus_task', (int) (bool) @$tasks_join_fields_data[$task->id]['bonus_task']);
                         $task->set_join_field($task_set, 'internal_comment', @$tasks_join_fields_data[$task->id]['internal_comment']);
                         $task->set_join_field($task_set, 'max_projects_selections', @$tasks_join_fields_data[$task->id]['max_projects_selections']);
                     } else {
                         $task_set->delete($task);
                     }
                 }
             }
         }
         if ($task_set->save() && $this->lang->save_overlay_array(remove_base_url_from_overlay_array($overlay, 'instructions')) && $this->db->trans_status()) {
             $this->db->trans_commit();
             $this->messages->add_message('lang:admin_task_sets_flash_message_save_successful', Messages::MESSAGE_TYPE_SUCCESS);
             $this->_action_success();
         } else {
             $this->db->trans_rollback();
             $this->messages->add_message('lang:admin_task_sets_flash_message_save_fail', Messages::MESSAGE_TYPE_ERROR);
         }
         redirect(create_internal_url('admin_task_sets'));
     } else {
         $this->db->trans_rollback();
         $this->edit();
     }
 }
예제 #4
0
 public function update()
 {
     $this->load->library('form_validation');
     $this->form_validation->set_rules('course_id', 'id', 'required');
     $this->form_validation->set_rules('course[name]', 'lang:admin_courses_form_field_name', 'required');
     $this->form_validation->set_rules('course[period_id]', 'lang:admin_courses_form_field_period', 'required');
     $this->form_validation->set_rules('course[capacity]', 'lang:admin_courses_form_field_capacity', 'required|integer|greater_than[0]');
     $this->form_validation->set_rules('course[default_points_to_remove]', 'lang:admin_courses_form_field_default_points_to_remove', 'required|numeric|greater_than[0]');
     if ($this->form_validation->run()) {
         $course_id = intval($this->input->post('course_id'));
         $course = new Course();
         $course->get_by_id($course_id);
         if ($course->exists()) {
             $course_data = $this->input->post('course');
             $course->from_array($course_data, array('name', 'period_id', 'capacity', 'default_points_to_remove'));
             $course->description = remove_base_url($course_data['description']);
             $course->allow_subscription_to = preg_match(self::REGEXP_PATTERN_DATETYME, $course_data['allow_subscription_to']) ? $course_data['allow_subscription_to'] : NULL;
             $course->groups_change_deadline = preg_match(self::REGEXP_PATTERN_DATETYME, $course_data['groups_change_deadline']) ? $course_data['groups_change_deadline'] : NULL;
             $course->test_scoring_deadline = preg_match(self::REGEXP_PATTERN_DATETYME, $course_data['test_scoring_deadline']) ? $course_data['test_scoring_deadline'] : NULL;
             $course->hide_in_lists = isset($course_data['hide_in_lists']) ? 1 : 0;
             $course->auto_accept_students = isset($course_data['auto_accept_students']) ? 1 : 0;
             $overlay = $this->input->post('overlay');
             $this->_transaction_isolation();
             $this->db->trans_begin();
             if ($course->save() && $this->lang->save_overlay_array(remove_base_url_from_overlay_array($overlay, 'description')) && $this->db->trans_status()) {
                 $this->db->trans_commit();
                 $this->messages->add_message('lang:admin_courses_flash_message_save_successful', Messages::MESSAGE_TYPE_SUCCESS);
                 $this->_action_success();
                 $this->output->set_internal_value('course_id', $course->id);
             } else {
                 $this->db->trans_rollback();
                 $this->messages->add_message('lang:admin_courses_flash_message_save_failed', Messages::MESSAGE_TYPE_ERROR);
             }
         } else {
             $this->messages->add_message('lang:admin_courses_error_course_not_found', Messages::MESSAGE_TYPE_ERROR);
         }
         redirect(create_internal_url('admin_courses/index'));
     } else {
         $this->edit();
     }
 }
예제 #5
0
 public function save_test_configuration($test_id)
 {
     $this->_transaction_isolation();
     $this->db->trans_begin();
     $test = new Test();
     $test->get_by_id(intval($test_id));
     if ($test->exists()) {
         $this->load->library('form_validation');
         $this->form_validation->set_rules('test[name]', 'lang:admin_tests_test_form_field_name', 'required');
         $this->form_validation->set_rules('test[timeout]', 'lang:admin_tests_test_form_field_timeout', 'required|greater_than_equal[100]');
         $valid = TRUE;
         $test_object = $this->load->test($test->type);
         try {
             $test_object->initialize($test);
             $valid = $test_object->validate_test_configuration();
         } catch (TestException $e) {
             $this->db->trans_rollback();
             $this->messages->add_message($e->getMessage(), Messages::MESSAGE_TYPE_ERROR);
             redirect(create_internal_url('admin_tests/configure_test/' . $test_id));
             die;
         }
         if ($this->form_validation->run() && $valid) {
             $test_data = $this->input->post('test');
             $test->name = $test_data['name'];
             $test->timeout = (int) $test_data['timeout'];
             $test->enabled = isset($test_data['enabled']) ? 1 : 0;
             $test->enable_scoring = isset($test_data['enable_scoring']) ? 1 : 0;
             $test->instructions = isset($test_data['instructions']) ? remove_base_url($test_data['instructions']) : '';
             $can_save = TRUE;
             try {
                 $config_data = is_array($this->input->post('configuration')) ? $this->input->post('configuration') : array();
                 $upload_data = array();
                 $can_save = $test_object->handle_uploads($upload_data);
                 $config_data = array_merge($config_data, $upload_data);
                 $test->configuration = serialize($test_object->prepare_test_configuration($config_data));
             } catch (TestException $e) {
                 $this->db->trans_rollback();
                 $this->messages->add_message($e->getMessage(), Messages::MESSAGE_TYPE_ERROR);
                 redirect(create_internal_url('admin_tests/configure_test/' . $test_id));
                 die;
             }
             if ($can_save) {
                 $overlay = $this->input->post('overlay');
                 if ($test->save() && $this->lang->save_overlay_array(remove_base_url_from_overlay_array($overlay, 'instructions')) && $this->db->trans_status()) {
                     $this->db->trans_commit();
                     $this->messages->add_message('lang:admin_tests_flash_message_configuration_saved', Messages::MESSAGE_TYPE_SUCCESS);
                     $this->_action_success();
                 } else {
                     $this->db->trans_rollback();
                     $this->messages->add_message('lang:admin_tests_flash_message_configuration_save_failed', Messages::MESSAGE_TYPE_SUCCESS);
                 }
                 redirect(create_internal_url('admin_tests/configure_test/' . $test_id));
             } else {
                 $this->db->trans_rollback();
                 $this->configure_test($test_id);
             }
         } else {
             $this->db->trans_rollback();
             $this->configure_test($test_id);
         }
     } else {
         $this->db->trans_rollback();
         redirect(create_internal_url('admin_tests/configure_test/' . $test_id));
     }
 }