KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

SwitchBoard Application

 
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive
View previous topic :: View next topic  
Author Message
Bryce
KiXforms Supporter
KiXforms Supporter


Joined: 26 Mar 2003
Posts: 69

PostPosted: Thu Aug 05, 2004 4:43 pm    Post subject: SwitchBoard Application Reply with quote

Here is a custom built app that i made for a unique problem that we were facing here at the office.

Since we use a receptionist to handle all incoming phone calls, we are required to let the receptionist know our location, if we are at the desk, if we are out of the office, if on site what site we are on, and other helpful information.


So i wrote this 2 part Application.

SwitchBoard.kix is the client application it sits in the task bar and monitors computer inactivity. After a set number of minutes of inactivity, you will be marked as "Away". It also has a do not disturb mode that you can manually set. You can set your away message to what ever you want.

Operator.kix is the Operator Console. This is the program that the receptionist runs. It collects all of the client data for display. It also will let the receptionist change a clients away message, and turn off and on the DnD mode on a client.

be sure to change the $database location on both scripts.

Enjoy!
Bryce


Last edited by Bryce on Thu Aug 05, 2004 4:53 pm; edited 1 time in total
Back to top
View user's profile Send private message
Bryce
KiXforms Supporter
KiXforms Supporter


Joined: 26 Mar 2003
Posts: 69

PostPosted: Thu Aug 05, 2004 4:44 pm    Post subject: switchboard.kix Reply with quote

Code:

Break On
$=SetOption("NoVarsInStrings","on")
$settings = "HKEY_CURRENT_USER\Software\SwitchBoard"
$version = "1.0"

;set the folder for the centeral database.
$database = "f:\SwitchBoard\DataBase\"

$System = CreateObject("Kixtart.System")

$SBHeartBeat = $system.timer()
$SBHeartBeat.interval = 500
$SBHeartBeat.ontick = "SBHeartBeat()"
$SBHeartBeat.enabled = 1

$Updatetimer = $system.timer()
$Updatetimer.interval = 5000
$Updatetimer.ontick = "Update()"
$Updatetimer.enabled = 1

$AFkTimer = $system.timer()
$AFKTimer.interval = 1000
$AFKTimer.ontick = "AFKTimer($System.Environment.LastUserInput)"
$AFKTimer.enabled = 1

$AFkIconTimer = $system.timer()
$AFKIconTimer.interval = 500
$AFKIconTimer.ontick = "AFKIconTimer()"

$NotifyIcon1 = $System.NotifyIcon()
$NotifyIcon1.Icon = $System.Icon("shell32.dll;160")
$NotifyIcon1.OnDoubleClick = "$form.show"
$NotifyIcon1.Visible = 1

;KD START

;************* Form **************
$Form = $System.Form()
$Form.FormBorderStyle = 3
$Form.Height = 254
$Form.Left = 115
$Form.MaximizeBox = "False"
$Form.MinimizeBox = "False"
$Form.ShowInTaskBar = "True"
$Form.SizeGripStyle = 2
$Form.Text = "Switch Board " + $version
$Form.Top = 40
$Form.Width = 286
;**************************************

;************* Away **************
$Away = $Form.Controls.GroupBox()
$Away.Height = 168
$Away.Left = 0
$Away.Text = "Away"
$Away.Top = 0
$Away.Width = 278
;**************************************

;************* AwayOnOff **************
$AwayOnOff = $Away.Controls.CheckBox()
$AwayOnOff.CheckAlign = 16
$AwayOnOff.Checked = "True"
$AwayOnOff.CheckState = 0
$AwayOnOff.Height = 18
$AwayOnOff.Left = 10
$AwayOnOff.Text = "I am Away from the computer"
$AwayOnOff.Top = 20
$AwayOnOff.Width = 170
$AwayOnOff.OnClick = "AwayOnOffClick($AwayOnOff.checkstate)"
;**************************************

;************* Awaytext **************
$awayText = $Away.Controls.TextBox()
$AwayText.Height = 93
$AwayText.Left = 10
$AwayText.Multiline = "True"
$AwayText.Text = "I am Away from my desk"
$AwayText.Top = 40
$AwayText.Width = 261
$awaYtext.OnTextChanged = "RemoveCommas($AwayText.Text)"
;**************************************

;************* AutoAFK **************
$AutoAFK = $Away.Controls.CheckBox()
$AutoAFK.CheckAlign = 16
$AutoAFK.Checked = "True"
$AutoAFK.CheckState = 1
$AutoAFK.Height = 17
$AutoAFK.Left = 10
$AutoAFK.Text = "Enable Auto Away"
$AutoAFK.Top = 140
$AutoAFK.Width = 117
$autoAFK.onclick = "AutoAFKClick($autoafk.checkstate)"
;**************************************

;************* AutoAfkmin **************
$AutoAfkmin = $Away.Controls.ComboBox()
$AutoAfkmin.DropDownWidth = 121
$AutoAfkmin.DropDownStyle = 2
$AutoAfkmin.Height = 21
$AutoAfkmin.Left = 140
$AutoAfkmin.Sorted = "False"
$AutoAfkmin.Text = "--Auto away minutes--"
$AutoAfkmin.Top = 140
$AutoAfkmin.Width = 132
;$AutoAfkmin.additem("0.2 Minutes")
;$AutoAfkmin.additem("1 Minutes")
$AutoAfkmin.additem("5 Minutes")
$AutoAfkmin.additem("10 Minutes")
$AutoAfkmin.additem("15 Minutes")
$AutoAfkmin.additem("20 Minutes")
$AutoAfkmin.additem("30 Minutes")
$AutoAfkmin.additem("45 Minutes")
$AutoAfkmin.additem("60 Minutes")
;**************************************

;************* Button1 **************
$Button1 = $Form.Controls.Button()
$Button1.Height = 23
$Button1.Left = 100
$Button1.Text = "OK"
$Button1.Top = 190
$Button1.Width = 75
$Button1.onclick = "SaveState() $form.hide"
$Button1.ContextMenu = $System.ContextMenu()
$Button1Exit = $Button1.ContextMenu.MenuItems.Add("Exit...")
$Button1Exit.OnClick = "$notifyicon1.Visible = 0"
;**************************************

;KD END


LoadState()

;$Form.Show
While $notifyicon1.Visible
   $=Execute($Form.DoEvents())
Loop
savestate()
Exit 1

Function RemoveCommas($text)
   If InSTR($text,",")
      $text = Join(Split($text,","),"")
      $awaytext.text = $text
      $awaytext.selectionstart = Len($text)
   EndIf
EndFunction

;new 2way update, operator console can set client away message.
Function Update()
   DIM $status
   If ReadProfileString($database+@USERID+".ini","operator","Overwrite")
      $status = Split(ReadProfileString($database+@USERID+".ini","operator","status"),",")

      AwayOnOffClick(Val($status[1]))
      $afkflag          = $status[1]
      $AFKTimer.enabled = $status[2]
      $awaytext.text    = Join(Split($status[3],"|"),@CRLF)
      
      $=WriteProfileString($database+@USERID+".ini","operator","","")
      $status = ""+$status[0]+","+$status[1]+","+$status[2]+","+$status[3]+","+@DATE+","+@TIME
   Else
      $status = ""+@FULLNAME+","+$afkflag+","+$AFKTimer.enabled+","+Join(Split($awaytext.text,@CRLF),"|")+","+@DATE+","+@TIME
   EndIf
   $ = WriteProfileString($database + @USERID + ".ini","SwitchBoard",@USERID,$status)
EndFunction

;old oneway update
;Function Update()
;   DIM $status
;   $status = ""+@FULLNAME+","+$afkflag+","+$AFKTimer.enabled+","+Join(Split($awaytext.text,@CRLF),"|")+","+@DATE+","+@TIME
;   $ = WriteProfileString($database + @USERID + ".ini","SwitchBoard",@USERID,$status)
;EndFunction

Function SBHeartBeat
   $afkIconTimer.enabled = IIf($afkflag,1,0)
EndFunction

Function AfKIconTimer
   $lasthb = setnotifyicon($lasthb)
EndFunction

Function AFkTimer($tick)
   DIM $a,b
   $a = Val(Left(@TICKS,-3)) - Val(Left($tick,-3))
   $b = Val(Split($Autoafkmin.text)[0])*60
   If $a => $b
      $afkflag=1
   Else
      $afkflag=0
      $ = SetNotifyIcon(0)
   EndIf
EndFunction


Function SaveState
   $=WriteValue($settings,"autoafk.enabled",$autoafk.enabled,"reg_sz")
   $=WriteValue($settings,"autoafk.Checkstate",$autoafk.checkstate,"reg_sz")
   $=WriteValue($settings,"autoafkMin.enabled",$autoafkmin.enabled,"reg_sz")
   $=WriteValue($settings,"autoafkMin.SelectedIndex",$autoafkmin.SelectedIndex,"reg_sz")
   $=WriteValue($settings,"AFKTimer.enabled",$AFKTimer.enabled,"reg_sz")
   $=WriteValue($settings,"Form.left",$Form.Left,"reg_sz")
   $=WriteValue($settings,"Form.top",$Form.top,"reg_sz")
   $=WriteValue($settings,"AwayText.text",$AwayText.Text,"reg_sz")
EndFunction

Function LoadState
   $autoafk.enabled    = 1; readvalue($settings,"autoafk.enabled")
   $autoafk.checkstate    = 1; readvalue($settings,"autoafk.checkstate")
   $autoafkmin.enabled    = 1; readvalue($settings,"autoafkmin.enabled")
   $autoafkmin.SelectedIndex= ReadValue($settings,"autoafkmin.SelectedIndex")
   $AFKTimer.enabled   = 1; readvalue($settings,"AFKTimer.enabled")
   $Form.Left       = ReadValue($settings,"Form.left")
   $Form.top       = ReadValue($settings,"Form.top")
   $awaytext.text       = ReadValue($settings,"AwayText.text")
   If $awaytext.text = "" $awaytext.text = "I am away from my computer" EndIf
EndFunction

Function AwayOnOffClick($checked)
   If $checked
      $afktimer.enabled=0
      $afkflag=1
      If $autoafk.checkstate
         $autoafk.enabled = 0
         $autoafkmin.enabled=0
      Else
         $autoafk.enabled = 0
      EndIf
   Else
      $afkflag=0
      If $autoafk.checkstate
         $autoafk.enabled = 1
         $autoafkmin.enabled=1
         $afktimer.enabled=1
      Else
         $autoafk.enabled = 1
         $autoafkmin.enabled=0
      EndIf
   EndIf
   $AwayOnOff.CheckState = $checked
EndFunction

Function AutoAfkClick($checked)
   If $checked
      $afktimer.enabled=1
      $AutoAfkmin.enabled = 1
   Else
      $afkflag=0
      $afktimer.enabled=0
      $AutoAfkmin.enabled = 0
   EndIf      
EndFunction

Function SetNotifyIcon($n)
   If not $n
      $NotifyIcon1.Icon = $System.Icon("shell32.dll;160")
      $SetNotifyIcon = 1
   Else
      $NotifyIcon1.Icon = $System.Icon("shell32.dll;109")
      $SetNotifyIcon = 0
   EndIf
EndFunction
Back to top
View user's profile Send private message
Bryce
KiXforms Supporter
KiXforms Supporter


Joined: 26 Mar 2003
Posts: 69

PostPosted: Thu Aug 05, 2004 4:47 pm    Post subject: operator.kix Reply with quote

Code:

Break On
$=SetOption("NoVarsInStrings","on")
$System = CreateObject("Kixtart.System")



$database = "f:\SwitchBoard\DataBase\"



Global $userdata[]
;KD START

;************* Form **************
$Form = $System.Form()
$Form.FormBorderStyle = 4
$Form.Height = 521
$Form.Left = 59
$Form.MaximizeBox = "False"
$Form.Text = "SwitchBoard Operator"
$Form.Top = 91
$Form.Width = 598
;**************************************

;************* ListView **************
$ListView = $Form.Controls.ListView()
$ListView.Height = 455
$ListView.Left = 0
$ListView.Top = 30
$ListView.Width = 588
$listview.anchor = 15
;**************************************

;KD END

;************* Form **************
$client = $System.Form()
$client.FormBorderStyle = 3
$client.Height = 254
$client.Left = 115
$client.MaximizeBox = "False"
$client.MinimizeBox = "False"
$client.ShowInTaskBar = "True"
$client.SizeGripStyle = 2
$client.Top = 40
$client.Width = 286
;**************************************

;************* Away **************
$Away = $client.Controls.GroupBox()
$Away.Height = 168
$Away.Left = 0
$Away.Text = "Away"
$Away.Top = 0
$Away.Width = 278
;**************************************

;************* AwayOnOff **************
$AwayOnOff = $Away.Controls.CheckBox()
$AwayOnOff.CheckAlign = 16
$AwayOnOff.Checked = "True"
$AwayOnOff.Height = 18
$AwayOnOff.Left = 10
$AwayOnOff.Text = "I am Away from the computer"
$AwayOnOff.Top = 20
$AwayOnOff.Width = 170
;$AwayOnOff.OnClick = "AwayOnOffClick($AwayOnOff.checkstate)"
;**************************************

;************* Awaytext **************
$awayText = $Away.Controls.TextBox()
$AwayText.Height = 93
$AwayText.Left = 10
$AwayText.Multiline = "True"
$AwayText.Top = 40
$AwayText.Width = 261
$awaYtext.OnTextChanged = "RemoveCommas($AwayText.Text)"
;**************************************

;************* Button1 **************
$Button1 = $client.Controls.Button()
$Button1.Height = 23
$Button1.Left = 50
$Button1.Text = "Cancel"
$Button1.Top = 190
$Button1.Width = 75
$Button1.onclick = "$client.hide"
;**************************************

;************* Button2 **************
$Button2 = $client.Controls.Button()
$Button2.Height = 23
$Button2.Left = 150
$Button2.Text = "Change"
$Button2.Top = 190
$Button2.Width = 75
;**************************************




$Timer = $Form.Controls.Timer()
$timer.interval= 3000
$timer.ontimer = "getdata"

$ListView.SmallImageList = $form.SmallImageList
$ListView.OnDoubleClick = "SetViewClient($ListView.FocusedItem.index)"

$= $ListView.Columns.Add("Status",45)
$= $ListView.Columns.Add("Name")
$= $ListView.Columns.Add("Message",324+115)

getdata

$Form.Show
While $Form.Visible
   $=Execute($System.Application.DoEvents())
Loop
Exit 1

Function SetViewClient($number)
   DIM $data
   $data= $userdata[$number]
   $client.top = $form.top+100
   $client.left = $form.left+100
   $client.Text = "Switch Board (" + Split($data[0],"=")[1] + ")"

   $AwayOnOff.CheckState = $data[1]
   $AwayText.Text = Join(Split($data[3],"|"),@CRLF)

   $client.show
   $Button2.onclick = "$client.hide OperatorOverwrite("+$number+")"
EndFunction

Function OperatorOverwrite($number)
   DIM $status, $data,$file
   $data = $userdata[$number]
   If $AwayOnOff.CheckState
      $status=$data[0]+",1,0,"+Join(Split($awaytext.text,@CRLF),"|")+","+@DATE+","+@TIME
   Else
      $status=$data[0]+",0,1,"+Join(Split($awaytext.text,@CRLF),"|")+","+@DATE+","+@TIME
   EndIf
   $userdata[$number] = Split($status,",")
   $file = $database +Split($data[0],"=")[0]+".ini"
   $ = WriteProfileString($file,"operator","overwrite",1)
   $ = WriteProfileString($file,"operator","status",SubSTR($status,InSTR($status,"=")+1))
EndFunction


Function RemoveCommas($text)
   If InSTR($text,",")
      $text = Join(Split($text,","),"")
      $awaytext.text = $text
      $awaytext.selectionstart = Len($text)
   EndIf
EndFunction


Function Getdata
   DIM $temp,$file,$,$sname
   $temp = Getfilenames($database)
   If UBound($temp)+1
      ReDIM $userdata[UBound($temp)]
      For $ = 0 To UBound($temp)
         $sname = Split(SubSTR($temp[$],Len($database)+1),".")[0]
         $userdata[$]=Split($sname+"="+ReadProfileString($temp[$],"switchboard",$sname),",")
      Next
   EndIf
   refreshlistview
EndFunction

Function RefreshListview
   DIM $user,$,$i
   For Each $user In $userdata
      If UBound($user)=5
         $lastup = flipctime(@DATE,@TIME)-flipctime($user[4],$user[5])
         $ = iscan(Split($user[0],"=")[1])
         $AwayIcon = IIf(Val($user[1]),IIf(Val($user[2]),35,37),34)
         If $lastup>60*15 $awayicon = 15 EndIf

         If $awayicon = 37 $dnd = "(DnD) " Else $dnd = "" EndIf
         
         Select
         ;  Case $lastup>60*15
         ;   If $+1 $listview.items($).remove EndIf            
           Case $+1
            ;If $lastup>60*15 $listview.ForeColor = 169,169,169 EndIf
            $listview.items($).subitems(0).ImageIndex = $AwayIcon
            $listview.items($).subitems(1).text = Split($user[0],"=")[1]
            $listview.items($).subitems(2).text = IIf(Val($user[1]),$dnd+$user[3],"")
            If $awayicon=15 $listview.items($).subitems(2).text = "(Not online) "+$user[3] EndIf
           Case $=-1
            ;add the item
            $items = $listview.items.add
            $items.subitems(1).text = Split($user[0],"=")[1]
            $items.subitems(0).ImageIndex = $AwayIcon
            $items.subitems(2).text = IIf(Val($user[1]),$dnd+$user[3],"")
            If $awayicon=15 $items.subitems(2).text = "(Not online) "+$user[3] EndIf
         EndSelect

      EndIf
   Next
   If UBound($userdata) <>  $listview.items.count-1
      For $ = 0 To $listview.items.count-1
         For Each $user In $userdata
            If $listview.items($).subitems(1).text = Split($user[0],"=")[1]
               $keep = 1
            EndIf
         Next
         If not $keep
            $listview.items($).remove
         EndIf
         $keep=0
      Next
   EndIf
EndFunction

Function IScan($name)
   DIM $
   For $ = 0 To $listview.items.count
      If $listview.items($).subitems(1).text = $name
         $iscan = $
         Exit
      EndIf
   Next
   $iscan=-1
EndFunction

Function GetFilenames($path,optional $passedarray)
   DIM $fso, $folder, $files, $file, $i
   DIM $tarray[0]
   $fso = CreateObject("Scripting.FileSystemObject")
   $folder = $fso.getfolder($path)
   $files = $folder.files
   For Each $file In $files
      $tarray[$i] = $file
      $i = $i + 1
      ReDIM preserve $tarray[$i]
   Next
   If $i
      ReDIM preserve $tarray[$i-1]
   Else
      $tarray = 0
   EndIf
   $getfilenames = $tarray
EndFunction


;FUNCTION      FlipcTime()
;
;ACTION        Converts a Kixtart format date/time into a cTime time
;
;AUTHOR        Bryce Lindsay
;
;VERSION       1.0 first publish
;              1.1 removed dependencies
;              1.2 added Time Zone support
;
;KIXTART       4.12+
;
;SYNTAX        RETCODE = FLIPCTIME(DATE,TIME,[TIME ZONE])
;
;PARAMETERS    DATE
;              Date in YYYY/MM/DD
;
;              TIME
;              Time in HH:MM[:SS]
;
;              Optional ZIME ZONE
;              the timezone taht you want to adjust for.
;
;RETURN        the given date/time in number of seconds that have passed since 1970/01/01 00:00:00
;
;REMARKS       See this thread for original idea
;              http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=80863
;              Also know as UNIX time.
;              this will error out for dates that are past January 19, 2038 the y2k38 bug!!
;
;DEPENDENCIES  None
;
;              ;give the Epoc time for the central time zone in the US(-6)
;EXAMPLE       $return = FlipcTime("2004/07/08","14:45:23",-6)
;             
Function FlipcTime($date,$time,optional $tz)
   DIM $y,$m,$d
   $date = Split($date,"/")
   If UBound($date) <> 2 Exit(1) EndIf
   $y=Val($date[0]) $m=Val($date[1]) $d=Val($date[2])
   If $m<3
      $m=$m+12
      $y=$y-1
   EndIf
   $Date=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306
   $time = Split($time,":")
   Select
      Case UBound($time)=1
         ReDIM preserve $time[2]
         $time[2]=0
      Case UBound($time)=2
      Case 1
         Exit(1)
   EndSelect
   $time = (Val($time[0])*3600)+(Val($time[1])*60)+Val($time[2])
   $flipctime = IIf($tz,(($date-719163)*86400 + $time)-($tz*3600),($date-719163)*86400 + $time)
EndFunction

Back to top
View user's profile Send private message
cmelin
KiXforms Novice
KiXforms Novice


Joined: 02 Jun 2004
Posts: 2
Location: Strasbourg (France)

PostPosted: Mon Aug 16, 2004 1:35 pm    Post subject: Reply with quote

interesting demo of kixforms. it looks like a kind of limited "instant messaging".

it would be nice to hide the console but if you add this option, you should add a popupmenu on the systray icon to close the application.

_________________
Christophe MELIN
Back to top
View user's profile Send private message
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Mon Aug 16, 2004 1:50 pm    Post subject: Reply with quote

1) to run scripts where you don't EXPLICITLY NEED console, USE WKIX32
2) this program is not mentioned to be stopped at any time

even shawn does not follow the first rule, but he is basta-fart Wink

_________________
Hammer
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Mon Aug 16, 2004 2:10 pm    Post subject: Reply with quote

You've forgot to mention to use wkix32 within a shortcut not a batch file
_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
Bryce
KiXforms Supporter
KiXforms Supporter


Joined: 26 Mar 2003
Posts: 69

PostPosted: Mon Aug 16, 2004 4:32 pm    Post subject: Reply with quote

Normally i would not want the users to end the program, but there is a way to exit the program... right click the OK button to get the exit option.

I was not able to get context menus on the systemicon... did Shawn add that feature?

Wkix32 is what i use to run this program from the main logon script.

run 'f:\switchboard\wkix32.exe -i f:\switchboard\switchboard.kix'

I have a shortcut icon for the operator.kix users that uses wkix32.

Bryce
Back to top
View user's profile Send private message
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Tue Aug 17, 2004 7:55 am    Post subject: Reply with quote

Man, I tried real hard for the last hour to join the NotifyIcon sample script and Chris' ContextMenu stuff...

I failed miserably because of missing Mouse coordinates when clicking the Notify Icon Rolling Eyes

Think this Context-Menu-On-Notify-Icon thingie is one to add on the feature request list

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group