/**
 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
 * all the essential functionalities required for any enterprise.
 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
 *
 * OrangeHRM 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.
 *
 * OrangeHRM 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
 *
 */
function populateActivities($projectId, $activityId = -1)
{
    ob_clean();
    require ROOT_PATH . '/language/default/lang_default_full.php';
    $timeController = new TimeController();
    $projectActivities = $timeController->fetchProjectActivities($projectId);
    $objResponse = new xajaxResponse();
    $xajaxFiller = new xajaxElementFiller();
    $element = "cmbActivity";
    if (count($projectActivities) == 0) {
        $projectActivities[0][0] = -1;
        $projectActivities[0][1] = "- {$lang_Time_Timesheet_SelectProjectFirst} -";
        $objResponse = $xajaxFiller->cmbFillerById($objResponse, $projectActivities, 0, 'frmTimesheet', $element, 0);
    } else {
        if ($activityId != -1) {
            $projectActivityObject = new ProjectActivity();
            if ($projectId == $projectActivityObject->retrieveActivityProjectId($activityId)) {
                $activityExists = false;
                $i = 0;
                foreach ($projectActivities as $activity) {
                    if ($activity[$i][0] == $activityId) {
                        $activityExists = true;
                    }
                    $i++;
                }
                if (!$activityExists) {
                    $count = count($projectActivities);
                    $projectActivities[$count][0] = $activityId;
                    $projectActivities[$count][1] = $projectActivityObject->retrieveActivityName($activityId);
                }
            }
        }
        $objResponse->addScript("document.getElementById('" . $element . "').options.length = 0;");
        $objResponse->addScript("document.getElementById('" . $element . "').options[0] = new Option('- {$lang_Common_Select} -','-1');");
        $objResponse = $xajaxFiller->cmbFillerById($objResponse, $projectActivities, 0, 'frmTimesheet', $element, 1);
    }
    $objResponse->addScript('document.getElementById("' . $element . '").focus();');
    $objResponse->addAssign('status', 'innerHTML', '');
    return $objResponse->getXML();
}
</th>
			<th class="tableMiddleRight"></th>
		</tr>
	</thead>
	<tbody>
		<?php 
$customerObj = new Customer();
$projectObj = new Projects();
$projectActivityObj = new ProjectActivity();
if (isset($timeExpenses) && is_array($timeExpenses)) {
    foreach ($timeExpenses as $timeExpense) {
        $projectId = $timeExpense->getProjectId();
        $projectName = $projectObj->retrieveProjectName($projectId);
        $customerName = $projectObj->retrieveCustomerName($projectId);
        $activityId = $timeExpense->getActivityId();
        $activityName = $projectActivityObj->retrieveActivityName($activityId);
        $projectDet = $projectObj->fetchProject($projectId);
        $projectActivities = $projectActivityObj->getActivityList($projectId);
        ?>
			<tr id="row[<?php 
        echo $row;
        ?>
]">
				<td class="tableMiddleLeft"></td>
				<td ><input type="checkbox" id="deleteEvent[]" name="deleteEvent[]" value="<?php 
        echo $timeExpense->getTimeEventId();
        ?>
" /></td>
				<td ><select id="cmbProject[<?php 
        echo $row;
        ?>