Location: PHPKode > scripts > ER Manager > ermanager/template.php
<?php
/**
 * Template functions
 *
 * These functions prepare the data for assignment to the template engine
 *
 * @todo replace additional assignments of config options by using $config
 * @package template
 * @version $Id: template.php,v 1.1.1.1 2004/07/28 12:09:06 pbworks Exp $
 */

require_once "session.php";

/**
 * Assigns language strings and config options to the smarty engine
 */
function tpl_language(){
  global $smarty;
  global $lang;
  global $config;
  $smarty->assign('lang',$lang);
  $smarty->assign('config',$config);
}

/**
 * Assigns the headerurls to the smarty engine
 *
 * @param string $help    The helpfile to display (optional, without extension)
 */
function tpl_header($help = ''){
  global $smarty;
	global $lang;
	global $config;
  
  global $id;
	global $diskid;
	
	$header[browse] = 'index.php';
	$header[random] = 'show.php';
	$header[search] = 'search.php';
	$header[stats]  = 'stats.php';
	if ($config[imdbBrowser]) $header[imdbBrowser] = 'trace.php';
	if ($help){
	  $header[help] = 'help.php?page='.$help.'.html';
	}else{
	  $header[help] = 'help.php';
  }
  
	if(localnet()) {
	  if(check_permission(AUTH_WRITE)) $header['new']  = 'edit.php';
	  if(check_permission(AUTH_ADMIN)) $header['setup']  = 'setup.php';
	  if ($id) {
	    if (!ereg ("edit.php$", $_SERVER['PHP_SELF'])) {
      	if(check_permission(AUTH_WRITE)) $header[edit]   = 'edit.php?id='.$id;
      }
      if (!ereg ("show.php$", $_SERVER['PHP_SELF'])) {
      	$header[view]   = 'show.php?id='.$id;
      }
      if(check_permission(AUTH_WRITE)) $header[del]    = 'delete.php?delid='.$id;
    }
    if(check_permission(AUTH_WRITE)){
 		  if (isset($diskid)) {
 			  $header[borrow] = 'borrow.php?diskid='.$diskid;
 		  }else{
 			  $header[borrow] = 'borrow.php';
 		  }
 		}
	}
	if ($config[multiuser]){
    $header[login] = 'login.php';
  }

  if($config[multiuser]){
    $smarty->assign('loggedin',$_COOKIE['VDBusername']);	
  }
	$smarty->assign('header',$header);
	$smarty->assign('style',$config[style]);
	$smarty->assign('langcode',$config[language]);
	$smarty->assign('localnet',localnet());
}

/**
 * Assigns the filter options to the smarty engine
 */
function tpl_filters($filter,$showtv){
  global $smarty;
  global $lang;
	
	$filters[all]=$lang[radio_all];
	$filters[NUM]='#';
	$filters[ABC]='ABC';
	$filters[DEF]='DEF';
	$filters[GHI]='GHI';
	$filters[JKL]='JKL';
	$filters[MNO]='MNO';
	$filters[PQRS]='PQRS';
	$filters[TUV]='TUV';
	$filters[WXYZ]='WXYZ';
	$filters[unseen]=$lang[radio_unseen];
	$filters['new']=$lang[radio_new];
	$filters[wanted]=$lang[radio_wanted];
	
	$smarty->assign('filters',$filters);
	$smarty->assign('filter',$filter);
	$smarty->assign('showtv',$showtv);
	// enable dynamic columns in list view
	$smarty->assign('listcolumns',$_SESSION['vdb'][listcolumns]);
}

/**
 * Assigns the searchresults/browselist to the smarty engine
 */
 
function tpl_list($list){
  global $smarty;
  global $config;

  $smarty->assign('list',$list);
} 

function tpl_list_companies($list){
  global $smarty;
  global $config;

  $smarty->assign('list',$list);
} 

function tpl_list_forma_info($list_forma_info){
  global $smarty;
  global $config;
	
  $smarty->assign('forma_info',$list_forma_info);
}
 
function tpl_list_notes($list_notes){
  global $smarty;
  global $config;

  $smarty->assign('notes',$list_notes);
}

function tpl_list_todos($list_todos){
  global $smarty;
  global $config;

  $smarty->assign('todos',$list_todos);
}

function tpl_list_todos_done($list_todos_done){
  global $smarty;
  global $config;

  $smarty->assign('todos_done',$list_todos_done);
}

/**
 * Assigns debug infos and version to the smarty engine
 */
function tpl_footer(){
  global $smarty;
  global $config;
  
  if ($config[debug]) {
	  $out = $config;
	  $out[db_password]='***';
		ob_start();
		print '<pre>';
		print_r($out);
		print '</pre>';
    phpinfo();
    $debug .= ob_get_contents();
    ob_end_clean();
    $smarty->assign('DEBUG',$debug);
	}
	$version = join('',file('doc/VERSION'));
	$smarty->assign('version',$version);
}

/**
 * Assigns the videoinfos to the smarty engine
 */
function tpl_show($video,$genres){
  global $smarty;
  global $config;
  
  //imageurl
  $video[0][imgurl] = getThumbnail($video[0][imgurl]);

  //make soft linebreaks:
  $video[0][filename] = preg_replace("/_/","_<wbr>",$video[0][filename]);
  $video[0][filename] = preg_replace("/\./",".<wbr>",$video[0][filename]);
  $video[0][filename] = preg_replace("/-/","-<wbr>",$video[0][filename]);
  //humanreadable filesize:
  if ($video[0]['filesize'] != 0) {
	  $video[0]['filesize'] = round($video[0]['filesize']/(1024*1024),2);
  }
  //break plot and comment
  $video[0][plot]     = nl2br($video[0][plot]);
  $video[0][comment]  = nl2br($video[0][comment]);

  //prepare castarray
  $castary=split("\n",$video[0][actors]);
  foreach ($castary as $actor){
    $actorary    = split("::",$actor);
    $cast[name]  = $actorary[0];
    $roleary     = split("/",$actorary[1]);
    for ($i=0; $i < count($roleary);$i++){
      $roleary[$i] = preg_replace("/\(/","<small>(",$roleary[$i]);
      $roleary[$i] = preg_replace("/\)/",")</small>",$roleary[$i]);
    }
    $cast[roles] = $roleary;
    $cast[imdburl]="http://uk.imdb.com/Name?".urlencode(decodeHTML($cast[name]));
    //check for actor thumbnail
    if($config[actorpics]){
      $cast[imgurl] = getActorThumbnail($cast[name]);
    }else{
      $cast[imgurl]="";
    }
    
    $video[0][cast][]=$cast;
  }

  //prepare the castcolumn stuff
  $castbreak = ceil(count($video[0][cast]) / $config[castcolumns]);

  //prepare the custom fields
  for($i=1; $i < 5; $i++){
    if (!empty($config['custom'.$i])){
      $video[0]['custom'.$i.'name'] = $config['custom'.$i];
      $run = 'custom_'.$config['custom'.$i.'type'].'_output';
      $video[0]['custom'.$i.'out']  = $run('custom'.$i,$video[0]['custom'.$i]);
    }
  }

  $smarty->assign('castbreak',$castbreak);
  $smarty->assign('castcolumns',$config[castcolumns]);
  $smarty->assign('video',$video[0]);
  $smarty->assign('genres',$genres);
}

/**
 * Assigns the videoinfos to the smarty engine
 */
function tpl_edit($entity){
  global $smarty;
  global $config;

  //create a form ready quoted version for each value
  foreach(array_keys($entity[0]) as $key){
    $entity[0]['q_'.$key] = formvar($entity[0][$key]);
  }

if($entity[0][company_id]==NULL) {
$entity[0][company_id] = $_GET['company_id'];
} //end set company_id

if($entity[0][date]) {
  //splits the date date in day, month and year
  list($year, $month, $day) = split('[/.-]', $entity[0][date]);  
  $entity[0][day] = $day;
  $entity[0][month] = $month;
  $entity[0][year] = $year;
} else {
  $entity[0][day] = date("j");
  $entity[0][month] = date("m");
  $entity[0][year] = date("Y");
}

if($entity[0][deadline]) {
  //splits the date date in day, month and year
  list($year, $month, $day) = split('[/.-]', $entity[0][deadline]);  
  $entity[0][day] = $day;
  $entity[0][month] = $month;
  $entity[0][year] = $year;
} // end if date
    
  $smarty->assign('entity',$entity[0]);
}

function tpl_edit_forma($entity){
  global $smarty;
  global $config;

  //create a form ready quoted version for each value
  foreach(array_keys($entity[0]) as $key){
    $entity[0]['q_'.$key] = formvar($entity[0][$key]);
  }

  if($entity[0][company_id]==NULL) {
    $entity[0][company_id] = $_GET['company_id'];
  } //end set company_id
    
  $smarty->assign('entity',$entity[0]);
}

function tpl_edit_company($entity){
  global $smarty;
  global $config;

  //create a form ready quoted version for each value
  foreach(array_keys($entity[0]) as $key){
    $entity[0]['q_'.$key] = formvar($entity[0][$key]);
  }

  if ( ereg("I", $entity[0][language]) ) { $entity[0][lang_i]="i"; }
  if ( ereg("D", $entity[0][language]) ) { $entity[0][lang_d]="d"; }
  if ( ereg("F", $entity[0][language]) ) { $entity[0][lang_f]="f"; }
  if ( ereg("E", $entity[0][language]) ) { $entity[0][lang_e]="e"; }
    
  $smarty->assign('entity',$entity[0]);
}

?>
Return current item: ER Manager