1
0
mirror of synced 2024-11-22 13:26:10 +03:00

merging second

This commit is contained in:
pomadchin 2013-08-14 11:05:37 +04:00
commit dec7cd50ea
6 changed files with 336 additions and 7 deletions

View File

@ -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']] =
'<select name="delivery-type-' . $bitrixDeliveryType['ID'] . '" class="typeselect">';
$input['delivery-type-' . $bitrixDeliveryType['ID']] .= '<option value=""></option>';
foreach($arResult['deliveryTypesList'] as $deliveryType) {
if ($deliveryTypesArr[$bitrixDeliveryType['ID']] == $deliveryType['code']) {
$input['delivery-type-' . $bitrixDeliveryType['ID']] .=
'<option value="' . $deliveryType['code'] . '" selected>';
} else {
$input['delivery-type-' . $bitrixDeliveryType['ID']] .=
'<option value="' . $deliveryType['code'] . '">';
}
$input['delivery-type-' . $bitrixDeliveryType['ID']] .=
$APPLICATION->ConvertCharset($deliveryType['name'], 'utf-8', SITE_CHARSET);
$input['delivery-type-' . $bitrixDeliveryType['ID']] .= '</option>';
}
$input['delivery-type-' . $bitrixDeliveryType['ID']] .= '</select>';
}
foreach($arResult['bitrixPaymentTypesList'] as $bitrixPaymentType) {
$input['payment-type-' . $bitrixPaymentType['ID']] =
'<select name="payment-type-' . $bitrixPaymentType['ID'] . '" class="typeselect">';
$input['payment-type-' . $bitrixPaymentType['ID']] .= '<option value=""></option>';
foreach($arResult['paymentTypesList'] as $paymentType) {
if ($paymentTypesArr[$bitrixPaymentType['ID']] == $paymentType['code']) {
$input['payment-type-' . $bitrixPaymentType['ID']] .=
'<option value="' . $paymentType['code'] . '" selected>';
} else {
$input['payment-type-' . $bitrixPaymentType['ID']] .=
'<option value="' . $paymentType['code'] . '">';
}
$input['payment-type-' . $bitrixPaymentType['ID']] .=
$APPLICATION->ConvertCharset($paymentType['name'], 'utf-8', SITE_CHARSET);
$input['payment-type-' . $bitrixPaymentType['ID']] .= '</option>';
}
$input['payment-type-' . $bitrixPaymentType['ID']] .= '</select>';
}
foreach($arResult['bitrixPaymentStatusesList'] as $bitrixPaymentStatus) {
$input['payment-status-' . $bitrixPaymentStatus['ID']] =
'<select name="payment-status-' . $bitrixPaymentStatus['ID'] . '" class="typeselect">';
$input['payment-status-' . $bitrixPaymentStatus['ID']] .= '<option value=""></option>';
foreach($arResult['paymentGroupList'] as $orderStatusGroup){
if(empty($orderStatusGroup['statuses'])) continue;
$input['payment-status-' . $bitrixPaymentStatus['ID']].=
'<optgroup label="' . $orderStatusGroup['name'] . '">';
foreach($orderStatusGroup['statuses'] as $payment) {
if ($paymentStatusesArr[$bitrixPaymentStatus['ID']] == $arResult['paymentList'][$payment]['code']) {
$input['payment-status-' . $bitrixPaymentStatus['ID']] .=
'<option value="' . $arResult['paymentList'][$payment]['code'] . '" selected>';
} else {
$input['payment-status-' . $bitrixPaymentStatus['ID']] .=
'<option value="' . $arResult['paymentList'][$payment]['code'] . '">';
}
$input['payment-status-' . $bitrixPaymentStatus['ID']] .=
$APPLICATION->ConvertCharset($arResult['paymentList'][$payment]['name'], 'utf-8', SITE_CHARSET);
$input['payment-status-' . $bitrixPaymentStatus['ID']] .= '</option>';
}
$input['payment-status-' . $bitrixPaymentStatus['ID']] .= '</optgroup>';
}
$input['payment-status-' . $bitrixPaymentStatus['ID']] .= '</select>';
}
foreach($arResult['bitrixPaymentList'] as $bitrixPayment) {
$input['payment-' . $bitrixPayment['ID']] =
'<select name="payment-' . $bitrixPayment['ID'] . '" class="typeselect">';
$input['payment-' . $bitrixPayment['ID']] .= '<option value=""></option>';
foreach($arResult['paymentStatusesList'] as $paymentStatus) {
if ($paymentArr[$bitrixPayment['ID']] == $paymentStatus['code']) {
$input['payment-' . $bitrixPayment['ID']] .=
'<option value="' . $paymentStatus['code'] . '" selected>';
} else {
$input['payment-' . $bitrixPayment['ID']] .=
'<option value="' . $paymentStatus['code']. '">';
}
$input['payment-' . $bitrixPayment['ID']] .=
$APPLICATION->ConvertCharset($paymentStatus['name'], 'utf-8', SITE_CHARSET);
$input['payment-' . $bitrixPayment['ID']] .= '</option>';
}
$input['payment-' . $bitrixPayment['ID']] .= '</select>';
}
foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType) {
$input['order-type-' . $bitrixOrderType['ID']] =
'<select name="order-type-' . $bitrixOrderType['ID'] . '" class="typeselect">';
$input['order-type-' . $bitrixOrderType['ID']] .= '<option value=""></option>';
foreach($arResult['orderTypesList'] as $orderType) {
if ($orderTypesArr[$bitrixOrderType['ID']] == $orderType['code']) {
$input['order-type-' . $bitrixOrderType['ID']] .=
'<option value="' . $orderType['code'] . '" selected>';
} else {
$input['order-type-' . $bitrixOrderType['ID']] .=
'<option value="' . $orderType['code']. '">';
}
$input['order-type-' . $bitrixOrderType['ID']] .=
$APPLICATION->ConvertCharset($orderType['name'], 'utf-8', SITE_CHARSET);
$input['order-type-' . $bitrixOrderType['ID']] .= '</option>';
}
$input['order-type-' . $bitrixOrderType['ID']] .= '</select>';
}
$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');
}
}
}

View File

@ -1,6 +1,10 @@
<?php
IncludeModuleLangFile(__FILE__);
$MODULE_ID = 'intaro.intarocrm';
$CRM_API_HOST_OPTION = 'api_host';
$api_host = COption::GetOptionString($MODULE_ID, $CRM_API_HOST_OPTION, 0);
//bitrix pyament Y/N
$arResult['bitrixPaymentList'][0]['NAME'] = GetMessage('PAYMENT_Y');
$arResult['bitrixPaymentList'][0]['ID'] = 'Y';
@ -37,6 +41,61 @@ $defaultPayment = array(
?>
<style type="text/css">
input[name="update"] {
right:2px;
position: absolute !important;
top:3px;
}
</style>
<script type="text/javascript" src="/bitrix/js/main/jquery/jquery-1.7.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('input[name="update"]').live('click', function() {
$('input[name="step"]').val(2);
BX.showWait();
var updButton = this;
// hide next step button
$(updButton).css('opacity', '0.5').attr('disabled', 'disabled');
var handlerUrl = $(this).parents('form').attr('action');
var data = $(this).parents('form').serialize() + '&ajax=1';
$.ajax({
type: 'POST',
url: handlerUrl,
data: data,
dataType: 'json',
success: function(response) {
if(response.success) {
$.each(response.result, function(i,item){
$('select[name="' + i + '"]').replaceWith(item);
});
}
BX.closeWait();
$(updButton).css('opacity', '1').removeAttr('disabled');
$('input[name="step"]').val(3);
if(!response.success)
alert('<?php echo GetMessage('MESS_5'); ?>');
},
error: function () {
BX.closeWait();
$(updButton).css('opacity', '1').removeAttr('disabled');
$('input[name="step"]').val(3);
alert('<?php echo GetMessage('MESS_5'); ?>');
}
});
return false;
});
});
</script>
<div class="adm-detail-content-item-block">
<form action="<?php echo $APPLICATION->GetCurPage() ?>" method="POST">
<?php echo bitrix_sessid_post(); ?>
@ -48,11 +107,20 @@ $defaultPayment = array(
<table class="adm-detail-content-table edit-table" id="edit1_edit_table">
<tbody>
<tr class="heading">
<td colspan="2"><b><?php echo GetMessage('STEP_NAME'); ?></b></td>
<td colspan="2" style="position:relative;">
<b><?php echo GetMessage('STEP_NAME'); ?></b>
<input type="submit" name="update" value="<?php echo GetMessage('UPDATE_CATS'); ?>" class="adm-btn-save">
</td>
</tr>
<tr align="center">
<td colspan="2"><b><?php echo GetMessage('INFO_1'); ?></b></td>
</tr>
<tr align="center">
<td colspan="2"><?php echo GetMessage('INFO_2') . " " . "<a href='". $api_host ."/admin/statuses' target=_blank>" . GetMessage('URL_1') . "</a>" . " " . 'IntaroCRM.'; ?></td>
</tr>
<tr align="center">
<td colspan="2"><?php echo GetMessage('INFO_3'); ?></td>
</tr>
<tr class="heading">
<td colspan="2"><b><?php echo GetMessage('DELIVERY_TYPES_LIST'); ?></b></td>
</tr>

View File

@ -1,5 +1,5 @@
<?
$arModuleVersion = array(
'VERSION' => '0.3.7',
'VERSION_DATE' => '2013-08-06 15:07:00',
);
'VERSION_DATE' => '2013-08-14 10:59:00',
);

View File

@ -10,4 +10,9 @@ $MESS ['PAYMENT_LIST'] = 'Оплата';
$MESS ['PAYMENT_Y'] = 'Оплачен';
$MESS ['PAYMENT_N'] = 'Не оплачен';
$MESS ['CANCELED'] = 'Флаг «Отменен»';
$MESS ['INFO_1'] = ' Задайте соответствие между справочниками 1C-Битрикс и справочниками IntaroCRM.';
$MESS ['INFO_1'] = 'Задайте соответствие между справочниками 1C-Битрикс и справочниками IntaroCRM.';
$MESS ['INFO_2'] = 'В случае, если вы не нашли подходящих значений в справочниках IntaroCRM, вы можете внести их в разделе';
$MESS ['URL_1'] = 'Администрирование';
$MESS ['INFO_3'] = 'После этого подгрузите новые значения, нажав кнопку «Обновить справочники»';
$MESS ['UPDATE_CATS'] = 'Обновить справочники';
$MESS ['MESS_5'] = 'Произошла ошибка сервера, обратитесь в Интаро Софт.';

View File

@ -21,4 +21,5 @@ $MESS ['ERR_404'] = 'Возможно не верно введен адрес CR
$MESS ['ERR_403'] = 'Неверный apiKey.';
$MESS ['ERR_0'] = 'Превышено время ожидания ответа от сервера.';
$MESS ['ICRM_OPTIONS_OK'] = 'Изменения успешно сохранены.';
$MESS ['CANCELED'] = 'Флаг «Отменен»';
$MESS ['CANCELED'] = 'Флаг «Отменен»';
$MESS ['INFO_1'] = ' Задайте соответствие между справочниками 1C-Битрикс и справочниками IntaroCRM.';

View File

@ -286,6 +286,9 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
</tr>
<?php $tabControl->BeginNextTab(); ?>
<input type="hidden" name="tab" value="catalog">
<tr align="center">
<td colspan="2"><b><?php echo GetMessage('INFO_1'); ?></b></td>
</tr>
<tr class="heading">
<td colspan="2"><b><?php echo GetMessage('DELIVERY_TYPES_LIST'); ?></b></td>
</tr>