public static function getAllSports()
 {
     try {
         $conn = connection::getConnectionObject();
         $con = $conn->getConnection();
         $stm = $con->stmt_init();
         $stm->prepare("SELECT sport_id,name FROM Sport");
         //           // $result = mysqli_query($con,$sql);
         //
         //
         $stm->execute();
         $result = $stm->get_result();
         //
         $equipmentArray = array();
         while ($row = $result->fetch_assoc()) {
             $eqOb = new Sport();
             $eqOb->setName($row["name"]);
             $eqOb->setSportId($row["sport_id"]);
             $equipmentArray[] = $eqOb;
         }
         return $equipmentArray;
     } catch (Exception $e) {
         return "error";
     } finally {
         //$conn->close();
         // $stm->close();
     }
 }
 public static function getAllSport()
 {
     $stm = null;
     try {
         $conn = connection::getConnectionObject();
         $con = $conn->getConnection();
         $stm = $con->stmt_init();
         $stm->prepare("select * from sport");
         $stm->execute();
         $result = $stm->get_result();
         $sportArray = array();
         while ($row = $result->fetch_assoc()) {
             $sport = new Sport();
             $sport->setSportId($row["sport_id"]);
             $sport->setName($row["name"]);
             $sportArray[] = $sport;
         }
         return $sportArray;
     } catch (Exception $e) {
         return "error";
     } finally {
         //$conn->close();
         //$stm->close();
     }
 }
 public static function getAllLocations()
 {
     try {
         $conn = connection::getConnectionObject();
         $con = $conn->getConnection();
         $stm = $con->stmt_init();
         $stm->prepare("SELECT resource_id ,locationName FROM location");
         //
         //
         $stm->execute();
         $result = $stm->get_result();
         //
         $locationarray = array();
         $count = 0;
         while ($row = $result->fetch_assoc()) {
             $location = new Location();
             $location->setName($row["locationName"]);
             $location->setResourceid($row["resource_id"]);
             $locationarray[] = $location;
         }
         return $locationarray;
     } catch (Exception $e) {
         return "error";
     } finally {
         //$conn->close();
         $stm->close();
     }
 }
 public static function updateRequestResources($resourcesArray)
 {
     $conn = connection::getConnectionObject();
     $con = $conn->getConnection();
     foreach ($resourcesArray as $value) {
         $sql = $con->prepare("UPDATE requestresource set state=? WHERE resource_id=? and request_id=? and itemBorrowingDate=?");
         $sql->bind_param("isss", $value->getStatus(), $value->getResourceId(), $value->getRequestId(), $value->getItemBorrowingDate());
         if ($sql->execute() == TRUE) {
             echo "New record created successfully in RESOURCE table";
         } else {
             echo "Error in resource adding: <br>";
         }
     }
 }
 public static function getLastStudentID()
 {
     $conn = connection::getConnectionObject();
     $con = $conn->getConnection();
     $stm = $con->stmt_init();
     $stm->prepare("SELECT request_id FROM request ORDER BY request_id DESC limit 1");
     $stm->execute();
     $result = $stm->get_result();
     while ($row = $result->fetch_assoc()) {
         $r = $row["request_id"];
     }
     $s = substr($r, 2) + 1;
     return $s;
 }
 public static function getSportName($id)
 {
     try {
         $conn = connection::getConnectionObject();
         $con = $conn->getConnection();
         $stm = $con->stmt_init();
         $stm->prepare("SELECT name FROM sport WHERE sport_id=" + $id);
         $stm->execute();
         $result = $stm->get_result();
         echo 'ID: ' . $result['name'] . '<br>';
         return $result;
     } catch (Exception $e) {
         return "error";
     } finally {
     }
 }
 public static function getLastResourceID()
 {
     $conn = cont\connection::getConnectionObject();
     $con = $conn->getConnection();
     $sql = "SELECT max(resource_id) FROM resource";
     if ($result = mysqli_query($con, $sql)) {
         $row = mysqli_fetch_row($result);
         if ($row[0] == null) {
             $r = 0;
         } else {
             $r = $row[0];
         }
         mysqli_free_result($result);
     }
     return $r + 1;
 }
 public static function saveToSupplier(Supplier $spp)
 {
     $conn = cont\connection::getConnectionObject();
     $con = $conn->getConnection();
     $sql = $con->prepare("INSERT INTO Supplier VALUES (?,?,?,? )");
     $supplierId = $spp->getSupplierId();
     $name = $spp->getName();
     $contactNo = $spp->getContactNo();
     $Nic = $spp->getNic();
     $sql->bind_param("ssss", $supplierId, $name, $contactNo, $Nic);
     if ($sql->execute() == TRUE) {
         echo "New record created successfully";
         return true;
     } else {
         echo "not working";
         echo "Error: " . $sql . "<br>";
         return false;
     }
 }
 public static function saveToAchievement(Achievement $achievement)
 {
     $conn = cont\connection::getConnectionObject();
     $con = $conn->getConnection();
     $sql = $con->prepare("INSERT INTO achievement VALUES (?,?,?,? )");
     $sport_id = $achievement->getSportId();
     $achievement_id = $achievement->getAchievementId();
     $description = $achievement->getDescription();
     $date = $achievement->getDate();
     echo $sport_id;
     echo $achievement_id;
     echo $description;
     echo $date;
     $sql->bind_param("ssss", $sport_id, $achievement_id, $description, $date);
     $sql->execute();
     if ($sql->errno) {
         echo "FAILURE!!! " . $sql->error;
     } else {
         echo "Updated {$sql->affected_rows} rows";
     }
 }
 public static function getRequestResource(en\Request $request)
 {
     $request_id = $request->getRequestId();
     $conn = cont\connection::getConnectionObject();
     $con = $conn->getConnection();
     $sql = $con->prepare("SELECT * FROM RequestResource WHERE request_id={$request_id}");
     $sql->bind_param('s', $request_id);
     $sql->execute();
     $result = $sql->get_result();
     //
     $requestResources = array();
     $res_num = 0;
     while ($row = $result->fetch_assoc()) {
         $requestResource = new en\RequestResource();
         $requestResource->setResourceId($row[1]);
         $requestResource->setItemBorrowingDate($row[2]);
         $requestResource->setIssueDate($row[3]);
         $requestResource->setReturnDate($row[4]);
         $requestResource->setStatus($row[5]);
         $requestResources[$res_num] = $requestResource;
         $res_num++;
     }
     return $requestResources;
 }
 public static function getLastStudentID()
 {
     $conn = connection::getConnectionObject();
     $con = $conn->getConnection();
     $sql = "SELECT student_id FROM student ORDER BY student_id DESC limit 1";
     if ($result = mysqli_query($con, $sql)) {
         $row = mysqli_fetch_row($result);
         if ($row[0] == null) {
             $r = 0;
         } else {
             $r = $row[0];
         }
         mysqli_free_result($result);
     }
     return $r + 1;
 }