diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index a56f6a50..00653968 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -105,6 +105,259 @@ class intaro_intarocrm extends CModule ); return; } + + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') + && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) { + + $api_host = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, 0); + $api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0); + $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key); + + //prepare crm lists + $arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList(); + + if ((int) $this->INTARO_CRM_API->getStatusCode() != 200) { + $APPLICATION->RestartBuffer(); + header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); + die(json_encode(array("success" => false))); + } + + $arResult['deliveryTypesList'] = $this->INTARO_CRM_API->deliveryTypesList(); + $arResult['paymentTypesList'] = $this->INTARO_CRM_API->paymentTypesList(); + $arResult['paymentStatusesList'] = $this->INTARO_CRM_API->paymentStatusesList(); // --statuses + $arResult['paymentList'] = $this->INTARO_CRM_API->orderStatusesList(); + $arResult['paymentGroupList'] = $this->INTARO_CRM_API->orderStatusGroupsList(); // -- statuses groups + + //bitrix orderTypesList -- personTypes + $dbOrderTypesList = CSalePersonType::GetList( + array( + "SORT" => "ASC", + "NAME" => "ASC" + ), + array( + "ACTIVE" => "Y", + ), + false, + false, + array() + ); + + + //form order types ids arr + $orderTypesArr = array(); + if ($arOrderTypesList = $dbOrderTypesList->Fetch()) { + do { + $arResult['bitrixOrderTypesList'][] = $arOrderTypesList; + $orderTypesArr[$arOrderTypesList['ID']] = htmlspecialchars(trim($_POST['order-type-' . $arOrderTypesList['ID']])); + } 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 { + $arResult['bitrixDeliveryTypesList'][] = $arDeliveryTypesList; + $deliveryTypesArr[$arDeliveryTypesList['ID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryTypesList['ID']])); + } while ($arDeliveryTypesList = $dbDeliveryTypesList->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 { + $arResult['bitrixPaymentTypesList'][] = $arPaymentTypesList; + $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['Y'] = htmlspecialchars(trim($_POST['payment-status-Y'])); + if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) { + do { + $arResult['bitrixPaymentStatusesList'][] = $arPaymentStatusesList; + $paymentStatusesArr[$arPaymentStatusesList['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $arPaymentStatusesList['ID']])); + } while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()); + } + + $arResult['bitrixPaymentStatusesList'][] = array( + 'ID' => 'Y', + 'NAME' => GetMessage('CANCELED') + ); + + //form payment ids arr + $paymentArr = array(); + $paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y'])); + $paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N'])); + + COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize($orderTypesArr)); + COption::SetOptionString($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR, serialize($deliveryTypesArr)); + COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_TYPES, serialize($paymentTypesArr)); + COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr)); + COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT, serialize($paymentArr)); + + // generate updated select inputs + $input = array(); + + foreach($arResult['bitrixDeliveryTypesList'] as $bitrixDeliveryType) { + $input['delivery-type-' . $bitrixDeliveryType['ID']] = + ''; + } + + foreach($arResult['bitrixPaymentTypesList'] as $bitrixPaymentType) { + $input['payment-type-' . $bitrixPaymentType['ID']] = + ''; + } + + foreach($arResult['bitrixPaymentStatusesList'] as $bitrixPaymentStatus) { + $input['payment-status-' . $bitrixPaymentStatus['ID']] = + ''; + } + + foreach($arResult['bitrixPaymentList'] as $bitrixPayment) { + $input['payment-' . $bitrixPayment['ID']] = + ''; + } + + foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType) { + $input['order-type-' . $bitrixOrderType['ID']] = + ''; + } + + $APPLICATION->RestartBuffer(); + header('Content-Type: application/x-javascript; charset='.LANG_CHARSET); + die(json_encode(array("success" => true, "result" => $input))); + } $api_host = htmlspecialchars(trim($_POST[$this->CRM_API_HOST_OPTION])); $api_key = htmlspecialchars(trim($_POST[$this->CRM_API_KEY_OPTION])); @@ -445,5 +698,4 @@ class intaro_intarocrm extends CModule function DeleteFiles() { unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/intarocrm_run.php'); unlink($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/intarocrm_setup.php'); - } -} \ No newline at end of file + } \ No newline at end of file diff --git a/intaro.intarocrm/install/step2.php b/intaro.intarocrm/install/step2.php index 030c96f5..a7128715 100755 --- a/intaro.intarocrm/install/step2.php +++ b/intaro.intarocrm/install/step2.php @@ -1,6 +1,10 @@ + + + + +