Skip to content

Commit 30ac8bb

Browse files
committed
23 Feb 2023
1) Core engine update - Will no longer throw "dynamic properties are deprecated" warnings on PHP 8.2+ 2) PHP-JWT update 3) Generic visuals and class updates
1 parent 6996fbc commit 30ac8bb

31 files changed

+230
-172
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Just access `http://your-site.com/` in your browser and walk through the install
3535
2) Visit https://code-boxx.com/i-was-here-php-attendance-system/ for the full documentation!
3636
<br><br>
3737

38+
## :star: SUPPORT
39+
Like this project? Just give it a star. That will indirectly help grow my blog a little bit. :wink:
40+
<br><br>
41+
3842
## :newspaper: LICENSE
3943
Copyright by Code Boxx
4044

@@ -54,4 +58,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5458
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5559
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5660
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
57-
SOFTWARE.
61+
SOFTWARE.

assets/HEAD-iwh.jpg

-77.7 KB
Binary file not shown.

assets/forgot.jpg

-43.9 KB
Binary file not shown.

assets/forgot.webp

31.5 KB
Loading

assets/head-iwh.webp

36.5 KB
Loading

assets/iwh-1a.png

-8.29 KB
Loading

assets/login.jpg

-50.1 KB
Binary file not shown.

assets/login.webp

32 KB
Loading

lib/LIB-Classes.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function save ($cid, $uid, $date, $desc=null, $id=null) {
1414
// (A2) ADD/UPDATE CLASS
1515
if ($id==null) {
1616
$fields[] = "class_hash";
17-
$data[] = $this->core->random(12);
17+
$data[] = $this->Core->random(12);
1818
$this->DB->insert("classes", $fields, $data);
1919
} else {
2020
$data[] = $id;
@@ -61,14 +61,14 @@ function getAll ($search=null, $page=null) {
6161

6262
// (D2) PAGINATION
6363
if ($page != null) {
64-
$this->core->paginator($this->DB->fetchCol(
64+
$this->Core->paginator($this->DB->fetchCol(
6565
"SELECT COUNT(*) $sql", $data
6666
), $page);
6767
}
6868

6969
// (D3) RESULT
7070
$sql .= " ORDER BY `class_date` DESC";
71-
if ($page != null) { $sql .= $this->core->page["lim"]; }
71+
if ($page != null) { $sql .= $this->Core->page["lim"]; }
7272
return $this->DB->fetchAll(
7373
"SELECT cl.*, DATE_FORMAT(cl.`class_date`, '".DT_LONG."') `cd`, co.`course_code`, co.`course_name`, u.`user_name` $sql",
7474
$data, "class_id"
@@ -80,8 +80,8 @@ function getAll ($search=null, $page=null) {
8080
// $uid : user id or email
8181
function attend ($id, $uid) {
8282
// (E1) VERIFY VALID USER
83-
$this->core->load("Users");
84-
$user = $this->core->Users->get($uid);
83+
$this->Core->load("Users");
84+
$user = $this->Users->get($uid);
8585
if (!is_array($user) || $user["user_role"]!="S") {
8686
$this->error = "Invalid user";
8787
return false;
@@ -221,14 +221,14 @@ function getByTeacher ($uid, $date=null, $range=null, $page=null) {
221221

222222
// (J2) PAGINATION
223223
if ($page != null) {
224-
$this->core->paginator(
224+
$this->Core->paginator(
225225
$this->DB->fetchCol("SELECT COUNT(*) $sql", $data), $page
226226
);
227227
}
228228

229229
// (J3) GET CLASSES
230230
$sql = "SELECT cl.*, DATE_FORMAT(cl.`class_date`, '".DT_LONG."') `cd`, co.`course_code`, co.`course_name` $sql ORDER BY `class_date` DESC";
231-
if ($page != null) { $sql .= $this->core->page["lim"]; }
231+
if ($page != null) { $sql .= $this->Core->page["lim"]; }
232232

233233
// (J4) RESULTS
234234
return $this->DB->fetchAll($sql, $data, "class_id");
@@ -263,7 +263,7 @@ function getByStudent ($uid, $date=null, $range=null, $page=null) {
263263

264264
// (K2) PAGINATION
265265
if ($page != null) {
266-
$this->core->paginator(
266+
$this->Core->paginator(
267267
$this->DB->fetchCol("SELECT COUNT(*) FROM `classes` cl $sql", $data), $page
268268
);
269269
}
@@ -274,7 +274,7 @@ function getByStudent ($uid, $date=null, $range=null, $page=null) {
274274
LEFT JOIN `attendance` a ON (cl.`class_id`=a.`class_id` AND a.`user_id`=?)
275275
LEFT JOIN `courses` co ON (cl.`course_id`=co.`course_id`)
276276
$sql ORDER BY `class_date` DESC";
277-
if ($page != null) { $sql .= $this->core->page["lim"]; }
277+
if ($page != null) { $sql .= $this->Core->page["lim"]; }
278278
array_unshift($data, $uid);
279279

280280
// (K4) RESULTS
@@ -284,8 +284,8 @@ function getByStudent ($uid, $date=null, $range=null, $page=null) {
284284
// (L) IMPORT CLASS
285285
function import ($code, $date, $email, $desc) {
286286
// (L1) CHECK - COURSE CODE
287-
$this->core->load("Courses");
288-
$course = $this->core->Courses->get($code);
287+
$this->Core->load("Courses");
288+
$course = $this->Courses->get($code);
289289
if (!is_array($course)) {
290290
$this->error = "Invalid course - $code";
291291
return false;

lib/LIB-Core.php

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,52 @@
11
<?php
22
class CoreBoxx {
3-
// (A) PROPERTIES & CONSTRUCTOR
4-
public $error = ""; // error message, if any
3+
// (A) PROPERTIES
4+
public $loaded = []; // modules loaded
5+
public $error = ""; // error message, if any
56
public $page = null; // pagination data, if any
6-
function __construct () {
7-
$GLOBALS["_SESS"] = []; // initialize global session variable
8-
}
97

10-
// (B) MODULES
11-
// (B1) LOAD MODULE
8+
// (B) CONSTRUCTOR - INITIALIZE GLOBAL SESSION VARIABLE
9+
function __construct () { $GLOBALS["_SESS"] = []; }
10+
11+
// (C) MODULES HANDLER
12+
// (C1) IS MODULE LOADED?
13+
// $module : module to check
14+
function loaded ($module) { return isset($this->loaded[$module]); }
15+
16+
// (C2) LOAD MODULE
1217
// $module : module to load
13-
function load ($module) { if (!$this->loaded($module)) {
18+
function load ($module) : void {
19+
if ($this->loaded($module)) { return; }
1420
$file = PATH_LIB . "LIB-$module.php";
1521
if (file_exists($file)) {
1622
require $file;
17-
$this->$module = new $module($this);
23+
$this->loaded[$module] = new $module($this);
1824
} else { throw new Exception("$module module not found!"); }
19-
}}
25+
}
2026

21-
// (B2) IS MODULE LOADED?
22-
// $module : module to check
23-
function loaded ($module) {
24-
return isset($this->$module) && is_object($this->$module);
27+
// (C3) "MAGIC LINK" TO MODULE
28+
function __get ($name) {
29+
if (isset($this->loaded[$name])) { return $this->loaded[$name]; }
2530
}
2631

27-
// (C) FUNCTION MAPPING
28-
// (C1) AUTO MAP $_POST OR $_GET TO MODULE FUNCTION
32+
// (D) FUNCTION MAPPING
33+
// (D1) AUTO MAP $_POST OR $_GET TO MODULE FUNCTION
2934
// $module : module to load
3035
// $function : function to run
3136
// $mode : POST or GET
3237
function autoCall ($module, $function, $mode="POST") {
33-
// (C1-1) LOAD MODULE
38+
// (D1-1) LOAD MODULE
3439
$this->load($module);
3540

36-
// (C1-2) MAP POST OR GET?
41+
// (D1-2) MAP POST OR GET?
3742
if ($mode=="POST") { $target =& $_POST; }
3843
else { $target =& $_GET; }
3944

40-
// (C1-3) GET FUNCTION PARAMETERS
45+
// (D1-3) GET FUNCTION PARAMETERS
4146
$reflect = new ReflectionMethod($module, $function);
4247
$params = $reflect->getParameters();
4348

44-
// (C1-4) EVIL MAPPING
49+
// (D1-4) EVIL MAPPING
4550
$evil = "\$results = \$this->$module->$function(";
4651
if (count($params)==0) { $evil .= ");"; }
4752
else {
@@ -61,40 +66,40 @@ function autoCall ($module, $function, $mode="POST") {
6166
$evil = substr($evil, 0, -1) . ");";
6267
}
6368

64-
// (C1-5) EVIL RESULTS
69+
// (D1-5) EVIL RESULTS
6570
eval($evil);
6671
return $results;
6772
}
6873

69-
// (C2) AUTO MAP $_POST OR $_GET TO MODULE FUNCTION & API RESPOND
74+
// (D2) AUTO MAP $_POST OR $_GET TO MODULE FUNCTION & API RESPOND
7075
// $module : module to load
7176
// $function : function to run
7277
// $mode : POST or GET
73-
function autoAPI ($module, $function, $mode="POST") {
78+
function autoAPI ($module, $function, $mode="POST") : void {
7479
$result = $this->autoCall($module, $function, $mode);
7580
$this->respond($result, null, null,
7681
$this->DB->lastID!==null ? $this->DB->lastID : null
7782
);
7883
}
7984

80-
// (C3) SAME AS ABOVE, BUT FOR "GET ENTRIES" API FUNCTIONS
85+
// (D3) SAME AS ABOVE, BUT FOR "GET ENTRIES" API FUNCTIONS
8186
// $module : module to load
8287
// $function : function to run
8388
// $mode : POST or GET
84-
function autoGETAPI ($module, $function, $mode="POST") {
89+
function autoGETAPI ($module, $function, $mode="POST") : void {
8590
$results = $this->autoCall($module, $function, $mode);
8691
$this->respond($results!==false, null, $results);
8792
}
8893

89-
// (D) SYSTEM
90-
// (D1) STANDARD JSON RESPONSE
94+
// (E) SYSTEM
95+
// (E1) STANDARD JSON RESPONSE
9196
// $status : 1 or 0, true or false
9297
// $msg : system message
9398
// $data : optional, data append
9499
// $more : optional, supplementary data
95100
// $http : optional, HTTP response code (401, 403, 500, etc...)
96101
// $exit : stop process, default true
97-
function respond ($status, $msg=null, $data=null, $more=null, $http=null, $exit=true) {
102+
function respond ($status, $msg=null, $data=null, $more=null, $http=null, $exit=true) : void {
98103
if ($http!==null) { http_response_code($http); }
99104
if ($msg === null) {
100105
if ($status==1) { $msg = "OK"; }
@@ -107,9 +112,9 @@ function respond ($status, $msg=null, $data=null, $more=null, $http=null, $exit=
107112
if ($exit) { exit(); }
108113
}
109114

110-
// (D2) STANDARD ERROR HANDLER
111-
function ouch ($ex) {
112-
// (D2-1) OUTPUT JSON ENCODED MESSAGE IN API MODE
115+
// (E2) STANDARD ERROR HANDLER
116+
function ouch ($ex) : void {
117+
// (E2-1) OUTPUT JSON ENCODED MESSAGE IN API MODE
113118
if (defined("API_MODE")) {
114119
$this->respond(0,
115120
ERR_SHOW ? $ex->getMessage() : "OPPS! An error has occured.",
@@ -119,7 +124,7 @@ function ouch ($ex) {
119124
] : null);
120125
}
121126

122-
// (D2-2) SHOW HTML ERROR MESSAGE IN WEB MODE
127+
// (E2-2) SHOW HTML ERROR MESSAGE IN WEB MODE
123128
else if (defined("WEB_MODE")) { ?>
124129
<div style="box-sizing:border-box;position:fixed;top:0;left:0;width:100vw;height:100vh;z-index:9999;background:#fff;color:#000;padding:30px;font-family:arial">
125130
<h1 style="font-size:50px;padding:0;margin:0">(╯°□°)╯︵ ┻━┻</h1>
@@ -136,7 +141,7 @@ function ouch ($ex) {
136141
</div>
137142
<?php }
138143

139-
// (D2-3) OUTPUT PLAIN TEXT OTHERWISE
144+
// (E2-3) OUTPUT PLAIN TEXT OTHERWISE
140145
else {
141146
echo "An error has occured.";
142147
if (ERR_SHOW) {
@@ -148,51 +153,56 @@ function ouch ($ex) {
148153
}
149154
}
150155

151-
// (E) OTHER CONVENIENCE
152-
// (E1) GENERATE RANDOM STRING
156+
// (F) OTHER CONVENIENCE
157+
// (F1) GENERATE RANDOM STRING
153158
// $length : number of bytes
154-
function random ($length=8) {
155-
return bin2hex(random_bytes($length));
156-
}
159+
function random ($length=8) { return bin2hex(random_bytes($length)); }
157160

158-
// (E2) PAGINATION CALCULATOR
161+
// (F2) PAGINATION CALCULATOR
159162
// $entries : total number of entries
160163
// $now : current page
161-
function paginator ($entries, $now=1) {
162-
// (E2-1) TOTAL NUMBER OF PAGES
164+
function paginator ($entries, $now=1) : void {
165+
// (F2-1) TOTAL NUMBER OF PAGES
163166
$this->page = [
164167
"entries" => (int) $entries,
165168
"total" => ceil($entries / PAGE_PER)
166169
];
167170

168-
// (E2-2) CURRENT PAGE
171+
// (F2-2) CURRENT PAGE
169172
$this->page["now"] = $now > $this->page["total"] ? $this->page["total"] : $now ;
170173
if ($this->page["now"]<=0) { $this->page["now"] = 1; }
171174
$this->page["now"] = (int) $this->page["now"];
172175

173-
// (E2-3) LIMIT X,Y
176+
// (F2-3) LIMIT X,Y
174177
$this->page["x"] = ($this->page["now"] - 1) * PAGE_PER;
175178
$this->page["y"] = PAGE_PER;
176179
$this->page["lim"] = " LIMIT {$this->page["x"]}, {$this->page["y"]}";
177180
}
178181

179-
// (E3) REDIRECT
180-
function redirect ($page="", $url=HOST_BASE) {
182+
// (F3) REDIRECT
183+
function redirect ($page="", $url=HOST_BASE) : void {
181184
header("Location: $url$page");
182185
exit();
183186
}
184187
}
185188

186-
// (F) ALL LIBRARIES SHOULD EXTEND THIS CORE CLASS
189+
// (G) ALL MODULES SHOULD EXTEND THIS CORE CLASS
187190
class Core {
191+
// (G1) LINK MODULE TO CORE
192+
public $Core;
193+
public $error;
188194
function __construct ($core) {
189-
$this->core =& $core; // Link to core
190-
$this->error =& $core->error; // Error message
191-
if ($core->loaded("DB")) { $this->DB =& $core->DB; } // Link to database module
195+
$this->Core =& $core;
196+
$this->error =& $core->error;
197+
}
198+
199+
// (G2) MAKE MODULES LINKING EASIER
200+
function __get ($name) {
201+
if (isset($this->Core->loaded[$name])) { return $this->Core->loaded[$name]; }
192202
}
193203
}
194204

195-
// (G) CORE OBJECT + GLOBAL ERROR HANDLING
205+
// (H) CORE OBJECT + GLOBAL ERROR HANDLING
196206
$_CORE = new CoreBoxx();
197207
function _CORERR ($ex) { global $_CORE; $_CORE->ouch($ex); }
198208
set_exception_handler("_CORERR");

0 commit comments

Comments
 (0)