-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddresources.php
316 lines (248 loc) · 13.3 KB
/
addresources.php
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
<?php
include_once("analyticstracking.php");
include 'internal_api.php';
session_start();
if (!empty($_POST)){
$resource=array();
if (isset($_POST["text"]) && $_POST["text"]<>'') {
$text=$_POST["text"];
$resource= addResource($_POST["topicid"],"Text", $text, null, 0);
}
if ((isset($_POST["videourl"]) && $_POST["videourl"]<>'') && (isset($_POST["videotext"]) && $_POST["videotext"]<>'')) {
if ($_POST["featured"]==1){
$resource= addResource($_POST["topicid"],"Video", $_POST["videourl"], $_POST["videotext"], 1);
}
else{
$resource= addResource($_POST["topicid"],"Video", $_POST["videourl"], $_POST["videotext"], 0);
}
}
if ((isset($_POST["linkurl"]) && $_POST["linkurl"]<>'') && (isset($_POST["linktext"]) && $_POST["linktext"]<>'')) {
$resource= addResource($_POST["topicid"],"Link", $_POST["linkurl"], $_POST["linktext"], 0);
}
}
if (!isset($_SESSION["loggedin"]) && $_SESSION["loggedin"]!=1 ){
$_SESSION["intended"]="addresources";
header( 'Location: login') ;
}
else if (!isset($_SESSION["instructor"]) && $_SESSION["instructor"]==0){
echo'YOU DO NOT HAVE ACCESS';
}
else{
?>
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>LearningX | Your perfect Java teacher</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="bower_components/paper-dialog/paper-dialog.html">
<link rel="import" href="bower_components/paper-dialog-scrollable/paper-dialog-scrollable.html">
<link rel="import" href="bower_components/paper-input/paper-textarea.html">
<link rel="import" href="bower_components/paper-checkbox/paper-checkbox.html">
<link rel="import" href="bower_components/iron-form/iron-form.html">
<link rel="import" href="bower_components/paper-toast/paper-toast.html">
<link rel="import" href="bower_components/iron-ajax/iron-ajax.html">
<link rel="import" href="bower_components/paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="bower_components/paper-item/paper-item.html">
<link rel="import" href="bower_components/paper-listbox/paper-listbox.html">
<link rel="import" href="bower_components/paper-input/paper-input.html">
<link rel="import" href="bower_components/paper-button/paper-button.html">
<link rel="stylesheet" href="css/normalize.css">
<!-- Dropdown.js -->
<link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'>
<link rel="stylesheet" href="css/style.css">
<link rel="import" href="bower_components/paper-material/paper-material.html">
<link rel="import" href="bower_components/paper-styles/paper-styles.html">
<link rel="import" href="css/my_custom_styles.html">
</head>
<body>
<?php include 'menu.php';?>
<div class="container" >
<div class="row" >
<div class="col-lg-8 col-lg-offset-2" >
<?php include 'header.html';?>
<?php if (isset($_SESSION["instructor"]) && $_SESSION["instructor"]==1){ ?>
<center>
<h3>Add Resources</h3></center>
<paper-button id="my-button2" class="my-button2" onclick="showTaskDialog()">Instructions </paper-button>
<center>
<paper-material elevation="3" class="card">
<center>
<?php if (isset($resource[0]["created"]) && $resource[0]["created"]=='Success'){?>
<h4 style="color:red">Resource(s) Created</h4>
<?php }?>
<form is="iron-form" id="form" method="post">
<select class="myselect" id="topicSelect" onchange="getTopic()">
<option value="0">Select Topic</option>
<?php $topics=array();
//Set the Array to call the function (this function is in internal_api.php)
$topics=getTopics();
//Loop through the results and display them.. you can write out HTML with them as you see I'm writing out the topic and then the BR HTML tag. If you need help concatenating the tags let me know
foreach($topics as $item) {
echo '<option value="' . $item["topicID"] . '">'. $item["topic"] . '</option>';
}
?>
</select>
<paper-input class="my-class" id="topicid" name="topicid" style="display:none;" ></paper-input>
<paper-input class="my-class" id="resourcetype" name="resourcetype" style="display:none;" ></paper-input>
<br><br>
<div id="resourceDiv" style="display: none;">
<select class="myselect" id="resourceSelect" onchange="getResource()">
<option value="0"><b>Select Resource Type</b></option>
<option value="Video"><b>Video</b></option>
<option value="Text"><b>Text</b></option>
<option value="Link"><b>Link</b></option>
</select>
</div>
<br>
<br>
<div id="videoDiv" style="display:none;">
<paper-input class="my-class" type="url" id="videourl" name="videourl" label="Enter a Video URL" ></paper-input>
Include http:// i.e. http://www.site.com
<paper-input class="my-class" id="videotext" name="videotext" label="Enter a Title for this Video" ></paper-input>
<br>
<paper-checkbox class="my-check" name="featuredcheck" id="featuredcheck" onclick="toggleFeatured();" >Featured</paper-checkbox>
<br>
<paper-input class="my-class" id="featured" name="featured" value="0" style="display:none;"></paper-input>
<br>
</div>
<div id="textDiv" style="display:none;">
<paper-textarea class="my-area-class" id="text" name="text" label="Resource"></paper-textarea>
You can enter HTML Tags into this field like <B>BOLD TEXT HERE</B> <br>
To enter line breaks please use the <BR> HTML tag. i.e. This is on one line <BR> this is on another<br>
<font style="color:red"> IF YOU SUBMIT A TEXT RESOURCE IT WILL OVERWRITE THE EXISTING TEXT DISPLAYED ON THE TOPIC PAGE. THERE CAN BE ONLY ONE TEXT RESOURCE PER TOPIC</font>
<br>
</div>
<div id="linkDiv" style="display:none;" >
<paper-input class="my-class" type="url" id="linkurl" name="linkurl" label="Enter a URL" ></paper-input>
Include http:// i.e. http://www.site.com
<paper-input class="my-class" id="linktext" name="linktext" label="Enter a Title for this Link" ></paper-input>
<br>
</div>
<paper-button id="my-button" name="my-button" class="my-button" raised onclick="submitForm();" style="display:none;">Add Resource(s)</paper-button>
<br>
<button type="submit" id="SubmitButton" name="submit" style="visibility:hidden;"></button>
</form>
<br>
<script>
function getTopic() {
document.getElementById("topicid").value=jQuery("#topicSelect option:selected").val();
if (jQuery("#topicSelect option:selected").val()==0){
document.getElementById("resourceDiv").style.display="none";
document.getElementById('videoDiv').style.display="none";
document.getElementById('textDiv').style.display="none";
document.getElementById('linkDiv').style.display="none";
document.getElementById('resourceSelect').selectedIndex=0;
}
else{
document.getElementById("resourceDiv").style.display="block";
}
}
function getResource() {
document.getElementById("resourcetype").value=jQuery("#resourceSelect option:selected").val();
if (jQuery("#resourceSelect option:selected").val()=='Video'){
document.getElementById('videoDiv').style.display="block";
document.getElementById('textDiv').style.display="none";
document.getElementById('linkDiv').style.display="none";
document.getElementById('my-button').style.display="block";
}
else if (jQuery("#resourceSelect option:selected").val()=='Text'){
document.getElementById('textDiv').style.display="block";
document.getElementById('videoDiv').style.display="none";
document.getElementById('linkDiv').style.display="none";
document.getElementById('my-button').style.display="block";
}
else if (jQuery("#resourceSelect option:selected").val()=='Link'){
document.getElementById('linkDiv').style.display="block";
document.getElementById('videoDiv').style.display="none";
document.getElementById('textDiv').style.display="none";
document.getElementById('my-button').style.display="block";
}
else{
document.getElementById('linkDiv').style.display="none";
document.getElementById('videoDiv').style.display="none";
document.getElementById('textDiv').style.display="none";
document.getElementById('my-button').style.display="none";
}
}
function toggleFeatured(){
if (document.getElementById('featured').value=="1"){
document.getElementById('featured').value="0";
}
else {
alert ("Setting this video to be featured will replace the video that is currently featured(if there is one) and that video will be moved to additional resources")
document.getElementById('featured').value="1";
}
//alert (document.getElementById('featured').value);
}
function submitForm(){
if (document.getElementById('videourl').value!='' && document.getElementById('videotext').value==''){
document.querySelector('#toast2').text= "You Entered a Video URL without giving it a title. Please either give it a title or remove the url and resubmit";
document.querySelector('#toast2').show();
document.getElementById('videoDiv').style.display="block";
document.getElementById('textDiv').style.display="none";
document.getElementById('linkDiv').style.display="none";
}
else if (document.getElementById('linkurl').value!='' && document.getElementById('linktext').value==''){
document.querySelector('#toast2').text= "You Entered a Link URL without giving it a title. Please either give it a title or remove the url and resubmit";
document.querySelector('#toast2').show();
document.getElementById('videoDiv').style.display="none";
document.getElementById('textDiv').style.display="none";
document.getElementById('linkDiv').style.display="block";
}
else{
document.querySelector('#toast').text= "Adding Topic Resource...";
document.querySelector('#toast').show();
document.getElementById('SubmitButton').click();
console.log("Submitted!")
}
//end
//document.getElementById('SubmitButton').click();
}
function disableType(){
alert (document.getElementById('videourl').value);
if (document.getElementById('videotext').value!='' || document.getElementById('videourl').value !=''
|| document.getElementById('text').value !='' ||document.getElementById('linkurl').value !='' ||document.getElementById('linktext').value!=''){
document.getElementById('resourceSelect').disabled=true;
}
else{
document.getElementById('resourceSelect').disabled=false;
}
}
function showTaskDialog(){
document.getElementById('instructions').toggle();
}
</script>
</center>
<br />
</paper-material>
</center>
<?php } else {?>
<h1> you do not have access</h1>
<?php }?>
</div>
</div>
</div>
</div>
<!-- /#page-content-wrapper -->
<paper-toast id="toast" text="Registering..."></paper-toast>
<paper-toast visible="false" id="toast2" text="Login Failed, Please Try Again..."></paper-toast>
<paper-dialog id="instructions" name="instructions" modal on-iron-overlay-closed="dismissDialog">
<h2 style="color: #28547a;">Instructions</h2>
<paper-dialog-scrollable>
<p style="color:black;font-size: 16px;font-weight: bold;">Select a topic that you want to add resources to, then select the resource type from the dropdown and fill out the information. You can add 1 to 3 resources per form submission; 1 video, 1 text and 1 link. You can submit more than 3 resources but only 3 per form submission. Once your fill out the first resrouce you can select a different resource type from the dropdown and populate that as well. There can be only one "Text" resource per topic. Any resource you set to Text will replace the current text under the featured video on the topic page. You can use HTML tags in the text resource type. There has to be one featured video per topic. If you add a new video and select it to be featured it will replace the currently featured video (if there is one) and then move that video url to the additonal resoucres section</p>
</paper-dialog-scrollable>
<div class="buttons">
<paper-button style="color:#28547a;" dialog-dismiss>OK</paper-button>
</div>
</paper-dialog>
</div>
<!-- /#wrapper -->
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js'></script>
<script src="js/index.js"></script>
<?php }?>
</body>
</html>