From da1735f3c8762cee01e535ed555e092656bfc57a Mon Sep 17 00:00:00 2001 From: xia0ta0 Date: Tue, 3 Sep 2013 14:25:20 +0800 Subject: [PATCH] * reset setCompany. --- module/common/control.php | 1 + module/common/model.php | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/module/common/control.php b/module/common/control.php index 8b8f132cc2..87386cdc45 100644 --- a/module/common/control.php +++ b/module/common/control.php @@ -22,6 +22,7 @@ class common extends control parent::__construct(); $this->common->startSession(); $this->common->sendHeader(); + $this->common->setCompany(); $this->common->setUser(); $this->common->loadConfigFromDB(); $this->common->loadCustomFromDB(); diff --git a/module/common/model.php b/module/common/model.php index a61ef445c6..2ce01a9975 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -36,6 +36,31 @@ class commonModel extends model header("Cache-control: private"); } + /** + * Set the commpany. + * + * First, search company by the http host. If not found, search by the default domain. Last, use the first as the default. + * After get the company, save it to session. + * @access public + * @return void + */ + public function setCompany() + { + $httpHost = $this->server->http_host; + + if($this->session->company) + { + $this->app->company = $this->session->company; + } + else + { + $company = $this->loadModel('company')->getFirst(); + if(!$company) $this->app->triggerError(sprintf($this->lang->error->companyNotFound, $httpHost), __FILE__, __LINE__, $exit = true); + $this->session->set('company', $company); + $this->app->company = $company; + } + } + /** * Set the user info. *