Advertisement
Guest User

viewtopic_hookup.php

a guest
Mar 10th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.91 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. *
  5. * @package phpBB Hookup MOD
  6. * @version $Id: viewtopic_hookup.php 3 2009-05-08 11:24:55Z joas $
  7. * @copyright (c) 2007, 2008, 2009 Pyramide und gn#36 ?
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. *
  10. */
  11.  
  12. if (!defined('IN_PHPBB'))
  13. {
  14. exit;
  15. }
  16.  
  17. if (isset($topic_data['hookup_enabled']) && $topic_data['hookup_enabled'])
  18. {
  19. if (!function_exists('generate_smilies'))
  20. {
  21. include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  22. }
  23. if (!function_exists('user_get_id_name'))
  24. {
  25. include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  26. }
  27. if (!class_exists('messenger'))
  28. {
  29. include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  30. }
  31. if (!class_exists('topic'))
  32. {
  33. include($phpbb_root_path . 'includes/functions_post_oo.' . $phpEx);
  34. }
  35.  
  36. $user->add_lang('mods/hookup');
  37. $user->add_lang('acp/common'); //for L_RUN
  38.  
  39.  
  40. $userlist = array();
  41. $userids = array();
  42. $comments = array();
  43. $datelist = array();
  44. $available_data = array();
  45. $available_sums = array();
  46. $hookup_errors = array();
  47. $is_hookup_owner = ($user->data['user_id'] == $topic_data['topic_poster']) || $auth->acl_get('m_edit', $forum_id);
  48.  
  49. //POST-vars
  50. $delete_hookup = request_var('delete_hookup', 'no');
  51. $delete_user_ids = request_var('delete_user', array(0));
  52. $delete_date_ids = request_var('delete_date', array(0));
  53. $add_dates = trim(request_var('add_date', '', true));
  54. $invite_self = trim(request_var('invite_self', ''));
  55. $add_users = trim(request_var('usernames', '', true)); //can't use add_user because the javascript popup requires the fields name to be "usernames"
  56. $add_groups = request_var('add_groups', array(0));
  57. $set_active = request_var('set_active', -1);
  58.  
  59.  
  60. //load list of groups for "add groups" box
  61. $sql = 'SELECT group_id, group_name, group_type
  62. FROM ' . GROUPS_TABLE . '
  63. WHERE group_type <> ' . GROUP_HIDDEN;
  64. $result = $db->sql_query($sql);
  65.  
  66. $s_group_list = '';
  67. while ($row = $db->sql_fetchrow($result))
  68. {
  69. $s_group_list .= '<option value="' . $row['group_id'] . '"' . ($row['group_type'] == GROUP_SPECIAL ? ' class="sep"' : '') .'>';
  70. $s_group_list .= ($row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name']);
  71. $s_group_list .= '</option>';
  72. }
  73. $db->sql_freeresult($result);
  74.  
  75. $template->assign_var('S_GROUP_LIST', $s_group_list);
  76.  
  77.  
  78. //load user_ids for this hookup
  79. $sql = 'SELECT user_id, notify_status, comment
  80. FROM ' . HOOKUP_MEMBERS_TABLE . '
  81. WHERE topic_id = ' . $topic_id;
  82. $result = $db->sql_query($sql);
  83. while ($row = $db->sql_fetchrow($result))
  84. {
  85. $userids[] = $row['user_id'];
  86.  
  87. $comments[$row['user_id']] = $row['comment'];
  88. //reset the notify_status for the viewing user if nescessary
  89. if ($row['user_id'] == $user->data['user_id'] && $row['notify_status'])
  90. {
  91. $sql = 'UPDATE ' . HOOKUP_MEMBERS_TABLE . "
  92. SET notify_status = 0
  93. WHERE topic_id = $topic_id
  94. AND user_id = {$user->data['user_id']}";
  95. $db->sql_query($sql);
  96. }
  97. }
  98. $db->sql_freeresult($result);
  99.  
  100. //invite self
  101. if (($topic_data['hookup_self_invite'] || $is_hookup_owner) && $invite_self == 'join' && !in_array($user->data['user_id'], $userids))
  102. {
  103. //user or owner wants to join and is not a member yet.
  104. $sql_array = array(
  105. 'topic_id' => $topic_id,
  106. 'user_id' => $user->data['user_id'],
  107. 'notify_status' => 0 //would be set to 0 on the next refresh anyway
  108. );
  109. $sql = 'INSERT INTO ' . HOOKUP_MEMBERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_array);
  110. $db->sql_query($sql);
  111. $userids[] = $user->data['user_id'];
  112. }
  113. elseif ($topic_data['hookup_self_invite'] && $invite_self == 'leave' && in_array($user->data['user_id'], $userids))
  114. {
  115. //user wants to leave and is a member, display confirmation box first
  116. if (confirm_box(true))
  117. {
  118. $where_sql = " WHERE topic_id = $topic_id AND user_id = {$user->data['user_id']}";
  119. $sql = 'DELETE FROM ' . HOOKUP_MEMBERS_TABLE . $where_sql;
  120. $db->sql_query($sql);
  121. $sql = 'DELETE FROM ' . HOOKUP_AVAILABLE_TABLE . $where_sql;
  122. $db->sql_query($sql);
  123.  
  124. $userids = array_diff($userids, array($user->data['user_id']));
  125. }
  126. else
  127. {
  128. $s_hidden_fields = build_hidden_fields(array(
  129. 't' => $topic_id,
  130. 'invite_self' => 'leave',
  131. ));
  132. confirm_box(false, $user->lang['HOOKUP_INVITE_SELF_LEAVE_CONFIRM'], $s_hidden_fields);
  133. }
  134. }
  135.  
  136. //add users
  137. if ($is_hookup_owner && !empty($add_users))
  138. {
  139. $username_array = array_unique(explode("\n", $add_users));
  140. $username_array = array_map('utf8_clean_string', $username_array);
  141.  
  142. //get some userdata
  143. $sql = 'SELECT user_id, username, user_type, user_permissions, user_lang, user_email, user_jabber, user_notify_type
  144. FROM ' . USERS_TABLE . '
  145. WHERE ' . $db->sql_in_set('username_clean', $username_array);
  146. $result = $db->sql_query($sql);
  147.  
  148. $new_users = array();
  149. while ($row = $db->sql_fetchrow($result))
  150. {
  151. $new_users[$row['user_id']] = $row;
  152. }
  153. $db->sql_freeresult($result);
  154.  
  155. $userids_to_add = array_diff(array_keys($new_users), $userids);
  156. $userids_already_added = array_intersect(array_keys($new_users), $userids);
  157. }
  158.  
  159. //add group(s)
  160. else if ($is_hookup_owner && count($add_groups) > 0)
  161. {
  162. //get some userdata
  163. $sql = 'SELECT u.user_id, u.username, u.user_type, u.user_permissions, u.user_lang, u.user_email, u.user_jabber, u.user_notify_type
  164. FROM ' . USER_GROUP_TABLE . ' ug
  165. JOIN ' . USERS_TABLE . ' u
  166. ON (u.user_id = ug.user_id)
  167. WHERE ' . $db->sql_in_set('ug.group_id', $add_groups) . '
  168. AND ug.user_pending = 0';
  169. $result = $db->sql_query($sql);
  170.  
  171. $new_users = array();
  172. while ($row = $db->sql_fetchrow($result))
  173. {
  174. $new_users[$row['user_id']] = $row;
  175. }
  176. $db->sql_freeresult($result);
  177.  
  178. $userids_to_add = array_diff(array_keys($new_users), $userids);
  179. //dont set $userids_already_added because it might generate a lot of warnings
  180. }
  181.  
  182. //now that we have the user_ids and data, add the users
  183. if (isset($userids_to_add) && count($userids_to_add) > 0)
  184. {
  185. //check if users have read permission
  186. $user_auth = new auth();
  187. foreach($userids_to_add as $key => $user_id)
  188. {
  189. $user_auth->acl($new_users[$user_id]);
  190. if (!$user_auth->acl_get('f_read', $forum_id))
  191. {
  192. $hookup_errors[] = sprintf($user->lang['USER_CANNOT_READ_FORUM'], $new_users[$user_id]['username']);
  193. unset($userids_to_add[$key]);
  194. }
  195. }
  196.  
  197. //insert users into database
  198. $sql_array = array();
  199. foreach($userids_to_add as $user_id)
  200. {
  201. $sql_array[] = array(
  202. 'topic_id' => $topic_id,
  203. 'user_id' => $user_id,
  204. 'notify_status' => 1 //no need to notify the user about new dates when he hasn't visited the
  205. //hookup yet and thus not even entered his available info for the first dates
  206. );
  207. }
  208. $db->sql_multi_insert(HOOKUP_MEMBERS_TABLE, $sql_array);
  209.  
  210. //notify new users about invitation
  211. $messenger = new messenger();
  212. foreach($userids_to_add as $user_id)
  213. {
  214. $userdata = $new_users[$user_id];
  215. $messenger->template('hookup_added', $userdata['user_lang']);
  216. $messenger->to($userdata['user_email'], $userdata['username']);
  217. $messenger->im($userdata['user_jabber'], $userdata['username']);
  218. $messenger->assign_vars(array(
  219. 'USERNAME' => $userdata['username'],
  220. 'TOPIC_TITLE' => $topic_data['topic_title'],
  221. 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id",
  222. ));
  223. $messenger->send($userdata['user_notify_type']);
  224. }
  225. $messenger->save_queue();
  226.  
  227. //add userids to local array
  228. $userids = array_merge($userids, $userids_to_add);
  229. }
  230.  
  231. //generate error messages for users that are already members
  232. if (isset($userids_already_added) && count($userids_already_added) > 0)
  233. {
  234. foreach($userids_already_added as $userid)
  235. {
  236. $hookup_errors[] = sprintf($user->lang['HOOKUP_USER_EXISTS'], $new_users[$userid]['username']);
  237. }
  238. }
  239.  
  240.  
  241. //disable/delete whole hookup
  242. if ($delete_hookup == 'disable' || $delete_hookup == 'delete')
  243. {
  244. if (confirm_box(true))
  245. {
  246. if ($delete_hookup == 'delete')
  247. {
  248. $sql = 'UPDATE ' . TOPICS_TABLE . "
  249. SET hookup_enabled = 0,
  250. hookup_active_date=0
  251. WHERE topic_id = $topic_id";
  252. $db->sql_query($sql);
  253. $sql = 'DELETE FROM ' . HOOKUP_DATES_TABLE . " WHERE topic_id = $topic_id";
  254. $db->sql_query($sql);
  255. $sql = 'DELETE FROM ' . HOOKUP_MEMBERS_TABLE . " WHERE topic_id = $topic_id";
  256. $db->sql_query($sql);
  257. $sql = 'DELETE FROM ' . HOOKUP_AVAILABLE_TABLE . " WHERE topic_id = $topic_id";
  258. $db->sql_query($sql);
  259. }
  260. else //disable
  261. {;
  262. $sql = 'UPDATE ' . TOPICS_TABLE . "
  263. SET hookup_enabled = 0
  264. WHERE topic_id = $topic_id";
  265. $db->sql_query($sql);
  266. }
  267. redirect($viewtopic_url);
  268. }
  269. else
  270. {
  271. $s_hidden_fields = build_hidden_fields(array(
  272. 't' => $topic_id,
  273. 'delete_hookup' => $delete_hookup
  274. ));
  275. confirm_box(false, $user->lang['DELETE_HOOKUP_' . strtoupper($delete_hookup) . '_CONFIRM'], $s_hidden_fields);
  276. }
  277. }
  278.  
  279.  
  280. //confirm box for user/date deletion (only one confirm box because you can delete both with one <form>)
  281. $delete_confirm = false;
  282. if ($is_hookup_owner && (count($delete_user_ids) > 0 || count($delete_date_ids) > 0))
  283. {
  284. if (confirm_box(true))
  285. {
  286. $delete_confirm = true;
  287. }
  288. else
  289. {
  290. $s_hidden_fields = build_hidden_fields(array(
  291. 't' => $topic_id,
  292. 'delete_date' => $delete_date_ids,
  293. 'delete_user' => $delete_user_ids,
  294. //'available' => $available,
  295. ));
  296. confirm_box(false, sprintf($user->lang['HOOKUP_DELETE_CONFIRM'], count($delete_date_ids), count($delete_user_ids)), $s_hidden_fields);
  297. }
  298. }
  299.  
  300. //delete users
  301. if ($is_hookup_owner && count($delete_user_ids) > 0 && $delete_confirm)
  302. {
  303. //make sure we only have ints.
  304. $delete_ids = array_map('intval', $_POST['delete_user']);
  305. $where_sql = " WHERE topic_id = $topic_id AND " . $db->sql_in_set('user_id', $delete_ids);
  306. $sql = 'DELETE FROM ' . HOOKUP_MEMBERS_TABLE . $where_sql;
  307. $db->sql_query($sql);
  308. $sql = 'DELETE FROM ' . HOOKUP_AVAILABLE_TABLE . $where_sql;
  309. $db->sql_query($sql);
  310.  
  311. $userids = array_diff($userids, $delete_ids);
  312. }
  313.  
  314. //delete date(s)
  315. if ($is_hookup_owner && count($delete_date_ids) > 0 && $delete_confirm)
  316. {
  317. //make sure we only have ints.
  318. $delete_ids = array_map('intval', $_POST['delete_date']);
  319. $where_sql = " WHERE topic_id = $topic_id AND " . $db->sql_in_set('date_id', $delete_ids);
  320. $sql = 'DELETE FROM ' . HOOKUP_DATES_TABLE . $where_sql;
  321. $db->sql_query($sql);
  322. $sql = 'DELETE FROM ' . HOOKUP_AVAILABLE_TABLE . $where_sql;
  323. $db->sql_query($sql);
  324. }
  325.  
  326.  
  327. //load list of invited users so we can check who is permitted to add dates
  328. $sql = 'SELECT user_id, username, user_colour
  329. FROM ' . USERS_TABLE . '
  330. WHERE ' . $db->sql_in_set('user_id', $userids, false, true) . '
  331. ORDER BY username_clean ASC';
  332. $result = $db->sql_query($sql);
  333. $userlist = $db->sql_fetchrowset($result);
  334.  
  335. //build list of user_ids
  336. foreach ($userlist as $ignore => $userrow)
  337. {
  338. $userids[] = $userrow['user_id'];
  339. }
  340. $db->sql_freeresult($result);
  341. $is_hookup_member = in_array($user->data['user_id'], $userids);
  342.  
  343. //add a new date. this needs to be done after we loaded the userlist but before the datelist
  344. if (($is_hookup_owner || $is_hookup_member) && strlen($add_dates) > 0)
  345. {
  346. $add_dates = array_map("trim", explode("\n", $add_dates));
  347. $sql_data = array();
  348.  
  349. //replace german date format
  350. $add_dates = preg_replace('#(\\d{1,2})\\. ?(\\d{1,2})\\. ?(\\d{4})#', '$3-$2-$1', $add_dates);
  351.  
  352. foreach($add_dates as $date)
  353. { $desc_match = preg_match('#,(.*)#', $date, $description);
  354. //strtotime uses the local (server) timezone, so parse manually and use gmmktime to ignore any timezone
  355. if (!preg_match('#(\\d{4})-(\\d{1,2})-(\\d{1,2}) (\\d{1,2}):(\\d{2})#', $date, $m))
  356. {
  357. $hookup_errors[] = "$date: {$user->lang['INVALID_DATE']}";
  358. }
  359. else
  360. {
  361. if ($desc_match)
  362. {
  363. $description = trim($description[1]);
  364. }
  365. else
  366. {
  367. $description = '';
  368. }
  369. $date_time = gmmktime($m[4], $m[5], 0, $m[2], $m[3], $m[1]);
  370.  
  371. //manually subtract users timezone and dst
  372. $date_time -= ($user->timezone + $user->dst);
  373.  
  374. if ($date_time < time())
  375. {
  376. $hookup_errors[] = "$date: {$user->lang['CANNOT_ADD_PAST']}";
  377. }
  378. else
  379. {
  380. //check for duplicate
  381. $sql = 'SELECT date_id, description
  382. FROM ' . HOOKUP_DATES_TABLE . "
  383. WHERE topic_id = $topic_id
  384. AND date_time = $date_time AND description = '" . $db->sql_escape($description) . "'";
  385. $result = $db->sql_query($sql);
  386. if ($db->sql_fetchrow($result))
  387. {
  388. $hookup_errors[] = sprintf($user->lang['DATE_ALREADY_ADDED'], $user->format_date($date_time));
  389. }
  390. else
  391. {
  392. $sql_data[] = array(
  393. 'topic_id' => $topic_id,
  394. 'date_time' => $date_time, 'description' => $description
  395. );
  396. }
  397. $db->sql_freeresult($result);
  398. }
  399. }
  400. }
  401. if (count($sql_data) > 0)
  402. {
  403. $db->sql_multi_insert(HOOKUP_DATES_TABLE, $sql_data);
  404.  
  405. //notify members about new dates
  406. $messenger = new messenger();
  407. $notified_userids = array();
  408.  
  409. $sql = 'SELECT u.user_id, u.username, u.user_lang, u.user_email, u.user_jabber, u.user_notify_type
  410. FROM ' . HOOKUP_MEMBERS_TABLE . ' hm
  411. JOIN ' . USERS_TABLE . " u
  412. ON (u.user_id = hm.user_id)
  413. WHERE hm.topic_id = $topic_id
  414. AND hm.user_id <> {$user->data['user_id']}
  415. AND hm.notify_status = 0";
  416. $result = $db->sql_query($sql);
  417. while ($row = $db->sql_fetchrow($result))
  418. {
  419. $messenger->template('hookup_dates_added', $row['user_lang']);
  420. $messenger->to($row['user_email'], $row['username']);
  421. $messenger->im($row['user_jabber'], $row['username']);
  422. $messenger->assign_vars(array(
  423. 'USERNAME' => $row['username'],
  424. 'TOPIC_TITLE' => $topic_data['topic_title'],
  425. 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id"
  426. ));
  427. $messenger->send($row['user_notify_type']);
  428.  
  429. $notified_userids[] = $row['user_id'];
  430. }
  431. $db->sql_freeresult($result);
  432.  
  433. $messenger->save_queue();
  434.  
  435. //set notify status
  436. if (count($notified_userids))
  437. {
  438. $sql = 'UPDATE ' . HOOKUP_MEMBERS_TABLE . "
  439. SET notify_status = 1
  440. WHERE topic_id = $topic_id
  441. AND " . $db->sql_in_set('user_id', $notified_userids);
  442. $db->sql_query($sql);
  443. }
  444. }
  445. }
  446.  
  447.  
  448. //load dates for this hookup
  449. $sql = 'SELECT date_id, date_time, description
  450. FROM ' . HOOKUP_DATES_TABLE . '
  451. WHERE topic_id = ' . $topic_id . '
  452. ORDER BY date_time ASC';
  453. $result = $db->sql_query($sql);
  454. //associative array date_id => date_row
  455. while ($row = $db->sql_fetchrow($result))
  456. {
  457. $datelist[$row['date_id']] = $row;
  458. }
  459. $db->sql_freeresult($result);
  460.  
  461.  
  462. //load available info
  463. foreach($datelist as $date)
  464. {
  465. $available_sums[$date['date_id']] = array(HOOKUP_YES => 0, HOOKUP_MAYBE => 0, HOOKUP_NO => 0);
  466. }
  467.  
  468. $sql = 'SELECT date_id, user_id, available
  469. FROM ' . HOOKUP_AVAILABLE_TABLE . '
  470. WHERE topic_id = ' . $topic_id;
  471. $result = $db->sql_query($sql);
  472. while ($row = $db->sql_fetchrow($result))
  473. {
  474. $available_data[$row['user_id']][$row['date_id']] = $row['available'];
  475. $available_sums[$row['date_id']][$row['available']]++;
  476. }
  477. $db->sql_freeresult($result);
  478.  
  479. //update this users available info
  480. if ($is_hookup_member && isset($_POST['available']) && is_array($_POST['available']))
  481. {
  482. foreach($_POST['available'] as $date_id => $available)
  483. {
  484. //ignore HOOKUP_UNSET and other invalid values
  485. if (!is_numeric($date_id) || !isset($datelist[$date_id]) || !in_array($available, array(HOOKUP_YES, HOOKUP_NO, HOOKUP_MAYBE)))
  486. {
  487. continue;
  488. }
  489.  
  490. //update existing row
  491. if (isset($available_data[$user->data['user_id']][$date_id]))
  492. {
  493. $old_status = $available_data[$user->data['user_id']][$date_id];
  494. //ignore unchanged values
  495. if ($old_status == $available)
  496. {
  497. continue;
  498. }
  499.  
  500. $sql = 'UPDATE ' . HOOKUP_AVAILABLE_TABLE . "
  501. SET available = $available
  502. WHERE user_id = {$user->data['user_id']}
  503. AND date_id = $date_id";
  504. $db->sql_query($sql);
  505.  
  506. //update local stats
  507. $available_sums[$date_id][$old_status]--;
  508. $available_sums[$date_id][$available]++;
  509. }
  510. //insert new row
  511. else
  512. {
  513. $sql_ary = array(
  514. 'topic_id' => $topic_id,
  515. 'date_id' => $date_id,
  516. 'user_id' => $user->data['user_id'],
  517. 'available' => $available,
  518. );
  519. $sql = 'INSERT INTO ' . HOOKUP_AVAILABLE_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
  520. $db->sql_query($sql);
  521.  
  522. //update local stats
  523. $available_sums[$date_id][$available]++;
  524. }
  525.  
  526.  
  527. //replace value in array
  528. $available_data[$user->data['user_id']][$date_id] = $available;
  529. }
  530.  
  531. //Update Comment:
  532. $comment = request_var('comment', '', true);
  533. $sql = 'UPDATE ' . HOOKUP_MEMBERS_TABLE . "
  534. SET comment='" . $db->sql_escape($comment) . "'
  535. WHERE user_id={$user->data['user_id']}
  536. AND topic_id = $topic_id";
  537. $db->sql_query($sql);
  538. $comments[$user->data['user_id']] = $comment;
  539. }
  540.  
  541. //Set active date
  542. if ($is_hookup_owner && ($set_active > -1))
  543. {
  544. if ($set_active != 0 && !isset($datelist[$set_active]))
  545. {
  546. trigger_error('NO_DATE');
  547. }
  548.  
  549. $active_date_formatted = $set_active != 0 ? $user->format_date($datelist[$set_active]['date_time']) : '-';
  550.  
  551. if (confirm_box(true))
  552. {
  553. $title_prefix = request_var('title_prefix', false);
  554. $send_email = request_var('send_email', false);
  555. $post_reply = request_var('post_reply', false);
  556.  
  557. //insert active date (short format) into topic title. this will use language
  558. //and timezone of the "active maker" but the alternative would be
  559. //to query the HOOKUP_DATES table every time we need the topic title
  560. if ($set_active == 0 || $title_prefix)
  561. {
  562. $new_title = preg_replace('#^(\\[.+?\\] )?#', ($set_active != 0 ? '[' . $user->format_date($datelist[$set_active]['date_time'], $user->lang['HOOKUP_DATEFORMAT_TITLE']) . '] ' : ''), $topic_data['topic_title']);
  563.  
  564. $sql = 'UPDATE ' . TOPICS_TABLE . '
  565. SET hookup_active_date = ' . (int) $set_active . ",
  566. topic_title = '" . $db->sql_escape($new_title) . "'
  567. WHERE topic_id = $topic_id";
  568. $db->sql_query($sql);
  569.  
  570. $sql = 'UPDATE ' . POSTS_TABLE . "
  571. SET post_subject='" . $db->sql_escape($new_title) . "'
  572. WHERE post_id = {$topic_data['topic_first_post_id']}";
  573. $db->sql_query($sql);
  574. }
  575. else
  576. {
  577. //only set hookup_active_date
  578. $sql = 'UPDATE ' . TOPICS_TABLE . '
  579. SET hookup_active_date = ' . (int) $set_active . "
  580. WHERE topic_id = $topic_id";
  581. $db->sql_query($sql);
  582. }
  583.  
  584.  
  585. //notify all members about active date
  586. if ($set_active != 0 && $send_email)
  587. {
  588. $messenger = new messenger();
  589. $title_without_date = preg_replace('#^(\\[.+?\\] )#', '', $topic_data['topic_title']);
  590.  
  591. $sql = 'SELECT u.user_id, u.username, u.user_lang, u.user_dateformat, u.user_email, u.user_jabber, u.user_notify_type
  592. FROM ' . HOOKUP_MEMBERS_TABLE . ' hm
  593. JOIN ' . USERS_TABLE . " u
  594. ON (u.user_id = hm.user_id)
  595. WHERE hm.topic_id = $topic_id";
  596. $result = $db->sql_query($sql);
  597. while ($row = $db->sql_fetchrow($result))
  598. {
  599. $messenger->template('hookup_active_date', $row['user_lang']);
  600. $messenger->to($row['user_email'], $row['username']);
  601. $messenger->im($row['user_jabber'], $row['username']);
  602. $messenger->assign_vars(array(
  603. 'USERNAME' => $row['username'],
  604. 'TOPIC_TITLE' => $title_without_date,
  605. 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id",
  606. //TODO use recipients language
  607. 'ACTIVE_DATE' => $user->format_date($datelist[$set_active]['date_time'], $row['user_dateformat'], true),
  608. 'ACTIVE_DATE_SHORT'=> $user->format_date($datelist[$set_active]['date_time'], $user->lang['HOOKUP_DATEFORMAT']),
  609. ));
  610. $messenger->send($row['user_notify_type']);
  611. }
  612. $db->sql_freeresult($result);
  613.  
  614. $messenger->save_queue();
  615. }
  616.  
  617. //post reply to this topic. Again this can only be in the "active maker"s language
  618. if ($post_reply)
  619. {
  620. $message = $user->lang['SET_ACTIVE_POST_TEMPLATE'];
  621. $message = str_replace('{ACTIVE_DATE}', $user->format_date($datelist[$set_active]['date_time'], $user->lang['HOOKUP_DATEFORMAT_POST']), $message);
  622.  
  623. $post = new post($topic_id);
  624. $post->post_text = $message;
  625. $post->submit();
  626. }
  627.  
  628. meta_refresh(3, $viewtopic_url);
  629. $message = ($set_active != 0 ? sprintf($user->lang['ACTIVE_DATE_SET'], $active_date_formatted) : $user->lang['ACTIVE_DATE_UNSET']) . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $viewtopic_url . '">', '</a>');
  630. trigger_error($message);
  631. }
  632. else
  633. {
  634. $s_hidden_fields = build_hidden_fields(array(
  635. 't' => $topic_id,
  636. 'set_active'=> $set_active
  637. ));
  638. if ($set_active != 0)
  639. {
  640. confirm_box(false, sprintf($user->lang['SET_ACTIVE_CONFIRM'], $active_date_formatted), $s_hidden_fields, 'hookup_active_date_confirm.html');
  641. }
  642. else
  643. {
  644. confirm_box(false, 'UNSET_ACTIVE', $s_hidden_fields);
  645. }
  646. }
  647. }
  648.  
  649. if (count($datelist) == 0)
  650. {
  651. $hookup_errors[] = $user->lang['HOOKUP_NO_DATES'];
  652. }
  653. if (count($userlist) == 0)
  654. {
  655. $hookup_errors[] = $user->lang['HOOKUP_NO_USERS'];
  656. }
  657.  
  658.  
  659. //template
  660. $template->assign_vars(array(
  661. 'S_HAS_HOOKUP' => true,
  662. 'S_IS_SELF_INVITE' => $topic_data['hookup_self_invite'],
  663. 'S_IS_HOOKUP_OWNER' => $is_hookup_owner,
  664. 'S_IS_HOOKUP_MEMBER'=> $is_hookup_member,
  665. 'S_HOOKUP_ACTION' => $viewtopic_url,
  666. 'S_LANG_PATH' => $user->lang_path . $user->lang_name,
  667. 'S_LANG_NAME' => $user->lang_name,
  668. 'S_NUM_DATES' => count($datelist),
  669. 'S_NUM_DATES_PLUS_1'=> count($datelist)+1,
  670. 'S_ACTIVE_DATE' => $topic_data['hookup_active_date'],
  671. 'S_HAS_DATES' => (count($datelist) > 0),
  672. 'S_HAS_USERS' => (count($userlist) > 0),
  673. 'ACTIVE_DATE_DATE' => isset($datelist[$topic_data['hookup_active_date']]) ? $user->format_date($datelist[$topic_data['hookup_active_date']]['date_time']) : '-',
  674. 'U_UNSET_ACTIVE' => $viewtopic_url . '&amp;set_active=0',
  675. 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=ucp&amp;field=usernames'),
  676. 'UA_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=ucp&field=usernames', false),
  677. 'HOOKUP_ERRORS' => (count($hookup_errors) > 0) ? implode('<br />', $hookup_errors) : false,
  678. 'HOOKUP_YES' => HOOKUP_YES,
  679. 'HOOKUP_MAYBE' => HOOKUP_MAYBE,
  680. 'HOOKUP_NO' => HOOKUP_NO,
  681. 'HOOKUP_UNSET' => HOOKUP_UNSET,
  682. 'L_HOOKUP_YES' => $user->lang['HOOKUP_STATUS'][HOOKUP_YES],
  683. 'L_HOOKUP_NO' => $user->lang['HOOKUP_STATUS'][HOOKUP_NO],
  684. 'L_HOOKUP_MAYBE' => $user->lang['HOOKUP_STATUS'][HOOKUP_MAYBE],
  685. 'L_HOOKUP_UNSET' => $user->lang['HOOKUP_STATUS'][HOOKUP_UNSET],
  686. //one letter versions for summaries
  687. 'L_HOOKUP_Y' => $user->lang['HOOKUP_STATUS'][HOOKUP_YES]{0},
  688. 'L_HOOKUP_N' => $user->lang['HOOKUP_STATUS'][HOOKUP_NO]{0},
  689. 'L_HOOKUP_M' => $user->lang['HOOKUP_STATUS'][HOOKUP_MAYBE]{0},
  690.  
  691. ));
  692.  
  693. foreach($datelist as $hookup_date)
  694. {
  695. $yes_count = $available_sums[$hookup_date['date_id']][HOOKUP_YES];
  696. $maybe_count = $available_sums[$hookup_date['date_id']][HOOKUP_MAYBE];
  697. $no_count = $available_sums[$hookup_date['date_id']][HOOKUP_NO];
  698. //$total_count = $yes_count + $maybe_count + $no_count; //unset_count?
  699. $total_count = count($userlist);
  700. $unset_count = $total_count - ($yes_count + $maybe_count + $no_count);
  701.  
  702. $yes_percent = $total_count > 0 ? round(($yes_count / $total_count) * 100) : 0;
  703. $maybe_percent = $total_count > 0 ? round(($maybe_count / $total_count) * 100) : 0;
  704. $no_percent = $total_count > 0 ? round(($no_count / $total_count) * 100) : 0;
  705. $unset_percent = 100 - ($yes_percent + $maybe_percent + $no_percent);
  706.  
  707. $template->assign_block_vars('date', array(
  708. 'ID' => $hookup_date['date_id'],
  709. 'DATE' => $user->format_date($hookup_date['date_time'], $user->lang['HOOKUP_DATEFORMAT']), 'DESCRIPTION' => $hookup_date['description'],
  710. 'FULL_DATE' => $user->format_date($hookup_date['date_time']),
  711. //'ADDED_AT_BY' => sprintf($user->lang['ADDED_AT_BY'], $user->format_date($hookup_date['added_at']), $hookup_date['added_by_name']),
  712. 'YES_COUNT' => $yes_count,
  713. 'YES_PERCENT' => $yes_percent,
  714. 'MAYBE_COUNT' => $maybe_count,
  715. 'MAYBE_PERCENT' => $maybe_percent,
  716. 'NO_COUNT' => $no_count,
  717. 'NO_PERCENT' => $no_percent,
  718. 'UNSET_COUNT' => $unset_count,
  719. 'UNSET_PERCENT' => $unset_percent,
  720. 'S_IS_ACTIVE' => $hookup_date['date_id'] == $topic_data['hookup_active_date'],
  721. 'U_SET_ACTIVE' => $viewtopic_url . '&amp;set_active=' . $hookup_date['date_id'],
  722. ));
  723. }
  724.  
  725. foreach($userlist as $hookup_user)
  726. {
  727. $is_self = ($hookup_user['user_id'] == $user->data['user_id']);
  728.  
  729. $template->assign_block_vars('user', array(
  730. 'ID' => $hookup_user['user_id'],
  731. 'NAME' => $hookup_user['username'],
  732. 'COMMENT' => isset($comments[$hookup_user['user_id']]) ? $comments[$hookup_user['user_id']] : '',
  733. 'USERNAME_FULL' => get_username_string('full', $hookup_user['user_id'], $hookup_user['username'], $hookup_user['user_colour']),
  734. 'IS_SELF' => $is_self
  735. ));
  736.  
  737. foreach($datelist as $hookup_date)
  738. {
  739. $available = isset($available_data[$hookup_user['user_id']][$hookup_date['date_id']])
  740. ? $available_data[$hookup_user['user_id']][$hookup_date['date_id']]
  741. : HOOKUP_UNSET;
  742.  
  743. $template->assign_block_vars('user.date', array(
  744. 'ID' => $hookup_date['date_id'],
  745. 'AVAILABLE' => $user->lang['HOOKUP_STATUS'][$available],
  746. 'STATUS_YES' => ($available == HOOKUP_YES),
  747. 'STATUS_NO' => ($available == HOOKUP_NO),
  748. 'STATUS_MAYBE' => ($available == HOOKUP_MAYBE),
  749. 'STATUS_UNSET' => ($available == HOOKUP_UNSET),
  750. 'S_SELECT_NAME' => 'available['.$hookup_date['date_id'].']',
  751. 'S_IS_ACTIVE' => $hookup_date['date_id'] == $topic_data['hookup_active_date'],
  752. ));
  753. }
  754. }
  755. }
  756. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement