<?php

require_once EGW_INCLUDE_ROOT . '/phpgwapi/inc/class.dragdrop.inc.php';
if ($GLOBALS['egw_info']['user']['preferences']['common']['enable_dragdrop']) {
    $dragdrop = new dragdrop();
    $maxOffLeft = $this->sideboxwidth - 200;
    $maxOffRight = 500 - $this->sideboxwidth;
    $maxOffLeft < 0 && ($maxOffLeft = 0);
    $maxOffRight < 0 && ($maxOffRight = 0);
    $dragdrop->addCustom('thesideboxcolumn', array('NO_DRAG'));
    $dragdrop->addCustom('sideresize', array('CURSOR_W_RESIZE', 'HORIZONTAL', 'MAXOFFLEFT+' . $maxOffLeft, 'MAXOFFRIGHT+' . $maxOffRight), array('sideboxwidth' => $this->sideboxwidth), 'phpgwapi.dragDropFunctions.dragSidebar', 'phpgwapi.dragDropFunctions.dropSidebar');
    $dragdrop->setJSCode();
}
// cancel: return to question editing without saving
if ($cmid) {
    list($module, $cm) = get_module_from_cmid($cmid);
    require_login($cm->course, false, $cm);
    if (!$returnurl) {
        $returnurl = "{$CFG->wwwroot}/question/edit.php?cmid={$cm->id}";
    }
} elseif ($courseid) {
    require_login($courseid, false);
    if (!$returnurl) {
        $returnurl = "{$CFG->wwwroot}/question/edit.php?courseid={$COURSE->id}";
    }
    $cm = null;
} else {
    print_error('needcmidorcourseid', 'qtype_dragdrop');
}
// Validate the question id
if (!($question = get_record('question', 'id', $id))) {
    print_error('questiondoesnotexist', 'question', $returnurl);
}
get_question_options($question);
if (!question_has_capability_on($question, 'edit')) {
    print_error('noeditingright', 'qtype_dragdrop');
}
$dd = new dragdrop($CFG, $id, $courseid, $cmid, $returnurl);
if ($process) {
    $dd->process($process);
} else {
    $dd->edit_positions();
}
echo '</body></html>';
 function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options)
 {
     global $CFG;
     // global feedback
     if ($options->feedback) {
         if ($state->raw_grade >= $question->options->feedbackfraction * $question->maxgrade) {
             if (!empty($question->options->feedbackok)) {
                 $feedback = $question->options->feedbackok;
             }
         } else {
             if (!empty($question->options->feedbackmissed)) {
                 $feedback = $question->options->feedbackmissed;
             }
         }
         if ($feedback) {
             echo '<table border="1" width="100%"><tr><td><b>';
             echo get_string('feedbackoverall', 'qtype_dragdrop') . ':</b> &nbsp;';
             echo $feedback;
             echo '</td></tr></table>';
         }
     }
     // the actual rendering is handled by the dragdrop class
     include_once "{$CFG->dirroot}/question/type/dragdrop/dragdrop.php";
     $dd = new dragdrop($CFG, $question->id, $cmoptions->course, 0, 0, $options, $question, $state);
     $dd->display_question();
 }