<?php

function json_data($result) {
    $data = array();
    foreach($result as $row) {			
        $i=0;
        $fdata = array();
        foreach ($row as $key=>$value) {
                array_push($fdata,array($value));
                //array_push($fdata,array($i => $value));
                $i++;
        }
        array_push($data, $fdata);
    } 
    return json_encode($data);
}

function json_fields($cols) {
    // activity_logs();
    //$i=0;
    $fields ='[';
    foreach($cols[0] as $flds=>$tname) {	
            $fields .= '"'.$flds.'",';
            //$i++;
    }
    $fields = rtrim($fields,',');
    $fields .='];';
    
    return $fields;
}

// function activity_logs(){
//     $CI =& get_instance();
//     $CI->load->model('my_model');
//     $data_logs = array(
//         'link'=>str_replace(base_url(),'',current_url()),
//         'login_type'=>$CI->session->userdata('login_type'),
//         'userid'=>$CI->session->userdata('user_id'),
//         'txdate'=>date('Y-m-d H:i:s'),
//         'ip'=>get_ip(),
//         'browser'=>get_user_browser()
//     );
//     $CI->my_model->insert('activity_logs',$data_logs);
// }

// function get_user_browser(){
//     $u_agent = $_SERVER['HTTP_USER_AGENT'];        
//     $ub = '';
//     if(preg_match('/MSIE/i',$u_agent)){$ub = "ie";}
//     elseif(preg_match('/Firefox/i',$u_agent)){$ub = "firefox";}
//     elseif(preg_match('/Chrome/i',$u_agent)){$ub = "chrome";}
//     elseif(preg_match('/Safari/i',$u_agent)){$ub = "safari";}
//     elseif(preg_match('/Flock/i',$u_agent)){$ub = "flock";}
//     elseif(preg_match('/Opera/i',$u_agent)){$ub = "opera";}
//     return $ub;
// }

// function get_ip(){
//     if(!empty($_SERVER['HTTP_CLIENT_IP'])) {
//         $ip = $_SERVER['HTTP_CLIENT_IP'];
//     }elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
//         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
//     }else {
//         $ip = $_SERVER['REMOTE_ADDR'];
//     }
//     return $ip;
// }

?>
