<?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');
  require('includes/classes/split_page_results_event.php');
  tep_get_last_access_file(); 
      $languages = tep_get_languages();
  
    $command=(isset($HTTP_GET_VARS['command'])?tep_db_prepare_input($HTTP_GET_VARS['command']):'');
  $id=(isset($HTTP_GET_VARS['id'])?(int)$HTTP_GET_VARS['id']:'');
  $page=(isset($HTTP_GET_VARS['page'])?(int)$HTTP_GET_VARS['page']:'');
  	
  if($command!=''){
   echo $command . '{}' . $id . '||';
  	switch($command){
		case 'get_details':
			echo do_get_details($id);
		break;
		case 'new':
		case 'edit':
			echo get_edit_details($id);
		break;
		case 'insert':
		case 'update':
			if($command=='insert')
				$id=0;
			echo save_details($id);
		break;	
		case 'delete':
			$status_query = tep_db_query("select count(*) as count from " . TABLE_ORDERS . " where orders_status = '" . (int)$id . "'");
			$status = tep_db_fetch_array($status_query);
	
			$remove_status = true;
			if ($id == DEFAULT_ORDERS_STATUS_ID) {
			  $remove_status = false;
			 $error=ERROR_REMOVE_DEFAULT_ORDER_STATUS;
			} elseif ($status['count'] > 0) {
			  $remove_status = false;
			  $error=ERROR_STATUS_USED_IN_ORDERS;
			} else {
			  $history_query = tep_db_query("select count(*) as count from " . TABLE_ORDERS_STATUS_HISTORY . " where orders_status_id = '" . (int)$id . "'");
			  $history = tep_db_fetch_array($history_query);
			  if ($history['count'] > 0) {
				$remove_status = false;
				$error=ERROR_STATUS_USED_IN_HISTORY;
			  }
			}
			echo delete_details($id,false);
		break;	
		case 'delete_confirm':
			echo delete_details($id,true);
		break;
		case 'page_navigation':
		$search_fnd=false;
			echo get_order_details();
		break;
	}
  	exit;
  }
  
?>
<!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>
    var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
	var prev_id='';
	var prev_page_id='';
	var page_id=1;
	var ajx_start=false;
	var close_obj=false;
	var form_obj=false;
	var row_expand=false;
	var lang=Array();
	
	<?php     for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
    	echo "lang[".$i."]=".$languages[$i]['id'].";\n";
    } ?>
	
	function do_close(id) {
		var head=document.getElementById('head_' + id);
		var data=document.getElementById('data_' + id);
		if(data.style.display=='' && data.innerHTML!='' && close_obj==false)  {
			data.style.display="none";
			data.innerHTML='';
			head.style.display='';
			row_expand=false;
			ajx_start=false;
			prev_id='';
		}
		close_obj=false;
		if(form_obj==true){
			 ajx_start=false;
			 return;
		 }
	}

	function do_page_fetch(id,action){ 
		if(ajx_start) return;
		else {
			ajx_start=true;
		}
		
		if(action!='new' && action!='insert'){
			document.getElementById('new_details').style.display="none";
			document.getElementById('span_new').style.display="none";
			document.getElementById('span_new').innerHTML="";
		}	
		
		document.getElementById('status_id').value=id;
		command='<?php echo tep_href_link(FILENAME_ORDERS_STATUS);?>' + '?command=' + action + '&id=' + id;
		switch(action){ 
			case 'get_details':
				var head=document.getElementById('head_' + id);
				var data=document.getElementById('data_' + id);
				if(prev_id!=id) {
					row_expand=false;
					close_obj=false;
					form_obj=false;
				}
				if(data.style.display=="none" && row_expand==false){
					row_expand=true;
					data.style.display="";
					document.getElementById('data_' + id).innerHTML=document.getElementById('loading').innerHTML;
					if(prev_id!=''){
						document.getElementById('head_' + prev_id).style.display="";
						document.getElementById('data_' + prev_id).innerHTML="";
						document.getElementById('data_' + prev_id).style.display="none";
					}
					prev_id=id;
					head.style.display="none"
					document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
					display_flag=1;
				}
			break;
			case 'new':
				document.getElementById('status_action').value='insert';
				//document.getElementById('ref_action').value='insert';
				if(document.getElementById('span_details')) document.getElementById('span_details').style.display="none";
				if(document.getElementById('span_edit')) document.getElementById('span_edit').style.display="none";
				if(document.getElementById('span_delete')) document.getElementById('span_delete').style.display="none";
					if(prev_id!='' && document.getElementById('head_' + prev_id)){
						document.getElementById('head_' + prev_id).style.display="";
						document.getElementById('data_' + prev_id).innerHTML="";
						document.getElementById('data_' + prev_id).style.display="none";
					}
					prev_id='';
					document.getElementById('new_details').style.display="";
					document.getElementById('span_new').style.display="";
					document.getElementById('span_new').innerHTML=document.getElementById('loading').innerHTML;
					display_flag=0;
					if(document.getElementById('result_found'))document.getElementById('result_found').style.display='none';
			break;
			//case 'new':
			case 'edit': close_obj=true;
				if(action=='new')
					document.getElementById('status_action').value='insert';
				else 
					document.getElementById('status_action').value='update';
				document.getElementById('span_details').style.display="none";
				document.getElementById('span_delete').style.display="none";
				document.getElementById('span_edit').style.display="";
				document.getElementById('span_edit').innerHTML=document.getElementById('loading').innerHTML;
				
			break;
			case 'insert':
				if(prev_id!=''){
					document.getElementById('head_' + prev_id).style.display="";
				 	document.getElementById('data_' + prev_id).style.display="none";
				 }
				prev_id='';
				if(document.getElementById('span_edit')) document.getElementById('span_edit').style.display="none";
				if(document.getElementById('span_details')) document.getElementById('span_details').style.display="none";
				if(document.getElementById('span_delete')) document.getElementById('span_delete').style.display="none";
				do_post_command('status',command);
				return;
			break;
			case 'update':
				document.getElementById('span_edit').style.display="none";
				document.getElementById('span_delete').style.display="none";
				document.getElementById('span_details').style.display="";
				document.getElementById('span_details').innerHTML=document.getElementById('loading').innerHTML;
				do_post_command('status',command);
				return;
			break;
			case 'delete': close_obj=true;
				document.getElementById('status_action').value='delete';
				document.getElementById('span_edit').style.display="none";
				document.getElementById('span_delete').style.display="";
				document.getElementById('span_delete').innerHTML=document.getElementById("loading").innerHTML;
				document.getElementById('span_details').style.display="none";
			break;
			case 'delete_confirm':
				document.getElementById('span_delete').innerHTML=document.getElementById("loading").innerHTML;
				document.getElementById('span_edit').style.display="none";
				document.getElementById('span_details').style.display="none";
				prev_id='';
			break;
			case 'close_status': close_obj=true;
				var span_details=document.getElementById("span_details");
				var span_edit=document.getElementById("span_edit");				
				var span_delete=document.getElementById("span_delete");
				var img_save = document.getElementById('img_save');
				var img_delete = document.getElementById('img_delete');
				document.getElementById('new_details').style.display="none";
				document.getElementById('span_new').style.display="none";
				
				if(span_edit.style.display=="") span_edit.style.display="none";
				if(span_delete.style.display=="") span_delete.style.display="none"; 	 			   	  	 	 			   	  	
				span_details.style.display="";
				if(img_save) img_save.style.display="none"; 
				if(img_delete) img_delete.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';	 	 			   	  			
					 }	 			   	  	  	 			   	  	 	 			   	  	
				ajx_start=false;
			return;
			break;
			case 'close': 
					document.getElementById('new_details').style.display="none";
					document.getElementById('span_new').style.display="none";
					ajx_start=false;
					document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
					display_flag=1;
					if(document.getElementById('result_found'))document.getElementById('result_found').style.display='';
			return;
			break;
		}
		do_get_command(command);
	}
	function do_result(result){ 
		var splt=Array();
		splt=result.split("{}");
		var spl_arr=Array();
		var sp1=splt[1];
		spl_arr=sp1.split("||");
		switch(splt[0]){
			case 'get_details':
				document.getElementById('head_' + spl_arr[0]).style.display="none";
				document.getElementById('data_' + spl_arr[0]).style.display="";
				document.getElementById('data_' + spl_arr[0]).innerHTML=spl_arr[1];
			break;	
			//case 'new':
			case 'edit':
				document.getElementById('img_save').style.display="";
				document.getElementById('img_delete').style.display="none";
				document.getElementById('span_edit').innerHTML=spl_arr[1];
			break;
			case 'update':
				document.getElementById('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';	 	 			   	  			
				}	 			   	  	  	 			   	  	 	 			   	  	
				var details=Array();
				details=spl_arr[1].split("{#}"); 
				if(details[1].substr(0,6)=='#STDE#'){
					var parr=Array();
					var parr=details[1].split('{$}');
					details[1]=parr[0].substr(6);
					if(document.getElementById('head_' + parr[1])) {
					var innerhtml=document.getElementById('head_' + parr[1]).innerHTML;
					document.getElementById('head_' + parr[1]).innerHTML=innerhtml.substr(3,((innerhtml.length)-16));
					}
					}
					document.getElementById('head_' + spl_arr[0]).innerHTML=details[1];	
				document.getElementById('row_heading').innerHTML=details[1];
				document.getElementById('span_details').innerHTML=details[0];
				
			break;
			case 'insert':
				document.getElementById('span_new').style.display="none";
				document.getElementById('span_new').innerHTML="";
				document.getElementById('new_details').style.display="none";
				document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
				var id_value=Array();
				id_value=spl_arr[1].split('{|}');
				var details=Array();
				details=id_value[1].split("{#}");	
				var row=document.getElementById('ref_table');
				var row_obj=row.insertRow(row.rows.length-2);
				var row_len=(row.rows.length-3);
				var cell_obj=row_obj.insertCell(0);
				cell_obj.className="dataTableContent";
				var classname;
				cell_obj.innerHTML=details[0];  
				row_obj.onmouseover=function (){rowOverEffect(this)};
				row_obj.onmouseout=function (){rowOutEffect(this)};
				row_obj.id="row_" + id_value[0];
				row_obj.onclick=function(){ ((document.getElementById("data_" + id_value[0]).style.display=='none')?do_page_fetch(id_value[0],'get_details'):'')};
				if((row_len % 2) == 0) classname="dataTableRowEven";
				else classname="dataTableRowOdd";
				row_obj.className=classname;
				row_obj.height="25px";
				command='<?php echo tep_href_link(FILENAME_ORDERS_STATUS);?>' + '?command=page_navigation&page=1';
				do_get_command(command);
			break;
			case 'new':
				document.getElementById('span_new').innerHTML=spl_arr[1];
			break;
			case 'delete':
				var details=Array();
				details=spl_arr[1].split("{#}");
				if(details[1]=='delete'){
					document.getElementById('img_save').style.display="none";
					document.getElementById('img_delete').style.display="";
				}else
					document.getElementById('img_save').style.display="";
				document.getElementById('span_delete').innerHTML=details[0];
			break;	
			case 'delete_confirm':
				document.getElementById('ref_table').deleteRow(document.getElementById('head_' +spl_arr[0]).parentNode.parentNode.rowIndex);
				command='<?php echo tep_href_link(FILENAME_ORDERS_STATUS);?>' + '?command=page_navigation&page=' + page_id;
				do_get_command(command);
			break;
			case 'page_navigation':
				document.getElementById('ajax_details').innerHTML=spl_arr[1];
			break;
		}
		ajx_start=false;
	}
	
	  var display_flag=1;
	 function do_hover_change(element,eve){ 
		 var span_details=document.getElementById("span_details"); 
		 var span_edit=document.getElementById("span_edit");
		 var span_delete=document.getElementById("span_delete");
	  	 if(element){		   		    		    
		    var img_get_src=element.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';
		  }
		 }		 
	 }  	

	 function do_hover_change_new(element,eve){ 
		 var span_details=document.getElementById("span_details"); 
		 var span_edit=document.getElementById("span_edit");
		 var span_delete=document.getElementById("span_delete");
		 if(display_flag==1){
			if (element.eve && mode==element.eve) return;
			if (eve==2)
				element.firstChild.src=element.firstChild.src.replace(".gif","_hover.gif");
			else
				element.firstChild.src=element.firstChild.src.replace("_hover.gif",".gif");
	 	}
	 }  	

	
	function ValidateForm(){
		close_obj=true;
		var id=document.getElementById('status_id').value;
		var action=document.getElementById('status_action').value;
		if(action=='delete'){
			do_page_fetch(id,'delete_confirm');
			prev_id='';
		} else {
			if(check_form()==true){ 
				form_obj=false;
				if(action=='insert'){
				page_id=1;
					do_page_fetch(0,'insert');
				}else if(action=='update')	{
					do_page_fetch(id,'update');
				}	
			}		
		}
			return false;		
	}
	
	function check_form(){ 
	var error_result='';
		for(i=0,n=lang.length;i<n;i++){
			if( (document.status.elements["orders_status_name[" + lang[i] +"]"].value=='') || (str_trim(document.status.elements["orders_status_name[" + lang[i] +"]"].value)=='') )	{
				error_result+='<?php echo ERR_STATUS_NAME;?>';
				break;
			}	
		}
		if(error_result!=''){
			alert(error_result);
			form_obj=true;
			close_obj=true;
			return false;
		}
		return true;
	}
	
	function do_page_navigation(value,params,name,plink){ 
	if(params=='page_navigation' && document.getElementById("page_''") && plink!=''){
		 page_id = parseInt(document.getElementById("page_''").options[document.getElementById("page_''").selectedIndex].value);
		if(plink=='next')
			page_id=page_id+1;
		else if(plink=='prev')
			page_id=page_id-1;
	}
	prev_page_id=page_id;
	prev_id='';
	command='<?php echo tep_href_link(FILENAME_ORDERS_STATUS);?>' + '?command=page_navigation&page=' + page_id;
	do_get_command(command);
}

</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 //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
	<tr> 
<!-- body_text //-->
		<td width="100%" valign="top">
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td valign="top">
						<table border="0" width="100%" cellspacing="0" cellpadding="0">
							<tr>
								<td valign="top"><?php echo tep_draw_form('status', FILENAME_ORDERS_STATUS, '' , 'post' ,'onSubmit="return ValidateForm();"')?>
									<table border="0" width="100%" cellspacing="0" cellpadding="0">
										<tr class="dataTableHeadingRow"><td>
											<?php echo  '<a id="img_new"   href="javascript:do_page_fetch(\'\',\'new\');" onmouseover="javascript:do_hover_change_new(this,2);" onmouseout="javascript:do_hover_change_new(this,1);">' . tep_image('images/template/img_new.gif','New','22','22') . '</a>';?>
										</td></tr>	
										<tr><td><?php echo tep_draw_separator('pixel_trans.gif','5','5');?></td></tr>
										<tr class="dataTableHeadingRow">
											<td class="dataTableHeadingContent"><?php echo TABLE_HEADING_ORDERS_STATUS; ?></td>
										</tr>
										<div id="loading" style="display:none"><div style="height:30px;margin-left:30px"><img src="images/24-1.gif"></div></div>
										<tr><td id="ajax_details">
											<?php get_order_details(); ?>
										</td></tr>
										<input id="status_id" type="hidden"><input id="status_action" type="hidden">
               						 </table>
								</td>
              				</tr>
            			</table>
					</td>
         		 </tr>
        	</table>
		</td>
      </tr>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

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

function get_order_details(){
	global $page,$languages_id; 
  $orders_status_query_raw = "select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = '" . $languages_id . "' order by orders_status_id desc";
  $orders_status_split = new splitPageResultsEvent($page, MAX_DISPLAY_SEARCH_RESULTS, $orders_status_query_raw, $orders_status_query_numrows);
  $orders_status_query = tep_db_query($orders_status_query_raw); $row=0;
   echo '<table cellpadding="0" cellspacing="0" border="0" width="100%"  id="ref_table">';
   if(tep_db_num_rows($orders_status_query)>0) {
	  while ($orders_status = tep_db_fetch_array($orders_status_query)) {
				if($row %2 ==0) $class="dataTableRowEven";
				else $class="dataTableRowOdd"; $row++;
		  echo '                  <tr id="defaultSelected"  height="25" class="'.$class.'" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="javascript:if(document.getElementById(\'data_' . $orders_status['orders_status_id']. '\').style.display==\'none\') do_page_fetch(\''. $orders_status['orders_status_id'] . '\',\'get_details\');">' . "\n";
					echo '<td  class="dataTableContent"><div id="head_' . $orders_status['orders_status_id'] .'">';
			if (DEFAULT_ORDERS_STATUS_ID == $orders_status['orders_status_id']) {
			  echo '<b>' . $orders_status['orders_status_name'] . ' (' . TEXT_DEFAULT . ')</b>' ;
			} else {
			  echo  $orders_status['orders_status_name'];
			}
	?></div><div id="data_<?php echo $orders_status['orders_status_id'];?>" style="display:none"></div></td>
				  </tr>
<?php
	  }
  } else echo '<tr><td align="center" class="main" id="result_found">' . TEXT_NO_ORDERS_STATUS . '</td></tr>';
  
?>		
				<tr id="new_details" style="display:none" class="openContent">
					<td>	
						<table cellpadding="2" cellspacing="2" border="0" width="100%">
							<tr class="openContent_top">
								<td class="inner_title"><?php echo TEXT_HEADING_NEW_ORDERS_STATUS;?></td>
								<td width="240" align="right"><input type="image" src="images/template/img_savel.gif" alt="save" title="save" border="0">&nbsp;&nbsp;<a href="javascript:do_page_fetch('','close');"><img src="images/template/img_closel.gif" alt="close" title="close" border="0"></a>&nbsp;&nbsp;</td>
							</tr>
							<tr><td><div id="span_new" style="display:none"></div></td></tr>
						</table>
					</td>
				</tr>	
				<tr><td><?php echo tep_draw_separator('pixel_trans.gif','10','10');?></td></tr>
              <tr>
                <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
                  <tr>
                    <td class="smallText" valign="top"><?php echo $orders_status_split->display_count($orders_status_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $page, TEXT_DISPLAY_NUMBER_OF_ORDERS_STATUS); ?></td>
                    <td class="smallText" align="right"><?php echo $orders_status_split->display_script_links($orders_status_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $page,'page_navigation','do_page_navigation(\'\'' ,'\'\''); ?></td>
                  </tr>
				  </table>
				 </td>
				</tr>
			</table>	  
<?php }

	function do_get_details($id){
		global $languages_id,$language;
  		$orders_status_query_raw = tep_db_query("select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = '" . (int)$languages_id . "' and orders_status_id='" . $id . "'");
		$orders_status = tep_db_fetch_array($orders_status_query_raw);	
		if(DEFAULT_ORDERS_STATUS_ID == $orders_status['orders_status_id'])
		{
		 $order_status_name=  $orders_status['orders_status_name'] . ' (' . TEXT_DEFAULT . ')' ;
		 
			} else {
		 $order_status_name=$orders_status['orders_status_name'];
			}  
			
		$result='<table width="100%" border="0" cellspacing="0" cellpadding="0" class="openContent">'.
				'<tr heigth="40" bgcolor="#EDF1FE"  class="openContent_top" onClick="javascript:do_close(\'' . $id . '\');">';  	
		$result.=		  '<td width="40" valign="top" align="center">&nbsp;</td>'.
				  '<td align="left" valign="middle" width="350" class="inner_title" id="row_heading">'. $order_status_name.'</td>'.
				  '<td width="470" align="left" class="main" valign="top">'.
				  	'<table border="0" cellspacing="0" cellpadding="0" style="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>';
							//$result.=	'<td width="10%" onclick="javascript:do_hover_change(this,1);do_page_fetch(\'\',\'new\');" onmouseover="javascript:do_hover_change(this,2);" onmouseout="javascript:do_hover_change(this,1);"><img alt="New" title="New" src="images/template/img_copy.gif"></td>';
					$result.=   '<td width="10%" onclick="javascript:do_hover_change(this,1);do_page_fetch(' . $id . ',\'edit\');" onmouseover="javascript:do_hover_change(this,2);" onmouseout="javascript:do_hover_change(this,3);"><img alt="Edit" title="Edit" src="images/template/img_edit.gif"></td>'.
				  	    '<td width="10%" onclick="javascript:do_hover_change(this,1);do_page_fetch(' . $id . ',\'delete\');" onmouseover="javascript:do_hover_change(this,2);" onmouseout="javascript:do_hover_change(this,3);"><img alt="Delete" title="Delete" src="images/template/img_trash.gif"></td>'.			  	    
				  	    '<td class="cell_bg_popm_right" width="10">&nbsp;</td>'.
				  	  '</tr>'.
				  	'</table>'.
				  '</td>';
			$result.=	 '<td width="240" align="right" id="img_save" style="display:none"><img src="images/template/img_savel.gif" alt="save" title="save" border="0" onClick="javascript:ValidateForm();">&nbsp;&nbsp;<img src="images/template/img_closel.gif" alt="close" title="close" border="0" onClick="javascript:do_page_fetch(' . $id .',\'close_status\');" style="cursor:hand;cursor:pointer">&nbsp;&nbsp;</td>'.
						 '<td width="140" align="right" id="img_delete" style="display:none"><img src="images/template/img_closel.gif" alt="close" title="close" border="0" onClick="javascript:do_page_fetch(' . $id .',\'close_status\');" style="cursor:hand;cursor:pointer"></td>'. 	
				'</tr>';
					$result.= '<tr ><td width="40" valign="top" align="center">&nbsp;</td><td colspan="4"><div id="span_details" class="openContent"><table cellpadding="2" cellspacing="2" border="0" width="100%">';
					$result.='<tr><td colspan="2">' . tep_draw_separator('pixel_trans.gif','10','10') . '</td></tr>';
					$result.='<tr><td class="main" width="125">' . TEXT_INFO_ORDERS_STATUS_NAME . '</td><td class="main">' . $order_status_name . '</td><tr>';
							
					$result.='<tr><td colspan="2">' . tep_draw_separator('pixel_trans.gif','10','10') . '</td></tr></table></div></td></tr>';
					$result.='<tr><td colspan="5"><span id="span_edit" style="display:none" class="openContent">2</span></td></tr>';
					$result.='<tr><td colspan="5"><span id="span_delete" style="display:none" class="openContent">3</span></td></tr>';
			$result .='</table>';
			return $result;
	}
	
	function get_edit_details($id){
		global $languages_id,$languages;
  		$orders_status_query_raw = tep_db_query("select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = '" . $languages_id . "' and orders_status_id='" . $id . "'");
		$orders_status = tep_db_fetch_array($orders_status_query_raw);		  
		  $result.='<table cellpadding="2" cellspacing="2" border="0" width="100%" align="center">'.
		  			'<tr><td width="40" valign="top" align="center">&nbsp;</td><td class="main">' .TEXT_INFO_ORDERS_STATUS_NAME .'<br>' ;
					 for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
							$result1 .= '<br>' . tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('orders_status_name[' . $languages[$i]['id'] . ']', tep_get_orders_status_name($orders_status['orders_status_id'], $languages[$i]['id'])) . '<br>';
						  }	
						 $result.= $result1.'</td></tr>';
      				if (DEFAULT_ORDERS_STATUS_ID != $orders_status['orders_status_id']) $result.= '<tr><td class="main" colspan="2">' . tep_draw_checkbox_field('default') . ' ' . TEXT_SET_DEFAULT . '</td></tr>';
					$result.='<tr><td width="40" valign="top" align="center">&nbsp;</td><td>' . tep_draw_separator('pixel_trans.gif','10','10') . '</td></tr>';
					$result.='</table>';
				return $result;	
	}
	
	function save_details($id){ 
		global $HTTP_POST_VARS,$languages,$languages_id;
		
		 for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
			$orders_status_name_array = $HTTP_POST_VARS['orders_status_name'];
			$language_id = $languages[$i]['id'];
			
            $sql_data_array = array('orders_status_name' => tep_db_prepare_input($orders_status_name_array[$language_id]));
	
			if ($id<=0) {
				if(empty($status_id)){
				  $next_id_query = tep_db_query("select max(orders_status_id) as orders_status_id from " . TABLE_ORDERS_STATUS . "");
				  $next_id = tep_db_fetch_array($next_id_query);
				  $status_id = $next_id['orders_status_id'] + 1;
			  }
			  $sql_data_array['orders_status_id']=$status_id;
			  $sql_data_array['language_id'] = $language_id;
			  if($language_id==$languages_id)
			  	$ids=$status_id;
			  tep_db_perform(TABLE_ORDERS_STATUS, $sql_data_array);
			  $new=true;
			} elseif ($id>0) { 
			  tep_db_perform(TABLE_ORDERS_STATUS, $sql_data_array, 'update', "orders_status_id = '" . $id . "' and language_id='" . $language_id . "'");
			  $new=false;
			}
		}
		if($id<=0){
			$id=$ids;
			echo $id . '{|}';
		}
        if (isset($HTTP_POST_VARS['default']) && ($HTTP_POST_VARS['default'] == 'on')) {
          tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . tep_db_input($id) . "' where configuration_key = 'DEFAULT_ORDERS_STATUS_ID'");
        }
		 echo get_updated_details($id,$new);
		
	}
	function get_updated_details($id,$new){
		global $languages_id;
  		$orders_status_query_raw = tep_db_query("select orders_status_id, orders_status_name from " . TABLE_ORDERS_STATUS . " where language_id = '" . $languages_id . "' and orders_status_id='" . $id . "'");
		$orders_status = tep_db_fetch_array($orders_status_query_raw);		
		$query=tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key='DEFAULT_ORDERS_STATUS_ID'");
		$results=tep_db_fetch_array($query);  
		  
		if($new){
				$result='<div id="head_'. $orders_status['orders_status_id'] .'">'. $orders_status['orders_status_name'].'</div><div id="data_'. $orders_status['orders_status_id'].'" style="display:none"></div>';
		} else {
			$result='<table cellpadding="2" cellspacing="2" border="0" width="100%">';
					$result.='<tr><td colspan="2">' . tep_draw_separator('pixel_trans.gif','10','10') . '</td></tr>';
					$result.='<tr><td class="main" width="125">' . TEXT_INFO_ORDERS_STATUS_NAME . '</td><td class="main">' . $orders_status['orders_status_name'] . '</td><tr>';
					$result.='<tr><td colspan="2">' . tep_draw_separator('pixel_trans.gif','10','10') . '</td></tr></table>';
		} 
		if($results['configuration_value']==$id)
			return $result . '{#}#STDE#' . '<b>' . $orders_status['orders_status_name']  .'(default)</b>'. '{$}' . DEFAULT_ORDERS_STATUS_ID;
		else	
			return $result . '{#}' . $orders_status['orders_status_name'];
	}
	function delete_details($id,$delete){
		global $error,$remove_status;
		if($delete){
       		 tep_db_query("delete from " . TABLE_ORDERS_STATUS . " where orders_status_id = '" . $id . "'");
		} else {
		$result.='<table cellpadding="2" cellspacing="2" border="0" width="100%">'.
					'<tr><td width="15">' . tep_image('images/template/img_trash.gif') . '</td><td class="inner_title">' . TEXT_INFO_HEADING_DELETE_ORDERS_STATUS . '</td></tr>';
					if(!$remove_status)
						$result.='<tr><td width="15"></td><td class="main">' . $error . '</td></tr>';
					else 	
						$result.='<tr><td width="15"></td><td class="main">' . TEXT_INFO_DELETE_INTRO . '</td></tr>';
					$result.='<tr><td colspan="2">'. tep_draw_separator('pixel_trans.gif','10','10') . '</td<tr>'.
					'</table>' ;
					if(!$remove_status)
						return  $result . '{#}'.'delete';
					else 	
						return $result . '{#}';
		}	
	}
	
?>