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/claim.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 RSDirectoryControllerClaim 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];
                }
            }

        }
        else {
            // 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_CLAIM_LISTING_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_CLAIM_LISTING_CLAIMED_SUCCESSFUL'));

            // in case there is an error with the email, show it
            if (RSDirectoryConfig::getInstance()->get('claim_email_error', 0))
            {
                $current_errors = $model->getError();
                if (!empty($current_errors))
                {
                    $response->email_message = array($current_errors);
                }
            }
        }

        $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', '');
        }

        $html = '';

        // Get the mainframe.
        $app = JFactory::getApplication();

        // Get the data.
        $skip_claim = false;
        if ($entry_id = $app->input->getInt( 'entry_id', 0))
        {
            $entry_details = RSDirectoryHelper::getEntry($entry_id);
            
            if ($entry_details && $entry_details->claim_listing_credits)
            {
                $html .= '<div class="alert alert-info">'.JText::sprintf('COM_RSDIRECTORY_ENTRY_CLAIM_CREDIT_COST', $entry_details->claim_listing_credits).'</div>';

                // check user credits
                $user_credits = RSDirectoryCredits::getUserCredits();
                if ($user_credits < $entry_details->claim_listing_credits)
                {
                    $user = JFactory::getUser();
                    if (empty($user->id))
                    {
                        $html .= '<div class="alert alert-'.(RSDirectoryHelper::isJ4() ? 'danger' : 'error').'">'.JText::_('COM_RSDIRECTORY_USER_MUST_BE_LOGGED_IN').'</div>';
                    }
                    else
                    {
                        $html .= '<div class="alert alert-'.(RSDirectoryHelper::isJ4() ? 'danger' : 'error').'">'.JText::sprintf('COM_RSDIRECTORY_ENTRY_CLAIM_CREDIT_INSUFFICIENT_CREDITS',$user_credits, RSDirectoryRoute::getURL('credits', 'default', array('entry_id'=>$entry_id,'claim'=>'1'))).'</div>';
                    }

                    $skip_claim = true;
                }
            }
        }

        if (!$skip_claim)
        {
            $html .= $form->renderFieldset('general');

            $html .= $this->getCaptcha();

            if (RSDirectoryConfig::getInstance()->get('use_consent_checkbox_on_claim_form', 0)) {
                $html .= '<div class="control-group">';
                $html .= '<label class="checkbox" for="submit_claim_consent">';
                $html .= '<input type="checkbox" id="submit_claim_consent" 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('claim');
    }

    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