;***************************************************
dialog sms_log {
  title "Логи сообщений"
  size -1 -1 204 123
  option dbu
  list 1, 6 14 50 77, size
  list 2, 58 14 60 77, size
  edit "", 3, 120 25 76 66, read multi return autohs autovs hsbar vsbar
  text "Адресат", 4, 7 4 25 8
  text "Дата", 5, 59 4 25 8
  text "Время и сообщение", 10, 122 4 49 8
  button "Копировать в буфер", 6, 120 94 76 10
  button "Перенести в текущее", 7, 120 106 76 10
  button "Удалить все логи адресата", 8, 6 94 50 22, multi
  button "Удалить соощение", 9, 59 94 60 22, multi
  combo 11, 121 14 74 77, size drop
}
;***************************************************
alias sms_log_set_adr {
  did -r sms_log 1 | %sms.log.num = 1
  %sms.log.num = 1
  while ($ini($nofile($script) $+ sms_logs.ini,%sms.log.num) != $null) {
    did -i sms_log 1 %sms.log.num $ini($nofile($script) $+ sms_logs.ini,%sms.log.num)
  %sms.log.num = %sms.log.num + 1 }
  did -c sms_log 1 1 
sms_log_set_date }
;***************************************************
alias sms_log_set_date {
  did -r sms_log 2 | %sms.log.num = 1
  while ($ini($nofile($script) $+ sms_logs.ini,$did(sms_log,1).seltext,%sms.log.num) != $null) {
    if (!$didwm(sms_log,2,$gettok($ini($nofile($script) $+ sms_logs.ini,$did(sms_log,1).seltext,%sms.log.num),1,39))) did -i sms_log 2 $calc($did(sms_log,2).lines + 1) $gettok($ini($nofile($script) $+ sms_logs.ini,$did(sms_log,1).seltext,%sms.log.num),1,39)
    %sms.log.num = %sms.log.num + 1
  }
  did -c sms_log 2 1 
sms_log_set_time }
;***************************************************
alias sms_log_set_time {
  did -r sms_log 11 | %sms.log.num = 1
  while ($ini($nofile($script) $+ sms_logs.ini,$did(sms_log,1).seltext,%sms.log.num) != $null) {
    if ($gettok($ini($nofile($script) $+ sms_logs.ini,$did(sms_log,1).seltext,%sms.log.num),1,39) == $did(sms_log,2).seltext) {
      if (!$didwm(sms_log,11,$gettok($ini($nofile($script) $+ sms_logs.ini,$did(sms_log,1).seltext,%sms.log.num),2,39))) did -i sms_log 11 $calc($did(sms_log,11).lines + 1) $gettok($ini($nofile($script) $+ sms_logs.ini,$did(sms_log,1).seltext,%sms.log.num),2,39)
    }
    %sms.log.num = %sms.log.num + 1
  }
  did -c sms_log 11 1 
sms_log_set_mess }
;***************************************************
alias sms_log_set_mess {
  did -r sms_log 3
  did -o sms_log 3 1 $replace($readini($nofile($script) $+ sms_logs.ini, $did(sms_log,1).seltext, $did(sms_log,2).seltext $+ ' $+ $did(sms_log,11).seltext),$chr(1),$crlf)
}
;***************************************************
on 1:dialog:sms_log:init:*:sms_log_set_adr
;***************************************************
on 1:dialog:sms_log:sclick:*:{
  if ($did == 1) { if ($did(1).seltext == $null) return | sms_log_set_date  }
  if ($did == 2) { if ($did(2).seltext == $null) return | sms_log_set_time  }
  if ($did == 11) { if ($did(11).seltext == $null) return | sms_log_set_mess  }
  if ($did == 6) { clipboard $replace($readini($nofile($script) $+ sms_logs.ini, $did(sms_log,1).seltext, $did(sms_log,2).seltext $+ ' $+ $did(sms_log,11).seltext),$chr(1),$crlf) }
  if ($did == 7) {
    did -r sms_dialog 10
    did -o sms_dialog 10 1 $replace($readini($nofile($script) $+ sms_logs.ini, $did(sms_log,1).seltext, $did(sms_log,2).seltext $+ ' $+ $did(sms_log,11).seltext),$chr(1),$crlf)
    sms_trans_edit 1
    dialog -x sms_log
  }
  if ($did == 8) { remini " $+ $nofile($script) $+ sms_logs.ini $+ " " $+ $did(1).seltext $+ " | sms_log_set_adr }
  if ($did == 9) { remini " $+ $nofile($script) $+ sms_logs.ini $+ " $did(1).seltext $did(2).seltext $+ ' $+ $did(11).seltext 
    if ($did(11).lines == 1 && $did(2).lines == 1) { remini " $+ $nofile($script) $+ sms_logs.ini $+ " " $+ $did(1).seltext $+ " | sms_log_set_adr }
    if ($did(11).lines == 1 && $did(2).lines != 1) { sms_log_set_date }
    if ($did(11).lines != 1) { sms_log_set_time }
  }
}
;***************************************************
on 1:dialog:sms_log:close:*:{
  if (($dialog(sms_dialog) == $null) && ($dialog(sms_upgrade) == $null) && ($dialog(sms_add_user) == $null) && ($dialog(sms_extra) == $null) && ($dialog(sms_adds) == $null) && ($dialog(sms_prefer) == $null)) .unload -rs sms_other.mrc
  .unload -rs sms_logs.mrc
}
