4 * Model for sending out reports in different ways
6 class Send_report_Model
extends Model
{
8 * @param $data The actual data to send
9 * @param $filename The filename to use when sending this
10 * @param $format The filetype - 'pdf', 'csv' or 'html'
11 * @param $recipient one email or a string composed of comma separated strings
12 * @throws RuntimeException if file is not readable
15 static function send($data, $filename, $format, $recipient)
19 if (strstr($to, ',')) {
20 $recipient = explode(',', $to);
21 if (is_array($recipient) && !empty($recipient)) {
23 foreach ($recipient as $user) {
29 $config = Kohana
::config('reports');
30 $mail_sender_address = $config['from_email'];
32 if (!empty($mail_sender_address)) {
33 $from = $mail_sender_address;
35 $hostname = exec('hostname --long');
36 $from = !empty($config['from']) ?
$config['from'] : Kohana
::config('config.product_name');
37 $from = str_replace(' ', '', trim($from));
38 if (empty($hostname) && $hostname != '(none)') {
39 // unable to get a valid hostname
40 $from = $from . '@localhost';
42 $from = $from . '@'.$hostname;
46 $plain = sprintf(_('Scheduled report sent from %s'),!empty($config['from']) ?
$config['from'] : $from);
47 $subject = _('Scheduled report').": $filename";
51 $mime = 'application/pdf';
54 $mime = 'application/csv';
57 $mime = 'application/csv';
60 $mime = 'application/binary';
64 # $mail_sent will contain the nr of mail sent - not used at the moment
65 $mail_sent = email
::send_report($to, $from, $subject, $plain, $mime, $filename, $data);
67 return (boolean
) $mail_sent;