a36016241f4508a47686699818b16f4830514d69
[project/luci.git] / applications / luci-asterisk / luasrc / view / asterisk / dialplans.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 -%>
15
16 <%+header%>
17
18 <%
19         local uci = luci.model.uci.cursor_state()
20         local ast = require "luci.asterisk"
21
22         function digit_pattern(s,t)
23                 return "<code style='padding: 2px; border:1px solid #CCCCCC; background-color: #FFFFFF'%s>%s</code>"
24                         %{ t and " title='" .. t .. "'" or "", s }
25         end
26
27         function rowstyle(i)
28                 return "cbi-rowstyle-%i" %{
29                         ( i % 2 ) == 0 and 2 or 1
30                 }
31         end
32
33         function format_matches(z)
34                 local html = { }
35
36                 if type(z) ~= "table" then
37                         z = { matches = { z } }
38                 end
39
40                 if z.localprefix then
41                         for _, m in ipairs(z.matches) do
42                                 html[#html+1] =
43                                         digit_pattern(z.localprefix, "local prefix") .. " " ..
44                                         digit_pattern(m)
45                         end
46                 end
47
48                 if z.intlmatches and #z.intlmatches > 0 then
49                         for _, i in ipairs(z.intlmatches) do
50                                 for _, m in ipairs(z.matches) do
51                                         html[#html+1] = "%s %s" %{
52                                                 digit_pattern("(%s)" % i, "intl. prefix"),
53                                                 digit_pattern(m)
54                                         }
55                                 end
56                         end
57                 else
58                         for _, m in ipairs(z.matches) do
59                                 html[#html+1] = digit_pattern(m)
60                         end
61                 end
62
63                 return table.concat(html, "; ")
64         end
65 %>
66
67
68 <form method="post" action="<%=luci.dispatcher.build_url("admin", "asterisk", "dialplans")%>" enctype="multipart/form-data">
69         <div>
70                 <script type="text/javascript" src="/luci-static/resources/cbi.js"></script>
71                 <input type="hidden" name="cbi.submit" value="1" />
72                 <input type="submit" value="Save" class="hidden" />
73         </div>
74
75 <div class="cbi-map" id="cbi-asterisk">
76         <h2><a id="content" name="content">Outgoing Call Routing</a></h2>
77         <div class="cbi-map-descr">
78                 Here you can manage your dial plans which are used to route outgoing calls from your local extensions.<br /><br />
79                 Related tasks:<br />
80                 <a href="<%=luci.dispatcher.build_url('admin/asterisk/dialplans/zones')%>" class="cbi-title-ref">Manage dialzones</a> |
81                 <a href="<%=luci.dispatcher.build_url('admin/asterisk/voicemail/mailboxes')%>" class="cbi-title-ref">Manage voicemail boxes</a> |
82                 <a href="<%=luci.dispatcher.build_url('admin/asterisk/meetme/rooms')%>" class="cbi-title-ref">Manage meetme rooms</a>
83         </div>
84         <!-- tblsection -->
85         <fieldset class="cbi-section" id="cbi-asterisk-sip">
86                 <!--<legend>Dialplans</legend>-->
87                 <div class="cbi-section-descr"></div>
88
89                 <% for i, plan in pairs(ast.dialplan.plans()) do %>
90                 <div class="cbi-section-node">
91                         <table class="cbi-section-table">
92                                 <tr class="cbi-section-table-titles">
93                                         <th style="text-align: left; padding: 3px" class="cbi-section-table-cell">
94                                                 <big>Dialplan <em><%=plan.name%></em></big>
95                                         </th>
96                                         <td>
97                                                 <a href="<%=luci.dispatcher.build_url('admin', 'asterisk', 'dialplans')%>?delplan=<%=plan.name%>">
98                                                         <img style="border:none" alt="Remove this dialplan" title="Remove this dialplan" src="/luci-static/resources/cbi/remove.gif" />
99                                                 </a>
100                                         </td>
101                                 </tr>
102
103                                 <!-- dialzones -->
104                                 <% local zones_used = { }; local row = 0 %>
105                                 <% for i, zone in ipairs(plan.zones) do zones_used[zone.name] = true %>
106                                 <tr class="cbi-section-table-row <%=rowstyle(row)%>">
107                                         <td style="text-align: left; padding: 3px" class="cbi-section-table-cell">
108                                                 <strong>&#x2514; Dialzone <em><%=zone.name%></em></strong> (<%=zone.description%>)
109                                                 <p style="padding-left: 1em; margin-bottom:0">
110                                                         Lines:
111                                                         <%=ast.tools.hyperlinks(
112                                                                 zone.trunks, function(v)
113                                                                         return luci.dispatcher.build_url("admin", "asterisk", "trunks", "%s") % v:lower()
114                                                                 end
115                                                         )%><br />
116                                                         Matches:
117                                                         <%=format_matches(zone)%>
118                                                 </p>
119                                         </td>
120                                         <td style="width:5%" class="cbi-value-field">
121                                                 <a href="<%=luci.dispatcher.build_url('admin/asterisk/dialplans/out', zone.name)%>">
122                                                         <img style="border:none" alt="Edit dialzone" title="Edit dialzone" src="/luci-static/resources/cbi/edit.gif" />
123                                                 </a>
124                                                 <a href="<%=luci.dispatcher.build_url('admin/asterisk/dialplans')%>?delzone.<%=plan.name%>=<%=zone.name%>">
125                                                         <img style="border:none" alt="Remove from this dialplan" title="Remove from this dialplan" src="/luci-static/resources/cbi/remove.gif" />
126                                                 </a>
127                                         </td>
128                                 </tr>
129                                 <% row = row + 1; end %>
130                                 <!-- /dialzones -->
131
132                                 <!-- voicemail -->
133                                 <% local boxes_used = { } %>
134                                 <% for ext, box in luci.util.kspairs(plan.voicemailboxes) do boxes_used[box.id] = true %>
135                                 <tr class="cbi-section-table-row <%=rowstyle(row)%>">
136                                         <td style="text-align: left; padding: 3px" class="cbi-section-table-cell">
137                                                 <strong>&#x2514; Voicemailbox <em><%=box.id%></em></strong> (<%=box.name%>)
138                                                 <p style="padding-left: 1em; margin-bottom:0">
139                                                         Owner: <%=box.name%> |
140                                                         eMail: <%=#box.email > 0 and box.email or 'n/a'%> |
141                                                         Pager: <%=#box.page  > 0 and box.page  or 'n/a'%><br />
142                                                         Matches: <%=format_matches(ext)%>
143                                                 </p>
144                                         </td>
145                                         <td style="width:5%" class="cbi-value-field">
146                                                 <a href="<%=luci.dispatcher.build_url('admin/asterisk/voicemail/mailboxes')%>">
147                                                         <img style="border:none" alt="Edit dialzone" title="Edit dialzone" src="/luci-static/resources/cbi/edit.gif" />
148                                                 </a>
149                                                 <a href="<%=luci.dispatcher.build_url('admin/asterisk/dialplans')%>?delvbox.<%=plan.name%>=<%=ext%>">
150                                                         <img style="border:none" alt="Remove from this dialplan" title="Remove from this dialplan" src="/luci-static/resources/cbi/remove.gif" />
151                                                 </a>
152                                         </td>
153                                 </tr>
154                                 <% row = row + 1; end %>
155                                 <!-- /voicemail -->
156
157                                 <!-- meetme -->
158                                 <% local rooms_used = { } %>
159                                 <% for ext, room in luci.util.kspairs(plan.meetmerooms) do rooms_used[room.room] = true %>
160                                 <tr class="cbi-section-table-row <%=rowstyle(row)%>">
161                                         <td style="text-align: left; padding: 3px" class="cbi-section-table-cell">
162                                                 <strong>&#x2514; MeetMe Room <em><%=room.room%></em></strong> (<%=room.description%>)
163                                                 <p style="padding-left: 1em; margin-bottom:0">
164                                                         Matches: <%=format_matches(ext)%>
165                                                 </p>
166                                         </td>
167                                         <td style="width:5%" class="cbi-value-field">
168                                                 <a href="<%=luci.dispatcher.build_url('admin/asterisk/meetme/rooms')%>">
169                                                         <img style="border:none" alt="Edit dialzone" title="Edit dialzone" src="/luci-static/resources/cbi/edit.gif" />
170                                                 </a>
171                                                 <a href="<%=luci.dispatcher.build_url('admin/asterisk/dialplans')%>?delmeetme.<%=plan.name%>=<%=ext%>">
172                                                         <img style="border:none" alt="Remove from this dialplan" title="Remove from this dialplan" src="/luci-static/resources/cbi/remove.gif" />
173                                                 </a>
174                                         </td>
175                                 </tr>
176                                 <% row = row + 1; end %>
177                                 <!-- /meetme -->
178
179                                 <tr class="cbi-section-table-row">
180                                         <td style="text-align: left; padding: 3px" class="cbi-section-table-cell" colspan="2">
181                                                 <hr style="margin-bottom:0.5em; border-width:0 0 1px 0" />
182
183                                                 Add Dialzone:<br />
184                                                 <select style="width:30%" name="addzone.<%=plan.name%>">
185                                                         <option value="">-- please select --</option>
186                                                         <% for _, zone in luci.util.kspairs(ast.dialzone.zones()) do %>
187                                                                 <% if not zones_used[zone.name] then %>
188                                                                         <option value="<%=zone.name%>"><%=zone.name%> (<%=zone.description%>)</option>
189                                                                 <% end %>
190                                                         <% end %>
191                                                 </select>
192                                                 <br /><br />
193
194                                                 Add Voicemailbox:<br />
195                                                 <select style="width:20%" name="addvbox.<%=plan.name%>" onchange="this.form['addvboxext.<%=plan.name%>'].value=this.options[this.selectedIndex].value.split('@')[0]">
196                                                         <option value="">-- please select --</option>
197                                                         <% for ext, box in luci.util.kspairs(ast.voicemail.boxes()) do %>
198                                                                 <% if not boxes_used[box.id] then %>
199                                                                         <option value="<%=box.id%>"><%=box.id%> (<%=box.name%>)</option>
200                                                                 <% end %>
201                                                         <% end %>
202                                                 </select>
203                                                 as extension
204                                                 <input type="text" style="width:5%" name="addvboxext.<%=plan.name%>" />
205                                                 <br /><br />
206
207                                                 Add MeetMe Conference:<br />
208                                                 <select style="width:20%" name="addmeetme.<%=plan.name%>" onchange="this.form['addmeetmeext.<%=plan.name%>'].value=this.options[this.selectedIndex].value">
209                                                         <option value="">-- please select --</option>
210                                                         <% for ext, room in luci.util.kspairs(ast.meetme.rooms()) do %>
211                                                                 <%# if not rooms_used[room.room] then %>
212                                                                         <option value="<%=room.room%>"><%=room.room%> (<%=room.description%>)</option>
213                                                                 <%# end %>
214                                                         <% end %>
215                                                 </select>
216                                                 as extension
217                                                 <input type="text" style="width:5%" name="addmeetmeext.<%=plan.name%>" />
218                                                 <br /><br />
219
220                                                 <input type="submit" class="cbi-button cbi-button-add" value="Add item &raquo;" title="Add item ..."/>
221                                         </td>
222                                 </tr>
223
224                         </table>
225
226                         <div class="cbi-section-create cbi-tblsection-create"></div>
227                 </div>
228                 <br />
229                 <% end %>
230
231                 <div class="cbi-section-node">
232                         <div class="cbi-section-create cbi-tblsection-create" style="padding: 3px">
233                                 <h3>Create a new dialplan</h3>
234                                 The name is required and must be unique. It may only contain the characters A-Z, a-z, 0-9 and _ .<br />
235
236                                 <%- if create_error then %>
237                                         <br /><span style="color:red">Invalid name given!</span><br />
238                                 <% end -%>
239
240                                 <br />
241                                 <input type="text" class="cbi-section-create-name" name="addplan" style="width:200px" />
242                                 <input type="submit" class="cbi-button cbi-button-add" value="Add dialplan" title="Add dialplan"/>
243                         </div>
244                 </div>
245
246         </fieldset>
247 </div>
248 </form>
249 <div class="clear"></div>
250 <%+footer%>