#ifndef SHARED_NEWS_UTIL_H
#define SHARED_NEWS_UTIL_H

#define MAX_DISCUSSION_NAME 35

extern char discussion_name[MAX_DISCUSSION_NAME + 1];
extern char discussion_path[MAX_PATH + 1];	     
extern char central_discussion_path[MAX_PATH + 1];   
extern char discussion_fname[MAX_FILENAME + 1];	

extern MSG_TREE_NODE *tree_head;
extern USER_INBOX_NODE   *user_head;

int editor_width_config(int config_setting);

int faculty_only_group (int grp);
int group_uses_topic (int grp);
int group_uses_name_filter (int grp);
void set_discussion_names (const char *coursepath, const char *username, int grp);


FILE *open_user_inbox(const char *mode);
void  write_user_inbox_record(int msg_id, time_t time_read);

USER_INBOX_NODE * build_user_inbox_list();
void free_user_inbox_list();
int is_teacher_hidden (MSG_STATUS status, time_t release_time, time_t unrelease_time, time_t current_time);
int msg_should_display(CENTRAL_INBOX_RECORD *data, SESSION *user, int grp, 
                             time_t current_time, int fac_teamteach, int show_teacher_hidden);
void build_msg_tree(SESSION *user, int grp, int show_all_teamteach, int show_teacher_hidden, time_t *current_time);
void build_event_list_msg_tree(SESSION *user, int grp, int show_all_teamteach, time_t *current_time);
void build_one_topic_tree(SESSION *user, int grp, long target_offset, 
                             MSG_TREE_NODE **msg_ptr, MSG_TREE_NODE **topic_ptr, int *msg_count, 
                             int include_all_topics, int show_teacher_hidden, time_t *current_time);
void build_fac_assign_read_tree(SESSION *user,  long target_offset, const char *receiver_username,
                             MSG_TREE_NODE **msg_ptr, MSG_TREE_NODE **topic_ptr, int *msg_count, time_t *current_time);
void build_topic_only_tree(SESSION *user, int grp);
void  free_msg_tree(MSG_TREE_NODE *root);
int has_unread_msgs(MSG_TREE_NODE *root, const char *username);
void count_all_msgs(MSG_TREE_NODE *root, int *total_msgs, int *total_unread, int *total_flagged);
void count_username_msgs(MSG_TREE_NODE *root, const char *username, int *total_msgs, 
							int *total_unread, int *total_teacher_hidden, int *total_flagged);
void count_topic_msgs(MSG_TREE_NODE *topic, int *total_msgs, int *total_unread, int *total_flagged);
void mark_msg_as_read(CENTRAL_INBOX_RECORD *msg, CONFIG_STRUCT *conf, SESSION *user);
void mark_msg_as_read_at_time(CENTRAL_INBOX_RECORD *msg, CONFIG_STRUCT *conf, SESSION *user, time_t now);

int allow_hotpot_exam_post(SESSION *user, int grp, int topic);
int is_hotpot_exam_dir(const char *directory_name);
int is_hotpot_exam(CENTRAL_INBOX_RECORD *msg, const char *course_path);

int modules_enabled (CONFIG_STRUCT *conf);
int only_handouts_enabled (CONFIG_STRUCT *conf);
void remove_stale_symlinks (const char *username, const char *crs, int access);

void display_protected_status(MSG_TREE_NODE *msg_ptr, const char *username, char *prefix);
void get_extension (const char *original_fname, char *extension);

void read_msg_record(long offset, CENTRAL_INBOX_RECORD *data);


void read_red_file (const char *red_fname, READ_STRUCT * read_info);

int find_longest_line( char *buf, CONFIG_STRUCT *conf);

void do_paste_textarea (const char *clipboard_path,
		   const char *msg_fname,
		   const char *sender_username,  char *sender_realname,
                   SESSION *user, CONFIG_STRUCT *conf);

char *replace_quot( char *orig_subject);

char *add_mark_to_msg( char *buf, int num_line);

int find_num_lines( char *buf);


void create_rec_list(const char *name, RECEIVER_NODE **head);


void set_news_msg_header_data(MSG_TREE_NODE *msg, char *name_prefix, int is_teacher_hidden, int is_read_only, char *topic_subject);

void set_news_attachment_data (MSG_TREE_NODE *msg_ptr,  char *topic_subject,
		      const char *course, const char *key, int grp,
		      int website_attached, char *from,
		      char team, int is_fac_teamteach, char *assign_read_student,
		      CONFIG_STRUCT *conf, int attachments_locked, 
		      const char *username,  ATTACHMENT_NODE *attachment_head, const char *name_prefix);


void
set_assign_read_heading_data (MSG_TREE_NODE *msg_ptr,  char *name_prefix, MSG_TREE_NODE *topic_ptr,
		       char *course,  char *key, CONFIG_STRUCT *conf, int teacher_hidden, 
	                          int can_write, int read_only);


int  is_lectern_lecture();
void get_orig_fname (const char *full_orig_name, char *orig_fname);
void write_cgi_file (FILE *infp, long size, const char *unique_fname);
int get_unique_fd(const char *base_dir, const char *filetype, char *unique_fname, time_t *time_sent);
void check_incomplete_upload();

#endif

