]> git.mjollnir.org Git - moodle.git/commitdiff
Bulk changes to support plugin-formats in glossaries.
authorstronk7 <stronk7>
Tue, 27 Jul 2004 17:19:47 +0000 (17:19 +0000)
committerstronk7 <stronk7>
Tue, 27 Jul 2004 17:19:47 +0000 (17:19 +0000)
See the TODO.txt to get details about pending tasks.
The db upgrade should work fine (not tested under postgresql).
The plugin architecture is finished too.
See Bug 936.
(http://moodle.org/bugs/bug.php?op=show&bugid=936)

23 files changed:
mod/glossary/TODO.txt
mod/glossary/config.html
mod/glossary/db/mysql.php
mod/glossary/db/mysql.sql
mod/glossary/db/postgres7.php
mod/glossary/db/postgres7.sql
mod/glossary/formats.php
mod/glossary/formats/continuous/continuous_format.php [new file with mode: 0644]
mod/glossary/formats/dictionary/dictionary_format.php [new file with mode: 0644]
mod/glossary/formats/encyclopedia/encyclopedia_format.php [new file with mode: 0644]
mod/glossary/formats/entrylist/entrylist_format.php [new file with mode: 0644]
mod/glossary/formats/faq/faq_format.php [new file with mode: 0644]
mod/glossary/formats/fullwithauthor/fullwithauthor_format.php [new file with mode: 0644]
mod/glossary/formats/fullwithoutauthor/fullwithoutauthor_format.php [new file with mode: 0644]
mod/glossary/lib.php
mod/glossary/mod.html
mod/glossary/print.php
mod/glossary/restorelib.php
mod/glossary/showentry.php
mod/glossary/sql.php
mod/glossary/tabs.html
mod/glossary/version.php
mod/glossary/view.php

index 874b90ebb97d677cba35653c54afca01d951c4bc..c390b3a5ad1fae65453826ad020c51dd0e3ad32b 100644 (file)
@@ -13,3 +13,9 @@ Things that are in the inkpot yet:
        * Show (or do not) the group breaks.
         * Default view for automatic links, entry view, etc.
        * What else? Post in http://moodle.org/mod/forum/view.php?id=742
+
+News about plugin-formats TODO (Updated: Jul 23, 2004 - Eloy)
+
+*Review every format (only dictionary has been polished just now).
+*Include a template format to make things easier for new formats.
+*Include support for a customised print view in each format.
index 8de4ace6923f0cde5fee819caae215301c92350d..57ac5bf72d8651c6401ca5bbae2efb976d968ea2 100644 (file)
 <tr>
     <td colspan=3 align=center>
 <?php
-    if ( !$displayformat = get_record("glossary_displayformats","fid",0) ) {
-        unset($displayformat);
-        $displayformat->fid = 0;
-        $displayformat->relatedview = 0;
-        $displayformat->visible = 1;
-        $displayformat->id = insert_record("glossary_displayformats",$displayformat);
-    }
-    if ( !$displayformat = get_record("glossary_displayformats","fid",1) ) {
-        unset($displayformat);
-        $displayformat->fid = 1;
-        $displayformat->relatedview = 1;
-        $displayformat->visible = 1;
-        $displayformat->id = insert_record("glossary_displayformats",$displayformat);
-    }
+
+    //Update and get available formats
+    $recformats = glossary_get_available_formats();
 
     $formats = array();
-    $formats[0] = get_string("displayformatdefault", "glossary");
-    $formats[1] = get_string("displayformatcontinuous", "glossary");
 
-    $basedir = opendir("$CFG->dirroot/mod/glossary/formats");
-    while ($dir = readdir($basedir)) {
-        $firstchar = substr($dir, 0, 1);
-        if ($firstchar == "." or $dir == "CVS" or $dir == "_vti_cnf") {
-            continue;
-        }
-        if (filetype("$CFG->dirroot/mod/glossary/formats/$dir") == "dir") {
-            continue;
-        }
-        if ( $pos = strpos($dir, ".") ) {
-            $dir = substr($dir, 0, $pos );
-            if ($dir != 0 and $dir != 1) {  // excluding basic formats
-                if ( !$displayformat = get_record("glossary_displayformats","fid",$dir) ) {
-                    unset($displayformat);
-                    $displayformat->fid = $dir;
-                    $displayformat->relatedview = $dir;
-                    $displayformat->visible = 1;
-                    $displayformat->id = insert_record("glossary_displayformats",$displayformat);
-                }
-                $formats[$dir] = get_string("displayformat$dir", "glossary");
-            }
-        }
+    //Take names
+    foreach ($recformats as $format) {
+        $formats[$format->id] = get_string("displayformat$format->name", "glossary");
     }
     asort($formats);
 
     echo '<table cellpadding="5" bgcolor="#FFFFFF" class="generaltab" width="40%" align="center">';
-    for ($i = 0; $i < count($formats); $i++) {
-        if ( $formats[$i] ) {
-            $format = get_record("glossary_displayformats","fid",$i);
-            echo '<tr>';
-                echo '<td>' . $formats[$i] . '</td>';
-                $eicon = "<a title=\"" . get_string("edit") . "\" href=\"$CFG->wwwroot/mod/glossary/formats.php?id=$i&mode=edit\"><img border=\"0\" src=\"../pix/t/edit.gif\"></a>";
-                if ( $format->visible ) {
-                    $vtitle = get_string("hide");
-                    $vicon = "hide.gif";
-                } else {
-                    $vtitle = get_string("show");
-                    $vicon = "show.gif";
-                }
-                $vicon = "<a title=\"" . $vtitle . "\" href=\"$CFG->wwwroot/mod/glossary/formats.php?id=$i&mode=visible\"><img border=\"0\" src=\"../pix/t/" . $vicon . "\"></a>";
-
-                echo '<td align="center"> ' . $eicon . '&nbsp;&nbsp;' . $vicon . '</td>';
-            echo '</tr>';
+    foreach ($formats as $formatid=>$formatname) {
+        $recformat = get_record('glossary_formats','id',$formatid);
+        echo '<tr>';
+        echo '<td>' . $formatname . '</td>';
+        $eicon = "<a title=\"" . get_string("edit") . "\" href=\"$CFG->wwwroot/mod/glossary/formats.php?id=$formatid&mode=edit\"><img border=\"0\" src=\"../pix/t/edit.gif\"></a>";
+        if ( $recformat->visible ) {
+            $vtitle = get_string("hide");
+            $vicon = "hide.gif";
+        } else {
+            $vtitle = get_string("show");
+            $vicon = "show.gif";
         }
+        $vicon = "<a title=\"" . $vtitle . "\" href=\"$CFG->wwwroot/mod/glossary/formats.php?id=$formatid&mode=visible\"><img border=\"0\" src=\"../pix/t/" . $vicon . "\"></a>";
+
+        echo '<td align="center" nowrap>' . $eicon . '&nbsp;&nbsp;' . $vicon . '</td>';
+        echo '</tr>';
     }
     echo '</table>';
 
         <td align=right><p>glossary_enablerssfeeds:</td>
         <td>
     <?php
-        if ($CFG->enablerssfeeds == 0) {
+        if (!isset($CFG->enablerssfeeds) || $CFG->enablerssfeeds == 0) {
             print_string("no");
         } else {
             unset($options);
             $options[0] = get_string("no");
             $options[1] = get_string("yes");
 
-            choose_from_menu ($options, "glossary_enablerssfeeds", $CFG->glossary_enablerssfeeds, "", "", "");
+            $glossary_enablerssfeeds = false;
+            if (isset($CFG->glossary_enablerssfeeds) && $CFG->glossary_enablerssfeeds == 1) {
+                $glossary_enablerssfeeds = true;
+            }
+
+            choose_from_menu ($options, "glossary_enablerssfeeds", $glossary_enablerssfeeds, "", "", "");
         }
     ?>
     </td>
     <td>
     <?php
         print_string("configenablerssfeeds","glossary");
-        if ($CFG->enablerssfeeds == 0) {
+        if (!isset($CFG->enablerssfeeds) || $CFG->enablerssfeeds == 0) {
             print_string("configenablerssfeedsdisabled");
         }
     ?>
index 3d12b0411595a94d3e7ad327652797b2b1d1cded..9475154bae5047d0dfa21c5a6fd17922c07065da 100644 (file)
@@ -274,6 +274,67 @@ function glossary_upgrade($oldversion) {
   if ( $oldversion < 2004072300) {
       table_column("glossary_alias", "alias", "alias", "VARCHAR", "255", "", "", "NOT NULL");
   }
+
+  if ( $oldversion < 2004072400) {
+
+      //Create new table glossary_formats to store format info
+      execute_sql("CREATE TABLE `{$CFG->prefix}glossary_formats` (
+                       `id` INT(10) unsigned NOT NULL auto_increment,
+                       `name` VARCHAR(50) NOT NULL,
+                       `popupformatname` VARCHAR(50) NOT NULL, 
+                       `visible` TINYINT(2) UNSIGNED NOT NULL default '1',
+                       `showgroup` TINYINT(2) UNSIGNED NOT NULL default '1',
+                       `defaultmode` VARCHAR(50) NOT NULL default '',
+                       `defaulthook` VARCHAR(50) NOT NULL default '',
+                       `sortkey` VARCHAR(50) NOT NULL default '',
+                       `sortorder` VARCHAR(50) NOT NULL default '',
+                   PRIMARY KEY  (`id`)                    
+                   ) TYPE=MyISAM COMMENT='Setting of the display formats'");
+
+      //Define current 0-6 format names
+      $formatnames = array('dictionary','continuous','fullwithauthor','encyclopedia',
+                           'faq','fullwithoutauthor','entrylist');
+
+      //Fill the new table from the old one (only 'valid', 0-6, formats)
+      if ($formats = get_records('glossary_displayformats')) {
+          foreach ($formats as $format) {
+              //Format names
+              if ($format->fid >= 0 && $format->fid <= 6) {
+                  $format->name = $formatnames[$format->fid];
+              }
+
+              //Format popupformatname
+              $format->popupformatname = 'dictionary';  //Default format
+              if ($format->relatedview >= 0 && $format->relatedview <= 6) {
+                  $format->popupformatname = $formatnames[$format->relatedview];
+              }
+
+              //Insert the new record
+              //Only if $format->name is set (ie. formats 0-6)
+              if ($format->name) {
+                  insert_record('glossary_formats',$format);
+              }
+              
+          }
+      }
+
+      //Drop the old formats table
+      execute_sql("DROP TABLE `{$CFG->prefix}glossary_displayformats`");
+
+      //Modify the glossary->displayformat field
+      table_column('glossary', 'displayformat', 'displayformat', 'VARCHAR', '50', '', 'dictionary', 'NOT NULL');
+
+      //Update glossary->displayformat field
+      if ($glossaries = get_records('glossary')) {
+          foreach($glossaries as $glossary) {
+              $displayformat = 'dictionary';  //Default format
+              if ($glossary->displayformat >= 0 && $glossary->displayformat <= 6) {
+                  $displayformat = $formatnames[$glossary->displayformat];
+              }
+              set_field('glossary','displayformat',$displayformat,'id',$glossary->id);
+          }
+      }
+  }
     
   return true;
 }
index 6fd23f6a262ef9249735981e503bb1e2b662172d..b55b314fa1872b07dcfe4513ad6bef213341b76d 100644 (file)
@@ -15,7 +15,7 @@ CREATE TABLE prefix_glossary (
      intro text NOT NULL,
      studentcanpost tinyint(2) unsigned NOT NULL default '0',
      allowduplicatedentries tinyint(2) unsigned NOT NULL default '0',
-     displayformat tinyint(2) unsigned NOT NULL default '0',
+     displayformat varchar(50) NOT NULL default 'dictionary',
      mainglossary tinyint(2) unsigned NOT NULL default '0',
      showspecial tinyint(2) unsigned NOT NULL default '1',
      showalphabet tinyint(2) unsigned NOT NULL default '1',
@@ -104,20 +104,16 @@ CREATE TABLE prefix_glossary_comments (
      PRIMARY KEY  (id)
 ) TYPE=MyISAM COMMENT='comments on glossary entries';
 
-CREATE TABLE prefix_glossary_displayformats (
+CREATE TABLE prefix_glossary_formats (
      id int(10) unsigned NOT NULL auto_increment,
-     fid int(10) unsigned NOT NULL default '0',
+     name varchar(50) NOT NULL,
+     popupformatname varchar(50) NOT NULL,
      visible tinyint(2) unsigned NOT NULL default '1',
-
-     relatedview tinyint(3) NOT NULL default '-1',
      showgroup tinyint(2) unsigned NOT NULL default '1',
-
      defaultmode varchar(50) NOT NULL default '',
      defaulthook varchar(50) NOT NULL default '',
-        
      sortkey varchar(50) NOT NULL default '',
      sortorder varchar(50) NOT NULL default '',
-        
      PRIMARY KEY  (id)
 ) TYPE=MyISAM COMMENT='Setting of the display formats';
 
index afa4ba491b78058029eadb2c5cbc0ae239e35ffd..1c9e6f734091fd704bacedbbbdfe6db262792845 100644 (file)
@@ -37,7 +37,68 @@ function glossary_upgrade($oldversion) {
       table_column("glossary_alias", "alias", "alias", "VARCHAR", "255", "", "", "NOT NULL");
   }
 
-    return true;
+  if ( $oldversion < 2004072400) {
+
+      //Create new table glossary_formats to store format info
+      execute_sql("CREATE TABLE `{$CFG->prefix}glossary_formats` (
+                       `id` INT(10) unsigned NOT NULL auto_increment,
+                       `name` VARCHAR(50) NOT NULL,
+                       `popupformatname` VARCHAR(50) NOT NULL, 
+                       `visible` int2 UNSIGNED NOT NULL default '1',
+                       `showgroup int2 UNSIGNED NOT NULL default '1',
+                       `defaultmode` VARCHAR(50) NOT NULL default '',
+                       `defaulthook` VARCHAR(50) NOT NULL default '',
+                       `sortkey` VARCHAR(50) NOT NULL default '',
+                       `sortorder` VARCHAR(50) NOT NULL default '',
+                   PRIMARY KEY  (`id`)                    
+                   ) TYPE=MyISAM COMMENT='Setting of the display formats'");
+
+      //Define current 0-6 format names
+      $formatnames = array('dictionary','continuous','fullwithauthor','encyclopedia',
+                           'faq','fullwithoutauthor','entrylist');
+
+      //Fill the new table from the old one (only 'valid', 0-6, formats)
+      if ($formats = get_records('glossary_displayformats')) {
+          foreach ($formats as $format) {
+              //Format names
+              if ($format->fid >= 0 && $format->fid <= 6) {
+                  $format->name = $formatnames[$format->fid];
+              }
+
+              //Format popupformatname
+              $format->popupformatname = 'dictionary';  //Default format
+              if ($format->relatedview >= 0 && $format->relatedview <= 6) {
+                  $format->popupformatname = $formatnames[$format->relatedview];
+              }
+
+              //Insert the new record
+              //Only if $format->name is set (ie. formats 0-6)
+              if ($format->name) {
+                  insert_record('glossary_formats',$format);
+              }
+              
+          }
+      }
+
+      //Drop the old formats table
+      execute_sql("DROP TABLE `{$CFG->prefix}glossary_displayformats`");
+
+      //Modify the glossary->displayformat field
+      table_column('glossary', 'displayformat', 'displayformat', 'VARCHAR', '50', '', 'dictionary', 'NOT NULL');
+
+      //Update glossary->displayformat field
+      if ($glossaries = get_records('glossary')) {
+          foreach($glossaries as $glossary) {
+              $displayformat = 'dictionary';  //Default format
+              if ($glossary->displayformat >= 0 && $glossary->displayformat <= 6) {
+                  $displayformat = $formatnames[$glossary->displayformat];
+              }
+              set_field('glossary','displayformat',$displayformat,'id',$glossary->id);
+          }
+      }
+  }
+
+  return true;
 }
 
 ?>
index 8d7a61f08525741854c6b732eacca66804151e95..5d1f637e52ac46f15fdd36857d54181ad106d162 100644 (file)
@@ -15,7 +15,7 @@ CREATE TABLE prefix_glossary (
      intro text NOT NULL default '',
      studentcanpost int2 NOT NULL default '0',
      allowduplicatedentries int2 NOT NULL default '0',
-     displayformat int2 NOT NULL default '0',
+     displayformat varchar(50) NOT NULL default 'dictionary',
      mainglossary int2 NOT NULL default '0',
      showspecial int2 NOT NULL default '1',
      showalphabet int2 NOT NULL default '1',
@@ -108,29 +108,25 @@ CREATE TABLE prefix_glossary_comments (
 );
 
 #
-# Table structure for table `glossary_displayformats`
+# Table structure for table `glossary_formats`
 #
 
-CREATE TABLE prefix_glossary_displayformats (
+CREATE TABLE prefix_glossary_formats (
      id SERIAL,
-     fid int4 NOT NULL default '0',
+     name varchar(50) NOT NULL,
+     popupformatname varchar(50) NOT NULL,
      visible int2 NOT NULL default '1',
-
-     relatedview int4 NOT NULL default '-1',
      showgroup int2 NOT NULL default '1',
-
      defaultmode varchar(50) NOT NULL default '',
      defaulthook varchar(50) NOT NULL default '',
-        
      sortkey varchar(50) NOT NULL default '',
      sortorder varchar(50) NOT NULL default '',
-        
      PRIMARY KEY  (id)
 );
 
 
 #
-# Table structure for table `forum_ratings`
+# Table structure for table `glossary_ratings`
 #
 
 CREATE TABLE prefix_glossary_ratings (
index 5982c0a0a34cec7435f8c914d0d59306f946660d..0c4e7ab39479685a0ac709f127320627e6046979 100644 (file)
         error("Site isn't defined!");
     }
     
-    if ( !$displayformat = get_record("glossary_displayformats","fid",$id) ) {
-        unset($displayformat);
-        $displayformat->fid = $id;
-        $displayformat->id = insert_record("glossary_displayformats",$displayformat);
+    if ( !$displayformat = get_record("glossary_formats","id",$id) ) {
+        error ("Invalid Glossary Format");
     }
 
     $form = data_submitted();
             } else {
                 $displayformat->visible = 1;
             }
-            update_record("glossary_displayformats",$displayformat);
+            update_record("glossary_formats",$displayformat);
         }
-        redirect($_SERVER["HTTP_REFERER"]);
+        redirect("../../admin/module.php?module=glossary#formats");
         die;
     } elseif ( $mode == 'edit' and $form) {
         
-        $displayformat->relatedview = $form->relatedview;
+        $displayformat->popupformatname = $form->popupformatname;
         $displayformat->showgroup   = $form->showgroup;
         $displayformat->defaultmode = $form->defaultmode;
         $displayformat->defaulthook = $form->defaulthook;
         $displayformat->sortkey     = $form->sortkey;
         $displayformat->sortorder   = $form->sortorder;
         
-        update_record("glossary_displayformats",$displayformat);
+        update_record("glossary_formats",$displayformat);
         redirect("../../admin/module.php?module=glossary#formats");
         die;
     }
     ?>
        <tr>
            <td colspan=3 align=center><strong>
-               <?php 
-        switch ( $id ) {
-        case 0: 
-            echo get_string('displayformatdefault',"glossary");
-        break;
-        
-        case 1: 
-            echo get_string('displayformatcontinuous',"glossary");
-        break;
-        default:
-            echo get_string('displayformat'.$id,"glossary");
-        break;
-        }
-        ?>
+               <?php echo get_string('displayformat'.$displayformat->name,"glossary"); ?>
         </strong></td>
        </tr>
     <tr valign=top>
-        <td align="right" width="20%">    
-                       <p>Related Display Format:</td>
+        <td align="right" width="20%"><?PHP print_string('popupformat','glossary'); ?></td>
         <td>
-        <SELECT size=1 name=relatedview>
-        <OPTION value=0 <?php if ( $displayformat->relatedview == 0 ) {
-                                  echo " SELECTED ";
-                              }
-                        ?>><?php p(get_string("displayformatdefault","glossary"))?></OPTION>
-        <OPTION value=1 <?php if ( $displayformat->relatedview == 1 ) {
-                                  echo " SELECTED ";
-                              }
-                        ?>><?php p(get_string("displayformatcontinuous","glossary"))?></OPTION>
      <?PHP
-        $i = 2;        
-        $dpname = get_string("displayformat".$i,"glossary");
-        $file = "$CFG->dirroot/mod/glossary/formats/$i.php";        
-        while ( file_exists($file) ) {
-            echo '<OPTION value="' . $i . '"';
-            if ( $displayformat->relatedview == $i ) {
-                echo " SELECTED ";
-            }
-            echo '> ' . get_string("displayformat".$i,"glossary") . '</OPTION>';
-            $i++;
-            $file = "$CFG->dirroot/mod/glossary/formats/$i.php";
+        //get and update available formats
+        $recformats = glossary_get_available_formats();
+
+        $formats = array();
+    
+        //Take names
+        foreach ($recformats as $format) {
+           $formats[$format->name] = get_string("displayformat$format->name", "glossary");
         }
+        //Sort it
+        asort($formats);
+        
+        choose_from_menu($formats,'popupformatname',$displayformat->popupformatname);
      ?>
-        </SELECT>
         </td>
         <td width="60%">
         <?php print_string("cnfrelatedview", "glossary") ?><br /><br />
         </td>
     </tr>
     <tr valign=top>
-        <td align="right" width="20%"><p>Default Mode:</td>
+        <td align="right" width="20%"><?PHP print_string('defaultmode','glossary'); ?></td>
         <td>
         <SELECT size=1 name=defaultmode>
     <?php 
         </td>
     </tr>
     <tr valign=top>
-        <td align="right" width="20%"><p>Default Hook:</td>
+        <td align="right" width="20%"><?PHP print_string('defaulthook','glossary'); ?></td>
         <td>
         <SELECT size=1 name=defaulthook>
     <?php 
         </td>
     </tr>
     <tr valign=top>
-        <td align="right" width="20%"><p>Default Sort Key:</td>
+        <td align="right" width="20%"><?PHP print_string('defaultsortkey','glossary'); ?></td>
         <td>
         <SELECT size=1 name=sortkey>
     <?php 
         </td>
     </tr>
     <tr valign=top>
-        <td align="right" width="20%"><p>Default Sort Order:</td>
+        <td align="right" width="20%"><?PHP print_string('defaultsortorder','glossary'); ?></td>
         <td>
         <SELECT size=1 name=sortorder>
     <?php 
         <td align="right" width="20%"><p>Include Group Breaks:</td>
         <td>
         <SELECT size=1 name=showgroup>
-    <?php 
+    <?php
         $yselected = "";
         $nselected = "";
         if ($displayformat->showgroup) {
diff --git a/mod/glossary/formats/continuous/continuous_format.php b/mod/glossary/formats/continuous/continuous_format.php
new file mode 100644 (file)
index 0000000..e3b75f4
--- /dev/null
@@ -0,0 +1,34 @@
+<?PHP  // $Id$
+
+function glossary_show_entry_continuous($course, $cm, $glossary, $entry, $mode="",$hook="",$printicons=1,$ratings=NULL) {
+
+    global $THEME, $USER;
+
+    $return = false;
+    if ($entry) {
+        glossary_print_entry_approval($cm, $entry, $mode);
+        glossary_print_entry_attachment($entry,"html","right");
+        glossary_print_entry_concept($entry);
+        echo ": ";
+
+        glossary_print_entry_definition($entry);
+
+        $icons = '';
+        if ( $printicons ) {
+            $icons = glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode, $hook,"html");
+        }
+
+        echo '(';
+        if ( $icons ) {
+            echo $icons;
+        }
+        $return = glossary_print_entry_ratings($course, $entry, $ratings);
+
+        echo ')<br>';
+
+    }
+    return $return;
+
+}
+
+?>
diff --git a/mod/glossary/formats/dictionary/dictionary_format.php b/mod/glossary/formats/dictionary/dictionary_format.php
new file mode 100644 (file)
index 0000000..781c13c
--- /dev/null
@@ -0,0 +1,26 @@
+<?PHP  // $Id$
+
+function glossary_show_entry_dictionary($course, $cm, $glossary, $entry, $mode="",$hook="",$printicons=1,$ratings=NULL) {
+
+    global $THEME, $CFG, $USER;
+
+    $colour = $THEME->cellheading2;
+
+    echo "\n<table border=0 width=95% cellspacing=0 valign=top cellpadding=3 class=forumpost align=center>\n";
+    echo "<tr>\n";
+    echo "<td width=\"100%\" valign=\"top\" bgcolor=\"#FFFFFF\">\n";
+    glossary_print_entry_approval($cm, $entry, $mode);
+    glossary_print_entry_attachment($entry,"html","right");
+    echo "<b>";
+    glossary_print_entry_concept($entry);
+    echo ":</b> ";
+    glossary_print_entry_definition($entry);
+    $return = glossary_print_entry_lower_section($course, $cm, $glossary, $entry,$mode,$hook,$printicons,$ratings);
+    echo "</td>\n";
+    echo "</tr>\n";
+    echo "</table>\n";
+
+    return $return;
+}
+
+?>
diff --git a/mod/glossary/formats/encyclopedia/encyclopedia_format.php b/mod/glossary/formats/encyclopedia/encyclopedia_format.php
new file mode 100644 (file)
index 0000000..035bc6e
--- /dev/null
@@ -0,0 +1,60 @@
+<?PHP  // $Id$
+
+function glossary_show_entry_encyclopedia($course, $cm, $glossary, $entry, $mode="",$hook="",$printicons=1,$ratings=NULL) {
+    global $THEME, $CFG, $USER;
+
+    $colour = $THEME->cellheading2;
+
+    $user = get_record("user", "id", $entry->userid);
+    $strby = get_string("writtenby", "glossary");
+
+    echo "\n<br /><table border=0 width=95% cellspacing=0 valign=top cellpadding=3 class=forumpost align=center>";
+
+    echo "\n<tr>";
+    echo "\n<td bgcolor=\"$colour\" width=35 valign=top class=\"forumpostpicture\">";
+    $return = false;
+    if ($entry) {
+        print_user_picture($user->id, $course->id, $user->picture);
+        echo "</td>";
+        echo "<td align=\"top\" width=100% bgcolor=\"$THEME->cellheading\" class=\"forumpostheader\">";
+        glossary_print_entry_approval($cm, $entry, $mode);
+        echo "<b>";
+        glossary_print_entry_concept($entry);
+               echo "</b><br />";
+        echo "<font size=\"2\">$strby " . fullname($user, isteacher($course->id)) . "</font>";
+        echo "&nbsp;&nbsp;<font size=1>(".get_string("lastedited").": ".
+             userdate($entry->timemodified).")</font>";
+        echo "</tr>";
+
+        echo "\n<tr>";
+        echo "\n<td bgcolor=\"$colour\" width=35 valign=top class=\"forumpostside\">&nbsp;</td>";
+        echo "\n<td width=100% align=\"top\" bgcolor=\"$THEME->cellcontent\" class=\"forumpostmessage\">";
+
+        if ($entry->attachment) {
+            $entry->course = $course->id;
+            if (strlen($entry->definition)%2) {
+                $align = "right";
+            } else {
+                $align = "left";
+            }
+            glossary_print_entry_attachment($entry,"",$align);
+        }
+        glossary_print_entry_definition($entry);
+
+        glossary_print_entry_lower_section($course, $cm, $glossary, $entry,$mode,$hook,$printicons);
+        echo ' ';
+        $return = glossary_print_entry_ratings($course, $entry, $ratings);
+
+    } else {
+        echo "<center>";
+        print_string("noentry", "glossary");
+        echo "</center>";
+    }
+    echo "</td></tr>";
+
+    echo "</table>\n";
+    
+    return $return;
+}
+
+?>
diff --git a/mod/glossary/formats/entrylist/entrylist_format.php b/mod/glossary/formats/entrylist/entrylist_format.php
new file mode 100644 (file)
index 0000000..729efe4
--- /dev/null
@@ -0,0 +1,34 @@
+<?PHP  // $Id$
+
+function glossary_show_entry_entrylist($course, $cm, $glossary, $entry, $mode="",$hook="",$printicons=1,$ratings=NULL) {
+    global $THEME, $USER;
+
+    $colour = "#FFFFFF";
+    $return = false;
+
+    echo "\n<table border=0 cellspacing=0 width=95% valign=top cellpadding=10>";
+
+    echo "\n<tr>";
+    echo "<td width=100% bgcolor=\"$colour\">";
+    if ($entry) {
+        echo "<b><a href=\"showentry.php?courseid=$course->id\&eid=$entry->id\&displayformat=dictionary\" target=\"_blank\" onClick=\"return openpopup('/mod/glossary/showentry.php?courseid=$course->id\&eid=$entry->id\&displayformat=dictionary', 'entry', 'menubar=0,location=0,scrollbars,resizable,width=600,height=450', 0);\">";
+
+        glossary_print_entry_concept($entry);
+        echo '</a></b> ';
+        if ( $return = glossary_print_entry_commentslink($course, $cm, $glossary, $entry,$mode,$hook, 'html') ) {
+            echo "<font size=-1>($return)</font>";
+        }
+
+        echo '<br />';
+    } else {
+        echo "<center>";
+        print_string("noentry", "glossary");
+        echo "</center>";
+    }
+    echo "</td></tr>";
+
+    echo "</table>\n";
+    return $return;
+}
+
+?>
diff --git a/mod/glossary/formats/faq/faq_format.php b/mod/glossary/formats/faq/faq_format.php
new file mode 100644 (file)
index 0000000..ee2c52b
--- /dev/null
@@ -0,0 +1,38 @@
+<?PHP  // $Id$
+
+function glossary_show_entry_faq($course, $cm, $glossary, $entry, $mode="",$hook="",$printicons=1,$ratings=NULL) {
+    global $THEME, $USER;
+    $return = false;
+    if ( $entry ) {
+        $colour = $THEME->cellheading2;
+
+        echo '<br /><table border=0 cellspacing=0 width=95% valign=top cellpadding=10 class=forumpost>';
+
+        echo '<tr>';
+        echo "<td width=100% bgcolor=\"$colour\">";
+        $entry->course = $course->id;
+        glossary_print_entry_approval($cm, $entry, $mode);
+        glossary_print_entry_attachment($entry,"html","right");
+
+        echo '<b>' . get_string("question","glossary") . ':</b> ';
+        glossary_print_entry_concept($entry) . '<br>';
+        echo '&nbsp;&nbsp;<font size=1>' . get_string("lastedited").': '.userdate($entry->timemodified) . '</font></tr>';
+        echo "<tr><td width=100% bgcolor=\"$THEME->cellcontent\">";            
+        echo '<b>' . get_string("answer","glossary") . ':</b> ';
+        glossary_print_entry_definition($entry);
+
+
+        glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook,$printicons);
+        echo ' ';
+        $return = glossary_print_entry_ratings($course, $entry, $ratings);
+        echo '</td></tr></table>';
+
+    } else {
+        echo '<center>';
+        print_string("noentry", "glossary");
+        echo '</center>';
+    }
+    return $return;
+}
+
+?>
diff --git a/mod/glossary/formats/fullwithauthor/fullwithauthor_format.php b/mod/glossary/formats/fullwithauthor/fullwithauthor_format.php
new file mode 100644 (file)
index 0000000..a1cfc48
--- /dev/null
@@ -0,0 +1,54 @@
+<?PHP  // $Id$
+
+function glossary_show_entry_fullwithauthor($course, $cm, $glossary, $entry, $mode="",$hook="",$printicons=1,$ratings=NULL) {
+    global $THEME, $CFG, $USER;
+
+    $colour = $THEME->cellheading2;
+
+    $user = get_record("user", "id", $entry->userid);
+    $strby = get_string("writtenby", "glossary");
+
+    echo "\n<br /><table border=0 width=95% cellspacing=0 valign=top cellpadding=3 class=forumpost align=center>";
+
+    echo "\n<tr>";
+    echo "\n<td bgcolor=\"$colour\" width=35 valign=top class=\"forumpostpicture\">";
+    $return = false;
+    if ($entry) {
+        print_user_picture($user->id, $course->id, $user->picture);
+
+        echo "</td>";
+        echo "<td valign=\"top\" width=100% bgcolor=\"$THEME->cellheading\" class=\"forumpostheader\">";
+
+        glossary_print_entry_approval($cm, $entry, $mode);
+        glossary_print_entry_attachment($entry,"html","right");
+
+        echo "<b>";
+        glossary_print_entry_concept($entry);
+               echo "</b><br />";
+
+        echo "<font size=\"2\">$strby " . fullname($user, isteacher($course->id)) . "</font>";
+        echo "&nbsp;&nbsp;<font size=1>(".get_string("lastedited").": ".
+             userdate($entry->timemodified).")</font>";
+        echo "</tr>";
+
+        echo "\n<tr>";
+        echo "\n<td bgcolor=\"$colour\" width=35 valign=top class=\"forumpostside\">&nbsp;</td>";
+        echo "\n<td width=100% bgcolor=\"$THEME->cellcontent\" class=\"forumpostmessage\">";
+
+        glossary_print_entry_definition($entry);
+        glossary_print_entry_lower_section($course, $cm, $glossary, $entry,$mode,$hook,$printicons);
+        echo ' ';
+        $return = glossary_print_entry_ratings($course, $entry, $ratings);
+
+    } else {
+        echo "<center>";
+        print_string("noentry", "glossary");
+        echo "</center>";
+    }
+    echo "</td></tr>";
+
+    echo "</table>\n";
+    return $return;
+}
+
+?>
diff --git a/mod/glossary/formats/fullwithoutauthor/fullwithoutauthor_format.php b/mod/glossary/formats/fullwithoutauthor/fullwithoutauthor_format.php
new file mode 100644 (file)
index 0000000..903f4f0
--- /dev/null
@@ -0,0 +1,38 @@
+<?PHP  // $Id$
+
+function glossary_show_entry_fullwithoutauthor($course, $cm, $glossary, $entry, $mode="",$hook="",$printicons=1,$ratings=NULL) {
+    global $THEME, $USER;
+
+    $colour = $THEME->cellheading2;
+    $return = false;
+
+    echo "\n<br /><table border=0 width=95% cellspacing=0 valign=top cellpadding=3 class=forumpost align=center>";
+
+    echo "\n<tr>";
+    echo "<td width=100% bgcolor=\"$THEME->cellheading\">";
+    glossary_print_entry_approval($cm, $entry, $mode);
+    if ($entry) {
+        glossary_print_entry_attachment($entry,"html","right");
+        echo "<b>";
+        glossary_print_entry_concept($entry);
+        echo "</b><br />";
+        echo "<font size=1>".get_string("lastedited").": ".userdate($entry->timemodified)."</font>";
+        echo "</tr>";
+        echo "\n<tr><td width=100% bgcolor=\"$THEME->cellcontent\">";
+               
+        glossary_print_entry_definition($entry);
+        glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook,$printicons);
+        echo ' ';
+        $return = glossary_print_entry_ratings($course, $entry, $ratings);
+    } else {
+        echo "<center>";
+        print_string("noentry", "glossary");
+        echo "</center>";
+    }
+    echo "</td></tr>";
+
+    echo "</table>\n";
+    return $return;
+}
+
+?>
index a9e9f2997222958f4411f7b990bc3746716f6560..e7033e1d5ca0f41965b666c3fafdd8905286447b 100644 (file)
@@ -18,9 +18,6 @@ define("GLOSSARY_IMPORT_VIEW", 5);
 define("GLOSSARY_EXPORT_VIEW", 6);
 define("GLOSSARY_APPROVAL_VIEW", 7);
 
-define("GLOSSARY_FORMAT_SIMPLE", 0);
-define("GLOSSARY_FORMAT_CONTINUOUS", 1);
-
 function glossary_add_instance($glossary) {
 /// Given an object containing all the necessary data,
 /// (defined by the form in mod.html) this function
@@ -184,23 +181,13 @@ function glossary_user_complete($course, $user, $mod, $glossary) {
     global $CFG;
 
     if ($entries = glossary_get_user_entries($glossary->id, $user->id)) {
-        if ( $glossary->displayformat == GLOSSARY_FORMAT_SIMPLE or
-             $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
-            print_simple_box_start("center","70%");
-        } else {
-            echo '<table width="95%" border="0"><tr><td>';
-        }
+        echo '<table width="95%" border="0"><tr><td>';
         foreach ($entries as $entry) {
             $cm = get_coursemodule_from_instance("glossary", $glossary->id, $course->id);
             glossary_print_entry($course, $cm, $glossary, $entry,"","",0);
             echo '<p>';
         }
-        if ( $glossary->displayformat == GLOSSARY_FORMAT_SIMPLE or
-             $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
-            print_simple_box_end();
-        } else {
-            echo '</td></tr></table>';
-        }
+        echo '</td></tr></table>';
     }
 }
 
@@ -219,6 +206,8 @@ function glossary_print_recent_activity($course, $isteacher, $timestart) {
         return false;
     }
 
+    $entries = array();
+
     foreach ($logs as $log) {
         //Create a temp valid module structure (course,id)
         $tempmod->course = $log->course;        
@@ -383,6 +372,67 @@ function glossary_scale_used ($glossaryid,$scaleid) {
 /// Any other glossary functions go here.  Each of them must have a name that
 /// starts with glossary_
 
+//This function return an array of valid glossary_formats records
+//Everytime it's called, every existing format is checked, new formats
+//are included if detected and old formats are deleted and any glossary
+//using an invalid format is updated to the default (dictionary).
+function glossary_get_available_formats() {
+
+    global $CFG;
+
+    //Get available formats (plugin) and insert (if necessary) them into glossary_formats
+    $formats = get_list_of_plugins('mod/glossary/formats');
+    foreach ($formats as $format) {
+        //If the format file exists
+        if (file_exists($CFG->dirroot.'/mod/glossary/formats/'.$format.'/'.$format.'_format.php')) {
+            include_once($CFG->dirroot.'/mod/glossary/formats/'.$format.'/'.$format.'_format.php');
+            //If the function exists
+            if (function_exists('glossary_show_entry_'.$format)) {
+                //If the format doesn't exist in the table
+                if (!$rec = get_record('glossary_formats','name',$format)) {
+                    //Insert the record in glossary_formats
+                    $gf->name = $format;
+                    $gf->popupformatname = $format;
+                    $gf->visible = 1;
+                    insert_record("glossary_formats",$gf);
+                }
+            }
+        }
+    }
+
+    //Delete non_existent formats from glossary_formats table
+    $formats = get_records("glossary_formats");
+    foreach ($formats as $format) {
+        $todelete = false;
+        //If the format file doesn't exists delete the record
+        if (!file_exists($CFG->dirroot.'/mod/glossary/formats/'.$format->name.'/'.$format->name.'_format.php')) {
+            $todelete = true;
+        } else {
+            include_once($CFG->dirroot.'/mod/glossary/formats/'.$format->name.'/'.$format->name.'_format.php');
+            //If the glossary_show_entry_XXXX doesn't exists delete the record
+            if (!function_exists('glossary_show_entry_'.$format->name)) {
+                $todelete = true;
+            }
+        }
+
+        if ($todelete) {
+            //Delete the format
+            delete_records('glossary_formats','name',$format->name);
+            //Reasign existing glossaries to default (dictionary) format
+            if ($glossaries = get_records('glossary','displayformat',$format->name)) {
+                foreach($glossaries as $glossary) {
+                    set_field('glossary','displayformat','dictionary','id',$glossary->id);
+                }
+            }
+        }
+    }
+
+    //Now everything is ready in glossary_formats table
+    $formats = get_records("glossary_formats");
+
+    return $formats;
+}
+
 function glossary_debug($debug,$text,$br=1) {
     if ( $debug ) {
         echo '<font color=red>' . $text . '</font>';
@@ -443,38 +493,19 @@ function glossary_print_entry($course, $cm, $glossary, $entry, $mode="",$hook=""
         $displayformat = $glossary->displayformat;
     }
     if ($entry->approved or ($USER->id == $entry->userid) or ($mode == 'approval' and !$entry->approved) ) {
-        $permissiongranted = 0;
-        $formatfile = "$CFG->dirroot/mod/glossary/formats/$displayformat.php";
-        $functionname = "glossary_print_entry_by_format";
-
-        $basicformat = ($displayformat == GLOSSARY_FORMAT_SIMPLE or
-                        $displayformat == GLOSSARY_FORMAT_CONTINUOUS);
-        if ( !$basicformat ) {
-            if ( file_exists($formatfile) ) {
-               include_once($formatfile);
-               if (function_exists($functionname) ) {
-                      $permissiongranted = 1;
-               }
-            }
-        } else {
-           $permissiongranted = 1;
-        }
-    
-        if ( !$basicformat and $permissiongranted or $displayformat >= 2) {
-            $return = glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode,$hook,$printicons,$ratings);
-        } else {
-            switch ( $displayformat ) {
-            case GLOSSARY_FORMAT_SIMPLE:
-                $return = glossary_print_entry_by_default($course, $cm, $glossary, $entry,$mode,$hook,$printicons,$ratings);
-            break;
-            case GLOSSARY_FORMAT_CONTINUOUS:
-                $return = glossary_print_entry_continuous($course, $cm, $glossary, $entry,$mode,$hook,$printicons,$ratings);
-            break;
+        $formatfile = $CFG->dirroot.'/mod/glossary/formats/'.$displayformat.'/'.$displayformat.'_format.php';
+        $functionname = 'glossary_show_entry_'.$displayformat;
+
+        if (file_exists($formatfile)) {
+            include_once($formatfile);
+            if (function_exists($functionname)) {
+                $return = $functionname($course, $cm, $glossary, $entry,$mode,$hook,$printicons,$ratings);
             }
         }
     }
-        return $return;
+    return $return;
 }
+
 function  glossary_print_entry_concept($entry) {
     $options->para = false;
     $text = format_text('<nolink>' . $entry->concept . '</nolink>', FORMAT_MOODLE, $options);
@@ -635,23 +666,30 @@ function glossary_print_entry_commentslink($course, $cm, $glossary, $entry,$mode
     }
 }
 
-function  glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook,$printicons) {
+function  glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook,$printicons,$ratings) {
 
     $aliases = glossary_print_entry_aliases($course, $cm, $glossary, $entry, $mode, $hook,"html");
     $icons   = "";
     if ( $printicons ) {
         $icons   = glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode, $hook,"html");
     }
-    if ( $aliases ) {
-        echo '<table border="0" width="100%" align="center"><tr>' .
-              '<td align="right" width="50%" valign=top><font size=1>' .
-              get_string("aliases","glossary") . ': ' . $aliases . '</td>' .
-              '<td align=right width="50%" valign=top>'.
-              $icons .
-              '</td></tr></table>';
-    } else {
-        echo "<p align=right>$icons";
+    if ($aliases || $printicons || $ratings) {
+        echo '<table border="0" width="100%" align="center">';
+        if ( $aliases ) {
+            echo '<tr><td align="center"  valign="top"><font size=1>' .
+                  get_string("aliases","glossary") . ': ' . $aliases . '</td></tr>';
+        }
+        if ($icons) {
+            echo '<tr><td align=right valign=top>'.  $icons . '</td></tr>';
+        }
+        if ($ratings) {
+            echo '<tr><td align=right valign=top>';
+            $return = glossary_print_entry_ratings($course, $entry, $ratings);
+            echo '</td></tr>';
+        }
+        echo '</table>';
     }
+    return $return;
 }
 
 function glossary_print_entry_attachment($entry,$format=NULL,$align="right") {
@@ -661,67 +699,20 @@ function glossary_print_entry_attachment($entry,$format=NULL,$align="right") {
     if ($entry->attachment) {
           $glossary = get_record("glossary","id",$entry->glossaryid);            
           $entry->course = $glossary->course; //used inside print_attachment
-          echo "<table border=0 align=$align><tr><td>";
+          echo "<table border=0 width=\"100%\"><tr><td align=\"$align\">\n";
           echo glossary_print_attachments($entry,$format,$align);
-          echo "</td></tr></table>";
+          echo "</td></tr></table>\n";
     }
 }
 
-function  glossary_print_entry_approval($cm, $entry, $mode) {
+function  glossary_print_entry_approval($cm, $entry, $mode,$align="right") {
     if ( $mode == 'approval' and !$entry->approved ) {
+        echo "<table border=0 width=\"100%\"><tr><td align=\"$align\">\n";
         echo "<a title=\"" . get_string("approve","glossary"). "\" href=\"approve.php?id=$cm->id&eid=$entry->id&mode=$mode\"><IMG align=\"right\" src=\"check.gif\" border=0 width=\"34\" height=\"34\"></a>";
+        echo "</td></tr></table>\n";
     }
 }
 
-function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$mode="",$hook="",$printicons=1, $ratings=NULL) {
-    global $THEME, $USER;
-
-    $colour = $THEME->cellheading2;
-
-    echo "\n<TR>";
-    echo "<TD WIDTH=100% valign=\"top\" BGCOLOR=\"#FFFFFF\">";
-        glossary_print_entry_approval($cm, $entry, $mode);
-        glossary_print_entry_attachment($entry,"html","right");
-        echo "<b>";
-        glossary_print_entry_concept($entry);
-        echo ":</b> ";
-        glossary_print_entry_definition($entry);
-        glossary_print_entry_lower_section($course, $cm, $glossary, $entry,$mode,$hook,$printicons);
-        echo ' ';
-        $return = glossary_print_entry_ratings($course, $entry, $ratings);
-    echo "</td>";
-    echo "</TR>";
-    return $return;
-}
-
-function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$mode="",$hook="",$printicons=1, $ratings = NULL) {
-    global $THEME, $USER;
-    $return = false;
-    if ($entry) {
-        glossary_print_entry_approval($cm, $entry, $mode);
-        glossary_print_entry_attachment($entry,"html","right");
-        glossary_print_entry_concept($entry);
-        echo " ";
-        
-        glossary_print_entry_definition($entry);
-        
-        $icons = '';
-        if ( $printicons ) {
-            $icons = glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode, $hook,"html");        
-        }        
-
-        echo '(';
-        if ( $icons ) {
-            echo $icons;
-        }
-        $return = glossary_print_entry_ratings($course, $entry, $ratings);
-        
-        echo ')<br>';
-
-    }
-    return $return;
-}
-
 function glossary_search($course, $searchterms, $extended = 0, $glossary = NULL) {
 // It returns all entries from all glossaries that matches the specified criteria 
 //    within a given $course. It performs an $extended search if necessary.
@@ -1187,7 +1178,7 @@ function glossary_print_tabbed_table_end() {
 }
 
 function glossary_print_approval_menu($cm, $glossary,$mode, $hook, $sortkey = '', $sortorder = '') {
-    if ($glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
+    if ($glossary->showalphabet) {
         echo '<center>' . get_string("explainalphabet","glossary") . '<p>';
     }
     glossary_print_special_links($cm, $glossary, $mode, $hook);
@@ -1213,7 +1204,7 @@ function glossary_print_export_menu($cm, $glossary, $mode, $hook, $sortkey='', $
 
 function glossary_print_alphabet_menu($cm, $glossary, $mode, $hook, $sortkey='', $sortorder = '') {
     if ( $mode != 'date' ) {
-        if ($glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
+        if ($glossary->showalphabet) {
             echo '<center>' . get_string("explainalphabet","glossary") . '<p>';
         }
 
@@ -1228,7 +1219,7 @@ function glossary_print_alphabet_menu($cm, $glossary, $mode, $hook, $sortkey='',
 }
 
 function glossary_print_author_menu($cm, $glossary,$mode, $hook, $sortkey = '', $sortorder = '') {
-    if ($glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
+    if ($glossary->showalphabet) {
         echo '<center>' . get_string("explainalphabet","glossary") . '<br />';
     }
 
@@ -1304,7 +1295,7 @@ global $CFG, $THEME;
 
 function glossary_print_all_links($cm, $glossary, $mode, $hook) {
 global $CFG;  
-     if ( $glossary->showall and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS) {
+     if ( $glossary->showall) {
          $strallentries       = get_string("allentries", "glossary");
          if ( $hook == 'ALL' ) {
               echo "<b>$strallentries</b>";
@@ -1317,7 +1308,7 @@ global $CFG;
 
 function glossary_print_special_links($cm, $glossary, $mode, $hook) {
 global $CFG;
-     if ( $glossary->showspecial and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS ) {
+     if ( $glossary->showspecial) {
          $strspecial          = get_string("special", "glossary");
          if ( $hook == 'SPECIAL' ) {
               echo "<b>$strspecial</b> | ";
@@ -1330,7 +1321,7 @@ global $CFG;
 
 function glossary_print_alphabet_links($cm, $glossary, $mode, $hook, $sortkey, $sortorder) {
 global $CFG;
-     if ( $glossary->showalphabet and $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS ) {
+     if ( $glossary->showalphabet) {
           $alphabet = explode(",", get_string("alphabet"));
           $letters_by_line = 14;
           for ($i = 0; $i < count($alphabet); $i++) {
@@ -1484,7 +1475,9 @@ function glossary_print_comment($course, $cm, $glossary, $entry, $comment) {
 }
 
 function  glossary_print_entry_ratings($course, $entry, $ratings = NULL) {
-global $USER;
+    
+    global $USER;
+
     $ratingsmenuused = false;
     if (!empty($ratings) and !empty($USER->id)) {
         $useratings = true;
@@ -1512,7 +1505,7 @@ global $USER;
 }
 
 function glossary_print_dynaentry($courseid, $entries, $displayformat = -1) {
-    global $THEME, $USER;
+    global $THEME, $USER,$CFG;
 
     $colour = $THEME->cellheading2;
 
@@ -1531,20 +1524,30 @@ function glossary_print_dynaentry($courseid, $entries, $displayformat = -1) {
             }
 
             //If displayformat is present, override glossary->displayformat
-            if ($displayformat == -1) {
+            if ($displayformat < 0) {
                 $dp = $glossary->displayformat;
-            } else { 
+            } else {
                 $dp = $displayformat;
             }
 
-            // Hard-coded until the Display formats manager is done.
-            if ( $dprecord = get_record("glossary_displayformats","fid", $dp) ) {
-                if ( $dprecord->relatedview >= 0 ) {
-                    $dp = $dprecord->relatedview;
-                }
+            //Get popupformatname
+            $format = get_record('glossary_formats','name',$dp);
+            $displayformat = $format->popupformatname;
+
+            //Check displayformat variable and set to default if necessary
+            if (!$displayformat) {
+                $displayformat = 'dictionary';
             }
 
-            glossary_print_entry($course, $cm, $glossary, $entry, "","",0,$dp);
+            $formatfile = $CFG->dirroot.'/mod/glossary/formats/'.$displayformat.'/'.$displayformat.'_format.php';
+            $functionname = 'glossary_show_entry_'.$displayformat;
+
+            if (file_exists($formatfile)) {
+                include_once($formatfile);
+                if (function_exists($functionname)) {
+                    $functionname($course, $cm, $glossary, $entry,'','','','');
+                }
+            }
         }
     }
     echo "</td>";
index c7c38a46493662c826f6eb47ff0396dba3eec146..6d91e1bd06839ebf3e25e6f7119c11b63b7fc1e6 100644 (file)
@@ -1,5 +1,7 @@
 <?PHP  // $Id$
 
+include_once($CFG->dirroot.'/mod/glossary/lib.php');
+
 if (!isset($form->studentcanpost)) {
     $form->studentcanpost = $CFG->glossary_studentspost;
 }
@@ -22,7 +24,7 @@ if (!isset($form->mainglossary)) {
     $form->mainglossary = 0;
 }
 if (!isset($form->displayformat)) {
-    $form->displayformat = 0;
+    $form->displayformat = 'dictionary';
 }
 if ( !isset($form->globalglossary) ) {
     $form->globalglossary = 0;
@@ -236,35 +238,21 @@ if (!$mainglossary or $mainglossary->id == $form->instance ) {
     <TD align=right><P><B><?php echo get_string("displayformat", "glossary") ?>:</B></P></TD>
     <TD>
     <?php
-    $formats = array();
-    $formats[0] = get_string("displayformatdefault", "glossary");
-    $formats[1] = get_string("displayformatcontinuous", "glossary");
-
-    $basedir = opendir("$CFG->dirroot/mod/glossary/formats");
-    while ($dir = readdir($basedir)) {
-        $firstchar = substr($dir, 0, 1);
-        if ($firstchar == "." or $dir == "CVS" or $dir == "_vti_cnf") {
-            continue;
-        }
-        if (filetype("$CFG->dirroot/mod/glossary/formats/$dir") == "dir") {
-            continue;
-        }
-        if ( $pos = strpos($dir, ".") ) {
-            $dir = substr($dir, 0, $pos );
-            if ($dir != 0 and $dir != 1) {  // excluding basic formats
-                $dp = get_record("glossary_displayformats","fid",$dir);
-                if ( !$dp or $dp->visible ) {
-                    $formats[$dir] = get_string("displayformat$dir", "glossary");
-                }
-            }
-        }
-    }
-    asort($formats);
-    choose_from_menu ($formats, "displayformat", $form->displayformat, "");
-
-?>
-
-    </select> <?php helpbutton("displayformat", get_string("displayformat", "glossary"), "glossary") ?>
+        //get and update available formats
+        $recformats = glossary_get_available_formats();
+    
+        $formats = array(); 
+        
+        //Take names
+        foreach ($recformats as $format) {
+           $formats[$format->name] = get_string("displayformat$format->name", "glossary");
+        }       
+        //Sort it
+        asort($formats);
+        
+        choose_from_menu($formats,'displayformat',$form->displayformat,'');
+    ?>
+    <?php helpbutton("displayformat", get_string("displayformat", "glossary"), "glossary") ?>
     </TD>
 </TR>
 <TR valign=top>
@@ -326,7 +314,8 @@ if (!$mainglossary or $mainglossary->id == $form->instance ) {
 </TR>
 <?php
     //Only show rss parameters if rss is activated at site and glossary levels
-    if ($CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds) {
+    if (isset($CFG->enablerssfeeds) && isset($CFG->glossary_enablerssfeeds) &&
+        $CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds) {
         echo "<tr valign=top>";
         echo "<td align=right><p><b>".get_string("rsstype").":</b></p></td>";
         echo "<td>";
index 6d50702d299361f8b9fa141eaf4885867553f74e..b89165bc2f2f8da6d7b718e33743fcddb89120bd 100644 (file)
@@ -1,5 +1,7 @@
 <?php   // $Id$
 
+    global $CFG;
+
     require_once("../../config.php");
     require_once("lib.php");
     
@@ -9,8 +11,8 @@
     optional_variable($sortkey,"UPDATE");          // Sorting key 
     optional_variable($sortorder,"asc");           // Sorting order 
     optional_variable($offset);                    // number of entries to bypass
+    optional_variable($displayformat,-1); 
 
-    print_header();
 
     if (! $cm = get_record("course_modules", "id", $id)) {
         error("Course Module ID was incorrect");
         error("Course module is incorrect");
     } 
     
-    global $CFG;
     if ( !$entriesbypage = $glossary->entbypage ) {
         $entriesbypage = $CFG->glossary_entbypage;
     }
 
+    print_header(strip_tags("$course->shortname: $glossary->name"));
+
     if ($CFG->forcelogin) {
         require_login();
     }
         } 
     }
 
+/// setting the default values for the display mode of the current glossary
+/// only if the glossary is viewed by the first time
+    if ( $dp = get_record('glossary_formats','name', $glossary->displayformat) ) {
+        $printpivot = $dp->showgroup;
+        if ( $mode == '' and $hook == '' and $show == '') {
+            $mode      = $dp->defaultmode;
+            $hook      = $dp->defaulthook;
+            $sortkey   = $dp->sortkey;
+            $sortorder = $dp->sortorder;
+        }
+    } else {
+        $printpivot = 1;
+        if ( $mode == '' and $hook == '' and $show == '') {
+            $mode = 'letter';
+            $hook = 'ALL';
+        }
+    }
+
+    if ( $displayformat == -1 ) {
+         $displayformat = $glossary->displayformat;
+    }
+
 /// stablishing flag variables
     if ( $sortorder = strtolower($sortorder) ) {
         if ($sortorder != 'asc' and $sortorder != 'desc') {
     if ( $hook == 'SPECIAL' ) {
         $alphabet = explode(",", get_string("alphabet"));
     }
-    $tableisopen = 0;
 
     $site = get_record("course","id",1);
     echo '<p align="right"><font size=-1>' . userdate(time()) . '</font></p>';
     echo '<strong>' . $site->fullname . '</strong><br>';
-    echo get_string("course") . ': <strong>' . $course->fullname . '</strong><br />';
+    echo get_string("course") . ': <strong>' . $course->fullname . ' ('. $course->shortname . ')</strong><br />';
     echo get_string("modulename","glossary") . ': <strong>' . $glossary->name . '</strong><p>';
     if ( $allentries ) {
         foreach ($allentries as $entry) {
             /// ok, if it's a valid entry.. Print it.
             if ( $showentry ) {
     
-                if ( !$tableisopen ) {
-                    echo '<table align="center" width="95%" bgcolor="#FFFFFF" style="border-style: solid; border-width: 1px;">';
-                    $tableisopen = 1;
-                }
                 if ( $currentpivot != strtoupper($pivot) ) {  
                     // print the group break if apply
                     if ( $printpivot )  {
                         $currentpivot = strtoupper($pivot);
     
-                        echo '<tr>';
                         $pivottoshow = $currentpivot;
                         if ( isset($entry->uid) ) {
-                        // printing the user icon if defined (only when browsing authors)
-                            echo '<td colspan="2" align="left" style="border-style: solid; border-width: 1px;">';
                             $user = get_record("user","id",$entry->uid);
                             $pivottoshow = fullname($user, isteacher($course->id));
-                        } else {
-                            echo '<td colspan="2" align="center" style="border-style: solid; border-width: 1px;">';
                         }
     
-                        echo "<strong><i>$pivottoshow</i></strong>" ;
-                        echo '</td>';
-                        echo '</tr>';
+                        echo "<p align=\"center\"><strong><i>$pivottoshow</i></strong></p>" ;
                     }
                 }
     
-                echo '<tr>';
-                echo '<td width="25%" align="right" valign="top"><b>'. $entry->concept . ': </b></td>';
-                echo '<td width="75%" style="border-style: solid; border-width: 1px;">';
+                echo '<b>'. strip_tags($entry->concept) . ': </b>';
+                $options->para = false;
+                $definition = format_text('<nolink>' . strip_tags($entry->definition) . '</nolink>', $entry->format,$options);
         
-                if ( $entry->attachment) {
-                    glossary_print_entry_attachment($entry);
-                }
-                echo strip_tags($entry->definition);
+                echo ($definition);
         
-                echo '<br><br></tr>';
+                echo '<br><br>';
             }
         }
     }
-    if ($tableisopen) {
-        echo '</table>';
-    }
-    echo '<center><font size=-1>' . userdate(time()) . '</font></center>';
 
     echo '</body></html>';
 ?>
index 92164286d1b3e9dd896579347ad0281614313bb9..fbb555075e24247938bf22c4a927b2ae9035120c 100644 (file)
                 }
             }
 
+            //To mantain backwards compatibility (pre 1.4) we have to check the displayformat field
+            //If it's numeric (0-6) we have to convert it to its new formatname.
+            //Define current 0-6 format names
+            $formatnames = array('dictionary','continuous','fullwithauthor','encyclopedia',
+                                 'faq','fullwithoutauthor','entrylist');
+            //If it's numeric, we are restoring a pre 1.4 course, do the conversion
+            if (is_numeric($glossary->displayformat)) {
+                $displayformat = 'dictionary';  //Default format
+                if ($glossary->displayformat >= 0 && $glossary->displayformat <= 6) {
+                  $displayformat = $formatnames[$glossary->displayformat];
+                }
+                $glossary->displayformat = $displayformat;
+            }
+
+            //Now check that the displayformat exists in the server, else default to dictionary
+            $formats = get_list_of_plugins('mod/glossary/formats');
+            if (!in_array($glossary->displayformat,$formats)) {
+                $glossary->displayformat = 'dictionary';
+            }
+
             //The structure is equal to the db, so insert the glossary
             $newid = insert_record ("glossary",$glossary);
 
index 57281756423d7fca5f2a57f00bcd7487a4485404..d8fe45765f41fbf20e129886dc08ea6165cf70fe 100644 (file)
         require_login();
     }
 
+    if ($eid) {
+        $entries[] = get_record("glossary_entries", "id", $eid);
+
+    } else if ($concept) {
+        $entries = get_records_sql("select e.* from {$CFG->prefix}glossary_entries e, {$CFG->prefix}glossary g".
+                                  " where e.glossaryid = g.id and".
+                                      " (e.casesensitive != 0 and ucase(concept) = '" . strtoupper(trim($concept)). "' or".
+                                      " e.casesensitive = 0 and concept = '$concept') and".
+                                      " (g.course = $courseid or g.globalglossary) and".
+                                      " e.usedynalink != 0 and g.usedynalink != 0");
+    }
+
+    foreach ($entries as $entry) {
+        $glossary = get_record('glossary','id',$entry->glossaryid);
+    }
+
     if (!empty($courseid)) {
         $course = get_record("course", "id", $courseid);
         if ($course->category) {
             "$strglossaries -> $strsearch", "", "", true, "&nbsp;", "&nbsp;");
         }
 
-
     } else {
         print_header();    // Needs to be something here to allow linking back to the whole glossary
     }
 
-
-    if ($eid) {
-        $entries[] = get_record("glossary_entries", "id", $eid);
-
-    } else if ($concept) {
-        $entries = get_records_sql("select e.* from {$CFG->prefix}glossary_entries e, {$CFG->prefix}glossary g".
-                                  " where e.glossaryid = g.id and".
-                                      " (e.casesensitive != 0 and ucase(concept) = '" . strtoupper(trim($concept)). "' or".
-                                      " e.casesensitive = 0 and concept = '$concept') and".
-                                      " (g.course = $courseid or g.globalglossary) and".
-                                      " e.usedynalink != 0 and g.usedynalink != 0");
-    } 
-
     if ($entries) {
         glossary_print_dynaentry($courseid, $entries, $displayformat);
     }    
index a7073d53a801dc43df7da1b20c774195385050fd..fbfc2b98cf3e762c7431b26c16bc5e69c04bfa65 100644 (file)
                           ge.id = gec.entryid AND gc.id = gec.categoryid AND
                           (ge.approved != 0 $userid)";
 
-            if ( $glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS ) {
-                $sqlorderby = ' ORDER BY gc.name, ge.timecreated';
-            } else {
-                $sqlorderby = ' ORDER BY gc.name, ge.concept';
-            }
+            $sqlorderby = ' ORDER BY gc.name, ge.concept';
 
         } elseif ($hook == GLOSSARY_SHOW_NOT_CATEGORISED ) { 
 
index 4ec828ba5a434061053747ff2150eb82530668a4..241bd7b89db4703a20c3c5502d287c2a113d3b24 100644 (file)
 
     $data[GLOSSARY_DATE_VIEW]->link = "view.php?id=$id&mode=date";
 
-    if ( $glossary->displayformat != GLOSSARY_FORMAT_CONTINUOUS ) {
+    $data[GLOSSARY_STANDARD_VIEW]->link = "view.php?id=$id&mode=letter";
+    $data[GLOSSARY_CATEGORY_VIEW]->link = "view.php?id=$id&mode=cat";
+    $data[GLOSSARY_AUTHOR_VIEW]->link = "view.php?id=$id&mode=author";
 
-        $data[GLOSSARY_STANDARD_VIEW]->link = "view.php?id=$id&mode=letter";
-        $data[GLOSSARY_CATEGORY_VIEW]->link = "view.php?id=$id&mode=cat";
-        $data[GLOSSARY_AUTHOR_VIEW]->link = "view.php?id=$id&mode=author";
-
-    }
 
     if (isteacher($course->id)) {
         $data[GLOSSARY_APPROVAL_VIEW]->caption = get_string("waitingapproval", "glossary");
index 4778508f1f28cc2a376fd8ff5837b4deb423a2fd..5d4b605712d39e95f2546abecca9626a7d4e8e19 100644 (file)
@@ -5,7 +5,7 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004072300;  // The current module version (Date: YYYYMMDDXX)
+$module->version  = 2004072700;  // The current module version (Date: YYYYMMDDXX)
 $module->requires = 2004052501;  // Requires this Moodle version
 $module->cron     = 0;           // Period for cron to check this module (secs)
 
index c3af03db506dabcbdbe89fc78f880e120c2f1b14..bea8ebd2f223df1e975a36e8684baa5dacf83fe7 100644 (file)
@@ -70,7 +70,7 @@
 
 /// setting the default values for the display mode of the current glossary
 /// only if the glossary is viewed by the first time
-    if ( $dp = get_record("glossary_displayformats","fid", $glossary->displayformat) ) {
+    if ( $dp = get_record('glossary_formats','name', $glossary->displayformat) ) {
         $printpivot = $dp->showgroup;
         if ( $mode == '' and $hook == '' and $show == '') {
             $mode      = $dp->defaultmode;
@@ -89,9 +89,6 @@
     if ( $displayformat == -1 ) {
          $displayformat = $glossary->displayformat;
     } 
-    if ( $displayformat == GLOSSARY_FORMAT_CONTINUOUS ) { 
-        $mode = 'date';
-    }
 
     if ( $show ) {
         $mode = 'term';
     
     case 'entry':  /// Looking for a certain entry id
         $tab = GLOSSARY_STANDARD_VIEW;
-        if ( $dp = get_record("glossary_displayformats","fid", $glossary->displayformat) ) {
-            if ( $dp->relatedview >= 0 ) {
-                $displayformat = $dp->relatedview;
-            }
+        if ( $dp = get_record("glossary_formats","name", $glossary->displayformat) ) {
+            $displayformat = $dp->popupformatname;
         }
     break;
     
         navmenu($course, $cm));
 
     //If rss are activated at site and glossary level and this glossary has rss defined, show link
-        if ($CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds && $glossary->rsstype and $glossary->rssarticles) {
+        if (isset($CFG->enablerssfeeds) && isset($CFG->glossary_enablerssfeeds) &&
+            $CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds && $glossary->rsstype and $glossary->rssarticles) {
             echo '<table width="100%" border="0" cellpadding="3" cellspacing="0"><tr valign="top"><td align="right">';
             $tooltiptext = get_string("rsssubscriberss","glossary",$glossary->name);
             rss_print_link($course->id, $USER->id, "glossary", $glossary->id, $tooltiptext);
     echo '<p align="center"><font size="3"><b>' . stripslashes_safe($glossary->name);
     if ( $isuserframe and $mode != 'search') {
     /// the "Print" icon
-        echo " <a title =\"". get_string("printerfriendly","glossary") . "\" target=\"_blank\" href=\"print.php?id=$cm->id&mode=$mode&hook=$hook&sortkey=$sortkey&sortorder=$sortorder&offset=$offset\">";
+        echo " <a title =\"". get_string("printerfriendly","glossary") . "\" target=\"printview\" href=\"print.php?id=$cm->id&mode=$mode&hook=$hook&sortkey=$sortkey&sortorder=$sortorder&offset=$offset\">";
         echo '<img border=0 src="print.gif"/></a>';
     }
     echo '</b></font></p>';
     $currentpivot = '';
     $ratingsmenuused = NULL;
     $paging = NULL;
-    $tableisopen = 0;
     if ( $hook == 'SPECIAL' ) {
         $alphabet = explode(",", get_string("alphabet"));
     }
 
                     // print the group break if apply
                     if ( $printpivot )  {
-                        if ( $tableisopen ) {
-                            print_simple_box_end();
-                            $tableisopen = 0;
-                        }
                         $currentpivot = strtoupper($pivot);
 
                         echo '<p>';
                         echo "<strong> $pivottoshow</strong>" ;
                         echo '</td></tr></table>';
 
-                        if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS OR 
-                            $glossary->displayformat == GLOSSARY_FORMAT_SIMPLE ) {
-                            print_simple_box_start("center","95%","#ffffff","5","generalbox");
-                            $tableisopen = 1;
-                        }
                     }
                 }
                 
-                if ( !$tableisopen ) {
-                    if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS OR 
-                        $glossary->displayformat == GLOSSARY_FORMAT_SIMPLE ) {
-                        print_simple_box_start("center","95%","#ffffff","5","generalbox");
-                        $tableisopen = 1;
-                    }
-                }
-
                 $concept = $entry->concept;
                 $definition = $entry->definition;
     
                 $entriesshown++;
             }
         }
-        if ( $tableisopen ) {
-            if ($glossary->displayformat == GLOSSARY_FORMAT_CONTINUOUS OR 
-                $glossary->displayformat == GLOSSARY_FORMAT_SIMPLE) {
-                print_simple_box_end();
-                $tableisopen = 0;
-            }
-        }
     }
     if ( !$entriesshown ) {
         print_simple_box('<center>' . get_string("noentries","glossary") . '</center>',"center","95%");