From ad58adac109d37179ed223c926d4e740b7ad17a8 Mon Sep 17 00:00:00 2001
From: willcast <willcast>
Date: Mon, 29 Sep 2003 03:06:30 +0000
Subject: [PATCH] - Exported entries are now linked instead of copied to the
 main glossary. - Short tags are gone. - Little changes in ES language.

---
 lang/en/glossary.php                      |   4 +-
 lang/en/help/glossary/mainglossary.html   |   2 +-
 lang/en/help/glossary/studentcanpost.html |   5 +-
 lang/es/glossary.php                      |  50 ++++----
 lang/es/help/glossary/mainglossary.html   |   9 +-
 lang/es/help/glossary/studentcanpost.html |  12 +-
 mod/glossary/backuplib.php                |   5 +-
 mod/glossary/db/mysql.php                 |   6 +
 mod/glossary/db/mysql.sql                 |   1 +
 mod/glossary/db/oci8po.sql                |   9 +-
 mod/glossary/db/postgres7.sql             |   1 +
 mod/glossary/deleteentry.php              |  96 +++++++-------
 mod/glossary/edit.html                    |  30 ++---
 mod/glossary/edit.php                     |   3 +-
 mod/glossary/editcategories.html          |  10 +-
 mod/glossary/editcategories.php           |  77 ++++++------
 mod/glossary/exportentry.php              |  51 +++-----
 mod/glossary/lib.php                      |  69 +++++++---
 mod/glossary/minus.gif                    | Bin 0 -> 839 bytes
 mod/glossary/mod.html                     | 145 +++++++++++-----------
 mod/glossary/restorelib.php               |   9 +-
 mod/glossary/version.php                  |   4 +-
 mod/glossary/view.php                     |  51 ++++----
 23 files changed, 363 insertions(+), 286 deletions(-)
 create mode 100644 mod/glossary/minus.gif

diff --git a/lang/en/glossary.php b/lang/en/glossary.php
index 03f63c30f0..567c79edd1 100644
--- a/lang/en/glossary.php
+++ b/lang/en/glossary.php
@@ -34,6 +34,7 @@ $string['entryexported'] = "Entry succesfully exported.";
 $string['explainspecial'] = "<b>Special</b> will show all concepts that do not begin with a letter.<br>";
 $string['explainalphabet'] = "Select the letter you want to look for.<p>";
 $string['explainall'] = "<b>ALL</b> will show all entries in one page.";
+$string['exportedentry'] = "Exported entry";
 $string['exporttomainglossary'] = "Export to main glossary";
 $string['glossarytype'] = "Glossary Type";
 $string['mainglossary'] = "Main glossary";
@@ -45,13 +46,14 @@ $string['noentries'] = "No entries found in this section";
 $string['noentry'] = "No entry found.";
 $string['searchconcept'] = "Search:";
 $string['searchindefinition'] = "Search in concept AND definitions?";
-$string['secundaryglossary'] = "Secondary glossary";
+$string['secondaryglossary'] = "Secondary glossary";
 $string['showspecial'] = "Show 'Special' link";
 $string['showalphabet'] = "Show alphabet";
 $string['showall'] = "Show 'ALL' link";
 $string['special'] = "Special";
 $string['standardview'] = "Standard View";
 $string['studentcanpost'] = "Students can add entries";
+$string['warningstudentcapost'] = "(This apply only if the glossary is not the main one)";
 $string['writtenby'] = "By";
 
 ?>
diff --git a/lang/en/help/glossary/mainglossary.html b/lang/en/help/glossary/mainglossary.html
index 3bd1afcce3..de29e62db5 100644
--- a/lang/en/help/glossary/mainglossary.html
+++ b/lang/en/help/glossary/mainglossary.html
@@ -2,4 +2,4 @@
 
 <P>The system allows to export entries from any secondary glossary to the main one of the course.
 <p>In order to do this, you should specify which glossary is the main one.
-<p>Note: You can have only one main glossary per course.
+<p>Note: You can have only one main glossary per course and its entries could be updated or deleted by teachers only.
diff --git a/lang/en/help/glossary/studentcanpost.html b/lang/en/help/glossary/studentcanpost.html
index 6d7af75445..957d3eaf5d 100644
--- a/lang/en/help/glossary/studentcanpost.html
+++ b/lang/en/help/glossary/studentcanpost.html
@@ -1,4 +1,5 @@
 <P ALIGN=CENTER><B>Students can post entries</B></P>
 
-<P>You can specify whether a user can or cannot add, edit or delete his/her own entries in this glossary.
-<p><b>Note:</b> A teacher can edit or delete any entry at any time.
\ No newline at end of file
+<P>You can specify whether a user can or cannot add, edit or delete his/her own entries.
+Entries exported to a main glossary can be updated or deleted by teachers only.
+<p><b>Note:</b> A teacher can edit or delete any entry at any time. This variable is not used if the glossary is the main one.
diff --git a/lang/es/glossary.php b/lang/es/glossary.php
index 83b3c32f8e..947a4963e7 100644
--- a/lang/es/glossary.php
+++ b/lang/es/glossary.php
@@ -1,58 +1,58 @@
 <?PHP // $Id$ 
       // glossary.php - created with Moodle 1.1 (2003082800)
-
-
 $string['addentry'] = "Agregar entrada";
-$string['allcategories'] = "Todas las categorías";
 $string['allentries'] = "TODAS";
+$string['allcategories'] = "Todas las categorías";
 $string['allowduplicatedentries'] = "Permitir entradas duplicadas";
-$string['alphabet'] = "A|B|C|CH|D|E|F|G|H|I|J|K|L|LL|M|N|Ñ|O|P|Q|R|S|T|U|V|W|X|Y|Z";
-$string['areyousuredelete'] = "¿Está seguro que desea borrar esta entrada?";
+$string['alphabet'] = "A|B|C|D|E|F|G|H|I|J|K|L|M|N|Ñ|O|P|Q|R|S|T|U|V|W|X|Y|Z";
+$string['areyousuredelete'] = "¿Está seguro que desea borrarla?";
 $string['attachment'] = "Adjunto";
-$string['back'] = "Atrás";
+$string['back'] = "Volver";
 $string['categories'] = "Categorías";
+$string['categoryview'] = "Vista por Categoría";
 $string['category'] = "Categoría";
-$string['categorydeleted'] = "Categoría borrada";
-$string['categoryview'] = "Por categoría";
+$string['categorydeleted'] = "Categoría eliminada";
 $string['concept'] = "Concepto";
 $string['concepts'] = "Conceptos";
 $string['definition'] = "Definición";
 $string['definitions'] = "Definiciones";
 $string['deleteentry'] = "Borrar entrada";
-$string['deletingnoneemptycategory'] = "Borrar una categoría no borrará las entradas. Si desea borrar las entradas tendrá que hacerlo manualmente.";
-$string['displayformat'] = "¿Formato de muestra?";
-$string['displayformat1'] = "Completo con autor.";
-$string['displayformat2'] = "Completo sin autor.";
+$string['deletingnoneemptycategory'] = "Si una categoría es eliminada por consiguiente su relación con las entradas también lo será. Si desea eliminar las entradas, tendrá que hacerlo manualmente.";
+$string['displayformat'] = "Formato de muestra de entradas";
 $string['displayformatdefault'] = "Simple, estilo diccionario";
-$string['editcategories'] = "Editar categorías";
+$string['displayformat1'] = "Completo sin autor.";
+$string['displayformat2'] = "Completo con autor.";
 $string['editentry'] = "Editar entrada";
+$string['editcategories'] = "Editar categorías";
 $string['entries'] = "Entradas";
-$string['entrieswithoutcategory'] = "Entradas sin categorías";
+$string['entrieswithoutcategory'] = "Entradas sin categoría";
 $string['entry'] = "Entrada";
 $string['entryalreadyexist'] = "Esta entrada ya existe.";
 $string['entrydeleted'] = "Entrada borrada.";
 $string['entryexported'] = "Entrada exportada con éxito.";
-$string['explainall'] = "<b>Todas</b> mostrará todas las entradas en una página.";
-$string['explainalphabet'] = "Seleccione la letra inicial que usted desea buscar.<p> ";
-$string['explainspecial'] = "<b>Especial</b> mostrará todos los conceptos que no comienzan con una letra.<br>";
-$string['exporttomainglossary'] = "Exportar todo el glosario";
+$string['explainspecial'] = "<b>Especial</b> mostrará todos los conceptos que comiencen con símbolos.<br>";
+$string['explainalphabet'] = "Seleccione la letra que desea buscar.<p>";
+$string['explainall'] = "<b>TODAS</b> mostrará todas las entradas en una página.";
+$string['exporttomainglossary'] = "Exportar al glosario principal";
+$string['exportedentry'] = "Entrada exportada";
 $string['glossarytype'] = "Tipo de glosario";
 $string['mainglossary'] = "Glosario principal";
 $string['modulename'] = "Glosario";
 $string['modulenameplural'] = "Glosarios";
 $string['newglossaryentries'] = "Nuevas entradas en el glosario:";
 $string['nocategorized'] = "Sin categoría";
-$string['noentries'] = "No se encontraron entradas en esta sección";
+$string['noentries'] = "No se encontraro entradas en esta sección";
 $string['noentry'] = "No se econtró ninguna entrada.";
 $string['searchconcept'] = "Buscar:";
-$string['searchindefinition'] = "¿Buscar en conceptos Y definiciones?";
-$string['secundaryglossary'] = "Glosario secundario";
-$string['showall'] = "Mostrar el enlace 'Todas'";
-$string['showalphabet'] = "Mostrar el alfabeto";
-$string['showspecial'] = "Mostrar el enlace 'Especial'";
+$string['searchindefinition'] = "¿Buscar en conceptos y definiciones?";
+$string['secondaryglossary'] = "Glosario secundario";
+$string['showspecial'] = "Mostrar enlace 'Especial'";
+$string['showalphabet'] = "Mostrar alfabeto";
+$string['showall'] = "Mostrar enlace 'TODAS'";
 $string['special'] = "Especial";
-$string['standardview'] = "Visualización estándar";
+$string['standardview'] = "Vista Normal";
 $string['studentcanpost'] = "Los estudiantes pueden agregar entradas";
+$string['warningstudentcapost'] = "(Esto sólo aplica si el glosario no es principal)";
 $string['writtenby'] = "Por";
 
 ?>
diff --git a/lang/es/help/glossary/mainglossary.html b/lang/es/help/glossary/mainglossary.html
index e0606fbb3d..4b68b18c86 100644
--- a/lang/es/help/glossary/mainglossary.html
+++ b/lang/es/help/glossary/mainglossary.html
@@ -1,4 +1,5 @@
-<P ALIGN=CENTER><B>Es este el glosario principal del curso?</B></P>
-
-<P>El sistema permite exportar definiciones de los glosarios secundarios al glosario principal del sistema.
-<p>Para hacer esto, usted debe especificar cual de los glosarios es el principal. Note que sólo puede tener un glosario principal por curso.
\ No newline at end of file
+<P ALIGN=CENTER><B>Es este el glosario principal del curso?</B></P>
+
+<P>El sistema permite exportar definiciones de los glosarios secundarios al glosario principal del sistema.
+<p>Para hacer esto, usted debe especificar cual de los glosarios es el principal.
+<p>Note que sólo puede tener un glosario principal por curso y sus entradas sólo podrán ser editadas o borradas por un profesor.
diff --git a/lang/es/help/glossary/studentcanpost.html b/lang/es/help/glossary/studentcanpost.html
index b913616e99..4cbbe22e65 100644
--- a/lang/es/help/glossary/studentcanpost.html
+++ b/lang/es/help/glossary/studentcanpost.html
@@ -1,5 +1,7 @@
-<P ALIGN=CENTER><B>Los estudiantes podrán agregar definiciones?</B></P>
-
-<P>Indique si desea que los estudiantes puedan o no agregar definiciones al glosario.
-
-<p>Si seleccionan que en efecto pueden hacerlo, el sistema le permitirá, además, modificar y eliminar sus propias definiciones.
+<P ALIGN=CENTER><B>Los estudiantes podrán agregar definiciones?</B></P>
+
+<P>Puede especificar si los estudiantes pueden o no agregar, modificar y eliminar sus propias definiciones al glosario.
+Las entradas exportadas a un glosario principal, sólo podrán ser editadas o borradas por un profesor.
+<p>Un profesor puede modificar o borrar cualquier entrada.
+<p>Esta variable no tiene efecto si el glosario es principal.
+
diff --git a/mod/glossary/backuplib.php b/mod/glossary/backuplib.php
index 39b7b55fd8..0b0fe07552 100644
--- a/mod/glossary/backuplib.php
+++ b/mod/glossary/backuplib.php
@@ -28,7 +28,7 @@
         $status = true;
 
         //Iterate over glossary table
-        $glossaries = get_records ("glossary","course",$preferences->backup_course,"id");
+        $glossaries = get_records ("glossary","course",$preferences->backup_course,"mainglossary");
         if ($glossaries) {
             foreach ($glossaries as $glossary) {
                 //Start mod
@@ -80,7 +80,7 @@
                 fwrite ($bf,full_tag("GLOSSARYID",6,false,$glo_cat->glossaryid));
                 fwrite ($bf,full_tag("NAME",6,false,$glo_cat->name));
 
-                $entries = get_records("glossary_entries_categories","categoryid",$glo_cat->id,"entryid");
+                $entries = get_records("glossary_entries_categories","categoryid",$glo_cat->id,"mainglossary");
                 if ($entries) {
                     $status =fwrite ($bf,start_tag("ENTRIES",6,true));
                     foreach ($entries as $entry) {
@@ -129,6 +129,7 @@
                     fwrite ($bf,full_tag("DEFINITION",6,false,$glo_ent->definition));
                     fwrite ($bf,full_tag("FORMAT",6,false,$glo_ent->format));
                     fwrite ($bf,full_tag("ATTACHMENT",6,false,$glo_ent->attachment));
+                    fwrite ($bf,full_tag("SOURCEGLOSSARYID",6,false,$glo_ent->sourceglossaryid));
                     fwrite ($bf,full_tag("TIMECREATED",6,false,$glo_ent->timecreated));
                     fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$glo_ent->timemodified));
                     fwrite ($bf,full_tag("TEACHERENTRY",6,false,$glo_ent->teacherentry));
diff --git a/mod/glossary/db/mysql.php b/mod/glossary/db/mysql.php
index 10e386dbd4..2fb33b28b9 100644
--- a/mod/glossary/db/mysql.php
+++ b/mod/glossary/db/mysql.php
@@ -59,6 +59,12 @@ function glossary_upgrade($oldversion) {
         execute_sql("ALTER TABLE `{$CFG->prefix}glossary_entries_categories` DROP PRIMARY KEY ");
         execute_sql("ALTER TABLE `{$CFG->prefix}glossary_entries_categories` ADD `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
     }
+    
+    if ( $oldversion < 2003092400 ) {
+        execute_sql( "ALTER TABLE `{$CFG->prefix}glossary_entries` " .
+                    "ADD `sourceglossaryid` INT(10) unsigned NOT NULL DEFAULT '0' AFTER `attachment` " );
+
+    }
 
     return true;
 }
diff --git a/mod/glossary/db/mysql.sql b/mod/glossary/db/mysql.sql
index e6803406de..06e34348fb 100644
--- a/mod/glossary/db/mysql.sql
+++ b/mod/glossary/db/mysql.sql
@@ -39,6 +39,7 @@ CREATE TABLE prefix_glossary_entries (
      timecreated int(10) unsigned NOT NULL default '0',
      timemodified int(10) unsigned NOT NULL default '0',
      teacherentry tinyint(2) unsigned NOT NULL default '0',
+     sourceglossaryid int(10) unsigned NOT NULL '0',
      PRIMARY KEY  (id)
 ) TYPE=MyISAM COMMENT='all glossary entries';
 
diff --git a/mod/glossary/db/oci8po.sql b/mod/glossary/db/oci8po.sql
index 2da8a15d77..b9738b92db 100755
--- a/mod/glossary/db/oci8po.sql
+++ b/mod/glossary/db/oci8po.sql
@@ -61,7 +61,8 @@ CREATE TABLE prefix_glossary_entries (
   attachment varchar2(100) default '' not null,
   timecreated number(10) default '0' not null,
   timemodified number(10) default '0' not null,
-  teacherentry number(2) default '0' not null
+  teacherentry number(2) default '0' not null,
+  sourceglossaryid number(10) default '0' not null
 );
 
 COMMENT on table prefix_glossary_entries is 'all glossary entries';
@@ -155,9 +156,15 @@ rem
 
 INSERT INTO prefix_log_display VALUES ('glossary', 'add', 'glossary', 'name');
 INSERT INTO prefix_log_display VALUES ('glossary', 'update', 'glossary', 'name');
+INSERT INTO prefix_log_display VALUES ('glossary', 'delete', 'glossary', 'name');
 
 INSERT INTO prefix_log_display VALUES ('glossary', 'view', 'glossary', 'name');
 INSERT INTO prefix_log_display VALUES ('glossary', 'view all', 'glossary', 'name');
 
 INSERT INTO prefix_log_display VALUES ('glossary', 'add entry', 'glossary', 'name');
 INSERT INTO prefix_log_display VALUES ('glossary', 'update entry', 'glossary', 'name');
+INSERT INTO prefix_log_display VALUES ('glossary', 'delete entry', 'glossary', 'name');
+
+INSERT INTO prefix_log_display VALUES ('glossary', 'add category', 'glossary', 'name');
+INSERT INTO prefix_log_display VALUES ('glossary', 'update category', 'glossary', 'name');
+INSERT INTO prefix_log_display VALUES ('glossary', 'delete category', 'glossary', 'name');
diff --git a/mod/glossary/db/postgres7.sql b/mod/glossary/db/postgres7.sql
index 24035e989e..81631aaeee 100644
--- a/mod/glossary/db/postgres7.sql
+++ b/mod/glossary/db/postgres7.sql
@@ -39,6 +39,7 @@ CREATE TABLE prefix_glossary_entries (
      timecreated int4 NOT NULL default '0',
      timemodified int4 NOT NULL default '0',
      teacherentry int2 NOT NULL default '0',
+     sourceglossaryid int4 NOT NULL default '0',
      PRIMARY KEY(id)
 );
 
diff --git a/mod/glossary/deleteentry.php b/mod/glossary/deleteentry.php
index 4d4e334040..ef773ecb7c 100644
--- a/mod/glossary/deleteentry.php
+++ b/mod/glossary/deleteentry.php
@@ -6,7 +6,7 @@
     require_variable($id);    // course module ID
     require_variable($mode);  // edit or delete
     optional_variable($go);  // commit the operation?
-    optional_variable($entry);  // edit or delete
+    optional_variable($entry);  // entry id
 
     $strglossary = get_string("modulename", "glossary");
     $strglossaries = get_string("modulenameplural", "glossary");
@@ -47,48 +47,58 @@
 /// If data submitted, then process and store.
     
     if ($mode == "edit" or $mode == "delete" ) {
-	echo "<p>";
-	if ( isteacher($cm->id) or $glossary->studentcanpost ) {
-		if ($go) {	// the operation was confirmed.
-			if ( $mode == "delete") {
-				glossary_delete_old_attachments($entry);
-				delete_records("glossary_entries","id", $entry);				
-				print_simple_box_start("center","40%", "#FFBBBB");
-				echo "<center>$entrydeleted"; //CAMBIAR
-				echo "</center>";
-				print_simple_box_end();
-			}
-    			print_footer($course);
-                  add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&currentview=$currentview&cat=$cat", $entry);
-			redirect("view.php?id=$cm->id&currentview=$currentview&cat=$cat");
-		} else {		// the operation has not been confirmed yet so ask the user to do so
-			if ( $mode == "delete") {				
-				print_simple_box_start("center","40%", "#FFBBBB");
-				echo "<center><b>$entryfields->concept</b><br>$strareyousuredelete";
-				
-				?>
-                    <form name="form" method="post" action="deleteentry.php">
-
-                    <input type="hidden" name=id 		   value="<?php p($cm->id) ?>">
-                    <input type="hidden" name=mode         value="delete">
-                    <input type="hidden" name=go       value="1">
-                    <input type="hidden" name=entry         value="<?php p($entry) ?>">
-                    <input type="hidden" name=currentview value=<? p($currentview) ?>>
-                    <input type="hidden" name=cat=<? p($cat) ?>>
-
-                    <input type="submit" value=" <?php print_string("yes")?> ">
-                    <input type=button value=" <?php print_string("no")?> " onclick="javascript:history.go(-1);">
-
-                    </form>
-               	</center>
-               	<?
-				print_simple_box_end();
-			}
-		} 
-	} else {
-		error("You are not allowed to edit or delete entries");
-	}
-    } else {
+    	echo "<p>";
+    	if ( isteacher($cm->id) or $glossary->studentcanpost ) {
+    		if ($go) {	// the operation was confirmed.
+    			if ( $mode == "delete") {
+    			    // if it is an imported entry, just delete the relation
+    			    $entry = get_record("glossary_entries","id", $entry);
+    			    if ( $entry->sourceglossaryid ) {
+    			        $entry->glossaryid = $entry->sourceglossaryid;
+    			        $entry->sourceglossaryid = 0;
+                        if (! update_record("glossary_entries", $entry)) {
+                   	        error("Could not update your glossary");
+               	        }
+    			    } else {
+    				    glossary_delete_old_attachments($entry->id);
+    				    delete_records("glossary_entries","id", $entry->id);				
+    			    }
+    			
+                    print_simple_box_start("center","40%", "#FFBBBB");
+    				echo "<center>$entrydeleted"; //CAMBIAR
+    				echo "</center>";
+    				print_simple_box_end();
+    			}
+        			print_footer($course);
+                      add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&currentview=$currentview&cat=$cat", $entry);
+    			redirect("view.php?id=$cm->id&currentview=$currentview&cat=$cat");
+    		} else {		// the operation has not been confirmed yet so ask the user to do so
+    			if ( $mode == "delete") {				
+    				print_simple_box_start("center","40%", "#FFBBBB");
+    				echo "<center><b>$entryfields->concept</b><br>$strareyousuredelete";
+    				
+    				?>
+                        <form name="form" method="post" action="deleteentry.php">
+
+                        <input type="hidden" name=id 		   value="<?php p($cm->id) ?>">
+                        <input type="hidden" name=mode         value="delete">
+                        <input type="hidden" name=go       value="1">
+                        <input type="hidden" name=entry         value="<?php p($entry) ?>">
+                        <input type="hidden" name=currentview value=<?php p($currentview) ?>>
+                        <input type="hidden" name=cat=<?php p($cat) ?>>
+
+                        <input type="submit" value=" <?php print_string("yes")?> ">
+                        <input type=button value=" <?php print_string("no")?> " onclick="javascript:history.go(-1);">
+
+                        </form>
+                   	</center>
+                   	<?php
+    				print_simple_box_end();
+    			}
+    		}
+    	} else {
+    		error("You are not allowed to edit or delete entries");
+    	}
     }
     print_footer($course);
 ?>
diff --git a/mod/glossary/edit.html b/mod/glossary/edit.html
index 5482caf73c..c173ac0f07 100644
--- a/mod/glossary/edit.html
+++ b/mod/glossary/edit.html
@@ -1,37 +1,39 @@
-<?
+<?php
 	global $CFG, $THEME;
     	require_once("../../config.php");
 ?>
 <FORM name="theform" method="post" <?=$onsubmit ?> action="edit.php" enctype="multipart/form-data">
-<table  class=generalbox cellpadding=5 bgcolor="<? p($THEME->cellheading)?>">
+<table  class=generalbox cellpadding=5 bgcolor="<?php p($THEME->cellheading)?>">
 <tr valign=top>
     <td align=right><p><b><?php echo get_string("concept","glossary") ?>:</b></p></td>
     <td>
-        <INPUT type="text" name="concept" size=30 value="<? p($form->concept) ?>">
+        <INPUT type="text" name="concept" size=30 value="<?php p($form->concept) ?>">
     </td>
 </tr>
 <tr valign=top>
     <td align=right><p><b><?php echo get_string("categories","glossary") ?>:</b></p></td>
     <td>	
-	<?
+	<?php
 		$categories = get_records("glossary_categories","glossaryid",$glossary->id);
 		echo "<select size=\"6\" name=\"categories[]\" multiple=\"yes\">";
 		echo "<option value=0>" . get_string("nocategorized","glossary") . "</optioon>";
 
-		foreach ( $categories as $category ) {
-			echo "  <option ";
+		if ( $categories ) {
+            foreach ( $categories as $category ) {
+			    echo "  <option ";
 
-			if ( record_exists("glossary_entries_categories","entryid",$entry->id,"categoryid",$category->id) ) {
-				echo "selected " ;
-			}
-			echo "value=\"$category->id\">$category->name</option>\n";
+			    if ( record_exists("glossary_entries_categories","entryid",$entry->id,"categoryid",$category->id) ) {
+				    echo "selected " ;
+			    }
+			    echo "value=\"$category->id\">$category->name</option>\n";
+            }
 		}
 	?>
 	</select>
     </td>
 </tr>
 <tr valign=top>
-    <td align=right><p><b><? echo get_string("definition","glossary") ?>:</b></p>
+    <td align=right><p><b><?php echo get_string("definition","glossary") ?>:</b></p>
     <font size="1">
      <?php
         helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
@@ -75,7 +77,7 @@
 <tr>
 <td colspan=2>
 	<p align=center>
-	<? if ($entry->id) {
+	<?php if ($entry->id) {
 		echo "<input type=\"hidden\" name=entry value=\"$entry->id\">";
    	 }
 	?>
@@ -83,8 +85,8 @@
 	<input type="hidden" name=currentview value="<?=$currentview ?>">
 	<input type="hidden" name=cat value="<?=$cat ?>">
 
-	<input type="submit" value="<? print_string("savechanges") ?>">
-	<input type="reset" value="<? print_string("revert") ?>">
+	<input type="submit" value="<?php print_string("savechanges") ?>">
+	<input type="reset" value="<?php print_string("revert") ?>">
 	</P>
 </td>
 </tr>
diff --git a/mod/glossary/edit.php b/mod/glossary/edit.php
index 99467bcc7f..63d4ec9a7b 100644
--- a/mod/glossary/edit.php
+++ b/mod/glossary/edit.php
@@ -95,10 +95,11 @@ if ($e) {
                 $newentry->timecreated = time();
                 $newentry->timemodified = time();
                 $newentry->teacherentry = isteacher($course->id,$USER->id);
+                $newentry->sourceglossaryid = 0;
 
                 $PermissionGranted = 1;
                 if ( !$glossary->allowduplicatedentries ) {
-                       $dupentries = get_record("glossary_entries","UCASE(concept)", strtoupper($newentry->concept));
+                       $dupentries = get_record("glossary_entries","UCASE(concept)", strtoupper($newentry->concept), "glossaryid", $glossary->id);
                        if ($dupentries) {
                               $PermissionGranted = 0;
                        }
diff --git a/mod/glossary/editcategories.html b/mod/glossary/editcategories.html
index fdfc0d156e..278776cfd3 100644
--- a/mod/glossary/editcategories.html
+++ b/mod/glossary/editcategories.html
@@ -1,11 +1,11 @@
-<?
+<?PHP
 	global $CFG, $THEME;
     	require_once("../../config.php");
 
 ?>
 
 <FORM name="form" method="post" <?=$onsubmit ?> action="editcategories.php">
-<table  class=generalbox cellpadding=5 bgcolor="<? p($THEME->cellheading)?>">
+<table  class=generalbox cellpadding=5 bgcolor="<?php p($THEME->cellheading)?>">
 <tr valign=top>
     <td align=right><p><b><?php echo get_string("name") ?>:</b></p></td>
     <td>
@@ -17,9 +17,9 @@
 	<input type="hidden" name=id value="<?=$cm->id ?>">
 	<input type="hidden" name=action value="<?=$action?>">
 	<input type="hidden" name=confirm value=1>
-	<input type="hidden" name=cat value=<? p($cat) ?>>
-	<input type="submit" value="<? print_string("savechanges") ?>">
-	<input type="reset" value="<? print_string("back","glossary") ?>"  onclick="javascript:history.go(-1);">
+	<input type="hidden" name=cat value=<?php p($cat) ?>>
+	<input type="submit" value="<?php print_string("savechanges") ?>">
+	<input type="reset" value="<?php print_string("back","glossary") ?>"  onclick="javascript:history.go(-1);">
 	</P>
 </td>
 </tr>
diff --git a/mod/glossary/editcategories.php b/mod/glossary/editcategories.php
index bf2260e66b..37fda34aec 100644
--- a/mod/glossary/editcategories.php
+++ b/mod/glossary/editcategories.php
@@ -56,11 +56,11 @@
                     $CategoryObject->name = $name;
 
                     if ( !update_record("glossary_categories", $CategoryObject) ) {
-     				error("Weird error. The category was not updated.");
-              			
-          			redirect("editcategories.php?id=$cm->id");
+     				    error("Weird error. The category was not updated.");
+     				    redirect("editcategories.php?id=$cm->id");
+                    } else {
+                        add_to_log($course->id, "glossary", "edit category", "editcategories.php?id=$cm->id", $cat);
                     }
-                    
                } else {
                     echo "<p align=\"center\">" . get_string("edit"). " " . get_string("category","glossary") . "<font size=\"3\">";
 
@@ -72,26 +72,26 @@
           } elseif ( $action == "delete" ) {
                if ( $confirm ) {
                
-				delete_records("glossary_entries_categories","categoryid", $cat);
+				    delete_records("glossary_entries_categories","categoryid", $cat);
                     delete_records("glossary_categories","id", $cat);
 				
-				print_simple_box_start("center","40%", "#FFBBBB");
-				echo "<center>" . get_string("categorydeleted","glossary") ."</center>";
-				echo "</center>";
-				print_simple_box_end();
+				    print_simple_box_start("center","40%", "#FFBBBB");
+				    echo "<center>" . get_string("categorydeleted","glossary") ."</center>";
+				    echo "</center>";
+				    print_simple_box_end();
 				
          			print_footer($course);
 
                     add_to_log($course->id, "glossary", "delete category", "editcategories.php?id=$cm->id", $cat);
                     
-     			redirect("editcategories.php?id=$cm->id");
+     			    redirect("editcategories.php?id=$cm->id");
                } else {
                     echo "<p align=\"center\">" . get_string("delete"). " " . get_string("category","glossary") . "<font size=\"3\">";
 
-     			print_simple_box_start("center","40%", "#FFBBBB");
-     			echo "<center><b>$category->name</b><br>";
+     			    print_simple_box_start("center","40%", "#FFBBBB");
+     			    echo "<center><b>$category->name</b><br>";
      			
-     			$num_entries = count_records("glossary_entries_categories","categoryid",$category->id);
+     			    $num_entries = count_records("glossary_entries_categories","categoryid",$category->id);
                     if ( $num_entries ) {
                          print_string("deletingnoneemptycategory","glossary");
                     }
@@ -109,29 +109,29 @@
                     <input type="submit" value=" <?php print_string("yes")?> ">
                     </form>
                     </td><td align=left width=50%>
-                    <?
+                    <?php
                     unset($options);
                     $options = array ("id" => $id);
                     print_single_button("editcategories.php", $options, get_string("no") );
                     echo "</td></tr></table>";
-     			echo "</center>";
-     			print_simple_box_end();
+     			    echo "</center>";
+     			    print_simple_box_end();
                }
           }
      } elseif ( $action == "add" ) {
           if ( $confirm ) {
-               $dupcategory = get_record("glossary_categories","lcase(name)",strtolower($name));
+               $dupcategory = get_record("glossary_categories","lcase(name)",strtolower($name),"glossaryid",$glossary->id);
                if ( $dupcategory ) {
                     echo "<p align=\"center\">" . get_string("add"). " " . get_string("category","glossary") . "<font size=\"3\">";
                     
-				print_simple_box_start("center","40%", "#FFBBBB");
-				echo "<center>" . get_string("duplicatedcategory","glossary") ."</center>";
-				echo "</center>";
-				print_simple_box_end();
+ 				    print_simple_box_start("center","40%", "#FFBBBB");
+				    echo "<center>" . get_string("duplicatedcategory","glossary") ."</center>";
+				    echo "</center>";
+				    print_simple_box_end();
 				
          			print_footer($course);
 
-     			redirect("editcategories.php?id=$cm->id&action=add&&name=$name");
+     			    redirect("editcategories.php?id=$cm->id&action=add&&name=$name");
 
                } else {
                     $action = "";
@@ -139,11 +139,11 @@
                     $CategoryObject->glossaryid = $glossary->id;
 
                     if ( ! $CategoryObject->id = insert_record("glossary_categories", $CategoryObject) ) {
-     				error("Weird error. The category was not inserted.");
+     				    error("Weird error. The category was not inserted.");
               			
-          			redirect("editcategories.php?id=$cm->id");
+          			    redirect("editcategories.php?id=$cm->id");
                     } else {
-                         add_to_log($course->id, "glossary", "add category", "editcategories.php?id=$cm->id", $cat);
+                        add_to_log($course->id, "glossary", "add category", "editcategories.php?id=$cm->id", $CategoryObject->id);
                     }
              }
           } else {
@@ -154,7 +154,6 @@
      }
      
      if ( $action ) {
-
           print_footer();
           die;
      }
@@ -162,41 +161,41 @@
 ?>
 
 
-<p align="center"><? p(get_string("edit")) ?> <? p(get_string("categories","glossary")) ?><font size="3">
+<p align="center"><?php p(get_string("edit")) ?> <?php p(get_string("categories","glossary")) ?><font size="3">
 
 <FORM name="theform" method="post" <?=$onsubmit ?> action="editcategories.php">
-<table width="40%" class=generalbox cellpadding=5 bgcolor="<? p($THEME->cellheading)?>">
+<table width="40%" class=generalbox cellpadding=5 bgcolor="<?php p($THEME->cellheading)?>">
         <tr>
           <td width="90%" align="center"><b>
-          <? p(get_string("categories","glossary")) ?></b></td>
+          <?php p(get_string("categories","glossary")) ?></b></td>
           <td width="10%" align="center"><b>
-          <? p(get_string("action")) ?></b></td>
+          <?php p(get_string("action")) ?></b></td>
         </tr>
-        <tr><td width=100% colspan=2  bgcolor="<? p($THEME->cellheading2)?>">
+        <tr><td width=100% colspan=2  bgcolor="<?php p($THEME->cellheading2)?>">
         
         <table width=100%>
-<?
+<?php
      $categories = get_records("glossary_categories","glossaryid",$glossary->id,"name ASC");
 
      if ( $categories ) {
           foreach ($categories as $category) {
                $num_entries = count_records("glossary_entries_categories","categoryid",$category->id);
              ?>
-             <tr bgcolor="<? p($THEME->cellheading2)?>">
+             <tr bgcolor="<?php p($THEME->cellheading2)?>">
                <td width="90%" align="left">
-               <?
+               <?php
                     echo "<b>$category->name</b> <font size=-1>($num_entries " . get_string("entries","glossary") . ")</font>";
                ?>
                </td>
                <td width="10%" align="center"><b>
-               <?
+               <?php
           		echo "<a href=\"editcategories.php?id=$cm->id&action=delete&cat=$category->id\"><img  alt=\"" . get_string("delete") . "\"src=\"../../pix/t/delete.gif\" height=11 width=11 border=0></a> ";
           	  	echo "<a href=\"editcategories.php?id=$cm->id&action=edit&cat=$category->id\"><img  alt=\"" . get_string("edit") . "\" src=\"../../pix/t/edit.gif\" height=11 width=11 border=0></a>";
                ?>
                </b></td>
              </tr>
              
-             <?
+             <?php
           }
      }
 ?>
@@ -204,8 +203,8 @@
         
         </td>
         <tr>
-        <td width=100% colspan=2  align=center bgcolor="<? p($THEME->cellheading2)?>">
-            <?
+        <td width=100% colspan=2  align=center bgcolor="<?php p($THEME->cellheading2)?>">
+            <?php
             
              $options['id'] = $cm->id;
              $options['action'] = "add";
@@ -230,4 +229,4 @@
 
 </form>
 
-<? print_footer() ?>
+<?php print_footer() ?>
diff --git a/mod/glossary/exportentry.php b/mod/glossary/exportentry.php
index 35ea5ad9fe..85d6f8b785 100644
--- a/mod/glossary/exportentry.php
+++ b/mod/glossary/exportentry.php
@@ -1,4 +1,4 @@
-<?
+<?PHP
 	require_once("../../config.php");
 	require_once("lib.php");
 
@@ -66,45 +66,30 @@
 				}
 			}
 			if ( $PermissionGranted ) {
-               	$newentry->userid = $entry->userid;
-      	      	$newentry->glossaryid = $mainglossary->id;
-	           	$newentry->concept = $entry->concept;
-               	$newentry->definition = $entry->definition;
-      	       	$newentry->format = $entry->format;
-		  	   	$newentry->timecreated = $entry->timecreated;
-	   		   	$newentry->timemodified = $entry->timemodified;
-			   	$newentry->teacherentry = $entry->teacherentry;
-			   	$newentry->attachment = $entry->attachment;
-
-		   		if (! $newentry->id = insert_record("glossary_entries", $newentry) ) {
+			
+                $entry->glossaryid       = $mainglossary->id;
+                $entry->sourceglossaryid = $glossary->id;
+                
+                if (! update_record("glossary_entries", $entry)) {
 					error("Could not export the entry to the main glossary");
 				} else {
-                         print_simple_box_start("center", "60%", "$THEME->cellheading");
-                         echo "<p align=center><font size=3>$entryexported</font></p></font>";
-                         if ($newentry->attachment) {
-                              $entry->course = $cm->course;
-               	          $newentry->course = $cm->course;
-                              if ( !glossary_copy_attachments($entry, $newentry) ) {
-                                   echo "<p align=\"center\">However, the attachment couldn't be exported.";
-                              }
-                         }
-                         
-                         add_to_log($course->id, "glossary", "add entry", "view.php?id=$cm->id&currentview=$currentview&cat=$cat&eid=".$entry->id, "$newentry->id");
-
-                         print_continue("view.php?id=$cm->id&currentview=$currentview&cat=$cat&eid=".$entry->id);
-                         print_simple_box_end();
-
-     					print_footer();
-
-     	                redirect("view.php?id=$cm->id&currentview=$currentview&cat=$cat&eid=".$entry->id);
-     	                die;
+                    print_simple_box_start("center", "60%", "$THEME->cellheading");
+                    echo "<p align=center><font size=3>$entryexported</font></p></font>";
+
+                    print_continue("view.php?id=$cm->id&eid=".$entry->id);
+                    print_simple_box_end();
+
+     				print_footer();
+
+     	            redirect("view.php?id=$cm->id&eid=".$entry->id);
+     	            die;
 				}
 			} else {
 			    print_simple_box_start("center", "60%", "#FFBBBB");
 			    echo "<p align=center><font size=3>$entryalreadyexist</font></p></font>";
 				echo "<p align=center>";
 
-				print_continue("view.php?id=$cm->id&currentview=$currentview&cat=$cat&eid=".$entry->id);
+				print_continue("view.php?id=$cm->id&eid=".$entry->id);
 
 			    print_simple_box_end();
 			}
@@ -113,7 +98,7 @@
 	    	print_simple_box_start("center", "60%", "#FFBBBB");
 	    	echo "<p align=center><font size=3>A weird error was found while trying to export this entry. Operation cancelled.</font></p></font>";
 
-			print_continue("view.php?id=$cm->id&currentview=$currentview&cat=$cat&eid=".$entry->id);
+			print_continue("view.php?id=$cm->id&eid=".$entry->id);
 
 	    	print_simple_box_end();
 	}
diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php
index 11ecadd34a..91f07af166 100644
--- a/mod/glossary/lib.php
+++ b/mod/glossary/lib.php
@@ -217,19 +217,39 @@ function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$curren
 function glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview="",$cat="") {
     global $THEME, $USER;
 
-	  if (isteacher($course->id) or $glossary->studentcanpost and $entry->userid == $USER->id) {
+    $ImportedEntry = ($entry->sourceglossaryid == $glossary->id);
+    $IsTeacher = isteacher($course->id);
+    $IsMainGlossary = $glossary->mainglossary;
+    
+	if ($IsTeacher or $glossary->studentcanpost and $entry->userid == $USER->id) {
  	  	echo "<p align=right>";
-		if (isteacher($course->id) and !$glossary->mainglossary) {
+ 	  	// only teachers can export entries so check it out
+		if ($IsTeacher and !$IsMainGlossary and !$ImportedEntry) {
 			$mainglossary = get_record("glossary","mainglossary",1,"course",$course->id);
-			if ( $mainglossary ) {
-
-				echo "<a href=\"exportentry.php?id=$cm->id&entry=$entry->id&currentview=$currentview&cat=$cat\"><img  alt=\"" . get_string("exporttomainglossary","glossary") . "\"src=\"export.gif\" height=11 width=11 border=0></a> ";
+			if ( $mainglossary ) {  // if there is a main glossary defined, allow to export the current entry
+				
+                echo "<a href=\"exportentry.php?id=$cm->id&entry=$entry->id&currentview=$currentview&cat=$cat\"><img  alt=\"" . get_string("exporttomainglossary","glossary") . "\"src=\"export.gif\" height=11 width=11 border=0></a> ";
 
 			}
 		}
-		echo "<a href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id&currentview=$currentview&cat=$cat\"><img  alt=\"" . get_string("delete") . "\"src=\"../../pix/t/delete.gif\" height=11 width=11 border=0></a> ";
-	  	echo "<a href=\"edit.php?id=$cm->id&e=$entry->id&currentview=$currentview&cat=$cat\"><img  alt=\"" . get_string("edit") . "\" src=\"../../pix/t/edit.gif\" height=11 width=11 border=0></a>";
-	  }
+		
+        if ( $entry->sourceglossaryid ) {
+            $icon = "minus.gif";   // graphical metaphor (minus) for deleting an imported entry
+        } else {
+            $icon = "../../pix/t/delete.gif";
+        }
+
+		// Exported entries can be updated/deleted only by teachers in the main glossary
+        if ( !$ImportedEntry and ($IsTeacher or !$IsMainGlossary) ) {
+            echo "<a href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id&currentview=$currentview&cat=$cat\"><img  alt=\"" . get_string("delete") . "\"src=\"";
+            echo $icon;
+            echo "\" height=11 width=11 border=0></a> ";
+            
+            echo "<a href=\"edit.php?id=$cm->id&e=$entry->id&currentview=$currentview&cat=$cat\"><img  alt=\"" . get_string("edit") . "\" src=\"../../pix/t/edit.gif\" height=11 width=11 border=0></a>";
+        } elseif ( $ImportedEntry ) {
+            echo "<font size=-1>" . get_string("exportedentry","glossary") . "</font>";
+        }
+	}
 }
 
 function glossary_search_entries($searchterms, $glossary, $includedefinition) {
@@ -298,7 +318,7 @@ function glossary_search_entries($searchterms, $glossary, $includedefinition) {
     $selectsql = "{$CFG->prefix}glossary_entries e,
                   {$CFG->prefix}glossary g $onlyvisibletable
              WHERE ($conceptsearch OR $definitionsearch)
-               AND e.glossaryid = g.id $onlyvisible
+               AND (e.glossaryid = g.id or e.sourceglossaryid = g.id) $onlyvisible
 		   AND g.id = $glossary->id";
 
     $totalcount = count_records_sql("SELECT COUNT(*) FROM $selectsql");
@@ -499,7 +519,7 @@ function glossary_print_attachments($entry, $return=NULL) {
     return $imagereturn;
 }
 
-function print_tabbed_table_start($data, $CurrentTab, $tTHEME = NULL) {
+function glossary_print_tabbed_table_start($data, $CurrentTab, $tTHEME = NULL) {
 
 if ( !$tTHEME ) {
      global $THEME;
@@ -522,19 +542,22 @@ $NumRows              = (int) ( $Tabs / $TabsPerRow ) + 1;
 
 ?>
   <center>
-  <table border="0" cellpadding="0" cellspacing="0" width="<? p($TableWidth) ?>">
+  <table border="0" cellpadding="0" cellspacing="0" width="<?php p($TableWidth) ?>">
     <tr>
       <td width="100%">
 
       <table border="0" cellpadding="0" cellspacing="0" width="100%">
 
-<?
+<?php
 $TabProccessed = 0;
 for ($row = 0; $row < $NumRows; $row++) {
      echo "<tr>\n";
      if ( $row != $CurrentRow ) {
           for ($col = 0; $col < $TabsPerRow; $col++) {
                if ( $TabProccessed < $Tabs ) {
+                    if ( $col == 0 ) {
+                        echo "<td width=\"$TabSeparation\" align=\"center\">&nbsp;</td>";
+                    }
                     if ($TabProccessed == $CurrentTab) {
                          $CurrentColor = $CurrentTabColor;
                     } else {
@@ -569,6 +592,9 @@ for ($row = 0; $row < $NumRows; $row++) {
           $TabProccessed = $FirstTabInCurrentRow;
           for ($col = 0; $col < $TabsPerRow; $col++) {
                if ( $TabProccessed < $Tabs ) {
+                    if ( $col == 0 ) {
+                        echo "<td width=\"$TabSeparation\" align=\"center\">&nbsp;</td>";
+                    }
                     if ($TabProccessed == $CurrentTab) {
                          $CurrentColor = $CurrentTabColor;
                     } else {
@@ -607,15 +633,15 @@ for ($row = 0; $row < $NumRows; $row++) {
       </td>
     </tr>
     <tr>
-      <td width="100%" bgcolor="<? p($TableColor) ?>"><hr></td>
+      <td width="100%" bgcolor="<?php p($TableColor) ?>"><hr></td>
     </tr>
     <tr>
-      <td width="100%" bgcolor="<? p($TableColor) ?>">
+      <td width="100%" bgcolor="<?php p($TableColor) ?>">
           <center>
-<?
+<?php
 }
 
-function print_tabbed_table_end() {
+function glossary_print_tabbed_table_end() {
      echo "</center><p></td></tr></table></center>";
 }
 
@@ -722,4 +748,15 @@ global $CFG, $THEME;
      echo "<tr><td colspan=3><hr></td></tr>";
      echo "</table>";
 }
+
+function glossary_sort_entries ( $entry0, $entry1 ) {
+    if ( strtolower(ltrim($entry0->concept)) < strtolower(ltrim($entry1->concept)) ) {
+        return -1;
+    } elseif ( strtolower(ltrim($entry0->concept)) > strtolower(ltrim($entry1->concept)) ) {
+        return 1;
+    } else {
+        return 0;
+    }
+}
+
 ?>
diff --git a/mod/glossary/minus.gif b/mod/glossary/minus.gif
new file mode 100644
index 0000000000000000000000000000000000000000..3561016ec9a95273e15b74be2746a20342e3966d
GIT binary patch
literal 839
zcmb7@A#2-V5XMhbw3NVRDnd<RB4VmXpkp$yWz58`5HWKmUm$W&NIyWBI5U>nm9XlV
zjhO~cRpbjSP#smKuD^TRFVNS7<9+YB-}Br*??1ddd-M5F4&`1RkBXRxi-brDm8z(T
zx@d@IU7CuSn2Uv2)>~I`6L;|t&uR^oFbS6ki9|_KB~8*LLy`h*q|u_8*I9Gwn5wIW
zYSvgPGc{KWwJZuQ-PBz@)U%*?8>ZnJp^-4ss%e_88JbLm8Zn@u1dBTcqm49LG-nyA
zn&W0+mgSGJRPN?so@EybF2gOtB5@BCZ!O(2EU`x(VA4$-_y+=qP$LF3lstul!Du6m
zR#tL#P0b1StRV5nSgHt*Bv<T0!KG(-k|RkI09-sLXxtJdd4NebalnLO972s4&~$<Y
z2ZPZ@I%`GsnrmuKvN3|hA7iN^vliIaUleVlwa>Psf@-<fdRvsm*wU$OH^YV8Jk;_V
zRyk;skmhq>ON57~HcC33PPg0b^?Ln&e=rz~Mx*g~Jef?U)9GwBo6qNq#bUW!u2!q{
zdcE0fw%hG)w|ne;`jDUhbMk-hK;%kZS8M$zWdD_XIyfHw`u^u)|K;uZ@aNIr%NHl-
VKD_?%_2TaI+sB*hf4{%T+XvoJb}Ik?

literal 0
HcmV?d00001

diff --git a/mod/glossary/mod.html b/mod/glossary/mod.html
index 98c9f829d3..951173a9fa 100644
--- a/mod/glossary/mod.html
+++ b/mod/glossary/mod.html
@@ -5,87 +5,92 @@
 <CENTER>
 <TABLE cellpadding=5>
 <TR valign=top>
-    <TD align=right><P><B><? print_string("name") ?>:</B></P></TD>
+    <TD align=right><P><B><?php print_string("name") ?>:</B></P></TD>
     <TD>
-        <INPUT type="text" name="name" size=30 value="<? p($form->name) ?>">
+        <INPUT type="text" name="name" size=30 value="<?php p($form->name) ?>">
     </TD>
 </TR>
 <!-- More rows go in here... -->
+<?php
+$mainglossary = get_record("glossary","mainglossary",1,"course",$form->course);
+if (!$mainglossary or $mainglossary->id == $form->instance ) {
+?>
 <TR valign=top>
-    <TD align=right><P><B><? echo get_string("studentcanpost", "glossary") ?>:</B></P></TD>
+    <TD align=right><P><B><?php echo get_string("glossarytype", "glossary") ?>:</B></P></TD>
     <TD>
-  <select size="1" name="studentcanpost">
-  <option value="1" <? 
-   if ( $form->studentcanpost ) {
+  <select size="1" name="mainglossary">
+  <option value="1" <?php
+   if ( $form->mainglossary ) {
       echo "selected";
    }
-   ?>><? echo get_string("yes") ?></option>
-  <option value="0" <? 
-   if ( !$form->studentcanpost ) {
+   ?>><?php echo get_string("mainglossary", "glossary") ?></option>
+  <option value="0" <?php
+   if ( !$form->mainglossary ) {
       echo "selected";
    }
-   ?>><? echo get_string("no") ?>
+   ?>><?php echo get_string("secondaryglossary", "glossary") ?>
   </option>
-  </select> <? helpbutton("studentcanpost", get_string("studentcanpost", "glossary"), "glossary") ?>
+  </select> <?php helpbutton("mainglossary", get_string("mainglossary", "glossary"), "glossary") ?>
     </TD>
 </TR>
+<?php
+} else {
+	echo "<INPUT type=\"hidden\" name=mainglossary value=\"0\">";
+}
+?>
 <TR valign=top>
-    <TD align=right><P><B><? echo get_string("allowduplicatedentries", "glossary") ?>:</B></P></TD>
+    <TD align=right><P><B><?php p(get_string("studentcanpost", "glossary")) ?>:</B><br>
+    <font size=1><?php p(get_string("warningstudentcapost","glossary")) ?></font></P></TD>
     <TD>
-  <select size="1" name="allowduplicatedentries">
-  <option value="1" <? 
-   if ( $form->allowduplicatedentries ) {
+  <select size="1" name="studentcanpost">
+  <option value="1" <?php
+   if ( $form->studentcanpost ) {
       echo "selected";
    }
-   ?> 
-   ><? echo get_string("yes") ?></option>
-  <option value="0" <? 
-   if ( !$form->allowduplicatedentries ) {
+   ?>><?php echo get_string("yes") ?></option>
+  <option value="0" <?php
+   if ( !$form->studentcanpost ) {
       echo "selected";
    }
-   ?>><? echo get_string("no") ?>
+   ?>><?php echo get_string("no") ?>
   </option>
-  </select> <? helpbutton("allowduplicatedentries", get_string("allowduplicatedentries", "glossary"), "glossary") ?>
+  </select> <?php helpbutton("studentcanpost", get_string("studentcanpost", "glossary"), "glossary") ?>
     </TD>
 </TR>
-<?
-$mainglossary = get_record("glossary","mainglossary",1,"course",$form->course);
-if (!$mainglossary or $mainglossary->id == $form->instance ) {
-?>
 <TR valign=top>
-    <TD align=right><P><B><? echo get_string("glossarytype", "glossary") ?>:</B></P></TD>
+    <TD align=right><P><B><?php echo get_string("allowduplicatedentries", "glossary") ?>:</B></P></TD>
     <TD>
-  <select size="1" name="mainglossary">
-  <option value="1" <? 
-   if ( $form->mainglossary ) {
+  <select size="1" name="allowduplicatedentries">
+  <option value="1" <?php
+   if ( $form->allowduplicatedentries ) {
       echo "selected";
    }
-   ?>><? echo get_string("mainglossary", "glossary") ?></option>
-  <option value="0" <? 
-   if ( !$form->mainglossary ) {
+   ?> 
+   ><?php echo get_string("yes") ?></option>
+  <option value="0" <?php
+   if ( !$form->allowduplicatedentries ) {
       echo "selected";
    }
-   ?>><? echo get_string("secundaryglossary", "glossary") ?>
+   ?>><?php echo get_string("no") ?>
   </option>
-  </select> <? helpbutton("mainglossary", get_string("mainglossary", "glossary"), "glossary") ?>
+  </select> <?php helpbutton("allowduplicatedentries", get_string("allowduplicatedentries", "glossary"), "glossary") ?>
     </TD>
 </TR>
-<?
-} else {
-	echo "<INPUT type=\"hidden\" name=mainglossary value=\"0\">";
-}
-?>
 <TR valign=top>
-    <TD align=right><P><B><? echo get_string("displayformat", "glossary") ?>:</B></P></TD>
+<td colspan=2><hr>
+</tr>
+</tr>
+<TR valign=top>
+    <TD align=right><P><B><?php echo get_string("displayformat", "glossary") ?>:</B></P></TD>
     <TD>
   <select size="1" name="displayformat">
-  <option value="0" <? 
+  <option value="0" <?php
    if ( $form->displayformat == 0) {
       echo "selected";
    }
-  ?>><? echo get_string("displayformatdefault", "glossary") ?></option>
+  ?>><?php echo get_string("displayformatdefault", "glossary") ?></option>
 
-<?
+<?php
     global $CFG;
 
     $basedir = opendir("$CFG->dirroot/mod/glossary/formats");
@@ -112,75 +117,75 @@ if (!$mainglossary or $mainglossary->id == $form->instance ) {
 	
 ?>
 
-    </select> <? helpbutton("displayformat", get_string("displayformat", "glossary"), "glossary") ?>
+    </select> <?php helpbutton("displayformat", get_string("displayformat", "glossary"), "glossary") ?>
     </TD>
 </TR>
 <TR valign=top>
-    <TD align=right><P><B><? echo get_string("showspecial", "glossary") ?>:</B></P></TD>
+    <TD align=right><P><B><?php echo get_string("showspecial", "glossary") ?>:</B></P></TD>
     <TD>
   <select size="1" name="showspecial">
-  <option value="1" <? 
+  <option value="1" <?php
    if ( $form->showspecial ) {
       echo "selected";
    }
    ?> 
-   ><? echo get_string("yes") ?></option>
-  <option value="0" <? 
+   ><?php echo get_string("yes") ?></option>
+  <option value="0" <?php
    if ( !$form->showspecial ) {
       echo "selected";
    }
-   ?>><? echo get_string("no") ?>
+   ?>><?php echo get_string("no") ?>
   </option>
-  </select> <? helpbutton("shows", get_string("showspecial", "glossary"), "glossary") ?>
+  </select> <?php helpbutton("shows", get_string("showspecial", "glossary"), "glossary") ?>
     </TD>
 </TR>
 <TR valign=top>
-    <TD align=right><P><B><? echo get_string("showalphabet", "glossary") ?>:</B></P></TD>
+    <TD align=right><P><B><?php echo get_string("showalphabet", "glossary") ?>:</B></P></TD>
     <TD>
   <select size="1" name="showalphabet">
-  <option value="1" <? 
+  <option value="1" <?php
    if ( $form->showalphabet ) {
       echo "selected";
    }
    ?> 
-   ><? echo get_string("yes") ?></option>
-  <option value="0" <? 
+   ><?php echo get_string("yes") ?></option>
+  <option value="0" <?php
    if ( !$form->showalphabet ) {
       echo "selected";
    }
-   ?>><? echo get_string("no") ?>
+   ?>><?php echo get_string("no") ?>
   </option>
-  </select> <? helpbutton("shows", get_string("showalphabet", "glossary"), "glossary") ?>
+  </select> <?php helpbutton("shows", get_string("showalphabet", "glossary"), "glossary") ?>
     </TD>
 </TR>
 <TR valign=top>
-    <TD align=right><P><B><? echo get_string("showall", "glossary") ?>:</B></P></TD>
+    <TD align=right><P><B><?php echo get_string("showall", "glossary") ?>:</B></P></TD>
     <TD>
   <select size="1" name="showall">
-  <option value="1" <? 
+  <option value="1" <?php
    if ( $form->showall ) {
       echo "selected";
    }
    ?> 
-   ><? echo get_string("yes") ?></option>
-  <option value="0" <? 
+   ><?php echo get_string("yes") ?></option>
+  <option value="0" <?php
    if ( !$form->showall ) {
       echo "selected";
    }
-   ?>><? echo get_string("no") ?>
+   ?>><?php echo get_string("no") ?>
   </option>
-  </select> <? helpbutton("shows", get_string("showall", "glossary"), "glossary") ?>
+  </select> <?php helpbutton("shows", get_string("showall", "glossary"), "glossary") ?>
     </TD>
 </TR>
 </TABLE>
 <!-- These hidden variables are always the same -->
-<INPUT type="hidden" name=course        value="<? p($form->course) ?>">
-<INPUT type="hidden" name=coursemodule  value="<? p($form->coursemodule) ?>">
-<INPUT type="hidden" name=section       value="<? p($form->section) ?>">
-<INPUT type="hidden" name=module        value="<? p($form->module) ?>">
-<INPUT type="hidden" name=modulename    value="<? p($form->modulename) ?>">
-<INPUT type="hidden" name=instance      value="<? p($form->instance) ?>">
-<INPUT type="hidden" name=mode          value="<? p($form->mode) ?>">
-<INPUT type="submit" value="<? print_string("savechanges") ?>">
+<INPUT type="hidden" name=course        value="<?php p($form->course) ?>">
+<INPUT type="hidden" name=coursemodule  value="<?php p($form->coursemodule) ?>">
+<INPUT type="hidden" name=section       value="<?php p($form->section) ?>">
+<INPUT type="hidden" name=module        value="<?php p($form->module) ?>">
+<INPUT type="hidden" name=modulename    value="<?php p($form->modulename) ?>">
+<INPUT type="hidden" name=instance      value="<?php p($form->instance) ?>">
+<INPUT type="hidden" name=mode          value="<?php p($form->mode) ?>">
+<INPUT type="submit" value="<?php print_string("savechanges") ?>">
 </CENTER>
 </FORM>
diff --git a/mod/glossary/restorelib.php b/mod/glossary/restorelib.php
index c1309cb963..ba812beb44 100644
--- a/mod/glossary/restorelib.php
+++ b/mod/glossary/restorelib.php
@@ -109,15 +109,22 @@
             $entry->definition = backup_todb($ent_info['#']['DEFINITION']['0']['#']);
             $entry->format = backup_todb($ent_info['#']['FORMAT']['0']['#']);
             $entry->attachment = backup_todb($ent_info['#']['ATTACHMENT']['0']['#']);
+            $entry->sourceglossaryid = backup_todb($ent_info['#']['SOURCEGLOSSARYID']['0']['#']);
             $entry->timecreated = backup_todb($ent_info['#']['TIMECREATED']['0']['#']);
             $entry->timemodified = backup_todb($ent_info['#']['TIMEMODIFIED']['0']['#']);
             $entry->teacherentry = backup_todb($ent_info['#']['TEACHERENTRY']['0']['#']);
 
+
             //We have to recode the userid field
             $user = backup_getid($restore->backup_unique_code,"user",$entry->userid);
             if ($user) {
                 $entry->userid = $user->new_id;
-             }
+            }
+            //We have to recode the sourceglossaryid field
+            $source = backup_getid($restore->backup_unique_code,"glossary",$entry->sourceglossaryid);
+            if ($source) {
+                $entry->sourceglossaryid = $source->new_id;
+            }
             //If it's a teacher entry or userinfo was selected, restore the entry
             if ($entry->teacherentry or $restore->mods['glossary']->userinfo) {
                 //The structure is equal to the db, so insert the glossary_entries
diff --git a/mod/glossary/version.php b/mod/glossary/version.php
index 243607b010..75cec4a16d 100644
--- a/mod/glossary/version.php
+++ b/mod/glossary/version.php
@@ -5,9 +5,9 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2003092102;  // The current module version (Date: YYYYMMDDXX)
+$module->version  = 2003092400;  // The current module version (Date: YYYYMMDDXX)
 $module->cron     = 0;           // Period for cron to check this module (secs)
 
-$release = "0.3.2 development";   // User-friendly version number
+$release = "0.4 development";   // User-friendly version number
 
 ?>
diff --git a/mod/glossary/view.php b/mod/glossary/view.php
index 2ab900ec3b..10bf3d280b 100644
--- a/mod/glossary/view.php
+++ b/mod/glossary/view.php
@@ -72,13 +72,12 @@
         $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
     }
 
-     $strglossaries   = get_string("modulenameplural", "glossary");
-     $strglossary     = get_string("modulename", "glossary");
-     $strallcategories= get_string("allcategories", "glossary");
-     $straddentry     = get_string("addentry", "glossary");
-     $strnoentries    = get_string("noentries", "glossary");
-
-    print_header("$course->shortname: $glossary->name", "$course->fullname",
+    $strglossaries   = get_string("modulenameplural", "glossary");
+    $strglossary     = get_string("modulename", "glossary");
+    $strallcategories= get_string("allcategories", "glossary");
+    $straddentry     = get_string("addentry", "glossary");
+    $strnoentries    = get_string("noentries", "glossary");
+    print_header(strip_tags("$course->shortname: $glossary->name"), "$course->fullname",
                  "$navigation <A HREF=index.php?id=$course->id>$strglossaries</A> -> $glossary->name",
                   "", "", true, update_module_button($cm->id, $course->id, $strglossary),
                   navmenu($course, $cm));
@@ -91,11 +90,11 @@
           echo "<table width=100% border=0><tr><td width=50% align=right>";
      	?>
      	<form method="POST" action="view.php">
-     	  <? p(get_string("searchconcept","glossary")) ?> <input type="text" name="search" size="20" value=""> <br><? p(get_string("searchindefinition","glossary")) ?> <input type="checkbox" name="includedefinition" value="1">
-     	  <input type="submit" value="Search" name="searchbutton">
-     	  <input type="hidden" name="id" value="<? p($cm->id) ?>">
+     	  <?php p(get_string("searchconcept","glossary")) ?> <input type="text" name="search" size="20" value=""> <br><?php p(get_string("searchindefinition","glossary")) ?> <input type="checkbox" name="includedefinition" value="1">
+     	  <input type="submit" value="<?php p(get_string("search")) ?>" name="searchbutton">
+     	  <input type="hidden" name="id" value="<?php p($cm->id) ?>">
      	</form>
-     	<?
+     	<?php
           echo "</td><td valign=top align=right width=50%>";
            if (isteacher($course->id) or ($glossary->studentcanpost) and !isguest($course->id)) {
               $options = array ("id" => "$cm->id");
@@ -116,7 +115,7 @@
      } else {
           $CurrentTab = 0;
      }
-     print_tabbed_table_start($data, $CurrentTab, $tCFG);
+     glossary_print_tabbed_table_start($data, $CurrentTab, $tCFG);
      echo "<center>";
      if ( $currentview ) {
          glossary_print_categories_menu($course, $cm, $glossary, $cat, $category);
@@ -140,16 +139,26 @@
 		$allentries = get_records("glossary_entries", "id", $eid);
 	} elseif ( $currentview and $cat == 0 ) {   // Browsing all categories
         $sql = "SELECT gec.id gecid, gc.name, gc.id CID, ge.*
-            FROM {$CFG->prefix}glossary_entries ge,
-                {$CFG->prefix}glossary_entries_categories gec,
-                {$CFG->prefix}glossary_categories gc
-            WHERE ge.glossaryid = '$glossary->id' AND
-                gec.entryid = ge.id AND
-                gc.id = gec.categoryid
-            ORDER BY gc.name, ge.concept";
+                FROM {$CFG->prefix}glossary_entries ge,
+                    {$CFG->prefix}glossary_entries_categories gec,
+                    {$CFG->prefix}glossary_categories gc
+                WHERE (ge.glossaryid = '$glossary->id' or ge.sourceglossaryid = '$glossary->id') AND
+                    gec.entryid = ge.id AND
+                    gc.id = gec.categoryid
+                ORDER BY gc.name, ge.concept";
 	    $allentries = get_records_sql( $sql );
 	} else {			// looking for terms that begin with a specify letter or entries with no category associated
-		$allentries = get_records("glossary_entries", "glossaryid", $glossary->id,"concept ASC");
+		$ownentries = get_records("glossary_entries", "glossaryid", $glossary->id,"concept ASC");
+		$importedentries = get_records("glossary_entries", "sourceglossaryid", $glossary->id,"concept ASC");
+		
+		if ( $ownentries and $importedentries ) {
+		    $allentries = array_merge($ownentries, $importedentries);
+		    usort($allentries, glossary_sort_entries);		
+		} elseif ( $importedentries ) {
+		    $allentries = $importedentries;
+		} elseif ( $ownentries ) {
+		    $allentries = $ownentries;
+		}
 	}
 
     if ( $allentries ) {
@@ -261,7 +270,7 @@
 	}
 
      echo "</center>";
-     print_tabbed_table_end();
+     glossary_print_tabbed_table_end();
 
 /// Finish the page
     print_footer($course);
-- 
2.39.5