php - 2个复选框之间的链接问题,不应该插入数据
问题描述
好的,我有一个问题。让我解释一下。
我需要列出一些输入(复选框)中的所有模式,然后我们可以选择我们想要操作的模式,以赋予特定用户特权。
无论如何,我得到了这个,正如你所看到的:
<div id="list-schemas">
<?php
foreach ($schemas as $elt) {
echo '<input type="checkbox" name="schemas[]" value="' . $elt->getSchema() . '"/>' . $elt->getSchema() . '<br />';
}
?>
</div>
然后,我还需要放置一些具有权限的复选框,我这样做了:
<div id="div-privileges">
<?php
foreach ($schemas as $elt) {
echo '<div class="list">';
echo '<label for="list">' . $elt->getSchema() . ' :</label><br />';
echo '<input type="checkbox" name="privileges[' . $elt->getSchema() . '][]" value="REVOKE"/> REVOKE ? <br />';
echo '<input type="checkbox" name="privileges[' . $elt->getSchema() . '][]" value="ALL"/> ALL PRIVILEGES ? <br />';
echo '<hr>';
echo '<input type="checkbox" name="privileges[' . $elt->getSchema() . '][]" value="SELECT"/> SELECT ? <br />';
echo '<input type="checkbox" name="privileges[' . $elt->getSchema() . '][]" value="INSERT"/> INSERT ? <br />';
echo '<input type="checkbox" name="privileges[' . $elt->getSchema() . '][]" value="UPDATE"/> UPDATE ? <br />';
echo '<input type="checkbox" name="privileges[' . $elt->getSchema() . '][]" value="DELETE"/> DELETE ? <br />';
echo '<hr>';
echo '<input type="checkbox" name="privileges[' . $elt->getSchema() . '][]" value="CREATE"/>CREATE ? <br />';
echo '</div>';
}
?>
</div>
看起来像这样:https ://image.noelshack.com/fichiers/2019/37/3/1568191628-capture2.png
所以,这就是说,这是我在 UserManager.class.php 中的函数更新:
public static function update(User $newPerso){
$db = DbConnect::getDb();
$newLogin= pg_escape_string($newPerso->getLogin());
$arraySchemas=$newPerso->getSchemas();
$arrayPrivileges=$newPerso->getPrivileges();
if (isset($arraySchemas)){
foreach($arrayPrivileges as $schema => $privileges){
if (isset($arrayPrivileges)){
foreach($privileges as $privilege){
if($privilege=="REVOKE"){
pg_query("{$privilege} ALL ON ALL TABLES IN SCHEMA {$schema} FROM {$newLogin};");
}
else if($privilege=="CREATE"){
pg_query("GRANT {$privilege} ON SCHEMA {$schema} TO {$newLogin};");
}
else if($privilege=="ALL" || $privilege=="INSERT" || $privilege=="SELECT" || $privilege=="UPDATE" || $privilege=="DELETE"){
pg_query("GRANT {$privilege} ON ALL TABLES IN SCHEMA {$schema} TO {$newLogin};");
}
}
}
}
}
}
事实是,当我这样做时:https ://image.noelshack.com/fichiers/2019/37/3/1568193038-capture3.png
它有效,用户将在“公共”上使用 SELECT + INSERT 并在“schematest”上使用 UPDATE + DELETE
但,
当我这样做时:https ://image.noelshack.com/fichiers/2019/37/3/1568186255-capture.png
我的用户将拥有(在该示例中):
这两种模式中的所有特权...
它适用于“公共”是正常的,但我如何才能防止“schematest”..?
解决方案
伙计们,我添加了一个“&& in_array($schema, $arraySchemas)”
它现在似乎有效,让我告诉你:
public static function update(User $newPerso){
$db = DbConnect::getDb();
$newLogin= pg_escape_string($newPerso->getLogin());
$arraySchemas=$newPerso->getSchemas();
$arrayPrivileges=$newPerso->getPrivileges();
if (isset($arraySchemas)){
foreach($arrayPrivileges as $schema => $privileges){
if (isset($arrayPrivileges) && in_array($schema, $arraySchemas)){ /****<- RIGHT HERE****/
foreach($privileges as $privilege){
if($privilege=="REVOKE"){
pg_query("{$privilege} ALL ON ALL TABLES IN SCHEMA {$schema} FROM {$newLogin};");
}
else if($privilege=="CREATE"){
pg_query("GRANT {$privilege} ON SCHEMA {$schema} TO {$newLogin};");
pg_query("GRANT USAGE ON SCHEMA {$schema} TO {$newLogin};");
}
else if($privilege=="ALL" || $privilege=="INSERT" || $privilege=="SELECT" || $privilege=="UPDATE" || $privilege=="DELETE"){
pg_query("GRANT {$privilege} ON ALL TABLES IN SCHEMA {$schema} TO {$newLogin};");
pg_query("GRANT USAGE ON SCHEMA {$schema} TO {$newLogin};");
}
}
}
}
}
}
推荐阅读
- python - Pandas iloc 返回的范围与 loc 不同
- swift - (lldb) 错误:匿名闭包参数不包含在闭包中
- git - git rebase 停止在 git for windows 中工作
- c# - 如何从 Xamarin.ios 本机应用程序中的自定义控制器类打开新的故事板?
- c++ - C++ std::fill 和 std::fill_n 错误“错误 C2679”
- laravel - 如何使用另一种形式在单个复选框中设置和获取选中或未选中的值
- mysql - 如何找到一种类型的所有最新记录?
- javascript - jquery off('click') on('click') 绑定和解除绑定
- javascript - 多个选项卡中的自动单击按钮
- angular - ts 3.0.1 的 subscribe() 预期声明或声明