<?php
/******************************************************************************
************** Simple SMS Site Software *********************************
************** SSSSv1.0*****************************************************
************** by (aq) limited http://aql.com *******************************
************** All Rights Reserved ******************************************
************** Please read COPYRIGHT file prior to modification********
********************************************************************************/
session_start();
$only_mine = $_GET['o'];
$user = $_SESSION['user'];
$pass = $_SESSION['pass'];
include("inc/header.inc.php");
include("inc/dbinfo.inc.php");
if ($access == "forbidden") {
include("inc/restricted.inc.php");
}
elseif ($access == "locked") {
include("inc/restricted.inc.php");
}
else {
?>
<h1>Address Book Viewer</h1>
<?
if ($access == 'admin') {
if ($only_mine == '1') {
?>
<a href="do_show_address_book.php?o=2">Show all</a>
<?
}
else {
?>
<a href="do_show_address_book.php?o=1">Show mine</a>
<?
}
}
// query db, make array of usernames
$query = "SELECT username FROM address_book";
if ($access != 'admin') {
$query.=" WHERE username='$user'";
}
elseif ($only_mine == '1') {
$query.=" WHERE username='$user'";
}
$result = mysql_query($query);
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row_count = mysql_num_rows($result); // count number of results (i.e rows)
for($i = 0; $i < $row_count; $i++)
{
$user_row = mysql_fetch_row($result);
foreach ($user_row as $x) {
$usernameArray[] = $x;
}
}
// query db, make array of contact names
$query = "SELECT name FROM address_book";
if ($access != 'admin') {
$query.=" WHERE username='$user'";
}
elseif ($only_mine == '1') {
$query.=" WHERE username='$user'";
}
$result = mysql_query($query);
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
for($i = 0; $i < $row_count; $i++)
{
$name_row = mysql_fetch_row($result);
foreach ($name_row as $x) {
$nameArray[] = $x;
}
}
// query db, make array of contact numbers
$query = "SELECT number FROM address_book";
if ($access != 'admin') {
$query.=" WHERE username='$user'";
}
elseif ($only_mine == '1') {
$query.=" WHERE username='$user'";
}
$result = mysql_query($query);
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
for($i = 0; $i < $row_count; $i++)
{
$num_row = mysql_fetch_row($result);
foreach ($num_row as $x) {
$numArray[] = $x;
}
}
// query db, make array of other contact details
$query = "SELECT other_details FROM address_book";
if ($access != 'admin') {
$query.=" WHERE username='$user'";
}
elseif ($only_mine == '1') {
$query.=" WHERE username='$user'";
}
$result = mysql_query($query);
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
for($i = 0; $i < $row_count; $i++)
{
$other_row = mysql_fetch_row($result);
foreach ($other_row as $x) {
$otherArray[] = $x;
}
}
// create table column names
?>
<table class=outline>
<tr BGCOLOR="#66AACC">
<td><p align="center">Username</p></td>
<td><p align="center">Name</p></td>
<td><p align="center">Number</p></td>
<td><p align="center">Other Details</p></td>
<td><p align="center">SMS</p></td>
<td><p align="center">Wap Push</p></td>
<td><p align="center">Remove</p></td></b>
</tr>
<?
if ($row_count == 0) {
?>
<tr BGCOLOR=<?echo "$colour";?>>
<td><p align="center">No Contacts</p></td>
<td><p align="center">-</p></td>
<td><p align="center">-</p></td>
<td><p align="center">-</p></td>
<td><p align="center">-</p></td>
<td><p align="center">-</p></td>
<td><p align="center">-</p></td>
</tr><?
}
else {
for($i = 0; $i < $row_count; $i++) // cycle through contacts and add to table
{
if ($oddRow == 1) {
$colour = "#99CCFF";
$oddRow = 0;
}
else {
$colour = "#FFFFFF";
$oddRow = 1;
}
// the bit that fills the table
?>
<tr BGCOLOR=<?echo "$colour";?>>
<td><p align="center"><?echo "$usernameArray[$i]";?></p></td>
<td><p align="center"><?echo "$nameArray[$i]";?></p></td>
<td><p align="center"><?echo "$numArray[$i]";?></p></td>
<td><p align="center"><?echo "$otherArray[$i]";?></p></td>
<td><p align="center"><a href="user_send.php?numbers=<?echo "$numArray[$i]"?>">SMS</a></p></td>
<td><p align="center"><a href="user_send_wap.php?numbers=<?echo "$numArray[$i]"?>">WAP</a></p></td>
<td><p align="center"><a href="do_delete_contact.php?u=<?echo "$usernameArray[$i]"?>&n=<?echo "$nameArray[$i]";?>&p=<?echo $pass?>">Remove</a></p></td>
</tr><?
}
}
?>
</table>
<?
}
include("inc/footer.inc.php");
?>