<?php
	/**
	 * used for debug purpose only. It prints out a given variable
	 * @param mixed $what
	 * @param string $label
	 * @param string $verbose
	 */
	function d( $what, $label = '', $verbose = false ) {
		$stack = debug_backtrace();
		
		echo '<textarea cols="80" rows="15">';

		if( !empty ( $label ) ) {
			echo $label . ': ' . "\n";
		}

		if( $verbose ) {
			var_dump( $what );
			$stack_shift = array_shift( $stack );
		}else{
			print_r( $what );
		}

		echo '</textarea>' . "\n";
		echo "<br/>stacktrace<br/>";
		echo '<textarea cols="80" rows="5">';
			print_r( $stack );
		echo '</textarea>' . "\n";
	}

	/**
	 * d() function overload with $verbose=true
	 *
	 * @param mixed $what        	
	 * @param mixed $label        	
	 */
	function dd( $what, $label = '' ) {
		d( $what, $label, true );
	}

	/**
	 * Quick logging function. Uses Log class to write information to a file
	 * @param string $message (message to log)
	 * @param bool $verbose log extra information
	 */
	function l( $message, $verbose = false ) {
		$log_file = _APPLICATION_LOG_PATH . '/' . _APPLICATION_NAME . '.log';
		$l = new Log ( $log_file );
		
		if( $verbose == true ){
			$message = var_export( $message, true );
		}else{
			$message = print_r( $message, true );
		}

		// add file name and line nummber
		$debug_backtrace = debug_backtrace();
		if( is_array( $debug_backtrace) == true ){
			$stack = array_shift( $debug_backtrace );
			$message = 'file: ' . $stack['file'] . ' (' . $stack['line'] . ')' . "\n" . $message;
		}

		$l->write ( $message );
	}
	
	/**
	 * overload of l() function with $verbose = true
	 *
	 * @param mixed $message (message to log)
	 */
	function ll( $message ) {
		l( $message, true );
	}
