
PK 
<?php
//include '../settings/constant.php';
//include('Mail.php');
//include('Mail/mime.php');
//include 'mimetype.php';
require("class.phpmailer.php");
class FUNCTIONS {
/////////////////////////////////////////////////////////////////////////////////////////
//GENERAL FUNCTIONS//////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
//Function to get current page url============================================
public function getpageurl(){
$relative_path = $_SERVER['PHP_SELF'];
$relative_path_arr = explode('/', $relative_path);
$page_uri = $relative_path_arr[count($relative_path_arr)-1];
return $page_uri;
}
public function curPageURL() {
$pageURL = 'http';
if(isset($_SERVER["HTTPS"]))
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 to get the clients IP Address======================================
public function getClientIP() {
if (isset($_SERVER)) {
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
return $_SERVER["HTTP_X_FORWARDED_FOR"];
if (isset($_SERVER["HTTP_CLIENT_IP"]))
return $_SERVER["HTTP_CLIENT_IP"];
return $_SERVER["REMOTE_ADDR"];
}
if (getenv('HTTP_X_FORWARDED_FOR'))
return getenv('HTTP_X_FORWARDED_FOR');
if (getenv('HTTP_CLIENT_IP'))
return getenv('HTTP_CLIENT_IP');
return getenv('REMOTE_ADDR');
}
//============================================================================
//Function to upload the file=================================================
public function uploadFile($newfilename, $foldername, $id){
$allowedExts = array("jpeg", "jpg", "png");
$temp = explode(".", $_FILES[$id]["name"]);
$extension = end($temp);
//$rand = uniqid('CHILD-',true);
if (in_array($extension, $allowedExts)) {
move_uploaded_file($_FILES[$id]["tmp_name"], $foldername.$newfilename.'.'.$extension);
$flag[0] = 1;
$flag[1] = $foldername.$newfilename.'.'.$extension;
$flag[2] = $newfilename.'.'.$extension;
$flag[3] = $extension;
} else {
$msg = "Invalid file type";
$flag[0] = 0;
}
return $flag;
}
//============================================================================
//Function to upload the file=================================================
public function uploadPdf($newfilename, $foldername, $id){
$allowedExts = "pdf";
$temp = explode(".", $_FILES[$id]["name"]);
$extension = end($temp);
//$rand = uniqid('CHILD-',true);
if ($allowedExts) {
move_uploaded_file($_FILES[$id]["tmp_name"], $foldername.$newfilename.'.'.$extension);
$flag[0] = 1;
$flag[1] = $foldername.$newfilename.'.'.$extension;
$flag[2] = $newfilename.'.'.$extension;
$flag[3] = $extension;
} else {
$msg = "Invalid file type";
$flag[0] = 0;
}
return $flag;
}
//============================================================================
//Function to upload the MS-Excel file========================================
public function uploadExcelFile($newfilename, $foldername, $id){
$allowedExts = array("xls", "xlsx");
$temp = explode(".", $_FILES[$id]["name"]);
$extension = end($temp);
//$rand = uniqid('CHILD-',true);
if (in_array($extension, $allowedExts)) {
move_uploaded_file($_FILES[$id]["tmp_name"], $foldername.$newfilename.'.'.$extension);
$flag[0] = 1;
$flag[1] = $foldername.$newfilename.'.'.$extension;
$flag[2] = $newfilename.'.'.$extension;
$flag[3] = $extension;
} else {
$msg = "Invalid file type";
$flag[0] = 0;
}
return $flag;
}
//============================================================================
public function generateOTP($digit){
$x = $digit-1; // Amount of digits
$min = pow(10,$x);
$max = (pow(10,$x+1)-1);
$otp = rand($min, $max);
$_SESSION['otpAuth'] =$otp;
return $otp;
}
//Function to Send SMS========================================================
public function sendSMS($msg, $numbers){
//Sender ID,While using route4 sender id should be 6 characters long.
$senderId = "DEMOOO";
//Your message to send, Add URL encoding here.
$message = urlencode($msg);
//Define route
//$route = "default";
$route = "2";
//API URL
//http://198.24.149.4/API/pushsms.aspx?loginID=askermd10&password=123456&mobile=8794944152&text=HI HOW ARE YOU&senderid=DEMOOO&route_id=2&Unicode=0
$url="http://198.24.149.4/API/pushsms.aspx?loginID=askermd10&password=123456&mobile=".$numbers."&text=".$message."&senderid=".$senderId."&route_id=".$route."&Unicode=0";
// init the resource
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_RETURNTRANSFER => true,
));
//Ignore SSL certificate verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//get response
$output = curl_exec($ch);
//Print error if any
if(curl_errno($ch))
{
echo 'error:' . curl_error($ch);
}
curl_close($ch);
return $output;
}
//============================================================================
//Function to Send Email======================================================
public function sendMail($maildata=NULL, $smtp=NULL){
$recipients = (!empty($maildata->to)?$maildata->to.', ':'').
(!empty($maildata->cc)?$maildata->cc.', ':'').
(!empty($maildata->bcc)?$maildata->bcc.', ':'');
$headers['From'] = $maildata->fromname."<$maildata->from>";
$headers['To'] = $maildata->to;
$headers['Cc'] = $maildata->cc;
$headers['Subject'] = $maildata->subject;
$headers['Content-Type'] = "text/html; charset=\"UTF-8\"";
$headers['Content-Transfer-Encoding'] = '8bit';
$body = $maildata->message;
// Define SMTP Parameters
$params = (array) $smtp;
// Create the mail object using the Mail::factory method
$mail_object = & Mail::factory('smtp', $params);
// Send the message
$result = $mail_object->send($recipients, $headers, $body);
return $result;
}
//============================================================================
public function String2Stars($string='',$first=0,$last=0,$rep='*'){
$begin = substr($string,0,$first);
$middle = str_repeat($rep,strlen(substr($string,$first,$last)));
$end = substr($string,$last);
$stars = $begin.$middle.$end;
return $stars;
}
/////////////////////////////////////////////////////////////////////////////////////////
//END GENERAL FUNCTIONS//////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
//ADMIN RELATED FUNCTIONS////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
public function getAdminUsers($id=NULL,$username=NULL,$password=NULL,$email=NULL,$mobile=NULL,$type=NULL,$isactive=NULL){
$condition = "";
if(!empty($id)){
$condition.=empty($condition)?" id='$id' ":" AND id='$id' ";
}
if(!empty($username)){
$condition.=empty($condition)?" username='$username' ":" AND username='$username' ";
}
if(!empty($password)){
$condition.=empty($condition)?" password=MD5('$password') ":" AND password=MD5('$password') ";
}
if(!empty($email)){
$condition.=empty($condition)?" email='$email' ":" AND email='$email' ";
}
if(!empty($mobile)){
$condition.=empty($condition)?" mobile='$mobile' ":" AND mobile='$mobile' ";
}
if(!empty($type)){
$condition.=empty($condition)?" type='$type' ":" AND type='$type' ";
}
if(!empty($isactive)){
$condition.=empty($condition)?" isactive='$isactive' ":" AND isactive='$isactive' ";
}
$condition = trim(str_replace(' ', ' ', $condition));
$sql = (!empty($condition))?
"SELECT * FROM `admin_users` WHERE $condition ":
"SELECT * FROM `admin_users`";
//echo $sql;
$pdodb = PDODB::getInstance(); //print_r($pdodb); exit();
$result = Array();
if(!empty($pdodb)){
$result = $pdodb->query($sql);
PDODB::closeInstance();
}else{
echo 'Not Connected<br/>';
}
return ($result);
}
public function getCourse($id=NULL,$isactive=NULL,$orderBy='ASC'){
$condition = "";
if (!empty($orderBy) && in_array($orderBy, ['ASC','DESC'])) {
$orderBy ="ORDER BY id $orderBy";
}else{
$orderBy='';
}
if(!empty($id)){
$condition.=empty($condition)?" id='$id' ":" AND id='$id' ";
}
if(!empty($isactive)){
$condition.=empty($condition)?" isactive='$isactive' ":" AND isactive='$isactive' ";
}
$condition = trim(str_replace(' ', ' ', $condition));
$sql = (!empty($condition))?
"SELECT * FROM `tb_course` WHERE $condition $orderBy":
"SELECT * FROM `tb_course` $orderBy";
//echo $sql; exit();
$pdodb = PDODB::getInstance();
if(!empty($pdodb)){
$result = $pdodb->query($sql);
PDODB::closeInstance();
}else{
echo 'Not Connected<br/>';
}
return ($result);
}
public function getTeam($id=NULL,$isactive=NULL,$orderBy='ASC'){
$condition = "";
if (!empty($orderBy) && in_array($orderBy, ['ASC','DESC'])) {
$orderBy ="ORDER BY id $orderBy";
}else{
$orderBy='';
}
if(!empty($id)){
$condition.=empty($condition)?" id='$id' ":" AND id='$id' ";
}
if(!empty($isactive)){
$condition.=empty($condition)?" isactive='$isactive' ":" AND isactive='$isactive' ";
}
$condition = trim(str_replace(' ', ' ', $condition));
$sql = (!empty($condition))?
"SELECT * FROM `tb_team` WHERE $condition $orderBy":
"SELECT * FROM `tb_team` $orderBy";
//echo $sql; exit();
$pdodb = PDODB::getInstance();
if(!empty($pdodb)){
$result = $pdodb->query($sql);
PDODB::closeInstance();
}else{
echo 'Not Connected<br/>';
}
return ($result);
}
public function getBlog($id=NULL,$isactive=NULL,$orderBy='ASC'){
$condition = "";
if (!empty($orderBy) && in_array($orderBy, ['ASC','DESC'])) {
$orderBy ="ORDER BY id $orderBy";
}else{
$orderBy='';
}
if(!empty($id)){
$condition.=empty($condition)?" id='$id' ":" AND id='$id' ";
}
if(!empty($isactive)){
$condition.=empty($condition)?" isactive='$isactive' ":" AND isactive='$isactive' ";
}
$condition = trim(str_replace(' ', ' ', $condition));
$sql = (!empty($condition))?
"SELECT * FROM `tb_blog` WHERE $condition $orderBy":
"SELECT * FROM `tb_blog` $orderBy";
//echo $sql; exit();
$pdodb = PDODB::getInstance();
if(!empty($pdodb)){
$result = $pdodb->query($sql);
//print_r($result);
PDODB::closeInstance();
}else{
echo 'Not Connected<br/>';
}
return ($result);
}
public function getBlog2($id=NULL,$isactive=NULL,$start_from=NULL,$limit=NULL){
$condition = "";
if(!empty($id)){
$condition.=empty($condition)?" id='$id' ":" AND id='$id' ";
}
if(!empty($isactive)){
$condition.=empty($condition)?" isactive='$isactive' ":" AND isactive='$isactive' ";
}
$condition = trim(str_replace(' ', ' ', $condition));
$retVal = (!empty($cat_id)) ? 'LIMIT 0,10' : '' ;
$sql = (!empty($condition))?
"SELECT * FROM `tb_blog` WHERE $condition $retVal":
"SELECT * FROM `tb_blog` $retVal";
//echo $sql; exit();
$pdodb = PDODB::getInstance();
if(!empty($pdodb)){
$result = $pdodb->query($sql);
//print_r($result);
PDODB::closeInstance();
}else{
echo 'Not Connected<br/>';
}
return ($result);
}
public function getCat($cat_id=NULL,$isactive=NULL){
$condition = "";
if(!empty($cat_id)){
$condition.=empty($condition)?" cat_id='$cat_id' ":" AND cat_id='$cat_id' ";
}
if(!empty($isactive)){
$condition.=empty($condition)?" isactive='$isactive' ":" AND isactive='$isactive' ";
}
$condition = trim(str_replace(' ', ' ', $condition));
$sql = (!empty($condition))?
"SELECT * FROM `category` WHERE $condition ":
"SELECT * FROM `category`";
//echo $sql; exit();
$pdodb = PDODB::getInstance();
if(!empty($pdodb)){
$result = $pdodb->query($sql);
//print_r($result);
PDODB::closeInstance();
}else{
echo 'Not Connected<br/>';
}
return ($result);
}
public function toJsAlert($location = null, $message = '')
{
echo "<script LANGUAGE='JavaScript'>
window.alert('$message');
window.location.href='$location';
</script>";
//echo "<script>alwindow.location.href='$location';</script>";
exit();
}
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
}
?>


PK 99