');
$group = array();
$group[] = $form->createElement('radio', 'students_can_edit', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'students_can_edit', null, get_lang('No'), 0);
$form->addGroup($group, 'students_can_edit_group', get_lang('StudentsCanEdit'), ' ');
$group = array();
$group[] = $form->createElement('radio', 'approval_direct', null, get_lang('Approval'), 1);
$group[] = $form->createElement('radio', 'approval_direct', null, get_lang('Direct'), 0);
$group = array();
$group[] = $form->createElement('radio', 'allow_attachments', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'allow_attachments', null, get_lang('No'), 0);
$group = array();
$group[] = $form->createElement('radio', 'allow_new_threads', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'allow_new_threads', null, get_lang('No'), 0);
$form->addGroup($group, 'allow_new_threads_group', get_lang('AllowNewThreads'), ' ');
$group = array();
$group[] = $form->createElement('radio', 'default_view_type', null, get_lang('Flat'), 'flat');
$group[] = $form->createElement('radio', 'default_view_type', null, get_lang('Threaded'), 'threaded');
$group[] = $form->createElement('radio', 'default_view_type', null, get_lang('Nested'), 'nested');
$form->addGroup($group, 'default_view_type_group', get_lang('DefaultViewType'), ' ');
// Drop down list: Groups
$groups = GroupManager::get_group_list();
$groups_titles[0] = get_lang('NotAGroupForum');
foreach ($groups as $key => $value) {
$groups_titles[$value['id']] = $value['name'];
}
$form->addElement('select', 'group_forum', get_lang('ForGroup'), $groups_titles);
// Public or private group forum
$group = array();
$group[] = $form->createElement('radio', 'public_private_group_forum', null, get_lang('Public'), 'public');
$group[] = $form->createElement('radio', 'public_private_group_forum', null, get_lang('Private'), 'private');
$form->addGroup($group, 'public_private_group_forum_group', get_lang('PublicPrivateGroupForum'), '');
// Forum image
$form->add_progress_bar();
if (isset($inputvalues['forum_image']) && strlen($inputvalues['forum_image']) > 0) {
$image_path = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/forum/images/'.$inputvalues['forum_image'];
$image_size = api_getimagesize($image_path);
$img_attributes = '';
if (!empty($image_size)) {
if ($image_size['width'] > 100 || $image_size['height'] > 100) {
//limit display width and height to 100px
$img_attributes = 'width="100" height="100"';
}
$show_preview_image = '
';
$form->addElement('label', get_lang('PreviewImage'), $show_preview_image);
$form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
}
}
$forum_image = isset($inputvalues['forum_image']) ? $inputvalues['forum_image'] : '';
$form->addElement('file', 'picture', ($forum_image != '' ? get_lang('UpdateImage') : get_lang('AddImage')));
$form->addRule('picture', get_lang('OnlyImagesAllowed'), 'filetype', array('jpg', 'jpeg', 'png', 'gif'));
$form->addElement('html', '
');
// The OK button
if (isset($_GET['id']) && $_GET['action'] == 'edit') {
$form->addButtonUpdate(get_lang('ModifyForum'), 'SubmitForum');
} else {
$form->addButtonCreate(get_lang('CreateForum'), 'SubmitForum');
}
// setting the rules
$form->addRule('forum_title', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('forum_category', get_lang('ThisFieldIsRequired'), 'required');
$defaultSettingAllowNewThreads = api_get_default_tool_setting('forum', 'allow_new_threads', 0);
// Settings the defaults
if (empty($inputvalues) || !is_array($inputvalues)) {
$defaults['allow_anonymous_group']['allow_anonymous'] = 0;
$defaults['students_can_edit_group']['students_can_edit'] = 0;
$defaults['approval_direct_group']['approval_direct'] = 0;
$defaults['allow_attachments_group']['allow_attachments'] = 1;
$defaults['allow_new_threads_group']['allow_new_threads'] = $defaultSettingAllowNewThreads;
$defaults['default_view_type_group']['default_view_type'] = api_get_setting('default_forum_view');
$defaults['public_private_group_forum_group']['public_private_group_forum'] = 'public';
if (isset($_GET['forumcategory'])) {
$defaults['forum_category'] = Security::remove_XSS($_GET['forumcategory']);
}
} else { // the default values when editing = the data in the table
$defaults['forum_id'] = isset($inputvalues['forum_id']) ? $inputvalues['forum_id'] : null;
$defaults['forum_title'] = prepare4display(isset($inputvalues['forum_title']) ? $inputvalues['forum_title'] : null);
$defaults['forum_comment'] = prepare4display(isset($inputvalues['forum_comment']) ? $inputvalues['forum_comment'] : null);
$defaults['forum_category'] = isset($inputvalues['forum_category']) ? $inputvalues['forum_category'] : null;
$defaults['allow_anonymous_group']['allow_anonymous'] = isset($inputvalues['allow_anonymous']) ? $inputvalues['allow_anonymous'] : null;
$defaults['students_can_edit_group']['students_can_edit'] = isset($inputvalues['allow_edit']) ? $inputvalues['allow_edit'] : null;
$defaults['approval_direct_group']['approval_direct'] = isset($inputvalues['approval_direct_post']) ? $inputvalues['approval_direct_post'] : null;
$defaults['allow_attachments_group']['allow_attachments'] = isset($inputvalues['allow_attachments']) ? $inputvalues['allow_attachments'] : null;
$defaults['allow_new_threads_group']['allow_new_threads'] = isset($inputvalues['allow_new_threads']) ? $inputvalues['allow_new_threads'] : $defaultSettingAllowNewThreads;
$defaults['default_view_type_group']['default_view_type'] = isset($inputvalues['default_view']) ? $inputvalues['default_view'] : null;
$defaults['public_private_group_forum_group']['public_private_group_forum'] = isset($inputvalues['forum_group_public_private']) ? $inputvalues['forum_group_public_private'] : null;
$defaults['group_forum'] = isset($inputvalues['forum_of_group']) ? $inputvalues['forum_of_group'] : null;
}
$form->setDefaults($defaults);
// Validation or display
if ($form->validate()) {
$check = Security::check_token('post');
if ($check) {
$values = $form->exportValues();
$return_message = store_forum($values);
Display :: display_confirmation_message($return_message);
}
Security::clear_token();
} else {
$token = Security::get_token();
$form->addElement('hidden', 'sec_token');
$form->setConstants(array('sec_token' => $token));
$form->display();
}
}
/**
* This function deletes the forum image if exists
*
* @param int forum id
* @return boolean true if success
* @author Julio Montoya