|
4 | 4 | # Copyright (c) 2012 - 2021 MantisBT Team - [email protected] |
5 | 5 | # Licensed under the MIT license |
6 | 6 |
|
7 | | -form_security_validate("plugin_Snippets_list_action"); |
| 7 | +form_security_validate( "plugin_Snippets_list_action" ); |
8 | 8 |
|
9 | | -$global = gpc_get_bool("global"); |
| 9 | +$global = gpc_get_bool( "global" ); |
10 | 10 |
|
11 | | -if ($global) { |
12 | | - access_ensure_global_level(plugin_config_get("edit_global_threshold")); |
| 11 | +if( $global ) { |
| 12 | + access_ensure_global_level( plugin_config_get( "edit_global_threshold" ) ); |
13 | 13 | $user_id = 0; |
14 | | -} else { |
15 | | - access_ensure_global_level(plugin_config_get("edit_own_threshold")); |
| 14 | +} |
| 15 | +else { |
| 16 | + access_ensure_global_level( plugin_config_get( "edit_own_threshold" ) ); |
16 | 17 | $user_id = auth_get_current_user_id(); |
17 | 18 | } |
18 | 19 |
|
19 | | -$action = gpc_get_string("action"); |
| 20 | +$action = gpc_get_string( "action" ); |
| 21 | +$snippet_list = gpc_get_int_array( "snippet_list", array() ); |
20 | 22 |
|
21 | | -$snippet_list = gpc_get_int_array("snippet_list", array()); |
| 23 | +$t_redirect_page = plugin_page( "snippet_list", true ) . Snippet::global_url( $global ); |
22 | 24 |
|
23 | | -if (count($snippet_list) < 1) { |
24 | | - form_security_purge("plugin_Snippets_list_action"); |
| 25 | +if( count( $snippet_list ) < 1 ) { |
| 26 | + form_security_purge( "plugin_Snippets_list_action" ); |
25 | 27 | helper_ensure_confirmed( |
26 | 28 | plugin_lang_get( 'action_nothing_to_do' ), |
27 | 29 | lang_get( 'ok' ) |
28 | 30 | ); |
29 | | - print_header_redirect(plugin_page("snippet_list", true) . Snippet::global_url($global)); |
| 31 | + print_header_redirect( $t_redirect_page ); |
30 | 32 | } |
31 | 33 |
|
32 | | -$snippets = Snippet::load_by_id($snippet_list, $user_id); |
33 | | - |
34 | | -function array_object_properties($arr, $prop) { |
35 | | - $props = array(); |
36 | | - foreach($arr as $key => $obj) { |
37 | | - $props[$key] = $obj->$prop; |
38 | | - } |
39 | | - return $props; |
40 | | -} |
| 34 | +$snippets = Snippet::load_by_id( $snippet_list, $user_id ); |
| 35 | +$single = count( $snippets ) == 1; |
41 | 36 |
|
42 | 37 | ### DELETE |
43 | | -if ($action == "delete") { |
44 | | - $snippet_names = array_object_properties(Snippet::clean($snippets), "name"); |
| 38 | +if( $action == "delete" ) { |
| 39 | + $snippet_names = array_column( Snippet::clean( $snippets ), 'name' ); |
45 | 40 | helper_ensure_confirmed( |
46 | | - plugin_lang_get("action_delete_confirm") |
| 41 | + plugin_lang_get( "action_delete_confirm" ) |
47 | 42 | . "<br>" . implode( ", ", $snippet_names ), |
48 | | - plugin_lang_get("action_delete") |
| 43 | + plugin_lang_get( "action_delete" ) |
49 | 44 | ); |
50 | | - Snippet::delete_by_id(array_keys($snippets), $user_id); |
| 45 | + Snippet::delete_by_id( array_keys( $snippets ), $user_id ); |
51 | 46 |
|
52 | | - form_security_purge("plugin_Snippets_list_action"); |
53 | | - print_successful_redirect(plugin_page("snippet_list", true) . Snippet::global_url($global)); |
| 47 | + form_security_purge( "plugin_Snippets_list_action" ); |
| 48 | + print_successful_redirect( $t_redirect_page ); |
54 | 49 |
|
55 | 50 | ### EDIT |
56 | | -} elseif ($action == "edit") { |
57 | | - $snippets = Snippet::clean($snippets, Snippet::TARGET_FORM); |
| 51 | +} elseif( $action == "edit" ) { |
| 52 | + $snippets = Snippet::clean( $snippets, Snippet::TARGET_FORM ); |
58 | 53 | layout_page_header(); |
59 | 54 | layout_page_begin(); |
60 | | -?> |
61 | | - |
62 | | -<br/> |
63 | 55 |
|
64 | | -<div id="snippet-div" class="form-container"> |
65 | | - <form action="<?php echo plugin_page( 'snippet_list_action' ) ?>" method="post"> |
66 | | - <?php echo form_security_field("plugin_Snippets_list_action") ?> |
67 | | - <?php if ($global): ?><input type="hidden" name="global" value="true"/><?php endif ?> |
68 | | - <input type="hidden" name="action" value="update"/> |
69 | | - |
70 | | -<div class="widget-box widget-color-blue2"> |
71 | | - <div class="widget-header widget-header-small"> |
72 | | - <h4 class="widget-title lighter"> |
73 | | - <i class="ace-icon fa fa-user"></i> |
74 | | - <?php echo plugin_lang_get( $global ? 'edit_global_title' : 'edit_title' ) ?> |
75 | | - </h4> |
76 | | - </div> |
77 | | - <div class="widget-body"> |
78 | | - <div class="widget-main no-padding"> |
79 | | - <div class="table-responsive"> |
80 | | - <table class="table table-bordered table-condensed table-striped"> |
| 56 | + $t_page_name = basename( __FILE__, '.php' ); |
| 57 | + print_account_menu( $t_page_name ); |
| 58 | +?> |
81 | 59 |
|
82 | | - <fieldset> |
| 60 | +<div class="col-md-12 col-xs-12"> |
| 61 | + <div class="space-10"></div> |
83 | 62 |
|
| 63 | + <div id="snippet-div" class="form-container"> |
| 64 | + <form action="<?php echo plugin_page( 'snippet_list_action' ) ?>" |
| 65 | + method="post"> |
| 66 | + <?php echo form_security_field( "plugin_Snippets_list_action" ) ?> |
| 67 | + <input type="hidden" name="action" value="update"/> |
84 | 68 | <?php |
85 | | - $first = true; |
86 | | - $single = count( $snippets ) == 1; |
87 | | - |
88 | | - foreach( $snippets as $snippet ) { |
89 | | - if ( !$first ) { |
| 69 | + if( $global ) { |
90 | 70 | ?> |
91 | | -<tr class="spacer"><td></td></tr> |
| 71 | + <input type="hidden" name="global" value="true"/> |
92 | 72 | <?php |
93 | | - } |
| 73 | + } |
94 | 74 | ?> |
95 | 75 |
|
96 | | -<tr> |
| 76 | + <div class="widget-box widget-color-blue2"> |
| 77 | + <div class="widget-header widget-header-small"> |
| 78 | + <h4 class="widget-title lighter"> |
| 79 | + <i class="ace-icon fa fa-file-o"></i> |
| 80 | + <?php echo plugin_lang_get( $global ? 'edit_global_title' : 'edit_title' ) ?> |
| 81 | + </h4> |
| 82 | + </div> |
| 83 | + <div class="widget-body"> |
| 84 | + <div class="widget-main no-padding table-responsive"> |
| 85 | + <table class="table table-bordered table-condensed table-striped"> |
| 86 | +<?php |
| 87 | + foreach( $snippets as $snippet ) { |
| 88 | +?> |
| 89 | + <tr> |
97 | 90 | <?php |
98 | 91 | # Hide checkbox when operating on a single Snippet |
99 | 92 | if( !$single ) { |
100 | 93 | ?> |
101 | | -<td class="center" rowspan="2"> |
102 | | - <!--suppress HtmlFormInputWithoutLabel --> |
103 | | - <input type="checkbox" name="snippet_list[]" value="<?php echo $snippet->id ?>" checked="checked"/> |
104 | | -</td> |
| 94 | + <td class="category center" |
| 95 | + rowspan="2"> |
| 96 | + <!--suppress HtmlFormInputWithoutLabel --> |
| 97 | + <input type="checkbox" |
| 98 | + name="snippet_list[]" |
| 99 | + class="ace" |
| 100 | + value="<?php echo $snippet->id ?>" |
| 101 | + checked="checked" |
| 102 | + /> |
| 103 | + <span class="lbl"></span> |
| 104 | + </td> |
105 | 105 | <?php |
106 | 106 | } |
107 | 107 | ?> |
108 | | -<td class="category"> |
| 108 | + <th> |
109 | 109 | <?php |
110 | 110 | # Add hidden field with Snippet id |
111 | 111 | if( $single ) { |
112 | 112 | ?> |
113 | | -<input type="hidden" name="snippet_list[]" value="<?php echo $snippet->id ?>" checked="checked"/> |
| 113 | + <input type="hidden" |
| 114 | + name="snippet_list[]" |
| 115 | + value="<?php echo $snippet->id ?>" |
| 116 | + checked="checked" |
| 117 | + /> |
114 | 118 | <?php |
115 | 119 | } |
116 | | - echo plugin_lang_get("edit_name") |
| 120 | + echo plugin_lang_get( "edit_name" ); |
| 121 | + $t_textarea = 'value_' . $snippet->id; |
117 | 122 | ?> |
118 | | -</td> |
119 | | -<td> |
120 | | - <!--suppress HtmlFormInputWithoutLabel --> |
121 | | - <input type="text" name="name_<?php echo $snippet->id ?>" size="40" value="<?php echo $snippet->name ?>"/> |
122 | | -</td> |
123 | | -</tr> |
124 | | - |
125 | | -<tr> |
126 | | - <td class="category"> |
127 | | - <label for="value_<?php echo $snippet->id ?>"> |
128 | | - <?php echo plugin_lang_get("edit_value") ?> |
129 | | - </label> |
130 | | - </td> |
131 | | - <td class="snippetspatternhelp"> |
132 | | - <textarea id="value_<?php echo $snippet->id ?>" name="value_<?php echo $snippet->id ?>" |
133 | | - cols="80" rows="6"><?php echo $snippet->value ?></textarea> |
134 | | - </td> |
135 | | -</tr> |
| 123 | + </th> |
| 124 | + <td> |
| 125 | + <!--suppress HtmlFormInputWithoutLabel --> |
| 126 | + <input type="text" |
| 127 | + name="name_<?php echo $snippet->id ?>" |
| 128 | + size="40" |
| 129 | + value="<?php echo $snippet->name ?>" |
| 130 | + /> |
| 131 | + </td> |
| 132 | + </tr> |
| 133 | + |
| 134 | + <tr> |
| 135 | + <th> |
| 136 | + <label for="<?php echo $t_textarea; ?>"> |
| 137 | + <?php echo plugin_lang_get( "edit_value" |
| 138 | + ) ?> |
| 139 | + </label> |
| 140 | + </th> |
| 141 | + <td class="snippetspatternhelp"> |
| 142 | + <textarea id="<?php echo $t_textarea; ?>" |
| 143 | + name="<?php echo $t_textarea; ?>" |
| 144 | + cols="80" |
| 145 | + rows="6"><?php echo $snippet->value ?></textarea> |
| 146 | + </td> |
| 147 | + </tr> |
136 | 148 |
|
137 | 149 | <?php |
138 | | - $first = false; |
139 | | - } |
| 150 | + # Add a spacer if processing more than one Snippet |
| 151 | + if( !$single ) { |
| 152 | +?> |
| 153 | + <tr class="spacer"><td></td></tr> |
| 154 | + <tr></tr> |
| 155 | +<?php |
| 156 | + } |
| 157 | + } # foreach |
140 | 158 | ?> |
141 | 159 |
|
142 | | -<tfoot> |
143 | | -<tr> |
144 | | -<td class="center" colspan="3"><input type="submit" value="<?php echo plugin_lang_get("action_edit") ?>"/></td> |
145 | | -</tr> |
146 | | -</tfoot> |
| 160 | + </table> |
| 161 | + </div> |
| 162 | + |
| 163 | + <div class="widget-toolbox padding-8 clearfix"> |
| 164 | + <button type="submit" |
| 165 | + class="btn btn-primary btn-white btn-round"> |
| 166 | + <?php echo plugin_lang_get( "action_update" ) ?> |
| 167 | + </button> |
| 168 | + </div> |
| 169 | + </div> |
| 170 | + </div> |
| 171 | + </form> |
| 172 | + </div> |
147 | 173 |
|
148 | | - </fieldset> |
149 | | -</table> |
150 | | -</form> |
151 | 174 | </div> |
152 | 175 |
|
153 | 176 | <?php |
154 | 177 | layout_page_end(); |
155 | 178 |
|
156 | 179 | ### UPDATE |
157 | | -} elseif ($action == "update") { |
158 | | - foreach($snippets as $snippet_id => $snippet) { |
159 | | - $new_name = gpc_get_string("name_{$snippet_id}"); |
160 | | - $new_value = gpc_get_string("value_{$snippet_id}"); |
161 | | - |
162 | | - if ($snippet->name != $new_name |
163 | | - || $snippet->value != $new_value) |
164 | | - { |
165 | | - if (!is_blank($new_name)) { |
| 180 | +} elseif( $action == "update" ) { |
| 181 | + foreach( $snippets as $snippet_id => $snippet ) { |
| 182 | + $new_name = gpc_get_string( "name_$snippet_id" ); |
| 183 | + $new_value = gpc_get_string( "value_$snippet_id" ); |
| 184 | + |
| 185 | + if( $snippet->name != $new_name || $snippet->value != $new_value ) { |
| 186 | + if( !is_blank( $new_name ) ) { |
166 | 187 | $snippet->name = $new_name; |
167 | 188 | } |
168 | | - if (!is_blank($new_value)) { |
| 189 | + if( !is_blank( $new_value ) ) { |
169 | 190 | $snippet->value = $new_value; |
170 | 191 | } |
171 | 192 |
|
172 | 193 | $snippet->save(); |
173 | 194 | } |
174 | 195 | } |
175 | 196 |
|
176 | | - form_security_purge("plugin_Snippets_list_action"); |
177 | | - print_successful_redirect(plugin_page("snippet_list", true) . Snippet::global_url($global)); |
178 | | - |
| 197 | + form_security_purge( "plugin_Snippets_list_action" ); |
| 198 | + print_successful_redirect( $t_redirect_page ); |
179 | 199 | } |
0 commit comments