<?php
include ("../config.php");
if (((($_GET['load'] == "help") or ($_GET['load'] == "chat") or ($_GET['load'] == "login") or ($_GET['load'] == "logout")))) {
if (($_GET['load'] == "help") && ($_GET['id'] == "list3")) {
eval (" ?>" . admin_header() . " <?php ");
if ($wysiwyg == "True") {
echo wysiwyg();
}
}
} else {
eval (" ?>" . admin_header() . " <?php ");
if ($wysiwyg == "True" && $_GET['load'] != "templates") {
echo wysiwyg();
}
echo '<SCRIPT LANGUAGE="JavaScript">var checkflag = "false";function check(field) {if (checkflag == "false") {for (i = 0; i < field.length; i++) {field[i].checked = true;}checkflag = "true";return "Uncheck All"; }else {for (i = 0; i < field.length; i++) {field[i].checked = false; }checkflag = "false";return "Check All"; }}</script>';
}
if ($ipbancheck3 == "0") {if ($numv == "0"){
	if ($warn == $naum) {
	echo "You Do Not Have Access to the Admin Panel";
}
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}

$from = (($page * $setting[max_results]) - $setting[max_results]);

$admin_page = "yes";
if ((($userlevel == "3") or ($userlevel == "4") or ($userlevel == "5"))) {
	echo "Sorry $username, but you do not have permission to the PR Manager. You are only a $level.";
} else {
	echo "<center><a href=\"pr.php?load=pr&view=quickadd\"><b>Quick Add</b></a> | <a href=\"pr.php?load=pr&view=add\">Add Company</a> | <a href=\"pr.php?load=pr\">Manage Companies</a>";

if ($_GET['view'] == "search") {
	echo "<title>OneCMS - www.onecms.net > PR Manager > Search</title><form action='pr.php?load=pr&view=search'  method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for company</td><td><input type='text' name='search'></td><td><input type='submit' name='Submit' value='Search'></td></tr></table></form>";

	echo "<form action='pr.php?load=pr&view=manage' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Company Name</b></td><td><b><b>Edit</b></td><td><b>Delete</b></td></tr><center><div align=\"center\">";

	$query="SELECT * FROM ".$pre."pr WHERE name LIKE '%" . $_POST['search'] . "%' ORDER BY `id` DESC LIMIT $from, $setting[max_results]";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$id = "$row[id]";
		$name2 = "$row[name]";
		$name = stripslashes($name2);
    	echo "<tr><td><a href='".$ppart1.$row[id].fthrough($row[name], "").$ppart2."' target='popup'>$name</a></td><td><input type=\"checkbox\" name=\"id[]\" value=\"$id\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$id\"></td></tr>";
    }

echo "<tr><td><div align='right'><input type='submit' name='submit' value='Submit'></td><td><input type=button value='Check All' onClick='this.value=check(this.form)'></td><td><a href=\"pr.php?load=pr&view=add\">Add Company</a></td></tr></form></table><br><br>";
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."pr WHERE name LIKE '%" . $_POST['search'] . "%'"),0);

$total_pages = ceil($total_results / $setting[max_results]);
if ($total_pages > 1) {
echo "<center>";

// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"pr.php?load=pr&page=$prev\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"pr.php?load=pr&page=$i\">$i</a>&nbsp;";if (($i/25) == (int)($i/25)) {echo "<br>";}
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"pr.php?load=pr&page=$next\">Next>></a>";
}
echo "</center>";
}
}

if ($_GET['view'] == "") {
	echo "<title>OneCMS - www.onecms.net > PR Manager</title><form action='pr.php?load=pr&view=search'  method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Search for company</td><td><input type='text' name='search'></td><td><input type='submit' name='Submit' value='Search'></td></tr></table></form>";

	echo "<form action='pr.php?load=pr&view=manage' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Company Name</b></td><td><b>Type</b></td><td><b><b>Edit</b></td><td><b>Delete</b></td></tr>";

$query="SELECT * FROM ".$pre."pr ORDER BY `id` DESC LIMIT $from, $setting[max_results]";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		$id = "$row[id]";
		$name2 = "$row[name]";
		$name = stripslashes($name2);
    	echo "<tr><td><a href='".$ppart1.$row[id].fthrough($row[name], "").$ppart2."' target='popup'>$name</a></td><td>$row[type]</td><td><input type=\"checkbox\" name=\"id[]\" value=\"$id\"></td><td><input type=\"checkbox\" name=\"delete[]\" value=\"$id\"></td></tr>";
    }

echo "<tr><td><div align='right'><input type='submit' name='submit' value='Submit'></td><td><input type=button value='Check All' onClick='this.value=check(this.form)'></td><td><a href=\"pr.php?load=pr&view=add\">Add company</a></td></tr></form></table><br><br>";
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."pr"),0);

$total_pages = ceil($total_results / $setting[max_results]);
if ($total_pages > 1) {
echo "<center>";

// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"pr.php?load=pr&page=$prev\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"pr.php?load=pr&page=$i\">$i</a>&nbsp;";if (($i/25) == (int)($i/25)) {echo "<br>";}
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"pr.php?load=pr&page=$next\">Next>></a>";
}
echo "</center>";
}
}

if ($_GET['view'] == "quickadd") {
echo "<form action=\"pr.php?load=pr&view=quickadd\" method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>How many companies to quick add?</td><td><input type='text' name='search'></td><td><input type='submit' name='addd' value='Submit'></td></tr></table></form><form action='pr.php?load=pr&view=add2' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"left\">";

if ($_POST['search']) {
echo "<input type=\"hidden\" name=\"s\" value='".$_POST['search']."'>";

    for($i = 0; $i < $_POST['search']; $i = $i+1) {
	echo "<tr><td><b><center>Company #".$i."</b></center></td></tr><tr><td>Name</td><td><input type=\"text\" name='name_".$i."'></td></tr>";
}
echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr>";
}
echo "</form></table>";
}

if (($_GET['view'] == "add") && ($_GET['add'] == "")) {
echo "<form action=\"pr.php?load=pr&view=add\" method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>How many companies to add?</td><td><input type='text' name='search'></td><td><input type='submit' name='addd' value='Submit'></td></tr></table></form><form action='pr.php?load=pr&view=add2' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"left\">";

if ($_POST['search']) {

echo "<input type=\"hidden\" name=\"s\" value='".$_POST['search']."'>";

    for($i = 0; $i < $_POST['search']; $i = $i+1) {
	echo "<tr><td><b><center>Company #".$i."</b></center></td></tr><tr><td>Name</td><td><input type=\"text\" name='name_".$i."'></td></tr><tr><td>Phone</td><td><input type=\"text\" name='phone_".$i."'></td></tr><tr><td>Country</td><td><input type=\"text\" name='country_".$i."'></td></tr><tr><td>Logo</td><td><input type=\"text\" name='logo_".$i."'></td></tr><tr><td>Site URL</td><td><input type='text' name='site_".$i."'></td></tr><tr><td>Address</td><td><textarea name='address_".$i."' cols='36' rows='12'></textarea></td></tr><tr><td>Description</td><td><textarea name='des_".$i."' cols='36' rows='12'></textarea></td></tr>";
}
echo "<tr><td><input type=\"submit\" name=\"Add\" value=\"Add\"></td></tr>";
}
echo "</form></table>";
}

   if (($_GET['view'] == "add2") && ($_GET['add'] == "")) {
   for($i = 0; $i < $_POST['s']; $i = $i+1) {
   //while (list(, $val) = each ($_POST["type_$i"])) 
   {
   $r = mysql_query("INSERT INTO ".$pre."pr VALUES (null, '".$_POST["name_$i"]."', '".$val."', '".$_POST["country_$i"]."', '".$_POST["logo_$i"]."', '".$_POST["phone_$i"]."', '".$_POST["site_$i"]."', '".addslashes($_POST["des_$i"])."')") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$r."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   }
   }
if ($r == TRUE) {
echo re_direct("1500", "pr.php?load=pr");
echo "The company(s) have been entered. <a href=\"pr.php?load=pr\">Return to PR Manager Home</a>";
}
}

	if ((($_GET['view'] == "manage") && ($_POST['delete'] == "") && ($_GET['edit'] == ""))) {

	echo "<form action='pr.php?load=pr&view=manage&edit=2' name='form1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"left\">";

    while (list(, $i) = each ($_POST['id'])) {
	$query="SELECT * FROM ".$pre."pr WHERE id = '$i'";
	$result=mysql_query($query);
	while($row2 = mysql_fetch_array($result)) {
                 
    echo "<input type='hidden' name='id[]' value='".$i."'><input type='hidden' name='name2_".$i."' value='".$row2['name']."'><tr><td><b><center>Company #".$i."</b></center></td></tr><tr><td>Name</td><td><input type=\"text\" name='name_".$i."' value='".$row2['name']."'></td></tr><tr><td>Phone</td><td><input type=\"text\" name='phone_".$i."' value='".$row2['phone']."'></td></tr><tr><td>Country</td><td><input type=\"text\" name='country_".$i."' value='".$row2['country']."'></td></tr><tr><td>Logo</td><td><input type=\"text\" name='logo_".$i."' value='".$row2['logo']."'></td></tr><tr><td>Site URL</td><td><input type='text' name='site_".$i."' value='".$row2[site]."'></td></tr><tr><td>Address</td><td><textarea name='address_".$i."' cols='36' rows='12'>".stripslashes($row2[address])."</textarea></tr></td><tr><td>Description</td><td><textarea name='des_".$i."' cols='36' rows='12'>".stripslashes($row2[des])."</textarea></td></tr>";
}
}
echo "<tr><td><input type=\"submit\" name=\"Modify\" value=\"Modify\"></td></tr></form></table>";
}

  if (($_GET['view'] == "manage") && ($_GET['edit'] == "2")) {
   while (list(, $i) = each ($_POST['id'])) {
   $count = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."pr WHERE name = '".$_POST["name_$i"]."'"));
   if ($count > "1") {
   $r = mysql_query("UPDATE ".$pre."pr SET name = '".addslashes($_POST["name_$i"])."', phone = '".$_POST["phone_$i"]."', country = '".$_POST["country_$i"]."', logo = '".$_POST["logo_$i"]."', address = '".$_POST["address_$i"]."', site = '".$_POST["site_$i"]."', des = '".addslashes($_POST["des_$i"])."' WHERE name = '".$_POST["name_$i"]."'") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$r."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   } else {
   $r = mysql_query("UPDATE ".$pre."pr SET name = '".addslashes($_POST["name_$i"])."', phone = '".$_POST["phone_$i"]."', country = '".$_POST["country_$i"]."', logo = '".$_POST["logo_$i"]."', address = '".$_POST["address_$i"]."', site = '".$_POST["site_$i"]."', des = '".addslashes($_POST["des_$i"])."' WHERE id = '".$i."'") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$r."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
   }

}
if ($r == TRUE) {
echo re_direct("1500", "pr.php?load=pr");
echo "The company(s) have been updated. <a href=\"pr.php?load=pr\">Return to PR Manager Home</a>";
}
}

if (($_GET['view'] == "manage") && ($_POST['id'] == "")) {
echo '<SCRIPT LANGUAGE="JavaScript">
var agree=confirm("Confirm Deletion?");
if (agree)
document.write("");
else
history.go(-1);
</SCRIPT>';

while (list(, $val) = each ($_POST['delete'])) {
	$delete = mysql_query("DELETE FROM ".$pre."pr WHERE id = '$val'") or die("<font color='red'><b>A fatal MySQL error occured</b></font>.<br><br><b>Query:</b> ".$delete."<br><b>Error:</b> (".mysql_errno().")".mysql_error());
}
if ($delete == TRUE) {
echo re_direct("1500", "pr.php?load=pr");
echo "The company(s) have been deleted. <a href=\"pr.php?load=pr\">Return to PR Manager Home</a>";
}
}
}
}
}

if (($_GET['load'] == "help") or ($_GET['load'] == "chat")) {
if (($_GET['load'] == "help") && ($_GET['id'] == "list3")) {
eval (" ?>" . admin_footer() . " <?php ");
}
} else {
eval (" ?>" . admin_footer() . " <?php ");
}
?>