143 lines
3.1 KiB
PHP
Executable file
143 lines
3.1 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);
|
|
}
|
|
|
|
|
|
/**
|
|
* Fetch all the Emails that are from, to, cc a User ID
|
|
*
|
|
* @param <type> $id
|
|
* @return <type>
|
|
*/
|
|
function view_user_emails($id) {
|
|
if(!$id) {
|
|
return;
|
|
}
|
|
else {
|
|
//$this->set('emails', $this->paginate());
|
|
$fromMailIDs = $this->Email->find('list', array('conditions'=>array('Email.user_id'=>$id)));
|
|
$recMailIDs = $this->Email->EmailRecipient->find('list', array('conditions'=>array('EmailRecipient.user_id'=>$id)));
|
|
|
|
$allIDs = $fromMailIDs + $recMailIDs;
|
|
|
|
sort($allIDs);
|
|
|
|
$this->set('allIDs', $allIDs);
|
|
|
|
|
|
|
|
$this->paginate = array(
|
|
'conditions' => array('Email.id'=>$allIDs),
|
|
'order'=>array('Email.udate DESC')
|
|
);
|
|
|
|
|
|
$userMail = $this->paginate('Email');
|
|
//$userMail = $this->Email->find('all', array('conditions'=>array('Email.id'=>$allIDs), 'order'=>array('Email.udate DESC')));
|
|
$this->set('userMail', $userMail);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
?>
|