<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class SmsMarketing extends CI_Controller {

    public function __construct(){
        parent::__construct();

        if(!isset($_SESSION['login'])){
        	
        	redirect('Welcome');
        }
    }


    public function insertSmsMarketingPackage(){
        $this->load->view('user/add-sms-package');
    }

    public function submitSmsPackage(){
        $this->form_validation->set_rules('title', 'Title', 'required');
		$this->form_validation->set_rules('price', 'Price', 'required');
        $this->form_validation->set_rules('type', 'Type', 'required');
        $this->form_validation->set_rules('description', 'Description', 'required');
        
        if ($this->form_validation->run() == FALSE){

			$this->session->set_flashdata('error', 'Set Title, Price, Type and Description Field');

        	redirect("user/SmsMarketing/insertSmsMarketingPackage");
                
        }
        else{
            $data = array(
                'title' => $this->input->post('title'),
                'price' => $this->input->post('price'),
                'type' => $this->input->post('type'),
                'description' => $this->input->post('description')
            );

            $this->load->model('sms_marketing_model');
            $res = $this->sms_marketing_model->insert_sms_package($data);
            
            $var['vars'] = array(

                's_msg' => 'Successfully Inserted',
                'type' => $this->input->post('type')

            );
            
            if($res == TRUE){
                $this->session->set_flashdata('success', array( 's_msg' => 'Successfully Inserted','type' => $this->input->post('type')));
                redirect("user/SmsMarketing/insertSmsMarketingPackage");
            }
            else{
                $this->session->set_flashdata('error', 'Something went wrong');
                redirect("user/SmsMarketing/insertSmsMarketingPackage");
            }
        }
    }

    public function showSmsMarketingPackage(){
        $this->load->model('sms_marketing_model');
        $data['results'] = $this->sms_marketing_model->show_sms_package();
        $this->load->view('user/list-sms-package', $data);
    }

    public function editSmsMarketing(){

        $data = array(
            'smspackageid' => $this->input->get('smspackageid')
        );

        $this->load->model('sms_marketing_model');
        $data['edit'] = "editSmsMarketing";
        $data['results'] = $this->sms_marketing_model->single_sms_package($data);
        $this->load->view('user/add-sms-package', $data);
    }

    public function updateSmsMarketing(){
        $this->form_validation->set_rules('title', 'Title', 'required');
        $this->form_validation->set_rules('price', 'Price', 'required');
        $this->form_validation->set_rules('type', 'Type', 'required');
        $this->form_validation->set_rules('description', 'Description', 'required');

        if ($this->form_validation->run() == FALSE){

			$this->session->set_flashdata('error', 'Set Title, Price, Type and Description');

        	redirect('user/SmsMarketing/insertSmsMarketingPackage');
                
        }
        else{
            $data = array(
                'smspackageid' => $this->input->post('smspackageid'),
                'title' => $this->input->post('title'),
                'price' => $this->input->post('price'),
                'type' => $this->input->post('type'),
                'description' => $this->input->post('description')
            );

            $this->load->model('sms_marketing_model');
            $res = $this->sms_marketing_model->update_sms_package($data);

            $var['vars'] = array(

                's_msg' => 'Successfully Updated',
                'type' => $this->input->post('type')

            );
            
            if($res == TRUE){
                $this->session->set_flashdata('success', array( 's_msg' => 'Successfully Updated','type' => $this->input->post('type')));
                redirect("user/SmsMarketing/editSmsMarketing?smspackageid=".$this->input->post('smspackageid'));
            }
            else{
                $this->session->set_flashdata('error', 'Something went wrong');
                redirect("user/SmsMarketing/editSmsMarketing?smspackageid=".$this->input->post('smspackageid'));
            }
        }
    }

    public function deleteSmsMarketing($smspackageid){
        $data = array(
            'smspackageid'=> $smspackageid
        );
        $this->load->model('sms_marketing_model');
        $res = $this->sms_marketing_model->delete_sms_package($data);
        
        if($res == TRUE){
            $this->session->set_flashdata('success', 'Successfully Deleted');
            redirect("user/SmsMarketing/showSmsMarketingPackage");
        }
        else{
            $this->session->set_flashdata('error', 'Something went wrong');
            redirect("user/HostingPackage/showSmsMarketingPackage");
        }
    }

    

}