-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubfield.php
More file actions
82 lines (68 loc) · 2.79 KB
/
subfield.php
File metadata and controls
82 lines (68 loc) · 2.79 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
<?php
/* ---------------------------------
--------------- MODEL --------------
--------------------------------- */
include("content/includes/model.php");
$field_id = (isset($_GET["field_id"])) ? $_GET["field_id"] : NULL;
if (isset($field_id) && check_field_id($field_id)) {
$actions = array("add", "edit", "delete");
$action = (isset($_GET["action"])) ? $_GET["action"] : NULL;
$id = (isset($_GET["id"]) && is_numeric($_GET["id"])) ? (intval($_GET["id"]) - 1) : NULL;
$content = get_field($field_id)["content"];
if (isset($action) && in_array($action, $actions) && (isset($id) && check_subfield_id($content, $id) || $action == "add")) {
if ($action == "add" || $action == "edit") {
$types = array(
"text" => "Texte",
"image" => "Image"
);
$type = get_field_type($field_id);
if (in_array($type, array_keys($types))) {
if ($type == "text") {
$data = (isset($_POST["text"])) ? htmlspecialchars($_POST["text"], ENT_QUOTES) : NULL;
} else {
$data = (isset($_FILES["file"])) ? $_FILES["file"] : NULL;
}
if (isset($data)) {
$errors = get_subfield_errors($type, $data);
if ($errors["valid"]) {
$data = (isset($errors["image_path"])) ? $errors["image_path"] : $data;
if ($action == "add") {
add_subfield($field_id, $content, $data);
} else {
edit_subfield($field_id, $id, $content, $data);
}
header("Location: " . $config["sitelink"] . "/field/edit/" . $field_id);
exit();
}
}
if ($action == "edit") {
$data = $content[$id];
}
$page = array(
"link" => $config["sitelink"] . "/subfield/" . $field_id . "/" . $action . ($action == "add" ? "" : "/" . ($id + 1)),
"title" => ($action == "add") ? (($type == "text") ? "Ajout d'un texte" : "Ajout d'une image") : (($type == "text") ? "Modification d'un texte" : "Modification d'une image"),
"breadcrumb" => ($action == "add") ? "Ajouter" : "Modifier",
"btn_text" => ($action == "add") ? (($type == "text") ? "Ajouter le texte" : "Ajouter l'image") : (($type == "text") ? "Modifier le texte" : "Modifier l'image"),
);
} else {
header("Location: " . $config["sitelink"] . "/fields");
exit();
}
} else {
delete_subfield($field_id, $id, $content);
header("Location: " . $config["sitelink"] . "/field/edit/" . $field_id);
exit();
}
} else {
header("Location: " . $config["sitelink"] . "/field/edit/" . $field_id);
exit();
}
} else {
header("Location: " . $config["sitelink"] . "/fields");
exit();
}
mysqli_close($db);
/* ---------------------------------
---------------- VUE ---------------
--------------------------------- */
include("content/vues/subfield.php");