/** * Edit Company Info * * @param void * @return null */ function edit() { if ($this->active_company->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $this->wireframe->print_button = false; if ($this->request->isApiCall() && !$this->request->isSubmitted()) { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if if (!$this->active_company->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if if ($this->active_company->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $options = array('office_address', 'office_phone', 'office_fax', 'office_homepage'); $company_data = $this->request->post('company'); if (!is_array($company_data)) { $company_data = array_merge(array('name' => $this->active_company->getName()), CompanyConfigOptions::getValues($options, $this->active_company)); } // if $this->smarty->assign('company_data', $company_data); if ($this->request->isSubmitted()) { db_begin_work(); $old_name = $this->active_company->getName(); $this->active_company->setAttributes($company_data); $save = $this->active_company->save(); if ($save && !is_error($save)) { foreach ($options as $option) { $value = trim(array_var($company_data, $option)); if ($option == 'office_homepage' && $value && strpos($value, '://') === false) { $value = 'http://' . $value; } // if if ($value == '') { CompanyConfigOptions::removeValue($option, $this->active_company); } else { CompanyConfigOptions::setValue($option, $value, $this->active_company); } // if } // foreach if ($this->active_company->getIsOwner()) { cache_remove('owner_company'); // force cache refresh on next load } // if db_commit(); if ($this->request->getFormat() == FORMAT_HTML) { flash_success("Company :name has been updated", array('name' => $old_name)); $this->redirectToUrl($this->active_company->getViewUrl()); } else { $this->serveData($this->active_company, 'company'); } // if } else { db_rollback(); if ($this->request->getFormat() == FORMAT_HTML) { $this->smarty->assign('errors', $save); } else { $this->serveData($save); } // if } // if } // if }