function udutu_find_common_ancestor($ancestors, $sco)
{
    $pos = udutu_array_search('identifier', $sco->parent, $ancestors);
    if ($sco->parent != '/') {
        if ($pos === false) {
            return udutu_find_common_ancestor($ancestors, udutu_get_parent($sco));
        }
    }
    return $pos;
}
function udutu_seq_exit_action_rules($seq, $userid)
{
    $sco = $seq->currentactivity;
    $ancestors = udutu_get_ancestors($sco);
    $exittarget = null;
    foreach (array_reverse($ancestors) as $ancestor) {
        if (udutu_seq_rules_check($ancestor, 'exit') != null) {
            $exittarget = $ancestor;
            break;
        }
    }
    if ($exittarget != null) {
        $commons = array_slice($ancestors, 0, udutu_find_common_ancestor($ancestors, $exittarget));
        /// Terminate Descendent Attempts Process
        if ($commons) {
            foreach ($commons as $ancestor) {
                udutu_seq_end_attempt($ancestor, $userid);
                $seq->currentactivity = $ancestor;
            }
        }
    }
    return $seq;
}