PageRenderTime 60ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_rsform/controller.php

https://bitbucket.org/organicdevelopment/joomla-2.5
PHP | 193 lines | 137 code | 41 blank | 15 comment | 26 complexity | 01142e4a528c48a49c5fb5328e1c884a 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. jimport('joomla.application.component.controller');
  10. class RSFormController extends JController
  11. {
  12. var $_db;
  13. function __construct()
  14. {
  15. parent::__construct();
  16. $this->_db = JFactory::getDBO();
  17. /*
  18. $view = JRequest::getVar('view', 'rsform');
  19. if ($view == 'rsform')
  20. $this->registerDefaultTask('showForm');
  21. */
  22. $doc =& JFactory::getDocument();
  23. $doc->addScript(JURI::root(true).'/components/com_rsform/assets/js/script.js');
  24. }
  25. function captcha()
  26. {
  27. require_once(JPATH_SITE.DS.'components'.DS.'com_rsform'.DS.'helpers'.DS.'captcha.php');
  28. $componentId = JRequest::getInt('componentId');
  29. $captcha = new RSFormProCaptcha($componentId);
  30. $session = JFactory::getSession();
  31. $session->set('com_rsform.captcha.'.$componentId, $captcha->getCaptcha());
  32. exit();
  33. }
  34. function plugin()
  35. {
  36. $mainframe =& JFactory::getApplication();
  37. $mainframe->triggerEvent('rsfp_f_onSwitchTasks');
  38. }
  39. /* deprecated */
  40. function showForm()
  41. {
  42. }
  43. function submissionsViewFile()
  44. {
  45. $lang = JFactory::getLanguage();
  46. $lang->load('com_rsform', JPATH_ADMINISTRATOR);
  47. $hash = JRequest::getCmd('hash');
  48. if (strlen($hash) != 32)
  49. return $this->setRedirect('index.php');
  50. $config = JFactory::getConfig();
  51. $secret = $config->getValue('config.secret');
  52. $this->_db->setQuery("SELECT * FROM #__rsform_submission_values WHERE MD5(CONCAT(SubmissionId,'".$this->_db->getEscaped($secret)."',FieldName)) = '".$hash."'");
  53. $result = $this->_db->loadObject();
  54. // Not found
  55. if (empty($result))
  56. return $this->setRedirect('index.php');
  57. // Not an upload field
  58. $this->_db->setQuery("SELECT c.ComponentTypeId FROM #__rsform_properties p LEFT JOIN #__rsform_components c ON (p.ComponentId=c.ComponentId) WHERE p.PropertyName='NAME' AND p.PropertyValue='".$this->_db->getEscaped($result->FieldName)."'");
  59. $type = $this->_db->loadResult();
  60. if ($type != 9)
  61. return $this->setRedirect('index.php', JText::_('RSFP_VIEW_FILE_NOT_UPLOAD'));
  62. jimport('joomla.filesystem.file');
  63. if (JFile::exists($result->FieldValue))
  64. RSFormProHelper::readFile($result->FieldValue);
  65. $this->setRedirect('index.php', JText::_('RSFP_VIEW_FILE_NOT_FOUND'));
  66. }
  67. function ajaxValidate()
  68. {
  69. $form = JRequest::getVar('form');
  70. $formId = (int) @$form['formId'];
  71. $this->_db->setQuery("SELECT ComponentId, ComponentTypeId FROM #__rsform_components WHERE `FormId`='".$formId."' AND `Published`='1' ORDER BY `Order`");
  72. $components = $this->_db->loadObjectList();
  73. $page = JRequest::getInt('page');
  74. if ($page)
  75. {
  76. $current_page = 1;
  77. foreach ($components as $i => $component)
  78. {
  79. if ($current_page != $page)
  80. unset($components[$i]);
  81. if ($component->ComponentTypeId == 41)
  82. $current_page++;
  83. }
  84. }
  85. $removeUploads = array();
  86. $removeRecaptcha = array();
  87. $formComponents = array();
  88. foreach ($components as $component)
  89. {
  90. $formComponents[] = $component->ComponentId;
  91. if ($component->ComponentTypeId == 9)
  92. $removeUploads[] = $component->ComponentId;
  93. if ($component->ComponentTypeId == 24)
  94. $removeRecaptcha[] = $component->ComponentId;
  95. }
  96. echo implode(',', $formComponents);
  97. echo "\n";
  98. $invalid = RSFormProHelper::validateForm($formId);
  99. //Trigger Event - onBeforeFormValidation
  100. $mainframe = JFactory::getApplication();
  101. $mainframe->triggerEvent('rsfp_f_onBeforeFormValidation', array(array('invalid'=>&$invalid)));
  102. if (count($invalid))
  103. {
  104. foreach ($invalid as $i => $componentId)
  105. if (in_array($componentId, $removeUploads) || in_array($componentId, $removeRecaptcha))
  106. unset($invalid[$i]);
  107. $invalidComponents = array_intersect($formComponents, $invalid);
  108. echo implode(',', $invalidComponents);
  109. }
  110. if (isset($invalidComponents))
  111. {
  112. echo "\n";
  113. $pages = RSFormProHelper::componentExists($formId, 41);
  114. $pages = count($pages);
  115. if ($pages && !$page)
  116. {
  117. $first = reset($invalidComponents);
  118. $current_page = 1;
  119. foreach ($components as $i => $component)
  120. {
  121. if ($component->ComponentId == $first)
  122. break;
  123. if ($component->ComponentTypeId == 41)
  124. $current_page++;
  125. }
  126. echo $current_page;
  127. echo "\n";
  128. echo $pages;
  129. }
  130. }
  131. jexit();
  132. }
  133. function confirm()
  134. {
  135. $db =& JFactory::getDBO();
  136. $hash = JRequest::getVar('hash');
  137. $db->setQuery("SELECT `SubmissionId` FROM `#__rsform_submissions` WHERE MD5(CONCAT(`SubmissionId`,`FormId`,`DateSubmitted`)) = '".$db->getEscaped($hash)."' ");
  138. $SubmissionId = $db->loadResult();
  139. if ($SubmissionId)
  140. {
  141. $db->setQuery("UPDATE `#__rsform_submissions` SET `confirmed` = 1 WHERE `SubmissionId` = '".$SubmissionId."' ");
  142. $db->query();
  143. JError::raiseNotice('200',JText::_('RSFP_SUBMISSION_CONFIRMED'));
  144. }
  145. else
  146. {
  147. JError::raiseWarning('500',JText::_('RSFP_SUBMISSION_CONFIRMED_ERROR'));
  148. return;
  149. }
  150. }
  151. }
  152. ?>