Example #1
0
// Status
$status = array();
$status[GROUP_PERMISSION_OPEN] = get_lang('Open');
$status[GROUP_PERMISSION_CLOSED] = get_lang('Closed');
$form->addElement('select', 'visibility', get_lang('GroupPermissions'), $status);
// Set default values
$defaults['status'] = GROUP_PERMISSION_OPEN;
$form->setDefaults($defaults);
// Submit button
$form->addButtonCreate(get_lang('Add'));
// Validate form
if ($form->validate()) {
    $check = Security::check_token('post');
    if ($check) {
        $values = $form->exportValues();
        $picture_element = $form->getElement('picture');
        $picture = $picture_element->getValue();
        $picture_uri = '';
        $name = $values['name'];
        $description = $values['description'];
        $url = $values['url'];
        $status = intval($values['visibility']);
        $picture = $_FILES['picture'];
        $parent_group_id = intval($values['parent_group']);
        $group_id = GroupPortalManager::add($name, $description, $url, $status);
        GroupPortalManager::set_parent_group($group_id, $parent_group_id);
        if (!empty($picture['name'])) {
            $picture_uri = GroupPortalManager::update_group_picture($group_id, $_FILES['picture']['name'], $_FILES['picture']['tmp_name']);
            GroupPortalManager::update($group_id, $name, $description, $url, $status, $picture_uri);
        }
        //@todo send emails
Example #2
0
/**
 * This function allows the platform admin to choose the default stylesheet
 * @author Patrick Cool <*****@*****.**>, Ghent University
 * @author Julio Montoya <*****@*****.**>, Chamilo
 */
function handle_stylesheets()
{
    global $_configuration;
    // Current style.
    $currentstyle = api_get_setting('stylesheets');
    $is_style_changeable = false;
    if ($_configuration['access_url'] != 1) {
        $style_info = api_get_settings('stylesheets', '', 1, 0);
        $url_info = api_get_access_url($_configuration['access_url']);
        if ($style_info[0]['access_url_changeable'] == 1 && $url_info['active'] == 1) {
            $is_style_changeable = true;
        }
    } else {
        $is_style_changeable = true;
    }
    $form = new FormValidator('stylesheet_upload', 'post', 'settings.php?category=Stylesheets#tabs-2');
    $form->addElement('text', 'name_stylesheet', get_lang('NameStylesheet'), array('size' => '40', 'maxlength' => '40'));
    $form->addRule('name_stylesheet', get_lang('ThisFieldIsRequired'), 'required');
    $form->addElement('file', 'new_stylesheet', get_lang('UploadNewStylesheet'));
    $allowed_file_types = array('css', 'zip', 'jpeg', 'jpg', 'png', 'gif', 'ico', 'psd');
    $form->addRule('new_stylesheet', get_lang('InvalidExtension') . ' (' . implode(',', $allowed_file_types) . ')', 'filetype', $allowed_file_types);
    $form->addRule('new_stylesheet', get_lang('ThisFieldIsRequired'), 'required');
    $form->addButtonUpload(get_lang('Upload'), 'stylesheet_upload');
    $show_upload_form = false;
    if (!is_writable(CSS_UPLOAD_PATH)) {
        Display::display_error_message(CSS_UPLOAD_PATH . get_lang('IsNotWritable'));
    } else {
        // Uploading a new stylesheet.
        if ($_configuration['access_url'] == 1) {
            $show_upload_form = true;
        } else {
            if ($is_style_changeable) {
                $show_upload_form = true;
            }
        }
    }
    // Stylesheet upload.
    if (isset($_POST['stylesheet_upload'])) {
        if ($form->validate()) {
            $values = $form->exportValues();
            $picture_element = $form->getElement('new_stylesheet');
            $picture = $picture_element->getValue();
            $result = upload_stylesheet($values, $picture);
            // Add event to the system log.
            $user_id = api_get_user_id();
            $category = $_GET['category'];
            Event::addEvent(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
            if ($result) {
                Display::display_confirmation_message(get_lang('StylesheetAdded'));
            }
        }
    }
    $form_change = new FormValidator('stylesheet_upload', 'post', api_get_self() . '?category=Stylesheets', null, array('id' => 'stylesheets_id'));
    $list_of_names = array();
    $selected = '';
    $dirpath = '';
    $safe_style_dir = '';
    if ($handle = @opendir(CSS_UPLOAD_PATH)) {
        $counter = 1;
        while (false !== ($style_dir = readdir($handle))) {
            if (substr($style_dir, 0, 1) == '.') {
                // Skip directories starting with a '.'
                continue;
            }
            $dirpath = CSS_UPLOAD_PATH . $style_dir;
            if (is_dir($dirpath)) {
                if ($style_dir != '.' && $style_dir != '..') {
                    if (isset($_POST['style']) && (isset($_POST['preview']) || isset($_POST['download'])) && $_POST['style'] == $style_dir) {
                        $safe_style_dir = $style_dir;
                    } else {
                        if ($currentstyle == $style_dir || $style_dir == 'chamilo' && !$currentstyle) {
                            if (isset($_POST['style'])) {
                                $selected = Database::escape_string($_POST['style']);
                            } else {
                                $selected = $style_dir;
                            }
                        }
                    }
                    $show_name = ucwords(str_replace('_', ' ', $style_dir));
                    if ($is_style_changeable) {
                        $list_of_names[$style_dir] = $show_name;
                    }
                    $counter++;
                }
            }
        }
        closedir($handle);
    }
    // Sort styles in alphabetical order.
    asort($list_of_names);
    $select_list = array();
    foreach ($list_of_names as $style_dir => $item) {
        $select_list[$style_dir] = $item;
    }
    $styles =& $form_change->addElement('select', 'style', get_lang('NameStylesheet'), $select_list);
    $styles->setSelected($selected);
    if ($form_change->validate()) {
        // Submit stylesheets.
        if (isset($_POST['save'])) {
            store_stylesheets();
            Display::display_normal_message(get_lang('Saved'));
        }
        if (isset($_POST['download'])) {
            $arch = api_get_path(SYS_ARCHIVE_PATH) . $safe_style_dir . '.zip';
            $dir = api_get_path(SYS_CSS_PATH) . 'themes/' . $safe_style_dir;
            if (is_dir($dir)) {
                $zip = new PclZip($arch);
                // Remove path prefix except the style name and put file on disk
                $zip->create($dir, PCLZIP_OPT_REMOVE_PATH, substr($dir, 0, -strlen($safe_style_dir)));
                //@TODO: use more generic script to download.
                $str = '<a class="btn btn-primary btn-large" href="' . api_get_path(WEB_CODE_PATH) . 'course_info/download.php?archive=' . str_replace(api_get_path(SYS_ARCHIVE_PATH), '', $arch) . '">' . get_lang('ClickHereToDownloadTheFile') . '</a>';
                Display::display_normal_message($str, false);
            } else {
                Display::addFlash(Display::return_message(get_lang('FileNotFound'), 'warning'));
            }
        }
    }
    if ($is_style_changeable) {
        $group = [$form_change->addButtonSave(get_lang('SaveSettings'), 'save', true), $form_change->addButtonPreview(get_lang('Preview'), 'preview', true), $form_change->addButtonDownload(get_lang('Download'), 'download', true)];
        $form_change->addGroup($group);
        if ($show_upload_form) {
            echo '<script>
            $(function() {
                $( "#tabs" ).tabs();
            });
            </script>';
            echo Display::tabs(array(get_lang('Update'), get_lang('UploadNewStylesheet')), array($form_change->return_form(), $form->return_form()));
        } else {
            $form_change->display();
        }
    } else {
        $form_change->freeze();
    }
}
 /**
  * Creates the form to create / edit an exercise
  * @param FormValidator $form
  */
 public function createForm($form, $type = 'full')
 {
     if (empty($type)) {
         $type = 'full';
     }
     // form title
     if (!empty($_GET['exerciseId'])) {
         $form_title = get_lang('ModifyExercise');
     } else {
         $form_title = get_lang('NewEx');
     }
     $form->addElement('header', $form_title);
     // Title.
     $form->addElement('text', 'exerciseTitle', get_lang('ExerciseName'), array('id' => 'exercise_title'));
     $form->addElement('advanced_settings', 'advanced_params', get_lang('AdvancedParameters'));
     $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
     $editor_config = array('ToolbarSet' => 'TestQuestionDescription', 'Width' => '100%', 'Height' => '150');
     if (is_array($type)) {
         $editor_config = array_merge($editor_config, $type);
     }
     $form->addHtmlEditor('exerciseDescription', get_lang('ExerciseDescription'), false, false, $editor_config);
     if ($type == 'full') {
         //Can't modify a DirectFeedback question
         if ($this->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_DIRECT) {
             // feedback type
             $radios_feedback = array();
             $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('ExerciseAtTheEndOfTheTest'), '0', array('id' => 'exerciseType_0', 'onclick' => 'check_feedback()'));
             if (api_get_setting('exercise.enable_quiz_scenario') == 'true') {
                 //Can't convert a question from one feedback to another if there is more than 1 question already added
                 if ($this->selectNbrQuestions() == 0) {
                     $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('DirectFeedback'), '1', array('id' => 'exerciseType_1', 'onclick' => 'check_direct_feedback()'));
                 }
             }
             $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('NoFeedback'), '2', array('id' => 'exerciseType_2'));
             $form->addGroup($radios_feedback, null, array(get_lang('FeedbackType'), get_lang('FeedbackDisplayOptions')), '');
             // Type of results display on the final page
             $radios_results_disabled = array();
             $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id' => 'result_disabled_0'));
             $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1', array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()'));
             $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id' => 'result_disabled_2'));
             //$radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ExamModeWithFinalScoreShowOnlyFinalScoreWithCategoriesIfAvailable'),  '3', array('id'=>'result_disabled_3','onclick' => 'check_results_disabled()'));
             $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), '');
             // Type of questions disposition on page
             $radios = array();
             $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1', array('onclick' => 'check_per_page_all()', 'id' => 'option_page_all'));
             $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), '2', array('onclick' => 'check_per_page_one()', 'id' => 'option_page_one'));
             $form->addGroup($radios, null, get_lang('QuestionsPerPage'), '');
         } else {
             // if is Directfeedback but has not questions we can allow to modify the question type
             if ($this->selectNbrQuestions() == 0) {
                 // feedback type
                 $radios_feedback = array();
                 $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('ExerciseAtTheEndOfTheTest'), '0', array('id' => 'exerciseType_0', 'onclick' => 'check_feedback()'));
                 if (api_get_setting('exercise.enable_quiz_scenario') == 'true') {
                     $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('DirectFeedback'), '1', array('id' => 'exerciseType_1', 'onclick' => 'check_direct_feedback()'));
                 }
                 $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('NoFeedback'), '2', array('id' => 'exerciseType_2'));
                 $form->addGroup($radios_feedback, null, array(get_lang('FeedbackType'), get_lang('FeedbackDisplayOptions')));
                 //$form->addElement('select', 'exerciseFeedbackType',get_lang('FeedbackType'),$feedback_option,'onchange="javascript:feedbackselection()"');
                 $radios_results_disabled = array();
                 $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id' => 'result_disabled_0'));
                 $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1', array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()'));
                 $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id' => 'result_disabled_2', 'onclick' => 'check_results_disabled()'));
                 $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), '');
                 // Type of questions disposition on page
                 $radios = array();
                 $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1');
                 $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), '2');
                 $form->addGroup($radios, null, get_lang('ExerciseType'));
             } else {
                 //Show options freeze
                 $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id' => 'result_disabled_0'));
                 $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1', array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()'));
                 $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id' => 'result_disabled_2', 'onclick' => 'check_results_disabled()'));
                 $result_disable_group = $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), '');
                 $result_disable_group->freeze();
                 //we force the options to the DirectFeedback exercisetype
                 $form->addElement('hidden', 'exerciseFeedbackType', EXERCISE_FEEDBACK_TYPE_DIRECT);
                 $form->addElement('hidden', 'exerciseType', ONE_PER_PAGE);
                 // Type of questions disposition on page
                 $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1', array('onclick' => 'check_per_page_all()', 'id' => 'option_page_all'));
                 $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), '2', array('onclick' => 'check_per_page_one()', 'id' => 'option_page_one'));
                 $type_group = $form->addGroup($radios, null, get_lang('QuestionsPerPage'), '');
                 $type_group->freeze();
             }
         }
         // number of random question
         $max = $this->id > 0 ? $this->selectNbrQuestions() : 10;
         $option = range(0, $max);
         $option[0] = get_lang('No');
         $option[-1] = get_lang('AllQuestionsShort');
         $form->addElement('select', 'randomQuestions', array(get_lang('RandomQuestions'), get_lang('RandomQuestionsHelp')), $option, array('id' => 'randomQuestions'));
         // Random answers
         $radios_random_answers = array();
         $radios_random_answers[] = $form->createElement('radio', 'randomAnswers', null, get_lang('Yes'), '1');
         $radios_random_answers[] = $form->createElement('radio', 'randomAnswers', null, get_lang('No'), '0');
         $form->addGroup($radios_random_answers, null, get_lang('RandomAnswers'), '');
         // Random by category
         $form->addElement('html', '<div class="clear">&nbsp;</div>');
         $radiocat = array();
         $radiocat[] = $form->createElement('radio', 'randomByCat', null, get_lang('YesWithCategoriesShuffled'), '1');
         $radiocat[] = $form->createElement('radio', 'randomByCat', null, get_lang('YesWithCategoriesSorted'), '2');
         $radiocat[] = $form->createElement('radio', 'randomByCat', null, get_lang('No'), '0');
         $radioCatGroup = $form->addGroup($radiocat, null, get_lang('RandomQuestionByCategory'), '');
         $form->addElement('html', '<div class="clear">&nbsp;</div>');
         // add the radio display the category name for student
         $radio_display_cat_name = array();
         $radio_display_cat_name[] = $form->createElement('radio', 'display_category_name', null, get_lang('Yes'), '1');
         $radio_display_cat_name[] = $form->createElement('radio', 'display_category_name', null, get_lang('No'), '0');
         $form->addGroup($radio_display_cat_name, null, get_lang('QuestionDisplayCategoryName'), '');
         // Attempts
         $attempt_option = range(0, 10);
         $attempt_option[0] = get_lang('Infinite');
         $form->addElement('select', 'exerciseAttempts', get_lang('ExerciseAttempts'), $attempt_option, ['id' => 'exerciseAttempts']);
         // Exercise time limit
         $form->addElement('checkbox', 'activate_start_date_check', null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()'));
         $var = Exercise::selectTimeLimit();
         if ($this->start_time != '0000-00-00 00:00:00') {
             $form->addElement('html', '<div id="start_date_div" style="display:block;">');
         } else {
             $form->addElement('html', '<div id="start_date_div" style="display:none;">');
         }
         $form->addElement('date_time_picker', 'start_time');
         $form->addElement('html', '</div>');
         $form->addElement('checkbox', 'activate_end_date_check', null, get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()'));
         if ($this->end_time != '0000-00-00 00:00:00') {
             $form->addElement('html', '<div id="end_date_div" style="display:block;">');
         } else {
             $form->addElement('html', '<div id="end_date_div" style="display:none;">');
         }
         $form->addElement('date_time_picker', 'end_time');
         $form->addElement('html', '</div>');
         //$check_option=$this->selectType();
         $diplay = 'block';
         $form->addElement('checkbox', 'propagate_neg', null, get_lang('PropagateNegativeResults'));
         $form->addElement('html', '<div class="clear">&nbsp;</div>');
         $form->addElement('checkbox', 'review_answers', null, get_lang('ReviewAnswers'));
         $form->addElement('html', '<div id="divtimecontrol"  style="display:' . $diplay . ';">');
         //Timer control
         //$time_hours_option = range(0,12);
         //$time_minutes_option = range(0,59);
         $form->addElement('checkbox', 'enabletimercontrol', null, get_lang('EnableTimerControl'), array('onclick' => 'option_time_expired()', 'id' => 'enabletimercontrol', 'onload' => 'check_load_time()'));
         $expired_date = (int) $this->selectExpiredTime();
         if ($expired_date != '0') {
             $form->addElement('html', '<div id="timercontrol" style="display:block;">');
         } else {
             $form->addElement('html', '<div id="timercontrol" style="display:none;">');
         }
         $form->addText('enabletimercontroltotalminutes', get_lang('ExerciseTotalDurationInMinutes'), false, ['id' => 'enabletimercontroltotalminutes', 'cols-size' => [2, 2, 8]]);
         $form->addElement('html', '</div>');
         $form->addElement('text', 'pass_percentage', array(get_lang('PassPercentage'), null, '%'), array('id' => 'pass_percentage'));
         $form->addRule('pass_percentage', get_lang('Numeric'), 'numeric');
         // add the text_when_finished textbox
         $form->addHtmlEditor('text_when_finished', get_lang('TextWhenFinished'), false, false, $editor_config);
         $defaults = array();
         if (api_get_setting('search.search_enabled') === 'true') {
             require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
             $form->addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument'));
             $form->addElement('select_language', 'language', get_lang('SearchFeatureDocumentLanguage'));
             $specific_fields = get_specific_field_list();
             foreach ($specific_fields as $specific_field) {
                 $form->addElement('text', $specific_field['code'], $specific_field['name']);
                 $filter = array('c_id' => "'" . api_get_course_int_id() . "'", 'field_id' => $specific_field['id'], 'ref_id' => $this->id, 'tool_id' => '\'' . TOOL_QUIZ . '\'');
                 $values = get_specific_field_values_list($filter, array('value'));
                 if (!empty($values)) {
                     $arr_str_values = array();
                     foreach ($values as $value) {
                         $arr_str_values[] = $value['value'];
                     }
                     $defaults[$specific_field['code']] = implode(', ', $arr_str_values);
                 }
             }
             //$form->addElement ('html','</div>');
         }
         $form->addElement('html', '</div>');
         //End advanced setting
         $form->addElement('html', '</div>');
     }
     // submit
     if (isset($_GET['exerciseId'])) {
         $form->addButtonSave(get_lang('ModifyExercise'), 'submitExercise');
     } else {
         $form->addButtonUpdate(get_lang('ProcedToQuestions'), 'submitExercise');
     }
     $form->addRule('exerciseTitle', get_lang('GiveExerciseName'), 'required');
     if ($type == 'full') {
         // rules
         $form->addRule('exerciseAttempts', get_lang('Numeric'), 'numeric');
         $form->addRule('start_time', get_lang('InvalidDate'), 'datetime');
         $form->addRule('end_time', get_lang('InvalidDate'), 'datetime');
     }
     // defaults
     if ($type == 'full') {
         if ($this->id > 0) {
             if ($this->random > $this->selectNbrQuestions()) {
                 $defaults['randomQuestions'] = $this->selectNbrQuestions();
             } else {
                 $defaults['randomQuestions'] = $this->random;
             }
             $defaults['randomAnswers'] = $this->selectRandomAnswers();
             $defaults['exerciseType'] = $this->selectType();
             $defaults['exerciseTitle'] = $this->get_formated_title();
             $defaults['exerciseDescription'] = $this->selectDescription();
             $defaults['exerciseAttempts'] = $this->selectAttempts();
             $defaults['exerciseFeedbackType'] = $this->selectFeedbackType();
             $defaults['results_disabled'] = $this->selectResultsDisabled();
             $defaults['propagate_neg'] = $this->selectPropagateNeg();
             $defaults['review_answers'] = $this->review_answers;
             $defaults['randomByCat'] = $this->selectRandomByCat();
             $defaults['text_when_finished'] = $this->selectTextWhenFinished();
             $defaults['display_category_name'] = $this->selectDisplayCategoryName();
             $defaults['pass_percentage'] = $this->selectPassPercentage();
             if ($this->start_time != '0000-00-00 00:00:00') {
                 $defaults['activate_start_date_check'] = 1;
             }
             if ($this->end_time != '0000-00-00 00:00:00') {
                 $defaults['activate_end_date_check'] = 1;
             }
             $defaults['start_time'] = $this->start_time != '0000-00-00 00:00:00' ? api_get_local_time($this->start_time) : date('Y-m-d 12:00:00');
             $defaults['end_time'] = $this->end_time != '0000-00-00 00:00:00' ? api_get_local_time($this->end_time) : date('Y-m-d 12:00:00', time() + 84600);
             // Get expired time
             if ($this->expired_time != '0') {
                 $defaults['enabletimercontrol'] = 1;
                 $defaults['enabletimercontroltotalminutes'] = $this->expired_time;
             } else {
                 $defaults['enabletimercontroltotalminutes'] = 0;
             }
         } else {
             $defaults['exerciseType'] = 2;
             $defaults['exerciseAttempts'] = 0;
             $defaults['randomQuestions'] = 0;
             $defaults['randomAnswers'] = 0;
             $defaults['exerciseDescription'] = '';
             $defaults['exerciseFeedbackType'] = 0;
             $defaults['results_disabled'] = 0;
             $defaults['randomByCat'] = 0;
             $defaults['text_when_finished'] = "";
             $defaults['start_time'] = date('Y-m-d 12:00:00');
             $defaults['display_category_name'] = 1;
             $defaults['end_time'] = date('Y-m-d 12:00:00', time() + 84600);
             $defaults['pass_percentage'] = '';
         }
     } else {
         $defaults['exerciseTitle'] = $this->selectTitle();
         $defaults['exerciseDescription'] = $this->selectDescription();
     }
     if (api_get_setting('search.search_enabled') === 'true') {
         $defaults['index_document'] = 'checked="checked"';
     }
     $form->setDefaults($defaults);
     // Freeze some elements.
     if ($this->id != 0 && $this->edit_exercise_in_lp == false) {
         $elementsToFreeze = array('randomQuestions', 'exerciseAttempts', 'propagate_neg', 'enabletimercontrol', 'review_answers');
         foreach ($elementsToFreeze as $elementName) {
             /** @var HTML_QuickForm_element $element */
             $element = $form->getElement($elementName);
             $element->freeze();
         }
         $radioCatGroup->freeze();
     }
 }
/**
 * This function allows the platform admin to choose the default stylesheet
 * @author Patrick Cool <*****@*****.**>, Ghent University
*/
function handle_stylesheets()
{
    global $_configuration;
    // Current style
    $currentstyle = api_get_setting('stylesheets');
    $is_style_changeable = false;
    if ($_configuration['access_url'] != 1) {
        $style_info = api_get_settings('stylesheets', '', 1, 0);
        $url_info = api_get_access_url($_configuration['access_url']);
        if ($style_info[0]['access_url_changeable'] == 1 && $url_info['active'] == 1) {
            $is_style_changeable = true;
            echo '<div class="actions" id="stylesheetuploadlink">';
            Display::display_icon('theme_add.gif');
            echo '<a href="" onclick="document.getElementById(\'newstylesheetform\').style.display = \'block\'; document.getElementById(\'stylesheetuploadlink\').style.display = \'none\';return false; ">' . get_lang('UploadNewStylesheet') . '</a>';
            echo '</div>';
        }
    } else {
        $is_style_changeable = true;
        echo '<div class="actions" id="stylesheetuploadlink">';
        Display::display_icon('theme_add.gif');
        echo '<a href="" onclick="document.getElementById(\'newstylesheetform\').style.display = \'block\'; document.getElementById(\'stylesheetuploadlink\').style.display = \'none\';return false; ">' . get_lang('UploadNewStylesheet') . '</a>';
        echo '</div>';
    }
    $form = new FormValidator('stylesheet_upload', 'post', 'settings.php?category=stylesheets&showuploadform=true');
    $form->addElement('text', 'name_stylesheet', get_lang('NameStylesheet'), array('size' => '40', 'maxlength' => '40'));
    $form->addRule('name_stylesheet', get_lang('ThisFieldIsRequired'), 'required');
    $form->addElement('file', 'new_stylesheet', get_lang('UploadNewStylesheet'));
    $allowed_file_types = array('css');
    $form->addRule('new_stylesheet', get_lang('InvalidExtension') . ' (' . implode(',', $allowed_file_types) . ')', 'filetype', $allowed_file_types);
    $form->addRule('new_stylesheet', get_lang('ThisFieldIsRequired'), 'required');
    $form->addElement('style_submit_button', 'stylesheet_upload', get_lang('Ok'), array('class' => 'save'));
    if ($form->validate() and is_writable(api_get_path(SYS_CODE_PATH) . 'css/')) {
        $values = $form->exportValues();
        $picture_element =& $form->getElement('new_stylesheet');
        $picture = $picture_element->getValue();
        upload_stylesheet($values, $picture);
        Display::display_confirmation_message(get_lang('StylesheetAdded'));
    } else {
        if (!is_writable(api_get_path(SYS_CODE_PATH) . 'css/')) {
            Display::display_error_message(api_get_path(SYS_CODE_PATH) . 'css/' . get_lang('IsNotWritable'));
        } else {
            if ($_GET['showuploadform'] == 'true') {
                echo '<div id="newstylesheetform">';
            } else {
                echo '<div id="newstylesheetform" style="display: none;">';
            }
            // uploading a new stylesheet
            if ($_configuration['access_url'] == 1) {
                $form->display();
            } else {
                if ($is_style_changeable) {
                    $form->display();
                }
            }
            echo '</div>';
        }
    }
    // Preview of the stylesheet
    echo '<div><iframe src="style_preview.php" width="100%" height="300" name="preview"></iframe></div>';
    echo '<form name="stylesheets" method="post" action="' . api_get_self() . '?category=' . Security::remove_XSS($_GET['category']) . '">';
    if ($handle = @opendir(api_get_path(SYS_PATH) . 'main/css/')) {
        $counter = 1;
        while (false !== ($style_dir = readdir($handle))) {
            if (substr($style_dir, 0, 1) == '.') {
                continue;
            }
            $dirpath = api_get_path(SYS_PATH) . 'main/css/' . $style_dir;
            if (is_dir($dirpath)) {
                if ($style_dir != '.' && $style_dir != '..') {
                    if ($currentstyle == $style_dir or $style_dir == 'dokeos_classic' and !$currentstyle) {
                        $selected = 'checked="checked"';
                    } else {
                        $selected = '';
                    }
                    $show_name = get_lang(str_replace(' ', '', ucwords(str_replace('_', ' ', $style_dir))));
                    if ($is_style_changeable) {
                        echo "<input type=\"radio\" name=\"style\" value=\"" . $style_dir . "\" " . $selected . " onClick=\"parent.preview.location='style_preview.php?style=" . $style_dir . "';\"/>";
                        echo '<a href="style_preview.php?style=' . $style_dir . '" target="preview">' . $show_name . '</a>';
                    } else {
                        echo '<a href="style_preview.php?style=' . $style_dir . '" target="preview">' . $show_name . '</a>';
                    }
                    //echo '<div id="Layer'.$counter.'" style="position:relative; width:687px; z-index:2; visibility: hidden;">';
                    //echo '<a href="#" onClick="MM_showHideLayers(\'Layer'.$counter.'\',\'\',\'hide\')">'.get_lang('Close').'</a>';
                    //echo '<iframe src="style_preview.php?style='.$file.'" width="100%" style="float:right;"></iframe></div>';
                    echo "<br />\n";
                    $counter++;
                }
            }
        }
        @closedir($handle);
    }
    if ($is_style_changeable) {
        echo '<button class="save" type="submit" name="submit_stylesheets"> ' . get_lang('SaveSettings') . ' </button></form>';
    }
}