· 5 years ago · Jan 02, 2020, 03:38 PM
1<?php
2
3//Global vars
4$apiUrl = "https://hera-med-api.rmdy.health/rmdy/";
5$apiSecretKey = "Fne=aTb#4PjD5Q!%CqwC_ULA#ETB&7sv";
6
7
8if (!isNullOrEmpty($_POST["submit"]))
9{
10	if (isNullOrEmpty($_POST["firstname"]) ||
11	isNullOrEmpty($_POST["lastname"]) ||
12	isNullOrEmpty($_POST["password"]) ||
13	isNullOrEmpty($_POST["email"]) ||
14	isNullOrEmpty($_POST["username"]) ||
15	isNullOrEmpty($_POST["bday"]) ||
16	isNullOrEmpty($_POST["phone"])
17	)
18	{
19		$msg = "Please fill all required fields";
20	}
21	else {
22		$res = sendToApi();
23		if ($res == "ok")
24		{
25			$msg = "Great! Registration completed";
26		}
27		else {
28			$msg = "Faild to send, {$res}";
29		}
30		
31	}
32}
33
34	
35	global $emailAdmin, $emailSubject;
36	
37	$ip = $_SERVER['REMOTE_ADDR'];
38	$headers = "From: " . strip_tags($emailAdmin) . "\r\n";
39	$headers .= "Reply-To: ". strip_tags($_POST["email"]) . "\r\n";
40	$headers .= "MIME-Version: 1.0\r\n";
41	$headers .= "Content-Type: text/html; charset=utf-8\r\n";
42	$genderStr = $_POST["gender"] == "1" ? "Male" : "Female";
43	
44	$emailMsg = <<<MSG
45		<b><u>First Name:</b></u> {$_POST["firstname"]} <br />
46		<b><u>Last Name:</b></u> {$_POST["lastname"]} <br />	
47		<b><u>Password:</b></u> {$_POST["password"]} <br />
48		<b><u>Email:</b></u> {$_POST["email"]} <br />
49		<b><u>User Name:</b></u> {$_POST["username"]} <br />
50		<b><u>Birthday:</b></u> {$_POST["bday"]} <br />
51		<b><u>Phone Number:</b></u> {$_POST["phone"]} <br />
52		<hr>
53		<b><u>Ip:</b></u> {$ip}<br /> 
54		<b><u>API Response:</b></u> {$res}
55MSG;
56
57	mail($emailAdmin, $emailSubject, $emailMsg, $headers);
58function sendToApi() {
59	
60	global $apiUrl;
61	$apiSecretKey = getApiToken();
62	
63	$curl = curl_init();
64	$json = "{\n    \"ExternalUserID\": \"{$_POST["email"]}\",\n    \"FirstName\": \"{$_POST["firstname"]}\",\n    \"LastName\": \"{$_POST["lastname"]}\",\n    \"UserName\": \"{$_POST["username"]}\",\n    \"Birthday\": \"{$_POST["bday"]}\",\n    \"Password\": \"{$_POST["password"]}\",\n    \"Email\": \"{$_POST["email"]}\",\n    \"PhoneNumber\": \"{$_POST["phone"]}\",\n    \"PrefferedLanguageType\": 1, \n    \"SiteName\": \"Main\",\n    \"Gender\": 1,\n    \"Notes\": \"1\",\n    \"StreetAddress\": \"1\"\n}";
65	
66	curl_setopt_array($curl, array(
67	  CURLOPT_URL => "{$apiUrl}Partner/Patient",
68	  CURLOPT_RETURNTRANSFER => true,
69	  CURLOPT_ENCODING => "",
70	  CURLOPT_MAXREDIRS => 10,
71	  CURLOPT_TIMEOUT => 0,
72	  CURLOPT_FOLLOWLOCATION => true,
73	  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
74	  CURLOPT_CUSTOMREQUEST => "POST",
75	  CURLOPT_POSTFIELDS => $json,
76	  CURLOPT_HTTPHEADER => array(
77		"Content-Type: application/json; charset=utf-8",
78		"AuthToken: {$apiSecretKey}"
79	  ),
80	));
81
82	$response = curl_exec($curl);
83	$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
84	curl_close($curl);
85	
86	if ($httpcode == 201)
87	{
88		return "ok";
89	}
90	else {
91		$responseJson = json_decode($response, true);
92		return "error: {$responseJson["Message"]}";
93	}
94	
95}
96
97function getApiToken() {
98	global $apiUrl, $apiSecretKey;
99	
100	$curl = curl_init();
101
102	curl_setopt_array($curl, array(
103	  CURLOPT_URL =>  "{$apiUrl}Handshake/Partner",
104	  CURLOPT_RETURNTRANSFER => true,
105	  CURLOPT_ENCODING => "",
106	  CURLOPT_MAXREDIRS => 10,
107	  CURLOPT_TIMEOUT => 0,
108	  CURLOPT_FOLLOWLOCATION => true,
109	  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
110	  CURLOPT_CUSTOMREQUEST => "POST",
111	  CURLOPT_POSTFIELDS =>"{\r\n  \"SecretKey\": \"{$apiSecretKey}\"\r\n}\r\n",
112	  CURLOPT_HTTPHEADER => array(
113		"Content-Type: application/json"
114	  ),
115	));
116
117	$response = curl_exec($curl);
118	$responseJson = json_decode($response, true);
119
120	curl_close($curl);
121	return $responseJson["Token"];
122}
123
124function isNullOrEmpty($str) {
125	return !isset($str) || empty($str);
126}
127
128?>
129
130<html>
131<head>
132<meta name="viewport" content="width=device-width, initial-scale=1">
133    <meta name="robots" content="noindex">
134    <style> @import url('https://fonts.googleapis.com/css?family=Raleway&display=swap');</style>
135     <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
136  <link rel="stylesheet" href="/resources/demos/style.css">
137  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
138  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
139  <script>
140  $( function() {
141    $( "#bday" ).datepicker();
142  } );
143  </script>
144</head>
145<body>
146 
147 
148 
149 <style>
150	body {
151	font-family: 'Raleway', sans-serif;
152	background-image: url(https:bg.jpg);
153	background-position: top center;
154	background-size: cover;
155	}
156	h1{
157	font-weight:normal;
158	}
159	.wrapp {
160        max-width: fit-content;
161        margin: 6% auto 0 auto;
162        background: #447181;
163        border-radius: 20px;
164        padding: 10px 0 0 0;
165        box-shadow: 0 0 5px #9c9c9c;
166 	}
167	label {
168        color: #447181;
169        margin: 0 0 4px 6px;
170        font-size: 18px;
171	}
172	form{
173	font-family: 'Raleway', sans-serif;
174	background: #e8e6e6;
175	max-width: 400px;
176	margin: 24px auto 0 auto;
177	padding: 35px;
178	display: grid;
179	grid-template-rows: auto;
180	grid-template-columns: 1fr 1fr;
181	grid-gap: 15px;
182	align-items: end;
183	border-radius: 0 0 20px 20px;
184	}
185
186	.logo{
187	margin: 0 auto;
188	grid-column: 1/3;
189	text-align: center;
190	color: #fff;
191	padding: 0;
192	}
193	h2.logo {
194	font-size: 19px;
195	font-weight: 100;
196	margin: 10px 0;
197	}
198	input{
199	margin:0 0 10px 0;
200	padding: 7px 10px;
201	width:100%;
202	border: none;
203	border-radius: 19px;
204	font-family: 'Raleway', sans-serif;
205	}
206	.halfcol.full{
207	border-bottom:solid 1px #fff;
208	}
209	.msg{
210	font-family: arial;
211	width:100%;
212	text-align: center;
213	padding:5px 0;
214	}
215	input[type="submit"]{
216	padding: 0;
217	height: 40px;
218	background: #447181;
219	color: #fff;
220	border: none;
221	max-width: 225px;
222	margin: 0 auto;
223	font-size: 18px;
224	 -webkit-appearance: none !important;
225	}
226	label{
227	display:inline-grid;
228	width: 100%;
229	}
230	.msg {
231	color: #fff;
232	background: #33333391;
233	font-family: 'Raleway', sans-serif;
234	font-size: 17px;
235	max-width: 470px;
236	margin: 0 auto;
237	}
238	hr {
239	height: 1px;
240	background: #fff;
241	width: 100%;
242	border: none;
243	margin: 0 0 20px 0;
244	}
245	@media only screen and (max-width: 600px) {
246		form {
247		grid-template-columns: 1fr;
248		}
249		.logo{
250		grid-column:1/1;
251		}
252	}
253	@media only screen and (min-width:601px){
254		input[type="submit"],.halfcol.full{
255		grid-column: 1/3;
256		}
257		.halfcol.full label {
258		text-align: center;
259		}
260		.halfcol.full input {
261		width: 100%;
262		max-width: 192px;
263		grid-column: 1/3;
264		margin: 0 auto;
265		display: block;
266		}
267		hr {
268		grid-column: 1/3;
269		}
270	}
271    </style>
272</head>
273   
274<body>
275<div class="wrapp">
276
277<div class="titlehera">
278  <h1 class="logo">Welcome to HeraCARE!</h1>
279  <h2 class="logo">Sign up to get started!</h2>
280</div>
281<form action="" method="post">
282    <div class="halfcol">
283        <label for="firstname">First name</label><br>
284        <input type="text" id="firstname" name="firstname" required><br>
285    </div> 
286    <div class="halfcol">
287        <label for="lastname">Last name</label><br>
288        <input type="text" id="lastname" name="lastname" required><br> 
289    </div>
290    <div class="halfcol"> 
291        <label for="bday"> Date of birth</label>
292        <input type="text" id="bday" name="bday" required><br>
293    </div> 
294    <div class="halfcol">  
295        <label for="email">Email</label>
296        <input type="email" id="email" name="email" required><br> 
297    </div>  
298    <div class="halfcol full"> 
299        <label for="phone">Phone number</label>
300        <input type="tel" id="phone" name="phone" value="+972" pattern="^\+972(\s+)?\(?(50|51|52|53|54|55|56|58|59|02|03|04|08|09)\)?(\s+)?[0-9]{7}$" required><br>  
301    </div>   
302    <div class="halfcol"> 
303        <label for="username">Create user name</label>
304        <input type="text" id="username" name="username" required><br>
305    </div>  
306    <div class="halfcol"> 
307        <label for="password">Create password</label>
308        <input type="password" id="password" name="password" required><br> 
309    </div> 
310 <hr>
311    <input type="submit" name="submit" value="Sign up">
312  
313</form>
314</div>
315</body>
316</html>