#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author:         Palmers Julian

 Script Function:
	Dieses Programm soll visuell zeigen, welche Computer in welchem Stockwerk online sind.

#ce ----------------------------------------------------------------------------
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

global $selectedFloor, $s = 0, $raumnummer[100], $person[200][2], $online[2]

$iniPath = @ScriptDir&"\Config.ini"

$windowSize = StringSplit(IniRead($iniPath,"Look","windowSize","900%700"),"%",2)
$tabSize = StringSplit(IniRead($iniPath,"Look","tabSize","700%700"),"%",2)
$bmpSize = StringSplit(IniRead($iniPath,"Look","bmpSize","700%700"),"%",2)

$hWnd = GUICreate("WhoIsInTheHouse", $windowSize[0], $windowSize[1])
$console = GUICtrlCreateInput("0. Stock", 0, $windowSize[1]-25, $windowSize[0], 25, $ES_READONLY)
GUICtrlCreateLabel("Legende:", $tabSize[0]+15, 20)
GUICtrlCreatePic(@ScriptDir&"\legende.jpg", $tabSize[0]+30, 40, 79, 53)

$image = GUICtrlCreatePic(@ScriptDir&"\0.bmp", 2, 25, $tabSize[0]-30, $tabSize[1]-30)
$tab = GUICtrlCreateTab(0, 0, $tabSize[0], $tabSize[1])
$tab0 = GUICtrlCreateTabItem("0. Stock")
$tab1 = GUICtrlCreateTabItem("1. Stock")
$tab2 = GUICtrlCreateTabItem("2. Stock")
$tab3 = GUICtrlCreateTabItem("3. Stock")
$tab4 = GUICtrlCreateTabItem("4. Stock")
$tab5 = GUICtrlCreateTabItem("5. Stock")
GUISetState()

$whoIsWhoIni = IniReadSection($iniPath,"WhoIsWho")
$j = $whoIsWhoIni[0][0]
local $whoIsWho[$j-1][5]
For $i=2 To $j
	$data = StringSplit($whoIsWhoIni[$i][1],"%",2)
	$whoIsWho[$i-2][0] = $whoIsWhoIni[$i][0]	;IP-Adresse
 	$whoIsWho[$i-2][1] = $data[0]				;Computername
	$whoIsWho[$i-2][2] = $data[1]				;Nachname
	$whoIsWho[$i-2][3] = $data[2]				;Vorname
	$whoIsWho[$i-2][4] = $data[3]				;Raumnummer
Next
;~ _ArrayDisplay($whoIsWho)

$whereIsWhereIni = IniReadSection($iniPath,"WhereIsWhere")
$j = $whereIsWhereIni[0][0]
local $whereIsWhere[$j-1][4]
For $i=2 To $j
	$data = StringSplit($whereIsWhereIni[$i][1],"%",2)
	$whereIsWhere[$i-2][0] = $whereIsWhereIni[$i][0]	;Raumnummer
 	$whereIsWhere[$i-2][1] = $data[0]					;X-Koordinate
	$whereIsWhere[$i-2][2] = $data[1]					;Y-Koordinate
	$whereIsWhere[$i-2][3] = 0							;Computeranzahl
Next
;~ _ArrayDisplay($whereIsWhere)

While 1
	$msg = GUIGetMsg()
	If ($msg = $tab OR $s = False) Then
		$s = True
		$online[0] = 0		;Online
		$online[1] = 0		;Gesamtanzahl
		$selectedFloor = 0
		$selectedFloor = GUICtrlRead($tab)
		GUICtrlSetImage($image, @ScriptDir&"\"&$selectedFloor&".bmp")
		GUICtrlSetData($console, $selectedFloor&". Stock gewählt")
#region Raumnummern
;~ 		For $i = 0 To 99
;~ 			GUICtrlDelete($raumnummer[$i])
;~ 			$raumnummer[$i] = ""
;~ 		Next
;~ 		For $i = 0 To UBound($whereIsWhere)-1
;~ 			If (StringLeft($whereIsWhere[$i][0],1) = ($selectedFloor)) Then
;~ 				$raumnummer[$i] = GUICtrlCreateLabel($whereIsWhere[$i][0], 5+($whereIsWhere[$i][1])*($tabSize[0]/$bmpSize[0])*0.965, ($whereIsWhere[$i][2])*($tabSize[1]/$bmpSize[1])*0.965)
;~ 			EndIf
;~ 		Next
#endregion
		For $i = 0 To 199
			GUICtrlDelete($person[$i][0])
			$person[$i][0] = ""
			$person[$i][1] = ""
		Next
#region Display
		For $i = 0 To UBound($whereIsWhere)-1
			$whereIsWhere[$i][3] = "0"
		Next
		For $l=0 To UBound($whoIsWho)-1
			If (StringLeft($whoIsWho[$l][4],1) = ($selectedFloor)) Then
				$person[$l][0] = GUICtrlCreateCheckbox($whoIsWho[$l][1], 5+($whereIsWhere[_ArraySearch($whereIsWhere,$whoIsWho[$l][4],"","","","",0)][1])*($tabSize[0]/$bmpSize[0])*0.965, (($whereIsWhere[_ArraySearch($whereIsWhere,$whoIsWho[$l][4],"","","","",0)][2])*($tabSize[1]/$bmpSize[1])*0.965)-($whereIsWhere[_ArraySearch($whereIsWhere,$whoIsWho[$l][4],"","","","",0)][3]*25))
;~ 	TODO			GUICtrlSetTip($person[$l][0],"Computer: "&$whoIsWho[$l][1]&@CRLF&"IP: "&$whoIsWho[$l][0]&@CRLF&"Benutzer: "&$whoIsWho[$l][2]&" "&$whoIsWho[$l][3]&@CRLF&@CRLF&"Raum: "&$whoIsWho[$l][4])
				If (Ping($whoIsWho[$l][0],50)<>0 AND TRUE) Then
					GUICtrlSetState($person[$l][0], $GUI_CHECKED)
					$online[0] = $online[0]+1
				Else
					GUICtrlSetState($person[$l][0], $GUI_UNCHECKED)
					GUICtrlSetState($person[$l][0], $GUI_DISABLE)
				EndIf
				$online[1] = $online[1]+1
				$person[$l][1] = $whoIsWho[$l][1]
				$whereIsWhere[_ArraySearch($whereIsWhere,$whoIsWho[$l][4],"","","","",0)][3]=$whereIsWhere[_ArraySearch($whereIsWhere,$whoIsWho[$l][4],"","","","",0)][3]+1
				GUICtrlSetData($console, $whoIsWho[$l][1]&" wird gepingt")
			EndIf
		Next
;~ 		_ArrayDisplay($person)
		For $l=0 To UBound($person)-1
			GUICtrlSetTip($person[$l][0],"test")
		Next
		GUICtrlSetData($console, "Alle Computer im "&$selectedFloor&". Stock wurden überprüft - ("&$online[0]&" von "&$online[1]&" online)")
#endregion

	EndIf

	Select
		Case $msg = $GUI_EVENT_CLOSE
			GUIDelete()
			Exit
	EndSelect
WEnd