PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/manage/add.php

https://github.com/anodyne/sms
PHP | 366 lines | 290 code | 54 blank | 22 comment | 26 complexity | 5ee0d5841d04c5a84b9925c81e28cca9 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. This is a necessary system file. Do not modify this page unless you are highly
  4. knowledgeable as to the structure of the system. Modification of this file may
  5. cause SMS to no longer function.
  6. Author: David VanScott [ davidv@anodyne-productions.com ]
  7. File: admin/manage/add.php
  8. Purpose: Page to add a player or NPC
  9. System Version: 2.6.8
  10. Last Modified: 2009-01-12 1142 EST
  11. **/
  12. /* access check */
  13. if(in_array("m_createcrew", $sessionAccess))
  14. {
  15. /* set the page class */
  16. $pageClass = "admin";
  17. $subMenuClass = "manage";
  18. $query = FALSE;
  19. $result = FALSE;
  20. $today = getdate();
  21. if(isset($_POST['action_create_x']))
  22. {
  23. foreach($_POST as $key => $value)
  24. {
  25. $$key = $value;
  26. }
  27. if($crewType == 'npc' && (in_array("m_npcs1", $sessionAccess ) || in_array("m_npcs2", $sessionAccess)))
  28. {
  29. $insert = "INSERT INTO sms_crew (crewType, firstName, middleName, lastName, gender, species, rankid, positionid) ";
  30. $insert.= "VALUES (%s, %s, %s, %s, %s, %s, %d, %d)";
  31. $query = sprintf(
  32. $insert,
  33. escape_string('npc'),
  34. escape_string($_POST['firstName']),
  35. escape_string($_POST['middleName']),
  36. escape_string($_POST['lastName']),
  37. escape_string($_POST['gender']),
  38. escape_string($_POST['species']),
  39. escape_string($_POST['rank']),
  40. escape_string($_POST['position'])
  41. );
  42. $result = mysql_query($query);
  43. /* optimize the table */
  44. optimizeSQLTable( "sms_crew" );
  45. $type = 'non-playing character';
  46. }
  47. elseif($crewType == "active" && in_array("m_crew", $sessionAccess))
  48. {
  49. if($password == $confirmPassword)
  50. {
  51. if(!is_numeric($position)) {
  52. $position = NULL;
  53. }
  54. /* get the position type from the database */
  55. $getPosType = "SELECT positionType FROM sms_positions WHERE positionid = $position LIMIT 1";
  56. $getPosTypeResult = mysql_query($getPosType);
  57. $positionType = mysql_fetch_row($getPosTypeResult);
  58. /* set the access levels accordingly */
  59. if($positionType[0] == "senior") {
  60. $accessID = 3;
  61. } else {
  62. $accessID = 4;
  63. }
  64. /* pull the default access levels from the db */
  65. $getGroupLevels = "SELECT * FROM sms_accesslevels WHERE id = $accessID LIMIT 1";
  66. $getGroupLevelsResult = mysql_query($getGroupLevels);
  67. $groups = mysql_fetch_array($getGroupLevelsResult);
  68. $insert = "INSERT INTO sms_crew (crewType, username, password, email, firstName, middleName, lastName, gender, ";
  69. $insert.= "species, rankid, positionid, joinDate, accessPost, accessManage, accessReports, accessUser, ";
  70. $insert.= "accessOthers, moderatePosts, moderateLogs, moderateNews) ";
  71. $insert.= "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %d, %d, %s, %s, %s, %s, %s, %s, %s, %s)";
  72. $query = sprintf(
  73. $insert,
  74. escape_string('active'),
  75. escape_string($_POST['username']),
  76. escape_string(md5($_POST['password'])),
  77. escape_string($_POST['email']),
  78. escape_string($_POST['firstName']),
  79. escape_string($_POST['middleName']),
  80. escape_string($_POST['lastName']),
  81. escape_string($_POST['gender']),
  82. escape_string($_POST['species']),
  83. escape_string($_POST['rank']),
  84. escape_string($_POST['position']),
  85. escape_string($today[0]),
  86. escape_string($groups[1]),
  87. escape_string($groups[2]),
  88. escape_string($groups[3]),
  89. escape_string($groups[4]),
  90. escape_string($groups[5]),
  91. escape_string($_POST['moderatePosts']),
  92. escape_string($_POST['moderateLogs']),
  93. escape_string($_POST['moderateNews'])
  94. );
  95. $result = mysql_query($query);
  96. update_position($position, 'give');
  97. /* optimize the table */
  98. optimizeSQLTable( "sms_crew" );
  99. optimizeSQLTable( "sms_positions" );
  100. $type = 'character';
  101. /** EMAIL THE PLAYER **/
  102. /* define the variables */
  103. $to = $email . ", " . printCOEmail();
  104. $from = printCO('short_rank') . " < " . printCOEmail() . " >";
  105. $subject = $emailSubject . " New Character Created";
  106. $message = "This is an automatic email to notify you that your new character has been created. Please log in to the site (" . $webLocation . ") using the username and password below to update your biography. If you have any questions, please contact the CO.
  107. USERNAME: " . $_POST['username'] . "
  108. PASSWORD: " . $_POST['password'] . "";
  109. /* send the email */
  110. mail( $to, $subject, $message, "From: " . $from . "\nX-Mailer: PHP/" . phpversion() );
  111. }
  112. else
  113. {
  114. $result = FALSE;
  115. }
  116. }
  117. }
  118. ?>
  119. <script type="text/javascript">
  120. $(document).ready(function() {
  121. $('#crewTypeN').click(function(){
  122. $('#pc').hide();
  123. });
  124. $('#crewTypeP').click(function(){
  125. $('#pc').show();
  126. });
  127. });
  128. </script>
  129. <div class="body">
  130. <?php
  131. $check = new QueryCheck;
  132. $check->checkQuery($result, $query);
  133. if(!empty($check->query))
  134. {
  135. $check->message($type, "create");
  136. $check->display();
  137. }
  138. ?>
  139. <span class="fontTitle">Add Crew</span><br /><br />
  140. <? if( in_array( "m_npcs1", $sessionAccess ) ) { ?>
  141. Department Heads are permitted to create NPCs for their own department and at ranks lower than their own. If you want an NPC to hold a rank equal to or higher than your own, please contact the CO or XO. Additionally, you can assign an NPC to any open position. If you have questions or problems, please contact the CO or XO.
  142. <? } elseif( in_array( "m_npcs2", $sessionAccess ) ) { ?>
  143. Commanding Officers and Executive Officers are permitted to create NPCs for any department and at any rank. Additionally, COs can assign an NPC to any open position in any department. COs are also the only members of the crew authorized to create new playing characters. New playing characters that are created will still need to be approved through the Control Panel before the player associated with the character can log in and begin simming.
  144. <? } ?><br /><br />
  145. <form method="post" action="<?=$webLocation;?>admin.php?page=manage&sub=add">
  146. <strong>Character Type</strong><br />
  147. <input type="radio" id="crewTypeP" name="crewType" value="active" <? if( !in_array( "m_crew", $sessionAccess ) ) { echo "disabled"; } else { echo "checked"; } ?>/> <label for="crewTypeP">Playing Character</label>
  148. <input type="radio" id="crewTypeN" name="crewType" value="npc" <? if( !in_array( "m_crew", $sessionAccess ) && ( in_array( "m_npcs1", $sessionAccess ) || in_array( "m_npcs2", $sessionAccess ) ) ) { echo " checked"; } ?> /> <label for="crewTypeN">Non-Playing Character</label>
  149. <? if( in_array( "m_crew", $sessionAccess ) ) { ?>
  150. <div id="pc">
  151. <table>
  152. <tr>
  153. <td colspan="3" height="15"></td>
  154. </tr>
  155. <tr>
  156. <td class="tableCellLabel">Username</td>
  157. <td>&nbsp;</td>
  158. <td><input type="text" class="image" name="username" /></td>
  159. </tr>
  160. <tr>
  161. <td class="tableCellLabel">Password</td>
  162. <td>&nbsp;</td>
  163. <td><input type="password" class="image" name="password" /></td>
  164. </tr>
  165. <tr>
  166. <td class="tableCellLabel">Confirm Password</td>
  167. <td>&nbsp;</td>
  168. <td><input type="password" class="image" name="confirmPassword" /></td>
  169. </tr>
  170. <tr>
  171. <td class="tableCellLabel">Email Address</td>
  172. <td>&nbsp;</td>
  173. <td><input type="text" class="image" name="email" /></td>
  174. </tr>
  175. <tr>
  176. <td colspan="3" height="15"></td>
  177. </tr>
  178. <tr>
  179. <td class="tableCellLabel">Moderate Posts?</td>
  180. <td>&nbsp;</td>
  181. <td>
  182. <input type="radio" name="moderatePosts" id="posts_y" value="y" /> <label for="posts_y">Yes</label>
  183. <input type="radio" name="moderatePosts" id="posts_n" value="n" checked /> <label for="posts_n">No</label>
  184. </td>
  185. </tr>
  186. <tr>
  187. <td class="tableCellLabel">Moderate Logs?</td>
  188. <td>&nbsp;</td>
  189. <td>
  190. <input type="radio" name="moderateLogs" id="logs_y" value="y" /> <label for="logs_y">Yes</label>
  191. <input type="radio" name="moderateLogs" id="logs_n" value="n" checked /> <label for="logs_n">No</label>
  192. </td>
  193. </tr>
  194. <tr>
  195. <td class="tableCellLabel">Moderate News?</td>
  196. <td>&nbsp;</td>
  197. <td>
  198. <input type="radio" name="moderateNews" id="news_y" value="y" /> <label for="news_y">Yes</label>
  199. <input type="radio" name="moderateNews" id="news_n" value="n" checked /> <label for="news_n">No</label>
  200. </td>
  201. </tr>
  202. </table>
  203. </div>
  204. <? } ?>
  205. <br /><br />
  206. <table>
  207. <tr>
  208. <td class="tableCellLabel">First Name</td>
  209. <td>&nbsp;</td>
  210. <td><input type="text" class="image" name="firstName" /></td>
  211. </tr>
  212. <tr>
  213. <td class="tableCellLabel">Middle Name</td>
  214. <td>&nbsp;</td>
  215. <td><input type="text" class="image" name="middleName" /></td>
  216. </tr>
  217. <tr>
  218. <td class="tableCellLabel">Last Name</td>
  219. <td>&nbsp;</td>
  220. <td><input type="text" class="image" name="lastName" /></td>
  221. </tr>
  222. <tr>
  223. <td class="tableCellLabel">Gender</td>
  224. <td>&nbsp;</td>
  225. <td>
  226. <select name="gender">
  227. <option value="Male">Male</option>
  228. <option value="Female">Female</option>
  229. <option value="Hermaphrodite">Hermaphrodite</option>
  230. <option value="Neuter">Neuter</option>
  231. </select>
  232. </td>
  233. </tr>
  234. <tr>
  235. <td class="tableCellLabel">Species</td>
  236. <td>&nbsp;</td>
  237. <td><input type="text" class="image" name="species" /></td>
  238. </tr>
  239. <tr>
  240. <td colspan="3" height="15"></td>
  241. </tr>
  242. <?
  243. if( in_array( "m_npcs2", $sessionAccess ) ) {
  244. $ranks = "SELECT rank.rankid, rank.rankName, rank.rankImage, dept.deptColor FROM sms_ranks AS rank, ";
  245. $ranks.= "sms_departments AS dept WHERE dept.deptClass = rank.rankClass AND dept.deptDisplay = 'y' ";
  246. $ranks.= "AND rank.rankDisplay = 'y' GROUP BY rank.rankid ORDER BY rank.rankClass, rank.rankOrder ASC";
  247. $ranksResult = mysql_query( $ranks );
  248. $positions = "SELECT position.positionid, position.positionName, dept.deptName, ";
  249. $positions.= "dept.deptColor FROM sms_positions AS position, sms_departments AS dept ";
  250. $positions.= "WHERE position.positionOpen > '0' AND dept.deptid = position.positionDept ";
  251. $positions.= "AND dept.deptDisplay = 'y' ORDER BY position.positionDept, position.positionid ASC";
  252. $positionsResult = mysql_query( $positions );
  253. } elseif( in_array( "m_npcs1", $sessionAccess ) ) {
  254. $userDeptQuery = "SELECT crew.positionid, crew.rankid, position.positionDept, rank.rankOrder FROM ";
  255. $userDeptQuery.= "sms_crew AS crew, sms_positions AS position, sms_ranks AS rank WHERE ";
  256. $userDeptQuery.= "crew.crewid = '$sessionCrewid' AND crew.positionid = position.positionid AND crew.rankid = rank.rankid LIMIT 1";
  257. $userDeptResult = mysql_query( $userDeptQuery );
  258. $userDept = mysql_fetch_row( $userDeptResult );
  259. $ranks = "SELECT rank.rankid, rank.rankName, rank.rankImage, dept.deptColor ";
  260. $ranks.= "FROM sms_ranks AS rank, sms_departments AS dept ";
  261. $ranks.= "WHERE dept.deptid = '$userDept[2]' AND dept.deptClass = rank.rankClass ";
  262. $ranks.= "AND rank.rankOrder >= '$userDept[3]' AND dept.deptDisplay = 'y' ";
  263. $ranks.= "AND rank.rankDisplay = 'y' GROUP BY rank.rankid ORDER BY rank.rankClass, rank.rankOrder ASC";
  264. $ranksResult = mysql_query( $ranks );
  265. $positions = "SELECT position.positionid, position.positionName, dept.deptName, dept.deptColor ";
  266. $positions.= "FROM sms_positions AS position, sms_departments AS dept ";
  267. $positions.= "WHERE position.positionOpen > '0' AND position.positionDept = dept.deptid AND ";
  268. $positions.= "position.positionDept = '$userDept[2]' ORDER BY positionOrder ASC";
  269. $positionsResult = mysql_query( $positions );
  270. }
  271. ?>
  272. <tr>
  273. <td class="tableCellLabel">Rank</td>
  274. <td>&nbsp;</td>
  275. <td>
  276. <select name="rank">
  277. <?
  278. while($rank = mysql_fetch_assoc($ranksResult)) {
  279. extract($rank, EXTR_OVERWRITE);
  280. echo "<option value='" . $rank['rankid'] . "' style='background:#000; color:#" . $rank['deptColor'] . ";'>" . $rank['rankName'] . "</option>";
  281. }
  282. ?>
  283. </select>
  284. </td>
  285. </tr>
  286. <tr>
  287. <td class="tableCellLabel">Position</td>
  288. <td>&nbsp;</td>
  289. <td>
  290. <select name="position">
  291. <?
  292. while( $position = mysql_fetch_assoc( $positionsResult ) ) {
  293. extract( $position, EXTR_OVERWRITE );
  294. echo "<option value='" . $position['positionid'] . "' style='color:#" . $position['deptColor'] . ";'>" . $position['deptName'] . " - " . $position['positionName'] . "</option>";
  295. }
  296. ?>
  297. </select>
  298. </td>
  299. </tr>
  300. <tr>
  301. <td colspan="3" height="25"></td>
  302. </tr>
  303. <tr>
  304. <td colspan="2"></td>
  305. <td><input type="image" src="<?=path_userskin;?>buttons/create.png" name="action_create" class="button" value="Create" /></td>
  306. </tr>
  307. </table>
  308. </form>
  309. </div>
  310. <? } else { errorMessage( "add character" ); } ?>