Exemplo n.º 1
0
        if ($modchooser == 0 && confirm_sesskey()) {
            set_user_preference('usemodchooser', $modchooser);
        }
    }
    if (has_capability('moodle/course:update', $context)) {
        if ($hide && confirm_sesskey()) {
            set_section_visible($course->id, $hide, '0');
            redirect($PAGE->url);
        }
        if ($show && confirm_sesskey()) {
            set_section_visible($course->id, $show, '1');
            redirect($PAGE->url);
        }
        if (!empty($section)) {
            if (!empty($move) and confirm_sesskey()) {
                if (move_section($course, $section, $move)) {
                    if ($course->id == SITEID) {
                        redirect($CFG->wwwroot . '/?redirect=0');
                    } else {
                        redirect(course_get_url($course));
                    }
                } else {
                    echo $OUTPUT->notification('An error occurred while moving a section');
                }
            }
        }
    }
} else {
    $USER->editing = 0;
}
$SESSION->fromdiscussion = $PAGE->url->out(false);
 /**
  * Handle any pre-display arguments for the course. Make legacy variables global.
  * TODO - Move arguments into object structure.
  *
  */
 function handle_args()
 {
     global $CFG, $USER, $PAGE, $SESSION, $course;
     global $section, $marker;
     /// These are needed in various library functions.
     $section = optional_param('section', 0, PARAM_INT);
     $marker = optional_param('marker', -1, PARAM_INT);
     $edit = optional_param('edit', -1, PARAM_BOOL);
     $hide = optional_param('hide', 0, PARAM_INT);
     $show = optional_param('show', 0, PARAM_INT);
     $move = optional_param('move', 0, PARAM_INT);
     if (!isset($USER->editing)) {
         $USER->editing = 0;
     }
     if ($PAGE->user_allowed_editing()) {
         if ($edit == 1 and confirm_sesskey()) {
             $USER->editing = 1;
         } else {
             if ($edit == 0 and confirm_sesskey()) {
                 $USER->editing = 0;
                 if (!empty($USER->activitycopy) && $USER->activitycopycourse == $course->id) {
                     $USER->activitycopy = false;
                     $USER->activitycopycourse = NULL;
                 }
             }
         }
         if ($hide && confirm_sesskey()) {
             set_section_visible($course->id, $hide, '0');
         }
         if ($show && confirm_sesskey()) {
             set_section_visible($course->id, $show, '1');
         }
         if (!empty($section)) {
             if (!empty($move) and confirm_sesskey()) {
                 if (!move_section($course, $section, $move)) {
                     notify('An error occurred while moving a section');
                 }
             }
         }
     } else {
         $USER->editing = 0;
     }
     $SESSION->fromdiscussion = $CFG->wwwroot . '/course/view.php?id=' . $course->id;
     if ($course->id == SITEID) {
         // This course is not a real course.
         redirect($CFG->wwwroot . '/');
     }
 }
Exemplo n.º 3
0
             // (weight field).
             blocks_move_block($PAGE, $blockinstance, $column, $value);
             break;
     }
     break;
 case 'section':
     if (!record_exists('course_sections', 'course', $course->id, 'section', $id)) {
         error_log('AJAX commands.php: Bad Section ID ' . $id);
         die;
     }
     switch ($field) {
         case 'visible':
             set_section_visible($course->id, $id, $value);
             break;
         case 'move':
             move_section($course, $id, $value);
             break;
     }
     rebuild_course_cache($course->id);
     break;
 case 'resource':
     if (!($mod = get_record('course_modules', 'id', $id, 'course', $course->id))) {
         error_log('AJAX commands.php: Bad course module ID ' . $id);
         die;
     }
     switch ($field) {
         case 'visible':
             set_coursemodule_visible($mod->id, $value);
             break;
         case 'groupmode':
             set_coursemodule_groupmode($mod->id, $value);
		break;
	case ACTION_MOVE :
		if(empty($move)){
			$responseobj->success = 0;
		    $responseobj->reason = "No movement specified";
		} else {
			$course = $DB->get_record('course', array('id'=>$course_id));
			// loop it 
			// dir, num
			$num = abs($move);
			
			$dir = $move/$num;
			$count = 0;
			$responseobj->success = 1;
			while($num > 0){
				if (!move_section($course, $section_id, $dir)) {
	        	    $responseobj->success = 0;
	        	    break;
				}
				$num--;
				$section_id += $dir;
			}
	 		if ($responseobj->success == 1) {
				$responseobj->reason = "Section moved ";
	        } else {
				$responseobj->reason = "An error occurred while moving a section " . $dir . ". broke at " . $num;
	        }
	        // Clear the navigation cache at this point so that the affects
	        // are seen immediatly on the navigation.
	        // $PAGE->navigation->clear_cache();
		}