PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/recruitment/apply/submit_application_exec.php

https://bitbucket.org/lecturer34/hrmis
PHP | 238 lines | 184 code | 47 blank | 7 comment | 27 complexity | 9c22782e33e3bbf57d6ffdd0276ebe91 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. if (!isset($_SESSION)) {
  3. session_start();
  4. }
  5. if(!isset($_SESSION['user_account_row_id']) || $_SESSION['user_account_row_id'] < 1){
  6. include_once('../access_error.php');
  7. $redirectToURL = '../';
  8. header("location: $redirectToURL");
  9. exit();
  10. }
  11. $accountID = (int)$_SESSION['user_account_row_id'];
  12. if(!isset($_SESSION['msgDetails'])){
  13. $_SESSION['msgCaption'] = '';
  14. $_SESSION['msgDetails'] = '';
  15. }
  16. require_once('../helper_functions.php');
  17. require_once('../../lib/database.php');
  18. openConnection();
  19. $redirectToURL = '../profile/profile.php';
  20. //clear_application_submit_session_vars();
  21. $advert_id = $_SESSION['advert_id'] + 1024;
  22. if( isset($_POST['btnSubmitApplication']) || isset($_POST['btnCancel']) ){
  23. if (isset($_POST['btnCancel']) ) {
  24. header("location: $redirectToURL");
  25. exit();
  26. }else if (isset($_POST['btnSubmitApplication'])) {
  27. $comments = trim($_POST['comments']);
  28. if(!$comments || mb_strlen($comments = trim($comments)) == 0){
  29. $_SESSION['app_Comments'] = 'No Comments';
  30. }else{
  31. $_SESSION['app_Comments'] = $comments;
  32. }
  33. if (submit_validation_errors() > 0){
  34. //there were validation errors
  35. //and the result is stored in $_SESSION['msgDetails']
  36. $redirectToURL = './?ref_tag=' . $advert_id;
  37. }else{
  38. //there were NO validation errors; poceed to save data:
  39. $r_id = $_SESSION['advt_response_id'];
  40. $comments = clean($_SESSION['app_Comments']);
  41. $dt = date('Y-m-d');
  42. $q = "UPDATE tbladvertresponses SET datecompleted = '$dt', timecompleted = CURTIME(), applicantcomments = '$comments' ";
  43. $q .= "WHERE responseid = $r_id";
  44. $query = mysql_query($q);
  45. if(mysql_affected_rows() == 1){
  46. $c = 'OK';
  47. $e = '';
  48. //capture the CV 'as is' at the time of submitting this application:
  49. $applicant_row_id = $_SESSION['user_account_row_id'];
  50. $q = "SELECT d.titleid, d.surname, d.firstname, d.othernames, d.gender, d.maritalstatus, d.physicalchallenge, d.birthdate, ";
  51. $q .= "d.birthplace, d.hometown, d.lga, d.state, d.nationality, d.personnelid, d.profile_pic, q.yearobtained, q.institutionobtained, ";
  52. $q .= "q.fieldofstudyid, q.qualificationtypeid, q.degreeclassid, ql.certificate, qc.qualification AS degreeclass, sf.studyfield, ";
  53. $q .= "c.primaryphone, c.currentaddress, c.permanenthomeaddress, op.phonenumber as otherphone, op.alternateemail, ";
  54. $q .= "lg.lganame, st.statename, cc.countryname FROM tblapplicantsdetails AS d ";
  55. $q .= "LEFT JOIN tblapplicantshighestqual AS q ON d.appaccountrowid = q.appaccountrowid ";
  56. $q .= "LEFT JOIN tblqualificationslookup AS ql ON q.qualificationtypeid = ql.id ";
  57. $q .= "LEFT JOIN tblqualificationclass AS qc ON q.degreeclassid = qc.qualificationclassid ";
  58. $q .= "LEFT JOIN tblstudyfieldlookup AS sf ON q.fieldofstudyid = sf.id ";
  59. $q .= "LEFT JOIN tblapplicantscontacts AS c ON q.appaccountrowid = c.appaccountrowid ";
  60. $q .= "LEFT JOIN tblapplicantsotherphones AS op ON q.appaccountrowid = op.appaccountrowid ";
  61. $q .= "LEFT JOIN tbllga as lg ON d.lga = lg.lgaid ";
  62. $q .= "LEFT JOIN tblstate AS st ON d.state = st.stateid ";
  63. $q .= "LEFT JOIN tblcountries AS cc ON d.nationality = cc.countryid ";
  64. $q .= "WHERE d.appaccountrowid = $applicant_row_id";
  65. $query = mysql_query($q);
  66. $foundRecord = mysql_num_rows($query);
  67. if ($foundRecord == 1) {
  68. $row = mysql_fetch_assoc($query);
  69. $t_id = $row['titleid'];
  70. $s_name = $row['surname'];
  71. $f_name = $row['firstname'];
  72. $o_name = $row['othernames'];
  73. $gender = $row['gender'];
  74. $m_status = $row['maritalstatus'];
  75. $p_challenge = $row['physicalchallenge'];
  76. $b_date = $row['birthdate'];
  77. $b_place = $row['birthplace'];
  78. $h_town = $row['hometown'];
  79. $p_id = $row['personnelid'];
  80. $pic = $row['profile_pic'];
  81. $qual = $row['certificate'];
  82. $q_year = $row['yearobtained'];
  83. $q_inst = $row['institutionobtained'];
  84. $q_field = $row['studyfield'];
  85. $q_class = $row['degreeclass'];
  86. $p_phone = $row['primaryphone'];
  87. $c_address = $row['currentaddress'];
  88. $p_address = $row['permanenthomeaddress'];
  89. $o_phone = $row['otherphone'];
  90. $alt_email = $row['alternateemail'];
  91. $lga = 'N/A';
  92. if(isset($row['lganame'])){
  93. $lga = $row['lganame'];
  94. }
  95. $state = 'N/A';
  96. if(isset($row['statename'])){
  97. $state = $row['statename'];
  98. }
  99. $nationality = 'N/A';
  100. if(isset($row['countryname'])){
  101. $nationality = $row['countryname'];
  102. }
  103. $q = "INSERT INTO tblapplicantscvs (advertresponseid, titleid, surname, firstname, othernames, gender, maritalstatus, physicalchallenge, ";
  104. $q .= "birthdate, birthplace, hometown, lga, state, nationality, personnelid, profile_pic, highestqualification, yearobtained, ";
  105. $q .= "institutionobtained, fieldofstudy, degreeclass, mainphone, otherphone, alternateemail, contactaddress, permanenthomeaddress) ";
  106. $q .= "VALUES ($r_id, $t_id, '$s_name', '$f_name', '$o_name', '$gender', '$m_status', '$p_challenge', '$b_date', '$b_place', '$h_town', ";
  107. $q .= "'$lga', '$state', '$nationality', '$p_id', '$pic', '$qual', '$q_year', '$q_inst', '$q_field', '$q_class', '$p_phone', ";
  108. $q .= "'$o_phone', '$alt_email', '$c_address', '$p_address')";
  109. $query = mysql_query($q);
  110. $lastID = mysql_insert_id();
  111. //also catpture applicant's professional qualifications "as is" at this point:
  112. $q = "SELECT p.qualificationid, p.yearobtained, p.awardingbody, lk.name AS qualification_name ";
  113. $q .= "FROM tblapplicantsprofqualifications AS p INNER JOIN tblprofessionalqualslookup AS lk ";
  114. $q .= "ON p.qualificationid = lk.id WHERE p.appaccountrowid = $applicant_row_id";
  115. $query = mysql_query($q);
  116. $foundRecord = mysql_num_rows($query);
  117. if ($foundRecord > 0) {
  118. while($row = mysql_fetch_assoc($query)){
  119. $q_name = $row['qualification_name'];
  120. $q_year = $row['yearobtained'];
  121. $q_body = $row['awardingbody'];
  122. $q2 = "INSERT INTO tblapplicantscvsprofquals (cvrowid, qualification, yearobtained, awardingbody) ";
  123. $q2 .= "VALUES ($lastID, '$q_name', '$q_year', '$q_body')";
  124. $query2 = mysql_query($q2);
  125. }//end while
  126. }
  127. //also catpture applicant's work experience "as is" at this point:
  128. $q = "SELECT employer, positionheld, responsibilities, datefrom, dateto FROM tblapplicantsworkexperience WHERE appaccountrowid = $applicant_row_id";
  129. $query = mysql_query($q);
  130. $foundRecord = mysql_num_rows($query);
  131. if ($foundRecord > 0) {
  132. while($row = mysql_fetch_assoc($query)){
  133. $e_employer = $row['employer'];
  134. $e_position = $row['positionheld'];
  135. $e_responsibility = $row['responsibilities'];
  136. $e_datefrom = $row['datefrom'];
  137. $e_dateto = $row['dateto'];
  138. $q2 = "INSERT INTO tblapplicantscvsworkexp (cvrowid, employer, positionheld, responsibilities, datefrom, dateto) ";
  139. $q2 .= "VALUES ($lastID, '$e_employer', '$e_position', '$e_responsibility', '$e_datefrom', '$e_dateto')";
  140. $query2 = mysql_query($q2);
  141. }//end while
  142. }
  143. }
  144. clear_application_submit_session_vars();
  145. $app_id = applicant_submitted_this_application(($advert_id - 1024), $applicant_row_id);
  146. $redirectToURL = 'print_application.php?ref_tag=' . ($app_id + 1024);
  147. }else{
  148. $redirectToURL = './?ref_tag=' . $advert_id;
  149. $c = 'Error';
  150. $e = 'There was an error while submitting the job application to the Server: <br />' . mysql_error();
  151. }
  152. $_SESSION['msgCaption'] = $c;
  153. $_SESSION['msgDetails'] = '<font style="color:red; font-size:16px">' . $e . '</font>';
  154. }//end if (submit_validation_errors() > 0)
  155. }//end if (isset($_POST['btnCancel']))
  156. }else{
  157. include_once('access_error.php');
  158. $redirectToURL = '../';
  159. }//end if( isset($_POST['btnSave']) || isset($_POST['btnCancel']) )
  160. header("location: $redirectToURL");
  161. exit();
  162. function submit_validation_errors(){
  163. $comments = $_SESSION['app_Comments'];
  164. $rT = '';
  165. $errCount = 0;
  166. if(mb_strlen(trim($comments)) > 500){
  167. $rT .= '<li>Your comments should not exceed 500 characters.</li>';
  168. $errCount += 1;
  169. }
  170. if(! is_numeric($_SESSION['advt_response_id']) || (int)$_SESSION['advt_response_id'] < 1){
  171. $rT .= '<li>Invalid job application ID.</li>';
  172. $errCount += 1;
  173. }
  174. $_SESSION['msgCaption'] = '';
  175. $_SESSION['msgDetails'] = '';
  176. if($errCount > 0){
  177. if ($errCount == 1){
  178. $errCaption = 'Ooops! You Have 1 Issue to Fix';
  179. }else{
  180. $errCaption = 'Ooops! You Have ' . $errCount . ' Issues to Fix';
  181. }
  182. $rT = '<ul style="color:#FF0000">' . $rT . '</ul>';
  183. $_SESSION['msgCaption'] = $errCaption;
  184. $_SESSION['msgDetails'] = $rT;
  185. }
  186. return $errCount;
  187. }
  188. function clear_application_submit_session_vars(){
  189. $_SESSION['app_Comments'] = '';
  190. }
  191. ?>