123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <?php
- class FacturisSync
- {
- public $language;
- public $db;
- public function __construct($db) {
- $this->language = $this->getLanguage();
- $this->db = $db;
- }
-
- private function getLanguage()
- {
- $language = new Core\Language\English();
- return $language;
- }
- public function showMenu()
- {
- $result = $this->downloadLog();
- if(empty($result))
- {
- $result = $this->clearLog();
- }
- if(empty($result))
- {
- $result = $this->saveOptions();
- }
- if(empty($result))
- {
- $result = $this->sync();
- }
-
- $this->getForm($this->db, $result);
- }
- function testAuth(){
- try{
- $formController = new \Controller\FormController();
- $formController->testAuth($this->db);
- \Core\Log\FileLog::write($this->language->get('success_test_auth'), \Core\Log\FileLog::INFO);
- echo '';exit;
- }
- catch(\Exception $e) {
- \Core\Log\FileLog::write($e->getMessage(), \Core\Log\FileLog::ERROR);
- echo $e->getMessage();exit;
- }
- }
- function getPdlGestiuni()
- {
- try{
- $formController = new \Controller\FormController();
- $result = $formController->getPdlGestiuni($this->db, $this->language);
- echo $result;exit;
- }
- catch(\Exception $e) {
- \Core\Log\FileLog::write($e->getMessage(), \Core\Log\FileLog::ERROR);
- echo '';exit;
- }
- }
- function checkLatestVersion()
- {
- try{
- $formController = new \Controller\FormController();
- $result = $formController->checkLatestVersion($this->db, $this->language);
- echo $result;exit;
- }
- catch(\Exception $e) {
- \Core\Log\FileLog::write($e->getMessage(), \Core\Log\FileLog::ERROR);
- echo '';exit;
- }
- }
- public function sync()
- {
- try{
- $syncController = new \Controller\SyncController($this->db, $this->language);
- $result = $syncController->sync();
- if(!empty($result))
- {
- \Core\Log\FileLog::write($result, \Core\Log\FileLog::INFO);
- }
-
- return array('success' => $result);
- }
- catch(\Exception $e) {
- $message = $this->language->get($e->getMessage());
- \Core\Log\FileLog::write($message, \Core\Log\FileLog::ERROR);
- return array('error' => $message);
- }
- }
- private function getForm($db, $result)
- {
- try{
- extract($result);
- $formController = new \Controller\FormController();
- $data = $formController->getForm($db, $this->language);
- extract($data);
-
- include('View/main.php');
- }
- catch(\Exception $e) {
- $message = $e->getMessage();
- \Core\Log\FileLog::write($message, \Core\Log\FileLog::ERROR);
- echo $message;
- }
- }
- function autoSync() {
- try{
- $shops = $this->db->getAll();
- if(!empty($shops))
- {
- foreach($shops as $shop)
- {
- if(isset($shop['market_code']))
- {
- try{
- $controller = new \Controller\SyncController($this->db, $this->language, $shop['market_code']);
- $result = $controller->autoSync();
- $message = 'Shop OK: ' . $shop['market_code'];
- echo $message . PHP_EOL;
- \Core\Log\FileLog::write($message, \Core\Log\FileLog::INFO);
- }
- catch(\Exception $e) {
- $messsage = 'Err shop: ' . $shop['market_code'] . ': ' . $this->language->get($e->getMessage());
- \Core\Log\FileLog::write($messsage, \Core\Log\FileLog::ERROR);
- echo $messsage . PHP_EOL;
- }
- }
- }
- }
- }
- catch(\Exception $e) {
- $messsage = 'Err cron: ' . $this->language->get($e->getMessage());
- \Core\Log\FileLog::write($messsage, \Core\Log\FileLog::ERROR);
- echo $messsage . PHP_EOL;
- }
- }
-
- public function downloadLog()
- {
- try{
- if(isset($_REQUEST['action']) && ($_REQUEST['action'] == 'downloadLog'))
- {
- $header = array(
- $this->language->get('log_header_date'),
- $this->language->get('log_header_type'),
- $this->language->get('log_header_description')
- );
-
- $logController = new \Controller\LogController();
- $logController->downloadFileLog(
- isset($_REQUEST['start']) ? $_REQUEST['start'] : date('d.m.Y H:i:s'),
- isset($_REQUEST['end']) ? $_REQUEST['end'] : date('d.m.Y H:i:s'),
- $header
- );
- return array('success' => $this->language->get('success_download_log'));
- }
- else
- {
- return array();
- }
- }
- catch(\Exception $e) {
- $message = $this->language->get('error_download_log');
- \Core\Log\FileLog::write($message, \Core\Log\FileLog::ERROR);
- return array('error' => $message);
- }
- }
- public function clearLog()
- {
- try{
- if(isset($_REQUEST['action']) && ($_REQUEST['action'] == 'clearLog'))
- {
- $result = null;
- $logController = new \Controller\LogController();
- $logController->clearFileLog();
- return array('success' => $this->language->get('success_clear_log'));
- }
- else
- {
- return array();
- }
- }
- catch(\Exception $e) {
- $message = $this->language->get('error_clear_log');
- \Core\Log\FileLog::write($message, \Core\Log\FileLog::ERROR);
- return array('error' => $message);
- }
- }
- public function saveOptions()
- {
- try{
- if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'save')
- {
- $this->db->saveOptions();
- $message = $this->language->get('success_save_data');
- \Core\Log\FileLog::write($message, \Core\Log\FileLog::INFO);
- return array('success' => $message);
- }
- else
- {
- return array();
- }
- }
- catch(\Exception $e) {
- $message = $this->language->get($e->getMessage());
- \Core\Log\FileLog::write($message, \Core\Log\FileLog::ERROR);
- return array('error' => $message);
- }
- }
-
- }
|