Merge branch 'wip-mdl-36736-m23' of git://github.com/rajeshtaneja/moodle into MOODLE_...
authorDan Poltawski <dan@moodle.com>
Mon, 17 Dec 2012 04:09:46 +0000 (12:09 +0800)
committerDan Poltawski <dan@moodle.com>
Mon, 17 Dec 2012 04:09:46 +0000 (12:09 +0800)
1  2 
course/lib.php
course/yui/toolboxes/toolboxes.js

diff --combined course/lib.php
@@@ -583,7 -583,7 +583,7 @@@ function print_log_csv($course, $user, 
              $ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
              $ldcache[$log->module][$log->action] = $ld;
          }
 -        if ($ld && !empty($log->info)) {
 +        if ($ld && is_numeric($log->info)) {
              // ugly hack to make sure fullname is shown correctly
              if (($ld->mtable == 'user') and ($ld->field ==  $DB->sql_concat('firstname', "' '" , 'lastname'))) {
                  $log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
          $firstField = format_string($courses[$log->course], true, array('context' => $coursecontext));
          $fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
          $row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action, $log->info);
 -        $actionurl = $CFG->wwwroot. make_log_url($log->module,$log->url);\r
 +        $actionurl = $CFG->wwwroot. make_log_url($log->module,$log->url);
          $row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action.' ('.$actionurl.')', $log->info);
          $text = implode("\t", $row);
          echo $text." \n";
@@@ -684,7 -684,7 +684,7 @@@ function print_log_xls($course, $user, 
              $ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
              $ldcache[$log->module][$log->action] = $ld;
          }
 -        if ($ld && !empty($log->info)) {
 +        if ($ld && is_numeric($log->info)) {
              // ugly hack to make sure fullname is shown correctly
              if (($ld->mtable == 'user') and ($ld->field == $DB->sql_concat('firstname', "' '" , 'lastname'))) {
                  $log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
@@@ -798,7 -798,7 +798,7 @@@ function print_log_ods($course, $user, 
              $ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
              $ldcache[$log->module][$log->action] = $ld;
          }
 -        if ($ld && !empty($log->info)) {
 +        if ($ld && is_numeric($log->info)) {
              // ugly hack to make sure fullname is shown correctly
              if (($ld->mtable == 'user') and ($ld->field == $DB->sql_concat('firstname', "' '" , 'lastname'))) {
                  $log->info = fullname($DB->get_record($ld->mtable, array('id'=>$log->info)), true);
@@@ -1484,16 -1484,15 +1484,16 @@@ function print_section($course, $sectio
              $modcontext = context_module::instance($mod->id);
              $canviewhidden = has_capability('moodle/course:viewhiddenactivities', $modcontext);
              $accessiblebutdim = false;
 +            $conditionalhidden = false;
              if ($canviewhidden) {
                  $accessiblebutdim = !$mod->visible;
                  if (!empty($CFG->enableavailability)) {
 -                    $accessiblebutdim = $accessiblebutdim ||
 -                        $mod->availablefrom > time() ||
 +                    $conditionalhidden = $mod->availablefrom > time() ||
                          ($mod->availableuntil && $mod->availableuntil < time()) ||
                          count($mod->conditionsgrade) > 0 ||
                          count($mod->conditionscompletion) > 0;
                  }
 +                $accessiblebutdim = $conditionalhidden || $accessiblebutdim;
              }
  
              $liclasses = array();
                  $linkclasses = '';
                  $textclasses = '';
                  if ($accessiblebutdim) {
 -                    $linkclasses .= ' dimmed conditionalhidden';
 -                    $textclasses .= ' dimmed_text conditionalhidden';
 +                    $linkclasses .= ' dimmed';
 +                    $textclasses .= ' dimmed_text';
 +                    if ($conditionalhidden) {
 +                        $linkclasses .= ' conditionalhidden';
 +                        $textclasses .= ' conditionalhidden';
 +                    }
                      $accesstext = '<span class="accesshide">'.
                          get_string('hiddenfromstudents').': </span>';
                  } else {
                          } else {
                              $extraclass = '';
                          }
 -                        echo "
 -<form class='togglecompletion$extraclass' method='post' action='".$CFG->wwwroot."/course/togglecompletion.php'><div>
 -<input type='hidden' name='id' value='{$mod->id}' />
 -<input type='hidden' name='modulename' value='".s($mod->name)."' />
 -<input type='hidden' name='sesskey' value='".sesskey()."' />
 -<input type='hidden' name='completionstate' value='$newstate' />
 -<input type='image' src='$imgsrc' alt='$imgalt' title='$imgtitle' />
 -</div></form>";
 +                        echo html_writer::start_tag('form', array(
 +                                'class' => 'togglecompletion' . $extraclass,
 +                                'method' => 'post',
 +                                'action' => $CFG->wwwroot . '/course/togglecompletion.php'));
 +                        echo html_writer::start_tag('div');
 +                        echo html_writer::empty_tag('input', array(
 +                                'type' => 'hidden', 'name' => 'id', 'value' => $mod->id));
 +                        echo html_writer::empty_tag('input', array(
 +                                'type' => 'hidden', 'name' => 'modulename',
 +                                'value' => $mod->name));
 +                        echo html_writer::empty_tag('input', array(
 +                                'type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
 +                        echo html_writer::empty_tag('input', array(
 +                                'type' => 'hidden', 'name' => 'completionstate',
 +                                'value' => $newstate));
 +                        echo html_writer::empty_tag('input', array(
 +                                'type' => 'image', 'src' => $imgsrc, 'alt' => $imgalt, 'title' => $imgtitle));
 +                        echo html_writer::end_tag('div');
 +                        echo html_writer::end_tag('form');
                      } else {
                          // In auto mode, or when editing, the icon is just an image
                          echo "<span class='autocompletion'>";
              if (!$mod->uservisible) {
                  echo '<div class="availabilityinfo">'.$mod->availableinfo.'</div>';
              } else if ($canviewhidden && !empty($CFG->enableavailability)) {
-                 $visibilityclass = '';
-                 if (!$mod->visible) {
-                     $visibilityclass = 'accesshide';
-                 }
-                 $ci = new condition_info($mod);
-                 $fullinfo = $ci->get_full_information();
-                 if($fullinfo) {
-                     echo '<div class="availabilityinfo '.$visibilityclass.'">'.get_string($mod->showavailability
-                         ? 'userrestriction_visible'
-                         : 'userrestriction_hidden','condition',
-                         $fullinfo).'</div>';
+                 // Don't add availability information if user is not editing and activity is hidden.
+                 if ($mod->visible || $PAGE->user_is_editing()) {
+                     $hidinfoclass = '';
+                     if (!$mod->visible) {
+                         $hidinfoclass = 'hide';
+                     }
+                     $ci = new condition_info($mod);
+                     $fullinfo = $ci->get_full_information();
+                     if($fullinfo) {
+                         echo '<div class="availabilityinfo '.$hidinfoclass.'">'.get_string($mod->showavailability
+                             ? 'userrestriction_visible'
+                             : 'userrestriction_hidden','condition',
+                             $fullinfo).'</div>';
+                     }
                  }
              }
  
@@@ -1880,7 -1867,7 +1883,7 @@@ function print_section_add_menus($cours
          // The module chooser link
          $modchooser = html_writer::start_tag('div', array('class' => 'mdl-right'));
          $modchooser.= html_writer::start_tag('div', array('class' => 'section-modchooser'));
 -        $icon = $OUTPUT->pix_icon('t/add', $straddeither);
 +        $icon = $OUTPUT->pix_icon('t/add', '');
          $span = html_writer::tag('span', $straddeither, array('class' => 'section-modchooser-text'));
          $modchooser .= html_writer::tag('span', $icon . $span, array('class' => 'section-modchooser-link'));
          $modchooser.= html_writer::end_tag('div');
@@@ -1932,7 -1919,7 +1935,7 @@@ function get_module_metadata($course, $
          if (!course_allowed_module($course, $modname)) {
              continue;
          }
 -        if (isset($modlist[$modname])) {
 +        if (isset($modlist[$course->id][$modname])) {
              // This module is already cached
              $return[$modname] = $modlist[$course->id][$modname];
              continue;
@@@ -4553,7 -4540,6 +4556,7 @@@ function include_course_ajax($course, $
          'courseid' => $course->id,
          'pagetype' => $PAGE->pagetype,
          'pagelayout' => $PAGE->pagelayout,
 +        'subpage' => $PAGE->subpage,
          'regions' => $PAGE->blocks->get_regions(),
      );
      $PAGE->requires->yui_module('moodle-core-blocks', 'M.core_blocks.init_dragdrop', array($params), null, true);
@@@ -37,7 -37,7 +37,7 @@@ YUI.add('moodle-course-toolboxes', func
          CONDITIONALHIDDEN : 'conditionalhidden',
          AVAILABILITYINFODIV : 'div.availabilityinfo',
          SHOWCLASS : 'editing_show',
-         ACCESSHIDECLASS : 'accesshide'
+         HIDECLASS : 'hide'
      };
  
      /**
@@@ -99,7 -99,7 +99,7 @@@
              var availabilityinfo = element.one(CSS.AVAILABILITYINFODIV);
  
              if (availabilityinfo) {
-                 availabilityinfo.toggleClass(CSS.ACCESSHIDECLASS);
+                 availabilityinfo.toggleClass(CSS.HIDECLASS);
              }
              return value;
          },
                  .setAttribute('href', newlink)
                  .setAttribute('title', left_string);
              anchor.appendChild(newicon);
 -            anchor.on('click', this.move_left, this);
              moveright.insert(anchor, 'before');
          },
          /**