--Copyright Simlor (http://www.computercraft.info/forums2/index.php?/user/55655-simlor/) -  Alle Rechte an diesen Programm sind Simlor vorbehalten.

--AcManager

backD = false
AC = 0

while true do

 Rechte()

 file = fs.open("SimSoft/Data/Config","r")
 local fileData = {}
 local line = file.readLine()
 repeat
 table.insert(fileData,line)
 line = file.readLine()
 until line == nil
 file.close()

 PassSOO = fileData[1]
 Hintergrund = fileData[2]
 Version = fileData[3]
 Sprache = fileData[4]
 --
 file = fs.open("SimSoft/Data/User/User1","r")
 local fileData = {}
 local line = file.readLine()
 repeat
 table.insert(fileData,line)
 line = file.readLine()
 until line == nil
 file.close()

 u1 = fileData[1]
 p1 = fileData[2]
 --
 file = fs.open("SimSoft/Data/User/User2","r")
 local fileData = {}
 local line = file.readLine()
 repeat
 table.insert(fileData,line)
 line = file.readLine()
 until line == nil
 file.close()

 u2 = fileData[1]
 p2 = fileData[2]
 ACTF2 = fileData[3]
 --
 file = fs.open("SimSoft/Data/User/User3","r")
 local fileData = {}
 local line = file.readLine()
 repeat
 table.insert(fileData,line)
 line = file.readLine()
 until line == nil
 file.close()

 u3 = fileData[1]
 p3 = fileData[2]
 ACTF3 = fileData[3]
 --

 BC(256)
 Clear()

 SimSoftBalken("SimSoft 4 - AcManager", 21)

 BC(256)
 
 w, h = term.getSize()
 
 wa = (w-6)
 
 CP(wa,5)
 TC(32)
 if Recht == "Guest" then
  recht = " User"
 elseif Recht == "Admin" then
  recht = "Admin"
 end
 print(recht)

 if AC == 0 then
  BC(256)
  CP(1,6)
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  
  BC(256)
  TC(1)
  CP(3,6)
  print(" Choose an account ")
  
  
  w, h = term.getSize()
  h = (h-1)
  BC(256)
  TC(1)
  CP(3,h)
  print("Desktop")
  
  while true do
   event,side,x,y = os.pullEvent()
   if event == "mouse_click" then
   
    if x >= 3 and x <= 9 and y == h then
	 backD = true
	 break
	end
    
	if x >= 3 and x <= 21 and y == 6 then
	 TC(1)
	 CP(3,6)
	 BC(8)
	 print(" Choose an account ")
	 TC(8)
	 BC(1)
	 CP(3,7)
	 print("                   ")
	 TC(1)
	 BC(8)
	 CP(3,8)
	 print(" Account 1 - Adm.  ")
	 TC(8)
	 BC(1)
	 CP(3,9)
	 print(" Account 2         ")
	 TC(1)
	 BC(8)
	 CP(3,10)
	 print(" Account 3         ")
	 
	 while true do
      event,side,x,y = os.pullEvent()
      if event == "mouse_click" then
	   
	   if x >= 3 and x <= 21 and y == 8 then
	    AC = 1
		break
	   elseif x >= 3 and x <= 21 and y == 9 then
	    AC = 2
		break
	   elseif x >= 3 and x <= 21 and y == 10 then
	    AC = 3
		break
	   elseif x >= 3 and x <= 21 and y >= 11 and y <= 19 or x >= 1 and x <= 51 and y >= 1 and y <= 5 or x >= 1 and x <= 2 and y >= 1 and y <= 19 or x >= 22 and x <= 51 and y >= 1 and y <= 19 then
	    AC = 0
		break
	   end
	  end
	 end
	end
	break
   end
  end
  
 elseif AC == 1 then
  BC(256)
  CP(1,6)
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  
  BC(256)
  TC(1)
  CP(3,6)
  print(" Account 1 - Admin ")
  
  w, h = term.getSize()
  h = (h-1)
  BC(256)
  TC(1)
  CP(3,h)
  print("Desktop")
  
  BC(256)
  TC(1)
  CP(4,9)
  write("Edit name")
  TC(128)
  print(" - "..u1)
  
  BC(256)
  TC(1)
  CP(4,11)
  write("Edit password")
  TC(128)
  print(" - ******")
  
  CP(4, 13)
  BC(256)
  TC(128)
  print("Login on/off")
  
  if PassSOO == "true" then
   CP(18,13)
   if Recht == "Admin" then
    BC(8)
    write("  ")
    BC(32768)
    print(" ")
   else 
    BC(16384)
    write("  ")
    BC(32768)
    print(" ")
   end
  else
   CP(18,13)
   if Recht == "Admin" then
    BC(32768)
    write(" ")
    BC(128)
    print("  ")
   else 
    BC(32768)
    write(" ")
    BC(16384)
    print("  ")
   end
  end
  
  while true do
   event,side,x,y = os.pullEvent()
   if event == "mouse_click" then
    
	if x >= 18 and x <= 20 and y == 13 then
	 if Recht == "Admin" then 
	  if PassSOO == "true" then
	   PassSOO = "false"
	  else
	   PassSOO = "true"
	  end
	 
	  local file = fs.open("SimSoft/Data/Config","w") 
      file.close()
	  local file = fs.open("SimSoft/Data/Config","w") 
	  file.writeLine(PassSOO)
	  file.writeLine(Hintergrund)
	  file.writeLine(Version)
	  file.writeLine(Sprache)
      file.close()
	 end
	end
	
	if x >= 3 and x <= 9 and y == h then
	 backD = true
	 break
	end
   
    if x >= 4 and x <= 12 and y == 9 then
	
	 if Recht == "Admin" then 
	  BC(256)
	  CP(16,9)
	  TC(128)
	  print("                         ")
	  CP(16,9)
	  nname = read()
	 
	  local file = fs.open("SimSoft/Data/User/User1","w") 
      file.close()
	  local file = fs.open("SimSoft/Data/User/User1","w") 
	  file.writeLine(nname)
	  file.writeLine(p1)
      file.close()
	  CP(16,9)
	  TC(32)
	  print("Saved!")
	  sleep(0.2)
	  break
	 else
	  CP(16,9)
	  BC(256)
	  TC(16384)
	  print("You are not a admin     ")
	  sleep(1)
	  break
	 end
	end
	
	if x >= 4 and x <= 16 and y == 11 then
	
	 if Recht == "Admin" then 
	  BC(256)
	  CP(20,11)
	  TC(128)
	  print("                         ")
	  CP(20,11)
	  npass = read("*")
	 
	  local file = fs.open("SimSoft/Data/User/User1","w") 
      file.close()
	  local file = fs.open("SimSoft/Data/User/User1","w") 
	  file.writeLine(u1)
	  file.writeLine(npass)
      file.close()
	  CP(20,11)
	  TC(32)
	  print("Saved!                  ")
	  sleep(0.2)
	  break
	 else
	  CP(20,11)
	  BC(256)
	  TC(16384)
	  print("You are not a admin     ")
	  sleep(1)
	  break
	 end
	end
	 
    
	if x >= 3 and x <= 21 and y == 6 then
	 TC(1)
	 CP(3,6)
	 BC(8)
	 print(" Choose an account ")
	 TC(8)
	 BC(1)
	 CP(3,7)
	 print("                   ")
	 TC(1)
	 BC(8)
	 CP(3,8)
	 print(" Account 1 - Adm.  ")
	 TC(8)
	 BC(1)
	 CP(3,9)
	 print(" Account 2         ")
	 TC(1)
	 BC(8)
	 CP(3,10)
	 print(" Account 3         ")
	 
	 while true do
      event,side,x,y = os.pullEvent()
      if event == "mouse_click" then
	   
	   if x >= 3 and x <= 21 and y == 8 then
	    AC = 1
		break
	   elseif x >= 3 and x <= 21 and y == 9 then
	    AC = 2
		break
	   elseif x >= 3 and x <= 21 and y == 10 then
	    AC = 3
		break
	   elseif x >= 3 and x <= 21 and y >= 11 and y <= 19 or x >= 1 and x <= 51 and y >= 1 and y <= 5 or x >= 1 and x <= 2 and y >= 1 and y <= 19 or x >= 22 and x <= 51 and y >= 1 and y <= 19 then
	    AC = 1
		break
	   end
	  end
	 end 
	end
	break
   end
  end
  
  elseif AC == 2 then
  BC(256)
  CP(1,6)
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  
  BC(256)
  TC(1)
  CP(3,6)
  print(" Account 2 ")
  
  w, h = term.getSize()
  h = (h-1)
  BC(256)
  TC(1)
  CP(3,h)
  print("Desktop")
  
  BC(256)
  TC(1)
  CP(4,9)
  write("Edit name")
  TC(128)
  print(" - "..u2)
  
  BC(256)
  TC(1)
  CP(4,11)
  write("Edit password")
  TC(128)
  print(" - ******")
  
  if ACTF2 == "true" then
   CP(15,6)
   if Recht == "Admin" then
    BC(8)
    write("  ")
    BC(32768)
    print(" ")
   else 
    BC(16384)
    write("  ")
    BC(32768)
    print(" ")
   end
  else
   CP(15,6)
   if Recht == "Admin" then
    BC(32768)
    write(" ")
    BC(128)
    print("  ")
   else 
    BC(32768)
    write(" ")
    BC(16384)
    print("  ")
   end
  end
  
  while true do
   event,side,x,y = os.pullEvent()
   if event == "mouse_click" then
   
    if x >= 15 and x <= 17 and y == 6 then
	 if Recht == "Admin" then 
	  if ACTF2 == "true" then
	   ACTF2 = "false"
	  else
	   ACTF2 = "true"
	  end
	 
	  local file = fs.open("SimSoft/Data/User/User2","w") 
      file.close()
	  local file = fs.open("SimSoft/Data/User/User2","w") 
	  file.writeLine(u2)
	  file.writeLine(p2)
	  file.writeLine(ACTF2)
      file.close()
	 end
	end
   
    if x >= 3 and x <= 9 and y == h then
	 backD = true
	 break
	end
   
    if x >= 4 and x <= 12 and y == 9 then
	
	 if Recht == "Admin" or RechtH == 2 then 
	  BC(256)
	  CP(16,9)
	  TC(128)
	  print("                         ")
	  CP(16,9)
	  nname = read()
	 
	  local file = fs.open("SimSoft/Data/User/User2","w") 
      file.close()
	  local file = fs.open("SimSoft/Data/User/User2","w") 
	  file.writeLine(nname)
	  file.writeLine(p2)
	  file.writeLine(ACTF2)
      file.close()
	  CP(16,9)
	  TC(32)
	  print("Saved!                   ")
	  sleep(0.2)
	  break
	 else
	  CP(16,9)
	  BC(256)
	  TC(16384)
	  print("You are not user 2     ")
	  sleep(1)
	  break
	 end
	end
	
	if x >= 4 and x <= 16 and y == 11 then
	
	 if Recht == "Admin" or RechtH == 2 then 
	  BC(256)
	  CP(20,11)
	  TC(128)
	  print("                         ")
	  CP(20,11)
	  npass = read("*")
	 
	  local file = fs.open("SimSoft/Data/User/User2","w") 
      file.close()
	  local file = fs.open("SimSoft/Data/User/User2","w") 
	  file.writeLine(u2)
	  file.writeLine(npass)
	  file.writeLine(ACTF2)
      file.close()
	  CP(20,11)
	  TC(32)
	  print("Saved!                  ")
	  sleep(0.2)
	  break
	 else
	  CP(20,11)
	  BC(256)
	  TC(16384)
	  print("You are not user 2    ")
	  sleep(1)
	  break
	 end
	end
	 
    
	if x >= 3 and x <= 13 and y == 6 then
	 TC(1)
	 CP(3,6)
	 BC(8)
	 print(" Choose an account ")
	 TC(8)
	 BC(1)
	 CP(3,7)
	 print("                   ")
	 TC(1)
	 BC(8)
	 CP(3,8)
	 print(" Account 1 - Adm.  ")
	 TC(8)
	 BC(1)
	 CP(3,9)
	 print(" Account 2         ")
	 TC(1)
	 BC(8)
	 CP(3,10)
	 print(" Account 3         ")
	 
	 while true do
      event,side,x,y = os.pullEvent()
      if event == "mouse_click" then
	   
	   if x >= 3 and x <= 21 and y == 8 then
	    AC = 1
		break
	   elseif x >= 3 and x <= 21 and y == 9 then
	    AC = 2
		break
	   elseif x >= 3 and x <= 21 and y == 10 then
	    AC = 3
		break
	   elseif x >= 3 and x <= 21 and y >= 11 and y <= 19 or x >= 1 and x <= 51 and y >= 1 and y <= 5 or x >= 1 and x <= 2 and y >= 1 and y <= 19 or x >= 22 and x <= 51 and y >= 1 and y <= 19 then
	    AC = 2
		break
	   end
	  end
	 end 
	end
	break
   end
  end
  
  elseif AC == 3 then
  BC(256)
  CP(1,6)
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  print("                                                   ")
  
  BC(256)
  TC(1)
  CP(3,6)
  print(" Account 3 ")
  
  w, h = term.getSize()
  h = (h-1)
  BC(256)
  TC(1)
  CP(3,h)
  print("Desktop")
  
  BC(256)
  TC(1)
  CP(4,9)
  write("Edit name")
  TC(128)
  print(" - "..u3)
  
  BC(256)
  TC(1)
  CP(4,11)
  write("Edit password")
  TC(128)
  print(" - ******")
  
  if ACTF3 == "true" then
   CP(15,6)
   if Recht == "Admin" then
    BC(8)
    write("  ")
    BC(32768)
    print(" ")
   else 
    BC(16384)
    write("  ")
    BC(32768)
    print(" ")
   end
  else
   CP(15,6)
   if Recht == "Admin" then
    BC(32768)
    write(" ")
    BC(128)
    print("  ")
   else 
    BC(32768)
    write(" ")
    BC(16384)
    print("  ")
   end
  end
  
  while true do
   event,side,x,y = os.pullEvent()
   if event == "mouse_click" then
   
    if x >= 15 and x <= 17 and y == 6 then
	 if Recht == "Admin" then 
	  if ACTF3 == "true" then
	   ACTF3 = "false"
	  else
	   ACTF3 = "true"
	  end
	 
	  local file = fs.open("SimSoft/Data/User/User3","w") 
      file.close()
	  local file = fs.open("SimSoft/Data/User/User3","w") 
	  file.writeLine(u3)
	  file.writeLine(p3)
	  file.writeLine(ACTF3)
      file.close()
	 end
	end
   
    if x >= 3 and x <= 9 and y == h then
	 backD = true
	 break
	end
   
    if x >= 4 and x <= 12 and y == 9 then
	
	 if Recht == "Admin" or RechtH == 3 then 
	  BC(256)
	  CP(16,9)
	  TC(128)
	  print("                         ")
	  CP(16,9)
	  nname = read()
	 
	  local file = fs.open("SimSoft/Data/User/User3","w") 
      file.close()
	  local file = fs.open("SimSoft/Data/User/User3","w") 
	  file.writeLine(nname)
	  file.writeLine(p3)
	  file.writeLine(ACTF3)
      file.close()
	  CP(16,9)
	  TC(32)
	  print("Saved!                   ")
	  sleep(0.2)
	  break
	 else
	  CP(16,9)
	  BC(256)
	  TC(16384)
	  print("You are not user 3     ")
	  sleep(1)
	  break
	 end
	end
	
	if x >= 4 and x <= 16 and y == 11 then
	
	 if Recht == "Admin" or RechtH == 3 then 
	  BC(256)
	  CP(20,11)
	  TC(128)
	  print("                         ")
	  CP(20,11)
	  npass = read("*")
	 
	  local file = fs.open("SimSoft/Data/User/User3","w") 
      file.close()
	  local file = fs.open("SimSoft/Data/User/User3","w") 
	  file.writeLine(u3)
	  file.writeLine(npass)
	  file.writeLine(ACTF3)
      file.close()
	  CP(20,11)
	  TC(32)
	  print("Saved!                  ")
	  sleep(0.2)
	  break
	 else
	  CP(20,11)
	  BC(256)
	  TC(16384)
	  print("You are not user 3     ")
	  sleep(1)
	  break
	 end
	end
	 
    
	if x >= 3 and x <= 13 and y == 6 then
	 TC(1)
	 CP(3,6)
	 BC(8)
	 print(" Choose an account ")
	 TC(8)
	 BC(1)
	 CP(3,7)
	 print("                   ")
	 TC(1)
	 BC(8)
	 CP(3,8)
	 print(" Account 1 - Adm.  ")
	 TC(8)
	 BC(1)
	 CP(3,9)
	 print(" Account 2         ")
	 TC(1)
	 BC(8)
	 CP(3,10)
	 print(" Account 3         ")
	 
	 while true do
      event,side,x,y = os.pullEvent()
      if event == "mouse_click" then
	   
	   if x >= 3 and x <= 21 and y == 8 then
	    AC = 1
		break
	   elseif x >= 3 and x <= 21 and y == 9 then
	    AC = 2
		break
	   elseif x >= 3 and x <= 21 and y == 10 then
	    AC = 3
		break
	   elseif x >= 3 and x <= 21 and y >= 11 and y <= 19 or x >= 1 and x <= 51 and y >= 1 and y <= 5 or x >= 1 and x <= 2 and y >= 1 and y <= 19 or x >= 22 and x <= 51 and y >= 1 and y <= 19 then
	    AC = 3
		break
	   end
	  end
	 end 
	end
	break
   end
  end
 end
 if backD == true then
  break
 end
end