Example #1
0
 public function Add($arFields)
 {
     /** @global CMain $APPLICATION */
     global $DB, $APPLICATION;
     if (!$this->CheckFields($arFields)) {
         return false;
     }
     foreach (GetModuleEvents("main", "OnBeforeGroupAdd", true) as $arEvent) {
         $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields));
         if ($bEventRes === false) {
             if ($err = $APPLICATION->GetException()) {
                 $this->LAST_ERROR .= $err->GetString() . "<br>";
             } else {
                 $this->LAST_ERROR .= "Unknown error in OnBeforeGroupAdd handler." . "<br>";
             }
             return false;
         }
     }
     if (is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y") {
         $arFields["ACTIVE"] = "N";
     }
     $arInsert = $DB->PrepareInsert("b_group", $arFields);
     $strSql = "\n\t\t\tINSERT INTO b_group (\n\t\t\t\t" . $arInsert[0] . "\n\t\t\t) VALUES(\n\t\t\t\t" . $arInsert[1] . "\n\t\t\t)\n\t\t";
     $DB->Query($strSql);
     $ID = $DB->LastID();
     if (count($arFields["USER_ID"]) > 0) {
         if (is_array($arFields["USER_ID"][0]) && count($arFields["USER_ID"][0]) > 0) {
             $arTmp = array();
             foreach ($arFields["USER_ID"] as $userId) {
                 if (intval($userId["USER_ID"]) > 0 && !in_array(intval($userId["USER_ID"]), $arTmp)) {
                     $arInsert = $DB->PrepareInsert("b_user_group", $userId);
                     $strSql = "INSERT INTO b_user_group(GROUP_ID, " . $arInsert[0] . ") " . "VALUES(" . $ID . ", " . $arInsert[1] . ")";
                     $DB->Query($strSql);
                     $arTmp[] = intval($userId["USER_ID"]);
                 }
             }
         } else {
             $strUsers = "0";
             foreach ($arFields["USER_ID"] as $userId) {
                 $strUsers .= "," . intval($userId);
             }
             $strSql = "INSERT INTO b_user_group(GROUP_ID, USER_ID) " . "SELECT " . $ID . ", ID " . "FROM b_user " . "WHERE ID in (" . $strUsers . ")";
             $DB->Query($strSql);
         }
         CUser::clearUserGroupCache();
     }
     $arFields["ID"] = $ID;
     foreach (GetModuleEvents("main", "OnAfterGroupAdd", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array(&$arFields));
     }
     return $ID;
 }
Example #2
0
 function Delete($ID)
 {
     /** @global CMain $APPLICATION */
     global $APPLICATION, $DB;
     $ID = intval($ID);
     if ($ID <= 2) {
         return false;
     }
     @set_time_limit(600);
     foreach (GetModuleEvents("main", "OnBeforeGroupDelete", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array($ID)) === false) {
             $err = GetMessage("MAIN_BEFORE_DEL_ERR") . ' ' . $arEvent['TO_NAME'];
             if ($ex = $APPLICATION->GetException()) {
                 $err .= ': ' . $ex->GetString();
             }
             $APPLICATION->throwException($err);
             return false;
         }
     }
     foreach (GetModuleEvents("main", "OnGroupDelete", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID));
     }
     CMain::DelGroupRight("", array($ID));
     if (!$DB->Query("DELETE FROM b_user_group WHERE GROUP_ID=" . $ID . " AND GROUP_ID>2", true)) {
         return false;
     }
     CUser::clearUserGroupCache();
     return $DB->Query("DELETE FROM b_group WHERE ID=" . $ID . " AND ID>2", true);
 }