<?php

function get_upload_field($id, $std = '', $desc = '') {

  $field = '<input id="' . $id . '" type="file" name="attachment_' . $id . '" />' .
           '<span class="submit"><input style="width:80%" name="Ines_upload" type="submit" value="Upload" class="button panel-upload-save" />
		   </span> <span class="description"> '. __($desc,'Ines') .' </span>';

  return $field;
}

load_theme_textdomain('Ines');
class Ines {
	function addOptions () {
	
		if (isset($_POST['Ines_reset'])) { Ines::initOptions(true); }
		if (isset($_POST['Ines_save'])) {

			$aOptions = Ines::initOptions(false);
		
			$aOptions['featured1-image'] = stripslashes($_POST['featured1-image']);
			$aOptions['featured1-link'] = stripslashes($_POST['featured1-link']);
			
			$aOptions['featured2-image'] = stripslashes($_POST['featured2-image']);
			$aOptions['featured2-link'] = stripslashes($_POST['featured2-link']);
			
			$aOptions['featured3-image'] = stripslashes($_POST['featured3-image']);
			$aOptions['featured3-link'] = stripslashes($_POST['featured3-link']);
			
			$aOptions['featured4-image'] = stripslashes($_POST['featured4-image']);
			$aOptions['featured4-link'] = stripslashes($_POST['featured4-link']);
			
			$aOptions['featured5-image'] = stripslashes($_POST['featured5-image']);
			$aOptions['featured5-link'] = stripslashes($_POST['featured5-link']);
			
			$aOptions['featured6-image'] = stripslashes($_POST['featured6-image']);
			$aOptions['featured6-link'] = stripslashes($_POST['featured6-link']);
			
      $aOptions['featured7-title'] = stripslashes($_POST['featured7-title']);
			$aOptions['featured7-link'] = stripslashes($_POST['featured7-link']);
      
      $aOptions['featured8-title'] = stripslashes($_POST['featured8-title']);
			$aOptions['featured8-link'] = stripslashes($_POST['featured8-link']);
      
      $aOptions['featured9-title'] = stripslashes($_POST['featured9-title']);
			$aOptions['featured9-link'] = stripslashes($_POST['featured9-link']);	
      
      $aOptions['featured10-title'] = stripslashes($_POST['featured10-title']);
			$aOptions['featured10-link'] = stripslashes($_POST['featured10-link']);
      					
			update_option('Ines_theme', $aOptions);
		}
		if (isset($_POST['Ines_upload'])) {

			$aOptions = Ines::initOptions(false);

            $whitelist = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png');
			
			if (!$_FILES['attachment_featured1-image']['type']=='') { 
				$up_file = 'featured1-image'; 
			}
			
			if (!$_FILES['attachment_featured2-image']['type']=='') { 
				$up_file = 'featured2-image'; 
			}
			
			if (!$_FILES['attachment_featured3-image']['type']=='') { 
				$up_file = 'featured3-image'; 
			}
			
			if (!$_FILES['attachment_featured4-image']['type']=='') { 
				$up_file = 'featured4-image'; 
			}
			
			if (!$_FILES['attachment_featured5-image']['type']=='') { 
				$up_file = 'featured5-image'; 
			}
				if (!$_FILES['attachment_featured6-image']['type']=='') { 
				$up_file = 'featured6-image'; 
			}
			
            $filetype = $_FILES['attachment_' . $up_file]['type'];

            if (in_array($filetype, $whitelist)) {
              $upload = wp_handle_upload($_FILES['attachment_' . $up_file], array('test_form' => false));
			  $aOptions[$up_file] = stripslashes($upload['url']);
			  update_option('Ines_theme', $aOptions);
            }
		}
		add_theme_page("Ines Theme Options", "Ines Theme Options", 'edit_themes', basename(__FILE__), array('Ines', 'displayOptions'));
	}
	function initOptions ($bReset) {
		$aOptions = get_option('Ines_theme');
		if (!is_array($aOptions) || $bReset) {

			$aOptions['featured1-image'] = 'http://dl.dropbox.com/u/1933107/themes/speed/Steam.png';
			$aOptions['featured1-link'] = 'http://milo317.com';
			
			$aOptions['featured2-image'] = 'http://dl.dropbox.com/u/1933107/themes/speed/Steam.png';
			$aOptions['featured2-link'] = 'http://milo317.com';
		
			$aOptions['featured3-image'] = 'http://dl.dropbox.com/u/1933107/themes/speed/Steam.png';
			$aOptions['featured3-link'] = 'http://milo317.com';
			
			$aOptions['featured4-image'] = 'http://dl.dropbox.com/u/1933107/themes/speed/Steam.png';
			$aOptions['featured4-link'] = 'http://milo317.com';
			
			$aOptions['featured5-image'] = 'http://dl.dropbox.com/u/1933107/themes/speed/Steam.png';
			$aOptions['featured5-link'] = 'http://milo317.com';
		
		  $aOptions['featured6-image'] = 'http://dl.dropbox.com/u/1933107/themes/speed/Steam.png';
			$aOptions['featured6-link'] = 'http://milo317.com';
			
			$aOptions['featured7-title'] = 'Members';
			$aOptions['featured7-link'] = '/members/';
			
			$aOptions['featured8-title'] = 'Groups';
			$aOptions['featured8-link'] = '/groups/';
			
			$aOptions['featured9-title'] = 'Forum';
			$aOptions['featured9-link'] = '/forums/';
			
			$aOptions['featured10-title'] = 'Activity';
			$aOptions['featured10-link'] = '/activity/';
			
      					
			update_option('Ines_theme', $aOptions);
		}
		return $aOptions;
	}
	function displayOptions () {
		$aOptions = Ines::initOptions(false);
?>
<div class="wrap">
	<h1>Ines Theme Options</h1>
	
<div style="border-bottom:1px solid #333;"></div>

<h2>Ines Theme options</h2> 
          
    <div style="border-bottom:1px solid #333;"></div>
    <div id="sideblock" style="float:right;width:220px;margin-left:10px;"> 
     <h3>Information</h3>
     <div id="dbx-content" style="text-decoration:none;">       
 			 <img src="<?php bloginfo('stylesheet_directory'); ?>/images/milo.png" /><a style="text-decoration:none;" href="http://3oneseven.com/"> 3oneseven</a><br /><br />
			 <img src="<?php bloginfo('stylesheet_directory'); ?>/images/32s.png" /><a style="text-decoration:none;" href="http://feeds2.feedburner.com/milo317"> Stay updated</a><br /><br />		 	 
			 <img src="<?php bloginfo('stylesheet_directory'); ?>/images/more.png" /><a style="text-decoration:none;" href="http://wp2.milo317.com"> Cool themes by milo317</a><br /><br />
			 <img src="<?php bloginfo('stylesheet_directory'); ?>/images/twit.png" /><a style="text-decoration:none;" href="http://twitter.com/milo317"> Follow updates on Twitter</a><br /><br />			
			 <img src="<?php bloginfo('stylesheet_directory'); ?>/images/idea.png" /><a style="text-decoration:none;" href="http://3oneseven.com/contact/"> Get special customization.</a>
</div>
</div> 
        
    <div style="margin-left:0px;">
    <form action="#" method="post" enctype="multipart/form-data" name="massive_form" id="massive_form">
		<fieldset name="general_options" class="options">
		        
      <h2 style="margin-bottom:0px;">Member Options:</h2>
        <p style="margin-top:0px;">You can add link and title by filling out the fields below.</p>
                               
     <h3>Members</h3>
        Fill in Text for boxes:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured7-title" id="featured7-title" value="<?php echo($aOptions['featured7-title']); ?>"></input>
        </div><br />
    
     Links To:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured7-link" id="featured7-link" size="30" value="<?php echo($aOptions['featured7-link']); ?>"></input>   
        </div><br />
        
          <h3>groups</h3>
        Fill in Text for boxes:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured8-title" id="featured8-title" value="<?php echo($aOptions['featured8-title']); ?>"></input>
        </div><br />
    
     Links To:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured8-link" id="featured8-link" size="30" value="<?php echo($aOptions['featured8-link']); ?>"></input>   
        </div><br />
                    
     <h3>Forums</h3>
        Fill in Text for boxes:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured9-title" id="featured9-title" value="<?php echo($aOptions['featured9-title']); ?>"></input>
        </div><br />
    
     Links To:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured9-link" id="featured9-link" size="30" value="<?php echo($aOptions['featured9-link']); ?>"></input>   
        </div><br />
        
      <h3>Activity</h3>
        Fill in Text for boxes:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured10-title" id="featured10-title" value="<?php echo($aOptions['featured10-title']); ?>"></input>
        </div><br />
    
     Links To:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured10-link" id="featured10-link" size="30" value="<?php echo($aOptions['featured10-link']); ?>"></input>   
        </div><br />   
            
        <div style="border-bottom:1px solid #333;"></div>
        <h2 style="margin-bottom:0px;">Ad Options:</h2>
        <p style="margin-top:0px;">You can add link and images by filling out the fields below.</p>
        		
<h3>ads #1</h3>
       Ad Image Location 150x150 pixels:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured1-image" id="featured1-image" size="30" value="<?php echo($aOptions['featured1-image']); ?>"></input> 
        </div><br />

        or upload an Ad Image Location 150x150 pixels:<br />
		<tr valign="top" class="upload <?php echo ($aOptions['featured1-image']); ?>">
          <th scope="row"><label for="<?php echo ($aOptions['featured1-image']); ?>"><?php echo __($value['name'],'Ines'); ?></label></th>
          <td>
		  <div id='imgupload'>
            <?php print get_upload_field('featured1-image', '', $aOptions['desc']); ?>
			</div>
          </td>
        </tr>
         
        Links To:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured1-link" id="featured1-link" size="30" value="<?php echo($aOptions['featured1-link']); ?>"></input>   
        </div><br />
        
       
		<h3>ads #2</h3>
        Ad Image Location 150x150 pixels:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured2-image" id="featured2-image" size="30" value="<?php echo($aOptions['featured2-image']); ?>"></input> 
        </div><br />

        or upload an Ad Image Location 150x150 pixels:<br />
		<tr valign="top" class="upload <?php echo ($aOptions['featured2-image']); ?>">
          <th scope="row"><label for="<?php echo ($aOptions['featured2-image']); ?>"><?php echo __($value['name'],'Ines'); ?></label></th>
          <td>
		  <div id='imgupload'>
            <?php print get_upload_field('featured2-image', '', $aOptions['desc']); ?>
			</div>
          </td>
        </tr>
        
        Links To:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured2-link" id="featured2-link" size="30" value="<?php echo($aOptions['featured2-link']); ?>"></input>   
        </div><br />
        
<h3>ads #3</h3>
        Ad Image Location 150x150 pixels:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured3-image" id="featured3-image" size="30" value="<?php echo($aOptions['featured3-image']); ?>"></input> 
        </div><br />

        or upload an Ad Image Location 150x150 pixels:<br />
		<tr valign="top" class="upload <?php echo ($aOptions['featured3-image']); ?>">
          <th scope="row"><label for="<?php echo ($aOptions['featured3-image']); ?>"><?php echo __($value['name'],'Ines'); ?></label></th>
          <td>
		  <div id='imgupload'>
            <?php print get_upload_field('featured3-image', '', $aOptions['desc']); ?>
			</div>
          </td>
        </tr>
        
        Links To:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured3-link" id="featured3-link" size="30" value="<?php echo($aOptions['featured3-link']); ?>"></input>   
        </div><br />
        
		<h3>ads #4</h3>
        Ad Image Location 150x150 pixels:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured4-image" id="featured4-image" size="30" value="<?php echo($aOptions['featured4-image']); ?>"></input> 
        </div><br />

        or upload an Ad Image Location 150x150 pixels:<br />
		<tr valign="top" class="upload <?php echo ($aOptions['featured4-image']); ?>">
          <th scope="row"><label for="<?php echo ($aOptions['featured4-image']); ?>"><?php echo __($value['name'],'Ines'); ?></label></th>
          <td>
		  <div id='imgupload'>
            <?php print get_upload_field('featured4-image', '', $aOptions['desc']); ?>
			</div>
          </td>
        </tr>
        
        Links To:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured4-link" id="featured4-link" size="30" value="<?php echo($aOptions['featured4-link']); ?>"></input>   
        </div><br />
        
        
			<h3>ads #5</h3>
        Ad Image Location 150x150 pixels:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured5-image" id="featured5-image" size="30" value="<?php echo($aOptions['featured5-image']); ?>"></input> 
        </div><br />
 
        or upload an Ad Image Location 150x150 pixels:<br />
		<tr valign="top" class="upload <?php echo ($aOptions['featured5-image']); ?>">
          <th scope="row"><label for="<?php echo ($aOptions['featured5-image']); ?>"><?php echo __($value['name'],'Ines'); ?></label></th>
          <td>
		  <div id='imgupload'>
            <?php print get_upload_field('featured5-image', '', $aOptions['desc']); ?>
			</div>
          </td>
        </tr>
       
        Links To:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured5-link" id="featured5-link" size="30" value="<?php echo($aOptions['featured5-link']); ?>"></input>   
        </div><br />
        
       		 
     <h3>ads #6</h3>
       Ad Image Location 150x150 pixels:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured6-image" id="featured6-image" size="30" value="<?php echo($aOptions['featured6-image']); ?>"></input> 
        </div><br />
 
        or upload an Ad Image Location 150x150 pixels:<br />
		<tr valign="top" class="upload <?php echo ($aOptions['featured6-image']); ?>">
          <th scope="row"><label for="<?php echo ($aOptions['featured6-image']); ?>"><?php echo __($value['name'],'Ines'); ?></label></th>
          <td>
		  <div id='imgupload'>
            <?php print get_upload_field('featured6-image', '', $aOptions['desc']); ?>
			</div>
          </td>
        </tr>
        
       Links To:<br />
		<div style="margin:0;padding:0;">
        <input style="width:80%" name="featured6-link" id="featured6-link" size="30" value="<?php echo($aOptions['featured6-link']); ?>"></input>   
        </div><br />
              
<div style="border-bottom:1px solid #333;"></div>
		</fieldset>
		<p class="submit"><input type="submit" name="Ines_reset" value="Reset" /></p>
		<p class="submit"><input type="submit" name="Ines_save" value="Save" /></p>
	</form>      
</div>
<?php
	}
}
// Register functions
add_action('admin_menu', array('Ines', 'addOptions'));
?>