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