Ejemplo n.º 1
0
             $sdata->chart_type = $settings->chart_type_global;
         } else {
             if ($settings->feedbacksections == 2) {
                 $sdata->chart_type = $settings->chart_type_two_sections;
             } else {
                 if ($settings->feedbacksections > 2) {
                     $sdata->chart_type = $settings->chart_type_sections;
                 }
             }
         }
     }
 } else {
     $sdata->feedbacksections = '';
 }
 $sdata->owner = $settings->owner;
 if (!($sid = $questionnaire->survey_update($sdata))) {
     print_error('couldnotcreatenewsurvey', 'questionnaire');
 } else {
     if ($submitbutton2) {
         $redirecturl = course_get_url($cm->course);
     } else {
         $redirecturl = $CFG->wwwroot . '/mod/questionnaire/view.php?id=' . $questionnaire->cm->id;
     }
     // Save current advanced settings only.
     if (isset($settings->submitbutton) || isset($settings->submitbutton2)) {
         redirect($redirecturl, get_string('settingssaved', 'questionnaire'));
     }
     // Delete existing section and feedback records for this questionnaire if any were previously set and None are wanted now
     // or Global feedback is now wanted.
     if ($sdata->feedbacksections == 0 || $questionnaire->survey->feedbacksections > 1 && $sdata->feedbacksections == 1) {
         if ($feedbacksections = $DB->get_records('questionnaire_fb_sections', array('survey_id' => $sid), '', 'id')) {
Ejemplo n.º 2
0
function questionnaire_add_instance($questionnaire)
{
    // Given an object containing all the necessary data,
    // (defined by the form in mod.html) this function
    // will create a new instance and return the id number
    // of the new instance.
    global $COURSE, $DB, $CFG;
    require_once $CFG->dirroot . '/mod/questionnaire/questionnaire.class.php';
    require_once $CFG->dirroot . '/mod/questionnaire/locallib.php';
    // Check the realm and set it to the survey if it's set.
    if (empty($questionnaire->sid)) {
        // Create a new survey.
        $cm = new Object();
        $qobject = new questionnaire(0, $questionnaire, $COURSE, $cm);
        if ($questionnaire->create == 'new-0') {
            $sdata = new Object();
            $sdata->name = $questionnaire->name;
            $sdata->realm = 'private';
            $sdata->title = $questionnaire->name;
            $sdata->subtitle = '';
            $sdata->info = '';
            $sdata->theme = '';
            // Theme is deprecated.
            $sdata->thanks_page = '';
            $sdata->thank_head = '';
            $sdata->thank_body = '';
            $sdata->email = '';
            $sdata->owner = $COURSE->id;
            if (!($sid = $qobject->survey_update($sdata))) {
                print_error('couldnotcreatenewsurvey', 'questionnaire');
            }
        } else {
            $copyid = explode('-', $questionnaire->create);
            $copyrealm = $copyid[0];
            $copyid = $copyid[1];
            if (empty($qobject->survey)) {
                $qobject->add_survey($copyid);
                $qobject->add_questions($copyid);
            }
            // New questionnaires created as "use public" should not create a new survey instance.
            if ($copyrealm == 'public') {
                $sid = $copyid;
            } else {
                $sid = $qobject->sid = $qobject->survey_copy($COURSE->id);
                // All new questionnaires should be created as "private".
                // Even if they are *copies* of public or template questionnaires.
                $DB->set_field('questionnaire_survey', 'realm', 'private', array('id' => $sid));
            }
        }
        $questionnaire->sid = $sid;
    }
    $questionnaire->timemodified = time();
    // May have to add extra stuff in here.
    if (empty($questionnaire->useopendate)) {
        $questionnaire->opendate = 0;
    }
    if (empty($questionnaire->useclosedate)) {
        $questionnaire->closedate = 0;
    }
    if ($questionnaire->resume == '1') {
        $questionnaire->resume = 1;
    } else {
        $questionnaire->resume = 0;
    }
    // Field questionnaire->navigate used for branching questionnaires. Starting with version 2.5.5.
    /* if ($questionnaire->navigate == '1') {
           $questionnaire->navigate = 1;
       } else {
           $questionnaire->navigate = 0;
       } */
    if (!($questionnaire->id = $DB->insert_record("questionnaire", $questionnaire))) {
        return false;
    }
    questionnaire_set_events($questionnaire);
    return $questionnaire->id;
}
function questionnaire_add_instance($questionnaire)
{
    /// Given an object containing all the necessary data,
    /// (defined by the form in mod.html) this function
    /// will create a new instance and return the id number
    /// of the new instance.
    global $COURSE;
    // Check the realm and set it to the survey if it's set.
    if (!empty($questionnaire->sid) && !empty($questionnaire->realm)) {
        // JR not needed
        //        set_field('questionnaire_survey', 'realm', $questionnaire->realm, 'id', $questionnaire->sid);
    } else {
        if (empty($questionnaire->sid)) {
            /// Create a new survey:
            $cm = new Object();
            $qobject = new questionnaire(0, $questionnaire, $COURSE, $cm);
            if ($questionnaire->create == 'new-0') {
                $sdata = new Object();
                $sdata->name = $questionnaire->name;
                $sdata->realm = 'private';
                $sdata->title = $questionnaire->name;
                $sdata->subtitle = '';
                $sdata->info = '';
                $sdata->theme = 'default.css';
                // JR DEV
                $sdata->thanks_page = '';
                $sdata->thank_head = '';
                $sdata->thank_body = '';
                $sdata->email = '';
                $sdata->owner = $COURSE->id;
                if (!($sid = $qobject->survey_update($sdata))) {
                    error('Could not create a new survey!');
                }
            } else {
                $copyid = explode('-', $questionnaire->create);
                $copyrealm = $copyid[0];
                $copyid = $copyid[1];
                if (empty($qobject->survey)) {
                    $qobject->add_survey($copyid);
                    $qobject->add_questions($copyid);
                }
                // JR new questionnaires created as "use public" should not create a new survey instance
                if ($copyrealm == 'public') {
                    $sid = $copyid;
                } else {
                    $sid = $qobject->sid = $qobject->survey_copy($COURSE->id);
                    // JR all new questionnaires should be created as "private", even if they are *copies* of public or template questionnaires
                    set_field('questionnaire_survey', 'realm', 'private', 'id', $questionnaire->sid);
                }
            }
            $questionnaire->sid = $sid;
        }
    }
    $questionnaire->timemodified = time();
    # May have to add extra stuff in here #
    if (empty($questionnaire->useopendate)) {
        $questionnaire->opendate = 0;
    }
    if (empty($questionnaire->useclosedate)) {
        $questionnaire->closedate = 0;
    }
    if ($questionnaire->resume == '1') {
        //JR
        $questionnaire->resume = 1;
    } else {
        $questionnaire->resume = 0;
    }
    $questionnaire->navigate = 1;
    // not used at all!
    return insert_record("questionnaire", $questionnaire);
}