PageRenderTime 64ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/administrator/components/com_rsform/helpers/rsform.php

https://bitbucket.org/biojazzard/joomla-eboracast
PHP | 3227 lines | 2600 code | 468 blank | 159 comment | 485 complexity | d761918b99cf7080f296165c389de889 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, MIT, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * @version 1.4.0
  4. * @package RSform!Pro 1.4.0
  5. * @copyright (C) 2007-2011 www.rsjoomla.com
  6. * @license GPL, http://www.gnu.org/copyleft/gpl.html
  7. */
  8. defined('_JEXEC') or die('Restricted access');
  9. require_once dirname(__FILE__).'/config.php';
  10. require_once dirname(__FILE__).'/version.php';
  11. // Product info
  12. if(!defined('_RSFORM_REVISION')) {
  13. $version = new RSFormProVersion();
  14. define('_RSFORM_PRODUCT', 'RSform!Pro');
  15. define('_RSFORM_VERSION', $version->long);
  16. define('_RSFORM_KEY', $version->key);
  17. define('_RSFORM_REVISION', $version->revision);
  18. }
  19. JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_rsform/tables');
  20. $cache = JFactory::getCache('com_rsform');
  21. $cache->clean();
  22. $lang = JFactory::getLanguage();
  23. $lang->load('com_rsform', JPATH_ADMINISTRATOR, 'en-GB', true);
  24. $lang->load('com_rsform', JPATH_ADMINISTRATOR, $lang->getDefault(), true);
  25. $lang->load('com_rsform', JPATH_ADMINISTRATOR, null, true);
  26. // Create the Legacy adapter
  27. $GLOBALS['RSadapter'] = RSFormProHelper::getLegacyAdapter();
  28. // Legacy function -- RSgetValidationRules()
  29. function RSgetValidationRules()
  30. {
  31. return RSFormProHelper::getValidationRules();
  32. }
  33. function _modifyResponsiveTemplate()
  34. {
  35. $buffer = JResponse::getBody();
  36. $buffer = trim($buffer);
  37. $lines = RSFormProHelper::explode($buffer);
  38. $line = $lines[0];
  39. if (strtolower($line) != '<!doctype html>')
  40. {
  41. // single line
  42. if (strpos($line, '>') !== false) {
  43. $buffer = str_replace($line, '<!doctype html>', $buffer);
  44. } else {
  45. // should be on multiple lines
  46. $i = 0;
  47. while (strpos($line, '>') === false) {
  48. $i++;
  49. $line = $lines[$i];
  50. }
  51. // bail out, we might be modifying something else
  52. if (strpos($line, '<') !== false) {
  53. return;
  54. }
  55. // remove the first lines...
  56. for ($j=0; $j<=$i; $j++) {
  57. unset($lines[$j]);
  58. }
  59. // add this on the first line
  60. array_unshift($lines, '<!doctype html>');
  61. // join the new buffer
  62. $buffer = implode("\r\n", $lines);
  63. }
  64. JResponse::setBody($buffer);
  65. }
  66. }
  67. class RSFormProHelper
  68. {
  69. public static function isJ16()
  70. {
  71. // just for legacy reasons
  72. return true;
  73. }
  74. public static function isJ($version) {
  75. static $cache = array();
  76. if (!isset($cache[$version])) {
  77. $jversion = new JVersion();
  78. $cache[$version] = $jversion->isCompatible($version);
  79. }
  80. return $cache[$version];
  81. }
  82. public static function getDate($date)
  83. {
  84. static $mask;
  85. if (!$mask) {
  86. $mask = RSFormProHelper::getConfig('global.date_mask');
  87. if (!$mask) {
  88. $mask = 'Y-m-d H:i:s';
  89. }
  90. }
  91. return JHTML::_('date', $date, $mask);
  92. }
  93. public static function getLegacyAdapter()
  94. {
  95. static $adapter;
  96. if (empty($adapter))
  97. {
  98. require_once JPATH_ADMINISTRATOR.'/components/com_rsform/helpers/legacy.php';
  99. $adapter = new RSAdapter();
  100. }
  101. return $adapter;
  102. }
  103. public static function getComponentId($name, $formId=0)
  104. {
  105. static $cache;
  106. if (!is_array($cache))
  107. $cache = array();
  108. if (empty($formId))
  109. {
  110. $formId = JRequest::getInt('formId');
  111. if (empty($formId))
  112. {
  113. $post = JRequest::getVar('form');
  114. $formId = (int) @$post['formId'];
  115. }
  116. }
  117. if (!isset($cache[$formId][$name]))
  118. $cache[$formId][$name] = RSFormProHelper::componentNameExists($name, $formId);
  119. return $cache[$formId][$name];
  120. }
  121. public static function checkValue($setvalue, $array)
  122. {
  123. if (!is_array($array))
  124. $array = RSFormProHelper::explode($array);
  125. if (strlen($setvalue))
  126. foreach ($array as $k => $v)
  127. {
  128. @list($value, $text) = explode("|", $v, 2);
  129. if ($value == $setvalue)
  130. $array[$k] = $v.'[c]';
  131. }
  132. return implode("\n", $array);
  133. }
  134. public static function createList($results, $value='value', $text='text')
  135. {
  136. $list = array();
  137. if (is_array($results))
  138. foreach ($results as $result)
  139. if (is_object($result))
  140. $list[] = $result->{$value}.'|'.$result->{$text};
  141. elseif (is_array($result))
  142. $list[] = $result[$value].'|'.$result[$text];
  143. return implode("\n", $list);
  144. }
  145. public static function displayForm($formId, $is_module=false)
  146. {
  147. $mainframe = JFactory::getApplication();
  148. $db = JFactory::getDBO();
  149. $db->setQuery("SELECT Published, FormTitle, MetaTitle, MetaDesc, MetaKeywords, ShowThankyou FROM #__rsform_forms WHERE FormId='".(int) $formId."'");
  150. $form = $db->loadObject();
  151. if (empty($form) || !$form->Published)
  152. {
  153. JError::raiseWarning(500, JText::_('_NOT_EXIST'));
  154. return;
  155. }
  156. $lang = RSFormProHelper::getCurrentLanguage($formId);
  157. $translations = RSFormProHelper::getTranslations('forms', $formId, $lang);
  158. if ($translations)
  159. foreach ($translations as $field => $value)
  160. {
  161. if (isset($form->$field))
  162. $form->$field = $value;
  163. }
  164. $doc = JFactory::getDocument();
  165. if (!$is_module)
  166. {
  167. if ($form->MetaDesc)
  168. $doc->setMetaData('description', $form->MetaDesc);
  169. if ($form->MetaKeywords)
  170. $doc->setMetaData('keywords', $form->MetaKeywords);
  171. if ($form->MetaTitle)
  172. $doc->setTitle($form->FormTitle);
  173. }
  174. $session = JFactory::getSession();
  175. $formparams = $session->get('com_rsform.formparams.'.$formId);
  176. // Form has been processed ?
  177. if ($formparams && $formparams->formProcessed)
  178. {
  179. // Must show Thank You Message
  180. if ($form->ShowThankyou)
  181. {
  182. return RSFormProHelper::showThankYouMessage($formId);
  183. }
  184. // Clear
  185. $session->clear('com_rsform.formparams.'.$formId);
  186. // Must show small message
  187. $mainframe->enqueueMessage(JText::_('RSFP_THANKYOU_SMALL'));
  188. }
  189. // Must process form
  190. $post = JRequest::getVar('form', array(), 'post', 'none', JREQUEST_ALLOWRAW);
  191. if (isset($post['formId']) && $post['formId'] == $formId)
  192. {
  193. $invalid = RSFormProHelper::processForm($formId);
  194. // Did not pass validation - show the form
  195. if ($invalid)
  196. {
  197. $mainframe->triggerEvent('rsfp_f_onBeforeShowForm');
  198. return RSFormProHelper::showForm($formId, $post, $invalid);
  199. }
  200. }
  201. // Default - show the form
  202. $mainframe->triggerEvent('rsfp_f_onBeforeShowForm');
  203. return RSFormProHelper::showForm($formId);
  204. }
  205. public static function WYSIWYG($name, $content, $hiddenField, $width, $height, $col, $row)
  206. {
  207. $editor = JFactory::getEditor();
  208. $params = array('relative_urls' => '0', 'cleanup_save' => '0', 'cleanup_startup' => '0', 'cleanup_entities' => '0');
  209. $id = trim(substr($name, 4), '][');
  210. $content = $editor->display($name, $content , $width, $height, $col, $row, true, $id, null, null, $params);
  211. return $content;
  212. }
  213. public static function getValidationRules()
  214. {
  215. require_once JPATH_SITE.'/components/com_rsform/helpers/validation.php';
  216. $results = get_class_methods('RSFormProValidations');
  217. return implode("\n",$results);
  218. }
  219. public static function readConfig($force=false)
  220. {
  221. $config = RSFormProConfig::getInstance();
  222. if ($force) {
  223. $config->reload();
  224. }
  225. return $config->getData();
  226. }
  227. public static function getConfig($name = null)
  228. {
  229. $config = RSFormProConfig::getInstance();
  230. if (is_null($name)) {
  231. return $config->getData();
  232. } else {
  233. return $config->get($name);
  234. }
  235. }
  236. public static function genKeyCode()
  237. {
  238. $code = RSFormProHelper::getConfig('global.register.code');
  239. return md5($code._RSFORM_KEY);
  240. }
  241. public static function componentNameExists($componentName, $formId, $currentComponentId=0)
  242. {
  243. $db = JFactory::getDBO();
  244. if ($componentName == 'formId')
  245. return true;
  246. $componentName = $db->escape($componentName);
  247. $formId = (int) $formId;
  248. $currentComponentId = (int) $currentComponentId;
  249. $query = "SELECT c.ComponentId FROM #__rsform_properties p LEFT JOIN #__rsform_components c ON (p.ComponentId = c.ComponentId)";
  250. $query .= "WHERE c.FormId='".$formId."' AND p.PropertyName='NAME' AND p.PropertyValue='".$componentName."'";
  251. if ($currentComponentId)
  252. $query .= " AND c.ComponentId != '".$currentComponentId."'";
  253. $db->setQuery($query);
  254. $exists = $db->loadResult();
  255. return $exists;
  256. }
  257. public static function copyComponent($sourceComponentId, $toFormId)
  258. {
  259. $sourceComponentId = (int) $sourceComponentId;
  260. $toFormId = (int) $toFormId;
  261. $db = JFactory::getDBO();
  262. $db->setQuery("SELECT * FROM #__rsform_components WHERE ComponentId='".$sourceComponentId."'");
  263. $component = $db->loadObject();
  264. if (!$component)
  265. return false;
  266. //get max ordering
  267. $db->setQuery("SELECT MAX(`Order`)+1 FROM #__rsform_components WHERE FormId = '".$toFormId."'");
  268. $component->Order = $db->loadResult();
  269. $db->setQuery("INSERT INTO #__rsform_components SET `FormId`='".$toFormId."', `ComponentTypeId`='".$component->ComponentTypeId."', `Order`='".$component->Order."',`Published`='".$component->Published."'");
  270. $db->execute();
  271. $newComponentId = $db->insertid();
  272. $db->setQuery("SELECT * FROM #__rsform_properties WHERE ComponentId='".$sourceComponentId."'");
  273. $properties = $db->loadObjectList();
  274. foreach ($properties as $property)
  275. {
  276. if ($property->PropertyName == 'NAME' && $toFormId == $component->FormId)
  277. {
  278. $property->PropertyValue .= ' copy';
  279. while (RSFormProHelper::componentNameExists($property->PropertyValue, $toFormId))
  280. $property->PropertyValue .= mt_rand(0,9);
  281. }
  282. $db->setQuery("INSERT INTO #__rsform_properties SET ComponentId='".$newComponentId."', PropertyName='".$db->escape($property->PropertyName)."', PropertyValue='".$db->escape($property->PropertyValue)."'");
  283. $db->execute();
  284. }
  285. // copy language
  286. $db->setQuery("SELECT * FROM #__rsform_translations WHERE `reference`='properties' AND `reference_id` LIKE '".$sourceComponentId.".%'");
  287. $translations = $db->loadObjectList();
  288. foreach ($translations as $translation)
  289. {
  290. $reference_id = $newComponentId.'.'.end(explode('.', $translation->reference_id, 2));
  291. $db->setQuery("INSERT INTO #__rsform_translations SET `form_id`='".$toFormId."', `lang_code`='".$db->escape($translation->lang_code)."', `reference`='properties', `reference_id`='".$db->escape($reference_id)."', `value`='".$db->escape($translation->value)."'");
  292. $db->execute();
  293. }
  294. return $newComponentId;
  295. }
  296. public static function getCurrentLanguage($formId=null)
  297. {
  298. $mainframe = JFactory::getApplication();
  299. $lang = JFactory::getLanguage();
  300. $session = JFactory::getSession();
  301. $formId = !$formId ? JRequest::getInt('formId') || JRequest::getInt('FormId') : $formId;
  302. // editing in backend ?
  303. if ($mainframe->isAdmin())
  304. {
  305. if (JRequest::getVar('task') == 'submissions.edit')
  306. {
  307. $cid = JRequest::getVar('cid', array());
  308. if (is_array($cid))
  309. $cid = (int) @$cid[0];
  310. $db = JFactory::getDBO();
  311. $db->setQuery("SELECT `Lang` FROM #__rsform_submissions WHERE SubmissionId='".$cid."'");
  312. $language = $db->loadResult();
  313. return $language;
  314. }
  315. return $session->get('com_rsform.form.'.$formId.'.lang', $lang->getTag());
  316. }
  317. // frontend
  318. else
  319. {
  320. return $lang->getTag();
  321. }
  322. }
  323. public static function getComponentProperties($components)
  324. {
  325. $db = JFactory::getDBO();
  326. if (is_numeric($components))
  327. {
  328. $componentId = (int) $components;
  329. //load component properties
  330. $db->setQuery("SELECT `PropertyName`, `PropertyValue` FROM #__rsform_properties WHERE `ComponentId`='".$componentId."'");
  331. $properties = $db->loadObjectList();
  332. //set up data array with component properties
  333. $data = array();
  334. foreach($properties as $property)
  335. $data[$property->PropertyName] = $property->PropertyValue;
  336. $data['componentId'] = $componentId;
  337. unset($properties);
  338. $db->setQuery("SELECT FormId FROM #__rsform_components WHERE ComponentId='".$componentId."'");
  339. $formId = $db->loadResult();
  340. // language
  341. $lang = RSFormProHelper::getCurrentLanguage($formId);
  342. $translations = RSFormProHelper::getTranslations('properties', $formId, $lang);
  343. foreach ($data as $property => $value)
  344. {
  345. $reference_id = $componentId.'.'.$property;
  346. if (isset($translations[$reference_id]))
  347. $data[$property] = $translations[$reference_id];
  348. }
  349. return $data;
  350. }
  351. elseif (is_array($components))
  352. {
  353. $componentIds = array();
  354. foreach ($components as $componentId)
  355. {
  356. if (is_object($componentId) && !empty($componentId->ComponentId))
  357. $componentIds[] = (int) $componentId->ComponentId;
  358. elseif (is_array($componentId) && !empty($componentId['ComponentId']))
  359. $componentIds[] = (int) $componentId['ComponentId'];
  360. else
  361. $componentIds[] = (int) $componentId;
  362. }
  363. if (!empty($componentIds))
  364. {
  365. $db->setQuery("SELECT `PropertyName`, `PropertyValue`, `ComponentId` FROM #__rsform_properties WHERE `ComponentId` IN (".implode(',', $componentIds).")");
  366. $results = $db->loadObjectList();
  367. $all_data = array();
  368. foreach ($results as $result)
  369. $all_data[$result->ComponentId][$result->PropertyName] = $result->PropertyValue;
  370. foreach ($all_data as $componentId => $properties)
  371. $all_data[$componentId]['componentId'] = $componentId;
  372. $db->setQuery("SELECT FormId FROM #__rsform_components WHERE ComponentId='".$componentIds[0]."'");
  373. $formId = $db->loadResult();
  374. // language
  375. $lang = RSFormProHelper::getCurrentLanguage($formId);
  376. $translations = RSFormProHelper::getTranslations('properties', $formId, $lang);
  377. foreach ($all_data as $componentId => $properties)
  378. {
  379. foreach ($properties as $property => $value)
  380. {
  381. $reference_id = $componentId.'.'.$property;
  382. if (isset($translations[$reference_id]))
  383. $properties[$property] = $translations[$reference_id];
  384. }
  385. $all_data[$componentId] = $properties;
  386. }
  387. return $all_data;
  388. }
  389. }
  390. return false;
  391. }
  392. public static function isCode($value)
  393. {
  394. $RSadapter = RSFormProHelper::getLegacyAdapter();
  395. if (strpos($value, '<code>') !== false)
  396. return eval($value);
  397. return $value;
  398. }
  399. public static function showPreview($formId, $componentId, $data)
  400. {
  401. $mainframe = JFactory::getApplication();
  402. $formId = (int) $formId;
  403. $componentId = (int) $componentId;
  404. // Legacy
  405. $r = array();
  406. $r['ComponentTypeName'] = $data['ComponentTypeName'];
  407. $out ='';
  408. //Trigger Event - rsfp_bk_onBeforeCreateComponentPreview
  409. $mainframe->triggerEvent('rsfp_bk_onBeforeCreateComponentPreview',array(array('out'=>&$out,'formId'=>$formId,'componentId'=>$componentId,'ComponentTypeName'=>$r['ComponentTypeName'],'data'=>$data)));
  410. static $passedPageBreak;
  411. switch($r['ComponentTypeName'])
  412. {
  413. case 'textBox':
  414. {
  415. $defaultValue = RSFormProHelper::isCode($data['DEFAULTVALUE']);
  416. $out.='<td>'.$data['CAPTION'].'</td>';
  417. $out.='<td><input type="text" value="'.RSFormProHelper::htmlEscape($defaultValue).'" size="'.$data['SIZE'].'" /></td>';
  418. }
  419. break;
  420. case 'textArea':
  421. {
  422. $defaultValue = RSFormProHelper::isCode($data['DEFAULTVALUE']);
  423. $out.='<td>'.$data['CAPTION'].'</td>';
  424. $out.='<td><textarea cols="'.$data['COLS'].'" rows="'.$data['ROWS'].'">'.RSFormProHelper::htmlEscape($defaultValue).'</textarea></td>';
  425. }
  426. break;
  427. case 'selectList':
  428. {
  429. $out.='<td>'.$data['CAPTION'].'</td>';
  430. $out.='<td><select '.($data['MULTIPLE']=='YES' ? 'multiple="multiple"' : '').' size="'.$data['SIZE'].'">';
  431. $items = RSFormProHelper::isCode($data['ITEMS']);
  432. $items = str_replace(array("\r\n", "\r"), "\n", $items);
  433. $items = explode("\n",$items);
  434. $special = array('[c]', '[g]', '[d]');
  435. foreach ($items as $item)
  436. {
  437. @list($val, $txt) = @explode('|', str_replace($special, '', $item), 2);
  438. if (is_null($txt))
  439. $txt = $val;
  440. // <optgroup>
  441. if (strpos($item, '[g]') !== false) {
  442. $out .= '<optgroup label="'.RSFormProHelper::htmlEscape($val).'">';
  443. continue;
  444. }
  445. // </optgroup>
  446. if(strpos($item, '[/g]') !== false) {
  447. $out .= '</optgroup>';
  448. continue;
  449. }
  450. $additional = '';
  451. // selected
  452. if (strpos($item, '[c]') !== false)
  453. $additional .= 'selected="selected"';
  454. // disabled
  455. if (strpos($item, '[d]') !== false)
  456. $additional .= 'disabled="disabled"';
  457. $out .= '<option '.$additional.' value="'.RSFormProHelper::htmlEscape($val).'">'.RSFormProHelper::htmlEscape($txt).'</option>';
  458. }
  459. $out.='</select></td>';
  460. }
  461. break;
  462. case 'checkboxGroup':
  463. {
  464. $i=0;
  465. $out.='<td>'.$data['CAPTION'].'</td>';
  466. $out.='<td>';
  467. $items = RSFormProHelper::isCode($data['ITEMS']);
  468. $items = str_replace(array("\r\n", "\r"), "\n", $items);
  469. $items = explode("\n",$items);
  470. $special = array('[c]', '[d]');
  471. foreach ($items as $item)
  472. {
  473. @list($val, $txt) = @explode('|', str_replace($special, '', $item), 2);
  474. if (is_null($txt))
  475. $txt = $val;
  476. $additional = '';
  477. // checked
  478. if (strpos($item, '[c]') !== false)
  479. $additional .= 'checked="checked"';
  480. // disabled
  481. if (strpos($item, '[d]') !== false)
  482. $additional .= 'disabled="disabled"';
  483. $out.='<input type="checkbox" '.$additional.' value="'.RSFormProHelper::htmlEscape($val).'" id="'.$data['NAME'].$i.'"/><label for="'.$data['NAME'].$i.'">'.$txt.'</label>';
  484. if($data['FLOW']=='VERTICAL') $out.='<br/>';
  485. $i++;
  486. }
  487. $out.='</td>';
  488. }
  489. break;
  490. case 'radioGroup':
  491. {
  492. $i=0;
  493. $out.='<td>'.$data['CAPTION'].'</td>';
  494. $out.='<td>';
  495. $items = RSFormProHelper::isCode($data['ITEMS']);
  496. $items = str_replace(array("\r\n", "\r"), "\n", $items);
  497. $items = explode("\n",$items);
  498. $special = array('[c]', '[d]');
  499. foreach ($items as $item)
  500. {
  501. @list($val, $txt) = @explode('|', str_replace($special, '', $item), 2);
  502. if (is_null($txt))
  503. $txt = $val;
  504. $additional = '';
  505. // checked
  506. if (strpos($item, '[c]') !== false)
  507. $additional .= 'checked="checked"';
  508. // disabled
  509. if (strpos($item, '[d]') !== false)
  510. $additional .= 'disabled="disabled"';
  511. $out.='<input type="radio" '.$additional.' value="'.RSFormProHelper::htmlEscape($val).'" id="'.$data['NAME'].$i.'"/><label for="'.$data['NAME'].$i.'">'.$txt.'</label>';
  512. if ($data['FLOW']=='VERTICAL') $out.='<br/>';
  513. $i++;
  514. }
  515. $out.='</td>';
  516. }
  517. break;
  518. case 'calendar':
  519. {
  520. $out.='<td>'.$data['CAPTION'].'</td>';
  521. $out.='<td><img src="'.JURI::root(true).'/administrator/components/com_rsform/assets/images/icons/calendar.png" /> '.JText::_('RSFP_COMP_FVALUE_'.$data['CALENDARLAYOUT']).'</td>';
  522. }
  523. break;
  524. case 'captcha':
  525. {
  526. $out.='<td>'.$data['CAPTION'].'</td>';
  527. $out.='<td>';
  528. switch (@$data['IMAGETYPE'])
  529. {
  530. default:
  531. case 'FREETYPE':
  532. case 'NOFREETYPE':
  533. $out.='<img src="index.php?option=com_rsform&amp;task=captcha&amp;componentId='.$componentId.'&amp;tmpl=component&amp;sid='.mt_rand().'" id="captcha'.$componentId.'" alt="'.$data['CAPTION'].'"/>';
  534. $out.=($data['FLOW']=='HORIZONTAL') ? '':'<br/>';
  535. $out.='<input type="text" value="" id="captchaTxt'.$componentId.'" '.$data['ADDITIONALATTRIBUTES'].' />';
  536. $out.=($data['SHOWREFRESH']=='YES') ? '&nbsp;&nbsp;<a href="" onclick="refreshCaptcha('.$componentId.',\'index.php?option=com_rsform&amp;task=captcha&amp;componentId='.$componentId.'&amp;tmpl=component\'); return false;">'.$data['REFRESHTEXT'].'</a>':'';
  537. break;
  538. case 'INVISIBLE':
  539. $out.='{hidden captcha}';
  540. break;
  541. }
  542. $out.='</td>';
  543. }
  544. break;
  545. case 'fileUpload':
  546. {
  547. $out.='<td>'.$data['CAPTION'].'</td>';
  548. $out.='<td><input type="file" /></td>';
  549. }
  550. break;
  551. case 'freeText':
  552. {
  553. $out.='<td>&nbsp;</td>';
  554. $out.='<td>'.$data['TEXT'].'</td>';
  555. }
  556. break;
  557. case 'hidden':
  558. {
  559. $out.='<td>&nbsp;</td>';
  560. $out.='<td>{hidden field}</td>';
  561. }
  562. break;
  563. case 'imageButton':
  564. {
  565. $out.='<td>'.$data['CAPTION'].'</td>';
  566. $out.='<td>';
  567. $out.='<input type="image" src="'.RSFormProHelper::htmlEscape($data['IMAGEBUTTON']).'"/>';
  568. if($data['RESET']=='YES')
  569. $out.='&nbsp;&nbsp;<input type="image" src="'.RSFormProHelper::htmlEscape($data['IMAGERESET']).'"/>';
  570. $out.='</td>';
  571. }
  572. break;
  573. case 'button':
  574. case 'submitButton':
  575. {
  576. $out.='<td>'.$data['CAPTION'].'</td>';
  577. if (isset($data['BUTTONTYPE']) && $data['BUTTONTYPE'] == 'TYPEBUTTON')
  578. $out.='<td><button type="button">'.RSFormProHelper::htmlEscape($data['LABEL']).'</button>';
  579. else
  580. $out.='<td><input type="button" value="'.RSFormProHelper::htmlEscape($data['LABEL']).'" />';
  581. if($data['RESET']=='YES')
  582. {
  583. if (isset($data['BUTTONTYPE']) && $data['BUTTONTYPE'] == 'TYPEBUTTON')
  584. $out.='&nbsp;&nbsp;<button type="reset">'.RSFormProHelper::htmlEscape($data['RESETLABEL']).'</button>';
  585. else
  586. $out.='&nbsp;&nbsp;<input type="reset" value="'.RSFormProHelper::htmlEscape($data['RESETLABEL']).'"/>';
  587. }
  588. $out.='</td>';
  589. }
  590. break;
  591. case 'password':
  592. {
  593. $out.='<td>'.$data['CAPTION'].'</td>';
  594. $out.='<td><input type="password" value="'.RSFormProHelper::htmlEscape($data['DEFAULTVALUE']).'" size="'.$data['SIZE'].'"/></td>';
  595. }
  596. break;
  597. case 'ticket':
  598. {
  599. $out.='<td>&nbsp;</td>';
  600. $out.='<td>'.RSFormProHelper::generateString($data['LENGTH'],$data['CHARACTERS']).'</td>';
  601. }
  602. break;
  603. case 'pageBreak':
  604. $out.='<td>&nbsp;</td>';
  605. $out.='<td>'.($passedPageBreak ? '<input type="button" value="'.RSFormProHelper::htmlEscape($data['PREVBUTTON']).'" />' : '').' <input type="button" value="'.RSFormProHelper::htmlEscape($data['NEXTBUTTON']).'" /></td>';
  606. $passedPageBreak = true;
  607. break;
  608. case 'rseprotickets':
  609. $out.='<td>'.$data['CAPTION'].'</td>';
  610. $out.='<td>'.JText::_('RSFP_RSEVENTSPRO_TICKETS').'</td>';
  611. break;
  612. default:
  613. $out = '<td colspan="2" style="color:#333333"><em>'.JText::_('RSFP_COMP_PREVIEW_NOT_AVAILABLE').'</em></td>';
  614. break;
  615. }
  616. //Trigger Event - rsfp_bk_onAfterCreateComponentPreview
  617. $mainframe->triggerEvent('rsfp_bk_onAfterCreateComponentPreview',array(array('out'=>&$out, 'formId'=>$formId, 'componentId'=>$componentId, 'ComponentTypeName'=>$r['ComponentTypeName'],'data'=>$data)));
  618. return $out;
  619. }
  620. public static function htmlEscape($val)
  621. {
  622. return htmlentities($val, ENT_COMPAT, 'UTF-8');
  623. }
  624. public static function explode($value)
  625. {
  626. $value = str_replace(array("\r\n", "\r"), "\n", $value);
  627. $value = explode("\n", $value);
  628. return $value;
  629. }
  630. public static function readFile($file, $download_name=null)
  631. {
  632. if (empty($download_name))
  633. $download_name = basename($file);
  634. $fsize = filesize($file);
  635. header("Cache-Control: public, must-revalidate");
  636. header('Cache-Control: pre-check=0, post-check=0, max-age=0');
  637. if (!preg_match('#MSIE#', $_SERVER['HTTP_USER_AGENT']))
  638. header("Pragma: no-cache");
  639. header("Expires: 0");
  640. header("Content-Description: File Transfer");
  641. header("Expires: Sat, 01 Jan 2000 01:00:00 GMT");
  642. if (preg_match('#Opera#', $_SERVER['HTTP_USER_AGENT']))
  643. header("Content-Type: application/octetstream");
  644. else
  645. header("Content-Type: application/octet-stream");
  646. header("Content-Length: ".(string) ($fsize));
  647. header('Content-Disposition: attachment; filename="'.$download_name.'"');
  648. header("Content-Transfer-Encoding: binary\n");
  649. ob_end_flush();
  650. RSFormProHelper::readFileChunked($file);
  651. exit();
  652. }
  653. public static function readFileChunked($filename, $retbytes=true)
  654. {
  655. $chunksize = 1*(1024*1024); // how many bytes per chunk
  656. $buffer = '';
  657. $cnt =0;
  658. $handle = fopen($filename, 'rb');
  659. if ($handle === false) {
  660. return false;
  661. }
  662. while (!feof($handle)) {
  663. $buffer = fread($handle, $chunksize);
  664. echo $buffer;
  665. if ($retbytes) {
  666. $cnt += strlen($buffer);
  667. }
  668. }
  669. $status = fclose($handle);
  670. if ($retbytes && $status) {
  671. return $cnt; // return num. bytes delivered like readfile() does.
  672. }
  673. return $status;
  674. }
  675. public static function getReplacements($SubmissionId, $skip_globals=false)
  676. {
  677. // Small hack
  678. return RSFormProHelper::sendSubmissionEmails($SubmissionId, true, $skip_globals);
  679. }
  680. public static function sendSubmissionEmails($SubmissionId, $only_return_replacements=false, $skip_globals=false)
  681. {
  682. $db = JFactory::getDBO();
  683. $u = JUri::getInstance();
  684. $config = JFactory::getConfig();
  685. $SubmissionId = (int) $SubmissionId;
  686. $mainframe = JFactory::getApplication();
  687. $Itemid = JRequest::getInt('Itemid');
  688. $Itemid = $Itemid ? '&amp;Itemid='.$Itemid : '';
  689. $db->setQuery("SELECT * FROM #__rsform_submissions WHERE SubmissionId='".$SubmissionId."'");
  690. $submission = $db->loadObject();
  691. $submission->values = array();
  692. $db->setQuery("SELECT FieldName, FieldValue FROM #__rsform_submission_values WHERE SubmissionId='".$SubmissionId."'");
  693. $fields = $db->loadObjectList();
  694. foreach ($fields as $field)
  695. $submission->values[$field->FieldName] = $field->FieldValue;
  696. unset($fields);
  697. $formId = $submission->FormId;
  698. $db->setQuery("SELECT * FROM #__rsform_forms WHERE FormId='".$formId."'");
  699. $form = $db->loadObject();
  700. $form->MultipleSeparator = str_replace(array('\n', '\r', '\t'), array("\n", "\r", "\t"), $form->MultipleSeparator);
  701. if (empty($submission->Lang))
  702. {
  703. if (!empty($form->Lang))
  704. $submission->Lang = $form->Lang;
  705. else
  706. {
  707. $lang = JFactory::getLanguage();
  708. $language = $lang->getDefault();
  709. $submission->Lang = $language;
  710. }
  711. $db->setQuery("UPDATE #__rsform_submissions SET Lang='".$db->escape($submission->Lang)."' WHERE SubmissionId='".$submission->SubmissionId."'");
  712. $db->execute();
  713. }
  714. $translations = RSFormProHelper::getTranslations('forms', $form->FormId, $submission->Lang);
  715. if ($translations)
  716. foreach ($translations as $field => $value)
  717. {
  718. if (isset($form->$field))
  719. $form->$field = $value;
  720. }
  721. $placeholders = array();
  722. $values = array();
  723. $db->setQuery("SELECT c.ComponentTypeId, p.ComponentId, p.PropertyName, p.PropertyValue FROM #__rsform_components c LEFT JOIN #__rsform_properties p ON (c.ComponentId=p.ComponentId) WHERE c.FormId='".$formId."' AND c.Published='1' AND p.PropertyName IN ('NAME', 'CAPTION', 'EMAILATTACH', 'WYSIWYG', 'ITEMS')");
  724. $components = $db->loadObjectList();
  725. $properties = array();
  726. $uploadFields = array();
  727. $multipleFields = array();
  728. $textareaFields = array();
  729. $userEmailUploads = array();
  730. $adminEmailUploads = array();
  731. $additionalEmailUploads = array();
  732. $additionalEmailUploadsIds = array();
  733. foreach ($components as $component)
  734. {
  735. // Upload fields - grab by NAME so that we can use it later on when checking $_FILES
  736. if ($component->ComponentTypeId == 9)
  737. {
  738. if ($component->PropertyName == 'EMAILATTACH')
  739. {
  740. $emailsvalues = $component->PropertyValue;
  741. $emailsvalues = trim($emailsvalues) != '' ? explode(',',$emailsvalues) : array();
  742. if (!empty($emailsvalues))
  743. foreach ($emailsvalues as $emailvalue)
  744. {
  745. if ($emailvalue == 'useremail' || $emailvalue == 'adminemail') continue;
  746. $additionalEmailUploadsIds[] = $emailvalue;
  747. }
  748. $additionalEmailUploadsIds = array_unique($additionalEmailUploadsIds);
  749. if (!empty($additionalEmailUploadsIds))
  750. foreach ($additionalEmailUploadsIds as $additionalEmailUploadsId)
  751. {
  752. if (in_array($additionalEmailUploadsId,$emailsvalues))
  753. $additionalEmailUploads[$additionalEmailUploadsId][] = $component->ComponentId;
  754. }
  755. }
  756. if ($component->PropertyName == 'NAME')
  757. $uploadFields[] = $component->PropertyValue;
  758. if ($component->PropertyName == 'EMAILATTACH' && !empty($component->PropertyValue))
  759. {
  760. $emailvalues = explode(',',$component->PropertyValue);
  761. if (in_array('useremail',$emailvalues))
  762. {
  763. $userEmailUploads[] = $component->ComponentId;
  764. //continue;
  765. }
  766. if (in_array('adminemail',$emailvalues))
  767. {
  768. $adminEmailUploads[] = $component->ComponentId;
  769. //continue;
  770. }
  771. }
  772. }
  773. // Multiple fields - grab by ComponentId for performance
  774. elseif (in_array($component->ComponentTypeId, array(3, 4)))
  775. {
  776. if ($component->PropertyName == 'NAME')
  777. $multipleFields[] = $component->ComponentId;
  778. }
  779. // Textarea fields - grab by ComponentId for performance
  780. elseif ($component->ComponentTypeId == 2)
  781. {
  782. if ($component->PropertyName == 'WYSIWYG' && $component->PropertyValue == 'NO')
  783. $textareaFields[] = $component->ComponentId;
  784. }
  785. $properties[$component->ComponentId][$component->PropertyName] = $component->PropertyValue;
  786. }
  787. // language
  788. $translations = RSFormProHelper::getTranslations('properties', $formId, $submission->Lang);
  789. foreach ($properties as $componentId => $componentProperties)
  790. {
  791. foreach ($componentProperties as $property => $value)
  792. {
  793. $reference_id = $componentId.'.'.$property;
  794. if (isset($translations[$reference_id]))
  795. $componentProperties[$property] = $translations[$reference_id];
  796. }
  797. $properties[$componentId] = $componentProperties;
  798. }
  799. $secret = $config->get('secret');
  800. foreach ($properties as $ComponentId => $property)
  801. {
  802. // {component:caption}
  803. $placeholders[] = '{'.$property['NAME'].':caption}';
  804. $values[] = isset($property['CAPTION']) ? $property['CAPTION'] : '';
  805. // {component:name}
  806. $placeholders[] = '{'.$property['NAME'].':name}';
  807. $values[] = $property['NAME'];
  808. // {component:value}
  809. $placeholders[] = '{'.$property['NAME'].':value}';
  810. $value = '';
  811. if (isset($submission->values[$property['NAME']]))
  812. {
  813. $value = $submission->values[$property['NAME']];
  814. // Check if this is an upload field
  815. if (in_array($property['NAME'], $uploadFields))
  816. $value = '<a href="'.JURI::root().'index.php?option=com_rsform&amp;task=submissions.view.file&amp;hash='.md5($submission->SubmissionId.$secret.$property['NAME']).$Itemid.'">'.basename($submission->values[$property['NAME']]).'</a>';
  817. // Check if this is a multiple field
  818. elseif (in_array($ComponentId, $multipleFields))
  819. $value = str_replace("\n", $form->MultipleSeparator, $value);
  820. elseif ($form->TextareaNewLines && in_array($ComponentId, $textareaFields))
  821. $value = nl2br($value);
  822. }
  823. $values[] = $value;
  824. if (isset($property['ITEMS'])) {
  825. $placeholders[] = '{'.$property['NAME'].':text}';
  826. if (isset($submission->values[$property['NAME']])) {
  827. $value = $submission->values[$property['NAME']];
  828. $all_values = explode("\n", $value);
  829. $all_texts = array();
  830. $items = RSFormProHelper::explode(RSFormProHelper::isCode($property['ITEMS']));
  831. $special = array('[c]', '[g]', '[d]');
  832. foreach ($all_values as $v => $value) {
  833. $all_texts[$v] = $value;
  834. foreach ($items as $item) {
  835. $item = str_replace($special, '', $item);
  836. @list($item_val, $item_text) = explode("|", $item, 2);
  837. if ($item_text && $item_val == $value)
  838. {
  839. $all_texts[$v] = $item_text;
  840. break;
  841. }
  842. }
  843. }
  844. if ($all_texts) {
  845. $values[] = implode($form->MultipleSeparator, $all_texts);
  846. } else {
  847. $values[] = $value;
  848. }
  849. } else {
  850. $values[] = '';
  851. }
  852. }
  853. // {component:path}
  854. // {component:localpath}
  855. if (in_array($property['NAME'], $uploadFields))
  856. {
  857. $placeholders[] = '{'.$property['NAME'].':path}';
  858. $placeholders[] = '{'.$property['NAME'].':localpath}';
  859. if (isset($submission->values[$property['NAME']])) {
  860. $filepath = $submission->values[$property['NAME']];
  861. $filepath = substr_replace($filepath, JURI::root(), 0, strlen(JPATH_SITE)+1);
  862. $filepath = str_replace(array('\\', '\\/', '//\\'), '/', $filepath);
  863. $values[] = $filepath;
  864. $values[] = $submission->values[$property['NAME']];
  865. }
  866. else {
  867. $values[] = '';
  868. $values[] = '';
  869. }
  870. }
  871. }
  872. $placeholders[] = '{_STATUS:value}';
  873. $values[] = isset($submission->values['_STATUS']) ? JText::_('RSFP_PAYPAL_STATUS_'.$submission->values['_STATUS']) : '';
  874. $placeholders[] = '{_ANZ_STATUS:value}';
  875. $values[] = isset($submission->values['_ANZ_STATUS']) ? JText::_('RSFP_ANZ_STATUS_'.$submission->values['_ANZ_STATUS']) : '';
  876. $user = JFactory::getUser($submission->UserId);
  877. if (empty($user->id))
  878. $user = JFactory::getUser(0);
  879. $root = $mainframe->isAdmin() ? JURI::root() : $u->toString(array('scheme','host', 'port'));
  880. $confirmation_hash = md5($submission->SubmissionId.$formId.$submission->DateSubmitted);
  881. $hash_link = 'index.php?option=com_rsform&task=confirm&hash='.$confirmation_hash;
  882. $confirmation = $root.($mainframe->isAdmin() ? $hash_link : JRoute::_($hash_link));
  883. if (!$skip_globals)
  884. {
  885. array_push($placeholders, '{global:username}', '{global:userid}', '{global:useremail}', '{global:fullname}', '{global:userip}', '{global:date_added}', '{global:sitename}', '{global:siteurl}','{global:confirmation}','{global:submissionid}', '{global:submission_id}');
  886. array_push($values, $user->username, $user->id, $user->email, $user->name, isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '', RSFormProHelper::getDate($submission->DateSubmitted), $config->get('sitename'), JURI::root(),$confirmation, $submission->SubmissionId, $submission->SubmissionId);
  887. }
  888. $mainframe->triggerEvent('rsfp_onAfterCreatePlaceholders', array(array('form' => &$form, 'placeholders' => &$placeholders, 'values' => &$values, 'submission' => $submission)));
  889. if ($only_return_replacements)
  890. return array($placeholders, $values);
  891. $userEmail = array(
  892. 'to' => str_replace($placeholders, $values, $form->UserEmailTo),
  893. 'cc' => str_replace($placeholders, $values, $form->UserEmailCC),
  894. 'bcc' => str_replace($placeholders, $values, $form->UserEmailBCC),
  895. 'from' => str_replace($placeholders, $values, $form->UserEmailFrom),
  896. 'replyto' => str_replace($placeholders, $values, $form->UserEmailReplyTo),
  897. 'fromName' => str_replace($placeholders, $values, $form->UserEmailFromName),
  898. 'text' => str_replace($placeholders, $values, $form->UserEmailText),
  899. 'subject' => str_replace($placeholders, $values, $form->UserEmailSubject),
  900. 'mode' => $form->UserEmailMode,
  901. 'files' => array()
  902. );
  903. // user cc
  904. if (strpos($userEmail['cc'], ',') !== false)
  905. $userEmail['cc'] = explode(',', $userEmail['cc']);
  906. // user bcc
  907. if (strpos($userEmail['bcc'], ',') !== false)
  908. $userEmail['bcc'] = explode(',', $userEmail['bcc']);
  909. jimport('joomla.filesystem.file');
  910. $file = str_replace($placeholders, $values, $form->UserEmailAttachFile);
  911. if ($form->UserEmailAttach && JFile::exists($file))
  912. $userEmail['files'][] = $file;
  913. // Need to attach files
  914. // User Email
  915. foreach ($userEmailUploads as $componentId)
  916. {
  917. $name = $properties[$componentId]['NAME'];
  918. if (!empty($submission->values[$name]))
  919. $userEmail['files'][] = $submission->values[$name];
  920. }
  921. $adminEmail = array(
  922. 'to' => str_replace($placeholders, $values, $form->AdminEmailTo),
  923. 'cc' => str_replace($placeholders, $values, $form->AdminEmailCC),
  924. 'bcc' => str_replace($placeholders, $values, $form->AdminEmailBCC),
  925. 'from' => str_replace($placeholders, $values, $form->AdminEmailFrom),
  926. 'replyto' => str_replace($placeholders, $values, $form->AdminEmailReplyTo),
  927. 'fromName' => str_replace($placeholders, $values, $form->AdminEmailFromName),
  928. 'text' => str_replace($placeholders, $values, $form->AdminEmailText),
  929. 'subject' => str_replace($placeholders, $values, $form->AdminEmailSubject),
  930. 'mode' => $form->AdminEmailMode,
  931. 'files' => array()
  932. );
  933. // admin cc
  934. if (strpos($adminEmail['cc'], ',') !== false)
  935. $adminEmail['cc'] = explode(',', $adminEmail['cc']);
  936. // admin bcc
  937. if (strpos($adminEmail['bcc'], ',') !== false)
  938. $adminEmail['bcc'] = explode(',', $adminEmail['bcc']);
  939. // Admin Email
  940. foreach ($adminEmailUploads as $componentId)
  941. {
  942. $name = $properties[$componentId]['NAME'];
  943. if (!empty($submission->values[$name]))
  944. $adminEmail['files'][] = $submission->values[$name];
  945. }
  946. $mainframe->triggerEvent('rsfp_beforeUserEmail', array(array('form' => &$form, 'placeholders' => &$placeholders, 'values' => &$values, 'submissionId' => $SubmissionId, 'userEmail'=>&$userEmail)));
  947. // Script called before the User Email is sent.
  948. eval($form->UserEmailScript);
  949. // mail users
  950. $recipients = explode(',',$userEmail['to']);
  951. if(!empty($recipients))
  952. foreach($recipients as $recipient)
  953. if(!empty($recipient))
  954. RSFormProHelper::sendMail($userEmail['from'], $userEmail['fromName'], $recipient, $userEmail['subject'], $userEmail['text'], $userEmail['mode'], !empty($userEmail['cc']) ? $userEmail['cc'] : null, !empty($userEmail['bcc']) ? $userEmail['bcc'] : null, $userEmail['files'], !empty($userEmail['replyto']) ? $userEmail['replyto'] : '');
  955. $mainframe->triggerEvent('rsfp_beforeAdminEmail', array(array('form' => &$form, 'placeholders' => &$placeholders, 'values' => &$values, 'submissionId' => $SubmissionId, 'adminEmail'=>&$adminEmail)));
  956. // Script called before the Admin Email is sent.
  957. eval($form->AdminEmailScript);
  958. //mail admins
  959. $recipients = explode(',',$adminEmail['to']);
  960. if(!empty($recipients))
  961. foreach($recipients as $recipient)
  962. if(!empty($recipient))
  963. RSFormProHelper::sendMail($adminEmail['from'], $adminEmail['fromName'], $recipient, $adminEmail['subject'], $adminEmail['text'], $adminEmail['mode'], !empty($adminEmail['cc']) ? $adminEmail['cc'] : null, !empty($adminEmail['bcc']) ? $adminEmail['bcc'] : null, $adminEmail['files'], !empty($adminEmail['replyto']) ? $adminEmail['replyto'] : '');
  964. //additional emails
  965. $db->setQuery("SELECT * FROM #__rsform_emails WHERE formId = ".$formId." ");
  966. $emails = $db->loadObjectList();
  967. $etranslations = RSFormProHelper::getTranslations('emails', $formId, $submission->Lang);
  968. if (!empty($emails))
  969. foreach ($emails as $email)
  970. {
  971. if (empty($email->from) || empty($email->fromname) || empty($email->subject) || empty($email->message)) continue;
  972. $fromname = isset($etranslations[$email->id.'.fromname']) ? $etranslations[$email->id.'.fromname'] : $email->fromname;
  973. $subject = isset($etranslations[$email->id.'.subject']) ? $etranslations[$email->id.'.subject'] : $email->subject;
  974. $message = isset($etranslations[$email->id.'.message']) ? $etranslations[$email->id.'.message'] : $email->message;
  975. $additionalEmail = array(
  976. 'to' => str_replace($placeholders, $values, $email->to),
  977. 'cc' => str_replace($placeholders, $values, $email->cc),
  978. 'bcc' => str_replace($placeholders, $values, $email->bcc),
  979. 'from' => str_replace($placeholders, $values, $email->from),
  980. 'replyto' => str_replace($placeholders, $values, $email->replyto),
  981. 'fromName' => str_replace($placeholders, $values, $fromname),
  982. 'text' => str_replace($placeholders, $values, $message),
  983. 'subject' => str_replace($placeholders, $values, $subject),
  984. 'mode' => $email->mode,
  985. 'files' => array()
  986. );
  987. if (!empty($additionalEmailUploads))
  988. foreach ($additionalEmailUploads as $additionalEmailId => $additionalEmailUpload)
  989. {
  990. if ($additionalEmailId == $email->id)
  991. foreach ($additionalEmailUpload as $componentId)
  992. {
  993. $name = $properties[$componentId]['NAME'];
  994. if (!empty($submission->values[$name]))
  995. $additionalEmail['files'][] = $submission->values[$name];
  996. }
  997. }
  998. // additional cc
  999. if (strpos($additionalEmail['cc'], ',') !== false)
  1000. $additionalEmail['cc'] = explode(',', $additionalEmail['cc']);
  1001. // additional bcc
  1002. if (strpos($additionalEmail['bcc'], ',') !== false)
  1003. $additionalEmail['bcc'] = explode(',', $additionalEmail['bcc']);
  1004. $mainframe->triggerEvent('rsfp_beforeAdditionalEmail', array(array('form' => &$form, 'placeholders' => &$placeholders, 'values' => &$values, 'submissionId' => $SubmissionId, 'additionalEmail'=>&$additionalEmail)));
  1005. eval($form->AdditionalEmailsScript);
  1006. // mail users
  1007. $recipients = explode(',',$additionalEmail['to']);
  1008. if(!empty($recipients))
  1009. foreach($recipients as $recipient)
  1010. if(!empty($recipient))
  1011. RSFormProHelper::sendMail($additionalEmail['from'], $additionalEmail['fromName'], $recipient, $additionalEmail['subject'], $additionalEmail['text'], $additionalEmail['mode'], !empty($additionalEmail['cc']) ? $additionalEmail['cc'] : null, !empty($additionalEmail['bcc']) ? $additionalEmail['bcc'] : null, $additionalEmail['files'], !empty($additionalEmail['replyto']) ? $additionalEmail['replyto'] : '');
  1012. }
  1013. return array($placeholders, $values);
  1014. }
  1015. public static function escapeArray(&$val, &$key)
  1016. {
  1017. $db = JFactory::getDBO();
  1018. $val = $db->escape($val);
  1019. $key = $db->escape($key);
  1020. }
  1021. public static function componentExists($formId, $componentTypeId)
  1022. {
  1023. $formId = (int) $formId;
  1024. $db = JFactory::getDBO();
  1025. if (is_array($componentTypeId))
  1026. {
  1027. JArrayHelper::toInteger($componentTypeId);
  1028. $db->setQuery("SELECT ComponentId FROM #__rsform_components WHERE ComponentTypeId IN (".implode(',', $componentTypeId).") AND FormId='".$formId."' AND Published='1'");
  1029. }
  1030. else
  1031. {
  1032. $componentTypeId = (int) $componentTypeId;
  1033. $db->setQuery("SELECT ComponentId FROM #__rsform_components WHERE ComponentTypeId='".$componentTypeId."' AND FormId='".$formId."' AND Published='1'");
  1034. }
  1035. return $db->loadColumn();
  1036. }
  1037. public static function cleanCache()
  1038. {
  1039. $cache = JCache::getInstance('page');
  1040. $id = $cache->makeId();
  1041. if ($handler = $cache->_getStorage()) {
  1042. $handler->remove($id, 'page');
  1043. }
  1044. // Test this
  1045. // $cache->clean();
  1046. }
  1047. public static function loadTheme($form)
  1048. {
  1049. jimport('joomla.html.parameter');
  1050. $doc = JFactory::getDocument();
  1051. $registry = new JRegistry();
  1052. $registry->loadString($form->ThemeParams, 'INI');
  1053. $form->ThemeParams =& $registry;
  1054. if ($form->ThemeParams->get('num_css', 0) > 0)
  1055. for ($i=0; $i<$form->ThemeParams->get('num_css'); $i++)
  1056. {
  1057. $css = $form->ThemeParams->get('css'.$i);
  1058. $doc->addStyleSheet(JURI::root(true).'/components/com_rsform/assets/themes/'.$form->ThemeParams->get('name').'/'.$css);
  1059. }
  1060. if ($form->ThemeParams->get('num_js', 0) > 0)
  1061. for ($i=0; $i<$form->ThemeParams->get('num_js'); $i++)
  1062. {
  1063. $js = $form->ThemeParams->get('js'.$i);
  1064. $doc->addScript(JURI::root(true).'/components/com_rsform/assets/themes/'.$form->ThemeParams->get('name').'/'.$js);
  1065. }
  1066. }
  1067. // conditions
  1068. public static function getConditions($formId, $lang=null)
  1069. {
  1070. $db = JFactory::getDBO();
  1071. if (!$lang)
  1072. $lang = RSFormProHelper::getCurrentLanguage();
  1073. // get all conditions
  1074. $db->setQuery("SELECT c.*,p.PropertyValue AS ComponentName FROM `#__rsform_conditions` c LEFT JOIN #__rsform_properties p ON (c.component_id = p.ComponentId) LEFT JOIN #__rsform_components comp ON (comp.ComponentId=p.ComponentId) WHERE c.`form_id` = ".$formId." AND c.lang_code='".$db->escape($lang)."' AND comp.Published = 1 AND p.PropertyName='NAME' ORDER BY c.`id` ASC");
  1075. if ($conditions = $db->loadObjectList())
  1076. {
  1077. // put them all in an array so we can use only one query
  1078. $cids = array();
  1079. foreach ($conditions as $condition)
  1080. $cids[] = $condition->id;
  1081. // get details
  1082. $db->setQuery("SELECT d.*,p.PropertyValue AS ComponentName FROM #__rsform_condition_details d LEFT JOIN #__rsform_properties p ON (d.component_id = p.ComponentId) LEFT JOIN #__rsform_components comp ON (comp.ComponentId=p.ComponentId) WHERE d.condition_id IN (".implode(",", $cids).") AND comp.Published = 1 AND p.PropertyName='NAME'");
  1083. $details = $db->loadObjectList();
  1084. // arrange details within conditions
  1085. foreach ($conditions as $i => $condition)
  1086. {
  1087. $condition->details = array();
  1088. foreach ($details as $detail)
  1089. {
  1090. if ($detail->condition_id != $condition->id) continue;
  1091. $condition->details[] = $detail;
  1092. }
  1093. $conditions[$i] = $condition;
  1094. }
  1095. // all done
  1096. return $conditions;
  1097. }
  1098. // nothing found
  1099. return false;
  1100. }
  1101. public static function showForm($formId, $val='', $validation=array())
  1102. {
  1103. $mainframe = JFactory::getApplication();
  1104. $formId = (int) $formId;
  1105. $db = JFactory::getDBO();
  1106. $doc = JFactory::getDocument();
  1107. $db->setQuery("SELECT `FormId`, `FormLayoutName`, `FormLayout`, `ScriptDisplay`, `ErrorMessage`, `FormTitle`, `CSS`, `JS`, `CSSClass`, `CSSId`, `CSSName`, `CSSAction`, `CSSAdditionalAttributes`, `AjaxValidation`, `ThemeParams` FROM #__rsform_forms WHERE FormId='".$formId."' AND `Published`='1'");
  1108. $form = $db->loadObject();
  1109. $lang = RSFormProHelper::getCurrentLanguage();
  1110. $translations = RSFormProHelper::getTranslations('forms', $form->FormId, $lang);
  1111. if ($translations)
  1112. foreach ($translations as $field => $value)
  1113. {
  1114. if (isset($form->$field))
  1115. $form->$field = $value;
  1116. }
  1117. if ($form->JS)
  1118. $doc->addCustomTag($form->JS);
  1119. if ($form->CSS)
  1120. $doc->addCustomTag($form->CSS);
  1121. if ($form->ThemeParams)
  1122. RSFormProHelper::loadTheme($form);
  1123. $doc->addStyleSheet(JURI::root(true).'/components/com_rsform/assets/css/front.css');
  1124. if ($doc->getDirection() == 'rtl')
  1125. $doc->addStyleSheet(JURI::root(true).'/components/com_rsform/assets/css/front-rtl.css');
  1126. $doc->addScript(JURI::root(true).'/components/com_rsform/assets/js/script.js');
  1127. $calendars = RSFormProHelper::componentExists($formId, 6); //6 is the componentTypeId for calendar
  1128. if(!empty($calendars))
  1129. {
  1130. $doc->addStyleSheet(JURI::root(true).'/components/com_rsform/assets/calendar/calendar.css');
  1131. $hidden = JRequest::getVar('hidden');
  1132. $all_data = RSFormProHelper::getComponentProperties($calendars);
  1133. foreach($calendars as $i => $calendarComponentId)
  1134. {
  1135. $data = $all_data[$calendarComponentId];
  1136. $calendars['CALENDARLAYOUT'][$i] = $data['CALENDARLAYOUT'];
  1137. $calendars['DATEFORMAT'][$i] = $data['DATEFORMAT'];
  1138. $calendars['VALUES'][$i] = '';
  1139. $calendars['EXTRA'][$i] = array();
  1140. if (!empty($hidden[$data['NAME']]))
  1141. $calendars['VALUES'][$i] = preg_replace('#[^0-9\/]+#i', '', $hidden[$data['NAME']]);
  1142. if (!empty($data['MINDATE']))
  1143. $calendars['EXTRA'][$i][] = "'mindate': '".$data['MINDATE']."'";
  1144. if (!empty($data['MAXDATE']))
  1145. $calendars['EXTRA'][$i][] = "'maxdate': '".$data['MAXDATE']."'";
  1146. $calendars['EXTRA'][$i] = '{'.implode(', ', $calendars['EXTRA'][$i]).'}';
  1147. }
  1148. unset($all_data);
  1149. $calendarsLayout = "'".implode("','", $calendars['CALENDARLAYOUT'])."'";
  1150. $calendarsFormat = "'".implode("','", $calendars['DATEFORMAT'])."'";
  1151. $calendarsValues = "'".implode("','", $calendars['VALUES'])."'";
  1152. $calendarsExtra = implode(',', $calendars['EXTRA']);
  1153. }
  1154. $formLayout = $form->FormLayout;
  1155. unset($form->FormLayout);
  1156. $errorMessage = $form->ErrorMessage;
  1157. unset($form->ErrorMessage);
  1158. $db->setQuery("SELECT p.PropertyValue AS name, c.ComponentId, c.ComponentTypeId, ct.ComponentTypeName, c.Order FROM #__rsform_properties p LEFT JOIN #__rsform_components c ON (c.ComponentId=p.ComponentId) LEFT JOIN #__rsform_component_types ct ON (ct.ComponentTypeId=c.ComponentTypeId) WHERE c.FormId='".$formId."' AND p.PropertyName='NAME' AND c.Published='1' ORDER BY c.Order");
  1159. $components = $db->loadObjectList();
  1160. $pages = array();
  1161. $page_progress = array();
  1162. $submits = array();
  1163. foreach ($components as $component)
  1164. {
  1165. if ($component->ComponentTypeId == 41)
  1166. $pages[] = $component->ComponentId;
  1167. elseif ($component->ComponentTypeId == 13)
  1168. $submits[] = $component->ComponentId;
  1169. }
  1170. $start_page = 0;
  1171. if (!empty($validation))
  1172. foreach ($components as $component)
  1173. {
  1174. if (in_array($component->ComponentId, $validation))
  1175. break;
  1176. if ($component->ComponentTypeId == 41)
  1177. $start_page++;
  1178. }
  1179. $find = array();
  1180. $replace = array();
  1181. $all_data = RSFormProHelper::getComponentProperties($components);
  1182. foreach ($components as $component)
  1183. {
  1184. $data = $all_data[$component->ComponentId];
  1185. $data['componentTypeId'] = $component->ComponentTypeId;
  1186. $data['ComponentTypeName'] = $component->ComponentTypeName;
  1187. $data['Order'] = $component->Order;
  1188. // Pagination
  1189. if ($component->ComponentTypeId == 41)
  1190. {
  1191. $data['PAGES'] = $pages;
  1192. $page_progress[] = array('show' => @$data['DISPLAYPROGRESS'] == 'YES', 'text' => @$data['DISPLAYPROGRESSMSG']);
  1193. }
  1194. elseif ($component->ComponentTypeId == 13)
  1195. {
  1196. $data['SUBMITS'] = $submits;
  1197. if ($componen

Large files files are truncated, but you can click here to view the full file