Current Path :
/
home
/
develito
/
httpdocs
/
components
/
com_raforms
/
controllers
/
Or
Select Your Path :
Upload File :
New :
File
Dir
/home/develito/httpdocs/components/com_raforms/controllers/fform.php
<?php /* ------------------------------------------------------------------------ # com_raforms - rootArea Forms # ------------------------------------------------------------------------ # author Markus Döhla # copyright Copyright (C) 2012 rootarea.de. All Rights Reserved. # @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL # license - Additional EULA on www.rootarea.de DOES NOT apply to ANY lite packages # Websites: http://www.rootarea.de # Technical Support: Forum - http://www.rootarea.de/en/forum ------------------------------------------------------------------------- */ //-- No direct access defined('_JEXEC') or die('=;)'); jimport('joomla.application.component.controller'); jimport('joomla.filesystem.file'); class RAformsControllerFForm extends JControllerLegacy { public function __construct() { parent::__construct(); $this->registerTask('add', 'display'); $this->registerTask('repeat', 'display'); $this->registerTask('duplicate', 'display'); } function display($cachable = false, $urlparams = array()) { $app = JFactory::getApplication(); $formdata = JRequest::get('post'); $Itemid = JRequest::getVar('Itemid'); $format = JRequest::getVar('format'); $currentPage = JRequest::getVar('raformsPage', null, null, 'int'); $gotoPage = JRequest::getVar('gotoPage', 1, null, 'int'); $menu = $app->getMenu(); $params = $menu->getParams($Itemid); // try to get the form id if called from category view $formid = $params->get('formid'); $formid = (empty($formid)) ? JRequest::getVar('formid') : $formid; $data = $app->getUserState( 'com_raforms.formrequest_form_' . $formid, array()); $ids = $this->checkRoute(); if ((!in_array($Itemid, $ids) && empty($ffparams)) && $format != 'raw') { $link = JRoute::_('index.php?Itemid='.$ids[0], false); $msg = JText::_('RAFORMS_RESTRICTED'); //$msg .= '<br>'; //$msg .= 'Itemid: ' . $Itemid . ' ;; ids: ' . print_r($ids); $error = 'error'; $this->setRedirect($link, $msg, $error); $this->redirect(); } else { switch($this->getTask()) { case 'save' : $this->save(); break; case 'add' : $app->setUserState('com_raforms.formrequest_form_'. $formid, null); $app->setUserState('com_raforms', null); case 'repeat' : case 'duplicate' : case 'gotoPage' : if ($currentPage != null) { $data[$currentPage] = $formdata; // store form data in session $app->setUserState( 'com_raforms.formrequest_form_' . $formid, $data); } else { $currentPage = 1; } case 'edit' : JModelLegacy::addIncludePath( JPATH_COMPONENT_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'models' ); $view = $this->getView('FForm', 'html'); //$view->edit = ($this->getTask() == 'add' || $this->getTask() == 'gotoPage') ? false : true; $submissionId = JRequest::getVar('id', null); $view->edit = (empty($submissionId)) ? false : true; $model1 = $this->getModel('FormResult'); $view->setModel($model1, true); $model2 = $this->getModel('FForm'); $view->setModel($model2); $model3 = $this->getModel('RAform'); $view->setModel($model3); if (JFile::exists(JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_raforms' . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'comments.php')) { $model4 = $this->getModel('Comments'); $view->setModel($model4); } JRequest::setVar( 'raformsPage', $currentPage); $view->display(); break; default: JRequest::setVar( 'view', 'fform'); parent::display(); break; } } } protected function checkRoute() { $db = JFactory::getDBO(); $user = JFactory::getUser(); $ids = array(); $sql = $db->getQuery(true); $sql->select('a.id'); $sql->from('#__menu a'); $sql->join('left', '#__extensions b on a.component_id = b.extension_id'); $sql->where('b.element = ' . $db->quote('com_raforms')); $sql->where('b.type = ' . $db->quote('component')); $sql->where('a.menutype != ' . $db->quote('main')); $sql->where('a.access IN (' . implode(',', $user->getAuthorisedViewLevels()) . ')'); $db->setQuery($sql); $ids = $db->loadColumn(); return $ids; } /** * Save a record (and redirect). * * @return void */ function save() { // Get POST $currentFormdata= JRequest::get('post'); $currentPage = JRequest::getVar('raformsPage', 1, null, 'int'); $keepvalues = JRequest::getVar('keepvalues', 0); $this->_formid = $currentFormdata['formid']; // Get Application $app = JFactory::getApplication(); // Get User $user = JFactory::getUser(); $formdata = $app->getUserState( 'com_raforms.formrequest_form_' . $this->_formid, array()); $formdata[$currentPage] = $currentFormdata; // If saving fails, store form data in session $app->setUserState( 'com_raforms.formrequest_form_'. $this->_formid, $formdata); // Get Model $model = $this->getModel('fform'); // Model data $data = $model->getFormData(); // Check if unique is active and block user if an entry already exists if (array_key_exists('unique', $data->config) && $data->config['unique'] == "true" && $model->checkUnique()) { if ($data->config['redirecterror'] == "") { $link = JRoute::_('index.php?option=com_raforms', false); } else { $link = JRoute::_($data->config['redirecterror'], false); } $msg = JText::_('RAFORMS_APPSAVE_UNIQUE_ERROR'); $error = "error"; } else { $preparedData = array(); // Validate form entries // And prepare data for storage foreach ($formdata as $page => $entries) { foreach ($entries['data'] as $k => $v) { $teststr = null; if (is_array($v)) { $teststr = implode('', $v); } else { $teststr = preg_replace("/\s+/", "", $v); } if (array_key_exists($k, $data->data)) { if (array_key_exists('validation', $data->data[$k]) && strlen($teststr) == 0) { $field = (!empty($data->data[$k]['label'])) ? $data->data[$k]['label'] : $k; $link = JRoute::_(JRequest::getURI(), false); $msg = JText::sprintf('RAFORMS_APPSAVE_ERROR', $field); $error = "error"; $this->setRedirect($link, $msg, $error); return false; } } } // Process Plugins $pluginModels = array(); if (isset($entries['plugins']) && is_array($entries['plugins'])) { foreach ($entries['plugins'] as $plugin => $pluginField) { if (is_file(JPATH_SITE . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'extension' . DIRECTORY_SEPARATOR . 'raforms_' . $plugin . DIRECTORY_SEPARATOR . 'site' . DIRECTORY_SEPARATOR . $plugin . 'Model.php') && JPluginHelper::isEnabled('extension', 'raforms_' . $plugin)) { // load plugin model and let it do its work JLoader::import('joomla.application.component.model'); JLoader::import( $plugin . 'Model', JPATH_SITE . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'extension' . DIRECTORY_SEPARATOR . 'raforms_' . $plugin . DIRECTORY_SEPARATOR . 'site'); if (isset($pModel)) { unset($pModel); } if (!isset($pluginModels[$plugin])) { $pModel = JModelLegacy::getInstance( $plugin, 'RAformsModelPlugin' ); $pluginModels[$plugin] = $pModel; } } } } // Process plugins preStore foreach ($pluginModels as $plugin => $pluginModel) { foreach ($entries['plugins'][$plugin] as $fieldName => $fieldData) { // field description data $descData = $data->data[$fieldName]; $newFieldData = $pluginModel->preStore($fieldName, $fieldData, $descData, $entries); // inject field data from plugin if applicable if (!empty($newFieldData) && $newFieldData !== false) { $entries['data'][$fieldName] = $newFieldData; } if ($newFieldData === false) { $link = JRoute::_(preg_replace('/(.*)task=([^&$]*)(.*)/', '$1task=fform.repeat$3', JRequest::getURI()), false); $msg = $pluginModel->getError(); $error = "error"; $this->setRedirect($link, $msg, $error); return false; } } } $preparedData = array_merge_recursive($preparedData, $entries); } //print "<pre>"; //print_r($formdata); //print_r($preparedData); //print "</pre>"; if($model->store($preparedData, $keepvalues)) { $msg = JText::_('RAFORMS_APPSAVE_SUCCS'); $error = ""; } else { $msg = JText::_('RAFORMS_APPSAVE_ERROR'.$model->getError()); $error = "error"; } // Process plugins postStore foreach ($pluginModels as $plugin => $pluginModel) { // call postStore hook: fieldname + formdata + entry id foreach ($preparedData['plugins'][$plugin] as $fieldName => $fieldData) { // field description data $descData = $data->data[$fieldName]; $postStore = $pluginModel->postStore($fieldName, $fieldData, $descData, $model->getId()); if ($postStore !== true) { $msg = JText::_('RAFORMS_APPSAVE_ERROR') . ': ' . $postStore; $error = "error"; } } } if (isset($data->config['mail-admin-sender-data']) && $data->config['mail-admin-sender-data'] == 1) { $model->sendAdminMail(); } if (array_key_exists('redirect', $formdata) && !empty($formdata['redirect'])) { switch ($formdata['redirect']) { case 'fform': $returnToCurrentForm = (array_key_exists('returntocurrentform', $formdata) && $formdata['returntocurrentform'] == 1); if ($returnToCurrentForm) { $task = '&task=fform.edit&id=' . $model->getId(); } else if (!$returnToCurrentForm && $keepvalues) { $task = '&task=fform.duplicate'; } else { $task = '&task=fform.add'; } $link = JRoute::_('index.php?option=com_raforms' . $task, false); break; case 'return': $link = JRoute::_('index.php', false); break; case 'formresultlist': $link = JRoute::_('index.php?option=com_raforms&task=formresultlist.display', false); break; case 'url': $link = (!empty($formdata['redirecturl'])) ? JRoute::_(rawurldecode($formdata['redirecturl'])) : JRoute::_('index.php', false); break; } } else { $link = JRoute::_('index.php?option=com_raforms&task=formresultlist.display', false); } } $this->setRedirect($link, $msg, $error); } function cancel() { $msg = JText::_('RAFORMS_CANCELLED'); $link = JRoute::_('index.php?option=com_raforms&task=formresultlist.display', false); $this->setRedirect($link, $msg, 'info'); } function delete() { $formid = JRequest::getVar( 'formid', 0 ); $id = JRequest::getVar( 'id', 0 ); $user = JFactory::getUser(); $raforms = $this->getModel('fform'); $formResult = $this->getModel('formresult'); $entryUser = $formResult->getDataVar('user'); $canDo = RAformsHelper::getActions($formid, 'raform'); if ($canDo->get('core.delete') || ($canDo->get('core.edit.own') && $user->id == $entryUser)) { if ($raforms->delete()) { $msg = JText::_('RAFORMS_DELETE_SUCCS'); $typ = 'info'; } else { $msg = JText::_('RAFORMS_DELETE_ERROR'); $typ = 'error'; } } else { $msg = JText::_('RAFORMS_DELETE_NOPERM'); $typ = 'error'; } //$link = JRoute::_('index.php?option=com_raforms&task=formresultlist.display', false); $link = JRoute::_('index.php', false); $this->setRedirect($link, $msg, $typ); } /* function import() { // Get Application $app =& JFactory::getApplication(); $formid = JRequest::getVar( 'formid', 0 ); // Get Model $model = $this->getModel('fform'); if($model->storeimport()) { $app->setUserState( 'formrequest', null); $msg = JText::_('Datensätze wurden erfolgreich importiert.'); $error = ""; } else { $msg = JText::_('Datensätze konnten nicht gespeichert werden '.$model->getError()); $error = "error"; } $this->setRedirect('index.php?option=com_raforms&formid='.$formid, $msg . ' <br/> ' . $this->getError()); } */ }