Current File : /home/inlingua/public_html/sensoriumpsychologists.com/include/function/basic.php
<?php
function include_functions($functions)
{
	foreach ($functions as $value):
		if(file_exists(DIR_FS_SITE.'include/function/'.$value.'.php')):
			include_once(DIR_FS_SITE.'include/function/'.$value.'.php');
		endif;
	endforeach;
}

function display_message($unset=0)
{
	$admin_user= new admin_session();
	if($admin_user->isset_pass_msg()):

		foreach ($admin_user->get_pass_msg() as $value):
			if(!is_array($value))
			{
				if (strstr($value, 'successfully'))
				{
		?>
<div class="alert alert-success alt alert-dismissible fade in">
		
		<button aria-hidden="true" data-dismiss="alert" class="close" type="button">&times;</button><strong>Success!</strong><br>
			
<?		
				echo '<i class="alert-icon border flaticon-check-mark"></i>';	
					echo '<p><b></b>&nbsp;'.$value.'</p>';
				}
				else
				{  ?>
			<div class="alert alert-danger alt alert-dismissible fade in">
<button type="button" data-dismiss="alert" aria-label="Close" class="close"><span aria-hidden="true">×</span></button><i class="alert-icon border flaticon-exclamation-mark1"></i><strong>Error Message!</strong><br>		
		
		<? echo '<i class="alert-icon border flaticon-exclamation-mark1"></i>';
					echo '<p style="color:white"><b></b>&nbsp;'.$value.'</p>';
				}
			}
			else
			{ ?>
<div class="alert alert-danger alt alert-dismissible fade in">
<button type="button" data-dismiss="alert" aria-label="Close" class="close"><span aria-hidden="true">×</span></button><i class="alert-icon border flaticon-exclamation-mark1"></i><strong>Error Message!</strong><br>
	<?		
				echo '<i class="alert-icon border flaticon-exclamation-mark1"></i>';
				foreach ($value as $val):
					echo '<p style="color:white"><b></b>&nbsp;'.$val.'</p>';
				endforeach; 
			}
		endforeach;
		?>
	</div>
<?php
	
	endif;
	($unset)?$admin_user->unset_pass_msg():'';
}

function get_billing_var_if_set($var)
{
	global $billing_address;
	return isset($billing_address[$var])?$billing_address[$var]:'';
}

function get_var_if_set($array, $var)
{
	return isset($array[$var])?$array[$var]:'';
}

function get_template($template_name, $array, $selected='')
{
	include_once(DIR_FS_SITE.'template/'.TEMPLATE.'/'.$template_name.'.php');
}

function head()
{
	# include all the header related things here... like... common meta tags/javascript files etc.
		?>
		<!--[if IE 6]>
		<link rel="stylesheet" type="text/css" href="<?php echo DIR_WS_SITE?>css/iecss.css" />
		<![endif]-->
		<script type="text/javascript" src="<?php echo DIR_WS_SITE?>js/boxOver.js"></script>
		<script type="text/javascript" src="<?php echo DIR_WS_SITE?>control/js/jquery-1.2.6.min.js"></script>
		<script type="text/javascript" src="<?php echo DIR_WS_SITE?>javascript/error_msg.js"></script>
		<?php
}

function body()
{
	# include all the body related things like... tracking code here.
	
}

function footer()
{
	# if you need to add something to the website footer... please add here.
}

function array_map_recursive($callback, $array) {
  $b = Array();
  foreach ($array as $key => $value) {
    $b[$key] = is_array($value) ? array_map_recursive($callback, $value) : call_user_func($callback, $value);
  }
  return $b;
}

function generatePassword($length = 6, $add_dashes = false, $available_sets = 'stpw')
{
	$sets = array();
	if(strpos($available_sets, 's') !== false)
		$sets[] = 'abcdefghjkmnpqrstuvwxyz';
	if(strpos($available_sets, 't') !== false)
		$sets[] = 'ABCDEFGHJKMNPQRSTUVWXYZ';
	if(strpos($available_sets, 'p') !== false)
		$sets[] = '23456789';
	if(strpos($available_sets, 'w') !== false)
		$sets[] = '!@#$%&*?';
	 
	$all = '';
	$password = '';
	foreach($sets as $set)
	{
		$password .= $set[array_rand(str_split($set))];
		$all .= $set;
	}
	 
	$all = str_split($all);
	for($i = 0; $i < $length - count($sets); $i++)
		$password .= $all[array_rand($all)];
	 
	$password = str_shuffle($password);
	 
	if(!$add_dashes)
		return $password;
	 
	$dash_len = floor(sqrt($length));
	$dash_str = '';
	while(strlen($password) > $dash_len)
	{
		$dash_str .= substr($password, 0, $dash_len) . '-';
		$password = substr($password, $dash_len);
	}
	$dash_str .= $password;
	return $dash_str;
}
function checkEmailexist($username)
{
	$QueryObj= new query('user');
	$QueryObj->Where="where username='".$username."'";
	$count = $QueryObj->count();
	if($count > 0):
		$flag ='<img src="'.DIR_WS_SITE_IMAGE.'not-available.png" />'; 
	else:
		$flag ='<img src="'.DIR_WS_SITE_IMAGE.'available.png" />';
	endif;
	return $flag; 
}
function getUserNameByID($ID)
{
	$QueryObj= new query('user');
	$QueryObj->Where="where id='".$ID."'";
	$user_info = $QueryObj->DisplayOne();
	$userName = $user_info->username;
	return $userName; 
}
function getUserDataByID($ID)
{
	$QueryObj= new query('user');
	$QueryObj->Where="where id='".$ID."'";
	$user_info = $QueryObj->DisplayOne();
	return $user_info; 
}

function getprojectinfo($ID)
{
	$QueryObj= new query('project');
	$QueryObj->Where="where id='".$ID."'";
	$project_info = $QueryObj->DisplayOne();
	
	return $project_info; 
}
function getNameBy($ID)
{
	$QueryObj= new query('user');
	$QueryObj->Where="where id='".$ID."'";
	$user_info = $QueryObj->DisplayOne();
	$userName = $user_info->first_name;
	return $userName; 
}
function create_slug($string){

// if no string
if($string == null){
return false;
}

$string = preg_replace( '/[«»""!?,.!@£$%^&*{};:()]+/', '', $string );
$string = strtolower($string);
$slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);

return $slug;
}
function getUserFullNameByID($ID)
{
	$QueryObj= new query('user');
	$QueryObj->Where="where id='".$ID."'";
	$user_info = $QueryObj->DisplayOne();
	if($user_info->access_level==5 || $user_info->access_level==6)
	{
		$userName = $user_info->companyname;
	}
	else
	{
		$userName = $user_info->firstname." ".$user_info->lastname;
	}
	return $userName; 
}
function getUserSnapByID($ID)
{
	$QueryObj= new query('user');
	$QueryObj->Where="where id='".$ID."'";
	$user_info = $QueryObj->DisplayOne();
	$userSnap = $user_info->prof_img;
	return $userSnap; 
}
function getCompanyID($ID)
{
	$QueryObj= new query('user');
	$QueryObj->Where="where id='".$ID."'";
	$user_info = $QueryObj->DisplayOne();
	$user_id = $user_info->id;
	return $user_id; 
}

function getCountryNameByISO($code)
{
	$QueryObj= new query('country');
	$QueryObj->Where="where iso='".$code."'";
	$country_info = $QueryObj->DisplayOne();
	$countryName = $country_info->name;
	return $countryName; 
}

function getUserContactNoByID($ID)
{
	$QueryObj= new query('user');
	$QueryObj->Where="where id='".$ID."'";
	$user_info = $QueryObj->DisplayOne();
	$userName = $user_info->phone;
	return $userName; 
}
function getPropertyAllreadySave($uID,$pId)
{
	$QueryObj= new query('watch_list');
	$QueryObj->Where="where user_id ='".$uID."' AND property_id = '".$pId."'";
	$prop_info = $QueryObj->DisplayOne();
	$count_watch_list = $QueryObj->GetNumRows();
	return $count_watch_list;
}
function getCurrentPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
function showLimitedWord($string, $word_limit)
{
    $words = explode(" ",$string);
    return implode(" ", array_splice($words, 0, $word_limit));
}
function quick_links_menu()
{
	$NotInArray = '"Home","Thank You","Login","Upload","About us","Resources","Home Page Add","Footer Section Contact Us","Footer Section Social Networks","Footer Section RSS Feed","Consignista Home Page Add"';
	$AllLinks = new query('content');
	$AllLinks->Where="where name NOT IN ($NotInArray) AND parent_id!='7'";
	$AllLinks->DisplayAll();
	while ($QueryLinks=$AllLinks->GetObjectFromRecord())
	{
		$urlPage = str_replace(" ","-",strtolower($QueryLinks->name));
?>
		<li><a href="<?=DIR_WS_SITE.$urlPage;?>"><?=$QueryLinks->name;?></a></li>
<?php
	}
}
function links_drop_down($p_id)
{
	$AllLinks = new query('content');
	$AllLinks->Where="where parent_id=".$p_id;
	$AllLinks->DisplayAll();
	echo "<ul>";
	while ($QueryLinks=$AllLinks->GetObjectFromRecord())
	{
		$urlPage = str_replace(" ","-",strtolower($QueryLinks->name));
?>
		<li><a href="<?=DIR_WS_SITE.$urlPage;?>"><?=$QueryLinks->name;?></a></li>
<?php
	}
	echo "</ul>";
}
function getPageContentById($content_id)
{
	$content_query= new query('content');
	$content_query->Where="where id='$content_id'";
	$content_object=$content_query->DisplayOne();
	$content=$content_object->page;
	return html_entity_decode($content);
}

function getValfromTblField($table_name,$field_name,$id)
{
	$tbl_query= new query($table_name);
	$tbl_query->Where="where id='$id'";
	$tbl_object=$tbl_query->DisplayOne();
	$value=$tbl_object->$field_name;
	return $value;
}
function checkUserRoleexist($role,$access_level)
{
	$QueryObj= new query('user_role');
	$QueryObj->Where="where role='".$role."' OR access_level='".$access_level."'";
	$count = $QueryObj->count();
	if($count > 0):
		return 0; 
	else:
		return 1;
	endif; 
}
function getRoleByAccLevel($access_level)
{
	$QueryObj= new query('user_role');
	$QueryObj->Where="where access_level='".$access_level."'";
	$tbl_object=$QueryObj->DisplayOne();
	$role = $tbl_object->role;
	return $role; 
}
function display_user_message($unset=0)
{
	$login_session= new user_session();
	if($login_session->isset_pass_msg()):
?>
	<div class="alert alert-warning alert-dismissable">
		<i class="fa fa-warning"></i>
		<!--<i class="fa fa-check"></i>-->
		<button aria-hidden="true" data-dismiss="alert" class="close" type="button">&times;</button>
		
		<?php
		foreach ($login_session->get_pass_msg() as $value):
			if(!is_array($value))
			{
				if (strstr($value, 'successfully'))
				{
					echo '<p><b>Success!</b>&nbsp;'.$value.'</p>';
				}
				else
				{
					echo '<p style="color:red"><b>Error!</b>&nbsp;'.$value.'</p>';
				}
			}
			else
			{
				foreach ($value as $val):
					echo '<p style="color:red"><b>Error!</b>&nbsp;'.$val.'</p>';
				endforeach; 
			}
		endforeach;
		?>
	</div>
<?php
	
	endif;
	($unset)?$login_session->unset_pass_msg():'';
}

function getCountryCodeBYISO($iso)
{
	$country_query= new query('country');
	$country_query->Where="where iso='$iso'";
	$country_object=$country_query->DisplayOne();
	$country_code=$country_object->phonecode;
	return $country_code;
}

function getCountryNameBYIP($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;
}
//Function to return out start and end dates of all months in a date range given

function rent_range($start_date, $end_date)
{
    $start_date = date("Y-m-d", strtotime($start_date));
    $end_date   = date("Y-m-d", strtotime($end_date));
    $start = strtotime($start_date);
    $end = strtotime($end_date);

    $month = $start;
    $months[] = date('Y-m', $start);
    while($month < $end) {
      $month = strtotime("+1 month", $month);
      $months[] = date('Y-m', $month);
    }

    foreach($months as $mon)
    {
        $mon_arr = explode( "-", $mon);
        $y = $mon_arr[0];
        $m = $mon_arr[1];
        $start_dates_arr[] = date("Y-m-d", strtotime($m.'/01/'.$y.' 00:00:00'));
        $end_dates_arr[] = date("Y-m-d", strtotime('-1 minute', strtotime('+1 month',strtotime($m.'/01/'.$y.' 00:00:00'))));
    }

    //to remove first month in start date and add our start date as first date
    array_shift($start_dates_arr);
    array_pop($start_dates_arr);
    array_unshift($start_dates_arr, $start_date);

    //To remove last month in end date and add our end date as last date
    array_pop($end_dates_arr);
    array_pop($end_dates_arr);
    array_push($end_dates_arr, $end_date);

    $result['start_dates'] = $start_dates_arr;
    $result['end_dates'] = $end_dates_arr;
    return $result;
}
function checkSignedUp($consultantId,$projectId)
{
	$QueryObj= new query('project_signup');
	$QueryObj->Where="where consultant_id='".$consultantId."' AND project_id='".$projectId."' AND is_approved!='No'";
	$info = $QueryObj->DisplayAll();
	$count_data = $QueryObj->GetNumRows();
	return $count_data;
}
function checkSignedUpApp($consultantId,$projectId)
{
	$QueryObj= new query('project_signup');
	$QueryObj->Where="where consultant_id='".$consultantId."' AND project_id='".$projectId."' AND is_approved='No'";
	$info = $QueryObj->DisplayAll();
	$count_data = $QueryObj->GetNumRows();
	return $count_data;
} 

function getUserInfoByID($ID)
{
	$QueryObj= new query('user');
	$QueryObj->Where="where id='".$ID."'";
	$user_info = $QueryObj->DisplayOne();
	return $user_info; 
}

function strip_html_tags( $text )
{
	$text = preg_replace(
		array(
			// Remove invisible content
			'@<p[^>]*?>.*?</p>@siu',
			'@<head[^>]*?>.*?</head>@siu',
			'@<style[^>]*?>.*?</style>@siu',
			'@<script[^>]*?.*?</script>@siu',
			'@<object[^>]*?.*?</object>@siu',
			'@<embed[^>]*?.*?</embed>@siu',
			'@<applet[^>]*?.*?</applet>@siu',
			'@<noframes[^>]*?.*?</noframes>@siu',
			'@<noscript[^>]*?.*?</noscript>@siu',
			'@<noembed[^>]*?.*?</noembed>@siu',

			// Add line breaks before & after blocks
			'@<((br)|(hr))@iu',
			'@</?((address)|(blockquote)|(center)|(del))@iu',
			'@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu',
			'@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu',
			'@</?((table)|(th)|(td)|(caption))@iu',
			'@</?((form)|(button)|(fieldset)|(legend)|(input))@iu',
			'@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu',
			'@</?((frameset)|(frame)|(iframe))@iu',
		),
		array(
			' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
			"\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0",
			"\n\$0", "\n\$0",
		),
		$text );
	return strip_tags( $text );
}

function getnamebyid1($TableName="",$FieldName="",$Id="",$FieldName1="")
{
	$QueryObj= new query($TableName);
	$QueryObj->Where="where ".$FieldName."='".$Id."'";
	$cate_info = $QueryObj->DisplayOne();
	$cate_Name = $cate_info->$FieldName1;
	return $cate_Name; 
	
}

function getUsersCountBycountry()
{
	$data = '<tr>';
		$data .= '<td align="center"><a href="#">USA</a></td>';
		$data .= '<td align="center">0</td>';
		$data .= '<td align="center">0</td>';
	$data .= '</tr>';
	return $data;
}

function signUpconsultentBypublicationId($pubId)
{
	$comma = "";
	$consultant_ids = "";
	$QueryObj= new query('project_signup');
	$QueryObj->Where="where project_id='".$pubId."' AND consultant_id != project_whoner";
	$QueryObj->DisplayAll();
	$consultant_count = $QueryObj->GetNumRows();
	$i = 1;
	while($consultant_info = $QueryObj->GetObjectFromRecord())
	{
		$otherAuthore = getUserInfoByID($consultant_info->consultant_id);
		$otherAuthore_access_level = $otherAuthore->access_level;
		switch (true) :
			case ($i < $consultant_count) :
				$comma = ", ";
			break;
			case ($i == $consultant_count) :
				$comma = "";
			break;
		endswitch;
		if($otherAuthore_access_level == 4)
		{
			$consultant_ids .= "<a href='".make_url('consltant','id='.$consultant_info->consultant_id)."'>".getUserFullNameByID($consultant_info->consultant_id)."</a>" .$comma;
		}
		else
		{
			$consultant_ids .= getUserFullNameByID($consultant_info->consultant_id)."".$comma;
		}
		$i++;
	}
	return $consultant_ids;
}

function getLinkwithHttp($link)
{
	if($link != '')
	{
		if (strpos($link,'http://') !== false || strpos($link,'https://') !== false)
		{
			$linkUrl = $link;
		}
		else
		{
			$linkUrl = "http://".$link;
		}
	}
	else
	{
		$linkUrl = $link;
	}
	return $linkUrl;
}

function cat_list($p_cid=0,$space=''){
 	 $q="SELECT * FROM categories WHERE parent_id='$p_cid'";
	$r=mysql_query($q) or die(mysql_error());
	
	$count=mysql_num_rows($r);
	
	if($p_cid==0){
		$space='';
	}else{
		$space .="&nbsp;&nbsp;&nbsp;&nbsp;";
	}
	if($count > 0){
		
		while($row=mysql_fetch_array($r)){
			echo "<option value='".$row['id']."' >".$space.$row['category']."</option>";
			
			cat_list($row['id'],$space);
		}
		
	}
}

?>