cmc-sales/controllers/emails_controller.php
2011-03-10 18:18:26 +11:00

106 lines
2.2 KiB
PHP
Executable file

<?php
class EmailsController extends AppController {
var $name = 'Emails';
var $helpers = array('Html', 'Form', 'Number', 'Text', 'Link');
var $components = array('RequestHandler');
var $paginate = array(
'contain' => false,
'limit' => 150,
'order'=>array('Email.id' => 'desc')
);
function index() {
$this->Email->recursive = 0;
$this->set('emails', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Email.', true));
$this->redirect(array('action'=>'index'));
}
$email = $this->Email->read(null, $id);
$this->set('email', $email);
$this->set('recipients', $this->Email->EmailRecipient->getRecipients($id));
/*$recQuery = array("OR" => array("User.id"=> array()));
foreach($email['EmailRecipient'] as $rec) {
$recQuery["OR"]["User.id"][] = $rec['id'];
}
$users = $this->Email->User->find('all', array('conditions'=>$recQuery));
$this->set('users',$users);/*
*
*/
//print_r($users);
//print_r($recQuery);
$body_ID = $this->findBodyID($email['EmailAttachment']);
$this->set('body_ID', $body_ID);
}
/**
* Returns the email_attachment ID of the first HTML attachment.
*
*
* @param <type> $email_attachments
* @return <type>
*/
function findBodyID($email_attachments) {
foreach($email_attachments as $attachment) {
if($attachment['is_message_body'] == 1) {
return $attachment['id'];
}
}
return false;
}
function frame($id = null) {
$email = $this->Email->find('first', array('conditions'=>array('Email.id'=>$id)));
$body_ID = $this->findBodyID($email['EmailAttachment']);
$this->set('body_ID', $body_ID);
$this->set('recipients', $this->Email->EmailRecipient->getRecipients($id));
$this->set('email', $email);
}
/* old shit here, Might be useful */
function show($id = null) {
$this->layout = 'minimal';
$this->set('email', $this->Email->read(null, $id));
}
/* Violates DRY. Should probably clean this up at some point */
function printview($id = null) {
$this->layout = 'minimal';
$this->set('email', $this->Email->read(null, $id));
}
}
?>