<?php
/*

  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  
  Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd 
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
  require('includes/application_top.php');
  tep_get_last_access_file(); 
  
  global $HTTP_SESSION_VARS, $_SESSION,$HTTP_POST_VARS;
    
  $action=($HTTP_GET_VARS['action'])?tep_db_prepare_input($HTTP_GET_VARS['action']):'';
/*  $actions=($_SESSION['actions_value'])?$_SESSION['actions_value']:'';
  $del_actions=($_SESSION['delete_value'])?$_SESSION['delete_value']:'';
*/
  $actions=($HTTP_POST_VARS['quick'])?tep_db_prepare_input($HTTP_POST_VARS['quick']):'';
  if($actions==''){
  $del_actions=($HTTP_POST_VARS['quick1'])?tep_db_prepare_input($HTTP_POST_VARS['quick1']):''; 
  }

  $links_id=($HTTP_GET_VARS['links_id'])?$HTTP_GET_VARS['links_id']:$HTTP_POST_VARS['links_id'];
  $position=isset($HTTP_GET_VARS['position'])?$HTTP_GET_VARS['position']:1;
  $links_name=($HTTP_GET_VARS['links_name'])?$HTTP_GET_VARS['links_name']:'';
  if($action!=""){
   	  if($action=='get_details'){
		 echo_get_details();
     }else if($action=='new') { 
	  unset($_SESSION['actions_value']);
	  $sql_data_array=array(  'filename' => tep_db_prepare_input($filename),
							  'login_group_id' =>$login_groups_id,
							  'params' => tep_db_prepare_input($params),
							  'title' => tep_db_prepare_input($HTTP_GET_VARS['links_name'])
							  );	
			 tep_db_query("update ". TABLE_QUICK_LINKS. " set sort_order=sort_order+1 where login_group_id='" . $login_groups_id ."'");
		   	 $sort_order_query=tep_db_query("select max(sort_order) as last_sort_order from ". TABLE_QUICK_LINKS. " where login_group_id='". $login_groups_id ."'");
	   		 $sort_order_result=tep_db_fetch_array($sort_order_query);
	   		 $sort_order=((int)$sort_order_result['last_sort_order'])+1;
	   		 $sql_data_array['sort_order']=tep_db_prepare_input($sort_order); 
			tep_db_perform(TABLE_QUICK_LINKS,$sql_data_array);
			$links_id = tep_db_insert_id();
			echo 'new_location';
   	  	    echo_get_details();
	    if(tep_session_is_registered('actions_value'))
	       tep_session_unregister('actions_value');
			exit;
	}else if($action=='cancel'){ 
	    if(tep_session_is_registered('actions_value'))
	      	tep_session_unregister('actions_value');
	    if(tep_session_is_registered('delete_value'))
	     	 tep_session_unregister('delete_value');	
	echo 'cancel^'.$HTTP_GET_VARS['filename'].'^'.$HTTP_GET_VARS['params'].'^'.$HTTP_GET_VARS['links_id'];
	}else if($action=='delete'){ 
	  unset($_SESSION['delete_value']);
		$query=tep_db_query("select * from ".TABLE_QUICK_LINKS ." where filename='". $filename . "' and links_id='" . (int)$HTTP_GET_VARS['links_id'] . "' and  params='". $params. "' and login_group_id='".$login_groups_id."'");
		if(tep_db_num_rows($query)>0){
			$result=tep_db_fetch_array($query);
			$links_id=$result['links_id'];
			$sort_order=$result['sort_order'];
				if($action=='delete'){
				  tep_db_query("update " . TABLE_QUICK_LINKS ." set sort_order= sort_order-1 where sort_order>".$sort_order." and login_group_id='".$login_groups_id ."'");
				  tep_db_query("delete from ".TABLE_QUICK_LINKS ." where links_id='".$links_id."' and login_group_id='". $login_groups_id ."'");
				  echo "deleted".$links_id . '||' ;
				  echo links_details();
				}	
				else	
					$action='';
		}	$HTTP_POST_VARS['links_id']=$links_id;
			$filename=$filename;
			$params=$params;
			$top = "top=1";
	}
	else if($action=='edit_link'){ 
		    $links_info=array('links_id'=>0,
		                        'filename'=>tep_db_prepare_input($HTTP_POST_VARS['filename']),
								'params' => tep_db_prepare_input($HTTP_POST_VARS['params']),
								'login_group_id' =>$login_groups_id,
								'title'=>''
					 			);					 			  
		     if($links_id){
			    $links_info_query=tep_db_query("SELECT * from " . TABLE_QUICK_LINKS . " where links_id='" . (int)$links_id . "' and login_group_id='" . $login_groups_id ."'");
			 	$links_info=tep_db_fetch_array($links_info_query);	
				$cnt=tep_db_num_rows($links_info_query);
			}
		    $lInfo=new objectInfo($links_info);	
		    echo 'edit';
			?>
			<table border="0" width="100%" cellspacing="0" cellpadding="2">
		 	  <tr>
		  		<td>
				<table border="0" cellpadding="5" cellspacing="0" width="100%">
					<tr>
						<td class="main" width="30%" align="right"><?php echo HEADING_LINK_TITLE;?></td>
						<td class="main" width="60%"><input type="text" name="links_name" id="links_name" size="35" maxlength="100" value="<?php echo tep_output_string($lInfo->title); ?>"  class="inputNormal" onBlur="javascript:toggle_focus(this,1);" onClick="javascript:toggle_focus(this,2);" onFocus="javascript:toggle_focus(this,2);"/></td>
					</tr>
					<tr><td><img src='images/pixel_trans.gif' border='0' alt='' width='5' height='15'></td></tr>
				</table>
				</td>
		  	</tr>
		 </table> 
 
<?php }else if($action=='update_link'){
			$links_name=(isset($HTTP_POST_VARS['links_name'])?$HTTP_POST_VARS['links_name']:'');
			$sql_data = array('filename' => tep_db_prepare_input($HTTP_POST_VARS['filename']),
							   'params' => tep_db_prepare_input($HTTP_POST_VARS['params']),
							   'login_group_id' =>$login_groups_id,
							   'title' =>tep_db_prepare_input($links_name)
							 );
			if ($links_id>0 && $HTTP_POST_VARS['action_type']=='edit')  { 
			tep_db_perform(TABLE_QUICK_LINKS, $sql_data, 'update', "links_id = '" . $links_id . "'");
			
			}
			
			echo_get_details();
			
	  }else if($action=='delete_link'){
			$options_string = 'delete';
		 	$options_string .="<table border='0' cellspacing='2' cellpadding='2' width='100%'><tr><td width='17' align='center'>".tep_image('images/template/img_trash.gif').'</td>';
		 	$options_string .='<td width="500" align="left" class="inner_title">'. TEXT_INFO_HEADING_DELETE_LINK . '</td></tr>';
		 	$options_string .='<tr><td></td><td width="500" align="left" class="main">'. TEXT_INFO_DELETE_INTRO . '<br></td></tr></table>';
		 	echo $options_string;
	 }else if($action=='delete_confirm'){   	    
	  	$query=tep_db_query("select sort_order from ". TABLE_QUICK_LINKS ." where links_id='" . (int)$links_id ."' and login_group_id='". $login_groups_id ."'");
		$result=tep_db_fetch_array($query);
		tep_db_query("update " . TABLE_QUICK_LINKS ." set sort_order= sort_order-1 where sort_order>".$result['sort_order']." and login_group_id='".$login_groups_id ."'");
		tep_db_query("delete from ".TABLE_QUICK_LINKS ." where links_id='". (int)$links_id ."' and login_group_id='". $login_groups_id ."'");
		echo "success_delete";
		echo links_details();
	   
	   /* $fetch_query=tep_db_query("select * from " . TABLE_QUICK_LINKS . " where login_group_id='".$login_groups_id ."' and links_id='" . $links_id . "' order by links_id desc ");
				 if (tep_db_num_rows($fetch_query)>0){
		 				?><script type="text/javascript">if(document.getElementById('no_result'))document.getElementById('no_result').style.display='none';</script>
				<?php } else { 
						 ?><script type="text/javascript">if(document.getElementById('no_result'))document.getElementById('no_result').style.display='';</script>
						<?php echo "success_delete"; }  */

	}else if($action=='pos_down' || $action=='pos_up'){ 		
			  $result='sort_order_error';	
			  $position = isset($HTTP_GET_VARS['pos'])?$HTTP_GET_VARS['pos']:0;
			  if (trim($action) == 'pos_up')
					$sort_query=tep_db_query("Select links_id,sort_order from ". TABLE_QUICK_LINKS ." where  sort_order<" .  $position . " order by sort_order desc limit 1");
			  else if($action=='pos_down')
				 	$sort_query=tep_db_query("Select sort_order, links_id from ". TABLE_QUICK_LINKS ." where sort_order>" . $position . " order by sort_order limit 1");
				if (tep_db_num_rows($sort_query)>0){						
						$sort_result = tep_db_fetch_array($sort_query);
						$prev_order=$sort_result['sort_order'];
						$result = tep_db_query("update " . TABLE_QUICK_LINKS . " set sort_order='" . $position ."' where links_id='" . (int)$sort_result['links_id'] . "'");
						if($result<0) $result='error';												
						$result = tep_db_query("update " . TABLE_QUICK_LINKS . " set sort_order='" . (int)$sort_result['sort_order'] . "' where links_id='" . $links_id ."'");
						if($result<0) $result='error';
						$result="sort_order_success".$prev_order;						
			    }	
			   echo $result; 	 	
		 }
	if( ($action!= 'insert') &&  ($action!= 'new')) 
		 exit;
 } 
 function new_data(){ 
 
 global $login_groups_id, $links_id, $filename, $params,  $breadcrumb;
 
// echo "b=" . $breadcrumb . "g_id=" . $login_groups_id . "link_io="  . $links_id . "f_name=" . $filename . "params=" . $params . "<br>";
			$HTTP_POST_VARS['links_id']=$links_id;
			//$filename=$filename . "?";
			//$params=$params . "top=1";
			$filename=$filename;
			$params=$params; 
	 $chk_query = tep_db_query("select count(*) as total from ".TABLE_QUICK_LINKS." where filename='" . tep_db_input($filename) . "'");
 $chk_array = tep_db_fetch_array($chk_query);
 
 if($chk_array['total']<=0){
		
			
	 ?><script type="text/javascript">if(document.getElementById('no_result'))document.getElementById('no_result').style.display='none';</script>
	  <table border="0" width="100%" cellspacing="0" cellpadding="2">
		 	  <tr>
		  		<td>
      			<?php echo tep_draw_form('quick_links_new', FILENAME_QUICK_LINKS, '' ,'post','onsubmit="javascript:new_datas(this);"');?>
				<div id="hide" style="display:block"> 
				<table border="0" cellpadding="5" cellspacing="0" width="100%" align="center" class='openContent_top'>
					<tr>
						<td class="main" align="center"><?php echo "<b>" . TEXT_INFO_HEADING_NEW_LINK . "<b>";?></td>
					</tr>
					<tr>
					   <td class="main" width="40%" align="center"><?php echo TEXT_INFO_LINK_NAME	. '&nbsp;&nbsp;&nbsp;' . tep_draw_input_field('links_name','','size=35 maxlength=100');?></td>
						<td align="left" width="40%"><?php echo tep_image_button('img_savel.gif', IMAGE_SAVE,'style="cursor:pointer;" onclick="javascript:new_datas(this);"') . tep_draw_separator('pixel_trans.gif','10','10') .'&nbsp;' . tep_image_button('cancel.gif', IMAGE_CANCEL,'style="cursor:pointer;" onclick="javascript:drop_datas(this);"');
					?>
					   </td>
					</tr>
					<tr>
					<td class="main" align="center" width="50%">
					<table border="0" cellpadding="1" cellspacing="0" width="100%">
					<tr><td id="params"><?php echo tep_draw_hidden_field('params',$params); ?></td></tr>
					<tr><td id="filename"><?php echo tep_draw_hidden_field('filename',$filename);?></td></tr>
					<tr><td id="links_name" class="main" width="6%"><?php echo tep_draw_hidden_field('links_name',$links_name); ?></td><td class="main" align="center" width="100%"></td></tr>
					<tr><td id="links_id"><?php echo tep_draw_hidden_field('links_id',$links_id);?></td></tr>
					</table></td>
					</tr>
					<tr height="20">
					</tr>
				</table>
				</div>  
				</form>
				</td>
				
		  	</tr> 
		 </table> 
<?php }
}

 function delete_data(){
 global $login_groups_id, $links_id, $filename, $params,  $breadcrumb,$HTTP_POST_VARS;
 
 $chk_query = tep_db_query("select count(*) as total from ".TABLE_QUICK_LINKS." where links_id='$links_id'");
 $chk_array = tep_db_fetch_array($chk_query);
 
 if($chk_array['total']>0){
?>
	 <table border="0" width="100%" cellspacing="0" cellpadding="2">
		 <tr>
		    <td>
        <?php echo tep_draw_form('quick_links_delete', FILENAME_QUICK_LINKS, '' ,'post','onsubmit="javascript:delete_link(this);"');?>
				<div id="delete" style="display:block"> 
				<table border="0" cellpadding="1" cellspacing="0" width="100%" class='openContent_top'>
				    <tr height="20"></tr>
				 	<tr>
					   <td class="main" width="30%" align="center"><font color="#FF0000"><?php echo "Are U Sure To Delete This Link ?";?></font></td>
					   <td width="20%" align="left"><?php echo tep_image_button('img_savel.gif', IMAGE_DELETE,'style="cursor:pointer;" onclick="javascript:delete_link(this);"') . tep_draw_separator('pixel_trans.gif','10','10') .'&nbsp;' . tep_image_button('cancel.gif', IMAGE_CANCEL,'style="cursor:pointer;" onclick="javascript:drop_data_cancel(this);"');?></td>
					</tr>
				  	<tr height="20"></tr>
				<tr><td id="params"><?php echo tep_draw_hidden_field('params',$params); ?></td></tr>
				<tr><td id="filename"><?php echo tep_draw_hidden_field('filename',$filename);?></td></tr>
				<tr><td id="links_id"><?php echo tep_draw_hidden_field('links_id',$links_id);?></td></tr>
				</table>
				</div>
				</form>
			</td>
		 </tr>
			</table> 		
 		<?php }
		}
 
  function echo_get_details(){
  	global $links_id, $login_groups_id,$HTTP_POST_VARS,$HTTP_GET_VARS;
	  $fetch_query=tep_db_query("select * from " . TABLE_QUICK_LINKS . " where login_group_id='".$login_groups_id ."' and links_id='" . $links_id . "' order by links_id desc ");
	//  echo "select * from " . TABLE_QUICK_LINKS . " where login_group_id='".$login_groups_id ."' and links_id='" . $links_id . "' order by links_id desc ";
	  if (tep_db_num_rows($fetch_query)>0){
		  $fetch_result=tep_db_fetch_array($fetch_query);
		  $title=$fetch_result["title"];
		  $links_id = $fetch_result["links_id"];
		  $file_name = $fetch_result["filename"];
		  $params = $fetch_result["params"];
		  $sort_order = $fetch_result["sort_order"];
		  $str_vals.= $title . "||" . $file_name .  "||" . $params . "||" . $sort_order . "||" . $links_id;	
     }else $str_vals = 'No Record Found';
   echo 'get_details'.$str_vals; 	
  }
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script language="javascript" src="includes/http.js"></script>
<script language="javascript">
var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
var max_display="<?php echo MAX_DISPLAY_SEARCH_RESULTS;?>";
var server_date="<?php echo getServerDate();?>";
  function new_datas(frm){
	var  error_result="";
	var links_name = document.getElementById("links_name").value;
	var params = document.getElementById("params").value;
 	var filename = document.getElementById("filename").value; 
	if(links_name=="" || str_trim(links_name)=="") {
	     error_result+="<?php echo tep_output_string(ERR_TITLE_NAME); ?>\n";		      
    		if (error_result!=""){
         		alert(error_result);
	 			return false;
	  		}
	} 
	ids="&links_name="+links_name;	
	command="<?php echo tep_href_link(FILENAME_QUICK_LINKS,'action=new');?>"+ids;
	do_get_command(command);
	if(document.getElementById("actions_flag")) document.getElementById("actions_flag").value="";
	if(document.getElementById("hide")) document.getElementById("hide").style.display="none"
	return false;
  }
  function drop_datas(frm){	
	if(document.getElementById("quick_action_insert")) document.getElementById("quick_action_insert").style.display="";
	srm=document.quick_links_new;
	var ids="";
	var params = srm.params.value;
 	var filename = srm.filename.value; 
	var links_id = srm.links_id.value;  
	ids="&filename="+filename+"&params="+params+"&links_id="+links_id;	
	command="<?php echo tep_href_link(FILENAME_QUICK_LINKS,'action=cancel');?>"+ids;
	do_get_command(command);
	if(document.getElementById("actions_flag")) document.getElementById("actions_flag").value="";
	if(document.getElementById("hide")) document.getElementById("hide").style.display='none';
	return false;
  } 
  
  function delete_link(frm){
	srm=document.quick_links_delete;
	var ids="";
	var params = srm.params.value;
 	var filename = srm.filename.value; 
	var links_id = srm.links_id.value;  
	ids="&filename="+filename+"&params="+params+"&links_id="+links_id;	
	command="<?php echo tep_href_link(FILENAME_QUICK_LINKS,'action=delete');?>"+ids;
	do_get_command(command);
	if(document.getElementById("delete")) document.getElementById("delete").style.display='none';
	return false;
  }
  function drop_data_cancel(frm){
	if(document.getElementById("quick_action_delete")) document.getElementById("quick_action_delete").style.display="";
	srm=document.quick_links_delete;
	var ids="";
	var params = srm.params.value;
 	var filename = srm.filename.value; 
	var links_id = srm.links_id.value;  
	ids="&filename="+filename+"&params="+params+"&links_id="+links_id;	
	command="<?php echo tep_href_link(FILENAME_QUICK_LINKS,'action=cancel');?>"+ids;
	do_get_command(command);
	if(document.getElementById("delete")) document.getElementById("delete").style.display='none';
	return false;
  } 
  function validateForm(lfrm){
      var error_result="";
      if(lfrm.action_type) var action_type=lfrm.action_type.value;
	  if(lfrm && lfrm.links_id) id=lfrm.links_id.value;
	  var span_details=document.getElementById("span_details");
	  var span_edit=document.getElementById("span_edit");				
	  var span_delete=document.getElementById("span_delete");
	  var loadings=document.getElementById("loading");
	  var ids="";	  	

	  if(span_edit.style.display==""){		  		  
			  if ( (lfrm.links_name.value=="") || (str_trim(lfrm.links_name.value)=="") ) 
				   error_result+="<?php echo tep_output_string(ERR_TITLE_NAME); ?>\n";		      
      if (error_result!=""){
         alert(error_result);
	 	 return false;
      }else if(span_edit.style.display==""){      							
			if(lfrm.action_type && lfrm.action_type.value=='edit')  ids="&links_id="+id;
			command="<?php echo tep_href_link(FILENAME_QUICK_LINKS,'action=update_link','NONSSL',true,false);?>"+ids;
			if(loadings) loadings.style.display="";
			if(span_edit) span_edit.style.display="none";
       }
	 }else if(span_delete.style.display==""){      							
			ids="&links_id="+id;
			command="<?php echo tep_href_link(FILENAME_QUICK_LINKS,'action=delete_confirm');?>"+ids;
			if(loadings) loadings.style.display="";
			if(span_delete) span_delete.style.display="none";
     }
	do_post_command('quick_links',command);
    return false;
   }   
var previous_id='';
function expand_category(id,category,r_type,sta){ 
		//if(category==3 && document.getElementById('head_'+id) && document.getElementById('head_'+id).style.display!='none' && document.getElementById("span_edit") && document.getElementById("span_edit").style.display=='none' && document.getElementById("span_delete") && document.getElementById("span_delete").style.display=='none') return;
		var frm=document.quick_links;
 	 	var res_display=document.getElementById("res_display"); 	 	 	 	 	 	 	 	 	 		 	  	 	
 	 	if(res_display) res_display.style.display="none"; 	 		 	 	
 	 	 if(frm && frm.links_id && frm.links_id.value>0)  {
			var old_ids=frm.links_id.value;			
			var pre_data_id=document.getElementById("data_"+old_ids);
			var pre_head=document.getElementById("head_"+old_ids);			
			var loadings=document.getElementById("loading");
			if(loadings) loadings.style.display="none";
		 }		 	 
			if(id>0 && frm.links_id.value>0 && frm.links_id.value!=id){			   
			   if(pre_head && pre_head.style.display=="") pre_head.style.display="none";
			   if(pre_data_id && pre_data_id.style.display=="none") pre_data_id.style.display="";
			   frm.links_id.value=id;			   
			}							
		if(category!=1 && frm && frm.links_id && frm.links_id.value=="") frm.links_id.value=id;		 								 	 	 	 
 	 	if(category){
 	 		var span_details=document.getElementById("span_details");
 	 		var span_edit=document.getElementById("span_edit");			
			var span_delete=document.getElementById("span_delete");								
			var data_id=document.getElementById("data_"+id);						
			var head=document.getElementById("head_"+id);
			var img_save=document.getElementById("img_save");			
			var command="";																		 
			
			switch(category){
 	 			case 3:
 	 			   if(head && head.style.display==""){
 	 			   	  if(span_details.style.display==""){
 	 			   	    head.style.display="none"; 	 			   	    
 	 			   	  	data_id.style.display=""; 	 			   	  	
 	 			   	  }else {
 	 			   	  	if(span_edit.style.display=="") span_edit.style.display="none";
 	 			   	  	if(span_delete.style.display=="") span_delete.style.display="none"; 
 	 			   	  	if(document.getElementById('img_update'))
			       		  document.getElementById('img_update').style.display='';
						span_details.style.display="";
 	 			   	  	if(img_save) img_save.style.display="none"; 
 	 			   	  	if(document.getElementById("img_ids")){
 	 			   	  		var tr_obj=document.getElementById("img_ids");
							if(tr_obj.childNodes[1].childNodes[0].src==img_src+'template/img_edit_hover.gif')	
 	 			   	  			tr_obj.childNodes[1].childNodes[0].src=img_src+'template/img_edit.gif';
 	 			   	  		if(tr_obj.childNodes[2].childNodes[0].src==img_src+'template/img_trash_hover.gif')	
 	 			   	  			tr_obj.childNodes[2].childNodes[0].src=img_src+'template/img_trash.gif';
 	 			   	  		if(tr_obj.childNodes[3].childNodes[0].src==img_src+'template/img_move_hover.gif')	
 	 			   	  			tr_obj.childNodes[3].childNodes[0].src=img_src+'template/img_move.gif';	 	 			   	  			
						}	 			   	  	  	 			   	  	 	 			   	  	
 	 			   	  }	 	 			    			   	   	 			   
 	 			 }else { 	 		
				 	if(previous_id!='')
						if(document.getElementById('head_'+previous_id))
							document.getElementById('head_'+previous_id).innerHTML='';	 	 	 			 	
 	 			 	if(data_id && data_id.style.display=="") data_id.style.display="none";
 	 			 	if(pre_head && pre_head.style.display=="") pre_head.style.display="none"; 	 			 	
 	 			 	if(head) {
 	 			 	 	head.style.display=""; 	 
 	 			 		head.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";	 			 		
 	 			 	}
 	 			 	command="<?php echo tep_href_link(FILENAME_QUICK_LINKS,'action=get_details');?>&links_id="+id; 	 			 	
					previous_id=id;
				 }
 	 			break;
 	 			case 4:
 	 					span_edit.style.display=""; 	 					
 	 					span_details.style.display=span_delete.style.display="none";
						if(document.getElementById('img_update'))
			        		 document.getElementById('img_update').style.display='none';
						span_edit.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 					if(frm.action_type) frm.action_type.value='edit'; 	 					
 	 					command="<?php echo tep_href_link(FILENAME_QUICK_LINKS,'action=edit_link');?>&links_id="+id; 
 	 			break; 	 			
 	 			case 5:	 	 				 	 				 	 		 	 				
 	 					span_delete.style.display="";
 	 					span_edit.style.display=span_details.style.display="none";
						span_delete.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 					command="<?php echo tep_href_link(FILENAME_QUICK_LINKS,'action=delete_link');?>&links_id="+id; 	 	 	 					 	 					 	 			
				break;
 	 			case 6:
 	 				 document.getElementById('img_update').style.display='';
					 span_edit.style.display=""; 	 					
 	 				 span_details.style.display=span_delete.style.display="none";
 	 				 span_edit.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
 	 				 var filename = document.getElementById('filename').value;
					 var params = document.getElementById('params').value;
					 var url = filename+"?"+params+"&top=1";
					 document.location.href = url;
 	 			break; 	
				case 7:
				case 8:
					var s_order=document.quick_links.sort_order;															
 	 				if(document.getElementById('img_save')) document.getElementById('img_save').style.display='none';
					if(head) var tbl_tr_obj=head.parentNode.parentNode;																									
					var pos_cnt=0;																																	
					pos="pos_up";
					if(category==7) pos="pos_down";
					command="<?php echo tep_href_link(FILENAME_QUICK_LINKS);?>?links_id="+id+"&pos="+r_type+"&action="+pos;					
					if(document.getElementById('img_save'))
			        	document.getElementById('img_save').style.display='none';
					if(s_order) s_order.value=pos;					
					var tpl_cnt=tbl_tr_obj.parentNode.rows.length;
					tpl_cnt=tpl_cnt-2;										
					if(tbl_tr_obj && (tbl_tr_obj.rowIndex==0 && pos=='pos_up' || tpl_cnt==tbl_tr_obj.rowIndex && pos=='pos_down')) return;
				break;		
				
				case 9:
				 if(head && data_id){
		 	 			  	head.style.display="none";
		 	 			  	head.innerHTML="";
		 	 			  	data_id.style.display="";	
		 	 			  } 
				break;
				
												
 	 		}
		   if(command!="") do_get_command(command);
 	 	}	
 	 }
	 
 	function do_result(result){  
		 if(result.substr(0,11)=='get_details'){
		 print_details('get_details',result.substr(11));}
		 else if(result.substr(0,12)=='new_location') print_details('new_location',result.substr(23));
		 else if(result.substr(0,14)=='success_delete') print_details('success_delete',result.substr(14));
		 else if(result.substr(0,5)=='close') print_details('close',result.substr(5));
		 else if(result.substr(0,7)=='deleted') print_details('deleted',result.substr(7));
	     else  if(result.substr(0,4)=='edit') print_details('edit',result.substr(4));
		 else if(result.substr(0,6)=='delete') print_details('delete',result.substr(6));
		 else if(result.substr(0,16)=='sort_order_error') print_details('sort_order_error',result.substr(16));
		 else if(result.substr(0,18)=='sort_order_success') print_details('sort_order_success',result.substr(18));
	var token=result.split('^');
	if(token[0]=='cancel'){ 
		file_name=token[1];
		param_s=token[2];
		url = file_name+'?'+param_s+'&top=1';
		location.href=url;
	  }
	}
   function print_details(category,result){	 
 	 	var no_result="";
 	 	var frm=document.quick_links;
 	    if(result!='' && result.length>0 && category!='edit'){
			splt_str=result.split("||"); 			  		
			var title = "";
			var filename="";
			var sort_order="";
			var params="";
			var id="";
			title = splt_str[0];
			filename = splt_str[1]; 	
			params = splt_str[2];
			sort_order = splt_str[3]; 
			id = splt_str[4];
 	 	}	  	 		  	 		 	 	 	  	 		 	  	 
 		if(frm && frm.links_id) var id=frm.links_id.value; 
 		var span_details=document.getElementById("span_details");	
 		var span_edit=document.getElementById("span_edit"); 	 		 	 		
 		var span_delete=document.getElementById("span_delete");				 	
 		var head=document.getElementById("head_"+id); 		 		 		  
 		var data_id=document.getElementById("data_"+id);
 		var res_display=document.getElementById("res_display");
 		var equip=document.getElementById("equip");
 		var img_save=document.getElementById("img_save");
		if(img_save && category!='get_details') img_save.style.display="";	
		switch(category){ 	 		 	 		 	 		 	 		
 	 		case 'get_details':
			document.getElementById('filename').value=filename;
			document.getElementById('params').value=params;
 	 	    if(head && no_result==""){	 	 		
	 	 		head.style.display="";
				if(data_id){		 	 		
		 	 		data_id.innerHTML='<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
						         '<tbody><tr>'+
						         	'<td class="dataTableContent" width="30%" align="left">'+title+'</td>'+
						         '</tr>'+
						      '</tbody></table>';	
	 	 		} 	 	 			
	 	 		include ="<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				"<tr heigth='40' class='openContent_top'>"+				  				  							  
				  "<td width='10' onclick='javascript:expand_category("+id+",9);'></td>"+				  							  
				  "<td width='30' valign='top' align='center'><a href='javascript:expand_category("+id+",8,"+sort_order+");'><img border='0' src='images/template/img_arrow_up.gif' alt='Up' title='Up'></a>&nbsp;<a href='javascript:expand_category("+id+",7,"+sort_order+");'><img border='0' src='images/template/img_arrow_down.gif' alt='Down' title='Down'></a></td>"+
				  "<td width='40' valign='top' align='center' onclick='javascript:expand_category("+id+",9);'>&nbsp;</td>"+
				  "<td valign='middle' width='300' class='inner_title' onclick='javascript:expand_category("+id+",9);'>"+title+"</td>"+
				  "<td width='100' align='left' class='main' valign='top'>"+
				  	"<table border='0' cellspacing='0' cellpadding='0' style='cursor:pointer;width:100;height:30px;display:inline;position:relative;'>"+
				  	  "<tr class='img_move' id='img_ids'>"+
				  	  	"<td class='cell_bg_popm_left' width='10'>&nbsp;</td>"+
				  	    "<td width='10%' onclick='javascript:change_class(this,1);expand_category("+id+",4)'; onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='Edit' title='Edit' src='images/template/img_edit.gif'></td>"+
				  	    "<td width='10%' onclick='javascript:change_class(this,1);expand_category("+id+",5)'; onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='Delete' title='Delete' src='images/template/img_trash.gif'></td>"+				  	    
				  	    "<td width='10%' id='img_update' onclick=javascript:change_class(this,1);expand_category('"+filename+"',6); onmouseover='javascript:change_class(this,2);' onmouseout='javascript:change_class(this,3);'><img alt='Go to' title='Go to' src='images/template/img_move.gif'></td>"+				  	    
						"<td class='cell_bg_popm_right' width='10'>&nbsp;</td>"+
				  	  "</tr>"+
				  	"</table>"+
				  "</td><td width='240'  onclick='javascript:expand_category("+id+",9);'>&nbsp;</td>"+
				 "<td width='80' align='right' id='img_save' style='display:none'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href=javascript:expand_category("+id+",3);><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</td>"+
				"</tr>"+
				"<tr style='height:10'><td id='loading' style='display:none' colspan='5'><img src='images/24-1.gif' alt='Loading...' title='Loading...'></td></tr>"+				
				"<tr>"+
				  "<td colspan='8' class='main'><span style='display:none' id='span_edit'></span><span style='display:none' id='span_delete'></span><span id='span_details'>"+	"<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				  		"<tr>"+
				  			"<td width='100'>&nbsp;</td>"+				  							  			
							"<td width='100%'>"+			  							  			
				  				"<table width='100%' border='0' cellspacing='0' cellpadding='2' class='main'>";				  														
										include+="<tr>"+
											"<td align='left' width='40'></td>"+
											"<td align='center' width='10'><b><?php echo TEXT_INFO_FILENAME;?></b></td>"+
											"<td align='left' width='20'>"+filename+"</td>"+
										"<tr>";
				  			  include+="</table></td>"+
								"</tr><tr><td><img src='images/pixel_trans.gif' border='0' alt='' width='5' height='20'></td></tr>";
							 "</table>"; 
					"</span>"+
				  "</td>"+
				"</tr>"+
			"</table>";
			head.innerHTML=include;
 	 		} 	 			 	 		
 	 	break;
 	 	case 'edit': 	 		 	 		 	 		 	 		
			if(span_edit) span_edit.style.display="";			
 	 		if(span_edit && span_details){
 	 			span_edit.innerHTML=result; 	 			
 	 			span_details.style.display='none';
 	 		}									  
 	// 	toggle_panel('Equipment:_','false','','0');	     					 		  												
 	 	break;
 	 	case 'delete': 	 				 	 	
 	 		if(span_delete) span_delete.style.display="";
 	 		if(span_delete){ 	 			
 	 			span_delete.innerHTML=result; 	 			
 	 			span_details.style.display=span_edit.style.display='none';
 	 		} 	 								   			   
 	 	break; 	 	
 	 	case 'success_delete':			 
			 if(head && data_id) {
			 	var tbl_obj=head.parentNode.parentNode.parentNode.parentNode;			 				 				 	
			 	if(tbl_obj) tbl_obj.deleteRow(head.parentNode.parentNode.rowIndex);
			 	data_id.innerHTML=head.innerHTML="";
			 	data_id.style.display=head.style.display="none";			 				 			
			} 
			 if(res_display){ 
	    	 	res_display.innerHTML="<?php echo TEXT_DELETE_SUCCESS;?>";
 	    	 	res_display.style.display="";
			 }
			 document.getElementById('ajax_details').innerHTML=title;
 	 	break;
 	 	case 'deleted':	
			 	var tbl_obj = document.getElementById("tbl");
				if(tbl_obj) tbl_obj.deleteRow(document.getElementById("data_"+title).parentNode.parentNode.rowIndex);
				document.getElementById('ajax_details').innerHTML=filename;

 	 	break;
		case 'new_location':
				var len=1;
				if(result!=""){
					result_splt=result.split('||');
					if(result_splt[4]>0){						
							var title=result_splt[0];	
							var id=result_splt[4];						   						
    						var tbl_obj=document.getElementById("tbl");							
    						var row_obj=tbl_obj.insertRow(tbl_obj.rows.length);
    						var row_cell=row_obj.insertCell(0);							
    						row_cell.innerHTML='<div id="data_'+id+'">'+
						       '<table border="0" cellpadding="0" cellspacing="0" width="100%">'+
						         '<tbody><tr>'+
						         	'<td class="dataTableContent" width="150" align="left">'+title+'</td>'+
						         '</tr>'+
						      '</tbody></table>'+
						      '</div>'+
						      '<div style="display:none;" class="openContent" id="head_'+id+'"></div>';
    						var rows_cnt=tbl_obj.rows.length-1;
    						var tbl=tbl_obj.rows[rows_cnt];
    						tbl.onclick=function () {((document.getElementById("head_"+id) && document.getElementById("head_"+id).style.display=='none')?expand_category(id,3):'')};
    						tbl.style.height="25px"; 
    						if(rows_cnt%2==0) tbl.className="dataTableRowOdd";
    						else tbl.className="dataTableRowEven";
    						tbl.onmouseover=function (){rowOverEffect(this)};
    						tbl.onmouseout=function (){rowOutEffect(this)};
    						if(head && data_id){
    							head.style.display="none";
    							data_id.style.display="";
    						}
    						if(res_display){
					    	 res_display.innerHTML="<?php echo LINK_INSERT_SUCCESSFULLY ;?>";
				 	    	 res_display.style.display=""; 	    	 	
 	    	 				}						    					
					}
				}																			 						
		break;
		
		case 'sort_order_success':
		case 'sort_order_error':
			
			if(document.quick_links.sort_order) var s_order=document.quick_links.sort_order.value;															
 	 		if(document.getElementById('img_save')) document.getElementById('img_save').style.display='none';
			if(category=='sort_order_success'){			  			   
			   if(head)  {
				var tbl_obj=head.parentNode.parentNode;
				var up_href=head.childNodes[0].childNodes[0].childNodes[0].childNodes[2].childNodes[0];
			    var down_href=head.childNodes[0].childNodes[0].childNodes[0].childNodes[2].childNodes[2];			    
			    var new_pos=result.substr(result.indexOf('sort_order_success'));			    
			    if(up_href && down_href && new_pos){
					up_href.href="javascript:expand_category("+id+",8,"+new_pos+")";
					down_href.href="javascript:expand_category("+id+",7,"+new_pos+")";
			    }
				var x=1;
				if(s_order && s_order!="" && s_order=="pos_up") x=-1;								
				var row=tbl_obj;
				var index=row.rowIndex;
				var count=tbl_obj.parentNode.rows.length;				
				if (x==-1 && index==0) return;
				if (x==1 && index==count-1) return;
				if (x==-1){
				   row.parentNode.insertBefore(row,row.parentNode.rows[index-1]);
				} else {
					if (index==row.parentNode.rows.length-2)
						row.parentNode.appendChild(row);
					else
						row.parentNode.insertBefore(row,row.parentNode.rows[index+2]);
				}																 							
  		      }			   			   					            	            	      		               	      	    	 	 			  
			}else if(category=='sort_order_error'){
				res_display.style.display=""; 	    	 	
			    res_display.innerHTML="<?php echo ERROR_IN_DATABASE_TRY_AGAIN;?>"; 	    	 	 	    	 	 	    	 	 	    	 	 
			}
		break;
	  } 
 	 	if(res_display.style.display=="") setTimeout("res_display.style.display='none'",2000); 	 	 	 	
 	 	clearTimeout();
	  }
	
	 function change_class(obj,eve){ 		 	 	
		 var span_details=document.getElementById("span_details"); 
		 var span_edit=document.getElementById("span_edit");
		 var span_delete=document.getElementById("span_delete");				 		 			 
		 if(obj){		   		    		    
		    var img_get_src=obj.childNodes[0];
			if(img_get_src){
			    if(img_get_src.src==img_src+'template/img_edit.gif') {
					if(span_edit && span_edit.style.display=="" && eve==1 || eve==2){ 
					 	img_get_src.src=img_src+'template/img_edit_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_edit_hover.gif' && span_edit && span_edit.style.display=="none") img_get_src.src=img_src+'template/img_edit.gif';
			    if(img_get_src.src==img_src+'template/img_trash.gif') {
					if(span_delete && span_delete.style.display=="" && eve==1 || eve==2){ 
					 	img_get_src.src=img_src+'template/img_trash_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_trash_hover.gif' && span_delete && span_delete.style.display=="none") img_get_src.src=img_src+'template/img_trash.gif';		    		    		     		   	
			    if(img_get_src.src==img_src+'template/img_move.gif') {
					if(span_edit && span_edit.style.display=="" && eve==1 || eve==2){ 
					 	img_get_src.src=img_src+'template/img_move_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_move_hover.gif' && span_edit && span_edit.style.display=="none") img_get_src.src=img_src+'template/img_move.gif';
			}
		 }		 
	  }
</script>	  	
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<!-- body //-->

<!-- header_eof //-->
<?php  //echo 'Hai welcome to Quick links';  ?>
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr> 
<!-- body_text //-->
    <td width="100%" valign="top">
		<table border="0" cellspacing="0" cellpadding="0" width=100%>
	 <tr><td>
      <?php echo tep_draw_form('quick_links', FILENAME_QUICK_LINKS, '' ,'post','onsubmit="javascript:return validateForm(this);"');?>
	 <table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr><td id="res_display" class="main" style="display:none"></td></tr>
			  <tr class="dataTableHeadingRow" height="20" valign="top">
					<td class="dataTableHeadingContent"><?php echo HEADING_LINK_TITLE; ?></td>
					<td class="dataTableHeadingContent" align="center">&nbsp;</td>
				<!--	<td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td> !-->
              </tr>
			  <tr></tr>
			  <tr>
			  <?php
			    unset($_SESSION['actions_value']); ?>
        	   <td colspan="3" id="ajax_details">		
		  		 <?php links_details();?>
			   </td>
			  </tr> 
			</table>  	
		<input type="hidden" name="filename" id="filename">
		<input type="hidden" name="params" id="params">
        <input type="hidden" name="links_id" id="links_id">
	    <input type="hidden" name="action_type" id="action_type">
    	<input type="hidden" id="sort_order">
	    <input type="hidden" name="icnt" id="icnt">
		<input type="hidden" name="actions_flag" id="actions_flag" value="<?php echo tep_output_string($_SESSION['actions_value']);?>">
        </form>
       </td>      
<!-- body_text_eof //-->
<!-- body_eof //-->
      </tr>
  </table></td>
  </tr>
  </table>
  
 
  
  <?php //echo 'Post Vars='; print_r($HTTP_POST_VARS);
//  echo '<script language="javascript">alert("' . print_r($HTTP_POST_VARS) . '");<\/script>';
  if( ($actions=='insert') && ($HTTP_POST_VARS['quick']=='insert') && ($HTTP_POST_VARS['quick1']=='') ){ 
	new_data(); 
  }  
  if( ($del_actions=='delete') && ($HTTP_POST_VARS['quick1']=='delete') && ($HTTP_POST_VARS['quick']=='') ){ 
 	   delete_data();
   }  ?>		
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer //-->
</body>
</html>
<?php require('includes/application_bottom.php');

function links_details(){ 
	global $login_groups_id;
?>
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="tbl">
					<?php
				 	 $links_sql = "select * from " . TABLE_QUICK_LINKS . " where login_group_id='".$login_groups_id ."' order by sort_order" ;
					
					 $links_query = tep_db_query($links_sql);
	  				 $rows=0;
					 if(tep_db_num_rows($links_query)>0){ 
				 	 while ($links = tep_db_fetch_array($links_query)) {
					 $class_name="dataTableRowEven";
  				     if($rows%2==0) $class_name="dataTableRowOdd"; 
						 $rows++;					
						 $class_name=(($class_name=='dataTableRowOdd')?'dataTableRowEven':'dataTabkeRowOdd');
						 if ((!isset($HTTP_GET_VARS['links_id']) || (isset($links_id) && ($links_id == $links['links_id']))) && !isset($cInfo)) {
					 	 $cInfo = new objectInfo($links);
						}
			 		 echo '<tr class="'.$class_name.'" style="height:25" onmouseover="rowOverEffect(this);" onmouseout="rowOutEffect(this);" onclick="javascript:if(document.getElementById(\'head_'.$links['links_id'].'\').style.display==\'none\') expand_category(' . $links['links_id'] . ',3);">' . "\n"; 
					?>	
						  <td colspan="4" width="100%">
							<div id="data_<?php echo $links['links_id'];?>">
							 <table border="0" cellspacing="0" cellpadding="0" width="100%">
								<tr style="cursor:pointer;">
									<td class='dataTableContent' width="150" align="left"><?php echo $links['title'] ; ?> </td>
								</tr>
							 </table>
							</div>
							<div class="openContent" id="head_<?php echo $links['links_id'];?>" style="display:none"></div>
						  </td>					      
						</tr>
					<?php
					  }
			 		}else echo '<tr><td class="smallText" id="no_result">'.TEXT_EMPTY_LINKS.'</td></tr>'; 
				   ?>
				</table><?php }
?>
	