GetCurPage() . '?mid=' . htmlspecialchars($mid) . '&lang=' . LANGUAGE_ID; $CRM_API_HOST_OPTION = 'api_host'; $CRM_API_KEY_OPTION = 'api_key'; $CRM_ORDER_TYPES_ARR = 'order_types_arr'; $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr'; $CRM_DELIVERY_SERVICES_ARR = 'deliv_services_arr'; $CRM_PAYMENT_TYPES = 'pay_types_arr'; $CRM_PAYMENT_STATUSES = 'pay_statuses_arr'; $CRM_PAYMENT = 'payment_arr'; //order payment Y/N $CRM_ORDER_LAST_ID = 'order_last_id'; $CRM_ORDER_SITES = 'sites_ids'; $CRM_ORDER_DISCHARGE = 'order_discharge'; $CRM_ORDER_PROPS = 'order_props'; $CRM_LEGAL_DETAILS = 'legal_details'; $CRM_CUSTOM_FIELDS = 'custom_fields'; $CRM_CONTRAGENT_TYPE = 'contragent_type'; $CRM_SITES_LIST= 'sites_list'; $CRM_ORDER_NUMBERS = 'order_numbers'; $CRM_CANSEL_ORDER = 'cansel_order'; if(!CModule::IncludeModule('intaro.retailcrm') || !CModule::IncludeModule('sale')) return; $_GET['errc'] = htmlspecialchars(trim($_GET['errc'])); $_GET['ok'] = htmlspecialchars(trim($_GET['ok'])); if($_GET['errc']) echo CAdminMessage::ShowMessage(GetMessage($_GET['errc'])); if($_GET['ok'] && $_GET['ok'] == 'Y') echo CAdminMessage::ShowNote(GetMessage('ICRM_OPTIONS_OK')); $arResult = array(); if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.retailcrm/classes/general/config/options.xml')) { $options = simplexml_load_file($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.retailcrm/classes/general/config/options.xml'); foreach($options->contragents->contragent as $contragent) { $type["NAME"] = $APPLICATION->ConvertCharset((string)$contragent, 'utf-8', SITE_CHARSET); $type["ID"] = (string)$contragent["id"]; $arResult['contragentType'][] = $type; unset ($type); } foreach($options->fields->field as $field) { $type["NAME"] = $APPLICATION->ConvertCharset((string)$field, 'utf-8', SITE_CHARSET); $type["ID"] = (string)$field["id"]; if ($field["group"] == 'custom') { $arResult['customFields'][] = $type; } elseif(!$field["group"]){ $arResult['orderProps'][] = $type; } else{ $groups = explode(",", (string)$field["group"]); foreach ($groups as $group) { $type["GROUP"][] = trim($group); } $arResult['legalDetails'][] = $type; } unset($type); } } $arResult['arSites'] = RCrmActions::SitesList(); //ajax update deliveryServices if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) { $api_host = COption::GetOptionString($mid, $CRM_API_HOST_OPTION, 0); $api_key = COption::GetOptionString($mid, $CRM_API_KEY_OPTION, 0); $api = new RetailCrm\ApiClient($api_host, $api_key); try { $api->paymentStatusesList(); } catch (\RetailCrm\Exception\CurlException $e) { RCrmActions::eventLog( 'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::paymentStatusesList::CurlException', $e->getCode() . ': ' . $e->getMessage() ); $APPLICATION->RestartBuffer(); header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); die(json_encode(array('success' => false, 'errMsg' => $e->getCode()))); } $optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0)); $arDeliveryServiceAll = \Bitrix\Sale\Delivery\Services\Manager::getActiveList(); foreach($optionsDelivTypes as $key => $deliveryType){ foreach($arDeliveryServiceAll as $deliveryService){ if($deliveryService['PARENT_ID'] != 0 && $deliveryService['PARENT_ID'] == $key){ $srv = explode(':', $deliveryService['CODE']); if(count($srv) == 2){ try { $api->deliveryServicesEdit(RCrmActions::clearArr(array( 'code' => $srv[1], 'name' => RCrmActions::toJSON($deliveryService['NAME']), 'deliveryType' => $deliveryType ))); } catch (\RetailCrm\Exception\CurlException $e) { RCrmActions::eventLog( 'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::deliveryServiceEdit::CurlException', $e->getCode() . ': ' . $e->getMessage() ); } } } } } $APPLICATION->RestartBuffer(); header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); die(json_encode(array('success' => true))); } //upload orders after install module if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') && isset($_POST['ajax']) && $_POST['ajax'] == 2){ $step = $_POST['step']; $orders = $_POST['orders']; $countStep = 50; // 50 orders on step if($orders){ $ordersArr = explode(',', $orders); $orders = array(); foreach($ordersArr as $_ordersArr){ $ordersList = explode('-', trim($_ordersArr)); if(count($ordersList) > 1){ for($i = (int)trim($ordersList[0]); $i <= (int)trim($ordersList[count($ordersList) - 1]); $i++){ $orders[] = $i; } } else{ $orders[] = (int)$ordersList[0]; } } $splitedOrders = array_chunk($orders, $countStep); $stepOrders = $splitedOrders[$step]; RetailCrmOrder::uploadOrders($countStep, false, $stepOrders); $percent = round((($step * $countStep + count($stepOrders)) * 100 / count($orders)), 1); $step++; if(!$splitedOrders[$step]){ $step='end'; } $res = array("step" => $step, "percent" => $percent, 'stepOrders' => $stepOrders); } else{ $orders = array(); for($i = 1; $i <= $countStep; $i++){ $orders[] = $i + $step * $countStep; } RetailCrmOrder::uploadOrders($countStep, false, $orders); $step++; $countLeft = (int) CSaleOrder::GetList(array("ID" => "ASC"), array('>ID' => $step * $countStep), array()); $countAll = (int) CSaleOrder::GetList(array("ID" => "ASC"), array(), array()); $percent = round(100 - ($countLeft * 100 / $countAll), 1); if($countLeft == 0){ $step = 'end'; } $res = array("step" => $step, "percent" => $percent, 'stepOrders' => $orders); } $APPLICATION->RestartBuffer(); header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); die(json_encode($res)); } //update connection settings if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $api_host = htmlspecialchars(trim($_POST['api_host'])); $api_key = htmlspecialchars(trim($_POST['api_key'])); //bitrix site list $siteListArr = array(); foreach ($arResult['arSites'] as $arSites) { $siteListArr[$arSites['LID']] = htmlspecialchars(trim($_POST['sites-id-' . $arSites['LID']])); } if($api_host && $api_key) { $api = new RetailCrm\ApiClient($api_host, $api_key); try { $api->paymentStatusesList(); } catch (\RetailCrm\Exception\CurlException $e) { RCrmActions::eventLog( 'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::paymentStatusesList::CurlException', $e->getCode() . ': ' . $e->getMessage() ); $uri .= '&errc=ERR_' . $e->getCode(); LocalRedirect($uri); } COption::SetOptionString($mid, 'api_host', $api_host); COption::SetOptionString($mid, 'api_key', $api_key); } //form order types ids arr $orderTypesList = RCrmActions::OrderTypesList($arResult['arSites']); $orderTypesArr = array(); foreach($orderTypesList as $orderType){ $orderTypesArr[$orderType['ID']] = htmlspecialchars(trim($_POST['order-type-' . $orderType['ID']])); } //form delivery types ids arr $arResult['bitrixDeliveryTypesList'] = RCrmActions::DeliveryList(); $deliveryTypesArr = array(); foreach($arResult['bitrixDeliveryTypesList'] as $delivery){ $deliveryTypesArr[$delivery['ID']] = htmlspecialchars(trim($_POST['delivery-type-' . $delivery['ID']])); } //form payment types ids arr $arResult['bitrixPaymentTypesList'] = RCrmActions::PaymentList(); $paymentTypesArr = array(); foreach($arResult['bitrixPaymentTypesList'] as $payment){ $paymentTypesArr[$payment['ID']] = htmlspecialchars(trim($_POST['payment-type-' . $payment['ID']])); } //form payment statuses ids arr $arResult['bitrixStatusesList'] = RCrmActions::StatusesList(); $paymentStatusesArr = array(); $canselOrderArr = array(); //$paymentStatusesArr['YY'] = htmlspecialchars(trim($_POST['payment-status-YY'])); foreach($arResult['bitrixStatusesList'] as $status){ $paymentStatusesArr[$status['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $status['ID']])); if(trim($_POST['order-cansel-' . $status['ID']]) == 'Y'){ $canselOrderArr[] = $status['ID']; } } //form payment ids arr $paymentArr = array(); $paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y'])); $paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N'])); $previousDischarge = COption::GetOptionString($mid, $CRM_ORDER_DISCHARGE, 0); //order discharge mode // 0 - agent // 1 - event $orderDischarge = 0; $orderDischarge = (int) htmlspecialchars(trim($_POST['order-discharge'])); ///////////тут дописать\\\\\\\\\\\\\\\ if (($orderDischarge != $previousDischarge) && ($orderDischarge == 0)) { // remove depenedencies UnRegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail"); UnRegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder"); UnRegisterModuleDependences("sale", "OnBeforeOrderAdd", $mid, "ICrmOrderEvent", "onBeforeOrderAdd"); } else if (($orderDischarge != $previousDischarge) && ($orderDischarge == 1)) { // event dependencies RegisterModuleDependences("sale", "OnOrderNewSendEmail", $mid, "ICrmOrderEvent", "onSendOrderMail"); RegisterModuleDependences("sale", "OnOrderUpdate", $mid, "ICrmOrderEvent", "onUpdateOrder"); RegisterModuleDependences("sale", "OnBeforeOrderAdd", $mid, "ICrmOrderEvent", "onBeforeOrderAdd"); } $orderPropsArr = array(); foreach ($orderTypesList as $orderType) { $propsCount = 0; $_orderPropsArr = array(); foreach ($arResult['orderProps'] as $orderProp) { if ((!(int) htmlspecialchars(trim($_POST['address-detail-' . $orderType['ID']]))) && $propsCount > 4){ break; } $_orderPropsArr[$orderProp['ID']] = htmlspecialchars(trim($_POST['order-prop-' . $orderProp['ID'] . '-' . $orderType['ID']])); $propsCount++; } $orderPropsArr[$orderType['ID']] = $_orderPropsArr; } //legal details props $legalDetailsArr = array(); foreach ($orderTypesList as $orderType) { $_legalDetailsArr = array(); foreach ($arResult['legalDetails'] as $legalDetails) { $_legalDetailsArr[$legalDetails['ID']] = htmlspecialchars(trim($_POST['legal-detail-' . $legalDetails['ID'] . '-' . $orderType['ID']])); } $legalDetailsArr[$orderType['ID']] = $_legalDetailsArr; } $customFieldsArr = array(); foreach ($orderTypesList as $orderType) { $_customFieldsArr = array(); foreach ($arResult['customFields'] as $custom) { $_customFieldsArr[$custom['ID']] = htmlspecialchars(trim($_POST['custom-fields-' . $custom['ID'] . '-' . $orderType['ID']])); } $customFieldsArr[$orderType['ID']] = $_customFieldsArr; } //contragents type list $contragentTypeArr = array(); foreach ($orderTypesList as $orderType) { $contragentTypeArr[$orderType['ID']] = htmlspecialchars(trim($_POST['contragent-type-' . $orderType['ID']])); } //order numbers $orderNumbers = htmlspecialchars(trim($_POST['order-numbers'])) ? htmlspecialchars(trim($_POST['order-numbers'])) : 'N'; COption::SetOptionString($mid, $CRM_SITES_LIST, serialize(RCrmActions::clearArr($siteListArr))); COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize(RCrmActions::clearArr($orderTypesArr))); COption::SetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, serialize(RCrmActions::clearArr($deliveryTypesArr))); COption::SetOptionString($mid, $CRM_PAYMENT_TYPES, serialize(RCrmActions::clearArr($paymentTypesArr))); COption::SetOptionString($mid, $CRM_PAYMENT_STATUSES, serialize(RCrmActions::clearArr($paymentStatusesArr))); COption::SetOptionString($mid, $CRM_PAYMENT, serialize(RCrmActions::clearArr($paymentArr))); COption::SetOptionString($mid, $CRM_ORDER_DISCHARGE, $orderDischarge); COption::SetOptionString($mid, $CRM_ORDER_PROPS, serialize(RCrmActions::clearArr($orderPropsArr))); COption::SetOptionString($mid, $CRM_CONTRAGENT_TYPE, serialize(RCrmActions::clearArr($contragentTypeArr))); COption::SetOptionString($mid, $CRM_LEGAL_DETAILS, serialize(RCrmActions::clearArr($legalDetailsArr))); COption::SetOptionString($mid, $CRM_CUSTOM_FIELDS, serialize(RCrmActions::clearArr($customFieldsArr))); COption::SetOptionString($mid, $CRM_ORDER_NUMBERS, $orderNumbers); COption::SetOptionString($mid, $CRM_CANSEL_ORDER, serialize(RCrmActions::clearArr($canselOrderArr))); $uri .= '&ok=Y'; LocalRedirect($uri); } else { $api_host = COption::GetOptionString($mid, $CRM_API_HOST_OPTION, 0); $api_key = COption::GetOptionString($mid, $CRM_API_KEY_OPTION, 0); $api = new RetailCrm\ApiClient($api_host, $api_key); //prepare crm lists try { $arResult['orderTypesList'] = $api->orderTypesList()->orderTypes; $arResult['deliveryTypesList'] = $api->deliveryTypesList()->deliveryTypes; $arResult['deliveryServicesList'] = $api->deliveryServicesList()->deliveryServices; $arResult['paymentTypesList'] = $api->paymentTypesList()->paymentTypes; $arResult['paymentStatusesList'] = $api->paymentStatusesList()->paymentStatuses; // --statuses $arResult['paymentList'] = $api->statusesList()->statuses; $arResult['paymentGroupList'] = $api->statusGroupsList()->statusGroups; // -- statuses groups $arResult['sitesList'] = $APPLICATION->ConvertCharsetArray($api->sitesList()->sites, 'utf-8', SITE_CHARSET); } catch (\RetailCrm\Exception\CurlException $e) { RCrmActions::eventLog( 'intaro.retailcrm/options.php', 'RetailCrm\ApiClient::*List::CurlException', $e->getCode() . ': ' . $e->getMessage() ); echo CAdminMessage::ShowMessage(GetMessage('ERR_' . $e->getCode())); } catch (InvalidArgumentException $e) { $badKey = true; echo CAdminMessage::ShowMessage(GetMessage('ERR_403')); } //bitrix orderTypesList -- personTypes $arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']); //bitrix deliveryTypesList $arResult['bitrixDeliveryTypesList'] = RCrmActions::DeliveryList(); //bitrix paymentTypesList $arResult['bitrixPaymentTypesList'] = RCrmActions::PaymentList(); //bitrix statusesList $arResult['bitrixPaymentStatusesList'] = RCrmActions::StatusesList(); /*$arResult['bitrixPaymentStatusesList'][] = array( 'ID' => 'YY', 'NAME' => GetMessage('CANCELED') );*/ //bitrix pyament Y/N $arResult['bitrixPaymentList'][0]['NAME'] = GetMessage('PAYMENT_Y'); $arResult['bitrixPaymentList'][0]['ID'] = 'Y'; $arResult['bitrixPaymentList'][1]['NAME'] = GetMessage('PAYMENT_N'); $arResult['bitrixPaymentList'][1]['ID'] = 'N'; //bitrix orderPropsList $arResult['arProp'] = RCrmActions::OrderPropsList(); //saved cat params $optionsOrderTypes = unserialize(COption::GetOptionString($mid, $CRM_ORDER_TYPES_ARR, 0)); $optionsDelivTypes = unserialize(COption::GetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, 0)); $optionsPayTypes = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_TYPES, 0)); $optionsPayStatuses = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT_STATUSES, 0)); // --statuses $optionsPayment = unserialize(COption::GetOptionString($mid, $CRM_PAYMENT, 0)); $optionsSitesList = unserialize(COption::GetOptionString($mid, $CRM_SITES_LIST, 0)); $optionsDischarge = COption::GetOptionString($mid, $CRM_ORDER_DISCHARGE, 0); $optionsOrderProps = unserialize(COption::GetOptionString($mid, $CRM_ORDER_PROPS, 0)); $optionsContragentType = unserialize(COption::GetOptionString($mid, $CRM_CONTRAGENT_TYPE, 0)); $optionsLegalDetails = unserialize(COption::GetOptionString($mid, $CRM_LEGAL_DETAILS, 0)); $optionsCustomFields = unserialize(COption::GetOptionString($mid, $CRM_CUSTOM_FIELDS, 0)); $optionsOrderNumbers = COption::GetOptionString($mid, $CRM_ORDER_NUMBERS, 0); $canselOrderArr = unserialize(COption::GetOptionString($mid, $CRM_CANSEL_ORDER, 0)); //$isCustomOrderType = function_exists('intarocrm_set_order_type') || function_exists('intarocrm_get_order_type'); $aTabs = array( array( "DIV" => "edit1", "TAB" => GetMessage('ICRM_OPTIONS_GENERAL_TAB'), "ICON" => "", "TITLE" => GetMessage('ICRM_OPTIONS_GENERAL_CAPTION') ), array( "DIV" => "edit2", "TAB" => GetMessage('ICRM_OPTIONS_CATALOG_TAB'), "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_CATALOG_CAPTION') ), array( "DIV" => "edit3", "TAB" => GetMessage('ICRM_OPTIONS_ORDER_PROPS_TAB'), "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_ORDER_PROPS_CAPTION') ), array( "DIV" => "edit4", "TAB" => GetMessage('OTHER_OPTIONS'), "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_ORDER_DISCHARGE_CAPTION') ) ); $tabControl = new CAdminTabControl("tabControl", $aTabs); $tabControl->Begin(); ?> AddHeadString(''); ?>