-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcasetracker_console_report.module
306 lines (293 loc) · 13.1 KB
/
casetracker_console_report.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<?php
include_once('casetracker_console_report.features.inc');
/**
* Implements hook_form_alter(
*/
function casetracker_console_report_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'spaces_features_form') {
//Load default values from database
$space = spaces_get_space();
$values = $space->controllers->variable->values['space'];
// Alter current form
$form['casetracker_report'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#title' => t('Report Settings'),
);
$form['casetracker_report']['page_settings'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Page Settings'),
);
$form['casetracker_report']['page_settings']['default_page_format'] = array(
'#type' => 'select',
'#title' => t('Default Page Format'),
'#required' => TRUE,
'#options' => views_pdf_get_page_formats(),
'#description' => t('This is the default page format. If you specifiy a different format in the template section, this settings will be override.'),
'#default_value' => isset($values['default_page_format']) ? $values['default_page_format'] : 'LETTER',
);
$form['casetracker_report']['page_settings']['default_page_format_custom'] = array(
'#type' => 'textfield',
'#title' => t('Custom Page Format'),
'#description' => t('Here you can specifiy a custom page format. The schema is "[width]x[height]".'),
'#default_value' => isset($values['default_page_format_custom']) ? $values['default_page_format_custom'] : '',
);
$form['casetracker_report']['page_settings']['default_page_orientation'] = array(
'#type' => 'radios',
'#title' => t('Default Page Orientation'),
'#required' => TRUE,
'#options' => array('P' => t('Portrait'), 'L' => t('Landscape')),
'#description' => t('This is the default page orientation.'),
'#default_value' => isset($values['default_page_orientation']) ? $values['default_page_orientation'] : 'P',
);
$form['casetracker_report']['page_settings']['unit'] = array(
'#type' => 'select',
'#title' => t('Unit'),
'#required' => TRUE,
'#options' => array('mm' => t('mm: Millimeter'), 'pt' => t('pt: Point'), 'cm' => t('cm: Centimeter'), 'in' => t('in: Inch')),
'#description' => t('This is the unit for the entered unit data. If you change this option all defined units were changed, but not converted.'),
'#default_value' => isset($values['unit']) ? $values['unit'] : 'mm',
);
$form['casetracker_report']['page_settings']['margin_left'] = array(
'#type' => 'textfield',
'#title' => t('Margin: Left'),
'#required' => TRUE,
'#default_value' => isset($values['margin_left']) ? $values['margin_left'] : '0',
);
$form['casetracker_report']['page_settings']['margin_right'] = array(
'#type' => 'textfield',
'#title' => t('Margin: Right'),
'#required' => TRUE,
'#default_value' => isset($values['margin_right']) ? $values['margin_right'] : '0',
);
$form['casetracker_report']['page_settings']['margin_top'] = array(
'#type' => 'textfield',
'#title' => t('Margin: Top'),
'#required' => TRUE,
'#default_value' => isset($values['margin_top']) ? $values['margin_top'] : '0',
);
$form['casetracker_report']['page_settings']['margin_bottom'] = array(
'#type' => 'textfield',
'#title' => t('Margin: Bottom'),
'#required' => TRUE,
'#default_value' => isset($values['margin_bottom']) ? $values['margin_bottom'] : '0',
);
$fonts = views_pdf_get_font_list();
$font_styles = array(
'b' => t('Bold'),
'i' => t('Italic'),
'u' => t('Underline'),
'd' => t('Line through'),
'o' => t('Overline')
);
$align = array(
'L' => t('Left'),
'C' => t('Center'),
'R' => t('Right'),
'J' => t('Justify'),
);
$hyphenate = array(
'none' => t('None'),
'auto' => t('Detect automatically'),
);
$hyphenate = array_merge($hyphenate, views_pdf_get_hyphenations());
$form['casetracker_report']['font'] = array(
'#title' => t('PDF Default Font Options'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => t('Here you specify a the default font settings for the document.'),
);
$form['casetracker_report']['font']['default_font_size'] = array(
'#type' => 'textfield',
'#title' => t('Font Size'),
'#size' => 10,
'#default_value' => isset($values['default_font_size']) ? $values['default_font_size'] : '11',
);
$form['casetracker_report']['font']['default_font_family'] = array(
'#type' => 'select',
'#title' => t('Font Family'),
'#options' => $fonts,
'#size' => 5,
'#default_value' => isset($values['default_font_family']) ? $values['default_font_family'] : '',
);
$form['casetracker_report']['font']['default_font_style'] = array(
'#type' => 'checkboxes',
'#title' => t('Font Style'),
'#options' => $font_styles,
'#default_value' => $values['default_font_style'],
);
$form['casetracker_report']['font']['default_text_align'] = array(
'#type' => 'radios',
'#title' => t('Text Alignment'),
'#options' => $align,
'#default_value' => $values['default_text_align'],
);
$form['casetracker_report']['font']['default_text_hyphenate'] = array(
'#type' => 'select',
'#title' => t('Text Hyphenation'),
'#options' => $hyphenate,
'#description' => t('If you want to use hyphenation, then you need to download from <a href="@url">ctan.org</a> your needed pattern set. Then upload it to the dir "hyphenate_patterns" in the TCPDF lib directory. Perhaps you need to create the dir first. If you select the automated detection, then we try to get the language of the current node and select an appropriate hyphenation pattern.', array('@url' => 'http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/tex')),
'#default_value' => isset($values['default_text_hyphenate']) ? $values['default_text_hyphenate'] : 'none',
);
$form['casetracker_report']['font']['default_font_color'] = array(
'#type' => 'textfield',
'#title' => t('Text Color'),
'#description' => t('If a value is entered without a comma, it will be interpreted as a hexadecimal RGB color. Normal RGB can be used by separating the components by a comma. e.g 255,255,255 for white. A CMYK color can be entered in the same way as RGB. e.g. 0,100,0,0 for magenta.'),
'#size' => 20,
'#default_value' => isset($values['default_font_color']) ? $values['default_font_color'] : '000000',
);
$form['casetracker_report']['template_settings'] = array(
'#title' => t('PDF Templates'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$templates = array_merge(array(t(' -- None -- ')), views_pdf_get_pdf_templates());
$form['casetracker_report']['template_settings']['leading_template'] = array(
'#type' => 'select',
'#options' => $templates,
'#title' => t('Leading PDF Template'),
'#required' => FALSE,
'#description' => t('Here you specify a PDF file to be printed in front of every row.'),
'#default_value' => isset($values['leading_template']) ? $values['leading_template'] : '',
);
$form['casetracker_report']['template_settings']['template'] = array(
'#type' => 'select',
'#options' => $templates,
'#title' => t('Template PDF'),
'#description' => t('Here you specify a PDF file on which the content is printed. The first page of this document is used for the first page, in the target document. The second page is used for the second page in the target document and so on. If the target document has more that this template file, the last page of the template will be repeated. The leading document has no effect on the order of the pages.'),
'#default_value' => isset($values['template']) ? $values['template'] : '',
);
$form['casetracker_report']['template_settings']['succeed_template'] = array(
'#type' => 'select',
'#options' => $templates,
'#title' => t('Succeed PDF Template'),
'#required' => FALSE,
'#description' => t('Here you specify a PDF file to be printed after the main content.'),
'#default_value' => isset($values['succeed_template']) ? $values['succeed_template'] : '',
);
$form['casetracker_report']['template_settings']['template_file'] = array(
'#type' => 'file',
'#title' => t('Upload New Template File'),
);
// Finally add our custom submit handler to upload pdf files
$form['#submit'][] = 'casetracker_console_report_upload_template';
}
}
/**
* Helper function to upload template to templates dir
*/
function casetracker_console_report_upload_template($form, &$form_state) {
// Save new file:
// Note: The jQuery update is required to use Ajax for file upload. With
// default Drupal jQuery it will not work.
// For upload with Ajax a iFrame is open and upload in it, because
// normal forms are not allowed to handle directly.
$files_path = file_directory_path();
$template_dir = variable_get('views_pdf_template_path', 'views_pdf_templates');
$dir = $files_path . '/' . $template_dir;
if (!is_dir($dir)) {
@mkdir($dir);
@chmod($dir, 0775);
}
if (is_writable($dir)) {
$template_path = file_create_path($dir);
$file = file_save_upload('template_file', array(), $template_path);
}
}
/**
* Implement hook_views_pre_render()
**/
function casetracker_console_report_views_pre_render(&$view) {
if ($view->name != 'casetracker_console' && !($view->name == 'casetracker_cases' && automodal_request_is_child())) {
return;
}
switch ($view->current_display) {
case 'page_1':
/**
* Add print button for report
*/
$link = 'casetracker/console/report';
$legend = t('Print Report');
drupal_add_css(drupal_get_path('module', 'casetracker_console_report'). '/css/buttons.css');
if (automodal_request_is_child()) {
$link = 'casetracker/filter/report';
$legend = t('Detailed Report');
}
// Handle exposed filters
$exclude = array('q', 'automodal', 'automodalClose');
foreach ($_GET as $key => $value) {
if (!in_array($key, $exclude)) {
// Special case for date filter
if ($key == 'field_due_date_value' && $value) {
$filter['field_due_date_value[value][date]'] = is_array($value['value']) ? $value['value']['date'] : $value['value'];
}
else {
$filter[$key] = $value;
}
}
}
$view->attachment_before = '<div class="print_button">'. l($legend, $link, array('query' => $filter)) .'</div>';
break;
case 'pdf_1':
// Add new row for set header
break;
}
}
/**
* Implement hook_views_pre_execute()
*/
function casetracker_console_report_views_pre_view(&$view, &$display_id, &$args) {
if ($view->name != 'casetracker_console_report' && $view->name != 'casetracker_cases_report') {
return;
}
if ($display_id == 'pdf_1') {
// Set custom options from space
$space = spaces_get_space();
$config = $space->controllers->variable->values['space'];
$exclude = array('spaces_preset_og', 'spaces_features', 'site_frontpage_path', 'designkit_image', 'designkit_color', 'path', 'style_plugin', 'style_options', 'defaults');
foreach ($view->display['pdf_1']->display_options as $key => $value) {
if (!in_array($key, $exclude)) {
$view->display_handler->set_option($key, $config[$key]);
}
}
}
}
/**
* Implementation of hook_views_default_views_alter().
*/
function casetracker_console_report_views_default_views_alter(&$views) {
if (module_exists('atrium_casetracker')) {
_casetracker_console_spaces_filter($views['casetracker_console_report']);
_casetracker_console_spaces_access($views['casetracker_console_report']);
}
if (is_array($views['casetracker_console_report']->display['default']->display_options['fields']))
$total = array_pop($views['casetracker_console_report']->display['default']->display_options['fields']);
$statuses = casetracker_realm_load('status');
$increment = 0;
foreach ($statuses as $status => $label) {
_casetracker_console_add_column($status, $label, ++$increment, $views['casetracker_console_report']);
}
$total_id = 'case_count_filter_' . ++$increment;
$total['id'] = $total_id;
$views['casetracker_console_report']->display['default']->display_options['fields'][$total_id] = $total;
}
/**
* Implements hook_views_query_alter()
*/
function casetracker_console_report_views_query_alter(&$view, &$query) {
if ($view->name != 'casetracker_console_report')
return;
// Unset filters others than Case Tracker project, node published & spaces
// from $query object to prevent get empty results on view
$keys = array('0');
foreach ($query->where as $key => $value) {
if (!in_array($key, $keys)) {
$query->where_date = $query->where[$key];
unset($query->where[$key]);
}
}
}