YaWK  24.1
Yet another WebKit
tourdates.php
Go to the documentation of this file.
1 <?php
3  /**
4  * <b>Manage & render a list for any kind of events or band tourdates</b>
5  * <p>Tour Dates Plugin hands you a simple but nice, clean bootstraped and
6  * sortable Data Table. You can use it to present Tour Dates or any
7  * other different kind of Events. Perfect for a Band Website or if
8  * you need to manage and display a tabluar list with fields like
9  * date, time, artist, venue & facebook event url. Data can be easily
10  * managed, added, edited, copied & deleted in the admin backend.</p>
11  * <p><i>Class covers both, backend & frontend functionality.
12  * See Methods Summary for Details!</i></p>
13  *
14  * @author Daniel Retzl <[email protected]>
15  * @copyright 2009-2015 Daniel Retzl
16  * @version 1.0.0
17  * @brief Tour Dates Plugin hands you a simple but nice, clean
18  * bootstraped & sortable Data Table. You can use it to present Tour
19  * Dates. (Or any other different kind of Events...) Perfect for a Band Website.
20  */
21  class tourdates
22  {
23  /** * @param int tourdate/event ID */
24  public $id;
25  /** * @param string event day */
26  public $day;
27  /** * @param string event month */
28  public $month;
29  /** * @param string event time */
30  public $time;
31  /** * @param string event date */
32  public $date;
33  /** * @param string event band name */
34  public $band;
35  /** * @param string event venue name */
36  public $venue;
37  /** * @param string facebook icon */
38  public $fbicon;
39  /** * @param string facebook event url */
40  public $fburl;
41  /** * @param int 0|1 1 means published, zero is not published */
42  public $published;
43 
44  /**
45  * @brief Inject Language Tags
46  * @author Daniel Retzl <[email protected]>
47  * @param array $lang language data array
48  * @param object $language the language object
49  * @return null
50  */
51  public function injectLanguageTags($lang, $language)
52  {
53  // #####################################################################################
54  // prepare language tag injection
55  // check if lang array is set
56  if (!isset($lang) || (empty($lang) || (!is_array($lang) || (!isset($language) || (empty($language))))))
57  { // if no lang array is set
58  // check if language object is set
59  if (!isset($language))
60  { // if not, include language class
61  require_once '../system/classes/language.php';
62  // and create new language object
63  $language = new \YAWK\language();
64  }
65  // ok...
66  $language->init();
67  // convert lang object param to array
68  $lang = (array) $language->lang;
69  }
70  // all should be set ok - finally: inject additional language tags
71  return $lang = $language->inject($lang, "../system/plugins/tourdates/language/");
72  }
73 
74  /**
75  * @brief get data and draw html return table for frontend
76  * @param object $db database
77  * @return bool|string the html table, inclkuding data
78  */
79  public function getFrontendTable($db)
80  {
81  /** @var $db \YAWK\db */
82  if (!$res = $db->query("SELECT * FROM {plugin_tourdates} WHERE published = '1' ORDER by date"))
83  { // q failed
84  print \YAWK\alert::draw("warning", "Fehler:", "Es tut mir leid, die Tabelle konnte nicht abgerufen werden.","","4200");
85  return false;
86  }
87  else
88  {
89  /* TABLE HEADER */
90  $html = "<h3>" . date('Y') . "</h3>" . "<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" class=\"table table-responsive\">
91  <tbody>";
92  /* TABLE CONTENT */
93  while ($row = mysqli_fetch_array($res)) {
94  $this->date = $row[1];
95  $this->band = $row[2];
96  $this->venue = $row[3];
97  $this->published = $row[4];
98  $this->fburl = $row[5];
99  if (!empty($this->fburl)) {
100  $this->fbicon = "<a href=\"$this->fburl\" target=\"_blank\"><img src=\"media/images/fbicon.png\"></a>";
101  } else {
102  $this->fbicon = "&nbsp;";
103  }
104 
105  /* date string to array function */
106  $splitDate = \YAWK\sys::splitDate($this->date);
107  /* set seperated vars */
108  $year = $splitDate['year'];
109  $this->day = $splitDate['day'];
110  $this->month = $splitDate['month'];
111  $this->time = $splitDate['time'];
112 
113  if ($this->published === '1') {
114  $pub = "success";
115  $pubtext = "On";
116  } else {
117  $pub = "danger";
118  $pubtext = "Off";
119  }
120  $html .= "<tr>
121  <td>$this->day. $this->month</td>
122  <td>$this->band</td>
123  <td>$this->time</td>
124  <td>$this->venue</td>
125  <td>$this->fbicon</td>
126  </tr>";
127 
128  }
129  /* TABLE FOOTER */
130  $html .= "</tbody>
131  </table>";
132  return $html;
133  }
134  } /* EOFunction getTable */
135 
136  /**
137  * @brief get data and draw html return table for backend
138  * @param object $db database
139  * @param array $lang language array
140  * @return bool|string the html table, including data
141  */
142  public function getBackendTable($db, $lang)
143  { /** @var $db \YAWK\db */
144  if (!$res = $db->query("SELECT * FROM {plugin_tourdates} ORDER by date"))
145  { // q failed, throw error
146  print \YAWK\alert::draw("warning", "Fehler:", "Es tut mir leid, die Tabelle konnte nicht abgerufen werden.","","4200");
147  return false;
148  }
149  else
150  {
151  /* TABLE HEADER */
152  $html = "";
153  /* TABLE CONTENT */
154  while ($row = mysqli_fetch_array($res)) {
155  $this->id = $row[0];
156  $this->date = $row[1];
157  $this->band = $row[2];
158  $this->venue = $row[3];
159  $this->published = $row[4];
160  $this->fburl = $row[5];
161 
162  if (!empty($this->fburl)) {
163  $this->fbicon = "<a href=\"$this->fburl\" target=\"_blank\"><i class=\"fa fa-facebook-square\"></i></a>";
164  } else {
165  $this->fbicon = "&nbsp;";
166  }
167 
168  /* date string to array function */
169  $splitDate = \YAWK\sys::splitDate($this->date);
170  /* set seperated vars */
171  $this->year = $splitDate['year'];
172  $this->day = $splitDate['day'];
173  $this->month = $splitDate['month'];
174  $this->time = $splitDate['time'];
175 
176  if ($this->published === '1') {
177  $pub = "success";
178  $pubtext = "On";
179  } else {
180  $pub = "danger";
181  $pubtext = "Off";
182  }
183  $html .= "<tr>
184  <td class=\"text-center\">
185  <a title=\"toggle&nbsp;status\" href=\"index.php?plugin=tourdates&pluginpage=tourdates-toggle&id=" . $this->id . "\">
186  <span class=\"label label-$pub\">$pubtext</span></a></td>
187  <td>$this->day. $this->month</td>
188  <td><a href=\"index.php?plugin=tourdates&pluginpage=tourdates-edit&id=" . $this->id . "\"><div>$this->band</div></a></td>
189  <td>$this->time</td>
190  <td>$this->venue</td>
191  <td class=\"text-center\">$this->fbicon</td>
192  <td class=\"text-center\"><a class=\"fa fa-copy\" title=\"" . $lang['TOUR_COPY'] . "\" href=\"index.php?plugin=tourdates&pluginpage=tourdates-copy&id=" . $this->id . "&copy=true\"></a>&nbsp;
193  <a class=\"fa fa-edit\"title=\"" . $lang['TOUR_EDIT'] . "\" href=\"index.php?plugin=tourdates&pluginpage=tourdates-edit&id=" . $this->id . "\"></a>&nbsp;
194  <a class=\"fa fa-trash-o\" role=\"dialog\" data-confirm=\"Den Termin &laquo;" . $this->date . " @ " . $this->venue . "&raquo; wirklich l&ouml;schen?\"
195  title=\"" . $lang['TOUR_DELETE'] . "\" href=\"index.php?plugin=tourdates&pluginpage=tourdates-delete&id=" . $this->id . "&delete=1\">
196  </a>
197  </td>
198  </tr>";
199 
200  }
201  return $html;
202  }
203  } /* EOFunction getAdminTable */
204 
205 
206  /**
207  * @brief toggle an entry online/offline, depending on published status
208  * @param object $db database
209  * @param int $id event ID to toggle
210  * @param int $published 0|1 1 means published, zero is not published
211  * @return bool
212  */
213  function toggleOffline($db, $id, $published)
214  { /** @var $db \YAWK\db */
215  // TOGGLE GIG STATUS
216  if (!$res = $db->query("UPDATE {plugin_tourdates}
217  SET published = '" . $published . "'
218  WHERE id = '" . $id . "'"))
219  { // q failed, throw error
220  print \YAWK\alert::draw("danger", "Error", "Event status could not be toggled.","","4200");
221  return false;
222  }
223  else
224  { // success
225  return true;
226  }
227  } /* EOFunction toggleOffline */
228 
229 
230  /**
231  * @brief load settings into object properties
232  * @param object $db database
233  * @param int $id event ID
234  */
235  function loadProperties($db, $id)
236  { /** @var $db \YAWK\db */
237  $res = $db->query("SELECT * FROM {plugin_tourdates}
238  WHERE id = '" . $id . "'");
239  if ($row = mysqli_fetch_row($res)) {
240  $this->id = $row[0];
241  $this->date = $row[1];
242  $this->band = $row[2];
243  $this->venue = $row[3];
244  $this->published = $row[4];
245  $this->fburl = $row[5];
246  }
247  } /* EOFunction loadProperties */
248 
249  /**
250  * @brief get highest ID from events (tourdates) database
251  * @param object $db database
252  * @return string|bool return highest ID or false
253  */
254  static function getMaxId($db)
255  { /** @var $db \YAWK\db */
256  $tourdates = new tourdates();
257  if ($res = $db->query("SELECT MAX(id) FROM {plugin_tourdates}"))
258  {
259  if ($row = mysqli_fetch_array($res)) { // success
260  return $tourdates->maxID = $row[0];
261  }
262  else
263  { // fetch failed
264  return false;
265  }
266  }
267  else
268  { // q failed
269  return false;
270  }
271  }
272 
273  /**
274  * @brief delete an entry
275  * @param object $db database
276  * @return bool
277  */
278  function delete($db)
279  { /** @var $db \YAWK\db */
280  if (!$res = $db->query("DELETE FROM {plugin_tourdates} WHERE id = '" . $this->id . "'"))
281  { // q failed, throw error
282  print \YAWK\alert::draw("danger", "Error", "Gig could not be deleted.", "plugin=tourdates","4200");
283  return false;
284  }
285  else
286  { // success
287  return true;
288  }
289  } /* EOFunction delete */
290 
291 
292  /**
293  * @brief copy an entry
294  * @param object $db database
295  * @param int $id event ID to copy
296  * @return bool
297  */
298  function copy($db, $id)
299  {
300  /** @var $db \YAWK\db */
301  if (!isset($tourdates))
302  { // create obj if its not set
303  $tourdates = new \YAWK\PLUGINS\TOURDATES\tourdates();
304  }
305  /* load properties for given ID */
306  $tourdates->loadProperties($db, $id);
307  $tourdates->id = self::getMaxId($db) + 1;
308  // # copy item to db tourdates
309  if (!$res = $db->query("INSERT INTO {plugin_tourdates} (id,date,band,venue,published,fburl)
310  VALUES ('" . $tourdates->id . "',
311  '" . $tourdates->date . "',
312  '" . $tourdates->band . "',
313  '" . $tourdates->venue . "',
314  '" . $tourdates->published . "',
315  '" . $tourdates->fburl . "')"))
316  { // q failed, throw error
317  print \YAWK\alert::draw("danger", "Error", "Gig could not be copied!","","4200");
318  return false;
319  }
320  else
321  { // success
322  return true;
323  }
324  } /* EOFunction copy($id); */
325 
326 
327  /**
328  * @brief create a new event (tourdate)
329  * @param object $db database
330  * @param string $date datetime
331  * @param string $band the band or artist
332  * @param string $venue venue where the event happens
333  * @param string $fburl URL to a facebook event (if any)
334  * @return bool
335  */
336  function create($db, $date, $band, $venue, $fburl)
337  {
338  /** @var $db \YAWK\db */
339  if (!isset($tourdates))
340  { // create obj if its not set
341  $tourdates = new \YAWK\PLUGINS\TOURDATES\tourdates();
342  }
343  /* get max ID and add 1 */
344  $id = self::getMaxId($db) + 1;
345  $published = 1;
346 
349 
350  // # create item in db tourdates
351  if (!$res = $db->query("INSERT INTO {plugin_tourdates} (id,date,band,venue,published,fburl)
352  VALUES ('" . $id . "',
353  '" . $date . "',
354  '" . $band . "',
355  '" . $venue . "',
356  '" . $published . "',
357  '" . $fburl . "')"))
358  { // q failed
359  return false;
360  }
361  else
362  { // success
363  return true;
364  }
365  } /* EOFunction create(); */
366 
367 
368  /**
369  * @brief edit an entry
370  * @param object $db database
371  * @param int $id event ID
372  * @param string $date event datetime
373  * @param string $band band or artist
374  * @param string $venue venue where the event happens
375  * @param string $fburl URL to a facebook event (if any)
376  * @return bool
377  */
378  function edit($db, $id, $date, $band, $venue, $fburl)
379  {
380  /** @var $db \YAWK\db */
381  // # update item
382  if (!$res = $db->query("UPDATE {plugin_tourdates}
383  SET date = '" . $date . "',
384  band = '" . $band . "',
385  venue = '" . $venue . "',
386  fburl = '" . $fburl . "'
387  WHERE id = '" . $id . "'"))
388  { // q failed
389  print \YAWK\alert::draw("danger", "Error", "Termin konnte nicht bearbeitet werden.","","4800");
390  return false;
391  }
392  else
393  { // success
394  return true;
395  }
396  } /* EOFunction edit(id); */
397  } // ./ class tourdates
398 } // ./namespace
print $lang['PAGE_ADD_BTN']
Definition: tourdates.php:43
$tourdates
Definition: tourdates.php:80
if(!isset($blog)) if(!isset($language)||(!isset($lang))) if(!isset($db)) $blog published
Definition: blog-toggle.php:17
Tour Dates Plugin hands you a simple but nice, clean bootstraped & sortable Data Table....
Definition: tourdates.php:22
injectLanguageTags($lang, $language)
Inject Language Tags.
Definition: tourdates.php:51
static splitDate($date)
split a date to month, day, year and time
Definition: sys.php:1502
static encodeChars($string)
convert german special chars and vowels into legal html
Definition: sys.php:1089
print $tourdates fburl
print $tourdates date
print $tourdates band
print $tourdates venue