public function add_page_header_links($event) { if (!empty($this->config['allow_visits_counter'])) { $this->language->add_lang('common', 'dmzx/counter'); $sql = 'SELECT COUNT(*) AS visits_counter FROM ' . $this->visits_counter_table . ' WHERE ' . $this->db->sql_in_set('uvc_ip', $this->user->ip); $result = $this->db->sql_query($sql); $visits_counter = (int) $this->db->sql_fetchfield('visits_counter'); $this->db->sql_freeresult($result); $visits = $this->config['visits_counter']; if ($visits_counter == 0) { $sql_ary = array('uvc_ip' => $this->user->ip, 'uvc_timestamp' => time()); $sql = 'INSERT INTO ' . $this->visits_counter_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); $this->config->increment('visits_counter', 1, true); } else { $sql_ary = array('uvc_timestamp' => time()); $sql = 'UPDATE ' . $this->visits_counter_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE ' . $this->db->sql_in_set('uvc_ip', $this->user->ip); $this->db->sql_query($sql); } $timestamp = time() - 3600 * 24; $sql_ary = array($timestamp); $sql = 'DELETE FROM ' . $this->visits_counter_table . ' WHERE uvc_timestamp < ' . $timestamp; $this->db->sql_query($sql); $sql = 'SELECT COUNT(*) AS num_del FROM ' . $this->visits_counter_table . ' '; $result = $this->db->sql_query($sql); $visitsok = (int) $this->db->sql_fetchfield('num_del'); $this->template->assign_vars(array('UNIQUE_VISITS_COUNTER' => $this->language->lang('UNIQUE_VISITS_COUNTER', $visitsok))); } }
/** * Executes the command cache:purge. * * Purge the cache (including permissions) and increment the asset_version number * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @return null */ protected function execute(InputInterface $input, OutputInterface $output) { $this->config->increment('assets_version', 1); $this->cache->purge(); // Clear permissions $this->auth->acl_clear_prefetch(); phpbb_cache_moderators($this->db, $this->cache, $this->auth); $this->log->add('admin', ANONYMOUS, '', 'LOG_PURGE_CACHE', time(), array()); $output->writeln($this->user->lang('PURGE_CACHE_SUCCESS')); }
/** * Remove post from topic and forum statistics * * @param $data array Contains information from the topics table about given topic * @param &$sql_data array Populated with the SQL changes, may be empty at call time * @return null */ public function remove_post_from_statistic($data, &$sql_data) { if ($data['post_visibility'] == ITEM_APPROVED) { $sql_data[$this->topics_table] = ((!empty($sql_data[$this->topics_table])) ? $sql_data[$this->topics_table] . ', ' : '') . 'topic_posts_approved = topic_posts_approved - 1'; $sql_data[$this->forums_table] = ((!empty($sql_data[$this->forums_table])) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_posts_approved = forum_posts_approved - 1'; if ($data['post_postcount']) { $sql_data[$this->users_table] = ((!empty($sql_data[$this->users_table])) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts - 1'; } $this->config->increment('num_posts', -1, false); } else if ($data['post_visibility'] == ITEM_UNAPPROVED || $data['post_visibility'] == ITEM_REAPPROVE) { $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_unapproved = forum_posts_unapproved - 1'; $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_unapproved = topic_posts_unapproved - 1'; } else if ($data['post_visibility'] == ITEM_DELETED) { $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_softdeleted = forum_posts_softdeleted - 1'; $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_softdeleted = topic_posts_softdeleted - 1'; } }
/** * {@inheritdoc} */ public function run() { $this->language->add_lang('migrator'); if (!isset($this->config['version_update_from'])) { $this->config->set('version_update_from', $this->config['version']); } $original_version = $this->config['version_update_from']; $this->migrator->set_output_handler(new log_wrapper_migrator_output_handler($this->language, new installer_migrator_output_handler($this->iohandler), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem)); $this->migrator->create_migrations_table(); $migrations = $this->extension_manager->get_finder()->core_path('phpbb/db/migration/data/')->extension_directory('/migrations')->get_classes(); $this->migrator->set_migrations($migrations); $migration_step_count = $this->installer_config->get('database_update_migration_steps', -1); if ($migration_step_count < 0) { $migration_step_count = count($this->migrator->get_installable_migrations()) * 2; $this->installer_config->set('database_update_migration_steps', $migration_step_count); } $progress_count = $this->installer_config->get('database_update_count', 0); $restart_progress_bar = $progress_count === 0; // Only "restart" when the update runs for the first time $this->iohandler->set_task_count($migration_step_count, $restart_progress_bar); $this->installer_config->set_task_progress_count($migration_step_count); while (!$this->migrator->finished()) { try { $this->migrator->update(); $progress_count++; $last_run_migration = $this->migrator->get_last_run_migration(); if (isset($last_run_migration['effectively_installed']) && $last_run_migration['effectively_installed']) { // We skipped two step, so increment $progress_count by another one $progress_count++; } else { if ($last_run_migration['task'] === 'process_schema_step' && !$last_run_migration['state']['migration_schema_done'] || $last_run_migration['task'] === 'process_data_step' && !$last_run_migration['state']['migration_data_done']) { // We just run a step that wasn't counted yet so make it count $migration_step_count++; } } $this->iohandler->set_task_count($migration_step_count); $this->installer_config->set_task_progress_count($migration_step_count); $this->iohandler->set_progress('STAGE_UPDATE_DATABASE', $progress_count); } catch (exception $e) { $msg = $e->getParameters(); array_unshift($msg, $e->getMessage()); $this->iohandler->add_error_message($msg); throw new user_interaction_required_exception(); } if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) { $this->installer_config->set('database_update_count', $progress_count); $this->installer_config->set('database_update_migration_steps', $migration_step_count); throw new resource_limit_reached_exception(); } } if ($original_version !== $this->config['version']) { $this->log->add('admin', isset($this->user->data['user_id']) ? $this->user->data['user_id'] : ANONYMOUS, $this->user->ip, 'LOG_UPDATE_DATABASE', false, array($original_version, $this->config['version'])); } $this->iohandler->add_success_message('INLINE_UPDATE_SUCCESSFUL'); $this->config->delete('version_update_from'); $this->cache->purge(); $this->config->increment('assets_version', 1); }
function random_bonus_increment($user_id) { /** * Read out config 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); $bonus_chance = ''; $bonus = false; // Basic value, sorry.. $bonus_value = 0.0; // Basic value // Following numbers are 'times 100' to get rid of commas, as mt_rand doesn't get comma numbers. $bonus_chance = $points_values['points_bonus_chance'] * 100; // The chance percentage for a user to get the bonus $random_number = mt_rand(0, 10000); // The random number we compare to the chance percentage if ($random_number <= $bonus_chance) { $bonus = true; // Check if we want a fixed bonus value or not if ($points_values['points_bonus_min'] == $points_values['points_bonus_max']) { $bonus_value = $points_values['points_bonus_min']; } else { // Create the bonus value, between the set minimum and maximum // Following numbers are 'times 100' to get rid of commas, as mt_rand doesn't get comma numbers. $bonus_random = mt_rand($points_values['points_bonus_min'] * 100, $points_values['points_bonus_max'] * 100) / 100; $bonus_value = round($bonus_random, 0, PHP_ROUND_HALF_UP); } } if ($bonus && $bonus_value) { $this->add_points((int) $user_id, $bonus_value); // Send out notification // Increase our notification sent counter $this->config->increment('points_notification_id', 1); // Store the notification data we will use in an array $data = array('points_notify_id' => (int) $this->config['points_notification_id'], 'points_notify_msg' => sprintf($this->user->lang['NOTIFICATION_RANDOM_BONUS'], $bonus_value, $this->config['points_name']), 'sender' => (int) $this->user->data['user_id'], 'receiver' => (int) $user_id, 'mode' => 'logs'); $this->notification_manager->add_notifications('dmzx.ultimatepoints.notification.type.points', $data); $sql_array = array('SELECT' => 'username', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'user_id = ' . (int) $user_id); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $points_user = $this->db->sql_fetchrow($result); // Add logs $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MOD_POINTS_RANDOM', false, array($points_user['username'])); } }
/** * Send notification to users * * @param int $rule_id The rule identifier * @return null * @access public */ public function send_notification($rule_id) { // Use a confirmation box routine when sending notifications if (confirm_box(true)) { // Increment our notifications sent counter $this->config->increment('boardrules_notification', 1); // Store the notification data we will use in an array $notification_data = array('rule_id' => $rule_id, 'notification_id' => $this->config['boardrules_notification']); // Create the notification $this->notification_manager->add_notifications('phpbb.boardrules.notification.type.boardrules', $notification_data); // Log the notification $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_BOARDRULES_NOTIFY_LOG'); } else { // Request confirmation from the user to send notification to all users // Build a hidden array of the form data confirm_box(false, $this->user->lang('ACP_BOARDRULES_NOTIFY_CONFIRM'), build_hidden_fields(array('action_send_notification' => true, 'rule_id' => $rule_id))); } }
/** * Do not increase the user's post count when copying the topic * * @param object $event The event object * @return null * @access public */ public function set_post_count($event) { $post_mode = $event['post_mode']; $data = $event['data']; if ($this->config['copy_topic_enable'] && $post_mode == 'post' && $data['forum_id'] == $this->config['copy_topic_to_forum']) { if ($this->check_fora()) { $sql_data = $event['sql_data']; // We do not want to increase the user's post count when copying the topic so we remove thr " + 1" from the end of the string $sql_data[$this->table_prefix . 'users']['stat'][0] = substr($sql_data[$this->table_prefix . 'users']['stat'][0], 0, -4); // We need to reduce the total topic & post count unless it is being overridden if (!$this->config['copy_topic_count_override']) { $this->config->increment('num_posts', -1, false); $this->config->increment('num_topics', -1, false); } $event->offsetSet('sql_data', $sql_data); } } }
/** * {@inheritdoc} */ public function run() { $this->language->add_lang('migrator'); if (!isset($this->config['version_update_from'])) { $this->config->set('version_update_from', $this->config['version']); } $original_version = $this->config['version_update_from']; $this->migrator->set_output_handler(new log_wrapper_migrator_output_handler($this->language, new installer_migrator_output_handler($this->iohandler), $this->phpbb_root_path . 'store/migrations_' . time() . '.log', $this->filesystem)); $this->migrator->create_migrations_table(); $migrations = $this->extension_manager->get_finder()->core_path('phpbb/db/migration/data/')->extension_directory('/migrations')->get_classes(); $this->migrator->set_migrations($migrations); $migration_count = count($this->migrator->get_migrations()); $this->iohandler->set_task_count($migration_count, true); $progress_count = $this->installer_config->get('database_update_count', 0); while (!$this->migrator->finished()) { try { $this->migrator->update(); $progress_count++; $this->iohandler->set_progress('STAGE_UPDATE_DATABASE', $progress_count); } catch (exception $e) { $msg = $e->getParameters(); array_unshift($msg, $e->getMessage()); $this->iohandler->add_error_message($msg); $this->iohandler->send_response(); throw new user_interaction_required_exception(); } if ($this->installer_config->get_time_remaining() <= 0 || $this->installer_config->get_memory_remaining() <= 0) { $this->installer_config->set('database_update_count', $progress_count); throw new resource_limit_reached_exception(); } } if ($original_version !== $this->config['version']) { $this->log->add('admin', isset($this->user->data['user_id']) ? $this->user->data['user_id'] : ANONYMOUS, $this->user->ip, 'LOG_UPDATE_DATABASE', false, array($original_version, $this->config['version'])); } $this->iohandler->finish_progress('INLINE_UPDATE_SUCCESSFUL'); $this->iohandler->add_success_message('INLINE_UPDATE_SUCCESSFUL'); $this->config->delete('version_update_from'); $this->cache->purge(); $this->config->increment('assets_version', 1); }
/** * Delete attachments from filesystem */ protected function remove_from_filesystem() { $space_removed = $files_removed = 0; foreach ($this->physical as $file_ary) { if ($this->unlink_attachment($file_ary['filename'], 'file', true) && !$file_ary['is_orphan']) { // Only non-orphaned files count to the file size $space_removed += $file_ary['filesize']; $files_removed++; } if ($file_ary['thumbnail']) { $this->unlink_attachment($file_ary['filename'], 'thumbnail', true); } } /** * Perform additional actions after attachment(s) deletion from the filesystem * * @event core.delete_attachments_from_filesystem_after * @var string mode Variable containing attachments deletion mode, can be: post|message|topic|attach|user * @var mixed ids Array or comma separated list of ids corresponding to the mode * @var bool resync Flag indicating if posts/messages/topics should be synchronized * @var string sql_id The field name to collect/delete data for depending on the mode * @var array post_ids Array with post ids for deleted attachment(s) * @var array topic_ids Array with topic ids for deleted attachment(s) * @var array message_ids Array with private message ids for deleted attachment(s) * @var array physical Array with deleted attachment(s) physical file(s) data * @var int num_deleted The number of deleted attachment(s) from the database * @var int space_removed The size of deleted files(s) from the filesystem * @var int files_removed The number of deleted file(s) from the filesystem * @since 3.1.7-RC1 */ $vars = array('mode', 'ids', 'resync', 'sql_id', 'post_ids', 'topic_ids', 'message_ids', 'physical', 'num_deleted', 'space_removed', 'files_removed'); extract($this->dispatcher->trigger_event('core.delete_attachments_from_filesystem_after', compact($vars))); if ($space_removed || $files_removed) { $this->config->increment('upload_dir_size', $space_removed * -1, false); $this->config->increment('num_files', $files_removed * -1, false); } }
protected function finalise_update() { $this->cache->purge(); $this->config->increment('assets_version', 1); }
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); // Check, if user is allowed to use the robbery if (!$this->auth->acl_get('u_use_robbery')) { $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); } // Check, if robbery is enabled if (!$points_config['robbery_enable']) { $message = $this->user->lang['ROBBERY_DISABLED'] . '<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' => 'robbery')), 'FORUM_NAME' => sprintf($this->user->lang['POINTS_ROBBERY'], $this->config['points_name']))); // Read out cash of current user $pointsa = $this->user->data['user_points']; // Check key add_form_key('robbery_attack'); $submit = isset($_POST['submit']) ? true : false; if ($submit) { if (!check_form_key('robbery_attack')) { trigger_error('FORM_INVALID'); } // Add all required informations $username = utf8_normalize_nfc($this->request->variable('username', '', true)); $attacked_amount = round($this->request->variable('attacked_amount', 0.0), 2); if ($attacked_amount <= 0) { $message = $this->user->lang['ROBBERY_TOO_SMALL_AMOUNT'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } // Check, if user has entered the name of the user to be robbed if (empty($username)) { $message = $this->user->lang['ROBBERY_NO_ID_SPECIFIED'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } // Check, if user tries to rob himself if ($this->user->data['username_clean'] == utf8_clean_string($username)) { $message = $this->user->lang['ROBBERY_SELF'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } // Check, if user is trying to rob to much cash if ($points_values['robbery_loose'] != 0) { if ($this->user->data['user_points'] < $attacked_amount / 100 * $points_values['robbery_loose']) { $message = $this->user->lang['ROBBERY_TO_MUCH'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } } // Select the user_id of user to be robbed $sql_array = array('SELECT' => 'user_id', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'username_clean = "' . $this->db->sql_escape(utf8_clean_string($username)) . '"'); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $user_id = (int) $this->db->sql_fetchfield('user_id'); $this->db->sql_freeresult($result); // If no matching user id is found if (!$user_id) { $message = $this->user->lang['POINTS_NO_USER'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } // If the robbed user doesn't have enough cash $sql_array = array('SELECT' => 'user_points', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => 'user_id = ' . (int) $user_id); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $pointsa = $this->db->sql_fetchfield('user_points'); $this->db->sql_freeresult($result); if ($attacked_amount > $pointsa) { $message = $this->user->lang['ROBBERY_TO_MUCH_FROM_USER'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } // Check, if user tries to rob more than x % of users cash if ($points_values['robbery_max_rob'] != 0) { if ($attacked_amount > $pointsa / 100 * $points_values['robbery_max_rob']) { $message = sprintf($this->user->lang['ROBBERY_MAX_ROB'], $points_values['robbery_max_rob']) . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } } // Get some info about the robbed user $user_namepoints = get_username_string('full', $checked_user['user_id'], $checked_user['username'], $checked_user['user_colour']); // Genarate a random number $rand_base = $points_values['robbery_chance']; $rand_value = rand(0, 100); // If robbery was successful and notification is enabled, send notification if ($rand_value <= $rand_base) { $this->functions_points->add_points($this->user->data['user_id'], $attacked_amount); $this->functions_points->substract_points($user_id, $attacked_amount); // Add robbery to the log $sql = 'INSERT INTO ' . $this->points_log_table . ' ' . $this->db->sql_build_array('INSERT', array('point_send' => (int) $this->user->data['user_id'], 'point_recv' => $user_id, 'point_amount' => $attacked_amount, 'point_sendold' => $this->user->data['user_points'], 'point_recvold' => $pointsa, 'point_comment' => '', 'point_type' => '3', 'point_date' => time())); $this->db->sql_query($sql); if ($points_config['robbery_notify']) { // Increase our notification sent counter $this->config->increment('points_notification_id', 1); // Store the notification data we will use in an array $data = array('points_notify_id' => (int) $this->config['points_notification_id'], 'points_notify_msg' => sprintf($this->user->lang['NOTIFICATION_ROBBERY_SUCCES'], $attacked_amount, $this->config['points_name']), 'sender' => (int) $this->user->data['user_id'], 'receiver' => (int) $user_id, 'mode' => 'robbery'); // Create the notification $this->notification_manager->add_notifications('dmzx.ultimatepoints.notification.type.points', $data); } $message = $this->user->lang['ROBBERY_SUCCESFUL'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } else { if ($points_values['robbery_loose'] != 0) { $lose = $attacked_amount / 100 * $points_values['robbery_loose']; $this->functions_points->substract_points($this->user->data['user_id'], $lose); if ($points_config['robbery_notify']) { // Increase our notification sent counter $this->config->increment('points_notification_id', 1); // Store the notification data we will use in an array $data = array('points_notify_id' => (int) $this->config['points_notification_id'], 'points_notify_msg' => $this->user->lang['NOTIFICATION_ROBBERY_FAILED'], 'sender' => (int) $this->user->data['user_id'], 'receiver' => (int) $user_id, 'mode' => 'robbery'); // Create the notification $this->notification_manager->add_notifications('dmzx.ultimatepoints.notification.type.points', $data); } $message = $this->user->lang['ROBBERY_BAD'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } } $this->template->assign_vars(array('USER_NAME' => get_username_string('full', $checked_user['user_id'], $points_config['username'], $points_config['user_colour']), 'U_ACTION' => $this->u_action, 'S_HIDDEN_FIELDS' => $hidden_fields)); } $this->template->assign_vars(array('USER_POINTS' => sprintf($this->functions_points->number_format_points($pointsa)), 'POINTS_NAME' => $this->config['points_name'], 'LOTTERY_NAME' => $points_values['lottery_name'], 'BANK_NAME' => $points_values['bank_name'], 'L_ROBBERY_CHANCE' => sprintf($this->user->lang['ROBBERY_CHANCE'], $this->functions_points->number_format_points($points_values['robbery_max_rob']), $this->functions_points->number_format_points($points_values['robbery_chance'])), 'L_ROBBERY_AMOUNTLOSE' => sprintf($this->user->lang['ROBBERY_AMOUNTLOSE'], $this->functions_points->number_format_points($points_values['robbery_loose'])), 'U_FIND_USERNAME' => append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", "mode=searchuser&form=post&field=username"), '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'))); // Generate the page page_header($this->user->lang['POINTS_ROBBERY']); // Generate the page template $this->template->set_filenames(array('body' => 'points/points_robbery.html')); page_footer(); }
function main() { // 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); // Check Points Config Table if Bank is Enabled $sql = 'SELECT config_value FROM ' . $this->points_config_table . ' WHERE config_name = "bank_enable"'; $result = $this->db->sql_query($sql); $is_bank_enabled = $this->db->sql_fetchfield('config_value'); $this->db->sql_freeresult($result); // Check if bank is enabled if (1 > $points_values['bank_pay_period']) { $message = $this->user->lang['BANK_ERROR_PAYOUTTIME_SHORT'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } if ($is_bank_enabled != 1) { $message = $this->user->lang['BANK_DISABLED'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller') . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } if (!$this->auth->acl_get('u_use_bank')) { $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); } $withdrawtotal_check = ''; // Add part to bar $this->template->assign_block_vars('navlinks', array('U_VIEW_FORUM' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')), 'FORUM_NAME' => $points_values['bank_name'])); // Check, if it's time to pay users $time = time(); if ($time - $points_values['bank_last_restocked'] > $points_values['bank_pay_period']) { $this->functions_points->set_points_values('bank_last_restocked', $time); // Pay the users $sql = 'UPDATE ' . $this->points_bank_table . ' SET holding = holding + round((holding / 100) * ' . $points_values['bank_interest'] . ') WHERE holding < ' . $points_values['bank_interestcut'] . ' OR ' . $points_values['bank_interestcut'] . ' = 0'; $this->db->sql_query($sql); // Mantain the bank costs if ($points_values['bank_cost'] != '0') { $sql = 'UPDATE ' . $this->points_bank_table . ' SET holding = holding - ' . $points_values['bank_cost'] . ' WHERE holding >= ' . $points_values['bank_cost'] . ''; $this->db->sql_query($sql); } // Increase our notification sent counter $this->config->increment('points_notification_id', 1); $data = array('points_notify_id' => (int) $this->config['points_notification_id'], 'points_notify_msg' => $this->user->lang['NOTIFICATION_BANK_PAYOUT'], 'sender' => $this->user->data['user_id'], 'receiver' => (int) $this->user->data['user_id'], 'mode' => 'bank'); // Send the notification $this->notification_manager->add_notifications('dmzx.ultimatepoints.notification.type.points', $data); $sql_array = array('SELECT' => 'username', '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); $points_user = $this->db->sql_fetchrow($result); // Add logs $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MOD_POINTS_BANK_PAYS', false, array($points_user['username'])); } $sql_array = array('SELECT' => '*', 'FROM' => array($this->points_bank_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); $row = $this->db->sql_fetchrow($result); $action = $this->request->variable('action', ''); add_form_key('bank_action'); // Default bank info page if (empty($action)) { $this->template->set_filenames(array('body' => 'points/points_bank.html')); if (!isset($row['holding']) && $this->user->data['user_id'] > 0 && $this->user->data['username'] != ANONYMOUS) { $this->template->assign_block_vars('no_account', array('USER_NO_ACCOUNT' => sprintf($this->user->lang['BANK_USER_NO_ACCOUNT'], $points_values['bank_name']), 'OPEN_ACCOUNT' => sprintf($this->user->lang['BANK_OPEN_ACCOUNT'], '<a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank', 'action' => 'createaccount')) . '" title="' . $this->user->lang['BANK_OPEN_ACCOUNT'] . '!">', '</a>'))); } else { if ($this->user->data['user_id'] > 0 && $this->user->data['username'] != ANONYMOUS) { $this->template->assign_block_vars('has_account', array()); } } $sql_array = array('SELECT' => 'SUM(holding) AS total_holding, count(user_id) AS total_users', 'FROM' => array($this->points_bank_table => 'u'), 'WHERE' => 'id > 0'); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $b_row = $this->db->sql_fetchrow($result); $bankholdings = $b_row['total_holding'] ? $b_row['total_holding'] : 0; $bankusers = $b_row['total_users']; $withdrawtotal = $row['fees'] == 'on' ? $row['holding'] - round($row['holding'] / 100 * $points_values['bank_fees']) : $row['holding']; if ($row['fees'] == 'on' && $this->user->lang['BANK_WITHDRAW_RATE']) { $this->template->assign_block_vars('switch_withdraw_fees', array()); } if ($points_values['bank_min_withdraw']) { $this->template->assign_block_vars('switch_min_with', array()); } if ($points_values['bank_min_deposit']) { $this->template->assign_block_vars('switch_min_depo', array()); } $banklocation = ' -> <a href="' . $this->helper->route('dmzx_ultimatepoints_controller') . '" class="nav">' . $points_values['bank_name'] . '</a>'; $title = $points_values['bank_name'] . '; ' . (!is_numeric($row['holding']) ? $this->user->lang['BANK_ACCOUNT_OPENING'] : $this->user->lang['BANK_DEPOSIT_WITHDRAW'] . ' ' . $this->config['points_name']); page_header($points_values['bank_name']); $bank_enable = $is_bank_enabled; $this->template->assign_vars(array('BANK_NAME' => $points_values['bank_name'], 'BANKLOCATION' => $banklocation, 'BANK_OPENED' => $this->user->format_date($bank_enable), 'BANK_HOLDINGS' => sprintf($this->functions_points->number_format_points($bankholdings)), 'BANK_ACCOUNTS' => $bankusers, 'BANK_FEES' => $points_values['bank_fees'], 'BANK_INTEREST' => $points_values['bank_interest'], 'BANK_MIN_WITH' => sprintf($this->functions_points->number_format_points($points_values['bank_min_withdraw'])), 'BANK_MIN_DEPO' => sprintf($this->functions_points->number_format_points($points_values['bank_min_deposit'])), 'BANK_MAX_HOLD' => sprintf($this->functions_points->number_format_points($points_values['bank_interestcut'])), 'BANK_TITLE' => $title, 'POINTS_NAME' => $this->config['points_name'], 'USER_BALANCE' => sprintf($this->functions_points->number_format_points($row['holding'])), 'USER_GOLD' => $this->user->data['user_points'], 'USER_WITHDRAW' => sprintf(number_format($withdrawtotal, 2, '.', '')), 'U_WITHDRAW' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank', 'action' => 'withdraw')), 'U_DEPOSIT' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank', 'action' => 'deposit')))); } else { if ($action == 'createaccount') { if (!$this->user->data['is_registered']) { login_box(); } $this->template->set_filenames(array('body' => 'points/points_bank.html')); if (is_numeric($row['holding'])) { trigger_error(' ' . $this->user->lang['YES_ACCOUNT'] . '!<br /><br />' . sprintf($this->user->lang['BANK_BACK_TO_BANK'], '<a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')) . '">', '</a>') . sprintf('<br />' . $this->user->lang['BANK_BACK_TO_INDEX'], '<a href="' . append_sid("{$this->phpbb_root_path}index.{$this->phpEx}") . '">', '</a>')); } else { $sql = 'INSERT INTO ' . $this->points_bank_table . ' ' . $this->db->sql_build_array('INSERT', array('user_id' => (int) $this->user->data['user_id'], 'opentime' => time(), 'fees' => 'on')); $this->db->sql_query($sql); trigger_error(' ' . $this->user->lang['BANK_WELCOME_BANK'] . ' ' . $points_values['bank_name'] . '! <br />' . $this->user->lang['BANK_START_BALANCE'] . '<br />' . $this->user->lang['BANK_YOUR_ACCOUNT'] . '!<br /><br />' . sprintf($this->user->lang['BANK_BACK_TO_BANK'], '<a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')) . '">', '</a>') . sprintf('<br />' . $this->user->lang['BANK_BACK_TO_INDEX'], '<a href="' . append_sid("{$this->phpbb_root_path}index.{$this->phpEx}") . '">', '</a>')); } } else { if ($action == 'deposit') { if (!check_form_key('bank_action')) { trigger_error('FORM_INVALID'); } $deposit = round($this->request->variable('deposit', 0.0), 2); if (!$this->user->data['is_registered']) { login_box(); } if ($deposit < $points_values['bank_min_deposit']) { $message = sprintf($this->user->lang['BANK_DEPOSIT_SMALL_AMOUNT'], $points_values['bank_min_deposit'], $this->config['points_name']) . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } else { if ($deposit < 1) { $message = $this->user->lang['BANK_ERROR_DEPOSIT'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } else { if ($deposit > $this->user->data['user_points']) { $message = sprintf($this->user->lang['BANK_ERROR_NOT_ENOUGH_DEPOSIT'], $this->config['points_name']) . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } } } $this->functions_points->substract_points($this->user->data['user_id'], $deposit); $sql_array = array('SELECT' => 'holding, totaldeposit', 'FROM' => array($this->points_bank_table => 'b'), 'WHERE' => 'user_id = ' . (int) $this->user->data['user_id']); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $user_bank = $this->db->sql_fetchrow($result); $user_holding = $user_bank['holding']; $user_totaldeposit = $user_bank['totaldeposit']; $this->db->sql_freeresult($result); $data = array('holding' => $user_holding + $deposit, 'totaldeposit' => $user_totaldeposit + $deposit); $sql = 'UPDATE ' . $this->points_bank_table . ' SET ' . $this->db->sql_build_array('UPDATE', $data) . ' WHERE user_id = ' . (int) $this->user->data['user_id']; $this->db->sql_query($sql); trigger_error(' ' . $this->user->lang['BANK_HAVE_DEPOSIT'] . ' ' . sprintf($this->functions_points->number_format_points($deposit)) . ' ' . $this->config['points_name'] . ' ' . $this->user->lang['BANK_TO_ACCOUNT'] . '<br />' . $this->user->lang['BANK_NEW_BALANCE'] . ' ' . sprintf($this->functions_points->number_format_points($row['holding'] + $deposit)) . '.<br />' . $this->user->lang['BANK_LEAVE_WITH'] . ' ' . sprintf($this->functions_points->number_format_points($this->user->data['user_points'] - $deposit)) . ' ' . $this->config['points_name'] . ' ' . $this->user->lang['BANK_ON_HAND'] . '.<br /><br />' . sprintf($this->user->lang['BANK_BACK_TO_BANK'], '<a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')) . '">', '</a>') . sprintf('<br />' . $this->user->lang['BANK_BACK_TO_INDEX'], '<a href="' . append_sid("{$this->phpbb_root_path}index.{$this->phpEx}") . '">', '</a>')); } else { if ($action == 'withdraw') { if (!check_form_key('bank_action')) { trigger_error('FORM_INVALID'); } $withdraw = round($this->request->variable('withdraw', 0.0), 2); if (!$this->user->data['is_registered']) { login_box(); } if ($withdraw < $points_values['bank_min_withdraw']) { $message = sprintf($this->user->lang['BANK_WITHDRAW_SMALL_AMOUNT'], $points_values['bank_min_withdraw'], $this->config['points_name']) . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } else { if ($withdraw < 1) { $message = $this->user->lang['BANK_ERROR_WITHDRAW'] . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } } if ($row['fees'] == 'on') { $withdrawtotal_check = $row['fees'] == 'on' ? $row['holding'] - round($row['holding'] / 100 * $points_values['bank_fees']) : $row['holding']; $fees = round($row['holding'] / 100 * $points_values['bank_fees']); if ($withdraw == $withdrawtotal_check) { $withdrawtotal = $withdraw + $fees; } else { $withdrawtotal = round($withdraw / 100 * $points_values['bank_fees']) + $withdraw; } } else { $withdrawtotal = 0; } if ($row['holding'] < $withdrawtotal) { $message = sprintf($this->user->lang['BANK_ERROR_NOT_ENOUGH_WITHDRAW'], $this->config['points_name']) . '<br /><br /><a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')) . '">« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; trigger_error($message); } // Transfer points to users cash account $this->functions_points->add_points($this->user->data['user_id'], $withdraw); // Update users bank account $sql_array = array('SELECT' => 'holding, totalwithdrew', 'FROM' => array($this->points_bank_table => 'b'), 'WHERE' => 'user_id = ' . (int) $this->user->data['user_id']); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $user_bank = $this->db->sql_fetchrow($result); $user_holding = $user_bank['holding']; $user_totalwithdrew = $user_bank['totalwithdrew']; $this->db->sql_freeresult($result); $data = array('holding' => $user_holding - $withdrawtotal, 'totalwithdrew' => $user_totalwithdrew + $withdraw); $sql = 'UPDATE ' . $this->points_bank_table . ' SET ' . $this->db->sql_build_array('UPDATE', $data) . ' WHERE user_id = ' . (int) $this->user->data['user_id']; $this->db->sql_query($sql); trigger_error(' ' . $this->user->lang['BANK_HAVE_WITHDRAW'] . ' ' . sprintf($this->functions_points->number_format_points($withdraw)) . ' ' . $this->config['points_name'] . ' ' . $this->user->lang['BANK_FROM_ACCOUNT'] . '. <br />' . $this->user->lang['BANK_NEW_BALANCE'] . ' ' . sprintf($this->functions_points->number_format_points($row['holding'] - $withdrawtotal)) . ' ' . $this->config['points_name'] . '.<br />' . $this->user->lang['BANK_NOW_HAVE'] . ' ' . sprintf($this->functions_points->number_format_points($this->user->data['user_points'] + $withdraw)) . ' ' . $this->config['points_name'] . ' ' . $this->user->lang['BANK_ON_HAND'] . '.<br /><br />' . sprintf($this->user->lang['BANK_BACK_TO_BANK'], '<a href="' . $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')) . '">', '</a>') . sprintf('<br />' . $this->user->lang['BANK_BACK_TO_INDEX'], '<a href="' . append_sid("{$this->phpbb_root_path}index.{$this->phpEx}") . '">', '</a>')); } else { redirect($this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank'))); } } } } // Generate most rich banker to show $limit = $points_values['number_show_top_points']; $sql_array = array('SELECT' => 'u.user_id, u.username, u.user_colour, b.*', 'FROM' => array(USERS_TABLE => 'u'), 'LEFT_JOIN' => array(array('FROM' => array($this->points_bank_table => 'b'), 'ON' => 'u.user_id = b.user_id')), 'WHERE' => 'b.holding > 0', 'ORDER_BY' => 'b.holding DESC, u.username ASC'); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query_limit($sql, $limit); while ($row = $this->db->sql_fetchrow($result)) { $this->template->assign_block_vars('bank', array('USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'POINT' => sprintf($this->functions_points->number_format_points($row['holding'])))); } $this->db->sql_freeresult($result); // Generate the time format function time_format($secs, $filter = false) { global $user; $output = ''; $filter = $filter ? explode('|', strtolower($filter)) : false; $time_array = array('year' => 60 * 60 * 24 * 365, 'month' => 60 * 60 * 24 * 30, 'week' => 60 * 60 * 24 * 7, 'day' => 60 * 60 * 24, 'hour' => 60 * 60, 'minute' => 60, 'second' => 0); foreach ($time_array as $key => $value) { if ($filter && !in_array($key, $filter)) { continue; } $item = $value ? intval(intval($secs) / $value) : intval($secs); if ($item > 0) { $secs = $secs - $item * $value; $output .= ' ' . $item . ' ' . ($item > 1 ? $user->lang['TIME_' . strtoupper($key) . 'S'] : $user->lang['TIME_' . strtoupper($key)]); } } return $output; } $this->template->assign_vars(array('BANK_INTEREST_PERIOD' => time_format($points_values['bank_pay_period']), 'BANK_COST' => sprintf($this->functions_points->number_format_points($points_values['bank_cost'])), 'LOTTERY_NAME' => $points_values['lottery_name'], 'BANK_NAME' => $points_values['bank_name'], 'BANK_NOBODY_IN_BANK' => sprintf($this->user->lang['BANK_NOBODY_IN_BANK'], $this->config['points_name'], $points_values['bank_name']), 'S_DISPLAY_INDEX' => $points_values['number_show_top_points'] > 0 ? true : false, 'L_BANK_DESCRIPTION' => sprintf($this->user->lang['BANK_DESCRIPTION'], $this->config['points_name']), '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'))); page_footer(); }