-
Notifications
You must be signed in to change notification settings - Fork 0
/
courses_teacher.php
57 lines (48 loc) · 1.58 KB
/
courses_teacher.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
<?php
session_start();
require_once('config.php');
require_once('functions.php');
if(!db_check_larare($_SESSION['sendMe']['id'])) {
header("Location: index.php");
}
$message = "";
if(isset($_GET['action'])) {
$action = $_GET['action'];
if($action == "delete") {
$id = db_clean($_GET['id']);
$sql = "SELECT id FROM kurs WHERE id='$id' AND skapad_av='$userId' LIMIT 1";
if(mysql_num_rows(mysql_query($sql)) == 1) {
$sql = "UPDATE kurs SET active='0' WHERE id='$id' AND skapad_av='$userId' LIMIT 1";
mysql_query($sql);
$message = "Kursen togs bort.";
}
}
}
// Skapa en kurs
if(isset($_POST['courseName'])) {
$kursNamn = db_clean($_POST['courseName']);
if(db_check_course_name($kursNamn)) {
$message = "Kursnamnet finns redan!";
} else {
// Skapa kursen
$sql = "INSERT INTO kurs(namn, skapad_av, skapad_datum) VALUES('".
$kursNamn."','".$_SESSION['sendMe']['id']."','".time()."')";
mysql_query($sql);
$message = "Kursen skapades";
}
}
$sql = "SELECT * FROM kurs WHERE skapad_av='".$_SESSION['sendMe']['id']."' AND active='1' ORDER BY namn";
$q = mysql_query($sql);
if(mysql_num_rows($q) > 0) {
while($r = mysql_fetch_array($q)) {
$_kurser[] = $r;
}
}
$smarty->assign('message', $message);
$smarty->assign('userName', $userName);
$smarty->assign('siteMenu', create_menu($userId));
$smarty->assign('title', "SendMe :: Hantera mina kurser");
$smarty->assign('kurser', $_kurser);
$smarty->assign('page', "courses_teacher");
$smarty->display('main.tpl');
?>