From 73e6ac63d9a7a97f2977d5ea246aeef91f74c2a3 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Thu, 1 Jul 2004 20:07:43 +0000 Subject: [PATCH] Some polishing of "TAB" chars in source code done. Minor changes in glossary export/import to include the displayformat field. Added a new feature (it was hidden and uncompleted in source code): Import a glossary file, creating automatically a new glossary activity. Bug 1606. http://moodle.org/bugs/bug.php?op=show&bugid=1606 Merged from MOODLE_13_STABLE --- mod/glossary/import.html | 8 +- mod/glossary/import.php | 174 +++++++++++++++++++++++++-------------- mod/glossary/lib.php | 1 + 3 files changed, 115 insertions(+), 68 deletions(-) diff --git a/mod/glossary/import.html b/mod/glossary/import.html index 59464d4b26..756d4362e2 100644 --- a/mod/glossary/import.html +++ b/mod/glossary/import.html @@ -19,11 +19,7 @@

:

: @@ -48,4 +44,4 @@ - \ No newline at end of file + diff --git a/mod/glossary/import.php b/mod/glossary/import.php index 9292092d13..e9c35a264d 100644 --- a/mod/glossary/import.php +++ b/mod/glossary/import.php @@ -2,6 +2,7 @@ require_once("../../config.php"); require_once("lib.php"); + require_once("$CFG->dirroot/course/lib.php"); global $CFG, $USER; require_variable($id); // Course Module ID @@ -77,7 +78,7 @@ $form = data_submitted(); $file = $_FILES["file"]; -// if ($xml = glossary_read_imported_file("C:\\download\\moodle\\moodle\\cursos\\10\\glossary\\Testing_Glossary\\glossary.xml") ) { + if ($xml = glossary_read_imported_file($file['tmp_name']) ) { $importedentries = 0; @@ -90,42 +91,51 @@ if ( $xmlglossary['NAME'][0]['#'] ) { unset($glossary); - $glossary->name = addslashes(utf8_decode($xmlglossary['NAME'][0]['#'])); - $glossary->course = $course->id; - $glossary->globalglossary = $xmlglossary['GLOBALGLOSSARY'][0]['#']; - $glossary->entbypage = $xmlglossary['ENTBYPAGE'][0]['#']; - $glossary->intro = addslashes(utf8_decode($xmlglossary['INTRO'][0]['#'])); - $glossary->showspecial = $xmlglossary['SHOWSPECIAL'][0]['#']; - $glossary->showalphabet = $xmlglossary['SHOWALPHABET'][0]['#']; - $glossary->showall = $xmlglossary['SHOWALL'][0]['#']; - $glossary->timecreated = time(); - $glossary->timemodified = time(); + $glossary->name = addslashes(utf8_decode($xmlglossary['NAME'][0]['#'])); + $glossary->course = $course->id; + $glossary->globalglossary = $xmlglossary['GLOBALGLOSSARY'][0]['#']; + $glossary->intro = addslashes(utf8_decode($xmlglossary['INTRO'][0]['#'])); + $glossary->showspecial = $xmlglossary['SHOWSPECIAL'][0]['#']; + $glossary->showalphabet = $xmlglossary['SHOWALPHABET'][0]['#']; + $glossary->showall = $xmlglossary['SHOWALL'][0]['#']; + $glossary->timecreated = time(); + $glossary->timemodified = time(); // Setting the default values if no values were passed if ( isset($xmlglossary['STUDENTCANPOST'][0]['#']) ) { - $glossary->studentcanpost = $xmlglossary['STUDENTCANPOST'][0]['#']; + $glossary->studentcanpost = $xmlglossary['STUDENTCANPOST'][0]['#']; + } else { + $glossary->studentcanpost = $CFG->glossary_studentspost; + } + if ( isset($xmlglossary['ENTBYPAGE'][0]['#']) ) { + $glossary->entbypage = $xmlglossary['ENTBYPAGE'][0]['#']; } else { - $glossary->studentcanpost = $CFG->cnfstudentcanpost; + $glossary->entbypage = $CFG->glossary_entbypage; } if ( isset($xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#']) ) { $glossary->allowduplicatedentries = $xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#']; } else { - $glossary->allowduplicatedentries = $CFG->cnfallowdupentries; + $glossary->allowduplicatedentries = $CFG->glossary_dupentries; + } + if ( isset($xmlglossary['DISPLAYFORMAT'][0]['#']) ) { + $glossary->displayformat = $xmlglossary['DISPLAYFORMAT'][0]['#']; + } else { + $glossary->displayformat = 2; } if ( isset($xmlglossary['ALLOWCOMMENTS'][0]['#']) ) { - $glossary->allowcomments = $xmlglossary['ALLOWCOMMENTS'][0]['#']; + $glossary->allowcomments = $xmlglossary['ALLOWCOMMENTS'][0]['#']; } else { - $glossary->allowcomments = $CFG->cnfallowcomments; + $glossary->allowcomments = $CFG->glossary_allowcomments; } if ( isset($xmlglossary['USEDYNALINK'][0]['#']) ) { - $glossary->usedynalink = $xmlglossary['USEDYNALINK'][0]['#']; + $glossary->usedynalink = $xmlglossary['USEDYNALINK'][0]['#']; } else { - $glossary->usedynalink = $CFG->cnflinkglossaries; + $glossary->usedynalink = $CFG->glossary_linkentries; } if ( isset($xmlglossary['DEFAULTAPPROVAL'][0]['#']) ) { - $glossary->defaultapproval = $xmlglossary['DEFAULTAPPROVAL'][0]['#']; + $glossary->defaultapproval = $xmlglossary['DEFAULTAPPROVAL'][0]['#']; } else { - $glossary->defaultapproval = $CFG->cnfapprovalstatus; + $glossary->defaultapproval = $CFG->glossary_defaultapproval; } // Include new glossary and return the new ID @@ -135,6 +145,47 @@ print_footer($course); exit; } else { + //The instance has been created, so lets do course_modules + //and course_sections + $mod->groupmode = $course->groupmode; /// Default groupmode the same as course + + $mod->instance = $glossary->id; + // course_modules and course_sections each contain a reference + // to each other, so we have to update one of them twice. + + if (! $currmodule = get_record("modules", "name", 'glossary')) { + error("Glossary module doesn't exist"); + } + $mod->module = $currmodule->id; + $mod->course = $course->id; + $mod->modulename = 'glossary'; + + if (! $mod->coursemodule = add_course_module($mod) ) { + error("Could not add a new course module"); + } + + if (! $sectionid = add_mod_to_section($mod) ) { + error("Could not add the new course module to that section"); + } + //We get the section's visible field status + $visible = get_field("course_sections","visible","id",$sectionid); + + if (! set_field("course_modules", "visible", $visible, "id", $mod->coursemodule)) { + error("Could not update the course module with the correct visibility"); + } + + if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) { + error("Could not update the course module with the correct section"); + } + add_to_log($course->id, "course", "add mod", + "../mod/$mod->modulename/view.php?id=$mod->coursemodule", + "$mod->modulename $mod->instance"); + add_to_log($course->id, $mod->modulename, "add", + "view.php?id=$mod->coursemodule", + "$mod->instance", $mod->coursemodule); + + rebuild_course_cache($course->id); + print_simple_box(get_string("newglossarycreated","glossary"),"center","70%"); echo '

'; } @@ -150,16 +201,20 @@ for($i = 0; $i < sizeof($xmlentries); $i++) { // Inserting the entries $xmlentry = $xmlentries[$i]; - unset($newentry); - $newentry->concept = addslashes(trim(utf8_decode($xmlentry['#']['CONCEPT'][0]['#']))); - $newentry->definition = addslashes(utf8_decode($xmlentry['#']['DEFINITION'][0]['#'])); + $newentry->concept = addslashes(trim(utf8_decode($xmlentry['#']['CONCEPT'][0]['#']))); + $newentry->definition = addslashes(utf8_decode($xmlentry['#']['DEFINITION'][0]['#'])); + if ( isset($xmlentry['#']['CASESENSITIVE'][0]['#']) ) { + $newentry->casesensitive = $xmlentry['#']['CASESENSITIVE'][0]['#']; + } else { + $newentry->casesensitive = $CFG->glossary_casesensitive; + } $permissiongranted = 1; if ( $newentry->concept and $newentry->definition ) { if ( !$glossary->allowduplicatedentries ) { // checking if the entry is valid (checking if it is duplicated when should not be) - if ( $glossary->casesensitive ) { + if ( $newentry->casesensitive ) { $dupentry = get_record("glossary_entries","concept",$newentry->concept,"glossaryid",$glossary->id); } else { $dupentry = get_record("glossary_entries","ucase(concept)",strtoupper($newentry->concept),"glossaryid",$glossary->id); @@ -170,32 +225,27 @@ } } else { $permissiongranted = 0; - } +} if ($permissiongranted) { $newentry->glossaryid = $glossary->id; $newentry->sourceglossaryid = 0; $newentry->approved = 1; $newentry->userid = $USER->id; + $newentry->teacherentry = 1; $newentry->format = $xmlentry['#']['FORMAT'][0]['#']; $newentry->timecreated = time(); $newentry->timemodified = time(); - $newentry->teacherentry = $xmlentry['#']['TEACHERENTRY'][0]['#']; - + // Setting the default values if no values were passed if ( isset($xmlentry['#']['USEDYNALINK'][0]['#']) ) { $newentry->usedynalink = $xmlentry['#']['USEDYNALINK'][0]['#']; } else { - $newentry->usedynalink = $CFG->cnfusedynalink; - } - if ( isset($xmlentry['#']['CASESENSITIVE'][0]['#']) ) { - $newentry->casesensitive = $xmlentry['#']['CASESENSITIVE'][0]['#']; - } else { - $newentry->casesensitive = $CFG->cnfcasesensitive; + $newentry->usedynalink = $CFG->glossary_linkentries; } if ( isset($xmlentry['#']['FULLMATCH'][0]['#']) ) { $newentry->fullmatch = $xmlentry['#']['FULLMATCH'][0]['#']; } else { - $newentry->fullmatch = $CFG->cnffullmatch; + $newentry->fullmatch = $CFG->glossary_fullmatch; } if ( $newentry->id = insert_record("glossary_entries",$newentry) ) { @@ -271,42 +321,42 @@ } // processed entries echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + if ( $catsincl ) { echo ''; - echo ''; - echo ''; + echo ''; + echo ''; echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - if ( $catsincl ) { - echo ''; - echo ''; - echo ''; - echo ''; - } + } echo '
'; + echo get_string("totalentries","glossary"); + echo ':'; + echo $importedentries + $entriesrejected; + echo '
'; + echo get_string("importedentries","glossary"); + echo ':'; + echo $importedentries; + if ( $entriesrejected ) { + echo ' (' . get_string("rejectedentries","glossary") . ": $entriesrejected)"; + } + echo '
'; - echo get_string("totalentries","glossary"); - echo ':'; - echo $importedentries + $entriesrejected; - echo ''; + echo get_string("importedcategories","glossary"); + echo ':'; + echo $importedcats; + echo '
'; - echo get_string("importedentries","glossary"); - echo ':'; - echo $importedentries; - if ( $entriesrejected ) { - echo ' (' . get_string("rejectedentries","glossary") . ": $entriesrejected)"; - } - echo '
'; - echo get_string("importedcategories","glossary"); - echo ':'; - echo $importedcats; - echo '


'; // rejected entries if ($rejections) { echo '
'; echo ''; - echo $rejections; + echo $rejections; echo '
' . get_string("rejectionrpt","glossary") . '


'; } } else { diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index a948420164..48d25963af 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -1556,6 +1556,7 @@ global $CFG; fwrite ($h,glossary_full_tag("INTRO",2,false,$glossary->intro)); fwrite ($h,glossary_full_tag("STUDENTCANPOST",2,false,$glossary->studentcanpost)); fwrite ($h,glossary_full_tag("ALLOWDUPLICATEDENTRIES",2,false,$glossary->allowduplicatedentries)); + fwrite ($h,glossary_full_tag("DISPLAYFORMAT",2,false,$glossary->displayformat)); fwrite ($h,glossary_full_tag("SHOWSPECIAL",2,false,$glossary->showspecial)); fwrite ($h,glossary_full_tag("SHOWALPHABET",2,false,$glossary->showalphabet)); fwrite ($h,glossary_full_tag("SHOWALL",2,false,$glossary->showall)); -- 2.39.5