Repository navigation
Expand file tree
/
Copy pathshare.php
More file actions
186 lines (161 loc) · 7.9 KB
/
Copy pathshare.php
File metadata and controls
186 lines (161 loc) · 7.9 KB
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
<?php
require_once "../config.php";
require_once "./terms.php";
use \Tsugi\Core\LTIX;
$LAUNCH = LTIX::requireData();
$p = $CFG->dbprefix;
if (!$USER->instructor) {
?>
<link rel="stylesheet" href="css/learner.css" type="text/css">
<?php
echo '<p class="learner-text">This tool is for instructors only.</p>';
return;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Saving or updating a cell in the table
$courseId = isset($_POST["course_id"]) ? $_POST["course_id"] : false;
if (!$courseId) {
$_SESSION["error"] = "Error sharing course plan, plan not set properly.";
header('Location: ' . addSession('index.php'));
return;
}
$email_array = array_unique(explode(",", $_POST["emails"]));
$edit_access = isset($_POST["access"]) && $_POST["access"] == "edit" ? 1 : 0;
$notify = isset($_POST["notify"]) && $_POST["notify"] == "1" ? true : false;
$errors = false;
foreach ($email_array as $email) {
// Check for existing share row
$email = trim($email); // Remove any whitespace
$checkStmt = $PDOX->prepare("SELECT * FROM {$p}course_planner_share WHERE course_id = :course AND user_email = :email");
$checkStmt->execute(array(":course" => $courseId, ":email" => $email));
$check = $checkStmt->fetch(PDO::FETCH_ASSOC);
if (!$check) {
// Not currently shared so insert record
$newStmt = $PDOX->prepare("INSERT INTO {$p}course_planner_share (course_id, user_email, can_edit) VALUES (:courseId, :email, :canEdit)");
$newStmt->execute(array(
":courseId" => $courseId,
":email" => $email,
":canEdit" => $edit_access
));
// Notify if set
if ($notify) {
// Notify elearning that there is a new answer
// the message
$access_string = $edit_access == 1 ? "edit" : "read-only";
$msg = "Hello!\n\nYou have been granted ".$access_string." access to a new course plan created by ".$USER->displayname." via the \"Course Planner\" tool in Isidore. You will find the course plan in the \"Shared with me\" section on the main page of the tool.\n\nYou can access the course planning tool by logging into Isidore and clicking on \"Course Planner\" in the left-hand menu from the Home page.\n\nHappy Planning!";
// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);
$headers = "From: Course Planner < no-reply@learningapps.udayton.edu >\n";
// send email
mail($email, "You have been granted ".$access_string." access to a new course plan!", $msg, $headers);
}
} else {
$errors = true;
}
}
$success = "Access granted successfully.";
if ($notify) {
$success = $success." Email notifications sent successfully.";
}
if ($errors) {
$success = $success. " Some users were previously granted access and were skipped.";
}
if (isset($_POST["back"]) && $_POST["back"] == "edit") {
$back = "edit";
} else {
$back = "index";
}
$_SESSION["success"] = $success;
header('Location: ' . addSession('share.php?course='.$courseId.'&back='.$back));
return;
}
if (isset($_GET["course"])) {
$course = $_GET["course"];
// Get the title for the course
$query = "SELECT * FROM {$p}course_planner_main WHERE course_id = :courseId;";
$arr = array(':courseId' => $course);
$courseData = $PDOX->rowDie($query, $arr);
$courseTitle = $courseData ? $courseData["title"] : "";
$courseTerm = $courseData ? $courseData["term"] : 202080;
} else {
$_SESSION["error"] = "Unable to share course plan. Invalid id.";
header("Location: " . addSession("index.php"));
return;
}
$sharesqry = $PDOX->prepare("SELECT * FROM {$p}course_planner_share WHERE course_id = :course_id ORDER BY user_email");
$sharesqry->execute(array(":course_id" => $course));
$shares = $sharesqry->fetchAll(PDO::FETCH_ASSOC);
$back = isset($_GET["back"]) && $_GET["back"] == 'edit' ? "edit" : "index";
$menu = new \Tsugi\UI\MenuSet();
$menu->setHome('Course Planner', 'index.php');
if ($back == "index") {
$menu->addRight('Exit Sharing <span class="fas fa-sign-out-alt" aria-hidden="true"></span>', 'index.php');
} else {
$menu->addRight('Exit Sharing <span class="fas fa-sign-out-alt" aria-hidden="true"></span>', 'edit.php?course='.$course);
}
$OUTPUT->header();
?>
<link rel="stylesheet" href="css/planner.css" type="text/css">
<?php
$OUTPUT->bodyStart();
$OUTPUT->topNav($menu);
echo '<div class="container-fluid">';
$OUTPUT->flashMessages();
$termTitle = getTerm($courseTerm);
echo '<h3 class="term-title">'.$termTitle.'</h3>';
$OUTPUT->pageTitle($courseTitle, false, false);
?>
<div class="row">
<div class="col-sm-6">
<div class="planbox">
<h3 style="margin:0;">Share with people </h3>
<p>Enter an email (or emails comma-separated) below to share this plan.</p>
<form class="form" method="post">
<input type="hidden" name="course_id" value="<?=$course?>">
<input type="hidden" name="back" value="<?=$back?>">
<div class="form-group">
<label for="addpeople" id="addpeoplelabel">Add people by email address</label>
<input type="text" class="form-control" name="emails" value="" placeholder="e.g. email@udayton.edu, email2@udayton.edu" required autofocus>
</div>
<div class="radio">
<label><input type="radio" name="access" value="edit" checked> User(s) can edit</label>
</div>
<div class="radio">
<label><input type="radio" name="access" value="locked"> Read-only access</label>
</div>
<div class="form-group">
<div class="checkbox">
<label><input type="checkbox" name="notify" value="1"> Notify user(s) via email</label>
</div>
</div>
<button type="submit" class="btn btn-sm btn-primary">Grant Access</button>
</form>
</div>
</div>
<div class="col-sm-6">
<h3>Currently shared with</h3>
<?php
if (!$shares) {
echo '<p><em>This course plan is not currently shared with anyone else.</em></p>';
} else {
echo '<div class="list-group">';
foreach ($shares as $share) {
echo '<div class="list-group-item h4"><span class="email">'.$share["user_email"].'</span>';
echo '<div class="pull-right">';
if ($share["can_edit"]) {
echo '<a href="toggleaccess.php?course='.$course.'&email='.urlencode($share["user_email"]).'&access=readonly&back='.$back.'" class="plan-link" title="User can edit this plan"><span class="fas fa-lock-open" aria-hidden="true"></span><span class="sr-only">Make read-only</span></a>';
} else {
echo '<a href="toggleaccess.php?course='.$course.'&email='.urlencode($share["user_email"]).'&access=edit&back='.$back.'" onclick="return confirm(\'Are you sure you want to grant this user the ability to edit this course plan?\');" class="plan-link" title="User has read-only access to this plan"><span class="fas fa-lock" aria-hidden="true"></span><span class="sr-only">Allow editing</span></a>';
}
echo '<a href="unshare.php?course='.$course.'&email='.urlencode($share["user_email"]).'&back2=share&back='.$back.'" class="plan-link" title="Unshare"><span class="fas fa-user-slash" aria-hidden="true"></span><span class="sr-only">Unshare</span></a>';
echo '</div></div>';
}
echo '</div>';
}
?>
</div>
</div>
<?php
echo '</div>';// end container
$OUTPUT->footerStart();
$OUTPUT->footerEnd();