<commit_before><?php
/**
 * @author putypuruty
 * 
 * Business logic for editing a post.
 * TODO: refactor code, comments
 */
	
	if ($id != 0)
	{
		$j = new Job($id);
	}
	
	$jobToEdit = $j->GetInfo();
	$smarty->assign_by_ref('job', $jobToEdit);
	
	$smarty->assign('show_preview', false);
	
	if (!empty($_POST))
	{
		// validation
		$errors = array();
		
		if ($_POST['company'] == '')
			$errors['company'] = $translations['jobs']['name_error'];
		
		if ($_POST['title'] == '')
			$errors['title'] = $translations['jobs']['title_error'];
		
		if ($_POST['description'] == '')
			$errors['description'] = $translations['jobs']['description_error'];
		
		if ($_POST['poster_email'] == '')
			$errors['poster_email'] = $translations['jobs']['email_error'];

		$isCitySelected = false;

		if (!isset($_POST['city_id']))
			$city_id = -1;
		else
		{
			$city_id = $_POST['city_id'];
			$isCitySelected = true;
		}
				
		$jobToEdit['company'] = $_POST['company'];
		$jobToEdit['url'] = $_POST['url'];
		$jobToEdit['title'] = $_POST['title'];
		$jobToEdit['city_id'] = $city_id;
		$jobToEdit['location_outside_ro_where'] = ($isCitySelected ? '' : $_POST['location_outside_ro_where']);
		$jobToEdit['category_id'] = $_POST['category_id'];
		$jobToEdit['type_id'] = $_POST['type_id'];
		$jobToEdit['description'] = $_POST['description'];
		$jobToEdit['apply'] = '';
		$jobToEdit['poster_email'] = $_POST['poster_email'];
		$jobToEdit['apply_online'] = $_POST['apply_online'];

		$jobToEdit['textiledDescription'] = $textile->TextileThis($_POST['description']);
		$jobToEdit['location_outside_ro'] = $jobToEdit['location_outside_ro_where'];
		
		if ($isCitySelected)
		{
			$cityName = '';
			
			// TODO: make a getCityByID function
			
			if ($city_id == -1)
				$cityName = 'Anywhere';
			else
			{
				$cities = get_cities();
				
				foreach ($cities as $city)
				{
					if ($city['id'] == $city_id)
					{
						$cityName = $city['name'];
						break;
					}
				}
			}
			
			$jobToEdit['location'] = $cityName;
		}
		else
			$jobToEdit['location'] = $jobToEdit['location_outside_ro'];
			<commit_msg>refactored code to use the get_city_by_id method<commit_after><?php
/**
 * @author putypuruty
 * 
 * Business logic for editing a post.
 */
	
	if ($id != 0)
	{
		$j = new Job($id);
	}
	
	$jobToEdit = $j->GetInfo();
	$smarty->assign_by_ref('job', $jobToEdit);
	
	$smarty->assign('show_preview', false);
	
	if (!empty($_POST))
	{
		// validation
		$errors = array();
		
		if ($_POST['company'] == '')
			$errors['company'] = $translations['jobs']['name_error'];
		
		if ($_POST['title'] == '')
			$errors['title'] = $translations['jobs']['title_error'];
		
		if ($_POST['description'] == '')
			$errors['description'] = $translations['jobs']['description_error'];
		
		if ($_POST['poster_email'] == '')
			$errors['poster_email'] = $translations['jobs']['email_error'];

		$isCitySelected = false;

		// we didn't receive a city (when the cities combo is disabled)
		if (!isset($_POST['city_id']))
			$city_id = -1;
		else
		{
			$city_id = $_POST['city_id'];
			$isCitySelected = true;
		}
				
		$jobToEdit['company'] = $_POST['company'];
		$jobToEdit['url'] = $_POST['url'];
		$jobToEdit['title'] = $_POST['title'];
		$jobToEdit['city_id'] = $city_id;
		$jobToEdit['location_outside_ro_where'] = ($isCitySelected ? '' : $_POST['location_outside_ro_where']);
		$jobToEdit['category_id'] = $_POST['category_id'];
		$jobToEdit['type_id'] = $_POST['type_id'];
		$jobToEdit['description'] = $_POST['description'];
		$jobToEdit['apply'] = '';
		$jobToEdit['poster_email'] = $_POST['poster_email'];
		$jobToEdit['apply_online'] = $_POST['apply_online'];

		$jobToEdit['textiledDescription'] = $textile->TextileThis($_POST['description']);
		$jobToEdit['location_outside_ro'] = $jobToEdit['location_outside_ro_where'];
		
		if ($isCitySelected)
		{
			$city = get_city_by_id($city_id);
			
			$jobToEdit['location'] = $city['name'];
		}
		else
			$jobToEdit['location'] = $jobToEdit['location_outside_ro'];
			
{'fraction_non_alphanumeric': 0.21408943292530602, 'fraction_numerical': 0.0012490632025980515, 'mean_word_length': 4.545706371191136, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7432685', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1405, 'n_words': 219}