<?php

function __response_publish($publish = false, $params = null){
    $ci = &get_instance();

    if($publish){

        $type    = "publish";
        $message = '<font color="#009900"><i class="fa fa-check-square">&nbsp;</i>Data berhasil dipublish</font>';

        if($params !== null){
            if(isset($params['type']) && !empty($params['type'])){
                $type = $params['type'];
            }

            if(isset($params['message']) && !empty($params['message'])){
                $message = $params['message'];
            }
        }

        $output = array('success'=>true,
                        'type'=>$type,
                        'message'=>$message);
    }else{

        $message = '<font color="#eb3a28"><i class="fa fa-exclamation-triangle">&nbsp;</i>Data gagal dipublish</font>';

        if($params !== null){
            if(isset($params['message']) && !empty($params['message'])){
                $message = $params['message'];
            }
        }

        $output = array('success'=>false,
                        'message'=>$message);
    }

    $response = $ci->MY_response;
    foreach($output as $key => $value){
        $response[$key] = $value;
    }

    if($params !== null && isset($params['new_params'])){
        $response = array_merge($response,$params['new_params']);
    }

    echo json_encode($response);
}



function __response_pengajuan($pengajuan = false, $params = null){
    $ci = &get_instance();

    if($pengajuan){

        $type    = "pengajuan";
        $message = '<font color="#009900"><i class="fa fa-check-square">&nbsp;</i>Data berhasil diajukan</font>';

        if($params !== null){
            if(isset($params['type']) && !empty($params['type'])){
                $type = $params['type'];
            }

            if(isset($params['message']) && !empty($params['message'])){
                $message = $params['message'];
            }
        }

        $output = array('success'=>true,
                        'type'=>$type,
                        'message'=>$message);
    }else{

        $message = '<font color="#eb3a28"><i class="fa fa-exclamation-triangle">&nbsp;</i>Data gagal diajukan</font>';

        if($params !== null){
            if(isset($params['message']) && !empty($params['message'])){
                $message = $params['message'];
            }
        }

        $output = array('success'=>false,
                        'message'=>$message);
    }

    $response = $ci->MY_response;
    foreach($output as $key => $value){
        $response[$key] = $value;
    }

    if($params !== null && isset($params['new_params'])){
        $response = array_merge($response,$params['new_params']);
    }

    echo json_encode($response);
}

function __response_approve_kpi($approve = false, $params = null){
    $ci = &get_instance();
    if($approve){
        $type    = "approve";
        $message = '<font color="#009900"><i class="fa fa-check-square">&nbsp;</i>Data berhasil disetujui</font>';

        if($params !== null){
            if(isset($params['type']) && !empty($params['type'])){
                $type = $params['type'];
            }

            if(isset($params['message']) && !empty($params['message'])){
                $message = $params['message'];
            }

        }

        $output = array('success'=>true,
                        'type'=>$type,
                        'message'=>$message);
    }else{
        $message = '<font color="#eb3a28"><i class="fa fa-exclamation-triangle">&nbsp;</i>Data gagal disetujui</font>';

        if($params !== null){
            if(isset($params['message']) && !empty($params['message'])){
                $message = $params['message'];
            }
        }

        $output = array('success'=>false,
                        'message'=>$message);
    }

    $response = $ci->MY_response;
    foreach($output as $key => $value){
        $response[$key] = $value;
    }

    if($params !== null && isset($params['new_params'])){
        $response = array_merge($response,$params['new_params']);
    }

    echo json_encode($response);
}

function __response_accept($accept = false, $params = null){
    $ci = &get_instance();
    if($accept){
        $type    = "accept";
        $message = '<font color="#009900"><i class="fa fa-check-square">&nbsp;</i>Data berhasil diterima</font>';

        if($params !== null){
            if(isset($params['type']) && !empty($params['type'])){
                $type = $params['type'];
            }

            if(isset($params['message']) && !empty($params['message'])){
                $message = $params['message'];
            }

        }

        $output = array('success'=>true,
                        'type'=>$type,
                        'message'=>$message);
    }else{
        $message = '<font color="#eb3a28"><i class="fa fa-exclamation-triangle">&nbsp;</i>Data gagal diterima</font>';

        if($params !== null){
            if(isset($params['message']) && !empty($params['message'])){
                $message = $params['message'];
            }
        }

        $output = array('success'=>false,
                        'message'=>$message);
    }

    $response = $ci->MY_response;
    foreach($output as $key => $value){
        $response[$key] = $value;
    }

    if($params !== null && isset($params['new_params'])){
        $response = array_merge($response,$params['new_params']);
    }

    echo json_encode($response);
}