#include <stdio.h>
#include <fcntl.h>
#include <sys\stat.h>
#include <io.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <process.h>
#include <stdarg.h>
#include <dos.h>
#include <bios.h>
#include <sys/timeb.h>
#include <share.h>
#include <sys/timeb.h>
#include <time.h>
#include "camkit.h"
int hasntvoted = 1;
char answer;
char answer1[60];
char answer2[60];
char answer3[60];
char answer4[60];
char answer5[60];
char answer6[60];
char answer7[60];
char answer8[60];
char answer9[60];
char answer10[60];
char answer11[60];
char answer12[60];
char answer13[60];
char answer14[60];
char date[10];
int TRUE1 = 1;
int vote[5];
int jouststoday = 0;
long endtime;
int extension=0;

/*****************************************************************
 *         M A I N   P R O C E D U R E   F O R   E D I T O R     *
 *****************************************************************/
main(argc,argv)
int argc;
char *argv[];
{
   int count;
  char answer, baudrate[6];
  if(argc != 4)
  {
    clrscr();
    printf("Either you enter too many paramters, or not enough to load the Door!\n\r");
    printf("Usage is: C:>CAMKIT BBSTYPE PATH/NAME MULTITASK[NO or YES]\r");
    printf("Example:  C:>CAMKIT PCB C:\\PCB\\PCBOARD.SYS NO\n\r");
    printf("Example:  C:>CAMKIT QBBS C:\\QUICKBBS\\DORINFO1.DEF YES\n\r");
    printf("BBSTYPE:  Either PCB or QBBS (Must be in CAPS)\n\r");
    printf("PATH/NAME:  This is your PATH plus your BBS Information:\n\r");
    printf("            Your File Name should be something like:\n\r");
    printf("            PCBOARD.SYS  [For PCBoard 14.x]\n\r");
    printf("            DORINFO1.DEF [For QuickBBS 2.04]\n\r");
    printf("MULTITASK:  Either Answer YES or NO [In CAPS].  If you are using\n\r");
    printf("            some type of multitasker set this option to YES\n\r");
    printf("            OtherWise set it to NO\n\r");
    printf("NOTE:  Multitasking was tried only under DoubleDos\n\r");
    exit(0);
  }
  strcpy(PATH,argv[2]);
  strcpy(MULTITASK,argv[3]);
  openall();
  testcarrier();
  cls();
  /*  Main Code Goes Here */

  cls();
  DisplayBar();
  pwhite(CLEAR);
/*  DisplayFile("\\pcb\\gen\\cnfn");   Display a File On Startup */
      pred("                               W  E  L  C  O  M  E\n\r");
      pred("                                       T  O\n\r");
      pred("                          T H E E  S C R I P T  D O O R");
  pmagenta("\n\r\n\r\n\r\n\r\n\r\n\r");
  pmagenta("                             Written by Cam N. DeBuck\n\r");
    pwhite("                           Copyright 1989 Cam N. DeBuck\n\r");
  pmagenta("\n\r\n\r\n\r");
  pmagenta("\n\r\n\r\n\r\n\r");
  sleep(2);
  DisplayBar();
  askfirst();
  questionaire();
  write_script_information("INFO.TXT");
  exitit();
  /*  End Main Code Here */
  exitit();
}


showinfo()
{
  pblue("\n\r\n\rHere are the Answers You Replied to Each Question\n\r\n\r");
  pred("Question 1: ");
  pwhite(answer1);
  pwhite("\r");
  pred("Question 2: ");
  pwhite(answer2);
  pwhite("\r");
  pred("Question 3: ");
  pwhite(answer3);
  pwhite("\r");
  pred("Question 4: ");
  pwhite(answer4);
  pwhite("\r");
  pred("Question 5: ");
  pwhite(answer5);
  pwhite("\r");
  pred("Question 6: ");
  pwhite(answer6);
  pwhite("\r");
  pred("Question 7: ");
  pwhite(answer7);
  pwhite("\r");
  pred("Question 8: ");
  pwhite(answer8);
  pwhite("\r");
  pred("Question 9: ");
  pwhite(answer9);
  pwhite("\r");
  pred("Question 10: ");
  pwhite(answer10);
  pwhite("\r");
  pred("Question 11: ");
  pwhite(answer11);
  pwhite("\r");
  pred("Question 12: ");
  pwhite(answer12);
  pwhite("\r");
  pred("Question 13: ");
  pwhite(answer13);
  pwhite("\r");
  if(extension)
  {
    pred("Question 14: ");
    pwhite(answer14);
    extension = 0;
    pwhite("\r\n\r");
    strcat(answer13," ");
    strcat(answer13,answer14);
  }
  pyellow("\n\rDid you Answer *ALL* Questions Correctly? (Y/N)\n\r");
  pblue("[-]\n\r ");
  getstring(1);
  answer = command_string[0];
  if(answer=='y')
    answer = 'Y';
  strcat(answer13,"\n");
}

extension13()
{
  pwhite("What is the Name and Number of your BBS?\n\r");
  pblue("[-------------------------------------(000)000-0000]\n\r ");
  getstring(50);
  strcpy(answer14,command_string);
  extension = 1;
}

write_script_information(char filename[20])
{
  int fptr;
char quest1[]={"Q: What Kind(s) Of Computer(s) Do You Use?\n"};
char quest2[]={"Q: How Long Have You Been UsingComputers?\n"};
char quest3[]={"Q: What Do You Use Your Computer For?\n"};
char quest4[]={"Q: Are You Calling From Out Of State? (Y/N)  <RESPONSE REQUIRED>\n"};
char quest5[]={"Q: What Is Your Age?\n"};
char quest6[]={"Q: What Is Your Street Address?              <RESPONSE REQUIRED>\n"};
char quest7[]={"Q: What Is Your City/State & Zip?            <RESPONSE REQUIRED>\n"};
char quest8[]={"Q: What Is A Phone Number You Can Be Reached At For Verification?    <REQUIRED>\n"};
char quest9[]={"Q: What Is The Name & Number Of Your Favorite BBS?\n"};
char quest10[]={"Q: How Often Do You Call Bulletin Boards?\n"};
char quest11[]={"Q: What Do You Like Most About Bulletin Boards?\n"};
char quest12[]={"Q: What Do You Like Least About Bulletin Boards?  <Besides LONG Questionaires>\n"};
char quest13[]={"Q: Are You A Sysop, If Yes, What Is The Name/Number Of Your Board? <Y/N> <REQ>\n"};
char ans1[]={"A: "};
char aster[]={"**************************************************************\n"};
char endit[]={"\n"};
char from[]={"From: "};
  currentdate();
  fptr = sopen(filename,O_WRONLY | O_APPEND | O_CREAT | O_TEXT, SH_DENYNONE,S_IWRITE);

  write(fptr,&aster,strlen(aster));
  write(fptr,&from,strlen(from));
  write(fptr,&Name,strlen(Name));
  write(fptr,&date,strlen(date));
  write(fptr,&endit,strlen(endit));
  write(fptr,&quest1,strlen(quest1));
  write(fptr,&ans1,strlen(ans1));
  write(fptr,&answer1,strlen(answer1));
  write(fptr,&quest2,strlen(quest2));
  write(fptr,&ans1,strlen(ans1));
  write(fptr,&answer2,strlen(answer2));
  write(fptr,&quest3,strlen(quest3));
  write(fptr,&ans1,strlen(ans1));
  write(fptr,&answer3,strlen(answer3));
  write(fptr,&quest4,strlen(quest4));
  write(fptr,&ans1,strlen(ans1));
  write(fptr,&answer4,strlen(answer4));
  write(fptr,&quest5,strlen(quest5));
  write(fptr,&ans1,strlen(ans1));
  write(fptr,&answer5,strlen(answer5));
  write(fptr,&quest6,strlen(quest6));
  write(fptr,&ans1,strlen(ans1));
  write(fptr,&answer6,strlen(answer6));
  write(fptr,&quest7,strlen(quest7));
  write(fptr,&ans1,strlen(ans1));
  write(fptr,&answer7,strlen(answer7));
  write(fptr,&quest8,strlen(quest8));
  write(fptr,&ans1,strlen(ans1));
  write(fptr,&answer8,strlen(answer8));
  write(fptr,&quest9,strlen(quest9));
  write(fptr,&ans1,strlen(ans1));
  write(fptr,&answer9,strlen(answer9));
  write(fptr,&quest10,strlen(quest10));
  write(fptr,&ans1,strlen(ans1));
  write(fptr,&answer10,strlen(answer10));
  write(fptr,&quest11,strlen(quest11));
  write(fptr,&ans1,strlen(ans1));
  write(fptr,&answer11,strlen(answer11));
  write(fptr,&quest12,strlen(quest12));
  write(fptr,&ans1,strlen(ans1));
  write(fptr,&answer12,strlen(answer12));
  write(fptr,&quest13,strlen(quest13));
  write(fptr,&ans1,strlen(ans1));
  write(fptr,&answer13,strlen(answer13));
  close(fptr);
}

questionaire()
{
  pblue("                       Hacker's Haven Script Questionaire\n\r");
  pblue("          If You Are A First Time User, Please Answer All Questions!\n\r");
  pblue("                 Upon Doing So, Your Access Will Be Increased\n\r");
  while(answer!='Y')
  {
    question1();
    question2();
    question3();
    question4();
    question5();
    question6();
    question7();
    question8();
    question9();
    question10();
    question11();
    question12();
    question13();
    showinfo();
  }

}
question1()
{
    pblue("What Kind(s) Of Computer(s) Do You Use? \n\r");
    pblue("[-------------------------------------------------------]\n\r ");
    getstring(55);
    strcpy(answer1,command_string);
    strcat(answer1,"\n");
}
question2()
{
  pgreen("How Long Have You Been Using Computers?\n\r");
  pblue("[-------------------------------------------------------]\n\r ");
  getstring(55);
  strcpy(answer2,command_string);
    strcat(answer2,"\n");
}
question3()
{
  pwhite("What Do You Use Your Computer For?\n\r");
  pblue("[-------------------------------------------------------]\n\r ");
  getstring(55);
  strcpy(answer3,command_string);
    strcat(answer3,"\n");
}
question4()
{
  pyellow("Are You Calling From Out Of State? (Y/N)\n\r");
  pblue("[-]\n\r ");
  getstring(1);
  if(command_string[0]=='y')
    command_string[0] = 'Y';
  strcpy(answer4,command_string);
    strcat(answer4,"\n");
}
question5()
{
  pmagenta("What Is Your Age?\n\r");
  pblue("[--]\n\r ");
  getstring(2);
  strcpy(answer5,command_string);
    strcat(answer5,"\n");
}
question6()
{
  pgreen("What Is Your Street Address?  (Important To Send You Your New Password)\n\r");
  pblue("[-------------------------------------------------------]\n\r ");
  getstring(55);
  strcpy(answer6,command_string);
  strcat(answer6,"\n");
}
question7()
{
  pwhite("What Is Your City/State & Zip? (Important To Send You Your New Password)\n\r");
  pblue("[-------------------------------------------------------]\n\r ");
  getstring(55);
  strcpy(answer7,command_string);
  strcat(answer7,"\n");
}
question8()
{
  pyellow("What Is A Phone Number You Can Be Reached At For Verification? <REQUIRED>\n\r");
  pblue("[(000)000-0000]\n\r ");
  getstring(13);
  strcpy(answer8,command_string);
  strcat(answer8,"\n");
}
question9()
{
  pmagenta("What Is The Name & Number Of Your Favorite BBS?\n\r");
  pblue("[------------------------------------------(000)000-0000]\n\r ");
  getstring(55);
  strcpy(answer9,command_string);
  strcat(answer9,"\n");
}
question10()
{
  pgreen("How Often Do You Call Bulletin Boards?\n\r");
  pblue("[-------------------------------------------------------]\n\r ");
  getstring(55);
  strcpy(answer10,command_string);
  strcat(answer10,"\n");
}
question11()
{
  pyellow("What Do You Like Most About Bulletin Boards?\n\r");
  pblue("[-------------------------------------------------------]\n\r ");
  getstring(55);
  strcpy(answer11,command_string);
  strcat(answer11,"\n");
}
question12()
{
  pwhite("What Do You Like Least About Bulletin Boards? <Besides LONG Questionaires>\n\r");
  pblue("[-------------------------------------------------------]\n\r ");
  getstring(55);
  strcpy(answer12,command_string);
  strcat(answer12,"\n");
}
question13()
{
  pred("Are You A Sysop? (Y/N) [Co-Sysop isn't a VALID YES]\n\r");
  pblue("[-]\n\r ");
  getstring(1);
  if(command_string[0]=='y')
    command_string[0] = 'Y';
  strcpy(answer13,command_string);
  if(command_string[0] == 'Y')
    extension13();
  else
  if(command_string[0] == 'y')
    extension13();
}

askfirst()
{
  pwhite("\n\r\n\r");
  pyellow("Are You Calling Long Distance (Y/N)?\n\r");
  pblue("[-]\n\r ");
  getstring(1);
  if(command_string[0]=='y')
    command_string[0]='Y';
  if(command_string[0]!='Y')
    baduser();
  pwhite("\n\r\n\r");
}

baduser()
{
  pmagenta("Sorry, the Script Questionaire Is For Long Distance Callers *ONLY*\n\r");
  pgreen("Please Use The Verification Door [Door #4]\n\r");
  pyellow("Thank You\n\r");
   pwhite("  --Ed & Cam--\n\r\n\r\n\r");
   pred("Returning To The Professional Executive Connection\n\r\n\r");
  exitit();
}

currentdate()
{
  struct tm *tm_now;
  time_t secs_now;
  char *str_now;
  char month[4];
  char day[4];
  char year[6];
  char time2[10];

  time(&secs_now);

  tm_now = localtime(&secs_now);
  ++tm_now->tm_mon;

  itoa(tm_now->tm_mon,month,10);
  itoa(tm_now->tm_mday,day,10);
  itoa(tm_now->tm_year,year,10);

  strcpy(date,", ");
  if(strlen(month)==1)
    strcat(date,"0");
  strcat(date,month);
  strcat(date,"-");
  if(strlen(day)==1)
    strcat(date,"0");
  strcat(date,day);
  strcat(date,"-");
  strcat(date,year);
  strcat(date," ");
  strcat(date,"(");
  time2[0]=pcb.TimeOn[0];
  time2[1]=pcb.TimeOn[1];;
  time2[2]=pcb.TimeOn[2];;
  time2[3]=pcb.TimeOn[3];;
  time2[4]=pcb.TimeOn[4];;
  time2[5]='\0';
  strcat(date,time2);
  strcat(date,")");
}
