Hi,
ich habe für nen Kumpel mal fix ein Script geschrieben mit der er nen Teil seiner Webseite Updaten kann.
Eigentlich nicht schwer, leider werden mir irgenwo die Umlaute zerhackt. Ich vermute bei _FileWriteToLine
Kennt jemand eine Lösung für das Problem?
Es gibt noch ein zweites Problem, wenn jemand zufällig den Fehler findet bitte melden, ansonsten such ich den später selbst:
Nach einer aktualisierung verdoppelt sich beim nächsten mal der letzte Eintrag, starte ich das Script neu passiert das nicht.
Ansonsten funktioniert das Script einwandfrei
Spoiler anzeigen
;*****************************************
;Erstellt mit ISN AutoIt Studio v. 0.95 BETA
;*****************************************
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include "Forms\gui.isf"
; -- Created with ISN Form Studio 2 for ISN AutoIt Studio -- ;
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiButton.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <FTPEx.au3>
Global $aArray
Global $start
Global $ende
Global $fpath = @ScriptDir & "\ergebnisse.php"
Global $rfile = 'ergebnisse.php'
$server = ' '
$username = ' '
$pass = ' '
$gui = GUICreate("Update Ergebnisse",722,523,-1,-1,-1,-1)
$btn_hoch = GUICtrlCreateButton("Hoch",588,401,100,30,-1,-1)
$btn_runter = GUICtrlCreateButton("Runter",588,450,100,30,-1,-1)
Global $liste = GUICtrlCreatelistview("Titel |Text ",40,190,534,309,-1,512)
$inp_titel = GUICtrlCreateInput("",80,57,290,21,-1,512)
GUICtrlCreateLabel("Titel:",50,60,26,15,-1,-1)
GUICtrlSetBkColor(-1,"-2")
GUICtrlCreateLabel("Text:",50,100,24,15,-1,-1)
GUICtrlSetBkColor(-1,"-2")
GUICtrlSetStyle($liste, $LVS_REPORT, $LVS_EX_FULLROWSELECT)
$inp_text = GUICtrlCreateInput("",80,97,289,20,-1,512)
$btn_add = GUICtrlCreateButton("Hinzufügen",406,53,100,30,-1,-1)
$btn_upload = GUICtrlCreateButton("Upload",590,140,100,30,-1,-1)
$btn_del = GUICtrlCreateButton("Löschen",589,320,100,30,-1,-1)
$btn_nxline = GUICtrlCreateButton("Nächste Zeile <br />",407,94,109,30,-1,-1)
GUISetState(@SW_SHOW,$gui)
;TODO: EDIT Funktion erstellen, Fehler nach dem Upload beheben (erneuter Import?)
$down = _FTP_Transfer ($server, $username, $pass, $fpath, $rfile, 0)
If $down Then
MsgBox(16, "Fehler", "Es ist ein Fehler beim Download aufgetreten!")
Exit
EndIf
_importData ()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $btn_add
GUICtrlCreateListViewItem(GUICtrlRead($inp_titel) & "|" & GUICtrlRead($inp_text), $liste)
Case $btn_del
_GUICtrlListView_DeleteItemsSelected($liste)
Case $btn_nxline
$tmptxt = GUICtrlRead($inp_text)
GUICtrlSetData($inp_text, $tmptxt & "<br />")
GUICtrlSetState($inp_text, $GUI_FOCUS)
Send("{RIGHT}")
Case $btn_runter
_GUICtrlListView_MoveItems($gui, $liste,1)
Case $btn_hoch
_GUICtrlListView_MoveItems($gui, $liste,-1)
Case $btn_upload
GUICtrlSetState ($btn_upload, $GUI_Disable)
_writeData ()
$up = _FTP_Transfer ($server, $username, $pass, $fpath, $rfile, 1)
GUICtrlSetState ($btn_upload, $GUI_Enable)
If $up Then
MsgBox(16, "Fehler", "Es ist ein Fehler beim Upload aufgetreten!")
Else
MsgBox(0, "Erfolg", "Die Übertragung wurde erfolgreich beendet!")
EndIf
MsgBox(0, "Hinweis", "Aufgrund eines noch bestehenden Fehlers, wird das Programm jetzt beendet! Für eine weitere Anpassung starten Sie das Programm bitte neu!")
Exit
EndSwitch
Sleep(10)
WEnd
Func _importData()
$tmpFile = FileOpen($fpath, FileGetEncoding($fpath) + $FO_READ)
$aArray = FileReadToArray($tmpFile)
If @error Then
MsgBox(0, "", "Fehler beim einlesen der Datei. Fehler: " & @error)
Exit
EndIf
; Start und Ende finden
$start = _ArraySearch($aArray, "<!--Start-->",0, 0, 0, 1)
If @error Then
MsgBox(0, "", "Fehler beim der Suche nach dem Startpunk. Fehler: " & @error)
Exit
EndIf
$ende = _ArraySearch($aArray, "<!--Ende-->",0, 0, 0, 1)
If @error Then
MsgBox(0, "", "Fehler beim der Suche nach dem Endpunk. Fehler: " & @error)
Exit
EndIf
For $i = $start To $ende
If stringinstr($aArray[$i], '<p class="pcont2">') Then
$tmp = StringTrimLeft ($aArray[$i], 18)
$tmp = StringTrimRight($tmp, 10)
$tmp2 = StringTrimRight($aArray[$i+1], 6)
GUICtrlCreateListViewItem($tmp & "|" & $tmp2, $liste)
Endif
Next
FileClose($tmpFile)
EndFunc
Func _writeData ()
Local $asplit
$delanzahl = ($ende) - ($start) - 1
For $i = 1 to $delanzahl
_FileWriteToLineExt($fpath, $start+2, "", 1)
If @error Then
MsgBox(0, "", "Fehler beim löschen der Zeilen in der Datei. Fehler: " & @error)
Exit
EndIf
Next
Local $itemc = _GUICtrlListView_GetItemCount ($liste)
$start2 = $start+2
For $i = 1 To $itemc
$tmp = _GUICtrlListView_GetItemTextString ($liste, $i-1)
$asplit = StringSplit($tmp, "|")
_FileWriteToLineExt($fpath, $start2, '<p class="pcont2">' & $asplit[1] & '</p><br />', 0)
If @error Then
MsgBox(0, "", "Fehler beim schreiben in die Datei. Fehler: " & @error)
Exit
EndIf
$start2 +=1
_FileWriteToLineExt($fpath, $start2, $asplit[2] & '<br />', 0)
If @error Then
MsgBox(0, "", "Fehler beim schreiben in die Datei. Fehler: " & @error)
Exit
EndIf
$start2 +=1
_FileWriteToLineExt($fpath, $start2, '<hr class="hr1" /> ', 0)
If @error Then
MsgBox(0, "", "Fehler beim schreiben in die Datei. Fehler: " & @error)
Exit
EndIf
$start2 +=1
Next
EndFunc
;===============================================================================
; Function Name: _FTP_Transfer()
; Description: Download oder Upload einer Datei von/auf einen FTP Server. (Download or upload a file from/to FTP server.)
;
; Parameter(s): $sServer - Serveradresse
; $sUser - FTP Benutzer
; $sPass - FTP Passwort
; $sFile - Dateiname mit Pfad, der lokalen Datei. Z.B.: @ScriptDir & "\test.php"
; $sRemoteFile - Dateiname auf dem Server ohne Pfad mit Erweiterung. Z.B.: test.php
; $iMode - Angabe des Modus:
; 0 Download Modus
; 1 Upload Modus
;
; Requirement(s): #include <FTPEx.au3>
;
; Return Value(s): Erfolg (On success) - 0
; Fehler (On failure) - 1
;
; Author(s): C.Krogmann (Neklor)
;===============================================================================
Func _FTP_Transfer ($sServer, $sUser, $sPass, $sFile, $sRemoteFile, $iMode)
Local $iErr = 0
Local $hOpen = _FTP_Open('MyFTP Control')
If @error Then
MsgBox(16, "Fehler", "FTP Session kann nicht gestartet werden. Fehler: " & @error)
$iErr = 1
EndIf
Local $hConn = _FTP_Connect($hOpen, $sServer, $sUser, $sPass)
If @error Then
MsgBox(16, "Fehler", "Verbindung zum FTP Server nicht möglich. Fehler: " & @error)
$iErr = 1
EndIf
If $iMode = 0 Then
_FTP_FileGet($hConn, $sRemoteFile, $sFile)
If @error Then
MsgBox(16, "Fehler", "Fehler beim Download der Datei. Fehler: " & @error)
$iErr = 1
EndIf
ElseIf $iMode = 1 Then
_FTP_FileDelete ($hConn, $sRemoteFile)
If @error Then
MsgBox(16, "Fehler", "Löschen der Datei auf dem Server nicht möglich: " & @error)
$iErr = 1
EndIf
_FTP_FilePut ($hConn, $sFile, $sRemoteFile)
If @error Then
MsgBox(16, "Fehler", "Ein Fehler ist bei der Übertragung aufgetreten: " & @error)
$iErr = 1
EndIf
Else
MsgBox(16, "Fehler", "Ungültiger Modus!")
Local $hFtpc = _FTP_Close($hConn)
Local $hFtpo = _FTP_Close($hOpen)
Exit
EndIf
Local $hFtpc = _FTP_Close($hConn)
Local $hFtpo = _FTP_Close($hOpen)
Return $iErr
EndFunc
;===============================================================================
; Function Name: _GUICtrlListView_MoveItems()
; Description: Move selected item(s) in ListView Up or Down.
;
; Parameter(s): $hWnd - Window handle of ListView control (can be a Title).
; $vListView - The ID/Handle/Class of ListView control.
; $iDirection - [Optional], define in what direction item(s) will move:
; 1 (default) - item(s) will move Next.
; -1 item(s) will move Back.
; $sIconsFile - Icon file to set image for the items (only for internal usage).
; $iIconID_Checked - Icon ID in $sIconsFile for checked item(s).
; $iIconID_UnChecked - Icon ID in $sIconsFile for Unchecked item(s).
;
; Requirement(s): #include <GuiListView.au3>, AutoIt 3.2.10.0.
;
; Return Value(s): On seccess - Move selected item(s) Next/Back.
; On failure - Return "" (empty string) and set @error as following:
; 1 - No selected item(s).
; 2 - $iDirection is wrong value (not 1 and not -1).
; 3 - Item(s) can not be moved, reached last/first item.
;
; Note(s): * This function work with external ListView Control as well.
; * If you select like 15-20 (or more) items, moving them can take a while (depends on how many items moved).
;
; Author(s): G.Sandler a.k.a CreatoR (<a href='http://creator-lab.ucoz.ru' class='bbc_url' title='External link' rel='nofollow external'>http://creator-lab.ucoz.ru</a>)
;===============================================================================
Func _GUICtrlListView_MoveItems($hWnd, $vListView, $iDirection=1, $sIconsFile="", $iIconID_Checked=0, $iIconID_UnChecked=0)
Local $hListView = $vListView
If Not IsHWnd($hListView) Then $hListView = ControlGetHandle($hWnd, "", $hListView)
Local $aSelected_Indices = _GUICtrlListView_GetSelectedIndices($hListView, 1)
If UBound($aSelected_Indices) < 2 Then Return SetError(1, 0, "")
If $iDirection <> 1 And $iDirection <> -1 Then Return SetError(2, 0, "")
Local $iTotal_Items = ControlListView($hWnd, "", $hListView, "GetItemCount")
Local $iTotal_Columns = ControlListView($hWnd, "", $hListView, "GetSubItemCount")
Local $iUbound = UBound($aSelected_Indices)-1, $iNum = 1, $iStep = 1
Local $iCurrent_Index, $iUpDown_Index, $sCurrent_ItemText, $sUpDown_ItemText
Local $iCurrent_Index, $iCurrent_CheckedState, $iUpDown_CheckedState
If ($iDirection = -1 And $aSelected_Indices[1] = 0) Or _
($iDirection = 1 And $aSelected_Indices[$iUbound] = $iTotal_Items-1) Then Return SetError(3, 0, "")
ControlListView($hWnd, "", $hListView, "SelectClear")
Local $aOldSelected_IDs[1]
Local $iIconsFileExists = FileExists($sIconsFile)
If $iIconsFileExists Then
For $i = 1 To $iUbound
ReDim $aOldSelected_IDs[UBound($aOldSelected_IDs)+1]
_GUICtrlListView_SetItemSelected($hListView, $aSelected_Indices[$i], True)
$aOldSelected_IDs[$i] = GUICtrlRead($vListView)
_GUICtrlListView_SetItemSelected($hListView, $aSelected_Indices[$i], False)
Next
ControlListView($hWnd, "", $hListView, "SelectClear")
EndIf
If $iDirection = 1 Then
$iNum = $iUbound
$iUbound = 1
$iStep = -1
EndIf
For $i = $iNum To $iUbound Step $iStep
$iCurrent_Index = $aSelected_Indices[$i]
$iUpDown_Index = $aSelected_Indices[$i]+1
If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i]-1
$iCurrent_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iCurrent_Index)
$iUpDown_CheckedState = _GUICtrlListView_GetItemChecked($hListView, $iUpDown_Index)
_GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index)
For $j = 0 To $iTotal_Columns-1
$sCurrent_ItemText = _GUICtrlListView_GetItemText($hListView, $iCurrent_Index, $j)
$sUpDown_ItemText = _GUICtrlListView_GetItemText($hListView, $iUpDown_Index, $j)
_GUICtrlListView_SetItemText($hListView, $iUpDown_Index, $sCurrent_ItemText, $j)
_GUICtrlListView_SetItemText($hListView, $iCurrent_Index, $sUpDown_ItemText, $j)
Next
_GUICtrlListView_SetItemChecked($hListView, $iUpDown_Index, $iCurrent_CheckedState)
_GUICtrlListView_SetItemChecked($hListView, $iCurrent_Index, $iUpDown_CheckedState)
If $iIconsFileExists Then
If $iCurrent_CheckedState = 1 Then
GUICtrlSetImage(GUICtrlRead($vListView), $sIconsFile, $iIconID_Checked, 0)
Else
GUICtrlSetImage(GUICtrlRead($vListView), $sIconsFile, $iIconID_UnChecked, 0)
EndIf
If $iUpDown_CheckedState = 1 Then
GUICtrlSetImage($aOldSelected_IDs[$i], $sIconsFile, $iIconID_Checked, 0)
Else
GUICtrlSetImage($aOldSelected_IDs[$i], $sIconsFile, $iIconID_UnChecked, 0)
EndIf
EndIf
_GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index, 0)
Next
For $i = 1 To UBound($aSelected_Indices)-1
$iUpDown_Index = $aSelected_Indices[$i]+1
If $iDirection = -1 Then $iUpDown_Index = $aSelected_Indices[$i]-1
_GUICtrlListView_SetItemSelected($hListView, $iUpDown_Index)
Next
EndFunc
; #FUNCTION# ====================================================================================================================
; Original _FileWriteToLine from:
; Author ........: cdkid
; Modified.......: partypooper, MrCreatoR
;
; New Version: _FileWriteToLineExt by Neklor
; Mod........: Files will be saved in UTF-8 NOBOM now.
; ===============================================================================================================================
Func _FileWriteToLineExt($sFilePath, $iLine, $sText, $iOverWrite = 0)
If $iLine <= 0 Then Return SetError(4, 0, 0)
If Not IsString($sText) Then
$sText = String($sText)
If $sText = "" Then Return SetError(6, 0, 0)
EndIf
If $iOverWrite <> 0 And $iOverWrite <> 1 Then Return SetError(5, 0, 0)
If FileExists($sFilePath) = 0 Then Return SetError(2, 0, 0)
Local $hFileOpen = FileOpen($sFilePath, FileGetEncoding($sFilePath) + $FO_READ)
Local $aArray = FileReadToArray($hFileOpen)
FileClose($hFileOpen)
Local $iUBound = UBound($aArray) - 1
If ($iUBound + 1) < $iLine Then Return SetError(1, 0, 0)
Local $hFileOpen = FileOpen($sFilePath, $FO_UTF8_NOBOM + $FO_OVERWRITE)
If $hFileOpen = -1 Then Return SetError(3, 0, 0)
Local $sData = ""
$iLine -= 1 ; Now the array is 0-based, so reduce the line number by 1.
For $i = 0 To $iUBound
If $i = $iLine Then
If $iOverWrite Then
If $sText Then $sData &= $sText & @CRLF
Else
$sData &= $sText & @CRLF & $aArray[$i] & @CRLF
EndIf
ElseIf $i < $iUBound Then
$sData &= $aArray[$i] & @CRLF
ElseIf $i = $iUBound Then
$sData &= $aArray[$i]
EndIf
Next
FileWrite($hFileOpen, $sData)
FileClose($hFileOpen)
Return 1
EndFunc ;==>_FileWriteToLine
ergebnisse.php
Achtung: Ab <!--Start--> fangen alle zeilen eigentlich ohne Leerzeichen vorweg an, ist hier wohl ein anzeigefehler im forum.
Spoiler anzeigen
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<? header("Content-Type: text/html; charset=utf-8"); ?>
<head>
<meta content="de" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Test</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="header">
<? include ("head.php"); ?>
</div>
<div id="navi">
<? include ("nav.php"); ?>
</div>
<div id="content" align="center">
<? include ("head.php"); ?>
<div id="content2" align="center">
<hr class="hr1" />
<!--Start-->
<p class="pcont2">Testevent1</p><br />
von März 2013 - Dezember 2013, 123 teststadt<br />
<hr class="hr1" />
<p class="pcont2">Testevent2</p><br />
von November 2013 - Dezember 2013, 124 Südöstliche Stadt<br />
<hr class="hr1" />
<p class="pcont2">Testevent3</p><br />
von November 2013 - Dezember 2013, 125 teststadt<br />
<hr class="hr1" />
<p class="pcont2">Testevent4</p><br />
von November 2013 - Dezember 2013, 126 teststadt<br />
<hr class="hr1" />
<p class="pcont2">Testevent5</p><br />
von November 2013 - Dezember 2013, 127 teststadt<br />
<hr class="hr1" />
<p class="pcont2">Testevent6</p><br />
von November 2013 - Dezember 2013, 128 teststadt<br />
<hr class="hr1" />
<!--Ende-->
<br />
</div>
</div>
</div>
</body>
</html>
Alles anzeigen