cmc-sales/controllers/emails_controller.php

143 lines
3.1 KiB
PHP
Raw Normal View History

2009-02-09 14:25:49 -08:00
<?php
class EmailsController extends AppController {
2011-03-09 23:18:26 -08:00
var $name = 'Emails';
var $helpers = array('Html', 'Form', 'Number', 'Text', 'Link');
var $components = array('RequestHandler');
2009-02-09 14:25:49 -08:00
2011-03-09 23:18:26 -08:00
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'));
2009-02-09 14:25:49 -08:00
}
2011-03-09 23:18:26 -08:00
$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'];
2009-02-09 14:25:49 -08:00
}
2011-03-09 23:18:26 -08:00
$users = $this->Email->User->find('all', array('conditions'=>$recQuery));
$this->set('users',$users);/*
*
*/
2009-02-09 14:25:49 -08:00
2011-03-09 23:18:26 -08:00
//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'];
}
}
2011-03-09 23:18:26 -08:00
return false;
2011-03-09 23:18:26 -08:00
}
2011-03-09 23:18:26 -08:00
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);
}
}
2011-03-09 23:18:26 -08:00
/* 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));
}
2009-02-09 14:25:49 -08:00
}
?>