Exemplo n.º 1
0
/** nf_getAwayReassignmentUid function
 * Recursive function used to get the user id to re-assign tasks to if the users Out-of-Office feature is active
 * Need to use a recursive function since new user may also be away and linked to another user
 * Function will use the $arrusers variable to test for possible infinite loop
 *
 * @param        int         $userID            User ID to check who has been setup in their preferences to redirect tasks to is
 * @param        mixed       $arrusers          array of users passed by the function to be used to test and prevent a loop
 * @return       int         user id to re-assigned tasks to
 *
 */
function nf_getAwayReassignmentUid($userID, $arrusers = '')
{
    global $_TABLES;
    if ($arrusers == '') {
        $arrusers = array();
    }
    // Initialize array that will be used to test we don't have users reassigning to each other
    $query = DB_query("SELECT away_start,away_return,reassign_uid,is_active FROM {$_TABLES['nf_useraway']} WHERE uid = {$userID}");
    list($datestart, $datereturn, $reassign_uid, $is_active) = DB_fetchArray($query);
    // Check and see if re-assign user is trying to link back - prevent a infinite loop
    if (in_array($reassign_uid, $arrusers)) {
        COM_errorLog("nf_getAwayReassignmentUid - possible assignment loop detected: UserID:{$userID}, re-assignuid:{$reassign_uid}");
        return $userID;
    } else {
        $arrusers[] = $reassign_uid;
        if ($is_active == 1 and time() > $datestart and time() < $datereturn) {
            // This user is also away
            $reassignToUserID = nf_getAwayReassignmentUid($reassign_uid, $arrusers);
        } else {
            $reassignToUserID = $userID;
        }
        // Check that user exists, is valid and status is an active user - else return original user id
        if ($reassignToUserID < 2 or DB_getItem($_TABLES['users'], 'status', "uid={$reassignToUserID}") != 3) {
            COM_errorLog("nf_getAwayReassignmentUid - assigment to invalid user detected: UserID:{$userID}, re-assignuid:{$reassignToUserID}");
            return $userID;
        } else {
            return $reassignToUserID;
        }
    }
}
Exemplo n.º 2
0
 /**
 * Method assign task - create productionAssignment Record and test if to-be-assigned user has their out-of-office setting active
 * @param        int         $queueID     Task ID from the workflow queue table
 * @param        array       $assignemnt  Array of records where the key is the variable id  if applicable and the user id
                                          If the assignment is by user, the key will be 0 or a negative value - in the case of multiple assignments
 * @return       n/a         No return
 */
 function assign_task($queueID, $userinfo)
 {
     global $_TABLES;
     $queueID = NXCOM_filterInt($queueID);
     foreach ($userinfo as $processVariable => $userID) {
         if (strpos($userID, ':') !== false) {
             $userIDs = explode(':', $userID);
         } else {
             $userIDs = array($userID);
         }
         foreach ($userIDs as $userID) {
             /* The array of users to be assigned may be an array of multiple assignments by user not variable
              * In this case, we can not have multiple array records with a key of 0 - so a negative value is used
              */
             if ($processVariable < 0) {
                 $processVariable = 0;
             }
             if ($userID > 1) {
                 $query = DB_query("SELECT away_start,away_return,is_active FROM {$_TABLES['nf_useraway']} WHERE uid = {$userID}");
                 list($datestart, $datereturn, $is_active) = DB_fetchArray($query);
                 // Check if user is away - away feature active and current time within the away window
                 if ($is_active == 1 and time() > $datestart and time() < $datereturn) {
                     /* User is away - determine who to re-assign task to */
                     $assignToUserID = nf_getAwayReassignmentUid($userID);
                     // If we have a new value for the assignment - then we need to set the assignBack field
                     if ($assignToUserID != $userID) {
                         $assignBack = $userID;
                     } else {
                         $assignBack = 0;
                     }
                 } else {
                     $assignToUserID = $userID;
                     $assignBack = 0;
                 }
             } else {
                 $assignToUserID = 0;
                 $assignBack = 0;
             }
             // Check and see if we have an production assignment record for this task and processVariable
             $sql = "SELECT uid FROM {$_TABLES['nf_productionassignments']} WHERE task_id={$queueID} ";
             if ($processVariable > 0) {
                 $sql .= "AND nf_processVariable={$processVariable}";
             } else {
                 $sql .= "AND nf_processVariable=0 AND uid={$userID}";
             }
             if (DB_numRows(DB_query($sql)) < count($userIDs)) {
                 $sql = "INSERT INTO {$_TABLES['nf_productionassignments']} (task_id,uid,nf_processVariable,assignBack_uid,last_updated) ";
                 $sql .= "VALUES ({$queueID}, {$assignToUserID}, {$processVariable}, {$assignBack}, UNIX_TIMESTAMP() )";
                 DB_query($sql);
             } else {
                 $sql = "UPDATE {$_TABLES['nf_productionassignments']} set uid={$assignToUserID}, last_updated=UNIX_TIMESTAMP(), ";
                 $sql .= "assignBack_uid = {$assignBack} ";
                 $sql .= "WHERE task_id={$queueID} AND nf_processVariable={$processVariable}";
                 DB_query($sql);
             }
         }
     }
 }