Xataface Email Module  0.3.2
Email/Mailmerge Module for Xataface
 All Data Structures Files Functions Variables Pages
email_cancel_job.php
Go to the documentation of this file.
1 <?php
3  const PERMISSION_DENIED = 8401.0;
4  const JOB_NOT_FOUND = 8404.1;
5  const EMAIL_NOT_FOUND = 8404.2;
6 
7 
8 
9  function handle($params){
10  session_write_close();
11  header('Connection:close');
12  $app = Dataface_Application::getInstance();
13  $query = $app->getQuery();
14 
15  try {
16 
17  if ( !@$query['--job-id'] ){
18  throw new Exception("No job ID specified");
19  }
20 
21  $job = df_get_record('xataface__email_jobs', array('job_id'=>'='.$query['--job-id']));
22  if ( !$job ){
23  throw new Exception("Job could not be found", self::JOB_NOT_FOUND);
24  }
25 
26  $email = df_get_record('xataface__email_newsletters', array('id'=>'='.$job->val('email_id')));
27  if ( !$email ){
28  throw new Exception("Email could not be found", self::EMAIL_NOT_FOUND);
29  }
30 
31 
32 
33  if ( !$job->checkPermission('cancel email job') or !$email->checkPermission('cancel email job') ){
34  throw new Exception("You don't have permission to cancel this job", self::PERMISSION_DENIED);
35  }
36 
37 
38  df_q("update xataface__email_jobs set cancelled=1 where job_id='".addslashes($query['--job-id'])."'");
39 
40  $this->out(array(
41  'code' => 200,
42  'message' => 'Successfully cancelled job'
43  ));
44 
45  } catch (Exception $ex){
46 
47  if ( $ex->getCode() > 8000 and $ex->getCode() < 9000 ){
48  $this->out(array(
49  'code' => intval($ex->getCode()-8000),
50  'message' => $ex->getMessage()
51  ));
52  } else {
53  throw $ex;
54  }
55  }
56  }
57 
58 
59  function out($out){
60  header('Content-type: text/json; charset="'.Dataface_Application::getInstance()->_conf['oe'].'"');
61  echo json_encode($out);
62 
63  }
64 }