<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004-2010 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts VistaCart                     |
// +----------------------------------------------------------------------+
// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |
?>
<?php echo $javascript->link('jquery.js'); ?>
<?php echo $javascript->link('hint.js'); ?>
<script>
function clickSearch()
{
	document.frmSearch.submit();
}
</script>

<script>
function validateFields()
{
	var errorstr = '';
	var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	 if($.trim($('#CustomfieldCustomName').val())=='')
		  { 
		    errorstr += "- Please Enter Customfield Name.\n"; 
			msgstr = msgstr + errorstr;
			alert(msgstr);
			$('#CustomfieldCustomName').focus();
			return false;
		 }	
		 else
		 {
		  return true;	
		 } 
} 
</script>

<script>

function showEdit(id)
{
   var total_rows=<?php echo $totrows;?>;
   for(i=0;i<=total_rows;i++)
   {
     if(i==id)
	 {
       $('#edit_txt'+i+'').hide(); $('#edit_lbl'+i+'').show();
	    $('#edit_box'+i+'').show(); 
		$('#btn_lbl'+i+'').show();
	 }
	 else
	 {
	  $('#edit_txt'+i+'').show(); $('#edit_lbl'+i+'').hide(); $('#btn_lbl'+i+'').hide();
	 } 
   }	  
   return false;
}

function validateField(editid,index)
{
  if($.trim($('#edit_box'+index+'').val())=='') 
  {
    alert("Please enter the customfield name");
	$('#edit_box'+index+'').focus();
	return false;
  }
  else	
  {
    $('#editid').val(editid);
	$('#editindex').val(index)	
    return true;
  }		
}

function hideButtons(id)
{
  $('#edit_txt'+id+'').show(); $('#edit_lbl'+id+'').hide(); $('#btn_lbl'+id+'').hide();
  return false;
}
</script>
	
<div align="center" class="subheading">
             <div align="left">Custom Fields
			 <a href="#" class="tooltip" title="In this page, you can add all product variables. For example: if your site sells clothes, you may have a shirt in your product list. The shirt can have different variants or product variables like size (XL,XXL,etc) color (blue, red), and fabric (cotton, polyester)" onclick="return false;">
			 <?php echo $html->image('/img/hint.png', array('border' => 0, 'text-decoration' => 'none'));?>	
			 </a>		
			 </div>
             </div>
             <br />
			 <?php if($session->check('Message.flash')) { ?><div id="okbox"><font color="#446423"><?php $session->flash(); ?></font></div><?php } ?>			
		 <!--Start of items Add area start -->   						
            <div align="left" id="item_details_admin">			                     
								<div align="left" class="inner_content_area_admin">		
								  <!--form area start -->
									<?php echo $form->create('Customfield', array('name' =>'Customfield')); ?>  
									  <div id="admin_heading">Add Custom Field </div>
									  
										  <div id="grid_admin">
											<div align="left" id="inner_leftcontent">
											  <p class="maintext_inner">Custom Field Name </p>
											</div>
                                                                                      <div align="right" id="inner_rightcontent" style="float:left;">
												<span class="toplinks">
													<?php echo $form->input('custom_name', array('label' => '','class' => 'box2_admin','size'=>27));?>
												</span>							
											</div>
											<div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
										  </div>
								  
								  
								
								   
											<div id="admin_bottom">
												<div align="left" id="inner_leftcontent">
												  <p class="maintext_inner">&nbsp;</p>
												</div>
                                                                                            <div align="right" id="inner_rightcontent" style="float:left;">
													<span class="toplinks">
												   <input name="submit" type="submit" class="buttn_admin" onclick="return validateFields();" value="Save" />
													<input name="button" type="button" class="buttn_admin" onclick="javascript:history.go(-1);" value="Cancel" />			
													</span>
												</div>
												<div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
												
									   <?php echo $form->end(); ?> 
								  <!--form area end -->			
								</div>
            </div>
            <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
            <br /> <br /> 	
		 <!--End of items add area -->   
			
			
			
			
			
			
				<!--Search area start -->
					<form action="<?php echo $sitebase.$sitefolder.'/'.$this->params["controller"];?>" method="get" name="frmSearch">
					   <div>
					     <div style=float:left>
							  <select name="cmbSearchType" class="box2_admin">
								<option value="name"  <?php if($cmbSearchType == "name" || $cmbSearchType == ""){ echo("selected"); } ?>>Custom Field Name</option>
								</select> &nbsp;
							<input type="text" name="txtSearch" maxlength="50" value="<?php echo(htmlentities($txtSearch)); ?>"  class="box2_admin">
							</div>
							<div>
							<a style="cursor:pointer" onClick="javascript:clickSearch();"><?php echo $html->image('/img/search_bttn.gif');?></a>
							</div>
	 	             </div>	
	                 <br />							
					</form>	
                 <!--Search area end -->
				
				
				
				<!--items display area start -->
				  <div align="center" id="items_display_area_admin">	
				  <form name="customlist" method="post" action="<?php echo $this->params['controller'];?>/edit">										
							   <div id="list_admin_top">
												<div class="list9"><strong>#</strong></div>
												<div class="list5"><strong><?php echo $paginator->sort('Custom Field', 'custom_name'); ?></strong></div>
												<div class="list6"><strong>Edit/Delete</strong></div>										
												<div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
								</div>

									<?php
									$i=0;
									$j=0;
									if(!empty($passedarg) && !isset($passedarg["page"]))								
									$cnt=1;
									else if(!empty($passedarg) && $passedarg["page"]==1)
									$cnt=1;
									else
									$cnt=((($passedarg["page"]-1)*($passedarg["limit"]))+1);
									if(!empty($customfield)){
									foreach ($customfield as $field){
									?>
										<div id="list_admin">
														<div class="list9"><?php echo $cnt++;?></div>
														<div class="list5">
																<label id="edit_txt<?php echo $j;?>">
																
																<?php echo Sanitize::html(stripslashes($field['Customfield']['custom_name'])); ?>
																</label>
																<label id="edit_lbl<?php echo $j;?>" style="display:none;">
																<input type="text" id="edit_box<?php echo $j;?>"  name="edit_cname<?php echo $j;?>"
                                                                                                                                       value="<?php echo stripslashes($field['Customfield']['custom_name']);?>" />
																</label>			
																<label id="btn_lbl<?php echo $j;?>" style="display:none;">
																<input type="submit" value="Update" onClick="return validateField('<?php echo$field['Customfield']['id'];?>','<?php echo $j;?>');">
																<input type="button" value="Cancel" onClick="return hideButtons('<?php echo $j;?>');">
																</label>
														</div>
														
														<div class="list6">
														<?php echo $html->link("Edit","/customfields/edit/",array("onclick"=>"return showEdit($i)")) ." / ".  $html->link('Delete',"/customfields/delete/".$field['Customfield']['id'],null,'Are you sure you want to delete this CustomField'); ?>
														</div>
														
														<div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
										</div>
								 <?php  
								 $i++;$j++;
								 }  ?>
			 
			                      <div id="admin_bottom">
										<div>
										<?php 
      if($cmbSearchType <> '' &&  $txtSearch <> ''){
       $paginator->options(array('url'=>array_merge(array('cmbSearchType'=>$cmbSearchType,
	   'txtSearch'=>$txtSearch),$this->passedArgs))); }  ?>   
	   
	     <?php echo $paginator->numbers(); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $paginator->counter(); ?>	   
	   
	    </div>																										
										<div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
						          </div>			
			 
							 <?php }  else { ?>
									  <div id="list_admin">
														
														<div>&nbsp;</div>
														<div><strong>Sorry no Custom Fields found!</strong></div>																		
														<div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
										</div>			     
							 <?php } ?>		    
				  <input type="hidden" id="editid" name="editid" value=""/>
                  <input type="hidden" id="editindex" name="editindex" value=""/>
                  </form>
				  <!--items display area end -->	  
				  
				    </div>							
 <div align="left" class="float_clear1"></div>
</div>
 <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div> 