#include "shared_copy_tab_file.h"

int copy_tab_file(CONFIG_STRUCT *conf)
{
     P_NODE *head, *faculty =0;
     char old_tab_file[MAX_PATH +1];
     char new_tab_file[MAX_PATH +1];
     struct stat file_stat;

     head = build_option_person_list (conf);
     for(faculty = head; faculty; faculty = faculty->next)
     {
	  if(faculty->data.group == FACULTY)
		 break;
     } 
     if(faculty)
     {
        snprintf(old_tab_file, MAX_PATH +1, "%s%s/%s/%s/%s", 
			conf->course_path, PEOPLE_DIR, faculty->data.username, GRADES_DIR, GRADES_TAB_FNAME);
	if(stat(old_tab_file, &file_stat))
		return 0;
        snprintf(new_tab_file, MAX_PATH +1, "%s%s", 
			conf->course_path, GRADE_BOOK_DIR);
	mkdir(new_tab_file, 0770);
        snprintf(new_tab_file, MAX_PATH +1, "%s%s/%s", 
			conf->course_path, GRADE_BOOK_DIR, GRADES_TAB_FNAME);
	copy_file(old_tab_file, new_tab_file);

     }
     else
	cs_critical_error(ERR_NO_TEACHER, "copy_tab_file");
     return 1;
}

