//******************************************************************************    phone number

$type = $this->telegram_model->get_chat($token,$chatid1);
$type = json_decode($type, true);

if($type['result']['type'] == "private" && $chatType == "private"){
    $userlang = $this->telegram_model->get_phone_sell_lang($user_id)[0]->lang;
    $is_user = $this->telegram_model->get_phone_sell($user_id);
    $persianKey = array("1"=>"🛍 خرید شماره مجازی","2"=>"🤝 همکاری","3"=>"📃 اخبار و مقالات","4"=>"☎️ پشتیبانی","5"=>"ℹ️ قوانین و مقررات","6"=>"👤 حساب کاربری","7"=>"✏️ ثبت نام شماره مجازی","8"=>"🏠 خانه",
                        "9"=>"📱 انتخاب پلتفرم","10"=>"💾 ذخیره","11"=>"💳 شارژ حساب","12"=>"📲 ارسال شماره موبایل","13"=>"صفحه بعد ⬅️","14"=>"➡️ صفحه قبل","15"=>"دریافت کد","16"=>"لغو","17"=>"لغو و اعلام مسدود");
    
    $englishKey = array("1"=>"🛍 Buy virtual number","2"=>"🤝 Cooperation","3"=>"📃 Articles","4"=>"☎️ Support","5"=>"ℹ️ Conditions","6"=>"👤 Profile","7"=>"✏️ register","8"=>"🏠 Home",
    "9"=>"📱 Choose platform","10"=>"💾 Save","11"=>"💳 Charge account","12"=>"Send mobile 📲","13"=>"Next page ⬅️","14"=>"➡️ previous page","15"=>"Get code","16"=>"Cancell","17"=>"Cancell and ban");
    
    if($userlang == "fa" || $message == "فارسی"){
        //$this->telegram_model->send_message_only($token,'-1001155301071',$contactGet );
        $buyanumber = $persianKey[1];
        $Cooperation = $persianKey[2];
        $articles = $persianKey[3];
        $Support = $persianKey[4];
        $Conditions = $persianKey[5];
        $profile = $persianKey[6];
        $RegisterBuyViertual = $persianKey[7];
        $home = $persianKey[8];
        $choosPlat = $persianKey[9];
        $save = $persianKey[10];
        $chargeAcc  = $persianKey[11];
        $nextRegKey = $persianKey[12];
        $nextPageKey = $persianKey[13];
        $prevPageKey = $persianKey[14];
        $getCodeKey = $persianKey[15];
        $cancellKey = $persianKey[16];
        $cancellBanKey = $persianKey[17];
        
        if($userlang == ""){
            $text = "یکی از گزینه ها را انتخاب کنید";
            $keyboard = array("keyboard" => array(array($buyanumber),array($Cooperation,$articles),array($Support,$Conditions)),"resize_keyboard"=>true);
            $this->telegram_model->send_message($token,$user_id,$text,$keyboard);
            $data = array("telid"=>$user_id,"lang"=>"fa");
            $this->telegram_model->set_phone_sell_lang($data);
        }
        
    }elseif($userlang == "en" || $message == "English"){
        //$this->telegram_model->send_message_only($token,'-1001155301071',$contactGet );
        $buyanumber = $englishKey[1];
        $Cooperation = $englishKey[2];
        $articles = $englishKey[3];
        $Support = $englishKey[4];
        $Conditions = $englishKey[5];
        $profile = $englishKey[6];
        $RegisterBuyViertual = $englishKey[7];
        $home = $englishKey[8];
        $choosPlat = $englishKey[9];
        $save = $englishKey[10];;
        $chargeAcc  = $englishKey[11];
        $nextRegKey = $englishKey[12];
        $nextPageKey = $englishKey[13];
        $prevPageKey = $englishKey[14];
        $getCodeKey = $englishKey[15];
        $cancellKey = $englishKey[16];
        $cancellBanKey = $englishKey[17];
        
        if($userlang == ""){
            $text = "Choose one key";
            $keyboard = array("keyboard" => array(array($buyanumber),array($Cooperation,$articles),array($Support,$Conditions)),"resize_keyboard"=>true);
            $this->telegram_model->send_message($token,$user_id,$text,$keyboard);
            $data = array("telid"=>$user_id,"lang"=>"en");
            $this->telegram_model->set_phone_sell_lang($data);
        }
        
    }
    
    
    if($message == "/start"){
        $is_user = $this->telegram_model->get_phone_sell($user_id);
        if(strlen($is_user[0]->reg_time) == 0){
            $this->telegram_model->clear_phone_sell($user_id);   
        }
        $data = array("lang"=>"");
        $this->telegram_model->update_phone_sell_lang($user_id,$data);
    }
    if($message == $home && strlen($home) > 0){
        
        if($userlang == "fa"){
            $text = "🔘 به منوی اصلی بازگشتید\n\n👇🏻 از دکمه های زیر استفاده کنید";
        }else{
            $text = "🔘 You are back to the main menu\n\n👇🏻 Use the following buttons";
        }
        $keyboard = array("keyboard" => array(array($buyanumber),array($Cooperation,$articles),array($Support,$Conditions)),"resize_keyboard"=>true);
        $this->telegram_model->send_message($token,$chatid1,$text,$keyboard);
        if(strlen($is_user[0]->reg_time) == 0){
            $this->telegram_model->clear_phone_sell($user_id);   
        }
    }
    
    if($message == $Cooperation && strlen($Cooperation) > 0){
        if($userlang == "fa"){
            $text = "این لینک را برای معرفی ربات به دوستانتان بدهید و از هر خرید آنها 10 درصد درآمد کسب کنید\n\n t.me/VieraBot?start=BVN-$user_id";
        }else{
            $text = "Give this link to your friends to introduce the bot and earn 10% of their purchases\n\n t.me/VieraBot?start=BVN-$user_id";
        }
        $this->telegram_model->send_message_only($token,$chatid1,$text );
    }
    
    if($message != "/start" && $message != $RegisterBuyViertual && $message != $nextRegKey &&
    $message != $buyanumber && $message != $home && $message != "👎 بازگشت" && $message != "❇️ ورود ❇️" && $message != $choosPlat){
        $is_user = $this->telegram_model->get_phone_sell($user_id);
        
        if(strlen($is_user[0]->telid) > 0 && strlen($is_user[0]->fullname) == 0){
            $data = array("fullname"=>$message);
            //$this->telegram_model->send_message_only($token,'-1001155301071',"نام: ".$message);
    	    $this->telegram_model->update_phone_sell($user_id,$data);
        }elseif(strlen($is_user[0]->telid) > 0 && strlen($is_user[0]->mobile) == 0 && strlen($contactGet) > 0){
            //if(){
                $data = array("mobile"=>$contactGet);
                //$this->telegram_model->send_message_only($token,'-1001155301071',"موبایل: ".$contactGet);
        	    $this->telegram_model->update_phone_sell($user_id,$data);
        	    $is_user = $this->telegram_model->get_phone_sell($user_id);
        	    $fullname = $is_user[0]->fullname;
                $mobile = trim(str_ireplace("+","",$is_user[0]->mobile))."+";
                if($userlang == "fa"){
                    $text = "🎫 اطلاعات ارسالی شما\n\n👤 نام: $fullname\n\n📲 موبایل: $mobile\n\n‼️ اگر اطلاعات درست است کلید ".'"💾 ذخیره"'." را بزنید، در غیر اینصورت کلید ".'"🏠 خانه"'." را زده و مراحل ثبت نام را دوباره انجام دهید";
                }else{
                    $text = "🎫 Your sent information\n\n👤 Name: $fullname\n\n📲 Mobile: $mobile\n\n‼️ If the information is correct, press the ".'"💾 Save"'." key, in Otherwise, press the key ".'"🏠 Home"'." and redo the registration process";
                }
    
                $keyboard = array("keyboard" => array(array("$save","$home")),"resize_keyboard"=>true);
                $this->telegram_model->send_message($token,$id,$text,$keyboard);
            //}
            
        }
    }
    if($message == $buyanumber && strlen($buyanumber) > 0){
        //forward chek shavad
        //$is_user = $this->telegram_model->get_phone_sell($user_id);
        
        if(count($is_user) > 0 && strlen($is_user[0]->fullname) > 0 && strlen($is_user[0]->mobile) > 0){
            
            if($userlang == "fa"){
                $text = "🌟 این ربات اتوماتیک است و میتوانید فقط در ظرف چند ثانیه شماره مجازی و کد تایید شماره مجازی خودتون رو دریافت کنید\n\n🎊 خرید شماره مجازی برای کشور های مختلف و نرم افزار های مختلف داخل ربات امکان پذیر است\n\n👇🏻 از دکمه های زیر استفاده کنید";
            }else{
                $text = "🌟 This robot is automatic and you can get your virtual number and verification code of your virtual number in just a few seconds\n\n🎊 It is possible to buy a virtual number for different countries and different software inside the robot. n\n👇🏻 use the following buttons";
            }
            
            $keyboard = array("keyboard" => array(array($choosPlat),array($chargeAcc,$profile),array($home)),"resize_keyboard"=>true);
            $result = $this->telegram_model->send_message($token,$id,$text,$keyboard);
            //$this->telegram_model->send_message_only($token,'-1001155301071',$result );
        }else{
            $this->telegram_model->clear_phone_sell($user_id);
            //$this->telegram_model->send_message_only($token,$chatid1,"شما هنوز ثبت نام نکرده اید.");
            if($userlang == "fa"){
                $text = "⚠️ شما هنوز ثبت نام نکرده اید\n\n📖 آیا مایل به ثبت نام هستید ؟";
            }else{
                $text = "⚠️ You are not registered yet\n\n📖 Do you want to register?";
            }
            
        	$keyboard = array("keyboard" => array(array($RegisterBuyViertual,$home)),"resize_keyboard"=>true);
        	$this->telegram_model->send_message($token,$id,$text,$keyboard);
        }
    }
    if($message == $RegisterBuyViertual && strlen($RegisterBuyViertual) > 0){
        //forward chek shavad
        $is_user = $this->telegram_model->get_phone_sell($user_id);
        $represent = $this->telegram_model->get_phone_sell_represent($user_id);
        
        if(count($is_user) == 0){
            $data = array("telid"=>$user_id);
    	    $this->telegram_model->set_phone_sell($data);
    	    if(count($represent) > 0){
                $data = array("present"=>$represent[0]->represent);
        	    $this->telegram_model->update_phone_sell($user_id,$data);
        	    $this->telegram_model->clear_phone_sell_represent($user_id);
            }
        }
        
        if($userlang == "fa"){
            $text = "👤 نام کامل خود را وارد نمایید\n\n‼️ سپس کلید ".'"بعدی ⬅️"'." را بزنید";
        }else{
            $text = "👤 Enter your full name\n\n‼️ Then press the ".'"next ⬅️"'." key";
        }
        
        //$keyboard = array("keyboard" => array(array("$nextRegKey","$home")),"resize_keyboard"=>true);
        $keyboard = array('keyboard' => array(array(array('text'=>$nextRegKey,'request_contact'=>true),$home)),"resize_keyboard"=>true);
        $this->telegram_model->send_message($token,$id,$text,$keyboard);
    }
    /*if($message == $nextRegKey){
        //forward chek shavad
        //$is_user = $this->telegram_model->get_phone_sell($user_id);
        if(strlen($is_user[0]->fullname) == 0){
            if($userlang == "fa"){
                $text = "👤 نام کامل خود را وارد نمایید\n\n‼️ سپس کلید ".'"بعدی ⬅️"'." را بزنید";
            }else{
                $text = "👤 Enter your full name\n\n‼️ Then press the ".'"next ⬅️"'." key";
            }
            
            //$keyboard = array("keyboard" => array(array("$nextRegKey","$home")),"resize_keyboard"=>true);
            $keyboard = array('keyboard' => array(array(array('text'=>$nextRegKey,'request_contact'=>true),$home)),"resize_keyboard"=>true);
            $this->telegram_model->send_message($token,$id,$text,$keyboard);
        }elseif(strlen($is_user[0]->mobile) == 0){
            if($userlang == "fa"){
                $text = "📲 شماره موبایل خود را وارد نمایید\n\n‼️ سپس کلید ".'"بعدی ⬅️"'." را بزنید";
            }else{
                $text = "📲 Enter your mobile number\n\n‼️ Then press the ".'"next ⬅️"'." key";
            }
            
            $keyboard = array('keyboard' => array(array(array( 'text'=>"SHOW PHONE",'request_contact'=>true),$home)),"resize_keyboard"=>true);
            //$keyboard = array("keyboard" => array(array("$nextRegKey","$home")),"resize_keyboard"=>true);
            $this->telegram_model->send_message($token,$id,$text,$keyboard);
        }elseif(strlen($contactGet) > 0){
            $fullname = $is_user[0]->fullname;
            $mobile = $is_user[0]->mobile;
            if($userlang == "fa"){
                $text = "🎫 اطلاعات ارسالی شما\n\n👤 نام: $fullname\n\n📲 موبایل: $mobile\n\n‼️ اگر اطلاعات درست است کلید ".'"💾 ذخیره"'." را بزنید، در غیر اینصورت کلید ".'"🏠 خانه"'." را زده و مراحل ثبت نام را دوباره انجام دهید";
            }else{
                $text = "🎫 Your sent information\n\n👤 Name: $fullname\n\n📲 Mobile: $mobile\n\n‼️ If the information is correct, press the ".'"💾 Save"'." key, in Otherwise, press the key ".'"🏠 Home"'." and redo the registration process";
            }

            $keyboard = array("keyboard" => array(array("$save","$home")),"resize_keyboard"=>true);
            $this->telegram_model->send_message($token,$id,$text,$keyboard);
        }
    }*/
    if($message == $save && strlen($save) > 0){
        //forward chek shavad
        $data = array("reg_time"=>time());
    	$this->telegram_model->update_phone_sell($user_id,$data);
    	if($userlang == "fa"){
            $text = "✅ ثبت نام شما با موفقیت انجام شد\n\n⚠️ لطفا برای خرید شماره مجازی ابتدا حساب کاربری خود را شارژ نمائید\n\n👇🏻 از دکمه های زیر استفاده کنید";
        }else{
            $text = "Your registration has been successfully completed\n\n⚠️ Please top up your user account first to purchase a virtual number\n\n👇🏻 use the following buttons";
        }
        
        $keyboard = array("keyboard" => array(array($choosPlat),array($chargeAcc,$profile),array($home)),"resize_keyboard"=>true);
        $this->telegram_model->send_message($token,$id,$text,$keyboard);
    }
    if($message == $chargeAcc && strlen($chargeAcc) > 0){
        //forward chek shavad
        //$is_user = $this->telegram_model->get_phone_sell($user_id);
        $this_charge = number_format($is_user[0]->charge);
        if($this_charge == ""){
            $this_charge = 0;
        }
        if($userlang == "fa"){
            $text = "💎 برای افزایش موجودی حساب خود لطفا مبلغ دلخواه خود را به شماره کارت زیر واریز کرده و عکس رسید را همراه با شناسه کاربری خود برای بخش پشتیبانی ارسال کنید\n\n💳 6362 1410 4457 2545\n👤 بنام: امیرحسین\n\n🆔 شناسه: ".$is_user[0]->telid."\n\n💰 موجودی فعلی: ".$this_charge." تومان";
        }else{
            $text = "💎 To increase your account balance, please deposit the desired amount to the card number below and send a photo of the receipt along with your user ID to the support department\n\n💳 6362 1410 4457 2545\n👤 Name: Amir Hossein \n\n🆔 ID: ".$is_user[0]->telid."\n\n💰 Current balance: ".$this_charge." Toman";
        }
        
        $this->telegram_model->send_message_only($token,$chatid1,$text );
    }
    if($message === $profile && strlen($profile) > 0){
        //forward chek shavad
        //if(strpos($message,"Profile") == 5|| strpos($message,"حساب کاربری") == 5){
            //$this->telegram_model->send_message_only($token,$chatid1,strpos($message,"Profile") );
            $is_user = $this->telegram_model->get_phone_sell($user_id);
            $orders_phone = $this->telegram_model->get_phone_sell_order($user_id);
            $buy_count = count($orders_phone);
            $balance = number_format((($is_user[0]->charge == '') ? 0 : $is_user[0]->charge));
            $reg_persian = $this->persiandate->jdate("l Y/m/d",$is_user[0]->reg_time,"",'Asia/Tehran',"en");
            if($userlang == "fa"){
                $text = "🎫 حساب کاربری شما در ویرابات\n\n👤 نام: ".$is_user[0]->fullname."\n\n📲 موبایل: ".$is_user[0]->mobile."\n\n🆔 شناسه: ".$is_user[0]->telid."\n\n💰 موجودی حساب: ".$balance." تومان\n\n🛍 تعداد خرید: ".$buy_count."\n\n⏰ زمان ثبت نام: ".$reg_persian."\n\n👤";
            }else{
                $text = "🎫 Your user account in Virabat\n\n👤 Name: ".$is_user[0]->fullname."\n\n📲 Mobile: ".$is_user[0]->mobile."\n \n🆔 ID: ".$is_user[0]->telid."\n\n💰 Account balance: ".$balance." Tomans\n\n🛍 Number of purchases: ".$buy_count."\n\n ⏰ Registration time: ".$reg_persian."\n\n👤";
            }
            
            $this->telegram_model->send_message_only($token,$chatid1,$text );
        //}
        
    }
    if($message == $articles && strlen($articles) > 0){
        //forward chek shavad
        if($userlang == "fa"){
            $this->telegram_model->send_message_only($token,$chatid1,"این سرویس بزودی فعال می شود" );
        }else{
            $this->telegram_model->send_message_only($token,$chatid1,"This service will be activated soon" );
        }
        
    }
    if($message == $Support && strlen($Support) > 0){
        //forward chek shavad
        if($userlang == "fa"){
            $this->telegram_model->send_message_only($token,$chatid1,"این سرویس بزودی فعال می شود" );
        }else{
            $this->telegram_model->send_message_only($token,$chatid1,"This service will be activated soon" );
        }
    }
    if($message == $Conditions && strlen($Conditions) > 0){
        //forward chek shavad
        if($userlang == "fa"){
            $this->telegram_model->send_message_only($token,$chatid1,"این سرویس بزودی فعال می شود" );
        }else{
            $this->telegram_model->send_message_only($token,$chatid1,"This service will be activated soon" );
        }
    }
    if($message == $choosPlat && strlen($choosPlat) > 0){
        //forward chek shavad
        $arraydata = array();
        $myNumServices = $this->telegram_model->get_phone_sell_services();
        $name_need = ["Telegram","Instagram","whatsapp","viber","wechat","google","facebook","twitter","microsoft","line","yahoo","beetalk","linkedin","amazon","netflix","discord","apple","Blizzard","signal","Tango","Likee","tiktok"];
        $emoji_need = array("tiktok"=>"📱","signal"=>"📡","Tango"=>"👥","discord"=>"🗣","apple"=>"🍎","Blizzard"=>"🕹","linkedin"=>"📇","amazon"=>"🛒","netflix"=>"🎞","line"=>"💬","yahoo"=>"📨",
                                "beetalk"=>"🐝","facebook"=>"👤","twitter"=>"🐦","microsoft"=>"💻","viber"=>"💬","wechat"=>"💬","google"=>"🔍","Telegram"=>"💎","Instagram"=>"📸","whatsapp"=>"📞");
        if($userlang == "fa"){
            $text = "🔘 میخواهید در چه برنامه ای ثبت نام کنید؟ سرویس یا اپلیکیشن مورد نظر خود را انتخاب کنید 👇🏻\n\n⚠️ در انتخاب سرویس دقت کنید! زیرا کد تایید ارسالی بر اساس سرویس دسته بندی خواهد شد";
        }else{
            $text = "What program do you want to register for? Choose the service or application you want 👇🏻\n\n⚠️ Be careful in choosing the service! Because the confirmation code sent will be categorized according to the service";
        }
        
        $keyName = "";
    	$arraydata = array(array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array());
        $arraynumber = 0;
    	$jw = 1;
    	for($i=0;$i<45;$i++){
	        if($myNumServices[$i]->name == "دیگـر سرویـس‌ها"){
	            continue;
	        }else{
	            
	            if(in_array($myNumServices[$i]->name_en, $name_need)){
	                $keyId = $myNumServices[$i]->id;
	                if($myNumServices[$i]->active == "1"){
	                    $emoji = $emoji_need[$myNumServices[$i]->name_en];
	                    if($userlang == "fa"){
	                        if($myNumServices[$i]->name == "جیمیل - گوگل - یوتیوب"){
            	                $keyName = "گوگل";
            	                //$this->telegram_model->send_message_only($token,'-1001155301071',$myNumServices[$i]->active );
                	        }elseif($myNumServices[$i]->name == "Tango"){
                	            $keyName = "تانگو";
                	        }elseif($myNumServices[$i]->name == "نت‌فلیکس"){
                	            $keyName = "نتفلیکس";
                	        }else{
                	            $keyName = str_ireplace("ـ","",$myNumServices[$i]->name);
                	        }
	                    }else{
	                        $keyName = $myNumServices[$i]->name_en;
	                    }
	                    
            	        $keyName = $keyName." $emoji";
            	        $keyNameData = "service-$keyId";
                        array_push($arraydata[$arraynumber],array(text=>$keyName,callback_data=>$keyNameData));
                        if($jw % 3 == 0){
                            $arraynumber++;
                	    }
                        $jw++;
	                }
    	            
    	        }
	        }
        }
    	$keyboard =  array("inline_keyboard" => $arraydata);
    	$result = $this->telegram_model->send_message($token,$chatid1,$text,$keyboard);
    	$result1 = json_decode($result, true);
    	if($userlang == "fa"){
            $text = "لطفا یکی از موارد را انتخاب کنید";
        }else{
            $text = "Please choose one of the items";
        }
    	
    	$keyboard = array("keyboard" => array(array("$chargeAcc","$home")),"resize_keyboard"=>true);
        $result = $this->telegram_model->send_message($token,$chatid1,$text,$keyboard);
        //$result = json_decode($result, true);
        //$data = array("content"=>$result["result"]["message_id"]);
        //$this->telegram_model->update_temp(6,$data);
    }
}

//$res = $this->telegram_model->send_message_only($token,'-1001155301071',$callback_inline_message_id);
//$this->telegram_model->send_message_only($token,'-1001155301071',$res);

//$callback_message = $update->callback_query->data;
//$callback_chatid = $update->callback_query->message->chat->id;
//$callback_userid = $update->callback_query->from->id;
//$callback_fname = $update->callback_query->from->first_name;
$type1 = $this->telegram_model->get_chat($token,$callback_chatid);
$type1 = json_decode($type1, true);

if($type1['result']['type'] == "private" && $callback_chatType == "private"){
    $userlang = $this->telegram_model->get_phone_sell_lang($callback_chatid)[0]->lang;
    $persianKey = array("1"=>"🛍 خرید شماره مجازی","2"=>"🤝 همکاری","3"=>"📃 اخبار و مقالات","4"=>"☎️ پشتیبانی","5"=>"ℹ️ قوانین و مقررات","6"=>"👤 حساب کاربری","7"=>"✏️ ثبت نام شماره مجازی","8"=>"🏠 خانه",
                            "9"=>"📱 انتخاب پلتفرم","10"=>"💾 ذخیره","11"=>"💳 شارژ حساب","12"=>"بعدی ⬅️","13"=>"صفحه بعد ⬅️","14"=>"➡️ صفحه قبل","15"=>"دریافت کد","16"=>"لغو","17"=>"لغو و اعلام مسدود");
    
    $englishKey = array("1"=>"🛍 Buy virtual number","2"=>"🤝 Cooperation","3"=>"📃 Articles","4"=>"☎️ Support","5"=>"ℹ️ Conditions","6"=>"👤 Profile","7"=>"✏️ register","8"=>"🏠 Home",
    "9"=>"📱 Choose platform","10"=>"💾 Save","11"=>"💳 Charge account","12"=>"Next ⬅️","13"=>"Next page ⬅️","14"=>"➡️ previous page","15"=>"Get code","16"=>"Cancell","17"=>"Cancell and ban");
    
    if($userlang == "fa" || $message == "فارسی"){
        $this->telegram_model->send_message_only($token,'-1001155301071',$contactGet );
        $buyanumber = $persianKey[1];
        $Cooperation = $persianKey[2];
        $articles = $persianKey[3];
        $Support = $persianKey[4];
        $Conditions = $persianKey[5];
        $profile = $persianKey[6];
        $RegisterBuyViertual = $persianKey[7];
        $home = $persianKey[8];
        $choosPlat = $persianKey[9];
        $save = $persianKey[10];
        $chargeAcc  = $persianKey[11];
        $nextRegKey = $persianKey[12];
        $nextPageKey = $persianKey[13];
        $prevPageKey = $persianKey[14];
        $getCodeKey = $persianKey[15];
        $cancellKey = $persianKey[16];
        $cancellBanKey = $persianKey[17];
        
        
    }elseif($userlang == "en" || $message == "English"){
        $this->telegram_model->send_message_only($token,'-1001155301071',$contactGet );
        $buyanumber = $englishKey[1];
        $Cooperation = $englishKey[2];
        $articles = $englishKey[3];
        $Support = $englishKey[4];
        $Conditions = $englishKey[5];
        $profile = $englishKey[6];
        $RegisterBuyViertual = $englishKey[7];
        $home = $englishKey[8];
        $choosPlat = $englishKey[9];
        $save = $englishKey[10];;
        $chargeAcc  = $englishKey[11];
        $nextRegKey = $englishKey[12];
        $nextPageKey = $englishKey[13];
        $prevPageKey = $englishKey[14];
        $getCodeKey = $englishKey[15];
        $cancellKey = $englishKey[16];
        $cancellBanKey = $englishKey[17];
        /*if($userlang == ""){
            $text = "Choose one key";
            $data = array("telid"=>$user_id,"lang"=>"en");
            $keyboard = array("keyboard" => array(array($buyanumber),array($Cooperation,$articles),array($Support,$Conditions)),"resize_keyboard"=>true);
            $this->telegram_model->send_message($token,$user_id,$text,$keyboard);
            $this->telegram_model->set_phone_sell_lang($data);
        }*/
        
    }
    if($callback_message == "info"){
        if($userlang == "fa"){
            $text = "این کلید برای نمایش اطلاعات است. برای خرید شماره لطفا کلید خرید را فشار دهید";
        }else{
            $text = "This key is for displaying information. To buy the number, please press the buy key";
        }
        
        $res = $this->telegram_model->send_message_answer_callback($token,$callback_chatid,$callback_id,$text);
    }else{
        $ction = explode("-",$callback_message);
        //$res = $this->telegram_model->send_message_only($token,'-1001155301071',"key result: ".$ction[0]);
        if($ction[0] == "service"){
            $platId = $ction[1];
            //$platId = (int)filter_var($callback_message, FILTER_SANITIZE_NUMBER_INT);
            /*$info = $this->telegram_model->number_getinfo($platId, $country);
            $info = json_decode($info, true);
            $infoSort = array();
            foreach ($info as $key => $row) {
                $return_country[$key]  = $row['country'];
                $return_amount[$key] = $row['amount'];
            }
            array_multisort($info, $return_country, SORT_ASC, $return_amount, SORT_ASC);
            //$sorted = array_orderby($data, 'return_fare', SORT_ASC, 'one_way_fare', SORT_ASC);
            array_multisort(array_column($info, 'country'),  SORT_ASC,array_column($info, 'amount'), SORT_ASC,$info);
            $sortCounter = 0;
            for($k = 0; $k < count($info); $k++){
                if($info[$k-1]['country'] != $info[$k]['country']){
                    $infoSort[$sortCounter] = $info[$k];
                    $sortCounter++;
                }
            }*/
            
            $mycountrys = $this->telegram_model->get_phone_sell_country();
            if($userlang == "fa"){
                $platform_name = $this->telegram_model->get_phone_sell_services_one($platId)[0]->name;
                $text = "📱 پلتفرم انتخاب شده: #$platform_name\n\n👇🏻 کشور مورد نظر خود را انتخاب کنید";
            }else{
                $platform_name = $this->telegram_model->get_phone_sell_services_one($platId)[0]->name_en;
                $text = "📱 Selected platform: #$platform_name\n\n👇🏻 Select your desired country";
            }
            
        	$arraydata = array(array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array());
            $arraynumber = 0;
        	$jw = 1;
        	for($i = 0; $i < 23; $i++){
        	    if($i == 22){
        	        array_push($arraydata[$arraynumber],array(text=>"$choosPlat",callback_data=>"platforms"));
        	        if($jw % 1 == 0){
                        $arraynumber++;
            	    }
        	    }elseif($i == 21){
        	        array_push($arraydata[$arraynumber],array(text=>"$nextPageKey",callback_data=>"country-next-1-$platId"));
        	        if($jw % 2 == 0){
                        $arraynumber++;
            	    }
        	    }else{
        	        $keyEmoji = json_decode($mycountrys[$i]->emoji, true);
            	    //$price = $infoSort[$i]['amount'];
            	    if($userlang == "fa"){
                        $keyName = $mycountrys[$i]->country." $keyEmoji";
                    }else{
                        $keyName = $mycountrys[$i]->name_en." $keyEmoji";
                    }
                    
                    $keyNameData = "country-".$mycountrys[$i]->id."-plat-$platId";
                    array_push($arraydata[$arraynumber],array(text=>$keyName,callback_data=>$keyNameData));
                    if($jw % 3 == 0){
                        $arraynumber++;
            	    }
        	    }
        		
                $jw++;
            }
        	$keyboard =  array("inline_keyboard" => $arraydata);
            $result = $this->telegram_model->edit_message_key($token,$callback_chatid,$callback_message_id,$text,$keyboard);
        }elseif($ction[0] == "country"){
            //$res = $this->telegram_model->send_message_only($token,'-1001155301071',"callback : ".$callback_message);
            //$res = $this->telegram_model->send_message_only($token,'-1001155301071',"page: ".$ction[4]);
            if($ction[1] == "next"){
                $page_country = $ction[2];
                $platId = $ction[3];
                $start = $page_country*23;
                $end = ($page_country+1)*23+1;
                $nextPage = $page_country+1;
                $prevPage = $page_country-1;
                $mycountrys = $this->telegram_model->get_phone_sell_country();
                //$text = "کشور مورد نظر خود را انتخاب کنید";
                $platform_name = $this->telegram_model->get_phone_sell_services_one($platId)[0]->name;
                if($userlang == "fa"){
                    $text = "📱 پلتفرم انتخاب شده: #$platform_name\n\n👇🏻 کشور مورد نظر خود را انتخاب کنید";
                }else{
                    $text = "📱 Selected platform: #$platform_name\n\n👇🏻 Select your desired country";
                }
                
            	$arraydata = array(array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array());
                $arraynumber = 0;
            	$jw = 1;
            	//$res = $this->telegram_model->send_message_only($token,'-1001155301071',count($mycountrys)."\n\n".$page_country * 21 + 21);
            	for($i = $start; $i < $end; $i++){
            	    if($i == $end-3){
            	        if($page_country * 21 + 42 < count($mycountrys)){
            	            array_push($arraydata[$arraynumber],array(text=>"$nextPageKey",callback_data=>"country-next-$nextPage-$platId-$page_country"));
            	        }else{
            	           $jw++; 
            	        }
            	    }elseif($i == $end-2){
            	        if($page_country * 21 + 42 < count($mycountrys)){
            	            $jw++;
            	        }else{
            	            $jw = $jw+2;
            	        }
            	        
            	        array_push($arraydata[$arraynumber],array(text=>"$prevPageKey",callback_data=>"country-prev-$prevPage-$platId-$page_country"));
            	    }elseif($i == $end-1){
            	        array_push($arraydata[$arraynumber],array(text=>"$choosPlat",callback_data=>"platforms"));
            	    }else{
            	        $keyEmoji = json_decode($mycountrys[$i]->emoji, true);
                	    //$price = $infoSort[$i]['amount'];
                	    if($userlang == "fa"){
                            $keyName = $mycountrys[$i]->country." $keyEmoji";
                        }else{
                            $keyName = $mycountrys[$i]->name_en." $keyEmoji";
                        }
                        
                        $keyNameData = "country-".$mycountrys[$i]->id."-plat-$platId-$page_country";
                        if(strlen($keyName) < 5){
                            $jw++;
                        }else{
                            array_push($arraydata[$arraynumber],array(text=>$keyName,callback_data=>$keyNameData));
                        }
                        
                        if($jw % 3 == 0){
                            $arraynumber++;
                	    }
            	    }
            		if($jw % 3 == 0){
                        $arraynumber++;
            	    }
                    $jw++;
                }
            	$keyboard =  array("inline_keyboard" => $arraydata);
                $result = $this->telegram_model->edit_message_key($token,$callback_chatid,$callback_message_id,$text,$keyboard);
            }
            elseif($ction[1] == "prev"){
                
                //$res = $this->telegram_model->send_message_only($token,'-1001155301071',"prev: ".$callback_message);
                $page_country = $ction[2];
                $platId = $ction[3];
                if($page_country > 6){
                    $page_country = $page_country -1;
                }
                $start = $page_country*23;
                $end = ($page_country+1)*23+1;
                $nextPage = $page_country+1;
                $prevPage = $page_country-1;
                //$res = $this->telegram_model->send_message_only($token,'-1001155301071',"start: ".$start);
                $mycountrys = $this->telegram_model->get_phone_sell_country();
                //$text = "کشور مورد نظر خود را انتخاب کنید";
                $platform_name = $this->telegram_model->get_phone_sell_services_one($platId)[0]->name;
                if($userlang == "fa"){
                    $text = "📱 پلتفرم انتخاب شده: #$platform_name\n\n👇🏻 کشور مورد نظر خود را انتخاب کنید";
                }else{
                    $text = "📱 Selected platform: #$platform_name\n\n👇🏻 Select your desired country";
                }
                
            	$arraydata = array(array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array());
                $arraynumber = 0;
            	$jw = 1;
            	//$res = $this->telegram_model->send_message_only($token,'-1001155301071',count($mycountrys)."\n\n".$page_country * 21 + 21);
            	for($i = $start; $i < $end; $i++){
            	    if($i == $end-3){
            	        if($page_country * 21 + 42 < count($mycountrys)){
            	            array_push($arraydata[$arraynumber],array(text=>"$nextPageKey",callback_data=>"country-next-$nextPage-$platId-$page_country"));
            	        }else{
            	           $jw++; 
            	        }
            	    }elseif($i == $end-2){
            	        if($page_country * 21 + 42 < count($mycountrys)){
            	            $jw++;
            	        }else{
            	            $jw = $jw+2;
            	        }
            	        if($start > 0)
            	        array_push($arraydata[$arraynumber],array(text=>"$prevPageKey",callback_data=>"country-prev-$prevPage-$platId-$page_country"));
            	    }elseif($i == $end-1){
            	        array_push($arraydata[$arraynumber],array(text=>"$choosPlat",callback_data=>"platforms"));
            	    }else{
            	        $keyEmoji = json_decode($mycountrys[$i]->emoji, true);
                	    //$price = $infoSort[$i]['amount'];
                	    if($userlang == "fa"){
                            $keyName = $mycountrys[$i]->country." $keyEmoji";
                        }else{
                            $keyName = $mycountrys[$i]->name_en." $keyEmoji";
                        }
                        $keyNameData = "country-".$mycountrys[$i]->id."-plat-$platId-$page_country";
                        
                        //$res = $this->telegram_model->send_message_only($token,'-1001155301071',"strlen: ".strlen($keyName));
                        if(strlen($keyName) < 5){
                            $jw++;
                        }else{
                            array_push($arraydata[$arraynumber],array(text=>$keyName,callback_data=>$keyNameData));
                        }
                        
                        if($jw % 3 == 0){
                            $arraynumber++;
                	    }
            	    }
            		if($jw % 3 == 0){
                        $arraynumber++;
            	    }
                    $jw++;
                }
            	$keyboard =  array("inline_keyboard" => $arraydata);
                $result = $this->telegram_model->edit_message_key($token,$callback_chatid,$callback_message_id,$text,$keyboard);
            }else{
                $platId = $ction[3];
                $country = $ction[1];
                
                $page_country = $ction[4];
                //$res = $this->telegram_model->send_message_only($token,'-1001155301071',"preve this page: ".$prevPage);
                $myInfo = $this->telegram_model->number_getinfo($platId, $country);
                $myInfo = json_decode($myInfo, true);
                $platform_buy = $this->telegram_model->get_phone_sell_services_one($myInfo[0]['service'])[0]->name;
        	    $country_info = $this->telegram_model->get_phone_sell_country_one($myInfo[0]['country']);
        	    $country_buy = $country_info[0]->country;
        	    $country_buyEmoji = json_decode($country_info[0]->emoji, true);
                $areacode = $country_info[0]->areacode;
                //$this->telegram_model->send_message_only($token,'-1001155301071',"count info: ".count($myInfo));
                if($userlang == "fa"){
                    $text = "✅ اپراتورهای موجود برای #".$platform_buy." در کشور #".str_ireplace(" ","_",$country_buy)." ".$country_buyEmoji."\n🔢 پیش شماره: 00".$areacode."\n⚠️ قیمت‌ها به تومان می‌باشد\n✅";
                }else{
                    $text = " ✅ Available operators for #".$platform_buy." in country #".str_ireplace(" ","_",$country_buy)." ".$country_buyEmoji."\n🔢 Prenumber: 00".$areacode."\n⚠️ Prices are in Tomans\n ✅";
                    $temp_sell_price = $this->telegram_model->get_temp(8);
                    if( time() - $temp_sell_price[0]->content > 3600){
                        
                        $html = file_get_html("https://talakar.com/%d9%82%db%8c%d9%85%d8%aa-%d8%af%d9%84%d8%a7%d8%b1/");
                        $var_td = $html->find('td');
                        $dPrice = $var_td[1]->plaintext;
                        $time_update = $var_td[5]->plaintext;
                        if(strlen($dPrice) > 3){
                            $this->telegram_model->send_message_only($token,'-1001155301071',"this info: ".$dPrice);
                            $data = array("name"=>$dPrice,"content"=>time());
                            $this->telegram_model->update_temp(8,$data);
                        }else{
                            $dPrice = $temp_sell_price[0]->name;
                            $this->telegram_model->send_message_only($token,'-1001155301071',"this 1 info: ".$dPrice);
                            $this->telegram_model->send_message_only($token,'-1001155301071',"قیمت دلار در فروش شماره چک شود");
                        }
                    }else{
                        $dPrice = $temp_sell_price[0]->name;
                        $this->telegram_model->send_message_only($token,'-1001155301071',"this 2 info: ".$dPrice);
                    }
                    $dPrice = $dPrice/10;
                    //$this->telegram_model->send_message_only($token,'-1001155301071',"count info: ".$dPrice);
                    //$this->telegram_model->send_message_only($token,'-1001155301071',"count info: ".$reg_georg);
                    
                }
                
            	$arraydata = array(array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array());
                $arraynumber = 0;
            	$jw = 1;
            	$count_number = 0;
            	for($k = 0; $k < count($myInfo); $k++){
            	    if($myInfo[$k]['count'] > 0){
            	        $count_number++;
            	    }
            	}
            	//$this->telegram_model->send_message_only($token,'-1001155301071',"count info: ".$count_number);
            	if((isset($myInfo['RESULT']) && $myInfo['RESULT'] == 0) || $count_number == 0){
            	    if($userlang == "fa"){
                        $text = "متاسفانه در حال حاضر هیچ اپراتوری در این کشور شماره مجازی ارائه نمی‌دهد";
                    }else{
                        $text = "Unfortunately, currently no operator in this country offers a virtual number";
                    }
            	    
                    $res = $this->telegram_model->send_message_answer_callback($token,$callback_chatid,$callback_id,$text);
            	}else{
            	    for($i = 0; $i < count($myInfo)+2; $i++){
                	    if($i == count($myInfo)+2-1){
                	        $arraynumber++;
                	        array_push($arraydata[$arraynumber],array(text=>"$choosPlat",callback_data=>"platforms"));
                	        
                	    }elseif($i == count($myInfo)+2-2){
                	        $arraynumber++;
                	        //array_push($arraydata[$arraynumber],array(text=>"➡️ صفحه قبل",callback_data=>"1"));
                	        array_push($arraydata[$arraynumber],array(text=>"$prevPageKey",callback_data=>"country-prev-$page_country-$platId"));
                	    }else{
                	        if($myInfo[$i]['count'] > 0 && $myInfo[$i]['count'] !== "?"){
                	            //$this->telegram_model->send_message_only($token,'-1001155301071',"key result: ".$myInfo[$i]['operator']);
                	            
                	            if($userlang == "fa"){
                	                $Buy_price = $myInfo[$i]['amount']+($myInfo[$i]['amount']*20/100);
                	                $Buy_price = $Buy_price < 10000 ? $Buy_price+20000 : $Buy_price;
                	                $Buy_price_f = number_format($Buy_price);
                                    array_push($arraydata[$arraynumber],array(text=>"💳 خرید",callback_data=>"buy-".$myInfo[$i]['service']."-".$myInfo[$i]['country']."-".$myInfo[$i]['operator']."-".$Buy_price)
                                    ,array(text=>"قیمت: ".$Buy_price_f,callback_data=>"buy-".$myInfo[$i]['service']."-".$myInfo[$i]['country']."-".$myInfo[$i]['operator']."-".$Buy_price)
                                    ,array(text=>"اپراتور ".$myInfo[$i]['operator'],callback_data=>"buy-".$myInfo[$i]['service']."-".$myInfo[$i]['country']."-".$myInfo[$i]['operator']."-".$Buy_price));
                                }else{
                                    $Buy_price = $myInfo[$i]['amount']+($myInfo[$i]['amount']*20/100);
                                    $Buy_price = $Buy_price < 10000 ? $Buy_price+20000 : $Buy_price;
                                    $Buy_price = round($Buy_price/$dPrice,2);
                                    
                                    //$Buy_price = round($Buy_price+($Buy_price*10/100));
                                    $Buy_price = $Buy_price+($Buy_price*10/100);
                                    $Buy_price = ceil($Buy_price*2)/2;
                                    if($Buy_price < 1){
                                        $Buy_price = ceil($Buy_price);
                                    }
                                    array_push($arraydata[$arraynumber],array(text=>"💳 buy",callback_data=>"buy-".$myInfo[$i]['service']."-".$myInfo[$i][ 'country']."-".$myInfo[$i]['operator']."-".$Buy_price)
                                    ,array(text=>"Price: ".$Buy_price,callback_data=>"buy-".$myInfo[$i]['service']."-".$myInfo[$i]['country']. "-".$myInfo[$i]['operator']."-".$Buy_price)
                                    ,array(text=>"Operator ".$myInfo[$i]['operator'],callback_data=>"buy-".$myInfo[$i]['service']."-".$myInfo[$i]['country']."-".$myInfo[$i]['operator']."-".$Buy_price));
                                 
                                }
                	            
                                $arraynumber++;
                	        }
                	    }
                    }
                    
                	$keyboard =  array("inline_keyboard" => $arraydata);
                    $result = $this->telegram_model->edit_message_key($token,$callback_chatid,$callback_message_id,$text,$keyboard);
            	}
            }
        }elseif($ction[0] == "platforms"){
            $method = $ction[1];
            $numId = $ction[2];
            $price_back = $ction[3];
            //$this->telegram_model->send_message_only($token,'-1001155301071',"price back:".$price_back);
            if($ction[1] == "cancelnumber" || $ction[1] == "bannumber"){
                $number_info = $this->telegram_model->number_get_code($numId);
                $number_info = json_decode($number_info, true);
                $result = $number_info["RESULT"];
                $code = $number_info["CODE"];
                $number =  $number_info["number"];
                if($result == 2 && $code > 0){
                    $data = array("code"=>$code,"status"=>6);
                    $this->telegram_model->update_phone_sell_order($data, $callback_chatid, $numId);
                    $this->telegram_model->send_message_only($token,$callback_chatid,"getCode1: #$code");
                }else{
                    $is_user = $this->telegram_model->get_phone_sell($callback_chatid);
                    $cancel_res = $this->telegram_model->number_cancell($method ,$numId);
                    $number_info = $this->telegram_model->number_get_code($numId);
                    $number_info = json_decode($number_info, true);
                    $result = $number_info["RESULT"];
                    $code = $number_info["CODE"];
                    $number =  $number_info["number"];
                    if($result != 2 && $result != 6){
                        $data = array("charge"=>($is_user[0]->charge + $price_back));
                        $this->telegram_model->update_phone_sell($callback_chatid,$data);
                        $this->telegram_model->clear_phone_sell_order($callback_chatid,$numId);
                    }else{
                        $this->telegram_model->send_message_only($token,$callback_chatid,"getCode1: #$code");
                    }
                }
            }elseif($ction[1] == "getCode"){
                $order_check = $this->telegram_model->get_phone_sell_order($callback_chatid, $numId);
                $cuTime = time();
                $diff = $cuTime-$order_check[0]->time_use;
                if($diff < 0){
                    //$this->telegram_model->send_message_only($token,'-1001155301071',"time use:".$diff);
                    if(strlen($order_check[0]->code) > 0){
                        if($userlang == "fa"){
                            $this->telegram_model->send_message_only($token,$callback_chatid,"کد موجود برای شما: #".$order_check[0]->code);
                        }else{
                            $this->telegram_model->send_message_only($token,$callback_chatid,"available code for you: #".$order_check[0]->code);
                        }
                        
                    }else{
                        $number_info = $this->telegram_model->number_get_code($numId);
                        //$this->telegram_model->send_message_only($token,'-1001155301071',"get new1:".$number_info);
                        $number_info = json_decode($number_info, true);
                        $result = $number_info["RESULT"];
                        $code = $number_info["CODE"];
                        $number =  $number_info["number"];
                        //$this->telegram_model->send_message_only($token,'-1001155301071',"get new2:".$code);
                        if($result == 2 || $result == 6){
                            $data = array("code"=>$code,"status"=>6);
                            $this->telegram_model->update_phone_sell_order($data, $callback_chatid, $numId);
                            if($userlang == "fa"){
                                $this->telegram_model->send_message_only($token,$callback_chatid,"کد ارسالی برای شما: #$code");
                            }else{
                                $this->telegram_model->send_message_only($token,$callback_chatid,"Code sent to you: #$code");
                            }
                            
                        }else{
                            if($userlang == "fa"){
                                $text = "متاسفانه هنوز کد دریافت نشده است";
                            }else{
                                $text = "Unfortunately, the code has not been received yet";
                            }
                            
                            $res = $this->telegram_model->send_message_answer_callback($token,$callback_chatid,$callback_id,$text);
                            //$this->telegram_model->send_message_only($token,'-1001155301071',"getCode4: not recive");
                            die();
                        }
                    }
                }else{
                    if($userlang == "fa"){
                        $text = "متاسفانه زمان استفاده به پایان رسیده است";
                    }else{
                        $text = "Unfortunately, the usage time has expired";
                    }
                    
                    $res = $this->telegram_model->send_message_answer_callback($token,$callback_chatid,$callback_id,$text);
                    die();
                }
            }
            //else{
                $arraydata = array();
                $myNumServices = $this->telegram_model->get_phone_sell_services();
                $name_need = ["Telegram","Instagram","whatsapp","viber","wechat","google","facebook","twitter","microsoft","line","yahoo","beetalk","linkedin","amazon","netflix","discord","apple","Blizzard","signal","Tango","Likee","tiktok"];
                $emoji_need = array("tiktok"=>"📱","signal"=>"📡","Tango"=>"👥","discord"=>"🗣","apple"=>"🍎","Blizzard"=>"🕹","linkedin"=>"📇","amazon"=>"🛒","netflix"=>"🎞","line"=>"💬","yahoo"=>"📨",
                                    "beetalk"=>"🐝","facebook"=>"👤","twitter"=>"🐦","microsoft"=>"💻","viber"=>"💬","wechat"=>"💬","google"=>"🔍","Telegram"=>"💎","Instagram"=>"📸","whatsapp"=>"📞");
                if($userlang == "fa"){
                    $text = "🔘 میخواهید در چه برنامه ای ثبت نام کنید؟ سرویس یا اپلیکیشن مورد نظر خود را انتخاب کنید 👇🏻\n\n⚠️ در انتخاب سرویس دقت کنید! زیرا کد تایید ارسالی بر اساس سرویس دسته بندی خواهد شد";
                }else{
                    $text = "What program do you want to register for? Choose the service or application you want 👇🏻\n\n⚠️ Be careful in choosing the service! Because the confirmation code sent will be categorized according to the service";
                }
                
                $keyName = "";
            	$arraydata = array(array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array());
                $arraynumber = 0;
            	$jw = 1;
            	for($i=0;$i<45;$i++){
        	        if($myNumServices[$i]->name == "دیگـر سرویـس‌ها"){
        	            continue;
        	        }else{
        	            if(in_array($myNumServices[$i]->name_en, $name_need)){
        	                $keyId = $myNumServices[$i]->id;
        	                if($myNumServices[$i]->active == "1"){
        	                    $emoji = $emoji_need[$myNumServices[$i]->name_en];
        	                    if($userlang == "fa"){
        	                        if($myNumServices[$i]->name == "جیمیل - گوگل - یوتیوب"){
                    	                $keyName = "گوگل";
                    	                //$this->telegram_model->send_message_only($token,'-1001155301071',$myNumServices[$i]->active );
                        	        }elseif($myNumServices[$i]->name == "Tango"){
                        	            $keyName = "تانگو";
                        	        }else{
                        	            $keyName = str_ireplace("ـ","",$myNumServices[$i]->name);
                        	        }
        	                    }else{
        	                        $keyName = $myNumServices[$i]->name_en;
        	                    }
        	                    
                    	        $keyName = $keyName." $emoji";
                    	        $keyNameData = "service-$keyId";
                                array_push($arraydata[$arraynumber],array(text=>$keyName,callback_data=>$keyNameData));
                                if($jw % 3 == 0){
                                    $arraynumber++;
                        	    }
                                $jw++;
        	                }
            	            
            	        }
        	        }
                }
            	$keyboard =  array("inline_keyboard" => $arraydata);
            	//$result = $this->telegram_model->send_message($token,$chatid1,$text,$keyboard);
            	$result = $this->telegram_model->edit_message_key($token,$callback_chatid,$callback_message_id,$text,$keyboard);
            	$result1 = json_decode($result, true);
            	//$text = "لطفا یکی از موارد را انتخاب کنید";
            	//$keyboard = array("keyboard" => array(array("💳 شارژ حساب","🏠 خانه")),"resize_keyboard"=>true);
                //$result = $this->telegram_model->send_message($token,$callback_chatid,$text,$keyboard);
                //$this->telegram_model->send_message_only($token,'-1001155301071',$result);
            //}
            
        }
        elseif($ction[0] == "buy"){
            $service = $ction[1];
            $country = $ction[2];
            $operator = $ction[3];
            $price = $ction[4];
            //$this->telegram_model->send_message_only($token,'-1001155301071',"buy price 2: ".$price);
            //die();
            $is_user = $this->telegram_model->get_phone_sell($callback_chatid);
            $thisLang = $this->telegram_model->get_phone_sell_lang($callback_chatid);
            if($thisLang == "fa"){
                $charge = $is_user[0]->charge;
            }else{
                $charge = $is_user[0]->charge_en;
            }
            if($charge >= $price){
                
                $newNumber = $this->telegram_model->number_get($service, $country, $operator);
                $this->telegram_model->send_message_only($token,'-1001155301071',"number res: ".$newNumber);
                $newNumber = json_decode($newNumber, true);
                $this->telegram_model->send_message_only($token,'-1001155301071',"number res ID: ".$newNumber["ID"]);
                $res = $newNumber["RESULT"];
                $number = $newNumber["NUMBER"];
                $numId = $newNumber["ID"];
                $this->telegram_model->send_message_only($token,'-1001155301071',"number res ID: ".$numId);
                $areaCode = $newNumber["AREACODE"];
                $timeUse = $newNumber["TIME"];
                $cuTime = time();
                if($res != 1){
                    if($userlang == "fa"){
                        $text = "در حال حاضر سرویس این اپراتور با اختلال مواجه است. لطفا یک اپراتور دیگر یا کشور دیگری انتخاب کنید";
                    }else{
                        $text = "The service of this operator is currently interrupted. Please choose another operator or another country";
                    }
                    
                    $res = $this->telegram_model->send_message_answer_callback($token,$callback_chatid,$callback_id,$text);
                }
                elseif($res == 1){
                    if($userlang == "fa"){
                        $data = array("charge"=>($is_user[0]->charge - $price));
                    }else{
                        $data = array("charge_en"=>($is_user[0]->charge_en - $price));
                    }
                    
                    $this->telegram_model->update_phone_sell($callback_chatid,$data);
                    if($userlang == "fa"){
                        $keyName = ["لغو و اعلام مسدود","لغو"];
                    }else{
                        $keyName = ["Cancel and Ban","Cancel"];
                    }
                    
                    $text = "شماره شما: $number\nپیش شماره: $areaCode\nمدت زمان قابل استفاده: $timeUse\nدر صورتیکه در زمان مشخص شده از شماره استفاده نکنید هزینه مسترد نمی‌گردد";
                	$arraydata = array(array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array(),array());
                    $arraynumber = 0;
                	$jw = 1;
                	for($i = 0; $i < 3; $i++){
                	    if($i == 2){
                	        array_push($arraydata[$arraynumber],array(text=>"دریافت کد",callback_data=>"platforms-getCode-$numId"));
                	        if($jw % 1 == 0){
                                $arraynumber++;
                    	    }
                	    }else{
                	        if($keyName[$i] == "Cancel" || $keyName[$i] == "لغو"){
                	            $method = "cancelnumber";
                	        }else{
                	            $method = "bannumber";
                	        }
                            array_push($arraydata[$arraynumber],array(text=>$keyName[$i],callback_data=>"platforms-$method-$numId-$price"));
                            if($jw % 2 == 0){
                                $arraynumber++;
                    	    }
                	    }
                		
                        $jw++;
                    }
                    $timeUse = explode(":",$timeUse);
                    $timeUse = $timeUse[1]*60+$timeUse[2]+$cuTime;
                    $data = array("telid"=>$callback_chatid,"platform"=>$service,"country"=>$country,"number"=>$number,"num_id"=>$numId,"time_use"=>$timeUse,"time_buy"=>$cuTime,"price"=>$price,"status"=>1);
                    $this->telegram_model->set_phone_sell_order($data);
                	$keyboard =  array("inline_keyboard" => $arraydata);
                    $result = $this->telegram_model->edit_message_key($token,$callback_chatid,$callback_message_id,$text,$keyboard);
                }
            }else{
                if($userlang == "fa"){
                    $text = "موجودی حساب شما کافی نیست. لطفا اول حساب خود را شارژ کنید";
                }else{
                    $text = "Your account balance is insufficient. Please top up your account first";
                }
                
                $res = $this->telegram_model->send_message_answer_callback($token,$callback_chatid,$callback_id,$text);
            }
            //$this->telegram_model->send_message_only($token,'-1001155301071',"key buy - $service - $country - $operator");
        }/*elseif($ction[0] == "getCode"){
            
            $number_info = $this->telegram_model->number_get_code($id);
            $number_info = json_decode($number_info, true);
            $result = $number_info["RESULT"];
            $code = $number_info["CODE"];
            $number =  $number_info["number"];
            if($result == 1 && $code > 0){
                $this->telegram_model->send_message_only($token,'-1001155301071',"getCode1: $code");
            }else{
                $this->telegram_model->send_message_only($token,'-1001155301071',"getCode2: $code");
            }
            
        }*/
        
    }
    
}   

if($message == "num" && $chatid1 == '-1001155301071'){
    /*$myNumtimeUpdate = $this->telegram_model->get_temp(7);
    if(time()-$myNumtimeUpdate[0]->content > 3600){
        $data = array();
        $this->telegram_model->send_message_only($token,'-1001155301071',time()-$myNumServices[0]->time." this");
        $numservices = $this->telegram_model->number_getservices();
        $numservices = json_decode($numservices, true);
        for($i = 0; $i < count($numservices); $i++){
            $data[$i] = array('name' => $numservices[$i]['name'],"name_en"=>$numservices[$i]['name_en'],"description"=>$numservices[$i]['description'],"image"=>$numservices[$i]['image'],"active"=>$numservices[$i]['active']);
        }
        $result = $this->telegram_model->update_phone_sell_services_batch($data);
        $this->telegram_model->send_message_only($token,'-1001155301071',"save service: ".$result);
        //------------------
        $data = array();
        $numcountry = $this->telegram_model->number_getcountry();
        $numcountry = json_decode($numcountry, true);
        foreach($numcountry as $key => $value){
          $numcountry[$key]['emoji'] = json_encode($numcountry[$key]['emoji']);
        }
        for($i = 0; $i < count($numcountry); $i++){
            $data[$i] = array('country' => $numcountry[$i]['name'],"name_en"=>$numcountry[$i]['name_en'],"areacode"=>$numcountry[$i]['areacode'],"emoji"=>$numcountry[$i]['emoji'],"active"=>$numcountry[$i]['active']);
        }
        $result = $this->telegram_model->update_phone_sell_country_batch($data);
        $this->telegram_model->send_message_only($token,'-1001155301071',"save country res: ".$result);
    }*/
    
    /*$myNumInfo = $this->telegram_model->get_phone_sell_country();
    if(time()-$myNumInfo[0]->time > 3600){
        $info = $this->telegram_model->number_getinfo($service);
        //$data = array("country"=>$numcountry,"time"=>time());
        //$result = $this->telegram_model->set_phone_sell_country($data);
        //$this->telegram_model->send_message_only($token,'-1001155301071',"save country: ".$result);
    }*/
    
}