Plugin Directory

Changeset 2056056


Ignore:
Timestamp:
03/23/2019 09:19:03 PM (7 years ago)
Author:
magent
Message:

COmpleted phpvars fix for experience spends - reducing number of inputs on page

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vampire-character/trunk/inc/xpfunctions.php

    r1847089 r2056056  
    11<?php
     2
    23function vtm_xp_spend_content_filter($content) {
    34
     
    1112
    1213
    13 /*
    1414function vtm_doPendingXPSpend($character) {
    1515    global $wpdb;
    1616    $characterID = vtm_establishCharacterID($character);
    1717    $playerID    = vtm_establishPlayerID($character);
    18    
     18       
     19    $count = 0;
     20    $requestspends = array();
     21    foreach ($_REQUEST as $spend => $details) {
     22        $data = explode(":",$spend);
     23        if (count($data) > 1) {
     24           
     25            $data        = explode(":",$spend);
     26            $count++;
     27            vtm_save_to_pending($data, $details, $playerID, $characterID
     28            );
     29        }
     30    }   
     31   
     32   
     33    /*
    1934    $submitted = array();
    2035    if (isset($_REQUEST['stat_level'])) {
     
    4661        $newid = vtm_save_to_pending('combo', 'CHARACTER_COMBO_DISCIPLINE', 'COMBO_DISCIPLINE', 'COMBO_DISCIPLINE_ID', $playerID, $characterID);
    4762    }
    48    
    49     if (count($submitted) > 0) {
     63    */
     64   
     65    if ($count > 0) {
    5066        $email = get_option( 'vtm_replyto_address', get_option( 'vtm_chargen_email_from_address', get_bloginfo('admin_email') ) );
    5167        $body = "<p>A user has submitted experience spends.</p><p>View the spends here: " .
     
    5470    }
    5571}
    56    
     72    /*
    5773//  master_xp_update VTM_FORM
    5874function vtm_handleMasterXP() {
     
    85101       
    86102    //echo "<!--";
    87     print_r($_POST);
     103    //print_r($_POST);
    88104    //echo "-->";
    89105   
     
    98114    // Cancel Spends
    99115
    100     $docancel = (isset($_REQUEST['stat_cancel'])
    101                 || isset($_REQUEST['skill_cancel'])
    102                 || isset($_REQUEST['disc_cancel'])
    103                 || isset($_REQUEST['combo_cancel'])
    104                 || isset($_REQUEST['path_cancel'])
    105                 || isset($_REQUEST['ritual_cancel'])
    106                 || isset($_REQUEST['merit_cancel'])
    107                 );
     116    $docancel = isset($_REQUEST['cancel']);
     117    if ($docancel) {
     118        vtm_cancel_pending($_REQUEST['cancel']);
     119    }
     120   
    108121    /*  if (isset($_REQUEST['stat_cancel']))    vtm_cancel_pending($_REQUEST['stat_cancel']);
    109122    if (isset($_REQUEST['skill_cancel']))   vtm_cancel_pending($_REQUEST['skill_cancel']);
     
    156169
    157170    $output = "";
    158 $character   = vtm_establishCharacter($character);
     171    $character   = vtm_establishCharacter($character);
    159172    $characterID = vtm_establishCharacterID($character);
    160173
    161174    $spent = 0;
    162     foreach ($_REQUEST as $spend => $level) {
     175    foreach ($_REQUEST as $spend => $details) {
    163176        $data = explode(":",$spend);
    164177        if (count($data) > 1) {
    165             $spent += $data[4];
     178            $spent += $data[5];
    166179        }
    167180    }
     
    255268    // get the current pending spends for this character
    256269    $pendingSpends = vtm_get_pending($characterID);
     270   
    257271    $sectioncontent['stat']   = vtm_render_spend_table('stat', 'vtm_get_sql_stats', $characterID, $maxRating, $xp_avail);
    258     //$sectioncontent['skill']  = array(); //vtm_render_skills($characterID, $maxRating, $pendingSpends, $xp_avail);
    259272    $sectioncontent['skill']  = vtm_render_spend_table('skill', 'vtm_get_sql_skills', $characterID, $maxRating, $xp_avail);
    260273    $sectioncontent['disc']   = vtm_render_spend_table('disc', 'vtm_get_sql_disc', $characterID, $maxDiscipline, $xp_avail);
    261     $sectioncontent['combo']  = array(); //vtm_render_combo($characterID, $pendingSpends, $xp_avail);
     274    $sectioncontent['combo']  = vtm_render_spend_table('combo', 'vtm_get_sql_combo', $characterID, $maxRating, $xp_avail);
    262275    $sectioncontent['path']   = vtm_render_spend_table('path', 'vtm_get_sql_path', $characterID, $maxRating, $xp_avail);
    263     $sectioncontent['ritual'] = array(); //vtm_render_rituals($characterID, 5, $pendingSpends, $xp_avail);
    264     $sectioncontent['merit']  = array(); //vtm_render_merits($characterID, $pendingSpends, $xp_avail);
     276    $sectioncontent['ritual'] = vtm_render_spend_table('ritual', 'vtm_get_sql_ritual', $characterID, 5, $xp_avail); //vtm_render_rituals($characterID, 5, $pendingSpends, $xp_avail);
     277    $sectioncontent['merit']  = vtm_render_spend_table('merit', 'vtm_get_sql_merit', $characterID, 100, $xp_avail); //vtm_render_merits($characterID, $pendingSpends, $xp_avail);
    265278   
    266279   
     
    417430    $sql = $wpdb->prepare($sql, $characterID);
    418431    $characterMaximums = $wpdb->get_results($sql);
     432
    419433    foreach ($characterMaximums as $charMax) {
    420434        $maxRating = $charMax->max_rating;
     
    436450    $requestChTables = array();
    437451    $requestspends = array();
    438     foreach ($_REQUEST as $spend => $level) {
     452    foreach ($_REQUEST as $spend => $details) {
    439453        $data = explode(":",$spend);
    440454        if (count($data) > 1) {
    441             array_push($requestspends, $spend);
    442             $requestItemTables[$data[0]] = 1;
    443             if ($data[3] != 0) {
    444                 $requestChTables[$data[2]] = 1;
     455            $requestspends[$spend] = $details;
     456            $requestItemTables[$data[1]] = 1;
     457            if ($data[4] != 0) {
     458                $requestChTables[$data[3]] = 1;
    445459            }
    446460        }
    447461    }   
    448462    ksort($requestspends);
     463   
     464    // print "<br>";
     465    // print_r($requestspends);
     466    // print "<br>";
    449467   
    450468    // Query the Item Table information
     
    454472        $columns = "";
    455473        $existing_columns = $wpdb->get_col("DESC " . VTM_TABLE_PREFIX . $itemtable, 0);
     474
    456475        $match_columns = array_intersect(array("SPECIALISATION_AT"), $existing_columns);
    457476        $columns = empty($match_columns) ? "" : ",SPECIALISATION_AT";
     477        $match_columns = array_intersect(array("HAS_SPECIALISATION"), $existing_columns);
     478        $columns .= empty($match_columns) ? "" : ",HAS_SPECIALISATION";
     479
    458480        $itemInfo[$itemtable] = $wpdb->get_results("SELECT ID,NAME $columns FROM " . VTM_TABLE_PREFIX . $itemtable, OBJECT_K);
    459     }
    460     //print_r($itemInfo);
     481       
     482       
     483    }
    461484    // Query the character table
    462485    $charTableInfo = array();
    463486    foreach ($requestChTables as $chartable => $discard) {
    464         $charTableInfo[$chartable] = $wpdb->get_results(
    465             $wpdb->prepare("SELECT ID,COMMENT FROM " . VTM_TABLE_PREFIX . $chartable . "WHERE CHARACTER_ID = '%s'",$characterID)
    466         );
    467     }
    468     print_r($charTableInfo);
     487        $sql = $wpdb->prepare("SELECT ID,COMMENT,LEVEL FROM " . VTM_TABLE_PREFIX . $chartable . " WHERE CHARACTER_ID = '%s'",$characterID);
     488        //print "SQL: $sql<br>";
     489        $charTableInfo[$chartable] = $wpdb->get_results($sql, OBJECT_K);
     490    }
     491    // print "<br>";
     492    // print_r($charTableInfo);
     493    // print "<br>";
    469494   
    470495    // Display the table
    471     $index = 0;
    472     foreach ($requestspends as $spend) {
    473         $level = $_REQUEST[$spend];
     496    foreach ($requestspends as $spend => $details) {
     497        $level = $details["level"];
     498        //print_r($details);
     499        //print "$spend = level: $level<br>";
    474500
    475501        if ($level != 0) {
    476             $data = explode(":",$spend);
    477             $itemtable = $data[0];
    478             $itemid = $data[1];
    479             $chartable = $data[2];
    480             $chartableid = $data[3];
    481             $xpcost = $data[4];
    482             $specat = isset($itemInfo[$itemtable][$itemid]->SPECIALISATION_AT) ? $itemInfo[$itemtable][$itemid]->SPECIALISATION_AT : '';
    483             $comment = isset($charTableInfo[$chartable][$chartableid]->COMMENT) ? $charTableInfo[$chartable][$chartableid]->COMMENT : '';
    484             $spendcomment = isset($charTableInfo[$chartable][$chartableid]->LEVEL) ? $charTableInfo[$chartable][$chartableid]->LEVEL : '0';
    485             $spendcomment = $itemInfo[$itemtable][$itemid]->NAME . " $spendcomment > $level";
    486             $train = isset($trains[$index])? $trains[$index] : '';
    487            
    488             $rowoutput .= "<tr><td class='vtmcol_key'>{$itemInfo[$itemtable][$itemid]->NAME}</td>";
    489            
     502            $data        = explode(":",$spend);
     503            $index       = $data[0];
     504            $itemtable   = $data[1];
     505            $itemid      = $data[2];
     506            $chartable   = $data[3];
     507            $chartableid = $data[4];
     508            $xpcost      = $data[5];
     509           
     510            $hasspec      = isset($itemInfo[$itemtable][$itemid]->HAS_SPECIALISATION) ? $itemInfo[$itemtable][$itemid]->HAS_SPECIALISATION : '';
     511            $specat       = isset($itemInfo[$itemtable][$itemid]->SPECIALISATION_AT) ? $itemInfo[$itemtable][$itemid]->SPECIALISATION_AT : '';
     512            $comment      = isset($charTableInfo[$chartable][$chartableid]->COMMENT) ? $charTableInfo[$chartable][$chartableid]->COMMENT : '';
     513            //$spendcomment = isset($charTableInfo[$chartable][$chartableid]->LEVEL)  ? $charTableInfo[$chartable][$chartableid]->LEVEL : '0';
     514            if ($itemtable == "RITUAL")
     515                $spendcomment = "Ritual: ";
     516            elseif ($itemtable == "MERIT")
     517                if ($level > 0)
     518                    $spendcomment = "Buy Merit: ";
     519                else
     520                    $spendcomment = "Remove Flaw: ";
     521            else
     522                $spendcomment = "";
     523            $spendcomment .= $itemInfo[$itemtable][$itemid]->NAME;
     524            if (!empty($comment)) $spendcomment .= " ($comment)";
     525            $spendcomment .= " ";
     526            if ($itemtable == "RITUAL")
     527                $spendcomment .= " (Level $level)";
     528            elseif ($itemtable == "MERIT")
     529                $spendcomment .= " (Level $level)";
     530            else {
     531                $spendcomment .= isset($charTableInfo[$chartable][$chartableid]->LEVEL) ? $charTableInfo[$chartable][$chartableid]->LEVEL : '0';
     532                $spendcomment .= " > $level";
     533            }
     534            $train = isset($details['training'])? $details['training'] : '';
     535           
     536            // print $itemInfo[$itemtable][$itemid]->NAME . ", $chartable, $chartableid: ";
     537            // print_r($charTableInfo[$chartable][$chartableid]);
     538            // print "<br>\n";
     539           
     540            $rowoutput .= "<tr><td class='vtmcol_key'>".vtm_formatOutput($itemInfo[$itemtable][$itemid]->NAME);
     541            $rowoutput .= "<input type='hidden' name='{$spend}[level]' value='{$level}'>";
     542            $rowoutput .= "<input type='hidden' name='{$spend}[name]' value='{$itemInfo[$itemtable][$itemid]->NAME}'>";
     543            $rowoutput .= "</td>";
     544                       
    490545            // specialisation
    491             if ($specat == 'Y') {
    492                 $rowoutput .= "<td>??</td>";
    493                 // if (empty($specs[$index]))
    494                     // $rowoutput .= "<td><input type='text' name='{$type}_spec[" . $index . "]' value='' size=15 maxlength=60></td>";
    495                 // else
    496                     // $rowoutput .= "<td>{$spec}<input type='hidden' name='{$type}_spec[" . $index . "]' value='{$specs[$index]}'></td>";
    497             } elseif ($specat > 0 && $specat <= $level) {
    498                 if (empty($comment))
    499                     $rowoutput .= "<td><input type='text' name='{$spend}:spec:" . $index . "' value='' size=15 maxlength=60></td>";
    500                 else
    501                     $rowoutput .= "<td>{$comment}<input type='hidden' name='{$type}_spec:" . $index . "' value='{$comment}'></td>";
    502             } else {
    503                 $rowoutput .= "<td>&nbsp;</td>";
     546            if (empty($comment)) {
     547                if ($hasspec == 'Y' || ($specat > 0 && $specat <= $level)) {
     548                    $spec = empty($details['spec']) ? "" : $details['spec'];
     549                    $rowoutput .= "<td><input type='text' name='{$spend}[spec]' value='{$spec}' size=15 maxlength=60></td>";
     550                }
     551                else {
     552                    $rowoutput .= "<td>&nbsp;</td>";
     553                }
     554            }
     555            else {
     556                $rowoutput .= "<td>".vtm_formatOutput($comment)."<input type='hidden' name='{$spend}[spec]' value='{$comment}'></td>";
    504557            }
    505558           
    506559            // Spend information
    507             $rowoutput .= "<td>$spendcomment</td>";
     560            $rowoutput .= "<td>".vtm_formatOutput($spendcomment)."<input type='hidden' name='{$spend}[detail]' value='{$spendcomment}'></td>";
    508561           
    509562            // cost
    510             $rowoutput .= "<td>$xpcost</td>";
     563            $rowoutput .= "<td>".vtm_formatOutput($xpcost)."</td>";
    511564           
    512565            // Training
    513             $rowoutput .= "<td><input type='text'  name='{$spend}:training:$index' value='$train' size=30 maxlength=160 /></td>";
     566            $rowoutput .= "<td><input type='text'  name='{$spend}[training]' value='$train' size=30 maxlength=160 /></td>";
    514567            $rowoutput .= "</tr>";
    515568           
    516             $index++;
    517569        }
    518570    }
     
    772824                skilltype.name              as grp,
    773825                0                           as curr_level,
    774                 ''                          as comment,
     826                pending.SPECIALISATION      as comment,
    775827                0                           as cha_item_id,
    776828                steps.XP_COST               as xp_cost,
     
    902954   
    903955   
    904     $sql = $wpdb->prepare($sql, $characterID, $characterID, $characterID);
     956    $sql = $wpdb->prepare($sql, $characterID, $characterID, $characterID, $characterID, $characterID);
    905957    //echo "<p>SQL: $sql</p>";
    906958    $character_skills_xp = vtm_reformat_skills_xp($wpdb->get_results($sql));
     
    10461098
    10471099}
    1048 
     1100function vtm_get_sql_combo($characterID) {
     1101    global $wpdb;
     1102   
     1103    $sql = "SELECT
     1104                combo.id                                as item_id,
     1105                combo.NAME                              as item_name,
     1106                0                                       as spec_at,
     1107                ''                                      as grp,
     1108                IF(ISNULL(charcombo.ID),0,1)            as curr_level,
     1109                ''                                      as comment,
     1110                charcombo.ID                            as cha_item_id,
     1111                combo.COST                              as xp_cost,
     1112                1                                       as next_level,
     1113                NOT(ISNULL(pending.CHARTABLE_LEVEL))    as pending_level,
     1114                NOT(ISNULL(pending.CHARTABLE_LEVEL))    as has_pending,
     1115                pending.ID                              as pending_id,
     1116                combo.VISIBLE                           as visible,
     1117                IF(SUM(IF(prereq.DISCIPLINE_LEVEL <= chardisc.LEVEL,1,0)) = COUNT(prereq.DISCIPLINE_LEVEL),'Y','N') as meets_prereq
     1118            FROM
     1119                " . VTM_TABLE_PREFIX . "DISCIPLINE disciplines,
     1120                " . VTM_TABLE_PREFIX . "COMBO_DISCIPLINE combo
     1121                LEFT JOIN
     1122                    (SELECT ID, COMBO_DISCIPLINE_ID
     1123                    FROM " . VTM_TABLE_PREFIX . "CHARACTER_COMBO_DISCIPLINE
     1124                    WHERE CHARACTER_ID = %s
     1125                    ) as charcombo
     1126                ON
     1127                    charcombo.COMBO_DISCIPLINE_ID = combo.ID
     1128                LEFT JOIN
     1129                    (SELECT ID, CHARTABLE_LEVEL, CHARTABLE_ID, ITEMTABLE_ID
     1130                    FROM
     1131                        " . VTM_TABLE_PREFIX . "PENDING_XP_SPEND
     1132                    WHERE
     1133                        CHARACTER_ID = %s
     1134                        AND CHARTABLE = 'CHARACTER_COMBO_DISCIPLINE'
     1135                    ) as pending
     1136                ON
     1137                    pending.ITEMTABLE_ID = combo.ID
     1138                    ,
     1139                " . VTM_TABLE_PREFIX . "COMBO_DISCIPLINE_PREREQUISITE prereq
     1140                LEFT JOIN
     1141                    (SELECT DISCIPLINE_ID as ID, LEVEL
     1142                    FROM " . VTM_TABLE_PREFIX . "CHARACTER_DISCIPLINE
     1143                    WHERE CHARACTER_ID = %s
     1144                    ) as chardisc
     1145                ON
     1146                    prereq.DISCIPLINE_ID = chardisc.ID
     1147            WHERE   
     1148                prereq.COMBO_DISCIPLINE_ID = combo.ID
     1149                AND prereq.DISCIPLINE_ID = disciplines.ID
     1150            GROUP BY combo.NAME";
     1151    $sql = $wpdb->prepare($sql, $characterID,$characterID,$characterID);
     1152   
     1153    return $sql;
     1154}
     1155   
    10491156
    10501157function vtm_get_sql_disc($characterID) {
     
    12151322
    12161323}
     1324function vtm_get_sql_merit($characterID) {
     1325    global $wpdb;
     1326
     1327    $sql = "SELECT
     1328                merit.ID                        as item_id,
     1329                merit.name                      as item_name,
     1330                IF(cha_merit.level < 0,'Remove Flaws','Buy Merits') as grp,
     1331                cha_merit.level                 as curr_level,
     1332                cha_merit.comment               as comment,
     1333                cha_merit.id                    as cha_item_id,
     1334                merit.XP_COST                   as xp_cost,
     1335                merit.value                     as next_level,
     1336                pendingspend.CHARTABLE_LEVEL    as pending_level,
     1337                NOT(ISNULL(pendingspend.ID))    as has_pending,
     1338                pendingspend.ID                 as pending_id,
     1339                merit.has_specialisation        as has_specialisation,
     1340                merit.VISIBLE                   as visible,
     1341                merit.MULTIPLE                  as multiple
     1342            FROM
     1343                " . VTM_TABLE_PREFIX . "MERIT merit,
     1344                " . VTM_TABLE_PREFIX . "CHARACTER_MERIT cha_merit
     1345                LEFT JOIN
     1346                    (SELECT ID, CHARTABLE_LEVEL, CHARTABLE_ID, ITEMTABLE_ID, SPECIALISATION
     1347                    FROM
     1348                        " . VTM_TABLE_PREFIX . "PENDING_XP_SPEND pending
     1349                    WHERE
     1350                        pending.CHARACTER_ID = %s
     1351                        AND pending.CHARTABLE = 'CHARACTER_MERIT'
     1352                    ) as pendingspend
     1353                ON
     1354                    pendingspend.CHARTABLE_ID = cha_merit.ID
     1355            WHERE   
     1356                cha_merit.MERIT_ID = merit.ID
     1357                AND cha_merit.CHARACTER_ID = %s
     1358            UNION
     1359            SELECT
     1360                merit.ID                        as item_id,
     1361                merit.name                      as item_name,
     1362                IF(merit.value < 0,'Remove Flaws','Buy Merits') as grp,
     1363                0                               as curr_level,
     1364                pendingspend.SPECIALISATION     as comment,
     1365                0                               as cha_item_id,
     1366                merit.XP_COST                   as xp_cost,
     1367                merit.value                     as next_level,
     1368                pendingspend.CHARTABLE_LEVEL    as pending_level,
     1369                1                               as has_pending,
     1370                pendingspend.ID                 as pending_id,
     1371                merit.has_specialisation        as has_specialisation,
     1372                merit.VISIBLE                   as visible,
     1373                merit.MULTIPLE                  as multiple
     1374            FROM
     1375                " . VTM_TABLE_PREFIX . "MERIT merit,
     1376                " . VTM_TABLE_PREFIX . "PENDING_XP_SPEND pendingspend
     1377            WHERE
     1378                merit.ID = pendingspend.ITEMTABLE_ID
     1379                AND pendingspend.CHARACTER_ID = %s
     1380                AND pendingspend.CHARTABLE = 'CHARACTER_MERIT'
     1381                AND merit.value >= 0
     1382            UNION
     1383            SELECT
     1384                merit.ID                        as item_id,
     1385                merit.name                      as item_name,
     1386                IF(merit.value < 0,'Remove Flaws','Buy Merits') as grp,
     1387                0                               as curr_level,
     1388                ''                              as comment,
     1389                0                               as cha_item_id,
     1390                merit.XP_COST                   as xp_cost,
     1391                merit.value                     as next_level,
     1392                0                               as pending_level,
     1393                0                               as has_pending,
     1394                0                               as pending_id,
     1395                merit.has_specialisation        as has_specialisation,
     1396                merit.VISIBLE                   as visible,
     1397                merit.MULTIPLE                  as multiple
     1398            FROM
     1399                " . VTM_TABLE_PREFIX . "MERIT merit
     1400                LEFT JOIN
     1401                    (SELECT *
     1402                    FROM " . VTM_TABLE_PREFIX . "CHARACTER_MERIT) as cm
     1403                ON
     1404                    merit.ID = cm.MERIT_ID
     1405            WHERE
     1406                (merit.MULTIPLE = 'Y'
     1407                OR (merit.MULTIPLE = 'N' AND ISNULL(cm.ID)))
     1408                AND merit.XP_COST > 0
     1409                AND merit.VISIBLE = 'Y'
     1410            ORDER BY grp DESC, curr_level DESC, item_name";
     1411           
     1412    $sql = $wpdb->prepare($sql, $characterID,$characterID,$characterID);
     1413    //print "SQL: $sql";
     1414    return $sql;
     1415}
     1416function vtm_get_sql_ritual($characterID) {
     1417    global $wpdb;
     1418   
     1419    $sql = "SELECT
     1420                ritual.ID                       as item_id,
     1421                ritual.name                     as item_name,
     1422                0                               as spec_at,
     1423                disc.name                       as grp,     
     1424                NOT(ISNULL(cha_ritual.level))   as curr_level,
     1425                cha_ritual.ID                   as cha_item_id,
     1426                ritual.COST                     as xp_cost,
     1427                1                               as next_level,
     1428                pendingspend.CHARTABLE_LEVEL    as pending_level,
     1429                NOT(ISNULL(CHARTABLE_LEVEL))    as has_pending,
     1430                pendingspend.ID                 as pending_id,
     1431                char_disc.level                 as disclevel,
     1432                ritual.level                    as rituallevel
     1433            FROM
     1434                " . VTM_TABLE_PREFIX . "DISCIPLINE disc,
     1435                " . VTM_TABLE_PREFIX . "RITUAL ritual
     1436                LEFT JOIN
     1437                    (SELECT ID, LEVEL, COMMENT, CHARACTER_ID, RITUAL_ID
     1438                    FROM
     1439                        " . VTM_TABLE_PREFIX . "CHARACTER_RITUAL
     1440                    WHERE
     1441                        CHARACTER_ID = %s
     1442                    ) cha_ritual
     1443                ON
     1444                    cha_ritual.RITUAL_ID = ritual.ID
     1445                LEFT JOIN
     1446                    (SELECT ID, CHARTABLE_LEVEL, CHARTABLE_ID, ITEMTABLE_ID
     1447                    FROM
     1448                        " . VTM_TABLE_PREFIX . "PENDING_XP_SPEND pending
     1449                    WHERE
     1450                        pending.CHARACTER_ID = %s
     1451                        AND pending.CHARTABLE = 'CHARACTER_RITUAL'
     1452                    ) as pendingspend
     1453                ON
     1454                    pendingspend.ITEMTABLE_ID = ritual.id
     1455                LEFT JOIN
     1456                    (SELECT *
     1457                    FROM
     1458                        " . VTM_TABLE_PREFIX . "CHARACTER_DISCIPLINE
     1459                    WHERE
     1460                        CHARACTER_ID = %s
     1461                    ) as char_disc
     1462                ON
     1463                    char_disc.DISCIPLINE_ID = ritual.DISCIPLINE_ID
     1464            WHERE
     1465                disc.ID = ritual.DISCIPLINE_ID
     1466                AND char_disc.level >= ritual.level
     1467                AND ritual.VISIBLE = 'Y'
     1468                AND (NOT(ISNULL(cha_ritual.level)) OR ritual.COST > 0)
     1469           ORDER BY grp, ritual.level, ritual.name";
     1470    $sql = $wpdb->prepare($sql, $characterID,$characterID,$characterID);
     1471   
     1472    return $sql;
     1473}
     1474
    12171475function vtm_render_rituals($characterID, $maxRating, $pendingSpends, $xp_avail) {
    12181476    global $wpdb;
     
    12691527                AND (NOT(ISNULL(cha_ritual.level)) OR ritual.COST > 0)
    12701528           ORDER BY grp, ritual.level, ritual.name";
    1271     $sql = $wpdb->prepare($sql, $characterID,$characterID,$characterID);
     1529    $sql = $wpdb->prepare($sql, $characterID,$characterID,$characterID,$characterID);
    12721530    //echo "<p>SQL: $sql</p>";
    12731531    $character_data = $wpdb->get_results($sql);
     
    13431601                AND prereq.DISCIPLINE_ID = disciplines.ID
    13441602            GROUP BY combo.NAME";
    1345     $sql = $wpdb->prepare($sql, $characterID,$characterID,$characterID);
     1603    $sql = $wpdb->prepare($sql, $characterID,$characterID,$characterID,$characterID);
    13461604    //echo "<p>SQL: $sql</p>";
    13471605    $character_data = $wpdb->get_results($sql);
     
    14631721    $levelsdata    = isset($_REQUEST[$type . '_level']) ? $_REQUEST[$type . '_level'] : array();
    14641722
    1465     if ($type == 'path') {
     1723    if ($type == 'path' || $type == 'ritual' || $type == 'merit') {
    14661724        $columns = min(2, $vtmglobal['config']->WEB_COLUMNS);
    14671725    } else {
     
    14751733   
    14761734    $allxpdata = $wpdb->get_results(call_user_func($sqlfunction, $characterID));
     1735    //if ($type == 'merit') print_r($allxpdata);
    14771736   
    14781737    $max2display = vtm_get_max_dots($allxpdata, $maxRating);
     
    14881747            //$id = $xpdata->id;
    14891748           
     1749            if ($type == "combo") {
     1750                // don't display combo-disciplines if you don't have them and you
     1751                // don't meet the pre-requisites
     1752                if ($xpdata->meets_prereq == 'N' && $xpdata->curr_level == 0)
     1753                    continue;
     1754                // don't display if you don't have them and it isn't set to be visible
     1755                if ($xpdata->visible == 'N' && $xpdata->curr_level == 0)
     1756                    continue;
     1757                // don't display if they don't have an xp cost
     1758                if ($xpdata->xp_cost == 0)
     1759                    continue;
     1760               
     1761            }
     1762           
    14901763            $tmp_max2display = $max2display;
    1491             $checkboxname = "UNDEFINED";
     1764            $checkboxname = "$id:";
    14921765            switch($type) {
    14931766                case 'stat':
    1494                     $checkboxname = "STAT:{$xpdata->item_id}:CHARACTER_STAT:{$xpdata->cha_item_id}";
     1767                    $checkboxname .= "STAT:{$xpdata->item_id}:CHARACTER_STAT:{$xpdata->cha_item_id}";
    14951768                    switch ($xpdata->item_name) {
    14961769                        case 'Willpower':   
     
    15181791                            $maxRating = 5;
    15191792                            break;
     1793                        default:
     1794                            $tmp_max2display = $maxRating > 5 ? 10 : 5;
    15201795                    }
    15211796                    break;
    15221797                case 'disc':
    1523                     $checkboxname = "DISCIPLINE:{$xpdata->item_id}:CHARACTER_DISCIPLINE:{$xpdata->cha_item_id}";
     1798                    $checkboxname .= "DISCIPLINE:{$xpdata->item_id}:CHARACTER_DISCIPLINE:{$xpdata->cha_item_id}";
     1799                    break;
     1800                case 'combo':
     1801                    $checkboxname .= "COMBO_DISCIPLINE:{$xpdata->item_id}:CHARACTER_COMBO_DISCIPLINE:{$xpdata->cha_item_id}";
     1802                    $tmp_max2display = 1;
    15241803                    break;
    15251804                case 'path':
    1526                     $checkboxname = "PATH:{$xpdata->item_id}:CHARACTER_PATH:{$xpdata->cha_item_id}";
     1805                    $checkboxname .= "PATH:{$xpdata->item_id}:CHARACTER_PATH:{$xpdata->cha_item_id}";
    15271806                    $tmp_max2display = 5;
    15281807                    $maxRating = min(5,$xpdata->disclevel);
    15291808                    break;
    15301809                case 'skill':
    1531                     $checkboxname = "SKILL:{$xpdata->item_id}:CHARACTER_SKILL:{$xpdata->cha_item_id}";
     1810                    $checkboxname .= "SKILL:{$xpdata->item_id}:CHARACTER_SKILL:{$xpdata->cha_item_id}";
     1811                    break;
     1812                case 'ritual':
     1813                    $checkboxname .= "RITUAL:{$xpdata->item_id}:CHARACTER_RITUAL:{$xpdata->cha_item_id}";
     1814                    $tmp_max2display = 1;
     1815                    break;
     1816                case 'merit':
     1817                    $checkboxname .= "MERIT:{$xpdata->item_id}:CHARACTER_MERIT:{$xpdata->cha_item_id}";
     1818                    $tmp_max2display = 1;
    15321819                    break;
    15331820            }
     
    15611848                $name .= " (P)";
    15621849            }
     1850            if ($type == 'ritual') {
     1851                $name = "(Level $xpdata->rituallevel) $name";
     1852            }
     1853            if ($type == 'merit') {
     1854                $name = "(Level $xpdata->next_level) $name";
     1855            }
    15631856            //if ($type == 'path') $name .= " (" . $xpdata->disclevel . "/$maxRating)";
    15641857            $name      = vtm_formatOutput($name);
     
    15901883                elseif ($xpdata->pending_level)
    15911884                    if ($xpdata->pending_level >= $i)
     1885                        $rowoutput .= "<img alt='X' src='$pendingdoturl'>";
     1886                    elseif ($type == 'merit' && $xpdata->next_level < 0 && $xpdata->xp_cost)
    15921887                        $rowoutput .= "<img alt='X' src='$pendingdoturl'>";
    15931888                    else
     
    16031898                    $rowoutput .= "<img alt='O' src='$emptydoturl'>";
    16041899                }
    1605                 else
     1900                elseif ($type == 'combo' || $type == 'ritual') {
     1901                    $xpcost = $xpdata->xp_cost;
     1902               
     1903                    if ($xp_avail >= $xpcost) {
     1904                   
     1905                        $rowoutput .= "<input type='CHECKBOX' name='$checkboxname:{$xpcost}[level]'   value='{$xpdata->next_level}' id='vtmcb_{$type}_$id' ";
     1906                        if (isset($levelsdata[$id]))
     1907                            $rowoutput .= "checked";
     1908                        $rowoutput .= "><label for='vtmcb_{$type}_$id' title='[ ]'>&nbsp;</label>";
     1909                    } else
     1910                        $rowoutput .= "<img alt='O' src='$emptydoturl'>";
     1911                                   
     1912                }
     1913                elseif ($type == 'merit') {
     1914                    $xpcost = $xpdata->xp_cost;
     1915                    if ($xpdata->next_level < 0) { // Flaw
     1916                        if($xpcost) {
     1917                            if ($xp_avail >= $xpcost) {
     1918                                $rowoutput .= "<input type='CHECKBOX' name='$checkboxname:{$xpcost}[level]'   value='{$xpdata->next_level}' id='vtmcb_{$type}_$id' ";
     1919                                if (isset($levelsdata[$id]))
     1920                                    $rowoutput .= "checked";
     1921                                $rowoutput .= "><label for='vtmcb_{$type}_$id' title='[ ]'>&nbsp;</label>";
     1922                            } else
     1923                                $rowoutput .= "<img alt='O' src='$emptydoturl'>";
     1924
     1925                        } else
     1926                                $rowoutput .= "<img alt='O' src='$fulldoturl'>";
     1927                    } else {
     1928                        if ($xp_avail >= $xpcost) {
     1929                            $rowoutput .= "<input type='CHECKBOX' name='$checkboxname:{$xpcost}[level]'   value='{$xpdata->next_level}' id='vtmcb_{$type}_$id' ";
     1930                            if (isset($levelsdata[$id]))
     1931                                $rowoutput .= "checked";
     1932                            $rowoutput .= "><label for='vtmcb_{$type}_$id' title='[ ]'>&nbsp;</label>";
     1933                        } else
     1934                            $rowoutput .= "<img alt='O' src='$emptydoturl'>";
     1935                    }
     1936                }
     1937                else {
    16061938                    if ($xpdata->next_level == $i) {
    16071939                       
     
    16181950                            //$rowoutput .= "<input type='hidden'   name='{$type}_cost[" . $id . "]'    value='" . $xpcost . "' >";
    16191951                            //$rowoutput .= "<input type='hidden'   name='{$type}_comment[" . $id . "]' value='$comment' >";
    1620                             $rowoutput .= "<input type='CHECKBOX' name='$checkboxname:$xpcost'   value='$i' id='vtmcb_{$type}_$id' ";
     1952                            $rowoutput .= "<input type='CHECKBOX' name='$checkboxname:{$xpcost}[level]'   value='$i' id='vtmcb_{$type}_$id' ";
    16211953                            if (isset($levelsdata[$id]) && $i == $levelsdata[$id])
    16221954                                $rowoutput .= "checked";
     
    16281960                    else
    16291961                        $rowoutput .= "<img alt='O' src='$emptydoturl'>";
    1630                        
     1962                }   
    16311963            }
    16321964           
     
    16351967            $xpcost = ($xpdata->next_level <= $maxRating) ? $xpdata->xp_cost . "xp" : "";
    16361968            if ($xpdata->has_pending)
    1637                 $rowoutput .= "<td class='vtmxp_cost'><input class='vtmxp_clear' type='submit' name='{$type}_cancel[{$xpdata->pending_id}]' value='Del'></td>";
     1969                $rowoutput .= "<td class='vtmxp_cost'><input class='vtmxp_clear' type='submit' name='cancel[{$xpdata->pending_id}]' value='Del'></td>";
    16381970            elseif ($xpdata->xp_cost == 0) {
    16391971                $rowoutput .= "<td class='vtmxp_cost'>&nbsp;</td>";
     
    22542586}
    22552587
    2256 function vtm_save_to_pending($type, $table, $itemtable, $itemidname, $playerID, $characterID) {
     2588function vtm_save_to_pending($data, $details, $playerID, $characterID) {
    22572589    global $wpdb;
    22582590
    22592591    $newid = "";
    2260 
    2261     $ids             = isset($_REQUEST[$type . '_id'])       ? $_REQUEST[$type . '_id'] : array();
    2262     $levels          = isset($_REQUEST[$type . '_level'])    ? $_REQUEST[$type . '_level'] : array();
    2263     $specialisations = isset($_REQUEST[$type . '_spec'])     ? $_REQUEST[$type . '_spec'] : array();
    2264     $training        = isset($_REQUEST[$type . '_training']) ? $_REQUEST[$type . '_training'] : array();
    2265     $itemid          = isset($_REQUEST[$type . '_itemid'])   ? $_REQUEST[$type . '_itemid'] : array();
    2266     $costlvls        = isset($_REQUEST[$type . '_cost'])     ? $_REQUEST[$type . '_cost'] : array();
    2267     $comments        = isset($_REQUEST[$type . '_comment'])  ? $_REQUEST[$type . '_comment'] : array();
     2592   
     2593    $index       = $data[0];
     2594    $itemtable   = $data[1];
     2595    $itemid      = $data[2];
     2596    $chartable   = $data[3];
     2597    $chartableid = $data[4];
     2598    $xpcost      = $data[5];
     2599    $spec        = isset($details['spec']) ? $details['spec'] : '';
     2600    $level       = isset($details['level']) ? $details['level'] : 0;
     2601    $training    = isset($details['training']) ? $details['training'] : '';
     2602    $itemidname  = isset($details['name']) ? $details['name'] : '';
     2603    $comment     = isset($details['detail']) ? $details['detail'] : '';
     2604
     2605    // print "<p>$index: <br>";
     2606    // print_r($data);
     2607    // print "<br>";
     2608    // print_r($details);
     2609    // print "<p>";
     2610           
     2611    //if ($level) {
     2612        $dataarray = array (
     2613            'PLAYER_ID'       => $playerID,
     2614            'CHARACTER_ID'    => $characterID,
     2615            'CHARTABLE'       => $chartable,
     2616            'CHARTABLE_ID'    => $chartableid,
     2617            'CHARTABLE_LEVEL' => $level,
     2618            'AWARDED'         => Date('Y-m-d'),
     2619            'AMOUNT'          => $xpcost * -1,
     2620            'COMMENT'         => $comment,
     2621            'SPECIALISATION'  => $spec,
     2622            'TRAINING_NOTE'   => $training,
     2623            'ITEMTABLE'       => $itemtable,
     2624            'ITEMNAME'        => $itemidname,
     2625            'ITEMTABLE_ID'    => $itemid
     2626        );
     2627       
     2628        //print_r($dataarray);
     2629       
     2630        $wpdb->insert(VTM_TABLE_PREFIX . "PENDING_XP_SPEND",
     2631                    $dataarray,
     2632                    array (
     2633                        '%d',
     2634                        '%d',
     2635                        '%s',
     2636                        '%d',
     2637                        '%d',
     2638                        '%s',
     2639                        '%d',
     2640                        '%s',
     2641                        '%s',
     2642                        '%s',
     2643                        '%s',
     2644                        '%s',
     2645                        '%d'
     2646                    )
     2647                );
     2648       
     2649        $newid = $wpdb->insert_id;
     2650        if ($newid  == 0) {
     2651            echo "<p style='color:red'><b>Error:</b> XP Spend failed for data (";
     2652            print_r($dataarray);
     2653            print $wpdb->last_error;
     2654            echo ")</p>";
     2655        }
     2656    //}
     2657   
     2658   
     2659    return $newid;
     2660                           
     2661}
     2662
     2663function vtm_save_merit_to_pending ($type, $table, $itemtable, $itemidname, $playerID, $characterID) {
     2664    global $wpdb;
     2665   
     2666    $wpdb->show_errors();
     2667
     2668    $newid = "";
     2669
     2670    $ids             = $_REQUEST[$type . '_id'];
     2671    $levels          = $_REQUEST[$type . '_level'];
     2672    $specialisations = $_REQUEST[$type . '_spec'];
     2673    $training        = $_REQUEST[$type . '_training'];
     2674    $itemid          = $_REQUEST[$type . '_itemid'];
     2675    $costlvls        = $_REQUEST[$type . '_cost'];
     2676    $comments        = $_REQUEST[$type . '_comment'];
    22682677   
    22692678    //print_r($_REQUEST);
     
    22832692                'AWARDED'         => Date('Y-m-d'),
    22842693                'AMOUNT'          => $costlvls[$index] * -1,
    2285                 'COMMENT'         => isset($comments[$index]) ? $comments[$index] : '',
    2286                 'SPECIALISATION'  => isset($specialisations[$index]) ? $specialisations[$index] : '',
     2694                'COMMENT'         => $comments[$index],
     2695                'SPECIALISATION'  => $specialisations[$index],
    22872696                'TRAINING_NOTE'   => $training[$index],
    22882697                'ITEMTABLE'       => $itemtable,
     
    23092718                        )
    23102719                    );
    2311            
     2720            $wpdb->print_error();
    23122721            $newid = $wpdb->insert_id;
    23132722            if ($newid  == 0) {
    23142723                echo "<p style='color:red'><b>Error:</b> XP Spend failed for data (";
    23152724                print_r($dataarray);
    2316                 $wpdb->print_error();
    2317                 echo ")</p>";
    2318             }
    2319         }
    2320    
    2321     }   
    2322    
    2323     return $newid;
    2324                            
    2325 }
    2326 
    2327 function vtm_save_merit_to_pending ($type, $table, $itemtable, $itemidname, $playerID, $characterID) {
    2328     global $wpdb;
    2329 
    2330     $newid = "";
    2331 
    2332     $ids             = $_REQUEST[$type . '_id'];
    2333     $levels          = $_REQUEST[$type . '_level'];
    2334     $specialisations = $_REQUEST[$type . '_spec'];
    2335     $training        = $_REQUEST[$type . '_training'];
    2336     $itemid          = $_REQUEST[$type . '_itemid'];
    2337     $costlvls        = $_REQUEST[$type . '_cost'];
    2338     $comments        = $_REQUEST[$type . '_comment'];
    2339    
    2340     //print_r($_REQUEST);
    2341     //echo "<pre>";
    2342     //print_r($itemid);
    2343     //echo "</pre>";
    2344    
    2345     foreach ($levels as $index => $level) {
    2346        
    2347         if ($level) {
    2348             $dataarray = array (
    2349                 'PLAYER_ID'       => $playerID,
    2350                 'CHARACTER_ID'    => $characterID,
    2351                 'CHARTABLE'       => $table,
    2352                 'CHARTABLE_ID'    => $ids[$index],
    2353                 'CHARTABLE_LEVEL' => $level,
    2354                 'AWARDED'         => Date('Y-m-d'),
    2355                 'AMOUNT'          => $costlvls[$index] * -1,
    2356                 'COMMENT'         => $comments[$index],
    2357                 'SPECIALISATION'  => $specialisations[$index],
    2358                 'TRAINING_NOTE'   => $training[$index],
    2359                 'ITEMTABLE'       => $itemtable,
    2360                 'ITEMNAME'        => $itemidname,
    2361                 'ITEMTABLE_ID'    => $itemid[$index]
    2362             );
    2363            
    2364             $wpdb->insert(VTM_TABLE_PREFIX . "PENDING_XP_SPEND",
    2365                         $dataarray,
    2366                         array (
    2367                             '%d',
    2368                             '%d',
    2369                             '%s',
    2370                             '%d',
    2371                             '%d',
    2372                             '%s',
    2373                             '%d',
    2374                             '%s',
    2375                             '%s',
    2376                             '%s',
    2377                             '%s',
    2378                             '%s',
    2379                             '%d'
    2380                         )
    2381                     );
    2382            
    2383             $newid = $wpdb->insert_id;
    2384             if ($newid  == 0) {
    2385                 echo "<p style='color:red'><b>Error:</b> XP Spend failed for data (";
    2386                 print_r($dataarray);
    2387                 $wpdb->print_error();
    2388                 echo ")</p>";
     2725                $wpdb->print_error() .
     2726                $wpdb->last_error .
     2727                $wpdb->last_query;
    23892728            }
    23902729        }
     
    24612800        $data = explode(":",$spend);
    24622801        if (count($data) > 1) {
    2463             $xp_spent += $data[4];
     2802            $xp_spent += $data[5];
    24642803        }
    24652804    }
     
    24902829
    24912830function vtm_validate_details($characterID) {
     2831    global $wpdb;
     2832
     2833   
     2834    // Extract the spends and what tables we need to query from
     2835    // the $_REQUEST
     2836    $requestItemTables = array();
     2837    $requestChTables = array();
     2838    $requestspends = array();
     2839    foreach ($_REQUEST as $spend => $details) {
     2840        $data = explode(":",$spend);
     2841        if (count($data) > 1) {
     2842            $requestspends[$spend] = $details;
     2843            $requestItemTables[$data[1]] = 1;
     2844            if ($data[4] != 0) {
     2845                $requestChTables[$data[3]] = 1;
     2846            }
     2847        }
     2848    }   
     2849    //print "<br>";
     2850    //print_r($requestspends);
     2851    //print "<br>";
     2852   
     2853   
     2854    // Query the Item Table information
     2855    $itemInfo = array();
     2856    foreach ($requestItemTables as $itemtable => $discard) {
     2857        //Table has SPECIALISATION_AT column?
     2858        $columns = "";
     2859        $existing_columns = $wpdb->get_col("DESC " . VTM_TABLE_PREFIX . $itemtable, 0);
     2860
     2861        $match_columns = array_intersect(array("SPECIALISATION_AT"), $existing_columns);
     2862        $columns = empty($match_columns) ? "" : ",SPECIALISATION_AT";
     2863        $match_columns = array_intersect(array("HAS_SPECIALISATION"), $existing_columns);
     2864        $columns .= empty($match_columns) ? "" : ",HAS_SPECIALISATION";
     2865
     2866        $itemInfo[$itemtable] = $wpdb->get_results("SELECT ID,NAME $columns FROM " . VTM_TABLE_PREFIX . $itemtable, OBJECT_K);
     2867       
     2868    }
     2869
     2870    // Query the character table
     2871    $charTableInfo = array();
     2872    foreach ($requestChTables as $chartable => $discard) {
     2873        $sql = $wpdb->prepare("SELECT ID,COMMENT,LEVEL FROM " . VTM_TABLE_PREFIX . $chartable . " WHERE CHARACTER_ID = '%s'",$characterID);
     2874        //print "SQL: $sql<br>";
     2875        $charTableInfo[$chartable] = $wpdb->get_results($sql, OBJECT_K);
     2876    }
    24922877
    24932878    $outputError = "";
     2879    foreach ($requestspends as $key => $spend) {
     2880
     2881            $data        = explode(":",$key);
     2882            $index       = $data[0];
     2883            $itemtable   = $data[1];
     2884            $itemid      = $data[2];
     2885            $chartable   = $data[3];
     2886            $chartableid = $data[4];
     2887            $xp_cost     = $data[5];
     2888           
     2889            if (isset($spend['spec']) && empty($spend['spec'])) {
     2890                $outputError .= "<li>Missing specialisation for {$itemInfo[$itemtable][$itemid]->NAME}</li>";
     2891            }
     2892            if (isset($spend['training']) && empty(($spend['training']))) {
     2893                $outputError .= "<li>Missing training information for {$itemInfo[$itemtable][$itemid]->NAME}";
     2894                if (isset($spend['spec']) && !empty($spend['spec'])) {
     2895                    $outputError .= " ({$spend['spec']})";
     2896                }
     2897                $outputError .= "</li>";
     2898            }
     2899    }
     2900    if (!empty($outputError)) {
     2901        $outputError = "<ul>$outputError</ul>";
     2902    }
     2903   
    24942904    /*
    24952905    $defaultTrainingString = "";
Note: See TracChangeset for help on using the changeset viewer.