/**
  * Update and save the current configuration
  * @param $result
  * @return mixed
  */
 public function saveSettings($result)
 {
     if (!isset($this->name)) {
         $result['error'] = "A config-set name must be supplied";
         return $result;
     }
     $this->configMdl = new ConfigModel();
     $config = $this->configMdl->get($this->name);
     if ($config !== false) {
         if (sizeof($config) > 0) {
             $this->curconfig = json_decode($config[0]['data']);
             // get the json object
             $configbk = $this->curconfig;
             if (isset($this->data->gcontactcode) && $this->data->gcontactcode != '') {
                 // Get google access token
                 $tokens = GoogleIntegration::processGoogleAuthCode($this->data->gcontactcode);
                 if ($tokens) {
                     $tokens = json_decode($tokens);
                     $this->data->gcontacttoken = $tokens;
                     $this->data->gcontact = 1;
                 }
                 unset($this->data->gcontactcode);
             }
             // generate new qr code
             if ($this->name == "pos") {
                 if ($this->data->recqrcode !== $configbk->recqrcode && $this->data->recqrcode != "") {
                     $this->generateQRCode();
                 }
             }
             foreach ($this->curconfig as $key => $value) {
                 if (isset($this->data->{$key})) {
                     // update the config value if specified in the data
                     $this->curconfig->{$key} = $this->data->{$key};
                 }
             }
             if ($this->configMdl->edit($this->name, json_encode($this->curconfig)) === false) {
                 $result['error'] = "Could not update config record: " . $this->configMdl->errorInfo;
             } else {
                 $conf = $this->curconfig;
                 if ($this->name == "general") {
                     unset($conf->gcontacttoken);
                     $conf->timezone = $this->data->timezone;
                     if ($conf->timezone != getenv("WPOS_TIMEZONE")) {
                         $this->updateConfigFileValue('timezone', $conf->timezone);
                     }
                 } else {
                     if ($this->name == "accounting") {
                         unset($conf->xerotoken);
                     }
                 }
                 // send config update to POS terminals
                 $socket = new WposSocketIO();
                 $socket->sendConfigUpdate($conf, $this->name);
                 // Success; log data
                 Logger::write("System configuration updated:" . $this->name, "CONFIG", json_encode($conf));
             }
         } else {
             // if current settings are null, create a new record with the specified name
             if ($this->configMdl->create($this->name, json_encode($this->data)) === false) {
                 $result['error'] = "Could not insert new config record: " . $this->configMdl->errorInfo;
             }
         }
     } else {
         $result['error'] = "Could not retrieve the selected config record: " . $this->configMdl->errorInfo;
     }
     return $result;
 }
Example #2
0
 private function broadcastTaxUpdate()
 {
     $taxconfig = WposPosData::getTaxes();
     if (!isset($taxconfig['error'])) {
         $socket = new WposSocketIO();
         $socket->sendConfigUpdate($taxconfig['data'], "tax");
     }
 }