diff --git a/assets/js/edit.js b/assets/js/edit.js index c9e65dd780931f45b09c9449ec8d8d411a381d68..9d7309063d6fc6354ab3e458c36321b95888996e 100644 --- a/assets/js/edit.js +++ b/assets/js/edit.js @@ -1,8 +1,10 @@ window.addEventListener('load', function() { + // --Uploading file-- var input = document.getElementById('field_data'); var infoArea = document.getElementById('filename'); var image = document.getElementById('prof_pic'); - + + // On browse button clicked. input.addEventListener('change', function ( event ) { // the change event gives us the input it occurred in @@ -13,17 +15,17 @@ window.addEventListener('load', function() { // use fileName however fits your app best, i.e. add it into a div infoArea.value = fileName; - + var imagePath = URL.createObjectURL(event.target.files[0]); image.src = imagePath; }); - + + // --Validate and send changed data // Add validator for the fields below. var name = document.getElementById('field_name'); var address = document.getElementById('field_address'); var phone = document.getElementById('field_phone'); - // let pic_id = document.getElementById('field_image_id'); - //let image = document.getElementById('field_data'); + name.onchange = function(e) { if (this.value.match(nameRE)) { name_ok = true; @@ -49,7 +51,6 @@ window.addEventListener('load', function() { var name_ok = name.value !== ""; var address_ok = address.value !== ""; var phone_ok = phone.value !== ""; - // var pic_id_ok = false; // On save button clicked. let button = document.getElementById('save_button'); diff --git a/controller/BiodataController.php b/controller/BiodataController.php index 1768ab07c7e471c2c92bc2fdbacef2ec2dca31b6..4f59995e8d2e038812a93c65ed0b52f7521fe2b6 100644 --- a/controller/BiodataController.php +++ b/controller/BiodataController.php @@ -15,6 +15,7 @@ class BiodataController extends BaseController { if (isset($username)) { $model_biodata = new Model\BiodataModel(); $biodata = $model_biodata->findByID($username); + //There is profile for $username if (isset($biodata)) { $this->setResponse(200, "Success"); return $biodata->asArray(); diff --git a/controller/EditController.php b/controller/EditController.php index c51f3ced98b2562597fcae539f18419f3f0989d4..c73cb3eada6c7934285a33da46031d5b5ecb77d4 100644 --- a/controller/EditController.php +++ b/controller/EditController.php @@ -15,24 +15,20 @@ class EditController extends BaseController { if (isset($username)) { $image_id = null; - //If uploaded an image + //Uploaded an image if ((isset($_FILES['image'])) && (!empty($_FILES['image']['tmp_name']))) { $file = file_get_contents($_FILES['image']["tmp_name"]); $info = pathinfo($_FILES['image']['name']); $ext = $info['extension']; $model_image = new Model\ImageModel(); $image = $model_image->findByID((int) $this->getArg('pic_id')); + //Updating profile picture if (isset($image)) { $image->data = $file; $image->type = $ext; - $model_image->update($image); - // if ($model_image->affectedRow > 0) { - // $this->setResponse(200, "Ganti gambar"); - // } else { - // $this->setResponse(200, "Unchanged."); - // } - // return $image->id; + $model_image->update($image); } + //Set profile picture for user else { $image = new Entity\ImageEntity(array( "id" => 0, @@ -46,51 +42,35 @@ class EditController extends BaseController { $model_account = new Model\AccountModel(); $model_biodata = new Model\BiodataModel(); - // $model_image = new Model\ImageModel(); - $user = $model_account->findByID($username); + + //Updating data if (isset($this->params["data"]["name"])) { - // Data received. - // $image = $model_image->findByID($this->getArg('pic_id')); $biodata = $model_biodata->findByID($username); $biodata->name = $this->getArg('name'); $biodata->address = $this->getArg('address'); $biodata->phone = $this->getArg('phone'); + + //Update profile picture if (isset($image_id)) { $biodata->pic_id = $image_id; } $model_biodata->update($biodata); - - // $model_biodata->update($biodatas); - + $this->setResponse(200, "User $username updated"); return $biodata->asArray(); - // return $params; } else { - //Initial condition $biodata = $model_biodata->findByID($username); $arr_bio = $biodata->asArray(); - // $biodatas = new Entity\GenericEntity(array( - // "username" => $username, - // "name" => $arr_bio['name'], - // "email" => $arr_bio['email'], - // "address" => $arr_bio['address'], - // "phone" => $arr_bio['phone'], - // "pic_id" => $arr_bio["pic_id"], - // // "pic_id" => "100", - // )); - $this->setResponse(200, "Please edit"); + $this->setResponse(200, "User $username data accepted"); return $arr_bio; - // return $_FILES; } - - } else { $this->setResponse(401, "Please log in first"); return $params; } } - + } ?> \ No newline at end of file