Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

fix(resource): Fix bad SQL request #11702 #11749

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions www/include/configuration/configResources/DB-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,23 +294,34 @@ function insertResource($ret = array())
if (!count($ret)) {
$ret = $form->getSubmitValues();
}
$rq = "INSERT INTO cfg_resource ";
$rq .= "(resource_name, resource_line, resource_comment, resource_activate) ";
$rq .= "VALUES (";
isset($ret["resource_name"]) && $ret["resource_name"] != null
? $rq .= "'" . $pearDB->escape($ret["resource_name"]) . "', "
: $rq .= "NULL, ";
isset($ret["resource_line"]) && $ret["resource_line"] != null
? $rq .= "'" . $pearDB->escape($ret["resource_line"]) . "', "
: $rq .= "NULL, ";
isset($ret["resource_comment"]) && $ret["resource_comment"] != null
? $rq .= "'" . $pearDB->escape($ret["resource_comment"]) . "', "
: $rq .= "NULL, ";
isset($ret["resource_activate"]["resource_activate"]) && $ret["resource_activate"]["resource_activate"] != null
? $rq .= "'" . $ret["resource_activate"]["resource_activate"] . "'"
: $rq .= "NULL";
$rq .= ")";
$pearDB->query($rq);
$statement = $pearDB->prepare(
"INSERT INTO cfg_resource
(resource_name, resource_line, resource_comment, resource_activate)
VALUES (:name, :line, :comment, :is_activated)"
);
$statement->bindValue(
':name',
! empty($ret["resource_name"])
? $ret["resource_name"]
: null
);
$statement->bindValue(
':line',
! empty($ret["resource_line"])
? $ret["resource_line"]
: null
);
$statement->bindValue(
':comment',
! empty($ret["resource_comment"])
? $ret["resource_comment"]
: null
);
$isActivated = isset($ret["resource_activate"]["resource_activate"])
&& (bool) (int) $ret["resource_activate"]["resource_activate"];
$statement->bindValue(':is_activated', (string) (int) $isActivated);
$statement->execute();

$dbResult = $pearDB->query("SELECT MAX(resource_id) FROM cfg_resource");
$resource_id = $dbResult->fetch();

Expand Down