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'; if(!CModule::IncludeModule('intaro.intarocrm') || !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.intarocrm/classes/general/config/options.xml')) { $options = simplexml_load_file($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.intarocrm/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); } } //else error $arResult['arSites'] = array(); $rsSites = CSite::GetList($by, $sort, array('ACTIVE' => 'Y')); while ($ar = $rsSites->Fetch()){ $arResult['arSites'][] = $ar; } //ajax update deliveryServices if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) { $result = array(); $api_host = COption::GetOptionString($mid, $CRM_API_HOST_OPTION, 0); $api_key = COption::GetOptionString($mid, $CRM_API_KEY_OPTION, 0); $api = new RetailCrm\RestApi($api_host, $api_key); try { $api->paymentStatusesList(); } catch (\RetailCrm\Exception\CurlException $e) { ICrmOrderActions::eventLog( 'intaro.crm/options.php', 'RetailCrm\RestApi::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)); // bitrix deliveryServicesList $dbDeliveryServicesList = CSaleDeliveryHandler::GetList( array( 'SORT' => 'ASC', 'NAME' => 'ASC' ), array( 'ACTIVE' => 'Y', 'SITE_ID' => $arResult['arSites'][0]['LID'] ) ); if ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()) { do { if(!$optionsDelivTypes[$arDeliveryServicesList['SID']]) { ICrmOrderActions::eventLog('options.php', 'No delivery type relations established', $arDeliveryServicesList['SID'] . ':' . $id); continue; } foreach($arDeliveryServicesList['PROFILES'] as $id => $profile) { // send to crm try { $api->deliveryServiceEdit(ICrmOrderActions::clearArr(array( 'code' => $arDeliveryServicesList['SID'] . '-' . $id, 'name' => ICrmOrderActions::toJSON($profile['TITLE']), 'deliveryType' => $arDeliveryServicesList['SID'] ))); } catch (\RetailCrm\Exception\CurlException $e) { ICrmOrderActions::eventLog( 'intaro.crm/options.php', 'RetailCrm\RestApi::deliveryServiceEdit::CurlException', $e->getCode() . ': ' . $e->getMessage() ); } } } while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()); } $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]; ICrmOrderActions::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; } ICrmOrderActions::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\RestApi($api_host, $api_key); try { $api->paymentStatusesList(); } catch (\RetailCrm\Exception\CurlException $e) { ICrmOrderActions::eventLog( 'intaro.crm/options.php', 'RetailCrm\RestApi::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); } //bitrix orderTypesList -- personTypes $dbOrderTypesList = CSalePersonType::GetList( array( "SORT" => "ASC", "NAME" => "ASC" ), array( "ACTIVE" => "Y", ), false, false, array() ); //form order types ids arr $orderTypesArr = array(); $orderTypesList = array(); if ($arOrderTypesList = $dbOrderTypesList->Fetch()) { do { $orderTypesArr[$arOrderTypesList['ID']] = $_POST['order-type-' . $arOrderTypesList['ID']]; $orderTypesList[] = $arOrderTypesList; } while ($arOrderTypesList = $dbOrderTypesList->Fetch()); } //bitrix deliveryTypesList $dbDeliveryTypesList = CSaleDelivery::GetList( array( "SORT" => "ASC", "NAME" => "ASC" ), array( "ACTIVE" => "Y", ), false, false, array() ); //form delivery types ids arr $deliveryTypesArr = array(); if ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()) { do { $deliveryTypesArr[$arDeliveryTypesList['ID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryTypesList['ID']])); } while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()); } //bitrix deliveryServicesList $dbDeliveryServicesList = CSaleDeliveryHandler::GetList( array( 'SORT' => 'ASC', 'NAME' => 'ASC' ), array( 'ACTIVE' => 'Y', 'SITE_ID' => $arResult['arSites'][0]['LID'] ) ); //form delivery services ids arr if ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()) { do { //auto delivery types $deliveryTypesArr[$arDeliveryServicesList['SID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryServicesList['SID']])); } while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()); } //bitrix paymentTypesList $dbPaymentTypesList = CSalePaySystem::GetList( array( "SORT" => "ASC", "NAME" => "ASC" ), array( "ACTIVE" => "Y" ) ); //form payment types ids arr $paymentTypesArr = array(); if ($arPaymentTypesList = $dbPaymentTypesList->Fetch()) { do { $paymentTypesArr[$arPaymentTypesList['ID']] = htmlspecialchars(trim($_POST['payment-type-' . $arPaymentTypesList['ID']])); } while ($arPaymentTypesList = $dbPaymentTypesList->Fetch()); } //bitrix paymentStatusesList $dbPaymentStatusesList = CSaleStatus::GetList( array( "SORT" => "ASC", "NAME" => "ASC" ), array( "LID" => "ru", //ru "ACTIVE" => "Y" ) ); //form payment statuses ids arr $paymentStatusesArr['YY'] = htmlspecialchars(trim($_POST['payment-status-YY'])); if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) { do { $paymentStatusesArr[$arPaymentStatusesList['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $arPaymentStatusesList['ID']])); } while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()); } //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']])); } COption::SetOptionString($mid, $CRM_SITES_LIST, serialize(ICrmOrderActions::clearArr($siteListArr))); COption::SetOptionString($mid, $CRM_ORDER_TYPES_ARR, serialize(ICrmOrderActions::clearArr($orderTypesArr))); COption::SetOptionString($mid, $CRM_DELIVERY_TYPES_ARR, serialize(ICrmOrderActions::clearArr($deliveryTypesArr))); COption::SetOptionString($mid, $CRM_PAYMENT_TYPES, serialize(ICrmOrderActions::clearArr($paymentTypesArr))); COption::SetOptionString($mid, $CRM_PAYMENT_STATUSES, serialize(ICrmOrderActions::clearArr($paymentStatusesArr))); COption::SetOptionString($mid, $CRM_PAYMENT, serialize(ICrmOrderActions::clearArr($paymentArr))); COption::SetOptionString($mid, $CRM_ORDER_DISCHARGE, $orderDischarge); COption::SetOptionString($mid, $CRM_ORDER_PROPS, serialize(ICrmOrderActions::clearArr($orderPropsArr))); COption::SetOptionString($mid, $CRM_CONTRAGENT_TYPE, serialize(ICrmOrderActions::clearArr($contragentTypeArr))); COption::SetOptionString($mid, $CRM_LEGAL_DETAILS, serialize(ICrmOrderActions::clearArr($legalDetailsArr))); COption::SetOptionString($mid, $CRM_CUSTOM_FIELDS, serialize(ICrmOrderActions::clearArr($customFieldsArr))); $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\RestApi($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->orderStatusesList()->statuses; $arResult['paymentGroupList'] = $api->orderStatusGroupsList()->statusGroups; // -- statuses groups $arResult['sitesList'] = $api->sitesList()->sites; } catch (\RetailCrm\Exception\CurlException $e) { ICrmOrderActions::eventLog( 'intaro.crm/options.php', 'RetailCrm\RestApi::*List::CurlException', $e->getCode() . ': ' . $e->getMessage() ); echo CAdminMessage::ShowMessage(GetMessage('ERR_' . $e->getCode())); } //bitrix orderTypesList -- personTypes $dbOrderTypesList = CSalePersonType::GetList( array( "SORT" => "ASC", "NAME" => "ASC" ), array( "ACTIVE" => "Y", ), false, false, array() ); if ($arOrderTypesList = $dbOrderTypesList->Fetch()) { do { $arResult['bitrixOrderTypesList'][] = $arOrderTypesList; } while ($arOrderTypesList = $dbOrderTypesList->Fetch()); } //bitrix deliveryTypesList $dbDeliveryTypesList = CSaleDelivery::GetList( array( "SORT" => "ASC", "NAME" => "ASC" ), array( "ACTIVE" => "Y", ), false, false, array() ); if ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()) { do { $arResult['bitrixDeliveryTypesList'][] = $arDeliveryTypesList; } while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()); } // bitrix deliveryServicesList $dbDeliveryServicesList = CSaleDeliveryHandler::GetList( array( 'SORT' => 'ASC', 'NAME' => 'ASC' ), array( 'ACTIVE' => 'Y', 'SITE_ID' => $arResult['arSites'][0]['LID'] ) ); if ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()) { do { $arResult['bitrixDeliveryTypesList'][] = array('ID' => $arDeliveryServicesList['SID'], 'NAME' => $arDeliveryServicesList['NAME']); } while ($arDeliveryServicesList = $dbDeliveryServicesList->Fetch()); } //bitrix paymentTypesList $dbPaymentTypesList = CSalePaySystem::GetList( array( "SORT" => "ASC", "NAME" => "ASC" ), array( "ACTIVE" => "Y" ) ); if ($arPaymentTypesList = $dbPaymentTypesList->Fetch()) { do { $arResult['bitrixPaymentTypesList'][] = $arPaymentTypesList; } while ($arPaymentTypesList = $dbPaymentTypesList->Fetch()); } //bitrix paymentStatusesList $dbPaymentStatusesList = CSaleStatus::GetList( array( "SORT" => "ASC", "NAME" => "ASC" ), array( "LID" => "ru", //ru "ACTIVE" => "Y" ) ); if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) { do { $arResult['bitrixPaymentStatusesList'][] = $arPaymentStatusesList; } while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()); } $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'; $dbProp = CSaleOrderProps::GetList(array(), array()); while ($arProp = $dbProp->GetNext()) { $arResult['arProp'][$arProp['PERSON_TYPE_ID']][] = $arProp; } //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)); $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('ICRM_OPTIONS_ORDER_DISCHARGE_TAB'), "ICON" => '', "TITLE" => GetMessage('ICRM_OPTIONS_ORDER_DISCHARGE_CAPTION') ) ); $tabControl = new CAdminTabControl("tabControl", $aTabs); $tabControl->Begin(); ?> AddHeadString(''); ?>
BeginNextTab(); ?> 1):?> BeginNextTab(); ?> BeginNextTab(); ?> 4) echo 'class="address-detail-' . $bitrixOrderType['ID'] . '"'; if(($countProps > 4) && (count($optionsOrderProps[$bitrixOrderType['ID']]) < 6)) echo 'style="display:none;"';?>> 0):?> > > BeginNextTab(); ?> Buttons(); ?> End(); ?>

0%
0%