* @copyrights (c) 2021, 2024, 5 Mode
*/
// PAGE PARAMETERS
$groupName = PHP_STR;
$userName = PHP_STR;
$defLocation = PHP_STR;
$defPhone = PHP_STR;
$defStatus2 = PHP_STR;
$defOnline = 0;
$curgroup = filter_input(INPUT_POST, "_group")??"";
$curgroup = strip_tags($curgroup);
$aGroups = $FRIENDS;
$checkin = filter_input(INPUT_POST, "_checkin")??"";
$checkin = strip_tags($checkin);
$checkinPassword = filter_input(INPUT_POST, "txtCheckinPassword")??"";
$checkinPassword = strip_tags($checkinPassword);
$newLocation = filter_input(INPUT_POST, "txtNewLocation")??"";
$newLocation = strip_tags($newLocation);
$newPhone = filter_input(INPUT_POST, "txtNewPhone")??"";
$newPhone = strip_tags($newPhone);
$newStatus = filter_input(INPUT_POST, "txtNewStatus")??"";
$newStatus = strip_tags($newStatus);
$newOnline = filter_input(INPUT_POST, "cbNewOnline")??"";
$newOnline = strip_tags($newOnline);
$lang = APP_DEF_LANG;
$lang1 = substr(strip_tags(filter_input(INPUT_GET, "hl")??""), 0, 5);
if ($lang1 !== PHP_STR) {
$lang = $lang1;
}
$shortLang = getShortLang($lang);
$password = filter_input(INPUT_POST, "Password")??"";
$password = strip_tags($password);
if ($password !== PHP_STR) {
$hash = hash("sha256", $password . APP_SALT, false);
foreach($aGroups as $keyg => $valg) {
$aFriends = $valg;
$ii = 0;
foreach($aFriends as $keyf => $valf) {
$ii++;
$aFFields = $valf;
$name = $keyf;
if ($hash === $aFFields['HASH']) {
$groupName = $keyg;
$userName = $name;
$defLocation = $aFFields['Location'];
$defPhone = $aFFields['Phone'];
$defStatus2 = $aFFields['defStatus'];
$defOnline = $aFFields['online'];
break;
}
}
if ($userName !== PHP_STR) {
break;
}
}
if ($userName === PHP_STR) {
$password=PHP_STR;
$curgroup=PHP_STR;
}
}
if ($password !== PHP_STR || DEMO) {
$CURRENT_VIEW = PUBLIC_VIEW;
} else {
$CURRENT_VIEW = LOCKED_VIEW;
}
//echo("groupName=".$groupName."
");
//echo("userName=".$userName."
");
//echo("curgroup=".$curgroup."
");
//exit(1);
if ($curgroup===PHP_STR) {
if ($groupName !== PHP_STR) {
$curgroup=$groupName;
}
}
function cleanPath($p) {
$pattern = $p . DIRECTORY_SEPARATOR . "*";
$paths = glob($pattern);
foreach($paths as $path) {
unlink($path);
}
}
// CHECKIN
if (($password!==PHP_STR) && ($checkin!==PHP_STR) && ($checkinPassword === $password)) {
$groupPath = APP_DATA_PATH . DIRECTORY_SEPARATOR . $groupName;
$userPath = $groupPath . DIRECTORY_SEPARATOR . $userName;
if (!is_readable($groupPath)) {
mkdir($groupPath);
}
if (!is_readable($userPath)) {
mkdir($userPath);
}
$locationPath = $userPath . DIRECTORY_SEPARATOR . "location";
if (!is_readable($locationPath)) {
mkdir($locationPath);
}
cleanPath($locationPath);
$s = preg_replace("/[^\w\-\, ]/iu", "", $newLocation);
touch($locationPath . DIRECTORY_SEPARATOR . $s);
$phonePath = $userPath . DIRECTORY_SEPARATOR . "phone";
if (!is_readable($phonePath)) {
mkdir($phonePath);
}
cleanPath($phonePath);
$s = preg_replace("/[^0-9\-\.\+ ]/iu", "", $newPhone);
touch($phonePath . DIRECTORY_SEPARATOR . $s);
$statusPath = $userPath . DIRECTORY_SEPARATOR . "status";
if (!is_readable($statusPath)) {
mkdir($statusPath);
}
cleanPath($statusPath);
$s = preg_replace("/[^\w\-\_\.\,\: ]/iu", "", $newStatus);
touch($statusPath . DIRECTORY_SEPARATOR . $s);
$onlinePath = $userPath . DIRECTORY_SEPARATOR . "online";
if (!is_readable($onlinePath)) {
mkdir($onlinePath);
}
cleanPath($onlinePath);
$s = preg_replace("/[^0-1]/iu", "", $newOnline);
if ($s === PHP_STR) {
$s = "1";
}
touch($onlinePath . DIRECTORY_SEPARATOR . $s);
}
function readdata($p) {
$pattern = $p . DIRECTORY_SEPARATOR . "*";
$paths = glob($pattern);
if (count($paths)>0) {
return basename($paths[0]);
} else {
return null;
}
}
// READING INFO FROM DATA PATH
foreach($aGroups as $keyg => $valg) {
//$aFriends = $valg;
$gname = $keyg;
//$ii = 0;
foreach($valg as $keyf => $valf) {
//$ii++;
//$aFFields = $valf;
$uname = $keyf;
$groupPath = APP_DATA_PATH . DIRECTORY_SEPARATOR . $gname;
$userPath = $groupPath . DIRECTORY_SEPARATOR . $uname;
if (!is_readable($groupPath) || !is_readable($userPath)) {
continue;
}
$locationPath = $userPath . DIRECTORY_SEPARATOR . "location";
$valf["Location"] = readdata($locationPath)??$valf["Location"];
$aGroups[$gname][$uname]["Location"] = $valf["Location"];
//echo($valf["Location"]);
$phonePath = $userPath . DIRECTORY_SEPARATOR . "phone";
$valf["Phone"] = readdata($phonePath)??$valf["Phone"];
$aGroups[$gname][$uname]["Phone"] = $valf["Phone"];
//echo($valf["Phone"]);
$statusPath = $userPath . DIRECTORY_SEPARATOR . "status";
$valf["defStatus"] = readdata($statusPath)??$valf["defStatus"];
$aGroups[$gname][$uname]["defStatus"] = $valf["defStatus"];
//echo($valf["defStatus"]);
$onlinePath = $userPath . DIRECTORY_SEPARATOR . "online";
$valf["online"] = (int)readdata($onlinePath)??$valf["online"];
$aGroups[$gname][$uname]["online"] = $valf["online"];
//echo($valf["online"]);
}
}
?>