}
    }
}
// security: teachers can view all assignments, students only their own
if (count($args) >= 3 and strtolower($args[1]) == 'moddata' and strtolower($args[2]) == 'assignment') {
    $lifetime = 0;
    // do not cache assignments, students may reupload them
    if (!has_capability('mod/assignment:grade', get_context_instance(CONTEXT_COURSE, $course->id)) and $args[4] != $USER->id) {
        print_error('Access not allowed');
    }
}
// Antoni Mas: eMail Security
if (strtolower($args[3]) == 'email') {
    // Get mail
    $email = new eMail();
    $email->set_email($args[5]);
    if (!$email->can_readmail($USER)) {
        print_error('Access not allowed');
    }
}
// security: force download of all attachments submitted by students
if (count($args) >= 3 and strtolower($args[1]) == 'moddata' and (strtolower($args[2]) == 'forum' or strtolower($args[2]) == 'assignment' or strtolower($args[2]) == 'data' or strtolower($args[2]) == 'glossary' or strtolower($args[2]) == 'wiki' or strtolower($args[2]) == 'exercise' or strtolower($args[2]) == 'workshop')) {
    $forcedownload = 1;
    // force download of all attachments
}
if ($args[0] == 'blog') {
    $forcedownload = 1;
    // force download of all attachments
}
// security: some protection of hidden resource files
// warning: it may break backwards compatibility
     foreach ($mailids as $mail) {
         $email = new eMail();
         $email->set_email($mail);
         $success &= $email->mark2read($USER->id, $courseid, true);
     }
     if ($success) {
         notify(get_string('toreadok', 'block_email_list'), 'notifysuccess');
     } else {
         notify(get_string('failmarkreaded', 'block_email_list'));
     }
     break;
 case 'tounread':
     $success = true;
     foreach ($mailids as $mail) {
         $email = new eMail();
         $email->set_email($mail);
         $success &= $email->mark2unread($USER->id, $courseid, true);
     }
     if ($success) {
         notify(get_string('tounreadok', 'block_email_list'), 'notifysuccess');
     } else {
         notify(get_string('failmarkunreaded', 'block_email_list'));
     }
     break;
 case 'move2folder':
     // In variable folderid
     $success = true;
     // Move mails -- This variable is an array of ID's
     if (is_array($mailid)) {
         foreach ($mailid as $mail) {
             // Get foldermail reference
Пример #3
0
 function definition()
 {
     global $CFG, $COURSE;
     // Get customdata
     $oldmail = $this->_customdata['oldmail'];
     $action = $this->_customdata['action'];
     $mform =& $this->_form;
     /// Print the required moodle fields first
     $mform->addElement('header', 'moodle', get_string('mail', 'block_email_list'));
     $mform->addElement('button', 'urlcc', get_string('participants', 'block_email_list') . '...', array('onclick' => "this.target='participants'; return openpopup('/blocks/email_list/email/participants.php?id={$COURSE->id}', 'participants', 'menubar=0,location=0,scrollbars=1,resizable,width=760,height=700', 0);"));
     // Mail to
     if ($CFG->email_enable_ajax) {
         $mform->addElement('html', '<div class="mform fitemtitle">' . get_string('for', 'block_email_list') . '</div>');
         // Add div html element
         $mform->addElement('html', '<div class="ajax_selected_participants">');
         // Added to allow for YUI autocomplete styling
         $mform->addElement('html', '<div class="yui-skin-sam">');
         // Change textarea to text.
         $mform->addElement('text', 'nameto', '', array('size' => '5', 'class' => 'ajax_textareacontacts'));
         // Stores the YUI autocomplete results
         $mform->addElement('static', 'qResultsTo', '', '<div id="qResultsTo"></div>');
         $mform->addElement('html', '</div>');
         // Close div html element
         $mform->addElement('html', '</div>');
     } else {
         $mform->addElement('textarea', 'nameto', get_string('for', 'block_email_list'), array('rows' => '2', 'cols' => '65', 'class' => 'textareacontacts', 'disabled' => 'true'));
     }
     // Mail cc
     if ($CFG->email_enable_ajax) {
         // Added to allow for YUI autocomplete styling
         $mform->addElement('html', '<div class="yui-skin-sam">');
         $mform->addElement('textarea', 'namecc', get_string('cc', 'block_email_list'), array('rows' => '1', 'cols' => '65', 'class' => 'textareacontacts', 'multiple' => 'multiple'));
         // Stores the YUI autocomplete results
         $mform->addElement('static', 'qResultsCC', '', '<div id="qResultsCC"></div>');
         $mform->addElement('html', '</div>');
     } else {
         $mform->addElement('textarea', 'namecc', get_string('cc', 'block_email_list'), array('rows' => '1', 'cols' => '65', 'class' => 'textareacontacts', 'disabled' => 'true'));
     }
     // Mail bcc
     if ($CFG->email_enable_ajax) {
         // Added to allow for YUI autocomplete styling
         $mform->addElement('html', '<div class="yui-skin-sam">');
         $mform->addElement('textarea', 'namebcc', get_string('bcc', 'block_email_list'), array('rows' => '1', 'cols' => '65', 'class' => 'textareacontacts', 'multiple' => 'multiple'));
         // Stores the YUI autocomplete results
         $mform->addElement('static', 'qResultsBCC', '', '<div id="qResultsBCC"></div>');
         $mform->addElement('html', '</div>');
     } else {
         $mform->addElement('textarea', 'namebcc', get_string('bcc', 'block_email_list'), array('rows' => '1', 'cols' => '65', 'class' => 'textareacontacts', 'disabled' => 'true'));
     }
     $mform->addElement('text', 'subject', get_string('subject', 'block_email_list'), 'class="emailsubject" maxlength="254" size="60"');
     $mform->setDefault('subject', '');
     $mform->addRule('subject', get_string('nosubject', 'block_email_list'), 'required', null, 'client');
     $mform->setType('nosubject', PARAM_MULTILANG);
     $this->set_upload_manager(new upload_manager('FILE', false, false, $COURSE, false, 0, true, true, false));
     // Add old attachments
     if (isset($oldmail->id)) {
         if ($oldmail->id > 0) {
             $email = new eMail();
             $email->set_email($oldmail);
             if ($email->has_attachments()) {
                 // Get mail attachments
                 $attachments = $email->get_attachments();
                 if ($attachments) {
                     $i = 0;
                     foreach ($attachments as $attachment) {
                         $mform->addElement('checkbox', 'oldattachment' . $i . 'ck', get_string('attachment', 'block_email_list'), $attachment->name);
                         $mform->setDefault('oldattachment' . $i . 'ck', true);
                         $mform->addElement('hidden', 'oldattachment' . $i, "{$attachment->path}/{$attachment->name}");
                         $i++;
                     }
                 }
             }
         }
     }
     // Upload files
     $mform->addElement('file', 'FILE_0', get_string('attachment', 'block_email_list'));
     $mform->addElement('link', 'addinput', '<img alt="' . get_string('attachment', 'block_email_list') . '" id="imgattachment" src="images/clip.gif" />', '#', get_string('anotherfile', 'block_email_list'), 'onclick="addFileInput(\'' . get_string("remove", "block_email_list") . '\');"');
     // Patch. Thanks
     /// TODO: Add all inputs files who added by user
     foreach ($_FILES as $key => $value) {
         if (substr($key, 0, strlen($key) - 1) == 'FILE_' && !$mform->elementExists($key)) {
             $mform->addElement('file', $key, '', 'value="' . $value . '"');
         }
     }
     $mform->addElement('htmleditor', 'body', get_string('body', 'block_email_list'), array('rows' => '25', 'cols' => '65'));
     $mform->setDefault('body', '');
     $mform->setType('body', PARAM_RAW);
     /// Add some extra hidden fields
     if (isset($oldmail->id)) {
         $mform->addElement('hidden', 'id', $oldmail->id);
     } else {
         $mform->addElement('hidden', 'id');
     }
     $mform->addElement('hidden', 'course', $COURSE->id);
     $mform->addElement('hidden', 'action', $action);
     $mform->addElement('hidden', 'to');
     $mform->addElement('hidden', 'cc');
     $mform->addElement('hidden', 'bcc');
     if (isset($oldmail->id)) {
         $mform->addElement('hidden', 'oldmailid', $oldmail->id);
     }
     // Add 3 buttons (Send, Draft, Cancel)
     $buttonarray = array();
     $buttonarray[] =& $mform->createElement('submit', 'send', get_string('send', 'block_email_list'));
     $buttonarray[] =& $mform->createElement('submit', 'draft', get_string('savedraft', 'block_email_list'));
     $buttonarray[] =& $mform->createElement('cancel');
     $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     $mform->closeHeaderBefore('buttonar');
 }
/**
 * This function prints all mails
 *
 * @uses $CFG, $COURSE, $SESSION
 * @param int $userid User ID
 * @param string $order Order by ...
 * @param object $options Options for url
 * @param boolean $search When show mails on search
 * @param array $mailssearch Mails who has search
 * @return boolean Success/Fail
 * @todo Finish documenting this function
 **/
function email_showmails($userid, $order = '', $page = 0, $perpage = 10, $options = NULL, $search = false, $mailssearch = NULL)
{
    global $CFG, $COURSE, $SESSION;
    // CONTRIB-690
    if (!empty($_POST['perpage']) and is_numeric($_POST['perpage'])) {
        $SESSION->email_mailsperpage = $_POST['perpage'];
    } else {
        if (!isset($SESSION->email_mailsperpage) or empty($SESSION->email_mailsperpage)) {
            $SESSION->email_mailsperpage = 10;
            // Default value
        }
    }
    require_once 'tablelib.php';
    require_once 'email.class.php';
    // Get actual course
    if (!($course = get_record("course", "id", $COURSE->id))) {
        print_error('invalidcourseid', 'block_email_list');
    }
    if ($course->id == SITEID) {
        $coursecontext = get_context_instance(CONTEXT_SYSTEM);
        // SYSTEM context
    } else {
        $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
        // Course context
    }
    $url = '';
    // Build url part options
    if ($options) {
        $url = email_build_url($options);
    }
    /// Print all mails in this HTML file
    // Should use this variable so that we don't break stuff every time a variable is added or changed.
    $baseurl = $CFG->wwwroot . '/blocks/email_list/email/index.php?' . $url . '&amp;page=' . $page . '&amp;perpage=' . $perpage;
    // Print init form from send data
    echo '<form id="sendmail" action="' . $CFG->wwwroot . '/blocks/email_list/email/index.php?id=' . $course->id . '&amp;folderid=' . $options->folderid . '" method="post" target="' . $CFG->framename . '" name="sendmail">';
    if ($course->id == SITEID) {
        $tablecolumns = array('', 'icon', 'course', 'subject', 'writer', 'timecreated');
    } else {
        $tablecolumns = array('', 'icon', 'subject', 'writer', 'timecreated');
    }
    $folder = NULL;
    if (isset($options->folderid)) {
        if ($options->folderid != 0) {
            // Get folder
            $folder = email_get_folder($options->folderid);
        } else {
            // solve problem with select an x mails per page for maintein in this folder
            if (isset($options->folderoldid) && $options->folderoldid != 0) {
                $options->folderid = $options->folderoldid;
                $folder = email_get_folder($options->folderid);
            }
        }
    }
    // If actual folder is inbox type, ... change tag showing.
    if ($folder) {
        if (email_isfolder_type($folder, EMAIL_INBOX)) {
            $strto = get_string('from', 'block_email_list');
        } else {
            $strto = get_string('to', 'block_email_list');
        }
    } else {
        $strto = get_string('from', 'block_email_list');
    }
    if ($course->id == SITEID) {
        $tableheaders = array('', '', get_string('course'), get_string('subject', 'block_email_list'), $strto, get_string('date', 'block_email_list'));
    } else {
        $tableheaders = array('', '', get_string('subject', 'block_email_list'), $strto, get_string('date', 'block_email_list'));
    }
    $table = new email_flexible_table('list-mails-' . $userid);
    $table->define_columns($tablecolumns);
    $table->define_headers($tableheaders);
    $table->define_baseurl($baseurl);
    $table->set_attribute('align', 'center');
    $table->set_attribute('width', '100%');
    $table->set_attribute('class', 'emailtable');
    $table->set_control_variables(array(TABLE_VAR_SORT => 'ssort', TABLE_VAR_HIDE => 'shide', TABLE_VAR_SHOW => 'sshow', TABLE_VAR_IFIRST => 'sifirst', TABLE_VAR_ILAST => 'silast', TABLE_VAR_PAGE => 'spage'));
    $table->sortable(true, 'timecreated', SORT_DESC);
    $table->setup();
    // When no search
    if (!$search) {
        // Get mails
        $mails = email_get_mails($userid, $course->id, $table->get_sql_sort(), '', '', $options);
    } else {
        $mails = $mailssearch;
    }
    // Define long page.
    $totalcount = count($mails);
    $table->pagesize($SESSION->email_mailsperpage, $totalcount);
    $table->inputs(true);
    // Now, re-getting emails, apply pagesize (limit)
    if (!$search) {
        // Get mails
        $mails = email_get_mails($userid, $course->id, $table->get_sql_sort(), $table->get_page_start(), $table->get_page_size(), $options);
    }
    if (!$mails) {
        $mails = array();
    }
    $mailsids = email_get_ids($mails);
    // Print all rows
    foreach ($mails as $mail) {
        $attribute = array();
        $email = new eMail();
        $email->set_email($mail);
        if ($folder) {
            if (email_isfolder_type($folder, EMAIL_SENDBOX)) {
                $struser = $email->get_users_send(has_capability('moodle/site:viewfullnames', $coursecontext));
            } else {
                if (email_isfolder_type($folder, EMAIL_INBOX)) {
                    $struser = $email->get_fullname_writer(has_capability('moodle/site:viewfullnames', $coursecontext));
                    if (!$email->is_readed($userid, $mail->course)) {
                        $attribute = array('bgcolor' => $CFG->email_table_field_color);
                    }
                } else {
                    if (email_isfolder_type($folder, EMAIL_TRASH)) {
                        $struser = $email->get_fullname_writer(has_capability('moodle/site:viewfullnames', $coursecontext));
                        if (!$email->is_readed($userid, $mail->course)) {
                            $attribute = array('bgcolor' => $CFG->email_table_field_color);
                        }
                    } else {
                        if (email_isfolder_type($folder, EMAIL_DRAFT)) {
                            $struser = $email->get_users_send(has_capability('moodle/site:viewfullnames', $coursecontext));
                            if (!$email->is_readed($userid, $mail->course)) {
                                $attribute = array('bgcolor' => $CFG->email_table_field_color);
                            }
                        } else {
                            $struser = $email->get_fullname_writer(has_capability('moodle/site:viewfullnames', $coursecontext));
                            if (!$email->is_readed($userid, $mail->course)) {
                                $attribute = array('bgcolor' => $CFG->email_table_field_color);
                            }
                        }
                    }
                }
            }
        } else {
            // Format user's
            $struser = $email->get_fullname_writer(has_capability('moodle/site:viewfullnames', $coursecontext));
            if (!$email->is_readed($userid, $mail->course)) {
                $attribute = array('bgcolor' => $CFG->email_table_field_color);
            }
        }
        if (!isset($options->folderid)) {
            $options->folderid = 0;
        }
        if (email_isfolder_type($folder, EMAIL_DRAFT)) {
            $urltosent = '<a href="' . $CFG->wwwroot . '/blocks/email_list/email/sendmail.php?id=' . $mail->id . '&amp;action=' . EMAIL_EDITDRAFT . '&amp;course=' . $course->id . '">' . $mail->subject . '</a>';
        } else {
            if ($course->id == SITEID) {
                $urltosent = '<a href="' . $CFG->wwwroot . '/blocks/email_list/email/view.php?id=' . $mail->id . '&amp;action=' . EMAIL_VIEWMAIL . '&amp;course=' . $mail->course . '&amp;folderid=' . $options->folderid . '&amp;mails=' . $mailsids . '">' . $mail->subject . '</a>';
            } else {
                $urltosent = '<a href="' . $CFG->wwwroot . '/blocks/email_list/email/view.php?id=' . $mail->id . '&amp;action=' . EMAIL_VIEWMAIL . '&amp;course=' . $course->id . '&amp;folderid=' . $options->folderid . '&amp;mails=' . $mailsids . '">' . $mail->subject . '</a>';
            }
        }
        $attachment = '';
        if ($email->has_attachments()) {
            $attachment = '<img src="' . $CFG->wwwroot . '/blocks/email_list/email/images/clip.gif" alt="attachment" /> ';
        }
        // Display diferent color if mail is reply or reply all
        $extraimginfo = '';
        if ($email->is_answered($userid, $course->id)) {
            // Color td
            unset($attribute);
            $attribute = array('bgcolor' => $CFG->email_answered_color);
            // Adding info img
            $extraimginfo = '<img src="' . $CFG->wwwroot . '/blocks/email_list/email/images/answered.gif" alt="" /> ';
        }
        if (!($course_mail = get_record("course", "id", $mail->course))) {
            print_error('invalidcourseid', 'block_email_list');
        }
        if ($course->id == SITEID) {
            $table->add_data(array('<input id="mail" type="checkbox" name="mailid[]" value="' . $mail->id . '" />', $course_mail->fullname, $attachment . $extraimginfo, $urltosent, $struser, userdate($mail->timecreated)), $attribute);
        } else {
            $table->add_data(array('<input id="mail" type="checkbox" name="mailid[]" value="' . $mail->id . '" />', $attachment . $extraimginfo, $urltosent, $struser, userdate($mail->timecreated)), $attribute);
        }
        // Save previous mail
        $previousmail = $mail->id;
    }
    $table->print_html();
    // Print select action, if have mails
    if ($mails) {
        email_print_select_options($options, $SESSION->email_mailsperpage);
    }
    // End form
    echo '</form>';
    return true;
}
Пример #5
0
$selectedusers = optional_param('selectedusers', '', PARAM_ALPHANUM);
// User who send mail
// If defined course to view
if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
    print_error('invalidcourseid', 'block_email_list');
}
if ($course->id == SITEID) {
    $coursecontext = get_context_instance(CONTEXT_SYSTEM);
    // SYSTEM context
} else {
    $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
    // Course context
}
// eMail
$email = new eMail();
$email->set_email($mailid);
require_login($course->id, false);
// No autologin guest
if (!email_is_enabled_email_list($course->id)) {
    print_error('blocknotavailable', 'block_email_list');
}
// Add log for one course
add_to_log($course->id, 'email_list', 'view mail', 'view.php?id=' . $mailid, 'View mail ' . $email->subject, 0, $USER->id);
/// Print the page header
$preferencesbutton = email_get_preferences_button($courseid);
$stremail = get_string('name', 'block_email_list');
// Add subject on information page
$stremail .= ' :: ' . $email->subject;
$PAGE->requires->js('/blocks/email_list/email/treemenu.js');
$PAGE->requires->js('/blocks/email_list/email/email.js');
$PAGE->requires->css('/blocks/email_list/email/treemenu.css');
Пример #6
0
    print_error('courseavailablenot', 'moodle');
}
$options = new stdClass();
$options->course = $course->id;
$options->folderid = 0;
$baseurl = email_build_url($options);
$PAGE->requires->css('/blocks/email_list/email/email.css');
$PAGE->set_cacheable(true);
$PAGE->set_focuscontrol('');
$PAGE->set_heading('');
// Required
$PAGE->set_title(get_string('printpreview', 'block_email_list'));
echo $OUTPUT->header($navigation);
foreach ($mailids as $mailid) {
    $email = new eMail();
    $email->set_email((int) $mailid);
    $email->display($course->id, 0, false, false, $baseurl, $USER, false);
}
echo '<script type="text/javascript">
	<!--

	var da = (document.all) ? 1 : 0;
	var pr = (window.print) ? 1 : 0;
	var mac = (navigator.userAgent.indexOf("Mac") != -1);

	if (window.addEventListener) {
	    window.addEventListener(\'load\', printWin, false);
	} else if (window.attachEvent) {
	    window.attachEvent(\'onload\', printWin);
	} else if (window.onload != null) {
	    var oldOnLoad = window.onload;