PageRenderTime 84ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://bitbucket.org/organicdevelopment/joomla-2.5
PHP | 3182 lines | 2568 code | 464 blank | 150 comment | 480 complexity | bdd0af366eb5ce7b1bb8307504cf05dd MD5 | raw file
Possible License(s): LGPL-3.0, GPL-2.0, MIT, BSD-3-Clause, LGPL-2.1

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

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