<?php
session_start();
include("./functions.php");
include("./header.php");

echo "<script type=\"text/javascript\">
function CSB(){
if (document.mform.all.checked){
xxx = true;
} else {
xxx = false;
}
for (i = 0; i < document.forms['mform'].length; i++) {
document.forms['mform'].elements[i].checked = xxx
}
}
</script>\n";

//echo("<script src=\"pop.js\" type=\"text/javascript\" language=\"javascript\"></script><table width=\"100%\"><tr><td align=\"right\"><a href=\"javascript:OpenWin('pop_help/manage_wp_projects.html', 'help', 380, 400);\"><img src=\"images/q.gif\" width=\"16\" height=\"16\" border=0 hspace=\"4\"><small>Help</small></a>&nbsp;&nbsp;</td></tr></table><br>");

if($_REQUEST['submit'] == "Delete All Selected") {

	foreach($_REQUEST['selchk'] AS $checked) {

		mysql_query("delete from autoposter_articles where project_id='$checked'");
		mysql_query("delete from autoposter_projects where id='$checked'");
	}

}

echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"5\" border=\"0\" bordercolor=\"#000000\" align=\"center\">";
echo "<tr><td colspan=\"2\" bgcolor=\"#C0C0C0\" align=\"center\"><font face=verdana, arial>Manage Article Projects</td></tr>";
echo "</table><br />";

echo '<table width="100%" bgcolor="#c0c0c0" cellpadding="5" cellspacing="1" border=0 align=center>
<form NAME=mform action="manage_wp_projects.php" method="post"><font face=verdana, arial>
<tr><td bgcolor="#eeeeee" align="center">ID</font></td><td bgcolor="#eeeeee"><font face=verdana, arial>&nbsp;PROJECT TITLE</font></td><td bgcolor="#eeeeee"><font face=verdana, arial>&nbsp;PROJECT SUBMIT TO</font></td><td bgcolor="#eeeeee" align="center"><font face=verdana, arial>TOTAL AMOUNT PUBLISHED</font></td><td bgcolor="#eeeeee" align="center"><font face=verdana, arial># OF ARTICLES PENDING</font></td><td bgcolor="#eeeeee" align="center"><font face=verdana, arial>PUBLISHED STATUS</font></td><td align=center><input type=checkbox onClick=\'return CSB()\' name=all></td></tr>';

$res1 = mysql_query("select * from Projects");
for ($ii = 0; $ii < mysql_num_rows($res1); $ii++) {
$id1 = mysql_result($res1, $ii, "project_id");

    $res = mysql_query("select * from autoposter_projects where server_id='$id1' ORDER BY `id` DESC");
    for ($i = 0; $i < mysql_num_rows($res); $i++) {
         $id = mysql_result($res, $i, "id");

        error_reporting(0);
        $total_articles = mysql_result(mysql_query("select count(*) from autoposter_articles where project_id='$id'"),0);
        if($total_articles == 0) {
           $res = mysql_query("delete from autoposter_projects where id='$id'");
        }
    }
}


$lim = $Config->PROJECTS_PER_PAGE;
$s = $_REQUEST['s'];
if (!isset($s) || $s < 1 || !is_numeric($s)) {
$s = 1;
}
$start = ($s - 1) * $lim;
        $fquery = "select a.*, b.* from autoposter_projects a, Projects b where b.project_id=a.server_id";
        $countpages = $fquery;
        $fquery = $fquery . " order by a.id desc limit $start, $lim";
        $res = mysql_query($fquery);
        $pages = ceil(mysql_num_rows(mysql_query($countpages)) / $lim);
        if ($pages > 0) {
            echo("<p align=center style=\"font-size: 85%\">");
            for ($i = 1; $i <= $pages; $i++) {
                echo("[");
                if ($i == $s) {echo("<b>");}
                else {echo("<a href=?s=$i>");}
                echo("Page $i");
                if ($i == $s) {echo("</b>");}
                else {echo("</a>");}
                echo("]  ");
}
echo("</p><br />");

    for ($i = 0; $i < mysql_num_rows($res); $i++) {
        $id = mysql_result($res, $i, "a.id");
        $name = mysql_result($res, $i, "a.name");
        $server_id = mysql_result($res, $i, "a.server_id");

		$domain = mysql_result(mysql_query("select domain from Projects where project_id='$server_id'"),0);
		$web_folder = mysql_result(mysql_query("select web_folder from Projects where project_id='$server_id'"),0);

		if($web_folder=="") {
			$domain_url = $domain;
		} else {
			$domain_url = $domain . "/" . $web_folder . "/";
		}

        $articles_pending = mysql_result(mysql_query("select count(*) from autoposter_articles where posted='0' and project_id='$id'"),0);
        $articles_posted = mysql_result(mysql_query("select count(*) from autoposter_articles where posted='1' and project_id='$id'"),0);

        if($articles_pending > 0) {
           $articles_posted_status = "Pending Completion";
        } else {
           $articles_posted_status = "Posting Completed";
        }

		echo '<tr><td align="center" bgcolor="#eeeeee">&nbsp;'.$id.'</td><td align="left" bgcolor="#eeeeee"><font face=verdana, arial>&nbsp;<a href="manage_wordpress.php?pjid='.$id.'">'.$name.'</a></td><td align="left" bgcolor="#eeeeee"><font face=verdana, arial>&nbsp;<a target=_blank href="http://'.$domain_url.'">'.$domain_url.'</a></td></td><td align="center" bgcolor="#eeeeee"><font face=verdana, arial>'.$articles_posted.'</td><td align="center" bgcolor="#eeeeee"><font face=verdana, arial>'.$articles_pending.'</td><td align="center" bgcolor="#eeeeee"><font face=verdana, arial>'.$articles_posted_status.'</td><td align="center"><font face=verdana, arial><input type=checkbox name=selchk[] value='.$id.'></td></tr>';
  	}
	}
    echo '<tr><td colspan="7" align="right" bgcolor="#eeeeee"><font face=verdana, arial><input type=submit name=submit value="Delete All Selected" onclick="return confirm(\'Are you sure?\')" style="color: #000000; font-size: 8pt; font-weight: bold; border: 1px ridge #000000; background-color: #E1EBFB"></td></tr></form></table>';

include("./footer.php");
?>