PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/post/addjp.php

https://github.com/anodyne/sms
PHP | 347 lines | 256 code | 63 blank | 28 comment | 34 complexity | 907249217a210b86664f7917d675ad7f 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/post/addjp.php
  8. Purpose: Page to add a joint post
  9. System Version: 2.6.10
  10. Last Modified: 2009-09-08 0843 EST
  11. **/
  12. /* access check */
  13. if( in_array( "p_addjp", $sessionAccess ) ) {
  14. /* set the page class and vars */
  15. $pageClass = "admin";
  16. $subMenuClass = "post";
  17. $result = FALSE;
  18. $query = FALSE;
  19. if(isset($_GET['id']))
  20. {
  21. if(is_numeric($_GET['id'])) {
  22. $id = $_GET['id'];
  23. } else {
  24. errorMessageIllegal( "add JP page" );
  25. exit();
  26. }
  27. }
  28. if(isset($_GET['number']))
  29. {
  30. if(is_numeric($_GET['number'])) {
  31. $number = $_GET['number'];
  32. } else {
  33. errorMessageIllegal( "add JP page" );
  34. exit();
  35. }
  36. }
  37. if(isset($_GET['delete']))
  38. {
  39. if(is_numeric($_GET['delete'])) {
  40. $delete = $_GET['delete'];
  41. } else {
  42. errorMessageIllegal( "add JP page" );
  43. exit();
  44. }
  45. }
  46. if(isset($_GET['add']))
  47. {
  48. if(is_numeric($_GET['add'])) {
  49. $add = $_GET['add'];
  50. } else {
  51. errorMessageIllegal( "add JP page" );
  52. exit();
  53. }
  54. }
  55. if(!isset($number)) {
  56. $number = 2;
  57. } elseif( $number > JP_AUTHORS ) {
  58. $number = JP_AUTHORS;
  59. }
  60. if(isset($_POST['action_x']))
  61. {
  62. $jpnumber = $_POST['jpNumber'];
  63. for ($n=1; $n<=$jpnumber; $n++)
  64. {
  65. $authors[] = $_POST['author' . $n];
  66. }
  67. /* make a string of the authors */
  68. $postAuthors = implode(',', $authors);
  69. $insert = "INSERT INTO sms_posts (postAuthor, postTitle, postLocation, postTimeline, postContent, postPosted, postMission, ";
  70. $insert.= "postStatus, postTag) VALUES (%s, %s, %s, %s, %s, UNIX_TIMESTAMP(), %d, %s, %s)";
  71. $query = sprintf(
  72. $insert,
  73. escape_string($postAuthors),
  74. escape_string($_POST['postTitle']),
  75. escape_string($_POST['postLocation']),
  76. escape_string($_POST['postTimeline']),
  77. escape_string($_POST['postContent']),
  78. escape_string($_POST['postMission']),
  79. escape_string('activated'),
  80. escape_string($_POST['postTag'])
  81. );
  82. $result = mysql_query($query);
  83. for($i=1; $i<=$number; $i++)
  84. {
  85. /* set the author var */
  86. $author = $_POST['author' . $i];
  87. if(!is_numeric($author)) {
  88. $author = NULL;
  89. }
  90. /* update the player's last post timestamp */
  91. $updateTimestamp = "UPDATE sms_crew SET lastPost = UNIX_TIMESTAMP() WHERE crewid = $author LIMIT 1";
  92. $updateTimestampResult = mysql_query( $updateTimestamp );
  93. }
  94. /* optimize the crew table */
  95. optimizeSQLTable( "sms_crew" );
  96. optimizeSQLTable( "sms_posts" );
  97. /* if the user wants to send the email out, do it */
  98. if(isset($_POST['sendEmail']))
  99. {
  100. foreach($_POST as $key => $value)
  101. {
  102. $$key = $value;
  103. }
  104. if(is_numeric($_POST['author1'])) {
  105. $emailAuthor = $_POST['author1'];
  106. }
  107. /* set the email author */
  108. $userFetch = "SELECT crew.crewid, crew.firstName, crew.lastName, crew.email, rank.rankShortName ";
  109. $userFetch.= "FROM sms_crew AS crew, sms_ranks AS rank ";
  110. $userFetch.= "WHERE crew.crewid = $emailAuthor AND crew.rankid = rank.rankid LIMIT 1";
  111. $userFetchResult = mysql_query( $userFetch );
  112. while( $userFetchArray = mysql_fetch_array( $userFetchResult ) ) {
  113. extract( $userFetchArray, EXTR_OVERWRITE );
  114. }
  115. $firstName = str_replace( "'", "", $firstName );
  116. $lastName = str_replace( "'", "", $lastName );
  117. $from = $rankShortName . " " . $firstName . " " . $lastName . " < " . $email . " >";
  118. /* define the variables */
  119. $to = getCrewEmails("emailPosts");
  120. $subject = $emailSubject . " " . printMissionTitle( $postMission ) . " - " . $postTitle;
  121. $message = "A Post By " . displayEmailAuthors($postAuthors, 'noLink') . "\r\n";
  122. $message.= "Location: " . stripslashes($postLocation) . "\r\n";
  123. $message.= "Timeline: " . stripslashes($postTimeline) . "\r\n";
  124. $message.= "Tag: " . stripslashes($postTag) . "\r\n\r\n";
  125. $message.= stripslashes($postContent);
  126. /* send the email */
  127. mail( $to, $subject, $message, "From: " . $from . "\nX-Mailer: PHP/" . phpversion() );
  128. }
  129. }
  130. ?>
  131. <script type="text/javascript">
  132. $(document).ready(function() {
  133. $('#participants').change(function(){
  134. var number = $(this).val();
  135. window.location = "<?php echo $webLocation;?>admin.php?page=post&sub=addjp&number=" + number;
  136. });
  137. });
  138. </script>
  139. <div class="body">
  140. <?php
  141. $check = new QueryCheck;
  142. $check->checkQuery( $result, $query );
  143. if( !empty( $check->query ) ) {
  144. $check->message( "joint post", "add" );
  145. $check->display();
  146. }
  147. ?>
  148. <span class="fontTitle">Add Joint Mission Entry</span><br /><br />
  149. This page should be used in the event that a member of the crew has accidentally posted incorrectly. For instance, if a player has replied to one of the emails sent out to the system instead of logging in and posting, you can copy and paste the contents of their email into this form and put the entry into the system. For all other joint posts, please use the <a href="<?=$webLocation;?>admin.php?page=post&sub=jp"> Write Joint Post</a> page.<br /><br />
  150. <span class="fontNormal">
  151. <b>Select the number of participants:</b> &nbsp;
  152. <select id="participants">
  153. <option value="">Please Choose One</option>
  154. <?php for ($k=2; $k<=JP_AUTHORS; $k++): ?>
  155. <option value="<?php echo $k;?>"><?php echo $k;?> People</option>
  156. <?php endfor;?>
  157. </select>
  158. </span><br /><br />
  159. <form method="post" action="<?=$webLocation;?>admin.php?page=post&sub=addjp">
  160. <table>
  161. <?
  162. $authorNum = 1;
  163. for( $i=1; $i<=$number; $i++ ) {
  164. ?>
  165. <tr>
  166. <td class="narrowLabel tableCellLabel">
  167. <b>Author #<?=$i;?></b>
  168. </td>
  169. <td>&nbsp;</td>
  170. <td>
  171. <select name="author<?=$authorNum;?>">
  172. <?
  173. /* query the users database */
  174. $sql = "SELECT crew.crewid, crew.firstName, crew.lastName, rank.rankName ";
  175. $sql.= "FROM sms_crew AS crew, sms_ranks AS rank ";
  176. $sql.= "WHERE crew.crewType = 'active' AND crew.rankid = rank.rankid ";
  177. $sql.= "ORDER BY crew.rankid ASC";
  178. $result = mysql_query( $sql );
  179. /*
  180. start looping through what the query returns
  181. until it runs out of records
  182. */
  183. while( $myrow = mysql_fetch_array( $result ) ) {
  184. extract( $myrow, EXTR_OVERWRITE );
  185. /* $authorNumber = $author . $authorNum; */
  186. $authorNumber = $rankName . " " . $firstName . " " . $lastName;
  187. echo "<option value='" . $myrow['crewid'] . "'>" . $authorNumber . "</option>";
  188. }
  189. ?>
  190. </select>
  191. </td>
  192. </tr>
  193. <? $authorNum = $authorNum + 1; } ?>
  194. <? if(!isset($number)) { ?>
  195. <input type="hidden" name="jpNumber" value="2" />
  196. <? } else { ?>
  197. <input type="hidden" name="jpNumber" value="<?=$number;?>" />
  198. <? } ?>
  199. <tr>
  200. <td class="narrowLabel tableCellLabel">Mission</td>
  201. <td>&nbsp;</td>
  202. <td class="fontNormal">
  203. <?
  204. $missionTitle = "SELECT missionid, missionTitle FROM sms_missions WHERE missionStatus = 'current' LIMIT 1";
  205. $missionTitleResult = mysql_query( $missionTitle );
  206. $missionCount = mysql_num_rows( $missionTitleResult );
  207. while( $titleArray = mysql_fetch_array( $missionTitleResult ) ) {
  208. extract( $titleArray, EXTR_OVERWRITE );
  209. }
  210. if( $missionCount == 0 ) {
  211. echo "<b>Please create a mission before posting!</b>";
  212. } else {
  213. $missions = "SELECT missionid, missionTitle, missionStatus FROM sms_missions WHERE ";
  214. $missions.= "missionStatus != 'upcoming'";
  215. $missionsResult = mysql_query( $missions );
  216. echo "<select name='postMission'>";
  217. while( $missionArray = mysql_fetch_array( $missionsResult ) ) {
  218. extract( $missionArray, EXTR_OVERWRITE );
  219. echo "<option value='" . $missionid . "'";
  220. if( $missionStatus == "current" ) {
  221. echo " selected ";
  222. }
  223. echo ">";
  224. printText( $missionTitle );
  225. echo "</option>";
  226. }
  227. echo "</select>";
  228. }
  229. ?>
  230. </td>
  231. </tr>
  232. <tr>
  233. <td colspan="3" height="10"></td>
  234. </tr>
  235. <tr>
  236. <td class="narrowLabel tableCellLabel">Title</td>
  237. <td>&nbsp;</td>
  238. <td><input type="text" class="name" name="postTitle" style="font-weight:bold;" length="100" /></td>
  239. </tr>
  240. <tr>
  241. <td class="narrowLabel tableCellLabel">Location</td>
  242. <td>&nbsp;</td>
  243. <td><input type="text" class="name" name="postLocation" style="font-weight:bold;" length="100" /></td>
  244. </tr>
  245. <tr>
  246. <td class="narrowLabel tableCellLabel">Timeline</td>
  247. <td>&nbsp;</td>
  248. <td><input type="text" class="name" name="postTimeline" style="font-weight:bold;" length="100" /></td>
  249. </tr>
  250. <tr>
  251. <td class="narrowLabel tableCellLabel">Tag</td>
  252. <td>&nbsp;</td>
  253. <td><input type="text" class="name" name="postTag" style="font-weight:bold;" length="100" /></td>
  254. </tr>
  255. <tr>
  256. <td class="narrowLabel tableCellLabel">Send Email?</td>
  257. <td>&nbsp;</td>
  258. <td><input type="checkbox" name="sendEmail" value="y" checked="checked" /></td>
  259. </tr>
  260. <tr>
  261. <td colspan="3" height="10"></td>
  262. </tr>
  263. <tr>
  264. <td class="narrowLabel tableCellLabel">Content</td>
  265. <td>&nbsp;</td>
  266. <td><textarea name="postContent" class="desc" rows="15"></textarea></td>
  267. </tr>
  268. <tr>
  269. <td colspan="3" height="20"></td>
  270. </tr>
  271. <? if( $missionCount > "0" ) { ?>
  272. <tr>
  273. <td colspan="2">&nbsp;</td>
  274. <td>
  275. <input type="image" src="<?=path_userskin;?>buttons/add.png" name="action" class="button" value="Add" />
  276. </td>
  277. </tr>
  278. <? } ?>
  279. </table>
  280. </form>
  281. </div>
  282. <? } else { errorMessage( "add joint post" ); } ?>