Beispiel #1
0
         continue;
     }
     // calculate points ber character bonus
     // let's see if the number of characters in the post is greater than the minimum characters
     if (($charcount = my_strlen($post['message'])) >= $mybb->settings['newpoints_income_minchar']) {
         $bonus = $charcount * $mybb->settings['newpoints_income_perchar'];
     } else {
         $bonus = 0;
     }
     // give points to the poster
     $points += ($mybb->settings['newpoints_income_newpost'] + $bonus) * $allforumrules[$post['fid']]['rate'];
     $thread = get_thread($post['tid']);
     if ($thread['uid'] != $user['uid']) {
         // we are not the thread started so give points to him/her
         if ($mybb->settings['newpoints_income_perreply'] != 0) {
             newpoints_addpoints($thread['uid'], $mybb->settings['newpoints_income_perreply'], $allforumrules[$post['fid']]['rate'], $grouprules['rate']);
         }
     }
 }
 // poll votes
 if ($mybb->settings['newpoints_income_pervote'] != 0) {
     // just count the votes and don't get the poll and the thread (to calculate the correct income value  using the forum income rate but as it is a slow process, let's just not use forum rate here)
     $pollvotes_query = $db->simple_select("pollvotes", "COUNT(*) AS votes", "uid='" . $user['uid'] . "'");
     $votes = $db->fetch_field($pollvotes_query, "votes");
     $points += $votes * $mybb->settings['newpoints_income_pervote'];
 }
 // private messages
 if ($mybb->settings['newpoints_income_pmsent'] != 0) {
     // count private messages this user has sent
     $pmssent_query = $db->simple_select("privatemessages", "COUNT(*) AS numpms", "fromid='" . $user['uid'] . "' AND toid!='" . $user['uid'] . "' AND receipt!='1'");
     $pmssent = $db->fetch_field($pmssent_query, "numpms");
Beispiel #2
0
function newpoints_shop_admin()
{
    global $db, $lang, $mybb, $page, $run_module, $action_file, $mybbadmin, $plugins;
    newpoints_lang_load('newpoints_shop');
    if ($run_module == 'newpoints' && $action_file == 'newpoints_shop') {
        if ($mybb->request_method == "post") {
            switch ($mybb->input['action']) {
                case 'do_addcat':
                    if ($mybb->input['name'] == '') {
                        newpoints_shop_messageredirect($lang->newpoints_shop_missing_field, 1);
                    }
                    $name = $db->escape_string($mybb->input['name']);
                    $description = $db->escape_string($mybb->input['description']);
                    // get visible to user groups options
                    if (is_array($mybb->input['usergroups'])) {
                        foreach ($mybb->input['usergroups'] as $gid) {
                            if ($gid == $mybb->input['usergroups']) {
                                unset($mybb->input['usergroups'][$gid]);
                            }
                        }
                        $usergroups = implode(",", $mybb->input['usergroups']);
                    } else {
                        $usergroups = '';
                    }
                    $usergroups = $db->escape_string($usergroups);
                    $visible = intval($mybb->input['visible']);
                    $icon = $db->escape_string($mybb->input['icon']);
                    $disporder = intval($mybb->input['disporder']);
                    $expanded = intval($mybb->input['expanded']);
                    $insert_query = array('name' => $name, 'description' => $description, 'usergroups' => $usergroups, 'visible' => $visible, 'disporder' => $disporder, 'icon' => $icon, 'expanded' => $expanded);
                    $db->insert_query('newpoints_shop_categories', $insert_query);
                    newpoints_shop_messageredirect($lang->newpoints_shop_cat_added);
                    break;
                case 'do_editcat':
                    $cid = intval($mybb->input['cid']);
                    if ($cid <= 0 || !($cat = $db->fetch_array($db->simple_select('newpoints_shop_categories', '*', "cid = {$cid}")))) {
                        newpoints_shop_messageredirect($lang->newpoints_shop_invalid_cat, 1);
                    }
                    if ($mybb->input['name'] == '') {
                        newpoints_shop_messageredirect($lang->newpoints_shop_missing_field, 1);
                    }
                    $name = $db->escape_string($mybb->input['name']);
                    $description = $db->escape_string($mybb->input['description']);
                    // get visible to user groups options
                    if (is_array($mybb->input['usergroups'])) {
                        foreach ($mybb->input['usergroups'] as $gid) {
                            if ($gid == $mybb->input['usergroups']) {
                                unset($mybb->input['usergroups'][$gid]);
                            }
                        }
                        $usergroups = implode(",", $mybb->input['usergroups']);
                    } else {
                        $usergroups = '';
                    }
                    $usergroups = $db->escape_string($usergroups);
                    $visible = intval($mybb->input['visible']);
                    $icon = $db->escape_string($mybb->input['icon']);
                    $disporder = intval($mybb->input['disporder']);
                    $expanded = intval($mybb->input['expanded']);
                    $update_query = array('name' => $name, 'description' => $description, 'usergroups' => $usergroups, 'visible' => $visible, 'disporder' => $disporder, 'icon' => $icon, 'expanded' => $expanded);
                    $db->update_query('newpoints_shop_categories', $update_query, 'cid=\'' . $cid . '\'');
                    newpoints_shop_messageredirect($lang->newpoints_shop_cat_edited);
                    break;
                case 'do_additem':
                    if ($mybb->input['name'] == '' || $mybb->input['cid'] == '') {
                        newpoints_shop_messageredirect($lang->newpoints_shop_missing_field, 1);
                    }
                    $name = $db->escape_string($mybb->input['name']);
                    $description = $db->escape_string($mybb->input['description']);
                    $icon = $db->escape_string($mybb->input['icon']);
                    $pm = $db->escape_string($mybb->input['pm']);
                    $price = floatval($mybb->input['price']);
                    $infinite = intval($mybb->input['infinite']);
                    if ($infinite == 1) {
                        $stock = 0;
                    } else {
                        $stock = intval($mybb->input['stock']);
                    }
                    $limit = intval($mybb->input['limit']);
                    $visible = intval($mybb->input['visible']);
                    $disporder = intval($mybb->input['disporder']);
                    $sendable = intval($mybb->input['sendable']);
                    $sellable = intval($mybb->input['sellable']);
                    $cid = intval($mybb->input['cid']);
                    if ($cid <= 0 || !($cat = $db->fetch_array($db->simple_select('newpoints_shop_categories', '*', "cid = {$cid}")))) {
                        newpoints_shop_messageredirect($lang->newpoints_shop_invalid_cat, 1);
                    }
                    $insert_array = array('name' => $name, 'description' => $description, 'icon' => $icon, 'visible' => $visible, 'disporder' => $disporder, 'price' => $price, 'infinite' => $infinite, 'stock' => $stock, 'limit' => $limit, 'sendable' => $sendable, 'sellable' => $sellable, 'cid' => $cid, 'pm' => $pm);
                    $plugins->run_hooks("newpoints_shop_commit", $insert_array);
                    $db->insert_query('newpoints_shop_items', $insert_array);
                    $db->write_query('UPDATE ' . TABLE_PREFIX . 'newpoints_shop_categories SET items = items+1 WHERE cid=\'' . $cid . '\'');
                    newpoints_shop_messageredirect($lang->newpoints_shop_item_added, 0, "items&amp;cid=" . $cid);
                    break;
                case 'do_edititem':
                    $iid = intval($mybb->input['iid']);
                    if ($iid <= 0 || !($item = $db->fetch_array($db->simple_select('newpoints_shop_items', '*', "iid = {$iid}")))) {
                        newpoints_shop_messageredirect($lang->newpoints_shop_invalid_item, 1, 'items');
                    }
                    if ($mybb->input['name'] == '' || $mybb->input['cid'] == '') {
                        newpoints_shop_messageredirect($lang->newpoints_shop_missing_field, 1);
                    }
                    $name = $db->escape_string($mybb->input['name']);
                    $description = $db->escape_string($mybb->input['description']);
                    $icon = $db->escape_string($mybb->input['icon']);
                    $price = floatval($mybb->input['price']);
                    $pm = $db->escape_string($mybb->input['pm']);
                    $infinite = intval($mybb->input['infinite']);
                    if ($infinite == 1) {
                        $stock = 0;
                    } else {
                        $stock = intval($mybb->input['stock']);
                    }
                    $limit = intval($mybb->input['limit']);
                    $visible = intval($mybb->input['visible']);
                    $disporder = intval($mybb->input['disporder']);
                    $sendable = intval($mybb->input['sendable']);
                    $sellable = intval($mybb->input['sellable']);
                    $cid = intval($mybb->input['cid']);
                    if ($cid <= 0 || !($cat = $db->fetch_array($db->simple_select('newpoints_shop_categories', '*', "cid = {$cid}")))) {
                        newpoints_shop_messageredirect($lang->newpoints_shop_invalid_cat, 1);
                    }
                    $update_array = array('name' => $name, 'description' => $description, 'icon' => $icon, 'visible' => $visible, 'disporder' => $disporder, 'price' => $price, 'infinite' => $infinite, 'stock' => $stock, 'limit' => $limit, 'sendable' => $sendable, 'sellable' => $sellable, 'cid' => $cid, 'pm' => $pm);
                    $plugins->run_hooks("newpoints_shop_commit", $update_array);
                    $db->update_query('newpoints_shop_items', $update_array, 'iid=\'' . $iid . '\'');
                    if ($cid != $item['cid']) {
                        $db->write_query('UPDATE ' . TABLE_PREFIX . 'newpoints_shop_categories SET items = items-1 WHERE cid=\'' . $item['cid'] . '\'');
                        $db->write_query('UPDATE ' . TABLE_PREFIX . 'newpoints_shop_categories SET items = items+1 WHERE cid=\'' . $cid . '\'');
                    }
                    newpoints_shop_messageredirect($lang->newpoints_shop_item_edited, 0, "items&amp;cid=" . $cid);
                    break;
            }
        }
        if ($mybb->input['action'] == 'do_deletecat') {
            $page->add_breadcrumb_item($lang->newpoints_shop, 'index.php?module=newpoints-shop');
            $page->output_header($lang->newpoints_shop);
            $cid = intval($mybb->input['cid']);
            if ($mybb->input['no']) {
                admin_redirect("index.php?module=newpoints-shop");
            }
            if ($mybb->request_method == "post") {
                if ($cid <= 0 || !($cat = $db->fetch_array($db->simple_select('newpoints_shop_categories', 'cid', "cid = {$cid}")))) {
                    newpoints_shop_messageredirect($lang->newpoints_shop_invalid_cat, 1);
                }
                $db->delete_query('newpoints_shop_categories', "cid = {$cid}");
                // unassign items from this category
                $db->update_query('newpoints_shop_items', array('cid' => 0), "cid = {$cid}");
                newpoints_shop_messageredirect($lang->newpoints_shop_cat_deleted);
            } else {
                $mybb->input['cid'] = intval($mybb->input['cid']);
                $form = new Form("index.php?module=newpoints-shop&amp;action=do_deletecat&amp;cid={$mybb->input['cid']}&amp;my_post_key={$mybb->post_code}", 'post');
                echo "<div class=\"confirm_action\">\n";
                echo "<p>{$lang->newpoints_shop_confirm_deletecat}</p>\n";
                echo "<br />\n";
                echo "<p class=\"buttons\">\n";
                echo $form->generate_submit_button($lang->yes, array('class' => 'button_yes'));
                echo $form->generate_submit_button($lang->no, array("name" => "no", 'class' => 'button_no'));
                echo "</p>\n";
                echo "</div>\n";
                $form->end();
            }
        } elseif ($mybb->input['action'] == 'do_deleteitem') {
            $page->add_breadcrumb_item($lang->newpoints_shop, 'index.php?module=newpoints-shop');
            $page->output_header($lang->newpoints_shop);
            $iid = intval($mybb->input['iid']);
            if ($mybb->input['no']) {
                admin_redirect("index.php?module=newpoints-shop", 0, "items&amp;cid=" . $cid);
            }
            if ($mybb->request_method == "post") {
                if ($iid <= 0 || !($item = $db->fetch_array($db->simple_select('newpoints_shop_items', 'cid', "iid = {$iid}")))) {
                    newpoints_shop_messageredirect($lang->newpoints_shop_invalid_item, 1, "items&amp;cid=" . $cid);
                }
                $db->delete_query('newpoints_shop_items', "iid = {$iid}");
                // remove one from the items count
                $db->write_query('UPDATE ' . TABLE_PREFIX . 'newpoints_shop_categories SET items = items-1 WHERE cid=\'' . $item['cid'] . '\'');
                newpoints_shop_messageredirect($lang->newpoints_shop_item_deleted, 0, "items&amp;cid=" . $cid);
            } else {
                $mybb->input['iid'] = intval($mybb->input['iid']);
                $form = new Form("index.php?module=newpoints-shop&amp;action=do_deleteitem&amp;iid={$mybb->input['iid']}&amp;my_post_key={$mybb->post_code}", 'post');
                echo "<div class=\"confirm_action\">\n";
                echo "<p>{$lang->newpoints_shop_confirm_deleteitem}</p>\n";
                echo "<br />\n";
                echo "<p class=\"buttons\">\n";
                echo $form->generate_submit_button($lang->yes, array('class' => 'button_yes'));
                echo $form->generate_submit_button($lang->no, array("name" => "no", 'class' => 'button_no'));
                echo "</p>\n";
                echo "</div>\n";
                $form->end();
            }
        } elseif ($mybb->input['action'] == 'remove') {
            $page->add_breadcrumb_item($lang->newpoints_shop, 'index.php?module=newpoints-shop');
            $page->output_header($lang->newpoints_shop);
            $iid = intval($mybb->input['iid']);
            $mybb->input['uid'] = intval($mybb->input['uid']);
            if ($mybb->input['no']) {
                admin_redirect("index.php?module=newpoints-shop", 0, "items&amp;cid=" . $cid);
            }
            if ($mybb->request_method == "post") {
                if ($iid <= 0 || !($item = $db->fetch_array($db->simple_select('newpoints_shop_items', '*', "iid = {$iid}")))) {
                    newpoints_shop_messageredirect($lang->newpoints_shop_invalid_item, 1, "items&amp;cid=" . $cid);
                }
                $uid = (int) $mybb->input['uid'];
                if ($uid <= 0) {
                    newpoints_shop_messageredirect($lang->newpoints_shop_invalid_user, 1);
                }
                $user = get_user($uid);
                // we're viewing someone else's inventory
                if (empty($user)) {
                    newpoints_shop_messageredirect($lang->newpoints_shop_invalid_user, 1);
                }
                $inventory = @unserialize($user['newpoints_items']);
                if (!$inventory) {
                    newpoints_shop_messageredirect($lang->newpoints_shop_inventory_empty, 1);
                }
                // make sure we own the item
                $key = array_search($item['iid'], $inventory);
                if ($key === false) {
                    newpoints_shop_messageredirect($lang->newpoints_shop_selected_item_not_owned, 1);
                }
                // remove item from our inventory
                unset($inventory[$key]);
                sort($inventory);
                $db->update_query('users', array('newpoints_items' => serialize($inventory)), 'uid=\'' . $uid . '\'');
                // update stock
                if ($item['infinite'] != 1) {
                    $db->update_query('newpoints_shop_items', array('stock' => $item['stock'] + 1), 'iid=\'' . $item['iid'] . '\'');
                }
                newpoints_addpoints($uid, floatval($item['price']) * $mybb->settings['newpoints_shop_percent']);
                newpoints_shop_messageredirect($lang->newpoints_shop_item_removed, 0, "inventory&amp;uid=" . $uid);
            } else {
                $form = new Form("index.php?module=newpoints-shop&amp;action=remove&amp;iid={$mybb->input['iid']}&amp;uid={$mybb->input['uid']}&amp;my_post_key={$mybb->post_code}", 'post');
                echo "<div class=\"confirm_action\">\n";
                echo "<p>{$lang->newpoints_shop_confirm_removeitem}</p>\n";
                echo "<br />\n";
                echo "<p class=\"buttons\">\n";
                echo $form->generate_submit_button($lang->yes, array('class' => 'button_yes'));
                echo $form->generate_submit_button($lang->no, array("name" => "no", 'class' => 'button_no'));
                echo "</p>\n";
                echo "</div>\n";
                $form->end();
            }
        }
        if (!$mybb->input['action'] || $mybb->input['action'] == 'categories' || $mybb->input['action'] == 'inventory' || $mybb->input['action'] == 'addcat' || $mybb->input['action'] == 'editcat') {
            $page->add_breadcrumb_item($lang->newpoints_shop, 'index.php?module=newpoints-shop');
            $page->output_header($lang->newpoints_shop);
            $sub_tabs['newpoints_shop_categories'] = array('title' => $lang->newpoints_shop_categories, 'link' => 'index.php?module=newpoints-shop', 'description' => $lang->newpoints_shop_categories_desc);
            if (!$mybb->input['action'] || $mybb->input['action'] == 'categories' || $mybb->input['action'] == 'addcat' || $mybb->input['action'] == 'editcat') {
                $sub_tabs['newpoints_shop_categories_add'] = array('title' => $lang->newpoints_shop_addcat, 'link' => 'index.php?module=newpoints-shop&amp;action=addcat', 'description' => $lang->newpoints_shop_addcat_desc);
                $sub_tabs['newpoints_shop_categories_edit'] = array('title' => $lang->newpoints_shop_editcat, 'link' => 'index.php?module=newpoints-shop&amp;action=editcat', 'description' => $lang->newpoints_shop_editcat_desc);
                $sub_tabs['newpoints_shop_categories_delete'] = array('title' => $lang->newpoints_shop_deletecat, 'link' => 'index.php?module=newpoints-shop&amp;action=do_deletecat', 'description' => $lang->newpoints_shop_deletecat_desc);
            }
        }
        if ($mybb->input['action'] == 'inventory') {
            $sub_tabs['newpoints_shop_inventory'] = array('title' => $lang->newpoints_shop_inventory, 'link' => 'index.php?module=newpoints-shop&amp;action=inventory&amp;uid=' . intval($mybb->input['uid']), 'description' => $lang->newpoints_shop_inventory_desc);
        }
        if ($mybb->input['action'] == 'items' || $mybb->input['action'] == 'additem' || $mybb->input['action'] == 'edititem') {
            $page->add_breadcrumb_item($lang->newpoints_shop, 'index.php?module=newpoints-shop');
            $page->output_header($lang->newpoints_shop);
            $sub_tabs['newpoints_shop_categories'] = array('title' => $lang->newpoints_shop_categories, 'link' => 'index.php?module=newpoints-shop', 'description' => $lang->newpoints_shop_categories_desc);
            $sub_tabs['newpoints_shop_items'] = array('title' => $lang->newpoints_shop_items, 'link' => 'index.php?module=newpoints-shop&amp;action=items&amp;cid=' . intval($mybb->input['cid']), 'description' => $lang->newpoints_shop_items_desc);
            if ($mybb->input['action'] == 'items' || $mybb->input['action'] == 'additem' || $mybb->input['action'] == 'edititem') {
                $sub_tabs['newpoints_shop_items_add'] = array('title' => $lang->newpoints_shop_additem, 'link' => 'index.php?module=newpoints-shop&amp;action=additem&amp;cid=' . intval($mybb->input['cid']), 'description' => $lang->newpoints_shop_additem_desc);
                $sub_tabs['newpoints_shop_items_edit'] = array('title' => $lang->newpoints_shop_edititem, 'link' => 'index.php?module=newpoints-shop&amp;action=edititem', 'description' => $lang->newpoints_shop_edititem_desc);
                $sub_tabs['newpoints_shop_items_delete'] = array('title' => $lang->newpoints_shop_deleteitem, 'link' => 'index.php?module=newpoints-shop&amp;action=do_deleteitem', 'description' => $lang->newpoints_shop_deleteitem_desc);
            }
        }
        if (!$mybb->input['action'] || $mybb->input['action'] == 'categories') {
            $page->output_nav_tabs($sub_tabs, 'newpoints_shop_categories');
            // table
            $table = new Table();
            $table->construct_header($lang->newpoints_shop_cat_name, array('width' => '30%'));
            $table->construct_header($lang->newpoints_shop_cat_description, array('width' => '35%'));
            $table->construct_header($lang->newpoints_shop_cat_items, array('width' => '10%', 'class' => 'align_center'));
            $table->construct_header($lang->newpoints_shop_cat_disporder, array('width' => '10%', 'class' => 'align_center'));
            $table->construct_header($lang->newpoints_shop_cat_action, array('width' => '25%', 'class' => 'align_center'));
            $query = $db->simple_select('newpoints_shop_categories', '*', '', array('order_by' => 'disporder', 'order_dir' => 'ASC'));
            while ($cat = $db->fetch_array($query)) {
                $table->construct_cell("<a href=\"index.php?module=newpoints-shop&amp;action=items&amp;cid={$cat['cid']}\">" . htmlspecialchars_uni($cat['name']) . "</a>");
                $table->construct_cell(htmlspecialchars_uni($cat['description']));
                $table->construct_cell(intval($cat['items']), array('class' => 'align_center'));
                $table->construct_cell(intval($cat['disporder']), array('class' => 'align_center'));
                // actions column
                $table->construct_cell("<a href=\"index.php?module=newpoints-shop&amp;action=editcat&amp;cid=" . intval($cat['cid']) . "\">" . $lang->newpoints_shop_edit . "</a> - <a href=\"index.php?module=newpoints-shop&amp;action=do_deletecat&amp;cid=" . intval($cat['cid']) . "\">" . $lang->newpoints_shop_delete . "</a>", array('class' => 'align_center'));
                $table->construct_row();
            }
            if ($table->num_rows() == 0) {
                $table->construct_cell($lang->newpoints_shop_no_cats, array('colspan' => 5));
                $table->construct_row();
            }
            $table->output($lang->newpoints_shop_categories);
        } elseif ($mybb->input['action'] == 'addcat') {
            $page->output_nav_tabs($sub_tabs, 'newpoints_shop_categories_add');
            $query = $db->simple_select("usergroups", "gid, title", "gid != '1'", array('order_by' => 'title'));
            while ($usergroup = $db->fetch_array($query)) {
                $options[$usergroup['gid']] = $usergroup['title'];
            }
            $form = new Form("index.php?module=newpoints-shop&amp;action=do_addcat", "post", "newpoints_shop");
            $form_container = new FormContainer($lang->newpoints_shop_addcat);
            $form_container->output_row($lang->newpoints_shop_addedit_cat_name . "<em>*</em>", $lang->newpoints_shop_addedit_cat_name_desc, $form->generate_text_box('name', '', array('id' => 'name')), 'name');
            $form_container->output_row($lang->newpoints_shop_addedit_cat_description, $lang->newpoints_shop_addedit_cat_description_desc, $form->generate_text_box('description', '', array('id' => 'description')), 'description');
            $form_container->output_row($lang->newpoints_shop_addedit_cat_visible, $lang->newpoints_shop_addedit_cat_visible_desc, $form->generate_yes_no_radio('visible', 1), 'visible');
            $form_container->output_row($lang->newpoints_shop_addedit_cat_icon, $lang->newpoints_shop_addedit_cat_icon_desc, $form->generate_text_box('icon', '', array('id' => 'icon')), 'icon');
            $form_container->output_row($lang->newpoints_shop_addedit_cat_usergroups, $lang->newpoints_shop_addedit_cat_usergroups_desc, $form->generate_select_box('usergroups[]', $options, '', array('id' => 'usergroups', 'multiple' => true, 'size' => 5)), 'groups');
            $form_container->output_row($lang->newpoints_shop_addedit_cat_disporder, $lang->newpoints_shop_addedit_cat_disporder_desc, $form->generate_text_box('disporder', '0', array('id' => 'disporder')), 'disporder');
            $form_container->output_row($lang->newpoints_shop_addedit_cat_expanded, $lang->newpoints_shop_addedit_cat_expanded_desc, $form->generate_yes_no_radio('expanded', 1), 'expanded');
            $form_container->end();
            $buttons = "";
            $buttons[] = $form->generate_submit_button($lang->newpoints_shop_submit);
            $buttons[] = $form->generate_reset_button($lang->newpoints_shop_reset);
            $form->output_submit_wrapper($buttons);
            $form->end();
        } elseif ($mybb->input['action'] == 'editcat') {
            $page->output_nav_tabs($sub_tabs, 'newpoints_shop_categories_edit');
            $cid = intval($mybb->input['cid']);
            if ($cid <= 0 || !($cat = $db->fetch_array($db->simple_select('newpoints_shop_categories', '*', "cid = {$cid}")))) {
                newpoints_shop_messageredirect($lang->newpoints_shop_invalid_cat, 1);
            }
            $query = $db->simple_select("usergroups", "gid, title", "gid != '1'", array('order_by' => 'title'));
            while ($usergroup = $db->fetch_array($query)) {
                $options[$usergroup['gid']] = $usergroup['title'];
            }
            $form = new Form("index.php?module=newpoints-shop&amp;action=do_editcat", "post", "newpoints_shop");
            echo $form->generate_hidden_field('cid', $cat['cid']);
            $form_container = new FormContainer($lang->newpoints_shop_addcat);
            $form_container->output_row($lang->newpoints_shop_addedit_cat_name . "<em>*</em>", $lang->newpoints_shop_addedit_cat_name_desc, $form->generate_text_box('name', htmlspecialchars_uni($cat['name']), array('id' => 'name')), 'name');
            $form_container->output_row($lang->newpoints_shop_addedit_cat_description, $lang->newpoints_shop_addedit_cat_description_desc, $form->generate_text_box('description', htmlspecialchars_uni($cat['description']), array('id' => 'description')), 'description');
            $form_container->output_row($lang->newpoints_shop_addedit_cat_visible, $lang->newpoints_shop_addedit_cat_visible_desc, $form->generate_yes_no_radio('visible', intval($cat['visible'])), 'visible');
            $form_container->output_row($lang->newpoints_shop_addedit_cat_icon, $lang->newpoints_shop_addedit_cat_icon_desc, $form->generate_text_box('icon', htmlspecialchars_uni($cat['icon']), array('id' => 'icon')), 'icon');
            $form_container->output_row($lang->newpoints_shop_addedit_cat_usergroups, $lang->newpoints_shop_addedit_cat_usergroups_desc, $form->generate_select_box('usergroups[]', $options, explode(',', $cat['usergroups']), array('id' => 'usergroups', 'multiple' => true, 'size' => 5)), 'groups');
            $form_container->output_row($lang->newpoints_shop_addedit_cat_disporder, $lang->newpoints_shop_addedit_cat_disporder_desc, $form->generate_text_box('disporder', intval($cat['disporder']), array('id' => 'disporder')), 'disporder');
            $form_container->output_row($lang->newpoints_shop_addedit_cat_expanded, $lang->newpoints_shop_addedit_cat_expanded_desc, $form->generate_yes_no_radio('expanded', intval($cat['expanded'])), 'expanded');
            $form_container->end();
            $buttons = "";
            $buttons[] = $form->generate_submit_button($lang->newpoints_shop_submit);
            $buttons[] = $form->generate_reset_button($lang->newpoints_shop_reset);
            $form->output_submit_wrapper($buttons);
            $form->end();
        } else {
            if ($mybb->input['action'] == 'items') {
                $page->output_nav_tabs($sub_tabs, 'newpoints_shop_items');
                $cid = intval($mybb->input['cid']);
                if ($cid <= 0 || !($cat = $db->fetch_array($db->simple_select('newpoints_shop_categories', '*', "cid = {$cid}")))) {
                    newpoints_shop_messageredirect($lang->newpoints_shop_invalid_cat, 1);
                }
                // table
                $table = new Table();
                $table->construct_header($lang->newpoints_shop_item_icon, array('width' => '10%', 'class' => 'align_center'));
                $table->construct_header($lang->newpoints_shop_item_name, array('width' => '30%'));
                $table->construct_header($lang->newpoints_shop_item_price, array('width' => '15%', 'class' => 'align_center'));
                $table->construct_header($lang->newpoints_shop_item_disporder, array('width' => '15%', 'class' => 'align_center'));
                $table->construct_header($lang->newpoints_shop_item_action, array('width' => '20%', 'class' => 'align_center'));
                $query = $db->simple_select('newpoints_shop_items', '*', 'cid=\'' . $cid . '\'', array('order_by' => 'disporder', 'order_dir' => 'ASC'));
                while ($item = $db->fetch_array($query)) {
                    if ($item['infinite'] == 1) {
                        $item['stock'] = $lang->newpoints_shop_infinite;
                    }
                    if ($item['visible'] == 0) {
                        $visible_info = ' (<span style="color: #FF0000;">hidden</span>)';
                    } else {
                        $visible_info = '';
                    }
                    $table->construct_cell(htmlspecialchars_uni($item['icon']) ? '<img src="' . $mybb->settings['bburl'] . '/' . $item['icon'] . '">' : '<img src="' . $mybb->settings['bburl'] . '/images/newpoints/default.png">', array('class' => 'align_center'));
                    $table->construct_cell(htmlspecialchars_uni($item['name']) . " (" . (intval($item['infinite']) ? $lang->newpoints_shop_infinite : intval($item['stock'])) . ")" . $visible_info . "<br /><small>" . htmlspecialchars_uni($item['description']) . "</small>");
                    $table->construct_cell(newpoints_format_points($item['price']), array('class' => 'align_center'));
                    $table->construct_cell(intval($item['disporder']), array('class' => 'align_center'));
                    // actions column
                    $table->construct_cell("<a href=\"index.php?module=newpoints-shop&amp;action=edititem&amp;iid=" . intval($item['iid']) . "\">" . $lang->newpoints_shop_edit . "</a> - <a href=\"index.php?module=newpoints-shop&amp;action=do_deleteitem&amp;iid=" . intval($item['iid']) . "\">" . $lang->newpoints_shop_delete . "</a>", array('class' => 'align_center'));
                    $table->construct_row();
                }
                if ($table->num_rows() == 0) {
                    $table->construct_cell($lang->newpoints_shop_no_items, array('colspan' => 6));
                    $table->construct_row();
                }
                $table->output($lang->newpoints_shop_items);
            } elseif ($mybb->input['action'] == 'additem') {
                $page->output_nav_tabs($sub_tabs, 'newpoints_shop_items_add');
                $cid = intval($mybb->input['cid']);
                if ($cid > 0) {
                    if ($cid <= 0 || !($cat = $db->fetch_array($db->simple_select('newpoints_shop_categories', '*', "cid = {$cid}")))) {
                        newpoints_shop_messageredirect($lang->newpoints_shop_invalid_cat, 1);
                    }
                } else {
                    $cid = 0;
                }
                $categories[0] = $lang->newpoints_shop_select_cat;
                $query = $db->simple_select('newpoints_shop_categories', '*');
                while ($cat = $db->fetch_array($query)) {
                    $categories[$cat['cid']] = $cat['name'];
                }
                $form = new Form("index.php?module=newpoints-shop&amp;action=do_additem", "post", "newpoints_shop");
                $form_container = new FormContainer($lang->newpoints_shop_additem);
                $form_container->output_row($lang->newpoints_shop_addedit_item_name . "<em>*</em>", $lang->newpoints_shop_addedit_item_name_desc, $form->generate_text_box('name', '', array('id' => 'name')), 'name');
                $form_container->output_row($lang->newpoints_shop_addedit_item_description, $lang->newpoints_shop_addedit_item_description_desc, $form->generate_text_box('description', '', array('id' => 'description')), 'description');
                $form_container->output_row($lang->newpoints_shop_addedit_item_price, $lang->newpoints_shop_addedit_item_price_desc, $form->generate_text_box('price', '0', array('id' => 'price')), 'price');
                $form_container->output_row($lang->newpoints_shop_addedit_item_icon, $lang->newpoints_shop_addedit_item_icon_desc, $form->generate_text_box('icon', '', array('id' => 'icon')), 'icon');
                $form_container->output_row($lang->newpoints_shop_addedit_item_disporder, $lang->newpoints_shop_addedit_item_disporder_desc, $form->generate_text_box('disporder', '0', array('id' => 'disporder')), 'disporder');
                $form_container->output_row($lang->newpoints_shop_addedit_item_stock, $lang->newpoints_shop_addedit_item_stock_desc, $form->generate_text_box('stock', '0', array('id' => 'stock')), 'stock');
                $form_container->output_row($lang->newpoints_shop_addedit_item_infinite, $lang->newpoints_shop_addedit_item_infinite_desc, $form->generate_yes_no_radio('infinite', 1), 'infinite');
                $form_container->output_row($lang->newpoints_shop_addedit_item_limit, $lang->newpoints_shop_addedit_item_limit_desc, $form->generate_text_box('limit', '0', array('id' => 'limit')), 'limit');
                $form_container->output_row($lang->newpoints_shop_addedit_item_visible, $lang->newpoints_shop_addedit_item_visible_desc, $form->generate_yes_no_radio('visible', 1), 'visible');
                $form_container->output_row($lang->newpoints_shop_addedit_item_sendable, $lang->newpoints_shop_addedit_item_sendable_desc, $form->generate_yes_no_radio('sendable', 1), 'sendable');
                $form_container->output_row($lang->newpoints_shop_addedit_item_sellable, $lang->newpoints_shop_addedit_item_sellable_desc, $form->generate_yes_no_radio('sellable', 1), 'sellable');
                $form_container->output_row($lang->newpoints_shop_addedit_item_pm, $lang->newpoints_shop_addedit_item_pm_desc, $form->generate_text_area('pm', '', array('id' => 'pm_text')), 'pm');
                $form_container->output_row($lang->newpoints_shop_addedit_item_category . "<em>*</em>", $lang->newpoints_shop_addedit_item_category_desc, $form->generate_select_box('cid', $categories, $cid, array('id' => 'cid')), 'cid');
                $args = array($form_container, $form, array());
                $plugins->run_hooks("newpoints_shop_row", $args);
                $form_container->end();
                $buttons = "";
                $buttons[] = $form->generate_submit_button($lang->newpoints_shop_submit);
                $buttons[] = $form->generate_reset_button($lang->newpoints_shop_reset);
                $form->output_submit_wrapper($buttons);
                $form->end();
            } elseif ($mybb->input['action'] == 'edititem') {
                $page->output_nav_tabs($sub_tabs, 'newpoints_shop_items_edit');
                $iid = intval($mybb->input['iid']);
                if ($iid <= 0 || !($item = $db->fetch_array($db->simple_select('newpoints_shop_items', '*', "iid = {$iid}")))) {
                    newpoints_shop_messageredirect($lang->newpoints_shop_invalid_item, 1, 'items');
                }
                $categories[0] = $lang->newpoints_shop_select_cat;
                $query = $db->simple_select('newpoints_shop_categories', '*');
                while ($cat = $db->fetch_array($query)) {
                    $categories[$cat['cid']] = $cat['name'];
                }
                $form = new Form("index.php?module=newpoints-shop&amp;action=do_edititem", "post", "newpoints_shop");
                echo $form->generate_hidden_field('iid', $iid);
                $form_container = new FormContainer($lang->newpoints_shop_additem);
                $form_container->output_row($lang->newpoints_shop_addedit_item_name . "<em>*</em>", $lang->newpoints_shop_addedit_item_name_desc, $form->generate_text_box('name', htmlspecialchars_uni($item['name']), array('id' => 'name')), 'name');
                $form_container->output_row($lang->newpoints_shop_addedit_item_description, $lang->newpoints_shop_addedit_item_description_desc, $form->generate_text_box('description', htmlspecialchars_uni($item['description']), array('id' => 'description')), 'description');
                $form_container->output_row($lang->newpoints_shop_addedit_item_price, $lang->newpoints_shop_addedit_item_price_desc, $form->generate_text_box('price', floatval($item['price']), array('id' => 'price')), 'price');
                $form_container->output_row($lang->newpoints_shop_addedit_item_icon, $lang->newpoints_shop_addedit_item_icon_desc, $form->generate_text_box('icon', htmlspecialchars_uni($item['icon']), array('id' => 'icon')), 'icon');
                $form_container->output_row($lang->newpoints_shop_addedit_item_disporder, $lang->newpoints_shop_addedit_item_disporder_desc, $form->generate_text_box('disporder', intval($item['disporder']), array('id' => 'disporder')), 'disporder');
                $form_container->output_row($lang->newpoints_shop_addedit_item_stock, $lang->newpoints_shop_addedit_item_stock_desc, $form->generate_text_box('stock', intval($item['stock']), array('id' => 'stock')), 'stock');
                $form_container->output_row($lang->newpoints_shop_addedit_item_infinite, $lang->newpoints_shop_addedit_item_infinite_desc, $form->generate_yes_no_radio('infinite', intval($item['infinite'])), 'infinite');
                $form_container->output_row($lang->newpoints_shop_addedit_item_limit, $lang->newpoints_shop_addedit_item_limit_desc, $form->generate_text_box('limit', intval($item['limit']), array('id' => 'limit')), 'limit');
                $form_container->output_row($lang->newpoints_shop_addedit_item_visible, $lang->newpoints_shop_addedit_item_visible_desc, $form->generate_yes_no_radio('visible', intval($item['visible'])), 'visible');
                $form_container->output_row($lang->newpoints_shop_addedit_item_sendable, $lang->newpoints_shop_addedit_item_sendable_desc, $form->generate_yes_no_radio('sendable', intval($item['sendable'])), 'sendable');
                $form_container->output_row($lang->newpoints_shop_addedit_item_sellable, $lang->newpoints_shop_addedit_item_sellable_desc, $form->generate_yes_no_radio('sellable', intval($item['sellable'])), 'sellable');
                $form_container->output_row($lang->newpoints_shop_addedit_item_pm, $lang->newpoints_shop_addedit_item_pm_desc, $form->generate_text_area('pm', htmlspecialchars_uni($item['pm']), array('id' => 'pm_text')), 'pm');
                $form_container->output_row($lang->newpoints_shop_addedit_item_category . "<em>*</em>", $lang->newpoints_shop_addedit_item_category_desc, $form->generate_select_box('cid', $categories, intval($item['cid']), array('id' => 'cid')), 'cid');
                $args = array($form_container, $form, $item);
                $plugins->run_hooks("newpoints_shop_row", $args);
                $form_container->end();
                $buttons = "";
                $buttons[] = $form->generate_submit_button($lang->newpoints_shop_submit);
                $buttons[] = $form->generate_reset_button($lang->newpoints_shop_reset);
                $form->output_submit_wrapper($buttons);
                $form->end();
            } else {
                if ($mybb->input['action'] == 'inventory') {
                    $page->output_nav_tabs($sub_tabs, 'newpoints_shop_inventory');
                    $uid = (int) $mybb->input['uid'];
                    if ($uid <= 0) {
                        newpoints_shop_messageredirect($lang->newpoints_shop_invalid_user, 1);
                    }
                    $user = get_user($uid);
                    // we're viewing someone else's inventory
                    if (empty($user)) {
                        newpoints_shop_messageredirect($lang->newpoints_shop_invalid_user, 1);
                    }
                    $inventory = @unserialize($user['newpoints_items']);
                    if (!$inventory) {
                        $inventory = array(0);
                    }
                    // Item id is 0 because it doesn't exist, this when we use it in the query we won't show anything
                    // table
                    $table = new Table();
                    $table->construct_header($lang->newpoints_shop_item_icon, array('width' => '10%', 'class' => 'align_center'));
                    $table->construct_header($lang->newpoints_shop_item_name, array('width' => '30%'));
                    $table->construct_header($lang->newpoints_shop_item_price, array('width' => '15%', 'class' => 'align_center'));
                    $table->construct_header($lang->newpoints_shop_item_disporder, array('width' => '15%', 'class' => 'align_center'));
                    $table->construct_header($lang->newpoints_shop_item_action, array('width' => '20%', 'class' => 'align_center'));
                    $query = $db->simple_select('newpoints_shop_items', '*', 'iid IN (' . implode(',', array_unique($inventory)) . ')', array('order_by' => 'disporder', 'order_dir' => 'ASC'));
                    while ($item = $db->fetch_array($query)) {
                        if ($item['infinite'] == 1) {
                            $item['stock'] = $lang->newpoints_shop_infinite;
                        }
                        if ($item['visible'] == 0) {
                            $visible_info = ' (<span style="color: #FF0000;">hidden</span>)';
                        } else {
                            $visible_info = '';
                        }
                        $table->construct_cell(htmlspecialchars_uni($item['icon']) ? '<img src="' . $mybb->settings['bburl'] . '/' . $item['icon'] . '">' : '<img src="' . $mybb->settings['bburl'] . '/images/newpoints/default.png">', array('class' => 'align_center'));
                        $table->construct_cell(htmlspecialchars_uni($item['name']) . " (" . count(array_keys($inventory, $item['iid'])) . ")" . $visible_info . "<br /><small>" . htmlspecialchars_uni($item['description']) . "</small>");
                        $table->construct_cell(newpoints_format_points($item['price']), array('class' => 'align_center'));
                        $table->construct_cell(intval($item['disporder']), array('class' => 'align_center'));
                        // actions column
                        $table->construct_cell("<a href=\"index.php?module=newpoints-shop&amp;action=remove&amp;iid=" . intval($item['iid']) . "&amp;uid=" . (int) $user['uid'] . "\">" . $lang->newpoints_shop_remove . "</a>", array('class' => 'align_center'));
                        $table->construct_row();
                    }
                    if ($table->num_rows() == 0) {
                        $table->construct_cell($lang->newpoints_shop_no_items, array('colspan' => 5));
                        $table->construct_row();
                    }
                    $table->output($lang->newpoints_shop_inventory_of . " " . htmlspecialchars_uni($user['username']));
                }
            }
        }
        $page->output_footer();
        exit;
    }
}
Beispiel #3
0
 function newpoints_perview()
 {
     global $db, $mybb, $cache, $groupscache, $userupdates;
     if (!$mybb->user['uid']) {
         return;
     }
     if ($mybb->settings['newpoints_main_enabled'] != 1) {
         return;
     }
     // check group rules - primary group check
     $grouprules = newpoints_getallrules('group');
     if (empty($grouprules)) {
         return;
     }
     if ($mybb->settings['newpoints_income_pageview'] != 0) {
         newpoints_addpoints($mybb->user['uid'], $mybb->settings['newpoints_income_pageview'], 1, $grouprules[$mybb->user['usergroup']]['rate']);
     }
     if ($mybb->settings['newpoints_income_visit'] != 0) {
         if (TIME_NOW - $mybb->user['lastactive'] > 900) {
             newpoints_addpoints($mybb->user['uid'], $mybb->settings['newpoints_income_visit'], 1, $grouprules[$mybb->user['usergroup']]['rate']);
         }
     }
     foreach ($grouprules as $gid => $rule) {
         if ($rule['pointsearn'] == 0 || $rule['period'] == 0 || $rule['lastpay'] > TIME_NOW - $rule['period']) {
             return;
         }
         //die("testing".$rule['pointsearn']." | ".$rule['period']." | ".$rule['lastpay']." | ".TIME_NOW);
         $amount = floatval($rule['pointsearn']);
         $userupdates[$gid] = $amount;
         // update rule with last payment
         $db->update_query('newpoints_grouprules', array('lastpay' => TIME_NOW), 'gid=\'' . $gid . '\'');
         if ($mybb->user['usergroup'] == $gid) {
             $mybb->user['newpoints'] += $amount;
         }
         if (!empty($userupdates)) {
             // run updates to users on shut down
             add_shutdown('newpoints_update_users');
         }
     }
 }
Beispiel #4
0
        error($lang->newpoints_cant_donate_self);
    }
    $amount = round(floatval($mybb->input['amount']), (int) $mybb->settings['newpoints_main_decimal']);
    // do we have enough points?
    if ($amount <= 0 || $amount > $mybb->user['newpoints']) {
        error($lang->newpoints_invalid_amount);
    }
    // make sure we're sending points to a valid user
    $touser = newpoints_getuser_byname($username, 'uid,username');
    if (!$touser) {
        error($lang->newpoints_invalid_user);
    }
    // remove points from us
    newpoints_addpoints($mybb->user['uid'], -$amount);
    // give points to user
    newpoints_addpoints($username, $amount, 1, 1, true);
    // send pm to the user if the "Send PM on donate" setting is set to Yes
    if ($mybb->settings['newpoints_main_donationspm'] != 0) {
        if ($mybb->input['reason'] != '') {
            newpoints_send_pm(array('subject' => $lang->newpoints_donate_subject, 'message' => $lang->sprintf($lang->newpoints_donate_message_reason, newpoints_format_points($amount), htmlspecialchars_uni($mybb->input['reason'])), 'receivepms' => 1, 'touid' => $touser['uid']));
        } else {
            newpoints_send_pm(array('subject' => $lang->newpoints_donate_subject, 'message' => $lang->sprintf($lang->newpoints_donate_message, newpoints_format_points($amount)), 'receivepms' => 1, 'touid' => $touser['uid']));
        }
    }
    // log donation
    newpoints_log('donation', $lang->sprintf($lang->newpoints_donate_log, $touser['username'], $touser['uid'], $amount));
    $plugins->run_hooks("newpoints_do_donate_end");
    redirect($mybb->settings['bburl'] . "/newpoints.php", $lang->sprintf($lang->newpoints_donated, newpoints_format_points($amount)));
}
$plugins->run_hooks("newpoints_terminate");
exit;
Beispiel #5
0
         error('You do not have enough points to purchase this item.');
     } else {
         // take the points from the user
         newpoints_addpoints($mybb->user['uid'], -$info->cost);
         $mybb->settings['lock_tax'] = $mybb->settings['lock_tax'];
         if (is_numeric($mybb->settings['lock_tax']) && $mybb->settings['lock_tax'] > 0) {
             $tax = $mybb->settings['lock_tax'];
         }
         if (isset($tax) && $tax > 100) {
             $tax = 100;
         }
         if (is_numeric($tax)) {
             $info->cost = $info->cost - $info->cost / 100 * $tax;
         }
         // give them to the creator of the post
         newpoints_addpoints($post['uid'], $info->cost);
         // add the user to the list of people with access to the content
         $allowed[] = $mybb->user['uid'];
         $allowed = implode(',', $allowed);
         $unlocked = array("unlocked" => $allowed);
         $db->update_query("posts", $unlocked, "pid='{$info->pid}'");
     }
 }
 // now, check that the post actually exists
 $query = $db->simple_select('posts', '*', "pid = '{$info->pid}'");
 if ($db->num_rows($query)) {
     // if it does, redirect the user to the post.
     $post = $db->fetch_array($query);
     $url = $mybb->settings['bburl'] . '/' . get_post_link($info->pid) . '#pid' . $info->pid;
     header("Location: " . $url);
     exit;