4 * This page will handle the form submission from edit_report.php
5 * and either add, update or delete a report.
8 * report_id (optional) - the report id of the report to edit.
9 * If blank, user is adding a new report.
10 * public (optional) - If set to '1' and user is an admin user,
11 * then we are creating a report for the public user.
15 * include_header (Y or N)
21 * action (if 'delete' button pressed)
27 * Same as in edit_report.php...
28 * If system setting $reports_enabled is set to anything other than
29 * 'Y', then don't allow access to this page.
30 * If $allow_view_other is 'N', then do not allow selection of
32 * Can only delete/edit an event if you are the creator of the event
33 * or you are an admin user.
35 include_once $gfplugins.'webcalendar/www/includes/init.php';
36 load_user_categories ();
39 $report_id = getIntValue ( "report_id", true );
41 if ( empty ( $reports_enabled ) || $reports_enabled != 'Y' ) {
42 $error = translate ( "You are not authorized" ) . ".";
45 $updating_public = false;
46 if ( $is_admin && ! empty ( $public ) && $public_access == "Y" ) {
47 $updating_public = true;
50 if ( $single_user == 'Y' || $disable_participants_field == 'Y' ) {
57 $adding_report = ( empty ( $report_id ) || $report_id <= 0 );
60 // Can only edit/delete if you created the event or your are an admin.
61 if ( empty ( $error ) && $single_user != 'N' && ! empty ( $report_id ) &&
62 $report_id > 0 && ! $is_admin ) {
63 $res = dbi_query ( "SELECT cal_login FROM webcal_report " .
64 "WHERE report_id = $report_id" );
66 if ( $row = dbi_fetch_row ( $res ) ) {
67 if ( $row[0] != $login ) {
68 $error = translate("You are not authorized");
71 $error = "No such report id";
73 dbi_free_result ( $res );
75 $error = translate("Database error" ) . ": " . dbi_error ();
79 // Validate templates to make sure the required variables are found.
80 // Page template must include ${days}
81 if ( empty ( $error ) ) {
82 if ( ! strstr ( $page_template, '${days}' ) ) {
83 $error = "<p>" . translate ( "Error" ) . " [" .
84 translate ( "Page template" ) . "]: " .
85 str_replace ( " N ", ' <tt>${days}</tt> ',
86 translate ( "Variable N not found" ) ) .
89 // Day template must include ${events}
90 if ( ! strstr ( $day_template, '${events}' ) ) {
91 if ( ! empty ( $error ) )
93 $error .= "<p>" . translate ( "Error" ) . " [" .
94 translate ( "Day template" ) . "]: " .
95 str_replace ( " N ", ' <tt>${events}</tt> ',
96 translate ( "Variable N not found" ) ) .
99 // Event template must include ${name}
100 if ( ! strstr ( $event_template, '${name}' ) ) {
101 if ( ! empty ( $error ) )
103 $error .= "<p>" . translate ( "Error" ) . " [" .
104 translate ( "Event template" ) . "]: " .
105 str_replace ( " N ", ' <tt>${name}</tt> ',
106 translate ( "Variable N not found" ) ) .
111 if ( empty ( $error ) && ! empty ( $report_id ) &&
112 ( $action == "Delete" || $action == translate ( "Delete" ) ) ) {
113 if ( ! dbi_query ( "DELETE FROM webcal_report_template " .
114 "WHERE cal_report_id = $report_id" ) )
115 $error = translate("Database error") . ": " . dbi_error ();
116 if ( empty ( $error ) &
117 ! dbi_query ( "DELETE FROM webcal_report " .
118 "WHERE cal_report_id = $report_id" ) )
119 $error = translate("Database error") . ": " . dbi_error ();
120 // send back to main report listing page
121 if ( empty ( $error ) )
122 do_redirect ( "report.php" );
125 if ( empty ( $error ) ) {
129 $names[] = "cal_login";
130 $values[] = ( $updating_public ? "'__public__'" : "'$login'" );
132 $names[] .= "cal_update_date";
133 $values[] = date ( "Ymd" );
135 $names[] = "cal_report_type";
136 $values[] = "'html'";
138 $names[] = "cal_report_name";
139 if ( empty ( $report_name ) || trim ( $report_name ) == '' )
140 $report_name = translate ( "Unnamed Report" );
141 $values[] = "'$report_name'";
143 $names[] = "cal_user";
144 if ( ! $is_admin || empty ( $report_user ) ) {
147 $values[] = "'$report_user'";
150 $names[] = "cal_include_header";
151 if ( empty ( $include_header ) || $include_header != 'Y' ) {
157 $names[] = "cal_time_range";
158 $values[] = ( ! isset ( $time_range ) ? 11 : $time_range );
160 $names[] = "cal_cat_id";
161 $values[] = ( empty ( $cat_id ) ? "NULL" : $cat_id );
163 $names[] = "cal_allow_nav";
164 $values[] = ( empty ( $allow_nav ) || $allow_nav != 'Y' ) ? "'N'" : "'Y'";
166 $names[] = "cal_include_empty";
167 $values[] = ( empty ( $include_empty ) || $include_empty != 'Y' ) ? "'N'" : "'Y'";
169 $names[] = "cal_is_global";
170 $values[] = ( empty ( $is_global ) || $is_global != 'Y' ) ? "'N'" : "'Y'";
172 $names[] = "cal_show_in_trailer";
173 $values[] = ( empty ( $show_in_trailer ) || $show_in_trailer != 'Y' ) ? "'N'" : "'Y'";
175 if ( $adding_report ) {
176 $res = dbi_query ( "SELECT MAX(cal_report_id) FROM webcal_report" );
179 if ( $row = dbi_fetch_row ( $res ) ) {
180 $newid = $row[0] + 1;
182 dbi_free_result ( $res );
184 $names[] = "cal_report_id";
186 $sql = "INSERT INTO webcal_report ( ";
187 for ( $i = 0; $i < count ( $names ); $i++ ) {
192 $sql .= " ) VALUES ( ";
193 for ( $i = 0; $i < count ( $values ); $i++ ) {
201 $sql = "UPDATE webcal_report SET ";
202 for ( $i = 0; $i < count ( $names ); $i++ ) {
205 $sql .= "$names[$i] = $values[$i]";
207 $sql .= " WHERE cal_report_id = $report_id";
209 //echo "SQL: $sql"; exit;
213 if ( empty ( $error ) ) {
214 if ( ! dbi_query ( $sql ) ) {
215 $error = translate ( "Database error" ) . ": " . dbi_error ();
219 if ( empty ( $error ) ) {
220 if ( ! $adding_report ) {
221 if ( ! dbi_query ( "DELETE FROM webcal_report_template " .
222 "WHERE cal_report_id = $report_id" ) )
223 $error = translate("Database error") . ": " . dbi_error ();
225 if ( empty ( $error ) &&
226 ! dbi_query ( "INSERT INTO webcal_report_template " .
227 "( cal_report_id, cal_template_type, cal_template_text ) VALUES ( " .
228 "$report_id, 'P', '$page_template' )" ) )
229 $error = translate("Database error") . ": " . dbi_error ();
230 if ( empty ( $error ) &&
231 ! dbi_query ( "INSERT INTO webcal_report_template " .
232 "( cal_report_id, cal_template_type, cal_template_text ) VALUES ( " .
233 "$report_id, 'D', '$day_template' )" ) )
234 $error = translate("Database error") . ": " . dbi_error ();
235 if ( empty ( $error ) &&
236 ! dbi_query ( "INSERT INTO webcal_report_template " .
237 "( cal_report_id, cal_template_type, cal_template_text ) VALUES ( " .
238 "$report_id, 'E', '$event_template' )" ) )
239 $error = translate("Database error") . ": " . dbi_error ();
242 if ( empty ( $error ) ) {
243 if ( $updating_public )
244 do_redirect ( "report.php?public=1" );
246 do_redirect ( "report.php" );
253 <h2><?php etranslate("Error")?></h2>
255 <?php echo $error ; ?>
258 <?php print_trailer(); ?>