Esempio n. 1
0
 public 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 = context_course::instance($COURSE->id);
     $config = clampmail::load_config($COURSE->id);
     $permission = has_capability('block/clampmail:cansend', $context);
     $icon_class = array('class' => 'icon');
     if ($permission) {
         $cparam = array('courseid' => $COURSE->id);
         $send_email_str = clampmail::_s('composenew');
         $send_email = html_writer::link(new moodle_url('/blocks/clampmail/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 = clampmail::_s('signature');
         $signature = html_writer::link(new moodle_url('/blocks/clampmail/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 = clampmail::_s('drafts');
         $drafts = html_writer::link(new moodle_url('/blocks/clampmail/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 = clampmail::_s('history');
         $history = html_writer::link(new moodle_url('/blocks/clampmail/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/clampmail:allowalternate', $context)) {
         $alt_str = clampmail::_s('alternate');
         $alt = html_writer::link(new moodle_url('/blocks/clampmail/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/clampmail:canconfig', $context)) {
         $config_str = clampmail::_s('config');
         $config = html_writer::link(new moodle_url('/blocks/clampmail/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;
 }
Esempio n. 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_clampmail', '', $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_clampmail', '', $type);
}
$canimpersonate = has_capability('block/clampmail:canimpersonate', $context);
if (!$canimpersonate and $userid != $USER->id) {
    print_error('not_valid_user', 'block_clampmail');
}
$config = clampmail::load_config($courseid);
$valid_actions = array('delete', 'confirm');
$can_send = has_capability('block/clampmail:cansend', $context);
$proper_permission = ($can_send or !empty($config['allowstudents']));
$can_delete = ($can_send 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_clampmail');
}
if (isset($action) and !in_array($action, $valid_actions)) {
    print_error('not_valid_action', 'block_clampmail', '', $action);
}
if (isset($action) and empty($typeid)) {
    print_error('not_valid_typeid', 'block_clampmail', '', $action);
}
$blockname = clampmail::_s('pluginname');
Esempio n. 3
0
 public function definition()
 {
     global $CFG, $USER, $COURSE, $OUTPUT;
     $mform =& $this->_form;
     $mform->addElement('hidden', 'mailto', '');
     $mform->setType('mailto', PARAM_RAW);
     $mform->addElement('hidden', 'userid', $USER->id);
     $mform->setType('userid', PARAM_INT);
     $mform->addElement('hidden', 'courseid', $COURSE->id);
     $mform->setType('courseid', PARAM_INT);
     $mform->addElement('hidden', 'type', '');
     $mform->setType('type', PARAM_ALPHA);
     $mform->addElement('hidden', 'typeid', 0);
     $mform->setType('typeid', PARAM_INT);
     $role_options = array('none' => clampmail::_s('no_filter'));
     foreach ($this->_customdata['roles'] as $role) {
         $role_options[$role->shortname] = $role->name;
     }
     $group_options = empty($this->_customdata['groups']) ? array() : array('all' => clampmail::_s('all_sections'));
     foreach ($this->_customdata['groups'] as $group) {
         $group_options[$group->id] = $group->name;
     }
     $group_options[0] = clampmail::_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'), clampmail::_s('drafts'));
     $links[] =& $mform->createElement('static', 'draft_link', '', $draft_link);
     $context = context_course::instance($COURSE->id);
     $config = clampmail::load_config($COURSE->id);
     $can_send = (has_capability('block/clampmail:cansend', $context) or !empty($config['allowstudents']));
     if ($can_send) {
         $history_link = html_writer::link($gen_url('log'), clampmail::_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', clampmail::_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', clampmail::_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(clampmail::_s($text), $text);
     };
     $center_buttons = new html_table_cell();
     $center_buttons->text = $embed($OUTPUT->larrow() . ' ' . clampmail::_s('add_button'), 'add_button') . $embed(clampmail::_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', clampmail::_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', clampmail::_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/clampmail:allowalternate', $context)) {
         $alternates = $this->_customdata['alternates'];
     } else {
         $alternates = array();
     }
     if (empty($alternates)) {
         $mform->addElement('static', 'from', clampmail::_s('from'), $USER->email);
         $mform->setType('from', PARAM_EMAIL);
     } else {
         $options = array(0 => $USER->email) + $alternates;
         $mform->addElement('select', 'alternateid', clampmail::_s('from'), $options);
         $mform->setType('alternateid', PARAM_INT);
     }
     $mform->addElement('static', 'selectors', '', html_writer::table($table));
     $mform->setType('selectors', PARAM_RAW);
     $mform->addElement('filemanager', 'attachments', clampmail::_s('attachment'));
     $mform->setType('attachments', PARAM_FILE);
     $mform->addElement('text', 'subject', clampmail::_s('subject'));
     $mform->setType('subject', PARAM_TEXT);
     $mform->addRule('subject', null, 'required');
     $mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $mform->addElement('editor', 'message_editor', clampmail::_s('message'), null, $this->_customdata['editor_options']);
     $options = $this->_customdata['sigs'] + array(-1 => 'No ' . clampmail::_s('sig'));
     $mform->addElement('select', 'sigid', clampmail::_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', clampmail::_s('receipt'), array(' '), false);
     $mform->addHelpButton('receipt_action', 'receipt', 'block_clampmail');
     $mform->setDefault('receipt', !empty($config['receipt']));
     $buttons = array();
     $buttons[] =& $mform->createElement('submit', 'send', clampmail::_s('send_email'));
     $buttons[] =& $mform->createElement('submit', 'draft', clampmail::_s('save_draft'));
     $buttons[] =& $mform->createElement('cancel');
     $mform->addGroup($buttons, 'buttons', clampmail::_s('actions'), array(' '), false);
 }