PageRenderTime 56ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/core/acp/event.php

https://github.com/nopticon/hyd
PHP | 270 lines | 217 code | 48 blank | 5 comment | 11 complexity | 888b626ae7e81c7f5d2b5cd6417df395 MD5 | raw file
Possible License(s): MIT
  1. <?php namespace App;
  2. class __event extends mac {
  3. public function __construct() {
  4. parent::__construct();
  5. $this->auth('colab');
  6. }
  7. public function home() {
  8. global $user, $cache, $upload;
  9. $error = w();
  10. if (_button()) {
  11. $filepath = config('events_path');
  12. $filepath_1 = $filepath . 'future/';
  13. $filepath_2 = $filepath_1 . 'thumbnails/';
  14. $f = $upload->process($filepath_1, 'event_image', 'jpg');
  15. if (!sizeof($upload->error) && $f !== false) {
  16. $img = sql_total('_events');
  17. // Create vars
  18. $event_name = request_var('event_name', '');
  19. $event_artists = request_var('event_artists', '', true);
  20. $event_year = request_var('event_year', 0);
  21. $event_month = request_var('event_month', 0);
  22. $event_day = request_var('event_day', 0);
  23. $event_hours = request_var('event_hours', 0);
  24. $event_minutes = request_var('event_minutes', 0);
  25. $event_current_topic = request_var('event_current_topic', 0);
  26. $time_c = $user->timezone - $user->dst;
  27. $v_date = gmmktime($event_hours, $event_minutes, 0, $event_month, $event_day, $event_year) - $time_c;
  28. foreach ($f as $row) {
  29. $xa = $upload->resize($row, $filepath_1, $filepath_1, $img, [600, 400], false, false, true);
  30. if ($xa === false) {
  31. continue;
  32. }
  33. $xb = $upload->resize($row, $filepath_1, $filepath_2, $img, [100, 75], false, false);
  34. $event_alias = $event_alias2 = friendly($event_name);
  35. $event_count = 0;
  36. while (true) {
  37. $sql = 'SELECT id
  38. FROM _events
  39. WHERE event_alias = ?';
  40. if (!sql_fieldrow(sql_filter($sql, $event_alias))) {
  41. break;
  42. }
  43. $event_count++;
  44. $event_alias = $event_alias2 . '-' . $event_count;
  45. }
  46. $insert = [
  47. 'event_alias' => $event_alias,
  48. 'title' => $event_name,
  49. 'archive' => '',
  50. 'date' => (int) $v_date,
  51. 'event_update' => time()
  52. ];
  53. $event_id = sql_insert('events', $insert);
  54. //
  55. $artists_ary = explode(nr(), $event_artists);
  56. foreach ($artists_ary as $row) {
  57. $subdomain = get_subdomain($row);
  58. $sql = 'SELECT *
  59. FROM _artists
  60. WHERE subdomain = ?';
  61. if ($a_row = sql_fieldrow(sql_filter($sql, $subdomain))) {
  62. $sql = 'SELECT *
  63. FROM _artists_events
  64. WHERE a_artist = ?
  65. AND a_event = ?';
  66. if (!sql_fieldrow(sql_filter($sql, $a_row['ub'], $event_id))) {
  67. $sql_insert = [
  68. 'a_artist' => $a_row['ub'],
  69. 'a_event' => $event_id
  70. ];
  71. sql_insert('artists_events', $sql_insert);
  72. }
  73. }
  74. }
  75. // Alice: Create topic
  76. $post_message = 'Evento publicado';
  77. $post_time = time();
  78. $forum_id = 21;
  79. $poster_id = 1433;
  80. $sql = 'SELECT *
  81. FROM _forum_topics
  82. WHERE topic_id = ?';
  83. if (!$row_current_topic = sql_fieldrow(sql_filter($sql, $event_current_topic))) {
  84. $insert = [
  85. 'topic_title' => $event_name,
  86. 'topic_poster' => $poster_id,
  87. 'topic_time' => $post_time,
  88. 'forum_id' => $forum_id,
  89. 'topic_locked' => 0,
  90. 'topic_announce' => 0,
  91. 'topic_important' => 0,
  92. 'topic_vote' => 1,
  93. 'topic_featured' => 1,
  94. 'topic_points' => 1
  95. ];
  96. $topic_id = sql_insert('forum_topics', $insert);
  97. $event_current_topic = 0;
  98. } else {
  99. $topic_id = $event_current_topic;
  100. $post_message .= ' en la secci&oacute;n de eventos';
  101. $sql = 'UPDATE _forum_topics SET topic_title = ?
  102. WHERE topic_id = ?';
  103. sql_query(sql_filter($sql, $event_name, $topic_id));
  104. }
  105. $post_message .= '.';
  106. $poll_length = 0;
  107. $insert = [
  108. 'topic_id' => (int) $topic_id,
  109. 'forum_id' => $forum_id,
  110. 'poster_id' => $poster_id,
  111. 'post_time' => $post_time,
  112. 'poster_ip' => $user->ip,
  113. 'post_text' => $post_message,
  114. 'post_np' => ''
  115. ];
  116. $post_id = sql_insert('forum_posts', $insert);
  117. $sql = 'UPDATE _events SET event_topic = ?
  118. WHERE id = ?';
  119. sql_query(sql_filter($sql, $topic_id, $event_id));
  120. $insert = [
  121. 'topic_id' => (int) $topic_id,
  122. 'vote_text' => '&iquest;Asistir&aacute;s a ' . $event_name . '?',
  123. 'vote_start' => time(),
  124. 'vote_length' => (int) ($poll_length * 86400)
  125. ];
  126. $poll_id = sql_insert('poll_options', $insert);
  127. $poll_options = [
  128. 1 => 'Si asistir&eacute;'
  129. ];
  130. foreach ($poll_options as $option_id => $option_text) {
  131. $sql_insert = [
  132. 'vote_id' => (int) $poll_id,
  133. 'vote_option_id' => (int) $option_id,
  134. 'vote_option_text' => $option_text,
  135. 'vote_result' => 0
  136. ];
  137. sql_insert('poll_results', $sql_insert);
  138. }
  139. $forum_plus = !$event_current_topic ? ', forum_topics = forum_topics + 1 ' : '';
  140. $sql = 'UPDATE _forums
  141. SET forum_posts = forum_posts + 1, forum_last_topic_id = ?' . $forum_plus . '
  142. WHERE forum_id = ?';
  143. sql_query(sql_filter($sql, $topic_id, $forum_id));
  144. $sql = 'UPDATE _forum_topics SET topic_first_post_id = ?, topic_last_post_id = ?
  145. WHERE topic_id = ?';
  146. sql_query(sql_filter($sql, $post_id, $post_id, $topic_id));
  147. $sql = 'UPDATE _members SET user_posts = user_posts + 1
  148. WHERE user_id = ?';
  149. sql_query(sql_filter($sql, $poster_id));
  150. // Notify
  151. $user->save_unread(UH_T, $topic_id);
  152. // Post event to Facebook page
  153. $event = [
  154. 'id' => $img,
  155. 'event_alias' => $event_alias,
  156. 'title' => $event_name,
  157. 'date' => $v_date
  158. ];
  159. $response = facebook_event($event);
  160. $insert = [
  161. 'event_id' => $img,
  162. 'created_at' => $user->format_date(false, 'Y-m-d')
  163. ];
  164. $event_id = sql_insert('events_share', $insert);
  165. redirect($response['event_url']);
  166. }
  167. }
  168. _style('error', [
  169. 'MESSAGE' => parse_error($upload->error)
  170. ]);
  171. }
  172. $year = date('Y');
  173. $dates = [
  174. 'day' => range(1, 31),
  175. 'month' => range(1, 12),
  176. 'year' => range($year, $year + 3),
  177. ];
  178. _style('dates');
  179. foreach ($dates as $name => $value) {
  180. _style('dates.block', [
  181. 'NAME' => $name
  182. ]);
  183. foreach ($value as $name2 => $value2) {
  184. _style('dates.block.list', [
  185. 'NUMBER' => $value2
  186. ]);
  187. }
  188. }
  189. $hours = [
  190. 'hours' => range(0, 23),
  191. 'minutes' => range(0, 59, 5),
  192. ];
  193. _style('hours');
  194. foreach ($hours as $name => $value) {
  195. _style('hours.block', [
  196. 'NAME' => $name
  197. ]);
  198. foreach ($value as $name2 => $value2) {
  199. _style('hours.block.list', [
  200. 'NUMBER' => $value2
  201. ]);
  202. }
  203. }
  204. $sql = 'SELECT topic_id, topic_title
  205. FROM _forum_topics t
  206. LEFT OUTER JOIN _events e ON t.topic_id = e.event_topic
  207. WHERE e.event_topic IS NULL
  208. AND forum_id = 21
  209. ORDER BY topic_time DESC';
  210. $topics = sql_rowset($sql);
  211. foreach ($topics as $i => $row) {
  212. if (!$i) {
  213. _style('topics');
  214. }
  215. _style('topics.row', [
  216. 'TOPIC_ID' => $row['topic_id'],
  217. 'TOPIC_TITLE' => $row['topic_title']
  218. ]);
  219. }
  220. return;
  221. }
  222. }