;***************************************************
dialog sms_upgrade {
  title "Обновление"
  size -1 -1 191 175
  option dbu
  text "Страна", 2, 7 9 19 8
  text "Оператор", 3, 7 89 25 8
  text "Регион", 4, 95 10 18 8
  button "Загрузить список", 5, 32 8 54 10
  button "Загрузить список", 6, 120 8 54 10, disable
  button "Загрузить список", 8, 83 88 54 10, disable
  button "Загрузить оператора", 10, 147 125 37 17, disable default multi ok
  button "Выход", 11, 148 145 37 17, multi cancel
  list 1, 7 19 80 64, size vsbar
  list 7, 95 19 80 64, size vsbar
  list 9, 7 99 131 64, size vsbar
  text "", 12, 139 88 51 16
  text "", 13, 139 106 51 16
}
;***************************************************
alias sms_upg_check_op {
  %sms.op.numss = 1
  while ($ini($nofile($script) $+ operators.ini,%sms.op.numss) != $null) {
    if ($ini($nofile($script) $+ operators.ini,%sms.op.numss) == %sms_upg.country $+ . $+ %sms_upg.region $+ . $+ $gettok($1,1,46)) {

      if ($readini($nofile($script) $+ operators.ini,%sms_upg.country $+ . $+ %sms_upg.region $+ . $+ $gettok($1,1,46),ver) != $gettok($1,2,46)) return new
      else return true
    }
    %sms.op.numss = %sms.op.numss + 1
  }
  return false
}
alias sms_upgrade_set_op {
  %sms.list.nums = 1
  did -r %sms_dialog %sms.curcombo
  while (%sms.list.nums <= $numtok(%sms.upgrade.op,124)) {
    %sms_upg_chek = $sms_upg_check_op($gettok(%sms.upgrade.op,%sms.list.nums,124))
    if (%sms_upg_chek == false) did -i %sms_dialog %sms.curcombo $calc($did(%sms_dialog,%sms.curcombo).lines + 1) $gettok($gettok(%sms.upgrade.op,%sms.list.nums,124),1,46)
    if (%sms_upg_chek == new) did -i %sms_dialog %sms.curcombo $calc($did(%sms_dialog,%sms.curcombo).lines + 1) [!] $+ $gettok($gettok(%sms.upgrade.op,%sms.list.nums,124),1,46)
    %sms.list.nums = %sms.list.nums + 1
  }
  if ($did(%sms_dialog,%sms.curcombo).lines != 0) {
    did -c %sms_dialog %sms.curcombo 1

    if ($mid($did(%sms_dialog,9).seltext,1,3) == [!]) %sms_upgr.oper = $gettok($did(%sms_dialog,9).seltext,2,93) | else %sms_upgr.oper = $did(%sms_dialog,9).seltext
    did -o sms_upgrade 12 1 Версия на сайте от $mid($sms_upgrade_op_ver,5,2) $+ . $+ $mid($sms_upgrade_op_ver,3,2) $+ . $+ $mid($sms_upgrade_op_ver,1,2) $mid($sms_upgrade_op_ver,7,2) $+ : $+ $mid($sms_upgrade_op_ver,9,2)
    if ($mid($did(%sms_dialog,9).seltext,1,3) == [!]) did -o sms_upgrade 13 1 Ваша версия от $mid($sms_read_op_ver,5,2) $+ . $+ $mid($sms_read_op_ver,3,2) $+ . $+ $mid($sms_read_op_ver,1,2) $mid($sms_read_op_ver,7,2) $+ : $+ $mid($sms_read_op_ver,9,2)
    else did -o sms_upgrade 13 1 У вас нет этого оператора.
    did -e %sms_dialog %sms.blbut 
    return 1
  }
  else return 0
}
alias sms_op_update {
  if ($1 == 1) {
    %sms.upgrade.op = $2-
    if ($sms_upgrade_set_op == 0) sms_extra.at Новых операторов нет
  }
  if ($1 == 2) {
    if ($mid($did(%sms_dialog,9).seltext,1,3) == [!]) remini " $+ $nofile($script) $+ operators.ini $+ " %sms_upg.country $+ . $+ %sms_upg.region $+ . $+ %sms_upgr.oper
    write " $+ $nofile($script) $+ operators.ini $+ " $replace($2-,~,$lf)
    if ($sms_upgrade_set_op == 0) sms_extra.at Загружено. Новых операторов нет.
    else sms_extra.at Загружено.
  }
}
;===================================================
alias -l sms_upgrade_op_ver return $gettok($wildtok(%sms.upgrade.op,%sms_upgr.oper $+ *,1,124),2,46)
alias -l sms_read_op_ver return $readini($nofile($script) $+ operators.ini,%sms_upg.country $+ . $+ %sms_upg.region $+ . $+ %sms_upgr.oper,ver)
;***************************************************
on 1:dialog:sms_upgrade:sclick:*:{
  %sms_dialog = sms_upgrade
  if ($did == 5) { did -r $dname 1,7,9 | did -b $dname 6,8,10 | %sms.curcombo = 1 | %sms.blbut = 6 | sms_update }
  if ($did == 6) { did -r $dname 7,9 | did -b $dname 8,10 | %sms.curcombo = 7 | %sms.blbut = 8 | %sms_upg.country = $did(1).seltext | sms_update $did(1).seltext }
  if ($did == 8) { did -r $dname 9 | did -b $dname 10 | %sms.curcombo = 9 | %sms.blbut = 10 | %sms_upg.region = $did(7).seltext | sms_update %sms_upg.country $did(7).seltext }
  if ($did == 10) {  sms_update %sms_upg.country %sms_upg.region $wildtok(%sms.upgrade.op,%sms_upgr.oper $+ *,1,124) | halt }
  if ($did == 9) {
    if ($mid($did(9).seltext,1,3) == [!]) %sms_upgr.oper = $gettok($did(9).seltext,2,93) | else %sms_upgr.oper = $did(9).seltext
    did -o sms_upgrade 12 1 Версия на сайте от $mid($sms_upgrade_op_ver,5,2) $+ . $+ $mid($sms_upgrade_op_ver,3,2) $+ . $+ $mid($sms_upgrade_op_ver,1,2) $mid($sms_upgrade_op_ver,7,2) $+ : $+ $mid($sms_upgrade_op_ver,9,2)
    if ($mid($did(9).seltext,1,3) == [!]) did -o sms_upgrade 13 1 Ваша версия от $mid($sms_read_op_ver,5,2) $+ . $+ $mid($sms_read_op_ver,3,2) $+ . $+ $mid($sms_read_op_ver,1,2) $mid($sms_read_op_ver,7,2) $+ : $+ $mid($sms_read_op_ver,9,2)
    else did -o sms_upgrade 13 1 У вас нет этого оператора.
  }
}
;***************************************************
on 1:dialog:sms_upgrade:close:*:{
  if (($dialog(sms_dialog) == $null) && ($dialog(sms_add_user) == $null) && ($dialog(sms_log) == $null) && ($dialog(sms_extra) == $null) && ($dialog(sms_adds) == $null) && ($dialog(sms_prefer) == $null)) .unload -rs sms_other.mrc
  if (($dialog(sms_adds) == $null) && ($dialog(sms_dialog) == $null)) .unload -rs sms_http.mrc
  .unload -rs sms_upgrade.mrc
}
