config.inc.php,可以取得登入者的權限。
[root@moodle mod_tmp]# diff -urNwbBE mrbs/web/functions.php ../blocks/mrbs/web/functions.php
--- mrbs/web/functions.php 2012-10-21 19:24:42.000000000 +0800
+++ ../blocks/mrbs/web/functions.php 2014-03-23 15:08:10.651787017 +0800
@@ -21,6 +21,7 @@
// over the place. so we test to see if it is set, and if not then set
// it.
require_once('mrbs_auth.php');
+require_once('config.inc.php');
$pview = optional_param('pview', 0, PARAM_INT);
@@ -106,13 +107,13 @@
$homeurl = new moodle_url('/blocks/mrbs/web/index.php');
$gotostr = get_string('goto', 'block_mrbs');
- $gotourl = new moodle_url('/blocks/mrbs/web/day.php');
+ $gotourl = new moodle_url('/blocks/mrbs/web/week.php'); //dywang
if ($userview) {
$gotourl = new moodle_url('/blocks/mrbs/web/userweek.php');
}
- $roomsearchstr = get_string('roomsearch', 'block_mrbs');
- $roomsearchurl = new moodle_url('/blocks/mrbs/web/roomsearch.php');
$helpstr = get_string('help');
$helpurl = new moodle_url('/blocks/mrbs/web/help.php', array('day'=>$day, 'month'=>$month, 'year'=>$year));
@@ -165,12 +166,12 @@
</TD>
HTML2END;
if (!$userview) {
- if (has_capability("block/mrbs:forcebook", $context)) {
+/* if (has_capability("block/mrbs:forcebook", $context)) {
echo'<TD CLASS="banner" BGCOLOR="#C0E0FF" ALIGN=CENTER>
<a href="edit_entry.php?force=TRUE">'.get_string('forciblybook', 'block_mrbs').'</a>
</TD>';
}
-
+*/
echo '<TD CLASS="banner" BGCOLOR="#C0E0FF" ALIGN=CENTER>';
echo '<a target="popup" title="'.$roomsearchstr.'" href="'.$roomsearchurl.'" ';
echo 'onclick="this.target=\'popup\'; return openpopup(\''.$roomsearchurl.'\', \'popup\', \'toolbar=1,location=0,scrollbars,resizable,width=500,height=400\', 0);">';
@@ -184,14 +185,14 @@
if ($canadmin) {
echo '<TD CLASS="banner" BGCOLOR="#C0E0FF" ALIGN=CENTER><A HREF="'.$adminurl.'">'.$adminstr.'</A></TD>';
}
- echo '<TD CLASS="banner" BGCOLOR="#C0E0FF" ALIGN=CENTER><A HREF="'.$reporturl.'">'.$reportstr.'</A></TD>';
+/* echo '<TD CLASS="banner" BGCOLOR="#C0E0FF" ALIGN=CENTER><A HREF="'.$reporturl.'">'.$reportstr.'</A></TD>';
echo '<TD CLASS="banner" BGCOLOR="#C0E0FF" ALIGN=CENTER><FORM METHOD=GET ACTION="'.$searchurl.'">';
echo '<FONT SIZE=2><A HREF="'.$searchadvurl.'">'.$searchstr.'</A></FONT>
<INPUT TYPE=TEXT NAME="search_str" VALUE="'.$search_str.'" SIZE=10>
<INPUT TYPE=HIDDEN NAME=day VALUE="'.$day.'" >
<INPUT TYPE=HIDDEN NAME=month VALUE="'.$month.'" >
<INPUT TYPE=HIDDEN NAME=year VALUE="'.$year.'" >';
- if (!empty($area)) {
+*/ if (!empty($area)) {
echo "<INPUT TYPE=HIDDEN NAME=area VALUE=$area>\n";
}
echo '</FORM></TD>';
@@ -355,12 +356,13 @@
global $DB;
// Get first area in database
- $area = $DB->get_records('block_mrbs_area', null, 'area_name', 'id', 0, 1);
+ $area = $DB->get_records('block_mrbs_area', null, 'area_name', 'id', 0); //dywang
if (empty($area)) {
return 0;
}
}
$USER 全域變數。管理者才需要使用的「區域」列表,全域變數 $area_list_format。
@@ -369,13 +371,21 @@
// This could be changed to implement something like per-user defaults.
function get_default_room($area)
{
- global $DB;
+ global $DB,$USER,$area_list_format;
// Get first room in database
+ if ($area_list_format == "select") {
+ $room = $DB->get_records('block_mrbs_room', array('area_id'=>$area,'room_name'=>$USER->firstname,'description'=>$USER->lastname), 'room_name', 'id', 0, 1); //dywang
+ } else {
$room = $DB->get_records('block_mrbs_room', array('area_id'=>$area), 'room_name', 'id', 0, 1);
+ }
if (empty($room)) {
+ if ( authGetUserLevel($USER->id) == '2') { //dywang
+ $room = $DB->get_records('block_mrbs_room', array('area_id'=>$area), 'room_name', 'id', 0, 1);
+ } else {
return 0;
}
+ }
// Extract the first (and only!) item in the returned array
$room = reset($room);
return $room->id;
@@ -529,13 +540,20 @@
function make_room_select_html( $link, $area, $current, $year, $month, $day )
{
- global $DB;
+ global $DB,$USER;
$out_html = "
<form name=\"roomChangeForm\" method=get action=\"$link\">
<select name=\"room\" onChange=\"document.roomChangeForm.submit()\">";
+ if ( authGetUserLevel($USER->id) == '2') { //dywang
$rooms = $DB->get_records('block_mrbs_room', array('area_id'=>$area), 'room_name');
+ }
+ else {
+ //$rooms = $DB->get_records('block_mrbs_room', array('area_id'=>$area,'room_name'=>$USER->firstname), 'room_name');
+ $rooms = $DB->get_records('block_mrbs_room', array('room_name'=>$USER->firstname,'description'=>$USER->lastname), 'room_name'); //dywang
+ }
+//print_r($USER);
foreach ($rooms as $room) {
$selected = ($room->id == $current) ? "selected" : "";
$out_html .= "