-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.php
More file actions
107 lines (75 loc) · 3.35 KB
/
Copy pathprocess.php
File metadata and controls
107 lines (75 loc) · 3.35 KB
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
<?php
$errors = array(); // array to hold validation errors
$data = array(); // array to pass back data
// validate the variables ======================================================
// if any of these variables don't exist, add an error to our $errors array
if (empty($_POST['title']))
$errors['title'] = 'Title is required.';
if (empty($_POST['description']))
$errors['description'] = 'Description is required.';
if ( ! empty($errors)) {
// if there are items in our errors array, return those errors
$data['success'] = false;
$data['errors'] = $errors;
} else {
session_start();
require('db.php');
if (isset($_SESSION['username'])){
$username = $_SESSION['username'];
$username = stripslashes($username);
$title = $_POST['title'];
$title = stripslashes($title);
$description = $_POST['description'];
$description = stripslashes($description);
$query = "SELECT * FROM projects WHERE title='$title'";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$rows = mysqli_num_rows($result);
if($rows>=1){
$data['success'] = false;
$errors['title'] = 'Title is taken.';
$data['errors'] = $errors;
}else{
$projectID;
$last_version = 0;
$query = "INSERT INTO projects (username, title, description, last_version) VALUES ('".$username."', '".$title."', '".$description."', '".$last_version."')";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$query = "SELECT * FROM projects WHERE title='$title'";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$rows = mysqli_num_rows($result);
if($rows>=1){
while($row = mysqli_fetch_array($result)) {
$projectID = $row[1];
$data['projectID'] = $row[1];
}
}
$timestamp = date('Y-m-d h:i:s');
$query = "INSERT INTO versions (projectID, title, description, parent, file, timestamp, username) VALUES ('".$projectID.
"', 'Ver 1', 'Default version text, please edit to your liking using the pencil icon in the top right', '0', 'no file','".$timestamp."', '".$username."')";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$query = "SELECT * FROM versions WHERE projectID='$projectID' ORDER BY timestamp ASC LIMIT 1";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$row = mysqli_fetch_array($result);
$data['versionID'] = $row[1];
$colorBits = "";
foreach (range(1, 17) as $i) {
$colorBits = $colorBits . rand(0,1) . ",";
}
$color = "";
$query = "SELECT * FROM icon_colors ORDER BY RAND() LIMIT 1";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$rows = mysqli_num_rows($result);
if($rows>=1){
while($row = mysqli_fetch_array($result)) {
$color = $row[0];
}
}
$query = "INSERT INTO project_icons (projectID, colorBits, color, username) VALUES ('".$projectID."', '".$colorBits."', '".$color."', '".$username."')";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$data['success'] = true;
$data['message'] = 'Success!';
}
}
}
// return all our data to an AJAX call
echo json_encode($data);
?>