Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-19-2014, 11:22 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Problem with User Additions

Hey all! I am trying to design a system for our staff to add "points" to users for participating in events. I currently have the following code. The "Edit" and "Update" code works. I have tested it. What is not working is the main "add" part. A staff member should be able to type in multiple usernames separated by a semicolon ( then the correct number of points should be added. If anyone can help, let me know!

http://pastebin.com/Z2QxkkZU

Thanks again!
Reply With Quote
  #2  
Old 10-20-2014, 10:12 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What happens when you try to add? The only thing I can see is that at the end of your update query sql you have:
Code:
username='$u[0]'";
and I believe it should just be $u.
Reply With Quote
  #3  
Old 10-20-2014, 08:12 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have it working a bit, but now there is only one issue. Code below:

Basically, in the "UPDATE" portion, it works except when $upoints is 0, then the query is not executed and no confirmation message appears.

PHP Code:
<?php
// In Game Activity Points
// by DrMath
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### PRE-CACHE TEMPLATES AND DATA ######################
$phrasegroups = array('style');
$specialtemplates = array('products');

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');
require_once(
DIR '/includes/adminfunctions_template.php');

$this_script 'iga_points';

$rpm_ver 1.0;

$rpm_mouseover_fontcolor '#D04850';

// ######################## CHECK ADMIN PERMISSIONS #######################
if (!can_administer('canadminusers'))
{
    
print_cp_no_permission();
}

print_cp_header();
echo 
"<div class='pagetitle'>In Game Activity System</div>";

//Possible Point Values
$pointreasons = array("Attended a Gamenight (+15)""Attended a Contest/Torunament (+25)");

/////////////////////// front page
if ( empty($_POST['do']) ) {
    
print_form_header($this_script'add');
    
print_table_header('Add Points');
    
print_label_row('Notice:''Select the point value based on the event.');
    
print_select_row('Points''points'$pointreasons);
    
print_label_row('Users:''Input the usernames of all the users you wish to give the above points to. You must separate names using a semicolon (;).');
    
print_textarea_row('Users''users','',12,100,false,false);
    
print_submit_row('Add Points');
    
    
////////////////////// edit points
    
print_form_header($this_script'edit');
    
print_table_header('Edit Points');
    
print_label_row('Username:''Enter the username of who you want to edit the points value of.');
    
print_input_row('Username''username');
    
print_submit_row('Edit Points');
}

/////////////////////// add
if ( $_POST['do'] == 'add' ) {
   
    if ( empty(
$_POST['points']) OR empty($_POST['users']) ) { rpm_print_stop_back('Please be sure every required field is filled out before submitting.'); }
   
    
$vbulletin->input->clean_array_gpc('p', array(
        
'points'         => TYPE_UNIT,
        
'users'          => TYPE_STR
        
));
    
    
$apoints $vbulletin->GPC['points'];
    if (
$apoints == 0) { $addpoints 15; }
    if (
$apoints == 1) { $addpoints 25; }
    
$ausers $db->escape_string($vbulletin->GPC['users']);
    
$addusers explode(";",$ausers);
    
//$adate = date("Y-m-d");
    
    
foreach ($addusers as &$u) {
        
$user trim($u);
        
$sql "UPDATE " TABLE_PREFIX "user SET iga_points = iga_points + $addpoints, iga_lastpointsdate = NOW() WHERE username='$user'";
        
$db->query_write($sql);
    }
   
    
define('CP_REDIRECT''iga_points.php');
    
print_stop_message('iga_points_added');
}  

/////////////////////// edit
if ( $_POST['do'] == 'edit' ) {
   
    if ( !isset(
$_POST['username']) ) { rpm_print_stop_back('Please be sure every required field is filled out before submitting.'); }
    
   
    
$vbulletin->input->clean_array_gpc('p', array(
        
'username'      => TYPE_STR
        
));
    
    
$edituser $db->escape_string($vbulletin->GPC['username']);
    
    
$sql "SELECT iga_points FROM " TABLE_PREFIX "user WHERE username = '$edituser'";
    
$result $db->query_read_slave($sql);
    
$cpoints mysql_result($result,0);
    
    
print_form_header($this_script'update');
    
print_table_header("Update ".$edituser."'s Points");
    echo 
"<input type='hidden' name='username' value='$edituser'>";
    
print_label_row('Note:''Points must be between 0 and 400.');
    
print_input_row('Points''points'$cpoints);
    
print_submit_row('Update Points');
}

/////////////////////// add
if ( $_POST['do'] == 'update' ) {
   
    if ( empty(
$_POST['username']) OR empty($_POST['points']) ) { rpm_print_stop_back('Please be sure every required field is filled out before submitting.'); }
   
    
$vbulletin->input->clean_array_gpc('p', array(
        
'username'  => TYPE_STR,
        
'points'    => TYPE_UNIT
        
));
    
    
$uuser $db->escape_string($vbulletin->GPC['username']);
    
$upoints $vbulletin->GPC['points'];
    
//$udate = date("Y-m-d");
    
    
if ($upoints || $upoints 400) {
        
define('CP_REDIRECT''iga_points.php');
        
print_stop_message('iga_points_val_error');
    } else {
        
$sql "UPDATE " TABLE_PREFIX "user SET iga_points=$upoints, iga_lastpointsdate=NOW() WHERE username = '$uuser'";
        
$db->query_write($sql);
        
define('CP_REDIRECT''iga_points.php');
        
print_stop_message('iga_points_updated'); 
    }
    
}

print_cp_footer();
?>
Reply With Quote
  #4  
Old 10-20-2014, 08:25 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You have empty($_POST['points']), but that will be true if it's 0 (see the php page for empty()). I think you want to use !isset($_POST['points']) instead.
Reply With Quote
2 благодарности(ей) от:
KGodel, Lynne
  #5  
Old 10-20-2014, 08:33 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you based kh99. <3 I'm still a noob at this stuff. T.T
Reply With Quote
  #6  
Old 10-22-2014, 08:09 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Alright, so I have added another way to add points to make it easier for my members. Here is the code:

PHP Code:
<?php
// In Game Activity Points
// by DrMath
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### PRE-CACHE TEMPLATES AND DATA ######################
$phrasegroups = array('style');
$specialtemplates = array('products');

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');
require_once(
DIR '/includes/adminfunctions_template.php');

$this_script 'iga_points';

$rpm_ver 1.0;

$rpm_mouseover_fontcolor '#D04850';

// ######################## CHECK ADMIN PERMISSIONS #######################
if (!can_administer('canadminusers'))
{
    
print_cp_no_permission();
}

print_cp_header();
echo 
"<div class='pagetitle'>In Game Activity System</div>";

//Possible Point Values
$pointreasons = array("Attended a Gamenight (+15)""Attended a Contest/Torunament (+25)");

// Get Divisions //
$sql "SELECT gamename, ingamename, profilefield FROM " TABLE_PREFIX "gamelist ORDER BY gamename ASC";
$result $db->query_read_slave($sql);
$divisions = array();
while ( 
$a mysql_fetch_array($result) ) {
    
$divisions[] = $a;
    
$divnames[] = $a[0];
}

/////////////////////// front page
if ( empty($_POST['do']) ) {
    
    
////////////////////// add points via division
    
print_form_header($this_script'div');
    
print_table_header('Add Points via Division');
    
print_label_row('Notice:''Select the division you are entering activity for.');
    
print_select_row('Divisions''division'$divnames);
    
print_submit_row('Select Division');
    
    
////////////////////// add points text area
    
print_form_header($this_script'add');
    
print_table_header('Add Points');
    
print_label_row('Notice:''Select the point value based on the event.');
    
print_select_row('Points''points'$pointreasons);
    
print_label_row('Users:''Input the usernames of all the users you wish to give the above points to. You must separate names using a semicolon (;).');
    
print_textarea_row('Users''users','',12,100,false,false);
    
print_submit_row('Add Points');
    
    
////////////////////// edit points
    
print_form_header($this_script'edit');
    
print_table_header('Edit Points');
    
print_label_row('Username:''Enter the username of who you want to edit the points value of.');
    
print_input_row('Username''username');
    
print_submit_row('Edit Points');
}

/////////////////////// div selected
if ( $_POST['do'] == 'div' ) {
   
    if ( !isset(
$_POST['division']) ) { rpm_print_stop_back('Please select a division.'); }
   
    
$vbulletin->input->clean_array_gpc('p', array(
        
'division'         => TYPE_UNIT
        
));
    
    
// Division Name //
    
$n $vbulletin->GPC['division'];
    
$divname $divisions[$n][0];
    
$divign $divisions[$n][1];
    
$divfield $divisions[$n][2];
    $+++++
eck 1<<$n;
    
    
// Get Main Members
    
$mainusers $db->query_read_slave("SELECT user.userid, user.username, userfield. " $divfield ." FROM " TABLE_PREFIX "user AS user LEFT JOIN " TABLE_PREFIX "userfield as userfield ON (userfield.userid = user.userid) WHERE (userfield.field5='" $divname "') AND (user.username != '') AND (user.usergroupid NOT IN (1,3,4,7,8,20,21,23,45)) ORDER BY username");
    if (!
$mainusers){ die('Invalid query: ' mysql_error()); }
    
// Set the Users Array
    
$maingameusers = array();
    while (
$user mysql_fetch_array($mainusers)) {
        if (
$user[2] == null) { $ign "N/A"; } else { $ign $user[2]; }
        
$maingameusers[$user[0]] = $user[1] . "  -  " $divign ": " $ign;
    }

    
// Get Other Game Members
    
$otherusers $db->query_read_slave("SELECT user.userid, user.username, userfield. " $divfield " FROM " TABLE_PREFIX "user AS user LEFT JOIN " TABLE_PREFIX "userfield as userfield ON (userfield.userid = user.userid) WHERE (userfield.field5 != '" $divname "') AND (userfield.field6 & " . $+++++eck ") AND (user.username != '') AND (user.usergroupid NOT IN (1,3,4,7,8,20,21,23,45)) ORDER BY username");
    if (!
$otherusers){ die('Invalid query: ' mysql_error()); }
    
// Set the Users Aray
    
$othergameusers = array();
    while (
$user mysql_fetch_array($otherusers)) {
        if (
$user[2] == null) { $ign "N/A"; } else { $ign $user[2]; }
        
$othergameusers[$user[0]] = $user[1] . "  -  " $divign ": " $ign;
    }
    
    
////////////////////// select users to get points
    
print_form_header($this_script'divadd');
    
print_table_header('Add Points to ' $divname ' Members');
    
print_label_row('Event Type:''Select the event type (and point value) to give.');
    
print_select_row('Points''points'$pointreasons);
    
print_label_row('Main Users:''Select the Main-Game users who attended the event.');
    
print_select_row('Main Users''mainusers'$maingameusers,null,false,10,true);
    
print_label_row('Other Users:''Select the Other-Game users who attended the event.');
    
print_select_row('Other Users''otherusers'$othergameusers,null,false,10,true);
    
print_label_row('Note:''Hold the control key while clicking to select multiple names.');
    
print_submit_row('Add Points to Selected Users','Reset');
    


/////////////////////// add
if ( $_POST['do'] == 'add' ) {
   
    if ( !isset(
$_POST['points']) OR empty($_POST['users']) ) { rpm_print_stop_back('Please be sure every required field is filled out before submitting.'); }
   
    
$vbulletin->input->clean_array_gpc('p', array(
        
'points'         => TYPE_UNIT,
        
'users'          => TYPE_STR
        
));
    
    
$apoints $vbulletin->GPC['points'];
    if (
$apoints == 0) { $addpoints 15; }
    if (
$apoints == 1) { $addpoints 25; }
    
$ausers $db->escape_string($vbulletin->GPC['users']);
    
$addusers explode(";",$ausers);
    
//$adate = date("Y-m-d");
    
    
foreach ($addusers as &$u) {
        
$user trim($u);
        
$sql "UPDATE " TABLE_PREFIX "user SET iga_points = iga_points + $addpoints, iga_lastpointsdate = NOW() WHERE username='$user'";
        
$db->query_write($sql);
    }
   
    
define('CP_REDIRECT''iga_points.php');
    
print_stop_message('iga_points_added');
}  

/////////////////////// add via division
if ( $_POST['do'] == 'divadd' ) {
   
    if ( !isset(
$_POST['points']) OR empty($_POST['mainusers']) ) { rpm_print_stop_back('Please be sure every required field is filled out before submitting.'); }
   
    
$vbulletin->input->clean_array_gpc('p', array(
        
'points'         => TYPE_UNIT,
        
'mainusers'      => TYPE_ARRAY,
        
'otherusers'     => TYPE_ARRAY
        
));
    
    
$apoints $vbulletin->GPC['points'];
    if (
$apoints == 0) { $addpoints 15; }
    if (
$apoints == 1) { $addpoints 25; }
    
$addmain $addother = array();
    
$addmain $vbulletin->GPC['mainusers'];
    
$addother $vbulletin->GPC['otherusers'];
    
//$adate = date("Y-m-d");
    
    // Main Gamers
    
foreach ($addmain as &$u) {
        
$sql "UPDATE " TABLE_PREFIX "user SET iga_points = iga_points + $addpoints, iga_lastpointsdate = NOW() WHERE userid=$u";
        
$db->query_write($sql);
    }
    
    
// Other Gamers
    
foreach ($addother as &$u) {
        
$sql "UPDATE " TABLE_PREFIX "user SET iga_points = iga_points + $addpoints, iga_lastpointsdate = NOW() WHERE userid=$u";
        
$db->query_write($sql);
    }
   
    
define('CP_REDIRECT''iga_points.php');
    
print_stop_message('iga_points_added');
}  

/////////////////////// edit
if ( $_POST['do'] == 'edit' ) {
   
    if ( !isset(
$_POST['username']) ) { rpm_print_stop_back('Please be sure every required field is filled out before submitting.'); }
    
   
    
$vbulletin->input->clean_array_gpc('p', array(
        
'username'      => TYPE_STR
        
));
    
    
$edituser $db->escape_string($vbulletin->GPC['username']);
    
    
$sql "SELECT iga_points FROM " TABLE_PREFIX "user WHERE username = '$edituser'";
    
$result $db->query_read_slave($sql);
    
$cpoints mysql_result($result,0);
    
    
print_form_header($this_script'update');
    
print_table_header("Update ".$edituser."'s Points");
    echo 
"<input type='hidden' name='username' value='$edituser'>";
    
print_label_row('Note:''Points must be between 0 and 400.');
    
print_input_row('Points''points'$cpoints);
    
print_submit_row('Update Points');
}

/////////////////////// add
if ( $_POST['do'] == 'update' ) {
   
    if ( empty(
$_POST['username']) OR !isset($_POST['points']) ) { rpm_print_stop_back('Please be sure every required field is filled out before submitting.'); }
   
    
$vbulletin->input->clean_array_gpc('p', array(
        
'username'  => TYPE_STR,
        
'points'    => TYPE_UNIT
        
));
    
    
$uuser $db->escape_string($vbulletin->GPC['username']);
    
$upoints $vbulletin->GPC['points'];
    
    
//$udate = date("Y-m-d");
    
    
if ($upoints or $upoints 400) {
        
define('CP_REDIRECT''iga_points.php');
        
print_stop_message('iga_points_val_error');
    } else {
        
$sql "UPDATE " TABLE_PREFIX "user SET iga_points=$upoints, iga_lastpointsdate=NOW() WHERE username = '$uuser'";
        
$db->query_write($sql);
        
define('CP_REDIRECT''iga_points.php');
        
print_stop_message('iga_points_updated'); 
    }
    
}

print_cp_footer();
?>
The issue occurs in the "add via division" section. The message appears, saying that it has added the points but the queries are not actually being executed. Any suggestions would be helpful! This is coming along nicely for me!
Reply With Quote
  #7  
Old 10-22-2014, 08:16 PM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Not entirely sure but I believe iga_lastpointsdate = NOW should be iga_lastpointsdate = TIMENOW
Reply With Quote
Благодарность от:
KGodel
  #8  
Old 10-22-2014, 08:21 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The NOW works. I've tested that. ^^ The newest addition was the "div" and "divadd" parts. I'm thinking there is something wonky when I attempt to pass the array of values from the multiple-selection box. All other methods of input work, so that's why I think it has to be that part of the query.

EDIT: I found the error. I needed to add square brackets to the names of the multi-select menus in order to have them pass the information as an array. Thanks for the help!
Reply With Quote
  #9  
Old 10-22-2014, 09:21 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The correct function is being used: NOW() is a database function and does refer to the immediate timedate stamp, "timenow()" is the PHP version.

@KGodel, I am too busy today, but I will try to take a look at it tomorrow if no one has answered your question.
Reply With Quote
Благодарность от:
KGodel
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:13 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04477 seconds
  • Memory Usage 2,409KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (4)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete