Changeset 2056056
- Timestamp:
- 03/23/2019 09:19:03 PM (7 years ago)
- File:
-
- 1 edited
-
vampire-character/trunk/inc/xpfunctions.php (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vampire-character/trunk/inc/xpfunctions.php
r1847089 r2056056 1 1 <?php 2 2 3 function vtm_xp_spend_content_filter($content) { 3 4 … … 11 12 12 13 13 /*14 14 function vtm_doPendingXPSpend($character) { 15 15 global $wpdb; 16 16 $characterID = vtm_establishCharacterID($character); 17 17 $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 /* 19 34 $submitted = array(); 20 35 if (isset($_REQUEST['stat_level'])) { … … 46 61 $newid = vtm_save_to_pending('combo', 'CHARACTER_COMBO_DISCIPLINE', 'COMBO_DISCIPLINE', 'COMBO_DISCIPLINE_ID', $playerID, $characterID); 47 62 } 48 49 if (count($submitted) > 0) { 63 */ 64 65 if ($count > 0) { 50 66 $email = get_option( 'vtm_replyto_address', get_option( 'vtm_chargen_email_from_address', get_bloginfo('admin_email') ) ); 51 67 $body = "<p>A user has submitted experience spends.</p><p>View the spends here: " . … … 54 70 } 55 71 } 56 72 /* 57 73 // master_xp_update VTM_FORM 58 74 function vtm_handleMasterXP() { … … 85 101 86 102 //echo "<!--"; 87 print_r($_POST);103 //print_r($_POST); 88 104 //echo "-->"; 89 105 … … 98 114 // Cancel Spends 99 115 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 108 121 /* if (isset($_REQUEST['stat_cancel'])) vtm_cancel_pending($_REQUEST['stat_cancel']); 109 122 if (isset($_REQUEST['skill_cancel'])) vtm_cancel_pending($_REQUEST['skill_cancel']); … … 156 169 157 170 $output = ""; 158 $character = vtm_establishCharacter($character);171 $character = vtm_establishCharacter($character); 159 172 $characterID = vtm_establishCharacterID($character); 160 173 161 174 $spent = 0; 162 foreach ($_REQUEST as $spend => $ level) {175 foreach ($_REQUEST as $spend => $details) { 163 176 $data = explode(":",$spend); 164 177 if (count($data) > 1) { 165 $spent += $data[ 4];178 $spent += $data[5]; 166 179 } 167 180 } … … 255 268 // get the current pending spends for this character 256 269 $pendingSpends = vtm_get_pending($characterID); 270 257 271 $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);259 272 $sectioncontent['skill'] = vtm_render_spend_table('skill', 'vtm_get_sql_skills', $characterID, $maxRating, $xp_avail); 260 273 $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); 262 275 $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); 265 278 266 279 … … 417 430 $sql = $wpdb->prepare($sql, $characterID); 418 431 $characterMaximums = $wpdb->get_results($sql); 432 419 433 foreach ($characterMaximums as $charMax) { 420 434 $maxRating = $charMax->max_rating; … … 436 450 $requestChTables = array(); 437 451 $requestspends = array(); 438 foreach ($_REQUEST as $spend => $ level) {452 foreach ($_REQUEST as $spend => $details) { 439 453 $data = explode(":",$spend); 440 454 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; 445 459 } 446 460 } 447 461 } 448 462 ksort($requestspends); 463 464 // print "<br>"; 465 // print_r($requestspends); 466 // print "<br>"; 449 467 450 468 // Query the Item Table information … … 454 472 $columns = ""; 455 473 $existing_columns = $wpdb->get_col("DESC " . VTM_TABLE_PREFIX . $itemtable, 0); 474 456 475 $match_columns = array_intersect(array("SPECIALISATION_AT"), $existing_columns); 457 476 $columns = empty($match_columns) ? "" : ",SPECIALISATION_AT"; 477 $match_columns = array_intersect(array("HAS_SPECIALISATION"), $existing_columns); 478 $columns .= empty($match_columns) ? "" : ",HAS_SPECIALISATION"; 479 458 480 $itemInfo[$itemtable] = $wpdb->get_results("SELECT ID,NAME $columns FROM " . VTM_TABLE_PREFIX . $itemtable, OBJECT_K); 459 } 460 //print_r($itemInfo); 481 482 483 } 461 484 // Query the character table 462 485 $charTableInfo = array(); 463 486 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>"; 469 494 470 495 // 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>"; 474 500 475 501 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 490 545 // 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> </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> </td>"; 553 } 554 } 555 else { 556 $rowoutput .= "<td>".vtm_formatOutput($comment)."<input type='hidden' name='{$spend}[spec]' value='{$comment}'></td>"; 504 557 } 505 558 506 559 // Spend information 507 $rowoutput .= "<td> $spendcomment</td>";560 $rowoutput .= "<td>".vtm_formatOutput($spendcomment)."<input type='hidden' name='{$spend}[detail]' value='{$spendcomment}'></td>"; 508 561 509 562 // cost 510 $rowoutput .= "<td> $xpcost</td>";563 $rowoutput .= "<td>".vtm_formatOutput($xpcost)."</td>"; 511 564 512 565 // 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>"; 514 567 $rowoutput .= "</tr>"; 515 568 516 $index++;517 569 } 518 570 } … … 772 824 skilltype.name as grp, 773 825 0 as curr_level, 774 ''as comment,826 pending.SPECIALISATION as comment, 775 827 0 as cha_item_id, 776 828 steps.XP_COST as xp_cost, … … 902 954 903 955 904 $sql = $wpdb->prepare($sql, $characterID, $characterID, $characterID );956 $sql = $wpdb->prepare($sql, $characterID, $characterID, $characterID, $characterID, $characterID); 905 957 //echo "<p>SQL: $sql</p>"; 906 958 $character_skills_xp = vtm_reformat_skills_xp($wpdb->get_results($sql)); … … 1046 1098 1047 1099 } 1048 1100 function 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 1049 1156 1050 1157 function vtm_get_sql_disc($characterID) { … … 1215 1322 1216 1323 } 1324 function 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 } 1416 function 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 1217 1475 function vtm_render_rituals($characterID, $maxRating, $pendingSpends, $xp_avail) { 1218 1476 global $wpdb; … … 1269 1527 AND (NOT(ISNULL(cha_ritual.level)) OR ritual.COST > 0) 1270 1528 ORDER BY grp, ritual.level, ritual.name"; 1271 $sql = $wpdb->prepare($sql, $characterID,$characterID,$characterID );1529 $sql = $wpdb->prepare($sql, $characterID,$characterID,$characterID,$characterID); 1272 1530 //echo "<p>SQL: $sql</p>"; 1273 1531 $character_data = $wpdb->get_results($sql); … … 1343 1601 AND prereq.DISCIPLINE_ID = disciplines.ID 1344 1602 GROUP BY combo.NAME"; 1345 $sql = $wpdb->prepare($sql, $characterID,$characterID,$characterID );1603 $sql = $wpdb->prepare($sql, $characterID,$characterID,$characterID,$characterID); 1346 1604 //echo "<p>SQL: $sql</p>"; 1347 1605 $character_data = $wpdb->get_results($sql); … … 1463 1721 $levelsdata = isset($_REQUEST[$type . '_level']) ? $_REQUEST[$type . '_level'] : array(); 1464 1722 1465 if ($type == 'path' ) {1723 if ($type == 'path' || $type == 'ritual' || $type == 'merit') { 1466 1724 $columns = min(2, $vtmglobal['config']->WEB_COLUMNS); 1467 1725 } else { … … 1475 1733 1476 1734 $allxpdata = $wpdb->get_results(call_user_func($sqlfunction, $characterID)); 1735 //if ($type == 'merit') print_r($allxpdata); 1477 1736 1478 1737 $max2display = vtm_get_max_dots($allxpdata, $maxRating); … … 1488 1747 //$id = $xpdata->id; 1489 1748 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 1490 1763 $tmp_max2display = $max2display; 1491 $checkboxname = " UNDEFINED";1764 $checkboxname = "$id:"; 1492 1765 switch($type) { 1493 1766 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}"; 1495 1768 switch ($xpdata->item_name) { 1496 1769 case 'Willpower': … … 1518 1791 $maxRating = 5; 1519 1792 break; 1793 default: 1794 $tmp_max2display = $maxRating > 5 ? 10 : 5; 1520 1795 } 1521 1796 break; 1522 1797 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; 1524 1803 break; 1525 1804 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}"; 1527 1806 $tmp_max2display = 5; 1528 1807 $maxRating = min(5,$xpdata->disclevel); 1529 1808 break; 1530 1809 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; 1532 1819 break; 1533 1820 } … … 1561 1848 $name .= " (P)"; 1562 1849 } 1850 if ($type == 'ritual') { 1851 $name = "(Level $xpdata->rituallevel) $name"; 1852 } 1853 if ($type == 'merit') { 1854 $name = "(Level $xpdata->next_level) $name"; 1855 } 1563 1856 //if ($type == 'path') $name .= " (" . $xpdata->disclevel . "/$maxRating)"; 1564 1857 $name = vtm_formatOutput($name); … … 1590 1883 elseif ($xpdata->pending_level) 1591 1884 if ($xpdata->pending_level >= $i) 1885 $rowoutput .= "<img alt='X' src='$pendingdoturl'>"; 1886 elseif ($type == 'merit' && $xpdata->next_level < 0 && $xpdata->xp_cost) 1592 1887 $rowoutput .= "<img alt='X' src='$pendingdoturl'>"; 1593 1888 else … … 1603 1898 $rowoutput .= "<img alt='O' src='$emptydoturl'>"; 1604 1899 } 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='[ ]'> </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='[ ]'> </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='[ ]'> </label>"; 1933 } else 1934 $rowoutput .= "<img alt='O' src='$emptydoturl'>"; 1935 } 1936 } 1937 else { 1606 1938 if ($xpdata->next_level == $i) { 1607 1939 … … 1618 1950 //$rowoutput .= "<input type='hidden' name='{$type}_cost[" . $id . "]' value='" . $xpcost . "' >"; 1619 1951 //$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' "; 1621 1953 if (isset($levelsdata[$id]) && $i == $levelsdata[$id]) 1622 1954 $rowoutput .= "checked"; … … 1628 1960 else 1629 1961 $rowoutput .= "<img alt='O' src='$emptydoturl'>"; 1630 1962 } 1631 1963 } 1632 1964 … … 1635 1967 $xpcost = ($xpdata->next_level <= $maxRating) ? $xpdata->xp_cost . "xp" : ""; 1636 1968 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>"; 1638 1970 elseif ($xpdata->xp_cost == 0) { 1639 1971 $rowoutput .= "<td class='vtmxp_cost'> </td>"; … … 2254 2586 } 2255 2587 2256 function vtm_save_to_pending($ type, $table, $itemtable, $itemidname, $playerID, $characterID) {2588 function vtm_save_to_pending($data, $details, $playerID, $characterID) { 2257 2589 global $wpdb; 2258 2590 2259 2591 $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 2663 function 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']; 2268 2677 2269 2678 //print_r($_REQUEST); … … 2283 2692 'AWARDED' => Date('Y-m-d'), 2284 2693 '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], 2287 2696 'TRAINING_NOTE' => $training[$index], 2288 2697 'ITEMTABLE' => $itemtable, … … 2309 2718 ) 2310 2719 ); 2311 2720 $wpdb->print_error(); 2312 2721 $newid = $wpdb->insert_id; 2313 2722 if ($newid == 0) { 2314 2723 echo "<p style='color:red'><b>Error:</b> XP Spend failed for data ("; 2315 2724 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; 2389 2728 } 2390 2729 } … … 2461 2800 $data = explode(":",$spend); 2462 2801 if (count($data) > 1) { 2463 $xp_spent += $data[ 4];2802 $xp_spent += $data[5]; 2464 2803 } 2465 2804 } … … 2490 2829 2491 2830 function 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 } 2492 2877 2493 2878 $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 2494 2904 /* 2495 2905 $defaultTrainingString = "";
Note: See TracChangeset
for help on using the changeset viewer.