Esempio n. 1
0
function GetCrmActivityCommunicationsPage($ID, $pageSize, $pageNumber)
{
    $dbRes = CCrmActivity::GetCommunicationList(array('ID' => 'ASC'), array('ACTIVITY_ID' => $ID), false, array('bShowAll' => false, 'nPageSize' => $pageSize, 'iNumPage' => $pageNumber));
    $communicationData = array();
    while ($result = $dbRes->Fetch()) {
        $result['ENTITY_SETTINGS'] = isset($result['ENTITY_SETTINGS']) && $result['ENTITY_SETTINGS'] !== '' ? unserialize($result['ENTITY_SETTINGS']) : array();
        CCrmActivity::PrepareCommunicationInfo($result);
        $communicationData[] = array('id' => $result['ID'], 'type' => $result['TYPE'], 'value' => $result['VALUE'], 'entityId' => $result['ENTITY_ID'], 'entityType' => CCrmOwnerType::ResolveName($result['ENTITY_TYPE_ID']), 'entityTitle' => $result['TITLE'], 'entityUrl' => CCrmOwnerType::GetShowUrl($result['ENTITY_TYPE_ID'], $result['ENTITY_ID']));
    }
    return array('DATA' => array('ID' => $ID, 'PAGE_SIZE' => $dbRes->NavPageSize, 'PAGE_NUMBER' => $dbRes->NavPageNomer, 'PAGE_COUNT' => $dbRes->NavPageCount, 'COMMUNICATIONS' => $communicationData));
}
Esempio n. 2
0
    public function showField($arField, $arUF = array())
    {
        $strResult = "";
        switch ($arField["FORMAT"]) {
            case "LEAD_PROGRESS":
                if (!empty($arField["VALUE"])) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<span class="crm-feed-info-text-padding crm-feed-info-bar-cont">';
                    $strResult .= CCrmViewHelper::RenderLeadStatusControl(array('ENTITY_TYPE_NAME' => CCrmOwnerType::Lead, 'REGISTER_SETTINGS' => true, 'PREFIX' => "", 'ENTITY_ID' => CCrmLiveFeedEntity::Lead, 'CURRENT_ID' => $arField["VALUE"], 'READ_ONLY' => true));
                    $strResult .= '</span>';
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "DEAL_PROGRESS":
                if (!empty($arField["VALUE"])) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<span class="crm-feed-info-text-padding crm-feed-info-bar-cont">';
                    $strResult .= CCrmViewHelper::RenderDealStageControl(array('ENTITY_TYPE_NAME' => CCrmOwnerType::Deal, 'REGISTER_SETTINGS' => true, 'PREFIX' => "", 'ENTITY_ID' => CCrmLiveFeedEntity::Deal, 'CURRENT_ID' => $arField["VALUE"], 'READ_ONLY' => true));
                    $strResult .= '</span>';
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "INVOICE_PROGRESS":
                if (!empty($arField["VALUE"])) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<span class="crm-feed-info-text-padding crm-feed-info-bar-cont">';
                    $strResult .= CCrmViewHelper::RenderInvoiceStatusControl(array('ENTITY_TYPE_NAME' => CCrmOwnerType::Invoice, 'REGISTER_SETTINGS' => true, 'PREFIX' => "", 'ENTITY_ID' => CCrmLiveFeedEntity::Invoice, 'CURRENT_ID' => $arField["VALUE"], 'READ_ONLY' => true));
                    $strResult .= "</span>";
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "LEAD_STATUS":
                $infos = CCrmStatus::GetStatus('STATUS');
                if (!empty($arField["VALUE"]) && array_key_exists($arField["VALUE"], $infos)) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<span class="crm-feed-info-text-padding">';
                    $strResult .= $infos[$arField["VALUE"]]["NAME"];
                    $strResult .= "</span>";
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "PERSON_NAME":
                if (is_array($arField["VALUE"])) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<span class="crm-feed-info-text-padding">';
                    $strResult .= CUser::FormatName(CSite::GetNameFormat(), $arField["VALUE"]);
                    $strResult .= "</span>";
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "PERSON_ID":
                if (intval($arField["VALUE"]) > 0) {
                    $dbUser = CUser::GetByID(intval($arField["VALUE"]));
                    if ($arUser = $dbUser->GetNext()) {
                        $strResult .= "#row_begin#";
                        $strResult .= "#cell_begin_left#";
                        $strResult .= $arField["TITLE"] . ":";
                        $strResult .= "#cell_end#";
                        $strResult .= "#cell_begin_right#";
                        if ($arUser["PERSONAL_PHOTO"] > 0) {
                            $arFileTmp = CFile::ResizeImageGet($arUser["PERSONAL_PHOTO"], array('width' => 39, 'height' => 39), BX_RESIZE_IMAGE_EXACT, false);
                        }
                        $strUser = "";
                        $strUser .= '<div class="feed-com-avatar crm-feed-company-avatar">';
                        if (is_array($arFileTmp) && isset($arFileTmp['src'])) {
                            if (strlen($this->params["PATH_TO_USER"]) > 0) {
                                $strUser .= '<a target="_blank" href="' . str_replace(array("#user_id#", "#USER_ID#"), intval($arField["VALUE"]), $this->params["PATH_TO_USER"]) . '"><img src="' . $arFileTmp['src'] . '" alt=""/></a>';
                            } else {
                                $strUser .= '<img src="' . $arFileTmp['src'] . '" alt=""/>';
                            }
                        }
                        $strUser .= '</div>';
                        if (strlen($this->params["PATH_TO_USER"]) > 0) {
                            $strUser .= '<a class="crm-detail-info-resp-name" target="_blank" href="' . str_replace(array("#user_id#", "#USER_ID#"), intval($arField["VALUE"]), $this->params["PATH_TO_USER"]) . '">' . CUser::FormatName(CSite::GetNameFormat(), $arUser, true, false) . '</a>';
                        } else {
                            $strUser .= '<span class="crm-detail-info-resp-name">' . CUser::FormatName(CSite::GetNameFormat(), $arUser, true, false) . '</span>';
                        }
                        if (strlen($arUser["WORK_POSITION"]) > 0) {
                            $strUser .= '<span class="crm-detail-info-resp-descr">' . $arUser["WORK_POSITION"] . '</span>';
                        }
                        $strResult .= '<span class="crm-detail-info-resp">' . $strUser . '</span>';
                        $strResult .= "#cell_end#";
                        $strResult .= "#row_end#";
                    }
                }
                break;
            case "COMPANY_ID":
                if (intval($arField["VALUE"]) > 0) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<span class="crm-feed-info-text-padding">';
                    $strResult .= CCrmViewHelper::PrepareEntityBaloonHtml(array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $arField["VALUE"], 'PREFIX' => "", 'CLASS_NAME' => '', 'CHECK_PERMISSIONS' => 'N'));
                    $strResult .= '</span>';
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "COMPANY_TYPE":
                $infos = CCrmStatus::GetStatusListEx('COMPANY_TYPE');
                if (!empty($arField["VALUE"]) && array_key_exists($arField["VALUE"], $infos)) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<span class="crm-feed-info-text-padding">';
                    $strResult .= $infos[$arField["VALUE"]];
                    $strResult .= '</span>';
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "CONTACT_ID":
                if (intval($arField["VALUE"]) > 0) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<div class="crm-feed-client-block">';
                    $strResult .= '<span class="feed-com-avatar crm-feed-user-avatar">';
                    $dbRes = CCrmContact::GetListEx(array(), array('=ID' => $arField["VALUE"], 'CHECK_PERMISSIONS' => 'N'), false, false, array('PHOTO'));
                    if (($arRes = $dbRes->Fetch()) && intval($arRes["PHOTO"]) > 0) {
                        $arFileTmp = CFile::ResizeImageGet($arRes["PHOTO"], array('width' => 39, 'height' => 39), BX_RESIZE_IMAGE_EXACT, false);
                        if (is_array($arFileTmp) && isset($arFileTmp["src"])) {
                            $strResult .= '<img width="39" height="39" src="' . $arFileTmp['src'] . '" alt="">';
                        }
                    }
                    $strResult .= '</span>';
                    $strResult .= CCrmViewHelper::PrepareEntityBaloonHtml(array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $arField["VALUE"], 'PREFIX' => "", 'CLASS_NAME' => '', 'CHECK_PERMISSIONS' => 'N'));
                    $strResult .= '</div>';
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "COMBI_CLIENT":
                if (is_array($arField["VALUE"]) && (array_key_exists("CONTACT_ID", $arField["VALUE"]) && intval($arField["VALUE"]["CONTACT_ID"]) > 0 || array_key_exists("CONTACT_NAME", $arField["VALUE"]) && strlen($arField["VALUE"]["CONTACT_NAME"]) > 0 || array_key_exists("CONTACT_LAST_NAME", $arField["VALUE"]) && strlen($arField["VALUE"]["CONTACT_LAST_NAME"]) > 0 || array_key_exists("COMPANY_ID", $arField["VALUE"]) && intval($arField["VALUE"]["COMPANY_ID"]) > 0)) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    if (array_key_exists("CONTACT_ID", $arField["VALUE"]) && intval($arField["VALUE"]["CONTACT_ID"]) > 0 || array_key_exists("CONTACT_NAME", $arField["VALUE"]) && strlen($arField["VALUE"]["CONTACT_NAME"]) > 0 || array_key_exists("CONTACT_LAST_NAME", $arField["VALUE"]) && strlen($arField["VALUE"]["CONTACT_LAST_NAME"]) > 0) {
                        if (array_key_exists("CONTACT_ID", $arField["VALUE"]) && intval($arField["VALUE"]["CONTACT_ID"]) > 0) {
                            $strResult .= '<div class="crm-feed-client-block">';
                            $strResult .= '<span class="feed-com-avatar crm-feed-user-avatar">';
                            $dbRes = CCrmContact::GetListEx(array(), array('=ID' => $arField["VALUE"]["CONTACT_ID"], 'CHECK_PERMISSIONS' => 'N'), false, false, array('PHOTO', 'COMPANY_ID'));
                            if ($arRes = $dbRes->Fetch()) {
                                $contactCompanyID = $arRes['COMPANY_ID'];
                                if (intval($arRes["PHOTO"]) > 0) {
                                    $arFileTmp = CFile::ResizeImageGet($arRes["PHOTO"], array('width' => 39, 'height' => 39), BX_RESIZE_IMAGE_EXACT, false);
                                    if (is_array($arFileTmp) && isset($arFileTmp["src"])) {
                                        $strResult .= '<img width="39" height="39" src="' . $arFileTmp['src'] . '" alt="">';
                                    }
                                }
                            }
                            $strResult .= '</span>';
                            $strResult .= CCrmViewHelper::PrepareEntityBaloonHtml(array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $arField["VALUE"]["CONTACT_ID"], 'PREFIX' => '', 'CLASS_NAME' => '', 'CHECK_PERMISSIONS' => 'N'));
                        } else {
                            $strResult .= '<div class="crm-feed-client-block">';
                            $strResult .= '<span class="feed-com-avatar crm-feed-user-avatar">';
                            if (intval($arField['VALUE']['PHOTO_ID']) > 0) {
                                $arFileTmp = CFile::ResizeImageGet($arField['VALUE']['PHOTO_ID'], array('width' => 39, 'height' => 39), BX_RESIZE_IMAGE_EXACT, false);
                                if (is_array($arFileTmp) && isset($arFileTmp["src"])) {
                                    $strResult .= '<img width="39" height="39" src="' . $arFileTmp['src'] . '" alt="">';
                                }
                            }
                            $strResult .= '</span>';
                            if (array_key_exists("ENTITY_ID", $arField["VALUE"]) && intval($arField["VALUE"]["ENTITY_ID"]) > 0) {
                                $url = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Contact, $arField["VALUE"]["ENTITY_ID"], true);
                            }
                            $clientName = CCrmContact::PrepareFormattedName(array('HONORIFIC' => isset($arField['VALUE']['HONORIFIC']) ? $arField['VALUE']['HONORIFIC'] : '', 'NAME' => isset($arField['VALUE']['CONTACT_NAME']) ? $arField['VALUE']['CONTACT_NAME'] : '', 'LAST_NAME' => isset($arField['VALUE']['CONTACT_LAST_NAME']) ? $arField['VALUE']['CONTACT_LAST_NAME'] : '', 'SECOND_NAME' => isset($arField['VALUE']['CONTACT_SECOND_NAME']) ? $arField['VALUE']['CONTACT_SECOND_NAME'] : ''));
                            $strResult .= strlen($url) > 0 ? '<a href="' . $url . '" class="crm-feed-client-name">' . $clientName . '</a>' : $clientName;
                        }
                        $strResult .= '<span class="crm-feed-client-company">';
                        $strResult .= CCrmViewHelper::PrepareEntityBaloonHtml(array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => array_key_exists("COMPANY_ID", $arField["VALUE"]) && intval($arField["VALUE"]["COMPANY_ID"]) > 0 ? $arField["VALUE"]["COMPANY_ID"] : intval($contactCompanyID), 'PREFIX' => '', 'CLASS_NAME' => '', 'CHECK_PERMISSIONS' => 'N'));
                        $strResult .= '</span>';
                        $strResult .= '</div>';
                    } else {
                        $strResult .= CCrmViewHelper::PrepareEntityBaloonHtml(array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $arField["VALUE"]["COMPANY_ID"], 'PREFIX' => "", 'CLASS_NAME' => '', 'CHECK_PERMISSIONS' => 'N'));
                    }
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "COMBI_COMPANY":
                if (is_array($arField["VALUE"]) && (array_key_exists("TITLE", $arField["VALUE"]) && strlen($arField["VALUE"]["TITLE"]) > 0)) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $url = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Company, $arField["VALUE"]["ENTITY_ID"]);
                    if (intval($arField['VALUE']['LOGO_ID']) > 0) {
                        $arFileTmp = CFile::ResizeImageGet($arField['VALUE']['LOGO_ID'], array('width' => 39, 'height' => 39), BX_RESIZE_IMAGE_EXACT, false);
                    }
                    if (is_array($arFileTmp) && isset($arFileTmp['src'])) {
                        $strResult .= '<a class="crm-feed-user-block" href="' . $url . '">';
                        $strResult .= '<span class="feed-com-avatar crm-feed-company-avatar">';
                        $strResult .= '<img width="39" height="39" alt="" src="' . $arFileTmp['src'] . '">';
                        $strResult .= '</span>';
                        $strResult .= '<span class="crm-feed-user-name">' . $arField["VALUE"]["TITLE"] . '</span>';
                        $strResult .= '</a>';
                    } else {
                        $strResult .= '<a class="crm-feed-info-link" href="' . $url . '">' . $arField["VALUE"]["TITLE"] . '</a>';
                    }
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "COMBI_CLIENT_NAME":
                if (is_array($arField["VALUE"]) && (array_key_exists("CONTACT_NAME", $arField["VALUE"]) && strlen($arField["VALUE"]["CONTACT_NAME"]) > 0 || array_key_exists("CONTACT_LAST_NAME", $arField["VALUE"]) && strlen($arField["VALUE"]["CONTACT_LAST_NAME"]) > 0 || array_key_exists("COMPANY_TITLE", $arField["VALUE"]) && strlen($arField["VALUE"]["COMPANY_TITLE"]) > 0)) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    if (array_key_exists("CONTACT_NAME", $arField["VALUE"]) && strlen($arField["VALUE"]["CONTACT_NAME"]) > 0 || array_key_exists("CONTACT_LAST_NAME", $arField["VALUE"]) && strlen($arField["VALUE"]["CONTACT_LAST_NAME"]) > 0) {
                        $strResult .= '<div class="crm-feed-client-block">';
                        $strResult .= '<span class="feed-com-avatar crm-feed-user-avatar"></span>';
                        $strResult .= CCrmContact::PrepareFormattedName(array("HONORIFIC" => $arField["VALUE"]["HONORIFIC"], "NAME" => $arField["VALUE"]["CONTACT_NAME"], "LAST_NAME" => $arField["VALUE"]["CONTACT_LAST_NAME"], "SECOND_NAME" => $arField["VALUE"]["CONTACT_SECOND_NAME"]));
                        $strResult .= '<span class="crm-feed-client-company">' . (strlen($arField["VALUE"]["COMPANY_TITLE"]) > 0 ? $arField["VALUE"]["COMPANY_TITLE"] : "") . '</span>';
                        $strResult .= '</div>';
                    } else {
                        $strResult .= $arField["VALUE"]["COMPANY_TITLE"];
                    }
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "DEAL_ID":
                if (intval($arField["VALUE"]) > 0) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<span class="crm-feed-info-text-padding">';
                    $strResult .= CCrmViewHelper::PrepareEntityBaloonHtml(array('ENTITY_TYPE_ID' => CCrmOwnerType::Deal, 'ENTITY_ID' => $arField["VALUE"], 'PREFIX' => "", 'CLASS_NAME' => '', 'CHECK_PERMISSIONS' => 'N'));
                    $strResult .= '</span>';
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "COMMUNICATIONS":
                if (is_array($arField["VALUE"]) && count($arField["VALUE"]) > 0) {
                    $arCommunication = $arField["VALUE"][0];
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<div class="crm-feed-client-block">';
                    if (in_array($arCommunication["ENTITY_TYPE_ID"], array(CCrmOwnerType::Company, CCrmOwnerType::Contact, CCrmOwnerType::Lead))) {
                        $strResult .= '<span class="feed-com-avatar crm-feed-user-avatar">';
                        if ($arCommunication["ENTITY_TYPE_ID"] == CCrmOwnerType::Contact) {
                            $dbRes = CCrmContact::GetListEx(array(), array('=ID' => $arCommunication["ENTITY_ID"], 'CHECK_PERMISSIONS' => 'N'), false, false, array('PHOTO'));
                            if (($arRes = $dbRes->Fetch()) && intval($arRes["PHOTO"]) > 0) {
                                $arFileTmp = CFile::ResizeImageGet($arRes["PHOTO"], array('width' => 39, 'height' => 39), BX_RESIZE_IMAGE_EXACT, false);
                                if (is_array($arFileTmp) && isset($arFileTmp["src"])) {
                                    $strResult .= '<img width="39" height="39" src="' . $arFileTmp['src'] . '" alt="">';
                                }
                            }
                        } elseif ($arCommunication["ENTITY_TYPE_ID"] == CCrmOwnerType::Company) {
                            $dbRes = CCrmCompany::GetListEx(array(), array('=ID' => $arCommunication["ENTITY_ID"], 'CHECK_PERMISSIONS' => 'N'), false, false, array('LOGO'));
                            if (($arRes = $dbRes->Fetch()) && intval($arRes["LOGO"]) > 0) {
                                $arFileTmp = CFile::ResizeImageGet($arRes["LOGO"], array('width' => 30, 'height' => 30), BX_RESIZE_IMAGE_EXACT, false);
                                if (is_array($arFileTmp) && isset($arFileTmp["src"])) {
                                    $strResult .= '<img width="30" height="30" src="' . $arFileTmp['src'] . '" alt="">';
                                }
                            }
                        }
                        $strResult .= '</span>';
                    }
                    $arBaloonFields = array('ENTITY_TYPE_ID' => $arCommunication["ENTITY_TYPE_ID"], 'ENTITY_ID' => $arCommunication["ENTITY_ID"], 'PREFIX' => "", 'CLASS_NAME' => 'crm-feed-client-name', 'CHECK_PERMISSIONS' => 'N');
                    if ($arCommunication["ENTITY_TYPE_ID"] == CCrmOwnerType::Lead && is_array($arCommunication["ENTITY_SETTINGS"])) {
                        $arBaloonFields["TITLE"] = isset($arCommunication["ENTITY_SETTINGS"]["LEAD_TITLE"]) ? htmlspecialcharsback($arCommunication["ENTITY_SETTINGS"]["LEAD_TITLE"]) : "";
                        $arBaloonFields["NAME"] = isset($arCommunication["ENTITY_SETTINGS"]["NAME"]) ? htmlspecialcharsback($arCommunication["ENTITY_SETTINGS"]["NAME"]) : "";
                        $arBaloonFields["LAST_NAME"] = isset($arCommunication["ENTITY_SETTINGS"]["LAST_NAME"]) ? htmlspecialcharsback($arCommunication["ENTITY_SETTINGS"]["LAST_NAME"]) : "";
                        $arBaloonFields["SECOND_NAME"] = isset($arCommunication["ENTITY_SETTINGS"]["SECOND_NAME"]) ? htmlspecialcharsback($arCommunication["ENTITY_SETTINGS"]["SECOND_NAME"]) : "";
                    }
                    $strResult .= '<div>' . CCrmViewHelper::PrepareEntityBaloonHtml($arBaloonFields) . '</div>';
                    switch ($arCommunication["TYPE"]) {
                        case 'EMAIL':
                            $strResult .= '<div><a href="mailto:' . $arCommunication["VALUE"] . '" class="crm-feed-client-phone">' . $arCommunication["VALUE"] . '</div>';
                            break;
                        case 'PHONE':
                            if (CCrmSipHelper::isEnabled()) {
                                ob_start();
                                ?>
								<script type="text/javascript">
								if (typeof (window.bSipManagerUrlDefined_<?php 
                                echo $arCommunication["ENTITY_TYPE_ID"];
                                ?>
) === 'undefined')
								{
									window.bSipManagerUrlDefined_<?php 
                                echo $arCommunication["ENTITY_TYPE_ID"];
                                ?>
 = true;
									BX.ready(
										function()
										{
											var mgr = BX.CrmSipManager.getCurrent();
											mgr.setServiceUrl(
												"CRM_<?php 
                                echo CUtil::JSEscape(CCrmOwnerType::ResolveName($arCommunication["ENTITY_TYPE_ID"]));
                                ?>
",
												"<?php 
                                echo CUtil::JSEscape($this->arSipServiceUrl[$arCommunication["ENTITY_TYPE_ID"]]);
                                ?>
"
											);

											if(typeof(BX.CrmSipManager.messages) === 'undefined')
											{
												BX.CrmSipManager.messages =
												{
													"unknownRecipient": "<?php 
                                echo GetMessageJS('CRM_LF_SIP_MGR_UNKNOWN_RECIPIENT');
                                ?>
",
													"enableCallRecording": "<?php 
                                echo GetMessageJS('CRM_LF_SIP_MGR_ENABLE_CALL_RECORDING');
                                ?>
",
													"makeCall": "<?php 
                                echo GetMessageJS('CCRM_LF_SIP_MGR_MAKE_CALL');
                                ?>
"
												};
											}
										}
									);
								}
								</script>
								<?php 
                                $strResult .= ob_get_contents();
                                ob_end_clean();
                            }
                            $strResult .= '<div><span class="crm-feed-num-block">' . CCrmViewHelper::PrepareMultiFieldHtml('PHONE', array('VALUE' => $arCommunication["VALUE"], 'VALUE_TYPE_ID' => 'WORK'), array('ENABLE_SIP' => true, 'SIP_PARAMS' => array('ENTITY_TYPE' => 'CRM_' . CCrmOwnerType::ResolveName($arCommunication["ENTITY_TYPE_ID"]), 'ENTITY_ID' => $arCommunication["ENTITY_ID"]))) . '</span></div>';
                            if (defined("BX_COMP_MANAGED_CACHE")) {
                                $GLOBALS["CACHE_MANAGER"]->RegisterTag("CRM_CALLTO_SETTINGS");
                            }
                            break;
                    }
                    $strResult .= '<span class="crm-feed-client-company">' . (is_array($arCommunication["ENTITY_SETTINGS"]) && isset($arCommunication["ENTITY_SETTINGS"]["COMPANY_TITLE"]) ? $arCommunication["ENTITY_SETTINGS"]["COMPANY_TITLE"] : "") . '</span>';
                    $strResult .= '</div>';
                    $moreCnt = count($arField["VALUE"]) - 1;
                    if ($moreCnt > 0) {
                        $strResult .= "#clients_more_link#";
                    }
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "AVATAR_ID":
                if (intval($arField["VALUE"]) > 0) {
                    $arFileTmp = CFile::ResizeImageGet($arField["VALUE"], array('width' => $this->params["AVATAR_SIZE"], 'height' => $this->params["AVATAR_SIZE"]), BX_RESIZE_IMAGE_EXACT, false);
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<span class="crm-feed-info-text-padding">';
                    $strResult .= '<img src="' . $arFileTmp["src"] . '" border="0" alt="' . $this->params["AVATAR_SIZE"] . '" width="" height="' . $this->params["AVATAR_SIZE"] . '">';
                    $strResult .= '</span>';
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "SUM":
                if (intval($arField["VALUE"]["VALUE"]) > 0) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<span class="crm-feed-info-text-padding">';
                    $strResult .= '<span class="crm-feed-info-sum">' . CCrmCurrency::MoneyToString($arField["VALUE"]["VALUE"], $arField["VALUE"]["CURRENCY"]) . '</span>';
                    $strResult .= '</span>';
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "PHONE":
            case "EMAIL":
                if (!empty($arField["VALUE"])) {
                    $infos = CCrmFieldMulti::GetEntityTypes();
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<span class="crm-feed-info-text-padding">';
                    $strResult .= CCrmViewHelper::PrepareFirstMultiFieldHtml($arField["FORMAT"], $arField["VALUE"], $infos[$arField["FORMAT"]]);
                    if (count($arField["VALUE"]) > 1 || !empty($arField["VALUE"]["WORK"]) && count($arField["VALUE"]["WORK"]) > 1 || !empty($arField["VALUE"]["MOBILE"]) && count($arField["VALUE"]["MOBILE"]) > 1 || !empty($arField["VALUE"]["FAX"]) && count($arField["VALUE"]["FAX"]) > 1 || !empty($arField["VALUE"]["PAGER"]) && count($arField["VALUE"]["PAGER"]) > 1 || !empty($arField["VALUE"]["OTHER"]) && count($arField["VALUE"]["OTHER"]) > 1) {
                        $anchorID = strtolower($arField["FORMAT"]);
                        $strResult .= '<span style="margin-left: 10px;" class="crm-item-tel-list" id="' . htmlspecialcharsbx($anchorID) . '"' . ' onclick="' . CCrmViewHelper::PrepareMultiFieldValuesPopup($anchorID, $anchorID, $arField["FORMAT"], $arField["VALUE"], $infos[$arField["FORMAT"]]) . '"></span>';
                    }
                    $strResult .= '</span>';
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                    if ($arField["FORMAT"] == "PHONE" && defined("BX_COMP_MANAGED_CACHE")) {
                        $GLOBALS["CACHE_MANAGER"]->RegisterTag("CRM_CALLTO_SETTINGS");
                    }
                }
                break;
            case "TEXT_FORMATTED":
            case "TEXT_FORMATTED_BOLD":
                if ($arField["VALUE"] != CCrmLiveFeed::UntitledMessageStub) {
                    $text_formatted = $this->ParseText(htmlspecialcharsback($arField["VALUE"]), $arUF, $arParams["PARAMS"]);
                    if (strlen($text_formatted) > 0) {
                        $strResult .= "#row_begin#";
                        $strResult .= "#cell_begin_colspan2#";
                        if ($arField["FORMAT"] == "TEXT_FORMATTED_BOLD") {
                            $strResult .= "<b>" . $text_formatted . "</b>";
                        } else {
                            $strResult .= $text_formatted;
                        }
                        $strResult .= "#cell_end#";
                        $strResult .= "#row_end#";
                    }
                }
                break;
            case "COMBI_TITLE":
                if (is_array($arField["VALUE"]) && array_key_exists("TITLE", $arField["VALUE"]) && strlen($arField["VALUE"]["TITLE"]) > 0) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<span class="crm-feed-info-text-padding">';
                    if (array_key_exists("URL", $arField["VALUE"]) && strlen($arField["VALUE"]["URL"]) > 0) {
                        $strResult .= '<a href="' . $arField["VALUE"]["URL"] . '">' . $arField["VALUE"]["TITLE"] . '</a>';
                    } elseif (array_key_exists("ONCLICK", $arField["VALUE"]) && strlen($arField["VALUE"]["ONCLICK"]) > 0) {
                        $strResult .= '<a href="javascript:void(0)" onclick="' . $arField["VALUE"]["ONCLICK"] . '">' . $arField["VALUE"]["TITLE"] . '</a>';
                    } else {
                        $strResult .= $arField["VALUE"]["TITLE"];
                    }
                    $strResult .= '</span>';
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "COMBI_TITLE_ID":
                if (is_array($arField["VALUE"]) && array_key_exists("TITLE", $arField["VALUE"]) && strlen($arField["VALUE"]["TITLE"]) > 0 && array_key_exists("ID", $arField["VALUE"]) && strlen($arField["VALUE"]["ID"]) > 0) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<span class="crm-feed-info-text-padding">';
                    if (array_key_exists("URL", $arField["VALUE"]) && strlen($arField["VALUE"]["URL"]) > 0) {
                        $strResult .= '<a href="' . $arField["VALUE"]["URL"] . '">' . GetMessage("C_CRM_LF_COMBI_TITLE_ID_VALUE", array("#ID#" => $arField["VALUE"]["ID"], "#TITLE#" => $arField["VALUE"]["TITLE"])) . '</a>';
                    } else {
                        $strResult .= GetMessage("C_CRM_LF_COMBI_TITLE_ID_VALUE", array("#ID#" => $arField["VALUE"]["ID"], "#TITLE#" => $arField["VALUE"]["TITLE"]));
                    }
                    $strResult .= '</span>';
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "TEXT_ADD":
                if (strlen($arField["VALUE"]) > 0) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<span class="crm-feed-info-text-padding">';
                    $strResult .= '<span class="crm-feed-info-name">' . $arField["VALUE"] . '</span>';
                    $strResult .= '</span>';
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
                break;
            case "TEXT":
            default:
                if (strlen($arField["VALUE"]) > 0) {
                    $strResult .= "#row_begin#";
                    $strResult .= "#cell_begin_left#";
                    $strResult .= $arField["TITLE"] . ":";
                    $strResult .= "#cell_end#";
                    $strResult .= "#cell_begin_right#";
                    $strResult .= '<span class="crm-feed-info-text-padding">';
                    $strResult .= $arField["VALUE"];
                    $strResult .= '</span>';
                    $strResult .= "#cell_end#";
                    $strResult .= "#row_end#";
                }
        }
        return $strResult;
    }
Esempio n. 3
0
 function __CrmQuickPanelViewPrepareCompanyInfo($entityFields, &$entityContext, $key = '', $useTildeKey = true)
 {
     if ($key === '') {
         $key = 'COMPANY';
     }
     $map = array('ID' => ($useTildeKey ? '~' : '') . $key . '_ID', 'TITLE' => ($useTildeKey ? '~' : '') . $key . '_TITLE', 'LOGO' => ($useTildeKey ? '~' : '') . $key . '_LOGO');
     $entityContext['COMPANY_INFO'] = array('ID' => isset($entityFields[$map['ID']]) ? (int) $entityFields[$map['ID']] : 0, 'TITLE' => '');
     if ($entityContext['COMPANY_INFO']['ID'] > 0 && isset($entityFields[$map['TITLE']])) {
         $entityContext['COMPANY_INFO']['TITLE'] = $entityFields[$map['TITLE']];
         $entityContext['COMPANY_INFO']['SHOW_URL'] = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Company, $entityContext['COMPANY_INFO']['ID'], false);
         if (isset($entityFields[$map['LOGO']])) {
             $file = new CFile();
             $fileInfo = $file->ResizeImageGet($entityFields[$map['LOGO']], array('width' => 48, 'height' => 31), BX_RESIZE_IMAGE_PROPORTIONAL);
             $entityContext['COMPANY_INFO']['IMAGE_URL'] = is_array($fileInfo) && isset($fileInfo['src']) ? $fileInfo['src'] : '';
         } else {
             $entityContext['COMPANY_INFO']['IMAGE_URL'] = '';
         }
         $entityContext['COMPANY_INFO']['FM'] = __CrmQuickPanelViewLoadMultiFields(CCrmOwnerType::CompanyName, $entityContext['COMPANY_INFO']['ID']);
         $entityContext['COMPANY_INFO']['MULTI_FIELDS_OPTIONS'] = array('ENABLE_SIP' => true, 'SIP_PARAMS' => array('ENTITY_TYPE' => 'CRM_' . CCrmOwnerType::CompanyName, 'ENTITY_ID' => $entityContext['COMPANY_INFO']['ID']));
     }
 }
Esempio n. 4
0
 public static function GetDocumentAdminPage($documentId)
 {
     $arDocumenInfo = self::GetDocumentInfo($documentId);
     if (empty($arDocumenInfo)) {
         return null;
     }
     $entityTypeName = isset($arDocumenInfo['TYPE']) ? $arDocumenInfo['TYPE'] : '';
     $entityTypeID = $entityTypeName !== '' ? CCrmOwnerType::ResolveID($entityTypeName) : CCrmOwnerType::Undefined;
     $entityID = isset($arDocumenInfo['ID']) ? intval($arDocumenInfo['ID']) : 0;
     return $entityTypeID !== CCrmOwnerType::Undefined && $entityID > 0 ? CCrmOwnerType::GetShowUrl($entityTypeID, $entityID, false) : null;
 }
Esempio n. 5
0
    $entityID = isset($_POST['ENITY_ID']) ? intval($_POST['ENITY_ID']) : 0;
    if ($entityID <= 0) {
        __CrmCompanyShowEndJsonResonse(array('ERROR' => 'ENITY ID IS INVALID OR NOT DEFINED!'));
    }
    $dbRes = CCrmCompany::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'Y'), false, false, array('TITLE', 'LOGO'));
    $arRes = $dbRes ? $dbRes->Fetch() : null;
    if (!$arRes) {
        __CrmCompanyShowEndJsonResonse(array('ERROR' => 'ENITY IS NOT FOUND!'));
    } else {
        if (!isset($arRes['LOGO'])) {
            $imageUrl = '';
        } else {
            $fileInfo = CFile::ResizeImageGet($arRes['LOGO'], array('width' => 42, 'height' => 42), BX_RESIZE_IMAGE_PROPORTIONAL, false);
            $imageUrl = isset($fileInfo['src']) ? $fileInfo['src'] : '';
        }
        __CrmCompanyShowEndJsonResonse(array('DATA' => array('TITLE' => isset($arRes['TITLE']) ? $arRes['TITLE'] : '', 'LEGEND' => '', 'IMAGE_URL' => $imageUrl, 'SHOW_URL' => CCrmOwnerType::GetShowUrl(CCrmOwnerType::Company, $entityID, false))));
    }
}
$type = isset($_POST['OWNER_TYPE']) ? strtoupper($_POST['OWNER_TYPE']) : '';
if ($type !== 'CO') {
    __CrmCompanyShowEndJsonResonse(array('ERROR' => 'OWNER_TYPE IS NOT SUPPORTED!'));
}
if (!CCrmCompany::CheckUpdatePermission(0)) {
    __CrmCompanyShowEndJsonResonse(array('ERROR' => 'PERMISSION DENIED!'));
}
if ($mode === 'UPDATE') {
    $ID = isset($_POST['OWNER_ID']) ? $_POST['OWNER_ID'] : 0;
    if ($ID <= 0) {
        __CrmCompanyShowEndJsonResonse(array('ERROR' => 'ID IS INVALID OR NOT DEFINED!'));
    }
    if (!CCrmCompany::CheckUpdatePermission($ID)) {
Esempio n. 6
0
 public function Update($ID, array &$arFields, $bCompare = true, $bUpdateSearch = true, $options = array())
 {
     global $DB;
     $this->LAST_ERROR = '';
     $ID = (int) $ID;
     if (!is_array($options)) {
         $options = array();
     }
     $arFilterTmp = array('ID' => $ID);
     if (!$this->bCheckPermission) {
         $arFilterTmp['CHECK_PERMISSIONS'] = 'N';
     }
     $obRes = self::GetListEx(array(), $arFilterTmp);
     if (!($arRow = $obRes->Fetch())) {
         return false;
     }
     $iUserId = CCrmSecurityHelper::GetCurrentUserID();
     if (isset($arFields['DATE_CREATE'])) {
         unset($arFields['DATE_CREATE']);
     }
     if (isset($arFields['DATE_MODIFY'])) {
         unset($arFields['DATE_MODIFY']);
     }
     $arFields['~DATE_MODIFY'] = $DB->CurrentTimeFunction();
     if (!isset($arFields['MODIFY_BY_ID']) || $arFields['MODIFY_BY_ID'] <= 0) {
         $arFields['MODIFY_BY_ID'] = $iUserId;
     }
     if (isset($arFields['ASSIGNED_BY_ID']) && $arFields['ASSIGNED_BY_ID'] <= 0) {
         unset($arFields['ASSIGNED_BY_ID']);
     }
     $assignedByID = (int) (isset($arFields['ASSIGNED_BY_ID']) ? $arFields['ASSIGNED_BY_ID'] : $arRow['ASSIGNED_BY_ID']);
     $bResult = false;
     if (!$this->CheckFields($arFields, $ID, $options)) {
         $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR;
     } else {
         if ($this->bCheckPermission && !CCrmAuthorizationHelper::CheckUpdatePermission(self::$TYPE_NAME, $ID, $this->cPerms)) {
             $this->LAST_ERROR = GetMessage('CRM_PERMISSION_DENIED');
             $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR;
             return false;
         }
         $beforeEvents = GetModuleEvents('crm', 'OnBeforeCrmDealUpdate');
         while ($arEvent = $beforeEvents->Fetch()) {
             if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) {
                 if (isset($arFields['RESULT_MESSAGE'])) {
                     $this->LAST_ERROR = $arFields['RESULT_MESSAGE'];
                 } else {
                     $this->LAST_ERROR = GetMessage('CRM_DEAL_UPDATE_CANCELED', array('#NAME#' => $arEvent['TO_NAME']));
                     $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR;
                 }
                 return false;
             }
         }
         $arAttr = array();
         $arAttr['STAGE_ID'] = !empty($arFields['STAGE_ID']) ? $arFields['STAGE_ID'] : $arRow['STAGE_ID'];
         $arAttr['OPENED'] = !empty($arFields['OPENED']) ? $arFields['OPENED'] : $arRow['OPENED'];
         $arEntityAttr = self::BuildEntityAttr($assignedByID, $arAttr);
         $sEntityPerm = $this->cPerms->GetPermType('DEAL', 'WRITE', $arEntityAttr);
         $this->PrepareEntityAttrs($arEntityAttr, $sEntityPerm);
         //Prevent 'OPENED' field change by user restricted by BX_CRM_PERM_OPEN permission
         if ($sEntityPerm === BX_CRM_PERM_OPEN && isset($arFields['OPENED']) && $arFields['OPENED'] !== 'Y' && $assignedByID !== $iUserId) {
             $arFields['OPENED'] = 'Y';
         }
         if (isset($arFields['ASSIGNED_BY_ID']) && $arRow['ASSIGNED_BY_ID'] != $arFields['ASSIGNED_BY_ID']) {
             CCrmEvent::SetAssignedByElement($arFields['ASSIGNED_BY_ID'], 'DEAL', $ID);
         }
         $sonetEventData = array();
         if ($bCompare) {
             $arEvents = self::CompareFields($arRow, $arFields, $this->bCheckPermission);
             foreach ($arEvents as $arEvent) {
                 $arEvent['ENTITY_TYPE'] = 'DEAL';
                 $arEvent['ENTITY_ID'] = $ID;
                 $arEvent['EVENT_TYPE'] = 1;
                 if (!isset($arEvent['USER_ID'])) {
                     $arEvent['USER_ID'] = $iUserId;
                 }
                 $CCrmEvent = new CCrmEvent();
                 $eventID = $CCrmEvent->Add($arEvent, $this->bCheckPermission);
                 if (is_int($eventID) && $eventID > 0) {
                     $fieldID = isset($arEvent['ENTITY_FIELD']) ? $arEvent['ENTITY_FIELD'] : '';
                     if ($fieldID === '') {
                         continue;
                     }
                     switch ($fieldID) {
                         case 'STAGE_ID':
                             $sonetEventData[CCrmLiveFeedEvent::Progress] = array('TYPE' => CCrmLiveFeedEvent::Progress, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_STAGE'), 'MESSAGE' => '', 'PARAMS' => array('START_STATUS_ID' => $arRow['STAGE_ID'], 'FINAL_STATUS_ID' => $arFields['STAGE_ID'])));
                             break;
                         case 'ASSIGNED_BY_ID':
                             $sonetEventData[CCrmLiveFeedEvent::Responsible] = array('TYPE' => CCrmLiveFeedEvent::Responsible, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_ASSIGNED_BY'), 'MESSAGE' => '', 'PARAMS' => array('START_RESPONSIBLE_ID' => $arRow['ASSIGNED_BY_ID'], 'FINAL_RESPONSIBLE_ID' => $arFields['ASSIGNED_BY_ID'])));
                             break;
                         case 'CONTACT_ID':
                         case 'COMPANY_ID':
                             if (!isset($sonetEventData[CCrmLiveFeedEvent::Client])) {
                                 $oldContactID = isset($arRow['CONTACT_ID']) ? intval($arRow['CONTACT_ID']) : 0;
                                 $oldCompanyID = isset($arRow['COMPANY_ID']) ? intval($arRow['COMPANY_ID']) : 0;
                                 $sonetEventData[CCrmLiveFeedEvent::Client] = array('CODE' => 'CLIENT', 'TYPE' => CCrmLiveFeedEvent::Client, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_CLIENT'), 'MESSAGE' => '', 'PARAMS' => array('START_CLIENT_CONTACT_ID' => $oldContactID, 'FINAL_CLIENT_CONTACT_ID' => isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : $oldContactID, 'START_CLIENT_COMPANY_ID' => $oldCompanyID, 'FINAL_CLIENT_COMPANY_ID' => isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : $oldCompanyID)));
                             }
                             break;
                         case 'TITLE':
                             $sonetEventData[CCrmLiveFeedEvent::Denomination] = array('TYPE' => CCrmLiveFeedEvent::Denomination, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_TITLE'), 'MESSAGE' => '', 'PARAMS' => array('START_TITLE' => $arRow['TITLE'], 'FINAL_TITLE' => $arFields['TITLE'])));
                             break;
                     }
                 }
             }
             // CHECK IF COMPANY/CONTACT WAS ADDED/REMOVED
             if (!isset($sonetEventData[CCrmLiveFeedEvent::Client]) && (!isset($arRow['COMPANY_ID']) && isset($arFields['COMPANY_ID']) || isset($arRow['COMPANY_ID']) && !isset($arFields['COMPANY_ID']) || !isset($arRow['CONTACT_ID']) && isset($arFields['CONTACT_ID']) || isset($arRow['CONTACT_ID']) && !isset($arFields['CONTACT_ID']))) {
                 $sonetEventData[CCrmLiveFeedEvent::Client] = array('CODE' => 'CLIENT', 'TYPE' => CCrmLiveFeedEvent::Client, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_CLIENT'), 'MESSAGE' => '', 'PARAMS' => array('START_CLIENT_CONTACT_ID' => isset($arRow['CONTACT_ID']) ? intval($arRow['CONTACT_ID']) : 0, 'FINAL_CLIENT_CONTACT_ID' => isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : 0, 'START_CLIENT_COMPANY_ID' => isset($arRow['COMPANY_ID']) ? intval($arRow['COMPANY_ID']) : 0, 'FINAL_CLIENT_COMPANY_ID' => isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : 0)));
             }
         }
         // Calculation of Account Data
         $accData = CCrmAccountingHelper::PrepareAccountingData(array('CURRENCY_ID' => isset($arFields['CURRENCY_ID']) ? $arFields['CURRENCY_ID'] : (isset($arRow['CURRENCY_ID']) ? $arRow['CURRENCY_ID'] : null), 'SUM' => isset($arFields['OPPORTUNITY']) ? $arFields['OPPORTUNITY'] : (isset($arRow['OPPORTUNITY']) ? $arRow['OPPORTUNITY'] : null), 'EXCH_RATE' => isset($arFields['EXCH_RATE']) ? $arFields['EXCH_RATE'] : (isset($arRow['EXCH_RATE']) ? $arRow['EXCH_RATE'] : null)));
         if (is_array($accData)) {
             $arFields['ACCOUNT_CURRENCY_ID'] = $accData['ACCOUNT_CURRENCY_ID'];
             $arFields['OPPORTUNITY_ACCOUNT'] = $accData['ACCOUNT_SUM'];
         }
         $accData = CCrmAccountingHelper::PrepareAccountingData(array('CURRENCY_ID' => isset($arFields['CURRENCY_ID']) ? $arFields['CURRENCY_ID'] : (isset($arRow['CURRENCY_ID']) ? $arRow['CURRENCY_ID'] : null), 'SUM' => isset($arFields['TAX_VALUE']) ? $arFields['TAX_VALUE'] : (isset($arRow['TAX_VALUE']) ? $arRow['TAX_VALUE'] : null), 'EXCH_RATE' => isset($arFields['EXCH_RATE']) ? $arFields['EXCH_RATE'] : (isset($arRow['EXCH_RATE']) ? $arRow['EXCH_RATE'] : null)));
         if (is_array($accData)) {
             $arFields['TAX_VALUE_ACCOUNT'] = $accData['ACCOUNT_SUM'];
         }
         $enableCloseDateSync = \Bitrix\Crm\Settings\DealSettings::isCloseDateSyncEnabled();
         if (isset($arFields['STAGE_ID'])) {
             $now = ConvertTimeStamp(time(), 'SHORT', SITE_ID);
             $isFinalStage = self::GetStageSemantics($arFields['STAGE_ID']) !== 'process';
             $isStageChanged = !isset($arRow['STAGE_ID']) || $arRow['STAGE_ID'] !== $arFields['STAGE_ID'];
             $arFields['CLOSED'] = $isFinalStage ? 'Y' : 'N';
             if ($enableCloseDateSync && $isFinalStage && $isStageChanged) {
                 $arFields['CLOSEDATE'] = $now;
                 $arFields['~CLOSEDATE'] = $DB->CharToDateFunction($now, 'SHORT', false);
             } elseif (isset($arFields['CLOSEDATE']) && $arFields['CLOSEDATE'] !== '') {
                 $arFields['~CLOSEDATE'] = $DB->CharToDateFunction($arFields['CLOSEDATE'], 'SHORT', false);
             }
         } elseif ($enableCloseDateSync && self::GetStageSemantics($arRow['STAGE_ID']) !== 'process' && isset($arFields['CLOSEDATE'])) {
             unset($arFields['CLOSEDATE']);
         }
         if (isset($arFields['BEGINDATE']) && $arFields['BEGINDATE'] !== '') {
             $arFields['~BEGINDATE'] = $DB->CharToDateFunction($arFields['BEGINDATE'], 'SHORT', false);
         }
         if (isset($arFields['BEGINDATE'])) {
             $arFields['__BEGINDATE'] = $arFields['BEGINDATE'];
             unset($arFields['BEGINDATE']);
         }
         if (isset($arFields['CLOSEDATE'])) {
             $arFields['__CLOSEDATE'] = $arFields['CLOSEDATE'];
             unset($arFields['CLOSEDATE']);
         }
         unset($arFields['ID']);
         $sUpdate = $DB->PrepareUpdate('b_crm_deal', $arFields);
         if (strlen($sUpdate) > 0) {
             $DB->Query("UPDATE b_crm_deal SET {$sUpdate} WHERE ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
             $bResult = true;
         }
         //Restore BEGINDATE and CLOSEDATE
         if (isset($arFields['__BEGINDATE'])) {
             $arFields['BEGINDATE'] = $arFields['__BEGINDATE'];
             unset($arFields['__BEGINDATE']);
         }
         if (isset($arFields['__CLOSEDATE'])) {
             $arFields['CLOSEDATE'] = $arFields['__CLOSEDATE'];
             unset($arFields['__CLOSEDATE']);
         }
         if (defined("BX_COMP_MANAGED_CACHE")) {
             static $arNameFields = array("TITLE");
             $bClear = false;
             foreach ($arNameFields as $val) {
                 if (isset($arFields[$val])) {
                     $bClear = true;
                     break;
                 }
             }
             if ($bClear) {
                 $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Deal . "_" . $ID);
             }
         }
         CCrmPerms::UpdateEntityAttr('DEAL', $ID, $arEntityAttr);
         CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $GLOBALS['USER_FIELD_MANAGER'], array('IS_NEW' => false));
         $GLOBALS['USER_FIELD_MANAGER']->Update(self::$sUFEntityID, $ID, $arFields);
         //Statistics & History -->
         $currentDbResult = \CCrmDeal::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('*', 'UF_*'));
         $currentFields = $currentDbResult->Fetch();
         Bitrix\Crm\Statistics\DealSumStatisticEntry::register($ID, $currentFields);
         Bitrix\Crm\History\DealStageHistoryEntry::synchronize($ID, $currentFields);
         Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::synchronize($ID, $currentFields);
         Bitrix\Crm\Statistics\DealActivityStatisticEntry::synchronize($ID, $currentFields);
         if (isset($arFields['STAGE_ID'])) {
             Bitrix\Crm\History\DealStageHistoryEntry::register($ID, $arFields, array('IS_NEW' => false));
         }
         //<-- Statistics & History
         if ($bUpdateSearch) {
             $arFilterTmp = array('ID' => $ID);
             if (!$this->bCheckPermission) {
                 $arFilterTmp['CHECK_PERMISSIONS'] = 'N';
             }
             CCrmSearch::UpdateSearch($arFilterTmp, 'DEAL', true);
         }
         $arFields['ID'] = $ID;
         if (isset($arFields['FM']) && is_array($arFields['FM'])) {
             $CCrmFieldMulti = new CCrmFieldMulti();
             $CCrmFieldMulti->SetFields('DEAL', $ID, $arFields['FM']);
         }
         // Responsible user sync
         //CCrmActivity::Synchronize(CCrmOwnerType::Deal, $ID);
         $registerSonetEvent = isset($options['REGISTER_SONET_EVENT']) && $options['REGISTER_SONET_EVENT'] === true;
         if ($bResult && isset($arFields['ASSIGNED_BY_ID'])) {
             CCrmSonetSubscription::ReplaceSubscriptionByEntity(CCrmOwnerType::Deal, $ID, CCrmSonetSubscriptionType::Responsibility, $arFields['ASSIGNED_BY_ID'], $arRow['ASSIGNED_BY_ID'], $registerSonetEvent);
         }
         if ($bResult && $bCompare && $registerSonetEvent && !empty($sonetEventData)) {
             //CONTACT
             $newContactID = isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : 0;
             $oldContactID = isset($arRow['CONTACT_ID']) ? intval($arRow['CONTACT_ID']) : 0;
             $contactID = $newContactID > 0 ? $newContactID : $oldContactID;
             //COMPANY
             $newCompanyID = isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : 0;
             $oldCompanyID = isset($arRow['COMPANY_ID']) ? intval($arRow['COMPANY_ID']) : 0;
             $companyID = $newCompanyID > 0 ? $newCompanyID : $oldCompanyID;
             $modifiedByID = intval($arFields['MODIFY_BY_ID']);
             foreach ($sonetEventData as &$sonetEvent) {
                 $sonetEventType = $sonetEvent['TYPE'];
                 $sonetEventCode = isset($sonetEvent['CODE']) ? $sonetEvent['CODE'] : '';
                 $sonetEventFields =& $sonetEvent['FIELDS'];
                 $sonetEventFields['ENTITY_TYPE_ID'] = CCrmOwnerType::Deal;
                 $sonetEventFields['ENTITY_ID'] = $ID;
                 $sonetEventFields['USER_ID'] = $modifiedByID;
                 //Register contact & company relations
                 if ($sonetEventCode === 'CLIENT') {
                     $sonetEventFields['PARENTS'] = array();
                     //If contact changed bind events to old and new contacts
                     if ($oldContactID !== $newContactID) {
                         if ($oldContactID > 0) {
                             $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $oldContactID);
                         }
                         if ($newContactID > 0) {
                             $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $newContactID);
                         }
                     }
                     //If company changed bind events to old and new companies
                     if ($oldCompanyID !== $newCompanyID) {
                         if ($oldCompanyID > 0) {
                             $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $oldCompanyID);
                         }
                         if ($newCompanyID > 0) {
                             $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $newCompanyID);
                         }
                     }
                 } elseif ($contactID > 0 || $companyID > 0) {
                     $sonetEventFields['PARENTS'] = array();
                     if ($contactID > 0) {
                         $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $contactID);
                     }
                     if ($companyID > 0) {
                         $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $companyID);
                     }
                 }
                 $logEventID = CCrmLiveFeed::CreateLogEvent($sonetEventFields, $sonetEventType);
                 if ($logEventID && CModule::IncludeModule("im")) {
                     $url = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Deal, $ID);
                     $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0 ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", ""));
                     if ($sonetEvent['TYPE'] == CCrmLiveFeedEvent::Responsible && $sonetEventFields['PARAMS']['FINAL_RESPONSIBLE_ID'] != $modifiedByID) {
                         $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $sonetEventFields['PARAMS']['FINAL_RESPONSIBLE_ID'], "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "deal_update", "NOTIFY_TAG" => "CRM|DEAL_RESPONSIBLE|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_DEAL_RESPONSIBLE_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>")), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_DEAL_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']))) . " (" . $serverName . $url . ")");
                         CIMNotify::Add($arMessageFields);
                     }
                     if ($sonetEvent['TYPE'] == CCrmLiveFeedEvent::Responsible && $sonetEventFields['PARAMS']['START_RESPONSIBLE_ID'] != $modifiedByID) {
                         $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $sonetEventFields['PARAMS']['START_RESPONSIBLE_ID'], "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "deal_update", "NOTIFY_TAG" => "CRM|DEAL_RESPONSIBLE|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_DEAL_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>")), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_DEAL_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']))) . " (" . $serverName . $url . ")");
                         CIMNotify::Add($arMessageFields);
                     }
                     if ($sonetEvent['TYPE'] == CCrmLiveFeedEvent::Progress && $sonetEventFields['PARAMS']['START_STATUS_ID'] && $sonetEventFields['PARAMS']['FINAL_STATUS_ID']) {
                         $assignedByID = isset($arFields['ASSIGNED_BY_ID']) ? $arFields['ASSIGNED_BY_ID'] : $arRow['ASSIGNED_BY_ID'];
                         $infos = CCrmStatus::GetStatus('DEAL_STAGE');
                         if ($assignedByID != $modifiedByID && array_key_exists($sonetEventFields['PARAMS']['START_STATUS_ID'], $infos) && array_key_exists($sonetEventFields['PARAMS']['FINAL_STATUS_ID'], $infos)) {
                             $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $assignedByID, "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "deal_update", "NOTIFY_TAG" => "CRM|DEAL_PROGRESS|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_DEAL_PROGRESS_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>", "#start_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['START_STATUS_ID']]['NAME']), "#final_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['FINAL_STATUS_ID']]['NAME']))), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_DEAL_PROGRESS_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']), "#start_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['START_STATUS_ID']]['NAME']), "#final_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['FINAL_STATUS_ID']]['NAME']))) . " (" . $serverName . $url . ")");
                             CIMNotify::Add($arMessageFields);
                         }
                     }
                 }
                 unset($sonetEventFields);
             }
             unset($sonetEvent);
         }
         if ($bResult) {
             $afterEvents = GetModuleEvents('crm', 'OnAfterCrmDealUpdate');
             while ($arEvent = $afterEvents->Fetch()) {
                 ExecuteModuleEventEx($arEvent, array(&$arFields));
             }
         }
         self::PullChange('UPDATE', array('ID' => $ID));
     }
     return $bResult;
 }
Esempio n. 7
0
 public function Update($ID, array &$arFields, $bCompare = true, $bUpdateSearch = true, $arOptions = array())
 {
     global $DB;
     $this->LAST_ERROR = '';
     $ID = (int) $ID;
     if (!is_array($arOptions)) {
         $arOptions = array();
     }
     $arFilterTmp = array('ID' => $ID);
     if (!$this->bCheckPermission) {
         $arFilterTmp['CHECK_PERMISSIONS'] = 'N';
     }
     $obRes = self::GetListEx(array(), $arFilterTmp);
     if (!($arRow = $obRes->Fetch())) {
         return false;
     }
     $iUserId = CCrmSecurityHelper::GetCurrentUserID();
     if (isset($arFields['DATE_CREATE'])) {
         unset($arFields['DATE_CREATE']);
     }
     if (isset($arFields['DATE_MODIFY'])) {
         unset($arFields['DATE_MODIFY']);
     }
     $arFields['~DATE_MODIFY'] = $DB->CurrentTimeFunction();
     if (isset($arFields['DATE_CLOSED'])) {
         unset($arFields['DATE_CLOSED']);
     }
     if (!empty($arFields['STATUS_ID']) && $arFields['STATUS_ID'] !== $arRow['STATUS_ID']) {
         self::EnsureStatusesLoaded();
         if (in_array($arFields['STATUS_ID'], self::$LEAD_STATUSES_BY_GROUP['FINISHED'])) {
             $arFields['~DATE_CLOSED'] = $DB->CurrentTimeFunction();
         }
     }
     if (!isset($arFields['MODIFY_BY_ID']) || $arFields['MODIFY_BY_ID'] <= 0) {
         $arFields['MODIFY_BY_ID'] = $iUserId;
     }
     if (isset($arFields['ASSIGNED_BY_ID']) && $arFields['ASSIGNED_BY_ID'] <= 0) {
         unset($arFields['ASSIGNED_BY_ID']);
     }
     $assignedByID = (int) (isset($arFields['ASSIGNED_BY_ID']) ? $arFields['ASSIGNED_BY_ID'] : $arRow['ASSIGNED_BY_ID']);
     $bResult = false;
     if (!$this->CheckFields($arFields, $ID, $arOptions)) {
         $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR;
     } else {
         if ($this->bCheckPermission && !CCrmAuthorizationHelper::CheckUpdatePermission(self::$TYPE_NAME, $ID, $this->cPerms)) {
             $this->LAST_ERROR = GetMessage('CRM_PERMISSION_DENIED');
             $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR;
             return false;
         }
         $beforeEvents = GetModuleEvents('crm', 'OnBeforeCrmLeadUpdate');
         while ($arEvent = $beforeEvents->Fetch()) {
             if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) {
                 if (isset($arFields['RESULT_MESSAGE'])) {
                     $this->LAST_ERROR = $arFields['RESULT_MESSAGE'];
                 } else {
                     $this->LAST_ERROR = GetMessage('CRM_LEAD_UPDATE_CANCELED', array('#NAME#' => $arEvent['TO_NAME']));
                     $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR;
                 }
                 return false;
             }
         }
         $arAttr = array();
         $arAttr['STATUS_ID'] = !empty($arFields['STATUS_ID']) ? $arFields['STATUS_ID'] : $arRow['STATUS_ID'];
         $arAttr['OPENED'] = !empty($arFields['OPENED']) ? $arFields['OPENED'] : $arRow['OPENED'];
         $arEntityAttr = self::BuildEntityAttr($assignedByID, $arAttr);
         $sEntityPerm = $this->cPerms->GetPermType('LEAD', 'WRITE', $arEntityAttr);
         $this->PrepareEntityAttrs($arEntityAttr, $sEntityPerm);
         //Prevent 'OPENED' field change by user restricted by BX_CRM_PERM_OPEN permission
         if ($sEntityPerm === BX_CRM_PERM_OPEN && isset($arFields['OPENED']) && $arFields['OPENED'] !== 'Y' && $assignedByID !== $iUserId) {
             $arFields['OPENED'] = 'Y';
         }
         if (isset($arFields['ASSIGNED_BY_ID']) && $arRow['ASSIGNED_BY_ID'] != $arFields['ASSIGNED_BY_ID']) {
             CCrmEvent::SetAssignedByElement($arFields['ASSIGNED_BY_ID'], 'LEAD', $ID);
         }
         $sonetEventData = array();
         if ($bCompare) {
             $res = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'LEAD', 'ELEMENT_ID' => $ID));
             $arRow['FM'] = array();
             while ($ar = $res->Fetch()) {
                 $arRow['FM'][$ar['TYPE_ID']][$ar['ID']] = array('VALUE' => $ar['VALUE'], 'VALUE_TYPE' => $ar['VALUE_TYPE']);
             }
             $arEvents = self::CompareFields($arRow, $arFields);
             foreach ($arEvents as $arEvent) {
                 $arEvent['ENTITY_TYPE'] = 'LEAD';
                 $arEvent['ENTITY_ID'] = $ID;
                 $arEvent['EVENT_TYPE'] = 1;
                 $CCrmEvent = new CCrmEvent();
                 $eventID = $CCrmEvent->Add($arEvent);
                 if (is_int($eventID) && $eventID > 0) {
                     $fieldID = isset($arEvent['ENTITY_FIELD']) ? $arEvent['ENTITY_FIELD'] : '';
                     if ($fieldID === '') {
                         continue;
                     }
                     switch ($fieldID) {
                         case 'STATUS_ID':
                             $sonetEventData[] = array('TYPE' => CCrmLiveFeedEvent::Progress, 'FIELDS' => array('TITLE' => GetMessage('CRM_LEAD_EVENT_UPDATE_STATUS'), 'MESSAGE' => '', 'PARAMS' => array('START_STATUS_ID' => $arRow['STATUS_ID'], 'FINAL_STATUS_ID' => $arFields['STATUS_ID'])));
                             break;
                         case 'ASSIGNED_BY_ID':
                             $sonetEventData[] = array('TYPE' => CCrmLiveFeedEvent::Responsible, 'FIELDS' => array('TITLE' => GetMessage('CRM_LEAD_EVENT_UPDATE_ASSIGNED_BY'), 'MESSAGE' => '', 'PARAMS' => array('START_RESPONSIBLE_ID' => $arRow['ASSIGNED_BY_ID'], 'FINAL_RESPONSIBLE_ID' => $arFields['ASSIGNED_BY_ID'])));
                             break;
                         case 'TITLE':
                             $sonetEventData[] = array('TYPE' => CCrmLiveFeedEvent::Denomination, 'FIELDS' => array('TITLE' => GetMessage('CRM_LEAD_EVENT_UPDATE_TITLE'), 'MESSAGE' => '', 'PARAMS' => array('START_TITLE' => $arRow['TITLE'], 'FINAL_TITLE' => $arFields['TITLE'])));
                             break;
                     }
                 }
             }
         }
         if (isset($arFields['BIRTHDAY_SORT'])) {
             unset($arFields['BIRTHDAY_SORT']);
         }
         if (isset($arFields['BIRTHDATE'])) {
             if ($arFields['BIRTHDATE'] !== '') {
                 $birthDate = $arFields['BIRTHDATE'];
                 $arFields['~BIRTHDATE'] = $DB->CharToDateFunction($birthDate, 'SHORT', false);
                 $arFields['BIRTHDAY_SORT'] = \Bitrix\Crm\BirthdayReminder::prepareSorting($birthDate);
                 unset($arFields['BIRTHDATE']);
             } else {
                 $arFields['BIRTHDAY_SORT'] = \Bitrix\Crm\BirthdayReminder::prepareSorting('');
             }
         }
         // Calculation of Account Data
         $accData = CCrmAccountingHelper::PrepareAccountingData(array('CURRENCY_ID' => isset($arFields['CURRENCY_ID']) ? $arFields['CURRENCY_ID'] : (isset($arRow['CURRENCY_ID']) ? $arRow['CURRENCY_ID'] : null), 'SUM' => isset($arFields['OPPORTUNITY']) ? $arFields['OPPORTUNITY'] : (isset($arRow['OPPORTUNITY']) ? $arRow['OPPORTUNITY'] : null), 'EXCH_RATE' => isset($arFields['EXCH_RATE']) ? $arFields['EXCH_RATE'] : (isset($arRow['EXCH_RATE']) ? $arRow['EXCH_RATE'] : null)));
         if (is_array($accData)) {
             $arFields['ACCOUNT_CURRENCY_ID'] = $accData['ACCOUNT_CURRENCY_ID'];
             $arFields['OPPORTUNITY_ACCOUNT'] = $accData['ACCOUNT_SUM'];
         }
         unset($arFields['ID']);
         if (isset($arFields['NAME']) && isset($arFields['LAST_NAME'])) {
             $arFields['FULL_NAME'] = trim($arFields['NAME'] . ' ' . $arFields['LAST_NAME']);
         } else {
             $dbRes = $DB->Query("SELECT NAME, LAST_NAME FROM b_crm_lead WHERE ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
             $arRes = $dbRes->Fetch();
             $arFields['FULL_NAME'] = trim((isset($arFields['NAME']) ? $arFields['NAME'] : $arRes['NAME']) . ' ' . (isset($arFields['LAST_NAME']) ? $arFields['LAST_NAME'] : $arRes['LAST_NAME']));
         }
         $sUpdate = $DB->PrepareUpdate('b_crm_lead', $arFields, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
         if (strlen($sUpdate) > 0) {
             $DB->Query("UPDATE b_crm_lead SET {$sUpdate} WHERE ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
             if (isset($arFields['COMPANY_TITLE'])) {
                 $newCompanyTitle = $arFields['COMPANY_TITLE'];
                 $oldCompanyTitle = isset($arRow['COMPANY_TITLE']) ? $arRow['COMPANY_TITLE'] : '';
                 if ($newCompanyTitle !== $oldCompanyTitle) {
                     \Bitrix\Crm\Integrity\DuplicateOrganizationCriterion::register(CCrmOwnerType::Lead, $ID, $newCompanyTitle);
                 }
             }
             if (isset($arFields['LAST_NAME']) || isset($arFields['NAME']) || isset($arFields['SECOND_NAME'])) {
                 $lastName = isset($arFields['LAST_NAME']) ? $arFields['LAST_NAME'] : (isset($arRow['LAST_NAME']) ? $arRow['LAST_NAME'] : '');
                 $name = isset($arFields['NAME']) ? $arFields['NAME'] : (isset($arRow['NAME']) ? $arRow['NAME'] : '');
                 $secondName = isset($arFields['SECOND_NAME']) ? $arFields['SECOND_NAME'] : (isset($arRow['SECOND_NAME']) ? $arRow['SECOND_NAME'] : '');
                 \Bitrix\Crm\Integrity\DuplicatePersonCriterion::register(CCrmOwnerType::Lead, $ID, $lastName, $name, $secondName);
             }
             $bResult = true;
         }
         if (defined("BX_COMP_MANAGED_CACHE")) {
             static $arNameFields = array("TITLE");
             $bClear = false;
             foreach ($arNameFields as $val) {
                 if (isset($arFields[$val])) {
                     $bClear = true;
                     break;
                 }
             }
             if ($bClear) {
                 $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Lead . "_" . $ID);
             }
         }
         CCrmPerms::UpdateEntityAttr('LEAD', $ID, $arEntityAttr);
         if (isset($arFields['ADDRESS']) || isset($arFields['ADDRESS_2']) || isset($arFields['ADDRESS_CITY']) || isset($arFields['ADDRESS_POSTAL_CODE']) || isset($arFields['ADDRESS_REGION']) || isset($arFields['ADDRESS_PROVINCE']) || isset($arFields['ADDRESS_COUNTRY'])) {
             \Bitrix\Crm\EntityAddress::register(CCrmOwnerType::Lead, $ID, \Bitrix\Crm\EntityAddress::Primary, array('ADDRESS_1' => isset($arFields['ADDRESS']) ? $arFields['ADDRESS'] : (isset($arRow['ADDRESS']) ? $arRow['ADDRESS'] : null), 'ADDRESS_2' => isset($arFields['ADDRESS_2']) ? $arFields['ADDRESS_2'] : (isset($arRow['ADDRESS_2']) ? $arRow['ADDRESS_2'] : null), 'CITY' => isset($arFields['ADDRESS_CITY']) ? $arFields['ADDRESS_CITY'] : (isset($arRow['ADDRESS_CITY']) ? $arRow['ADDRESS_CITY'] : null), 'POSTAL_CODE' => isset($arFields['ADDRESS_POSTAL_CODE']) ? $arFields['ADDRESS_POSTAL_CODE'] : (isset($arRow['ADDRESS_POSTAL_CODE']) ? $arRow['ADDRESS_POSTAL_CODE'] : null), 'REGION' => isset($arFields['ADDRESS_REGION']) ? $arFields['ADDRESS_REGION'] : (isset($arRow['ADDRESS_REGION']) ? $arRow['ADDRESS_REGION'] : null), 'PROVINCE' => isset($arFields['ADDRESS_PROVINCE']) ? $arFields['ADDRESS_PROVINCE'] : (isset($arRow['ADDRESS_PROVINCE']) ? $arRow['ADDRESS_PROVINCE'] : null), 'COUNTRY' => isset($arFields['ADDRESS_COUNTRY']) ? $arFields['ADDRESS_COUNTRY'] : (isset($arRow['ADDRESS_COUNTRY']) ? $arRow['ADDRESS_COUNTRY'] : null), 'COUNTRY_CODE' => isset($arFields['ADDRESS_COUNTRY_CODE']) ? $arFields['ADDRESS_COUNTRY_CODE'] : (isset($arRow['ADDRESS_COUNTRY_CODE']) ? $arRow['ADDRESS_COUNTRY_CODE'] : null)));
         }
         CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $GLOBALS['USER_FIELD_MANAGER'], array('IS_NEW' => false));
         $GLOBALS['USER_FIELD_MANAGER']->Update(self::$sUFEntityID, $ID, $arFields);
         if (isset($arFields['FM']) && is_array($arFields['FM'])) {
             $CCrmFieldMulti = new CCrmFieldMulti();
             $CCrmFieldMulti->SetFields(CCrmOwnerType::LeadName, $ID, $arFields['FM']);
             $multifields = \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::prepareEntityMultifieldsValues(CCrmOwnerType::Lead, $ID);
             \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::register(CCrmOwnerType::Lead, $ID, 'EMAIL', \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::extractMultifieldsValues($multifields, 'EMAIL'));
             \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::register(CCrmOwnerType::Lead, $ID, 'PHONE', \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::extractMultifieldsValues($multifields, 'PHONE'));
         }
         \Bitrix\Crm\Integrity\DuplicateEntityRanking::registerEntityStatistics(CCrmOwnerType::Lead, $ID, array_merge($arRow, $arFields));
         if ($bUpdateSearch) {
             CCrmSearch::UpdateSearch(array('ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), 'LEAD', true);
         }
         $arFields['ID'] = $ID;
         // Responsible user sync
         //CCrmActivity::Synchronize(CCrmOwnerType::Lead, $ID);
         // Sonet events registration
         $registerSonetEvent = isset($arOptions['REGISTER_SONET_EVENT']) && $arOptions['REGISTER_SONET_EVENT'] === true;
         if ($bResult && isset($arFields['ASSIGNED_BY_ID'])) {
             CCrmSonetSubscription::ReplaceSubscriptionByEntity(CCrmOwnerType::Lead, $ID, CCrmSonetSubscriptionType::Responsibility, $arFields['ASSIGNED_BY_ID'], $arRow['ASSIGNED_BY_ID'], $registerSonetEvent);
         }
         if ($bResult && $bCompare && $registerSonetEvent && !empty($sonetEventData)) {
             $modifiedByID = intval($arFields['MODIFY_BY_ID']);
             foreach ($sonetEventData as &$sonetEvent) {
                 $sonetEventFields =& $sonetEvent['FIELDS'];
                 $sonetEventFields['ENTITY_TYPE_ID'] = CCrmOwnerType::Lead;
                 $sonetEventFields['ENTITY_ID'] = $ID;
                 $sonetEventFields['USER_ID'] = $modifiedByID;
                 $logEventID = CCrmLiveFeed::CreateLogEvent($sonetEventFields, $sonetEvent['TYPE']);
                 if ($logEventID && CModule::IncludeModule("im")) {
                     $url = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Lead, $ID);
                     $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0 ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", ""));
                     if ($sonetEventFields['PARAMS']['FINAL_RESPONSIBLE_ID'] != $modifiedByID && $sonetEvent['TYPE'] == CCrmLiveFeedEvent::Responsible) {
                         $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $sonetEventFields['PARAMS']['FINAL_RESPONSIBLE_ID'], "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "lead_update", "NOTIFY_TAG" => "CRM|LEAD_RESPONSIBLE|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_LEAD_RESPONSIBLE_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>")), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_LEAD_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']))) . " (" . $serverName . $url . ")");
                         CIMNotify::Add($arMessageFields);
                     }
                     if ($sonetEvent['TYPE'] == CCrmLiveFeedEvent::Responsible && $sonetEventFields['PARAMS']['START_RESPONSIBLE_ID'] != $modifiedByID) {
                         $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $sonetEventFields['PARAMS']['START_RESPONSIBLE_ID'], "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "lead_update", "NOTIFY_TAG" => "CRM|LEAD_RESPONSIBLE|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_LEAD_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>")), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_LEAD_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']))) . " (" . $serverName . $url . ")");
                         CIMNotify::Add($arMessageFields);
                     }
                     if ($sonetEvent['TYPE'] == CCrmLiveFeedEvent::Progress && $sonetEventFields['PARAMS']['START_STATUS_ID'] && $sonetEventFields['PARAMS']['FINAL_STATUS_ID']) {
                         $assignedByID = isset($arFields['ASSIGNED_BY_ID']) ? $arFields['ASSIGNED_BY_ID'] : $arRow['ASSIGNED_BY_ID'];
                         $infos = CCrmStatus::GetStatus('STATUS');
                         if ($assignedByID != $modifiedByID && array_key_exists($sonetEventFields['PARAMS']['START_STATUS_ID'], $infos) && array_key_exists($sonetEventFields['PARAMS']['FINAL_STATUS_ID'], $infos)) {
                             $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $assignedByID, "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "lead_update", "NOTIFY_TAG" => "CRM|LEAD_PROGRESS|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_LEAD_PROGRESS_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>", "#start_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['START_STATUS_ID']]['NAME']), "#final_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['FINAL_STATUS_ID']]['NAME']))), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_LEAD_PROGRESS_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']), "#start_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['START_STATUS_ID']]['NAME']), "#final_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['FINAL_STATUS_ID']]['NAME']))) . " (" . $serverName . $url . ")");
                             CIMNotify::Add($arMessageFields);
                         }
                     }
                 }
                 unset($sonetEventFields);
             }
             unset($sonetEvent);
         }
         if ($bResult) {
             $afterEvents = GetModuleEvents('crm', 'OnAfterCrmLeadUpdate');
             while ($arEvent = $afterEvents->Fetch()) {
                 ExecuteModuleEventEx($arEvent, array(&$arFields));
             }
         }
     }
     return $bResult;
 }
Esempio n. 8
0
 public static function PrepareClientInfoV2($arParams)
 {
     $showUrl = isset($arParams['SHOW_URL']) ? $arParams['SHOW_URL'] : '';
     if ($showUrl === '') {
         $entityTypeID = isset($arParams['ENTITY_TYPE_ID']) ? intval($arParams['ENTITY_TYPE_ID']) : 0;
         $entityID = isset($arParams['ENTITY_ID']) ? intval($arParams['ENTITY_ID']) : 0;
         if ($entityTypeID > 0 && $entityID > 0) {
             $showUrl = CCrmOwnerType::GetShowUrl($entityTypeID, $entityID);
         }
     }
     $photoID = isset($arParams['PHOTO_ID']) ? intval($arParams['PHOTO_ID']) : 0;
     $photoUrl = $photoID > 0 ? CFile::ResizeImageGet($photoID, array('width' => 30, 'height' => 30), BX_RESIZE_IMAGE_EXACT) : '';
     $name = isset($arParams['NAME']) ? $arParams['NAME'] : '';
     $description = isset($arParams['DESCRIPTION']) ? $arParams['DESCRIPTION'] : '';
     $html = isset($arParams['ADDITIONAL_HTML']) ? $arParams['ADDITIONAL_HTML'] : '';
     if ($showUrl !== '') {
         return '<a class="crm-item-client-block" href="' . htmlspecialcharsbx($showUrl) . '"><div class="crm-item-client-img">' . (isset($photoUrl['src']) ? '<img alt="" src="' . htmlspecialcharsbx($photoUrl['src']) . '"/>' : '') . '</div>' . '<span class="crm-item-client-alignment"></span>' . '<span class="crm-item-client-alignment-block">' . '<div class="crm-item-client-name">' . htmlspecialcharsbx($name) . '</div><div class="crm-item-client-description">' . htmlspecialcharsbx($description) . $html . '</div></span></a>';
     }
     return '<span class="crm-item-client-block"><div class="crm-item-client-img">' . (isset($photoUrl['src']) ? '<img alt="" src="' . htmlspecialcharsbx($photoUrl['src']) . '"/>' : '') . '</div>' . '<span class="crm-item-client-alignment"></span>' . '<span class="crm-item-client-alignment-block">' . '<div class="crm-item-client-name">' . htmlspecialcharsbx($name) . '</div><div class="crm-item-client-description">' . htmlspecialcharsbx($description) . $html . '</div></span></span>';
 }
Esempio n. 9
0
 public function Update($ID, array &$arFields, $bCompare = true, $bUpdateSearch = true, $options = array())
 {
     global $DB;
     $this->LAST_ERROR = '';
     $ID = (int) $ID;
     if (!is_array($options)) {
         $options = array();
     }
     $arFilterTmp = array('ID' => $ID);
     if (!$this->bCheckPermission) {
         $arFilterTmp['CHECK_PERMISSIONS'] = 'N';
     }
     $obRes = self::GetListEx(array(), $arFilterTmp);
     if (!($arRow = $obRes->Fetch())) {
         return false;
     }
     $iUserId = CCrmSecurityHelper::GetCurrentUserID();
     if (isset($arFields['DATE_CREATE'])) {
         unset($arFields['DATE_CREATE']);
     }
     if (isset($arFields['DATE_MODIFY'])) {
         unset($arFields['DATE_MODIFY']);
     }
     $arFields['~DATE_MODIFY'] = $DB->CurrentTimeFunction();
     if (!isset($arFields['MODIFY_BY_ID']) || $arFields['MODIFY_BY_ID'] <= 0) {
         $arFields['MODIFY_BY_ID'] = $iUserId;
     }
     if (isset($arFields['REVENUE'])) {
         $arFields['REVENUE'] = floatval($arFields['REVENUE']);
     }
     if (isset($arFields['ASSIGNED_BY_ID']) && $arFields['ASSIGNED_BY_ID'] <= 0) {
         unset($arFields['ASSIGNED_BY_ID']);
     }
     $assignedByID = (int) (isset($arFields['ASSIGNED_BY_ID']) ? $arFields['ASSIGNED_BY_ID'] : $arRow['ASSIGNED_BY_ID']);
     $bResult = false;
     if (!$this->CheckFields($arFields, $ID, $options)) {
         $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR;
     } else {
         if ($this->bCheckPermission && !CCrmAuthorizationHelper::CheckUpdatePermission(self::$TYPE_NAME, $ID, $this->cPerms)) {
             $this->LAST_ERROR = GetMessage('CRM_PERMISSION_DENIED');
             $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR;
             return false;
         }
         $arAttr = array();
         $arAttr['OPENED'] = !empty($arFields['OPENED']) ? $arFields['OPENED'] : $arRow['OPENED'];
         $arEntityAttr = self::BuildEntityAttr($assignedByID, $arAttr);
         $sEntityPerm = $this->cPerms->GetPermType('COMPANY', 'WRITE', $arEntityAttr);
         $this->PrepareEntityAttrs($arEntityAttr, $sEntityPerm);
         //Prevent 'OPENED' field change by user restricted by BX_CRM_PERM_OPEN permission
         if ($sEntityPerm === BX_CRM_PERM_OPEN && isset($arFields['OPENED']) && $arFields['OPENED'] !== 'Y' && $assignedByID !== $iUserId) {
             $arFields['OPENED'] = 'Y';
         }
         if (isset($arFields['LOGO']) && is_array($arFields['LOGO']) && strlen(CFile::CheckImageFile($arFields['LOGO'])) === 0) {
             $arFields['LOGO']['MODULE_ID'] = 'crm';
             if ($arFields['LOGO_del'] == 'Y' && !empty($arRow['LOGO'])) {
                 CFile::Delete($arRow['LOGO']);
             }
             CFile::SaveForDB($arFields, 'LOGO', 'crm');
             if ($arFields['LOGO_del'] == 'Y' && !isset($arFields['LOGO'])) {
                 $arFields['LOGO'] = '';
             }
         }
         $sonetEventData = array();
         if ($bCompare) {
             $res = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'COMPANY', 'ELEMENT_ID' => $ID));
             $arRow['FM'] = array();
             while ($ar = $res->Fetch()) {
                 $arRow['FM'][$ar['TYPE_ID']][$ar['ID']] = array('VALUE' => $ar['VALUE'], 'VALUE_TYPE' => $ar['VALUE_TYPE']);
             }
             $arEvents = self::CompareFields($arRow, $arFields);
             foreach ($arEvents as $arEvent) {
                 $arEvent['ENTITY_TYPE'] = 'COMPANY';
                 $arEvent['ENTITY_ID'] = $ID;
                 $arEvent['EVENT_TYPE'] = 1;
                 if (!isset($arEvent['USER_ID'])) {
                     $arEvent['USER_ID'] = $iUserId;
                 }
                 $CCrmEvent = new CCrmEvent();
                 $eventID = $CCrmEvent->Add($arEvent, $this->bCheckPermission);
                 if (is_int($eventID) && $eventID > 0) {
                     $fieldID = isset($arEvent['ENTITY_FIELD']) ? $arEvent['ENTITY_FIELD'] : '';
                     if ($fieldID === '') {
                         continue;
                     }
                     switch ($fieldID) {
                         case 'ASSIGNED_BY_ID':
                             $sonetEventData[] = array('TYPE' => CCrmLiveFeedEvent::Responsible, 'FIELDS' => array('TITLE' => GetMessage('CRM_COMPANY_EVENT_UPDATE_ASSIGNED_BY'), 'MESSAGE' => '', 'PARAMS' => array('START_RESPONSIBLE_ID' => $arRow['ASSIGNED_BY_ID'], 'FINAL_RESPONSIBLE_ID' => $arFields['ASSIGNED_BY_ID'])));
                             break;
                         case 'TITLE':
                             $sonetEventData[] = array('TYPE' => CCrmLiveFeedEvent::Denomination, 'FIELDS' => array('TITLE' => GetMessage('CRM_COMPANY_EVENT_UPDATE_TITLE'), 'MESSAGE' => '', 'PARAMS' => array('START_TITLE' => $arRow['TITLE'], 'FINAL_TITLE' => $arFields['TITLE'])));
                             break;
                     }
                 }
             }
         }
         unset($arFields["ID"]);
         $beforeEvents = GetModuleEvents('crm', 'OnBeforeCrmCompanyUpdate');
         while ($arEvent = $beforeEvents->Fetch()) {
             if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) {
                 if (isset($arFields['RESULT_MESSAGE'])) {
                     $this->LAST_ERROR = $arFields['RESULT_MESSAGE'];
                 } else {
                     $this->LAST_ERROR = GetMessage('CRM_COMPANY_UPDATE_CANCELED', array('#NAME#' => $arEvent['TO_NAME']));
                     $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR;
                 }
                 return false;
             }
         }
         $sUpdate = $DB->PrepareUpdate('b_crm_company', $arFields, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
         if (strlen($sUpdate) > 0) {
             $DB->Query("UPDATE b_crm_company SET {$sUpdate} WHERE ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
             $bResult = true;
             $newTitle = isset($arFields['TITLE']) ? $arFields['TITLE'] : '';
             $oldTitle = isset($arRow['TITLE']) ? $arRow['TITLE'] : '';
             if ($newTitle !== '' && $newTitle !== $oldTitle) {
                 \Bitrix\Crm\Integrity\DuplicateOrganizationCriterion::register(CCrmOwnerType::Company, $ID, $newTitle);
             }
         }
         if (defined("BX_COMP_MANAGED_CACHE")) {
             static $arNameFields = array("TITLE");
             $bClear = false;
             foreach ($arNameFields as $val) {
                 if (isset($arFields[$val])) {
                     $bClear = true;
                     break;
                 }
             }
             if ($bClear) {
                 $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Company . "_" . $ID);
             }
         }
         CCrmPerms::UpdateEntityAttr('COMPANY', $ID, $arEntityAttr);
         CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $GLOBALS['USER_FIELD_MANAGER'], array('IS_NEW' => false));
         $GLOBALS['USER_FIELD_MANAGER']->Update(self::$sUFEntityID, $ID, $arFields);
         if (isset($arFields['FM']) && is_array($arFields['FM'])) {
             $CCrmFieldMulti = new CCrmFieldMulti();
             $CCrmFieldMulti->SetFields('COMPANY', $ID, $arFields['FM']);
             \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::register(CCrmOwnerType::Company, $ID, 'EMAIL', \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::extractMultifieldsValues($arFields['FM'], 'EMAIL'));
             \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::register(CCrmOwnerType::Company, $ID, 'PHONE', \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::extractMultifieldsValues($arFields['FM'], 'PHONE'));
         }
         \Bitrix\Crm\Integrity\DuplicateEntityRanking::registerEntityStatistics(CCrmOwnerType::Company, $ID, array_merge($arRow, $arFields));
         if ($bUpdateSearch) {
             CCrmSearch::UpdateSearch(array('ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), 'COMPANY', true);
         }
         $arFields['ID'] = $ID;
         if (isset($arFields['CONTACT_ID']) && is_array($arFields['CONTACT_ID'])) {
             if (!empty($arFields['CONTACT_ID'])) {
                 $arCurrentContact = array();
                 $res = CCrmContact::GetContactByCompanyId($arFields['ID']);
                 while ($ar = $res->Fetch()) {
                     $arCurrentContact[] = $ar['ID'];
                 }
                 $arAdd = array_diff($arFields['CONTACT_ID'], $arCurrentContact);
                 $arDelete = array_diff($arCurrentContact, $arFields['CONTACT_ID']);
                 $CCrmContact = new CCrmContact();
                 $CCrmContact->UpdateCompanyId($arAdd, $arFields['ID']);
                 $CCrmContact->UpdateCompanyId($arDelete, 0);
                 if (isset($GLOBALS["USER"])) {
                     if (!class_exists('CUserOptions')) {
                         include_once $_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/classes/" . $GLOBALS['DBType'] . "/favorites.php";
                     }
                     CUserOptions::SetOption("crm", "crm_contact_search", array('last_selected' => implode(',', $arAdd)));
                 }
             } else {
                 $arDelete = array();
                 $res = CCrmContact::GetContactByCompanyId($arFields['ID']);
                 while ($ar = $res->Fetch()) {
                     $arDelete[] = $ar['ID'];
                 }
                 $CCrmContact = new CCrmContact();
                 $CCrmContact->UpdateCompanyId($arDelete, 0);
             }
         }
         $registerSonetEvent = isset($options['REGISTER_SONET_EVENT']) && $options['REGISTER_SONET_EVENT'] === true;
         if ($bResult && isset($arFields['ASSIGNED_BY_ID'])) {
             CCrmSonetSubscription::ReplaceSubscriptionByEntity(CCrmOwnerType::Company, $ID, CCrmSonetSubscriptionType::Responsibility, $arFields['ASSIGNED_BY_ID'], $arRow['ASSIGNED_BY_ID'], $registerSonetEvent);
         }
         if ($bResult && $bCompare && $registerSonetEvent && !empty($sonetEventData)) {
             $modifiedByID = intval($arFields['MODIFY_BY_ID']);
             foreach ($sonetEventData as &$sonetEvent) {
                 $sonetEventFields =& $sonetEvent['FIELDS'];
                 $sonetEventFields['ENTITY_TYPE_ID'] = CCrmOwnerType::Company;
                 $sonetEventFields['ENTITY_ID'] = $ID;
                 $sonetEventFields['USER_ID'] = $modifiedByID;
                 $logEventID = CCrmLiveFeed::CreateLogEvent($sonetEventFields, $sonetEvent['TYPE']);
                 if ($logEventID && $sonetEvent['TYPE'] == CCrmLiveFeedEvent::Responsible && CModule::IncludeModule("im")) {
                     $url = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Company, $ID);
                     $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0 ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", ""));
                     if ($sonetEventFields['PARAMS']['FINAL_RESPONSIBLE_ID'] != $modifiedByID) {
                         $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $sonetEventFields['PARAMS']['FINAL_RESPONSIBLE_ID'], "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "company_update", "NOTIFY_TAG" => "CRM|COMPANY_RESPONSIBLE|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_COMPANY_RESPONSIBLE_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>")), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_COMPANY_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']))) . " (" . $serverName . $url . ")");
                         CIMNotify::Add($arMessageFields);
                     }
                     if ($sonetEventFields['PARAMS']['START_RESPONSIBLE_ID'] != $modifiedByID) {
                         $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $sonetEventFields['PARAMS']['START_RESPONSIBLE_ID'], "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "company_update", "NOTIFY_TAG" => "CRM|COMPANY_RESPONSIBLE|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_COMPANY_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>")), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_COMPANY_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']))) . " (" . $serverName . $url . ")");
                         CIMNotify::Add($arMessageFields);
                     }
                 }
                 unset($sonetEventFields);
             }
             unset($sonetEvent);
         }
         if ($bResult) {
             $afterEvents = GetModuleEvents('crm', 'OnAfterCrmCompanyUpdate');
             while ($arEvent = $afterEvents->Fetch()) {
                 ExecuteModuleEventEx($arEvent, array(&$arFields));
             }
         }
     }
     return $bResult;
 }
Esempio n. 10
0
 public static function findByPhoneNumber($number, $params = array())
 {
     if (!is_string($number)) {
         throw new \Bitrix\Main\ArgumentTypeException('number', 'string');
     }
     if ($number === '') {
         throw new \Bitrix\Main\ArgumentException('Is empty', 'number');
     }
     if (!is_array($params)) {
         $params = array();
     }
     $userID = isset($params['USER_ID']) ? intval($params['USER_ID']) : 0;
     if ($userID <= 0) {
         $userID = CCrmPerms::GetCurrentUserID();
     }
     $isAdmin = CCrmPerms::IsAdmin($userID);
     $userPermissions = CCrmPerms::GetUserPermissions($userID);
     $enableExtendedMode = isset($params['ENABLE_EXTENDED_MODE']) ? (bool) $params['ENABLE_EXTENDED_MODE'] : true;
     $contactFormID = isset($params['CONTACT_FORM_ID']) ? intval($params['CONTACT_FORM_ID']) : '';
     if ($contactFormID === '') {
         $contactFormID = CCrmContact::DEFAULT_FORM_ID;
     }
     $dups = array();
     $criterion = new \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion('PHONE', $number);
     $entityTypes = array(CCrmOwnerType::Contact, CCrmOwnerType::Company, CCrmOwnerType::Lead);
     foreach ($entityTypes as $entityType) {
         $duplicate = $criterion->find($entityType, 1);
         if ($duplicate !== null) {
             $dups[] = $duplicate;
         }
     }
     $entityByType = array();
     foreach ($dups as &$dup) {
         /** @var \Bitrix\Crm\Integrity\Duplicate $dup */
         $entities = $dup->getEntities();
         if (!(is_array($entities) && !empty($entities))) {
             continue;
         }
         //Each entity type limited by 50 items
         foreach ($entities as &$entity) {
             /** @var \Bitrix\Crm\Integrity\DuplicateEntity $entity */
             $entityTypeID = $entity->getEntityTypeID();
             $entityID = $entity->getEntityID();
             $fields = null;
             if ($entityTypeID === CCrmOwnerType::Contact) {
                 $dbEntity = CCrmContact::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'HONORIFIC', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'PHOTO', 'POST', 'COMPANY_ID', 'COMPANY_TITLE', 'ASSIGNED_BY_ID'));
                 $entityFields = is_object($dbEntity) ? $dbEntity->Fetch() : null;
                 if (is_array($entityFields)) {
                     $formattedName = CCrmContact::PrepareFormattedName(array('HONORIFIC' => isset($entityFields['HONORIFIC']) ? $entityFields['HONORIFIC'] : '', 'NAME' => isset($entityFields['NAME']) ? $entityFields['NAME'] : '', 'SECOND_NAME' => isset($entityFields['SECOND_NAME']) ? $entityFields['SECOND_NAME'] : '', 'LAST_NAME' => isset($entityFields['LAST_NAME']) ? $entityFields['LAST_NAME'] : ''));
                     $fields = array('ID' => intval($entityFields['ID']), 'FORMATTED_NAME' => $formattedName, 'PHOTO' => isset($entityFields['PHOTO']) ? intval($entityFields['PHOTO']) : 0, 'COMPANY_ID' => isset($entityFields['COMPANY_ID']) ? intval($entityFields['COMPANY_ID']) : 0, 'COMPANY_TITLE' => isset($entityFields['COMPANY_TITLE']) ? $entityFields['COMPANY_TITLE'] : '', 'POST' => isset($entityFields['POST']) ? $entityFields['POST'] : '', 'ASSIGNED_BY_ID' => isset($entityFields['ASSIGNED_BY_ID']) ? intval($entityFields['ASSIGNED_BY_ID']) : 0, 'CAN_READ' => CCrmContact::CheckReadPermission($entityID, $userPermissions));
                     if ($fields['CAN_READ'] && $enableExtendedMode) {
                         $deals = array();
                         $dbDeal = CCrmDeal::GetListEx(array('BEGINDATE' => 'ASC'), array('=CONTACT_ID' => $entityID, 'CLOSED' => 'N', 'CHECK_PERMISSIONS' => $isAdmin ? 'N' : 'Y'), false, array('nTopCount' => 2), array('ID', 'TITLE', 'STAGE_ID'), array('PERMS' => $userPermissions));
                         if (is_object($dbDeal)) {
                             while ($dealFields = $dbDeal->Fetch()) {
                                 $dealID = intval($dealFields['ID']);
                                 //$dealFields['CAN_READ'] = CCrmDeal::CheckReadPermission($dealID, $userPermissions);
                                 $dealFields['SHOW_URL'] = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Deal, $dealID);
                                 $deals[] = $dealFields;
                             }
                         }
                         $fields['DEALS'] =& $deals;
                         unset($deals);
                     }
                 }
             } elseif ($entityTypeID === CCrmOwnerType::Company) {
                 $dbEntity = CCrmCompany::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'TITLE', 'LOGO', 'ASSIGNED_BY_ID'));
                 $entityFields = is_object($dbEntity) ? $dbEntity->Fetch() : null;
                 if (is_array($entityFields)) {
                     $fields = array('ID' => intval($entityFields['ID']), 'TITLE' => isset($entityFields['TITLE']) ? $entityFields['TITLE'] : '', 'LOGO' => isset($entityFields['LOGO']) ? intval($entityFields['LOGO']) : 0, 'ASSIGNED_BY_ID' => isset($entityFields['ASSIGNED_BY_ID']) ? intval($entityFields['ASSIGNED_BY_ID']) : 0, 'CAN_READ' => CCrmCompany::CheckReadPermission($entityID, $userPermissions));
                     if ($fields['CAN_READ'] && $enableExtendedMode) {
                         $deals = array();
                         $dbDeal = CCrmDeal::GetListEx(array('BEGINDATE' => 'ASC'), array('=COMPANY_ID' => $entityID, 'CLOSED' => 'N', 'CHECK_PERMISSIONS' => $isAdmin ? 'N' : 'Y'), false, array('nTopCount' => 2), array('ID', 'TITLE', 'STAGE_ID'), array('PERMS' => $userPermissions));
                         if (is_object($dbDeal)) {
                             while ($dealFields = $dbDeal->Fetch()) {
                                 $dealID = intval($dealFields['ID']);
                                 //$dealFields['CAN_READ'] = CCrmDeal::CheckReadPermission($dealID, $userPermissions);
                                 $dealFields['SHOW_URL'] = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Deal, $dealID);
                                 $deals[] = $dealFields;
                             }
                         }
                         $fields['DEALS'] =& $deals;
                         unset($deals);
                     }
                 }
             } elseif ($entityTypeID === CCrmOwnerType::Lead) {
                 $dbEntity = CCrmLead::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'TITLE', 'HONORIFIC', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'POST', 'COMPANY_TITLE', 'ASSIGNED_BY_ID'));
                 $entityFields = is_object($dbEntity) ? $dbEntity->Fetch() : null;
                 if (is_array($entityFields)) {
                     $formattedName = '';
                     if (!empty($entityFields['NAME']) || !empty($entityFields['SECOND_NAME']) || !empty($entityFields['LAST_NAME'])) {
                         $formattedName = CCrmLead::PrepareFormattedName(array('HONORIFIC' => isset($entityFields['HONORIFIC']) ? $entityFields['HONORIFIC'] : '', 'NAME' => isset($entityFields['NAME']) ? $entityFields['NAME'] : '', 'SECOND_NAME' => isset($entityFields['SECOND_NAME']) ? $entityFields['SECOND_NAME'] : '', 'LAST_NAME' => isset($entityFields['LAST_NAME']) ? $entityFields['LAST_NAME'] : ''));
                     }
                     $fields = array('ID' => intval($entityFields['ID']), 'TITLE' => isset($entityFields['TITLE']) ? $entityFields['TITLE'] : '', 'FORMATTED_NAME' => $formattedName, 'COMPANY_TITLE' => isset($entityFields['COMPANY_TITLE']) ? $entityFields['COMPANY_TITLE'] : '', 'POST' => isset($entityFields['POST']) ? $entityFields['POST'] : '', 'ASSIGNED_BY_ID' => isset($entityFields['ASSIGNED_BY_ID']) ? intval($entityFields['ASSIGNED_BY_ID']) : 0, 'CAN_READ' => CCrmLead::CheckReadPermission($entityID, $userPermissions));
                 }
             }
             if (!is_array($fields)) {
                 continue;
             }
             if ($fields['CAN_READ'] && $enableExtendedMode) {
                 $showUrl = $fields['SHOW_URL'] = CCrmOwnerType::GetShowUrl($entityTypeID, $entityID);
                 if ($showUrl !== '') {
                     $fields['ACTIVITY_LIST_URL'] = CCrmUrlUtil::AddUrlParams($showUrl, array("{$contactFormID}_active_tab" => 'tab_activity'));
                     $fields['INVOICE_LIST_URL'] = CCrmUrlUtil::AddUrlParams($showUrl, array("{$contactFormID}_active_tab" => 'tab_invoice'));
                     if ($entityTypeID === CCrmOwnerType::Contact || $entityTypeID === CCrmOwnerType::Company) {
                         $fields['DEAL_LIST_URL'] = CCrmUrlUtil::AddUrlParams($showUrl, array("{$contactFormID}_active_tab" => 'tab_deal'));
                     }
                 }
                 $activities = array();
                 $dbActivity = CCrmActivity::GetList(array('DEADLINE' => 'ASC'), array('COMPLETED' => 'N', 'BINDINGS' => array(array('OWNER_TYPE_ID' => $entityTypeID, 'OWNER_ID' => $entityID)), 'CHECK_PERMISSIONS' => $isAdmin ? 'N' : 'Y'), false, array('nTopCount' => 4), array('ID', 'SUBJECT', 'START_TIME', 'END_TIME', 'DEADLINE'), array('PERMS' => $userPermissions));
                 if (is_object($dbActivity)) {
                     while ($activityFields = $dbActivity->Fetch()) {
                         $activityFields['SHOW_URL'] = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Activity, $activityFields['ID']);
                         $activities[] =& $activityFields;
                         unset($activityFields);
                     }
                 }
                 $fields['ACTIVITIES'] =& $activities;
                 unset($activities);
             }
             $entityTypeName = CCrmOwnerType::ResolveName($entityTypeID);
             if (!isset($entityByType[$entityTypeName])) {
                 $entityByType[$entityTypeName] = array($fields);
             } elseif (!in_array($entityID, $entityByType[$entityTypeName], true)) {
                 $entityByType[$entityTypeName][] = $fields;
             }
         }
     }
     unset($dup);
     return $entityByType;
 }
Esempio n. 11
0
 public function Update($ID, array &$arFields, $bCompare = true, $bUpdateSearch = true, $arOptions = array())
 {
     global $DB;
     $this->LAST_ERROR = '';
     $ID = (int) $ID;
     if (!is_array($arOptions)) {
         $arOptions = array();
     }
     $arFilterTmp = array('ID' => $ID);
     if (!$this->bCheckPermission) {
         $arFilterTmp['CHECK_PERMISSIONS'] = 'N';
     }
     $obRes = self::GetListEx(array(), $arFilterTmp);
     if (!($arRow = $obRes->Fetch())) {
         return false;
     }
     $iUserId = CCrmSecurityHelper::GetCurrentUserID();
     if (isset($arFields['DATE_CREATE'])) {
         unset($arFields['DATE_CREATE']);
     }
     if (isset($arFields['DATE_MODIFY'])) {
         unset($arFields['DATE_MODIFY']);
     }
     $arFields['~DATE_MODIFY'] = $DB->CurrentTimeFunction();
     if (!isset($arFields['MODIFY_BY_ID']) || $arFields['MODIFY_BY_ID'] <= 0) {
         $arFields['MODIFY_BY_ID'] = $iUserId;
     }
     if (isset($arFields['ASSIGNED_BY_ID']) && $arFields['ASSIGNED_BY_ID'] <= 0) {
         unset($arFields['ASSIGNED_BY_ID']);
     }
     $assignedByID = (int) (isset($arFields['ASSIGNED_BY_ID']) ? $arFields['ASSIGNED_BY_ID'] : $arRow['ASSIGNED_BY_ID']);
     $bResult = false;
     if (!$this->CheckFields($arFields, $ID, $arOptions)) {
         $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR;
     } else {
         if ($this->bCheckPermission && !CCrmAuthorizationHelper::CheckUpdatePermission(self::$TYPE_NAME, $ID, $this->cPerms)) {
             $this->LAST_ERROR = GetMessage('CRM_PERMISSION_DENIED');
             $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR;
             return false;
         }
         if (!isset($arFields['ID'])) {
             $arFields['ID'] = $ID;
         }
         $beforeEvents = GetModuleEvents('crm', 'OnBeforeCrmContactUpdate');
         while ($arEvent = $beforeEvents->Fetch()) {
             if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) {
                 if (isset($arFields['RESULT_MESSAGE'])) {
                     $this->LAST_ERROR = $arFields['RESULT_MESSAGE'];
                 } else {
                     $this->LAST_ERROR = GetMessage('CRM_CONTACT_UPDATE_CANCELED', array('#NAME#' => $arEvent['TO_NAME']));
                     $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR;
                 }
                 return false;
             }
         }
         $arAttr = array();
         $arAttr['OPENED'] = !empty($arFields['OPENED']) ? $arFields['OPENED'] : $arRow['OPENED'];
         $arEntityAttr = self::BuildEntityAttr($assignedByID, $arAttr);
         $sEntityPerm = $this->cPerms->GetPermType('CONTACT', 'WRITE', $arEntityAttr);
         $this->PrepareEntityAttrs($arEntityAttr, $sEntityPerm);
         //Prevent 'OPENED' field change by user restricted by BX_CRM_PERM_OPEN permission
         if ($sEntityPerm === BX_CRM_PERM_OPEN && isset($arFields['OPENED']) && $arFields['OPENED'] !== 'Y' && $assignedByID !== $iUserId) {
             $arFields['OPENED'] = 'Y';
         }
         if (isset($arFields['PHOTO']) && is_array($arFields['PHOTO']) && strlen(CFile::CheckImageFile($arFields['PHOTO'])) === 0) {
             $arFields['PHOTO']['MODULE_ID'] = 'crm';
             if ($arFields['PHOTO_del'] == 'Y' && !empty($arRow['PHOTO'])) {
                 CFile::Delete($arRow['PHOTO']);
             }
             CFile::SaveForDB($arFields, 'PHOTO', 'crm');
             if ($arFields['PHOTO_del'] == 'Y' && !isset($arFields['PHOTO'])) {
                 $arFields['PHOTO'] = '';
             }
         }
         if (isset($arFields['ASSIGNED_BY_ID']) && intval($arRow['ASSIGNED_BY_ID']) !== intval($arFields['ASSIGNED_BY_ID'])) {
             CcrmEvent::SetAssignedByElement($arFields['ASSIGNED_BY_ID'], 'CONTACT', $ID);
         }
         $sonetEventData = array();
         if ($bCompare) {
             $res = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'CONTACT', 'ELEMENT_ID' => $ID));
             $arRow['FM'] = array();
             while ($ar = $res->Fetch()) {
                 $arRow['FM'][$ar['TYPE_ID']][$ar['ID']] = array('VALUE' => $ar['VALUE'], 'VALUE_TYPE' => $ar['VALUE_TYPE']);
             }
             $arEvents = self::CompareFields($arRow, $arFields, $arOptions);
             foreach ($arEvents as $arEvent) {
                 $arEvent['ENTITY_TYPE'] = 'CONTACT';
                 $arEvent['ENTITY_ID'] = $ID;
                 $arEvent['EVENT_TYPE'] = 1;
                 if (!isset($arEvent['USER_ID'])) {
                     $arEvent['USER_ID'] = $iUserId;
                 }
                 $CCrmEvent = new CCrmEvent();
                 $eventID = $CCrmEvent->Add($arEvent, $this->bCheckPermission);
                 if (is_int($eventID) && $eventID > 0) {
                     $fieldID = isset($arEvent['ENTITY_FIELD']) ? $arEvent['ENTITY_FIELD'] : '';
                     if ($fieldID === '') {
                         continue;
                     }
                     switch ($fieldID) {
                         case 'ASSIGNED_BY_ID':
                             $sonetEventData[] = array('TYPE' => CCrmLiveFeedEvent::Responsible, 'FIELDS' => array('TITLE' => GetMessage('CRM_CONTACT_EVENT_UPDATE_ASSIGNED_BY'), 'MESSAGE' => '', 'PARAMS' => array('START_RESPONSIBLE_ID' => $arRow['ASSIGNED_BY_ID'], 'FINAL_RESPONSIBLE_ID' => $arFields['ASSIGNED_BY_ID'])));
                             break;
                         case 'COMPANY_ID':
                             $sonetEventData[] = array('CODE' => 'COMPANY', 'TYPE' => CCrmLiveFeedEvent::Owner, 'FIELDS' => array('TITLE' => GetMessage('CRM_CONTACT_EVENT_UPDATE_COMPANY'), 'MESSAGE' => '', 'PARAMS' => array('START_OWNER_COMPANY_ID' => $arRow['COMPANY_ID'], 'FINAL_OWNER_COMPANY_ID' => $arFields['COMPANY_ID'])));
                             break;
                     }
                 }
             }
         }
         $newName = isset($arFields['NAME']) ? $arFields['NAME'] : '';
         $oldName = isset($arRow['NAME']) ? $arRow['NAME'] : '';
         $newSecondName = isset($arFields['SECOND_NAME']) ? $arFields['SECOND_NAME'] : '';
         $oldSecondName = isset($arRow['SECOND_NAME']) ? $arRow['SECOND_NAME'] : '';
         $newLastName = isset($arFields['LAST_NAME']) ? $arFields['LAST_NAME'] : '';
         $oldLastName = isset($arRow['LAST_NAME']) ? $arRow['LAST_NAME'] : '';
         $newHonorific = isset($arFields['HONORIFIC']) ? $arFields['HONORIFIC'] : '';
         $oldHonorific = isset($arRow['HONORIFIC']) ? $arRow['HONORIFIC'] : '';
         if ($newName !== $oldName || $newSecondName !== $oldSecondName || $newLastName !== $oldLastName || $newHonorific !== $oldHonorific) {
             CCrmActivity::ResetEntityCommunicationSettings(CCrmOwnerType::Contact, $ID);
         }
         if (isset($arFields['BIRTHDAY_SORT'])) {
             unset($arFields['BIRTHDAY_SORT']);
         }
         if (isset($arFields['BIRTHDATE'])) {
             if ($arFields['BIRTHDATE'] !== '') {
                 $birthDate = $arFields['BIRTHDATE'];
                 $arFields['~BIRTHDATE'] = $DB->CharToDateFunction($birthDate, 'SHORT', false);
                 $arFields['BIRTHDAY_SORT'] = \Bitrix\Crm\BirthdayReminder::prepareSorting($birthDate);
                 unset($arFields['BIRTHDATE']);
             } else {
                 $arFields['BIRTHDAY_SORT'] = \Bitrix\Crm\BirthdayReminder::prepareSorting('');
             }
         }
         if (isset($arFields['NAME']) && isset($arFields['LAST_NAME'])) {
             $arFields['FULL_NAME'] = self::GetFullName($arFields);
         } else {
             $dbRes = $DB->Query("SELECT NAME, LAST_NAME FROM b_crm_contact WHERE ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
             $arRes = $dbRes->Fetch();
             if (isset($arFields['NAME'])) {
                 $arRes['NAME'] = $arFields['NAME'];
             }
             if (isset($arFields['LAST_NAME'])) {
                 $arRes['LAST_NAME'] = $arFields['LAST_NAME'];
             }
             $arFields['FULL_NAME'] = self::GetFullName($arRes);
         }
         if (isset($arFields['HAS_EMAIL'])) {
             unset($arFields['HAS_EMAIL']);
         }
         if (isset($arFields['HAS_PHONE'])) {
             unset($arFields['HAS_PHONE']);
         }
         unset($arFields['ID']);
         $sUpdate = $DB->PrepareUpdate('b_crm_contact', $arFields, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
         if (strlen($sUpdate) > 0) {
             $bResult = true;
             $DB->Query("UPDATE b_crm_contact SET {$sUpdate} WHERE ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
             if (isset($arFields['LAST_NAME']) || isset($arFields['NAME']) || isset($arFields['SECOND_NAME'])) {
                 $lastName = isset($arFields['LAST_NAME']) ? $arFields['LAST_NAME'] : (isset($arRow['LAST_NAME']) ? $arRow['LAST_NAME'] : '');
                 $name = isset($arFields['NAME']) ? $arFields['NAME'] : (isset($arRow['NAME']) ? $arRow['NAME'] : '');
                 $secondName = isset($arFields['SECOND_NAME']) ? $arFields['SECOND_NAME'] : (isset($arRow['SECOND_NAME']) ? $arRow['SECOND_NAME'] : '');
                 \Bitrix\Crm\Integrity\DuplicatePersonCriterion::register(CCrmOwnerType::Contact, $ID, $lastName, $name, $secondName);
             }
         }
         CCrmPerms::UpdateEntityAttr('CONTACT', $ID, $arEntityAttr);
         if (isset($arFields['ADDRESS']) || isset($arFields['ADDRESS_2']) || isset($arFields['ADDRESS_CITY']) || isset($arFields['ADDRESS_POSTAL_CODE']) || isset($arFields['ADDRESS_REGION']) || isset($arFields['ADDRESS_PROVINCE']) || isset($arFields['ADDRESS_COUNTRY'])) {
             \Bitrix\Crm\EntityAddress::register(CCrmOwnerType::Contact, $ID, \Bitrix\Crm\EntityAddress::Primary, array('ADDRESS_1' => isset($arFields['ADDRESS']) ? $arFields['ADDRESS'] : (isset($arRow['ADDRESS']) ? $arRow['ADDRESS'] : null), 'ADDRESS_2' => isset($arFields['ADDRESS_2']) ? $arFields['ADDRESS_2'] : (isset($arRow['ADDRESS_2']) ? $arRow['ADDRESS_2'] : null), 'CITY' => isset($arFields['ADDRESS_CITY']) ? $arFields['ADDRESS_CITY'] : (isset($arRow['ADDRESS_CITY']) ? $arRow['ADDRESS_CITY'] : null), 'POSTAL_CODE' => isset($arFields['ADDRESS_POSTAL_CODE']) ? $arFields['ADDRESS_POSTAL_CODE'] : (isset($arRow['ADDRESS_POSTAL_CODE']) ? $arRow['ADDRESS_POSTAL_CODE'] : null), 'REGION' => isset($arFields['ADDRESS_REGION']) ? $arFields['ADDRESS_REGION'] : (isset($arRow['ADDRESS_REGION']) ? $arRow['ADDRESS_REGION'] : null), 'PROVINCE' => isset($arFields['ADDRESS_PROVINCE']) ? $arFields['ADDRESS_PROVINCE'] : (isset($arRow['ADDRESS_PROVINCE']) ? $arRow['ADDRESS_PROVINCE'] : null), 'COUNTRY' => isset($arFields['ADDRESS_COUNTRY']) ? $arFields['ADDRESS_COUNTRY'] : (isset($arRow['ADDRESS_COUNTRY']) ? $arRow['ADDRESS_COUNTRY'] : null), 'COUNTRY_CODE' => isset($arFields['ADDRESS_COUNTRY_CODE']) ? $arFields['ADDRESS_COUNTRY_CODE'] : (isset($arRow['ADDRESS_COUNTRY_CODE']) ? $arRow['ADDRESS_COUNTRY_CODE'] : null)));
         }
         CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $GLOBALS['USER_FIELD_MANAGER'], array('IS_NEW' => false));
         $GLOBALS['USER_FIELD_MANAGER']->Update(self::$sUFEntityID, $ID, $arFields);
         if (defined("BX_COMP_MANAGED_CACHE")) {
             static $arNameFields = array("NAME", "LAST_NAME", "SECOND_NAME");
             $bClear = false;
             foreach ($arNameFields as $val) {
                 if (isset($arFields[$val])) {
                     $bClear = true;
                     break;
                 }
             }
             if ($bClear) {
                 $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Contact . "_" . $ID);
             }
         }
         if (isset($arFields['FM']) && is_array($arFields['FM'])) {
             $CCrmFieldMulti = new CCrmFieldMulti();
             $CCrmFieldMulti->SetFields(CCrmOwnerType::ContactName, $ID, $arFields['FM']);
             $multifields = \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::prepareEntityMultifieldsValues(CCrmOwnerType::Contact, $ID);
             $emails = \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::extractMultifieldsValues($multifields, 'EMAIL');
             \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::register(CCrmOwnerType::Contact, $ID, 'EMAIL', $emails);
             $phones = \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::extractMultifieldsValues($multifields, 'PHONE');
             \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion::register(CCrmOwnerType::Contact, $ID, 'PHONE', $phones);
             $hasEmail = empty($emails) ? 'N' : 'Y';
             $hasPhone = empty($phones) ? 'N' : 'Y';
             if ($hasEmail !== (isset($arRow['HAS_EMAIL']) ? $arRow['HAS_EMAIL'] : 'N') || $hasPhone !== (isset($arRow['HAS_PHONE']) ? $arRow['HAS_PHONE'] : 'N')) {
                 $DB->Query("UPDATE b_crm_contact SET HAS_EMAIL = '{$hasEmail}', HAS_PHONE = '{$hasPhone}' WHERE ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__);
                 $arFields['HAS_EMAIL'] = $hasEmail;
                 $arFields['HAS_PHONE'] = $hasPhone;
             }
         }
         \Bitrix\Crm\Integrity\DuplicateEntityRanking::registerEntityStatistics(CCrmOwnerType::Contact, $ID, array_merge($arRow, $arFields));
         if ($bUpdateSearch) {
             CCrmSearch::UpdateSearch(array('ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), 'CONTACT', true);
         }
         if (isset($GLOBALS["USER"]) && isset($arFields['COMPANY_ID']) && intval($arFields['COMPANY_ID']) > 0) {
             if (!class_exists('CUserOptions')) {
                 include_once $_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/classes/" . $GLOBALS['DBType'] . "/favorites.php";
             }
             CUserOptions::SetOption("crm", "crm_company_search", array('last_selected' => $arFields['COMPANY_ID']));
         }
         $arFields['ID'] = $ID;
         $newCompanyID = isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : 0;
         $oldCompanyID = isset($arRow['COMPANY_ID']) ? intval($arRow['COMPANY_ID']) : 0;
         $companyID = $newCompanyID > 0 ? $newCompanyID : $oldCompanyID;
         $registerSonetEvent = isset($arOptions['REGISTER_SONET_EVENT']) && $arOptions['REGISTER_SONET_EVENT'] === true;
         if ($bResult && isset($arFields['ASSIGNED_BY_ID'])) {
             CCrmSonetSubscription::ReplaceSubscriptionByEntity(CCrmOwnerType::Contact, $ID, CCrmSonetSubscriptionType::Responsibility, $arFields['ASSIGNED_BY_ID'], $arRow['ASSIGNED_BY_ID'], $registerSonetEvent);
         }
         if ($bResult && $bCompare && $registerSonetEvent && !empty($sonetEventData)) {
             $modifiedByID = intval($arFields['MODIFY_BY_ID']);
             foreach ($sonetEventData as &$sonetEvent) {
                 $sonetEventType = $sonetEvent['TYPE'];
                 $sonetEventCode = isset($sonetEvent['CODE']) ? $sonetEvent['CODE'] : '';
                 $sonetEventFields =& $sonetEvent['FIELDS'];
                 $sonetEventFields['ENTITY_TYPE_ID'] = CCrmOwnerType::Contact;
                 $sonetEventFields['ENTITY_ID'] = $ID;
                 $sonetEventFields['USER_ID'] = $modifiedByID;
                 //Register company relation
                 if ($sonetEventCode === 'COMPANY') {
                     //If company changed bind events to old and new companies
                     $sonetEventFields['PARENTS'] = array();
                     if ($oldCompanyID > 0) {
                         $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $oldCompanyID);
                     }
                     if ($newCompanyID > 0) {
                         $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $newCompanyID);
                     }
                 } elseif ($companyID > 0) {
                     $sonetEventFields['PARENT_ENTITY_TYPE_ID'] = CCrmOwnerType::Company;
                     $sonetEventFields['PARENT_ENTITY_ID'] = $companyID;
                 }
                 $logEventID = CCrmLiveFeed::CreateLogEvent($sonetEventFields, $sonetEventType);
                 if ($logEventID && $sonetEvent['TYPE'] == CCrmLiveFeedEvent::Responsible && CModule::IncludeModule("im")) {
                     $url = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Contact, $ID);
                     $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0 ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", ""));
                     if ($sonetEventFields['PARAMS']['FINAL_RESPONSIBLE_ID'] != $modifiedByID) {
                         $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $sonetEventFields['PARAMS']['FINAL_RESPONSIBLE_ID'], "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "contact_update", "NOTIFY_TAG" => "CRM|CONTACT_RESPONSIBLE|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_CONTACT_RESPONSIBLE_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['FULL_NAME']) . "</a>")), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_CONTACT_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['FULL_NAME']))) . " (" . $serverName . $url . ")");
                         CIMNotify::Add($arMessageFields);
                     }
                     if ($sonetEventFields['PARAMS']['START_RESPONSIBLE_ID'] != $modifiedByID) {
                         $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $sonetEventFields['PARAMS']['START_RESPONSIBLE_ID'], "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "contact_update", "NOTIFY_TAG" => "CRM|CONTACT_RESPONSIBLE|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_CONTACT_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['FULL_NAME']) . "</a>")), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_CONTACT_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['FULL_NAME']))) . " (" . $serverName . $url . ")");
                         CIMNotify::Add($arMessageFields);
                     }
                 }
                 unset($sonetEventFields);
             }
             unset($sonetEvent);
         }
         if ($bResult) {
             $afterEvents = GetModuleEvents('crm', 'OnAfterCrmContactUpdate');
             while ($arEvent = $afterEvents->Fetch()) {
                 ExecuteModuleEventEx($arEvent, array(&$arFields));
             }
         }
     }
     return $bResult;
 }
Esempio n. 12
0
    $responsibleUrl = isset($item['PATH_TO_RESPONSIBLE']) ? $item['PATH_TO_RESPONSIBLE'] : '';
    if ($responsibleUrl === '') {
        $responsibleUrl = CComponentEngine::MakePathFromTemplate($arResult['PATH_TO_USER_PROFILE'], array('user_id' => $responsibleID));
    }
    $editorItem = array('ID' => $item['~ID'], 'typeID' => $item['~TYPE_ID'], 'subject' => $item['~SUBJECT'], 'description' => isset($item['DESCRIPTION_RAW']) ? $item['DESCRIPTION_RAW'] : '', 'descriptionHtml' => isset($item['DESCRIPTION_HTML']) ? $item['DESCRIPTION_HTML'] : '', 'direction' => intval($item['~DIRECTION']), 'location' => $item['~LOCATION'], 'start' => isset($item['~START_TIME']) ? ConvertTimeStamp(MakeTimeStamp($item['~START_TIME']), 'FULL', SITE_ID) : '', 'end' => isset($item['~END_TIME']) ? ConvertTimeStamp(MakeTimeStamp($item['~END_TIME']), 'FULL', SITE_ID) : '', 'deadline' => isset($item['~DEADLINE']) ? ConvertTimeStamp(MakeTimeStamp($item['~DEADLINE']), 'FULL', SITE_ID) : '', 'completed' => $item['~COMPLETED'] == 'Y', 'notifyType' => intval($item['~NOTIFY_TYPE']), 'notifyValue' => intval($item['~NOTIFY_VALUE']), 'priority' => intval($item['~PRIORITY']), 'responsibleID' => $responsibleID, 'responsibleName' => isset($item['~RESPONSIBLE_FULL_NAME'][0]) ? $item['~RESPONSIBLE_FULL_NAME'] : GetMessage('CRM_UNDEFINED_VALUE'), 'responsibleUrl' => $responsibleUrl, 'storageTypeID' => intval($item['STORAGE_TYPE_ID']), 'files' => $item['FILES'], 'webdavelements' => $item['WEBDAV_ELEMENTS'], 'diskfiles' => $item['DISK_FILES'], 'associatedEntityID' => isset($item['~ASSOCIATED_ENTITY_ID']) ? intval($item['~ASSOCIATED_ENTITY_ID']) : 0);
    if (!$commLoaded) {
        $editorItem['communicationsLoaded'] = false;
    } else {
        $editorItem['communicationsLoaded'] = true;
        $editorItem['communications'] = $commData;
    }
    if (isset($item['OWNER_TYPE_ID']) && isset($item['OWNER_ID'])) {
        $editorItem['ownerType'] = CCrmOwnerType::ResolveName($item['OWNER_TYPE_ID']);
        $editorItem['ownerID'] = $item['OWNER_ID'];
        $editorItem['ownerTitle'] = CCrmOwnerType::GetCaption($item['OWNER_TYPE_ID'], $item['OWNER_ID']);
        $editorItem['ownerUrl'] = CCrmOwnerType::GetShowUrl($item['OWNER_TYPE_ID'], $item['OWNER_ID']);
    }
    $editorItems[] = $editorItem;
    // <-- Preparing activity editor item
}
unset($item);
if ($arResult['NEED_FOR_CONVERTING_OF_CALENDAR_EVENTS']) {
    ?>
<div class="crm-view-message"><?php 
    echo GetMessage('CRM_ACTION_CONVERTING_OF_CALENDAR_EVENTS', array('#URL_EXECUTE_CONVERTING#' => htmlspecialcharsbx($arResult['CAL_EVENT_CONV_EXEC_URL']), '#URL_SKIP_CONVERTING#' => htmlspecialcharsbx($arResult['CAL_EVENT_CONV_SKIP_URL'])));
    ?>
</div><?php 
}
if ($arResult['NEED_FOR_CONVERTING_OF_TASKS']) {
    ?>
<div class="crm-view-message"><?php 
Esempio n. 13
0
     break;
 case CTaskColumnList::COLUMN_PRIORITY:
     echo GetMessage('TASKS_LIST_ITEMS_PRIORITY_' . $task['PRIORITY']);
     break;
 case CTaskColumnList::COLUMN_UF_CRM:
     if (empty($task['UF_CRM_TASK'])) {
         break;
     }
     $collection = array();
     sort($task['UF_CRM_TASK']);
     foreach ($task['UF_CRM_TASK'] as $value) {
         $crmElement = explode('_', $value);
         $type = $crmElement[0];
         $typeId = CCrmOwnerType::ResolveID(CCrmOwnerTypeAbbr::ResolveName($type));
         $title = CCrmOwnerType::GetCaption($typeId, $crmElement[1]);
         $url = CCrmOwnerType::GetShowUrl($typeId, $crmElement[1]);
         if (!isset($collection[$type])) {
             $collection[$type] = array();
         }
         $collection[$type][] = '<a href="' . $url . '">' . $title . '</a>';
     }
     if ($collection) {
         echo '<div class="tasks-list-crm-div">';
         $prevType = null;
         foreach ($collection as $type => $items) {
             if ($type !== $prevType) {
                 if ($prevType !== null) {
                     echo ' &nbsp;&nbsp; ';
                 }
                 echo '<span class="tasks-list-crm-div-type">' . GetMessage('TASKS_LIST_CRM_TYPE_' . $type) . ':</span>';
             }
Esempio n. 14
0
$arParams['NAME_FORMAT'] = isset($arParams['NAME_FORMAT']) ? $arParams['NAME_FORMAT'] : '';
$arResult['NAME_FORMAT'] = $arParams['NAME_FORMAT'] !== '' ? $arParams['NAME_FORMAT'] : \Bitrix\Crm\Format\PersonNameFormatter::getFormat();
$utils = new CComponentUtil();
$arParams['DATE_FORMAT'] = isset($arParams['DATE_FORMAT']) ? $arParams['DATE_FORMAT'] : '';
$arResult['DATE_FORMAT'] = $arParams['DATE_FORMAT'] !== '' ? $arParams['DATE_FORMAT'] : $utils->GetDateFormatDefault(true);
$arParams['INTERVAL_IN_DAYS'] = isset($arParams['INTERVAL_IN_DAYS']) ? (int) $arParams['INTERVAL_IN_DAYS'] : 7;
$intervalInDays = $arParams['INTERVAL_IN_DAYS'] > 0 ? $arParams['INTERVAL_IN_DAYS'] : 7;
$arParams['CHECK_PERMISSIONS'] = isset($arParams['CHECK_PERMISSIONS']) ? strtoupper($arParams['CHECK_PERMISSIONS']) : 'Y';
$enablePermissionCheck = $arParams['CHECK_PERMISSIONS'] !== 'N';
$arParams['LIMIT'] = isset($arParams['LIMIT']) ? (int) $arParams['LIMIT'] : 5;
$limit = $arParams['LIMIT'] > 0 ? $arParams['LIMIT'] : 5;
$currentDate = ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'SHORT', SITE_ID);
$items = array();
if ($canReadLead) {
    $items = array_merge(BirthdayReminder::getNearestEntities(\CCrmOwnerType::Lead, $currentDate, '', $intervalInDays, $enablePermissionCheck, $limit), $items);
}
if ($canReadContact) {
    $items = array_merge(BirthdayReminder::getNearestEntities(\CCrmOwnerType::Contact, $currentDate, '', $intervalInDays, $enablePermissionCheck, $limit), $items);
}
sortByColumn($items, 'BIRTHDAY_SORT');
if (count($items) > $limit) {
    $items = array_slice($items, 0, $limit);
}
foreach ($items as &$item) {
    $item['SHOW_URL'] = \CCrmOwnerType::GetShowUrl($item['ENTITY_TYPE_ID'], $item['ID'], $enablePermissionCheck);
}
unset($item);
if (!empty($items)) {
    $arResult['ITEMS'] = $items;
    $this->IncludeComponentTemplate();
}
Esempio n. 15
0
    function __CrmActivityListRenderItems($items, $showMode, $showTop, &$editorCfg)
    {
        $editorItems = array();
        $count = count($items);
        $now = time() + CTimeZone::GetOffset();
        $toolbarID = '';
        if ($editorCfg['ENABLE_TOOLBAR']) {
            $toolbarID = $editorCfg['EDITOR_ID'] . '_toolbar';
            ?>
<ul id="<?php 
            echo htmlspecialcharsbx($toolbarID);
            ?>
" class="crm-view-actions">
			<?php 
            if ($editorCfg['ENABLE_TASK_ADD']) {
                ?>
			<li class="crm-activity-command-add-task">
				<i></i>
				<span><?php 
                echo htmlspecialcharsbx(GetMessage('CRM_ACTIVITY_LIST_ADD_TASK'));
                ?>
</span>
			</li>
			<?php 
            }
            ?>
			<?php 
            if ($editorCfg['ENABLE_CALENDAR_EVENT_ADD']) {
                ?>
			<li class="crm-activity-command-add-call">
				<i></i>
				<span><?php 
                echo htmlspecialcharsbx(GetMessage('CRM_ACTIVITY_LIST_ADD_CALL'));
                ?>
</span>
			</li>
			<li class="crm-activity-command-add-meeting">
				<i></i>
				<span><?php 
                echo htmlspecialcharsbx(GetMessage('CRM_ACTIVITY_LIST_ADD_MEETING'));
                ?>
</span>
			</li>
			<?php 
            }
            ?>
			<?php 
            if ($editorCfg['ENABLE_EMAIL_ADD']) {
                ?>
			<li class="crm-activity-command-add-email">
				<i></i>
				<span><?php 
                echo htmlspecialcharsbx(GetMessage('CRM_ACTIVITY_LIST_ADD_EMAIL'));
                ?>
</span>
			</li>
			<?php 
            }
            ?>
		</ul>
	<?php 
        }
        ?>
	<table class="crm-view-table crm-activity-table">
		<thead>
			<tr class="crm-activity-table-head" style="<?php 
        echo $count > 0 ? '' : 'display:none;';
        ?>
" >
				<td>&nbsp;</td>
				<td><?php 
        echo htmlspecialcharsbx(GetMessage('CRM_ACTIVITY_ROW_COL_TTL_TYPE'));
        ?>
</td>
				<td><?php 
        echo htmlspecialcharsbx(GetMessage('CRM_ACTIVITY_ROW_COL_TTL_SUBJECT'));
        ?>
</td>
				<td><?php 
        echo htmlspecialcharsbx(GetMessage('CRM_ACTIVITY_ROW_COL_TTL_DEAD_LINE'));
        ?>
</td>
				<td><?php 
        echo htmlspecialcharsbx(GetMessage('CRM_ACTIVITY_ROW_COL_TTL_RESPONSIBLE'));
        ?>
</td>
			</tr>
		</thead>
		<tbody>
			<?php 
        $processed = 0;
        for ($i = 0; $i < $count; $i++) {
            $item =& $items[$i];
            if ($showMode == 'NOT_COMPLETED' && $item['COMPLETED'] == 'Y' || $showMode == 'COMPLETED' && $item['COMPLETED'] == 'N') {
                continue;
            }
            $processed++;
            $commData = array();
            if (isset($item['COMMUNICATIONS'])) {
                foreach ($item['COMMUNICATIONS'] as &$arComm) {
                    CCrmActivity::PrepareCommunicationInfo($arComm);
                    $commData[] = array('id' => $arComm['ID'], 'type' => $arComm['TYPE'], 'value' => $arComm['VALUE'], 'entityId' => $arComm['ENTITY_ID'], 'entityType' => CCrmOwnerType::ResolveName($arComm['ENTITY_TYPE_ID']), 'entityTitle' => $arComm['TITLE']);
                }
                unset($arComm);
            }
            $rowID = $editorCfg['PREFIX'];
            if ($rowID !== '') {
                $rowID .= '_';
            }
            $rowID .= '_row_' . strval($processed);
            $editorItem = array('ID' => $item['~ID'], 'rowID' => $rowID, 'typeID' => $item['~TYPE_ID'], 'subject' => strval($item['~SUBJECT']), 'description' => strval($item['~DESCRIPTION']), 'direction' => intval($item['~DIRECTION']), 'location' => strval($item['~LOCATION']), 'start' => isset($item['~START_TIME']) ? ConvertTimeStamp(MakeTimeStamp($item['~START_TIME']), 'FULL', SITE_ID) : '', 'end' => isset($item['~END_TIME']) ? ConvertTimeStamp(MakeTimeStamp($item['~END_TIME']), 'FULL', SITE_ID) : '', 'deadline' => isset($item['~DEADLINE']) ? ConvertTimeStamp(MakeTimeStamp($item['~DEADLINE']), 'FULL', SITE_ID) : '', 'completed' => strval($item['~COMPLETED']) == 'Y', 'notifyType' => intval($item['~NOTIFY_TYPE']), 'notifyValue' => intval($item['~NOTIFY_VALUE']), 'priority' => intval($item['~PRIORITY']), 'responsibleID' => isset($item['~RESPONSIBLE_ID'][0]) ? intval($item['~RESPONSIBLE_ID']) : 0, 'responsibleName' => isset($item['~RESPONSIBLE_FULL_NAME'][0]) ? $item['~RESPONSIBLE_FULL_NAME'] : GetMessage('CRM_UNDEFINED_VALUE'), 'storageTypeID' => intval($item['STORAGE_TYPE_ID']), 'files' => $item['FILES'], 'webdavelements' => $item['WEBDAV_ELEMENTS'], 'associatedEntityID' => isset($item['~ASSOCIATED_ENTITY_ID']) ? intval($item['~ASSOCIATED_ENTITY_ID']) : 0, 'communications' => $commData);
            if (isset($item['OWNER_TYPE_ID']) && isset($item['OWNER_ID'])) {
                $editorItem['ownerType'] = CCrmOwnerType::ResolveName($item['OWNER_TYPE_ID']);
                $editorItem['ownerID'] = $item['OWNER_ID'];
                $editorItem['ownerTitle'] = CCrmOwnerType::GetCaption($item['OWNER_TYPE_ID'], $item['OWNER_ID']);
                $editorItem['ownerUrl'] = CCrmOwnerType::GetShowUrl($item['OWNER_TYPE_ID'], $item['OWNER_ID']);
            }
            $editorItems[] = $editorItem;
            $rowClass = 'crm-activity-row';
            if ($processed % 2 === 0) {
                $rowClass .= ' crm-activity-row-even';
            }
            if (intval($item['~PRIORITY']) === CCrmActivityPriority::High) {
                $rowClass .= ' crm-activity-row-important';
            }
            ?>
			<tr id="<?php 
            echo htmlspecialcharsbx($rowID);
            ?>
" class="<?php 
            echo htmlspecialcharsbx($rowClass);
            ?>
" style="<?php 
            echo $showTop > 0 && $processed > $showTop ? 'display:none;' : '';
            ?>
">
				<td><!--Delete-->
					<?php 
            if (!$arResult['READ_ONLY']) {
                ?>
						<span class="crm-view-table-column-delete"></span>
					<?php 
            }
            ?>
				</td>
				<td> <!--Type-->
					<a class="crm-activity-type" href="#"><?php 
            echo $item['TYPE_NAME'];
            ?>
</a>
				</td>
				<td> <!--Subject-->
					<a class="crm-activity-subject" href="#"><?php 
            echo $item['SUBJECT'];
            ?>
</a>
				</td>
				<td> <!--End time-->
					<?php 
            $deadline = isset($item['~DEADLINE']) ? MakeTimeStamp($item['~DEADLINE']) : null;
            ?>
					<span <?php 
            echo $item['~COMPLETED'] !== 'Y' && $deadline !== null && $deadline < $now ? 'style="color:#ff0000;"' : '';
            ?>
>
						<?php 
            echo $deadline !== null ? htmlspecialcharsbx(CCrmComponentHelper::TrimDateTimeString(FormatDate('FULL', $deadline))) : '';
            ?>
					</span>
				</td>
				<td> <!--Responsible-->
			<span>
				<?php 
            echo isset($item['RESPONSIBLE_FULL_NAME'][0]) ? $item['RESPONSIBLE_FULL_NAME'] : GetMessage('CRM_UNDEFINED_VALUE');
            ?>
			</span>
				</td>
			</tr>
				<?php 
        }
        unset($item);
        ?>
		</tbody>
	</table>
	<?php 
        if ($showTop > 0 && $processed > $showTop) {
            ?>
	<div class="crm-activity-show-all-wrapper">
		<a href="#" class="crm-activity-command-show-all" ><?php 
            echo str_replace('#COUNT#', strval($processed), GetMessage('CRM_ACTIVITY_SHOW_ALL'));
            ?>
</a>
	</div>
	<?php 
        }
        $GLOBALS['APPLICATION']->IncludeComponent('bitrix:crm.activity.editor', '', array('CONTAINER_ID' => $editorCfg['CONTAINER_ID'], 'EDITOR_ID' => $editorCfg['EDITOR_ID'], 'EDITOR_TYPE' => $editorCfg['EDITOR_TYPE'], 'PREFIX' => $editorCfg['PREFIX'], 'OWNER_TYPE' => $editorCfg['OWNER_TYPE'], 'OWNER_ID' => $editorCfg['OWNER_ID'], 'ENABLE_TASK_ADD' => $editorCfg['ENABLE_TASK_ADD'], 'ENABLE_CALENDAR_EVENT_ADD' => $editorCfg['ENABLE_CALENDAR_EVENT_ADD'], 'ENABLE_EMAIL_ADD' => $editorCfg['ENABLE_EMAIL_ADD'], 'READ_ONLY' => $editorCfg['READ_ONLY'], 'ENABLE_UI' => $editorCfg['ENABLE_UI'], 'ENABLE_TOOLBAR' => $editorCfg['ENABLE_TOOLBAR'], 'TOOLBAR_ID' => $toolbarID, 'BUTTON_ID' => $editorCfg['BUTTON_ID'], 'EDITOR_ITEMS' => $editorItems), null, array('HIDE_ICONS' => 'Y'));
    }
Esempio n. 16
0
 public static function Notify(&$arFields, $schemeTypeID, $tag = '')
 {
     if (!is_array($arFields)) {
         return false;
     }
     $responsibleID = $arFields['RESPONSIBLE_ID'] ? intval($arFields['RESPONSIBLE_ID']) : 0;
     if ($responsibleID <= 0) {
         return false;
     }
     if ($schemeTypeID === CCrmNotifierSchemeType::IncomingEmail) {
         $showUrl = CCrmOwnerType::GetShowUrl($arFields['OWNER_TYPE_ID'] ? intval($arFields['OWNER_TYPE_ID']) : 0, $arFields['OWNER_ID'] ? intval($arFields['OWNER_ID']) : 0);
         if ($showUrl === '') {
             return false;
         }
         $subject = isset($arFields['SUBJECT']) ? $arFields['SUBJECT'] : '';
         $addresserHtml = '';
         $communications = isset($arFields['COMMUNICATIONS']) ? $arFields['COMMUNICATIONS'] : array();
         if (!empty($communications)) {
             $comm = $communications[0];
             $caption = '';
             if (isset($comm['ENTITY_TYPE_ID']) && isset($comm['ENTITY_ID'])) {
                 $caption = CCrmOwnerType::GetCaption($comm['ENTITY_TYPE_ID'], $comm['ENTITY_ID']);
             }
             if ($caption === '') {
                 $caption = $comm['VALUE'];
             }
             $addresserShowUrl = CCrmOwnerType::GetShowUrl($comm['ENTITY_TYPE_ID'], $comm['ENTITY_ID']);
             $addresserHtml = $addresserShowUrl !== '' ? '<a target="_blank" href="' . htmlspecialcharsbx($addresserShowUrl) . '">' . htmlspecialcharsbx($caption) . '</a>' : htmlspecialcharsbx($caption);
         }
         if ($addresserHtml === '') {
             $messageTemplate = GetMessage('CRM_ACTIVITY_NOTIFY_MESSAGE_INCOMING_EMAIL');
             return CCrmNotifier::Notify($responsibleID, str_replace('#VIEW_URL#', htmlspecialcharsbx($showUrl), $messageTemplate), str_replace('#VIEW_URL#', htmlspecialcharsbx(CCrmUrlUtil::ToAbsoluteUrl($showUrl)), $messageTemplate), $schemeTypeID, $tag);
         }
         $messageTemplate = GetMessage('CRM_ACTIVITY_NOTIFY_MESSAGE_INCOMING_EMAIL_EXT');
         return CCrmNotifier::Notify($responsibleID, str_replace(array('#VIEW_URL#', '#SUBJECT#', '#ADDRESSER#'), array(htmlspecialcharsbx($showUrl), htmlspecialcharsbx($subject), $addresserHtml), $messageTemplate), str_replace(array('#VIEW_URL#', '#SUBJECT#', '#ADDRESSER#'), array(htmlspecialcharsbx(CCrmUrlUtil::ToAbsoluteUrl($showUrl)), htmlspecialcharsbx($subject), $addresserHtml), $messageTemplate), $schemeTypeID, $tag);
     }
     return false;
 }
Esempio n. 17
0
    }
    $entityID = isset($_POST['ENITY_ID']) ? intval($_POST['ENITY_ID']) : 0;
    if ($entityID <= 0) {
        __CrmLeadShowEndJsonResonse(array('ERROR' => 'ENITY ID IS INVALID OR NOT DEFINED!'));
    }
    $dbRes = CCrmLead::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'Y'), false, false, array('TITLE', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'COMPANY_TITLE'));
    $arRes = $dbRes ? $dbRes->Fetch() : null;
    if (!$arRes) {
        __CrmLeadShowEndJsonResonse(array('ERROR' => 'ENITY IS NOT FOUND!'));
    } else {
        if (isset($arRes['NAME']) || isset($arRes['LAST_NAME'])) {
            $title = CUser::FormatName(\Bitrix\Crm\Format\PersonNameFormatter::getFormat(), array('LOGIN' => '', 'NAME' => isset($arRes['NAME']) ? $arRes['NAME'] : '', 'SECOND_NAME' => isset($arRes['SECOND_NAME']) ? $arRes['SECOND_NAME'] : '', 'LAST_NAME' => isset($arRes['LAST_NAME']) ? $arRes['LAST_NAME'] : ''), false, false);
        } else {
            $title = isset($arRes['TITLE']) ? $arRes['TITLE'] : '';
        }
        __CrmLeadShowEndJsonResonse(array('DATA' => array('TITLE' => $title, 'LEGEND' => isset($arRes['COMPANY_TITLE']) ? $arRes['COMPANY_TITLE'] : '', 'IMAGE_URL' => '', 'SHOW_URL' => CCrmOwnerType::GetShowUrl(CCrmOwnerType::Lead, $entityID, false))));
    }
}
$type = isset($_POST['OWNER_TYPE']) ? strtoupper($_POST['OWNER_TYPE']) : '';
if ($type !== 'L') {
    __CrmLeadShowEndJsonResonse(array('ERROR' => 'OWNER_TYPE IS NOT SUPPORTED!'));
}
$CCrmLead = new CCrmLead();
if ($CCrmLead->cPerms->HavePerm('LEAD', BX_CRM_PERM_NONE, 'WRITE')) {
    __CrmLeadShowEndJsonResonse(array('ERROR' => 'PERMISSION DENIED!'));
}
if ($mode === 'UPDATE') {
    $ID = isset($_POST['OWNER_ID']) ? $_POST['OWNER_ID'] : 0;
    if ($ID <= 0) {
        __CrmLeadShowEndJsonResonse(array('ERROR' => 'ID IS INVALID OR NOT DEFINED!'));
    }