/
home
/
u764571690
/
domains
/
savitrfoundation.com
/
public_html
/
functions
/
/home/u764571690/domains/savitrfoundation.com/public_html/functions
mkdir
upload
Name
Size
Mode
Actions
function.php
68110
0644
edit
dl
rm
Edit:
/home/u764571690/domains/savitrfoundation.com/public_html/functions/function.php
(68110B)
<?php ob_start(); ini_set("session.cookie_secure", 1); ini_set("display_errors", 1); ini_set("track_errors", 1); ini_set("html_errors", 1); ini_set("allow_url_include", 0); error_reporting(E_ALL); use Razorpay\Api\Api; date_default_timezone_set('Asia/Kolkata'); global $base_url; define('MAIL_FROM','manish@manish.aits.ooo'); define('IMG_BASE',$_SERVER['DOCUMENT_ROOT'].'/stock-admin/'); define('VALIDATION_JS','dataValidationlib.js?_='.time()); if (session_status() == PHP_SESSION_NONE) { session_start(); } function connection() { $con = mysqli_connect("localhost","u764571690_savitr","Ojaspunj@6264","u764571690_savitr"); return($con); } $con = connection(); global $con; function login($table) { global $con; $array=array(); $result = mysqli_query($con,"SHOW COLUMNS FROM $table"); while($row = mysqli_fetch_array($result)) { $field_array = $row['Field']; if ($row['Extra'] == 'auto_increment' && $row['Key'] == 'PRI') { $id_column = $row['Field']; } if(isset($_POST["$field_array"])) { $array["$field_array"]=mysqli_real_escape_string($con, $_POST["$field_array"]); } } $array_keys = array_keys($array); $value = htmlentities(implode(",", $array)); $array_values = explode(",", $value); $username = $array_values[0]; $password = $array_values[1]; $password_column_name =$array_keys[1]; $query = "$table where $array_keys[0] = '$username' AND $array_keys[1] = '$password'"; $hashed_password = getdetail($query,$password_column_name); // will use it when we will convert this function to hashed password. $count_entry = countnum($query); if($count_entry==1) { $get_admin_id = getdetail($query,$id_column); $_SESSION['admin']=$get_admin_id; $encoded_id = password_hash($get_admin_id,PASSWORD_DEFAULT); $_SESSION['secure'] = $encoded_id; redirect("home"); return("success"); } else { return("failed"); } } function checksessionid($for="") { if (session_status() == PHP_SESSION_NONE) { session_start(); } if(!isset($_SESSION['userid'])) { // $_SESSION['userid'] = ""; redirect("index.php?p=login"); } else { //session variable for global usage $userid = $_SESSION['userid']; return($userid); } } //Redirection function==>> function redirect($url) { Header("location:".$url); } //logout function==>> function logout($session_id="",$for="") { if(empty($session_id)) { session_destroy(); } else { unset($session_id); } redirect($for); } //Old ?p= concept navigation not supported now. function navigation($p) { global $con; $filename = "pages/$p.php"; //echo $filename;exit; if (file_exists($filename)) { include_once "pages/$p.php"; } else { echo '<div class="site-content"> <h3 class="alert alert-danger">The Page You Are Looking For Does Not Exists</h3></div>'; } } //insert function latest--->>>>> //clean the inputted values function clean($input_array,$type='array') { if($type == 'array') { $clean_array = array(); foreach($input_array as $key=>$string) { // $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens. $clean_array[$key] = preg_replace('/[^A-Za-z0-9\-:_.@]/', ' ', $string); // Removes special chars. } } else { $clean_array = preg_replace('/[^A-Za-z0-9\-:_.]/', ' ', $input_array); } return $clean_array; } //insert via array--->>>>> // function insertarray($table,$array) // { // // echo "insert into $table ($columns) VALUES ($value)"; // global $con; // $columns= implode(",", array_keys($array)); // $value= implode("','", $array); // if(is_numeric($value)) // { // $value = $value; // } // else // { // $add="'"; // $value=$add.$value.$add; // } // "insert into $table ($columns) VALUES ($value)"; // //mysqli_set_charset('utf8'); // mysqli_set_charset($con, 'utf8'); // $sql=mysqli_query($con,"insert into $table ($columns) VALUES ($value)"); // //echo mysqli_error($con); // return mysqli_insert_id($con); // } function insertarray($table,$array) { global $con; mysqli_set_charset($con, 'utf8'); $error = ''; $val_bind =''; $table = trim($table); $sql = "SHOW COLUMNS FROM $table"; $col_qry = mysqli_query($con,$sql); $colres = $col_qry -> fetch_all(MYSQLI_ASSOC); foreach($colres as $res) { $db_col[] = $res['Field']; } foreach($array as $key=>$val) { if(in_array($key, $db_col)) { $col_arr[] = $key; $quote_arr[] ="?"; $array_values[] = htmlentities($val); $val_bind .='s'; } else { $error = 'Column '.$key.' not existist in table '.$table; } } if($error == '') { $temp_value = implode(",", $quote_arr); $columns = implode(",", $col_arr); $stmt = $con -> prepare("INSERT INTO $table ($columns) VALUES ($temp_value)"); if ( false===$stmt ) { $error = 'prepare() failed: ' . htmlspecialchars($con->error); } else { $rc = $stmt->bind_param("$val_bind", ...$array_values); if ( false===$rc ) { $error = 'bind_param() failed: ' . htmlspecialchars($stmt->error); } } } if($error == '') { $stmt->execute(); $stmt -> close(); return $con->insert_id; } else { return $error; } } //update function latest--->>>>> function updatearray($table,$array,$where) { global $con; $value=""; foreach($array as $key=>$val) { $value.=$key."='".htmlentities($val)."',"; } mysqli_set_charset($con, 'utf8'); // return "update $table set ".rtrim($value,",")." where ".$where; $sql=mysqli_query($con,"update $table set ".rtrim($value,",")." where ".$where); return mysqli_affected_rows($con); } // Count Number of Rows==>>>>>> function countnum($table) { global $con; $sql = mysqli_query($con,"select * from $table"); $num = mysqli_num_rows($sql); return($num); } // Fetch Details from Tables =>>>>> function fetchall($table,$select='*') { global $con; mysqli_set_charset($con, 'utf8'); $sql = mysqli_query($con,"select ".$select." from $table"); $ab = array(); while($row = mysqli_fetch_assoc($sql)) { $ab[]=$row; } return($ab); } // SMS Gateway Function->>> function sendsms2($mobile,$msg) { $senderid='AITSOO'; $apikey = '2541AWk8uZSTw5b8fb01b'; $msg = urlencode($msg); $url = "https://bulksms.aits.ooo/api/sendhttp.php?authkey=$apikey&mobiles=$mobile&message=$msg&sender=$senderid&route=8"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result=curl_exec($ch); curl_close($ch); } #>>>>> delete >>>>>>>>>>>>> function del($string) { global $con; $d=mysqli_query($con,"delete from $string"); return(mysqli_error($con)); } #post-->>>>>>>>>>>>>>>>>>> function post($name, $lev=0) { if(isset($_POST["$name"])) { global $con; $nn=mysqli_real_escape_string($con, $_POST["$name"]); if($nn!='') { return($nn); } elseif($lev==1) { die("Invalid Parameter Passed in Field"); } } elseif($lev==1) { die("Invalid Name"); } } //include any file on page. function inc($for="") { include_once $for.".php"; } //get specific detail from user table function getuserdetail($user,$detail) { global $con; $sql = mysqli_query($con,"select $detail from user where username='$user'"); $row = mysqli_fetch_assoc($sql); return($det = $row["$detail"]); } //get specific details from any table function getdetail($table,$detail) { global $con; $sql = mysqli_query($con,"select $detail from $table"); $row = mysqli_fetch_assoc($sql); $det = (isset($row["$detail"]))?$row["$detail"]:''; return($det); } //upload files function function uploadmultifiles($file,$target) { //var_dump($_FILES[$file]);exit; $FILES=$filename=array(); for($i=0;$i<count($_FILES[$file]['name']);$i++) { $FILES[$i]['name']= $_FILES[$file]['name'][$i]; $FILES[$i]['type']= $_FILES[$file]['type'][$i]; $FILES[$i]['tmp_name']= $_FILES[$file]['tmp_name'][$i]; $FILES[$i]['error']= $_FILES[$file]['error'][$i]; $FILES[$i]['size']= $_FILES[$file]['size'][$i]; } $i=0; foreach( $FILES as $val) { $tname=explode(".",$val['name']); $newname = $tname[0].time().".".$tname[1]; $filename[$i]['file']=$target.$newname; $filename[$i]['type']=$val['type']; $target_file = $target.basename($val['name']); $uploadOk = 1; $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); // $imageFileType; /* if($imageFileType != "jpg" && $imageFileType != "JPG" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "JPEG" && $imageFileType != "mp4" ) { echo "Sorry, only JPG, JPEG, PNG & mp4 files are allowed."; return $uploadOk = 0; }*/ move_uploaded_file($val['tmp_name'],$target.$newname); $i++; } return $filename; } //upload single image function function uploadimg($file,$target='./uploads/') { $filename=array(); $newname = $_FILES[$file]['name']; $filename='./uploads/'.$newname; $target_file = './upload/' . basename($_FILES[$file]['name']); $uploadOk = 1; $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); if($imageFileType != "doc" && $imageFileType != "docx" ) { echo "Sorry, only Doc, Docx"; return $uploadOk = 0; } move_uploaded_file($_FILES[$file]['tmp_name'],$target.$newname); return $filename; } //function for future use for inserting data with less efforts. function intotable2($table, $url) { global $con; $stu=array(); $sql = "SHOW COLUMNS FROM $table"; $result = mysqli_query($con,$sql); while($row = mysqli_fetch_array($result)) { //removing 'date' from array bcoz its timestamp and here it will receive blank value if allowed to pass. if($row['Field']!='date') { if($row['Field']=='company_logo' ) { $ar = $row['Field']; $stu["$ar"]= $url; } else { $ar = $row['Field']; if(isset($_POST["$ar"])) { $stu["$ar"]=mysqli_real_escape_string($con, $_POST["$ar"]); } } } } $columns= implode(",", array_keys($stu)); $value= implode("','", $stu); $add="'"; $value=$add.$value.$add; $sql=mysqli_query($con,"insert into $table ($columns) VALUES ($value)"); return(mysqli_error($con)); } //send mail using php mail() function with HTML template. function sendmail($to,$subject,$from,$mailtext) { $message = ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="viewport" content="width=device-width" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Function Hall Booking</title> </head> <body style="margin:0px; background: #f8f8f8; "> <div width="100%" style="background: #f8f8f8; padding: 0px 0px; font-family:arial; line-height:28px; height:100%; width: 100%; color: #514d6a;"> <div style="max-width: 700px; padding:50px 0; margin: 0px auto; font-size: 14px"> <table border="0" cellpadding="0" cellspacing="0" style="width: 100%; margin-bottom: 20px"> <tbody> <!--<tr> <td style="vertical-align: top; padding-bottom:30px;" align="center"><a href="http://iilmt.com/crmnew" target="_blank"><img src="http://iilmt.com/img/oqzMrl1.png" height="90" alt="IILMT" style="border:none;width: 100%;background: #382c23;padding: 5px;"></a> </td> </tr>--> </tbody> </table> <div style="padding: 40px; background: #fff;"> <table border="0" cellpadding="0" cellspacing="0" style="width: 100%;"> <tbody> <tr> <td><b>To Function Hall Booking,</b><br> '.$mailtext.' <p>Function Hall Booking</p> </td> </tr> </tbody> </table> </div> <div style="text-align: center; font-size: 12px; color: #b2b2b5; margin-top: 20px"> <p> Powered by AITS <br></p> </div> </div> </div> </body> </html> '; $headers = "From: " . $from . "\r\n"; $headers .= "Reply-To: " . $from . "\r\n"; $headers .= "Return-Path: " . $from . "\r\n"; $headers .= "CC: " . $from . "\r\n"; $headers .= "BCC: " . $from . "\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; mail($to, $subject, $message, $headers); } //date comparision function function datecompare($from,$to) { if(strtotime($from) >= strtotime($to)) { return 0; } else { return 1; } } //convert any string to SLUG function slugify($text) { // replace non letter or digits by - $text = preg_replace('~[^\pL\d]+~u', '-', $text); // transliterate $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); // remove unwanted characters $text = preg_replace('~[^-\w]+~', '', $text); // trim $text = trim($text, '-'); // remove duplicate - $text = preg_replace('~-+~', '-', $text); // lowercase $text = strtolower($text); if (empty($text)) { return 'n-a'; } return $text; } //instamojo payment gateway function. function instamojo($amount,$phone,$buyer,$email,$redirect_url) { $purpose="New Purchase By $buyer"; include 'pages/instamojo.php'; // live // $api = new Instamojo\Instamojo('34072f77b15323b2943ff8a8eae2189e', 'f7557a7da8ea3be60ac44bd56b1c58cc','https://www.instamojo.com/api/1.1/'); //test $api = new Instamojo\Instamojo('test_f116f514c66e65a02e580dbd7cb', 'test_9b1b953b73a317f568a76acf154','https://test.instamojo.com/api/1.1/'); try { $response = $api->paymentRequestCreate(array( "purpose" => $purpose, "amount" => $amount, "buyer_name" => $buyer, "phone" => $phone, "send_email" => true, "send_sms" => true, "email" => $email, 'allow_repeated_payments' => false, "redirect_url" => $redirect_url // "webhook" => "http://shop.esbicm.com/index2.php?p=webhook" )); //print_r($response); return $response; //$pay_ulr = $response['longurl']; //Redirect($response['longurl'],302); //Go to Payment page //header("Location: $pay_ulr"); exit(); } catch (Exception $e) { print('Error: ' . $e->getMessage()); } } // AITS NEW MASTER FUNCTION for navigation & Various purpose. // function for getting theme options if available and if available apply active theme. function get_theme() { if(checktable('themes')==0) { $return = NULL; } else { return "inc/".getdetail("themes where status=1 and is_activated=1 limit 1","folder"); } } //build theme URL for css & js etc. function theme_url() { $base_url = get_domain(); $theme_url = get_theme(); return($base_url.$theme_url."/"); } function aits($index) { inc("pages/head"); $path = ltrim($_SERVER['REQUEST_URI'], '/'); // Trim leading slash(es) $elements = explode('/', $path); // Split path on slashes if(empty($elements[$index])) { // No path elements means home inc("pages/home"); } else { $slug = $elements[$index]; //check if it is directory if(is_dir($slug)) { echo "given param is directory"; // get all params $slug = $elements[1]; } $page_exist = countnum("aits_pages where slug='$slug'"); if($page_exist==0) { $temp_page = "pages/$slug.php"; if (file_exists($temp_page)) { $page_to_load=$slug; } else { $notfound='pages/404.php'; if (file_exists($notfound)) { $page_to_load='404'; } else { $page_to_load='home'; } } inc("pages/$page_to_load"); } else { $get_page_details = fetchall("aits_pages where slug='$slug'","page_to_load,ID"); foreach($get_page_details as $get_page) { $page_to_load = $get_page['page_to_load']; if(empty($page_to_load)) { $page_to_load='404';} $page_id = $get_page['ID']; $query_string = 'id'; inc("pages/$page_to_load"); } } } inc("pages/foot"); } //aits extended function for which custom theme is valid. function aits_theme($index) { if(get_theme()!=NULL) { $theme_path = get_theme(); } else { $theme_path = NULL; } inc("$theme_path/pages/head"); $path = ltrim($_SERVER['REQUEST_URI'], '/'); // Trim leading slash(es) $elements = explode('/', $path); // Split path on slashes if(empty($elements[$index])) { // No path elements means home inc("$theme_path/pages/home"); } else { $slug = $elements[$index]; //check if it is directory if(is_dir($slug)) { echo "given param is directory"; // get all params $slug = $elements[1]; } $page_exist = countnum("aits_pages where slug='$slug'"); if($page_exist==0) { $temp_page = "$theme_path/pages/$slug.php"; if (file_exists($temp_page)) { $page_to_load=$slug; } else { $notfound="$theme_path/pages/404.php"; if (file_exists($notfound)) { $page_to_load='404'; } else { $page_to_load='home'; } } inc("$theme_path/pages/$page_to_load"); } else { $get_page_details = fetchall("aits_pages where slug='$slug'","page_to_load,ID"); foreach($get_page_details as $get_page) { $page_to_load = $get_page['page_to_load']; if(empty($page_to_load)) { $page_to_load='404';} $page_id = $get_page['ID']; $query_string = 'id'; inc("$theme_path/pages/$page_to_load"); } } } inc("$theme_path/pages/foot"); } // function to get all the elements from the URL for e.g. aits.ooo/web/2/3 - > returns web,2,3 in array format. function get_all_id() { $path = ltrim($_SERVER['REQUEST_URI'], '/'); // Trim leading slash(es) $elements = explode('/', $path); $elements = preg_replace('/[^-a-zA-Z0-9_]/', '', $elements); return($elements); } // function to get specific element from the list of elements from the URL for e.g. aits.ooo/web/2/3 - > returns web or 2 or 3 which ever index is called. function get($value='') { $array = get_all_id(); if(array_key_exists($value,$array)) { return $array[$value]; } else { return "No Key Exist"; } } //function to get the current slug from URL entered. function get_current_slug($index) { $path = ltrim($_SERVER['REQUEST_URI'], '/'); // Trim leading slash(es) $elements = explode('/', $path); return($elements[$index]); } //get base URL // function base_url() // { // $path = ltrim($_SERVER['REQUEST_URI'], '/'); // Trim leading slash(es) // $elements = explode('/', $path); // if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') // $protocol = "https://"; // else // $protocol = "http://"; // // Split path on slashes // if(empty($elements[0])) { // return($protocol.$path); // } // else // { // return($protocol.$base = $_SERVER['SERVER_NAME'].'/'.$elements[0].'/'); // } // } function base_url($atRoot=FALSE, $atCore=FALSE, $parse=FALSE){ if (isset($_SERVER['HTTP_HOST'])) { $http = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http'; $hostname = $_SERVER['HTTP_HOST']; $dir = str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']); $core = preg_split('@/@', str_replace($_SERVER['DOCUMENT_ROOT'], '', realpath(dirname(__FILE__))), NULL, PREG_SPLIT_NO_EMPTY); $core = $core[0]; $tmplt = $atRoot ? ($atCore ? "%s://%s/%s/" : "%s://%s/") : ($atCore ? "%s://%s/%s/" : "%s://%s%s"); $end = $atRoot ? ($atCore ? $core : $hostname) : ($atCore ? $core : $dir); $base_url = sprintf( $tmplt, $http, $hostname, $end ); } else $base_url = 'http://localhost/'; if ($parse) { $base_url = parse_url($base_url); if (isset($base_url['path'])) if ($base_url['path'] == '/') $base_url['path'] = ''; } return $base_url; } //get current domain function get_domain() { if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') $url = "https://"; else $url = "http://"; // Append the host(domain name, ip) to the URL. $url.= $_SERVER['HTTP_HOST']; // Append the requested resource location to the URL $url.= $_SERVER['REQUEST_URI']; return $url; } //SEO function to generate the dynamic Breadcrumbs (Use with caution.) function getBreadCrumbJson($slug) { $base_url = "https://aits.ooo/"; $breadCrumb = array(); $p1 = array("@type"=>"ListItem","position"=>1,"item"=>array("@id"=>"https://aits.ooo","name"=>"Home")); array_push($breadCrumb,$p1); if($slug != '') { $f = fetchall("aits_pages where slug='$slug'"); if($f) { foreach($f as $f){} if($f['sub_parent'] > 0) { $p = fetchall("aits_pages where ID=$f[sub_parent]"); foreach($p as $p){} $p2 = array("@type"=>"ListItem","position"=>2,"item"=>array("@id"=>$base_url.$p['slug'],"name"=>$p['name'])); array_push($breadCrumb,$p2); $sp = fetchall("aits_pages where ID=$f[ID]"); foreach($sp as $sp){} $p3 = array("@type"=>"ListItem","position"=>3,"item"=>array("@id"=>$base_url.$sp['slug'],"name"=>$sp['name'])); array_push($breadCrumb,$p3); } else { $p = fetchall("aits_pages where ID=$f[ID]"); foreach($p as $p){} $p2 = array("@type"=>"ListItem","position"=>2,"item"=>array("@id"=>$base_url.$p['slug'],"name"=>$p['name'])); array_push($breadCrumb,$p2); } } } return json_encode($breadCrumb,JSON_UNESCAPED_SLASHES); } //function optimizes the image and resizes to desired width and height. function imageoptimize($full_img_path,$width,$height) { include_once "pages/imgutil.php"; $img = new ImageUtil($full_img_path); // set width, height and image resize option $img->resize($width,$height) //->render('smallwonder.jpg') // add watermark // ->watermark('../images/watermark.png', 60, 5, 'TL') // save path to file. Can be .jpg, .jpeg, .gif or .png ->save($full_img_path); } // This function returns the Country , State , City, Country Code,Continent & Continent Code Just by the User's IP Address. function ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) { $output = NULL; if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) { $ip = $_SERVER["REMOTE_ADDR"]; if ($deep_detect) { if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_CLIENT_IP']; } } $purpose = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose))); $support = array("country", "countrycode", "state", "region", "city", "location", "address"); $continents = array( "AF" => "Africa", "AN" => "Antarctica", "AS" => "Asia", "EU" => "Europe", "OC" => "Australia (Oceania)", "NA" => "North America", "SA" => "South America" ); if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) { $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip)); if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) { switch ($purpose) { case "location": $output = array( "city" => @$ipdat->geoplugin_city, "state" => @$ipdat->geoplugin_regionName, "country" => @$ipdat->geoplugin_countryName, "country_code" => @$ipdat->geoplugin_countryCode, "continent" => @$continents[strtoupper($ipdat->geoplugin_continentCode)], "continent_code" => @$ipdat->geoplugin_continentCode ); break; case "address": $address = array($ipdat->geoplugin_countryName); if (@strlen($ipdat->geoplugin_regionName) >= 1) $address[] = $ipdat->geoplugin_regionName; if (@strlen($ipdat->geoplugin_city) >= 1) $address[] = $ipdat->geoplugin_city; $output = implode(", ", array_reverse($address)); break; case "city": $output = @$ipdat->geoplugin_city; break; case "state": $output = @$ipdat->geoplugin_regionName; break; case "region": $output = @$ipdat->geoplugin_regionName; break; case "country": $output = @$ipdat->geoplugin_countryName; break; case "countrycode": $output = @$ipdat->geoplugin_countryCode; break; } } } return $output; /* usage*/ /*echo ip_info("Visitor", "Country"); // India echo ip_info("Visitor", "Country Code"); // IN echo ip_info("Visitor", "State"); // Andhra Pradesh echo ip_info("Visitor", "City"); // Proddatur echo ip_info("Visitor", "Address"); // Proddatur, Andhra Pradesh, India print_r(ip_info("Visitor", "Location")); // Array ( [city] => Proddatur [state] => Andhra Pradesh [country] => India [country_code] => IN [continent] => Asia [continent_code] => AS ) */ } function insert($table,$manual_data="") { global $con; mysqli_set_charset($con, 'utf8'); $array=array(); $result = mysqli_query($con,"SHOW COLUMNS FROM $table"); while($row = mysqli_fetch_array($result)) { $field_array = $row['Field']; if(isset($_POST["$field_array"])) { $array["$field_array"]=mysqli_real_escape_string($con, $_POST["$field_array"]); } if(!empty($manual_data)) { $namearray = array(); foreach ($manual_data as $key => $value) { $namearray [] = $value; $array["$key"]=mysqli_real_escape_string($con, $value); } } } $array = clean($array); $count = count($array); $qm = array(); $bind=''; for($qs=0;$qs<$count;$qs++) { $qm[$qs] = '?'; $bind[$qs] = 's'; } $temp_value = implode(",", $qm); $bind_value = implode(",", (array) $bind); $columns = implode(",", array_keys($array)); $array_keys = array_keys($array); $value = htmlentities(implode(",", $array)); $array_values = explode(",", $value); $stmt = $con -> prepare("INSERT INTO $table ($columns) VALUES ($temp_value)"); $stmt -> bind_param("$bind_value", ...$array_values); $rc = $stmt -> execute(); if ( false===$rc ) { die('execute() failed: ' . htmlspecialchars($stmt->error)); } $stmt -> close(); return $con->insert_id; } function form_fields() { $list = array( 'text'=>'Text Box', 'select'=>'Drop Down', 'multiselect'=>'Multi-Select', 'radio'=>'Radio Button', 'checkbox'=>'Checkbox', 'area'=>'Description Box', 'date'=>'Date', ); return $list; } // generate HTMl code block for input type function genControlcode($type_id,$input,$default='') { $type_info = fetchall("field_types where ID=$type_id"); $type_info = $type_info[0]; $name = strtolower(str_replace(" ","_",$type_info['name'])); $html = ''; if($input == 'text') { } if($input == 'select') { $html.='<select class="form-control form-control-sm" name="'.$name.'" id="'.$name.'">'; $html.='<option value="0" selected="selected">Select Option</option>'; $options = fetchall("field_values where ftyp_id=$type_id and status=0 order by sort_order"); if(!empty($options)) { foreach($options as $option) { if(!empty($default) and $option['name'] == $default): $html.='<option value="'.$option['name'].'" selected="selected">'.$option['name'].'</option>'; else: $html.='<option value="'.$option['name'].'">'.$option['name'].'</option>'; endif; } } $html.='</select>'; } if($input == 'multiselect') { } if($input == 'radio') { } if($input == 'checkbox') { } if($input == 'area') { } if($input == 'date') { } return $html; } // generate SelectBox function genDropDown($table,$name,$opt='',$val='',$default='',$class='', $disable='',$where='') { if($class =='') { $class='form-control form-control-sm'; } if($opt == '') { $opt = 'ID'; } if($val == '') { $val = 'name'; } $html ='<select class="'.$class.'" name="'.$name.'" id="'.$name.'" '.$disable.'>'; $html.='<option value="" selected="selected">Choose Option</option>'; if($where == '') { $options = fetchall($table); } else { $options = fetchall($table.' where '.$where); } if(!empty($options)) { foreach($options as $option) { if(!empty($default) and $option[$opt] == $default): $html.='<option value="'.$option[$opt].'" selected="selected">'.$option[$val].'</option>'; else: $html.='<option value="'.$option[$opt].'">'.$option[$val].'</option>'; endif; } } $html.='</select>'; return $html; } //function to check if table exist in current database function checktable($table) { global $con; $sql = mysqli_query($con,"SHOW TABLES LIKE '".$table."'"); if(mysqli_num_rows($sql)==1) { return(1); } else { return(0); } } // function getDTjson($table) // { // global $con; // $result = mysqli_query($con,"SHOW COLUMNS FROM $table"); // $col = mysqli_fetch_all($result,MYSQLI_ASSOC); // $json_array = array(); // foreach($col as $c) // { // $data['data'] = $c['Field']; // array_push($json_array,$data); // } // return json_encode($json_array); // } function getMemberAge($created) { $jdate = $created; $origin = new DateTime($jdate); $target = new DateTime(date('Y-m-d')); $interval = $origin->diff($target); $year = $interval->format('%y'); return $year; } // Payment Gateway function genRazorPayOrder($amount=10000){ $api_key = API_KEY; $api_secret = API_SECRET; $api = new Api($api_key, $api_secret); $receipt = 'PKG'.time(); $orderParams = array('receipt' => $receipt, 'amount' => $amount, 'currency' => 'INR'); $order = $api->order->create($orderParams); return $order; } function getTotalPaid($type,$id ) { global $con; $sql = "select sum(amount) as amount from payment_master WHERE type_id=$id and type=$type"; $query = mysqli_query($con,$sql); $res = $query -> fetch_row(); if($res[0]=='') { return 0; } else { return $res[0]; } } function generateRandomNumer(){ global $con; $randomString = rand(11111111,99999999);; //Check newly generated Code exist in DB table or not. $query = "select * from products where code ='".$randomString."'"; $result=mysqli_query($con,$query); $resultCount=mysqli_num_rows($result); if($resultCount>0){ //IF code is already exist then function will call it self until unique code has been generated and inserted in Db. generateRandomNumer(); }else{ return $randomString; } } function convertYoutube($string) { return preg_replace( "/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", "<iframe src=\"//www.youtube.com/embed/$2\" allowfullscreen></iframe>", $string ); } function encCard($number) { $rtDigit = array(); $i=1; $digits = explode(" ",$number); foreach($digits as $d) { if($i>1 && $i<4) { $rtDigit[] = 'XXXX'; } else { $rtDigit[] = $d; } $i++; } return implode(' ',$rtDigit); } function updateStock($from,$type,$prouctArray) { //echo $type; exit; global $con; if($type == 1) { // print_r($prouctArray); exit; foreach($prouctArray as $k=>$v) { $prodID = $k; $Qty = $v['qty']; $batch = $v['bno']; $mfg = $v['mfg']; $exp = $v['exp']; $sql = "UPDATE `products` SET quantity = quantity+".$Qty." WHERE ID=".$prodID; mysqli_query($con,$sql); $chkSql = mysqli_query($con, "SELECT * FROM wh_stock_master WHERE item_id=$prodID and wh_id=$from and batch_no='$batch'"); $count = mysqli_num_rows($chkSql); if($count > 0) { $sql2 = "UPDATE `wh_stock_master` SET quantity = quantity+".$Qty." WHERE item_id = $prodID and wh_id = $from and batch_no = '$batch'"; } else { $sql2 = "INSERT INTO `wh_stock_master`(`item_id`, `batch_no`,`mfg_date`,`exp_date`,`wh_id`, `quantity`) VALUES ('$prodID','$batch','$mfg','$exp',$from,$Qty)"; } mysqli_query($con,$sql2); } } if($type == 2) { foreach($prouctArray as $k=>$v) { $prodID = $k; $Qty = $v['qty']; $batch = $v['bno']; $mfg = $v['mfg']; $exp = $v['exp']; $sql3 = "UPDATE `products` SET quantity = quantity-".$Qty." WHERE ID=".$prodID; mysqli_query($con,$sql3); $sql4 = "UPDATE `wh_stock_master` SET quantity = quantity-".$Qty." WHERE item_id = $prodID and wh_id = $from and batch_no = '$batch'"; mysqli_query($con,$sql4); } } } function transferStock($from,$to,$prouctArray) { global $con; foreach($prouctArray as $k=>$v) { $prodID = $k; $Qty = $v['qty']; $batch = $v['bno']; $mfg = $v['mfg']; $exp = $v['exp']; $sql = "UPDATE `wh_stock_master` SET quantity = quantity-".$Qty." WHERE item_id=$prodID and wh_id=$from and batch_no='$batch'"; mysqli_query($con,$sql); $chkSql = mysqli_query($con, "SELECT * FROM wh_stock_master WHERE item_id=$prodID and wh_id=$to and batch_no='$batch'"); $count = mysqli_num_rows($chkSql); if($count > 0) { $sql2 = "UPDATE `wh_stock_master` SET quantity = quantity+".$Qty." WHERE item_id = $prodID and wh_id = $to and batch_no = '$batch'"; } else { $sql2 = "INSERT INTO `wh_stock_master`(`item_id`, `batch_no`,`mfg_date`,`exp_date`,`wh_id`, `quantity`) VALUES ('$prodID','$batch','$mfg','$exp',$to,$Qty)"; } mysqli_query($con,$sql2); } } function updateDepoStock($from,$to,$prouctArray,$return=false) { global $con; if($return === true) { foreach($prouctArray as $k=>$v) { $prodID = $k; $Qty = $v['qty']; $batch = $v['bno']; $mfg = $v['mfg']; $exp = $v['exp']; $sql = "UPDATE `csa_stock_master` SET quantity = quantity-".$Qty." WHERE item_id=$prodID and csa_id=$from and batch_no='$batch'"; mysqli_query($con,$sql); $chkSql = mysqli_query($con, "SELECT * FROM depo_stock_master WHERE item_id=$prodID and depo_id=$to and batch_no='$batch'"); $count = mysqli_num_rows($chkSql); if($count > 0) { $sql2 = "UPDATE `depo_stock_master` SET quantity = quantity+".$Qty." WHERE item_id = $prodID and depo_id = $to and batch_no = '$batch'"; } else { $sql2 = "INSERT INTO `depo_stock_master`(`item_id`, `batch_no`,`mfg_date`,`exp_date`,`csa_id`, `quantity`) VALUES ('$prodID','$batch','$mfg','$exp',$to,$Qty)"; } mysqli_query($con,$sql2); } } else { foreach($prouctArray as $k=>$v) { $prodID = $k; $Qty = $v['qty']; $batch = $v['bno']; $mfg = $v['mfg']; $exp = $v['exp']; $sql = "UPDATE `depo_stock_master` SET quantity = quantity-".$Qty." WHERE item_id=$prodID and depo_id=$from and batch_no='$batch'"; mysqli_query($con,$sql); $chkSql = mysqli_query($con, "SELECT * FROM csa_stock_master WHERE item_id=$prodID and csa_id=$to and batch_no='$batch'"); $count = mysqli_num_rows($chkSql); if($count > 0) { $sql2 = "UPDATE `csa_stock_master` SET quantity = quantity+".$Qty." WHERE item_id = $prodID and csa_id = $to and batch_no = '$batch'"; } else { $sql2 = "INSERT INTO `csa_stock_master`(`item_id`, `batch_no`,`mfg_date`,`exp_date`,`csa_id`, `quantity`) VALUES ('$prodID','$batch','$mfg','$exp',$to,$Qty)"; } mysqli_query($con,$sql2); } } } function updateCSAStock($from,$prouctArray,$return=false) { global $con; if($return === true) { foreach($prouctArray as $k=>$v) { $sql_2 = "UPDATE `csa_stock_master` SET quantity = quantity+".$v." WHERE item_id=".$k." and csa_id=".$from; mysqli_query($con,$sql_2); } } else { foreach($prouctArray as $k=>$v) { $sql_2 = "UPDATE `csa_stock_master` SET quantity = quantity-".$v." WHERE item_id=".$k." and csa_id=".$from; mysqli_query($con,$sql_2); } } } function DepotransferStock($from,$to,$prouctArray) { global $con; foreach($prouctArray as $k=>$v) { $prodID = $k; $Qty = $v['qty']; $batch = $v['bno']; $mfg = $v['mfg']; $exp = $v['exp']; $sql = "UPDATE `wh_stock_master` SET quantity = quantity-".$Qty." WHERE item_id=$prodID and wh_id=$from and batch_no='$batch'"; mysqli_query($con,$sql); $chkSql = mysqli_query($con, "SELECT * FROM depo_stock_master WHERE item_id=$prodID and depo_id=$to and batch_no='$batch'"); $count = mysqli_num_rows($chkSql); if($count > 0) { $sql2 = "UPDATE `depo_stock_master` SET quantity = quantity+".$Qty." WHERE item_id = $prodID and depo_id = $to and batch_no = '$batch'"; } else { $sql2 = "INSERT INTO `depo_stock_master`(`item_id`, `batch_no`,`mfg_date`,`exp_date`,`depo_id`, `quantity`) VALUES ('$prodID','$batch','$mfg','$exp',$to,$Qty)"; } mysqli_query($con,$sql2); } } function adjustStock($whid,$prouctArray,$reverse=false) { global $con; foreach($prouctArray as $k=>$v) { $productID = $v['prod_id']; $type = $v['type']; $qty = $v['qty']; $chkSql = mysqli_query($con, "SELECT * FROM wh_stock_master WHERE item_id=".$productID." and wh_id=".$whid); $count = mysqli_num_rows($chkSql); if($count > 0) { if($type == 1 && $reverse === false) { //Increase stock on addition $sql2 = "UPDATE `wh_stock_master` SET quantity = quantity+".$qty." WHERE item_id=".$productID." and wh_id=".$whid; $sql3 = "UPDATE `products` SET quantity = quantity+".$qty." WHERE ID=".$productID; } else if($type == 1 && $reverse === true) { //Decrease Stock on deletion $sql2 = "UPDATE `wh_stock_master` SET quantity = quantity-".$qty." WHERE item_id=".$productID." and wh_id=".$whid; $sql3 = "UPDATE `products` SET quantity = quantity-".$qty." WHERE ID=".$productID; } else if($type == 2 && $reverse === false) { //Decrease Stock on addition $sql2 = "UPDATE `wh_stock_master` SET quantity = quantity-".$qty." WHERE item_id=".$productID." and wh_id=".$whid; $sql3 = "UPDATE `products` SET quantity = quantity-".$qty." WHERE ID=".$productID; } else { //Increase Stock on deletion $sql2 = "UPDATE `wh_stock_master` SET quantity = quantity+".$qty." WHERE item_id=".$productID." and wh_id=".$whid; $sql3 = "UPDATE `products` SET quantity = quantity+".$qty." WHERE ID=".$productID; } mysqli_query($con,$sql3); } else { if($type == 1) { //Increase stock $sql2 = "INSERT INTO `wh_stock_master`(`item_id`, `wh_id`, `quantity`) VALUES ('$productID',$whid,$qty)"; } { unset($prouctArray[$k]); } } mysqli_query($con,$sql2); } return $prouctArray; } function razorpay($user_id,$amount,$name='',$email='',$phone='') { require('../payments/razorpay/razorpay-php/Razorpay.php'); $keyId = getdetail("payment_gateway where ID = 1 ","merchant_key"); $keySecret = getdetail("payment_gateway where ID = 1 ","salt"); $displayCurrency = 'INR'; //These should be commented out in production // This is for error reporting // Add it to config.php to report any errors error_reporting(E_ALL); ini_set('display_errors', 1); // Create the Razorpay Order // if($user_id > 0) // { // $users = fetchall("users where ID=$user_id"); // foreach($users as $U) // { // $name = $U['name']; // $email = $U['email']; // $phone = $U['mobile']; // } // } $api = new Api($keyId, $keySecret); $recipt_no = rand(); $orderData = [ 'receipt' => $recipt_no, 'amount' => $amount * 100, // 2000 rupees in paise 'currency' => 'INR', 'payment_capture' => 1 // auto capture ]; $razorpayOrder = $api->order->create($orderData); $razorpayOrderId = $razorpayOrder['id']; $_SESSION['razorpay_order_id'] = $razorpayOrderId; $displayAmount = $amount = $orderData['amount']; if ($displayCurrency !== 'INR') { $url = "https://api.fixer.io/latest?symbols=$displayCurrency&base=INR"; $exchange = json_decode(file_get_contents($url), true); $displayAmount = $exchange['rates'][$displayCurrency] * $amount / 100; } $trn['order_id'] = $razorpayOrderId; $trn['user_id'] = $user_id; $trn['amount'] = $amount / 100; $trn['name'] = $name; $trn['email'] = $email; $trn['number'] = $phone; $nid = insertarray('razorpay',$trn); $data = [ "key" => $keyId, "amount" => $amount, "name" => "AFFLUENT IT SERVICES PVT LTD IT DEPARTMENT", "description" => "Payement", "image" => "../uploads/book/aits.logo.png", "prefill" => [ "name" => $name, "email" => $email, "contact" => $phone, ], "notes" => [ "address" => "Hello World", "merchant_order_id" => "12312321", ], "theme" => [ "color" => "#F37254" ], "order_id" => $razorpayOrderId, ]; if ($displayCurrency !== 'INR') { $data['display_currency'] = $displayCurrency; $data['display_amount'] = $displayAmount; } $json = json_encode(array( 'success'=>1, 'data'=> $data )); // echo "$json"; echo "<html> <head> <form id='razorpay_form' action='horoscope/payments/razorpay/verify.php' method='POST'> <script> function loadPaymentModal() { const elem = document.getElementsByClassName('razorpay-payment-button')[0]; elem.click(); setTimeout(() => $('.razorpay-payment-button').hide() , 2000); } </script> <script onLoad='loadPaymentModal()' src='https://checkout.razorpay.com/v1/checkout.js' data-key='".$data['key']."' data-amount='". $data['amount'] ."' data-currency='INR' data-name='".$data['name']."' data-image='".$data['image']."' data-description='".$data['description']."' data-prefill.name='".$data['prefill']['name']."' data-prefill.email='".$data['prefill']['email']."' data-prefill.contact='".$data['prefill']['contact']."' data-notes.shopping_order_id='3456' data-order_id='".$data['order_id']."'"; if ($displayCurrency !== 'INR') { echo "data-display_amount='".$data['display_amount']."'"; } if ($displayCurrency !== 'INR') { echo "data-display_currency='".$data['display_currency']."'"; } echo " > </script> <input type='hidden' name='shopping_order_id' value='3456'> </form> </html>"; } function getProductDetails($pid,$wid,$type=1) { //$type denots that if it is 1 result process for purchase order if it is 2 result process for Sales global $con; if($type == 2) { $sql = "SELECT s.quantity, p.ID, p.name,p.code,p.price,p.pur_rate,p.cost,p.ord_tax,u.code as unit FROM `wh_stock_master` as s JOIN products as p on p.ID=s.item_id JOIN units as u on u.ID = p.unit where s.item_id=".$pid." and s.wh_id=".$wid; } else { $sql = "SELECT p.ID,p.name,p.code,p.price,p.cost,p.pur_rate,p.ord_tax,IFNULL(s.quantity,0) AS quantity,u.code as unit FROM products AS p LEFT JOIN `wh_stock_master` as s on s.item_id=p.ID AND s.wh_id=".$wid." JOIN units as u on u.ID = p.unit WHERE p.ID=".$pid; } $query = mysqli_query($con,$sql); $res = $query -> fetch_assoc(); return $res; } function getDepoProductDetails($pid,$wid) { global $con; $sql = "SELECT s.quantity, p.ID, p.name,p.code,p.price,p.cost,p.ord_tax,u.code as unit FROM `depo_stock_master` as s JOIN products as p on p.ID=s.item_id JOIN units as u on u.ID = p.unit where s.item_id=".$pid." and s.depo_id=".$wid; $query = mysqli_query($con,$sql); $res = $query -> fetch_assoc(); return $res; } function getCSAProductDetails($pid,$wid) { global $con; $sql = "SELECT s.quantity, p.ID, p.name,p.code,p.price,p.cost,p.ord_tax,u.code as unit FROM `csa_stock_master` as s JOIN products as p on p.ID=s.item_id JOIN units as u on u.ID = p.unit where s.item_id=".$pid." and s.csa_id=".$wid; $query = mysqli_query($con,$sql); $res = $query -> fetch_assoc(); return $res; } function taxableAmount($tax,$cost) { $tax = $cost*$tax/100; $taxableAmount = $cost+$tax; return number_format($taxableAmount,'2','.',''); } function password_gen($length_of_string) { $str_result = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; return substr(str_shuffle($str_result), 0, $length_of_string); } function csaDropDown($depoid,$name, $default, $attr='class="form-control"' ) { $html ='<select name="'.$name.'" id="'.$name.'" '.$attr.'>'; $html.='<option value="" selected="selected">Choose Option</option>'; if($depoid !='') { $options = fetchall("users where role_id=2 and top_level=$depoid"); } else { $options = fetchall("users where role_id=2"); } if(!empty($options)) { foreach($options as $option) { if(!empty($default) and $option['ID'] == $default): $html.='<option value="'.$option['ID'].'" selected="selected">'.$option['name'].'</option>'; else: $html.='<option value="'.$option['ID'].'">'.$option['name'].'</option>'; endif; } } $html.='</select>'; return $html; } function stokiestDropDown($depoid,$name, $default, $attr='class="form-control"' ) { $html ='<select name="'.$name.'" id="'.$name.'" '.$attr.'>'; $html.='<option value="" selected="selected">Choose Option</option>'; $options = fetchall("users where role_id=3 and top_level=$depoid"); if(!empty($options)) { foreach($options as $option) { if(!empty($default) and $option['ID'] == $default): $html.='<option value="'.$option['ID'].'" selected="selected">'.$option['name'].'</option>'; else: $html.='<option value="'.$option['ID'].'">'.$option['name'].'</option>'; endif; } } $html.='</select>'; return $html; } function BatchDropDown($ID,$warehouse,$name,$table,$default='',$attr='class="form-control"' ) { $html ='<select name="'.$name.'[]" '.$attr.'>'; $html.='<option value="" selected="selected">Select</option>'; if($table == 'warehouse') { $options = fetchall("wh_stock_master where wh_id=$warehouse and item_id=$ID and quantity > 0"); } if($table == 'depo') { $options = fetchall("depo_stock_master where depo_id=$warehouse and item_id=$ID and quantity > 0"); } if($table == 'csa') { $options = fetchall("csa_stock_master where csa_id=$warehouse and item_id=$ID and quantity > 0"); } if(!empty($options)) { foreach($options as $option) { $uid = getdetail("products where ID=$ID","unit"); $unit = getdetail("units where ID=$uid","name"); if(!empty($default) and $option['ID'] == $default): $html.='<option value="'.$option['ID'].'-'.$option['quantity'].'" selected="selected">'.$option['batch_no'].' [Qty: '.$option['quantity'].' '.$unit.']-[Exp:'.$option['exp_date'].']</option>'; else: $html.='<option value="'.$option['ID'].'-'.$option['quantity'].'">'.$option['batch_no'].' [Qty: '.$option['quantity'].' '.$unit.']-[Exp:'.$option['exp_date'].']</option>'; endif; } } $html.='</select>'; return $html; } // Function For EHRM Added on 08-Aug-2021 //New functions added by manish 16dec2020 function getLoginStatus($empid) { global $con; mysqli_set_charset($con, 'utf8'); // echo "SELECT * FROM attendance where emp_id = ".$empid." AND DATE(`createdat`) = CURDATE()"; $query = mysqli_query($con,"SELECT * FROM attendance where emp_id = ".$empid." AND DATE(`createdat`) = CURDATE()"); $num_row = $query->num_rows; if($num_row > 0) { $res = $query -> fetch_assoc(); $response = json_encode($res); } else { $response = $num_row; } return $response; } function getTimeData($id,$type) { global $con; mysqli_set_charset($con, 'utf8'); $query = mysqli_query($con,"SELECT * FROM attendance where atid = ".$id); $num = $query->num_rows; if($num > 0) { $res = $query -> fetch_assoc(); if($type == 'break') { if($res['break_time'] > 0) { $newWorkingtime = $res['break_time']; $response = sprintf("%02d", intdiv($newWorkingtime, 60)).':'. sprintf("%02d", ($newWorkingtime % 60)); } else { $response = '00:00'; } } if($type == 'workhours') { if($res['day_log_mins'] > 0) { $total_login_min = $res['day_log_mins']; $break_time = $res['break_time']; $newWorkingtime = $total_login_min - $break_time; $response = sprintf("%02d", intdiv($newWorkingtime, 60)).':'. sprintf("%02d", ($newWorkingtime % 60)); } else { $response = '00:00'; } } if($type == 'totalhours') { if($res['day_log_mins'] > 0) { $total_login_min = $res['day_log_mins']; $response = sprintf("%02d", intdiv($total_login_min, 60)).':'. sprintf("%02d", ($total_login_min % 60)); } else { $response = '00:00'; } } } else { $response = '00:00'; } return $response; } function generatedSalaryofmonth($empid) { // global $con; mysqli_set_charset($con, 'utf8'); $query = mysqli_query($con,"SELECT SUM(day_payable) as salary FROM attendance where emp_id = ".$empid." AND MONTH(`createdat`) = MONTH(CURRENT_DATE())"); $num_row = $query->num_rows; if($num_row > 0) { $res = $query -> fetch_assoc(); $response = $res['salary']; } else { $response = 0; } return $response; } function getleavedays($date1,$date2) { $diff = strtotime($date2) - strtotime($date1); // 1 day = 24 hours // 24 * 60 * 60 = 86400 seconds return abs(round($diff / 86400)); } function getCurMntTimeSheet($empid) { echo "SELECT * FROM attendance where emp_id = ".$empid." AND MONTH(`createdat`) = MONTH(CURRENT_DATE()"; exit; global $con; mysqli_set_charset($con, 'utf8'); $query = mysqli_query($con,"SELECT * FROM attendance where emp_id = ".$empid." AND MONTH(`createdat`) = MONTH(CURRENT_DATE()"); $num_row = $query->num_rows; if($num_row > 0) { $response = $query -> fetch_assoc(); // $response = json_encode($res); } else { $response = $num_row; } return $response; } function Get_Employee_Salary_Dates_Of_Month($emp_salary_date,$month,$year) { $curr_date = date('d'); //3-03-2022 // feb - march if($curr_date > $emp_salary_date){ $currunt_month = $month; $next_month = $month + 1; $year = $year; $next_year = $year; if($next_month > 12){ $next_month = 1; $next_year = $year + 1; } $start_date = $year."-".$currunt_month."-".$emp_salary_date; $end_date = $next_year."-".$next_month."-".$emp_salary_date; }else{ $currunt_month = $month - 1; $next_month = $currunt_month +1; $year = $year; $next_year = $year; if($next_month == 0){ $next_month = 12; $next_year = date('Y') - 1;} $start_date = $year."-".$currunt_month."-".$emp_salary_date; $end_date = $next_year."-".$next_month."-".$emp_salary_date; } $date_array = array( 'start_date'=> $start_date, 'end_date' => $end_date, ); return $date_array; } function Get_Employee_Salary_Dates_Of_Month_For_Filter($emp_salary_date,$month,$year) { $curr_date = date('d'); //3-03-2022 // feb - march if($curr_date > $emp_salary_date){ $currunt_month = $month; $next_month = $month + 1; $year = $year; $next_year = $year; if($next_month > 12){ $next_month = 1; $next_year = $year + 1; } $start_date = $year."-".$currunt_month."-".$emp_salary_date; $end_date = $next_year."-".$next_month."-".$emp_salary_date; }else{ $currunt_month = $month; $next_month = $currunt_month + 1; $year = $year; $next_year = $year; if($next_month == 0){ $next_month = 12; $next_year = date('Y') - 1;} $start_date = $year."-".$currunt_month."-".$emp_salary_date; $end_date = $next_year."-".$next_month."-".$emp_salary_date; } $date_array = array( 'start_date'=> $start_date, 'end_date' => $end_date, ); return $date_array; } function Daily_Salary_Count_With_Date_Year($salary,$working_Hour,$salary_month_total_day) { $total_working_hours = getdetail("setting where setting_name = 'total_working_hours'","value"); $total_monthly_working_hours = $total_working_hours*$salary_month_total_day; $per_hour_salary = $salary/$total_monthly_working_hours; return $calculate_working_hour_salary = round($per_hour_salary*$working_Hour,2); } function Daily_Salary_Count($salary,$working_Hour,$emp_salary_date) { $curr_date = date('d'); //3-03-2022 // feb - march if($curr_date > $emp_salary_date){ $currunt_month = date('m'); $next_month = date('m') + 1; $year = date('Y'); $next_year = date('Y'); if($next_month > 12){ $next_month = 1; $next_year = date('Y') + 1; } $salary_month_total_day = get_diffrence_date($year."-".$currunt_month."-".$emp_salary_date,$next_year."-".$next_month."-".$emp_salary_date); }else{ $currunt_month = date('m'); $next_month = date('m') - 1; $year = date('Y'); $next_year = date('Y'); if($next_month == 0){ $next_month = 12; $next_year = date('Y') - 1;} $salary_month_total_day = get_diffrence_date($year."-".$currunt_month."-".$emp_salary_date,$next_year."-".$next_month."-".$emp_salary_date); } $total_working_hours = getdetail("setting where setting_name = 'total_working_hours'","value"); $total_monthly_working_hours = $total_working_hours*$salary_month_total_day; $per_hour_salary = $salary/$total_monthly_working_hours; return $calculate_working_hour_salary = round($per_hour_salary*$working_Hour,2); } function get_employee_details($url) { $curl = curl_init(); date_default_timezone_set('asia/kolkata'); curl_setopt_array($curl, array( CURLOPT_URL => "$url", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vaGlwZXJyLmNvbSIsInN1YiI6ImQwNjIwZmU2ZjBkODQ1MDVhMzU4NmVmNTBlZmE4NjBlIiwiYXVkIjoic2VydmVyIn0.r41pP9on4H0a4EvcVD2HTAI95Rr9yj6szjhEkx83_t0" ), )); $response = curl_exec($curl); $data = json_decode($response, true); // echo "<pre>"; // print_r($data); // exit; return $data; } function convertTime($dec) { // start by converting to seconds $seconds = ($dec * 3600 ); // we're given hours, so let's get those the easy way $hours = floor($dec); // since we've "calculated" hours, let's remove them from the seconds variable $seconds -= $hours * 3600; // calculate minutes left $minutes = floor($seconds / 60); // remove those from seconds as well $seconds -= $minutes * 60; // return the time formatted HH:MM:SS // return lz($hours).":".lz($minutes); return $hours.':'. sprintf("%02d", ($minutes % 60)); } // lz = leading zero function lz($num) { return (strlen($num) < 2) ? "0{$num}" : $num; } //get active time function get_active_time($total_time,$idle_time) { $a = new DateTime($total_time); $b = new DateTime($idle_time); $interval = $a->diff($b); $data = $interval->format("%H:%i"); $val = explode(":",$data); $hour = $val[0]; $min = lz($val[1]); return $hour.":".$min; } function get_working_hour($total_time,$idle_time) { $a = new DateTime($total_time); $b = new DateTime($idle_time); $interval = $a->diff($b); $data = $interval->format("%H:%i"); $val = explode(":",$data); $hour = $val[0]; $min = lz($val[1]); $salary_show_type = getdetail("setting where setting_name='half_hour_login_system'","value"); if($salary_show_type == 0) { return $hour; }else{ $decimal_value = convetminutetodecimal($min); if($decimal_value >= 0.5) { return $hour+0.5; }else{ return $hour; } } } function convetminutetodecimal($min){ return $min/60; } function get_active_hour($total_time) { $val = explode(":",$total_time); $hour = lz($val[0]); $min = $val[1]; return $hour.":".$min; } function get_diffrence_date($start_date,$end_date) { $a = new DateTime($start_date); $b = new DateTime($end_date); $interval = $a->diff($b); return $interval->days; } function get_differnce_time($end_time,$last_activity_time) { $a = new DateTime($end_time); $b = new DateTime($last_activity_time); $interval = $a->diff($b); $data = $interval->format("%H:%i"); $val = explode(":",$data); $hour = $val[0]; $min = lz($val[1]); return $min; } function AmountInWords(float $amount) { $amount_after_decimal = round($amount - ($num = floor($amount)), 2) * 100; // Check if there is any number after decimal $amt_hundred = null; $count_length = strlen($num); $x = 0; $string = array(); $change_words = array(0 => '', 1 => 'One', 2 => 'Two', 3 => 'Three', 4 => 'Four', 5 => 'Five', 6 => 'Six', 7 => 'Seven', 8 => 'Eight', 9 => 'Nine', 10 => 'Ten', 11 => 'Eleven', 12 => 'Twelve', 13 => 'Thirteen', 14 => 'Fourteen', 15 => 'Fifteen', 16 => 'Sixteen', 17 => 'Seventeen', 18 => 'Eighteen', 19 => 'Nineteen', 20 => 'Twenty', 30 => 'Thirty', 40 => 'Forty', 50 => 'Fifty', 60 => 'Sixty', 70 => 'Seventy', 80 => 'Eighty', 90 => 'Ninety'); $here_digits = array('', 'Hundred','Thousand','Lakh', 'Crore'); while( $x < $count_length ) { $get_divider = ($x == 2) ? 10 : 100; $amount = floor($num % $get_divider); $num = floor($num / $get_divider); $x += $get_divider == 10 ? 1 : 2; if ($amount) { $add_plural = (($counter = count($string)) && $amount > 9) ? 's' : null; $amt_hundred = ($counter == 1 && $string[0]) ? ' and ' : null; $string [] = ($amount < 21) ? $change_words[$amount].' '. $here_digits[$counter]. $add_plural.' '.$amt_hundred:$change_words[floor($amount / 10) * 10].' '.$change_words[$amount % 10]. ' '.$here_digits[$counter].$add_plural.' '.$amt_hundred; } else $string[] = null; } $implode_to_Rupees = implode('', array_reverse($string)); $get_paise = ($amount_after_decimal > 0) ? "And " . ($change_words[$amount_after_decimal / 10] . " " . $change_words[$amount_after_decimal % 10]) . ' Paise' : ''; return ($implode_to_Rupees ? $implode_to_Rupees . 'Rupees ' : '') . $get_paise; } // Function to process blog formatting codes and convert them to HTML function processBlogContent($content) { // First decode any HTML entities $content = html_entity_decode($content); // If content already contains HTML tags, don't process formatting codes if (strpos($content, '<') !== false && strpos($content, '>') !== false) { // Content already has HTML, just clean up any remaining formatting codes if needed // Remove any remaining data-start and data-end attributes $content = preg_replace('/\s*data-start="[^"]*"/', '', $content); $content = preg_replace('/\s*data-end="[^"]*"/', '', $content); // Clean up extra whitespace $content = preg_replace('/\s+/', ' ', $content); return $content; } // Convert [h3] tags to <h3> tags $content = preg_replace('/\[h3\](.*?)\[\/h3\]/s', '<h3>$1</h3>', $content); // Convert [blockquote] tags to <blockquote> tags $content = preg_replace('/\[blockquote\](.*?)\[\/blockquote\]/s', '<blockquote>$1</blockquote>', $content); // Convert [strong] tags to <strong> tags $content = preg_replace('/\[strong\](.*?)\[\/strong\]/s', '<strong>$1</strong>', $content); // Convert [em] tags to <em> tags $content = preg_replace('/\[em\](.*?)\[\/em\]/s', '<em>$1</em>', $content); // Convert [p] tags to <p> tags $content = preg_replace('/\[p\](.*?)\[\/p\]/s', '<p>$1</p>', $content); // Handle data-start and data-end attributes if they exist $content = preg_replace('/data-start="[^"]*"/', '', $content); $content = preg_replace('/data-end="[^"]*"/', '', $content); // Clean up extra whitespace $content = preg_replace('/\s+/', ' ', $content); return $content; } ?>
Save
cmd:
run