|
25 | 25 | if ( isset($_POST['id']) && is_numeric($_POST['id']) && $_POST['id'] >= 0) $eventId = $_POST['id']; |
26 | 26 | if ( isset($_POST['name']) && !empty($_POST['name'])) $eventName = sanitize_userinput($_POST['name']); |
27 | 27 | if ( !empty($_POST['location'])) $eventLocation = sanitize_userinput($_POST['location']); |
28 | | -if ( !empty($_POST['link'])) $eventLink = escape_text((filter_var($_POST['link'], FILTER_VALIDATE_URL)===false?(filter_var(SITE_PROTOCOL.$_POST['link'], FILTER_VALIDATE_URL)!==false?SITE_PROTOCOL.$_POST['link']:$error='Ungültiger Event-Link'):$_POST['link'])); |
29 | | -if ( !empty($_POST['review_url'])) $eventReviewlink = escape_text((filter_var($_POST['review_url'], FILTER_VALIDATE_URL)===false?(filter_var(SITE_PROTOCOL.$_POST['review_url'], FILTER_VALIDATE_URL)!==false?SITE_PROTOCOL.$_POST['review_url']:$error='Ungültige Review-URL'):$_POST['review_url'])); |
| 28 | +if ( !empty($_POST['link'])) $eventLink = (filter_var($_POST['link'], FILTER_VALIDATE_URL)===false?(filter_var(SITE_PROTOCOL.$_POST['link'], FILTER_VALIDATE_URL)!==false?SITE_PROTOCOL.$_POST['link']:$error='Ungültiger Event-Link'):$_POST['link']); |
| 29 | +if ( !empty($_POST['review_url'])) $eventReviewlink = (filter_var($_POST['review_url'], FILTER_VALIDATE_URL)===false?(filter_var(SITE_PROTOCOL.$_POST['review_url'], FILTER_VALIDATE_URL)!==false?SITE_PROTOCOL.$_POST['review_url']:$error='Ungültige Review-URL'):$_POST['review_url']); |
30 | 30 | if ( !empty($_POST['description'])) $eventDescription = htmlspecialchars_decode($_POST['description'], ENT_COMPAT | ENT_SUBSTITUTE); |
31 | 31 | if ( isset($_POST['gallery_id']) && is_numeric($_POST['gallery_id']) && $_POST['gallery_id'] >= 0) $eventGallery = $_POST['gallery_id']; |
32 | 32 | if ( isset($_GET['join']) && is_numeric($_GET['join']) && $_GET['join'] >= 0) $eventJoinId = $_GET['join']; |
|
38 | 38 | /** Validation Error */ |
39 | 39 | case (!empty($error)): |
40 | 40 | /** If $error break switch() instantly */ |
41 | | - if (DEVELOPMENT) error_log(sprintf('[DEBUG] <%s:%d> Error: %s', __FILE__, __LINE__, $error)); |
| 41 | + zorgDebugger::me()->warn('Validation Error: %s%s', [$error]); |
42 | 42 | break; |
43 | 43 |
|
44 | 44 |
|
45 | 45 | /** Add new Event */ |
46 | 46 | case ((isset($_POST['action']) && $_POST['action'] === 'new')): |
47 | | - if (DEVELOPMENT) error_log(sprintf('[DEBUG] <%s:%d> New Event: %s', __FILE__, __LINE__, $eventName)); |
48 | | - $sql = 'INSERT INTO |
49 | | - events |
50 | | - (name, location, link, description, startdate, enddate, gallery_id, reportedby_id, reportedon_date, review_url) |
51 | | - VALUES |
52 | | - ( |
53 | | - "'.$eventName.'" |
54 | | - ,"'.$eventLocation.'" |
55 | | - ,"'.$eventLink.'" |
56 | | - ,"'.$eventDescription.'" |
57 | | - ,"'.$_POST['startYear'].'-'.$_POST['startMonth'].'-'.$_POST['startDay'].' '.$_POST['startHour'].':00" |
58 | | - ,"'.$_POST['endYear'].'-'.$_POST['endMonth'].'-'.$_POST['endDay'].' '.$_POST['endHour'].':00" |
59 | | - ,'.$eventGallery.' |
60 | | - ,'.$user->id.' |
61 | | - ,'.timestamp(true).' |
62 | | - ,"'.$eventReviewlink.'" |
63 | | - )'; |
64 | | - $idNewEvent = $db->query($sql, __FILE__, __LINE__, 'INSERT INTO events'); |
| 47 | + zorgDebugger::me()->debug('Adding new Event: %s', [$eventName]); |
| 48 | + $startdate = sprintf('%s-%s-%s %s:00', $_POST['startYear'], $_POST['startMonth'], $_POST['startDay'], $_POST['startHour']); |
| 49 | + $enddate = sprintf('%s-%s-%s %s:00', $_POST['endYear'], $_POST['endMonth'], $_POST['endDay'], $_POST['endHour']); |
| 50 | + $values = [ |
| 51 | + 'name' => $eventName, |
| 52 | + 'location' => $eventLocation, |
| 53 | + 'link' => $eventLink, |
| 54 | + 'description' => $eventDescription, |
| 55 | + 'startdate' => $startdate, |
| 56 | + 'enddate' => $enddate, |
| 57 | + 'gallery_id' => $eventGallery, |
| 58 | + 'reportedby_id' => $user->id, |
| 59 | + 'reportedon_date' => timestamp(true), |
| 60 | + 'review_url' => $eventReviewlink |
| 61 | + ]; |
| 62 | + $idNewEvent = $db->insert('events', $values, __FILE__, __LINE__, 'INSERT INTO events'); |
65 | 63 |
|
66 | 64 | /** Error */ |
67 | 65 | if (empty($idNewEvent)) |
|
80 | 78 |
|
81 | 79 | /** Save updated Event details */ |
82 | 80 | case ((isset($_POST['action']) && $_POST['action'] === 'edit')): |
83 | | - if (DEVELOPMENT) error_log(sprintf('[DEBUG] <%s:%d> Update Event: %d "%s"', __FILE__, __LINE__, $eventId, $eventName)); |
| 81 | + zorgDebugger::me()->debug('Update existing Event: %d «%s»', [$eventId, $eventName]); |
84 | 82 |
|
| 83 | + $newStartdate = sprintf('%s-%s-%s %s:00', $_POST['startYear'], $_POST['startMonth'], $_POST['startDay'], $_POST['startHour']); |
| 84 | + $newEnddate = sprintf('%s-%s-%s %s:00', $_POST['endYear'], $_POST['endMonth'], $_POST['endDay'], $_POST['endHour']); |
85 | 85 | $sql = 'UPDATE events |
86 | 86 | SET |
87 | 87 | name = "'.$eventName.'" |
88 | 88 | , location = "'.$eventLocation.'" |
89 | 89 | , link = "'.$eventLink.'" |
90 | 90 | , description = "'.$eventDescription.'" |
91 | | - , startdate = "'.$_POST['startYear'].'-'.$_POST['startMonth'].'-'.$_POST['startDay'].' '.$_POST['startHour'].':00" |
92 | | - , enddate = "'.$_POST['endYear'].'-'.$_POST['endMonth'].'-'.$_POST['endDay'].' '.$_POST['endHour'].':00" |
| 91 | + , startdate = "'.$newStartdate.'" |
| 92 | + , enddate = "'.$newEnddate.'" |
93 | 93 | , gallery_id = '.$eventGallery.' |
94 | 94 | , review_url = "'.$eventReviewlink.'" |
95 | 95 | WHERE id = '.$eventId |
96 | 96 | ; |
97 | | - if (DEVELOPMENT) error_log($sql); |
| 97 | + // TODO use $db->update() Method |
98 | 98 | $result = $db->query($sql, __FILE__, __LINE__, 'edit'); |
99 | 99 | if ($result === false) $error = 'Error updating Event ID "' . $eventId . '"'; |
100 | 100 |
|
|
103 | 103 |
|
104 | 104 | /** Join User to Event */ |
105 | 105 | case (isset($eventJoinId) && is_numeric($eventJoinId)): |
106 | | - if (DEVELOPMENT) error_log(sprintf('[DEBUG] <%s:%d> Join Event: %d', __FILE__, __LINE__, $eventJoinId)); |
| 106 | + zorgDebugger::me()->debug('User joins Event: %d', [$eventJoinId]); |
107 | 107 | $redirect_url .= '&event_id='.$eventJoinId; |
108 | 108 |
|
109 | | - $sql = 'INSERT INTO events_to_user VALUES('.$user->id.', '.$eventJoinId.')'; |
110 | | - if ($db->query($sql,__FILE__, __LINE__) === false) |
111 | | - { |
| 109 | + $insertValues = ['user_id' => $user->id, 'event_id' => $eventJoinId]; |
| 110 | + if ($db->insert('events_to_user', $insertValues, __FILE__, __LINE__) === false) { |
112 | 111 | $error = 'Cannot join Event ID ' . $eventJoinId; |
113 | | - break; |
114 | 112 | } else { |
115 | | - /** Activity Eintrag auslösen */ |
116 | 113 | Activities::addActivity($user->id, 0, 'nimmt an <a href="'.$redirect_url.'">'.Events::getEventName($eventJoinId).'</a> teil.', 'ev'); |
117 | 114 | } |
118 | 115 |
|
|
121 | 118 |
|
122 | 119 | /** Unjoin User from Event */ |
123 | 120 | case (isset($eventUnjoinId) && is_numeric($eventUnjoinId)): |
124 | | - if (DEVELOPMENT) error_log(sprintf('[DEBUG] <%s:%d> Unjoin Event: %d', __FILE__, __LINE__, $eventUnjoinId)); |
| 121 | + zorgDebugger::me()->debug('User unjoins Event: %d', [$eventUnjoinId]); |
125 | 122 | $redirect_url .= '&event_id='.$eventUnjoinId; |
126 | 123 |
|
127 | | - $sql = 'DELETE FROM events_to_user WHERE user_id = '.$user->id.' AND event_id = '.$eventUnjoinId; |
128 | | - if (!$db->query($sql,__FILE__, __LINE__)) $error = 'Cannot unjoin Event ID ' . $eventUnjoinId; |
| 124 | + $sql = 'DELETE FROM events_to_user WHERE user_id=? AND event_id=?'; |
| 125 | + if (!$db->query($sql,__FILE__, __LINE__, 'Event Unjoin', [$user->id, $eventUnjoinId])) $error = 'Cannot unjoin Event ID ' . $eventUnjoinId; |
129 | 126 |
|
130 | 127 | break; |
131 | 128 |
|
132 | 129 |
|
133 | 130 | /** Post Event to Twitter */ |
134 | 131 | case ((isset($_POST['action']) && $_POST['action'] === 'tweet')): |
135 | | - if (DEVELOPMENT) error_log(sprintf('[DEBUG] <%s:%d> Tweet Event: %s', __FILE__, __LINE__, $redirect_url)); |
| 132 | + zorgDebugger::me()->debug('Tweet Event: %s', [$redirect_url]); |
136 | 133 |
|
137 | 134 | /** |
138 | 135 | * Load Twitter Class & Grab the Twitter API Keys |
|
194 | 191 | } |
195 | 192 |
|
196 | 193 | /** Redirect request */ |
197 | | -if (DEVELOPMENT) error_log(sprintf('[DEBUG] <%s:%d> Redirecting to %s', __FILE__, __LINE__, $redirect_url.rawurlencode($error))); |
198 | | -header('Location: ' . $redirect_url . ( !empty($error) ? '&error='.rawurlencode($error) : '') ); |
| 194 | +$goToUrl = $redirect_url . ( !empty($error) ? '&error='.rawurlencode($error) : ''); |
| 195 | +zorgDebugger::me()->debug('Redirecting to %s', [$goToUrl]); |
| 196 | +header('Location: ' . $goToUrl ); |
199 | 197 | exit; |
0 commit comments