PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/azora.local/register.php

https://gitlab.com/nvtdn2006/azora
PHP | 284 lines | 243 code | 40 blank | 1 comment | 44 complexity | b665f8c3d8d13bed4a024ff94427e8e2 MD5 | raw file
  1. <?php require_once './includes/application.php'; $this->template = 'registration'; $this->title = 'Registration'; ?>
  2. <?php
  3. JSManager::getInstance()->add('jquery');
  4. JSManager::getInstance()->add('validation');
  5. JSManager::getInstance()->add('jquery.ui');
  6. CSSManager::getInstance()->add('/js/jqueryui/smoothness/jquery-ui-1.8.16.custom.css');
  7. $config = Factory::getConfig();
  8. $cryptographer = Factory::getCryptographer();
  9. $error = array();
  10. DomainManager::getInstance()->load('Customer');
  11. $customerObj = new Customer();
  12. $customer = array();
  13. DomainManager::getInstance()->load('Company');
  14. $companyObj = new Company();
  15. $company = $companyObj->getCompany();
  16. $company = $company[0];
  17. if ( (isset($_POST['register']) && $_POST['register'] == 'Register')
  18. || (isset($_POST['hidden_submit']) && $_POST['hidden_submit'] == 'Register') // FX.1304.005 - if not find submit, check hidden submit
  19. ) {
  20. $isValid = true;
  21. if (!empty($_POST['captcha'])) {
  22. if (empty($_POST['captcha']) || trim(strtolower($_POST['captcha'])) != $_SESSION['captcha']) {
  23. $isValid = false;
  24. array_push($error, 'Invalid verification code.');
  25. } else {
  26. if ($_POST['email'] != $_POST['reenteremail']) {
  27. $isValid = false;
  28. array_push($error, 'Emails do not match.');
  29. }
  30. if ($_POST['password'] != $_POST['reenterpassword']) {
  31. $isValid = false;
  32. array_push($error, 'Passwords do not match.');
  33. }
  34. }
  35. unset($_SESSION['captcha']);
  36. } else {
  37. $isValid = false;
  38. array_push($error, 'Invalid verification code.');
  39. }
  40. $dob_year = substr($_POST['dob'],6,4);
  41. $dob_month = substr($_POST['dob'],3,2);
  42. $dob_day = substr($_POST['dob'],0,2);
  43. $dob = date("Y-m-d", mktime(0,0,0,$dob_month,$dob_day,$dob_year));
  44. if ($isValid) {
  45. if (!checkdate($dob_month, $dob_day, $dob_year)) {
  46. $isValid = false;
  47. array_push($error, 'Invalid date of birth.');
  48. }
  49. }
  50. if ($isValid) {
  51. $today = getdate();
  52. $today = date("Y-m-d", mktime(0,0,0,$today['mon'],$today['mday'],$today['year']));
  53. if ( $dob >= $today ) {
  54. $isValid = false;
  55. array_push($error, 'Invalid date of birth.');
  56. }
  57. }
  58. if ($isValid) {
  59. if ($customerObj->isExistNRIC($_POST['nric'])) {
  60. $isValid = false;
  61. array_push($error, 'Your NRIC/FIN is already exist in system, please re-enter.');
  62. }
  63. }
  64. if ($isValid) {
  65. if ($customerObj->isExistEmail($_POST['email'])) {
  66. $isValid = false;
  67. array_push($error, 'Your email is already exist in system, please re-enter.');
  68. }
  69. }
  70. if ($isValid) {
  71. if ($customerObj->isExistCustomer($_POST['nric'], $_POST['email'])) {
  72. $isValid = false;
  73. array_push($error, 'User already exists in system, please check your NRIC/FIN or Email.');
  74. }
  75. }
  76. if ($isValid) {
  77. $customer = array('nric' => $_POST['nric'],
  78. 'name' => $_POST['name'],
  79. 'dob' => $dob,
  80. 'address' => $_POST['address'],
  81. 'company' => $_POST['company'],
  82. 'mobile' => $_POST['mobile'],
  83. 'home' => $_POST['home'],
  84. 'email' => $_POST['email'],
  85. 'password' => $_POST['password']);
  86. if ($customerObj->registerCustomer($customer)) {
  87. //$activation_link = $config['PRMSConfig']->live_site . '/activate.php?atk=' . $customer['activation_key'] . '&id=' . $cryptographer->Encrypt($customer['id']);
  88. $activation_link = $config['PRMSConfig']->live_site . '/activate.php?atk=' . $customer['activation_key'] . '&id=' . $customer['id'];
  89. $customer['activation_link'] = $activation_link;
  90. $customer['company_name'] = $company['company_name'];
  91. $mailer = new SiteMailer();
  92. $mailer->toMail = $customer['email'] ;
  93. $mailer->subject = 'Welcome to '.$company['company_name'].' redemption website';
  94. $mailer->PrepareMail('sendActivationToCustomer', $customer);
  95. if ($mailer->Send())
  96. header( 'Location: complete.php');
  97. }
  98. }
  99. }
  100. if (isset($_REQUEST['nric']))
  101. $customer['nric'] = $_REQUEST['nric'];
  102. else
  103. $customer['nric'] = '';
  104. if (isset($_REQUEST['name']))
  105. $customer['name'] = $_REQUEST['name'];
  106. else
  107. $customer['name'] = '';
  108. if (isset($_REQUEST['dob']))
  109. $customer['dob'] = $_REQUEST['dob'];
  110. else
  111. $customer['dob'] = '';
  112. if (isset($_REQUEST['address']))
  113. $customer['address'] = $_REQUEST['address'];
  114. else
  115. $customer['address'] = '';
  116. if (isset($_REQUEST['company']))
  117. $customer['company'] = $_REQUEST['company'];
  118. else
  119. $customer['company'] = '';
  120. if (isset($_REQUEST['mobile']))
  121. $customer['mobile'] = $_REQUEST['mobile'];
  122. else
  123. $customer['mobile'] = '';
  124. if (isset($_REQUEST['home']))
  125. $customer['home'] = $_REQUEST['home'];
  126. else
  127. $customer['home'] = '';
  128. if (isset($_REQUEST['email']))
  129. $customer['email'] = $_REQUEST['email'];
  130. else
  131. $customer['email'] = '';
  132. if (isset($_REQUEST['reenteremail']))
  133. $customer['reenteremail'] = $_REQUEST['reenteremail'];
  134. else
  135. $customer['reenteremail'] = '';
  136. ?>
  137. <div id="registration" >Registration</div>
  138. <div class="register-icon"></div>
  139. <?php
  140. if (isset($error) && count($error) > 0) {
  141. ?>
  142. <div class="error-info form-info">
  143. <?php foreach ($error as $handle) {
  144. echo "<p>$handle</p>";
  145. } ?>
  146. </div>
  147. <?php
  148. }
  149. ?>
  150. <form name="registerform" id="registerform" action="register.php" method="post">
  151. <table class="formview" width="100%" border="0" cellspacing="3px" cellpadding="3px">
  152. <tr>
  153. <td class="LabelCell Required">NRIC / FIN <span class="hint">(Identity for account)</span></td>
  154. <td><input type="text" name="nric" id="nric" maxlength="25" class="input Required AlphaNumberic" value="<?php echo $customer['nric']; ?>" size="20" tabindex="10" /></td>
  155. </tr>
  156. <tr>
  157. <td class="LabelCell Required">Name</td>
  158. <td><input type="text" name="name" id="name" maxlength="255" class="input Required" value="<?php echo $customer['name']; ?>" size="20" tabindex="20" /></td>
  159. </tr>
  160. <tr>
  161. <td class="LabelCell Required">Date of Birth <span class="hint">(DD/MM/YYYY)</span></td>
  162. <td><input type="text" name="dob" id="dob" maxlength="10" class="input Required ValidDate" value="<?php echo $customer['dob']; ?>" size="20" tabindex="30" /></td>
  163. </tr>
  164. <tr>
  165. <td class="LabelCell">Address</td>
  166. <td><input type="text" name="address" id="address" maxlength="500" class="input" value="<?php echo $customer['address']; ?>" size="20" tabindex="40" /></td>
  167. </tr>
  168. <tr>
  169. <td class="LabelCell Required">Company <span class="hint">(N.A. if not applicable)</span></td>
  170. <td><input type="text" name="company" id="company" maxlength="500" class="input Required" value="<?php echo $customer['company']; ?>" size="20" tabindex="50" /></td>
  171. </tr>
  172. <tr>
  173. <td class="SectionBar" colspan="2">
  174. Contacts
  175. </td>
  176. </tr>
  177. <tr>
  178. <td class="LabelCell Required">Mobile</td>
  179. <td><input type="text" name="mobile" id="mobile" maxlength="50" class="input Required" value="<?php echo $customer['mobile']; ?>" size="20" tabindex="60" /></td>
  180. </tr>
  181. <tr>
  182. <td class="LabelCell">Home</td>
  183. <td><input type="text" name="home" id="home" maxlength="50" class="input" value="<?php echo $customer['home']; ?>" size="20" tabindex="70" /></td>
  184. </tr>
  185. <tr>
  186. <td class="SectionBar" colspan="2">
  187. Email
  188. </td>
  189. </tr>
  190. <tr>
  191. <td class="LabelCell Required">Your Email <span class="hint">(due to activation)</span></td>
  192. <td><input type="text" name="email" id="email" maxlength="50" class="input Required ValidEmail" value="<?php echo $customer['email']; ?>" size="20" tabindex="80" /></td>
  193. </tr>
  194. <tr>
  195. <td class="LabelCell Required">Re-enter Email</td>
  196. <td><input type="text" name="reenteremail" id="reenteremail" maxlength="50" class="input Required ValidEmail" value="<?php echo $customer['reenteremail']; ?>" size="20" tabindex="90" /></td>
  197. </tr>
  198. <tr>
  199. <td class="SectionBar" colspan="2">
  200. Passwords
  201. </td>
  202. </tr>
  203. <tr>
  204. <td class="LabelCell Required">Your Password</td>
  205. <td><input type="password" name="password" id="password" maxlength="50" class="input Required" value="" size="20" tabindex="100" /></td>
  206. </tr>
  207. <tr>
  208. <td class="LabelCell Required">Re-enter Password</td>
  209. <td><input type="password" name="reenterpassword" id="reenterpassword" maxlength="50" class="input Required" value="" size="20" tabindex="110" /></td>
  210. </tr>
  211. <tr>
  212. <td class="SectionBar" colspan="2">
  213. Word Verification
  214. </td>
  215. </tr>
  216. <tr>
  217. <td class="LabelCell Required">Type the characters</td>
  218. <td>
  219. <img src="components/cool.php.captcha/captcha.php" id="captcha" />&nbsp;&nbsp;&nbsp;
  220. <!-- CHANGE TEXT LINK -->
  221. <a href="#" onclick="
  222. document.getElementById('captcha').src='components/cool.php.captcha/captcha.php?'+Math.random();
  223. document.getElementById('captcha-form').focus();"
  224. id="change-image">Not readable? Change text.</a>&nbsp;<br/><br/>
  225. <input type="text" name="captcha" id="captcha-form" class="input Required" tabindex="120" /><br/>
  226. </td>
  227. </tr>
  228. <tr>
  229. <td class="BottomToolBar" colspan="2">
  230. <input type="submit" name="register" id="register" class="button-primary" value="Register" tabindex="130"/>
  231. <a href="index.php" class="button-secondary" tabindex="140">Cancel</a>
  232. </td>
  233. </tr>
  234. </table>
  235. </form>
  236. <script type="text/javascript">
  237. $(document).ready(function() {
  238. loadValidation('registerform');
  239. <?php if ($_SERVER['REQUEST_METHOD'] != "POST") { ?>
  240. $("#nric").focus();
  241. <?php } ?>
  242. $( "#dob" ).datepicker({ dateFormat: 'dd/mm/yy'});
  243. });
  244. </script>