#ifndef SHARED_SERACH_PROFILE_H
#define SHARED_SERACH_PROFILE_H

#define MAX_FULL_RECORDS_PER_PAGE 200    /* for full record searches, limit to this number of records per page */


/* fields to search */
#define ALL_FIELDS 0
#define USERNAME_FIELD 1
#define ID_FIELD 2
#define NAME_FIELD 3

/* users to include in search */
#define ALL_USERS 0
#define STUDENT_USERS 1
#define FACULTY_USERS 2
#define CLASSLESS_USERS 3

/* report type */
#define FULL_RESULTS 0
#define INDEX_RESULTS 1

/* part of string to match */
#define CONTAINS 0
#define START_WITH 1
#define END_WITH 2

/* sort by */
#define SORT_LAST 0
#define SORT_USERNAME 1
#define SORT_ID 2
#define SORT_FIRST 3



#define NO_MATCH -1

typedef struct course_info{
    char course_no[MAX_COURSE_NO + 1];
    char title[MAX_COURSE_TITLE + 1];
    char semester[MAX_SEMESTER + 1];
    char instructor[MAX_INSTRUCTOR + 1];
    char course_dir[MAX_PATH + 1];
    int standalone;
    int template;
    int access;
    struct course_info *next;
}COURSE_INFO;





typedef struct username_group_node
{
 char username[MAX_USERNAME + 1];
 GROUP_TYPE group;      /* faculty or student */
 struct username_group_node *next;
} USERNAME_GROUP_NODE;


typedef struct course_node
 {
  COURSE_INFO course_data;      
  USERNAME_GROUP_NODE *user_head;
  struct course_node *next;
 } COURSE_NODE; 


 typedef struct user_course_node
  {
   COURSE_NODE *course_data;
   GROUP_TYPE group;
   struct user_course_node *next;
  } USER_COURSE_NODE;  
   

typedef struct profile_node
 {
   USER_DATA person;
   int username_match;
   int realname_match;
   int id_match;
   USER_COURSE_NODE *course_head;
   struct profile_node *next;
} PROFILE_NODE;
   



void
read_search_parameters(char *key, char *crs, char *group, char *oper, char *search, int *field, int *users, int *results, 
				 int *sensitive, int *where, int *sort, int *start_record, int *records_per_page);



PROFILE_NODE *
sort_profile_list (PROFILE_NODE *pers_head, int sort);

PROFILE_NODE *build_profile_list(const char *search, int sensitive, int where, int field, 
								int users, int sort, int start_record, int records_per_page,
				                                 int *count);
         
void free_profile_list(PROFILE_NODE *head);
void set_highlighted(char *string, int match, int search_len, const char *name_string, int num);
int
find_user_in_course(P_NODE *person_crs, const char *username);

int parse_line(const char *str, P_NODE *user_data);
#endif

