<?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();
	require(DIR_WS_CLASSES . 'currencies.php');
	$currencies = new currencies();
	$currency=DEFAULT_CURRENCY;
	$server_date = getServerDate(true);
	$language_query=tep_db_query("select * from ".TABLE_LANGUAGES );
	$language_count=tep_db_num_rows($language_query);
	$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
	if(EVENTS_DATE_FORMAT=="Y-m-d")
		$date_format="%Y-%m-%d";
	else if(EVENTS_DATE_FORMAT=="m-d-Y")
		$date_format="%m-%d-%Y";
	else if(EVENTS_DATE_FORMAT=="d-m-Y")	
		$date_format="%d-%m-%Y";
	$current_date=getServerDate();
  if (tep_not_null($action)) {
	switch ($action) {
		case 'new_service_category':
		case 'edit_service_category':
			if (ALLOW_CATEGORY_DESCRIPTIONS == 'true')
				$HTTP_GET_VARS['action']=$HTTP_GET_VARS['action'] . '_ACD';
			break;
		case 'insert_service_category':
		case 'update_service_category':
			if ( ($HTTP_POST_VARS['edit_x']) || ($HTTP_POST_VARS['edit_y']) ) {
				$HTTP_GET_VARS['action'] = 'edit_service_category_ACD';
			} else {
				if (isset($HTTP_POST_VARS['services_categories_id'])) $services_categories_id = tep_db_prepare_input($HTTP_POST_VARS['services_categories_id']);
				
				// for edit get the update id
				if ($services_categories_id == '') {
					$services_categories_id = tep_db_prepare_input($HTTP_GET_VARS['secID']);
				}

				$sort_order = ((int)$HTTP_POST_VARS['sort_order']!=0?tep_db_prepare_input($HTTP_POST_VARS['sort_order']):1);
				
				$sql_data_array = array('sort_order' => $sort_order);
				
				// insert the category
				if ($action == 'insert_service_category') {
					$insert_sql_data = array(	'parent_id' => $current_service_category_id,
												'date_added' => $server_date);
				
					$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
			
					tep_db_perform(TABLE_SERVICES_CATEGORIES, $sql_data_array);
				
					$services_categories_id = tep_db_insert_id();
					
				} elseif ($action == 'update_service_category') {
					
					$update_sql_data = array('last_modified' => $server_date);
				
					$sql_data_array = array_merge($sql_data_array, $update_sql_data);
				
					tep_db_perform(TABLE_SERVICES_CATEGORIES, $sql_data_array, 'update', "services_categories_id = '" . (int)$services_categories_id . "'");
				}
				// update the service category description
				$languages = tep_get_languages();
				for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
					$services_categories_name_array = $HTTP_POST_VARS['services_categories_name'];
					$language_id = $languages[$i]['id'];
					$sql_data_array = array('services_categories_name' => tep_db_prepare_input($services_categories_name_array[$language_id]));
								
					if (ALLOW_CATEGORY_DESCRIPTIONS == 'true') {
						$sql_data_array = array('services_categories_name' => tep_db_prepare_input($HTTP_POST_VARS['services_categories_name'][$language_id]),
												'services_categories_heading_title' => tep_db_prepare_input($HTTP_POST_VARS['services_categories_heading_title'][$language_id]),
												'services_categories_description' => tep_db_prepare_input($HTTP_POST_VARS['services_categories_description'][$language_id]),
												'services_categories_notes' => tep_db_prepare_input($HTTP_POST_VARS['services_categories_notes'][$language_id]));
					}
					// insert the category
					if ($action == 'insert_service_category') {
						$insert_sql_data = array(	'services_categories_id' => $services_categories_id,
													'language_id' => $languages[$i]['id']);
					
						$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
					
						tep_db_perform(TABLE_SERVICES_CATEGORIES_DESCRIPTION, $sql_data_array);
					} elseif ($action == 'update_service_category') { //update the category
						tep_db_perform(TABLE_SERVICES_CATEGORIES_DESCRIPTION, $sql_data_array, 'update', "services_categories_id = '" . (int)$services_categories_id . "' and language_id = '" . (int)$languages[$i]['id'] . "'");
					}
				}
				// update the services categories image
				if (ALLOW_CATEGORY_DESCRIPTIONS == 'true') {
					tep_db_query("update " . TABLE_SERVICES_CATEGORIES . " set services_categories_image = '" . $HTTP_POST_VARS['services_categories_image'] . "' where services_categories_id = '" .  (int)tep_db_input($services_categories_id) . "'");
					$services_categories_image = '';
				} else {
					if ($services_categories_image = new upload('services_categories_image', DIR_FS_CATALOG_IMAGES)) {
						tep_db_query("update " . TABLE_SERVICES_CATEGORIES . " set services_categories_image = '" . tep_db_input($services_categories_image->filename) . "' where services_categories_id = '" . (int)$services_categories_id . "'");
					}
				}

				if (isset($secPath))
					tep_redirect(tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&secID=' . $services_categories_id));
				else
					tep_redirect(tep_href_link(FILENAME_SERVICES, 'secID=' . $services_categories_id));

        	}
			break;
		case 'delete_service_category_confirm': // delete the service_category
			if (isset($HTTP_POST_VARS['services_categories_id'])) {
				$services_categories_id = tep_db_prepare_input($HTTP_POST_VARS['services_categories_id']);
				$services_categories = tep_get_services_category_tree($services_categories_id, '', '0', '', true);
				$service = array();
				$service_delete = array();
				
				//get the service details belong to the deleted category
				for ($i=0, $n=sizeof($services_categories); $i<$n; $i++) {
					$service_ids_query = tep_db_query("SELECT service_id from " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " where services_categories_id = '" . (int)$services_categories[$i]['id'] . "'");
					while ($service_ids = tep_db_fetch_array($service_ids_query)) {
						$service[$service_ids['service_id']]['services_categories'][] = $services_categories[$i]['id'];
					}
				}

				reset($service);
				while (list($key, $value) = each($service)) {
					$service_category_ids = '';
				
					for ($i=0, $n=sizeof($value['services_categories']); $i<$n; $i++) {
						$service_category_ids .= "'" . (int)$service['services_categories'][$i] . "', ";
					}
					$service_category_ids = substr($service_category_ids, 0, -2);
					$check_query = tep_db_query("SELECT count(*) as total from " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " where service_id = '" . (int)$key . "' and services_categories_id not in (" . $service_category_ids . ")");
					$check = tep_db_fetch_array($check_query);
					if ($check['total'] < '1') {
						$service_delete[$key] = $key;
					}
				}
				tep_set_time_limit(0);

				for ($i=0, $n=sizeof($services_categories); $i<$n; $i++) {
					tep_remove_service_category($services_categories[$i]['id']);
				}

				reset($service_delete);
				while (list($key) = each($service_delete)) {
					tep_remove_service($key);
				}
			}
				tep_redirect(tep_href_link(FILENAME_SERVICES,'secPath=' . $secPath));
				break;
			case 'move_service_category_confirm':
				if (isset($HTTP_POST_VARS['services_categories_id']) && ($HTTP_POST_VARS['services_categories_id'] != $HTTP_POST_VARS['move_to_service_category_id'])) {
					$services_categories_id = tep_db_prepare_input($HTTP_POST_VARS['services_categories_id']);
					$new_parent_id = tep_db_prepare_input($HTTP_POST_VARS['move_to_service_category_id']);
					
					$path = explode('_', tep_get_generated_service_category_path_ids($new_parent_id));
					// check if the directory to move is a child category
					if (in_array($services_categories_id, $path)) {
						$messageStack->add_session(ERROR_CANNOT_MOVE_SERVICES_CATEGORY_TO_PARENT, 'error');
						tep_redirect(tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&secID=' . $services_categories_id));
					} else {
						tep_db_query("update " . TABLE_SERVICES_CATEGORIES . " set parent_id = '" . (int)$new_parent_id . "', last_modified ='". $server_date ."' where services_categories_id = '" . (int)$services_categories_id . "'");
						tep_redirect(tep_href_link(FILENAME_SERVICES, 'secID=' . $services_categories_id));
					}
				}
				break;
			case 'new_service':
			case 'edit_service':
				if (ALLOW_CATEGORY_DESCRIPTIONS == 'true')
					$HTTP_GET_VARS['action']=$HTTP_GET_VARS['action'] . '_ACD';
				break;

			case 'setflag':
				// set the service status
				if ( ($HTTP_GET_VARS['flag'] == '0') || ($HTTP_GET_VARS['flag'] == '1') ) {
					if (isset($HTTP_GET_VARS['seID'])) {
						tep_set_service_status($HTTP_GET_VARS['seID'], $HTTP_GET_VARS['flag']);
					}
		
				}
				tep_redirect(tep_href_link(FILENAME_SERVICES, 'secPath=' . $HTTP_GET_VARS['secPath'] . 'seID=' . $HTTP_GET_VARS['seID']));
				break;
			case 'insert_service':
			case 'update_service':
				//PR Algozone: copy image only if modified
				$service_image = new upload('service_image');
				$service_image->set_destination(DIR_FS_CATALOG_IMAGES);
				if($span_days!='Y')
				   $span_days='N';
				$include_resource=$HTTP_POST_VARS['include_resource'];
				$include_resource_arr=tep_db_prepare_input($HTTP_POST_VARS['include_resource_arr']);
				$selected_rid=$HTTP_POST_VARS['include_resource_arr'];
				
				 if($include_resource!='Y')
				 {
				 	$quantity=tep_db_prepare_input($HTTP_POST_VARS['quantity']);
				   $include_resource='N' ;
				   }
			     else if($include_resource=='Y')
				 {
				 	$quantity=sizeof($selected_rid);
					}
					
					if($resource_price!='Y') $resource_price='N';
					if($resource_price=='N'){
					   $service_tax_class_id=tep_db_prepare_input($HTTP_POST_VARS['service_tax_class_id']);
					   $service_costs=tep_db_prepare_input($HTTP_POST_VARS['service_costs_net']);
					 }
				
				$no_booking_stime=tep_prepare_time("no_booking_stime");
				$no_booking_etime=tep_prepare_time("no_booking_etime");
				$loading_stime=tep_prepare_time("loading_stime");
				$loading_etime=tep_prepare_time("loading_etime");
				
				if ($service_image->parse() && $service_image->save()) {
					$service_image_name = $service_image->filename;
				} else {
					$service_image_name = (isset($HTTP_POST_VARS['service_previous_image']) ? $HTTP_POST_VARS['service_previous_image'] : '');
				}

				if (isset($HTTP_POST_VARS['edit_x']) || isset($HTTP_POST_VARS['edit_y'])) {
					$HTTP_GET_VARS['action'] = 'edit_service_ACD';
				} else {	
					if (isset($HTTP_GET_VARS['seID'])) $service_id = tep_db_prepare_input($HTTP_GET_VARS['seID']);
						$service_date_available = tep_prepare_date($HTTP_POST_VARS['service_date_available']);
						$booking_type=(isset($HTTP_POST_VARS['booking_type'])?$HTTP_POST_VARS['booking_type']:'H');
						$no_booking_start=$no_booking_end="";
						$no_booking_time=tep_db_prepare_input($HTTP_POST_VARS['no_booking_time']);
						if($no_booking_time!='Y') $no_booking_time='N';
						$booking_buffer='N';
						if (defined("SERVICES_BUFFER_BOOKING") && (SERVICES_BUFFER_BOOKING=='true' || SERVICES_BUFFER_BOOKING==1)){
							$no_booking_sdate = tep_prepare_date($HTTP_POST_VARS['no_booking_sdate']);
							$no_booking_edate = tep_prepare_date($HTTP_POST_VARS['no_booking_edate']);
							$recurring_type = $HTTP_POST_VARS['recurring_type'];
							if($HTTP_POST_VARS['sel_book_buffer']=='Y') $booking_buffer='Y,'.$HTTP_POST_VARS['book_minute']; 
						}
						$include_loadings=tep_db_prepare_input($HTTP_POST_VARS['include_loadings']);
						if($include_loadings!='Y') $include_loadings='N';
						if($include_loadings=='Y'){
							$loading_sdate = tep_prepare_date($HTTP_POST_VARS['loading_sdate']);
							$loading_edate = tep_prepare_date($HTTP_POST_VARS['loading_edate']);
							$loading_recurring_type = $HTTP_POST_VARS['loading_recurring_type'];
						}
					
						$multiple_purchase=$HTTP_POST_VARS['multiple_purchase'] ;
						if($multiple_purchase!='Y') $multiple_purchase='N';

						$provider_id=$rate=$base_rate=$backup_provider=0;
						$provider=tep_db_prepare_input($HTTP_POST_VARS['provider']);

						$rate_type='GP';
						
						if($service_costs=='') $service_costs='0';
						if($service_tax_class_id=='') $service_tax_class_id='0';
						$booking_granular=(isset($HTTP_POST_VARS['booking_granular'])?$HTTP_POST_VARS['booking_granular']:1);
						$max_bookings = $HTTP_POST_VARS['max_bookings'] ? $HTTP_POST_VARS['max_bookings']:1;
						$sql_data_array = array('service_date_available' => $service_date_available,
												'service_location'=>tep_db_prepare_input($HTTP_POST_VARS['service_location']),
												'span_days'=>$span_days,
												'include_resource'=>$include_resource,
												'include_loadings' =>$include_loadings,
												'include_resource_price'=>$resource_price,
												'service_total_time' =>tep_db_prepare_input($HTTP_POST_VARS['service_total_time']),
												'max_bookings' =>$max_bookings,
												'quantity' =>$quantity,
												'booking_granular' =>$booking_granular ,
												'service_status' => tep_db_prepare_input($HTTP_POST_VARS['service_status']),
												'conditions'=>tep_db_prepare_input($HTTP_POST_VARS['service_conditions']),
												'service_costs'=>$service_costs,
												'pending_period'=>tep_db_prepare_input($HTTP_POST_VARS['pending_period']),
												'service_renewal_start'=>tep_db_prepare_input($HTTP_POST_VARS['service_renewal_start']),
												'service_renewal_end'=>tep_db_prepare_input($HTTP_POST_VARS['service_renewal_end']),
												'multiple_purchase' =>$multiple_purchase,
												'no_booking_time'=>$no_booking_time,
												'service_tax_class_id'=>$service_tax_class_id,
												'booking_type'=>$booking_type,
												'booking_buffer'=>$booking_buffer
												);
						if (isset($service_image_name) && tep_not_null($service_image_name) && ($service_image_name != 'none')) {
							$sql_data_array['service_image'] = tep_db_prepare_input($service_image_name);
						}	
		
						if ($action == 'insert_service') {
							$insert_sql_data = array('service_date_added' => $server_date);
							$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
							tep_db_perform(TABLE_SERVICES, $sql_data_array);
						    $service_id=tep_db_insert_id();		
						} elseif ($action == 'update_service') {

							$update_sql_data = array('service_last_modified' => $server_date);
							$sql_data_array = array_merge($sql_data_array, $update_sql_data);
							tep_db_perform(TABLE_SERVICES, $sql_data_array, 'update', "service_id = '" . (int)$service_id . "'");
							tep_db_query("delete from ".TABLE_SERVICES_NO_BOOKING_DAYS ." where service_id = '" .(int)$service_id ."'");//print_r($sql_no_booking_array);
							tep_db_query("delete from " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " where service_id = '". (int)$service_id . "'");
							tep_db_query("delete from ".TABLE_SERVICES_LOADINGS." where service_id='".$service_id."'");
				        }
						


						# create loop here to insert rows for multiple categories
						$selected_service_catids = $HTTP_POST_VARS['service_categories_ids'];
						if ($selected_service_catids)
						{
							foreach ($selected_service_catids as $current_service_category_id)
							{
								tep_db_query("insert into " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " (service_id, services_categories_id) values ('" . $service_id . "', '" . $current_service_category_id . "')");
								$secPath=$current_service_category_id;
							 }
						}
						# create loop here to insert rows for multiple resources
					
						if ($selected_rid)
						{
							if($service_id)
							   tep_db_query("delete from " . TABLE_SERVICES_TO_SERVICES_RESOURCES . " where service_id = '". (int)$service_id . "'");
  						    if($include_resource=='Y'){
							  foreach ($selected_rid as $current_service_resource_id)
							    {
							 	tep_db_query("insert into " . TABLE_SERVICES_TO_SERVICES_RESOURCES . " (service_id, service_resource_id) values ('" . $service_id . "', '" . $current_service_resource_id . "')");
								$secPath=$current_service_category_id;
								}
							}
								
							
						}
								      // echo $no_booking_time;
					   if($no_booking_time=='Y')
						{
						
						$booking_dates=(isset($HTTP_POST_VARS['no_booking_dates'])?$HTTP_POST_VARS['no_booking_dates']:'');
						
						if($booking_dates!='')
							$no_booking_dates_array=split('/',$booking_dates);	
						for($bcnt=0;$bcnt<count($no_booking_dates_array)-1;$bcnt++){			
					
						  $no_booking_recurring_array=split('#',$no_booking_dates_array[$bcnt]);
						  if(sizeof($no_booking_recurring_array)>0)
						  {	
						  	$no_booking_sdate=$no_booking_recurring_array[0];
							$no_booking_edate=$no_booking_recurring_array[1];
							$no_booking_stime=$no_booking_recurring_array[2];
							$no_booking_etime=$no_booking_recurring_array[3];
							$recurring_type=$no_booking_recurring_array[4];
							$recurring_details=$no_booking_recurring_array[5];
						 tep_db_query("insert into " .TABLE_SERVICES_NO_BOOKING_DAYS . " (service_id,no_booking_start_date,no_booking_end_date,no_booking_start_time,no_booking_end_time,recurring_type,recurring_details) values('" .$service_id."','".tep_convert_date_raw($no_booking_sdate)."','".tep_convert_date_raw($no_booking_edate)."','".$no_booking_stime."','".$no_booking_etime."','".$recurring_type."','".$recurring_details."')");
						  }
						}
					}	
					//echo $HTTP_POST_VARS['loading_dates'];
					   if($include_loadings=='Y')
						{
						
						$loading_dates=(isset($HTTP_POST_VARS['loading_dates'])?$HTTP_POST_VARS['loading_dates']:'');
						if($loading_dates!='')
							$loading_dates_array=split('/',$loading_dates);	
						for($bcnt=0;$bcnt<count($loading_dates_array)-1;$bcnt++){			
					
						  $loading_recurring_array=split('#',$loading_dates_array[$bcnt]);
						  if(sizeof($loading_recurring_array)>0)
						  {	
						  	$loading_sdate=$loading_recurring_array[0];
							$loading_edate=$loading_recurring_array[1];
							$loading_stime=$loading_recurring_array[2];
							$loading_etime=$loading_recurring_array[3];
							$recurring_type=$loading_recurring_array[4];
							$recurring_details=$loading_recurring_array[5];
							$loading_price=$loading_recurring_array[6];
							$loading_type=$loading_recurring_array[7];
							
						  tep_db_query("insert into " .TABLE_SERVICES_LOADINGS . " (service_id,loadings_start_date,loadings_end_date,loadings_start_time,loadings_end_time,recurring_type,recurring_details,loadings_price,loadings_type) values('" .$service_id."','".tep_convert_date_raw($loading_sdate)."','".tep_convert_date_raw($loading_edate)."','".$loading_stime."','".$loading_etime."','".$recurring_type."','".$recurring_details."','".
						  			tep_db_input($loading_price)."','".tep_db_input($loading_type)."')");
						  }
						}
					}	
					
						$languages = tep_get_languages();
						for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
							$language_id = $languages[$i]['id'];
					
							$sql_data_array = array('service_name' => tep_db_prepare_input($HTTP_POST_VARS['service_name'][$language_id]),
													'service_description' => tep_db_prepare_input($HTTP_POST_VARS['service_description'][$language_id]),
													'service_url' => tep_db_prepare_input($HTTP_POST_VARS['service_url'][$language_id]));
							if ($action == 'insert_service') {
								$insert_sql_data = array(	'service_id' => $service_id,
															'language_id' => $language_id);
								$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
								tep_db_perform(TABLE_SERVICES_DESCRIPTION, $sql_data_array);
							} elseif ($action == 'update_service') {
								tep_db_perform(TABLE_SERVICES_DESCRIPTION, $sql_data_array, 'update', "service_id = '" . (int)$service_id . "' and language_id = '" . (int)$language_id . "'");
							}
						}
						
			
				}
				tep_redirect(tep_href_link(FILENAME_SERVICES_MAINPAGE,'top=1&mPath=3'));				
        		break;
			case 'delete_service_confirm':
				if (isset($HTTP_POST_VARS['service_id']) && isset($HTTP_POST_VARS['services_categories']) && is_array($HTTP_POST_VARS['services_categories'])) {
					$service_id = tep_db_prepare_input($HTTP_POST_VARS['service_id']);
					$services_categories = $HTTP_POST_VARS['services_categories'];
					
				
					for ($i=0, $n=sizeof($services_categories); $i<$n; $i++) {
						tep_db_query("delete from " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " where service_id = '" . (int)$service_id . "' and services_categories_id = '" . (int)$services_categories[$i] . "'");
					}
			
					$services_categories_query = tep_db_query("SELECT count(*) as total from " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " where service_id = '" . (int)$service_id . "'");
					$services_categories = tep_db_fetch_array($services_categories_query);
					if ($services_categories['total'] == '0') {
						tep_remove_service($service_id);
					}
				}

				tep_redirect(tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath));
				break;
			case 'move_service_confirm':
				$service_id = tep_db_prepare_input($HTTP_POST_VARS['service_id']);
				$new_parent_id = tep_db_prepare_input($HTTP_POST_VARS['move_to_service_category_id']);
				if ($new_parent_id!=0)
				{
					// check if the moved service already exists in the category
					$duplicate_check_query = tep_db_query("SELECT count(*) as total from " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " where service_id = '" . (int)$service_id . "' and services_categories_id = '" . (int)$new_parent_id . "'");
					$duplicate_check = tep_db_fetch_array($duplicate_check_query);
					if ($duplicate_check['total'] < 1) tep_db_query("update " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " set services_categories_id = '" . (int)$new_parent_id . "' where service_id = '" . (int)$service_id . "' and services_categories_id = '" . (int)$current_service_category_id . "'");
				
					tep_redirect(tep_href_link(FILENAME_SERVICES, 'secPath=' . $new_parent_id . '&seID=' . $service_id));
				}
        		break;
      		case 'copy_to_confirm':
				if (isset($HTTP_POST_VARS['service_id']) && isset($HTTP_POST_VARS['services_categories_id'])) {
					$service_id = tep_db_prepare_input($HTTP_POST_VARS['service_id']);
					$services_categories_id = tep_db_prepare_input($HTTP_POST_VARS['services_categories_id']);
				// copying is as a link
				if ($HTTP_POST_VARS['copy_as'] == 'link') {
					if ($services_categories_id != $current_service_category_id) {
						$check_query = tep_db_query("SELECT count(*) as total from " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " where service_id = '" . (int)$service_id . "' and services_categories_id = '" . (int)$services_categories_id . "'");
						$check = tep_db_fetch_array($check_query);
						// check if service already does not exist
						if ($check['total'] < '1') {
							tep_db_query("insert into " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " (service_id, services_categories_id) values ('" . (int)$service_id . "', '" . (int)$services_categories_id . "')");
						}
					} else {
						$messageStack->add_session(ERROR_CANNOT_LINK_TO_SAME_SERVICES_CATEGORY, 'error');
					}
				} elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
					// copying it is as a new one
	  // This is for Diveabout
					$service_query = tep_db_query("SELECT su.service_image, su.service_date_added,su.service_location, su.service_last_modified, date_format(su.service_date_available, '%Y-%m-%d') " .
										   "as service_date_available, su.span_days,su.include_resource,su.include_loadings,su.service_status,su.no_booking_time,su.max_bookings,su.quantity,su.service_total_time,su.booking_granular,".
										   " su.pending_period, " .
										   "su.service_renewal_start,su.service_renewal_end,su.conditions ,su.multiple_purchase," .
										   "su.service_tax_class_id, su.service_costs,su.include_resource_price,su.booking_type  " .
										   " from " . TABLE_SERVICES . " su where su.service_id = '" . (int)$service_id . "' ");
					$service = tep_db_fetch_array($service_query);
					$service["service_date_added"]=$server_date;
					tep_db_perform(TABLE_SERVICES,$service);
					/*tep_db_query("insert into " . TABLE_SERVICES . " (service_image, service_date_added,service_date_available, service_status, service_location,".
									"service_start_time,service_end_time,no_booking_start,no_booking_end,no_booking_until_date,max_bookings,quantity,".
									"service_total_time,booking_granular,provider_id,backup_provider,provider_rate_type,provider_rate,provider_base_rate,provider,pending_period,services_renewal_start,services_renewal_end,".
									"conditions,no_booking_until,multiple_purchase,no_booking_time,service_tax_class_id,service_costs,booking_type,service_week ) ".
									"values ('" . tep_db_input($service['service_image']) . "',  now(), '" . tep_db_input($service['service_date_available']) . "', '" . 
									tep_db_input($service['service_status'])."','".tep_db_input($service['service_location'])."','".tep_db_input($service['service_start_time']).
									"','".tep_db_input($service['service_end_time'])."','".tep_db_input($service['service_start_date'])."','".
									tep_db_input($service['service_end_date'])."','".tep_db_input($service['service_future_date'])."','".tep_db_input($service['service_max_booking'])."','".tep_db_input($service['service_quantity'])."','".
									tep_db_input($service['service_total_time'])."','".tep_db_input($service['service_booking_granular'])."','".
									tep_db_input($service['service_provider'])."','".tep_db_input($service['service_backup_provider'])."','".tep_db_input($service['provider_rate_type'])."','".
									tep_db_input($service['provider_rate'])."','".tep_db_input($service['provider_base_rate'])."','".tep_db_input($service['provider'])."','".
									tep_db_input($service['service_pending_period'])."','".tep_db_input($service['services_renewal_start'])."','".tep_db_input($service['services_renewal_end'])."','".
									tep_db_input($service['service_conditions'])."','".
									tep_db_input($service['recurring_until'])."','".tep_db_input($service['multiple_purchase'])."','".tep_db_input($service['no_booking_time'])
									 ."', '" . tep_db_input($service['service_tax_class_id']) . "', '" . tep_db_input($service['service_costs']) . "', '" . tep_db_input($service['booking_type']). "', '". 
									 tep_db_input($service['service_week']).")");*/
					$dup_service_id = tep_db_insert_id();
					
					
					$description_query = tep_db_query("SELECT language_id, service_name, service_description,service_url from " . TABLE_SERVICES_DESCRIPTION . " where service_id = '" . (int)$service_id . "'");
					while ($description = tep_db_fetch_array($description_query)) {
						tep_db_query("insert into " . TABLE_SERVICES_DESCRIPTION . " (service_id, language_id, service_name, service_description, service_url, service_viewed) values ('" . 
									(int)$dup_service_id . "', '" . (int)$description['language_id'] . "', '" . tep_db_input($description['service_name']) . "', '" . tep_db_input($description['service_description']) . "', '" . 
									tep_db_input($description['service_url']) . "', '0')");
					}
					tep_db_query("insert into " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " (service_id, services_categories_id) values ('" . (int)$dup_service_id . "', '" . (int)$services_categories_id . "')");
					$booking_query=tep_db_query("select no_booking_start_date, no_booking_end_date, no_booking_start_time, no_booking_end_time,recurring_type, recurring_details from ".TABLE_SERVICES_NO_BOOKING_DAYS ." where service_id=" .(int)$service_id);
					while($booking=tep_db_fetch_array($booking_query))
					{
						tep_db_query("insert into " .TABLE_SERVICES_NO_BOOKING_DAYS ."(service_id,no_booking_start_date,no_booking_end_date,no_booking_start_time,no_booking_end_time,recurring_type, recurring_details) values( '".
								(int)$dup_service_id. "' ,'".tep_db_input($booking["no_booking_start_date"])."' , '". tep_db_input($booking["no_booking_end_date"]) . "' , '" . tep_db_input($booking["no_booking_start_time"]) . "', '" . tep_db_input($booking["no_booking_end_time"]) . "', '" . tep_db_input($booking["recurring_type"]) . "', '" . tep_db_input($booking["recurring_details"]) . "')");
								
					}	
					$loadings_query=tep_db_query("select loadings_start_date, loadings_end_date, loadings_start_time, loadings_end_time,recurring_type, recurring_details,loadings_price,loadings_type from ".TABLE_SERVICES_LOADINGS ." where service_id=" .(int)$service_id);
					while($loadings=tep_db_fetch_array($loadings_query))
					{
					tep_db_query("insert into " .TABLE_SERVICES_LOADINGS ."(service_id,loadings_start_date,loadings_end_date,loadings_start_time,loadings_end_time,recurring_type, recurring_details,loadings_price,loadings_type) values( '".
								(int)$dup_service_id. "' ,'".tep_db_input($loadings["loadings_start_date"])."' , '". tep_db_input($loadings["loadings_end_date"]) . "' , '" . tep_db_input($loadings["loadings_start_time"]) . "', '" . tep_db_input($loadings["loadings_end_time"]) . "', '" . tep_db_input($loadings["recurring_type"]) . "', '" . tep_db_input($loadings["recurring_details"]) . "','".
								tep_db_input($loadings['loadings_price'])."','".tep_db_input($loadings['loadings_type'])."')");
								
						}
					
					// copy service messages
					if (isset($HTTP_POST_VARS["copy_service"])){
						$message_query=tep_db_query("SELECT message_send,message_subject,message_text,message_format,service_id,message_type,message_reply_to from " . 
													TABLE_SERVICES_MESSAGES . " su where service_id='" . (int)$service_id ."'"
													);
						while($message_result=tep_db_fetch_array($message_query)){
							$message_result["service_id"]=$dup_service_id;
							tep_db_perform(TABLE_SERVICES_MESSAGES,$message_result);
						}
						
					}
			}
			}

			tep_redirect(tep_href_link(FILENAME_SERVICES, 'secPath=' . $services_categories_id . '&seID=' . $service_id));
			break;
		case 'new_service_preview':
				// copy image only if modified
			$service_image = new upload('service_image');
			$service_image->set_destination(DIR_FS_CATALOG_IMAGES);
			if ($service_image->parse() && $service_image->save()) { 
				$service_image_name = $service_image->filename;
			} else { 
				$service_image_name = (isset($HTTP_POST_VARS['service_previous_image']) ? $HTTP_POST_VARS['service_previous_image'] : '');
			}
			break;
		}
	}

// check if the catalog image directory exists
	if (is_dir(DIR_FS_CATALOG_IMAGES)) {
		if (!is_writeable(DIR_FS_CATALOG_IMAGES)) $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_NOT_WRITEABLE, 'error');
	} else {
		$messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_DOES_NOT_EXIST, 'error');
	}

	$go_back_to=$REQUEST_URI;
?>
<!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/services.js"></script>
<script language="JavaScript" src="includes/date-picker.js"></script>
<script type="text/javascript" src="htmlarea/htmlarea.js"></script>
<script type="text/javascript" src="htmlarea/editor.js"></script>
<?php include(DIR_WS_INCLUDES."date_format_js.php")?>
<?php
// WebMakers.com Added: Java Scripts
include(DIR_WS_INCLUDES . 'javascript/' . 'webmakers_added_js.php');
?>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">
<div id="spiffycalendar" class="text"></div>
<!-- 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="2">
		<?php   //----- new_category / edit_category (when ALLOW_CATEGORY_DESCRIPTIONS is 'true') -----
	
			if ($HTTP_GET_VARS['action'] == 'new_service_category_ACD' || $HTTP_GET_VARS['action'] == 'edit_service_category_ACD') {
				if ( ($HTTP_GET_VARS['secID']) && (!$HTTP_POST_VARS) ) {
					
					$services_categories_query = tep_db_query("SELECT suc.services_categories_id, sucd.services_categories_name, 
					sucd.services_categories_heading_title, sucd.services_categories_description, suc.services_categories_image, 
					suc.parent_id, suc.sort_order, suc.date_added, suc.last_modified,sucd.services_categories_notes from " . TABLE_SERVICES_CATEGORIES . " suc, " . TABLE_SERVICES_CATEGORIES_DESCRIPTION . " sucd
					where suc.services_categories_id = sucd.services_categories_id and suc.services_categories_id = '" . (int)$HTTP_GET_VARS['secID'] . "' and 
					sucd.language_id = '" . (int)$languages_id . "' order by suc.sort_order, sucd.services_categories_name");
					
					$service_category = tep_db_fetch_array($services_categories_query);
					$sucInfo = new objectInfo($service_category);
				} elseif ($HTTP_POST_VARS) {
				
					$sucInfo = new objectInfo($HTTP_POST_VARS);
					$services_categories_name = $HTTP_POST_VARS['services_categories_name'];
					$services_categories_heading_title = $HTTP_POST_VARS['services_categories_heading_title'];
					$services_categories_description = $HTTP_POST_VARS['services_categories_description'];
					$services_categories_url = $HTTP_POST_VARS['services_categories_url'];
					$services_categories_notes= $HTTP_POST_VARS['services_categories_notes'];
				} else {
					$sucInfo = new objectInfo(array());
				}
				$languages = tep_get_languages();
				$text_new_or_edit = ($HTTP_GET_VARS['action']=='new_service_category_ACD') ? TEXT_INFO_HEADING_NEW_SERVICES_CATEGORY : TEXT_INFO_HEADING_EDIT_SERVICES_CATEGORY;
		?>
			<tr>
				<td>
				<table border="0" width="100%" cellspacing="0" cellpadding="0">
					<!--<tr>
						<td class="pageHeading"><?php //echo sprintf($text_new_or_edit, tep_output_generated_service_category_path($current_service_category_id)); ?></td>
						<td class="pageHeading" align="right"><?php //echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
					</tr>!-->
				</table>
				</td>
			</tr>
			<tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
			</tr>
			<tr><?php echo tep_draw_form('new_service_category', FILENAME_SERVICES, 'secPath=' . $secPath . '&secID=' . $HTTP_GET_VARS['secID'] . '&action=new_service_category_preview', 'post', 'enctype="multipart/form-data" onSubmit="javascript:return validate_image()"'); ?>
				<td>
				<table border="0" cellspacing="0" cellpadding="2">
				<?php

				for ($i=0; $i<sizeof($languages); $i++) {
				?>
					<tr>
						<td class="main"><?php if ($i == 0) echo TEXT_EDIT_SERVICES_CATEGORIES_NAME; ?></td>
						<td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('services_categories_name[' . $languages[$i]['id'] . ']', (tep_not_null($services_categories_name[$languages[$i]['id']]) ? stripslashes($services_categories_name[$languages[$i]['id']]) : tep_get_service_category_name($sucInfo->services_categories_id, $languages[$i]['id']))); ?></td>
					</tr>
				<?php
				}
				?>
				<tr>
					<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>
				<?php
				for ($i=0; $i<sizeof($languages); $i++) {
				?>
				<tr>
					<td class="main"><?php if ($i == 0) echo TEXT_EDIT_SERVICES_CATEGORIES_HEADING_TITLE; ?></td>
					<td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('services_categories_heading_title[' . $languages[$i]['id'] . ']', (tep_not_null($services_categories_heading_title[$languages[$i]['id']]) ? stripslashes($services_categories_heading_title[$languages[$i]['id']]) : tep_get_service_category_title($sucInfo->services_categories_id, $languages[$i]['id']))); ?></td>
				</tr>
				<?php
				}
				?>
				<tr>
					<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>
				<?php
				for ($i=0; $i<sizeof($languages); $i++) {
				?>
				<tr>
					<td class="main" valign="top"><?php if ($i == 0) echo TEXT_EDIT_SERVICES_CATEGORIES_DESCRIPTION; ?></td>
					<td>
					<table border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td class="main" valign="top"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?>&nbsp;</td>
							<td class="main"><?php echo tep_draw_textarea_field('services_categories_description[' . $languages[$i]['id'] . ']', 'soft', '70', '15', (tep_not_null($services_categories_description[$languages[$i]['id']]) ? stripslashes($services_categories_description[$languages[$i]['id']]) : tep_get_service_category_description($sucInfo->services_categories_id, $languages[$i]['id']))); ?></td>
						</tr>
					</table>
					</td>
				</tr>
				<?php
				}
				?>
				<?php
				for ($i=0; $i<sizeof($languages); $i++) {
				?>
				<tr>
					<td class="main" valign="top"><?php if ($i == 0) echo TEXT_EDIT_SERVICES_CATEGORIES_NOTES; ?></td>
					<td>
					<table border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td class="main" valign="top"><?php  echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?>&nbsp;</td>
							<td class="main"><?php echo tep_draw_textarea_field('services_categories_notes[' . $languages[$i]['id'] . ']', 'soft', '70', '15', (tep_not_null($services_categories_notes[$languages[$i]['id']]) ? stripslashes($services_categories_notes[$languages[$i]['id']]) : tep_get_service_category_notes($sucInfo->services_categories_id, $languages[$i]['id']))); ?></td>
						</tr>
					</table>
					</td>
				</tr>
				<?php
				}
				?>
				<tr>
					<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>
				<tr>
					<td class="main"><?php echo TEXT_EDIT_SERVICES_CATEGORIES_IMAGE; ?></td>
					<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_file_field('services_categories_image') . '<br>' . tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . $sucInfo->services_categories_image . tep_draw_hidden_field('services_categories_previous_image', $sucInfo->services_categories_image); ?></td>
				</tr>
				<tr>
					<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>
				<tr>
					<td class="main"><?php echo TEXT_EDIT_SERVICES_CATEGORIES_SORT_ORDER; ?></td>
					<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_input_field('sort_order', $sucInfo->sort_order, 'size="2"'); ?></td>
				</tr>
				<tr>
					<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>
			</table>
			</td>
		</tr>
		<tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		</tr>
		<tr>
			<td class="main" align="right"><?php echo tep_draw_hidden_field('services_categories_date_added', (($sucInfo->date_added) ? $sucInfo->date_added : date('Y-m-d'))) . tep_draw_hidden_field('parent_id', $sucInfo->parent_id) . tep_image_submit('button_preview.gif', IMAGE_PREVIEW) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_SERVICES_MAINPAGE,'top=1&mPath=3') . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; ?></td>
		</tr>
	<?php
			echo "</form>";
	} elseif ($HTTP_GET_VARS['action'] == 'new_service_ACD' || $HTTP_GET_VARS['action'] == 'edit_service_ACD'){
	
				$languages = tep_get_languages();
				$parameters = array('service_name' => '',
									'service_description' => '',
									'service_url' => '',
									'service_id' => '',
									'service_image' => '',
									'service_type'=>'T',
									'service_date_added' => '',
									'service_last_modified' => '',
									'service_date_available' => '',
									'span_days'=>'Y',
									'include_resource_price'=>'Y',
									'include_resource'=>'Y',
									'include_loadings' =>'Y',
									'service_location'=>'',
									'max_booking' => '1',
									'quantity' => '1',
									'service_total_time' =>'1',
									'booking_granular' =>'1',
									'no_booking_stime'=>'00:00:AM',
									'no_booking_etime'=>'00:00:AM',
									'loading_stime' =>'00:00:AM',
									'loading_etime' =>'00:00:AM',
									'pending_period'=>'1',
									'service_renewal_start'=>'0',
									'service_renewal_end'=>'0',
									'service_conditions'=>'',
									'multiple_purchase'=>'N',
									'no_booking_time'=> 'Y',
									'booking_type'=>'H',
									'booking_buffer'=>'N'
									);
			$suInfo = new objectInfo($parameters);
			
			require(DIR_WS_CLASSES . 'payment.php');
			$payment_modules = new payment;
			if (isset($HTTP_GET_VARS['seID']) && (!$HTTP_POST_VARS)) {
	  // This is for Diveabout
			  $service_query = tep_db_query("SELECT sud.service_name, sud.service_description, sud.service_url, su.service_id, su.service_image, " .
										   "su.service_date_added,su.service_location, su.service_last_modified, date_format(su.service_date_available, '%Y-%m-%d') " .
										   "as service_date_available, su.span_days,su.service_status,".
										   " su.max_bookings,su.quantity,"."su.service_total_time,su.booking_granular,".
										   "su.pending_period,su.service_renewal_start,su.service_renewal_end,".
										   "su.conditions as service_conditions,su.multiple_purchase ,su.no_booking_time,su.include_resource,su.include_loadings,su.include_resource_price,su.service_tax_class_id, su.service_costs,su.booking_type,su.booking_buffer " .
										   "  from " . TABLE_SERVICES . " su, " . TABLE_SERVICES_DESCRIPTION . " sud where su.service_id=sud.service_id  " .
										   " and su.service_id = '" . (int)$HTTP_GET_VARS['seID'] . "' and sud.language_id = '" . (int)$languages_id . "'");
										   
			  $service = tep_db_fetch_array($service_query);
		
			  $suInfo=new objectInfo($service);
			} elseif ($HTTP_POST_VARS) {
			  $suInfo=new objectInfo($HTTP_POST_VARS);
			  $service_name = $HTTP_POST_VARS['service_name'];
			  $service_description = $HTTP_POST_VARS['service_description'];
			  $service_url = $HTTP_POST_VARS['service_url'];
			} 
			$form_action = ($HTTP_GET_VARS['seID']) ? 'update_service' : 'insert_service';
			
			#fetch tax descriptions start
			$tax_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
			$tax_class_query = tep_db_query("SELECT tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_title");
			while ($tax_class = tep_db_fetch_array($tax_class_query)) {
			  $tax_class_array[] = array('id' => $tax_class['tax_class_id'],
										 'text' => $tax_class['tax_class_title']);
			} 
			#fetch tax descriptions end
			
			#fetch no booking days start
			
		//	$no_booking_array=array(array('id'=>'0','text' =>TEXT_NONE));
			$no_booking_array=array();
			$no_booking_query=tep_db_query("select no_booking_start_date, no_booking_end_date, recurring_type, recurring_details, time_format(no_booking_start_time,'%l:%i%p') as no_booking_stime, no_booking_start_time ,time_format(no_booking_end_time,'%l:%i%p') as no_booking_etime, no_booking_end_time from " . TABLE_SERVICES_NO_BOOKING_DAYS. "  where service_id= '" .(int)$HTTP_GET_VARS['seID']."' order by no_booking_start_date");
			while($no_booking_day=tep_db_fetch_array($no_booking_query)) {
				$no_booking_sdate=$no_booking_day['no_booking_start_date'];
				$no_booking_edate=$no_booking_day['no_booking_end_date'];
				if($suInfo->booking_type=='H')$no_booking_stime=$no_booking_day['no_booking_start_time'];
				if($suInfo->booking_type=='H')$no_booking_etime=$no_booking_day['no_booking_end_time'];
				if($suInfo->booking_type=='H')$booking_stime=$no_booking_day['no_booking_stime'];
				if($suInfo->booking_type=='H')$booking_etime=$no_booking_day['no_booking_etime'];
				$recurring_type=$no_booking_day['recurring_type'];
				$recurring_details=$no_booking_day['recurring_details'];
				$no_booking_array[]=form_recurring_array($no_booking_sdate,$no_booking_edate,$no_booking_stime,$no_booking_etime,$booking_stime,$booking_etime,$recurring_type,$recurring_details);
			}	
			
			$loading_array=array();//echo "select loadings_start_date, loadings_end_date, recurring_type, recurring_details, time_format(loadings_start_time,'%l:%i%p') as loadings_stime, loadings_start_time ,time_format(loadings_end_time,'%l:%i%p') as loadings_etime, loadings_end_time,loadings_price,loadings_type from " . TABLE_SERVICES_LOADINGS. "  where service_id= '" .(int)$HTTP_GET_VARS['seID']."' order by loadings_start_date";
			$loading_query=tep_db_query("select loadings_start_date, loadings_end_date, recurring_type, recurring_details, time_format(loadings_start_time,'%l:%i%p') as loadings_stime, loadings_start_time ,time_format(loadings_end_time,'%l:%i%p') as loadings_etime, loadings_end_time,loadings_price,loadings_type from " . TABLE_SERVICES_LOADINGS. "  where service_id= '" .(int)$HTTP_GET_VARS['seID']."' order by loadings_start_date");
			while($loading_day=tep_db_fetch_array($loading_query)) {
				$loading_sdate=$loading_day['loadings_start_date'];
				$loading_edate=$loading_day['loadings_end_date'];
				$loading_stime=$loading_day['loadings_start_time'];
				$loading_etime=$loading_day['loadings_end_time'];
				$stime=$loading_day['loadings_stime'];
				$etime=$loading_day['loadings_etime'];
				$recurring_type=$loading_day['recurring_type'];
				$recurring_details=$loading_day['recurring_details'];
				$loading_price=$loading_day['loadings_price'];
				$loading_type=$loading_day['loadings_type'];
				$loading_array[]=form_load_recurring_array($loading_sdate,$loading_edate,$loading_stime,$loading_etime,$stime,$etime,$recurring_type,$recurring_details,$loading_price,$loading_type);
			}	
		//	echo date('F',strtotime(10));	
			# fetch location names start
			$location_query=tep_db_query("SELECT * from " . TABLE_SERVICES_LOCATIONS . ' order by service_location_name');
			$location_array=array();
			while($location_result=tep_db_fetch_array($location_query)){
			   $location_array[]=array('id'=>$location_result['service_location_id'],'text'=>$location_result['service_location_name'],'seats'=>$location_result["service_location_seats"]);
			}
			$loading_type_array=array(array('id'=>'C','text'=>'Currency'),array('id'=>'P','text'=>'Percentage'));												
							
			#fetch selected categories start
			$services_categories_query_selected = tep_db_query("SELECT services_categories_id from " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " where service_id = '" . (int)$HTTP_GET_VARS['seID'] . "'");
			$first_category=tep_db_query("select services_categories_id from ". TABLE_SERVICES_CATEGORIES);
			$first_cate=tep_db_fetch_array($first_category);
			$services_categories_array_selected = array(array('id' =>($secPath=='')?$first_cate['services_categories_id']:$secPath));
			while ($services_categories = tep_db_fetch_array($services_categories_query_selected)) {
			  $services_categories_array_selected[] = array('id' => $services_categories['services_categories_id']);
			}
			#fetch selected resource start
			
			$services_resources_query_selected = tep_db_query("SELECT service_resource_id from " . TABLE_SERVICES_TO_SERVICES_RESOURCES . " where service_id = '" . (int)$HTTP_GET_VARS['seID'] . "'");
			$services_resources_array_selected = array(array('id' => ''));
			while ($services_resources = tep_db_fetch_array($services_resources_query_selected)) {
			  $services_resources_array_selected[] = array('id' => $services_resources['service_resource_id']);
			}
			#fetch selected categories end
			
			$services_categories_array = array(array('id' => '', 'text' => TEXT_NONE));
			$language_id = 1;
			$services_categories_array = tep_get_services_category_tree(); 
			$booking_type=array(array('id'=>'H','text'=>TEXT_HOURS),array('id'=>'D','text'=>TEXT_DAYS));
			$status_array=array(array('id'=>1,'text'=>TEXT_HIDE_NONE),
								array('id'=>0,'text'=>TEXT_HIDE_ALWAYS));
								
			if (!isset($suInfo->service_status)) $suInfo->service_status = '1';
			
			$rate_type_array=array(	array('id'=>'GP','text'=>TEXT_RATE_TYPE_GP),
							array('id'=>'MU','text'=>TEXT_RATE_TYPE_MU),
							array('id'=>'FL','text'=>TEXT_RATE_TYPE_FL));
			
			if ($no_booking_sdate=="" || $no_booking_sdate=="0000-00-00") $no_booking_sdate=$current_date;
			if ($no_booking_edate=="" || $no_booking_edate=="0000-00-00") $no_booking_edate=$current_date;
		//	if ($suInfo->no_booking_until_date=="" || $suInfo->no_booking_until_date=="0000-00-00") $suInfo->no_booking_until_date=$current_date;

			require(DIR_WS_INCLUDES . 'services.js.php');
			$formname='new_service';
				
		echo tep_draw_form('new_service', FILENAME_SERVICES, 'secPath=' . $secPath  . '&seID=' . $HTTP_GET_VARS['seID'] . '&action='. $form_action, 'post', 'onSubmit="return ValidateForm();" enctype="multipart/form-data"'); ?>
		<?php echo '<input type="hidden" name="booking_dates" value="">';?>
			<table border="0" width="100%" cellspacing="0" cellpadding="2">
				<tr>
					<td>
					<table border="0" width="100%" cellspacing="0" cellpadding="0">
						<tr>
							<td class="pageHeading"><?php echo sprintf(TEXT_NEW_SERVICES, tep_output_generated_service_category_path($current_service_category_id)); ?></td>
							<td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
						</tr>
					</table>
					</td>
				</tr>
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>				
				<tr>
					<td>
						<table border=0 cellpadding="0" cellspacing="0">
							<tr>
								<td class="main" width="150" valign="top"><?php echo TEXT_SERVICES_CATEGORIES; ?></td>
								<td class="main" width="200"><?php echo tep_draw_mselect_menu('service_categories_ids[]', $services_categories_array, $services_categories_array_selected, 'size=10 id=service_categories_ids style="width:400"'); ?></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
				</tr>
				<tr>
					<td>
					<table border=0 cellpadding="0" cellspacing="0">
						<tr>
							<td class="main" width="150" valign="top"><?php echo TEXT_SERVICES_STATUS; ?></td>
							<td class="main" width="200" valign="top"><?php echo tep_draw_pull_down_menu('service_status', $status_array, $suInfo->service_status); ?></td>
							<?php $_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);?>
							<td class="main" width="150" valign="top"><?php echo TEXT_SERVICES_DATE_AVAILABLE; ?><br><small>(<?php echo $date_format;?>)</small></td>
							<td class="main" width="200" valign="top">
							<?php 
								echo tep_draw_date_field("service_date_available",(tep_not_null($suInfo->service_date_available)?format_date($suInfo->service_date_available):format_date($current_date)),'size=10');
							?>
						</tr>
					</table>
					</td>
				</tr>
				
				<?php tep_content_title_top("General"); ?>
				<tr>
					<td>
					<table border="0" cellpadding="4" cellspacing="0" >
						<tr>
							<td>
							<table border="0" cellpadding="0" cellspacing="0">
								<?php
								for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
								?>
										<tr>
																																				<td class="main" width="150"><?php if ($i == 0) echo TEXT_SERVICES_NAME; ?></td>
												<td class="main"><?php //echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('hai',tep_get_service_name($suInfo->service_id, $languages[$i]['id']),'id=service_name_value size=40'); ?></td>
												<td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('service_name[' . $languages[$i]['id'] . ']', (isset($service_name[$languages[$i]['id']]) ? $service_name[$languages[$i]['id']] : tep_get_service_name($suInfo->service_id, $languages[$i]['id'])),'id=service_name_value[] size=40'); ?></td>
										</tr>
								<?php
								}
								?>
							</table>
							</td>
						</tr>
						<tr>
							<td>
							<table border="0" cellpadding="0" cellspacing="0">
								<?php
								for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
								?>
									<tr>
										<td class="main" valign="top" width="150"><?php if ($i == 0) echo TEXT_SERVICES_DESCRIPTION; ?></td>
										<td>
										<table border="0" cellspacing="0" cellpadding="0">
											<tr>
												<td class="main" valign="top"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?>&nbsp;</td>
												<td class="main"><?php echo tep_draw_textarea_field('service_description[' . $languages[$i]['id'] . ']', 'soft', '80', '24', (isset($service_description[$languages[$i]['id']]) ? $service_description[$languages[$i]['id']] : tep_get_service_description($suInfo->service_id, $languages[$i]['id'])), 'id="service_description[' . $languages[$i]['id'] . ']"'); ?></td>
											</tr>
										</table>
										</td>
								</tr>
							<?php
							}
							?>
						</table>
						</td>
					</tr>
					<tr>
						<td colspan="2">
						<table cellpadding="0" cellspacing="0" border="0">
							<?php
							for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
							?>
								<tr>
									<td class="main" width="120"><?php if ($i == 0) echo TEXT_SERVICES_URL . '<br><small>' . TEXT_SERVICES_URL_WITHOUT_HTTP . '</small>'; ?></td>
									<td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('service_url[' . $languages[$i]['id'] . ']', (isset($service_url[$languages[$i]['id']]) ? $service_url[$languages[$i]['id']] : tep_get_service_url($suInfo->service_id, $languages[$i]['id'])),'size=40'); ?></td>
									<td class="main" valign="middle" ><?php echo '&nbsp;&nbsp;'.TEXT_SERVICES_IMAGE .'&nbsp;&nbsp;&nbsp;'. tep_draw_file_field('service_image') . $suInfo->service_image . tep_draw_hidden_field('service_previous_image', $suInfo->service_image); ?></td>
								</tr>
							<?php
							}
							?>
							</table>
							</td>
					</tr>
					<tr>
						<td>
						<table border=0 cellpadding="0" cellspacing="0">
							<tr>
								<td class="main" width="150"><?php echo TEXT_SERVICES_LOCATION; ?></td>
								<td class="main" width="200"><?php echo tep_draw_pull_down_menu('service_location', $location_array,$suInfo->service_location); ?></td>
							</tr>
						</table>
						</td>
					</tr>
				</table>
				</td>
			</tr>
			<?php tep_content_title_bottom(); ?>
			
			<?php tep_content_title_top("Bookings"); ?>
			<tr>
				<td>
				<table border="0" cellpadding="4" cellspacing="0" width="80%">
					<tr>
						<td>
						<table cellpadding="0" cellspacing="0" border="0">
							<tr>
								<td class="main" width="150"><?php echo TEXT_BOOKING_TYPE;?></td>
								<td class="main"><?php echo tep_draw_pull_down_menu('booking_type',$booking_type,$suInfo->booking_type,'onchange="javascript:do_check_control(1);"');?></td>
								<td><?php echo tep_draw_separator('pixel_trans.gif', '20', '3'); ?></td> 
								<td class="main" width="100"><?php  echo  tep_draw_checkbox_field('span_days','Y',($suInfo->span_days=='Y'?true:false),'').  TEXT_SPAN_DAYS;?></td>
								<td class="main"><?php  ?></td>
							</tr>
						</table>
						</td>
					</tr>
					<tr>
						<td>
						<table border=0 cellpadding="0" cellspacing="0">
							<tr>
								<td class="main" width="150"><?php // echo TEXT_SERVICES_START_TIME; ?></td>
								<td class="main" width="200"><?php //echo tep_draw_time_field('service_start_time',$suInfo->service_start_time);?></td>
								<td class="main" width="150"><?php //echo TEXT_SERVICES_END_TIME; ?></td>
								<td class="main" width="200"><?php // echo tep_draw_time_field('service_end_time',$suInfo->service_end_time);?></td>
							</tr>
						 </table>
						</td>
					</tr> 
					<tr>
						<td>
						<table cellpadding="0" cellspacing="0" border="0">
							<tr>
								<td class="main" width="150"><?php echo TEXT_SERVICES_BOOKING_GRANULAR; ?></td>
								<td class="main"><?php echo tep_draw_input_field('booking_granular',$suInfo->booking_granular,'size=10 maxlength=6' . (($suInfo->booking_type=='D')?' disabled=disabled':''));?>
								</td>
								<td>
									<table cellpadding="0" cellspacing="0" border="0">
								<tr>
								<td class="main" width="180"><?php echo tep_draw_separator('pixel_trans.gif',40,10).TEXT_SERVICES_TOTAL_TIME; ?></td>
								<td class="main"><?php echo tep_draw_separator('pixel_trans.gif',68,10) . tep_draw_input_field('service_total_time',$suInfo->service_total_time,'size=10 maxlength=6').'&nbsp;<span id="spHours1">' .($suInfo->booking_type=="D"?TEXT_DAYS:TEXT_HOURS) . '</span>';	?>
								</td>
							</tr>
						</table>
						</td>
							</tr>
						</table>
						</td>
						
					</tr>
					<tr>
						<td>
						<table cellpadding="0" cellspacing="0" border="0" >
							<tr>
								<td class="main" width="150"><?php echo TEXT_QUANTITY; ?></td>
								<td class="main">
								<?php echo tep_draw_input_field('quantity',$suInfo->quantity,' size=10 ' . (($suInfo->include_resource=='Y')?'disabled':'enabled'));?>
								</td>
								<td>
								<table cellpadding="0" cellspacing="0" border="0">
							<tr>
								<td class="main" width="250"><?php echo tep_draw_separator('pixel_trans.gif',40,10). TEXT_EVENTS_MAX_BOOKINGS; ?></td>
								<td class="main">
								<?php echo tep_draw_input_field('max_bookings',$suInfo->max_bookings,'size=10 maxlength=6') . '&nbsp;<span id="spHours2">' . ($suInfo->booking_type=="D"?TEXT_DAYS:TEXT_HOURS) . '</span>';	?>
								</td>
							</tr>
						</table>
						</td>
							</tr>
						    </table>
						</td>
					   </tr>
						<tr>
						  <td>	
							<table cellpadding="0" cellspacing="0" border="0">
                     			<tr>
								<td class="main" width="150"><?PHP echo tep_draw_checkbox_field('include_resource','Y',($suInfo->include_resource=='Y'?true:false),'','onClick="do_check_control(7)"').TEXT_INCLUDE_RESOURCE; ?></td>
							</tr>
							</table>
						</td>
					</tr>
					<Tr>
					 <Td><?PHP 
					    $services_resources_array = array(array('id' => '', 'text' => TEXT_NONE));?>
						<table cellpadding="0" cellspacing="0" border="0" id="display_resource"  style="<?PHP echo (($suInfo->include_resource=='Y')?"display:''":"display:none");  ?>">
							<tr><?PHP $services_resources_array=tep_get_resource_tree(); ?>
							 <td class="main" width="150">
							  <?PHP echo tep_draw_mselect_menu('include_resource_arr[]',$services_resources_array, $services_resources_array_selected, 'size=5 id=include_resource_arr style="width:200"');  ?></td>
									<td></td>									
								</tr>
							</table>
						</Td>
			    	</Tr> 
				</table>
				</td>
			</tr>
			<?php tep_content_title_bottom(); ?>
			
			<?php tep_content_title_top("Fees"); ?>
			
			<tr>
				<td>
				<table border=0 cellpadding="4" cellspacing="0"  width="70%">
					<tr>
						<td class="main" width="150"><?php echo tep_draw_checkbox_field('resource_price','Y',($suInfo->include_resource_price=='Y'?true:false),'',($suInfo->include_resource=='Y'?'enabled':'disabled') . ' onClick="do_check_control(6)"').TEXT_SERVICES_RESOURCE_PRICE; ?></td>
						<td class="main"><?php  ?></td>
					</tr>
					<tr>
						<td class="main" width="150"><?php echo TEXT_SERVICES_TAX_CLASS; ?></td>
						<td class="main"><?php echo tep_draw_pull_down_menu('service_tax_class_id', $tax_class_array, $suInfo->service_tax_class_id, 'onchange="updateGross()"'); ?></td>
					<!--</tr>
					<tr>-->
						<td class="main"><?php echo TEXT_SERVICES_FEES_NET_INFO; ?></td>
						<td class="main"><?php 
						$price=$suInfo->service_costs;
			           	if(strpos($price,".") && substr($price,strpos($price,"."))<=0) $price=(int)$price;
						echo tep_draw_input_field('service_costs_net', $price, 'onKeyUp="updateGross()"'); ?></td>
					<!--</tr>
					<tr>-->
						<td class="main"><?php echo TEXT_SERVICES_FEES_GROSS_INFO; ?></td>
						<td class="main"><?php echo tep_draw_input_field('service_costs_gross', $suInfo->service_costs, 'OnKeyUp="updateNet()"') ; ?></td>
					</tr>
					  </table>
				</td>
			</tr>	 
				<?php tep_content_title_bottom(); ?>
				<?php tep_content_title_top("Blocked Out Time"); ?>
				<tr>
					<td>
					<table border=0 cellpadding="4" cellspacing="0"  >
						<tr>
							<td valign="top" width="10"><?php echo tep_draw_checkbox_field('no_booking_time','Y',($suInfo->no_booking_time=='Y'?true:false),'','onClick="do_check_control(2)"');
							$_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);?></td>
							<td class="main" width="150" valign="top"><?php echo TEXT_SERVICE_NOBOOK_SDATE; ?><br><small>(<?php echo $date_format;?>)</small></td>
							<td class="main" width="200" valign="top"><?php	
								echo tep_draw_date_field("no_booking_sdate",((tep_not_null($no_booking_sdate))?format_date($no_booking_sdate):format_date($current_date)),"size=10");
							?>
							<td class="main" width="150"><?php echo TEXT_SERVICE_NOBOOK_STIME; ?></td>
							<td class="main" width="200"><?php echo tep_draw_time_field("no_booking_stime",$no_booking_stime);?></td>
						</tr>
						<tr>
							<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
						</tr>
						<tr>
							<td width="10"></td>
							<td class="main" valign="top"><?php echo TEXT_SERVICE_NOBOOK_EDATE;; ?><br><small>(<?php echo $date_format;?>)</small></td>
							<td class="main" valign="top"><?php 
							
							 echo tep_draw_date_field("no_booking_edate",(tep_not_null($no_booking_edate)?format_date($no_booking_edate):$current_date),"size=10");?>
							<td class="main" ><?php echo TEXT_SERVICE_NOBOOK_ETIME; ?></td>
							<td class="main"><?php echo tep_draw_time_field('no_booking_etime',$no_booking_etime);?></td>
						</tr>
						
						
						 
						<Tr id="recurring_type_option">
							<td></td>
							<Td colspan="4" align="left">
							<table cellpadding="0" cellspacing="0" width="100%" border="0">
								
								<Tr>
								<?php if($recurring_type=="")
									 		$recurring_type="DD"?>
									<td class="main"><?php echo TEXT_SERVICE_TYPE_DAILY; ?></td>
									<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('recurring_type', 'DD', ($recurring_type=='DD'?true:false),'','onClick=javascript:clear_block_content();') . sprintf(TEXT_DAYS_DISPLAY , tep_draw_input_field('daily_days', $daily_days,'size=5 maxlength=2') ); ?></td>
								</Tr>
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<Tr>
								<td class="main"><?php echo TEXT_SERVICE_TYPE_WEEKLY; ?></td>
									<?php  
						//	echo $week_selected;
						//	$days_select_array=split(",",$week_selected);
							$count=0;
							$icnt=1;
							$no_booking_week_days=array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
							$check_weekdays="";
							$check_weekdays='<table border="0" cellspacing="0" cellpadding="0" class="formArea"><tr>';
							for ($i = 0, $n = sizeof($no_booking_week_days); $i < $n; $i++) {
								$temp='<td class="main"';
								if ($i%2==0) $temp.=' bgcolor="#ebebff" ';
								$temp.='>';
							//	echo $no_booking_week_days[$i];
							//	echo $i;
								$temp.=tep_draw_checkbox_field('no_booking_week_days[]', $i+1, '','','') . '&nbsp;' . $no_booking_week_days[$i] . '&nbsp;';
									//if($days_select_array[$count]==$icnt)
									//	$count++;
								$temp.='</td>';
								$check_weekdays.=$temp;
							//	echo $check_weekdays;
							//	echo $i;
							$icnt++;	
							}
							
							  $check_weekdays.="</tr></table>";
							?>
							  
							  
							  <td colspan="2"><table cellpadding="0" cellspacing="0" ><tr><Td class="main"><?php  echo tep_draw_separator('pixel_trans.gif', '24', '15')  .'&nbsp;' . tep_draw_radio_field('recurring_type', 'WW', ($recurring_type=='WW'?true:false),'','onClick=javascript:clear_block_content();'); ?></td>
							  <td class="main"><?php echo sprintf(TEXT_WEEKS_DISPLAY,tep_draw_input_field('weekly_weeks', $weekly_weeks,'size=5 maxlength=2')) . '&nbsp;'; ?></td>
							  <td class="main"><?php  echo $check_weekdays; ?> </td>
							  </tr></table></td>
								</Tr>
								<tr>
									<td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td class="main"><?php echo TEXT_SERVICE_TYPE_MONTHLY; ?></td>
									<td class="main" colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('recurring_type', 'MD', ($recurring_type=='MD'?true:false),'','onClick=javascript:clear_block_content();') . sprintf(TEXT_MONTHS_DISPLAY1, tep_draw_input_field('monthly_days', $monthly_days ,'size=5 maxlength=2') , tep_draw_input_field('monthly_months', $monthly_months ,'size=5 maxlength=2') ); ?><br><br>
													 <?php  echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('recurring_type', 'MM', ($recurring_type=='MM'?true:false),'','onClick=javascript:clear_block_content();') . sprintf(TEXT_MONTHS_DISPLAY2, tep_draw_date_combo_select('weeks','monthly_weeks',$monthly_weeks) , tep_draw_date_combo_select('days',"monthly_week_days",$monthly_week_days) , tep_draw_input_field('monthly_week_months', $monthly_week_months,'size=5 maxlength=2')); ?></td>
								</tr>
								<tr>
									<td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td class="main"><?php echo TEXT_SERVICE_TYPE_YEARLY; ?></td>
									<td class="main" colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('recurring_type', 'YD', ($recurring_type=='YD'?true:false),'','onClick=javascript:clear_block_content();') .sprintf(TEXT_YEARS_DISPLAY1, tep_draw_date_combo_select('months','yearly_months',$yearly_months) , tep_draw_input_field('yearly_month_days', $yearly_month_days,'size=5 maxlength=2'));?><br><br>
												 <?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('recurring_type', 'YY', ($recurring_type=='YY'?true:false),'','onClick=javascript:clear_block_content();') .sprintf(TEXT_YEARS_DISPLAY2,tep_draw_date_combo_select('weeks','yearly_weeks',$yearly_weeks), tep_draw_date_combo_select('days',"yearly_week_days",$yearly_week_days), tep_draw_date_combo_select('months',"yearly_week_months",$yearly_week_months));?></td>
								</tr>
								<tr>
									<td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td colspan="3">
									<table border=0 cellpadding="4" cellspacing="0" width="670" >
										<tr>
											<td class="main" colspan="4" width="70%"><?php echo tep_draw_pull_down_menu('no_booking_date_list',$no_booking_array,'','id="no_booking_date_list" size=10 style="width:100%" onmousekeyup="javascript:do_date_action(\'select\');" onmousekeydown="javascript:do_date_action(\'select\');" onClick="javascript:do_date_action(\'select\');"');
												echo tep_draw_hidden_field('no_booking_dates');
											?></td>
											<td class="main" valign="middle" width="5%"><?php echo '<a href="javascript:do_date_action(\'add\');">' . tep_image_button('button_add.gif',IMAGE_ADD_DATE) . '</a><br><br><a href="javascript:do_date_action(\'edit\')">' . tep_image_button('button_update.gif',IMAGE_EDIT_DATE) . '<a><br><br><a href="javascript:do_date_action(\'delete\')">' . tep_image_button('button_delete.gif',IMAGE_DELETE_DATE) . '<a>';?></td>
										</tr>
										 <tr>
											<td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
										</tr>											
									</table>
									</td>
								</tr>	
								
							</table></Td>
						</Tr>	
						<?php 
						$splt_book_buffer=split(",",$suInfo->booking_buffer);
						$bk_buffer='N';
						$bk_buffer_minute=0; 
						if($splt_book_buffer[1]){
							$bk_buffer=$splt_book_buffer[0];
						 	$bk_buffer_minute=$splt_book_buffer[1]; 
						}
						if(defined("SERVICES_BUFFER_BOOKING") && (SERVICES_BUFFER_BOOKING=='true' || SERVICES_BUFFER_BOOKING==1)) {
						?> 	
							<tr> 
							   <td colspan="3">
							     <table border="0" cellspacing="0" cellpadding="0" width="100%">
							    	<tr>
							    	 	<td class="main" align="left"><?php echo tep_draw_checkbox_field('sel_book_buffer','Y',true,'',' onclick="javascript:do_booking_buffer(this.checked);"');?></td>
										<td colspan="2" class="main" width="550" align="left" id="box_buffer"><?php echo TEXT_BOOKING_BUFFER.' ' .tep_draw_pull_down_menu("book_minute",$minute_array,$bk_buffer_minute) ;?></td>
							    	</tr>  
							     </table>
							   </td>
							</tr>
						<?php } ?>
						<script language="javascript">do_booking_buffer(<?php echo ($bk_buffer=='Y')?'true':'false';?>);</script>
					</table>
					</td>
				</tr>
				
				<?php tep_content_title_bottom(); ?>
				<?php tep_content_title_top("Loadings"); ?>
				<Tr>
					<td>
						<table cellpadding="0"  border="0" cellspacing="0" width="100%">
							<tr><td>
								<table cellpadding="4" cellspacing="0" >
									<tr>
										<td class="main"><?PHP echo tep_draw_checkbox_field('include_loadings','Y',($suInfo->include_loadings=='Y'?true:false),'','onClick="do_check_control(8)"'); ?></td>
										<td class="main" width="150" valign="top"><?php echo TEXT_SERVICE_NOBOOK_SDATE; ?><br><small>(<?php echo $date_format;?>)</small></td>
										<td class="main" width="200" valign="top"><?php 
										$_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);
										echo tep_draw_date_field("loading_sdate",(tep_not_null($loading_sdate)?format_date($loading_sdate):format_date($current_date)),"size=10");?>
										<td class="main" width="150"><?php echo TEXT_SERVICE_NOBOOK_STIME; ?></td>
										<td class="main" width="200"><?php echo tep_draw_time_field("loading_stime",$loading_stime);?></td>
									</tr>
									<tr>
										<td colspan="5"><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
									</tr>
									<tr>
										<td width="10"></td>
										<td class="main" valign="top"><?php echo TEXT_SERVICE_NOBOOK_EDATE;; ?><br><small>(<?php echo $date_format;?>)</small></td>
										<td class="main" valign="top"><?php 
										
										 echo tep_draw_date_field("loading_edate",(tep_not_null($loading_edate)?format_date($loading_edate):format_date($current_date)),"size=10");?>
										<td class="main" ><?php echo TEXT_SERVICE_NOBOOK_ETIME; ?></td>
										<td class="main"><?php echo tep_draw_time_field('loading_etime',$loading_etime);?></td>
									</tr>
									<tr>
										<td width="10" valign="top" colspan="5">&nbsp;<?php // echo tep_draw_checkbox_field('no_booking_until','Y',($suInfo->no_booking_until=='Y'?true:false),'','onclick="do_check_control(3)"');?></td>
									</tr>
									<Tr id="loading_recurring_type_option">
										<td></td>
										<Td colspan="4" align="left">
											<table cellpadding="0" cellspacing="0" width="100%" border="0">
												<Tr>
												<?php 
												echo $loading_daily_days;
												if($loading_recurring_type=="")
															$loading_recurring_type="DD"?>
													<td class="main"><?php echo TEXT_SERVICE_TYPE_DAILY; ?></td>
													<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('loading_recurring_type', 'DD', ($loading_recurring_type=='DD'?true:false),'','onClick=javascript:clear_load_content();') . sprintf(TEXT_DAYS_DISPLAY , tep_draw_input_field('loading_daily_days', $loading_daily_days,'size=5 maxlength=2') ); ?></td>
												</Tr>
												<tr>
													<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
												</tr>
												<Tr>
													<td class="main"><?php echo TEXT_SERVICE_TYPE_WEEKLY; ?></td>
													<?php  
														//	echo $week_selected;
														//	$days_select_array=split(",",$week_selected);
															$count=0;
															$icnt=1;
															$loading_week_days=array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
															$loading_check_weekdays="";
															$loading_check_weekdays='<table border="0" cellspacing="0" cellpadding="0" class="formArea"><tr>';
															for ($i = 0, $n = sizeof($loading_week_days); $i < $n; $i++) {
																$temp='<td class="main"';
																if ($i%2==0) $temp.=' bgcolor="#ebebff" ';
																$temp.='>';
															//	echo $no_booking_week_days[$i];
															//	echo $i;
																$temp.=tep_draw_checkbox_field('loading_week_days[]', $i+1, '','','') . '&nbsp;' . $loading_week_days[$i] . '&nbsp;';
																	//if($loading_days_select_array[$count]==$icnt)
																	//	$count++;
																$temp.='</td>';
																$loading_check_weekdays.=$temp;
															//	echo $check_weekdays;
															//	echo $i;
															$icnt++;	
															}
															
															  $loading_check_weekdays.="</tr></table>";
														?>
											 		  <td colspan="2">
													  <table cellpadding="0" cellspacing="0" ><tr><Td class="main"><?php  echo tep_draw_separator('pixel_trans.gif', '24', '15')  .'&nbsp;' . tep_draw_radio_field('loading_recurring_type', 'WW', ($loading_recurring_type=='WW'?true:false),'','onClick=javascript:clear_load_content();'); ?></td>
													  <td class="main"><?php echo sprintf(TEXT_WEEKS_DISPLAY,tep_draw_input_field('loading_weekly_weeks', $loading_weekly_weeks,'size=5 maxlength=2')) . '&nbsp;'; ?></td>
													  <td class="main"><?php  echo $loading_check_weekdays; ?> </td>
											 	 </tr>
											</table></td>
										</Tr>
										<tr>
											<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
										</tr>
										<tr>
											<td class="main"><?php echo TEXT_SERVICE_TYPE_MONTHLY; ?></td>
											<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('loading_recurring_type', 'MD', ($loading_recurring_type=='MD'?true:false),'','onClick=javascript:clear_load_content();') . sprintf(TEXT_MONTHS_DISPLAY1, tep_draw_input_field('loading_monthly_days', $loading_monthly_days ,'size=5 maxlength=2') , tep_draw_input_field('loading_monthly_months', $loading_monthly_months ,'size=5 maxlength=2') ); ?><br><br>
															 <?php  echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('loading_recurring_type', 'MM', ($loading_recurring_type=='MM'?true:false),'','onClick=javascript:clear_load_content();') . sprintf(TEXT_MONTHS_DISPLAY2, tep_draw_date_combo_select('weeks','loading_monthly_weeks',$loading_monthly_weeks) , tep_draw_date_combo_select('days',"loading_monthly_week_days",$loading_monthly_week_days) , tep_draw_input_field('loading_monthly_week_months', $loading_monthly_week_months,'size=5 maxlength=2')); ?></td>
										</tr>
										<tr>
											<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
										</tr>
										<tr>
											<td class="main"><?php echo TEXT_SERVICE_TYPE_YEARLY; ?></td>
											<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('loading_recurring_type', 'YD', ($loading_recurring_type=='YD'?true:false),'','onClick=javascript:clear_load_content();') .sprintf(TEXT_YEARS_DISPLAY1, tep_draw_date_combo_select('months','loading_yearly_months',$loading_yearly_months) , tep_draw_input_field('loading_yearly_month_days', $loading_yearly_month_days,'size=5 maxlength=2'));?><br><br>
														 <?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('loading_recurring_type', 'YY', ($loading_recurring_type=='YY'?true:false),'','onClick=javascript:clear_load_content();') .sprintf(TEXT_YEARS_DISPLAY2,tep_draw_date_combo_select('weeks','loading_yearly_weeks',$loading_yearly_weeks), tep_draw_date_combo_select('days',"loading_yearly_week_days",$loading_yearly_week_days), tep_draw_date_combo_select('months',"loading_yearly_week_months",$loading_yearly_week_months));?></td>
										</tr>
										<tr>
											<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
										</tr>
										<tr>
											<td colspan="2">
											<table border="0" cellpadding="4" cellspacing="0" width="810" >
												<tr>
													<td class="main" colspan="4" ><?php echo tep_draw_pull_down_menu('loading_date_list',$loading_array,'','id="loading_date_list" size=10 style="width:100%" onClick="javascript:do_date_action_load(\'select\');"');
														echo tep_draw_hidden_field('loading_dates');
													?></td>
													<td class="main" valign="middle" width="5%"><?php echo '<a href="javascript:do_date_action_load(\'add\');">' . tep_image_button('button_add.gif',IMAGE_ADD_DATE) . '</a><br><br><a href="javascript:do_date_action_load(\'edit\')">' . tep_image_button('button_update.gif',IMAGE_EDIT_DATE) . '<a><br><br><a href="javascript:do_date_action_load(\'delete\')">' . tep_image_button('button_delete.gif',IMAGE_DELETE_DATE) . '<a>';?></td>
												</tr>
												<tr>
													<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
												</tr>
												<tr>
												
													<td class="main" valign="middle">&nbsp;<?php echo TEXT_SERVICES_LOADING_PRICE;?></td>
													<td class="main"><?php echo tep_draw_input_field('loading_price',$loading_price);?></td>
													
												<!--</tr>
												<tr>
													<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
												</tr>
												<tr>-->
													<td width="150" class="main">&nbsp;<?php echo TEXT_SERVICES_LOADING_TYPE;?></td>
													<td class="main" valign="top"><?php echo tep_draw_pull_down_menu("loading_type",$loading_type_array,$loading_type,'');?>
													</td>
												</tr>
		
												<tr>
													<td>&nbsp;</td>
													<td class="main" width="200" valign="top"><?php //echo tep_draw_date_field("no_booking_date",format_date($current_date),"size=10");?>
													</td>
													<td colspan="2">&nbsp;</td>
												</tr>
											</table>
											</td>
										</tr>	
									</table></Td>
									</Tr>	
								</table>
							</td></tr>
						</table>
					</td>
				</Tr> 
					<?php tep_content_title_bottom(); ?>
					
					
					<?php tep_content_title_top("Conditions"); ?>
					<tr>
						<td  width="400">
						<table border="0"  cellspacing="0" cellpadding="4">
							<tr>
								<td class="main" width="150"><?php echo TEXT_SERVICES_PENDING_PERIOD;?></td>
								<td class="main"><?php echo tep_draw_input_field("pending_period",$suInfo->pending_period,'size=5 maxlength:6') . '&nbsp;' . TEXT_SERVICES_DAYS;?></td>
							</tr>
							<tr>
								<td class="main" width="150"><?php echo TEXT_SERVICES_RENEWAL_START; ?></td>
								<td class="main" width="200" valign="top" ><?php echo tep_draw_input_field("service_renewal_start",$suInfo->service_renewal_start,'size=5 maxlength:6').'&nbsp;' . TEXT_SERVICES_DAYS;?></td>
							</tr>
							<tr>
								<td class="main" width="150"><?php echo TEXT_SERVICES_RENEWAL_END;?></td>
								<td class="main" width="200" valign="top" ><?php echo tep_draw_input_field("service_renewal_end",$suInfo->service_renewal_end,'size=5 maxlength:6') . '&nbsp;' . TEXT_SERVICES_DAYS;?></td>
							</tr>
							<tr>
								<td colspan="2" class="main"><?php echo tep_draw_checkbox_field('multiple_purchase','Y',($suInfo->multiple_purchase=='Y'?true:false),'',($suInfo->include_resource=='Y')?'disabled':'enabled') . TEXT_MULTIPLE_PURCHASES;?></td>
							</tr>	
						</table>
						</td>
						<td align="left" width="" valign="top">
									<table border="0" cellpadding="0" cellspacing="0">
										<tr>	
											<td class="main" width="150" valign="top"><?php echo '&nbsp;&nbsp;'.TEXT_SERVICES_CONDITIONS;?></td>
											<td class="main" width="200"><?php echo tep_draw_textarea_field("service_conditions",'wrap',50,5,$suInfo->service_conditions);?></td>
										</tr>
									</table>
								</td>
					</tr>
					<?php tep_content_title_bottom(); ?>
					<script language="javascript">
						<!-- 
						init_page();
						//-->
					</script>
					<tr>
						<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
					</tr>
					<tr>
						<td class="main" align="right">
							<?php 
								echo tep_draw_hidden_field('service_date_added', (($suInfo->date_added) ? $suInfo->date_added : date('Y-m-d'))) . tep_image_submit('button_save.gif', IMAGE_SAVE_SERVICES) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_SERVICES_MAINPAGE,'top=1&mPath=3') . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; 
							?>
						</td>
					</tr>
				</table>
				</td>
			</tr>
			
	<?php
	  if (HTML_AREA_WYSIWYG_DISABLE == 'Disable') {} else {
	  for ($i = 0, $n = sizeof($languages); $i < $n; $i++) { ?>
            <script>initEditor('service_description[<?php echo $languages[$i]['id']; ?>]');</script>
	<?php }
	   }
	} elseif ($HTTP_GET_VARS['action'] == 'new_service_category_preview') {
		if ($HTTP_POST_VARS) {
			$sucInfo = new objectInfo($HTTP_POST_VARS);
			$services_categories_name = $HTTP_POST_VARS['services_categories_name'];
			$services_categories_heading_title = $HTTP_POST_VARS['services_categories_heading_title'];
			$services_categories_description = $HTTP_POST_VARS['services_categories_description'];
			$services_categories_notes = $HTTP_POST_VARS['services_categories_notes'];
			// copy image only if modified
			$services_categories_image = new upload('services_categories_image');
			$services_categories_image->set_destination(DIR_FS_CATALOG_IMAGES);
			if ($services_categories_image->parse() && $services_categories_image->save()) {
				$services_categories_image_name = $services_categories_image->filename;
			} else {
				$services_categories_image_name = $HTTP_POST_VARS['services_categories_previous_image'];
			}
	    } else {
			$service_category_query = tep_db_query("SELECT suc.services_categories_id, sucd.language_id,  sucd.services_categories_heading_title,
			 sucd.services_categories_description, suc.services_categories_image, suc.sort_order, suc.date_added, suc.last_modified,sucd.services_categories_notes from " . TABLE_SERVICES_CATEGORIES . " suc, " . TABLE_SERVICES_CATEGORIES_DESCRIPTION . " 
			sucd where suc.services_categories_id = sucd.services_categories_id and suc.services_categories_id = '" . (int)$HTTP_GET_VARS['secID'] . "' and sucd.language_id='" . $languages_id . "'");
			
			$service_category = tep_db_fetch_array($service_category_query);
			
			$sucInfo = new objectInfo($service_category);
			$services_categories_image_name = $sucInfo->services_categories_image;
		}

		$form_action = ($HTTP_GET_VARS['secID']) ? 'update_service_category' : 'insert_service_category';
		
		echo tep_draw_form($form_action, FILENAME_SERVICES, 'secPath=' . $secPath . '&secID=' . $HTTP_GET_VARS['secID'] . '&action=' . $form_action, 'post', 'enctype="multipart/form-data"');
		$languages = tep_get_languages();
		for ($i=0; $i<sizeof($languages); $i++) {
			if ($HTTP_GET_VARS['read'] == 'only') {
				$sucInfo->services_categories_name = tep_get_service_category_name($sucInfo->services_categories_id, $languages[$i]['id']);
				$sucInfo->services_categories_heading_title = tep_get_service_category_title($sucInfo->services_categories_id, $languages[$i]['id']);
				$sucInfo->services_categories_description = tep_get_service_category_description($sucInfo->services_categories_id, $languages[$i]['id']);
				$sucInfo->services_categories_notes = tep_get_service_category_notes($sucInfo->services_categories_id, $languages[$i]['id']);
			} else {
				$sucInfo->services_categories_name = tep_db_prepare_input($services_categories_name[$languages[$i]['id']]);
				$sucInfo->services_categories_heading_title = tep_db_prepare_input($services_categories_heading_title[$languages[$i]['id']]);
				$sucInfo->services_categories_description = tep_db_prepare_input($services_categories_description[$languages[$i]['id']]);
				$sucInfo->services_categories_notes = tep_db_prepare_input($services_categories_notes[$languages[$i]['id']]);
			}
	?>
		  <tr>
			<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
			  <tr>
				<td class="pageHeading"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . $sucInfo->services_categories_heading_title; ?></td>
			  </tr>
			</table></td>
		  </tr>
		  <tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		  </tr>
		  <tr>
			<td class="main"><?php echo tep_image(DIR_WS_CATALOG_IMAGES . $services_categories_image_name, $sucInfo->services_categories_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="right" hspace="5" vspace="5"') . $sucInfo->services_categories_description; ?></td>
		  </tr>
          <tr>
		    <td class="main"><?php echo $sucInfo->services_categories_notes ;?></td>
		  </tr>
		<?php
			}
			if ($HTTP_GET_VARS['read'] == 'only') {
			  if ($HTTP_GET_VARS['origin']) {
				$pos_params = strpos($HTTP_GET_VARS['origin'], '?', 0);
				if ($pos_params != false) {
				  $back_url = substr($HTTP_GET_VARS['origin'], 0, $pos_params);
				  $back_url_params = substr($HTTP_GET_VARS['origin'], $pos_params + 1);
				} else {
				  $back_url = $HTTP_GET_VARS['origin'];
				  $back_url_params = '';
				}
			  } else {
				$back_url = FILENAME_SERVICES;
				$back_url_params = 'secPath=' . $secPath . '&secID=' . $sucInfo->services_categories_id;
			  }
		?>
	  <tr>
		<td align="right"><?php echo '<a href="' . tep_href_link($back_url, $back_url_params, 'NONSSL') . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>'; ?></td>
	  </tr>
		<?php
			} else {
		?>
			  <tr>
				<td align="right" class="smallText">
		<?php
		/* Re-Post all POST'ed variables */
			  reset($HTTP_POST_VARS);
			  while (list($key, $value) = each($HTTP_POST_VARS)) {
				if (!is_array($HTTP_POST_VARS[$key])) {
				  echo tep_draw_hidden_field($key, htmlspecialchars(stripslashes($value)));
				}
			  }
			  $languages = tep_get_languages();
			  for ($i=0; $i<sizeof($languages); $i++) {
				echo tep_draw_hidden_field('services_categories_name[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($services_categories_name[$languages[$i]['id']])));
				echo tep_draw_hidden_field('services_categories_heading_title[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($services_categories_heading_title[$languages[$i]['id']])));
				echo tep_draw_hidden_field('services_categories_description[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($services_categories_description[$languages[$i]['id']])));
				echo tep_draw_hidden_field('services_categories_notes[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($services_categories_notes[$languages[$i]['id']])));
			  }
			  echo tep_draw_hidden_field('X_services_categories_image', stripslashes($services_categories_image_name));
			  echo tep_draw_hidden_field('services_categories_image', stripslashes($services_categories_image_name));
		
			  echo tep_image_submit('button_back.gif', IMAGE_BACK, 'name="edit"') . '&nbsp;&nbsp;';
		
			  if ($HTTP_GET_VARS['secID']) {
				echo tep_image_submit('button_update.gif', IMAGE_UPDATE);
			  } else {
				echo tep_image_submit('button_insert.gif', IMAGE_INSERT);
			  }
			  echo '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&secID=' . $HTTP_GET_VARS['secID']) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
		?></td>
      	</form></tr>
		<?php
    		}
		  } else if ($action=="new_service_preview") {
  
		   if (tep_not_null($HTTP_POST_VARS)) {
			  $suInfo = new objectInfo($HTTP_POST_VARS);
			  $service_name = $HTTP_POST_VARS['service_name'];
			  $service_description = $HTTP_POST_VARS['service_description'];
			  $service_url = $HTTP_POST_VARS['service_url'];
			} else {
			  $service_query = tep_db_query("SELECT su.service_id, sud.language_id, sud.service_name, sud.service_description, sud.service_url, su.service_image, su.service_date_added, su.service_last_modified, su.service_date_available, su.service_status,su.service_costs,su.booking_type " . 
										  " from " . TABLE_SERVICES . " su, " . TABLE_SERVICES_DESCRIPTION . 
						  				  " sud where su.service_id = sud.service_id and su.service_id = '" . (int)$HTTP_GET_VARS['seID'] . "' and language_id='" . $languages_id . "'");
			  $service = tep_db_fetch_array($service_query);
				$suInfo = new objectInfo($service);
		
			  $service_image_name = $suInfo->service_image;
			}
		
			$form_action = (isset($HTTP_GET_VARS['seID'])) ? 'update_service' : 'insert_service';

			echo tep_draw_form($form_action, FILENAME_SERVICES, '&secPath=' . $secPath . (isset($HTTP_GET_VARS['seID']) ? '&seID=' . $HTTP_GET_VARS['seID'] : '') . '&action=' . $form_action, 'post', 'enctype="multipart/form-data"');
		
			$languages = tep_get_languages();
			for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
			  if (isset($HTTP_GET_VARS['read']) && ($HTTP_GET_VARS['read'] == 'only')) {
			  } else {
				$suInfo->service_name = tep_db_prepare_input($service_name[$languages[$i]['name']]);
				$suInfo->service_description = tep_db_prepare_input($service_description[$languages[$i]['id']]);
				$suInfo->service_url = tep_db_prepare_input($service_url[$languages[$i]['id']]);
			  }
			  
			?>
		<table border="0" width="100%" cellspacing="0" cellpadding="2">
			<tr>
			<td>
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td class="pageHeading"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . $suInfo->service_name; ?></td>
					<td class="pageHeading" align="right"><?php echo $currencies->format($suInfo->service_costs); ?></td>
				</tr>
			</table>
			</td>
		</tr>
		<tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		</tr>
		<tr>
			<td class="main"><?php echo tep_image(DIR_WS_CATALOG_IMAGES . $service_image_name, $suInfo->service_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="right" hspace="5" vspace="5"') . $suInfo->service_description; ?></td>
		</tr>
		<?php
			  if ($suInfo->service_url) {
		?>
		<tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		</tr>
		<tr>
			<td class="main"><?php echo sprintf(TEXT_SERVICES_MORE_INFORMATION, $suInfo->service_url); ?></td>
		</tr>
		<?php
			  }
		?>
		<tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		</tr>
		<?php
			  if ($suInfo->service_date_available > $current_date) {
		?>
		<tr>
			<td align="center" class="smallText"><?php echo sprintf(TEXT_SERVICES_DATE_AVAILABLE_PRE,tep_date_long($suInfo->service_date_available)); ?></td>
		</tr>
		<?php
			  } else {
		?>
			<tr>
			<td align="center" class="smallText"><?php echo sprintf(TEXT_SERVICES_DATE_ADDED_PRE, tep_date_long($suInfo->service_date_added)); ?></td>
			</tr>
		<?php
			  }
		?>
		  <tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		  </tr>
		<?php
			}
		
			if (isset($HTTP_GET_VARS['read']) && ($HTTP_GET_VARS['read'] == 'only')) {
				  if (isset($HTTP_GET_VARS['origin'])) {
					$pos_params = strpos($HTTP_GET_VARS['origin'], '?', 0);
					if ($pos_params != false) {
					  $back_url = substr($HTTP_GET_VARS['origin'], 0, $pos_params);
					  $back_url_params = substr($HTTP_GET_VARS['origin'], $pos_params + 1);
					} else {
					  $back_url = $HTTP_GET_VARS['origin'];
					  $back_url_params = '';
					}
				  } else {
					$back_url = FILENAME_SERVICES;
					$back_url_params = 'secPath=' . $secPath . '&seID=' . $suInfo->service_id;
				  }
		?>
		  <tr>
			<td align="right"><?php echo '<a href="' . tep_href_link($back_url, $back_url_params, 'NONSSL') . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>'; ?></td>
		  </tr>
		<?php
			} else {
		?>
		  <tr>
			<td align="right" class="smallText">
			<?php
			if (false) {
			/* Re-Post all POST'ed variables */
				reset($HTTP_POST_VARS);
				  while (list($key, $value) = each($HTTP_POST_VARS)) {
					if (!is_array($HTTP_POST_VARS[$key])) {
					  echo tep_draw_hidden_field($key, htmlspecialchars(stripslashes($value)));
					}
				  }
				  $languages = tep_get_languages();
				  for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
					echo tep_draw_hidden_field('service_name[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($subsciption_name[$languages[$i]['id']])));
					echo tep_draw_hidden_field('service_description[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($service_description[$languages[$i]['id']])));
					echo tep_draw_hidden_field('service_url[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($service_url[$languages[$i]['id']])));
				  }
			} // false

			  reset($HTTP_POST_VARS);
			  while (list($key, $value) = each($HTTP_POST_VARS)) {
				if (is_array($value)) {
				  while (list($k, $v) = each($value)) {
					echo tep_draw_hidden_field($key . '[' . $k . ']', htmlspecialchars(stripslashes($v)));
				  }
				} else {
				  echo tep_draw_hidden_field($key, htmlspecialchars(stripslashes($value)));
				}
			  }
			  echo tep_draw_hidden_field('service_image', stripslashes($service_image_name));
		
			  echo tep_image_submit('button_back.gif', IMAGE_BACK, 'name="edit"') . '&nbsp;&nbsp;';
		
			  if (isset($HTTP_GET_VARS['seID'])) {
				echo tep_image_submit('button_update.gif', IMAGE_UPDATE);
			  } else {
				echo tep_image_submit('button_insert.gif', IMAGE_INSERT);
			  }
			  echo '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . (isset($HTTP_GET_VARS['seID']) ? '&seID=' . $HTTP_GET_VARS['seID'] : '')) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
		  }
		?>
		</td>
    </tr>
</table>
	</form>
	<?php } else { ?>
			<table border="0" width="100%" cellspacing="0" cellpadding="2">
			  <tr>
				<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
				  <tr>
				    <!--<td class="pageHeading"><?PHP //if(!$current_service_category_id) echo HEADING_TITLE; ?></td>!-->
				    <td class="pageHeading"><?php echo tep_output_rev_generated_service_category_path($current_service_category_id); ?></td>
					<td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>
					<td align="right"><table border="0" width="100%" cellspacing="0" cellpadding="0">
					  <tr>
						<td class="smallText" align="right">
		<?php 
			echo tep_draw_form('search', FILENAME_SERVICES, '', 'get');
			echo HEADING_TITLE_SEARCH . ' ' . tep_draw_input_field('search');
			echo '</form>';
		?>
						</td>
					  </tr>
					   <tr>
						<td class="smallText" align="right">
		<?php
			echo tep_draw_form('goto', FILENAME_SERVICES, '', 'get');
			echo HEADING_TITLE_GOTO . ' ' . tep_draw_pull_down_menu('secPath', tep_get_services_category_tree(), $current_service_category_id, 'onChange="this.form.submit();"');
			echo '</form>';
			
			
			
		?>
						</td>
					  </tr>
				   </table></td>
				  </tr>
				  </table>
				  </td>
				</tr>  
			  <tr>
				<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
				  <tr>
					<td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
					  <tr class="dataTableHeadingRow">
						<td class="dataTableHeadingContent"><?php echo TABLE_HEADING_SERVICES_CATEGORIES; ?></td>
						<td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_SERVICES_STATUS; ?></td>
						<td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_SERVICES_ACTION; ?>&nbsp;</td>
					  </tr>
				<?php
					$services_categories_count = 0;
					$rows = 0;
					if (isset($HTTP_GET_VARS['search'])) {
					  $search = tep_db_prepare_input($HTTP_GET_VARS['search']);
				
					  $services_categories_query = tep_db_query("SELECT suc.services_categories_id, sucd.services_categories_name, suc.services_categories_image, suc.parent_id, suc.sort_order, suc.date_added, suc.last_modified from " . TABLE_SERVICES_CATEGORIES . " suc, " . TABLE_SERVICES_CATEGORIES_DESCRIPTION . " sucd where suc.services_categories_id = sucd.services_categories_id and sucd.language_id = '" . (int)$languages_id . "' and sucd.services_categories_name like '%" . tep_db_input($search) . "%' order by suc.sort_order, sucd.services_categories_name");
					  
					} else {
					  $services_categories_query = tep_db_query("SELECT suc.services_categories_id, sucd.services_categories_name, suc.services_categories_image, suc.parent_id, suc.sort_order, suc.date_added, suc.last_modified from " . TABLE_SERVICES_CATEGORIES . " suc, " . TABLE_SERVICES_CATEGORIES_DESCRIPTION . " sucd where suc.services_categories_id = sucd.services_categories_id and suc.parent_id = '" . (int)$current_service_category_id . "' and sucd.language_id = '" . (int)$languages_id . "' order by suc.sort_order, sucd.services_categories_name");
					 
					}
					while ($services_categories = tep_db_fetch_array($services_categories_query)) {
					  $services_categories_count++;
					  $rows++;
					  // Get parent_id for subcategories if search
					  if (isset($HTTP_GET_VARS['search'])) $secPath=$services_categories['parent_id'];

					  if ((!isset($HTTP_GET_VARS['secID']) && !isset($HTTP_GET_VARS['seID']) || (isset($HTTP_GET_VARS['secID']) && ($HTTP_GET_VARS['secID'] == $services_categories['services_categories_id']))) && !isset($sucInfo) && (substr($action, 0, 3) != 'new')) {
						$service_category_childs = array('childs_count' => tep_childs_in_service_category_count($services_categories['services_categories_id']));
						$service_category_service = array('service_count' => tep_service_in_service_category_count($services_categories['services_categories_id']));
						$sucInfo_array = array_merge($services_categories, $service_category_childs, $service_category_service);
						$sucInfo = new objectInfo($sucInfo_array);  
					  }
					  if (isset($sucInfo) && is_object($sucInfo) && ($services_categories['services_categories_id'] == $sucInfo->services_categories_id) ) {
						echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&secID=' . $services_categories['services_categories_id'] . '&action=new_service_category_preview&read=only') . '\'">' . "\n";
					  } else {
						echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&secID=' . $services_categories['services_categories_id']) . '\'">' . "\n";
					  } ?>
					<td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_SERVICES, tep_get_service_path($services_categories['services_categories_id'])) . '">' . tep_image(DIR_WS_ICONS . 'folder.gif', ICON_FOLDER) . '</a>&nbsp;<b>' . $services_categories['services_categories_name'] . '</b>'; ?></td>
					<td class="dataTableContent" align="center">&nbsp;</td>
					<td class="dataTableContent" align="right"><?php if (isset($sucInfo) && is_object($sucInfo) && ($services_categories['services_categories_id'] == $sucInfo->services_categories_id) ) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&secID=' . $services_categories['services_categories_id'] . '&action=new_service_category_preview&read=only') . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
				  </tr>
				<?php
					}
					$service_count=0;
					if (isset($HTTP_GET_VARS['search'])) {
						$service_query = tep_db_query("SELECT su.service_id, sud.service_name, su.service_image, su.service_date_added, su.service_last_modified, su.service_date_available, su.service_status, su2c.services_categories_id from " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " su2c, " . TABLE_SERVICES . " su, " . TABLE_SERVICES_DESCRIPTION . " sud  where su.service_id = su2c.service_id and su.service_id = sud.service_id and sud.language_id = '" . (int)$languages_id . "' and sud.service_name like '%" . tep_db_input($search) . "%' order by sud.service_name");
						
					} else {
						$service_query = tep_db_query("SELECT su.service_id, sud.service_name, su.service_image, su.service_date_added, su.service_last_modified, su.service_date_available, su.service_status from " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " su2c, " . TABLE_SERVICES . " su, " . TABLE_SERVICES_DESCRIPTION . " sud where su.service_id = su2c.service_id and su.service_id=sud.service_id and sud.language_id = '" . (int)$languages_id . "' and su2c.services_categories_id = '" . (int)$current_service_category_id . "' order by sud.service_name");
						
					}
					while( $service=tep_db_fetch_array($service_query)){
						$rows++;
						$service_count++;
			
						if ( (!isset($HTTP_GET_VARS['seID']) && !isset($HTTP_GET_VARS['secID']) || (isset($HTTP_GET_VARS['seID']) && ($HTTP_GET_VARS['seID'] == $service['service_id']))) && !isset($suInfo) && !isset($sucInfo) && (substr($action, 0, 3) != 'new')){
							$service_attributes = array('attribute_count' => tep_service_in_attribute_count($service['service_id']));
							$suInfo_array = array_merge($service, $service_attributes);
							//$suInfo=new objectInfo($service_attributes);
							$suInfo=new objectInfo($suInfo_array);
						}

						
					  if (isset($suInfo) && is_object($suInfo) && ($service['service_id'] == $suInfo->service_id)) {
						echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&seID=' . $service['service_id'] . '&action=new_service_preview&read=only') . '\'">' . "\n";
					  } else {
						echo '              <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&seID=' . $service['service_id']) . '\'">' . "\n";
					  }
				?>
									<td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&seID=' . $service['service_id']) . '&action=new_service_preview&read=only' . '">' . tep_image(DIR_WS_ICONS . 'preview.gif', ICON_PREVIEW) . '</a>&nbsp;' . $service["service_name"]; ?></td>
					                <td class="dataTableContent" align="left">
										<?php
											  if ($service['service_status'] == '1') {
											   echo tep_image(DIR_WS_IMAGES . 'icon_status_green.gif', IMAGE_ICON_STATUS_GREEN, 10, 10) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_SERVICES, 'action=setflag&flag=0&secPath=' . $secPath . '&seID=' . $service['service_id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 10, 10) . '</a>';
												  } else {
												echo '<a href="' . tep_href_link(FILENAME_SERVICES, 'action=setflag&flag=1&secPath=' . $secPath . '&seID=' . $service['service_id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 10, 10) . '</a>&nbsp;&nbsp;' . tep_image(DIR_WS_IMAGES . 'icon_status_red.gif', IMAGE_ICON_STATUS_RED, 10, 10);
												if ($service['service_status']==2){
													echo '&nbsp;' . tep_image(DIR_WS_ICONS . 'warning.gif',IMAGE_HIDE_START_SERVICES);
												} else if($service['service_status']>=3) {
													echo '&nbsp;' . tep_image(DIR_WS_ICONS . 'warning.gif',IMAGE_HIDE_END_SERVICES);
												}
											  }
										?>
									</td>
					                <td class="dataTableContent" align="right"><?php if (isset($suInfo) && is_object($suInfo) && ($service['service_id'] == $suInfo->service_id)) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&seID=' . $service['service_id']  . '&action=new_service_preview&read=only') . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
								</tr>
							<?php
								}
									$secPath_back = '';
									if (sizeof($secPath_array) > 0) {
									  for ($i=0, $n=sizeof($secPath_array)-1; $i<$n; $i++) {
										if (empty($secPath_back)) {
										  $secPath_back .= $secPath_array[$i];
										} else {
										  $secPath_back .= '_' . $secPath_array[$i];
										}
									  }
									}
									
									$secPath_back = (tep_not_null($secPath_back)) ? 'secPath=' . $secPath_back . '&' : '';
							?>
								  <tr>
									<td colspan="3"><table border="0" width="100%" cellspacing="0" cellpadding="2">
									  <tr>
										<td class="smallText"><?php echo TEXT_SERVICES_CATEGORIES . '&nbsp;' . $services_categories_count . '<br>' . TEXT_SERVICES . '&nbsp;' . $service_count; ?></td>
										<td align="right" class="smallText"><?php if (sizeof($secPath_array) > 0) echo '<a href="' . tep_href_link(FILENAME_SERVICES, $secPath_back . 'secID=' . $current_service_category_id) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>&nbsp;';
										 if (!isset($HTTP_GET_VARS['search'])) echo '<a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&action=new_service_category') . '">' . tep_image_button('button_new_category.gif', IMAGE_NEW_CATEGORY) . '</a>&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&action=new_service') . '">' . tep_image_button('button_new_service.gif', IMAGE_NEW_SERVICES) . '</a>'; ?>&nbsp;</td>
									  </tr>
									</table>
									</td>
								  </tr>
							</table>
							</td >
							<?php
								$heading = array();
								$contents = array();
								switch ($action) {
								  case 'new_service_category':
										$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_NEW_SERVICES_CATEGORY . '</b>');
										$contents = array('form' => tep_draw_form('new_service_category', FILENAME_SERVICES, 'action=insert_service_category&secPath=' . $secPath, 'post', 'enctype="multipart/form-data"'));
										$contents[] = array('text' => TEXT_NEW_SERVICES_CATEGORY_INTRO);
								
										$service_category_inputs_string = '';
										$languages = tep_get_languages();
										for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
										  $service_category_inputs_string .= '<br>' . tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('services_categories_name[' . $languages[$i]['id'] . ']');
										}
										$contents[] = array('text' => '<br>' . TEXT_SERVICES_CATEGORIES_NAME . $service_category_inputs_string);
										$contents[] = array('text' => '<br>' . TEXT_SERVICES_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('services_categories_image'));
										$contents[] = array('text' => '<br>' . TEXT_SORT_ORDER . '<br>' . tep_draw_input_field('sort_order', '', 'size="2"'));
										$contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_save.gif', IMAGE_SAVE) . ' <a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
										break;
								  case 'edit_service_category':
										$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_EDIT_SERVICES_CATEGORY . '</b>');
					
										$contents = array('form' => tep_draw_form('services_categories', FILENAME_SERVICES, 'action=update_service_category&secPath=' . $secPath, 'post', 'enctype="multipart/form-data"') . tep_draw_hidden_field('services_categories_id', $sucInfo->services_categories_id));
										$contents[] = array('text' => TEXT_EDIT_INTRO);
								
										$service_category_inputs_string = '';
										$languages = tep_get_languages();
										for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
										  $service_category_inputs_string .= '<br>' . tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('services_categories_name[' . $languages[$i]['id'] . ']', tep_get_service_category_name($sucInfo->services_categories_id, $languages[$i]['id']));
										}
								
										$contents[] = array('text' => '<br>' . TEXT_EDIT_SERVICES_CATEGORIES_NAME . $service_category_inputs_string);
										$contents[] = array('text' => '<br>' . tep_image(DIR_WS_CATALOG_IMAGES . $sucInfo->services_categories_image, $sucInfo->categories_name) . '<br>' . DIR_WS_CATALOG_IMAGES . '<br><b>' . $sucInfo->services_categories_image . '</b>');
										$contents[] = array('text' => '<br>' . TEXT_EDIT_SERVICES_CATEGORIES_IMAGE . '<br>' . tep_draw_file_field('services_categories_image'));
										$contents[] = array('text' => '<br>' . TEXT_EDIT_SORT_ORDER . '<br>' . tep_draw_input_field('sort_order', $sucInfo->sort_order, 'size="2"'));
										$contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_save.gif', IMAGE_SAVE) . ' <a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&secID=' . $sucInfo->services_categories_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
										break;
								  case 'delete_service_category':
										$err_delete=false;
										if ($sucInfo->service_count>0 || $sucInfo->childs_count>0)
									   $err_delete=true;
										$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_SERVICES_CATEGORY . '</b>');
										$contents = array('form' => tep_draw_form('services_categories', FILENAME_SERVICES, 'action=delete_service_category_confirm&secPath=' . $secPath) . tep_draw_hidden_field('services_categories_id', $sucInfo->services_categories_id));
										$contents[] = array('text' => TEXT_DELETE_SERVICES_CATEGORY_INTRO);
										$contents[] = array('text' => '<br><b>' . $sucInfo->services_categories_name . '</b>');
										if ($sucInfo->childs_count>0) $contents[] = array('text' => '<br>' . sprintf(TEXT_DELETE_WARNING_CHILDS, $sucInfo->childs_count));
										if ($sucInfo->service_count>0) $contents[] = array('text' => '<br>' . sprintf(TEXT_DELETE_WARNING_SERVICES, $sucInfo->service_count));
										$contents[] = array('align' => 'center', 'text' => '<br>' . ($err_delete==false?tep_image_submit('button_delete.gif', IMAGE_DELETE):'') . ' <a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&secID=' . $sucInfo->services_categories_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
										
										break;
									case 'move_service_category':
										$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_MOVE_SERVICES_CATEGORY . '</b>');
					
										$contents = array('form' => tep_draw_form('services_categories', FILENAME_SERVICES, 'action=move_service_category_confirm&secPath=' . $secPath) . tep_draw_hidden_field('services_categories_id', $sucInfo->services_categories_id));
										$contents[] = array('text' => sprintf(TEXT_MOVE_SERVICES_CATEGORIES_INTRO, $sucInfo->services_categories_name));
										$contents[] = array('text' => '<br>' . sprintf(TEXT_MOVE, $sucInfo->services_categories_name) . '<br>' . tep_draw_pull_down_menu('move_to_service_category_id', tep_get_services_category_tree(), $current_service_category_id));
										$contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_move.gif', IMAGE_MOVE) . ' <a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&secID=' . $sucInfo->services_categories_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
										break;
									case 'move_service':
										$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_MOVE_SERVICES . '</b>');
								
										$contents = array('form' => tep_draw_form('service', FILENAME_SERVICES, 'action=move_service_confirm&secPath=' . $secPath) . tep_draw_hidden_field('service_id', $suInfo->service_id));
										$contents[] = array('text' => sprintf(TEXT_MOVE_SERVICES_INTRO, $sucInfo->service_name));
										$contents[] = array('text' => '<br>' . TEXT_INFO_CURRENT_SERVICES_CATEGORIES . '<br><b>' . tep_output_generated_service_category_path($suInfo->service_id, 'service') . '</b>');
										$contents[] = array('text' => '<br>' . sprintf(TEXT_MOVE, $sucInfo->service_name) . '<br>' . tep_draw_pull_down_menu('move_to_service_category_id', tep_get_services_category_tree(), $current_service_category_id));
										$contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_move.gif', IMAGE_MOVE) . ' <a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&seID=' . $suInfo->service_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
										break;
								  	case 'delete_service':
								  		$err_delete=false;
										if ($suInfo->attribute_count>0 )
									   	$err_delete=true;
										$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_SERVICES . '</b>');
								
										$contents = array('form' => tep_draw_form('service', FILENAME_SERVICES, 'action=delete_service_confirm&secPath=' . $secPath) . tep_draw_hidden_field('service_id', $suInfo->service_id));
										$contents[] = array('text' => TEXT_DELETE_SERVICES_INTRO);
										$contents[] = array('text' => '<br><b>' . $suInfo->service_name . '</b>');
										if ($suInfo->attribute_count>0) $contents[] = array('text' => '<br>' . sprintf(TEXT_DELETE_WARNING_SERVICES, $suInfo->attribute_count));

										if($err_delete==false){
										$services_categories_string = '';
										$services_categories = tep_generate_service_category_path($suInfo->service_id, 'service');
										
										
										for ($i = 0, $n = sizeof($services_categories); $i < $n; $i++) {
											$service_category_path = '';
											for ($j = 0, $k = sizeof($services_categories[$i]); $j < $k; $j++) {
												$service_category_path .= $services_categories[$i][$j]['text'] . '&nbsp;&gt;&nbsp;';
											}
											$service_category_path = substr($service_category_path, 0, -16);
											
											$services_categories_string .= tep_draw_checkbox_field('services_categories[]', $services_categories[$i][sizeof($services_categories[$i])-1]['id'], true) . '&nbsp;' . $service_category_path . '<br>';
										
										}
										$services_categories_string = substr($services_categories_string, 0, -4);
								
										$contents[] = array('text' => '<br>' . $services_categories_string);}
								        $contents[] = array('align' => 'center', 'text' => '<br>' . ($err_delete==false?tep_image_submit('button_delete.gif', IMAGE_DELETE):'') . ' <a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&seID=' . $suInfo->service_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
								        break;
									case 'copy_to':
										$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_COPY_TO . '</b>');
										$contents = array('form' => tep_draw_form('copy_to', FILENAME_SERVICES, 'action=copy_to_confirm&secPath=' . $secPath) . tep_draw_hidden_field('service_id', $suInfo->service_id));
										$contents[] = array('text' => TEXT_INFO_COPY_TO_INTRO);
										$contents[] = array('text' => '<br>' . TEXT_INFO_CURRENT_SERVICES_CATEGORIES . '<br><b>' . tep_output_generated_service_category_path($suInfo->service_id, 'service') . '</b>');
										$contents[] = array('text' => '<br>' . TEXT_SERVICES_CATEGORIES . '<br>' . tep_draw_pull_down_menu('services_categories_id', tep_get_services_category_tree(), $current_service_category_id));
										$contents[] = array('text' => '<br>' . TEXT_HOW_TO_COPY . '<br>' . tep_draw_radio_field('copy_as', 'link', true) . ' ' . TEXT_COPY_AS_LINK . '<br>' . tep_draw_radio_field('copy_as', 'duplicate') . ' ' . TEXT_COPY_AS_DUPLICATE);
										$contents[] = array('text' => '<br>' . tep_draw_checkbox_field('copy_service','1')  . TEXT_COPY_MESSAGES);
										$contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_copy.gif', IMAGE_COPY) . ' <a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&seID=' . $suInfo->service_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
										break;
									default:
									
										if ($rows>0) {
										  if (isset($sucInfo) && is_object($sucInfo)) { // category info box contents
										 
											$heading[] = array('text' => '<b>' . $sucInfo->services_categories_name . '</b>');
											$contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&secID=' . $sucInfo->services_categories_id . '&action=edit_service_category') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&secID=' . $sucInfo->services_categories_id . '&action=delete_service_category') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) 
											 . '</a> <a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&secID=' . $sucInfo->services_categories_id . '&action=move_service_category') . '">' . tep_image_button('button_move.gif',IMAGE_MOVE) . '</a>');
											$contents[] = array('text' => '<br>' . TEXT_DATE_ADDED . ' ' . format_date($sucInfo->date_added));
											if (tep_not_null($sucInfo->last_modified)) $contents[] = array('text' => TEXT_LAST_MODIFIED . ' ' . format_date($sucInfo->last_modified));
											$contents[] = array('text' => '<br>' . tep_info_image($sucInfo->services_categories_image, $sucInfo->services_categories_name, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT) . '<br>' . $sucInfo->services_categories_image);
											$contents[] = array('text' => '<br>' . TEXT_SUB_SERVICES_CATEGORIES . ' ' . $sucInfo->childs_count . '<br>' . TEXT_SERVICES . ' ' . $sucInfo->service_count);
									  } elseif (isset($suInfo) && is_object($suInfo)) { // service info box contents
									  			

											$heading[] = array('text' => '<b>' . tep_get_service_name($suInfo->service_id, $languages_id) . '</b>');
											$contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&seID=' . $suInfo->service_id . '&action=new_service') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&seID=' . $suInfo->service_id . '&action=delete_service') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a><br>' 
																. '<a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&seID=' . $suInfo->service_id . '&action=move_service') . '">' . tep_image_button('button_move.gif', IMAGE_MOVE) . '</a> <a href="' . tep_href_link(FILENAME_SERVICES, 'secPath=' . $secPath . '&seID=' . $suInfo->service_id . '&action=copy_to') . '">' . tep_image_button('button_copy_to.gif', IMAGE_COPY_TO) . '</a><p>');
											
											$contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_SERVICES_MESSAGES, 'serviceID=' . $suInfo->service_id) . '">' . tep_image_button('button_messages.gif', IMAGE_SERVICES_MESSAGES) .'</a>'.'&nbsp;'. '<a href="' . tep_href_link(FILENAME_SERVICES_SMS_MESSAGES,'serviceID=' . $suInfo->service_id) . '">' . tep_image_button('button_sms.gif', IMAGE_SMS_MESSAGES) . '</a>');
											$contents[] = array('text' => '<br>' . TEXT_DATE_ADDED . ' ' . format_date($suInfo->service_date_added));
											if (tep_not_null($suInfo->service_last_modified)) $contents[] = array('text' => TEXT_LAST_MODIFIED . ' ' . format_date($suInfo->service_last_modified));
											if ($current_date < $suInfo->service_date_available) $contents[] = array('text' => TEXT_DATE_AVAILABLE . ' ' . format_date($suInfo->service_date_available));
											$contents[] = array('text' => '<br>' . tep_info_image($suInfo->service_image, $suInfo->service_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '<br>' . $suInfo->service_image);
										}
								  } else { // create service category/service info
									  $heading[] = array('text' => '<b>' . EMPTY_SERVICES_CATEGORY . '</b>');
							
									  $contents[] = array('text' => TEXT_NO_CHILD_SERVICES_CATEGORIES_OR_SERVICES);
								  }
								  break;
								}
								if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
								  echo '            <td width="25%" valign="top">' . "\n";
							
								  $box = new box;
								  echo $box->infoBox($heading, $contents);
							
								  echo '            </td>' . "\n";
								}
					?>
          </tr>
        </table></td>
      </tr>
    </table>
<?php
  }
?>
    </td>
<!-- body_text_eof //-->
  </tr>
</table>
<script language="javascript" type="text/javascript">
	function validate_image(){
		var image_types=Array(".png",".jpg",".jpeg",".gif");
		var frm = document.new_service_category;
		var error = "";
		if (frm.elements["services_categories_image"].value!="" && !check_mime_type(frm.elements["services_categories_image"],image_types)){
			error="* <?php echo ERR_IMAGE_UPLOAD_TYPE;?>\n";
		}
		if(error!=""){
			alert(error);
			return false;
		}
		return true;
	}
</script>
<!-- body_eof //-->

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

		
?>