PageRenderTime 65ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  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 ($components as $component)
  1186. {
  1187. if ($component->ComponentTypeId == 41)
  1188. $pages[] = $component->ComponentId;
  1189. elseif ($component->ComponentTypeId == 13)
  1190. $submits[] = $component->ComponentId;
  1191. }
  1192. $start_page = 0;
  1193. if (!empty($validation))
  1194. foreach ($components as $component)
  1195. {
  1196. if (in_array($component->ComponentId, $validation))
  1197. break;
  1198. if ($component->ComponentTypeId == 41)
  1199. $start_page++;
  1200. }
  1201. $find = array();
  1202. $replace = array();
  1203. $all_data = RSFormProHelper::getComponentProperties($components);
  1204. foreach ($components as $component)
  1205. {
  1206. $data = $all_data[$component->ComponentId];
  1207. $data['componentTypeId'] = $component->ComponentTypeId;
  1208. $data['ComponentTypeName'] = $component->ComponentTypeName;
  1209. $data['Order'] = $component->Order;
  1210. // Pagination
  1211. if ($component->ComponentTypeId == 41)
  1212. {
  1213. $data['PAGES'] = $pages;
  1214. $page_progress[] = array('show' => @$data['DISPLAYPROGRESS'] == 'YES', 'text' => @$data['DISPLAYPROGRESSMSG']);
  1215. }
  1216. elseif ($component->ComponentTypeId == 13)
  1217. {
  1218. $data['SUBMITS'] = $submits;
  1219. if ($component->ComponentId == end($submits))
  1220. $page_progress[] = array('show' => @$data['DISPLAYPROGRESS'] == 'YES', 'text' => @$data['DISPLAYPROGRESSMSG']);
  1221. }
  1222. // Caption
  1223. $find[] = '{'.$component->name.':caption}';
  1224. $caption = '';
  1225. if (isset($data['SHOW']) && $data['SHOW'] == 'NO')
  1226. $caption = '';
  1227. elseif (isset($data['CAPTION']))
  1228. $caption = $data['CAPTION'];
  1229. $replace[] = $caption;
  1230. // Body
  1231. $find[] = '{'.$component->name.':body}';
  1232. $replace[] = RSFormProHelper::getFrontComponentBody($formId, $component->ComponentId, $data, $val, in_array($component->ComponentId,$validation), $form->FormLayoutName);
  1233. // Description
  1234. $find[] = '{'.$component->name.':description}';
  1235. $description = '';
  1236. if (isset($data['SHOW']) && $data['SHOW'] == 'NO')
  1237. $description = '';
  1238. elseif (isset($data['DESCRIPTION']))
  1239. $description = $data['DESCRIPTION'];
  1240. $replace[] = $description;
  1241. // Validation message
  1242. $find[] = '{'.$component->name.':validation}';
  1243. $validationMessage = '';
  1244. if (isset($data['SHOW']) && $data['SHOW'] == 'NO')
  1245. $validationMessage = '';
  1246. elseif (isset($data['VALIDATIONMESSAGE']))
  1247. {
  1248. if(!empty($validation) && in_array($component->ComponentId,$validation))
  1249. $validationMessage = '<span id="component'.$component->ComponentId.'" class="formError">'.$data['VALIDATIONMESSAGE'].'</span>';
  1250. else
  1251. $validationMessage = '<span id="component'.$component->ComponentId.'" class="formNoError">'.$data['VALIDATIONMESSAGE'].'</span>';
  1252. }
  1253. $replace[] = $validationMessage;
  1254. }
  1255. unset($all_data);
  1256. $u = RSFormProHelper::getURL();
  1257. //Trigger Event - onInitFormDisplay
  1258. $mainframe->triggerEvent('rsfp_f_onInitFormDisplay',array(array('find'=>&$find,'replace'=>&$replace,'formLayout'=>&$formLayout)));
  1259. $user = JFactory::getUser();
  1260. $jconfig = JFactory::getConfig();
  1261. array_push($find, '{global:formtitle}', '{global:username}', '{global:userip}', '{global:userid}', '{global:useremail}', '{global:fullname}', '{global:sitename}', '{global:siteurl}');
  1262. array_push($replace, $form->FormTitle, $user->get('username'), isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '', $user->get('id'), $user->get('email'), $user->get('name'), $jconfig->getValue('config.sitename'), JURI::root());
  1263. $formLayout = str_replace($find,$replace,$formLayout);
  1264. if (strpos($formLayout, 'class="formError"') !== false)
  1265. $formLayout = str_replace('{error}', $errorMessage, $formLayout);
  1266. elseif ($form->AjaxValidation)
  1267. $formLayout = str_replace('{error}', '<div id="rsform_error_'.$formId.'" style="display: none;">'.$errorMessage.'</div>', $formLayout);
  1268. else
  1269. $formLayout = str_replace('{error}', '', $formLayout);
  1270. $formLayout.= '<input type="hidden" name="form[formId]" value="'.$formId.'"/>';
  1271. if ($form->FormLayoutName == 'responsive')
  1272. {
  1273. $form->CSSClass .= ' formResponsive';
  1274. if (RSFormProHelper::getConfig('auto_responsive'))
  1275. {
  1276. $doc->addCustomTag('<meta name="viewport" content="width=device-width, initial-scale=1.0">');
  1277. $mainframe->registerEvent('onAfterRender', '_modifyResponsiveTemplate');
  1278. }
  1279. }
  1280. $CSSClass = $form->CSSClass ? ' class="'.RSFormProHelper::htmlEscape(trim($form->CSSClass)).'"' : '';
  1281. $CSSId = $form->CSSId ? ' id="'.RSFormProHelper::htmlEscape(trim($form->CSSId)).'"' : '';
  1282. $CSSName = $form->CSSName ? ' name="'.RSFormProHelper::htmlEscape(trim($form->CSSName)).'"' : '';
  1283. $u = $form->CSSAction ? RSFormProHelper::htmlEscape($form->CSSAction) : $u;
  1284. $CSSAdditionalAttributes = $form->CSSAdditionalAttributes ? ' '.trim($form->CSSAdditionalAttributes) : '';
  1285. if (!empty($pages))
  1286. {
  1287. $total_pages = count($pages)+1;
  1288. $step = floor(100/$total_pages);
  1289. $replace_progress = array('{page}', '{total}', '{percent}');
  1290. $with_progress = array(1, $total_pages, $step*1);
  1291. $progress = reset($page_progress);
  1292. $progress_script = '';
  1293. $formLayout = '<div id="rsform_progress_'.$formId.'" class="rsformProgress">'.($progress['show'] ? str_replace($replace_progress, $with_progress, $progress['text']) : '').'</div>'."\n".$formLayout;
  1294. foreach ($page_progress as $p => $progress)
  1295. {
  1296. $progress['text'] = str_replace(array("\r", "\n"), array('', '\n'), addcslashes($progress['text'], "'"));
  1297. $replace_progress = array('{page}', '{total}', '{percent}');
  1298. $with_progress = array($p+1, $total_pages, $p+1 == $total_pages ? 100 : $step*($p+1));
  1299. $progress_script .= "if (page == ".$p.") document.getElementById('rsform_progress_".$formId."').innerHTML = '".($progress['show'] ? str_replace($replace_progress, $with_progress, $progress['text']) : '')."';";
  1300. }
  1301. $formLayout .= "\n".'<script type="text/javascript">'."\n".'function rsfp_showProgress_'.$formId.'(page) {'."\n".$progress_script."\n".'}'."\n".'</script>';
  1302. }
  1303. $formLayout = '<form method="post" '.$CSSId.$CSSClass.$CSSName.$CSSAdditionalAttributes.' enctype="multipart/form-data" action="'.RSFormProHelper::htmlEscape($u).'">'.$formLayout.'</form>';
  1304. if(!empty($calendars))
  1305. {
  1306. $formLayout .= "\n".'<script type="text/javascript" src="'.JURI::root(true).'/components/com_rsform/assets/calendar/cal.js?v=42"></script>'."\n";
  1307. $formLayout .= '<script type="text/javascript">'.RSFormProHelper::getCalendarJS().'</script>'."\n";
  1308. $formLayout .= '<script type="text/javascript" defer="defer">rsf_CALENDAR.util.Event.addListener(window, "load", rsfp_init('.$formId.',{ layouts: Array('.$calendarsLayout.'), formats: Array('.$calendarsFormat.'), values: Array('.$calendarsValues.'), extra: Array('.$calendarsExtra.') }));</script>'."\n";
  1309. }
  1310. if (!empty($pages))
  1311. {
  1312. $formLayout .= '<script type="text/javascript" src="'.JURI::root(true).'/components/com_rsform/assets/js/pages.js?v=42"></script>'."\n";
  1313. $formLayout .= '<script type="text/javascript">rsfp_changePage('.$formId.', '.$start_page.', '.count($pages).')</script>'."\n";
  1314. }
  1315. if ($form->AjaxValidation || !empty($pages))
  1316. $formLayout .= '<script type="text/javascript">var rsfp_ajax_root = \''.addslashes(JURI::root(true)).'\'</script>';
  1317. if ($form->AjaxValidation)
  1318. $formLayout .= '<script type="text/javascript">rsfp_addEvent(window, \'load\', function(){var form = rsfp_getForm('.$formId.'); form.onsubmit = ajaxValidation;});</script>';
  1319. if ($conditions = RSFormProHelper::getConditions($formId))
  1320. {
  1321. $formLayout .= '<script type="text/javascript">';
  1322. foreach ($conditions as $condition)
  1323. {
  1324. $formLayout .= "\n".'function rsfp_runCondition'.$condition->id.'(){';
  1325. if ($condition->details)
  1326. {
  1327. $condition_vars = array();
  1328. foreach ($condition->details as $detail)
  1329. {
  1330. $formLayout .= "\n"."isChecked = rsfp_verifyChecked(".$formId.", '".addslashes($detail->ComponentName)."', '".addslashes($detail->value)."');";
  1331. $formLayout .= "\n"."condition".$detail->id." = isChecked == ".($detail->operator == 'is' ? 'true' : 'false').";";
  1332. $condition_vars[] = "condition".$detail->id;
  1333. }
  1334. if ($condition->block)
  1335. {
  1336. $block = JFilterOutput::stringURLSafe($condition->ComponentName);
  1337. $formLayout .= "\n"."items = rsfp_getBlock(".$formId.", '".addslashes($block)."');";
  1338. }
  1339. else
  1340. {
  1341. $formLayout .= "\n"."items = rsfp_getFieldsByName(".$formId.", '".addslashes($condition->ComponentName)."');";
  1342. }
  1343. $formLayout .= "\n"."if (items) {";
  1344. $formLayout .= "\n"."if (".implode($condition->condition == 'all' ? '&&' : '||', $condition_vars).")";
  1345. $formLayout .= "\n"."rsfp_setDisplay(items, '".($condition->action == 'show' ? '' : 'none')."');";
  1346. $formLayout .= "\n".'else';
  1347. $formLayout .= "\n"."rsfp_setDisplay(items, '".($condition->action == 'show' ? 'none' : '')."');";
  1348. $formLayout .= "\n"."}";
  1349. }
  1350. $formLayout .= "\n".'}';
  1351. $formLayout .= "\n".'rsfp_runCondition'.$condition->id.'();';
  1352. if ($condition->details)
  1353. foreach ($condition->details as $detail)
  1354. {
  1355. $formLayout .= "\n"."rsfp_addCondition(".$formId.", '".addslashes($detail->ComponentName)."', rsfp_runCondition".$condition->id.");";
  1356. }
  1357. }
  1358. $formLayout .= "\n".'</script>';
  1359. }
  1360. $RSadapter = RSFormProHelper::getLegacyAdapter();
  1361. eval($form->ScriptDisplay);
  1362. //Trigger Event - onBeforeFormDisplay
  1363. $mainframe->triggerEvent('rsfp_f_onBeforeFormDisplay', array(array('formLayout'=>&$formLayout,'formId'=>$formId)));
  1364. return $formLayout;
  1365. }
  1366. function showThankYouMessage($formId)
  1367. {
  1368. $mainframe =& JFactory::getApplication();
  1369. $output = '';
  1370. $formId = (int) $formId;
  1371. $db =& JFactory::getDBO();
  1372. $db->setQuery("SELECT ThemeParams FROM #__rsform_forms WHERE FormId='".$formId."'");
  1373. $form = $db->loadObject();
  1374. if ($form->ThemeParams)
  1375. RSFormProHelper::loadTheme($form);
  1376. $session =& JFactory::getSession();
  1377. $formparams = $session->get('com_rsform.formparams.'.$formId);
  1378. $output = base64_decode($formparams->thankYouMessage);
  1379. // Clear
  1380. $session->clear('com_rsform.formparams.'.$formId);
  1381. //Trigger Event - onAfterShowThankyouMessage
  1382. $mainframe->triggerEvent('rsfp_f_onAfterShowThankyouMessage', array(array('output'=>&$output,'formId'=>&$formId)));
  1383. // Cache enabled ?
  1384. jimport('joomla.plugin.helper');
  1385. $cache_enabled = JPluginHelper::isEnabled('system', 'cache');
  1386. if ($cache_enabled)
  1387. RSFormProHelper::cleanCache();
  1388. return $output;
  1389. }
  1390. function processForm($formId)
  1391. {
  1392. $mainframe =& JFactory::getApplication();
  1393. $formId = (int) $formId;
  1394. $db = JFactory::getDBO();
  1395. $db->setQuery("SELECT `Keepdata`, `ConfirmSubmission`, `ScriptProcess`, `ScriptProcess2`, `UserEmailScript`, `AdminEmailScript`, `ReturnUrl`, `ShowThankyou`, `Thankyou`, `ShowContinue` FROM #__rsform_forms WHERE `FormId`='".$formId."'");
  1396. $form = $db->loadObject();
  1397. $lang = RSFormProHelper::getCurrentLanguage();
  1398. $translations = RSFormProHelper::getTranslations('forms', $formId, $lang);
  1399. if ($translations)
  1400. foreach ($translations as $field => $value)
  1401. {
  1402. if (isset($form->$field))
  1403. $form->$field = $value;
  1404. }
  1405. $invalid = RSFormProHelper::validateForm($formId);
  1406. //Trigger Event - onBeforeFormValidation
  1407. $mainframe->triggerEvent('rsfp_f_onBeforeFormValidation', array(array('invalid'=>&$invalid)));
  1408. $userEmail=array(
  1409. 'to'=>'',
  1410. 'cc'=>'',
  1411. 'bcc'=>'',
  1412. 'from'=>'',
  1413. 'replyto'=>'',
  1414. 'fromName'=>'',
  1415. 'text'=>'',
  1416. 'subject'=>'',
  1417. 'files' =>array()
  1418. );
  1419. $adminEmail=array(
  1420. 'to'=>'',
  1421. 'cc'=>'',
  1422. 'bcc'=>'',
  1423. 'from'=>'',
  1424. 'replyto'=>'',
  1425. 'fromName'=>'',
  1426. 'text'=>'',
  1427. 'subject'=>'',
  1428. 'files' =>array()
  1429. );
  1430. $post = JRequest::getVar('form', array(), 'post', 'none', JREQUEST_ALLOWRAW);
  1431. $_POST['form'] = $post;
  1432. $RSadapter = RSFormProHelper::getLegacyAdapter();
  1433. eval($form->ScriptProcess);
  1434. if (!empty($invalid))
  1435. return $invalid;
  1436. $post = $_POST['form'];
  1437. //Trigger Event - onBeforeFormProcess
  1438. $mainframe->triggerEvent('rsfp_f_onBeforeFormProcess');
  1439. if (empty($invalid))
  1440. {
  1441. // Cache enabled ?
  1442. jimport('joomla.plugin.helper');
  1443. $cache_enabled = JPluginHelper::isEnabled('system', 'cache');
  1444. if ($cache_enabled)
  1445. RSFormProHelper::cleanCache();
  1446. $user = JFactory::getUser();
  1447. $confirmsubmission = $form->ConfirmSubmission ? 0 : 1;
  1448. // Add to db (submission)
  1449. $date = JFactory::getDate();
  1450. $db->setQuery("INSERT INTO #__rsform_submissions SET `FormId`='".$formId."', `DateSubmitted`='".$date->toMySQL()."', `UserIp`='".(isset($_SERVER['REMOTE_ADDR']) ? $db->getEscaped($_SERVER['REMOTE_ADDR']) : '')."', `Username`='".$db->getEscaped($user->get('username'))."', `UserId`='".(int) $user->get('id')."', `Lang`='".RSFormProHelper::getCurrentLanguage()."', `confirmed` = '".$confirmsubmission."' ");
  1451. $db->query();
  1452. $SubmissionId = $db->insertid();
  1453. $files = JRequest::get('files');
  1454. if (isset($files['form']['tmp_name']) && is_array($files['form']['tmp_name']))
  1455. {
  1456. $names = array();
  1457. foreach ($files['form']['tmp_name'] as $fieldName => $val)
  1458. {
  1459. if ($files['form']['error'][$fieldName]) continue;
  1460. $names[] = $db->getEscaped($fieldName);
  1461. }
  1462. $componentIds = array();
  1463. if (!empty($names))
  1464. {
  1465. $db->setQuery("SELECT c.ComponentId, p.PropertyValue FROM #__rsform_components c LEFT JOIN #__rsform_properties p ON (c.ComponentId=p.ComponentId AND p.PropertyName='NAME') WHERE c.FormId='".$formId."' AND p.PropertyValue IN ('".implode("','", $names)."')");
  1466. $results = $db->loadObjectList();
  1467. foreach ($results as $result)
  1468. $componentIds[$result->PropertyValue] = $result->ComponentId;
  1469. }
  1470. $all_data = RSFormProHelper::getComponentProperties($componentIds);
  1471. jimport('joomla.filesystem.file');
  1472. foreach ($files['form']['tmp_name'] as $fieldName => $val)
  1473. {
  1474. if ($files['form']['error'][$fieldName]) continue;
  1475. $data = @$all_data[$componentIds[$fieldName]];
  1476. if (empty($data)) continue;
  1477. // Prefix
  1478. $prefix = uniqid('').'-';
  1479. if (isset($data['PREFIX']) && strlen(trim($data['PREFIX'])) > 0)
  1480. $prefix = RSFormProHelper::isCode($data['PREFIX']);
  1481. // Path
  1482. $realpath = realpath($data['DESTINATION'].DS);
  1483. if (substr($realpath, -1) != DS)
  1484. $realpath .= DS;
  1485. // Filename
  1486. $file = $realpath.$prefix.$files['form']['name'][$fieldName];
  1487. // Upload File
  1488. JFile::upload($files['form']['tmp_name'][$fieldName], $file);
  1489. // Add to db (submission value)
  1490. $db->setQuery("INSERT INTO #__rsform_submission_values SET `SubmissionId`='".$SubmissionId."', `FormId`='".$formId."', `FieldName`='".$db->getEscaped($fieldName)."', `FieldValue`='".$db->getEscaped($file)."'");
  1491. $db->query();
  1492. $emails = !empty($data['EMAILATTACH']) ? explode(',',$data['EMAILATTACH']) : array();
  1493. // Attach to user and admin email
  1494. if (in_array('useremail',$emails))
  1495. $userEmail['files'][] = $file;
  1496. if (in_array('adminemail',$emails))
  1497. $adminEmail['files'][] = $file;
  1498. }
  1499. }
  1500. //Trigger Event - onBeforeStoreSubmissions
  1501. $mainframe->triggerEvent('rsfp_f_onBeforeStoreSubmissions', array(array('formId'=>$formId,'post'=>&$post,'SubmissionId'=>$SubmissionId)));
  1502. // Add to db (values)
  1503. foreach ($post as $key => $val)
  1504. {
  1505. $val = is_array($val) ? implode("\n", $val) : $val;
  1506. $val = RSFormProHelper::stripJava($val);
  1507. $db->setQuery("INSERT INTO #__rsform_submission_values SET `SubmissionId`='".$SubmissionId."', `FormId`='".$formId."', `FieldName`='".$db->getEscaped($key)."', `FieldValue`='".$db->getEscaped($val)."'");
  1508. $db->query();
  1509. }
  1510. //Trigger Event - onAfterStoreSubmissions
  1511. $mainframe->triggerEvent('rsfp_f_onAfterStoreSubmissions', array(array('SubmissionId'=>$SubmissionId, 'formId'=>$formId)));
  1512. // Send emails
  1513. list($replace, $with) = RSFormProHelper::sendSubmissionEmails($SubmissionId);
  1514. // Thank You Message
  1515. $thankYouMessage = str_replace($replace, $with, $form->Thankyou);
  1516. $form->ReturnUrl = str_replace($replace, $with, $form->ReturnUrl);
  1517. // Set redirect link
  1518. $u = RSFormProHelper::getURL();
  1519. // Create the Continue button
  1520. $continueButton = '';
  1521. if ($form->ShowContinue)
  1522. {
  1523. // Create goto link
  1524. $goto = 'document.location.reload();';
  1525. // Cache workaround #1
  1526. if ($cache_enabled)
  1527. $goto = "document.location='".addslashes($u)."';";
  1528. if (!empty($form->ReturnUrl))
  1529. $goto = "document.location='".addslashes($form->ReturnUrl)."';";
  1530. // Continue button
  1531. $continueButtonLabel = JText::_('RSFP_THANKYOU_BUTTON');
  1532. if (strpos($continueButtonLabel, 'input'))
  1533. $continueButton = JText::sprintf('RSFP_THANKYOU_BUTTON',$goto);
  1534. else
  1535. $continueButton = '<br/><input type="button" class="rsform-submit-button" name="continue" value="'.JText::_('RSFP_THANKYOU_BUTTON').'" onclick="'.$goto.'"/>';
  1536. }
  1537. // get mappings data
  1538. $db->setQuery("SELECT * FROM #__rsform_mappings WHERE formId = ".(int) $formId." ORDER BY ordering ASC");
  1539. $mappings = $db->loadObjectList();
  1540. // get Post to another location
  1541. $db->setQuery("SELECT * FROM #__rsform_posts WHERE form_id='".(int) $formId."' AND enabled='1'");
  1542. $silentPost = $db->loadObject();
  1543. $RSadapter = RSFormProHelper::getLegacyAdapter();
  1544. eval($form->ScriptProcess2);
  1545. $thankYouMessage .= $continueButton;
  1546. //Mappings
  1547. if (!empty($mappings))
  1548. {
  1549. $lastinsertid = '';
  1550. $replacewith = $with;
  1551. array_walk($replacewith, array('RSFormProHelper', 'escapeSql'));
  1552. foreach ($mappings as $mapping)
  1553. {
  1554. //get the query
  1555. $query = RSFormProHelper::getMappingQuery($mapping);
  1556. //replace the placeholders
  1557. $query = str_replace($replace, $replacewith, $query);
  1558. //replace the last insertid placeholder
  1559. $query = str_replace('{last_insert_id}',$lastinsertid,$query);
  1560. if ($mapping->connection)
  1561. {
  1562. $options = array(
  1563. 'host' => $mapping->host,
  1564. 'user' => $mapping->username,
  1565. 'password' => $mapping->password,
  1566. 'database' => $mapping->database
  1567. );
  1568. $database = JDatabase::getInstance($options);
  1569. //is a valid database connection
  1570. if (is_a($database,'JException')) continue;
  1571. $database->setQuery($query);
  1572. $database->query();
  1573. $lastinsertid = $database->insertid();
  1574. } else
  1575. {
  1576. $db->setQuery($query);
  1577. $db->query();
  1578. $lastinsertid = $db->insertid();
  1579. }
  1580. }
  1581. }
  1582. if (!$form->Keepdata)
  1583. {
  1584. $db->setQuery("DELETE FROM #__rsform_submission_values WHERE SubmissionId = ".(int) $SubmissionId." ");
  1585. $db->query();
  1586. $db->setQuery("DELETE FROM #__rsform_submissions WHERE SubmissionId = ".(int) $SubmissionId." ");
  1587. $db->query();
  1588. }
  1589. if ($silentPost && !empty($silentPost->url) && $silentPost->url != 'http://')
  1590. {
  1591. // url
  1592. $url = $silentPost->url;
  1593. // set the variables to be sent
  1594. // the format of the variables is var1=value1&var2=value2&var3=value3
  1595. $data = array();
  1596. foreach ($post as $key => $value)
  1597. {
  1598. if (is_array($value))
  1599. foreach ($value as $post2 => $value2)
  1600. $data[] = urlencode($key).'[]='.urlencode($value2);
  1601. else
  1602. $data[] = urlencode($key).'='.urlencode($value);
  1603. }
  1604. // do we need to post silently?
  1605. if ($silentPost->silent)
  1606. {
  1607. $data = implode('&', $data);
  1608. $params = array(
  1609. 'method' => $silentPost->method ? 'POST' : 'GET'
  1610. );
  1611. require_once dirname(__FILE__).'/connect.php';
  1612. RSFormProConnect($url, $data, $params);
  1613. }
  1614. else
  1615. {
  1616. // just try to redirect
  1617. if ($silentPost->method)
  1618. {
  1619. @ob_end_clean();
  1620. // create form
  1621. $output = array();
  1622. $output[] = '<form id="formSubmit" method="POST" action="'.RSFormProHelper::htmlEscape($url).'">';
  1623. foreach ($post as $key => $value)
  1624. {
  1625. if (is_array($value))
  1626. foreach ($value as $post2 => $value2)
  1627. $output[] = '<input type="hidden" name="'.RSFormProHelper::htmlEscape($key).'[]" value="'.RSFormProHelper::htmlEscape($value2).'" />';
  1628. else
  1629. $output[] = '<input type="hidden" name="'.RSFormProHelper::htmlEscape($key).'[]" value="'.RSFormProHelper::htmlEscape($value).'" />';
  1630. }
  1631. $output[] = '</form>';
  1632. $output[] = '<script type="text/javascript">';
  1633. $output[] = 'function formSubmit() { document.getElementById(\'formSubmit\').submit(); }';
  1634. $output[] = 'try { window.addEventListener ? window.addEventListener("load",formSubmit,false) : window.attachEvent("onload",formSubmit); }';
  1635. $output[] = 'catch (err) { formSubmit(); }';
  1636. $output[] = '</script>';
  1637. // echo form and submit it
  1638. echo implode("\r\n", $output);
  1639. die();
  1640. }
  1641. else
  1642. {
  1643. $data = implode('&', $data);
  1644. $mainframe->redirect($url.(strpos($url, '?') === false ? '?' : '&').$data);
  1645. }
  1646. }
  1647. }
  1648. //Trigger - After form process
  1649. $mainframe->triggerEvent('rsfp_f_onAfterFormProcess', array(array('SubmissionId'=>$SubmissionId,'formId'=>$formId)));
  1650. if (!$form->ShowThankyou && $form->ReturnUrl)
  1651. {
  1652. $mainframe->redirect($form->ReturnUrl);
  1653. return;
  1654. }
  1655. // SESSION quick hack - we base64 encode it here and decode it when we show it
  1656. $session =& JFactory::getSession();
  1657. $formParams = new stdClass();
  1658. $formParams->formProcessed = true;
  1659. $formParams->submissionId = $SubmissionId;
  1660. $formParams->thankYouMessage = base64_encode($thankYouMessage);
  1661. $session->set('com_rsform.formparams.'.$formId, $formParams);
  1662. // Cache workaround #2
  1663. if ($cache_enabled)
  1664. {
  1665. $uniqid = uniqid('rsform');
  1666. $u .= (strpos($u, '?') === false) ? '?skipcache='.$uniqid : '&skipcache='.$uniqid;
  1667. }
  1668. $mainframe->redirect($u);
  1669. }
  1670. return false;
  1671. }
  1672. function getURL()
  1673. {
  1674. // IIS hack
  1675. if (RSFormProHelper::getConfig('global.iis') && !empty($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'IIS') !== false && !empty($_SERVER['QUERY_STRING']))
  1676. {
  1677. $u = JRoute::_('index.php?'.$_SERVER['QUERY_STRING'],false);
  1678. }
  1679. else
  1680. {
  1681. $u = JFactory::getURI();
  1682. if (RSFormProHelper::isJ16())
  1683. {
  1684. // 1.6
  1685. $u = JFactory::getURI($u->get('_uri'));
  1686. $u = $u->toString($parts = array('scheme', 'user', 'pass', 'host', 'port', 'path', 'query', 'fragment'));
  1687. }
  1688. else
  1689. {
  1690. // 1.5
  1691. $u = $u->toString();
  1692. // Joom!Fish workarounds...
  1693. if (file_exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomfish'.DS.'joomfish.php'))
  1694. {
  1695. $u = JFactory::getURI();
  1696. $u = $u->_uri;
  1697. }
  1698. // sh404SEF workarounds... as usual...
  1699. if (class_exists('shRouter'))
  1700. {
  1701. $shConfig = shRouter::shGetConfig();
  1702. if ($shConfig->Enabled)
  1703. {
  1704. $menus =& JApplication::getMenu('site', array());
  1705. $active = $menus->getActive();
  1706. if (!empty($active->home))
  1707. {
  1708. $db =& JFactory::getDBO();
  1709. $db->setQuery("SELECT `link` FROM #__menu WHERE `home`='1' LIMIT 1");
  1710. $u = JURI::root(true).'/'.$active->link.'&Itemid='.$active->id;
  1711. }
  1712. }
  1713. }
  1714. }
  1715. }
  1716. return $u;
  1717. }
  1718. function verifyChecked($componentName, $value, $post)
  1719. {
  1720. if (isset($post['form'][$componentName]))
  1721. {
  1722. if (is_array($post['form'][$componentName]) && in_array($value, $post['form'][$componentName]))
  1723. return 1;
  1724. if (!is_array($post['form'][$componentName]) && $post['form'][$componentName] == $value)
  1725. return 1;
  1726. return 0;
  1727. }
  1728. return 0;
  1729. }
  1730. function validateForm($formId)
  1731. {
  1732. require_once JPATH_SITE.DS.'components'.DS.'com_rsform'.DS.'helpers'.DS.'validation.php';
  1733. $mainframe =& JFactory::getApplication();
  1734. $db = JFactory::getDBO();
  1735. $invalid = array();
  1736. $formId = (int) $formId;
  1737. $post = JRequest::get('post', JREQUEST_ALLOWRAW);
  1738. $db->setQuery("SELECT ComponentId, ComponentTypeId FROM #__rsform_components WHERE FormId='".$formId."' AND Published=1 ORDER BY `Order`");
  1739. if ($components = $db->loadObjectList())
  1740. {
  1741. $componentIds = array();
  1742. foreach ($components as $component)
  1743. $componentIds[] = $component->ComponentId;
  1744. $all_data = RSFormProHelper::getComponentProperties($componentIds);
  1745. if (empty($all_data))
  1746. return $invalid;
  1747. if ($conditions = RSFormProHelper::getConditions($formId))
  1748. {
  1749. foreach ($conditions as $condition)
  1750. {
  1751. if ($condition->details)
  1752. {
  1753. $condition_vars = array();
  1754. foreach ($condition->details as $detail)
  1755. {
  1756. $isChecked = RSFormProHelper::verifyChecked($detail->ComponentName, $detail->value, $post);
  1757. $condition_vars[] = $detail->operator == 'is' ? $isChecked : !$isChecked;
  1758. }
  1759. // this check is performed like this
  1760. // 'all' must be true (ie. no 0s in the array); 'any' can be true (ie. one value of 1 in the array will do)
  1761. $result = $condition->condition == 'all'? !in_array(0, $condition_vars) : in_array(1, $condition_vars);
  1762. // if the item is hidden, no need to validate it
  1763. if (($condition->action == 'show' && !$result) || ($condition->action == 'hide' && $result))
  1764. foreach ($components as $i => $component)
  1765. if ($component->ComponentId == $condition->component_id)
  1766. {
  1767. // ... just remove it from the components array
  1768. unset($components[$i]);
  1769. break;
  1770. }
  1771. }
  1772. }
  1773. }
  1774. foreach ($components as $component)
  1775. {
  1776. $data = $all_data[$component->ComponentId];
  1777. $required = isset($data['REQUIRED']) ? $data['REQUIRED'] : 'NO';
  1778. $validationRule = isset($data['VALIDATIONRULE']) ? $data['VALIDATIONRULE'] : '';
  1779. $typeId = $component->ComponentTypeId;
  1780. // CAPTCHA
  1781. if ($typeId == 8)
  1782. {
  1783. $session =& JFactory::getSession();
  1784. $captchaCode = $session->get('com_rsform.captcha.'.$component->ComponentId);
  1785. if ($data['IMAGETYPE'] == 'INVISIBLE')
  1786. {
  1787. $words = RSFormProHelper::getInvisibleCaptchaWords();
  1788. if (!empty($post[$captchaCode]))
  1789. $invalid[] = $data['componentId'];
  1790. foreach ($words as $word)
  1791. if (!empty($post[$word]))
  1792. $invalid[] = $data['componentId'];
  1793. }
  1794. else
  1795. {
  1796. if (empty($post['form'][$data['NAME']]) || empty($captchaCode) || $post['form'][$data['NAME']] != $captchaCode)
  1797. $invalid[] = $data['componentId'];
  1798. }
  1799. }
  1800. // Trigger Event - rsfp_bk_validate_onSubmitValidateRecaptcha
  1801. if ($typeId == 24)
  1802. $mainframe->triggerEvent('rsfp_bk_validate_onSubmitValidateRecaptcha',array(array('data'=> &$data,'invalid'=> &$invalid)));
  1803. if ($typeId == 9)
  1804. {
  1805. $files = JRequest::getVar('form', null, 'files');
  1806. // File has been *sent* to the server
  1807. if (isset($files['tmp_name'][$data['NAME']]) && $files['error'][$data['NAME']] != 4)
  1808. {
  1809. // File has been uploaded correctly to the server
  1810. if ($files['error'][$data['NAME']] == 0)
  1811. {
  1812. // Let's check if the extension is allowed
  1813. $buf = explode('.', $files['name'][$data['NAME']]);
  1814. $m = '#'.preg_quote($buf[count($buf)-1]).'#';
  1815. if (!empty($data['ACCEPTEDFILES']) && !preg_match(strtolower($m),strtolower($data['ACCEPTEDFILES'])))
  1816. $invalid[] = $data['componentId'];
  1817. // Let's check if it's the correct size
  1818. if ($files['size'][$data['NAME']] > 0 && $data['FILESIZE'] > 0 && $files['size'][$data['NAME']] > $data['FILESIZE']*1024)
  1819. $invalid[] = $data['componentId'];
  1820. }
  1821. // File has not been uploaded correctly - next version we'll trigger some messages based on the error code
  1822. else
  1823. $invalid[] = $data['componentId'];
  1824. }
  1825. // File has not been sent but it's required
  1826. elseif($required == 'YES')
  1827. $invalid[] = $data['componentId'];
  1828. continue;
  1829. }
  1830. if ($required == 'YES')
  1831. {
  1832. if (!isset($post['form'][$data['NAME']]))
  1833. {
  1834. $invalid[] = $data['componentId'];
  1835. continue;
  1836. }
  1837. if (!is_array($post['form'][$data['NAME']]) && strlen(trim($post['form'][$data['NAME']])) == 0)
  1838. {
  1839. $invalid[] = $data['componentId'];
  1840. continue;
  1841. }
  1842. if (!is_array($post['form'][$data['NAME']]) && strlen(trim($post['form'][$data['NAME']])) > 0 && is_callable(array('RSFormProValidations', $validationRule)) && call_user_func(array('RSFormProValidations', $validationRule),$post['form'][$data['NAME']],isset($data['VALIDATIONEXTRA']) ? $data['VALIDATIONEXTRA'] : '',$data) == false)
  1843. {
  1844. $invalid[] = $data['componentId'];
  1845. continue;
  1846. }
  1847. if (is_array($post['form'][$data['NAME']]))
  1848. {
  1849. $valid = implode('',$post['form'][$data['NAME']]);
  1850. if(empty($valid))
  1851. {
  1852. $invalid[] = $data['componentId'];
  1853. continue;
  1854. }
  1855. }
  1856. }
  1857. else
  1858. {
  1859. if (isset($post['form'][$data['NAME']]) && !is_array($post['form'][$data['NAME']]) && strlen(trim($post['form'][$data['NAME']])) > 0 && is_callable(array('RSFormProValidations', $validationRule)) && call_user_func(array('RSFormProValidations', $validationRule),$post['form'][$data['NAME']],isset($data['VALIDATIONEXTRA']) ? $data['VALIDATIONEXTRA'] : '', $data) == false)
  1860. {
  1861. $invalid[] = $data['componentId'];
  1862. continue;
  1863. }
  1864. }
  1865. }
  1866. }
  1867. return $invalid;
  1868. }
  1869. function getFrontComponentBody($formId, $componentId, $data, $value='', $invalid=false, $layoutName)
  1870. {
  1871. $mainframe =& JFactory::getApplication();
  1872. $formId = (int) $formId;
  1873. $componentId = (int) $componentId;
  1874. $db = JFactory::getDBO();
  1875. // Optimized, don't need this anymore
  1876. //$db->setQuery("SELECT `ComponentTypeId`, `Order` FROM #__rsform_components WHERE ComponentId='".$componentId."' LIMIT 1");
  1877. //$r = $db->loadAssoc();
  1878. // For legacy reasons...
  1879. $r = array();
  1880. $r['ComponentTypeId'] = $data['componentTypeId'];
  1881. $r['Order'] = @$data['Order'];
  1882. $out = '';
  1883. //Trigger Event - rsfp_bk_onBeforeCreateFrontComponentBody
  1884. $mainframe->triggerEvent('rsfp_bk_onBeforeCreateFrontComponentBody',array(array('out'=>&$out, 'formId'=>$formId, 'componentId'=>$componentId,'data'=>&$data,'value'=>&$value)));
  1885. switch($data['ComponentTypeName'])
  1886. {
  1887. case 1:
  1888. case 'textBox':
  1889. $defaultValue = RSFormProHelper::isCode($data['DEFAULTVALUE']);
  1890. $className = 'rsform-input-box';
  1891. if ($invalid)
  1892. $className .= ' rsform-error';
  1893. RSFormProHelper::addClass($data['ADDITIONALATTRIBUTES'], $className);
  1894. $out .= '<input type="text" value="'.(isset($value[$data['NAME']]) ? RSFormProHelper::htmlEscape($value[$data['NAME']]) : RSFormProHelper::htmlEscape($defaultValue)).'" size="'.$data['SIZE'].'" '.((int) $data['MAXSIZE'] > 0 ? 'maxlength="'.(int) $data['MAXSIZE'].'"' : '').' name="form['.$data['NAME'].']" id="'.$data['NAME'].'" '.$data['ADDITIONALATTRIBUTES'].'/>';
  1895. break;
  1896. case 2:
  1897. case 'textArea':
  1898. $defaultValue = RSFormProHelper::isCode($data['DEFAULTVALUE']);
  1899. $className = 'rsform-text-box';
  1900. if ($invalid)
  1901. $className .= ' rsform-error';
  1902. RSFormProHelper::addClass($data['ADDITIONALATTRIBUTES'], $className);
  1903. if (isset($data['WYSIWYG']) && $data['WYSIWYG'] == 'YES')
  1904. {
  1905. $out .= RSFormProHelper::WYSIWYG('form['.$data['NAME'].']', (isset($value[$data['NAME']]) ? RSFormProHelper::htmlEscape($value[$data['NAME']]) : RSFormProHelper::htmlEscape($defaultValue)), 'id['.$data['NAME'].']', $data['COLS']*10, $data['ROWS']*10, $data['COLS'], $data['ROWS']);
  1906. }
  1907. else
  1908. $out .= '<textarea cols="'.(int) $data['COLS'].'" rows="'.(int) $data['ROWS'].'" name="form['.$data['NAME'].']" id="'.$data['NAME'].'" '.$data['ADDITIONALATTRIBUTES'].'>'.(isset($value[$data['NAME']]) ? RSFormProHelper::htmlEscape($value[$data['NAME']]) : RSFormProHelper::htmlEscape($defaultValue)).'</textarea>';
  1909. break;
  1910. case 3:
  1911. case 'selectList':
  1912. $className = 'rsform-select-box';
  1913. if ($invalid)
  1914. $className .= ' rsform-error';
  1915. RSFormProHelper::addClass($data['ADDITIONALATTRIBUTES'], $className);
  1916. $out .= '<select '.($data['MULTIPLE']=='YES' ? 'multiple="multiple"' : '').' name="form['.$data['NAME'].'][]" '.((int) $data['SIZE'] > 0 ? 'size="'.(int) $data['SIZE'].'"' : '').' id="'.$data['NAME'].'" '.$data['ADDITIONALATTRIBUTES'].' >';
  1917. $items = RSFormProHelper::explode(RSFormProHelper::isCode($data['ITEMS']));
  1918. $special = array('[c]', '[g]', '[d]');
  1919. foreach ($items as $item)
  1920. {
  1921. @list($val, $txt) = @explode('|', str_replace($special, '', $item), 2);
  1922. if (is_null($txt))
  1923. $txt = $val;
  1924. // <optgroup>
  1925. if (strpos($item, '[g]') !== false) {
  1926. $out .= '<optgroup label="'.RSFormProHelper::htmlEscape($val).'">';
  1927. continue;
  1928. }
  1929. // </optgroup>
  1930. if(strpos($item, '[/g]') !== false) {
  1931. $out .= '</optgroup>';
  1932. continue;
  1933. }
  1934. $additional = '';
  1935. // selected
  1936. if ((strpos($item, '[c]') !== false && empty($value)) || (isset($value[$data['NAME']]) && in_array($val, $value[$data['NAME']])))
  1937. $additional .= 'selected="selected"';
  1938. // disabled
  1939. if (strpos($item, '[d]') !== false)
  1940. $additional .= 'disabled="disabled"';
  1941. $out .= '<option '.$additional.' value="'.RSFormProHelper::htmlEscape($val).'">'.RSFormProHelper::htmlEscape($txt).'</option>';
  1942. }
  1943. $out .= '</select>';
  1944. $option = JRequest::getCmd('option');
  1945. $view = JRequest::getCmd('view');
  1946. $layout = JRequest::getCmd('layout');
  1947. if ($option == 'com_rsevents' && $view == 'events' && $layout == 'subscribe' && $data['NAME'] == 'RSEventsTickets')
  1948. {
  1949. $db->setQuery("SELECT ConfigValue FROM #__rsevents_config WHERE ConfigName = 'event.multiple.tickets' ");
  1950. $multipleTickets = $db->loadResult();
  1951. if ($multipleTickets)
  1952. {
  1953. $lang =& JFactory::getLanguage();
  1954. $lang->load('com_rsevents', JPATH_SITE);
  1955. $out .= ' <a onclick="add_ticket(1,\''.JText::_('RSE_REMOVE_TICKET',true).'\');" href="javascript:void(0)">'.JText::_('RSE_ADD_TICKET').'</a> ';
  1956. $out .= '<br /><span id="tickets"></span>';
  1957. $out .= '<span id="rse_tickets_ids"></span>'."\n";
  1958. $out .= '<span id="rse_tickets_no"></span>'."\n";
  1959. }
  1960. }
  1961. break;
  1962. case 4:
  1963. case 'checkboxGroup':
  1964. $i = 0;
  1965. $items = RSFormProHelper::explode(RSFormProHelper::isCode($data['ITEMS']));
  1966. $special = array('[c]', '[d]');
  1967. foreach ($items as $item)
  1968. {
  1969. @list($val, $txt) = @explode('|', str_replace($special, '', $item), 2);
  1970. if (is_null($txt))
  1971. $txt = $val;
  1972. $additional = '';
  1973. // checked
  1974. if ((strpos($item, '[c]') !== false && empty($value)) || (isset($value[$data['NAME']]) && in_array($val, $value[$data['NAME']])))
  1975. $additional .= 'checked="checked"';
  1976. // disabled
  1977. if (strpos($item, '[d]') !== false)
  1978. $additional .= 'disabled="disabled"';
  1979. if ($data['FLOW']=='VERTICAL' && $layoutName == 'responsive')
  1980. $out .= '<p class="rsformVerticalClear">';
  1981. $out .= '<input '.$additional.' name="form['.$data['NAME'].'][]" type="checkbox" value="'.RSFormProHelper::htmlEscape($val).'" id="'.$data['NAME'].$i.'" '.$data['ADDITIONALATTRIBUTES'].' /><label for="'.$data['NAME'].$i.'">'.$txt.'</label>';
  1982. if ($data['FLOW']=='VERTICAL')
  1983. {
  1984. if ($layoutName == 'responsive')
  1985. $out .= '</p>';
  1986. else
  1987. $out .= '<br />';
  1988. }
  1989. $i++;
  1990. }
  1991. break;
  1992. case 5:
  1993. case 'radioGroup':
  1994. $i = 0;
  1995. $items = RSFormProHelper::explode(RSFormProHelper::isCode($data['ITEMS']));
  1996. $special = array('[c]', '[d]');
  1997. foreach ($items as $item)
  1998. {
  1999. @list($val, $txt) = @explode('|', str_replace($special, '', $item), 2);
  2000. if (is_null($txt))
  2001. $txt = $val;
  2002. $additional = '';
  2003. // checked
  2004. if ((strpos($item, '[c]') !== false && empty($value)) || (isset($value[$data['NAME']]) && $val == $value[$data['NAME']]))
  2005. $additional .= 'checked="checked"';
  2006. // disabled
  2007. if (strpos($item, '[d]') !== false)
  2008. $additional .= 'disabled="disabled"';
  2009. if ($data['FLOW']=='VERTICAL' && $layoutName == 'responsive')
  2010. $out .= '<p class="rsformVerticalClear">';
  2011. $out .= '<input '.$additional.' name="form['.$data['NAME'].']" type="radio" value="'.RSFormProHelper::htmlEscape($val).'" id="'.$data['NAME'].$i.'" '.$data['ADDITIONALATTRIBUTES'].' /><label for="'.$data['NAME'].$i.'">'.$txt.'</label>';
  2012. if ($data['FLOW']=='VERTICAL')
  2013. {
  2014. if ($layoutName == 'responsive')
  2015. $out .= '</p>';
  2016. else
  2017. $out .= '<br />';
  2018. }
  2019. $i++;
  2020. }
  2021. break;
  2022. case 6:
  2023. case 'calendar':
  2024. $calendars = RSFormProHelper::componentExists($formId, 6);
  2025. $calendars = array_flip($calendars);
  2026. $defaultValue = isset($value[$data['NAME']]) ? $value[$data['NAME']] : (isset($data['DEFAULTVALUE']) ? RSFormProHelper::isCode($data['DEFAULTVALUE']) : '');
  2027. switch($data['CALENDARLAYOUT'])
  2028. {
  2029. case 'FLAT':
  2030. $className = 'rsform-calendar-box';
  2031. if ($invalid)
  2032. $className .= ' rsform-error';
  2033. $out .= '<input id="txtcal'.$formId.'_'.$calendars[$componentId].'" name="form['.$data['NAME'].']" type="text" '.($data['READONLY'] == 'YES' ? 'readonly="readonly"' : '').' class="txtCal '.$className.'" value="'.RSFormProHelper::htmlEscape($defaultValue).'" '.$data['ADDITIONALATTRIBUTES'].'/><br />';
  2034. $out .= '<div id="cal'.$formId.'_'.$calendars[$componentId].'Container" style="z-index:'.(9999-$data['Order']).'"></div>';
  2035. break;
  2036. case 'POPUP':
  2037. $data['ADDITIONALATTRIBUTES2'] = $data['ADDITIONALATTRIBUTES'];
  2038. $className = 'rsform-calendar-box';
  2039. if ($invalid)
  2040. $className .= ' rsform-error';
  2041. RSFormProHelper::addClass($data['ADDITIONALATTRIBUTES'], $className);
  2042. $out .= '<input id="txtcal'.$formId.'_'.$calendars[$componentId].'" name="form['.$data['NAME'].']" type="text" '.($data['READONLY'] == 'YES' ? 'readonly="readonly"' : '').' value="'.RSFormProHelper::htmlEscape($defaultValue).'" '.$data['ADDITIONALATTRIBUTES'].'/>';
  2043. $className = 'rsform-calendar-button';
  2044. if ($invalid)
  2045. $className .= ' rsform-error';
  2046. $out .= '<input id="btn'.$formId.'_'.$calendars[$componentId].'" type="button" value="'.RSFormProHelper::htmlEscape($data['POPUPLABEL']).'" onclick="showHideCalendar(\'cal'.$formId.'_'.$calendars[$componentId].'Container\');" class="btnCal '.$className.'" '.$data['ADDITIONALATTRIBUTES2'].' />';
  2047. $out .= '<div id="cal'.$formId.'_'.$calendars[$componentId].'Container" style="clear:both;display:none;position:absolute;z-index:'.(9999-$data['Order']).'"></div>';
  2048. break;
  2049. }
  2050. $out .= '<input id="hiddencal'.$formId.'_'.$calendars[$componentId].'" type="hidden" name="hidden['.$data['NAME'].']" />';
  2051. break;
  2052. case 7:
  2053. case 'button':
  2054. $button_type = (isset($data['BUTTONTYPE']) && $data['BUTTONTYPE'] == 'TYPEBUTTON') ? 'button' : 'input';
  2055. $data['ADDITIONALATTRIBUTES2'] = $data['ADDITIONALATTRIBUTES'];
  2056. $className = 'rsform-button';
  2057. if ($invalid)
  2058. $className .= ' rsform-error';
  2059. RSFormProHelper::addClass($data['ADDITIONALATTRIBUTES'], $className);
  2060. if ($button_type == 'button')
  2061. $out .= '<button type="button" name="form['.$data['NAME'].']" id="'.$data['NAME'].'" '.$data['ADDITIONALATTRIBUTES'].'>'.RSFormProHelper::htmlEscape($data['LABEL']).'</button>';
  2062. else
  2063. $out .= '<input type="button" value="'.RSFormProHelper::htmlEscape($data['LABEL']).'" name="form['.$data['NAME'].']" id="'.$data['NAME'].'" '.$data['ADDITIONALATTRIBUTES'].' />';
  2064. if ($data['RESET']=='YES')
  2065. {
  2066. $className = 'rsform-reset-button';
  2067. RSFormProHelper::addClass($data['ADDITIONALATTRIBUTES2'], $className);
  2068. if ($button_type == 'button')
  2069. $out .= '&nbsp;&nbsp;<button type="reset" name="form['.$data['NAME'].']" id="'.$data['NAME'].'" '.$data['ADDITIONALATTRIBUTES2'].'>'.RSFormProHelper::htmlEscape($data['RESETLABEL']).'</button>';
  2070. else
  2071. $out .= '&nbsp;&nbsp;<input type="reset" value="'.RSFormProHelper::htmlEscape($data['RESETLABEL']).'" name="form['.$data['NAME'].']" id="'.$data['NAME'].'" '.$data['ADDITIONALATTRIBUTES2'].' />';
  2072. }
  2073. break;
  2074. case 8:
  2075. case 'captcha':
  2076. switch (@$data['IMAGETYPE'])
  2077. {
  2078. default:
  2079. case 'FREETYPE':
  2080. case 'NOFREETYPE':
  2081. $className = 'rsform-captcha-box';
  2082. if ($invalid)
  2083. $className .= ' rsform-error';
  2084. RSFormProHelper::addClass($data['ADDITIONALATTRIBUTES'], $className);
  2085. $out .= '<img src="'.JRoute::_('index.php?option=com_rsform&amp;task=captcha&amp;componentId='.$componentId.'&amp;tmpl=component&amp;sid='.mt_rand()).'" id="captcha'.$componentId.'" alt="'.RSFormProHelper::htmlEscape($data['CAPTION']).' "/>';
  2086. if ($data['FLOW'] == 'VERTICAL')
  2087. $out .= '<br />';
  2088. $out .= '<input type="text" name="form['.$data['NAME'].']" value="" id="captchaTxt'.$componentId.'" '.$data['ADDITIONALATTRIBUTES'].' />';
  2089. if ($data['SHOWREFRESH']=='YES')
  2090. $out .= '&nbsp;&nbsp;<a href="javascript:void(0)" onclick="refreshCaptcha('.$componentId.',\''.JRoute::_('index.php?option=com_rsform&task=captcha&componentId='.$componentId.'&tmpl=component').'\'); return false;">'.$data['REFRESHTEXT'].'</a>';
  2091. break;
  2092. case 'INVISIBLE':
  2093. // a list of words that spam bots might auto-complete
  2094. $words = RSFormProHelper::getInvisibleCaptchaWords();
  2095. $word = $words[array_rand($words, 1)];
  2096. // a list of styles so that the field is hidden
  2097. $styles = array('display: none !important', 'position: absolute !important; left: -4000px !important; top: -4000px !important;', 'position: absolute !important; left: -4000px !important; top: -4000px !important; display: none !important', 'position: absolute !important; display: none !important', 'display: none !important; position: absolute !important; left: -4000px !important; top: -4000px !important;');
  2098. $style = $styles[array_rand($styles, 1)];
  2099. // now we're going to shuffle the properties of the html tag
  2100. $properties = array('type="text"', 'name="'.$word.'"', 'value=""', 'style="'.$style.'"');
  2101. shuffle($properties);
  2102. $session =& JFactory::getSession();
  2103. $session->set('com_rsform.captcha.'.$componentId, $word);
  2104. $out .= '<input '.implode(' ', $properties).' />';
  2105. break;
  2106. }
  2107. break;
  2108. case 9:
  2109. case 'fileUpload':
  2110. $className = 'rsform-upload-box';
  2111. if ($invalid)
  2112. $className .= ' rsform-error';
  2113. RSFormProHelper::addClass($data['ADDITIONALATTRIBUTES'], $className);
  2114. $out .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.(int) $data['FILESIZE'].'000" />';
  2115. $out .= '<input type="file" name="form['.$data['NAME'].']" id="'.$data['NAME'].'" '.$data['ADDITIONALATTRIBUTES'].' />';
  2116. break;
  2117. case 10:
  2118. case 'freeText':
  2119. $out .= $data['TEXT'];
  2120. break;
  2121. case 11:
  2122. case 'hidden':
  2123. $defaultValue = RSFormProHelper::isCode($data['DEFAULTVALUE']);
  2124. $out .= '<input type="hidden" name="form['.$data['NAME'].']" id="'.$data['NAME'].'" value="'.RSFormProHelper::htmlEscape($defaultValue).'" '.$data['ADDITIONALATTRIBUTES'].' />';
  2125. break;
  2126. case 12:
  2127. case 'imageButton':
  2128. $data['ADDITIONALATTRIBUTES2'] = $data['ADDITIONALATTRIBUTES'];
  2129. $className = 'rsform-image-button';
  2130. RSFormProHelper::addClass($data['ADDITIONALATTRIBUTES'], $className);
  2131. $data['ADDITIONALATTRIBUTES3'] = $data['ADDITIONALATTRIBUTES'];
  2132. $pages = RSFormProHelper::componentExists($formId, 41);
  2133. $pages = count($pages);
  2134. if (!empty($pages))
  2135. {
  2136. if (empty($data['PREVBUTTON']))
  2137. $data['PREVBUTTON'] = JText::_('PREV');
  2138. $onclick = 'rsfp_changePage('.$formId.', '.($pages-1).', '.$pages.')';
  2139. RSFormProHelper::addOnClick($data['ADDITIONALATTRIBUTES3'], $onclick);
  2140. $out .= '<input type="button" value="'.RSFormProHelper::htmlEscape($data['PREVBUTTON']).'" id="'.$data['NAME'].'Prev" '.$data['ADDITIONALATTRIBUTES3'].' />';
  2141. }
  2142. $out .= '<input type="image" src="'.RSFormProHelper::htmlEscape($data['IMAGEBUTTON']).'" name="form['.$data['NAME'].']" id="'.$data['NAME'].'" '.$data['ADDITIONALATTRIBUTES2'].' />';
  2143. if ($data['RESET']=='YES')
  2144. {
  2145. $className = 'rsform-reset-button';
  2146. RSFormProHelper::addClass($data['ADDITIONALATTRIBUTES2'], $className);
  2147. $out .= '<input type="reset" name="" id="reset_'.$data['NAME'].'" style="display: none !important" />&nbsp;&nbsp;<input onclick="document.getElementById(\'reset_'.$data['NAME'].'\').click();return false;" type="image" src="'.RSFormProHelper::htmlEscape($data['IMAGERESET']).'" name="form['.$data['NAME'].']" '.$data['ADDITIONALATTRIBUTES2'].' />';
  2148. }
  2149. break;
  2150. case 13:
  2151. case 'submitButton':
  2152. $button_type = (isset($data['BUTTONTYPE']) && $data['BUTTONTYPE'] == 'TYPEBUTTON') ? 'button' : 'input';
  2153. $data['ADDITIONALATTRIBUTES2'] = $data['ADDITIONALATTRIBUTES'];
  2154. $className = 'rsform-submit-button';
  2155. RSFormProHelper::addClass($data['ADDITIONALATTRIBUTES'], $className);
  2156. $data['ADDITIONALATTRIBUTES3'] = $data['ADDITIONALATTRIBUTES'];
  2157. $last_submit = $componentId == end($data['SUBMITS']);
  2158. $pages = RSFormProHelper::componentExists($formId, 41);
  2159. $pages = count($pages);
  2160. if (!empty($pages) && $last_submit)
  2161. {
  2162. if (empty($data['PREVBUTTON']))
  2163. $data['PREVBUTTON'] = JText::_('PREV');
  2164. $onclick = 'rsfp_changePage('.$formId.', '.($pages-1).', '.$pages.')';
  2165. RSFormProHelper::addOnClick($data['ADDITIONALATTRIBUTES3'], $onclick);
  2166. if ($button_type == 'button')
  2167. $out .= '<button type="button" id="'.$data['NAME'].'Prev" '.$data['ADDITIONALATTRIBUTES3'].'>'.RSFormProHelper::htmlEscape($data['PREVBUTTON']).'</button>';
  2168. else
  2169. $out .= '<input type="button" value="'.RSFormProHelper::htmlEscape($data['PREVBUTTON']).'" id="'.$data['NAME'].'Prev" '.$data['ADDITIONALATTRIBUTES3'].' />';
  2170. }
  2171. if ($button_type == 'button')
  2172. $out .= '<button type="submit" name="form['.$data['NAME'].']" id="'.$data['NAME'].'" '.$data['ADDITIONALATTRIBUTES'].'>'.RSFormProHelper::htmlEscape($data['LABEL']).'</button>';
  2173. else
  2174. $out .= '<input type="submit" value="'.RSFormProHelper::htmlEscape($data['LABEL']).'" name="form['.$data['NAME'].']" id="'.$data['NAME'].'" '.$data['ADDITIONALATTRIBUTES'].' />';
  2175. if ($data['RESET']=='YES')
  2176. {
  2177. $className = 'rsform-reset-button';
  2178. RSFormProHelper::addClass($data['ADDITIONALATTRIBUTES2'], $className);
  2179. if ($button_type == 'button')
  2180. $out .= '&nbsp;&nbsp;<button type="reset" name="form['.$data['NAME'].']" '.$data['ADDITIONALATTRIBUTES2'].'>'.RSFormProHelper::htmlEscape($data['RESETLABEL']).'</button>';
  2181. else
  2182. $out .= '&nbsp;&nbsp;<input type="reset" value="'.RSFormProHelper::htmlEscape($data['RESETLABEL']).'" name="form['.$data['NAME'].']" '.$data['ADDITIONALATTRIBUTES2'].' />';
  2183. }
  2184. break;
  2185. case 14:
  2186. case 'password':
  2187. $defaultValue = '';
  2188. if ($data['VALIDATIONRULE'] != 'password')
  2189. $defaultValue = $data['DEFAULTVALUE'];
  2190. $className = 'rsform-password-box';
  2191. if ($invalid)
  2192. $className .= ' rsform-error';
  2193. RSFormProHelper::addClass($data['ADDITIONALATTRIBUTES'], $className);
  2194. $out .= '<input type="password" value="'.RSFormProHelper::htmlEscape($defaultValue).'" size="'.(int) $data['SIZE'].'" name="form['.$data['NAME'].']" id="'.$data['NAME'].'" '.((int) $data['MAXSIZE'] > 0 ? 'maxlength="'.(int) $data['MAXSIZE'].'"' : '').' '.$data['ADDITIONALATTRIBUTES'].' />';
  2195. break;
  2196. case 15:
  2197. case 'ticket':
  2198. $out .= '<input type="hidden" name="form['.$data['NAME'].']" value="'.RSFormProHelper::generateString($data['LENGTH'],$data['CHARACTERS']).'" '.$data['ADDITIONALATTRIBUTES'].' />';
  2199. break;
  2200. case 41:
  2201. case 'pageBreak':
  2202. $validate = 'false';
  2203. if (isset($data['VALIDATENEXTPAGE']) && $data['VALIDATENEXTPAGE'] == 'YES')
  2204. $validate = 'true';
  2205. $className = 'rsform-button';
  2206. if ($invalid)
  2207. $className .= ' rsform-error';
  2208. RSFormProHelper::addClass($data['ADDITIONALATTRIBUTES'], $className);
  2209. $data['ADDITIONALATTRIBUTES2'] = $data['ADDITIONALATTRIBUTES'];
  2210. $num = count($data['PAGES']);
  2211. $pos = array_search($componentId, $data['PAGES']);
  2212. if ($pos)
  2213. {
  2214. $onclick = 'rsfp_changePage('.$formId.', '.($pos-1).', '.$num.')';
  2215. RSFormProHelper::addOnClick($data['ADDITIONALATTRIBUTES'], $onclick);
  2216. $out .= '<input type="button" value="'.RSFormProHelper::htmlEscape($data['PREVBUTTON']).'" '.$data['ADDITIONALATTRIBUTES'].' id="'.$data['NAME'].'Prev" />';
  2217. }
  2218. if ($pos < count($data['PAGES']))
  2219. {
  2220. $onclick = 'rsfp_changePage('.$formId.', '.($pos+1).', '.$num.', '.$validate.')';
  2221. RSFormProHelper::addOnClick($data['ADDITIONALATTRIBUTES2'], $onclick);
  2222. $out .= '<input type="button" value="'.RSFormProHelper::htmlEscape($data['NEXTBUTTON']).'" '.$data['ADDITIONALATTRIBUTES2'].' id="'.$data['NAME'].'Next" />';
  2223. }
  2224. break;
  2225. case 32:
  2226. case 'rseprotickets':
  2227. $html = '';
  2228. if (JRequest::getCmd('option') == 'com_rseventspro')
  2229. {
  2230. $cid = JRequest::getInt('cid');
  2231. $db->setQuery("SELECT COUNT(id) FROM #__rseventspro_tickets WHERE ide = ".$cid."");
  2232. $eventtickets = $db->loadResult();
  2233. $html .= '<input type="text" id="numberinp" name="numberinp" value="1" size="3" style="display: none;" onkeyup="this.value=this.value.replace(/[^0-9\.\,]/g, \'\');" />';
  2234. $html .= '<select name="number" id="number"><option value="1">1</option></select> ';
  2235. $className = 'rsform-select-box';
  2236. if ($invalid)
  2237. $className .= ' rsform-error';
  2238. RSFormProHelper::addClass($data['ADDITIONALATTRIBUTES'], $className);
  2239. $html .= '<select name="form['.$data['NAME'].']" id="'.$data['NAME'].'" '.$data['ADDITIONALATTRIBUTES'].' >';
  2240. $items = RSFormProHelper::explode(RSFormProHelper::isCode($data['ITEMS']));
  2241. $special = array('[c]', '[g]', '[d]');
  2242. foreach ($items as $item)
  2243. {
  2244. @list($val, $txt) = @explode('|', str_replace($special, '', $item), 2);
  2245. if (is_null($txt))
  2246. $txt = $val;
  2247. // <optgroup>
  2248. if (strpos($item, '[g]') !== false) {
  2249. $out .= '<optgroup label="'.RSFormProHelper::htmlEscape($val).'">';
  2250. continue;
  2251. }
  2252. // </optgroup>
  2253. if(strpos($item, '[/g]') !== false) {
  2254. $out .= '</optgroup>';
  2255. continue;
  2256. }
  2257. $additional = '';
  2258. // selected
  2259. if ((strpos($item, '[c]') !== false && empty($value)) || (isset($value[$data['NAME']]) && $val == $value[$data['NAME']]))
  2260. $additional .= 'selected="selected"';
  2261. // disabled
  2262. if (strpos($item, '[d]') !== false)
  2263. $additional .= 'disabled="disabled"';
  2264. $html .= '<option '.$additional.' value="'.RSFormProHelper::htmlEscape($val).'">'.RSFormProHelper::htmlEscape($txt).'</option>';
  2265. }
  2266. $html .= '</select>';
  2267. if (JRequest::getCmd('option') == 'com_rseventspro' && JRequest::getCmd('layout') == 'subscribe')
  2268. {
  2269. $db->setQuery("SELECT `value` FROM `#__rseventspro_config` WHERE `name` = 'multi_tickets'");
  2270. $multipleTickets = $db->loadResult();
  2271. if ($multipleTickets)
  2272. {
  2273. $lang =& JFactory::getLanguage();
  2274. $lang->load('com_rseventspro', JPATH_SITE);
  2275. $html .= ' <a href="javascript:void(0);" onclick="rs_add_ticket();">'.JText::_('RSEPRO_SUBSCRIBER_ADD_TICKET').'</a> ';
  2276. }
  2277. }
  2278. $html .= ' <img id="rs_loader" src="'.JURI::root().'components/com_rseventspro/assets/images/loader.gif" alt="" style="vertical-align: middle; display: none;" />';
  2279. if (JRequest::getCmd('option') == 'com_rseventspro' && JRequest::getCmd('layout') == 'subscribe' && $multipleTickets)
  2280. {
  2281. $html .= '<br /> <br /> <span id="tickets"></span>';
  2282. $html .= '<span id="hiddentickets"></span>';
  2283. }
  2284. $html .= ' <br /> <span id="tdescription"></span>';
  2285. $html .= '<input type="hidden" name="from" id="from" value="" />';
  2286. if (!empty($eventtickets))
  2287. $out .= $html;
  2288. }
  2289. break;
  2290. }
  2291. //Trigger Event - rsfp_bk_onAfterCreateFrontComponentBody
  2292. $mainframe->triggerEvent('rsfp_bk_onAfterCreateFrontComponentBody',array(array('out'=>&$out, 'formId'=>$formId, 'componentId'=>$componentId,'data'=>$data,'value'=>$value,'r'=>$r, 'invalid' => $invalid)));
  2293. return $out;
  2294. }
  2295. function addClass(&$attributes, $className)
  2296. {
  2297. if (preg_match('#class="(.*?)"#is', $attributes, $matches))
  2298. $attributes = str_replace($matches[0], str_replace($matches[1], $matches[1].' '.$className, $matches[0]), $attributes);
  2299. else
  2300. $attributes .= ' class="'.$className.'"';
  2301. return $attributes;
  2302. }
  2303. function addOnClick(&$attributes, $onClick)
  2304. {
  2305. if (preg_match('#onclick="(.*?)"#is', $attributes, $matches))
  2306. $attributes = str_replace($matches[0], str_replace($matches[1], $matches[1].'; '.$onClick, $matches[0]), $attributes);
  2307. else
  2308. $attributes .= ' onclick="'.$onClick.'"';
  2309. return $attributes;
  2310. }
  2311. function getInvisibleCaptchaWords()
  2312. {
  2313. return array('Website', 'Email', 'Name', 'Address', 'User', 'Username', 'Comment', 'Message');
  2314. }
  2315. function generateString($length, $characters, $type='Random')
  2316. {
  2317. $length = (int) $length;
  2318. if($type == 'Random')
  2319. {
  2320. switch($characters)
  2321. {
  2322. case 'ALPHANUMERIC':
  2323. default:
  2324. $possible = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  2325. break;
  2326. case 'ALPHA':
  2327. $possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  2328. break;
  2329. case 'NUMERIC':
  2330. $possible = '0123456789';
  2331. break;
  2332. }
  2333. if($length<1||$length>255) $length = 8;
  2334. $key = '';
  2335. $i = 0;
  2336. while ($i < $length) {
  2337. $key .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
  2338. $i++;
  2339. }
  2340. }
  2341. if($type == 'Sequential')
  2342. {
  2343. $key = 0;
  2344. }
  2345. return $key;
  2346. }
  2347. // todo - use Joomla! string functions # done for now
  2348. // optimize to ignore false alerts
  2349. function stripJava($val)
  2350. {
  2351. static $filter;
  2352. if (is_null($filter))
  2353. {
  2354. jimport('joomla.filter.filterinput');
  2355. $filter =& JFilterInput::getInstance(array('form', 'input', 'select', 'textarea'), array('style'), 1, 1);
  2356. }
  2357. $val = preg_replace('/([\x00-\x08][\x0b-\x0c][\x0e-\x20])/', "", $val);
  2358. $val = str_replace("\0", "", $val);
  2359. return $filter->clean($val);
  2360. // remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed
  2361. // this prevents some character re-spacing such as <java\0script>
  2362. // note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs
  2363. $val = preg_replace('/([\x00-\x08][\x0b-\x0c][\x0e-\x20])/', '', $val);
  2364. // straight replacements, the user should never need these since they're normal characters
  2365. // this prevents like <IMG SRC=&#X40&#X61&#X76&#X61&#X73&#X63&#X72&#X69&#X70&#X74&#X3A&#X61&#X6C&#X65&#X72&#X74&#X28&#X27&#X58&#X53&#X53&#X27&#X29>
  2366. $search = 'abcdefghijklmnopqrstuvwxyz';
  2367. $search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  2368. $search .= '1234567890!@#$%^&*()';
  2369. $search .= '~`";:?+/={}[]-_|\'\\';
  2370. for ($i = 0; $i < strlen($search); $i++) {
  2371. // ;? matches the ;, which is optional
  2372. // 0{0,7} matches any padded zeros, which are optional and go up to 8 chars
  2373. // &#x0040 @ search for the hex values
  2374. $val = preg_replace('/(&#[x|X]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); // with a ;
  2375. // &#00064 @ 0{0,7} matches '0' zero to seven times
  2376. $val = preg_replace('/(&#0{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ;
  2377. }
  2378. // now the only remaining whitespace attacks are \t, \n, and \r
  2379. // ([ \t\r\n]+)?
  2380. $ra1 = Array('\/([ \t\r\n]+)?javascript', '\/([ \t\r\n]+)?vbscript', ':([ \t\r\n]+)?expression', '<([ \t\r\n]+)?applet', '<([ \t\r\n]+)?meta', '<([ \t\r\n]+)?xml', '<([ \t\r\n]+)?blink', '<([ \t\r\n]+)?link', '<([ \t\r\n]+)?style', '<([ \t\r\n]+)?script', '<([ \t\r\n]+)?embed', '<([ \t\r\n]+)?object', '<([ \t\r\n]+)?iframe', '<([ \t\r\n]+)?frame', '<([ \t\r\n]+)?frameset', '<([ \t\r\n]+)?ilayer', '<([ \t\r\n]+)?layer', '<([ \t\r\n]+)?bgsound', '<([ \t\r\n]+)?title', '<([ \t\r\n]+)?base');
  2381. $ra2 = Array('onabort([ \t\r\n]+)?=', 'onactivate([ \t\r\n]+)?=', 'onafterprint([ \t\r\n]+)?=', 'onafterupdate([ \t\r\n]+)?=', 'onbeforeactivate([ \t\r\n]+)?=', 'onbeforecopy([ \t\r\n]+)?=', 'onbeforecut([ \t\r\n]+)?=', 'onbeforedeactivate([ \t\r\n]+)?=', 'onbeforeeditfocus([ \t\r\n]+)?=', 'onbeforepaste([ \t\r\n]+)?=', 'onbeforeprint([ \t\r\n]+)?=', 'onbeforeunload([ \t\r\n]+)?=', 'onbeforeupdate([ \t\r\n]+)?=', 'onblur([ \t\r\n]+)?=', 'onbounce([ \t\r\n]+)?=', 'oncellchange([ \t\r\n]+)?=', 'onchange([ \t\r\n]+)?=', 'onclick([ \t\r\n]+)?=', 'oncontextmenu([ \t\r\n]+)?=', 'oncontrolselect([ \t\r\n]+)?=', 'oncopy([ \t\r\n]+)?=', 'oncut([ \t\r\n]+)?=', 'ondataavailable([ \t\r\n]+)?=', 'ondatasetchanged([ \t\r\n]+)?=', 'ondatasetcomplete([ \t\r\n]+)?=', 'ondblclick([ \t\r\n]+)?=', 'ondeactivate([ \t\r\n]+)?=', 'ondrag([ \t\r\n]+)?=', 'ondragend([ \t\r\n]+)?=', 'ondragenter([ \t\r\n]+)?=', 'ondragleave([ \t\r\n]+)?=', 'ondragover([ \t\r\n]+)?=', 'ondragstart([ \t\r\n]+)?=', 'ondrop([ \t\r\n]+)?=', 'onerror([ \t\r\n]+)?=', 'onerrorupdate([ \t\r\n]+)?=', 'onfilterchange([ \t\r\n]+)?=', 'onfinish([ \t\r\n]+)?=', 'onfocus([ \t\r\n]+)?=', 'onfocusin([ \t\r\n]+)?=', 'onfocusout([ \t\r\n]+)?=', 'onhelp([ \t\r\n]+)?=', 'onkeydown([ \t\r\n]+)?=', 'onkeypress([ \t\r\n]+)?=', 'onkeyup([ \t\r\n]+)?=', 'onlayoutcomplete([ \t\r\n]+)?=', 'onload([ \t\r\n]+)?=', 'onlosecapture([ \t\r\n]+)?=', 'onmousedown([ \t\r\n]+)?=', 'onmouseenter([ \t\r\n]+)?=', 'onmouseleave([ \t\r\n]+)?=', 'onmousemove([ \t\r\n]+)?=', 'onmouseout([ \t\r\n]+)?=', 'onmouseover([ \t\r\n]+)?=', 'onmouseup([ \t\r\n]+)?=', 'onmousewheel([ \t\r\n]+)?=', 'onmove([ \t\r\n]+)?=', 'onmoveend([ \t\r\n]+)?=', 'onmovestart([ \t\r\n]+)?=', 'onpaste([ \t\r\n]+)?=', 'onpropertychange([ \t\r\n]+)?=', 'onreadystatechange([ \t\r\n]+)?=', 'onreset([ \t\r\n]+)?=', 'onresize([ \t\r\n]+)?=', 'onresizeend([ \t\r\n]+)?=', 'onresizestart([ \t\r\n]+)?=', 'onrowenter([ \t\r\n]+)?=', 'onrowexit([ \t\r\n]+)?=', 'onrowsdelete([ \t\r\n]+)?=', 'onrowsinserted([ \t\r\n]+)?=', 'onscroll([ \t\r\n]+)?=', 'onselect([ \t\r\n]+)?=', 'onselectionchange([ \t\r\n]+)?=', 'onselectstart([ \t\r\n]+)?=', 'onstart([ \t\r\n]+)?=', 'onstop([ \t\r\n]+)?=', 'onsubmit([ \t\r\n]+)?=', 'onunload([ \t\r\n]+)?=', 'style([ \t\r\n]+)?=');
  2382. $ra = array_merge($ra1, $ra2);
  2383. foreach ($ra as $tag)
  2384. {
  2385. $pattern = '#'.$tag.'#i';
  2386. preg_match_all($pattern, $val, $matches);
  2387. foreach ($matches[0] as $match)
  2388. $val = str_replace($match, substr($match, 0, 2).'<x>'.substr($match, 2), $val);
  2389. }
  2390. return $val;
  2391. }
  2392. function getCalendarJS()
  2393. {
  2394. $out = '//CALENDAR SETUP'."\n";
  2395. $m_short = $m_long = array();
  2396. for ($i=1; $i<=12; $i++)
  2397. {
  2398. $m_short[] = '"'.JText::_('RSFP_CALENDAR_MONTHS_SHORT_'.$i, true).'"';
  2399. $m_long[] = '"'.JText::_('RSFP_CALENDAR_MONTHS_LONG_'.$i, true).'"';
  2400. }
  2401. $w_1 = $w_short = $w_med = $w_long = array();
  2402. for ($i=0; $i<=6; $i++)
  2403. {
  2404. $w_1[] = '"'.JText::_('RSFP_CALENDAR_WEEKDAYS_1CHAR_'.$i, true).'"';
  2405. $w_short[] = '"'.JText::_('RSFP_CALENDAR_WEEKDAYS_SHORT_'.$i, true).'"';
  2406. $w_med[] = '"'.JText::_('RSFP_CALENDAR_WEEKDAYS_MEDIUM_'.$i, true).'"';
  2407. $w_long[] = '"'.JText::_('RSFP_CALENDAR_WEEKDAYS_LONG_'.$i, true).'"';
  2408. }
  2409. $out .= 'var MONTHS_SHORT = Array('.implode(',', $m_short).');'."\n";
  2410. $out .= 'var MONTHS_LONG = Array('.implode(',', $m_long).');'."\n";
  2411. $out .= 'var WEEKDAYS_1CHAR = Array('.implode(',', $w_1).');'."\n";
  2412. $out .= 'var WEEKDAYS_SHORT = Array('.implode(',', $w_short).');'."\n";
  2413. $out .= 'var WEEKDAYS_MEDIUM = Array('.implode(',', $w_med).');'."\n";
  2414. $out .= 'var WEEKDAYS_LONG = Array('.implode(',', $w_long).');'."\n";
  2415. $out .= 'var START_WEEKDAY = '.JText::_('RSFP_CALENDAR_START_WEEKDAY').';';
  2416. return $out;
  2417. }
  2418. function getTranslations($reference, $formId, $lang, $select = 'value')
  2419. {
  2420. $db =& JFactory::getDBO();
  2421. $db->setQuery("SELECT `Lang` FROM #__rsform_forms WHERE FormId='".(int) $formId."'");
  2422. $current_lang = $db->loadResult();
  2423. if ($current_lang == $lang)
  2424. return false;
  2425. switch ($reference)
  2426. {
  2427. case 'forms':
  2428. $db->setQuery("SELECT * FROM #__rsform_translations WHERE `form_id`='".(int) $formId."' AND `lang_code`='".$db->getEscaped($lang)."' AND `reference`='forms'");
  2429. $results = $db->loadObjectList();
  2430. $return = array();
  2431. foreach ($results as $result)
  2432. $return[$result->reference_id] = ($select == '*') ? $result : (isset($result->$select) ? $result->$select : false);
  2433. return $return;
  2434. break;
  2435. case 'emails':
  2436. $db->setQuery("SELECT * FROM #__rsform_translations WHERE `form_id`='".(int) $formId."' AND `lang_code`='".$db->getEscaped($lang)."' AND `reference`='emails'");
  2437. $results = $db->loadObjectList();
  2438. $return = array();
  2439. foreach ($results as $result)
  2440. $return[$result->reference_id] = ($select == '*') ? $result : (isset($result->$select) ? $result->$select : false);
  2441. return $return;
  2442. break;
  2443. case 'properties':
  2444. $db->setQuery("SELECT * FROM #__rsform_translations WHERE `form_id`='".(int) $formId."' AND `lang_code`='".$db->getEscaped($lang)."' AND `reference`='properties'");
  2445. $results = $db->loadObjectList();
  2446. $return = array();
  2447. foreach ($results as $result)
  2448. $return[$result->reference_id] = ($select == '*') ? $result : (isset($result->$select) ? $result->$select : false);
  2449. return $return;
  2450. break;
  2451. }
  2452. return false;
  2453. }
  2454. function getTranslatableProperties()
  2455. {
  2456. return array('LABEL', 'RESETLABEL', 'PREVBUTTON', 'NEXTBUTTON', 'CAPTION', 'DESCRIPTION', 'VALIDATIONMESSAGE', 'DEFAULTVALUE', 'ITEMS', 'TEXT', 'REFRESHTEXT', 'DISPLAYPROGRESSMSG');
  2457. }
  2458. function translateIcon()
  2459. {
  2460. return JHTML::image('administrator/components/com_rsform/assets/images/translate.gif', JText::_('RSFP_THIS_ITEM_IS_TRANSLATABLE'), 'title="'.JText::_('RSFP_THIS_ITEM_IS_TRANSLATABLE').'" style="vertical-align: bottom"');
  2461. }
  2462. function mappingsColumns($config,$method,$row = null)
  2463. {
  2464. jimport('joomla.application.component.model');
  2465. JModel::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_rsform'.DS.'models');
  2466. $model = JModel::getInstance('mappings', 'RSFormModel');
  2467. $columns = $model->getColumns($config);
  2468. $table = isset($config['table']) ? $config['table'] : '';
  2469. if (!RSFormProHelper::isJ16())
  2470. $table = '`'.$table.'`';
  2471. $columns = isset($columns[$table]) ? $columns[$table] : array();
  2472. $data = @unserialize($row->data);
  2473. if ($data === false) $data = array();
  2474. $where = @unserialize($row->wheredata);
  2475. if ($where === false) $where = array();
  2476. $extra = @unserialize($row->extra);
  2477. if ($extra === false) $extra = array();
  2478. $andor = @unserialize($row->andor);
  2479. if ($andor === false) $andor = array();
  2480. $operators = array(
  2481. JHTML::_('select.option', '=', JText::_( 'RSFP_OPERATOR_EQUALS' ) ),
  2482. JHTML::_('select.option', '!=', JText::_( 'RSFP_OPERATOR_NOTEQUAL' ) ),
  2483. JHTML::_('select.option', '>', JText::_( 'RSFP_OPERATOR_GREATER_THAN' ) ),
  2484. JHTML::_('select.option', '<', JText::_( 'RSFP_OPERATOR_LESS_THAN' ) ),
  2485. JHTML::_('select.option', '>=', JText::_( 'RSFP_OPERATOR_EQUALS_GREATHER_THAN' ) ),
  2486. JHTML::_('select.option', '<=', JText::_( 'RSFP_OPERATOR_EQUALS_LESS_THAN' ) ),
  2487. JHTML::_('select.option', '%..%', JText::_( 'RSFP_OPERATOR_LIKE' ) ),
  2488. JHTML::_('select.option', '%..', JText::_( 'RSFP_OPERATOR_STARTS_WITH' ) ),
  2489. JHTML::_('select.option', '..%', JText::_( 'RSFP_OPERATOR_ENDS_WITH' ) ),
  2490. );
  2491. $html = '';
  2492. $html .= ($method == 'set') ? JText::_('RSFP_SET').'<hr />' : JText::_('RSFP_WHERE').'<hr />';
  2493. $html .= '<table class="admintable">';
  2494. if (!empty($columns))
  2495. {
  2496. $html .= '<tr>';
  2497. $html .= '<td>&nbsp;</td>';
  2498. if ($method == 'where')
  2499. {
  2500. $html .= '<td>&nbsp;</td>';
  2501. $html .= '<td>&nbsp;</td>';
  2502. }
  2503. $html .= '<td align="right"><button class="rs_button" type="submit">'.JText::_('SAVE').'</button></td>';
  2504. $html .= '</tr>';
  2505. }
  2506. if (!empty($columns))
  2507. foreach ($columns as $column => $type)
  2508. {
  2509. if ($method == 'set')
  2510. {
  2511. $value = isset($data[$column]) ? $data[$column] : '';
  2512. $name = 'f_'.$column;
  2513. } else
  2514. {
  2515. $value = isset($where[$column]) ? $where[$column] : '';
  2516. $name = 'w_'.$column;
  2517. $op = isset($extra[$column]) ? $extra[$column] : '=';
  2518. $op2 = isset($andor[$column]) ? $andor[$column] : 0;
  2519. }
  2520. $html .= '<tr>';
  2521. $html .= '<td width="80" nowrap="nowrap" align="right" class="key">'.$column.' ('.$type.')</td>';
  2522. if ($method == 'where')
  2523. $html .= '<td>'.JHTML::_('select.genericlist', $operators, 'o_'.$column, 'class="inputbox"', 'value', 'text',$op).'</td>';
  2524. if (strpos($type, 'text') !== false)
  2525. $html .= '<td><textarea class="rs_textarea" onclick="toggleDropdown(this,returnMappingsExtra());" onkeydown="closeAllDropdowns();" style="width:300px; height: 200px;" id="'.RSFormProHelper::htmlEscape($name).'" name="'.RSFormProHelper::htmlEscape($name).'">'.RSFormProHelper::htmlEscape($value).'</textarea></td>';
  2526. else
  2527. $html .= '<td><input type="text" class="rs_inp rs_80" onclick="toggleDropdown(this,returnMappingsExtra());" onkeydown="closeAllDropdowns();" size="35" value="'.RSFormProHelper::htmlEscape($value).'" id="'.RSFormProHelper::htmlEscape($name).'" name="'.RSFormProHelper::htmlEscape($name).'"></td>';
  2528. if ($method == 'where')
  2529. $html .= '<td>'.JHTML::_('select.booleanlist', 'c_'.$column, 'class="inputbox"', $op2,'RSFP_OR','RSFP_AND').'</td>';
  2530. $html .= '</tr>';
  2531. }
  2532. if (!empty($columns))
  2533. {
  2534. $html .= '<tr>';
  2535. $html .= '<td>&nbsp;</td>';
  2536. if ($method == 'where')
  2537. {
  2538. $html .= '<td>&nbsp;</td>';
  2539. $html .= '<td>&nbsp;</td>';
  2540. }
  2541. $html .= '<td align="right"><button class="rs_button" type="submit">'.JText::_('SAVE').'</button></td>';
  2542. $html .= '</tr>';
  2543. }
  2544. $html .= '</table>';
  2545. return $html;
  2546. }
  2547. function getMappingQuery($row)
  2548. {
  2549. $db =& JFactory::getDBO();
  2550. $query = '';
  2551. $database = '';
  2552. if (!empty($row->database))
  2553. {
  2554. if ($row->connection)
  2555. $database = $row->database.'.';
  2556. }
  2557. //get the fields
  2558. $data = @unserialize($row->data);
  2559. if ($data === false) $data = array();
  2560. //get the where fields
  2561. $wheredata = @unserialize($row->wheredata);
  2562. if ($wheredata === false) $wheredata = array();
  2563. //get the operators
  2564. $extra = @unserialize($row->extra);
  2565. if ($extra === false) $extra = array();
  2566. //get the and / or operators
  2567. $andor = @unserialize($row->andor);
  2568. if ($andor === false) $andor = array();
  2569. $set = array();
  2570. $where = '';
  2571. //make the WHERE cause
  2572. $i = 0;
  2573. if (!empty($wheredata))
  2574. foreach ($wheredata as $column => $field)
  2575. {
  2576. $andorop = isset($andor[$column]) ? $andor[$column] : 0;
  2577. $andorop = $andorop ? "OR" : "AND";
  2578. $operator = isset($extra[$column]) ? $extra[$column] : '=';
  2579. $where .= $i ? " ".$andorop." " : '';
  2580. if ($operator == '%..%')
  2581. $where .= " ".$db->nameQuote($column)." LIKE '%".$db->getEscaped($field)."%' ";
  2582. elseif ($operator == '%..')
  2583. $where .= " ".$db->nameQuote($column)." LIKE '%".$db->getEscaped($field)."' ";
  2584. elseif ($operator == '..%')
  2585. $where .= " ".$db->nameQuote($column)." LIKE '".$db->getEscaped($field)."%' ";
  2586. else
  2587. $where .= " ".$db->nameQuote($column)." ".$operator." '".$db->getEscaped($field)."' ";
  2588. $i++;
  2589. }
  2590. //the WHERE cause
  2591. $where = !empty($where) ? " WHERE ".$where : '';
  2592. if (!empty($data))
  2593. foreach ($data as $column => $field)
  2594. $set[] = $db->nameQuote($column)." = '".$db->getEscaped($field)."'";
  2595. if ($row->method == 0)
  2596. $query = "INSERT INTO ".$database.$db->nameQuote($row->table)." SET ".implode(' , ',$set);
  2597. if ($row->method == 1)
  2598. $query = "UPDATE ".$database.$db->nameQuote($row->table)." SET ".implode(' , ',$set).$where;
  2599. if ($row->method == 2)
  2600. $query = "DELETE FROM ".$database.$db->nameQuote($row->table).$where;
  2601. return $query;
  2602. }
  2603. function escapeSql(&$value)
  2604. {
  2605. $db = JFactory::getDBO();
  2606. $value = $db->getEscaped($value);
  2607. }
  2608. function sendMail($from, $fromname, $recipient, $subject, $body, $mode=0, $cc=null, $bcc=null, $attachment=null, $replyto=null, $replytoname=null)
  2609. {
  2610. // for 1.5 use the default sendMail() which works correctly
  2611. if (!RSFormProHelper::isJ16())
  2612. return JUtility::sendMail($from, $fromname, $recipient, $subject, $body, $mode, $cc, $bcc, $attachment, $replyto, $replytoname);
  2613. // until Joomla! solves all JUtility::sendMail() related issues, we're going to use our function here so that no extra reply-tos get added
  2614. // Get a JMail instance
  2615. $mail = JFactory::getMailer();
  2616. $config = &JFactory::getConfig();
  2617. $mailfrom = $config->get('mailfrom');
  2618. $mail->ClearReplyTos();
  2619. $mail->setSender(array($from, $fromname));
  2620. $mail->setSubject($subject);
  2621. $mail->setBody($body);
  2622. // Are we sending the email as HTML?
  2623. if ($mode)
  2624. $mail->IsHTML(true);
  2625. $mail->addRecipient($recipient);
  2626. $mail->addCC($cc);
  2627. $mail->addBCC($bcc);
  2628. $mail->addAttachment($attachment);
  2629. // Take care of reply email addresses
  2630. if (is_array($replyto)) {
  2631. $mail->ClearReplyTos();
  2632. $numReplyTo = count($replyto);
  2633. for ($i = 0; $i < $numReplyTo; $i++)
  2634. {
  2635. $mail->addReplyTo(array($replyto[$i], $replytoname[$i]));
  2636. }
  2637. }
  2638. else if (!empty($replyto)) {
  2639. $mail->ClearReplyTos();
  2640. $mail->addReplyTo(array($replyto, $replytoname));
  2641. }
  2642. return $mail->Send();
  2643. }
  2644. }