Advertisement
Guest User

Untitled

a guest
Jun 28th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.45 KB | None | 0 0
  1. <?php
  2.  
  3. class Web_Snippet_Legacy_Contact_ContactForms extends Web_Snippet_Legacy_Abstract {
  4.  
  5. protected $_name = 'ContactForms';
  6. protected $_category = 'Web_Category_Legacy_Contact';
  7.  
  8. /**
  9. * Parse it and return
  10. *
  11. * @return string
  12. */
  13. protected function dispatch() {
  14. $limit = $this->getProp('limit');
  15. require_once(self::getModx()->config['base_path'] . 'core/components/blank/lib/recaptchalib.php');
  16. $publickey = "intentionally left blank";
  17. $privatekey = "intentionally left blank";
  18.  
  19. if (isset($_POST['formid'])) {
  20. $resp = recaptcha_check_answer(
  21. $privatekey
  22. , 'intentionally left blank'
  23. , $_POST["recaptcha_challenge_field"]
  24. , $_POST["recaptcha_response_field"]
  25. );
  26. if (!$resp->is_valid) {
  27. $captcha_fail = true;
  28. }
  29. }
  30.  
  31. if (isset($_POST['formid']) && !isset($captcha_fail)) {
  32. $submitted_form = self::getModx()->getObject('modResource', array('id' => $_POST['formid']));
  33.  
  34. $postal_code = $_POST['form']['postal'] = $_POST['form']['postal'] . $_POST['form']['postal1'];
  35. $_POST['form']['phone'] = $_POST['form']['phone'] . $_POST['form']['phone2'] . $_POST['form']['phone3'];
  36. unset($_POST['form']['postal1']);
  37. unset($_POST['form']['phone2']);
  38. unset($_POST['form']['phone3']);
  39.  
  40. $fieldmap = array();
  41. $fieldmap['name'] = 'Name';
  42. $fieldmap['city'] = 'City';
  43. $fieldmap['title'] = 'Title';
  44. $fieldmap['province'] = 'Province';
  45. $fieldmap['address'] = 'Address';
  46. $fieldmap['email'] = 'Email';
  47. $fieldmap['postal'] = 'Postal Code';
  48. $fieldmap['phone'] = 'Phone Number';
  49. $fieldmap['productType'] = 'Interested Product Types';
  50. $fieldmap['moreInfo'] = 'I would like more information on';
  51. $fieldmap['comments'] = 'Comments';
  52. $fieldmap['school'] = 'School';
  53. $fieldmap['company'] = 'Company';
  54. $fieldmap['crossroads'] = 'Main Intersection';
  55. $fieldmap['propertytype'] = 'Property Type';
  56. $fieldmap['zoning'] = 'Zoning';
  57. $fieldmap['locationdetails'] = 'Location Details';
  58.  
  59. if (self::getModx()->lang == 'fr') {
  60. switch ($submitted_form->get('id')) {
  61. case 86:
  62. $subject = 'Possibilit&eacute; d\'affichage';
  63. break;
  64. case 87:
  65. $subject = 'Location d\'une propri&eacute;t&eacute; ou d\'un &eacute;difice';
  66. break;
  67. case 91:
  68. $subject = 'Demande de proposition';
  69. break;
  70. case 92:
  71. $subject = 'Demande d\'un fournisseur';
  72. break;
  73. case 90:
  74. $subject = 'Renseignements g&eacute;n&eacute;raux';
  75. break;
  76. case 336:
  77. $subject = '';
  78. break;
  79. case 89:
  80. $subject = 'Demande d\'un &eacute;tudiant';
  81. break;
  82. }
  83.  
  84. $mail_subject = 'Requ&ecirc;te via site Web : ' . $subject;
  85. } else {
  86. switch ($submitted_form->get('id')) {
  87. case 86:
  88. $subject = ' Advertising Opportunities';
  89. break;
  90. case 87:
  91. $subject = ' Leasing Property or Building';
  92. break;
  93. case 91:
  94. $subject = ' Request for Proposal';
  95. break;
  96. case 92:
  97. $subject = ' Supplier Request';
  98. break;
  99. case 90:
  100. $subject = ' General Information';
  101. break;
  102. case 336:
  103. $subject = '';
  104. break;
  105. case 89:
  106. $subject = 'Student Request';
  107. break;
  108. }
  109.  
  110. $mail_subject = 'Website Inquiry: ' . $subject;
  111. ;
  112. }
  113.  
  114.  
  115. if (self::getModx()->lang == 'fr') {
  116. $fieldmap = array();
  117. $fieldmap['name'] = 'Nom ';
  118. $fieldmap['city'] = 'Ville ';
  119. $fieldmap['title'] = 'Titre ';
  120. $fieldmap['province'] = 'Province ';
  121. $fieldmap['address'] = 'Adresse ';
  122. $fieldmap['email'] = 'Courriel ';
  123. $fieldmap['postal'] = 'Code postal ';
  124. $fieldmap['phone'] = 'T&eacute;l&eacute;phone ';
  125. $fieldmap['productType'] = 'Types de produits int&eacute;ress&eacute;es ';
  126. $fieldmap['moreInfo'] = 'Je voudrais plus d\'informations sur ';
  127. $fieldmap['comments'] = 'Commentaires ';
  128. $fieldmap['school'] = 'L\'&eacute;cole ';
  129. $fieldmap['company'] = 'Soci&eacute;t&eacute; ';
  130. $fieldmap['crossroads'] = 'Voie de circulation principale &agrave; proximit&eacute;';
  131. $fieldmap['propertytype'] = 'Type de propri&eacute;t&eacute; ';
  132. $fieldmap['zoning'] = 'Zonage ';
  133. $fieldmap['locationdetails'] = 'D&eacutetails de l\'emplacement';
  134.  
  135. $message = "Cette demande, re&ccedil;ue via le site 192.168.4.64 a &eacute;t&eacute; exp&eacute;di&eacute;e par " . htmlentities(filter_var($_POST['form']['name'])) . " le " . date('Y-m-d') . " &agrave; " . date('H:i:s') . " et concerne le formulaire intitul&eacute; " . $subject . ". Cette personne recevra &eacute;galement un avis automatique d&eacute;taillant vos coordonn&eacute;es afin qu'elle puisse effectuer un suivi aupr&egrave;s de vous. Veuillez r&eacute;pondre &agrave; l'int&eacute;rieur de 24 &agrave; 48 heures ou transf&eacute;rez la demande &agrave; un autre membre de l'&eacute;quipe afin de garantir le suivi de la demande.<br><br>\n\n";
  136. } else {
  137. $fieldmap = array();
  138. $fieldmap['name'] = 'Name';
  139. $fieldmap['city'] = 'City';
  140. $fieldmap['title'] = 'Title';
  141. $fieldmap['province'] = 'Province';
  142. $fieldmap['address'] = 'Address';
  143. $fieldmap['email'] = 'Email';
  144. $fieldmap['postal'] = 'Postal Code';
  145. $fieldmap['phone'] = 'Phone Number';
  146. $fieldmap['productType'] = 'Interested Product Types';
  147. $fieldmap['moreInfo'] = 'I would like more information on';
  148. $fieldmap['comments'] = 'Comments';
  149. $fieldmap['school'] = 'School';
  150. $fieldmap['company'] = 'Company';
  151. $fieldmap['crossroads'] = 'Main Intersection';
  152. $fieldmap['propertytype'] = 'Property Type';
  153. $fieldmap['zoning'] = 'Zoning';
  154. $fieldmap['locationdetails'] = 'Location Details';
  155.  
  156. $message = "The following request from 192.168.4.64 has been sent by " . htmlentities(filter_var($_POST['form']['name'])) . " at " . date('Y-m-d H:i:s') . " regarding " . $subject . " . This person will have also received an automatic notification containing your contact information for follow-up purposes. Please respond within 24-48 hours or forward to another team member for the appropriate follow-up.<br><br>\n\n";
  157. }
  158.  
  159. foreach ($_POST['form'] as $field_name => $form_data) {
  160. if (is_array($form_data)) {
  161. $message .= $fieldmap[$field_name] . ":<br>\n";
  162.  
  163. foreach ($form_data as $val) {
  164. if (trim($val))
  165. $message .= htmlentities(filter_var($val), ENT_NOQUOTES) . "<br>\n";
  166. }
  167.  
  168. $message .= "<br>\n";
  169. }
  170. else {
  171. if (trim($form_data))
  172. $message .= $fieldmap[$field_name] . ': ' . htmlentities(filter_var($form_data), ENT_NOQUOTES) . "<br>\n";
  173. }
  174. }
  175.  
  176. $employee = self::getModx()->getObject('modResource', array('id' => $_POST['employeeid']));
  177. $con_subject = $mail_subject;
  178.  
  179.  
  180. if (self::getModx()->lang == 'fr') {
  181. $from = 'Info PATTISON';
  182. } else {
  183. $from = 'PATTISON Info';
  184. }
  185.  
  186. if ($_SERVER['REMOTE_ADDR'] == '192.168.4.64') {
  187. mail('blank', html_entity_decode($con_subject), $message, "MIME-Version: 1.0\r\nContent-type: text/html; charset=ISO-8859-2\r\nFrom: \"" . $from . "\" <info_reply@192.168.4.64>");
  188. } else {
  189. mail($employee->getTVValue('Employee Email Address'), html_entity_decode($con_subject), $message, "MIME-Version: 1.0\r\nContent-type: text/html; charset=ISO-8859-2\r\nFrom: \"" . $from
  190. . "\" <info_reply@192.168.4.64>");
  191. }
  192. $alias_var = $GLOBALS['lang']['tv'][self::getModx()->lang]['alias'];
  193. $response_var = $GLOBALS['lang']['tv'][self::getModx()->lang]['formresponder'];
  194. $employee_title_var = $GLOBALS['lang']['tv'][self::getModx()->lang]['jobtitle'];
  195.  
  196. $curr_page = self::getModx()->resource;
  197. $response = $submitted_form->getTVValue($response_var);
  198. $response = str_replace(chr(194), '', $response);
  199. $office_location = self::getModx()->getObject('modResource', array('id' => $employee->get('parent')));
  200.  
  201. $response = str_replace(array('{name}', '{date}', '{contact-name}', '{contact-title}', '{contact-email}', '{office-city}', '{office-province}', '{office-postalcode}', '{office-address}', '{office-telephone}', '{office-fax}'), array(ucwords($_POST['form']['name']), date('d/m/Y'), $employee->get('pagetitle'), $employee->getTVValue($employee_title_var), $employee->getTVValue('Employee Email Address'), $office_location->getTVValue('Office City'), $office_location->getTVValue('Office Province'), $office_location->getTVValue('Office Postal Code'), $office_location->getTVValue('Office Address'), $office_location->getTVValue('Office Telephone Number'), $office_location->getTVValue('Office Fax Number')), $response);
  202.  
  203. if (self::getModx()->lang == 'fr')
  204. $subject = 'Confirmation de votre demande : ' . $submitted_form->getTVValue('French Form Title');
  205. else
  206. $subject = 'Confirmation of your request: ' . $submitted_form->getTVValue('English Form Title');
  207.  
  208. mail($_POST['form']['email'], html_entity_decode(strip_tags($subject)), $response, "MIME-Version: 1.0\r\nContent-type: text/html; charset=ISO-8859-2\r\nFrom: \"" . $from . "\" <info_reply@192.168.4.64>");
  209.  
  210. header('Location: ' . $curr_page->getTVValue($alias_var) . '?sent-form=1');
  211.  
  212. die;
  213. }
  214.  
  215.  
  216. $output = '<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>';
  217.  
  218. if (self::getModx()->lang == 'en')
  219. $output .= '<p style="width: 350px; font-weight: bold;"><br>Thank you for your interest, you will be contacted by the appropriate employee when your request has been reviewed.</p>';
  220. else
  221. $output .= '<p style="width: 350px; font-weight: bold;">Je vous remercie de votre int&eacute;r&eacute;t, vous serez contact&eacute; par l\'employ&eacute; appropri&eacute; lorsque votre demande aura &eacute;t&eacute; examin&eacute;e.</p>';
  222.  
  223.  
  224. $form_pages = self::getModx()->getCollection('modResource', array('parent' => self::getModx()->resource->get('id')));
  225.  
  226. $forms = array();
  227.  
  228. $name_var = $GLOBALS['lang']['tv'][self::getModx()->lang]['formtitle'];
  229.  
  230. $output .= '<label for="topic">[[!get-lang-static?variable=topic]]:</label>
  231. <select id="topic" name="topic" onchange="$(\'.form\').hide(); $(\'#\' + $(this).val()).show(); if ($(\'div.form\').eq($(this).attr(\'selectedIndex\') - 1).attr(\'submittable\') != \'No\') { $(\'form input[type=submit]:visible\').before($(\'#captcha_container\').show()); Recaptcha.create(\'' . $publickey . '\', $(this).val() + \'_captcha_container\', { theme: \'clean\' }); }">
  232. <option value="">-- [[!get-lang-static?variable=selecttopic]] --</option>';
  233.  
  234. foreach ($form_pages as $form) {
  235. $output .= '<option value="' . strtolower(str_replace(" ", "", $form->get('pagetitle'))) . '" ' . ($form->get('id') == $_POST['formid'] ? 'SELECTED' : '') . '>' . $form->getTVValue($name_var) . '</option>';
  236. }
  237.  
  238. $output .= '</select>';
  239. $count = 1;
  240. foreach ($form_pages as $key => $form) {
  241. $name_var = $GLOBALS['lang']['tv'][self::getModx()->lang]['formtagline'];
  242. $output .= '<div class="form" id="' . strtolower(str_replace(" ", "", $form->get('pagetitle'))) . '" style="' . ($form->get('id') == $_POST['formid'] ? '' : 'display: none;') . '" submittable="' . $form->getTVValue('Submittable') . '">';
  243. $output .= '<div class="required" style="width: 375px; margin-right: 0px;">*[[!get-lang-static?variable=requiredfields]]</div>';
  244. $output .= '<form id="' . strtolower(str_replace(" ", "", $form->get('pagetitle'))) . '" action="[[!get-lang-tv?variable=alias]]" method="POST" onsubmit="return ' . strtolower(str_replace(" ", "", $form->get('pagetitle'))) . '_submit();">';
  245. $output .= '<input type="hidden" name="formid" value="' . $form->get('id') . '">';
  246. $output .= '<input type="hidden" id="employeeid" name="employeeid" value="' . $form->get('id') . '">';
  247.  
  248. $output .= '
  249.  
  250.  
  251. <!-- RZAK:START:' . $form->get('pagetitle') . '-->
  252.  
  253. ';
  254. $output .= self::getModx()->runSnippet($form->getTVValue('Form'), array('captcha_fail' => $captcha_fail, 'tagline' => $form->getTVValue($name_var), 'form_data' => $_POST['form'], 'form' => $form));
  255. $output .= '
  256.  
  257.  
  258. <!-- RZAK:END:' . $form->get('pagetitle') . '-->
  259.  
  260. ';
  261.  
  262. $output .= '<div id="' . strtolower(str_replace(" ", "", $form->get('pagetitle'))) . '_captcha_container"></div>';
  263.  
  264. if ($form->getTVValue('Submittable') != 'No')
  265. $output .= '<br/><a style="margin-left: 115px;" href="#" onclick="$(\'form\').eq(' . $count . ').submit(); return false;" class="button">[[!get-lang-static?variable=submit]]</a>';
  266.  
  267. $output .= '</form>';
  268. $output .= '</div>';
  269.  
  270. $count++;
  271. }
  272.  
  273. if ($_GET['form']) {
  274. $output .= '<script>
  275. $(\'#topic\').val(\'' . $_GET['form'] . '\');
  276. $(\'#\' + $(\'#topic\').val()).show();
  277.  
  278. ';
  279.  
  280. if ($_GET['form'] != 'jobopportunities')
  281. $output .= '
  282. $(\'form input[type=submit]:visible\').before($(\'#captcha_container\').show());
  283. Recaptcha.create(\'' . $publickey . '\', $(\'#topic\').val() + \'_captcha_container\', { theme: \'clean\' }); ';
  284.  
  285. $output .= '</script>';
  286. }
  287.  
  288. if ($_POST['formid']) {
  289. $output .= '<script>$(\'#topic\').trigger(\'onchange\');</script>';
  290. }
  291.  
  292.  
  293. $output .= '
  294.  
  295. <div class="clear"></div>
  296. <div class="clear"></div>';
  297.  
  298.  
  299. return $output;
  300. }
  301.  
  302. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement