<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ServiceAsha
 *
 * @author zmq163
 */
class MiraServeyForm extends CI_Controller {

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->model('Mira_servey_form_model');
    }

    /**
     * 
     * 
     * 
     * 
     * 
     */
     
     
    public function miraTheater() {

         $input = json_decode(file_get_contents("php://input"), true);

    // Safety check
    if (!isset($input['activity_data']) || !is_array($input['activity_data'])) {
        echo json_encode([
            'status' => FALSE,
            'message' => 'Invalid or missing activity_data'
        ]);
        return;
    }

    $response = $this->Mira_servey_form_model->mira_theater_data($input['activity_data']);
    echo json_encode($response);
    }
    
    
    public function miraImageUpload() {
    // Load the upload library
    $this->load->library('upload');
    $dir_id = $this->input->post('dir_id');
    if((int)$dir_id==1)
    $upload_path = './public/storage/mira_theater_activity/';  
    else if((int)$dir_id==2)
    $upload_path = './public/storage/kiosk_activity/';
    else if((int)$dir_id==3)
    $upload_path = './public/storage/poster_compaign_activity/';
    else if((int)$dir_id==4)
    $upload_path = './public/storage/stakeholder_meeting_activity/';
    else if((int)$dir_id==5)
    $upload_path = './public/storage/training_activity/';
  
    if (!is_dir($upload_path)) {
        mkdir($upload_path, 0777, true); // Create folder if not exists
    }

    $config['upload_path']   = $upload_path;
    $config['allowed_types'] = 'jpg|jpeg|png';
    $config['max_size']      = 2048; // 2MB max size

    $this->upload->initialize($config);

    $image_path = '';

    if (!empty($_FILES['photo_path']['name'])) {
        if ($this->upload->do_upload('photo_path')) {
            $upload_data = $this->upload->data();
        } else {
            echo json_encode([
                'status' => false,
                'message' => $this->upload->display_errors()
            ]);
            return;
        }
    }

   
    $result = array('status' => true,
                'message' => 'success');
    echo json_encode($result);
}
    
     
   

}
