/** * Like a post by first adding an entry into the likes table * and then updating the like counter in the post table. * * @param int @post_id The post to be edited. * * @return int @likes_count The new likes count. */ public function like($post_id) { // Insert into likes table. $sql_ary[] = array('post_id' => $post_id, 'user_id' => $this->user->data['user_id']); $this->db->sql_multi_insert($this->table_prefix . 'likes', $sql_ary); $likes_count = $this->inc_likes_count($post_id); return $likes_count; }
/** * Flushes the buffer content to the DB and clears the buffer. * * @return bool True when some data was flushed to the database. * False otherwise. */ public function flush() { if (!empty($this->buffer)) { $this->db->sql_multi_insert($this->table_name, $this->buffer); $this->buffer = array(); return true; } return false; }
/** * Insert page link location data for a page * * @param int $page_id Page identifier * @param array $link_ids Page link location identifiers * @return page_interface $this object for chaining calls * @throws \phpbb\pages\exception\out_of_bounds * @access public */ public function insert_page_links($page_id, $link_ids) { // First remove any existing page link data for this page $this->remove_page_links($page_id); $sql_ary = array(); foreach ($link_ids as $link_id) { $sql_ary[] = array('page_id' => (int) $page_id, 'page_link_id' => (int) $link_id); } if (sizeof($sql_ary)) { // Insert the new page link data for this page $this->db->sql_multi_insert($this->pages_pages_links_table, $sql_ary); } return $this; }
public function setStartAssets($user_id, $country) { $sql = 'SELECT id FROM ' . $this->container->getParameter('tables.consim.assets') . ' WHERE type_id = ' . self::CURRENCY_TYPE . ' or type_id = ' . self::BOND_TYPE; $result = $this->db->sql_query($sql); $insert = array(); while ($row = $this->db->sql_fetchrow($result)) { $value = 0; //set start value for country of birth if ($row['id'] == 1 && $country == 'bak' || $row['id'] == 2 && $country == 'sur' || $row['id'] == 3 && $country == 'frt') { $value = 50; } $insert[] = array('user_id' => (int) $user_id, 'asset_id' => (int) $row['id'], 'value' => $value); /**$this->container->get('consim.core.entity.inventory_item') ->insert($user_id, $row['id'], $value);*/ } $this->db->sql_freeresult($result); $this->db->sql_multi_insert($this->container->getParameter('tables.consim.users_assets'), $insert); }
/** * Finds whether the given tags already exist and if not creates them in the db. */ private function create_missing_tags($tags) { // we will get all existing tags of $tags // and then substract these from $tags // result contains the tags that needs to be created // to_create = $tags - exting // ensure that there isn't a tag twice in the array $tags = array_unique($tags); $existing_tags = $this->get_existing_tags($tags); // find all tags that are not in $existing_tags and add them to $sql_ary_new_tags $sql_ary_new_tags = array(); foreach ($tags as $tag) { if (!$this->in_array_r($tag, $existing_tags)) { // tag needs to be created $sql_ary_new_tags[] = array('tag' => $tag, 'tag_lowercase' => utf8_strtolower($tag)); } } // create the new tags $this->db->sql_multi_insert($this->table_prefix . tables::TAGS, $sql_ary_new_tags); }
/** * Cache moderators. Called whenever permissions are changed * via admin_permissions. Changes of usernames and group names * must be carried through for the moderators table. * * @param \phpbb\db\driver\driver_interface $db Database connection * @param \phpbb\cache\driver\driver_interface Cache driver * @param \phpbb\auth\auth $auth Authentication object * @return null */ function phpbb_cache_moderators($db, $cache, $auth) { // Remove cached sql results $cache->destroy('sql', MODERATOR_CACHE_TABLE); // Clear table switch ($db->get_sql_layer()) { case 'sqlite': case 'sqlite3': $db->sql_query('DELETE FROM ' . MODERATOR_CACHE_TABLE); break; default: $db->sql_query('TRUNCATE TABLE ' . MODERATOR_CACHE_TABLE); break; } // We add moderators who have forum moderator permissions without an explicit ACL_NEVER setting $sql_ary = array(); // Grab all users having moderative options... $hold_ary = $auth->acl_user_raw_data(false, 'm_%', false); // Add users? if (sizeof($hold_ary)) { // At least one moderative option warrants a display $ug_id_ary = array_keys($hold_ary); // Remove users who have group memberships with DENY moderator permissions $sql_ary_deny = array('SELECT' => 'a.forum_id, ug.user_id, g.group_id', 'FROM' => array(ACL_OPTIONS_TABLE => 'o', USER_GROUP_TABLE => 'ug', GROUPS_TABLE => 'g', ACL_GROUPS_TABLE => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(ACL_ROLES_DATA_TABLE => 'r'), 'ON' => 'a.auth_role_id = r.role_id')), 'WHERE' => '(o.auth_option_id = a.auth_option_id OR o.auth_option_id = r.auth_option_id) AND ((a.auth_setting = ' . ACL_NEVER . ' AND r.auth_setting IS NULL) OR r.auth_setting = ' . ACL_NEVER . ') AND a.group_id = ug.group_id AND g.group_id = ug.group_id AND NOT (ug.group_leader = 1 AND g.group_skip_auth = 1) AND ' . $db->sql_in_set('ug.user_id', $ug_id_ary) . "\n\t\t\t\tAND ug.user_pending = 0\n\t\t\t\tAND o.auth_option " . $db->sql_like_expression('m_' . $db->get_any_char())); $sql = $db->sql_build_query('SELECT', $sql_ary_deny); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if (isset($hold_ary[$row['user_id']][$row['forum_id']])) { unset($hold_ary[$row['user_id']][$row['forum_id']]); } } $db->sql_freeresult($result); if (sizeof($hold_ary)) { // Get usernames... $sql = 'SELECT user_id, username FROM ' . USERS_TABLE . ' WHERE ' . $db->sql_in_set('user_id', array_keys($hold_ary)); $result = $db->sql_query($sql); $usernames_ary = array(); while ($row = $db->sql_fetchrow($result)) { $usernames_ary[$row['user_id']] = $row['username']; } $db->sql_freeresult($result); foreach ($hold_ary as $user_id => $forum_id_ary) { // Do not continue if user does not exist if (!isset($usernames_ary[$user_id])) { continue; } foreach ($forum_id_ary as $forum_id => $auth_ary) { $sql_ary[] = array('forum_id' => (int) $forum_id, 'user_id' => (int) $user_id, 'username' => (string) $usernames_ary[$user_id], 'group_id' => 0, 'group_name' => ''); } } } } // Now to the groups... $hold_ary = $auth->acl_group_raw_data(false, 'm_%', false); if (sizeof($hold_ary)) { $ug_id_ary = array_keys($hold_ary); // Make sure not hidden or special groups are involved... $sql = 'SELECT group_name, group_id, group_type FROM ' . GROUPS_TABLE . ' WHERE ' . $db->sql_in_set('group_id', $ug_id_ary); $result = $db->sql_query($sql); $groupnames_ary = array(); while ($row = $db->sql_fetchrow($result)) { if ($row['group_type'] == GROUP_HIDDEN || $row['group_type'] == GROUP_SPECIAL) { unset($hold_ary[$row['group_id']]); } $groupnames_ary[$row['group_id']] = $row['group_name']; } $db->sql_freeresult($result); foreach ($hold_ary as $group_id => $forum_id_ary) { // If there is no group, we do not assign it... if (!isset($groupnames_ary[$group_id])) { continue; } foreach ($forum_id_ary as $forum_id => $auth_ary) { $flag = false; foreach ($auth_ary as $auth_option => $setting) { // Make sure at least one ACL_YES option is set... if ($setting == ACL_YES) { $flag = true; break; } } if (!$flag) { continue; } $sql_ary[] = array('forum_id' => (int) $forum_id, 'user_id' => 0, 'username' => '', 'group_id' => (int) $group_id, 'group_name' => (string) $groupnames_ary[$group_id]); } } } $db->sql_multi_insert(MODERATOR_CACHE_TABLE, $sql_ary); }
/** * Updates wordlist and wordmatch tables when a message is posted or changed * * @param string $mode Contains the post mode: edit, post, reply, quote * @param int $post_id The id of the post which is modified/created * @param string &$message New or updated post content * @param string &$subject New or updated post subject * @param int $poster_id Post author's user id * @param int $forum_id The id of the forum in which the post is located */ public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id) { if (!$this->config['fulltext_native_load_upd']) { /** * The search indexer is disabled, return */ return; } // Split old and new post/subject to obtain array of 'words' $split_text = $this->split_message($message); $split_title = $this->split_message($subject); $cur_words = array('post' => array(), 'title' => array()); $words = array(); if ($mode == 'edit') { $words['add']['post'] = array(); $words['add']['title'] = array(); $words['del']['post'] = array(); $words['del']['title'] = array(); $sql = 'SELECT w.word_id, w.word_text, m.title_match FROM ' . SEARCH_WORDLIST_TABLE . ' w, ' . SEARCH_WORDMATCH_TABLE . " m WHERE m.post_id = $post_id AND w.word_id = m.word_id"; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $which = ($row['title_match']) ? 'title' : 'post'; $cur_words[$which][$row['word_text']] = $row['word_id']; } $this->db->sql_freeresult($result); $words['add']['post'] = array_diff($split_text, array_keys($cur_words['post'])); $words['add']['title'] = array_diff($split_title, array_keys($cur_words['title'])); $words['del']['post'] = array_diff(array_keys($cur_words['post']), $split_text); $words['del']['title'] = array_diff(array_keys($cur_words['title']), $split_title); } else { $words['add']['post'] = $split_text; $words['add']['title'] = $split_title; $words['del']['post'] = array(); $words['del']['title'] = array(); } unset($split_text); unset($split_title); // Get unique words from the above arrays $unique_add_words = array_unique(array_merge($words['add']['post'], $words['add']['title'])); // We now have unique arrays of all words to be added and removed and // individual arrays of added and removed words for text and title. What // we need to do now is add the new words (if they don't already exist) // and then add (or remove) matches between the words and this post if (sizeof($unique_add_words)) { $sql = 'SELECT word_id, word_text FROM ' . SEARCH_WORDLIST_TABLE . ' WHERE ' . $this->db->sql_in_set('word_text', $unique_add_words); $result = $this->db->sql_query($sql); $word_ids = array(); while ($row = $this->db->sql_fetchrow($result)) { $word_ids[$row['word_text']] = $row['word_id']; } $this->db->sql_freeresult($result); $new_words = array_diff($unique_add_words, array_keys($word_ids)); $this->db->sql_transaction('begin'); if (sizeof($new_words)) { $sql_ary = array(); foreach ($new_words as $word) { $sql_ary[] = array('word_text' => (string) $word, 'word_count' => 0); } $this->db->sql_return_on_error(true); $this->db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary); $this->db->sql_return_on_error(false); } unset($new_words, $sql_ary); } else { $this->db->sql_transaction('begin'); } // now update the search match table, remove links to removed words and add links to new words foreach ($words['del'] as $word_in => $word_ary) { $title_match = ($word_in == 'title') ? 1 : 0; if (sizeof($word_ary)) { $sql_in = array(); foreach ($word_ary as $word) { $sql_in[] = $cur_words[$word_in][$word]; } $sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . ' AND post_id = ' . intval($post_id) . " AND title_match = $title_match"; $this->db->sql_query($sql); $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' SET word_count = word_count - 1 WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . ' AND word_count > 0'; $this->db->sql_query($sql); unset($sql_in); } } $this->db->sql_return_on_error(true); foreach ($words['add'] as $word_in => $word_ary) { $title_match = ($word_in == 'title') ? 1 : 0; if (sizeof($word_ary)) { $sql = 'INSERT INTO ' . SEARCH_WORDMATCH_TABLE . ' (post_id, word_id, title_match) SELECT ' . (int) $post_id . ', word_id, ' . (int) $title_match . ' FROM ' . SEARCH_WORDLIST_TABLE . ' WHERE ' . $this->db->sql_in_set('word_text', $word_ary); $this->db->sql_query($sql); $sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' SET word_count = word_count + 1 WHERE ' . $this->db->sql_in_set('word_text', $word_ary); $this->db->sql_query($sql); } } $this->db->sql_return_on_error(false); $this->db->sql_transaction('commit'); // destroy cached search results containing any of the words removed or added $this->destroy_cache(array_unique(array_merge($words['add']['post'], $words['add']['title'], $words['del']['post'], $words['del']['title'])), array($poster_id)); unset($unique_add_words); unset($words); unset($cur_words); }
function main($checked_user) { // Get all values $sql = 'SELECT * FROM ' . $this->points_values_table; $result = $this->db->sql_query($sql); $points_values = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); // Get all point config names and config values $sql = 'SELECT config_name, config_value FROM ' . $this->points_config_table; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $points_config[$row['config_name']] = $row['config_value']; } $this->db->sql_freeresult($result); // Set some variables $start = $this->request->variable('start', 0); $number = $points_values['number_show_per_page']; add_form_key('lottery_tickets'); // Check, if lottery is enabled if (!$points_config['lottery_enable']) { $message = $this->user->lang['LOTTERY_DISABLED'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller') . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } // Check, if user is allowed to use the lottery if (!$this->auth->acl_get('u_use_lottery')) { $message = $this->user->lang['NOT_AUTHORISED'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller') . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } // Add part to bar $this->template->assign_block_vars('navlinks', array('U_VIEW_FORUM' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')), 'FORUM_NAME' => $points_values['lottery_name'])); // Add lottery base amount in description $this->template->assign_vars(array('L_LOTTERY_BASE_AMOUNT' => sprintf($this->user->lang['LOTTERY_DESCRIPTION'], sprintf($this->functions_points->number_format_points($points_values['lottery_base_amount'])), $this->config['points_name']))); // Recheck, if lottery was run, for those boards only having one user per day and which don't call the index page first if ($points_values['lottery_draw_period'] != 0 && time() > $points_values['lottery_last_draw_time'] + $points_values['lottery_draw_period']) { $this->functions_points->run_lottery(); } // Check, if user has purchased tickets if ($this->request->variable('purchase_ticket', false) && $this->user->data['user_id'] != ANONYMOUS) { if (!check_form_key('lottery_tickets')) { trigger_error('FORM_INVALID'); } // How many tickets have been bought? $total_tickets_bought = $this->request->variable('total_tickets', 0); // Check, if user already bought tickets $sql_array = array('SELECT' => 'COUNT(ticket_id) AS number_of_tickets', 'FROM' => array($this->points_lottery_tickets_table => 't'), 'WHERE' => 'user_id = ' . (int) $this->user->data['user_id']); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $number_tickets = $this->db->sql_fetchfield('number_of_tickets'); $this->db->sql_freeresult($result); // Check, if the user tries to buy more tickets than allowed if ($total_tickets_bought > $points_values['lottery_max_tickets']) { $message = sprintf($this->user->lang['LOTTERY_MAX_TICKETS_REACH'], $points_values['lottery_max_tickets']) . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } // Check in user try to buy negative tickets if ($total_tickets_bought <= 0) { $message = $this->user->lang['LOTTERY_NEGATIVE_TICKETS'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } // Check, if the already bought tickets and the new request are higher than the max set number of tickets if ($number_tickets + $total_tickets_bought > $points_values['lottery_max_tickets']) { $message = sprintf($this->user->lang['LOTTERY_MAX_TICKETS_LEFT'], $points_values['lottery_max_tickets'] - $number_tickets) . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } // Check, if the user sent an empty value if (!$total_tickets_bought) { $message = $this->user->lang['LOTTERY_INVALID_INPUT'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } // Check. if lottery is enabled if ($points_config['lottery_enable'] != 0 && $points_values['lottery_ticket_cost'] != 0) { // Grab users total cash $sql_array = array('SELECT' => '*', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'user_id = ' . (int) $this->user->data['user_id']); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $purchaser = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); // Check, if the user has enough cash to buy tickets if ($points_values['lottery_ticket_cost'] * $total_tickets_bought > $purchaser['user_points']) { $message = $this->user->lang['LOTTERY_LACK_FUNDS'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } } // Loop through total purchased tickets and create insert array for ($i = 0, $total_tickets_bought; $i < $total_tickets_bought; $i++) { $sql_insert_ary[] = array('user_id' => $this->user->data['user_id']); } $this->db->sql_multi_insert($this->points_lottery_tickets_table, $sql_insert_ary); // Check again, if lottery is enabled if ($points_config['lottery_enable'] != 0) { // Deduct cost $viewer_cash = $purchaser['user_points'] - $points_values['lottery_ticket_cost'] * $total_tickets_bought; $this->functions_points->set_points($this->user->data['user_id'], $viewer_cash); // Update jackpot $this->functions_points->set_points_values('lottery_jackpot', $points_values['lottery_jackpot'] + $points_values['lottery_ticket_cost'] * $total_tickets_bought); } $message = $this->user->lang['LOTTERY_TICKET_PURCHASED'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); $this->template->assign_vars(array('U_ACTION' => $this->u_action)); } // Display main page $history_mode = $this->request->variable('history', ''); if ($history_mode) { // If no one has ever won, why bother doing anything else? if ($points_values['points_winners_total'] = 0) { $message = $this->user->lang['LOTTERY_NO_WINNERS'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } $total_wins = $points_values['points_winners_total']; // Check, if no entries returned, only self search would turn up empty at this point if ($history_mode == 'ego') { $sql_array = array('SELECT' => 'COUNT(id) AS viewer_history', 'FROM' => array($this->points_lottery_history_table => 'h'), 'WHERE' => 'user_id = ' . (int) $this->user->data['user_id']); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $total_wins = (int) $this->db->sql_fetchfield('viewer_history'); $this->db->sql_freeresult($result); if ($total_wins == 0) { $message = $this->user->lang['LOTTERY_NEVER_WON'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } $this->template->assign_vars(array('U_VIEW_HISTORY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery', 'history' => 'all')), 'U_TRANSFER_USER' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'transfer_user')), 'U_LOGS' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'logs')), 'U_LOTTERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')), 'U_BANK' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')), 'U_ROBBERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')))); } // Check, if user is viewing all or own entries if ($history_mode == 'all') { $sql_array = array('SELECT' => 'COUNT(id) AS total_entries', 'FROM' => array($this->points_lottery_history_table => 'h')); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $total_entries = (int) $this->db->sql_fetchfield('total_entries'); $this->db->sql_freeresult($result); $sql_array = array('SELECT' => 'h.*, u.*', 'FROM' => array($this->points_lottery_history_table => 'h'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'h.user_id = u.user_id')), 'ORDER_BY' => 'time DESC'); } else { $sql_array = array('SELECT' => 'COUNT(id) AS total_entries', 'FROM' => array($this->points_lottery_history_table => 'h'), 'WHERE' => 'user_id = ' . (int) $this->user->data['user_id']); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $total_entries = (int) $this->db->sql_fetchfield('total_entries'); $this->db->sql_freeresult($result); $sql_array = array('SELECT' => 'h.*, u.*', 'FROM' => array($this->points_lottery_history_table => 'h'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'h.user_id = u.user_id')), 'WHERE' => 'h.user_id = ' . (int) $this->user->data['user_id'], 'ORDER_BY' => 'time DESC'); } $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query_limit($sql, $number, $start); $row_color = $start; while ($row = $this->db->sql_fetchrow($result)) { $row_color++; // Check, if winner is user if ($row['user_id'] != 0) { $history_member = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']); } else { $history_member = $this->user->lang['LOTTERY_NO_WINNER']; } $this->template->assign_block_vars('history_row', array('NUMBER' => $row_color, 'U_WINNER_PROFILE' => $history_member, 'WINNER_PROFILE' => $history_member, 'USERNAME' => $row['username'], 'WINNINGS' => sprintf($this->functions_points->number_format_points($row['amount'])), 'DATE' => $this->user->format_date($row['time']), 'ROW_COLOR' => $row_color)); $this->template->assign_vars(array('U_VIEW_HISTORY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery', 'history' => 'all')), 'U_VIEW_SELF_HISTORY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery', 'history' => 'ego')), 'U_INFO' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'info')), 'U_TRANSFER_USER' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'transfer_user')), 'U_LOGS' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'logs')), 'U_LOTTERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')), 'U_BANK' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')), 'U_ROBBERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')))); } //Start pagination $this->pagination->generate_template_pagination($this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery', 'history' => $history_mode)), 'pagination', 'start', $total_entries, $number, $start); // Viewing a history page $this->template->assign_vars(array('CASH_NAME' => $this->config['points_name'], 'PAGINATION' => $this->user->lang('POINTS_LOG_COUNT', $total_entries), 'LOTTERY_NAME' => $points_values['lottery_name'], 'BANK_NAME' => $points_values['bank_name'], 'S_VIEW_HISTORY' => true, 'U_BACK_TO_LOTTERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')), 'U_VIEW_SELF_HISTORY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery', 'history' => 'ego')), 'U_TRANSFER_USER' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'transfer_user')), 'U_LOGS' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'logs')), 'U_LOTTERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')), 'U_BANK' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')), 'U_ROBBERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')))); } else { // Show main lottery page $viewer_total_tickets = ''; if ($this->user->data['user_id'] != ANONYMOUS) { //Select total tickets viewer owns $sql_array = array('SELECT' => 'COUNT(ticket_id) AS num_tickets', 'FROM' => array($this->points_lottery_tickets_table => 'h'), 'WHERE' => 'user_id = ' . (int) $this->user->data['user_id']); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $viewer_total_tickets = (int) $this->db->sql_fetchfield('num_tickets'); $this->db->sql_freeresult($result); } // User color selection $sql_array = array('SELECT' => 'user_id, username, user_colour', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'user_id = ' . (int) $points_values['lottery_prev_winner_id']); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); if ($row == null) { $username_colored = $this->user->lang['LOTTERY_NO_WINNER']; } else { $username_colored = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']); } // Check, if previous winner is a user if ($points_values['lottery_prev_winner_id'] != 0) { $link_member = append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", "mode=viewprofile&u=" . $points_values['lottery_prev_winner_id']); } else { $link_member = ''; } // Select the total number of tickets $sql_array = array('SELECT' => 'COUNT(ticket_id) AS no_of_tickets', 'FROM' => array($this->points_lottery_tickets_table => 't')); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $no_of_tickets = $row['no_of_tickets']; $this->db->sql_freeresult($result); // Select the total number of players $sql_array = array('SELECT' => 'user_id', 'FROM' => array($this->points_lottery_tickets_table => 't')); $sql = $this->db->sql_build_query('SELECT_DISTINCT', $sql_array); $result = $this->db->sql_query($sql); $no_of_players = 0; while ($row = $this->db->sql_fetchrow($result)) { $no_of_players += 1; } $this->db->sql_freeresult($result); $this->template->assign_vars(array('JACKPOT' => sprintf($this->functions_points->number_format_points($points_values['lottery_jackpot']), $this->config['points_name']), 'POINTS_NAME' => $this->config['points_name'], 'TICKET_COST' => sprintf($this->functions_points->number_format_points($points_values['lottery_ticket_cost'])), 'PREVIOUS_WINNER' => $username_colored, 'NEXT_DRAWING' => $this->user->format_date($points_values['lottery_last_draw_time'] + $points_values['lottery_draw_period'], false, true), 'LOTTERY_NAME' => $points_values['lottery_name'], 'BANK_NAME' => $points_values['bank_name'], 'VIEWER_TICKETS_TOTAL' => $viewer_total_tickets, 'LOTTERY_TICKETS' => $no_of_tickets, 'LOTTERY_PLAYERS' => $no_of_players, 'MAX_TICKETS' => $points_values['lottery_max_tickets'], 'S_PURCHASE_SINGLE' => $viewer_total_tickets == 0 && $points_config['lottery_multi_ticket_enable'] == 0 && $points_config['lottery_enable'] == 1 ? true : false, 'S_PURCHASE_MULTI' => $viewer_total_tickets < $points_values['lottery_max_tickets'] && $points_config['lottery_multi_ticket_enable'] == 1 && $points_config['lottery_enable'] == 1 ? true : false, 'S_MULTI_TICKETS' => $points_config['lottery_multi_ticket_enable'] == 1 ? true : false, 'S_LOTTERY_ENABLE' => $points_config['lottery_enable'] == 1 ? true : false, 'S_DRAWING_ENABLED' => $points_values['lottery_draw_period'] ? true : false, 'U_PREVIOUS_WINNER' => $link_member, 'U_VIEW_HISTORY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery', 'history' => 'all')), 'U_VIEW_SELF_HISTORY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery', 'history' => 'ego')), 'U_TRANSFER_USER' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'transfer_user')), 'U_LOGS' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'logs')), 'U_LOTTERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')), 'U_BANK' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')), 'U_ROBBERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')), 'U_INFO' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'info')), 'U_USE_TRANSFER' => $this->auth->acl_get('u_use_transfer'), 'U_USE_LOGS' => $this->auth->acl_get('u_use_logs'), 'U_USE_LOTTERY' => $this->auth->acl_get('u_use_lottery'), 'U_USE_BANK' => $this->auth->acl_get('u_use_bank'), 'U_USE_ROBBERY' => $this->auth->acl_get('u_use_robbery'), 'USER_POINTS' => sprintf($this->functions_points->number_format_points($checked_user['user_points'])))); } // Generate the page header page_header($points_values['lottery_name']); // Generate the page template $this->template->set_filenames(array('body' => 'points/points_lottery.html')); page_footer(); }
public function activedate_set(\Symfony\Component\EventDispatcher\Event $event) { $topic_data = $event['topic_data']; $first_post = intval($topic_data['topic_first_post_id']); if (0 == $event['set_active']) { $sql = 'DELETE FROM ' . $this->cal_table . ' WHERE post_id = ' . $first_post; $this->db->sql_query($sql); $sql = 'DELETE FROM ' . $this->cal_participants_table . ' WHERE post_id = ' . $first_post; $this->db->sql_query($sql); } else { // Copy Date & entries if ($this->hookup->topic_id != $event['topic_id']) { if ($this->hookup->topic_id != 0) { $this->hookup = new hookup(); } $this->hookup->load_hookup($event['topic_id']); } $set_date = isset($this->hookup->hookup_dates[$event['set_active']]) ? isset($this->hookup->hookup_dates[$event['set_active']]['date_time']) ? $this->hookup->hookup_dates[$event['set_active']]['date_time'] : 0 : 0; if (!$set_date) { // We can't enter a text without date return; } // Quick & dirty: The event $sql = 'SELECT id FROM ' . $this->cal_event_table . ' WHERE event = \'hookup\''; $result = $this->db->sql_query_limit($sql, 1); $event_id = $this->db->sql_fetchfield('id'); $this->db->sql_freeresult($result); if (!$event_id) { $sql_ary = array('event' => 'hookup', 'participants' => 1); $sql = 'INSERT INTO ' . $this->cal_event_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); $event_id = $this->db->sql_nextid(); } $sql = 'SELECT count(*) as cnt FROM ' . $this->cal_table . ' WHERE post_id = ' . $topic_data['topic_first_post_id']; $result = $this->db->sql_query($sql); $cnt = $this->db->sql_fetchfield('cnt'); $this->db->sql_freeresult($result); $sql_ary = array('post_id' => $topic_data['topic_first_post_id'], 'event_id' => $event_id, 'event_name' => $topic_data['topic_title'], 'date_from' => date('Y-m-d', $set_date)); if ($cnt) { $sql = 'UPDATE ' . $this->cal_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE post_id = ' . $topic_data['topic_first_post_id']; } else { $sql = 'INSERT INTO ' . $this->cal_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); } $this->db->sql_query($sql); // Participants $part_ary = $this->part_ary; // Already entered? $entered_users = array(); if ($cnt) { $sql = 'SELECT user_id FROM ' . $this->cal_participants_table . ' WHERE ' . $this->db->sql_in_set('user_id', array_keys($this->hookup->hookup_users)); $result = $this->db->sql_query($sql); $entered_users = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); } $sql_ary = array(); foreach ($this->hookup->hookup_users as $user_id => $userdata) { // Did the user enter anything for this date? if (!isset($this->hookup->hookup_availables[$user_id][$event['set_active']]) || $this->hookup->hookup_availables[$user_id][$event['set_active']] == hookup::HOOKUP_UNSET) { continue; } if (in_array($user_id, $entered_users)) { // Update instead: $sql = 'UPDATE ' . $this->cal_participants_table . ' SET ' . $this->db->sql_build_array('UPDATE', array('participants' => $part_ary[$this->hookup->hookup_availables[$user_id][$event['set_active']]], 'comment' => $userdata['comment'], 'date' => date('Y-m-d-H-i'))) . " WHERE user_id = {$user_id} AND post_id = {$topic_data['topic_first_post_id']}"; $this->db->sql_query($sql); continue; } $sql_ary[] = array('post_id' => $topic_data['topic_first_post_id'], 'user_id' => $user_id, 'participants' => $part_ary[$this->hookup->hookup_availables[$user_id][$event['set_active']]], 'comments' => $userdata['comment'], 'date' => date('Y-m-d-H-i')); } $this->db->sql_multi_insert($this->cal_participants_table, $sql_ary); } }
/** * Permission Set * * Allows you to set permissions for a certain group/role * * @param string $name The name of the role/group * @param string|array $auth_option The auth_option or array of * auth_options you would like to set * @param string $type The type (role|group) * @param bool $has_permission True if you want to give them permission, * false if you want to deny them permission * @return null * @throws \phpbb\db\migration\exception */ public function permission_set($name, $auth_option, $type = 'role', $has_permission = true) { if (!is_array($auth_option)) { $auth_option = array($auth_option); } $new_auth = array(); $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $new_auth[] = (int) $row['auth_option_id']; } $this->db->sql_freeresult($result); if (empty($new_auth)) { return; } $current_auth = array(); $type = (string) $type; // Prevent PHP bug. switch ($type) { case 'role': $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . "\n\t\t\t\t\tWHERE role_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); $role_id = (int) $this->db->sql_fetchfield('role_id'); if (!$role_id) { throw new \phpbb\db\migration\exception('ROLE_NOT_EXIST', $name); } $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE role_id = ' . $role_id; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $current_auth[$row['auth_option_id']] = $row['auth_setting']; } $this->db->sql_freeresult($result); break; case 'group': $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . "\n\t\t\t\t\tWHERE group_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); $group_id = (int) $this->db->sql_fetchfield('group_id'); if (!$group_id) { throw new \phpbb\db\migration\exception('GROUP_NOT_EXIST', $name); } // If the group has a role set for them we will add the requested permissions to that role. $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' WHERE group_id = ' . $group_id . ' AND auth_role_id <> 0 AND forum_id = 0'; $this->db->sql_query($sql); $role_id = (int) $this->db->sql_fetchfield('auth_role_id'); if ($role_id) { $sql = 'SELECT role_name, role_type FROM ' . ACL_ROLES_TABLE . ' WHERE role_id = ' . $role_id; $this->db->sql_query($sql); $role_data = $this->db->sql_fetchrow(); $role_name = $role_data['role_name']; $role_type = $role_data['role_type']; // Filter new auth options to match the role type: a_ | f_ | m_ | u_ // Set new auth options to the role only if options matching the role type were found $auth_option = array_filter($auth_option, function ($option) use($role_type) { return strpos($option, $role_type) === 0; }); if (sizeof($auth_option)) { return $this->permission_set($role_name, $auth_option, 'role', $has_permission); } } $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' WHERE group_id = ' . $group_id; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $current_auth[$row['auth_option_id']] = $row['auth_setting']; } $this->db->sql_freeresult($result); break; } $sql_ary = array(); switch ($type) { case 'role': foreach ($new_auth as $auth_option_id) { if (!isset($current_auth[$auth_option_id])) { $sql_ary[] = array('role_id' => $role_id, 'auth_option_id' => $auth_option_id, 'auth_setting' => $has_permission); } } $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); break; case 'group': foreach ($new_auth as $auth_option_id) { if (!isset($current_auth[$auth_option_id])) { $sql_ary[] = array('group_id' => $group_id, 'auth_option_id' => $auth_option_id, 'auth_setting' => $has_permission); } } $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary); break; } $this->auth->acl_clear_prefetch(); }