File: /home/barbeatleanalyti/public_html/manage.beatleanalytics.com/site/include/functions.php final
<?php
/* <summary>
File contains all common functions
<author>
Beatle Buddy 2017.
</author>
Version 1.0
</summary>
*/
//ob_start();
session_start();
error_reporting(0);
/*<summary>
Assign passed value from either $_GET or $_POST or $_COOKIE to variable
</summary>
<param name="var">string var</param>
<param name="default">string default</param>
<returns>Return string value</returns>
*/
function loadVariable($var,$default)
{
global ${$var};
$value = ${$var};
if($value != "")
{
return $value;
}
elseif (isset($_POST[$var]))
{
return $_POST[$var];
} elseif (isset($_GET[$var]))
{
return $_GET[$var];
}
elseif(isset($_COOKIE[$var]))
{
return $_COOKIE[$var];
}
else
{
return $default;
}
}
/*<summary>
Check field whether is mepty or not
</summary>
*/
function CreateUniqueID($Val,$PreFix){
$val1 = strlen($Val);
$digit = "";
for($i=4; $i>$val1; $i--) {
$digit .= "0";
}
return $PreFix.$digit.$Val;
}
function ValidateFieldBlank($FieldArr){
$error = 0;
foreach($FieldArr as $Field => $FieldVal){
$FieldVal = trim($FieldVal);
if($FieldVal == "" || empty($FieldVal)){
$error = 1;
}
}
if($error == 0)
return true;
else
return false;
}
function ValidateFieldBlankWithZero($FieldArr){
$error = 0;
foreach($FieldArr as $Field => $FieldVal){
$FieldVal = trim($FieldVal);
if($FieldVal == "" || empty($FieldVal) ){
if($FieldVal != 0){
$error = 1;
}
}
}
if($error == 0)
return true;
else
return false;
}
function ValidateCheckBox($FieldArr){
$error = 0;
if(count($FieldArr) <= 0){
return false;
exit;
}
foreach($FieldArr as $Field => $FieldVal){
$FieldVal = trim($FieldVal);
if( $FieldVal == "" || empty($FieldVal) ){
$error = 1;
}
}
if($error == 0)
return true;
else
return false;
}
function Recursion_array_Update($mapping_data,$TaskID,$TeamID){}
function Recursion_array_Update1($mapping_data_,$ParentID,$TaskID,$TeamID){}
function Recursion_array_Update3($mapping_data2,$TaskID,$ParentID,$TeamID){}
function CheckTaskEmployee($TaskID,$employeeID,$TeamID){}
function SetUpAllPostValue($DataArr){
$error = 0;
foreach($DataArr as $Field => $FieldVal){
$FieldVal = trim($FieldVal);
if( $FieldVal == "" || empty( $FieldVal) ){
$error = 1;
}
}
if($error == 0)
return true;
else
return false;
}
function EmailValidation($email){
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
return false;
}
else
{
return true;
}
}
function FetchJoblocation($LOC){}
function ReturnPostFormData($FieldArr,$pg,$msg,$val){
?>
<form name="returnFrom" id="returnFrom" method="post" action="<?php echo SERVER_ROOT.$pg?>">
<input type="hidden" name="error" id="error" value="<?php echo $val ?>" />
<input type="hidden" name="msg" id="msg" value="<?php echo $msg;?>" />
<?php
foreach($FieldArr as $Field => $FieldVal){
if($Field != 'Validation')
echo '<input type="hidden" name="'.$Field.'" value="'.$FieldVal.'" >';
}
?>
</form>
<script>
document.getElementById('returnFrom').submit();
</script>
<? //header("Location: index.html");
exit;
}
function CaptchaValidate($captch){
if($captch == $_SESSION['CaptchaCode']){
return true;
}else{
return false;
}
}
function PasswordCompare($pass1,$pass2){
if($pass1 == $pass2){
return true;
}else{
return false;
}
}
function DateCompare($StartDate,$EndDate){
if($StartDate<=$EndDate){
return true;
}
else{
return false;}
}
function ZipCode($zip){
if(is_numeric($zip)){
if(strlen($zip)==6){
return true;
}
}
else
{
return false;
}
}
function PasswordLength($length)
{
if(strlen($length) < 5 || strlen($length) > 12 ){
return false;
}else{
return true;
}
}
function Mobile($Mo){
if(is_numeric($Mo))
{
if(strlen($Mo) >= 8 && strlen($Mo) <= 15 ){
return true;
}
}
else
{
return false;
}
}
/*<summary>
Check whether IP address restricted or not
</summary>
*/
function ip_validity()
{
global $objDB;
$SQL = "SELECT IPAddress FROM restrictedip WHERE IPAddress='".$_SERVER["REMOTE_ADDR"]."'";
$resip = $objDB->select($SQL);
if(count($resip) > 0){
echo "<span class='fp_width'>Sorry! you have a restriction to access this site!</span>";
exit;
}
}
/*<summary>
return d-m-y- format of date
</summary>
<param name="date">string date</param>
<returns>Return string value</returns>
*/
function foreignDate($date)
{
if($date!='')
{
$date_array = explode(" ", $date);
$only_date = explode("-", $date_array[0]);
if($date_array[1] != "")
$NewDate = date('m-d-Y',mktime(0,0,0,$only_date[1],$only_date[2],$only_date[0]))." ".$date_array[1];
else
$NewDate = date('m-d-Y',mktime(0,0,0,$only_date[1],$only_date[2],$only_date[0]));
return $NewDate;
}
else
{
return '';
}
}
function AddFieldAddslashes($value){
global $objDB;
return $value = mysqli_real_escape_string($objDB->CONN,trim($value));
}
function RemoveFieldAddslashes($value){
return $value = stripslashes(trim($value));
}
function displayStaticPages()
{}
/* <summary>
Check for any event rotating banner/theme schedules or not for current date
</summary>
<param name="date">current date</param>
<param name="StoreID">int StoreID</param>
<returns>Return an array contains rotating banner/theme scheduled for current day</returns>
*/
function checkEvent($date,$StoreID)
{}
/* <summary>
Check for any pricing discount set for any kind of event
</summary>
<param name="date">current date</param>
<param name="StoreID">int StoreID</param>
<returns>Return an array contains discount amount scheduled for current day</returns>
*/
function checkEventDiscount($date,$StoreID)
{}
function check_blocked_visit_ip()
{
global $objDB;
$SQL = "SELECT IP FROM visit_block_ip WHERE IP = '".$_SERVER['REMOTE_ADDR']."'";
$res = $objDB->select($SQL);
if(count($res) > 0)
return true;
else
return false;
}
function FetchEmployeeType(){}
function FetchUserType($UType){}
function FetchUserDetails($UID,$UType){
global $objDB;
$SQL = "SELECT db_username FROM beatle_userlogin WHERE userId = ".$UID;
$rsData = $objDB->sql_query($SQL);
return $rsData[0]['db_username'];
exit;
}
function FetchDepartment($DepID){}
function FetchAllDetailsOfAnUsers($UID,$UType){}
function FetchInternalPositionName($DesiID){}
function FetchInternalDesignationID($ParentID){}
function FetchUserUniqueID($UID,$UType){}
function FetchEmployeeID($UniqueID){}
function MoveUploadedFile($Source,$Destination){
if(move_uploaded_file($Source,$Destination))
return true;
else
return false;
}
function GeneratePassword($length_ = 8){
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < $length_; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
function paginationval_new($s,$perpage,$start=1,$nume,$totalpage,$pg,$link="")
{
$start1 = $start;
?>
<div class="row">
<div class="col-md-12">
<div class="col-md-12 no-padding col-sm-12">
<div class="col-md-2 form-group">
<div class="dataTables_info text-xs-center text-md-left" style="padding-top:8px;">Total <?php echo $nume ?> Records found </div>
</div>
<div class="col-md-2 col-sm-12 form-group form-horizontal">
<div class="input-group input-group-sm">
<div class="input-group-btn">
<button type="button" class="btn btn-default">Record per page</button>
</div>
<?php
$one = "";
$ten = "";
$twtyfive = "" ;
$fty = "";
$hndr = "";
$fvhndrd = "";
if($perpage == 1)
$one = 'selected="selected"';
else if($perpage == 10)
$ten = 'selected="selected"';
else if($perpage == 25)
$twtyfive = 'selected="selected"';
else if($perpage == 50)
$fty = 'selected="selected"';
else if($perpage == 100)
$hndrd = 'selected="selected"';
else if($perpage == 500)
$fvhndrd = 'selected="selected"';
else if($perpage == 0)
$all = 'selected="selected"';
//$js_per_page_record = "javascript:window.location.href=\"admin.html?start=1&perpage=\"+this.value+\"&s=$s\" ";
?>
<!--javascript:window.location.href="admin.html?start=1&perpage=this.value&s=<?php echo $s?>" -->
<select style="padding:2px;" class="form-control " id='per_page_record' onchange='javascript:window.location.href="<?php echo $pg?>.html?start=1&perpage="+this.value+"&s=<?php echo $s;if($link != "")echo $link;?>" '>
<option <?php echo $ten ?> value='10'> 10 </option>
<option <?php echo $twtyfive ?> value='25'> 25 </option>
<option <?php echo $fty ?> value='50'> 50 </option>
<option <?php echo $hndrd ?> value='100'> 100 </option>
<option <?php echo $fvhndrd ?> value='500'> 500 </option>
<?php
if($pg == 'employee') {
?>
<option <?php echo $all ?> value='0'> All </option>
<? } ?>
</select>
</div>
</div>
<div class="col-md-6 text-center col-sm-12 form-group no-padding">
<div class="col-sm-12">
<div class="dataTables_paginate paging_simple_numbers text-sm">
<ul class="pagination no-margin pagination-sm">
<?php
if ($start1 > 4)
{
$j=$start1 - 1;
$nxt = $start - 1;
?>
<li class="paginate_button previous" id="example1_previous">
<a style="cursor:pointer;" onclick='javascript: window.location.href="<?php echo $pg?>.html?start=1&perpage=<?php echo $perpage; ?>&s=<?php echo $s;if($link != "")echo $link;?>"' id='link_first_true' title='First Page'><font face='Verdana' > <i class="fa fa-angle-double-left"></i> </font></a>
</li>
<li class="paginate_button previous " id="example1_previous">
<a style="cursor:pointer;" onclick='javascript: window.location.href="<?php echo $pg?>.html?start=<?php echo $nxt;?>&perpage=<?php echo $perpage ?>&s=<?php echo $s;if($link != "")echo $link;?>"' id='link_prev_true' title='Prev Page'><font face='Verdana' > <i class="fa fa-angle-double-left"></i><i class="fa fa-angle-double-left"></i> </font></a>
<span> .. </span>
</li>
<?php
}else
{
$j=$start1 - 1;
?>
<li class="paginate_button previous disabled" id="example1_previous">
<a style="cursor:pointer;" id='link_first_false' title='First page link disabled'> <i class="fa fa-angle-double-left"></i> </a>
</li>
<li class="paginate_button previous disabled" id="example1_previous">
<a style="cursor:pointer;" id='link_prev_false' title='Previous page link disabled'> <i class="fa fa-angle-double-left"></i><i class="fa fa-angle-double-left"></i> </a>
</li>
<?php }
//for($i=$start1 - 4; $i<$start1+5; $i++)
if($start1 < 7) {
$val = 7;
$newval1 = $val-$start1;
$newval12 = 3;
}else{
$newval1 = 4;
$newval12 = 3;
}
if($newval1 <= 4){
$newval1 = 4;
}
if($perpage == 0 && $pg == 'employee'){
$totalpage = 1;
}
for($i=$start1 - $newval12; $i < $start1 + $newval1 ; $i++)
{
if($i <= $totalpage && $i > 0 )
{
if ($i == $start1){ ?>
<li class="paginate_button active">
<span><b> <?php echo $i ?> </b> </span>
</li>
<input type='hidden' id='hdn_current_link' title='<?php echo $i ?>' value='<?php echo $i ?>' />
<?php }
else
{ ?>
<li class="paginate_button">
<span id='c_link'> <a href='<?php echo $pg?>.html?start=<?php echo $i?>&perpage=<?php echo $perpage?>&s=<?php echo $s;if($link != "")echo $link;?>'><?php echo $i ?> </a> </span>
</li>
<?php }
}
}
if ($start1 < $totalpage - 3)
{
$j=$start1 + 1;
$prv = $start + 1; ?>
<span style="float:left; margin:10px 5px 0px 4px;"> .. </span>
<li class="paginate_button next">
<a style="cursor:pointer;" onclick='javascript: window.location.href= "<?php echo $pg?>.html?start=<?php echo $prv ?>&perpage=<?php echo $perpage ?>&s=<?php echo $s;if($link != "")echo $link;?>"' id='link_next_true' title='Next Page'><font face='Verdana'> <i class="fa fa-angle-double-right"></i><i class="fa fa-angle-double-right"></i> </font></a>
</li>
<li class="paginate_button next">
<a style="cursor:pointer;" onclick='javascript: window.location.href= "<?php echo $pg?>.html?start=<?php echo $totalpage ?>&perpage=<?php echo $perpage ?>&s=<?php echo $s;if($link != "")echo $link;?>"' id='link_last_true' title='Last Page'><font face='Verdana' > <i class="fa fa-angle-double-right"></i> </font></a>
</li>
<?php
}else
{
$j=$start1 + 4;
?>
<li class="paginate_button next disabled">
<a id='link_next_false' title='Next page link disabled '><i class="fa fa-angle-double-right"></i><i class="fa fa-angle-double-right"></i> </a>
</li>
<li class="paginate_button next disabled">
<a id='link_last_false' title='Last page link disabled '> <i class="fa fa-angle-double-right"></i> </a>
</li>
<?php } ?>
</ul></div></div>
</div>
<div class="col-md-2 pull-right form-group col-sm-12 form-horizontal">
<div class="input-group input-group-sm">
<div class="input-group-btn">
<button type="button" class="btn btn-default"> Direct Page</button>
</div>
<select class="form-control" id='select_id' onchange='javascript:window.location.href="<?php echo $pg?>.html?start="+this.value+"&perpage=<?php echo $perpage?>&s=<?php echo $s;if($link != "")echo $link;?>"'>
<?php
if($perpage == 0 && $pg == 'employee'){
$totalpage = 1;
}
for($k = 1; $k < $totalpage + 1; $k++ )
{
?>
<option value='<?php echo $k; ?>' <?php if($k == $start1) echo "selected='selected'"; ?> > <?php echo $k ?> </option>
<?php } ?>
</select>
</div>
</div>
</div>
</div>
</div>
<?php }
function pagination_log($s,$perpage,$start=1,$nume,$totalpage,$pg,$v="")
{
$start1 = $start;
?>
<div class="row">
<div class="col-md-12 ">
<div class="col-md-12 col-sm-12 no-padding">
<div class="col-md-2 form-group">
<div class="dataTables_info text-xs-center text-md-left" style="padding-top:8px;">Total <?php echo $nume ?> Records found </div>
</div>
<div class="col-md-2 col-xs-12 col-sm-12 form-group form-horizontal">
<div class="input-group input-group-sm">
<div class="input-group-btn">
<button type="button" class="btn btn-default">Record per page</button>
</div>
<?php
$one = "";
$ten = "";
$twtyfive = "" ;
$fty = "";
$hndr = "";
$fvhndrd = "";
if($perpage == 1)
$one = 'selected="selected"';
else if($perpage == 10)
$ten = 'selected="selected"';
else if($perpage == 25)
$twtyfive = 'selected="selected"';
else if($perpage == 50)
$fty = 'selected="selected"';
else if($perpage == 100)
$hndrd = 'selected="selected"';
else if($perpage == 500)
$fvhndrd = 'selected="selected"';
else if($perpage == 0)
$all = 'selected="selected"';
//$js_per_page_record = "javascript:window.location.href=\"admin.html?start=1&perpage=\"+this.value+\"&s=$s\" ";
?>
<!--javascript:window.location.href="admin.html?start=1&perpage=this.value&s=<?php echo $s?>" -->
<select class="form-control" id='per_page_record' onchange='javascript:window.location.href="<?php echo $pg?>.html?v=<?php echo $v;?>&start=1&perpage="+this.value+"&s=<?php echo $s.$link?>"'>
<option <?php echo $ten ?> value='10'> 10 </option>
<option <?php echo $twtyfive ?> value='25'> 25 </option>
<option <?php echo $fty ?> value='50'> 50 </option>
<option <?php echo $hndrd ?> value='100'> 100 </option>
<option <?php echo $fvhndrd ?> value='500'> 500 </option>
<?php
if($pg == 'employee' || $pg == 'addcitylist') {
?>
<option <?php echo $all ?> value='0'> All </option>
<? } ?>
</select>
</div>
</div>
<div class="col-md-6 col-xs-12 text-sm-center text-md-left col-sm-12 form-group no-padding">
<div class="col-sm-12 text-center col-xs-12 text-sm">
<div class="dataTables_paginate paging_simple_numbers text-sm">
<ul class="pagination no-margin pagination-sm">
<?php
if ($start1 > 4)
{
$j=$start1 - 1;
$nxt = $start - 1;
?>
<li class="paginate_button previous" id="example1_previous">
<a style="cursor:pointer;" onclick='javascript: window.location.href= "<?php echo $pg?>.html?v=<?php echo $v;?>&start=1&perpage=<?php echo $perpage; ?>&s=<?php echo $s.$link?>"' id='link_first_true' title='First Page'><font face='Verdana' > <i class="fa fa-angle-double-left"></i> </font></a>
</li>
<li style="cursor:pointer;" class="paginate_button previous" id="example1_previous">
<a onclick='javascript: window.location.href="<?php echo $pg?>.html?v=<?php echo $v;?>&start=<?php echo $nxt;?>&perpage=<?php echo $perpage ?>&s=<?php echo $s.$link?>"' id='link_prev_true' title='Prev Page'><font face='Verdana' > <i class="fa fa-angle-double-left"></i><i class="fa fa-angle-double-left"></i> </font></a>
<span> .. </span>
</li>
<?php
}else
{
$j=$start1 - 1;
?>
<li class="paginate_button previous disabled" id="example1_previous">
<a style="cursor:pointer;" id='link_first_false' title='First page link disabled'><font face='Verdana' > <i class="fa fa-angle-double-left"></i> </font></a>
</li>
<li class="paginate_button previous disabled" id="example1_previous">
<a style="cursor:pointer;" id='link_prev_false' title='Previous page link disabled'><font face='Verdana' > <i class="fa fa-angle-double-left"></i><i class="fa fa-angle-double-left"></i> </font></a>
</li>
<?php }
//for($i=$start1 - 4; $i<$start1+5; $i++)
if($start1 < 7) {
$val = 7;
$newval1 = $val-$start1;
$newval12 = 3;
}else{
$newval1 = 4;
$newval12 = 3;
}
if($newval1 <= 4){
$newval1 = 4;
}
if($perpage == 0 && $pg == 'employee'){
$totalpage = 1;
}
for($i=$start1 - $newval12; $i < $start1 + $newval1 ; $i++)
{
if($i <= $totalpage && $i > 0 )
{
if ($i == $start1){ ?>
<li class="paginate_button active">
<span><b> <?php echo $i ?> </b> </span>
<input type='hidden' id='hdn_current_link' title='<?php echo $i ?>' value='<?php echo $i ?>' />
</li>
<?php }
else
{ ?>
<li class="paginate_button">
<span id='c_link'> <a href='<?php echo $pg?>.html?v=<?php echo $v;?>&start=<?php echo $i?>&perpage=<?php echo $perpage?>&s=<?php echo $s.$link ?>'><?php echo $i ?> </a> </span>
</li>
<?php }
}
}
if ($start1 < $totalpage - 3)
{
$j=$start1 + 1;
$prv = $start + 1; ?>
<li class="paginate_button next">
<span> .. </span>
<a style="cursor:pointer;" onclick='javascript: window.location.href= "<?php echo $pg?>.html?v=<?php echo $v;?>&start=<?php echo $prv ?>&perpage=<?php echo $perpage ?>&s=<?php echo $s.$link ?>"' id='link_next_true' title='Next Page'><font face='Verdana' > <i class="fa fa-angle-double-right"></i><i class="fa fa-angle-double-right"></i> </font></a>
</li>
<li class="paginate_button next">
<a style="cursor:pointer;" onclick='javascript: window.location.href= "<?php echo $pg?>.html?v=<?php echo $v;?>&start=<?php echo $totalpage ?>&perpage=<?php echo $perpage ?>&s=<?php echo $s.$link ?>"' id='link_last_true' title='Last Page'><font face='Verdana' > <i class="fa fa-angle-double-right"></i> </font></a>
</li>
<?php
}else
{
$j=$start1 + 4;
?>
<li class="paginate_button next disabled">
<a style="cursor:pointer;" id='link_next_false' title='Next page link disabled '> <i class="fa fa-angle-double-right"></i><i class="fa fa-angle-double-right"></i> </a>
</li>
<li class="paginate_button next disabled">
<a style="cursor:pointer;" id='link_last_false' title='Last page link disabled '> <i class="fa fa-angle-double-right"></i> </a>
</li>
<?php } ?>
</ul></div></div>
</div>
<div class="col-md-2 col-sm-12 pull-right form-horizontal">
<div class="col-md-12 col-xs-12 col-sm-12 form-group">
<div class="input-group input-group-sm">
<div class="input-group-btn">
<button type="button" class="btn btn-default"> Direct Page</button>
</div>
<select class="form-control " id='select_id' onchange='javascript:window.location.href="<?php echo $pg?>.html?v=<?php echo $v;?>&start="+this.value+"&perpage=<?php echo $perpage?>&s=<?php echo $s.$link?>"'>
<?php
if($perpage == 0 && $pg == 'employee'){
$totalpage = 1;
}
for($k = 1; $k < $totalpage + 1; $k++ )
{
?>
<option value='<?php echo $k; ?>' <?php if($k == $start1) echo "selected='selected'"; ?> > <?php echo $k ?> </option>
<?php } ?>
</select>
</div>
</div>
</div>
</div>
</div>
</div>
<?php }
function number_to_word($number = '')
{
$hyphen = '-';
$conjunction = ' and ';
$separator = ', ';
$negative = 'negative ';
$decimal = ' point ';
$dictionary = array(
0 => 'zero',
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 => 'fourty',
50 => 'fifty',
60 => 'sixty',
70 => 'seventy',
80 => 'eighty',
90 => 'ninety',
100 => 'hundred',
1000 => 'thousand',
1000000 => 'million',
1000000000 => 'billion',
1000000000000 => 'trillion',
1000000000000000 => 'quadrillion',
1000000000000000000 => 'quintillion'
);
if (!is_numeric($number)) {
return false;
}
if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) {
// overflow
trigger_error(
'convert_number_to_words only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX,
E_USER_WARNING
);
return false;
}
if ($number < 0) {
return $negative . number_to_word(abs($number));
}
$string = $fraction = null;
if (strpos($number, '.') !== false) {
list($number, $fraction) = explode('.', $number);
}
switch (true) {
case $number < 21:
$string = $dictionary[$number];
break;
case $number < 100:
$tens = ((int) ($number / 10)) * 10;
$units = $number % 10;
$string = $dictionary[$tens];
if ($units) {
$string .= $hyphen . $dictionary[$units];
}
break;
case $number < 1000:
$hundreds = $number / 100;
$remainder = $number % 100;
$string = $dictionary[$hundreds] . ' ' . $dictionary[100];
if ($remainder) {
$string .= $conjunction . number_to_word($remainder);
}
break;
default:
$baseUnit = pow(1000, floor(log($number, 1000)));
$numBaseUnits = (int) ($number / $baseUnit);
$remainder = $number % $baseUnit;
$string = number_to_word($numBaseUnits) . ' ' . $dictionary[$baseUnit];
if ($remainder) {
$string .= $remainder < 100 ? $conjunction : $separator;
$string .= number_to_word($remainder);
}
break;
}
if (null !== $fraction && is_numeric($fraction)) {
$string .= $decimal;
$words = array();
foreach (str_split((string) $fraction) as $number) {
$words[] = $dictionary[$number];
}
$string .= implode(' ', $words);
}
return $string;
}
function trim_all( $str , $what = NULL , $with = ' ' )
{
if( $what === NULL )
{
// Character Decimal Use
// "\0" 0 Null Character
// "\t" 9 Tab
// "\n" 10 New line
// "\x0B" 11 Vertical Tab
// "\r" 13 New Line in Mac
// " " 32 Space
$what = "\\x00-\\x20"; //all white-spaces and control chars
}
return trim( preg_replace( "/[".$what."]+/" , $with , $str ) , $what );
}
function str_replace_last( $search , $replace , $str ) {
if( ( $pos = strrpos( $str , $search ) ) !== false ) {
$search_length = strlen( $search );
$str = substr_replace( $str , $replace , $pos , $search_length );
}
return $str;
}
function FetchClientID(){}
function FetchMasterAdminID(){}
function ResetEmpolyeeType($empType,$typeVal,$tmpVal){}
function GetEmpolyeeTypeRs($empType,$typeVal,$tmpVal){}
function FetchUserTabbing(){}
function FetchOverTime($Date,$EmployeeID,$rsShiftData,$rsClientOT){}
function FetchShiftTotalHours($EmployeeID){}
function FethComponetName($KeyName,$Type){}
function CheckTaskTabbing(){}
function CheckValidPresentID($table,$field,$value){
global $objDB;
$SQL = "SELECT {$field} FROM {$table} WHERE `{$field}` = '{$value}'";
$rsData = $objDB->sql_query($SQL);
if(!$rsData){
// Return post date if controller class does not exists.
ReturnPostFormData(array(),"error.html","Oops.. There is something wrong to fetch data, please try again with proper value.",1);
exit;
}
}
function ViewReporting($MappingArr){}
function FindStateName($StateID){}
function FindCityName($CityID){}
function FindBranchName($BranchID){}
function FetchTaskManagementDetails($ID,$find){}
function CheckIsFirstTask(){}
function FetchAppconfigStatus($FildName=""){
global $objDB;
$SQL= "SELECT Status FROM appconfig WHERE ConfigName='".$FildName."'";
$Result = $objDB->sql_query($SQL);
return $Result[0]['Status'];
}
function FetchInternalDesignationDataEmployee($DesigID){}
function backPG(){
$UType = $_SESSION['UserInfo']['UType'];
if(strtolower($UType) == "masteradmin"){
return "dashboardma";
}else if(strtolower($UType) == "admin"){
return "dashboardadmin";
}else if( strtolower($UType) == "employee"){
return "dashboardemp";
}else {
return "index";
}
}
function FetchPaymentDue(){
}
function FetchLastPaymentHistory(){
}
function FetchBankList(){}
function CartToHTML(){} // CartToHTML
function CartTaxCompute(){}
function CartVatCompute(){}
function FetchLastDocumentNumber($ref){}
function FetchUserDesignation(){
global $objDB;
$SQL = "SELECT db_usertype FROM beatle_userlogin WHERE userId = '".$_SESSION['UserInfo']['UserID']."' ";
$rsIntDesi = $objDB->sql_query($SQL);
return $rsIntDesi[0]['db_usertype'];
}
function FetchUserWebProfileImage(){
global $objDB;
$SQL = "SELECT webprofileimage FROM beatle_userlogin WHERE userId = '".$_SESSION['UserInfo']['UserID']."' ";
$rsProfile = $objDB->sql_query($SQL);
return $rsProfile[0]['webprofileimage'];
}
function FetchOrgImage(){
global $objDB;
$SQL = "SELECT
beatle_organization.db_Orgpics
FROM
beatle_organization
RIGHT JOIN beatle_userlogin ON beatle_organization.OrgId = beatle_userlogin.OrgID WHERE beatle_userlogin.userId = '".$_SESSION['UserInfo']['UserID']."' ";
$orgProfile = $objDB->sql_query($SQL);
return $orgProfile[0]['db_Orgpics'];
}
function removeprofileimage(){
global $objDB;
$File = FetchUserWebProfileImage();
if($File){
$myFile = UPLOAD_WEBPROFILEIMAGE."/".$File;
unlink($myFile);
}
$SQL = "UPDATE beatle_userlogin SET webprofileimage = NULL WHERE userId = '".$_SESSION['UserInfo']['UserID']."' ";
$upload = $objDB->sql_query($SQL);
return $upload;
}
function FetchQuickMenuList(){}
function StockUpdatesDetails(){}
function CheckQuantity($Quantity,$ProductID,$SerialNumber){}
function UpdateStockOnHand($ProductID,$StockOnHand){}
function FetchQuantity($ProductID){}
function CheckEmployeeNewTicket($TicketID){}
function TicketEmployeeList(){}
function FetchProfileImage($UserID,$UType){}
function FetchProductDetails($ProductID){}
function FetchProductPurchesDetails($ProductID){}
function FetchCustomerList($CompanyID){}
function getBody($uid, $imap) {}
function get_part($imap, $uid, $mimetype, $structure = false, $section = false) {}
function get_mime_type($structure) {}
function SetIMAPData(){}
function fetchMailCredentials(){}
function FetchMailBasicInfo($fromInfo,$replyInfo,$header){}
function FetchFileFaFaWord($Type){}
function FetchMailAttechment($varI){}
function FetchMailHeaderData($msgID){}
function FetchProductSerialList($ProductID){}
function FetchProductSerialNumber($SerialNo,$ProductID){}
function FetchProductAllSerialNumber($ProductID){}
function FetchAllEmployee($EmployeeID){}
function CheckProductSerialNumber($ProductID,$SerialNumber){}
function FetchProductStock($ProductID){}
function AddDuplicateProductStock($ProductID){}
function FetchMailboxListHTML(){}
function ReadMailHTML(){}
function FetchUserAddressBook($value){}
function SetDataToSession(){ }
function FetchChartHTML(){}
function CheckUserLoginOrNot(){ }
function FetchLeftSideBarUser(){}
function GetMappingData($MappingData,$Parent){}
function fetchOrganizationName(){
global $objDB;
if($_SESSION['UserInfo']['UType'] == 'End_user'){
return 'Beatle Analytics';
}else{
$SQL = "SELECT
beatle_organization.db_Orgname
FROM
beatle_organization
RIGHT JOIN beatle_userlogin ON beatle_organization.OrgId = beatle_userlogin.OrgID WHERE beatle_userlogin.userId = ".$_SESSION['UserInfo']['UserID']." ";
$rsUserInfo = $objDB->sql_query($SQL);
return $rsUserInfo[0]['db_Orgname'];
}
}
function IndustryPageIDS($PageType="",$BranchID="",$IndustryID=""){
global $objDB;
//print_r($_SESSION);
$SQL = "SELECT GROUP_CONCAT(beatle_industry.db_pagesId) AS PageID FROM beatle_branch INNER JOIN beatle_industry ON
beatle_branch.branchId = beatle_industry.db_bracnchid WHERE
beatle_branch.db_branchOrg = ".$_SESSION['OtherInfo']['OrgID'];
if(!empty($BranchID))
$SQL .= " AND beatle_branch.branchId = ".$BranchID;
if(!empty($IndustryID))
$SQL .= " AND beatle_industry.IndId = ".$IndustryID;
$rsPages = $objDB->sql_query($SQL);
if($PageType != "" && !empty($rsPages[0]['PageID'])) {
$SQL = "SELECT GROUP_CONCAT(pageId) AS PageID FROM beatle_page WHERE pageId IN (".$rsPages[0]['PageID'].") AND LOWER(db_pagetype) = '".strtolower($PageType)."'";
$rsPages = $objDB->sql_query($SQL);
if(!empty($rsPages[0]['PageID'])) {
$rsArr = explode(",",$rsPages[0]['PageID']);
$returnArr = array();
foreach($rsArr as $key => $val){
if(!in_array($val,$returnArr))
$returnArr[] = $val;
}
return $returnArr;
}else {
return array();
}
}else{
return array();
}
}
function FetchIndustryIDS($IndustryID="",$orgID,$typeEqual){
global $objDB;
$SQL = "SELECT beatle_industry.* FROM beatle_branch INNER JOIN beatle_industry ON
beatle_branch.branchId = beatle_industry.db_bracnchid WHERE 1 = 1";
if($typeEqual == 'equal'){
$SQL .= " AND beatle_branch.db_branchOrg = ".$orgID;
}else if($typeEqual == 'notequal'){
$SQL .= " AND beatle_branch.db_branchOrg != ".$orgID;
}
if(!empty($IndustryID))
$SQL .= " AND beatle_industry.IndId = ".$IndustryID;
//echo $SQL;
$rsIndustrys = $objDB->sql_query($SQL);
return $rsIndustrys;
}
function fetchExpiredSubscriptionDetails(){
global $objDB;
$sdate = date("Y-m-d H:i:s");
$rsarray = array();
// $SQL = "SELECT * FROM beatle_userlogin WHERE userId = ".$_SESSION['UserInfo']['UserID']." AND db_valid >= '".$sdate."' " ;
$SQL = "SELECT db_valid FROM beatle_userlogin WHERE OrgID = ".$_SESSION['OtherInfo']['OrgID']." AND db_usertype = 'owner' AND db_valid >= '".$sdate."' " ;
$rsSub = $objDB->sql_query($SQL);
$datetime1 = new DateTime($sdate);
$datetime2 = new DateTime($rsSub[0]['db_valid']);
$interval = $datetime1->diff($datetime2);
$diff = $interval->format('%a');
$rsarray['exValue'] = $rsSub;
$rsarray['exDiffValue'] = $diff;
//echo "expired value " .$rsarray['exValue'];
return $rsarray;
}
///////////////////////////// CODE FOR SUMMARY PAGE AND DASHBOARD PAGE.
function fetchRatingForCurrentIndustry($IndID,$BranchID,$orgID,$type,$FromDate,$ToDate,$BranchID0,$IndustryID0){
global $objDB,$pg,$currentDate;
include_once("summery.php");
$bojSummery = new include_summery();
// echo "<pre>";
// echo "ind".$IndID." ";
// echo "branch".$BranchID." ";
// echo "orgID".$orgID."</br>";
// echo "type".$type."</br>";
// echo "</pre>";
if(strtolower($_SESSION['UserInfo']['UType']) == 'owner')
$SQL = "SELECT db_orgtype FROM beatle_organization WHERE OrgId = ".$orgID;
$rsOrganizations_ = $objDB->sql_query($SQL);
$orgType = $rsOrganizations_[0]['db_orgtype'];
if(strtolower($_SESSION['UserInfo']['UType']) == 'manager')
$SQL = "SELECT db_branch_type FROM beatle_branch WHERE branchId = ".$BranchID;
$rsBranchDetails = $objDB->sql_query($SQL);
$branchType = $rsBranchDetails[0]['db_branch_type'];
if(strtolower($_SESSION['UserInfo']['UType']) == 'line_manager')
$SQL = "SELECT db_ind_type_id FROM beatle_industry WHERE IndId = ".$IndID;
$rsIndDetails = $objDB->sql_query($SQL);
$indTypeId = $rsIndDetails[0]['db_ind_type_id'];
$SQL ="";
if(strtolower($_SESSION['UserInfo']['UType']) == 'owner'){
$SQL = "SELECT
beatle_organization.OrgId AS OrgIDS,
beatle_organization.db_Orgname,
beatle_organization.db_orgtype,
beatle_branch.branchId,
beatle_branch.db_branchOrg,
beatle_branch.db_branch_type,
beatle_industry.IndId,
beatle_industry.db_industry,
beatle_industry.db_ind_type_id,
beatle_industry.db_pagesId
FROM
beatle_organization
INNER JOIN beatle_branch ON beatle_organization.OrgId = beatle_branch.db_branchOrg
INNER JOIN beatle_industry ON beatle_branch.branchId = beatle_industry.db_bracnchid
WHERE beatle_organization.OrgId <> ".$orgID." AND beatle_organization.db_orgtype = '".$orgType."' " ;
}else if(strtolower($_SESSION['UserInfo']['UType']) == 'manager'){
$SQL = "SELECT
beatle_organization.OrgId AS OrgIDS,
beatle_organization.db_Orgname,
beatle_organization.db_orgtype,
beatle_branch.branchId,
beatle_branch.db_branchOrg,
beatle_branch.db_branch_type,
beatle_industry.IndId,
beatle_industry.db_industry,
beatle_industry.db_ind_type_id,
beatle_industry.db_pagesId
FROM
beatle_organization
INNER JOIN beatle_branch ON beatle_organization.OrgId = beatle_branch.db_branchOrg
INNER JOIN beatle_industry ON beatle_branch.branchId = beatle_industry.db_bracnchid
WHERE beatle_branch.branchId <> ".$BranchID." AND
beatle_branch.db_branch_type = '".$branchType."' " ;
}else if(strtolower($_SESSION['UserInfo']['UType']) == 'line_manager'){
$SQL = "SELECT
beatle_organization.OrgId AS OrgIDS,
beatle_organization.db_Orgname,
beatle_organization.db_orgtype,
beatle_branch.branchId,
beatle_branch.db_branchOrg,
beatle_branch.db_branch_type,
beatle_industry.IndId,
beatle_industry.db_industry,
beatle_industry.db_ind_type_id,
beatle_industry.db_pagesId
FROM
beatle_organization
INNER JOIN beatle_branch ON beatle_organization.OrgId = beatle_branch.db_branchOrg
INNER JOIN beatle_industry ON beatle_branch.branchId = beatle_industry.db_bracnchid
WHERE beatle_industry.IndId <> ".$IndID." AND
beatle_industry.db_ind_type_id = ".$indTypeId." " ;
}
$rsIndustry_ = $objDB->sql_query($SQL);
$orgID_=array();
$branchID_=array();
$induID_=array();
if (!empty($rsIndustry_)) {
//return false;
for($indst=0; $indst<count($rsIndustry_); $indst++){
//echo "orgs ".$rsIndustry_[$indst]['OrgIDS'];
//echo "ind ".$rsIndustry_[$indst]['IndId'];
$orgID_[] = $rsIndustry_[$indst]['OrgIDS'];
$branchID_[] = $rsIndustry_[$indst]['branchId'];
$induID_[] = $rsIndustry_[$indst]['IndId'];
}
}else{
$orgID_[] = 0;
$branchID_[]= 0;
$induID_[] = 0;
}
// echo '<pre>';
// print_r($induID_);
// echo '</pre>';
$SQL = "SELECT db_ind_type_id, db_pagesId FROM beatle_industry WHERE IndId = ".$IndID;
$rsIndustry = $objDB->sql_query($SQL);
$returnArr = array();
$returnArr['performance'] = 0;
$returnArr['score'] = 0;
$performance = 0;
$score = 0;
$performanceWeekly = 0;
$scoreWeekly = 0;
$avgValueDB = 0;
$SQL = "SELECT GROUP_CONCAT(IndId) AS IndustryIDs FROM beatle_industry WHERE db_ind_type_id = ".$rsIndustry[0]['db_ind_type_id']."";
if($type == 'ind')
$SQL .= " AND IndId != ".$IndID."";
$rsIndustryIDs = $objDB->sql_query($SQL);
//echo '<pre>';
//print_r($rsIndustryIDs);
//echo '</pre>';
//echo "<br /><br />";
$avgValue = "0.00";
if(count($rsIndustry) > 0 && count($rsIndustryIDs) > 0){
//echo "<br />";
//echo $rsIndustry[0]['db_pagesId'];
//echo $rsIndustryIDs[0]['IndustryIDs'];
//echo "<br /><br />";
$rsPages = explode(",",$rsIndustry[0]['db_pagesId']);
if(count($rsPages) > 0 && !empty($rsIndustry[0]['db_pagesId']) && !empty($rsIndustryIDs[0]['IndustryIDs'])) {
//if($pg == 'summery') {
// if($type == 'us') {
/////////// CODE ONLY FOR PERFORMANCE MONTHLY //////////////////
if($pg == 'summery') {
//$fdate = date("Y-m-d",strtotime("-30 days"));
$fdate = date("Y-m-d",strtotime("-30 days"));
$tdate = date("Y-m-d");
}else{
$fdate = date("Y-m-d",strtotime($FromDate));
$tdate = date("Y-m-d",strtotime($ToDate));
}
$dtcnt = 0;
while(strtotime($fdate) <= strtotime($tdate)) {
$dtcnt++;
$SQL = "SELECT AVG(db_surveyValue) AS AvgValue FROM beatle_survey WHERE db_surveyPageid IN(".$rsIndustry[0]['db_pagesId'].") ";
//$SQL .= " AND db_surveyIndId IN (".$IndID.")";
if($type == 'us')
$SQL .= " AND db_surveyIndId IN (".$IndID.")";
else if($type == 'ind')
$SQL .= " AND db_surveyIndId IN (".$rsIndustryIDs[0]['IndustryIDs'].") ";
$SQL .= " AND db_surveyValue IN (1,2,3,4,5) AND is_submit = 'Y'";
//$SQL .= " AND orgid = ".$orgID. " AND db_surveyBranchid = ".$BranchID ;
if($type == 'us'){
$SQL .= " AND orgid = ".$orgID. " AND db_surveyBranchid = ".$BranchID ;
}elseif($type == 'ind'){
if(empty($BranchID0) and empty($IndustryID0)){
$SQL .= " AND orgid != ".$orgID;
}elseif(!empty($BranchID0) and empty($IndustryID0)){
$SQL .= " AND db_surveyBranchid != ".$BranchID;
}
}
$SQL .= " AND created_date BETWEEN '".$fdate." 00:00:00' AND '".$fdate." 23:59:59' ";
//echo "<pre>";
$rsCountSurvey = $objDB->sql_query($SQL);
//echo $fdate." ".$rsCountSurvey[0]['AvgValue'];
//print_r($rsCountSurvey);
//echo " # ";
$performance = $performance + $rsCountSurvey[0]['AvgValue'];
//echo " <br />";
$fdate = date("Y-m-d",strtotime($fdate." + 1day"));
}
// WHILE COMPLETED
if($type == 'us'){
if(fetchActiveScoreCheckedData() == "checked"){
if($pg == 'summery'){
if($performance > 0){
$performance = number_format(($performance / fetchZeroFeedbackDays($orgID,$BranchID,$IndID,date("Y-m-d",strtotime("-30 days")),date("Y-m-d"))),2);
}else{
$performance = "0.00";
}
}else{
if($performance > 0){
$performance = number_format(($performance / fetchZeroFeedbackDays($orgID,$BranchID,$IndID,$FromDate,$ToDate)),2);
}else{
$performance = "0.00";
}
}
}else{
if($performance > 0){
$performance = number_format(($performance / $dtcnt),2);
}else{
$performance = "0.00";
}
}
}elseif($type == 'ind'){
if($performance > 0){
$performance = number_format(($performance / $dtcnt),2);
}else{
$performance = "0.00";
}
}
$SQL = "";
$SQL = "SELECT AVG(db_surveyValue) AS AvgValue FROM beatle_survey WHERE db_surveyPageid IN(".$rsIndustry[0]['db_pagesId'].") ";
//$SQL .= " AND db_surveyIndId IN (".$IndID.")";
if($type == 'us')
$SQL .= " AND db_surveyIndId IN (".$IndID.")";
else if($type == 'ind')
$SQL .= " AND db_surveyIndId IN (".$rsIndustryIDs[0]['IndustryIDs'].") ";
$SQL .= " AND db_surveyValue IN (1,2,3,4,5) AND is_submit = 'Y'";
//$SQL .= " AND orgid = ".$orgID. " AND db_surveyBranchid = ".$BranchID ;
if($type == 'us')
$SQL .= " AND orgid = ".$orgID. " AND db_surveyBranchid = ".$BranchID ;
else if($type == 'ind')
$SQL .= " AND orgid != ".$orgID;
if(empty($currentDate))
$SQL .= " AND created_date BETWEEN '".date("Y-m-d")." 00:00:00' AND '".date("Y-m-d")." 23:59:59' ";
else
$SQL .= " AND created_date BETWEEN '".date("Y-m-d",strtotime($currentDate))." 00:00:00' AND '".date("Y-m-d",strtotime($currentDate))." 23:59:59' ";
//echo $SQL;
//echo "<br /><br />";
$rsCountSurveyToday = $objDB->sql_query($SQL);
$score = $score + number_format($rsCountSurveyToday[0]['AvgValue'],2);
/////////// CODE ONLY FOR PERFORMANCE MONTHLY COMPLETED //////////////////
//}
/////////// CODE ONLY FOR PERFORMANCE WEEKLY FRO US VS. IND. IN SUMMERY PAGE START //////////////////
$endDate = date("Y-m-d");
$startDate = date("Y-m-d",strtotime("-6 days"));
while($startDate <= $endDate){
$returnArr['days'][] = strtoupper(substr(date("D",strtotime($startDate)),0,2));
$returnArr['fulldayswithdate'][] = date("l d/m/Y",strtotime($startDate));
$SQL = "";
$SQL = "SELECT AVG(db_surveyValue) AS AvgValue FROM beatle_survey WHERE db_surveyPageid IN(".$rsIndustry[0]['db_pagesId'].") ";
if($type == 'us')
$SQL .= " AND db_surveyIndId IN (".$IndID.")";
else if($type == 'ind')
$SQL .= " AND db_surveyIndId IN (".implode(',',$induID_).") ";
//$SQL .= " AND db_surveyIndId IN (".implode(',',$induID_).") ";
//$SQL .= " AND db_surveyIndId IN (".$rsIndustryIDs[0]['IndustryIDs'].") ";
$SQL .= " AND db_surveyValue IN (1,2,3,4,5) AND is_submit = 'Y'";
if($type == 'us')
$SQL .= " AND orgid = ".$orgID. " AND db_surveyBranchid = ".$BranchID ;
else if($type == 'ind')
if(strtolower($_SESSION['UserInfo']['UType']) == 'owner')
$SQL .= " AND orgid IN (".implode(',',$orgID_).")";
elseif(strtolower($_SESSION['UserInfo']['UType']) == 'manager')
$SQL .= " AND orgid IN (".implode(',',$orgID_).") AND db_surveyBranchid IN (".implode(',',$branchID_).")";
// if(empty($BranchID0) and empty($IndustryID0)){
// $SQL .= " AND orgid != ".$orgID;
// }elseif(!empty($BranchID0) and empty($IndustryID0)){
// $SQL .= " AND db_surveyBranchid != ".$BranchID;
// }
//$SQL .= " AND orgid IN (".implode(',',$orgID_).")";
$SQL .= " AND created_date BETWEEN '".date("Y-m-d",strtotime($startDate))." 00:00:00' AND '".date("Y-m-d",strtotime($startDate))." 23:59:59' ";
$rsCountSurveyWeekly = $objDB->sql_query($SQL);
$performanceWeekly = $rsCountSurveyWeekly[0]['AvgValue'];
if(!empty($performanceWeekly))
$returnArr['weekly'][] = $performanceWeekly;
else
$returnArr['weekly'][] = 0;
//$returnArr['weekly'][] = rand(0,4);
/*echo $SQL;
echo "<br>";*/
/*echo "<pre>";
print_r($returnArr['weekly']);
echo "</pre>";*/
$SQL = "SELECT COUNT(db_surveyValue) AS TotalCount FROM beatle_survey WHERE
db_surveyPageid IN (".$rsIndustry[0]['db_pagesId'].") AND
db_surveyValue IN (1,2,3,4,5) AND is_submit = 'Y' ";
$SQL .= " AND db_surveyIndId IN (".$IndID.") ";
$SQL .= " AND orgid = ".$orgID. " AND db_surveyBranchid = ".$BranchID;
$SQL .= " AND created_date BETWEEN '".date("Y-m-d",strtotime($startDate))." 00:00:00' AND '".date("Y-m-d",strtotime($startDate))." 23:59:59' ";
$SQL .= " GROUP BY tokenid";
$rsTotalCount = $objDB->sql_query($SQL);
$returnArr['weekly_feedback_total'][] = count($rsTotalCount);
//echo count($rsTotalCount)."<br>";
$startDate = date("Y-m-d",strtotime($startDate." +1 days"));
} //// CODE FOR WEEKLY PERFORMANCE COMPLETED
///////WEEKLY FEEDBACK COUNT START
/*$endDate = date("Y-m-d");
$startDate = date("Y-m-d",strtotime("-6 days"));
while($startDate <= $endDate){
$SQL = "SELECT COUNT(db_surveyValue) AS TotalCount FROM beatle_survey WHERE
db_surveyPageid IN (".$rsIndustry[0]['db_pagesId'].") AND
db_surveyValue IN (1,2,3,4,5) AND is_submit = 'Y' ";
$SQL .= " AND db_surveyIndId IN (".$IndID.") ";
$SQL .= " AND orgid = ".$orgID. " AND db_surveyBranchid = ".$BranchID;
$SQL .= " AND created_date BETWEEN '".date("Y-m-d",strtotime($startDate))." 00:00:00' AND '".date("Y-m-d",strtotime($startDate))." 23:59:59' ";
$SQL .= " GROUP BY tokenid";
$rsTotalCount = $objDB->sql_query($SQL);
$returnArr['weekly_feedback_total'] = count($rsTotalCount);
}*/
//WEEKLY FEEDBACK COUNT COMPLETED
//} // IF COMPLETED FOR SUMMEY PAGE
// CODE FOR DASHBARD PAGE AVERAGE VALUE
if($pg == 'dashboardma') {
$fdateDash = $FromDate;
$tdateDash = $ToDate;
$dtcnt = 0;
while(strtotime($fdateDash) <= strtotime($tdateDash)) {
$dtcnt++;
$SQL = "SELECT AVG(db_surveyValue) AS AvgValue FROM beatle_survey WHERE db_surveyPageid IN(".$rsIndustry[0]['db_pagesId'].") ";
if($type == 'us')
$SQL .= " AND db_surveyIndId IN (".$IndID.")";
else if($type == 'ind')
$SQL .= " AND db_surveyIndId IN (".$rsIndustryIDs[0]['IndustryIDs'].") ";
$SQL .= " AND db_surveyValue IN (1,2,3,4,5) AND is_submit = 'Y'";
if($type == 'us'){
$SQL .= " AND orgid = ".$orgID. " AND db_surveyBranchid = ".$BranchID ;
}else if($type == 'ind'){
if(empty($BranchID0) and empty($IndustryID0)){
$SQL .= " AND orgid != ".$orgID;
}elseif(!empty($BranchID0) and empty($IndustryID0)){
$SQL .= " AND db_surveyBranchid != ".$BranchID;
}
}
$SQL .= " AND created_date BETWEEN '".date("Y-m-d",strtotime($fdateDash))." 00:00:00' AND '".date("Y-m-d",strtotime($fdateDash))." 23:59:59' ";
//if($type == 'us' && $IndID == 12)
//echo $SQL;
$rsCountSurvey = $objDB->sql_query($SQL);
//echo $FromDate. " # ".$rsCountSurvey[0]['AvgValue']." # ";
$avgValueDB = $avgValueDB + $rsCountSurvey[0]['AvgValue'];
//if($type == 'us' && $IndID == 12)
//echo "<br />".$rsCountSurvey[0]['AvgValue']."<br /><br />";
$fdateDash = date("Y-m-d",strtotime($fdateDash." +1 days"));
}
if($type == 'us'){
if(fetchActiveScoreCheckedData() == "checked"){
//echo "checked";
if($avgValueDB > 0){
$avgValueDB = number_format(($avgValueDB / fetchZeroFeedbackDays($orgID,$BranchID,$IndID,$FromDate,$ToDate)),2);
}else{
$avgValueDB = "0.00";
}
}else{
//echo "not checked";
if($avgValueDB > 0){
$avgValueDB = number_format(($avgValueDB / $dtcnt),2);
}else{
$avgValueDB = "0.00";
}
}
}else{
if($avgValueDB > 0){
$avgValueDB = number_format(($avgValueDB / $dtcnt),2);
}else{
$avgValueDB = "0.00";
}
}
}else{
//echo "XXXX<br />";
$avgValueDB = "0.00";
}
//if($type == 'us') {
//echo $FromDate;
//echo " ## ";
//}
}else{
$returnArr['weekly'] = array(0=>0,1=>0,2=>0,3=>0,4=>0,5=>0,6=>0);
$returnArr['weekly_feedback_total'] = array(0=>0,1=>0,2=>0,3=>0,4=>0,5=>0,6=>0);
//$returnArr['weekly'] = array(0=>2,1=>2,2=>3,3=>4,4=>4,5=>1,6=>1);
$performance = 0;
$score = 0;
$avgValueDB = "0.00";
}
}
$returnArr['performance'] = $performance;
$returnArr['score'] = $score;
$returnArr['avgValueDB'] = $avgValueDB;
//echo "<pre>";
//print_r($returnArr);
//echo "</pre>";
//$returnArr['performanceWeekly'] = $performanceWeekly;
return $returnArr;
}
function fetchAvgLowRating($type,$BranchID,$IndustryID,$orgID,$FromDate,$ToDate){
global $objDB,$pg,$currentDate;
//echo "##############";
include_once("summery.php");
$bojSummery = new include_summery();
//echo "xxxxxxxxxxxxx";
//die;
$rsBranches = $bojSummery->fetchBranchesData($BranchID);
$returnArr = array();
$avgUSTotal = 0;
$SUM = 0;
$SUMOve = 0;
for($i=0; $i<count($rsBranches); $i++) {
$rsIndustry = $bojSummery->fetchIndustryData($rsBranches[$i]['branchId'],$IndustryID);
for($indst=0; $indst<count($rsIndustry); $indst++){
$rsPages = explode(",",$rsIndustry[$indst]['db_pagesId']);
if(count($rsPages) > 0 && !empty($rsIndustry[0]['db_pagesId'])) {
if($pg == 'summery') {
$SQL_ = "SELECT count(db_surveyValue) AS AvgValue from beatle_survey WHERE db_surveyPageid IN (".$rsIndustry[$indst]['db_pagesId'].") AND db_surveyIndId IN (".$rsIndustry[$indst]['IndId'].") AND db_surveyValue IN (1,2) AND is_submit = 'Y' ";
$SQL_ .= " AND orgid = ".$orgID. " AND db_surveyBranchid = ".$rsBranches[$i]['branchId'];
if(empty($currentDate))
$SQL_ .= " AND created_date BETWEEN '".date("Y-m-d")." 00:00:00' AND '".date("Y-m-d")." 23:59:59' ";
else
$SQL_ .= " AND created_date BETWEEN '".date("Y-m-d",strtotime($currentDate))." 00:00:00' AND '".date("Y-m-d",strtotime($currentDate))." 23:59:59' ";
$SQL_ .= " GROUP BY tokenid";
$rsCountSurvey = $objDB->sql_query($SQL_);
if(count($rsCountSurvey) > 0){
foreach($rsCountSurvey as $key => $val) {
$SUM = $SUM + $val['AvgValue'];
}
}
$SQL_ = "";
$SQL_ = "SELECT count(db_surveyValue) AS AvgValue from beatle_survey WHERE db_surveyPageid IN (".$rsIndustry[$indst]['db_pagesId'].") AND db_surveyIndId IN (".$rsIndustry[$indst]['IndId'].") AND db_surveyValue IN (1,2,3,4,5) AND is_submit = 'Y' ";
$SQL_ .= " AND orgid = ".$orgID. " AND db_surveyBranchid = ".$rsBranches[$i]['branchId'];
//$SQL_ .= " AND created_date BETWEEN '".date("Y-m-d")." 00:00:00' AND '".date("Y-m-d")." 23:59:59' ";
if(empty($currentDate))
$SQL_ .= " AND created_date BETWEEN '".date("Y-m-d")." 00:00:00' AND '".date("Y-m-d")." 23:59:59' ";
else
$SQL_ .= " AND created_date BETWEEN '".date("Y-m-d",strtotime($currentDate))." 00:00:00' AND '".date("Y-m-d",strtotime($currentDate))." 23:59:59' ";
$SQL_ .= " GROUP BY tokenid";
$rsCountSurveyOver = $objDB->sql_query($SQL_);
if(count($rsCountSurveyOver) > 0){
foreach($rsCountSurveyOver as $key => $val) {
$SUMOve = $SUMOve + $val['AvgValue'];
}
}
}else if($pg == 'dashboardma'){
$SQL_ = "SELECT count(db_surveyValue) AS AvgValue from beatle_survey WHERE db_surveyPageid IN (".$rsIndustry[$indst]['db_pagesId'].") AND db_surveyIndId IN (".$rsIndustry[$indst]['IndId'].") AND db_surveyValue IN (1,2) AND is_submit = 'Y' ";
$SQL_ .= " AND orgid = ".$orgID. " AND db_surveyBranchid = ".$rsBranches[$i]['branchId'];
//$SQL_ .= " AND created_date BETWEEN '".date("Y-m-d",strtotime("-30 days"))." 00:00:00' AND '".date("Y-m-d")." 23:59:59' ";
$SQL_ .= " AND created_date BETWEEN '".date("Y-m-d",strtotime($FromDate))." 00:00:00' AND '".date("Y-m-d",strtotime($ToDate))." 23:59:59' ";
$SQL_ .= " GROUP BY tokenid";
$rsCountSurvey = $objDB->sql_query($SQL_);
if(count($rsCountSurvey) > 0){
foreach($rsCountSurvey as $key => $val) {
$SUM = $SUM + $val['AvgValue'];
}
}
$SQL_ = "";
$SQL_ = "SELECT count(db_surveyValue) AS AvgValue from beatle_survey WHERE db_surveyPageid IN (".$rsIndustry[$indst]['db_pagesId'].") AND db_surveyIndId IN (".$rsIndustry[$indst]['IndId'].") AND db_surveyValue IN (1,2,3,4,5) AND is_submit = 'Y' ";
$SQL_ .= " AND orgid = ".$orgID. " AND db_surveyBranchid = ".$rsBranches[$i]['branchId'];
//$SQL_ .= " AND created_date BETWEEN '".date("Y-m-d",strtotime("-30 days"))." 00:00:00' AND '".date("Y-m-d")." 23:59:59' ";
$SQL_ .= " AND created_date BETWEEN '".date("Y-m-d",strtotime($FromDate))." 00:00:00' AND '".date("Y-m-d",strtotime($ToDate))." 23:59:59' ";
$SQL_ .= " GROUP BY tokenid";
$rsCountSurveyOver = $objDB->sql_query($SQL_);
if(count($rsCountSurveyOver) > 0){
foreach($rsCountSurveyOver as $key => $val) {
$SUMOve = $SUMOve + $val['AvgValue'];
}
}
}
}else{
//$returnArr[] = "0.00";
//echo "NO PAGES FOUND";
}
}
}
$returnArr['today_lowrating'] = $SUM;
$returnArr['ove_lowrating'] = $SUMOve;
return $returnArr;
}
function fetchTotalFeedback($type,$BranchID,$IndustryID,$orgID,$FromDate,$ToDate){
global $objDB,$pg,$currentDate;
include_once("summery.php");
$bojSummery = new include_summery();
//$SQL = "SELECT userId FROM beatle_userlogin WHERE db_username = 'Guest' AND db_userLoginName = 'Guest' AND db_usertype = 'End_user' ";
$SQL = "SELECT userId FROM beatle_userlogin WHERE db_userLoginName = 'Guest' AND db_usertype = 'End_user' ";
$rsGuest = $objDB->sql_query($SQL);
//$guestid = $rsGuest[0]['userId'];
$idArr = array();
for($i=0; $i<count($rsGuest); $i++){
if(!in_array($rsGuest[$i]['userId'],$idArr)) {
$idArr[] = $rsGuest[$i]['userId'];
}
}
$datetime1 = new DateTime($FromDate);
$datetime2 = new DateTime($ToDate);
$interval = $datetime1->diff($datetime2);
$diff = $interval->format('%a');
$diff = $diff + 1;
$rsBranches = $bojSummery->fetchBranchesData($BranchID);
$returnArr = array();
$avgUSTotal = 0;
for($i=0; $i<count($rsBranches); $i++) {
$rsIndustry = $bojSummery->fetchIndustryData($rsBranches[$i]['branchId'],$IndustryID);
$cnt = count($rsIndustry);
for($indst=0; $indst < $cnt; $indst++){
$SQL = "SELECT count(pageId) AS pageId FROM beatle_page WHERE pageId IN (".$rsIndustry[$indst]['db_pagesId'].") AND db_pagetype = 'Content'";
$rsCountContnentPages = $objDB->sql_query($SQL);
$rsPages = explode(",",$rsIndustry[$indst]['db_pagesId']);
if(count($rsPages) > 0 && !empty($rsIndustry[$indst]['db_pagesId'])) {
#################################
$SQL = "SELECT GROUP_CONCAT(IndId) AS IndustryIDs FROM beatle_industry WHERE db_ind_type_id = ".$rsIndustry[$indst]['db_ind_type_id']."";
$SQL .= " AND IndId = ".$rsIndustry[$indst]['IndId'];
$rsIndustryIDs = $objDB->sql_query($SQL);
#################################
if(!empty($rsIndustryIDs[0]['IndustryIDs'])){
$SQL = "SELECT count(db_surveyValue) AS TotalCount FROM beatle_survey WHERE
db_surveyPageid IN (".$rsIndustry[$indst]['db_pagesId'].") AND
db_surveyValue IN (1,2,3,4,5) AND is_submit = 'Y' ";
$SQL .= " AND db_surveyIndId IN (".$rsIndustryIDs[0]['IndustryIDs'].") ";
$SQL .= " AND orgid = ".$orgID. " AND db_surveyBranchid = ".$rsBranches[$i]['branchId'];
if(empty($currentDate))
$SQL .= " AND created_date BETWEEN '".date("Y-m-d")." 00:00:00' AND '".date("Y-m-d")." 23:59:59' ";
else
$SQL .= " AND created_date BETWEEN '".date("Y-m-d",strtotime($currentDate))." 00:00:00' AND '".date("Y-m-d",strtotime($currentDate))." 23:59:59' ";
$SQL .= " GROUP BY tokenid";
$rsCountSurvey = $objDB->sql_query($SQL);
$returnArr['count'] = count($rsCountSurvey);
//echo "<pre>";
//print_r($rsCountSurvey);
//echo "</pre>";
// TOTAL FEEDBACK
$SQL = "SELECT COUNT(db_surveyValue) AS TotalCount FROM beatle_survey WHERE
db_surveyPageid IN (".$rsIndustry[$indst]['db_pagesId'].") AND
db_surveyValue IN (1,2,3,4,5) AND is_submit = 'Y' ";
$SQL .= " AND db_surveyIndId IN (".$rsIndustryIDs[0]['IndustryIDs'].") ";
$SQL .= " AND orgid = ".$orgID. " AND db_surveyBranchid = ".$rsBranches[$i]['branchId'];
if($pg == 'summery'){
$SQL .= " AND created_date BETWEEN '".date("Y-m-d",strtotime("-30 days"))." 00:00:00' AND '".date("Y-m-d")." 23:59:59' ";
}else{
$SQL .= " AND created_date BETWEEN '".date("Y-m-d",strtotime($FromDate))." 00:00:00' AND '".date("Y-m-d",strtotime($ToDate))." 23:59:59' ";
}
$SQL .= " GROUP BY tokenid";
$rsTotalCountSurvey = $objDB->sql_query($SQL);
$returnArr['guest_total'] = count($rsTotalCountSurvey);
// GUEST FEEDBACK
$SQL = "SELECT COUNT(db_surveyValue) AS TotalCount FROM beatle_survey WHERE
db_surveyPageid IN (".$rsIndustry[$indst]['db_pagesId'].") AND
db_surveyValue IN (1,2,3,4,5) AND is_submit = 'Y' AND db_surveyUserid IN (".implode(",",$idArr).") ";
$SQL .= " AND db_surveyIndId IN (".$rsIndustryIDs[0]['IndustryIDs'].") ";
$SQL .= " AND orgid = ".$orgID. " AND db_surveyBranchid = ".$rsBranches[$i]['branchId'];
if($pg == 'summery')
$SQL .= " AND created_date BETWEEN '".date("Y-m-d",strtotime("-30 days"))." 00:00:00' AND '".date("Y-m-d")." 23:59:59' ";
else
$SQL .= " AND created_date BETWEEN '".date("Y-m-d",strtotime($FromDate))." 00:00:00' AND '".date("Y-m-d",strtotime($ToDate))." 23:59:59' ";
$SQL .= " GROUP BY tokenid";
$rsGuestCountSurvey = $objDB->sql_query($SQL);
$returnArr['guest_count'] = count($rsGuestCountSurvey);
}
else{
//echo "<br /> ELSE HERE <br />";
$returnArr['count'] = 0;
$returnArr['guest_total'] = 0;
$returnArr['guest_count'] = 0;
//$returnArr['weekly_feedback_total'] = array(0=>0,1=>0,2=>0,3=>0,4=>0,5=>0,6=>0);
}
// $avgValue = number_format($rsCountSurvey[0]['AvgValue'],2);
}else{
//echo "NO PAGES FOUND";
}
}
}
//echo "EXIT HERE";
//echo "<pre>";
//print_r($returnArr);
//echo "</pre>";
return $returnArr;
}
function FetchCustomerData($branchid,$indid,$orgid,$today = 'N',$FromDate,$ToDate){
global $objDB,$pg,$currentDate;
//include_once("summery.php");
///$bojSummery = new include_summery();
if($today == 'N') {
if($pg == 'summery') {
$SQL = "SELECT GROUP_CONCAT(DISTINCT db_surveyUserid SEPARATOR ',') AS db_surveyUserid FROM beatle_survey WHERE orgid = ".$_SESSION['OtherInfo']['OrgID']." AND is_submit = 'Y' GROUP BY created_date";
$rsUserIDS = $objDB->sql_query($SQL);
}else if($pg == 'dashboardma'){
$SQL = "SELECT GROUP_CONCAT(DISTINCT db_surveyUserid SEPARATOR ',') AS db_surveyUserid FROM beatle_survey WHERE orgid = ".$_SESSION['OtherInfo']['OrgID']." AND is_submit = 'Y' AND created_date BETWEEN '".date("Y-m-d",strtotime($FromDate))." 00:00:00' AND '".date("Y-m-d",strtotime($ToDate))." 23:59:59' GROUP BY created_date";
$rsUserIDS = $objDB->sql_query($SQL);
}
}else{
$SQL = "SELECT GROUP_CONCAT(DISTINCT db_surveyUserid SEPARATOR ',') AS db_surveyUserid FROM beatle_survey WHERE orgid = ".$_SESSION['OtherInfo']['OrgID']." AND is_submit = 'Y' ";
if(empty($currentDate))
$SQL .= "AND created_date BETWEEN '".date("Y-m-d")." 00:00:00' AND '".date("Y-m-d")." 23:59:59' GROUP BY created_date";
else
$SQL .= "AND created_date BETWEEN '".date("Y-m-d",strtotime($currentDate))." 00:00:00' AND '".date("Y-m-d",strtotime($currentDate))." 23:59:59' GROUP BY created_date";
$rsUserIDS = $objDB->sql_query($SQL);
}
if(count($rsUserIDS) <= 0)
return 0;
$idArr = array();
for($i=0; $i<count($rsUserIDS); $i++){
if(!in_array($rsUserIDS[$i]['db_surveyUserid'],$idArr)) {
$idArr[] = $rsUserIDS[$i]['db_surveyUserid'];
}
}
if(count($idArr) <= 0){
return 0;
}
//changed bcoz of login issue
$SQL = "SELECT userId FROM beatle_userlogin WHERE userId IN (".implode(',',$idArr).") AND lower(db_usertype) = 'end_user'";
//if(!empty($this->CustomerID)){
//$SQL .= " AND `userId` = ".$this->CustomerID;
//}
$rsUserInfo = $objDB->sql_query($SQL);
$idArr = array();
for($i=0; $i<count($rsUserInfo); $i++){
if(!in_array($rsUserInfo[$i]['userId'],$idArr)) {
$idArr[] = $rsUserInfo[$i]['userId'];
}
}
//$SQL = "SELECT * FROM beatle_survey WHERE is_submit = 'Y' AND db_surveyUserid IN (".implode(",",$idArr).") AND orgid = ".$_SESSION['OtherInfo']['OrgID']." GROUP BY db_surveyUserid ORDER BY created_date DESC";
//if(count($idArr) > 0) {
$SQL = "SELECT
beatle_survey.surveyId,
beatle_survey.db_surveyBranchid,
beatle_survey.db_surveyUserid,
beatle_survey.db_surveyIndId,
beatle_survey.db_surveyPageid,
beatle_survey.db_surveyContentId,
beatle_survey.db_surveyValue,
beatle_survey.created_date,
beatle_survey.updated_date,
beatle_survey.tokenid,
beatle_survey.orgid,
beatle_survey.is_submit,
beatle_userlogin.db_phone,
beatle_userlogin.db_userLoginName,
beatle_userlogin.db_username,
beatle_userlogin.userId
FROM
beatle_survey
INNER JOIN beatle_userlogin ON beatle_survey.db_surveyUserid = beatle_userlogin.userId
WHERE beatle_survey.is_submit = 'Y' AND beatle_survey.db_surveyUserid IN (".implode(",",$idArr).") ";
$SQL .= " AND beatle_userlogin.db_username <> 'Guest' AND beatle_userlogin.db_userLoginName <> 'Guest' " ;
//if(!empty($this->FromDate) && !empty($this->ToDate)){
//$SQL .= " AND beatle_survey.created_date BETWEEN '".date("Y-m-d",strtotime($this->FromDate))." 00:00:00' AND '".date("Y-m-d",strtotime($this->ToDate))." 23:59:59' ";
//}
if(!empty($orgid))
$SQL .= " AND beatle_survey.orgid = ".$orgid." " ;
else
$SQL .= " AND beatle_survey.orgid = ".$_SESSION['OtherInfo']['OrgID']." " ;
if(!empty($branchid))
$SQL .= " AND beatle_survey.db_surveyBranchid = ".$branchid." " ;
if(!empty($indid))
$SQL .= " AND beatle_survey.db_surveyIndId = ".$indid." " ;
if($pg == 'summery') {
if($today == 'Y') {
if(empty($currentDate))
$SQL .= " AND beatle_survey.created_date BETWEEN '".date("Y-m-d")." 00:00:00' AND '".date("Y-m-d")." 23:59:59' ";
else
$SQL .= " AND beatle_survey.created_date BETWEEN '".date("Y-m-d",strtotime($currentDate))." 00:00:00' AND '".date("Y-m-d",strtotime($currentDate))." 23:59:59' ";
}
}else if($pg == 'dashboardma'){
if($today == 'Y') {
$SQL .= " AND beatle_survey.created_date BETWEEN '".date("Y-m-d")." 00:00:00' AND '".date("Y-m-d")." 23:59:59' ";
}
else if($today == 'N') {
$SQL .= " AND beatle_survey.created_date BETWEEN '".date("Y-m-d",strtotime($FromDate))." 00:00:00' AND '".date("Y-m-d",strtotime($ToDate))." 23:59:59' ";
}
}
//if(!empty($this->TokenID))
//$SQL .= " AND beatle_survey.tokenid = '".$this->TokenID."' " ;
$SQL .= " GROUP BY beatle_survey.tokenid ORDER BY beatle_survey.created_date DESC";
$rsUserInfo_ = $objDB->sql_query($SQL);
//echo count($rsUserInfo_);
//die();
return count($rsUserInfo_);
}
function fetchTotalUser(){
global $objDB;
$SQL = "SELECT BranchID, IndustryID FROM beatle_userlogin WHERE userId = ".$_SESSION['UserInfo']['UserID'];
$rsData = $objDB->sql_query($SQL);
$orgid = $_SESSION['OtherInfo']['OrgID'];
$branchid = $rsData[0]['BranchID'];
$indid = $rsData[0]['IndustryID'];
$SQL = "SELECT count(userId) AS TotalUser FROM beatle_userlogin WHERE OrgID = ".$orgid." AND db_usertype != 'End_user' ";
if(!empty($branch) && $branch != 0){
$SQL .= " AND BranchID = ".$branchid." " ;
}
if(!empty($indid) && $indid != 0){
$SQL .= " AND IndustryID = ".$indid." " ;
}
$rsData = $objDB->sql_query($SQL);
$user = $rsData[0]['TotalUser'] - 1;
if($user <= 0)
$user = 0;
return $user;
}
function fetchMyVisitData_Customer(){
global $objDB;
$SQL = "SELECT
beatle_survey.surveyId AS totalVisit
FROM
beatle_survey
INNER JOIN beatle_userlogin ON beatle_survey.db_surveyUserid = beatle_userlogin.userId
WHERE beatle_survey.is_submit = 'Y' AND beatle_survey.db_surveyUserid = ".$_SESSION['UserInfo']['UserID'];
$SQL .= " GROUP BY beatle_survey.tokenid ORDER BY beatle_survey.created_date DESC";
//echo $SQL;
$rsUserInfo_ = $objDB->sql_query($SQL);
$totalVisit = count($rsUserInfo_);
return $totalVisit;
}
function fetchMyOrderData_Customer(){
global $objDB;
$SQL = "SELECT * FROM beatle_order WHERE userid = ".$_SESSION['UserInfo']['UserID']." ORDER BY created_date DESC";
$rsOrderd = $objDB->sql_query($SQL);
return count($rsOrderd);
}
function addEmailSendInformation($insertArr){
global $objDB;
$SQL = "INSERT INTO beatle_crone SET
userid = '".$insertArr['userid']."',
orgid = '".$insertArr['orgid']."',
emailid = '".$insertArr['emailid']."',
indid = '".$insertArr['indid']."',
branchid = '".$insertArr['branchid']."',
customername = '".$insertArr['customername']."',
send_by_id = '".$insertArr['send_by_id']."',
emailbody = '".$insertArr['emailbody']."',
status = '".$insertArr['status']."',
created_date = '".$insertArr['created_date']."',
sent_date = '".$insertArr['sent_date']."',
type = '".$insertArr['type']."',
response = '".$insertArr['response']."',
email_subject = '".$insertArr['email_subject']."' ";
$objDB->sql_query($SQL);
}
function updateEmailSentInformation($status,$croneid,$response){
global $objDB;
$SQL = "UPDATE beatle_crone SET
sent_date = '".date("Y-m-d H:i:s")."',
response = '".$response."',
status = '".$status."'
WHERE
croneid = ".$croneid;
$upload = $objDB->sql_query($SQL);
}
function fetchTotalPointsClient(){
global $objDB;
$SQL = "SELECT SUM(point) AS TotalPoint FROM beatle_offers_apply WHERE approved = 'Y' AND orgid = ".$_SESSION['OtherInfo']['OrgID'];
$rsData = $objDB->sql_query($SQL);
$SQL = "SELECT SUM(point) AS UsedTotalPoint FROM beatle_manage_points WHERE orgid = ".$_SESSION['OtherInfo']['OrgID'];
$rsUsedData = $objDB->sql_query($SQL);
return ($rsData[0]['TotalPoint'] - $rsUsedData[0]['UsedTotalPoint']);
}
function fetchRemainPointClient($type){
global $objDB;
$SQL = "SELECT customer_use_point AS UsedTotalPoint FROM beatle_manage_points WHERE type = '".$type."' AND orgid = ".$_SESSION['OtherInfo']['OrgID']." ORDER BY id DESC LIMIT 1";
$rsUsedData = $objDB->sql_query($SQL);
if($rsUsedData[0]['UsedTotalPoint'] > 0)
return $rsUsedData[0]['UsedTotalPoint'];
else
return 0;
}
function deductPointFromDB(){
global $objDB;
$SQL = "SELECT * FROM beatle_manage_points WHERE orgid = ".$_SESSION['OtherInfo']['OrgID']." ORDER BY id DESC LIMIT 1";
$rsUsedData = $objDB->sql_query($SQL);
if($rsUsedData[0]['customer_use_point'] > 0) {
$pt = $rsUsedData[0]['customer_use_point'] - 1;
$SQL = "UPDATE beatle_manage_points SET
customer_use_point = '".$pt."' WHERE id = ".$rsUsedData[0]['id'];
$objDB->sql_query($SQL);
}
}
function fetchAllRedeemData(){
global $objDB;
$SQL = "SELECT * FROM beatle_manage_points WHERE orgid = ".$_SESSION['OtherInfo']['OrgID']." ORDER BY id DESC LIMIT 5";
$rsData = $objDB->sql_query($SQL);
return $rsData;
}
function fetchAllPurchaseHistoryData(){
global $objDB;
$SQL = "SELECT * FROM beatle_purchase WHERE orgid = ".$_SESSION['OtherInfo']['OrgID']." ORDER BY purchaseid DESC LIMIT 5";
$rsData = $objDB->sql_query($SQL);
return $rsData;
}
function fetch_ticket_for_tabbing($type,$today=''){
// parameters of today = today,monthly
// parameters of type = new,
global $objDB,$currentDate;
if($_SESSION['UserInfo']['UType'] == 'line_manager') {
$SQL = "SELECT * FROM beatle_ticket WHERE
assignto = ".$_SESSION['UserInfo']['UserID']." AND
assignto_type = 'line_manager' AND
parentid = 0 ";
}
else if($_SESSION['UserInfo']['UType'] == 'manager') {
$SQL = "SELECT * FROM beatle_ticket WHERE 1 = 1 AND
(assignto_type = 'line_manager' OR assignto_type = 'manager') ";
}else if($_SESSION['UserInfo']['UType'] == 'owner'){
$SQL = "SELECT * FROM beatle_ticket WHERE 1 = 1 ";
}
// $SQL = "";
$SQL .= " AND orgid = ".$_SESSION['OtherInfo']['OrgID']." ";
if($_SESSION['UserInfo']['UType'] != 'owner')
$SQL .= " AND branchid = ".$_SESSION['OtherInfo']['BranchID']." ";
if($_SESSION['UserInfo']['UType'] == 'manager')
{
$SQL .= " AND indid IN (SELECT IndId FROM beatle_industry WHERE db_bracnchid = ".$_SESSION['OtherInfo']['BranchID'].")";
}
else if($_SESSION['UserInfo']['UType'] == 'line_manager'){
$SQL .= " AND indid = ".$_SESSION['OtherInfo']['IndustryID'];
}
if($type != ''){
if($type == 'new'){
$SQL .= " AND (status = 'new' OR status = 'forward') ";
}else
$SQL .= " AND status = '".$type."' ";
}
$SQL .= " AND usertype = 'End_user' ";
if($today == 'today'){
if(empty($curDate))
$curDate = date("Y-m-d");
else
$curDate = date("Y-m-d",strtotime($currentDate));
$SQL .= " AND created_date BETWEEN '".$curDate." 00:00:00' AND '".$curDate." 23:59:59' ";
}else if($today == 'monthly'){
$prevDate = date("Y-m-d",strtotime("-1 month"));
$curDate = date("Y-m-d");
$SQL .= " AND created_date BETWEEN '".$prevDate." 00:00:00' AND '".$curDate." 23:59:59' ";
}
//$SQL .= " AND active = 'Y' ";
$SQL .= " GROUP BY ticketuid ORDER BY created_date DESC";
//echo $SQL;
$rsUserInfo = $objDB->sql_query($SQL);
$cntRtn = count($rsUserInfo);
if(strlen(count($rsUserInfo)) == 1)
$cntRtn = "0".count($rsUserInfo);
return $cntRtn;
}
function fetchActiveScoreCheckedData(){
global $objDB;
$SQL = "select db_pagepermistion from beatle_userlogin where userId = ".$_SESSION['UserInfo']['UserID'];
$rsData = $objDB->sql_query($SQL);
if(strpos($rsData[0]['db_pagepermistion'],"ason")){
return "checked";
}else{
if($rsData[0]['db_pagepermistion'] == "ason")
return "checked";
else
return "";
}
}
function fetchPercentageViewCheckedData(){
global $objDB;
$SQL = "select db_pagepermistion from beatle_userlogin where userId = ".$_SESSION['UserInfo']['UserID'];
$rsData = $objDB->sql_query($SQL);
if(strpos($rsData[0]['db_pagepermistion'],"pvon")){
return "checked";
}else{
if($rsData[0]['db_pagepermistion'] == "pvon")
return "checked";
else
return "";
}
}
function fetchZeroFeedbackDays($orgID,$BranchID,$IndustryID,$FromDate,$ToDate){
global $objDB;
//$date = $this->FromDate;
//$end_date = $this->ToDate;
$SQL = "SELECT surveyId FROM beatle_survey WHERE is_submit = 'Y' ";
if(empty($BranchID) and empty($IndustryID)){
$SQL .= " AND orgid = ".$orgID;
}elseif(!empty($BranchID) and empty($IndustryID)){
$SQL .= " AND orgid = ".$orgID." AND db_surveyBranchid = ".$BranchID;
}elseif(!empty($BranchID) && !empty($IndustryID)){
$SQL .= " AND orgid = ".$orgID." AND db_surveyBranchid = ".$BranchID." AND db_surveyIndId = ".$IndustryID;
}
$SQL .= " AND created_date BETWEEN '".date("Y-m-d",strtotime($FromDate))." 00:00:00' AND '".date("Y-m-d",strtotime($ToDate))." 23:59:59' ";
$SQL .= " GROUP BY DATE(created_date)";
$rsCountDay = $objDB->sql_query($SQL);
return count($rsCountDay);
}
?>