summaryrefslogtreecommitdiff
path: root/tbc_external_review.module
blob: 68472371e32f1e0559d7d33f6890cedf602fa6f2 (plain)
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
<?php 
    function tbc_external_review_menu() {
        $items = array();
        
        $items["tbc_external_review/books_available"] = array(
            "title" => "ER Books Available",
            "page callback" => "tbc_external_review_all",
            "access arguments" => array("access tbc_external_review"),
            "type" => MENU_CALLBACK
        );
        $items["tbc_external_review/reviewer_profile"] = array(
            "title" => "TBC External Reviewer Profile",
            "page callback" => "tbc_external_review_profile_all",
            "access arguments" => array("access tbc_external_review"),
            "type" => MENU_CALLBACK
        );
        $items["tbc_external_review/view_reviewers"] = array(
            "title" => "ER List Reviewers",
            "page callback" => "tbc_external_review_view_all",
            "access arguments" => array("administer tbc_external_review"),
            "type" =>  MENU_NORMAL_ITEM
        );
        $items["tbc_external_review/reviewer_selections"] = array(
            "title" => "TBC External Reviewer Selections",
            "page callback" => "tbc_external_review_reviewer_selections_all",
            "access arguments" => array("administer tbc_external_review"),
            "type" => MENU_CALLBACK
        );
        $items["tbc_external_review/selected_books"] = array(
            "title" => "Books for External Review",
            "page callback" => "tbc_external_review_selected_books_all",
            "access arguments" => array("download tbc_external_review"),
            "type" => MENU_NORMAL_ITEM
        );
        $items["tbc_external_review/comments"] = array(
            "title" => "External Review Comments",
            "page callback" => "tbc_external_review_comments_all",
            "access arguments" => array("download tbc_external_review"),
            "type" => MENU_NORMAL_ITEM
        );
        $items["tbc_external_review/manage_comments"] = array(
            "title" => "ER Manage Comments",
            "page callback" => "tbc_external_review_manage_comments_all",
            "access arguments" => array("administer tbc_external_review"),
            "type" => MENU_NORMAL_ITEM
        );
        $items["tbc_external_review/status"] = array(
            "title" => "ER View Status",
            "page callback" => "tbc_external_review_status_all",
            "access arguments" => array("administer tbc_external_review"),
            "type" => MENU_NORMAL_ITEM
        );
        $items["tbc_external_review/ajax"] = array(
            "page callback" => "tbc_external_review_ajax",
            "access arguments" => array("download tbc_external_review"),
            "type" => MENU_CALLBACK
        );
        return $items;
    }

    function tbc_external_review_perm() {
        return array(
            "access tbc_external_review", "administer tbc_external_review",
            "download tbc_external_review"
        );
    }

    /*
        book selection form
        {external_review_details} database required.
        fields: preference_id, uid, status
        status = 1 for selected.
    */
    function tbc_external_review_form($form_state) {
        global $user;
        $form = array();
        
        /* create multiple checkboxes from database */
        $result = remaining_books();
        $num_rows = mysql_num_rows($result);
        if($num_rows > 0) {
            while($row = db_fetch_object($result)) {
                $form[$row->id] = array(
                    "#type" => "checkbox",
                    "#title" => t("{$row->book} by {$row->author} ( ed: {$row->edition}, pub: {$row->year})"),
                );
            }
            $form["submit"] = array(
                "#type" => "submit",
                "#value" => "Submit",
            );
        } else {
            drupal_set_message("<strong>All the available books have been selected. Please wait for more updates.</strong>", "status");
        }
        return $form;
    }

    function tbc_external_review_form_validate($form, &$form_state) {
        $result = remaining_books();
        $count = 0;
        $selections = array();
        while($row = db_fetch_object($result)) {
            if($form_state["values"][$row->id] == 1) {
                $count++;
                array_push($selections, $row->id);
            }
        }
        $remaining = remaining_books_count();
        if($count > $remaining) {
            form_set_error("", "You can select a maximum of <strong>{$remaining}</strong> books.");
        } else {
            $form_state["values"]["selections"] = $selections;
        }
    }
    
    function tbc_external_review_form_submit($form, &$form_state) {
        global $user;
        
        $selections = $form_state["values"]["selections"];
        foreach($selections as $selection) {
            $query = "update {external_review_details} set uid = {$user->uid}, status = 1 where preference_id = {$selection}";
            db_query($query);
        }
        drupal_set_message("<strong>Your selections have been updated sucessfully.</strong>", "status");
    }

    function tbc_external_review_all() {
        global $user;
        $page_content = "";
        
        $remaining = remaining_books_count();
        if($remaining > 0) {
            $page_content = "You have <strong>{$remaining}</strong> selections remaining:";
            $page_content .= drupal_get_form("tbc_external_review_form");
        } else {
            $page_content = "Thanks for your selections.";
        }
        return $page_content;
    }

    /* helper functions */
    function remaining_books_count() {
        global $user;
        /*finding how many books the user can select */
        $query = "select count(*) from {external_review_details} where uid = {$user->uid}";
        $result = db_query($query);
        $row = db_fetch_array($result);
        $remaining = 6 - $row["count(*)"];
        return $remaining;
    }

    function remaining_books() {
        $query = "select * from {textbook_companion_preference} where id in (select preference_id from {external_review_details} where status = 0)";
        $result = db_query($query);
        return $result;
    }

    /*
        external reviewer profile form,
        save the data in {external_review_profile}
    */
    function tbc_external_review_profile_form() {
        global $user;
        $form = array();
        /* populating the form with previous entry details if exists */
        $query = "select * from {external_review_profile} where uid = %d";
        $result = db_query($query, $user->uid);
        $row = db_fetch_array($result);
        
        $form["first_name"] = array(
            "#type" => "textfield",
            "#title" => t("First Name"),
            "#required" => True,
            "#default_value" => $row["first_name"],
        );
        $form["last_name"] = array(
            "#type" => "textfield",
            "#title" => t("Last Name"),
            "#required" => True,
            "#default_value" => $row["last_name"],
        );
        $form["designation"] = array(
            "#type" => "textfield",
            "#title" => t("Designation"),
            "#required" => True,
            "#default_value" => $row["designation"],
        );
        $form["university"] = array(
            "#type" => "textfield",
            "#title" => t("University/Institute"),
            "#required" => True,
            "#default_value" => $row["university"],
        );
        $form["phone"] = array(
            "#type" => "textfield",
            "#title" => t("Phone Number"),
            "#required" => True,
            "#default_value" => $row["phone"],
        );
        $form["email"] = array(
            "#type" => "textfield",
            "#title" => t("Email"),
            "#required" => True,
            "#default_value" => $row["email"],
        );
        $form["alt_email"] = array(
            "#type" => "textfield",
            "#title" => t("Alternate Email"),
            "#default_value" => $row["alt_email"],
        );
        $form["address"] = array(
            "#type" => "textarea",
            "#title" => t("Postal Address"),
            "#required" => True,
            "#default_value" => $row["address"],
        );
        $form["description"] = array(
            "#type" => "textarea",
            "#title" => t("Description: 
                (Research interest / Level of expertise in Scilab / Teaching Expertise )
            "),
            "#required" => True,
            "#default_value" => $row["description"],
        );
        $form["submit"] =array(
            "#type" => "submit",
            "#value" => "Update Profile",
        );
        return $form;
    }

    function tbc_external_review_profile_form_validate($form, &$form_state) {
        /* validating phone */
        if(!preg_match("/^[0-9]+$/", $form_state["values"]["phone"])) {
            form_set_error("phone", "Please enter a valid Phone Number, only (0-9) allowed.");
        }
        /*validating email */
        if(!valid_email_address($form_state["values"]["email"])) {
            form_set_error("email", "Please enter a valid Email address");
        }
        if($form_state["values"]["alt_email"] && !valid_email_address($form_state["values"]["alt_email"])) {
            form_set_error("alt_email", "Please enter a valid Alternate Email address" );
        }
        /* validating address */
        if(strlen($form_state["values"]["address"]) < 20) {
            form_set_error("address", "Please enter a proper Postal Address.");
        }
        /* validating description */
        if(strlen($form_state["values"]["description"]) < 25) {
            form_set_error("description", "Please enter a longer description.");
        }
    }

    function tbc_external_review_profile_form_submit($form, &$form_state) {
        global $user;
        /* setting $val as the new values array */
        $val = array(); 
        $val = $form_state["values"];
        
        /* checking whether the user already has an entry */
        $query = "select uid from {external_review_profile} where uid = %d";
        $result = db_query($query, $user->uid);
        $has_entry = mysql_num_rows($result);
        
        if($has_entry) {
            /* update the existing entry */
            $query = "update {external_review_profile} 
                    set 
                    first_name = '%s', last_name = '%s', designation = '%s', 
                    university = '%s', phone = '%s', email = '%s', alt_email = '%s',
                    address = '%s', description = '%s' 
                    where uid = %d
            ";
            $result = db_query(
                $query, $val["first_name"], $val["last_name"], $val["designation"], $val["university"],
                $val["phone"], $val["email"], $val["alt_email"], $val["address"], $val["description"],
                $user->uid
            );
        } else {
            /* create a new entry */
            $query = "insert into {external_review_profile} 
                    (uid, first_name, last_name, designation, university, phone, email, alt_email, address, description) 
                    values
                    (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')
            ";
            $result = db_query(
                $query, $user->uid, $val["first_name"], $val["last_name"], $val["designation"], $val["university"],
                $val["phone"], $val["email"], $val["alt_email"], $val["address"], $val["description"]
            );
        }
        if($result) {
            drupal_set_message("Profile updated successfully. Thank you.", "status");
        } else {
            drupal_set_message("Database updation failed. Please contact support.", "error");
        }
        drupal_goto('tbc_external_review');
    }

    function tbc_external_review_profile_all() {
        $page_content = "";
        $page_content .= drupal_get_form("tbc_external_review_profile_form");
        return $page_content;
    }

    function tbc_external_review_view_all() {
        $page_content = "";
        $query = "select * from {external_review_profile}";
        $result = db_query($query);
        
        $page_content .= "<ul>";
        while($row = db_fetch_object($result)) {
            $page_content .= "<li>";
            $page_content .= l("{$row->first_name} {$row->last_name}", "tbc_external_review/reviewer_selections/{$row->uid}");
            $page_content .= "</li>";
        }
        $page_content .= "</ul>";
        return $page_content;
    }

    function tbc_external_review_reviewer_selections_all($uid=0) {
        $page_content = "";
        
        $query = "SELECT * FROM {external_review_profile} WHERE uid = %d";
        $result = db_query($query, $uid);
        $row = db_fetch_object($result);
        $page_content .= "Books selected by <strong>{$row->first_name} {$row->last_name}</strong>";
        $query = "
            SELECT * FROM {textbook_companion_preference} WHERE id IN 
            (SELECT preference_id FROM {external_review_details} WHERE uid = %d)
        ";
        $result = db_query($query, $uid);
        
        $page_content .= "<ol>";
        while($row = db_fetch_object($result)) {
            $page_content .= "<li>";
            $page_content .= t("{$row->book} by {$row->author} ( ed: {$row->edition}, pub: {$row->year})");
            $page_content .= "</li>";
        }
        $page_content .= "</ol>";
        return $page_content;
    }

    function tbc_external_review_selected_books_all() {
        global $user;
        $page_content = "";
        $page_content .= "- Please click the books to <b>download</b> them.";
        $query = "
            SELECT * FROM {textbook_companion_preference} WHERE id IN 
            (SELECT preference_id FROM {external_review_details} WHERE uid = %d)
        ";
        $result = db_query($query, $user->uid);
        
        $page_content .= "<ol>";
        while($row = db_fetch_object($result)) {
            $page_content .= "<li>";
            $page_content .= l(t("{$row->book} by {$row->author} ( ed: {$row->edition}, pub: {$row->year})"), "full_download_external/book/{$row->id}");
            $page_content .= "</li>";
        }
        $page_content .= "</ol>";
        return $page_content;
    }
    
    function tbc_external_review_comments_all() {
        global $user;
        $page_content = "";
        $page_content = "* Use this form to notify only examples that have errors.";
        $page_content .= drupal_get_form("tbc_external_review_comment_form");
        return $page_content;
    }

    function tbc_external_review_comment_form($form_state) {
        $form = array();
        global $user;
        global $base_url;
        $form["wrapper"] = array(
            "#type" => "fieldset",
            "#title" => t("
                Reviewer comments
                <img id='ajax-loader' src='" . "{$base_url}/" . drupal_get_path("module", "tbc_external_review") ."/img/throbber.gif'>
            "),
            "#prefix" => "<div id='comment-form-wrapper'>",
            "#suffix" => "</div>",
        );
        $form["wrapper"]["book"] = array(
            "#type" => "select",
            "#title" => t("Please select the book."),
            "#options" => _get_books($user->uid),
        );
        $form["wrapper"]["chapter"] = array(
            "#type" => "select",
            "#title" => t("Please select the chapter"),
        );
        $form["wrapper"]["example"] = array(
            "#type" => "select",
            "#title" => t("Please select the example"),
        );
        $form["wrapper"]["error"] = array(
            "#type" => "fieldset",
            "#title" => "Types of errors found",
            "#prefix" => "<div id='comment-error-wrapper'>",
            "#suffix" => "</div>",
        );
        $form["wrapper"]["error"]["ncf"] = array(
            "#type" => "radios",
            "#title" => t("Naming convention followed? (Checklist point 1, 2 and 4)"),
            "#options" => array(
                t("Yes"),
                t("No"),
            ),
        );
        $form["wrapper"]["error"]["eit"] = array(
            "#type" => "radios",
            "#title" => t("Error in textbook mentioned as comment?"),
            "#options" => array(
                t("Yes"),
                t("No"),
            ),
        );
        $form["wrapper"]["error"]["axl"] = array(
            "#type" => "radios",
            "#title" => t("Axes labeled ?"),
            "#options" => array(
                t("Yes"),
                t("No"),
            ),
        );
        $form["wrapper"]["error"]["sua"] = array(
            "#type" => "radios",
            "#title" => t("Symbols used are appropiate?"),
            "#options" => array(
                t("Yes"),
                t("No"),
            ),
        );
        $form["wrapper"]["error"]["sfu"] = array(
            "#type" => "radios",
            "#title" => t("Scilab functions used?"),
            "#options" => array(
                t("Yes"),
                t("No"),
            ),
        );
        $form["wrapper"]["error"]["sum"] = array(
            "#type" => "radios",
            "#title" => t("Solved using Matlab in textbook?"),
            "#options" => array(
                t("Yes"),
                t("No"),
            ),
        );
        $form["wrapper"]["error"]["aci"] = array(
            "#type" => "radios",
            "#title" => t("Appropriate comments included as mentioned in checklist point 7 ?"),
            "#options" => array(
                t("Yes"),
                t("No"),
            ),
        );
        $form["wrapper"]["error"]["auu"] = array(
            "#type" => "radios",
            "#title" => t("Appropriate units used as given in the textbook?"),
            "#options" => array(
                t("Yes"),
                t("No"),
            ),
        );
        $form["wrapper"]["error"]["teo"] = array(
            "#type" => "radios",
            "#title" => t("Typographical errors in output and/or comments?"),
            "#options" => array(
                t("Yes"),
                t("No"),
            ),
        );
        $form["wrapper"]["error"]["amt"] = array(
            "#type" => "radios",
            "#title" => t("Answers matching with the textbook?"),
            "#options" => array(
                t("Yes"),
                t("No"),
            ),
        );
        $form["wrapper"]["error"]["comment"] = array(
            "#type" => "textarea",
            "#title" => t("Other commment ? (if any)"),
        );
        $form["wrapper"]["submit"] = array(
            "#type" => "submit",
            "#value" => "Submit Comment"
        );
        return $form;
    }
    
    function tbc_external_review_comment_form_validate($form, &$form_state) {
        // for future use
    }

    function tbc_external_review_comment_form_submit($form, &$form_state) {
        global $user;
        $v = $form_state["values"];
        $query = "insert into {external_review_comments}
            (uid, preference_id, chapter_id, example_id, ncf, eit, axl, sua, sfu, sum, aci, auu, teo, amt, comment)
            values
            (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, '%s')
        ";
        $result = db_query(
            $query, $user->uid, $v["book"], $v["chapter"], $v["example"], 
            $v["ncf"], $v["eit"], $v["axl"], $v["sua"], $v["sfu"], $v["sum"], 
            $v["aci"], $v["auu"], $v["teo"], $v["amt"], $v["comment"]
        );
        drupal_set_message(t("Comment submited successfully"), "status");
    }

    /* Ajax Calls */
    function tbc_external_review_ajax($item, $key) {
        function _bool($var) {
            if($var == 1) {
                return "No";
            }
            return "Yes";
        }
        
        $data = "";
        if($item == "book" && $key) {
            $query = "select * from {textbook_companion_chapter} where preference_id = %d order by number";
            $result = db_query($query, $key);
            
            $data .= "<option value='0'>Please select the chapter.</option>";
            while($row = db_fetch_object($result)) {
                $data .= "<option value='{$row->id}'>{$row->number} {$row->name}</option>";
            }
        } else if($item == "chapter" && $key) {
            $query = "select * from {textbook_companion_example} where chapter_id = %d order by number";
            $result = db_query($query, $key);
            
            $data .= "<option value='0'>Please select the example.</option>";
            while($row = db_fetch_object($result)) {
                $data .= "<option value='{$row->id}'>{$row->number} {$row->caption}</option>";
            }
        } else if($item = "comment" && $key) {
            $query = "
                SELECT * FROM {external_review_comments} WHERE id = %d
            ";
            $result = db_query($query, $key);
            $row = db_fetch_object($result);
            
            $data .= "<table><th>Type of Error</th><th>Status</th>";
            $data .= "<tr><td>Naming convention followed?</td><td>" . _bool($row->ncf) . "</td></tr>";
            $data .= "<tr><td>Problem statement included in code?</td><td>" . _bool($row->eit) . "</td></tr>";
            $data .= "<tr><td>Axes labeled ?</td><td>" . _bool($row->axl) . "</td></tr>";
            $data .= "<tr><td>Symbols used are appropiate?</td><td>" . _bool($row->sua) . "</td></tr>";
            $data .= "<tr><td>Scilab functions used?</td><td>" . _bool($row->sfu) . "</td></tr>";
            $data .= "<tr><td>Solved using Matlab in textbook?</td><td>" . _bool($row->sum) . "</td></tr>";
            $data .= "<tr><td>Appropriate comments included as mentioned in checklist point 7 ?</td><td>" . _bool($row->aci) . "</td></tr>";
            $data .= "<tr><td>Appropriate units used as given in the textbook?</td><td>" . _bool($row->auu) . "</td></tr>";
            $data .= "<tr><td>Typographical errors in output and/or comments?</td><td>" . _bool($row->teo) . "</td></tr>";
            $data .= "<tr><td>Answers matching with the textbook?</td><td>" . _bool($row->amt) . "</td></tr>";
            $data .= "<tr><td>Any Other Comment ?</td><td>" . $row->comment . "</td></tr>";
            $data .= "</table>";
        }
        echo $data;
        exit();
    }

    /* Comment form helper functions */
    function _get_books($uid) {
        $query = "select * from {textbook_companion_preference} where id in 
            (select preference_id from {external_review_details} where uid = %d)
        ";
        $result = db_query($query, $uid);
        
        $books = array();
        $books[0] = "Please select a book";
        while($row = db_fetch_object($result)) {
            $books[$row->id] = $row->book;
        }
        return $books;
    }

    function tbc_external_review_status_all() {
        $page_content = "";
        $query = "
            SELECT * from textbook_companion_preference tcp INNER JOIN external_review_details erd 
            ON (tcp.id = erd.preference_id AND erd.status=1) INNER JOIN users ON (erd.uid = users.uid)
            ORDER BY users.name
        ";
        $result = db_query($query);
        $headers = array(
            "Book", 
            "Author",
            "User",
        );
        $rows = array();
        while($row = db_fetch_object($result)) {
            $item = array(
                "{$row->book}",
                "{$row->author}",
                "{$row->name}",
            );
            array_push($rows, $item);
        }
        $page_content .= "<h2><u>Selected Books</u></h2>";
        $page_content .= theme("table", $headers, $rows);
        
        $query = "
            SELECT * from textbook_companion_preference tcp INNER JOIN external_review_details erd 
            ON (tcp.id = erd.preference_id AND erd.status=0) INNER JOIN users ON (erd.uid = users.uid)
        ";
        $result = db_query($query);
        $headers = array(
            "Book", 
            "Author",
        );
        $rows = array();
        while($row = db_fetch_object($result)) {
            $item = array(
                "{$row->book}",
                "{$row->author}",
            );
            array_push($rows, $item);
        }
        $page_content .= "<h2><u>Books Not Selected</u></h2>";
        $page_content .= theme("table", $headers, $rows);
        return $page_content;
    }

    function tbc_external_review_manage_comments_all($preference_id=0) {
        global $base_url;
        $page_content = "";
        if($preference_id) {
            global $user;
            /* displaying comments of a particular user */
            $query = "
                SELECT erc.*, cha.number AS chapter, exa.number AS example FROM external_review_comments erc
                LEFT JOIN textbook_companion_chapter cha ON cha.id = erc.chapter_id 
                LEFT JOIN textbook_companion_example exa ON exa.id = erc.example_id
                WHERE erc.preference_id = %d
                ORDER BY erc.time DESC
            ";
            $result = db_query($query, $preference_id);
            $headers = array(
                "Chapter", "Example",
                "Time", "Action"
            );
            $rows = array();
            while($row = db_fetch_object($result)) {
                $options = array(
                    /* # linking in drupal l() */
                    "fragment" => " ",
                    "external" => TRUE,
                    "attributes" => array(
                        "class" => "view-comment",
                        "data-comment" => "{$row->id}",
                    )
                );
                $item = array(
                    "{$row->chapter}",
                    "{$row->example}",
                    "{$row->time}",
                    l("View", "", $options),
                );
                array_push($rows, $item);
            }
            $page_content .= theme("table", $headers, $rows);
            $page_content .= "<div id='lightbox-wrapper'>";
            $page_content .= "<div id='lightbox-inner'></div></div> ";
        } else {
            /* displaying the list of users */
            $query = "
                SELECT DISTINCT erc.preference_id, pre.book, pre.author, usr_con.name AS contributor, usr_ext.name AS reviewer
                FROM external_review_comments erc
                LEFT JOIN textbook_companion_preference pre ON erc.preference_id = pre.id
                LEFT JOIN textbook_companion_proposal pro ON pre.proposal_id = pro.id
                LEFT JOIN users usr_con ON usr_con.uid = pro.uid
                LEFT JOIN users usr_ext ON usr_ext.uid = erc.uid
                ORDER BY pre.book
            ";
            $result = db_query($query);
            $headers = array(
                "Book", "Author",
                "Contributor", "Reviewer",
                "Action",
            );
            $rows = array();
            while($row = db_fetch_object($result)) {
                $item = array(
                    "{$row->book}",
                    "{$row->author}",
                    "{$row->contributor}",
                    "{$row->reviewer}",
                    l("View", "tbc_external_review/manage_comments/" . $row->preference_id),
                );
                array_push($rows, $item);
            }
            $page_content .= theme("table", $headers, $rows);
        }
        return $page_content;
    }

    function tbc_external_review_init() {
        drupal_add_css(drupal_get_path("module", "tbc_external_review") . "/css/tbc_external_review.css");
        drupal_add_js(drupal_get_path("module", "tbc_external_review") . "/js/jquery.lightbox_me.js");
        drupal_add_js(drupal_get_path("module", "tbc_external_review") . "/js/tbc_external_review.js");
    }
?>