]> git.mjollnir.org Git - moodle.git/commitdiff
- Now entries could be commented by other users.
authorwillcast <willcast>
Thu, 16 Oct 2003 05:15:59 +0000 (05:15 +0000)
committerwillcast <willcast>
Thu, 16 Oct 2003 05:15:59 +0000 (05:15 +0000)
- KNOWN BUG: It does not restore the comments even when userinfo is set... Eloy! I need your help! :)

14 files changed:
lang/en/glossary.php
lang/en/help/glossary/allowcomments.html [new file with mode: 0644]
mod/glossary/backuplib.php
mod/glossary/comment.gif [new file with mode: 0644]
mod/glossary/comment.html [new file with mode: 0644]
mod/glossary/comment.php [new file with mode: 0644]
mod/glossary/comments.php [new file with mode: 0644]
mod/glossary/db/mysql.php
mod/glossary/db/mysql.sql
mod/glossary/db/postgres7.sql
mod/glossary/lib.php
mod/glossary/mod.html
mod/glossary/restorelib.php
mod/glossary/version.php

index 7ce7d0d72595d89c053e6b9916f99a26be408589..d43001b9e10a851c6a8105c133f09cf761e8720b 100644 (file)
@@ -1,20 +1,29 @@
 <?PHP // $Id$ 
       // glossary.php - created with Moodle 1.1 Beta (2003082001)
 
+$string['addcomment'] = "Add comment";
 $string['addentry'] = "Add a new entry";
 $string['allentries'] = "ALL";
 $string['allcategories'] = "All Categories";
+$string['allowcomments'] = "Allow comments on entries";
 $string['allowduplicatedentries'] = "Duplicated entries allowed";
 $string['alphabet'] = "A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z";
 $string['areyousuredelete'] = "Are you sure you want to delete this entry?";
+$string['areyousuredeletecomment'] = "Are you sure you want to delete this comment?";
 $string['attachment'] = "Attachment";
 $string['back'] = "Back";
 $string['categories'] = "Categories";
 $string['categoryview'] = "Browse by category";
 $string['category'] = "Category";
 $string['categorydeleted'] = "Category deleted";
+$string['comment'] = "Comment";
+$string['commentdeleted'] = "The comment has been deleted.";
+$string['commentupdated'] = "The comment has been updated.";
+$string['comments'] = "Comments";
+$string['commentson'] = "Comments on";
 $string['concept'] = "Concept";
 $string['concepts'] = "Concepts";
+$string['deletingcomment'] = "Deleting comment";
 $string['definition'] = "Definition";
 $string['definitions'] = "Definitions";
 $string['deleteentry'] = "Delete entry";
@@ -24,8 +33,9 @@ $string['displayformatdefault'] = "Simple, dictionary style";
 $string['displayformat1'] = "Full without author";
 $string['displayformat2']  = "Full with author";
 $string['displayformat3']  = "Encyclopedia";
-$string['editentry'] = "Edit entry";
 $string['editcategories'] = "Edit categories";
+$string['editentry'] = "Edit entry";
+$string['editingcomment'] = "Editing comment";
 $string['entries'] = "Entries";
 $string['entrieswithoutcategory'] = "Entries without category";
 $string['entry'] = "Entry";
@@ -41,8 +51,11 @@ $string['glossarytype'] = "Glossary Type";
 $string['mainglossary'] = "Main glossary";
 $string['modulename'] = "Glossary";
 $string['modulenameplural'] = "Glossaries";
+$string['maxtimehaspassed'] = "Sorry, but the maximum time for editing this comment (\$a) has passed!";
 $string['newglossaryentries'] = "New glossary entries:";
 $string['notcategorised'] = "Not categorised";
+$string['nocomment'] = "No comment found";
+$string['nocomments'] = "(No comments found on this entry)";
 $string['noentries'] = "No entries found in this section";
 $string['noentry'] = "No entry found.";
 $string['searchindefinition'] = "Search definitions too";
@@ -55,5 +68,6 @@ $string['standardview'] = "Browse by alphabet";
 $string['studentcanpost'] = "Students can add entries";
 $string['warningstudentcapost'] = "(Applies only if the glossary is not the main one)";
 $string['writtenby'] = "by";
+$string['youarenottheauthor'] = "You are not the author of this comment, therefore, you are not allowed to edit it.";
 
 ?>
diff --git a/lang/en/help/glossary/allowcomments.html b/lang/en/help/glossary/allowcomments.html
new file mode 100644 (file)
index 0000000..d404442
--- /dev/null
@@ -0,0 +1,4 @@
+<P ALIGN=CENTER><B>Allow comments on entries</B></P>
+
+<P>You can specify if the system should or should not allow comments on glossary entries.
+
index 9a406ab2000b88e69d4f448fd893a0c0c65d6561..1ab0e729b2eafa2ba3671bd88d1d848c7a50b87c 100644 (file)
     //                        |                                       |
     //                  glossary_entries -------------- glossary_entries_categories
     //         (UL,pk->id, fk->glossaryid, files)      (UL, [pk->categoryid,entryid]
+    //                        |                                       
+    //                        |                                       
+    //                        |                                       
+    //                  glossary_comments
+    //         (UL,pk->id, fk->entryid)
+    //
     //
     // Meaning: pk->primary key field of the table
     //          fk->foreign key to link with parent
@@ -45,6 +51,7 @@
                 fwrite ($bf,full_tag("SHOWSPECIAL",4,false,$glossary->showspecial));
                 fwrite ($bf,full_tag("SHOWALPHABET",4,false,$glossary->showalphabet));
                 fwrite ($bf,full_tag("SHOWALL",4,false,$glossary->showall));
+                fwrite ($bf,full_tag("ALLOWCOMMENTS",4,false,$glossary->allowcomments));
                 fwrite ($bf,full_tag("TIMECREATED",4,false,$glossary->timecreated));
                 fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$glossary->timemodified));
                 
@@ -52,6 +59,9 @@
 
                 backup_glossary_categories($bf,$preferences,$glossary->id, $preferences->mods["glossary"]->userinfo);
 
+                if ( $preferences->mods["glossary"]->userinfo ) {
+                    backup_glossary_comments($bf,$preferences,$glossary->id, $preferences->mods["glossary"]->userinfo);
+                }
                 //End mod
                 $status =fwrite ($bf,end_tag("MOD",3,true));
             }
                     fwrite ($bf,full_tag("TIMECREATED",6,false,$glo_ent->timecreated));
                     fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$glo_ent->timemodified));
                     fwrite ($bf,full_tag("TEACHERENTRY",6,false,$glo_ent->teacherentry));
-
+/*
+                    if ( $userinfo ) {
+                        $comments = get_records("glossary_comments","entryid",$glo_ent->id);
+                        if ( $comments ) {
+                            $status =fwrite ($bf,start_tag("COMMENTS",6,true));
+                            foreach ($comments as $comment) {
+                                $status =fwrite ($bf,start_tag("COMMENT",7,true));
+
+                                fwrite ($bf,full_tag("ID",6,false,$comment->id));
+                                fwrite ($bf,full_tag("USERID",6,false,$comment->userid));
+                                fwrite ($bf,full_tag("COMMENT",6,false,$comment->comment));
+                                fwrite ($bf,full_tag("FORMAT",6,false,$comment->format));
+                                fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$comment->timemodified));
+
+                                $status =fwrite ($bf,end_tag("COMMENT",7,true));
+                            }
+                            $status =fwrite ($bf,end_tag("COMMENTS",6,true));
+                        }
+                    }
+*/
                     $status =fwrite ($bf,end_tag("ENTRY",5,true));
 
                     //Now include entry attachment in backup (if it exists)
         return $status;
     }
    
-
     //Backup glossary files because we've selected to backup user info
     //or current entry is a teacher entry
     function backup_glossary_files($bf,$preferences,$glossary,$entry) {
diff --git a/mod/glossary/comment.gif b/mod/glossary/comment.gif
new file mode 100644 (file)
index 0000000..0dd9874
Binary files /dev/null and b/mod/glossary/comment.gif differ
diff --git a/mod/glossary/comment.html b/mod/glossary/comment.html
new file mode 100644 (file)
index 0000000..7376426
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+    global $CFG, $THEME;
+    require_once("../../config.php");
+    require_once("lib.php");
+?>
+<FORM name="theform" method="post" <?=$onsubmit ?> action="comment.php">
+<table  class=generalbox cellpadding=5 bgcolor="<?php p($THEME->cellheading)?>">
+<tr valign=top>
+    <td align=right><p><b><?php echo get_string("comment","glossary") ?>:</b></p>
+    <font size="1">
+     <?php
+        helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
+        echo "<br />";
+        if ($usehtmleditor) {
+           helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
+        } else {
+           emoticonhelpbutton("form", "comment");
+        } 
+      ?>
+      <br />
+    </font>
+    </td>
+    <td>
+    <?php
+       print_textarea($usehtmleditor, 20, 60, 680, 400, "text", $form->text);
+    
+       echo "<p align=right>";
+          helpbutton("textformat", get_string("helpformatting"));
+       print_string("formattexttype");
+       echo ":&nbsp;";
+       if (!$form->format) {
+           $form->format = $defaultformat;
+       }
+       choose_from_menu(format_text_menu(), "format", $format->format, ""); 
+       echo "</p>";
+    ?>
+    </td>
+</tr>
+<tr>
+<td colspan=2>
+       <p align=center>
+       <?php 
+           if ($comment->id) {
+                   echo "<input type=\"hidden\" name=cid value=\"$comment->id\">";
+           }
+       ?>
+       <input type="hidden" name=id value="<?=$cm->id ?>">
+       <input type="hidden" name=eid value="<?=$entry->id ?>">
+       <input type="hidden" name=action value="<?=$action ?>">
+       <input type="hidden" name=confirm value="1">
+
+       <input type="submit" value="<?php print_string("savechanges") ?>">
+       <input type="reset" value="<?php print_string("revert") ?>">
+       </P>
+</td>
+</tr>
+</table>
+</p>
+
+
+</form>
+
+<?PHP 
+   if ($usehtmleditor) { 
+       print_richedit_javascript("theform", "text", "no");
+   }
+?>
+
diff --git a/mod/glossary/comment.php b/mod/glossary/comment.php
new file mode 100644 (file)
index 0000000..026220a
--- /dev/null
@@ -0,0 +1,210 @@
+<?php // $Id$
+
+/// This page prints a particular instance of glossary
+    require_once("../../config.php");
+    require_once("lib.php");
+    
+    require_variable($id);             // Course Module ID
+    require_variable($eid);            // Entry ID
+    optional_variable($cid,0);         // Comment ID
+
+    optional_variable($action,"add");     // Action to perform
+    optional_variable($confirm,0);     // Confirm the action
+    
+    $action = strtolower($action);
+       
+       global $THEME, $USER, $CFG;
+    
+    if (! $cm = get_record("course_modules", "id", $id)) {
+        error("Course Module ID was incorrect");
+    } 
+    
+    if (! $course = get_record("course", "id", $cm->course)) {
+        error("Course is misconfigured");
+    } 
+    
+    if (! $glossary = get_record("glossary", "id", $cm->instance)) {
+        error("Course module is incorrect");
+    } 
+    
+   if (! $entry = get_record("glossary_entries", "id", $eid)) {
+      error("Entry is incorrect");
+   }
+   
+   if ( $cid ) {
+      if (! $comment = get_record("glossary_comments", "id", $cid)) {
+          error("Comment is incorrect");
+      }
+   } 
+
+    require_login($course->id);    
+    if (!$cm->visible and !isteacher($course->id)) {
+        notice(get_string("activityiscurrentlyhidden"));
+    } 
+    
+    add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id");
+    
+/// Printing the page header
+    if ($course->category) {
+        $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
+    } 
+    
+    switch ( $action ){
+        case "add":
+            $straction = get_string("addingcomment","glossary");
+        break;
+        case "edit":
+            $straction = get_string("editingcomment","glossary");
+        break;
+        case "delete":
+            $straction = get_string("deletingcomment","glossary");
+        break;
+       }
+    $strglossaries = get_string("modulenameplural", "glossary");
+    $strglossary = get_string("modulename", "glossary");
+    $strcomments = get_string("comments", "glossary");
+
+    print_header(strip_tags("$course->shortname: $glossary->name"), "$course->fullname",
+        "$navigation <A HREF=index.php?id=$course->id>$strglossaries</A> -> <A HREF=view.php?id=$cm->id>$glossary->name</a> -> <A HREF=comments.php?id=$cm->id&eid=$entry->id>$strcomments</a> -> " . $straction,
+        "", "", true, update_module_button($cm->id, $course->id, $strglossary),
+        navmenu($course, $cm));
+    
+    print_heading($glossary->name);
+
+/// Info boxes
+
+    if ( $glossary->intro ) {
+           print_simple_box_start("center","70%");
+        echo '<p>';
+        echo $glossary->intro;
+        echo '</p>';
+        print_simple_box_end();
+    }
+
+    echo "<p align=center>";
+    echo "<table class=\"generalbox\" width=\"70%\" align=\"center\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">";
+    echo "<tr bgcolor=$THEME->cellheading2><td align=center>";
+        echo "<b>$entry->concept</b>";
+    echo "</td></tr>";
+    echo "<tr><TD WIDTH=100% BGCOLOR=\"#FFFFFF\">";
+    if ($entry->attachment) {
+          $entry->course = $course->id;
+          echo "<table border=0 align=right><tr><td>";
+          echo glossary_print_attachments($entry,"html");
+          echo "</td></tr></table>";
+    }
+    echo format_text($entry->definition, $entry->format);
+    echo "</td>";
+    echo "</TR></table><p align=center>";
+
+/// Input section
+    if ( $action == "delete" ) {
+        if ( $confirm ) {
+            delete_records("glossary_comments","id", $cid);                            
+
+            print_simple_box_start("center","40%", "#FFBBBB");
+            echo "<center>" . get_string("commentdeleted","glossary") . "</center>";
+            print_simple_box_end();
+
+            print_footer($course);
+            add_to_log($course->id, "glossary", "delete comment", "comments.php?id=$cm->id&eid=$entry->id", $comment);
+            redirect("comments.php?id=$cm->id&eid=$entry->id");
+        } else {
+            echo "<p align=center>";
+            echo "<table class=\"generalbox\" width=\"70%\" align=\"center\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">";
+            echo "<tr><td align=right width=25% BGCOLOR=\"$THEME->cellheading\">";
+
+            $user = get_record("user", "id", $comment->userid);
+            $strby = get_string("writtenby","glossary");
+
+            print_user_picture($user->id, $course->id, $user->picture);
+            echo "<br><FONT SIZE=2>$strby $user->firstname $user->lastname</font>";
+            echo "<br><FONT SIZE=1>(".get_string("lastedited").": ".userdate($comment->timemodified).")</FONT></small>";
+
+            echo "</td><TD WIDTH=75% BGCOLOR=\"$THEME->cellcontent\">";
+                echo format_text($comment->comment, $comment->format);
+            echo "</td></TR></table>";
+            echo "<p align=center>";
+
+                    print_simple_box_start("center","40%", "#FFBBBB");
+                    echo "<center><br>" . get_string("areyousuredeletecomment","glossary");
+?>
+             <form name="form" method="post" action="comment.php">
+            <input type="hidden" name=id            value="<?php p($id) ?>">
+            <input type="hidden" name=eid           value="<?php p($eid) ?>">
+            <input type="hidden" name=cid           value="<?php p($cid) ?>">
+            <input type="hidden" name=action        value="delete">
+            <input type="hidden" name=confirm       value="1">
+            <input type="submit" value=" <?php print_string("yes")?> ">
+            <input type=button value=" <?php print_string("no")?> " onclick="javascript:history.go(-1);">
+
+        </form>
+        </center>
+        <?php
+            print_simple_box_end();
+        }
+    } else {
+        if ( $action == "edit" ) {
+            if ( (time() - $comment->timemodified >= $CFG->maxeditingtime or $USER->id != $comment->userid) and !isteacher($course->id) ) {
+                echo "<center><strong>";
+                if ( $USER->id != $comment->userid ) {
+                    echo get_string("youarenottheauthor","glossary",$CFG->maxeditingtime);
+                } elseif (time() - $comment->timemodified >= $CFG->maxeditingtime ) {
+                    echo get_string("maxtimehaspassed","glossary",$CFG->maxeditingtime);
+                }
+                echo "</strong></center>";
+                print_footer($course);
+                die;
+            }
+        }
+        
+        if ( $confirm and $form = data_submitted() ) {
+            $form->text = clean_text($form->text, $form->format);
+
+            $newentry->entryid = $entry->id;
+            $newentry->comment = $form->text;
+            $newentry->format = $form->format;
+            $newentry->timemodified = $comment->timemodified;
+                       
+            if ( $action == "add" ) {
+                $newentry->userid = $USER->id;
+
+                if (! $newentry->id = insert_record("glossary_comments", $newentry)) {
+                    error("Could not insert this new comment");
+                } else {
+                    add_to_log($course->id, "glossary", "add comment", "comments.php?id=$cm->id&eid=$entry->id", "$newentry->id");
+                }
+            } else {
+                $newentry->id = $form->cid;
+                $newentry->userid = $comment->userid;
+
+                if (! update_record("glossary_comments", $newentry)) {
+                    error("Could not update this comment");
+                } else {
+                    add_to_log($course->id, "glossary", "update comment", "comments.php?id=$cm->id&eid=$entry->id", "$newentry->id");
+                }
+            }
+            print_simple_box_start("center","40%", "#FFBBBB");
+            echo "<center>" . get_string("commentupdated","glossary") . "</center>";
+            print_simple_box_end();
+
+            print_footer($course);
+
+            redirect("comments.php?id=$cm->id&eid=$entry->id");
+        } else {
+            if ($usehtmleditor = can_use_richtext_editor()) {
+                $defaultformat = FORMAT_HTML;
+                $onsubmit = "onsubmit=\"copyrichtext(theform.text);\"";
+            } else {
+                $defaultformat = FORMAT_MOODLE;
+                $onsubmit = "";
+            }
+
+            $form->text = $comment->comment;
+            $form->format = $comment->format;
+            include("comment.html");
+        }
+    }
+/// Finish the page
+    print_footer($course);
+?>
\ No newline at end of file
diff --git a/mod/glossary/comments.php b/mod/glossary/comments.php
new file mode 100644 (file)
index 0000000..1d3da9c
--- /dev/null
@@ -0,0 +1,105 @@
+<?php // $Id$
+
+/// This page prints a particular instance of glossary
+    require_once("../../config.php");
+    require_once("lib.php");
+    
+    require_variable($id);           // Course Module ID
+    require_variable($eid);         // Entry ID
+       
+       global $THEME, $USER, $CFG;
+    
+    if (! $cm = get_record("course_modules", "id", $id)) {
+        error("Course Module ID was incorrect");
+    } 
+    
+    if (! $course = get_record("course", "id", $cm->course)) {
+        error("Course is misconfigured");
+    } 
+    
+    if (! $glossary = get_record("glossary", "id", $cm->instance)) {
+        error("Course module is incorrect");
+    } 
+    
+    if (! $entry = get_record("glossary_entries", "id", $eid)) {
+        error("Entry is incorrect");
+    } 
+
+
+    require_login($course->id);    
+    if (!$cm->visible and !isteacher($course->id)) {
+        notice(get_string("activityiscurrentlyhidden"));
+    } 
+    
+    add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id");
+    
+    
+/// Printing the page header
+    if ($course->category) {
+        $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
+    } 
+    
+    $strglossaries = get_string("modulenameplural", "glossary");
+    $strglossary = get_string("modulename", "glossary");
+    $strallcategories = get_string("allcategories", "glossary");
+    $straddentry = get_string("addentry", "glossary");
+    $strnoentries = get_string("noentries", "glossary");
+    $strsearchconcept = get_string("searchconcept", "glossary");
+    $strsearchindefinition = get_string("searchindefinition", "glossary");
+    $strsearch = get_string("search");
+    
+    print_header(strip_tags("$course->shortname: $glossary->name"), "$course->fullname",
+        "$navigation <A HREF=index.php?id=$course->id>$strglossaries</A> -> <A HREF=view.php?id=$cm->id>$glossary->name</a> -> " . get_string("comments","glossary"),
+        "", "", true, update_module_button($cm->id, $course->id, $strglossary),
+        navmenu($course, $cm));
+    
+    print_heading($glossary->name);
+
+/// Info boxes
+
+    if ( $glossary->intro ) {
+           print_simple_box_start("center","70%");
+        echo '<p>';
+        echo $glossary->intro;
+        echo '</p>';
+        print_simple_box_end();
+    }
+
+    echo "<p align=center>";
+    echo "<table class=\"generalbox\" width=\"70%\" align=\"center\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">";
+       echo "<tr bgcolor=$THEME->cellheading2><td align=center>";
+           echo "<table border=0 width=100%><tr><td width=33%></td><td width=33% align=center>";
+           echo get_string("commentson","glossary") . " <b>$entry->concept</b></td>";
+           echo "<td width=33% align=right>";  
+        if ( $glossary->allowcomments ) {      
+            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> ";
+        }
+           echo "</td></tr></table>";
+                       
+       echo "</td></tr>";
+    echo "<tr><TD WIDTH=100% BGCOLOR=\"#FFFFFF\">";
+    if ($entry->attachment) {
+          $entry->course = $course->id;
+          echo "<table border=0 align=right><tr><td>";
+          echo glossary_print_attachments($entry,"html");
+          echo "</td></tr></table>";
+    }
+    echo "<b>$entry->concept</b>: ";
+    echo format_text($entry->definition, $entry->format);
+    echo "</td>";
+    echo "</TR></table>";
+
+/// comments
+    $comments = get_records("glossary_comments","entryid",$entry->id,"timemodified ASC");
+    if ( !$comments ) {
+        echo "<p align=center><strong>" .  get_string("nocomments","glossary") . "</string>";
+    } else {
+        foreach ($comments as $comment) {
+                   echo "<p align=center>";
+                   glossary_print_comment($course, $cm, $glossary, $entry, $comment);
+        }
+    }
+
+/// Finish the page
+    print_footer($course);
+?>
\ No newline at end of file
index 17a69aeb7e695b4d7dce11807e96faef2aaac8de..ac24cb0a97d6c2aa85e4d23f1ceb45184d8140eb 100644 (file)
@@ -72,6 +72,25 @@ function glossary_upgrade($oldversion) {
 
     }
 
+    if ( $oldversion < 2003101501 ) {
+        execute_sql( "ALTER TABLE `{$CFG->prefix}glossary` " .
+                    "ADD `allowcomments`  TINYINT(2) UNSIGNED NOT NULL DEFAULT '0' AFTER `showall` " );
+
+        execute_sql("CREATE TABLE `{$CFG->prefix}glossary_comments` (
+                    `id` INT(10) unsigned NOT NULL auto_increment,
+                    `entryid` INT(10) UNSIGNED NOT NULL default '0',
+                    `userid` INT(10) UNSIGNED NOT NULL default '0',
+                    `comment` TEXT NOT NULL default '',
+                    `timemodified` INT(10) UNSIGNED NOT NULL default '0',
+                    `format` TINYINT(2) UNSIGNED NOT NULL default '0',
+                    PRIMARY KEY  (`id`)
+                    ) TYPE=MyISAM COMMENT='comments on glossary entries'");
+
+        execute_sql(" INSERT INTO {$CFG->prefix}log_display VALUES ('glossary', 'add comment', 'glossary', 'name') ");
+        execute_sql(" INSERT INTO {$CFG->prefix}log_display VALUES ('glossary', 'update comment', 'glossary', 'name') ");
+        execute_sql(" INSERT INTO {$CFG->prefix}log_display VALUES ('glossary', 'delete comment', 'glossary', 'name') ");
+    }
+
     return true;
 }
 
index d6196acb98a6ae5f0cda015350ae11924e8086a1..e7d3696045367c515674c26a8956ee8303608f56 100644 (file)
@@ -20,6 +20,7 @@ CREATE TABLE prefix_glossary (
      showspecial tinyint(2) unsigned NOT NULL default '1',
      showalphabet tinyint(2) unsigned NOT NULL default '1',
      showall tinyint(2) unsigned NOT NULL default '1',
+     allowcomments tinyint(2) unsigned NOT NULL default '0',
      timecreated int(10) unsigned NOT NULL default '0',
      timemodified int(10) unsigned NOT NULL default '0',
      PRIMARY KEY  (id)
@@ -66,6 +67,17 @@ CREATE TABLE prefix_glossary_entries_categories (
      PRIMARY KEY  (id)
 ) TYPE=MyISAM COMMENT='categories of each glossary entry';
 
+CREATE TABLE prefix_glossary_comments (
+     id int(10) unsigned NOT NULL auto_increment,
+     entryid int(10) unsigned NOT NULL default '0',
+     userid int(10) unsigned NOT NULL default '0',
+     comment text NOT NULL,
+     format tinyint(2) unsigned NOT NULL default '0',
+     timemodified int(10) unsigned NOT NULL default '0',
+        
+     PRIMARY KEY  (id)
+) TYPE=MyISAM COMMENT='comments on glossary entries';
+
 #
 # Dumping data for table `log_display`
 #
@@ -79,4 +91,7 @@ INSERT INTO prefix_log_display VALUES ('glossary', 'update entry', 'glossary', '
 INSERT INTO prefix_log_display VALUES ('glossary', 'add category', 'glossary', 'name');
 INSERT INTO prefix_log_display VALUES ('glossary', 'update category', 'glossary', 'name');
 INSERT INTO prefix_log_display VALUES ('glossary', 'delete category', 'glossary', 'name');
+INSERT INTO prefix_log_display VALUES ('glossary', 'add comment', 'glossary', 'name');
+INSERT INTO prefix_log_display VALUES ('glossary', 'update comment', 'glossary', 'name');
+INSERT INTO prefix_log_display VALUES ('glossary', 'delete comment', 'glossary', 'name');
 
index 0c1746c09c18e342caf462acb7d6c2cd485f607c..310a4ca3d5ba66f5f7778638c3b7eda2947ab466 100644 (file)
@@ -20,6 +20,7 @@ CREATE TABLE prefix_glossary (
      showspecial int2 NOT NULL default '1',
      showalphabet int2 NOT NULL default '1',
      showall int2 NOT NULL default '1',
+     allowcomments int2 NOT NULL default '0',
      timecreated int4 NOT NULL default '0',
      timemodified int4 NOT NULL default '0',
      PRIMARY KEY  (id)
@@ -66,6 +67,20 @@ CREATE TABLE prefix_glossary_entries_categories (
      PRIMARY KEY  (id)
 );
 
+#
+# Table structure for table `glossary_comments`
+#
+
+CREATE TABLE prefix_glossary_comments (
+     id SERIAL,
+     entryid int4 NOT NULL default '0',
+     userid int4 NOT NULL default '0',
+     comment text NOT NULL,
+     format int2 NOT NULL default '0',
+     timemodified int4 NOT NULL default '0',
+     PRIMARY KEY  (id)
+);
+
 #
 # Dumping data for table `log_display`
 #
@@ -79,4 +94,6 @@ INSERT INTO prefix_log_display VALUES ('glossary', 'update entry', 'glossary', '
 INSERT INTO prefix_log_display VALUES ('glossary', 'add category', 'glossary', 'name');
 INSERT INTO prefix_log_display VALUES ('glossary', 'update category', 'glossary', 'name');
 INSERT INTO prefix_log_display VALUES ('glossary', 'delete category', 'glossary', 'name');
-
+INSERT INTO prefix_log_display VALUES ('glossary', 'add comment', 'glossary', 'name');
+INSERT INTO prefix_log_display VALUES ('glossary', 'update comment', 'glossary', 'name');
+INSERT INTO prefix_log_display VALUES ('glossary', 'delete comment', 'glossary', 'name');
index a0096525ef3b3c8d2f156c976c4cf7148e15f433..08279b094de08769484d34635cd0a170d3713b33 100644 (file)
@@ -235,25 +235,34 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview
     $isteacher = isteacher($course->id);
     $ismainglossary = $glossary->mainglossary;
     
-       if ($isteacher or $glossary->studentcanpost and $entry->userid == $USER->id) {
-               echo "<p align=right>";
-               // only teachers can export entries so check it out
-               if ($isteacher and !$ismainglossary and !$importedentry) {
-                       $mainglossary = get_record("glossary","mainglossary",1,"course",$course->id);
-                       if ( $mainglossary ) {  // if there is a main glossary defined, allow to export the current entry
-                               
+    echo "<table width=100% border=0><tr><td>";
+        
+    $count = count_records("glossary_comments","entryid",$entry->id);
+    echo "<a href=\"comments.php?id=$cm->id&eid=$entry->id\">$count " . get_string("comments","glossary") . "</a>";
+    echo "</td><td align=\"right\">";
+    if ( $glossary->allowcomments ) {
+        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> ";
+    }
+       
+    if ($isteacher or $glossary->studentcanpost and $entry->userid == $USER->id) {
+        // only teachers can export entries so check it out
+
+        if ($isteacher and !$ismainglossary and !$importedentry) {
+            $mainglossary = get_record("glossary","mainglossary",1,"course",$course->id);
+            if ( $mainglossary ) {  // if there is a main glossary defined, allow to export the current entry
+
                 echo "<a href=\"exportentry.php?id=$cm->id&entry=$entry->id&currentview=$currentview&cat=$cat\"><img  alt=\"" . get_string("exporttomainglossary","glossary") . "\"src=\"export.gif\" height=11 width=11 border=0></a> ";
 
-                       }
-               }
-               
+            }
+        }
+
         if ( $entry->sourceglossaryid ) {
             $icon = "minus.gif";   // graphical metaphor (minus) for deleting an imported entry
         } else {
             $icon = "../../pix/t/delete.gif";
         }
 
-               // Exported entries can be updated/deleted only by teachers in the main glossary
+        // Exported entries can be updated/deleted only by teachers in the main glossary
         if ( !$importedentry and ($isteacher or !$ismainglossary) ) {
             echo "<a href=\"deleteentry.php?id=$cm->id&mode=delete&entry=$entry->id&currentview=$currentview&cat=$cat\"><img  alt=\"" . get_string("delete") . "\"src=\"";
             echo $icon;
@@ -263,7 +272,8 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry,$currentview
         } elseif ( $importedentry ) {
             echo "<font size=-1>" . get_string("exportedentry","glossary") . "</font>";
         }
-       }
+    }
+    echo "</td></tr></table>";
 }
 
 function glossary_search_entries($searchterms, $glossary, $includedefinition) {
@@ -325,9 +335,9 @@ function glossary_search_entries($searchterms, $glossary, $includedefinition) {
         }
     }
 
-       if ( !$includedefinition ) {
-               $definitionsearch = "0";
-       }
+    if ( !$includedefinition ) {
+        $definitionsearch = "0";
+    }
 
     $selectsql = "{$CFG->prefix}glossary_entries e,
                   {$CFG->prefix}glossary g $onlyvisibletable
@@ -337,7 +347,7 @@ function glossary_search_entries($searchterms, $glossary, $includedefinition) {
 
     $totalcount = count_records_sql("SELECT COUNT(*) FROM $selectsql");
 
-       return get_records_sql("SELECT e.concept, e.definition, e.userid, e.timemodified, e.id, e.format  FROM
+    return get_records_sql("SELECT e.concept, e.definition, e.userid, e.timemodified, e.id, e.format  FROM
                             $selectsql ORDER BY e.concept ASC $limit");
 }
 
@@ -571,13 +581,13 @@ for ($row = 0; $row < $numrows; $row++) {
                         echo "<a href=\"" . $data[$tabproccessed]->link . "\">";
                     }
 
-                                       if ( !$data[$tabproccessed]->link ) {
-                                           echo "<font color=\"$inactivefontcolor\">";
-                                       }
+                    if ( !$data[$tabproccessed]->link ) {
+                        echo "<font color=\"$inactivefontcolor\">";
+                    }
                     echo $data[$tabproccessed]->caption;
-                                       if ( !$data[$tabproccessed]->link ) {
-                                           echo "</font>";
-                                       }
+                    if ( !$data[$tabproccessed]->link ) {
+                        echo "</font>";
+                    }
 
                     if ($tabproccessed != $currenttab and $data[$tabproccessed]->link) {
                         echo "</a>";
@@ -615,13 +625,13 @@ for ($row = 0; $row < $numrows; $row++) {
                         echo "<a href=\"" . $data[$tabproccessed]->link . "\">";
                     }
 
-                                       if ( !$data[$tabproccessed]->link ) {
-                                           echo "<font color=\"$inactivefontcolor\">";
-                                       }
+                    if ( !$data[$tabproccessed]->link ) {
+                        echo "<font color=\"$inactivefontcolor\">";
+                    }
                     echo $data[$tabproccessed]->caption;
-                                       if ( !$data[$tabproccessed]->link ) {
-                                           echo "</font>";
-                                       }
+                    if ( !$data[$tabproccessed]->link ) {
+                        echo "</font>";
+                    }
 
                     if ($tabproccessed != $currenttab and $data[$tabproccessed]->link) {
                         echo "</a>";
@@ -783,4 +793,49 @@ function glossary_sort_entries ( $entry0, $entry1 ) {
     }
 }
 
+function glossary_print_comment($course, $cm, $glossary, $entry, $comment) {
+    global $THEME, $CFG, $USER;
+
+//    if ($entry->timemarked < $entry->modified) {
+        $colour = $THEME->cellheading2;
+//    } else {
+//        $colour = $THEME->cellheading;
+//    }
+
+    $user = get_record("user", "id", $comment->userid);
+    $strby = get_string("writtenby","glossary");
+
+    echo "<table class=\"generalbox\"  BORDER=1 CELLSPACING=0 valign=top cellpadding=0 width=70% border=0><tr><td>";
+
+    echo "\n<TABLE width=\"100%\" BORDER=0 CELLSPACING=0 valign=top cellpadding=5><tr>";
+  
+    echo "\n<TD BGCOLOR=\"$THEME->cellheading\" WIDTH=25% VALIGN=TOP align=right >";
+    print_user_picture($user->id, $course->id, $user->picture);
+    echo "<br><FONT SIZE=2>$strby $user->firstname $user->lastname</font>";
+    echo "<br><FONT SIZE=1>(".get_string("lastedited").": ".userdate($comment->timemodified).")</FONT></small><br>";
+    echo "</TD>";
+       
+    echo "<TD NOWRAP valign=top WIDTH=75% BGCOLOR=\"$THEME->cellcontent\">";
+    if ($comment) {
+           echo format_text($comment->comment, $comment->format);
+    } else {
+         echo "<center>";
+        print_string("nocomment", "glossary");
+         echo "</center>";
+    }
+
+    echo "<p align=right>";
+       if ( (time() - $comment->timemodified <  $CFG->maxeditingtime and $USER->id == $comment->userid)  or isteacher($course->id) ) {
+        echo "<a href=\"comment.php?id=$cm->id&eid=$entry->id&cid=$comment->id&action=edit\"><img  alt=\"" . get_string("edit") . "\" src=\"../../pix/t/edit.gif\" height=11 width=11 border=0></a> ";
+       }
+       if ( $USER->id == $comment->userid or isteacher($course->id) ) {
+        echo "<a href=\"comment.php?id=$cm->id&eid=$entry->id&cid=$comment->id&action=delete\"><img  alt=\"" . get_string("delete") . "\" src=\"../../pix/t/delete.gif\" height=11 width=11 border=0></a>";
+       }
+    echo "</td>";
+       
+    echo "</tr></TABLE>\n";
+
+    echo "</td></tr></table>";
+}
+
 ?>
index ca0238dff04e257194b6d8b263b5f654053e4253..3da3f7ab59090caf8f282120f0a7b1c879a5a529 100644 (file)
@@ -93,6 +93,25 @@ if (!$mainglossary or $mainglossary->id == $form->instance ) {
   </select> <?php helpbutton("allowduplicatedentries", get_string("allowduplicatedentries", "glossary"), "glossary") ?>
     </TD>
 </TR>
+<TR valign=top>
+    <TD align=right><P><B><?php echo get_string("allowcomments", "glossary") ?>:</B></P></TD>
+    <TD>
+  <select size="1" name="allowcomments">
+  <option value="1" <?php
+   if ( $form->allowcomments ) {
+      echo "selected";
+   }
+   ?> 
+   ><?php echo get_string("yes") ?></option>
+  <option value="0" <?php
+   if ( !$form->allowcomments ) {
+      echo "selected";
+   }
+   ?>><?php echo get_string("no") ?>
+  </option>
+  </select> <?php helpbutton("allowcomments", get_string("allowcomments", "glossary"), "glossary") ?>
+    </TD>
+</TR>
 <TR valign=top>
 <td colspan=2><hr>
 </tr>
index 085ed792ea89197de427bc3a42532810a81d92fd..274fbb947f6995f284bfa4ec3571acafa10b4c27 100644 (file)
@@ -49,6 +49,7 @@
             $glossary->showspecial = backup_todb($info['MOD']['#']['SHOWSPECIAL']['0']['#']);
             $glossary->showalphabet = backup_todb($info['MOD']['#']['SHOWALPHABET']['0']['#']);
             $glossary->showall = backup_todb($info['MOD']['#']['SHOWALL']['0']['#']);
+            $glossary->allowcomments = backup_todb($info['MOD']['#']['ALLOWCOMMENTS']['0']['#']);
             $glossary->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
             $glossary->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
 
             $entry->timemodified = backup_todb($ent_info['#']['TIMEMODIFIED']['0']['#']);
             $entry->teacherentry = backup_todb($ent_info['#']['TEACHERENTRY']['0']['#']);
 
-
             //We have to recode the userid field
             $user = backup_getid($restore->backup_unique_code,"user",$entry->userid);
             if ($user) {
index de38c6f75f0f06c64ced2adf7bdc7ed6427c3094..1f92564c725a34fa5d607f88231e2f054cd9f58b 100644 (file)
@@ -5,7 +5,7 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2003101500;  // The current module version (Date: YYYYMMDDXX)
+$module->version  = 2003101501;  // The current module version (Date: YYYYMMDDXX)
 $module->cron     = 0;           // Period for cron to check this module (secs)
 
 $release = "0.5 development";   // User-friendly version number