<?php

/* * ***** Purpose : Function for use to print array in formatted way****** */

function pr($ary = array()) {
    echo '<pre>';
    print_r($ary);
    echo '</pre>';
}

/* * ***** Purpose : Function for use to print message in formatted way****** */

function show_message($message = null, $class = null) {
    return '<div class="alert alert-' . $class . ' display-hide" style="display: block;">			
				<button data-close="alert" class="close"></button>
				<span>' . $message . '</span></div>';
}

/* * ***** Purpose : Function for use to print message in formatted way****** */



/* * ***** Purpose : Function for use to print message in formatted way****** */

function countries_list($selected = 'false') {
    $ci = &get_instance();
    $ci->db->select('*');
    $ci->db->from('countries');
    $ci->db->where('is_active', '1');
    $ci->db->order_by('country_name', 'asc');
    $query = $ci->db->get();
    $results = $query->result_array();
    $response = array();
    $response[''] = 'Select Country';
    if (!empty($results)) {
        foreach ($results as $result) {
            $response[$result['country_id']] = $result['country_name'];
        }
    }
    return $response;
}

function get_country_name($id) {
    $ci = &get_instance();
    $ci->db->select('*');
    $ci->db->from('countries');
    $ci->db->where('is_active', '1');
    $ci->db->where('country_id', $id);

    $query = $ci->db->get();
    $results = $query->result_array();
    if (isset($results[0]['country_name']))
        return $results[0]['country_name'];
}

function get_state_name($id) {
    $ci = &get_instance();
    $ci->db->select('*');
    $ci->db->from('states');
    $ci->db->where('is_active', '1');
    $ci->db->where('state_id', $id);

    $query = $ci->db->get();
    $results = $query->result_array();
    if (isset($results[0]['state_name']))
        return $results[0]['state_name'];
}

function get_city_name($id) {
    $ci = &get_instance();
    $ci->db->select('*');
    $ci->db->from('cities');
    $ci->db->where('is_active', '1');
    $ci->db->where('city_id', $id);
    $query = $ci->db->get();
    $results = $query->result_array();
    if (isset($results[0]['city_name']))
        return $results[0]['city_name'];
}

function state_list($selected = 'false') {

    if ($selected != '' && $selected != 0) {
        $ci = &get_instance();
        $ci->db->select('*');
        $ci->db->from('states');
        $ci->db->where('is_active', '1');
        $ci->db->where('country_id', $selected);
        $ci->db->order_by('state_name', 'asc');
        $query = $ci->db->get();
        $results = $query->result_array();

        $response = array();
        $response[''] = 'Select State';
        if (!empty($results)) {
            foreach ($results as $result) {
                $response[$result['state_id']] = $result['state_name'];
            }
        }
    } else {
        $response[''] = "Select State";
    }
    return $response;
}

function city_list($selected = 'false') {
    if ($selected != '' && $selected != 0) {
        $ci = &get_instance();
        $ci->db->select('*');
        $ci->db->from('cities');
        $ci->db->where('is_active', '1');
        $ci->db->where('state_id', $selected);
        $ci->db->order_by('city_name', 'asc');
        $query = $ci->db->get();
        $results = $query->result_array();
        $response = array();
        $response[''] = 'Select City';
        if (!empty($results)) {
            foreach ($results as $result) {
                $response[$result['city_id']] = $result['city_name'];
            }
        }
    } else {
        $response[''] = "Select City";
    }
    return $response;
}

function admin_users_list() {
    $ci = &get_instance();
    $ci->db->select('*');
    $ci->db->from('admin');
    $query = $ci->db->get();
    $results = $query->result_array();
    $response = array();
    $response[''] = 'Select User';
    if (!empty($results)) {
        foreach ($results as $result) {
            $response[$result['id']] = $result['username'];
        }
    }
    return $response;
}

function type_list() {
    return array("" => "Select User", "super" => "super", "normal" => "normal");
}

function account_type_list() {
    return array("" => "Select Active/Inactive", "1" => "Active", "0" => "Inactive");
}

function convertTimeStamp($date) {
    $month = array("jan" => 1, "feb" => 2, "mar" => 3, "apr" => 4, "may" => 5, "jun" => 6, "jul" => 7, "aug" => 8, "sep" => 9, "oct" => 10, "nov" => 11, "dec" => 12);
    $parts = explode('-', $date);
    $parts[0] = $month[strtolower($parts[0])];
    return $timestamp = mktime(0, 0, 0, $parts[0], $parts[1], $parts[2]);
}

function convertTimeStamp2($date) {
    $month = array("jan" => 1, "feb" => 2, "mar" => 3, "apr" => 4, "may" => 5, "jun" => 6, "jul" => 7, "aug" => 8, "sep" => 9, "oct" => 10, "nov" => 11, "dec" => 12);
    $parts = explode('-', $date);
    $parts[0] = $month[strtolower($parts[0])];
    return $timestamp = mktime(23, 59, 59, $parts[0], $parts[1], $parts[2]);
}

function encode($key) {
    return base64_encode($key);
}

function decode($key) {
    return base64_decode($key);
}

 function stringcutter($str, $val) {
	    if(strlen($str)>$val){
			$str=substr($str,0,$val);
			$str=$str."...";	
		}
		else{
			$str=$str;	
		}
        return $str;
    }