<commit_before><?php // $Id$
/**
 * Allows a teacher to create, edit and delete categories
 *
 * @author <NAME> and many others.
 *         {@link http://moodle.org}
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package questionbank
 */

    require_once("../config.php");
    require_once($CFG->dirroot."/question/editlib.php");
    require_once($CFG->dirroot."/question/category_class.php");



    list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('categories');

    // get values from form for actions on this page
    $param = new stdClass();


    $param->moveup = optional_param('moveup', 0, PARAM_INT);
    $param->movedown = optional_param('movedown', 0, PARAM_INT);
    $param->moveupcontext = optional_param('moveupcontext', 0, PARAM_INT);
    $param->movedowncontext = optional_param('movedowncontext', 0, PARAM_INT);
    $param->tocontext = optional_param('tocontext', 0, PARAM_INT);
    $param->left = optional_param('left', 0, PARAM_INT);
    $param->right = optional_param('right', 0, PARAM_INT);
    $param->delete = optional_param('delete', 0, PARAM_INT);
    $param->confirm = optional_param('confirm', 0, PARAM_INT);
    $param->cancel = optional_param('cancel', '', PARAM_ALPHA);
    $param->move = optional_param('move', 0, PARAM_INT);
    $param->moveto = optional_param('moveto', 0, PARAM_INT);
    $param->edit = optional_param('edit', 0, PARAM_INT);

    $qcobject = new question_category_object($pagevars['cpage'], $thispageurl, $contexts->having_one_edit_tab_cap('categories'), $param->edit, $pagevars['cat'], $param->delete,
                                $contexts->having_cap('moodle/question:add'));

    $streditingcategories = get_string('editcategories', 'quiz');
    if ($param->left || $param->right || $param->moveup || $param->movedown|| $param->moveupcontext || $param->movedowncontext){
        confirm_sesskey();
        foreach ($qcobject->editlists as $list){
            //processing of these actions is handled in the method where appropriate and page redirects.
            $list->process_actions($param->left, $param->right, $param->moveup, $param->movedown,
                                    $param->moveupcontext, $param->movedowncontext, $param->tocontext);
        }
    }
    if ($param->delete && ($questionstomove = $DB->count_records("question", array("category" => $param->delete)))){
        if (!$category = $DB->get_record("question_categories", array("id" => $param->delete))) {  // security
            print_error('nocate', 'question', $thispageurl->out(), $param->delete);
        }
        $categorycontext = get_context_instance_by_id($category->contextid);
        $qcobject->moveform = new question_move_form($thispageurl,
                    array('contexts'=>array($categorycontext), 'currentcat'=>$param->delete));
        if ($qcobject->moveform->is_cancelled()){
            redirect($thispageurl->out());
        }  elseif ($formdata = $qcobject->moveform->get_data()) {
            /// 'confirm' is the category to move existing questions to
            list($tocategoryid, $tocontextid) = explode(',', $formdata->category);
            $qcobject->move_questions_and_delete_category($formdata->delete, $tocategoryid);
            $thispageurl->remove_params('cat');
            $thispageurl->remove_params('category'); // TODO check in fix for bug 5353
            redirect($thispageurl->out());
        }
    } else {
        $questionstomove = 0;
    }
    if ($qcobject->catform->is_cancelled()){
        redirect($thispageurl->out());
    }elseif ($catformdata = $qcobject->catform->get_data()) {
        if (!$catformdata->id) {//new category
            $qcobject->add_category($catformdata->parent, $catformdata->name, $catformdata->info);
        } else {
            $qcobject->update_category($catformdata->id, $catformdata->parent, $catformdata->name, $catformdata->info);
        }
        redirect($thispageurl->out());
    } elseif ((!empty($param->delete) and (!$questionstomove) and confirm_sesskey()))  {
        $qcobject->delete_category($param->delete);//delete the category now no questions to move
    }
    $navlinks = array();
    if ($cm!==null) {
        // Page header
        $strupdatemodule = has_capability('moodle/course:manageactivities', $contexts->lowest())
            ? update_module_button($cm->id, $COURSE->id, get_string('modulename', $cm->modname))
            : "";
        $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname),<commit_msg>Question bank: error when deleting empty categories.<commit_after><?php // $Id$
/**
 * Allows a teacher to create, edit and delete categories
 *
 * @author <NAME> and many others.
 *         {@link http://moodle.org}
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package questionbank
 */

    require_once("../config.php");
    require_once($CFG->dirroot."/question/editlib.php");
    require_once($CFG->dirroot."/question/category_class.php");



    list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('categories');

    // get values from form for actions on this page
    $param = new stdClass();


    $param->moveup = optional_param('moveup', 0, PARAM_INT);
    $param->movedown = optional_param('movedown', 0, PARAM_INT);
    $param->moveupcontext = optional_param('moveupcontext', 0, PARAM_INT);
    $param->movedowncontext = optional_param('movedowncontext', 0, PARAM_INT);
    $param->tocontext = optional_param('tocontext', 0, PARAM_INT);
    $param->left = optional_param('left', 0, PARAM_INT);
    $param->right = optional_param('right', 0, PARAM_INT);
    $param->delete = optional_param('delete', 0, PARAM_INT);
    $param->confirm = optional_param('confirm', 0, PARAM_INT);
    $param->cancel = optional_param('cancel', '', PARAM_ALPHA);
    $param->move = optional_param('move', 0, PARAM_INT);
    $param->moveto = optional_param('moveto', 0, PARAM_INT);
    $param->edit = optional_param('edit', 0, PARAM_INT);

    $qcobject = new question_category_object($pagevars['cpage'], $thispageurl, $contexts->having_one_edit_tab_cap('categories'), $param->edit, $pagevars['cat'], $param->delete,
                                $contexts->having_cap('moodle/question:add'));

    $streditingcategories = get_string('editcategories', 'quiz');
    if ($param->left || $param->right || $param->moveup || $param->movedown|| $param->moveupcontext || $param->movedowncontext){
        confirm_sesskey();
        foreach ($qcobject->editlists as $list){
            //processing of these actions is handled in the method where appropriate and page redirects.
            $list->process_actions($param->left, $param->right, $param->moveup, $param->movedown,
                                    $param->moveupcontext, $param->movedowncontext, $param->tocontext);
        }
    }
    if ($param->delete && ($questionstomove = $DB->count_records("question", array("category" => $param->delete)))){
        if (!$category = $DB->get_record("question_categories", array("id" => $param->delete))) {  // security
            print_error('nocate', 'question', $thispageurl->out(), $param->delete);
        }
        $categorycontext = get_context_instance_by_id($category->contextid);
        $qcobject->moveform = new question_move_form($thispageurl,
                    array('contexts'=>array($categorycontext), 'currentcat'=>$param->delete));
        if ($qcobject->moveform->is_cancelled()){
            redirect($thispageurl->out());
        }  elseif ($formdata = $qcobject->moveform->get_data()) {
            /// 'confirm' is the category to move existing questions to
            list($tocategoryid, $tocontextid) = explode(',', $formdata->category);
            $qcobject->move_questions_and_delete_category($formdata->delete, $tocategoryid);
            $thispageurl->remove_params('cat');
            $thispageurl->remove_params('category');
            redirect($thispageurl->out());
        }
    } else {
        $questionstomove = 0;
    }
    if ($qcobject->catform->is_cancelled()){
        redirect($thispageurl->out());
    }elseif ($catformdata = $qcobject->catform->get_data()) {
        if (!$catformdata->id) {//new category
            $qcobject->add_category($catformdata->parent, $catformdata->name, $catformdata->info);
        } else {
            $qcobject->update_category($catformdata->id, $catformdata->parent, $catformdata->name, $catformdata->info);
        }
        redirect($thispageurl->out());
    } elseif ((!empty($param->delete) and (!$questionstomove) and confirm_sesskey()))  {
        $thispageurl->remove_params('cat');
        $thispageurl->remove_params('category');
        $qcobject->delete_category($param->delete);//delete the category now no questions to move
    }
    $navlinks = array();
    if ($cm!==null) {
        // Page header
        $strupdatemodule = has_capability('moodle/course:manageactivities', $contexts->lowest())
            ? update_module_button($cm->id, $COURSE->id, get_string('modulename', $cm->modname))
            : "";
        $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname),
{'fraction_non_alphanumeric': 0.1694619908516663, 'fraction_numerical': 0.00326726203441516, 'mean_word_length': 3.47078870496592, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 175, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1963242', 'n_tokens_mistral': 2845, 'n_tokens_neox': 2768, 'n_words': 500}