Advertisement
Guest User

Untitled

a guest
Nov 10th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.25 KB | None | 0 0
  1. <?
  2.  
  3. class DriverApplicationController extends ApplicationController {
  4.  
  5. function main() {
  6. $common_trucks = array(
  7. 'Tanker',
  8. 'Bus-Straight',
  9. 'Bus-Articulated',
  10. 'Cabover Tractor',
  11. 'Class B Vehicle',
  12. 'Conventional Tractor',
  13. 'Tractor-Trailer',
  14. 'Day Cab',
  15. 'Day Cab Conventional',
  16. 'Dump Truck',
  17. 'LC Truck',
  18. 'Straight Truck',
  19. 'Other'
  20. );
  21. $common_trailers = array(
  22. 'Flatbed',
  23. 'Van',
  24. 'Container',
  25. 'Doubles',
  26. 'Liftgate',
  27. 'Reefer Trailer',
  28. 'Tank Trailer',
  29. 'Step Deck',
  30. 'Other'
  31. );
  32. $trailer_lengths = array(
  33. '31 feet or less',
  34. '32 to 44 feet',
  35. '45 to 52 feet',
  36. '53 feet or more',
  37. 'Other'
  38. );
  39.  
  40. $this->assign('common_trucks', $common_trucks);
  41. $this->assign('common_trailers', $common_trailers);
  42. $this->assign('trailer_lengths', $trailer_lengths);
  43.  
  44. $this->assign('states', get_states());
  45. $this->assign('countries', get_countries());
  46.  
  47. $data = array(
  48. 'pi' => array(
  49. 'country_id' => 'US'
  50. ),
  51. 'employment0' => array(
  52. 'country_id' => 'US'
  53. )
  54. );
  55. if (isset($_GET['_debug']))
  56. $data = array(
  57. 'pi' => array(
  58. 'first_name' => 'Marius',
  59. 'last_name' => 'Valeanu',
  60. 'address' => '8 W Maple St',
  61. 'city' => 'Chicago',
  62. 'state_id' => 'IL',
  63. 'zip' => '66000',
  64. 'country_id' => 'US',
  65. 'address_since_m' => '01',
  66. 'address_since_y' => '2006',
  67. 'ssn' => '123456789',
  68. 'dob_m' => '09',
  69. 'dob_d' => '03',
  70. 'dob_y' => '1979',
  71. 'phone' => '1234567890',
  72. 'alt_phone' => '0987654321',
  73. 'contact_time' => '9am - 6pm',
  74. 'how' => 'Friends'
  75. ),
  76. 'gi' => array(
  77. 'us_citizen' => 'yes',
  78. 'eligible' => 'yes',
  79. 'employed' => 'yes',
  80. 'english' => 'Yes',
  81. 'worked_before' => 'no',
  82. 'any_other_name' => 'no',
  83. 'notify' => 'Silviana Valeanu, Same address, 0760830522'
  84. ),
  85. 'de' => array(
  86. 'experience_st' => '1 year',
  87. 'experience_tst' => '2 years',
  88. 'experience_ttt' => '3 years',
  89. 'awards' => 'None'
  90. ),
  91. 'ed' => array(
  92. 'highest_grade' => 'University',
  93. 'last_school' => 'Al. I. Cuza, Iasi, RO'
  94. ),
  95. 'licenses' => array(
  96. 'no' => '123',
  97. 'expiration' => '07/12/2024',
  98. 'physical_expiration' => '07/11/2024',
  99. 'state' => 'IL',
  100. 'current' => 'yes',
  101. 'commercial' => 'yes',
  102. 'cdl_class' => 'Some class'
  103. ),
  104. 'endorsements' => array(
  105. 'tanker' => 'Ta1',
  106. 'HAZMAT' => 'HA2',
  107. 'x' => 'x3',
  108. 'dt' => 'dt4'
  109. ),
  110. 'military' => array(
  111. 'service' => 'Not done'
  112. ),
  113. 'employment0' => array(
  114. 'start_m' => '01',
  115. 'start_y' => '2008',
  116. 'company' => 'Image Factory',
  117. 'street' => '2310 Morning Way',
  118. 'city' => 'La Jolla',
  119. 'state_id' => 'CA',
  120. 'zip' => '90100',
  121. 'country_id' => 'US',
  122. 'phone' => '1234567890',
  123. 'position' => 'Programmer',
  124. 'reason' => 'Other better offer',
  125. 'commercial' => 'yes',
  126. 'terminated' => 'no',
  127. 'fmcsr' => 'no',
  128. 'sensitive' => 'no',
  129. 'areas' => 'California',
  130. 'miles' => '50 - 60',
  131. 'pay' => 'so so',
  132. 'equipment' => 'Tanker',
  133. 'trailer' => 'Van',
  134. 'length' => '31 feet or less'
  135. ),
  136. 'mvr' => array(
  137. 'privilege' => 'no',
  138. 'suspension' => 'no',
  139. 'alcohol' => 'no',
  140. 'drug' => 'no',
  141. 'reckless' => 'no',
  142. 'positive' => 'no'
  143. ),
  144. 'tcv' => array(
  145. 'violations' => 'no'
  146. ),
  147. 'var' => array(
  148. 'involved' => 'no'
  149. ),
  150. 'cr' => array(
  151. 'convicted' => 'no',
  152. 'deferred' => 'no',
  153. 'felony' => 'no',
  154. 'permit' => 'NA',
  155. 'misdemeanor' => 'no'
  156. )
  157. );
  158. $this->assign('data', $data);
  159.  
  160. $content = get_content('driver-application');
  161. $this->assign('content', $content);
  162. $this->assign('_page_title', $content['title']);
  163. }
  164.  
  165. function post() {
  166. $data = $_POST;
  167. clean_post_data_rec($data);
  168.  
  169. $return = array('success' => 1, 'step' => 1);
  170. if (!isset($data['step']) || $data['step'] < 1 || $data['step'] > 4) {
  171. $return['success'] = 0;
  172. $return['message'] = 'Current form step is invalid!';
  173. }
  174. else {
  175. for ($i = 1; $i <= $data['step']; $i++) {
  176. $return['step'] = $i;
  177. $method = 'checkStep' . intval($i);
  178. if (method_exists($this, $method)) {
  179. $return = array_merge($return, $this->$method($data));
  180. if (!$return['success'])
  181. break;
  182. }
  183. }
  184. }
  185.  
  186. if ($return['success'] && $data['step'] == 4) {
  187. $pdf_file = $this->generatePdf($data);
  188. send_mail(
  189. CONTACT_EMAIL,
  190. 'Driver Application: ' . $data['pi']['last_name'] . ', ' . $data['pi']['first_name'],
  191. 'You can find the pdf application attached.',
  192. false,
  193. array(rewrite_escape(date('Y m d') . ' ' . $data['pi']['last_name'] . ' ' . $data['pi']['first_name'], '_') => $pdf_file)
  194. );
  195. unlink($pdf_file);
  196.  
  197. $return['message'] = "Your application has been successfully received!\nThank you for your time.";
  198. }
  199.  
  200. header('Cache-Control: no-cache, must-revalidate');
  201. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  202. header('Content-type: application/json');
  203. echo json_encode($return);
  204. return $this->render(null);
  205. }
  206.  
  207. function checkStep1($data) {
  208. $return = array('error_fields' => array());
  209.  
  210. $fields = array(
  211. 'first_name',
  212. 'last_name',
  213. 'address',
  214. 'city',
  215. 'state_id',
  216. 'zip',
  217. 'country_id',
  218. 'address_since_m',
  219. 'address_since_y',
  220. /*'address_3_years',*/
  221. 'ssn',
  222. 'dob_m',
  223. 'dob_d',
  224. 'dob_y',
  225. 'phone',
  226. 'contact_time',
  227. 'how'
  228. );
  229. foreach ($fields as $field)
  230. if (!isset($data['pi'][$field]))
  231. $return['error_fields'][] = 'pi-' . $field;
  232.  
  233. if ($return['error_fields']) {
  234. $return['success'] = 0;
  235. $return['message'] = 'The fields in red are required!';
  236. }
  237. else {
  238. $return['message'] = array();
  239.  
  240. $address_since = date('Y-m', strtotime($data['pi']['address_since_y'] . '-' . $data['pi']['address_since_m'] . '-01'));
  241. if ($address_since > date('Y-m', strtotime('-7 years'))) {
  242. $return['error_fields'][] = 'pi-address_3_years';
  243. $return['message'][] = 'Please enter previous residences to cover the last 7 years!';
  244. }
  245.  
  246. $dob = date('Y-m-d', strtotime($data['pi']['dob_y'] . '-' . $data['pi']['dob_m'] . '-' . $data['pi']['dob_d']));
  247. if ($dob > date('Y-m-d', strtotime('-18 years'))) {
  248. $return['error_fields'][] = 'pi-dob_m';
  249. $return['message'][] = 'You must be 18 to apply!';
  250. }
  251.  
  252. if ($data['pi']['country_id'] == 'US' && strlen(preg_replace('/[^\d]+/', '', $data['pi']['ssn'])) != 9) {
  253. $return['error_fields'][] = 'pi-ssn';
  254. $return['message'][] = 'SSN is invalid (9 digits required)!';
  255. }
  256.  
  257. if (strlen(preg_replace('/[^\d]+/', '', $data['pi']['phone'])) < 10) {
  258. $return['error_fields'][] = 'pi-phone';
  259. $return['message'][] = 'Phone is invalid (10 digits required)!';
  260. }
  261.  
  262. if (isset($data['pi']['alt_phone']) && strlen(preg_replace('/[^\d]+/', '', $data['pi']['alt_phone'])) < 10) {
  263. $return['error_fields'][] = 'pi-alt_phone';
  264. $return['message'][] = 'Alt. phone is invalid (10 digits required)!';
  265. }
  266.  
  267. if ($return['error_fields']) {
  268. $return['success'] = 0;
  269. $return['message'] = implode("\n", $return['message']);
  270. }
  271. else
  272. unset($return['error_fields'], $return['message']);
  273. }
  274.  
  275. return $return;
  276. }
  277.  
  278.  
  279. function generatePdf($data) {
  280. require_once(LIB_DIR . 'tcpdf/config/lang/eng.php');
  281. require_once(LIB_DIR . 'tcpdf/tcpdf.php');
  282.  
  283. // create new PDF document
  284. $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  285.  
  286. // set document information
  287. $pdf->SetCreator(PDF_CREATOR);
  288. $pdf->SetAuthor(SITE_NAME);
  289. $pdf->SetTitle('Driver Application');
  290. $pdf->SetSubject('Driver Application');
  291. $pdf->SetKeywords('Driver Application');
  292.  
  293. // remove default header/footer
  294. $pdf->setPrintHeader(false);
  295. $pdf->setPrintFooter(false);
  296.  
  297. // set default monospaced font
  298. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  299.  
  300. //set margins
  301. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  302.  
  303. //set auto page breaks
  304. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  305.  
  306. //set image scale factor
  307. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  308.  
  309. //set some language-dependent strings
  310. $pdf->setLanguageArray($l);
  311.  
  312. // ---------------------------------------------------------
  313.  
  314. // add a page
  315. $pdf->AddPage();
  316.  
  317. // start writing
  318. $pdf->SetFont('times', 'B', 24);
  319. $txt = 'Driver Application';
  320. $pdf->Write(0, $txt, '', 0, 'C');
  321. $pdf->Ln(20);
  322.  
  323. $groups = array(
  324. 'PERSONAL INFORMATION' => array(
  325. array('Name:', $data['pi']['last_name'] . ', ' . $data['pi']['first_name']),
  326. array('Address:', $data['pi']['address']),
  327. array('City, State Zip:', $data['pi']['city'] . ', ' . ($data['pi']['state_id'] ? $data['pi']['state_id'] : 'Non US') . ' ' . $data['pi']['zip']),
  328. array('Country:', $this->dbi->getOne('select label from countries where id = ?', $data['pi']['country_id'])),
  329. array('Previous addressed:', isset($data['pi']['address_3_years']) ? $data['pi']['address_3_years'] : 'NA'),
  330. array('SSN:', $data['pi']['ssn']),
  331. array('Date of Birth:', $data['pi']['dob_m'] . '/' . $data['pi']['dob_d'] . '/' . $data['pi']['dob_y']),
  332. array('Phone:', $data['pi']['phone']),
  333. array('Alt. Phone:', isset($data['pi']['alt_phone']) ? $data['pi']['alt_phone'] : 'NA'),
  334. array('Best Contact Time:', $data['pi']['contact_time']),
  335. array('How did you hear about us?', $data['pi']['how'])
  336. ),
  337. 'GENERAL INFORMATION' => array(
  338. array('What position are you applying for?', 'Sub Contractor'),
  339. array('If you are applying for a sub-contractor position, who would you be driving for?', 'Butacis Trucking'),
  340. array('Are you a U.S. citizen?', $data['gi']['us_citizen']),
  341. array('Are you legally eligible for employment in the United States?', $data['gi']['eligible']),
  342. array('Are you currently employed?', $data['gi']['employed']),
  343. array('What date did your last employment end?', isset($data['gi']['employment_end']) ? $data['gi']['employment_end'] : 'NA'),
  344. array('Do you read, write and speak English?', $data['gi']['english']),
  345. array('Have you ever worked for this company before?', $data['gi']['worked_before']),
  346. array('Enter start and end dates, location, position, rate of pay, and reason for leaving:', isset($data['gi']['worked_before_details']) ? $data['gi']['worked_before_details'] : 'NA'),
  347. /*array('Do you have a current TWIC card?', $data['gi']['twic']),
  348. array('Expiration date:', isset($data['gi']['twic_expiration']) ? $data['gi']['twic_expiration'] : 'NA'),*/
  349. array('Please enter the names of any relatives employed here:', isset($data['gi']['relatives']) ? $data['gi']['relatives'] : 'NA'),
  350. array('Have you ever been known by any other name?', $data['gi']['any_other_name']),
  351. array('Enter name:', isset($data['gi']['other_name']) ? $data['gi']['other_name'] : 'NA'),
  352. array('Who referred you?', isset($data['gi']['referrals']) ? $data['gi']['referrals'] : 'NA'),
  353. array('In case of Emergency, notify (list name, address, and phone):', $data['gi']['notify']),
  354. ),
  355. 'DRIVING EXPERIENCE' => array(
  356. array('How much experience do you have in each of these types of equipment?', ''),
  357. array('Straight Truck:', $data['de']['experience_st']),
  358. array('Tractor and Semi-Trailer:', $data['de']['experience_tst']),
  359. array('Tractor - Two Trailers:', $data['de']['experience_ttt']),
  360. array('Other:', isset($data['de']['experience_other']) ? $data['de']['experience_other'] : 'NA'),
  361. array('Which safe driving awards do you hold and from whom?', $data['de']['awards'])
  362. ),
  363. 'EDUCATION' => array(
  364. array('List highest grade completed:', $data['ed']['highest_grade']),
  365. array('List last school attended (name, city, and state):', $data['ed']['last_school'])
  366. ),
  367. 'LICENSES' => array(
  368. array('License Number:', $data['licenses']['no']),
  369. array('License Expiration Date:', $data['licenses']['expiration']),
  370. array('Physical Expiration Date:', $data['licenses']['physical_expiration']),
  371. array('State, Country:', $data['licenses']['state']),
  372. array('Is this your current driver license?', $data['licenses']['current']),
  373. array('Is this a commercial driver license?', $data['licenses']['commercial']),
  374. array('CDL Class:', $data['licenses']['cdl_class'])
  375. ),
  376. 'ENDORSEMENTS' => array(
  377. array('Tanker Endorsement:', $data['endorsements']['tanker']),
  378. array('HAZMAT Endorsement:', $data['endorsements']['HAZMAT']),
  379. array('X Endorsement:', $data['endorsements']['x']),
  380. array('Doubles / Triples Endorsement:', $data['endorsements']['dt']),
  381. array('Other Endorsement:', isset($data['endorsements']['other']) ? $data['endorsements']['other'] : 'NA'),
  382. ),
  383. 'MILITARY' => array(
  384. array('Military Service:', $data['military']['service'])
  385. )
  386. );
  387. $groups['PREVIOUS EMPLOYMENT INFORMATION'] = array();
  388. for ($i = 0; $i < $data['employment_records']; $i++)
  389. $groups['EMPLOYMENT RECORD #' . ($i + 1)] = array(
  390. array('Starting Date:', $data['employment' . $i]['start_m'] . '/' . $data['employment' . $i]['start_y']),
  391. array('Ending Date:', isset($data['employment' . $i]['end_m']) && isset($data['employment' . $i]['end_y']) ? $data['employment' . $i]['end_m'] . '/' . $data['employment' . $i]['end_y'] : 'Current'),
  392. array('Company Name:', $data['employment' . $i]['company']),
  393. array('Street Address:', $data['employment' . $i]['street']),
  394. array('City, State Zip:', $data['employment' . $i]['city'] . ', ' . ($data['employment' . $i]['state_id'] ? $data['employment' . $i]['state_id'] : 'Non US') . ' ' . $data['employment' . $i]['zip']),
  395. array('Country:', $this->dbi->getOne('select label from countries where id = ?', $data['employment' . $i]['country_id'])),
  396. array('Telephone:', $data['employment' . $i]['phone']),
  397. array('Position Held:', $data['employment' . $i]['position']),
  398. array('Reason for Leaving:', isset($data['employment' . $i]['reason']) ? $data['employment' . $i]['reason'] : 'NA'),
  399. array('Did you operate a commercial motor vehicle?', $data['employment' . $i]['commercial']),
  400. array('Were you terminated?', $data['employment' . $i]['terminated']),
  401. array('Were you subject to the Federal Motor Carrier Safety Regulations while employed by this employer?', $data['employment' . $i]['fmcsr']),
  402. array('Did you perform any safety sensitive functions in this job, regulated by DOT, and subject to drug and alcohol testing?', $data['employment' . $i]['sensitive']),
  403. /*array('Is this your current employer?', $data['employment' . $i]['current']),*/
  404. array('Areas Driven:', $data['employment' . $i]['areas']),
  405. array('Miles Weekly:', $data['employment' . $i]['miles']),
  406. array('Pay Range (cents/mile):', $data['employment' . $i]['pay']),
  407. array('Type of Equipment:', $data['employment' . $i]['equipment']),
  408. array('Type Of Trailer:', $data['employment' . $i]['trailer']),
  409. array('Trailer Length:', $data['employment' . $i]['length'])
  410. );
  411. $groups['MOTOR VEHICLE RECORD'] = array(
  412. array('Has any license, permit or privilege ever been denied, suspended or revoked for any reason?', $data['mvr']['privilege']),
  413. array('Have you ever been convicted of driving during license suspension or revocation, or driving without a valid license or an expired license, or are any charges pending?', $data['mvr']['suspension']),
  414. array('Have you ever been convicted for any alcohol or controlled substance related offense while operating a motor vehicle, or are any charges pending?', $data['mvr']['alcohol']),
  415. array('Have you ever been convicted for possession, sale or transfer of a drug, marijuana, amphetamines, or derivatives thereof, or are any charges pending?', $data['mvr']['drug']),
  416. array('Have you ever been convicted of reckless driving, careless driving or careless operation of a motor vehicle, or are any charges pending?', $data['mvr']['reckless']),
  417. array('Have you ever tested positive, or refused to test, on any pre-employment drug or alcohol test administered by an employer to which you applied for, but did not obtain, safety-sensitive transportation work covered by DOT agency drug and alcohol testing rules during the past three years?', $data['mvr']['positive'])
  418. );
  419. $groups['TRAFFIC CONVICTIONS / VIOLATIONS'] = array(
  420. array('Have you had any moving violations or traffic convictions in the past 3 years?', $data['tcv']['violations']),
  421. array('Violation Date(s):', isset($data['tcv']['date']) ? $data['tcv']['date'] : 'NA'),
  422. array('Violation Charge(s)/Description(s):', isset($data['tcv']['description']) ? $data['tcv']['description'] : 'NA'),
  423. array('If Speeding, MPH over the speed limit:', isset($data['tcv']['mph']) ? $data['tcv']['mph'] : 'NA'),
  424. array('State(s):', isset($data['tcv']['state']) ? $data['tcv']['state'] : 'NA')
  425. );
  426. $penalties = array('Penalty/Fine (select all that apply):', '');
  427. if (isset($data['tcv']['penalty'])) {
  428. foreach ($data['tcv']['penalty'] as $penalty)
  429. $penalties[1] .= ($penalties[1] ? ', ' : '') . $penalty;
  430. }
  431. else
  432. $penalties[1] = 'NA';
  433. $groups['TRAFFIC CONVICTIONS / VIOLATIONS'][] = $penalties;
  434. $groups['TRAFFIC CONVICTIONS / VIOLATIONS'][] = array('Fine Amount (If Applicable):', isset($data['tcv']['amount']) ? $data['tcv']['amount'] : 'NA');
  435. $groups['TRAFFIC CONVICTIONS / VIOLATIONS'][] = array('Comments - If you answered "Other Penalty", please provide additional detail:', isset($data['tcv']['comments']) ? $data['tcv']['comments'] : 'NA');
  436. $groups['VEHICLE ACCIDENT RECORD'] = array(
  437. array('Were you involved in any accidents/incidents with any vehicle in the last 3 Years (even if not at fault)?', $data['var']['involved']),
  438. array('Date(s) of accident/incident:', isset($data['var']['date']) ? $data['var']['date'] : 'NA'),
  439. array('Type(s) of accident/incident:', isset($data['var']['type']) ? $data['var']['type'] : 'NA'),
  440. array('Please describe:', isset($data['var']['describe']) ? $data['var']['describe'] : 'NA'),
  441. array('Were you in a commercial vehicle?', $data['var']['commercial']),
  442. array('If yes, was this a Department of Transportation reportable accident?', $data['var']['reportable']),
  443. array('Were you at fault?', $data['var']['fault']),
  444. array('Were you ticketed?', $data['var']['ticketed']),
  445. array('State/Prov:', isset($data['var']['state']) ? $data['var']['state'] : 'NA'),
  446. );
  447. $groups['CRIMINAL RECORD'] = array(
  448. array('Have you ever been convicted of a crime?', $data['cr']['convicted']),
  449. array('Do you have any Deferred Prosecutions or any criminal charges pending?', $data['cr']['deferred']),
  450. array('Have you ever pled "guilty" to, been convicted of, pled "no contest" to a felony?', $data['cr']['felony']),
  451. array('If you have any felony convictions, do you currently hold a Ministers Permit to enter or exit Canada?', $data['cr']['permit']),
  452. array('Have you, within the last 7 years, pled guilty to, been convicted of, had prosecution deferred in connection with, or pled "no contest" to a misdemeanor?', $data['cr']['misdemeanor'])
  453. );
  454.  
  455. foreach ($groups as $group => $lines) {
  456. $pdf->SetFont('times', 'B', 14);
  457. $pdf->Write(0, $group, '', 0, 'C');
  458. $pdf->Ln(10);
  459.  
  460. foreach ($lines as $line) {
  461. $pdf->SetFont('times', 'I' . (!$line[1] ? 'B' : ''), 11);
  462. $pdf->Write(0, $line[0]);
  463. if ($line[1]) {
  464. $pdf->Ln();
  465. $pdf->SetFont('times', 'B', 12);
  466. $pdf->Write(0, $line[1]);
  467. }
  468. $pdf->Ln(10);
  469. }
  470.  
  471. $pdf->Ln(4);
  472. }
  473.  
  474. // ---------------------------------------------------------
  475.  
  476. //Close and output PDF document
  477. $filename = ROOT_DIR . TMP_DIR . generate_filename_from_time() . '.pdf';
  478. $pdf->Output($filename, 'F');
  479.  
  480. return $filename;
  481. }
  482.  
  483. }
  484.  
  485. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement