gruffen commited on 2011-05-17 01:50:21
Showing 4 changed files, with 178 additions and 0 deletions.
... | ... |
@@ -305,6 +305,15 @@ $txt['shd_ticket_move_deleted_abort'] = 'Abort, take me to the recycle bin'; |
305 | 305 |
$txt['shd_ticket_move_deleted_delete'] = 'Continue, abandon the deleted replies (do not move them into the new topic)'; |
306 | 306 |
$txt['shd_ticket_move_deleted_undelete'] = 'Continue, undelete the replies (move them into the new topic)'; |
307 | 307 |
|
308 |
+$txt['shd_ticket_move_cfs'] = 'This ticket has custom fields that may need to be moved.'; |
|
309 |
+$txt['shd_ticket_move_cfs_warn'] = 'Some of these fields may not be visible to other users. These fields are indicated with an exclamation mark.'; |
|
310 |
+$txt['shd_ticket_move_cfs_warn_user'] = 'You can see this field, other users cannot - but once it becomes part of the forum, it will become visible to everyone who can access the forum.'; |
|
311 |
+$txt['shd_ticket_move_cfs_purge'] = 'Delete the field contents'; |
|
312 |
+$txt['shd_ticket_move_cfs_embed'] = 'Keep the field and put it in the new topic'; |
|
313 |
+$txt['shd_ticket_move_cfs_user'] = 'Currently visible to regular users'; |
|
314 |
+$txt['shd_ticket_move_cfs_staff'] = 'Currently visible to staff members'; |
|
315 |
+$txt['shd_ticket_move_cfs_admin'] = 'Currently visible to administrators'; |
|
316 |
+ |
|
308 | 317 |
// Merge ticket |
309 | 318 |
$txt['shd_merge_ticket'] = 'Merge ticket'; |
310 | 319 |
$txt['shd_ticket_to_merge'] = 'Ticket to merge'; |
... | ... |
@@ -142,6 +142,118 @@ function shd_tickettotopic() |
142 | 142 |
if (empty($context['categories'])) |
143 | 143 |
fatal_lang_error('shd_moveticket_noboards', false); |
144 | 144 |
|
145 |
+ // OK, now we got to check for custom fields. In any case, we need to fetch the list of fields that might be applicable to this ticket. |
|
146 |
+ shd_load_language('SimpleDeskAdmin'); |
|
147 |
+ $context['field_types'] = array( |
|
148 |
+ CFIELD_TYPE_TEXT => array($txt['shd_admin_custom_fields_ui_text'], 'text'), |
|
149 |
+ CFIELD_TYPE_LARGETEXT => array($txt['shd_admin_custom_fields_ui_largetext'], 'largetext'), |
|
150 |
+ CFIELD_TYPE_INT => array($txt['shd_admin_custom_fields_ui_int'], 'int'), |
|
151 |
+ CFIELD_TYPE_FLOAT => array($txt['shd_admin_custom_fields_ui_float'], 'float'), |
|
152 |
+ CFIELD_TYPE_SELECT => array($txt['shd_admin_custom_fields_ui_select'], 'select'), |
|
153 |
+ CFIELD_TYPE_CHECKBOX => array($txt['shd_admin_custom_fields_ui_checkbox'], 'checkbox'), |
|
154 |
+ CFIELD_TYPE_RADIO => array($txt['shd_admin_custom_fields_ui_radio'], 'radio'), |
|
155 |
+ CFIELD_TYPE_MULTI => array($txt['shd_admin_custom_fields_ui_multi'], 'multi'), |
|
156 |
+ ); |
|
157 |
+ |
|
158 |
+ $query = $smcFunc['db_query']('', ' |
|
159 |
+ SELECT hdcf.id_field, hdcf.field_name, hdcf.field_order, hdcf.field_type, hdcf.can_see |
|
160 |
+ FROM {db_prefix}helpdesk_custom_fields_depts AS hdd |
|
161 |
+ INNER JOIN {db_prefix}helpdesk_custom_fields AS hdcf ON (hdd.id_field = hdcf.id_field) |
|
162 |
+ WHERE hdd.id_dept = {int:dept} |
|
163 |
+ AND hdcf.active = {int:active} |
|
164 |
+ ORDER BY hdcf.field_order', |
|
165 |
+ array( |
|
166 |
+ 'dept' => $dept, |
|
167 |
+ 'active' => 1, |
|
168 |
+ ) |
|
169 |
+ ); |
|
170 |
+ $context['custom_fields'] = array(); |
|
171 |
+ $is_staff = shd_allowed_to('shd_staff', $dept); |
|
172 |
+ $is_admin = shd_allowed_to('admin_helpdesk', $dept); |
|
173 |
+ while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
174 |
+ { |
|
175 |
+ list($user_see, $staff_see) = explode(',', $row['can_see']); |
|
176 |
+ $context['custom_fields'][$row['id_field']] = array( |
|
177 |
+ 'id_field' => $row['id_field'], |
|
178 |
+ 'name' => $row['field_name'], |
|
179 |
+ 'type' => $row['field_type'], |
|
180 |
+ 'visible' => array( |
|
181 |
+ 'user' => $user_see, |
|
182 |
+ 'staff' => $staff_see, |
|
183 |
+ 'admin' => true, |
|
184 |
+ ), |
|
185 |
+ 'values' => array(), |
|
186 |
+ ); |
|
187 |
+ } |
|
188 |
+ $smcFunc['db_free_result']($query); |
|
189 |
+ |
|
190 |
+ // Having got all the possible fields for this ticket, let's fetch the values for it. That way if we don't have any values for a field, we don't have to care about showing the user. |
|
191 |
+ // But first, we need all the message ids. |
|
192 |
+ $context['ticket_messages'] = array(); |
|
193 |
+ $query = $smcFunc['db_query']('', ' |
|
194 |
+ SELECT id_msg |
|
195 |
+ FROM {db_prefix}helpdesk_ticket_replies AS hdtr |
|
196 |
+ WHERE id_ticket = {int:ticket}', |
|
197 |
+ array( |
|
198 |
+ 'ticket' => $context['ticket_id'], |
|
199 |
+ ) |
|
200 |
+ ); |
|
201 |
+ while ($row = $smcFunc['db_fetch_row']($query)) |
|
202 |
+ $context['ticket_messages'][] = $row[0]; |
|
203 |
+ $smcFunc['db_free_result']($query); |
|
204 |
+ |
|
205 |
+ // Now get a reference for the field values. |
|
206 |
+ $query = shd_db_query('', ' |
|
207 |
+ SELECT cfv.id_post, cfv.id_field, cfv.post_type |
|
208 |
+ FROM {db_prefix}helpdesk_custom_fields_values AS cfv |
|
209 |
+ WHERE (cfv.id_post = {int:ticket} AND cfv.post_type = 1)' . (!empty($context['ticket_messages']) ? ' |
|
210 |
+ OR (cfv.id_post IN ({array_int:msgs}) AND cfv.post_type = 2)' : ''), |
|
211 |
+ array( |
|
212 |
+ 'ticket' => $context['ticket_id'], |
|
213 |
+ 'msgs' => $context['ticket_messages'], |
|
214 |
+ ) |
|
215 |
+ ); |
|
216 |
+ while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
217 |
+ $context['custom_fields'][$row['id_field']]['values'][$row['post_type']][$row['id_post']] = true; |
|
218 |
+ $smcFunc['db_free_result']($query); |
|
219 |
+ |
|
220 |
+ // Having now established what fields we do actually have values for, let's proceed to deal with them. |
|
221 |
+ foreach ($context['custom_fields'] as $field_id => $field) |
|
222 |
+ { |
|
223 |
+ // Didn't we have any values? If not, prune it, not interested. |
|
224 |
+ if (empty($field['values'])) |
|
225 |
+ unset($context['custom_fields'][$field_id]); |
|
226 |
+ |
|
227 |
+ // If the user is an administrator, they can always see the fields. |
|
228 |
+ if ($is_admin) |
|
229 |
+ { |
|
230 |
+ // But users might not be able to, in which case warn the user. |
|
231 |
+ if (!$field['visible']['user'] || !$field['visible']['staff']) |
|
232 |
+ { |
|
233 |
+ $context['custom_fields'][$field_id]['visible_warn'] = true; |
|
234 |
+ $context['custom_fields_warning'] = true; |
|
235 |
+ } |
|
236 |
+ } |
|
237 |
+ elseif ($is_staff) |
|
238 |
+ { |
|
239 |
+ // So they're staff. But the field might not be visible to them; they can't deal with it. |
|
240 |
+ if (!$field['visible']['staff']) |
|
241 |
+ fatal_lang_error('cannot_shd_move_ticket_topic_hidden_cfs', false); |
|
242 |
+ elseif (!$field['visible']['user']) |
|
243 |
+ { |
|
244 |
+ // Normal mortals can't see it even if this person can, so warn them. |
|
245 |
+ $context['custom_fields'][$field_id]['visible_warn'] = true; |
|
246 |
+ $context['custom_fields_warning'] = true; |
|
247 |
+ } |
|
248 |
+ } |
|
249 |
+ else |
|
250 |
+ { |
|
251 |
+ // Non staff aren't special. They should not be able to make this decision. If someone can't see it, they don't get to make the choice. |
|
252 |
+ if (!$field['visible']['user'] || !$field['visible']['staff']) |
|
253 |
+ fatal_lang_error('cannot_shd_move_ticket_topic_hidden_cfs', false); |
|
254 |
+ } |
|
255 |
+ } |
|
256 |
+ |
|
145 | 257 |
// Store the ticket subject for the template |
146 | 258 |
$context['ticket_subject'] = $subject; |
147 | 259 |
|
... | ... |
@@ -118,6 +118,63 @@ function template_shd_tickettotopic() |
118 | 118 |
</fieldset>'; |
119 | 119 |
} |
120 | 120 |
|
121 |
+ if (!empty($context['custom_fields'])) |
|
122 |
+ { |
|
123 |
+ echo ' |
|
124 |
+ <br /> |
|
125 |
+ <fieldset id="custom_fields"> |
|
126 |
+ <dl class="settings"> |
|
127 |
+ <dt> |
|
128 |
+ <strong>', $txt['shd_ticket_move_cfs'], '</strong>'; |
|
129 |
+ if (!empty($context['custom_fields_warning'])) |
|
130 |
+ echo ' |
|
131 |
+ <div class="error">', $txt['shd_ticket_move_cfs_warn'], '</div>'; |
|
132 |
+ |
|
133 |
+ echo ' |
|
134 |
+ </dt> |
|
135 |
+ <br />'; |
|
136 |
+ |
|
137 |
+ foreach ($context['custom_fields'] as $field) |
|
138 |
+ { |
|
139 |
+ echo ' |
|
140 |
+ <dt>'; |
|
141 |
+ |
|
142 |
+ if (!empty($field['visible_warn'])) |
|
143 |
+ echo ' |
|
144 |
+ <img src="' . $settings['default_images_url'] . '/simpledesk/warning.png" alt="', $txt['shd_ticket_move_cfs_warn_user'], '" title="', $txt['shd_ticket_move_cfs_warn_user'], '" />'; |
|
145 |
+ else |
|
146 |
+ echo ' |
|
147 |
+ <img src="' . $settings['default_images_url'] . '/simpledesk/perm_yes.png" />'; |
|
148 |
+ |
|
149 |
+ echo ' |
|
150 |
+ <img src="', $settings['default_images_url'], '/simpledesk/cf_ui_', $context['field_types'][$field['type']][1], '.png" class="icon" alt="', $context['field_types'][$field['type']][0], '" title="', $context['field_types'][$field['type']][0], '" />', $field['name']; |
|
151 |
+ |
|
152 |
+ foreach ($field['visible'] as $group => $visible) |
|
153 |
+ { |
|
154 |
+ if (!$visible) |
|
155 |
+ continue; |
|
156 |
+ |
|
157 |
+ echo ' |
|
158 |
+ <img src="' . $settings['default_images_url'] . '/simpledesk/', $group, '.png" alt="', $txt['shd_ticket_move_cfs_' . $group], '" title="', $txt['shd_ticket_move_cfs_' . $group], '" style="margin-right:0px;" />'; |
|
159 |
+ |
|
160 |
+ } |
|
161 |
+ |
|
162 |
+ echo ' |
|
163 |
+ </dt> |
|
164 |
+ <dd> |
|
165 |
+ <select name="field', $field['id_field'], '"> |
|
166 |
+ <option value="keep">', $txt['shd_ticket_move_cfs_embed'], '</option> |
|
167 |
+ <option value="lose">', $txt['shd_ticket_move_cfs_purge'], '</option> |
|
168 |
+ </select> |
|
169 |
+ </dd>'; |
|
170 |
+ } |
|
171 |
+ |
|
172 |
+ echo ' |
|
173 |
+ </dd> |
|
174 |
+ </dl> |
|
175 |
+ </fieldset>'; |
|
176 |
+ } |
|
177 |
+ |
|
121 | 178 |
echo ' |
122 | 179 |
<input type="submit" value="', $txt['shd_move_ticket'], '" onclick="return submitThisOnce(this);" accesskey="s" class="button_submit" /> |
123 | 180 |
<input type="submit" name="cancel" value="', $txt['shd_cancel_ticket'], '" accesskey="c" class="button_submit" /> |
124 | 181 |