From: willcast Allow comments on entries You can specify if the system should or should not allow comments on glossary entries.
+
diff --git a/mod/glossary/backuplib.php b/mod/glossary/backuplib.php
index 9a406ab200..1ab0e729b2 100644
--- a/mod/glossary/backuplib.php
+++ b/mod/glossary/backuplib.php
@@ -11,6 +11,12 @@
// | |
// 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));
}
@@ -134,7 +144,26 @@
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)
@@ -151,7 +180,6 @@
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
index 0000000000..0dd9874c06
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
index 0000000000..737642670e
--- /dev/null
+++ b/mod/glossary/comment.html
@@ -0,0 +1,68 @@
+
+
'; + echo $glossary->intro; + echo '
'; + print_simple_box_end(); + } + + echo ""; + echo "
"; + echo "$entry->concept"; + echo " | |
";
+ if ($entry->attachment) {
+ $entry->course = $course->id;
+ echo "
| ";
+ echo "
"; + +/// Input section + if ( $action == "delete" ) { + if ( $confirm ) { + delete_records("glossary_comments","id", $cid); + + print_simple_box_start("center","40%", "#FFBBBB"); + echo "
"; + echo "
cellheading\">";
+
+ $user = get_record("user", "id", $comment->userid);
+ $strby = get_string("writtenby","glossary");
+
+ print_user_picture($user->id, $course->id, $user->picture);
+ echo " $strby $user->firstname $user->lastname"; + echo " (".get_string("lastedited").": ".userdate($comment->timemodified).")"; + + echo " | cellcontent\">"; + echo format_text($comment->comment, $comment->format); + echo " |
"; + + print_simple_box_start("center","40%", "#FFBBBB"); + echo "
'; + echo $glossary->intro; + echo '
'; + print_simple_box_end(); + } + + echo ""; + echo "
";
+ echo "
| |||
";
+ if ($entry->attachment) {
+ $entry->course = $course->id;
+ echo "
| ";
+ echo "
" . get_string("nocomments","glossary") . "";
+ } else {
+ foreach ($comments as $comment) {
+ echo " ";
+ glossary_print_comment($course, $cm, $glossary, $entry, $comment);
+ }
+ }
+
+/// Finish the page
+ print_footer($course);
+?>
\ No newline at end of file
diff --git a/mod/glossary/db/mysql.php b/mod/glossary/db/mysql.php
index 17a69aeb7e..ac24cb0a97 100644
--- a/mod/glossary/db/mysql.php
+++ b/mod/glossary/db/mysql.php
@@ -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;
}
diff --git a/mod/glossary/db/mysql.sql b/mod/glossary/db/mysql.sql
index d6196acb98..e7d3696045 100644
--- a/mod/glossary/db/mysql.sql
+++ b/mod/glossary/db/mysql.sql
@@ -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');
diff --git a/mod/glossary/db/postgres7.sql b/mod/glossary/db/postgres7.sql
index 0c1746c09c..310a4ca3d5 100644
--- a/mod/glossary/db/postgres7.sql
+++ b/mod/glossary/db/postgres7.sql
@@ -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');
diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php
index a0096525ef..08279b094d 100644
--- a/mod/glossary/lib.php
+++ b/mod/glossary/lib.php
@@ -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 " ";
- // 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 " ";
+ if ( (time() - $comment->timemodified < $CFG->maxeditingtime and $USER->id == $comment->userid) or isteacher($course->id) ) {
+ echo "id&eid=$entry->id&cid=$comment->id&action=edit\"> :
";
}
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 "link . "\">";
}
- if ( !$data[$tabproccessed]->link ) {
- echo "";
- }
+ if ( !$data[$tabproccessed]->link ) {
+ echo "";
+ }
echo $data[$tabproccessed]->caption;
- if ( !$data[$tabproccessed]->link ) {
- echo "";
- }
+ if ( !$data[$tabproccessed]->link ) {
+ echo "";
+ }
if ($tabproccessed != $currenttab and $data[$tabproccessed]->link) {
echo "";
@@ -615,13 +625,13 @@ for ($row = 0; $row < $numrows; $row++) {
echo "link . "\">";
}
- if ( !$data[$tabproccessed]->link ) {
- echo "";
- }
+ if ( !$data[$tabproccessed]->link ) {
+ echo "";
+ }
echo $data[$tabproccessed]->caption;
- if ( !$data[$tabproccessed]->link ) {
- echo "";
- }
+ if ( !$data[$tabproccessed]->link ) {
+ echo "";
+ }
if ($tabproccessed != $currenttab and $data[$tabproccessed]->link) {
echo "";
@@ -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 "";
+
+ $count = count_records("glossary_comments","entryid",$entry->id);
+ echo "id&eid=$entry->id\">$count " . get_string("comments","glossary") . "";
+ echo " ";
+ if ( $glossary->allowcomments ) {
+ echo "id&eid=$entry->id\"> ";
+ }
+
+ 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 "id&entry=$entry->id¤tview=$currentview&cat=$cat\">
";
- }
- }
-
+ }
+ }
+
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 "id&mode=delete&entry=$entry->id¤tview=$currentview&cat=$cat\">
" . get_string("exportedentry","glossary") . "";
}
- }
+ }
+ echo "
";
+}
+
?>
diff --git a/mod/glossary/mod.html b/mod/glossary/mod.html
index ca0238dff0..3da3f7ab59 100644
--- a/mod/glossary/mod.html
+++ b/mod/glossary/mod.html
@@ -93,6 +93,25 @@ if (!$mainglossary or $mainglossary->id == $form->instance ) {
+";
+
+ echo "\n
\n";
+
+ echo "";
+
+ echo "\n cellheading\" WIDTH=25% VALIGN=TOP align=right >";
+ print_user_picture($user->id, $course->id, $user->picture);
+ echo " ";
+
+ echo "
$strby $user->firstname $user->lastname";
+ echo "
(".get_string("lastedited").": ".userdate($comment->timemodified).")
";
+ echo "cellcontent\">";
+ if ($comment) {
+ echo format_text($comment->comment, $comment->format);
+ } else {
+ echo " ";
+
+ echo " ";
+ }
+ if ( $USER->id == $comment->userid or isteacher($course->id) ) {
+ echo "id&eid=$entry->id&cid=$comment->id&action=delete\">
";
+ }
+ echo "
+
+
+
+
+
diff --git a/mod/glossary/restorelib.php b/mod/glossary/restorelib.php
index 085ed792ea..274fbb947f 100644
--- a/mod/glossary/restorelib.php
+++ b/mod/glossary/restorelib.php
@@ -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']['#']);
@@ -115,7 +116,6 @@
$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) {
diff --git a/mod/glossary/version.php b/mod/glossary/version.php
index de38c6f75f..1f92564c72 100644
--- a/mod/glossary/version.php
+++ b/mod/glossary/version.php
@@ -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