-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoin-project.php
executable file
·152 lines (133 loc) · 4.07 KB
/
join-project.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
<?php
/**
* @src /join-project.php
* Join Project page
* @author Fred Stark
*/
require_once('includes/include.php');
// Set page settings
$pageTitle = "Collaborate - ProjectHub";
$style = "project";
//User must be logged in
if (!$user->isLoggedIn){ header("Location: http://".$_SERVER['HTTP_HOST']); die(); }
if(empty($_GET))
{
if(empty($_POST)) {
echo "<script>history.go(-1);</script>";
die();
}
}
$roleId = (isset($_GET['role'])) ? $_GET['role'] : "" ;
$project = new Project();
if (isset($_GET['id'])) {
$project->getById($_GET['id']);
} else {
$project->getById($_POST['project']);
}
// Process creation if forms posted
if(!empty($_POST))
{
//Perform some validation
// if(strlen($title) == 0 )
// {
// $errors[] = "Looks like you forgot to enter a title! A title helps draw attention to your project.";
// }
//End data validation
if(count($errors) == 0)
{
//Construct a project object and populate its variables
$joinRequest = new JoinRequest();
$joinRequest->projectId = $_POST["project"];
$joinRequest->user = $user;
$joinRequest->message = $_POST["message"];
$joinRequest->role = new Role();
if ($_POST['role'] !== "") { $joinRequest->role->getById($_POST['role']); }
// Persist new project to database
$result = $joinRequest->saveToDatabase();
if($result)
{
$message[] = "Request sent successfully";
$_SESSION['message'] = $message;
$user->tags = explode(',', $_POST['skills']);
$result = $user->saveToDatabase();
if (!$result) {
$errors[] = "could not add skills";
} else {
header("Location: http://".$_SERVER['HTTP_HOST']."/project.php?id=".$_POST["project"]);
die();
}
}
else
{
$message[] = $result;
$_SESSION['message'] = $message;
}
}
}
// Load form
include 'includes/header.php';
include 'includes/navbar.php';
echo <<<HTML
<div class="container">
<div class="content">
<div class="projectTitle bootstrap">
<h1>Join $project->title <br/>
<small> </small>
</h1>
</div>
<div id="success">
HTML;
if (isset($message)) {
foreach ($message as $message) { echo "<p class='message'>".$message."</p>"; }
unset($_SESSION['message']);
}
if (isset($errors)) {
foreach ($errors as $error) { echo "<p class='error'>".$error."</p>"; }
unset($_SESSION['errors']);
}
echo <<<HTML
</div>
<div class="boxLayout">
<div id="regbox" class="bootstrap">
<form name="join" action="{$_SERVER['PHP_SELF']}" method="post">
<p>
<label><h3>Write a quick message to the team</h3></label>
<small>Tell why you want to work on "{$project->title}" </small><br>
<textarea name="message" id="message"></textarea>
</p>
<p>
<label><h3>What skills do you bring?:</h3></label>
HTML;
?> <input type="text" id="skills" name="skills" style="width:33%" value="<?php echo implode(", ", $user->tags); ?>"/>
<?php echo <<<HTML
</p>
<p>
<input type="hidden" name="project" value="{$project->projectId}" />
<input type="hidden" name="role" value="{$roleId}" />
<button type="submit" name="submit" value="submit" class="btn btn-success">Send Request</button>
</p>
</form>
</div>
</div>
</div>
</div>
HTML;
?>
<script>
$(function() {
$('#message').editable({
inlineMode: false,
language: 'en_gb',
buttons: ['undo', 'redo' , 'sep', 'bold', 'italic', 'underline']
});
});
$("#skills").select2({
tags: [],
tokenSeparators: [",", " "],
placeholder: "type your skills separated by commas",
formatNoMatches: "type to search or add new skills"
});
</script>
<?php
include('includes/footer.php');
?>