<?

/* Nulled by Wizzywig */
/***********تعريب***********/
/**          saher        **/
/**  منتديات شباب وصبايا  **/
/**   www.shababtop.com   **/
/**  saher1986@live.com   **/
/***************************/
	session_start();
	require_once ("../includes/data_core.php");
	require_once ("includes/functions_update.php");

	// Check Admin is Logged In
	require_once ("includes/functions_login.php");
	
	// Get the page to process
	if (!empty($_GET['do']))
		$do = $_GET['do'];
	else
		$do = "manageusers";

	// Ban IP Submit Processor
	if (isset($_POST['ban_ip_submit']) || isset($_POST['ban_ip_submit_x'])) {
		$ip_addys = split("[\n]", $_POST['ban_ip']);
		foreach ($ip_addys as $addy) {
			$sql = "SELECT ban_ip FROM arrowchat_banlist WHERE ban_ip='".$addy."'";
			$result = mysql_query($sql);
			if ($result && mysql_num_rows($result) > 0) {
				$error = "هذا الـ IP محظور سابقًا.";
			}
			
			if (empty($error)) {
				$sql = "INSERT INTO arrowchat_banlist (ban_ip) VALUES ('".$addy."')";
				$result = mysql_query($sql);
				if (!$result) {
					$error = "هناك خطأ بالاتصال بقاعدة البيانات. يرجى المحاولة مرة أخرى.";
				}
			}
		}
		
		if (empty($error)) {
			$msg = "تم حظر الـ IP بنجاح.";
			update_config_file();
		}
	}
	
	// Unban IP Submit Processor
	if (isset($_POST['unban_ip_submit']) || isset($_POST['unban_ip_submit_x'])) {
		$ips = $_POST['unban_ip'];
		if ($ips) {
			foreach ($ips as $unbans) {
				$sql = "DELETE FROM arrowchat_banlist WHERE ban_id='".$unbans."'";
				$result = mysql_query($sql);
				if (!$result) {
					$error = "هناك خطأ بالاتصال بقاعدة البيانات.";
				}
			}
			if (empty($error)) {
				$msg = "تم إلغاء الحظر عن عناوين الـ IP بنجاح.";
				update_config_file();
			}
		} else {
			$error = "لم تختر أي عناوين IP";
		}
	}
	
	// Ban Username Submit Processor
	if (isset($_POST['ban_username_submit']) || isset($_POST['ban_username_submit_x'])) {
		$usernames = split("[\n]", $_POST['ban_username']);
		foreach ($usernames as $username) {
			$sql = "SELECT ".DB_USERTABLE_USERID." FROM ".TABLE_PREFIX.DB_USERTABLE." WHERE LOWER(".DB_USERTABLE_NAME.")='".strtolower($username)."'";
			$result2 = mysql_query($sql);
			$row2 = mysql_fetch_array($result2);
			if (!$result2 || mysql_num_rows($result2) < 1) {
				$error = "لم يتم العثور على عضو بهذا الإسم.";
			}
			
			$sql = "SELECT ban_userid FROM arrowchat_banlist WHERE ban_userid='".$row2[DB_USERTABLE_USERID]."'";
			$result = mysql_query($sql);
			if ($result && mysql_num_rows($result) > 0) {
				$error = "الإسم محظور مسبقًا.";
			}
			
			if (empty($error)) {
				$sql = "INSERT INTO arrowchat_banlist (ban_userid) VALUES ('".$row2[DB_USERTABLE_USERID]."')";
				$result = mysql_query($sql);
				if (!$result) {
					$error = "هناك خطأ بالاتصال بقاعدة البيانات. يرجى المحاولة مرة أخرى.";
				}
			}
		}
		
		if (empty($error)) {
			$msg = "تم حظر الأسماء بنجاح.";
			update_config_file();
		}
	}
	
	// Unban Username Submit Processor
	if (isset($_POST['unban_username_submit']) || isset($_POST['unban_username_submit_x'])) {
		$usernames = $_POST['unban_username'];
		if ($usernames) {
			foreach ($usernames as $unbans) {
				$sql = "DELETE FROM arrowchat_banlist WHERE ban_id='".$unbans."'";
				$result = mysql_query($sql);
				if (!$result) {
					$error = "هناك خطأ بالاتصال بقاعدة البيانات.";
				}
			}
			if (empty($error)) {
				$msg = "تم إلغاء الحظر عن الأسماء بنجاح.";
				update_config_file();
			}
		} else {
			$error = "لم تختر أي عناوين IP";
		}
	}
?>

<? require ("includes/pages_header.php"); ?>

<?
	if (!empty($msg)) {
?>
			<div dir="rtl" class="success"> 
				<div dir="rtl" style="font-weight: bold;">تم بنجاح:</div> 
				<?=$msg?>
			</div> 
<?
	}
?>
<?
	if (!empty($error)) {
?>
			<div dir="rtl" class="error"> 
				<div dir="rtl" style="font-weight: bold;">عذرًا !! كان هناك خطأ:</div> 
				<?=$error?>
			</div> 
<?
	}
?>

			<div dir="rtl" class="title_bg"> 
				<div dir="rtl" class="title">الأعضاء</div> 
				<div dir="rtl" class="module_content">
<?
	if ($do == "logs") {
?>
					<form method="post" action="users.php?do=manageusers" enctype="multipart/form-data">
					<img src="images/icons/address_32.png" alt="" border="0" />&nbsp;<div dir="rtl" class="subtitle">إدارة الأعضاء</div><br />
					<table dir="rtl" cellspacing="0" cellpadding="0" class="module_table">
						<tr>
							<td dir="rtl" style="width: 150px;">البحث عن الأعضاء:</td>
							<td><input type="text" name="username" /></td>
						</tr>
					</table>
					
					<p dir="rtl" class="submit">
						<input type="submit" name="user_search" class="button-primary" value="بـحـث" />
					</p>
<?
		if (!empty($_REQUEST['w'])) {
?>
					</form>

				</div>
			</div>
			<div dir="rtl" class="title_bg"> 
				<div dir="rtl" class="title">محادثة</div> 
				<div dir="rtl" class="module_content">
					<form method="post" action="<?=$_SERVER['PHP_SELF']?>?do=<?=$_GET['do']?>" enctype="multipart/form-data">
					<div dir="rtl" style="height: 300px; overflow: auto;" id="chatboxes">
<?
			$sql = "SELECT * FROM arrowchat WHERE (arrowchat.to='".mysql_real_escape_string($_REQUEST['w'])."' && arrowchat.from='".mysql_real_escape_string($_REQUEST['id'])."') || (arrowchat.to='".mysql_real_escape_string($_REQUEST['id'])."' && arrowchat.from='".mysql_real_escape_string($_REQUEST['w'])."') ORDER BY id ASC";
			$result = mysql_query($sql);
			$sql = "SELECT ".DB_USERTABLE_NAME.", ".DB_USERTABLE_USERID." FROM ".TABLE_PREFIX.DB_USERTABLE." WHERE ".DB_USERTABLE_USERID."='".$_REQUEST[w]."'";
			$result2 = mysql_query($sql);
			$sql = "SELECT ".DB_USERTABLE_NAME.", ".DB_USERTABLE_USERID." FROM ".TABLE_PREFIX.DB_USERTABLE." WHERE ".DB_USERTABLE_USERID."='".$_REQUEST[id]."'";
			$result3 = mysql_query($sql);
			if ($result && mysql_num_rows($result) > 0) {
				$row2 = mysql_fetch_array($result2);
				$row3 = mysql_fetch_array($result3);
				while ($row = mysql_fetch_array($result)) {
					if ($row['from'] == $_REQUEST['w']) {
?>					
						<div dir="rtl" style="padding:5px 10px 5px 0px; float: right; background-color: #f3f3f3; width: 523px;"><a href="users.php?do=logs&id=<?=$_REQUEST['w']?>"><b><?=$row2[DB_USERTABLE_NAME]?></b></a>: <?=$row['message']?></div><div dir="rtl" style="padding:5px 0px; float: right; background-color: #f3f3f3; width: 150px;"><?=date('M j, Y g:i a', $row['sent'])?></div><div dir="rtl" class="clear"></div>
<?
					} else {
?>
						<div dir="rtl" style="padding:5px 0px; float: right"><a href="users.php?do=logs&id=<?=$_REQUEST['id']?>"><b><?=$row3[DB_USERTABLE_NAME]?></b></a>: <?=$row['message']?></div><div dir="rtl" style="float: right; width: 150px;"><?=date('M j, Y g:i a', $row['sent'])?></div><div dir="rtl" class="clear"></div>
<?
					}
?>
<?
				}
			} else {
?>
				عفوًا !! لم يتم العثور على اي محادثات من أو إلى هؤلاء الأعضاء.
<?
			}
?>
					</div>
			<script type="text/javascript">
				var objDiv = document.getElementById("chatboxes");
				objDiv.scrollTop = objDiv.scrollHeight;
			</script>
<?
		}
?>
<?
		if (!empty($_REQUEST['id'])) {
			$sql = "SELECT ".DB_USERTABLE_NAME.", ".DB_USERTABLE_USERID." FROM ".TABLE_PREFIX.DB_USERTABLE." WHERE ".DB_USERTABLE_USERID."='".$_REQUEST[id]."'";
			$result = mysql_query($sql);
?>
					</form>

				</div>
			</div>
			<div dir="rtl" class="title_bg"> 
				<div dir="rtl" class="title">السجل</div> 
				<div dir="rtl" class="module_content">
					<form method="post" action="<?=$_SERVER['PHP_SELF']?>?do=<?=$_GET['do']?>" enctype="multipart/form-data">
					<table dir="rtl" cellspacing="0" cellpadding="0" class="module_table">
<?
			if ($result && mysql_num_rows($result) > 0) {
				$row = mysql_fetch_array($result);
?>

						<tr>
							<td><b><?=$row[DB_USERTABLE_NAME]?></b> (<a href="users.php?do=view&id=<?=$_REQUEST[id]?>">تعديل</a>)</td>
						</tr>
						<tr>
<?
				$sql = "SELECT arrowchat.to FROM arrowchat WHERE arrowchat.from='".$_REQUEST[id]."' GROUP BY arrowchat.to";
				$result2 = mysql_query($sql);
				$i = 1;
				if ($result2 && mysql_num_rows($result2) > 0) {
					while ($row2 = mysql_fetch_array($result2)) {
						$sql = "SELECT ".DB_USERTABLE_NAME." FROM ".TABLE_PREFIX.DB_USERTABLE." WHERE ".DB_USERTABLE_USERID."='".$row2[to]."'";
						$result3 = mysql_query($sql);
						$row3 = mysql_fetch_array($result3);
?>
							<td dir="rtl" style="width:175px; text-align: center;"><a href="users.php?do=logs&id=<?=$_REQUEST[id]?>&w=<?=$row2['to']?>"><?=$row3[DB_USERTABLE_NAME]?></a></td>
<?
						if ($i%4 == 0) {
?>
						</tr>
						<tr>
<?
						}
?>
<?
						$i++;
					}
				} else {
?>
						<td>هذا العضو لم يقم أبدًا بأي محادثة.</td>
<?
				}
			} else {
?>
						لايوجد عضو بهذا الرقم.
<?
			}
?>
						</tr>
					</table>
					</form>
				</div>
			</div>
			<div dir="rtl" class="title_bg"> 
				<div dir="rtl" class="title">آخر 20 رسالة</div> 
				<div dir="rtl" class="module_content">
					<form method="post" action="<?=$_SERVER['PHP_SELF']?>?do=<?=$_GET['do']?>" enctype="multipart/form-data">
					<table dir="rtl" cellspacing="0" cellpadding="0" class="module_table">
<?
			$sql = "SELECT * FROM arrowchat WHERE arrowchat.from='".mysql_real_escape_string($_REQUEST[id])."' ORDER BY arrowchat.id DESC LIMIT 20";
			$result = mysql_query($sql);
			if ($result && mysql_num_rows($result) > 0) {
?>
						<tr>
							<td style="width: 175px;" class="row2">أرسلت إلى</td>
							<td style="width: 525px;" class="row2">الرسالة</td>
						</tr>
<?
				while ($row = mysql_fetch_array($result)) {
					$sql = "SELECT ".DB_USERTABLE_NAME." FROM ".TABLE_PREFIX.DB_USERTABLE." WHERE ".DB_USERTABLE_USERID."='".$row[to]."'";
					$result2 = mysql_query($sql);
					$to_username = mysql_fetch_row($result2);
?>
						<tr>
							<td dir="rtl" class="row1"><a href="users.php?do=logs&id=<?=$row[to]?>"><?=$to_username[0]?></a></td>
							<td dir="rtl" class="row1"><?=$row[message]?></td>
						</tr>
<?
				}
			} else {
?>
						لا يمتلك هذا العضو اي محادثات في قاعدة البيانات.
<?
			}
?>
					</table>
<?
		}
	}
?>

<?
	if ($do == "manageusers") {
?>
					<form method="post" action="<?=$_SERVER['PHP_SELF']?>?do=<?=$_GET['do']?>" enctype="multipart/form-data">
					<img src="images/icons/address_32.png" alt="" border="0" />&nbsp;<div dir="rtl" class="subtitle">إدارة الأعضاء</div><br />
					<table dir="rtl" cellspacing="0" cellpadding="0" class="module_table">
						<tr>
							<td dir="rtl" style="width: 150px;">البحث عن الأعضاء:</td>
							<td><input type="text" name="username" /></td>
						</tr>
					</table>
					<p dir="rtl" class="submit">
						<input type="submit" name="user_search" class="button-primary" value="بـحـث" />
					</p>
<?
		if (!empty($_POST['user_search'])) {
			$sql = "SELECT ".DB_USERTABLE_NAME.", ".DB_USERTABLE_USERID." FROM ".TABLE_PREFIX.DB_USERTABLE." WHERE LOWER(".DB_USERTABLE_NAME.") LIKE '%".mysql_real_escape_string(strtolower($_POST[username]))."%' ORDER BY ".DB_USERTABLE_NAME." ASC LIMIT 20";
			$result = mysql_query($sql);
?>
					</form>

				</div>
			</div>
			<div dir="rtl" class="title_bg"> 
				<div dir="rtl" class="title">النتائج</div> 
				<div dir="rtl" class="module_content">
					<form method="post" action="<?=$_SERVER['PHP_SELF']?>?do=<?=$_GET['do']?>" enctype="multipart/form-data">
					<table dir="rtl" cellspacing="0" cellpadding="0" class="module_table">
						<tr style="height: 25px;">
							<td dir="rtl" style="width: 125px;" class="row2">رقم العضو</td>
							<td dir="rtl" style="width: 400px;" class="row2">الإسم</td>
							<td dir="rtl" style="width: 175px;" class="row2">الحدث</td>
						</tr>
<?
			while ($row = mysql_fetch_array($result)) {
?>
						<tr style="height: 25px;">
							<td dir="rtl" style="width: 175px;" class="row1"><?=$row[DB_USERTABLE_USERID]?></td>
							<td dir="rtl" style="width: 350px;" class="row1"><?=$row[DB_USERTABLE_NAME]?></td>
							<td dir="rtl" style="width: 175px;" class="row1"><a href="users.php?do=logs&id=<?=$row[DB_USERTABLE_USERID]?>">السجل</a></td>
						</tr>
<?
			}
?>
					</table>
<?
		}
	}
?>
<?
	if ($do == "banusernames") {
?>
					<form method="post" action="<?=$_SERVER['PHP_SELF']?>?do=<?=$_GET['do']?>" enctype="multipart/form-data">
					<img src="images/icons/block_32.png" alt="" border="0" />&nbsp;<div dir="rtl" class="subtitle">حظر الأعضاء</div><br />
					<table dir="rtl" cellspacing="0" cellpadding="0" class="module_table">
						<tr>
							<th valign="top">
								اسم العضو<br />
								<span dir="rtl" class="subtext">ضع كل اسم في سطر منفرد.</span>
							</th>
							<td><textarea name="ban_username" style="width: 300px; height: 200px;"></textarea></td>
						</tr>
					</table>
					
					<p dir="rtl" class="submit">
						<input type="submit" name="ban_username_submit" class="button-primary" value="حظر الأعضاء" />
					</p>
					</form>

				</div>
			</div>
			<div dir="rtl" class="title_bg"> 
				<div dir="rtl" class="title">إلغاء الحظر</div> 
				<div dir="rtl" class="module_content">
					<form method="post" action="<?=$_SERVER['PHP_SELF']?>?do=<?=$_GET['do']?>" enctype="multipart/form-data">
					<table dir="rtl" cellspacing="0" cellpadding="0" class="module_table">
						<tr>
							<th valign="top">
								الأسماء<br />
								<span dir="rtl" class="subtext">اختر الإسم لإلغاء الحظر عنه.</span>
							</th>
							<td>
								<select multiple="multiple" name="unban_username[]" style="width: 300px; height: 200px;">
<?
		$sql = "SELECT * FROM arrowchat_banlist WHERE ban_userid IS NOT NULL";
		$result = mysql_query($sql);
		if ($result && mysql_num_rows($result) > 0) {
			while ($row = mysql_fetch_array($result)) {
				$sql = "SELECT ".DB_USERTABLE_NAME." FROM ".TABLE_PREFIX.DB_USERTABLE." WHERE ".DB_USERTABLE_USERID."='".$row[ban_userid]."'";
				$result2 = mysql_query($sql);
				$row2 = mysql_fetch_array($result2);
?>
									<option value="<?=$row['ban_id']?>"><?=$row2[DB_USERTABLE_NAME]?></option>
<?
			}
		} else {
?>
									<option value="0">لا يوجد أعضاء محظورون</option>
<?
	}
?>
								</select>
							</td>
						</tr>
					</table>
					
					<p dir="rtl" class="submit">
						<input dir="rtl" type="submit" name="unban_username_submit" class="button-primary" value="إلغاء الحظر" />
					</p>
<?
	}
?>
<?
	if ($do == "banip") {
?>
					<form method="post" action="<?=$_SERVER['PHP_SELF']?>?do=<?=$_GET['do']?>" enctype="multipart/form-data">
					<img src="images/icons/block_32.png" alt="" border="0" />&nbsp;<div class="subtitle">حظر عناوين الـ IP</div><br />
					<table dir="rtl" cellspacing="0" cellpadding="0" class="module_table">
						<tr>
							<th valign="top">
								عنوان الـ IP<br />
								<span dir="rtl" class="subtext">ضع كل عنوان IP في سطر منفرد.</span>
							</th>
							<td><textarea dir="ltr" name="ban_ip" style="width: 300px; height: 200px;"></textarea></td>
						</tr>
					</table>
					
					<p dir="rtl" class="submit">
						<input type="submit" name="ban_ip_submit" class="button-primary" value="حظر الـ IP" />
					</p>
					</form>

				</div>
			</div>
			<div dir="rtl" class="title_bg"> 
				<div dir="rtl" class="title">إلغاء الحظر</div> 
				<div dir="rtl" class="module_content">
					<form method="post" action="<?=$_SERVER['PHP_SELF']?>?do=<?=$_GET['do']?>" enctype="multipart/form-data">
					<table dir="rtl" cellspacing="0" cellpadding="0" class="module_table">
						<tr>
							<th valign="top">
								عناوين الـ IP<br />
								<span dir="rtl" class="subtext">اختر عنوان الـ IP لإلغاء الحظر عنه.</span>
							</th>
							<td>
								<select multiple="multiple" name="unban_ip[]" style="width: 300px; height: 200px;">
<?
		$sql = "SELECT * FROM arrowchat_banlist WHERE ban_ip IS NOT NULL";
		$result = mysql_query($sql);
		if ($result && mysql_num_rows($result) > 0) {
			while ($row = mysql_fetch_array($result)) {
?>
									<option value="<?=$row['ban_id']?>"><?=$row['ban_ip']?></option>
<?
			}
		} else {
?>
									<option value="0">لا يوجد عناوين IP محظورة</option>
<?
	}
?>
								</select>
							</td>
						</tr>
					</table>
					
					<p dir="rtl" class="submit">
						<input type="submit" name="unban_ip_submit" class="button-primary" value="إلغاء الحظر" />
					</p>
<?
	}
?>
					
					</form>

				</div>
			</div>

<? require ("includes/pages_footer.php"); ?>