Example #1
0
File: Db.php Project: vgrish/dvelum
 /**
  * Save database connection config
  */
 public function saveAction()
 {
     $name = Request::post('name', 'string', false);
     $pass = Request::post('pass', 'string', false);
     $host = Request::post('host', 'string', false);
     $user = Request::post('user', 'string', false);
     $base = Request::post('base', 'string', false);
     $id = Request::post('id', 'integer', false);
     $setpass = Request::post('setpass', 'boolean', false);
     $config = array('user' => $user, 'pass' => $pass, 'base' => $base, 'host' => $host, 'name' => $name);
     if ($id !== false && $id >= 0) {
         if (!$this->_connConfig->offsetExists($id)) {
             Response::jsonError($this->_lang->WRONG_REQUEST);
         }
         if (!$setpass) {
             $oldCfg = $this->_connConfig->get($id);
             $config['pass'] = $oldCfg['pass'];
         }
     } else {
         $id = $this->_connConfig->getCount();
         while ($this->_connConfig->offsetExists($id)) {
             $id++;
         }
     }
     $this->_connConfig->set($id, $config);
     if ($this->_connConfig->save()) {
         Response::jsonSuccess();
     } else {
         Response::jsonError($this->_lang->CANT_WRITE_FS);
     }
 }