220 lines
5.6 KiB
PHP
220 lines
5.6 KiB
PHP
<?php
|
|
if (!defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
/*
|
|
* ASM
|
|
*
|
|
* @author Venba Developers & Contributors
|
|
* @copyright Copyright (c) 2012 - 2017 InvoicePlane.com
|
|
* @license https://venbainfotech.com/license.txt
|
|
* @link https://venbainfotech.com.com
|
|
*/
|
|
|
|
//check auth
|
|
if (!function_exists('check_auth'))
|
|
{
|
|
function check_auth()
|
|
{
|
|
// Get a reference to the controller object
|
|
$ci =& get_instance();
|
|
return $ci->auth_model->is_logged_in();
|
|
|
|
// if($ci->session->userdata('logged_in') == TRUE)
|
|
// {
|
|
// return true;
|
|
// }
|
|
// return false;
|
|
}
|
|
}
|
|
|
|
//check admin
|
|
if (!function_exists('is_superadmin'))
|
|
{
|
|
function is_superadmin()
|
|
{
|
|
// Get a reference to the controller object
|
|
$ci =& get_instance();
|
|
return $ci->auth_model->is_superadmin();
|
|
}
|
|
}
|
|
//check admin
|
|
if (!function_exists('is_admin'))
|
|
{
|
|
function is_admin()
|
|
{
|
|
// Get a reference to the controller object
|
|
$ci =& get_instance();
|
|
return $ci->auth_model->is_admin();
|
|
}
|
|
}
|
|
|
|
//check user
|
|
if (!function_exists('is_user'))
|
|
{
|
|
function is_user()
|
|
{
|
|
// Get a reference to the controller object
|
|
$ci =& get_instance();
|
|
return $ci->auth_model->is_user();
|
|
}
|
|
}
|
|
|
|
|
|
//get logged user
|
|
if (!function_exists('user'))
|
|
{
|
|
function user()
|
|
{
|
|
// Get a reference to the controller object
|
|
$ci =& get_instance();
|
|
$user = $ci->auth_model->get_logged_user();
|
|
if (empty($user))
|
|
{
|
|
$ci->auth_model->logout();
|
|
} else {
|
|
return $user;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
if (!function_exists('hash_password')) {
|
|
function hash_password($password)
|
|
{
|
|
$ci =& get_instance();
|
|
return password_hash($password, PASSWORD_BCRYPT);
|
|
}
|
|
}
|
|
|
|
|
|
// current date time function
|
|
if(!function_exists('my_date_now')){
|
|
function my_date_now(){
|
|
$dt = new DateTime('now', new DateTimezone(get_time_zone()));
|
|
$date_time = $dt->format('Y-m-d H:i:s');
|
|
return $date_time;
|
|
}
|
|
}
|
|
|
|
// show current date & time with custom format
|
|
if(!function_exists('my_date_show_time')){
|
|
function my_date_show_time($date){
|
|
if($date != ''){
|
|
$date2 = date_create($date);
|
|
$date_new = date_format($date2,"d M Y h:i A");
|
|
return $date_new;
|
|
}else{
|
|
return '';
|
|
}
|
|
}
|
|
}
|
|
|
|
// show current date with custom format
|
|
if(!function_exists('my_date_show')){
|
|
function my_date_show($date){
|
|
|
|
if($date != ''){
|
|
$date2 = date_create($date);
|
|
$date_new = date_format($date2,"d M Y");
|
|
return $date_new;
|
|
}else{
|
|
return '';
|
|
}
|
|
}
|
|
}
|
|
|
|
// show current date with custom format
|
|
if(!function_exists('month_show')){
|
|
function month_show($date){
|
|
|
|
if($date != ''){
|
|
$date2 = date_create($date);
|
|
$date_new = date_format($date2,"M Y");
|
|
return $date_new;
|
|
}else{
|
|
return '';
|
|
}
|
|
}
|
|
}
|
|
|
|
// show current date with custom format
|
|
if(!function_exists('show_year')){
|
|
function show_year($date){
|
|
|
|
if($date != ''){
|
|
$date2 = date_create($date);
|
|
$date_new = date_format($date2,"Y");
|
|
return $date_new;
|
|
}else{
|
|
return '';
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//get days
|
|
if (!function_exists('get_days')) {
|
|
function get_days()
|
|
{
|
|
$days = array(
|
|
'1'=>'Saturday',
|
|
'2'=>'Sunday',
|
|
'3'=>'Monday',
|
|
'4'=>'Tuesday',
|
|
'5'=>'Wednesday',
|
|
'6'=>'Thursday',
|
|
'7'=>'Friday'
|
|
);
|
|
return $days;
|
|
}
|
|
}
|
|
|
|
// show different between two dates
|
|
if(!function_exists('day_different')){
|
|
function day_different($to){
|
|
|
|
if($to != ''){
|
|
$days = (new DateTime())->diff(new DateTime($to))->days;
|
|
return $days;
|
|
}else{
|
|
return '';
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// audit history function
|
|
if(!function_exists('audit_history')){
|
|
function audit_history($postData,$table,$business_id){
|
|
|
|
if($table != ''){
|
|
$id = $postData->id;
|
|
$ci =& get_instance();
|
|
$TableData = $ci->MY_Model->getData($table,$id,$business_id);
|
|
$Output = array();
|
|
foreach($postData as $postDatakey=>$postDatavalue)
|
|
{
|
|
foreach($TableData as $TableDatakey=>$TableDatavalue)
|
|
{
|
|
if($postDatakey == $TableDatakey)
|
|
{
|
|
if($postDatavalue != $TableDatavalue)
|
|
{
|
|
$data['table_name'] = $table;
|
|
$data['column_name'] = $postDatakey;
|
|
$data['old_value'] = $TableDatavalue;
|
|
$data['new_value'] = $postDatavalue;
|
|
$data['created_by'] = user()->id;
|
|
$data['business_id'] = $business_id;
|
|
$data['primary_id'] = $id;
|
|
array_push($Output,$data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $Output;
|
|
}else{
|
|
return '';
|
|
}
|
|
}
|
|
} |