to imitate the thread has fixed the issue.
However i'll post the two offending procedures ( although you won't be able to run them ) but as you say fresh eye
Code: Select all
Procedure window_send_email(start_date.i)
Global window_send_email = OpenWindow(#PB_Any, 164, 63, 330, 230, "Sending request email", #PB_Window_BorderLess|#PB_Window_ScreenCentered)
If window_send_email
StickyWindow(window_send_email, #True)
DisableWindow(window_main, #True)
update_log_file("Sending request email - opened form ", window_send_email)
width.i = WindowWidth(window_send_email)
height.i = WindowHeight(window_send_email)
Global GBL_send_email_background = window_background_icon_bar(window_send_email, #WIN_STANDARD, 0, 0, width, height, hex_decode(GBL_colour_scheme), "Sending request email", #yes, #yes, #yes, #no)
Global btn_send_email_min.i = CanvasGadget(#PB_Any, width-50, 0, 20, 20)
form_control_button(btn_send_email_min, icn_minimise)
GadgetToolTip(btn_send_email_min, "Minimise")
Global btn_send_email_close.i = CanvasGadget(#PB_Any, width-28, 0, 20, 20)
form_control_button(btn_send_email_close, icn_close)
GadgetToolTip(btn_send_email_close, "Close")
gadget_GBL_display_row.i = 35
fld_send_email_status = EditorGadget(#PB_Any , 15, gadget_GBL_display_row, 300, 160, #PB_Editor_WordWrap|#PB_Editor_ReadOnly)
SetGadgetText(fld_send_email_status, "")
gadget_GBL_display_row + 165
fld_send_email_progress= ProgressBarGadget(#PB_Any , 15, gadget_GBL_display_row, WindowWidth(window_send_email)-30, 20, 0, 100, #PB_ProgressBar_Smooth)
; repaint the calling window
RedrawWindow_(WindowID(window_send_email),#NUL,#NUL,#RDW_ALLCHILDREN|#RDW_INVALIDATE)
While WindowEvent():Wend
Else
update_log_file("engineering_frm_time_manager - window_send_email, UNABLE TO OPEN ", window_main)
window_warning("PAPERCLIP Error", "Sorry I was unable to open the engineering_frm_time_manager - window_send_email." + Chr(13) + "It could be locked Or may Not exist", "YES", window_send_email, 200)
End
EndIf
timer = CreateThread(@send_emails(), start_date)
window_send_email_status = 0
Repeat
Event = WaitWindowEvent()
Select Event
; enable dragging of window
Case #WM_LBUTTONDOWN
SendMessage_(WindowID(window_send_email), #WM_NCLBUTTONDOWN, #HTCAPTION , #Null)
Case #PB_Event_Gadget
;button events
; /----------------------------------------------------------------\
; | btn_send_email_min events |
;{ \----------------------------------------------------------------/
If EventGadget() = btn_send_email_min
gadget_id = btn_send_email_min
icon = icn_minimise
Select EventType()
Case #PB_EventType_MouseEnter
form_control_button_over(gadget_id, $0000CC, icon)
Case #PB_EventType_MouseLeave
form_control_button_over(gadget_id, GBL_layer_border, icon)
Case #PB_EventType_LeftButtonDown
Case #PB_EventType_LeftButtonUp ; button up action
form_control_button_over(gadget_id, GBL_layer_border, icon)
SetWindowState(GetActiveWindow(), #PB_Window_Minimize)
EndSelect
;}
; /----------------------------------------------------------------\
; | btn_send_email_close events |
;{ \----------------------------------------------------------------/
ElseIf EventGadget() = btn_send_email_close
gadget_id = btn_send_email_close
icon = icn_close
Select EventType()
Case #PB_EventType_MouseEnter
form_control_button_over(gadget_id, $0000CC, icon)
Case #PB_EventType_MouseLeave
form_control_button_over(gadget_id, GBL_layer_border, icon)
Case #PB_EventType_LeftButtonDown
Case #PB_EventType_LeftButtonUp ; button up action
window_send_email_status = 1
EndSelect
EndIf
;}
EndSelect
Until window_send_email_status = 1
DisableWindow(window_main, #False)
StickyWindow(window_send_email, #False)
CloseWindow(window_send_email)
; repaint the calling window
RedrawWindow_(WindowID(window_main),#NUL,#NUL,#RDW_ALLCHILDREN|#RDW_INVALIDATE)
SetActiveWindow(window_main)
SetActiveGadget(-1) ; set no active gadget on active window
EndProcedure
Procedure send_emails(start_date)
InitNetwork()
If CreateMail(0, hex_decode(GBL_email_user), "")
SetGadgetText(fld_send_email_status, "Composing email")
SetMailAttribute(0, #PB_Mail_Subject, "Timesheet for approval")
SetMailBody(0, "A new timesheet has been submitted by " + hex_decode(GBL_forename) + "." + hex_decode(GBL_surname) + " for your approval." + #CRLF$ + #CRLF$ +
"This timesheet is for the week begining " + FormatDate("%dd/%mm/%yyyy", start_date))
SetGadgetText(fld_send_email_status, GetGadgetText(fld_send_email_status) + Chr(13) + "Getting email recipients")
; build the sql query
; this query gets all the email adressees
GBL_sql = "SELECT "
GBL_sql + "email_user "
GBL_sql + "FROM "
GBL_sql + "tbl_user "
GBL_sql + "WHERE "
GBL_sql + "ets_approval = 1 "
; Execute a SQL query
If DatabaseQuery(0, GBL_sql)
While NextDatabaseRow(0)
; Change the recipients to real one
recipient.s = GetDatabaseString(0, 0)
AddMailRecipient(0, recipient, #PB_Mail_To)
SetGadgetText(fld_send_email_status, GetGadgetText(fld_send_email_status) + Chr(13) + recipient)
Wend
Else
window_warning("D A T A B A S E E R R O R", GBL_sql + Chr(13) + Chr(13) + " This sql failed", "YES", window_send_email, 500)
EndIf
Result = SendMail(0, "xxxx.xxxx.com", 25, 1, hex_decode(GBL_email_user), hex_decode(GBL_email_pass))
SetGadgetText(fld_send_email_status, GetGadgetText(fld_send_email_status) + Chr(13) + "Sending email - Please wait...")
direction = 0
Repeat
Progress = MailProgress(0)
Delay(300)
If direction = 0
SetGadgetState(fld_send_email_progress, GetGadgetState(fld_send_email_progress) + 10)
If GetGadgetState(fld_send_email_progress) = 100
direction = 1
EndIf
Else
SetGadgetState(fld_send_email_progress, GetGadgetState(fld_send_email_progress) - 10)
If GetGadgetState(fld_send_email_progress) = 0
direction = 0
EndIf
EndIf
Progress = MailProgress(0)
Delay(300)
Select progress
Case #PB_Mail_Connected ; The mail transfer is in its initialization phase.
SetGadgetText(fld_send_email_status, GetGadgetText(fld_send_email_status) + Chr(13) + "Sending...")
Case #PB_Mail_Finished ; The mail transfer is finished correctly.
SetGadgetText(fld_send_email_status, GetGadgetText(fld_send_email_status) + Chr(13) + "Finished")
Case #PB_Mail_Error
SetGadgetText(fld_send_email_status, GetGadgetText(fld_send_email_status) + Chr(13) + " + + + E R R O R + + + ")
EndSelect
Until Progress = #PB_Mail_Finished Or Progress = #PB_Mail_Error
If Progress = #PB_Mail_Finished
SetGadgetText(fld_send_email_status, GetGadgetText(fld_send_email_status) + Chr(13) + "Mail correctly sent")
SetGadgetText(fld_send_email_status, GetGadgetText(fld_send_email_status) + Chr(13) + "Updating time sheet status for selected week")
ResetList(employee()) ; Reset the list index before the first element.
GBL_sql = "UPDATE "
GBL_sql + "tbl_time_sheet "
GBL_sql + "SET "
GBL_sql + "tbl_time_sheet.approved = 1 "
GBL_sql + "WHERE "
GBL_sql + "tbl_time_sheet.project_day >= '" + FormatDate("%yyyy-%mm-%dd", start_date) + "' "
GBL_sql + "AND tbl_time_sheet.project_day <= '" + FormatDate("%yyyy-%mm-%dd", AddDate(start_date, #PB_Date_Day, 6 )) + "' "
GBL_sql + "AND tbl_time_sheet.user_name = '" + hex_decode(GBL_username) + "' "
; Execute a SQL query
If DatabaseQuery(0, GBL_sql)
SetGadgetText(fld_send_email_status, GetGadgetText(fld_send_email_status) + Chr(13) + "Completed - refreshing display")
get_user_open_projects(start_date)
Else
window_warning("D A T A B A S E E R R O R", GBL_sql + Chr(13) + Chr(13) + " This sql failed", "YES", window_send_email, 500)
EndIf
Else
MessageRequester("Error", "Can't sent the mail !")
EndIf
EndIf
window_send_email_status = 1
EndProcedure