--- edit_webwork_form.php	2009-07-06 15:28:18.634849643 -0400

+++ edit_webwork_form.php	2009-07-06 16:29:46.506348995 -0400

@@ -40,9 +40,41 @@

         $mform->addElement('header', 'generalheader', get_string("general", 'form'));

         

         //Question Category

-        $mform->addElement('questioncategory', 'category', get_string('category', 'quiz'), null,

-                array('courseid' => $COURSE->id, 'published' => true, 'only_editable' => true));

-                

+        if (!isset($this->question->id)){

+            //adding question

+            $mform->addElement('questioncategory', 'category', get_string('category', 'quiz'),

+                    array('contexts' => $this->contexts->having_cap('moodle/question:add')));

+        } elseif (!($this->question->formoptions->canmove || $this->question->formoptions->cansaveasnew)){

+            //editing question with no permission to move from category.

+            $mform->addElement('questioncategory', 'category', get_string('category', 'quiz'),

+                    array('contexts' => array($this->categorycontext)));

+        } elseif ($this->question->formoptions->movecontext){

+            //moving question to another context.

+            $mform->addElement('questioncategory', 'categorymoveto', get_string('category', 'quiz'),

+                    array('contexts' => $this->contexts->having_cap('moodle/question:add')));

+

+        } else {

+            //editing question with permission to move from category or save as new q

+            $currentgrp = array();

+            $currentgrp[0] =& $mform->createElement('questioncategory', 'category', get_string('categorycurrent', 'question'),

+                    array('contexts' => array($this->categorycontext)));

+            if ($this->question->formoptions->canedit || $this->question->formoptions->cansaveasnew){

+                //not move only form

+                $currentgrp[1] =& $mform->createElement('checkbox', 'usecurrentcat', '', get_string('categorycurrentuse', 'question'));

+                $mform->setDefault('usecurrentcat', 1);

+            }

+            $currentgrp[0]->freeze();

+            $currentgrp[0]->setPersistantFreeze(false);

+            $mform->addGroup($currentgrp, 'currentgrp', get_string('categorycurrent', 'question'), null, false);

+

+            $mform->addElement('questioncategory', 'categorymoveto', get_string('categorymoveto', 'question'),

+                    array('contexts' => array($this->categorycontext)));

+            if ($this->question->formoptions->canedit || $this->question->formoptions->cansaveasnew){

+                //not move only form

+                $mform->disabledIf('categorymoveto', 'usecurrentcat', 'checked');

+            }

+        }

+               

         //Question Name

         $mform->addElement('text', 'name', get_string('questionname', 'quiz'),

                 array('size' => 50));

@@ -86,6 +118,21 @@

         $mform->addElement('hidden', 'versioning');

         $mform->setType('versioning', PARAM_BOOL);

 

+        $mform->addElement('hidden', 'movecontext');

+        $mform->setType('movecontext', PARAM_BOOL);

+

+        $mform->addElement('hidden', 'cmid');

+        $mform->setType('cmid', PARAM_INT);

+        $mform->setDefault('cmid', 0);

+

+        $mform->addElement('hidden', 'courseid');

+        $mform->setType('courseid', PARAM_INT);

+        $mform->setDefault('courseid', 0);

+

+        $mform->addElement('hidden', 'returnurl');

+        $mform->setType('returnurl', PARAM_LOCALURL);

+        $mform->setDefault('returnurl', 0);

+

         $buttonarray = array();

         $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));

         if (!empty($this->question->id)) {

@@ -94,7 +141,7 @@

         $buttonarray[] = &$mform->createElement('cancel');

         $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);

         $mform->closeHeaderBefore('buttonar');

-    }

+}

     

     function definition_inner(&$mform) {    

         //CODE HEADER

