$options->filterid = $filterid;
$options->folderoldid = $folderoldid;
/// 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>&#160;</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 {
Exemplo n.º 2
0
     if ($success) {
         echo $OUTPUT->notification(get_string('cleantrashok', 'block_email_list'), '');
     } else {
         echo $OUTPUT->notification(get_string('cleantrashfail', 'block_email_list'), '');
     }
     $options->folderid = $id;
     $options->folderoldid = 0;
     email_showmails($USER->id, '', 0, 10, $options);
     break;
 case md5('edit'):
     // 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);
     }
     $mform = new folder_form('folder.php', array('id' => $id, 'action' => $action, 'course' => $courseid));
     $folder = email_get_folder($id);
     $folder->foldercourse = $folder->course;
     unset($folder->course);
     $mform->set_data($folder);
     if ($data = $mform->get_data()) {
         $updatefolder = new stdClass();
         // Clean name
         $updatefolder->name = strip_tags($data->name);
         // Add user and course
         $updatefolder->userid = $USER->id;
         $updatefolder->course = $data->foldercourse;
         // Add id
         $updatefolder->id = $data->id;
         /// Update folder
         // Get old folder params
         if (!($oldfolder = $DB->get_record('block_email_list_folder', array('id' => $data->id)))) {
/**
 * 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;
            }
        }
    }
}
Exemplo n.º 4
0
/**
 * 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 '&#160;&#160;';
    // 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>';
}