
alias autotm {
  if $dialog(chanad) = $null { dialog -ma chanad chanad }
}
dialog chanad {
  size -1 -1 480 245
  icon Scripts\Icons\conpanel.icl, 13

  title "Messaggio automatico a tempo"
  button "Ok",1, 385 215 65 20, OK
  box "",2, 10 85 220 125, tab1
  box "",3, 245 85 220 125, tab1
  box "Messaggio al canale :",5, 10 10 455 50, tab1

  edit "",6, 20 30 440 20, autohs tab1
  text "Ogni:",8, 20 68 79 20, tab1
  edit "",9, 70 66 35 20, tab1 autohs
  text "min(ti)",45, 108 68 79 20, tab1

  button "Avvia Msg",12, 40 215 60 20, tab1
  button "Ferma Msg",13, 140 215 60 20, tab1

  text "Canale #1",14, 20 105 65 20, tab2
  text "Canale #2",15, 20 125 65 20, tab2
  text "Canale #3",16, 20 145 65 20, tab2
  text "Canale #4",17, 20 165 65 20, tab2
  text "Canale #5",18, 20 185 65 20, tab2
  text "Canale #6",19, 255 105 65 20, tab2
  text "Canale #7",20, 255 125 65 20, tab2
  text "Canale #8",21, 255 145 65 20, tab2
  text "Canale #9",22, 255 165 65 20, tab2
  text "Canale #10",23, 255 185 65 20, tab2

  edit "",24, 90 105 95 20, tab2 autohs
  edit "",25, 90 125 95 20, tab2 autohs
  edit "",26, 90 145 95 20, tab2 autohs
  edit "",27, 90 165 95 20, tab2 autohs
  edit "",28, 90 185 95 20, tab2 autohs
  edit "",29, 325 105 95 20, tab2 autohs
  edit "",30, 325 125 95 20, tab2 autohs
  edit "",31, 325 145 95 20, tab2 autohs
  edit "",32, 325 165 95 20, tab2 autohs
  edit "",33, 325 185 95 20, tab2 autohs

  check "Tutti i canali",34, 275 215 85 20, tab2

  button "Togli",35, 188 105 35 20, tab2
  button "Togli",36, 188 125 35 20, tab2
  button "Togli",37, 188 145 35 20, tab2
  button "Togli",38, 188 165 35 20, tab2
  button "Togli",39, 188 185 35 20, tab2
  button "Togli",40, 423 105 35 20, tab2
  button "Togli",41, 423 125 35 20, tab2
  button "Togli",42, 423 145 35 20, tab2
  button "Togli",43, 423 165 35 20, tab2
  button "Togli",44, 423 185 35 20, tab2
}

ON *:dialog:chanad:edit:*: {
  if ($did == 6) { set %chan.item $did(6) }
  if ($did == 9) { set %chan.delay $did(9) }
  if ($did == 24) { set %chan.chan1 $did(24) }
  if ($did == 25) { set %chan.chan2 $did(25) }
  if ($did == 26) { set %chan.chan3 $did(26) }
  if ($did == 27) { set %chan.chan4 $did(27) }
  if ($did == 28) { set %chan.chan5 $did(28) }
  if ($did == 29) { set %chan.chan6 $did(29) }
  if ($did == 30) { set %chan.chan7 $did(30) }
  if ($did == 31) { set %chan.chan8 $did(31) }
  if ($did == 32) { set %chan.chan9 $did(32) }
  if ($did == 33) { set %chan.chan10 $did(33) }
}
ON *:DIALOG:chanad:init:0: {

  did -o chanad 6 1 %chan.item $did(6)
  did -o chanad 9 1 %chan.delay $did(9)
  did -o chanad 24 1 %chan.chan1 $did(24)
  did -o chanad 25 1 %chan.chan2 $did(25)
  did -o chanad 26 1 %chan.chan3 $did(26)
  did -o chanad 27 1 %chan.chan4 $did(27)
  did -o chanad 28 1 %chan.chan5 $did(28)
  did -o chanad 29 1 %chan.chan6 $did(29)
  did -o chanad 30 1 %chan.chan7 $did(30)
  did -o chanad 31 1 %chan.chan8 $did(31)
  did -o chanad 32 1 %chan.chan9 $did(32)
  did -o chanad 33 1 %chan.chan10 $did(33)
  if (%channel.all == off) { did -e $dname 24,25,26,27,28,29,30,31,32,33,14,15,16,17,18,19,20,21,22,23,35,36,37,38,39,40,41,42,43,44 }
  if (%channel.all == on) { did -b $dname 24,25,26,27,28,29,30,31,32,33,14,15,16,17,18,19,20,21,22,23,35,36,37,38,39,40,41,42,43,44 | did -c $dname 34 }
}
ON *:DIALOG:chanad:sclick:*: {
  if ($did == 34) { if ($did($dname,$did).state == 1) { did -b $dname 24,25,26,27,28,29,30,31,32,33,14,15,16,17,18,19,20,21,22,23,35,36,37,38,39,40,41,42,43,44 | set %channel.all on } | else { did -e $dname 24,25,26,27,28,29,30,31,32,33,14,15,16,17,18,19,20,21,22,23,35,36,37,38,39,40,41,42,43,44 | set %channel.all off } }
  if ($did == 12) {
    if (%chan.delay == $null) { echo -a 3* 7[3Auto Timed MSG7]4: Metti un tempo. | goto bleh }
    set %channel on
    .timerchanAd 1 .1 chanAdOn
    echo -a 3* 7[3Auto Timed MSG7]4: Partito!
    :bleh
  }
  if ($did == 13) {
    .timerchanAd off
    echo -a 3* 7[3Auto Timed MSG7]4: Stoppato.
    set %channel off
  }
  if ($did == 35) { unset %chan.chan1 | did -o chanad 24 1 %chan.chan1 }
  if ($did == 36) { unset %chan.chan2 | did -o chanad 25 1 %chan.chan2 }
  if ($did == 37) { unset %chan.chan3 | did -o chanad 26 1 %chan.chan3 }
  if ($did == 38) { unset %chan.chan4 | did -o chanad 27 1 %chan.chan4 }
  if ($did == 39) { unset %chan.chan5 | did -o chanad 28 1 %chan.chan5 }
  if ($did == 40) { unset %chan.chan6 | did -o chanad 29 1 %chan.chan6 }
  if ($did == 41) { unset %chan.chan7 | did -o chanad 30 1 %chan.chan7 }
  if ($did == 42) { unset %chan.chan8 | did -o chanad 31 1 %chan.chan8 }
  if ($did == 43) { unset %chan.chan9 | did -o chanad 32 1 %chan.chan9 }
  if ($did == 44) { unset %chan.chan10 | did -o chanad 33 1 %chan.chan10 }
}

alias -l chanDisplayAd {
  return %chan.item
}
alias -l saychan {
  msg $active %chan.item
}
alias -l chanDisplayAd2 {
  if (%channel.all == on) { amsg $chanDisplayAd | goto end }
  if (%chan.chan1 != $null) && ($chan(%chan.chan1) != $null) { msg %chan.chan1 $chanDisplayAd }
  if (%chan.chan2 != $null) && ($chan(%chan.chan2) != $null) { msg %chan.chan2 $chanDisplayAd }
  if (%chan.chan3 != $null) && ($chan(%chan.chan3) != $null) { msg %chan.chan3 $chanDisplayAd }
  if (%chan.chan4 != $null) && ($chan(%chan.chan4) != $null) { msg %chan.chan4 $chanDisplayAd }
  if (%chan.chan5 != $null) && ($chan(%chan.chan5) != $null) { msg %chan.chan5 $chanDisplayAd }
  if (%chan.chan6 != $null) && ($chan(%chan.chan6) != $null) { msg %chan.chan6 $chanDisplayAd }
  if (%chan.chan7 != $null) && ($chan(%chan.chan7) != $null) { msg %chan.chan7 $chanDisplayAd }
  if (%chan.chan8 != $null) && ($chan(%chan.chan8) != $null) { msg %chan.chan8 $chanDisplayAd }
  if (%chan.chan9 != $null) && ($chan(%chan.chan9) != $null) { msg %chan.chan9 $chanDisplayAd }
  if (%chan.chan10 != $null) && ($chan(%chan.chan10) != $null) { msg %chan.chan10 $chanDisplayAd }
  :end
}
alias -l chanAdOn {
  .timerchanAd 0 $calc(%chan.delay * 60) chanDisplayAd2
  set %channel on
  chanDisplayAd2
}
alias -l chanAdOff {
  .timerchanAd off | set %channel off | halt
}

alias automsg dialog -mo dialog chanad
