JezK
Edit File: admin_functions.php
<?php if(!isset($dbpath)) { $dbpath=''; } include($dbpath.'config/db.php'); Class admin { /* Getting Database configurations from ../config/db.php */ private $dbHost=DB_HOST; private $dbUser=DB_USER; private $dbPassword=DB_PASSWORD; private $dbName=DB_DATABASE; private $db=''; private $adminTable='admin'; private $currentTimeStamp; public function __construct(){ $this->connectToDb(); session_start(); $this->currentTimeStamp=date('Y-m-d H:s:i'); $this->currentDate=date('Y-m-d'); } private function connectToDb(){ try { $this->db = new PDO("mysql:host=".$this->dbHost.";dbname=".$this->dbName."", $this->dbUser, $this->dbPassword); } catch(PDOException $e) { echo $e->getMessage(); } } public function dbconnection() { $this->con=mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE) or die("could not connect database"); return $this->con; } public function login($uname,$pwd) { $returnValue=false; $this->uname=$uname; $this->pwd=$pwd; //echo "login started"; if($this->isUser($uname,$pwd)) { $returnValue=true; $_SESSION['username']=$this->adminData['admin_name']; $_SESSION['usertype']='admin'; $_SESSION['adminid']=$this->adminData['admin_id']; } return $returnValue; } public function logout() { session_destroy(); return true; } private function isUser($uname,$pwd){ $returnValue=false; $query="SELECT * FROM ".$this->adminTable." WHERE email=:username AND password=:pwd"; //echo $query; $stmt=$this->db->prepare($query); $stmt->bindParam(':username', $uname, PDO::PARAM_STR); $stmt->bindParam(':pwd', $pwd, PDO::PARAM_STR); $stmt->execute(); if($stmt->rowCount() == 1) { $this->adminData= $stmt->fetch(PDO::FETCH_ASSOC); $returnValue=true; } return $returnValue; } private function isAdmin($email) { $returnValue=false; $query="SELECT * FROM ".$this->adminTable." WHERE email=:email"; //echo $query; $stmt=$this->db->prepare($query); $stmt->bindParam(':email', $email, PDO::PARAM_STR); $stmt->execute(); if($stmt->rowCount() == 1) { $returnValue=true; } return $returnValue; } public function addgalleryimages($galleryimagefiles) { $returnValue=false; $multipleImageFiles=$this->reArrayFiles($galleryimagefiles); foreach($multipleImageFiles as $singleFile) { $returnValue=true; $imagepath=''; $query="INSERT gallery SET imagepath=:imagepath,created_date='".$this->currentDate."'"; $stmt=$this->db->prepare($query); $stmt->bindParam(':imagepath', $imagepath, PDO::PARAM_STR); $stmt->execute(); $galleryimageid=$this->db->lastInsertId(); $fileName=$singleFile['name']; if(move_uploaded_file($singleFile['tmp_name'],'./uploads/'.$galleryimageid.'_'.$fileName)) { $imagepath=$galleryimageid.'_'.$fileName; $query="UPDATE gallery SET imagepath=:imagepath WHERE gallery_id=:galleryimageid"; $stmt=$this->db->prepare($query); $stmt->bindParam(':imagepath', $imagepath, PDO::PARAM_STR); $stmt->bindParam(':galleryimageid', $galleryimageid, PDO::PARAM_INT); $stmt->execute(); } } return $returnValue; } public function getGalleryList() { $returnValue=false; $query="SELECT * FROM gallery"; $stmt=$this->db->prepare($query); $stmt->execute(); if($stmt->rowCount() != 0) { $returnValue=$stmt->fetchAll(PDO::FETCH_ASSOC); } return $returnValue; } private function RandomString($length) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $randstring = ''; for ($i = 0; $i < $length; $i++) { $randstring .= $characters[rand(0, strlen($characters)-1)]; } return $randstring; } private function reArrayFiles(&$file_post) { $file_ary = array(); $file_count = count($file_post['name']); $file_keys = array_keys($file_post); for ($i=0; $i<$file_count; $i++) { foreach ($file_keys as $key) { $file_ary[$i][$key] = $file_post[$key][$i]; } } return $file_ary; } /* Revathi start*/ public function inset_mandal($mandalname,$villagename) { $sql_val="SELECT `mandal_id` FROM `mandals` WHERE `mandal_name`='".$mandalname."'"; $res_val=mysqli_query($this->con,$sql_val); if(mysqli_num_rows($res_val)>0) { $error=1; }else { $error=2; $query="INSERT INTO mandals(mandal_name) values('".$mandalname."')"; $result=mysqli_query($this->con,$query); $mandalid=mysqli_insert_id($this->con); foreach($villagename as $village_data) { $que="INSERT INTO villages(mandal_id,village_name) values('".$mandalid."','".$village_data."')"; $res=mysqli_query($this->con,$que); } } return $error; } public function admin_login($email,$password) { $query="select admin_email,password from admin where admin_email='".$email."' and password='".$password."'"; $res=mysqli_query($this->con,$query); if(mysqli_num_rows($res)>0) { $error=1; }else { $error=2; } return $error; } public function user_tables() { $command="SELECT name,mobile,bloodgroup FROM users"; $results=mysqli_query($this->con,$command); return $results; } /* Revathi end*/ /*ramya start */ public function insert_bloodgroup($newgrp) { $sql_val="SELECT `id` FROM `bloodgroups` WHERE `bloodgroup`='".$newgrp."'"; $res_val=mysqli_query($this->con,$sql_val); if(mysqli_num_rows($res_val)>0) { $error=1; }else { $error=2; $query="INSERT INTO bloodgroups(bloodgroup) values('".$newgrp."')"; $result=mysqli_query($this->con,$query); } return $error; } public function display_bloodgroup() { $sql = "SELECT `bloodgroup` FROM `bloodgroups`" ; $result = mysqli_query($this->con, $sql); if(mysqli_num_rows($result) > 0) { $val=1; } } } /*ramya end*/ ?>