set default value for pwdExpiration when unsetting it

This commit is contained in:
Uwe Steinmann 2017-02-18 07:38:26 +01:00
parent a5e984587d
commit 5921b1e731
2 changed files with 13 additions and 6 deletions

View File

@ -1279,11 +1279,15 @@ class SeedDMS_Core_DMS {
}
if($role == '')
$role = '0';
if(trim($pwdexpiration) == '' || trim($pwdexpiration) == 'never')
$pwdexpiration = null;
elseif(trim($pwdexpiration) == 'now')
$pwdexpiration = date('Y-m-d H:i:s');
$queryStr = "INSERT INTO `tblUsers` (`login`, `pwd`, `fullName`, `email`, `language`, `theme`, `comment`, `role`, `hidden`, `disabled`, `pwdExpiration`, `quota`, `homefolder`) VALUES (".$db->qstr($login).", ".$db->qstr($pwd).", ".$db->qstr($fullName).", ".$db->qstr($email).", '".$language."', '".$theme."', ".$db->qstr($comment).", '".intval($role)."', '".intval($isHidden)."', '".intval($isDisabled)."', ".($pwdexpiration === null ? 'NULL' : $db->qstr($pwdexpiration)).", '".intval($quota)."', ".($homefolder ? intval($homefolder) : "NULL").")";
if(trim($pwdexpiration) == '' || trim($pwdexpiration) == 'never') {
if($db->getDriver() == 'sqlite')
$pwdexpiration = $db->qstr('0000-00-00 00:00:00');
else
$pwdexpiration = 'DEFAULT';
} elseif(trim($pwdexpiration) == 'now')
$pwdexpiration = $db->qstr(date('Y-m-d H:i:s'));
$queryStr = "INSERT INTO `tblUsers` (`login`, `pwd`, `fullName`, `email`, `language`, `theme`, `comment`, `role`, `hidden`, `disabled`, `pwdExpiration`, `quota`, `homefolder`) VALUES (".$db->qstr($login).", ".$db->qstr($pwd).", ".$db->qstr($fullName).", ".$db->qstr($email).", '".$language."', '".$theme."', ".$db->qstr($comment).", '".intval($role)."', '".intval($isHidden)."', '".intval($isDisabled)."', ".$pwdexpiration.", '".intval($quota)."', ".($homefolder ? intval($homefolder) : "NULL").")";
echo $queryStr;
$res = $this->db->getResult($queryStr);
if (!$res)
return false;

View File

@ -269,7 +269,10 @@ class SeedDMS_Core_User { /* {{{ */
$db = $this->_dms->getDB();
if(trim($newPwdExpiration) == '' || trim($newPwdExpiration) == 'never') {
$queryStr = "UPDATE `tblUsers` SET `pwdExpiration` = NULL WHERE `id` = " . $this->_id;
if($db->getDriver() == 'sqlite')
$queryStr = "UPDATE `tblUsers` SET `pwdExpiration` = '0000-00-00 00:00:00' WHERE `id` = " . $this->_id;
else
$queryStr = "UPDATE `tblUsers` SET `pwdExpiration` = DEFAULT WHERE `id` = " . $this->_id;
} else {
if(trim($newPwdExpiration) == 'now')
$newPwdExpiration = date('Y-m-d H:i:s');