防止删除某些产品

时间:2019-04-25 08:53:17

标签: crm sugarcrm suitecrm

您好,我想在用户单击删除按钮时禁止删除或阻止它们删除某个模块中的某些产品。有专家知道吗? 在此先感谢您的帮助。

找到了一个尝试将其放在一起的示例代码,但我认为还有更多缺失之处。抱歉,我对此很陌生:

<?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.");
}

这是我要禁用的删除按钮。 p1

也是删除按钮的inspect元素: enter image description here

2 个答案:

答案 0 :(得分:0)

在执行查询之前,您需要设置要保护的产品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
} 

答案 1 :(得分:0)

在view.detail.php中添加以下行

unset($ this-> dv-> defs ['templateMeta'] ['form'] ['buttons'] [2]);