Index: adminmenus.php
===================================================================
--- adminmenus.php	(revision 169171)
+++ adminmenus.php	(working copy)
@@ -1,22 +1,16 @@
 <?php
 
-if (function_exists('wp_enqueue_style')) {
-	wp_enqueue_script('jquery');
-	wp_enqueue_script('thickbox');
-	wp_enqueue_style('thickbox');
-}
-
 //Write Manage Menu
 function wp125_write_managemenu() {
 echo '<div class="wrap">
 <h2>'.__('Manage Ads', 'wp125').'</h2>';
 
 //Handle deactivations
-if ($_GET['wp125action'] == "deactivate") {
+if (isset($_GET['wp125action']) && $_GET['wp125action'] == "deactivate") {
 $theid = $_GET['theid'];
 echo '<div id="message" class="updated fade"><p>'.__('Are you sure you want to deactivate the ad?', 'wp125').' <a href="admin.php?page=wp125/wp125.php&wp125action=deactivateconf&theid='.$theid.'">'.__('Yes', 'wp125').'</a> &nbsp; <a href="admin.php?page=wp125/wp125.php">'.__('No!', 'wp125').'</a></p></div>';
 }
-if ($_GET['wp125action'] == "deactivateconf") {
+if (isset($_GET['wp125action']) && $_GET['wp125action'] == "deactivateconf") {
 $theid = $_GET['theid'];
 global $wpdb, $table_prefix;
 $adtable_name = $wpdb->prefix . "wp125_ads";
@@ -25,11 +19,11 @@
 }
 
 //Handle REactivations
-if ($_GET['wp125action'] == "activate") {
+if (isset($_GET['wp125action']) && $_GET['wp125action'] == "activate") {
 $theid = $_GET['theid'];
 echo '<div id="message" class="updated fade"><p>'.__('Are you sure you want to reactivate the ad?', 'wp125').' <a href="admin.php?page=wp125/wp125.php&showmanage=inactive&wp125action=activateconf&theid='.$theid.'">'.__('Yes', 'wp125').'</a> &nbsp; <a href="admin.php?page=wp125/wp125.php&showmanage=inactive">'.__('No!', 'wp125').'</a></p></div>';
 }
-if ($_GET['wp125action'] == "activateconf") {
+if (isset($_GET['wp125action']) && $_GET['wp125action'] == "activateconf") {
 $theid = $_GET['theid'];
 global $wpdb, $table_prefix;
 $adtable_name = $wpdb->prefix . "wp125_ads";
@@ -38,7 +32,7 @@
 }
 
 echo '<ul class="subsubsub">'; ?>
-<li><a href="admin.php?page=wp125/wp125.php"  <?php if ($_GET['showmanage'] != 'inactive') { echo 'class="current"'; } ?>><?php _e('Active Ads', 'wp125'); ?></a> | </li><li><a href="admin.php?page=wp125/wp125.php&showmanage=inactive" <?php if ($_GET['showmanage'] == 'inactive') { echo 'class="current"'; } ?>><?php _e('Inactive Ads', 'wp125'); ?></a></li>
+<li><a href="admin.php?page=wp125/wp125.php"  <?php if (isset($_GET['showmanage']) && $_GET['showmanage'] != 'inactive') { echo 'class="current"'; } ?>><?php _e('Active Ads', 'wp125'); ?></a> | </li><li><a href="admin.php?page=wp125/wp125.php&showmanage=inactive" <?php if (isset($_GET['showmanage']) && $_GET['showmanage'] == 'inactive') { echo 'class="current"'; } ?>><?php _e('Inactive Ads', 'wp125'); ?></a></li>
 <?php echo '</ul>
 <table class="widefat">
 <thead><tr>
@@ -54,7 +48,7 @@
 
 global $wpdb;
 $adtable_name = $wpdb->prefix . "wp125_ads";
-if ($_GET['showmanage'] == 'inactive') {
+if (isset($_GET['showmanage']) && $_GET['showmanage'] == 'inactive') {
 $wp125db = $wpdb->get_results("SELECT * FROM $adtable_name WHERE status = '0' ORDER BY id DESC", OBJECT);
 } else {
 $wp125db = $wpdb->get_results("SELECT * FROM $adtable_name WHERE status != '0' ORDER BY id DESC", OBJECT);
@@ -69,7 +63,7 @@
 echo '<td>'.$wp125db->start_date.'</td>';
 echo '<td>'.$wp125db->end_date.'</td>';
 echo '<td><a href="admin.php?page=wp125_addedit&editad='.$wp125db->id.'">'.__('Edit', 'wp125').'</a></td>';
-if ($_GET['showmanage'] == 'inactive') {
+if (isset($_GET['showmanage']) && $_GET['showmanage'] == 'inactive') {
 echo '<td><a href="admin.php?page=wp125/wp125.php&showmanage=inactive&wp125action=activate&theid='.$wp125db->id.'">'.__('Activate', 'wp125').'</a></td>';
 } else {
 echo '<td><a href="admin.php?page=wp125/wp125.php&wp125action=deactivate&theid='.$wp125db->id.'">'.__('Deactivate', 'wp125').'</a></td>';
@@ -100,14 +94,16 @@
 $setting_emailonexp = get_option("wp125_emailonexp");
 $setting_defaultad = get_option("wp125_defaultad");
 //If post is being edited, grab current info
-if ($_GET['editad']!='') {
+if (!empty($_GET['editad'])) {
 $theid = $_GET['editad'];
 $editingad = $wpdb->get_row("SELECT * FROM $adtable_name WHERE id = '$theid'", OBJECT);
+} else {
+$editingad = (object)array('name' => '', 'slot' => '', 'target' => '', 'end_date' => '00/00/0000', 'image_url' => '');
 }
 ?><div class="wrap">
 
 <?php
-if ($_POST['Submit']) {
+if (!empty($_POST['Submit'])) {
 $post_editedad = $wpdb->escape($_POST['editedad']);
 $post_adname = $wpdb->escape($_POST['adname']);
 $post_adslot = $wpdb->escape($_POST['adslot']);
@@ -137,11 +133,11 @@
 echo '<div id="message" class="updated fade"><p>'.__('Ad', 'wp125').' &quot;'.$post_adname.'&quot; '.__('updated.', 'wp125').'</p></div>';
 }
 }
-if ($_POST['deletead']) {
+if (!empty($_POST['deletead'])) {
 $post_editedad = $wpdb->escape($_POST['editedad']);
 echo '<div id="message" class="updated fade"><p>'.__('Do you really want to delete this ad record? This action cannot be undone.', 'wp125').' <a href="admin.php?page=wp125_addedit&deletead='.$post_editedad.'">'.__('Yes', 'wp125').'</a> &nbsp; <a href="admin.php?page=wp125_addedit&editad='.$post_editedad.'">'.__('No!', 'wp125').'</a></p></div>';
 }
-if ($_GET['deletead']!='') {
+if (!empty($_GET['deletead'])) {
 $thead=$_GET['deletead'];
 $updatedb = "DELETE FROM $adtable_name WHERE id='$thead'";
 $results = $wpdb->query($updatedb);
@@ -154,7 +150,7 @@
 <form method="post" action="admin.php?page=wp125_addedit">
 <table class="form-table">
 
-<?php if ($_GET['editad']!='') { echo '<input name="editedad" type="hidden" value="'.$_GET['editad'].'" />'; } ?>
+<?php if (!empty($_GET['editad'])) { echo '<input name="editedad" type="hidden" value="'.$_GET['editad'].'" />'; } ?>
 
 <tr valign="top">
 <th scope="row"><?php _e('Name', 'wp125'); ?></th>
@@ -176,19 +172,22 @@
 <td><input name="adtarget" type="text" id="adtarget" value="<?php if ($editingad->target!='') { echo $editingad->target; } else { echo 'http://'; } ?>" size="40" /><br/><?php _e('Where should the ad link to?', 'wp125'); ?></td>
 </tr>
 
-<?php if ($_GET['editad']!='') {
+<?php
 $enddate = $editingad->end_date;
 if ($enddate != '00/00/0000') {
 $enddate = strtotime($enddate);
 $endmonth = date('m', $enddate);
 $endday = date('d', $enddate);
 $endyear = date('Y', $enddate);
-} else { $endmonth='00'; $endday='00'; $endyear='0000'; }
+} else {
+$endmonth='00';
+$endday='00';
+$endyear='0000';
 } ?>
 <tr valign="top">
 <th scope="row"><?php _e('Expiration', 'wp125'); ?></th>
 <td><label for="adexp">
-<?php if ($_GET['editad']=='') { ?><select name="adexp" id="adexp" onChange="isOtherDate(this.value)">
+<?php if (isset($_GET['editad']) && $_GET['editad']=='') { ?><select name="adexp" id="adexp" onChange="isOtherDate(this.value)">
 <option value="manual"><?php _e("I'll remove it manually", 'wp125'); ?></option>
 <option selected="selected" value="30">30 <?php _e('Days', 'wp125'); ?></option>
 <option value="60">60 <?php _e('Days', 'wp125'); ?></option>
@@ -196,10 +195,10 @@
 <option value="120">120 <?php _e('Days', 'wp125'); ?></option>
 <option value="other"><?php _e('Other', 'wp125'); ?></option>
 </select><?php } ?></label>
- <span id="adexp-date">&nbsp;&nbsp; <?php _e('Month:', 'wp125'); ?> <input type="text" name="adexp-mo" id="adexp-mo" size="2" value="<?php if ($endmonth!='') { echo $endmonth; } else { echo date('m'); } ?>" /> <?php _e('Day:', 'wp125'); ?> <input type="text" name="adexp-day" id="adexp-day" size="2" value="<?php if ($endday!='') { echo $endday; } else {  echo date('d'); } ?>" /> <?php _e('Year:', 'wp125'); ?> <input type="text" name="adexp-yr" id="adexp-yr" size="4" value="<?php if ($endyear!='') { echo $endyear; } else {  echo date('Y'); } ?>" /> <?php if ($_GET['editad']!='') { ?><br /> &nbsp;&nbsp; <?php _e('Use 00/00/0000 for manual removal.', 'wp125'); ?><?php } ?></span>
+ <span id="adexp-date">&nbsp;&nbsp; <?php _e('Month:', 'wp125'); ?> <input type="text" name="adexp-mo" id="adexp-mo" size="2" value="<?php if ($endmonth!='') { echo $endmonth; } else { echo date('m'); } ?>" /> <?php _e('Day:', 'wp125'); ?> <input type="text" name="adexp-day" id="adexp-day" size="2" value="<?php if ($endday!='') { echo $endday; } else {  echo date('d'); } ?>" /> <?php _e('Year:', 'wp125'); ?> <input type="text" name="adexp-yr" id="adexp-yr" size="4" value="<?php if ($endyear!='') { echo $endyear; } else {  echo date('Y'); } ?>" /> <?php if (!empty($_GET['editad'])) { ?><br /> &nbsp;&nbsp; <?php _e('Use 00/00/0000 for manual removal.', 'wp125'); ?><?php } ?></span>
 </td></tr>
 
-<?php if ($_GET['editad']=='') { ?><script type="text/javascript">
+<?php if (isset($_GET['editad']) && $_GET['editad']=='') { ?><script type="text/javascript">
 document.getElementById("adexp-date").style.display = "none";
 function isOtherDate(obj) {
 if (obj=="other") {
@@ -210,7 +209,7 @@
 }
 </script><?php } ?>
 
-<?php if ($_GET['editad']=='') { ?>
+<?php if (isset($_GET['editad']) && $_GET['editad']=='') { ?>
 <tr valign="top">
 <th scope="row"><?php _e('Click Tracking', 'wp125'); ?></th>
 <td><input type="checkbox" name="countclicks" checked="checked" /> <?php _e('Count the number of times this ad is clicked', 'wp125'); ?></td>
@@ -223,7 +222,7 @@
 </tr>
 
 </table>
-<p class="submit"><input type="submit" name="Submit" value="<?php _e('Save Ad', 'wp125'); ?>" /> &nbsp; <?php if ($_GET['editad']!='') { ?><input type="submit" name="deletead" value="<?php _e('Delete Ad', 'wp125'); ?>" /><?php } ?></p>
+<p class="submit"><input type="submit" name="Submit" value="<?php _e('Save Ad', 'wp125'); ?>" /> &nbsp; <?php if (!empty($_GET['editad'])) { ?><input type="submit" name="deletead" value="<?php _e('Delete Ad', 'wp125'); ?>" /><?php } ?></p>
 </form>
 <?php wp125_admin_page_footer(); ?>
 </div><?php
@@ -233,7 +232,7 @@
 //DB Data
 global $wpdb;
 //Add settings, if submitted
-if ($_POST['issubmitted']=='yes') {
+if (isset($_POST['issubmitted']) && $_POST['issubmitted']=='yes') {
 $post_adorient = $wpdb->escape($_POST['adorient']);
 $post_numslots = $wpdb->escape($_POST['numads']);
 $post_adorder = $wpdb->escape($_POST['adorder']);
Index: wp125.php
===================================================================
--- wp125.php	(revision 169171)
+++ wp125.php	(working copy)
@@ -61,20 +61,28 @@
 
 
 
+//Add the Admin Menus
+add_action('admin_menu', 'wp125_add_admin_menu');
+function wp125_add_admin_menu() {
+	load_plugin_textdomain('wp125', PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)).'/translations', dirname(plugin_basename(__FILE__)).'/translations');
+	$pages = array();
+	$pages[] = add_menu_page(__("125x125 Ads", 'wp125'), __("Ads", 'wp125'), MANAGEMENT_PERMISSION, __FILE__, "wp125_write_managemenu");
+	$pages[] = add_submenu_page(__FILE__, __("Manage 125x125 Ads", 'wp125'), __("Manage", 'wp125'), MANAGEMENT_PERMISSION, __FILE__, "wp125_write_managemenu");
+	$pages[] = add_submenu_page(__FILE__, __("Add/Edit 125x125 Ads", 'wp125'), __("Add/Edit", 'wp125'), MANAGEMENT_PERMISSION, 'wp125_addedit', "wp125_write_addeditmenu");
+	$pages[] = add_submenu_page(__FILE__, __("125x125 Ad Settings", 'wp125'), __("Settings", 'wp125'), MANAGEMENT_PERMISSION, 'wp125_settings', "wp125_write_settingsmenu");
+	
+	foreach ( $pages as $my_page )
+		add_action('admin_print_scripts-' . $my_page, 'wp125_register_scripts_styles', 9); //Add it a little earlier.
 
-//Add the Admin Menus
-if (is_admin()) {
-	function wp125_add_admin_menu() {
-		load_plugin_textdomain('wp125', PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)).'/translations', dirname(plugin_basename(__FILE__)).'/translations');
-		add_menu_page(__("125x125 Ads", 'wp125'), __("Ads", 'wp125'), MANAGEMENT_PERMISSION, __FILE__, "wp125_write_managemenu");
-		add_submenu_page(__FILE__, __("Manage 125x125 Ads", 'wp125'), __("Manage", 'wp125'), MANAGEMENT_PERMISSION, __FILE__, "wp125_write_managemenu");
-		add_submenu_page(__FILE__, __("Add/Edit 125x125 Ads", 'wp125'), __("Add/Edit", 'wp125'), MANAGEMENT_PERMISSION, 'wp125_addedit', "wp125_write_addeditmenu");
-		add_submenu_page(__FILE__, __("125x125 Ad Settings", 'wp125'), __("Settings", 'wp125'), MANAGEMENT_PERMISSION, 'wp125_settings', "wp125_write_settingsmenu");
-	}
 	//Include menus
 	require_once(dirname(__FILE__).'/adminmenus.php');
 }
 
+function wp125_register_scripts_styles() {
+	wp_enqueue_script('jquery');
+	wp_enqueue_script('thickbox');
+	wp_enqueue_style('thickbox');
+}
 
 
 //Check Ad Date, and deactivate if the time is up
