<?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');
	
	
	
	
	$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
	$error = false;
	$processed = false;

	if (tep_not_null($action)) {
		switch ($action) {
			case 'insert':
			case 'update':
			$provider_firstname = tep_db_prepare_input($HTTP_POST_VARS['provider_firstname']);
			$provider_lastname = tep_db_prepare_input($HTTP_POST_VARS['provider_lastname']);
			$provider_email_address=tep_db_prepare_input($HTTP_POST_VARS['provider_email_address']);
			$provider_street_address = tep_db_prepare_input($HTTP_POST_VARS['provider_street_address']);
			$provider_suburb = tep_db_prepare_input($HTTP_POST_VARS['provider_suburb']);
			$provider_city = tep_db_prepare_input($HTTP_POST_VARS['provider_city']);
			$provider_state = tep_db_prepare_input($HTTP_POST_VARS['provider_state']);
			$provider_country = tep_db_prepare_input($HTTP_POST_VARS['provider_country']);
			$provider_postcode = tep_db_prepare_input($HTTP_POST_VARS['provider_postcode']);
			$provider_telephone = tep_db_prepare_input($HTTP_POST_VARS['provider_telephone']);
			$provider_fax = tep_db_prepare_input($HTTP_POST_VARS['provider_fax']);
			
			if (strlen($provider_firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) {
				$error = true;
				$entry_firstname_error = true;
			} else {
				$entry_firstname_error = false;
			}
			
			
			if (strlen($provider_lastname) < ENTRY_LAST_NAME_MIN_LENGTH) {
				$error = true;
				$entry_lastname_error = true;
			} else {
				$entry_lastname_error = false;
			}
			
			if (!tep_validate_email($provider_email_address)) {
				$error = true;
				$entry_email_address_check_error = true;
				
			} else {
				$entry_email_address_check_error = false;
			}
		
			if (strlen($provider_street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) {
				$error = true;
				$entry_street_address_error = true;
			} else {
				$entry_street_address_error = false;
			}

			if (strlen($provider_postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
				$error = true;
				$entry_post_code_error = true;
			} else {
				$entry_post_code_error = false;
			}

			if (strlen($provider_city) < ENTRY_CITY_MIN_LENGTH) {
				$error = true;
				$entry_city_error = true;
			} else {
				$entry_city_error = false;
			}

			if ($provider_country == false) {
				$error = true;
				$entry_country_error = true;
			} else {
				$entry_country_error = false;
			}
			if (ACCOUNT_STATE == 'true') {
				if ($entry_country_error == true) {
					$entry_state_error = true;
				} else {
					$zone_id = 0;
					$entry_state_error = false;
					$check_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = '" . (int)$provider_country . "'");
					$check_value = tep_db_fetch_array($check_query);
					$entry_state_has_zones = ($check_value['total'] > 0);
					if ($entry_state_has_zones == true) {
						$zone_query = tep_db_query("select zone_id from " . TABLE_ZONES . " where zone_country_id = '" . (int)$provider_country . "' and zone_name = '" . tep_db_input($provider_state) . "'");
						if (tep_db_num_rows($zone_query) == 1) {
							$zone_values = tep_db_fetch_array($zone_query);
							$entry_zone_id = $zone_values['zone_id'];
						} else {
							$error = true;
							$entry_state_error = true;
						}
					} else {
						if ($entry_state == false) {
							$error = true;
							$entry_state_error = true;
						}
					}
				}
				
			}
			if (strlen($provider_telephone) < ENTRY_TELEPHONE_MIN_LENGTH) {
				$error = true;
				$entry_telephone_error = true;
			} else {
				$entry_telephone_error = false;
			}
          
			$check_email = tep_db_query("select provider_email_address from " . TABLE_SERVICES_PROVIDERS . " where provider_email_address = '" . tep_db_input($provider_email_address) . "' and provider_id != '" . (int)$HTTP_GET_VARS['itID'] . "'");
			if (tep_db_num_rows($check_email)) {
				$error = true;
				$entry_email_address_exists = true;
			} else {
				$entry_email_address_exists = false;
			}
			$sql_data_array = array(
										'provider_firstname' => $provider_firstname,
										'provider_lastname' => $provider_lastname,
										'provider_email_address' => $provider_email_address,
										'provider_street_address'=>$provider_street_address,
										'provider_suburb'=>$provider_suburb,
										'provider_city'=>$provider_city,
										'provider_state'=>$provider_state,
										'provider_country'=>$provider_country,
										'provider_postcode'=>$provider_postcode,
										'provider_telephone'=>$provider_telephone,
										'provider_fax' => $provider_fax);

							$provider_id = tep_db_prepare_input($HTTP_GET_VARS['itID']);

			//if ($error == false) {
			
			//	$sql_data_array = array('service_firstname' => $service_firstname,
			//							'service_lastname' => $service_lastname,
			//							'service_email_address' =>$service_email_address);
				
				if ($action=='update'){
					tep_db_perform(TABLE_SERVICES_PROVIDERS, $sql_data_array, 'update', "provider_id ='" . (int)$provider_id . "'");
				} else {
					tep_db_perform(TABLE_SERVICES_PROVIDERS, $sql_data_array, 'insert');
					$provider_id = tep_db_insert_id();
				}

			tep_redirect(tep_href_link(FILENAME_SERVICES_PROVIDERS,'itID=' . $provider_id));
		
		//} else if ($error == true) {
		//					tep_db_perform(TABLE_SERVICES_PROVIDERS, $sql_data_array, 'update', "provider_id = '" . (int)$provider_id . "'");
							

		//	$itInfo = new objectInfo($HTTP_POST_VARS);
		//	$processed = true;
		//}
        break;
	/*case 'member_new':
		$service_firstname = tep_db_prepare_input($HTTP_POST_VARS['service_firstname']);
			$service_lastname = tep_db_prepare_input($HTTP_POST_VARS['service_lastname']);
		$service_email_address=tep_db_prepare_input($HTTP_POST_VARS['service_email_address']);
			$service_street_address = tep_db_prepare_input($HTTP_POST_VARS['service_street_address']);
			$service_suburb = tep_db_prepare_input($HTTP_POST_VARS['service_suburb']);
			$service_city = tep_db_prepare_input($HTTP_POST_VARS['service_city']);
			$service_state = tep_db_prepare_input($HTTP_POST_VARS['service_state']);
			$service_country = tep_db_prepare_input($HTTP_POST_VARS['service_country']);
			$service_postcode = tep_db_prepare_input($HTTP_POST_VARS['service_postcode']);
			$service_telephone = tep_db_prepare_input($HTTP_POST_VARS['service_telephone']);
			$service_fax = tep_db_prepare_input($HTTP_POST_VARS['service_fax']);
			
			if (strlen($service_firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) {
				$error = true;
				$entry_firstname_error = true;
			} else {
				$entry_firstname_error = false;
			}
			
			if (strlen($service_lastname) < ENTRY_LAST_NAME_MIN_LENGTH) {
				$error = true;
				$entry_lastname_error = true;
			} else {
				$entry_lastname_error = false;
			}
			
			if (tep_check_date_raw($service_dob,EVENTS_DATE_FORMAT)) {
				$entry_date_of_birth_error = false;
			} else {
				$error = true;
				$entry_date_of_birth_error = true;
			}
			
			
			if (!tep_validate_email($service_email_address)) {
				$error = true;
				$entry_email_address_check_error = true;
			} else {
				$entry_email_address_check_error = false;
			}
			
			if (strlen($service_street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) {
				$error = true;
				$entry_street_address_error = true;
			} else {
				$entry_street_address_error = false;
			}

			if (strlen($service_postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
				$error = true;
				$entry_post_code_error = true;
			} else {
				$entry_post_code_error = false;
			}

			if (strlen($service_city) < ENTRY_CITY_MIN_LENGTH) {
				$error = true;
				$entry_city_error = true;
			} else {
				$entry_city_error = false;
			}

			if ($service_country == false) {
				$error = true;
				$entry_country_error = true;
			} else {
				$entry_country_error = false;
			}

			if (ACCOUNT_STATE == 'true') {
				if ($entry_country_error == true) {
					$entry_state_error = true;
				} else {
					$zone_id = 0;
					$entry_state_error = false;
					$check_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = '" . (int)$service_country . "'");
					$check_value = tep_db_fetch_array($check_query);
					$entry_state_has_zones = ($check_value['total'] > 0);
					if ($entry_state_has_zones == true) {
						$zone_query = tep_db_query("select zone_id from " . TABLE_ZONES . " where zone_country_id = '" . (int)$service_country . "' and zone_name = '" . tep_db_input($service_state) . "'");
						if (tep_db_num_rows($zone_query) == 1) {
							$zone_values = tep_db_fetch_array($zone_query);
							$entry_zone_id = $zone_values['zone_id'];
						} else {
							$error = true;
							$entry_state_error = true;
						}
					} else {
						if ($entry_state == false) {
							$error = true;
							$entry_state_error = true;
						}
					}
				}
			}
			if (strlen($service_telephone) < ENTRY_TELEPHONE_MIN_LENGTH) {
				$error = true;
				$entry_telephone_error = true;
			} else {
				$entry_telephone_error = false;
			}

			$check_email = tep_db_query("select service_email_address from " . TABLE_SERVICES_PROVIDERS . " where service_email_address = '" . tep_db_input($service_email_address) . "' and provider_id != '" . (int)$HTTP_GET_VARS['itID'] . "'");
			if (tep_db_num_rows($check_email)) {
				$error = true;
				$entry_email_address_exists = true;
			} else {
				$entry_email_address_exists = false;
			}
										$sql_data_array = array(
										'service_firstname' => $service_firstname,
										'service_lastname' => $service_lastname,
										'service_email_address' =>$service_email_address,
										'service_street_address'=>$service_street_address,
										'service_suburb'=>$service_suburb,
										'service_city'=>$service_city,
										'service_state'=>$service_state,
										'service_country'=>$service_country,
										'service_postcode'=>$service_postcode,
										'service_telephone'=>$service_telephone,
										'service_fax' => $service_fax);
			tep_db_perform(TABLE_SERVICES_PROVIDERS, $sql_data_array, 'insert');
					$provider_id = tep_db_insert_id();
				
			tep_redirect(tep_href_link(FILENAME_SERVICES_PROVIDERS,'itID=' . $provider_id));*/


	case 'deleteconfirm':
		$provider_id = tep_db_prepare_input($HTTP_GET_VARS['itID']);
		
		tep_db_query("delete from " . TABLE_SERVICES_PROVIDERS . " where provider_id = '" . (int)$provider_id . "'");
		
		tep_redirect(tep_href_link(FILENAME_SERVICES_PROVIDERS, tep_get_all_get_params(array('itID', 'action'))));
		break;
	case 'edit':
		$service_query = tep_db_query("select i.provider_id, i.provider_firstname, i.provider_lastname, i.provider_email_address, i.provider_street_address, i.provider_suburb, i.provider_postcode, i.provider_city, i.provider_state, i.provider_country,i.provider_telephone, i.provider_fax " .
								  " from " . TABLE_SERVICES_PROVIDERS . " i  where i.provider_id = '" . (int)$HTTP_GET_VARS['itID'] . "'" . "");
		$service = tep_db_fetch_array($service_query);
		if (!is_array($service)) $service=array();
		$itInfo = new objectInfo($service);
		
	}
}
?>
<!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>
<?php
  if ($action == 'edit' || $action == 'update' || $action=='new') {
?>
<script language="javascript"><!--

function check_form() {
  var error = 0;
  var error_message = "<?php echo JS_ERROR; ?>";

  var provider_firstname = document.service.provider_firstname.value;
  var provider_lastname = document.service.provider_lastname.value;
  var provider_email_address = document.service.provider_email_address.value;
  var provider_street_address = document.service.provider_street_address.value;
  var provider_postcode = document.service.provider_postcode.value;
  var provider_city = document.service.provider_city.value;
  var provider_telephone = document.service.provider_telephone.value;

  
  if (provider_firstname == "" || provider_firstname.length < <?php echo ENTRY_FIRST_NAME_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_FIRST_NAME; ?>";
    error = 1;
  }

  if (provider_lastname == "" || provider_lastname.length < <?php echo ENTRY_LAST_NAME_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_LAST_NAME; ?>";
    error = 1;
  }

 if (provider_email_address == "" || provider_email_address.length < <?php echo ENTRY_EMAIL_ADDRESS_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_EMAIL_ADDRESS; ?>";
    error = 1;
  }

  if (provider_street_address == "" || provider_street_address.length < <?php echo ENTRY_STREET_ADDRESS_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_ADDRESS; ?>";
    error = 1;
  }
  
   if (provider_postcode == "" || provider_postcode.length < <?php echo ENTRY_POSTCODE_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_POST_CODE; ?>";
    error = 1;
  }
  
  
  if(isNaN(provider_postcode))	{
	error_message = error_message+"<?php echo TEXT_ERR_POSTCODE;?>\n";
	error=1;
	}
  
   		

  if (provider_city == "" || provider_city.length < <?php echo ENTRY_CITY_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_CITY; ?>";
    error = 1;
  }
  if (document.service.elements['provider_state'].type != "hidden") {
    if (document.service.provider_state.value == '' || document.service.provider_state.value.length < <?php echo ENTRY_STATE_MIN_LENGTH; ?> ) {
       error_message = error_message + "<?php echo JS_STATE; ?>";
       error = 1;
    }
  }

  if (document.service.elements['provider_country'].type != "hidden") {
    if (document.service.provider_country.value == 0) {
      error_message = error_message + "<?php echo JS_COUNTRY; ?>";
      error = 1;
    }
  }
  
  if(isNaN(provider_telephone)){
	error_message = error_message+"<?php echo TEXT_ERR_TELEPHONE?>\n";
	error=1;
	}
  	
  if ( provider_telephone == "" || provider_telephone.length < <?php echo ENTRY_TELEPHONE_MIN_LENGTH; ?>) {
    error_message = error_message + "<?php echo JS_TELEPHONE; ?>";
    error = 1;
  }

  if (error == 1) {
    alert(error_message);
    return false;
  } else {
    return true;
  }
}
//--></script>
<?php
  }
?>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
	<tr>
	<!-- body_text //-->
	<td width="100%" valign="top">
	<table border="0" width="100%" cellspacing="0" cellpadding="2">
	<?php
		if ($action == 'edit' || $action == 'update' || $action=='new') {
			$action = (isset($HTTP_GET_VARS['itID']) ? "update" : "insert");
			$is_read_only=false;	
	?>
		<tr>
			<td>
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
				<td class="pageHeading"><?php echo HEADING_TITLE; ?></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('service', FILENAME_SERVICES_PROVIDERS, tep_get_all_get_params(array('action')) . 'action='.$action, 'post', 'onSubmit="return check_form();"'); 
		
			?>
			
			<td class="formAreaTitle"><?php echo CATEGORY_PERSONAL; ?></td>
		</tr>
		<tr>
			<td class="formArea">
			<table border="0" cellspacing="2" cellpadding="2">
				
          <tr>
            <td class="main"><?php echo TEXT_FIRSTNAME; ?></td>
            <td class="main">
<?php
  if ($is_read_only){
  	echo $itInfo->provider_firstname;
  } else if ($error == true) {
    if ($entry_firstname_error == true) {
      echo tep_draw_input_field('provider_firstname', $itInfo->provider_firstname, 'maxlength="32" size="32"') . '&nbsp;' . ENTRY_FIRST_NAME_ERROR;
    } else {
      echo $itInfo->provider_firstname . tep_draw_hidden_field('provider_firstname');
    }
  } else {
    echo tep_draw_input_field('provider_firstname', $itInfo->provider_firstname, 'maxlength="32" size="32"', true);
  }
?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_LASTNAME; ?></td>
            <td class="main">
<?php
  if ($is_read_only){
  	echo $itInfo->provider_lastname;
  } else if ($error == true) {
    if ($entry_lastname_error == true) {
      echo tep_draw_input_field('provider_lastname', $itInfo->provider_lastname, 'maxlength="32" size="32"') . '&nbsp;' . ENTRY_LAST_NAME_ERROR;
    } else {
      echo $itInfo->provider_lastname . tep_draw_hidden_field('provider_lastname');
    }
  } else {
    echo tep_draw_input_field('provider_lastname', $itInfo->provider_lastname, 'maxlength="32" size="32"', true);
  }
?></td>
          </tr>
		   <tr>
            <td class="main"><?php echo TEXT_EMAIL_ADDRESS; ?></td>
            <td class="main">
<?php
  if ($is_read_only){
  	echo $itInfo->provider_email_address;
  } else if ($error == true) {
    if ($entry_email_address_error == true) {
      echo tep_draw_input_field('provider_email_address', $itInfo->provider_email_address, 'maxlength="96" size="32"') . '&nbsp;' . ENTRY_EMAIL_ADDRESS_ERROR;
    } elseif ($entry_email_address_check_error == true) {
      echo tep_draw_input_field('provider_email_address', $itInfo->provider_email_address, 'maxlength="96" size="32"') . '&nbsp;' . ENTRY_EMAIL_ADDRESS_CHECK_ERROR;
    } elseif ($entry_email_address_exists == true) {
      echo tep_draw_input_field('provider_email_address', $itInfo->provider_email_address, 'maxlength="96" size="32"') . '&nbsp;' . ENTRY_EMAIL_ADDRESS_ERROR_EXISTS;
    } else {
      echo $provider_email_address . tep_draw_hidden_field('provider_email_address');
    }
  } else {
    echo tep_draw_input_field('provider_email_address', $itInfo->provider_email_address, 'maxlength="96" size="32"', true);
  }
?></td>
          </tr>
         
          </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="formAreaTitle"><?php echo TEXT_CATEGORY_ADDRESS; ?></td>
      </tr>
      <tr>
        <td class="formArea"><table border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td class="main"><?php echo TEXT_STREET_ADDRESS; ?></td>
            <td class="main">
<?php
  if ($is_read_only){
  	echo $itInfo->provider_street_address;
  } else if ($error == true) {
    if ($provider_street_address_error == true) {
      echo tep_draw_input_field('provider_street_address', $itInfo->provider_street_address, 'maxlength="64" size=64') . '&nbsp;' . ENTRY_STREET_ADDRESS_ERROR;
    } else {
      echo $itInfo->provider_street_address . tep_draw_hidden_field('provider_street_address');
    }
  } else {
    echo tep_draw_input_field('provider_street_address', $itInfo->provider_street_address, 'maxlength="64" size=64', true);
  }
?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_SUBURB; ?></td>
            <td class="main">
<?php
	if ($is_read_only){
		echo $itInfo->provider_suburb;
    } else if ($error == true) {
      if ($entry_suburb_error == true) {
        echo tep_draw_input_field('provider_suburb', $itInfo->provider_suburb, 'maxlength="32"') . '&nbsp;' . ENTRY_SUBURB_ERROR;
      } else {
        echo $itInfo->provider_suburb . tep_draw_hidden_field('provider_suburb');
      }
    } else {
      echo tep_draw_input_field('provider_suburb', $itInfo->provider_suburb, 'maxlength="32"');
    }
?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_POST_CODE; ?></td>
            <td class="main">
<?php
  if ($is_read_only){
  	echo $itInfo->provider_postcode;
  } else if ($error == true) {
    if ($entry_postcode_error == true) {
      echo tep_draw_input_field('provider_postcode', $itInfo->provider_postcode, 'maxlength="8"') . '&nbsp;' . ENTRY_POSTCODE_ERROR;
    } else {
      echo $itInfo->provider_postcode . tep_draw_hidden_field('provider_postcode');
    }
  } else {
    echo tep_draw_input_field('provider_postcode', $itInfo->provider_postcode, 'maxlength="8"', true);
  }
?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_CITY; ?></td>
            <td class="main">
<?php
  if ($is_read_only){
  	echo $itInfo->provider_city;
  } else if ($error == true) {
    if ($entry_city_error == true) {
      echo tep_draw_input_field('provider_city', $itInfo->provider_city, 'maxlength="32"') . '&nbsp;' . ENTRY_CITY_ERROR;
    } else {
      echo $itInfo->provider_city . tep_draw_hidden_field('provider_city');
    }
  } else {
    echo tep_draw_input_field('provider_city', $itInfo->provider_city, 'maxlength="32"', true);
  }
?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_STATE; ?></td>
            <td class="main">
<?php

   $providers_state = $itInfo->provider_state;
	if ($is_read_only){
		echo $itInfo->provider_state;;
    } else if ($error == true) {
      if ($entry_state_error == true) {
       /*  if ($entry_state_has_zones == true) {
         $zones_array = array();
          $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . tep_db_input($itInfo->provider_country) . "' order by zone_name");
          while ($zones_values = tep_db_fetch_array($zones_query)) {
            $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
          } 
          echo tep_draw_pull_down_menu('provider_state', $zones_array) . '&nbsp;' . ENTRY_STATE_ERROR;
        } else { */
          echo tep_draw_input_field('provider_state',  $itInfo->provider_state) . '&nbsp;' . ENTRY_STATE_ERROR;
        //}
      } else {
        echo $provider_state . tep_draw_hidden_field('provider_state');
      }
    } else {
      echo tep_draw_input_field('provider_state', $itInfo->provider_state,'',true);
    }

?></td>
         </tr>
          <tr>
            <td class="main"><?php echo TEXT_COUNTRY; ?></td>
            <td class="main">
<?php
  if ($is_read_only){
  	echo $itInfo->provider_country;
  } else if ($error == true) {
    if ($entry_country_error == true) {
      echo tep_draw_pull_down_menu('provider_country', tep_get_countries(), $itInfo->provider_country) . '&nbsp;' . ENTRY_COUNTRY_ERROR;
    } else {
      echo tep_get_country_name($itInfo->provider_country) . tep_draw_hidden_field('provider_country');
    }
  } else {
    echo tep_draw_pull_down_menu('provider_country', tep_get_countries(), $itInfo->provider_country);
  }
?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="formAreaTitle"><?php echo TEXT_CATEGORY_CONTACT; ?></td>
      </tr>
      <tr>
        <td class="formArea"><table border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td class="main"><?php echo TEXT_TELEPHONE; ?></td>
            <td class="main">
<?php
  if ($is_read_only){
  	echo $itInfo->provider_telephone;	
  } else if ($error == true) {
    if ($provider_telephone_error == true) {
      echo tep_draw_input_field('provider_telephone', $itInfo->provider_telephone, 'maxlength="32"') . '&nbsp;' . ENTRY_TELEPHONE_NUMBER_ERROR;
    } else {
      echo $itInfo->provider_telephone . tep_draw_hidden_field('provider_telephone');
    }
  } else {
    echo tep_draw_input_field('provider_telephone', $itInfo->provider_telephone, 'maxlength="32"', true);
  }
?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_MOBILE_NUMBER; ?></td>
            <td class="main">
<?php
  if ($is_read_only){
  	echo $itInfo->provider_fax;
  } else if ($processed == true) {
    echo $itInfo->provider_fax . tep_draw_hidden_field('provider_fax');
	
  } else {
    echo tep_draw_input_field('provider_fax', $itInfo->provider_fax, 'maxlength="32"');
  }
 
?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
     
			
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
	  
        <td align="right" class="main"><?php 
		echo tep_image_submit('button_update.gif', IMAGE_UPDATE);//update
											  echo ' <a href="' . tep_href_link(FILENAME_SERVICES_PROVIDERS) .'">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; 
										?></td>
										
										
      </tr></form>
<?php
  } else {
?>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr><?php echo tep_draw_form('search', FILENAME_SERVICES_PROVIDERS, '', 'get'); ?>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>
            <td class="smallText" align="right"><?php if ($login_groups_name==TEXT_ADMINISTRATOR_ENTRY) echo HEADING_TITLE_SEARCH . ' ' . tep_draw_input_field('search'); ?></td>
          </form></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_NAME; ?></td>
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_EMAIL; ?></td>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
              </tr>
<?php
    $search = '';
    if (isset($HTTP_GET_VARS['search']) && tep_not_null($HTTP_GET_VARS['search'])) {
      $keywords = tep_db_input(tep_db_prepare_input($HTTP_GET_VARS['search']));
      $search = " and (a.provider_lastname like '%" . $keywords . "%' or a.provider_firstname like '%" . $keywords . "%' or a.provider_email_address like '%" . $keywords . "%')";
    }
  	
    $service_query_raw = "select a.provider_id, a.provider_lastname, a.provider_firstname, a.provider_email_address from " . TABLE_SERVICES_PROVIDERS . " a "   . $search  . " order by a.provider_firstname,a.provider_lastname";
    $service_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $service_query_raw, $service_query_numrows);
    $service_query = tep_db_query($service_query_raw);
	$it_total=0;
    while ($service = tep_db_fetch_array($service_query)) {
      $it_total++;
      if ((!isset($HTTP_GET_VARS['itID']) || (isset($HTTP_GET_VARS['itID']) && ($HTTP_GET_VARS['itID'] == $service['provider_id']))) && !isset($itInfo)) {
        $itInfo = new objectInfo($service);
      }

      if (isset($itInfo) && is_object($itInfo) && ($service['provider_id'] == $itInfo->provider_id)) {
        echo '          <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_SERVICES_PROVIDERS, tep_get_all_get_params(array('itID', 'action')) . 'itID=' . $itInfo->provider_id . '&action=edit') . '\'">' . "\n";
      } else {
        echo '          <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_SERVICES_PROVIDERS, tep_get_all_get_params(array('itID')) . 'itID=' . $service['provider_id']) . '\'">' . "\n";
      }
?>
                <td class="dataTableContent"><?php echo $service['provider_firstname']; ?>&nbsp;<?php echo $service['provider_lastname']; ?></td>
                <td class="dataTableContent"><?php echo $service['provider_email_address']; ?></td>
                <td class="dataTableContent" align="right"><?php if (isset($itInfo) && is_object($itInfo) && ($service['provider_id'] == $itInfo->provider_id)) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_SERVICES_PROVIDERS, tep_get_all_get_params(array('itID')) . 'itID=' . $service['provider_id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?>&nbsp;</td>
              </tr>
<?php
    }
?>
              
	        <tr><td><?php echo tep_draw_separator('pixel_trans.gif',5,10); ?></td></tr>
                <tr><td colspan="4"><table border="0" width="100%" cellspacing="0" cellpadding="2">
                  <tr>
                    <td class="smallText" valign="top"><?php echo $service_split->display_count($service_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $HTTP_GET_VARS['page'], TEXT_DISPLAY_NUMBER_OF_PROVIDERS); ?></td>
                    <td class="smallText" align="right"><?php echo $service_split->display_links($service_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $HTTP_GET_VARS['page'], tep_get_all_get_params(array('page', 'info', 'x', 'y', 'itID'))); ?></td>
                  </tr>
		  <tr><td><?php echo tep_draw_separator('pixel_trans.gif',5,10); ?></td></tr>
		  <tr><td align="right" colspan="2">
                  <?php 
                     if (isset($HTTP_GET_VARS['search']) && tep_not_null($HTTP_GET_VARS['search'])) {
                          echo '<a href="' . tep_href_link(FILENAME_SERVICES_PROVIDERS) . '">' . tep_image_button('button_reset.gif', IMAGE_RESET) . '</a>';}
		     else {
		                      echo '<a href="' . tep_href_link(FILENAME_SERVICES_PROVIDERS,'action=new') .'">' . tep_image_button('button_new.gif', IMAGE_NEW) . '</a>';
	            }
	          ?></td>
                  </tr>
                </table></td>
              </tr>
            </table></td>
<?php
  $heading = array();
  $contents = array();

  switch ($action) {
  case 'new_member': 
     		 $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_NEW . '</b>');
     		 
     		    $contents = array('form' => tep_draw_form('service', FILENAME_SERVICES_PROVIDERS, 'action=member_new', 'post', 'enctype="multipart/form-data"')); 
   		        $contents = array('form' => tep_draw_form('service', FILENAME_SERVICES_PROVIDERS, 'action=member_new&page=' . $page , 'post', 'enctype="multipart/form-data"')); 
				
				if ($HTTP_GET_VARS['error']) {
        $contents[] = array('text' => TEXT_INFO_ERROR); 
      }
      $contents[] = array('text' => '<br>&nbsp;' . TEXT_FIRSTNAME . '<br>&nbsp;' . tep_draw_input_field('provider_firstname')); 
      $contents[] = array('text' => '<br>&nbsp;' . TEXT_LASTNAME . '<br>&nbsp;' . tep_draw_input_field('provider_lastname'));
      $contents[] = array('text' => '<br>&nbsp;' . TEXT_EMAIL_ADDRESS . '<br>&nbsp;' . tep_draw_input_field('provider_email_address')); 
	  $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_insert.gif', IMAGE_INSERT) . ' <a href="' . tep_href_link(FILENAME_SERVICES_PROVIDERS, 'action=insert&'  ) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
	  break;
	 
    case 'confirm':
      $heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_PROVIDER . '</b>');

      $contents = array('form' => tep_draw_form('service', FILENAME_SERVICES_PROVIDERS, tep_get_all_get_params(array('itID', 'action')) . 'itID=' . $itInfo->provider_id . '&action=deleteconfirm'));
      $contents[] = array('text' => TEXT_DELETE_INTRO . '<br><br><b>' . $itInfo->provider_firstname . ' ' . $itInfo->provider_lastname . '</b>');
      $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_delete.gif', IMAGE_DELETE) . ' <a href="' . tep_href_link(FILENAME_SERVICES_PROVIDERS, tep_get_all_get_params(array('itID', 'action')) . 'itID=' . $itInfo->provider_id) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
      break;
    default:
      if (isset($itInfo) && is_object($itInfo)) {
        $heading[] = array('text' => '<b>' . $itInfo->provider_firstname . ' ' . $itInfo->provider_lastname . '</b>');
	$display_text='<a href="' . tep_href_link(FILENAME_SERVICES_PROVIDERS, tep_get_all_get_params(array('itID', 'action')) . 'itID=' . $itInfo->provider_id . '&action=edit') . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a>';
    
           $display_text.='&nbsp;' . '<a href="' . tep_href_link(FILENAME_SERVICES_PROVIDERS, tep_get_all_get_params(array('itID', 'action')) . 'itID=' . $itInfo->provider_id . '&action=confirm') . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a>';
        $contents[]=array('align'=>center,'text'=>$display_text);
      }
      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>
<?php
  }
?>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

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

