Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

- Cleaning a lot of code in edit.php and view.php

- Removing more notices when debug is ON
- Added a new feature: Now the entries have a default approval status... Not approved entries are shown on a teachers-only frame from which they can be approved or not prior to be visible by everyone.
  • Loading branch information...
commit c76e673ab527e77025b1249041cfd097b501efdc 1 parent 016f1be
authored October 21, 2003
38  mod/glossary/approve.php
... ...
@@ -0,0 +1,38 @@
  1
+<?php 
  2
+
  3
+    require_once("../../config.php");
  4
+    require_once("lib.php");
  5
+    
  6
+    require_variable($id);           // Course Module ID
  7
+    optional_variable($eid);         // Entry ID
  8
+
  9
+    optional_variable($tab,GLOSSARY_APPROVAL_VIEW);
  10
+    optional_variable($l,"ALL");
  11
+
  12
+    if (! $cm = get_record("course_modules", "id", $id)) {
  13
+        error("Course Module ID was incorrect");
  14
+    } 
  15
+    
  16
+    if (! $course = get_record("course", "id", $cm->course)) {
  17
+        error("Course is misconfigured");
  18
+    } 
  19
+    
  20
+    if (! $glossary = get_record("glossary", "id", $cm->instance)) {
  21
+        error("Course module is incorrect");
  22
+    } 
  23
+    
  24
+    require_login($course->id);    
  25
+    if (!isteacher($course->id)) {
  26
+        error("You must be a teacher to use this page.");
  27
+    } 
  28
+    $newentry->id = $eid;
  29
+    $newentry->approved = 1;
  30
+
  31
+    if (! update_record("glossary_entries", $newentry)) {
  32
+        error("Could not update your glossary");
  33
+    } else {
  34
+        add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&eid=$eid", "$eid");
  35
+    }
  36
+    redirect("view.php?id=$cm->id&tab=$tab&l=ALL");
  37
+    die;
  38
+?>
BIN  mod/glossary/check.gif
10  mod/glossary/comment.html
@@ -28,10 +28,12 @@
28 28
    	   helpbutton("textformat", get_string("helpformatting"));
29 29
        print_string("formattexttype");
30 30
        echo ":&nbsp;";
31  
-       if (!$form->format) {
32  
-           $form->format = $defaultformat;
  31
+       if (!isset($form->format)) {
  32
+           if (!$form->format) {
  33
+               $form->format = $defaultformat;
  34
+           }
33 35
        }
34  
-       choose_from_menu(format_text_menu(), "format", $format->format, ""); 
  36
+       choose_from_menu(format_text_menu(), "format", $form->format, ""); 
35 37
        echo "</p>";
36 38
     ?>
37 39
     </td>
@@ -40,7 +42,7 @@
40 42
 <td colspan=2>
41 43
 	<p align=center>
42 44
 	<?php 
43  
-	    if ($comment->id) {
  45
+	    if (isset($comment->id)) {
44 46
 		    echo "<input type=\"hidden\" name=cid value=\"$comment->id\">";
45 47
    	    }
46 48
 	?>
12  mod/glossary/comment.php
@@ -150,7 +150,7 @@
150 150
             $newentry->entryid = $entry->id;
151 151
             $newentry->comment = $form->text;
152 152
             $newentry->format = $form->format;
153  
-            $newentry->timemodified = $comment->timemodified;
  153
+            $newentry->timemodified = time();
154 154
 			
155 155
             if ( $action == "add" ) {
156 156
                 $newentry->userid = $USER->id;
@@ -185,9 +185,13 @@
185 185
                 $defaultformat = FORMAT_MOODLE;
186 186
                 $onsubmit = "";
187 187
             }
188  
-
189  
-            $form->text = $comment->comment;
190  
-            $form->format = $comment->format;
  188
+            if (isset($comment) ) {
  189
+                $form->text = $comment->comment;
  190
+                $form->format = $comment->format;
  191
+            } else {
  192
+                $form->text = "";
  193
+                $form->format = $defaultformat;
  194
+            }
191 195
             include("comment.html");
192 196
         }
193 197
     }
9  mod/glossary/db/mysql.php
@@ -109,6 +109,15 @@ function glossary_upgrade($oldversion) {
109 109
         execute_sql( "UPDATE `{$CFG->prefix}glossary`" .
110 110
                     " SET displayformat = 5 WHERE displayformat = 1");
111 111
     }
  112
+    if ( $oldversion < 2003102000 ) {
  113
+        execute_sql( "ALTER TABLE `{$CFG->prefix}glossary`" .
  114
+                     " ADD `defaultapproval` TINYINT(2) UNSIGNED NOT NULL default '1' AFTER `usedynalink`");
  115
+					
  116
+        execute_sql( "ALTER TABLE `{$CFG->prefix}glossary_entries`" .
  117
+                    " ADD `approved` TINYINT(2) UNSIGNED NOT NULL default '1' AFTER `fullmatch`");
  118
+
  119
+        execute_sql(" INSERT INTO {$CFG->prefix}log_display VALUES ('glossary', 'approve entry', 'glossary', 'name') ");
  120
+    }
112 121
     return true;
113 122
 }
114 123
 
3  mod/glossary/db/mysql.sql
@@ -22,6 +22,7 @@ CREATE TABLE prefix_glossary (
22 22
      showall tinyint(2) unsigned NOT NULL default '1',
23 23
      allowcomments tinyint(2) unsigned NOT NULL default '0',
24 24
      usedynalink tinyint(2) unsigned NOT NULL default '1',
  25
+     defaultapproval tinyint(2) unsigned NOT NULL default '1',
25 26
      timecreated int(10) unsigned NOT NULL default '0',
26 27
      timemodified int(10) unsigned NOT NULL default '0',
27 28
      PRIMARY KEY  (id)
@@ -46,6 +47,7 @@ CREATE TABLE prefix_glossary_entries (
46 47
      usedynalink tinyint(2) unsigned NOT NULL default '1',
47 48
      casesensitive tinyint(2) unsigned NOT NULL default '0',
48 49
      fullmatch tinyint(2) unsigned NOT NULL default '1',
  50
+     approved tinyint(2) unsigned NOT NULL default '1',
49 51
      PRIMARY KEY  (id)
50 52
 ) TYPE=MyISAM COMMENT='all glossary entries';
51 53
 
@@ -98,4 +100,5 @@ INSERT INTO prefix_log_display VALUES ('glossary', 'delete category', 'glossary'
98 100
 INSERT INTO prefix_log_display VALUES ('glossary', 'add comment', 'glossary', 'name');
99 101
 INSERT INTO prefix_log_display VALUES ('glossary', 'update comment', 'glossary', 'name');
100 102
 INSERT INTO prefix_log_display VALUES ('glossary', 'delete comment', 'glossary', 'name');
  103
+INSERT INTO prefix_log_display VALUES ('glossary', 'approve entry', 'glossary', 'name');
101 104
 
8  mod/glossary/deleteentry.php
@@ -7,6 +7,8 @@
7 7
     require_variable($mode);  // edit or delete
8 8
     optional_variable($go);  // commit the operation?
9 9
     optional_variable($entry);  // entry id
  10
+    optional_variable($tab); // browsing entries by categories?
  11
+    optional_variable($cat);         // categoryID
10 12
 
11 13
     $strglossary = get_string("modulename", "glossary");
12 14
     $strglossaries = get_string("modulenameplural", "glossary");
@@ -72,8 +74,8 @@
72 74
                     print_simple_box_end();
73 75
                 }
74 76
                 print_footer($course);
75  
-                add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&currentview=$currentview&cat=$cat", $entry);
76  
-                redirect("view.php?id=$cm->id&currentview=$currentview&cat=$cat");
  77
+                add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&tab=$tab&cat=$cat", $entry);
  78
+                redirect("view.php?id=$cm->id&tab=$tab&cat=$cat");
77 79
             } else {        // the operation has not been confirmed yet so ask the user to do so
78 80
                 if ( $mode == "delete") {				
79 81
                     print_simple_box_start("center","40%", "#FFBBBB");
@@ -86,7 +88,7 @@
86 88
                         <input type="hidden" name=mode         value="delete">
87 89
                         <input type="hidden" name=go       value="1">
88 90
                         <input type="hidden" name=entry         value="<?php p($entry) ?>">
89  
-                        <input type="hidden" name=currentview value=<?php p($currentview) ?>>
  91
+                        <input type="hidden" name=tab value=<?php p($tab) ?>>
90 92
                         <input type="hidden" name=cat=<?php p($cat) ?>>
91 93
 
92 94
                         <input type="submit" value=" <?php print_string("yes")?> ">
2  mod/glossary/dynalink.php
@@ -20,7 +20,7 @@ function glossary_dynamic_link($courseid, $text) {
82  mod/glossary/edit.html
@@ -4,29 +4,30 @@
4 4
 <tr valign=top>
5 5
     <td align=right><p><b><?php echo get_string("concept","glossary") ?>:</b></p></td>
6 6
     <td>
7  
-        <INPUT type="text" name="concept" size=30 value="<?php p($form->concept) ?>">
  7
+        <INPUT type="text" name="concept" size=30 value="<?php p($newentry->concept) ?>">
8 8
     </td>
9 9
 </tr>
10 10
 <tr valign=top>
11 11
     <td align=right><p><b><?php echo get_string("categories","glossary") ?>:</b></p></td>
12 12
     <td>	
13  
-	<?php
14  
-		$categories = get_records("glossary_categories","glossaryid",$glossary->id);
15  
-		echo "<select size=\"6\" name=\"categories[]\" multiple=\"yes\">";
16  
-		echo "<option value=\"0\">" . get_string("notcategorised","glossary") . "</optioon>";
  13
+    <?php
  14
+        $categories = get_records("glossary_categories","glossaryid",$glossary->id);
  15
+        echo "<select size=\"6\" name=\"categories[]\" multiple=\"yes\">";
  16
+        echo "<option value=\"0\">" . get_string("notcategorised","glossary") . "</optioon>";
17 17
 
18  
-		if ( $categories ) {
  18
+        if ( $categories ) {
19 19
             foreach ( $categories as $category ) {
20  
-			    echo "  <option ";
21  
-
22  
-			    if ( record_exists("glossary_entries_categories","entryid",$entry->id,"categoryid",$category->id) ) {
23  
-				    echo "selected " ;
24  
-			    }
25  
-			    echo "value=\"$category->id\">$category->name</option>\n";
  20
+                echo "  <option ";
  21
+                if (isset($newentry->id)) {
  22
+                    if ( record_exists("glossary_entries_categories","entryid",$newentry->id,"categoryid",$category->id) ) {
  23
+                        echo "selected " ;
  24
+                    }
  25
+                }
  26
+                echo "value=\"$category->id\">$category->name</option>\n";
26 27
             }
27  
-		}
28  
-	?>
29  
-	</select>
  28
+        }
  29
+    ?>
  30
+    </select>
30 31
     </td>
31 32
 </tr>
32 33
 <tr valign=top>
@@ -34,14 +35,18 @@
34 35
     <td>
35 36
     <select size="1" name="usedynalink">
36 37
      <option value="1" <?php
37  
-      if ( $form->usedynalink ) {
38  
-         echo "selected";
  38
+      if ( isset($newentry->usedynalink) ) {
  39
+         if ($newentry->usedynalink) {
  40
+             echo "selected";
  41
+         }
39 42
       }
40 43
       ?> 
41 44
       ><?php echo get_string("yes") ?></option>
42 45
      <option value="0" <?php
43  
-      if ( !$form->usedynalink ) {
44  
-         echo "selected";
  46
+      if ( isset($newentry->usedynalink) ) {
  47
+         if (!$newentry->usedynalink) {
  48
+             echo "selected";
  49
+	     }
45 50
       }
46 51
       ?>><?php echo get_string("no") ?>
47 52
      </option>
@@ -53,14 +58,18 @@
53 58
     <td>
54 59
     <select size="1" name="casesensitive">
55 60
      <option value="1" <?php
56  
-      if ( $form->casesensitive ) {
57  
-         echo "selected";
  61
+      if ( isset($newentry->casesensitive) ) {
  62
+          if ( $newentry->casesensitive ) {
  63
+             echo "selected";
  64
+          }
58 65
       }
59 66
       ?> 
60 67
       ><?php echo get_string("yes") ?></option>
61 68
      <option value="0" <?php
62  
-      if ( !$form->casesensitive ) {
63  
-         echo "selected";
  69
+      if ( isset($newentry->casesensitive) ) {
  70
+          if ( !$newentry->casesensitive ) {
  71
+             echo "selected";
  72
+          }
64 73
       }
65 74
       ?>><?php echo get_string("no") ?>
66 75
      </option>
@@ -72,14 +81,18 @@
72 81
     <td>
73 82
     <select size="1" name="fullmatch">
74 83
      <option value="1" <?php
75  
-      if ( $form->fullmatch ) {
76  
-         echo "selected";
  84
+      if ( isset($newentry->fullmatch) ) {
  85
+          if ( $newentry->fullmatch ) {
  86
+             echo "selected";
  87
+          }
77 88
       }
78 89
       ?> 
79 90
       ><?php echo get_string("yes") ?></option>
80 91
      <option value="0" <?php
81  
-      if ( !$form->fullmatch ) {
82  
-         echo "selected";
  92
+      if ( isset($newentry->fullmatch) ) {
  93
+          if ( !$newentry->fullmatch ) {
  94
+             echo "selected";
  95
+          }
83 96
       }
84 97
       ?>><?php echo get_string("no") ?>
85 98
      </option>
@@ -103,16 +116,16 @@
103 116
     </td>
104 117
     <td>
105 118
     <?php
106  
-       print_textarea($usehtmleditor, 20, 60, 680, 400, "text", $entry->text);
  119
+       print_textarea($usehtmleditor, 20, 60, 680, 400, "text", $newentry->definition);
107 120
     
108 121
        echo "<p align=right>";
109 122
    	 helpbutton("textformat", get_string("helpformatting"));
110 123
        print_string("formattexttype");
111 124
        echo ":&nbsp;";
112  
-       if (!$form->format) {
113  
-           $form->format = $defaultformat;
  125
+       if (!isset($newentry->format)) {
  126
+           $newentry->format = $defaultformat;
114 127
        }
115  
-       choose_from_menu(format_text_menu(), "format", $entry->format, ""); 
  128
+       choose_from_menu(format_text_menu(), "format", $newentry->format, ""); 
116 129
        echo "</p>";
117 130
     ?>
118 131
     </td>
@@ -131,13 +144,14 @@
131 144
 <tr>
132 145
 <td colspan=2>
133 146
 	<p align=center>
134  
-	<?php if ($entry->id) {
135  
-		echo "<input type=\"hidden\" name=entry value=\"$entry->id\">";
  147
+	<?php if (isset($newentry->id)) {
  148
+		echo "<input type=\"hidden\" name=e value=\"$newentry->id\">";
136 149
    	 }
137 150
 	?>
138 151
 	<input type="hidden" name=id value="<?=$cm->id ?>">
139  
-	<input type="hidden" name=currentview value="<?=$currentview ?>">
  152
+	<input type="hidden" name=tab value="<?=$tab ?>">
140 153
 	<input type="hidden" name=cat value="<?=$cat ?>">
  154
+	<input type="hidden" name=confirm value="1">
141 155
 
142 156
 	<input type="submit" value="<?php print_string("savechanges") ?>">
143 157
 	<input type="reset" value="<?php print_string("revert") ?>">
233  mod/glossary/edit.php
@@ -6,8 +6,9 @@
6 6
 
7 7
 require_variable($id);    // Course Module ID
8 8
 optional_variable($e);    // EntryID
  9
+optional_variable($confirm,0);    // proceed. Edit the edtry
9 10
 
10  
-optional_variable($currentview);   // categories if by category?
  11
+optional_variable($tab);   // categories if by category?
11 12
 optional_variable($cat);    // CategoryID
12 13
 
13 14
 if (! $cm = get_record("course_modules", "id", $id)) {
@@ -27,124 +28,121 @@
27 28
 if (! $glossary = get_record("glossary", "id", $cm->instance)) {
28 29
     error("Course module is incorrect");
29 30
 }
30  
-
31  
-if ($e) {
32  
-     $form = get_record("glossary_entries", "id", $e);
33  
-
34  
-     $newentry->id = $form->id;
35  
-     $newentry->concept = $form->concept;
36  
-     $newentry->definition = $form->definition;
37  
-     $newentry->format = $form->format;
38  
-     $newentry->timemodified = time();
39  
-
40  
-     $entry->id = $form->id;
41  
-     $entry->text = $form->definition;
42  
-     $entry->format = $form->format;
43  
-} else {
44  
-     if ($form = data_submitted()) {
45  
-     /// If data submitted, then process and store.
46  
-          $timenow = time();
47  
-
48  
-          $form->text = clean_text($form->text, $form->format);
49  
-
50  
-          if ($entry) {
51  
-                $newentry->id = $entry;
52  
-                $newentry->course = $glossary->course;
53  
-                $newentry->glossaryid = $glossary->id;
54  
-                $newentry->concept = $form->concept;
55  
-                $newentry->definition = $form->text;
56  
-                $newentry->format = $form->format;
57  
-                $newentry->usedynalink = $form->usedynalink;
58  
-                $newentry->casesensitive = $form->casesensitive;
59  
-                $newentry->fullmatch = $form->fullmatch;
60  
-                $newentry->timemodified = time();		
61  
-                $newentry->teacherentry = isteacher($course->id,$USER->id);
62  
-
63  
-                $permissiongranted = 1;
64  
-                if ( !$glossary->allowduplicatedentries ) {
65  
-                    $dupentries = get_records("glossary_entries","UCASE(concept)", strtoupper($newentry->concept));
66  
-                    if ($dupentries) {          	
67  
-                         foreach ($dupentries as $curentry) {
68  
-                             if ( $glossary->id == $curentry->glossaryid ) {
69  
-                                 if ( $curentry->id != $entry ) {
70  
-                                     $permissiongranted = 0;
71  
-                                 }
72  
-                              }
73  
-                         }
74  
-                     }
75  
-                }
76  
-                if ( $permissiongranted ) {
77  
-                    $newentry->attachment = $_FILES["attachment"];
78  
-                    if ($newfilename = glossary_add_attachment($newentry, $newentry->attachment)) {
79  
-                         $newentry->attachment = $newfilename;
80  
-                    } else {
81  
-                         unset($newentry->attachment);
82  
-                    }
83  
-                    if (! update_record("glossary_entries", $newentry)) {
84  
-               	        error("Could not update your glossary");
85  
-               	    } else {
86  
-                      add_to_log($course->id, "glossary", "update entry", "view.php?id=$cm->id&eid=$newentry->id", "$newentry->id");
87  
-           	        }
88  
-                } else {
89  
-               	   error("Could not update this glossary entry because this concept already exist.");
90  
-                }
91  
-          } else {
92  
-                $newentry->userid = $USER->id;
93  
-                $newentry->course = $glossary->course;
94  
-                $newentry->glossaryid = $glossary->id;
95  
-                $newentry->concept = $form->concept;
96  
-                $newentry->definition = $form->text;
97  
-                $newentry->format = $form->format;
98  
-                $newentry->timecreated = time();
99  
-                $newentry->usedynalink = $form->usedynalink;
100  
-                $newentry->casesensitive = $form->casesensitive;
101  
-                $newentry->fullmatch = $form->fullmatch;
102  
-                $newentry->timemodified = time();
103  
-                $newentry->teacherentry = isteacher($course->id,$USER->id);
104  
-                $newentry->sourceglossaryid = 0;
105  
-
106  
-                $permissiongranted = 1;
107  
-                if ( !$glossary->allowduplicatedentries ) {
108  
-                       $dupentries = get_record("glossary_entries","UCASE(concept)", strtoupper($newentry->concept), "glossaryid", $glossary->id);
109  
-                       if ($dupentries) {
110  
-                              $permissiongranted = 0;
  31
+if ( $confirm ) {
  32
+    $form = data_submitted();
  33
+
  34
+    $timenow = time();
  35
+    $form->text = clean_text($form->text, $form->format);
  36
+
  37
+    $newentry->course = $glossary->course;
  38
+    $newentry->glossaryid = $glossary->id;
  39
+
  40
+    $newentry->concept = $form->concept;
  41
+    $newentry->definition = $form->text;
  42
+    $newentry->format = $form->format;
  43
+    $newentry->usedynalink = $form->usedynalink;
  44
+    $newentry->casesensitive = $form->casesensitive;
  45
+    $newentry->fullmatch = $form->fullmatch;
  46
+    $newentry->timemodified = $timenow;		
  47
+
  48
+    if ($e) {
  49
+        $newentry->id = $e;
  50
+    
  51
+        $permissiongranted = 1;
  52
+        if ( !$glossary->allowduplicatedentries ) {
  53
+            if ($dupentries = get_records("glossary_entries","UCASE(concept)", strtoupper($newentry->concept))) {
  54
+                foreach ($dupentries as $curentry) {
  55
+                    if ( $glossary->id == $curentry->glossaryid ) {
  56
+                       if ( $curentry->id != $entry ) {
  57
+                          $permissiongranted = 0;
  58
+                           break;
111 59
                        }
  60
+                    }
112 61
                 }
113  
-                if ( $permissiongranted ) {
114  
-                       if (! $newentry->id = insert_record("glossary_entries", $newentry)) {
115  
-                             error("Could not insert this new entry");
116  
-                       } else {
117  
-                              $newentry->attachment = $_FILES["attachment"];
118  
-                              if ($newfilename = glossary_add_attachment($newentry, $newentry->attachment)) {
119  
-                                   $newentry->attachment = $newfilename;
120  
-                              } else {
121  
-                                   unset($newentry->attachment);
122  
-                              }
123  
-                              set_field("glossary_entries", "attachment", $newfilename, "id", $newentry->id);
124  
-
125  
-                              add_to_log($course->id, "glossary", "add entry", "view.php?id=$cm->id&eid=$newentry->id&currentview=$currentview&cat=$cat", "$newentry->id");
126  
-                       }
  62
+            }
  63
+        }
  64
+    
  65
+        if ( $permissiongranted ) {
  66
+            $newentry->attachment = $_FILES["attachment"];
  67
+            if ($newfilename = glossary_add_attachment($newentry, $newentry->attachment)) {
  68
+                $newentry->attachment = $newfilename;
  69
+            } else {
  70
+                unset($newentry->attachment);
  71
+            }
  72
+            if (! update_record("glossary_entries", $newentry)) {
  73
+                error("Could not update your glossary");
  74
+            } else {
  75
+                add_to_log($course->id, "glossary", "update entry", "view.php?id=$cm->id&eid=$newentry->id&tab=$tab&cat=$cat", "$newentry->id");
  76
+           	}
  77
+        } else {
  78
+            error("Could not update this glossary entry because this concept already exist.");
  79
+        }
  80
+    } else {
  81
+        $newentry->userid = $USER->id;
  82
+        $newentry->timecreated = $timenow;
  83
+        $newentry->sourceglossaryid = 0;
  84
+        $newentry->approved = $glossary->defaultapproval or isteacher($course->id);
  85
+        $newentry->teacherentry = isteacher($course->id);
  86
+
  87
+        $permissiongranted = 1;
  88
+        if ( !$glossary->allowduplicatedentries ) {
  89
+            if ($dupentries = get_record("glossary_entries","UCASE(concept)", strtoupper($newentry->concept), "glossaryid", $glossary->id)) {
  90
+                $permissiongranted = 0;
  91
+            }
  92
+        }
  93
+        if ( $permissiongranted ) {
  94
+            if (! $newentry->id = insert_record("glossary_entries", $newentry)) {
  95
+                error("Could not insert this new entry");
  96
+            } else {
  97
+                $newentry->attachment = $_FILES["attachment"];
  98
+                if ($newfilename = glossary_add_attachment($newentry, $newentry->attachment)) {
  99
+                    $newentry->attachment = $newfilename;
127 100
                 } else {
128  
-                    error("Could not insert this glossary entry because this concept already exist.");
129  
-                }
130  
-          }
131  
-
132  
-           delete_records("glossary_entries_categories","entryid",$entry);
133  
-
134  
-           if ( $categories ) {
135  
-                $newcategory->entryid = $newentry->id;
136  
-                foreach ($categories as $category) {
137  
-                    if ( $category > 0 ) {
138  
-                        $newcategory->categoryid =$category;
139  
-                        insert_record("glossary_entries_categories",$newcategory);
140  
-                    } else {
141  
-                        break;
142  
-                    }
  101
+                     unset($newentry->attachment);
143 102
                 }
144  
-           }
145  
-          redirect("view.php?id=$cm->id&eid=$newentry->id");
146  
-          die;
147  
-     }
  103
+                set_field("glossary_entries", "attachment", $newfilename, "id", $newentry->id);
  104
+                add_to_log($course->id, "glossary", "add entry", "view.php?id=$cm->id&eid=$newentry->id&tab=$tab&cat=$cat", "$newentry->id");
  105
+            }
  106
+        } else {
  107
+            error("Could not insert this glossary entry because this concept already exist.");
  108
+        }
  109
+    }
  110
+
  111
+    delete_records("glossary_entries_categories","entryid",$e);
  112
+
  113
+    if ( $categories ) {
  114
+        $newcategory->entryid = $newentry->id;
  115
+        foreach ($categories as $category) {
  116
+            if ( $category > 0 ) {
  117
+                $newcategory->categoryid =$category;
  118
+                insert_record("glossary_entries_categories",$newcategory);
  119
+            } else {
  120
+                break;
  121
+            }
  122
+        }
  123
+    }
  124
+    redirect("view.php?id=$cm->id&eid=$newentry->id");
  125
+    die;
  126
+} else {
  127
+    if ($e) {
  128
+        $form = get_record("glossary_entries", "id", $e);
  129
+
  130
+        $newentry->id = $form->id;
  131
+        $newentry->concept = $form->concept;
  132
+        $newentry->definition = $form->definition;
  133
+        $newentry->format = $form->format;
  134
+        $newentry->timemodified = time();
  135
+        $newentry->approved = $glossary->defaultapproval or isteacher($course->id);
  136
+        $newentry->usedynalink = $form->usedynalink;
  137
+        $newentry->casesensitive = $form->casesensitive;
  138
+        $newentry->fullmatch = $form->fullmatch;
  139
+    } else {
  140
+        $newentry->concept = "";
  141
+        $newentry->definition = "";
  142
+        $newentry->usedynalink = 1;
  143
+        $newentry->casesensitive = 0;
  144
+        $newentry->fullmatch = 1;
  145
+    }
148 146
 }
149 147
 /// Otherwise fill and print the form.
150 148
 
@@ -160,11 +158,6 @@
160 158
     $onsubmit = "";
161 159
 }
162 160
 
163  
-if (empty($entry)) {
164  
-    $entry->text = "";
165  
-    $entry->format = $defaultformat;
166  
-}
167  
-
168 161
 print_header(strip_tags("$course->shortname: $glossary->name"), "$course->fullname",
169 162
              "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> 
170 163
               <A HREF=\"index.php?id=$course->id\">$strglossaries</A> -> 
9  mod/glossary/formats/2.php
... ...
@@ -1,6 +1,6 @@
1 1
 <?PHP  // $Id$
2 2
 
3  
-function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $currentview="",$cat="") {
  3
+function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $tab="",$cat="") {
4 4
     global $THEME, $CFG, $USER;
5 5
 
6 6
     $colour = $THEME->cellheading2;
@@ -16,7 +16,10 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $curren
16 16
         print_user_picture($user->id, $course->id, $user->picture);
17 17
     }
18 18
     echo "</td>";
19  
-    echo "<td nowrap width=100% bgcolor=\"$THEME->cellheading\" class=\"forumpostheader\">";
  19
+    echo "<td nowrap valign=\"top\" width=100% bgcolor=\"$THEME->cellheading\" class=\"forumpostheader\">";
  20
+    if ( $tab == GLOSSARY_APPROVAL_VIEW ) {
  21
+        echo "<a title=\"" . get_string("approve","glossary"). "\" href=\"approve.php?id=$cm->id&eid=$entry->id&tab=$tab\"><IMG align=\"right\" src=\"check.gif\" border=0 width=\"34\" height=\"34\"></a>";
  22
+    }
20 23
     if ($entry->attachment) {
21 24
           $entry->course = $glossary->course;
22 25
           echo "<table border=0 align=right><tr><td>";
@@ -36,7 +39,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $curren
36 39
     echo "\n<td width=100% bgcolor=\"$THEME->cellcontent\" class=\"forumpostmessage\">";
37 40
     if ($entry) {
38 41
         echo format_text($entry->definition, $entry->format);
39  
-        glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview,$cat);
  42
+        glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab,$cat);
40 43
 
41 44
     } else {
42 45
         echo "<center>";
11  mod/glossary/formats/3.php
... ...
@@ -1,6 +1,6 @@
1 1
 <?PHP  // $Id$
2 2
 
3  
-function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $currentview="",$cat="") {
  3
+function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $tab="",$cat="") {
4 4
     global $THEME, $CFG, $USER;
5 5
 
6 6
     $colour = $THEME->cellheading2;
@@ -16,8 +16,11 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $curren
16 16
         print_user_picture($user->id, $course->id, $user->picture);
17 17
     }
18 18
     echo "</td>";
19  
-    echo "<td nowrap width=100% bgcolor=\"$THEME->cellheading\" class=\"forumpostheader\">";
  19
+    echo "<td align=\"top\" nowrap width=100% bgcolor=\"$THEME->cellheading\" class=\"forumpostheader\">";
20 20
     if ($entry) {
  21
+        if ( $tab == GLOSSARY_APPROVAL_VIEW ) {
  22
+            echo "<a title=\"" . get_string("approve","glossary"). "\" href=\"approve.php?id=$cm->id&eid=$entry->id&tab=$tab\"><IMG align=\"right\" src=\"check.gif\" border=0 width=\"34\" height=\"34\"></a>";
  23
+        }
21 24
         echo "<b>$entry->concept</b><br />";
22 25
         echo "<font size=\"2\">$strby $user->firstname $user->lastname</font>";
23 26
         echo "&nbsp;&nbsp;<font size=1>(".get_string("lastedited").": ".
@@ -27,7 +30,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $curren
27 30
 
28 31
     echo "\n<tr>";
29 32
     echo "\n<td bgcolor=\"$colour\" width=35 valign=top class=\"forumpostside\">&nbsp;</td>";
30  
-    echo "\n<td width=100% bgcolor=\"$THEME->cellcontent\" class=\"forumpostmessage\">";
  33
+    echo "\n<td width=100% align=\"top\" bgcolor=\"$THEME->cellcontent\" class=\"forumpostmessage\">";
31 34
     if ($entry) {
32 35
         if ($entry->attachment) {
33 36
             $entry->course = $course->id;
@@ -42,7 +45,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $curren
42 45
         }
43 46
         echo format_text($entry->definition, $entry->format);
44 47
 
45  
-        glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview,$cat);
  48
+        glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab,$cat);
46 49
 
47 50
     } else {
48 51
         echo "<center>";
38  mod/glossary/formats/4.php
... ...
@@ -0,0 +1,38 @@
  1
+<?PHP  // $Id$
  2
+
  3
+function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$tab="",$cat="") {
  4
+    global $THEME, $USER;
  5
+
  6
+    if ( $entry ) {
  7
+        $colour = $THEME->cellheading2;
  8
+
  9
+        echo "\n<table border=1 cellspacing=0 width=95% valign=top cellpadding=10>";
  10
+
  11
+        echo "\n<tr>";
  12
+        echo "<td width=100% bgcolor=\"$colour\">";
  13
+        $entry->course = $course->id;
  14
+        if ( $tab == GLOSSARY_APPROVAL_VIEW ) {
  15
+            echo "<a title=\"" . get_string("approve","glossary"). "\" href=\"approve.php?id=$cm->id&eid=$entry->id&tab=$tab\"><IMG align=\"right\" src=\"check.gif\" border=0 width=\"34\" height=\"34\"></a>";
  16
+        }
  17
+        if ($entry->attachment) {
  18
+            echo "<table border=0 align=right><tr><td>";
  19
+            echo glossary_print_attachments($entry, "html");
  20
+            echo "</td></tr></table>";
  21
+        }
  22
+        echo "<b>" . get_string("question","glossary") . ":</b> $entry->concept<br>";
  23
+        echo "&nbsp;&nbsp;<font size=1>".get_string("lastedited").": ".userdate($entry->timemodified)."</font></tr>";
  24
+        echo "\n<tr><td width=100% bgcolor=\"$THEME->cellcontent\">";		
  25
+        echo "<b>" . get_string("answer","glossary") . ":</b> " . format_text($entry->definition, $entry->format);
  26
+
  27
+        glossary_print_entry_icons($course, $cm, $glossary, $entry, $tab, $cat);
  28
+        echo "</td></tr></table>\n";
  29
+
  30
+    } else {
  31
+        echo "<center>";
  32
+        print_string("noentry", "glossary");
  33
+        echo "</center>";
  34
+    }
  35
+
  36
+}
  37
+
  38
+?>
44  mod/glossary/formats/5.php
... ...
@@ -0,0 +1,44 @@
  1
+<?PHP  // $Id$
  2
+
  3
+function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$tab="",$cat="") {
  4
+    global $THEME, $USER;
  5
+
  6
+    $colour = $THEME->cellheading2;
  7
+
  8
+    echo "\n<table border=1 cellspacing=0 width=95% valign=top cellpadding=10>";
  9
+
  10
+    echo "\n<tr>";
  11
+    echo "<td width=100% bgcolor=\"$colour\">";
  12
+    if ( $tab == GLOSSARY_APPROVAL_VIEW ) {
  13
+        echo "<a title=\"" . get_string("approve","glossary"). "\" href=\"approve.php?id=$cm->id&eid=$entry->id&tab=$tab\"><IMG align=\"right\" src=\"check.gif\" border=0 width=\"34\" height=\"34\"></a>";
  14
+    }
  15
+    if ($entry->attachment) {
  16
+        $entry->course = $course->id;
  17
+        echo "<table border=0 align=right><tr><td>";
  18
+        echo glossary_print_attachments($entry, "html");
  19
+        echo "</td></tr></table>";
  20
+    }
  21
+    echo "<b>$entry->concept</b><br>";
  22
+    if ($entry) {
  23
+        echo "&nbsp;&nbsp;<font size=1>".get_string("lastedited").": ".userdate($entry->timemodified)."</font>";
  24
+    }
  25
+    echo "</tr>";
  26
+
  27
+    echo "\n<tr><td width=100% bgcolor=\"$THEME->cellcontent\">";
  28
+    if ($entry) {
  29
+        echo format_text($entry->definition, $entry->format);
  30
+
  31
+        glossary_print_entry_icons($course, $cm, $glossary, $entry, $tab, $cat);
  32
+
  33
+    } else {
  34
+        echo "<center>";
  35
+        print_string("noentry", "glossary");
  36
+        echo "</center>";
  37
+    }
  38
+    echo "</td></tr>";
  39
+
  40
+    echo "</table>\n";
  41
+
  42
+}
  43
+
  44
+?>
342  mod/glossary/lib.php
@@ -7,8 +7,10 @@
7 7
 
8 8
 define("GLOSSARY_SHOW_ALL_CATEGORIES", 0);
9 9
 define("GLOSSARY_SHOW_NOT_CATEGORISED", -1);
  10
+
10 11
 define("GLOSSARY_STANDARD_VIEW", 0);
11 12
 define("GLOSSARY_CATEGORY_VIEW", 1);
  13
+define("GLOSSARY_APPROVAL_VIEW", 2);
12 14
 
13 15
 define("GLOSSARY_FORMAT_SIMPLE", 0);
14 16
 define("GLOSSARY_FORMAT_CONTINUOUS", 1);
@@ -184,49 +186,79 @@ function glossary_get_entries($glossaryid, $entrylist) {
184 186
                             WHERE glossaryid = '$glossaryid'
185 187
                             AND id IN ($entrylist)");
186 188
 }
  189
+function glossary_get_entries_sorted($glossary, $where="", $orderby="") {
  190
+global $CFG;
  191
+    if ($where) {
  192
+       $where = " and $where";
  193
+    }
  194
+    if ($orderby) {
  195
+       $orderby = " ORDER BY $orderby";
  196
+    }
  197
+    return      get_records_sql("SELECT *
  198
+                                 FROM {$CFG->prefix}glossary_entries 
  199
+                                 WHERE (glossaryid = $glossary->id or sourceglossaryid = $glossary->id) $where $orderby");
  200
+}
  201
+
  202
+function glossary_get_entries_by_category($glossary, $cat, $where="", $orderby="") {
  203
+global $CFG;
  204
+    if ($where) {
  205
+       $where = " and $where";
  206
+    }
  207
+    if ($orderby) {
  208
+       $orderby = " ORDER BY $orderby";
  209
+    }
  210
+    return      get_records_sql("SELECT ge.*
  211
+                                 FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}glossary_entries_categories c
  212
+                                 WHERE (ge.id = c.entryid and c.categoryid = $cat) and
  213
+                                             (ge.glossaryid = $glossary->id or ge.sourceglossaryid = $glossary->id) $where $orderby");
  214
+}
187 215
 
188  
-function glossary_print_entry($course, $cm, $glossary, $entry, $currentview="",$cat="") {
  216
+function glossary_print_entry($course, $cm, $glossary, $entry, $tab="",$cat="") {
189 217
     global $THEME, $USER, $CFG;
190  
-    
191  
-    $permissiongranted = 0;
192  
-    $formatfile = "$CFG->dirroot/mod/glossary/formats/$glossary->displayformat.php";
193  
-    $functionname = "glossary_print_entry_by_format";
194  
-
195  
-    $basicformat = ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE or
196  
-                    $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS);
197  
-    if ( !$basicformat ) {
198  
-        if ( file_exists($formatfile) ) {
199  
-           include_once($formatfile);
200  
-           if (function_exists($functionname) ) {
201  
-              $permissiongranted = 1;
202  
-           }
  218
+
  219
+    if ($entry->approved or $USER->id == $entry->userid or $tab == GLOSSARY_APPROVAL_VIEW) {
  220
+        $permissiongranted = 0;
  221
+        $formatfile = "$CFG->dirroot/mod/glossary/formats/$glossary->displayformat.php";
  222
+        $functionname = "glossary_print_entry_by_format";
  223
+
  224
+        $basicformat = ($glossary->displayformat == GLOSSARY_FORMAT_SIMPLE or
  225
+                        $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS);
  226
+        if ( !$basicformat ) {
  227
+            if ( file_exists($formatfile) ) {
  228
+               include_once($formatfile);
  229
+               if (function_exists($functionname) ) {
  230
+                      $permissiongranted = 1;
  231
+               }
  232
+            }
  233
+        } else {
  234
+           $permissiongranted = 1;
203 235
         }
204  
-    } else {
205  
-       $permissiongranted = 1;
206  
-    }
207 236
     
208  
-    if ( !$basicformat and $permissiongranted ) {
209  
-        glossary_print_entry_by_format($course, $cm, $glossary, $entry,$currentview,$cat);
210  
-    } else {
211  
-        switch ( $glossary->displayformat ) {
212  
-            case GLOSSARY_FORMAT_SIMPLE:
213  
-                glossary_print_entry_by_default($course, $cm, $glossary, $entry,$currentview,$cat);
214  
-            break;
215  
-            case GLOSSARY_FORMAT_CONTINUOUS:
216  
-                glossary_print_entry_continuous($course, $cm, $glossary, $entry,$currentview,$cat);
217  
-            break;
  237
+        if ( !$basicformat and $permissiongranted ) {
  238
+            glossary_print_entry_by_format($course, $cm, $glossary, $entry,$tab,$cat);
  239
+        } else {
  240
+            switch ( $glossary->displayformat ) {
  241
+                case GLOSSARY_FORMAT_SIMPLE:
  242
+                    glossary_print_entry_by_default($course, $cm, $glossary, $entry,$tab,$cat);
  243
+                break;
  244
+                case GLOSSARY_FORMAT_CONTINUOUS:
  245
+                    glossary_print_entry_continuous($course, $cm, $glossary, $entry,$tab,$cat);
  246
+                    break;
  247
+            }
218 248
         }
219 249
     }
220  
-
221 250
 }
222 251
 
223  
-function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$currentview="",$cat="") {
  252
+function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$tab="",$cat="") {
224 253
     global $THEME, $USER;
225 254
 
226 255
     $colour = $THEME->cellheading2;
227 256
 
228 257
     echo "\n<TR>";
229  
-    echo "<TD WIDTH=100% BGCOLOR=\"#FFFFFF\">";
  258
+    echo "<TD WIDTH=100% valign=\"top\" BGCOLOR=\"#FFFFFF\">";
  259
+    if ( $tab == GLOSSARY_APPROVAL_VIEW ) {
  260
+        echo "<a title=\"" . get_string("approve","glossary"). "\" href=\"approve.php?id=$cm->id&eid=$entry->id&tab=$tab\"><IMG align=\"right\" src=\"check.gif\" border=0 width=\"34\" height=\"34\"></a>";
  261
+    }
230 262
     if ($entry->attachment) {
231 263
           $entry->course = $course->id;
232 264
           echo "<table border=0 align=right><tr><td>";
@@ -235,14 +267,17 @@ function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$curren
235 267
     }
236 268
     echo "<b>$entry->concept</b>: ";
237 269
     echo format_text($entry->definition, $entry->format);
238  
-    glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview,$cat);
  270
+    glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab,$cat);
239 271
     echo "</td>";
240 272
     echo "</TR>";
241 273
 }
242 274
 
243  
-function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$currentview="",$cat="") {
  275
+function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$tab="",$cat="") {
244 276
     global $THEME, $USER;
245 277
     if ($entry) {
  278
+        if ( $tab == GLOSSARY_APPROVAL_VIEW ) {
  279
+            echo "<a title=\"" . get_string("approve","glossary"). "\" href=\"approve.php?id=$cm->id&eid=$entry->id&tab=$tab\"><IMG align=\"right\" src=\"check.gif\" border=0 width=\"34\" height=\"34\"></a>";
  280
+        }
246 281
         if ($entry->attachment) {
247 282
             $entry->course = $course->id;
248 283
             echo "<table border=0 align=right><tr><td>";
@@ -252,31 +287,34 @@ function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$curren
252 287
         echo " $entry->concept ";
253 288
         echo format_text($entry->definition, $entry->format);
254 289
 
255  
-        glossary_print_entry_icons($course, $cm, $glossary, $entry, $currentview, $cat);
  290
+        glossary_print_entry_icons($course, $cm, $glossary, $entry, $tab, $cat);
256 291
     }
257 292
 }
258  
-function glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview="",$cat="") {
  293
+function glossary_print_entry_icons($course, $cm, $glossary, $entry,$tab="",$cat="") {
259 294
     global $THEME, $USER;
260 295
 
261 296
     $importedentry = ($entry->sourceglossaryid == $glossary->id);
262 297
     $isteacher = isteacher($course->id);
263 298
     $ismainglossary = $glossary->mainglossary;
264 299
 	
265  
-    echo "<p align=\"right\">";
  300
+    echo "<p align=\"right\"><font size=1>";
266 301
 
  302
+    if (!$entry->approved) {
  303
+        echo get_string("entryishidden","glossary");
  304
+    }
267 305
     $count = count_records("glossary_comments","entryid",$entry->id);
268 306
     if ($count) {
269  
-        echo "<font size=1><a href=\"comments.php?id=$cm->id&eid=$entry->id\">$count ";
  307
+        echo " <a href=\"comments.php?id=$cm->id&eid=$entry->id\">$count ";
270 308
         if ($count == 1) {
271 309
             print_string("comment", "glossary");
272 310
         } else {
273 311
             print_string("comments", "glossary");
274 312
         }
275  
-        echo "</a></font> ";
  313
+        echo "</a>";
276 314
     }
277  
-
  315
+    echo "</font>";
278 316
     if ( $glossary->allowcomments ) {
279  
-        echo "<a href=\"comment.php?id=$cm->id&eid=$entry->id\"><img  alt=\"" . get_string("addcomment","glossary") . "\" src=\"comment.gif\" height=16 width=16 border=0></a> ";
  317
+        echo " <a href=\"comment.php?id=$cm->id&eid=$entry->id\"><img  alt=\"" . get_string("addcomment","glossary") . "\" src=\"comment.gif\" height=16 width=16 border=0></a> ";
280 318
     }
281 319
 
282 320
     if ($isteacher or $glossary->studentcanpost and $entry->userid == $USER->id) {
@@ -285,7 +323,7 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview
285 323
             $mainglossary = get_record("glossary","mainglossary",1,"course",$course->id);
286 324
             if ( $mainglossary ) {  // if there is a main glossary defined, allow to export the current entry
287 325
 
288  
-                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> ";
  326
+                echo " <a href=\"exportentry.php?id=$cm->id&entry=$entry->id&tab=$tab&cat=$cat\"><img  alt=\"" . get_string("exporttomainglossary","glossary") . "\"src=\"export.gif\" height=11 width=11 border=0></a> ";
289 327
 
290 328
             }
291 329
         }
@@ -298,13 +336,13 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview
298 336
 
299 337
         // Exported entries can be updated/deleted only by teachers in the main glossary
300 338
         if ( !$importedentry and ($isteacher or !$ismainglossary) ) {
301  
-            echo "<a href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id&currentview=$currentview&cat=$cat\"><img  alt=\"" . get_string("delete") . "\"src=\"";
  339
+            echo " <a href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id&tab=$tab&cat=$cat\"><img  alt=\"" . get_string("delete") . "\"src=\"";
302 340
             echo $icon;
303 341
             echo "\" height=11 width=11 border=0></a> ";
304 342
             
305  
-            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>";
  343
+            echo " <a href=\"edit.php?id=$cm->id&e=$entry->id&tab=$tab&cat=$cat\"><img  alt=\"" . get_string("edit") . "\" src=\"../../pix/t/edit.gif\" height=11 width=11 border=0></a>";
306 344
         } elseif ( $importedentry ) {
307  
-            echo "<font size=-1>" . get_string("exportedentry","glossary") . "</font>";
  345
+            echo " <font size=-1>" . get_string("exportedentry","glossary") . "</font>";
308 346
         }
309 347
     }
310 348
 }
@@ -376,12 +414,12 @@ function glossary_search_entries($searchterms, $glossary, $includedefinition) {
376 414
                   {$CFG->prefix}glossary g $onlyvisibletable
377 415
              WHERE ($conceptsearch OR $definitionsearch)
378 416
                AND (e.glossaryid = g.id or e.sourceglossaryid = g.id) $onlyvisible
379  
-		   AND g.id = $glossary->id";
  417
+               AND g.id = $glossary->id AND e.approved != 0";
380 418
 
381  
-    $totalcount = count_records_sql("SELECT COUNT(*) FROM $selectsql");
  419
+//    $totalcount = count_records_sql("SELECT COUNT(*) FROM $selectsql");
382 420
 
383  
-    return get_records_sql("SELECT e.concept, e.definition, e.userid, e.timemodified, e.id, e.format  FROM
384  
-                            $selectsql ORDER BY e.concept ASC $limit");
  421
+    return get_records_sql("SELECT e.concept, e.definition, e.userid, e.timemodified, e.id, e.format 
  422
+                            FROM $selectsql ORDER BY e.concept ASC $limit");
385 423
 }
386 424
 
387 425
 function glossary_file_area_name($entry) {
@@ -710,39 +748,135 @@ function glossary_print_tabbed_table_end() {
710 748
      echo "</center><p></td></tr></table></center>";
711 749
 }
712 750
 
713  
-function glossary_print_alphabet_menu($cm, $glossary, $l, $sortkey, $sortorder = "") {
714  
-global $CFG, $THEME;
715  
-    $strselectletter     = get_string("selectletter", "glossary");
716  
-    $strspecial          = get_string("special", "glossary");
717  
-    $strallentries       = get_string("allentries", "glossary");
718  
-    $strsort             = get_string("sortchronogically", "glossary");
719  
-    $strsortbycreation   = get_string("sortbycreation", "glossary");
720  
-    $strsortbylastupdate = get_string("sortbylastupdate", "glossary");
  751
+function glossary_print_approval_menu($cm, $glossary, $l, $sortkey, $sortorder = "",$tab=GLOSSARY_STANDARD_VIEW) {
  752
+    $entriesawaiting     = get_string("entriesawaitingapproval", "glossary");
  753
+    echo "<center>$entriesawaiting<p>";
721 754
 
722  
-    $output = "";
723  
-    if ($glossary->showalphabet) {
724  
-        $output .= get_string("explainalphabet","glossary").'<br />';
  755
+    if ($glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
  756
+        echo '<center>' . get_string("explainalphabet","glossary") . '<br /><p>';
725 757
     }
  758
+    glossary_print_special_links($cm, $glossary,$l, $tab);
  759
+
  760
+    glossary_print_alphabet_links($cm, $glossary,$l, $tab);
  761
+
  762
+    glossary_print_all_links($cm, $glossary,$l, $tab);
  763
+	 
  764
+    glossary_print_sorting_links($cm, $sortkey,$sortorder, $tab);
  765
+}
  766
+
  767
+function glossary_print_alphabet_menu($cm, $glossary, $l, $sortkey, $sortorder = "", $tab=GLOSSARY_STANDARD_VIEW) {
  768
+    if ($glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
  769
+        echo '<center>' . get_string("explainalphabet","glossary") . '<br /><p>';
  770
+    }
  771
+    glossary_print_special_links($cm, $glossary,$l, $tab);
  772
+
  773
+    glossary_print_alphabet_links($cm, $glossary,$l, $tab);
  774
+
  775
+    glossary_print_all_links($cm, $glossary,$l, $tab);
  776
+	 
  777
+    glossary_print_sorting_links($cm, $sortkey,$sortorder, $tab);
  778
+}
  779
+
  780
+function glossary_print_categories_menu($course, $cm, $glossary, $cat, $category) {
  781
+global $CFG, $THEME;
  782
+     echo "<table border=0 width=100%>";
  783
+     echo "<tr>";
  784
+
  785
+     echo "<td align=center width=20%>";
  786
+     if ( isteacher($course->id) ) {
  787
+             $options['id'] = $cm->id;
  788
+             $options['cat'] = $cat;
  789
+             echo print_single_button("editcategories.php", $options, get_string("editcategories","glossary"), "get");
  790
+     }
  791
+     echo "</td>";
  792
+
  793
+     echo "<td align=center width=60%>";
  794
+     echo "<b>";
  795
+
  796
+     $menu[GLOSSARY_SHOW_ALL_CATEGORIES] = get_string("allcategories","glossary");
  797
+     $menu[GLOSSARY_SHOW_NOT_CATEGORISED] = get_string("notcategorised","glossary");
726 798
 
727  
-    echo "<center>$output<p>";
  799
+     $categories = get_records("glossary_categories", "glossaryid", $glossary->id, "name ASC");
  800
+     $selected = "";
  801
+     if ( $categories ) {
  802
+          foreach ($categories as $currentcategory) {
  803
+                 $url = $currentcategory->id;
  804
+                 if ( $category ) {
  805
+                     if ($currentcategory->id == $category->id) {
  806
+                         $selected = $url;
  807
+                     }
  808
+                 }
  809
+                 $menu[$url] = $currentcategory->name;
  810
+          }
  811
+     }
  812
+     if ( !$selected ) {
  813
+         $selected = GLOSSARY_SHOW_NOT_CATEGORISED;
  814
+     }
  815
+
  816
+     if ( $category ) {
  817
+        echo $category->name;
  818
+     } else {
  819
+        if ( $cat == GLOSSARY_SHOW_NOT_CATEGORISED ) {
  820
+
  821
+            echo get_string("entrieswithoutcategory","glossary");
  822
+            $selected = GLOSSARY_SHOW_NOT_CATEGORISED;
  823
+
  824
+        } elseif ( $cat == GLOSSARY_SHOW_ALL_CATEGORIES ) {
  825
+
  826
+            echo get_string("allcategories","glossary");
  827
+            $selected = GLOSSARY_SHOW_ALL_CATEGORIES;
  828
+
  829
+        }
  830
+     }
  831
+     echo "</b></td>";
  832
+     echo "<td align=center width=20%>";
  833
+
  834
+     echo popup_form("$CFG->wwwroot/mod/glossary/view.php?id=$cm->id&tab=" . GLOSSARY_CATEGORY_VIEW . "&cat=", $menu, "catmenu", $selected, "",
  835
+                      "", "", false);
728 836
 
729  
-     if ( $glossary->showspecial ) {
  837
+     echo "</td>";
  838
+     echo "</tr>";
  839
+
  840
+     echo "<tr><td colspan=3><hr></td></tr>";
  841
+     echo "</table>";
  842
+}
  843
+
  844
+function glossary_print_all_links($cm, $glossary, $l, $tab) {
  845
+global $CFG;  
  846
+     if ( $glossary->showall and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
  847
+         $strallentries       = get_string("allentries", "glossary");
  848
+         if ( $l == "ALL" ) {