xx{$ax['usr_all_cats']} \n"; while (list($ID,$name,$color,$bgColor) = $stH->fetch(PDO::FETCH_NUM)) { $selected = ($selCid == $ID) ? ' selected' : ''; $catColor = ($color ? "color:{$color};" : '').($bgColor ? "background-color:{$bgColor};" : ''); echo "\n"; } } function usrList($uid,$selUid) { global $ax, $usr; $stH = dbQuery("SELECT `ID`,`name`,`email` FROM `users`WHERE `status` >= 0 ORDER BY `name`"); echo "\n"; while (list($ID,$name,$email) = $stH->fetch(PDO::FETCH_NUM)) { if ($ID == 1 or $ID == $uid) { continue; } //public or current user $selected = ($selUid == $ID) ? ' selected' : ''; echo "\n"; } } function listUsers() { global $ax, $usr; echo "
\n"; } function editUser(&$user) { global $formCal, $ax, $set, $usr, $state; $uid = $user['id']; echo "\n"; } function transferEvents(&$user) { global $formCal, $ax, $state, $catID, $fromEvtD, $tillEvtD, $fromCreD, $tillCreD, $usrID; $uid = $user['id']; $stH = stPrep("SELECT `name`, `email` FROM `users` WHERE `ID` = ?"); stExec($stH,[$uid]); $row = $stH->fetch(PDO::FETCH_ASSOC); $stH = null; echo "\n"; } function addUser(&$user) { //add user account global $ax, $state, $today; do { //validate input if (!$user['name'] or !$user['mail'] or !$user['pword']) { $msg = 'E'.$ax['usr_cred_required']; break; } if (strpos($user['pword'],'~') !== false) { $msg = 'E'.$ax['pw_no_chars']; break; } if (!preg_match("/^[\w\s\._-]{2,}$/u", $user['name'])) { $msg = 'E'.$ax['usr_un_invalid']; break; } if (!filter_var($user['mail'],FILTER_VALIDATE_EMAIL)) { $msg = 'E'.$ax['usr_em_invalid']; break; } if ($user['phone'] and !preg_match("/^[+0][\d]{8,18}$/",$user['phone'])) { $msg = 'E'.$ax['usr_ph_invalid']; break; } //add to database $stH = stPrep("SELECT `name`,`email` FROM `users` WHERE (`name` = ? OR `email` = ?) AND `status` >= 0"); stExec($stH,[$user['name'],$user['mail']]); $row = $stH->fetch(PDO::FETCH_ASSOC); $stH = null; if ($row) { // name or email already exists $msg = $row['name'] == $user['name'] ? 'E'.$ax['usr_name_exists'] : 'E'.$ax['usr_email_exists']; break; } $xDate = $user['xDate'] ? DDtoID($user['xDate']) : '9999-00-00'; if ($xDate === false or $xDate <= $today) { $msg = 'E'.$ax['usr_xd_invalid']; break; } $password = md5($user['pword']); $notSrvs = ($user['notEml'] ? 'E' : '').($user['notTlg'] ? 'T' : '').($user['notSms'] ? 'S' : ''); $stH = stPrep("INSERT INTO `users` (`name`,`password`,`email`,`phone`,`msingID`,`notSrvs`,`groupID`,`language`,`expDate`) VALUES (?,?,?,?,?,?,?,?,?)"); stExec($stH,[$user['name'],$password,$user['mail'],$user['phone'],$user['msgID'],$notSrvs,$user['grpID'],$user['lang'],$xDate]); $user['id'] = dbLastRowId(); //set id to new user $msg = 'C'.$ax['usr_added']; $state = ''; } while (false); return $msg; } function updateUser(&$user) { //update user account global $ax, $state, $today; do { //validate input if (!preg_match("/^[\w\s\._-]{2,}$/u", $user['name'])) { $msg = 'E'.$ax['usr_un_invalid']; break; } if ($user['id'] > 1) { //not Public User if (!filter_var($user['mail'],FILTER_VALIDATE_EMAIL)) { $msg = 'E'.$ax['usr_em_invalid']; break; } if ($user['phone'] and !preg_match("/^[+0][\d]{8,18}$/",$user['phone'])) { $msg = 'E'.$ax['usr_ph_invalid']; break; } if ($user['msgID'] and !preg_match("~^\+?[\d]{8,12}$~",$user['msgID'])) { $msg = 'E'.$ax['usr_tg_invalid']; break; } } //for duplicates $stH = stPrep("SELECT `name`,`email` FROM `users` WHERE (`name` = ? OR `email` = ?) AND `ID` != ? AND `status` >= 0"); stExec($stH,[$user['name'],$user['mail'],$user['id']]); $row = $stH->fetch(PDO::FETCH_ASSOC); $stH = null; if ($row) { //name or email already exists $msg = $row['name'] == $user['name'] ? 'E'.$ax['usr_name_exists'] : 'E'.$ax['usr_email_exists']; break; } $xDate = $user['xDate'] ? DDtoID($user['xDate']) : '9999-00-00'; if ($xDate === false or $xDate <= $today) { $msg = 'E'.$ax['usr_xd_invalid']; break; } $notSrvs = ($user['notEml'] ? 'E' : '').($user['notTlg'] ? 'T' : '').($user['notSms'] ? 'S' : ''); //update user profile if ($user['pword']) { //new password if (strpos($user['pword'],'~') !== false) { $msg = 'E'.$ax['pw_no_chars']; break; } $password = md5($user['pword']); $stH = stPrep("UPDATE `users` SET `name` = ?,`password` = ?,`email` = ?,`phone` = ?,`msingID` = ?,`notSrvs` = ?,`groupID` = ?,`language` = ?,`expDate` = ? WHERE `ID` = ?"); stExec($stH,[$user['name'],$password,$user['mail'],$user['phone'],$user['msgID'],$notSrvs,$user['grpID'],$user['lang'],$xDate, $user['id']]); } else { //no new password $stH = stPrep("UPDATE `users` SET `name` = ?,`email` = ?,`phone` = ?,`msingID` = ?,`notSrvs` = ?,`groupID` = ?,`language` = ?,`expDate` = ? WHERE `ID` = ?"); stExec($stH,[$user['name'],$user['mail'],$user['phone'],$user['msgID'],$notSrvs,$user['grpID'],$user['lang'],$xDate, $user['id']]); } $msg = 'C'.$ax['usr_updated']; $state = ''; } while (false); return $msg; } function deleteUser($user) { //delete user account global $ax, $usr; do { if ($user['id'] == $usr['ID']) { $msg = 'E'.$ax['usr_cant_delete_yourself']; break; } $stH = stPrep("UPDATE `users` SET `status` = -1 WHERE `ID` = ?"); stExec($stH,[$user['id']]); $deleted = $stH->rowCount(); if (!$deleted) { $msg = 'E'."Database Error: {$ax['usr_not_deleted']}"; break; } $msg = 'C'.$ax['usr_deleted']; } while (false); return $msg; } function updateEvents($user) { //update events (transfer) global $ax, $state, $catID, $usrID, $fromEvtD, $tillEvtD, $fromCreD, $tillCreD; do { //validate input $sEvtDate = DDtoID($fromEvtD); $eEvtDate = DDtoID($tillEvtD); if ($sEvtDate === false or $eEvtDate === false) { $msg = 'E'.$ax['usr_invalid_sdata']; break; } if ($sEvtDate and $eEvtDate and $eEvtDate < $sEvtDate) { $msg = 'E'.$ax['usr_edate_lt_sdate']; break; } $sCreDate = DDtoID($fromCreD); $eCreDate = DDtoID($tillCreD); if ($sCreDate === false or $eCreDate === false) { $msg = 'E'.$ax['usr_invalid_cdata']; break; } if ($sCreDate and $eCreDate and $eCreDate < $sCreDate) { $msg = 'E'.$ax['usr_edate_lt_sdate']; break; } if (!$usrID) { $msg = 'E'.$ax['usr_no_new_owner']; break; } //update events $where = "`userID` = '{$user['id']}'"; if ($catID !== '*') { $where .= " AND `catID` = '{$catID}'"; } if ($sEvtDate) { $where .= " AND `sDate` >= '{$sEvtDate}'"; } if ($eEvtDate) { $where .= " AND `sDate` <= '{$eEvtDate}'"; } if ($sCreDate) { $where .= " AND substr(aDateTime,1,10) >= '{$sCreDate}'"; } if ($eCreDate) { $where .= " AND substr(aDateTime,1,10) <= '{$eCreDate}'"; } $stH = stPrep("UPDATE `events` SET `userID` = ? WHERE {$where} AND `status` >= 0"); stExec($stH,[$usrID]); $count = $stH->rowCount(); $msg = "C{$ax['usr_evts_transferred']}: $count"; $state = 'trans'; } while (false); return $msg; } //control logic if ($usr['privs'] >= 4) { //manager or admin $msg = ''; if (isset($_POST['addExe'])) { $msg = addUser($user); } elseif (isset($_POST['updExe'])) { $msg = updateUser($user); } elseif (isset($_POST['delExe'])) { $msg = deleteUser($user); } elseif (isset($_POST['trfExe'])) { $msg = updateEvents($user); } $class = $msg ? ($msg[0] == 'E' ? 'error' : 'confirm') : ''; $msg = substr($msg,1); echo $msg ? "{$msg}
\n" : "\n"; echo "
{$ax['no_way']}
\n"; } ?>