/**
  * Return the HTML form to display an item (generally a section/module item)
  * @param	string	Item type (module/dokeos_module)
  * @param	string	Title (optional, only when creating)
  * @param	string	Action ('add'/'edit')
  * @param	integer	lp_item ID
  * @param	mixed	Extra info
  * @return	string 	HTML form
  */
 public function display_item_form($item_type, $title = '', $action = 'add_item', $id = 0, $extra_info = 'new')
 {
     $course_id = api_get_course_int_id();
     $_course = api_get_course_info();
     global $charset;
     $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
     if ($id != 0 && is_array($extra_info)) {
         $item_title = $extra_info['title'];
         $item_description = $extra_info['description'];
         $item_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
         $item_path_fck = '/scorm/' . $this->path . '/' . stripslashes($extra_info['path']);
     } else {
         $item_title = '';
         $item_description = '';
         $item_path_fck = '';
     }
     if ($id != 0 && is_array($extra_info)) {
         $parent = $extra_info['parent_item_id'];
     } else {
         $parent = 0;
     }
     $id = intval($id);
     $sql = "SELECT * FROM " . $tbl_lp_item . "\n                WHERE\n                    c_id = " . $course_id . " AND\n                    lp_id = " . $this->lp_id . " AND\n                    id != {$id}";
     if ($item_type == 'module') {
         $sql .= " AND parent_item_id = 0";
     }
     $result = Database::query($sql);
     $arrLP = array();
     while ($row = Database::fetch_array($result)) {
         $arrLP[] = array('id' => $row['id'], 'item_type' => $row['item_type'], 'title' => $row['title'], 'path' => $row['path'], 'description' => $row['description'], 'parent_item_id' => $row['parent_item_id'], 'previous_item_id' => $row['previous_item_id'], 'next_item_id' => $row['next_item_id'], 'max_score' => $row['max_score'], 'min_score' => $row['min_score'], 'mastery_score' => $row['mastery_score'], 'prerequisite' => $row['prerequisite'], 'display_order' => $row['display_order']);
     }
     $this->tree_array($arrLP);
     $arrLP = isset($this->arrMenu) ? $this->arrMenu : null;
     unset($this->arrMenu);
     $url = api_get_self() . '?' . api_get_cidreq() . '&action=' . $action . '&type=' . $item_type . '&lp_id=' . $this->lp_id;
     $form = new FormValidator('form', 'POST', $url);
     $defaults['title'] = !empty($item_title) ? api_html_entity_decode($item_title, ENT_QUOTES, $charset) : '';
     $defaults['description'] = $item_description;
     $form->addElement('header', $title);
     //$arrHide = array($id);
     $arrHide[0]['value'] = Security::remove_XSS($this->name);
     $arrHide[0]['padding'] = 20;
     $charset = api_get_system_encoding();
     if ($item_type != 'module' && $item_type != 'dokeos_module') {
         for ($i = 0; $i < count($arrLP); $i++) {
             if ($action != 'add') {
                 if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
                     $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                     $arrHide[$arrLP[$i]['id']]['padding'] = 20 + $arrLP[$i]['depth'] * 20;
                     if ($parent == $arrLP[$i]['id']) {
                         $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                     }
                 }
             } else {
                 if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
                     $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                     $arrHide[$arrLP[$i]['id']]['padding'] = 20 + $arrLP[$i]['depth'] * 20;
                     if ($parent == $arrLP[$i]['id']) {
                         $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                     }
                 }
             }
         }
         if ($action != 'move') {
             $form->addElement('text', 'title', get_lang('Title'));
             $form->applyFilter('title', 'html_filter');
             $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
         } else {
             $form->addElement('hidden', 'title');
         }
         $parent_select = $form->addElement('select', 'parent', get_lang('Parent'), '', array('id' => 'idParent', 'onchange' => "javascript: load_cbo(this.value);"));
         foreach ($arrHide as $key => $value) {
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         }
         if (!empty($s_selected_parent)) {
             $parent_select->setSelected($s_selected_parent);
         }
     }
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     $arrHide = array();
     // POSITION
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
             //this is the same!
             if (isset($extra_info['previous_item_id']) && $extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                 $s_selected_position = $arrLP[$i]['id'];
             } elseif ($action == 'add') {
                 $s_selected_position = $arrLP[$i]['id'];
             }
             $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
         }
     }
     $position = $form->addElement('select', 'previous', get_lang('Position'), '', array('id' => 'previous'));
     $padding = isset($value['padding']) ? $value['padding'] : 0;
     $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:' . $padding . 'px;"');
     foreach ($arrHide as $key => $value) {
         $position->addOption($value['value'] . '"', $key, 'style="padding-left:' . $padding . 'px;"');
     }
     if (!empty($s_selected_position)) {
         $position->setSelected($s_selected_position);
     }
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     $form->addButtonSave(get_lang('SaveSection'), 'submit_button');
     if ($item_type == 'module' || $item_type == 'dokeos_module') {
         $form->addElement('hidden', 'parent', '0');
     }
     //fix in order to use the tab
     if ($item_type == 'chapter') {
         $form->addElement('hidden', 'type', 'chapter');
     }
     $extension = null;
     if (!empty($item_path)) {
         $extension = pathinfo($item_path, PATHINFO_EXTENSION);
     }
     //assets can't be modified
     //$item_type == 'asset' ||
     if ($item_type == 'sco' && ($extension == 'html' || $extension == 'htm')) {
         if ($item_type == 'sco') {
             $form->addElement('html', '<script type="text/javascript">alert("' . get_lang('WarningWhenEditingScorm') . '")</script>');
         }
         $renderer = $form->defaultRenderer();
         $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
         $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '500', 'FullPage' => true);
         $form->addHtmlEditor('content_lp', '', false, false, $editor_config);
         $content_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . $item_path_fck;
         $defaults['content_lp'] = file_get_contents($content_path);
     }
     $form->addElement('hidden', 'type', 'dokeos_' . $item_type);
     $form->addElement('hidden', 'post_time', time());
     $form->setDefaults($defaults);
     return $form->return_form();
 }
Example #2
0
 /**
  * @param FormValidator $form
  * @param string        $type
  * @param array         $data
  */
 public function setForm($form, $type = 'add', $data = array())
 {
     switch ($type) {
         case 'add':
             $header = get_lang('Add');
             break;
         case 'edit':
             $header = get_lang('Edit');
             break;
     }
     $form->addElement('header', $header);
     //Name
     $form->addElement('text', 'name', get_lang('Name'), array('maxlength' => 255));
     $form->applyFilter('name', 'html_filter');
     $form->applyFilter('name', 'trim');
     $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
     $form->addRule('name', '', 'maxlength', 255);
     // Description
     $form->addElement('textarea', 'description', get_lang('Description'), array('cols' => 58));
     $form->applyFilter('description', 'html_filter');
     $form->applyFilter('description', 'trim');
     if ($this->showGroupTypeSetting) {
         $form->addElement('checkbox', 'group_type', null, get_lang('SocialGroup'));
     }
     // url
     $form->addElement('text', 'url', get_lang('Url'));
     $form->applyFilter('url', 'html_filter');
     $form->applyFilter('url', 'trim');
     // Picture
     $allowed_picture_types = $this->getAllowedPictureExtensions();
     $form->addElement('file', 'picture', get_lang('AddPicture'));
     $form->addRule('picture', get_lang('OnlyImagesAllowed') . ' (' . implode(',', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types);
     if (isset($data['picture']) && strlen($data['picture']) > 0) {
         $picture = $this->get_picture_group($data['id'], $data['picture'], 80);
         $img = '<img src="' . $picture['file'] . '" />';
         $form->addElement('label', null, $img);
         $form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
     }
     $form->addElement('select', 'visibility', get_lang('GroupPermissions'), $this->getGroupStatusList());
     $form->setRequiredNote('<span class="form_required">*</span> <small>' . get_lang('ThisFieldIsRequired') . '</small>');
     // Setting the form elements
     if ($type == 'add') {
         $form->addButtonCreate($header);
     } else {
         $form->addButtonUpdate($header);
     }
 }
Example #3
0
      textarea = document.forms[0].description.value;
   }
}
</script>';
// Database table definitions
if (!empty($_GET['message'])) {
    $message = urldecode($_GET['message']);
}
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$tool_name = get_lang('AddGroups');
// Create the form
$form = new FormValidator('group_add');
$form->addElement('header', $tool_name);
// name
$form->addElement('text', 'name', get_lang('Name'), array('size' => 60, 'maxlength' => 120));
$form->applyFilter('name', 'html_filter');
$form->applyFilter('name', 'trim');
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
// Description
$form->addElement('textarea', 'description', get_lang('Description'), array('rows' => 3, 'cols' => 58, 'onKeyDown' => "text_longitud()", 'onKeyUp' => "text_longitud()"));
$form->applyFilter('description', 'html_filter');
$form->applyFilter('description', 'trim');
// url
$form->addElement('text', 'url', get_lang('URL'), array('size' => 35));
$form->applyFilter('url', 'html_filter');
$form->applyFilter('url', 'trim');
// Picture
$form->addElement('file', 'picture', get_lang('AddPicture'));
$allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif');
$form->addRule('picture', get_lang('OnlyImagesAllowed') . ' (' . implode(', ', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types);
//Group Parentship
$table_uf = Database::get_main_table(TABLE_MAIN_USER_FIELD);
$table_uf_opt = Database::get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
$table_uf_val = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'user_fields.php', 'name' => get_lang('UserFields'));
if ($_GET['action'] != 'edit') {
    $tool_name = get_lang('AddUserFields');
} else {
    $tool_name = get_lang('EditUserFields');
}
// Create the form
$form = new FormValidator('user_fields_add');
$form->addElement('header', '', $tool_name);
// Field display name
$form->addElement('text', 'fieldtitle', get_lang('FieldTitle'));
$form->applyFilter('fieldtitle', 'html_filter');
$form->applyFilter('fieldtitle', 'trim');
$form->addRule('fieldtitle', get_lang('ThisFieldIsRequired'), 'required');
// Field type
$types = UserManager::get_user_field_types();
$form->addElement('select', 'fieldtype', get_lang('FieldType'), $types, array('onchange' => 'change_image_user_field(this.value)'));
$form->addRule('fieldtype', get_lang('ThisFieldIsRequired'), 'required');
//Advanced parameters
$form->addElement('advanced_settings', '<a href="javascript://" onclick=" return advanced_parameters()"><span id="img_plus_and_minus"><div style="vertical-align:top;" >' . $showImg . '&nbsp;' . get_lang('AdvancedParameters') . '</div></span></a>');
//When edit, the combobox displey the field type displeyed else none
if (isset($_GET['action']) && $_GET['action'] == 'edit' && in_array($_GET['field_type'], array(3, 4, 5, 8))) {
    $form->addElement('html', '<div id="options" style="display:block">');
} else {
    $form->addElement('html', '<div id="options" style="display:none">');
}
//field label
$table_uf_opt = Database::get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
$table_uf_val = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'settings.php?category=Search', 'name' => get_lang('PlatformConfigSettings'));
$interbreadcrumb[] = array('url' => 'specific_fields.php', 'name' => get_lang('SpecificSearchFields'));
if ($_GET['action'] != 'edit') {
    $tool_name = get_lang('AddSpecificSearchField');
} else {
    $tool_name = get_lang('EditSpecificSearchField');
}
// Create the form
$form = new FormValidator('specific_fields_add');
// Field variable name
$form->addElement('hidden', 'field_id', (int) $_REQUEST['field_id']);
$form->addElement('text', 'field_name', get_lang('FieldName'));
$form->applyFilter('field_name', 'html_filter');
$form->applyFilter('field_name', 'trim');
$form->addRule('field_name', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('field_name', get_lang('OnlyLettersAndNumbersAllowed'), 'username');
$form->addRule('field_name', '', 'maxlength', 20);
// Set default values (only not empty when editing)
$defaults = array();
if (is_numeric($_REQUEST['field_id'])) {
    $form_information = get_specific_field_list(array('id' => (int) $_GET['field_id']));
    $defaults['field_name'] = $form_information[0]['name'];
}
$form->setDefaults($defaults);
// Submit button
$form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="add"');
// Validate form
if ($form->validate()) {
Example #6
0
    /**
     * @param FormValidator $form
     * @param array $extraData
     * @param string $form_name
     * @param bool $admin_permissions
     * @param int $user_id
     * @param array $extra
     * @param int $itemId
     *
     * @return array
     */
    public function set_extra_fields_in_form($form, $extraData, $form_name, $admin_permissions = false, $user_id = null, $extra = array(), $itemId = null)
    {
        $user_id = intval($user_id);
        $type = $this->type;
        // User extra fields
        if ($type == 'user') {
            $extra = UserManager::get_extra_fields(0, 50, 5, 'ASC', true, null, true);
        }
        $jquery_ready_content = null;
        if (!empty($extra)) {
            foreach ($extra as $field_details) {
                // Getting default value id if is set
                $defaultValueId = null;
                if (isset($field_details['options']) && !empty($field_details['options'])) {
                    $valueToFind = null;
                    if (isset($field_details['field_default_value'])) {
                        $valueToFind = $field_details['field_default_value'];
                    }
                    // If a value is found we override the default value
                    if (isset($extraData['extra_' . $field_details['field_variable']])) {
                        $valueToFind = $extraData['extra_' . $field_details['field_variable']];
                    }
                    foreach ($field_details['options'] as $option) {
                        if ($option['option_value'] == $valueToFind) {
                            $defaultValueId = $option['id'];
                        }
                    }
                }
                if (!$admin_permissions) {
                    if ($field_details['field_visible'] == 0) {
                        continue;
                    }
                }
                switch ($field_details['field_type']) {
                    case ExtraField::FIELD_TYPE_TEXT:
                        $form->addElement('text', 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], array('class' => 'span4'));
                        $form->applyFilter('extra_' . $field_details['field_variable'], 'stripslashes');
                        $form->applyFilter('extra_' . $field_details['field_variable'], 'trim');
                        if (!$admin_permissions) {
                            if ($field_details['field_visible'] == 0) {
                                $form->freeze('extra_' . $field_details['field_variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_TEXTAREA:
                        $form->add_html_editor('extra_' . $field_details['field_variable'], $field_details['field_display_text'], false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130'));
                        $form->applyFilter('extra_' . $field_details['field_variable'], 'stripslashes');
                        $form->applyFilter('extra_' . $field_details['field_variable'], 'trim');
                        if (!$admin_permissions) {
                            if ($field_details['field_visible'] == 0) {
                                $form->freeze('extra_' . $field_details['field_variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_RADIO:
                        $group = array();
                        if (isset($field_details['options']) && !empty($field_details['options'])) {
                            foreach ($field_details['options'] as $option_details) {
                                $options[$option_details['option_value']] = $option_details['option_display_text'];
                                $group[] = $form->createElement('radio', 'extra_' . $field_details['field_variable'], $option_details['option_value'], $option_details['option_display_text'] . '<br />', $option_details['option_value']);
                            }
                        }
                        $form->addGroup($group, 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], '');
                        if (!$admin_permissions) {
                            if ($field_details['field_visible'] == 0) {
                                $form->freeze('extra_' . $field_details['field_variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_CHECKBOX:
                        $group = array();
                        if (isset($field_details['options']) && !empty($field_details['options'])) {
                            foreach ($field_details['options'] as $option_details) {
                                $options[$option_details['option_value']] = $option_details['option_display_text'];
                                $group[] = $form->createElement('checkbox', 'extra_' . $field_details['field_variable'], $option_details['option_value'], $option_details['option_display_text'] . '<br />', $option_details['option_value']);
                            }
                        } else {
                            // We assume that is a switch on/off with 1 and 0 as values
                            $group[] = $form->createElement('checkbox', 'extra_' . $field_details['field_variable'], null, 'Yes <br />', null);
                        }
                        $form->addGroup($group, 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], '');
                        if (!$admin_permissions) {
                            if ($field_details['field_visible'] == 0) {
                                $form->freeze('extra_' . $field_details['field_variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_SELECT:
                        $get_lang_variables = false;
                        if (in_array($field_details['field_variable'], array('mail_notify_message', 'mail_notify_invitation', 'mail_notify_group_message'))) {
                            $get_lang_variables = true;
                        }
                        // Get extra field workflow
                        $userInfo = api_get_user_info();
                        $addOptions = array();
                        $optionsExists = Database::getManager()->getRepository('ChamiloCoreBundle:ExtraFieldOptionRelFieldOption')->findOneBy(array('fieldId' => $field_details['id']));
                        if ($optionsExists) {
                            if (isset($userInfo['status']) && !empty($userInfo['status'])) {
                                $fieldWorkFlow = Database::getManager()->getRepository('ChamiloCoreBundle:ExtraFieldOptionRelFieldOption')->findBy(array('fieldId' => $field_details['id'], 'relatedFieldOptionId' => $defaultValueId, 'roleId' => $userInfo['status']));
                                foreach ($fieldWorkFlow as $item) {
                                    $addOptions[] = $item->getFieldOptionId();
                                }
                            }
                        }
                        $options = array();
                        if (empty($defaultValueId)) {
                            $options[''] = get_lang('SelectAnOption');
                        }
                        $optionList = array();
                        if (!empty($field_details['options'])) {
                            foreach ($field_details['options'] as $option_details) {
                                $optionList[$option_details['id']] = $option_details;
                                if ($get_lang_variables) {
                                    $options[$option_details['option_value']] = get_lang($option_details['option_display_text']);
                                } else {
                                    if ($optionsExists) {
                                        // Adding always the default value
                                        if ($option_details['id'] == $defaultValueId) {
                                            $options[$option_details['option_value']] = $option_details['option_display_text'];
                                        } else {
                                            if (isset($addOptions) && !empty($addOptions)) {
                                                // Parsing filters
                                                if (in_array($option_details['id'], $addOptions)) {
                                                    $options[$option_details['option_value']] = $option_details['option_display_text'];
                                                }
                                            }
                                        }
                                    } else {
                                        // Normal behaviour
                                        $options[$option_details['option_value']] = $option_details['option_display_text'];
                                    }
                                }
                            }
                            if (isset($optionList[$defaultValueId])) {
                                if (isset($optionList[$defaultValueId]['option_value']) && $optionList[$defaultValueId]['option_value'] == 'aprobada') {
                                    if (api_is_question_manager() == false) {
                                        $form->freeze();
                                    }
                                }
                            }
                            // Setting priority message
                            if (isset($optionList[$defaultValueId]) && isset($optionList[$defaultValueId]['priority'])) {
                                if (!empty($optionList[$defaultValueId]['priority'])) {
                                    $priorityId = $optionList[$defaultValueId]['priority'];
                                    $option = new ExtraFieldOption($this->type);
                                    $messageType = $option->getPriorityMessageType($priorityId);
                                    $form->addElement('label', null, Display::return_message($optionList[$defaultValueId]['priority_message'], $messageType));
                                }
                            }
                        }
                        if ($get_lang_variables) {
                            $field_details['field_display_text'] = get_lang($field_details['field_display_text']);
                        }
                        // chzn-select doesn't work for sessions??
                        $form->addElement('select', 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], $options, array('id' => 'extra_' . $field_details['field_variable']));
                        if ($optionsExists && $field_details['field_loggeable'] && !empty($defaultValueId)) {
                            $form->addElement('textarea', 'extra_' . $field_details['field_variable'] . '_comment', $field_details['field_display_text'] . ' ' . get_lang('Comment'));
                            $em = Database::getManager();
                            $extraFieldValue = new ExtraFieldValue($this->type);
                            $repo = $em->getRepository($extraFieldValue->entityName);
                            $repoLog = $em->getRepository('Gedmo\\Loggable\\Entity\\LogEntry');
                            $newEntity = $repo->findOneBy(array($this->handlerEntityId => $itemId, 'fieldId' => $field_details['id']));
                            // @todo move this in a function inside the class
                            if ($newEntity) {
                                $logs = $repoLog->getLogEntries($newEntity);
                                if (!empty($logs)) {
                                    $html = '<b>' . get_lang('LatestChanges') . '</b><br /><br />';
                                    $table = new HTML_Table(array('class' => 'data_table'));
                                    $table->setHeaderContents(0, 0, get_lang('Value'));
                                    $table->setHeaderContents(0, 1, get_lang('Comment'));
                                    $table->setHeaderContents(0, 2, get_lang('ModifyDate'));
                                    $table->setHeaderContents(0, 3, get_lang('Username'));
                                    $row = 1;
                                    foreach ($logs as $log) {
                                        $column = 0;
                                        $data = $log->getData();
                                        $fieldValue = isset($data['fieldValue']) ? $data['fieldValue'] : null;
                                        $comment = isset($data['comment']) ? $data['comment'] : null;
                                        $table->setCellContents($row, $column, $fieldValue);
                                        $column++;
                                        $table->setCellContents($row, $column, $comment);
                                        $column++;
                                        $table->setCellContents($row, $column, api_get_local_time($log->getLoggedAt()->format('Y-m-d H:i:s')));
                                        $column++;
                                        $table->setCellContents($row, $column, $log->getUsername());
                                        $row++;
                                    }
                                    $form->addElement('label', null, $html . $table->toHtml());
                                }
                            }
                        }
                        if (!$admin_permissions) {
                            if ($field_details['field_visible'] == 0) {
                                $form->freeze('extra_' . $field_details['field_variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_SELECT_MULTIPLE:
                        $options = array();
                        foreach ($field_details['options'] as $option_id => $option_details) {
                            $options[$option_details['option_value']] = $option_details['option_display_text'];
                        }
                        $form->addElement('select', 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], $options, array('multiple' => 'multiple'));
                        if (!$admin_permissions) {
                            if ($field_details['field_visible'] == 0) {
                                $form->freeze('extra_' . $field_details['field_variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_DATE:
                        $form->addElement('datepickerdate', 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], array('form_name' => $form_name));
                        $form->_elements[$form->_elementIndex['extra_' . $field_details['field_variable']]]->setLocalOption('minYear', 1900);
                        $defaults['extra_' . $field_details['field_variable']] = date('Y-m-d 12:00:00');
                        if (!isset($form->_defaultValues['extra_' . $field_details['field_variable']])) {
                            $form->setDefaults($defaults);
                        }
                        if (!$admin_permissions) {
                            if ($field_details['field_visible'] == 0) {
                                $form->freeze('extra_' . $field_details['field_variable']);
                            }
                        }
                        $form->applyFilter('theme', 'trim');
                        break;
                    case ExtraField::FIELD_TYPE_DATETIME:
                        $form->addElement('datepicker', 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], array('form_name' => $form_name));
                        $form->_elements[$form->_elementIndex['extra_' . $field_details['field_variable']]]->setLocalOption('minYear', 1900);
                        $defaults['extra_' . $field_details['field_variable']] = date('Y-m-d 12:00:00');
                        if (!isset($form->_defaultValues['extra_' . $field_details['field_variable']])) {
                            $form->setDefaults($defaults);
                        }
                        if (!$admin_permissions) {
                            if ($field_details['field_visible'] == 0) {
                                $form->freeze('extra_' . $field_details['field_variable']);
                            }
                        }
                        $form->applyFilter('theme', 'trim');
                        break;
                    case ExtraField::FIELD_TYPE_DOUBLE_SELECT:
                        $first_select_id = 'first_extra_' . $field_details['field_variable'];
                        $url = api_get_path(WEB_AJAX_PATH) . 'extra_field.ajax.php?1=1';
                        $jquery_ready_content .= '
                        $("#' . $first_select_id . '").on("change", function() {
                            var id = $(this).val();
                            if (id) {
                                $.ajax({
                                    url: "' . $url . '&a=get_second_select_options",
                                    dataType: "json",
                                    data: "type=' . $type . '&field_id=' . $field_details['id'] . '&option_value_id="+id,
                                    success: function(data) {
                                        $("#second_extra_' . $field_details['field_variable'] . '").empty();
                                        $.each(data, function(index, value) {
                                            $("#second_extra_' . $field_details['field_variable'] . '").append($("<option/>", {
                                                value: index,
                                                text: value
                                            }));
                                        });
                                    },
                                });
                            } else {
                                $("#second_extra_' . $field_details['field_variable'] . '").empty();
                            }
                        });';
                        $first_id = null;
                        $second_id = null;
                        if (!empty($extraData)) {
                            $first_id = $extraData['extra_' . $field_details['field_variable']]['extra_' . $field_details['field_variable']];
                            $second_id = $extraData['extra_' . $field_details['field_variable']]['extra_' . $field_details['field_variable'] . '_second'];
                        }
                        $options = ExtraField::extra_field_double_select_convert_array_to_ordered_array($field_details['options']);
                        $values = array('' => get_lang('Select'));
                        $second_values = array();
                        if (!empty($options)) {
                            foreach ($options as $option) {
                                foreach ($option as $sub_option) {
                                    if ($sub_option['option_value'] == '0') {
                                        $values[$sub_option['id']] = $sub_option['option_display_text'];
                                    } else {
                                        if ($first_id === $sub_option['option_value']) {
                                            $second_values[$sub_option['id']] = $sub_option['option_display_text'];
                                        }
                                    }
                                }
                            }
                        }
                        $group = array();
                        $group[] = $form->createElement('select', 'extra_' . $field_details['field_variable'], null, $values, array('id' => $first_select_id));
                        $group[] = $form->createElement('select', 'extra_' . $field_details['field_variable'] . '_second', null, $second_values, array('id' => 'second_extra_' . $field_details['field_variable']));
                        $form->addGroup($group, 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], '&nbsp;');
                        if (!$admin_permissions) {
                            if ($field_details['field_visible'] == 0) {
                                $form->freeze('extra_' . $field_details['field_variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_DIVIDER:
                        $form->addElement('static', $field_details['field_variable'], '<br /><strong>' . $field_details['field_display_text'] . '</strong>');
                        break;
                    case ExtraField::FIELD_TYPE_TAG:
                        $field_variable = $field_details['field_variable'];
                        $field_id = $field_details['id'];
                        if ($this->type == 'user') {
                            // The magic should be here
                            $user_tags = UserManager::get_user_tags($user_id, $field_details['id']);
                            $tag_list = '';
                            if (is_array($user_tags) && count($user_tags) > 0) {
                                foreach ($user_tags as $tag) {
                                    $tag_list .= '<option value="' . $tag['tag'] . '" class="selected">' . $tag['tag'] . '</option>';
                                }
                            }
                            $url = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php?';
                        } else {
                            $extraFieldValue = new ExtraFieldValue($this->type);
                            $tags = array();
                            if (!empty($itemId)) {
                                $tags = $extraFieldValue->getAllValuesByItemAndField($itemId, $field_id);
                            }
                            $tag_list = '';
                            if (is_array($tags) && count($tags) > 0) {
                                $extraFieldOption = new ExtraFieldOption($this->type);
                                foreach ($tags as $tag) {
                                    $option = $extraFieldOption->get($tag['field_value']);
                                    $tag_list .= '<option value="' . $option['id'] . '" class="selected">' . $option['option_display_text'] . '</option>';
                                }
                            }
                            $url = api_get_path(WEB_AJAX_PATH) . 'extra_field.ajax.php';
                        }
                        $form->addElement('hidden', 'extra_' . $field_details['field_variable'] . '__persist__', 1);
                        $multiSelect = '<select id="extra_' . $field_details['field_variable'] . '" name="extra_' . $field_details['field_variable'] . '">
                                        ' . $tag_list . '
                                        </select>';
                        $form->addElement('label', $field_details['field_display_text'], $multiSelect);
                        $complete_text = get_lang('StartToType');
                        //if cache is set to true the jquery will be called 1 time
                        $jquery_ready_content .= <<<EOF
                    \$("#extra_{$field_variable}").fcbkcomplete({
                        json_url: "{$url}?a=search_tags&field_id={$field_id}&type={$this->type}",
                        cache: false,
                        filter_case: true,
                        filter_hide: true,
                        complete_text:"{$complete_text}",
                        firstselected: false,
                        filter_selected: true,
                        newel: true
                    });
EOF;
                        $jquery_ready_content = null;
                        break;
                    case ExtraField::FIELD_TYPE_TIMEZONE:
                        $form->addElement('select', 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], api_get_timezones(), '');
                        if ($field_details['field_visible'] == 0) {
                            $form->freeze('extra_' . $field_details['field_variable']);
                        }
                        break;
                    case ExtraField::FIELD_TYPE_SOCIAL_PROFILE:
                        // get the social network's favicon
                        $icon_path = UserManager::get_favicon_from_url($extraData['extra_' . $field_details['field_variable']], $field_details['field_default_value']);
                        // special hack for hi5
                        $leftpad = '1.7';
                        $top = '0.4';
                        $domain = parse_url($icon_path, PHP_URL_HOST);
                        if ($domain == 'www.hi5.com' or $domain == 'hi5.com') {
                            $leftpad = '3';
                            $top = '0';
                        }
                        // print the input field
                        $form->addElement('text', 'extra_' . $field_details['field_variable'], $field_details['field_display_text'], array('size' => 60, 'style' => 'background-image: url(\'' . $icon_path . '\'); background-repeat: no-repeat; background-position: 0.4em ' . $top . 'em; padding-left: ' . $leftpad . 'em; '));
                        $form->applyFilter('extra_' . $field_details['field_variable'], 'stripslashes');
                        $form->applyFilter('extra_' . $field_details['field_variable'], 'trim');
                        if ($field_details['field_visible'] == 0) {
                            $form->freeze('extra_' . $field_details['field_variable']);
                        }
                        break;
                }
            }
        }
        $return = array();
        $return['jquery_ready_content'] = $jquery_ready_content;
        return $return;
    }
Example #7
0
 /**
  * Returns the form to update or create a document
  * @param    string    Action (add/edit)
  * @param    integer    ID of the lp_item (if already exists)
  * @param    mixed    Integer if document ID, string if info ('new')
  * @return    string    HTML form
  */
 public function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
 {
     $course_id = api_get_course_int_id();
     $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
     $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
     $no_display_edit_textarea = false;
     //If action==edit document
     //We don't display the document form if it's not an editable document (html or txt file)
     if ($action == "edit") {
         if (is_array($extra_info)) {
             $path_parts = pathinfo($extra_info['dir']);
             if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
                 $no_display_edit_textarea = true;
             }
         }
     }
     $no_display_add = false;
     // If action==add an existing document
     // We don't display the document form if it's not an editable document (html or txt file).
     if ($action == "add") {
         if (is_numeric($extra_info)) {
             $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE c_id = " . $course_id . " AND id = " . Database::escape_string($extra_info);
             $result = Database::query($sql_doc);
             $path_file = Database::result($result, 0, 0);
             $path_parts = pathinfo($path_file);
             if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
                 $no_display_add = true;
             }
         }
     }
     if ($id != 0 && is_array($extra_info)) {
         $item_title = stripslashes($extra_info['title']);
         $item_description = stripslashes($extra_info['description']);
         $item_terms = stripslashes($extra_info['terms']);
         if (empty($item_title)) {
             $path_parts = pathinfo($extra_info['path']);
             $item_title = stripslashes($path_parts['filename']);
         }
     } elseif (is_numeric($extra_info)) {
         $sql_doc = "SELECT path, title FROM " . $tbl_doc . "\n                        WHERE c_id = " . $course_id . " AND id = " . Database::escape_string($extra_info);
         $result = Database::query($sql_doc);
         $row = Database::fetch_array($result);
         $explode = explode('.', $row['title']);
         if (count($explode) > 1) {
             for ($i = 0; $i < count($explode) - 1; $i++) {
                 $item_title .= $explode[$i];
             }
         } else {
             $item_title = $row['title'];
         }
         $item_title = str_replace('_', ' ', $item_title);
         if (empty($item_title)) {
             $path_parts = pathinfo($row['path']);
             $item_title = stripslashes($path_parts['filename']);
         }
     } else {
         $item_title = '';
         $item_description = '';
     }
     $return = '<legend>';
     if ($id != 0 && is_array($extra_info)) {
         $parent = $extra_info['parent_item_id'];
     } else {
         $parent = 0;
     }
     $sql = "SELECT * FROM " . $tbl_lp_item . "\n                WHERE c_id = " . $course_id . " AND lp_id = " . $this->lp_id;
     $result = Database::query($sql);
     $arrLP = array();
     while ($row = Database::fetch_array($result)) {
         $arrLP[] = array('id' => $row['id'], 'item_type' => $row['item_type'], 'title' => $row['title'], 'path' => $row['path'], 'description' => $row['description'], 'parent_item_id' => $row['parent_item_id'], 'previous_item_id' => $row['previous_item_id'], 'next_item_id' => $row['next_item_id'], 'display_order' => $row['display_order'], 'max_score' => $row['max_score'], 'min_score' => $row['min_score'], 'mastery_score' => $row['mastery_score'], 'prerequisite' => $row['prerequisite']);
     }
     $this->tree_array($arrLP);
     $arrLP = null;
     if (isset($this->arrMenu)) {
         $arrLP = $this->arrMenu;
         unset($this->arrMenu);
     }
     if ($action == 'add') {
         $return .= get_lang('CreateTheDocument');
     } elseif ($action == 'move') {
         $return .= get_lang('MoveTheCurrentDocument');
     } else {
         $return .= get_lang('EditTheCurrentDocument');
     }
     $return .= '</legend>';
     if (isset($_GET['edit']) && $_GET['edit'] == 'true') {
         $return .= Display::return_warning_message('<strong>' . get_lang('Warning') . ' !</strong><br />' . get_lang('WarningEditingDocument'), false);
     }
     $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING'], '', array('enctype' => "multipart/form-data"));
     $defaults['title'] = Security::remove_XSS($item_title);
     if (empty($item_title)) {
         $defaults['title'] = Security::remove_XSS($item_title);
     }
     $defaults['description'] = $item_description;
     $form->addElement('html', $return);
     if ($action != 'move') {
         $form->addElement('text', 'title', get_lang('Title'), array('id' => 'idTitle', 'class' => 'span4'));
         $form->applyFilter('title', 'html_filter');
     }
     //$arrHide = array($id);
     $arrHide[0]['value'] = $this->name;
     $arrHide[0]['padding'] = 3;
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($action != 'add') {
             if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                 $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
                 if ($parent == $arrLP[$i]['id']) {
                     $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                 }
             }
         } else {
             if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                 $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
                 if ($parent == $arrLP[$i]['id']) {
                     $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                 }
             }
         }
     }
     $parent_select = $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" id="idParent" style="width:40%;" onchange="javascript: load_cbo(this.value);"');
     $my_count = 0;
     foreach ($arrHide as $key => $value) {
         if ($my_count != 0) {
             // The LP name is also the first section and is not in the same charset like the other sections.
             $value['value'] = Security::remove_XSS($value['value']);
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         } else {
             $value['value'] = Security::remove_XSS($value['value']);
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         }
         $my_count++;
     }
     if (!empty($id)) {
         $parent_select->setSelected($parent);
     } else {
         $parent_item_id = Session::read('parent_item_id');
         $parent_select->setSelected($parent_item_id);
     }
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     $arrHide = array();
     $s_selected_position = null;
     //POSITION
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
             if (isset($extra_info['previous_item_id']) && $extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                 $s_selected_position = $arrLP[$i]['id'];
             } elseif ($action == 'add') {
                 $s_selected_position = $arrLP[$i]['id'];
             }
             $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
         }
     }
     $position = $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_item_form" style="width:40%;"');
     $position->addOption(get_lang('FirstPosition'), 0);
     foreach ($arrHide as $key => $value) {
         $padding = isset($value['padding']) ? $value['padding'] : 0;
         $position->addOption($value['value'], $key, 'style="padding-left:' . $padding . 'px;"');
     }
     $position->setSelected($s_selected_position);
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     if ($action != 'move') {
         $id_prerequisite = 0;
         if (is_array($arrLP)) {
             foreach ($arrLP as $key => $value) {
                 if ($value['id'] == $id) {
                     $id_prerequisite = $value['prerequisite'];
                     break;
                 }
             }
         }
         $arrHide = array();
         for ($i = 0; $i < count($arrLP); $i++) {
             if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
                 if (isset($extra_info['previous_item_id']) && $extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                     $s_selected_position = $arrLP[$i]['id'];
                 } elseif ($action == 'add') {
                     $s_selected_position = $arrLP[$i]['id'];
                 }
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
             }
         }
         if (!$no_display_add) {
             if ($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true') {
                 if (isset($_POST['content'])) {
                     $content = stripslashes($_POST['content']);
                 } elseif (is_array($extra_info)) {
                     //If it's an html document or a text file
                     if (!$no_display_edit_textarea) {
                         $content = $this->display_document($extra_info['path'], false, false);
                     }
                 } elseif (is_numeric($extra_info)) {
                     $content = $this->display_document($extra_info, false, false);
                 } else {
                     $content = '';
                 }
                 if (!$no_display_edit_textarea) {
                     // We need to calculate here some specific settings for the online editor.
                     // The calculated settings work for documents in the Documents tool
                     // (on the root or in subfolders).
                     // For documents in native scorm packages it is unclear whether the
                     // online editor should be activated or not.
                     // A new document, it is in the root of the repository.
                     $relative_path = '';
                     $relative_prefix = '';
                     if (is_array($extra_info) && $extra_info != 'new') {
                         // The document already exists. Whe have to determine its relative path towards the repository root.
                         $relative_path = explode('/', $extra_info['dir']);
                         $cnt = count($relative_path) - 2;
                         if ($cnt < 0) {
                             $cnt = 0;
                         }
                         $relative_prefix = str_repeat('../', $cnt);
                         $relative_path = array_slice($relative_path, 1, $cnt);
                         $relative_path = implode('/', $relative_path);
                         if (strlen($relative_path) > 0) {
                             $relative_path = $relative_path . '/';
                         }
                     } else {
                         $_course = api_get_course_info();
                         $result = $this->generate_lp_folder($_course);
                         $relative_path = api_substr($result['dir'], 1, strlen($result['dir']));
                         $relative_prefix = '../../';
                     }
                     $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '500', 'FullPage' => true, 'CreateDocumentDir' => $relative_prefix, 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/', 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/' . $relative_path);
                     if ($_GET['action'] == 'add_item') {
                         $class = 'add';
                         $text = get_lang('LPCreateDocument');
                     } else {
                         if ($_GET['action'] == 'edit_item') {
                             $class = 'save';
                             $text = get_lang('SaveDocument');
                         }
                     }
                     $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
                     $renderer = $form->defaultRenderer();
                     $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
                     $form->addElement('html', '<div>');
                     $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
                     $form->addElement('html', '</div>');
                     $defaults['content_lp'] = $content;
                 }
             } elseif (is_numeric($extra_info)) {
                 $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
                 $return = $this->display_document($extra_info, true, true, true);
                 $form->addElement('html', $return);
             }
         }
     }
     if ($action == 'move') {
         $form->addElement('hidden', 'title', $item_title);
         $form->addElement('hidden', 'description', $item_description);
     }
     if (is_numeric($extra_info)) {
         $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
         $form->addElement('hidden', 'path', $extra_info);
     } elseif (is_array($extra_info)) {
         $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
         $form->addElement('hidden', 'path', $extra_info['path']);
     }
     $form->addElement('hidden', 'type', TOOL_DOCUMENT);
     $form->addElement('hidden', 'post_time', time());
     $form->setDefaults($defaults);
     return $form->return_form();
 }
 /**
  * @param FormValidator $form
  * @param array
  *
  * @return FormValidator
  */
 public static function setGroupForm($form, $groupData = array())
 {
     // Name
     $form->addElement('text', 'name', get_lang('Name'), array('maxlength' => 120));
     $form->applyFilter('name', 'html_filter');
     $form->applyFilter('name', 'trim');
     $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
     // Description
     $form->addElement('textarea', 'description', get_lang('Description'), array('cols' => 58, 'onKeyDown' => "textarea_maxlength()", 'onKeyUp' => "textarea_maxlength()"));
     $form->applyFilter('description', 'html_filter');
     $form->applyFilter('description', 'trim');
     $form->addRule('name', '', 'maxlength', 255);
     // Url
     $form->addElement('text', 'url', 'URL');
     $form->applyFilter('url', 'html_filter');
     $form->applyFilter('url', 'trim');
     // Picture
     $form->addElement('file', 'picture', get_lang('AddPicture'));
     $allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif');
     $form->addRule('picture', get_lang('OnlyImagesAllowed') . ' (' . implode(',', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types);
     if (!empty($groupData)) {
         if (isset($groupData['picture_uri']) && strlen($groupData['picture_uri']) > 0) {
             $form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
         }
     }
     // 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, array());
     if (!empty($groupData)) {
         if (self::canLeaveFeatureEnabled($groupData)) {
             $form->addElement('checkbox', 'allow_members_leave_group', '', get_lang('AllowMemberLeaveGroup'));
         }
         // Set default values
         $form->setDefaults($groupData);
     }
     return $form;
 }
 /**
  * @Route("/add_course", name="add_course")
  * @Method({"GET|POST"})
  * @Security("has_role('ROLE_USER')")
  *
  * @return Response
  */
 public function addCourseAction()
 {
     // "Course validation" feature. This value affects the way of a new course creation:
     // true  - the new course is requested only and it is created after approval;
     // false - the new course is created immediately, after filling this form.
     $courseValidation = false;
     if (api_get_setting('course.course_validation') == 'true' && !api_is_platform_admin()) {
         $courseValidation = true;
     }
     // Displaying the header.
     $tool_name = $courseValidation ? get_lang('CreateCourseRequest') : get_lang('CreateSite');
     if (api_get_setting('course.allow_users_to_create_courses') == 'false' && !api_is_platform_admin()) {
         api_not_allowed(true);
     }
     // Check access rights.
     if (!api_is_allowed_to_create_course()) {
         api_not_allowed(true);
     }
     $url = $this->generateUrl('add_course');
     // Build the form.
     $form = new \FormValidator('add_course', 'post', $url);
     // Form title
     $form->addElement('header', $tool_name);
     // Title
     $form->addElement('text', 'title', array(get_lang('CourseName'), get_lang('Ex')), array('id' => 'title'));
     $form->applyFilter('title', 'html_filter');
     $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
     $form->addButtonAdvancedSettings('advanced_params');
     $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
     // Category category.
     $url = api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?a=search_category';
     $form->addElement('select_ajax', 'category_code', get_lang('CourseFaculty'), null, array('url' => $url));
     // Course code
     $form->addText('wanted_code', array(get_lang('Code'), get_lang('OnlyLettersAndNumbers')), '', array('maxlength' => \CourseManager::MAX_COURSE_LENGTH_CODE, 'pattern' => '[a-zA-Z0-9]+', 'title' => get_lang('OnlyLettersAndNumbers')));
     $form->applyFilter('wanted_code', 'html_filter');
     $form->addRule('wanted_code', get_lang('Max'), 'maxlength', \CourseManager::MAX_COURSE_LENGTH_CODE);
     // The teacher
     //array(get_lang('Professor'), null), null, array('size' => '60', 'disabled' => 'disabled'));
     $titular =& $form->addElement('hidden', 'tutor_name', '');
     if ($courseValidation) {
         // Description of the requested course.
         $form->addElement('textarea', 'description', get_lang('Description'), array('rows' => '3'));
         // Objectives of the requested course.
         $form->addElement('textarea', 'objetives', get_lang('Objectives'), array('rows' => '3'));
         // Target audience of the requested course.
         $form->addElement('textarea', 'target_audience', get_lang('TargetAudience'), array('rows' => '3'));
     }
     // Course language.
     $form->addElement('select_language', 'course_language', get_lang('Ln'), array(), array('style' => 'width:150px'));
     $form->applyFilter('select_language', 'html_filter');
     // Exemplary content checkbox.
     $form->addElement('checkbox', 'exemplary_content', null, get_lang('FillWithExemplaryContent'));
     if ($courseValidation) {
         // A special URL to terms and conditions that is set
         // in the platform settings page.
         $terms_and_conditions_url = trim(api_get_setting('course_validation_terms_and_conditions_url'));
         // If the special setting is empty,
         // then we may get the URL from Chamilo's module "Terms and conditions",
         // if it is activated.
         if (empty($terms_and_conditions_url)) {
             if (api_get_setting('registration.allow_terms_conditions') == 'true') {
                 $terms_and_conditions_url = api_get_path(WEB_CODE_PATH);
                 $terms_and_conditions_url .= 'auth/inscription.php?legal';
             }
         }
         if (!empty($terms_and_conditions_url)) {
             // Terms and conditions to be accepted before sending a course request.
             $form->addElement('checkbox', 'legal', null, get_lang('IAcceptTermsAndConditions'), 1);
             $form->addRule('legal', get_lang('YouHaveToAcceptTermsAndConditions'), 'required');
             // Link to terms and conditions.
             $link_terms_and_conditions = '
                 <script>
                 function MM_openBrWindow(theURL, winName, features) { //v2.0
                     window.open(theURL,winName,features);
                 }
                 </script>
             ';
             $link_terms_and_conditions .= \Display::url(get_lang('ReadTermsAndConditions'), '#', ['onclick' => "javascript:MM_openBrWindow('{$terms_and_conditions_url}', 'Conditions', 'scrollbars=yes, width=800');"]);
             $form->addElement('label', null, $link_terms_and_conditions);
         }
     }
     $obj = new \GradeModel();
     $obj->fill_grade_model_select_in_form($form);
     $form->addElement('html', '</div>');
     // Submit button.
     $form->addButtonCreate($courseValidation ? get_lang('CreateThisCourseRequest') : get_lang('CreateCourseArea'));
     // Set default values.
     if (isset($_user['language']) && $_user['language'] != '') {
         $values['course_language'] = $_user['language'];
     } else {
         $values['course_language'] = api_get_setting('language.platform_language');
     }
     $form->setDefaults($values);
     $message = null;
     $content = null;
     // Validate the form.
     if ($form->validate()) {
         $course_values = $form->exportValues();
         $wanted_code = $course_values['wanted_code'];
         //$category_code = $course_values['category_code'];
         $category_code = '';
         $title = $course_values['title'];
         $course_language = $course_values['course_language'];
         $exemplary_content = !empty($course_values['exemplary_content']);
         if ($courseValidation) {
             $description = $course_values['description'];
             $objetives = $course_values['objetives'];
             $target_audience = $course_values['target_audience'];
         }
         if ($wanted_code == '') {
             $wanted_code = \CourseManager::generate_course_code(api_substr($title, 0, \CourseManager::MAX_COURSE_LENGTH_CODE));
         }
         // Check whether the requested course code has already been occupied.
         if (!$courseValidation) {
             $course_code_ok = !\CourseManager::course_code_exists($wanted_code);
         } else {
             $course_code_ok = !\CourseRequestManager::course_code_exists($wanted_code);
         }
         if ($course_code_ok) {
             if (!$courseValidation) {
                 $params = array();
                 $params['title'] = $title;
                 $params['exemplary_content'] = $exemplary_content;
                 $params['wanted_code'] = $wanted_code;
                 $params['course_category'] = $category_code;
                 $params['course_language'] = $course_language;
                 $params['gradebook_model_id'] = isset($course_values['gradebook_model_id']) ? $course_values['gradebook_model_id'] : null;
                 $course_info = \CourseManager::create_course($params);
                 if (!empty($course_info)) {
                     $url = api_get_path(WEB_CODE_PATH);
                     $url .= 'course_info/start.php?cidReq=';
                     $url .= $course_info['code'];
                     $url .= '&first=1';
                     header('Location: ' . $url);
                     exit;
                 } else {
                     $this->addFlash('error', $this->trans('CourseCreationFailed'));
                     // Display the form.
                     $content = $form->returnForm();
                 }
             } else {
                 // Create a request for a new course.
                 $request_id = \CourseRequestManager::create_course_request($wanted_code, $title, $description, $category_code, $course_language, $objetives, $target_audience, api_get_user_id(), $exemplary_content);
                 if ($request_id) {
                     $course_request_info = \CourseRequestManager::get_course_request_info($request_id);
                     $message = (is_array($course_request_info) ? '<strong>' . $course_request_info['code'] . '</strong> : ' : '') . get_lang('CourseRequestCreated');
                     \Display::return_message($message, 'confirmation', false);
                     \Display::return_message('div', \Display::url(get_lang('Enter'), api_get_path(WEB_PATH) . 'user_portal.php', ['class' => 'btn btn-default']), ['style' => 'float: left; margin:0px; padding: 0px;']);
                 } else {
                     \Display::return_message(get_lang('CourseRequestCreationFailed'), 'error', false);
                     // Display the form.
                     $content = $form->returnForm();
                 }
             }
         } else {
             \Display::return_message(get_lang('CourseCodeAlreadyExists'), 'error', false);
             // Display the form.
             $content = $form->returnForm();
         }
     } else {
         if (!$courseValidation) {
             $this->addFlash('warning', get_lang('Explanation'));
         }
         // Display the form.
         $content = $form->returnForm();
     }
     return $this->render('ChamiloCoreBundle:Index:userportal.html.twig', array('content' => $content));
 }
if (api_get_setting('registration.allow_terms_conditions') == 'true') {
    $display_all_form = !isset($_SESSION['update_term_and_condition']['user_id']);
} else {
    $display_all_form = true;
}
if ($display_all_form) {
    if (api_is_western_name_order()) {
        //	FIRST NAME and LAST NAME
        $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40, 'disabled' => 'disabled'));
        $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40, 'disabled' => 'disabled'));
    } else {
        //	LAST NAME and FIRST NAME
        $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40, 'disabled' => 'disabled'));
        $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40, 'disabled' => 'disabled'));
    }
    $form->applyFilter('firstname', 'trim');
    $form->applyFilter('lastname', 'trim');
    $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
    $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
    //	EMAIL
    $form->addElement('text', 'email', get_lang('Email'), array('size' => 40, 'disabled' => 'disabled'));
    if (api_get_setting_in_list('registration.required_profile_fields', 'email')) {
        $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
    }
    $form->addRule('email', get_lang('EmailWrong'), 'email');
    /*if (api_get_setting('openid_authentication') == 'true') {
          $form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => 40, 'disabled' => 'disabled'));
      }*/
    //	USERNAME
    $form->addElement('text', 'username', get_lang('UserName'), array('size' => USERNAME_MAX_LENGTH, 'disabled' => 'disabled'));
    $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
Example #11
0
// COURSE SETTINGS
$form->addElement('html', '<div><h3>' . Display::return_icon('settings.png', Security::remove_XSS(get_lang('CourseSettings')), '', ICON_SIZE_SMALL) . ' ' . Security::remove_XSS(get_lang('CourseSettings')) . '</h3><div>');
$image_html = '';
// Display course picture
$course_path = api_get_path(SYS_COURSE_PATH) . $currentCourseRepository;
// course path
if (file_exists($course_path . '/course-pic85x85.png')) {
    $course_web_path = api_get_path(WEB_COURSE_PATH) . $currentCourseRepository;
    // course web path
    $course_medium_image = $course_web_path . '/course-pic85x85.png?' . rand(1, 1000);
    // redimensioned image 85x85
    $image_html = '<div class="row"><label class="col-md-2 control-label">' . get_lang('Image') . '</label> <div class="col-md-8"><img src="' . $course_medium_image . '" /></div></div>';
}
$form->addElement('html', $image_html);
$form->addText('title', get_lang('Title'), true);
$form->applyFilter('title', 'html_filter');
$form->applyFilter('title', 'trim');
$form->addElement('select', 'category_code', get_lang('Fac'), $categories, ['style' => 'width:350px', 'id' => 'category_code']);
$form->addElement('select_language', 'course_language', array(get_lang('Ln'), get_lang('TipLang')));
$form->addText('department_name', get_lang('Department'), false);
$form->applyFilter('department_name', 'html_filter');
$form->applyFilter('department_name', 'trim');
$form->addText('department_url', get_lang('DepartmentUrl'), false);
$form->applyFilter('department_url', 'html_filter');
// Picture
$form->addElement('file', 'picture', get_lang('AddPicture'), array('id' => 'picture', 'class' => 'picture-form'));
$form->addHtml('' . '<div class="form-group">' . '<label for="cropImage" id="labelCropImage" class="col-sm-2 control-label"></label>' . '<div class="col-sm-8">' . '<div id="cropImage" class="cropCanvas">' . '<img id="previewImage" >' . '</div>' . '<div>' . '<button class="btn btn-primary hidden" name="cropButton" id="cropButton"><em class="fa fa-crop"></em> ' . get_lang('CropYourPicture') . '</button>' . '</div>' . '</div>' . '</div>' . '');
$form->addHidden('cropResult', '');
$allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif');
$form->addRule('picture', get_lang('OnlyImagesAllowed') . ' (' . implode(',', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types);
//$form->addElement('html', '<div class="form-group "><div class="col-md-2"></div> <div class="col-md-8 help-image">'.get_lang('UniqueAnswerImagePreferredSize200x150').'</div></div>');
Example #12
0
    exit;
}
$currentUserId = api_get_user_id();
$currentUser = $entityManager->find('ChamiloUserBundle:User', $currentUserId);
$allowExport = $currentUser ? $currentUser->getId() === $skillIssue->getUser()->getId() : false;
$allowComment = $currentUser ? Skill::userCanAddFeedbackToUser($currentUser, $skillIssue->getUser()) : false;
$skillIssueDate = api_get_local_time($skillIssue->getAcquiredSkillAt());
$skillIssueInfo = ['id' => $skillIssue->getId(), 'datetime' => api_format_date($skillIssueDate, DATE_TIME_FORMAT_SHORT), 'argumentation' => $skillIssue->getArgumentation(), 'source_name' => $skillIssue->getSourceName(), 'user_id' => $skillIssue->getUser()->getId(), 'user_complete_name' => $skillIssue->getUser()->getCompleteName(), 'skill_badge_image' => $skillIssue->getSkill()->getWebIconPath(), 'skill_name' => $skillIssue->getSkill()->getName(), 'skill_short_code' => $skillIssue->getSkill()->getShortCode(), 'skill_description' => $skillIssue->getSkill()->getDescription(), 'skill_criteria' => $skillIssue->getSkill()->getCriteria(), 'badge_asserion' => [$skillIssue->getAssertionUrl()], 'comments' => [], 'feedback_average' => $skillIssue->getAverage()];
$skillIssueComments = $skillIssue->getComments(true);
foreach ($skillIssueComments as $comment) {
    $commentDate = api_get_local_time($comment->getFeedbackDateTime());
    $skillIssueInfo['comments'][] = ['text' => $comment->getFeedbackText(), 'value' => $comment->getFeedbackValue(), 'giver_complete_name' => $comment->getFeedbackGiver()->getCompleteName(), 'datetime' => api_format_date($commentDate, DATE_TIME_FORMAT_SHORT)];
}
$form = new FormValidator('comment');
$form->addTextarea('comment', get_lang('NewComment'), ['rows' => 4]);
$form->applyFilter('comment', 'trim');
$form->addRule('comment', get_lang('ThisFieldIsRequired'), 'required');
$form->addSelect('value', [get_lang('Value'), get_lang('RateTheSkillInPractice')], ['-', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
$form->addHidden('user', $skillIssue->getUser()->getId());
$form->addHidden('issue', $skillIssue->getId());
$form->addButtonSend(get_lang('Send'));
if ($form->validate() && $allowComment) {
    $values = $form->exportValues();
    $skillUserComment = new Chamilo\CoreBundle\Entity\SkillRelUserComment();
    $skillUserComment->setFeedbackDateTime(new DateTime())->setFeedbackGiver($currentUser)->setFeedbackText($values['comment'])->setFeedbackValue($values['value'] ? $values['value'] : null)->setSkillRelUser($skillIssue);
    $entityManager->persist($skillUserComment);
    $entityManager->flush();
    header("Location: " . $skillIssue->getIssueUrl());
    exit;
}
if ($allowExport) {
             $row['category'] = 0;
         }
         if (is_array($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']])) {
             // we are sure that the other site have a selected value
             if ($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value'] != '') {
                 $row['selected_value'] = $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value'];
             }
         }
         // there is no else because we load the default $row['selected_value'] of the main Dokeos site
     }
 }
 switch ($row['type']) {
     case 'textfield':
         if ($row['variable'] == 'account_valid_duration') {
             $form->addElement('text', $row['variable'], get_lang($row['comment']), array('maxlength' => '5'));
             $form->applyFilter($row['variable'], 'html_filter');
             $default_values[$row['variable']] = $row['selected_value'];
         } else {
             $form->addElement('text', $row['variable'], get_lang($row['comment']), $hideme);
             $form->applyFilter($row['variable'], 'html_filter');
             $default_values[$row['variable']] = $row['selected_value'];
         }
         break;
     case 'textarea':
         $form->addElement('textarea', $row['variable'], get_lang($row['comment']), $hideme);
         $default_values[$row['variable']] = $row['selected_value'];
         break;
     case 'radio':
         $values = get_settings_options($row['variable']);
         $group = array();
         if (is_array($values)) {
$form->addElement('hidden', 'survey_language');
$form->addElement('datepickerdate', 'start_date', get_lang('StartDate'), array('form_name' => 'survey'));
$form->addElement('datepickerdate', 'end_date', get_lang('EndDate'), array('form_name' => 'survey'));
$form->addElement('checkbox', 'anonymous', null, get_lang('Anonymous'));
$form->addElement('html_editor', 'survey_introduction', get_lang('SurveyIntroduction'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false));
$form->addElement('html_editor', 'survey_thanks', get_lang('SurveyThanks'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false));
// Aditional Parameters
$form->addElement('advanced_settings', '<a href="javascript: void(0);" onclick="javascript: advanced_parameters();" >
        <span id="plus_minus">&nbsp;' . Display::return_icon('div_show.gif', null, array('style' => 'vertical-align:middle')) . '&nbsp;' . get_lang('AdvancedParameters') . '</span></a>');
$form->addElement('html', '<div id="options" style="display: none;">');
if (Gradebook::is_active()) {
    // An option: Qualify the fact that survey has been answered in the gradebook
    $form->addElement('checkbox', 'survey_qualify_gradebook', null, get_lang('QualifyInGradebook'), 'onclick="javascript: if (this.checked) { document.getElementById(\'gradebook_options\').style.display = \'block\'; } else { document.getElementById(\'gradebook_options\').style.display = \'none\'; }"');
    $form->addElement('html', '<div id="gradebook_options"' . ($gradebook_link_id ? '' : ' style="display:none"') . '>');
    $form->addElement('text', 'survey_weight', get_lang('QualifyWeight'), 'value="0.00" style="width: 40px;" onfocus="javascript: this.select();"');
    $form->applyFilter('survey_weight', 'html_filter');
    $form->addElement('html', '</div>');
}
// Personality/Conditional Test Options
$surveytypes[0] = get_lang('Normal');
$surveytypes[1] = get_lang('Conditional');
if ($_GET['action'] == 'add') {
    $form->addElement('hidden', 'survey_type', 0);
    require_once api_get_path(LIBRARY_PATH) . 'surveymanager.lib.php';
    $survey_tree = new SurveyTree();
    $list_surveys = $survey_tree->createList($survey_tree->surveylist);
    $list_surveys[0] = '';
    $form->addElement('select', 'parent_id', get_lang('ParentSurvey'), $list_surveys);
    $defaults['parent_id'] = 0;
}
if ($survey_data['survey_type'] == 1 || $_GET['action'] == 'add') {
Example #15
0
$exercise_redirect = isset($_REQUEST['e']) && !empty($_REQUEST['e']) ? $_REQUEST['e'] : null;
if (!empty($course_code_redirect)) {
    Session::write('course_redirect', $course_code_redirect);
    Session::write('exercise_redirect', $exercise_redirect);
}
if ($user_already_registered_show_terms == false) {
    if (api_is_western_name_order()) {
        // FIRST NAME and LAST NAME
        $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
        $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
    } else {
        // LAST NAME and FIRST NAME
        $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
        $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
    }
    $form->applyFilter(array('lastname', 'firstname'), 'trim');
    $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
    $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
    // EMAIL
    $form->addElement('text', 'email', get_lang('Email'), array('size' => 40));
    if (api_get_setting('registration', 'email') == 'true') {
        $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
    }
    if (api_get_setting('profile.login_is_email') == 'true') {
        $form->applyFilter('email', 'trim');
        if (api_get_setting('registration', 'email') != 'true') {
            $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
        }
        $form->addRule('email', sprintf(get_lang('UsernameMaxXCharacters'), (string) USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
        $form->addRule('email', get_lang('UserTaken'), 'username_available');
    }
Example #16
0
function generate_settings_form($settings, $settings_by_access_list)
{
    global $_configuration, $settings_to_avoid, $convert_byte_to_mega_list;
    $table_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
    $form = new FormValidator('settings', 'post', 'settings.php?category=' . Security::remove_XSS($_GET['category']));
    $form->addElement('hidden', 'search_field', !empty($_GET['search_field']) ? Security::remove_XSS($_GET['search_field']) : null);
    $url_id = api_get_current_access_url_id();
    if (!empty($_configuration['multiple_access_urls']) && api_is_global_platform_admin() && $url_id == 1) {
        $group = array();
        $group[] = $form->createElement('button', 'mark_all', get_lang('MarkAll'));
        $group[] = $form->createElement('button', 'unmark_all', get_lang('UnmarkAll'));
        $form->addGroup($group, 'buttons_in_action_right');
    }
    $default_values = array();
    $url_info = api_get_access_url($url_id);
    $i = 0;
    foreach ($settings as $row) {
        if (in_array($row['variable'], array_keys($settings_to_avoid))) {
            continue;
        }
        if (!empty($_configuration['multiple_access_urls'])) {
            if (api_is_global_platform_admin()) {
                if ($row['access_url_locked'] == 0) {
                    if ($url_id == 1) {
                        if ($row['access_url_changeable'] == '1') {
                            $form->addElement('html', '<div style="float: right;"><a class="share_this_setting" data_status = "0"  data_to_send = "' . $row['variable'] . '" href="javascript:void(0);">' . Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')) . '</a></div>');
                        } else {
                            $form->addElement('html', '<div style="float: right;"><a class="share_this_setting" data_status = "1" data_to_send = "' . $row['variable'] . '" href="javascript:void(0);">' . Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')) . '</a></div>');
                        }
                    } else {
                        if ($row['access_url_changeable'] == '1') {
                            $form->addElement('html', '<div style="float: right;">' . Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')) . '</div>');
                        } else {
                            $form->addElement('html', '<div style="float: right;">' . Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')) . '</div>');
                        }
                    }
                }
            }
        }
        $hideme = array();
        $hide_element = false;
        if ($_configuration['access_url'] != 1) {
            if ($row['access_url_changeable'] == 0) {
                // We hide the element in other cases (checkbox, radiobutton) we 'freeze' the element.
                $hide_element = true;
                $hideme = array('disabled');
            } elseif ($url_info['active'] == 1) {
                // We show the elements.
                if (empty($row['variable'])) {
                    $row['variable'] = 0;
                }
                if (empty($row['subkey'])) {
                    $row['subkey'] = 0;
                }
                if (empty($row['category'])) {
                    $row['category'] = 0;
                }
                if (is_array($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']])) {
                    // We are sure that the other site have a selected value.
                    if ($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value'] != '') {
                        $row['selected_value'] = $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value'];
                    }
                }
                // There is no else{} statement because we load the default $row['selected_value'] of the main Chamilo site.
            }
        }
        switch ($row['type']) {
            case 'textfield':
                if (in_array($row['variable'], $convert_byte_to_mega_list)) {
                    $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment']), get_lang('MB')), array('maxlength' => '8'));
                    $form->applyFilter($row['variable'], 'html_filter');
                    $default_values[$row['variable']] = round($row['selected_value'] / 1024 / 1024, 1);
                } elseif ($row['variable'] == 'account_valid_duration') {
                    $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('maxlength' => '5'));
                    $form->applyFilter($row['variable'], 'html_filter');
                    $default_values[$row['variable']] = $row['selected_value'];
                    // For platform character set selection: Conversion of the textfield to a select box with valid values.
                } elseif ($row['variable'] == 'platform_charset') {
                    continue;
                } else {
                    $hideme['class'] = 'col-md-4';
                    $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), $hideme);
                    $form->applyFilter($row['variable'], 'html_filter');
                    $default_values[$row['variable']] = $row['selected_value'];
                }
                break;
            case 'textarea':
                if ($row['variable'] == 'header_extra_content') {
                    $file = api_get_path(SYS_PATH) . api_get_home_path() . 'header_extra_content.txt';
                    $value = '';
                    if (file_exists($file)) {
                        $value = file_get_contents($file);
                    }
                    $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('rows' => '10'), $hideme);
                    $default_values[$row['variable']] = $value;
                } elseif ($row['variable'] == 'footer_extra_content') {
                    $file = api_get_path(SYS_PATH) . api_get_home_path() . 'footer_extra_content.txt';
                    $value = '';
                    if (file_exists($file)) {
                        $value = file_get_contents($file);
                    }
                    $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('rows' => '10'), $hideme);
                    $default_values[$row['variable']] = $value;
                } else {
                    $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('rows' => '10'), $hideme);
                    $default_values[$row['variable']] = $row['selected_value'];
                }
                break;
            case 'radio':
                $values = api_get_settings_options($row['variable']);
                $group = array();
                if (is_array($values)) {
                    foreach ($values as $key => $value) {
                        $element =& $form->createElement('radio', $row['variable'], '', get_lang($value['display_text']), $value['value']);
                        if ($hide_element) {
                            $element->freeze();
                        }
                        $group[] = $element;
                    }
                }
                $form->addGroup($group, $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), '', false);
                $default_values[$row['variable']] = $row['selected_value'];
                break;
            case 'checkbox':
                // 1. We collect all the options of this variable.
                $sql = "SELECT * FROM {$table_settings_current}\n                        WHERE variable='" . $row['variable'] . "' AND access_url =  1";
                $result = Database::query($sql);
                $group = array();
                while ($rowkeys = Database::fetch_array($result)) {
                    // Profile tab option should be hidden when the social tool is enabled.
                    if (api_get_setting('social.allow_social_tool') == 'true') {
                        if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_profile') {
                            continue;
                        }
                    }
                    // Hiding the gradebook option.
                    if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_gradebook') {
                        continue;
                    }
                    $element =& $form->createElement('checkbox', $rowkeys['subkey'], '', get_lang($rowkeys['subkeytext']));
                    if ($row['access_url_changeable'] == 1) {
                        // 2. We look into the DB if there is a setting for a specific access_url.
                        $access_url = $_configuration['access_url'];
                        if (empty($access_url)) {
                            $access_url = 1;
                        }
                        $sql = "SELECT selected_value FROM {$table_settings_current}\n                                WHERE\n                                    variable='" . $rowkeys['variable'] . "' AND\n                                    subkey='" . $rowkeys['subkey'] . "' AND\n                                    subkeytext='" . $rowkeys['subkeytext'] . "' AND\n                                    access_url =  {$access_url}";
                        $result_access = Database::query($sql);
                        $row_access = Database::fetch_array($result_access);
                        if ($row_access['selected_value'] == 'true' && !$form->isSubmitted()) {
                            $element->setChecked(true);
                        }
                    } else {
                        if ($rowkeys['selected_value'] == 'true' && !$form->isSubmitted()) {
                            $element->setChecked(true);
                        }
                    }
                    if ($hide_element) {
                        $element->freeze();
                    }
                    $group[] = $element;
                }
                $form->addGroup($group, $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), '');
                break;
            case 'link':
                $form->addElement('static', null, array(get_lang($row['title']), get_lang($row['comment'])), get_lang('CurrentValue') . ' : ' . $row['selected_value'], $hideme);
                break;
            case 'select':
                /*
                 * To populate the list of options, the select type dynamically calls a function that must be called select_ + the name of the variable being displayed.
                 * The functions being called must be added to the file settings.lib.php.
                 */
                $form->addElement('select', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), call_user_func('select_' . $row['variable']), $hideme);
                $default_values[$row['variable']] = $row['selected_value'];
                break;
            case 'custom':
                break;
        }
        switch ($row['variable']) {
            case 'pdf_export_watermark_enable':
                $url = PDF::get_watermark(null);
                if ($url != false) {
                    $delete_url = '<a href="?delete_watermark">' . get_lang('DelImage') . ' ' . Display::return_icon('delete.png', get_lang('DelImage')) . '</a>';
                    $form->addElement('html', '<div style="max-height:100px; max-width:100px; margin-left:162px; margin-bottom:10px; clear:both;"><img src="' . $url . '" style="margin-bottom:10px;" />' . $delete_url . '</div>');
                }
                $form->addElement('file', 'pdf_export_watermark_path', get_lang('AddWaterMark'));
                $allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif');
                $form->addRule('pdf_export_watermark_path', get_lang('OnlyImagesAllowed') . ' (' . implode(',', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types);
                break;
            case 'timezone_value':
                $timezone = $row['selected_value'];
                if (empty($timezone)) {
                    $timezone = _api_get_timezone();
                }
                $form->addElement('html', sprintf(get_lang('LocalTimeUsingPortalTimezoneXIsY'), $timezone, api_get_local_time()));
                break;
        }
    }
    // end for
    if (!empty($settings)) {
        $form->setDefaults($default_values);
    }
    $form->addHtml('<div class="bottom_actions">');
    $form->addButtonSave(get_lang('SaveSettings'));
    $form->addHtml('</div>');
    return $form;
}
Example #17
0
$user_data['send_mail'] = 0;
$user_data['old_password'] = $user_data['password'];
//Convert the registration date of the user
//@todo remove the date_default_timezone_get() see UserManager::create_user function
$user_data['registration_date'] = api_get_local_time($user_data['registration_date'], null, date_default_timezone_get());
unset($user_data['password']);
$extra_data = UserManager::get_extra_user_data($user_id, true);
$user_data = array_merge($user_data, $extra_data);
// Create the form
$form = new FormValidator('user_edit', 'post', '', '', array('style' => 'width: 60%; float: ' . ($text_dir == 'rtl' ? 'right;' : 'left;')));
$form->addElement('header', '', $tool_name);
$form->addElement('hidden', 'user_id', $user_id);
if (api_is_western_name_order()) {
    // Firstname
    $form->addElement('text', 'firstname', get_lang('FirstName'));
    $form->applyFilter('firstname', 'html_filter');
    $form->applyFilter('firstname', 'trim');
    $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
    // Lastname
    $form->addElement('text', 'lastname', get_lang('LastName'));
    $form->applyFilter('lastname', 'html_filter');
    $form->applyFilter('lastname', 'trim');
    $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
} else {
    // Lastname
    $form->addElement('text', 'lastname', get_lang('LastName'));
    $form->applyFilter('lastname', 'html_filter');
    $form->applyFilter('lastname', 'trim');
    $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
    // Firstname
    $form->addElement('text', 'firstname', get_lang('FirstName'));
Example #18
0
}
$interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
Display::display_header(get_lang('LearnpathAddLearnpath'), 'Path');
echo '<div class="actions">';
echo '<a href="lp_controller.php?cidReq=' . $_course['sysCode'] . '">' . Display::return_icon('back.png', get_lang('ReturnToLearningPaths'), '', ICON_SIZE_MEDIUM) . '</a>';
echo '</div>';
Display::display_normal_message(get_lang('AddLpIntro'), false);
if ($_POST and empty($_REQUEST['lp_name'])) {
    Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'), false);
}
$form = new FormValidator('lp_add', 'post', 'lp_controller.php');
// Form title
$form->addElement('header', null, get_lang('AddLpToStart'));
// Title
$form->addElement('text', 'lp_name', api_ucfirst(get_lang('LPName')), array('class' => 'span6'));
$form->applyFilter('lp_name', 'html_filter');
$form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('hidden', 'post_time', time());
$form->addElement('hidden', 'action', 'add_lp');
$advanced = '<a href="javascript://" onclick=" return advanced_parameters()"><span id="img_plus_and_minus"><div style="vertical-align:top;" >&nbsp;' . $showImg . '&nbsp;' . get_lang('AdvancedParameters') . '</div></span></a>';
$form->addElement('advanced_settings', $advanced);
$form->addElement('html', '<div id="options" style="display:none">');
$items = learnpath::get_category_from_course_into_select(api_get_course_int_id());
if (!empty($items)) {
    $items = array_merge(array(get_lang('SelectACategory')), $items);
}
$form->addElement('select', 'category_id', get_lang('Category'), $items);
//Start date
$form->addElement('checkbox', 'activate_start_date_check', null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()'));
$form->addElement('html', '<div id="start_date_div" style="display:block;">');
$form->addElement('datepicker', 'publicated_on', get_lang('PublicationDate'), array('form_name' => 'lp_add'), 5);
Example #19
0
// Filtering teachers when creating a course.
if (api_is_multiple_url_enabled()) {
    $access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
    $sql = "SELECT u.user_id,lastname,firstname FROM {$table_user} as u\n            INNER JOIN {$access_url_rel_user_table} url_rel_user\n            ON (u.user_id=url_rel_user.user_id) WHERE url_rel_user.access_url_id=" . api_get_current_access_url_id() . " AND status=1" . $order_clause;
}
$res = Database::query($sql);
$teachers = array();
while ($obj = Database::fetch_object($res)) {
    $teachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname);
}
// Build the form.
$form = new FormValidator('update_course');
$form->addElement('header', $tool_name);
// Title
$form->addText('title', get_lang('Title'), true);
$form->applyFilter('title', 'html_filter');
$form->applyFilter('title', 'trim');
// Code
$form->addText('visual_code', array(get_lang('CourseCode'), get_lang('OnlyLettersAndNumbers')), false, ['maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE, 'pattern' => '[a-zA-Z0-9]+', 'title' => get_lang('OnlyLettersAndNumbers')]);
$form->applyFilter('visual_code', 'api_strtoupper');
$form->applyFilter('visual_code', 'html_filter');
$form->addRule('visual_code', get_lang('Max'), 'maxlength', CourseManager::MAX_COURSE_LENGTH_CODE);
$form->addElement('select', 'course_teachers', get_lang('CourseTeachers'), $teachers, ' id="course_teachers" class="chzn-select"  style="width:350px" multiple="multiple" ');
$form->applyFilter('course_teachers', 'html_filter');
// Category code
$url = api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?a=search_category';
$form->addElement('select_ajax', 'category_code', get_lang('CourseFaculty'), null, array('url' => $url));
// Course department
$form->addText('department_name', get_lang('CourseDepartment'), false, array('size' => '60'));
$form->applyFilter('department_name', 'html_filter');
$form->applyFilter('department_name', 'trim');
    $defaults['end_date'] = date('Y-m-d', $startdateandxdays);
    //$defaults['survey_share']['survey_share'] = 0;
    //$form_share_value = 1;
    $defaults['anonymous'] = 0;
}
// Initialize the object
$form = new FormValidator('survey', 'post', api_get_self() . '?action=' . Security::remove_XSS($_GET['action']) . '&survey_id=' . $survey_id);
$form->addElement('header', $tool_name);
// Setting the form elements
if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) {
    $form->addElement('hidden', 'survey_id');
}
$survey_code = $form->addElement('text', 'survey_code', get_lang('SurveyCode'), array('size' => '20', 'maxlength' => '20', 'autofocus' => 'autofocus'));
if ($_GET['action'] == 'edit') {
    //$survey_code->freeze();
    $form->applyFilter('survey_code', 'api_strtoupper');
}
$form->addElement('html_editor', 'survey_title', get_lang('SurveyTitle'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '200'));
$form->addElement('html_editor', 'survey_subtitle', get_lang('SurveySubTitle'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '100', 'ToolbarStartExpanded' => false));
// Pass the language of the survey in the form
$form->addElement('hidden', 'survey_language');
$form->addElement('date_picker', 'start_date', get_lang('StartDate'));
$form->addElement('date_picker', 'end_date', get_lang('EndDate'));
$form->addElement('checkbox', 'anonymous', null, get_lang('Anonymous'));
$visibleResults = array(SURVEY_VISIBLE_TUTOR => get_lang('Coach'), SURVEY_VISIBLE_TUTOR_STUDENT => get_lang('CoachAndStudent'), SURVEY_VISIBLE_PUBLIC => get_lang('Everyone'));
$form->addElement('select', 'visible_results', get_lang('ResultsVisibility'), $visibleResults);
//$defaults['visible_results'] = 0;
$form->addElement('html_editor', 'survey_introduction', get_lang('SurveyIntroduction'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false));
$form->addElement('html_editor', 'survey_thanks', get_lang('SurveyThanks'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false));
// Additional Parameters
$form->addButtonAdvancedSettings('advanced_params');
    /**
     * @param FormValidator $form
     * @param $extra_data
     * @param $form_name
     * @param bool $admin_permissions
     * @param null $user_id
     * @deprecated
     * @return array
     */
    static function set_extra_fields_in_form($form, $extra_data, $admin_permissions = false, $user_id = null)
    {
        $user_id = intval($user_id);
        // EXTRA FIELDS
        $extra = UserManager::get_extra_fields(0, 50, 5, 'ASC');
        $jquery_ready_content = null;
        foreach ($extra as $field_details) {
            if (!$admin_permissions) {
                if ($field_details[6] == 0) {
                    continue;
                }
            }
            switch ($field_details[2]) {
                case ExtraField::FIELD_TYPE_TEXT:
                    $form->addElement('text', 'extra_' . $field_details[1], $field_details[3], array('size' => 40));
                    $form->applyFilter('extra_' . $field_details[1], 'stripslashes');
                    $form->applyFilter('extra_' . $field_details[1], 'trim');
                    $form->applyFilter('extra_' . $field_details[1], 'html_filter');
                    if (!$admin_permissions) {
                        if ($field_details[7] == 0) {
                            $form->freeze('extra_' . $field_details[1]);
                        }
                    }
                    break;
                case ExtraField::FIELD_TYPE_TEXTAREA:
                    $form->addHtmlEditor('extra_' . $field_details[1], $field_details[3], false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130'));
                    $form->applyFilter('extra_' . $field_details[1], 'stripslashes');
                    $form->applyFilter('extra_' . $field_details[1], 'trim');
                    if (!$admin_permissions) {
                        if ($field_details[7] == 0) {
                            $form->freeze('extra_' . $field_details[1]);
                        }
                    }
                    break;
                case ExtraField::FIELD_TYPE_RADIO:
                    $group = array();
                    foreach ($field_details[9] as $option_id => $option_details) {
                        $options[$option_details[1]] = $option_details[2];
                        $group[] = $form->createElement('radio', 'extra_' . $field_details[1], $option_details[1], $option_details[2] . '<br />', $option_details[1]);
                    }
                    $form->addGroup($group, 'extra_' . $field_details[1], $field_details[3], '');
                    if (!$admin_permissions) {
                        if ($field_details[7] == 0) {
                            $form->freeze('extra_' . $field_details[1]);
                        }
                    }
                    break;
                case ExtraField::FIELD_TYPE_SELECT:
                    $get_lang_variables = false;
                    if (in_array($field_details[1], array('mail_notify_message', 'mail_notify_invitation', 'mail_notify_group_message'))) {
                        $get_lang_variables = true;
                    }
                    $options = array();
                    foreach ($field_details[9] as $option_id => $option_details) {
                        if ($get_lang_variables) {
                            $options[$option_details[1]] = get_lang($option_details[2]);
                        } else {
                            $options[$option_details[1]] = $option_details[2];
                        }
                    }
                    if ($get_lang_variables) {
                        $field_details[3] = get_lang($field_details[3]);
                    }
                    $form->addElement('select', 'extra_' . $field_details[1], $field_details[3], $options, array('id' => 'extra_' . $field_details[1]));
                    if (!$admin_permissions) {
                        if ($field_details[7] == 0) {
                            $form->freeze('extra_' . $field_details[1]);
                        }
                    }
                    break;
                case ExtraField::FIELD_TYPE_SELECT_MULTIPLE:
                    $options = array();
                    foreach ($field_details[9] as $option_id => $option_details) {
                        $options[$option_details[1]] = $option_details[2];
                    }
                    $form->addElement('select', 'extra_' . $field_details[1], $field_details[3], $options, array('multiple' => 'multiple'));
                    if (!$admin_permissions) {
                        if ($field_details[7] == 0) {
                            $form->freeze('extra_' . $field_details[1]);
                        }
                    }
                    break;
                case ExtraField::FIELD_TYPE_DATE:
                    $form->addDatePicker('extra_' . $field_details[1], $field_details[3]);
                    $defaults['extra_' . $field_details[1]] = date('Y-m-d 12:00:00');
                    $form->setDefaults($defaults);
                    if (!$admin_permissions) {
                        if ($field_details[7] == 0) {
                            $form->freeze('extra_' . $field_details[1]);
                        }
                    }
                    $form->applyFilter('theme', 'trim');
                    break;
                case ExtraField::FIELD_TYPE_DATETIME:
                    $form->addDateTimePicker('extra_' . $field_details[1], $field_details[3]);
                    $defaults['extra_' . $field_details[1]] = date('Y-m-d 12:00:00');
                    $form->setDefaults($defaults);
                    if (!$admin_permissions) {
                        if ($field_details[7] == 0) {
                            $form->freeze('extra_' . $field_details[1]);
                        }
                    }
                    $form->applyFilter('theme', 'trim');
                    break;
                case ExtraField::FIELD_TYPE_DOUBLE_SELECT:
                    foreach ($field_details[9] as $key => $element) {
                        if ($element[2][0] == '*') {
                            $values['*'][$element[0]] = str_replace('*', '', $element[2]);
                        } else {
                            $values[0][$element[0]] = $element[2];
                        }
                    }
                    $group = '';
                    $group[] = $form->createElement('select', 'extra_' . $field_details[1], '', $values[0], '');
                    $group[] = $form->createElement('select', 'extra_' . $field_details[1] . '*', '', $values['*'], '');
                    $form->addGroup($group, 'extra_' . $field_details[1], $field_details[3], '&nbsp;');
                    if (!$admin_permissions) {
                        if ($field_details[7] == 0) {
                            $form->freeze('extra_' . $field_details[1]);
                        }
                    }
                    /* Recoding the selected values for double : if the user has
                       selected certain values, we have to assign them to the
                       correct select form */
                    if (array_key_exists('extra_' . $field_details[1], $extra_data)) {
                        // exploding all the selected values (of both select forms)
                        $selected_values = explode(';', $extra_data['extra_' . $field_details[1]]);
                        $extra_data['extra_' . $field_details[1]] = array();
                        // looping through the selected values and assigning the selected values to either the first or second select form
                        foreach ($selected_values as $key => $selected_value) {
                            if (array_key_exists($selected_value, $values[0])) {
                                $extra_data['extra_' . $field_details[1]]['extra_' . $field_details[1]] = $selected_value;
                            } else {
                                $extra_data['extra_' . $field_details[1]]['extra_' . $field_details[1] . '*'] = $selected_value;
                            }
                        }
                    }
                    break;
                case ExtraField::FIELD_TYPE_DIVIDER:
                    $form->addElement('static', $field_details[1], '<br /><strong>' . $field_details[3] . '</strong>');
                    break;
                case ExtraField::FIELD_TYPE_TAG:
                    //the magic should be here
                    $user_tags = UserManager::get_user_tags($user_id, $field_details[0]);
                    $tag_list = '';
                    if (is_array($user_tags) && count($user_tags) > 0) {
                        foreach ($user_tags as $tag) {
                            $tag_list .= '<option value="' . $tag['tag'] . '" class="selected">' . $tag['tag'] . '</option>';
                        }
                    }
                    $multi_select = '<select id="extra_' . $field_details[1] . '" name="extra_' . $field_details[1] . '">
                                    ' . $tag_list . '
                                    </select>';
                    $form->addElement('label', $field_details[3], $multi_select);
                    $url = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php';
                    $complete_text = get_lang('StartToType');
                    //if cache is set to true the jquery will be called 1 time
                    $jquery_ready_content = <<<EOF
                    \$("#extra_{$field_details['1']}").fcbkcomplete({
                        json_url: "{$url}?a=search_tags&field_id={$field_details['0']}",
                        cache: false,
                        filter_case: true,
                        filter_hide: true,
                        complete_text:"{$complete_text}",
                        firstselected: true,
                        //onremove: "testme",
                        //onselect: "testme",
                        filter_selected: true,
                        newel: true
                    });
EOF;
                    break;
                case ExtraField::FIELD_TYPE_TIMEZONE:
                    $form->addElement('select', 'extra_' . $field_details[1], $field_details[3], api_get_timezones(), '');
                    if ($field_details[7] == 0) {
                        $form->freeze('extra_' . $field_details[1]);
                    }
                    break;
                case ExtraField::FIELD_TYPE_SOCIAL_PROFILE:
                    // get the social network's favicon
                    $icon_path = UserManager::get_favicon_from_url($extra_data['extra_' . $field_details[1]], $field_details[4]);
                    // special hack for hi5
                    $leftpad = '1.7';
                    $top = '0.4';
                    $domain = parse_url($icon_path, PHP_URL_HOST);
                    if ($domain == 'www.hi5.com' or $domain == 'hi5.com') {
                        $leftpad = '3';
                        $top = '0';
                    }
                    // print the input field
                    $form->addElement('text', 'extra_' . $field_details[1], $field_details[3], array('size' => 60, 'style' => 'background-image: url(\'' . $icon_path . '\'); background-repeat: no-repeat; background-position: 0.4em ' . $top . 'em; padding-left: ' . $leftpad . 'em; '));
                    $form->applyFilter('extra_' . $field_details[1], 'stripslashes');
                    $form->applyFilter('extra_' . $field_details[1], 'trim');
                    if ($field_details[7] == 0) {
                        $form->freeze('extra_' . $field_details[1]);
                    }
                    break;
                case ExtraField::FIELD_TYPE_FILE:
                    $extra_field = 'extra_' . $field_details[1];
                    $form->addElement('file', $extra_field, $field_details[3], null, '');
                    if ($extra_file_list = UserManager::build_user_extra_file_list($user_id, $field_details[1], '', true)) {
                        $form->addElement('static', $extra_field . '_list', null, $extra_file_list);
                    }
                    if ($field_details[7] == 0) {
                        $form->freeze($extra_field);
                    }
                    break;
                case ExtraField::FIELD_TYPE_MOBILE_PHONE_NUMBER:
                    $form->addElement('text', 'extra_' . $field_details[1], $field_details[3] . " (" . get_lang('CountryDialCode') . ")", array('size' => 40, 'placeholder' => '(xx)xxxxxxxxx'));
                    $form->applyFilter('extra_' . $field_details[1], 'stripslashes');
                    $form->applyFilter('extra_' . $field_details[1], 'trim');
                    $form->applyFilter('extra_' . $field_details[1], 'mobile_phone_number_filter');
                    $form->addRule('extra_' . $field_details[1], get_lang('MobilePhoneNumberWrong'), 'mobile_phone_number');
                    if (!$admin_permissions) {
                        if ($field_details[7] == 0) {
                            $form->freeze('extra_' . $field_details[1]);
                        }
                    }
                    break;
            }
        }
        $return = array();
        $return['jquery_ready_content'] = $jquery_ready_content;
        return $return;
    }
Example #22
0
 */
$form = new FormValidator('profile', 'post', api_get_self() . "?" . str_replace('&fe=1', '', Security::remove_XSS($_SERVER['QUERY_STRING'])), null);
if (api_is_western_name_order()) {
    //    FIRST NAME and LAST NAME
    $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
    $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
} else {
    //    LAST NAME and FIRST NAME
    $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
    $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
}
$options = api_get_setting_in_list('profile.changeable_options', 'name');
if (!$options) {
    $form->freeze(array('lastname', 'firstname'));
}
$form->applyFilter(array('lastname', 'firstname'), 'stripslashes');
$form->applyFilter(array('lastname', 'firstname'), 'trim');
$form->applyFilter(array('lastname', 'firstname'), 'html_filter');
$form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
//    USERNAME
$form->addElement('text', 'username', get_lang('UserName'), array('id' => 'username', 'maxlength' => USERNAME_MAX_LENGTH, 'size' => USERNAME_MAX_LENGTH));
if (api_get_setting('profile.login_is_email') == 'true') {
    $options = api_get_setting_in_list('profile.changeable_options', 'login');
    if (!$options) {
        $form->freeze('username');
    }
}
$form->applyFilter('username', 'stripslashes');
$form->applyFilter('username', 'trim');
$form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
Example #23
0
    $form = new FormValidator(
        'profile',
        'post',
        api_get_self()."?".str_replace('&show_form=1', '&show_form=1', $_SERVER['QUERY_STRING']),
        null,
        array('style' => 'width: 75%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;'))
    );

    if (api_is_western_name_order()) {
        if ($list['firstname'] == 1) {
            //FIRST NAME
            $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
            if (api_get_setting('profile', 'name') !== 'true') {
                $form->freeze(array('firstname'));
            }
            $form->applyFilter(array('firstname'), 'stripslashes');
            $form->applyFilter(array('firstname'), 'trim');
            $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
        }
        if ($list['lastname'] == 1) {
            //    LAST NAME
            $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
            if (api_get_setting('profile', 'name') !== 'true') {
                $form->freeze(array('lastname'));
            }
            $form->applyFilter(array('lastname'), 'stripslashes');
            $form->applyFilter(array('lastname'), 'trim');
            $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
        }
    } else {
        if ($list['lastname'] == 1) {
/**
 * Display the search form for the forum and display the search results
 * @return void display an HTML search results
 * @author Patrick Cool <*****@*****.**>, Ghent University, Belgium
 * @version march 2008, dokeos 1.8.5
 */
function forum_search()
{
    // Initialize the object.
    $form = new FormValidator('forumsearch', 'post', 'forumsearch.php?' . api_get_cidreq());
    // Setting the form elements.
    $form->addElement('header', '', get_lang('ForumSearch'));
    $form->addElement('text', 'search_term', get_lang('SearchTerm'), array('autofocus'));
    $form->applyFilter('search_term', 'html_filter');
    $form->addElement('static', 'search_information', '', get_lang('ForumSearchInformation'));
    $form->addButtonSearch(get_lang('Search'));
    // Setting the rules.
    $form->addRule('search_term', get_lang('ThisFieldIsRequired'), 'required');
    $form->addRule('search_term', get_lang('TooShort'), 'minlength', 3);
    // Validation or display.
    if ($form->validate()) {
        $values = $form->exportValues();
        $form->setDefaults($values);
        $form->display();
        // Display the search results.
        display_forum_search_results(stripslashes($values['search_term']));
    } else {
        $form->display();
    }
}
Example #25
0
}
$param_gradebook = '';
if (isset($_SESSION['gradebook'])) {
    $param_gradebook = '&gradebook=' . Security::remove_XSS($_SESSION['gradebook']);
}
if (!$error) {
    $token = Security::get_token();
}
$attendance_weight = floatval($attendance_weight);
// display form
$form = new FormValidator('attendance_edit', 'POST', 'index.php?action=attendance_edit&' . api_get_cidreq() . '&attendance_id=' . $attendance_id . $param_gradebook);
$form->addElement('header', '', get_lang('Edit'));
$form->addElement('hidden', 'sec_token', $token);
$form->addElement('hidden', 'attendance_id', $attendance_id);
$form->add_textfield('title', get_lang('Title'), true, array('size' => '50'));
$form->applyFilter('title', 'html_filter');
$form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '100%', 'Height' => '200'));
// Adavanced Parameters
if (Gradebook::is_active()) {
    if (!empty($attendance_qualify_title) || !empty($attendance_weight)) {
        $form->addElement('advanced_settings', 'id_qualify', get_lang('AdvancedParameters'));
        $form->addElement('html', '<div id="id_qualify_options" style="display:block">');
        $form->addElement('checkbox', 'attendance_qualify_gradebook', '', get_lang('QualifyAttendanceGradebook'), array('checked' => 'true', 'onclick' => 'javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}'));
        $form->addElement('html', '<div id="options_field" style="display:block">');
    } else {
        $form->addElement('advanced_settings', 'id_qualify', get_lang('AdvancedParameters'));
        $form->addElement('html', '<div id="id_qualify_options" style="display:none">');
        $form->addElement('checkbox', 'attendance_qualify_gradebook', '', get_lang('QualifyAttendanceGradebook'), 'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"');
        $form->addElement('html', '<div id="options_field" style="display:none">');
    }
    load_gradebook_select_in_tool($form);
    /**
     * @param FormValidator $form
     * @param array $extraData
     * @param bool $admin_permissions
     * @param int $user_id
     * @param array $extra
     * @param int $itemId
     * @param array $exclude variables of extra field to exclude
     * @return array
     */
    public function set_extra_fields_in_form($form, $extraData, $admin_permissions = false, $extra = array(), $itemId = null, $exclude = [])
    {
        $type = $this->type;
        $jquery_ready_content = null;
        if (!empty($extra)) {
            foreach ($extra as $field_details) {
                // Getting default value id if is set
                $defaultValueId = null;
                if (isset($field_details['options']) && !empty($field_details['options'])) {
                    $valueToFind = null;
                    if (isset($field_details['field_default_value'])) {
                        $valueToFind = $field_details['field_default_value'];
                    }
                    // If a value is found we override the default value
                    if (isset($extraData['extra_' . $field_details['variable']])) {
                        $valueToFind = $extraData['extra_' . $field_details['variable']];
                    }
                    foreach ($field_details['options'] as $option) {
                        if ($option['option_value'] == $valueToFind) {
                            $defaultValueId = $option['id'];
                        }
                    }
                }
                if (!$admin_permissions) {
                    if ($field_details['visible'] == 0) {
                        continue;
                    }
                    if (in_array($field_details['variable'], $exclude)) {
                        continue;
                    }
                }
                switch ($field_details['field_type']) {
                    case ExtraField::FIELD_TYPE_TEXT:
                        $form->addElement('text', 'extra_' . $field_details['variable'], $field_details['display_text'], array());
                        $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes');
                        $form->applyFilter('extra_' . $field_details['variable'], 'trim');
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_TEXTAREA:
                        $form->addHtmlEditor('extra_' . $field_details['variable'], $field_details['display_text'], false, false, array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130'));
                        $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes');
                        $form->applyFilter('extra_' . $field_details['variable'], 'trim');
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_RADIO:
                        $group = array();
                        if (isset($field_details['options']) && !empty($field_details['options'])) {
                            foreach ($field_details['options'] as $option_details) {
                                $options[$option_details['option_value']] = $option_details['display_text'];
                                $group[] = $form->createElement('radio', 'extra_' . $field_details['variable'], $option_details['option_value'], $option_details['display_text'] . '<br />', $option_details['option_value']);
                            }
                        }
                        $form->addGroup($group, 'extra_' . $field_details['variable'], $field_details['display_text'], '');
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_CHECKBOX:
                        $group = array();
                        if (isset($field_details['options']) && !empty($field_details['options'])) {
                            foreach ($field_details['options'] as $option_details) {
                                $options[$option_details['option_value']] = $option_details['display_text'];
                                $group[] = $form->createElement('checkbox', 'extra_' . $field_details['variable'], $option_details['option_value'], $option_details['display_text'] . '<br />', $option_details['option_value']);
                            }
                        } else {
                            $fieldVariable = "extra_{$field_details['variable']}";
                            $checkboxAttributes = array();
                            if (is_array($extraData) && array_key_exists($fieldVariable, $extraData)) {
                                $checkboxAttributes['checked'] = true;
                            }
                            // We assume that is a switch on/off with 1 and 0 as values
                            $group[] = $form->createElement('checkbox', 'extra_' . $field_details['variable'], null, get_lang('Yes'), $checkboxAttributes);
                        }
                        $form->addGroup($group, 'extra_' . $field_details['variable'], $field_details['display_text'], '');
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_SELECT:
                        $get_lang_variables = false;
                        if (in_array($field_details['variable'], array('mail_notify_message', 'mail_notify_invitation', 'mail_notify_group_message'))) {
                            $get_lang_variables = true;
                        }
                        // Get extra field workflow
                        $userInfo = api_get_user_info();
                        $addOptions = array();
                        $optionsExists = false;
                        global $app;
                        // Check if exist $app['orm.em'] object
                        if (isset($app['orm.em']) && is_object($app['orm.em'])) {
                            $optionsExists = $app['orm.em']->getRepository('ChamiloLMS\\Entity\\ExtraFieldOptionRelFieldOption')->findOneBy(array('fieldId' => $field_details['id']));
                        }
                        if ($optionsExists) {
                            if (isset($userInfo['status']) && !empty($userInfo['status'])) {
                                $fieldWorkFlow = $app['orm.em']->getRepository('ChamiloLMS\\Entity\\ExtraFieldOptionRelFieldOption')->findBy(array('fieldId' => $field_details['id'], 'relatedFieldOptionId' => $defaultValueId, 'roleId' => $userInfo['status']));
                                foreach ($fieldWorkFlow as $item) {
                                    $addOptions[] = $item->getFieldOptionId();
                                }
                            }
                        }
                        $options = array();
                        if (empty($defaultValueId)) {
                            $options[''] = get_lang('SelectAnOption');
                        }
                        $optionList = array();
                        if (!empty($field_details['options'])) {
                            foreach ($field_details['options'] as $option_details) {
                                $optionList[$option_details['id']] = $option_details;
                                if ($get_lang_variables) {
                                    $options[$option_details['option_value']] = get_lang($option_details['display_text']);
                                } else {
                                    if ($optionsExists) {
                                        // Adding always the default value
                                        if ($option_details['id'] == $defaultValueId) {
                                            $options[$option_details['option_value']] = $option_details['display_text'];
                                        } else {
                                            if (isset($addOptions) && !empty($addOptions)) {
                                                // Parsing filters
                                                if (in_array($option_details['id'], $addOptions)) {
                                                    $options[$option_details['option_value']] = $option_details['display_text'];
                                                }
                                            }
                                        }
                                    } else {
                                        // Normal behaviour
                                        $options[$option_details['option_value']] = $option_details['display_text'];
                                    }
                                }
                            }
                            if (isset($optionList[$defaultValueId])) {
                                if (isset($optionList[$defaultValueId]['option_value']) && $optionList[$defaultValueId]['option_value'] == 'aprobada') {
                                    // @todo function don't exists api_is_question_manager
                                    /*if (api_is_question_manager() == false) {
                                          $form->freeze();
                                      }*/
                                }
                            }
                            // Setting priority message
                            if (isset($optionList[$defaultValueId]) && isset($optionList[$defaultValueId]['priority'])) {
                                if (!empty($optionList[$defaultValueId]['priority'])) {
                                    $priorityId = $optionList[$defaultValueId]['priority'];
                                    $option = new ExtraFieldOption($this->type);
                                    $messageType = $option->getPriorityMessageType($priorityId);
                                    $form->addElement('label', null, Display::return_message($optionList[$defaultValueId]['priority_message'], $messageType));
                                }
                            }
                        }
                        if ($get_lang_variables) {
                            $field_details['display_text'] = get_lang($field_details['display_text']);
                        }
                        // chzn-select doesn't work for sessions??
                        $form->addElement('select', 'extra_' . $field_details['variable'], $field_details['display_text'], $options, array('id' => 'extra_' . $field_details['variable']));
                        /* Enable this when field_loggeable is introduced as a table field (2.0)
                                                if ($optionsExists && $field_details['field_loggeable'] && !empty($defaultValueId)) {
                        
                                                    $form->addElement(
                                                        'textarea',
                                                        'extra_' . $field_details['variable'] . '_comment',
                                                        $field_details['display_text'] . ' ' . get_lang('Comment')
                                                    );
                        
                                                    $extraFieldValue = new ExtraFieldValue($this->type);
                                                    $repo = $app['orm.em']->getRepository($extraFieldValue->entityName);
                                                    $repoLog = $app['orm.em']->getRepository('Gedmo\Loggable\Entity\LogEntry');
                                                    $newEntity = $repo->findOneBy(
                                                        array(
                                                            $this->handlerEntityId => $itemId,
                                                            'fieldId' => $field_details['id']
                                                        )
                                                    );
                                                    // @todo move this in a function inside the class
                                                    if ($newEntity) {
                                                        $logs = $repoLog->getLogEntries($newEntity);
                                                        if (!empty($logs)) {
                                                            $html = '<b>' . get_lang('LatestChanges') . '</b><br /><br />';
                        
                                                            $table = new HTML_Table(array('class' => 'data_table'));
                                                            $table->setHeaderContents(0, 0, get_lang('Value'));
                                                            $table->setHeaderContents(0, 1, get_lang('Comment'));
                                                            $table->setHeaderContents(0, 2, get_lang('ModifyDate'));
                                                            $table->setHeaderContents(0, 3, get_lang('Username'));
                                                            $row = 1;
                                                            foreach ($logs as $log) {
                                                                $column = 0;
                                                                $data = $log->getData();
                                                                $fieldValue = isset($data['fieldValue']) ? $data['fieldValue'] : null;
                                                                $comment = isset($data['comment']) ? $data['comment'] : null;
                        
                                                                $table->setCellContents($row, $column, $fieldValue);
                                                                $column++;
                                                                $table->setCellContents($row, $column, $comment);
                                                                $column++;
                                                                $table->setCellContents($row, $column, api_get_local_time($log->getLoggedAt()->format('Y-m-d H:i:s')));
                                                                $column++;
                                                                $table->setCellContents($row, $column, $log->getUsername());
                                                                $row++;
                                                            }
                                                            $form->addElement('label', null, $html.$table->toHtml());
                                                        }
                                                    }
                                                }
                                                */
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_SELECT_MULTIPLE:
                        $options = array();
                        foreach ($field_details['options'] as $option_id => $option_details) {
                            $options[$option_details['option_value']] = $option_details['display_text'];
                        }
                        $form->addElement('select', 'extra_' . $field_details['variable'], $field_details['display_text'], $options, array('multiple' => 'multiple'));
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_DATE:
                        $form->addDatePicker('extra_' . $field_details['variable'], $field_details['display_text']);
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        $form->applyFilter('theme', 'trim');
                        break;
                    case ExtraField::FIELD_TYPE_DATETIME:
                        $form->addDateTimePicker('extra_' . $field_details['variable'], $field_details['display_text']);
                        $defaults['extra_' . $field_details['variable']] = api_get_local_time();
                        if (!isset($form->_defaultValues['extra_' . $field_details['variable']])) {
                            $form->setDefaults($defaults);
                        }
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        $form->applyFilter('theme', 'trim');
                        break;
                    case ExtraField::FIELD_TYPE_DOUBLE_SELECT:
                        $first_select_id = 'first_extra_' . $field_details['variable'];
                        $url = api_get_path(WEB_AJAX_PATH) . 'extra_field.ajax.php?1=1';
                        $jquery_ready_content .= '
                        $("#' . $first_select_id . '").on("change", function() {
                            var id = $(this).val();
                            if (id) {
                                $.ajax({
                                    url: "' . $url . '&a=get_second_select_options",
                                    dataType: "json",
                                    data: "type=' . $type . '&field_id=' . $field_details['id'] . '&option_value_id="+id,
                                    success: function(data) {
                                        $("#second_extra_' . $field_details['variable'] . '").empty();
                                        $.each(data, function(index, value) {
                                            $("#second_extra_' . $field_details['variable'] . '").append($("<option/>", {
                                                value: index,
                                                text: value
                                            }));
                                        });
                                    },
                                });
                            } else {
                                $("#second_extra_' . $field_details['variable'] . '").empty();
                            }
                        });';
                        $first_id = null;
                        $second_id = null;
                        if (!empty($extraData)) {
                            $first_id = $extraData['extra_' . $field_details['variable']]['extra_' . $field_details['variable']];
                            $second_id = $extraData['extra_' . $field_details['variable']]['extra_' . $field_details['variable'] . '_second'];
                        }
                        $options = ExtraField::extra_field_double_select_convert_array_to_ordered_array($field_details['options']);
                        $values = array('' => get_lang('Select'));
                        $second_values = array();
                        if (!empty($options)) {
                            foreach ($options as $option) {
                                foreach ($option as $sub_option) {
                                    if ($sub_option['option_value'] == '0') {
                                        $values[$sub_option['id']] = $sub_option['display_text'];
                                    } else {
                                        if ($first_id === $sub_option['option_value']) {
                                            $second_values[$sub_option['id']] = $sub_option['display_text'];
                                        }
                                    }
                                }
                            }
                        }
                        $group = array();
                        $group[] = $form->createElement('select', 'extra_' . $field_details['variable'], null, $values, array('id' => $first_select_id));
                        $group[] = $form->createElement('select', 'extra_' . $field_details['variable'] . '_second', null, $second_values, array('id' => 'second_extra_' . $field_details['variable']));
                        $form->addGroup($group, 'extra_' . $field_details['variable'], $field_details['display_text'], '&nbsp;');
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_DIVIDER:
                        $form->addElement('static', $field_details['variable'], '<br /><strong>' . $field_details['display_text'] . '</strong>');
                        break;
                    case ExtraField::FIELD_TYPE_TAG:
                        $variable = $field_details['variable'];
                        $field_id = $field_details['id'];
                        //Added for correctly translate the extra_field
                        $get_lang_variables = false;
                        if (in_array($variable, ['tags'])) {
                            $get_lang_variables = true;
                        }
                        if ($get_lang_variables) {
                            $field_details['display_text'] = get_lang($field_details['display_text']);
                        }
                        $tagsSelect = $form->addSelect("extra_{$field_details['variable']}", $field_details['display_text']);
                        $tagsSelect->setAttribute('class', null);
                        $tagsSelect->setAttribute('id', "extra_{$field_details['variable']}");
                        $tagsSelect->setMultiple(true);
                        if ($this->type == 'user') {
                            /* //the magic should be here
                                                        $user_tags = UserManager::get_user_tags($user_id, $field_details[0]);
                            
                                                        $tag_list = '';
                                                        if (is_array($user_tags) && count($user_tags) > 0) {
                                                            foreach ($user_tags as $tag) {
                                                                $tag_list .= '<option value="'.$tag['tag'].'" class="selected">'.$tag['tag'].'</option>';
                                                            }
                                                        }
                            
                                                        $multi_select = '<select id="extra_'.$field_details[1].'" name="extra_'.$field_details[1].'">
                                                                '.$tag_list.'
                                                                </select>';
                            
                                                        $form->addElement('label', $field_details[3], $multi_select);
                                                        $url = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php';
                                                        $complete_text = get_lang('StartToType');
                                                        //if cache is set to true the jquery will be called 1 time
                                                        $jquery_ready_content = <<<EOF
                                                $("#extra_$field_details[1]").fcbkcomplete({
                                                    json_url: "$url?a=search_tags&field_id=$field_details[0]",
                                                    cache: false,
                                                    filter_case: true,
                                                    filter_hide: true,
                                                    complete_text:"$complete_text",
                                                    firstselected: true,
                                                    //onremove: "testme",
                                                    //onselect: "testme",
                                                    filter_selected: true,
                                                    newel: true
                                                });
                            EOF;
                                                        break;*/
                            // The magic should be here
                            $user_tags = UserManager::get_user_tags($itemId, $field_details['id']);
                            if (is_array($user_tags) && count($user_tags) > 0) {
                                foreach ($user_tags as $tag) {
                                    $tagsSelect->addOption($tag['tag'], $tag['tag'], ['selected' => 'selected', 'class' => 'selected']);
                                }
                            }
                            $url = api_get_path(WEB_AJAX_PATH) . 'user_manager.ajax.php';
                        } else {
                            $em = Database::getManager();
                            $fieldTags = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag')->findBy(['fieldId' => $field_id, 'itemId' => $itemId]);
                            foreach ($fieldTags as $fieldTag) {
                                $tag = $em->find('ChamiloCoreBundle:Tag', $fieldTag->getTagId());
                                if (empty($tag)) {
                                    continue;
                                }
                                $tagsSelect->addOption($tag->getTag(), $tag->getTag(), ['selected' => 'selected', 'class' => 'selected']);
                            }
                            $url = api_get_path(WEB_AJAX_PATH) . 'extra_field.ajax.php';
                        }
                        $complete_text = get_lang('StartToType');
                        //if cache is set to true the jquery will be called 1 time
                        $jquery_ready_content .= <<<EOF
                    \$("#extra_{$variable}").fcbkcomplete({
                        json_url: "{$url}?a=search_tags&field_id={$field_id}&type={$this->type}",
                        cache: false,
                        filter_case: true,
                        filter_hide: true,
                        complete_text:"{$complete_text}",
                        firstselected: false,
                        filter_selected: true,
                        newel: true
                    });
EOF;
                        break;
                    case ExtraField::FIELD_TYPE_TIMEZONE:
                        $form->addElement('select', 'extra_' . $field_details['variable'], $field_details['display_text'], api_get_timezones(), '');
                        if ($field_details['visible'] == 0) {
                            $form->freeze('extra_' . $field_details['variable']);
                        }
                        break;
                    case ExtraField::FIELD_TYPE_SOCIAL_PROFILE:
                        // get the social network's favicon
                        $extra_data_variable = isset($extraData['extra_' . $field_details['variable']]) ? $extraData['extra_' . $field_details['variable']] : null;
                        $field_default_value = isset($field_details['field_default_value']) ? $field_details['field_default_value'] : null;
                        $icon_path = UserManager::get_favicon_from_url($extra_data_variable, $field_default_value);
                        // special hack for hi5
                        $leftpad = '1.7';
                        $top = '0.4';
                        $domain = parse_url($icon_path, PHP_URL_HOST);
                        if ($domain == 'www.hi5.com' or $domain == 'hi5.com') {
                            $leftpad = '3';
                            $top = '0';
                        }
                        // print the input field
                        $form->addElement('text', 'extra_' . $field_details['variable'], $field_details['display_text'], array('size' => 60, 'style' => 'background-image: url(\'' . $icon_path . '\'); background-repeat: no-repeat; background-position: 0.4em ' . $top . 'em; padding-left: ' . $leftpad . 'em; '));
                        $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes');
                        $form->applyFilter('extra_' . $field_details['variable'], 'trim');
                        if ($field_details['visible'] == 0) {
                            $form->freeze('extra_' . $field_details['variable']);
                        }
                        break;
                    case ExtraField::FIELD_TYPE_MOBILE_PHONE_NUMBER:
                        $form->addElement('text', 'extra_' . $field_details[1], $field_details[3] . " (" . get_lang('CountryDialCode') . ")", array('size' => 40, 'placeholder' => '(xx)xxxxxxxxx'));
                        $form->applyFilter('extra_' . $field_details[1], 'stripslashes');
                        $form->applyFilter('extra_' . $field_details[1], 'trim');
                        $form->applyFilter('extra_' . $field_details[1], 'mobile_phone_number_filter');
                        $form->addRule('extra_' . $field_details[1], get_lang('MobilePhoneNumberWrong'), 'mobile_phone_number');
                        if ($field_details['visible'] == 0) {
                            $form->freeze('extra_' . $field_details['variable']);
                        }
                        break;
                    case ExtraField::FIELD_TYPE_INTEGER:
                        $form->addElement('number', 'extra_' . $field_details['variable'], $field_details['display_text'], array('class' => 'span1', 'step' => 1));
                        $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes');
                        $form->applyFilter('extra_' . $field_details['variable'], 'trim');
                        $form->applyFilter('extra_' . $field_details['variable'], 'intval');
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_FILE_IMAGE:
                        $fieldVariable = "extra_{$field_details['variable']}";
                        $fieldTexts = array($field_details['display_text']);
                        if (is_array($extraData) && array_key_exists($fieldVariable, $extraData)) {
                            if (file_exists(api_get_path(SYS_UPLOAD_PATH) . $extraData[$fieldVariable])) {
                                $fieldTexts[] = Display::img(api_get_path(WEB_UPLOAD_PATH) . $extraData[$fieldVariable], $field_details['display_text'], array('width' => '300'));
                            }
                        }
                        $form->addElement('file', $fieldVariable, $fieldTexts, array('accept' => 'image/*'));
                        $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes');
                        $form->applyFilter('extra_' . $field_details['variable'], 'trim');
                        $allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif');
                        $form->addRule('extra_' . $field_details['variable'], get_lang('OnlyImagesAllowed') . ' (' . implode(',', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types);
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_FLOAT:
                        $form->addElement('number', 'extra_' . $field_details['variable'], $field_details['display_text'], array('class' => 'span1', 'step' => '0.01'));
                        $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes');
                        $form->applyFilter('extra_' . $field_details['variable'], 'trim');
                        $form->applyFilter('extra_' . $field_details['variable'], 'floatval');
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_FILE:
                        $fieldVariable = "extra_{$field_details['variable']}";
                        $fieldTexts = array($field_details['display_text']);
                        if (is_array($extraData) && array_key_exists($fieldVariable, $extraData)) {
                            if (file_exists(api_get_path(SYS_UPLOAD_PATH) . $extraData[$fieldVariable])) {
                                $fieldTexts[] = Display::url(api_get_path(WEB_UPLOAD_PATH) . $extraData[$fieldVariable], api_get_path(WEB_UPLOAD_PATH) . $extraData[$fieldVariable], array('title' => $field_details['display_text'], 'target' => '_blank'));
                            }
                        }
                        $form->addElement('file', $fieldVariable, $fieldTexts, array());
                        $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes');
                        $form->applyFilter('extra_' . $field_details['variable'], 'trim');
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_VIDEO_URL:
                        //Added for correctly translate the extra_field
                        $get_lang_variables = false;
                        if (in_array($field_details['variable'], ['video_url'])) {
                            $get_lang_variables = true;
                        }
                        if ($get_lang_variables) {
                            $field_details['display_text'] = get_lang($field_details['display_text']);
                        }
                        $form->addUrl("extra_{$field_details['variable']}", $field_details['display_text'], false, ['placeholder' => 'https://']);
                        break;
                    case ExtraField::FIELD_TYPE_LETTERS_ONLY:
                        $form->addTextLettersOnly("extra_{$field_details['variable']}", $field_details['display_text']);
                        $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes');
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_ALPHANUMERIC:
                        $form->addTextAlphanumeric("extra_{$field_details['variable']}", $field_details['display_text']);
                        $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes');
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_LETTERS_SPACE:
                        $form->addTextLettersAndSpaces("extra_{$field_details['variable']}", $field_details['display_text']);
                        $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes');
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        break;
                    case ExtraField::FIELD_TYPE_ALPHANUMERIC_SPACE:
                        $form->addTextAlphanumericAndSpaces("extra_{$field_details['variable']}", $field_details['display_text']);
                        $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes');
                        if (!$admin_permissions) {
                            if ($field_details['visible'] == 0) {
                                $form->freeze('extra_' . $field_details['variable']);
                            }
                        }
                        break;
                }
            }
        }
        $return = array();
        $return['jquery_ready_content'] = $jquery_ready_content;
        return $return;
    }
Example #27
0
 /**
  * Returns the form to update or create a document
  *
  * @param	string	Action (add/edit)
  * @param	integer	ID of the lp_item (if already exists)
  * @param	mixed	Integer if document ID, string if info ('new')
  * @return	string	HTML form
  */
 function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
 {
     global $charset, $_course;
     require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
     require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
     $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
     $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
     $path_parts = pathinfo($extra_info['dir']);
     $no_display_edit_textarea = false;
     //If action==edit document
     //We don't display the document form if it's not an editable document (html or txt file)
     if ($action == "edit") {
         if (is_array($extra_info)) {
             if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
                 $no_display_edit_textarea = true;
             }
         }
     }
     $no_display_add = false;
     //If action==add an existing document
     //We don't display the document form if it's not an editable document (html or txt file)
     if ($action == "add") {
         if (is_numeric($extra_info)) {
             $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database::escape_string($extra_info);
             $result = Database::query($sql_doc, __FILE__, __LINE__);
             $path_file = Database::result($result, 0, 0);
             $path_parts = pathinfo($path_file);
             if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
                 $no_display_add = true;
             }
         }
     }
     // create css folder
     $css_name = api_get_setting('stylesheets');
     $perm = api_get_setting('permissions_for_new_directories');
     $perm = octdec(!empty($perm) ? $perm : '0770');
     $css_folder = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/css';
     if (!is_dir($css_folder)) {
         mkdir($css_folder);
         chmod($css_folder, $perm);
         $doc_id = add_document($_course, '/css', 'folder', 0, 'css');
         api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id']);
         api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id']);
     }
     if (!file_exists($css_folder . '/templates.css')) {
         if (file_exists(api_get_path(SYS_PATH) . 'main/css/' . $css_name . '/templates.css')) {
             $template_content = str_replace('../../img/', api_get_path(REL_CODE_PATH) . 'img/', file_get_contents(api_get_path(SYS_PATH) . 'main/css/' . $css_name . '/templates.css'));
             $template_content = str_replace('images/', api_get_path(REL_CODE_PATH) . 'css/' . $css_name . '/images/', $template_content);
             file_put_contents($css_folder . '/templates.css', $template_content);
         }
     }
     if ($action == 'add' && (isset($_GET['tplid']) && $_GET['tplid'] >= 0)) {
         $table_sys_template = Database::get_main_table(TABLE_MAIN_SYSTEM_TEMPLATE);
         $user_id = api_get_user_id();
         // Session used by the ajax request when we are using php 5.3
         $_SESSION['dbName'] = $_course['dbName'];
         // setting some paths
         $img_dir = api_get_path(REL_CODE_PATH) . 'img/';
         $default_course_dir = api_get_path(REL_CODE_PATH) . 'default_course_document/';
         if (!isset($_GET['resource'])) {
             // Load a template into a document
             $query = 'SELECT content, title FROM ' . $table_sys_template . ' WHERE id=' . Database::escape_string(Security::remove_XSS($_GET['tplid']));
             $result = Database::query($query, __FILE__, __LINE__);
             $obj = Database::fetch_object($result);
             $valcontent = $obj->content;
             $valtitle = $obj->title != '' ? get_lang($obj->title) : get_lang('Empty');
             if (isset($_GET['tplid']) && $_GET['tplid'] == 0) {
                 $valcontent = '<head>{CSS}<style type="text/css">.text{font-weight: normal;}</style></head><body></body>';
             }
             $template_css = '';
             if (strpos($valcontent, '/css/templates.css') === false) {
                 $template_css = '<link rel="stylesheet" href="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/css/templates.css" type="text/css" />';
             }
             $js = '';
             if (strpos($valcontent, 'javascript/jquery.highlight.js') === false) {
                 $js .= '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery-1.4.2.min.js" language="javascript"></script>';
                 $js .= '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'jwplayer/jwplayer.js" language="javascript"></script>' . PHP_EOL;
                 if (api_get_setting('show_glossary_in_documents') != 'none') {
                     $js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery.highlight.js"></script>';
                     if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
                         $js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/glossary/fck_glossary_manual.js"></script>';
                     } else {
                         $js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"></script>';
                     }
                 }
             }
             $valcontent = str_replace('{CSS}', $template_css . $js, $valcontent);
             if (strpos($valcontent, '/css/templates.css') === false) {
                 $valcontent = str_replace('</head>', $template_css . '</head>', $valcontent);
             }
             if (strpos($valcontent, 'javascript/jquery.highlight.js') === false) {
                 $valcontent = str_replace('</head>', $js . '</head>', $valcontent);
             }
             $valcontent = str_replace('{IMG_DIR}', $img_dir, $valcontent);
             $valcontent = str_replace('{REL_PATH}', api_get_path(REL_PATH), $valcontent);
             $valcontent = str_replace('{COURSE_DIR}', $default_course_dir, $valcontent);
         } elseif (isset($_GET['resource']) && $_GET['resource'] == 'mindmap' || $_GET['resource'] == 'video') {
             // Load a mindmap or video into a document
             $propTable = Database::get_course_table(TABLE_ITEM_PROPERTY);
             $curdirpath = '/mindmaps/';
             if ($_GET['resource'] == 'video') {
                 $curdirpath = '/video/';
                 $curdirpath_flv = '/video/flv/';
             }
             $my_course = api_get_course_id();
             $src_path = api_get_path(WEB_COURSE_PATH) . $my_course . '/document';
             $sql = "SELECT path,title FROM {$tbl_doc} doc,{$propTable} prop WHERE doc.id = prop.ref AND prop.tool = '" . TOOL_DOCUMENT . "'\n      AND doc.filetype = 'file' AND (doc.path LIKE '" . $curdirpath . "%' OR doc.path LIKE '" . $curdirpath_flv . "%') AND (doc.path NOT LIKE '" . $curdirpath . "%/%' OR doc.path NOT LIKE '" . $curdirpath_flv . "%/%')\n      AND prop.visibility = 1 AND doc.id = '" . Database::escape_string(Security::remove_XSS($_GET['tplid'])) . "'";
             $rs = Database::query($sql);
             $row = Database::fetch_array($rs);
             $resource = $src_path . $row['path'];
             $valtitle = $row['title'];
             if ($valtitle != '') {
                 $search = array('.png', '.gif', '.jpg', '.mpg', '.flv', '.swf');
                 // Add other extensions
                 $replace = array('', '', '', '', '', '');
                 $valtitle = str_replace($search, $replace, $valtitle);
             }
             if ($_GET['resource'] == 'mindmap') {
                 $valcontent = '<table cellspacing="2" cellpadding="10" border="0" style="width: 95%; height: 500px;">
           <tbody>
               <tr>
                   <td valign="top"><img border="0" vspace="0" hspace="0" src="' . $resource . '" alt="' . $title . '" title="' . $title . '"/></td>
               </tr>
           </tbody>
       </table>';
             } elseif ($_GET['resource'] == 'video') {
                 $sys_resource = api_get_path(SYS_COURSE_PATH) . $my_course . '/document' . $row['path'];
                 $resource_info = pathinfo($sys_resource);
                 //$video_web_path = api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/flvPlayer/';
                 $valcontent = '<table cellspacing="2" cellpadding="10" border="0" style="width: 95%; height: 500px;">
                                   <tbody>
                                       <tr>
                                          <td valign="top">                     
                                          <!-- Video player plugin -->
                                             <div id="player986311-parent" align="left">
                                             <div style="border-style: none; height: 240px; width: 375px; overflow: hidden; background-color: rgb(220, 220, 220);" id="test">
                                             <div style="display: none; visibility: hidden; width: 0px; height: 0px; overflow: hidden;" id="player986311-config">url=' . $resource . ' width=375 height=240 loop=1 play=true downloadable=false fullscreen=true</div>
                                                 <div class="thePlayer" id="player986311">';
                 if (in_array($resource_info['extension'], array('flv', 'mp4', 'mov'))) {
                     /*if (!api_is_windows_os()) {
                           $valcontent .= '   <script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/plugins/videoPlayer/jwplayer.min.js" type="text/javascript"></script>
                                               <object id="player986311-parent2" name="player986311-parent2" width="375" height="240" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
                                               <param name="movie" value="'.api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/plugins/videoPlayer/player.swf" />
                                               <param name="allowFullScreen" value="true" />
                                               <param name="allowscriptaccess" value="always" />
                                               <param name="seamlesstabbing" value="true" />
                                               <param name="wmode" value="transparent" />
                                               <param name="flashvars" value="id=player986311-parent2&autostart=true&repeat=false&file='.$resource.'&skin='.api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/plugins/videoPlayer/skins/facebook.zip&controlbar.position=over"  />                
                                               </object>
                                          ';                                                          
                       } else {*/
                     $valcontent .= '           
                             <script src="' . api_get_path(WEB_CODE_PATH) . 'inc/lib/fckeditor/editor/plugins/videoPlayer/jwplayer.min.js" type="text/javascript"></script>
                             <div id="player986311-parent2">Loading the player ...</div>
                             <script type="text/javascript">jwplayer("player986311-parent2").setup({flashplayer: "' . api_get_path(WEB_CODE_PATH) . 'inc/lib/fckeditor/editor/plugins/videoPlayer/player.swf",autostart: "true",repeat: "always",file: "' . $resource . '",height: 240,width: 375,skin: "' . api_get_path(WEB_CODE_PATH) . 'inc/lib/fckeditor/editor/plugins/videoPlayer/skins/facebook.zip"});</script>';
                     //}
                 } else {
                     $sType = '';
                     if ($resource_info['extension'] == 'mpg' || $resource_info['extension'] == 'mpeg') {
                         $sType = 'video/mpeg';
                     } else {
                         if ($resource_info['extension'] == 'avi' || $resource_info['extension'] == 'wmv' || $resource_info['extension'] == 'asf') {
                             $sType = 'video/x-msvideo';
                         }
                     }
                     $valcontent .= '<embed type="' . $sType . '" src="' . $resource . '"
                            autosize = "false"
                            autostart = "true"
                            loop = "false"
                            fullscreen = "true"
                            showcontrols = "true"
                            showpositioncontrols = "false"
                            showtracker = "true"
                            showaudiocontrols = "true"
                            showgotobar = "true"
                            showstatusbar = "true"
                            pluginspace = "http://www.microsoft.com/Windows/MediaPlayer/"
                            codebase = "http://www.microsoft.com/Windows/MediaPlayer/"';
                     $valcontent .= 'width="375px" height="240px"';
                     $valcontent .= '></embed>';
                 }
                 $valcontent .= '              </div>
                                              </div>
                                           </div> 
                                         </td>
                                       </tr>
                                   </tbody>
                               </table>';
             }
         }
     }
     if ($id != 0 && is_array($extra_info)) {
         $item_title = stripslashes($extra_info['title']);
         $item_description = stripslashes($extra_info['description']);
         $item_terms = stripslashes($extra_info['terms']);
         if (empty($item_title)) {
             $path_parts = pathinfo($extra_info['path']);
             $item_title = stripslashes($path_parts['filename']);
         }
     } elseif (is_numeric($extra_info)) {
         $sql_doc = "SELECT path, title\n\t\t\t\t\t\t\t\t\tFROM " . $tbl_doc . "\n\t\t\t\t\t\t\t\t\tWHERE id = " . Database::escape_string($extra_info);
         $result = Database::query($sql_doc, __FILE__, __LINE__);
         $row = Database::fetch_array($result);
         $explode = explode('.', $row['title']);
         if (count($explode) > 1) {
             for ($i = 0; $i < count($explode) - 1; $i++) {
                 $item_title .= $explode[$i];
             }
         } else {
             $item_title = $row['title'];
         }
         $item_title = str_replace('_', ' ', $item_title);
         if (empty($item_title)) {
             $path_parts = pathinfo($row['path']);
             $item_title = stripslashes($path_parts['filename']);
         }
     } else {
         $item_title = '';
         $item_description = '';
     }
     /* $return = '	<div class="row">
        <div class="form_header">'; */
     if ($id != 0 && is_array($extra_info)) {
         $parent = $extra_info['parent_item_id'];
     } else {
         $parent = 0;
     }
     $sql = "\n\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\tFROM " . $tbl_lp_item . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tlp_id = " . $this->lp_id;
     $result = Database::query($sql, __FILE__, __LINE__);
     $arrLP = array();
     while ($row = Database::fetch_array($result)) {
         $arrLP[] = array('id' => $row['id'], 'item_type' => $row['item_type'], 'title' => $row['title'], 'path' => $row['path'], 'description' => $row['description'], 'parent_item_id' => $row['parent_item_id'], 'previous_item_id' => $row['previous_item_id'], 'next_item_id' => $row['next_item_id'], 'display_order' => $row['display_order'], 'max_score' => $row['max_score'], 'min_score' => $row['min_score'], 'mastery_score' => $row['mastery_score'], 'prerequisite' => $row['prerequisite']);
     }
     $this->tree_array($arrLP);
     $arrLP = $this->arrMenu;
     unset($this->arrMenu);
     if (isset($_GET['edit']) && $_GET['edit'] == 'true') {
         $return .= Display::return_warning_message('<strong>' . get_lang("Warning") . ' !</strong><br />' . get_lang("WarningEditingDocument"), false);
     }
     require_once api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php';
     $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"], '', 'enctype="multipart/form-data"');
     $defaults["title"] = Security::remove_XSS(api_convert_encoding($item_title, api_get_system_encoding(), $this->encoding));
     if (empty($item_title)) {
         $defaults["title"] = Security::remove_XSS($item_title);
     }
     $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
     $form->addElement('html', $return);
     if ($action != 'move') {
         $form->addElement('html', '<div style="float:left;padding-right:135px;">');
         $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
         $form->applyFilter('title', 'html_filter');
         $form->addElement('html', '</div>');
     }
     //$arrHide = array($id);
     $arrHide[0]['value'] = $this->name;
     $arrHide[0]['padding'] = 3;
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($action != 'add') {
             if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                 $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
                 if ($parent == $arrLP[$i]['id']) {
                     $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                 }
             }
         } else {
             if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                 $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
                 if ($parent == $arrLP[$i]['id']) {
                     $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                 }
             }
         }
     }
     //$parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" style="width:40%;" onchange="load_cbo(this.value);"');
     $parent_select =& $form->addElement('select', 'parent', '', '', 'class="learnpath_item_form" style="width:40%;display:none;float:left" onchange="load_cbo(this.value);"');
     $my_count = 0;
     foreach ($arrHide as $key => $value) {
         if ($my_count != 0) {
             // the LP name is also the first section and is not in the same charset like the other sections
             $value['value'] = Security::remove_XSS(api_convert_encoding($value['value'], api_get_system_encoding(), $this->encoding));
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         } else {
             $value['value'] = Security::remove_XSS($value['value']);
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         }
         $my_count++;
     }
     if (!empty($id)) {
         $parent_select->setSelected($parent);
     } else {
         $parent_item_id = $_SESSION['parent_item_id'];
         $parent_select->setSelected($parent_item_id);
     }
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     $arrHide = array();
     //POSITION
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
             if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                 $s_selected_position = $arrLP[$i]['id'];
             } elseif ($action == 'add') {
                 $s_selected_position = $arrLP[$i]['id'];
             }
             $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"';
         }
     }
     //$position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
     $position =& $form->addElement('select', 'previous', '', '', 'id="idPosition" class="learnpath_item_form" style="width:40%;float:left;display:none;"');
     $position->addOption(get_lang("FirstPosition"), 0);
     foreach ($arrHide as $key => $value) {
         $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
     }
     $position->setSelected($s_selected_position);
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     if ($action != 'move') {
         $id_prerequisite = 0;
         if (is_array($arrLP)) {
             foreach ($arrLP as $key => $value) {
                 if ($value['id'] == $id) {
                     $id_prerequisite = $value['prerequisite'];
                     break;
                 }
             }
         }
         //comented the prerequisites, only visible in edit (new document)
         //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
         //$select_prerequisites->addOption(get_lang("NoPrerequisites"),0);
         // form element for uploading an mp3 file
         //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
         //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
         /* Code deprecated - moved to lp level (not lp-item)
             if ( api_get_setting('search_enabled') === 'true' )
             {
             //add terms field
             $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').'&nbsp;:','id="idTerms" class="learnpath_item_form"');
             $terms->setValue($item_terms);
             }
            */
         $arrHide = array();
         for ($i = 0; $i < count($arrLP); $i++) {
             if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
                 if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                     $s_selected_position = $arrLP[$i]['id'];
                 } elseif ($action == 'add') {
                     $s_selected_position = $arrLP[$i]['id'];
                 }
                 $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
             }
         }
         /* 	foreach($arrHide as $key => $value){
              $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
              if($key==$s_selected_position && $action == 'add'){
              $select_prerequisites -> setSelected(0);
              }
              elseif($key==$id_prerequisite && $action == 'edit'){
              $select_prerequisites -> setSelected($id_prerequisite);
              }
              }
             */
         if (!$no_display_add) {
             if ($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true') {
                 if (isset($_POST['content'])) {
                     $content = stripslashes($_POST['content']);
                 } elseif (is_array($extra_info)) {
                     //If it's an html document or a text file
                     if (!$no_display_edit_textarea) {
                         $content = $this->display_document($extra_info['path'], false, false);
                     }
                 } elseif (is_numeric($extra_info)) {
                     $content = $this->display_document($extra_info, false, false);
                 } else {
                     $content = '';
                 }
                 if (!$no_display_edit_textarea) {
                     // We need to claculate here some specific settings for the online editor.
                     // The calculated settings work for documents in the Documents tool
                     // (on the root or in subfolders).
                     // For documents in native scorm packages it is unclear whether the
                     // online editor should be activated or not.
                     $relative_path = $extra_info['dir'];
                     if ($relative_path == 'n/') {
                         // A new document, it is in the root of the repository.
                         $relative_path = '';
                         $relative_prefix = '';
                     } else {
                         // The document already exists. Whe have to determine its relative path towards the repository root.
                         $relative_path = explode('/', $relative_path);
                         $cnt = count($relative_path) - 2;
                         if ($cnt < 0) {
                             $cnt = 0;
                         }
                         $relative_prefix = str_repeat('../', $cnt);
                         $relative_path = array_slice($relative_path, 1, $cnt);
                         $relative_path = implode('/', $relative_path);
                         if (strlen($relative_path) > 0) {
                             $relative_path = $relative_path . '/';
                         }
                     }
                     $editor_config = array('ToolbarSet' => api_is_allowed_to_edit() ? 'Documents' : 'DocumentsStudent', 'Width' => '100%', 'Height' => '700', 'FullPage' => true, 'CreateDocumentDir' => $relative_prefix, 'CreateDocumentWebDir' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/', 'BaseHref' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/' . $relative_path);
                     if ($_GET['action'] == 'add_item') {
                         $class = 'save';
                         $text = get_lang('Validate');
                     } else {
                         if ($_GET['action'] == 'edit_item') {
                             $class = 'save';
                             $text = get_lang('SaveDocument');
                         }
                     }
                     $form->addElement('html', '<div style="float:right;margin-top:-55px">');
                     $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
                     $form->addElement('html', '</div>');
                     $renderer = $form->defaultRenderer();
                     $renderer->setElementTemplate('{label}{element}', 'content_lp');
                     //$form->addElement('html', '<div');
                     $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
                     //$form->addElement('html', '</div>');
                     $defaults["content_lp"] = $content;
                 }
             } elseif (is_numeric($extra_info)) {
                 $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
                 $return = $this->display_document($extra_info, true, true, true);
                 $form->addElement('html', $return);
             }
         }
     }
     // Add template to content
     if ($action == 'add' && (isset($_GET['tplid']) && $_GET['tplid'] >= 0)) {
         $defaults["content_lp"] = $valcontent;
         $defaults["title"] = $valtitle;
     }
     if ($action == 'move') {
         $form->addElement('hidden', 'title', $item_title);
         $form->addElement('hidden', 'description', $item_description);
     }
     if (is_numeric($extra_info)) {
         $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save" style="float:right"');
         $form->addElement('hidden', 'path', $extra_info);
     } elseif (is_array($extra_info)) {
         $form->addElement('html', '<div style="float:right;margin-top:-55px">');
         $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
         $form->addElement('hidden', 'path', $extra_info['path']);
         $form->addElement('html', '</div>');
     }
     $form->addElement('hidden', 'type', TOOL_DOCUMENT);
     $form->addElement('hidden', 'post_time', time());
     $form->setDefaults($defaults);
     return $form->return_form();
 }
 // Retrieve request's data from the corresponding database record.
 $course_request_info = CourseRequestManager::get_course_request_info($id);
 if (!is_array($course_request_info)) {
     // Prepare an error message notifying that the course request has not been found or does not exist.
     $message = get_lang('CourseRequestHasNotBeenFound');
     $is_error_message = true;
 } else {
     // Ensure the database prefix + database name do not get over 40 characters.
     $maxlength = 40;
     // Build the form.
     $form = new FormValidator('add_course', 'post', 'course_request_edit.php?id=' . $id . '&caller=' . $caller);
     // Form title.
     $form->addElement('header', $tool_name);
     // Title.
     $form->addElement('text', 'title', get_lang('CourseName'), array('size' => '60', 'id' => 'title'));
     $form->applyFilter('title', 'html_filter');
     $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
     // Course category.
     $url = api_get_path(WEB_AJAX_PATH) . 'course.ajax.php?a=search_category';
     $courseSelect = $form->addElement('select_ajax', 'category_code', get_lang('CourseFaculty'), null, array('url' => $url));
     if (!empty($course_request_info['category_code'])) {
         $data = CourseCategory::getCategory($course_request_info['category_code']);
         $courseSelect->addOption($data['name'], $data['code'], ['selected' => 'selected']);
     }
     // Course code.
     $form->addText('wanted_code', get_lang('Code'), false, array('size' => '$maxlength', 'maxlength' => $maxlength));
     $form->applyFilter('wanted_code', 'html_filter');
     $form->addRule('wanted_code', get_lang('Max'), 'maxlength', $maxlength);
     $form->addRule('wanted_code', get_lang('ThisFieldIsRequired'), 'required');
     // The teacher.
     $titular = $form->addText('tutor_name', get_lang('Professor'), null, array('size' => '60', 'disabled' => 'disabled'));
Example #29
0
    if(document.getElementById(\'end_date_div\').style.display == \'none\') {
        document.getElementById(\'end_date_div\').style.display = \'block\';
    } else {
        document.getElementById(\'end_date_div\').style.display = \'none\';
    }
}

</script>';
$gradebook = isset($_GET['gradebook']) ? Security::remove_XSS($_GET['gradebook']) : null;
$defaults = array();
$form = new FormValidator('form1', 'post', 'lp_controller.php');
// Form title
$form->addElement('header', get_lang('EditLPSettings'));
// Title
$form->addElement('text', 'lp_name', api_ucfirst(get_lang('LearnpathTitle')), array('class' => 'span5'));
$form->applyFilter('lp_name', 'html_filter');
$form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('hidden', 'lp_encoding');
$referer = isset($_REQUEST['referer']) ? Security::remove_XSS($_REQUEST['referer']) : null;
$form->addElement('hidden', 'referer', $referer);
$items = learnpath::get_category_from_course_into_select(api_get_course_int_id(), true);
$form->addElement('select', 'category_id', get_lang('Category'), $items);
//Hide toc frame
$hide_toc_frame = $form->addElement('checkbox', 'hide_toc_frame', null, get_lang('HideTocFrame'), array('onclick' => '$("#lp_layout_column").toggle()'));
if (api_get_setting('allow_course_theme') == 'true') {
    $mycourselptheme = api_get_course_setting('allow_learning_path_theme');
    if (!empty($mycourselptheme) && $mycourselptheme != -1 && $mycourselptheme == 1) {
        //LP theme picker
        $theme_select = $form->addElement('select_theme', 'lp_theme', get_lang('Theme'));
        $form->applyFilter('lp_theme', 'trim');
        $s_theme = $_SESSION['oLP']->get_theme();
/**
 * Display the search form for the forum and display the search results
 * @return void display an HTML search results
 * @author Patrick Cool <*****@*****.**>, Ghent University, Belgium
 * @version march 2008, dokeos 1.8.5
 */
function forum_search()
{
    global $origin;
    // Initialize the object.
    $form = new FormValidator('forumsearch', 'post', 'forumsearch.php?origin=' . $origin . '');
    // Settting the form elements.
    $form->addElement('header', '', get_lang('ForumSearch'));
    $form->addElement('text', 'search_term', get_lang('SearchTerm'), 'class="input_titles" id="search_title"');
    $form->applyFilter('search_term', 'html_filter');
    $form->addElement('static', 'search_information', '', get_lang('ForumSearchInformation'));
    $form->addElement('style_submit_button', null, get_lang('Search'), 'class="search"');
    // Setting the rules.
    $form->addRule('search_term', get_lang('ThisFieldIsRequired'), 'required');
    $form->addRule('search_term', get_lang('TooShort'), 'minlength', 3);
    // Validation or display.
    if ($form->validate()) {
        $values = $form->exportValues();
        $form->setDefaults($values);
        $form->display();
        // Display the search results.
        display_forum_search_results(stripslashes($values['search_term']));
    } else {
        $form->display();
    }
}