-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcourses_student.php
74 lines (58 loc) · 2.28 KB
/
courses_student.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
<?php
session_start();
if(!isset($_SESSION['sendMe']['id'])) {
header("Location: index.php");
}
require('config.php');
require('functions.php');
$userName = $_SESSION['sendMe']['fullName'];
$userId = $_SESSION['sendMe']['id'];
$menu = create_menu($userId);
$message = "";
$_minaKurserAntal = 0;
if(isset($_POST['submitAddCourse'])) {
$kurs_id = db_clean($_POST['kurs_id']);
//$message = $kurs_id;
$sql = "SELECT id FROM kurs_user WHERE user_id='".$_SESSION['sendMe']['id']."' AND kurs_id='$kurs_id' LIMIT 1";
if(mysql_num_rows(mysql_query($sql)) == 1) {
$message = "Du är redan medlem i den kursen.";
} else {
$sql = "INSERT INTO kurs_user(user_id, kurs_id) VALUES('".$_SESSION['sendMe']['id']."','".$kurs_id."')";
mysql_query($sql);
$message = "Du lades till i kursen ".db_get_course_name($kurs_id)." .";
}
}
// Hämta alla kurser
$sql = "SELECT id, namn, skapad_av FROM kurs WHERE active='1' ORDER BY namn";
$q = mysql_query($sql);
if(mysql_num_rows($q) > 0) {
while($r = mysql_fetch_array($q)) {
$_kurser[] = $r;
}
}
// Hämta vilka kurser jag är med i
//$sql = "SELECT kurs.id, kurs.namn, CONCAT(users.fnamn, " ", users.enamn) AS larare FROM kurs LEFT JOIN users ON kurs.skapad_av=users.id WHERE kurs.active='1' ORDER BY namn";
$sql = "SELECT kurs.id, kurs.namn, CONCAT(users.fnamn, ' ', users.enamn) AS larare FROM kurs_user LEFT JOIN kurs ON kurs_user.kurs_id=kurs.id LEFT JOIN users ON kurs.skapad_av=users.id WHERE user_id='$userId' AND kurs_user.active='1' AND kurs.active='1'";
//$sql = "SELECT kurs_id FROM kurs_user WHERE user_id='".$_SESSION['sendMe']['id']."' AND active='1'";
$q = mysql_query($sql);
if(mysql_num_rows($q) > 0) {
while($r = mysql_fetch_array($q)) {
$_minaKurser[] = $r;
$_minaKurserAntal++;
}
} else {
$_minaKurser[] = "";
}
$smarty->assign('message', $message);
$smarty->assign('userName', $userName);
$smarty->assign('siteMenu', $menu);
$smarty->assign('title', "SendMe :: Mina kurser");
$smarty->assign('kurser', $_kurser);
$smarty->assign('minaKurser', $_minaKurser);
$smarty->assign('minaKurserAntal', $_minaKurserAntal);
$smarty->assign('page', "courses_student");
$smarty->display('main.tpl');
die();
?>
<?php
?>