Location: PHPKode > projects > ARBS > arbs-1.5.1.78/functions.inc.php
<?php
/*
 * ARBS - Advanced Resource Booking System
 * Copyright (C) 2005-2007 ITMC der TU Dortmund
 * Based on MRBS by Daniel Gardner <http://mrbs.sourceforge.net/>
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */


#vals[0]=variablename
#vals[1]=typ
#	typ: 0: input   1: textarea  2:checkbox  3:radio  4:select
#	note: checkbox and radio are not finished yet
#vals[2]=param[] list of input params
#vals[3]=title(key for lang[] array) 
#vals[4]=description(key for lang[] array)

function drawFormRow($val){
    global $db_entry_fields,$db_entry_fields_session,$db_entry_fields_optional,$db_entry_all_fields_set,$lang,$$val[0];
    if(isset($_GET[$val[0]]))
	    $value=strip_tags($_GET[$val[0]]);
    else
	$value=strip_tags($$val[0]);
    $offset=array_search($val[0],$db_entry_fields);
    #$db_entry_all_fields_set=true;
    #everything saved in session? then do nothing
    if($_SESSION['db_entry_all_fields_set']&&$db_entry_fields_session[$offset])
    	return;
    echo "<tr><td width=150 align=right nowrap><b>",$val[3],"</b></td><td CLASS=CL style=\"background-color:#DDDDDD\" width=250><table border=0 cellspacing=0 cellpadding=0><tr><td>";
    switch($val[1]){
    	case 0:echo "<input type=text name=\"",$val[0],"\" value=\"",$value,"\"";
		drawInputParams($val[2]);
		echo ">";
		break;
	case 1:echo "<textarea name=\"",$val[0],"\"";
		drawInputParams($val[2]);
		echo ">",$value,"</textarea>";
		break;
	//note: checkbox and radio are not finished yet
	case 2:echo "<input type=checkbox name=\"",$val[0],"\" value=\"",$value,"\"";
		drawInputParams($val[2]);
		echo ">";
		break;
	case 3:echo "<input type=checkbox name=\"",$val[0],"\" value=\"",$value,"\"";
		drawInputParams($val[2]);
		echo ">";
		break;		
	case 4:echo "<select name=\"",$val[0],"\"";
		drawInputParams($val[2]);
		echo ">";
		foreach($val[2] as $oname=>$ovalue){
			if(substr($oname,0,7)=="option:")
			echo "<option value=\"".substr($oname,7)."\"",($value==substr($oname,7)?" selected":""),">",$ovalue,"</option>";
		}
		echo "</select>";
    }
    if(!$db_entry_fields_optional[$offset]){
	echo "</td><td>";
    	echo star();
	}
    echo "</td></tr></table></td><td width=650 style=\"background-color:#e0e4f1\">", $val[4], "&nbsp;</td></tr>";
    
}

function drawInputParams($param){
	foreach($param as $key=>$val)
	if(substr($key,0,7)!="option:")
		echo " $key=\"",$val,"\"";
}

#########
#drawTicket() gets all data for the requested id.
#if singleEntry==true, no further information will be collecte. otherwise, the functions tries to find more matcing entrys for the id
#the template parameter is optional and allow to use other template files from the ./<instance>/print-templates/ directory
#basic principle is, to simply include the template files after setting the variables to the desired values. 
#thus, the included termplates perform all the output on its own
#if the template was suchessfully printed, an arry of all printed entrys is returned
#########
function drawTicket($id,$singleEntry=true,$template="default"){
	global $instance;
	#check if all files are accesable
	if(!is_readable($instance."/print-templates/".$template."_head.inc")){
		printf(_("%s can't be read."), $instance."/print-templates/".$template."_head.inc");
		exit;
	}
	if(!is_readable($instance."/print-templates/".$template."_middle.inc")){
		printf(_("%s can't be read."), $instance."/print-templates/".$template."_middle.inc");
		exit;
	}
	if(!is_readable($instance."/print-templates/".$template."_foot.inc")){
		printf(_("%s can't be read."), $instance."/print-templates/".$template."_foot.inc");
		exit;
	}	
				
	$res=sql_query("SELECT * FROM mrbs_entry WHERE id='".$id."'");
	if(mysql_affected_rows()==0){
		printf(_("Couldn't find %d"), $id);
		exit;
	}
	#define all necessary variables
	$template_dbfield=mysql_fetch_array($res);
	
	$template_entry_starttime = strftime("%R" ,$template_dbfield['start_time']);
	$template_entry_startdate = strftime("%d.%m.%Y",$template_dbfield['start_time']);
	$template_entry_enddate = strftime("%d.%m.%Y" ,$template_dbfield['end_time']);
	$template_entry_endtime = strftime("%R",$template_dbfield['end_time']);
	$template_currentdate=date("d.m.Y");
	include $instance."/print-templates/".$template."_head.inc";

	$out_ids=array();
	#either get the very entry or look for all matching entrys
	if($singleEntry){	
		$res1 = sql_query("SELECT room_name FROM mrbs_room WHERE id='".$template_dbfield['room_id']."'");
		$zeile=mysql_fetch_row($res1);
		$booking['roomname']=$zeile[0];
		$booking['extras']=nl2br($template_dbfield['description']);
		include $instance."/print-templates/".$template."_middle.inc";	
		array_push($out_ids,$id);
	}
	else{
		$res1 = sql_query("SELECT r.room_name,e.description,e.id FROM mrbs_entry AS e LEFT JOIN mrbs_room AS r ON e.room_id=r.id
		WHERE e.start_time = '".$template_dbfield['start_time']."'
		AND e.end_time = '".$template_dbfield['end_time']."'
		AND e.name = '".addslashes($template_dbfield['name'])."'
		AND e.advisor_name='".addslashes($template_dbfield['advisor_name'])."'");
		while($zeile=mysql_fetch_row($res1)){
			$booking['roomname']=$zeile[0];
			$booking['extras']=nl2br(addslashes($zeile[1]));
			include $instance."/print-templates/".$template."_middle.inc";
			array_push($out_ids,$zeile[2]);
		}
	}	
	include $instance."/print-templates/".$template."_foot.inc";
	return $out_ids;
}


#this function kills all booking relevant informations from the session, but retaines instance and language information
function reset_session(){
	global $db_entry_fields;
	session_unregister("session_booking_ids");
	session_unregister("session_booking_rid");
	session_unregister("db_entry_all_fields_set");
	
	foreach($db_entry_fields as $val){
		session_unregister($val);
	}
	$_SESSION["db_entry_all_fields_set"]=false;
}

function star(){
	return "<img width='16' height='16' src='img/star.gif' border=0 style=\"clear:none;\">";
}

function buildSelectFormat($start,$end,$step,$selection,$prefix,$suffix){
	for($i=$start;$i<=$end;$i=$i+$step){
		$iv = $prefix.((strlen($i)==1)?("0"):("")).$i.$suffix;
		if($i==$selection)
			echo "<option value='$i' selected>$iv</option>";
		else
			echo "<option value='$i'>$iv</option>";
	}
}

function mrbsGetRoomName($id){
	$res = sql_query("SELECT room_name FROM mrbs_room WHERE (id = $id)");
	$row = sql_row($res, 0);
	$room=$row[0];
	return $room;
}

function buildSelect($start,$end,$step,$selection){
	for($i=$start;$i<=$end;$i=$i+$step){
		$iv = ((strlen($i)==1)?("0"):("")).$i;
		if($i==$selection)
			echo "<option value='$i' selected>$iv</option>";
		else
			echo "<option value='$i'>$iv</option>";
	}
}

function print_company_image(){
	global $mrbs_url,$mrbs_logoimage,$instance;
	if (strlen($mrbs_logoimage)>0){
			$path = $instance."/";
			echo "<a href='".$mrbs_url."'>";
			echo "<img src='".$path.$mrbs_logoimage."' border='0'></img>";
			echo "</a>";
	}
		
}


function formHiddenFields(){
	#certain fields should not be passed again: instance and select_language
	#passing them in every form is unnecessary and prevents further changing of these values
	$skip=array("instance","select_language");
	foreach($_GET as $key=>$val){
		if (strlen($val)){
			if(!in_array($key,$skip))
				echo "<input type='hidden' name='".$key."' value='".strip_tags($val)."'></input>";
		}
	}
}
function hrefGetVar($data,$var){
	$pos = strpos($data,$var."=");
	if($pos===false){
		return "";
	}
	else{
		return substr($data, $pos+strlen($var)+1, strpos($data,"&", $pos+strlen($var)+2)-($pos+strlen($var)+1));
	}
}

function print_header($day, $month, $year, $area){
	global $lang, $mrbs_company, $search_str,$nrbs_pageheader,$instance,$language_available,$session_selected_language,$header_links;

	# If we dont know the right date then make it up 
	if(!$day)
		$day   = date("d");
	if(!$month)
		$month = date("m");
	if(!$year)
		$year  = date("Y");
	if (empty($search_str))
		$search_str = "";

?>
	<HTML>
	<HEAD>
	<TITLE><?php echo(_("Reserving devices ONLINE")); ?></TITLE>
<?php
	   include("style.inc.php");
?>
	</HEAD>
<?php
#overlib javascript for hovering over entries
?>
<script type="text/javascript" src="js/overlib.js"><!-- overLIB (c) Erik Bosrup --></script>
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
	<BODY BGCOLOR="#ffffed" TEXT=black LINK="#5B69A6" VLINK="#5B69A6" ALINK=red>
<?php 
	if ( $GLOBALS["pview"] != 1 ) { 
?>
		<TABLE WIDTH="100%">
<?php
		if (strlen($nrbs_pageheader)>0){
?>
	   		<tr><td style="text-align:center;"><?php echo($nrbs_pageheader) ?></td></tr>
<?php
		}
?>
		<TR>
		<TD BGCOLOR="#5B69A6">
		<TABLE WIDTH="100%" BORDER=0>
	        <TR>
		<TD CLASS="banner" BGCOLOR="#C0E0FF">
		<FONT SIZE=4><B><?php echo $mrbs_company ?></B>
		</FONT>
		</TD>
		<TD CLASS="banner" BGCOLOR="#C0E0FF">
		<FORM ACTION="day.php" METHOD=GET>
<?php 
		formHiddenFields(); 
?>
		<FONT SIZE=2>
<?php
		genDateSelector("", $day, $month, $year);
		if (!empty($area))
			echo "<INPUT TYPE=HIDDEN NAME=area VALUE=$area>"; 
?> 
		<INPUT TYPE=SUBMIT VALUE="<?php echo(_("Start")); ?>"> </FONT> </FORM>
		</td>
<?php
if(count($language_available)>1){
	echo "<td CLASS=banner BGCOLOR=#C0E0FF><FORM ACTION=",$_SERVER['PHP_SELF']," METHOD=GET>",_("Language:");
	formHiddenFields();
	echo "<select name=select_language>";
	foreach($language_available as $key=>$val){
		echo "<option value=$val",($val==$session_selected_language?" selected":""),">",$key,"</option>";
	}
	echo "</select> <input type=submit value=\"-&gt;\"></form> </TD> ";
}
		for($i=0;isset($header_links[$i]);$i++){
			$ary = explode(";",$header_links[$i]);
?>
			<TD CLASS="banner" BGCOLOR="#33FF33" ALIGN=CENTER> 
			<A HREF="<?php echo($ary[1]) ?>
<?php
	 		if ($ary[2]==1)
	 			echo("?day=".$day."&month=".$month."&year=".$year);
	 		echo "\"";
	 		if($ary[3]==1)
	 			echo(" target='_blank'");
			echo ">";
			echo($ary[0]) 
?>
			</A></TD> 
<?php
		}
?>
		<TD CLASS="banner" BGCOLOR="#FF9933" ALIGN=CENTER> <A HREF="admin.php"><?php echo(_("Administration")); ?></A> </TD>
		<TD CLASS="banner" BGCOLOR="#C0E0FF" ALIGN=CENTER>
		<FORM METHOD=GET ACTION="search.php">
		<?php formHiddenFields(); ?>
		<FONT SIZE=2><?php echo(_("Search:")); ?> </FONT> <INPUT TYPE=TEXT   NAME="search_str" VALUE="<?php echo $search_str ?>" SIZE=10>
		
		</FORM> 
		</TD> </TR> </TABLE> </TD> </TR> </TABLE> 
<?php
	} 
}

function toTimeString(&$dur, &$units){
	global $lang;
	if($dur >= 60){
		$dur /= 60;		
		if($dur >= 60){
			$dur /= 60;			
			if(($dur >= 24) && ($dur % 24 == 0)){
				$dur /= 24;		
				if(($dur >= 7) && ($dur % 7 == 0)){
					$dur /= 7;
					
					if(($dur >= 52) && ($dur % 52 == 0)){
						$dur  /= 52;
						$units = _("Years");
					}
					else
						$units = _("Weeks");
				}
				else
					$units = _("Days");
			}
			else
				$units = _("Hours");
		}
		else
			$units = _("Minutes");
	}
	else
		$units = _("Secounds");
}

function parseDate($date){
	/* $s means "search";
	 * $r means "replace";
	 */
	$s = array();
	$r = array();
	
	$s[]="Monday";			$r[]=_("Monday");
	$s[]="Tuesday";			$r[]=_("Tuedsay");
	$s[]="Wednesday";		$r[]=_("Wednesday");
	$s[]="Thursday";		$r[]=_("Thursday");
	$s[]="Friday";			$r[]=_("Friday");
	$s[]="Saturday";		$r[]=_("Saturday");
	$s[]="Sunday";			$r[]=_("Sunday");
	
	$s[]="January";			$r[]=_("January");
	$s[]="February";		$r[]=_("February");
	$s[]="March";			$r[]=_("March");
	$s[]="April";			$r[]=_("April");
	$s[]="May";				$r[]=_("May");
	$s[]="June";			$r[]=_("June");
	$s[]="July";			$r[]=_("July");
	$s[]="August";			$r[]=_("August");
	$s[]="September";		$r[]=_("September");
	$s[]="October";			$r[]=_("October");
	$s[]="November";		$r[]=_("November");
	$s[]="December";		$r[]=_("December");
	
	$s[]="Jan";				$r[]=_("Jan");
	$s[]="Feb";				$r[]=_("Feb");
	$s[]="Mar";				$r[]=_("Mar");
	$s[]="Apr";				$r[]=_("Apr");
	$s[]="May";				$r[]=_("May");
	$s[]="Jun";				$r[]=_("Jun");
	$s[]="Jul";				$r[]=_("Jul");
	$s[]="Aug";				$r[]=_("Aug");
	$s[]="Sep";				$r[]=_("Sep");
	$s[]="Oct";				$r[]=_("Oct");
	$s[]="Nov";				$r[]=_("Nov");
	$s[]="Dec";				$r[]=_("Dec");
	
	
	
	return str_replace($s, $r, $date);
}

#functions creates two select fields: hour,minute
#timerange is determined by config values $resolution,$norningstarts,$eveningends
#parameter:
#$label_hour,$label_minute: set name of select fields
#optional:
#$history_hour,$history_minute: preselect an option
function genTimeSelector($label_hour,$label_minute,$history_hour=-1,$history_minute=-1){
	global $resolution,$morningstarts,$eveningends,$lastBookingHour;

	#hack to disallow booking 4 hours before
        if($label_hour=="hour"){
                $end=$lastBookingHour;
        }
	else
		$end=$eveningends;
	echo "<select name=$label_hour>";
	for($n=$morningstarts;$n<=$end;$n++){
		echo "<option value=$n",($history_hour==$n?" selected":""),">",(strlen($n)==1?"0$n":$n),"</option>";
	}
	echo "</select> : <select name=$label_minute>";
	#resolution is defined in seconds
	for($n=0;$n<60;$n+=($resolution/60)){
		echo "<option value=$n",($history_minute==$n?" selected":""),">",(strlen($n)==1?"0$n":$n),"</option>";
	}
	echo "</select>";
}

function genDateSelector($prefix, $day, $nonth, $year,$history=0,$id_prefix=""){
	if($day   == 0)
		$day = date("d");
	if($nonth == 0) 
		$nonth = date("m");
	if($year  == 0)
		$year = date("Y");
	
	echo "<SELECT id=\"${id_prefix}day\" NAME=\"${prefix}day\">\n";
	
	for($i = 1; $i <= 31; $i++)
		echo "<OPTION" . ($i == $day ? " SELECTED" : "") . " value=$i>$i</option>\n";
	
	echo "</SELECT>";
	echo "<SELECT id=\"${id_prefix}month\" NAME=\"${prefix}month\">\n";
	
	for($i = 1; $i <= 12; $i++){
		$n = parseDate(strftime("%b", mktime(0, 0, 0, $i, 1, $year)));
		
		print "<OPTION VALUE=\"$i\"" . ($i == $nonth ? " SELECTED" : "") . " value=$n>$n</option>\n";
	}
	
	echo "</SELECT>";
	echo "<SELECT id=\"${id_prefix}year\" NAME=\"${prefix}year\">\n";
	
	$nin = min($year, date("Y")) -$history;
	$nax = max($year, date("Y")) + 1;
	
	for($i = $nin; $i <= $nax; $i++)
		print "<OPTION" . ($i == $year ? " SELECTED" : "") . " value=$i>$i</option>\n";
	
	echo "</SELECT>";
}
#--------------------------

function genDateSelector1($prefix, $end_day, $end_month, $end_year){
        if($end_day   == 0) $end_day = date("d");
        if($end_month == 0) $end_month = date("m");
        if($end_year  == 0) $end_year = date("Y");

        echo "<SELECT NAME=\"${prefix}end_day\">\n";

        for($i = 1; $i <= 31; $i++)
                echo "<OPTION" . ($i == $end_day ? " SELECTED" : "") . ">$i\n";

        echo "</SELECT>";
        echo "<SELECT NAME=\"${prefix}end_month\">\n";

        for($i = 1; $i <= 12; $i++){
                $j = parseDate(strftime("%b", mktime(0, 0, 0, $i, 1, $end_year)));

                print "<OPTION VALUE=\"$i\"" . ($i == $end_month ? " SELECTED" : "") . ">$j\n";
        }

        echo "</SELECT>";
        echo "<SELECT NAME=\"${prefix}end_year\">\n";

        $nin = min($end_year, date("Y")) - 0;
        $nax = max($end_year, date("Y")) + 1;
        for($i = $nin; $i <= $nax; $i++)
                print "<OPTION" . ($i == $end_year ? " SELECTED" : "") . ">$i\n";
        echo "</select>";

}


#--------------------------

function genDateSelector2($prefix, $end_day, $end_month, $end_year,$history=0){
        if($end_day   == 0) $end_day = date("d");
        if($end_month == 0) $end_month = date("m");
        if($end_year  == 0) $end_year = date("Y");
 
 
        echo "<SELECT id=CP_endday NAME=\"${prefix}end_day\" onChange=\"document.main.reload()\">\n";


        for($i = 1; $i <= 31; $i++)
                echo "<OPTION" . ($i == $end_day ? " SELECTED" : "") . " value=$i>$i</option>\n";

        echo "</SELECT>";
        echo "<SELECT id=CP_endmonth NAME=\"${prefix}end_month\">\n";

        for($i = 1; $i <= 12; $i++){
                $j = parseDate(strftime("%b", mktime(0, 0, 0, $i, 1, $end_year)));
                print "<OPTION VALUE=\"$i\"" . ($i == $end_month ? " SELECTED" : "") . " value=$j>$j</option>\n";
        }

        echo "</SELECT>";
        echo "<SELECT id=CP_endyear NAME=\"${prefix}end_year\">\n";

        $nin = min($end_year, date("Y")) - $history;
        $nax = max($end_year, date("Y")) + 1;
	for($i = $nin; $i <= $nax; $i++)
                print "<OPTION" . ($i == $end_year ? " SELECTED" : "") . " value=$i>$i</option>\n";
	echo "</select>";
}





#-------------------------

# Error handler - this is used to display serious errors such as database
# errors without sending incomplete HTML pages. This is only used for
# errors which "should never happen", not those caused by bad inputs.
# If $need_header!=0 output the top of the page too, else assume the
# caller did that. Alway outputs the bottom of the page and exits.
function fatal_error($need_header, $message){
	global $lang;
	if ($need_header) 
		print_header(0, 0, 0, 0);
	echo $message;
	include("trailer.inc.php");
	exit;
}

# Apply backslash-escape quoting unless PHP is configured to do it
# automatically. Use this for GET/POST form parameters, since we
# cannot predict if the PHP configuration file has magic_quotes_gpc on.
function slashes($s){
	if (get_magic_quotes_gpc()) 
		return $s;
	else 
		return addslashes($s);
}

# Remove backslash-escape quoting if PHP is configured to do it with
# magic_quotes_gpc. Use this whenever you need the actual value of a GET/POST
# form parameter (which might have special characters) regardless of PHP's
# magic_quotes_gpc setting.
function unslashes($s){
	if (get_magic_quotes_gpc()) 
		return stripslashes($s);
	else
		return $s;
}

# Return a default area; used if no area is already known. This returns the
# lowest area ID in the database (no guaranty there is an area 1).
# This could be changed to implement something like per-user defaults.
function get_default_area(){
	$area = sql_query1("SELECT MIN(id) FROM mrbs_area");
	return ($area < 0 ? 0 : $area);
}
function get_default_category($area){
	$cat = sql_query1("SELECT MIN(id) FROM mrbs_category where area_id=$area");
	return ($cat < 0 ? 0 : $cat);
}


# Get the local day name based on language. Note 2000-01-02 is a Sunday.
function day_name($daynumber){
	return strftime("%A", mktime(0,0,0,1,2+$daynumber,2000));
}

# Output a start table cell tag <td> with color class and fallback color.
# $colclass is an entry type (A-J), "white" for empty, or "red" for highlighted.
# The colors for CSS browsers can be found in the style sheet. The colors
# in the array below are fallback for non-CSS browsers only.
function tdcell($colclass){
	# This should be 'static $ecolors = array(...)' but that crashes PHP3.0.12!
	static $ecolors;
	if (!isset($ecolors)) $ecolors = array("A"=>"#FFCCFF", "B"=>"#99CCCC",
		"C"=>"#FF9999", "D"=>"#FFFF99", "E"=>"#C0E0FF", "F"=>"#FFCC99",
		"G"=>"#FF6666", "H"=>"#66FFFF", "I"=>"#DDFFDD", "J"=>"#CCCCCC",
		"red"=>"#FFF0F0", "white"=>"#FFFFFF");
	if (isset($ecolors[$colclass]))
		echo "<td class=\"$colclass\" bgcolor=\"$ecolors[$colclass]\">";
	else
		echo "<td class=\"$colclass\">";
}

# Display the entry-type color key. This has up to 2 rows, up to 5 columns.
function show_colour_key(){
	global $typel,$lang;
	echo "<table border=0><tr>\n";
	for ($ct = "A"; $ct <= "J"; $ct++){
		if (!empty($typel[$ct])){			
			echo "<td class=$ct>$typel[$ct]</td>\n";
		}
	}
	echo "<td class=nofreeslots>", _("Booked out"), "</td></tr></table>\n";
}

# Round time down to the nearest resolution
function round_t_down($t, $resolution){
       return (int)$t - (int)$t % $resolution;
}

# Round time up to the nearest resolution
function round_t_up($t, $resolution){
       if ($t % $resolution != 0){
               return $t + $resolution - $t % $resolution;
       }
       else{
               return $t;
       }
}
function mailto($to,$from,$title,$text){
	if (strlen($text)>0)
		mail($to,$title,$text,"From: ".$from."\n\r");
}

function getMailTemplate($templateName,$status=""){
	global $instance;
	$ret ="";
	switch($templateName){
		case "new":
			if($status==0)
				$fn = "new_single_entry.inc";
			else
				$fn = "new_repeat_entry.inc";
		break;
		case "adminnew":
			if($status==0)
				$fn = "new_single_admininfo.inc";
			else
				$fn = "new_repeat_admininfo.inc";			
		break;
		case "type":
			$fn="edit_type_".$status.".inc";
			break;
        case "repeattype":
            $fn="edit_repeat_".$status.".inc";
            break;

		case "edit_single":
		$fn = "edit_single_".$status.".inc";
		break;
		case "edit_repeat":
                $fn = "edit_repeat_".$status.".inc";
                break;
		default:
		$fn = "";
	}
	if(strlen($fn)>0){
		$ret = fileContent($instance."/mail-templates/".$fn);
	}
	return $ret;
}
function fileContent($fn){
	if (file_exists($fn)){
		$f = fopen($fn,"r");
		$contents = fread($f,filesize($fn));
		fclose($f);
		return $contents;
	}
	return "";
}
function mailParseText($text,$entryID){
	// Daten ermitteln
	// die Funktionen geben einen Assoziativen Array
	// $data["room"] -> RaumFelder
	// $data["entry"] -> Eintrags-Felder, 
	// falls Repeat eintrag existiert, wird dieser genommen
	$rep=false;
	$data ="";
	$sql = "SELECT * FROM mrbs_entry WHERE id=$entryID";
	$ret = sql_query($sql);
	if (sql_count($ret)>0){
		$data["entry"] = sql_row_keyed($ret,0);
		if ($data["entry"]["repeat_id"]>0){
			$entryID=$data["entry"]["repeat_id"];
			$sql = "SELECT * FROM mrbs_repeat WHERE id=$entryID";
			$ret = sql_query($sql);
			$data["repeat"] = sql_row_keyed($ret,0);
			$rep=true;
		}
		$room_id = $data["entry"]["room_id"];
		$sql = "SELECT * FROM mrbs_room WHERE id=$room_id";
		$ret = sql_query($sql);
		$data["room"] = sql_row_keyed($ret,0);
		
		// Text Parsen:
		$ret="";
		$posEnd=0;
		$len =strlen($text);
		while (!(($pos = strpos($text,"[",$posEnd))===false)){
			$ret.=substr($text,$posEnd,$pos-$posEnd);
			$posEnd = strpos($text,"]",$pos)+1;
			$rplStr = substr($text,$pos+1,$posEnd-$len-1);
			$pPos =strpos($rplStr,".");
			if(!($pPos===false)){
				$sect = substr($rplStr,0,$pPos);
				$field = substr($rplStr,$pPos+1);
				if (strpos($field,"{")>0 && strpos($rplStr,".")>0){
					$dbfield = substr($field,0,strpos($field,"{"));
					$typeStr = substr($field,strpos($field,"{")+1);
					$typeStr = substr($typeStr,0,strlen($typeStr)-1);
					$type = substr($typeStr,0,strpos($typeStr,":"));
					$opt = substr($typeStr,strpos($typeStr,":")+1);
					if(isset($data[$sect][$dbfield])){
						if ($type=="date"){
							$ret .= parseDate(strftime($opt,$data[$sect][$dbfield]));
						}
						else{
							$ret .= $data[$sect][$dbfield];	
						}
					}
					else{
						//$ret .= "[".$rplStr."]";
					}
				}
				else{
					if(isset($data[$sect][$field]))
						$ret .= $data[$sect][$field];
					else
						$ret .= "[".$rplStr."]";
				}
			}
			else{
				$ret .= "[".$rplStr."]";
			}
		}		
		$ret.=substr($text,$posEnd);
		return $ret;
	}
	else{
		return "";
	}
}
function getSubject($text){
	return trim(substr($text,0,strpos($text,"\n")));
}
function removeSubject($text){
	return trim(substr($text,strpos($text,"\n")));
}

function drawTimeTableColum($room,$capacity,$zeit){
	global $resolution,$showSingleEntrysAsBlock;
	$wday=date("d",$zeit);
	$wmonth=date("m",$zeit);
	$wyear=date("Y",$zeit);
	$hour=date("H",$zeit);
	$minute=date("i",$zeit);
        $zeitt=$zeit+$resolution;
	//the LIMIT greatly improves performance, dont kill it!
	$eintraege = sql_query("SELECT type, id,title,start_time,end_time
        	FROM mrbs_entry
                Where room_id = $room
                AND start_time <= $zeit
                AND end_time >= $zeitt LIMIT 0,".($capacity));
if($hour==12 &&$wday==28 &&1==2)
echo "SELECT type, id,title,start_time,end_time
            FROM mrbs_entry
                Where room_id = $room
                AND start_time <= $zeit
                AND end_time >= $zeitt LIMIT 0,".($capacity);
	$reserviert = mysql_num_rows($eintraege);
	$verfuegbar = $capacity - $reserviert;

	if ( $capacity>0 && $verfuegbar<1 && !$showSingleEntrysAsBlock ) {
		tdcell(mysql_result($eintraege, $i , 0));
	}
        elseif($verfuegbar<1){
        	tdcell("nofreeslots");
        }
        else {
        	tdcell("white");
        }
                
	echo "<center>";

        if(!$showSingleEntrysAsBlock&&$verfuegbar==1&&$capacity==1) {
	        //do nothing
        	echo "<a href=\"edit_entry.php?view=week&room=$room"
                . "&hour=$hour&minute=$minute&year=$wyear&month=$wmonth"
                . "&day=$wday\"><img src=img/new.gif width=10 height=10 border=0></a>";
	} 
	elseif ($verfuegbar > 0) {
        	echo "<a href=\"edit_entry.php?view=week&room=$room"
                . "&hour=$hour&minute=$minute&year=$wyear&month=$wmonth"
                . "&day=$wday\"> ( $verfuegbar / $capacity ) <img src=img/new.gif width=10 height=10 border=0></a>";

	}
        elseif ($showSingleEntrysAsBlock){
	        echo " ( $verfuegbar / $capacity )";
	}
        echo "</center>";
	#begin table for entry list boxes
        #if there is only one entry, show this as text instead of box
      	if($reserviert==1&&!$showSingleEntrysAsBlock){
	        $type=mysql_result($eintraege, 0 , 0);
        	$id   = mysql_result($eintraege, 0 , 1 );
	        $thetitle=mysql_result($eintraege, 0 , 2);

                $links="view_entry.php?view=week&id=".$id."&day=$wday&month=$wmonth&year=$wyear";
                echo "<a href=\"$links\">",substr($thetitle,0,20),"</a>";
	}
        else{
        	echo "<table cellspacing=3 cellpadding=0 border=0><tr>";
                for ($i = 0 ; $i < $reserviert ; $i++){
		        $type=mysql_result($eintraege, $i , 0);
		        $id   = mysql_result($eintraege, $i , 1 );
        		$thetitle=mysql_result($eintraege, $i , 2);
	
                        $links="view_entry.php?view=week&id=".$id."&day=$wday&month=$wmonth&year=$wyear";
                        echo "<td class=$type><a onmouseover=\"return overlib('<b>",addslashes($thetitle),"</b><br>", _("from"), " ", strftime('%d.%b.%Y %H:%M',mysql_result($eintraege,$i,3)),"<br>", _("till"), " ",strftime('%d.%b.%Y %H:%M',mysql_result($eintraege,$i,4)),"');\" onmouseout=\"return nd();\" href=\"$links\" ><img src=img/pixel.gif width=10 height=10 border=0></a></td>";
		}
                echo "</tr></table>";
	}
	echo "</td>";
}
?>
Return current item: ARBS