HEX
Server: LiteSpeed
System: Linux s917.lon1.mysecurecloudhost.com 4.18.0-477.21.1.lve.1.el8.x86_64 #1 SMP Tue Sep 5 23:08:35 UTC 2023 x86_64
User: assibfaf (3034)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/assibfaf/public_html/prox-controllers/Api/Config.php
<?php 
/**
 * @package    Proxim
 * @author     Davison Pro <davisonpro.coder@gmail.com | https://davisonpro.dev>
 * @copyright  2019 Proxim
 * @version    1.0.0
 * @since      File available since Release 1.0.0
 */

namespace Proxim\Api;

use Db;
use Proxim\Route;
use Proxim\Tools;
use Proxim\Configuration;
use Proxim\Currency;
use Proxim\Database\DbQuery;
use Proxim\Module\Module;
use Proxim\Module\PaymentModule;
use Proxim\Util\ArrayUtils;
use Proxim\Presenter\Deadline\DeadlinePresenter;
use Proxim\Preference\UploadType;
use Proxim\Preference\PaperType;
use Proxim\Preference\Deadline;
use Proxim\Preference\Discipline;
use Proxim\Preference\PaperFormat;
use Proxim\Validate;

class Config extends Route {

    public function getConfig() {
        global $globals;
        $app = $this->app;
		$user = $app->container->user;
        $site = $app->container->site;
        
		$currencies = Currency::getCurrencies( true );
		
        $availableCurrencies = array();
		foreach ($currencies as $currency) {
			$availableCurrencies[] = array(
				"title" => ArrayUtils::get($currency, 'title'),
				"currencyId" => (int) ArrayUtils::get($currency, 'currency_id'),
				"symbols" => ArrayUtils::get($currency, 'symbol'),
				"exchangeRateData" => array(
					"currency" => ArrayUtils::get($currency, 'iso_code'),
					"rate" => (float) ArrayUtils::get($currency, 'conversion_rate'),
					"isInverted" => false
				)
			);
		}

        $paperTypes = $paperFormats = $academicLevels = $writerPreferences = $departments = array();

        $revisionDeadlines = array();
		foreach ( $globals['revisionDeadlines'] as $deadlineId => $deadline ) {
			$deadline['id'] = (int) $deadlineId;
			$revisionDeadlines[] = $deadline;
		}

		$paidRevisionDeadlines = array();
		foreach ( $globals['paidRevisionDeadlines'] as $serviceTypeId => $serviceTypeDeadlines ) {
			$serviceDeadlines = array();
			foreach( $serviceTypeDeadlines as $paidDeadlineId => $paidDeadlines ) {
				$deadlines = array();
				foreach( $paidDeadlines as $deadlineId => $deadline ) {
					$deadline['did'] = (int) $deadlineId;
					$deadlines[] = $deadline;
				}
				$serviceDeadlines[$paidDeadlineId] = $deadlines;
			}

			$paidRevisionDeadlines[$serviceTypeId] = $serviceDeadlines;
		}

		foreach ( $globals['departments'] as $departmentId => $department ) {
			$department['id'] = (int) $departmentId;
			$departments[] = $department;
		}

		$sitePaperFormats = PaperFormat::getPaperFormats();

		foreach ( $sitePaperFormats as $paperFormat ) {
			$paperFormats[] = array(
				'id' => (int) $paperFormat['paper_format_id'],
				'title' => $paperFormat['title']
			);
		}

		$sitePaperTypes = PaperType::getPaperTypes();

		$paperTypes = array();
		foreach ( $sitePaperTypes as $paperType ) {
			$paperTypes[] = array(
				'id' => (int) $paperType['paper_type_id'],
				'title' => $paperType['title']
			);
		}

		foreach ( $globals['academicLevels'] as $academicLevelId => $academicLevel ) {
			$academicLevel['id'] = $academicLevelId;
			$academicLevels[] = $academicLevel;
		}	

		foreach ( $globals['writerPreferences'] as $writerPreferenceId => $writerPreference ) {
			$writerPreference['id'] = (int) $writerPreferenceId;
			$writerPreferences[] = $writerPreference;
		}	

		$rawUploadTypes = UploadType::getUploadTypes();

		$uploadTypes = array();
		foreach( $rawUploadTypes as $uploadType ) {
			if( $uploadType['customer'] ) {
				$uploadTypes[] = array(
					'id' => (int) $uploadType['upload_type_id'],
					'description' => $uploadType['title']
				);
			}
		}

		$deadlinePresenter = new DeadlinePresenter();
		$deadlines = Deadline::getDeadlines( $site->id );

		$tariffs = array();
		foreach($deadlines as $deadline) {
			$tariff = new Deadline( (int) $deadline['deadline_id'] );
			if(Validate::isLoadedObject($tariff)) {
				$tariffs[] = $deadlinePresenter->present($tariff);
			}
		}

		$disciplineGroups = Discipline::getDisciplinesByGroup();
		
		$getTopPaperTypes = PaperType::getTopPaperTypes();
		$topPaperTypes = array();
		foreach( $getTopPaperTypes as $paperType ) {
			$paperType = new PaperType( (int) $paperType['paper_type_id'] );
			if(Validate::isLoadedObject($paperType)) {
				$topPaperTypes[] = (int) $paperType->id;
			}
		}

		$getTopDisciplines = Discipline::getTopDisciplines();
		$topDisciplines = array();
		foreach( $getTopDisciplines as $discipline ) {
			$discipline = new Discipline( (int) $discipline['topic_category_id'] );
			if(Validate::isLoadedObject($discipline)) {
				$topDisciplines[] = (int) $discipline->id;
			}
		}

		/** Countries **/
		$countries = array();
		$i = 0;
		foreach ($globals['countries'] as $key => $country) {
			$country['index'] = $i;
			$country['id'] = $key;
			$countries[] = $country;
			$i++;
        }	

		/** Payment methods **/
		$paymentModules = PaymentModule::getInstalledPaymentModules();
		$paymentMethods = array();
		foreach($paymentModules as $paymentModule) {
			$paymentModule = Module::getInstanceByName($paymentModule['name']);
			if(Validate::isLoadedObject($paymentModule)) {
				if($paymentModule->isActive()) {
					$paymentMethods[] = array(
						"enabled" => true,
						"name" => $paymentModule->displayName,
						"value" => $paymentModule->name,
						"availableCountries" => null
					);
				}
			}
		}

		if($user->isLogged() && Configuration::get('WALLET_ENABLED', PROX_ADMIN_SITE_ID)) {
			$paymentMethods[] = array(
				"enabled" => true,
				"name" => 'My Wallet',
				"value" => 'wallet',
				"availableCountries" => null
			);
		}

		$defaultTariffs = [];
		$default_deadlines = (string) Configuration::get('DEFAULT_DEADLINES');
		$default_deadlines = explode(',', $default_deadlines);
		
		foreach($default_deadlines as $deadline_id) {
			$defaultTariffs[] = (int) $deadline_id;
		}

        return $app->response([
            'success' => true,
            'countries' => $countries,
			'academicLevels' => $academicLevels,
			'departments' => $departments,
			'disciplinesGroups' => $disciplineGroups,
			'deadlines' => $tariffs,
			'tariffs' => $tariffs,
            'defaultTariffs' => $defaultTariffs,
			'paperFormats' => $paperFormats,
			'paperTypes' => $paperTypes,
			'revisionDeadlines' => $revisionDeadlines,
			'paidRevisionDeadlines' => $paidRevisionDeadlines,
            'writerPreferences' => $writerPreferences,
			'topPaperTypes' => $topPaperTypes,
			'topDisciplines' => $topDisciplines,
			'uploadTypes' => $uploadTypes,
			"siteCurrencies" => $availableCurrencies,
			"wordsPerPage" => (int) Configuration::get('WORDS_PER_PAGE', PROX_ADMIN_SITE_ID, 275),
			"walletEnabled" => (bool) Configuration::get('WALLET_ENABLED', PROX_ADMIN_SITE_ID, false),
			"prepapersEnabled" => (bool) Configuration::get('SELL_PREWRITTEN_PAPERS', $site->id, false),
			"leaveTipEnabled" => (bool) Configuration::get('LEAVE_TIP_ENABLED', PROX_ADMIN_SITE_ID, false),
            "siteCurrencyDefault" => (int) Configuration::get('CURRENCY_DEFAULT', $site->id, 1),
			"paymentMethods" => $paymentMethods,
            "defaultPaymentMethod" => Configuration::get('PAYMENT_METHOD_DEFAULT'),
            "defaultCourselevelId" => (int) Configuration::get('DEFAULT_COURSELEVEL', $site->id, 2),
            "urgentDeadlinesMaxPages" => (int) Configuration::get('URGENT_DEADLINE_MAX_PAGES', $site->id, 2),
            "hasDiscounts" => (bool) Configuration::get('DISCOUNTS_ENABLED', $site->id, false),
			"hasInquiry" => (bool) Configuration::get('INQUIRY_ENABLED', $site->id, false),
			"orderFormCoupons" => (bool) Configuration::get('ORDER_FORM_COUPONS', $site->id, false),
			"expertProofreading" => (bool) Configuration::get('EXPERT_PROOFREADING_ENABLED', $site->id, false),
            "vipSupport" => (bool) Configuration::get('VIP_SUPPORT_ENABLED', $site->id, false),
            "plagiarismReport" => (bool) Configuration::get('PLAGIARISM_REPORT_ENABLED', $site->id, false),
            "draftOutline" => (bool) Configuration::get('DRAFT_OUTLINE_ENABLED', $site->id, false),
            "writerSamples" => (bool) Configuration::get('WRITER_SAMPLES_ENABLED', $site->id, false),
            "progressiveDelivery" => (bool) Configuration::get('PROGRESSIVE_DELIVERY_ENABLED', $site->id, false),
            "copyOfSources" => (bool) Configuration::get('COPY_OF_SOURCES_ENABLED', $site->id, false),
            "siteFullName" => Configuration::get('SITE_NAME'),
			"siteUrlSsl" => Configuration::get('SITE_DOMAIN', PROX_SITE_ID, $app->base_uri),
        ]);
	}
	
	public function tipsForWriter() {
		$app = $this->app;

		if(!Configuration::get('LEAVE_TIP_ENABLED', PROX_ADMIN_SITE_ID, false)) {
			return $app->response([
				'success' => true,
				'tipsValues' => []
			]);
		}

		$sql = new DbQuery();
        $sql->select('*');
        $sql->from('tip_option');
        $sql->orderBy('type, value ASC');
        $result = Db::getInstance()->executeS($sql);

		$tipPresets = array();
		
        foreach($result as $tipPreset) {
            $tipPresets[] = array(
                'type' => (string) $tipPreset['type'],
                'value' => (float) $tipPreset['value'],
            );
		}
		
		$tipPresets[] = [
			'type' => 'customAmount'
		];

		return $app->response([
			'success' => true,
			'tipsValues' => $tipPresets
		]);
	}

    public function getUserCountry() {
        global $globals;
        $app = $this->app;

		$countries = ArrayUtils::get($globals, 'countries');
		$country_code = $app->container->cookie->country_code ? Tools::strtolower($app->container->cookie->country_code) : "us";
		$country = ArrayUtils::get($countries, $country_code);

		return $app->response([
			"success" => true,
			"defaultCountry" => [
				"id" => $country_code,
				"name" => ArrayUtils::get($country, 'name'),
				"code" => ArrayUtils::get($country, 'code'),
				"phoneCode" => ArrayUtils::get($country, 'phoneCode')
			]
		]);
    }

}