<?php

defined('BASEPATH') OR exit('No direct script access allowed');
/*
 * Copyright (c) 2018 Earworks.
 * Codeigniter Project Template Modification
 * Please contact our email for more information :
 *  contact@earworks.co.id
 */
if (!function_exists('output')) {

    function output($data = array(), $status = 1, $header = 200) {
        return get_instance()->output
                        ->set_content_type('application/json')
                        ->set_status_header($header)
                        ->set_output(json_encode(array(
                            'status' => $status,
                            'data' => $data
        )));
    }

}
if (!function_exists('output_blank')) {

    function output_blank($data = array(), $header = 200) {
        return get_instance()->output
                        ->set_content_type('application/json')
                        ->set_status_header($header)
                        ->set_output(json_encode($data));
    }

}
if (!function_exists('output_error')) {

    function output_error($message, $code = 0, $status = 2, $header = 200) {
        return get_instance()->output
                        ->set_content_type('application/json')
                        ->set_status_header($header)
                        ->set_output(json_encode(array(
                            'status' => $status,
                            'message' => $message,
                            'error' => $message,
                            'code' => $code
        )));
    }

}
if (!function_exists('output_invalid_token')) {

    function output_invalid_token($message = null, $header = 200) {
        if (!$message) {
            $message = "Your session has been expired. Please re-login.";
        }
        return get_instance()->output
                        ->set_content_type('application/json')
                        ->set_status_header($header)
                        ->set_output(json_encode(array(
                            'status' => 3,
                            'message' => $message,
                            'error' => 'Invalid nyelam_token',
                            'code' => -1
        )));
    }

}
if (!function_exists('get_basic_request')) {

    function get_basic_request($selected = null) {
        $CI = & get_instance();
        if ($selected) {
            return $CI->input->post($selected, true);
        }
        return array(
            'user_id' => $CI->input->post('user_id', true),
        );
    }

}