/// Print the main part of the page // Print principal table. This have 2 columns . . . and possibility to add right column. echo '<table id="layout-table"> <tr>'; // Print "blocks" of this account echo '<td style="width: 180px;" id="left-column">'; email_printblocks($USER->id, $courseid); // Close left column echo '</td>'; // Print principal column echo '<td id="middle-column">'; // Get actual folder, for show if (!($folder = email_get_folder($folderoldid))) { if (!($folder = email_get_folder($folderid))) { // Default, is inbox $folder = email_get_root_folder($USER->id, EMAIL_INBOX); } } // Print middle table print_heading_block(get_string('mailbox', 'block_email_list') . ': ' . $folder->name); echo '<div> </div>'; // Print tabs options email_print_tabs_options($courseid, $folderid); /// Prepare action if (!empty($action) and $mailid > 0) { // When remove an mail, this functions only accept array in param, overthere converting this param ... if (!is_array($mailid)) { $mailids = array($mailid); } else { $mailids = $mailid; }
/** * This functions return number of unreaded mails * * @uses $CFG * @param int $userid User ID * @param int $courseid Course ID * @param int $folderid Folder ID (Optional) When fault this param, return total number of unreaded mails * @return int Number of unread mails. * @todo Finish documenting this function **/ function email_count_unreaded_mails($userid, $courseid, $folderid = NULL) { global $CFG; if (!$folderid or $folderid <= 0) { // Get draft folder if ($folder = email_get_root_folder($userid, EMAIL_INBOX)) { $foldersid = $folder->id; // Get all subfolders if ($subfolders = email_get_all_subfolders($folder->id)) { foreach ($subfolders as $subfolder) { $foldersid .= ', ' . $subfolder->id; } } $sql = "SELECT count(*)\n\t\t FROM {$CFG->prefix}email_mail m\n\t\t LEFT JOIN {$CFG->prefix}email_send s ON m.id = s.mailid\n\t\t LEFT JOIN {$CFG->prefix}email_foldermail fm ON m.id = fm.mailid "; // WHERE principal clause for filter by user and course $wheresql = " WHERE s.userid = {$userid}\n\t\t\t\t\t\t AND s.course = {$courseid}\n\t\t\t\t\t\t AND fm.folderid IN ( {$foldersid} )\n\t\t\t\t\t\t AND s.readed = 0\n\t\t\t\t\t\t AND s.sended = 1"; return count_records_sql($sql . $wheresql); } else { return 0; } // return mails unreaded // wreturn count_records('email_send', 'userid', $userid, 'course', $courseid, 'readed', 0); } else { // Get folder if (!($folder = email_get_folder($folderid))) { return 0; } if (email_isfolder_type($folder, EMAIL_INBOX)) { // For apply order, I've writting an sql clause $sql = "SELECT count(*)\n\t\t FROM {$CFG->prefix}email_mail m\n\t\t LEFT JOIN {$CFG->prefix}email_send s ON m.id = s.mailid\n\t\t LEFT JOIN {$CFG->prefix}email_foldermail fm ON m.id = fm.mailid "; // WHERE principal clause for filter by user and course $wheresql = " WHERE s.userid = {$userid}\n\t\t\t\t\t\t AND s.course = {$courseid}\n\t\t\t\t\t\t AND fm.folderid = {$folder->id}\n\t\t\t\t\t\t AND s.readed = 0\n\t\t\t\t\t\t AND s.sended = 1"; return count_records_sql($sql . $wheresql); } else { if (email_isfolder_type($folder, EMAIL_DRAFT)) { // For apply order, I've writting an sql clause $sql = "SELECT count(*)\n\t\t \tFROM {$CFG->prefix}email_mail m\n\t\t \tLEFT JOIN {$CFG->prefix}email_foldermail fm ON m.id = fm.mailid "; // WHERE principal clause for filter user and course $wheresql = " WHERE m.userid = {$userid}\n\t\t\t\t\t\t AND m.course = {$courseid}\n\t\t\t\t\t\t AND fm.folderid = {$folder->id}"; return count_records_sql($sql . $wheresql); } else { return 0; } } } }
/** * Function to be run periodically according to the moodle cron * This function searches for things that need to be done, such * as sending out mail, toggling flags etc ... * * @uses $CFG * @return boolean * @todo Finish documenting this function **/ function cron() { global $CFG; // If no isset trackbymail, return cron. if (!isset($CFG->email_trackbymail)) { return true; } // If NOT enabled if ($CFG->email_trackbymail == 0) { return true; } // Get actualtime $now = time(); // Get record for mail list if ($block = get_record('block', 'name', 'email_list')) { if ($now > $block->lastcron) { $unreadmails = new stdClass(); // Get users who have unread mails $from = "{$CFG->prefix}user u,\n\t\t\t\t\t\t {$CFG->prefix}block_email_list_send s,\n\t\t\t\t\t\t {$CFG->prefix}block_email_list_mail m"; $where = " WHERE u.id = s.userid\n\t\t\t\t\t\t\t\tAND s.mailid = m.id\n\t\t\t\t\t\t\t\tAND m.timecreated > {$block->lastcron}\n\t\t\t\t\t\t\t\tAND s.readed = 0\n\t\t\t\t\t\t\t\tAND s.sended = 1"; // If exist any users if ($users = get_records_sql('SELECT u.* FROM ' . $from . $where)) { // For each user ... get this unread mails, and send alert mail. foreach ($users as $user) { $mails = new stdClass(); // Preferences! Can send mail? // Case: // 1.- Site allow send trackbymail // 1.1.- User doesn't define this settings -> Send mail // 1.2.- User allow trackbymail -> Send mail // 1.3.- User denied trackbymail -> Don't send mail // User can definied this preferences? if ($preferences = get_record('block_email_list_preference', 'userid', $user->id)) { if ($preferences->trackbymail == 0) { continue; } } // Get this unread mails if ($mails = email_get_unread_mails($user->id)) { $bodyhtml = '<head>'; foreach ($CFG->stylesheets as $stylesheet) { $bodyhtml .= '<link rel="stylesheet" type="text/css" href="' . $stylesheet . '" />' . "\n"; } $bodyhtml .= '</head>'; $bodyhtml .= "\n<body id=\"email\">\n\n"; $bodyhtml .= '<div class="content">' . get_string('listmails', 'block_email_list') . ": </div>\n\n"; $body = get_string('listmails', 'block_email_list') . ": \n\n"; $bodyhtml .= '<table border="0" cellpadding="3" cellspacing="0">'; $bodyhtml .= '<th class="header">' . get_string('course') . '</th>'; $bodyhtml .= '<th class="header">' . get_string('subject', 'block_email_list') . '</th>'; $bodyhtml .= '<th class="header">' . get_string('from', 'block_email_list') . '</th>'; $bodyhtml .= '<th class="header">' . get_string('date', 'block_email_list') . '</th>'; // Prepare messagetext foreach ($mails as $mail) { // Get folder $folder = email_get_root_folder($mail->userid, EMAIL_SENDBOX); if (!email_isfolder_type($folder, EMAIL_SENDBOX)) { continue; } if (isset($mail->mailid)) { $message = get_record('block_email_list_mail', 'id', $mail->mailid); $mailcourse = get_record('course', 'id', $mail->course); $body .= "---------------------------------------------------------------------\n"; $body .= get_string('course') . ": {$mailcourse->fullname} \n"; $body .= get_string('subject', 'block_email_list') . ": {$message->subject} \n"; $body .= get_string('from', 'block_email_list') . ": " . fullname(email_get_user($message->id)); $body .= " - " . userdate($message->timecreated) . "\n"; $body .= "---------------------------------------------------------------------\n\n"; $bodyhtml .= '<tr class="r0">'; $bodyhtml .= '<td class="cell c0">' . $mailcourse->fullname . '</td>'; $bodyhtml .= '<td class="cell c0">' . $message->subject . '</td>'; $bodyhtml .= '<td class="cell c0">' . fullname(email_get_user($message->id)) . '</td>'; $bodyhtml .= '<td class="cell c0">' . userdate($message->timecreated) . '</td>'; $bodyhtml .= '</tr>'; } } $bodyhtml .= '</table>'; $bodyhtml .= '</body>'; $body .= "\n\n\n\n"; email_to_user($user, get_string('emailalert', 'block_email_list'), get_string('emailalert', 'block_email_list') . ': ' . get_string('newmails', 'block_email_list'), $body, $bodyhtml); } } } } return true; } else { mtrace('FATAL ERROR: I couldn\'t read eMail list block'); return false; } }
switch ($action) { case md5('admin'): $hassubfolders = email_print_administration_folders($options); if (!$hassubfolders) { // Can create subfolders? if (!has_capability('block/email_list:createfolder', $context)) { print_error('forbiddencreatefolder', 'block_email_list', $CFG->wwwroot . '/blocks/email_list/email/index.php?id=' . $course->id); } // Print form to new folder echo $OUTPUT->notification(get_string('nosubfolders', 'block_email_list'), ''); $mform = new folder_form('folder.php', array('id' => $id, 'course' => $courseid, 'action' => '')); $mform->display(); } break; case 'cleantrash': $trash = email_get_root_folder($USER->id, EMAIL_TRASH); /// If necessary, delete mail and delete attachments $options->folderid = $trash->id; $success = true; $mails = email_get_mails($USER->id, $course->id, NULL, '', '', $options); // Delete reference mails $DB->delete_records('block_email_list_foldermail', array('folderid' => $trash->id)); // Get all trash mails if ($mails) { foreach ($mails as $mail) { // if mailid exist, continue ... if ($DB->get_records('block_email_list_foldermail', array('mailid' => $mail->id))) { continue; } else { // Mail is not reference by never folder (not possibility readed) if (email_delete_attachments($mail->id) and $DB->delete_records('block_email_list_mail', array('id' => $mail->id))) {
function definition_after_data() { global $USER; // Drop actualfolder if it proceding... $mform =& $this->_form; // Get parentfolder $parentfolder =& $mform->getElementValue('parentfolder'); // Get (actual) folderid $folderid =& $mform->getElementValue('id'); // Drop element. $mform->removeElement('parentfolder'); // Get root folders $folders = email_get_my_folders($USER->id, $mform->getElementValue('course'), true, true); // Get inbox, there default option on menu $inbox = email_get_root_folder($USER->id, EMAIL_INBOX); $menu = array(); // Insert into menu, only name folder foreach ($folders as $key => $foldername) { if ($key != $folderid) { $menu[$key] = $foldername; } } // Select parent folder $select =& MoodleQuickForm::createElement('select', 'parentfolder', get_string('linkto', 'block_email_list'), $menu); $mform->insertElementBefore($select, 'gost'); $mform->setDefault('parentfolder', $parentfolder); }
/** * This function prints select folders combobox, for move any mails * * @uses $USER * @param object $options */ function email_print_movefolder_button($options) { global $CFG, $USER; $courseid = NULL; if ($options->id == SITEID and $options->course != SITEID) { $courseid = $options->course; } else { $courseid = $options->id; } /// TODO: Changed this function, now cases are had: // 1.- Inbox folder: Only can move to subfolders inbox and trash folder. // 2.- Sendbox and draft folder: Only can move on this subfolders. // 3.- Trash folder: Can move any folder if (isset($options->folderid)) { // Get folder $folderbe = email_get_folder($options->folderid); } else { if (isset($options->folderoldid)) { // Get folder $folderbe = email_get_folder($options->folderoldid); } else { // Inbox folder $folderbe = email_get_root_folder($USER->id, EMAIL_INBOX); } } if (email_isfolder_type($folderbe, EMAIL_SENDBOX)) { // Get my sendbox folders $folders = email_get_my_folders($USER->id, $courseid, false, true, false, true); } else { if (email_isfolder_type($folderbe, EMAIL_DRAFT)) { // Get my sendbox folders $folders = email_get_my_folders($USER->id, $courseid, false, true, true, true); } else { if (email_isfolder_type($folderbe, EMAIL_TRASH)) { // Get my folders $folders = email_get_my_folders($USER->id, $courseid, false, false, false, false); } else { // Get my folders $folders = email_get_my_folders($USER->id, $courseid, false, true, true, false); } } } if ($folders) { $choose = ''; // Get my courses foreach ($folders as $key => $foldername) { $choose .= '<option value="' . $key . '">' . $foldername . '</option>'; } } echo '<select name="folderid" onchange="addAction(this)"> <option value="" selected="selected">' . get_string('movetofolder', 'block_email_list') . ':</option>' . $choose . ' </select>'; // Add 2 space echo '  '; // Change, now folderoldid is actual folderid if (!$options->folderid) { if ($inbox = email_get_root_folder($USER->id, EMAIL_INBOX)) { echo '<input type="hidden" name="folderoldid" value="' . $inbox->id . '" />'; } } else { echo '<input type="hidden" name="folderoldid" value="' . $options->folderid . '" />'; } // Define action //echo '<input type="hidden" name="action" value="move2folder" />'; // Add javascript for insert person/s who I've send mail $javascript = '<script type="text/javascript" language="JavaScript"> <!-- function addAction(form) { var d = document.createElement("div"); d.setAttribute("id", "action"); var act = document.createElement("input"); act.setAttribute("type", "hidden"); act.setAttribute("name", "action"); act.setAttribute("id", "action"); act.setAttribute("value", "move2folder"); d.appendChild(act); document.getElementById("move2folder").appendChild(d); document.sendmail.submit(); } --> </script>'; echo $javascript; // Print sent button //echo '<input type="submit" value="' .get_string('move'). '" onclick="javascript:addAction(this);" />'; //echo '</div>'; }
/** * This function insert reference mail <-> folder. There apply filters. * * @access private * @version 1.0 * @param int $userid User Id * @param string $foldername Folder name * @return boolean Success/Fail * @todo Finish documenting this function **/ function reference_mail_folder($userid, $foldername) { $foldermail = new stdClass(); $foldermail->mailid = $this->id; $folder = email_get_root_folder($userid, $foldername); $foldermail->folderid = $folder->id; // Insert into inbox user if (!insert_record('block_email_list_foldermail', $foldermail)) { return false; } return true; }
/** * This function remove eMail, if this does in TRASH folder remove of BBDD else move to TRASH folder. * * @param int $userid User Id * @param int $courseid Course Id * @param int $folderid Folder Id * @param boolean $silent Show or not show messages * @return boolean Success/Fail * @todo Finish documenting this function */ function remove($userid, $courseid, $folderid, $silent = false) { // First, show if folder remove or not $deletemails = false; $success = true; if (email_isfolder_type(get_record('email_folder', 'id', $folderid), EMAIL_TRASH)) { $deletemails = true; } // FIXME: Esborrar els attachments quan no hagi cap referència al mail // If delete definity mails ... if ($deletemails) { // Delete reference mail if (!delete_records('email_send', 'mailid', $this->id, 'userid', $userid, 'course', $courseid)) { return false; } } else { // Get remove folder user $removefolder = email_get_root_folder($userid, EMAIL_TRASH); // Get actual folder $actualfolder = email_get_reference2foldermail($this->id, $folderid); if ($actualfolder) { // Move mails to trash if (!email_move2folder($this->id, $actualfolder->id, $removefolder->id)) { $success = false; } else { // Mark the message as read set_field('email_send', 'readed', 1, 'mailid', $this->id, 'userid', $userid, 'course', $courseid); //Thanks Ann } } else { $success = false; } } // Notify if ($success) { add_to_log($this->course, 'email', 'remove mail', '', 'Remove ' . $this->subject, 0, $this->userid); if (!$silent) { notify(get_string('removeok', 'block_email_list'), 'notifysuccess'); } return true; } else { if (!$silent) { notify(get_string('removefail', 'block_email_list')); } return false; } }