-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.php
55 lines (45 loc) · 1.45 KB
/
log.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
<?php
require_once("inc/controller.php");
if(!$session->is_logged_in()){
redirect_to("timeline.php");
}
if(isset($_POST["submit"])){
$title = $_POST["title"];
$time = date("d-m-Y");
//$notes = str_replace("\n", "<br>", $_POST["notes"]);
$notes = $_POST["notes"];
$user_id = $session->user_id;
$body = "";
foreach($_POST as $key=>$value){
if(strpos($key,"exercise") !== false) {
// if the $_POST key contains exercise
$body .= "<strong>" . $value . "</strong>\n";
} elseif(strpos($key,"reps") !== false && preg_match('#[0-9]#',$value)) {
$body .= "<p>" . $value . " reps, ";
} elseif(strpos($key,"weight") !== false && preg_match('#[0-9]#',$value)) {
$body .= $value . " kg, ";
} elseif(strpos($key,"sets") !== false && preg_match('#[0-9]#',$value)) {
$body .= $value . " sets</p>\n";
}
}
$log = new Log();
if($log->input_validates($title)){
$log->title = $title;
$log->body = $body;
$log->notes = $notes;
$log->time = $time;
$log->user_id = $user_id;
$log->create();
$log_id = $database->insert_id();
$_SESSION["message"] = "Log added! positive";
redirect_to("share.php?log_id={$log_id}");
} else {
// $_SESSION["message"] gets set by the input_validates method
// so no need to set here
redirect_to("logging.php");
}
} else { // form has not been submitted
$_SESSION["message"] = "Something went wrong! negative";
redirect_to("index.php");
}
?>