├── .gitignore ├── README.md ├── assets ├── css │ ├── contact.css │ ├── dashboardStyle.css │ ├── employeeStyle.css │ ├── loginStyle.css │ ├── main.css │ └── normalize.css ├── html │ ├── footer.html │ └── header.html ├── img │ ├── asse.webp │ ├── b.png │ ├── c.png │ ├── v_50.png │ └── worker.gif └── js │ ├── contactScript.js │ ├── faceApi.js │ └── index.js ├── contact.php ├── index.php ├── package-lock.json ├── package.json ├── resources ├── employees.json ├── images_mock.json └── users.json └── src ├── dashboard.php ├── employee.php ├── imageGallery.php └── library ├── avatarsApi.php ├── employeeController.php ├── employeeManager.php ├── loginController.php ├── loginManager.php ├── logout.php ├── registerEmployee.php └── sessionHelper.php /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP BASIC APPLICATION TO MANAGE AN EMPLOYEES LIST 2 | 3 | ## Application main points 4 | 5 | 1. Login and logout with a json file as user storage 6 | 2. Controlled user session set to 10 minutes 7 | 3. Show data from a JSON in a JS Grid 8 | 4. Pagination of the data configured by the grid 9 | 5. Employees CRUD Create Read Delete and Update with a json file as employees storage 10 | 6. Employee page with employee detail 11 | 7. External web service to get employees images 12 | 8. Employee avatar through web service images 13 | 14 | ### File structure 15 | 16 | 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!! 17 | 18 | ``` 19 | assets/ 20 | resources/ 21 | src/ 22 | /library 23 | ``` 24 | 25 | - Assets contains html, css, js & images 26 | - Css just css files. 27 | - Resources folder contains users.json and employees.json 28 | - Src folder contains PHP files which contain HTML or JS 29 | - Src/library folder contains PHP files that contain just PHP 30 | 31 | **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.** 32 | 33 | We use some naming conventions when create code files. For instance a file which handles HTTP request we name it as `Controller`. 34 | 35 | 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. 36 | 37 | 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!!** 38 | 39 | 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. 40 | 41 | ``` 42 | index.php // which is the entry point of the application. The login view 43 | employeeController.php // file which has JUST the php code to handle employees request 44 | employeeManager.php // In this file we left you a list of named mehtods to implement and use. 45 | 46 | loginController.php // here you need to handle all HTTP request of login things 47 | loginManager.php // same thing here you need to write things as login validation logout etc.. 48 | 49 | sessionHelper.php // here you can add the code to check if the user session has expired. 50 | ``` 51 | 52 | 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. 53 | 54 | ### Including or importing code files to current file 55 | 56 | 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. 57 | 58 | So for instance a dashboard.php page can look like this at the beginning of the file: 59 | 60 | ``` 61 | 66 | 67 |
68 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Contact 24 | 25 | 26 | 27 |
28 |
29 | 30 |
31 |
32 |
33 | 36 |
37 | 38 |

Contact us

39 |

If you have questions or any problems with our program, please contact us, we will attend to you as soon as 40 | possible. Dev Team .

41 | 42 |
43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 |
52 | 57 |
58 |
59 |
60 |
61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | Employee management 26 | 27 | 28 | 29 |
30 |
31 | 32 |
33 |
34 | 35 |
36 |
37 |
38 | 39 |
40 |
41 |

Create new account. Employee Account

42 |
43 |
44 | 45 |
46 |
47 |
48 |
49 | 57 | 58 | 59 | 60 | 63 |
64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "assemblerschool", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "assemblerschool", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "bootstrap": "^5.2.0-beta1", 13 | "bootstrap-icons": "1.0.0-alpha4", 14 | "jquery": "3.5.1", 15 | "jsgrid": "1.5.3", 16 | "normalize.css": "^8.0.1" 17 | } 18 | }, 19 | "node_modules/@popperjs/core": { 20 | "version": "2.11.5", 21 | "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.5.tgz", 22 | "integrity": "sha512-9X2obfABZuDVLCgPK9aX0a/x4jaOEweTTWE2+9sr0Qqqevj2Uv5XorvusThmc9XGYpS9yI+fhh8RTafBtGposw==", 23 | "peer": true, 24 | "funding": { 25 | "type": "opencollective", 26 | "url": "https://opencollective.com/popperjs" 27 | } 28 | }, 29 | "node_modules/bootstrap": { 30 | "version": "5.2.0-beta1", 31 | "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.2.0-beta1.tgz", 32 | "integrity": "sha512-6qbgs177WZEFY4SLQUq3tEHayYG80nfDmyTpdKi0MJqRMdS+HAoq24+YKfx6wf+nHY0rx8zrh477J1lFu4WzOA==", 33 | "funding": [ 34 | { 35 | "type": "github", 36 | "url": "https://github.com/sponsors/twbs" 37 | }, 38 | { 39 | "type": "opencollective", 40 | "url": "https://opencollective.com/bootstrap" 41 | } 42 | ], 43 | "peerDependencies": { 44 | "@popperjs/core": "^2.11.5" 45 | } 46 | }, 47 | "node_modules/bootstrap-icons": { 48 | "version": "1.0.0-alpha4", 49 | "resolved": "https://registry.npmjs.org/bootstrap-icons/-/bootstrap-icons-1.0.0-alpha4.tgz", 50 | "integrity": "sha512-UcpSUPsvUiW7ueBQfXZSgknJv/rj060dglhWIRPjkLjUWa32jMWqsLXO8tXY2od4Ew6cuh0BJ3f8VOhQPVY4mA==", 51 | "engines": { 52 | "node": ">=10" 53 | } 54 | }, 55 | "node_modules/jquery": { 56 | "version": "3.5.1", 57 | "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.5.1.tgz", 58 | "integrity": "sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg==" 59 | }, 60 | "node_modules/jsgrid": { 61 | "version": "1.5.3", 62 | "resolved": "https://registry.npmjs.org/jsgrid/-/jsgrid-1.5.3.tgz", 63 | "integrity": "sha512-/BJgQp7gZe8o/VgNelwXc21jHc9HN+l7WPOkBhC9b9jPXFtOrU9ftNLPVBmKYCNlIulAbGTW8SDJI0mpw7uWxQ==" 64 | }, 65 | "node_modules/normalize.css": { 66 | "version": "8.0.1", 67 | "resolved": "https://registry.npmjs.org/normalize.css/-/normalize.css-8.0.1.tgz", 68 | "integrity": "sha512-qizSNPO93t1YUuUhP22btGOo3chcvDFqFaj2TRybP0DMxkHOCTYwp3n34fel4a31ORXy4m1Xq0Gyqpb5m33qIg==" 69 | } 70 | }, 71 | "dependencies": { 72 | "@popperjs/core": { 73 | "version": "2.11.5", 74 | "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.5.tgz", 75 | "integrity": "sha512-9X2obfABZuDVLCgPK9aX0a/x4jaOEweTTWE2+9sr0Qqqevj2Uv5XorvusThmc9XGYpS9yI+fhh8RTafBtGposw==", 76 | "peer": true 77 | }, 78 | "bootstrap": { 79 | "version": "5.2.0-beta1", 80 | "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.2.0-beta1.tgz", 81 | "integrity": "sha512-6qbgs177WZEFY4SLQUq3tEHayYG80nfDmyTpdKi0MJqRMdS+HAoq24+YKfx6wf+nHY0rx8zrh477J1lFu4WzOA==", 82 | "requires": {} 83 | }, 84 | "bootstrap-icons": { 85 | "version": "1.0.0-alpha4", 86 | "resolved": "https://registry.npmjs.org/bootstrap-icons/-/bootstrap-icons-1.0.0-alpha4.tgz", 87 | "integrity": "sha512-UcpSUPsvUiW7ueBQfXZSgknJv/rj060dglhWIRPjkLjUWa32jMWqsLXO8tXY2od4Ew6cuh0BJ3f8VOhQPVY4mA==" 88 | }, 89 | "jquery": { 90 | "version": "3.5.1", 91 | "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.5.1.tgz", 92 | "integrity": "sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg==" 93 | }, 94 | "jsgrid": { 95 | "version": "1.5.3", 96 | "resolved": "https://registry.npmjs.org/jsgrid/-/jsgrid-1.5.3.tgz", 97 | "integrity": "sha512-/BJgQp7gZe8o/VgNelwXc21jHc9HN+l7WPOkBhC9b9jPXFtOrU9ftNLPVBmKYCNlIulAbGTW8SDJI0mpw7uWxQ==" 98 | }, 99 | "normalize.css": { 100 | "version": "8.0.1", 101 | "resolved": "https://registry.npmjs.org/normalize.css/-/normalize.css-8.0.1.tgz", 102 | "integrity": "sha512-qizSNPO93t1YUuUhP22btGOo3chcvDFqFaj2TRybP0DMxkHOCTYwp3n34fel4a31ORXy4m1Xq0Gyqpb5m33qIg==" 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "assemblerschool", 3 | "version": "1.0.0", 4 | "description": "Part of basic web application project for Assembler School students", 5 | "main": "index.php", 6 | "scripts": { 7 | "test": "jest" 8 | }, 9 | "author": "Jose Manuel Orts", 10 | "license": "ISC", 11 | "dependencies": { 12 | "bootstrap": "^5.2.0-beta1", 13 | "bootstrap-icons": "1.0.0-alpha4", 14 | "jquery": "3.5.1", 15 | "jsgrid": "1.5.3", 16 | "normalize.css": "^8.0.1" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /resources/employees.json: -------------------------------------------------------------------------------- 1 | [{"id":1,"name":"Rack","lastName":"Lei","email":"jackon@network.com","gender":"man","city":"San Jone","streetAddress":"126","state":"CA","age":"24","postalCode":"394221","phoneNumber":"7383627627"},{"id":"2","name":"John","lastName":"Doe","email":"jhondoe@foo.com","gender":"man","city":"New York","streetAddress":"89","state":"WA","age":"34","postalCode":"09889","phoneNumber":"1283645645"},{"id":3,"name":"Leila","lastName":"Mills","email":"mills@leila.com","gender":"woman","city":"San Diego","streetAddress":"55","state":"CA","age":"29","postalCode":"098765","phoneNumber":"9983632461"},{"id":6,"name":"Brad","lastName":"Simpson","email":"brad@foo.com","gender":"man","age":40,"streetAddress":"128","city":"Atlanta","state":"GEO","postalCode":"394221","phoneNumber":"6854634522"},{"id":7,"name":"Neil","lastName":"Walker","email":"walkerneil@baz.com","gender":"man","age":42,"streetAddress":"1","city":"Nashville","state":"TN","postalCode":90143,"phoneNumber":"45372788192"},{"id":9,"name":"eeeeererererer","lastName":"erererererer","email":"erere@gmail.com","gender":"man","city":"Gij\u00f3n","street":"123","state":"Asturias Province","age":"23","postalCode":"33202","phoneNumber":"666666666"},{"id":7,"name":"javier","lastName":"fernandez","email":"jfernandez@gmaail.com","gender":"man","city":"Galicia","street":"12345","state":"GA","age":"23","postalCode":"33324","phoneNumber":"6768989898"}] -------------------------------------------------------------------------------- /resources/images_mock.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Yvonne Strahovski", 4 | "email": "yvonne.strahovski@gmail.com", 5 | "position": "Software Engineer", 6 | "photo": "https://m.media-amazon.com/images/M/MV5BMzI5NDIzNTQ1Nl5BMl5BanBnXkFtZTgwMjQ0Mzc1MTE@._V1_UY256_CR4,0,172,256_AL_.jpg" 7 | }, 8 | { 9 | "name": "Mario Palmer", 10 | "email": "mario.palmer@gmail.com", 11 | "position": "Senior Developer", 12 | "photo": "https://randomuser.me/api/portraits/men/33.jpg" 13 | }, 14 | { 15 | "name": "Ali Anari", 16 | "email": "ali.anari@gmail.com", 17 | "position": "Customer Service", 18 | "photo": "https://pbs.twimg.com/profile_images/647526574120529920/T5rm0m7W.jpg" 19 | }, 20 | { 21 | "name": "Ariyanna Hicks", 22 | "email": "ariyanna.hicks@gmail.com", 23 | "position": "Product Designer", 24 | "photo": "https://i.imgur.com/Qz5CrD0.jpg" 25 | }, 26 | { 27 | "name": "Jonathan Hung", 28 | "email": "jonathan.hung@gmail.com", 29 | "position": "Call Center Representative", 30 | "photo": "https://pbs.twimg.com/profile_images/869994638110736385/CVYUarcq.jpg" 31 | }, 32 | { 33 | "name": "Andr\u00c3\u00a9 B\u00c3\u00a1rtolo", 34 | "email": "andr\u00c3\u00a9.b\u00c3\u00a1rtolo@gmail.com", 35 | "position": "Clerical", 36 | "photo": "https://pbs.twimg.com/profile_images/1094979667143069696/QrD0ovrh.jpg" 37 | }, 38 | { 39 | "name": "Jennifer Aniston", 40 | "email": "jennifer.aniston@gmail.com", 41 | "position": "Customer Service", 42 | "photo": "https://images-na.ssl-images-amazon.com/images/M/MV5BNjk1MjIxNjUxNF5BMl5BanBnXkFtZTcwODk2NzM4Mg@@._V1_UY256_CR3,0,172,256_AL_.jpg" 43 | }, 44 | { 45 | "name": "Temperance Norwood", 46 | "email": "temperance.norwood@gmail.com", 47 | "position": "Software Engineer", 48 | "photo": "https://images.generated.photos/eL-OqIIteJK_ORyTXpJ96fDVgV_vY5PCvb0CfFGXMxs/rs:fit:512:512/Z3M6Ly9nZW5lcmF0/ZWQtcGhvdG9zLzAx/Njk3NTcuanBn.jpg" 49 | }, 50 | { 51 | "name": "", 52 | "email": "@gmail.com", 53 | "position": "Manager", 54 | "photo": "https://images.pexels.com/photos/38554/girl-people-landscape-sun-38554.jpeg?auto=compress&cs=tinysrgb&h=350" 55 | }, 56 | { 57 | "name": "Jessica Barden", 58 | "email": "jessica.barden@gmail.com", 59 | "position": "Software Engineer", 60 | "photo": "https://images-na.ssl-images-amazon.com/images/M/MV5BNzUwMjgxNTMyOF5BMl5BanBnXkFtZTcwMTIwNzU0NA@@._V1_UX172_CR0,0,172,256_AL_.jpg" 61 | } 62 | ] 63 | -------------------------------------------------------------------------------- /resources/users.json: -------------------------------------------------------------------------------- 1 | { 2 | "users": [ 3 | { 4 | "userId": 1, 5 | "name": "admin", 6 | "password": "$2y$10$nuh1LEwFt7Q2/wz9/CmTJO91stTBS4cRjiJYBY3sVCARnllI.wzBC", 7 | "email": "admin@assemblerschool.com" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /src/dashboard.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Dashboard 23 | 24 | 25 | 26 | 39 |
40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 |
IdNameEmailAgeStreetCityStatePostal CodePhone Number 
59 |
60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/employee.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Employee Form 16 | 17 | 18 | 19 | 20 |
21 |
22 |
23 | 24 |
25 |
26 |

Employee Form

27 | Back to Dashboard 28 |
29 |
30 |
31 |
32 |
33 |
34 | 35 | 36 |
37 |
38 | 39 | 40 |
41 |
42 | 43 | 44 |
45 |
46 | 47 | 51 |
52 |
53 | 54 | 55 |
56 |
57 | 58 | 59 |
60 |
61 | 62 | 63 |
64 | 65 |
66 | 67 | 68 |
69 |
70 | 71 | 72 |
73 |
74 | 75 | 76 |
77 |
78 | 79 |
80 | 81 |
82 |
83 |
84 |
85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /src/imageGallery.php: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/library/avatarsApi.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DogSoulDev/php-employee-management-v1/214d582cdebf4d43e0f35957bd3af8e156104a6f/src/library/avatarsApi.php -------------------------------------------------------------------------------- /src/library/employeeController.php: -------------------------------------------------------------------------------- 1 | "; 8 | // print_r($_SERVER); 9 | // echo ""; 10 | 11 | 12 | if ($method === 'GET' && $_SERVER['QUERY_STRING'] === 'all_data'){ 13 | displayAllEmployees(); 14 | }else if($method === 'GET' && isset($_GET['id'])){ 15 | $employeeId_array = getEmployee($_GET['id']); 16 | $object = json_encode($employeeId_array); 17 | echo $object; 18 | } 19 | else if($method === 'DELETE'){ 20 | // echo "esto viene de controller {$_GET['id']}"; 21 | $employeeId_array = deleteEmployee($_GET['id']); 22 | // $object = json_encode($employeeId_array); 23 | echo $employeeId_array; 24 | 25 | } 26 | 27 | else if ($method === 'POST'){ 28 | $newUser = array ( 29 | "id"=> getNextIdentifier(), 30 | "name"=> $_POST['name'], 31 | "lastName"=> $_POST['lastName'], 32 | "email"=> $_POST['email'], 33 | "gender"=> $_POST['gender'], 34 | "city"=> $_POST['city'], 35 | "street"=> $_POST['street'], 36 | "state"=> $_POST['state'], 37 | "age"=> $_POST['age'], 38 | "postalCode"=> $_POST['postalCode'], 39 | "phoneNumber"=> $_POST['phoneNumber'] 40 | ); 41 | 42 | addEmployee($newUser); 43 | phpAlert("Employee Successfully Saved!"); 44 | header("Location:../dashboard.php"); 45 | } 46 | 47 | 48 | 49 | 50 | // // $_GET['id'] = 1; 51 | // if ($method === 'GET' && isset($_GET['id'])){ 52 | // $employeeId_array = getEmployee($_GET['id']); 53 | // $object = json_encode($employeeId_array); 54 | // echo $object; 55 | 56 | // // print_r ($employeeId_array); 57 | // // var_dump ($object); 58 | // } 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | // $array = array("name" => "jose", "surname" => "Cuevas"); 70 | // print_r ($array); 71 | 72 | // $object = json_decode(json_encode($array)); 73 | 74 | // var_dump ($object); 75 | 76 | 77 | 78 | //VOLHA EXAMPLE 79 | /* require_once('employeeManager.php'); 80 | 81 | if (isset ($_GET ['action']) && $_GET ['action'] == 'getAll') { 82 | //echo "{'id':1}"; 83 | $data = getAllData(); 84 | echo (json_encode($data)); 85 | } 86 | */ 87 | 88 | 89 | 90 | ?> 91 | -------------------------------------------------------------------------------- /src/library/employeeManager.php: -------------------------------------------------------------------------------- 1 | getNextIdentifier(), 30 | // "name" => "Jose", 31 | // "lastName"=> "Cuevas", 32 | // "email"=> "cuevas@network.com", 33 | // "gender"=> "man", 34 | // "city"=> "----", 35 | // "streetAddress"=> "126111", 36 | // "state"=> "AS", 37 | // "age"=> "234", 38 | // "postalCode"=> "11", 39 | // "phoneNumber"=> "22312237" 40 | // ); 41 | 42 | // addEmployee($newUser); 43 | 44 | 45 | function deleteEmployee(string $id) 46 | { 47 | $json = file_get_contents("../../resources/employees.json"); 48 | $users_array = json_decode($json, true); 49 | 50 | foreach ($users_array as $user => $data){ 51 | 52 | // print_r ($users_array); 53 | if ($data['id'] == $id){ 54 | array_splice($users_array, $user, 1); 55 | // unset($users_array[$user]); 56 | } 57 | } 58 | $json_string_modified = json_encode($users_array); 59 | file_put_contents("../../resources/employees.json", $json_string_modified); 60 | 61 | return $json_string_modified; 62 | } 63 | 64 | 65 | // deleteEmployee(2); 66 | 67 | 68 | function updateEmployee(array $updateEmployee) 69 | { 70 | // TODO implement it 71 | } 72 | 73 | function getEmployee(string $id) 74 | { 75 | // TODO implement it 76 | $json = file_get_contents("../../resources/employees.json"); 77 | $user_array = json_decode($json, true); 78 | 79 | $employeeData = ''; 80 | foreach($user_array as $user) { 81 | if($user['id'] == $id) { 82 | // print_r ($user); 83 | $employeeData = $user; 84 | } 85 | } 86 | return $employeeData; 87 | } 88 | 89 | // getEmployee(45); 90 | 91 | 92 | 93 | function removeAvatar($id) 94 | { 95 | // TODO implement it 96 | } 97 | 98 | 99 | function getQueryStringParameters(){ 100 | // TODO implement it 101 | } 102 | 103 | function getNextIdentifier(){ 104 | $json = file_get_contents("../../resources/employees.json"); 105 | $users_array = json_decode($json, true); 106 | 107 | $lastArrayKey = array_key_last($users_array); 108 | $nextId = $lastArrayKey + 2; 109 | // print_r($nextId); 110 | return $nextId; 111 | } 112 | 113 | // Our functions 114 | function displayAllEmployees(){ 115 | $json = file_get_contents("../../resources/employees.json"); 116 | print_r ($json); 117 | } 118 | 119 | function phpAlert(string $msg){ 120 | echo ''; 121 | } 122 | ?> -------------------------------------------------------------------------------- /src/library/loginController.php: -------------------------------------------------------------------------------- 1 | "; 7 | print_r($_SERVER); 8 | echo ""; 9 | 10 | 11 | if($_SERVER['REQUEST_METHOD'] == "POST") { 12 | checkLogin($_POST['username'], $_POST['password']); 13 | }else if($_SERVER['QUERY_STRING'] == "logout"){ 14 | // logout(); 15 | unset($_SESSION); 16 | header("location: ../../index.php"); 17 | } 18 | 19 | 20 | 21 | 22 | ?> -------------------------------------------------------------------------------- /src/library/loginManager.php: -------------------------------------------------------------------------------- 1 | "; 16 | // var_dump($userDataName, $userDataPassword); 17 | // echo ""; 18 | } 19 | 20 | function checkUrl ($get){ 21 | if(isset($get['error'])){ 22 | echo ""; 23 | } 24 | } 25 | 26 | 27 | ?> -------------------------------------------------------------------------------- /src/library/logout.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/library/registerEmployee.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Register Account 15 | 16 | 17 | 18 |
19 |
20 | 21 |
22 |

Register Employee Account

23 |
24 | 26 |
27 |
28 | 29 | 30 |
31 | 32 | 33 |

I already have an account.

34 |
35 |
36 | 41 |
42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/library/sessionHelper.php: -------------------------------------------------------------------------------- 1 | 10) { //subtract new timestamp from the old one 3 | echo""; 4 | unset($_SESSION['username'], $_SESSION['password'], $_SESSION['timestamp']); 5 | $_SESSION['logged_in'] = false; 6 | header("Location: http://127.0.0.1/php-employee-management-v1/src/library/logout.php/");//redirect to index.php 7 | exit; 8 | } else { 9 | $_SESSION['timestamp'] = time(); //set new timestamp 10 | } 11 | ?> --------------------------------------------------------------------------------