Esempio n. 1
0
function saveJSONArray($newUserArray)
{
    $path_config_users = "";
    include "paths.php";
    $userArray = [];
    include "getUsersFromJSON.php";
    //checks boolean value to see if file is there. If not creates new array
    if (!empty($userArray)) {
        array_push($userArray, $newUserArray);
    } else {
        $userArray[0] = $newUserArray;
    }
    include_once "functions.php";
    $fileToSave = json_encode(getSortedUserArray($userArray), JSON_PRETTY_PRINT);
    file_put_contents($path_config_users, $fileToSave);
}
Esempio n. 2
0
 function deleteUser($username)
 {
     $path_config_users = "";
     include "paths.php";
     $userArray = [];
     include "getUsersFromJSON.php";
     if (isset($userArray)) {
         for ($i = 0; sizeof($userArray); $i++) {
             if ($userArray[$i]->{'username'} == $username) {
                 unset($userArray[$i]);
                 break;
             }
         }
         $userArray = array_values($userArray);
         file_put_contents($path_config_users, json_encode(getSortedUserArray($userArray), JSON_PRETTY_PRINT));
     }
 }