diff --git a/Apollo/api/application/controllers/University_Controller.php b/Apollo/api/application/controllers/University_Controller.php index 818ce1c7..11e8e3a6 100755 --- a/Apollo/api/application/controllers/University_Controller.php +++ b/Apollo/api/application/controllers/University_Controller.php @@ -64,22 +64,44 @@ class University_Controller extends REST_Controller { //update university details public function updateUniversityDetail_post() { + + //s print_r($_FILES); + $imagename=''; + $size=''; + $imageSource=''; + + if(!empty($_FILES)) + { + $imagename = $_FILES['idProof']['name']; + $size = $_FILES['idProof']['size']; + $imageSource = $_FILES['idProof']['tmp_name']; + } + + + // echo $imagename; + // echo $size; + // echo $imageSource; + // die(); + + $reqData = $this->post('data'); + $data = json_decode($reqData, true); $req['UpdatedBy'] = $this->post('updatedBy'); $date = date('Y-m-d H:i:s'); $req['UpdatedOn'] = $date; - $req['UniversityName']= $reqData['UniversityName']; - $req['UniversityShortName']= $reqData['UniversityShortName']; - $req['MobileNumber']= $reqData['MobileNumber']; - $req['EmailID']= $reqData['EmailID']; - $req['Address']= $reqData['Address']; - $req['IsActive']= $reqData['IsActive']; + $req['UniversityName']= $data['UniversityName']; + $req['UniversityShortName']= $data['UniversityShortName']; + $req['MobileNumber']= $data['MobileNumber']; + $req['EmailID']= $data['EmailID']; + $req['Address']= $data['Address']; + $req['IsActive']= $data['IsActive']; $req['BranchCode'] = $this->post('branchCode'); - $req['ID']= $reqData['ID']; + $req['ID']= $data['ID']; - $updateFor = $reqData['UniversityID']; + $updateFor = $data['UniversityID']; - $updateUniversityDetail = $this->university_model->update_university_details($updateFor, $req);// Check if the employee exist + + $updateUniversityDetail = $this->university_model->update_university_details($updateFor, $req,$imagename,$imageSource,$size);// Check if the employee exist if ($updateUniversityDetail) { $updateUniversityDetail['status'] = REST_Controller::HTTP_OK; @@ -124,20 +146,37 @@ class University_Controller extends REST_Controller { // insert university details public function insertUniversity_post() { + + // echo "sdg"; + + $imagename = $_FILES['idProof']['name']; + $size = $_FILES['idProof']['size']; + $imageSource = $_FILES['idProof']['tmp_name']; + // echo $imagename; + // echo $size; + // echo $imageSource; + + $reqData = $this->post('data'); + $temp = json_decode($reqData, true); + + //print_r($reqData); + //die(); $req['CreatedBy'] = $this->post('createdBy'); $date = date('Y-m-d H:i:s'); $req['CreatedOn'] = $date; - $req['UniversityName']= $reqData['UniversityName']; - $req['UniversityShortName']= $reqData['UniversityShortName']; - $req['MobileNumber']= $reqData['MobileNumber']; - $req['EmailID']= $reqData['EmailID']; - $req['Address']= $reqData['Address']; - $req['IsActive']= $reqData['switchsetting']; - $req['UniversityID']= $reqData['UniversityID']; + $req['UniversityName']= $temp['UniversityName']; + $req['UniversityShortName']= $temp['UniversityShortName']; + $req['MobileNumber']= $temp['MobileNumber']; + $req['EmailID']= $temp['EmailID']; + $req['Address']= $temp['Address']; + $req['IsActive']= $temp['switchsetting']; + $req['UniversityID']= $temp['UniversityID']; $req['BranchCode']= $this->post('branchCode'); - $insertUniv = $this->university_model->insert_Univ($req);// Check if the employee exist + + + $insertUniv = $this->university_model->insert_Univ($req,$imagename,$imageSource,$size);// Check if the employee exist if ($insertUniv) { $insertUniv['status'] = REST_Controller::HTTP_OK; diff --git a/Apollo/api/application/models/University_model.php b/Apollo/api/application/models/University_model.php index 69966e78..470eeb59 100755 --- a/Apollo/api/application/models/University_model.php +++ b/Apollo/api/application/models/University_model.php @@ -34,10 +34,35 @@ class University_model extends CI_Model $results['message'] = 'No record found'; } return $results; + + print_r($results); } // update univesity details - public function update_university_details($updateFor, $Arr) { + public function update_university_details($updateFor, $Arr,$imageName, $imageSource, $imageSize) { + + if($imageSource == '') + { + //echo "if"; + $imageNameDb = 'default.jpeg'; + // $Arr['ProfilePicPath'] = "university/".$imageNameDb; + } + + else + { + //echo "else"; + $target = "../images/university/"; + $getUploadStatus = $this->upload_image($imageSource, $imageSize, $target); + $imageNameDb = $getUploadStatus['status'] == true ? $getUploadStatus['imageName'] : $getUploadStatus['imageName'] = 'default.jpeg'; + // echo $imageNameDb; + $Arr['ProfilePicPath'] = "university/".$imageNameDb; + } + + + // print_r($Arr); + // die(); + + $this->db->where('UniversityID', $updateFor); $this->db->where('BranchCode', $Arr['BranchCode']); $this->db->where('ID', $Arr['ID']); @@ -47,7 +72,7 @@ class University_model extends CI_Model $result['message'] = "Successfully University details Updated"; } else { $result['updateUniversityStatus'] = false; - $result['message'] = "Successfully University details Updated"; + $result['message'] = "University details not Updated"; } return $result; } @@ -69,7 +94,35 @@ class University_model extends CI_Model } // add university details - public function insert_Univ($arr) { + public function insert_Univ($arr,$imageName, $imageSource, $imageSize) { + + // echo $imageName; + // echo $imageSource; + // echo $imageSize; + + if($imageSource == '') + { + //echo "if"; + $imageNameDb = 'default.jpeg'; + $arr['ProfilePicPath'] = "university/".$imageNameDb; + } + + else + { + //echo "else"; + $target = "../images/university/"; + $getUploadStatus = $this->upload_image($imageSource, $imageSize, $target); + $imageNameDb = $getUploadStatus['status'] == true ? $getUploadStatus['imageName'] : $getUploadStatus['imageName'] = 'default.jpeg'; + // echo $imageNameDb; + $arr['ProfilePicPath'] = "university/".$imageNameDb; + } + + + // // echo $imageName; + // // echo $imageSource; + // // echo $imageSize; + // echo $imageSource; + //die(); $this->db->select('*'); $this->db->from(UNIVERSITY); $this->db->where('UniversityID', $arr['UniversityID']); @@ -81,7 +134,7 @@ class University_model extends CI_Model $this->db->insert(UNIVERSITY, $arr); if ($this->db->affected_rows() == '1') { $result['addUniv'] = true; - $result['message'] = "Successfully University details added"; + $result['message'] = "Successfully University details added"; } else { $result['addUniv'] = false; $result['message'] = "Something went wrong.please try again"; @@ -382,4 +435,30 @@ class University_model extends CI_Model return $result; } + + // image upload in taget path + public function upload_image( $imageSource, $size, $target ) { + + //echo "fn"; + $key2 = substr(str_shuffle('abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 12); + $new_regNo = "Dri_" . $key2 . "." . 'jpeg'; + $targetPlace = $target . $new_regNo; + // echo $imageSource; + // exit(); + if(!move_uploaded_file($imageSource , $targetPlace)) + {//echo "if"; + return $result['status'] = false; + + $result['imageName'] = $new_regNo; + } + else + { + // echo "else"; + $result['status'] = true; + $result['imageName'] = $new_regNo; + + return $result; + } + } + } \ No newline at end of file diff --git a/Apollo/assets/js/controllers/universityCtrl.js b/Apollo/assets/js/controllers/universityCtrl.js index 41b43480..d9627339 100755 --- a/Apollo/assets/js/controllers/universityCtrl.js +++ b/Apollo/assets/js/controllers/universityCtrl.js @@ -12,6 +12,7 @@ app.controller('universityCtrl', ["$scope", "toaster", "$filter", "ngTableParams // get local cliend details var localDetail = JSON.parse(localStorage.getItem('localObj')); var localDetails = ipCookie('cookiechk'); + //alert(JSON.stringify(localDetail)); $scope.myModel = { 'UniversityID': '', @@ -21,6 +22,9 @@ app.controller('universityCtrl', ["$scope", "toaster", "$filter", "ngTableParams 'EmailID': '', 'Address': '', 'switchsetting': true, + + + }; @@ -63,7 +67,7 @@ app.controller('universityCtrl', ["$scope", "toaster", "$filter", "ngTableParams if (response.data.univList) { $scope.loader = false; $scope.emptyUniversity = true; - $scope.data = response.data.university_details; + $scope.univ = response.data.university_details; } else { $scope.loader = false; $scope.emptyUniversity = false; @@ -95,6 +99,56 @@ app.controller('universityCtrl', ["$scope", "toaster", "$filter", "ngTableParams }); } + + + + //--------------------------------------------------------------> + // getting for image to show + //--------------------------------------------------------------> + + $scope.stepsModel = []; + $scope.imageUpload = function (event) { + var files = event.target.files; //FileList object + + for (var i = 0; i < files.length; i++) { + var file = files[i]; + var reader = new FileReader(); + reader.onload = $scope.imageIsLoaded; + reader.readAsDataURL(file); + } + } + + $scope.imageIsLoaded = function (e) { + $scope.$apply(function () { + // $scope.stepsModel.push(e.target.result); + $scope.stepsModel[0] = e.target.result; + }); + } + + + //an array of files selected + $scope.filesimage = []; + + //listen for the file selected event + $scope.$on("fileSelected", function (event, args) { + $scope.$apply(function () { + //add the file object to the scope's files collection + $scope.filesimage[0] = args.file; + + // console.log($scope.filesimage); + }); + }); + + + // reset image + $scope.resetImage = function () { + $scope.filesimage.length = 0; + $scope.stepsModel.length = 0; + } + + + //------------------image functions over ----------> + $scope.setEditId = function (id) { // alert(id); $scope.editId = id; @@ -106,6 +160,7 @@ app.controller('universityCtrl', ["$scope", "toaster", "$filter", "ngTableParams } $scope.updateUniversityDetails = function (form, p) { + //alert() var firstError = null; if (form.$invalid) { var field = null, firstError = null; @@ -123,6 +178,14 @@ app.controller('universityCtrl', ["$scope", "toaster", "$filter", "ngTableParams // swal("The form cannot be submitted because it contains validation errors!", "Errors are marked with a red, dashed border!", "error"); } else { p.IsActive = p.IsActive === true ? 1 : 0; + var idProof = $scope.filesimage[0]; + + + if(idProof === undefined) + { + + //alert('if') + // alert(JSON.stringify(p)) var req = { method: 'POST', url: apiPoint.url + 'updateUniversityDetail/', @@ -130,7 +193,7 @@ app.controller('universityCtrl', ["$scope", "toaster", "$filter", "ngTableParams 'Content-Type': 'application/json' }, data: { - data: p, + data: JSON.stringify(p), updatedBy: localDetails.localUserID, branchCode: localDetails.localBranchID } @@ -145,6 +208,36 @@ app.controller('universityCtrl', ["$scope", "toaster", "$filter", "ngTableParams swal(" ", "Something went wrong, please try again.", "error"); } }); + } + + + else + { + +//alert('else') + var formData = new FormData(); + var idProof = $scope.filesimage[0]; + //alert(idProof) + + formData.append("data", JSON.stringify(p)); + formData.append("updatedBy", localDetails.localUserID); + formData.append("branchCode", localDetails.localBranchID); + formData.append('idProof', idProof); + + $http.post(apiPoint.url + 'updateUniversityDetail/', formData, { + transformRequest: angular.identity, + headers: { 'Content-Type': undefined, 'Process-Data': false }, + }).success(function (data) { + + if (data.updateUniversityStatus == true) { + swal("Success!", data.message, "success"); + $state.go($state.current, {}, { reload: true }); + } else { + // $scope.ldloading1[loading.replace('-', '_')] = false; + swal("Failed!", data.message, "error"); + } + }); + } } } @@ -168,32 +261,62 @@ app.controller('universityCtrl', ["$scope", "toaster", "$filter", "ngTableParams // swal("The form cannot be submitted because it contains validation errors!", "Errors are marked with a red, dashed border!", "error"); } else { $scope.myModel.switchsetting = $scope.myModel.switchsetting === true ? 1 : 0; - var req = { - method: 'POST', - url: apiPoint.url + 'insertUniversity/', - headers: { - 'Content-Type': 'application/json' - }, - data: { - data: $scope.myModel, - branchCode: localDetails.localBranchID, - createdBy: localDetails.localUserID, - } - }; - $http(req).then(function (response) { - if (response.data.addUniv == true) { - swal("", "University details added successfully.", "success"); - $state.go($state.current, {}, { reload: true }); - } - else if(response.data.addUniv == false){ - swal("","This University Id is already exist!", "error"); - } - else { - // $scope.ldloading1[loading.replace('-', '_')] = false; - swal("","Something went wrong, please try again.", "error"); - } - }); + var idProof = $scope.filesimage[0]; + var formData = new FormData(); + //var idProof = $scope.filesimage[0]; + + //alert(idProof); + // var req = { + // method: 'POST', + // url: apiPoint.url + 'insertUniversity/', + // headers: { + // 'Content-Type': 'application/json' + // }, + // data: { + // data: $scope.myModel, + // branchCode: localDetails.localBranchID, + // createdBy: localDetails.localUserID, + // } + // }; + formData.append("data", JSON.stringify($scope.myModel)); + formData.append("branchCode", localDetails.localBranchID); + formData.append("createdBy", localDetails.localUserID); + formData.append('idProof', idProof); + + + $http.post(apiPoint.url + 'insertUniversity/', formData, { + transformRequest: angular.identity, + headers: { 'Content-Type': undefined, 'Process-Data': false }, + }).success(function (data) { + if (data.addUniv == true) { + // swal("Success!", data.message, "success"); + // $state.go($state.current, {}, { reload: true }); + swal("Success!", data.message, "success"); + $state.go($state.current, {}, { reload: true }); + } else { + // $scope.ldloading1[loading.replace('-', '_')] = false; + swal("Failed!", data.message, "error"); + } + }); + + + + + // $http(req).then(function (response) { + // if (response.data.addUniv == true) { + // swal("", "University details added successfully.", "success"); + // $state.go($state.current, {}, { reload: true }); + // } + // else if(response.data.addUniv == false){ + // swal("","This University Id is already exist!", "error"); + + // } + // else { + // // $scope.ldloading1[loading.replace('-', '_')] = false; + // swal("","Something went wrong, please try again.", "error"); + // } + // }); } }, reset: function (form) { @@ -212,3 +335,22 @@ app.controller('universityCtrl', ["$scope", "toaster", "$filter", "ngTableParams } }]); + + + +// file upload directive +app.directive('fileUpload', function () { + return { + scope: true, //create a new scope + link: function (scope, el, attrs) { + el.bind('change', function (event) { + var files = event.target.files; + //iterate files since 'multiple' may be specified on the element + for (var i = 0; i < files.length; i++) { + //emit event upward + scope.$emit("fileSelected", { file: files[i] }); + } + }); + } + }; +}); diff --git a/Apollo/assets/views/editUniversityDetails.html b/Apollo/assets/views/editUniversityDetails.html index ef32b48c..0405c4d5 100755 --- a/Apollo/assets/views/editUniversityDetails.html +++ b/Apollo/assets/views/editUniversityDetails.html @@ -88,7 +88,94 @@ + + +
+ + +
+ + + + + + +
+
+ +
+
Update Profile Picture
+
+ +
+ +
+
+ + +
+
+ +
+ + + +
+
+ + +
+
+ +
+
+
+
+ + + +
+ + + +
+
+
+ + + + + + +
diff --git a/Apollo/assets/views/university.html b/Apollo/assets/views/university.html index dba0e9b3..21e166f8 100755 --- a/Apollo/assets/views/university.html +++ b/Apollo/assets/views/university.html @@ -61,7 +61,7 @@ - + {{p.UniversityID}} {{p.UniversityShortName}} @@ -178,6 +178,71 @@ Address is required
+ + + + +
+
+
+
+ +
+ + +
+
+
University Logo
+
+ +
+
+ +
+
+ + +
+
+ +
+
+
+
+ + + +
+ + + +
+
+
+
+
+ + + + + + + + + +