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

$sp_xlines = mysql_result(mysql_query("select spltarticlexline from autoposter_settings where id='1'"),0);

$dir = dirname(__FILE__)."/tmp/";
if (is_dir($dir)){
   if ($dh = opendir($dir)){
       while (($file = readdir($dh)) !== false){
       $file_ext = substr(strrchr($file, '.'), 1);
         if($file_ext == "zip"){
           @unlink($dir . $file);
           //echo "$file : $file_ext <br>";
         }
       }
       closedir($dh);
   }
}

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("<script src=\"pop.js\" type=\"text/javascript\" language=\"javascript\"></script><table width=\"100%\"><tr><td align=\"right\"><a href=\"javascript:OpenWin('pop_help/addnewproject.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\">Submit Articles</td></tr>";
echo "</table><br />";
?>

<form name="FormName" id="FormName" action="addnewproject_upload.php" method="post" enctype="multipart/form-data">
<table align="center" cellpadding="5" cellspacing="5">
<tr>
<td>Project Name:</td><td><input name="projectnm" type="text" value=""></td>
</tr>

<tr>
<td>Select Posting To:<br>For individual select use CTRL+SELECT<br />Multiple select use SHIFT+SELECT</font></td><td>
<select size="5" name="selt_server[]" width="340" style="width: 340px" multiple>
<?php
$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($i==0) {
		echo "<option value=\"{$project_id}\" selected>{$domain_url}</option>";
	} else {
		echo "<option value=\"{$project_id}\">{$domain_url}</option>";
	}
}
?>
</select></td>
</tr>

<tr>
<td>Load Meta Elements:<br />Select the profile you want to use with this blog.</td><td>
<select size="1" name="load_meta_profile">
<?php
$res = mysql_query("select * from autoposter_meta_profiles order by id asc");
for($i=0; $i<mysql_num_rows($res); $i++) {
	$id = mysql_result($res, $i, "id");
	$profile_name = mysql_result($res, $i, "profile_name");

	echo "<option value=\"{$id}\">{$profile_name}</option>";
}
?>
</select></td>
</tr>

<tr>
<td>Publish Type:</td><td>
<select size="1" name="selt_pubtype">
<option value="save_cron">Save & Cron</option>
<option value="pub_now">Publish Now</option>
</select></td>
</tr>

<?php
echo '<tr><td>Preset Date/Time:</td><td>';
echo seltmonth(date("m"));

echo '<input type="text" name="dd" value="'.date("d").'" size="2" maxlength="2" />
<input type="text" name="yy" value="'.date("Y").'" size="4" maxlength="5" /> @
<input type="text" name="hh" value="'.date("H").'" size="2" maxlength="2" /> :
<input type="text" name="mn" value="'.date("i").'" size="2" maxlength="2" /> :
<input type="text" name="ss" value="'.date("s").'" size="2" maxlength="2" />
</td></tr>';
?>

<tr>
<td width="45%">Randomize the Time/Post</td><td>
<select size="1" name="randomize_time">
<option value="no">No</option>
<option value="yes">Yes</option>
</select> it will randomize the time (hour, minute and second) per post.</td>
</tr>

<tr>
<td width="45%">Select Yes if you want to use the settings below (Post X Articles PER X Days), Select No if you want to use the settings above (Preset Date/Time):</td><td>
<select size="1" name="enable_x_art_st">
<option value="no">No</option>
<option value="yes">Yes</option>
</select></td>
</tr>

<tr>
<td>Post X Articles:</td><td><input name="postxarticle" type="text" value="" size="3"> ie. 2 - mean post two articles</td>
</tr>

<tr>
<td>Every X Day(s):</td><td><input name="xarticleinxdays" type="text" value="" size="3"> ie. 1 - every day</td>
</tr>

<tr>
<td>Split each article after (<?php echo $sp_xlines; ?>) lines <font color=red>(see Manage Content->Edit Settings)</font>:</td><td>
<select size="1" name="splt_artcl">
<option value="no">No</option>
<option value="yes">Yes</option>
</select></td>
</tr>

<tr>
<td>Select Multiple Articles:<br>For individual select use CTRL+SELECT<br />Multiple select use SHIFT+SELECT</font></td>
<td>
<?php
function mk_txt_line_array($buf){
    $lnarray = split("\n", $buf);

  return $lnarray;
}

$search = array ("'<script[^>]*?>.*?</script>'si",  // Strip out javascript
                 "'<[/!]*?[^<>]*?>'si",          // Strip out HTML tags
                 //"'([rn])[s]+'",                // Strip out white space
                 "'&(quot|#34);'i",                // Replace HTML entities
                 "'&(amp|#38);'i",
                 "'&(lt|#60);'i",
                 "'&(gt|#62);'i",
                 "'&(nbsp|#160);'i",
                 "'&(iexcl|#161);'i",
                 "'&(cent|#162);'i",
                 "'&(pound|#163);'i",
                 "'&(copy|#169);'i",
                 "'&#(d+);'e");                    // evaluate as php

$replace = array ("",
                 "",
                 //"\1",
                 "\"",
                 "&",
                 "<",
                 ">",
                 " ",
                 chr(161),
                 chr(162),
                 chr(163),
                 chr(169),
                 "chr(\1)");

$tmpdir = dirname(__FILE__)."/tmp/";
$tmpdir = str_replace("\\", "/", $tmpdir);
$tmpdir = str_replace("//", "/", $tmpdir);

$files = filelist($tmpdir, 1, 0, "all", 1);

$z=0;
if(count($files) > 0){
echo "<select size=\"7\" name=\"sltart[]\" width=\"514\" style=\"width: 514px\" multiple>";

foreach ($files as $list){//print array
	//echo "Path: " . $list['path'] . " ==> Name: " . $list['name'] ."<br><br>";

   $path = str_replace($tmpdir, "", $list['path']);
   $path = str_replace("\\", "/", $path);
   $path = str_replace("//", "/", $path);
   //echo $path."<br>";
   @chdir($tmpdir.$path);

   if(is_dir($list['name'])){
   	$z = $z+1;
   } else {
    $filepth = $tmpdir . $path . $list['name'];
    $fp = fopen($filepth, "r");
    $buffer = fread($fp, filesize($filepth));
    fclose($fp);

	$fntext = preg_replace($search, $replace, $buffer);
	$resultln = mk_txt_line_array(trim($fntext));
	$txttitle = trim($resultln[0]);

	if($txttitle == "\r"){
		$txttitle = trim($resultln[1]);
	}

	$txttitle = preg_replace($search, $replace, $txttitle); //must be after $txtdescription

    echo "<option value=\"".$tmpdir . $path . $list['name']."\"> [" . $path . $list['name'] . "] - " . trim($txttitle) . "</option>";
    //echo "<input name=\"sltart[]\" type=\"checkbox\" value=\"".$tmpdir . $path . $list['name']."\" class=\"results$z\"> [" . $list['name'] . "] - " . trim($txttitle);
   }
}
echo "</select>";
} else {
  echo "<div align=\"center\"><b>Please upload at least one article...</b></div>";
}
?>
</td>
</tr>

<tr><td>Set how many X article:<br />only affect while 'Next Without Selected'</font></td><td><input name="xarticle" type="text" value="" size="2"> ie. 5 - show five blank article box</td></tr>

<tr>
<td>&nbsp;</td><td><input type="submit" name="submit" value="NEXT WITH SELECTED" style="color: #000000; font-size: 8pt; font-weight: bold; border: 1px ridge #000000; background-color: #E1EBFB"> | <input type="submit" name="submit" value="NEXT WITHOUT SELECTED" style="color: #000000; font-size: 8pt; font-weight: bold; border: 1px ridge #000000; background-color: #E1EBFB"></td>
</tr>

</table>
</form>

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