PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/plugins/poll/admin-files/poll/index.php

https://github.com/nistormihai/Newscoop
PHP | 280 lines | 238 code | 30 blank | 12 comment | 34 complexity | 3c526af96c4011a0fda3dceebbd427dd MD5 | raw file
  1. <?php
  2. camp_load_translation_strings("plugin_poll");
  3. // Check permissions
  4. if (!$g_user->hasPermission('plugin_poll')) {
  5. camp_html_display_error(getGS('You do not have the right to manage polls.'));
  6. exit;
  7. }
  8. $f_language_selected = Input::Get('f_language_selected', 'int');
  9. $f_poll_limit = Input::Get('f_poll_limit', 'int', 20);
  10. $f_poll_offset = Input::Get('f_poll_offset', 'int', 0);
  11. $f_poll_order = Input::Get('f_poll_order', 'string', 'bynumber');
  12. $parents = Poll::getPolls(array('language_id' => $f_language_selected, 'parent_poll_nr' => 0), null, $f_poll_offset, $f_poll_limit, $f_poll_order);
  13. // add the copys
  14. foreach ($parents as $poll) {
  15. $polls[] = $poll;
  16. $copys = Poll::getPolls(array('language_id' => $poll->getLanguageId(), 'parent_poll_nr' => $poll->getNumber()));
  17. foreach ($copys as $poll) {
  18. $polls[] = $poll;
  19. }
  20. }
  21. $pager = new SimplePager(Poll::countPolls(), $f_poll_limit, "f_poll_offset", "index.php?f_poll_order=$f_poll_order&amp;", false);
  22. $allLanguages = Language::GetLanguages();
  23. include_once($GLOBALS['g_campsiteDir']."/$ADMIN_DIR/javascript_common.php");
  24. echo camp_html_breadcrumbs(array(
  25. array(getGS('Plugins'), $Campsite['WEBSITE_URL'] . '/admin/plugins/manage.php'),
  26. array(getGS('Polls'), ''),
  27. ));
  28. // DO NOT DELETE!!! Needed for localizer
  29. // getGS("Polls");
  30. ?>
  31. <script type="text/javascript" src="<?php echo $Campsite['WEBSITE_URL']; ?>/javascript/campsite-checkbox.js"></script>
  32. <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1" class="action_buttons" style="padding-top: 5px;">
  33. <TR>
  34. <TD><A HREF="edit.php" ><IMG SRC="<?php echo $Campsite["ADMIN_IMAGE_BASE_URL"]; ?>/add.png" BORDER="0"></A></TD>
  35. <TD><A HREF="edit.php" ><B><?php putGS("Add new Poll"); ?></B></A></TD>
  36. </tr>
  37. </TABLE>
  38. <p>
  39. <FORM name="poll_list" action="action.php" method="POST">
  40. <?php echo SecurityToken::FormParameter(); ?>
  41. <TABLE CELLSPACING="0" CELLPADDING="0" class="table_actions">
  42. <TR>
  43. <TD>
  44. <TABLE cellpadding="0" cellspacing="0">
  45. <TR>
  46. <TD ALIGN="left">
  47. <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="3" >
  48. <TR>
  49. <TD><?php putGS('Language'); ?>:</TD>
  50. <TD valign="middle">
  51. <SELECT NAME="f_language_selected" id="f_language_selected" class="input_select" onchange="location.href='index.php?f_language_selected='+document.getElementById('f_language_selected').options[document.getElementById('f_language_selected').selectedIndex].value;">
  52. <option value="0"><?php putGS("All"); ?></option>
  53. <?php
  54. foreach ($allLanguages as $languageItem) {
  55. echo '<OPTION value="'.$languageItem->getLanguageId().'"' ;
  56. if ($languageItem->getLanguageId() == $f_language_selected) {
  57. echo " selected";
  58. }
  59. echo '>'.htmlspecialchars($languageItem->getNativeName()).'</option>';
  60. } ?>
  61. </SELECT>
  62. </TD>
  63. </TR>
  64. </TABLE>
  65. </TD>
  66. <TD style="padding-left: 20px;">
  67. <script>
  68. function action_selected(dropdownElement)
  69. {
  70. // Verify that at least one checkbox has been selected.
  71. checkboxes = document.forms.poll_list["f_poll_code[]"];
  72. if (checkboxes) {
  73. isValid = false;
  74. numCheckboxesChecked = 0;
  75. // Special case for single checkbox
  76. // (when there is only one article in the section).
  77. if (!checkboxes.length) {
  78. isValid = checkboxes.checked;
  79. numCheckboxesChecked = isValid ? 1 : 0;
  80. }
  81. else {
  82. // Multiple checkboxes
  83. for (var index = 0; index < checkboxes.length; index++) {
  84. if (checkboxes[index].checked) {
  85. isValid = true;
  86. numCheckboxesChecked++;
  87. }
  88. }
  89. }
  90. if (!isValid) {
  91. alert("<?php putGS("You must select at least one poll to perform an action."); ?>");
  92. dropdownElement.options[0].selected = true;
  93. return;
  94. }
  95. }
  96. else {
  97. dropdownElement.options[0].selected = true;
  98. return;
  99. }
  100. // Get the index of the "delete" and "reset" option.
  101. deleteOptionIndex = -1;
  102. translateOptionIndex = -1;
  103. for (var index = 0; index < dropdownElement.options.length; index++) {
  104. if (dropdownElement.options[index].value == "delete") {
  105. deleteOptionIndex = index;
  106. }
  107. if (dropdownElement.options[index].value == "reset") {
  108. resetOptionIndex = index;
  109. }
  110. }
  111. // if the user has selected the "delete" option
  112. if (dropdownElement.selectedIndex == deleteOptionIndex) {
  113. ok = confirm("<?php putGS("Are you sure you want to delete the selected polls?"); ?>");
  114. if (!ok) {
  115. dropdownElement.options[0].selected = true;
  116. return;
  117. }
  118. }
  119. // if the user has selected the "reset" option
  120. if (dropdownElement.selectedIndex == resetOptionIndex) {
  121. ok = confirm("<?php putGS("Are you sure you want to reset counters on the selected polls?"); ?>");
  122. if (!ok) {
  123. dropdownElement.options[0].selected = true;
  124. return;
  125. }
  126. }
  127. // do the action if it isnt the first or second option
  128. if ( (dropdownElement.selectedIndex != 0)) {
  129. dropdownElement.form.submit();
  130. }
  131. }
  132. </script>
  133. <SELECT name="f_poll_list_action" class="input_select" onchange="action_selected(this);">
  134. <OPTION value=""><?php putGS("Actions"); ?>...</OPTION>
  135. <OPTION value="delete"><?php putGS("Delete"); ?></OPTION>
  136. <OPTION value="reset"><?php putGS("Reset"); ?></OPTION>
  137. </SELECT>
  138. </TD>
  139. <TD style="padding-left: 5px; font-weight: bold;">
  140. <input type="button" class="button" value="<?php putGS("Select All"); ?>" onclick="checkAll(<?php p(count($polls)); ?>);">
  141. <input type="button" class="button" value="<?php putGS("Select None"); ?>" onclick="uncheckAll(<?php p(count($polls)); ?>);">
  142. </TD>
  143. </TR>
  144. </TABLE>
  145. </TD>
  146. </TR>
  147. </TABLE>
  148. <p>
  149. <table class="indent">
  150. <tr>
  151. <td>
  152. <?php echo $pager->render(); ?>
  153. </td>
  154. </tr>
  155. </table>
  156. <?php
  157. $counter = 0;
  158. $color= 0;
  159. if (count($polls)) {
  160. ?>
  161. <TABLE BORDER="0" CELLSPACING="1" CELLPADDING="3" class="table_list" style="padding-top: 5px;" width="95%">
  162. <TR class="table_list_header">
  163. <TD width="10">&nbsp;</TD>
  164. <TD ALIGN="LEFT" VALIGN="TOP" width="800">
  165. <A href="index.php?f_poll_offset=<?php echo $f_poll_offset ?>&amp;f_poll_order=byname"><?php putGS("Name"); ?></a>
  166. &nbsp;<SMALL>(<?php putGS('click to edit'); ?></SMALL>
  167. </TD>
  168. <TD ALIGN="center" VALIGN="TOP" width="30">
  169. <A href="index.php?f_poll_offset=<?php echo $f_poll_offset ?>&amp;f_poll_order=bybegin"><?php putGS("Begin"); ?></a>
  170. </TD>
  171. <TD ALIGN="center" VALIGN="TOP" width="30">
  172. <A href="index.php?f_poll_offset=<?php echo $f_poll_offset ?>&amp;f_poll_order=byend"><?php putGS("End"); ?></a>
  173. </TD>
  174. <TD ALIGN="center" VALIGN="TOP" width="20">&nbsp;</TD>
  175. <TD ALIGN="center" VALIGN="TOP" width="20">&nbsp;</TD>
  176. <TD align="center" valign="top" width="20">&nbsp;</TD>
  177. <TD align="center" valign="top" width="20">&nbsp;</TD>
  178. </TR>
  179. <?php
  180. $used = array();
  181. foreach ($polls as $poll) {
  182. if ($color) {
  183. $rowClass = "list_row_even";
  184. } else {
  185. $rowClass = "list_row_odd";
  186. }
  187. $color = !$color;
  188. ?>
  189. <script>default_class[<?php p($counter); ?>] = "<?php p($rowClass); ?>";</script>
  190. <TR id="row_<?php p($counter); ?>" class="<?php p($rowClass); ?>" onmouseover="setPointer(this, <?php p($counter); ?>, 'over');" onmouseout="setPointer(this, <?php p($counter); ?>, 'out');">
  191. <TD>
  192. <input type="checkbox" value="<?php p((int)$poll->getNumber().'_'.(int)$poll->getLanguageId()); ?>" name="f_poll_code[]" id="checkbox_<?php p($counter); ?>" class="input_checkbox" onclick="checkboxClick(this, <?php p($counter); ?>);">
  193. </TD>
  194. <td>
  195. <?php
  196. if (!array_key_exists($poll->getNumber(), $used) && $poll->getProperty('parent_poll_nr') == 0) {
  197. p($poll->getNumber().'.');
  198. $used[$poll->getNumber()] = true;
  199. } elseif ($poll->getProperty('parent_poll_nr')) {
  200. p('\'-> '.$poll->getNumber().'.');
  201. } else {
  202. p('&nbsp;&nbsp;');
  203. }
  204. ?>
  205. <a href="edit.php?f_poll_nr=<?php p($poll->getNumber()); ?>&amp;f_fk_language_id=<?php p($poll->getLanguageId()); ?>">
  206. <?php p($poll->getProperty('title')); ?>
  207. </a>
  208. &nbsp; (<?php p($poll->getLanguageName()); ?>)
  209. </td>
  210. <td align="center"><?php p($poll->getProperty('date_begin')); ?></td>
  211. <td align="center"><?php p($poll->getProperty('date_end')); ?></td>
  212. <td align='center'>
  213. <?php if (!$poll->getProperty('parent_poll_nr')) { ?>
  214. <a href="translate.php?f_poll_nr=<?php p($poll->getNumber()); ?>&f_fk_language_id=<?php p($poll->getLanguageId()) ?>" title="<?php putGS('Translate') ?>">
  215. <IMG SRC="<?php echo $Campsite["ADMIN_IMAGE_BASE_URL"]; ?>/translate.png" BORDER="0">
  216. </a>
  217. <?php } ?>
  218. </td>
  219. <td align='center'>
  220. <?php if ($poll->isExtended()) { ?>
  221. <a href="copy.php?f_poll_nr=<?php p($poll->getNumber()); ?>&f_fk_language_id=<?php p($poll->getLanguageId()) ?>" title="<?php putGS('Copy') ?>">
  222. <IMG SRC="<?php echo $Campsite["ADMIN_IMAGE_BASE_URL"]; ?>/duplicate.png" BORDER="0">
  223. </a>
  224. <?php } ?>
  225. </td>
  226. <td align='center'>
  227. <a href="result.php?f_poll_nr=<?php p($poll->getNumber()); ?>&f_fk_language_id=<?php p($poll->getLanguageId()); ?>" title="<?php putGS('Result') ?>">
  228. <IMG SRC="<?php echo $Campsite["ADMIN_IMAGE_BASE_URL"]; ?>/preview.png" BORDER="0">
  229. </a>
  230. </td>
  231. <td align='center'>
  232. <a href="javascript: if (confirm('<?php echo camp_javascriptspecialchars(getGS('Are you sure you want to delete the poll "$1"?', $poll->getProperty('title'))); ?>')) location.href='do_delete.php?f_poll_nr=<?php p($poll->getNumber()); ?>&amp;f_fk_language_id=<?php p($poll->getLanguageId()); ?>&amp;<?php echo SecurityToken::URLParameter(); ?>'">
  233. <IMG SRC="<?php echo $Campsite["ADMIN_IMAGE_BASE_URL"]; ?>/delete.png" BORDER="0">
  234. </a>
  235. </td>
  236. </tr>
  237. <?php
  238. $counter++;
  239. }
  240. ?>
  241. </table>
  242. </FORM>
  243. <?php
  244. } else {?>
  245. <BLOCKQUOTE>
  246. <LI><?php putGS('No polls.'); ?></LI>
  247. </BLOCKQUOTE>
  248. <?php
  249. }
  250. ?>