packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/includes/template-wrapper.php
changeset 0 3906ca745819
child 3 a044870a9d3d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/includes/template-wrapper.php	Tue Jan 08 23:13:29 2013 -0500
@@ -0,0 +1,55 @@
+<?php
+
+function display_template($tpl, $assign = array())
+{
+	$smarty = new Smarty();
+	
+	$smarty->setTemplateDir(ACCOUNTS . 'includes/templates/');
+	$smarty->setCompileDir(ACCOUNTS . 'includes/templates/compiled/');
+	$smarty->setConfigDir(ACCOUNTS . 'includes/templates/');
+	$smarty->setCacheDir(ACCOUNTS . 'includes/templates/cache/');
+	
+	$smarty->assign('session', $_SESSION);
+	
+	$smarty->assign('user', isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'] : false);
+	if ( isset($_SERVER['REMOTE_USER']) )
+		$smarty->assign('userinfo', $ui = ldap_get_user($_SERVER['REMOTE_USER']));
+	
+	if ( $ui === false )
+		redirect('/logout');
+	
+	$smarty->assign('msgcodes', array(
+			'error' => E_ERROR
+			, 'warning' => E_WARNING
+			, 'notice' => E_NOTICE
+		));
+	
+	foreach ( $assign as $key => $value )
+	{
+		$smarty->assign($key, $value);
+	}
+	
+	$smarty->display("$tpl.tpl");
+}
+
+function parse_template($tpl, $assign = array())
+{
+	$smarty = new Smarty();
+	
+	$smarty->setTemplateDir(ACCOUNTS . 'includes/templates/');
+	$smarty->setCompileDir(ACCOUNTS . 'includes/templates/compiled/');
+	$smarty->setConfigDir(ACCOUNTS . 'includes/templates/');
+	$smarty->setCacheDir(ACCOUNTS . 'includes/templates/cache/');
+	
+	foreach ( $assign as $key => $value )
+	{
+		$smarty->assign($key, $value);
+	}
+	
+	return $smarty->fetch("$tpl.tpl");
+}
+
+function smarty_function_clear_messages($params)
+{
+	$_SESSION['messages'] = array();
+}