Adding a js function called maxCharForTextarea() in the main portal, merging 4 forms into 1 form in the usergroup.lib.php

skala
Julio Montoya 13 years ago
parent 66787b0858
commit 793e515e02
  1. 38
      main/admin/usergroups.php
  2. 29
      main/inc/ajax/model.ajax.php
  3. 2
      main/inc/lib/display.lib.php
  4. 100
      main/inc/lib/usergroup.lib.php
  5. 57
      main/social/group_add.php
  6. 68
      main/social/group_edit.php
  7. 13
      main/template/default/layout/footer.tpl

@ -45,10 +45,10 @@ if (isset($_GET['action']) && $_GET['action'] == 'editnote') {
//jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups';
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups';
//The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array(get_lang('Name'), get_lang('Users'), get_lang('Courses'), get_lang('Sessions'), get_lang('Actions'));
$columns = array(get_lang('Name'), get_lang('Users'), get_lang('Courses'), get_lang('Sessions'), get_lang('Type'), get_lang('Actions'));
//Column config
$column_model = array(
@ -57,6 +57,7 @@ $column_model = array(
array('name'=>'users', 'index'=>'users', 'width'=>'15', 'align'=>'left'),
array('name'=>'courses', 'index'=>'courses', 'width'=>'15', 'align'=>'left'),
array('name'=>'sessions', 'index'=>'sessions', 'width'=>'15', 'align'=>'left'),
array('name'=>'group_type', 'index'=>'group_type', 'width'=>'15', 'align'=>'left'),
array('name'=>'actions', 'index'=>'actions', 'width'=>'20', 'align'=>'left','sortable'=>'false','formatter'=>'action_formatter'),
);
//Autowidth
@ -98,20 +99,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'add') {
// Initiate the object
$form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
// Settting the form elements
$form->addElement('header', get_lang('Add'));
$form->addElement('text', 'name', get_lang('name'), array('size' => '70', 'id' => 'name'));
//$form->applyFilter('note_title', 'html_filter');
$form->add_html_editor('description', get_lang('Description'), false, false, array('Width' => '95%', 'Height' => '250'));
//$form->addElement('text', 'url', 'URL');
$form->addElement('checkbox', 'group_type', null, get_lang('SocialGroup'));
$form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="add"');
// Setting the rules
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
$usergroup->setForm($form, 'add');
// The validation or display
if ($form->validate()) {
@ -137,23 +125,17 @@ if (isset($_GET['action']) && $_GET['action'] == 'add') {
}// Action handling: Edition
elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) {
// Initialize the object
$form = new FormValidator('career', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.Security::remove_XSS($_GET['id']));
// Settting the form elements
$form->addElement('header', '', get_lang('Modify'));
$form->addElement('hidden', 'id',intval($_GET['id']));
$form->addElement('text', 'name', get_lang('Name'), array('size' => '70'));
$form->add_html_editor('description', get_lang('Description'), false, false, array('Width' => '95%', 'Height' => '250'));
$form->addElement('checkbox', 'group_type', null, get_lang('SocialGroup'));
$form = new FormValidator('usergroup', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.Security::remove_XSS($_GET['id']));
$defaults = $usergroup->get($_GET['id']);
$usergroup->setForm($form, 'edit', $defaults);
$form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');
// Setting the form elements
$form->addElement('hidden', 'id', intval($_GET['id']));
// Setting the defaults
$defaults = $usergroup->get($_GET['id']);
$form->setDefaults($defaults);
// Setting the rules
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
// The validation or display
if ($form->validate()) {
$check = Security::check_token('post');

@ -32,19 +32,20 @@ if (!in_array($sord, array('asc','desc'))) {
}
if (!in_array($action, array(
'get_exercise_results',
'get_hotpotatoes_exercise_results',
'get_work_user_list',
'get_timelines',
'get_user_skill_ranking',
'get_usergroups_teacher'))
'get_exercise_results',
'get_hotpotatoes_exercise_results',
'get_work_user_list',
'get_timelines',
'get_user_skill_ranking',
'get_usergroups_teacher'
))
) {
api_protect_admin_script(true);
}
//Search features
$ops = array (
$ops = array(
'eq' => '=', //equal
'ne' => '<>', //not equal
'lt' => '<', //less than
@ -523,7 +524,7 @@ switch ($action) {
$result = $new_result;
break;
case 'get_usergroups':
$columns = array('name', 'users', 'courses', 'sessions', 'actions');
$columns = array('name', 'users', 'courses', 'sessions', 'group_type', 'actions');
$result = Database::select('*', $obj->table, array('order'=>"name $sord", 'LIMIT'=> "$start , $limit"));
$new_result = array();
if (!empty($result)) {
@ -531,11 +532,19 @@ switch ($action) {
$group['sessions'] = count($obj->get_sessions_by_usergroup($group['id']));
$group['courses'] = count($obj->get_courses_by_usergroup($group['id']));
$group['users'] = count($obj->get_users_by_usergroup($group['id']));
$new_result[] = $group;
switch($group['group_type']) {
case '0':
$group['group_type'] = Display::label(get_lang('Class'), 'info');
break;
case '1' :
$group['group_type'] = Display::label(get_lang('Social'), 'success');
break;
}
$new_result[] = $group;
}
$result = $new_result;
}
$columns = array('name', 'users', 'courses','sessions');
$columns = array('name', 'users', 'courses','sessions', 'group_type');
if(!in_array($sidx, $columns)) {
$sidx = 'name';
}

@ -37,7 +37,7 @@ class Display
$app['classic_layout'] = true;
if ($app['allowed'] == true) {
ob_start(array($app['template'], 'manage_display'));
ob_start(array($app['template'], 'manage_display'));
} else {
$app->run();
exit;

@ -251,7 +251,7 @@ class UserGroup extends Model
}
}
//Addding new relationships
//Adding new relationships
if (!empty($new_items)) {
foreach ($new_items as $session_id) {
$params = array('session_id' => $session_id, 'usergroup_id' => $usergroup_id);
@ -409,15 +409,48 @@ class UserGroup extends Model
function save($values) {
$values['updated_on'] = $values['created_on'] = api_get_utc_datetime();
$values['group_type'] = isset($values['group_type']) ? intval($values['group_type']) : self::NORMAL_CLASS;
return parent::save($values);
$groupId = parent::save($values);
if ($groupId) {
$this->add_user_to_group(api_get_user_id(), $groupId, $values['visibility']);
$picture = isset($_FILES['picture']) ? $_FILES['picture'] : null;
$this->manageFileUpload($groupId, $picture);
}
return $groupId;
}
function manageFileUpload($groupId, $picture) {
if (!empty($picture['name'])) {
return $this->update_group_picture($groupId, $picture['name'], $picture['tmp_name']);
}
return false;
}
function update($values) {
$values['updated_on'] = api_get_utc_datetime();
$values['group_type'] = isset($values['group_type']) ? intval($values['group_type']) : self::NORMAL_CLASS;
if (isset($values['id'])) {
$picture = isset($_FILES['picture']) ? $_FILES['picture'] : null;
if (!empty($picture)) {
$picture = $this->manageFileUpload($values['id'], $picture);
if ($picture) {
$values['picture'] = $picture;
}
}
if (isset($values['delete_picture'])) {
$values['picture'] = null;
}
}
parent::update($values);
if (isset($values['delete_picture'])) {
$this->delete_group_picture($values['id']);
}
}
/**
@ -429,9 +462,9 @@ class UserGroup extends Model
* If an empty name is provided, then old user photos are deleted only, @see UserManager::delete_user_picture() as the prefered way for deletion.
* @param string $source_file The full system name of the image from which user photos will be created.
* @return string/bool Returns the resulting common file name of created images which usually should be stored in database.
* When deletion is recuested returns empty string. In case of internal error or negative validation returns FALSE.
* When an image is removed the function returns an empty string. In case of internal error or negative validation it returns FALSE.
*/
public function update_group_picture($group_id, $file = null, $source_file = null) {
public function update_group_picture($group_id, $file = null, $source_file = null) {
// Validation 1.
if (empty($group_id)) {
@ -446,7 +479,6 @@ class UserGroup extends Model
$path_info = self::get_group_picture_path_by_id($group_id, 'system', true);
$path = $path_info['dir'];
var_dump($path);
// If this directory does not exist - we create it.
if (!file_exists($path)) {
@ -511,6 +543,8 @@ class UserGroup extends Model
$image->getSize()->widen( 700 )
);*/
//Usign the Imagine service
$image = $app['imagine']->open($source_file);
$image->resize(new Imagine\Image\Box(200, 200))->save($path.'big_'.$filename);
@ -547,7 +581,7 @@ class UserGroup extends Model
* @param bool If we want that the function returns the /main/img/unknown.jpg image set it at true
* @return array Array of 2 elements: 'dir' and 'file' which contain the dir and file as the name implies if image does not exist it will return the unknow image if anonymous parameter is true if not it returns an empty er's
*/
public function get_group_picture_path_by_id($id, $type = 'none', $preview = false, $anonymous = false) {
public function get_group_picture_path_by_id($id, $type = 'none', $preview = false, $anonymous = false) {
switch ($type) {
case 'system': // Base: absolute system path.
@ -1153,12 +1187,10 @@ class UserGroup extends Model
return $return;
}
public function delete_group_picture($group_id) {
return self::update_group_picture($group_id);
}
public function is_group_admin($group_id, $user_id = 0) {
if (empty($user_id)) {
$user_id = api_get_user_id();
@ -1374,9 +1406,57 @@ class UserGroup extends Model
return $status;
}
public function setForm($form) {
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('class'=>'span5', 'maxlength'=>120));
$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('class'=>'span5', 'cols'=>58, 'onKeyDown' => "maxCharForTextarea(this);", 'onKeyUp' => "maxCharForTextarea(this);"));
$form->applyFilter('description', 'html_filter');
$form->applyFilter('description', 'trim');
$form->addElement('checkbox', 'group_type', null, get_lang('SocialGroup'));
// url
$form->addElement('text', 'url', get_lang('URL'), array('class'=>'span5'));
$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>');
$form->addElement('style_submit_button', 'submit', $header, 'class="add"');
}
public function getAllowedPictureExtensions() {
return $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
}
}

@ -8,7 +8,7 @@
* Initialization
*/
$language_file= 'userInfo';
$cidReset=true;
$cidReset = true;
require_once '../inc/global.inc.php';
api_block_anonymous_users();
@ -20,69 +20,16 @@ if (api_get_setting('allow_students_to_create_groups_in_social') == 'false' && !
api_not_allowed();
}
$htmlHeadXtra[] = '<script>
textarea = "";
num_characters_permited = 255;
function text_longitud(){
num_characters = document.forms[0].description.value.length;
if (num_characters > num_characters_permited){
document.forms[0].description.value = textarea;
} else {
textarea = document.forms[0].description.value;
}
}
</script>';
$table_message = Database::get_main_table(TABLE_MESSAGE);
$usergroup = new UserGroup();
$form = new FormValidator('add_group');
// name
$form->addElement('text', 'name', get_lang('Name'), array('class'=>'span5', '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('class'=>'span5', '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('class'=>'span5'));
$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);
// Status
$form->addElement('select', 'visibility', get_lang('GroupPermissions'), $usergroup->getGroupStatusList());
$form->addElement('style_submit_button','add_group', get_lang('AddGroup'),'class="save"');
$form->setRequiredNote(api_xml_http_response_encode('<span class="form_required">*</span> <small>'.get_lang('ThisFieldIsRequired').'</small>'));
$usergroup->setForm($form, 'add');
if ($form->validate()) {
$values = $form->exportValues();
$picture_element = $form->getElement('picture');
$picture = $picture_element->getValue();
$status = intval($values['visibility']);
$picture = $_FILES['picture'];
$values['type'] = $usergroup::SOCIAL_CLASS;
$groupId = $usergroup->save($values);
if ($groupId) {
$usergroup->add_user_to_group(api_get_user_id(), $groupId, $values['visibility']);
if (!empty($picture['name'])) {
$picture = $usergroup->update_group_picture($groupId, $_FILES['picture']['name'], $_FILES['picture']['tmp_name']);
$params = array('id' => $groupId, 'picture' => $picture);
$usergroup->update($params);
}
}
header('Location: groups.php?id='.$groupId.'&action=show_message&message='.urlencode(get_lang('GroupAdded')));
exit();
}

@ -19,19 +19,6 @@ if (api_get_setting('allow_social_tool') != 'true') {
$this_section = SECTION_SOCIAL;
$htmlHeadXtra[] = '<script>
var textarea = "";
var num_characters_permited = 255;
function textarea_maxlength(){
num_characters = document.forms[0].description.value.length;
if (num_characters > num_characters_permited){
document.forms[0].description.value = textarea;
}else{
textarea = document.forms[0].description.value;
}
}
</script>';
$group_id = isset($_GET['id']) ? intval($_GET['id']) : intval($_POST['id']);
$tool_name = get_lang('GroupEdit');
@ -55,47 +42,7 @@ if (!$usergroup->is_group_admin($group_id)) {
$form = new FormValidator('group_edit', 'post', '', '');
$form->addElement('hidden', 'id', $group_id);
// name
$form->addElement('text', 'name', get_lang('Name'), array('class' => 'span5', '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('class' => 'span5', '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', get_lang('URL'), array('class' => 'span5'));
$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 (strlen($group_data['picture']) > 0) {
$form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
}
//Status
$form->addElement('select', 'visibility', get_lang('GroupPermissions'), $usergroup->getGroupStatusList(), array());
// Submit button
$form->addElement('style_submit_button', 'submit', get_lang('ModifyInformation'), 'class="save"');
$usergroup->setForm($form, 'edit', $group_data);
// Set default values
$form->setDefaults($group_data);
@ -103,19 +50,6 @@ $form->setDefaults($group_data);
// Validate form
if ($form->validate()) {
$group = $form->exportValues();
$picture_element = $form->getElement('picture');
$picture = $picture_element->getValue();
$picture_uri = $group_data['picture'];
if ($group['delete_picture']) {
$picture_uri = $usergroup->delete_group_picture($group_id);
} elseif (!empty($picture['name'])) {
$picture_uri = $usergroup->update_group_picture(
$group_id,
$_FILES['picture']['name'],
$_FILES['picture']['tmp_name']
);
}
$group['id'] = $group_id;
$usergroup->update($group);
$tok = Security::get_token();

@ -87,6 +87,18 @@ jQuery.fn.filterByText = function(textbox) {
});
};
var textarea = "";
var max_char = 255;
function maxCharForTextarea(obj) {
num_characters = obj.value.length;
if (num_characters > max_char){
obj.value = textarea;
} else {
textarea = obj.value;
}
}
/* Makes row highlighting possible */
$(document).ready( function() {
//Chosen select
@ -126,7 +138,6 @@ $(document).ready( function() {
placement : 'right'
}
$('.boot-tooltip').tooltip(tip_options);
});
</script>
{% endraw %}

Loading…
Cancel
Save