#include "UserEdit.h"

void ViewMess(void);

/// EditMess()
void EditMess(void)
{
   BOOL  b;
   BOOL  Write    = FALSE;
   char  c[2];
   long  l;

   while(TRUE)
   {
      ViewMess();

      DLGInput("Select letter to edit parameter -> ",NULL,c,NULL,1,1,1);
      TwoLines();

      if(Sysop)
      {

///      Change Netmail Credit (A)
         if(!Strnicmp(c,"A",1))
         {
            l = IntQuery("Netmail Credits -> ",1,10000,0,&uin);
            TwoLines();

            if(l == 0) continue;

            if(udat.credit != (SHORT)l)
            {
               udat.credit = (SHORT)l;
               AFPrintf(&UserDat,sout,"%a7Changed!\n\n");
               Write = TRUE;
            }
         }
//-

///      Change Netmail Write Access (B)
         if(!Strnicmp(c,"B",1))
         {
            BOOL n;

            b = BoolQuery("Enable Netmail Write Access -> ",FALSE,&uin);
            TwoLines();

            n = udat.NetMail & NET_WRITE;

            if(n != (char)b)
            {
               if(b)
                  udat.NetMail = udat.NetMail | NET_WRITE;
               else
                  udat.NetMail = udat.NetMail & ~NET_WRITE;

               AFPrintf(&UserDat,sout,"%a7Changed!\n\n");
               Write = TRUE;
            }
         }
//-

///      Change Netmail CRASH Access (C)
         if(!Strnicmp(c,"C",1))
         {
            BOOL n;

            b = BoolQuery("Enable Netmail CRASH Access -> ",FALSE,&uin);
            TwoLines();

            n = udat.NetMail & NET_SYSOP;

            if(n != (char)b)
            {
               if(b)
                  udat.NetMail = udat.NetMail | NET_SYSOP;
               else
                  udat.NetMail = udat.NetMail & ~NET_SYSOP;

               AFPrintf(&UserDat,sout,"%a7Changed!\n\n");
               Write = TRUE;
            }
         }
//-

///      Change email write Access (D)
         if(!Strnicmp(c,"D",1))
         {
            BOOL u;

            b = BoolQuery("Enable Email Write Access -> ",FALSE,&uin);
            TwoLines();

            u = udat.UUCP & USENET_ACCESS;

            if(u != (char)b)
            {
               if(b)
                  udat.UUCP = udat.UUCP | USENET_ACCESS;
               else
                  udat.UUCP = udat.UUCP & ~USENET_ACCESS;

               AFPrintf(&UserDat,sout,"%a7Changed!\n\n");
               Write = TRUE;
            }
         }
//-

      }

///   Change Last Message Area (E)
      if(!Strnicmp(c,"E",1))
      {
         l = IntQuery("Last Message Area (-1 for PRVT) -> ",-1,999999,0,&uin);
         TwoLines();

         if(l == 0) continue;

         if(udat.Last_Area != l)
         {
            udat.Last_Area = l;
            AFPrintf(&UserDat,sout,"%a7Changed!\n\n");
            Write = TRUE;
         }
      }
//-

///   Change Capture settings (F)
      if(!Strnicmp(c,"F",1))
      {
         char f;

         f = udat.captureflags;

         b = BoolQuery("Enable Capture Settings -> ",FALSE,&uin);
         TwoLines();

         if(!b)
         {
            udat.captureflags = 0;
         }
         else
         {
            udat.captureflags = udat.captureflags | CAP_ENABLED;

            b = BoolQuery("Capture ANSI sequences -> ",FALSE,&uin);
            TwoLines();

            if(b)
               udat.captureflags = udat.captureflags | CAP_ANSI;
            else
               udat.captureflags = udat.captureflags & ~CAP_ANSI;

            b = BoolQuery("Enable MORE prompt during captures -> ",FALSE,&uin);
            TwoLines();

            if(b)
               udat.captureflags = udat.captureflags | CAP_MORE;
            else
               udat.captureflags = udat.captureflags & ~CAP_MORE;
         }

         if(f != udat.captureflags)
         {
            AFPrintf(&UserDat,sout,"%a7Changed!\n\n");
            Write = TRUE;
         }
      }
//-

///   Edit Message NewScan (G)
      if(!Strnicmp(c,"G",1))
      {
         EditScan(0);
      }
//-


///   Exit
      if(!Strnicmp(c,"X",1))
      {
         if(Write && Sysop)
         {
            struct NameStruct ns;

            strcpy(ns.name,name);

            if(0 == DeleteStruct(NAMERECORD,(char *)&ns,sizeof(struct NameStruct),30))
            {
               char fname[128];

               strcpy(ns.alias,udat.Alias);
               strcpy(ns.email,udat.Email);
               AddStruct(NAMERECORD,(char *)&ns,sizeof(struct NameStruct),30);

               ASPrintf(NULL,fname,"USER:%s/User.Data",name);
               UnderScore(fname);

               if(Same) memcpy(&UserDat,&udat,sizeof(struct USER_DATA));
               DeleteFile(fname);
               DumpFile(fname,(char *)&udat,sizeof(struct USER_DATA));
            }

            AFPrintf(&UserDat,sout,"%a7Changes saved.\n\n");
            Pause();
         }
         else
         {
            if(Sysop)
            {
               AFPrintf(&UserDat,sout,"%a7User record unchanged.\n\n");
               Pause();
            }
         }

         break;
      }
//-

///   Quit
      if(!Strnicmp(c,"Q",1))
      {
         if(Write)
         {
            AFPrintf(&UserDat,sout,"%b7 %a1NOTE: %b0%a7 Changes not saved!\n\n");
            Pause();
         }

         break;
      }
//-

   }

   return;
}
//-

/// ViewAcct()
void ViewMess(void)
{
   char temp[128];

   Clr(UserDat.Ansi_Flag);
   AFPrintf(&UserDat,sout,"\n%a6Message Preferences for user %a2[%au%a7%s%ao%a2]%a7\n",name);
   Draw_Line(UserDat.Screen_Width);

   if(Sysop)
      AFPrintf(&UserDat,sout,"%b0%a2[%a7A%a2] %a6NETMAIL CREDIT ....... %b7%a4 %-5d   ",udat.credit);
   else
      AFPrintf(&UserDat,sout,"%b0%a2[ ] %a6NETMAIL CREDIT ....... %b7%a1 %-5d   ",udat.credit);

   if(Sysop)
      AFPrintf(&UserDat,sout,"%b0  %a2[%a7B%a2] %a6NETMAIL WRITE ACCESS . %b7%a4 %-3.3s \n",(udat.NetMail & NET_WRITE) ? "YES" : "NO");
   else
      AFPrintf(&UserDat,sout,"%b0  %a2[ ] %a6NETMAIL WRITE ACCESS . %b7%a1 %-3.3s \n",(udat.NetMail & NET_WRITE) ? "YES" : "NO");

   if(Sysop)
      AFPrintf(&UserDat,sout,"%b0%a2[%a7C%a2] %a6NETMAIL CRASH ACCESS . %b7%a4 %-3.3s     ",(udat.NetMail & NET_SYSOP) ? "YES" : "NO");
   else
      AFPrintf(&UserDat,sout,"%b0%a2[ ] %a6NETMAIL CRASH ACCESS . %b7%a1 %-3.3s     ",(udat.NetMail & NET_SYSOP) ? "YES" : "NO");

   if(Sysop)
      AFPrintf(&UserDat,sout,"%b0  %a2[%a7D%a2] %a6EMAIL WRITE ACCESS ... %b7%a4 %-3.3s \n",(udat.UUCP & USENET_ACCESS) ? "YES" : "NO");
   else
      AFPrintf(&UserDat,sout,"%b0  %a2[ ] %a6EMAIL WRITE ACCESS ... %b7%a1 %-3.3s \n",(udat.UUCP & USENET_ACCESS) ? "YES" : "NO");

   AFPrintf(&UserDat,sout,"%b0%a7");
   Draw_Line(UserDat.Screen_Width);

   if(udat.Last_Area == PVTAREA)
      ASPrintf(NULL,temp,"PRIVATE");
   else
      ASPrintf(NULL,temp,"%-6ld",udat.Last_Area);

   AFPrintf(&UserDat,sout,"%b0%a2[%a7E%a2] %a6LAST MESSAGE AREA .... %b7%a4 %-7.7s \n",temp);

   if(udat.captureflags & CAP_ENABLED)
      ASPrintf(NULL,temp,"ACTIVE: ANSI = %s  MORE = %s",(udat.captureflags & CAP_ANSI) ? "ON" : "OFF",
                                                        (udat.captureflags & CAP_MORE) ? "ON" : "OFF");
   else
      ASPrintf(NULL,temp,"INACTIVE");

   AFPrintf(&UserDat,sout,"%b0%a2[%a7F%a2] %a6CAPTURE SETTINGS ..... %b7%a4 %-30.30s \n",temp);

   AFPrintf(&UserDat,sout,"%b0%a7");
   Draw_Line(UserDat.Screen_Width);

   AFPrintf(&UserDat,sout,"%b0%a2[%a7G%a2] %a6CHANGE NEWSCAN AREAS   ");
   AFPrintf(&UserDat,sout,"%b0           %a2[%a7I%a2] %a6CHANGE ARCHIVE AREAS\n");

   AFPrintf(&UserDat,sout,"%b0%a7");
   Draw_Line(UserDat.Screen_Width);

   AFPrintf(&UserDat,sout,"%a2[%a7H%a2] %a6Help    %a2[%a7?%a2] %a6Re-Display    %a2[%a7X%a2] %a6Save and Exit   %a2[%a7Q%a2] %a6Quit (no save)%a7\n");
   Draw_Line(UserDat.Screen_Width);

   AFPrintf(&UserDat,sout,"    %a6Text in %b7 %a1Red Text %b0%a6 is not editable.%a7\n");
   Draw_Line(UserDat.Screen_Width);
   OneLine();

   return;
}
//-
