users->user as $child) { if ((string)$child['name'] === $params['login']) { $exists = true; break; } } $usersFile = simplexml_load_file($path . $config['users']); foreach ($usersFile->users->user as $child) { if ((string)$child['name'] === $params['login']) { $exists = true; break; } } if ($exists) { return "name_exists"; } else { $requestFile = simplexml_load_file($path . $config['usersRequest']); $requestFilePath = $path . $config['usersRequest']; $newUser = $requestFile->users->addChild('user'); $newUser->addAttribute('name', $params['login']); $newUser->addAttribute('pass', $params['pass']); $newUser->addAttribute('access', ''); $newUser->addAttribute('email', $params['email']); $newUser->addAttribute('link', md5($params['login'].$params['pass'])); $dom = new DOMDocument('1.0', 'UTF-8'); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($requestFile->asXML()); if ($dom->save($requestFilePath)) { return sendRegistrationEmail($params); } else { throw new Exception("Error while creating user request", -32003); } } } /** * @brief Отправляет уведомление о регистрации пользователю и администратору * @param array $paramsEmail Массив с ключами 'login', 'pass', 'email' * @return string "true" при успешной отправке * @throws Exception Если произошла ошибка при отправке email */ function sendRegistrationEmail($paramsEmail) { global $config; $to = $config['emailAdmin']; $subject = '=?UTF-8?B?'.base64_encode('Запрос на создание аккаунта на сайте ').'?=' . $_SERVER['HTTP_HOST']; $message = 'Логин: ' . $paramsEmail['login'] . "\r\n"; $message .= 'Пароль: ' . $paramsEmail['pass'] . "\r\n"; $message .= 'Почта: ' . $paramsEmail['email'] . "\r\n"; $message .= 'Сайт: ' . $config['server'] . "\r\n"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type: text/html; charset=UTF-8" . "\r\n"; $headers .= "From: info@oblat.lv"; if (!mail($to, $subject, $message, $headers)) { throw new Exception("Error sending email", -32002); } return "true"; } ?>