FormController.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. namespace Controller;
  3. class FormController
  4. {
  5. public function getForm($db, $language)
  6. {
  7. $data = array();
  8. $settingsRepository = new \MarketplaceRepository\SettingsRepository($db);
  9. $settingsService = new \Core\App\Service\SettingsService(
  10. $settingsRepository
  11. );
  12. $data['title'] = $language->get('title');
  13. $data['description'] = $language->get('description');
  14. //tab1
  15. $data['tab_name_1'] = $language->get('tab_name_1');
  16. $data['tab_description_1'] = $language->get('tab_description_1');
  17. $dataTypes = $settingsService->getSyncDataTypes();
  18. $data['dataTypes'] = array(array('id' => '', 'label' => $language->get('data_type')));
  19. if(!empty($dataTypes))
  20. {
  21. foreach($dataTypes as $dataType)
  22. {
  23. $data['dataTypes'][] = array('id' => $dataType, 'label' => $language->get($dataType));
  24. }
  25. }
  26. sort($data['dataTypes']);
  27. $data['sync_btn'] = $language->get('sync_btn');
  28. $data['download_btn'] = $language->get('download_btn');
  29. $data['clear_btn'] = $language->get('clear_btn');
  30. $data['datatype_error'] = $language->get('datatype_error');
  31. $data['authform_error'] = $language->get('authform_error');
  32. $data['sync_please_wait'] = $language->get('sync_please_wait');
  33. $data['download_log_error_1'] = $language->get('download_log_error_1');
  34. $data['download_log_error_2'] = $language->get('download_log_error_2');
  35. $data['select_text'] = $language->get('select_text');
  36. //tab 2
  37. $data['tab_name_2'] = $language->get('tab_name_2');
  38. $data['tab_description_2'] = $language->get('tab_description_2');
  39. $data['auth_apikey'] = $language->get('auth_api_key');
  40. $data['auth_username'] = $language->get('auth_username');
  41. $data['auth_password'] = $language->get('auth_password');
  42. $data['auth_fiscalcode'] = $language->get('auth_fiscal_code');
  43. $data['auth_apikey_error'] = $language->get('auth_apikey_error');
  44. $data['auth_username_error'] = $language->get('auth_username_error');
  45. $data['auth_password_error'] = $language->get('auth_password_error');
  46. $data['auth_fiscalcode_error'] = $language->get('auth_fiscalcode_error');
  47. $data['save_btn'] = $language->get('save_btn');
  48. //tab 3
  49. $data['tab_name_3'] = $language->get('tab_name_3');
  50. $data['tab_name_3_1'] = $language->get('tab_name_3_1');
  51. $data['tab_name_3_2'] = $language->get('tab_name_3_2');
  52. $data['with_discount'] = $language->get('with_discount');
  53. $data['with_discount_desc'] = $language->get('with_discount_desc');
  54. //tab4
  55. $data['tab_name_4'] = $language->get('tab_name_4');
  56. //tab 5
  57. $data['tab_name_5'] = $language->get('tab_name_5');
  58. $data['datepicker'] = $language->get('datepicker');
  59. $data['tab_description_5_1'] = $language->get('tab_description_5_1');
  60. $data['tab_description_5_2'] = $language->get('tab_description_5_2');
  61. $data['confirm_clear_log'] = $language->get('confirm_clear_log');
  62. $syncOrdersAs = $settingsService->getSyncOrdersAs();
  63. $data['syncOrdersAs'] = array();
  64. if(!empty($syncOrdersAs))
  65. {
  66. foreach($syncOrdersAs as $syncOrdersAsElement)
  67. {
  68. $data['syncOrdersAs'][] = array('id' => $syncOrdersAsElement, 'label' => $language->get($syncOrdersAsElement));
  69. }
  70. }
  71. $data['sync_orders_as'] = $language->get('sync_orders_as');
  72. $data['proforma_series'] = $language->get('proforma_series');
  73. $data['days_ago'] = $language->get('days_ago');
  74. $data['auto_order_sync'] = $language->get('auto_order_sync');
  75. $data['auto_stock_sync'] = $language->get('auto_stock_sync');
  76. $autoSyncOptions = $settingsService->getAutoSyncOptions();
  77. $data['autoSyncOptions'] = array();
  78. if(!empty($autoSyncOptions))
  79. {
  80. foreach($autoSyncOptions as $autoSyncOptionsElement)
  81. {
  82. $data['autoSyncOptions'][] = array('id' => $autoSyncOptionsElement, 'label' => $language->get($autoSyncOptionsElement));
  83. }
  84. }
  85. $data['shopLocations'] = $this->getShopLocations($settingsRepository);
  86. $data['locations'] = $language->get('locations');
  87. $enabledDisabledOptions = $settingsService->getEnabledDisabledOptions();
  88. $data['withDiscountOptions'] = array();
  89. if(!empty($enabledDisabledOptions))
  90. {
  91. foreach($enabledDisabledOptions as $enabledDisabledOption)
  92. {
  93. $data['withDiscountOptions'][] = array('id' => $enabledDisabledOption, 'label' => $language->get($enabledDisabledOption));
  94. }
  95. }
  96. $data['filter_stock'] = $language->get('filter_stock');
  97. $data['loading_data_please_wait'] = $language->get('loading_data_please_wait');
  98. $data['option_proformaserie_error'] = $language->get('option_proformaserie_error');
  99. $data['option_daysago_error'] = $language->get('option_daysago_error');
  100. $data['version_text'] = $language->get('version_text');
  101. $data['option'] = $settingsService->getOptions();
  102. $data['auth'] = $settingsService->getAuth();
  103. $data['version_number'] = $settingsService->getVersion();
  104. $data['version_link'] = $settingsService->getVersionLink();
  105. $data['check_latest_version'] = $language->get('check_latest_version');
  106. //tutorials
  107. $data['tutorial_title'] = $language->get('tutorial_title');
  108. $data['tutorial_p'] = $language->get('tutorial_p');
  109. $data['tutorial_1'] = $language->get('tutorial_1');
  110. $data['tutorial_2'] = $language->get('tutorial_2');
  111. $data['tutorial_3'] = $language->get('tutorial_3');
  112. $data['tutorial_4'] = $language->get('tutorial_4');
  113. $data['show_tutorial'] = $settingsService->showTutorial();
  114. $data['authform_error'] = $language->get('authform_error');
  115. return $data;
  116. }
  117. public function testAuth($db)
  118. {
  119. $this->settingsRepository = new \MarketplaceRepository\SettingsRepository($db);
  120. $settingsService = new \Core\App\Service\SettingsService(
  121. $this->settingsRepository
  122. );
  123. $remoteStockRepository = new \Core\FacturisRepository\StockRepository(
  124. $_GET['fsync_auth_apikey'],
  125. $_GET['fsync_auth_username'],
  126. $_GET['fsync_auth_password'],
  127. $_GET['fsync_auth_fiscalcode']
  128. );
  129. $settingsService->testAuth($remoteStockRepository);
  130. }
  131. public function getPdlGestiuni($db, $language)
  132. {
  133. $settingsRepository = new \MarketplaceRepository\SettingsRepository($db);
  134. $settingsService = new \Core\App\Service\SettingsService(
  135. $settingsRepository
  136. );
  137. $remoteStockRepository = new \Core\FacturisRepository\StockRepository(
  138. $settingsRepository->getAuthApiKey(),
  139. $settingsRepository->getAuthUsername(),
  140. $settingsRepository->getAuthPassword(),
  141. $settingsRepository->getAuthFiscalCode()
  142. );
  143. $pdl_gestiuni = $settingsService->getPdlGestiuni($remoteStockRepository);
  144. $result = '';
  145. $result .= '<option value=""';
  146. $result .= (isset($_GET['fsync_option_filterstock']) && $_GET['fsync_option_filterstock'] == '') ? ' selected="selected" ' : '';
  147. $result .= ' >' . $language->get('filter_stock_all') . '</option>';
  148. if(!empty($pdl_gestiuni))
  149. {
  150. foreach($pdl_gestiuni as $pdl_gestiune)
  151. {
  152. $result .= '<option value=' . $pdl_gestiune['id'] . ' ';
  153. $result .= (isset($_GET['fsync_option_filterstock']) && $_GET['fsync_option_filterstock'] == $pdl_gestiune['id']) ? ' selected="selected" ' : '';
  154. $result .= ' >' . $pdl_gestiune['name'] . '</option>';
  155. }
  156. }
  157. echo $result;
  158. }
  159. public function checkLatestVersion($db, $language)
  160. {
  161. $settingsRepository = new \MarketplaceRepository\SettingsRepository($db);
  162. $settingsService = new \Core\App\Service\SettingsService(
  163. $settingsRepository
  164. );
  165. $settingsService->checkLatestVersion($language);
  166. }
  167. private function getShopLocations($settingsRepository)
  168. {
  169. $marketplaceStockRepository = new \MarketplaceRepository\StockRepository(
  170. $settingsRepository->getToken(),
  171. $settingsRepository->getShop()
  172. );
  173. return $marketplaceStockRepository->getShopLocations();
  174. }
  175. }