[% PROCESS tt/callforward_head.tt %]
[% META title = 'Call forward' %]

<div id="main">
    
    <div id="topmsg">
        <p> [% messages.topmsg %] </p>
    </div>
    <div id="toperr">
        <p> [% messages.toperr %] </p>
        <p> [% messages.prov_error %] </p>
    </div>

<div class="sperrehead">
    <h3>[% Catalyst.loc('Destination sets') %]</h2>
    <h2 class="umleitungfuer">[% Catalyst.loc('Settings for [_1]', subscriber.active_number) %]</h2>
</div>

<div id="spalten31">
    <div class="spalte1">
        
        [% FOREACH dset IN destination_sets %]
            <div id="dset-[% dset.id %]" class="set-container span-15 last">
              <div class="set-item span-15 last">
                  [% IF dset_id == dset.id %]
                      [% PROCESS set action = 'edit' %]
                  [% ELSE %]
                      [% PROCESS set action = 'view' %]
                  [% END %]
              </div>
 
              [% priority = 0 %]
              [% FOREACH dest IN dset.destinations %]

               <div id="dest-[% dest.id %]" class="sub-container span-15 last">
               [% IF (dest.id == -1) %]
                  [% PROCESS target action = 'add' %]
               [% ELSIF dtarget_id == dest.id %]
                  [% PROCESS target action = 'edit' %]
               [% ELSE %]
                  [% PROCESS target action = 'view' %]
               [% END %]

                [% priority = priority + 1 %]
                </div> <!-- dest-item -->
              [% END %]

              [%# dest is still available. this is expected behaviour 
                  see: http://template-toolkit.org/docs/manual/Directives.html#section_FOREACH %]

              [% IF priority == 0 or dset_id == dset.id %] [%# either editing set or nothing here so far, offer empty one %]
                  [% dest = undef %] [%# dest still holds the last one %]
                  <div class="sub-container span-15 last">
                      [% PROCESS target action = 'add' %]
                  </div>
              [% END %]

            </div> <!-- set-container -->
            <br clear="all" />
        [% END %]

        <div class="set-container span-15 last">
        <div class="set-item span-15 last">
            [% PROCESS set action = 'add' %]
        </div></div>

        </div> <!-- spalte1 -->

        <div class="spalte2">
            [% PROCESS tt/callforward_navi.tt %]
        </div> <!-- spalte2 -->

    </div> <!-- spalten31 -->
</div> <!-- main -->
  
<br clear="all" />

[%# ================================= %]

[% BLOCK set %]
    [% IF action == 'edit' or action == 'add' %]
        <form action="/callforward/destination/set/save" method="post">
        [% IF action == 'edit' %]
            <div class="span-8"> <input type="text" size="20" name="dsetname" value="[% dset.name %]"/> </div>
            [% FOREACH dest IN dset.destinations %]
                <input type="hidden" name="priority-[% dest.id %]" value="[% dest.priority.defined ? dest.priority : "0" %]"/>
            [% END %]
            <input type="hidden" name="priority_changed" value="0"/>
        [% ELSE %]
            <div class="span-8"> <input type="text" size="20" name="dsetname" value=""/> </div>
        [% END %]
    [% ELSE %]
        <form action="/callforward/destination/set/delete" method="post">
        <div class="span-8">[% dset.name %]</div>
    [% END %]
    
    <input type="hidden" name="subscriber_id" value="[% subscriber.subscriber_id %]"/>
    
    [% IF action == 'edit' or action == 'view' %]
        <input type="hidden" name="dset_id" value="[% dset.id %]"/>
    [% END %]

    [% IF action == 'edit' %]
        <div class="span-2">
            <p class="link_button">
                <label for="save_dset_[% dset.id %]">[% Catalyst.loc('Save') %]</label>
                <input type="image" class="hidden" src="/grafik/dot_trans.gif" alt="" id="save_dset_[% dset.id %]">
            </p>
        </div>
        <div class="span-1">
            <a class="link" href="/callforward/destination">[% Catalyst.loc('Cancel') %]</a>
        </div>
    [% ELSIF action == 'add' %]
        <div class="span-1"></div>
        <div class="span-3">
            <p class="link_button">
                <label for="add_dset_[% dset.id %]">[% Catalyst.loc('Add destinationset') %]</label>
                <input type="image" class="hidden" src="/grafik/dot_trans.gif" alt="" id="add_dset_[% dset.id %]">
            </p>
        </div>
    [% ELSIF action == 'view' %]
        <div class="span-2"><a class="link" href="/callforward/destination/set/[% dset.id %]/edit#dset-[% dset.id %]"><span class="button-edit">[% Catalyst.loc('Edit') %]</span></a></div>
        <div class="span-4">
            [% IF mapped.${dset.id} %]
                <p>[% mapped.${dset.id} %] [% Catalyst.loc('times(s) mapped') %]</p>
            [% ELSE %]
                <p class="link_button">
                    <label for="delete_dset_[% tset.id %]">[% Catalyst.loc('Delete') %]</label>
                    <input type="image" class="hidden" src="/grafik/dot_trans.gif" alt="" id="delete_dset_[% tset.id %]">
                </p>
            [% END %]
        </div>
    [% END %]

    </form>

[% END %]

[%# ================================= %]

[% BLOCK target %]

    [% IF action == 'edit' or action == 'add' %]
        <form action="/callforward/destination/target/save" method="post">
    [% ELSIF action == 'view' %]
        <form action="/callforward/destination/target/delete" method="post">
    [% END %]
        
    <input type="hidden" name="subscriber_id" value="[% subscriber.subscriber_id %]"/>
    <input type="hidden" name="dset_id" value="[% dset.id %]"/>
    
    [% IF action == 'edit' or action == 'view' %]
        <input type="hidden" name="dtarget_id" value="[% dest.id %]"/>
    [% END %]          

    [% IF action == 'edit' or action == 'add' %] 
        <div class="span-1">&nbsp;</div>
        <div class="span-10">
            [% IF Catalyst.config.voicemail_features %]
                <input type="radio" id="dest_voicebox" value="voicebox" name="dest_target" class="radio" 
                    [% IF dest.destination == "voicebox" %] checked="checked"[% END %]/>
                <label for="dest_voicebox">[% Catalyst.loc('Voicebox') %]</label>
                <br clear="all" />
            [% END %]
            [% IF Catalyst.config.fax_features %]
                <input type="radio" id="dest_faxserver" value="fax2mail" name="dest_target" class="radio"
                    [% IF dest.destination == "fax2mail" %] checked="checked"[% END %]/>
                <label for="[% preference.key %]faxserver">[% Catalyst.loc('Fax2Mail') %]</label>
                <br clear="all" />
            [% END %]

            [% IF Catalyst.config.conference_features %]
                <input type="radio" id="dest_conference" value="conference" name="dest_target" class="radio"
                    [% IF dest.destination == "conference" %] checked="checked"[% END %]/>
                <label for="[% preference.key %]conference">[% Catalyst.loc('Conference room') %]</label>
                <br clear="all" />
            [% END %]

            <input type="radio" id="dest_sipuri" value="sipuri" name="dest_target" class="radio"
                [% IF dest.destination != "conference" && dest.destination != "voicebox" && dest.destination != "fax2mail" %] 
                    checked="checked"[% END %]/>
            <label for="[% preference.key %]sipuri">[% Catalyst.loc('Number or SIP-URI:') %]</label>
            
            [% value = '' %]
            [% IF dest.destination != "conference" && dest.destination != "voicebox" && dest.destination != "fax2mail" %]
                [% value = dest.destination %]
            [% END %]
            <input type="text" id="dest_sipuritxt" name="dest_sipuri" size="20" value="[% value %]"/>
            <label for="[% preference.key %]timeout">[% Catalyst.loc('for') %]</label>

            [% value = '' %]
            [% IF dest.timeout.defined %]
                [% value = dest.timeout %]
            [% ELSE %]
                [% value = 300 %]
            [% END %]
            <input type="text" id="dest_timeout" name="dest_timeout" size="2" value="[% value %]" /><span>&nbsp;[% Catalyst.loc('seconds') %]</span>
           
            [% IF dest.id == dtarget_id %]
                [% IF messages.err_target %] <div id="errormsg"><p>[% messages.err_target %]</p></div> [% END %]
                [% IF messages.err_timeout %] <div id="errormsg"><p>[% messages.err_timeout %]</p></div> [% END %]
            [% END %]
        </div>

        [% IF action == 'edit' %]
            <div class="span-2">
                <p class="link_button">
                    <label for="save_dest_[% dest.id %]">[% Catalyst.loc('Save') %]</label>
                    <input type="image" class="hidden" src="/grafik/dot_trans.gif" alt="" id="save_dest_[% dest.id %]">
                </p>
            </div>
            <div class="span-1 last">
                <a class="link" href="/callforward/destination"><span class="button-cancel">[% Catalyst.loc('Cancel') %]</span></a>
            </div>
        [% ELSIF action == 'add' %]
            <div class="span-2 last">
                <p class="link_button">
                    <label for="add_dest_[% dset.id %]">[% Catalyst.loc('Add destination') %]</label>
                    <input type="image" class="hidden" src="/grafik/dot_trans.gif" alt="" id="add_dest_[% dset.id %]">
                </p>
            </div>
        [% END %]
    
    [% ELSIF action == 'view' %]
            <div class="span-1">
            [% IF dset.id == dset_id %]
                <a href="javascript:void(0)" onclick="move_up('dest-' + [% dest.id %])">&uarr;</a>
                <a href="javascript:void(0)" onclick="move_down('dest-' + [% dest.id %])">&darr;</a>
            [% ELSE %]&nbsp;
            [% END %]
            </div>

        <div class="span-10">
            [% IF Catalyst.config.voicemail_features and dest.destination == "voicebox" %]
                [% Catalyst.loc('Voicebox') %]
            [% ELSIF Catalyst.config.fax_features and dest.destination == "fax2mail" %]
                [% Catalyst.loc('Fax2Mail') %]
            [% ELSIF Catalyst.config.conference_features and dest.destination == "conference" %]
                [% Catalyst.loc('Conference room') %]
            [% ELSE %]
                [% dest.destination %] [% Catalyst.loc('for') %] [% dest.timeout %]<span>&nbsp;[% Catalyst.loc('seconds') %]</span>
            [% END %]
        </div>
        <div class="span-2"><a class="link" href="/callforward/destination/target/[% dest.id %]/edit#dest-[% dest.id %]"><span class="button-edit">[% Catalyst.loc('Edit') %]</span></a></div>
        <div class="span-1 last">
            <p class="link_button">
                <label for="delete_dtarget_[% dest.id %]">[% Catalyst.loc('Delete') %]</label>
                <input type="image" class="hidden" src="/grafik/dot_trans.gif" alt="" id="delete_dtarget_[% dest.id %]">
            </p>
        </div>
    [% END %]
        
    </form>        
    
[% END %]
