Group tutor can add events see BT#4284

skala
Julio Montoya 14 years ago
parent 6c91506111
commit aac7a6db0b
  1. 62
      main/calendar/agenda.lib.php
  2. 4
      main/calendar/agenda.php
  3. 69
      main/calendar/agenda_js.php
  4. 50
      main/group/group_edit.php
  5. 55
      main/group/group_space.php
  6. 18
      main/inc/ajax/agenda.ajax.php
  7. 120
      main/inc/lib/groupmanager.lib.php
  8. 6
      main/inc/lib/main_api.lib.php
  9. 8
      main/template/default/agenda/month.tpl

@ -71,8 +71,7 @@ class Agenda {
$attributes['all_day'] = $all_day; $attributes['all_day'] = $all_day;
$id = Database::insert($this->tbl_personal_agenda, $attributes); $id = Database::insert($this->tbl_personal_agenda, $attributes);
break; break;
case 'course': case 'course':
//$attributes['user'] = api_get_user_id();
$attributes['title'] = $title; $attributes['title'] = $title;
$attributes['content'] = $content; $attributes['content'] = $content;
$attributes['start_date'] = $start; $attributes['start_date'] = $start;
@ -84,27 +83,27 @@ class Agenda {
//simple course event //simple course event
$id = Database::insert($this->tbl_course_agenda, $attributes); $id = Database::insert($this->tbl_course_agenda, $attributes);
if ($id) { if ($id) {
//api_item_property_update($this->course, TOOL_CALENDAR_EVENT, $id, "AgendaAdded", api_get_user_id(), '','',$start, $end); $group_id = api_get_group_id();
$group_id = api_get_group_id();
if ((!is_null($users_to_send)) or (!empty($group_id))) { if ((!is_null($users_to_send)) or (!empty($group_id))) {
$send_to = self::separate_users_groups($users_to_send); $send_to = self::separate_users_groups($users_to_send);
if (isset($send_to['everyone']) && $send_to['everyone']) { if (isset($send_to['everyone']) && $send_to['everyone']) {
api_item_property_update($this->course, TOOL_CALENDAR_EVENT, $id,"AgendaAdded", api_get_user_id(), '','',$start,$end); api_item_property_update($this->course, TOOL_CALENDAR_EVENT, $id,"AgendaAdded", api_get_user_id(), $group_id ,'', $start, $end);
} else { } else {
// storing the selected groups // storing the selected groups
if (is_array($send_to['groups'])) { if (is_array($send_to['groups'])) {
foreach ($send_to['groups'] as $group) { foreach ($send_to['groups'] as $group) {
api_item_property_update($this->course, TOOL_CALENDAR_EVENT, $id, "AgendaAdded", api_get_user_id(), $group,0,$start, $end); api_item_property_update($this->course, TOOL_CALENDAR_EVENT, $id, "AgendaAdded", api_get_user_id(), $group,0, $start, $end);
} }
} }
// storing the selected users // storing the selected users
if (is_array($send_to['users'])) { if (is_array($send_to['users'])) {
foreach ($send_to['users'] as $my_user_id) { foreach ($send_to['users'] as $to_user_id) {
api_item_property_update($this->course, TOOL_CALENDAR_EVENT, $id, "AgendaAdded", api_get_user_id(), 0, $my_user_id, $start,$end); api_item_property_update($this->course, TOOL_CALENDAR_EVENT, $id, "AgendaAdded", api_get_user_id(), $group_id, $to_user_id, $start, $end);
} }
} }
} }
@ -113,8 +112,7 @@ class Agenda {
if (isset($add_as_announcement) && !empty($add_as_announcement)) { if (isset($add_as_announcement) && !empty($add_as_announcement)) {
self::store_agenda_item_as_announcement($id); self::store_agenda_item_as_announcement($id);
} }
} }
break; break;
case 'admin': case 'admin':
$attributes['title'] = $title; $attributes['title'] = $title;
@ -261,7 +259,7 @@ class Agenda {
* @param int course id *integer* not the course code * @param int course id *integer* not the course code
* *
*/ */
function get_events($start, $end, $user_id, $course_id = null, $group_id = null) { function get_events($start, $end, $course_id = null, $group_id = null) {
switch ($this->type) { switch ($this->type) {
case 'admin': case 'admin':
@ -424,6 +422,7 @@ class Agenda {
WHERE date >= '".$start."' AND (enddate <='".$end."' OR enddate IS NULL) AND user = $user_id"; WHERE date >= '".$start."' AND (enddate <='".$end."' OR enddate IS NULL) AND user = $user_id";
$result = Database::query($sql); $result = Database::query($sql);
$my_events = array();
if (Database::num_rows($result)) { if (Database::num_rows($result)) {
while ($row = Database::fetch_array($result, 'ASSOC')) { while ($row = Database::fetch_array($result, 'ASSOC')) {
$event = array(); $event = array();
@ -454,9 +453,8 @@ class Agenda {
function get_course_events($start, $end, $course_info, $group_id = 0) { function get_course_events($start, $end, $course_info, $group_id = 0) {
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
$group_list = GroupManager::get_group_list(null, $course_info['code']);
$group_list = GroupManager::get_group_list(null, $course_info['code']);
$group_name_list = array(); $group_name_list = array();
if (!empty($group_list)) { if (!empty($group_list)) {
@ -470,7 +468,7 @@ class Agenda {
} else { } else {
$group_memberships = array_keys($group_name_list); $group_memberships = array_keys($group_name_list);
} }
$tlb_course_agenda = Database::get_course_table(TABLE_AGENDA); $tlb_course_agenda = Database::get_course_table(TABLE_AGENDA);
$tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY); $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
@ -479,8 +477,8 @@ class Agenda {
if (!empty($group_id)) { if (!empty($group_id)) {
$group_memberships = array($group_id); $group_memberships = array($group_id);
} }
if (is_array($group_memberships) && count($group_memberships) >0) { if (is_array($group_memberships) && count($group_memberships) > 0) {
if (api_is_allowed_to_edit()) { if (api_is_allowed_to_edit()) {
$where_condition = "( ip.to_group_id is null OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) "; $where_condition = "( ip.to_group_id is null OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) ";
} else { } else {
@ -705,25 +703,25 @@ class Agenda {
* @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University * @author: Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @return html code * @return html code
*/ */
function construct_not_selected_select_form($group_list=null, $user_list=null,$to_already_selected=array()) { function construct_not_selected_select_form($group_list = null, $user_list = null, $to_already_selected = array()) {
$html = '<select id="users_to_send_id" data-placeholder="'.get_lang('Select').'" name="users_to_send[]" multiple="multiple" style="width:250px" class="chzn-select">'; $html = '<select id="users_to_send_id" data-placeholder="'.get_lang('Select').'" name="users_to_send[]" multiple="multiple" style="width:250px" class="chzn-select">';
// adding the groups to the select form // adding the groups to the select form
if (isset($to_already_selected) && $to_already_selected==='everyone') { if (isset($to_already_selected) && $to_already_selected==='everyone') {
} }
$html .= '<option value="everyone">'.get_lang('Everyone').'</option>'; $html .= '<option value="everyone">'.get_lang('Everyone').'</option>';
if (is_array($group_list)) { if (is_array($group_list)) {
$html .= '<optgroup label="'.get_lang('Groups').'">'; $html .= '<optgroup label="'.get_lang('Groups').'">';
foreach($group_list as $this_group) { foreach ($group_list as $this_group) {
//api_display_normal_message("group " . $thisGroup[id] . $thisGroup[name]); if (!is_array($to_already_selected) || !in_array("GROUP:".$this_group['id'], $to_already_selected)) {
if (!is_array($to_already_selected) || !in_array("GROUP:".$this_group['id'],$to_already_selected)) {
// $to_already_selected is the array containing the groups (and users) that are already selected // $to_already_selected is the array containing the groups (and users) that are already selected
$html .= "<option value=\"GROUP:".$this_group['id']."\">". $count_users = isset($this_group['count_users']) ? $this_group['count_users'] : $this_group['userNb'];
$this_group['name']." &ndash; " . $this_group['userNb'] . " " . get_lang('Users') . $count_users = " &ndash; $count_users ".get_lang('Users');
"</option>";
$html .= '<option value="GROUP:'.$this_group['id'].'"> '.$this_group['name'].$count_users.'</option>';
//$html .= "<option value=\"GROUP:".$this_group['id']."\"> ".$this_group['name']." ".get_lang('Users')."</option>";
} }
} }
$html .= '</optgroup>'; $html .= '</optgroup>';

@ -26,10 +26,10 @@ $action = isset($_GET['action']) ? $_GET['action'] : null;
$origin = isset($_GET['origin']) ? $_GET['origin'] : null; $origin = isset($_GET['origin']) ? $_GET['origin'] : null;
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
if (empty($action)) { if (empty($action)) {
header('Location: agenda_js.php?type=course'); $url = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=course';
header("Location: $url");
exit; exit;
} }

@ -37,19 +37,41 @@ if (api_is_platform_admin() && $type == 'admin') {
if (isset($_REQUEST['cidReq']) && !empty($_REQUEST['cidReq'])) { if (isset($_REQUEST['cidReq']) && !empty($_REQUEST['cidReq'])) {
$type = 'course'; $type = 'course';
} }
$is_group_tutor = false;
$group_id = api_get_group_id();
if (!empty($group_id)) {
$is_group_tutor = GroupManager::is_tutor_of_group(api_get_user_id(), $group_id);
$group_properties = GroupManager :: get_group_properties($group_id);
$interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
$interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$group_id, "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
}
$tpl = new Template(get_lang('Agenda')); $tpl = new Template(get_lang('Agenda'));
$tpl->assign('use_google_calendar', 0); $tpl->assign('use_google_calendar', 0);
$can_add_events = 0;
switch($type) { switch($type) {
case 'admin': case 'admin':
api_protect_admin_script(); api_protect_admin_script();
$this_section = SECTION_PLATFORM_ADMIN; $this_section = SECTION_PLATFORM_ADMIN;
if (api_is_platform_admin()) {
$can_add_events = 1;
}
break; break;
case 'course': case 'course':
api_protect_course_script(); api_protect_course_script();
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
if (api_is_allowed_to_edit()) {
$can_add_events = 1;
}
if (!empty($group_id)) {
if ($is_group_tutor) {
$can_add_events = 1;
}
}
break; break;
case 'personal': case 'personal':
if (api_is_anonymous()) { if (api_is_anonymous()) {
@ -61,19 +83,12 @@ switch($type) {
$tpl->assign('google_calendar_url', $extra_field_data['google_calendar_url']); $tpl->assign('google_calendar_url', $extra_field_data['google_calendar_url']);
} }
$this_section = SECTION_MYAGENDA; $this_section = SECTION_MYAGENDA;
if (!api_is_anonymous()) {
$can_add_events = 1;
}
break; break;
} }
$can_add_events = 0;
if (api_is_platform_admin() && $type == 'admin') {
$can_add_events = 1;
}
if (api_is_allowed_to_edit() && $type == 'course') {
$can_add_events = 1;
}
if (!api_is_anonymous() && $type == 'personal') {
$can_add_events = 1;
}
//Setting translations //Setting translations
$day_short = api_get_week_days_short(); $day_short = api_get_week_days_short();
@ -102,14 +117,13 @@ if ($region_value == 'en') {
$tpl->assign('region_value', $region_value); $tpl->assign('region_value', $region_value);
$export_icon = '../img/export.png'; $export_icon = '../img/export.png';
$export_icon_low = '../img/export_low_fade.png'; $export_icon_low = '../img/export_low_fade.png';
$export_icon_high = '../img/export_high_fade.png'; $export_icon_high = '../img/export_high_fade.png';
$tpl->assign('export_ical_confidential_icon', Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential'))); $tpl->assign('export_ical_confidential_icon', Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')));
if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && api_is_allowed_to_session_edit(false,true) OR $is_group_tutor) {
if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && api_is_allowed_to_session_edit(false,true)) {
if ($type == 'course') { if ($type == 'course') {
$actions = display_courseadmin_links(); $actions = display_courseadmin_links();
} }
@ -118,9 +132,15 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed
//Calendar Type : course, admin, personal //Calendar Type : course, admin, personal
$tpl->assign('type', $type); $tpl->assign('type', $type);
//Calendar type label
$tpl->assign('type_label', get_lang(ucfirst($type).'Calendar')); $type_event_class = $type.'_event';
$type_label = get_lang(ucfirst($type).'Calendar');
if ($type == 'course' && !empty($group_id)) {
$type_event_class = 'group_event';
$type_label = get_lang('GroupCalendar');
}
$tpl->assign('type_label', $type_label);
$tpl->assign('type_event_class', $type_event_class);
//Current user can add event? //Current user can add event?
$tpl->assign('can_add_events', $can_add_events); $tpl->assign('can_add_events', $can_add_events);
@ -131,15 +151,22 @@ $tpl->assign('web_agenda_ajax_url', $agenda_ajax_url);
$course_code = api_get_course_id(); $course_code = api_get_course_id();
if (api_is_allowed_to_edit() && $course_code != '-1' && $type == 'course') { if ((api_is_allowed_to_edit() || $is_group_tutor) && $course_code != '-1' && $type == 'course') {
$order = 'lastname'; $order = 'lastname';
if (api_is_western_name_order) { if (api_is_western_name_order) {
$order = 'firstname'; $order = 'firstname';
} }
$user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order); if (!empty($group_id)) {
$group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id()); $group_list = array($group_id => $group_properties);
$user_list = GroupManager::get_subscribed_users($group_id);
} else {
$user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order);
$group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
}
$agenda = new Agenda(); $agenda = new Agenda();
//This will fill the select called #users_to_send_id
$select = $agenda->construct_not_selected_select_form($group_list, $user_list); $select = $agenda->construct_not_selected_select_form($group_list, $user_list);
$tpl->assign('visible_to', $select); $tpl->assign('visible_to', $select);
} }

@ -25,16 +25,16 @@ api_protect_course_script(true);
/* Libraries & settings */ /* Libraries & settings */
require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php'; $group_id = api_get_group_id();
/* Constants & variables */ /* Constants & variables */
$current_group = GroupManager :: get_group_properties(api_get_group_id()); $current_group = GroupManager :: get_group_properties($group_id);
/* Header */ /* Header */
$nameTools = get_lang('EditGroup'); $nameTools = get_lang('EditGroup');
$interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups')); $interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups'));
$is_group_member = GroupManager :: is_tutor_of_group(api_get_user_id(), api_get_group_id()); $is_group_member = GroupManager :: is_tutor_of_group(api_get_user_id(), $group_id);
if (!api_is_allowed_to_edit(false,true) && !$is_group_member) { if (!api_is_allowed_to_edit(false,true) && !$is_group_member) {
api_not_allowed(true); api_not_allowed(true);
@ -125,43 +125,8 @@ $form->add_textfield('name', get_lang('GroupName'));
// Description // Description
$form->addElement('textarea', 'description', get_lang('Description'), array ('class' => 'span6', 'rows' => 6)); $form->addElement('textarea', 'description', get_lang('Description'), array ('class' => 'span6', 'rows' => 6));
// Search Members of group
//$form = new FormValidator('search_member', 'get', 'group_edit', '', null, false);
//$renderer = & $form->defaultRenderer();
//$renderer->setElementTemplate('<span>{element}</span> ');
//$form->add_textfield('keyword', get_lang('GroupMembers'), false);
//$form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="search"');
// Getting all the users
/*
if (isset($_SESSION['id_session'])) {
$complete_user_list = CourseManager :: get_user_list_from_course_code($_course['id'], true, $_SESSION['id_session']);
$complete_user_list2 = CourseManager :: get_coach_list_from_course_code($_course['id'], $_SESSION['id_session']);
$complete_user_list = array_merge($complete_user_list, $complete_user_list2);
} else {
$complete_user_list = CourseManager :: get_user_list_from_course_code($_course['id']);
}
foreach ($complete_user_list as $user_id => $o_course_user) {
if ((isset ($_GET['keyword']) && search_members_keyword($o_course_user['firstname'], $o_course_user['lastname'], $o_course_user['username'], $o_course_user['official_code'], $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) {
$groups_name = GroupManager :: get_user_group_name($user_id);
if ($is_western_name_order) {
$temp[] = $o_course_user['firstname'];
$temp[] = $o_course_user['lastname'];
} else {
$temp[] = $o_course_user['lastname'];
$temp[] = $o_course_user['firstname'];
}
$temp[] = $o_course_user['role'];
$temp[] = implode(', ', $groups_name); //Group
$temp[] = $o_course_user['official_code'];
}
}*/
$complete_user_list = GroupManager :: fill_groups_list($current_group['id']); $complete_user_list = GroupManager :: fill_groups_list($current_group['id']);
usort($complete_user_list, 'sort_users'); usort($complete_user_list, 'sort_users');
$possible_users = array(); $possible_users = array();
foreach ($complete_user_list as $index => $user) { foreach ($complete_user_list as $index => $user) {
@ -196,17 +161,18 @@ $group_tutors_element->setButtonAttributes('remove', array('class' => 'btn arrow
// Group members // Group members
$group_member_list = GroupManager :: get_subscribed_users($current_group['id']); $group_member_list = GroupManager :: get_subscribed_users($current_group['id']);
$selected_users = array (); $selected_users = array ();
foreach ($group_member_list as $index => $user) { foreach ($group_member_list as $index => $user) {
//$possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
$selected_users[] = $user['user_id']; $selected_users[] = $user['user_id'];
} }
// possible : number_groups_left > 0 and is group member // possible : number_groups_left > 0 and is group member
$possible_users = array(); $possible_users = array();
foreach ($complete_user_list as $index => $user) { foreach ($complete_user_list as $index => $user) {
if( $user['number_groups_left'] >0 || in_array($user['user_id'],$selected_users) ) if ($user['number_groups_left'] > 0 || in_array($user['user_id'], $selected_users) ) {
$possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')'; $possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')';
}
} }
$group_members_element = $form->addElement('advmultiselect', 'group_members', get_lang('GroupMembers'), $possible_users, 'style="width: 280px;"'); $group_members_element = $form->addElement('advmultiselect', 'group_members', get_lang('GroupMembers'), $possible_users, 'style="width: 280px;"');

@ -20,19 +20,22 @@ $current_course_tool = TOOL_GROUP;
// Notice for unauthorized people. // Notice for unauthorized people.
api_protect_course_script(true); api_protect_course_script(true);
/* Libraries & config files */ /* Libraries & config files */
require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
require_once api_get_path(SYS_CODE_PATH).'forum/forumconfig.inc.php'; require_once api_get_path(SYS_CODE_PATH).'forum/forumconfig.inc.php';
/* MAIN CODE */ /* MAIN CODE */
$current_group = GroupManager :: get_group_properties($_SESSION['_gid']); $group_id = api_get_group_id();
if (!is_array($current_group) ) { $user_id = api_get_user_id();
//display some error message
$current_group = GroupManager :: get_group_properties($group_id);
if (empty($current_group)) {
api_not_allowed();
} }
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
$nameTools = get_lang('GroupSpace'); $nameTools = get_lang('GroupSpace');
$interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups')); $interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups'));
@ -44,7 +47,7 @@ $forums_of_groups = get_forums_of_group($current_group['id']);
$forum_state_public = 0; $forum_state_public = 0;
if (is_array($forums_of_groups)) { if (is_array($forums_of_groups)) {
foreach ($forums_of_groups as $key => $value) { foreach ($forums_of_groups as $key => $value) {
if($value['forum_group_public_private'] == 'public') { if ($value['forum_group_public_private'] == 'public') {
$forum_state_public = 1; $forum_state_public = 1;
} }
} }
@ -69,16 +72,16 @@ Display::display_introduction_section(TOOL_GROUP);
/* /*
* User wants to register in this group * User wants to register in this group
*/ */
if (!empty($_GET['selfReg']) && GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $current_group['id'])) { if (!empty($_GET['selfReg']) && GroupManager :: is_self_registration_allowed($user_id, $current_group['id'])) {
GroupManager :: subscribe_users($_SESSION['_user']['user_id'], $current_group['id']); GroupManager :: subscribe_users($user_id, $current_group['id']);
Display :: display_normal_message(get_lang('GroupNowMember')); Display :: display_normal_message(get_lang('GroupNowMember'));
} }
/* /*
* User wants to unregister from this group * User wants to unregister from this group
*/ */
if (!empty($_GET['selfUnReg']) && GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $current_group['id'])) { if (!empty($_GET['selfUnReg']) && GroupManager :: is_self_unregistration_allowed($user_id, $current_group['id'])) {
GroupManager :: unsubscribe_users($_SESSION['_user']['user_id'], $current_group['id']); GroupManager :: unsubscribe_users($user_id, $current_group['id']);
Display::display_normal_message(get_lang('StudentDeletesHimself')); Display::display_normal_message(get_lang('StudentDeletesHimself'));
} }
echo '<div class="actions">'; echo '<div class="actions">';
@ -88,7 +91,7 @@ echo '<a href="group.php">'.Display::return_icon('back.png',get_lang('BackToGrou
* Register to group * Register to group
*/ */
$subscribe_group = ''; $subscribe_group = '';
if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $current_group['id'])) { if (GroupManager :: is_self_registration_allowed($user_id, $current_group['id'])) {
$subscribe_group = '<a class="btn" href="'.api_get_self().'?selfReg=1&amp;group_id='.$current_group['id'].'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."'".')) return false;">'.get_lang("RegIntoGroup").'</a>'; $subscribe_group = '<a class="btn" href="'.api_get_self().'?selfReg=1&amp;group_id='.$current_group['id'].'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."'".')) return false;">'.get_lang("RegIntoGroup").'</a>';
} }
@ -96,7 +99,7 @@ if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'],
* Unregister from group * Unregister from group
*/ */
$unsubscribe_group = ''; $unsubscribe_group = '';
if (GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $current_group['id'])) { if (GroupManager :: is_self_unregistration_allowed($user_id, $current_group['id'])) {
$unsubscribe_group = '<a class="btn" href="'.api_get_self().'?selfUnReg=1" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."'".')) return false;">'.get_lang("StudentUnsubscribe").'</a>'; $unsubscribe_group = '<a class="btn" href="'.api_get_self().'?selfUnReg=1" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."'".')) return false;">'.get_lang("StudentUnsubscribe").'</a>';
} }
echo '&nbsp;</div>'; echo '&nbsp;</div>';
@ -114,10 +117,6 @@ if (isset($_GET['action'])) {
$course_code = $_course['sysCode']; $course_code = $_course['sysCode'];
$is_course_member = CourseManager :: is_user_subscribed_in_real_or_linked_course(api_get_user_id(), $course_code); $is_course_member = CourseManager :: is_user_subscribed_in_real_or_linked_course(api_get_user_id(), $course_code);
/*
* Group title and comment
*/
/* /*
* Edit the group * Edit the group
*/ */
@ -242,6 +241,7 @@ echo '</ul>';
* List all the tutors of the current group * List all the tutors of the current group
*/ */
$tutors = GroupManager::get_subscribed_tutors($current_group['id']); $tutors = GroupManager::get_subscribed_tutors($current_group['id']);
$tutor_info = ''; $tutor_info = '';
if (count($tutors) == 0) { if (count($tutors) == 0) {
$tutor_info = get_lang('GroupNoneMasc'); $tutor_info = get_lang('GroupNoneMasc');
@ -361,23 +361,22 @@ function get_group_user_data($from, $number_of_items, $column, $direction) {
$sql .= " LIMIT $from,$number_of_items"; $sql .= " LIMIT $from,$number_of_items";
} else { } else {
if (api_is_allowed_to_edit()) { if (api_is_allowed_to_edit()) {
$sql = "SELECT $sql = "SELECT DISTINCT
user.user_id AS col0, u.user_id AS col0,
".(api_is_western_name_order() ? ".(api_is_western_name_order() ?
"user.firstname AS col1, "u.firstname AS col1,
user.lastname AS col2," u.lastname AS col2,"
: :
"user.lastname AS col1, "u.lastname AS col1,
user.firstname AS col2," u.firstname AS col2,"
)." )."
user.email AS col3 u.email AS col3
FROM ".$table_user." user, ".$table_group_user." group_rel_user FROM ".$table_user." u INNER JOIN ".$table_group_user." gu ON (gu.user_id = u.user_id) AND gu.c_id = $course_id
WHERE group_rel_user.c_id = $course_id AND group_rel_user.user_id = user.user_id WHERE gu.group_id = '".Database::escape_string($current_group['id'])."'";
AND group_rel_user.group_id = '".Database::escape_string($current_group['id'])."'";
$sql .= " ORDER BY col$column $direction "; $sql .= " ORDER BY col$column $direction ";
$sql .= " LIMIT $from,$number_of_items"; $sql .= " LIMIT $from,$number_of_items";
} else { } else {
$sql = "SELECT $sql = "SELECT DISTINCT
user.user_id AS col0, user.user_id AS col0,
". (api_is_western_name_order() ? ". (api_is_western_name_order() ?
"user.firstname AS col1, "user.firstname AS col1,

@ -14,19 +14,21 @@ $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
$type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], array('personal', 'course', 'admin')) ? $_REQUEST['type'] : 'personal'; $type = isset($_REQUEST['type']) && in_array($_REQUEST['type'], array('personal', 'course', 'admin')) ? $_REQUEST['type'] : 'personal';
if ($type =='course') { if ($type =='course') {
// Access control
api_protect_course_script(true); api_protect_course_script(true);
} }
$agenda = new Agenda(); $group_id = api_get_group_id();
$is_group_tutor = GroupManager::is_tutor_of_group(api_get_user_id(), $group_id);
$agenda = new Agenda();
$agenda->type = $type; //course,admin or personal $agenda->type = $type; //course,admin or personal
switch ($action) { switch ($action) {
case 'add_event': case 'add_event':
if (!api_is_allowed_to_edit(null, true) && $type == 'course') { if ((!api_is_allowed_to_edit(null, true) && !$is_group_tutor) && $type == 'course') {
break; break;
} }
echo $agenda->add_event($_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'], echo $agenda->add_event($_REQUEST['start'], $_REQUEST['end'], $_REQUEST['all_day'], $_REQUEST['view'],
$_REQUEST['title'], $_REQUEST['content'], $_REQUEST['users_to_send'], $_REQUEST['add_as_annonuncement']); $_REQUEST['title'], $_REQUEST['content'], $_REQUEST['users_to_send'], $_REQUEST['add_as_annonuncement']);
break; break;
@ -69,9 +71,9 @@ switch ($action) {
case 'get_events': case 'get_events':
$start = $_REQUEST['start']; $start = $_REQUEST['start'];
$end = $_REQUEST['end']; $end = $_REQUEST['end'];
$events = $agenda->get_events($start, $end, api_get_user_id(), api_get_course_int_id()); $events = $agenda->get_events($start, $end, api_get_course_int_id(), $group_id);
echo $events; echo $events;
break; break;
case 'get_user_agenda': case 'get_user_agenda':
//Used in the admin user list //Used in the admin user list
api_protect_admin_script(); api_protect_admin_script();

@ -430,32 +430,38 @@ class GroupManager {
* @param int $group_id The group from which properties are requested. * @param int $group_id The group from which properties are requested.
* @return array All properties. Array-keys are name, tutor_id, description, maximum_number_of_students, directory and visibility of tools * @return array All properties. Array-keys are name, tutor_id, description, maximum_number_of_students, directory and visibility of tools
*/ */
public static function get_group_properties ($group_id) { public static function get_group_properties($group_id) {
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
if (empty($group_id) or !is_integer(intval($group_id)) ) { if (empty($group_id) or !is_integer(intval($group_id)) ) {
return null; return null;
} }
$result = array();
$table_group = Database :: get_course_table(TABLE_GROUP); $table_group = Database :: get_course_table(TABLE_GROUP);
$sql = "SELECT * FROM $table_group WHERE c_id = $course_id AND id = ".Database::escape_string($group_id); $sql = "SELECT * FROM $table_group WHERE c_id = $course_id AND id = ".intval($group_id);
$db_result = Database::query($sql); $db_result = Database::query($sql);
$db_object = Database::fetch_object($db_result);
$db_object = Database::fetch_object($db_result);
$result['id'] = $db_object->id; $result['id'] = $db_object->id;
$result['name'] = $db_object->name; $result['name'] = $db_object->name;
$result['tutor_id'] = isset($db_object->tutor_id)?$db_object->tutor_id:null; $result['tutor_id'] = isset($db_object->tutor_id)?$db_object->tutor_id:null;
$result['description'] = $db_object->description; $result['description'] = $db_object->description;
$result['maximum_number_of_students'] = $db_object->max_student; $result['maximum_number_of_students'] = $db_object->max_student;
$result['doc_state'] = $db_object->doc_state; $result['doc_state'] = $db_object->doc_state;
$result['work_state'] = $db_object->work_state; $result['work_state'] = $db_object->work_state;
$result['calendar_state'] = $db_object->calendar_state; $result['calendar_state'] = $db_object->calendar_state;
$result['announcements_state'] = $db_object->announcements_state; $result['announcements_state'] = $db_object->announcements_state;
$result['forum_state'] = $db_object->forum_state; $result['forum_state'] = $db_object->forum_state;
$result['wiki_state'] = $db_object->wiki_state; $result['wiki_state'] = $db_object->wiki_state;
$result['chat_state'] = $db_object->chat_state; $result['chat_state'] = $db_object->chat_state;
$result['directory'] = $db_object->secret_directory; $result['directory'] = $db_object->secret_directory;
$result['self_registration_allowed'] = $db_object->self_registration_allowed; $result['self_registration_allowed'] = $db_object->self_registration_allowed;
$result['self_unregistration_allowed'] = $db_object->self_unregistration_allowed; $result['self_unregistration_allowed'] = $db_object->self_unregistration_allowed;
$result['count_users'] = count(self::get_subscribed_users($group_id));
$result['count_tutor'] = count(self::get_subscribed_tutors($group_id));
$result['count_all'] = $result['count_users'] + $result['count_tutor'];
return $result; return $result;
} }
/** /**
@ -745,7 +751,7 @@ class GroupManager {
* @param int $group_id The group * @param int $group_id The group
* @return array list of user id * @return array list of user id
*/ */
public static function get_users ($group_id) { public static function get_users ($group_id, $load_extra_info = false) {
$group_user_table = Database :: get_course_table(TABLE_GROUP_USER); $group_user_table = Database :: get_course_table(TABLE_GROUP_USER);
$group_id = Database::escape_string($group_id); $group_id = Database::escape_string($group_id);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
@ -753,39 +759,61 @@ class GroupManager {
$res = Database::query($sql); $res = Database::query($sql);
$users = array (); $users = array ();
while ($obj = Database::fetch_object($res)) { while ($obj = Database::fetch_object($res)) {
$users[] = $obj->user_id; if ($load_extra_info) {
$users[] = api_get_user_info($obj->user_id);
} else {
$users[] = $obj->user_id;
}
} }
return $users; return $users;
} }
public function get_members_and_tutors($group_id) {
$group_user_table = Database :: get_course_table(TABLE_GROUP_USER);
$tutor_user_table = Database :: get_course_table(TABLE_GROUP_TUTOR);
$course_id = api_get_course_int_id();
$group_id = intval($group_id);
$sql = "SELECT user_id FROM $group_user_table WHERE c_id = $course_id AND group_id = $group_id";
$res = Database::query($sql);
$users = array();
while ($obj = Database::fetch_object($res)) {
$users[] = api_get_user_info($obj->user_id);
}
/** $sql = "SELECT user_id FROM $tutor_user_table WHERE c_id = $course_id AND group_id = $group_id";
* Returns users belonging to any of the group $res = Database::query($sql);
* while ($obj = Database::fetch_object($res)) {
* @param array $groups list of group ids $users[] = api_get_user_info($obj->user_id);
* @return array list of user ids }
*/
public static function get_groups_users($groups = array())
{
$result = array();
$tbl_group_user = Database::get_course_table(TABLE_GROUP_USER);
$course_id = api_get_course_int_id();
$groups = array_map('intval', $groups); return $users;
$groups = implode(', ', $groups); //protect individual elements with surrounding quotes }
$sql = "SELECT DISTINCT user_id
FROM $tbl_group_user gu /**
WHERE c_id = $course_id AND gu.group_id IN ($groups)"; * Returns users belonging to any of the group
$rs = Database::query($sql); *
while ($row = Database::fetch_array($rs)) * @param array $groups list of group ids
{ * @return array list of user ids
$result[] = $row['user_id']; */
} public static function get_groups_users($groups = array()) {
$result = array();
$tbl_group_user = Database::get_course_table(TABLE_GROUP_USER);
$course_id = api_get_course_int_id();
return $result; $groups = array_map('intval', $groups);
$groups = implode(', ', $groups); //protect individual elements with surrounding quotes
$sql = "SELECT DISTINCT user_id
FROM $tbl_group_user gu
WHERE c_id = $course_id AND gu.group_id IN ($groups)";
$rs = Database::query($sql);
while ($row = Database::fetch_array($rs)) {
$result[] = $row['user_id'];
} }
return $result;
}
/** /**
* Fill the groups with students. * Fill the groups with students.
* The algorithm takes care to first fill the groups with the least # of users. * The algorithm takes care to first fill the groups with the least # of users.
@ -1083,7 +1111,7 @@ class GroupManager {
$member['lastname'] = $user->lastname; $member['lastname'] = $user->lastname;
$member['email'] = $user->email; $member['email'] = $user->email;
$member['username'] = $user->username; $member['username'] = $user->username;
$users[] = $member; $users[$member['user_id']] = $member;
} }
return $users; return $users;
} }

@ -1133,8 +1133,7 @@ function api_get_anonymous_id() {
$sql = "SELECT user_id FROM $table WHERE status = 6"; $sql = "SELECT user_id FROM $table WHERE status = 6";
$res = Database::query($sql); $res = Database::query($sql);
if (Database::num_rows($res) > 0) { if (Database::num_rows($res) > 0) {
$row = Database::fetch_array($res); $row = Database::fetch_array($res);
//error_log('api_get_anonymous_id() returns '.$row['user_id'], 0);
return $row['user_id']; return $row['user_id'];
} }
// No anonymous user was found. // No anonymous user was found.
@ -2819,8 +2818,7 @@ function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $us
$session_id = intval($session_id); $session_id = intval($session_id);
} else { } else {
$session_id = api_get_session_id(); $session_id = api_get_session_id();
} }
// Definition of tables. // Definition of tables.
$TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);

@ -38,7 +38,7 @@ $(document).ready(function() {
$("#dialog-form").dialog({ $("#dialog-form").dialog({
autoOpen: false, autoOpen: false,
modal : false, modal : false,
width : 550, width : 580,
height : 480, height : 480,
zIndex: 20000 // added because of qtip2 zIndex: 20000 // added because of qtip2
}); });
@ -46,7 +46,7 @@ $(document).ready(function() {
$("#simple-dialog-form").dialog({ $("#simple-dialog-form").dialog({
autoOpen: false, autoOpen: false,
modal : false, modal : false,
width : 550, width : 580,
height : 480, height : 480,
zIndex: 20000 // added because of qtip2 zIndex: 20000 // added because of qtip2
}); });
@ -164,7 +164,7 @@ $(document).ready(function() {
$('#color_calendar').html('{{type_label}}'); $('#color_calendar').html('{{type_label}}');
$('#color_calendar').removeClass('group_event'); $('#color_calendar').removeClass('group_event');
$('#color_calendar').addClass('label_tag'); $('#color_calendar').addClass('label_tag');
$('#color_calendar').addClass('{{type}}_event'); $('#color_calendar').addClass('{{ type_event_class }}');
allFields.removeClass( "ui-state-error" ); allFields.removeClass( "ui-state-error" );
$("#dialog-form").dialog("open"); $("#dialog-form").dialog("open");
@ -461,7 +461,7 @@ $(document).ready(function() {
<label></label> <label></label>
<div class="controls"> <div class="controls">
<label class="checkbox inline" for="add_as_annonuncement"> <label class="checkbox inline" for="add_as_annonuncement">
{{"AddAsAnnouncement"|get_lang}} {{ "AddAsAnnouncement"|get_lang }}
<input type="checkbox" name="add_as_annonuncement" id="add_as_annonuncement" /> <input type="checkbox" name="add_as_annonuncement" id="add_as_annonuncement" />
</label> </label>
</div> </div>

Loading…
Cancel
Save