コード例 #1
0
ファイル: index.php プロジェクト: hostellerie/nexpro
function display_mytasks()
{
    global $CONF_NF, $_USER, $_CONF, $_POST, $_TABLES, $actionurl, $formstatus_options, $usermodeUID, $optLinkVars, $errmsg, $LANG_NF00;
    $nfclass = new nexflow();
    $nfclass->_nfUserId = $usermodeUID;
    $nfclass->set_debug(false);
    $nfclass->getQueue();
    $srchFilter = COM_applyFilter($_REQUEST['srchFilter']);
    $srchText = COM_applyFilter($_REQUEST['srchText']);
    $idForAppGroup = COM_applyFilter($_REQUEST['idAppGroup'], true);
    $searchString = COM_applyFilter($_REQUEST['srchText']);
    $srchStatus = COM_applyFilter($_REQUEST['srchStatus']);
    $doSearch = COM_applyFilter($_POST['dosearch']);
    $taskconsolefilter = COM_applyFilter($_POST['taskconsolefilter'], true);
    $taskSort = COM_applyFilter($_REQUEST['tasksort']);
    $sortDirection = COM_applyFilter($_REQUEST['sortorder']);
    if (empty($taskSort)) {
        $taskSort = 'cdate';
    }
    if (empty($sortDirection)) {
        $sortDirection = 'desc';
    }
    //RK included these items here for future filtering abilities
    $pagesize = COM_applyFilter($_REQUEST['$pagesize'], true);
    $filterdate = COM_applyFilter($_REQUEST['filterdate']);
    $page = COM_applyFilter($_REQUEST['$page'], true);
    $imgset = $_CONF['layout_url'] . '/nexflow/images';
    $headingFilterOptions = '&taskuser='******'desc') {
        $headingFilterOptions .= '&sortorder=asc';
    } else {
        $headingFilterOptions .= '&sortorder=desc';
    }
    if (!empty($srchFilter)) {
        $headingFilterOptions .= "&srchFilter={$srchFilter}";
    }
    if (!empty($srchText)) {
        $headingFilterOptions .= "&srchText={$srchText}";
    }
    if (!empty($idForAppGroup)) {
        $headingFilterOptions .= "&idAppGroup={$idForAppGroup}";
    }
    if (!empty($srchStatus)) {
        $headingFilterOptions .= "&srchStatus={$srchStatus}";
    }
    $p = new Template($_CONF['path_layout'] . 'nexflow');
    $p->set_file(array('report' => 'taskconsole/viewtasks.thtml', 'records' => 'taskconsole/viewtask_record.thtml', 'javascript' => 'taskconsole/javascript/taskconsole.thtml'));
    $p->set_var('layout_url', $_CONF['layout_url']);
    $p->set_var('site_url', $_CONF['site_url']);
    $p->set_var('imgset', $imgset);
    $p->set_var('actionurl', $actionurl);
    $p->set_var('taskuser', $usermodeUID);
    $p->set_var('show_awaystatus', 'none');
    $heading1 = "<a href=\"{$actionurl}?tasksort=template{$headingFilterOptions}\">Flow Name</a>";
    if ($taskSort == 'template') {
        if ($sortDirection == 'asc') {
            $heading1 .= '<span style="padding-left:10px;"><img src="' . $imgset . '/bararrowdown.gif" border="0"></span>';
        } else {
            $heading1 .= '<span style="padding-left:10px;"><img src="' . $imgset . '/bararrowup.gif" border="0"></span>';
        }
    }
    $p->set_var('heading1', $heading1);
    $heading2 = "<a href=\"{$actionurl}?tasksort=taskname{$headingFilterOptions}\">Task Name</a>";
    if ($taskSort == 'taskname') {
        if ($sortDirection == 'asc') {
            $heading2 .= '<span style="padding-left:10px;"><img src="' . $imgset . '/bararrowdown.gif" border="0"></span>';
        } else {
            $heading2 .= '<span style="padding-left:10px;"><img src="' . $imgset . '/bararrowup.gif" border="0"></span>';
        }
    }
    $heading2 .= '<span style="padding-left:5px;font-weight:normal;font-size:9px;">[click on task name to perform]</span>';
    $p->set_var('heading2', $heading2);
    $heading3 = "<a href=\"{$actionurl}?tasksort=cdate{$headingFilterOptions}\">Assigned</a>";
    if ($taskSort == 'cdate') {
        if ($sortDirection == 'asc') {
            $heading3 .= '<span style="padding-left:10px;"><img src="' . $imgset . '/bararrowdown.gif" border="0"></span>';
        } else {
            $heading3 .= '<span style="padding-left:10px;"><img src="' . $imgset . '/bararrowup.gif" border="0"></span>';
        }
    }
    $p->set_var('heading3', $heading3);
    $p->set_var('srchText', $LANG_NF00['srchText']);
    $p->set_var('srchFilter', $LANG_NF00['srchFilter']);
    $p->set_var('srchFilterTitle', $LANG_NF00['srchFilterTitle']);
    $p->set_var('srchFilterReqDesc', $LANG_NF00['srchFilterReqDesc']);
    $p->set_var('srchFilterPrjName', $LANG_NF00['srchFilterPrjName']);
    $p->set_var('srchDoSearch', $LANG_NF00['srchDoSearch']);
    //search/filter area setup
    $appGroupDDL = COM_optionList($_TABLES['nf_appgroups'], 'id,AppGroup');
    $p->set_var('show_selectappfield', 'none');
    $p->set_var('show_searchtextfield', '');
    switch (strtolower($srchFilter)) {
        case 'appgroup':
            $appGroupDDL = COM_optionList($_TABLES['nf_appgroups'], 'id,AppGroup', $idForAppGroup);
            $p->set_var('srchselappgroup', 'selected');
            $p->set_var('show_selectappfield', '');
            $p->set_var('show_searchtextfield', 'none');
        case 'title':
            $p->set_var('srchseltitle', 'selected');
            break;
        case 'desc':
            $p->set_var('srchselreqdesc', 'selected');
            break;
    }
    $p->set_var('srchTextValue', $srchText);
    $p->set_var('srchApplicationGroups', $appGroupDDL);
    switch ($srchStatus) {
        case 1:
            $srchStatus = 0;
            //since the COM_applyfilter makes everything zero, we need to change this from 1 to 0 in code.
            $p->set_var('srchselactive', 'selected');
            break;
        case 2:
            $p->set_var('srchselonhold', 'selected');
            break;
        case 3:
            $p->set_var('srchselstarted', 'selected');
            break;
        case 4:
            $p->set_var('srchselunstarted', 'selected');
            break;
        case -1:
            $p->set_var('srchselany', 'selected');
            break;
    }
    $sel_sort_options = '';
    foreach ($CONF_NF['sortOptions'] as $value => $label) {
        if ($taskSort == $value) {
            $sel_sort_options .= '<option value="' . $value . '" SELECTED=SELECTED>' . $label . '</option>';
            $p->set_var('selected_tasksort_option', $value);
        } else {
            $sel_sort_options .= '<option value="' . $value . '">' . $label . '</option>';
        }
    }
    $p->set_var('sel_sort_options', $sel_sort_options);
    //end of search/filter area
    if (trim($errmsg) != '') {
        $p->set_var('error_message', $errmsg);
    } else {
        $p->set_var('show_message', 'none');
    }
    // Test to see if we enable the ability to select taskconsole view for another user
    if (SEC_hasRights('nexflow.admin')) {
        $p->set_var('show_seltaskuser', '');
        $p->set_var('sel_user_options', COM_optionList($_TABLES['users'], 'uid,username', $usermodeUID));
    } else {
        $p->set_var('show_seltaskuser', 'none');
        $p->set_var('sel_user_options', '');
    }
    if ($_REQUEST['autoclose']) {
        $autoclose = '<script type="text/javascript">' . LB;
        $autoclose .= 'window.onload = function() { ' . LB;
        $autoclose .= '    self.close();' . LB;
        $autoclose .= '    return true;' . LB;
        $autoclose .= '}' . LB;
        $autoclose .= '</script>' . LB;
        $p->set_var('javascript_close_onload', $autoclose);
    }
    $LANG_CONFIRM = 'Please confirm that you want to delete this process and task records';
    /* Clicking on Task Name triggers action and need to use icon in Actions Column to display project Details */
    $newFormLink = $actionurl . '?op=edit&formid=%s&projectid=%s&taskid=%s' . $optLinkVars;
    $editFormLink = $actionurl . '?op=edit&formid=%s&result=%s&taskid=%s' . $optLinkVars;
    $onClick_action = 'OnClick="ajaxStartTask(%s);"';
    /* @TODO: Commented out for now (Blaine)
       //$holdTaskLink = '<a href="#" onclick="ajaxPutOnHold(%s,%s);"><img src="' . $_CONF['layout_url'] . '/nexflow/images/onhold.png" border=0 alt="%s"></a>';
       */
    // Check if this user has any tasks that were reassigned
    $reassignedTaskCount = DB_count($_TABLES['nf_productionassignments'], 'assignBack_uid', $usermodeUID);
    if ($reassignedTaskCount > 0) {
        $reassignment_message .= '<div style="font-weight:normal;padding-left:20px;">';
        if ($reassignedTaskCount == 1) {
            $reassignment_message .= "You have 1 task that has been re-assigned. Click ";
        } else {
            $reassignment_message .= "You have {$reassignedTaskCount} tasks that have been re-assigned. Click ";
        }
        $reassignment_message .= '<a href="' . $actionurl . '?op=reassignments' . $optLinkVars . '">here</a> to view them</div>';
        $p->set_var('reassignment_message', $reassignment_message);
    } else {
        $p->set_var('show_reassignmentmessage', 'none');
    }
    /* This delete feature is disabled for production use via a config option. It will delete all related records for the project this task is linked to */
    $deleteLink = '<a href="' . $actionurl . '?op=delete&taskid=%s&project_id=%s' . $optLinkVars . '" onclick="return confirm(\'' . $LANG_CONFIRM . '\');">';
    $deleteLink .= '<img src="' . $_CONF['layout_url'] . '/nexflow/images/delete.gif" border="0" TITLE="Delete Record"></a>';
    $tasks = $nfclass->get_tasks();
    if ($taskconsolefilter) {
        $p->set_var('lang_hidefilter', 'hide filter');
        $sortedtasks = nf_getSortedTaskArray($tasks, $srchFilter, $taskSort, $srchText, $idForAppGroup, $srchStatus, $sortDirection);
    } elseif (!empty($taskSort)) {
        $p->set_var('hidefilter', 'none');
        $p->set_var('lang_hidefilter', 'show filter');
        $sortedtasks = nf_getSortedTaskArray($tasks, $srchFilter, $taskSort, $srchText, $idForAppGroup, $srchStatus, $sortDirection);
    } else {
        $p->set_var('hidefilter', 'none');
        $p->set_var('lang_hidefilter', 'show filter');
        if (is_array($tasks) and count($tasks) > 0) {
            arsort($tasks);
            // Show latest task first
            $sortedtasks = $tasks;
        } else {
            $sortedtasks = '';
        }
    }
    if (is_array($sortedtasks) and count($sortedtasks) > 0) {
        $i = 1;
        $p->set_var('num_records', count($sortedtasks));
        foreach ($sortedtasks as $taskrec) {
            $p->set_var('task_action_url', '');
            $p->set_var('task_onclick', '');
            $p->set_var('edit', '<span style="padding-left:2px;">&nbsp;</span>');
            $p->set_var('rowid', $i);
            $p->set_var('csscode', $i % 2 + 1);
            $p->set_var('class_newtask', '');
            $startedDate = DB_getItem($_TABLES['nf_queue'], 'startedDate', "id='{$taskrec['id']}'");
            $taskStatus = DB_getItem($_TABLES['nf_queue'], 'status', "id='{$taskrec['id']}'");
            $p->set_var('on_hold_notice', '');
            if ($taskStatus == 2) {
                $p->set_var('task_icon', 'onhold2.png');
                $p->set_var('on_hold_notice', '<p style="margin-bottom:5px;color:red">This Task is ON HOLD. It cannot be executed until it is put back into active status.</p>');
            } else {
                $p->set_var('task_icon', 'task.gif');
            }
            if ($startedDate == NULL or $startedDate == 0) {
                $p->set_var('task_icon', 'new_task.gif');
                $p->set_var('task_started_date', ",task not started");
                $p->set_var('task_onclick', sprintf($onClick_action, $taskrec['id']));
            } else {
                $p->set_var('task_started_date', ",started:{$startedDate}");
                $p->set_var('task_onclick', '');
            }
            $nfclass->_nfProcessId = $taskrec['processid'];
            $project_id = $nfclass->get_ProcessVariable('PID');
            $project_id = NXCOM_filterInt($project_id);
            if ($project_id == 0) {
                //lets try to do a simple select in the nfprojects table to ensure no project exists.
                $sql = "SELECT id from {$_TABLES['nf_projects']} where wf_process_id='{$taskrec['processid']}'";
                $res = DB_query($sql);
                list($project_id) = DB_fetchArray($res);
                $project_id = NXCOM_filterInt($project_id);
            }
            //at this point, if the project_id is still 0, then we have no project data to show
            //show a general task console line item for execution by the end user.
            $taskStatus = DB_getItem($_TABLES['nf_queue'], 'status', "id='{$taskrec['id']}'");
            if (SEC_hasRights('nexflow.admin')) {
                if ($taskStatus == 2) {
                    $p->set_var('hold', sprintf($holdTaskLink, $i, $taskrec['id'], 'Re-activate'));
                } else {
                    $p->set_var('hold', sprintf($holdTaskLink, $i, $taskrec['id'], 'Toggle On-Hold'));
                }
            }
            if ($project_id > 0) {
                $p->set_var('hidetaskinfo', '');
                $project_detailsLink = '<a href="#" onClick=\'ajaxViewProjectDetails(%s,%s,%s,%s);\'>';
                $project_detailsLink .= '<img src="' . $_CONF['layout_url'] . '/nexflow/images/details.png" border="0" TITLE="View Project Details"></a>&nbsp;';
                $project_detailsLink .= '<a href="#" onClick=\'ajaxViewProjectComments(%s,%s,%s,%s);\'>';
                $project_detailsLink .= '<img src="' . $_CONF['layout_url'] . '/nexflow/images/comment.gif" border="0" TITLE="View Project Comments"></a>&nbsp;';
                // If task is for a project on hold or in a Recycled or Killed status then do not show it
                // There should never be any tasks appearing is status is Killed as that workflow should have been forced to complete state.
                $project_state = DB_getItem($_TABLES['nf_projects'], 'status', "id='{$project_id}'");
                if ($project_state != 6 && $project_state != 7) {
                    if ($nfclass->_debug) {
                        $logmsg = "Row:{$i} -> Project ID:{$project_id},Task ID:{$taskrec['id']}. ";
                        $logmsg .= "Processid:{$taskrec['processid']}, Task:{$taskrec['taskname']}, ";
                        $logmsg .= "TaskID: {$taskrec['templateTaskid']}, TaskType: {$taskrec['stepType']}";
                        COM_errorLog($logmsg);
                    }
                    $p->set_var('task_id', $taskrec['id']);
                    $p->set_var('project_id', $project_id);
                    $p->set_var('project_details', sprintf($project_detailsLink, $i, $project_id, $usermodeUID, $taskrec['id'], $i, $project_id, $usermodeUID, $taskrec['id']));
                    // Determine if this task is for a regenerated workflow and we need to update the main project/request record
                    $parentProcessID = DB_getItem($_TABLES['nf_process'], 'pid', "id='{$taskrec['processid']}'");
                    if ($parentProcessID > 0) {
                        // Now check if this same template task id was executed in the previous process - if so then it is a recycled task
                        // Don't show the re-generated attribute if in this instance of the process we proceed further and are executing new tasks
                        if (DB_count($_TABLES['nf_queue'], array('nf_processID', 'nf_templateDataId'), array($parentProcessID, $taskrec['templateTaskid'])) > 0) {
                            $taskrec['taskname'] = '<div style="color:red;padding-right:5px;display:inline;">[R]</div>' . $taskrec['taskname'];
                        }
                    }
                    $pquery = DB_query("SELECT wf_process_id  FROM {$_TABLES['nf_projects']} WHERE id='{$project_id}'");
                    list($wf_process_id) = DB_fetchArray($pquery);
                    if ($wf_process_id > 0 and $wf_process_id == $parentProcessID) {
                        if ($nfclass->_debug) {
                            COM_errorLog("Taskconsole: Updated wf_process_id for project: {$project_id} from {$wf_process_id} to {$taskrec['processid']}");
                        }
                        DB_query("UPDATE {$_TABLES['nf_projects']} SET wf_process_id='{$taskrec['processid']}' WHERE id='{$project_id}'");
                    }
                    $p->set_var('project_number', $project_id);
                    // Retrieve any Project Comments
                    $comment_count = DB_count($_TABLES['nf_projectcomments'], 'project_id', $project_id);
                    if ($comment_count > 0) {
                        $csql = "SELECT timestamp, b.username FROM {$_TABLES['nf_projectcomments']} a ";
                        $csql .= "LEFT JOIN {$_TABLES['users']} b on a.uid=b.uid WHERE project_id='{$project_id}' ";
                        $csql .= "ORDER BY timestamp DESC LIMIT 1";
                        list($timestamp, $username) = DB_fetchArray(DB_query($csql));
                        $p->set_var('comments_note', "({$comment_count}) <b>Last by:</b>&nbsp;{$username}, " . strftime('%m/%d/%Y %H:%M', $timestamp));
                    } else {
                        $p->set_var('comments_note', 'No Comments');
                    }
                    // If this this is an interactive tasktype - Check and see if taskhistory record has a "started" timestamp set.
                    if ($taskrec['stepType'] == 1 or $taskrec['stepType'] == 7 or $taskrec['stepType'] == 8) {
                        $q1 = DB_query("SELECT project_id,date_started FROM {$_TABLES['nf_projecttaskhistory']} WHERE task_id='{$taskrec['id']}'");
                        if (DB_numRows($q1) == 0) {
                            // No task history record yet
                            $p->set_var('class_newtask', 'class="nexflowNewTask"');
                            $q2 = DB_query("SELECT UNIX_TIMESTAMP(createdDate) FROM {$_TABLES['nf_queue']} WHERE id='{$taskrec['id']}' ");
                            list($date_assigned) = DB_fetchArray($q2);
                            DB_query("INSERT INTO {$_TABLES['nf_projecttaskhistory']} (project_id,process_id,task_id,assigned_uid,date_assigned)\r\n                                VALUES ('{$project_id}','{$taskrec['processid']}','{$taskrec['id']}','{$usermodeUID}','{$date_assigned}') ");
                        } else {
                            list($xprj_id, $xdate_started) = DB_fetchArray($q1);
                            if ($xprj_id == 0) {
                                // Task history record - but missing project_id
                                $p->set_var('class_newtask', 'class="nexflowNewTask"');
                                DB_query("UPDATE {$_TABLES['nf_projecttaskhistory']} SET project_id='{$project_id}' WHERE task_id='{$taskrec['id']}'");
                            }
                        }
                    } else {
                        unset($xdate_started);
                    }
                    // Retrieve the project description for this task - used as Project Title
                    $pquery = DB_query("SELECT description,originator_uid FROM {$_TABLES['nf_projects']} WHERE id='{$project_id}'");
                    list($description, $originator) = DB_fetchArray($pquery);
                    $submitted_date = DB_getItem($_TABLES['nf_process'], 'initiatedDate', "id={$taskrec['processid']}");
                    $submitter_info = COM_getDisplayName($originator) . " / {$submitted_date}";
                    // Retrieve the flow name dynamic custom functions for appending to the display name to be used for the description
                    $descSQL = "SELECT b.templateName, a.customFlowName FROM {$_TABLES['nf_process']} a ";
                    $descSQL .= "INNER JOIN {$_TABLES['nf_template']} b on b.id=a.nf_templateId ";
                    $descSQL .= "WHERE a.id={$taskrec['processid']} ";
                    $descRes = DB_query($descSQL);
                    list($templateName, $processCustomName) = DB_fetchArray($descRes);
                    if (trim($description) != '') {
                        $p->set_var('description', $description);
                    } else {
                        $p->set_var('description', $templateName);
                    }
                    if ($processCustomName != '') {
                        $p->set_var('project_title', $processCustomName);
                    } else {
                        $p->set_var('project_title', $templateName);
                    }
                    $p->set_var('assigned_date', $taskrec['cdate']);
                    $p->set_var('submitter_info', $submitter_info);
                    if ($taskrec['stepType'] == 8) {
                        // This is a nexform autotag handler
                        $form_id = $taskrec['url'];
                        // Check and see if the same form has been submitted for this task yet.
                        $sql = "SELECT a.id,a.formtype,a.results_id,a.status,a.created_by_taskid, b.nf_templateDataID ";
                        $sql .= "FROM {$_TABLES['nf_projectforms']} a ";
                        $sql .= "LEFT JOIN {$_TABLES['nf_queue']} b on b.id=a.created_by_taskid ";
                        $sql .= "WHERE project_id='{$project_id}' AND form_id='{$form_id}' ";
                        $query = DB_query($sql);
                        $newFormRecord = false;
                        if (DB_numRows($query) >= 1) {
                            $newFormRecord = true;
                            while (list($prj_formid, $formtype, $result_id, $state, $created_by_taskid, $form_taskTemplateDataID) = DB_fetchArray($query)) {
                                // Check if this is the same task editing, Rejected form so Task is a new queue ID but same templateDataID or Final Edit Task
                                if ($taskrec['id'] == $created_by_taskid || $form_taskTemplateDataID == $taskrec['templateTaskid'] || in_array($taskrec['templateTaskid'], $CONF_NF['final_edit_tasks'])) {
                                    // Check and see if the created_by_taskid has been updated - since it will have the original task id
                                    if ($processPID != 0 and $created_by_taskid != $taskrec['id']) {
                                        DB_query("UPDATE {$_TABLES['nf_projectforms']} SET created_by_taskid='{$taskrec['id']}' WHERE id='{$prj_formid}'");
                                    }
                                    $p->set_var('state', $formstatus_options[$state]);
                                    if ($state == 0 or $state == 2 or $state == 3 or $state == 6) {
                                        // Not final distributed version or rejected
                                        // Need to reset the process variable used to check the form approval result
                                        $nfclass->_nfProcessId = $taskrec['processid'];
                                        $nfclass->set_ProcessVariable('Review_Approval', 0);
                                        /* Using Click on Task to trigger action method */
                                        if ($taskStatus != 2) {
                                            $p->set_var('task_action_url', sprintf($editFormLink, $form_id, $result_id, $taskrec['id']));
                                        } else {
                                            $p->set_var('task_action_url', "#");
                                        }
                                    }
                                    $sql = "SELECT timestamp FROM {$_TABLES['nf_projecttimestamps']} ";
                                    $sql .= "WHERE project_id={$project_id} ORDER BY timestamp DESC LIMIT 1";
                                    $q = DB_query($sql);
                                    list($timestamp) = DB_fetchArray($q);
                                    if ($timestamp > 0) {
                                        $p->set_var('date', strftime("%Y-%m-%d", $timestamp));
                                    } else {
                                        $q2 = DB_query("SELECT UNIX_TIMESTAMP(createdDate) FROM {$_TABLES['nf_queue']} WHERE id='{$taskrec['id']}' ");
                                        list($date_assigned) = DB_fetchArray($q2);
                                        $p->set_var('date', strftime("%Y-%m-%d", $date_assigned));
                                    }
                                    $newFormRecord = false;
                                }
                            }
                        }
                        if (DB_numRows($query) == 0 or $newFormRecord) {
                            // No record yet for this form and process - create mode
                            $p->set_var('state', 'New Task');
                            $p->set_var('class_newtask', 'class="nexflowNewTask"');
                            /* Using Click on Task to trigger action method */
                            if ($taskStatus != 2) {
                                $p->set_var('task_action_url', sprintf($newFormLink, $form_id, $project_id, $taskrec['id']));
                            } else {
                                $p->set_var('task_action_url', "#");
                            }
                            $q2 = DB_query("SELECT UNIX_TIMESTAMP(createdDate) FROM {$_TABLES['nf_queue']} WHERE id='{$taskrec['id']}' ");
                            list($date_assigned) = DB_fetchArray($q2);
                            $p->set_var('date', strftime("%Y-%m-%d", $date_assigned));
                        }
                        $q = DB_QUERY("SELECT statusmsg FROM {$_TABLES['nf_projecttimestamps']} WHERE project_id = '{$project_id}' ORDER BY timestamp DESC LIMIT 1");
                        list($statusmsg) = DB_fetchArray($q);
                        $p->set_var('full_statusmsg', $statusmsg);
                        $msglen = strpos($statusmsg, '.');
                        if ($msglen > 0 and $pos !== FALSE) {
                            $statusmsg = substr($statusmsg, 0, $msglen);
                        }
                        $p->set_var('statusmsg', $statusmsg);
                        $p->set_var('id', $project_id);
                        $p->set_var('task_name', $taskrec['taskname']);
                        $p->set_var('view', '');
                        $p->set_var('action_record', '');
                    } else {
                        // Nexflow task - not a form, Check for interactive function or manualweb step type
                        $p->set_var('id', $taskrec['id']);
                        $p->set_var('process_id', $taskrec['processid']);
                        /* Task date is in format yyyy-mm-dd hh:mm:ss -- only want to show date portion */
                        $showdate = explode(' ', $taskrec['cdate']);
                        $p->set_var('date', $showdate[0]);
                        $sql = "SELECT timestamp,statusmsg FROM {$_TABLES['nf_projecttimestamps']} ";
                        $sql .= "WHERE project_id = '{$project_id}' ORDER BY timestamp DESC LIMIT 1";
                        $q = DB_query($sql);
                        list($timestamp, $statusmsg) = DB_fetchArray($q);
                        $p->set_var('full_statusmsg', $statusmsg);
                        $msglen = strpos($statusmsg, '.');
                        if ($msglen > 0 and $pos !== FALSE) {
                            $statusmsg = substr($statusmsg, 0, $msglen);
                        }
                        $p->set_var('statusmsg', $statusmsg);
                        /* @TODO: $xdate_started has not be set  */
                        if (isset($xdate_started) and $xdate_started == 0) {
                            // Task exists in the taskhistory table but no start_date yet
                            $p->set_var('state', 'New Task');
                        } else {
                            $p->set_var('state', 'Started');
                        }
                        $p->set_var('task_name', $taskrec['taskname']);
                        if (strrpos($taskrec['url'], '?') > 0) {
                            $url = "{$_CONF['site_url']}/nexflow/{$taskrec['url']}&processid={$taskrec['processid']}&taskid={$taskrec['id']}";
                        } else {
                            $url = "{$_CONF['site_url']}/nexflow/{$taskrec['url']}?processid={$taskrec['processid']}&taskid={$taskrec['id']}";
                        }
                        $url .= $optLinkVars;
                        /* Using Click on Task to trigger action method */
                        if ($taskStatus != 2) {
                            $p->set_var('task_action_url', '#');
                            $p->set_var('task_onclick', "onClick=\"togglerec('action',{$i});ajaxStartTask({$taskrec['id']});\" ");
                        } else {
                            $p->set_var('task_action_url', '#');
                            $p->set_var('task_onclick', "");
                        }
                        $p->set_var('chk_accept', '');
                        $p->set_var('chk_reject', '');
                        $p->set_var('project_id', $project_id);
                        $p->set_var('project_id', $project_id);
                        $p->set_var('form_id', $form_id);
                        $p->set_var('taskuser', $usermodeUID);
                        /* Check for any specific tasks that will then over-ride the action url link */
                        if ($taskrec['stepType'] == 7) {
                            // Interactive Function
                            $function = $taskrec['url'];
                            if (function_exists($function)) {
                                /* Call the interactive function passing
                                 *  taskrec, template, rowid and current user if using the user-switch feature
                                 */
                                $function($taskrec, $p, $i, $usermodeUID);
                            }
                        } elseif ($taskrec['stepType'] == 8) {
                            //nexform
                            /* @TODO: What should we be doing in this case?  */
                        } else {
                            /* Using Click on Task to trigger action method */
                            if ($taskStatus != 2) {
                                $p->set_var('task_action_url', $url);
                                $p->set_var('task_onclick', sprintf($onClick_action, $taskrec['id']));
                            } else {
                                $p->set_var('task_action_url', "#");
                                $p->set_var('task_onclick', "");
                            }
                            $p->set_var('action_record', '');
                        }
                    }
                    if (!is_numeric($project_id)) {
                        // Disable the icon to show the task/project detail
                        $p->set_var('project_details', '<span style="padding-right:14px;">&nbsp;</span>');
                        $p->set_var('project_detail', '');
                    }
                }
            } else {
                //there is no project ID to be found.
                //we'll display the non-project formatted item instead
                $project_detailsLink = '<a href="#" onClick=\'ajaxViewProjectDetails(%s,%s,%s,%s);\'>';
                $project_detailsLink .= '<img src="' . $_CONF['layout_url'] . '/nexflow/images/details.png" border="0" TITLE="View Details"></a>&nbsp;';
                $project_detailsLink .= '<a href="#" onClick=\'ajaxViewProjectComments(%s,%s,%s,%s);\'>';
                $project_detailsLink .= '<img src="' . $_CONF['layout_url'] . '/nexflow/images/comment.gif" border="0" TITLE="View Project Comments"></a>&nbsp;';
                $p->set_var('hidetaskinfo', 'none');
                $p->set_var('task_id', $taskrec['id']);
                $p->set_var('project_id', $project_id);
                $p->set_var('project_details', sprintf($project_detailsLink, $i, $project_id, $usermodeUID, $taskrec['id'], $i, $project_id, $usermodeUID, $taskrec['id']));
                $p->set_var('id', $taskrec['id']);
                $p->set_var('process_id', $taskrec['processid']);
                //get the template name here:
                $sql = "SELECT  c.templateName, d.customFlowName FROM {$_TABLES['nf_queue']} a ";
                $sql .= "inner join {$_TABLES['nf_templatedata']} b on a.nf_templatedataid=b.id ";
                $sql .= "inner join {$_TABLES['nf_template']} c on b.nf_templateid=c.id ";
                $sql .= "inner join {$_TABLES['nf_process']} d on a.nf_processid=d.id ";
                $sql .= "WHERE a.id={$taskrec['id']}";
                $res2 = DB_query($sql);
                list($tname, $customDisplay) = DB_fetchArray($res2);
                if ($customDisplay != '') {
                    $tname .= $customDisplay;
                }
                $p->set_var('project_title', $tname);
                /* Task date is in format yyyy-mm-dd hh:mm:ss -- only want to show date portion */
                $showdate = explode(' ', $taskrec['cdate']);
                $p->set_var('date', $showdate[0]);
                $q = DB_QUERY("SELECT timestamp,statusmsg FROM {$_TABLES['nf_projecttimestamps']} WHERE project_id={$project_id} ORDER BY timestamp DESC LIMIT 1");
                list($timestamp, $statusmsg) = DB_fetchArray($q);
                $p->set_var('full_statusmsg', $statusmsg);
                $msglen = strpos($statusmsg, '.');
                if ($msglen > 0 and $pos !== FALSE) {
                    $statusmsg = substr($statusmsg, 0, $msglen);
                }
                $p->set_var('statusmsg', $statusmsg);
                if (isset($xdate_started) and $xdate_started == 0) {
                    // Task exists in the taskhistory table but no start_date yet
                    $p->set_var('state', 'New Task');
                } else {
                    $p->set_var('state', 'Started');
                }
                $p->set_var('task_name', $taskrec['taskname']);
                if (strrpos($taskrec['url'], '?') > 0) {
                    $url = "{$_CONF['site_url']}/nexflow/{$taskrec['url']}&processid={$taskrec['processid']}&taskid={$taskrec['id']}";
                } else {
                    $url = "{$_CONF['site_url']}/nexflow/{$taskrec['url']}?processid={$taskrec['processid']}&taskid={$taskrec['id']}";
                }
                $url .= $optLinkVars;
                /* Using Click on Task to trigger action method */
                $p->set_var('task_action_url', '#');
                if ($taskStatus != 2) {
                    $p->set_var('task_onclick', "onClick=\"togglerec('action',{$i});ajaxStartTask({$taskrec['id']});\" ");
                } else {
                    $p->set_var('task_onclick', "");
                }
                $p->set_var('task_name', $taskrec['taskname']);
                $p->set_var('chk_accept', '');
                $p->set_var('chk_reject', '');
                $p->set_var('project_id', $project_id);
                $p->set_var('form_id', $form_id);
                $p->set_var('taskuser', $usermodeUID);
                /* Check for any specific tasks that will then over-ride the action url link */
                if ($taskrec['stepType'] == 7) {
                    // Interactive Function
                    $function = $taskrec['url'];
                    if (function_exists($function)) {
                        /* Call the interactive function passing
                         *  taskrec, template, rowid and current user if using the user-switch feature
                         */
                        $function($taskrec, $p, $i, $usermodeUID);
                    }
                } elseif ($taskrec['stepType'] == 8) {
                    // nexform Task
                    $form_id = $taskrec['url'];
                    /* Using Click on Task to trigger action method */
                    if ($taskStatus != 2) {
                        $p->set_var('task_action_url', sprintf($newFormLink, $form_id, $project_id, $taskrec['id']));
                    } else {
                        $p->set_var('task_action_url', "#");
                    }
                } else {
                    /* Using Click on Task to trigger action method */
                    if ($taskStatus != 2) {
                        $p->set_var('task_action_url', $url);
                        $p->set_var('task_onclick', sprintf($onClick_action, $taskrec['id']));
                    } else {
                        $p->set_var('task_action_url', "#");
                        $p->set_var('task_onclick', "");
                    }
                    $p->set_var('action_record', '');
                }
                $p->set_var('project_details', '<span style="padding-right:14px;">&nbsp;</span>');
                $p->set_var('project_detail', '');
            }
            //end if - test for valid project_id
            $p->parse('view_records', 'records', true);
            $i++;
        }
        //end foreach
    } else {
        $p->set_var('num_records', 0);
        $p->set_var('view_records', '<tr><td colspan=5 style="padding-left:20px;">No Tasks</td></tr>');
    }
    $p->parse('javascript_code', 'javascript');
    $p->parse('output', 'report');
    return $p->finish($p->get_var('output'));
}