您好我想禁用删除或阻止他们在用户单击删除按钮时删除某些模块中的某些产品。有没有专家谁知道这个?在此先感谢任何帮助将不胜感激。
找到了一个试图把它放在一起的示例代码,但我认为还有一些缺失。对不起,我很新闻:
<?php
if (isset($_REQUEST['action'])
&& $_REQUEST['action'] == 'DetailView'){
$sql = 'update AOS_Products set deleted = 0 where id ="'.$bean->id.'"p';
$result = $GLOBALS['db']->query($sql);
$GLOBALS['db']->fetchByAssoc($result);
} else{
SugarApplication::appendErrorMessage("Warning: this product shouldn't be deleted.");
}
在执行查询之前,您需要设置要保护的产品ID
<?php
if (isset($_REQUEST['action'])
&& $_REQUEST['action'] == 'DetailView'){
$arrayId = array(1, 2, 3, 4); //ids to protect
$delete = True; //boolean used for check if delete or not
foreach ($arrayId as $id) {
if($bean->id == $id) //check if id to delete is one of the protected id's
{ //looking the code i guess "$bean->id" have the product id
$delete = False;
}
}
if($delete)
{
//if true, run the query for delete
$sql = 'update AOS_Products set deleted = 0 where id ="'.$bean->id.'"p';
$result = $GLOBALS['db']->query($sql);
$GLOBALS['db']->fetchByAssoc($result);
}
else
{
SugarApplication::appendErrorMessage("Warning: this product shouldn't be deleted.");
}
} else{
//Any message related to the reason of no access the first if
}