gruffen commited on 2011-07-07 16:15:15
Showing 4 changed files, with 390 additions and 0 deletions.
... | ... |
@@ -0,0 +1,32 @@ |
1 |
+<?php |
|
2 |
+################################################################## |
|
3 |
+# Simple Desk Project - www.simpledesk.net # |
|
4 |
+################################################################## |
|
5 |
+# An advanced help desk modifcation built on SMF # |
|
6 |
+################################################################## |
|
7 |
+# # |
|
8 |
+# * Copyright 2010 - SimpleDesk.net # |
|
9 |
+# # |
|
10 |
+# This file and its contents are subject to the license # |
|
11 |
+# included with this distribution, license.txt, which # |
|
12 |
+# states that this software is New BSD Licensed. # |
|
13 |
+# Any questions, please contact SimpleDesk.net # |
|
14 |
+# # |
|
15 |
+################################################################## |
|
16 |
+# SimpleDesk Version: 2.0 Anatidae # |
|
17 |
+# File Info: SDPluginReportToHelpdesk.english.php / 2.0 Anatidae # |
|
18 |
+################################################################## |
|
19 |
+// Version: 2.0 Anatidae; SimpleDesk staff list plugin |
|
20 |
+ |
|
21 |
+// Important! Before editing these language files please read the text at the top of index.english.php. |
|
22 |
+ |
|
23 |
+$txt['shdp_tally'] = 'Tally Custom Fields'; |
|
24 |
+$txt['shdp_tally_desc'] = 'This plugin can automatically tally up the totals of custom fields for you.'; |
|
25 |
+ |
|
26 |
+$txt['shdp_tally_totals'] = 'Totalled Values'; |
|
27 |
+ |
|
28 |
+$txt['shdp_tally_include_ticket'] = 'When totalling the values, include the value for the ticket (instead of only from replies)'; |
|
29 |
+$txt['shdp_tally_field_list'] = 'Which custom fields does this apply to?'; |
|
30 |
+$txt['shdp_tally_no_fields'] = 'You do not have any custom fields set up that can be used (only integer and floating-point fields can be used'; |
|
31 |
+ |
|
32 |
+?> |
|
0 | 33 |
\ No newline at end of file |
... | ... |
@@ -0,0 +1,19 @@ |
1 |
+<?xml version="1.0"?> |
|
2 |
+<!DOCTYPE package-info SYSTEM "http://www.simplemachines.org/xml/package-info"> |
|
3 |
+<package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/"> |
|
4 |
+ <id>SimpleDeskTeam:tally</id> |
|
5 |
+ <name>Tally</name> |
|
6 |
+ <version>1.0</version> |
|
7 |
+ <type>sdplugin</type> |
|
8 |
+ <install for="2.0"> |
|
9 |
+ <require-file name="SDPluginTally.english.php" destination="$languagedir" /> |
|
10 |
+ <require-dir name="tally" destination="$sourcedir/sd_plugins_source" /> |
|
11 |
+ |
|
12 |
+ <redirect url="?action=admin;area=helpdesk_plugins#js_feature_tally" /> |
|
13 |
+ </install> |
|
14 |
+ |
|
15 |
+ <uninstall for="2.0"> |
|
16 |
+ <remove-file name="$languagedir/SDPluginTally.english.php" /> |
|
17 |
+ <remove-dir name="$sourcedir/sd_plugins_source/tally" /> |
|
18 |
+ </uninstall> |
|
19 |
+</package-info> |
|
0 | 20 |
\ No newline at end of file |
... | ... |
@@ -0,0 +1,258 @@ |
1 |
+<?php |
|
2 |
+############################################################### |
|
3 |
+# Simple Desk Project - www.simpledesk.net # |
|
4 |
+############################################################### |
|
5 |
+# An advanced help desk modifcation built on SMF # |
|
6 |
+############################################################### |
|
7 |
+# # |
|
8 |
+# * Copyright 2010 - SimpleDesk.net # |
|
9 |
+# # |
|
10 |
+# This file and its contents are subject to the license # |
|
11 |
+# included with this distribution, license.txt, which # |
|
12 |
+# states that this software is New BSD Licensed. # |
|
13 |
+# Any questions, please contact SimpleDesk.net # |
|
14 |
+# # |
|
15 |
+############################################################### |
|
16 |
+# SimpleDesk Version: 2.0 Anatidae # |
|
17 |
+# File Info: SDPluginReportToHelpdesk.php / 2.0 Anatidae # |
|
18 |
+############################################################### |
|
19 |
+ |
|
20 |
+/** |
|
21 |
+ * This file handles tallying up custom fields. It's rather naughty because, for convenience (and performance), we invoke it during a template. |
|
22 |
+ * |
|
23 |
+ * Even more naughty, we don't bother to separate it out into a separate template. Good practice suggests we should but here, it's almost unnecessarily complicating matters. |
|
24 |
+ * |
|
25 |
+ * @package plugin |
|
26 |
+ * @since 2.0 |
|
27 |
+ */ |
|
28 |
+ |
|
29 |
+if (!defined('SMF')) |
|
30 |
+ die('Hacking attempt...'); |
|
31 |
+ |
|
32 |
+// Deal with the action |
|
33 |
+function shd_tally() |
|
34 |
+{ |
|
35 |
+ global $context, $modSettings, $smcFunc, $settings; |
|
36 |
+ |
|
37 |
+ if (!in_array('tally', $context['shd_plugins']) || empty($modSettings['shdp_tally_fields'])) |
|
38 |
+ return; |
|
39 |
+ |
|
40 |
+ // Figure out if this ticket has what we need. Only worry about tallying if the field would have appeared in this ticket page at least once (ticket or reply) |
|
41 |
+ $possible_fields = array(); |
|
42 |
+ // Gather fields from the ticket. |
|
43 |
+ foreach ($context['ticket']['custom_fields'] as $pos => $fields) |
|
44 |
+ foreach ($fields as $field_id => $field) |
|
45 |
+ $possible_fields[$field_id] = empty($field['icon']) ? $field['name'] : '<img src="' . $settings['default_images_url'] . '/simpledesk/cf/' . $field['icon'] . '" alt="" class="shd_smallicon" /> ' . $field['name']; |
|
46 |
+ |
|
47 |
+ // Gather fields from the replies. |
|
48 |
+ foreach ($context['custom_fields_replies'] as $dest => $fields) |
|
49 |
+ foreach ($fields as $field_id => $field) |
|
50 |
+ $possible_fields[$field_id] = empty($field['icon']) ? $field['name'] : '<img src="' . $settings['default_images_url'] . '/simpledesk/cf/' . $field['icon'] . '" alt="" class="shd_smallicon" /> ' . $field['name']; |
|
51 |
+ |
|
52 |
+ // Make sure we figure out what the admin selected, combined with what's available. |
|
53 |
+ if (!empty($possible_fields)) |
|
54 |
+ { |
|
55 |
+ $fields = explode(',', $modSettings['shdp_tally_fields']); |
|
56 |
+ $get_fields = array(); |
|
57 |
+ foreach ($fields as $field) |
|
58 |
+ { |
|
59 |
+ if (isset($possible_fields[$field])) |
|
60 |
+ $get_fields[] = (int) $field; |
|
61 |
+ } |
|
62 |
+ } |
|
63 |
+ |
|
64 |
+ if (empty($get_fields)) |
|
65 |
+ return; |
|
66 |
+ |
|
67 |
+ // So we have a list of fields we should be getting. First, we need to get the message ids. |
|
68 |
+ $msgs = array(); |
|
69 |
+ $query = $smcFunc['db_query']('', ' |
|
70 |
+ SELECT id_msg |
|
71 |
+ FROM {db_prefix}helpdesk_ticket_replies |
|
72 |
+ WHERE id_ticket = {int:ticket}', |
|
73 |
+ array( |
|
74 |
+ 'ticket' => $context['ticket_id'], |
|
75 |
+ ) |
|
76 |
+ ); |
|
77 |
+ while ($row = $smcFunc['db_fetch_row']($query)) |
|
78 |
+ $msgs[] = $row[0]; // Should *always* be a message in a ticket. |
|
79 |
+ $smcFunc['db_free_result']($query); |
|
80 |
+ |
|
81 |
+ $values = array(); |
|
82 |
+ $query = shd_db_query('', ' |
|
83 |
+ SELECT cfv.id_field, cfv.value, cfv.post_type, cf.field_type |
|
84 |
+ FROM {db_prefix}helpdesk_custom_fields_values AS cfv |
|
85 |
+ INNER JOIN {db_prefix}helpdesk_custom_fields AS cf ON (cfv.id_field = cf.id_field) |
|
86 |
+ WHERE ((cfv.id_post = {int:ticket} AND cfv.post_type = 1) |
|
87 |
+ OR (cfv.id_post IN ({array_int:msgs}) AND cfv.post_type = 2)) |
|
88 |
+ AND cfv.id_field IN ({array_int:fields})', |
|
89 |
+ array( |
|
90 |
+ 'ticket' => $context['ticket_id'], |
|
91 |
+ 'msgs' => $msgs, |
|
92 |
+ 'fields' => $get_fields, |
|
93 |
+ ) |
|
94 |
+ ); |
|
95 |
+ while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
96 |
+ { |
|
97 |
+ if (!isset($values[$row['id_field']])) |
|
98 |
+ $values[$row['id_field']] = 0; |
|
99 |
+ |
|
100 |
+ switch ($row['field_type']) |
|
101 |
+ { |
|
102 |
+ case CFIELD_TYPE_INT: |
|
103 |
+ if ($row['post_type'] == CFIELD_REPLY || !empty($modSettings['shdp_tally_include_ticket'])) |
|
104 |
+ $values[$row['id_field']] += (int) $row['value']; |
|
105 |
+ break; |
|
106 |
+ case CFIELD_TYPE_FLOAT: |
|
107 |
+ if ($row['post_type'] == CFIELD_REPLY || !empty($modSettings['shdp_tally_include_ticket'])) |
|
108 |
+ $values[$row['id_field']] += (float) $row['value']; |
|
109 |
+ break; |
|
110 |
+ default; |
|
111 |
+ break; |
|
112 |
+ } |
|
113 |
+ } |
|
114 |
+ $smcFunc['db_free_result']($query); |
|
115 |
+ |
|
116 |
+ if (empty($values)) |
|
117 |
+ return; |
|
118 |
+ |
|
119 |
+ $context['shdp_tally'] = array( |
|
120 |
+ 'displaying' => $get_fields, |
|
121 |
+ 'field_names' => $possible_fields, |
|
122 |
+ 'values' => $values, |
|
123 |
+ ); |
|
124 |
+ // Add it to the template list. |
|
125 |
+ array_unshift($context['leftcolumn_templates'], 'shdp_tally'); |
|
126 |
+} |
|
127 |
+ |
|
128 |
+// And now for a shocking display of not keeping things separated, the template. |
|
129 |
+function template_shdp_tally() |
|
130 |
+{ |
|
131 |
+ global $context, $txt, $settings; |
|
132 |
+ |
|
133 |
+ echo ' |
|
134 |
+ <div class="tborder"> |
|
135 |
+ <div class="title_bar grid_header"> |
|
136 |
+ <h3 class="titlebg"> |
|
137 |
+ <img src="', $settings['default_images_url'], '/simpledesk/custom_fields.png" alt="">', $txt['shdp_tally_totals'], ' |
|
138 |
+ </h3> |
|
139 |
+ </div> |
|
140 |
+ <div class="windowbg2" style="padding-top: 0.5em;"> |
|
141 |
+ <div class="information" style="margin: 0 1.2em 0 1.2em;"> |
|
142 |
+ <ul style="list-style-type: none; padding-left: 0; margin: 0;">'; |
|
143 |
+ |
|
144 |
+ foreach ($context['shdp_tally']['displaying'] as $field_id) |
|
145 |
+ { |
|
146 |
+ echo ' |
|
147 |
+ <li> |
|
148 |
+ <dl> |
|
149 |
+ <dt>', $context['shdp_tally']['field_names'][$field_id], ':</dt> |
|
150 |
+ <dd>', $context['shdp_tally']['values'][$field_id], '</dd> |
|
151 |
+ </dl> |
|
152 |
+ </li>'; |
|
153 |
+ |
|
154 |
+ }; |
|
155 |
+ |
|
156 |
+ echo ' |
|
157 |
+ </ul> |
|
158 |
+ </div> |
|
159 |
+ <span class="botslice"><span></span></span> |
|
160 |
+ </div> |
|
161 |
+ </div>'; |
|
162 |
+} |
|
163 |
+ |
|
164 |
+// Admin settings |
|
165 |
+function shdp_tally_options($return_config = false) |
|
166 |
+{ |
|
167 |
+ global $txt, $scripturl, $context, $settings, $sc, $modSettings, $smcFunc; |
|
168 |
+ |
|
169 |
+ $field_list = array(); |
|
170 |
+ $query = $smcFunc['db_query']('', ' |
|
171 |
+ SELECT id_field, icon, field_name, field_type |
|
172 |
+ FROM {db_prefix}helpdesk_custom_fields |
|
173 |
+ WHERE active = 1 |
|
174 |
+ AND field_type IN ({array_int:numeric_types}) |
|
175 |
+ ORDER BY field_order', |
|
176 |
+ array( |
|
177 |
+ 'numeric_types' => array(CFIELD_TYPE_INT, CFIELD_TYPE_FLOAT), |
|
178 |
+ ) |
|
179 |
+ ); |
|
180 |
+ while ($row = $smcFunc['db_fetch_assoc']($query)) |
|
181 |
+ $field_list[$row['id_field']] = $row; |
|
182 |
+ $smcFunc['db_free_result']($query); |
|
183 |
+ |
|
184 |
+ $context['post_url'] = $scripturl . '?action=admin;area=helpdesk_options;sa=tally;save'; |
|
185 |
+ $context['settings_title'] = $txt['shdp_tally']; |
|
186 |
+ $context['settings_icon'] = 'custom_fields.png'; |
|
187 |
+ |
|
188 |
+ if (empty($field_list)) |
|
189 |
+ $config_vars = array( |
|
190 |
+ $txt['shdp_tally_no_fields'], |
|
191 |
+ ); |
|
192 |
+ else |
|
193 |
+ { |
|
194 |
+ $config_vars = array( |
|
195 |
+ array('check', 'shdp_tally_include_ticket'), |
|
196 |
+ '', |
|
197 |
+ $txt['shdp_tally_field_list'], |
|
198 |
+ ); |
|
199 |
+ |
|
200 |
+ $selected = !empty($modSettings['shdp_tally_fields']) ? explode(',', $modSettings['shdp_tally_fields']) : array(); |
|
201 |
+ foreach ($field_list as $field_id => $field) |
|
202 |
+ { |
|
203 |
+ $string = 'shdp_tally_custom_field_' . $field_id; |
|
204 |
+ $config_vars[] = array('check', $string); |
|
205 |
+ $modSettings[$string] = in_array($field_id, $selected) ? 1 : 0; |
|
206 |
+ $txt[$string] = empty($field['icon']) ? $field['field_name'] : '<img src="' . $settings['default_images_url'] . '/simpledesk/cf/' . $field['icon'] . '" alt="" class="shd_smallicon" /> ' . $field['field_name']; |
|
207 |
+ } |
|
208 |
+ } |
|
209 |
+ |
|
210 |
+ if (isset($_GET['save']) && !empty($field_list)) |
|
211 |
+ { |
|
212 |
+ checkSession(); |
|
213 |
+ |
|
214 |
+ // We need to mangle-worzel the config values for saving, because we're not using the above. |
|
215 |
+ $fields = array(); |
|
216 |
+ foreach ($field_list as $field_id => $field) |
|
217 |
+ if (!empty($_POST['shdp_tally_custom_field_' . $field_id])) |
|
218 |
+ $fields[] = $field_id; |
|
219 |
+ |
|
220 |
+ $_POST['shdp_tally_fields'] = implode(',', $fields); |
|
221 |
+ $save_vars = array( |
|
222 |
+ array('check', 'shdp_tally_include_ticket'), |
|
223 |
+ array('text', 'shdp_tally_fields'), |
|
224 |
+ ); |
|
225 |
+ |
|
226 |
+ saveDBSettings($save_vars); |
|
227 |
+ redirectexit('action=admin;area=helpdesk_options;sa=tally'); |
|
228 |
+ } |
|
229 |
+ |
|
230 |
+ return $config_vars; |
|
231 |
+} |
|
232 |
+ |
|
233 |
+function shd_tally_adminmenu(&$admin_areas) |
|
234 |
+{ |
|
235 |
+ global $context, $modSettings, $txt; |
|
236 |
+ |
|
237 |
+ // Enabled? |
|
238 |
+ if (!in_array('tally', $context['shd_plugins'])) |
|
239 |
+ return; |
|
240 |
+ |
|
241 |
+ $admin_areas['helpdesk_info']['areas']['helpdesk_options']['subsections']['tally'] = array($txt['shdp_tally']); |
|
242 |
+} |
|
243 |
+ |
|
244 |
+function shd_tally_hdadminopts() |
|
245 |
+{ |
|
246 |
+ global $context, $modSettings, $txt; |
|
247 |
+ |
|
248 |
+ // Enabled? |
|
249 |
+ if (!in_array('tally', $context['shd_plugins'])) |
|
250 |
+ return; |
|
251 |
+ |
|
252 |
+ $context[$context['admin_menu_name']]['tab_data']['tabs']['tally'] = array( |
|
253 |
+ 'description' => $txt['shdp_tally_desc'], |
|
254 |
+ 'function' => 'shdp_tally_options', |
|
255 |
+ ); |
|
256 |
+} |
|
257 |
+ |
|
258 |
+?> |
|
0 | 259 |
\ No newline at end of file |
... | ... |
@@ -0,0 +1,81 @@ |
1 |
+<?php |
|
2 |
+########################################################### |
|
3 |
+# Simple Desk Project - www.simpledesk.net # |
|
4 |
+########################################################### |
|
5 |
+# An advanced help desk modifcation built on SMF # |
|
6 |
+########################################################### |
|
7 |
+# # |
|
8 |
+# * Copyright 2010 - SimpleDesk.net # |
|
9 |
+# # |
|
10 |
+# This file and its contents are subject to the license # |
|
11 |
+# included with this distribution, license.txt, which # |
|
12 |
+# states that this software is New BSD Licensed. # |
|
13 |
+# Any questions, please contact SimpleDesk.net # |
|
14 |
+# # |
|
15 |
+########################################################### |
|
16 |
+# SimpleDesk Version: 2.0 Anatidae # |
|
17 |
+# File Info: index.php / 2.0 Anatidae # |
|
18 |
+########################################################### |
|
19 |
+ |
|
20 |
+/** |
|
21 |
+ * @package plugin-reporttohelpdesk |
|
22 |
+ * @since 2.0 |
|
23 |
+*/ |
|
24 |
+ |
|
25 |
+if (!defined('SHD_VERSION')) |
|
26 |
+ die('Hacking attempt...'); |
|
27 |
+ |
|
28 |
+/* |
|
29 |
+ * Return information about this plugin. |
|
30 |
+ * |
|
31 |
+ * details |
|
32 |
+ * - name: a $txt reference for the plugin's name (so it can be translated), if not present as a $txt will be used as a literal. (Note, see includes - language below) |
|
33 |
+ * - description: a $txt reference one line description of the mod (translatable) - if not present, it will be used as a literal. |
|
34 |
+ * - author: Author's name, literal |
|
35 |
+ * - website: Website to link back to the author |
|
36 |
+ * - version: Plugin version |
|
37 |
+ * - compatibility: Array of supported SD version-strings |
|
38 |
+ * |
|
39 |
+ * includes |
|
40 |
+ * - source: a key-value pair array of file names to include at strategic points, key name is the point to include it on, value is a filename or array of filenames to include within the plugin's dir |
|
41 |
+ * - language: a key-value pair of array of language files to include, much like source. |
|
42 |
+ * |
|
43 |
+ * hooks |
|
44 |
+ * - key-value pair of hook name to function name or array of function names to be called at the hook point |
|
45 |
+ * |
|
46 |
+ * @since 2.0 |
|
47 |
+*/ |
|
48 |
+function shdplugin_tally() |
|
49 |
+{ |
|
50 |
+ return array( |
|
51 |
+ 'details' => array( // general plugin details |
|
52 |
+ 'title' => 'shdp_tally', |
|
53 |
+ 'description' => 'shdp_tally_desc', |
|
54 |
+ 'author' => 'Arantor', |
|
55 |
+ 'website' => 'http://innovatenotimitate.com/', |
|
56 |
+ 'version' => '1.0', |
|
57 |
+ 'compatibility' => array( |
|
58 |
+ 'SimpleDesk 2.0 Anatidae', // should tie up with the SHD_VERSION constants |
|
59 |
+ ), |
|
60 |
+ 'acp_url' => 'action=admin;area=helpdesk_options;sa=tally', |
|
61 |
+ ), |
|
62 |
+ 'includes' => array( |
|
63 |
+ 'source' => array( |
|
64 |
+ 'helpdesk' => 'SDPluginTally.php', |
|
65 |
+ 'hdadmin' => 'SDPluginTally.php', |
|
66 |
+ ), |
|
67 |
+ 'language' => array( |
|
68 |
+ 'helpdesk' => 'SDPluginTally', |
|
69 |
+ 'hdadmin' => 'SDPluginTally', |
|
70 |
+ ), |
|
71 |
+ ), |
|
72 |
+ 'hooks' => array( // what functions to call when |
|
73 |
+ 'tpl_display_lcol' => 'shd_tally', |
|
74 |
+ 'hdadminopts' => 'shd_tally_hdadminopts', |
|
75 |
+ 'adminmenu' => 'shd_tally_adminmenu', |
|
76 |
+ ), |
|
77 |
+ ); |
|
78 |
+} |
|
79 |
+ |
|
80 |
+ |
|
81 |
+?> |
|
0 | 82 |
\ No newline at end of file |
1 | 83 |