<?php
// save settings
if (!empty($_POST['cp_save'])) {

	// store options (not null or empty)
	foreach($_POST as $key => $value) {
		if ($key != 'cp_save') {
			$key_clean = str_replace('cp_', '', $key);
			$this->options["$key_clean"] = $_POST["$key"];
		}
	}

	// empty null fields must be passed manually
	$this->options['nav_custom'] = $_POST['cp_nav_custom'];
	$this->options['pages_custom'] = $_POST['cp_pages_custom'];
	$this->options['scroll_rated'] = $_POST['cp_scroll_rated'];
	$this->options['scroll_popular'] = $_POST['cp_scroll_popular'];
	$this->options['scrollables'] = $_POST['scrollables'];
	$this->options['catWidgets'] = $_POST['catWidgets'];
	$this->options['bottomCat'] = $_POST['bottomCat'];
	
	// ads changed
	if (!empty($this->options['ads']) && count($this->options["ads"]) > 0) {
		foreach($this->options["ads"] as $unique_ad) {
			if ($_POST[$unique_ad['name']."-status"] == 'delete') {
				unset($this->options['ads'][$unique_ad['name']]);
			} else {
				$this->options['ads'][$unique_ad['name']]['status'] = $_POST[$unique_ad['name']."-status"];
				$this->options['ads'][$unique_ad['name']]['start'] = $_POST[$unique_ad['name']."-start"];
				$this->options['ads'][$unique_ad['name']]['end'] = $_POST[$unique_ad['name']."-end"];
				$this->options['ads'][$unique_ad['name']]['code'] = $_POST[$unique_ad['name']."-code"];
				$this->options['ads'][$unique_ad['name']]['position'] = $_POST[$unique_ad['name']."-position"];	
			}
		}
	}

	update_option('news', $this->options);
	echo '<div class="updated fade" id="message"><p><strong>'.__('Settings saved.','news').'</strong></p></div>';

}

// ad creation and storing
if (!empty($_POST['adcode']) && !empty($_POST['adname'])) {

	if ($_POST['adstart'] == 'dd-mm-yyyy') { $_POST['adstart'] = ''; }
	if ($_POST['adend'] == 'dd-mm-yyyy') { $_POST['adend'] = ''; }

	// put new ad as option in database
	$this->options['ads'][$_POST['adname']] = array(
	'name' => $_POST['adname'],
	'position' => $_POST['adpos'], 
	'code' => $_POST['adcode'], 
	'start' => $_POST['adstart'], 
	'end' => $_POST['adend'], 
	'status' => $_POST['adstatus'],
	'clicks' => 0,
	'impressions' => 0
	);

	update_option('news', $this->options);

}

// image uploads
if ( isset( $_POST['html-upload'] ) && !empty( $_FILES ) ) {

	require_once(ABSPATH . 'wp-admin/includes/admin.php');
	
	// upload files
	$logo = media_handle_upload('logoupload', 0);
	$favicon = media_handle_upload('favupload', 0);
	
	unset($_FILES);
	
	// pass vars
	$this->options['logo'] = $logo;
	$this->options['favicon'] = $favicon;
	
	update_option('news', $this->options);
	echo '<div class="updated fade" id="message"><p><strong>'.__('Settings saved.','news').'</strong></p></div>';

}
?>

<div class="wrap deluxefw">

<h2><?php _e('NewsWorld Theme Options','news'); ?></h2>

<form id="file-form" enctype="multipart/form-data" action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">

<h3><span class="dhead"><?php _e('Logo and favicon','news'); ?></span><span class="dsubmit"><input type="submit" name="html-upload" class="button-secondary" value="<?php _e('Upload &amp; Save Changes','news'); ?>"></span></h3>

<table class="form-table">
<tr valign="top">
<th scope="row"><strong><?php _e('Active Logo','news'); ?></strong></th>
<td>
<?php $image = wp_get_attachment_image_src($this->options['logo'], 'full'); if (intval($this->options['logo']) && $image) { ?>
<img src="<?php echo $image[0]; ?>" alt="" /><br />
<?php _e('You have already uploaded a custom logo. If you wish to change your logo, please upload another logo below to overwrite existing logo.','news'); ?>
<?php } else { ?>
<img src="<?php bloginfo('template_directory'); ?>/images/logo.png" alt="" /><br />
<?php _e('It seems that you have not uploaded a custom logo yet. You can upload your custom logo below to overwrite the current theme logo.','news'); ?>
<?php } ?>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Upload your logo','news'); ?></th>
<td>
<?php _e('<strong>Recommended properties:</strong> PNG logo file with a height of 100 pixels.','news'); ?><br />
<input type="file" id="logoupload" name="logoupload" />
</td>
</tr>
<tr valign="top">
<th scope="row"><strong><?php _e('Active Favicon','news'); ?></strong></th>
<td>
<?php $image = wp_get_attachment_image_src($this->options['favicon'], 'full'); if (intval($this->options['favicon']) && $image) { ?>
<img src="<?php echo $image[0]; ?>" alt="" /><br />
<?php _e('You have already uploaded a custom favicon. If you wish to change your favicon, please upload another favicon below to overwrite existing favicon.','news'); ?>
<?php } else { ?>
<img src="<?php bloginfo('template_directory'); ?>/favicon.ico" alt="" /><br />
<?php _e('It seems that you have not uploaded a custom favicon yet. You can upload your custom favicon below to overwrite the current theme favicon.','news'); ?>
<?php } ?>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Upload your favicon','news'); ?></th>
<td>
<?php _e('The favicon file has to be in <strong>.ICO</strong> format.','news'); ?><br />
<input type="file" id="favupload" name="favupload" />
</td>
</tr>
</table>

</form>

<form action="" method="post">

<h3><span class="dhead"><?php _e('Style editor','news'); ?></span><span class="dsubmit"><input type="submit" name="cp_save" class="button-secondary" value="<?php _e('Save Changes','news'); ?>" /></span></h3>

<table class="form-table">
<tr valign="top">
<th scope="row"><label for="cp_style"><?php _e('Style','cmfy'); ?></label></th>
<td>
<select name="cp_style" id="cp_style">
<optgroup label="<?php _e('Built-in styles','cmfy'); ?>">
	<?php
	$dirPath = TEMPLATEPATH. '/styles/';
	if ($handle = opendir($dirPath)) {
	while (false !== ($file = readdir($handle))) {
	if ($file != "." && $file != "..") {
	if (is_file("$dirPath/$file")) {
	?>
	<option value="<?php echo $file; ?>"<?php selected($file, $this->options["style"]); ?>><?php echo $file; ?></option>
	<?php
	}
	}
	}
	closedir($handle);
	}
	?>
</optgroup>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row"><strong><?php _e('Change colors'); ?></strong></th>
<td>
<label for="css1"><?php _e('Primary link color','cmfy'); ?></label>
<input type="text" name="colors[]" id="css1" value="<?php echo $this->options["colors"][0]; ?>" class="colorpickerfield" maxlength="6" size="6" />
</td>
</tr>
<tr valign="top">
<th scope="row"><strong><?php _e('Change backgrounds'); ?></strong></th>
<td>
<label for="css2"><?php _e('Body background color','cmfy'); ?></label>
<input type="text" name="bgcolors[]" id="css2" value="<?php echo $this->options["bgcolors"][0]; ?>" class="colorpickerfield" maxlength="6" size="6" />
</td>
</tr>
</table>

<h3><span class="dhead"><?php _e('Manage Header','news'); ?></span><span class="dsubmit"><input type="submit" name="cp_save" class="button-secondary" value="<?php _e('Save Changes','news'); ?>" /></span></h3>

<table class="form-table">
<tr valign="top">
<th scope="row"><label for="cp_headerdate"><?php _e('Date format','news'); ?></label></th>
<td>
<input type="text" name="cp_headerdate" id="cp_headerdate" value="<?php echo $this->options["headerdate"]; ?>" class="regular-text" />
<span class="description"><?php _e('View the php <a href="http://php.net/manual/en/function.date.php">date()</a> function for more information. 
If you leave this field blank, current date will not be shown on the header.','news'); ?></span>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Breaking News Slideshow','news'); ?></th>
<td>
<label for="cp_showhotnews"><?php _e('Status','news'); ?></label>
<select name="cp_showhotnews" id="cp_showhotnews">
	<option value="1"<?php selected(1, $this->options["showhotnews"]); ?>><?php _e('Active','news'); ?></option>
	<option value="0"<?php selected(0, $this->options["showhotnews"]); ?>><?php _e('Inactive','news'); ?></option>
</select>
<label for="cp_hotnewsnum"><?php _e('Number of posts','news'); ?></label>
<input type="text" name="cp_hotnewsnum" id="cp_hotnewsnum" value="<?php echo $this->options["hotnewsnum"]; ?>" class="small-text" />
<label for="cp_hotnewseffect"><?php _e('Slideshow effect','news'); ?></label>
<select name="cp_hotnewseffect" id="cp_hotnewseffect">
	<option value="slide"<?php selected("slide", $this->options["hotnewseffect"]); ?>><?php _e('slide','news'); ?></option>
	<option value="fade"<?php selected("fade", $this->options["hotnewseffect"]); ?>><?php _e('fade','news'); ?></option>
	<option value="default"<?php selected("default", $this->options["hotnewseffect"]); ?>><?php _e('default','news'); ?></option>
</select>
<label for="cp_hotnewsinterval"><?php _e('Slideshow interval','news'); ?></label>
<input type="text" name="cp_hotnewsinterval" id="cp_hotnewsinterval" value="<?php echo $this->options["hotnewsinterval"]; ?>" class="small-text" />
<label for="cp_hotnewsfadein"><?php _e('FadeInSpeed','news'); ?></label>
<input type="text" name="cp_hotnewsfadein" id="cp_hotnewsfadein" value="<?php echo $this->options["hotnewsfadein"]; ?>" class="small-text" />
<label for="cp_hotnewsfadeout"><?php _e('FadeOutSpeed','news'); ?></label>
<input type="text" name="cp_hotnewsfadeout" id="cp_hotnewsfadeout" value="<?php echo $this->options["hotnewsfadeout"]; ?>" class="small-text" />
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Weather','news'); ?></th>
<td>
<label for="cp_getweather"><?php _e('Status','news'); ?></label>
<select name="cp_getweather" id="cp_getweather">
	<option value="1"<?php selected(1, $this->options["getweather"]); ?>><?php _e('Active','news'); ?></option>
	<option value="0"<?php selected(0, $this->options["getweather"]); ?>><?php _e('Inactive','news'); ?></option>
</select>
<label for="cp_wtype"><?php _e('Temperature scale','news'); ?></label>
<select name="cp_wtype" id="cp_wtype">
	<option value="c"<?php selected("c", $this->options["wtype"]); ?>><?php _e('Celsius','news'); ?></option>
	<option value="f"<?php selected("f", $this->options["wtype"]); ?>><?php _e('Fahrenheit','news'); ?></option>
</select><br />
<label for="cp_wcode"><?php _e('Location code','news'); ?></label>
<input type="text" name="cp_wcode" id="cp_wcode" value="<?php echo $this->options["wcode"]; ?>" class="regular-text" /><br />
<span class="description"><?php _e('Go to <a href="http://weather.yahoo.com/">Yahoo! Weather</a> then enter your location. Click on the RSS feed of your location 
then read the location code from the URL in address bar. The URL of the feed looks like: http://weather.yahooapis.com/forecastrss?<strong>p=USNY0996</strong>&u=f 
in this case the <strong>p=</strong> value is your location code, which is <strong>USNY0996</strong>','news'); ?></span>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Main Navigation','news'); ?></th>
<td>
<label for="cp_nav_sort"><?php _e('Order by','news'); ?></label>
<select name="cp_nav_sort" id="cp_nav_sort">
	<option value="ID"<?php selected("ID", $this->options["nav_sort"]); ?>>ID</option>
	<option value="name"<?php selected("name", $this->options["nav_sort"]); ?>>name</option>
	<option value="slug"<?php selected("slug", $this->options["nav_sort"]); ?>>slug</option>
	<option value="count"<?php selected("count", $this->options["nav_sort"]); ?>>count</option>
	<option value="term_group"<?php selected("term_group", $this->options["nav_sort"]); ?>>term_group</option>
</select>
<label for="cp_nav_order"><?php _e('Order','news'); ?></label>
<select name="cp_nav_order" id="cp_nav_order">
	<option value="ASC"<?php selected("ASC", $this->options["nav_order"]); ?>><?php _e('Ascending','news'); ?></option>
	<option value="DESC"<?php selected("DESC", $this->options["nav_order"]); ?>><?php _e('Descending','news'); ?></option>
</select>
<label for="cp_nav_hide_empty"><?php _e('Hide empty categories','news'); ?></label>
<select name="cp_nav_hide_empty" id="cp_nav_hide_empty">
	<option value="1"<?php selected(1, $this->options["nav_hide_empty"]); ?>><?php _e('Yes','news'); ?></option>
	<option value="0"<?php selected(0, $this->options["nav_hide_empty"]); ?>><?php _e('No','news'); ?></option>
</select><br />
<label for="cp_drop1effect"><?php _e('Dropdown effect','news'); ?></label>
<select name="cp_drop1effect" id="cp_drop1effect">
	<option value="fadeIn"<?php selected("fadeIn", $this->options["drop1effect"]); ?>>fadeIn</option>
	<option value="slideToggle"<?php selected("slideToggle", $this->options["drop1effect"]); ?>>slideToggle</option>
	<option value="slideDown"<?php selected("slideDown", $this->options["drop1effect"]); ?>>slideDown</option>
	<option value="show"<?php selected("show", $this->options["drop1effect"]); ?>>show</option>
</select>
<label for="cp_drop1speed"><?php _e('Effect speed','news'); ?></label>
<input type="text" name="cp_drop1speed" id="cp_drop1speed" value="<?php echo $this->options["drop1speed"]; ?>" class="small-text" /><br />
<input name="cp_nav_custom" type="checkbox" id="cp_nav_custom" value="1" <?php checked("1", $this->options["nav_custom"]); ?> />
<label for="cp_nav_custom"><?php _e('Check this box If you want to enable and use <strong>custom menus</strong> instead.','news'); ?></label>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Secondary Navigation','news'); ?></th>
<td>
<label for="cp_drop2effect"><?php _e('Dropdown effect','news'); ?></label>
<select name="cp_drop2effect" id="cp_drop2effect">
	<option value="fadeIn"<?php selected("fadeIn", $this->options["drop2effect"]); ?>>fadeIn</option>
	<option value="slideToggle"<?php selected("slideToggle", $this->options["drop2effect"]); ?>>slideToggle</option>
	<option value="slideDown"<?php selected("slideDown", $this->options["drop2effect"]); ?>>slideDown</option>
	<option value="show"<?php selected("show", $this->options["drop2effect"]); ?>>show</option>
</select>
<label for="cp_drop2speed"><?php _e('Effect speed','news'); ?></label>
<input type="text" name="cp_drop2speed" id="cp_drop2speed" value="<?php echo $this->options["drop2speed"]; ?>" class="small-text" /><br />
<input name="cp_pages_custom" type="checkbox" id="cp_pages_custom" value="1" <?php checked("1", $this->options["pages_custom"]); ?> />
<label for="cp_pages_custom"><?php _e('Check this box If you want to enable and use <strong>custom menus</strong> instead. If unchecked, 
NewsWorld will display its default built-in page links.','news'); ?></label>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_searchform"><?php _e('Search form','news'); ?></label></th>
<td>
<select name="cp_searchform" id="cp_searchform">
	<option value="1"<?php selected(1, $this->options["searchform"]); ?>><?php _e('Display','news'); ?></option>
	<option value="0"<?php selected(0, $this->options["searchform"]); ?>><?php _e('Do not display','news'); ?></option>
</select>
</td>
</tr>
</table>

<h3><span class="dhead"><?php _e('Miscellaneous','news'); ?></span><span class="dsubmit"><input type="submit" name="cp_save" class="button-secondary" value="<?php _e('Save Changes','news'); ?>" /></span></h3>

<table class="form-table">
<tr valign="top">
<th scope="row"><label for="cp_socialmodule"><?php _e('Activate the Social Network Module','news'); ?></label></th>
<td>
<select name="cp_socialmodule" id="cp_socialmodule">
	<option value="1"<?php selected(1, $this->options["socialmodule"]); ?>><?php _e('Yes','news'); ?></option>
	<option value="0"<?php selected(0, $this->options["socialmodule"]); ?>><?php _e('No','news'); ?></option>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_homegetauth"><?php _e('Display post author on home page','news'); ?></label></th>
<td>
<select name="cp_homegetauth" id="cp_homegetauth">
	<option value="1"<?php selected(1, $this->options["homegetauth"]); ?>><?php _e('Yes','news'); ?></option>
	<option value="0"<?php selected(0, $this->options["homegetauth"]); ?>><?php _e('No','news'); ?></option>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_latestn"><?php _e('Number of latest entries','news'); ?></label></th>
<td><input type="text" name="cp_latestn" id="cp_latestn" value="<?php echo $this->options["latestn"]; ?>" class="small-text" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_featuredn"><?php _e('Number of featured posts','news'); ?></label></th>
<td><input type="text" name="cp_featuredn" id="cp_featuredn" value="<?php echo $this->options["featuredn"]; ?>" class="small-text" />
<span class="description"><?php _e('The main slideshow/featured area. Recommended: 5 (default)','news'); ?></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Featured slideshow settings','news'); ?></th>
<td>
<label for="cp_fs_event"><?php _e('Slideshow event','news'); ?></label>
<select name="cp_fs_event" id="cp_fs_event">
	<option value="mouseover"<?php selected("mouseover", $this->options["fs_event"]); ?>>mouseover</option>
	<option value="click"<?php selected("click", $this->options["fs_event"]); ?>>click</option>
</select>
<label for="cp_fs_effect"><?php _e('Slideshow effect','news'); ?></label>
<select name="cp_fs_effect" id="cp_fs_effect">
	<option value="fade"<?php selected("fade", $this->options["fs_effect"]); ?>><?php _e('fade','news'); ?></option>
	<option value="slide"<?php selected("slide", $this->options["fs_effect"]); ?>><?php _e('slide','news'); ?></option>
	<option value="default"<?php selected("default", $this->options["fs_effect"]); ?>><?php _e('default','news'); ?></option>
</select>
<label for="cp_fs_fadein"><?php _e('FadeInSpeed','news'); ?></label>
<input type="text" name="cp_fs_fadein" id="cp_fs_fadein" value="<?php echo $this->options["fs_fadein"]; ?>" class="small-text" />
<label for="cp_fs_fadeout"><?php _e('FadeOutSpeed','news'); ?></label>
<input type="text" name="cp_fs_fadeout" id="cp_fs_fadeout" value="<?php echo $this->options["fs_fadeout"]; ?>" class="small-text" />
<label for="cp_fs_rotate"><?php _e('Rotation','news'); ?></label>
<select name="cp_fs_rotate" id="cp_fs_rotate">
	<option value="true"<?php selected("true", $this->options["fs_rotate"]); ?>><?php _e('Yes','news'); ?></option>
	<option value="false"<?php selected("false", $this->options["fs_rotate"]); ?>><?php _e('No','news'); ?></option>
</select>
<label for="cp_fs_autoplay"><?php _e('Autoplay','news'); ?></label>
<select name="cp_fs_autoplay" id="cp_fs_autoplay">
	<option value="true"<?php selected("true", $this->options["fs_autoplay"]); ?>><?php _e('Yes','news'); ?></option>
	<option value="false"<?php selected("false", $this->options["fs_autoplay"]); ?>><?php _e('No','news'); ?></option>
</select>
<label for="cp_fs_interval"><?php _e('Slideshow interval','news'); ?></label>
<input type="text" name="cp_fs_interval" id="cp_fs_interval" value="<?php echo $this->options["fs_interval"]; ?>" class="small-text" />
</td>
</tr>
</table>

<h3><span class="dhead"><?php _e('Main Tabs','news'); ?></span><span class="dsubmit"><input type="submit" name="cp_save" class="button-secondary" value="<?php _e('Save Changes','news'); ?>" /></span></h3>

<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Popular Tab','news'); ?></th>
<td>
<label for="cp_popularnum"><?php _e('Number of posts','news'); ?></label>
<input type="text" name="cp_popularnum" id="cp_popularnum" value="<?php echo $this->options["popularnum"]; ?>" class="small-text" />
<label for="cp_popularmode"><?php _e('Display most popular posts based on','news'); ?></label>
<select name="cp_popularmode" id="cp_popularmode">
	<option value="views"<?php selected("views", $this->options["popularmode"]); ?>><?php _e('Views count','news'); ?></option>
	<option value="comments"<?php selected("comments", $this->options["popularmode"]); ?>><?php _e('Comments count','news'); ?></option>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Top Rated Tab','news'); ?></th>
<td>
<label for="cp_ratednum"><?php _e('Number of posts','news'); ?></label>
<input type="text" name="cp_ratednum" id="cp_ratednum" value="<?php echo $this->options["ratednum"]; ?>" class="small-text" />
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Recent Comments Tab','news'); ?></th>
<td>
<label for="cp_recentc_num"><?php _e('Number of comments','news'); ?></label>
<input type="text" name="cp_recentc_num" id="cp_recentc_num" value="<?php echo $this->options["recentc_num"]; ?>" class="small-text" />
<label for="cp_recentc_container"><?php _e('Container','news'); ?></label>
<select name="cp_recentc_container" id="cp_recentc_container">
	<option value="ol"<?php selected("ol", $this->options["recentc_container"]); ?>>ol</option>
	<option value="ul"<?php selected("ul", $this->options["recentc_container"]); ?>>ul</option>
	<option value="div"<?php selected("div", $this->options["recentc_container"]); ?>>div</option>
</select>
<label for="cp_recentc_size"><?php _e('Gravatar size','news'); ?></label>
<input type="text" name="cp_recentc_size" id="cp_recentc_size" value="<?php echo $this->options["recentc_size"]; ?>" class="small-text" /><br />
<label for="cp_recentc_template"><?php _e('Recent Comment Template:','news'); ?></label>
<textarea name="cp_recentc_template" id="cp_recentc_template" rows="3" cols="50" class="large-text"><?php echo stripslashes($this->options["recentc_template"]); ?></textarea><br />
<?php _e('Allowed Template Variables','news'); ?><br />
<strong>%COMMENT%</strong> - <?php _e('Displays the comment content','news'); ?><br />
<strong>%COMMENT_URL%</strong> - <?php _e('Displays the comment URL','news'); ?><br />
<strong>%COMMENT_AUTHOR%</strong> - <?php _e('Displays the comment author name','news'); ?><br />
<strong>%AUTHOR_IMAGE%</strong> - <?php _e('Displays the comment author gravatar','news'); ?><br />
<strong>%POST_TITLE%</strong> - <?php _e('Displays the post title','news'); ?>
</td>
</tr>
</table>

<h3><span class="dhead"><?php _e('Main Scrollables','news'); ?></span><span class="dsubmit"><input type="submit" name="cp_save" class="button-secondary" value="<?php _e('Save Changes','news'); ?>" /></span></h3>

<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Select categories','news'); ?></th>
<td>
<?php
$cats = get_categories('hide_empty=0&orderby=ID');
foreach($cats as $cat) {
?>
<input type="checkbox" name="scrollables[]" id="<?php echo $cat->cat_ID; ?>" value="<?php echo $cat->cat_ID; ?>" <?php if (!empty($this->options['scrollables']) && in_array($cat->cat_ID, $this->options['scrollables'])) { echo "checked=\"checked\""; } ?> />
<label for="<?php echo $cat->cat_ID; ?>"><?php echo $cat->cat_name; ?></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php
}
?>
<input name="cp_scroll_rated" type="checkbox" id="cp_scroll_rated" value="1" <?php checked("1", $this->options["scroll_rated"]); ?> />
<label for="cp_scroll_rated"><?php _e('Top Rated','news'); ?></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="cp_scroll_popular" type="checkbox" id="cp_scroll_popular" value="1" <?php checked("1", $this->options["scroll_popular"]); ?> />
<label for="cp_scroll_popular"><?php _e('Most Popular','news'); ?></label>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_scrollablenum"><?php _e('Number of posts','news'); ?></label></th>
<td>
<input type="text" name="cp_scrollablenum" id="cp_scrollablenum" value="<?php echo $this->options["scrollablenum"]; ?>" class="small-text" />
<span class="description"><?php _e('This is the number of posts that will be fetched from each category/section. The viewport shows the recent 5 posts and a larger number 
will activate scrolling/navigating buttons to view all allowed posts.','news'); ?></span>
</td>
</tr>
</table>

<h3><span class="dhead"><?php _e('Main Category Widgets','news'); ?></span><span class="dsubmit"><input type="submit" name="cp_save" class="button-secondary" value="<?php _e('Save Changes','news'); ?>" /></span></h3>

<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Select categories','news'); ?></th>
<td>
<?php $cats = get_categories('hide_empty=0&orderby=ID'); foreach($cats as $cat) { ?>
<input type="checkbox" name="catWidgets[]" id="cat-<?php echo $cat->cat_ID; ?>" value="<?php echo $cat->cat_ID; ?>" <?php if (!empty($this->options['catWidgets']) && in_array($cat->cat_ID, $this->options['catWidgets'])) { echo "checked=\"checked\""; } ?> />
<label for="cat-<?php echo $cat->cat_ID; ?>"><?php echo $cat->cat_name; ?></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php } ?>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_catpostnum"><?php _e('Number of primary posts','news'); ?></label></th>
<td>
<input type="text" name="cp_catpostnum" id="cp_catpostnum" value="<?php echo $this->options["catpostnum"]; ?>" class="small-text" />
<span class="description"><?php _e('Number of primary posts to display for each category widget. (Default: 1 post)','news'); ?></span>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_catmorepostnum"><?php _e('Number of more posts','news'); ?></label></th>
<td>
<input type="text" name="cp_catmorepostnum" id="cp_catmorepostnum" value="<?php echo $this->options["catmorepostnum"]; ?>" class="small-text" />
<span class="description"><?php _e('Number of more posts to show under the main posts.','news'); ?></span>
</td>
</tr>
</table>

<h3><span class="dhead"><?php _e('Bottom Category Content','news'); ?></span><span class="dsubmit"><input type="submit" name="cp_save" class="button-secondary" value="<?php _e('Save Changes','news'); ?>" /></span></h3>

<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Select categories','news'); ?></th>
<td>
<?php $cats = get_categories('hide_empty=0&orderby=ID'); foreach($cats as $cat) { ?>
<input type="checkbox" name="bottomCat[]" id="bcat-<?php echo $cat->cat_ID; ?>" value="<?php echo $cat->cat_ID; ?>" <?php if (!empty($this->options['bottomCat']) && in_array($cat->cat_ID, $this->options['bottomCat'])) { echo "checked=\"checked\""; } ?> />
<label for="bcat-<?php echo $cat->cat_ID; ?>"><?php echo $cat->cat_name; ?></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php } ?>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_bottomcatnum"><?php _e('Number of posts','news'); ?></label></th>
<td>
<input type="text" name="cp_bottomcatnum" id="cp_bottomcatnum" value="<?php echo $this->options["bottomcatnum"]; ?>" class="small-text" />
<span class="description"><?php _e('This number should be 3 or its multiples for best view.','news'); ?></span>
</td>
</tr>
</table>

<h3><span class="dhead"><?php _e('Archive Settings','news'); ?></span><span class="dsubmit"><input type="submit" name="cp_save" class="button-secondary" value="<?php _e('Save Changes','news'); ?>" /></span></h3>

<table class="form-table">
<tr valign="top">
<th scope="row"><label for="cp_num_per_page"><?php _e('Posts per archive','news'); ?></label></th>
<td>
<input type="text" name="cp_num_per_page" id="cp_num_per_page" value="<?php echo $this->options["num_per_page"]; ?>" class="small-text" />
<span class="description"><?php _e('Set the number of visible posts/entries in every archive.','news'); ?></span>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_num_per_more"><?php _e('Posts Increment','news'); ?></label></th>
<td>
<input type="text" name="cp_num_per_more" id="cp_num_per_more" value="<?php echo $this->options["num_per_more"]; ?>" class="small-text" />
<span class="description"><?php _e('How many posts should be retrieved every time a user clicks on load more posts.','news'); ?></span>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_archivead"><?php _e('Display ads','news'); ?></label></th>
<td>
<select name="cp_archivead" id="cp_archivead">
	<option value="1"<?php selected(1, $this->options["archivead"]); ?>><?php _e('Active','news'); ?></option>
	<option value="0"<?php selected(0, $this->options["archivead"]); ?>><?php _e('Inactive','news'); ?></option>
</select>
<span class="description"><?php _e('When active, configured advertisements will be shown between the archived and paged results.','news'); ?></span>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Ad position','news'); ?></th>
<td>
<label for="cp_archivead_loop">Show an ad every</label> <input type="text" name="cp_archivead_loop" id="cp_archivead_loop" value="<?php echo $this->options["archivead_loop"]; ?>" class="small-text" /> posts or <label for="cp_archivead_fixed">show only 1 ad after</label> <input type="text" name="cp_archivead_fixed" id="cp_archivead_fixed" value="<?php echo $this->options["archivead_fixed"]; ?>" class="small-text" /> post(s) in every archive.
<span class="description"><?php _e('This will control where the ads will appear inside your archived and paged results.','news'); ?></span>
</td>
</tr>
</table>

<h3><span class="dhead"><?php _e('Setup NewsPulse','news'); ?></span><span class="dsubmit"><input type="submit" name="cp_save" class="button-secondary" value="<?php _e('Save Changes','news'); ?>" /></span></h3>

<table class="form-table">
<tr valign="top">
<th scope="row"><label for="cp_newspulse"><?php _e('Select NewsPulse page','news'); ?></label></th>
<td>
<select name="cp_newspulse" id="cp_newspulse">
	<option value=""<?php selected("", $this->options['newspulse']); ?>><?php _e('Disable','news'); ?></option>
	<?php $pages = get_pages(); ?>
	<?php foreach($pages as $page) { ?>
	<option value="<?php echo $page->ID; ?>"<?php selected($page->ID, $this->options['newspulse']); ?>><?php echo $page->post_title ?></option>
	<?php } ?>
</select>
<span class="description"><?php _e('To setup NewsPulse functionality, please create an empty page and assign it to <strong>NewsPulse</strong> custom page template. Then select the page from this dropdown list.','news'); ?></span>
</td>
</tr>
</table>

<h3><span class="dhead"><?php _e('Post Settings','news'); ?></span><span class="dsubmit"><input type="submit" name="cp_save" class="button-secondary" value="<?php _e('Save Changes','news'); ?>" /></span></h3>

<table class="form-table">
<tr valign="top">
<th scope="row"><label for="cp_postgallery"><?php _e('Photo Gallery Source','news'); ?></label></th>
<td>
<select name="cp_postgallery" id="cp_postgallery">
	<option value="attachment"<?php selected('attachment', $this->options["postgallery"]); ?>><?php _e('attachments','news'); ?></option>
	<option value="content"<?php selected('content', $this->options["postgallery"]); ?>><?php _e('post content','news'); ?></option>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_related"><?php _e('Related content module','news'); ?></label></th>
<td>
<select name="cp_related" id="cp_related">
	<option value="1"<?php selected(1, $this->options["related"]); ?>><?php _e('Active','news'); ?></option>
	<option value="0"<?php selected(0, $this->options["related"]); ?>><?php _e('Inactive','news'); ?></option>
</select>
<span class="description"><?php _e('When active, related content (depending on post type) will always be displayed below post.','news'); ?></span>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_related_num"><?php _e('Number of posts','news'); ?></label></th>
<td>
<input type="text" name="cp_related_num" id="cp_related_num" value="<?php echo $this->options["related_num"]; ?>" class="small-text" />
<span class="description"><?php _e('Maximum number of posts that will be displayed as related content below post.','news'); ?></span>
</td>
</tr>
</table>

<h3><span class="dhead"><?php _e('Integration','news'); ?></span><span class="dsubmit"><input type="submit" name="cp_save" class="button-secondary" value="<?php _e('Save Changes','news'); ?>" /></span></h3>

<table class="form-table">
<tr valign="top">
<th scope="row"><label for="cp_feedburner"><?php _e('FeedBurner URI','news'); ?></label></th>
<td>
<input type="text" name="cp_feedburner" id="cp_feedburner" value="<?php echo $this->options["feedburner"]; ?>" class="regular-text" />
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_twitter"><?php _e('Twitter username','news'); ?></label></th>
<td>
<input type="text" name="cp_twitter" id="cp_twitter" value="<?php echo $this->options["twitter"]; ?>" class="regular-text" />
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_facebook"><?php _e('Facebook Page URL','news'); ?></label></th>
<td>
<input type="text" name="cp_facebook" id="cp_facebook" value="<?php echo $this->options["facebook"]; ?>" class="regular-text" />
</td>
</tr>
</table>

<h3><span class="dhead"><?php _e('Ad Management','news'); ?></span><span class="dsubmit"><input type="submit" name="cp_save" class="button-secondary" value="<?php _e('Save Changes','news'); ?>" /></span></h3>

<table class="form-table">

<tr valign="top">
<th scope="row"><strong><?php _e('Add a new Ad','news'); ?></strong></th>
<td colspan="5"><?php _e('If you want to enable multiple ads rotation just add multiple ad codes to the same position.','news'); ?></td>
</tr>

<tr valign="top">
<th scope="row">Unique name</th>
<th scope="row">Ad position</th>
<th scope="row">Ad code</th>
<th scope="row">Start date</th>
<th scope="row">End date</th>
<th scope="row">Status</th>
</tr>

<tr valign="top">
<td><input type="text" value="" size="11" name="adname" id="adname" /></td>
<td>
<select name="adpos" id="adpos">
	<option value="Header">Header</option>
	<option value="Header Wide">Header Wide</option>
	<option value="Footer Wide">Footer Wide</option>
	<option value="Left">Left</option>
	<option value="Right">Right</option>
	<option value="Center of main page">Center of main page</option>
	<option value="Archives">Between Archived Results</option>
	<option value="NewsTable">NewsTable</option>
</select>
</td>
<td><textarea rows="5" cols="50" name="adcode" id="adcode"></textarea></td>
<td><input type="text" value="dd-mm-yyyy" size="11" name="adstart" id="adstart" /></td>
<td><input type="text" value="dd-mm-yyyy" size="11" name="adend" id="adend" /></td>
<td>
<select name="adstatus" id="adstatus">
	<option value="1"><?php _e('Active','news'); ?></option>
	<option value="0"><?php _e('Inactive','news'); ?></option>
</select>
</td>
</tr>

<?php if (!empty($this->options['ads']) && count($this->options['ads']) > 0) { ?>
<tr valign="top">
<th scope="row" colspan="9"><strong><?php _e('Created Ads','news'); ?></strong></th>
</tr>

<tr valign="top">
<th scope="row">Unique name</th>
<th scope="row">Ad position</th>
<th scope="row">Advertisement</th>
<th scope="row">Start date</th>
<th scope="row">End date</th>
<th scope="row">Impressions</th>
<th scope="row">Clicks</th>
<th scope="row">CTR</th>
<th scope="row">Status</th>
</tr>

<?php foreach ($this->options['ads'] as $k) { ?>
<tr valign="top">
<td><?php echo $k['name']; ?></td>
<td>
<select name="<?php echo $k['name']; ?>-position" id="<?php echo $k['name']; ?>-position">
	<option value="Header"<?php selected("Header", $k['position']); ?>>Header</option>
	<option value="Header Wide"<?php selected("Header Wide", $k['position']); ?>>Header Wide</option>
	<option value="Footer Wide"<?php selected("Footer Wide", $k['position']); ?>>Footer Wide</option>
	<option value="Left"<?php selected("Left", $k['position']); ?>>Left</option>
	<option value="Right"<?php selected("Right", $k['position']); ?>>Right</option>
	<option value="Center of main page"<?php selected("Center of main page", $k['position']); ?>>Center of main page</option>
	<option value="Archives"<?php selected("Archives", $k['position']); ?>>Between Archived Results</option>
	<option value="NewsTable"<?php selected("NewsTable", $k['position']); ?>>NewsTable</option>
</select>
</td>
<td><textarea rows="5" cols="50" name="<?php echo $k['name']; ?>-code" id="<?php echo $k['name']; ?>-code"><?php echo stripslashes($k['code']); ?></textarea></td>
<td><input type="text" value="<?php echo $k['start']; ?>" size="11" name="<?php echo $k['name']; ?>-start" id="<?php echo $k['name']; ?>-start" /></td>
<td><input type="text" value="<?php echo $k['end']; ?>" size="11" name="<?php echo $k['name']; ?>-end" id="<?php echo $k['name']; ?>-end" /></td>
<td><?php echo $k['impressions']; ?></td>
<td><?php echo $k['clicks']; ?></td>
<td><?php if ($k['impressions'] > 0) echo round(($k['clicks'] / $k['impressions']) * 100, 2).'%'; else echo '0%'; ?></td>
<td>
<select name="<?php echo $k['name']; ?>-status" id="<?php echo $k['name']; ?>-status">
	<option value="1"<?php selected(1, $k['status']); ?>><?php _e('Active','news'); ?></option>
	<option value="0"<?php selected(0, $k['status']); ?>><?php _e('Inactive','news'); ?></option>
	<option value="delete"><?php _e('Delete','news'); ?></option>
</select>
</td>
</tr>
<?php } } ?>

</table>

<h3><span class="dhead"><?php _e('Additional headers and footers','news'); ?></span><span class="dsubmit"><input type="submit" name="cp_save" class="button-secondary" value="<?php _e('Save Changes','news'); ?>" /></span></h3>

<table class="form-table">
<tr valign="top">
<th scope="row"><label for="cp_description"><?php _e('Meta description','news'); ?></label></th>
<td><input type="text" name="cp_description" id="cp_description" value="<?php echo $this->options["description"]; ?>" class="large-text" />
<span class="description"><?php _e('Describe your website. This meta description will be used by most major search engines.','news'); ?></span></td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_keywords"><?php _e('Meta keywords','news'); ?></label></th>
<td><input type="text" name="cp_keywords" id="cp_keywords" value="<?php echo $this->options["keywords"]; ?>" class="large-text" />
<span class="description"><?php _e('Enter a comma seperated list of keywords which can describe your website.','news'); ?></span></td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_headers"><?php _e('Additional headers','news'); ?></label></th>
<td>
<?php _e('Paste any additional headers in this area. This content will be added right before your HEAD closing tag. Use this area to add additional meta tags, 
references to css or javascript files, google analytics code, or anything that needs to be added to the head section of your site.','news'); ?><br />
<textarea name="cp_headers" id="cp_headers" rows="7" cols="50" class="large-text"><?php echo stripslashes($this->options["headers"]); ?></textarea>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="cp_footers"><?php _e('Additional footers','news'); ?></label></th>
<td>
<?php _e('Paste any additional footers in this area. This content will be added right before your BODY closing tag. Use this area to add contents or scripts you want to run at 
the bottom of the page.','news'); ?><br />
<textarea name="cp_footers" id="cp_footers" rows="7" cols="50" class="large-text"><?php echo stripslashes($this->options["footers"]); ?></textarea>
</td>
</tr>
</table>

</form>

</div>