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 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
|
<?php
/*
* $Id: edit_report.php,v 1.19 2004/11/19 08:47:34 cknudsen Exp $
*
* Page Description:
* This page will present the HTML form to add or edit a report.
*
* Input Parameters:
* report_id (optional) - the report id of the report to edit.
* If blank, user is adding a new report.
* public (optional) - If set to '1' and user is an admin user,
* then we are creating a report for the public user.
*
* Security:
* If system setting $reports_enabled is set to anything other than
* 'Y', then don't allow access to this page.
* If $allow_view_other is 'N', then do not allow selection of
* participants.
* If not an admin user, only report creator (cal_login in webcal_report)
* can edit/delete report.
*/
include_once 'includes/init.php';
load_user_categories ();
$updating_public = false;
$error = "";
if ( empty ( $reports_enabled ) || $reports_enabled != 'Y' ) {
$error = translate ( "You are not authorized" ) . ".";
}
if ( $is_admin && ! empty ( $public ) && $public_access == "Y" ) {
$updating_public = true;
$report_user = "__public__";
} else {
$report_user = '';
}
$report_id = getIntValue ( "report_id", true );
$adding_report = false;
if ( empty ( $report_id ) ) {
$adding_report = true;
$report_id = -1;
$include_header = 'Y';
$report_is_global = 'N';
$report_allow_nav = 'Y';
}
$show_participants = true;
if ( $single_user == 'Y' || $disable_participants_field == 'Y' )
$show_participants = false;
if ( $login == "__public__" ) {
$error = translate ( "You are not authorized" );
}
// Set date range options
$ranges = array (
"0" => translate ( "Tomorrow" ),
"1" => translate ( "Today" ),
"2" => translate ( "Yesterday" ),
"3" => translate ( "Day before yesterday" ),
"10" => translate ( "Next week" ),
"11" => translate ( "This week" ),
"12" => translate ( "Last week" ),
"13" => translate ( "Week before last" ),
"20" => translate ( "Next week and week after" ),
"21" => translate ( "This week and next week" ),
"22" => translate ( "Last week and this week" ),
"23" => translate ( "Last two weeks" ),
"30" => translate ( "Next month" ),
"31" => translate ( "This month" ),
"32" => translate ( "Last month" ),
"33" => translate ( "Month before last" ),
"40" => translate ( "Next year" ),
"41" => translate ( "This year" ),
"42" => translate ( "Last year" ),
"43" => translate ( "Year before last" )
);
// Get list of users that the current user can see
if ( empty ( $error ) && $show_participants ) {
$userlist = get_my_users ();
if ($nonuser_enabled == "Y" ) {
$nonusers = get_nonuser_cals ();
$userlist = ($nonuser_at_top == "Y") ? array_merge($nonusers, $userlist) : array_merge($userlist, $nonusers);
}
}
// Default values
$page_template = "<dl>\${days}</dl>";
$day_template = "<dt><b>\${date}</b></dt>\n<dd><dl>\${events}</dl></dd>";
$event_template = "<dt>\${name}</dt>\n<dd>" .
"<b>" . translate ( "Date" ) . ":</b> \${date}<br />\n" .
"<b>" . translate ( "Time" ) . ":</b> \${time}<br />\n" .
"\${description}</dd>\n";
if ( empty ( $error ) && $report_id > 0 ) {
$sql = "SELECT cal_login, cal_report_id, cal_is_global, " .
"cal_report_type, cal_include_header, cal_report_name, " .
"cal_time_range, cal_user, cal_allow_nav, cal_cat_id, " .
"cal_include_empty, cal_show_in_trailer, cal_update_date " .
"FROM webcal_report " .
"WHERE cal_report_id = $report_id";
//echo "SQL: $sql<br /><br />";
$res = dbi_query ( $sql );
if ( $res ) {
if ( $row = dbi_fetch_row ( $res ) ) {
$i = 0;
$report_login = $row[$i++];
$report_id = $row[$i++];
$report_is_global = $row[$i++];
$report_type = $row[$i++];
$report_include_header = $row[$i++];
$report_name = $row[$i++];
$report_time_range = $row[$i++];
$report_user = $row[$i++];
$report_allow_nav = $row[$i++];
$report_cat_id = $row[$i++];
$report_include_empty = $row[$i++];
$report_show_in_trailer = $row[$i++];
$report_update_date = $row[$i++];
// Check permissions.
if ( $show_participants && ! empty ( $report_user ) ) {
$user_is_in_list = false;
for ( $i = 0; $i < count ( $userlist ); $i++ ) {
if ( $report_user == $userlist[$i]['cal_login'] )
$user_is_in_list = true;
}
if ( ! $user_is_in_list && $report_login != $login && ! $is_admin ) {
$error = translate ( "You are not authorized" );
}
}
if ( ! $is_admin && $login != $report_login ) {
// If not admin, only creator can edit/delete the event
$error = translate ( "You are not authorized" );
}
// If we are editing a public user report we need to set $updating_public
if ( $is_admin && $report_login == "__public__" ) $updating_public = true;
} else {
$error = translate ( "Invalid report id" ) . ": $report_id";
}
dbi_free_result ( $res );
} else {
$error = translate("Database error") . ": " . dbi_error ();
}
$res = dbi_query ( "SELECT cal_template_type, cal_template_text " .
"FROM webcal_report_template " .
"WHERE cal_report_id = $report_id" );
if ( $res ) {
while ( $row = dbi_fetch_row ( $res ) ) {
if ( $row[0] == 'P' ) {
$page_template = $row[1];
} else if ( $row[0] == 'D' ) {
$day_template = $row[1];
} else if ( $row[0] == 'E' ) {
$event_template = $row[1];
}
}
dbi_free_result ( $res );
}
}
else {
// default values for new report
$report_login = $login;
$report_id = -1;
$report_is_global = 'N';
$report_type = 'html';
$report_include_header = 'Y';
$report_name = translate("Unnamed Report");
$report_time_range = 11; // current week
//$report_user already set
$report_allow_nav = 'Y';
$report_cat_id = '';
$report_include_empty = 'N';
$report_show_in_trailer = 'N';
$report_update_date = '';
}
print_header();
//echo "report_id: $report_id <br />\n";
//echo "report_name: $report_name <br />\n";
//echo "report_user: $report_user <br />\n";
?>
<h2><?php
if ( $updating_public )
echo translate($PUBLIC_ACCESS_FULLNAME) . " ";
if ( $adding_report )
etranslate("Add Report");
else
etranslate("Edit Report");
?></h2>
<?php
if ( ! empty ( $error ) ) {
echo $error;
include_once "includes/trailer.php";
exit;
}
?>
<form action="edit_report_handler.php" method="post" name="reportform">
<?php if ( $updating_public ) { ?>
<input type="hidden" name="public" value="1" />
<?php } ?>
<?php if ( ! $adding_report ) { ?>
<input type="hidden" name="report_id" value="<?php echo $report_id?>" />
<?php } ?>
<table style="border-width:0px;">
<tr><td>
<label for="rpt_name"><?php etranslate("Report name")?>:</label></td><td>
<input type="text" name="report_name" id="rpt_name" size="40" maxlength="50" value="<?php echo htmlentities ( $report_name ); ?>" />
</td></tr>
<?php
if ( $show_participants ) {
$users = "<option value=\"\"";
if ( empty ( $report_user ) )
$users .= " selected=\"selected\"";
$users .= ">" . translate ( "Current User" ) . "</option>\n";
for ( $i = 0; $i < count ( $userlist ); $i++ ) {
$users .= "<option value=\"" . $userlist[$i]['cal_login'] . "\"";
if ( ! empty ( $report_user ) ) {
if ( $report_user == $userlist[$i]['cal_login'] )
$users .= " selected=\"selected\"";
}
$users .= ">" . $userlist[$i]['cal_fullname'] . "</option>\n";
}
print "<tr><td><label for=\"rpt_user\">" .
translate("User") . ":</label></td>\n";
print "<td><select name=\"report_user\" id=\"rpt_user\" size=\"1\">$users\n";
print "</select>\n";
print "</td></tr>\n";
}
?>
<?php if ( $is_admin ) { ?>
<tr><td><label>
<?php etranslate("Global")?>:</label></td><td>
<label><input type="radio" name="is_global" value="Y"
<?php if ( $report_is_global != 'N' ) echo " checked=\"checked\""; ?> /> <?php etranslate("Yes") ?></label>
<label><input type="radio" name="is_global" value="N"
<?php if ( $report_is_global == 'N' ) echo " checked=\"checked\""; ?> /> <?php etranslate("No") ?></label>
</td></tr>
<?php } ?>
<?php
// The report will always be shown in the trailer for the creator
// of the report. For admin users who create a global report,
// allow option of adding to all users trailer.
if ( $is_admin ) {
?>
<tr><td><label>
<?php etranslate("Include link in trailer")?>:</label></td><td>
<label><input type="radio" name="show_in_trailer" value="Y"
<?php if ( $report_show_in_trailer != 'N' ) echo " checked=\"checked\""; ?> /> <?php etranslate("Yes") ?></label>
<label><input type="radio" name="show_in_trailer" value="N"
<?php if ( $report_show_in_trailer == 'N' ) echo " checked=\"checked\""; ?> /> <?php etranslate("No") ?></label>
</td></tr>
<?php } ?>
<tr><td><label>
<?php etranslate("Include standard header/trailer")?>: </label></td><td>
<label><input type="radio" name="include_header" value="Y"
<?php if ( $include_header != 'N' ) echo " checked=\"checked\""; ?> /> <?php etranslate("Yes") ?></label>
<label><input type="radio" name="include_header" value="N"
<?php if ( $report_include_header == 'N' ) echo " checked=\"checked\""; ?> /> <?php etranslate("No") ?></label>
</td></tr>
<tr><td>
<label for="rpt_time_range"><?php etranslate("Date range")?>:</label></td><td>
<select name="time_range" id="rpt_time_range">
<?php
while ( list ( $num, $descr ) = each ( $ranges ) ) {
echo "<option value=\"$num\"";
if ( $report_time_range == $num )
echo " selected=\"selected\"";
echo ">$descr</option>\n";
}
?></select>
</td></tr>
<tr><td>
<label for="rpt_cat_id"><?php etranslate("Category")?>:<label></td><td>
<select name="cat_id" id="rpt_cat_id">
<option value=""><?php etranslate("None") ?></option>
<?php
while ( list ( $cat_id, $descr ) = each ( $categories ) ) {
echo "<option value=\"$cat_id\"";
if ( $report_cat_id == $cat_id )
echo " selected=\"selected\"";
echo ">$descr</option>\n";
}
?></select>
</td></tr>
<tr><td><label>
<?php etranslate("Include previous/next links")?>:</label></td><td>
<label><input type="radio" name="allow_nav" value="Y"
<?php if ( $report_allow_nav != 'N' ) echo " checked=\"checked\""; ?> /> <?php etranslate("Yes") ?></label>
<label><input type="radio" name="allow_nav" value="N"
<?php if ( $report_allow_nav == 'N' ) echo " checked=\"checked\""; ?> /> <?php etranslate("No") ?></label>
</td></tr>
<tr><td><label>
<?php etranslate("Include empty dates")?>:</label></td><td>
<label><input type="radio" name="include_empty" value="Y"
<?php if ( $report_include_empty != 'N' ) echo " checked=\"checked\""; ?> /> <?php etranslate("Yes") ?></label>
<label><input type="radio" name="include_empty" value="N"
<?php if ( $report_include_empty == 'N' ) echo " checked=\"checked\""; ?> /> <?php etranslate("No") ?></label>
</td></tr>
</table>
<table style="border-width:0px;">
<tr><td> </td><td> </td><td><label>
<?php etranslate("Template variables")?></label>
</td></tr>
<tr><td valign="top"><label>
<?php etranslate("Page template")?>:</label></td><td>
<textarea rows="12" cols="60" name="page_template"><?php echo htmlentities ( $page_template )?></textarea></td><td style="vertical-align:top;">
<tt>${days}</tt><br />
<tt>${report_id}</tt><br />
</td></tr>
<tr><td valign="top"><label>
<?php etranslate("Day template")?>:</label></td><td>
<textarea rows="12" cols="60" name="day_template"><?php echo htmlentities ( $day_template )?></textarea></td><td style="vertical-align:top;">
<tt>${events}</tt><br />
<tt>${date}</tt><br />
<tt>${fulldate}</tt><br />
<tt>${report_id}</tt><br />
</td></tr>
<tr><td valign="top"><label>
<?php etranslate("Event template")?>:</label></td><td>
<textarea rows="12" cols="60" name="event_template"><?php echo htmlentities ( $event_template )?></textarea></td><td style="vertical-align:top;">
<tt>${name}</tt><br />
<tt>${description}</tt><br />
<tt>${date}</tt><br />
<tt>${fulldate}</tt><br />
<tt>${time}</tt><br />
<tt>${starttime}</tt><br />
<tt>${endtime}</tt><br />
<tt>${duration}</tt><br />
<tt>${priority}</tt><br />
<tt>${href}</tt><br />
<tt>${user}</tt><br />
<tt>${report_id}</tt>
</td></tr>
<tr><td colspan="2">
<input type="submit" value="<?php etranslate("Save")?>" />
<?php if ( ! $adding_report ) { ?>
<input type="submit" name="action" value="<?php etranslate("Delete");?>" onclick="return confirm('<?php etranslate("Are you sure you want to delete this report?")?>');" />
<?php } ?>
</td></tr>
</table>
</form>
<?php print_trailer(); ?>
</body>
</html>
|