![]() |
Xataface Email Module 0.3
Email/Mailmerge Module for Xataface
|
00001 <?php 00002 class actions_email_cancel_job { 00003 const PERMISSION_DENIED = 8401.0; 00004 const JOB_NOT_FOUND = 8404.1; 00005 const EMAIL_NOT_FOUND = 8404.2; 00006 00007 00008 00009 function handle($params){ 00010 session_write_close(); 00011 header('Connection:close'); 00012 $app = Dataface_Application::getInstance(); 00013 $query = $app->getQuery(); 00014 00015 try { 00016 00017 if ( !@$query['--job-id'] ){ 00018 throw new Exception("No job ID specified"); 00019 } 00020 00021 $job = df_get_record('xataface__email_jobs', array('job_id'=>'='.$query['--job-id'])); 00022 if ( !$job ){ 00023 throw new Exception("Job could not be found", self::JOB_NOT_FOUND); 00024 } 00025 00026 $email = df_get_record('xataface__email_newsletters', array('id'=>'='.$job->val('email_id'))); 00027 if ( !$email ){ 00028 throw new Exception("Email could not be found", self::EMAIL_NOT_FOUND); 00029 } 00030 00031 00032 00033 if ( !$job->checkPermission('cancel email job') or !$email->checkPermission('cancel email job') ){ 00034 throw new Exception("You don't have permission to cancel this job", self::PERMISSION_DENIED); 00035 } 00036 00037 00038 df_q("update xataface__email_jobs set cancelled=1 where job_id='".addslashes($query['--job-id'])."'"); 00039 00040 $this->out(array( 00041 'code' => 200, 00042 'message' => 'Successfully cancelled job' 00043 )); 00044 00045 } catch (Exception $ex){ 00046 00047 if ( $ex->getCode() > 8000 and $ex->getCode() < 9000 ){ 00048 $this->out(array( 00049 'code' => intval($ex->getCode()-8000), 00050 'message' => $ex->getMessage() 00051 )); 00052 } else { 00053 throw $ex; 00054 } 00055 } 00056 } 00057 00058 00059 function out($out){ 00060 header('Content-type: text/json; charset="'.Dataface_Application::getInstance()->_conf['oe'].'"'); 00061 echo json_encode($out); 00062 00063 } 00064 }