-
Notifications
You must be signed in to change notification settings - Fork 5
/
actions.php
executable file
·77 lines (63 loc) · 2.58 KB
/
actions.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
<?php
require_once("../../global/library.php");
use FormTools\Modules;
use FormTools\Sessions;
use FormTools\Submissions;
use FormTools\ViewFields;
switch ($request["action"]) {
// called by the administrator or client on the Edit Submission page
case "delete_submission_files":
$module = Modules::initModulePage("client");
$form_id = Sessions::get("curr_form_id");
$submission_id = Sessions::get("last_submission_id");
$view_id = Sessions::get("form_{$form_id}_view_id");
$field_id = $request["field_id"];
// check the submission and field being deleted belongs to the View the user is in
$view_field = ViewFields::getViewField($view_id, $field_id);
if (!Submissions::checkViewContainsSubmission($form_id, $view_id, $submission_id) || empty($view_field)) {
output_json_with_return_vars(array(
"success" => false,
"message" => "Permission denied."
));
break;
}
$files = $request["files"];
$force_delete = ($request["force_delete"] == "true") ? true : false;
list ($success, $message, $deleted_files) = $module->deleteFilesFromField($form_id, $submission_id, $field_id, $files, $force_delete);
output_json_with_return_vars(array(
"success" => $success,
"message" => $message,
"deleted_files" => $deleted_files
));
break;
// this is called when the field type is being used in the Form Builder. This is just slightly more restrictive than
// the logged-in context: it pulls the form ID and submission ID from sessions instead of from the page (which could
// be hacked)
case "delete_submission_file_standalone":
$module = Modules::initModulePage();
$published_form_id = (isset($request["published_form_id"])) ? $request["published_form_id"] : "";
if (empty($published_form_id)) {
output_json_with_return_vars(array(
"success" => 0,
"message" => "Your form is missing the form_tools_published_form_id ID field."
));
exit;
}
$form_id = $_SESSION["form_builder_{$published_form_id}"]["form_tools_form_id"];
$submission_id = $_SESSION["form_builder_{$published_form_id}"]["form_tools_submission_id"];
$field_id = $request["field_id"];
$force_delete = ($request["force_delete"] == "true") ? true : false;
$files = $request["files"];
list ($success, $message, $deleted_files) = $module->deleteFilesFromField($form_id, $submission_id, $field_id, $files, $force_delete);
output_json_with_return_vars(array(
"success" => 1,
"message" => $message,
"deleted_files" => $deleted_files
));
break;
}
function output_json_with_return_vars($data)
{
global $request;
echo json_encode(array_merge($request["return_vars"], $data));
}