Skip to content

Commit

Permalink
Some polishing of "TAB" chars in source code done.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stronk7 committed Jul 1, 2004
1 parent 49fe4f9 commit ae39746
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 68 deletions.
8 changes: 2 additions & 6 deletions mod/glossary/import.html
Expand Up @@ -19,11 +19,7 @@
<p align="right"><?PHP p(get_string("destination","glossary")) ?>:</td> <p align="right"><?PHP p(get_string("destination","glossary")) ?>:</td>
<td width="25%"><select size="1" name="dest"> <td width="25%"><select size="1" name="dest">
<option selected value="current"><?PHP p(get_string("currentglossary","glossary")) ?></option> <option selected value="current"><?PHP p(get_string("currentglossary","glossary")) ?></option>
<?PHP <option value="new"><?PHP p(get_string("newglossary","glossary")) ?></option>
// <option value="new">
//< PHP p(get_string("newglossary","glossary")) ? >
// </option>
?>
</select> <?PHP helpbutton("destination", get_string("destination", "glossary"), "glossary") ?></td> </select> <?PHP helpbutton("destination", get_string("destination", "glossary"), "glossary") ?></td>
<td width="25%"> <td width="25%">
<p align="right"><?PHP p(get_string("importcategories","glossary")) ?>:</td> <p align="right"><?PHP p(get_string("importcategories","glossary")) ?>:</td>
Expand All @@ -48,4 +44,4 @@
<input type="hidden" name="l" value="<?PHP p($l) ?>"> <input type="hidden" name="l" value="<?PHP p($l) ?>">
<input type="hidden" name="lasttab" value="<?PHP p($lasttab) ?>"> <input type="hidden" name="lasttab" value="<?PHP p($lasttab) ?>">
<input type="hidden" name="step" value="1"> <input type="hidden" name="step" value="1">
</form> </form>
174 changes: 112 additions & 62 deletions mod/glossary/import.php
Expand Up @@ -2,6 +2,7 @@


require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
require_once("$CFG->dirroot/course/lib.php");
global $CFG, $USER; global $CFG, $USER;


require_variable($id); // Course Module ID require_variable($id); // Course Module ID
Expand Down Expand Up @@ -77,7 +78,7 @@


$form = data_submitted(); $form = data_submitted();
$file = $_FILES["file"]; $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']) ) { if ($xml = glossary_read_imported_file($file['tmp_name']) ) {


$importedentries = 0; $importedentries = 0;
Expand All @@ -90,42 +91,51 @@


if ( $xmlglossary['NAME'][0]['#'] ) { if ( $xmlglossary['NAME'][0]['#'] ) {
unset($glossary); unset($glossary);
$glossary->name = addslashes(utf8_decode($xmlglossary['NAME'][0]['#'])); $glossary->name = addslashes(utf8_decode($xmlglossary['NAME'][0]['#']));
$glossary->course = $course->id; $glossary->course = $course->id;
$glossary->globalglossary = $xmlglossary['GLOBALGLOSSARY'][0]['#']; $glossary->globalglossary = $xmlglossary['GLOBALGLOSSARY'][0]['#'];
$glossary->entbypage = $xmlglossary['ENTBYPAGE'][0]['#']; $glossary->intro = addslashes(utf8_decode($xmlglossary['INTRO'][0]['#']));
$glossary->intro = addslashes(utf8_decode($xmlglossary['INTRO'][0]['#'])); $glossary->showspecial = $xmlglossary['SHOWSPECIAL'][0]['#'];
$glossary->showspecial = $xmlglossary['SHOWSPECIAL'][0]['#']; $glossary->showalphabet = $xmlglossary['SHOWALPHABET'][0]['#'];
$glossary->showalphabet = $xmlglossary['SHOWALPHABET'][0]['#']; $glossary->showall = $xmlglossary['SHOWALL'][0]['#'];
$glossary->showall = $xmlglossary['SHOWALL'][0]['#']; $glossary->timecreated = time();
$glossary->timecreated = time(); $glossary->timemodified = time();
$glossary->timemodified = time();


// Setting the default values if no values were passed // Setting the default values if no values were passed
if ( isset($xmlglossary['STUDENTCANPOST'][0]['#']) ) { 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 { } else {
$glossary->studentcanpost = $CFG->cnfstudentcanpost; $glossary->entbypage = $CFG->glossary_entbypage;
} }
if ( isset($xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#']) ) { if ( isset($xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#']) ) {
$glossary->allowduplicatedentries = $xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#']; $glossary->allowduplicatedentries = $xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#'];
} else { } else {
$glossary->allowduplicatedentries = $CFG->cnfallowdupentries; $glossary->allowduplicatedentries = $CFG->glossary_dupentries;
}
if ( isset($xmlglossary['DISPLAYFORMAT'][0]['#']) ) {
$glossary->allowduplicatedentries = $xmlglossary['DISPLAYFORMAT'][0]['#'];
} else {
$glossary->displayformat = 2;
} }
if ( isset($xmlglossary['ALLOWCOMMENTS'][0]['#']) ) { if ( isset($xmlglossary['ALLOWCOMMENTS'][0]['#']) ) {
$glossary->allowcomments = $xmlglossary['ALLOWCOMMENTS'][0]['#']; $glossary->allowcomments = $xmlglossary['ALLOWCOMMENTS'][0]['#'];
} else { } else {
$glossary->allowcomments = $CFG->cnfallowcomments; $glossary->allowcomments = $CFG->glossary_allowcomments;
} }
if ( isset($xmlglossary['USEDYNALINK'][0]['#']) ) { if ( isset($xmlglossary['USEDYNALINK'][0]['#']) ) {
$glossary->usedynalink = $xmlglossary['USEDYNALINK'][0]['#']; $glossary->usedynalink = $xmlglossary['USEDYNALINK'][0]['#'];
} else { } else {
$glossary->usedynalink = $CFG->cnflinkglossaries; $glossary->usedynalink = $CFG->glossary_linkentries;
} }
if ( isset($xmlglossary['DEFAULTAPPROVAL'][0]['#']) ) { if ( isset($xmlglossary['DEFAULTAPPROVAL'][0]['#']) ) {
$glossary->defaultapproval = $xmlglossary['DEFAULTAPPROVAL'][0]['#']; $glossary->defaultapproval = $xmlglossary['DEFAULTAPPROVAL'][0]['#'];
} else { } else {
$glossary->defaultapproval = $CFG->cnfapprovalstatus; $glossary->defaultapproval = $CFG->glossary_defaultapproval;
} }


// Include new glossary and return the new ID // Include new glossary and return the new ID
Expand All @@ -135,6 +145,47 @@
print_footer($course); print_footer($course);
exit; exit;
} else { } 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%"); print_simple_box(get_string("newglossarycreated","glossary"),"center","70%");
echo '<p>'; echo '<p>';
} }
Expand All @@ -150,16 +201,20 @@
for($i = 0; $i < sizeof($xmlentries); $i++) { for($i = 0; $i < sizeof($xmlentries); $i++) {
// Inserting the entries // Inserting the entries
$xmlentry = $xmlentries[$i]; $xmlentry = $xmlentries[$i];

unset($newentry); unset($newentry);
$newentry->concept = addslashes(trim(utf8_decode($xmlentry['#']['CONCEPT'][0]['#']))); $newentry->concept = addslashes(trim(utf8_decode($xmlentry['#']['CONCEPT'][0]['#'])));
$newentry->definition = addslashes(utf8_decode($xmlentry['#']['DEFINITION'][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; $permissiongranted = 1;
if ( $newentry->concept and $newentry->definition ) { if ( $newentry->concept and $newentry->definition ) {
if ( !$glossary->allowduplicatedentries ) { if ( !$glossary->allowduplicatedentries ) {
// checking if the entry is valid (checking if it is duplicated when should not be) // 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); $dupentry = get_record("glossary_entries","concept",$newentry->concept,"glossaryid",$glossary->id);
} else { } else {
$dupentry = get_record("glossary_entries","ucase(concept)",strtoupper($newentry->concept),"glossaryid",$glossary->id); $dupentry = get_record("glossary_entries","ucase(concept)",strtoupper($newentry->concept),"glossaryid",$glossary->id);
Expand All @@ -170,32 +225,27 @@
} }
} else { } else {
$permissiongranted = 0; $permissiongranted = 0;
} }
if ($permissiongranted) { if ($permissiongranted) {
$newentry->glossaryid = $glossary->id; $newentry->glossaryid = $glossary->id;
$newentry->sourceglossaryid = 0; $newentry->sourceglossaryid = 0;
$newentry->approved = 1; $newentry->approved = 1;
$newentry->userid = $USER->id; $newentry->userid = $USER->id;
$newentry->teacherentry = 1;
$newentry->format = $xmlentry['#']['FORMAT'][0]['#']; $newentry->format = $xmlentry['#']['FORMAT'][0]['#'];
$newentry->timecreated = time(); $newentry->timecreated = time();
$newentry->timemodified = time(); $newentry->timemodified = time();
$newentry->teacherentry = $xmlentry['#']['TEACHERENTRY'][0]['#'];

// Setting the default values if no values were passed // Setting the default values if no values were passed
if ( isset($xmlentry['#']['USEDYNALINK'][0]['#']) ) { if ( isset($xmlentry['#']['USEDYNALINK'][0]['#']) ) {
$newentry->usedynalink = $xmlentry['#']['USEDYNALINK'][0]['#']; $newentry->usedynalink = $xmlentry['#']['USEDYNALINK'][0]['#'];
} else { } else {
$newentry->usedynalink = $CFG->cnfusedynalink; $newentry->usedynalink = $CFG->glossary_linkentries;
}
if ( isset($xmlentry['#']['CASESENSITIVE'][0]['#']) ) {
$newentry->casesensitive = $xmlentry['#']['CASESENSITIVE'][0]['#'];
} else {
$newentry->casesensitive = $CFG->cnfcasesensitive;
} }
if ( isset($xmlentry['#']['FULLMATCH'][0]['#']) ) { if ( isset($xmlentry['#']['FULLMATCH'][0]['#']) ) {
$newentry->fullmatch = $xmlentry['#']['FULLMATCH'][0]['#']; $newentry->fullmatch = $xmlentry['#']['FULLMATCH'][0]['#'];
} else { } else {
$newentry->fullmatch = $CFG->cnffullmatch; $newentry->fullmatch = $CFG->glossary_fullmatch;
} }


if ( $newentry->id = insert_record("glossary_entries",$newentry) ) { if ( $newentry->id = insert_record("glossary_entries",$newentry) ) {
Expand Down Expand Up @@ -271,42 +321,42 @@
} }
// processed entries // processed entries
echo '<table border=0 width=100%>'; echo '<table border=0 width=100%>';
echo '<tr>';
echo '<td width=50% align=right>';
echo get_string("totalentries","glossary");
echo ':</td>';
echo '<td width=50%>';
echo $importedentries + $entriesrejected;
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width=50% align=right>';
echo get_string("importedentries","glossary");
echo ':</td>';
echo '<td width=50%>';
echo $importedentries;
if ( $entriesrejected ) {
echo ' <small>(' . get_string("rejectedentries","glossary") . ": $entriesrejected)</small>";
}
echo '</td>';
echo '</tr>';
if ( $catsincl ) {
echo '<tr>'; echo '<tr>';
echo '<td width=50% align=right>'; echo '<td width=50% align=right>';
echo get_string("totalentries","glossary"); echo get_string("importedcategories","glossary");
echo ':</td>'; echo ':</td>';
echo '<td width=50%>'; echo '<td width=50%>';
echo $importedentries + $entriesrejected; echo $importedcats;
echo '</td>'; echo '</td>';
echo '</tr>'; echo '</tr>';
echo '<tr>'; }
echo '<td width=50% align=right>';
echo get_string("importedentries","glossary");
echo ':</td>';
echo '<td width=50%>';
echo $importedentries;
if ( $entriesrejected ) {
echo ' <small>(' . get_string("rejectedentries","glossary") . ": $entriesrejected)</small>";
}
echo '</td>';
echo '</tr>';
if ( $catsincl ) {
echo '<tr>';
echo '<td width=50% align=right>';
echo get_string("importedcategories","glossary");
echo ':</td>';
echo '<td width=50%>';
echo $importedcats;
echo '</td>';
echo '</tr>';
}
echo '</table><hr width=75%>'; echo '</table><hr width=75%>';


// rejected entries // rejected entries
if ($rejections) { if ($rejections) {
echo '<center><table border=0 width=70%>'; echo '<center><table border=0 width=70%>';
echo '<tr><td align=center colspan=2 width=100%><strong>' . get_string("rejectionrpt","glossary") . '</strong></tr>'; echo '<tr><td align=center colspan=2 width=100%><strong>' . get_string("rejectionrpt","glossary") . '</strong></tr>';
echo $rejections; echo $rejections;
echo '</table></center><p><hr width=75%>'; echo '</table></center><p><hr width=75%>';
} }
} else { } else {
Expand Down
1 change: 1 addition & 0 deletions mod/glossary/lib.php
Expand Up @@ -1556,6 +1556,7 @@ function glossary_generate_export_file($glossary, $hook = "", $hook = 0) {
fwrite ($h,glossary_full_tag("INTRO",2,false,$glossary->intro)); 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("STUDENTCANPOST",2,false,$glossary->studentcanpost));
fwrite ($h,glossary_full_tag("ALLOWDUPLICATEDENTRIES",2,false,$glossary->allowduplicatedentries)); 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("SHOWSPECIAL",2,false,$glossary->showspecial));
fwrite ($h,glossary_full_tag("SHOWALPHABET",2,false,$glossary->showalphabet)); fwrite ($h,glossary_full_tag("SHOWALPHABET",2,false,$glossary->showalphabet));
fwrite ($h,glossary_full_tag("SHOWALL",2,false,$glossary->showall)); fwrite ($h,glossary_full_tag("SHOWALL",2,false,$glossary->showall));
Expand Down

0 comments on commit ae39746

Please sign in to comment.