diff --git a/.gitignore b/.gitignore index 7a1537ba..0ba7aef1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea -node_modules +node_modules/ +.DS_Store diff --git a/README.md b/README.md old mode 100644 new mode 100755 index ba20ee01..b48916f1 --- a/README.md +++ b/README.md @@ -1,52 +1,56 @@ -# PHP BASIC APPLICATION TO MANAGE AN EMPLOYEES LIST -## Application main points - -1. Login and logout with a json file as user storage -2. Controlled user session set to 10 minutes -3. Show data from a JSON in a JS Grid -4. Pagination of the data configured by the grid -5. Employees CRUD Create Read Delete and Update with a json file as employees storage -6. Employee page with employee detail -7. External web service to get employees images -8. Employee avatar through web service images - -### File structure - -This file structure has a specific purpose. So you have to implement all the required over it. Later when we get to OPP and MySQL we will refactor the project to get it more sophisticated, modern and cleaner. Please take care of it!! - -``` -assets/ -resources/ -src/ +# PHP BASIC APPLICATION TO MANAGE AN EMPLOYEES LIST + + +## Application main points + +1. Login and logout with a json file as user storage +2. Controlled user session set to 10 minutes +3. Show data from a JSON in a JS Grid +4. Pagination of the data configured by the grid +5. Employees CRUD Create Read Delete and Update with a json file as employees storage +6. Employee page with employee detail +7. External web service to get employees images +8. Employee avatar through web service images + + +### File structure +This file structure has a specific purpose. So you have to implement all the required over it. Later when we get to OPP and MySQL we will refactor the project to get it more sophisticated, modern and cleaner. Please take care of it!! + +```` +assets/ +css/ +resources/ +src/ /library -``` - -- Assets contains html, css, js & images -- Css just css files. -- Resources folder contains users.json and employees.json -- Src folder contains PHP files which contain HTML or JS -- Src/library folder contains PHP files that contain just PHP - -**We left to you the project files in their folders to give you a structure which we want you to work with in order to later refactor it.** - -We use some naming conventions when create code files. For instance a file which handles HTTP request we name it as `Controller`. - -In the other hand we have also the concept of `Manager` which typically implements an abstraction layer over a storage system, in this case as we are going to work with json files for a while (bear on mind later we refactor it to MySQL and then we will also have a `Model` file) we would need to create on it all functions we need to access the json file. +```` + +* Assets contains images and plain HTML files. +* Css just css files. +* Resources folder contains users.json and employees.json +* Src folder contains PHP files which contain HTML or JS +* Src/library folder contains PHP files that contain just PHP + +**We left to you the project files in their folders to give you a structure which we want you to work with in order to later refactor it.** + +We use some naming conventions when create code files. For instance a file which handles HTTP request we name it as `Controller`. + +In the other hand we have also the concept of `Manager` which typically implements an abstraction layer over a storage system, in this case as we are going to work with json files for a while (bear on mind later we refactor it to MySQL and then we will also have a `Model` file) we would need to create on it all functions we need to access the json file. A file called `Model` implements a database layer is a file which interacts directly with a Database. **On future projects we will refactor this project to add Models and much more!!** -We also added the concept of `Helper` which is a class which its finality is to help `Controllers` and `Managers` to be lighter and to keep single responsibility. +We also added the concept of `Helper` which is a class which its finality is to help `Controllers` and `Managers` to be lighter and to keep single responsibility. -``` + +``` index.php // which is the entry point of the application. The login view -employeeController.php // file which has JUST the php code to handle employees request +employeeController.php // file which has JUST the php code to handle employees request employeeManager.php // In this file we left you a list of named mehtods to implement and use. -loginController.php // here you need to handle all HTTP request of login things -loginManager.php // same thing here you need to write things as login validation logout etc.. +loginController.php // here you need to handle all HTTP request of login things +loginManager.php // same thing here you need to write things as login validation logout etc.. -sessionHelper.php // here you can add the code to check if the user session has expired. +sessionHelper.php // here you can add the code to check if the user session has expired. ``` The sessionHelper file need to be added to each page we visit in order to check if the user session has expired and if so to call the methods of the loginManager to logout the admin user. @@ -56,208 +60,206 @@ The sessionHelper file need to be added to each page we visit in order to check As you have seen in JS there are sentences to import code from other files to the current file we are working. In PHP happens the same thing. And as we want to encapsulate code by concepts( the login page request are managed by a loginController and so on) it is required to import files. So for instance a dashboard.php page can look like this at the beginning of the file: - ``` - - -
+ +
+ + + + + + + diff --git a/assets/header.html b/assets/header.html new file mode 100755 index 00000000..be3fa5bf --- /dev/null +++ b/assets/header.html @@ -0,0 +1,5 @@ +
+
+

Employees Manager

+

+
diff --git a/assets/html/footer.html b/assets/html/footer.html deleted file mode 100644 index e69de29b..00000000 diff --git a/assets/html/header.html b/assets/html/header.html deleted file mode 100644 index e69de29b..00000000 diff --git a/assets/js/index.js b/assets/js/index.js deleted file mode 100644 index e69de29b..00000000 diff --git a/css/base.css b/css/base.css new file mode 100755 index 00000000..3c4fd66d --- /dev/null +++ b/css/base.css @@ -0,0 +1,82 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +html { + height: 100%; +} + +body { + height: 100%; + padding: 10px; + color: #262626; + font-family: 'Helvetica Neue Light', 'Open Sans', Helvetica; + font-size: 14px; + font-weight: 300; +} + +h1 { + margin: 0 0 8px 0; + font-size: 24px; + font-family: 'Helvetica Neue Light', 'Open Sans', Helvetica; + font-weight: 300; +} + +h2 { + margin: 16px 0 8px 0; + font-size: 18px; + font-family: 'Helvetica Neue Light', 'Open Sans', Helvetica; + font-weight: 300; +} + +ul { + list-style: none; +} + +a { + color: #2ba6cb; + text-decoration: none; +} + +a:hover { + text-decoration: underline; + color: #258faf; +} + +input, button, select { + font-family: 'Helvetica Neue Light', 'Open Sans', Helvetica; + font-weight: 300; + font-size: 14px; + padding: 2px; +} + +.navigation { + width: 200px; + position: absolute; + top: 0; + bottom: 0; + left: 0; + padding: 10px; + border-right: 1px solid #e9e9e9; +} + +.navigation li { + margin: 10px 0; +} + +.demo-frame { + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 200px; +} + +iframe[name='demo'] { + display: block; + width: 100%; + height: 100%; + border: none; +} \ No newline at end of file diff --git a/css/login.css b/css/login.css new file mode 100755 index 00000000..06cf2fb9 --- /dev/null +++ b/css/login.css @@ -0,0 +1,7 @@ +.alert__msg{ + position: relative; + background-color: rgb(219, 246, 255); + padding: 4vh; + border: 1px solid lightgray; + border-radius: 5%; +} \ No newline at end of file diff --git a/css/main.css b/css/main.css new file mode 100755 index 00000000..d9087f09 --- /dev/null +++ b/css/main.css @@ -0,0 +1,2 @@ +@import 'base.css'; +@import 'login.css'; \ No newline at end of file diff --git a/index.php b/index.php old mode 100644 new mode 100755 index e117ab86..a7f9f473 --- a/index.php +++ b/index.php @@ -1 +1,67 @@ + + + + + + + + Employees + + + + + + + + + + + + +
+
+

Please Log in

+
+
+ +
+
+ +
+
+ +
+ +
+
+
+ $warning[text]
" : "" ?> + You have logged out or your session has expired"; + } ?> + +
+
+
+ + + \ No newline at end of file diff --git a/js/index.js b/js/index.js new file mode 100755 index 00000000..e794d69c --- /dev/null +++ b/js/index.js @@ -0,0 +1,72 @@ +$('#jsGrid').jsGrid({ + width: '100%', + filtering: true, + editing: true, + inserting: true, + sorting: true, + paging: true, + autoload: true, + pageSize: 15, + pageButtonCount: 5, + controller: { + loadData: function (filter) { + return $.ajax({ + type: 'GET', + url: '../src/library/employeeController.php', + data: filter, + success: function (response) { + console.log('GET: ', response) + }, + }) + }, + insertItem: function (item) { + return $.ajax({ + type: 'POST', + url: '../src/library/employeeController.php', + data: { newEmployee: item }, + success: function (response) { + console.log('POST: ', response) + }, + }) + }, + updateItem: function (item) { + return $.ajax({ + type: 'PUT', + url: '../src/library/employeeController.php', + data: { item }, + success: function (response) { + console.log('PUT: ', response) + }, + }) + }, + deleteItem: function (item) { + return $.ajax({ + type: 'DELETE', + url: '../src/library/employeeController.php', + data: { itemId: item.id }, + success: function (response) { + console.log('DELETE: ', response) + }, + }) + }, + }, + + fields: [ + { name: 'id', type: 'text', width: 30 }, + { name: 'name', type: 'text', width: 80, title: 'Name' }, + { name: 'email', type: 'text', width: 100, title: 'Email' }, + { name: 'age', type: 'number', width: 50, title: 'Age' }, + { name: 'streetAddress', type: 'text', width: 50, title: 'Street No.' }, + { name: 'city', type: 'text', width: 100, title: 'City' }, + { name: 'state', type: 'text', width: 50, title: 'Phone State' }, + { + name: 'postalCode', + type: 'text', + width: 150, + title: 'Phone Postal Code', + }, + { name: 'phoneNumber', type: 'text', width: 150, title: 'Phone Number' }, + + { type: 'control' }, + ], +}) diff --git a/package-lock.json b/package-lock.json new file mode 100755 index 00000000..380115f4 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,101 @@ +{ + "name": "assemblerschool", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "assemblerschool", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "bootstrap": "^4.6.1", + "bootstrap-icons": "^1.0.0-alpha4", + "jquery": "^3.6.0", + "jquery-1.8": "^1.8.3", + "jsgrid": "^1.5.3" + } + }, + "node_modules/bootstrap": { + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.6.1.tgz", + "integrity": "sha512-0dj+VgI9Ecom+rvvpNZ4MUZJz8dcX7WCX+eTID9+/8HgOkv3dsRzi8BGeZJCQU6flWQVYxwTQnEZFrmJSEO7og==", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/bootstrap" + }, + "peerDependencies": { + "jquery": "1.9.1 - 3", + "popper.js": "^1.16.1" + } + }, + "node_modules/bootstrap-icons": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/bootstrap-icons/-/bootstrap-icons-1.7.0.tgz", + "integrity": "sha512-x2ORQ3lv1QdSnIzzQdU8mf83fbCq4FIaUinrAWw+a/d186vO3Ph7qUfqzvQDBA41AD6IoxdRHD6zUt9IXC1J6A==", + "engines": { + "node": ">=10" + } + }, + "node_modules/jquery": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.0.tgz", + "integrity": "sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw==" + }, + "node_modules/jquery-1.8": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/jquery-1.8/-/jquery-1.8-1.8.3.tgz", + "integrity": "sha1-Bbzg17NK6QpQ03T1CLcK2Gl/FtE=" + }, + "node_modules/jsgrid": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/jsgrid/-/jsgrid-1.5.3.tgz", + "integrity": "sha1-sV/EJkgxU77itrVnMS9nXZKDSg0=" + }, + "node_modules/popper.js": { + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.16.1.tgz", + "integrity": "sha512-Wb4p1J4zyFTbM+u6WuO4XstYx4Ky9Cewe4DWrel7B0w6VVICvPwdOpotjzcf6eD8TsckVnIMNONQyPIUFOUbCQ==", + "deprecated": "You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1", + "peer": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/popperjs" + } + } + }, + "dependencies": { + "bootstrap": { + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.6.1.tgz", + "integrity": "sha512-0dj+VgI9Ecom+rvvpNZ4MUZJz8dcX7WCX+eTID9+/8HgOkv3dsRzi8BGeZJCQU6flWQVYxwTQnEZFrmJSEO7og==", + "requires": {} + }, + "bootstrap-icons": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/bootstrap-icons/-/bootstrap-icons-1.7.0.tgz", + "integrity": "sha512-x2ORQ3lv1QdSnIzzQdU8mf83fbCq4FIaUinrAWw+a/d186vO3Ph7qUfqzvQDBA41AD6IoxdRHD6zUt9IXC1J6A==" + }, + "jquery": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.6.0.tgz", + "integrity": "sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw==" + }, + "jquery-1.8": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/jquery-1.8/-/jquery-1.8-1.8.3.tgz", + "integrity": "sha1-Bbzg17NK6QpQ03T1CLcK2Gl/FtE=" + }, + "jsgrid": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/jsgrid/-/jsgrid-1.5.3.tgz", + "integrity": "sha1-sV/EJkgxU77itrVnMS9nXZKDSg0=" + }, + "popper.js": { + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.16.1.tgz", + "integrity": "sha512-Wb4p1J4zyFTbM+u6WuO4XstYx4Ky9Cewe4DWrel7B0w6VVICvPwdOpotjzcf6eD8TsckVnIMNONQyPIUFOUbCQ==", + "peer": true + } + } +} diff --git a/package.json b/package.json old mode 100644 new mode 100755 index 9cfa9ad1..9459c0d9 --- a/package.json +++ b/package.json @@ -9,9 +9,10 @@ "author": "Jose Manuel Orts", "license": "ISC", "dependencies": { - "bootstrap": "^4.5.0", + "bootstrap": "^4.6.1", "bootstrap-icons": "^1.0.0-alpha4", - "jquery": "^3.5.1", + "jquery": "^3.6.0", + "jquery-1.8": "^1.8.3", "jsgrid": "^1.5.3" } } diff --git a/resources/images_mock.json b/resources/images_mock.json old mode 100644 new mode 100755 diff --git a/resources/users.json b/resources/users.json old mode 100644 new mode 100755 diff --git a/src/dashboard.php b/src/dashboard.php old mode 100644 new mode 100755 index bd0bef21..5107fa86 --- a/src/dashboard.php +++ b/src/dashboard.php @@ -1 +1,22 @@ + + + + +
+

dashboard

+ +
+ Go to employee +

Hola:

+
+ + \ No newline at end of file diff --git a/src/employee.php b/src/employee.php old mode 100644 new mode 100755 index 2ac36b1d..f10d00e1 --- a/src/employee.php +++ b/src/employee.php @@ -1 +1,12 @@ + + +

employee

+ Go back + + + \ No newline at end of file diff --git a/src/imageGallery.php b/src/imageGallery.php old mode 100644 new mode 100755 diff --git a/src/library/avatarsApi.php b/src/library/avatarsApi.php old mode 100644 new mode 100755 diff --git a/src/library/employeeController.php b/src/library/employeeController.php old mode 100644 new mode 100755 index e69de29b..cb21b045 --- a/src/library/employeeController.php +++ b/src/library/employeeController.php @@ -0,0 +1,31 @@ + \ No newline at end of file diff --git a/src/library/employeeManager.php b/src/library/employeeManager.php old mode 100644 new mode 100755 index 257c204e..bdb05fdb --- a/src/library/employeeManager.php +++ b/src/library/employeeManager.php @@ -1,31 +1,66 @@ $newEmployee[$newId], + "name" => $newEmployee["name"], + "email" => $newEmployee["email"], + "age" => $newEmployee["age"], + "streetAddress" => $newEmployee["streetAddress"], + "city" => $newEmployee["city"], + "state" => $newEmployee["state"], + "postalCode" => $newEmployee["postalCode"], + "phoneNumber" => $newEmployee["phoneNumber"], + ); + + array_push($employeeArray, $newArray); + + file_put_contents("../../resources/employees.json", json_encode($employeeArray)); // TODO implement it } +function deleteEmployee(string $id) { + $employeesArray = json_decode(file_get_contents("../../resources/employees.json"), true); + $newArray = array(); -function updateEmployee(array $updateEmployee) -{ + foreach($employeesArray as $index => $employee) { + if($employee["id"] === $id) { + unset($employeesArray[$index]); + } else { + array_push($newArray, $employee); + } + } + file_put_contents("../../resources/employees.json", json_encode($newArray)); +} + +function updateEmployee(array $updateEmployee) { + $employeeArray = json_decode(file_get_contents("../../resources/employees.json")); + $id = 0; + foreach($employeeArray as $employee) { + $id ++; + } // TODO implement it + echo print_r($employeeArray); + } -function getEmployee(string $id) -{ +function getEmployee(string $id) { // TODO implement it } @@ -43,5 +78,10 @@ function getQueryStringParameters(): array function getNextIdentifier(array $employeesCollection): int { + // TODO implement it } + +function getEmployeesData() { + echo file_get_contents("../../resources/employees.json"); +} diff --git a/src/library/loginController.php b/src/library/loginController.php old mode 100644 new mode 100755 index e69de29b..12ae8e0c --- a/src/library/loginController.php +++ b/src/library/loginController.php @@ -0,0 +1,14 @@ + "danger", "text" => $errorMsg] ; + } + + } + + function timeExpires(){ + if(time() > $_SESSION["expTime"]+$_SESSION["time"]){ + + header("Location: ./library/loginController.php?logout"); + die(); + } + } \ No newline at end of file