/** * Trata o envio dos dados via ajax * * @access public */ public static function getAjax() { jimport('joomla.application.module.helper'); // Chama a biblioteca que trata campos de formulário $input = JFactory::getApplication()->input; // Chama biblioteca que trata os dados vindo das configurações no backend $module = JModuleHelper::getModule('wgroofcalculate'); $params = new JRegistry(); $params->loadString($module->params); $percent = $params->get('increase'); // pega os campos digitados pelo usuário no formulário de contato $inputs = $input->get('data', array(), 'ARRAY'); // atribui os campos nas variáveis foreach ($inputs as $input) { if ($input['name'] == 'areasize') { $areasize = $input['value']; } if ($input['name'] == 'correctfactor') { $correctfactor = $input['value']; } if ($input['name'] == 'rooftype') { $rooftype = $input['value']; } } //valida dados if (empty($areasize) || empty($correctfactor) || empty($rooftype)) { $data = ['response' => 0, 'msn' => JText::_('MOD_WGROOFCALCULATE_MSN_ERRO1')]; return json_encode($data); } else { if (!is_numeric($areasize)) { $data = ['response' => 1, 'msn' => JText::_('MOD_WGROOFCALCULATE_MSN_ERRO2')]; return json_encode($data); } else { $valuesToCaculate = modWGRoofCalculateHelper::dismemberValue($rooftype); $roofCalculate = $areasize * $correctfactor * $valuesToCaculate[1]; $roofCalculateTotal = round($roofCalculate + $roofCalculate * $percent / 100); $roofCalculateResult = ['totalRoof' => $roofCalculateTotal, 'totalWeight' => $roofCalculateTotal * $valuesToCaculate[0]]; $data = ['response' => 2, 'msn' => JText::sprintf('MOD_WGROOFCALCULATE_MSN_RESPONSE', $roofCalculateResult['totalRoof'], $roofCalculateResult['totalWeight'])]; return json_encode($data); } } }
<?php /** * @package Leowgweb.Module * @subpackage mod_wgroofcalculate * @copyright Copyright (C) 2016 Leowgweb.com, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // no direct access defined('_JEXEC') or die; // Include the syndicate functions only once require_once dirname(__FILE__) . '/helper.php'; $typesofroofs = modWGRoofCalculateHelper::getTypeRoof($params); $moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx')); $formsize = $params->get('formsize'); $formalign = $params->get('formalign'); $fieldalign = $params->get('fieldalign'); $fieldposition = $params->get('fieldposition'); // declarando dependências $pathimage = modWGRoofCalculateHelper::pullDependecies(); require JModuleHelper::getLayoutPath('mod_wgroofcalculate', $params->get('layout', 'default'));