<?php
session_start();
if (!isset($_SESSION['language'])){
	$language_data=mysql_fetch_assoc(mysql_query("Select * from languages order by id asc limit 1"));
	$_SESSION['language']=$language_data['id'];
	$language=$language_data['id'];
}else{
	$c_l=mysql_num_rows(mysql_query("Select * from languages where id='".$_SESSION['language']."'"));
	if ($c_l==0){
		$language_data=mysql_fetch_assoc(mysql_query("Select * from languages order by id asc limit 1"));
		$_SESSION['language']=$language_data['id'];
		$language=$language_data['id'];
	}else{
		$language=$_SESSION['language'];
	}
}


?>
<? $settings=mysql_fetch_assoc(mysql_query("Select * from settings where id=1"))?>
<? function get_pages_bread($recordid){
	$data=mysql_fetch_assoc(mysql_query("Select * from pages where id='".addslashes($recordid)."'"));
	$data_l=mysql_fetch_assoc(mysql_query("Select * from l_pages where page='".addslashes($recordid)."' and language='".$_SESSION['language']."'"));
	$parent='';
	if ($data['parent']!='0'){
	$parents=explode(",",$data['parents']);
	$size=sizeof($parents);
	for ($i=1; $i<$size; $i++){
		$result=mysql_fetch_assoc(mysql_query("Select * from pages where id='".addslashes($parents[$i])."'"));
		$result_l=mysql_fetch_assoc(mysql_query("Select * from l_pages where page='".addslashes($parents[$i])."' and language='".$_SESSION['language']."'"));
		$parent= $parent.' <li><a href="'.stripslashes($result_l['link']).'" >'.stripslashes($result_l['title']).'</a></li>';
	}
	}
	return $parent.'<li class="active">'.stripslashes($data_l['title']).'</li>' ;
}?>


<? function get_categories_bread($recordid){
	$data=mysql_fetch_assoc(mysql_query("Select * from categories where id='".addslashes($recordid)."'"));
	$data_l=mysql_fetch_assoc(mysql_query("Select * from l_categories where category='".addslashes($recordid)."' and language='".$_SESSION['language']."'"));
	$parent='';
	if ($data['parent']!='0'){
	$parents=explode(",",$data['parents']);
	$size=sizeof($parents);
	for ($i=1; $i<$size; $i++){
		$result=mysql_fetch_assoc(mysql_query("Select * from categories where id='".addslashes($parents[$i])."'"));
		$result_l=mysql_fetch_assoc(mysql_query("Select * from l_categories where category='".addslashes($parents[$i])."'  and language='".$_SESSION['language']."'"));
		$parent= $parent.' / <span class="color_light">'.stripslashes($result_l['title']).'</span>';
	}
	}
	return $parent.' / <span class="color_light">'.stripslashes($data_l['title']).'</span>' ;
}?>





<? 
if ($_POST['islem']=='dil_degistir'){
$_SESSION['language']=$_POST['dil'];
}
?>
<? function turkce_link($link){
	$link=strtolower(turkcekarakter(strip_tags(stripslashes($link))));
	return $link;
}?>


<? function imgtoclor($content){
	/* $content=preg_replace('#(<img[^>]+>)#', '<a class="group1" href="sdfsdf" >$1</a>', $content);
	$content=preg_replace('#<a class="group1" [^>]+><img[^>]+ src="([^"]*)" [^>]+></a>#', '<a class="group1" href="$1" [^>]+><img[^>]+></a>', $content);
*/
	$content=preg_replace('#(<img[^>]+src="([^"]*)"[^>]+>)#', '<a class="group1 colorbox_gallery" href="$2">$1</a>', $content);
	return($content);
}?>


<? 

$tarihgoster = array(
'January' => 'Ocak',
'February' => 'Şubat',
'March' => 'Mart',
'April' => 'Nisan',
'May' => 'Mayıs',
'June' => 'Haziran',
'July' => 'Temmuz',
'August' => 'Ağustos',
'September' => 'Eylül',
'October' => 'Ekim',
'November' => 'Kasım',
'December' => 'Aralık',
'Monday' => 'Pazartesi',
'Tuesday' => 'Salı',
'Wednesday' => 'Çarşamba',
'Thursday' => 'Perşembe',
'Friday' => 'Cuma',
'Saturday' => 'Cumartesi',
'Sunday' => 'Pazar'
);
$gunler=array('Pazartesi','Salı','Çarşamba','Perşembe','Cuma','Cumartesi','Pazar');


function randMixedName($prefix, $chr_length, $query_param = array()){
	$chars = array(
		'a','A', 
		'b','B', 
		'0',
		'c','C',
		'd','D',
		'1',
		'e','E',
		'f','F',
		'2',
		'g','G',
		'h','H',
		'3',													
		'i','I',
		'j','J',
		'4',
		'k','K',
		'l','L',
		'5',
		'm','M',
		'n','N',
		'6',
		'o','O',
		'p','P',
		'7',
		'r','R',
		's','S',
		'8',
		't','T',
		'u','U',
		'v','V',
		'w','W',
		'9',
		'x','X',
		'y','Y',
		'z','Z'
		);

	$result = '';
	for ( $i = 0 ; $i < $chr_length ; $i++ ){
		$rand = rand(0, 60);
		$result .= $chars[$rand];
	}
	
	if ( count($query_param) == 2 ){
		$name = mysql_num_rows(mysql_query("SELECT ".$query_param[1]." FROM ".$query_param[0]." WHERE ticket_key = '".$result."'"));
		if ( $name[$query_param[1]] > 0 )
		randMixedName($prefix, $chr_length, $query_param);
	}
	return $result;
}

function randMixedNumeric($prefix, $chr_length, $query_param = array()){
			
	$chars = array(
									'0',
									'1',
									'2',
									'3',													
									'4',
									'5',
									'6',
									'7',
									'8',
									'9'
									);

	$result = '';
	for ( $i = 0 ; $i < $chr_length ; $i++ ){
		
		$rand = rand(0, 9);
		$result .= $chars[$rand];

	}
	
	if ( count($query_param) == 2 ){
		$name = mysql_num_rows(mysql_query("SELECT ".$query_param[1]." FROM ".$query_param[0]." WHERE ticket_key = '".$result."'"));
		if ( $name[$query_param[1]] > 0 )
		randMixedNumeric($prefix, $chr_length, $query_param);
	}
	
	 return $result;
	
}
	
	
function sendPhpMailer( $subject, $email, $message, $body_type ){

//"Labx Başvurunuz Hakkında"
require_once("mail/class.phpmailer.php");


	$mail = new PHPMailer();
	$mail->IsSMTP();
	$mail->SMTPAuth = true;
	$mail->IsHTML(1);
			
	$mail->Host = 'mail.lab-x.org';
	$mail->Port = '25';  
	$mail->Username = 'bilgi@lab-x.org';
	$mail->Password = 'helix06';
	$mail->From = 'bilgi@lab-x.org';
	
	$mail->CharSet="UTF-8";
	$mail->FromName = 'LabX Girişimci';
	$mail->AddAddress('contact@mustafabalakar.com','Biz Sizi Arayalım');
	$mail->Subject = 'Biz Sizi Arayalım';
	
	$mail->Body=$message;
	if(!$mail->Send())
	{
			echo $mail->ErrorInfo.$message;
			
		$_SESSION['error']=$mail->ErrorInfo .$message;
	   exit;
	}	else{
		echo 'Mail Gönderilmiştir.';
	$_SESSION['error']='Mail Gönderilmiştir.';
	}


}	

?>