<?php
/**
 * @package     JohnCMS
 * @link        http://johncms.com
 * @copyright   Copyright (C) Clever
 * @author      http://t.me/clever_software
 */

defined('_IN_JOHNADM') or die('Error: restricted access');
if ($rights != 9) {
	echo '<div class="rmeni">Error! Error! Error!</div>';
	require('../incfiles/end.php');
	exit;
}
switch ($mod) {
	default:
		echo '<div class="phdr"><a href="/panel/index.php">Boshqaruv panel</a> | E`lon berish</div>';
		echo '<div class="list1">';
		echo'<form action="index.php?act=elon&amp;mod=send" method="POST">
		Kimdan:<br/><select name="sysadm"><option value="1">ID:1</option></select><br/>
		Kimga:<br/><select name="whom"><option value="1">hamma</option><option value="2">yigitlar</option><option value="3">qizlar</option><option value="4">administratsiya</option></select><br />';
		echo "E`lon manzili:<br /><input type='text' name='url' value='http://' /><br />\n";
		echo 'E`lon haqida ma`lumot:<br /><textarea name="message" cols="30" rows="5"></textarea> <br />
		<input type="submit" name="submit" value="Yuborish" /> </form></div>';
	break;

	case 'send':
        $message = isset($_POST['message']) ? functions::checkin(mb_substr(trim($_POST['message']), 0, 5000)) : '';
        $sysadm = isset($_POST['sysadm']) ? functions::checkin(mb_substr(trim($_POST['sysadm']), 0, 1)) : '';
        $whom = isset($_POST['whom']) ? functions::checkin(mb_substr(trim($_POST['whom']), 0, 1)) : '';
        $url = isset($_POST['url']) ? functions::checkin(mb_substr(trim($_POST['url']), 0, 256)) : '';
		if (empty($message)) {
			echo '<div class="rmenu">Siz bo\'sh xabar yubora olmaysiz!</div>';
			require('../incfiles/end.php');
			exit;
		}
		if ($whom == 1) {
			$userid = mysql_query("SELECT `id` FROM `users` WHERE `lastdate` > '" . (time() - 1209600) . "'");
		} elseif ($whom == 2) {
			$userid = mysql_query("SELECT `id` FROM `users` WHERE `sex` = 'm' AND `lastdate` > '" . (time() - 2592000) . "'");
		} elseif ($whom == 3) {
			$userid = mysql_query("SELECT `id` FROM `users` WHERE `sex` = 'zh' AND `lastdate` > '" . (time() - 2592000) . "'");
		} elseif ($whom == 4) {
			$userid = mysql_query("SELECT `id` FROM `users` WHERE `rights` != '0'");
		}
		$i = 0;
		while ($who = mysql_fetch_array($userid)) {
			if ($sysadm == 0) {
				$sys = 1;
			} else {
				$sys = 0;
			}
			$ank = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '$sysadm'"));
			$img ="";
			$name = '<a href="/users/profile.php?user='.$ank['id'].'"><b>' . $ank['name'] . '</b></a>';
			$comm = "";
			mysql_query("INSERT INTO `notification` (`img`, `user_id`, `name`, `ank_id`, `type`, `comm`, `url`, `text`, `time`, `read`) 
			VALUES('$img', '$who[id]', '$name', '$ank[id]', 'har_xil', '$comm', '$url', '$message', '" . time() . "', '1')");
			$i++;
		}
		echo '<div class="phdr>Natijalar:</div><div class="list2">E`loningiz '.$i.' nafar foydalanuvchiga yetkazildi.</div>';
	break;
}
?>