2013-07-05 18:19:42 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Module Install/Uninstall script
|
|
|
|
* Module name: intaro.crm
|
|
|
|
* Class name: intaro_crm
|
|
|
|
*/
|
|
|
|
|
|
|
|
global $MESS;
|
|
|
|
IncludeModuleLangFile(__FILE__);
|
|
|
|
if (class_exists('intaro_crm'))
|
|
|
|
return;
|
|
|
|
|
|
|
|
class intaro_crm extends CModule
|
|
|
|
{
|
|
|
|
var $MODULE_ID = 'intaro.crm';
|
|
|
|
var $MODULE_VERSION;
|
|
|
|
var $MODULE_VERSION_DATE;
|
|
|
|
var $MODULE_NAME;
|
|
|
|
var $MODULE_DESCRIPTION;
|
|
|
|
var $MODULE_GROUP_RIGHTS = 'N';
|
|
|
|
var $PARTNER_NAME;
|
|
|
|
var $PARTNER_URI;
|
|
|
|
var $INTARO_CRM_API;
|
|
|
|
|
|
|
|
var $CRM_API_HOST_OPTION = 'api_host';
|
|
|
|
var $CRM_API_KEY_OPTION = 'api_key';
|
2013-07-05 21:15:23 +04:00
|
|
|
var $CRM_ORDER_TYPES_ARR = 'order_types_arr';
|
2013-07-05 18:19:42 +04:00
|
|
|
var $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
|
|
|
|
var $CRM_PAYMENT_TYPES = 'pay_types_arr';
|
|
|
|
var $CRM_PAYMENT_STATUSES = 'pay_statuses_arr';
|
2013-07-08 15:08:14 +04:00
|
|
|
var $CRM_PAYMENT = 'payment_arr'; //order payment Y/N
|
|
|
|
|
2013-07-05 18:19:42 +04:00
|
|
|
|
|
|
|
var $INSTALL_PATH;
|
|
|
|
|
|
|
|
function intaro_crm()
|
|
|
|
{
|
|
|
|
$arModuleVersion = array();
|
|
|
|
$path = str_replace("\\", "/", __FILE__);
|
|
|
|
$path = substr($path, 0, strlen($path) - strlen("/index.php"));
|
|
|
|
$this->INSTALL_PATH = $path;
|
|
|
|
include($path."/version.php");
|
|
|
|
$this->MODULE_VERSION = $arModuleVersion["VERSION"];
|
|
|
|
$this->MODULE_VERSION_DATE = $arModuleVersion["VERSION_DATE"];
|
|
|
|
$this->MODULE_NAME = GetMessage('MODULE_NAME');
|
|
|
|
$this->MODULE_DESCRIPTION = GetMessage('MODULE_DESCRIPTION');
|
2013-07-05 21:15:23 +04:00
|
|
|
$this->PARTNER_NAME = GetMessage('MODULE_PARTNER_NAME');
|
|
|
|
$this->PARTNER_URI = GetMessage('MODULE_PARTNER_URI');
|
2013-07-05 18:19:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions DoInstall and DoUninstall are
|
|
|
|
* All other functions are optional
|
|
|
|
*/
|
|
|
|
|
|
|
|
function DoInstall()
|
|
|
|
{
|
|
|
|
global $APPLICATION, $step, $arResult;
|
|
|
|
|
2013-07-08 15:08:14 +04:00
|
|
|
include($this->INSTALL_PATH . '/../classes/general/RestApi.php');
|
|
|
|
|
2013-07-05 18:19:42 +04:00
|
|
|
$step = intval($_REQUEST['step']);
|
|
|
|
|
|
|
|
if ($step <= 1) {
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
|
|
|
GetMessage('MODULE_INSTALL_TITLE'),
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php'
|
|
|
|
);
|
|
|
|
} else if ($step == 2) {
|
|
|
|
if(!CModule::IncludeModule("sale")) {
|
|
|
|
//handler
|
|
|
|
}
|
|
|
|
|
|
|
|
$api_host = htmlspecialchars(trim($_POST[$this->CRM_API_HOST_OPTION]));
|
|
|
|
$api_key = htmlspecialchars(trim($_POST[$this->CRM_API_KEY_OPTION]));
|
|
|
|
|
|
|
|
if(!$api_host || !$api_key) {
|
|
|
|
$arResult['errCode'] = 'ERR_FIELDS_API_HOST';
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
|
|
|
GetMessage('MODULE_INSTALL_TITLE'),
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php'
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-08 15:08:14 +04:00
|
|
|
$this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key);
|
2013-07-05 18:19:42 +04:00
|
|
|
|
|
|
|
$this->INTARO_CRM_API->paymentStatusesList();
|
|
|
|
|
|
|
|
//check connection & apiKey valid
|
|
|
|
if((int) $this->INTARO_CRM_API->getStatusCode() != 200) {
|
|
|
|
$arResult['errCode'] = 'ERR_' . $this->INTARO_CRM_API->getStatusCode();
|
|
|
|
|
|
|
|
$APPLICATION->IncludeAdminFile(
|
|
|
|
GetMessage('MODULE_INSTALL_TITLE'),
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php'
|
|
|
|
);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_API_HOST_OPTION, $api_host);
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, $api_key);
|
|
|
|
|
|
|
|
//prepare crm lists
|
2013-07-05 21:15:23 +04:00
|
|
|
$arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList();
|
2013-07-05 18:19:42 +04:00
|
|
|
$arResult['deliveryTypesList'] = $this->INTARO_CRM_API->deliveryTypesList();
|
|
|
|
$arResult['paymentTypesList'] = $this->INTARO_CRM_API->paymentTypesList();
|
2013-07-08 15:08:14 +04:00
|
|
|
$arResult['paymentStatusesList'] = $this->INTARO_CRM_API->paymentStatusesList(); // --statuses
|
|
|
|
//$arResult['payment'] = $this->INTARO_CRM_API->getPymentsList() -- not exist
|
2013-07-05 18:19:42 +04:00
|
|
|
|
2013-07-05 21:15:23 +04:00
|
|
|
//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());
|
|
|
|
}
|
2013-07-05 18:19:42 +04:00
|
|
|
|
|
|
|
//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 paymentTypesList
|
|
|
|
$dbPaymentTypesList = CSalePaySystem::GetList(
|
|
|
|
array(
|
|
|
|
"SORT" => "ASC",
|
|
|
|
"NAME" => "ASC"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"ACTIVE" => "Y"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($arPaymentTypesList = $dbPaymentTypesList->Fetch()) {
|
|
|
|
do {
|
|
|
|
$arResult['bitrixPaymentTypesList'][] = $arPaymentTypesList;
|
|
|
|
} while ($arPaymentTypesList = $dbPaymentTypesList->Fetch());
|
|
|
|
}
|
|
|
|
|
2013-07-08 15:08:14 +04:00
|
|
|
//bitrix paymentStatusesList --statuses
|
2013-07-05 18:19:42 +04:00
|
|
|
$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());
|
|
|
|
}
|
|
|
|
|
2013-07-08 15:08:14 +04:00
|
|
|
$APPLICATION->IncludeAdminFile(
|
2013-07-05 18:19:42 +04:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'),
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step2.php'
|
|
|
|
);
|
|
|
|
|
2013-07-08 15:08:14 +04:00
|
|
|
} else if ($step == 3) {
|
2013-07-05 18:19:42 +04:00
|
|
|
if(!CModule::IncludeModule("sale")) {
|
|
|
|
//handler
|
|
|
|
}
|
2013-07-05 21:15:23 +04:00
|
|
|
|
|
|
|
//bitrix orderTypesList -- personTypes
|
|
|
|
$dbOrderTypesList = CSalePersonType::GetList(
|
|
|
|
array(
|
|
|
|
"SORT" => "ASC",
|
|
|
|
"NAME" => "ASC"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"ACTIVE" => "Y",
|
|
|
|
),
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
array()
|
|
|
|
);
|
|
|
|
|
|
|
|
//form order types ids arr
|
2013-07-08 15:08:14 +04:00
|
|
|
$orderTypesArr = array();
|
2013-07-05 21:15:23 +04:00
|
|
|
if ($arOrderTypesList = $dbOrderTypesList->Fetch()) {
|
|
|
|
do {
|
2013-07-08 15:08:14 +04:00
|
|
|
$orderTypesArr[$arOrderTypesList['ID']] = htmlspecialchars(trim($_POST['order-type-' . $arOrderTypesList['ID']]));
|
2013-07-05 21:15:23 +04:00
|
|
|
} while ($arOrderTypesList = $dbOrderTypesList->Fetch());
|
|
|
|
}
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
|
|
//bitrix deliveryTypesList
|
2013-07-05 18:19:42 +04:00
|
|
|
$dbDeliveryTypesList = CSaleDelivery::GetList(
|
|
|
|
array(
|
|
|
|
"SORT" => "ASC",
|
|
|
|
"NAME" => "ASC"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"ACTIVE" => "Y",
|
|
|
|
),
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
array()
|
|
|
|
);
|
|
|
|
|
|
|
|
//form delivery types ids arr
|
2013-07-08 15:08:14 +04:00
|
|
|
$deliveryTypesArr = array();
|
2013-07-05 18:19:42 +04:00
|
|
|
if ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch()) {
|
|
|
|
do {
|
2013-07-08 15:08:14 +04:00
|
|
|
$deliveryTypesArr[$arDeliveryTypesList['ID']] = htmlspecialchars(trim($_POST['delivery-type-' . $arDeliveryTypesList['ID']]));
|
2013-07-05 18:19:42 +04:00
|
|
|
} while ($arDeliveryTypesList = $dbDeliveryTypesList->Fetch());
|
|
|
|
}
|
|
|
|
|
2013-07-08 15:08:14 +04:00
|
|
|
//bitrix paymentTypesList
|
2013-07-05 18:19:42 +04:00
|
|
|
$dbPaymentTypesList = CSalePaySystem::GetList(
|
|
|
|
array(
|
|
|
|
"SORT" => "ASC",
|
|
|
|
"NAME" => "ASC"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"ACTIVE" => "Y"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
//form payment types ids arr
|
2013-07-08 15:08:14 +04:00
|
|
|
$paymentTypesArr = array();
|
2013-07-05 18:19:42 +04:00
|
|
|
if ($arPaymentTypesList = $dbPaymentTypesList->Fetch()) {
|
|
|
|
do {
|
2013-07-08 15:08:14 +04:00
|
|
|
$paymentTypesArr[$arPaymentTypesList['ID']] = htmlspecialchars(trim($_POST['payment-type-' . $arPaymentTypesList['ID']]));
|
2013-07-05 18:19:42 +04:00
|
|
|
} while ($arPaymentTypesList = $dbPaymentTypesList->Fetch());
|
|
|
|
}
|
|
|
|
|
2013-07-08 15:08:14 +04:00
|
|
|
//bitrix paymentStatusesList
|
2013-07-05 18:19:42 +04:00
|
|
|
$dbPaymentStatusesList = CSaleStatus::GetList(
|
|
|
|
array(
|
|
|
|
"SORT" => "ASC",
|
|
|
|
"NAME" => "ASC"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"LID" => "ru", //ru
|
|
|
|
"ACTIVE" => "Y"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
//form payment statuses ids arr
|
2013-07-05 21:15:23 +04:00
|
|
|
$paymentStatusesArr = array();
|
2013-07-05 18:19:42 +04:00
|
|
|
if ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch()) {
|
|
|
|
do {
|
2013-07-08 15:08:14 +04:00
|
|
|
$paymentStatusesArr[$arPaymentStatusesList['ID']] = htmlspecialchars(trim($_POST['payment-status-' . $arPaymentStatusesList['ID']]));
|
2013-07-05 18:19:42 +04:00
|
|
|
} while ($arPaymentStatusesList = $dbPaymentStatusesList->Fetch());
|
|
|
|
}
|
2013-07-08 15:08:14 +04:00
|
|
|
|
|
|
|
//form payment ids arr
|
|
|
|
$paymentArr = array();
|
|
|
|
$paymentArr['Y'] = htmlspecialchars(trim($_POST['payment-Y']));
|
|
|
|
$paymentArr['N'] = htmlspecialchars(trim($_POST['payment-N']));
|
2013-07-05 18:19:42 +04:00
|
|
|
|
2013-07-05 21:15:23 +04:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR, serialize($orderTypesArr));
|
2013-07-08 15:08:14 +04:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR, serialize($deliveryTypesArr));
|
2013-07-05 18:19:42 +04:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_TYPES, serialize($paymentTypesArr));
|
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES, serialize($paymentStatusesArr));
|
2013-07-08 15:08:14 +04:00
|
|
|
COption::SetOptionString($this->MODULE_ID, $this->CRM_PAYMENT, serialize($paymentArr));
|
2013-07-05 18:19:42 +04:00
|
|
|
RegisterModule($this->MODULE_ID);
|
|
|
|
|
2013-07-05 21:15:23 +04:00
|
|
|
$APPLICATION->IncludeAdminFile(
|
2013-07-05 18:19:42 +04:00
|
|
|
GetMessage('MODULE_INSTALL_TITLE'),
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step3.php'
|
|
|
|
);
|
2013-07-05 21:15:23 +04:00
|
|
|
}
|
2013-07-05 18:19:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function DoUninstall() {
|
2013-07-05 21:15:23 +04:00
|
|
|
global $APPLICATION;
|
2013-07-05 18:19:42 +04:00
|
|
|
|
2013-07-05 21:15:23 +04:00
|
|
|
UnRegisterModule($this->MODULE_ID);
|
2013-07-05 18:19:42 +04:00
|
|
|
|
2013-07-05 21:15:23 +04:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_API_HOST_OPTION);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_API_KEY_OPTION);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_DELIVERY_TYPES_ARR);
|
2013-07-05 18:19:42 +04:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT_TYPES);
|
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES);
|
2013-07-08 15:08:14 +04:00
|
|
|
COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT);
|
2013-07-05 18:19:42 +04:00
|
|
|
|
2013-07-05 21:15:23 +04:00
|
|
|
$APPLICATION->IncludeAdminFile(
|
|
|
|
GetMessage('MODULE_UNINSTALL_TITLE'),
|
|
|
|
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/unstep1.php'
|
2013-07-08 15:08:14 +04:00
|
|
|
);
|
2013-07-05 18:19:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|