/* * This program is for the students to send/receive voice email and register courses by * telephone. The main functions provided to the students including:1.registrate courses, * 2.drop courses, 3.list courses, 4.list grades at the end of semester, 5.change password, * 6.send voice email,7.listen to voice email. The program also provides service to the * instructors to manage the course registration including printing out registration list * of a course, setting number limit for the registration of a course. * * pragrammer: Huidong Ma * date:03/10/98 */ #include #include #include #include #include #include #include #include #include #define NAMELEN 10 #define CNAMELEN 30 #define FILELEN 15 #define MAXINCOURSE 40 typedef struct c_nodes{ int callcode; int code; char cname[CNAMELEN]; int section; struct c_nodes *restp; }courseT; typedef struct f_nodes{ char filename[FILELEN]; struct f_nodes *restp; }voicefileT; typedef struct s_nodes{ int ID; char firstname[NAMELEN]; char lastname[NAMELEN]; int PAC; voicefileT *fileheadp; struct s_nodes *restp; }studentT; typedef struct re_nodes{ int ID; char firstname[NAMELEN]; char lastname[NAMELEN]; int callcode; char grade[1]; struct re_nodes *restp; }registrateT; studentT *MakeStudentLink(FILE *infile,studentT *studentp); studentT *GetStudentNode(FILE *infile,int *status); studentT *AddStudentNode(studentT *headp,studentT *student); void ShowStudentLink(studentT *studentp); voicefileT* AddFileNode(voicefileT * fileheadp,char filename[]); courseT *MakeCourseLink(FILE *infile); void ShowCourse(courseT *headp,int callcode,int chdev); courseT *AddCourse(courseT *headp,courseT course); void ShowCourseLink(courseT *headp); registrateT *MakeRegistrateLink(FILE *infile); registrateT *AddRegistrate(registrateT *registratep,registrateT registrate); void ShowRegistrateLink(registrateT *registratep); int CheckCallInCourse(courseT *headp,int callcode); int IDfound(studentT *headp,int ID,int PAC,char firstname[],char lastname[]); registrateT* AddCallByPhone(registrateT *registratep,courseT *coursep,studentT *studentp,int ID,int callcode,int chdev); void ListByPhone(registrateT *registratep,courseT *coursep,int ID,int chdev); registrateT *DeleteCallByPhone(registrateT *headp,courseT *coursep,int ID,int callcode,int chdev); registrateT *DeleteCall(registrateT *registratep,int ID,int callcode,int *found); char *IndicateTime(void); char *SubString(char string[],int start,int num); void PrintStudentInFile(FILE *outfile,studentT *headp); void PrintRegistrateInFile(FILE *outfile,registrateT *registratep); void ClassRegistration(registrateT *registratep,courseT *coursep,int callcode,int chdev); void PrintClassRegistrationInFile(FILE *outfile,registrateT *registratep,int callcode); void GetGrade(registrateT *registratep,courseT *coursep,int ID,int chdev); void GetAllGrade(registrateT *registratep,courseT *coursep,studentT *studentp,int chdev); void ChangePAC(studentT *studentp,int ID,int nPAC); void FindAddFileNode(studentT *studentp,int ID,char filename[]); char *GenerateFileName(void); int InitBoard(char *channel); void SetHookOn(int chdev); void SetHookOff(int chdev); void PlayFile(studentT *studentp,int ID,int chdev); voicefileT* PlayVoiceFileLink(voicefileT *fileheadp,int chdev); void Play(int chdev,char* filename); void Play1(int chdev,char* filename); voicefileT *DeleteFileNode(voicefileT *fileheadp); int CheckID(int chdev,studentT *studentp,int *found,char firstname[],char lastname[]); void Rec(int chdev,char *filename); int GetDigit(int chdev,int num); int GetDigit1(int chdev,int num); int CharToInt(char ch); void Play(int chdev,char* filename); void ErrFun(int chdev); void WaitRing(int chdev); void AnnDoubD(int num,int chdev); void AnnDigit(int num,int chdev); void AnnTen(int num,int chdev); void AnnOne(int num,int chdev); void AnnChar(char ch[],int chdev); int main(void) { FILE *infile1,*infile2,*infile3; FILE *outfile1,*outfile2,*outfile3; studentT *studentp=NULL; courseT *coursep=NULL; registrateT *registratep=NULL; int command; int ID; int PAC; int IDtime=0; int found; int callcode; int acommand,acommand1; char firstname[NAMELEN]; char lastname[NAMELEN]; char datafile[15]; int nPAC,nPAC1; int rID; char filename[FILELEN]; int chdev; char charID[9]; int count; /* loop of operation */ for(count=0;count<100;count++){ /* open data file and read data to make links */ if((infile1=fopen("student.txt","r"))==NULL) printf("Can not open student.txt.\n"); studentp=MakeStudentLink(infile1,studentp); fclose(infile1); if((infile2=fopen("course.txt","r"))==NULL) printf("Can not open course.txt\n"); coursep=MakeCourseLink(infile2); fclose(infile2); if((infile3=fopen("registrate.txt","r"))==NULL) printf("Can not open registrate.txt\n"); registratep=MakeRegistrateLink(infile3); fclose(infile3); //ininiate board chdev=InitBoard("dxxxB1C1"); //play welcome.vox Play(chdev,"welcome.vox"); //check ID ID=CheckID(chdev,studentp,&found,firstname,lastname); /* if logon ID and PAC is accepted */ if(found==1){ //printf("\nYour name is "); Play(chdev,"Yourname.vox"); //change ID into string itoa(ID,charID,10); //announce name Play(chdev,strcat(charID,".vox")); // print and the time the name on screen printf("%s %s ",firstname,lastname); printf("%s\n",IndicateTime()); /*print manu for students */ do{ /*printf("\nPlease enter:\n"); printf("1 to registrate courses.\n"); printf("2 to drop courses.\n"); printf("3 to list courses.\n"); printf("4 to list grade.\n"); printf("5 to change you password.\n"); printf("6 to send a voice email.\n"); printf("7 to listen to a voice email.\n"); printf("0 to exit.\n"); printf("or other number to repeat the manu.\n"); printf(">"); */ Play1(chdev,"Manu1.vox"); //scanf("%d",&command); command=GetDigit1(chdev,1); switch(command){ /* to registrate courses */ case 1: //printf("Please enter the callcode>"); Play(chdev,"callcode.vox"); //scanf("%d",&callcode); callcode=GetDigit(chdev,4); //add course registratep=AddCallByPhone(registratep,coursep,studentp,ID,callcode,chdev); //update record outfile2=fopen("registrate.txt","w"); PrintRegistrateInFile(outfile2,registratep); fclose(outfile2); break; /* to drop courses */ case 2: //printf("Please enter the callcode>"); Play(chdev,"callcode.vox"); //scanf("%d",&callcode); callcode=GetDigit(chdev,4); //delete course registratep=DeleteCallByPhone(registratep,coursep,ID,callcode,chdev); //update record outfile2=fopen("registrate.txt","w"); PrintRegistrateInFile(outfile2,registratep); fclose(outfile2); break; /* to list courses */ case 3: ListByPhone(registratep,coursep,ID,chdev); break; /* to get grade of courses */ case 4: GetGrade(registratep,coursep,ID,chdev); break; /* change the password */ case 5: // printf("Please enter your new password>"); Play(chdev,"newpswd.vox"); //scanf("%d",&nPAC); nPAC=GetDigit(chdev,6); //printf("Please reenter you new password>"); Play(chdev,"rnewpswd.vox"); //scanf("%d",&nPAC1); nPAC1=GetDigit(chdev,6); //if two passwords are consistant if(nPAC1==nPAC){ //change password ChangePAC(studentp,ID,nPAC); //update file outfile1=fopen("student.txt","w"); PrintStudentInFile(outfile1,studentp); fclose(outfile1); //printf("You password has been changed\n"); Play(chdev,"pswdchge.vox"); } else //printf("You password is not correct\n"); Play(chdev,"pswdinco.vox"); break; /* send voice email */ case 6: //printf("Please enter the ID of the receiver>"); Play(chdev,"receiv.vox"); //scanf("%d",&rID); rID=GetDigit(chdev,8); //generate a random number as file name strcpy(filename,GenerateFileName()); //record Rec(chdev,filename); //add file name to the student's record FindAddFileNode(studentp,rID,filename); //update file outfile1=fopen("student.txt","w"); PrintStudentInFile(outfile1,studentp); fclose(outfile1); break; /* listen to an voice email */ case 7: //play file,delete filename and remove file PlayFile(studentp,ID,chdev); //update file outfile1=fopen("student.txt","w"); PrintStudentInFile(outfile1,studentp); fclose(outfile1); break; /* 9 for the faculty to start administration functions */ case 9: /* get an other 9 to start the administration through standart I/O.*/ acommand1=GetDigit(chdev,1); if(acommand1==9){ do{ /* print the manu */ printf("\nWelcome to Adiministration Manu.\n"); printf("Please enter:\n"); printf("1 to print out the registration of class.\n"); printf("2 to print out the grade of all the student.\n"); printf("0 to return to the previous manu.\n"); printf(">"); scanf("%d",&acommand); switch(acommand){ /* print out the registration list of a particular class */ case 1: printf("Please enter the callcode>"); scanf("%d",&callcode); ClassRegistration(registratep,coursep,callcode,chdev); itoa(callcode,datafile,10); strcat(datafile,".txt"); outfile3=fopen(datafile,"w"); PrintClassRegistrationInFile(outfile3,registratep,callcode); fclose(outfile3); break; /* print out all the grades of all the students */ case 2: GetAllGrade(registratep,coursep,studentp,chdev); break; } }while(acommand==1 || acommand==2); } } }while(command!=0); } Play(chdev,"byebye.vox"); } return(0); } /* input the data of students from text file and make a link of students */ studentT *MakeStudentLink(FILE *infile,studentT *studentp) { studentT *student; int status; for(student=GetStudentNode(infile,&status); status==1; student=GetStudentNode(infile,&status)){ studentp=AddStudentNode(studentp,student); } return(studentp); } /* input the data of a single student */ studentT *GetStudentNode(FILE *infile,int *status) { char tempfile[FILELEN]; studentT *student; student=(studentT *)malloc(sizeof(studentT)); *status=fscanf(infile,"%d%s%s%d",&student->ID, student->firstname, student->lastname, &student->PAC); if(*status!=4 && *status!=EOF) *status=0; else if(*status==EOF) *status=-1; else{ *status=1; student->fileheadp=NULL; for(fscanf(infile,"%s",tempfile);strcmp(tempfile,"-1")!=0;fscanf(infile,"%s",tempfile)){ student->fileheadp=AddFileNode(student->fileheadp,tempfile); } student->restp=NULL; } return(student); } /* add a student node to the student link */ studentT *AddStudentNode(studentT *headp,studentT *student) { studentT *temp; if (headp==NULL) headp=student; else{ for(temp=headp;temp->restp!=NULL;temp=temp->restp){}; temp->restp=student; } return(headp); } /* print out the link of students */ void ShowStudentLink(studentT *studentp) { studentT * tempp; for (tempp=studentp;tempp!=NULL;tempp=tempp->restp){ printf("%10s%10s%10d\n",tempp->firstname,tempp->lastname,tempp->PAC); } } /* add a file name to the link of voicefile of a student */ voicefileT* AddFileNode(voicefileT * fileheadp,char filename[]) { voicefileT *tempp; voicefileT *voicefile; voicefile=(voicefileT *)malloc(sizeof(voicefileT)); strcpy(voicefile->filename,filename); voicefile->restp=NULL; if(fileheadp==NULL) fileheadp=voicefile; else{ for(tempp=fileheadp;tempp->restp!=NULL;tempp=tempp->restp){} tempp->restp=voicefile; } return(fileheadp); } /* Play all the voice file of a student */ void ShowVoiceFileLink(voicefileT *fileheadp) { voicefileT *tempp; for(tempp=fileheadp;tempp!=NULL;tempp=tempp->restp){ printf("%s ",tempp->filename); } } /* input the course data from text file and make a link of courses */ courseT *MakeCourseLink(FILE *infile) { courseT course; courseT *coursep=NULL; int status1; for(status1=fscanf(infile,"%d%d%s%d",&course.callcode, &course.code, course.cname, &course.section); status1==4; status1=fscanf(infile,"%d%d%s%d",&course.callcode, &course.code, course.cname, &course.section)){ coursep=AddCourse(coursep,course); } return(coursep); } /* add a course node to the course link */ courseT *AddCourse(courseT *headp,courseT course) { courseT * newp; newp=new courseT; newp->callcode=course.callcode; newp->code=course.code; strcpy(newp->cname,course.cname); newp->section=course.section; newp->restp=headp; headp=newp; return (newp); } /* print out the course description according to the callcode */ void ShowCourse(courseT *headp,int callcode,int chdev) { courseT *tempp; int found=0; char charcallcode[4]; for(tempp=headp;tempp!=NULL && found!=1;tempp=tempp->restp){ if(callcode==tempp->callcode){ AnnDoubD(tempp->code,chdev); //printf(" %s- ",tempp->cname); itoa(callcode,charcallcode,10); //printf(" section "); Play(chdev,"section.vox"); AnnOne(tempp->section,chdev); Play(chdev,strcat(charcallcode,".vox")); found=1; } } if(tempp==NULL && found!=1) printf("Callcode not found.\n"); } /* print out the link of courses */ void ShowCourseLink(courseT *headp) { courseT *tempp; for(tempp=headp;tempp!=NULL;tempp=tempp->restp){ printf("%d ",tempp->callcode); } } /* input the registration data from text file and make a link of registration*/ registrateT *MakeRegistrateLink(FILE *infile) { registrateT registrate; registrateT *registratep=NULL; int status1; while((status1=fscanf(infile,"%d%s%s%d%s",®istrate.ID, registrate.firstname, registrate.lastname, ®istrate.callcode, registrate.grade))==5){ registratep=AddRegistrate(registratep,registrate); } return(registratep); } /* add a registration node to the link of registration.*/ registrateT *AddRegistrate(registrateT *registratep,registrateT registrate) { registrateT *newp; newp=new registrateT; newp->ID=registrate.ID; strcpy(newp->firstname,registrate.firstname); strcpy(newp->lastname,registrate.lastname); newp->callcode=registrate.callcode; strcpy(newp->grade,registrate.grade); newp->restp=registratep; registratep=newp; return(registratep); } /* print out a registration link */ void ShowRegistrateLink(registrateT *registratep) { registrateT *tempp; for(tempp=registratep;tempp!=NULL;tempp=tempp->restp){ printf("%d %s %s %d %s\n",tempp->ID,tempp->firstname, tempp->lastname,tempp->callcode,tempp->grade); } } /* delete a call from the callcode link */ registrateT *DeleteCall(registrateT *headp,int ID,int callcode,int *found) { registrateT *freep; registrateT *newp; newp=headp; if(newp==NULL) *found=0; else if(newp->ID==ID && newp->callcode==callcode){ freep=newp; newp=freep->restp; free(freep); *found=1; } else newp->restp=DeleteCall(newp->restp,ID,callcode,found); return(newp); } /* check if the callcode is included in the course schedule */ int CheckCallInCourse(courseT *headp,int callcode) { courseT *tempp; int found=0; for(tempp=headp;tempp!=NULL && found!=1;tempp=tempp->restp){ if(tempp->callcode==callcode){ found=1; } } return(found); } /* check the ID and PAC is in the students record */ int IDfound(studentT *headp,int ID,int PAC,char firstname[],char lastname[]) { studentT *tempp; int found=0; for(tempp=headp;tempp!=NULL && found!=1;tempp=tempp->restp){ if(tempp->ID==ID && tempp->PAC==PAC){ found=1; strcpy(firstname,tempp->firstname); strcpy(lastname,tempp->lastname); } } return(found); } /* add callcode to the registrate record by phone */ registrateT* AddCallByPhone(registrateT *registratep,courseT *coursep,studentT *studentp, int ID,int callcode,int chdev) { registrateT tempp; studentT *stempp; if(CheckCallInCourse(coursep,callcode)==1){ tempp.ID=ID; tempp.callcode=callcode; for(stempp=studentp;stempp!=NULL;stempp=stempp->restp){ if(stempp->ID==ID){ strcpy(tempp.firstname,stempp->firstname); strcpy(tempp.lastname,stempp->lastname); } } strcpy(tempp.grade,"N"); registratep=AddRegistrate(registratep,tempp); ShowCourse(coursep,callcode,chdev); //printf("has been added to your course list.\n"); Play(chdev,"addcrse.vox"); } else //printf("You entered a callcode which is not included in course schedule.\n"); Play(chdev,"crsenfnd.vox"); return (registratep); } /* list all the registrated courses of one student */ void ListByPhone(registrateT *registratep,courseT *coursep,int ID,int chdev) { registrateT *tempp; //printf("Your course list is:\n"); Play(chdev,"crselist.vox"); if(registratep==NULL) Play(chdev,"nocrse.vox"); else{ for(tempp=registratep;tempp!=NULL;tempp=tempp->restp){ if(tempp->ID==ID){ ShowCourse(coursep,tempp->callcode,chdev); } } } } /* delete a callcode from the registration record by phone */ registrateT *DeleteCallByPhone(registrateT *registratep,courseT *coursep,int ID,int callcode,int chdev) { int found=0; registratep=DeleteCall(registratep, ID, callcode,&found); if(found==1){ ShowCourse(coursep,callcode,chdev); //printf("has been deleted from your course list.\n"); Play(chdev,"deltcrse.vox"); } else //printf("Your callcode is not found in your course list.\n"); Play(chdev,"callnfnd.vox"); return(registratep); } /* get random digits as filename */ char *GenerateFileName(void) { unsigned int i=0; char filename[FILELEN]; srand( (unsigned)time( NULL ) ); i=rand() ; itoa(i,filename,10); strcat(filename,".vox"); return(filename); } /* substring function */ char *SubString(char string[],int start,int num) { char sub[10]; int i; for(i=0;irestp){ fprintf(outfile,"%d %s %s %d ",tempp->ID,tempp->firstname,tempp->lastname,tempp->PAC); for(ftempp=tempp->fileheadp;ftempp!=NULL;ftempp=ftempp->restp){ fprintf(outfile,"%s ",ftempp->filename); } fprintf(outfile,"-1\n"); } } /* print the registration record into a text file */ void PrintRegistrateInFile(FILE *outfile,registrateT *registratep) { registrateT *tempp; for(tempp=registratep;tempp!=NULL;tempp=tempp->restp){ fprintf(outfile,"%d %s %s %d %s \n",tempp->ID,tempp->firstname, tempp->lastname,tempp->callcode,tempp->grade); } } /* print out a registration list of a particular course */ void ClassRegistration(registrateT *registratep,courseT *coursep,int callcode,int chdev) { registrateT *tempp; printf("The registration list for "); ShowCourse(coursep,callcode,chdev); printf("\n"); for(tempp=registratep;tempp!=NULL;tempp=tempp->restp){ if(tempp->callcode==callcode) printf("%d %s %s\n",tempp->ID,tempp->firstname,tempp->lastname); } } /* print out the registration list of a course to a text file */ void PrintClassRegistrationInFile(FILE *outfile,registrateT *registratep,int callcode) { registrateT *tempp; for(tempp=registratep;tempp!=NULL;tempp=tempp->restp){ if(tempp->callcode==callcode) fprintf(outfile,"%d %s \n",tempp->ID,tempp->grade); } } /* get grade of a student */ void GetGrade(registrateT *registratep,courseT *coursep,int ID,int chdev) { FILE *infile; registrateT *tempp; registrateT registrate; char datafile[5]; int status; int found=0; for(tempp=registratep;tempp!=NULL;tempp=tempp->restp){ if(tempp->ID==ID){ found=1; itoa(tempp->callcode,datafile,10); strcat(datafile,".txt"); if((infile=fopen(datafile,"r"))==NULL){ ShowCourse(coursep,tempp->callcode,chdev); //printf("has not been graded.\n"); Play(chdev,"notgrded.vox"); } else{ while((status=fscanf(infile,"%d%s",®istrate.ID,registrate.grade))==2){ if(registrate.ID==ID){ ShowCourse(coursep,tempp->callcode,chdev); //printf("grade "); Play(chdev,"grade.vox"); AnnChar(registrate.grade,chdev); printf("\n"); } } } } } if(tempp==NULL && found!=1) Play(chdev,"nocrse.vox"); } /* get the grades of all the students */ void GetAllGrade(registrateT *registratep,courseT *coursep,studentT *studentp,int chdev) { studentT *tempp; for(tempp=studentp;tempp!=NULL;tempp=tempp->restp){ //printf("\n%d\n",tempp->ID); AnnDigit(tempp->ID,chdev); GetGrade(registratep,coursep,tempp->ID,chdev); } } /* announce number by double digit */ void AnnDoubD(int num,int chdev) { int a1,a2; a1=num/100; a2=num%100; AnnTen(a1,chdev); if(a2==0) //printf("hundred "); Play(chdev,"hundred.vox"); else if(a2<10){ //printf("o "); Play(chdev,"o.vox"); AnnOne(a2,chdev); } else AnnTen(a2,chdev); } /* announce number which has two digits */ void AnnTen(int num,int chdev) { int ten; int one; ten=num/10; one=num%10; switch (ten){ case 0:AnnOne(one,chdev);break; case 9:/*printf("ninety ");*/Play(chdev,"ninety.vox");AnnOne(one,chdev);break; case 8:/*printf("eighty ");*/Play(chdev,"eighty.vox");AnnOne(one,chdev);break; case 7:/*printf("seventy ");*/Play(chdev,"seventy.vox");AnnOne(one,chdev);break; case 6:/*printf("sixty ");*/Play(chdev,"sixty.vox");AnnOne(one,chdev);break; case 5:/*printf("fifty ");*/Play(chdev,"fifty.vox");AnnOne(one,chdev);break; case 4:/*printf("forty ");*/Play(chdev,"forty.vox");AnnOne(one,chdev);break; case 3:/*printf("thirty ");*/Play(chdev,"thirty.vox");AnnOne(one,chdev);break; case 2:/*printf("twenty ");*/Play(chdev,"twenty.vox");AnnOne(one,chdev);break; case 1: switch (one){ case 9:/*printf("nineteen ");*/Play(chdev,"nineteen.vox");break; case 8:/*printf("eightteen ");*/Play(chdev,"eighteen.vox");break; case 7:/*printf("seventeen ");*/Play(chdev,"sevnteen.vox");break; case 6:/*printf("sixteen ");*/Play(chdev,"sixteen.vox");break; case 5:/*printf("fifteen ");*/Play(chdev,"fifteen.vox");break; case 4:/*printf("fourteen ");*/Play(chdev,"fourteen.vox");break; case 3:/*printf("thirteen ");*/Play(chdev,"thirteen.vox");break; case 2:/*printf("twelve ");*/Play(chdev,"twelve.vox");break; case 1:/*printf("eleven ");*/Play(chdev,"eleven.vox");break; case 0:/*printf("ten ");*/Play(chdev,"ten.vox");break; };break; } } /* announce number less than ten */ void AnnOne(int num,int chdev) { switch(num){ case 0:break; case 1:/*printf("one ");*/Play(chdev,"one.vox");break; case 2:/*printf("two ");*/Play(chdev,"two.vox");break; case 3:/*printf("three ");*/Play(chdev,"three.vox");break; case 4:/*printf("four ");*/Play(chdev,"four.vox");break; case 5:/*printf("five ");*/Play(chdev,"five.vox");break; case 6:/*printf("six ");*/Play(chdev,"six.vox");break; case 7:/*printf("seven ");*/Play(chdev,"seven.vox");break; case 8:/*printf("eight ");*/Play(chdev,"eight.vox");break; case 9:/*printf("nine ");*/Play(chdev,"nine.vox");break; } } /* annouce digit one by one */ void AnnDigit(int num,int chdev) { int i; int m=100000000; int digit; for(i=0;i<9;i++){ digit=num/m; if(digit==0) //printf("o "); Play(chdev,"o.vox"); else{ AnnOne(digit,chdev); } num=num-digit*m; m=m/10; } printf("\n"); } /* announce character */ void AnnChar(char ch[],int chdev) { if(strcmp(ch,"A")==0) //printf("A"); Play(chdev,"A.vox"); if(strcmp(ch,"B")==0) //printf("B"); Play(chdev,"B.vox"); if(strcmp(ch,"C")==0) //printf("C"); Play(chdev,"C.vox"); if(strcmp(ch,"D")==0) //printf("D"); Play(chdev,"D.vox"); if(strcmp(ch,"F")==0) //printf("F"); Play(chdev,"F.vox"); if(strcmp(ch,"W")==0) //printf("W"); Play(chdev,"W.vox"); } /* change the password */ void ChangePAC(studentT *studentp,int ID,int nPAC) { studentT *tempp; for(tempp=studentp;tempp!=NULL;tempp=tempp->restp){ if (tempp->ID==ID) tempp->PAC=nPAC; } } /* find the student as the receiver of the voicefile and add it to the voicefile link */ void FindAddFileNode(studentT *studentp,int ID,char filename[]) { studentT *tempp; for(tempp=studentp;tempp!=NULL;tempp=tempp->restp){ if(tempp->ID==ID) tempp->fileheadp=AddFileNode(tempp->fileheadp,filename); } } /* play the voicefiles of a student */ void PlayFile(studentT *studentp,int ID,int chdev) { studentT *tempp; for(tempp=studentp;tempp!=NULL;tempp=tempp->restp){ if(tempp->ID==ID) tempp->fileheadp=PlayVoiceFileLink(tempp->fileheadp,chdev); } } /* play voicefile and delete it from the link */ voicefileT *PlayVoiceFileLink(voicefileT *fileheadp,int chdev) { int command; char Filename1[20]; if(fileheadp==NULL){ //printf("You don't have new message\n"); Play(chdev,"nomssge.vox"); return(fileheadp); } else{ //printf("%s\n",fileheadp->filename); Play(chdev,fileheadp->filename); printf("Playing %s ",fileheadp->filename); /*printf("Please enter 1 to repeat,2 to go on to the next message,"); printf("0 to return to the previous manu\n");*/ do{ Play1(chdev,"manu3.vox"); //scanf("%d",&command); command=GetDigit1(chdev,1); switch (command){ case 1: Play(chdev,fileheadp->filename); break; case 2: strcpy(Filename1,fileheadp->filename); remove(strcat("c:\\tad\\",Filename1)); fileheadp=DeleteFileNode(fileheadp); if(fileheadp==NULL){ Play(chdev,"nomssge.vox"); return(fileheadp); } else Play(chdev,fileheadp->filename); break; default: strcpy(Filename1,fileheadp->filename); remove(strcat("c:\\tad\\",Filename1)); fileheadp=DeleteFileNode(fileheadp); break; } }while(command==1||command==2); return(fileheadp); } } /* delete a file name from the link of voicefile */ voicefileT *DeleteFileNode(voicefileT *fileheadp) { voicefileT *freep; if(fileheadp==NULL) return(fileheadp); else{ freep=fileheadp; fileheadp=freep->restp; free(freep); } return(fileheadp); } /* convert char to int to simulate the dial board*/ int CharToInt(char ch) { int m; ch=toupper(ch); switch(ch){ case 'A':case 'B':case 'C': m=2; break; case 'D':case 'E':case 'F': m=3; break; case 'G':case 'H':case 'I': m=4; break; case 'J':case 'K':case 'L': m=5; break; case 'M':case 'N':case 'O': m=6; break; case 'P':case 'Q':case 'R':case 'S': m=7; break; case 'T':case 'U':case 'V': m=8; break; case 'W':case 'X':case 'Y': m=9; break; case 'Z': m=0; break; } return(m); } /* play voice file,not allow digit to terminate */ void Play(int chdev,char* filename) { char Filename1[20]; DV_TPT tpt[2]; if(dx_clrdigbuf(chdev)==-1) printf("Can not clear digbuf\n"); dx_clrtpt(tpt,1); tpt[0].tp_type=IO_EOT; tpt[0].tp_termno=DX_MAXDTMF; tpt[0].tp_length=0; // one digit to terminate tpt[0].tp_flags=TF_MAXDTMF; tpt[1].tp_termno=DX_LCOFF; tpt[1].tp_length=3; tpt[1].tp_flags=TF_LCOFF|TF_10MS; strcpy(Filename1,"c:\\tad\\"); strcat(Filename1,filename); if(dx_playf(chdev,Filename1,tpt,EV_SYNC)==-1){ printf("Can not play record\n"); ErrFun(chdev); } } /* play file and allow one digit terminate */ void Play1(int chdev,char* filename) { char Filename1[20]; DV_TPT tpt[2]; if(dx_clrdigbuf(chdev)==-1) printf("Can not clear digbuf\n"); dx_clrtpt(tpt,1); tpt[0].tp_type=IO_EOT; tpt[0].tp_termno=DX_MAXDTMF; tpt[0].tp_length=1; //allow one digit terminate tpt[0].tp_flags=TF_MAXDTMF; tpt[1].tp_termno=DX_LCOFF; tpt[1].tp_length=3; tpt[1].tp_flags=TF_LCOFF|TF_10MS; strcpy(Filename1,"c:\\tad\\"); strcat(Filename1,filename); if(dx_playf(chdev,Filename1,tpt,EV_SYNC)==-1){ printf("Can not play record\n"); ErrFun(chdev); } } /* get the digit from phone ,not clear the digit buffer*/ int GetDigit1(int chdev,int num) { int value; DV_TPT tpt[2]; DV_DIGIT digp; int numdigs; dx_clrtpt(tpt,2); tpt[0].tp_type=IO_CONT; tpt[0].tp_termno=DX_MAXDTMF; //Max number of digits tpt[0].tp_length=num; //teminate on num digits tpt[0].tp_flags=TF_MAXDTMF; //terminate if already in buf tpt[0].tp_data=IO_CONT; tpt[1].tp_type=IO_EOT; tpt[1].tp_termno=DX_MAXTIME; //max function time tpt[1].tp_length=120; //12 seconds tpt[1].tp_flags=TF_MAXTIME; //edge triggerd if((numdigs=dx_getdig(chdev,tpt,&digp,EV_SYNC))==-1) printf("Can not get digit.\n"); value=atoi(digp.dg_value); return(value); } /* get the digit from phone */ int GetDigit(int chdev,int num) { int value; DV_TPT tpt[3]; DV_DIGIT digp; int numdigs; long termtype; //clear the buffer if(dx_clrdigbuf(chdev)==-1) printf("Can not clear digbuf\n"); dx_clrtpt(tpt,3); tpt[0].tp_type=IO_CONT; tpt[0].tp_termno=DX_MAXDTMF; //Max number of digits tpt[0].tp_length=num; //teminate on num digits tpt[0].tp_flags=TF_MAXDTMF; //terminate if already in buf tpt[0].tp_data=IO_CONT; tpt[1].tp_type=IO_EOT; tpt[1].tp_termno=DX_MAXTIME; //max function time tpt[1].tp_length=120; //12 seconds tpt[1].tp_flags=TF_MAXTIME; //edge triggerd if((numdigs=dx_getdig(chdev,tpt,&digp,EV_SYNC))==-1) printf("Can not get digit.\n"); termtype=ATDX_TERMMSK(chdev);//check termination reason if(termtype & TM_MAXTIME) //if maxtime out and not 8 digits value=-1; else value=atoi(digp.dg_value); return(value); } /* display error message */ void ErrFun(int chdev) { printf("Error message %s\n",ATDV_ERRMSGP(chdev)); } /* wait for the ring */ void WaitRing(int chdev) { printf("Waiting for ring...\n"); if(dx_wtring(chdev,1,DX_OFFHOOK,-1)==-1){ printf("Can not wait for ring\n"); ErrFun(chdev); } } /* record voice file */ void Rec(int chdev,char *filename) { char Filename1[20]; DV_TPT tpt[2]; dx_clrtpt(tpt,2); tpt[0].tp_type=IO_CONT; tpt[0].tp_termno=DX_MAXDTMF; tpt[0].tp_length=1; tpt[0].tp_flags=TF_MAXDTMF; /* get one digit to terminate */ tpt[1].tp_type=IO_EOT; tpt[1].tp_termno=DX_MAXSIL; tpt[1].tp_length=40; tpt[1].tp_flags=TF_MAXSIL|TF_SETINIT; tpt[1].tp_data=40; /* get 2 second of silence to teminate */ strcpy(Filename1,"c:\\tad\\"); strcat(Filename1,filename); printf("Recording...\n"); if(dx_recf(chdev,Filename1,tpt,RM_TONE)==-1){ printf("Can not record file\n"); ErrFun(chdev); } } /* initiate board */ int InitBoard(char *channel) { int chdev; if((chdev=dx_open(channel,NULL))==-1){ printf("Can not open Channel"); ErrFun(chdev); } SetHookOn(chdev); SetHookOff(chdev); //WaitRing(chdev); if(dx_setdigbuf(chdev,DX_DIGCYCLIC)==-1) printf("Can not setdigbuf\n"); return(chdev); } /* check ID and password */ int CheckID(int chdev,studentT *studentp,int *found,char firstname[],char lastname[]) { int IDtime=0; int ID; int PAC; int wrong=0; /* allow to input logon ID and personal access code for a max of 3 times */ do{ do{ // printf("Please enter your logon ID>"); Play(chdev,"enterID.vox"); //scanf("%d",&ID); ID=GetDigit(chdev,8); //if ID is not 8 digit if(ID==-1){ Play(chdev,"IDincorr.vox"); wrong++; } }while(ID==-1 && wrong<3); if(wrong<3){ //printf("Please enter your password>"); Play(chdev,"password.vox"); //scanf("%d",&PAC); PAC=GetDigit(chdev,6); if((*found=IDfound(studentp,ID,PAC,firstname,lastname))!=1) //printf("\nYour logon ID is not correct.\n"); Play(chdev,"IDincorr.vox"); IDtime++; } }while(*found!=1 && wrong<3 && IDtime<3); return(ID); } /* set hook on */ void SetHookOn(int chdev) { if(dx_sethook(chdev,DX_ONHOOK,EV_SYNC)==-1){ printf("Can not set hook on\n"); ErrFun(chdev); } } /* set hook off */ void SetHookOff(int chdev) { if(dx_sethook(chdev,DX_OFFHOOK,EV_SYNC)==-1){ printf("Can not set hook on\n"); ErrFun(chdev); } } char *IndicateTime(void) { struct tm when; time_t now; time( &now ); when = *localtime( &now ); return(asctime( &when )); }