PageRenderTime 44ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/bitsand/admin/admin_edit_ic.php

http://bitsand.googlecode.com/
PHP | 481 lines | 388 code | 37 blank | 56 comment | 82 complexity | 2a1bce4ed28a9d3d32cba8ab0b0990dd MD5 | raw file
  1. <?php
  2. /*
  3. Bitsand - a web-based booking system for LRP events
  4. Copyright (C) 2006 - 2011 The Bitsand Project (http://bitsand.googlecode.com/)
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. */
  17. include ('../inc/inc_head_db.php');
  18. include ('../inc/inc_admin.php');
  19. include ('../inc/inc_forms.php');
  20. //Get player ID of player to be edited
  21. $admin_player_id = (int) $_GET ['pid'];
  22. //Initialise error message
  23. $sWarn = '';
  24. $db_prefix = DB_PREFIX;
  25. if ($_POST ['btnSubmit'] != '' && CheckReferrer ('admin_edit_ic.php')) {
  26. $sDataWarn = IC_Check ();
  27. if ($sDataWarn != '') {
  28. //Append warning to the IC Notes field if not already added
  29. $sNotes = ba_db_real_escape_string ($link, $_POST ['txtNotes']);
  30. if (stripos ($sNotes, "Illegal set of skills entered") === False)
  31. $sNotes .= "\nIllegal set of skills entered";
  32. }
  33. else
  34. $sNotes = ba_db_real_escape_string ($link, $_POST ['txtNotes']);
  35. //Character details - check if character exists
  36. $sql = "SELECT * FROM {$db_prefix}characters WHERE chPlayerID = $admin_player_id";
  37. $result = ba_db_query ($link, $sql);
  38. //If character does not exist insert a row so that UPDATE query will work
  39. if (ba_db_num_rows ($result) == 0) {
  40. $sql = "INSERT INTO {$db_prefix}characters (chPlayerID) VALUES ($admin_player_id)";
  41. if (! ba_db_query ($link, $sql)) {
  42. $sWarn = "There was a problem updating the IC details";
  43. LogError ("Error inserting player ID into characters table prior to running UPDATE query (admin_edit_ic.php). " .
  44. "Player ID: $admin_player_id");
  45. }
  46. }
  47. elseif (ba_db_num_rows ($result) > 1)
  48. LogWarning ("Multiple rows in characters table with player ID (admin_edit_ic.php) $admin_player_id");
  49. if ($_POST['selGroup'] == 'Other (enter name below)')
  50. $sSelGroupName = '';
  51. else
  52. $sSelGroupName = $_POST['selGroup'];
  53. if ($_POST['selAncestor'] == 'Other (enter name below)')
  54. $sSelAncestorName = '';
  55. else
  56. $sSelAncestorName = $_POST['selAncestor'];
  57. //Build up UPDATE query
  58. $sql = "UPDATE {$db_prefix}characters SET chName = '" . ba_db_real_escape_string ($link, $_POST ['txtCharName']) . "', " .
  59. "chPreferredName = '" . ba_db_real_escape_string($link, $_POST ['txtPreferredName']) . "', " .
  60. "chRace = '" . ba_db_real_escape_string ($link, $_POST ['selRace']) . "', " .
  61. "chGender = '" . ba_db_real_escape_string ($link, $_POST ['selGender']) . "', " .
  62. "chGroupSel = '" . ba_db_real_escape_string ($link, $sSelGroupName) . "', " .
  63. "chGroupText = '" . ba_db_real_escape_string ($link, $_POST ['txtGroup']) . "', " .
  64. "chFaction = '" . ba_db_real_escape_string ($link, $_POST ['selFaction']) . "', " .
  65. "chAncestor = '" . ba_db_real_escape_string ($link, $_POST ['txtAncestor']) . "', " .
  66. "chAncestorSel = '" . ba_db_real_escape_string ($link, $sSelAncestorName) . "', " .
  67. "chLocation = '" . ba_db_real_escape_string ($link, $_POST ['selLocation']) . "', " .
  68. "chNotes = '" . $sNotes . "', " .
  69. "chOSP = '" . ba_db_real_escape_string ($link, $_POST ['txtOSP']) . "' " .
  70. "WHERE chPlayerID = $admin_player_id";
  71. //Run query
  72. if (! ba_db_query ($link, $sql)) {
  73. $sWarn = "There was a problem updating the IC details";
  74. LogError ("Error updating character details (admin_edit_ic.php). Player ID: $admin_player_id");
  75. }
  76. //Guilds list: Delete existing rows from guildmembers, then run INSERT queries
  77. $sql = "DELETE FROM {$db_prefix}guildmembers WHERE gmPlayerID = $admin_player_id";
  78. if (! ba_db_query ($link, $sql)) {
  79. $sWarn = "There was a problem updating the IC details";
  80. LogError ("Error deleting existing guilds from guildmembers table during update of IC information. Player ID: $admin_player_id");
  81. }
  82. else {
  83. //Run INSERT queries
  84. $iGuildCount = 1;
  85. $sGuild = "selGuild1";
  86. $aGuild = array();
  87. while ($_POST [$sGuild] != ' None') {
  88. if (!in_array($_POST [$sGuild], $aGuild))
  89. {
  90. $sql = "INSERT INTO {$db_prefix}guildmembers (gmPlayerID, gmName) VALUES ($admin_player_id, '" .
  91. ba_db_real_escape_string ($link, $_POST ["selGuild$iGuildCount"]) . "')";
  92. //Run the INSERT query
  93. if (! ba_db_query ($link, $sql)) {
  94. $sWarn = "There was a problem updating the IC details";
  95. LogError ("Error inserting guilds into guildmembers. Player ID: $admin_player_id");
  96. }
  97. $aGuild[] = $_POST [$sGuild];
  98. }
  99. $sGuild = "selGuild" . ++$iGuildCount;
  100. }
  101. }
  102. //Skills list: Delete existing rows from skillstaken, then run INSERT queries
  103. $sql = "DELETE FROM {$db_prefix}skillstaken WHERE stPlayerID = $admin_player_id";
  104. if (! ba_db_query ($link, $sql)) {
  105. $sWarn = "There was a problem updating the IC details";
  106. LogError ("Error deleting existing skills from skillstaken table during update of IC information (admin_edit_ic.php). " .
  107. "Player ID: $admin_player_id");
  108. }
  109. else {
  110. //Run INSERT queries. For each skill, check if box was ticked (or SELECT value was greater than 0). If it was, run INSERT
  111. for ($i = 1; $i <= 34; $i++) {
  112. if ($_POST ['sk' . $i] != '') {
  113. //Skill was selected. Set up and run INSERT query
  114. $sql = "INSERT INTO {$db_prefix}skillstaken (stPlayerID, stSkillID) VALUES ($admin_player_id, $i)";
  115. if ($sql != '') {
  116. //Run the INSERT query
  117. if (! ba_db_query ($link, $sql)) {
  118. $sWarn = "There was a problem updating the IC details";
  119. LogError ("Error inserting skills taken (admin_edit_ic.php). Player ID: $admin_player_id");
  120. }
  121. }
  122. }
  123. }
  124. }
  125. //OSPs list: Delete existing rows from ospstaken, then run INSERT queries
  126. $sql = "DELETE FROM {$db_prefix}ospstaken WHERE otPlayerID = $admin_player_id";
  127. if (! ba_db_query ($link, $sql)) {
  128. $sWarn = "There was a problem updating the IC details";
  129. LogError ("Error deleting existing OSPs from ospstaken table during update of IC information. Player ID: $admin_player_id");
  130. }
  131. else {
  132. $os = array();
  133. foreach ($_POST as $key => $value) {
  134. if (substr ($key, 0, 6) == "hospID") {
  135. $sql = "INSERT INTO {$db_prefix}ospstaken (otPlayerID, otOspID, otAdditionalText) VALUES ($admin_player_id, '" .ba_db_real_escape_string ($link, $value) . "', '".ba_db_real_escape_string ($link,$_POST ["ospAdditionalText{$value}"])."')";
  136. if ($sql != '' && !in_array($value, $os)) {
  137. $os[] = $value;
  138. //Run the INSERT query
  139. if (! ba_db_query ($link, $sql)) {
  140. $sWarn = "There was a problem updating the IC details";
  141. LogError ("Error inserting osps taken (admin_edit_ic.php). Player ID: $admin_player_id");
  142. }
  143. }
  144. }
  145. }
  146. }
  147. //Do not redirect if there are any database warnings
  148. if ($sWarn == '') {
  149. //Make up URL & redirect. Any warnings about data are encoded into URL for display on next page
  150. if ($sDataWarn != '')
  151. $sURL = fnSystemURL () . "admin_viewdetails.php?pid=$admin_player_id&warn=" . urlencode ("IC details updated<br>" . $sDataWarn);
  152. else
  153. $sURL = fnSystemURL () . "admin_viewdetails.php?pid=$admin_player_id&green=" . urlencode ("IC details updated");
  154. header ("Location: $sURL");
  155. }
  156. }
  157. include ('../inc/inc_head_html.php');
  158. include ('../inc/inc_js_forms.php');
  159. //Get existing details if there are any
  160. $sql = "SELECT * FROM {$db_prefix}characters WHERE chPlayerID = $admin_player_id";
  161. $result = ba_db_query ($link, $sql);
  162. $row = ba_db_fetch_assoc ($result);
  163. $sNotes = $row ['chNotes'];
  164. $sOSP = $row ['chOSP'];
  165. // Get OOC name
  166. $sql = "SELECT plFirstName, plSurname FROM {$db_prefix}players WHERE plPlayerID = $admin_player_id";
  167. $nameresult = ba_db_query ($link, $sql);
  168. $namerow = ba_db_fetch_assoc ($nameresult);
  169. ?>
  170. <h1><?php echo TITLE?> - IC Details</h1>
  171. <?php
  172. if ($sWarn != '')
  173. echo "<p class = 'warn'>" . $sWarn . "</p>";
  174. ?>
  175. <p>
  176. <i>Required fields are <span class = "req_colour">shaded</span></i>. Details will appear on the character card <i>exactly</i> as typed.<br>
  177. </p>
  178. <div class = 'warn'>
  179. <?php
  180. echo "Note that you are editing the IC details for " .
  181. htmlentities ($namerow ['plFirstName']) . " " . htmlentities ($namerow ['plSurname']) .
  182. " (" . PID_PREFIX . sprintf ('%03s', $admin_player_id) . ")";
  183. ?>
  184. <br>
  185. It is possible to select illegal combinations of skills. BE CAREFUL!
  186. </div>
  187. <p>
  188. <form action = "admin_edit_ic.php?pid=<?php echo $admin_player_id?>" method = "post" name ='ic_form' onsubmit = "return ic_js_check ()" accept-charset="iso-8859-1">
  189. <table class='characterDisplay'><tr>
  190. <td>Character Name:</td>
  191. <td><input type = "text" name = "txtCharName" class = "required" value = "<?php echo htmlentities (stripslashes ($row ['chName']))?>"></td>
  192. </tr><tr>
  193. <td>Preferred Character Name:</td>
  194. <td><input type = "text" name = "txtPreferredName" class = 'text' value = "<?php echo htmlentities (stripslashes ($row ['chPreferredName']))?>"></td>
  195. </tr><tr>
  196. <td>Race &amp; Gender:</td>
  197. <td>
  198. <select class = "req_colour" name = "selRace">
  199. <?php
  200. $sValue = $row ['chRace'];
  201. $asOptions = array ('Beastkin', 'Drow', 'Dwarves', 'Elves', 'Fey', 'Halfling', 'Human', 'Mineral', 'Ologs', 'Plant', 'Umbral', 'Urucks');
  202. foreach ($asOptions as $sOption) {
  203. echo "<option value = '$sOption'";
  204. if ($sOption == $sValue)
  205. echo ' selected';
  206. echo ">" . htmlentities (stripslashes ($sOption)) . "</option>\n";
  207. }
  208. ?>
  209. </select>
  210. <select class = "req_colour" name = "selGender">
  211. <?php
  212. $sValue = $row ['chGender'];
  213. $asOptions = array ('Male', 'Female');
  214. foreach ($asOptions as $sOption) {
  215. echo "<option value = '$sOption'";
  216. if ($sOption == $sValue)
  217. echo ' selected';
  218. echo ">" . htmlentities (stripslashes ($sOption)) . "</option>\n";
  219. }
  220. ?>
  221. </select></td>
  222. </tr>
  223. <?php
  224. if (LIST_GROUPS_LABEL != '') {
  225. echo "<tr><td>" . LIST_GROUPS_LABEL . "</td><td>";
  226. echo "<select name = 'selGroup'>";
  227. if ($row ['chGroupSel'] != '')
  228. ListNames ($link, DB_PREFIX . 'groups', 'grName', stripslashes ($row ['chGroupSel']));
  229. else
  230. ListNames ($link, DB_PREFIX . 'groups', 'grName', 'Other (enter name below)');
  231. echo "</select><br>";
  232. if ($row ['chGroupText'] != '')
  233. echo "<input type = 'text' class = 'text' name = 'txtGroup' value = '" . htmlentities (stripslashes ($row ['chGroupText'])) . "'>";
  234. else
  235. echo "<input type = 'text' class = 'text' name = 'txtGroup' value = 'Enter name here if not in above list'>";
  236. echo "</td></tr>";
  237. }
  238. else {
  239. //Write out hidden fields so that queries don't get broken
  240. echo "<input type = 'hidden' name = 'selGroup' value = ''>";
  241. echo "<input type = 'hidden' name = 'txtGroup' value = ''>";
  242. }
  243. ?>
  244. <tr>
  245. <td>Faction:</td>
  246. <td><select name = "selFaction" class = "req_colour">
  247. <?php
  248. if ($row ['chFaction'] != '')
  249. ListNames ($link, DB_PREFIX . 'factions', 'faName', htmlentities (stripslashes ($row ['chFaction'])));
  250. else
  251. ListNames ($link, DB_PREFIX . 'factions', 'faName', DEFAULT_FACTION);
  252. ?>
  253. </select>
  254. </td>
  255. </tr><tr>
  256. <td>Ancestor:</td>
  257. <?php
  258. if (ANCESTOR_DROPDOWN)
  259. {
  260. echo "<td>";
  261. echo "<select name = 'selAncestor'>";
  262. if ($row ['chAncestorSel'] != '')
  263. ListNames ($link, DB_PREFIX . 'ancestors', 'anName', stripslashes ($row ['chAncestorSel']));
  264. else
  265. ListNames ($link, DB_PREFIX . 'ancestors', 'anName', 'Other (enter name below)');
  266. echo "</select>&nbsp; </td></tr><tr><td></td>";
  267. echo "<td>";
  268. if ($row ['chAncestor'] != '')
  269. echo "<input type = 'text' class = 'text' name = 'txtAncestor' value = '" . htmlentities (stripslashes ($row ['chAncestor'])) . "'>";
  270. else
  271. echo "<input type = 'text' class = 'text' name = 'txtAncestor' value = 'Enter name here if not in above list' onfocus = \"fnClearValue ('txtAncestor', 'Enter name here if not in above list')\">";
  272. echo "</td></tr>";
  273. }
  274. else
  275. {
  276. echo '<td><input type = "text" class = "text" name = "txtAncestor" value = "'.htmlentities (stripslashes ($row ['chAncestor'])).'"></td></tr>';
  277. echo "<input type = 'hidden' name = 'selAncestor' value = ''>";
  278. }
  279. ?>
  280. </tr>
  281. <?php
  282. if (LOCATIONS_LABEL == '')
  283. //Write a hidden field so that INSERT/UPDATE query does not break
  284. echo "<input type = 'hidden' name = 'selLocation' value = ''>";
  285. else {
  286. echo "<tr><td>" . LOCATIONS_LABEL . "</td><td><select name = 'selLocation'>";
  287. ListNames ($link, DB_PREFIX . 'locations', 'lnName', htmlentities (stripslashes ($row ['chLocation'])));
  288. echo "</select></td></tr>";
  289. }
  290. ?>
  291. </table>
  292. </p>
  293. <p>
  294. <b>Guilds</b><br>
  295. <?php
  296. //Get character's guilds. Fill an array with the details. The array can then be queried, avoiding repeated DB queries
  297. $result = ba_db_query ($link, "SELECT gmName FROM {$db_prefix}guildmembers WHERE gmPlayerID = $admin_player_id");
  298. //$asGuild will hold the guilds
  299. $asGuild = array ();
  300. while ($row = ba_db_fetch_assoc ($result))
  301. $asGuild [] = $row ['gmName'];
  302. //Write out the guild select boxes
  303. for ($iGuildCount = 1; $iGuildCount <= NUM_GUILDS; $iGuildCount++) {
  304. //Find out if character is in this guild
  305. if (count ($asGuild) >= $iGuildCount)
  306. //Find out which guild to select
  307. $sGuild = $asGuild [$iGuildCount - 1];
  308. else
  309. $sGuild = " None";
  310. //Following IF statement is used to determine if this guild drop-down box is displayed
  311. if ($iGuildCount > count ($asGuild) + 1)
  312. $sDisplay = 'none';
  313. else
  314. $sDisplay = 'inline';
  315. echo "<!-- SPAN is used to hide/show SELECTs. JavaScript is used to write SPAN tags so that, if JS is disabled, SELECT is always shown -->\n";
  316. echo "<script type = 'text/javascript'>\n<!--\n";
  317. echo "document.write (\"<span id = 'spnGuild$iGuildCount' style = 'display: $sDisplay'>\")\n// -->\n</script>\n";
  318. echo "Guild:\n";
  319. echo "<select name = 'selGuild$iGuildCount' onchange = 'fnGuilds ($iGuildCount)'>\n";
  320. ListNames ($link, DB_PREFIX . 'guilds', 'guName', $sGuild);
  321. echo "</select><br>\n";
  322. echo "<script type = 'text/javascript'>\n<!--\ndocument.write ('</span>')\n";
  323. echo "// -->\n</script>\n";
  324. }
  325. ?>
  326. </p>
  327. <p>
  328. <table>
  329. <tr><th colspan = "4">Skills</th></tr>
  330. <?php
  331. //Get character's skills. Fill an array with the skills. This array can then be queried, avoiding repeated DB queries
  332. $result = ba_db_query ($link, "SELECT * FROM {$db_prefix}skillstaken WHERE stPlayerID = $admin_player_id");
  333. $aiSkillID = array ();
  334. while ($row = ba_db_fetch_assoc ($result))
  335. $aiSkillID [] = $row ['stSkillID'];
  336. //$sTR is either "<tr class = 'highlight'>" or "" - used to switch between two pairs of columns
  337. $sTR = "<tr class = 'highlight'>";
  338. $result = ba_db_query ($link, "SELECT * FROM {$db_prefix}skills ORDER BY skID");
  339. while ($row = ba_db_fetch_assoc ($result)) {
  340. //Find out if character has this skill
  341. $has = array_search ($row ['skID'], $aiSkillID);
  342. echo "$sTR<td>{$row ['skName']} ({$row ['skCost']})</td><td>";
  343. echo "<input name = 'sk" . $row ['skID'] . "' value = '" . $row ['skCost'] . "' ";
  344. if ($has !== False)
  345. //Character has this skill - tick the box
  346. echo "checked ";
  347. echo "type = 'checkbox' onclick = 'fnCalculate ()'>";
  348. echo "</td>";
  349. if ($sTR == "<tr class = 'highlight'>") {
  350. $sTR = "";
  351. echo "\n";
  352. }
  353. else {
  354. $sTR = "<tr class = 'highlight'>";
  355. echo "</tr>\n";
  356. }
  357. }
  358. ?>
  359. <tr><td colspan = '4'><span id = 'spCost'></span></td></tr>
  360. <tr><td colspan = '4'>&nbsp;</td></tr>
  361. <tr><td colspan = '4'><?php echo IC_NOTES_TEXT ?><br>
  362. <textarea name = "txtNotes"><?php echo htmlentities (stripslashes ($sNotes))?></textarea>
  363. </td></tr>
  364. <tr><td colspan = '4'><b>Special items/powers/creatures</b> (you must provide photcopies<br>
  365. or scans for them to be valid at the event). Please enter one per line.<br>
  366. <textarea name = "txtOSP"><?php echo htmlentities (stripslashes ($sOSP))?></textarea>
  367. </td></tr>
  368. </table>
  369. <p>
  370. <b>OSPs</b><br>
  371. <?php
  372. //New and exciting way
  373. //Get character's OSPs. Fill an array with the details. The array can then be queried, avoiding repeated DB queries
  374. $result = ba_db_query ($link, "SELECT * FROM {$db_prefix}ospstaken, {$db_prefix}osps WHERE otPlayerID = $admin_player_id AND ospID = otOspID");
  375. //$asOSP will hold the OSP names, $aiOspID will hold the OSP ID numbers
  376. $asOSP = array ();
  377. $aiOspID = array ();
  378. echo "<ul id='osplist'>";
  379. while ($row = ba_db_fetch_assoc ($result)) {
  380. $asOSP [] = $row ['ospName'];
  381. $aiOspID [] = $row ['otOspID'];
  382. echo "<li id=osp".$row['ospID'].">".$row ['ospName'];
  383. echo "<input type='hidden' name='hospID".$row['ospID']."' value='".$row['ospID']."' />";
  384. if ($row['ospAllowAdditionalText'] == 1) { echo " (<input type='text' value='".$row ['otAdditionalText']."' name='ospAdditionalText".$row ['ospID']."' />)"; }
  385. echo " <input type='button' onclick='removeosp(".$row['ospID']."); return false;' value='x' /></li>\n";
  386. }
  387. echo "</ul>";
  388. ?>
  389. Add Occupational Skill: <input type='text' id='addos' name='addos' />
  390. <script type='text/javascript'>
  391. function removeosp(ospid) {
  392. $('#osp' + ospid).remove();
  393. }
  394. $().ready(function() {
  395. $("#addos").autocomplete({
  396. source: "../inc/inc_ossearch.php?pid=<?php echo $admin_player_id; ?>&",
  397. minLength: 2,
  398. focus: function( event, ui ) {
  399. $( "#addos" ).val( ui.item.label );
  400. return false;
  401. },
  402. select: function( event, ui ) {
  403. var newosp = "<li id='osp"+ui.item.value+"'>" + ui.item.label;
  404. newosp += "<input type='hidden' name='hospID"+ui.item.value+"' value='"+ui.item.value+"' />";
  405. if (ui.item.allowadditional == "1") { newosp += " (<input type='text' value='' name='ospAdditionalText"+ ui.item.value +"' />)"; }
  406. newosp += " <input type='button' onclick='removeosp("+ui.item.value+"); return false;' value='x' /></li>";
  407. $("#osplist").append(newosp);
  408. $("#addos").val('');
  409. return false;
  410. }
  411. });
  412. });
  413. </script>
  414. </p>
  415. <table>
  416. <tr><td colspan = '2'>
  417. <div class = "warn">Note that you are editing the IC details for player ID <?php echo PID_PREFIX . sprintf ('%03s', $admin_player_id)?><br>
  418. Illegal combinations of skills are allowed (a note will be added to the IC Notes). BE CAREFUL!</div>
  419. </td></tr>
  420. <tr><td class = 'mid'><input type = 'submit' value = 'Submit' name = 'btnSubmit'></td>
  421. <td class = 'mid'>
  422. <script type = 'text/javascript'>
  423. <!--
  424. //Use a button to reset the form, so that fnCalculate can be called *after* the reset
  425. document.write ("<input type = 'button' value = 'Reset' onclick = 'document.forms [0].reset (); fnCalculate ()'>")
  426. // -->
  427. </script>
  428. <noscript>
  429. <input type = 'reset' value = 'Reset'>
  430. </noscript>
  431. </td></tr>
  432. </table>
  433. </form>
  434. <script type = 'text/javascript'>
  435. <!--
  436. fnCalculate ()
  437. // -->
  438. </script>
  439. <?php
  440. include ('../inc/inc_foot.php');
  441. ?>