-
Notifications
You must be signed in to change notification settings - Fork 0
/
createProjectAction.php
90 lines (63 loc) · 2.81 KB
/
createProjectAction.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
<?php
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// ...
$project_id = $_POST["project-Id"];
$project_name = $_POST["project-name"];
$supervisor = $_POST["supervisor-name"];
$project_des = $_POST["project-description"];
$creator_mail = $_POST["project-creator-mail"];
// Database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Kanban_Board";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (isset($_SESSION['rfemail'])) {
$rfemail = $_SESSION['rfemail'];
}
$_SESSION['project_creator_email']=$creator_mail;
$verificationID = generateVerificationID();
$_SESSION['verificationID'] =$verificationID;
$sql = "INSERT INTO CreateProjectInfo (User_Email,Project_ID, Project_Name, Supervisor_Name, Project_Description, Project_Creator_Eail,VerificationID)
VALUES ('$rfemail','$project_id', '$project_name', '$supervisor','$project_des', '$creator_mail','$verificationID')";
if ($conn->query($sql) === TRUE) {
$subject = "Your are invited as supervisor in project ".$project_name;
$message = "Use the join ID and Verification ID to Join Your Project:\n";
$message .= "Join ID: $project_id" . "& Verification ID=" . urlencode($verificationID);
$headers = "From: ij.jhumu.nstu@gmail.com";
if(mail($creator_mail, $subject, $message, $headers)){
$sql2 = "INSERT INTO ProjectMember (Project_ID,User_Email,Invited_Member_Email,Reference_Code)
VALUES ('$project_id','$rfemail','$creator_mail','$verificationID')";
if ($conn->query($sql2) === TRUE) {
header("Location: home.php");
exit;
} else {
header("Location: home.php");
exit;
}
}else{
// $_SESSION['success'] = "Verification Email sending failed.";
header("Location: home.php");
exit;
}
}else {
$_SESSION['projectidbooked']="Try different Project ID";
header("Location: CreateProjectForm.php");
}
$conn->close();
}
function generateVerificationID() {
// Generate a random 6-character alphanumeric code
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$verificationCode = '';
for ($i = 0; $i < 6; $i++) {
$index = rand(0, strlen($characters) - 1);
$verificationCode .= $characters[$index];
}
return $verificationCode;
}
?>