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

echo "<!-- tinyMCE -->
<script language=\"javascript\" type=\"text/javascript\" src=\"jscripts/tiny_mce/tiny_mce.js\"></script>
<script language=\"javascript\" type=\"text/javascript\">
        // Notice: The simple theme does not use all options some of them are limited to the advanced theme
        tinyMCE.init({
        mode : \"textareas\",
        theme : \"advanced\",
        plugins : \"advlink,insertdatetime,preview\",
        theme_advanced_buttons1 : \"bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo, separator, link,unlink, separator, preview\",
        theme_advanced_buttons2 : \"\",
        theme_advanced_buttons3 : \"\",
        theme_advanced_toolbar_location : \"top\",
        theme_advanced_toolbar_align : \"left\",
        // theme_advanced_path_location : \"bottom\",
        extended_valid_elements : \"a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]\"
        });
</script>
<!-- /tinyMCE -->\n";

$sel_server_id = mysql_result(mysql_query("select server_id from autoposter_projects where id='".$_REQUEST['pjid']."'"),0);
$res = mysql_query("select * from Projects where project_id='{$sel_server_id}'");
$project_id = mysql_result($res, 0, "project_id");
$domain = mysql_result($res, 0, "domain");
$web_folder = mysql_result($res, 0, "web_folder");
$username = mysql_result($res, 0, "admin_login");
$password = mysql_result($res, 0, "admin_password");

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

$domain_url = "http://" . $domain_url . "/xmlrpc.php";

$url = parse_url($domain_url);
$host = trim($url['host']);
$path = trim($url['path']);

include_once("./class.mtclient.php");
include_once("./blogger.php");

$blog = new mtclient($username, $password, $host, $path);

$root = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['PHP_SELF'];
//$root = str_replace("control","",$root);
$root = str_replace("/manage_wordpress.php","",$root);
$rootpath =  $root . "/tmp/";
//echo $rootpath;

function get_usrid($value) {
        $counter = 0;
        if ( is_array($value) ) {
                foreach($value as $key=>$val){
                        if (is_array($val)) {
                                get_usrid($val);
                        }
                        else {
                                if($key == "userid"){
                                 return $val;
                                }
                                //echo "<tr>\n<td>$counter</td>\n<td>&nbsp;" . $key . "&nbsp;</td>\n<td>&nbsp;" . $val . "&nbsp;</td>\n</tr>\n";
                        }
                        $counter++;
                }
        }
}

$data = blogger_getUserInfo($username, $password);
$gtuserid = get_usrid($data);
$blogID = $gtuserid;

//echo $blogID;

$myBlogs = $blog->getCategoryList($blogID);

while (list($key, $value) = each($myBlogs)) {
   foreach($value as $k3 => $v4){
        $v5[] = $v4;
}
}

foreach ($v5 as $kz => $vz) {
         if(is_numeric($vz)){
            $n[] = $vz;
         } else {
            $c[] = $vz;
         }
}

for($i=0; $i < count($n); $i++) {
        $n2 = $n[$i];
        $c2 = $c[$i];

        $fn[] = array("$n2" => "$c2");
}

function get_cat_list($fnz, $catnm, $catid) {
$fncatnm = explode("[|]", $catnm);

//print_r($fncatnm);

$rt_txt = "<select size=\"5\" name=\"selcat_".$catid."[]\" multiple>\n";
while (list($key, $value) = each($fnz)) {
   foreach($value as $k3 => $v4) {
        if(array_search($v4, $fncatnm)) {
           $rt_txt .= "<option value=\"$v4\" selected>$v4</option>\n";
        } else {
          $rt_txt .= "<option value=\"$v4\">$v4</option>\n";
        }
   }
}
$rt_txt .= "</select>\n";

return $rt_txt;
}

function mk_txt_line_array($buf) {
    $lnarray = split("\n", $buf);

  return $lnarray;
}

function seltmonth($selmth) {
$mk_mm = array("01" => "January", "02" => "February", "03" => "March", "04" => "April", "05" => "May", "06" => "June", "07" => "July", "08" => "August", "09" => "September", "10" => "October", "11" => "November", "12" => "December");

$pr_txt = '<select name="mm[]">';

foreach($mk_mm as $k => $v) {
        if($k == $selmth){
        $pr_txt .= "<option value=\"$k\" selected>$v</option>";
        } else {
        $pr_txt .= "<option value=\"$k\">$v</option>";
        }
}

$pr_txt .= '</select>';

return $pr_txt;
}

function seltpublished($selpub) {
$mk_pub = array("true" => "Publish", "false" => "Draft");

$pr_txt = '<select name="selpublish[]">';

foreach($mk_pub as $k => $v) {
	if("$k" == "$selpub") {
		$pr_txt .= "<option value=\"$k\" selected>$v</option>";
	} else {
		$pr_txt .= "<option value=\"$k\">$v</option>";
	}
}

$pr_txt .= '</select>';

return $pr_txt;
}

//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>");

echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"5\" bgcolor=\"#FFFFFF\" bordercolor=\"#000000\" align=\"center\">";
echo "<tr><td colspan=\"2\" bgcolor=\"#C0C0C0\" align=\"center\">Modify Project</td></tr>";
echo "</table><br />";

echo "<table border=\"0\" align=\"center\" style=\"border-collapse: collapse\" bordercolor=\"#C0C0C0\" cellpadding=\"2\" cellspacing=\"2\">";
echo "<form name=\"FormName\" action=\"manage_wordpress_updates.php\" method=\"post\">\n";
echo "<input name=\"pjid\" type=\"hidden\" value=\"".$_REQUEST['pjid']."\">\n";

$pjname = mysql_result(mysql_query("select name from autoposter_projects where id='".$_REQUEST['pjid']."'"), 0);
$server_id = mysql_result(mysql_query("select server_id from autoposter_projects where id='".$_REQUEST['pjid']."'"), 0);

echo '<td>&nbsp;Project Name:</td><td><input name="projectnm" type="text" value="'.$pjname.'"></td>';
echo '<tr>
<td>&nbsp;Posting To:</td><td>
<select size="1" name="selt_server">';

$res = mysql_query("select * from Projects order by project_id desc");
for($i=0; $i<mysql_num_rows($res); $i++) {
	$project_id = mysql_result($res, $i, "project_id");
	$domain = mysql_result($res, $i, "domain");
	$web_folder = mysql_result($res, $i, "web_folder");

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

    if($project_id == $server_id) {
		echo "<option value=\"{$project_id}\" selected>{$domain_url}</option>";
    } else {
		echo "<option value=\"{$project_id}\">{$domain_url}</option>";
	}
}

echo '</select></td></tr>
<tr><td colspan="2"><br><br></td></tr>';

$iz = 1;
$res = mysql_query("select * from autoposter_articles where project_id='".$_REQUEST['pjid']."' ORDER BY `id` ASC");
for ($i = 0; $i < mysql_num_rows($res); $i++) {
        $id = mysql_result($res, $i, "id");
        $title = mysql_result($res, $i, "title");
        $description = mysql_result($res, $i, "description");
        $meta_keywords = mysql_result($res, $i, "meta_keywords");
        $meta_description = mysql_result($res, $i, "meta_description");
        $mt_excerpt = mysql_result($res, $i, "mt_excerpt");
        $mt_keywords = mysql_result($res, $i, "mt_keywords");
        $selpublish = mysql_result($res, $i, "selpublish");
        $selcat = mysql_result($res, $i, "selcat");
        $mm = mysql_result($res, $i, "mm");
        $dd = mysql_result($res, $i, "dd");
        $yy = mysql_result($res, $i, "yy");
        $hh = mysql_result($res, $i, "hh");
        $mn = mysql_result($res, $i, "mn");
        $ss = mysql_result($res, $i, "ss");

//$description = htmlentities(trim($description));

echo "<tr><td colspan=\"2\"><fieldset style=\"padding: 2\">
      <legend><u><b>$pjname - Article #$iz</b></u></legend><table>";

echo '<tr><td width=\"25%\">Remove:</td><td><input name="delart[]" type="checkbox" value="'.$id.'"> Yes <small>- Check the box to remove this article</small></td></tr>';
echo '<tr><td>Title:</td><td><input name="title[]" type="text" size="104" value="'.$title.'"></td></tr>';
echo '<tr><td>Post:</td><td><textarea name="description[]" rows=15 cols=100>'.$description.'</textarea></td></tr>';
echo '<tr><td>Tags<br>(separate with commas, must use space after comma)<br />i.e tag1, tag2:</td><td><input name="mt_keywords[]" type="text" size="104" value="'.$mt_keywords.'"></td></tr>';

echo '<tr><td>Optional Excerpt:</td><td><textarea name="mt_excerpt[]" rows="2" cols="100" wrap="on" class="mceNoEditor">'.$mt_excerpt.'</textarea></td></tr>';
echo '<tr><td>Meta Keywords (separate with commas):</td><td><input name="metakeywords[]" type="text" size="104" value="'.$meta_keywords.'"></td></tr>';
echo '<tr><td>Meta Description:</td><td><textarea name="metadescription[]" rows="2" cols="100" wrap="on" class="mceNoEditor">'.$meta_description.'</textarea></td></tr>';

echo "<input name=\"selpublish[]\" type=\"hidden\" value=\"true\">\n";

//echo "<tr><td>Publish:</td><td>";
//echo seltpublished($selpublish);
//echo "</td></tr>";

echo "<tr><td>Category:</td><td>";
echo get_cat_list($fn, "[|]".$selcat, $iz);
echo "</td></tr>";

echo '<tr><td>Date/Time:</td><td>';
echo seltmonth($mm);

echo '<input type="text" name="dd[]" value="'.$dd.'" size="2" maxlength="2" />
<input type="text" name="yy[]" value="'.$yy.'" size="4" maxlength="5" /> @
<input type="text" name="hh[]" value="'.$hh.'" size="2" maxlength="2" /> :
<input type="text" name="mn[]" value="'.$mn.'" size="2" maxlength="2" /> :
<input type="text" name="ss[]" value="'.$ss.'" size="2" maxlength="2" />
<input type="hidden" name="article_id[]" value="'.$id.'" />

</td></tr>
<tr><td colspan="2"><br></td></tr>';

echo "</fieldset></td></tr></table></td></tr>";

$iz++;
}

echo '<tr><td>&nbsp;</td><td align="right"><input type="submit" name="delete_only" 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">&nbsp;&nbsp;<input type="submit" name="save_update_only" value="Update Only" style="color: #000000; font-size: 8pt; font-weight: bold; border: 1px ridge #000000; background-color: #E1EBFB">&nbsp;&nbsp;<input type="submit" name="pub_later" value="Save & Re-Publish By Cron" style="color: #000000; font-size: 8pt; font-weight: bold; border: 1px ridge #000000; background-color: #E1EBFB">&nbsp;&nbsp;<input type="submit" name="pub_now" value="Save & Publish Now" style="color: #000000; font-size: 8pt; font-weight: bold; border: 1px ridge #000000; background-color: #E1EBFB">&nbsp;</td></tr>';
echo "</form></table>";

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