예제 #1
0
 /**
  * Synchronizes new participant entries from calendar to hookup
  *
  * @param \Symfony\Component\EventDispatcher\Event $event
  * @throws \Exception
  */
 public function sync_participant_calendar(\Symfony\Component\EventDispatcher\Event $event)
 {
     $sql_data = $event['sql_ary'];
     $post_id = (int) $sql_data['POST_ID'];
     // Retrieve Hookup for that post:
     $sql = 'SELECT p.topic_id, t.forum_id, t.topic_first_post_id FROM ' . POSTS_TABLE . ' p LEFT JOIN ' . TOPICS_TABLE . ' t ON p.topic_id = t.topic_id WHERE post_id = ' . $post_id;
     $result = $this->db->sql_query($sql);
     $row = $this->db->sql_fetchrow($result);
     $this->db->sql_freeresult($result);
     if (!$row || !$this->hookup->load_hookup($row['topic_id'])) {
         throw new \Exception('Loading topic or hookup failed. Post ID: ' . $post_id);
     }
     if (!$this->hookup->hookup_enabled || $post_id != $row['topic_first_post_id']) {
         // Don't sync if the hookup is disabled or the event is not linked to the first post of the topic
         return;
     }
     // Do not enter, if the user is not permitted to use the hookup
     // Ignore permissions, if called for user_id different from current user
     if ($event['user_id'] == $this->user->data['user_id'] && !$this->auth->acl_get('f_hookup', $row['forum_id'])) {
         return;
     }
     // Don't sync if no activedate is set
     if (!$this->hookup->hookup_active_date) {
         return;
     }
     $this->hookup->add_user($sql_data['USER_ID'], $sql_data['COMMENTS']);
     $this->hookup->set_user_date($sql_data['USER_ID'], $this->hookup->hookup_active_date, $this->part_ary_inv[$sql_data['PARTICIPANTS']]);
     $this->hookup->submit(false);
 }
예제 #2
0
    /**
     * Process adding hookup users
     *
     * @param \phpbb\event\data $event
     * @param bool $is_owner
     */
    protected function process_add_user($event, $is_owner)
    {
        $add_users = $this->request->variable('usernames', '', true);
        $add_groups = $this->request->variable('add_groups', array(0));
        if (empty($add_users) && empty($add_groups)) {
            return array();
        }
        if (!$is_owner) {
            return array($this->user->lang('NOT_AUTH_HOOKUP'));
        }
        $hookup_errors = array();
        // Add users
        if (!empty($add_users)) {
            // Cleanup Usernames
            $usernames = array_unique(explode("\n", $add_users));
            $usernames = array_map('utf8_clean_string', $usernames);
            //TODO: Prevent anonymous and bots
            $sql = 'SELECT user_id, username, user_type, user_permissions, user_lang, user_email, user_jabber, user_notify_type
				FROM ' . USERS_TABLE . '
				WHERE ' . $this->db->sql_in_set('username_clean', $usernames);
            $result = $this->db->sql_query($sql);
            $new_users = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $new_users[$row['user_id']] = $row;
            }
            $this->db->sql_freeresult($result);
            $userids_to_add = array_diff(array_keys($new_users), array_keys($this->hookup->hookup_users));
            $userids_already_added = array_intersect(array_keys($new_users), array_keys($this->hookup->hookup_users));
        }
        // Add groups
        if (!empty($add_groups)) {
            $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
				FROM ' . USER_GROUP_TABLE . ' ug
				JOIN ' . USERS_TABLE . ' u
					ON (u.user_id = ug.user_id)
				WHERE ' . $this->db->sql_in_set('ug.group_id', $add_groups) . '
					AND ug.user_pending = 0';
            $result = $this->db->sql_query($sql);
            $new_users = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $new_users[$row['user_id']] = $row;
            }
            $this->db->sql_freeresult($result);
            $userids_to_add = array_diff(array_keys($new_users), array_keys($this->hookup->hookup_users));
        }
        // Add & notify
        //now that we have the user_ids and data, add the users
        if (isset($userids_to_add) && count($userids_to_add) > 0) {
            //check if users have read permission
            $user_auth = new \phpbb\auth\auth();
            foreach ($userids_to_add as $key => $user_id) {
                $user_auth->acl($new_users[$user_id]);
                if (!$user_auth->acl_get('f_read', $event['forum_id']) || !$user_auth->acl_get('f_hookup', $event['forum_id'])) {
                    $hookup_errors[] = sprintf($this->user->lang['USER_CANNOT_READ_FORUM'], $new_users[$user_id]['username']);
                    unset($userids_to_add[$key]);
                }
            }
            //insert users into database
            foreach ($userids_to_add as $user_id) {
                //no need to notify the user about new dates when he hasn't visited the
                //hookup yet and thus not even entered his available info for the first dates
                $this->hookup->add_user($user_id, '', 1);
            }
            $this->hookup->submit(false);
            //notify new users about invitation
            if ($this->messenger == null) {
                include_once $this->phpbb_root_path . 'includes/functions_messenger.' . $this->phpEx;
                $this->messenger = new \messenger();
            }
            $messenger = $this->messenger;
            $forum_id = $event['forum_id'];
            $topic_id = $event['topic_id'];
            foreach ($userids_to_add as $user_id) {
                $userdata = $new_users[$user_id];
                $messenger->template('@gn36_hookup/hookup_added', $userdata['user_lang']);
                $messenger->to($userdata['user_email'], $userdata['username']);
                $messenger->im($userdata['user_jabber'], $userdata['username']);
                $messenger->assign_vars(array('USERNAME' => $userdata['username'], 'TOPIC_TITLE' => $event['topic_data']['topic_title'], 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->phpEx}?f={$forum_id}&t={$topic_id}"));
                $messenger->send($userdata['user_notify_type']);
            }
            $messenger->save_queue();
            //add userids to local array
            $userids = array_merge(array_keys($this->hookup->hookup_users), $userids_to_add);
        }
        //generate error messages for users that are already members
        if (isset($userids_already_added) && count($userids_already_added) > 0) {
            foreach ($userids_already_added as $userid) {
                $hookup_errors[] = sprintf($this->user->lang['HOOKUP_USER_EXISTS'], $new_users[$userid]['username']);
            }
        }
        return $hookup_errors;
    }
예제 #3
0
    /**
     * Process adding hookup users
     *
     * @param \phpbb\event\data $event
     * @param bool $is_owner
     */
    protected function process_add_user($event, $is_owner)
    {
        $add_users = $this->request->variable('usernames', '', true);
        $add_groups = $this->request->variable('add_groups', array(0));
        if (empty($add_users) && empty($add_groups)) {
            return array();
        }
        if (!$is_owner) {
            return array($this->user->lang('NOT_AUTH_HOOKUP'));
        }
        $hookup_errors = array();
        // Add users
        if (!empty($add_users)) {
            // Cleanup Usernames
            $usernames = array_unique(explode("\n", $add_users));
            $usernames = array_map('utf8_clean_string', $usernames);
            //TODO: Prevent anonymous and bots
            $sql = 'SELECT user_id, username, user_type, user_permissions, user_lang, user_email, user_jabber, user_notify_type
				FROM ' . USERS_TABLE . '
				WHERE ' . $this->db->sql_in_set('username_clean', $usernames);
            $result = $this->db->sql_query($sql);
            $new_users = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $new_users[$row['user_id']] = $row;
            }
            $this->db->sql_freeresult($result);
            $userids_to_add = array_diff(array_keys($new_users), array_keys($this->hookup->hookup_users));
            $userids_already_added = array_intersect(array_keys($new_users), array_keys($this->hookup->hookup_users));
        }
        // Add groups
        if (!empty($add_groups)) {
            $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
				FROM ' . USER_GROUP_TABLE . ' ug
				JOIN ' . USERS_TABLE . ' u
					ON (u.user_id = ug.user_id)
				WHERE ' . $this->db->sql_in_set('ug.group_id', $add_groups) . '
					AND ug.user_pending = 0';
            $result = $this->db->sql_query($sql);
            $new_users = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $new_users[$row['user_id']] = $row;
            }
            $this->db->sql_freeresult($result);
            $userids_to_add = array_diff(array_keys($new_users), array_keys($this->hookup->hookup_users));
        }
        // Add & notify
        //now that we have the user_ids and data, add the users
        if (isset($userids_to_add) && count($userids_to_add) > 0) {
            //check if users have read permission
            $user_auth = new \phpbb\auth\auth();
            foreach ($userids_to_add as $key => $user_id) {
                $user_auth->acl($new_users[$user_id]);
                if (!$user_auth->acl_get('f_read', $event['forum_id'])) {
                    $hookup_errors[] = sprintf($this->user->lang['USER_CANNOT_READ_FORUM'], $new_users[$user_id]['username']);
                    unset($userids_to_add[$key]);
                } else {
                    if (!$user_auth->acl_get('f_hookup', $event['forum_id'])) {
                        $hookup_errors[] = sprintf($this->user->lang['USER_CANNOT_HOOKUP'], $new_users[$user_id]['username']);
                        unset($userids_to_add[$key]);
                    }
                }
            }
            //insert users into database
            foreach ($userids_to_add as $user_id) {
                //no need to notify the user about new dates when he hasn't visited the
                //hookup yet and thus not even entered his available info for the first dates
                $this->hookup->add_user($user_id, '', 1);
            }
            $this->hookup->submit(false);
            foreach ($userids_to_add as $user_id) {
                // Notification
                $notify_data = array('user_id' => $this->user->data['user_id'], 'invited_user' => $user_id, 'topic_title' => $event['topic_data']['topic_title'], 'topic_id' => $event['topic_id'], 'forum_id' => $event['forum_id']);
                $this->notification_manager->add_notifications('gn36.hookup.notification.type.invited', $notify_data);
                $this->notification_manager->update_notifications('gn36.hookup.notification.type.user_added', $notify_data);
            }
        }
        //generate error messages for users that are already members
        if (isset($userids_already_added) && count($userids_already_added) > 0) {
            foreach ($userids_already_added as $userid) {
                $hookup_errors[] = sprintf($this->user->lang['HOOKUP_USER_EXISTS'], $new_users[$userid]['username']);
            }
        }
        return $hookup_errors;
    }