<?php
	
	if(key_exists('action', $_GET) && $_GET['action']<>'') $action = $_GET['action'];
	else $action = '';
	
	if($action=='update')
	{
		$avatar = '';
		$add_avatar = false;
		$file_tmp = $_FILES['avatar']['tmp_name'];
		$file = $_FILES['avatar']['name'];
		if(file_exists($file_tmp) && $file!='')
		{
			list($width, $height, $type, $attr) = getimagesize($file_tmp);
			$type = $_FILES['avatar']['type'];
			$size = round(filesize($file_tmp)/1024,2);
			$image_types = array('image/jpeg', 'image/pjpg', 'image/pjpeg');
			if($width>0 && $width<=100 && $height>0 && $height<=100  && in_array($type, $image_types) && $size<=15)
			{
				$avatar = substr(md5($_FILES['avatar']['name'].time()), 0, 12).'.jpg';
				$uploaddir = "/home/clients/peterpech.com/peterpech.com/4mobile/images/users/";
				$uploadfile = $uploaddir.$avatar;
				$check = move_uploaded_file($file_tmp, $uploadfile);
				if($check)
				{
					$register_error2 = 'Obrázok úspešne uložený';
					$_SESSION['avatar'] = $avatar;
					$add_avatar = true;
				}
				else $register_error2 = 'Chyba pri ukladaní obrázku';
			}
		}
			
			
		$register_error = '';
		if(key_exists('page_pozadia', $_POST) && key_exists('page_melody', $_POST) && key_exists('page_hry', $_POST) && key_exists('page_posta', $_POST) && key_exists('page_users', $_POST) && key_exists('page_video', $_POST) && key_exists('moj_mobil', $_POST))
		{
			if($_POST['page_pozadia']>0 && $_POST['page_pozadia']<=30 && $_POST['page_pozadia']<>'') $page_pozadia = $_POST['page_pozadia'];
			else $register_error .= 'Neplatná hodnota pre výpis pozadí!<br />';
			
			if($_POST['page_melody']>0 && $_POST['page_melody']<=50 && $_POST['page_melody']<>'') $page_melody = $_POST['page_melody'];
			else $register_error .= 'Neplatná hodnota pre výpis melódií!<br />';
			
			if($_POST['page_hry']>0 && $_POST['page_hry']<=30 && $_POST['page_hry']<>'') $page_hry = $_POST['page_hry'];
			else $register_error .= 'Neplatná hodnota pre výpis hier!<br />';
			
			if($_POST['page_posta']>0 && $_POST['page_posta']<=100 && $_POST['page_posta']<>'') $page_posta = $_POST['page_posta'];
			else $register_error .= 'Neplatná hodnota pre výpis správ!<br />';
			
			if($_POST['page_users']>0 && $_POST['page_users']<=100 && $_POST['page_users']<>'') $page_users = $_POST['page_users'];
			else $register_error .= 'Neplatná hodnota pre výpis používateľov!<br />';
			
			if($_POST['page_video']>0 && $_POST['page_video']<=30 && $_POST['page_video']<>'') $page_video = $_POST['page_video'];
			else $register_error .= 'Neplatná hodnota pre výpis videí!<br />';
			
			if($_POST['moj_mobil']>0) $moj_mobil = $_POST['moj_mobil'];
			else $register_error .= 'Nevybrali ste si Váš mobil!<br />';
		}
		else
		{
			$register_error = 'Nesprávne odoslaný formulár!<br />';
		}
		
		$mail = $_POST['mail'];
		//mail check
		$mail_check = ($mail != '');
		
		if($mail_check)
		{
			$query = "SELECT * FROM mobile_users WHERE mail LIKE '$mail' AND ID != '".$_SESSION['my_id']."'";
			$num = $dba->GetNums($query);
			$mail_check = ($num == 0);
		}
		if(!$mail_check)
		{
			$register_error = 'Zadaný email už používa iné konto! Zadajto prosím iný!';
		}
		
		if($register_error=='')
		{
			$mail = addslashes(htmlspecialchars($_POST['mail']));
			$mesto = addslashes(htmlspecialchars($_POST['mesto']));
			$icq = $_POST['icq'];
			$icq = str_replace('-', '', $icq);
			if($icq<100000000 || $icq >999999999) $icq = '';
			$msn = addslashes(htmlspecialchars($_POST['msn']));
			$gender = $_POST['gender'];
			if(key_exists('mlist', $_POST)) $mlist = $_POST['mlist']; else $mlist = 0;
			$moj_mobil = $_POST['moj_mobil'];
			$query="UPDATE mobile_users SET 
						mail='$mail', 
						gender=$gender, 
						news=$mlist, 
						page_pozadia=$page_pozadia, 
						page_melody=$page_melody, 
						page_hry=$page_hry, 
						page_posta=$page_posta, 
						page_users=$page_users, 
						page_video=$page_video, 
						moj_mobil=$moj_mobil, 
						mesto='$mesto', 
						icq='$icq', 
						msn='$msn'";
			if($add_avatar) $query.= ", avatar='$avatar' ";
			$query .="
					WHERE ID='".$_SESSION["my_id"]."'";
			$dba->ExecuteQuery($query);
			$register_error = 'Nastavenia boli úspešne uložené!';
			$_SESSION['mobile_page_pozadia'] = $page_pozadia;
			$_SESSION['mobile_page_melody'] = $page_melody;
			$_SESSION['mobile_page_hry'] = $page_hry;
			$_SESSION['mobile_page_posta'] = $page_posta;
			$_SESSION['mobile_page_users'] = $page_users;
			$_SESSION['mobile_page_video'] = $page_video;
		}
	}
 
	$edit_setings = true;
	
	require_once('modules/register_form.php');
	$query = "SELECT page_pozadia, page_melody, page_hry, page_users, page_posta, page_video
			  FROM mobile_users WHERE ID=".$_SESSION['my_id']." limit 0, 1";
	$result = $dba->GetResult($query);
	if($result)
	{
		$row = mysql_fetch_array($result);
		$page_pozadia = $row['page_pozadia'];
		$page_melody = $row['page_melody'];
		$page_hry = $row['page_hry'];
		$page_users = $row['page_users'];
		$page_posta = $row['page_posta'];
		$page_video = $row['page_video'];
	}
	else 
	{
		$page_pozadia = 0;
		$page_melody = 0;
		$page_hry = 0;
		$page_users = 0;
		$page_posta = 0;
		$page_video = 0;
	}
?>
<!--		<table width="80%" border='1' align="center">-->
		<tr><td width='40%' align='right'>Počet pozadí na jednej strane:</td><td align="left"> <input id="form_field02" type="text" name="page_pozadia" size="2" maxlength="2" value="<?php echo $page_pozadia; ?>"> (max 30)</td></tr>
		<tr><td align='right'>Počet melódií na jednej strane:</td><td align="left"> <input id="form_field02" type="text" name="page_melody" size="2" maxlength="2" value="<?php echo $page_melody; ?>"> (max 50)</td></tr>
		<tr><td align='right'>Počet hier na jednej strane:</td><td align="left"> <input id="form_field02" type="text" name="page_hry" size="2" maxlength="2" value="<?php echo $page_hry; ?>"> (max 30)</td></tr>
		<?php 
//			dump(round(fnExec_time() - $start_time, 5)); 
		
			echo '<tr><td align=\'right\'>Počet správ na jednej strane:</td><td align="left"> <input id="form_field02" type="text" name="page_posta" size="2" maxlength="2" value="'.$page_posta.'"></td></tr>';
//			dump(round(fnExec_time() - $start_time, 5)); 
			
		?>
		<tr><td align='right'>Počet užívateľov na jednej strane: </td><td align="left"><input id="form_field02" type="text" name="page_users" size="2" maxlength="2" value="<?php echo $page_users; ?>"></td></tr>
		<tr><td align='right'>Počet videí na jednej strane:</td><td align="left"> <input id="form_field02" type="text" name="page_video" size="2" maxlength="2" value="<?php echo $page_video; ?>"> (max 30)</td></tr>
		<tr><td colspan="2">
		<div id="form_popis02"><input id="form_button01" type="submit" name="Submit" value="OK">&nbsp;<input id="form_button01" type="reset" name="reset" value="Reset"></div>
	<div id="form_popis02">Pre počet zobrazení na jednej strane sú povolené hodnoty od 1 do 99!</div></td></tr>
	</table><br/>
	<?php 
	
	$avatar = $dba->GetOne('mobile_users', $_SESSION['my_id'], 'avatar');
	
		echo "<div align=\"center\">Váš obrázok:<br/><img src=\"http://4mobile.sk/images/users/".$avatar."\" alt=\"\" align=\"top\"/></div><br/>";
	?>
	</div>
	<div id="melodia_div">
		<span id="red_b">Nastavenia WAP:</span><br />
		<b>Nastavenie pre Orange</b><br />
		Úvodná alebo štartovacia stránka (Home alebo Homepage): http://wap.orange.sk	<br />
		Spôsob spojenia	(Session mode):	permanentné	<br />
		Ochrana spojenia (Connection security):	vypnutá	<br />
		Typ prenosu dát alebo typ volania (Data Call type alebo Call type):	ISDN<br />	
		Nosič (Bearer):	GSM data<br />	
		IP adresa (IP address):	195.012.140.145<br />	
		Číslo spojenia (Dial up number): +421905927927<br />
		Meno užívateľa (User name):	wap<br />	
		Heslo (Password): wap<br />	
		Typ autentifikácie (Authentication type): normálny<br />	
		Typ loginu (Login type): automatický<br />	
		Port číslo (vyžadujú niektoré typy mobilných telefónov)	9201<br /><br />
			
		Podrobný postup nastavenia pre každý telefón nájdete <a href="http://www.orangeportal.sk/mojmobil/mywap/mywap.dwp?tmpl=myWAPTel" target="_blank" id="menu01_link"><b>TU</b></a><br /><br />
		
		<b>Nastavenie pre T-Mobile Slovensko</b><br />
		Úvodná alebo štartovacia stránka (Home alebo Homepage):	http://wap.eurotel.sk<br />	
		Spôsob spojenia (Session mode):	priebežné<br />	
		Ochrana spojenia (Connection security):	vypnutá<br />	
		Typ prenosu dát alebo typ volania (Data Call type alebo Call type):	ISDN<br />	
		Nosič (Bearer):	GSM data<br />	
		IP adresa (IP address):	192.168.001.001<br />	
		Číslo spojenia (Dial up number): +421903499099<br />	
		Meno užívateľa (User name): eurotel<br />	
		Heslo (Password): wap<br />	
		Typ autentifikácie (Authentication type): normálny<br />	
		Typ loginu (Login type): automatický<br /><br />	
		
		Podrobný postup nastavenia pre každý telefón nájdete <a href="http://www.t-mobile.sk/sk/!pages.get?id=1604" target="_blank" id="menu01_link"><b>TU</b></a>
	</div>

	</form>
	