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 < 0 || $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();
?>