Spade

Mini Shell

Directory:~$ /home/lmsyaran/public_html/modules/mod_emergencyconsultant/
Upload File

[Home] [System Details] [Kill Me]
Current File:~$ /home/lmsyaran/public_html/modules/mod_emergencyconsultant/helper.php.bak_Stable

<?php
/*----------------------------------------------------------------------------------|
 www.vdm.io  |----/
				Vast Development Method 
/-------------------------------------------------------------------------------------------------------/

	@version		2.0.3
	@build			14th September, 2023
	@created		18th October, 2016
	@package		Demo
	@subpackage		helper.php
	@author			Llewellyn van der Merwe <https://www.vdm.io/>	
	@copyright		Copyright (C) 2015. All Rights Reserved
	@license		GNU/GPL Version 2 or later -
http://www.gnu.org/licenses/gpl-2.0.html
  ____  _____  _____  __  __  __      __       ___  _____  __  __  ____ 
_____  _  _  ____  _  _  ____ 
 (_  _)(  _  )(  _  )(  \/  )(  )    /__\     / __)(  _  )(  \/  )(  _ \( 
_  )( \( )( ___)( \( )(_  _)
.-_)(   )(_)(  )(_)(  )    (  )(__  /(__)\   ( (__  )(_)(  )    (  )___/
)(_)(  )  (  )__)  )  (   )(  
\____) (_____)(_____)(_/\/\_)(____)(__)(__)   \___)(_____)(_/\/\_)(__) 
(_____)(_)\_)(____)(_)\_) (__) 

/------------------------------------------------------------------------------------------------------*/

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

class ModEmergencyConsultantHelper
{
    public static function do_step0($input, $cb_user)
    {
        $topic= $input->get('topic', null,
'string');
        if (!$topic)
        {
            jfactory::getapplication()->enqueuemessage('یکی از
موضوعات را انتخاب کنید', 'warning');
            return;
        }

        $user= jfactory::getuser();
        $current_user_id= $user->get('id', 0,
'int');
        $current_user_name= $user->get('name');
        
        $groups = $user->get('groups');
if( in_array( "10" ,$groups ) )
{
    $errorfake="این درخواست از سمت یک مشاور
جهت آزمایش سامانه بوده است. لطفا بخش
اورژانس سامانه را آزمایش نکنید.فیلم
آموزشی موجود است به آن مراجعه کنید، نیازی
به زدن دکمه پذیرفتن نیست.";
}
        // dump($groups,"groups");
        $db     = JFactory::getDBO();
        foreach($groups as $group){
            $query  = 'SELECT title FROM #__usergroups';
            $query .= ' WHERE id = ' . $group;
            $db->setQuery( $query );
            $usergroups .= " ". $db->loadResult();
        }
       $usergroupnames="نقش واقعی فرد: ".$usergroups;
//        $timezone = (array)jFactory::getUser()->getTimezone();
//        date_default_timezone_set($timezone['timezone']);
        $time = date('H:i:s');

//        $emergency_start_time=
$cb_user->get('cb_emergency_start_time',
'00:00:00')== '00:00:00' ? '00:00:00':
$cb_user->get('cb_emergency_start_time');
//        $emergency_end_time=
$cb_user->get('cb_emergency_end_time', '00:00:00')==
'00:00:00' ? '23:59:59':
$cb_user->get('cb_emergency_start_time');


        $params =
JComponentHelper::getParams('com_reservation');
        $category_rules= $params->get('category_rule');
        foreach ($category_rules as $category_rule)
        {
            if ($category_rule->cat_rule== 'eplanrule')
            {
                $emergency_catid= $category_rule->catid;
            }
        }
        



//        $db = JFactory::getDbo();
//        $query = $db->getQuery(true);
//
//        $query->select('c.id as cbid, cb_queue_consultants,
cb_balechatid, cb_emergency_start_time, cb_emergency_end_time');
//        $query->from($db->quoteName('#__comprofiler',
'c'));
//        $query->join('INNER',
$db->quoteName('#__reservation_consultant', 'rc') .
' ON ' . $db->quoteName('rc.userid') . ' =
' . $db->quoteName('c.id'));
//        $query->join('INNER',
$db->quoteName('#__reservation_plan', 'p') . '
ON ' . $db->quoteName('rc.id') . ' = ' .
$db->quoteName('p.consultantid'));
//        $query->where($db->quoteName('c.cb_is_emergency')
. '= 1');
//        $query->where($db->quoteName('p.catid') .
'='. $emergency_catid);
//       
$query->where('TIME_FORMAT('.$db->quoteName('c.cb_emergency_start_time').',
\'%H:%i:%s\')' . '<=\''.
$time.'\'');
//       
$query->where('TIME_FORMAT('.$db->quoteName('c.cb_emergency_end_time').',
\'%H:%i:%s\')' . '>=\''.
$time.'\'');
//        $query->where($db->quoteName('c.cb_balechatid') .
'is not null');
//        $query->where($db->quoteName('p.published') .
'= 1');
//
//        $db->setQuery($query);
//        $results = $db->loadObjectList('cbid');


        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL =>
'https://erammoshaver.ir/index.php?option=com_comprofiler&view=pluginclass&plugin=cbautoactions&action=action&actions=125&Itemid=147',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'GET'
        ));

        $results = json_decode(curl_exec($curl));
        curl_close($curl);

        if (!empty($results))
        {
            $data= [];
            $text= " *{$errorfake}* مشاوره اورژانسی با
موضوع {$topic} توسط {$current_user_name} درخواست شده
است.
چنانچه شما سریع‌تر این درخواست را
بپذیرید میتوانید از سایر مشاورین پیشی
گرفته و به عنوان مشاور فرد موردنظر انتخاب
شوید ";
            foreach ($results as $result) {
                $consultant_user_id= $result->id;
                $data[]= [
                    "chat_id" => $result->cb_balechatid,
                    // "chat_id" => '2048243497',
                    // "text" =>
$text.'-'.$result->cb_balechatid, 
                    "text" => $text,
                    "reply_markup"=> [
                        "inline_keyboard"=>[
                            [['text'=>
"پذیرفتن", "callback_data"=>
"emergency_accept|{$current_user_id}|{$consultant_user_id}"]]
                        ]
                    ]
                ];
            } 

            $data[]= [
                "chat_id" => '@emergencyreq',
                "text" => "کاربر با شناسه
{$current_user_id} و نام {$current_user_name} درخواست
اورژانسی ارسال کرد *{$usergroupnames}* "
            ];
            self::send_bale_message($data);

            $cb_user->set('cb_emergency_step', 1); 
            $cb_user->set('cb_emergency_topic', $topic);
            return $cb_user->store();
        }

        jfactory::getapplication()->enqueuemessage("در حال
حاضر مشاوری آماده پذیرش درخواست مشاوره
در زمینه <b>{$topic}</b> نیست. لطفا مدتی
بعد تلاش کنید.", 'warning');

    }

    public static function do_step2($do, $cb_user)
    {

        if ($do== 'start')
        {
            $cb_user->set('cb_emergency_step', 0);
            $cb_user->set('cb_queue_consultants',
'');
            $cb_user->set('cb_emergency_topic',
'');
            $cb_user->store();

            $start_url=
jfactory::getApplication()->input->get('start_url',
'', 'string');
            header("Location: {$start_url}");
            exit();
        }
        elseif ($do== 'find_next')
        {
            $emergency_consultants=
unserialize($cb_user->get('cb_queue_consultants'));
            array_push($emergency_consultants,
array_shift($emergency_consultants));
            
            $cb_user->set('cb_queue_consultants',
serialize($emergency_consultants));
            return $cb_user->store();
        }
        else
        {
            $cb_user->set('cb_emergency_step', 0);
            $cb_user->set('cb_queue_consultants',
'');
            $cb_user->set('cb_emergency_topic',
'');
            return $cb_user->store();
        }
    }

    public static function emergency_consultant($cb_user)
    {

        $params =
JComponentHelper::getParams('com_reservation');
        $category_rules= $params->get('category_rule');
        foreach ($category_rules as $category_rule)
        {
            if ($category_rule->cat_rule== 'eplanrule')
            {
                $emergency_catid= $category_rule->catid;
            }
        }

        $emergency_consultant_id=
unserialize($cb_user->get('cb_queue_consultants'))[0];

        $db = JFactory::getDbo();
        $query = $db->getQuery(true);

        $query->select('p.*');
       
$query->from($db->quoteName('#__reservation_consultant',
'c'));
        $query->join('INNER',
$db->quoteName('#__reservation_plan', 'p') . '
ON ' . $db->quoteName('c.id') . ' = ' .
$db->quoteName('p.consultantid'));
       
$query->where($db->quoteName('c.userid').'='.$db->quote($emergency_consultant_id));
       
$query->where($db->quoteName('p.catid').'='.$db->quote($emergency_catid));
        $query->where($db->quoteName('p.published') .
'= 1');

        $db->setQuery($query);
        $emergency_consultant_plan = $db->loadObject();

        return [$emergency_consultant_id, $emergency_consultant_plan];
    }

    public static function calc_step($cb_user)
    {
            $emergency_step=
$cb_user->get('cb_emergency_step', 0);
            return (int)$emergency_step;
    }


    public static function get_topics($cb_user)
    {
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);

        $query->select('fieldlabel');
       
$query->from($db->quoteName('#__comprofiler_fields',
'f'));
        $query->join('INNER',
$db->quoteName('#__comprofiler_field_values', 'fv')
. ' ON ' . $db->quoteName('f.fieldid') . ' =
' . $db->quoteName('fv.fieldid'));
        $query->where($db->quoteName('f.name') .
'='. $db->quote('cb_userexpertisearea'));

        $db->setQuery($query);
        $results = $db->loadObjectList();
        return $results;
    }

    public static function send_bale_message($data=[])
    {
        $params= json_decode(jpluginhelper::getPlugin('chat',
'send_by_bale')->params);

        $bot_token= $params->bot_token;
        $getupdates_url=
"https://tapi.bale.ai/bot".$bot_token."/getupdates";
        $sendmessage_url=
"https://tapi.bale.ai/bot".$bot_token."/sendMessage";

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $sendmessage_url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt( $curl, CURLOPT_HTTPHEADER, array('Content-Type:
application/json'));
        foreach ($data as $item)
        {
            curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($item));
            $response = curl_exec($curl);
        }

        $response = json_decode($response);
//        $err = curl_error($curl);
        curl_close($curl);
        return $response;
    }


    public static function getAjax()
    {
        include_once(JPATH_ADMINISTRATOR .
'/components/com_comprofiler/plugin.foundation.php');

        $user= jfactory::getuser();
        $current_user_id= $user->get('id', 0,
'int');

        $cbUser = &CBuser::getInstance((int)$current_user_id);
        $cb_user = $cbUser->getUserData();

        $queue_consultants=
$cb_user->get('cb_queue_consultants', null);

        if (empty($queue_consultants))
            return false;

        return true;
    }
}