/**
 * 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 . '&page=' . $page . '&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;
}
Ejemplo n.º 2
0
// limit list to users with some role only
if ($roleid) {
    $wheres[] = "u.id IN (SELECT userid FROM {role_assignments} WHERE roleid = :roleid AND contextid {$contextlist})";
    $params['roleid'] = $roleid;
}
$from = implode("\n", $joins);
if ($wheres) {
    $where = "WHERE " . implode(" AND ", $wheres);
} else {
    $where = "";
}
$totalcount = $DB->count_records_sql("SELECT COUNT(u.id) {$from} {$where}", $params);
// Define long page.
$table->pagesize($perpage, $totalcount);
if ($courseid) {
    $userlist = $DB->get_recordset_sql("{$select} {$from} {$where} {$sort}", $params, $table->get_page_start(), $table->get_page_size());
    if ($userlist) {
        foreach ($userlist as $user) {
            $userpic = new moodle_user_picture();
            $userpic->user = $user;
            $userpic->courseid = $courseid;
            $pic = $OUTPUT->user_picture($userpic);
            $query = $_SERVER["QUERY_STRING"];
            $link = 'compose.php?' . $query;
            $link = '#';
            $canseefullname = has_capability('moodle/site:viewfullnames', $context);
            $table->add_data(array('<a href="#" onClick="if( manageContact(\'' . email_fullname($user, $canseefullname) . '\', \'' . $user->id . '\', \'add\', \'to\')){toggleRemoveAction(\'' . $user->id . '\');}">' . $pic . '<span>' . email_fullname($user, $canseefullname) . '</span></a>', '<div id="addto' . $user->id . '" align="center"><input id="' . email_fullname($user, $canseefullname) . '" name="useridto" type="hidden" value="' . $user->id . '"><input id="addto" type="button" value="' . get_string('for', 'block_email_list') . '" onClick="if( manageContact(\'' . addslashes(email_fullname($user, $canseefullname)) . '\', \'' . $user->id . '\', \'add\', \'to\')){toggleRemoveAction(\'' . $user->id . '\');}"></div>', '<div id="addcc' . $user->id . '" align="center"><input id="' . email_fullname($user, $canseefullname) . '" name="useridcc" type="hidden" value="' . $user->id . '"><input id="addcc" type="button" value="' . get_string('cc', 'block_email_list') . '" onClick="if( manageContact(\'' . addslashes(email_fullname($user, $canseefullname)) . '\', \'' . $user->id . '\', \'add\', \'cc\')){toggleRemoveAction(\'' . $user->id . '\');}"></div>', '<div id="addbcc' . $user->id . '" align="center"><input id="' . email_fullname($user, $canseefullname) . '" name="useridbcc" type="hidden" value="' . $user->id . '"><input id="addbcc" type="button" value="' . get_string('bcc', 'block_email_list') . '" onClick="if( manageContact(\'' . addslashes(email_fullname($user, $canseefullname)) . '\', \'' . $user->id . '\', \'add\', \'bcc\')){toggleRemoveAction(\'' . $user->id . '\');}"></div>', '<div id="removeuser' . $user->id . '" style="visibility:hidden;align:center"><input id="' . email_fullname($user, $canseefullname) . '" name="useridremove" type="hidden" value="' . $user->id . '"><a href="#" onClick="if( manageContact(\'' . addslashes(email_fullname($user, $canseefullname)) . '\', \'' . $user->id . '\', \'remove\', \'\')){toggleRemoveAction(\'' . $user->id . '\');}"><img src="' . $CFG->pixpath . '/t/emailno.gif" alt="' . get_string('remove', 'block_email_list') . '" title="' . get_string('remove', 'block_email_list') . '"></a></div>'));
        }
    }
}
//------------------------- INTERFACE
Ejemplo n.º 3
0
// Initial lastname search
if ($lastinitial) {
    $sqlsearch .= ' AND lastname ' . $like . ' \'' . $lastinitial . '%\'';
}
if ($currentgroup) {
    // Displaying a group by choice
    // FIX: TODO: This will not work if $currentgroup == 0, i.e. "those not in a group"
    $from .= 'LEFT JOIN ' . $CFG->prefix . 'groups_members gm ON u.id = gm.userid ';
    $where .= ' AND gm.groupid = ' . $currentgroup;
}
$totalcount = count_records_sql('SELECT COUNT(distinct u.id) ' . $from . $where . $sqlsearch);
// Each user could have > 1
// Define long page.
$table->pagesize($perpage, $totalcount);
if ($courseid) {
    $userlist = get_records_sql($select . $from . $where . $sqlsearch . $sort, $table->get_page_start(), $table->get_page_size());
    if ($userlist) {
        foreach ($userlist as $user) {
            $pic = print_user_picture($user, $courseid, false, 30, true, false);
            $query = $_SERVER["QUERY_STRING"];
            $link = 'compose.php?' . $query;
            $link = '#';
            $canseefullname = has_capability('moodle/site:viewfullnames', $context);
            $table->add_data(array('<a href="#" onClick="if( manageContact(\'' . email_fullname($user, $canseefullname) . '\', \'' . $user->id . '\', \'add\', \'to\')){toggleRemoveAction(\'' . $user->id . '\');}">' . $pic . '<span>' . email_fullname($user, $canseefullname) . '</span></a>', '<div id="addto' . $user->id . '" align="center"><input id="' . email_fullname($user, $canseefullname) . '" name="useridto" type="hidden" value="' . $user->id . '"><input id="addto" type="button" value="' . get_string('for', 'block_email_list') . '" onClick="if( manageContact(\'' . addslashes(email_fullname($user, $canseefullname)) . '\', \'' . $user->id . '\', \'add\', \'to\')){toggleRemoveAction(\'' . $user->id . '\');}"></div>', '<div id="addcc' . $user->id . '" align="center"><input id="' . email_fullname($user, $canseefullname) . '" name="useridcc" type="hidden" value="' . $user->id . '"><input id="addcc" type="button" value="' . get_string('cc', 'block_email_list') . '" onClick="if( manageContact(\'' . addslashes(email_fullname($user, $canseefullname)) . '\', \'' . $user->id . '\', \'add\', \'cc\')){toggleRemoveAction(\'' . $user->id . '\');}"></div>', '<div id="addbcc' . $user->id . '" align="center"><input id="' . email_fullname($user, $canseefullname) . '" name="useridbcc" type="hidden" value="' . $user->id . '"><input id="addbcc" type="button" value="' . get_string('bcc', 'block_email_list') . '" onClick="if( manageContact(\'' . addslashes(email_fullname($user, $canseefullname)) . '\', \'' . $user->id . '\', \'add\', \'bcc\')){toggleRemoveAction(\'' . $user->id . '\');}"></div>', '<div id="removeuser' . $user->id . '" style="visibility:hidden;align:center"><input id="' . email_fullname($user, $canseefullname) . '" name="useridremove" type="hidden" value="' . $user->id . '"><a href="#" onClick="if( manageContact(\'' . addslashes(email_fullname($user, $canseefullname)) . '\', \'' . $user->id . '\', \'remove\', \'\')){toggleRemoveAction(\'' . $user->id . '\');}"><img src="' . $CFG->pixpath . '/t/emailno.gif" alt="' . get_string('remove', 'block_email_list') . '" title="' . get_string('remove', 'block_email_list') . '"></a></div>'));
        }
    }
}
//------------------------- INTERFACE
// Print html
echo '<html>
	<body>';