2
0

Poll.template.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines
  7. * @copyright 2011 Simple Machines
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.1 Alpha 1
  11. */
  12. function template_main()
  13. {
  14. global $context, $settings, $options, $txt, $scripturl;
  15. // Some javascript for adding more options.
  16. echo '
  17. <script type="text/javascript"><!-- // --><![CDATA[
  18. var pollOptionNum = 0;
  19. var pollOptionId = ', $context['last_choice_id'], ';
  20. function addPollOption()
  21. {
  22. if (pollOptionNum == 0)
  23. {
  24. for (var i = 0; i < document.forms.postmodify.elements.length; i++)
  25. if (document.forms.postmodify.elements[i].id.substr(0, 8) == "options-")
  26. pollOptionNum++;
  27. }
  28. pollOptionNum++
  29. pollOptionId++
  30. setOuterHTML(document.getElementById("pollMoreOptions"), \'<li><label for="options-\' + pollOptionId + \'" ', (isset($context['poll_error']['no_question']) ? ' class="error"' : ''), '>', $txt['option'], ' \' + pollOptionNum + \'</label>: <input type="text" name="options[\' + (pollOptionId) + \']" id="options-\' + (pollOptionId) + \'" value="" size="80" maxlength="255" class="input_text" /></li><li id="pollMoreOptions"></li\');
  31. }
  32. // ]]></script>';
  33. // Start the main poll form.
  34. echo '
  35. <div id="edit_poll">
  36. <form action="' . $scripturl . '?action=editpoll2', $context['is_edit'] ? '' : ';add', ';topic=' . $context['current_topic'] . '.' . $context['start'] . '" method="post" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this); smc_saveEntities(\'postmodify\', [\'question\'], \'options-\');" name="postmodify" id="postmodify">
  37. <div class="cat_bar">
  38. <h3 class="catbg">', $context['page_title'], '</h3>
  39. </div>';
  40. if (!empty($context['poll_error']['messages']))
  41. echo '
  42. <div class="errorbox">
  43. <dl class="poll_error">
  44. <dt>
  45. ', $context['is_edit'] ? $txt['error_while_editing_poll'] : $txt['error_while_adding_poll'], ':
  46. </dt>
  47. <dt>
  48. ', empty($context['poll_error']['messages']) ? '' : implode('<br />', $context['poll_error']['messages']), '
  49. </dt>
  50. </dl>
  51. </div>';
  52. echo '
  53. <div>
  54. <span class="upperframe"><span></span></span>
  55. <div class="roundframe">
  56. <input type="hidden" name="poll" value="', $context['poll']['id'], '" />
  57. <fieldset id="poll_main">
  58. <legend><span ', (isset($context['poll_error']['no_question']) ? ' class="error"' : ''), '>', $txt['poll_question'], ':</span></legend>
  59. <input type="text" name="question" size="80" value="', $context['poll']['question'], '" class="input_text" />
  60. <ul class="poll_main">';
  61. foreach ($context['choices'] as $choice)
  62. {
  63. echo '
  64. <li>
  65. <label for="options-', $choice['id'], '" ', (isset($context['poll_error']['poll_few']) ? ' class="error"' : ''), '>', $txt['option'], ' ', $choice['number'], '</label>:
  66. <input type="text" name="options[', $choice['id'], ']" id="options-', $choice['id'], '" value="', $choice['label'], '" class="input_text" size="80" maxlength="255" />';
  67. // Does this option have a vote count yet, or is it new?
  68. if ($choice['votes'] != -1)
  69. echo ' (', $choice['votes'], ' ', $txt['votes'], ')';
  70. echo '
  71. </li>';
  72. }
  73. echo '
  74. <li id="pollMoreOptions"></li>
  75. </ul>
  76. <strong><a href="javascript:addPollOption(); void(0);">(', $txt['poll_add_option'], ')</a></strong>
  77. </fieldset>
  78. <fieldset id="poll_options">
  79. <legend>', $txt['poll_options'], ':</legend>
  80. <dl class="settings poll_options">';
  81. if ($context['can_moderate_poll'])
  82. {
  83. echo '
  84. <dt>
  85. <label for="poll_max_votes">', $txt['poll_max_votes'], ':</label>
  86. </dt>
  87. <dd>
  88. <input type="text" name="poll_max_votes" id="poll_max_votes" size="2" value="', $context['poll']['max_votes'], '" class="input_text" />
  89. </dd>
  90. <dt>
  91. <label for="poll_expire">', $txt['poll_run'], ':</label><br />
  92. <em class="smalltext">', $txt['poll_run_limit'], '</em>
  93. </dt>
  94. <dd>
  95. <input type="text" name="poll_expire" id="poll_expire" size="2" value="', $context['poll']['expiration'], '" onchange="this.form.poll_hide[2].disabled = isEmptyText(this) || this.value == 0; if (this.form.poll_hide[2].checked) this.form.poll_hide[1].checked = true;" maxlength="4" class="input_text" /> ', $txt['days_word'], '
  96. </dd>
  97. <dt>
  98. <label for="poll_change_vote">', $txt['poll_do_change_vote'], ':</label>
  99. </dt>
  100. <dd>
  101. <input type="checkbox" id="poll_change_vote" name="poll_change_vote"', !empty($context['poll']['change_vote']) ? ' checked="checked"' : '', ' class="input_check" />
  102. </dd>';
  103. if ($context['poll']['guest_vote_allowed'])
  104. echo '
  105. <dt>
  106. <label for="poll_guest_vote">', $txt['poll_guest_vote'], ':</label>
  107. </dt>
  108. <dd>
  109. <input type="checkbox" id="poll_guest_vote" name="poll_guest_vote"', !empty($context['poll']['guest_vote']) ? ' checked="checked"' : '', ' class="input_check" />
  110. </dd>';
  111. }
  112. echo '
  113. <dt>
  114. ', $txt['poll_results_visibility'], ':
  115. </dt>
  116. <dd>
  117. <input type="radio" name="poll_hide" id="poll_results_anyone" value="0"', $context['poll']['hide_results'] == 0 ? ' checked="checked"' : '', ' class="input_radio" /> <label for="poll_results_anyone">', $txt['poll_results_anyone'], '</label><br />
  118. <input type="radio" name="poll_hide" id="poll_results_voted" value="1"', $context['poll']['hide_results'] == 1 ? ' checked="checked"' : '', ' class="input_radio" /> <label for="poll_results_voted">', $txt['poll_results_voted'], '</label><br />
  119. <input type="radio" name="poll_hide" id="poll_results_expire" value="2"', $context['poll']['hide_results'] == 2 ? ' checked="checked"' : '', empty($context['poll']['expiration']) ? 'disabled="disabled"' : '', ' class="input_radio" /> <label for="poll_results_expire">', $txt['poll_results_after'], '</label>
  120. </dd>
  121. </dl>
  122. </fieldset>';
  123. // If this is an edit, we can allow them to reset the vote counts.
  124. if ($context['is_edit'])
  125. echo '
  126. <fieldset id="poll_reset">
  127. <legend>', $txt['reset_votes'], '</legend>
  128. <input type="checkbox" name="resetVoteCount" value="on" class="input_check" /> ' . $txt['reset_votes_check'] . '
  129. </fieldset>';
  130. echo '
  131. <div class="righttext padding">
  132. <input type="submit" name="post" value="', $txt['save'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit" />
  133. </div>
  134. </div>
  135. <span class="lowerframe"><span></span></span>
  136. </div>
  137. <input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '" />
  138. <input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
  139. </form>
  140. </div>
  141. <br class="clear" />';
  142. }
  143. ?>