-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessVersion.php
More file actions
94 lines (71 loc) · 2.8 KB
/
Copy pathprocessVersion.php
File metadata and controls
94 lines (71 loc) · 2.8 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
<?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);
if(isset($_POST['parent'])){
$parent = $_POST['parent'];
$parent = stripslashes($parent);
}else {
$parent = 0;
}
$projectID = $_POST['projectID'];
$projectID = stripslashes($projectID);
if(isset($_POST['file'])){
$file = $_POST['file'];
}else {
$file = "no file";
}
$query = "SELECT * FROM versions WHERE projectID='$projectID'";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$rows = mysqli_num_rows($result);
if($rows>=1){
while($row = mysqli_fetch_array($result)) {
$c = 2;
if($row[2] == $title){
$title = $title . "_" . $c;
}else if(strtok($row[2], '_') == $title){
$c = substr($row[2], strpos($row[2], "_") + 2);
$c++;
$title = $title . "_" . $c;
}
}
}
$timestamp = date('Y-m-d h:i:s');
$query = "INSERT INTO versions (projectID, title, description, parent, file, timestamp, username) VALUES ('".$projectID."', '".
$title."', '".
$description."', '".
$parent."', '".
$file."', '".
$timestamp."', '".
$username."')";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
//new search to make sure the added version is loaded on creation
$query = "SELECT * FROM versions WHERE projectID='$projectID' ORDER BY timestamp DESC LIMIT 1";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$row = mysqli_fetch_array($result);
$data['versionID'] = $row[1];
}
$data['success'] = true;
$data['message'] = 'Success!';
}
// return all our data to an AJAX call
echo json_encode($data);