<?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";

if($_REQUEST['load_meta_profile']) {
	$res = mysql_query("select * from autoposter_meta_profiles where id='".$_REQUEST['load_meta_profile']."'");
	$metakeywords = mysql_result($res, 0, "meta_keywords");
	$metadescription = mysql_result($res, 0, "meta_description");
	$mt_keywords_tages = mysql_result($res, 0, "mt_keywords");
}

$root = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['PHP_SELF'];
//$root = str_replace("control","",$root);
$root = str_replace("/wordpress_newproject_withoutupload.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++;
                }
        }
}

function get_cat_list($fnz, $pjid, $catid) {
$rt_txt = "<select size=\"5\" name=\"selcat_{$pjid}_{$catid}[]\" multiple>\n";
$iz = 0;
while (list($key, $value) = each($fnz)) {
   foreach($value as $k3 => $v4){
        if($iz == 0){
           $rt_txt .= "<option value=\"$v4\" selected>$v4</option>\n";
        } else {
          $rt_txt .= "<option value=\"$v4\">$v4</option>\n";
        }
}
$iz++;
}
$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;
}

echo "<table border=\"0\" align=\"center\" style=\"border-collapse: collapse\" bordercolor=\"#C0C0C0\" cellpadding=\"2\" cellspacing=\"2\">";
echo "<form name=\"FormName\" action=\"wordpress_submit.php\" method=\"post\">\n";
echo "<input name=\"pjid\" type=\"hidden\" value=\"".$_REQUEST['pjid']."\">\n";
echo "<tr><td colspan=\"2\" align=\"center\"><b>You have to follow this Server Date/Time: ".date("M, d-Y H:i:s O")."</b><br /><br /></td>";

$iz = 0;
$chkdt = 0;
$cntdt = 0;

while($iz < $_REQUEST['xarticle']) {

	if($_REQUEST['randomize_time'] == "yes") {
      	$mkdt = date("Y-m-d-H-i-s", mktime(rand(01, 23),rand(01, 59),rand(01, 59),$_REQUEST['mm'],$_REQUEST['dd'],$_REQUEST['yy']));
      	$sptdt = split("-", $mkdt);

      	$_REQUEST['yy'] = $sptdt[0];
      	$_REQUEST['mm'] = $sptdt[1];
      	$_REQUEST['dd'] = $sptdt[2];
      	$_REQUEST['hh'] = $sptdt[3];
      	$_REQUEST['mn'] = $sptdt[4];
      	$_REQUEST['ss'] = $sptdt[5];
   	}

	if($_REQUEST['enable_x_art_st'] == "yes") {

   			if($cntdt > $_REQUEST['postxarticle']-1) {

      			$mkdt = date("Y-m-d-H-i-s", mktime($_REQUEST['hh'],$_REQUEST['mn'],$_REQUEST['ss'],$_REQUEST['mm'],$_REQUEST['dd']+$_REQUEST['xarticleinxdays'],$_REQUEST['yy']));
      			$sptdt = split("-", $mkdt);

      			$_REQUEST['yy'] = $sptdt[0];
      			$_REQUEST['mm'] = $sptdt[1];
      			$_REQUEST['dd'] = $sptdt[2];
      			$_REQUEST['hh'] = $sptdt[3];
      			$_REQUEST['mn'] = $sptdt[4];
      			$_REQUEST['ss'] = $sptdt[5];

				$cntdt = 0;
   			}

	}

echo "<tr><td colspan=\"2\"><fieldset style=\"padding: 2\">
      <legend><u><b>Article #".($chkdt+1)."</b></u></legend><table>";

echo '<tr><td width=\"25%\">Title:</td><td><input name="title[]" type="text" size="75" value=""></td></tr>';
echo '<tr><td>Post:</td><td><textarea name="description[]" rows="15" cols="75"></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="75" value="'.trim($mt_keywords_tages).'"></td></tr>';

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

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

//echo '<tr><td>Publish:</td><td><select size="1" name="selpublish[]">
//<option value="true">Publish</option>
//<!-- <option value="false">Draft</option> -->
//</select></td></tr>';

$pjlst = explode(",", $_REQUEST['pjid']);
foreach($pjlst as $pjid) {
	$rntctlst = 1;
	echo include('connect_xmlprc.php');
}

if($_REQUEST['selt_pubtype'] == "save_cron") {
echo '<tr><td>Date/Time:</td><td>';
echo seltmonth($_REQUEST['mm']);

echo '<input type="text" name="dd[]" value="'.$_REQUEST['dd'].'" size="2" maxlength="2" />
<input type="text" name="yy[]" value="'.$_REQUEST['yy'].'" size="4" maxlength="5" /> @
<input type="text" name="hh[]" value="'.$_REQUEST['hh'].'" size="2" maxlength="2" /> :
<input type="text" name="mn[]" value="'.$_REQUEST['mn'].'" size="2" maxlength="2" /> :
<input type="text" name="ss[]" value="'.$_REQUEST['ss'].'" size="2" maxlength="2" />
</td></tr>';
} elseif($_REQUEST['selt_pubtype'] == "pub_now") {
echo '<input type="hidden" name="mm[]" value="'.date("m").'" size="2" maxlength="2" />
<input type="hidden" name="dd[]" value="'.date("d").'" size="2" maxlength="2" />
<input type="hidden" name="yy[]" value="'.date("Y").'" size="4" maxlength="5" />
<input type="hidden" name="hh[]" value="'.date("H").'" size="2" maxlength="2" />
<input type="hidden" name="mn[]" value="'.date("i").'" size="2" maxlength="2" />
<input type="hidden" name="ss[]" value="'.date("s").'" size="2" maxlength="2" />';
}

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

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

$iz++;
$chkdt++;
$cntdt++;
}

echo '<tr><td>&nbsp;</td><td align="right">';

echo "<input name=\"selcatcnt\" type=\"hidden\" value=\"$iz\">";

if($_REQUEST['selt_pubtype'] == "save_cron") {
	echo '<input type="submit" name="pub_later" value="Save & Cron" style="color: #000000; font-size: 8pt; font-weight: bold; border: 1px ridge #000000; background-color: #E1EBFB">&nbsp;';
} elseif($_REQUEST['selt_pubtype'] == "pub_now") {
	echo '<input type="submit" name="pub_now" value="Publish Now" style="color: #000000; font-size: 8pt; font-weight: bold; border: 1px ridge #000000; background-color: #E1EBFB">&nbsp;';
}

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

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