BLACKSITE
:
216.73.216.50
:
174.141.238.224 / www.sscmp.com
:
Windows NT WIN-17DAGV8E5LJ 10.0 build 20348 (Windows Server 2016) AMD64
C:
/
Inetpub
/
vhosts
/
sscmp.com
/
httpdocs
/
library
/
Upload File:
files >> C:/Inetpub/vhosts/sscmp.com/httpdocs/library/methods_lib.php
<?php Class Athentication { private $conn; private $crud; public function __construct($db){ $this->conn = $db; $this->crud = new CrudOperation($this->conn); } ///////////////////////////////////////////////////////////////////////////////////////// // verify user password from database /////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// public function verify_password($username = "", $password = "", $user_type = "", $enc_type = "",$salt=""){ if($user_type == "ADMIN"){ $password_fetched = $this->crud->fetch_single_value("administrator", "admin_pass", "(admin_uid = '".$username."' and admin_type = '".$user_type."' and status = '1')", "limit 1", false); if($enc_type != ""){ $password = $enc_type($password.$salt); } if($password_fetched == $password) { return true; } else { return false; } } else if($user_type == "SCHOOL"){ $password_fetched = $this->crud->fetch_single_value("schools", "password", "(userid = '".$username."')", "limit 1", false); if($enc_type != ""){ $password = $enc_type($password.$salt); } if($password_fetched == $password) { return true; } else { return false; } } else { return false; } } ///////////////////////////////////////////////////////////////////////////////////////// // create session for user login //////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// public function tbldatalist($table = ""){ $treatmentlst=$this->crud->fetch_multi_row($table, "*", "", "", "order by id asc", false); return $treatmentlst; } public function start_login_session($table_id = 0, $username = "", $user_type = ""){ $_SESSION["table_id"] = $table_id; $_SESSION["user_name"] = $username; $_SESSION["user_type"] = $user_type; if($user_type=="teacher") { $condition=" teachers.userid ='".$table_id."'"; $teacher = $this->crud->fetch_single_row("teachers", "teachers.*, class_teacher.classname as cname, class_teacher.section as secname, class_teacher.class_id as cid, class_teacher.classsectionid as secid ", "","", " INNER JOIN class_teacher on class_teacher.teacherid = teachers.id WHERE ".$condition." limit 1", false); $arr = array( 'names' => $teacher['teachername'], 'classid' => $teacher['cid'], 'sectionid' => $teacher['secid'], 'userid' => $teacher['id'], 'classname'=>$teacher['cname'], 'sectionname'=>$teacher['secname'], ); // dummy array $_SESSION['user'] = $arr; // session var "step1" now stores array value } } ///////////////////////////////////////////////////////////////////////////////////////// // validate user session //////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// public function validate_session($username = "", $user_type = ""){ $issession = false; $user_name_new = isset($_SESSION["user_name"]) ? $_SESSION["user_name"] : rand(1,1000); $user_type_new = isset($_SESSION["user_type"]) ? $_SESSION["user_type"] : rand(1,1000); if(($username == $user_name_new) && ($user_type == $user_type_new)){ $issession = true; } return $issession; } //////**********************////////////// } ///////// General Methods ///////////////// Class Method { /////////////////////////////////////////////////////////////////////////////////// // method to remove some charactor from string //////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// public function strip_full($input_string = ""){ $input_string = htmlspecialchars($input_string); $input_string = str_replace("'", "", $input_string); $input_string = str_replace(",", "", $input_string); $input_string = str_replace("~", "", $input_string); $input_string = str_replace("`", "", $input_string); $input_string = str_replace('"', "", $input_string); $input_string = str_replace('delete from', "", $input_string); $input_string = str_replace('drop table', "", $input_string); return $input_string; } //////////////////////////////////////////////////////////////////////////////////////// // method to remove some charactor from string ///////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// public function strip_partial($input_string = ""){ $input_string = str_replace("'", "", $input_string); $input_string = str_replace(",", "", $input_string); $input_string = str_replace("~", "", $input_string); $input_string = str_replace("`", "", $input_string); $input_string = str_replace('"', "", $input_string); return $input_string; } ///////////////////////////////////////////////////////////////////////////////// // check varible existance and value not null /////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// public function is_not_null($variable_type = "", $variable_list = ""){ $variables = explode("~", $variable_list); $error = 0; if($variable_type == "POST"){ foreach ($variables as $variable){ if(isset($_POST[$variable])){ if(trim($_POST[$variable]) == "" && $_POST[$variable] == NULL){ $error++; } } else { $error++; } } } else if($variable_type == "GET"){ foreach ($variables as $variable){ if(isset($_GET[$variable])){ if(trim($_GET[$variable]) == "" && $_GET[$variable] == NULL){ $error++; } } else { $error++; } } } else if($variable_type == "FILES"){ foreach ($variables as $variable){ if(!isset($_FILES[$variable])){ $error++; } } } else if($variable_type == "SESSION"){ foreach ($variables as $variable){ if(isset($_SESSION[$variable])){ if(trim($_SESSION[$variable]) == "" && $_SESSION[$variable] == NULL){ $error++; } } else { $error++; } } } else if($variable_type == "REQUEST"){ foreach ($variables as $variable){ if(isset($_REQUEST[$variable])){ if(trim($_REQUEST[$variable]) == "" && $_REQUEST[$variable] == NULL){ $error++; } } else { $error++; } } } else if($variable_type == "COOKIE"){ foreach ($variables as $variable){ if(isset($_COOKIE[$variable])){ if(trim($_COOKIE[$variable]) == "" && $_COOKIE[$variable] == NULL){ $error++; } } else { $error++; } } } else if($variable_type == "SERVER"){ foreach ($variables as $variable){ if(isset($_SERVER[$variable])){ if(trim($_SERVER[$variable]) == "" && $_SERVER[$variable] == NULL){ $error++; } } else { $error++; } } } if($error == 0){return true;}else{return false;} } ///////////////////////////////////////////////////////////////////////////////////////// // upload files ///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////// public function uploadimage($file = "",$filename_custem = "", $folder = "", $allowed_exts = "", $allowed_type = "", $minsize = 0, $maxsize = 0){ $filename = "N"; if ($_FILES[$file]["name"] != "") { $ext = explode(".", $_FILES[$file]["name"]); $extn = strtolower(end($ext)); if($filename_custem != ""){ $filename = $filename_custem.".".$extn; } else { $filename = substr(str_replace(" ", "-", $ext[0]), 0, 10) . "_" . time() .".". $extn; } if (file_exists($folder . $filename)) { unlink($folder . $filename); } $error = 0; if (round(($_FILES[$file]["size"]) / 1024) < $minsize) { $error++; } if (round(($_FILES[$file]["size"]) / 1024) > $maxsize) { $error++; } if(is_array($allowed_type)){ if (!in_array($_FILES[$file]["type"], $allowed_type)) { $error++; } } if(is_array($allowed_exts)){ if (!in_array($extn, $allowed_exts)) { $error++; } } if($error == 0 ){ if(move_uploaded_file($_FILES[$file]["tmp_name"],$folder . $filename)){ $filename = $filename; } else {$filename = "N";} } else{ $filename = "N";//round(($_FILES[$file]["size"])); } } else { $filename = "N"; } return $filename; } //////////////////////////////////////////////////////////////////////////////////////// function createThumbs($image_path, $thumb_path, $thumb_height){ if(file_exists($thumb_path)){unlink($thumb_path);} $img = imagecreatefromjpeg( "{$image_path}" ); $width = imagesx( $img ); $height = imagesy( $img ); // calculate thumbnail size $new_width = floor($width * ($thumb_height / $height)); $new_height = $thumb_height; // create a new temporary image $tmp_img = imagecreatetruecolor($new_width, $new_height); // copy and resize old image into new image imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // save thumbnail into a file imagejpeg( $tmp_img, "{$thumb_path}"); } /////////////////////////////////////////////////////////////////////////////////////// // recieve message from session /////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////////////////// public function recieve_message(){ $msg = isset($_SESSION["message"]) ? $_SESSION["message"] : ""; $_SESSION["message"] = ""; $temp = explode("~", $msg); $msg_arr = array(); $msg_arr[0] = isset($temp[0]) ? $temp[0]: ""; $msg_arr[1] = isset($temp[1]) ? $temp[1]: ""; return $msg_arr; } //////////////////////////////////////////////////////////////////////////////////////// // redirect to url ///////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// public function redirect($url = "", $message = ""){ $_SESSION["message"] = isset($message) ? $message : ""; header("Location: ".$url); } ///////////////////////////////////////////////////////////////////////////////////////// // Get Current Username, User Type and User Role ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// public function get_user_name(){ $user_name = isset($_SESSION["user_name"]) ? $_SESSION["user_name"] : rand(1001,9999); return $user_name; } public function get_user_type(){ $user_type = isset($_SESSION["user_type"]) ? $_SESSION["user_type"] : rand(1001,9999); return $user_type; } ///////////////////////////////////////////////////////////////////////////////////// // pagination /////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// public function pagination($totalpage = 0,$pagenum = 0,$totalitem = 0,$url = ""){ echo '<ul class="pagination" style="margin: 0;">'; $iter_one = 0; for($i = 1; $i <= $totalpage; $i++){ if($iter_one == 0){ echo'<li class="paginate_button previous'; if(($pagenum - 1) <= 0){echo 'disabled';} echo '" id="example2_previous"><a href="'; if(($pagenum - 1) <= 0){echo 'javascript:void();';}else{echo $url.'/'.$totalitem.'/'.($pagenum - 1);} echo '">Previous</a></li>'; $iter_one = 1; } echo '<li class="paginate_button '; if($i == $pagenum){echo 'active';} echo '"><a href="'.$url.'/'.$totalitem.'/'.$i.'">'.$i.'</a></li>'; if($i == $totalpage){ echo '<li class="paginate_button next'; if(($pagenum + 1) > $totalpage){echo 'disabled';} echo '" id="example2_next"><a href="'; if(($pagenum + 1) > $totalpage){echo 'javascript:void();';}else{echo $url.'/'.$totalitem.'/'.($pagenum - 1);} echo '" >Next</a></li>'; } } echo '</ul>'; } ////////////////////////////////////////// } ?>