<?php 
	
	
	// 
	include_once "phpqrcode/qrlib.php";  
	
	
	// include_once "includes/functions.php";  

	
	//include "includes/configuration.php";  
     		 
		 
		   
	  
	      $text = get_matric_no($p);
		  $text2 = str_replace('/', '-', $text);

	 	  
	  
	
		  
		   //$image = '<img src="admin/pictures/passports/'.$row['image'].'"/>';
		  $fileName = str_replace('/', '-', $text).'.png';
		  //$fileName =  $text.'png';
		   
		   
		   
		   
		   // how to build raw content - QRCode with detailed Business Card (VCard) 
		
			$tempDir = 'codes/'; 
		
			// here our data 
			$name         = strtoupper(get_user_fullname($p)).' N: '.$text; 
			$sortName     = strtoupper(get_user_fullname($p)).' N: '.$text;  //'Doe;John'; 
			$phone        =  get_user_phone_no($p); // '(049)012-345-678'; 
			 // '(049)012-345-678'; 
			//$phonePrivate = $row['mobile_number']; //'(049)012-345-987'; 
			//											 $phoneCell    = '(049)888-123-123'; 
			//$orgName      = 'My Company Inc.'; 
			
			//$avatarJpegFileName = 'NSG-GH-251.jpg';  //$image; // 'avatar.jpg';
		
			$email        = get_user_email($p); //'john.doe@example.com'; 
		
			// if not used - leave blank! 
		 //   $addressLabel     = 'Our Office'; 
		//    $addressPobox     = ''; 
		//    $addressExt       = 'Suite 123'; 
		//    $addressStreet    = '7th Avenue'; 
		//    $addressTown      = 'New York'; 
		//    $addressRegion    = 'NY'; 
		//    $addressPostCode  = '91921-1234'; 
		//    $addressCountry   = 'USA';
		
		    $addressLabel     = 'Address'; 
		    $addressPobox     = ''; 
		    $addressExt       = ''; 
		    $addressStreet    = ''; 
		    $addressTown      = ''; 
		    $addressRegion    = ''; 
		    $addressPostCode  = ''; 
		    $addressCountry   = ''; 
		
		
				
			// we building raw data 
			$codeContents  = 'BEGIN:VCARD'."\n"; 
			$codeContents .= 'VERSION:2.1'."\n"; 
		    $codeContents .= 'N:'.$sortName."\n"; 
			$codeContents .= 'FN:'.$name."\n"; 
			//$codeContents .= 'ORG:'.$orgName."\n"; 
		
			$codeContents .= 'TEL;WORK;VOICE:'.$phone."\n"; 
			//$codeContents .= 'TEL;HOME;VOICE:'.$phonePrivate."\n"; 
			//$codeContents .= 'TEL;TYPE=cell:'.$phoneCell."\n"; 
		
			$codeContents .= 'ADR;TYPE=home;'. 
				'LABEL="'.$addressLabel.'":' 
				.$addressPobox.';' 
		        .$addressExt.';' 
		        .$addressStreet.';' 
		        .$addressTown.';' 
		        .$addressPostCode.';' 
		        .$addressCountry 
			."\n"; 
			
			
			//$codeContents .= 'EMAIL:'.$email."\n"; 
			//$codeContents .= 'PHOTO;JPEG;ENCODING=BASE64:'.base64_encode(file_get_contents($avatarJpegFileName))."\n";
		
			$codeContents .= 'END:VCARD'; 
		
			// generating 
			QRcode::png($codeContents, $tempDir.$fileName, QR_ECLEVEL_L, 1); 
		
			 // displaying 
		     // echo '<img src="'.EXAMPLE_TMP_URLRELPATH.'026.png" />'; 
			 // echo '<img src="'.$tempDir.$fileName.'" />'; // comment the image to be echoed

	
	  
//	  QRcode::png($text); 









//
//// how to save PNG codes to server
//    
//    $tempDir = 'codes/';
//    
//    //$codeContents = str_replace('/','-',$text);
//	$codeContents = $text;
//    
//    // we need to generate filename somehow, 
//    // with md5 or with database ID used to obtains $codeContents...
//	
//	
//    $fileName = 'picx_'.md5($codeContents).'.png';
//    
//    $pngAbsoluteFilePath = $tempDir.$fileName;
//    $urlRelativeFilePath = 'codes/'.$fileName;
//    
//    // generating
//    if (!file_exists($pngAbsoluteFilePath)) {
//        QRcode::png($codeContents, $pngAbsoluteFilePath);
//        echo 'File generated!';
//        echo '<hr />';
//    } else {
//        echo 'File already generated! We can use this cached file to speed up site on common codes!';
//        echo '<hr />';
//    }
//    
//    echo 'Server PNG File: '.$pngAbsoluteFilePath;
//    echo '<hr />';
//    
//    // displaying
//    echo '<img src="'.$urlRelativeFilePath.'" />'; 
//	
	
	

					
?>