next up previous contents
Next: gotoroom.php 程式修改 Up: Timetable 課表 Previous: edit_entry.php 程式修改   Contents

function.php 程式修改

  1. 修改函式庫檔案。因顯示區分管理者與非管理者,故首先加入 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);
    
  2. 以「日」顯示,改成以「週」顯示。取消抬頭「會議室」搜尋的連結。
    @@ -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));
    
  3. 取消「會議室」預約編輯連結。
    @@ -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);">';
    
  4. 取消「日期」顯示。
    @@ -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>';
    
  5. 「區域」資料取得改成不限數量。
    @@ -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;
         }
     }
    
  6. 要使用者用戶資料,故加入$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;
    
  7. 一般用戶只要顯示自己的「課表」,管理者可以看到所有課程的「課表」。
         // 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 .= "
    



2018-08-14