2 /************************************************************************/
\r
4 /************************************************************************/
\r
5 /* Copyright (c) 2002-2010 */
\r
6 /* Inclusive Design Institute */
\r
7 /* http://atutor.ca */
\r
8 /* This program is free software. You can redistribute it and/or */
\r
9 /* modify it under the terms of the GNU General Public License */
\r
10 /* as published by the Free Software Foundation. */
\r
11 /************************************************************************/
\r
14 * The Assignment Dropbox is designed for instructors to manage assignment
\r
15 * submissions and for students to submit assignments.
\r
17 * This file contains the functions used by Assignment Dropbox.
\r
20 if (!defined('AT_INCLUDE_PATH')) { exit; }
\r
23 * given an owner_type and owner_id
\r
24 * returns false if user cannot read or write to this workspace
\r
25 * returns WORKSPACE_AUTH_READ if the user can read
\r
26 * returns WORKSPACE_AUTH_WRITE if the user can write
\r
28 function ad_authenticate($owner_id) {
\r
29 if (authenticate(AT_PRIV_ASSIGNMENTS, AT_PRIV_RETURN))
\r
31 // instructors have read only access to assignments
\r
36 // students have read access to their own assignments
\r
38 $sql = "SELECT COUNT(*) cnt FROM ".TABLE_PREFIX."files
\r
39 WHERE owner_id =".$owner_id."
\r
40 AND owner_type= ".WORKSPACE_ASSIGNMENT."
\r
41 AND member_id = ".$_SESSION['member_id'];
\r
42 $result = mysql_query($sql, $db);
\r
43 $row = mysql_fetch_assoc($result);
\r
45 if ($row['cnt'] > 0) RETURN true;
\r
47 // enrolled students can submit the assignments that assign to him/her
\r
48 if ($_SESSION['member_id'] && $_SESSION['enroll']) {
\r
49 // assignments that are assigned to all students
\r
50 $sql = "SELECT count(*) cnt FROM ".TABLE_PREFIX."assignments
\r
51 WHERE assignment_id = ".$owner_id."
\r
53 AND course_id=".$_SESSION[course_id];
\r
54 $result = mysql_query($sql, $db);
\r
55 $row = mysql_fetch_assoc($result);
\r
57 if ($row['cnt'] > 0) RETURN true;
\r
59 // assignments that are assigned to a group,
\r
60 // and this group has "file storage" tool available
\r
61 // and the student is in this group
\r
62 $groups_list = implode(',',$_SESSION['groups']); // the groups that the student belongs to
\r
63 $sql = "SELECT count(*) cnt
\r
64 FROM ".TABLE_PREFIX."groups_types gt, ".TABLE_PREFIX."groups g, ".TABLE_PREFIX."assignments a
\r
65 WHERE g.group_id in (".$groups_list.")
\r
66 AND g.group_id in (SELECT group_id FROM ".TABLE_PREFIX."file_storage_groups)
\r
67 AND g.type_id = gt.type_id
\r
68 AND gt.course_id = $_SESSION[course_id]
\r
69 AND gt.type_id = a.assign_to
\r
70 AND a.assignment_id = ".$owner_id;
\r
71 $result = mysql_query($sql, $db);
\r
72 $row = mysql_fetch_assoc($result);
\r
74 if ($row['cnt'] > 0) RETURN true;
\r