<html>
<!-- demo page to create the lab tables -->
<head>
<?
include("cfg.php");
include("auth.php");
?>
<title>Event Self Registration :: arsLab</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=<? echo $ars[charSet]; ?>">
<link href="lab.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
<!--
// window.open for cells
function clkOp(cellID)
{
popWin = window.open("<? echo $SCRIPT_NAME; ?>?submit=" + cellID <? echo isset($labID)?"+ \"&labID=$labID\"":""; ?>,"pop","height=250,width=360,top=50,left=50,resizable");
popWin.focus();
}
function lightCell(sw, myID)
{
var myObj = document.getElementById(myID);
if( sw )
{
myObj.style.cursor = "hand";
myObj.style.background = "#FFFF80";
} else {
myObj.style.cursor = "auto";
myObj.style.background = "white";
}
}
-->
</script>
</head>
<body bgcolor=white>
<?
// functions
function OC($cellID)
{
return "onClick=\"clkOp('$cellID');\" onMouseMove=\"lightCell(1,'lab$cellID');\" onMouseOut=\"lightCell(0,'lab$cellID');\"";
}
// convert hebrew chars into unicode
function Heb( $str )
{
$s = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
$res = "";
foreach( $s as $k => $v )
{
$ski = Ord($v);
if( $ski > 223 && 249 < $ski )
{
$ski += 1264;
$res = $res . "&#$ski;";
} else {
$res = $res . $v;
}
}
return $res;
}
// get lab data by ID
if( isset($labID) && is_numeric($labID) )
{
// get lab records
$db = mysql_pconnect($ars[host],$ars[user],$ars[pass]);
mysql_select_db($ars[dbname],$db);
if( $res = mysql_query("select * from labs where id = $labID") )
{
if( $lab = mysql_fetch_array($res) )
{
// prepare the needed vars:
$v_days = $lab[repeat];
$my_width = $lab["class"] * $lab[seats] + 2;
$my_height = $lab[places] + 1;
$my_length = $my_height * $my_width;
list($t_date,$t_hour) = split(" ",$lab[starts]);
list($t_year,$t_mon,$t_day) = split("-",$t_date);
$t_date = mktime(0,0,0,$t_mon,$t_day,$t_year);
list($t_hour,$t_minute,$t_sec) = split(":",$t_hour);
$t_int = $lab[inter];
$t_min = $lab[session];
$t_pause = $lab[pause];
// figure out days jump;
$my_jump = 10;
while( $my_jump < $my_length ) { $my_jump *= 10; }
// create CSS hash
$css[0] = "tbl9L";
$css[1] = "tbl9R";
for ( $i = 2; $i < $lab[seats] ; $i++ ) { $css[$i] = "tbl9M"; }
}
else // of fetch_array
die("<p class=err0><b>Error! could not get data for event by id</b></p>\n");
}
else // of mysql_query
die("<p class=err0><b>Error! " . mysql_error() . "</b> (while trying to fetch event by id)</p>\n");
}
if( isset($submit) )
{
if( isset($id) && isset($pass) )
{
//$l = getLogin( $id, $pass );
$l = call_user_func($lab[func], $id, $pass );
if( strlen($l) < 1 )
{
unset($id);
unset($pass);
unset($l);
$badlogon = "Information supplied is incorrect.";
} else {
$l = Heb($l);
}
}
if( $submit != "Yes" )
{
// do time calcs
if( isset($index) && is_numeric($index) ) $submit = $index;
$j = (int) ($submit / $my_jump);
$j2 = $submit % $my_jump;
$tt = (int) (($j2 % $my_width - 1) / $lab[seats]);
$add_hr = (int) ($t_min / 60);
$add_min = $t_min % 60;
$pause_hr = (int) ($t_pause / 60);
$pause_min = $t_pause % 60;
$hr1 = $t_hour + ($add_hr + $pause_hr)*$tt;
$min1 = $t_minute + ($add_min + $pause_min)*$tt;
if( $min1 > 59 )
{
$conv = (int) ($min1 / 60);
$min1 = $min1 % 60;
$hr1 += $conv;
}
$hr1 = $hr1 % 24;
$hr2 = $hr1 + $add_hr;
$min2 = $min1 + $add_min;
if( $min2 > 59 )
{
$conv = (int) ($min2 / 60);
$min2 = $min2 % 60;
$hr2 += $conv;
}
$hr2 = $hr2 % 24;
$pp = (int) ($j2 / $my_width);
$pl = (int) (($j2 % $my_width - 1) % $lab[seats]);
$pl++;
// center all
echo "<center>\n";
echo "<form method=post action=\"$SCRIPT_NAME\">\n";
if( isset($badlogon) ) { echo "<p class=err0><b>$badlogon</b></p>\n"; }
echo "<input type=hidden name=index value=\"$submit\">\n";
echo "<input type=hidden name=labID value=\"$labID\">\n";
// get login info
echo "<table border=0 cellspacing=0 cellpadding=2>\n";
echo "<tr align=center bgcolor=$ars[titleBG]>\n";
echo " <td colspan=2 class=tbl10w><b>Register To: "";
echo isset($lab[title])?"$lab[title]":"Unknown Event";
echo ""</b></td>\n";
echo "</tr>\n";
echo "<tr align=center bgcolor=#8080FF>\n";
echo " <td class=tbl10w align=right>Target Date:</td>\n";
printf(" <td class=tbl10w><b>%s</b></td>\n",date("l, F jS Y",$t_date + $j*$t_int*86400));
echo "</tr>\n";
echo "<tr align=center bgcolor=#8080FF>\n";
echo " <td class=tbl10w align=right>Target Time:</td>\n";
printf(" <td class=tbl10w><b>%02d:%02d - %02d:%02d</b></td>\n",$hr1, $min1,$hr2, $min2);
echo "</tr>\n";
echo "<tr align=center bgcolor=#8080FF>\n";
echo " <td class=tbl10w align=right>Target Place:</td>\n";
printf(" <td class=tbl10w><b>%d (%d/%d)</b></td>\n",$pp,$pl,$lab[seats]);
echo "</tr>\n";
// display logon request
if( empty($id) && empty($pass) )
{
echo "<tr align=center bgcolor=#A0A0FF>\n";
echo " <td colspan=2 class=tbl10w>";
if( isset($lab[POPtitle]) && strlen($lab[POPtitle]) )
echo $lab[POPtitle];
else
echo $ars[pop];
echo "</td>\n";
echo "</tr>\n";
echo "<tr align=center bgcolor=#A0A0FF>\n";
echo " <td class=tbl10w align=right><b>";
if( strlen($lab[POP1]) )
echo $lab[POP1];
else
echo $ars[first];
echo "</b></td>\n";
echo " <td class=tbl10w><input type=text name=id size=15 maxlength=12 class=btn9></td>\n";
echo "</tr>\n";
echo "<tr align=center bgcolor=#A0A0FF>\n";
echo " <td class=tbl10w align=right><b>";
if( strlen($lab[POP2]) )
echo $lab[POP2];
else
echo $ars[second];
echo "</b></td>\n";
echo " <td class=tbl10w><input type=";
if( isset($lab[isPass]) && $lab[isPass] != 1 )
echo "text";
else
echo "password";
echo " name=pass size=15 maxlength=50 class=btn9></td>\n";
echo "</tr>\n";
echo "<tr align=center bgcolor=#A0A0FF>\n";
echo " <td colspan=2 class=tbl9>\n";
echo " <input type=submit name=submit value=\"Login\" class=btn10w> \n";
echo " <input type=reset value=\"Close\" class=btn10w onClick=\"window.close();\"></td>\n";
echo "</tr>\n";
}
else
{
// Add a new entry
if( isset($id) )
{
echo "<input type=hidden name=id value=\"$id\">\n";
echo "<input type=hidden name=pass value=\"$pass\">\n";
}
echo "<tr align=center bgcolor=#A0A0FF>\n";
echo " <td class=tbl10w colspan=2><b>Hello $l</b></td>\n";
echo "</tr>\n";
echo "<tr align=center bgcolor=#A0A0FF>\n";
echo " <td class=tbl10w colspan=2><b>Are you <u>sure</u> you want to register?</b></td>\n";
echo "</tr>\n";
echo "<tr align=center bgcolor=#A0A0FF>\n";
echo " <td class=tbl10w colspan=2>\n";
echo " <input type=submit name=submit value=\"Yes\" class=btn10w> \n";
echo " <input type=reset value=\"No\" onClick=\"window.close();\" class=btn10w>\n";
echo " </td>\n";
echo "</tr>\n";
}
//close table
echo "</table>\n";
echo "</form>\n";
die("</html>\n");
}
else
{
// register the user
if( isset($l) && isset($id) && isset($index) && isset($labID) )
{
$db =mysql_pconnect($ars[host],$ars[user],$ars[pass]);
mysql_select_db($ars[dbname],$db);
// get the table data
if( $res = mysql_query("select name,multi,closed,mother from labs where id = \"$labID\"") )
{
if( ! $mylab = mysql_fetch_array($res) )
die("<p class=err0><b>Query returned bad data: " . mysql_error() . "</b></p>\n</body></html>\n");
}
else
die("<p class=err0><b>Could not get table data: " . mysql_error() . "</b></p>\n</body></html>\n");
// check if lab is closed
if( $mylab[closed] )
{
echo "<center><p class=err0><b>This event is closed for registration.<br></b>\n";
echo " If you have any questions contact <a href=\"mailto:$mylab[mother]\">$mylab[mother]</a>\n";
die("</p></body></html>");
}
// check that number of times registered is as allowed
//$IntID = (int) $id;
//echo "<!-- ID: $id cast: $IntID lab: $labID -->\n";
if( $mylab[multi] != "0" && $res = mysql_query("select count(id) as x from $mylab[name] where id = \"$id\"") )
{
if( ($row = mysql_fetch_array($res)) && ($row[x] >= $mylab[multi]) )
{
echo "<center><p class=err0>\n";
if( $mylab[multi] == 1 )
echo " <b>You are already registered for this event.<br>You are allowed to register only <u>once</u>.<br>\n";
else
echo " <b>You have passed your registration quota for this event.<br><u>$mylab[multi]</u> entries are allowed (total).<br>\n";
echo " If you have any questions contact <a href=\"mailto:$mylab[mother]\">$mylab[mother]</a>\n";
die("</p></body></html>");
}
}
// register the user
//echo "<!-- XXX $row[x] -->\n";
if( mysql_query("insert into $mylab[name] set place=\"$index\", id=\"$id\", name=\"$l\"") )
{
echo "<p class=err1><b>Registration succeeded</b></p>\n";
}
else
{
echo "<p class=err0>Registration Failed. " . mysql_error() . " </p>\n";
}
// close HTML
echo "<script language=\"JavaScript\"><!--\n";
echo "opener.location.reload();\n";
echo "setTimeout(\"window.close();\",3000);\n";
echo "--></script>\n";
die("</body></html>\n");
} // if 4 x isset()
} // else of registration
} // if isset-submit
// time to get lab data
if( isset($labID) && is_numeric($labID) )
{
$db = mysql_pconnect($ars[host],$ars[user],$ars[pass]);
mysql_select_db($ars[dbname],$db);
if( $res = mysql_query("select name,closed from labs where id = \"$labID\"") )
{
$mylab = mysql_fetch_array($res);
if( empty($mylab[name]) || strlen($mylab[name]) < 1 )
die("<center><p class=err0><b>Error, can't get event name: " . mysql_error() . "</b></p></body></html>\n");
}
else
die("<center><p class=err0><b>Error, can't get event name: " . mysql_error() . "</b></p></body></html>\n");
if( $res = mysql_query("select * from $mylab[name]") )
{
while( $row = mysql_fetch_array($res) )
$name[$row[place]] = $row[name];
}
else
die("<center><p class=err0><b>Error, can't get registrant data for Lab$labID: " . mysql_error() . "</b></p></body></html>\n");
}
// start displaying the lab
if( isset($lab[title]) )
{
// display lab's title
echo "<table border=1 cellspacing=0 cellpadding=2 bordercolor=black bgcolor=$ars[titleBG] width=\"100%\">\n";
echo "<tr align=center><td class=tbl10w><b>$lab[title]</b></td></tr>\n";
echo "</table><br>\n";
}
if( isset($lab[header]) && $lab[header] != "" )
{
// display header in a black box
echo "<center>\n";
echo "<table border=1 cellspacing=0 cellpadding=4 bordercolor=black class=tbl9>\n";
echo "<tr><td>\n";
echo $lab[header];
echo "</td></tr>\n";
echo "</table>\n";
echo "</center>\n";
}
// display closed message if needed
if( $mylab[closed] )
echo "<center><p class=err0><b>Event is closed for registration</b></p></center>\n";
// days loop
for ( $j = 0; $j < $lab[repeat]; $j++ )
{
$pad = $j * $my_jump;
echo "<br><center>\n";
echo "<table border=1 cellspacing=0 cellpadding=2 bordercolor=black>\n";
echo "<tr align=center bgcolor=$ars[titleBG]>\n";
printf(" <td class=tbl9 colspan=\"%d\"><b>%s</b></td>\n",$my_width,date("l, F jS Y",$t_date + 86400*$j*$t_int));
echo "</tr>\n";
echo "<tr align=center bgcolor=$ars[titleBG]>\n";
echo " <td class=tbl9> </td>\n";
$add_hr = (int) ($t_min / 60);
$add_min = $t_min % 60;
$pause_hr = (int) ($t_pause / 60);
$pause_min = $t_pause % 60;
$hr1 = $t_hour;
$min1 = $t_minute;
for( $i = 0; $i < $lab["class"]; $i++ )
{
$hr2 = $hr1 + $add_hr;
$min2 = $min1 + $add_min;
if( $min2 > 59 )
{
$conv = (int) ($min2 / 60);
$min2 = $min2 % 60;
$hr2 += $conv;
}
$hr2 = $hr2 % 24;
printf(" <td class=tbl9 colspan=%d><b>%02d:%02d - %02d:%02d</b></td>\n",$lab[seats],$hr1,$min1,$hr2,$min2);
// prepare for next interval
$hr1 = $hr2 + $pause_hr;
$min1 = $min2 + $pause_min;
if( $min1 > 59 )
{
$conv = (int) ($min1 / 60);
$min1 = $min1 %60;
$hr1 += $conv;
}
$hr1 = $hr1 % 24;
}
echo " <td class=tbl9> </td>\n";
echo "</tr>\n";
// one table loop = one lab
for ( $i = $my_width; $i < $my_length; $i++ )
{
if( ($i % $my_width) == 0 )
{
echo "<tr align=center>\n";
printf(" <td class=tbl9>#%d</td>\n",$i/$my_width);
continue;
}
if( ($i % $my_width ) == ($my_width - 1) )
{
printf(" <td class=tbl9>#%d</td>\n",$i/$my_width);
echo "</tr>\n";
continue;
}
// print data
$c = ($i % $my_width) % $lab[seats];
if( isset( $name[$i+$pad] ) )
printf(" <td class=%s width=120>%s</td>\n",$css[$c],$name[$i+$pad]);
elseif ( isset($mylab[closed]) && $mylab[closed] == 1 )
printf(" <td class=%s width=120> </td>\n",$css[$c]);
else
printf(" <td class=%s width=120 id=\"lab%d\" %s> </td>\n",$css[$c],$i+$pad,OC($i+$pad));
} // end for of lab loop
echo "</table>\n</center><br>\n";
} // end for of days loop
if( isset($lab[footer]) && $lab[footer] != "" )
{
// display footer in a black box
echo "<center>\n";
echo "<table border=1 cellspacing=0 cellpadding=4 bordercolor=black class=tbl9>\n";
echo "<tr><td>\n";
echo $lab[footer];
echo "</td></tr>\n";
echo "</table>\n";
echo "</center>\n";
}
if( empty($labID) )
{
$db = mysql_pconnect($ars[host],$ars[user],$ars[pass]);
mysql_select_db($ars[dbname],$db);
if( isset($cat) && is_numeric($cat) )
{
// get a specific category only
$wh = "where cat = $cat";
}
else
{
$title = "<p class=adm9 align=center><u>Current Self Registration Events running on this server:</u><br></p>\n";
}
if( $res = mysql_query("select id,title,cat,closed,info from labs inner join category on cat = cid $wh order by cat,closed") )
{
echo $title;
echo "<center>\n";
echo "<table border=1 cellspacing=0 cellpadding=4 bordercolor=\"#000080\">\n";
echo "<tr class=adm9b>\n";
echo " <td>Event Description</td>\n";
echo " <td>Status</td>\n";
echo "</tr>\n";
$myCat = "";
$i = 0;
while( $row = mysql_fetch_array($res) )
{
if( isset($open) && $row[closed] ) continue;
if( $row[info] != $myCat )
{
echo "<tr>\n";
echo " <td colspan=2 class=adm9b>Events in category: "<a href=\"$SCRIPT_NAME?cat=$row[cat]\">$row[info]</a>"</td>\n";
echo "</tr>\n";
$myCat = $row[info];
}
echo "<tr>\n";
if( $row[closed] == 0 )
{
echo " <td class=adm9><a href=\"$SCRIPT_NAME?labID=$row[id]\">$row[title]</a></td>\n";
echo " <td class=adm9>Open</td>\n";
}
else
{
echo " <td class=adm9>$row[title]</td>\n";
echo " <td class=adm9>Closed</td>\n";
}
$i++;
}
echo "<tr>\n";
echo " <td colspan=2 align=center class=adm9b>";
if( $i > 0 )
echo "$i events displayed";
else
echo "No events to display";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
if( empty($open) )
echo "<br><font class=\"adm9\"><a href=\"$SCRIPT_NAME?open=1&cat=$cat\">Click here to view open events only</a></font>\n";
echo "</center>\n";
}
else
die("<b>Could not get event list: " . mysql_error() . "</b>\n");
echo "<p class=adm9b align=center> Event Admin: <a href=\"mailto:$ars[admin]\">$ars[admin]</a></p>\n";
}
?>
</p>
</body>
</html>