PageRenderTime 59ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/siteadmin/poll-edit.php

http://pacercms.googlecode.com/
PHP | 227 lines | 197 code | 21 blank | 9 comment | 27 complexity | 0c1916dc5e4664442e5b7756406669d4 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. // Loads everything needed to run PacerCMS
  3. include('cm-includes/cm-header.php');
  4. // Declare the current module
  5. $module = "poll-edit";
  6. $pmodule = "poll-browse";
  7. $mode = "edit"; // Default
  8. // SECURITY - User must be authenticated to view page //
  9. cm_auth_module($module);
  10. // Change mode based on query string
  11. if (!empty($_GET['action']))
  12. {
  13. $mode = $_GET['action'];
  14. }
  15. // If action is delete, call delete function
  16. if ($mode == "delete" && is_numeric($_POST['delete-id']))
  17. {
  18. $id = $_POST['delete-id'];
  19. $stat = cm_delete_poll($id);
  20. if ($stat) {
  21. header("Location: $pmodule.php?msg=deleted");
  22. exit;
  23. } else {
  24. cm_error(gettext("Error in 'cm_delete_poll' function."));
  25. exit;
  26. }
  27. }
  28. // These will be changed later if needed, set defaults.
  29. $volume = $_COOKIE['issue-browse-volume'];
  30. $id = $_GET["id"];
  31. // If action is edit, call edit function
  32. if ($mode == "edit")
  33. {
  34. if (is_numeric($_POST['id']))
  35. {
  36. $poll['question'] = prep_string($_POST['question']);
  37. $poll['r1'] = prep_string($_POST['r1']);
  38. $poll['r2'] = prep_string($_POST['r2']);
  39. $poll['r3'] = prep_string($_POST['r3']);
  40. $poll['r4'] = prep_string($_POST['r4']);
  41. $poll['r5'] = prep_string($_POST['r5']);
  42. $poll['r6'] = prep_string($_POST['r6']);
  43. $poll['r7'] = prep_string($_POST['r7']);
  44. $poll['r8'] = prep_string($_POST['r8']);
  45. $poll['r9'] = prep_string($_POST['r9']);
  46. $poll['r10'] = prep_string($_POST['r10']);
  47. $poll['article_id'] = $_POST['article'];
  48. $id = $_POST['id'];
  49. $stat = cm_edit_poll($poll,$id);
  50. if ($stat) {
  51. header("Location: $pmodule.php?msg=updated");
  52. exit;
  53. } else {
  54. cm_error(gettext("Error in 'cm_edit_poll' function."));
  55. exit;
  56. }
  57. } elseif (!empty($_POST)) {
  58. cm_error(gettext("Did not have a poll question to load."));
  59. exit;
  60. }
  61. }
  62. // If action is new, call add function
  63. if ($mode == "new" && !empty($_POST['question']))
  64. {
  65. $poll['question'] = prep_string($_POST['question']);
  66. $poll['r1'] = prep_string($_POST['r1']);
  67. $poll['r2'] = prep_string($_POST['r2']);
  68. $poll['r3'] = prep_string($_POST['r3']);
  69. $poll['r4'] = prep_string($_POST['r4']);
  70. $poll['r5'] = prep_string($_POST['r5']);
  71. $poll['r6'] = prep_string($_POST['r6']);
  72. $poll['r7'] = prep_string($_POST['r7']);
  73. $poll['r8'] = prep_string($_POST['r8']);
  74. $poll['r9'] = prep_string($_POST['r9']);
  75. $poll['r10'] = prep_string($_POST['r10']);
  76. $poll['article_id'] = $_POST['article'];
  77. $stat = cm_add_poll($poll);
  78. if ($stat) {
  79. header("Location: $pmodule.php?msg=added");
  80. exit;
  81. } else {
  82. cm_error(gettext("Error in 'cm_add_poll' function."));
  83. exit;
  84. }
  85. }
  86. // Only call database if in edit mode.
  87. if ($mode == "edit" && is_numeric($id))
  88. {
  89. $query = "SELECT * FROM cm_poll_questions WHERE id = $id; ";
  90. $result = cm_run_query($query);
  91. if ($result->RecordCount() != 1)
  92. {
  93. cm_error(gettext("That poll question cannot be loaded."));
  94. }
  95. $id = $result->Fields('id');
  96. $question = $result->Fields('poll_question');
  97. $r1 = $result->Fields('poll_response_1');
  98. $r2 = $result->Fields('poll_response_2');
  99. $r3 = $result->Fields('poll_response_3');
  100. $r4 = $result->Fields('poll_response_4');
  101. $r5 = $result->Fields('poll_response_5');
  102. $r6 = $result->Fields('poll_response_6');
  103. $r7 = $result->Fields('poll_response_7');
  104. $r8 = $result->Fields('poll_response_8');
  105. $r9 = $result->Fields('poll_response_9');
  106. $r10 = $result->Fields('poll_response_10');
  107. $article = $result->Fields('article_id');
  108. }
  109. get_cm_header();
  110. ?>
  111. <h2><a href="<?php echo "$pmodule.php"; ?>"><?php echo gettext("Poll Manager"); ?></a></h2>
  112. <form action="<?php echo "$module.php?action=$mode"; ?>" method="post">
  113. <fieldset class="<?php echo "$module-form"; ?>">
  114. <legend><?php echo gettext("Question Editor"); ?></legend>
  115. <div class="sidebar">
  116. <p>
  117. <label for="article"><?php echo gettext("Related Article ID"); ?></label>
  118. <br />
  119. <input type="text" name="article" id="article" value="<?php echo $article; ?>" />
  120. </p>
  121. <?php if ($mode == "edit") { ?>
  122. <h4><?php echo gettext("Audit"); ?></h4>
  123. <p style="width:200px:"><?php cm_poll_cleanup($id) ?></p>
  124. <h4><?php echo gettext("Current Results"); ?></h4>
  125. <?php cm_poll_results($id); ?>
  126. <?php } ?>
  127. </div>
  128. <p>
  129. <label for="question"><?php echo gettext("Poll Question"); ?></label>
  130. <br/>
  131. <textarea name="question" id="question"><?php echo $question; ?></textarea>
  132. </p>
  133. <p>
  134. <label for="r1"><?php echo gettext("Option 1"); ?></label>
  135. <br />
  136. <input type="text" name="r1" id="r1" value="<?php echo htmlentities($r1, ENT_QUOTES, 'UTF-8'); ?>" class="text" />
  137. </p>
  138. <p>
  139. <label for="r2"><?php echo gettext("Option 2"); ?></label>
  140. <br />
  141. <input type="text" name="r2" id="r2" value="<?php echo htmlentities($r2, ENT_QUOTES, 'UTF-8'); ?>" class="text" />
  142. </p>
  143. <p>
  144. <label for="r3"><?php echo gettext("Option 3"); ?></label>
  145. <br />
  146. <input type="text" name="r3" id="r3" value="<?php echo htmlentities($r3, ENT_QUOTES, 'UTF-8'); ?>" class="text" />
  147. </p>
  148. <p>
  149. <label for="r4"><?php echo gettext("Option 4"); ?></label>
  150. <br />
  151. <input type="text" name="r4" id="r4" value="<?php echo htmlentities($r4, ENT_QUOTES, 'UTF-8'); ?>" class="text" />
  152. </p>
  153. <p>
  154. <label for="r5"><?php echo gettext("Option 5"); ?></label>
  155. <br />
  156. <input type="text" name="r5" id="r5" value="<?php echo htmlentities($r5, ENT_QUOTES, 'UTF-8'); ?>" class="text" />
  157. </p>
  158. <p>
  159. <label for="r6"><?php echo gettext("Option 6"); ?></label>
  160. <br />
  161. <input type="text" name="r6" id="r6" value="<?php echo htmlentities($r6, ENT_QUOTES, 'UTF-8'); ?>" class="text" />
  162. </p>
  163. <p>
  164. <label for="r7"><?php echo gettext("Option 7"); ?></label>
  165. <br />
  166. <input type="text" name="r7" id="r7" value="<?php echo htmlentities($r7, ENT_QUOTES, 'UTF-8'); ?>" class="text" />
  167. </p>
  168. <p>
  169. <label for="r8"><?php echo gettext("Option 8"); ?></label>
  170. <br />
  171. <input type="text" name="r8" id="r8" value="<?php echo htmlentities($r8, ENT_QUOTES, 'UTF-8'); ?>" class="text" />
  172. </p>
  173. <p>
  174. <label for="r9"><?php echo gettext("Option 9"); ?></label>
  175. <br />
  176. <input type="text" name="r9" id="r9" value="<?php echo htmlentities($r9, ENT_QUOTES, 'UTF-8'); ?>" class="text" />
  177. </p>
  178. <p>
  179. <label for="r10"><?php echo gettext("Option 10"); ?></label>
  180. <br />
  181. <input type="text" name="r10" id="r10" value="<?php echo htmlentities($r10, ENT_QUOTES, 'UTF-8'); ?>" class="text" />
  182. </p>
  183. <p>
  184. <?php if ($mode == "new") { ?>
  185. <input type="submit" value="<?php echo gettext("Add Poll"); ?>" name="submit" id="submit" class="button" />
  186. <?php } if ($mode == "edit") { ?>
  187. <input type="submit" value="<?php echo gettext("Update Poll"); ?>" name="update" id="update" class="button" />
  188. <input name="id" type="hidden" id="id" value="<?php echo $id; ?>" />
  189. <?php } ?>
  190. <input type="button" value="<?php echo gettext("Cancel"); ?>" name="cancel_modify" id="cancel_modify" class="button" onClick="javascript:history.back();" />
  191. </p>
  192. </fieldset>
  193. </form>
  194. <h2><?php echo gettext("Delete Poll"); ?> <a href="javascript:toggleLayer('deleteRecord');" name="delete">&raquo;&raquo;</a></h2>
  195. <div id="deleteRecord">
  196. <form action="<?php echo "$module.php?action=delete"; ?>" method="post">
  197. <fieldset class="<?php echo "$module-delete" ?>">
  198. <legend><?php echo gettext("Confirm Delete"); ?></legend>
  199. <p><?php echo gettext("Are you sure you want to delete this poll and associated ballots?"); ?></p>
  200. <input type="submit" name="submit-delete" id="submit-delete" value="<?php echo gettext("Delete"); ?>" class="button" />
  201. <input type="button" name="cancel-delete" id="cancel-delete" value="<?php echo gettext("Cancel"); ?>" onClick="toggleLayer('deleteRecord');" class="button" />
  202. <input type="hidden" name="delete-id" id="delete-id" value="<?php echo $id; ?>" />
  203. </fieldset>
  204. </form>
  205. </div>
  206. <?php get_cm_footer(); ?>