echo $friend["hebBirthday"];
    ?>
</td><td><?php 
    echo $friend["dateThisYear"];
    ?>
</td>
                </tr><?php 
}
?>
        </table>
    	<b><u>Your friends special dates in the coming week:</u></b>
        <table>
            <tr><th>Name</th><th>Event</th><th>Hebrew Date</th><th>Next Occurance</th></tr>
        <?php 
$friendlist = $_REQUEST['fb_sig_friends'];
$specialDays = DateRecord::findByWhere('DateRecord', "uid in({$friendlist})");
foreach ($specialDays as $friend) {
    if (strtotime($friend->getNextOccurance()) > strtotime('+1 week')) {
        break;
    }
    ?>
<tr>
                	<td  width='200'>
                    	<a href="moreDates/?action=index&uid=<?php 
    echo $friend->data["uid"];
    ?>
">
                    	<fb:name uid='<?php 
    echo $friend->data["uid"];
    ?>
' capitalize='true' shownetwork='true' />
for ($i = 0; $i < 70; $i++) {
    $cdate = date("Y-m-d", strtotime(jdtogregorian(jewishtojd($aTodayHebrew[0], $aTodayHebrew[1], $aTodayHebrew[2] - $i))));
    $cDates[$i] = $cdate;
}
$cDatesStr = join("','", $cDates);
$iLimit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 0;
$iStopLimit = isset($_REQUEST['toLimit']) ? $_REQUEST['toLimit'] : 300;
$i = 0;
$actualPosts = 0;
?>
<h1><a href="?limit=<?php 
echo $iLimit + $iStopLimit;
?>
">Next -></a></h1><?php 
flush();
$specialDays = DateRecord::findByWhere('DateRecord', "originalDate in('{$cDatesStr}') LIMIT  {$iLimit}, {$iStopLimit}");
print_r_debug($specialDays);
foreach ($specialDays as $rs) {
    $userRecord = $rs->getUserRecord();
    $facebook->user = $rs->data['uid'];
    $facebook->api_client->session_key = $userRecord->data['sessionId'];
    try {
        generateAndPublishFeed($rs);
        $i++;
    } catch (FacebookRestClientException $e) {
        print_r($e);
    }
    if ($i % 20 == 0) {
        ob_flush();
        flush();
    }
            $nextAction = 'create';
        }
        break;
    case 'edit':
        $rec = DateRecord::findById('DateRecord', $_REQUEST['id']);
        $nextAction = "update";
        if (!$rec) {
            $action = 'show';
        }
        break;
    case 'update':
        $rec = DateRecord::findById('DateRecord', $_REQUEST[$_REQUEST['hashNameSpace'] . 'id']);
        $rec->update($_REQUEST);
        if ($rec->save()) {
            updateJDateProfile(false);
            $action = 'show';
        } else {
            $action = 'edit';
            $nextAction = 'update';
        }
        break;
    case 'delete':
        $rec = DateRecord::findById('DateRecord', $_REQUEST['id']);
        if ($rec && $rec->delete()) {
            updateJDateProfile(false);
            actionRedirect('index');
        }
        $action = 'show';
        break;
}
include 'views/template.php';
function updateJDateProfile($updateDB = true)
{
    global $facebook;
    global $bBornAfterSunset, $profileDesign, $displayCurrent, $displayLink, $birthday, $success;
    dbConnect();
    if (isset($_POST["Submit"]) && $_POST["Submit"] == "Submit" && $updateDB) {
        $strBornAfterSunset = "";
        if (isset($_POST["chkSunset"]) && $_POST["chkSunset"] == "on") {
            $strBornAfterSunset = "true";
        } else {
            $strBornAfterSunset = "false";
        }
        $profileDesign = isset($_POST["profileDesign"]) ? $_POST["profileDesign"] : 1;
        $displayCurrent = isset($_REQUEST["chkToday"]);
        $displayLink = isset($_REQUEST["chkExplanation"]);
        $sql = "UPDATE fbJewishDates SET BornAtNight={$strBornAfterSunset}, style={$profileDesign}, displayLink='{$displayLink}', displayCurrent='{$displayCurrent}' WHERE uid={$facebook->user}";
        mysql_query($sql) or die("You must un-install and re-install this app");
        $success = true;
    }
    $sql = "SELECT BornAtNight, Birthday, style, displayCurrent, displayLink FROM fbJewishDates WHERE uid='{$facebook->user}'";
    $results = mysql_query($sql);
    if (!($rs = mysql_fetch_assoc($results))) {
        addBirthdayRecord();
        $results = mysql_query($sql);
        $rs = mysql_fetch_assoc($results);
    }
    mysql_close();
    $bBornAfterSunset = $rs['BornAtNight'];
    $profileDesign = $rs['style'];
    $displayCurrent = $rs['displayCurrent'];
    $displayLink = $rs['displayLink'];
    $birthday = date("M d, Y", strtotime($rs['Birthday']));
    //$userInfo = $facebook->api_client->fql_query("SELECT birthday FROM user WHERE uid=$user");
    //$birthday = $userInfo[0]['birthday'];
    $fbml = printJewishBirthday($birthday, $bBornAfterSunset, $profileDesign, $displayCurrent, $displayLink);
    $mobileFBML = $fbml;
    $mainFBML = $fbml;
    $ahebdate = explode("/", strGregToHeb($birthday, false, $bornAtNight));
    $info_fields = array(array('field' => 'My Hebrew Birthday', 'items' => array(array('label' => strGregToHeb($birthday, true, $bBornAfterSunset), 'description' => 'A kabbalisticly powerful day.', 'link' => 'http://apps.facebook.com/jewishdates/'))), array('field' => 'Next Occurence', 'items' => array(array('label' => dateThisYear($ahebdate), 'description' => 'The next gregorian date that will corespond with my Hebrew Birthday', 'link' => 'http://apps.facebook.com/jewishdates/'))));
    $moreFBML = '<b><u>Special Dates</u></b><br />';
    $specialDays = DateRecord::findByWhere('DateRecord', "uid={$facebook->user}");
    foreach ($specialDays as $friend) {
        $moreFBML .= '<div><b>' . $friend->data['title'] . ':</b>' . $friend->getHebrewDate('longeng') . ' - ' . $friend->getNextOccurance() . '</div>';
        $info_fields[] = array('field' => $friend->data['title'], 'items' => array(array('label' => $friend->getHebrewDate('longeng'), 'description' => 'Hebrew Date', 'link' => 'http://apps.facebook.com/jewishdates/'), array('label' => 'Next Occurance: ' . $friend->getNextOccurance(), 'description' => 'Gregorian Date this coming year', 'link' => 'http://apps.facebook.com/jewishdates/')));
    }
    $facebook->api_client->profile_setFBML($fbml . $moreFBML, $facebook->profileID, $fbml . $moreFBML, NULL, $mobileFBML, $mainFBML);
    $facebook->api_client->profile_setInfo('Jewish Dates', 1, $info_fields, $user);
    $refValue = "Todays Hebrew Date is:<br />" . strGregToHeb(date("M d, Y"), true);
    $facebook->api_client->fbml_setRefHandle("Today_H", $refValue);
    $facebook->api_client->fbml_setRefHandle("Message", "<fb:subtitle><a href='http://apps.facebook.com/jewishdates/'>Add this to my profile.</a></fb:subtitle>");
    //<div style='text-align:center;color:red;'>Help 'Jewish Dates'.<br />Support <a href='http://apps.facebook.com/jewishdates/supportChabadOfNewPaltz'>Chabad of New Paltz</a><hr /></div>
    $facebook->api_client->fbml_setRefHandle("Explanation", "<a href='http://www.chabad.org/library/article.asp?AID=144345'>What is a Jewish Birthday?</a>");
}