YaWK  24.1
Yet another WebKit
booking.php
Go to the documentation of this file.
1 <?php
3  /**
4  * @details <b>Let users submit appointments from frontend. You can view & manage them in backend.</b>
5  * <p>The Booking Plugin is a simple but nice, clean frontend form. Users
6  * can submit appointments. The entries are managable in the backend.
7  * Perfect for any kind of appointment requests. E.g. if you are a Hairdresser
8  * your customers can submit their wished dates. If you are a musician, this is perfect
9  * to do your bookings. You can manage them in the Backend and view all bookings in a
10  * sortable, clean table. You can set the Appointment to "done", rate it, count how many
11  * times you've met that user, how many bookings were successful and many, many more.</p>
12  *
13  * <p><i>Class covers both, backend & frontend functionality.
14  * See Methods Summary for Details!</i></p>
15  *
16  * @author Daniel Retzl <[email protected]>
17  * @copyright 2009-2016 Daniel Retzl
18  * @version 1.0.0
19  * @brief Booking Plugin is perfect if you want to let your customers submit
20  * appointments from frontend. Entries can be viewed, setup and monitored in the backend.
21  */
22  class booking
23  {
24  /** @var string language */
25  public $lang;
26  /** * @param string booking day */
27  public $day;
28  /** * @param string booking month */
29  public $month;
30  /** * @param string booking time */
31  public $time;
32  /** * @param string booking ID */
33  public $id;
34  /** * @param string user ID who booked */
35  public $uid;
36  /** * @param string group ID */
37  public $gid;
38  /** * @param string date when the booking was created */
39  public $date_created;
40  /** * @param int 0|1 is this a confirmed booking? */
42  /** * @param string booking name */
43  public $name;
44  /** * @param string booking email address */
45  public $email;
46  /** * @param string booking phone number */
47  public $phone;
48  /** * @param string booking text */
49  public $text;
50  /** * @param int 0|1 was the booking successful? */
51  public $success;
52  /** * @param int internal voting for this booking (school grades) */
53  public $grade;
54  /** * @param int how often has this client (email adress) successful booked? */
55  public $visits;
56  /** * @param string internal comment for this booking (max 255 chars) */
57  public $comment;
58  /** * @param string IP Address of the user who booked */
59  public $ip;
60  /** * @param string users hostname */
61  public $hostname;
62  /** * @param int how much is this booking worth? */
63  public $income;
64  /** * @param int 0|1 is this booking confirmed? */
65  public $confirmed;
66  /** * @param string user booking time */
68  /** * @param string user booking month */
70  /** * @param string user booking day */
71  public $datewish_day;
72  /** * @param string user booking year */
74  /** * @param string user booking date wish (full) */
75  public $date_wish;
76  /** * @param string alternative user booking time */
78  /** * @param string alternative user booking month */
80  /** * @param string alternative user booking day */
82  /** * @param string alternative user booking year */
84  /** * @param string alternative user booking date (full) */
86  /** * @param string user booking message */
87  public $message;
88  /** * @param string the complete useragent */
89  public $useragent;
90  /** * @param string referer: where did the user came from? (last url) */
91  public $referer;
92  /** * @param int expected money from outstanding bookings */
94  /** * @param int 0|1 is this booking set to outdated? */
95  public $outdated;
96  /** * @param int 0|1 is this user (email adress) banned? */
97  public $ban;
98  /** * @param int 0|1 is this user invited? */
99  public $invited;
100 
101  /**
102  * @brief count and return how many successful booking an email adress made
103  * @param object $db database
104  * @param string $email email adress you wish to check
105  * @return int|bool
106  */
107  public function countVisits($db, $email)
108  { /** @var $db \YAWK\db */
109  $i = 0;
110  if ($res = $db->query("SELECT id FROM {plugin_booking}
111  WHERE email = '".$email."' AND success = '1'")) {
112  while ($row = mysqli_fetch_array($res)){
113  $i++;
114  }
115  return $i;
116  }
117  else {
118  return false;
119  }
120  }
121 
122  /**
123  * @brief get statistics from all bookings
124  * @param array $lang language array
125  * @param object $db database
126  */
127  public function getStats($db, $lang)
128  { /** @var $db \YAWK\db */
129  $income_sum = 0;
130  $success_sum = 0;
131  $grade_sum = 0;
132  $i_dates = 0;
133  $outstanding_sum = 0;
134  $confirmed_outstanding_sum = 0;
135  $i_date_waiting_sum = 0;
136  $i_date_fix_sum = 0;
137  $i_date_outdated = 0;
138  $i_date_success = 0;
139  if ($res = $db->query("SELECT success, income, grade, ban, confirmed, outdated FROM {plugin_booking}")) {
140  while ($row = mysqli_fetch_assoc($res)) {
141  $this->success = $row['success'];
142  $this->income = $row['income'];
143  $this->grade = $row['grade'];
144  $this->ban = $row['ban'];
145  $this->confirmed = $row['confirmed'];
146  $this->outdated = $row['outdated'];
147 
148  $i_dates++;
149  $success_sum += $this->success;
150  $grade_sum += $this->grade;
151 
152  // add NOT confirmed money
153  if ($this->confirmed === '0' && $this->success !== '1' && $this->outdated !== '1'){
155  $i_date_waiting_sum++;
156  }
157  // add confirmed money
158  if ($this->confirmed === '1' && $this->success !== '1' && $this->outdated !== '1'){
159  $confirmed_outstanding_sum += $this->income;
160  $i_date_fix_sum++;
161  }
162  // add outdated data
163  if ($this->outdated === '1'){
164  $i_date_outdated++;
165  }
166  // add succeeded money
167  if ($this->success === '1'){
168  $income_sum += $this->income;
169  $i_date_success++;
170  }
171  }
172  // calculate average grade
173  if (isset($this->grade)) {
174  if (isset($i_date_success) && (!empty($i_date_success)))
175  {
176  $avgGrade = $grade_sum / $i_date_success;
177  }
178  else
179  {
180  $avgGrade = 0;
181  }
182  $avgGrade = substr("$avgGrade", 0, 3);
183  } else { $avgGrade = 0; }
184 
185 
186  echo "<ul class='list-group'>
187  <li class='list-group-item'><h4><i class='fa fa-money'></i> &nbsp;$lang[BOOKING_STATS_OUTSTANDING]&nbsp; <b class='text-green'>&euro; ".$confirmed_outstanding_sum.",-</b></li></h4>
188  <li class='list-group-item'><h4><i class='fa fa-money'></i> &nbsp;$lang[BOOKING_STATS_CONFIRMED]&nbsp; <b class='text-orange'>&euro; ".$outstanding_sum.",- </b></li></h4>
189  <li class='list-group-item'><h4><i class='fa fa-money'></i> &nbsp;$lang[BOOKING_STATS_EARNED]&nbsp; <b class='text-green'>&euro; ".$income_sum.",- </b></li></h4>
190  <li class='list-group-item'><h4><i class='fa fa-calendar'></i> &nbsp;$lang[OVERALL] <b>".$i_dates."</b> $lang[BOOKING_INQUIRES] <b class='text-green'>".$success_sum."</b> $lang[BOOKINGS] $lang[SUCCESSFUL]. <b class='text-orange'>".$i_date_waiting_sum."</b> $lang[NOT_CONFIRMED], <b class='text-green'>".$i_date_fix_sum."</b> $lang[CONFIRMED]. <b>".$i_date_outdated."</b> $lang[OUTDATED].</li></h4>
191  <li class='list-group-item'><h4><i class='fa fa-calendar'></i> &nbsp;$lang[BOOKING_AVG_VOTING] <b>".$avgGrade."</b></li></h4>
192  </ul>";
193 
194  }
195  }
196 
197  /**
198  * @brief set a booking to banned (to see clearly: nope, we dont want this)
199  * this is useful to detect and handle fake bookings, fun bookings, nonsense entries...
200  * @param object $db database
201  * @param int $id the booking ID to ban
202  * @param string $email the email address you wish to ban
203  * @return bool
204  */
205  function toggleBan($db, $id, $email)
206  { /** @var $db \YAWK\db */
207  if ($res = $db->query("SELECT ban FROM {plugin_booking}
208  WHERE id = '".$id."'"))
209  if ($row = mysqli_fetch_row($res))
210  { // prepare vars
211  $ban = $row[0];
212  if ($ban === '0') { $ban = 1; } else { $ban = 0; }
213  }
214  // toggle ban status
215  if (!$res = $db->query("UPDATE {plugin_booking}
216  SET ban = '" . $ban . "'
217  WHERE email = '".$email."'"))
218  {
219  print \YAWK\alert::draw("danger", "Error", "Ban status could not be toggled.", "",2000);
220  }
221  return true;
222  }
223 
224  /**
225  * @brief toggle a booking to outdated.
226  * @param object $db database
227  * @param int $id the booking id to toggle
228  * @return bool
229  */
230  function toggleOutdated($db, $id)
231  { /** @var $db \YAWK\db */
232  if ($res = $db->query("SELECT outdated FROM {plugin_booking}
233  WHERE id = '".$id."'"))
234  if ($row = mysqli_fetch_row($res))
235  {
236  $this->outdated = $row[0];
237  }
238  if ($this->outdated === '0') { $this->outdated = 1; } else { $this->outdated = 0; }
239  // toggle outdated status
240  if (!$res = $db->query("UPDATE {plugin_booking}
241  SET outdated = '" . $this->outdated . "'
242  WHERE id = '".$id."'"))
243  {
244  print \YAWK\alert::draw("danger", "Error", "Outdated status could not be toggled.","",2000);
245  }
246  return true;
247  }
248 
249  /**
250  * @brief if you like, you can invite users to a private member area. allow users to register and become members
251  * after they did a successful booking. Whatever you put in your members area (eg. vip club) is on your own.
252  * @param object $db database
253  * @param int $id booking ID (unused, yet)
254  * @param string $email booking email address -> the user you wish to invite
255  * @param string $name the name that the user have set in the course of booking.
256  * @return bool
257  */
258  function inviteUser($db, $id, $email, $name)
259  { /** @var $db \YAWK\db */
260  // get admin email adress from db
261  $admin_email = \YAWK\settings::getSetting($db, "admin_email");
262  // set invite status in user db
263  if ($res = $db->query("UPDATE {plugin_booking} SET invited = '1' WHERE email='".$email."'"))
264  { // send email to invite user...
266  $from = $admin_email;
267  $to = $email;
268  $cc = $admin_email;
269  $subject = "VIP Club Invitation";
270  $msg = "Hello $name!\n
271  Your Access to our VIP Club is now activated!
272  Please visit the following URL in your Browser:
273 
274  ".$host."/welcome.html
275 
276  There you can register with your Emailadress $to.
277  Have fun!
278  Regards,
279  ".$host."";
280  \YAWK\email::sendEmail($from, $to, "", $subject, $msg);
281  \YAWK\email::sendEmail($to, $from, "", $subject, $msg);
282  echo \YAWK\alert::draw("success", "Success", "Invitation Email sent to $to","index.php?plugin=booking","1800");
283  }
284  else {
285  echo \YAWK\alert::draw("danger", "Error", "Could not invite user! Status cannot be changed. No email sent.","","3800");
286  }
287  return false;
288  }
289 
290  /**
291  * @brief draw (output) html of the frontend form. This is displayed to the user. He will use to place a booking
292  * @return string
293  */
294  public function getFrontendForm($config, $lang)
295  {
296  /*
297  echo "<pre>";
298  echo "<h1>THIS object:</h1>";
299  print_r($this);
300  echo "<hr>";
301  echo "<h2>config object:</h2>";
302  print_r($config);
303  echo "</pre>";
304  */
305 
306  // init form html code markup variable
307  $html = "";
308 
309  $html .= "
310 <form class=\"form\" id=\"form\" method=\"post\" action=\"booking.html\">
311  <div class=\"row\">
312  <div class=\"col-md-4\">";
313 
314  // NAME
315  if ($config->bookingContactName !== "false")
316  {
317  if ($config->bookingContactName === "required")
318  { $requiredMarkup = "*"; }
319  else { $requiredMarkup = ""; }
320 
321  $html .= "
322  <label for=\"name\">Name".$requiredMarkup."</label>
323  <input type=\"text\" name=\"name\" id=\"name\" class=\"form-control\" placeholder=\"Your name\">
324  <br>";
325  }
326 
327  // EMAIL
328  if ($config->bookingEmail !== "false")
329  {
330  if ($config->bookingEmail === "required")
331  { $requiredMarkup = "*"; }
332  else { $requiredMarkup = ""; }
333 
334  $html .= "
335  <label for=\"email\">Email".$requiredMarkup."</label>
336  <input type=\"text\" name=\"email\" id=\"email\" class=\"form-control\" placeholder=\"[email protected]\">
337  <br>";
338  }
339 
340  // PHONE
341  if ($config->bookingPhone !== "false")
342  {
343  if ($config->bookingPhone === "required")
344  { $requiredMarkup = "*"; }
345  else { $requiredMarkup = ""; }
346 
347  $html .= "
348  <label for=\"phone\">Phone".$requiredMarkup."</label>
349  <input type=\"text\" name=\"phone\" id=\"phone\" class=\"form-control\" placeholder=\"+00 1234 / 1234567\">
350  <br>";
351  }
352  $html .= "
353 <br><br>
354  </div>
355  <div class=\"col-md-8\">
356  <div class=\"row\">
357  <div class=\"col-md-6\">
358  <!-- left -->";
359 
360  // EVENT DATE TIME
361  if ($config->bookingEventDatetime !== "false")
362  {
363  if ($config->bookingEventDatetime === "required")
364  { $requiredMarkup = "*"; }
365  else { $requiredMarkup = ""; }
366 
367  $html .= "
368  <label for=\"eventDateTime\">Event Date + Time".$requiredMarkup."</label>
369  <input type=\"text\" name=\"eventDateTime\" id=\"eventDateTime\" class=\"form-control\" placeholder=\"select Date\">
370  <br>";
371  }
372 
373  $html .= "</div>
374  <div class=\"col-md-6\">
375  <!-- right -->";
376 
377  // EVENT DATE TIME
378  if ($config->bookingBand !== "false")
379  {
380  if ($config->bookingBand === "required")
381  { $requiredMarkup = "*"; }
382  else { $requiredMarkup = ""; }
383 
384  $html .= "
385  <label for=\"band\">Band".$requiredMarkup."</label>
386  <select name=\"band\" id=\"band\" class=\"form-control\">
387  <option value=\"\">bitte ausw&auml;hlen</option>
388  <option value=\"Duo: Stephan Heiner &amp; B&ouml;rns Funkyfingers\">Duo: Stephan Heiner &amp; B&ouml;rns Funkyfingers</option>
389  <option value=\"Trio: BSB (B&ouml;rns, Stephan, Bertl)\">Trio: BSB (B&ouml;rns, Stephan, Bertl)</option>
390  <option value=\"Tommy Lee &amp; Glacestrizzis\">Tommy Lee &amp; Glacestrizzis</option>
391  <option value=\"WiR &amp; Jetzt\">WiR &amp; Jetzt</option>
392  </select>
393  <br>";
394  }
395 
396  // EVENT TYPE
397  if ($config->bookingLocationType !== "false")
398  {
399  if ($config->bookingLocationType === "required")
400  { $requiredMarkup = "*"; }
401  else { $requiredMarkup = ""; }
402 
403  $html .= "
404  <label for=\"locationType\">Art der Veranstaltung".$requiredMarkup."</label>
405  <select name=\"locationType\" id=\"locationType\" class=\"form-control\">
406  <option value=\"\">bitte ausw&auml;hlen</option>
407  <option value=\"Hochzeit\">Hochzeit</option>
408  <option value=\"Geburtstagsparty\">Geburtstagsparty</option>
409  <option value=\"Private Veranstaltung\">Private Veranstaltung</option>
410  <option value=\"Firmen Event\">Firmen Event</option>
411  <option value=\"Weihnachtsfeier\">Weihnachtsfeier</option>
412  <option value=\"Gro&szlig;veranstaltung\">Gro&szlig;veranstaltung</option>
413  <option value=\"Andere\">Andere</option>
414  </select>
415  <br>";
416  }
417 
418  // LOCATION
419  if ($config->bookingLocation !== "false")
420  {
421  if ($config->bookingLocation === "required")
422  { $requiredMarkup = "*"; }
423  else { $requiredMarkup = ""; }
424 
425  $html .= "
426  <label for=\"location\">Location".$requiredMarkup."</label>
427  <select name=\"location\" id=\"location\" class=\"form-control\">
428  <option value=\"\">bitte ausw&auml;hlen</option>
429  <option value=\"Indoor\">Indoor</option>
430  <option value=\"Outdoor\">Outdoor</option>
431  </select>
432  <br>";
433  }
434 
435  // LOCATION
436  if ($config->bookingCrowdAmount !== "false")
437  {
438  if ($config->bookingCrowdAmount === "required")
439  { $requiredMarkup = "*"; }
440  else { $requiredMarkup = ""; }
441 
442  $html .= "
443  <label for=\"crowdAmount\">Gr&ouml;&szlig;e".$requiredMarkup."</label>
444  <select name=\"crowdAmount\" id=\"crowdAmount\" class=\"form-control\">
445  <option value=\"\">bitte ausw&auml;hlen</option>
446  <option value=\"0 - 50\">0 - 50 Personen</option>
447  <option value=\"50 - 100\">50 - 100 Personen</option>
448  <option value=\"100 - 200\">100 - 200 Personen</option>
449  <option value=\"300 - 500\">300 - 500 Personen</option>
450  <option value=\"500 - 1000\">500 - 1000 Personen</option>
451  <option value=\"> 1000\">> 1000 Personen</option>
452  </select>
453  <br>";
454  }
455 
456  $html .="</div>
457  </div>";
458 
459  // MESSAGE
460  if ($config->bookingMessage !== "false")
461  {
462  if ($config->bookingMessage === "required")
463  { $requiredMarkup = "*"; }
464  else { $requiredMarkup = ""; }
465 
466  $html .= "
467  <label for=\"message\">Message".$requiredMarkup."</label>
468  <textarea name=\"mesage\" id=\"message\" class=\"form-control\" rows=\"8\"></textarea>
469  <br>";
470  }
471 
472  $html .="<label for=\"mailCopy\">Send a copy of this message to myself. &nbsp;
473  <input type=\"checkbox\" name=\"mailCopy\" value=\"1\" checked aria-checked=\"true\" id=\"mailCopy\"></label>
474  <button type=\"submit\" class=\"btn btn-success pull-right\" style=\"margin-top:1%;\" contenteditable=\"false\"><i class=\"fa fa-envelope-o\"></i> &nbsp;Send Message</button>
475  <input type=\"hidden\" name=\"sent\" value=\"1\">";
476 
477 
478  $html .= "</div>
479  </div>
480  </form>";
481  return $html;
482  } /* EOFunction getTable */
483 
484  /**
485  * @brief get data and draw (output) html backend table of all bookings
486  * @param object $db database
487  * @param int $i sql limitation number
488  * @param string $field database field
489  * @param string $value value to get
490  * @return string
491  */
492  public function getBackendTable($db, $i, $field, $value)
493  { /** @var $db \YAWK\db */
494  global $lang;
495  if (isset($field) && isset($value))
496  { // user clicked on email or ip adress
497  if (!empty($field) && !empty($value))
498  { // select data
499  $sql = "SELECT * FROM {plugin_booking} WHERE $field = '".$value."' ORDER by $field DESC";
500  }
501  else
502  { // show default table: all
503  $sql = "SELECT * FROM {plugin_booking} ORDER by date_created DESC $i";
504  }
505  }
506  else
507  { // show default table: all
508  $sql = "SELECT * FROM {plugin_booking} ORDER by date_created DESC $i";
509  }
510 
511  if (!$res = $db->query($sql)) {
512  echo "<br><br>";
513  print \YAWK\alert::draw("warning", "Could not get booking table data...", "Seems like there is a problem with the database.","",3800);
514  exit;
515  } else {
516  /* TABLE HEADER */
517  $html = "";
518  /* TABLE CONTENT */
519  while ($row = mysqli_fetch_assoc($res)) {
520  $this->id = $row['id'];
521  $this->uid = $row['uid'];
522  $this->gid = $row['gid'];
523  $this->date_created = $row['date_created'];
524  $this->date_wish = $row['date_wish'];
525  $this->date_alternative = $row['date_alternative'];
526  $this->confirmed = $row['confirmed'];
527  $this->name = $row['name'];
528  $this->email = $row['email'];
529  $this->phone = $row['phone'];
530  $this->text = $row['text'];
531  $this->success = $row['success'];
532  $this->grade = $row['grade'];
533  $this->visits = $row['visits'];
534  $this->comment = $row['comment'];
535  $this->ip = $row['ip'];
536  $this->useragent = $row['useragent'];
537  $this->ban = $row['ban'];
538  $this->outdated = $row['outdated'];
539  $this->cut = $row['cut'];
540  $this->invited = $row['invited'];
541 
542  /* date string to array function */
543  $year = date('Y');
544  $splitDate_created = \YAWK\sys::splitDateShort($this->date_created);
545  $splitDate_wish = \YAWK\sys::splitDateShort($this->date_wish);
546  $splitDate_alternative = \YAWK\sys::splitDateShort($this->date_alternative);
547  // date created
548  $year_created = $splitDate_created['year'];
549  $day_created = $splitDate_created['day'];
550  $month_created = $splitDate_created['month'];
551  $time_created = $splitDate_created['time'];
552  // date wish
553  $year_wish = $splitDate_wish['year'];
554  $day_wish = $splitDate_wish['day'];
555  $month_wish = $splitDate_wish['month'];
556  $time_wish = $splitDate_wish['time'];
557  // date alternative
558  $year_alt = $splitDate_alternative['year'];
559  $day_alt = $splitDate_alternative['day'];
560  $month_alt = $splitDate_alternative['month'];
561  $time_alt = $splitDate_alternative['time'];
562  // make dates pretty
563  $prettydate_created = "$day_created.$month_created $year, $time_created";
564  $prettydate_wish = "$day_wish.$month_wish $time_wish";
565  $prettydate_alternative = "$day_alt.$month_alt $time_alt";
566 
567  // if alternative is zero, make it empty for a better tbl view experience
568  if ($prettydate_alternative === "0.00. 00:00"){
569  $prettydate_alternative = '';
570  }
571  // check confirmed status
572  if ($this->confirmed === '1') {
573  $pub = "success";
574  $pubtext = "<i class=\"fa fa-check\"> 2 confirmed</i>";
575  }
576  else {
577  $pub = "warning";
578  $pubtext = "<i class=\"fa fa-times\"> 1 not confirmed</i>";
579  }
580  if ($this->success === '1'){
581  $pub = "info";
582  $pubtext = "<i class=\"fa fa-check-circle-o\" title='erledigt'> 3 successful</i>";
583  }
584  if ($this->ban === '1'){
585  $pub = "danger";
586  $pubtext = "<i class=\"fa fa-warning\" title='careful'> 4 careful!</i>";
587  }
588  if ($this->outdated === '1'){
589  $pub = "inverse";
590  $pubtext = "<i title='Outdated'> 5 outdated</i>";
591  $msgstyle = "style=\"color:#707070;\"";
592  } else { $msgstyle = ""; }
593  // if visits are bigger than zero, change color
594  if ($this->visits > '0') {
595  $color = "text-info";
596  $visitHtml = "<span class=\"label label-success\">$this->visits</span>";
597  } else {
598  $color = "text-muted";
599  $visitHtml = "<span class=\"label label-danger\">$this->visits</span>";
600  }
601  $html .= "<tr>
602  <td class=\"text-center\">
603  <a title=\"toggle&nbsp;status\" href=\"index.php?plugin=booking&pluginpage=booking-toggle&toggle=1&id=" . $this->id . "\">
604  <span class=\"label label-$pub\">$pubtext</span></a></td>
605  <td><small>$prettydate_created</small></td>
606  <td><a href=\"index.php?plugin=booking&pluginpage=booking-edit&id=" . $this->id . "\"><div class=\"$color\">$this->name</a><p class=\"small\">
607  <a href=\"index.php?plugin=booking&pluginpage=booking&email=$this->email\" target=\"_blank\">$this->email</a><br>
608  <a href=\"index.php?plugin=booking&pluginpage=booking&phone=$this->phone\" target=\"_blank\">$this->phone</a></p>
609  </div></td>
610  <td class=\"text-center\">$prettydate_wish<p style=\"color:#707070;\">$prettydate_alternative</p></td>
611  <td ".$msgstyle.">$this->text</td>
612  <td class=\"text-center\">".self::countVisits($db, $this->email)."</td>
613  <td class=\"text-center\"><a href=\"index.php?plugin=booking&pluginpage=booking&ip=$this->ip\" target=\"_blank\">$this->ip</a></td>
614  <td class=\"text-center\">
615  <a class=\"fa fa-hourglass-end\" title=\"".$lang['OUTDATED']."\" href=\"index.php?plugin=booking&pluginpage=booking-toggle&outdated=1&id=".$this->id."\"></a>&nbsp;
616  <a class=\"fa fa-ban\" title=\"".$lang['BAN']."\" href=\"index.php?plugin=booking&pluginpage=booking-toggle&ban=1&id=".$this->id."\"></a>&nbsp;
617  <a class=\"fa fa-edit\" title=\"" . $lang['EDIT'] . "\" href=\"index.php?plugin=booking&pluginpage=booking-edit&id=" . $this->id . "\"></a>&nbsp;
618  <a class=\"fa fa-trash-o\" role=\"dialog\" data-confirm=\"Den Termin &laquo;" . $this->name . " @ " . $this->date_wish . "&raquo; wirklich l&ouml;schen?\"
619  title=\"" . $lang['DELETE'] . "\" href=\"index.php?plugin=booking&pluginpage=booking&id=" . $this->id . "&delete=1\">
620  </a>
621  </td>
622  </tr>";
623 
624  }
625  return $html;
626  }
627  } /* EOFunction getAdminTable */
628 
629  /**
630  * @brief save (update) booking data
631  * @param object $db database
632  * @return bool
633  */
634  function save($db)
635  { /** @var $db \YAWK\db */
636  if (!$res = $db->query("UPDATE {plugin_booking} SET
637  income = '".$this->income."',
638  grade = '".$this->grade."',
639  comment = '".$this->comment."',
640  date_wish = '".$this->date_wish."',
641  date_alternative = '".$this->date_alternative."',
642  comment = '".$this->comment."',
643  confirmed = '1'
644  WHERE id = '".$this->id."' "))
645  {
646  print \YAWK\alert::draw("danger", "Error", "Unable to save booking details.", "",3800);
647  }
648  return true;
649  }
650 
651  /**
652  * @brief toggle a booking online or offline
653  * @param object $db database
654  * @param int $id booking ID to toggle
655  * @param int $confirmed 0|1 confirmed status
656  * @param int $success 0|1 success status
657  * @return bool
658  */
659  function toggleOffline($db, $id, $confirmed, $success)
660  { /** @var $db \YAWK\db */
661  // TOGGLE GIG STATUS
662  if (!$res = $db->query("UPDATE {plugin_booking}
663  SET confirmed = '" . $confirmed . "',
664  success = '".$success."'
665  WHERE id = '" . $id . "'"))
666  {
667  print \YAWK\alert::draw("danger", "Error", "Booking status could not be toggled.","",3800);
668  }
669  return true;
670  } /* EOFunction toggleOffline */
671 
672 
673  /**
674  * @brief load booking data into object properties
675  * @param object $db database
676  * @param string $id the booking id to load
677  */
678  function loadProperties($db, $id)
679  { /** @var $db \YAWK\db */
680  $res = $db->query("SELECT * FROM {plugin_booking} WHERE id = '" . $id . "'");
681  if ($row = mysqli_fetch_assoc($res)) {
682  $this->id = $row['id'];
683  $this->uid = $row['uid'];
684  $this->gid = $row['gid'];
685  $this->date_created = $row['date_created'];
686  $this->date_wish = $row['date_wish'];
687  $this->date_alternative = $row['date_alternative'];
688  $this->confirmed = $row['confirmed'];
689  $this->todo = $row['todo'];
690  $this->name = $row['name'];
691  $this->email = $row['email'];
692  $this->phone = $row['phone'];
693  $this->text = $row['text'];
694  $this->success = $row['success'];
695  $this->income = $row['income'];
696  $this->grade = $row['grade'];
697  $this->visits = $row['visits'];
698  $this->comment = $row['comment'];
699  $this->ip = $row['ip'];
700  $this->useragent = $row['useragent'];
701  $this->ban = $row['ban'];
702  $this->outdated = $row['outdated'];
703  $this->referer = $row['referer'];
704  $this->cut = $row['cut'];
705  $this->invited = $row['invited'];
706  }
707  } /* EOFunction loadProperties */
708 
709  /**
710  * @brief get highest ID from booking table
711  * @param object $db database
712  * @return string|bool the max ID or false
713  */
714  static function getMaxId($db)
715  { /** @var $db \YAWK\db */
716  $booking = new booking();
717  $res = $db->query("SELECT MAX(id) FROM {plugin_booking}");
718  if ($row = mysqli_fetch_array($res)) {
719  return $booking->maxID = $row[0];
720  }
721  else
722  {
723  return false;
724  }
725  }
726 
727  /**
728  * @brief return any booking property
729  * @param object $db database
730  * @param int $id affected booking ID
731  * @param string $property the property to get
732  * @return string|bool the selected booking property or false
733  */
734  function getProperty($db, $id, $property)
735  { /** @var $db \YAWK\db */
736  $res = $db->query("SELECT " . $property . " FROM {plugin_booking}
737  WHERE id = '" . $id . "'");
738  if ($row = mysqli_fetch_row($res)) {
739  return $row[0];
740  }
741  else
742  {
743  return false;
744  }
745  }
746 
747 
748  /**
749  * @brief delete a single booking
750  * @param object $db database
751  * @param int $id the booking ID to delete
752  * @return bool
753  */
754  function delete($db, $id)
755  { /** @var $db \YAWK\db */
756  if (!$res = $db->query("DELETE FROM {plugin_booking} WHERE id = '" . $id . "'")) {
757  return false;
758  }
759  return true;
760  } /* EOFunction delete */
761 
762 
763  /**
764  * @brief create a new booking
765  * @param object $db database
766  */
767  function create($db)
768  { /** @var $db \YAWK\db */
769  if (!isset($_POST['todo'])){
770  $_POST['todo'] = 0;
771  }
772  // if user is logged in, build booking data from session vars (name, userid, groupid)
773  if (isset($_SESSION['username']) && (isset($_SESSION['uid']) && (isset($_SESSION['gid'])))){
774  $this->name = $_SESSION['username'];
775  $this->uid = $_SESSION['uid'];
776  $this->gid = $_SESSION['gid'];
777  $this->email = $db->quote($_POST['email']);
778  $this->phone = $db->quote($_POST['phone']);
779  $this->todo = $db->quote($_POST['todo']);
780  if (isset($_POST['datewish-month'])){
781  $this->datewish_month = $db->quote($_POST['datewish-month']);
782  }
783  else
784  {
785  $this->datewish_month = '';
786  }
787  if (isset($_POST['datewish-day'])){
788  $this->datewish_day = $db->quote($_POST['datewish-day']);
789  }
790  else
791  {
792  $this->datewish_day = '';
793  }
794  if (isset($_POST['datewish-time'])){
795  $this->datewish_time = $db->quote($_POST['datewish-time']);
796  }
797  else
798  {
799  $this->datewish_time = '';
800  }
801  if (isset($_POST['alternative-month'])){
802  $this->alternative_month = $db->quote($_POST['alternative-month']);
803  }
804  else
805  {
806  $this->alternative_month = '';
807  }
808  if (isset($_POST['alternative-day'])){
809  $this->alternative_day = $db->quote($_POST['alternative-day']);
810  }
811  else
812  {
813  $this->alternative_day = '';
814  }
815  if (isset($_POST['alternative-time'])){
816  $this->alternative_time = $db->quote($_POST['alternative-time']);
817  }
818  else
819  {
820  $this->alternative_time = '';
821  }
822  $this->message = $db->quote($_POST['message']);
823  }
824  else {
825  // else get the POST vars escaped
826  $this->name = $db->quote($_POST['name']);
827  $this->email = $db->quote($_POST['email']);
828  $this->phone = $db->quote($_POST['phone']);
829  $this->todo = $db->quote($_POST['todo']);
830  if (isset($_POST['datewish-month'])){
831  $this->datewish_month = $db->quote($_POST['datewish-month']);
832  }
833  else
834  {
835  $this->datewish_month = '';
836  }
837  if (isset($_POST['datewish-day'])){
838  $this->datewish_day = $db->quote($_POST['datewish-day']);
839  }
840  else
841  {
842  $this->datewish_day = '';
843  }
844  if (isset($_POST['datewish-time'])){
845  $this->datewish_time = $db->quote($_POST['datewish-time']);
846  }
847  else
848  {
849  $this->datewish_time = '';
850  }
851  if (isset($_POST['alternative-month'])){
852  $this->alternative_month = $db->quote($_POST['alternative-month']);
853  }
854  else
855  {
856  $this->alternative_month = '';
857  }
858  if (isset($_POST['alternative-day'])){
859  $this->alternative_day = $db->quote($_POST['alternative-day']);
860  }
861  else
862  {
863  $this->alternative_day = '';
864  }
865  if (isset($_POST['alternative-time'])){
866  $this->alternative_time = $db->quote($_POST['alternative-time']);
867  }
868  else
869  {
870  $this->alternative_time = '';
871  }
872  $this->message = $db->quote($_POST['message']);
873  }
874 
875  /* generate ID manually to prevent id holes */
876  $res_blog = $db->query("SELECT MAX(id) FROM {plugin_booking}");
877  $row = mysqli_fetch_row($res_blog);
878  if (!isset($row[0])){
879  $this->id = 1;
880  } else {
881  $this->id = $row[0] + 1;
882  }
883  // switch entities
884  $this->name = htmlentities($this->name);
885  $this->email = htmlentities($this->email);
886  $this->phone = htmlentities($this->phone);
887  $this->message = htmlentities($this->message);
888  // strip tags
889  $this->name = strip_tags($this->name);
890  $this->email = strip_tags($this->email);
891  $this->phone = strip_tags($this->phone);
892  $this->message = strip_tags($this->message);
893  // trim tags
894  $this->name = trim($this->name);
895  $this->email = trim($this->email);
896  $this->phone = trim($this->phone);
897  $this->message = trim($this->message);
898 
899  // nl2br message
900  $this->message = nl2br($this->message);
901 
902  // set income automatically based on selected todofield
903 
904  // build datetime string out of form vars
905  $year = date('Y');
906  $this->date_wish = "$year-$this->datewish_month-$this->datewish_day $this->datewish_time:00";
907  $this->date_alternative = "$year-$this->alternative_month-$this->alternative_day $this->alternative_time:00";
908  // set current datetime for field "date_created"
909  $this->date_created = date("Y-m-d G:i:s");
910 
911  // get user data
912  $this->ip = $_SERVER['REMOTE_ADDR'];
913  $this->useragent = $_SERVER['HTTP_USER_AGENT'];
914  $this->referer = $_SERVER['HTTP_REFERER'];
915 
916  // insert into db
917  $res = $db->query("INSERT INTO {plugin_booking}
918  (id, uid, gid, date_created, date_wish, date_alternative, name, email, phone, text, ip, useragent, referer)
919  VALUES('" . $this->id . "',
920  '" . $this->uid . "',
921  '" . $this->gid . "',
922  '" . $this->date_created . "',
923  '" . $this->date_wish . "',
924  '" . $this->date_alternative . "',
925  '" . $this->name . "',
926  '" . $this->email . "',
927  '" . $this->phone . "',
928  '" . $this->message . "',
929  '" . $this->ip . "',
930  '" . $this->useragent . "',
931  '" . $this->referer . "')");
932 
933  // prepare email data
934  $email_message = "Danke ".$this->name."! Du hast mir am ".$this->date_created." einen Terminvorschlag geschickt!\n
935  Ich werde mich so bald als moeglich bei Dir melden!\n\r
936  Wunschtermin: ".$this->date_wish."\n
937  Alternative : ".$this->date_alternative."\n
938  Email : ".$this->email."\n
939  Telefon : ".$this->phone."\n
940  Nachricht : ".$this->message."\n";
941 
942  $adminEmail = \YAWK\settings::getSetting($db, "admin_email");
943 
944  if (isset($_POST['mailCopy']) && ($_POST['mailCopy'] == '1')){
945  // send email to user AND admin
946  $sent_admin = \YAWK\email::sendEmail("$this->email", "$adminEmail", "", "Danke fuer Deinen Terminvorschlag!", "$email_message");
947  $sent_user = \YAWK\email::sendEmail("$adminEmail", "$this->email", "", "Danke fuer Deinen Terminvorschlag!", "$email_message");
948  $sent = '';
949  } else {
950  // send email to admin only
951  $sent = \YAWK\email::sendEmail("$this->email", "$adminEmail", "", "Du hast einen neuen Terminvorschlag!", "$email_message");
952  $sent_admin = '';
953  $sent_user = '';
954  }
955 
956  if ($res && $sent_admin && $sent_user || $sent) {
957  \YAWK\alert::draw("success", "Erfolg", "Vielen Dank f�r Deinen Terminvorschlag! Ich werde mich so bald als m&ouml;glich bei Dir melden!","",4200);
958  } else {
959  \YAWK\alert::draw("warning", "Fehler", "Es tut mir leid, der Terminvorschlag konnte nicht abgeschickt werden! Bitte versuche es sp&auml;ter nochmal. Danke!","",4200);
960  }
961 
962  }
963  }
964 } /* CLASS booking */
$blog gid
Definition: blog-setup.php:139
Booking Plugin is perfect if you want to let your customers submit appointments from frontend....
Definition: booking.php:23
getFrontendForm($config, $lang)
draw (output) html of the frontend form. This is displayed to the user. He will use to place a bookin...
Definition: booking.php:294
static draw($type, $title, $text, $redirect, $delay)
Definition: alert.php:30
static sendEmail($email_from, $email_to, $email_cc, $email_subject, $email_message)
send an email
Definition: email.php:31
static getSetting($db, $property)
Get and return value for property from settings database.
Definition: settings.php:470
static splitDateShort($date)
split a date to month, day, year and time this is the same as splitDate() but keep the months short
Definition: sys.php:1572
exit
$sql
Definition: message-new.php:32
$host
Definition: page-edit.php:65
$value
Definition: booking.php:10
$booking
Definition: booking.php:8
$field
Definition: booking.php:9
$template name
print $tourdates date
$i