This repository has been archived by the owner on Jul 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SavedReports.php
347 lines (281 loc) · 7.71 KB
/
SavedReports.php
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<?php
/**
* Saved Reports (Setup)
*
* @package Reports
*/
// RosarioSIS 2.9: ajaxLink( 'Side.php' );
$reload_side = '<script>
var side_link = document.createElement("a");
side_link.href = "Side.php";
side_link.target = "menu";
ajaxLink(side_link);
</script>';
// Save New Report.
if ( $_REQUEST['modfunc'] === 'new'
&& AllowEdit() )
{
$report_id = DBGet( DBQuery( "SELECT " . db_seq_nextval( 'SAVED_REPORTS_SEQ' ) . ' AS ID' ) );
$report_id = $report_id[1]['ID'];
DBQuery( "INSERT INTO SAVED_REPORTS (ID,TITLE,STAFF_ID,PHP_SELF,SEARCH_PHP_SELF,SEARCH_VARS)
values(
'" . $report_id . "',
'" . DBEscapeString( dgettext( 'Reports', 'Untitled' ) ) . "',
'" . User( 'STAFF_ID' ) . "',
'" . PreparePHP_SELF( $_SESSION['_REQUEST_vars'] ) . "',
'" . $_SESSION['Search_PHP_SELF'] . "',
'" . /*serialize( $_SESSION['Search_vars'] ) .*/ "')" );
// FJ disable Publishing options.
$modname = 'Reports/RunReport.php&id=' . $report_id;
// Admin can Use Report.
DBQuery( "INSERT INTO PROFILE_EXCEPTIONS (PROFILE_ID,MODNAME,CAN_USE,CAN_EDIT)
values('1','" . $modname . "','Y','Y')" );
unset( $_REQUEST['modfunc'] );
unset( $_SESSION['_REQUEST_vars']['modfunc'] );
// Reload Side.php Menu.
echo $reload_side;
}
// Update Saved Report.
if ( isset( $_REQUEST['values'] )
&& isset( $_POST['values'] )
&& AllowEdit() )
{
foreach ( (array)$_REQUEST['values'] as $id => $columns )
{
$sql = "UPDATE SAVED_REPORTS SET ";
foreach ( (array)$columns as $column => $value )
{
if ( function_exists( 'DBEscapeIdentifier' ) ) // RosarioSIS 3.0+.
{
$escaped_column = DBEscapeIdentifier( $column );
}
else
{
$escaped_column = '"' . mb_strtolower( $column ) . '"';
}
$sql .= $escaped_column . "='" . $value . "',";
}
$sql = mb_substr( $sql, 0, -1 ) . " WHERE ID='" . $id . "'";
DBQuery( $sql );
}
// Reload Side.php Menu.
echo $reload_side;
}
// Add profile exceptions for the Saved Reports to appear in the menu.
if ( isset( $_REQUEST['profiles'] )
&& isset( $_POST['profiles'] )
&& AllowEdit() )
{
$profiles_RET = DBGet( DBQuery( "SELECT ID,TITLE
FROM USER_PROFILES" ) );
$reports_RET = DBGet( DBQuery( "SELECT ID
FROM SAVED_REPORTS" ) );
foreach( (array)$reports_RET as $report_id )
{
$report_id = $report_id['ID'];
$modname = 'Reports/RunReport.php&id=' . $report_id;
if ( ! isset( $exceptions_RET[ $report_id ] ) )
{
$exceptions_RET[ $report_id ] = DBGet( DBQuery( "SELECT PROFILE_ID,CAN_USE,CAN_EDIT
FROM PROFILE_EXCEPTIONS
WHERE MODNAME='" . $modname . "'"), array(), array( 'PROFILE_ID' ) );
}
foreach ( (array)$profiles_RET as $profile )
{
$profile_id = $profile['ID'];
if ( ! isset( $exceptions_RET[ $report_id ][ $profile_id ] ) )
{
DBQuery( "INSERT INTO PROFILE_EXCEPTIONS (PROFILE_ID,MODNAME)
values('" . $profile_id . "','" . $modname . "')" );
}
if ( ! $_REQUEST['profiles'][ $report_id ][ $profile_id ] )
{
DBQuery( "UPDATE PROFILE_EXCEPTIONS
SET CAN_USE='N',CAN_EDIT='N'
WHERE PROFILE_ID='" . $profile_id . "'
AND MODNAME='" . $modname . "'" );
}
else
{
DBQuery( "UPDATE PROFILE_EXCEPTIONS
SET CAN_USE='Y',CAN_EDIT='Y'
WHERE PROFILE_ID='" . $profile_id . "'
AND MODNAME='". $modname . "'" );
}
/*if ( ! $_REQUEST['profiles'][ str_replace( '.', '_', $modname ) ] )
{
$update_profile = "UPDATE PROFILE_EXCEPTIONS SET ";
if ( ! $_REQUEST['can_use'][ str_replace( '.', '_', $modname ) ] )
{
$update_profile .= "CAN_USE='N'";
}
$update_profile .= " WHERE PROFILE_ID='" . $profile_id . "'
AND MODNAME='" . $modname . "'";
DBQuery( $update_profile );
}*/
}
}
}
DrawHeader( ProgramTitle() );
// Remove Saved Report.
if ( $_REQUEST['modfunc'] === 'remove'
&& AllowEdit() )
{
if ( DeletePrompt( _( 'Saved Report' ) ) )
{
DBQuery( "DELETE FROM SAVED_REPORTS
WHERE ID='" . $_REQUEST['id'] . "'" );
$modname = 'Reports/RunReport.php&id=' . $_REQUEST['id'];
DBQuery( "DELETE FROM PROFILE_EXCEPTIONS
WHERE MODNAME='" . $modname . "'" );
unset( $_REQUEST['modfunc'] );
unset( $_SESSION['_REQUEST_vars']['modfunc'] );
// Reload Side.php Menu.
echo $reload_side;
}
}
// Display Saved Report.
if ( $_REQUEST['modfunc'] !== 'remove' )
{
$saved_reports_RET = DBGet(
DBQuery( "SELECT ID,TITLE,PHP_SELF,'' AS PUBLISHING
FROM SAVED_REPORTS
ORDER BY TITLE" ),
array(
'TITLE' => '_makeTextInput',
'PHP_SELF' => '_makeProgram',
// FJ disable Publishing options.
//'PUBLISHING' => '_makePublishing',
)
);
$columns = array(
'TITLE' => _( 'Title' ),
'PHP_SELF' => _( 'Program Title' ),
// FJ disable Publishing options.
//'PUBLISHING' => _('Publishing Options' ),
);
$link['remove']['link'] = "Modules.php?modname=". $_REQUEST['modname'] . "&modfunc=remove";
$link['remove']['variables'] = array( 'id' => 'ID' );
echo '<form action="Modules.php?modname=' . $_REQUEST['modname'] . '&modfunc=update" method="POST">';
DrawHeader( '', SubmitButton( _( 'Save' ) ) );
ListOutput( $saved_reports_RET, $columns, 'Saved Report', 'Saved Reports', $link );
echo '<div class="center">' . SubmitButton( _( 'Save' ) ) . '</div>';
echo '</form>';
}
/**
* Make Text Input
*
* Local function
*
* @global $THIS_RET Current Return value
*
* @param string $value Value.
* @param string $column 'TITLE'.
*
* @return string Text Input
*/
function _makeTextInput( $value, $column )
{
global $THIS_RET;
if ( isset( $THIS_RET['ID'] ) )
{
$id = $THIS_RET['ID'];
}
else
$id = 'new';
if ( $value === dgettext( 'Reports', 'Untitled' ) )
{
$div = false;
}
else
$div = true;
$extra = 'maxlength="100"';
$run_button = '';
if ( $id !== 'new' )
{
$run_button = '<a href="Modules.php?modname=Reports/RunReport.php&id=' . $id . '" style="float: right;" title="' . _( 'Run' ) . '">
<img src="assets/themes/' . Preferences( 'THEME' ) . '/btn/next.png" class="button" /></a>';
}
return '<div style="float:left;">' . TextInput(
$value,
'values[' . $id . '][' . $column . ']',
'',
$extra,
$div
) . '</div>' . $run_button;
}
/**
* Make Program Title
*
* Local function
*
* @param string $value Value.
* @param string $column 'PHP_SELF'.
*
* @return string ProgramTitle( $modname )
*/
function _makeProgram( $value, $column )
{
if ( strpos( $value, '&' ) )
{
$modname = mb_substr($value, 20, strpos( $value, '&' ) - 20 );
}
else
$modname = mb_substr( $value, 20 );
return ProgramTitle( $modname );
}
/**
* Make Publishing options
*
* Local function
*
* @global $THIS_RET Current Return value
*
* @param string $value Value.
* @param string $column 'PUBLISHING'.
*
* @return string Publishing options
*/
function _makePublishing( $value, $column )
{
global $THIS_RET;
static $profiles_RET = null,
$schools_RET;
if ( ! $profiles_RET )
{
$profiles_RET = DBGet( DBQuery( "SELECT ID,TITLE
FROM USER_PROFILES" ) );
}
$exceptions_RET = DBGet( DBQuery( "SELECT CAN_EDIT,CAN_USE,PROFILE_ID
FROM PROFILE_EXCEPTIONS
WHERE MODNAME='Reports/RunReport.php&id=" . $THIS_RET['ID'] . "'" ), array(), array( 'PROFILE_ID' ) );
$return = '<table class="cellspacing-0"><tr><td colspan="4"><b>' .
_( 'Profiles' ) . ': </b></td></tr>';
$i = 0;
foreach ( (array) $profiles_RET as $profile )
{
$i++;
$return .= '<td>' .
CheckboxInput(
$exceptions_RET[ $profile['ID'] ][1]['CAN_USE'],
'profiles[' . $THIS_RET['ID'] . '][' . $profile['ID'] . ']',
$profile['TITLE'],
'',
true
) .
'</td>';
if ( $i % 4 == 0
&& $i !== count( $profiles_RET ) )
{
$return .= '</tr><tr>';
}
}
for ( ; $i % 4 != 0; $i++ )
{
$return .= '<td></td>';
}
/*$return .= '</tr><tr><td colspan="2"><b><a href="#">' .
_( 'Schools' ) . ': ...</a></b></td>';*/
$return .= '</tr></table>';
return $return;
}