OverLord Shell

Path : G:/PleskVhosts/jaincensus.com/macciaweb.ultraliant.com/businessforum/
File Upload :
Current File : G:/PleskVhosts/jaincensus.com/macciaweb.ultraliant.com/businessforum/general_function.php

<?php
/*
@Purpose: General Functions
@Author: Rajashree
@CreatedOn: 7 April 2016
@ModifiedOn: 7 April 2016
*/

/*** @START: FUNCTION TO CLOSE DB CONNECTION ***/


function connClose()
{
	global $connection;
   $connection->close();
}
/*** @END: FUNCTION TO CLOSE DB CONNECTION ***/

/*** @START: FUNCTION TO CLEAN STRING ***/
function clean($string)
{
   $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
   $string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
   $string = preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one.

   return $string;
}
/*** @END: FUNCTION TO CLEAN STRING ***/

/*** @START: FUNCTION TO GET DROPDOWN ***/
function getDropDown($id,$tablename, $option, $value, $condn=null, $selected=null,$onChange=null,$valid=null,$class=null)
{
	
	global $connection;
	$condn = (!empty($condn)) ? "WHERE $condn" : null;
	$onChange = (!empty($onChange)) ? $onChange : null;
	$class = (!empty($class)) ? $class : "form-control";

	$valid = ($valid == true) ? $valid = 'data-validation="required" data-validation-error-msg="Invalid selection"' : null;
	
	/*** begin the select ***/
	$dropdown = '<select  class="'.$class.'" name='.$id.' id='.$id.' '.$onChange.' '.$valid.'><option value="">Select</option>'."\n";
	//echo "SELECT $option,$value FROM $tablename $condn ORDER BY $option";exit;
	$str=$connection->query("SELECT $option,$value FROM $tablename $condn ORDER BY $option");
	while($strow=$str->fetch_assoc())
	{
		/*** assign a selected value ***/
		$select = $selected==$strow[$value] ? ' selected' : null;
		/*** add each option to the dropdown ***/
		$dropdown .= '<option value="'.$strow[$value].'" '.$select.'>'.$strow[$option].'</option>'."\n";
	}
	$str->free();
	$dropdown .= '</select>'."\n";
	return $dropdown;
}
/*** @END: FUNCTION TO GET DROPDOWN ***/

/*** @START: FUNCTION TO INSERT DATA INTO TABLE ***/
function dbRowInsert($table_name, $data)
{
	global $connection;
    // retrieve the keys of the array (column titles)
    $fields = array_keys($data);

    // build the query
     $sql = "INSERT INTO ".$table_name."(`".implode('`,`', $fields)."`)VALUES('".implode("','", $data)."')";
	
	$insertsql=$connection->query($sql);
	$insertid = $connection->insert_id;
	
	$insertsql = ($insertsql == 1) ? "success-".$insertid."" : "An unknown error occured. Please try again.";
	
	return $insertsql;
}
function dbRowInsert1($table_name, $data)
{
	global $connection_jc;
    // retrieve the keys of the array (column titles)
    $fields = array_keys($data);

    // build the query
    $sql = "INSERT INTO ".$table_name."(`".implode('`,`', $fields)."`)VALUES('".implode("','", $data)."')";
	
	$insertsql=$connection_jc->query($sql);
	$insertid = $connection_jc->insert_id;
	
	$insertsql = ($insertsql == 1) ? "success-".$insertid."" : "An unknown error occured. Please try again.";
	
	return $insertsql;
}
/*** @END: FUNCTION TO INSERT DATA INTO TABLE ***/

/*** @START: FUNCTION TO UPDATE DATA INTO TABLE ***/
// again where clause is left optional
function dbRowUpdate($table_name, $data, $where_clause=null)
{
	global $connection;
    // check for optional where clause
    $whereSQL = '';
    if(!empty($where_clause))
    {
        // check to see if the 'where' keyword exists
        if(substr(strtoupper(trim($where_clause)), 0, 5) != 'WHERE')
        {
            // not found, add key word
            $whereSQL = " WHERE ".$where_clause;
        }
		else
        {
            $whereSQL = " ".trim($where_clause);
        }
    }
    // start the actual SQL statement
    $sql = "UPDATE ".$table_name." SET ";

    // loop and build the column /
    $sets = array();
    foreach($data as $column => $value)
    {
         $sets[] = "`".$column."` = '".$value."'";
    }
    $sql .= implode(', ', $sets);

    // append the where statement
    $sql .= $whereSQL;
	
    $updatesql = $connection->query($sql);

    // run and return the query result
	
	$updatesql = ($updatesql == 1) ? "success" : "An unknown error occured. Please try again.";

    return $updatesql;
}
function dbRowUpdate1($table_name, $data, $where_clause=null)
{
	global $connection_jc;
    // check for optional where clause
    $whereSQL = '';
    if(!empty($where_clause))
    {
        // check to see if the 'where' keyword exists
        if(substr(strtoupper(trim($where_clause)), 0, 5) != 'WHERE')
        {
            // not found, add key word
            $whereSQL = " WHERE ".$where_clause;
        }
		else
        {
            $whereSQL = " ".trim($where_clause);
        }
    }
    // start the actual SQL statement
    $sql = "UPDATE ".$table_name." SET ";

    // loop and build the column /
    $sets = array();
    foreach($data as $column => $value)
    {
         $sets[] = "`".$column."` = '".$value."'";
    }
    $sql .= implode(', ', $sets);

    // append the where statement
    $sql .= $whereSQL;
	
    $updatesql = $connection_jc->query($sql);

    // run and return the query result
	
	$updatesql = ($updatesql == 1) ? "success" : "An unknown error occured. Please try again.";

    return $updatesql;
}
/*** @END: FUNCTION TO UPDATE DATA INTO TABLE ***/
function getData1($table, $matchid, $id, $field=null, $condn=null)
{
	global $connection_jc;
	
	$field = (!empty($field)) ? $field : '*';
	$condn = (!empty($condn)) ? $condn : null;
	
   	 $sql= "SELECT $field FROM $table WHERE $matchid=$id $condn";
// exit;
	$getdata = $connection_jc->query($sql);
	$info=$getdata->fetch_assoc();

	$getdata->free();
	
	return $info;
}
/*** @START: FUNCTION TO DELETE DATA FROM TABLE ***/
function dbRowDelete($table_name, $primary_key, $value)
{
	global $connection;

	$sql = "DELETE FROM ".$table_name." WHERE ".$primary_key."=".$value;
	
	$deletesql=$connection->query($sql);
	
	$deletesql = ($deletesql == 1) ? "success" : "An unknown error occured. Please try again.";
	
	return $deletesql;
}
/*** @END: FUNCTION TO DELETE DATA FROM TABLE ***/


/*** @START: FUNCTION TO UPLOAD FILE ***/
function uploadFile($file_id, $folder="", $types="")
{
	if(!empty($_FILES[$file_id]['name']))
	{
		$file_title = $_FILES[$file_id]['name'];
		//Get file extension
		
		$ext_arr = split("\.",basename($file_title));
		$ext = strtolower($ext_arr[count($ext_arr)-1]); //Get the last extension
	
		//Not really uniqe - but for all practical reasons, it is
		$uniqer = substr(md5(uniqid(rand(),1)),0,5);
		$file_name = $uniqer . "_" . $file_title;//Get Unique Name
	
		$all_types = explode(",",strtolower($types));
		if($types)
		{
			if(in_array($ext,$all_types));
			else
			{
				$result = "'".$_FILES[$file_id]['name']."' is not a valid file."; //Show error if any.
				return array('',$result);
			}
		}
	
		//Where the file must be uploaded to
		if($folder) $folder .= "/";//Add a '/' at the end of the folder
		$uploadfile = $folder . $file_name;
	
		$result = "";
		//Move the file from the stored location to the new location
		if (!move_uploaded_file($_FILES[$file_id]['tmp_name'], $uploadfile))
		{
			$result = "Cannot upload the file '".$_FILES[$file_id]['name']."'"; //Show error if any.
			if(!file_exists($folder))
			{
				$result .= " : Folder don't exist.";
			}
			elseif(!is_writable($folder))
			{
				$result .= " : Folder not writable.";
			}
			elseif(!is_writable($uploadfile))
			{
				$result .= " : File not writable.";
			}
			$file_name = "";
			
		}
		else
		{
			if(!$_FILES[$file_id]['size'])
			{ //Check if the file is made
				@unlink($uploadfile);//Delete the Empty file
				$file_name = '';
				$result = "Empty file found - please use a valid file."; //Show the error message
			}
			else
			{
				chmod($uploadfile,0777);//Make it universally writable.
			}
		}
	
		return array($file_name,$result);
	}
}
/*** @END: FUNCTION TO UPLOAD FILE ***/


/*** @START: FUNCTION TO FETCH DATA INTO TABLE ***/
function getData($table, $matchid, $id, $field=null, $condn=null)
{
	global $connection;
	
	$field = (!empty($field)) ? $field : '*';
	$condn = (!empty($condn)) ? $condn : null;
	
 	$sql= "SELECT $field FROM $table WHERE $matchid=$id $condn";
// exit;
	$getdata = $connection->query($sql);
	$info=$getdata->fetch_assoc();
	$getdata->free();
	
	return $info;
}

/*** @END: FUNCTION TO FETCH DATA INTO TABLE ***/

/*** @START: FUNCTION TO FETCH DATA (MULTIPLE ROWS) INTO TABLE ***/
function getDataMulti($table, $matchid=null, $id=null, $field=null, $condn=null)
{
	global $connection;
	$info=array();
	
	$match="";
	$matchid = (!empty($matchid)) ? $matchid : null;
	if(!empty($matchid)){
		$match = (!empty($id)) ? $matchid."=".$id." AND " : null;
	}
	else{
		$matchid = NULL;
	}
	$field = (!empty($field)) ? $field : '*';
	$condn = (!empty($condn)) ? $condn : null;
	//echo
	 $sql= "SELECT $field FROM $table WHERE $match $condn"; 
	//exit;

	$getdata = $connection->query($sql);
	while($row=$getdata->fetch_assoc()){
		array_push($info,$row);
	}
	$getdata->free();
	
	return $info;
}
/*** @END: FUNCTION TO FETCH DATA (MULTIPLE ROWS) INTO TABLE ***/

/*** @START: FUNCTION TO GET MENU ***/
function getMenu()
{
	global $connection;

	 $menu = '<ul class="topmenu" style="float: right;">';
     
     
	 $sqlmenu=$connection->query("SELECT * FROM `busdir_mst_menu` WHERE active='y'");
	while($mdata=$sqlmenu->fetch_assoc())
	{
		/*** assign a selected value ***/
		
		$url = ($mdata['hascontent'] == 'y') ? 'about.php?id='.base64_encode($mdata['menu_id']).'' : $mdata['url'];
		
		/*** add each option to the dropdown ***/
		$menu .= '<li><a href="'.$url.'"><span class="'.$mdata['class'].'" aria-hidden="true"></span>'.$mdata['menu_name'].'</a></li>';
	}
	
	if((!empty($_SESSION['company_id'])) && (!empty($_SESSION['company_name']))){
		$menu .= '
			<li class="dropdown">
					<a class="dropdown-toggle" data-toggle="dropdown" href="#"><span class="glyphicon glyphicon-user"></span>'.$_SESSION['company_name'].' <b class="caret"></b></a>
				<ul class="dropdown-menu" style="background-color: brown;">';
				 if($_SESSION['role']=='jb'){
					$menu .= '<li><a href="candidatec.php"><span class="glyphicon glyphicon-dashboard"></span>My Dashboard</a></li>';
				 }else{
					 	$menu .= '<li><a href="multicomp.php"><span class="glyphicon glyphicon-dashboard"></span>My Dashboard</a></li>
					 
					<li><a href="plansadd.php" ><span class="fa fa-inr"></span style="margin-left: 2%;">Plans</a></li> ';} 
					$menu .= '<li><a href="changepass.php"><span class="glyphicon glyphicon-log-out"></span>Change Password </a></li> 
					<li><a href="logout.php"><span class="glyphicon glyphicon-log-out"></span>Logout</a></li>
				</ul>
			</li>';
	}
	else{
		$menu .='
		<a href="login/" class="use1" style="color: #ffffff;font-size: 117%;border-left: solid;
    
    padding-top: 13px;
    padding-bottom: 14px;    border-width: thin;">&nbsp;<span class="glyphicon glyphicon-log-in"></span>  Business</a>
&nbsp;
<a href="login/" style="color: #ffffff;font-size: 117%;    border-right: solid;
    padding-top: 13px;
    padding-bottom: 13px;    border-width: thin;">/ Job Seeker &nbsp;</a>';
		 //'<li><a href="login.php" class="use1"><span class="glyphicon glyphicon-log-in"></span>Login / Register</a></li>';

	}
	$menu .='</ul>';
	
	return $menu;
}
/*** @END: FUNCTION TO GET MENU ***/

function isAuthorized($company_id,$company_name,$loggedin)
{
	// user can access every action
	if ((!empty($company_id)) && (!empty($company_name)) && (!empty($loggedin))){
		return true;
	}
	else{
		header("location:index.php");
	}
}
?>

xRyukZ - Copyright 2k19