-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsave_to_db.php
48 lines (41 loc) · 1.41 KB
/
save_to_db.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
<?php
include("functions.php");
$status = [ "status" => "error", "msg" => "Something went wrong while saving the model" ];
if(array_key_exists("session_id", $_COOKIE)) {
$keys = ["model_structure", "model_weights", "model_data", "requests_public", "category_full", "network_name"];
$data = array();
foreach ($keys as $key) {
if(array_key_exists($key, $_POST) && $_POST[$key]) {
$data[$key] = $_POST[$key];
} else {
print "$key does not exist";
exit(0);
}
}
if(get_number_model_names($data["network_name"]) != 0) {
$status["msg"] = "Model name already exists.";
exit(0);
}
$user = get_user_id_from_session_id($_COOKIE["session_id"]);
if(is_null($user)) {
$status["msg"] = "User doesn't exist.";
} else {
$model_structure = $data["model_structure"];
$model_weights = $data["model_weights"];
$model_data = $data["model_data"];
$is_public = $data["requests_public"];
$category_full = $data["category_full"];
$network_name = $data["network_name"];
$new_id = save_to_db($model_structure, $model_weights, $model_data, $user, $is_public, $network_name);
if($new_id) {
$status = [ "status" => "ok", "msg" => "Saving data was successful.", "id" => $new_id ];
} else {
$status["msg"] = "Failed to save to the DB.";
}
}
} else {
$status["msg"] = "You are not logged in.";
}
header('Content-Type: application/json');
print json_encode($status);
?>