Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12345 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
 
4
/**
5
 * Static content controller
6
 *
7
 * Override this controller by placing a copy in controllers directory of an application
8
 *
9
 * @package       app.Controller
10
 * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
11
 */
12
class NewslettersController extends AppController {
13
 
14
/**
15
 * This controller does not use a model
16
 *
17
 * @var array
18
 */
19
	public $uses = array('Api');
20
 
21
	public function add($type='privatedeal') {
22
		$apiurl = Configure::read('newsletterapi');		
23
		$products = Cache::read($type);
24
        if(!isset($products) || empty($products)){
25
			$products = $this->Api->getProducts($apiurl[$type]['url'],$apiurl[$type]['params']);
26
			Cache::write($type,$products);
27
		}	
28
		$key = 'lists';
29
		$lists = Cache::read($key);
30
        if(!isset($lists) || empty($lists)){
31
			$lists = $this->Api->getLists();
32
			Cache::write($key,$lists);
33
		}
34
		if($lists['DATASET']['TYPE']=='success'){
35
			$this->set('lists',$lists);
36
		}
37
		$this->set('products',$products);
38
	}
39
 
40
	public function addnewsletter() {
41
		if ($this->request->is('post') || $this->request->is('put')) {
42
			$this->layout = 'ajax';
43
			$response = $this->Api->addmessage($this->request->data['list'],$this->request->data['text'],$this->request->data['html'],$this->request->data['subject']);
44
			if(!empty($response) && isset($response['DATASET']['DATA'])) {
45
				$response = $this->Api->sendmessage($this->request->data['list'],$response['DATASET']['DATA']);
46
				if(!empty($response) && isset($response['DATASET']['DATA'])) {
47
					$result = array('success'=>true,'message'=>'Newsletter sent successfully');				
48
				}else{
49
					$result = array('success'=>false,'message'=>'Newsletter delivery failed. Please Try again');		
50
				}
51
			}else{
52
				$result = array('success'=>false,'message'=>'Newsletter addition failed. Please Try again');				
53
			}
54
			echo json_encode($result);die;
55
		}
56
	}
57
}