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 "
{$ax['usr_list_of_users']}\n"; $stH = stPrep("SELECT u.`ID`, u.`name`, u.`email`, u.`phone`, u.`msingID`, u.`notSrvs`, u.`language`, u.`expDate`, u.`login0`, u.`login1`, u.`loginCnt`, g.`name` AS gname, g.`color` FROM `users` AS u INNER JOIN `groups` AS g ON g.`ID` = u.`groupID` WHERE u.`status` >= 0 ORDER BY CASE WHEN u.`ID` <= 2 THEN u.`ID` ELSE u.`name` END"); stExec($stH,null); $rows = $stH->fetchAll(PDO::FETCH_ASSOC); echo "\n"; echo "\n\n"; foreach ($rows as $user) { $xDate = $user['expDate'][0] !='9' ? IDtoDD($user['expDate']) : ''; $firstLoginD = ($user['login0'] != '9999-00-00') ? IDtoDD($user['login0']) : ''; $lastLoginD = ($user['login1'] != '9999-00-00') ? IDtoDD($user['login1']) : ''; $style = $user['color'] ? " style='background-color:{$user['color']};'" : ''; $notVia = rtrim((strpos($user['notSrvs'],'E') !== false ? 'E+' : '').(strpos($user['notSrvs'],'T') !== false ? 'T+' : '').(strpos($user['notSrvs'],'S') !== false ? 'S+' : ''),'+'); echo ""; echo "{$user['gname']}\n"; } echo "
 {$ax['id']} {$ax['usr_name']}{$ax['usr_email']}{$ax['usr_phone_br']}{$ax['usr_tg_id_br']}{$ax['usr_not_via_br']}{$ax['usr_language']}{$ax['usr_group']}{$ax['usr_expires']}{$ax['usr_login_0']}{$ax['usr_login_1']}{$ax['usr_login_cnt']}
{$user['ID']}{$user['name']}{$user['email']}{$user['phone']}{$user['msingID']}{$notVia}".ucfirst($user['language'])."{$xDate}{$firstLoginD}{$lastLoginD}{$user['loginCnt']}"; echo ($usr['privs'] == 9 or $user['ID'] != 2) ? " " : ''; echo " "; echo ($user['ID'] > 2 and $user['ID'] != $usr['ID']) ? "" : ''; echo "
\n"; echo "
\n"; } function editUser(&$user) { global $formCal, $ax, $set, $usr, $state; $uid = $user['id']; echo "
{$formCal}
"; if ($state != 'add' and !isset($_POST["uName"])) { $stH = stPrep("SELECT * FROM `users` WHERE `ID` = ?"); stExec($stH,[$uid]); $row = $stH->fetch(PDO::FETCH_ASSOC); $stH = null; if ($row) { $user['name'] = $row['name']; $user['mail'] = $row['email']; $user['phone'] = $row['phone']; $user['msgID'] = $row['msingID']; $user['notEml'] = (strpos($row['notSrvs'],'E') !== false) ? 1 : 0; $user['notTlg'] = (strpos($row['notSrvs'],'T') !== false) ? 1 : 0; $user['notSms'] = (strpos($row['notSrvs'],'S') !== false) ? 1 : 0; $user['lang'] = $row['language'] ?: $set['language']; $user['grpID'] = $row['groupID']; $user['xDate'] = $row['expDate'][0] !='9' ? IDtoDD($row['expDate']) : ''; } $pwStar = "*"; echo "{$ax['usr_edit_user']}\n"; } else { $pwStar = ''; echo "{$ax['usr_add']}\n"; } echo " \n"; echo "\n"; if ($state != 'add') { echo "\n"; } echo "\n"; if ($uid != 1) { //not public access echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if ($pwStar) { echo "\n"; } } echo ""; if ($uid == $usr['ID'] or $uid == 2) { //can't put yourself or the admin in a different group or change the account expiry date $stH = stPrep("SELECT `name`,`color` FROM `groups` WHERE `ID` = ?"); stExec($stH,[$user['grpID']]); $row = $stH->fetch(PDO::FETCH_ASSOC); $stH = null; $color = $row['color'] ? " style='background-color:{$row['color']};'" : ''; echo "\n"; if ($user['xDate']) { echo "\n"; echo "\n"; } echo "
{$ax['id']}: {$user['id']}
{$ax['usr_name']}:
{$ax['usr_email']}:
{$ax['usr_phone']}:
{$ax['usr_tg_id']}:
{$ax['usr_not_via']}:
{$ax['usr_ui_language']}:
{$ax['usr_password']} {$pwStar}:
{$pwStar} {$ax['usr_if_changing_pw']}
{$ax['usr_group']}:{$row['name']}
{$ax['usr_expir_date']}:{$user['xDate']}\n"; } } else { $stH = stPrep("SELECT `ID`,`name`,`color` FROM `groups` WHERE `status` >= 0 ORDER BY `ID`"); stExec($stH,null); echo "
{$ax['usr_expir_date']}:📅 ({$ax['usr_blank_none']})
\n
\n"; if ($state == 'add') { echo ""; } else { echo ""; } 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 "
{$formCal}
{$ax['usr_transfer_ownership']}"; echo "\n"; echo "\n"; echo "
{$ax['usr_cur_owner']}: {$row['name']} ({$row['email']})
"; echo "
\n"; echo "\n"; echo "\n"; echo "\n\n"; echo "\n\n"; echo "\n"; echo "\n"; echo "\n"; echo "
{$ax['usr_event_cat']}:
{$ax['usr_sdate_between']}:* 📅 📅
{$ax['usr_cdate_between']}:* 📅 📅
*{$ax['usr_blank_no_limit']}
 
{$ax['usr_new_owner']}:\n"; echo "
\n"; echo "
\n"; echo "
{$ax['usr_no_undone']}!
\n"; echo "
\n"; echo ""; 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 "
\n"; if (!$state or isset($_POST['back'])) { listUsers(); //no add / no edit } elseif ($state == 'add' or $state == 'edit') { editUser($user); //add or edit } elseif ($state == 'trans') { transferEvents($user); //transfer events } echo "
\n"; } else { echo "

{$ax['no_way']}

\n"; } ?>