<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of admission
*
* @author Suharshana DsW
*/
class Admission {
public $id;
public $full_name;
public $birthday;
public $gender;
public $nationality;
public $email;
public $contact;
public $address;
public $photograph;
public $birth_certificate;
public $leaving_certificate;
public $school_report;
public function __construct($id) {
if ($id) {
$db = new Database();
$id = mysql_real_escape_string($id);
$query = "SELECT `id`,`full_name`,`birthday`,`gender`,`nationality`,`email`,`contact`.`address`,`photograph`,`birth_certificate`,`leaving_certificate`,`school_report` FROM `admission` WHERE `id`=" . $id;
$result = mysql_fetch_array($db->readQuery($query));
$this->id = $result['id'];
$this->full_name = $result['full_name'];
$this->birthday = $result['birthday'];
$this->gender = $result['gender'];
$this->nationality = $result['nationality'];
$this->email = $result['email'];
$this->contact = $result['contact'];
$this->address = $result['address'];
$this->photograph = $result['photograph'];
$this->birth_certificate = $result['birth_certificate'];
$this->leaving_certificate = $result['leaving_certificate'];
$this->school_report = $result['school_report'];
return $this;
}
}
public function create() {
$db = new Database();
$full_name = mysql_real_escape_string($this->full_name);
$birthday = mysql_real_escape_string($this->birthday);
$gender = mysql_real_escape_string($this->gender);
$nationality = mysql_real_escape_string($this->nationality);
$email = mysql_real_escape_string($this->email);
$contact = mysql_real_escape_string($this->contact);
$address = mysql_real_escape_string($this->address);
$photograph = mysql_real_escape_string($this->photograph);
$birth_certificate = mysql_real_escape_string($this->birth_certificate);
$leaving_certificate = mysql_real_escape_string($this->leaving_certificate);
$school_report = mysql_real_escape_string($this->school_report);
$query = "INSERT INTO `admission` (`full_name`,`birthday`,`gender`,`nationality`,`email`,`contact`,`address`,`photograph`,`birth_certificate`,`leaving_certificate`,`school_report`) VALUES ('"
. $full_name . "','"
. $birthday . "', '"
. $gender. "', '"
. $nationality . "', '"
. $email . "', '"
. $contact . "', '"
. $address . "', '"
. $photograph . "', '"
. $birth_certificate . "', '"
. $leaving_certificate . "', '"
. $school_report. "')";
$result = $db->readQuery($query);
if ($result) {
$last_id = mysql_insert_id();
return $this->__construct($last_id);
} else {
return FALSE;
}
}
public function all() {
$query = "SELECT * FROM `admission` ORDER BY id ASC";
$db = new Database();
$result = $db->readQuery($query);
$array_res = array();
while ($row = mysql_fetch_array($result)) {
array_push($array_res, $row);
}
return $array_res;
}
public function update() {
$db = new Database();
$full_name = mysql_real_escape_string($this->full_name);
$birthday = mysql_real_escape_string($this->birthday);
$gender = mysql_real_escape_string($this->gender);
$nationality = mysql_real_escape_string($this->nationality);
$email = mysql_real_escape_string($this->email);
$contact = mysql_real_escape_string($this->contact);
$address = mysql_real_escape_string($this->address);
$photograph = mysql_real_escape_string($this->photograph);
$birth_certificate = mysql_real_escape_string($this->birth_certificate);
$leaving_certificate = mysql_real_escape_string($this->leaving_certificate);
$school_report = mysql_real_escape_string($this->school_report);
$query = "UPDATE `admission` SET "
. "`full_name` ='" . $full_name . "', "
. "`birthday` ='" . $birthday . "', "
. "`gender` ='" .$gender . "', "
. "`nationality` ='" . $nationality . "', "
. "`email` ='" . $email . "', "
. "`contact` ='" . $contact . "', "
. "`address` ='" . $address . "', "
. "`photograph` ='" . $photograph . "', "
. "`birth_certificate` ='" . $birth_certificate . "', "
. "`leaving_certificate` ='" . $leaving_certificate . "', "
. "`school_report` ='" .$school_report . "' "
. "WHERE `id` = '" . $this->id . "'";
$result = $db->readQuery($query);
if ($result) {
return $this->__construct($this->id);
} else {
return FALSE;
}
}
public function delete() {
$this->deletePhotos();
unlink(Helper::getSitePath() . "upload/activity/" . $this->image_name);
$query = 'DELETE FROM `admission` WHERE id="' . $this->id . '"';
$db = new Database();
return $db->readQuery($query);
}
public function deletePhotos() {
$ACTIVITY_PHOTO = new ActivitiesPhoto(NULL);
$allPhotos = $ACTIVITY_PHOTO->getActivitiesPhotosById($this->id);
foreach ($allPhotos as $photo) {
$IMG = $ACTIVITY_PHOTO->image_name = $photo["image_name"];
unlink(Helper::getSitePath() . "upload/activity/gallery/" . $IMG);
unlink(Helper::getSitePath() . "upload/activity/gallery/thumb/" . $IMG);
$ACTIVITY_PHOTO->id = $photo["id"];
$ACTIVITY_PHOTO->delete();
}
}
}
|