Пример #1
0
 function get_content()
 {
     global $CFG, $COURSE, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
     $config = quickmail::load_config($COURSE->id);
     $permission = has_capability('block/quickmail:cansend', $context);
     $can_send = ($permission or !empty($config['allowstudents']));
     $icon_class = array('class' => 'icon');
     if ($can_send) {
         $cparam = array('courseid' => $COURSE->id);
         $send_email_str = quickmail::_s('composenew');
         $send_email = html_writer::link(new moodle_url('/blocks/quickmail/email.php', $cparam), $send_email_str);
         $this->content->items[] = $send_email;
         $this->content->icons[] = $OUTPUT->pix_icon('i/email', $send_email_str, 'moodle', $icon_class);
         $signature_str = quickmail::_s('signature');
         $signature = html_writer::link(new moodle_url('/blocks/quickmail/signature.php', $cparam), $signature_str);
         $this->content->items[] = $signature;
         $this->content->icons[] = $OUTPUT->pix_icon('i/edit', $signature_str, 'moodle', $icon_class);
         $draft_params = $cparam + array('type' => 'drafts');
         $drafts_email_str = quickmail::_s('drafts');
         $drafts = html_writer::link(new moodle_url('/blocks/quickmail/emaillog.php', $draft_params), $drafts_email_str);
         $this->content->items[] = $drafts;
         $this->content->icons[] = $OUTPUT->pix_icon('i/settings', $drafts_email_str, 'moodle', $icon_class);
         $history_str = quickmail::_s('history');
         $history = html_writer::link(new moodle_url('/blocks/quickmail/emaillog.php', $cparam), $history_str);
         $this->content->items[] = $history;
         $this->content->icons[] = $OUTPUT->pix_icon('i/settings', $history_str, 'moodle', $icon_class);
     }
     if (has_capability('block/quickmail:allowalternate', $context)) {
         $alt_str = quickmail::_s('alternate');
         $alt = html_writer::link(new moodle_url('/blocks/quickmail/alternate.php', $cparam), $alt_str);
         $this->content->items[] = $alt;
         $this->content->icons[] = $OUTPUT->pix_icon('i/edit', $alt_str, 'moodle', $icon_class);
     }
     if (has_capability('block/quickmail:canconfig', $context)) {
         $config_str = quickmail::_s('config');
         $config = html_writer::link(new moodle_url('/blocks/quickmail/config.php', $cparam), $config_str);
         $this->content->items[] = $config;
         $this->content->icons[] = $OUTPUT->pix_icon('i/settings', $config_str, 'moodle', $icon_class);
     }
     return $this->content;
 }
Пример #2
0
$page = optional_param('page', 0, PARAM_INT);
$perpage = optional_param('perpage', 10, PARAM_INT);
$userid = optional_param('userid', $USER->id, PARAM_INT);
if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
    print_error('no_course', 'block_quickmail', '', $courseid);
}
$context = context_course::instance($courseid);
// Has to be in on of these
if (!in_array($type, array('log', 'drafts'))) {
    print_error('not_valid', 'block_quickmail', '', $type);
}
$canimpersonate = has_capability('block/quickmail:canimpersonate', $context);
if (!$canimpersonate and $userid != $USER->id) {
    print_error('not_valid_user', 'block_quickmail');
}
$config = quickmail::load_config($courseid);
$valid_actions = array('delete', 'confirm');
$can_send = has_capability('block/quickmail:cansend', $context);
$proper_permission = ($can_send or !empty($config['allowstudents']));
//managers can delete by capability 'candelete';
//those with 'cansend' (incl students, if $config['allowstudents']) can only delete drafts;
$can_delete = (has_capability('block/quickmail:candelete', $context) or $can_send and $type == 'drafts' or $proper_permission and $type == 'drafts');
// Stops students from tempering with history
if (!$proper_permission or !$can_delete and in_array($action, $valid_actions)) {
    print_error('no_permission', 'block_quickmail');
}
if (isset($action) and !in_array($action, $valid_actions)) {
    print_error('not_valid_action', 'block_quickmail', '', $action);
}
if (isset($action) and empty($typeid)) {
    print_error('not_valid_typeid', 'block_quickmail', '', $action);
Пример #3
0
 public function definition()
 {
     global $CFG, $USER, $COURSE, $OUTPUT;
     $mform =& $this->_form;
     $mform->addElement('hidden', 'mailto', '');
     $mform->addElement('hidden', 'userid', $USER->id);
     $mform->addElement('hidden', 'courseid', $COURSE->id);
     $mform->addElement('hidden', 'type', '');
     $mform->addElement('hidden', 'typeid', 0);
     $role_options = array('none' => quickmail::_s('no_filter'));
     foreach ($this->_customdata['roles'] as $role) {
         $role_options[$role->shortname] = $role->name;
     }
     $group_options = empty($this->_customdata['groups']) ? array() : array('all' => quickmail::_s('all_sections'));
     foreach ($this->_customdata['groups'] as $group) {
         $group_options[$group->id] = $group->name;
     }
     $group_options[0] = quickmail::_s('no_section');
     $user_options = array();
     foreach ($this->_customdata['users'] as $user) {
         $user_options[$this->option_value($user)] = $this->option_display($user);
     }
     $links = array();
     $gen_url = function ($type) use($COURSE) {
         $email_param = array('courseid' => $COURSE->id, 'type' => $type);
         return new moodle_url('emaillog.php', $email_param);
     };
     $draft_link = html_writer::link($gen_url('drafts'), quickmail::_s('drafts'));
     $links[] =& $mform->createElement('static', 'draft_link', '', $draft_link);
     $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
     $config = quickmail::load_config($COURSE->id);
     $can_send = (has_capability('block/quickmail:cansend', $context) or !empty($config['allowstudents']));
     if ($can_send) {
         $history_link = html_writer::link($gen_url('log'), quickmail::_s('history'));
         $links[] =& $mform->createElement('static', 'history_link', '', $history_link);
     }
     $mform->addGroup($links, 'links', ' ', array(' | '), false);
     $req_img = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('req'), 'class' => 'req'));
     $table = new html_table();
     $table->attributes['class'] = 'emailtable';
     $selected_required_label = new html_table_cell();
     $selected_required_label->text = html_writer::tag('strong', quickmail::_s('selected') . $req_img, array('class' => 'required'));
     $role_filter_label = new html_table_cell();
     $role_filter_label->colspan = "2";
     $role_filter_label->text = html_writer::tag('div', quickmail::_s('role_filter'), array('class' => 'object_labels'));
     $select_filter = new html_table_cell();
     $select_filter->text = html_writer::tag('select', array_reduce($this->_customdata['selected'], array($this, 'reduce_users'), ''), array('id' => 'mail_users', 'multiple' => 'multiple', 'size' => 30));
     $embed = function ($text, $id) {
         return html_writer::tag('p', html_writer::empty_tag('input', array('value' => $text, 'type' => 'button', 'id' => $id)));
     };
     $embed_quick = function ($text) use($embed) {
         return $embed(quickmail::_s($text), $text);
     };
     $center_buttons = new html_table_cell();
     $center_buttons->text = $embed($OUTPUT->larrow() . ' ' . quickmail::_s('add_button'), 'add_button') . $embed(quickmail::_s('remove_button') . ' ' . $OUTPUT->rarrow(), 'remove_button') . $embed_quick('add_all') . $embed_quick('remove_all');
     $filters = new html_table_cell();
     $filters->text = html_writer::tag('div', html_writer::select($role_options, '', 'none', null, array('id' => 'roles'))) . html_writer::tag('div', quickmail::_s('potential_sections'), array('class' => 'object_labels')) . html_writer::tag('div', html_writer::select($group_options, '', 'all', null, array('id' => 'groups', 'multiple' => 'multiple', 'size' => 5))) . html_writer::tag('div', quickmail::_s('potential_users'), array('class' => 'object_labels')) . html_writer::tag('div', html_writer::select($user_options, '', '', null, array('id' => 'from_users', 'multiple' => 'multiple', 'size' => 20)));
     $table->data[] = new html_table_row(array($selected_required_label, $role_filter_label));
     $table->data[] = new html_table_row(array($select_filter, $center_buttons, $filters));
     if (has_capability('block/quickmail:allowalternate', $context)) {
         $alternates = $this->_customdata['alternates'];
     } else {
         $alternates = array();
     }
     if (empty($alternates)) {
         $mform->addElement('static', 'from', quickmail::_s('from'), $USER->email);
     } else {
         $options = array(0 => $USER->email) + $alternates;
         $mform->addElement('select', 'alternateid', quickmail::_s('from'), $options);
     }
     $mform->addElement('static', 'selectors', '', html_writer::table($table));
     $mform->addElement('filemanager', 'attachments', quickmail::_s('attachment'));
     $mform->addElement('text', 'subject', quickmail::_s('subject'));
     $mform->setType('subject', PARAM_TEXT);
     $mform->addRule('subject', null, 'required');
     $mform->addElement('editor', 'message_editor', quickmail::_s('message'), null, $this->_customdata['editor_options']);
     $options = $this->_customdata['sigs'] + array(-1 => 'No ' . quickmail::_s('sig'));
     $mform->addElement('select', 'sigid', quickmail::_s('signature'), $options);
     $radio = array($mform->createElement('radio', 'receipt', '', get_string('yes'), 1), $mform->createElement('radio', 'receipt', '', get_string('no'), 0));
     $mform->addGroup($radio, 'receipt_action', quickmail::_s('receipt'), array(' '), false);
     $mform->addHelpButton('receipt_action', 'receipt', 'block_quickmail');
     $mform->setDefault('receipt', !empty($config['receipt']));
     $buttons = array();
     $buttons[] =& $mform->createElement('submit', 'send', quickmail::_s('send_email'));
     $buttons[] =& $mform->createElement('submit', 'draft', quickmail::_s('save_draft'));
     $buttons[] =& $mform->createElement('cancel');
     $mform->addGroup($buttons, 'buttons', quickmail::_s('actions'), array(' '), false);
 }