Skip to content

Commit 1457f45

Browse files
committed
2.0.0
1 parent 162aa1c commit 1457f45

File tree

7 files changed

+940
-1001
lines changed

7 files changed

+940
-1001
lines changed

actions.php

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,62 @@
11
<?php
22

3-
require_once("../../global/session_start.php");
4-
require_once(dirname(__FILE__) . "/library.php");
5-
ft_check_permission("user");
6-
7-
$request = array_merge($_POST, $_GET);
8-
9-
$return_str = "";
10-
if (isset($request["return_vars"]))
11-
{
12-
$vals = array();
13-
while (list($key, $value) = each($request["return_vars"]))
14-
{
15-
$vals[] = "\"$key\": \"$value\"";
16-
}
17-
$return_str = ", " . implode(", ", $vals);
3+
require_once("../../global/library.php");
4+
5+
use FormTools\Modules;
6+
7+
$module = Modules::initModulePage("client");
8+
9+
10+
switch ($request["action"]) {
11+
12+
// called by the administrator or client on the Edit Submission page. Note that we pull the submission ID
13+
// and the form ID from sessions rather than have them explictly passed by the JS. This is a security precaution -
14+
// it prevents a potential hacker exploiting this function here. Instead they'd have to set the sessions by another
15+
// route which is trickier
16+
case "delete_submission_file":
17+
$form_id = $request["form_id"];
18+
$submission_id = $request["submission_id"];
19+
$field_id = $request["field_id"];
20+
$force_delete = ($request["force_delete"] == "true") ? true : false;
21+
22+
// TODO beef up the security here. Check that the person logged in is permitted to see this submission & field...
23+
24+
list ($success, $message) = $module->deleteFileSubmission($form_id, $submission_id, $field_id, $force_delete);
25+
output_json_with_return_vars(array(
26+
"success" => ($success) ? 1 : 0,
27+
"message" => $message
28+
));
29+
break;
30+
31+
// this is called when the field type is being used in the Form Builder. This is just slightly more restrictive than
32+
// the logged-in context: it pulls the form ID and submission ID from sessions instead of from the page (which could
33+
// be hacked)
34+
case "delete_submission_file_standalone":
35+
$published_form_id = (isset($request["published_form_id"])) ? $request["published_form_id"] : "";
36+
37+
if (empty($published_form_id)) {
38+
output_json_with_return_vars(array(
39+
"success" => 0,
40+
"message" => "Your form is missing the form_tools_published_form_id ID field."
41+
));
42+
exit;
43+
}
44+
$form_id = $_SESSION["form_builder_{$published_form_id}"]["form_tools_form_id"];
45+
$submission_id = $_SESSION["form_builder_{$published_form_id}"]["form_tools_submission_id"];
46+
$field_id = $request["field_id"];
47+
$force_delete = ($request["force_delete"] == "true") ? true : false;
48+
49+
list ($success, $message) = $module->deleteFileSubmission($form_id, $submission_id, $field_id, $force_delete);
50+
output_json_with_return_vars(array(
51+
"success" => 0,
52+
"message" => $message
53+
));
54+
break;
1855
}
1956

2057

21-
switch ($request["action"])
58+
function output_json_with_return_vars($data)
2259
{
23-
// called by the administrator or client on the Edit Submission page. Note that we pull the submission ID
24-
// and the form ID from sessions rather than have them explictly passed by the JS. This is a security precaution -
25-
// it prevents a potential hacker exploiting this function here. Instead they'd have to set the sessions by another
26-
// route which is trickier
27-
case "delete_submission_file":
28-
$form_id = $request["form_id"];
29-
$submission_id = $request["submission_id"];
30-
$field_id = $request["field_id"];
31-
$force_delete = ($request["force_delete"] == "true") ? true : false;
32-
33-
// TODO beef up the security here. Check that the person logged in is permitted to see this submission & field...
34-
35-
list($success, $message) = ft_file_delete_file_submission($form_id, $submission_id, $field_id, $force_delete);
36-
$success = ($success) ? 1 : 0;
37-
$message = ft_sanitize($message);
38-
$message = preg_replace("/\\\'/", "'", $message);
39-
echo "{ \"success\": \"$success\", \"message\": \"$message\" {$return_str} }";
40-
break;
41-
42-
// this is called when the field type is being used in the Form Builder. This is just slightly more restrictive than
43-
// the logged-in context: it pulls the form ID and submission ID from sessions instead of from the page (which could
44-
// be hacked)
45-
case "delete_submission_file_standalone":
46-
$published_form_id = (isset($request["published_form_id"])) ? $request["published_form_id"] : "";
47-
if (empty($published_form_id))
48-
{
49-
echo "{ \"success\": \"0\", \"message\": \"Your form is missing the form_tools_published_form_id ID field.\" {$return_str} }";
50-
exit;
51-
}
52-
$form_id = $_SESSION["form_builder_{$published_form_id}"]["form_tools_form_id"];
53-
$submission_id = $_SESSION["form_builder_{$published_form_id}"]["form_tools_submission_id"];
54-
$field_id = $request["field_id"];
55-
$force_delete = ($request["force_delete"] == "true") ? true : false;
56-
57-
list($success, $message) = ft_file_delete_file_submission($form_id, $submission_id, $field_id, $force_delete);
58-
$success = ($success) ? 1 : 0;
59-
$message = ft_sanitize($message);
60-
$message = preg_replace("/\\\'/", "'", $message);
61-
echo "{ \"success\": \"$success\", \"message\": \"$message\" {$return_str} }";
62-
break;
63-
}
60+
global $request;
61+
echo json_encode(array_merge($request["return_vars"], $data));
62+
}

0 commit comments

Comments
 (0)