]> git.mjollnir.org Git - moodle.git/commitdiff
- Global glossaries now available. All current rules apply to its entries.
authorwillcast <willcast>
Wed, 29 Oct 2003 23:33:54 +0000 (23:33 +0000)
committerwillcast <willcast>
Wed, 29 Oct 2003 23:33:54 +0000 (23:33 +0000)
lang/en/glossary.php
mod/glossary/db/mysql.php
mod/glossary/db/mysql.sql
mod/glossary/db/postgres7.sql
mod/glossary/dynalink.php
mod/glossary/edit.html
mod/glossary/edit.php
mod/glossary/lib.php
mod/glossary/mod.html
mod/glossary/showentry.php
mod/glossary/version.php

index 7d0cf64999786d64d298e15a2cbabe13449a92db..8bf6356ed141d5e29e73636bc87c3011b323f7d5 100644 (file)
@@ -59,8 +59,10 @@ $string['explainalphabet'] = "Browse the glossary using this index";
 $string['explainall'] = "Shows ALL entries on one page";
 $string['exportedentry'] = "Exported entry";
 $string['exporttomainglossary'] = "Export to main glossary";
+$string['fillfields'] = "Concept and definition are mandatory fields.";
 $string['fullmatch'] = "Match whole words only<br><small>(when automatically linked)</small>";
 $string['glossarytype'] = "Glossary Type";
+$string['isglobal'] = "Is this glossary global?";
 $string['mainglossary'] = "Main glossary";
 $string['modulename'] = "Glossary";
 $string['modulenameplural'] = "Glossaries";
index 20b5483844f2f605b2e534cb39dffa813ab7e880..e996b6ba9bc4512c004b46234fa0ce8ddf5ad8af 100644 (file)
@@ -118,6 +118,11 @@ function glossary_upgrade($oldversion) {
 
         execute_sql(" INSERT INTO {$CFG->prefix}log_display VALUES ('glossary', 'approve entry', 'glossary', 'name') ");
     }
+
+    if ( $oldversion < 2003102800 ) {
+        execute_sql( "ALTER TABLE `{$CFG->prefix}glossary`" .
+                     " ADD `globalglossary` TINYINT(2) UNSIGNED NOT NULL default '0' AFTER `defaultapproval`");
+    }
     return true;
 }
 
index 99276273fd784b936bba0b6683d7fe687852c485..1c19299bcb58b5d631331d5a5fa58f1b4382fd2f 100644 (file)
@@ -23,6 +23,7 @@ CREATE TABLE prefix_glossary (
      allowcomments tinyint(2) unsigned NOT NULL default '0',
      usedynalink tinyint(2) unsigned NOT NULL default '1',
      defaultapproval tinyint(2) unsigned NOT NULL default '1',
+     globalglossary tinyint(2) unsigned NOT NULL default '0',
      timecreated int(10) unsigned NOT NULL default '0',
      timemodified int(10) unsigned NOT NULL default '0',
      PRIMARY KEY  (id)
index 0f45bdd21c725629b7dbc91e342fd0906784cf27..cf6cfd2072f3b6e3b1e78f8138464a809153fd44 100644 (file)
@@ -22,6 +22,7 @@ CREATE TABLE prefix_glossary (
      showall int2 NOT NULL default '1',
      allowcomments int2 NOT NULL default '0',
      usedynalink int2 NOT NULL default '1',
+     globalglossary int2 NOT NULL default '0',
      timecreated int4 NOT NULL default '0',
      timemodified int4 NOT NULL default '0',
      PRIMARY KEY  (id)
index 21504fbc2b2122e72b1c742173cf25be64bac8ea..7762b41ee097edb939d1d312738bffea1dbf0b85 100644 (file)
         $GLOSSARY_CONCEPT_IS_ENTRY = 0;
         $GLOSSARY_CONCEPT_IS_CATEGORY = 1;
 
-        $glossarieslist = get_records_select("glossary", "usedynalink != 0 and course = $courseid","id");
+//        $glossarieslist = get_records_select("glossary", "usedynalink != 0 and (course = $courseid or global != 0)","id");
+        $glossarieslist = get_records_select("glossary", "usedynalink != 0 and (course = $courseid or globalglossary != 0)","globalglossary, id");
         if ( $glossarieslist ) {
             $glossaries = "";
             foreach ( $glossarieslist as $glossary ) {
                 $glossaries .= "$glossary->id,";
             }
             $glossaries=substr($glossaries,0,-1);
-
 ///         sorting by the lenght of the concept in order to assure that large concepts 
 ///            could be linked first, if they exist in the text to parse
             switch ($CFG->dbtype) {
@@ -34,7 +34,7 @@
                 break;
             }
             
-            $entries = get_records_select("glossary_entries", "glossaryid IN ($glossaries) AND usedynalink != 0 and approved != 0","$ebylenght glossaryid","id,glossaryid,concept,casesensitive,$GLOSSARY_CONCEPT_IS_ENTRY category,fullmatch");
+            $entries = get_records_select("glossary_entries", "glossaryid IN ($glossaries) AND usedynalink != 0 and approved != 0 and concept != ''","$ebylenght glossaryid","id,glossaryid,concept,casesensitive,$GLOSSARY_CONCEPT_IS_ENTRY category,fullmatch");
             $categories  = get_records_select("glossary_categories", "glossaryid IN ($glossaries)", "$cbylenght glossaryid,id","id,glossaryid,name concept, 1 casesensitive,$GLOSSARY_CONCEPT_IS_CATEGORY category, 1 fullmatch");
             if ( $entries and $categories ) {
                 $concepts = array_merge($entries, $categories);
@@ -53,7 +53,6 @@
                         $glossary = get_record("glossary","id",$concept->glossaryid);
                         $lastglossary = $glossary->id;
                     }
-
                     if ( $concept->category ) {
                         if ( $lastcategory != $concept->id ) {
                             $category = get_record("glossary_categories","id",$concept->id);
         }
         // getting ride of all other tags
         $final = array();
-        preg_match_all('/<(.+?)>/is',$text,$list_of_words);
+        preg_match_all('/<(.+?)>/is',$text,$list_of_tags);
 
-        foreach (array_unique($list_of_words[0]) as $key=>$value) {
+        foreach (array_unique($list_of_tags[0]) as $key=>$value) {
             $final['<|'.$key.'|>'] = $value;
         }
 
         if ( $excludes ) {
             $text = str_replace(array_keys($excludes),$excludes,$text);
         }
-        if ( isset($words) and $fullmatch ) {
-            if ($words) {
-                $text = str_replace(array_keys($words),$words,$text);
+        if ( $fullmatch ) {
+            if ( isset($words) ) {
+                if ($words) {
+                    $text = str_replace(array_keys($words),$words,$text);
+                }
             }
         }
         return stripslashes($text);
index a2b17d7b4652e6c62fb0c125cab99bcf166320e6..86f381042b6b25f3b1fcd6ffaa18577e92c3d157 100644 (file)
@@ -1,6 +1,16 @@
 <center>
 <form name="form" method="post" <?=$onsubmit ?> action="edit.php" enctype="multipart/form-data">
 <table  class=generalbox cellpadding=5 bgcolor="<?php p($THEME->cellheading)?>">
+<?PHP
+if (isset($errors)) {
+?>
+    <tr valign=top>
+        <td colspan=2 align=center><strong><font color=red><?PHP p($errors) ?></font></strong>
+        </td>
+    </tr>
+<?PHP
+}
+?>
 <tr valign=top>
     <td align=right><p><b><?php echo get_string("concept","glossary") ?>:</b></p></td>
     <td>
index 2a2413ebc4bd8a165f29d3b0c556cbb6e676bff7..c49d82de89e9e62cf7d7d6cb073435c8f35f4e20 100644 (file)
@@ -21,7 +21,7 @@ if (! $course = get_record("course", "id", $cm->course)) {
 
 require_login($course->id);
 
-if (isguest()) {
+if ( isguest() ) {
     error("Guests are not allowed to edit glossaries", $_SERVER["HTTP_REFERER"]);
 }
 
@@ -47,6 +47,34 @@ if ( $confirm ) {
     $newentry->fullmatch = $form->fullmatch;
     $newentry->timemodified = $timenow;                
 
+    if ($form->concept == '' or trim($form->text) == '' ) {
+        $errors = get_string('fillfields','glossary');
+        $strglossary = get_string("modulename", "glossary");
+        $strglossaries = get_string("modulenameplural", "glossary");
+        $stredit = get_string("edit");
+
+        if ($usehtmleditor = can_use_richtext_editor()) {
+            $defaultformat = FORMAT_HTML;
+            $onsubmit = "onsubmit=\"copyrichtext(form.text);\"";
+        } else {
+            $defaultformat = FORMAT_MOODLE;
+            $onsubmit = "";
+        }
+
+        print_header(strip_tags("$course->shortname: $glossary->name"), "$course->fullname",
+             "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> 
+              <A HREF=\"index.php?id=$course->id\">$strglossaries</A> -> 
+              <A HREF=\"view.php?id=$cm->id\">$glossary->name</A> -> $stredit", "form.text",
+              "", true, "", navmenu($course, $cm));
+
+        print_heading($glossary->name);
+
+        include("edit.html");
+
+        print_footer($course);
+        die;
+    }
+
     if ($e) {
         $newentry->id = $e;
     
@@ -123,7 +151,7 @@ if ( $confirm ) {
             }
         }
     }
-    redirect("view.php?id=$cm->id&eid=$newentry->id");
+    redirect("view.php?id=$cm->id&eid=$newentry->id&tab=$tab&cat=$cat");
     die;
 } else {
     if ($e) {
@@ -154,7 +182,7 @@ $stredit = get_string("edit");
 
 if ($usehtmleditor = can_use_richtext_editor()) {
     $defaultformat = FORMAT_HTML;
-    $onsubmit = "onsubmit=\"copyrichtext(theform.text);\"";
+    $onsubmit = "onsubmit=\"copyrichtext(form.text);\"";
 } else {
     $defaultformat = FORMAT_MOODLE;
     $onsubmit = "";
@@ -163,7 +191,7 @@ if ($usehtmleditor = can_use_richtext_editor()) {
 print_header(strip_tags("$course->shortname: $glossary->name"), "$course->fullname",
              "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> 
               <A HREF=\"index.php?id=$course->id\">$strglossaries</A> -> 
-              <A HREF=\"view.php?id=$cm->id\">$glossary->name</A> -> $stredit", "theform.text",
+              <A HREF=\"view.php?id=$cm->id\">$glossary->name</A> -> $stredit", "form.text",
               "", true, "", navmenu($course, $cm));
 
 print_heading($glossary->name);
index 55f55cc32ac7f156d97765c2e3146b35d2b6419c..1d4d25c5e0a25b00cb32a6e80dbea46a0b874f52 100644 (file)
@@ -22,6 +22,12 @@ function glossary_add_instance($glossary) {
 /// will create a new instance and return the id number
 /// of the new instance.
 
+    if ( !isset($glossary->globalglossary) ) {
+        $glossary->globalglossary = 0;
+    } elseif ( !isadmin() ) {
+        $glossary->globalglossary = 0;
+    }
+
     $glossary->timecreated = time();
     $glossary->timemodified = $glossary->timecreated;
 
@@ -36,6 +42,10 @@ function glossary_update_instance($glossary) {
 /// (defined by the form in mod.html) this function
 /// will update an existing instance with new data.
 
+    if ( !isadmin() ) {
+        unset($glossary->globalglossary);
+    }
+
     $glossary->timemodified = time();
     $glossary->id = $glossary->instance;
 
@@ -1022,7 +1032,7 @@ function glossary_print_dynaentry($courseid, $entries) {
             if (! $course = get_record("course", "id", $glossary->course)) {
                 error("Glossary is misconfigured - don't know what course it's from");
             }
-            if (!$cm = get_coursemodule_from_instance("glossary", $entry->glossaryid, $courseid) ) {
+            if (!$cm = get_coursemodule_from_instance("glossary", $entry->glossaryid, $glossary->course) ) {
                 error("Glossary is misconfigured - don't know what course module it is ");
             }
             glossary_print_entry($course, $cm, $glossary, $entry);
index 978f54ecfdfab0348d4d223a3cc69c34d3d97f38..f60b5f325093ef50d681cc3673eae76f751d0bb7 100644 (file)
@@ -38,6 +38,9 @@ if (!isset($form->studentcanpost)) {
 if (!isset($form->usedynalink)) {
     $form->usedynalink = 1;
 }
+if ( !isset($form->globalglossary) ) {
+    $form->globalglossary = 0;
+}
 ?>
 <FORM name="form" method="post" action="<?=$ME ?>">
 <CENTER>
@@ -67,6 +70,28 @@ if (!isset($form->usedynalink)) {
 </tr>
 <!-- More rows go in here... -->
 <?php
+if (isadmin() ) {
+?>
+<TR valign=top>
+    <TD align=right><P><B><?php echo get_string("isglobal", "glossary") ?>:</B></P></TD>
+    <TD>
+<?php
+    $selected = "";
+    if ( isset($form->globalglossary) ) {
+        if ($form->globalglossary) {
+            $selected = "checked";
+        }
+    }
+?> 
+  <input type="checkbox" name="globalglossary" value=1 <?PHP p($selected)?>> <?php helpbutton("globalglossary", get_string("globallossary", "glossary"), "glossary") ?>
+    </TD>
+</TR>
+<?php
+} else {
+   echo '<INPUT type="hidden" name=globalglossary value="' . $form->globalglossary . '">';
+}
+?>
+<?php
 $mainglossary = get_record("glossary","mainglossary",1,"course",$form->course);
 if (!$mainglossary or $mainglossary->id == $form->instance ) {
 ?>
@@ -78,7 +103,8 @@ if (!$mainglossary or $mainglossary->id == $form->instance ) {
    if ( $form->mainglossary ) {
       echo "selected";
    }
-   ?>><?php echo get_string("mainglossary", "glossary") ?></option>
+?>>
+<?php echo get_string("mainglossary", "glossary") ?></option>
   <option value="0" <?php
    if ( !$form->mainglossary ) {
       echo "selected";
index 9687fad3504659380b09a6fae27fa9753261211b..610905ce473918b9ce3f96b1b278fb239bd333bd 100644 (file)
@@ -10,7 +10,7 @@
                                   " where e.glossaryid = g.id and".
                                       " (e.casesensitive != 0 and ucase(concept) = '" . strtoupper(trim($concept)). "' or".
                                       " e.casesensitive = 0 and concept = '$concept') and".
-                                      " g.course = $courseid and".
+                                      " (g.course = $courseid or g.globalglossary) and".
                                       " e.usedynalink != 0 and g.usedynalink != 0");
     
     glossary_print_dynaentry($courseid, $entries);
index 1b01d94ac43ed24f43ac86489e9663d42c512345..eac0bd7f6c539aba58eaf9c49f8dad90db8c0264 100644 (file)
@@ -5,7 +5,7 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2003102000;  // The current module version (Date: YYYYMMDDXX)
+$module->version  = 2003102800;  // The current module version (Date: YYYYMMDDXX)
 $module->cron     = 0;           // Period for cron to check this module (secs)
 
 $release = "0.5 development";   // User-friendly version number