Пример #1
0
 function addFamilyMember()
 {
     if (isset($_POST["UserName"]) && isset($_POST["UserPass"]) && isset($_POST["UserInfoTel"]) && isset($_POST["UserInfoFirstName"]) && isset($_POST["UserInfoLastName"])) {
         if (Users::isUserExistByMail($_POST["UserName"])) {
             echo json_encode(array("errors" => array("L'adresse de courriel que vous avez fournie est déjà utilisé")));
         } else {
             $salt = Registration::generateSalt();
             $crypt = crypt($_POST["UserPass"], $salt);
             $ownerId = Users::getFamilyOwnerByUserId($_SESSION["id"]);
             Users::addUser($_POST["UserName"], $_POST["UserInfoTel"], $_POST["UserInfoFirstName"], $_POST["UserInfoLastName"], $ownerId[0][0], $crypt, $salt);
             $userId = Users::getUserIdByName($_POST["UserName"]);
             $user = Users::getUser($userId);
             $phoneNumber = $user["UserInfoTel"];
             $phoneNumber = Registration::normalizePhoneNumber($phoneNumber);
             $user["UserInfoTel"] = $phoneNumber[0] . " (" . mb_substr($phoneNumber, 1, 3) . ") " . mb_substr($phoneNumber, 4, 3) . "-" . mb_substr($phoneNumber, 7, 4);
             echo json_encode($user);
         }
     }
 }