Exemplo n.º 1
0
function local_mail_downloadall($message) {
    $attachments = local_mail_attachments($message);
    if (count($attachments) > 1) {
        foreach ($attachments as $attach) {
            $filename = clean_filename($attach->get_filename());
            $filesforzipping[$filename] = $attach;
        }
        $filename = clean_filename(fullname($message->sender()) . '-' .
                                   $message->subject() . '.zip');
        if ($zipfile = pack_files($filesforzipping)) {
            send_temp_file($zipfile, $filename);
        }
    }
}
Exemplo n.º 2
0
    public function mail($message, $reply = false, $offset = 0) {
        global $CFG, $USER;

        $totalusers = 0;
        $output = '';

        if (!$reply) {
            $output .= html_writer::empty_tag('input', array(
                    'type' => 'hidden',
                    'name' => 'm',
                    'value' => $message->id(),
            ));

            $output .= html_writer::empty_tag('input', array(
                    'type' => 'hidden',
                    'name' => 'offset',
                    'value' => $offset,
            ));
        }

        $output .= $this->output->container_start('mail_header');
        $output .= $this->output->container_start('left');
        $output .= $this->output->user_picture($message->sender());
        $output .= $this->output->container_end();
        $output .= $this->output->container_start('mail_info');
        $output .= html_writer::link(new moodle_url('/user/view.php',
                                            array(
                                                'id' => $message->sender()->id,
                                                'course' => $message->course()->id
                                            )),
                                    fullname($message->sender()),
                                    array('class' => 'user_from'));
        $output .= $this->date($message, true);
        if (!$reply) {
            $output .= $this->output->container_start('mail_recipients');
            foreach (array('to', 'cc', 'bcc') as $role) {
                $recipients = $message->recipients($role);
                if (!empty($recipients)) {
                    if ($role == 'bcc' and $message->sender()->id !== $USER->id) {
                        continue;
                    }
                    $output .= html_writer::start_tag('div');
                    $output .= html_writer::tag('span', get_string($role, 'local_mail'), array('class' => 'mail_role'));
                    $numusers = count($recipients);
                    $totalusers += $numusers;
                    $cont = 1;
                    foreach ($recipients as $user) {
                        $output .= html_writer::link(new moodle_url('/user/view.php',
                                            array(
                                                'id' => $user->id,
                                                'course' => $message->course()->id
                                            )),
                                            fullname($user));
                        if ($cont < $numusers) {
                            $output .= ', ';
                        }
                        $cont += 1;
                    }
                    $output .= ' ';
                    $output .= html_writer::end_tag('div');
                }
            }
            $output .= $this->output->container_end();
        } else {
            $output .= html_writer::tag('div', '', array('class' => 'mail_recipients'));
        }
        $output .= $this->output->container_end();
        $output .= $this->output->container_end();

        $output .= $this->output->container_start('mail_body');
        $output .= $this->output->container_start('mail_content');
        $output .= local_mail_format_content($message);
        $attachments = local_mail_attachments($message);
        if ($attachments) {
            $output .= $this->output->container_start('mail_attachments');
            if (count($attachments) > 1) {
                $text = get_string('attachnumber', 'local_mail', count($attachments));
                $output .= html_writer::tag('span', $text, array('class' => 'mail_attachment_text'));
                $downloadurl = new moodle_url($this->page->url, array('downloadall' => '1'));
                $iconimage = $this->output->pix_icon('a/download_all', get_string('downloadall', 'local_mail'), 'moodle', array('class' => 'icon'));
                $output .= html_writer::start_div('mail_attachment_downloadall');
                $output .= html_writer::link($downloadurl, $iconimage);
                $output .= html_writer::link($downloadurl, get_string('downloadall', 'local_mail'), array('class' => 'mail_downloadall_text'));
                $output .= html_writer::end_div();
            }
            foreach ($attachments as $attach) {
                $filename = $attach->get_filename();
                $filepath = $attach->get_filepath();
                $mimetype = $attach->get_mimetype();
                $iconimage = $this->output->pix_icon(file_file_icon($attach), get_mimetype_description($attach), 'moodle', array('class' => 'icon'));
                $path = '/'.$attach->get_contextid().'/local_mail/message/'.$attach->get_itemid().$filepath.$filename;
                $fullurl = moodle_url::make_file_url('/pluginfile.php', $path, true);
                $output .= html_writer::start_tag('div', array('class' => 'mail_attachment'));
                $output .= html_writer::link($fullurl, $iconimage);
                $output .= html_writer::link($fullurl, s($filename));
                $output .= html_writer::tag('span', display_size($attach->get_filesize()), array('class' => 'mail_attachment_size'));
                $output .= html_writer::end_tag('div');
            }
            $output .= $this->output->container_end();
        }
        $output .= $this->output->container_end();
        $output .= $this->newlabelform();
        if (!$reply) {
            if ($message->sender()->id !== $USER->id) {
                $output .= $this->toolbar('reply', $message->course()->id, array('replyall' => ($totalusers > 1)));
            } else {
                $output .= $this->toolbar('forward', $message->course()->id);
            }
        }
        $output .= $this->output->container_end();
        return $output;
    }