Skip to content

Commit

Permalink
MDL-24941, fixed nopermission error when student entering scheduled c…
Browse files Browse the repository at this point in the history
…hat session
  • Loading branch information
Dongsheng Cai committed Nov 17, 2010
1 parent 5bf7254 commit 1d5bd3d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 19 deletions.
27 changes: 16 additions & 11 deletions calendar/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_y
} else if ($event->userid) { // User event
$popupicon = 'c/user';
}

$dayhref->set_anchor('event_'.$event->id);

$popupcontent .= html_writer::start_tag('div');
$popupcontent .= $OUTPUT->pix_icon($popupicon, $popupalt);
$popupcontent .= html_writer::link($dayhref, format_string($event->name, true));
Expand Down Expand Up @@ -955,7 +955,7 @@ function calendar_time_representation($time) {
* @param int $d
* @param int $m
* @param int $y
* @return moodle_url
* @return moodle_url
*/
function calendar_get_link_href($linkbase, $d, $m, $y) {
if (empty($linkbase)) {
Expand Down Expand Up @@ -1016,7 +1016,7 @@ function calendar_get_link_previous($text, $linkbase, $d, $m, $y, $accesshide=fa

/**
* Build and return a next month HTML link, with an arrow.
*
*
* @param string $text The text label.
* @param string|moodle_url $linkbase The URL stub.
* @param int $d $m $y Day of month, month and year numbers.
Expand Down Expand Up @@ -1549,7 +1549,7 @@ function calendar_format_event_time($event, $now, $linkparams = null, $usecommon
} else {
$url = calendar_get_link_href(new moodle_url(CALENDAR_URL.'view.php', $linkparams), $enddate['mday'], $enddate['mon'], $enddate['year']);
$eventtime = html_writer::link($url, $daystart).$timestart.' <strong>&raquo;</strong> ';

$url = calendar_get_link_href(new moodle_url(CALENDAR_URL.'view.php', $linkparams), $startdate['mday'], $startdate['mon'], $startdate['year']);
$eventtime .= html_writer::link($url, $dayend).$timeend;
}
Expand Down Expand Up @@ -1947,8 +1947,9 @@ public function count_repeats() {
* @see update_event()
*
* @param stdClass $data
* @param boolean $checkcapability if moodle should check calendar managing capability or not
*/
public function update($data) {
public function update($data, $checkcapability=true) {
global $CFG, $DB, $USER;

foreach ($data as $key=>$value) {
Expand All @@ -1960,8 +1961,10 @@ public function update($data) {

if (empty($this->properties->id) || $this->properties->id < 1) {

if (!calendar_add_event_allowed($this->properties)) {
print_error('nopermissions');
if ($checkcapability) {
if (!calendar_add_event_allowed($this->properties)) {
print_error('nopermissiontoupdatecalendar');
}
}

if ($usingeditor) {
Expand Down Expand Up @@ -2055,8 +2058,10 @@ public function update($data) {
return true;
} else {

if(!calendar_edit_event_allowed($this->properties)) {
print_error('nopermissions');
if ($checkcapability) {
if(!calendar_edit_event_allowed($this->properties)) {
print_error('nopermissiontoupdatecalendar');
}
}

if ($usingeditor) {
Expand Down Expand Up @@ -2504,4 +2509,4 @@ public function add_sidecalendar_blocks(core_calendar_renderer $renderer, $showf
$block->title = get_string('monthlyview', 'calendar');
$renderer->add_pretend_calendar_block($block, BLOCK_POS_RIGHT);
}
}
}
1 change: 1 addition & 0 deletions lang/en/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@
$string['nopermissiontorate'] = 'Rating of items not allowed!';
$string['nopermissiontoshow'] = 'No permission to see this!';
$string['nopermissiontounlock'] = 'No permission to unlock!';
$string['nopermissiontoupdatecalendar'] = 'Sorry, but you do not currently have permissions to update calendar event';
$string['nopermissiontoviewgrades'] = 'Can not view grades.';
$string['nopermissiontoviewletergrade'] = 'Missing permission to view letter grades';
$string['nopermissiontoviewpage'] = 'You are not allowed to look at this page';
Expand Down
2 changes: 1 addition & 1 deletion mod/chat/gui_basic/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_login($course->id, false, $cm);
require_capability('mod/chat:chat',$context);
require_capability('mod/chat:chat', $context);
$PAGE->set_pagelayout('base');

/// Check to see if groups are being used here
Expand Down
2 changes: 1 addition & 1 deletion mod/chat/gui_header_js/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

require_login($course->id, false, $cm);

require_capability('mod/chat:chat',$context);
require_capability('mod/chat:chat', $context);

/// Check to see if groups are being used here
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
Expand Down
1 change: 1 addition & 0 deletions mod/chat/lang/en/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
$string['servermax'] = 'Max users';
$string['serverport'] = 'Server port';
$string['sessions'] = 'Chat sessions';
$string['sessionstart'] = 'Chat session will be start in: {$a}';
$string['strftimemessage'] = '%H:%M';
$string['studentseereports'] = 'Everyone can view past sessions';
$string['studentseereports_help'] = 'If set to No, only users have mod/chat:readlog capability are able to see the chat logs';
Expand Down
2 changes: 1 addition & 1 deletion mod/chat/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ function chat_update_chat_times($chatid=0) {
if ($event->id = $DB->get_field_select('event', 'id', $cond, $params)) {
$event->timestart = $chat->chattime;
$calendarevent = calendar_event::load($event->id);
$calendarevent->update($event);
$calendarevent->update($event, false);
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions mod/chat/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

/// This page prints a particular instance of chat

require_once(dirname(__FILE__) . '/../../config.php');
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require_once($CFG->dirroot . '/mod/chat/lib.php');
require_once($CFG->libdir.'/completionlib.php');
require_once($CFG->libdir . '/completionlib.php');

$id = optional_param('id', 0, PARAM_INT);
$c = optional_param('c', 0, PARAM_INT);
Expand Down Expand Up @@ -109,12 +109,16 @@
echo $OUTPUT->box(format_module_intro('chat', $chat, $cm->id), 'generalbox', 'intro');
}

if (has_capability('mod/chat:chat',$context)) {
if (has_capability('mod/chat:chat', $context)) {
/// Print the main part of the page
echo $OUTPUT->box_start('generalbox', 'enterlink');

if ($chat->chattime and $chat->schedule) { // A chat is scheduled
echo "<p class=\"nextchatsession\">$strnextsession: ".userdate($chat->chattime).' ('.usertimezone($USER->timezone).')</p>';
$now = time();
$span = $chat->chattime - $now;
if ($chat->chattime and $chat->schedule and ($span>0)) { // A chat is scheduled
echo '<p>';
echo get_string('sessionstart', 'chat', format_time($span));
echo '</p>';
}

if (empty($USER->screenreader)) {
Expand Down

0 comments on commit 1d5bd3d

Please sign in to comment.