separate (Tracker.Manipulate_Data.Prioritize)


procedure Sort_El_In_Pr is
    --------------------------------------------------------------------------------
    --|
    --|  NAME:  SORT_EL_IN_PR
    --|
    --|  OVERVIEW:
    --|    This procedure sorts the elements belonging to a given person using the
    --|    milestones sorted by completion sequence and the milestone's elements
    --|    sorted by element priority.  Sorting is done by walking down each
    --|    milestone's element list and deleting and adding any elements which
    --|    belong to this person.
    --|
    --|  EXCEPTIONS HANDLED:
    --|    others   an error message is printed and execution continues
    --|
    --|  HISTORY:
    --|    written by   Bonnie Burkhardt   March 1985
    --------------------------------------------------------------------------------

    use El_List_Pkg;

    Ele_Ptr : Element_Pointer;
    Ele_Ptr2 : Element_Pointer;
    End_List : Boolean := False;
    Pr_Initials : String (1 .. Pr_Init_Max_Len) := Pr_Ptr.Initials;
    Sorted_El_List : El_List_Pkg.List_Type;
    Found : Boolean := False;

begin
    -- check each milestone's element list for elements that belong to this person
    Start_Walk (Sorted_Ms_List);

    loop
        Walk (Sorted_Ms_List, Ms_Ptr, End_List);
        exit when End_List;

        -- examine the milestone's list of elements for any elements belonging
        -- to this person
        Start_Walk (Ms_Ptr.Element_List);

        loop
            Walk (Ms_Ptr.Element_List, Ele_Ptr, End_List);
            exit when End_List;

            if Ele_Ptr.More_Than_One_Person then
                for Ac_Index in 1 .. Num_Of_Activities loop
                    if Ele_Ptr.People_Initials (Ac_Index) = Pr_Initials then
                        Find (Sorted_El_List, Ele_Ptr.Desc_Key,
                              Ele_Ptr2, Found);

                        if not Found then
                            Add (Sorted_El_List, Ele_Ptr.Desc_Key, Ele_Ptr);
                        end if;
                    end if;
                end loop;

            else
                -- only one person assigned
                if Ele_Ptr.Person_Initials = Pr_Initials then
                    Add (Sorted_El_List, Ele_Ptr.Desc_Key, Ele_Ptr);
                end if;
            end if;

        end loop;
    end loop;

    Pr_Ptr.Element_List := Sorted_El_List;

exception
    when others =>
        Put_Line ("exception raised in SORT_EL_IN_PR.");
end Sort_El_In_Pr;
