From f92a62f70e69e86296eea5a22ee84b0e1ab6a5bb Mon Sep 17 00:00:00 2001 From: Grisha Pomadchin Date: Wed, 7 Aug 2013 14:45:25 +0400 Subject: [PATCH] statuses ajax update --- intaro.intarocrm/install/index.php | 258 ++++++++++++++++++++- intaro.intarocrm/install/step2.php | 70 +++++- intaro.intarocrm/install/version.php | 2 +- intaro.intarocrm/lang/ru/install/step2.php | 7 +- intaro.intarocrm/lang/ru/options.php | 3 +- intaro.intarocrm/options.php | 3 + 6 files changed, 336 insertions(+), 7 deletions(-) diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index e731ff7e..1db78e65 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -105,7 +105,260 @@ 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])); @@ -228,7 +481,7 @@ class intaro_intarocrm extends CModule 'ID' => 'Y', 'NAME' => GetMessage('CANCELED') ); - + $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step2.php' @@ -364,7 +617,7 @@ class intaro_intarocrm extends CModule COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT, serialize($paymentArr)); COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0); - + $APPLICATION->IncludeAdminFile( GetMessage('MODULE_INSTALL_TITLE'), $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step3.php' @@ -375,7 +628,6 @@ class intaro_intarocrm extends CModule RegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder"); RegisterModuleDependences("sale", "OnSalePayOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSalePayOrder"); - //agent $dateAgent = new DateTime(); 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 @@ + + + + +
@@ -48,11 +107,20 @@ $defaultPayment = array( - + + + + + + + diff --git a/intaro.intarocrm/install/version.php b/intaro.intarocrm/install/version.php index 477013cf..0a92b4c6 100755 --- a/intaro.intarocrm/install/version.php +++ b/intaro.intarocrm/install/version.php @@ -1,5 +1,5 @@ '0.3.7', - 'VERSION_DATE' => '2013-08-06 15:07:00', + 'VERSION_DATE' => '2013-08-07 14:44:00', ); diff --git a/intaro.intarocrm/lang/ru/install/step2.php b/intaro.intarocrm/lang/ru/install/step2.php index cad51a52..a0a57f6c 100755 --- a/intaro.intarocrm/lang/ru/install/step2.php +++ b/intaro.intarocrm/lang/ru/install/step2.php @@ -10,4 +10,9 @@ $MESS ['PAYMENT_LIST'] = 'Оплата'; $MESS ['PAYMENT_Y'] = 'Оплачен'; $MESS ['PAYMENT_N'] = 'Не оплачен'; $MESS ['CANCELED'] = 'Флаг «Отменен»'; -$MESS ['INFO_1'] = ' Задайте соответствие между справочниками 1C-Битрикс и справочниками IntaroCRM.'; \ No newline at end of file +$MESS ['INFO_1'] = 'Задайте соответствие между справочниками 1C-Битрикс и справочниками IntaroCRM.'; +$MESS ['INFO_2'] = 'В случае, если вы не нашли подходящих значений в справочниках IntaroCRM, вы можете внести их в разделе'; +$MESS ['URL_1'] = 'Администрирование'; +$MESS ['INFO_3'] = 'После этого подгрузите новые значения, нажав кнопку «Обновить справочники»'; +$MESS ['UPDATE_CATS'] = 'Обновить справочники'; +$MESS ['MESS_5'] = 'Произошла ошибка сервера, обратитесь в Интаро Софт.'; \ No newline at end of file diff --git a/intaro.intarocrm/lang/ru/options.php b/intaro.intarocrm/lang/ru/options.php index 473cf341..34572124 100755 --- a/intaro.intarocrm/lang/ru/options.php +++ b/intaro.intarocrm/lang/ru/options.php @@ -21,4 +21,5 @@ $MESS ['ERR_404'] = 'Возможно не верно введен адрес CR $MESS ['ERR_403'] = 'Неверный apiKey.'; $MESS ['ERR_0'] = 'Превышено время ожидания ответа от сервера.'; $MESS ['ICRM_OPTIONS_OK'] = 'Изменения успешно сохранены.'; -$MESS ['CANCELED'] = 'Флаг «Отменен»'; \ No newline at end of file +$MESS ['CANCELED'] = 'Флаг «Отменен»'; +$MESS ['INFO_1'] = ' Задайте соответствие между справочниками 1C-Битрикс и справочниками IntaroCRM.'; \ No newline at end of file diff --git a/intaro.intarocrm/options.php b/intaro.intarocrm/options.php index 9c8043f8..3f1d439a 100755 --- a/intaro.intarocrm/options.php +++ b/intaro.intarocrm/options.php @@ -286,6 +286,9 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { BeginNextTab(); ?> + + +
+ + +
" . GetMessage('URL_1') . "" . " " . 'IntaroCRM.'; ?>