diff --git a/intaro.intarocrm/install/export/intarocrm_run.php b/intaro.intarocrm/install/export/intarocrm_run.php new file mode 100644 index 00000000..23091100 --- /dev/null +++ b/intaro.intarocrm/install/export/intarocrm_run.php @@ -0,0 +1,18 @@ +IntaroCRM +set_time_limit(0); + +global $APPLICATION; +if (!CModule::IncludeModule("iblock")) + return; +if (!CModule::IncludeModule("catalog")) + return; +if (!CModule::IncludeModule("intaro.intarocrm")) + return; + +$loader = new ICMLLoader(); +$loader->iblocks = $IBLOCK_EXPORT; +$loader->articleProperties = $IBLOCK_PROPERTY_ARTICLE; +$loader->filename = $SETUP_FILE_NAME; +$loader->application = $APPLICATION; +$loader->Load(); \ No newline at end of file diff --git a/intaro.intarocrm/install/export/intarocrm_setup.php b/intaro.intarocrm/install/export/intarocrm_setup.php new file mode 100644 index 00000000..60eee5bd --- /dev/null +++ b/intaro.intarocrm/install/export/intarocrm_setup.php @@ -0,0 +1,256 @@ +IntaroCRM + +if(!check_bitrix_sessid()) return; + +__IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/lang/", "/icml_export_setup.php")); + +if (($ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY') && $STEP == 1) +{ + if (isset($arOldSetupVars['SETUP_FILE_NAME'])) + $SETUP_FILE_NAME = $arOldSetupVars['SETUP_FILE_NAME']; + if (isset($arOldSetupVars['SETUP_PROFILE_NAME'])) + $SETUP_PROFILE_NAME = $arOldSetupVars['SETUP_PROFILE_NAME']; +} + + +if ($STEP>1) +{ + + if (strlen($SETUP_FILE_NAME)<=0) + { + $arSetupErrors[] = GetMessage("CET_ERROR_NO_FILENAME"); + } + elseif ($APPLICATION->GetFileAccessPermission($SETUP_FILE_NAME) < "W") + { + $arSetupErrors[] = str_replace("#FILE#", $SETUP_FILE_NAME, GetMessage('CET_YAND_RUN_ERR_SETUP_FILE_ACCESS_DENIED')); + } + + if (($ACTION=="EXPORT_SETUP" || $ACTION == 'EXPORT_EDIT' || $ACTION == 'EXPORT_COPY') && strlen($SETUP_PROFILE_NAME)<=0) + { + $arSetupErrors[] = GetMessage("CET_ERROR_NO_PROFILE_NAME"); + } + + if (!empty($arSetupErrors)) + { + $STEP = 1; + } +} + +if (!empty($arSetupErrors)) + echo ShowError(implode('
', $arSetupErrors)); + + +if ($STEP==1) +{ + + +?> +
+

+ "ASC", "NAME"=>"ASC"),array('CHECK_PERMISSIONS' => 'Y','MIN_PERMISSION' => 'W')); + while ($res = $db_res->Fetch()) + { + if ($arCatalog = CCatalog::GetByIDExt($res["ID"])) + { + if($arCatalog['CATALOG_TYPE'] == "D" || $arCatalog['CATALOG_TYPE'] == "X" || $arCatalog['CATALOG_TYPE'] == "P") + { + $arSiteList = array(); + $rsSites = CIBlock::GetSite($res["ID"]); + while ($arSite = $rsSites->Fetch()) + { + $arSiteList[] = $arSite["SITE_ID"]; + } + $db_properties = CIBlock::GetProperties($res['ID'], Array()); + + $properties = Array(); + while($prop = $db_properties->Fetch()) + $properties[] = $prop; + + + $boolExport = (in_array($res['ID'],$IBLOCK_EXPORT)); + $arIBlockList[] = array( + 'ID' => $res['ID'], + 'NAME' => $res['NAME'], + 'IBLOCK_TYPE_ID' => $res['IBLOCK_TYPE_ID'], + 'IBLOCK_EXPORT' => $boolExport, + 'PROPERTIES' => $properties, + 'SITE_LIST' => '('.implode(' ',$arSiteList).')', + ); + + if ($boolExport) + $intCountChecked++; + $intCountAvailIBlock++; + } + } + } + if ($intCountChecked == $intCountAvailIBlock) + $boolAll = true; + + ?> + + + + + + + + + + + + + + + + + + $arIBlock) + { + ?> + + + + + + + +
+
+
+
+   +
+
+
+
+ + + > + + +   +
+ + + + " + + onclick="checkOne(this,);" + > + + + +
+ +
+
+
+ +

+ + +
+
+
+ + + +

+ +
+
+
+ + + + + + + + + + + + "> + + + + "> + + +
+ + \ No newline at end of file diff --git a/intaro.intarocrm/install/index.php b/intaro.intarocrm/install/index.php index 21d70fb5..b18be419 100755 --- a/intaro.intarocrm/install/index.php +++ b/intaro.intarocrm/install/index.php @@ -1,871 +1,888 @@ -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'); - $this->PARTNER_NAME = GetMessage('MODULE_PARTNER_NAME'); - $this->PARTNER_URI = GetMessage('MODULE_PARTNER_URI'); - } - - /** - * Functions DoInstall and DoUninstall are - * All other functions are optional - */ - - function DoInstall() - { - global $APPLICATION, $step, $arResult; - - if (!in_array('curl', get_loaded_extensions())) { - $APPLICATION->ThrowException( GetMessage("INTAROCRM_CURL_ERR") ); - return false; - } - - include($this->INSTALL_PATH . '/../classes/general/RestApi.php'); - include($this->INSTALL_PATH . '/../classes/general/ICrmOrderActions.php'); - include($this->INSTALL_PATH . '/../classes/general/ICMLLoader.php'); - - $step = intval($_REQUEST['step']); - - if ($step <= 1) { - if(!CModule::IncludeModule("sale")) { - $arResult['errCode'] = 'ERR_SALE'; - } - - if(!CModule::IncludeModule("iblock")) { - $arResult['errCode'] = 'ERR_IBLOCK'; - } - - if(!CModule::IncludeModule("catalog")) { - $arResult['errCode'] = 'ERR_CATALOG'; - } - - $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")) { - $arResult['errCode'] = 'ERR_SALE'; - } - - if(!CModule::IncludeModule("iblock")) { - $arResult['errCode'] = 'ERR_IBLOCK'; - } - - if(!CModule::IncludeModule("catalog")) { - $arResult['errCode'] = 'ERR_CATALOG'; - } - - if(isset($arResult['errCode']) && $arResult['errCode']) { - $APPLICATION->IncludeAdminFile( - GetMessage('MODULE_INSTALL_TITLE'), - $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php' - ); - 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])); - - // form correct url - $api_host = parse_url($api_host); - $api_host = $api_host['scheme'] . '://' . $api_host['host']; - - 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; - } - - $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key); - - $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 - $arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList(); - $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() - ); - - 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 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 --statuses - $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' => 'Y', - 'NAME' => GetMessage('CANCELED') - ); - - $APPLICATION->IncludeAdminFile( - GetMessage('MODULE_INSTALL_TITLE'), - $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step2.php' - ); - - } else if ($step == 3) { - if(!CModule::IncludeModule("sale")) { - //handler - } - - if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') - && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) { - ICrmOrderActions::uploadOrders(); // each 50 - - $lastUpOrderId = COption::GetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0); - $countLeft = (int) CSaleOrder::GetList(array("ID" => "ASC"), array('>ID' => $lastUpOrderId), array()); - $countAll = (int) CSaleOrder::GetList(array("ID" => "ASC"), array(), array()); - - if(!isset($_POST['finish'])) - $finish = 0; - else - $finish = (int) $_POST['finish']; - - $percent = 100 - round(($countLeft * 100 / $countAll), 1); - - if(!$countLeft) - $finish = 1; - - $APPLICATION->RestartBuffer(); - header('Content-Type: application/x-javascript; charset='.LANG_CHARSET); - die(json_encode(array("finish" => $finish, "percent" => $percent))); - } - - if (isset($_POST['back']) && $_POST['back']) { - $APPLICATION->IncludeAdminFile( - GetMessage('MODULE_INSTALL_TITLE'), - $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php' - ); - } - - //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 { - $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 { - $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 { - $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 { - $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'])); - - 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)); - 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' - ); - } else if ($step == 4) { - if(!CModule::IncludeModule("iblock")) { - $arResult['errCode'] = 'ERR_IBLOCK'; - } - - if(!CModule::IncludeModule("catalog")) { - $arResult['errCode'] = 'ERR_CATALOG'; - } - $APPLICATION->IncludeAdminFile( - GetMessage('MODULE_INSTALL_TITLE'), - $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step4.php' - ); - - } else if ($step == 5) { - if(isset($arResult['errCode']) && $arResult['errCode']) { - $APPLICATION->IncludeAdminFile( - GetMessage('MODULE_INSTALL_TITLE'), - $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step4.php' - ); - return; - } - - if (isset($_POST['back']) && $_POST['back']) { - $APPLICATION->IncludeAdminFile( - GetMessage('MODULE_INSTALL_TITLE'), - $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step3.php' - ); - } - - RegisterModule($this->MODULE_ID); - - RegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder"); - RegisterModuleDependences("sale", "OnSalePayOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSalePayOrder"); - - if(!CModule::IncludeModule("iblock")) { - $arResult['errCode'] = 'ERR_IBLOCK'; - } - - if (!CModule::IncludeModule("catalog")) { - $arResult['errCode'] = 'ERR_CATALOG'; - } - - if (!isset($_POST['IBLOCK_EXPORT'])) - $iblocks = 0; - else - $iblocks = $_POST['IBLOCK_EXPORT']; - - if (!isset($_POST['IBLOCK_PROPERTY_ARTICLE'])) - $articleProperties = 0; - else - $articleProperties = $_POST['IBLOCK_PROPERTY_ARTICLE']; - - if (!isset($_POST['SETUP_PROFILE_NAME'])) - $profileName = 0; - else - $profileName = $_POST['SETUP_PROFILE_NAME']; - - if (!isset($_POST['SETUP_FILE_NAME'])) - $filename = 0; - else - $filename = $_POST['SETUP_FILE_NAME']; - - if (!isset($_POST['TYPE_LOADING'])) - $typeLoading = 0; - else - $typeLoading = $_POST['TYPE_LOADING']; - - if (isset($_POST['LOAD_NOW'])) { - - $loader = new ICMLLoader(); - $loader->iblocks = $iblocks; - $loader->articleProperties = $articleProperties; - $loader->filename = $filename; - $loader->application = $APPLICATION; - $loader->Load(); - } - if (!isset($_POST['TYPE_LOADING'])) - $typeLoading = 0; - else - $typeLoading = $_POST['TYPE_LOADING']; - - if ($typeLoading == 'agent' || $typeLoading == 'cron') { - $dbProfile = CCatalogExport::GetList(array(), array("FILE_NAME" => $this->INTARO_CRM_EXPORT)); - - while ($arProfile = $dbProfile->Fetch()) { - if ($arProfile["DEFAULT_PROFILE"] != "Y") - CAgent::RemoveAgent("CCatalogExport::PreGenerateExport(" . $arProfile['ID'] . ");", "catalog"); - } - $ar = $this->GetProfileSetupVars($iblocks, $articleProperties, $filename); - $PROFILE_ID = CCatalogExport::Add(array( - "LAST_USE" => false, - "FILE_NAME" => $this->INTARO_CRM_EXPORT, - "NAME" => $profileName, - "DEFAULT_PROFILE" => "N", - "IN_MENU" => "N", - "IN_AGENT" => "N", - "IN_CRON" => "N", - "NEED_EDIT" => "N", - "SETUP_VARS" => $ar - )); - if (intval($PROFILE_ID) <= 0) { - $arResult['errCode'] = 'ERR_IBLOCK'; - return; - } - if ($typeLoading == 'agent') { - - $dateAgent = new DateTime(); - $intAgent = new DateInterval('PT60S'); // PT60S - 60 sec; - $dateAgent->add($intAgent); - CAgent::AddAgent( - "CCatalogExport::PreGenerateExport(" . $PROFILE_ID . ");", "catalog", "N", 86400, $dateAgent->format('d.m.Y H:i:s'), // date of first check - "Y", // агент активен - $dateAgent->format('d.m.Y H:i:s'), // date of first start - 30 - ); - - CCatalogExport::Update($PROFILE_ID, array( - "IN_CRON" => ($arProfile["IN_AGENT"] == "Y" ? "N" : "Y") - )); - } else { - $agent_period = 24; - $agent_php_path = "/usr/local/php/bin/php"; - - if (!file_exists($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "cron_frame.php")) { - CheckDirPath($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS); - $tmp_file_size = filesize($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS_DEF . "cron_frame.php"); - $fp = fopen($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS_DEF . "cron_frame.php", "rb"); - $tmp_data = fread($fp, $tmp_file_size); - fclose($fp); - - $tmp_data = str_replace("#DOCUMENT_ROOT#", $_SERVER["DOCUMENT_ROOT"], $tmp_data); - $tmp_data = str_replace("#PHP_PATH#", $agent_php_path, $tmp_data); - - $fp = fopen($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "cron_frame.php", "ab"); - fwrite($fp, $tmp_data); - fclose($fp); - } - - $cfg_data = ""; - if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg")) { - $cfg_file_size = filesize($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg"); - $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", "rb"); - $cfg_data = fread($fp, $cfg_file_size); - fclose($fp); - } - - CheckDirPath($_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "logs/"); - - if ($arProfile["IN_CRON"] == "Y") { - // remove - $cfg_data = preg_replace("#^.*?" . preg_quote(CATALOG_PATH2EXPORTS) . "cron_frame.php +" . $PROFILE_ID . " *>.*?$#im", "", $cfg_data); - } else { - $strTime = "0 */" . $agent_period . " * * * "; - if (strlen($cfg_data) > 0) - $cfg_data .= "\n"; - - $cfg_data .= $strTime . $agent_php_path . " -f " . $_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "cron_frame.php " . $PROFILE_ID . " >" . $_SERVER["DOCUMENT_ROOT"] . CATALOG_PATH2EXPORTS . "logs/" . $PROFILE_ID . ".txt\n"; - } - - CCatalogExport::Update($PROFILE_ID, array( - "IN_CRON" => ($arProfile["IN_CRON"] == "Y" ? "N" : "Y") - )); - - CheckDirPath($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/"); - $cfg_data = preg_replace("#[\r\n]{2,}#im", "\n", $cfg_data); - $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", "wb"); - fwrite($fp, $cfg_data); - fclose($fp); - - $arRetval = array(); - @exec("crontab " . $_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", $arRetval, $return_var); - } - } - - //agent - $dateAgent = new DateTime(); - $intAgent = new DateInterval('PT60S'); // PT60S - 60 sec; - $dateAgent->add($intAgent); - - CAgent::AddAgent( - "ICrmOrderActions::uploadOrdersAgent();", - $this->MODULE_ID, - "N", - 600, // interval - 10 mins - $dateAgent->format('d.m.Y H:i:s'), // date of first check - "Y", // агент активен - $dateAgent->format('d.m.Y H:i:s'), // date of first start - 30 - ); - - $this->CopyFiles(); - - // statistic update - $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); - $this->INTARO_CRM_API->statisticUpdate(); - - $APPLICATION->IncludeAdminFile( - GetMessage('MODULE_INSTALL_TITLE'), - $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step5.php' - ); - } - } - - function DoUninstall() { - global $APPLICATION; - - CAgent::RemoveAgent("ICrmOrderActions::uploadOrdersAgent();", $this->MODULE_ID); - - 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); - COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT_TYPES); - COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES); - COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT); - COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_LAST_ID); - - UnRegisterModuleDependences("sale", "OnSalePayOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSalePayOrder"); - UnRegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder"); - - $this->DeleteFiles(); - - UnRegisterModule($this->MODULE_ID); - - $APPLICATION->IncludeAdminFile( - GetMessage('MODULE_UNINSTALL_TITLE'), - $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/unstep1.php' - ); - - } - - function CopyFiles() { - CopyDirFiles( - $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/export/', - $_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/', - true, true - ); - } - - 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 +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'); + $this->PARTNER_NAME = GetMessage('MODULE_PARTNER_NAME'); + $this->PARTNER_URI = GetMessage('MODULE_PARTNER_URI'); + } + + /** + * Functions DoInstall and DoUninstall are + * All other functions are optional + */ + + function DoInstall() + { + global $APPLICATION, $step, $arResult; + + if (!in_array('curl', get_loaded_extensions())) { + $APPLICATION->ThrowException( GetMessage("INTAROCRM_CURL_ERR") ); + return false; + } + + include($this->INSTALL_PATH . '/../classes/general/RestApi.php'); + include($this->INSTALL_PATH . '/../classes/general/ICrmOrderActions.php'); + include($this->INSTALL_PATH . '/../classes/general/ICMLLoader.php'); + + $step = intval($_REQUEST['step']); + + if ($step <= 1) { + if(!CModule::IncludeModule("sale")) { + $arResult['errCode'] = 'ERR_SALE'; + } + + if(!CModule::IncludeModule("iblock")) { + $arResult['errCode'] = 'ERR_IBLOCK'; + } + + if(!CModule::IncludeModule("catalog")) { + $arResult['errCode'] = 'ERR_CATALOG'; + } + + $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")) { + $arResult['errCode'] = 'ERR_SALE'; + } + + if(!CModule::IncludeModule("iblock")) { + $arResult['errCode'] = 'ERR_IBLOCK'; + } + + if(!CModule::IncludeModule("catalog")) { + $arResult['errCode'] = 'ERR_CATALOG'; + } + + if(isset($arResult['errCode']) && $arResult['errCode']) { + $APPLICATION->IncludeAdminFile( + GetMessage('MODULE_INSTALL_TITLE'), + $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php' + ); + 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])); + + // form correct url + $api_host = parse_url($api_host); + $api_host = $api_host['scheme'] . '://' . $api_host['host']; + + 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; + } + + $this->INTARO_CRM_API = new \IntaroCrm\RestApi($api_host, $api_key); + + $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 + $arResult['orderTypesList'] = $this->INTARO_CRM_API->orderTypesList(); + $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() + ); + + 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 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 --statuses + $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' => 'Y', + 'NAME' => GetMessage('CANCELED') + ); + + $APPLICATION->IncludeAdminFile( + GetMessage('MODULE_INSTALL_TITLE'), + $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step2.php' + ); + + } else if ($step == 3) { + if(!CModule::IncludeModule("sale")) { + //handler + } + + if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') + && isset($_POST['ajax']) && ($_POST['ajax'] == 1)) { + ICrmOrderActions::uploadOrders(); // each 50 + + $lastUpOrderId = COption::GetOptionString($this->MODULE_ID, $this->CRM_ORDER_LAST_ID, 0); + $countLeft = (int) CSaleOrder::GetList(array("ID" => "ASC"), array('>ID' => $lastUpOrderId), array()); + $countAll = (int) CSaleOrder::GetList(array("ID" => "ASC"), array(), array()); + + if(!isset($_POST['finish'])) + $finish = 0; + else + $finish = (int) $_POST['finish']; + + $percent = 100 - round(($countLeft * 100 / $countAll), 1); + + if(!$countLeft) + $finish = 1; + + $APPLICATION->RestartBuffer(); + header('Content-Type: application/x-javascript; charset='.LANG_CHARSET); + die(json_encode(array("finish" => $finish, "percent" => $percent))); + } + + if (isset($_POST['back']) && $_POST['back']) { + $APPLICATION->IncludeAdminFile( + GetMessage('MODULE_INSTALL_TITLE'), + $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step1.php' + ); + } + + //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 { + $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 { + $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 { + $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 { + $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'])); + + 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)); + 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' + ); + } else if ($step == 4) { + if(!CModule::IncludeModule("iblock")) { + $arResult['errCode'] = 'ERR_IBLOCK'; + } + + if(!CModule::IncludeModule("catalog")) { + $arResult['errCode'] = 'ERR_CATALOG'; + } + $APPLICATION->IncludeAdminFile( + GetMessage('MODULE_INSTALL_TITLE'), + $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step4.php' + ); + + } else if ($step == 5) { + + if(!CModule::IncludeModule("iblock")) { + $arResult['errCode'] = 'ERR_IBLOCK'; + } + + if(!CModule::IncludeModule("catalog")) { + $arResult['errCode'] = 'ERR_CATALOG'; + } + + if(isset($arResult['errCode']) && $arResult['errCode']) { + $APPLICATION->IncludeAdminFile( + GetMessage('MODULE_INSTALL_TITLE'), + $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step4.php' + ); + return; + } + + if (isset($_POST['back']) && $_POST['back']) { + $APPLICATION->IncludeAdminFile( + GetMessage('MODULE_INSTALL_TITLE'), + $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step3.php' + ); + } + + if(!isset($_POST['IBLOCK_EXPORT'])) + $arResult['errCode'] = 'ERR_FIELDS_IBLOCK'; + else + $iblocks = $_POST['IBLOCK_EXPORT']; + + if(!isset($_POST['IBLOCK_PROPERTY_ARTICLE'])) + $arResult['errCode'] = 'ERR_FIELDS_ARTICLE'; + else + $articleProperties = $_POST['IBLOCK_PROPERTY_ARTICLE']; + + if(!isset($_POST['SETUP_FILE_NAME'])) + $arResult['errCode'] = 'ERR_FIELDS_FILE'; + else + $filename = $_POST['SETUP_FILE_NAME']; + + + if(!isset($_POST['TYPE_LOADING'])) + $typeLoading = 0; + else + $typeLoading = $_POST['TYPE_LOADING']; + + if(!isset($_POST['SETUP_PROFILE_NAME']) ) + $profileName = ""; + else + $profileName = $_POST['SETUP_PROFILE_NAME']; + + if ($typeLoading != 'none' && $profileName == "") + $arResult['errCode'] = 'ERR_FIELDS_PROFILE'; + + if(isset($arResult['errCode']) && $arResult['errCode']) { + $APPLICATION->IncludeAdminFile( + GetMessage('MODULE_INSTALL_TITLE'), + $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step4.php' + ); + return; + } + + RegisterModule($this->MODULE_ID); + RegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder"); + + if (isset($_POST['LOAD_NOW'])) { + + $loader = new ICMLLoader(); + $loader->iblocks = $iblocks; + $loader->articleProperties = $articleProperties; + $loader->filename = $filename; + $loader->application = $APPLICATION; + $loader->Load(); + + } + + if ($typeLoading == 'agent' || $typeLoading == 'cron') { + if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/catalog_export/' . $this->INTARO_CRM_EXPORT . '_run.php')) { + $dbProfile = CCatalogExport::GetList(array(), array("FILE_NAME" => $this->INTARO_CRM_EXPORT)); + + while ($arProfile = $dbProfile->Fetch()) { + if ($arProfile["DEFAULT_PROFILE"]!="Y") + CAgent::RemoveAgent("CCatalogExport::PreGenerateExport(".$arProfile['ID'].");", "catalog"); + } + } + $ar = $this->GetProfileSetupVars($iblocks, $articleProperties, $filename); + $PROFILE_ID = CCatalogExport::Add(array( + "LAST_USE" => false, + "FILE_NAME" => $this->INTARO_CRM_EXPORT, + "NAME" => $profileName, + "DEFAULT_PROFILE" => "N", + "IN_MENU" => "N", + "IN_AGENT" => "N", + "IN_CRON" => "N", + "NEED_EDIT" => "N", + "SETUP_VARS" => $ar + )); + if (intval($PROFILE_ID) <= 0) { + $arResult['errCode'] = 'ERR_IBLOCK'; + return; + } + if ($typeLoading == 'agent') { + + $dateAgent = new DateTime(); + $intAgent = new DateInterval('PT60S'); // PT60S - 60 sec; + $dateAgent->add($intAgent); + CAgent::AddAgent( + "CCatalogExport::PreGenerateExport(" . $PROFILE_ID . ");", + "catalog", + "N", + 86400, + $dateAgent->format('d.m.Y H:i:s'), // date of first check + "Y", // агент активен + $dateAgent->format('d.m.Y H:i:s'), // date of first start + 30 + ); + + CCatalogExport::Update($PROFILE_ID, array( + "IN_CRON" => ($arProfile["IN_AGENT"]=="Y" ? "N" : "Y") + )); + } else { + $agent_period = 24; + $agent_php_path = "/usr/local/php/bin/php"; + + if (!file_exists($_SERVER["DOCUMENT_ROOT"].CATALOG_PATH2EXPORTS."cron_frame.php")) + { + CheckDirPath($_SERVER["DOCUMENT_ROOT"].CATALOG_PATH2EXPORTS); + $tmp_file_size = filesize($_SERVER["DOCUMENT_ROOT"].CATALOG_PATH2EXPORTS_DEF."cron_frame.php"); + $fp = fopen($_SERVER["DOCUMENT_ROOT"].CATALOG_PATH2EXPORTS_DEF."cron_frame.php", "rb"); + $tmp_data = fread($fp, $tmp_file_size); + fclose($fp); + + $tmp_data = str_replace("#DOCUMENT_ROOT#", $_SERVER["DOCUMENT_ROOT"], $tmp_data); + $tmp_data = str_replace("#PHP_PATH#", $agent_php_path, $tmp_data); + + $fp = fopen($_SERVER["DOCUMENT_ROOT"].CATALOG_PATH2EXPORTS."cron_frame.php", "ab"); + fwrite($fp, $tmp_data); + fclose($fp); + } + + $cfg_data = ""; + if (file_exists($_SERVER["DOCUMENT_ROOT"]."/bitrix/crontab/crontab.cfg")) + { + $cfg_file_size = filesize($_SERVER["DOCUMENT_ROOT"]."/bitrix/crontab/crontab.cfg"); + $fp = fopen($_SERVER["DOCUMENT_ROOT"]."/bitrix/crontab/crontab.cfg", "rb"); + $cfg_data = fread($fp, $cfg_file_size); + fclose($fp); + } + + CheckDirPath($_SERVER["DOCUMENT_ROOT"].CATALOG_PATH2EXPORTS."logs/"); + + if ($arProfile["IN_CRON"]=="Y") + { + // remove + $cfg_data = preg_replace("#^.*?".preg_quote(CATALOG_PATH2EXPORTS)."cron_frame.php +".$PROFILE_ID." *>.*?$#im", "", $cfg_data); + } + else + { + $strTime = "0 */".$agent_period." * * * "; + if (strlen($cfg_data)>0) + $cfg_data .= "\n"; + + $cfg_data .= $strTime.$agent_php_path." -f ".$_SERVER["DOCUMENT_ROOT"].CATALOG_PATH2EXPORTS."cron_frame.php ".$PROFILE_ID." >".$_SERVER["DOCUMENT_ROOT"].CATALOG_PATH2EXPORTS."logs/".$PROFILE_ID.".txt\n"; + } + + CCatalogExport::Update($PROFILE_ID, array( + "IN_CRON" => ($arProfile["IN_CRON"]=="Y" ? "N" : "Y") + )); + + CheckDirPath($_SERVER["DOCUMENT_ROOT"]."/bitrix/crontab/"); + $cfg_data = preg_replace("#[\r\n]{2,}#im", "\n", $cfg_data); + $fp = fopen($_SERVER["DOCUMENT_ROOT"]."/bitrix/crontab/crontab.cfg", "wb"); + fwrite($fp, $cfg_data); + fclose($fp); + + $arRetval = array(); + @exec("crontab ".$_SERVER["DOCUMENT_ROOT"]."/bitrix/crontab/crontab.cfg", $arRetval, $return_var); + + } + } + + // + + //agent + + $dateAgent = new DateTime(); + $intAgent = new DateInterval('PT60S'); // PT60S - 60 sec; + $dateAgent->add($intAgent); + + CAgent::AddAgent( + "ICrmOrderActions::uploadOrdersAgent();", + $this->MODULE_ID, + "N", + 600, // interval - 10 mins + $dateAgent->format('d.m.Y H:i:s'), // date of first check + "Y", // агент активен + $dateAgent->format('d.m.Y H:i:s'), // date of first start + 30 + ); + + $this->CopyFiles(); + + $APPLICATION->IncludeAdminFile( + GetMessage('MODULE_INSTALL_TITLE'), + $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/step5.php' + ); + } + } + + function DoUninstall() { + global $APPLICATION; + + CAgent::RemoveAgent("ICrmOrderActions::uploadOrdersAgent();", $this->MODULE_ID); + + 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); + COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT_TYPES); + COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT_STATUSES); + COption::RemoveOption($this->MODULE_ID, $this->CRM_PAYMENT); + COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_LAST_ID); + + UnRegisterModuleDependences("sale", "OnSalePayOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSalePayOrder"); + UnRegisterModuleDependences("sale", "OnSaleCancelOrder", $this->MODULE_ID, "ICrmOrderEvent", "onSaleCancelOrder"); + + $this->DeleteFiles(); + + UnRegisterModule($this->MODULE_ID); + + $APPLICATION->IncludeAdminFile( + GetMessage('MODULE_UNINSTALL_TITLE'), + $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/unstep1.php' + ); + + } + + function CopyFiles() { + CopyDirFiles( + $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . $this->MODULE_ID . '/install/export/', + $_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/include/catalog_export/', + true, true + ); + } + + 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'); + } +} diff --git a/intaro.intarocrm/install/step4.php b/intaro.intarocrm/install/step4.php index 81178e93..50f0ae17 100644 --- a/intaro.intarocrm/install/step4.php +++ b/intaro.intarocrm/install/step4.php @@ -4,6 +4,8 @@ if(!check_bitrix_sessid()) return; IncludeModuleLangFile(__FILE__); __IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.intarocrm/lang/", "/icml_export_setup.php")); +if(isset($arResult['errCode']) && $arResult['errCode']) + echo CAdminMessage::ShowMessage(GetMessage($arResult['errCode'])); ?>


@@ -53,8 +55,8 @@ __IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro. } } } - if ($intCountChecked == $intCountAvailIBlock) - $boolAll = true; + $intCountChecked = $intCountAvailIBlock; + $boolAll = true; ?> @@ -100,6 +102,7 @@ __IncludeLang(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/intaro.

-
+

-
+


  - +


-