-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass.php
894 lines (547 loc) · 20.7 KB
/
class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
<?php
class WebEstimator {
// The Data Connection
private $db;
// The Steps List
public $steps = array();
// == INIT ==================================================
function __construct() {
session_start();
// If not on development mode
if ( substr($_SERVER["SERVER_NAME"], 0, 4) != "dev." ) {
// Force SSL
if ( !$this->isSSL() ) {
header( 'Location: '.$this->currentPageURL("", true) );
die();
}
// Force WWW
if ( substr($_SERVER["SERVER_NAME"], 0, 4) != "www." ) {
header( 'Location: '.$this->currentPageURL("", true, true) );
die();
}
}
// DB Connect
$this->db = $this->dbConnect();
// List Steps
$this->steps = $this->listSteps();
// Login
if ( isset($_GET["login"]) && isset($_POST["login-name"]) && isset($_POST["login-pass"]) )
$this->logIn($_POST["login-name"], $_POST["login-pass"]);
// Logout
if ( isset($_GET["logout"]) ) $this->logOut();
// AJAX Handler
if ( isset($_POST["ajax_action"]) )
$this->ajaxHandler($_POST);
// PRINT THE TEMPLATE
ob_start();
include('view/main.php');
ob_end_flush();
// DB Disconnect
$this->db = $this->dbDisconnect();
}
// == DATA CONNECTION ==================================================
function dbConnect() {
require "config.php";
$conn_error = "";
try {
$conn = new PDO("mysql:host=$servername;dbname=$database", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->query("SET NAMES 'utf8'");
}
catch(PDOException $e) {
$conn_error = "Connection failed: " . $e->getMessage();
return $conn_error;
}
return $conn;
}
// == DB DISCONNECTION ==================================================
function dbDisconnect() {
$this->db = null;
}
// == DB QUERY ==================================================
function dbQuery($query, $prepare = false) {
if ($prepare)
return $this->db->prepare($query);
return $this->db->query($query);
}
// == HOME PAGE URL ==================================================
function homePageURL() {
return "http".($this->isSSL() ? "s" : "")."://".$_SERVER["SERVER_NAME"].str_replace("/index.php", "", $_SERVER["PHP_SELF"]);
}
// == AJAX HANDLER ==================================================
function ajaxHandler($data) {
$response['success'] = false;
if ($data['ajax_action'] == 'update-time' && $this->isAdmin()) { // Admin Update Input Time
$stmt = $this->dbQuery("UPDATE inputs SET input_time='".$data['input_time']."' WHERE input_ID='".$data['input_ID']."'", true);
$stmt->execute();
$response['success'] = $stmt->rowCount() == 1 ? true : false;
$response['input_time'] = $data['input_time'];
$response['input_ID'] = $data['input_ID'];
} elseif ($data['ajax_action'] == 'duplicate-input' && $this->isAdmin()) { // Admin Duplicate an Input
// Prepare the duplicate data
$result = $this->dbQuery("SELECT * FROM inputs WHERE input_ID = ".$data['input_ID']." LIMIT 1");
$row = $result->fetch(PDO::FETCH_ASSOC);
$SQL = "INSERT INTO inputs (";
// Add the keys
$first = true;
foreach($row as $key => $val) {
if($key != "" && !is_numeric($key) && $key != 'input_ID' && $val != null) {
if (!$first) $SQL .= ', ';
$SQL .= $key;
$first = false;
}
}
$SQL .= ') VALUES (';
// Add the Values
$first = true;
foreach($row as $key => $val) {
if($key != "" && !is_numeric($key) && $key != 'input_ID' && $val != null) {
if (!$first) $SQL .= ', ';
if ($key == "input_slug") $val = $val."_new";
$SQL .= "'". addslashes($val)."'";
$first = false;
}
}
$SQL .= ')';
$stmt = $this->dbQuery($SQL, true);
$stmt->execute();
$response['success'] = $stmt->rowCount() == 1 ? true : false;
$response['input_ID'] = $data['input_ID'];
//$response['success'] = $SQL;
} elseif ($data['ajax_action'] == 'delete-input' && $this->isAdmin()) { // Admin Duplicate an Input
$stmt = $this->dbQuery("DELETE FROM inputs WHERE input_ID='".$data['input_ID']."'", true);
$stmt->execute();
$response['success'] = $stmt->rowCount() == 1 ? true : false;
$response['input_ID'] = $data['input_ID'];
} else {
$response['success'] = false;
}
echo json_encode($response);
die();
}
// == CURRENT PAGE URL ==================================================
function currentPageURL($add = "", $forceSSL = false, $forceWWW = false) {
$pageURL = 'http';
if ( (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") || $forceSSL )
$pageURL .= "s";
$pageURL .= "://";
if ( $forceWWW && substr($_SERVER["SERVER_NAME"], 0, 4) != "www." )
$pageURL .= "www.";
if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443")
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
else
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
if ($add != "") {
if ( strpos($pageURL,'?') == false ) { $pageURL .= "?".$add; } else { $pageURL .= "&".$add; }
}
return $pageURL;
}
// == LOG IN ==================================================
function logIn($userName, $password) {
$userName = stripslashes($userName);
$password = stripslashes($password);
$stmt = $this->dbQuery("SELECT * FROM users WHERE user_name='".$userName."' OR user_email='".$userName."' LIMIT 1");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() > 0 && password_verify($password, $row['user_password'])) {
$_SESSION['user_ID'] = $row['user_ID'];
header("location: ".$this->removeQueryArg('error', $_SERVER['HTTP_REFERER']) );
die();
} else {
header("location: ".$this->queryArg('error', 'wrong', $_SERVER['HTTP_REFERER']) );
die();
}
}
// == LOG OUT ==================================================
function logOut() {
if( session_destroy() ) {
header("Location: ".$_SERVER['HTTP_REFERER']); // Redirecting to previous page
die();
}
}
// == USER LOGGED IN? ==================================================
function isLoggedIn() {
return ( isset($_SESSION['user_ID']) ) ? true : false;
}
// == USER ADMIN? ==================================================
function isAdmin() {
return $this->isLoggedIn() && $this->userInfo('user_level') == 0 ? true : false;
}
// == SSL MODE? ==================================================
function isSSL() {
return isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on" ? true : false;
}
// == CURRENT USER INFO ==================================================
function userInfo($info, $userID = "") {
if ( $this->isLoggedIn() && $userID == "" ) $userID = $_SESSION['user_ID'];
elseif ( !$this->isLoggedIn() && $userID == "" ) return false;
$stmt = $this->dbQuery("SELECT * FROM users WHERE user_ID='".$userID."' LIMIT 1");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
return $row[$info];
}
// == SHOW PAGE CONTENT ==================================================
function showContent() {
if ( isset($_GET['error']) ) {
echo "<h1 style='text-align: center;'>Username or password is wrong</h1>";
echo "<h3 style='text-align: center;'>Please try again</h3>";
} else {
// STEP BAR
include("view/progress_bar.php");
// SHOW Questions
include("view/step_content.php");
}
}
// == LIST STEPS ==================================================
function listSteps() {
$steps = array();
$stepNo = 1;
$steps_query = $this->dbQuery('SELECT step_slug, step_name FROM steps WHERE main_choice_ID = '.$this->mainChoiceCategoryID().' OR main_choice_ID = '.$this->mainChoiceID().' ORDER BY step_order');
while ($step = $steps_query->fetch()) {
$steps[$stepNo] = array(
'step_name' => $step['step_name'],
'step_slug' => $step['step_slug']
);
$stepNo++;
}
return $steps;
}
// == CURRENT STEP SLUG ==================================================
function stepSlug($isStepSlug = "") {
if ($_SERVER["QUERY_STRING"] == "") { // If it's Home Page
if ($isStepSlug != "" ) {
return ($isStepSlug == "concept" ? true : false);
} else {
return "concept";
}
} elseif ( isset($_GET['go']) ) { // ...&go=xxx
if ($isStepSlug != "" ) {
return ($isStepSlug == $_GET['go'] ? true : false);
} else {
return $_GET['go'];
}
} else { // ...&xxx=current...
$new_gets = array_flip($_GET);
if ($isStepSlug != "" ) {
return (isset($new_gets['current']) && $isStepSlug == $new_gets['current'] ? true : false);
} else {
return (isset($new_gets['current']) ? $new_gets['current'] : 'other');
}
}
}
// == CURRENT STEP ID ==================================================
function stepID( $stepSlug = "" ) {
$stmt = $this->dbQuery("SELECT step_ID FROM steps WHERE step_slug = '".($stepSlug != '' ? $stepSlug : $this->stepSlug())."' LIMIT 1");
$row = $stmt->fetch();
return $row['step_ID'];
}
// == STEP TITLE ==================================================
function stepTitle($stepSlug = "") {
$stmt = $this->dbQuery("SELECT step_name FROM steps WHERE step_slug = '".($stepSlug != '' ? $stepSlug : $this->stepSlug())."' LIMIT 1");
$row = $stmt->fetch();
return $row['step_name'];
}
// == STEP NUMBER ==================================================
function stepNo($stepSlug = "") {
if ($stepSlug == "") $stepSlug = $this->stepSlug();
foreach ($this->steps as $no => $step) {
if ($step['step_slug'] == $stepSlug ) {
return $no;
break;
}
}
}
// == NEXT STEP ==================================================
function nextStepSlug($stepSlug = "") {
if ($stepSlug == "") $stepSlug = $this->stepSlug();
return $this->steps[ $this->stepNo($stepSlug) + 1 ]['step_slug'];
}
// == MAIN CHOICE TITLE ==================================================
function mainChoiceTitle($main_choice = "") {
$stmt = $this->dbQuery("SELECT main_choice_name FROM main_choices WHERE main_choice_slug = '".($main_choice != '' ? $main_choice : $this->mainChoice())."' LIMIT 1");
$row = $stmt->fetch();
return $row['main_choice_name'];
}
// == GET SELECTED MAIN CHOICE ==================================================
function mainChoice() {
if ( isset($_GET['concept']) )
return $_GET['concept'];
else
return "ecommerce";
}
// == GET SELECTED MAIN CHOICE ID ==================================================
function mainChoiceID() {
$stmt = $this->dbQuery("SELECT main_choice_ID FROM main_choices WHERE main_choice_slug = '".$this->mainChoice()."' LIMIT 1");
$row = $stmt->fetch();
return $row['main_choice_ID'];
}
// == GET SELECTED MAIN CHOICE CATEGORY ==================================================
function mainChoiceCategory() {
$stmt = $this->dbQuery("SELECT main_choice_name FROM main_choices WHERE main_choice_ID = '".$this->mainChoiceCategoryID()."' LIMIT 1");
$row = $stmt->fetch();
return $row['main_choice_name'];
}
// == GET SELECTED MAIN CHOICE CATEGORY ID ==================================================
function mainChoiceCategoryID() {
$stmt = $this->dbQuery("SELECT main_choice_parent_ID FROM main_choices WHERE main_choice_ID = '".$this->mainChoiceID()."' LIMIT 1");
$row = $stmt->fetch();
return $row['main_choice_parent_ID'];
}
// == STEP STATUS ==================================================
function stepStatus($step) {
if (
( isset($_GET[$step]) && $_GET[$step]=="current" ) ||
( $this->isFirstStep($step) && !isset($_GET[$step]) ) ||
( isset($_GET["go"]) && $_GET["go"]==$step) )
{
return "current";
}
elseif ( !isset($_GET[$step]) && !$this->isFirstStep($step) )
{
return "notyet";
}
elseif ( isset($_GET[$step]) && $_GET[$step] == "" )
{
return "skipped";
}
elseif ( isset($_GET[$step]) && $_GET[$step] != "" )
{
return "done";
}
}
// == FIELD SLUG ==================================================
function fieldSlug($stepSlug, $fieldIndex = 0) {
$stmt = $this->dbQuery("SELECT field_slug FROM fields WHERE step_ID = '".$this->stepID($stepSlug)."' LIMIT 1 OFFSET $fieldIndex");
$row = $stmt->fetch();
if ( $row['field_slug'] == "" )
return "NOT FOUND";
else
return $row['field_slug'];
}
// == FIELD SHORT NAME ==================================================
function fieldShortName($fieldSlug) {
$stmt = $this->dbQuery("SELECT field_short_name FROM fields WHERE field_slug = '".$fieldSlug."' LIMIT 1");
$row = $stmt->fetch();
return $row['field_short_name'];
}
// == INPUT VALUES ==================================================
function inputValues($findSlug = null, $stepSlug = "") {
// DATA SAMPLE
// &domain=yes&server=other&static_pages=home--about--privacy--terms--contact--more_static-4
// If not stepSlug specified, use the current step slug
$stepSlug = $stepSlug != '' ? $stepSlug : $this->stepSlug();
// Parse the fields in the step
$fields = explode('--', $_GET[$stepSlug]);
// Parse the field data
$values = array();
foreach ($fields as $field) {
if ($field != "current" && $field != "na") {
if ( strpos($field, "-") ) { // xxxx-y
$parsedField = explode('-', $field);
$inputSlug = $parsedField[0];
$inputValue = $parsedField[1];
$values[$inputSlug] = $inputValue;
} else { // xxx--yyy--zzz
$values[$stepSlug][] = $field;
}
}
}
// Check
if ( $findSlug !== null ) {
if ( isset($values[$findSlug]) ) $return = $values[$findSlug];
else $return = false;
} else {
$return = $values;
}
// If result is an array and has only one item
if ( is_array($return) && count($return) == 1 )
return current($return);
else
return $return;
}
// == INPUT TIME ==================================================
function inputTime($inputSlugOrID, $inputValue = "", $singular = false) {
if ( is_numeric($inputSlugOrID) )
$sqlBeginning = "SELECT input_time FROM inputs WHERE input_ID = ".$inputSlugOrID;
else
$sqlBeginning = "SELECT input_time FROM inputs WHERE input_slug = '".$inputSlugOrID."'";
$stmt = $this->dbQuery("$sqlBeginning LIMIT 1");
$row = $stmt->fetch();
if ( !is_numeric($inputValue) && !is_numeric($inputSlugOrID) ) {
$stmt = $this->dbQuery("$sqlBeginning AND input_value = '".$inputValue."' LIMIT 1");
$row = $stmt->fetch();
$time = $row['input_time'];
} else {
if ( $singular ) $inputValue = 1;
$time = intval($row['input_time']) * $inputValue;
}
return $time;
}
// == INPUT NAME ==================================================
function inputName($inputSlug, $inputValue = "") {
if (is_numeric($inputValue)) return $inputValue;
$stmt = $this->dbQuery("SELECT input_name FROM inputs WHERE input_slug = '".$inputSlug."' LIMIT 1");
if ($inputValue != "" && !is_numeric($inputValue))
$stmt = $this->dbQuery("SELECT input_name FROM inputs WHERE input_slug = '".$inputSlug."' AND input_value = '".$inputValue."' LIMIT 1");
$row = $stmt->fetch();
return $row['input_name'];
}
// == INPUT SHORT NAME ==================================================
function inputShortName($inputSlug, $inputValue = "") {
if (is_numeric($inputValue)) return $inputValue;
$stmt = $this->dbQuery("SELECT input_name, input_short_name, input_value FROM inputs WHERE input_slug = '".$inputSlug."' LIMIT 1");
if ($inputValue != "" && !is_numeric($inputValue))
$stmt = $this->dbQuery("SELECT input_name, input_short_name, input_value FROM inputs WHERE input_slug = '".$inputSlug."' AND input_value = '".$inputValue."' LIMIT 1");
$row = $stmt->fetch();
if ( $inputValue == "" && !is_numeric($row['input_value']) ) return false;
if ($row['input_short_name'] != "")
return $row['input_short_name'];
else
return $row['input_name'];
}
// == INPUT ADMIN ==================================================
function inputAdmin($inputID) {
$output = "";
if ( $this->isLoggedIn() && $this->isAdmin() ) {
$inputTime = $this->inputTime($inputID, "", true);
$output .= '
<span class="input-admin">
<span class="field update-time">
<span data-toggle="tooltip" title="Change and Press enter to update">
<input type="number" value="'.$inputTime.'" class="form-control"> minutes
</span>
<a href="#" data-toggle="tooltip" title="Update the time">
<span class="fui-time"></span>
</a>
</span>
<span class="field duplicate-input">
<a href="#" data-toggle="tooltip" data-title="Duplicate">
<span class="fui-windows"></span>
</a>
</span>
<span class="field edit-input">
<a href="#" data-toggle="tooltip" data-title="Edit">
<span class="fui-new"></span>
</a>
</span>
<span class="field delete-input">
<a href="#" data-toggle="tooltip" data-title="Delete">
<span class="fui-trash"></span>
</a>
</span>
</span>
';
}
return $output;
}
// == IS FIRST STEP? ==================================================
function isLastStep($step) {
$steps = $this->steps;
$totalSteps = count($this->steps);
$lastStepNumber = $totalSteps - 1;
if ( isset($steps[$lastStepNumber]['step_slug']) && $steps[$lastStepNumber]['step_slug'] == $step )
return true;
else
return false;
}
// == IS LAST STEP? ==================================================
function isFirstStep($step) {
return ($step == "concept") ? true : false;
}
// == PROGRESS BAR LINKS ==================================================
function stepLink($step) {
$url = $this->currentPageURL();
if ( $this->stepSlug($step) ) { // Avoid if the destination step is our current step
$url = "#";
} elseif ( $this->stepStatus($step) == "notyet" ) { // Avoid if the destination step is not seen yet
$url = "#";
} else {
// If the current step has no data yet, make this step skipped
if ( isset($_GET[$this->stepSlug()]) && $_GET[$this->stepSlug()] == "current" )
$url = $this->queryArg( $this->stepSlug(), "", $url );
// If destination step is skipped, put "=current" to destination
if( $this->stepStatus($step) == "skipped" ) {
$url = $this->removeQueryArg( "go", $url );
$url = $this->queryArg( $step, "current", $url );
// If destination step is input, put "&go=destination"
} elseif ( $this->stepStatus($step) == "done" ) {
$url = $this->queryArg( "go", $step, $url );
}
}
return $url;
}
// == ADD/UPDATE QUERY ARGUMENT ==================================================
function queryArg($key, $value, $url) {
$parsed = parse_url($url);
if ( isset($parsed['query']) ) {
$query = $parsed['query'];
// Parse the query
parse_str($query, $params);
// Add
$params[$key] = $value;
// Build new query
$newQuery = http_build_query($params);
return $parsed['scheme']."://".$parsed['host'].$parsed['path']."?".$newQuery;
} else {
return $url."?".$key."=".$value;
}
}
// == REMOVE QUERY ARGUMENT ==================================================
function removeQueryArg($key, $url) {
$parsed = parse_url($url);
if ( isset($parsed['query']) ) {
$query = $parsed['query'];
// Parse the query
parse_str($query, $params);
// Delete
unset($params[$key]);
// Build new query
$newQuery = http_build_query($params);
return $parsed['scheme']."://".$parsed['host'].$parsed['path'].(empty($newQuery) ? "" : "?").$newQuery;
} else {
return $url;
}
}
// == SUBMIT LINK ==================================================
function submitLink($data, $next_step, $delete = "") {
$url = $this->currentPageURL();
// Clear unnecessary variables if requested
if ( $delete != "" ) {
foreach ($delete as $del) {
$url = $this->removeQueryArg( $del, $url );
}
}
// Always add the data to current step
$url = $this->queryArg( $this->stepSlug(), $data, $url );
// If destination is not empty
if ( isset($_GET[$next_step]) && $_GET[$next_step] != "" ) {
$url = $this->queryArg( "go", $next_step, $url );
} else {
$url = $this->removeQueryArg( "go", $url );
$url = $this->queryArg( $next_step, "current", $url );
}
return $url;
}
// == BEAUTIFY MINUTES ==================================================
function beautifyMinutes($minutes) {
if ($minutes < 0 || !is_numeric($minutes)) return;
$hours = floor($minutes / 60);
$hoursText = $hours." hour".($hours > 1 ? "s" : "");
$minutes = ($minutes % 60);
$minutesText = $minutes." minute".($minutes > 1 ? "s" : "");
$separator = " ";
if (
($hours == 0 && $minutes != 0) ||
($hours != 0 && $minutes == 0) ||
($hours == 0 && $minutes == 0)
) $separator = "";
$time = ($hours != 0 ? $hoursText : '').$separator.($minutes != 0 ? $minutesText : '');
if ($time == "") $time = "Nothing";
return $time;
}
// == BRING THE OLD DATA ==================================================
function bringData() {
foreach ($_GET as $data => $value) {
echo "<input type='text' name='$data' value='$value' hidden='true'>\n";
}
}
}
?>