diff --git a/model/BiodataModel.php b/model/BiodataModel.php index 364641ce32ff450efb3fb809cab0877fb5c389ca..c63d2155cf9ce68085c87e45f25f754238fd617b 100644 --- a/model/BiodataModel.php +++ b/model/BiodataModel.php @@ -1,100 +1,100 @@ -<?php -namespace JLAS\Book\Model; - -class BiodataModel extends BaseModel { - - function __construct() { - parent::__construct("GenericEntity"); - $this->table = "biodata"; - } - - /** - * Find an account with specific username. - * @param string $id The username of the biodata. - * @return GenericEntity the entity with matching id. - */ - public function findByID($id) { - $result = $this->query("SELECT * FROM $this->table WHERE `username` = :id LIMIT 1", array(":id"=>$id)); - if (count($this->queryResult) > 0) { - return $this->newEntity($this->queryResult[0]); - } - return null; - } - - /** - * Find an entity matching the criteria. - * @return array an array containing all matching entities. - */ - public function find($criteria, $data) { - $result = $this->query("SELECT * FROM $this->table WHERE $criteria", $data); - $retval = array(); - if ($result) { - foreach ($this->queryResult as $row) { - array_push($retval, $this->newEntity($row)); - } - } - return $retval; - } - - /** - * Insert a new entity into the database. - * @param GenericEntity $entity the entity to be created. - * @return boolean if the creation is successful. - */ - public function create($entity) { - if ($this->findByID($entity->username) != null) { - return false; - } - $result = $this->query( - "INSERT INTO $this->table (`username`, `name`, `email`, `address`, `phone`, `pic_id`) VALUES (:username, :name, :email, :address, :phone, :pic_id)", - array( - ":username" => $entity->username, - ":name" => $entity->name, - ":email" => $entity->email, - ":address" => $entity->address, - ":phone" => $entity->phone, - ":pic_id" => $entity->pic_id, - ) - ); - return $result; - } - - /** - * Update an entity in the database. - * @param GenericEntity $entity the entity to be updated. - * @return boolean if the update is successful. - */ - public function update($entity) { - $result = $this->query( - "UPDATE $this->table SET `name`=:name, `email`=:email, `address`=:address, `phone`=:phone, `pic_id`=:pic_id WHERE `username`=:username", - array( - ":username" => $entity->username, - ":name" => $entity->name, - ":email" => $entity->email, - ":address" => $entity->address, - ":phone" => $entity->phone, - ":pic_id" => $entity->pic_id, - ) - ); - return $result; - } - - /** - * Delete an entity from the database. - * @param GenericEntity $entity the entity to be deleted. - * @return boolean if the deletion is successful. - */ - public function delete($entity) { - $result = $this->query( - "DELETE FROM $this->table WHERE `username`=:username", - array( - ":username" => $entity->username, - ) - ); - return $result; - - } - -} - +<?php +namespace JLAS\Book\Model; + +class BiodataModel extends BaseModel { + + function __construct() { + parent::__construct("GenericEntity"); + $this->table = "biodata"; + } + + /** + * Find an account with specific username. + * @param string $id The username of the biodata. + * @return GenericEntity the entity with matching id. + */ + public function findByID($id) { + $result = $this->query("SELECT * FROM $this->table WHERE `username` = :id LIMIT 1", array(":id"=>$id)); + if (count($this->queryResult) > 0) { + return $this->newEntity($this->queryResult[0]); + } + return null; + } + + /** + * Find an entity matching the criteria. + * @return array an array containing all matching entities. + */ + public function find($criteria, $data) { + $result = $this->query("SELECT * FROM $this->table WHERE $criteria", $data); + $retval = array(); + if ($result) { + foreach ($this->queryResult as $row) { + array_push($retval, $this->newEntity($row)); + } + } + return $retval; + } + + /** + * Insert a new entity into the database. + * @param GenericEntity $entity the entity to be created. + * @return boolean if the creation is successful. + */ + public function create($entity) { + if ($this->findByID($entity->username) != null) { + return false; + } + $result = $this->query( + "INSERT INTO $this->table (`username`, `name`, `email`, `address`, `phone`, `pic_id`) VALUES (:username, :name, :email, :address, :phone, :pic_id)", + array( + ":username" => $entity->username, + ":name" => $entity->name, + ":email" => $entity->email, + ":address" => $entity->address, + ":phone" => $entity->phone, + ":pic_id" => $entity->pic_id, + ) + ); + return $result; + } + + /** + * Update an entity in the database. + * @param GenericEntity $entity the entity to be updated. + * @return boolean if the update is successful. + */ + public function update($entity) { + $result = $this->query( + "UPDATE $this->table SET `name`=:name, `email`=:email, `address`=:address, `phone`=:phone, `pic_id`=:pic_id WHERE `username`=:username", + array( + ":username" => $entity->username, + ":name" => $entity->name, + ":email" => $entity->email, + ":address" => $entity->address, + ":phone" => $entity->phone, + ":pic_id" => $entity->pic_id, + ) + ); + return $result; + } + + /** + * Delete an entity from the database. + * @param GenericEntity $entity the entity to be deleted. + * @return boolean if the deletion is successful. + */ + public function delete($entity) { + $result = $this->query( + "DELETE FROM $this->table WHERE `username`=:username", + array( + ":username" => $entity->username, + ) + ); + return $result; + + } + +} + ?> \ No newline at end of file diff --git a/view/edit_biodata.php b/view/edit_biodata.php index 25b1a537b8b2dba21d9912e427d9b5a752f17c41..1611914baf78b594f107f2e54219c9d100e5c437 100644 --- a/view/edit_biodata.php +++ b/view/edit_biodata.php @@ -52,7 +52,7 @@ alt="Profile Picture"> </td> <td> Update profile picture <br> - <input id="field_data" name="image" type="file" accept="image/jpg|image/png" class="inputfile"/><label for="field_data">Browse...</label> + <input id="field_data" name="image" type="file" accept="image/jpeg, image/png, image/gif" class="inputfile"/><label for="field_data">Browse...</label> <!-- <input type="text" id="filename" class="fieldname" name="pic_id" value="<?php echo $data["pic_id"]?>"></div> --> <!-- <form action="ajax/image/set" method="POST" id="prof_pic_form"> <input id="field_data" name="data" type="file" accept="image/jpg|image/png" class="inputfile"/><label for="field_data">Browse...</label>