Current Path :
/
home
/
develito
/
www
/
components
/
com_raforms
/
views
/
fform
/
Or
Select Your Path :
Upload File :
New :
File
Dir
//home/develito/www/components/com_raforms/views/fform/view.html.php
<?php //-- No direct access defined('_JEXEC') or die('=;)'); jimport('joomla.application.component.view'); class RAformsViewFForm extends JViewLegacy { function display($tpl = null) { $app = JFactory::getApplication(); $document = JFactory::getDocument(); $categories = JCategories::getInstance('raforms'); $this->user = JFactory::getUser(); $this->params = $app->getParams(); $this->showDeleteButton = false; $this->edit = (isset($this->edit)) ? $this->edit : false; $this->allowedit = true; $this->comments = false; $this->commentPosition = 1; $form = $this->getModel('raform'); $formData = $form->getData(); $category = $categories->get($formData->catid); // check for permission to edit form data $this->id = JRequest::getVar('id', null, null, 'int'); $this->formid = $form->id; $submitformname = 'raforms-form-' . $this->formid; // check if access is not public $groups = $this->user->getAuthorisedViewLevels(); $return = ''; if ((!in_array($formData->access, $groups)) || (!in_array($category->access, $groups))) { $uri = JFactory::getURI(); $return = (string)$uri; JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR')); return; } if ($this->edit === true) { $this->params->set('formid', $this->formid); // getData of dataset for frontend form // if not already there $requestData = $app->getUserState( 'com_raforms.formrequest_form_'. $this->formid, null); if ( $requestData == null || $requestData['data']['id'] != $this->id) { $formresult = $this->getModel('FormResult'); $data = $formresult->getData($formData); // Set form data if it's an already saved record if (!empty($formresult->id) && count($data) > 0) { $app->setUserState( 'com_raforms.formrequest_form_'. $this->formid, $data); } } if (!empty($this->id)) { $canDo = RAformsHelper::getActions($this->formid, 'raform'); $this->allowedit = ($canDo->get('core.edit') || ($canDo->get('core.edit.own') && $data['user'] == $this->user->id)) ? true : false; $this->showDeleteButton = ($canDo->get('core.delete') || ($canDo->get('core.edit.own') && $data['user'] == $this->user->id)) ? true : false; /* // Comments */ if (array_key_exists('comments', $formData->config) && $formData->config['comments']) { $this->commentsCanDo = RAformsHelper::getActions($this->formid, 'comment'); $comments = $this->getModel('comments'); $comments->setId($this->formid); $comments->setEntryId($this->id); $this->comments = (isset($formData->config['comment-access']) && (in_array($formData->config['comment-access'], $this->user->getAuthorisedViewLevels()))) ? true : false; $this->commentItems = $comments->getItems(); $this->commentCSS = (isset($formData->config['comment-css'])) ? $formData->config['comment-css'] : ''; $this->commentDisplay = $formData->config['comment-display']; $this->commentsSlide = (empty($formData->config['comment-slide'])) ? 'vertical' : $formData->config['comment-slide']; $this->commentPosition = $formData->config['comment-position']; } } } // To prevent loading plugin javascript before mootools, // we load the framework into the document here JHTML::_('behavior.framework', true); // add standard javascript $this->addStandardJS($submitformname); // add CSS if applicable if (!empty($formData->config['form-css'])) { $document->addStyleDeclaration($formData->config['form-css']); } // get frontend form elements $raforms = $this->getModel('fform'); $this->page = JRequest::getVar('gotoPage', 1, null, 'int'); $this->form = $raforms->getFormattedForm($this->page); $this->pages = $raforms->getPages(); // add extended javascript $this->addExtendedJS($submitformname); /* print "<pre>"; print_r($data); print "</pre>"; die; */ // quick and dirty fix for beez3 template failure if there is no ul.menu in header div -.- $siteTemplate = $app->getTemplate(true); if ($siteTemplate->template == 'beez3') { $document->addScript( JUri::root().'components/com_raforms/js/beez3_fix.js' ); } // Set formname as pagetitle $document->setTitle( $this->form->formname ); parent::display($tpl); } function addStandardJS ($submitformname) { $document = JFactory::getDocument(); $javascript = <<<EOT window.addEvent('domready', function() {\n document.getElements('input').each(function(el) { if ( el.getParent('div.formField') && ['checkbox', 'radio', 'text'].contains(el.get('type'))) { el.getParent('div.formField').store('background', el.getParent('div.formField').getStyle('background-color')); } }); document.getElements('select').each(function(el) { if ( el.getParent('div.formField') ) { el.getParent('div.formField').store('background', el.getParent('div.formField').getStyle('background-color')); } }); document.getElements('textarea').each(function(el) { if ( el.getParent('div.formField') ) { el.getParent('div.formField').store('background', el.getParent('div.formField').getStyle('background-color')); } }); window.raformsValidate = new Form.Validator.Inline(document.id('$submitformname'), { evaluateOnSubmit: false, evaluateFieldsOnChange: false, evaluateFieldsOnBlur: false, errorPrefix: '' });\n raformsValidate.addAllThese([ ['validate-one-required', { errorMsg: Joomla.JText._('RAFORMS_VALIDATION_ONE_REQUIRED'), test: function(element, props){ var p = element.getParent('div.formField'); var retval = false; return p.getElements('input').some(function(el) { if (['checkbox', 'radio'].contains(el.get('type'))) { if (el.get('checked')) { element.getParent('div.formField').setStyle('background-color', element.getParent('div.formField').retrieve('background')); retval = true; } else { element.getParent('div.formField').setStyle('background-color', '#FF0000'); } } else { if (el.get('value')) { element.getParent('div.formField').setStyle('background-color', element.getParent('div.formField').retrieve('background')); retval = true; } else { element.getParent('div.formField').setStyle('background-color', '#FF0000'); } } return retval; }); } }], ['required', { errorMsg: Joomla.JText._('RAFORMS_VALIDATION_REQUIRED'), test: function(element) { var val = element.get('value'); // replace spaces val = val.split(' ').join(''); if (val == null || val.length == 0) { element.getParent('div.formField').setStyle('background-color', '#FF0000'); return false; } else { element.getParent('div.formField').setStyle('background-color', element.getParent('div.formField').retrieve('background')); } return true; } }], ['validate-email', { errorMsg: Joomla.JText._('RAFORMS_VALIDATION_EMAIL_NOT_VALID'), test: function(element) { if (!(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i).test(element.get('value'))) { element.getParent('div.formField').setStyle('background-color', '#FF0000'); return false; } else { element.getParent('div.formField').setStyle('background-color', element.getParent('div.formField').retrieve('background')); } return true; } }] ]); });\n EOT; $document->addScriptDeclaration($javascript); } function addExtendedJS($submitformname) { $document = JFactory::getDocument(); $javascript = <<<EOT window.addEvent('domready', function() {\n EOT; // Specials for Submit /* if (property_exists($this->form, 'submitjs') && is_array($this->form->submitjs)) { foreach ($this->form->submitjs as $js) { if (!empty($js)) { $javascript .= $js; } } } // domready js if (property_exists($this->form, 'effects_domready') && is_array($this->form->effects_domready)) { foreach ($this->form->effects_domready as $js) { if (!empty($js)) { $javascript .= $js; } } } */ if (!$this->allowedit) { $javascript .= <<<EOT $$('#$submitformname input').each ( function (el) { var typ = el.get('type'); if (typ == 'text') { var val = el.get('value'); new Element ('div', {'text': val}).replaces(el); } if (typ == 'checkbox' || typ == 'radio') { el.disabled = true; } }); var selOpt = []; $$('#$submitformname select').each ( function (el) { var texts = el.getSelected().get('text'); new Element ('div', {'html': texts.join('<br/>')}).replaces(el); }); $$('#$submitformname textarea').each ( function (el) { // exclude comment textarea if (el.get('id') != 'comment') { var val = el.get('text'); var style = el.get('style'); style = (!style.match(/;$/)) ? style + ';' : style; new Element ('div', {'text': val, 'style': style + ' overflow: auto;'}).replaces(el); } }); $$('.formLabel').setStyle('font-weight', 'bold'); EOT; } /* if (property_exists($this->form, 'effects') && is_array($this->form->effects)) { foreach ($this->form->effects as $js) { if (!empty($js)) { $javascript .= $js; } } } */ $javascript .= <<<EOT });\n EOT; $document->addScriptDeclaration($javascript); } } ?>