static function getDebugOption() { $debugoption = DebugOption::getUserOption(EGS_USERNAME); if (!$debugoption->isLoaded()) { $debugoption = DebugOption::getCompanyOption(EGS_COMPANY_ID); } return $debugoption; }
public function save() { if (!$this->CheckParams($this->modeltype)) { sendBack(); } $this->loadData(); $systemcompany = $this->_uses[$this->modeltype]; $db = DB::Instance(); $db->StartTrans(); $errors = array(); $flash = Flash::Instance(); $data = $this->_data[$this->modeltype]; if (!isset($data['id']) || empty($data['id'])) { $company = DataObject::Factory($data, $errors, 'Company'); if (count($errors) > 0 || !$company->save()) { $errors[] = 'Failed to create Company'; $db->FailTrans(); } else { $data['company_id'] = $company->id; } } if (isset($data['debug_options']) && isset($data['id'])) { $debug = DebugOption::getCompanyOption($data['id']); if (isset($data['debug_enabled'])) { $data['DebugOption']['company_id'] = $data['id']; $data['DebugOption']['options'] = $debug->setOptions($data['debug_options']); } else { if ($debug->isLoaded()) { $debug->delete(); } unset($data['DebugOption']); } } else { unset($data['DebugOption']); } if (isset($data['delete_logo'])) { if ($this->delete_logo($systemcompany->logo_file_id, $errors)) { $data['logo_file_id'] = NULL; } else { $errors[] = 'Error deleting Logo image'; } } if (!empty($_FILES['file']['name'])) { // Need to upload file before checking $file = File::Factory($_FILES['file'], $errors, DataObjectFactory::Factory('File')); if ($file->save()) { if (!is_null($systemcompany->logo_file_id)) { $old_file = DataObjectFactory::Factory('File'); if (!$this->delete_logo($systemcompany->logo_file_id, $errors)) { $errors[] = 'Error replacing Logo image'; } } $data['logo_file_id'] = $file->id; } else { $errors[] = 'Error loading Logo image'; } } if (count($errors) == 0) { if (!parent::save($this->modeltype, $data, $errors)) { $errors[] = 'Failed to save System Company'; $db->FailTrans(); } } if (count($errors) == 0) { $result = $this->saved_model->setPermissions($this->_data['Permission'], $errors); if ($result === FALSE) { $errors[] = 'Failed to save System Company Permissions'; $db->FailTrans(); } } $db->CompleteTrans(); if (count($errors) > 0) { $flash->addErrors($errors); if (isset($data['id'])) { $this->_data['id'] = $data['id']; } $this->refresh(); } else { sendTo($this->name, 'index', $this->_modules); } }