File: comment.php

package info (click to toggle)
moodle 1.4.4.dfsg.1-3sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 57,876 kB
  • ctags: 29,496
  • sloc: php: 271,617; sql: 5,084; xml: 702; perl: 638; sh: 403; java: 283; makefile: 42; pascal: 21
file content (198 lines) | stat: -rw-r--r-- 7,629 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php // $Id: comment.php,v 1.10.2.7 2004/11/17 00:06:36 stronk7 Exp $

/// This page prints a particular instance of glossary
    require_once("../../config.php");
    require_once("lib.php");

    require_variable($id);             // Course Module ID
    require_variable($eid);            // Entry ID
    optional_variable($cid,0);         // Comment ID

    optional_variable($confirm,0);     // Confirm the action

    $action = optional_param('action','add');

    $action = strtolower($action);

    global $THEME, $USER, $CFG;

    if (! $cm = get_record("course_modules", "id", $id)) {
        error("Course Module ID was incorrect");
    } 

    if (! $course = get_record("course", "id", $cm->course)) {
        error("Course is misconfigured");
    } 

    if (! $glossary = get_record("glossary", "id", $cm->instance)) {
        error("Course module is incorrect");
    } 

    if (! $entry = get_record("glossary_entries", "id", $eid)) {
        error("Entry is incorrect");
    }

    if ( $cid ) {
        if (! $comment = get_record("glossary_comments", "id", $cid)) {
            error("Comment is incorrect");
        }
    } 

    require_login($course->id);    
    if (!$cm->visible and !isteacher($course->id)) {
        notice(get_string("activityiscurrentlyhidden"));
    } 
    if (isguest()) {
        error("Guests are not allowed to post comments", $_SERVER["HTTP_REFERER"]);
    }    
    add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id",$cm->id);

    switch ( $action ){
        case "add":
            $straction = get_string("addingcomment","glossary");
            break;
        case "edit":
            $straction = get_string("editingcomment","glossary");
            break;
        case "delete":
            $straction = get_string("deletingcomment","glossary");
            break;
        default:
            $action = "add";
            $straction = get_string("addingcomment","glossary");
            break;
    }
    $strglossaries = get_string("modulenameplural", "glossary");
    $strglossary = get_string("modulename", "glossary");
    $strcomments = get_string("comments", "glossary");

    print_header_simple(strip_tags("$glossary->name"), "",
            "<A HREF=index.php?id=$course->id>$strglossaries</A> -> <A HREF=view.php?id=$cm->id>$glossary->name</a> -> <A HREF=comments.php?id=$cm->id&eid=$entry->id>$strcomments</a> -> " . $straction,
            "", "", true, update_module_button($cm->id, $course->id, $strglossary),
            navmenu($course, $cm));
    
    echo "<center>";

/// Input section

    if ( $action == "delete" ) {
        if (($comment->userid <> $USER->id) and !isteacher($glossary->course)) {
            error("You can't delete other people's comments!");
        }
        if (!$glossary->allowcomments && !isteacher($glossary->course)) {
                error("You can't delete comments in this glossary!");
            }
        if ( $confirm ) {
            delete_records("glossary_comments","id", $cid);             

            print_simple_box_start("center","40%", "#FFBBBB");
            echo "<center>" . get_string("commentdeleted","glossary") . "</center>";
            print_simple_box_end();

            print_footer($course);
            add_to_log($course->id, "glossary", "delete comment", "comments.php?id=$cm->id&eid=$entry->id", "$comment->id",$cm->id);
            redirect("comments.php?id=$cm->id&eid=$entry->id");

        } else {

            glossary_print_comment($course, $cm, $glossary, $entry, $comment);

            print_simple_box_start("center","40%", "#FFBBBB");
            echo "<center><br>" . get_string("areyousuredeletecomment","glossary");
            ?>
                <form name="form" method="post" action="comment.php">
                <input type="hidden" name=id            value="<?php p($id) ?>">
                <input type="hidden" name=eid           value="<?php p($eid) ?>">
                <input type="hidden" name=cid           value="<?php p($cid) ?>">
                <input type="hidden" name=action        value="delete">
                <input type="hidden" name=confirm       value="1">
                <input type="submit" value=" <?php print_string("yes")?> ">
                <input type=button value=" <?php print_string("no")?> " onclick="javascript:history.go(-1);">

                </form>
                </center>
            <?php
            print_simple_box_end();
        }
    } else {
        if (!$glossary->allowcomments && !isteacher($glossary->course)) {
            error("You can't add/edit comments to this glossary!");
        }
        if ( $action == "edit" ) {
            if (!isset($comment->timemodified)) {
                $timetocheck = 0;
            } else {
                $timetocheck = $comment->timemodified;
            }
            $ineditperiod = ((time() - $timetocheck <  $CFG->maxeditingtime) || $glossary->editalways);
            if ( (!$ineditperiod || $USER->id != $comment->userid) and !isteacher($course->id) and $cid) {
                if ( $USER->id != $comment->userid ) {
                    error("You can't edit other people's comments!");
                } elseif (!$ineditperiod) {
                    error("You can't edit this. Time expired!");
                }
                die;
            }
        }

        if ( $confirm and $form = data_submitted() ) {
            //$form->text = clean_text($form->text, $form->format);

            $newentry->entryid = $entry->id;
            $newentry->comment = $form->text;
            $newentry->format = $form->format;
            $newentry->timemodified = time();

            if ( $action == "add" ) {
                $newentry->userid = $USER->id;

                if (! $newentry->id = insert_record("glossary_comments", $newentry)) {
                    error("Could not insert this new comment");
                } else {
                    add_to_log($course->id, "glossary", "add comment", "comments.php?id=$cm->id&eid=$entry->id", "$newentry->id", $cm->id);
                }
            } else {
                $newentry->id = $form->cid;
                $newentry->userid = $comment->userid;

                if (! update_record("glossary_comments", $newentry)) {
                    error("Could not update this comment");
                } else {
                    add_to_log($course->id, "glossary", "update comment", "comments.php?id=$cm->id&eid=$entry->id", "$newentry->id",$cm->id);
                }
            }
            print_simple_box_start("center","40%", "#FFBBBB");
            echo "<center>" . get_string("commentupdated","glossary") . "</center>";
            print_simple_box_end();

            print_footer($course);

            redirect("comments.php?id=$cm->id&eid=$entry->id");

        } else {
            /// original glossary entry
            glossary_print_entry($course, $cm, $glossary, $entry, "", "", false);
            echo "<br />";

            if ($usehtmleditor = can_use_html_editor()) {
                $defaultformat = FORMAT_HTML;
            } else {
                $defaultformat = FORMAT_MOODLE;
            }
            if (isset($comment) ) {
                $form->text = $comment->comment;
                $form->format = $comment->format;
            } else {
                $form->text = "";
                $form->format = $defaultformat;
            }
            include("comment.html");

            if ($usehtmleditor) { 
                use_html_editor("text");
            }
        }
    }
    /// Finish the page
    print_footer($course);
?>