ManageBans.template.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2014 Simple Machines and individual contributors
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.1 Alpha 1
  11. */
  12. function template_ban_edit()
  13. {
  14. global $context, $scripturl, $txt, $modSettings;
  15. echo '
  16. <div id="manage_bans">
  17. <form id="admin_form_wrapper" action="', $context['form_url'], '" method="post" accept-charset="', $context['character_set'], '" onsubmit="return confirmBan(this);">
  18. <div class="cat_bar">
  19. <h3 class="catbg">
  20. ', $context['ban']['is_new'] ? $txt['ban_add_new'] : $txt['ban_edit'] . ' \'' . $context['ban']['name'] . '\'', '
  21. </h3>
  22. </div>';
  23. if ($context['ban']['is_new'])
  24. echo '
  25. <div class="information">', $txt['ban_add_notes'], '</div>';
  26. // If there were errors creating the ban, show them.
  27. if (!empty($context['error_messages']))
  28. {
  29. echo '
  30. <div class="errorbox">
  31. <strong>', $txt['ban_errors_detected'], '</strong>
  32. <ul>';
  33. foreach ($context['error_messages'] as $error)
  34. echo '
  35. <li class="error">', $error, '</li>';
  36. echo '
  37. </ul>
  38. </div>';
  39. }
  40. echo '
  41. <div class="content">
  42. <dl class="settings">
  43. <dt id="ban_name_label">
  44. <strong>', $txt['ban_name'], ':</strong>
  45. </dt>
  46. <dd>
  47. <input type="text" id="ban_name" name="ban_name" value="', $context['ban']['name'], '" size="45" maxlength="60" class="input_text">
  48. </dd>';
  49. if (isset($context['ban']['reason']))
  50. echo '
  51. <dt>
  52. <strong><label for="reason">', $txt['ban_reason'], ':</label></strong><br>
  53. <span class="smalltext">', $txt['ban_reason_desc'], '</span>
  54. </dt>
  55. <dd>
  56. <textarea name="reason" id="reason" cols="40" rows="3" style="min-height: 64px; max-height: 64px; min-width: 50%; max-width: 99%;">', $context['ban']['reason'], '</textarea>
  57. </dd>';
  58. if (isset($context['ban']['notes']))
  59. echo '
  60. <dt>
  61. <strong><label for="ban_notes">', $txt['ban_notes'], ':</label></strong><br>
  62. <span class="smalltext">', $txt['ban_notes_desc'], '</span>
  63. </dt>
  64. <dd>
  65. <textarea name="notes" id="ban_notes" cols="40" rows="3" style="min-height: 64px; max-height: 64px; min-width: 50%; max-width: 99%;">', $context['ban']['notes'], '</textarea>
  66. </dd>';
  67. echo '
  68. </dl>
  69. <fieldset class="ban_settings floatleft">
  70. <legend>
  71. ', $txt['ban_expiration'], '
  72. </legend>
  73. <input type="radio" name="expiration" value="never" id="never_expires" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'never' ? ' checked' : '', ' class="input_radio"> <label for="never_expires">', $txt['never'], '</label><br>
  74. <input type="radio" name="expiration" value="one_day" id="expires_one_day" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'one_day' ? ' checked' : '', ' class="input_radio"> <label for="expires_one_day">', $txt['ban_will_expire_within'], '</label>: <input type="number" name="expire_date" id="expire_date" size="3" value="', $context['ban']['expiration']['days'], '" class="input_text"> ', $txt['ban_days'], '<br>
  75. <input type="radio" name="expiration" value="expired" id="already_expired" onclick="fUpdateStatus();"', $context['ban']['expiration']['status'] == 'expired' ? ' checked' : '', ' class="input_radio"> <label for="already_expired">', $txt['ban_expired'], '</label>
  76. </fieldset>
  77. <fieldset class="ban_settings floatright">
  78. <legend>
  79. ', $txt['ban_restriction'], '
  80. </legend>
  81. <input type="radio" name="full_ban" id="full_ban" value="1" onclick="fUpdateStatus();"', $context['ban']['cannot']['access'] ? ' checked' : '', ' class="input_radio"> <label for="full_ban">', $txt['ban_full_ban'], '</label><br>
  82. <input type="radio" name="full_ban" id="partial_ban" value="0" onclick="fUpdateStatus();"', !$context['ban']['cannot']['access'] ? ' checked' : '', ' class="input_radio"> <label for="partial_ban">', $txt['ban_partial_ban'], '</label><br>
  83. <input type="checkbox" name="cannot_post" id="cannot_post" value="1"', $context['ban']['cannot']['post'] ? ' checked' : '', ' class="ban_restriction input_radio"> <label for="cannot_post">', $txt['ban_cannot_post'], '</label> (<a href="', $scripturl, '?action=helpadmin;help=ban_cannot_post" onclick="return reqOverlayDiv(this.href);">?</a>)<br>
  84. <input type="checkbox" name="cannot_register" id="cannot_register" value="1"', $context['ban']['cannot']['register'] ? ' checked' : '', ' class="ban_restriction input_radio"> <label for="cannot_register">', $txt['ban_cannot_register'], '</label><br>
  85. <input type="checkbox" name="cannot_login" id="cannot_login" value="1"', $context['ban']['cannot']['login'] ? ' checked' : '', ' class="ban_restriction input_radio"> <label for="cannot_login">', $txt['ban_cannot_login'], '</label><br>
  86. </fieldset>
  87. <br class="clear_right">';
  88. if (!empty($context['ban_suggestions']))
  89. {
  90. echo '
  91. <fieldset>
  92. <legend>
  93. <input type="checkbox" onclick="invertAll(this, this.form, \'ban_suggestion\');" class="input_check"> ', $txt['ban_triggers'], '
  94. </legend>
  95. <dl class="settings">
  96. <dt>
  97. <input type="checkbox" name="ban_suggestions[]" id="main_ip_check" value="main_ip" class="input_check"', !empty($context['ban_suggestions']['main_ip']) ? ' checked' : '', '>
  98. <label for="main_ip_check">', $txt['ban_on_ip'], '</label>
  99. </dt>
  100. <dd>
  101. <input type="text" name="main_ip" value="', $context['ban_suggestions']['main_ip'], '" size="44" onfocus="document.getElementById(\'main_ip_check\').checked = true;" class="input_text">
  102. </dd>';
  103. if (empty($modSettings['disableHostnameLookup']))
  104. echo '
  105. <dt>
  106. <input type="checkbox" name="ban_suggestions[]" id="hostname_check" value="hostname" class="input_check"', !empty($context['ban_suggestions']['hostname']) ? ' checked' : '', '>
  107. <label for="hostname_check">', $txt['ban_on_hostname'], '</label>
  108. </dt>
  109. <dd>
  110. <input type="text" name="hostname" value="', $context['ban_suggestions']['hostname'], '" size="44" onfocus="document.getElementById(\'hostname_check\').checked = true;" class="input_text">
  111. </dd>';
  112. echo '
  113. <dt>
  114. <input type="checkbox" name="ban_suggestions[]" id="email_check" value="email" class="input_check"', !empty($context['ban_suggestions']['email']) ? ' checked' : '', '>
  115. <label for="email_check">', $txt['ban_on_email'], '</label>
  116. </dt>
  117. <dd>
  118. <input type="text" name="email" value="', $context['ban_suggestions']['email'], '" size="44" onfocus="document.getElementById(\'email_check\').checked = true;" class="input_text">
  119. </dd>
  120. <dt>
  121. <input type="checkbox" name="ban_suggestions[]" id="user_check" value="user" class="input_check"', !empty($context['ban_suggestions']['user']) || isset($context['ban']['from_user']) ? ' checked' : '', '>
  122. <label for="user_check">', $txt['ban_on_username'], '</label>:
  123. </dt>
  124. <dd>
  125. <input type="text" ', isset($context['ban']['from_user']) ? 'readonly value="' . $context['ban_suggestions']['member']['name'] . '"' : ' value=""', ' name="user" id="user" size="44" class="input_text">
  126. </dd>
  127. </dl>';
  128. if (!empty($context['ban_suggestions']['other_ips']))
  129. {
  130. foreach ($context['ban_suggestions']['other_ips'] as $key => $ban_ips)
  131. {
  132. if (!empty($ban_ips))
  133. {
  134. echo '
  135. <div>', $txt[$key], ':</div>
  136. <dl class="settings">';
  137. $count = 0;
  138. foreach ($ban_ips as $ip)
  139. echo '
  140. <dt>
  141. <input type="checkbox" id="suggestions_', $key ,'_', $count, '" name="ban_suggestions[', $key ,'][]"', !empty($context['ban_suggestions']['saved_triggers'][$key]) && in_array($ip, $context['ban_suggestions']['saved_triggers'][$key]) ? ' checked' : '', ' value="', $ip, '" class="input_check">
  142. </dt>
  143. <dd>
  144. <label for="suggestions_', $key ,'_', $count++, '">', $ip, '</label>
  145. </dd>';
  146. echo '
  147. </dl>';
  148. }
  149. }
  150. }
  151. echo '
  152. </fieldset>';
  153. }
  154. echo '
  155. <input type="submit" name="', $context['ban']['is_new'] ? 'add_ban' : 'modify_ban', '" value="', $context['ban']['is_new'] ? $txt['ban_add'] : $txt['ban_modify'], '" class="button_submit">
  156. <input type="hidden" name="old_expire" value="', $context['ban']['expiration']['days'], '">
  157. <input type="hidden" name="bg" value="', $context['ban']['id'], '">', isset($context['ban']['from_user']) ? '
  158. <input type="hidden" name="u" value="' . $context['ban_suggestions']['member']['id'] . '">' : '', '
  159. <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
  160. <input type="hidden" name="', $context['admin-bet_token_var'], '" value="', $context['admin-bet_token'], '">
  161. </div>
  162. </form>';
  163. if (!$context['ban']['is_new'] && empty($context['ban_suggestions']))
  164. {
  165. echo '
  166. <br>';
  167. template_show_list('ban_items');
  168. }
  169. echo '
  170. </div>
  171. <script><!-- // --><![CDATA[
  172. var fUpdateStatus = function ()
  173. {
  174. document.getElementById("expire_date").disabled = !document.getElementById("expires_one_day").checked;
  175. document.getElementById("cannot_post").disabled = document.getElementById("full_ban").checked;
  176. document.getElementById("cannot_register").disabled = document.getElementById("full_ban").checked;
  177. document.getElementById("cannot_login").disabled = document.getElementById("full_ban").checked;
  178. }
  179. addLoadEvent(fUpdateStatus);';
  180. // Auto suggest only needed for adding new bans, not editing
  181. if ($context['ban']['is_new'] && empty($_REQUEST['u']))
  182. echo '
  183. var oAddMemberSuggest = new smc_AutoSuggest({
  184. sSelf: \'oAddMemberSuggest\',
  185. sSessionId: smf_session_id,
  186. sSessionVar: smf_session_var,
  187. sSuggestId: \'user\',
  188. sControlId: \'user\',
  189. sSearchType: \'member\',
  190. sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
  191. bItemList: false
  192. });
  193. function onUpdateName(oAutoSuggest)
  194. {
  195. document.getElementById(\'user_check\').checked = true;
  196. return true;
  197. }
  198. oAddMemberSuggest.registerCallback(\'onBeforeUpdate\', \'onUpdateName\');';
  199. echo '
  200. function confirmBan(aForm)
  201. {
  202. if (aForm.ban_name.value == \'\')
  203. {
  204. alert(\'', $txt['ban_name_empty'], '\');
  205. return false;
  206. }
  207. if (aForm.partial_ban.checked && !(aForm.cannot_post.checked || aForm.cannot_register.checked || aForm.cannot_login.checked))
  208. {
  209. alert(\'', $txt['ban_restriction_empty'], '\');
  210. return false;
  211. }
  212. }// ]]></script>';
  213. }
  214. function template_ban_edit_trigger()
  215. {
  216. global $context, $settings, $scripturl, $txt, $modSettings;
  217. echo '
  218. <div id="manage_bans">
  219. <form id="admin_form_wrapper" action="', $context['form_url'], '" method="post" accept-charset="', $context['character_set'], '">
  220. <div class="cat_bar">
  221. <h3 class="catbg">
  222. ', $context['ban_trigger']['is_new'] ? $txt['ban_add_trigger'] : $txt['ban_edit_trigger_title'], '
  223. </h3>
  224. </div>
  225. <div class="windowbg">
  226. <div class="content">
  227. <fieldset>
  228. <legend>
  229. <input type="checkbox" onclick="invertAll(this, this.form, \'ban_suggestion\');" class="input_check"> ', $txt['ban_triggers'], '
  230. </legend>
  231. <dl class="settings">
  232. <dt>
  233. <input type="checkbox" name="ban_suggestions[]" id="main_ip_check" value="main_ip" class="input_check"', $context['ban_trigger']['ip']['selected'] ? ' checked' : '', '>
  234. <label for="main_ip_check">', $txt['ban_on_ip'], '</label>
  235. </dt>
  236. <dd>
  237. <input type="text" name="main_ip" value="', $context['ban_trigger']['ip']['value'], '" size="44" onfocus="document.getElementById(\'main_ip_check\').checked = true;" class="input_text">
  238. </dd>';
  239. if (empty($modSettings['disableHostnameLookup']))
  240. echo '
  241. <dt>
  242. <input type="checkbox" name="ban_suggestions[]" id="hostname_check" value="hostname" class="input_check"', $context['ban_trigger']['hostname']['selected'] ? ' checked' : '', '>
  243. <label for="hostname_check">', $txt['ban_on_hostname'], '</label>
  244. </dt>
  245. <dd>
  246. <input type="text" name="hostname" value="', $context['ban_trigger']['hostname']['value'], '" size="44" onfocus="document.getElementById(\'hostname_check\').checked = true;" class="input_text">
  247. </dd>';
  248. echo '
  249. <dt>
  250. <input type="checkbox" name="ban_suggestions[]" id="email_check" value="email" class="input_check"', $context['ban_trigger']['email']['selected'] ? ' checked' : '', '>
  251. <label for="email_check">', $txt['ban_on_email'], '</label>
  252. </dt>
  253. <dd>
  254. <input type="text" name="email" value="', $context['ban_trigger']['email']['value'], '" size="44" onfocus="document.getElementById(\'email_check\').checked = true;" class="input_text">
  255. </dd>
  256. <dt>
  257. <input type="checkbox" name="ban_suggestions[]" id="user_check" value="user" class="input_check"', $context['ban_trigger']['banneduser']['selected'] ? ' checked' : '', '>
  258. <label for="user_check">', $txt['ban_on_username'], '</label>:
  259. </dt>
  260. <dd>
  261. <input type="text" value="' . $context['ban_trigger']['banneduser']['value'] . '" name="user" id="user" size="44" onfocus="document.getElementById(\'user_check\').checked = true;"class="input_text">
  262. </dd>
  263. </dl>
  264. </fieldset>
  265. <input type="submit" name="', $context['ban_trigger']['is_new'] ? 'add_new_trigger' : 'edit_trigger', '" value="', $context['ban_trigger']['is_new'] ? $txt['ban_add_trigger_submit'] : $txt['ban_edit_trigger_submit'], '" class="button_submit">
  266. </div>
  267. </div>
  268. <input type="hidden" name="bi" value="' . $context['ban_trigger']['id'] . '">
  269. <input type="hidden" name="bg" value="' . $context['ban_trigger']['group'] . '">
  270. <input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '">
  271. <input type="hidden" name="', $context['admin-bet_token_var'], '" value="', $context['admin-bet_token'], '">
  272. </form>
  273. </div>
  274. <script><!-- // --><![CDATA[
  275. var oAddMemberSuggest = new smc_AutoSuggest({
  276. sSelf: \'oAddMemberSuggest\',
  277. sSessionId: smf_session_id,
  278. sSessionVar: smf_session_var,
  279. sSuggestId: \'username\',
  280. sControlId: \'user\',
  281. sSearchType: \'member\',
  282. sTextDeleteItem: \'', $txt['autosuggest_delete_item'], '\',
  283. bItemList: false
  284. });
  285. function onUpdateName(oAutoSuggest)
  286. {
  287. document.getElementById(\'user_check\').checked = true;
  288. return true;
  289. }
  290. oAddMemberSuggest.registerCallback(\'onBeforeUpdate\', \'onUpdateName\');
  291. // ]]></script>';
  292. }
  293. ?>