123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <?php
- namespace Controller;
- class FormController
- {
- public function getForm($db, $language)
- {
- $data = array();
- $settingsRepository = new \MarketplaceRepository\SettingsRepository($db);
-
- $settingsService = new \Core\App\Service\SettingsService(
- $settingsRepository
- );
-
- $data['title'] = $language->get('title');
- $data['description'] = $language->get('description');
- //tab1
- $data['tab_name_1'] = $language->get('tab_name_1');
- $data['tab_description_1'] = $language->get('tab_description_1');
- $dataTypes = $settingsService->getSyncDataTypes();
- $data['dataTypes'] = array(array('id' => '', 'label' => $language->get('data_type')));
- if(!empty($dataTypes))
- {
- foreach($dataTypes as $dataType)
- {
- $data['dataTypes'][] = array('id' => $dataType, 'label' => $language->get($dataType));
- }
- }
- sort($data['dataTypes']);
- $data['sync_btn'] = $language->get('sync_btn');
- $data['download_btn'] = $language->get('download_btn');
- $data['clear_btn'] = $language->get('clear_btn');
- $data['datatype_error'] = $language->get('datatype_error');
- $data['authform_error'] = $language->get('authform_error');
- $data['sync_please_wait'] = $language->get('sync_please_wait');
- $data['download_log_error_1'] = $language->get('download_log_error_1');
- $data['download_log_error_2'] = $language->get('download_log_error_2');
-
- $data['select_text'] = $language->get('select_text');
-
- //tab 2
- $data['tab_name_2'] = $language->get('tab_name_2');
- $data['tab_description_2'] = $language->get('tab_description_2');
- $data['auth_apikey'] = $language->get('auth_api_key');
- $data['auth_username'] = $language->get('auth_username');
- $data['auth_password'] = $language->get('auth_password');
- $data['auth_fiscalcode'] = $language->get('auth_fiscal_code');
- $data['auth_apikey_error'] = $language->get('auth_apikey_error');
- $data['auth_username_error'] = $language->get('auth_username_error');
- $data['auth_password_error'] = $language->get('auth_password_error');
- $data['auth_fiscalcode_error'] = $language->get('auth_fiscalcode_error');
- $data['save_btn'] = $language->get('save_btn');
- //tab 3
- $data['tab_name_3'] = $language->get('tab_name_3');
- $data['tab_name_3_1'] = $language->get('tab_name_3_1');
- $data['tab_name_3_2'] = $language->get('tab_name_3_2');
- $data['with_discount'] = $language->get('with_discount');
- $data['with_discount_desc'] = $language->get('with_discount_desc');
- //tab4
- $data['tab_name_4'] = $language->get('tab_name_4');
- //tab 5
- $data['tab_name_5'] = $language->get('tab_name_5');
- $data['datepicker'] = $language->get('datepicker');
- $data['tab_description_5_1'] = $language->get('tab_description_5_1');
- $data['tab_description_5_2'] = $language->get('tab_description_5_2');
- $data['confirm_clear_log'] = $language->get('confirm_clear_log');
- $syncOrdersAs = $settingsService->getSyncOrdersAs();
- $data['syncOrdersAs'] = array();
- if(!empty($syncOrdersAs))
- {
- foreach($syncOrdersAs as $syncOrdersAsElement)
- {
- $data['syncOrdersAs'][] = array('id' => $syncOrdersAsElement, 'label' => $language->get($syncOrdersAsElement));
- }
- }
- $data['sync_orders_as'] = $language->get('sync_orders_as');
- $data['proforma_series'] = $language->get('proforma_series');
- $data['days_ago'] = $language->get('days_ago');
- $data['auto_order_sync'] = $language->get('auto_order_sync');
- $data['auto_stock_sync'] = $language->get('auto_stock_sync');
- $autoSyncOptions = $settingsService->getAutoSyncOptions();
- $data['autoSyncOptions'] = array();
- if(!empty($autoSyncOptions))
- {
- foreach($autoSyncOptions as $autoSyncOptionsElement)
- {
- $data['autoSyncOptions'][] = array('id' => $autoSyncOptionsElement, 'label' => $language->get($autoSyncOptionsElement));
- }
- }
- $data['shopLocations'] = $this->getShopLocations($settingsRepository);
- $data['locations'] = $language->get('locations');
-
- $enabledDisabledOptions = $settingsService->getEnabledDisabledOptions();
- $data['withDiscountOptions'] = array();
- if(!empty($enabledDisabledOptions))
- {
- foreach($enabledDisabledOptions as $enabledDisabledOption)
- {
- $data['withDiscountOptions'][] = array('id' => $enabledDisabledOption, 'label' => $language->get($enabledDisabledOption));
- }
- }
- $data['filter_stock'] = $language->get('filter_stock');
- $data['loading_data_please_wait'] = $language->get('loading_data_please_wait');
- $data['option_proformaserie_error'] = $language->get('option_proformaserie_error');
- $data['option_daysago_error'] = $language->get('option_daysago_error');
- $data['version_text'] = $language->get('version_text');
-
- $data['option'] = $settingsService->getOptions();
-
- $data['auth'] = $settingsService->getAuth();
- $data['version_number'] = $settingsService->getVersion();
- $data['version_link'] = $settingsService->getVersionLink();
- $data['check_latest_version'] = $language->get('check_latest_version');
-
- //tutorials
- $data['tutorial_title'] = $language->get('tutorial_title');
- $data['tutorial_p'] = $language->get('tutorial_p');
- $data['tutorial_1'] = $language->get('tutorial_1');
- $data['tutorial_2'] = $language->get('tutorial_2');
- $data['tutorial_3'] = $language->get('tutorial_3');
- $data['tutorial_4'] = $language->get('tutorial_4');
- $data['show_tutorial'] = $settingsService->showTutorial();
- $data['authform_error'] = $language->get('authform_error');
-
-
- return $data;
-
- }
- public function testAuth($db)
- {
- $this->settingsRepository = new \MarketplaceRepository\SettingsRepository($db);
- $settingsService = new \Core\App\Service\SettingsService(
- $this->settingsRepository
- );
- $remoteStockRepository = new \Core\FacturisRepository\StockRepository(
- $_GET['fsync_auth_apikey'],
- $_GET['fsync_auth_username'],
- $_GET['fsync_auth_password'],
- $_GET['fsync_auth_fiscalcode']
- );
- $settingsService->testAuth($remoteStockRepository);
- }
- public function getPdlGestiuni($db, $language)
- {
- $settingsRepository = new \MarketplaceRepository\SettingsRepository($db);
- $settingsService = new \Core\App\Service\SettingsService(
- $settingsRepository
- );
-
- $remoteStockRepository = new \Core\FacturisRepository\StockRepository(
- $settingsRepository->getAuthApiKey(),
- $settingsRepository->getAuthUsername(),
- $settingsRepository->getAuthPassword(),
- $settingsRepository->getAuthFiscalCode()
- );
-
- $pdl_gestiuni = $settingsService->getPdlGestiuni($remoteStockRepository);
-
- $result = '';
- $result .= '<option value=""';
- $result .= (isset($_GET['fsync_option_filterstock']) && $_GET['fsync_option_filterstock'] == '') ? ' selected="selected" ' : '';
- $result .= ' >' . $language->get('filter_stock_all') . '</option>';
- if(!empty($pdl_gestiuni))
- {
- foreach($pdl_gestiuni as $pdl_gestiune)
- {
- $result .= '<option value=' . $pdl_gestiune['id'] . ' ';
- $result .= (isset($_GET['fsync_option_filterstock']) && $_GET['fsync_option_filterstock'] == $pdl_gestiune['id']) ? ' selected="selected" ' : '';
- $result .= ' >' . $pdl_gestiune['name'] . '</option>';
- }
- }
- echo $result;
- }
- public function checkLatestVersion($db, $language)
- {
- $settingsRepository = new \MarketplaceRepository\SettingsRepository($db);
- $settingsService = new \Core\App\Service\SettingsService(
- $settingsRepository
- );
- $settingsService->checkLatestVersion($language);
- }
- private function getShopLocations($settingsRepository)
- {
- $marketplaceStockRepository = new \MarketplaceRepository\StockRepository(
- $settingsRepository->getToken(),
- $settingsRepository->getShop()
- );
-
- return $marketplaceStockRepository->getShopLocations();
- }
- }
|