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

Commit

Permalink
fix(resource): Fix bad SQL request (#11702) (#11751)
Browse files Browse the repository at this point in the history
  • Loading branch information
callapa authored Sep 13, 2022
1 parent 66a3ec7 commit 3a4ce8b
Showing 1 changed file with 28 additions and 17 deletions.
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

0 comments on commit 3a4ce8b

Please sign in to comment.