From e0a0a1146b14678142468d4ed1cd27544705766d Mon Sep 17 00:00:00 2001 From: moodler Date: Mon, 6 Oct 2003 12:00:28 +0000 Subject: [PATCH] Moving Dialogue into the main tree for convenience. --- lang/en/dialogue.php | 68 ++ lang/en/help/dialogue/closedialogue.html | 13 + lang/en/help/dialogue/deleteafter.html | 7 + lang/en/help/dialogue/dialoguetype.html | 17 + lang/en/help/dialogue/info.html | 20 + lang/en/help/dialogue/maildefault.html | 7 + lang/en/help/dialogue/mods.html | 8 + lang/en/help/dialogue/multiple.html | 10 + lang/en/help/dialogue/writing.html | 18 + mod/dialogue/README.txt | 2 + mod/dialogue/backuplib.php | 184 ++++ mod/dialogue/db/mysql.php | 16 + mod/dialogue/db/mysql.sql | 77 ++ mod/dialogue/dialogues.php | 212 +++++ mod/dialogue/edit.html | 46 + mod/dialogue/edit.php | 96 ++ mod/dialogue/icon.gif | Bin 0 -> 206 bytes mod/dialogue/index.php | 53 ++ mod/dialogue/lib.php | 1111 ++++++++++++++++++++++ mod/dialogue/mod.html | 116 +++ mod/dialogue/restorelib.php | 225 +++++ mod/dialogue/version.php | 11 + mod/dialogue/view.php | 173 ++++ 23 files changed, 2490 insertions(+) create mode 100644 lang/en/dialogue.php create mode 100644 lang/en/help/dialogue/closedialogue.html create mode 100644 lang/en/help/dialogue/deleteafter.html create mode 100644 lang/en/help/dialogue/dialoguetype.html create mode 100644 lang/en/help/dialogue/info.html create mode 100644 lang/en/help/dialogue/maildefault.html create mode 100644 lang/en/help/dialogue/mods.html create mode 100644 lang/en/help/dialogue/multiple.html create mode 100644 lang/en/help/dialogue/writing.html create mode 100644 mod/dialogue/README.txt create mode 100644 mod/dialogue/backuplib.php create mode 100644 mod/dialogue/db/mysql.php create mode 100644 mod/dialogue/db/mysql.sql create mode 100644 mod/dialogue/dialogues.php create mode 100644 mod/dialogue/edit.html create mode 100644 mod/dialogue/edit.php create mode 100755 mod/dialogue/icon.gif create mode 100644 mod/dialogue/index.php create mode 100644 mod/dialogue/lib.php create mode 100644 mod/dialogue/mod.html create mode 100644 mod/dialogue/restorelib.php create mode 100644 mod/dialogue/version.php create mode 100644 mod/dialogue/view.php diff --git a/lang/en/dialogue.php b/lang/en/dialogue.php new file mode 100644 index 0000000000..f4da37ddd1 --- /dev/null +++ b/lang/en/dialogue.php @@ -0,0 +1,68 @@ +
Are you sure you want to close this dialogue?"; +$string['close'] = "Close"; +$string['closed'] = "Closed"; +$string['deleteafter'] = "Delete Closed Dialogues after (Days)"; +$string['dialogueclosed'] = "Dialogue Closed"; +$string['dialogueintro'] = "Dialogue Introduction"; +$string['dialoguemail'] = "\$a->userfrom has posted a new entry in your +dialogue entry for '\$a->dialogue' + +You can see it appended to your dialogue entry: + + \$a->url"; +$string['dialoguemailhtml'] = "\$a->userfrom has posted a new entry in your +dialogue entry for '\$a->dialogue'

+You can see it appended to your url\\\">dialogue."; +$string['dialoguename'] = "Dialogue name"; + +$string['dialogueopened'] = "Dialogue opened with \$a"; +$string['dialoguewith'] = "Dialogue with \$a"; +$string['of'] = "of"; +$string['everybody'] = "Everybody"; +$string['open'] = "Open"; +$string['lastentry'] = "Last Entry"; +$string['maildefault'] = "Mail Default"; +$string['namehascloseddialogue'] = "\$a has closed dialogue"; +$string['newdialogueentries'] = "New dialogue entries"; +$string['newentry'] = "New Entry"; +$string['noavailablepeople'] = "There is no one available to have a Dialogue with."; +$string['nopersonchosen'] = "No Person Chosen"; +$string['notextentered'] = "No Text Entered"; +$string['notstarted'] = "You have not started this dialogue yet"; +$string['numberofentries'] = "Number of entries"; +$string['numberofentriesadded'] = "Number of entries added: \$a"; +$string['onwrote'] = "On \$a wrote"; +$string['onyouwrote'] = "On \$a you wrote"; +$string['open'] = "Open"; +$string['openadialoguewith'] = "Open a Dialogue with"; +$string['opendialogue'] = "Open Dialogue"; +$string['pane0'] = "Open a Dialogue"; +$string['pane1'] = "\$a Dialogues awaiting Replies from you"; +$string['pane1one'] = "1 Dialogue awaiting a Reply from you"; +$string['pane2'] = "\$a Dialogues awaiting Replies from the other person"; +$string['pane2one'] = "1 Dialogue awaiting a Reply from the other person"; +$string['pane3'] = "\$a Closed Dialogues"; +$string['pane3one'] = "1 Closed Dialogue"; +$string['sendmailmessages'] = "Send Mail Messages about my new entries"; +$string['status'] = "Status"; +$string['studenttostudent'] = "Student to Student"; +$string['subject'] = "Subject"; +$string['teachertostudent'] = "Teacher to Student"; +$string['typefirstentry'] = "Type the first entry here"; +$string['typefollowup'] = "Type follow-up here"; +$string['typeofdialogue'] = "Type of Dialogue"; +$string['typereply'] = "Type reply here"; +$string['viewallentries'] = "View \$a Dialogue entries"; + +?> diff --git a/lang/en/help/dialogue/closedialogue.html b/lang/en/help/dialogue/closedialogue.html new file mode 100644 index 0000000000..aae4554159 --- /dev/null +++ b/lang/en/help/dialogue/closedialogue.html @@ -0,0 +1,13 @@ +

Closing Dialogues

+

You can close a dialogue at any time. Closing a dialogue + stops the dialogue and removes it from your current list of dialogues. That is, + closed dialogues do not appear on this page.

+ +

You will be able to view closed dialogues but you can not add to them. + However, closed dialogues are eventually deleted and after that point they + obviously will not be available even for viewing.

+ +

If you do close this dialogue, then you will have to start a new dialogue + if you want to continue to "talk" with this person. That person + will re-appear in the list of people you can start dialogues with.

+ diff --git a/lang/en/help/dialogue/deleteafter.html b/lang/en/help/dialogue/deleteafter.html new file mode 100644 index 0000000000..0e7ef00ee6 --- /dev/null +++ b/lang/en/help/dialogue/deleteafter.html @@ -0,0 +1,7 @@ +

Deletion of Dialogues

+

This option sets the time interval in days for the deletion of + dialogues. It only applies to CLOSED dialogues.

+ +

If the time period is set to zero then dialogues are never +deleted.

+ diff --git a/lang/en/help/dialogue/dialoguetype.html b/lang/en/help/dialogue/dialoguetype.html new file mode 100644 index 0000000000..722dc283ba --- /dev/null +++ b/lang/en/help/dialogue/dialoguetype.html @@ -0,0 +1,17 @@ +

Dialogue Types

+

There are three types of Dialogues.

+ +
  1. Teacher to Student This allows dialogues between + teachers and students. Dialogues can be started by either + teachers or students. In the lists of people, teachers only + see students and students only see teachers.

  2. + +
  3. Student to Student This allows dialogues between + students. Teachers are not included at all in this type of + dialogue

  4. + +
  5. Everybody This allows everybody in the Class to + start a dialogue with anybody else. Teachers can start + dialogues with other teachers and students, students can start + dialogues with other students and teachers.

  6. +
diff --git a/lang/en/help/dialogue/info.html b/lang/en/help/dialogue/info.html new file mode 100644 index 0000000000..586e5fea8e --- /dev/null +++ b/lang/en/help/dialogue/info.html @@ -0,0 +1,20 @@ + Dialogues

+ +

This module provides a simple communication method between pairs of users. + A teacher can open an dialogue with a student, a student can open + a dialogue with a teacher, and (optionally) a student can open a + dialogue with another student. A teacher or student can be involved + in many on-going dialogues at any time.

+ +

A dialogue can have an unlimited number of entries, normally the + "conversation" takes place as a set of interleaved + replies. This format is not enforced and either party can add to the + dialogue at any time.

+ +

A dialogue can be closed by either party at any time. Closed dialogues + cannot be reopened. However, a closed + dialogue can be viewed by either party provided it is still in existence...

+ +

...The module deletes closed dialogues and all their entries after a + certain time. That time is set here when the Dialogue is created.

+ diff --git a/lang/en/help/dialogue/maildefault.html b/lang/en/help/dialogue/maildefault.html new file mode 100644 index 0000000000..9f19b3c3f1 --- /dev/null +++ b/lang/en/help/dialogue/maildefault.html @@ -0,0 +1,7 @@ +

Set Mail Default

+

This sets the default value for the "Send this message + by email" option when adding a new entry. If this option + is set to "Yes" then the sent mail box will be checked. + Otherwise the send mail box will not be checked. +

+ diff --git a/lang/en/help/dialogue/mods.html b/lang/en/help/dialogue/mods.html new file mode 100644 index 0000000000..43c3800db3 --- /dev/null +++ b/lang/en/help/dialogue/mods.html @@ -0,0 +1,8 @@ +

 Dialogues

+ diff --git a/lang/en/help/dialogue/multiple.html b/lang/en/help/dialogue/multiple.html new file mode 100644 index 0000000000..9997acd5c5 --- /dev/null +++ b/lang/en/help/dialogue/multiple.html @@ -0,0 +1,10 @@ +

Multiple Dialogues

+ +

This option allows a person to start more than one dialogue with + someone else. The default is No, which only allows one (open) + dialogue between two people.

+ +

Allowing multiple dialogues may result in an abuse of this + facility. Some people may be "pestered" by others + opening many unwanted dialogues with them.

+ diff --git a/lang/en/help/dialogue/writing.html b/lang/en/help/dialogue/writing.html new file mode 100644 index 0000000000..f453f31d97 --- /dev/null +++ b/lang/en/help/dialogue/writing.html @@ -0,0 +1,18 @@ +

Writing

+ +

When writing text for others to read, try and write directly to your audience.

+ +

Explain your ideas as clearly and simply as you can to help avoid misunderstandings. + One thing you can do is to avoid long words when a short one will do.

+ +

In a dialogue it will really help to keep your posts short and on-topic. + You can always close a dialogue and start another one if you want to start + discussing something else. + +

When replying to others, try and think of interesting questions you + can ask them. This will help both you and the other person think (and learn!) + about the subject you are discussing.

+ + +

More info about asking questions

+

More info about reading

diff --git a/mod/dialogue/README.txt b/mod/dialogue/README.txt new file mode 100644 index 0000000000..77c4f90a6b --- /dev/null +++ b/mod/dialogue/README.txt @@ -0,0 +1,2 @@ +By Ray Kingdon +-------------- diff --git a/mod/dialogue/backuplib.php b/mod/dialogue/backuplib.php new file mode 100644 index 0000000000..f389ed2a9b --- /dev/null +++ b/mod/dialogue/backuplib.php @@ -0,0 +1,184 @@ +id) + // | + // | + // | + // dialogue_conversations + // (UL,pk->id, fk->dialogueid) + // | + // | + // | + // dialogue_entries + // (UL,pk->id, fk->dialogueid,conversationid) + // + // Meaning: pk->primary key field of the table + // fk->foreign key to link with parent + // nt->nested field (recursive data) + // CL->course level info + // UL->user level info + // files->table may have files) + // + //----------------------------------------------------------- + + function dialogue_backup_mods($bf,$preferences) { + + global $CFG; + + $status = true; + + //Iterate over dialogue table + $dialogues = get_records ("dialogue","course",$preferences->backup_course,"id"); + if ($dialogues) { + foreach ($dialogues as $dialogue) { + //Start mod + fwrite ($bf,start_tag("MOD",3,true)); + //Print dialogue data + fwrite ($bf,full_tag("ID",4,false,$dialogue->id)); + fwrite ($bf,full_tag("MODTYPE",4,false,"dialogue")); + fwrite ($bf,full_tag("NAME",4,false,$dialogue->name)); + fwrite ($bf,full_tag("INTRO",4,false,$dialogue->intro)); + fwrite ($bf,full_tag("DELETEAFTER",4,false,$dialogue->deleteafter)); + fwrite ($bf,full_tag("DIALOGUETYPE",4,false,$dialogue->dialoguetype)); + fwrite ($bf,full_tag("MULTIPLECONVERSATIONS",4,false,$dialogue->multipleconversations)); + fwrite ($bf,full_tag("MAILDEFAULT",4,false,$dialogue->maildefault)); + fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$dialogue->timemodified)); + + //if we've selected to backup users info, then execute backup_dialogue_conversations + if ($preferences->mods["dialogue"]->userinfo) { + $status = backup_dialogue_conversations($bf,$preferences,$dialogue->id); + } + //End mod + $status =fwrite ($bf,end_tag("MOD",3,true)); + } + } + return $status; + } + + //Backup dialogue_conversations contents (executed from dialogue_backup_mods) + function backup_dialogue_conversations ($bf,$preferences,$dialogue) { + + global $CFG; + + $status = true; + + $dialogue_conversations = get_records("dialogue_conversations","dialogue",$dialogue,"id"); + //If there is conversationss + if ($dialogue_conversations) { + //Write start tag + $status =fwrite ($bf,start_tag("CONVERSATIONS",4,true)); + //Iterate over each entry + foreach ($dialogue_conversations as $conversation) { + //Start entry + $status =fwrite ($bf,start_tag("CONVERSATION",5,true)); + //Print dialogue_entries contents + fwrite ($bf,full_tag("ID",6,false,$conversation->id)); + fwrite ($bf,full_tag("USERID",6,false,$conversation->userid)); + fwrite ($bf,full_tag("RECIPIENTID",6,false,$conversation->recipientid)); + fwrite ($bf,full_tag("LASTID",6,false,$conversation->lastid)); + fwrite ($bf,full_tag("TIMEMODIFIED",6,false,$conversation->timemodified)); + fwrite ($bf,full_tag("CLOSED",6,false,$conversation->closed)); + fwrite ($bf,full_tag("CTYPE",6,false,$conversation->ctype)); + fwrite ($bf,full_tag("FORMAT",6,false,$conversation->format)); + fwrite ($bf,full_tag("SUBJECT",6,false,$conversation->subject)); + //End entry + $status =fwrite ($bf,end_tag("CONVERSATION",5,true)); + } + //if we've selected to backup users info, then execute backup_dialogue_entries + if ($preferences->mods["dialogue"]->userinfo) { + $status = backup_dialogue_entries($bf,$preferences,$conversation->id); + } + + //Write end tag + $status =fwrite ($bf,end_tag("CONVERSATIONS",4,true)); + } + return $status; + } + + //Backup dialogue_entries contents (executed from dialogue_backup_mods) + function backup_dialogue_entries ($bf,$preferences,$conversationid) { + + global $CFG; + + $status = true; + + $dialogue_entries = get_records("dialogue_entries","conversationid",$conservationid,"id"); + //If there is entries + if ($dialogue_entries) { + //Write start tag + $status =fwrite ($bf,start_tag("ENTRIES",4,true)); + //Iterate over each entry + foreach ($dialogue_entries as $entry) { + //Start entry + $status =fwrite ($bf,start_tag("ENTRY",5,true)); + //Print dialogue_entries contents + fwrite ($bf,full_tag("ID",6,false,$entry->id)); + fwrite ($bf,full_tag("USERID",6,false,$entry->userid)); + fwrite ($bf,full_tag("TIMECREATED",6,false,$entry->modified)); + fwrite ($bf,full_tag("MAILED",6,false,$entry->text)); + fwrite ($bf,full_tag("TEXT",6,false,$entry->format)); + //End entry + $status =fwrite ($bf,end_tag("ENTRY",5,true)); + } + //Write end tag + $status =fwrite ($bf,end_tag("ENTRIES",4,true)); + } + return $status; + } + + ////Return an array of info (name,value) + function dialogue_check_backup_mods($course,$user_data=false,$backup_unique_code) { + //First the course data + $info[0][0] = get_string("modulenameplural","dialogue"); + if ($ids = dialogue_ids ($course)) { + $info[0][1] = count($ids); + } else { + $info[0][1] = 0; + } + + //Now, if requested, the user_data + if ($user_data) { + $info[1][0] = get_string("entries","dialogue"); + if ($ids = dialogue_entry_ids_by_course ($course)) { + $info[1][1] = count($ids); + } else { + $info[1][1] = 0; + } + } + return $info; + } + + + + + + + // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE + + //Returns an array of dialogues id + function dialogue_ids ($course) { + + global $CFG; + + return get_records_sql ("SELECT a.id, a.course + FROM {$CFG->prefix}dialogue a + WHERE a.course = '$course'"); + } + + //Returns an array of dialogue entries id + function dialogue_entry_ids_by_course ($course) { + + global $CFG; + + return get_records_sql ("SELECT s.id , s.dialogue + FROM {$CFG->prefix}dialogue_entries s, + {$CFG->prefix}dialogue a + WHERE a.course = '$course' AND + s.dialogue = a.id"); + } +?> diff --git a/mod/dialogue/db/mysql.php b/mod/dialogue/db/mysql.php new file mode 100644 index 0000000000..ca351c2b94 --- /dev/null +++ b/mod/dialogue/db/mysql.php @@ -0,0 +1,16 @@ +prefix}dialogue` ADD `multipleconversations` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER `dialoguetype`"); + execute_sql(" ALTER TABLE `{$CFG->prefix}dialogue_conversations` ADD `subject` VARCHAR(100) NOT NULL DEFAULT ''"); + } + + $result = true; + return $result; +} diff --git a/mod/dialogue/db/mysql.sql b/mod/dialogue/db/mysql.sql new file mode 100644 index 0000000000..1c2407983f --- /dev/null +++ b/mod/dialogue/db/mysql.sql @@ -0,0 +1,77 @@ +# +# A note on the naming convention used in this module: +# +# As a Dialogue instance can have a number of Dialogues +# the fact that a course can have more than one Dialogue +# instance complicates the nomenclature within the code. +# We want to easily refer to dialogues within dialogues. +# +# For this reason a Dialogue instance is said to have +# a set of Conversations (not dialogues). So the code +# (and the table structure here) uses conversations +# within dialogues. The term "conversation" is just an +# INTERNAL name and it is NOT used in the user +# interface. There is NO need to distinguish between +# dialogue instances and a set of dialogues within one +# dialogue instance from the point of view of teachers +# or students point of view. + +# +# Table structure for table `dialogue` +# + +CREATE TABLE prefix_dialogue ( + id int(10) unsigned NOT NULL auto_increment, + course int(10) unsigned NOT NULL default '0', + deleteafter smallint(5) unsigned NOT NULL default '14', + dialoguetype tinyint(3) NOT NULL default '0', + multipleconversations tinyint(3) NOT NULL default '0', + maildefault tinyint(3) NOT NULL default '0', + timemodified int(10) unsigned NOT NULL default '0', + name varchar(255) default NULL, + intro text, + PRIMARY KEY (id) +) TYPE=MyISAM; +# -------------------------------------------------------- + +# +# Table structure for table `dialogue_conversations` (Virtual Conversations) +# + +CREATE TABLE prefix_dialogue_conversations ( + id int(10) unsigned NOT NULL auto_increment, + dialogueid int(10) unsigned NOT NULL default '0', + userid int(10) unsigned NOT NULL default '0', + recipientid int(10) unsigned NOT NULL default '0', + lastid int(10) unsigned NOT NULL default '0', + timemodified int(10) unsigned NOT NULL default '0', + closed tinyint(3) NOT NULL default '0', + ctype tinyint(3) NOT NULL default '0', + format tinyint(2) NOT NULL default '0', + subject varchar(100) not null default '', + PRIMARY KEY (id), + KEY (dialogueid), + KEY (timemodified) +) TYPE=MyISAM COMMENT='All the conversations between pairs of people'; + +# +# Table structure for table `dialogue_entries` +# + +CREATE TABLE prefix_dialogue_entries ( + id int(10) unsigned NOT NULL auto_increment, + dialogueid int(10) unsigned NOT NULL default '0', + conversationid int(10) unsigned NOT NULL default '0', + userid int(10) unsigned NOT NULL default '0', + timecreated int(10) unsigned NOT NULL default '0', + mailed int(1) unsigned NOT NULL default '0', + text text NOT NULL, + PRIMARY KEY (id), + KEY (conversationid) +) TYPE=MyISAM COMMENT='All the conversation entries'; + +# +# Data for the table `log_display` +# + +INSERT INTO prefix_log_display VALUES ('dialogue', 'view', 'dialogue', 'name'); diff --git a/mod/dialogue/dialogues.php b/mod/dialogue/dialogues.php new file mode 100644 index 0000000000..6e005cf459 --- /dev/null +++ b/mod/dialogue/dialogues.php @@ -0,0 +1,212 @@ +course)) { + error("Course is misconfigured"); + } + + require_login($course->id); + + if (! $dialogue = get_record("dialogue", "id", $cm->instance)) { + error("Course module dialogue is incorrect"); + } + + require_login($course->id); + + $navigation = ""; + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + + $strdialogues = get_string("modulenameplural", "dialogue"); + $strdialogue = get_string("modulename", "dialogue"); + + // ... print the header and... + print_header("$course->shortname: $dialogue->name", "$course->fullname", + "$navigation id>$strdialogues -> + id\">$dialogue->name", + "", "", true); + + + require_variable($action); // need something to do! + + /************** close conversation ************************************/ + if ($action == 'closeconversation') { + if (empty($_GET['cid'])) { + error("Close dialogue: Missing conversation id"); + } + else { + $conversationid = $_GET['cid']; + } + if (!set_field("dialogue_conversations", "closed", 1, "id", $conversationid)) { + error("Close dialogue: unable to set closed"); + } + if (!set_field("dialogue_conversations", "lastid", $USER->id, "id", $conversationid)) { + error("Close dialogue: unable to set lastid"); + } + $pane=$_GET['pane']; + + add_to_log($course->id, "dialogue", "closed", "view.php?id=$cm->id", "$conversationid"); + redirect("view.php?id=$cm->id&pane=$pane", get_string("dialogueclosed", "dialogue")); + } + + + /****************** confirm close ************************************/ + elseif ($action == 'confirmclose' ) { + + if (empty($_GET['cid'])) { + error("Confirm Close: conversation id missing"); + } + if (!$conversation = get_record("dialogue_conversations", "id", $_GET['cid'])) { + error("Confirm close: cannot get conversation record"); + } + if ($conversation->userid == $USER->id) { + if (!$user = get_record("user", "id", $conversation->recipientid)) { + error("Confirm Close: cannot get recipient record"); + } + } + else { + if (!$user = get_record("user", "id", $conversation->userid)) { + error("Confirm Close: cannot get user record"); + } + } + $pane = $_GET['pane']; + notice_yesno(get_string("confirmclosure", "dialogue", "$user->firstname $user->lastname"), + "dialogues.php?action=closeconversation&id=$cm->id&cid=$conversation->id&pane=$pane", + "view.php?id=$cm->id&pane=$pane"); + } + + + /****************** insert conversation entries ******************************/ + elseif ($action == 'insertentries' ) { + + $timenow = time(); + $n = 0; + // get all the open conversations for this user + if ($conversations = dialogue_get_conversations($dialogue, $USER, "closed = 0")) { + foreach ($conversations as $conversation) { + $textarea_name = "reply$conversation->id"; + if (!empty($_POST[$textarea_name])) { + $item->dialogueid = $dialogue->id; + $item->conversationid = $conversation->id; + $item->userid = $USER->id; + $item->timecreated = time(); + // set mailed flag if checkbox is not set + if (empty($_POST['sendthis'])) { + $item->mailed = 1; + } + $item->text = $_POST[$textarea_name]; + if (!$item->id = insert_record("dialogue_entries", $item)) { + error("Insert Entries: Could not insert dialogue record!"); + } + if (!set_field("dialogue_conversations", "lastid", $USER->id, "id", $conversation->id)) { + error("Insert Entries: could not set lastid"); + } + if (!set_field("dialogue_conversations", "timemodified", $timenow, "id", + $conversation->id)) { + error("Insert Entries: could not set lastid"); + } + add_to_log($course->id, "dialogue", "add entry", "view.php?id=$cm->id", "$item->id"); + $n++; + } + } + } + redirect("view.php?id=$cm->id&pane={$_POST['pane']}", get_string("numberofentriesadded", + "dialogue", $n)); + } + + /****************** list closed conversations *********************************/ + elseif ($action == 'listclosed') { + + echo "
\n"; + print_simple_box( text_to_html($dialogue->intro) , "center"); + echo "
"; + + dialogue_list_closed_conversations($dialogue, $USER); + } + + /****************** open conversation ************************************/ + elseif ($action == 'openconversation' ) { + + if ($_POST['recipientid'] == 0) { + redirect("view.php?id=$cm->id", get_string("nopersonchosen", "dialogue")); + } elseif (empty($_POST['firstentry'])) { + redirect("view.php?id=$cm->id", get_string("notextentered", "dialogue")); + } else { + $conversation->dialogueid = $dialogue->id; + $conversation->userid = $USER->id; + $conversation->recipientid = $_POST['recipientid']; + $conversation->lastid = $USER->id; // this USER is adding an entry too + $conversation->timemodified = time(); + $conversation->subject = $_POST['subject']; // may be blank + if (!$conversation->id = insert_record("dialogue_conversations", $conversation)) { + error("Open dialogue: Could not insert dialogue record!"); + } + add_to_log($course->id, "dialogue", "open", "view.php?id=$cm->id", "$dialogue->id"); + + // now add the entry + $entry->dialogueid = $dialogue->id; + $entry->conversationid = $conversation->id; + $entry->userid = $USER->id; + $entry->timecreated = time(); + // set mailed flag if checkbox is not set + if (empty($_POST['sendthis'])) { + $entry->mailed = 1; + } + $entry->text = $_POST['firstentry']; + if (!$entry->id = insert_record("dialogue_entries", $entry)) { + error("Insert Entries: Could not insert dialogue record!"); + } + add_to_log($course->id, "dialogue", "add entry", "view.php?id=$cm->id", "$entry->id"); + + if (!$user = get_record("user", "id", $conversation->recipientid)) { + error("Open dialogue: user record not found"); + } + redirect("view.php?id=$cm->id", get_string("dialogueopened", "dialogue", + "$user->firstname $user->lastname")); + } + } + + + /****************** show dialogue ****************************************/ + elseif ($action == 'showdialogue') { + + if (!$conversation = get_record("dialogue_conversations", "id", $_GET['conversationid'])) { + error("Show Dialogue: can not get conversation record"); + } + + echo "
\n"; + print_simple_box( text_to_html($dialogue->intro) , "center"); + echo "
"; + + dialogue_show_conversation($dialogue, $conversation, $USER); + dialogue_show_other_conversations($dialogue, $conversation); + } + + + /*************** no man's land **************************************/ + else { + error("Fatal Error: Unknown Action: ".$action."\n"); + } + + print_footer($course); + +?> diff --git a/mod/dialogue/edit.html b/mod/dialogue/edit.html new file mode 100644 index 0000000000..a557e0dbe2 --- /dev/null +++ b/mod/dialogue/edit.html @@ -0,0 +1,46 @@ +
action="edit.php"> + + +
+ + "; + helpbutton("writing", get_string("helpwriting"), "moodle", true, true); + echo "
"; + if ($usehtmleditor) { + helpbutton("richtext", get_string("helprichtext"), "moodle", true, true); + } else { + emoticonhelpbutton("theform", "text"); + } + ?> +
+
+
+ +text); ?> + +

+format, ""); + echo ""; + helpbutton("textformat", get_string("helpformatting")); + echo ""; +?> +

+ +

+ +"> +"> +

+
+ + + diff --git a/mod/dialogue/edit.php b/mod/dialogue/edit.php new file mode 100644 index 0000000000..23ca38bc65 --- /dev/null +++ b/mod/dialogue/edit.php @@ -0,0 +1,96 @@ +course)) { + error("Course is misconfigured"); + } + + require_login($course->id); + + if (isguest()) { + error("Guests are not allowed to edit dialogues", $_SERVER["HTTP_REFERER"]); + } + + if (! $dialogue = get_record("dialogue", "id", $cm->instance)) { + error("Course module is incorrect"); + } + + $entry = get_record("dialogue_entries", "userid", $USER->id, "dialogue", $dialogue->id); + + +/// If data submitted, then process and store. + + if ($form = data_submitted()) { + + $timenow = time(); + + $form->text = clean_text($form->text, $form->format); + + if ($entry) { + $newentry->id = $entry->id; + $newentry->text = $form->text; + $newentry->format = $form->format; + $newentry->modified = $timenow; + if (! update_record("dialogue_entries", $newentry)) { + error("Could not update your dialogue"); + } + add_to_log($course->id, "dialogue", "update entry", "view.php?id=$cm->id", "$newentry->id"); + } else { + $newentry->userid = $USER->id; + $newentry->dialogue = $dialogue->id; + $newentry->text = $form->text; + $newentry->format = $form->format; + $newentry->modified = $timenow; + if (! $newentry->id = insert_record("dialogue_entries", $newentry)) { + error("Could not insert a new dialogue entry"); + } + add_to_log($course->id, "dialogue", "add entry", "view.php?id=$cm->id", "$newentry->id"); + } + + redirect("view.php?id=$cm->id"); + die; + } + +/// Otherwise fill and print the form. + + $strdialogue = get_string("modulename", "dialogue"); + $strdialogues = get_string("modulenameplural", "dialogue"); + $stredit = get_string("edit"); + + if ($usehtmleditor = can_use_richtext_editor()) { + $defaultformat = FORMAT_HTML; + $onsubmit = "onsubmit=\"copyrichtext(theform.text);\""; + } else { + $defaultformat = FORMAT_MOODLE; + $onsubmit = ""; + } + + if (empty($entry)) { + $entry->text = ""; + $entry->format = $defaultformat; + } + + print_header("$course->shortname: $dialogue->name", "$course->fullname", + "wwwroot/course/view.php?id=$course->id\">$course->shortname -> + id\">$strdialogues -> + id\">$dialogue->name -> $stredit", "theform.text", + "", true, "", navmenu($course, $cm)); + + echo "
\n"; + + print_simple_box( text_to_html($dialogue->intro) , "center"); + + echo "
"; + + include("edit.html"); + + print_footer($course); + +?> diff --git a/mod/dialogue/icon.gif b/mod/dialogue/icon.gif new file mode 100755 index 0000000000000000000000000000000000000000..a32d346e0c2f58b4da56f05c5eb657ade70f7cd2 GIT binary patch literal 206 zcmZ?wbhEHb6krfwIKsg2{|pcr&rDFPZmZ7 z1_=fokQB&H23Bu{vfh-=xi3uDys=ue{MM#dtgA!k?M|`!zwL&D`<<^T`wwa;YmqzGelQC_T6_?b*tOYX9zG@0{{uHW|#l~ literal 0 HcmV?d00001 diff --git a/mod/dialogue/index.php b/mod/dialogue/index.php new file mode 100644 index 0000000000..2208557bd4 --- /dev/null +++ b/mod/dialogue/index.php @@ -0,0 +1,53 @@ +id); + add_to_log($course->id, "dialogue", "view all", "index.php?id=$course->id", ""); + + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + + $strdialogue = get_string("modulename", "dialogue"); + $strdialogues = get_string("modulenameplural", "dialogue"); + $strname = get_string("name"); + $stropendialogues = get_string("open", "dialogue")." ".$strdialogues; + $strcloseddialogues = get_string("closed", "dialogue")." ".$strdialogues; + + print_header("$course->shortname: $strdialogues", "$course->fullname", "$navigation $strdialogues", + "", "", true, "", navmenu($course)); + + + if (!$dialogues = get_all_instances_in_course("dialogue", $course)) { + notice("There are no dialogues", "../../course/view.php?id=$course->id"); + die; + } + + $timenow = time(); + + $table->head = array ($strname, $stropendialogues, $strcloseddialogues); + $table->align = array ("CENTER", "CENTER", "CENTER"); + + foreach ($dialogues as $dialogue) { + + if (!$cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) { + error("Course Module ID was incorrect"); + } + $table->data[] = array ("id\">$dialogue->name", + dialogue_count_open($dialogue, $USER), dialogue_count_closed($dialogue, $USER)); + } + echo "
"; + print_table($table); + + print_footer($course); + +?> + diff --git a/mod/dialogue/lib.php b/mod/dialogue/lib.php new file mode 100644 index 0000000000..1d2ea6e86c --- /dev/null +++ b/mod/dialogue/lib.php @@ -0,0 +1,1111 @@ + 0, 7 => 7, 14 => 14, 30 => 30, 150 => 150, 365 => 365 ); + + +// STANDARD MODULE FUNCTIONS ///////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_add_instance($dialogue) { +// Given an object containing all the necessary data, +// (defined by the form in mod.html) this function +// will create a new instance and return the id number +// of the new instance. + + $dialogue->timemodified = time(); + + return insert_record("dialogue", $dialogue); +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_cron () { +// Function to be run periodically according to the moodle cron + + global $CFG, $USER; + +// delete any closed conversations which have expired + dialogue_delete_expired_conversations(); + +// Finds all dialogue entries that have yet to be mailed out, and mails them + if ($entries = get_records_select("dialogue_entries", "mailed = '0'")) { + foreach ($entries as $entry) { + + echo "Processing dialogue entry $entry->id\n"; + + if (! $userfrom = get_record("user", "id", "$entry->userid")) { + echo "Could not find user $entry->userid\n"; + continue; + } + // get conversation record + if(!$conversation = get_record("dialogue_conversations", "id", $entry->conversationid)) { + echo "Could not find conversation $entry->conversationid\n"; + } + if ($userfrom->id == $conversation->userid) { + if (!$userto = get_record("user", "id", $conversation->recipientid)) { + echo "Could not find use $conversation->recipientid\n"; + } + } + else { + if (!$userto = get_record("user", "id", $conversation->userid)) { + echo "Could not find use $conversation->userid\n"; + } + } + + $USER->lang = $userto->lang; + + if (! $dialogue = get_record("dialogue", "id", $conversation->dialogueid)) { + echo "Could not find dialogue id $conversation->dialogueid\n"; + continue; + } + if (! $course = get_record("course", "id", "$dialogue->course")) { + echo "Could not find course $dialogue->course\n"; + continue; + } + if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) { + echo "Course Module ID was incorrect\n"; + } + + if (! isstudent($course->id, $userfrom->id) and !isteacher($course->id, $userfrom->id)) { + continue; // Not an active participant + } + if (! isstudent($course->id, $userto->id) and !isteacher($course->id, $userto->id)) { + continue; // Not an active participant + } + + $strdialogues = get_string("modulenameplural", "dialogue"); + $strdialogue = get_string("modulename", "dialogue"); + + unset($dialogueinfo); + $dialogueinfo->userfrom = "$userfrom->firstname $userfrom->lastname"; + $dialogueinfo->dialogue = "$dialogue->name"; + $dialogueinfo->url = "$CFG->wwwroot/mod/dialogue/view.php?id=$cm->id"; + + $postsubject = "$course->shortname: $strdialogues: $dialogue->name: ". + get_string("newentry", "dialogue"); + $posttext = "$course->shortname -> $strdialogues -> $dialogue->name\n"; + $posttext .= "---------------------------------------------------------------------\n"; + $posttext .= get_string("dialoguemail", "dialogue", $dialogueinfo); + $posttext .= "---------------------------------------------------------------------\n"; + if ($userto->mailformat == 1) { // HTML + $posthtml = "

". + "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". + "wwwroot/mod/dialogue/index.php?id=$course->id\">dialogues ->". + "wwwroot/mod/dialogue/view.php?id=$cm->id\">$dialogue->name

"; + $posthtml .= "
"; + $posthtml .= "

".get_string("dialoguemailhtml", "dialogue", $dialogueinfo)."

"; + $posthtml .= "

"; + } else { + $posthtml = ""; + } + + if (! email_to_user($userto, $userfrom, $postsubject, $posttext, $posthtml)) { + echo "Error: dialogue cron: Could not send out mail for id $entry->id to user $userto->id ($userto->email)\n"; + } + if (! set_field("dialogue_entries", "mailed", "1", "id", "$entry->id")) { + echo "Could not update the mailed field for id $entry->id\n"; + } + } + } + + return true; +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_delete_instance($id) { +// Given an ID of an instance of this module, +// this function will permanently delete the instance +// and any data that depends on it. + + if (! $dialogue = get_record("dialogue", "id", $id)) { + return false; + } + + $result = true; + + if (! delete_records("dialogue_conversations", "dialogueid", $dialogue->id)) { + $result = false; + } + + if (! delete_records("dialogue_entries", "dialogueid", $dialogue->id)) { + $result = false; + } + + if (! delete_records("dialogue", "id", $dialogue->id)) { + $result = false; + } + + return $result; + +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_print_recent_activity($course, $isteacher, $timestart) { + global $CFG; + + // have a look for new entries + $addentrycontent = false; + if ($logs = dialogue_get_add_entry_logs($course, $timestart)) { + // got some, see if any belong to a visible module + foreach ($logs as $log) { + // Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->dialogueid; + //Obtain the visible property from the instance + if (instance_is_visible("dialogue",$tempmod)) { + $addentrycontent = true; + break; + } + } + // if we got some "live" ones then output them + if ($addentrycontent) { + $strftimerecent = get_string("strftimerecent"); + print_headline(get_string("newdialogueentries", "dialogue").":"); + foreach ($logs as $log) { + //Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->dialogueid; + //Obtain the visible property from the instance + if (instance_is_visible("dialogue",$tempmod)) { + $date = userdate($log->time, $strftimerecent); + echo "

$date - $log->firstname $log->lastname
"; + echo "\"wwwroot/mod/dialogue/$log->url\">"; + echo "$log->name"; + echo "\"

"; + } + } + } + } + + // have a look for closed conversations + $closedcontent = false; + if ($logs = dialogue_get_closed_logs($course, $timestart)) { + // got some, see if any belong to a visible module + foreach ($logs as $log) { + // Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->dialogueid; + //Obtain the visible property from the instance + if (instance_is_visible("dialogue",$tempmod)) { + $closedcontent = true; + break; + } + } + // if we got some "live" ones then output them + if ($closedcontent) { + $strftimerecent = get_string("strftimerecent"); + print_headline(get_string("modulenameplural", "dialogue").":"); + foreach ($logs as $log) { + //Create a temp valid module structure (only need courseid, moduleid) + $tempmod->course = $course->id; + $tempmod->id = $log->dialogueid; + //Obtain the visible property from the instance + if (instance_is_visible("dialogue",$tempmod)) { + $date = userdate($log->time, $strftimerecent); + echo "

$date - ".get_string("namehascloseddialogue", "dialogue", + "$log->firstname $log->lastname")."
"; + echo "\"wwwroot/mod/dialogue/$log->url\">"; + echo "$log->name"; + echo "\"

"; + } + } + } + } + return $addentrycontent or $closedcontent; +} + + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_update_instance($dialogue) { +// Given an object containing all the necessary data, +// (defined by the form in mod.html) this function +// will update an existing instance with new data. + + $dialogue->timemodified = time(); + $dialogue->id = $dialogue->instance; + + return update_record("dialogue", $dialogue); +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_user_complete($course, $user, $mod, $dialogue) { + + if ($conversations = dialogue_get_conversations($dialogue, $user)) { + print_simple_box_start(); + $table->head = array (get_string("dialoguewith", "dialogue"), + get_string("numberofentries", "dialogue"), get_string("lastentry", "dialogue"), + get_string("status", "dialogue")); + $table->width = "100%"; + $table->align = array ("left", "center", "left", "left"); + $table->size = array ("*", "*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + foreach ($conversations as $conversation) { + if ($user->id != $conversation->userid) { + if (!$with = get_record("user", "id", $conversation->userid)) { + error("User's record not found"); + } + } + else { + if (!$with = get_record("user", "id", $conversation->recipientid)) { + error("User's record not found"); + } + } + $total = dialogue_count_entries($dialogue, $conversation); + $byuser = dialogue_count_entries($dialogue, $conversation, $user); + if ($conversation->closed) { + $status = get_string("closed", "dialogue"); + } else { + $status = get_string("open", "dialogue"); + } + $table->data[] = array("$with->firstname $with->lastname", $byuser." ". + get_string("of", "dialogue")." ".$total, userdate($conversation->timemodified), $status); + } + print_table($table); + print_simple_box_end(); + } + else { + print_string("noentry", "dialogue"); + } +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_user_outline($course, $user, $mod, $dialogue) { + if ($entries = dialogue_get_user_entries($dialogue, $user)) { + $result->info = count($entries); + foreach ($entries as $entry) { + // dialogue_get_user_entries returns the most recent entry first + $result->time = $entry->timecreated; + break; + } + return $result; + } + return NULL; +} + + +// SQL FUNCTIONS /////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_count_closed($dialogue, $user) { + + return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND + (userid = $user->id OR recipientid = $user->id) AND closed = 1"); + } + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_count_entries($dialogue, $conversation, $user = '') { + + if (empty($user)) { + return count_records_select("dialogue_entries", "conversationid = $conversation->id"); + } + else { + return count_records_select("dialogue_entries", "conversationid = $conversation->id AND + userid = $user->id"); + } +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_count_open($dialogue, $user) { + + return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND + (userid = $user->id OR recipientid = $user->id) AND closed = 0"); + } + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_count_needing_replies_other($dialogue, $user) { +// count [conversations] needing replies [from] other [person] + return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND + (userid = $user->id OR recipientid = $user->id) AND lastid = $user->id AND closed = 0"); + } + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_count_needing_replies_self($dialogue, $user) { +// count [conversations] needing replies [from] self + + return count_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND + (userid = $user->id OR recipientid = $user->id) AND lastid != $user->id AND closed = 0"); + } + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_delete_expired_conversations() { + + if ($dialogues = get_records("dialogue")) { + foreach ($dialogues as $dialogue) { + if ($dialogue->deleteafter) { + $expirytime = time() - $dialogue->deleteafter * 86400; + if ($conversations = get_records_select("dialogue_conversations", + "$timemodified < $expirytime AND closed = 1")) { + foreach ($conversations as $conversation) { + delete_records("dialogue_conversations", "id", $conversation->id); + delete_records("dialogue_entries", "conversationid", $conversation->id); + } + } + } + } + } +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_get_available_users($dialogue) { + + if (! $course = get_record("course", "id", $dialogue->course)) { + error("Course is misconfigured"); + } + switch ($dialogue->dialoguetype) { + case 0 : // teacher to student + if (isteacher($course->id)) { + return dialogue_get_available_students($dialogue); + } + else { + return dialogue_get_available_teachers($dialogue); + } + case 1: // student to student + if (isstudent($course->id)) { + return dialogue_get_available_students($dialogue); + } + else { + return; + } + case 2: // everyone + if ($teachers = dialogue_get_available_teachers($dialogue)) { + foreach ($teachers as $userid=>$name) { + $names[$userid] = $name; + } + $names[-1] = "-------------"; + } + if ($students = dialogue_get_available_students($dialogue)) { + foreach ($students as $userid=>$name) { + $names[$userid] = $name; + } + } + if (isset($names)) { + return $names; + } + return; + } +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_get_available_students($dialogue) { +global $USER; + + if (! $course = get_record("course", "id", $dialogue->course)) { + error("Course is misconfigured"); + } + // get the students on this course... + if ($users = get_course_students($course->id, "u.firstname, u.lastname")) { + foreach ($users as $otheruser) { + // ...exclude self and... + if ($USER->id != $otheruser->id) { + // ...any already in any open conversations unless multiple conversations allowed + if ($dialogue->multipleconversations or count_records_select("dialogue_conversations", + "dialogueid = $dialogue->id AND + ((userid = $USER->id AND recipientid = $otheruser->id) OR + (userid = $otheruser->id AND recipientid = $USER->id)) AND closed = 0") == 0) { + $names[$otheruser->id] = "$otheruser->firstname $otheruser->lastname"; + } + } + } + } + if (isset($names)) { + return $names; + } + return; +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_get_available_teachers($dialogue) { +global $USER; + + if (! $course = get_record("course", "id", $dialogue->course)) { + error("Course is misconfigured"); + } + // get the teachers on this course... + if ($users = get_course_teachers($course->id, "u.firstname, u.lastname")) { + // $names[0] = "-----------------------"; + foreach ($users as $otheruser) { + // ...exclude self and ... + if ($USER->id != $otheruser->id) { + // ...any already in open conversations unless multiple conversations allowed + if ($dialogue->multipleconversations or count_records_select("dialogue_conversations", + "dialogueid = $dialogue->id AND ((userid = $USER->id AND + recipientid = $otheruser->id) OR (userid = $otheruser->id AND + recipientid = $USER->id)) AND closed = 0") == 0) { + $names[$otheruser->id] = "$otheruser->firstname $otheruser->lastname"; + } + } + } + } + if (isset($names)) { + return $names; + } + return; +} + + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_get_conversations($dialogue, $user, $condition = '') { + global $CFG; + + if (!empty($condition)) { + return get_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND + (userid = $user->id OR recipientid = $user->id) AND $condition", "timemodified DESC"); + } + else { + return get_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND + (userid = $user->id OR recipientid = $user->id)", "timemodified DESC"); + } +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_get_users_done($dialogue) { + global $CFG; + return get_records_sql("SELECT u.* + FROM {$CFG->prefix}user u, + {$CFG->prefix}user_students s, + {$CFG->prefix}user_teachers t, + {$CFG->prefix}dialogue_entries j + WHERE ((s.course = '$dialogue->course' AND s.userid = u.id) + OR (t.course = '$dialogue->course' AND t.userid = u.id)) + AND u.id = j.userid + AND j.dialogue = '$dialogue->id' + ORDER BY j.modified DESC"); +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_get_user_entries($dialogue, $user) { + global $CFG; + return get_records_select("dialogue_entries", "dialogueid = $dialogue->id AND userid = $user->id", + "timecreated DESC"); +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_get_add_entry_logs($course, $timestart) { + // get the "add entry" entries and add the first and last names, we are not interested in the entries + // make by this user (the last condition)! + global $CFG, $USER; + return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, e.dialogueid, d.name + FROM {$CFG->prefix}log l, + {$CFG->prefix}dialogue d, + {$CFG->prefix}dialogue_conversations c, + {$CFG->prefix}dialogue_entries e, + {$CFG->prefix}user u + WHERE l.time > $timestart AND l.course = $course->id AND l.module = 'dialogue' + AND l.action = 'add entry' + AND e.id = l.info + AND c.id = e.conversationid + AND (c.userid = $USER->id or c.recipientid = $USER->id) + AND d.id = e.dialogueid + AND u.id = e.userid + AND e.userid != $USER->id"); +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_get_closed_logs($course, $timestart) { + // get the "closed" entries and add the first and last names, we are not interested in the entries + // make by this user (the last condition)! + global $CFG, $USER; + return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, c.dialogueid, d.name + FROM {$CFG->prefix}log l, + {$CFG->prefix}dialogue d, + {$CFG->prefix}dialogue_conversations c, + {$CFG->prefix}user u + WHERE l.time > $timestart AND l.course = $course->id AND l.module = 'dialogue' + AND l.action = 'closed' + AND c.id = l.info + AND (c.userid = $USER->id or c.recipientid = $USER->id) + AND d.id = c.dialogueid + AND u.id = c.lastid + AND c.lastid != $USER->id"); +} + + +// OTHER dialogue FUNCTIONS /////////////////////////////////////////////////////////////////// + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_list_conversations_closed($dialogue, $user) { + + if (! $course = get_record("course", "id", $dialogue->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) { + error("Course Module ID was incorrect"); + } + + if ($conversations = dialogue_get_conversations($dialogue, $user, "closed = 1")) { + print_simple_box_start(); + $table->head = array (get_string("dialoguewith", "dialogue"), + get_string("numberofentries", "dialogue"), get_string("lastentry", "dialogue"), + get_string("status", "dialogue")); + $table->width = "100%"; + $table->align = array ("left", "center", "left", "left"); + $table->size = array ("*", "*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; + + foreach ($conversations as $conversation) { + if ($user->id != $conversation->userid) { + if (!$with = get_record("user", "id", $conversation->userid)) { + error("User's record not found"); + } + } + else { + if (!$with = get_record("user", "id", $conversation->recipientid)) { + error("User's record not found"); + } + } + $total = dialogue_count_entries($dialogue, $conversation); + $byuser = dialogue_count_entries($dialogue, $conversation, $user); + if ($conversation->closed) { + $status = get_string("closed", "dialogue"); + } else { + $status = get_string("open", "dialogue"); + } + $table->data[] = array("id&action=showdialogue&conversationid=$conversation->id\">". + "$with->firstname $with->lastname", $byuser." ".get_string("of", "dialogue")." ".$total, + userdate($conversation->timemodified), $status); + } + print_table($table); + print_simple_box_end(); + } + else { + print_string("noentry", "dialogue"); + } +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_list_conversations_other($dialogue, $user) { +// list the conversations awaiting response from the other person + global $THEME; + + if (! $course = get_record("course", "id", $dialogue->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) { + error("Course Module ID was incorrect"); + } + + $timenow = time(); + $showbutton = false; + $showemoticon = false; // never show emoticons for now - need to close or reload the popup + // window to get the focus into the correct textarea on the second time round + + echo "
\n"; + echo "\n"; + echo "id\">\n"; + echo "\n"; + + if ($conversations = dialogue_get_conversations($dialogue, $user, "lastid = $user->id AND closed = 0")) { + $showbutton = true; + print_simple_box_start("center", "", $THEME->cellcontent2); + foreach ($conversations as $conversation) { + echo "
\n"; + echo ""; + echo "\n"; + + if ($entries = get_records_select("dialogue_entries", "conversationid = $conversation->id", "id")) { + foreach ($entries as $entry) { + if ($entry->userid == $user->id) { + echo "\n"; + } + echo "\n"; + echo ""; + echo "
cellheading2\" valign=\"top\">\n"; + if ($conversation->userid == $user->id) { + if (!$otheruser = get_record("user", "id", $conversation->recipientid)) { + error("User not found"); + } + } + else { + if (!$otheruser = get_record("user", "id", $conversation->userid)) { + error("User not found"); + } + } + // print_user_picture($user->id, $course->id, $user->picture); + echo "".get_string("dialoguewith", "dialogue", "$otheruser->firstname $otheruser->lastname"). + "cellheading2\">$conversation->subject 
\n"; + echo "
\n"; + echo "id&cid=$conversation->id&pane=2\">". + get_string("close", "dialogue")."\n"; + helpbutton("closedialogue", get_string("close", "dialogue"), "dialogue"); + echo "
\n"; + echo text_to_html("".get_string("onyouwrote", "dialogue", + userdate($entry->timecreated)).":
".$entry->text); + } + else { + echo "
body\">\n"; + echo text_to_html("".get_string("onwrote", "dialogue", + userdate($entry->timecreated)." ".$otheruser->firstname).":
". + $entry->text); + } + } + echo "
". + get_string("typefollowup", "dialogue")."
\n"; + helpbutton("writing", get_string("helpwriting"), "dialogue", true, true); + echo "
"; + if ($showemoticon) { + emoticonhelpbutton("replies", "reply$conversation->id"); + $showemoticon = false; + } + echo "
\n"; + // use a cumbersome name on the textarea as the emoticonhelp doesn't like an "array" name + echo "\n"; + echo "

\n"; + } + print_simple_box_end(); + } + if ($showbutton) { + echo "
\n"; + echo "".get_string("sendmailmessages", "dialogue").": \n"; + if ($dialogue->maildefault) { + echo "\n"; + } + else { + echo "\n"; + } + echo "
\n"; + } + echo "
\n"; +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_list_conversations_self($dialogue, $user) { + global $THEME; + + if (! $course = get_record("course", "id", $dialogue->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) { + error("Course Module ID was incorrect"); + } + + $timenow = time(); + $showbutton = false; + $showemoticon = false; // never show emoticons for now - need to close or reload the popup + // window to get the focus into the correct textarea on the second time round + + echo "
\n"; + echo "\n"; + echo "id\">\n"; + echo "\n"; + + // first the ones requiring a resonse from the user + if ($conversations = dialogue_get_conversations($dialogue, $user, "lastid != $user->id AND closed = 0")) { + $showbutton = true; + print_simple_box_start("center"); + foreach ($conversations as $conversation) { + echo "
\n"; + echo ""; + echo ""; + + if ($entries = get_records_select("dialogue_entries", "conversationid = $conversation->id", "id")) { + foreach ($entries as $entry) { + if ($entry->userid == $user->id) { + echo "\n"; + } + else { + echo "\n"; + } + } + } + + echo "\n"; + echo ""; + echo "
cellheading2\" valign=\"top\">\n"; + if ($conversation->userid == $user->id) { + if (!$otheruser = get_record("user", "id", $conversation->recipientid)) { + error("User not found"); + } + } + else { + if (!$otheruser = get_record("user", "id", $conversation->userid)) { + error("User not found"); + } + } + // print_user_picture($user->id, $course->id, $user->picture); + echo "".get_string("dialoguewith", "dialogue", "$otheruser->firstname $otheruser->lastname"). + "cellheading2\">$conversation->subject 
\n"; + echo "
\n"; + if (dialogue_count_entries($dialogue, $conversation)) { + echo "id&cid=$conversation->id&pane=1\">". + get_string("close", "dialogue")."\n"; + helpbutton("closedialogue", get_string("close", "dialogue"), "dialogue"); + } + else { + echo " "; + } + echo "
\n"; + echo text_to_html("".get_string("onyouwrote", "dialogue", + userdate($entry->timecreated)).":
".$entry->text); + echo "
body\">\n"; + echo text_to_html("".get_string("onwrote", "dialogue", + userdate($entry->timecreated)." ".$otheruser->firstname). + ":
".$entry->text); + echo "
\n"; + if ($entries) { + echo "".get_string("typereply", "dialogue")."\n"; + } + else { + echo "".get_string("typefirstentry", "dialogue")."\n"; + } + echo "
\n"; + helpbutton("writing", get_string("helpwriting"), "dialogue", true, true); + echo "
"; + if ($showemoticon) { + emoticonhelpbutton("replies", "reply$conversation->id"); + $showemoticon = false; + } + echo "
\n"; + // use a cumbersome name on the textarea as the emoticonhelp doesn't like an "array" name + echo "\n"; + echo "

\n"; + } + print_simple_box_end(); + if ($showbutton) { + echo "
\n"; + echo "".get_string("sendmailmessages", "dialogue").": \n"; + if ($dialogue->maildefault) { + echo "\n"; + } + else { + echo "\n"; + } + echo "
\n"; + } + echo "
\n"; + } +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_print_feedback($course, $entry, $grades) { + global $CFG, $THEME; + + if (! $teacher = get_record("user", "id", $entry->teacher)) { + error("Weird dialogue error"); + } + + echo "\n
"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo ""; + + echo "\n
body\" WIDTH=35 VALIGN=TOP>"; + print_user_picture($teacher->id, $course->id, $teacher->picture); + echo "cellheading\">$teacher->firstname $teacher->lastname"; + echo "  ".userdate($entry->timemarked).""; + echo "
cellcontent\">"; + + echo "

"; + if ($grades[$entry->rating]) { + echo get_string("grade").": "; + echo $grades[$entry->rating]; + } else { + print_string("nograde"); + } + echo "

"; + + echo text_to_html($entry->comment); + echo "
"; + echo "
"; +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_print_tabbed_heading($tabs) { +// Prints a tabbed heading where one of the tabs highlighted. +// $tabs is an object with several properties. +// $tabs->names is an array of tab names +// $tabs->urls is an array of links +// $tabs->align is an array of column alignments (defaults to "center") +// $tabs->size is an array of column sizes +// $tabs->wrap is an array of "nowrap"s or nothing +// $tabs->highlight is an index (zero based) of "active" heading . +// $tabs->width is an percentage of the page (defualts to 80%) +// $tabs->cellpadding padding on each cell (defaults to 5) + + global $CFG, $THEME; + + if (isset($tabs->names)) { + foreach ($tabs->names as $key => $name) { + if (!empty($tabs->urls[$key])) { + $url =$tabs->urls[$key]; + if ($tabs->highlight == $key) { + $tabcontents[$key] = "$name"; + } else { + $tabcontents[$key] = "$name"; + } + } else { + $tabcontents[$key] = "$name"; + } + } + } + + if (empty($tabs->width)) { + $tabs->width = "80%"; + } + + if (empty($tabs->cellpadding)) { + $tabs->cellpadding = "5"; + } + + // print_simple_box_start("center", "$table->width", "#ffffff", 0); + echo "cellpadding\" cellspacing=\"0\" class=\"generaltable\">\n"; + + if (!empty($tabs->names)) { + echo ""; + echo "\n"; + foreach ($tabcontents as $key => $tab) { + if (isset($align[$key])) { + $alignment = "align=\"$align[$key]\""; + } else { + $alignment = "align=\"center\""; + } + if (isset($size[$key])) { + $width = "width=\"$size[$key]\""; + } else { + $width = ""; + } + if (isset($wrap[$key])) { + $wrapping = "no wrap"; + } else { + $wrapping = ""; + } + if ($key == $tabs->highlight) { + echo "\n"; + } else { + echo "\n"; + } + echo "\n"; + } + echo "\n"; + } else { + echo "\n"; + } + // bottom stripe + $ncells = count($tabs->names)*2 +1; + $height = 2; + echo "\n"; + echo "
". + "wwwroot/pix/spacer.gif\" alt=\"\">cellheading2\">$tabbody\">$tab". + "wwwroot/pix/spacer.gif\" alt=\"\">
No names specified
cellheading2\">". + "wwwroot/pix/spacer.gif\" alt=\"\">
\n"; + // print_simple_box_end(); + + return true; +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_print_user_entry($course, $user, $entry, $teachers, $grades) { + global $THEME, $USER; + + if ($entry->timemarked < $entry->modified) { + $colour = $THEME->cellheading2; + } else { + $colour = $THEME->cellheading; + } + + echo "\n"; + + echo "\n"; + echo "\n"; + echo ""; + + echo "\n"; + + if ($entry) { + echo "\n"; + echo ""; + } + echo "
body\" WIDTH=35 VALIGN=TOP>"; + print_user_picture($user->id, $course->id, $user->picture); + echo "$user->firstname $user->lastname"; + if ($entry) { + echo "  ".get_string("lastedited").": ".userdate($entry->modified).""; + } + echo "
cellcontent\">"; + if ($entry) { + echo format_text($entry->text, $entry->format); + } else { + print_string("noentry", "dialogue"); + } + echo "
"; + if (!$entry->teacher) { + $entry->teacher = $USER->id; + } + print_user_picture($entry->teacher, $course->id, $teachers[$entry->teacher]->picture); + echo "".get_string("feedback").":"; + choose_from_menu($grades, "r$entry->id", $entry->rating, get_string("nograde")."..."); + if ($entry->timemarked) { + echo "  ".userdate($entry->timemarked).""; + } + echo "

"; + echo "

\n"; +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_show_conversation($dialogue, $conversation, $user) { + global $THEME; + + if (! $course = get_record("course", "id", $dialogue->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) { + error("Course Module ID was incorrect"); + } + + $timenow = time(); + print_simple_box_start("center"); + echo "
\n"; + + echo ""; + echo ""; + echo ""; + + if ($entries = get_records_select("dialogue_entries", "conversationid = $conversation->id", "id")) { + foreach ($entries as $entry) { + if ($entry->userid == $user->id) { + echo "\n"; + } + else { + echo "\n"; + } + } + } + echo "
cellheading2\" valign=\"top\">\n"; + if ($conversation->userid == $user->id) { + if (!$otheruser = get_record("user", "id", $conversation->recipientid)) { + error("User not found"); + } + } + else { + if (!$otheruser = get_record("user", "id", $conversation->userid)) { + error("User not found"); + } + } + // print_user_picture($user->id, $course->id, $user->picture); + echo "".get_string("dialoguewith", "dialogue", "$otheruser->firstname $otheruser->lastname"). + "cellheading2\" valign=\"top\">$conversation->subject 
\n"; + echo text_to_html("".get_string("onyouwrote", "dialogue", + userdate($entry->timecreated)). + ":
".$entry->text); + echo "
body\">\n"; + echo text_to_html("".get_string("onwrote", "dialogue", + userdate($entry->timecreated)." ".$otheruser->firstname).":
".$entry->text); + echo "

\n"; + print_simple_box_end(); + print_continue("view.php?id=$cm->id&pane=3"); +} + + +////////////////////////////////////////////////////////////////////////////////////// +function dialogue_show_other_conversations($dialogue, $conversation) { +// prints the other CLOSED conversations for this pair of users + global $THEME, $USER; + + if (! $course = get_record("course", "id", $dialogue->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("dialogue", $dialogue->id, $course->id)) { + error("Course Module ID was incorrect"); + } + + if (!$user = get_record("user", "id", $conversation->userid)) { + error("User not found"); + } + if (!$otheruser = get_record("user", "id", $conversation->recipientid)) { + error("User not found"); + } + + if ($conversations = get_records_select("dialogue_conversations", "dialogueid = $dialogue->id AND + (userid = $user->id AND recipientid = $otheruser->id) OR (userid = $otheruser->id AND + recipientid = $user->id) AND closed = 1", "timemodified DESC")) { + if (count($conversations) > 1) { + $timenow = time(); + foreach ($conversations as $otherconversation) { + if ($conversation->id != $otherconversation->id) { + // for this conversation work out which is the other user + if ($otherconversation->userid == $USER->id) { + if (!$otheruser = get_record("user", "id", $otherconversation->recipientid)) { + error("Show other conversations: could not get user record"); + } + } + else { + if (!$otheruser = get_record("user", "id", $otherconversation->userid)) { + error("Show other conversations: could not get user record"); + } + } + print_simple_box_start("center"); + echo "
\n"; + + echo ""; + echo ""; + echo ""; + if ($entries = get_records_select("dialogue_entries", + "conversationid = $otherconversation->id", "id")) { + foreach ($entries as $entry) { + if ($entry->userid == $USER->id) { + echo "\n"; + } + else { + echo "\n"; + } + } + } + + echo "
cellheading2\" VALIGN=TOP>\n"; + // print_user_picture($otheruser->id, $course->id, $otheruser->picture); + echo "".get_string("dialoguewith", "dialogue", + "$otheruser->firstname $otheruser->lastname")."cellheading2\" valign=\"top\">$conversation->subject 
\n"; + echo text_to_html("".get_string("onyouwrote", "dialogue", + userdate($entry->timecreated)).":
".$entry->text); + echo "
body\">\n"; + echo text_to_html("".get_string("onwrote", "dialogue", + userdate($entry->timecreated)." ".$otheruser->firstname). + ":
".$entry->text); + echo "

\n"; + print_simple_box_end(); + } + } + print_continue("view.php?id=$cm->id&pane=3"); + } + } +} + + + +?> + diff --git a/mod/dialogue/mod.html b/mod/dialogue/mod.html new file mode 100644 index 0000000000..d156544808 --- /dev/null +++ b/mod/dialogue/mod.html @@ -0,0 +1,116 @@ +name)) { + $form->name = ""; + } + if (!isset($form->intro)) { + $form->intro = ""; + } + if (!isset($form->deleteafter)) { + $form->deleteafter = 0; + } + if (!isset($form->dialoguetype)) { + $form->dialoguetype = 0; + } + if (!isset($form->multipleconversations)) { + $form->multipleconversations = 0; + } + if (!isset($form->maildefault)) { + $form->maildefault = 0; + } +?> + +
action="mod.php"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

:

+ +

:

+ + "; + emoticonhelpbutton("form", "intro"); + ?> +
+
+ +
+ +

:

+ dirroot/mod/dialogue/lib.php"); + choose_from_menu($DIALOGUE_DAYS, "deleteafter", $form->deleteafter, ""); + helpbutton("deleteafter", get_string("deleteafter", "dialogue"), "dialogue"); + ?> +

:

+ dialoguetype, ""); + helpbutton("dialoguetype", get_string("typeofdialogue", "dialogue"), "dialogue"); + ?> +

:

+ multipleconversations, ""); + helpbutton("multiple", get_string("allowmultiple", "dialogue"), "dialogue"); + ?> +

:

+ maildefault, ""); + helpbutton("maildefault", get_string("maildefault", "dialogue"), "dialogue"); + ?> +
+
+ + + + + + + +"> +"> + +
diff --git a/mod/dialogue/restorelib.php b/mod/dialogue/restorelib.php new file mode 100644 index 0000000000..fd78ae14cf --- /dev/null +++ b/mod/dialogue/restorelib.php @@ -0,0 +1,225 @@ +dialogueid) + // | + // | + // | + // dialogue_conversations + // (UL,pk->id, fk->dialogueid) + // | + // | + // | + // dialogue_entries + // (UL,pk->id, fk->conversationid) + // + // Meaning: pk->primary key field of the table + // fk->foreign key to link with parent + // nt->nested field (recursive data) + // CL->course level info + // UL->user level info + // files->table may have files) + // + //----------------------------------------------------------- + + //This function executes all the restore procedure about this mod + function dialogue_restore_mods($mod,$restore) { + + global $CFG; + + $status = true; + + //Get record from backup_ids + $data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id); + + if ($data) { + //Now get completed xmlized object + $info = $data->info; + //traverse_xmlize($info); //Debug + //print_object ($GLOBALS['traverse_array']); //Debug + //$GLOBALS['traverse_array']=""; //Debug + + //Now, build the dialogue record structure + $dialogue->course = $restore->course_id; + $dialogue->name = backup_todb($info['MOD']['#']['NAME']['0']['#']); + $dialogue->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']); + $dialogue->deleteafter = backup_todb($info['MOD']['#']['DELETEAFTER']['0']['#']); + $dialogue->dialoguetype = backup_todb($info['MOD']['#']['DIALOGUETYPE']['0']['#']); + $dialogue->multipleconversations = backup_todb($info['MOD']['#']['MULTIPLECONVERSATIONS']['0']['#']); + $dialogue->maildefault = backup_todb($info['MOD']['#']['MAILDEFAULT']['0']['#']); + $dialogue->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); + + //We have to recode the assessed field if it is <0 (scale) + if ($dialogue->assessed < 0) { + $scale = backup_getid($restore->backup_unique_code,"scale",abs($dialogue->assessed)); + if ($scale) { + $dialogue->assessed = -($scale->new_id); + } + } + + //The structure is equal to the db, so insert the dialogue + $newid = insert_record ("dialogue",$dialogue); + + //Do some output + echo "
  • ".get_string("modulename","dialogue")." \"".$dialogue->name."\"
    "; + backup_flush(300); + + if ($newid) { + //We have the newid, update backup_ids + backup_putid($restore->backup_unique_code,$mod->modtype, + $mod->id, $newid); + //Now check if want to restore user data and do it. + if ($restore->mods['dialogue']->userinfo) { + //Restore dialogue_conversations + $status = dialogue_conversations_restore_mods ($mod->id, $newid,$info,$restore); + } + } else { + $status = false; + } + + //Finalize ul + echo "
"; + + } else { + $status = false; + } + + return $status; + } + + + //This function restores the dialogue_conversations + function dialogue_conversations_restore_mods($old_dialogue_id, $new_dialogue_id,$info,$restore) { + + global $CFG; + + $status = true; + + //Get the entries array + $conversations = $info['MOD']['#']['CONVERSATIONS']['0']['#']['CONVERSATION']; + + //Iterate over conversations + for($i = 0; $i < sizeof($converstions); $i++) { + $conversation_info = $conversations[$i]; + //traverse_xmlize($conversation_info); //Debug + //print_object ($GLOBALS['traverse_array']); //Debug + //$GLOBALS['traverse_array']=""; //Debug + + //We'll need this later!! + $oldid = backup_todb($sub_info['#']['ID']['0']['#']); + $olduserid = backup_todb($sub_info['#']['USERID']['0']['#']); + + //Now, build the dialogue_ENTRIES record structure + $conversation->dialogue = $new_dialogue_id; + $conversation->userid = backup_todb($conversation_info['#']['USERID']['0']['#']); + $conversation->recipientid = backup_todb($conversation_info['#']['RECIPIENTID']['0']['#']); + $conversation->lastid = backup_todb($conversation_info['#']['LASTID']['0']['#']); + $conversation->timemodified = backup_todb($conversation_info['#']['TIMEMODIFIED']['0']['#']); + $conversation->closed = backup_todb($conversation_info['#']['CLOSED']['0']['#']); + $conversation->ctype = backup_todb($conversation_info['#']['CTYPE']['0']['#']); + $conversation->format = backup_todb($conversation_info['#']['FORMAT']['0']['#']); + $conversation->subject = backup_todb($conversation_info['#']['SUBJECT']['0']['#']); + //We have to recode the userid and recipientid fields + $user = backup_getid($restore->backup_unique_code,"user",$conversation->userid); + if ($user) { + $conversation->userid = $user->new_id; + } + $user = backup_getid($restore->backup_unique_code,"user",$conversation->recipientid); + if ($user) { + $conversation->recipientid = $user->new_id; + } + + //The structure is equal to the db, so insert the dialogue_conversation + $newid = insert_record ("dialogue_conversations",$conversation); + + //Do some output + if (($i+1) % 50 == 0) { + echo "."; + if (($i+1) % 1000 == 0) { + echo "
"; + } + backup_flush(300); + } + + if ($newid) { + //We have the newid, update backup_ids + backup_putid($restore->backup_unique_code, "dialogue_conversations", + $oldid, $newid); + //Now check if want to restore user data and do it. + if ($status) { + //Restore dialogue_entries + $status = dialogue_entries_restore_mods ($new_dialogue_id, $newid,$conversation,$restore); + } + } else { + $status = false; + } + + } + + return $status; + } + + //This function restores the dialogue_entries + function dialogue_entries_restore_mods($old_dialogue_id, $new_dialogue_id,$conversation,$restore) { + + global $CFG; + + $status = true; + + //Get the entries array + $entries = $info['MOD']['#']['ENTRIES']['0']['#']['ENTRY']; + + //Iterate over entries + for($i = 0; $i < sizeof($entries); $i++) { + $entry_info = $entries[$i]; + //traverse_xmlize($entry_info); //Debug + //print_object ($GLOBALS['traverse_array']); //Debug + //$GLOBALS['traverse_array']=""; //Debug + + //We'll need this later!! + $oldid = backup_todb($sub_info['#']['ID']['0']['#']); + $olduserid = backup_todb($sub_info['#']['USERID']['0']['#']); + + //Now, build the dialogue_ENTRIES record structure + $entry->dialogue = $new_dialogue_id; + $entry->conversationid = $conversation->id; + $entry->userid = backup_todb($entry_info['#']['USERID']['0']['#']); + $entry->timecreated = backup_todb($entry_info['#']['TIMECREATED']['0']['#']); + $entry->mailed = backup_todb($entry_info['#']['MAILED']['0']['#']); + $entry->text = backup_todb($entry_info['#']['TEXT']['0']['#']); + + //We have to recode the userid field + $user = backup_getid($restore->backup_unique_code,"user",$entry->userid); + if ($user) { + $entry->userid = $user->new_id; + } + + //The structure is equal to the db, so insert the dialogue_entry + $newid = insert_record ("dialogue_entries",$entry); + + //Do some output + if (($i+1) % 50 == 0) { + echo "."; + if (($i+1) % 1000 == 0) { + echo "
"; + } + backup_flush(300); + } + + if ($newid) { + //We have the newid, update backup_ids + backup_putid($restore->backup_unique_code,"dialogue_entry",$oldid, + $newid); + } else { + $status = false; + } + } + + return $status; + } + +?> diff --git a/mod/dialogue/version.php b/mod/dialogue/version.php new file mode 100644 index 0000000000..c29a074e69 --- /dev/null +++ b/mod/dialogue/version.php @@ -0,0 +1,11 @@ +version = 2003100500; +$module->cron = 60; + +?> diff --git a/mod/dialogue/view.php b/mod/dialogue/view.php new file mode 100644 index 0000000000..83cb0e453c --- /dev/null +++ b/mod/dialogue/view.php @@ -0,0 +1,173 @@ +course)) { + error("Course is misconfigured"); + } + + require_login($course->id); + + if (! $dialogue = get_record("dialogue", "id", $cm->instance)) { + error("Course module is incorrect"); + } + + add_to_log($course->id, "dialogue", "view", "view.php?id=$cm->id", "$dialogue->id"); + + if (! $cw = get_record("course_sections", "id", $cm->section)) { + error("Course module is incorrect"); + } + + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + + $strdialogue = get_string("modulename", "dialogue"); + $strdialogues = get_string("modulenameplural", "dialogue"); + + print_header("$course->shortname: $dialogue->name", "$course->fullname", + "$navigation id\">$strdialogues -> $dialogue->name", + "", "", true, + update_module_button($cm->id, $course->id, $strdialogue), navmenu($course, $cm)); + + // ...and if necessary set default action + + optional_variable($action); + + if (!isguest()) { // it's a teacher or student + if (!$cm->visible and isstudent($course->id)) { + $action = 'notavailable'; + } + if (empty($action)) { + $action = 'view'; + } + } + else { // it's a guest, oh no! + $action = 'notavailable'; + } + + + +/*********************** dialogue not available (for gusets mainly)***********************/ + if ($action == 'notavailable') { + print_heading(get_string("notavailable", "dialogue")); + } + + + /************ view **************************************************/ + elseif ($action == 'view') { + + print_simple_box( text_to_html($dialogue->intro) , "center"); + echo "
"; + // get some stats + $countneedingrepliesself = dialogue_count_needing_replies_self($dialogue, $USER); + $countneedingrepliesother = dialogue_count_needing_replies_other($dialogue, $USER); + $countclosed = dialogue_count_closed($dialogue, $USER); + + // set the pane if it's in a GET or POST + if (isset($_REQUEST['pane'])) { + $pane = $_REQUEST['pane']; + } else { + // set default pane + $pane = 0; + if ($countneedingrepliesother) { + $pane = 2; + } + if ($countneedingrepliesself) { + $pane =1; + } + } + + // set up tab table + $tabs->names[0] = get_string("pane0", "dialogue"); + if ($countneedingrepliesself == 1) { + $tabs->names[1] = get_string("pane1one", "dialogue"); + } else { + $tabs->names[1] = get_string("pane1", "dialogue", $countneedingrepliesself); + } + if ($countneedingrepliesother == 1) { + $tabs->names[2] = get_string("pane2one", "dialogue"); + } else { + $tabs->names[2] = get_string("pane2", "dialogue", $countneedingrepliesother); + } + if ($countclosed == 1) { + $tabs->names[3] = get_string("pane3one", "dialogue"); + } else { + $tabs->names[3] = get_string("pane3", "dialogue", $countclosed); + } + + $tabs->urls[0] = "view.php?id=$cm->id&pane=0"; + $tabs->urls[1] = "view.php?id=$cm->id&pane=1"; + $tabs->urls[2] = "view.php?id=$cm->id&pane=2"; + $tabs->urls[3] = "view.php?id=$cm->id&pane=3"; + $tabs->highlight = $pane; + dialogue_print_tabbed_heading($tabs); + echo "
\n"; + switch ($pane) { + case 0: + if ($names = dialogue_get_available_users($dialogue)) { + print_simple_box_start("center"); + echo "
"; + echo "
\n"; + echo "id\">\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo ""; + echo "\n"; + echo "
".get_string("openadialoguewith", "dialogue"). + " : "; + choose_from_menu($names, "recipientid"); + echo "
".get_string("subject", "dialogue")." :
". + get_string("typefirstentry", "dialogue")."
\n"; + helpbutton("writing", get_string("helpwriting"), "dialogue", true, true); + echo "
"; + $showemoticon = false; + if ($showemoticon) { + emoticonhelpbutton("replies", "firstentry"); + } + echo "
\n"; + echo "\n"; + echo "
\n"; + echo "
"; + print_simple_box_end(); + } else { + print_heading(get_string("noavailablepeople", "dialogue")); + print_continue("view.php?id=$cm->id"); + } + break; + case 1: + // print active conversations requiring a reply + dialogue_list_conversations_self($dialogue, $USER); + break; + case 2: + // print active conversations requiring a reply from the other person. + dialogue_list_conversations_other($dialogue, $USER); + break; + case 3: + dialogue_list_conversations_closed($dialogue, $USER); + } + } + + /*************** no man's land **************************************/ + else { + error("Fatal Error: Unknown Action: ".$action."\n"); + } + + print_footer($course); + +?> -- 2.39.5