Added tcl (mod_rivet) realization
This commit is contained in:
parent
f1d16afe25
commit
cad6ff9fef
|
@ -8,12 +8,17 @@
|
|||
|
||||
package require mysqltcl
|
||||
|
||||
|
||||
proc main {} {
|
||||
if { [::rivet::var exists query_type] } {
|
||||
set query_type [::rivet::var get query_type]
|
||||
if {$query_type == "internal"} {
|
||||
set output "[header] [body] [getInternalNumbers] [footer]"
|
||||
} elseif {$query_type == "external"} {
|
||||
set output "[header] [body] [getCOline] [footer]"
|
||||
} elseif {$query_type == "ldap"} {
|
||||
set output "[header] [body] [getLDAPusers] [footer]"
|
||||
} elseif {$query_type == "report"} {
|
||||
set output "[header] [body] [reportForm] [reportData] [footer]"
|
||||
}
|
||||
} else {
|
||||
set output "[header] [body] [footer]"
|
||||
|
@ -21,7 +26,6 @@ proc main {} {
|
|||
return $output
|
||||
}
|
||||
|
||||
|
||||
proc header {} {
|
||||
set txtHeader "<html><head><meta charset=\"utf-8\"><link rel=\"shortcut icon\" href=\"favicon.png\" >\n
|
||||
<link rel=\"icon\" type=\"image/png\" href=\"favicon.png\" >\n
|
||||
|
@ -54,8 +58,10 @@ proc menu {} {
|
|||
}
|
||||
|
||||
proc connectDB {} {
|
||||
return [mysql::connect -host localhost -user root -db ats -encoding binary]
|
||||
|
||||
return [mysql::connect -host localhost -user root -db ats]
|
||||
}
|
||||
proc disconnectDB {handle} {
|
||||
mysql::close $handle
|
||||
}
|
||||
|
||||
# Список внутренних номеров из СУБД
|
||||
|
@ -65,7 +71,6 @@ proc getInternalNumbers {} {
|
|||
set result "<h4 align=left>Список внутренних телефонов</h4>"
|
||||
set qr "SELECT * FROM int_number ORDER by $order"
|
||||
set query [mysql::query $conn $qr]
|
||||
|
||||
set listHeader "<table class=\"table_dark\"><tr><th>№ п/п</th>\n
|
||||
<th><a href=index.py?query_type=internal&order=int_number>Телефон</a></th>\n
|
||||
<th><a href=index.py?query_type=internal&order=fio>ФИО</a></th>\n
|
||||
|
@ -73,34 +78,122 @@ proc getInternalNumbers {} {
|
|||
set result "$result $listHeader"
|
||||
set rowData ""
|
||||
while {[set row [mysql::fetch $query]]!=""} {
|
||||
set rowData "<tr><td>[lindex $row 0]</td>
|
||||
append rowData "<tr><td>[lindex $row 0]</td>
|
||||
<td>[lindex $row 1]</td>
|
||||
<td>[lindex $row 2]</td>
|
||||
<td>[lindex $row 4]</td>
|
||||
<td><a href=\"mailto:[lindex $row 3]\">[lindex $row 3]</a></td></tr>\n"
|
||||
}
|
||||
mysql::endquery $query
|
||||
#set result "$result [encoding convertto utf-8 $rowData]"
|
||||
set result "$result $rowData"
|
||||
|
||||
disconnectDB $conn
|
||||
return "$result </table>\n"
|
||||
|
||||
}
|
||||
|
||||
|
||||
# Список пользователей (ФИО, телефон, почта, отдел) из LDAP (AD)
|
||||
proc getLDAPusers {} {
|
||||
}
|
||||
|
||||
# Список внешних линий
|
||||
proc getCOline {} {
|
||||
set conn [connectDB]
|
||||
set order "ext_co_line"
|
||||
set result "<h4 align=left>Список городских линий</h4>"
|
||||
set qr "SELECT * FROM ext_co_line ORDER by $order"
|
||||
set query [mysql::query $conn $qr]
|
||||
|
||||
set listHeader "<table class=\"table_dark\"><tr><th>№ п/п</th>\n
|
||||
<th><a href=index.py?query_type=external&order=int_number>Линия</a></th>\n
|
||||
<th><a href=index.py?query_type=external&order=fio>Номер</a></th>\n
|
||||
<th>Описание</tr>\n"
|
||||
set result "$result $listHeader"
|
||||
set rowData ""
|
||||
while {[set row [mysql::fetch $query]] != ""} {
|
||||
append rowData "<tr><td>[lindex $row 0]</td>
|
||||
<td>[lindex $row 1]</td>
|
||||
<td>[lindex $row 2]</td>
|
||||
<td>[lindex $row 3]</td></tr>\n"
|
||||
}
|
||||
mysql::endquery $query
|
||||
#set result "$result [encoding convertfro utf-8 $rowData]"
|
||||
set result "$result $rowData"
|
||||
disconnectDB $conn
|
||||
return "$result </table>\n"
|
||||
}
|
||||
|
||||
proc ReportForm {} {
|
||||
}
|
||||
|
||||
proc ReportData {environ} {
|
||||
proc reportForm {} {
|
||||
set txtReportForm "<h3 align=center>Отчёт по звонкам</h3><table><tr valign=top><td>
|
||||
<form><input type=hidden name=\"query_type\" value=\"report\">
|
||||
<fieldset class=\"report\">
|
||||
<label>Номер<input type=\"text\" name=\"int_number\"></label>
|
||||
<label>Период с<input type=\"date\" name=\"date_begin\"></label>
|
||||
<label>По<input type=\"date\" name=\"date_end\"></label>
|
||||
</fieldset>
|
||||
<fieldset class=\"report-action\">
|
||||
<input class=\"btn\" type=\"submit\" name=\"submit\" value=\"Выбрать\">
|
||||
</fieldset></form></td>"
|
||||
return $txtReportForm
|
||||
}
|
||||
|
||||
proc reportData {} {
|
||||
set result ""
|
||||
set err ""
|
||||
# Проверяем введенные параметры отчёта как на наличие так и на корректность
|
||||
if { [::rivet::var exists int_number] } {
|
||||
set number [::rivet::var get int_number]
|
||||
if {[regexp -nocase -all -- {^([0-9][0-9][0-9])$} $number match v1]} {
|
||||
append result $number
|
||||
} else {
|
||||
append err "<p><font color=red></b>Введите номер телефона</b></font></p>"
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
if { [::rivet::var exists date_begin] } {
|
||||
if [regexp -nocase -- {^(0[1-9]|[12][0-9]|3[01])[.](0[1-9]|1[012])[.](19|20[0-9][0-9])$} [::rivet::var get date_begin] match d m y] {
|
||||
set dBegin "$y-$m-$d"
|
||||
} else {
|
||||
append err "<p><font color=red></b>Введите дату начала</b></font></p>"
|
||||
}
|
||||
}
|
||||
if { [::rivet::var exists date_end] } {
|
||||
if [regexp -nocase -- {^(0[1-9]|[12][0-9]|3[01])[.](0[1-9]|1[012])[.](19|20[0-9][0-9])$} [::rivet::var get date_end] match d m y] {
|
||||
set dEnd "$y-$m-$d"
|
||||
} else {
|
||||
append err "<p><font color=red></b>Введите дату окончания</b></font></p>"
|
||||
}
|
||||
}
|
||||
if {$err ne ""} {
|
||||
return "<td>$err</td></tr></table>"
|
||||
}
|
||||
set conn [connectDB]
|
||||
set order "call_date"
|
||||
set result "<td><h4 align=left>Список звонков с номера $number</h4>"
|
||||
set qr "SELECT * FROM cdr where int_number=\'$number\' AND call_date BETWEEN CAST(\'$dBegin\' AS DATE) AND CAST(\'$dEnd\' AS DATE) LIMIT 1000"
|
||||
set query [mysql::query $conn $qr]
|
||||
set listHeader "<table class=\"table_dark\"><tr>
|
||||
<th>№ п/п</th><th>Дата</th><th>Время</th><th>Внут.номер</th><th>Внеш.линия</th><th>Вызываемый номер</th>
|
||||
<th>Ring</th><th>Длительность</th><th>АСС</th><th>Код звонка</th><th>Направление</th><tr>"
|
||||
|
||||
append result $listHeader
|
||||
set rowData ""
|
||||
while {[set row [mysql::fetch $query]]!=""} {
|
||||
append rowData "<tr>"
|
||||
# этот цикл формирует строку:
|
||||
#rowData = '<td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td><td>{}</td></tr>'\
|
||||
#.format(row[0], row[1], row[2], row[3], row[4], row[5], row[5], row[7], row[9], row[9], row[10])
|
||||
for {set i 0} {$i <=10} {incr i} {
|
||||
append rowData "<td>[lindex $row $i]</td>"
|
||||
}
|
||||
}
|
||||
|
||||
append result "$rowData </table></td></tr></table>"
|
||||
|
||||
return $result
|
||||
}
|
||||
|
||||
#puts [header]
|
||||
#puts [body]
|
||||
#puts [footer]
|
||||
puts [main]
|
||||
?>
|
||||
|
||||
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
<?
|
||||
######################################################
|
||||
# web
|
||||
# Distributed under GNU Public License
|
||||
# Author: Sergey Kalinin banzaj28@yandex.ru
|
||||
# Copyright (c) "Sergey Kalinin", 2017, http://nuk-svk.ru
|
||||
######################################################
|
||||
|
||||
|
||||
set errlist {}
|
||||
if { [::rivet::var exists title] } {
|
||||
set title [::rivet::var get title]
|
||||
} else {
|
||||
set errlist "You need to enter a title"
|
||||
}
|
||||
|
||||
if { [::rivet::var exists salary] } {
|
||||
set salary [::rivet::var get salary]
|
||||
if { ! [string is digit $salary] } {
|
||||
lappend errlist "Salary must be a number"
|
||||
}
|
||||
} else {
|
||||
lappend errlist "You need to enter a salary"
|
||||
}
|
||||
|
||||
if { [::rivet::var exists boss] } {
|
||||
set boss [::rivet::var get boss]
|
||||
} else {
|
||||
set boss "Mr. Burns"
|
||||
}
|
||||
|
||||
if { [::rivet::var exists skills] } {
|
||||
set skills [::rivet::var list skills]
|
||||
} else {
|
||||
lappend errlist "You need to enter some skills"
|
||||
}
|
||||
|
||||
if { [llength $errlist] != 0 } {
|
||||
foreach err $errlist {
|
||||
puts "<b> $err </b>"
|
||||
}
|
||||
} else {
|
||||
puts "Thanks for the information!"
|
||||
?>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><b>Title:</b></td>
|
||||
<td><?= $title ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>Boss:</b></td>
|
||||
<td><?= $boss ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>Salary:</b></td>
|
||||
<td><?= $salary ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>Skills:</b></td>
|
||||
<td><?= $skills ?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user