JOIN REQUEST AUTO-APPROVE BOT  v2  (PHP + MySQL, cPanel ready)
==============================================================

PEHLE SE CHALTE BOT KO UPDATE KARNA HO (upgrade)
1. Backup lo: folder download + phpMyAdmin se database export.
2. Is zip ki saari files apne joinbot folder me upload karo (overwrite = Yes).
   ✅ app/config.php ko mat chhedo — zip me config.php hai hi nahi (sirf config.sample.php hai).
3. Owner account se bot ko /start bhejo. Nayi tables/columns apne aap ban jate hain
   (purana data safe rehta hai). Koi error ho to app/error.log dekho.
4. Cron job pehle jaisa hi rahega (har minute cron.php). Webhook dobara set karne ki zaroorat nahi.
5. Ab admin ke liye /start ya /help bhejo — saari commands dikhengi.

NAYA INSTALL (fresh)
1. @BotFather se bot banao -> token lo. Apni numeric ID @userinfobot se lo.
2. cPanel me MySQL database + user banao.
3. Pura folder upload karo. app/config.sample.php ka naam app/config.php karke sab details bharo.
4. Browser me kholo:  https://yourdomain.com/joinbot/setup.php?key=TUMHARI_CRON_KEY
   -> tables + webhook set. Phir setup.php DELETE kar do.
5. cPanel -> Cron Jobs -> har minute:
   * * * * * /usr/local/bin/php /home/USERNAME/public_html/joinbot/cron.php >/dev/null 2>&1

==============================================================
V2 ME NAYA KYA HAI
==============================================================
1) ADMIN /start: saari commands + unka kaam dikhta hai. "👑 Admin Panel" button bhi milta hai.
   Telegram ke "/" menu me bhi admin ko apni commands dikhti hain.

2) SAARI COMMANDS STEP-BY-STEP (ek line me kuch likhna nahi):
   /add       -> user ki chat ID (ya @username) -> plans ke buttons -> click = plan active
   /deduct    -> user ID -> confirm button
   /user      -> user ID -> detail + quick buttons (Plan Add / Deactivate / Ban / Unban)
   /ban /unban            -> user ID -> confirm
   /banchannel /unbanchannel -> channels ki list (buttons) ya chat ID -> confirm
   /setplan   -> naam -> price -> channels (buttons) -> days (buttons)
   /plan /delplan         -> list / delete (confirm ke saath)
   /admin (sirf owner)    -> sub-admins add / remove buttons se
   (Purane one-line format ab bhi chalte hain, par zaroori nahi.)

3) /broadcast  (admin) — bot ke saare users ko (hazaar ho ya lakh)
   Image? Yes/No -> description -> Buttons? Yes/No -> button naam -> link -> colour
   (🔴 Red / 🟢 Green / 🔵 Blue / ⚪ Default) -> aur button? -> PREVIEW
   Preview ke neeche: ✅ Send | ✏️ Edit | ❌ Cancel
   Edit me: Description / Image / Buttons / Pura Edit. Buttons me jitne hain utne dikhte hain —
   jis par click karo wahi edit hota hai (baaki same rehte hain).
   Send ke baad background me chalta hai (cron ke saath ~1,500 msg/min, Telegram limit ke andar).
   Complete hone par report aati hai (sent / failed). "🛑 Stop" button se rok sakte ho.
   (/boardcast likhne par bhi chalega.)

4) /stats (admin) — Total active plans, Total users, Active plan users, Today / Last 7 days / Month sale,
   Total channels, Total requests (accept + pending). Neeche buttons:
   📢 Total Channel | 👥 Total User | 📨 Total Request | 📗 Excel Export | 📕 PDF Export

   /totalchannel — har channel ka link, members, kitni requests accept hui, pending (ek page me 10, Prev/Next)
   /totaluser    — saare bot users (ek page me 15, Prev/Next)
   /totalreq     — accept hui requests: user + kis channel ki (Prev/Next)
   Export: Excel (.xlsx — Summary, Plans, Channels, Users, Requests, Sales) ya PDF (summary + channels + sales).
   Excel me users/requests ki last 20,000 rows aati hain.

5) PLAN WALE CLIENTS KE LIYE
   /mystats (ya 📊 My Stats button): plan, channels used/limit, total join users, requests accept,
   channel-wise users, alert reach.
   /alert (ya 📣 Alert button): sirf apne channel(s) se join hue users ko message.
   Same flow: image -> text -> buttons (colour) -> preview -> send.
   Spam se bachne ke liye ek alert ke baad ALERT_COOLDOWN_MIN (default 30 min) ruknna padta hai.

6) COLOURED BUTTONS: bot ke menu / actions me blue-green-red buttons. Agar kisi Telegram version par
   colour support na ho to bot khud bina colour ke chalne lagta hai (app/nostyle.flag banta hai).
   Colours band karne ke liye config.php me: define('BTN_STYLES', false);

7) OLD REQUESTS wala feature hata diya gaya hai (abhi ke liye). Request Settings me ab sirf
   "Auto-approve ON/OFF" hai. OFF / plan expire me bot requests ko chhedta nahi.

8) Bot strong banaya: crash-safe broadcast queue (resume ho jata hai), parallel sending, auto-block
   detection, error log, ek jagah se sab errors catch, auto DB upgrade.

==============================================================
ZAROOR PADHO — ALERT / BROADCAST KI TELEGRAM LIMIT
==============================================================
Telegram bot ko wahi user message karne deta hai jisne bot start kiya ho, ya jisse bot ne join request
accept karte waqt welcome DM bheja ho. Isliye /alert sirf unhi tak pahunchta hai (stats me "Alert pahunch sakta hai"
wala number). Jyada reach ke liye client ko welcome message (💬 Set Message) zaroor set karwao.
Jo users bot block kar dete hain unhe bot khud next broadcast se hata deta hai.

PLAN KAISE ACTIVATE KARE
 /add -> user ID -> plan par click. Dubara /add karne par days purane expiry me add hote hain (renewal).

SECURITY
 - Webhook sirf Telegram ke secret-token header se chalta hai (baaki sab 403)
 - Sab SQL prepared statements; user ka text HTML-escape hota hai
 - app/ folder .htaccess se web par band hai (error.log bhi usi me)
 - Admin commands sirf owner / sub-admins; /admin sirf owner
 - Bot token / DB password kisi ko mat bhejo. Leak ho jaye to BotFather me /revoke karo.

CRON KYA KARTA HAI
 expiry message | network error wali requests retry | broadcast / alert queue | purani entries safai

FILES
 webhook.php, cron.php, setup.php  — root
 app/boot.php, db.php, tg.php, util.php, join.php, stats.php, export.php, broadcast.php,
 app/user_flow.php, admin_flow.php, schema.sql, config.sample.php, .htaccess
