<?php
//کرونجاب یک دقیه ای ست کنید
include '../botseen6.5.php';
include '../config.php';
//=======================================================
$send = mysqli_fetch_assoc(mysqli_query($connect,"SELECT * FROM `sendall` LIMIT 1"));
$daily = mysqli_fetch_assoc(mysqli_query($connect,"SELECT * FROM `daily` LIMIT 1"));
//======================// send //=======================
if($send['step'] == 'send'){
$alluser = mysqli_num_rows(mysqli_query($connect,"select id from `user`"));
$users = mysqli_query($connect,"SELECT id FROM `user` LIMIT 100 OFFSET {$send['user']}");
if($send['chat'] == false){
while($row = mysqli_fetch_assoc($users))
     bot('sendmessage',[
        'chat_id'=>$row['id'],        
		'text'=>$send['text'],
        ]);	
}else{
while($row = mysqli_fetch_assoc($users))
  bot('sendphoto',[
	'chat_id'=>$row['id'],
	'photo'=>$send['chat'],
	'caption'=>$send['text'],
 ]);
}
$connect->query("UPDATE `sendall` SET `user` = `user` + 100 LIMIT 1");
if($send['user'] + 100 >= $alluser){
  bot('sendmessage',[
      'chat_id'=>$admin[0],
      'text'=>"📍 پیام برای همه کابران ارسال شد",
 ]);
$connect->query("UPDATE `sendall` SET `step` = 'none' , `text` = '' , `user` = '0' , `chat` = '' LIMIT 1");	
}
}
//======================// forward //=======================
elseif($send['step'] == 'forward'){
$alluser = mysqli_num_rows(mysqli_query($connect,"select id from `user`"));
$users = mysqli_query($connect,"SELECT id FROM `user` LIMIT 100 OFFSET {$send['user']}");
while($row = mysqli_fetch_assoc($users))
bot('ForwardMessage',[
'chat_id'=>$row['id'],   
'from_chat_id'=>$send['chat'],
'message_id'=>$send['text'],
]);	
$connect->query("UPDATE `sendall` SET `user` = `user` + 100 LIMIT 1");
if($send['user'] + 100 >= $alluser){
  bot('sendmessage',[
      'chat_id'=>$admin[0],
      'text'=>"📍 پیام برای همه کابران فوروارد شد",
 ]);
$connect->query("UPDATE `sendall` SET `step` = 'none' , `text` = '' , `user` = '0' , `chat` = '' LIMIT 1");		
}
}
//======================// daily user //=======================
elseif($daily['time'] < date("Y-m-d H:i:s")){
$users = mysqli_num_rows(mysqli_query($connect,'select `id` from `user`'));
$userlimit = mysqli_query($connect,"SELECT id FROM `user` LIMIT 100 OFFSET {$daily['user']}");
while($row = mysqli_fetch_assoc($userlimit))
	bot('sendmessage',[
	'chat_id'=>$row['id'],
	'text'=>$start,
    'reply_markup'=>$channelorderkey
    		]);
$connect->query("UPDATE `daily` SET `user` = `user` + 100 LIMIT 1");
if($daily['user'] + 100 >= $users){
$time = date("Y-m-d H:i:s", strtotime("+7 day"));
$connect->query("UPDATE `daily` SET `time` = '$time' , `user` = '0' LIMIT 1");
}
}
//======================// Order Seen //=======================
$orderseen = mysqli_query($connect,"SELECT * FROM `orderseen` WHERE `stats` = '0'");
while($row = mysqli_fetch_assoc($orderseen)) {
	$result = curl("$webapi/api.php?apikey=$apikey&type=status&id={$row['key']}");

	if($result->stats==1){
	$exlink = explode('/', $row['link']);
    $channelorder = $exlink[count($exlink) - 2];
    $id = end($exlink);
    bot('sendmessage',[
	'chat_id'=>$row['id'],
    'text'=>"✅ سفارش بازدید با شماره پیگیری {$row['key']} با موفقیت #تکمیل شد .

⚡️ سرعت تکمیل : {$row['speed']}
⏱ زمان : {$row['time']}
💰 هزینه سفارش : {$row['amount']} تومان
👁‍🗨 تعداد بازدید درخواستی : {$row['view']}
",
            ]);	
    $connect->query("UPDATE `orderseen` SET `stats` = '1' WHERE `key` = '{$row['key']}' LIMIT 1");
	}
}
//==============================================================//

?> 