function execute()
 {
     global $g_oSession;
     $bExport = isset($_REQUEST['export']) && $_REQUEST['export'] == '1';
     if (!$bExport) {
         commonHeader();
     }
     $begindate = @DCL_Sanitize::ToDate($_REQUEST['begindate']);
     $enddate = @DCL_Sanitize::ToDate($_REQUEST['enddate']);
     if ($begindate === null || $enddate === null) {
         if ($bExport) {
             commonHeader();
         }
         trigger_error(STR_WOST_DATEERR, E_USER_ERROR);
         $this->GetParameters(false);
         return;
     }
     $g_oSession->Register('personnel_activity_begindate', $begindate);
     $g_oSession->Register('personnel_activity_enddate', $enddate);
     $g_oSession->Register('personnel_activity_bytype', $_REQUEST['bytype']);
     $g_oSession->Register('personnel_activity_groupby', $_REQUEST['groupby']);
     $g_oSession->Register('personnel_activity_responsible', $_REQUEST['responsible']);
     $g_oSession->Register('personnel_activity_department', $_REQUEST['department']);
     $g_oSession->Register('personnel_activity_timesheet', isset($_REQUEST['timesheet']) ? $_REQUEST['timesheet'] : 'N');
     $g_oSession->Edit();
     $bTimesheet = isset($_REQUEST['timesheet']) && $_REQUEST['timesheet'] == 'Y';
     if ($bTimesheet && $_REQUEST['groupby'] != '1' && $_REQUEST['groupby'] != '2' && $_REQUEST['groupby'] != '4' && $_REQUEST['groupby'] != '5') {
         if ($bExport) {
             commonHeader();
         }
         trigger_error('Timesheet report must by grouped by project, action, action by, or product.', E_USER_ERROR);
         $this->GetParameters(false);
         return;
     }
     if ($_REQUEST['groupby'] == '5' && $_REQUEST['bytype'] != '2') {
         trigger_error('Grouping by Action By must use report by department.', E_USER_ERROR);
         $this->GetParameters(false);
         return;
     }
     $objDB = new dclDB();
     $sReportFor = '';
     $sCols = 'timecards.jcn, timecards.seq, timecards.hours';
     if ($_REQUEST['bytype'] == '2' || $_REQUEST['groupby'] == '5') {
         $sCols .= ', personnel.short';
         if ($bTimesheet && $_REQUEST['groupby'] == '5') {
             $sCols .= ' AS name';
         }
     }
     if ($_REQUEST['groupby'] == '1') {
         $sCols .= ', dcl_projects.name';
     } else {
         if ($_REQUEST['groupby'] == '2') {
             $sCols .= ', actions.name';
         } else {
             if ($_REQUEST['groupby'] == '3') {
                 $sCols .= ', ' . $objDB->ConvertDate('timecards.actionon', 'actionon');
             } else {
                 if ($_REQUEST['groupby'] == '4') {
                     $sCols .= ', products.name';
                 }
             }
         }
     }
     if ($bTimesheet) {
         $sCols .= ', ' . $objDB->ConvertDate('timecards.actionon', 'actionon');
     }
     $iGroupColumn = -1;
     $query = "select {$sCols} from timecards ";
     if ($_REQUEST['groupby'] == '0' || $_REQUEST['groupby'] == '3' || $_REQUEST['groupby'] == '5') {
         // None (0) or date (3) or action by (5)
         if ($_REQUEST['bytype'] == '1') {
             if (($responsible = DCL_Sanitize::ToInt($_REQUEST['responsible'])) === null) {
                 trigger_error('Data sanitize failed.');
                 return;
             }
             $query .= ' where actionby=' . $responsible;
             $query .= ' and actionon between ' . $objDB->DisplayToSQL($begindate) . ' and ' . $objDB->DisplayToSQL($enddate);
         } else {
             if (($department = DCL_Sanitize::ToInt($_REQUEST['department'])) === null) {
                 trigger_error('Data sanitize failed.');
                 return;
             }
             $query .= $objDB->JoinKeyword . ' personnel on actionby = personnel.id ';
             $query .= 'where personnel.department=' . $department;
             $query .= ' and actionon between ' . $objDB->DisplayToSQL($begindate) . ' and ' . $objDB->DisplayToSQL($enddate);
         }
         if ($_REQUEST['groupby'] == '0') {
             $query .= ' order by jcn, seq';
         } else {
             if ($_REQUEST['groupby'] == '5') {
                 $query .= ' order by personnel.short, jcn, seq';
                 $iGroupColumn = 2;
             } else {
                 $query .= ' order by actionon, jcn, seq';
                 $iGroupColumn = 13;
                 if ($_REQUEST['bytype'] != '1') {
                     $iGroupColumn++;
                 }
                 if ($_REQUEST['groupby'] != '1') {
                     $iGroupColumn++;
                 }
             }
         }
     } else {
         if ($_REQUEST['groupby'] == '1') {
             // projects
             if ($_REQUEST['bytype'] == '1') {
                 if (($responsible = DCL_Sanitize::ToInt($_REQUEST['responsible'])) === null) {
                     trigger_error('Data sanitize failed.');
                     return;
                 }
                 $query .= 'left join projectmap on timecards.jcn = projectmap.jcn and projectmap.seq in (timecards.seq, 0) ';
                 $query .= 'left join dcl_projects on dcl_projects.projectid = projectmap.projectid ';
                 $query .= ' where timecards.actionby=' . $responsible;
                 $query .= ' and timecards.actionon between ' . $objDB->DisplayToSQL($begindate) . ' and ' . $objDB->DisplayToSQL($enddate);
                 $iGroupColumn = 13;
             } else {
                 if (($department = DCL_Sanitize::ToInt($_REQUEST['department'])) === null) {
                     trigger_error('Data sanitize failed.');
                     return;
                 }
                 $query .= $objDB->JoinKeyword . ' personnel on actionby = personnel.id ';
                 $query .= 'left join projectmap on timecards.jcn = projectmap.jcn and projectmap.seq in (timecards.seq, 0) ';
                 $query .= 'left join dcl_projects on dcl_projects.projectid = projectmap.projectid ';
                 $query .= 'where personnel.department=' . $department;
                 $query .= ' and actionon between ' . $objDB->DisplayToSQL($begindate) . ' and ' . $objDB->DisplayToSQL($enddate);
                 $iGroupColumn = 14;
             }
             $query .= ' order by dcl_projects.name, timecards.jcn, timecards.seq';
         } else {
             if ($_REQUEST['groupby'] == '2') {
                 // actions
                 if ($_REQUEST['bytype'] == '1') {
                     if (($responsible = DCL_Sanitize::ToInt($_REQUEST['responsible'])) === null) {
                         trigger_error('Data sanitize failed.');
                         return;
                     }
                     $query .= $objDB->JoinKeyword . ' actions on timecards.action = actions.id ';
                     $query .= ' where timecards.actionby=' . $responsible;
                     $query .= ' and timecards.actionon between ' . $objDB->DisplayToSQL($begindate) . ' and ' . $objDB->DisplayToSQL($enddate);
                     $iGroupColumn = 14;
                 } else {
                     if (($department = DCL_Sanitize::ToInt($_REQUEST['department'])) === null) {
                         trigger_error('Data sanitize failed.');
                         return;
                     }
                     $query .= $objDB->JoinKeyword . ' personnel on actionby = personnel.id ';
                     $query .= $objDB->JoinKeyword . ' actions on timecards.action = actions.id ';
                     $query .= 'where personnel.department=' . $department;
                     $query .= ' and actionon between ' . $objDB->DisplayToSQL($begindate) . ' and ' . $objDB->DisplayToSQL($enddate);
                     $iGroupColumn = 15;
                 }
                 $query .= ' order by actions.name, timecards.jcn, timecards.seq';
             } else {
                 // product
                 if ($_REQUEST['bytype'] == '1') {
                     if (($responsible = DCL_Sanitize::ToInt($_REQUEST['responsible'])) === null) {
                         trigger_error('Data sanitize failed.');
                         return;
                     }
                     $query .= $objDB->JoinKeyword . ' workorders on timecards.jcn = workorders.jcn and timecards.seq = workorders.seq ';
                     $query .= $objDB->JoinKeyword . ' products on workorders.product = products.id ';
                     $query .= ' where timecards.actionby=' . $responsible;
                     $query .= ' and timecards.actionon between ' . $objDB->DisplayToSQL($begindate) . ' and ' . $objDB->DisplayToSQL($enddate);
                     $iGroupColumn = 14;
                 } else {
                     if (($department = DCL_Sanitize::ToInt($_REQUEST['department'])) === null) {
                         trigger_error('Data sanitize failed.');
                         return;
                     }
                     $query .= $objDB->JoinKeyword . ' personnel on actionby = personnel.id ';
                     $query .= $objDB->JoinKeyword . ' workorders on timecards.jcn = workorders.jcn and timecards.seq = workorders.seq ';
                     $query .= $objDB->JoinKeyword . ' products on workorders.product = products.id ';
                     $query .= 'where personnel.department=' . $department;
                     $query .= ' and actionon between ' . $objDB->DisplayToSQL($begindate) . ' and ' . $objDB->DisplayToSQL($enddate);
                     $iGroupColumn = 15;
                 }
                 $query .= ' order by products.name, timecards.jcn, timecards.seq';
             }
         }
     }
     if (isset($_REQUEST['timesheet']) && $_REQUEST['timesheet'] == 'Y') {
         $this->ShowTimesheet($query, $iGroupColumn);
     } else {
         $this->ShowReport($query, $iGroupColumn);
     }
 }