I have been throgh this code upside down, backwards, forwards, commented out sections, and just cannot seem to see where my misplaced bracket might be. It was working really well a day or so ago, and somehow I broke it...
The specific error I am getting is:
Parse error: parse error, unexpected $ in /my/path/is/here/dotinfo/ref_availability.php on line 458
Line 458 is the last line after the trailing ?>
I commented out a number of sections to see if I can narrow down the issue, and I've determined that the offending code may be somewhere in the [red]colored[/red] section. When I comment out the red section, it runs without seeing the parse error.
Each of the functions at the top of the page seem to check out (e.g. I comment out each function between the curly braces, and i get the same error)
----------
Jeff Wigal
Referee Assistant for MS Access
The specific error I am getting is:
Parse error: parse error, unexpected $ in /my/path/is/here/dotinfo/ref_availability.php on line 458
Line 458 is the last line after the trailing ?>
I commented out a number of sections to see if I can narrow down the issue, and I've determined that the offending code may be somewhere in the [red]colored[/red] section. When I comment out the red section, it runs without seeing the parse error.
Each of the functions at the top of the page seem to check out (e.g. I comment out each function between the curly braces, and i get the same error)
Code:
<?php
require_once('includes/header.php');
require_once('includes/htmlheader.php');
require_once('HTML/QuickForm.php');
require_once "Auth.php";
require_once 'Calendar/Month/Weekdays.php';
require_once "MDB.php";
require_once 'Date.php';
function series_avail ($values) {
$db = MDB::connect(PGSQL_REFASST);
if (MDB::isError($db)) {
echo "DSN " . $pgsql_refasst;
die ($db->getMessage());
}
print_r($values);
$date = array('Y' => $values['startdate']['Y'],
'M' => $values['startdate']['M'],
'd' => $values['startdate']['d']);
$enddate = array('Y' => $values['enddate']['Y'],
'M' => $values['enddate']['M'],
'd' => $values['enddate']['d']);
print_r($date);
$d = new Date_Calc();
$iterations = 0;
$sql = "insert into dotinfo_availability (availability_customer_id, availability_referee_id, ".
"availability_date, availability_start_time, availability_end_time) ".
"values ( ".getCustomerID($values['user']).", "
.getRefereeID($values['user']).", '"
. $date['Y']."-". $date['M']."-". $date['d']."', '"
.$values['starttime']['h'] .":".$values['starttime']['i']."', '"
.$values['endtime']['h'] .":".$values['endtime']['i']."')";
echo "<br><br>".$sql."\r";
while (mktime(0,0,0,$date['M'],$date['d'],$date['Y']) <=
mktime(0,0,0,$enddate['M'],$enddate['d'],$enddate['Y'])
and $iterations <100) {
$iterations = $iterations +1;
$sql = "insert into dotinfo_availability (availability_customer_id, availability_referee_id, ".
"availability_date, availability_start_time, availability_end_time) ".
"values ( ".getCustomerID($values['user']).", "
.getRefereeID($values['user']).", '"
. $date['Y']."-". $date['M']."-". $date['d']."', '"
.$values['starttime']['h'] .":".$values['starttime']['i']."', '"
.$values['endtime']['h'] .":".$values['endtime']['i']."')";
switch ($values['frequency']) {
case '7':
echo "<br><br>".$sql;
echo "<br>EXECUTE.<br>";
$res = $db->query($sql);
if (MDB::isError($db)) {
echo "INSERT error:" . $db->getMessage();
}else{
echo "<p>Record inserted successfully.</p>";
}
break;
case '1':
// if current date meets criteria, execute sql
echo "<br><br>".$sql;
if ($d->dayOfWeek($date['d'],$date['M'],$date['Y']) == $values['weekday']) {
$res = $db->query($sql);
if (MDB::isError($db)) {
echo "INSERT error:" . $db->getMessage();
}else{
echo "<p>Record inserted successfully.</p>";
}
}else{
echo "<br>SKIP.<br>";
}
break;
case '5':
// if current date meets criteria, execute sql
echo "<br><br>".$sql;
if ($d->dayOfWeek($date['d'],$date['M'],$date['Y']) == 0
OR $d->dayOfWeek($date['d'],$date['M'],$date['Y']) == 6) {
echo "<br>SKIP.<br>";
}else{
$res = $db->query($sql);
if (MDB::isError($db)) {
echo "INSERT error:" . $db->getMessage();
}else{
echo "<p>Record inserted successfully.</p>";
}
}
break;
} //end switch
//move next
$date = array('Y'=> $d->nextDay($date['d'],$date['M'],$date['Y'],"%Y"),
'M'=> $d->nextDay($date['d'],$date['M'],$date['Y'],"%m"),
'd' =>$d->nextDay($date['d'],$date['M'],$date['Y'],"%e")
);
}// end while
}
function insert_avail ($values) {
$db = MDB::connect(PGSQL_REFASST);
if (MDB::isError($db)) {
echo "DSN " . $pgsql_refasst;
die ($db->getMessage());
}
$starttime = "";
$endtime = "";
if ($values['starttime']['A'] == 'AM'){
$starttime .= $values['starttime']['h'];
}else{
$starttime .= $values['starttime']['h']+12;
}
if ($values['endtime']['A'] == 'AM'){
$endtime .= $values['endtime']['h'];
}else{
$endtime .= $values['endtime']['h']+12;
}
$starttime .= ":" . $values['starttime']['i'];
$endtime .= ":" . $values['endtime']['i'];
$availdate = $values['mydate']['Y'] . "-" .$values['mydate']['M']. "-" .$values['mydate']['d'];
$sql = "INSERT INTO dotinfo_availability (availability_referee_id, availability_customer_id, "
."availability_date, availability_start_time, availability_end_time) "
. "VALUES (" . getRefereeID($values['user']) . ", "
. getCustomerID($values['user'])
. ", '$availdate','$starttime','$endtime')";
echo "<br><br>".$sql;
print_r($values['starttime'] );
print_r($values['endtime'] );
print_r($values['mydate'] );
$res = $db->query($sql);
if (MDB::isError($db)) {
echo "INSERT error:" . $db->getMessage();
}else{
echo "<p>Record inserted successfully.</p>";
}
}
function AddEntryFromCalendar($month, $day, $year, $customerid, $refid) {
$db = MDB::connect(PGSQL_REFASST);
if (MDB::isError($db)) {
echo "DSN " . $pgsql_refasst;
die ($db->getMessage());
}
$sql = "INSERT INTO dotinfo_availability (availability_referee_id, availability_customer_id, "
."availability_date, availability_start_time, availability_end_time) "
."VALUES ($refid, $customerid, '$year-$month-$day', '00:01:00','23:59:00')";
//echo "<br><br>".$sql;
$res = $db->query($sql);
if (MDB::isError($db)) {
echo "INSERT error:" . $db->getMessage();
}else{
echo "<p>Record inserted successfully.</p>";
}
}
function RemoveEntryFromCalendar($month, $day, $year, $customerid, $refid) {
$db = MDB::connect(PGSQL_REFASST);
if (MDB::isError($db)) {
echo "DSN " . $pgsql_refasst;
die ($db->getMessage());
}
$sql = "DELETE FROM dotinfo_availability WHERE availability_date = '$year-$month-$day' "
."AND availability_customer_id = $customerid "
."AND availability_referee_id = $refid";
//echo "<br><br>".$sql;
$res = $db->query($sql);
if (MDB::isError($db)) {
echo "DELETE error:" . $db->getMessage();
}else{
echo "<p>Record removed successfully.</p>";
}
}
$a = new Auth("DB", unserialize(AUTH_PARAM_ARRAY));
$a->start();
if ($logout =="1") {
//echo "logout called";
$a->logout();
$a->start();
}
if ($a->checkAuth()) {
/*
* The output of your site goes here.
*/
if ($action=="add") {
AddEntryFromCalendar ($month, $day, $year,
getcustomerID($a->getUserName()),
getrefereeID ($a->getUserName()) );
}
if ($action=="remove") {
RemoveEntryFromCalendar ($month, $day, $year,
getcustomerID($a->getUserName()),
getrefereeID ($a->getUserName()) );
}
echo "<h2>This is the ref availability page.</h2>";
$customerid = getcustomerID($a->getUserName());
$RefID = getrefereeID($a->getUserName());
$db = MDB::connect(PGSQL_REFASST);
if (MDB::isError($db)) {
echo "DSN " . $pgsql_refasst;
die ($db->getMessage());
}
$sql = "SELECT DISTINCT availability_date FROM dotinfo_availability "
."WHERE availability_start_time = '00:01:00' "
."AND availability_end_time = '23:59:00' "
."AND availability_referee_id = $RefID "
."AND availability_customer_id = $customerid";
//echo "<br><br>".$sql;
$res = $db->query($sql);
if (MDB::isError($db)) {
echo "allday error:" . $db->getMessage();
}
$avail_allday = $db->fetchCol($res);
echo "<!-- ";
print_r($avail_allday);
echo "-->";
$sql = "SELECT DISTINCT availability_date FROM dotinfo_availability "
."WHERE (availability_start_time <> '00:01:00' "
."OR availability_end_time <> '23:59:00' ) "
."AND availability_referee_id = $RefID "
."AND availability_customer_id = $customerid";
//echo "<br><br>".$sql;
$res = $db->query($sql);
if (MDB::isError($db)) {
echo "partial day error:" . $db->getMessage();
}
$avail_part_day = $db->fetchCol($res);
echo "<!-- ";
print_r($avail_part_day);
echo "-->";
echo "<center><table><tr valign=\"top\">";
[red]for ($i = 0; $i <= 5 ; $i++) { //start six calendar for loop
echo "<td>";
if (date('n') + $i > 12 ){
$dayuse = mktime(0,0,0,date('n')-12 + $i,1,date('Y')+1);
}else{
$dayuse = mktime(0,0,0,date('n') + $i ,1,date('Y'));
}
$Month = new Calendar_Month_Weekdays(date('Y',$dayuse), date('n',$dayuse),0);
$Month->build();
echo "<!-- ";
print_r($Month);
echo "-->";
echo "<b>".date("M Y", $dayuse)."</b><br>";
echo "<table border = \"1\">\n";
echo "<tr><td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td>";
while ($Day = $Month->fetch() ) {
if ($Day->isFirst() ) {
echo "<tr>\n";
}
if ($Day->isEmpty() ) {
echo "<td> </td>\n";
} else {
echo "<td><a href=\"ref_availability.php?day=". $Day->thisDay();
echo "&month=".date("n",$dayuse);
echo "&year=".date("Y",$dayuse);
echo "&action=add";
echo "\"><b>";
echo $Day->thisDay()."</b></a><br> ";
if ($Day->ThisMonth() < 10) {
$tmpMonth= "0" . $Day->ThisMonth();
}else{
$tmpMonth= $Day->ThisMonth();
}
if ($Day->ThisDay() < 10) {
$tmpDay= "0" . $Day->ThisDay();
}else{
$tmpDay= $Day->ThisDay();
}
if (
array_search(
$Day->thisYear() . "-".$tmpMonth."-".$tmpDay,$avail_allday)
) {
echo "<a href=\"ref_availability.php?day=". $Day->thisDay();
echo "&month=".date("n",$dayuse);
echo "&year=".date("Y",$dayuse);
echo "&action=remove";
echo "\">X</a> ";
}
if (array_search(
$Day->thisYear() . "-".$tmpMonth."-".$tmpDay,$avail_part_day)) {
echo "+";
}
echo "</td>\n";
}//end isempty else
`
if ($Day->isLast()) {
echo "</tr>\n";
}
}; //end single month calendar 'while loop'
echo "</table>\n";
echo "</td>";
if ($i == 2 ){
echo "</tr><tr valign=\"top\">";
}
}//end six calendars 'for loop'
[/red]
echo "</tr></table></center>";
$options = array(
'language' => 'en',
'format' => 'dMY',
'minYear' => date('Y'),
'maxYear' => date('Y') +1
);
$options_time = array(
'language' => 'en',
'format' => 'hiA'
);
$date_defaults = array(
'd' => date('d'),
'M' => date('n'),
'Y' => date('Y')
);
$start_defaults = array(
'h' => 1,
'i' => 0,
'A' => 'AM'
);
$end_defaults = array(
'h' => 11,
'i' => 00,
'A' => 'PM'
);
$form = new HTML_QuickForm('frmAddAvailability', 'post');
$form->addElement('header', 'MyHeader', 'Add Availability');
$form->setDefaults(
array('mydate' => $date_defaults,
'starttime' =>$start_defaults,
'endtime' => $end_defaults,
'mydate' => $options,
'user' => $a->getUserName() )
);
$form->addElement('date', 'mydate', 'Choose date', $options);
$form->addElement('date', 'starttime', 'Start Time',$options_time);
$form->addElement('date', 'endtime', 'End Time',$options_time);
$form->addElement('submit', 'btnSubmit', 'Submit');
$form->addElement('hidden', 'user');
if ($form->validate()) {
$form->process('insert_avail',false);
$form->setDefaults(Null);
$form->Display();
}else {
$form->display();
}
$opt_freq = array('7' => 'Daily',
'5' => 'Monday-Friday',
'1' => 'Single Weekday'
);
$opt_weekday = array ('0' => 'Sunday',
'1' => 'Monday',
'2' => 'Tuesday',
'3' => 'Wednesday',
'4' => 'Thursday',
'5' => 'Friday',
'6' => 'Saturday'
);
$form2 = new HTML_QuickForm('frmSeriesAvailability', 'post');
$form2->addElement('header', 'MyHeader', 'Add Availability');
$form2->setDefaults(
array('startdate' => $date_defaults,
'enddate' => $date_defaults,
'starttime' => $start_defaults,
'endtime' => $end_defaults,
'user' => $a->getUserName() )
);
$form2->addElement('date', 'startdate', 'Start date', $options);
$form2->addElement('date', 'enddate', 'End date', $options);
$form2->addElement('select', 'weekday', 'Weekday', $opt_weekday);
$form2->addElement('select', 'frequency', 'Frequency', $opt_freq);
$form2->addElement('date', 'starttime', 'Start Time',$options_time);
$form2->addElement('date', 'endtime', 'End Time',$options_time);
$form2->addElement('submit', 'btnSubmit', 'Submit');
$form2->addElement('hidden', 'user');
if ($form2->validate()) {
$form2->process('series_avail',false);
$form2->setDefaults(Null);
$form2->Display();
}else {
$form2->display();
}
} //end authenticated content
require_once('includes/footer.php');
require_once('includes/htmlfooter.php');
?>
----------
Jeff Wigal
Referee Assistant for MS Access