Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

<?php
App::uses('AppController', 'Controller');

/**
 * Static content controller
 *
 * Override this controller by placing a copy in controllers directory of an application
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
 */
class NewslettersController extends AppController {

/**
 * This controller does not use a model
 *
 * @var array
 */
        public $uses = array('Api');

        public function add($type='privatedeal') {
                $apiurl = Configure::read('newsletterapi');             
                $products = Cache::read($type);
        if(!isset($products) || empty($products)){
                        $products = $this->Api->getProducts($apiurl[$type]['url'],$apiurl[$type]['params']);
                        Cache::write($type,$products);
                }       
                $key = 'lists';
                $lists = Cache::read($key);
        if(!isset($lists) || empty($lists)){
                        $lists = $this->Api->getLists();
                        Cache::write($key,$lists);
                }
                if($lists['DATASET']['TYPE']=='success'){
                        $this->set('lists',$lists);
                }
                $this->set('products',$products);
        }

        public function addnewsletter() {
                if ($this->request->is('post') || $this->request->is('put')) {
                        $this->layout = 'ajax';
                        $response = $this->Api->addmessage($this->request->data['list'],$this->request->data['text'],$this->request->data['html'],$this->request->data['subject']);
                        if(!empty($response) && isset($response['DATASET']['DATA'])) {
                                $response = $this->Api->sendmessage($this->request->data['list'],$response['DATASET']['DATA']);
                                if(!empty($response) && isset($response['DATASET']['DATA'])) {
                                        $result = array('success'=>true,'message'=>'Newsletter sent successfully');                             
                                }else{
                                        $result = array('success'=>false,'message'=>'Newsletter delivery failed. Please Try again');            
                                }
                        }else{
                                $result = array('success'=>false,'message'=>'Newsletter addition failed. Please Try again');                            
                        }
                        echo json_encode($result);die;
                }
        }
}