-
Notifications
You must be signed in to change notification settings - Fork 0
/
profiles.php
97 lines (97 loc) · 3.85 KB
/
profiles.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
<?php
require './includes/config.inc.php';
include './includes/login.inc.php';
$row = null;
//check if we are viewing a specific profile
if (isset($_GET['id']) || isset($_GET['name'])) {
if (isset($_GET['id']) && filter_var($_GET['id'], FILTER_VALIDATE_INT, array('min_range'=>1))) {
$pid = $_GET['id'];
//query profiles database
require_once MYSQL;
$r = $dbc->query("CALL get_profile ('id', $pid, NULL)");
$row = $r->fetch(PDO::FETCH_ASSOC);
if (empty($row)) { //if no results
$pageTitle = 'Profile Not Found';
include './includes/header.html';
echo '<div class="centeredDiv"><h2>No profile found!</h2></div>';
include './includes/footer.html';
exit();
}
$r->closeCursor();
}else if (isset($_GET['name']) && preg_match('/^[a-zA-Z\'\-]+ [a-zA-Z\'\-]+$/', $_GET['name'])) {
$name = $_GET['name'];
//query profiles thru user name
require_once MYSQL;
$q = "CALL get_profile ('name', NULL, '$name')";
$stmt = $dbc->prepare($q);
$stmt->execute(array($name));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (empty($row)) {
$pageTitle = 'Profile Not Found';
include './includes/header.html';
echo '<div class="centeredDiv"><h2>No profile found!</h2></div>';
include './includes/footer.html';
exit();
}
$stmt->closeCursor();
}
//if query succeeded, show profile view
if (!empty($row)) {
//parse the links
if (!empty($row['links'])) {
$links = explode('|', $row['links']);
$linkURL = array();
$linkDesc = array();
foreach ($links as $i=>$pair) {
$a = explode('\\', $pair);
$linkURL[$i] = $a[0];
$linkDesc[$i] = $a[1];
}
}
//get relevant events info for this profile
$events = array();
$q = $dbc->query("SELECT id, DATE_FORMAT(`date`, '%a. %M %D, %Y') AS edate, start_time, end_time, title, venue
FROM events_profiles JOIN events ON event_id=id
WHERE profile_id={$row['user_id']} AND `date` >= CURDATE()
ORDER BY `date` ASC, start_time ASC");
while ($r = $q->fetch(PDO::FETCH_ASSOC)) {
//check if event has ending time
if (!empty($r['end_time']))
$r['time'] = parseTime($r['start_time']).'-'.parseTime($r['end_time']);
else
$r['time'] = parseTime($r['start_time']);
$events[$r['edate']][] = $r;
}
//get associated secondary instruments
$secInstr = array();
$q = 'SELECT instr.name FROM instr JOIN profiles_secondaryinstr ON instr.id=instr_id WHERE profile_id='.$row['user_id'];
$stmt = $dbc->query($q);
while ($instrName = $stmt->fetchColumn()) {
$secInstr[] = ucwords($instrName);
}
//display the profile view
$pageTitle = $row['name'];
include './includes/header.html';
include './views/profile_view.html';
include './includes/footer.html';
exit();
}
}
//show the profile selection page.
require_once MYSQL;
$pageTitle = 'Musician Profiles';
include './includes/header.html';
//get all profiles sorted by instr
$baseInstr = array ('bass','drums','guitar','piano','saxophone','trombone','trumpet','vocal');
$r = $dbc->query('CALL get_profiles ()');
$rows = array();
while ($row = $r->fetch(PDO::FETCH_ASSOC)) {
$rows[$row['instr_name']][] = $row; //fetch all rows into this array of arrays indexed by instr name
}
if (empty($rows)) {
echo '<div class="centeredDiv"><h2>No profiles exist.</h2></div>';
}else{
include './views/profiles.html';
}
include './includes/footer.html';
?>