Example #1
0
 public static function InstallGeneralChat($agentMode = false)
 {
     $chatId = self::GetGeneralChatId();
     if ($chatId > 0) {
         return $agentMode ? false : true;
     }
     if (!IsModuleInstalled('intranet')) {
         return false;
     }
     global $DB;
     $sqlCounter = "SELECT COUNT(ID) as CNT FROM b_user WHERE ACTIVE = 'Y'";
     $dbRes = $DB->Query($sqlCounter, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     if ($row = $dbRes->Fetch()) {
         if ($row['CNT'] > 500) {
             return false;
         }
     }
     $res = $DB->Query("select ID from b_user_field where field_name='UF_DEPARTMENT'");
     if ($result = $res->Fetch()) {
         $fieldId = intval($result['ID']);
     } else {
         return false;
     }
     $CIMChat = new self(0);
     $chatId = $CIMChat->Add(array('TYPE' => IM_MESSAGE_OPEN, 'COLOR' => "AZURE", 'USERS' => false, 'TITLE' => GetMessage('IM_GENERAL_TITLE'), 'DESCTIPTION' => GetMessage('IM_GENERAL_DESCRIPTION')));
     if (!$chatId) {
         return false;
     }
     $res = $DB->Query("select ID from b_user_field where field_name='UF_DEPARTMENT'");
     if ($result = $res->Fetch()) {
         $fieldId = intval($result['ID']);
     } else {
         return false;
     }
     $sql = "\n\t\t\tinsert into b_im_relation (USER_ID, MESSAGE_TYPE, CHAT_ID)\n\t\t\tselect distinct b_user.ID, '" . IM_MESSAGE_OPEN . "', " . intval($chatId) . "\n\t\t\tfrom b_user\n\t\t\tinner join b_utm_user on b_utm_user.VALUE_ID = b_user.ID and b_utm_user.FIELD_ID = " . $fieldId . " and b_utm_user.VALUE_INT > 0\n\t\t\tWHERE b_user.ACTIVE = 'Y'\n\t\t";
     $result = $DB->Query($sql);
     if (!$result) {
         return false;
     }
     self::linkGeneralChatId($chatId);
     $messageId = $CIMChat->AddMessage(array("TO_CHAT_ID" => $chatId, "MESSAGE" => GetMessage('IM_GENERAL_DESCRIPTION'), "FROM_USER_ID" => 0, "SYSTEM" => 'Y'));
     return $agentMode ? false : true;
 }