Jump to content

Read code from variable


Go to solution Solved by Sepodati,

Recommended Posts

Hello, I have this ad banner script and try to add another column that shows ad preview.

I added the extra column and code that is included to show an add. This shows static add with a given id.

 

However I need to show preview related to each row dynamical.

Somehow the table shows ID's for each row, but i don't know how to pass that to my code

 

code in my preview column

<?php @readfile('localhost/mysa_output.php?r='.$_SERVER['REMOTE_ADDR'].'&h='.urlencode($_SERVER['HTTP_HOST']).'&rf='.urlencode($_SERVER['HTTP_REFERER']).'&show_ad=read row id and put here'); ?>

whole script

<?php

// Display the list of ads
function ad_list() {
	global $db, $db_prefix;

  ?>

  <div align="right">	<a href="index.php?a=ad_create"><img src="img/create.gif" height="16" width="16" border="0" align="absmiddle" alt="Create a new ad">Create a new ad</a></div>
	<h2>Ad Listing</h2>

  <script type="text/javascript" src="js/tablesort.js"></script>
  <script type="text/javascript" src="js/pagination.js"></script>
  <span class="small_text">Click on the column header text to filter by column, or double-click to sort a column.</span>
  <table id="theTable" cellpadding="0" cellspacing="0" class="tablesort sortable-onload-1 rowstyle-alt no-arrow paginate-20 max-pages-5">
    <thead>
  		<tr class="tablesort">
  			<th class="tablesort sortable" width="5%">
        	ID        </th>
  			<th class="tablesort sortable" width="5%" align="middle">
          Status  			</th>
      	<th class="tablesort sortable" width="15%">
          Description  			</th>
      	<th class="tablesort sortable" width="15%">
          Advertiser  			</th>
      	<th class="tablesort sortable" width="15%">
          Ad Group  			</th>
        <th class="tablesort sortable" width="10%">
          Impressions (Today)*  			</th>
  			<th class="tablesort sortable" width="10%">
          Impressions (Life)  			</th>
        <th class="tablesort sortable" width="10%">
          Clicks  			</th>
      	<th class="tablesort" width="5%" align="middle">
          Edit  			</th>
        <th class="tablesort" width="5%" align="middle">
          Delete  			</th>
        <th class="tablesort" width="5%" align="middle">Preview</th>
        <th class="tablesort" width="5%" align="middle">
          Ad Code  			</th>
		  </tr>
    </thead>
    <tbody>
  <?php

  // Used to alternate row colors
  $rowclass = 'class = "row1"';

	$count = 1;

  // Look up the ads
	$sql_query_ad = 'SELECT * FROM '.$db_prefix.'ads ORDER by id ASC';
  $sql_result_ad = $db->select($sql_query_ad);
	while ($sql_row_ad=$db->get_row($sql_result_ad, 'MYSQL_ASSOC')) {

    $ad_id  = $sql_row_ad['id'];
		$ad_status  = $sql_row_ad['status'];
		$ad_description = trim($sql_row_ad['description']);
		$ad_impressions  = $sql_row_ad['impressions'];
		$ad_clicks  = $sql_row_ad['clicks'];
		$ad_track_clicks = $sql_row_ad['track_clicks'];

		// Lookup advertiser description
    $ad_advertiser_id  = $sql_row_ad['advertiser_id'];
		$sql_query_advertiser = 'SELECT description FROM '.$db_prefix.'advertisers WHERE id='.$ad_advertiser_id;
		$advertiser_description = trim($db->select_one($sql_query_advertiser));

  	// Lookup group description
  	$ad_group_ids = array();
  	$group_description = '';
		$sql_query_in_groups = 'SELECT group_id FROM '.$db_prefix.'group_ads WHERE ad_id='.$ad_id.' ORDER by group_id ASC';
  	$sql_result_in_groups = $db->select($sql_query_in_groups);
		while ($sql_row_in_groups=$db->get_row($sql_result_in_groups, 'MYSQL_ASSOC')) {
			$sql_query_group = 'SELECT description FROM '.$db_prefix.'groups WHERE id='.$sql_row_in_groups['group_id'];
			$group_description = $group_description.trim($db->select_one($sql_query_group)).'<br>';
		}
		if ($group_description == ''){
     $group_description = 'n/a';
		}

    // Get current impressions
		$sql_query_curr_stats='SELECT impressions FROM '.$db_prefix.'stats_compiled WHERE ad_id='.$ad_id.' AND date = DATE("'.date('Y-m-d').'")';
		$curr_stats = $db->select_one($sql_query_curr_stats);

		// Translate ad status
		$ad_status_text = '';
		if ($ad_status==1) {
			$ad_status_text = 'status_on.gif';
		} else {
      $ad_status_text = 'status_off.gif';
		}

		?>
		<tr <?php echo $rowclass; ?>>
			<td class="tablesort">
      	<?= $ad_id; ?>      </td>
			<td class="tablesort" align="middle">
        <img src="img/<?= $ad_status_text; ?>" width="16" height="16">			</td>
    	<td class="tablesort">
        <a href="index.php?a=ad_edit&id=<?= $ad_id ?>"><?= $ad_description; ?></a>			</td>
    	<td class="tablesort">
        <?= $advertiser_description; ?>			</td>
    	<td class="tablesort">
        <?= $group_description; ?>			</td>
      <td class="tablesort">
        <?= number_format($curr_stats); ?>			</td>
			<td class="tablesort">
        <?= number_format($ad_impressions); ?>			</td>
      <td class="tablesort">
        <?php if ($ad_track_clicks == 1){
					echo number_format($ad_clicks);
				} else {
					echo 'n/a';
				}
				?>			</td>
    	<td class="tablesort" align="middle">
        <a href="index.php?a=ad_edit&id=<?= $ad_id ?>"><img src="img/edit.gif" height="19" width="19" border="0" alt="Edit Ad"></a>			</td>
      <td class="tablesort" align="middle">
        <a href="index.php?a=ad_delete_confirm&id=<?= $ad_id ?>"><img src="img/delete.gif" height="19" width="19" border="0" alt="Delete Ad"></a>			</td>
    	<td class="tablesort" align="middle"><?php @readfile('localhost/mysa_output.php?r='.$_SERVER['REMOTE_ADDR'].'&h='.urlencode($_SERVER['HTTP_HOST']).'&rf='.urlencode($_SERVER['HTTP_REFERER']).'&show_ad=$rowclass'); ?> </td>
    	<td class="tablesort" align="middle">
        <a href="index.php?a=ad_code&id=<?= $ad_id ?>"><img src="img/code.gif" height="19" width="19" border="0" alt="Ad Code"></a>			</td>
		</tr>

		<?php

    if ($rowclass == 'class = "row1"'){
      $rowclass = 'class = "row2"';
    } else {
      $rowclass = 'class = "row1"';
    }
		$count++;
	}



  ?>
    </tbody>
	</table>
<br />
	<span class="small_text">* As of approximately a half-hour ago. You can update it now in the Ad Stats area.</span>
  <?php
}


// Edit an ad
function ad_edit($ad_id){
	global $db, $db_prefix, $config_enable_expiration, $config_enable_geo;

  // Look up the ad
	$sql_query_ad = 'SELECT * FROM '.$db_prefix.'ads WHERE id='.$ad_id;
  $sql_result_ad = $db->select($sql_query_ad);
  $sql_row_ad=$db->get_row($sql_result_ad, 'MYSQL_ASSOC');

  $ad_id  = $sql_row_ad['id'];
  $ad_type = $sql_row_ad['ad_type']; 
	$ad_status  = $sql_row_ad['status'];
	$ad_description = htmlspecialchars(trim($sql_row_ad['description']));
	$ad_impressions  = $sql_row_ad['impressions'];
	$ad_countries_on = htmlspecialchars(strtoupper(trim($sql_row_ad['countries_on'])));
	$ad_countries_off = htmlspecialchars(strtoupper(trim($sql_row_ad['countries_off'])));
  $ad_advertiser_id  = $sql_row_ad['advertiser_id'];
  $ad_impressions  = $sql_row_ad['impressions'];
  $ad_clicks  = $sql_row_ad['clicks'];
	$ad_weight  = $sql_row_ad['weight'];

	$ad_impressions += 0;
	$ad_clicks += 0;
	$ad_weight += 0;
	
	// Row alternating color
	$last_tr_id = 'row2';
	?>
  <script language="JavaScript" type="text/javascript">
  <!--
    function resetCounter(objectid){
      document.getElementById(objectid).value="0";
    }
  //-->
  </script>
  <script language="JavaScript" type="text/javascript">
	<!--
		function openChild(file,window,width,height,resizable) {
		  childWindow=open(file,window,'resizable='+resizable+',width='+width+',height='+height);
		  if (childWindow.opener == null) childWindow.opener = self;
  	}
    function getSelectedRadio(buttonGroup) {
		   // returns the array number of the selected radio button or -1 if no button is selected
		   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
		      for (var i=0; i<buttonGroup.length; i++) {
		         if (buttonGroup[i].checked) {
		            return i
		         }
		      }
		   } else {
		      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
		   }
		   // if we get to this point, no radio button is selected
		   return -1;
		} // Ends the "getSelectedRadio" function
		function getSelectedRadioValue(buttonGroup) {
		   // returns the value of the selected radio button or "" if no button is selected
		   var i = getSelectedRadio(buttonGroup);
		   if (i == -1) {
		      return "";
		   } else {
		      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
		         return buttonGroup[i].value;
		      } else { // The button group is just the one button, and it is checked
		         return buttonGroup.value;
		      }
		   }
		} // Ends the "getSelectedRadioValue" function
  //-->
  </script>
	<h2>Edit Ad ID <?= $ad_id; ?>
	  <span class="tablesort">
	  <?= $ad_id ?>
    </span></h2>
<form name="ads" action="index.php?a=ad_edit_save&id=<?= $ad_id ?>" method="POST">
	<table cellpadding="0" cellspacing="2" border="0" class="table">
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Ad Enabled
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="radio" name="ad_status" value="1" <?php if ($ad_status==1) { echo 'checked="checked"'; } ?>>Yes<br>
				<input type="radio" name="ad_status" value="0" <?php if ($ad_status==0) { echo 'checked="checked"'; } ?>>No<br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Click 'Yes' to enable the ad, or 'No' to disable the ad.
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Ad Description
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_description" value="<?= $ad_description ?>"><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Description of the ad (for your reporting purposes only)
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Advertiser
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<select name="ad_advertiser_id">
				<?php
				  // Look up the advertisers
					$sql_query_advertisers = 'SELECT id,description FROM '.$db_prefix.'advertisers ORDER by id ASC';
  				$sql_result_advertisers = $db->select($sql_query_advertisers);
					while ($sql_row_advertisers=$db->get_row($sql_result_advertisers, 'MYSQL_ASSOC')) {

						$ad_advertiser_all_id  = $sql_row_advertisers['id'];
						$ad_advertiser_all_descriptions  = htmlspecialchars(trim($sql_row_advertisers['description']));
						$ad_advertiser_selected = '';
						if ($ad_advertiser_all_id == $ad_advertiser_id) { $ad_advertiser_selected='selected="selected"'; }
						echo '<option value="'.$ad_advertiser_all_id.'" '.$ad_advertiser_selected.'>'.$ad_advertiser_all_descriptions.'</option>';
					}
				?>
				</select><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Select the advertiser (for your reporting purposes only)
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Ad Group
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<select name="ad_group_id[]" multiple="multiple" size="4">
					<option value="0">-none-</option>
				<?php
					$ad_group_ids = array();
					$sql_query_in_groups = 'SELECT group_id FROM '.$db_prefix.'group_ads WHERE ad_id='.$ad_id.' ORDER by group_id ASC';
  				$sql_result_in_groups = $db->select($sql_query_in_groups);
					while ($sql_row_in_groups=$db->get_row($sql_result_in_groups, 'MYSQL_ASSOC')) {
						array_push($ad_group_ids,$sql_row_in_groups['group_id']);
					}

				  // Look up the groups
					$sql_query_groups = 'SELECT id,description FROM '.$db_prefix.'groups ORDER by id ASC';
  				$sql_result_groups = $db->select($sql_query_groups);
					while ($sql_row_groups=$db->get_row($sql_result_groups, 'MYSQL_ASSOC')) {

						$ad_group_all_id  = $sql_row_groups['id'];
						$ad_group_all_descriptions  = htmlspecialchars(trim($sql_row_groups['description']));
						$ad_group_selected = '';
						if (in_array($ad_group_all_id,$ad_group_ids)){
							$ad_group_selected='selected';
						}
						echo '<option value="'.$ad_group_all_id.'" '.$ad_group_selected.'>'.$ad_group_all_descriptions.'</option>';
					}
				?>
				</select><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Select the ad grouping(s).
				<li>All ads in the same group will be cycled amongst each other.
				<li>Select '-none-' to not have this ad be part of a group.
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
    		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Ad Weight
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<select name="ad_weight" size="1">
				<?php
					for ($weight_count=10; $weight_count > 0; $weight_count--){

						if ($ad_weight == $weight_count){$weight_selected = 'selected="selected"';} else {$weight_selected = '';}
						echo '<option value="'.$weight_count.'" '.$weight_selected.'>'.$weight_count.'</option>';
				} ?>
				</select><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Select the ad weight for this ad amongst the ads in it's group
				<li>10 is the highest weight, with this ad being shown as much as possible.
				<li>You can leave all ads at 10 by default to evenly distribute.
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
    <?php
		if ($config_enable_geo == 1){
		?>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Display in these countries ONLY
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<select name="ad_countries_on[]" multiple="multiple" size="4">
				<option value =""></option>
				<?php
					// Put the current countries into an array for comparing
					$arr_countries_on = array();
					$arr_countries_on = explode(",", $ad_countries_on);

				  // Look up the countries
					$sql_query_countries = 'SELECT * FROM '.$db_prefix.'countries ORDER by name ASC';
  				$sql_result_countries = $db->select($sql_query_countries);
					while ($sql_row_countries=$db->get_row($sql_result_countries, 'MYSQL_ASSOC')) {

						$ad_country_all_code  = $sql_row_countries['code'];
						$ad_country_all_name  = htmlspecialchars(trim($sql_row_countries['name']));

						// If code is in the array, then show it selected
						$ad_country_all_selected = '';
						if (in_array($ad_country_all_code,$arr_countries_on)){
							$ad_country_all_selected = 'selected';
						}

						echo '<option value="'.$ad_country_all_code.'" '.$ad_country_all_selected.'>'.$ad_country_all_name.'</option>';
					}
				?>
				</select><br>
				<i>Currently Selected Countries:</i><br />
				<?php
				if (count($arr_countries_on) > 0){
					$country_on_list = '';
					foreach($arr_countries_on as $arr_country_on){
						if ($arr_country_on != ''){
              // Lookup Country Name
					    $mysa_country_name_sql_query = 'SELECT name FROM '.$db_prefix.'countries WHERE code=\''.$arr_country_on.'\'';
							$country_name = $db->select_one($mysa_country_name_sql_query);
							$country_on_list .=  $country_name.'<br />';
						}
					}
				} else {
					echo 'None selected';
				}
				if ($country_on_list == '') {
					echo 'None selected';
				} else {
					echo $country_on_list;
				}
				?>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Select one or more countries from the list to display the ad in those countries ONLY.
				<li>To display in all countries (except any listed in the 'do not display' box below), select nothing.
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Display in all countries BUT these
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<select name="ad_countries_off[]" multiple="multiple" size="4">
				<option value =""></option>
				<?php
					// Put the current countries into an array for comparing
					$arr_countries_off = array();
					$arr_countries_off = explode(",", $ad_countries_off);

				  // Look up the countries
					$sql_query_countries = 'SELECT * FROM '.$db_prefix.'countries ORDER by name ASC';
  				$sql_result_countries = $db->select($sql_query_countries);
					while ($sql_row_countries=$db->get_row($sql_result_countries, 'MYSQL_ASSOC')) {

						$ad_country_all_code  = $sql_row_countries['code'];
						$ad_country_all_name  = htmlspecialchars(trim($sql_row_countries['name']));

						// If code is in the array, then show it selected
						$ad_country_all_selected = '';
						if (in_array($ad_country_all_code,$arr_countries_off)){
							$ad_country_all_selected = 'selected';
						}

						echo '<option value="'.$ad_country_all_code.'" '.$ad_country_all_selected.'>'.$ad_country_all_name.'</option>';
					}
				?>
				</select><br>
				<i>Currently Selected Countries:</i><br />
				<?php
				if (count($arr_countries_off) > 0){
					$country_off_list = '';
					foreach($arr_countries_off as $arr_country_off){
						if ($arr_country_off != ''){
              // Lookup Country Name
					    $mysa_country_name_sql_query = 'SELECT name FROM '.$db_prefix.'countries WHERE code=\''.$arr_country_off.'\'';
							$country_name = $db->select_offe($mysa_country_name_sql_query);
							$country_off_list .=  $country_name.'<br />';
						}
					}
				} else {
					echo 'None selected';
				}
				if ($country_off_list == '') {
					echo 'None selected';
				} else {
					echo $country_off_list;
				}
				?>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Select one or more countries from the list to NOT display the ad in those countries.  It will display in all other countries.
 				<li>To display in all countries (or only those specified in the box above), select nothing.
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
	<?php
	}
	?>
	<?php

	if ($config_enable_expiration == 1){
		$ad_expiration_date = trim($sql_row_ad['expiration_date']);
		?>
		<script type="text/javascript" src="js/calendarDateInput.js"></script>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Expiration Date
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<?php
				if ($ad_expiration_date == '') {
				?>
    			<script>DateInput('ad_expiration_date', false, 'YYYY-MM-DD')</script>
				<?php } else { ?>
					<script>DateInput('ad_expiration_date', false, 'YYYY-MM-DD', '<?= $ad_expiration_date; ?>')</script>
				<?php } ?>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Select the date for which the ad should expire.<br>
				<li>To pick a day if none is already selected, first select the month and the rest of the options will appear.
				<li>To remove an expiration date, select the empty option above the 'january' in the month selector.
				<li>On that day the ad's status will be set to disabled on the first attempt to display it.
				</ul>
			</td>
		</tr>
	<?php } ?>	
    <?php if ($ad_impressions > 0){?>
    <tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>" width="25%">
				Lifetime Ad Impressions
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" id="ad_impressions" name="ad_impressions" readonly="true" value="<?= $ad_impressions ?>"> <input type="button" value="Reset" class="button" onClick="resetCounter('ad_impressions')"><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Lifetime ad impressions (separate counter from the montly impressions). Click Reset to reset to zero.
				</ul>
			</td>
		</tr>
    <?php } ?>
    <?php if ($ad_clicks > 0){?>
    <tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>" width="25%">
				Lifetime Ad Clicks
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" id="ad_clicks" name="ad_clicks" readonly="true" value="<?= $ad_clicks ?>"> <input type="button" value="Reset" class="button" onClick="resetCounter('ad_clicks')"><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Lifetime ad clicks. Click Reset to reset to zero.
				</ul>
			</td>
		</tr>
    <?php } ?>
		<tr>
			<td colspan="2"> </td>
		</tr>

		<?php

	$ad_type  = $sql_row_ad['type'];
	if ($ad_type == 0){ // AD Code

		$ad_code_text = trim(stripslashes($sql_row_ad['code_text']));
		?>

		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Ad Code
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<textarea name="ad_code_text" rows="10" cols="50"><?= $ad_code_text ?></textarea><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>The code from the ad provider such as Google AdSense or Yahoo Publisher
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>

		<?php


	} else if ($ad_type == 1){  // Text Link

		$ad_anchor_text = htmlspecialchars(trim(stripslashes($sql_row_ad['anchor_text'])));
		$ad_link_url = htmlspecialchars(trim(stripslashes($sql_row_ad['link_url'])));
		$ad_text_css_class = htmlspecialchars(trim(stripslashes($sql_row_ad['css_class'])));
		$ad_track_clicks = $sql_row_ad['track_clicks'];
		$ad_cookie  = $sql_row_ad['cookie'];
		
		?>

		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Anchor Text
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_anchor_text" value="<?= $ad_anchor_text ?>"><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Anchor text for the text link.
				</ul>
			</td>
		</tr>
  	<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Link URL
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_text_link_url" value="<?= $ad_link_url ?>"><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>URL to link to (include the http://, https://, etc.)
				</ul>
			</td>
		</tr>
    <tr>
			<td colspan="2"> </td>
		</tr>
    <tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				CSS Class
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_text_css_class" value="<?= $ad_text_css_class ?>"><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Name of the CSS Class to format the link
				<li>Can be left blank, which is default
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
    	<td class="title" id="<?php echo $last_tr_id; ?>">
				Track Clicks
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="radio" name="ad_track_clicks_text" value="1" <?php if ($ad_track_clicks==1) { echo 'checked="checked"'; } ?>>Yes<br>
				<input type="radio" name="ad_track_clicks_text" value="0" <?php if ($ad_track_clicks==0) { echo 'checked="checked"'; } ?>>No<br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Click 'Yes' to track clicks on the ad, or 'No' to disable tracking and just use direct linking.
				</ul>
			</td>
    </tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
    	<td class="title" id="<?php echo $last_tr_id; ?>">
				Use Cookie Tracking
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="radio" name="ad_cookie_text" value="1" <?php if ($ad_cookie==1) { echo 'checked="checked"'; } ?>>Yes<br>
				<input type="radio" name="ad_cookie_text" value="0" <?php if ($ad_cookie==0) { echo 'checked="checked"'; } ?>>No<br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Click 'Yes' to use cookies to prevent displaying the ad to the same user, or 'No' to not use cookie tracking.
				<li>The cookie will last for a period set in the Configuration section (or until the user clears their cookies.)
				<li>If there are no other ads to be displayed, or the user has seen them all, this setting will be ignored.
				</ul>
			</td>
    </tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
    <tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
    	<td class="title" id="<?php echo $last_tr_id; ?>"> 
				
			</td>
			<td id="<?php echo $last_tr_id; ?>">
			<?php
			$mysa_sql_query_config = 'SELECT url FROM '.$db_prefix.'config';
      $mysa_sql_result_config = $db->select($mysa_sql_query_config);
			$mysa_sql_row_config = $db->get_row($mysa_sql_result_config, 'MYSQL_ASSOC');
			$mysa_config_url = $mysa_sql_row_config['url'];
			?>
				<INPUT TYPE="button" VALUE="Preview Ad" class="button" onClick="openChild('ad_preview.php?mysa_ad_type='+ads.ad_type.value+'&mysa_ad_track_clicks='+getSelectedRadioValue(ad_track_clicks_text)+'&mysa_ad_cookie='+getSelectedRadioValue(ad_cookie_text)+'&anchor_text='+ads.ad_anchor_text.value+'&css_class='+ads.ad_text_css_class.value+'&link_url='+ads.ad_text_link_url.value+'&mysa_ad_id=<?php echo $ad_id; ?>&mysa_config_url=<?php echo $mysa_config_url; ?>','win2',640,480,'yes')">
			</td>
    </tr>
		<tr>
			<td colspan="2"> </td>
		</tr>

		<?php


	} else if ($ad_type == 2){  // Image banner

		$ad_banner_src = htmlspecialchars(trim(stripslashes($sql_row_ad['banner_src'])));
		$ad_banner_width = $sql_row_ad['banner_width'];
		$ad_banner_height = $sql_row_ad['banner_height'];
		$ad_banner_alt_text = htmlspecialchars(trim(stripslashes($sql_row_ad['banner_alt_text'])));
		$ad_link_url = htmlspecialchars(trim(stripslashes($sql_row_ad['link_url'])));
		$ad_banner_css_class = htmlspecialchars(trim(stripslashes($sql_row_ad['css_class'])));
		$ad_track_clicks = $sql_row_ad['track_clicks'];
		$ad_cookie  = $sql_row_ad['cookie'];
		
		?>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Banner Source URL
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_banner_src" value="<?= $ad_banner_src ?>">
        <input type="button" value="Upload Banner" class="button" onClick="openChild('banner_upload.php','win2',300,200,'no')">
        <br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>URL pointing to the banner image/flash (such as http://localhost/banner.jpg)
				</ul>
			</td>
		</tr>
    <tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Banner Link URL
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_link_url" value="<?= $ad_link_url ?>"><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>URL to link to (include the http://, ftp://, etc.)
				<li><b>Not used for Flash banners - Must send URL in Flash code</b>
				</ul>
			</td>
		</tr>
    <tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Banner Alternate Text
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_banner_alt_text" value="<?= $ad_banner_alt_text ?>"><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Image alternate text for the 'alt' tag
				<li><b>Not used for Flash banners</b>
				</ul>
			</td>
		</tr>
    <tr>
			<td colspan="2"> </td>
		</tr>
    <tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td> </td>
			<td>
				<INPUT TYPE="button" VALUE="Get Image Size" class="button" onClick="openChild('getimagesize.php?url='+ads.ad_banner_src.value,'win2',10,10,'no')">
			</td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Banner Image Height
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_banner_height" size="5" value="<?= $ad_banner_height ?>"><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Height for the banner image
				</ul>
			</td>
		</tr>
    <tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Banner Image Width
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_banner_width" size="5" value="<?= $ad_banner_width ?>"><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Width for the banner image
				</ul>
			</td>
		</tr>
    <tr>
			<td colspan="2"> </td>
		</tr>
    <tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				CSS Class
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_banner_css_class" value="<?= $ad_banner_css_class ?>"><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Name of the CSS Class to format the link
				<li>Can be left blank, which is default
				</ul>
			</td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td colspan="2"> </td>
		</tr>
    <tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
    	<td class="title" id="<?php echo $last_tr_id; ?>">
				Track Clicks
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="radio" name="ad_track_clicks_banner" value="1" <?php if ($ad_track_clicks==1) { echo 'checked="checked"'; } ?>>Yes<br>
				<input type="radio" name="ad_track_clicks_banner" value="0" <?php if ($ad_track_clicks==0) { echo 'checked="checked"'; } ?>>No<br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Click 'Yes' to track clicks on the ad, or 'No' to disable tracking and just use direct linking.
				<li><b>Not used for Flash banners - Must send URL in Flash code</b>
				<li>To track Flash banners: In Flash code, send clicks to http://mysimpleads_install_path/mysa_redir.php?a_id=ADID where ADID is the id of the ad to track
				</ul>
			</td>
    </tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
    	<td class="title" id="<?php echo $last_tr_id; ?>">
				Use Cookie Tracking
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="radio" name="ad_cookie_banner" value="1" <?php if ($ad_cookie==1) { echo 'checked="checked"'; } ?>>Yes<br>
				<input type="radio" name="ad_cookie_banner" value="0" <?php if ($ad_cookie==0) { echo 'checked="checked"'; } ?>>No<br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Click 'Yes' to use cookies to prevent displaying the ad to the same user, or 'No' to not use cookie tracking.
				<li>The cookie will last for a period set in the Configuration section (or until the user clears their cookies.)
				<li>If there are no other ads to be displayed, or the user has seen them all, this setting will be ignored.
				</ul>
			</td>
    </tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
    <tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
    	<td class="title" id="<?php echo $last_tr_id; ?>"> 
				
			</td>
			<td id="<?php echo $last_tr_id; ?>">
			<?php
			$mysa_sql_query_config = 'SELECT url FROM '.$db_prefix.'config';
      $mysa_sql_result_config = $db->select($mysa_sql_query_config);
			$mysa_sql_row_config = $db->get_row($mysa_sql_result_config, 'MYSQL_ASSOC');
			$mysa_config_url = $mysa_sql_row_config['url'];
			?>
				<INPUT TYPE="button" VALUE="Preview Ad" class="button" onClick="openChild('ad_preview.php?mysa_ad_type='+ads.ad_type.value+'&mysa_ad_track_clicks='+getSelectedRadioValue(ad_track_clicks_banner)+'&mysa_ad_cookie='+getSelectedRadioValue(ad_cookie_banner)+'&banner_src='+ads.ad_banner_src.value+'&banner_width='+ads.ad_banner_width.value+'&banner_height='+ads.ad_banner_height.value+'&banner_alt_text='+ads.ad_banner_alt_text.value+'&css_class='+ads.ad_banner_css_class.value+'&link_url='+ads.ad_link_url.value+'&mysa_ad_id=<?php echo $ad_id; ?>&mysa_config_url=<?php echo $mysa_config_url; ?>','win2',640,480,'yes')">
			</td>
    </tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<?php

	}

	?>
		<tr>
			<td colspan="2">
				<input type="submit" class="button" value="Save">  
				<input type="reset" class="button" value="Cancel" onClick="history.back()">
			</td>
		</tr>
    <tr>
			<td colspan="2"> </td>
		</tr>
	</table>
	<input type="hidden" name="ad_type" value="<?php echo $ad_type; ?>">
	</form>
	<?php
}





function ad_create(){
	global $db, $db_prefix, $config_enable_expiration, $config_enable_geo;

	// Row alternating color
	$last_tr_id = 'row2';
	?>
  <script language="JavaScript" type="text/javascript">
	<!--
		function openChild(file,window,width,height,resizable) {
		  childWindow=open(file,window,'resizable='+resizable+',width='+width+',height='+height);
		  if (childWindow.opener == null) childWindow.opener = self;
  	}
    function getSelectedRadio(buttonGroup) {
		   // returns the array number of the selected radio button or -1 if no button is selected
		   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
		      for (var i=0; i<buttonGroup.length; i++) {
		         if (buttonGroup[i].checked) {
		            return i
		         }
		      }
		   } else {
		      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
		   }
		   // if we get to this point, no radio button is selected
		   return -1;
		} // Ends the "getSelectedRadio" function
		function getSelectedRadioValue(buttonGroup) {
		   // returns the value of the selected radio button or "" if no button is selected
		   var i = getSelectedRadio(buttonGroup);
		   if (i == -1) {
		      return "";
		   } else {
		      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
		         return buttonGroup[i].value;
		      } else { // The button group is just the one button, and it is checked
		         return buttonGroup.value;
		      }
		   }
		} // Ends the "getSelectedRadioValue" function
  //-->
  </script>

	<h2>Create a new ad</h2>
	<form name="ads" action="index.php?a=ad_create_save" method="POST">
	<table cellpadding="0" cellspacing="2" border="0" class="table">
	<tr>
	<td>
	<table cellpadding="0" cellspacing="2" border="0" width="100%">
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title"  id="<?php echo $last_tr_id; ?>" width="25%">
				Ad Enabled
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="radio" name="ad_status" value="1" checked="checked">Yes<br>
				<input type="radio" name="ad_status" value="0">No<br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Click 'Yes' to enable the ad, or 'No' to disable the ad.
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>" width="25%">
				Ad Description
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_description" value=""><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Description of the ad (for your reporting purposes only)
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>" width="25%">
				Advertiser
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<select name="ad_advertiser_id">
				<?php
				  // Look up the advertisers
					$sql_query_advertisers = 'SELECT id,description FROM '.$db_prefix.'advertisers ORDER by id ASC';
  				$sql_result_advertisers = $db->select($sql_query_advertisers);
					while ($sql_row_advertisers=$db->get_row($sql_result_advertisers, 'MYSQL_ASSOC')) {

						$ad_advertiser_all_id  = $sql_row_advertisers['id'];
						$ad_advertiser_all_descriptions  = trim($sql_row_advertisers['description']);
						$ad_advertiser_selected = '';
						echo '<option value="'.$ad_advertiser_all_id.'">'.$ad_advertiser_all_descriptions.'</option>';
					}
				?>
				</select><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Select the advertiser (for your reporting purposes only)
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>" width="25%">
				Ad Group
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<select name="ad_group_id[]" multiple="multiple" size="4">
					<option value="0">-none-</option>
				<?php
				  // Look up the groups
					$sql_query_groups = 'SELECT id,description FROM '.$db_prefix.'groups ORDER by id ASC';
  				$sql_result_groups = $db->select($sql_query_groups);
					while ($sql_row_groups=$db->get_row($sql_result_groups, 'MYSQL_ASSOC')) {
						$ad_group_all_id  = $sql_row_groups['id'];
						$ad_group_all_descriptions  = trim($sql_row_groups['description']);
						$ad_group_selected = '';
						echo '<option value="'.$ad_group_all_id.'">'.$ad_group_all_descriptions.'</option>';
					}
				?>
				</select><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Select the ad grouping(s).
				<li>All ads in the same group will be cycled amongst each other.
				<li>Select '-none-' to not have this ad be part of a group.
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
  	<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Ad Weight
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<select name="ad_weight" size="1">
				<?php
					for ($weight_count=10; $weight_count > 0; $weight_count--){
					echo '<option value="'.$weight_count.'">'.$weight_count.'</option>';
				} ?>
				</select><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Select the ad weight for this ad amongst the ads in it's group.
				<li>10 is the highest weight, with this ad being shown as much as possible.
				<li>You can leave all ads at 10 by default to evenly distribute.
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<?php
		if ($config_enable_geo == 1){
		?>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>" width="25%">
				Display in these countries ONLY
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<select name="ad_countries_on[]" multiple="multiple" size="4">
				<option value =""></option>
				<?php
				  // Look up the countries
					$sql_query_countries = 'SELECT * FROM '.$db_prefix.'countries ORDER by name ASC';
  				$sql_result_countries = $db->select($sql_query_countries);
					while ($sql_row_countries=$db->get_row($sql_result_countries, 'MYSQL_ASSOC')) {

						$ad_country_all_code  = $sql_row_countries['code'];
						$ad_country_all_name  = trim($sql_row_countries['name']);
						echo '<option value="'.$ad_country_all_code.'">'.$ad_country_all_name.'</option>';
					}
				?>
				</select><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Select one or more countries from the list to display the ad in those countries ONLY.
				<li>To display in all countries (except any listed in the 'do not display' box below), select nothing.
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>" width="25%">
				Display in all countries BUT these
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<select name="ad_countries_off[]" multiple="multiple" size="4">
				<option value =""></option>
				<?php
				  // Look up the countries
					$sql_query_countries = 'SELECT * FROM '.$db_prefix.'countries ORDER by name ASC';
  				$sql_result_countries = $db->select($sql_query_countries);
					while ($sql_row_countries=$db->get_row($sql_result_countries, 'MYSQL_ASSOC')) {

						$ad_country_all_code  = $sql_row_countries['code'];
						$ad_country_all_name  = trim($sql_row_countries['name']);
						echo '<option value="'.$ad_country_all_code.'">'.$ad_country_all_name.'</option>';
					}
				?>
				</select><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Select one or more countries from the list to NOT display the ad in those countries.  It will display in all other countries.
 				<li>To display in all countries (or only those specified in the box above), select nothing.
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
	<?php
	}
	?>
	<?php

	if ($config_enable_expiration == 1){
		?>
		<script type="text/javascript" src="js/calendarDateInput.js"></script>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>" width="25%">
				Expiration Date
			</td>
			<td id="<?php echo $last_tr_id; ?>">
    		<script>DateInput('ad_expiration_date', false, 'YYYY-MM-DD')</script>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Select the date for which the ad should expire.<br>
				<li>To pick a day if none is already selected, first select the month and the rest of the options will appear.
				<li>To remove an expiration date, select the empty option above the 'january' in the month selector.
				<li>On that day the ad's status will be set to disabled on the first attempt to display it.
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>

		<?php
	}

	?>
	</table>
	<script language=javascript type='text/javascript'>
		function showhide(id){
			if (id=="0") {
				document.getElementById("1").style.display="none";
				document.getElementById("2").style.display="none";
				document.getElementById("0").style.display="";
			}
			if (id=="1") {
				document.getElementById("0").style.display="none";
				document.getElementById("2").style.display="none";
				document.getElementById("1").style.display="";
			}
			if (id=="2") {
				document.getElementById("0").style.display="none";
				document.getElementById("1").style.display="none";
				document.getElementById("2").style.display="";
			}
		}
	</script>
	<table cellpadding="0" cellspacing="2" border="0" width="100%">
	<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
		<td class="title" id="<?php echo $last_tr_id; ?>" width="25%">
			Ad Type
		</td>
		<td id="<?php echo $last_tr_id; ?>">
			<select name="ad_type" onchange="javascript:showhide(ad_type.options[ad_type.selectedIndex].value)">
			<option value="">-Select Type-</option>
			<option value="0">Ad Code</option>
			<option value="1">Text Link</option>
			<option value="2">Image Banner</option>
			</select><br>
			<ul class="ul" id="<?php echo $last_tr_id; ?>">
			<li>Select the type of ad
			</ul>
		</td>
	</tr>
	<tr>
		<td colspan="2"> </td>
	</tr>
	</table>

	<div style="display: none;" id="0">
	<table cellpadding="0" cellspacing="2" border="0" width="100%">
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>" width="25%">
				Ad Code
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<textarea name="ad_code_text" rows="10" cols="50"></textarea><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>The code from the ad provider such as Google AdSense or Yahoo Publisher
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
	</table>
	</div>

	<div style="display: none;" id="1">
	<table cellpadding="0" cellspacing="2" border="0" width="100%">
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>" width="25%">
				Anchor Text
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_anchor_text" value=""><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Anchor text for the text link.
				</ul>
			</td>
		</tr>
    <tr>
			<td colspan="2"> </td>
		</tr>
    <tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Link URL
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_text_link_url" value=""><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>URL to link to (include the http://, ftp://, etc.)
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				CSS Class
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_text_css_class" value=""><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Name of the CSS Class to format the link
				<li>Can be left blank, which is default
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
    <tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
    	<td class="title" id="<?php echo $last_tr_id; ?>">
				Track Clicks
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="radio" name="ad_track_clicks_text" value="1" >Yes<br>
				<input type="radio" name="ad_track_clicks_text" value="0" checked="checked">No<br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Click 'Yes' to track clicks on the ad, or 'No' to disable tracking and just use direct linking.
				</ul>
			</td>
    </tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
    	<td class="title" id="<?php echo $last_tr_id; ?>">
				Use Cookie Tracking
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="radio" name="ad_cookie_text" value="1">Yes<br>
				<input type="radio" name="ad_cookie_text" value="0" checked="checked">No<br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Click 'Yes' to use cookies to prevent displaying the ad to the same user, or 'No' to not use cookie tracking.
				<li>The cookie will last for a period set in the Configuration section (or until the user clear's their cookies.)
				<li>If there are no other ads to be displayed, or the user has seen them all, this setting will be ignored.
				</ul>
			</td>
    </tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
    <tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
    	<td class="title" id="<?php echo $last_tr_id; ?>"> 
				
			</td>
			<td id="<?php echo $last_tr_id; ?>">
			<?php
			$mysa_sql_query_config = 'SELECT url FROM '.$db_prefix.'config';
      $mysa_sql_result_config = $db->select($mysa_sql_query_config);
			$mysa_sql_row_config = $db->get_row($mysa_sql_result_config, 'MYSQL_ASSOC');
			$mysa_config_url = $mysa_sql_row_config['url'];
			?>
				<INPUT TYPE="button" VALUE="Preview Ad" class="button" onClick="openChild('ad_preview.php?mysa_ad_type='+ads.ad_type.value+'&mysa_ad_track_clicks='+getSelectedRadioValue(ad_track_clicks_text)+'&mysa_ad_cookie='+getSelectedRadioValue(ad_cookie_text)+'&anchor_text='+ads.ad_anchor_text.value+'&link_url='+ads.ad_text_link_url.value+'&css_class='+ads.ad_text_css_class.value+'&mysa_ad_id=&mysa_config_url=<?php echo $mysa_config_url; ?>','win2',640,480,'yes')">
			</td>
    </tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
	</table>
	</div>

	<div style="display: none;" id="2">
	<table cellpadding="0" cellspacing="2" border="0" width="100%">
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Banner Source URL
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_banner_src" value="">
        <input type="button" value="Upload Banner" class="button" onClick="openChild('banner_upload.php','win2',300,200,'no')">
        <br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>URL pointing to the banner image/flash (such as http://localhost/banner.jpg)
				</ul>
			</td>
		</tr>
    <tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Banner Link URL
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_link_url" value="">
				<br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>URL to link to (include the http://, ftp://, etc.)
				<li><b>Not used for Flash banners - Must send URL in Flash code</b>
				</ul>
			</td>
		</tr>
    <tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Banner Alternate Text
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_banner_alt_text" value=""><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Image alternate text for the 'alt' tag
				<li><b>Not used for Flash banners</b>
				</ul>
			</td>
		</tr>
    <tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td> </td>
			<td>
				<INPUT TYPE="button" VALUE="Get Image Size" class="button" onClick="openChild('getimagesize.php?url='+ads.ad_banner_src.value,'win2',10,10,'no')">
			</td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Banner Image Height
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_banner_height" size="5" value=""><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Height for the banner image
				</ul>
			</td>
		</tr>
    <tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				Banner Image Width
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_banner_width" size="5" value=""><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Width for the banner image
				</ul>
			</td>
		</tr>
    <tr>
			<td colspan="2"> </td>
		</tr>
    <tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td class="title" id="<?php echo $last_tr_id; ?>">
				CSS Class
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="text" class="textbox" name="ad_banner_css_class" value=""><br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Name of the CSS Class to format the link
				<li>Can be left blank, which is default
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
			<td colspan="2"> </td>
		</tr>
    <tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
    	<td class="title" id="<?php echo $last_tr_id; ?>">
				Track Clicks
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="radio" name="ad_track_clicks_banner" value="1" >Yes<br>
				<input type="radio" name="ad_track_clicks_banner" value="0" checked="checked">No<br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Click 'Yes' to track clicks on the ad, or 'No' to disable tracking and just use direct linking.
				<li><b>Not used for Flash banners - Must send URL in Flash code</b>
				<li>To track Flash banners: In Flash code, send clicks to http://mysimpleads_install_path/mysa_redir.php?a_id=ADID where ADID is the id of the ad to track
				</ul>
			</td>
    </tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
		<tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
    	<td class="title" id="<?php echo $last_tr_id; ?>">
				Use Cookie Tracking
			</td>
			<td id="<?php echo $last_tr_id; ?>">
				<input type="radio" name="ad_cookie_banner" value="1">Yes<br>
				<input type="radio" name="ad_cookie_banner" value="0" checked="checked">No<br>
				<ul class="ul" id="<?php echo $last_tr_id; ?>">
				<li>Click 'Yes' to use cookies to prevent displaying the ad to the same user, or 'No' to not use cookie tracking.
				<li>The cookie will last for a period set in the Configuration section (or until the user clear's their cookies.)
				<li>If there are no other ads to be displayed, or the user has seen them all, this setting will be ignored.
				</ul>
			</td>
    </tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
    <tr valign="top" id="<?php if ($last_tr_id=='row1'){$last_tr_id='row2'; } else { $last_tr_id='row1';} echo $last_tr_id; ?>">
    	<td class="title" id="<?php echo $last_tr_id; ?>"> 
				
			</td>
			<td id="<?php echo $last_tr_id; ?>">
			<?php
			$mysa_sql_query_config = 'SELECT url FROM '.$db_prefix.'config';
      $mysa_sql_result_config = $db->select($mysa_sql_query_config);
			$mysa_sql_row_config = $db->get_row($mysa_sql_result_config, 'MYSQL_ASSOC');
			$mysa_config_url = $mysa_sql_row_config['url'];
			?>
				<INPUT TYPE="button" VALUE="Preview Ad" class="button" onClick="openChild('ad_preview.php?mysa_ad_type='+ads.ad_type.value+'&mysa_ad_track_clicks='+getSelectedRadioValue(ad_track_clicks_banner)+'&mysa_ad_cookie='+getSelectedRadioValue(ad_cookie_banner)+'&banner_src='+ads.ad_banner_src.value+'&banner_width='+ads.ad_banner_width.value+'&banner_height='+ads.ad_banner_height.value+'&banner_alt_text='+ads.ad_banner_alt_text.value+'&link_url='+ads.ad_link_url.value+'&css_class='+ads.ad_banner_css_class.value+'&mysa_ad_id=&mysa_config_url=<?php echo $mysa_config_url; ?>','win2',640,480,'yes')">
			</td>
    </tr>
		<tr>
			<td colspan="2"> </td>
		</tr>

	</table>
	</div>

		<tr>
			<td colspan="2">
				<input type="submit" class="button" value="Save">  
				<input type="reset" class="button" value="Cancel" onClick="history.back()">
			</td>
		</tr>
    <tr>
			<td colspan="2"> </td>
		</tr>
	</td>
	</tr>
	</table>
	</form>
	<?php
}





// Save the ad changes
function ad_save($ad_id){

	global $db, $db_prefix, $config_enable_alerts;

	// Get ad variables from posted form
	$ad_type = $_POST['ad_type'];
	$ad_description = quote_smart(trim($_POST['ad_description']));
	$ad_status = $_POST['ad_status'];
	$ad_advertiser_id = $_POST['ad_advertiser_id'];
	$ad_expiration_date= quote_smart(trim($_POST['ad_expiration_date']));
	$ad_code_text = quote_smart(trim($_POST['ad_code_text']));
	$ad_anchor_text = quote_smart(trim($_POST['ad_anchor_text']));
	$ad_banner_src = quote_smart(trim($_POST['ad_banner_src']));
	$ad_banner_alt_text = quote_smart(trim($_POST['ad_banner_alt_text']));
	$ad_banner_width = $_POST['ad_banner_width'];
	$ad_banner_height = $_POST['ad_banner_height'];
	$ad_link_url = quote_smart(trim($_POST['ad_link_url']));
	if ($ad_link_url == '') {
		$ad_link_url = quote_smart(trim($_POST['ad_text_link_url']));
	}
  $ad_impressions = $_POST['ad_impressions'];
  $ad_clicks = $_POST['ad_clicks'];
	$ad_weight = $_POST['ad_weight'];
  
  $ad_track_clicks = 0;
  $ad_cookie = 0;
	$ad_css_class = '';
  if ($ad_type == 1){
		$ad_track_clicks = $_POST['ad_track_clicks_text'];
		$ad_cookie = $_POST['ad_cookie_text'];
		$ad_css_class = $_POST['ad_text_css_class'];
	}elseif ($ad_type == 2){
		$ad_track_clicks = $_POST['ad_track_clicks_banner'];
		$ad_cookie = $_POST['ad_cookie_banner'];
		$ad_css_class = $_POST['ad_banner_css_class'];
	}

	$message = '';
	// Must put in an ad description
	if ($ad_description == '') {
		$message = 'Please enter a name/description for the ad.';
		?>
    <script language="JavaScript">
			<!--
			alert ("<?= $message; ?>");
			history.back();
			//-->
		</script>
		<?php
		return;
	}

	// Convert country select arrays to a csv format
	$ad_countries_on = '';
	if (isset($_POST['ad_countries_on'])){
	  foreach($_POST['ad_countries_on'] as $ad_countries_on_raw)
	  {
	        $ad_countries_on .= trim($ad_countries_on_raw).',';
	  }
		if ($ad_countries_on != '') { $ad_countries_on = strtolower(rtrim($ad_countries_on, ',')); }
	}

	$ad_countries_off = '';
	if (isset($_POST['ad_countries_off'])){
	  foreach($_POST['ad_countries_off'] as $ad_countries_off_raw)
	  {
	        $ad_countries_off .= trim($ad_countries_off_raw).',';
	  }
		if ($ad_countries_off != '') { $ad_countries_off = strtolower(rtrim($ad_countries_off, ',')); }
	}

	// Convert to integers
	$ad_status += 0;
	$ad_advertiser_id += 0;
	$ad_track_clicks += 0;
	$ad_cookie += 0;
  $ad_banner_width += 0;
	$ad_banner_height += 0;
  $ad_impressions += 0;
  $ad_clicks += 0;
	$ad_weight += 0;

	$ret = '';
	if ($ad_id > -1){ // Update existing ad
		$ad_update_query = 'UPDATE '.$db_prefix.'ads SET ';
		$ad_update_query .= "description = \"$ad_description\",";
		$ad_update_query .= "status = $ad_status,";
		$ad_update_query .= "advertiser_id = $ad_advertiser_id,";
		$ad_update_query .= "expiration_date = \"$ad_expiration_date\",";
		$ad_update_query .= "code_text = \"$ad_code_text\",";
		$ad_update_query .= "anchor_text = \"$ad_anchor_text\",";
		$ad_update_query .= "banner_src = \"$ad_banner_src\",";
		$ad_update_query .= "banner_alt_text = \"$ad_banner_alt_text\",";
		$ad_update_query .= "banner_width = $ad_banner_width,";
		$ad_update_query .= "banner_height = $ad_banner_height,";
		$ad_update_query .= "link_url = \"$ad_link_url\",";
		$ad_update_query .= "css_class = \"$ad_css_class\",";
		$ad_update_query .= "countries_on = \"$ad_countries_on\",";
		$ad_update_query .= "countries_off = \"$ad_countries_off\",";
    $ad_update_query .= "impressions = $ad_impressions,";
    $ad_update_query .= "clicks = $ad_clicks,";
		$ad_update_query .= "track_clicks = $ad_track_clicks,";
		$ad_update_query .= "cookie = $ad_cookie,";
		$ad_update_query .= "weight = $ad_weight";
		$ad_update_query .= " WHERE id = $ad_id";
		$ret = $db->update_sql($ad_update_query);
		if ($ret == false){
			$message = "Error Updating ad.  Please check your database connection";
		} else {
			$message = "Ad updated";
		}

	} else { // Insert new ad

		
    // Must select an ad type
		if ($ad_type == '') {
			$message = 'Please select an ad type.';
			?>
	    <script language="JavaScript">
				<!--
				alert ("<?= $message; ?>");
				history.back();
				//-->
			</script>
			<?php
			return;
		}
		$ad_type += 0;

		$ad_insert_query = 'INSERT INTO '.$db_prefix.'ads ';
		$ad_insert_query .= '(description,status,advertiser_id,expiration_date,';
		$ad_insert_query .= 'code_text,anchor_text,banner_src,banner_alt_text,banner_width,';
		$ad_insert_query .= 'banner_height,link_url,css_class,countries_on,countries_off,type,track_clicks,cookie,weight) VALUES ';
		$ad_insert_query .= "(\"$ad_description\",$ad_status,$ad_advertiser_id,\"$ad_expiration_date\",";
		$ad_insert_query .= "\"$ad_code_text\",\"$ad_anchor_text\",\"$ad_banner_src\",\"$ad_banner_alt_text\",$ad_banner_width,";
		$ad_insert_query .= "$ad_banner_height,\"$ad_link_url\",\"$ad_css_class\",\"$ad_countries_on\",\"$ad_countries_off\",$ad_type,$ad_track_clicks,$ad_cookie,$ad_weight)";

		$ret = $db->insert_sql($ad_insert_query);
		if ($ret == false){
			$message = "Error creating ad.  Please check your database connection";
		} else {
			$message = "Ad Created";
		}

		// Lookup Ad Id
    $mysa_ad_id_sql_query = 'SELECT id FROM '.$db_prefix.'ads ORDER BY id DESC LIMIT 1';
		$ad_id = $db->select_one($mysa_ad_id_sql_query);
	}

	// Update group_ads with ad's groups
	$ad_group_update_query='DELETE FROM '.$db_prefix.'group_ads WHERE ad_id='.$ad_id;
	$ret = $db->update_sql($ad_group_update_query);
	$ad_groups = '';
	if (isset($_POST['ad_group_id'])){
	  foreach($_POST['ad_group_id'] as $group_id)
	  {
	  	$group_id += 0;
			if ($group_id > 0){
		  	$ad_insert_query = 'INSERT INTO '.$db_prefix.'group_ads ';
				$ad_insert_query .= '(group_id,ad_id) VALUES ';
				$ad_insert_query .= "($group_id,$ad_id)";
				$ret = $db->insert_sql($ad_insert_query);
			}
	  }
	}

		?>
		<script language="JavaScript">
			<!--
		<?php if ($config_enable_alerts){ ?>
		alert ("<?= $message; ?>");
		<?php } ?>
			window.location="index.php";
			//-->
		</script>
		<?php

}


// Delete an ad
function ad_delete_confirm($ad_id){
	?>
	<script language="JavaScript">
		<!--
		function confirm_entry()
		{
			input_box=confirm("Delete ad id <?= $ad_id; ?> ?");
			if (input_box==true)

			{
				// Output when OK is clicked
				window.location="index.php?a=ad_delete&id=<?= $ad_id; ?>";
			} else {
				window.location="index.php";
			}

		}
		confirm_entry();
		-->
	</script>
	<?php
}


// Delete an ad
function ad_delete($ad_id){
	global $db, $db_prefix;

	$message = '';

	// Update group_ads with ad's groups
	$ad_group_update_query='DELETE FROM '.$db_prefix.'group_ads WHERE ad_id='.$ad_id;
	$ret = $db->update_sql($ad_group_update_query);

	//mysql_query("DELETE FROM example WHERE age='15'")
	$ad_delete_query = 'DELETE FROM '.$db_prefix.'ads WHERE id='.$ad_id;
	$ret = $db->delete_sql($ad_delete_query);
	if ($ret == false){
		$message = 'Error Deleting ad id '.$ad_id.'.  Please check your database connection';
	} else {
		$message = 'Ad id '.$ad_id.' deleted';
	}

	?>
	<script language="JavaScript">
		<!--
		alert ("<?= $message; ?>");
		window.location="index.php";
		//-->
	</script>

	<?php

}

function ad_code($ad_id){
	global $db, $db_prefix;

  // Look up the ad
	$sql_query_ad = 'SELECT * FROM '.$db_prefix.'ads WHERE id='.$ad_id;
  $sql_result_ad = $db->select($sql_query_ad);
  $sql_row_ad=$db->get_row($sql_result_ad, 'MYSQL_ASSOC');
	$ad_type = $sql_row_ad['type'];

  // Check if member of a group
  $ad_group_id = -1;
  $sql_query_in_groups = 'SELECT group_id FROM '.$db_prefix.'group_ads WHERE ad_id='.$ad_id.' ORDER by group_id ASC';
  $ad_group_id = $db->select_one($sql_query_in_groups);

  $curr_url_path = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
	$last_slash_url_path = substr($curr_url_path,0,strrpos($curr_url_path, '/'));
	$url_path = substr($last_slash_url_path,0,strrpos($last_slash_url_path, '/'));

  $php_ad_insert_code = '';
	if ($ad_group_id > 0 ){
	  $php_ad_insert_code .= '<strong>In Grouping : </strong><br><span class="code" onclick="selectElement(this)">'.highlight_string('<?php include_once("'.mysa_c('path').'/mysimpleads.php");show_ad_group('.$ad_group_id.'); ?>',true)."</span>\n";
  }
	$php_ad_insert_code .= '<br><strong>By Itself : </strong><br><span class="code" onclick="selectElement(this)">'.highlight_string('<?php include_once("'.mysa_c('path').'/mysimpleads.php");show_ad('.$ad_id.'); ?>',true)."</span>\n";
  $php_ad_insert_code .= '<br> <br>Note 1: Make sure that the path to the mysimpleads code in the "include_once" function is correct.';
	$php_ad_insert_code .= '<br> <br>Note 2: If you are inside a PHP block, do not include the '.highlight_string('<?php',true).' and '.highlight_string('?>',true).' tags';

	$php_readfile_code = '';
	if (ini_get("allow_url_fopen")){
		if ($ad_group_id > 0 ){
	  	$php_readfile_code .= '<strong>In Grouping : </strong><br><span class="code" onclick="selectElement(this)">'.highlight_string('<?php @readfile(\'http://'.$url_path.'/mysa_output.php?r=\'.$_SERVER[\'REMOTE_ADDR\'].\'&h=\'.urlencode($_SERVER[\'HTTP_HOST\']).\'&rf=\'.urlencode($_SERVER[\'HTTP_REFERER\']).\'&show_ad_group='.$ad_group_id.'\'); ?>',true)."</span>\n";
		}
	  $php_readfile_code .= '<br><strong>By Itself : </strong><br><span class="code" onclick="selectElement(this)">'.highlight_string('<?php @readfile(\'http://'.$url_path.'/mysa_output.php?r=\'.$_SERVER[\'REMOTE_ADDR\'].\'&h=\'.urlencode($_SERVER[\'HTTP_HOST\']).\'&rf=\'.urlencode($_SERVER[\'HTTP_REFERER\']).\'&show_ad='.$ad_id.'\'); ?>',true)."</span>\n";
		$php_readfile_code .= '<br> <br>Note 1: The PHP ini setting of "allow_url_fopen" must be set to "true" on the host of the site you will be using this code on.  If not, use one of the other two methods.';
		$php_readfile_code .= '<br> <br>Note 2: If you are inside a PHP block, do not include the '.highlight_string('<?php',true).' and '.highlight_string('?>',true).' tags';
	}

	$token = sha1(uniqid(mt_rand()));
  $js_ad_insert_code = '';
	$js_ad_insert_code .= 'Inbetween the '.htmlspecialchars('<head>').' and '.htmlspecialchars('</head>').' tags insert the following line :<br><span class="code" onclick="selectElement(this)">'.htmlspecialchars('<script language="JavaScript" type="text/javascript" src="mysimpleads/mysa_adcode.js"></script>').'</span><br> <br>';
	if ($ad_group_id > 0 ){
		$js_ad_insert_code .= '<strong>In Grouping : </strong><br>';
    $js_ad_insert_code .= '<span class="code" onclick="selectElement(this)">'.htmlspecialchars('<span id="'.$token.'">').'<br>';
		$js_ad_insert_code .= htmlspecialchars('<script language="JavaScript" type="text/javascript">').'<br>';
		$js_ad_insert_code .= htmlspecialchars('/*<![CDATA[*/').'<br>';
		$js_ad_insert_code .= htmlspecialchars('mysa_loadad("http://'.$url_path.'/mysa_output.php?show_ad_group='.$ad_group_id.'","'.$token.'");').'<br>';
		$js_ad_insert_code .= htmlspecialchars('/*]]>*/').'<br>';
		$js_ad_insert_code .= htmlspecialchars('</script></span>').'</span><br>';
	}
  $js_ad_insert_code .= '<strong>By itself : </strong><br>';
  $js_ad_insert_code .= '<span class="code" onclick="selectElement(this)">'.htmlspecialchars('<span id="'.$token.'">').'<br>';
	$js_ad_insert_code .= htmlspecialchars('<script language="JavaScript" type="text/javascript">').'<br>';
	$js_ad_insert_code .= htmlspecialchars('/*<![CDATA[*/').'<br>';
	$js_ad_insert_code .= htmlspecialchars('mysa_loadad("http://'.$url_path.'/mysa_output.php?show_ad='.$ad_id.'","'.$token.'");').'<br>';
	$js_ad_insert_code .= htmlspecialchars('/*]]>*/').'<br>';
	$js_ad_insert_code .= htmlspecialchars('</script></span>').'</span><br>';
	$js_ad_insert_code .= '<br> <br>Note 1: Make sure that the path to the mysimpleads code in the head tags and the "loadad" function is correct in terms of being relative to the location where you will insert this code.';
	$js_ad_insert_code .= '<br> <br>Note 2: You cannot use the javascript injection function to inject text that contains javascript components, such as those in AdSense or YPN code.  Please use PHP for those.';
	
  if ($ad_type > 0){
  	$token = sha1(uniqid(mt_rand()));
		$js_ajax_ad_insert_code = '';
		$js_ajax_ad_insert_code .= 'Inbetween the '.htmlspecialchars('<head>').' and '.htmlspecialchars('</head>').' tags insert the following line :<br><span class="code" onclick="selectElement(this)">'.htmlspecialchars('<script language="JavaScript" type="text/javascript" src="mysimpleads/mysa_adcode.js"></script>').'</span><br> <br>';
		if ($ad_group_id > 0){
      $js_ajax_ad_insert_code .= '<strong>In Grouping : </strong><br>';
      $js_ajax_ad_insert_code .= '<span class="code" onclick="selectElement(this)">'.htmlspecialchars('<span id="'.$token.'">').'<br>';
		  $js_ajax_ad_insert_code .= htmlspecialchars('<script language="JavaScript" type="text/javascript">').'<br>';
		  $js_ajax_ad_insert_code .= htmlspecialchars('/*<![CDATA[*/').'<br>';
		  $js_ajax_ad_insert_code .= htmlspecialchars('mysa_rotate("http://'.$url_path.'/mysa_output.php?show_ad_group='.$ad_group_id.'","'.$token.'",10000);').'<br>';
		  $js_ajax_ad_insert_code .= htmlspecialchars('/*]]>*/').'<br>';
		  $js_ajax_ad_insert_code .= htmlspecialchars('</script></span>').'</span><br>';
    }
    $js_ajax_ad_insert_code .= '<strong>By itself : </strong><br>';
    $js_ajax_ad_insert_code .= '<span class="code" onclick="selectElement(this)">'.htmlspecialchars('<span id="'.$token.'">').'<br>';
	  $js_ajax_ad_insert_code .= htmlspecialchars('<script language="JavaScript" type="text/javascript">').'<br>';
	  $js_ajax_ad_insert_code .= htmlspecialchars('/*<![CDATA[*/').'<br>';
	  $js_ajax_ad_insert_code .= htmlspecialchars('mysa_rotate("http://'.$url_path.'/mysa_output.php?show_ad='.$ad_id.'","'.$token.'",10000);').'<br>';
	  $js_ajax_ad_insert_code .= htmlspecialchars('/*]]>*/').'<br>';
	  $js_ajax_ad_insert_code .= htmlspecialchars('</script></span>').'</span><br>';
	  $js_ajax_ad_insert_code .= '<br> <br>Note 1: Make sure that the path to the mysimpleads code in the head tags and the "loadad" function is correct in terms of being relative to the location where you will insert this code.';
		$js_ajax_ad_insert_code .= '<br> <br>Note 2: You cannot use the Ajax Rotating Banner/Text Links Code to inject text that contains javascript components, such as those in AdSense or YPN code.  Please use PHP for those.';
		$js_ajax_ad_insert_code .= '<br> <br>Note 3: You can change the 10000 to anything you want - it is the number of milliseconds (10 sec * 1000 = 10000) between ad rotations. Do not go less than 5000.';
	}
  
  
  ?>
  <script language=javascript type='text/javascript'>
  function selectElement (element) {
    if (document.selection) {
      var range = document.body.createTextRange();
      range.moveToElementText(element);
      range.select();
    }
    else if (window.getSelection) {
      var range = document.createRange();
      range.selectNodeContents(element);
      var selection = window.getSelection();
      selection.removeAllRanges();
      selection.addRange(range);
   }
  }
  </script>

	<script language=javascript type='text/javascript'>
		function showhide(id){
			if (id=="0") {
				document.getElementById("1").style.display="none";
				document.getElementById("2").style.display="none";
				document.getElementById("0").style.display="";
				document.getElementById("3").style.display="none";
			}
			if (id=="1") {
				document.getElementById("0").style.display="none";
				document.getElementById("2").style.display="none";
				document.getElementById("1").style.display="";
				document.getElementById("3").style.display="none";
			}
			if (id=="2") {
				document.getElementById("0").style.display="none";
				document.getElementById("1").style.display="none";
				document.getElementById("2").style.display="";
				document.getElementById("3").style.display="none";
			}
			if (id=="3") {
				document.getElementById("0").style.display="none";
				document.getElementById("1").style.display="none";
				document.getElementById("2").style.display="none";
				document.getElementById("3").style.display="";
			}
		}
	</script>
	<table cellpadding="0" cellspacing="2" border="0" width="100%">
	<tr valign="top">
		<td class="title">
			Code Type
		</td>
		<td>
			<form>
			<select name="code_type" onchange="javascript:showhide(code_type.options[code_type.selectedIndex].value)">
			<option value="">-Select Code Type-</option>
			<option value="0">PHP Remote Read Code</option>
			<option value="1">PHP Insert Code</option>
			<option value="2">Javascript Injection</option>
			<?php if ($ad_type > 0){?>
					<option value="3">Ajax Rotating Banner/Text Links Code</option>
			<?php } ?>
			</select>
			</form>
			<br>
			<ul class="ul">
			<li>Select the type of code to insert into your page
			<li>If available, utilize the PHP Remote Read code, as it is the most compatible
			</ul>
		</td>
	</tr>
	<tr>
		<td colspan="2"> </td>
	</tr>
	</table>

  <div style="display: none;" id="0">
	<table cellpadding="0" cellspacing="2" border="0" width="100%">
		<tr valign="top">
			<td class="title">
				PHP Remote Read Code
			</td>
			<td>
				<?= $php_readfile_code; ?>
        <br> <br>*<strong>Click on code to highlight for copying</strong>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
	</table>
	</div>
	
	<div style="display: none;" id="1">
	<table cellpadding="0" cellspacing="2" border="0" width="100%">
		<tr valign="top">
			<td class="title">
				PHP Insert Code
			</td>
			<td>
				<?= $php_ad_insert_code; ?>
        <br> <br>*<strong>Click on code to highlight for copying</strong>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
	</table>
	</div>

  <div style="display: none;" id="2">
	<table cellpadding="0" cellspacing="2" border="0" width="100%">
		<tr valign="top">
			<td class="title">
				Javascript Injection Code
			</td>
			<td>
				<?= $js_ad_insert_code; ?>
        <br> <br>*<strong>Click on code to highlight for copying</strong>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
	</table>
	</div>
	
	<div style="display: none;" id="3">
	<table cellpadding="0" cellspacing="2" border="0" width="100%">
		<tr valign="top">
			<td class="title">
				Ajax Rotating Banner/Text Links Code
			</td>
			<td>
				<?= $js_ajax_ad_insert_code; ?>
        <br> <br>*<strong>Click on code to highlight for copying</strong>
			</td>
		</tr>
		<tr>
			<td colspan="2"> </td>
		</tr>
	</table>
	</div>

  <a href="index.php">Back to Ad Listing</a>
	<?php
}

?>
Edited by smile
Link to comment
https://forums.phpfreaks.com/topic/304670-read-code-from-variable/
Share on other sites

<?php @readfile('localhost/mysa_output.php?r='.$_SERVER['REMOTE_ADDR'].'&h='.urlencode($_SERVER['HTTP_HOST']).'&rf='.urlencode($_SERVER['HTTP_REFERER']).'&show_ad=read row id and put here'); ?>
Unless you have a file named exactly that (spoiler: you don't) then it won't work.

 

That ad code is stupid. Really stupid. If there's any way you can avoid or stop using it, please do.

 

If you can't then

 

The best way to do the preview is probably with an iframe.

<iframe src="/mysa_output.php?r=..." width="???" height="???"></iframe>
Fill in the ... that I was too lazy to include, and pick a width and height that makes sense for the ad.

Thank you for quick reply the script is called mySimpleAds, the code for preview is generated by the script to pull the ad specified by ID and place it on some web page.

 

I wish to modify the admin page of the script that is table with all banners there would be preview shown in every row for every ad.

I'm actually not using this for ads at all.

Sorry for my bad english.

 

your iframe methot is not related to my question as I wonder how to pass the ID of a row to the code to generate previews for each orw depending on ID.

 

0vxqs0J.jpg

 

P.S. Why "ad code is stupid. Really stupid. If there's any way you can avoid or stop using it, please do."?

Edited by smile

I tried this, does not pass the ID

<?php @readfile('localhost/mysa_output.php?r='.$_SERVER['REMOTE_ADDR'].'&h='.urlencode($_SERVER['HTTP_HOST']).'&rf='.urlencode($_SERVER['HTTP_REFERER']).'&show_ad=$ad_id'); ?>

does not work.

 

When I look how the ad code button works that shomehow reads proper ID I see this code

<?= $ad_id ?>"><img src="img/code.gif" height="19" width="19" border="0" alt="Ad Code"></a>			</td>
		</tr>

		<?php

    if ($rowclass == 'class = "row1"'){
      $rowclass = 'class = "row2"';
    } else {
      $rowclass = 'class = "row1"';
    }
		$count++;
	}



  ?>

This seems to read the ID then check something and count?

 

how do I make my preview work.

Edited by smile

I'm actually not using this for ads at all.

It's a script for ads. What else could you be using it for?

 

your iframe methot is not related to my question

Strictly speaking, no. But it is related to your problem about getting a preview of the ad (or whatever).

 

P.S. Why "ad code is stupid. Really stupid. If there's any way you can avoid or stop using it, please do."?

1. It gives you instructions to copy and paste PHP code. You should never have to do that.

2. It tells you to use readfile() to a location on your website. That is slow and wasteful.

3. Almost everything named "my" or "simple" is bad.

 

I tried this, does not pass the ID

Not least because you are trying to put a variable into a single-quoted ' string. Variables do not work in single-quoted strings.

 

This seems to read the ID then check something and count?

I don't know why you're showing that. The =$ad_id?> part puts the $ad_id onto the page. That's the right variable for the ID but does not help you get the ID into a string. It will, however, get the ID into the IFRAME I said you need to use - or at least it will when you eventually do that.

 

how do I make my preview work.

Do what I said about using an IFRAME.

pasting just the 

<?= $ad_id ?>

into the row populates the table with row corresponding to its id just like first row

 

rK6vzvG.jpg

 

But does the $ad_id know what ID is a given row is not clear. I'm not a programmer so maybe it's only me why put into the typical ad pull code it does now work

<?php @readfile('localhost/mysa_output.php?r='.$_SERVER['REMOTE_ADDR'].'&h='.urlencode($_SERVER['HTTP_HOST']).'&rf='.urlencode($_SERVER['HTTP_REFERER']).'$ad_id'); ?>
Edited by smile

If you want an image, you have to use an <img> tag.

Just guessing here, but would something like this work:
 

<img src="localhost/mysa_output.php?r=<?=$_SERVER['REMOTE_ADDR']?>&h=<?=urlencode($_SERVER['HTTP_HOST'])?>&rf=<?=urlencode($_SERVER['HTTP_REFERER'])?>&show_ad=<?=$ad_id?>" />

I'm assuming that mysa_output.php actually outputs the image file if the appropriate query string is passed. Knowing how you displayed the ad on your actual webpages (not in the control panel) would be helpful.

-John

The mysa_output.php as I understand outputs whatever user posts into a database cell. I use html code with images and date expiration script. So the mysa_output.php outputs chunk of html code.

 

Your code with img does not work :(

 

Actual code used on pages is (obviously my URL is replaced by localhost here)

<?php @readfile('localhost/mysa_output.php?r='.$_SERVER['REMOTE_ADDR'].'&h='.urlencode($_SERVER['HTTP_HOST']).'&rf='.urlencode($_SERVER['HTTP_REFERER']).'&show_ad=18'); ?> 

What ad to output is specified by ID in this code, If I paste this into my admin backend it work OK. However this as expected outputs same for every row as ID is static.

Edited by smile
  • Solution

If that's the case, then it should be this:

 

<?php @readfile('localhost/mysa_output.php?r='.$_SERVER['REMOTE_ADDR'].'&h='.urlencode($_SERVER['HTTP_HOST']).'&rf='.urlencode($_SERVER['HTTP_REFERER']).'&show_ad='.$ad_id); ?>
Edited by Sepodati
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.