next up previous contents
Next: en/block_mrbs.php 程式修改 Up: Timetable 課表 Previous: trailer.php 程式修改   Contents

week.php 程式修改

  1. 避免一般用戶瀏覽其他用戶的課表,加上若不是自己的課表且不是管理者,就直接 return。
    [root@moodle mod_tmp]# diff -urNwbBE mrbs/web/week.php ../blocks/mrbs/web/week.php
    --- mrbs/web/week.php	2012-10-21 19:24:42.000000000 +0800
    +++ ../blocks/mrbs/web/week.php	2014-09-23 10:14:56.724583441 +0800
    @@ -33,6 +33,7 @@
     $pview = optional_param('pview', 0, PARAM_INT);
     $timetohighlight = optional_param('timetohighlight', -1, PARAM_INT);
     
    +if ( $room != 0 and $room != $USER->id and authGetUserLevel($USER->id) != 2) {return;} //dywang
     $num_of_days = $cfg_mrbs->weeklength;
     if ($num_of_days==0) {
         $num_of_days=7; //if user has not configured this, default to 7
    
  2. 預設「課表」為個人課表。
    @@ -75,7 +76,8 @@
     if ($area > 0) {
         $thisurl->param('area', $area);
     } else {
    -    $area = get_default_area();
    +	$area = $DB->get_field('block_mrbs_room', 'area_id', array('description'=>$USER->lastname));
     }
     if ($room > 0) {
         $thisurl->param('room', $area);
    
  3. 取消「區域」顯示,如果是管理者,則出現「區域」的選擇。
    @@ -113,12 +114,14 @@
         $this_room_name = "";
     
         // Show all areas
    -    echo "<td width=\"30%\"><u>".get_string('areas','block_mrbs')."</u><br>";
     }
     
       // show either a select box or the normal html list
     if ($area_list_format == "select") {
    +    if ( authGetUserLevel($USER->id) == '2') { //dywang
         echo make_area_select_html('week.php', $area, $year, $month, $day); // from functions.php
    +	}
         $this_area_name = $DB->get_field('block_mrbs_area', 'area_name', array('id'=>$area));
         $this_room_name = $DB->get_field('block_mrbs_room', 'room_name', array('id'=>$room));
         $this_room_description = $DB->get_field('block_mrbs_room', 'description', array('id'=>$room));
    
  4. 修改顯示寬度。
    @@ -140,17 +143,23 @@
     }
     
     if ( $pview != 1) {
    -    echo "</td>\n";
     
         // Show all rooms in the current area
    -    echo "<td width=\"30%\"><u>".get_string('rooms','block_mrbs')."</u><br>";
    +    echo "<td width=\"10%\"><u>".get_string('rooms','block_mrbs')."</u><br>";
     }
    
  5. 如果是管理者,則顯示「會議室」選擇。
     // should we show a drop-down for the room list, or not?
    -if ($area_list_format == "select") {
    +if ( authGetUserLevel($USER->id) == 2) { //dywang
         echo make_room_select_html('week.php', $area, $room, $year, $month, $day); // from functions.php
     } else {
    -    $rooms = $DB->get_records('block_mrbs_room', array('area_id'=>$area), 'room_name');
    +	 $rooms = $DB->get_records('block_mrbs_room', array('description'=>$USER->lastname), 'room_name,area_id'); 
         foreach ($rooms as $dbroom) {
             if ( $pview != 1 ) {
                 echo '<a href="'.($baseurl->out(true, array('area'=>$area, 'room'=>$dbroom->id))).'" title="'.$dbroom->room_name.'">';
    
  6. 如果是管理者,則可以以「日期」或「會議室」搜尋課表。
    @@ -170,8 +179,27 @@
     if ( $pview != 1 ) {
         echo "</td>\n";
     
    +    if ( authGetUserLevel($USER->id) == 2) { //dywang
    +		//insert the goto room form
    +		$gotoroom = new moodle_url('/blocks/mrbs/web/gotoroom.php');
    +		$gostr = get_string('goroom', 'block_mrbs');
    +		$gotoval = '';
    +		$gotomsg = '';
    +		if ($roomnotfound) {
    +			$gotoval = $roomnotfound;
    +			$gotomsg = ' '.get_string('noroomsfound', 'block_mrbs');
    +		}
    +		echo "<td width=\"20%\"><h3>".get_string('findroom', 'block_mrbs')."</h3>
    +            <form action='$gotoroom' method='get'>
    +                <input type='text' name='room' value='$gotoval'>
    +                <input type='hidden' name='day' value='$day'>
    +                <input type='hidden' name='month' value='$month'>
    +                <input type='hidden' name='year' value='$year'>
    +                <input type='submit' value='$gostr'>$gotomsg
    +            </form></td>";
    +	}
         //Draw the three month calendars
    -    minicals($year, $month, $day, $area, $room, 'week');
    +    //minicals($year, $month, $day, $area, $room, 'week'); //dywang
         echo "</tr></table>\n";
     }
    
  7. 若每個老師或學生的課表都獨立建立,則同一門課含老師若有 60 位用戶,課表將重複 60 次。課表資料已相當大,若還以這樣的方式建立資料表,查詢時非常慢。為改善此一問題,特將每門課的課表獨立建立,且只建一筆。用戶查詢時,先判斷是否有修這門課,有則加入課表。這種方式可有效降低資料量,查詢速度也加快很多。以下就是查詢該用戶所參與的課程。
    @@ -215,6 +243,21 @@
     $roomdata = $DB->get_record('block_mrbs_room', array('id'=>$room));
     $allowedtobook = allowed_to_book($USER, $roomdata);
     
    +$sql = " firstname = ? AND lastname = ?"; //dywang begin
    +$users = $DB->get_records_select('user', $sql, array($roomdata->room_name, $roomdata->description)); 
    +foreach ($users as $user) {
    +	$user_id=$user->id;
    +}
    +$courses = enrol_get_users_courses($user_id); 
    +foreach($courses as $course) {
    +    $courseids .= $course->id.',';
    +}
    +$courseids .= $room;
    +
    
  8. 改變課表查詢方式為,用戶參與的課程。
     //Get all appointments for this week in the room that we care about
     // This data will be retrieved day-by-day
     for ($j = 0; $j<=($num_of_days-1) ; $j++) {
    @@ -228,10 +271,15 @@
         // Note: weekday here is relative to the $weekstarts configuration variable.
         // If 0, then weekday=0 means Sunday. If 1, weekday=0 means Monday.
     
    -    $sql = 'room_id = ? AND start_time <= ? AND end_time > ?';
    -    $entries = $DB->get_records_select('block_mrbs_entry', $sql, array($room, $pm7[$j], $am7[$j]));
    +    $sql = "room_id in($courseids) AND start_time <= ? AND end_time > ?"; //dywang
    +    $entries = $DB->get_records_select('block_mrbs_entry', $sql, array($pm7[$j], $am7[$j])); //dywang
     
         foreach ($entries as $entry) {
    
  9. 增加會議室 id 紀錄。
    @@ -255,6 +302,7 @@
             $end_t = min(round_t_up($entry->end_time, $resolution, $am7[$j]) - $resolution, $pm7[$j]);
             for ($t = $start_t; $t <= $end_t; $t += $resolution) {
                 $d[$j][date($format,$t)]["id"]    = $entry->id;
    +            $d[$j][date($format,$t)]["room_id"]    = $entry->room_id; //dywang
                 $d[$j][date($format,$t)]["color"] = $entry->type;
                 $d[$j][date($format,$t)]["data"]  = "";
                 $d[$j][date($format,$t)]["long_descr"]  = "";
    
  10. 改變「節次」顯示寬度。
    @@ -312,7 +361,7 @@
     echo "<table cellspacing=0 border=1 width=\"100%\">";
     
     // The header row contains the weekday names and short dates.
    -echo "<tr><th width=\"1%\"><br>".($enable_periods ? get_string('period','block_mrbs') : get_string('time'))."</th>";
    +echo "<tr><th width=\"5%\"><br>".($enable_periods ? get_string('period','block_mrbs') : get_string('time'))."</th>"; //dywang
     if (empty($dateformat)) {
         $dformat = "%a<br>%b %d";
     } else {
    
  11. 改變右邊時間顯示寬度。
    @@ -328,7 +377,7 @@
     }
     // next line to display times on right side
     if ( FALSE != $times_right_side ) {
    -    echo "<th width=\"1%\"><br>"
    +    echo "<th width=\"5%\"><br>"  //dywang
         . ( $enable_periods  ? get_string('period','block_mrbs') : get_string('time') )
         . "</th>";
     }
    
  12. 增加會議室 id 紀錄。
    @@ -390,6 +439,7 @@
     
             if(isset($d[$thisday][$time_t]["id"])) {
                 $id    = $d[$thisday][$time_t]["id"];
    +            $room_id    = $d[$thisday][$time_t]["room_id"];
                 $color = $d[$thisday][$time_t]["color"];
                 $descr = s($d[$thisday][$time_t]["data"]);
                 $long_descr = s($d[$thisday][$time_t]["long_descr"]);
    
  13. 一般用戶對於不是自己設定的行程,也就是共用的課表資料,不能修改。
    @@ -459,7 +509,10 @@
                 $viewentry = new moodle_url('/blocks/mrbs/web/view_entry.php',
                                             array('id'=>$id, 'area'=>$area, 'day'=>$wday,
                                                   'month'=>$wmonth, 'year'=>$wyear));
    -            echo ' <a href="'.$viewentry.'" title="'.$long_descr.'">'.$descr.'</a>';
    +			if ( $room_id != $room and authGetUserLevel($USER->id) != 2) { echo "$long_descr/$descr";} //dywang
    +            else {echo ' <a href="'.$viewentry.'" title="'.$long_descr.'">'.$long_descr.'/'.$descr.'</a>';} //dywang
             } else {
                 echo "&nbsp;\"&nbsp;";
             }
    



2018-08-14