Sindbad~EG File Manager

Current Path : /var/www/ispania.gr/components/com_rsdirectory/controllers/
Upload File :
Current File : /var/www/ispania.gr/components/com_rsdirectory/controllers/contact.php

<?php
/**
 * @package	RSDirectory!
 * @copyright	(c) 2013 - 2021 RSJoomla!
 * @link		https://www.rsjoomla.com
 * @license	GNU General Public License http://www.gnu.org/licenses/gpl-3.0.en.html
 */

// No direct access.
defined('_JEXEC') or die('Restricted access');

/**
 * Contact controller.
 */
class RSDirectoryControllerContact extends JControllerForm
{
	/**
     * Method to save a record.
     *
     * @access public
     *
     * @param string $key The name of the primary key of the URL variable.
     * @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
     *
     * @return bool True if successful, false otherwise.
     */
    public function save($key = null, $urlVar = null)
    {
        // Check for request forgeries.
			
		// Get the mainframe.
        $app = JFactory::getApplication();
			
		 // Get the data.
        $data = $app->input->get( 'jform', array(), 'array' );
			
		// Get the Entry model.
        $model = $this->getModel();
            
        // Get the form.
        $form = $model->getForm();
            
        // Validate the posted data.
        $return = $model->validate($form, $data);
        
		// store the errors for the response
		$response_errors = new stdClass();
        // Check for validation errors.
        if ($return === false)
        {
            // Get the validation messages.
            $errors = $model->getErrors();
                
            // Push up to three validation messages out to the user.
            for ( $i = 0, $n = count($errors); $i < $n && $i < 3; $i++ )
            {
                if ($errors[$i] instanceof Exception)
                {
					$response_errors->warning[] = $errors[$i]->getMessage(); 
                }
                else
                {
					$response_errors->warning[] = $errors[$i];
                }
            }

        }
			
		// Attempt to save the configuration.
        $data = $return;
        $return = $model->save($data);
            
            
        // Check the return value.
        if ($return === false)
        {
			$response_errors->warning[] = JText::sprintf( 'COM_RSDIRECTORY_CONTACT_FAILED', $model->getError() );
        }
		
		$response = new stdClass();	
		$status = true;
		
		if (isset($response_errors->warning)) {
			$status = false;
			$response->errors = $response_errors;
		} else {
			$response->message = array(JText::_('COM_RSDIRECTORY_CONTACT_MESSAGE_SENT'));
		}
		
		$this->showResponse($status, $response);
	}
	
	public function showForm() {
		
		$model  = $this->getModel();
		$form   = $model->getForm();

		// remove "input-xxlarge" class for J4
		if (RSDirectoryHelper::isJ4())
		{
			$form->setFieldAttribute('message', 'class', '');
		}
		
		$user = JFactory::getUser();

		if ($user->id)
		{
			$form->removeField('name');
			$form->removeField('email');
		}

		$html  = $form->renderFieldset('general');
		
		$html .= $this->getCaptcha();

		if (RSDirectoryConfig::getInstance()->get('use_consent_checkbox_on_contact_author_form', 0)) {
			$html .= '<div class="control-group">';
				$html .= '<label class="checkbox form-check-label" for="submit_contact_consent">';
					$html .= '<input type="checkbox" id="submit_contact_consent" class="form-check-input" value="1" name="i_consent_to_privacy_policy_and_submit_my_details"/> ';
					$html .= JText::_('COM_RSDIRECTORY_CONSENT_DEFAULT_SUBMIT');
				$html .= '</label>';
			$html .= '</div>';
		}
		
		
		$response = new stdClass();
		$response->form = $html;
	
		$this->showResponse(true, $response);
	
	}
	
	protected function getCaptcha() {
		return RSDirectoryHelper::buildCaptcha('contact');
	}
	
	protected function showResponse($success, $data=null) {
		$app 		= JFactory::getApplication();
		$document 	= JFactory::getDocument();
		
		// set JSON encoding
		$document->setMimeEncoding('application/json');
		
		// compute the response
		$response = new stdClass();
		$response->success = $success;
		if ($data) {
			$response->data = $data;
		}
		
		// show the response
		echo json_encode($response);
		
		// close
		$app->close();
	}
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists