error()) return; $required = array( 'name', 'sys_name', 'passowrd', 'password_type', ); if (0 == $id) { $this->setReqAttr($required); return; } if (!$this->chkTable_()) return; $this->attr['id'] = $id; // Initialise object via Table object $this->Table->setId($id); // select data from table if (!$this->Table->select()) { $this->attr['id'] = -1; $this->setError_(get_class($this) . ': unable to select: ' . $this->Table->getErrorMsg()); return; } // fetch table row, $this->attr = $this->Table->fetchArray(); if (!$this->attr) { $this->attr = $this->resetAttr_(); $this->setError_(get_class($this) . ': unable to fetch array: ' . $this->Table->getErrorMsg()); return; } $this->oldAttr_ = $this->attr; } function resetAttr_() { return array( 'id' => 0, 'name' => '', 'password' => '', 'password_type' => 'plain', 'sys_name' => '', ); } function getInputableAttr_() { $ret = array( 'name' => '', ); if (0 == $this->getId()) $ret['sys_name'] = ''; return $ret; } function initFromSubmit() { $password = $this->fetchSubmitVar('password'); if ($password) $this->setPassword($password, 'plain'); return cObject::initFromSubmit(); } function isExist($name = '') { if (!(isset($this) && is_object($this) && get_class($this) == 'fileserveruser')) return FileServerShare::isExist(0, $name); if (!$this->chkTable_()) return false; $ret = $this->Table->isExist($this->getId(), $this->getName()); if ($this->Table->error()) { $this->setError_($this->Table->getErrorMsg()); return false; } return $ret; } function update() { $create = 0 == $this->getId(); if (!cObject::update()) return false; include_once('modules/fileserver/FileServerManager.php'); $myFileServerManager =& FileServerManagerMaker(); if ($myFileServerManager->error()) { $this->setError_('Unable to create FileServerManager object: ' . $myFileServerManager->getErrormsg()); return false; } if ($create) { if (false === $myFileServerManager->add_user($this->getName(), $this->getSysName(), $this->getPassword(), true)) { $this->setError_('FileServerManager::add_user() failed: ' . $myFileServerManager->getErrorMsg()); return false; } } else { if ($this->isAttrChanged('name') && (false === $myFileServerManager->rename_user($this->getOldAttr('name'), $this->getName(), $this->getSysName(), true))) { $this->setError_('FileServerManager::rename_user() failed: ' . $myFileServerManager->getErrorMsg()); return false; } } if ($this->isAttrChanged('password') && (false === $myFileServerManager->set_user_password($this->getName(), $this->getSysName(), $this->getPassword(), true))) { $this->setError_('FileServerManager::set_user_password() failed: ' . $myFileServerManager->getErrorMsg()); return false; } return true; } function delete() { if (0 == $this->getId()) return true; //clean valid users reference $query = 'DELETE from ' . FILESERVER_TABLE_VALID_USERS . ' WHERE uid = "' . $this->getId() . '"'; if (false === mysql_query($query)) { $this->setError_('mysql_query() failed: ' . db_error()); return false; } if(!cObject::delete()) return false; include_once('modules/fileserver/FileServerManager.php'); $myFileServerManager =& FileServerManagerMaker(); if ($myFileServerManager->error()) { $this->setError_('Unable to create FileServerManager object: ' . $myFileServerManager->getErrormsg()); return false; } if (false === $myFileServerManager->del_user($this->getName(), $this->getSysName(), true)) { $this->setError_('FileServerManager::del_user() failed: ' . $myFileServerManager->getErrorMsg()); return false; } return true; } function getName() { return $this->getAttr('name'); } function getSysName() { return $this->getAttr('sys_name'); } function getPassword() { return $this->getAttr('password'); } function getPasswordType() { return $this->getAttr('password_type'); } function setName($name) { return $this->setAttr('name', $name); } function setSysName($sys_name) { return $this->setAttr('sys_name', $sys_name); } function setPassword($password, $password_type) { $ret = $this->setAttr('password', $password); return $this->setAttr('password_type', $password_type) && $ret; } function chk_name_($name) { include_once('class.Checker.php'); return Checker::sys_login($name); } function chk_sys_name_($sys_name) { include_once('class.Checker.php'); return Checker::sys_login($sys_name); } function chk_password_($password) { return mb_strlen($password) > 0; } function chk_password_type_($password_type) { return in_array($password_type, array('plain', 'crypt')); } } //______________________________________________________________________________ include_once('class.Table.php'); class FileServerUserTable extends Table { function FileServerUserTable($fieldNames) { if (!is_array($fieldNames)) { $this->setError_('field names are not an array'); return; } $tableCards = FILESERVER_TABLE_USERS; $fNames = array_keys($fieldNames); $this->Table($tableCards, $fNames); } function isExist($id, $name) { $name = idn_toascii($name); $query = 'SELECT count(*) FROM ' . FILESERVER_TABLE_USERS . ' WHERE name="' . mysql_escape_string($name) . '" AND id !="' . $id . '"'; $res = mysql_query($query); if (!$res) { if (is_object($this)) { $this->setError_('Unable to query: ' . db_error()); return false; } psaerror('Unable to query: ' . db_error()); } list($num) = mysql_fetch_row($res); mysql_free_result($res); return ($num + 0 > 0); }} ?>