Location: PHPKode > scripts > LQueryBU > LQueryBU/query_units/examples/functions/examplef2.php
====EXECPHPCODE====

<?php
// Parameteres are recived as any other sql unit, throw the parameteres array, and can be 
// used [PARAMETER1]  or  $RECORD->parameter1 , as you prefer.

// EXAMPLE OF CRYPT/DECRYPT FUNCTIONALITY
// Recieves [MODE] (as C or D , meaning CRYPT, DECRYPT) and [STRING] (string to crypt/decrypt)

// Inside a Unit, in the POST_FORMAT_FIELDS, you can call this function as this:
// $RECORD->IDCrypt = $this->getDataQuery("/functions/examplef2",array("MODE" => "C","STRING" => $RECORD->ID));

$cryptMode = "[MODE]"!=""?"[MODE]":"C";
$cryptKey = "aK83[53T}&Gz!Y()";
$cryptText = "[STRING]";

$returnText = "";

$cryptIvs = mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB );
$cryptIv = mcrypt_create_iv( $cryptIvs );

switch ($cryptMode)
{
		case "D":
			$returnText = unserialize(mcrypt_decrypt( MCRYPT_RIJNDAEL_256, $cryptKey, base64_decode($cryptText), MCRYPT_MODE_ECB, $cryptIv ));
		break;
		case "C":
		default:
			$returnText =  rtrim(base64_encode(mcrypt_encrypt( MCRYPT_RIJNDAEL_256, $cryptKey, serialize($cryptText), MCRYPT_MODE_ECB, $cryptIv )),"=");
		break;
}

return $returnText;
?>
Return current item: LQueryBU