Пример #1
0
 /**
  * Validation - Check if entry type is valid
  */
 public function validEntrytype($data)
 {
     $values = array_values($data);
     if (!isset($values)) {
         return false;
     }
     $value = $values[0];
     /* Load the Entrytype model */
     App::import("Webzash.Model", "Entrytype");
     $Entrytype = new Entrytype();
     if ($Entrytype->exists($value)) {
         return true;
     } else {
         return false;
     }
 }
Пример #2
0
 function beforeFilter()
 {
     /* Read URL to get the controller name */
     $url_params = Router::getParams();
     /* Load account setting only if the controller is NOT in admin sections */
     if ($url_params['controller'] == 'admin' || $url_params['controller'] == 'wzusers' || $url_params['controller'] == 'wzaccounts' || $url_params['controller'] == 'wzsettings') {
         return;
     }
     if (!$this->Auth->user('id')) {
         return;
     }
     /* Load account related settings and entry types */
     $account_id = CakeSession::read('ActiveAccount.id');
     if (empty($account_id)) {
         $this->Session->setFlash(__d('webzash', 'Please choose a account.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account'));
     }
     /* Write settings */
     App::import("Webzash.Model", "Setting");
     $Setting = new Setting();
     $setting = '';
     try {
         $setting = $Setting->findById(1);
     } catch (Exception $e) {
         CakeSession::delete('ActiveAccount.id');
         CakeSession::delete('ActiveAccount.account_role');
         $this->Session->setFlash(__d('webzash', 'Settings table is missing. Please check whether this is a valid account database.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account'));
     }
     if (!$setting) {
         CakeSession::delete('ActiveAccount.id');
         CakeSession::delete('ActiveAccount.account_role');
         $this->Session->setFlash(__d('webzash', 'Account settings not found. Please check if the database settings are correct.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account'));
     }
     /* Check if database version is correct */
     if ($setting['Setting']['database_version'] < 5) {
         CakeSession::delete('ActiveAccount.id');
         CakeSession::delete('ActiveAccount.account_role');
         $this->Session->setFlash(__d('webzash', 'You are connecting to a database which belongs to older version of this application. Please check the Wiki in the help section on how to upgrade your database.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account'));
     }
     if ($setting['Setting']['database_version'] == 5) {
         /* If user has admin role then redirect to update page */
         if (CakeSession::read('ActiveAccount.account_role') == "admin") {
             $this->Session->setFlash(__d('webzash', 'You need to update the account database before activating this account.'), 'danger');
             return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzaccounts', 'action' => 'update'));
         }
         /* If user does not belong to admin role then show message to contact administrator */
         CakeSession::delete('ActiveAccount.id');
         CakeSession::delete('ActiveAccount.account_role');
         $this->Session->setFlash(__d('webzash', 'You need to update the account database before activating this account. Kindly contact the site administrator to update the account database.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account'));
     }
     if ($setting['Setting']['database_version'] > 6) {
         CakeSession::delete('ActiveAccount.id');
         CakeSession::delete('ActiveAccount.account_role');
         $this->Session->setFlash(__d('webzash', 'You are connecting to a database which belongs to newer version of this application. Please upgrade this application before you can connect to the database.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account'));
     }
     /* Validate settings */
     if (!($setting['Setting']['decimal_places'] == 2 || $setting['Setting']['decimal_places'] == 3)) {
         CakeSession::delete('ActiveAccount.id');
         CakeSession::delete('ActiveAccount.account_role');
         $this->Session->setFlash(__d('webzash', 'Decimal places should be set to 2 or 3 in account settings.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account'));
     }
     Configure::write('Account.name', $setting['Setting']['name']);
     Configure::write('Account.address', $setting['Setting']['address']);
     Configure::write('Account.email', $setting['Setting']['email']);
     Configure::write('Account.currency_symbol', $setting['Setting']['currency_symbol']);
     Configure::write('Account.currency_format', $setting['Setting']['currency_format']);
     Configure::write('Account.decimal_places', $setting['Setting']['decimal_places']);
     $dateFormat = explode('|', $setting['Setting']['date_format']);
     Configure::write('Account.dateformatPHP', $dateFormat[0]);
     Configure::write('Account.dateformatJS', $dateFormat[1]);
     Configure::write('Account.startdate', $setting['Setting']['fy_start']);
     Configure::write('Account.enddate', $setting['Setting']['fy_end']);
     Configure::write('Account.locked', $setting['Setting']['account_locked']);
     Configure::write('Account.email_use_default', $setting['Setting']['email_use_default']);
     Configure::write('Account.CurrentDatabaseVersion', $setting['Setting']['database_version']);
     /* Write entry types */
     App::import("Webzash.Model", "Entrytype");
     $Entrytype = new Entrytype();
     $rawentrytypes = '';
     try {
         $rawentrytypes = $Entrytype->find('all');
     } catch (Exception $e) {
         CakeSession::delete('ActiveAccount.id');
         CakeSession::delete('ActiveAccount.account_role');
         $this->Session->setFlash(__d('webzash', 'Entry types table is missing. Please check whether this is a valid account database.'), 'danger');
         return $this->redirect(array('plugin' => 'webzash', 'controller' => 'wzusers', 'action' => 'account'));
     }
     $entrytypes = array();
     foreach ($rawentrytypes as $entrytype) {
         $entrytypes[$entrytype['Entrytype']['id']] = array('prefix' => $entrytype['Entrytype']['prefix'], 'suffix' => $entrytype['Entrytype']['suffix'], 'zero_padding' => $entrytype['Entrytype']['zero_padding'], 'label' => $entrytype['Entrytype']['label'], 'name' => $entrytype['Entrytype']['name']);
     }
     Configure::write('Account.ET', $entrytypes);
 }