{include="global_header"}
{if condition="isset($show_error_box)"}
{include="message_box"}
{/if}
<br>
<script type="text/javascript" charset="utf-8"> 
    function add() {
        $('#adding').append('<input type="hidden" name="sub_type" value="add"/>');
        document.adding.submit();
    }
    function submit_go() {
        $('#spinner').toggle();
        $('#go').append('<input type="hidden" name="sub_type" value="go"/>');
        document.go.submit();
    }
    function submit_managed(type) {
        $('#managed').append('<input type="hidden" name="sub_type" value="'+ type +'"/>');
        document.managed.submit();
    }
    function submit_wtype_managed(type,id) {
        $('#managed').append('<input type="hidden" name="edit_id" value="'+ id +'"/><input type="hidden" name="sub_type" value="'+ type +'"/>');
        document.managed.submit();
    }
    function submit_unmanaged() {
        $('#unmanaged').append('<input type="hidden" name="sub_type" value="add_selected_phones"/>');
        document.unmanaged.submit();
    }
    function submit_global(type) {
        $('#globalmanaged').append('<input type="hidden" name="sub_type" value="'+ type +'"/>');
        document.globalmanaged.submit();
    }
    function submit_global2(type) {
        $('#globalmanaged2').append('<input type="hidden" name="sub_type" value="'+ type +'"/>');
        document.globalmanaged2.submit();
    }
    function submit_global3(type) {
        $('#globalmanaged3').append('<input type="hidden" name="sub_type" value="'+ type +'"/>');
        document.globalmanaged3.submit();
    }
    function submit_wtype(type,id) {
        $('#adding').append('<input type="hidden" name="edit_id" value="'+ id +'"/><input type="hidden" name="sub_type" value="'+ type +'"/>');
        document.adding.submit();
    }
    function submit_wtype_sub(type,id,sub) {
        $('#adding').append('<input type="hidden" name="edit_id" value="'+ id +'"/><input type="hidden" name="sub_type" value="'+ type +'"/><input type="hidden" name="sub_type_sub" value="'+ sub +'"/>');
        document.adding.submit();
    }
    function delete_device(id) {
        if (confirm('Are you sure you want to delete this device?')) {
            submit_wtype('delete_device',id);
        }
    }
    function popitup(url, name) {
        newwindow=window.open(url + '&model_list=' + document.getElementById('model_new').value + '&template_list=' + document.getElementById('template_list').value + '&rand=' + new Date().getTime(),'name2','height=1000,width=950');
        if (window.focus) {newwindow.focus()}
        return false;
    }

    function submit_stype(type,id) {
        newwindow=window.open('config.php?display=epm_config&quietmode=1&handler=file&file=popup.html.php&module=endpointman&pop_type=edit_specifics&edit_id=' + id + '&rand=' + new Date().getTime(),'name2','height=700,width=750');
        if (window.focus) {newwindow.focus()}
        return false;
    }
</script>

<center>
    {if condition="$no_add == FALSE"}
    <form id='go' action='config.php?type=tool&amp;display=epm_devices' method='POST'>
        <label><?php echo _('Search for new devices in netmask')?>
            <input name="netmask" type="text" value="{$srvip}/24">
            <input type="Submit" name="button_go" id="button_go" onclick="submit_go();" value="<?php echo _('Go')?>">
        </label>
        <label>
            <input name="nmap" type="checkbox" value="1" checked><?php echo _('Use NMAP')?>
        </label>
    </form>
    {/if}
</center>
<table align='center' width='90%'>
    <tr>
        <td align='center' width='45'></td>
        <td width="157" align='center'><h3><?php echo _('Mac Address')?></h3></td>
        <td width="187" align='center'><h3><?php echo _('Brand')?></h3></td>
        <td width="216" align='center'><h3><?php echo _('Model of Phone')?></h3></td>
        <td width="172" align='center'><h3><?php echo _('Line')?></h3></td>
        <td width="275" align='center'><h3><?php echo _('Extension Number')?></h3></td>
        <td width="154" align='center'><h3><?php echo _('Template')?></h3></td>

        <td width="234" align='center'></td>
        <td align='center'></td>
    </tr>
        <form name="adding" id="adding" action='config.php?type=tool&amp;display=epm_devices' method='POST' />

	{if condition="$no_add == FALSE"}
    <tr>
    <td align='center' width='2%'>&nbsp;</td>

    <td align='center'>
	{if condition="$mode == 'EDIT'"}
	{$mac}
	{else}
        <input name='mac' type='text' tabindex='1' size="17" maxlength="17">
	{/if}</td>
    <td align='center'>  <label>
	{if condition="$mode == 'EDIT'"}
            {$name}
	{else}
            <select name="brand_list" id="brand_edit">
                {loop name="brand_ava"}
                <option value="{$value.value}" {if condition="isset($value.selected)"}selected{/if}>{$value.text}</option>
                {/loop}
            </select></label>
	{/if}
    </td>
    <td align='center'>
        <label>
	{if condition="$mode == 'EDIT'"}
            <input name="display" type="hidden" value="epm_devices">
            <select name="model_list" id="model_new">
                {loop name="models_ava"}
                <option value="{$value.value}" {if condition="!empty($value.selected)"}selected{/if}>{$value.text}</option>
                {/loop}
            </select>
	{else}
            <select name="model_list" id="model_new"><option></option></select>
	{/if}
        </label></td>
    <td align='center'></td>
    <td align='center'></td>
    <td align='center'>  <div id="demo"><select name="template_list" id="template_list">
                {loop name="display_templates"}
                <option value="{$value.value}" {if condition="isset($value.selected)"}selected{/if}>{$value.text}</option>
                {/loop}
            </select>
            <a href="#" onclick="return popitup('config.php?display=epm_config&amp;quietmode=1&amp;handler=file&amp;file=popup.html.php&amp;module=endpointman&amp;pop_type=edit_template&amp;edit_id={$edit_id}', 'Template Editor')"><img src='assets/endpointman/images/edit.png' title="Edit Template Selected on the Left" border="0"></a></div>
        </label></td>
    <td align='center'>
	{if condition="$mode == 'EDIT'"}
        <input type='Submit' name='button_save' onclick="submit_wtype_sub('edit',{$edit_id},'button_save');" value='<?php echo _('Save')?>'>
	{else}
               <input type='Submit' name='button_add' onclick="add();" value='<?php echo _('Add')?>'>
	{/if}
    </td>

    <td align='center'>{if condition="$mode != 'EDIT'"}<input type='reset' value='<?php echo _('Reset')?>'>{/if}</td>
</tr>
{loop name="line_list_edit"}
<tr>
    <td align='center' width='2%'>&nbsp;</td>

    <td align='center'></td>
    <td align='center'></td>
    <td align='center'></td>
    <td align='center'>
        <label>
            <select name="line_list_{$value.luid}" id="line_list" >
                {loop name="value.line_list"}
                <option value="{$value.value}" {if condition="isset($value.selected)"}selected{/if}>{$value.text}</option>
                {/loop}
            </select>
        </label></td>
    <td align='center'>
        <select name="ext_list_{$value.luid}" id="select">
            {loop name="value.reg_list"}
            <option value="{$value.value}" {if condition="isset($value.selected)"}selected{/if}>{$value.text}</option>
            {/loop}
        </select>
        </label>
    </td>
    <td align='center'></td>
    <td align='center'>{if condition="!isset($disabled_delete_line)"}<div id="demo"><a href="#" onclick="submit_wtype_sub('edit',{$value.luid},'delete');"><img src="assets/endpointman/images/delete.png" title="Delete Line from Device to the Left"></div>{/if}</a></td>
    <td align='center'></td>
</tr>
{/loop}
{if condition="$mode != 'EDIT'"}
<tr>
    <td align='center' width='2%'>&nbsp;</td>

    <td align='center'></td>
    <td align='center'></td>
    <td align='center'></td>
    <td align='center'>
        <label>
            <select name="line_list" id="line_list" >
                <option></option>
            </select>
        </label></td>
    <td align='center'>
        <select name="ext_list" id="select">
            {loop name="display_ext"}
            <option value="{$value.value}">{$value.text}</option>
            {/loop}
        </select>
        </label>
    </td>
    <td align='center'></td>
    <td align='center'></a></td>
    <td align='center'></td>
</tr>
{/if}
{if condition="$mode == 'EDIT'"}
<tr>
    <td align='center'>&nbsp;</td>
    <td align='center'></td>
    <td align='center'></td>
    <td align='center'></td>
    <td align='center'>&nbsp;</td>
    <td align='center'>&nbsp;</td>
    <td align='center'></td>
    <td align='center'><div id="demo"><a href="#" onclick="submit_wtype_sub('edit',{$edit_id},'add_line_x');"><img src="assets/endpointman/images/add.png" alt="Add Line" border="0" width="24" height="24" title="Add a Line to the device currently being edited"></a></div></td>
    <td align='center'></td>
</tr> 
{else}
<tr>
    <td align='center'>&nbsp;</td>
    <td align='center'></td>
    <td align='center'></td>
    <td align='center'></td>
    <td align='center'>&nbsp;</td>
    <td align='center'>&nbsp;</td>
    <td align='center'></td>
    <td align='center'><a href="#" onclick="add_line();"><img src="assets/endpointman/images/add.png" alt="Add Line" border="0" width="24" height="24"></a></td>
    <td align='center'></td>
</tr>
{/if}
{/if}
</table>
</form>

{if condition="$searched == 1"}
<table width='90%' align='center'>
    <tr>
        <td align='center'>&nbsp;</td>
        <td align='center'>&nbsp;</td>
        <td align='center'>&nbsp;</td>
        <td colspan="3" align='center'><h3><?php echo _('Unmanaged Extensions')?></h3></td>
        <td align='center'>&nbsp;</td>
        <td align='center'>&nbsp;</td>
        <td align='center'>&nbsp;</td>
    </tr>
	{if condition="is_array($unmanaged)"}
    <form id="unmanaged" action='' method='POST'>
		{loop name="unmanaged"}
        <input name="mac_{$value.id}" type="hidden" value="{$value.mac_strip}">
        <input name="brand_{$value.id}" type="hidden" value="{$value.brand_id}">
        <tr>
            <td align='center' width='20'><input type="checkbox" name="add[]" value="{$value.id}"></td>
            <td align='center' width='148'>{$value.mac_strip}<br />({$value.ip})</td>
            <td width="188" align='center'>{$value.brand}</td>
            <td width="216" align='center'>

                <select name="model_list_{$value.id}">

	    {loop name="value.list"}

                    <option value="{$value.id}">{$value.model}</option>

	      {/loop}

                </select></td>
            <td width="141" align='center'>

            </td>

            <td width="276" align='center'>
                <select name="ext_list_{$value.id}" id="ext">

	    {loop name="display_ext"}

                    <option value="{$value.value}">{$value.text}</option>

	      {/loop}

                </select></td>
            <td align='center' width='220'>&nbsp;</td>
            <td align='center' width='154'></td>
            <td align='center' width='73'>&nbsp;</td>
        </tr>
		{/loop}
        <tr>
        <table width="90%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td><center><input type="submit" name="button_add_selected_phones" onclick="submit_unmanaged();" value="<?php echo _('Add Selected Phones')?>"><br /><input type="checkbox" name="reboot_sel">Reboot Phones</center></td>
            </tr>
        </table>
        </tr>
    </form>
	{/if}
</table>
{/if}

<table width='90%' align='center' id='devList'>
    <tr class="headerRow">
        <td width="3%" align='center'>&nbsp;</td>
        <td align='center'>&nbsp;</td>
        <td align='center'>&nbsp;</td>
        <td colspan="3" style='vertical-align:text-bottom;text-align:center;'><h3><?php echo _('Current Managed Extensions')?></h3></td>
        <td align='center'>&nbsp;</td>
        <td align='center'></td>
        <td align='center'></td>
    </tr>
    <tr>
        <td colspan="7" id="expander"><a onclick="toggleDisplayAll('expand')"><img src="assets/endpointman/images/expand.png" id="toggle_all_img" title="Click to Expand All Line Information">Expand All Line Info</a></td>
    </tr>
    <tr class="headerRow">
        <td width="3%" align='center'>&nbsp;</td>
        <td align='center'><h3>Mac Address</h3></td>
        <td align='center'><h3>Brand</h3></td>
        <td align='center'><h3>Model of Phone</h3></td>
        <td align='center'><h3>Line</h3></td>
        <td align='center'><h3>Extension Number</h3></td>
        <td align='center'><h3>Template</h3></td>
        <!--<td align='center'><h3>Specific</h3></td>-->
        <td align='center'><h3>Edit</h3></td>
        <td align='center'><h3>Delete</h3></td>
    </tr>
    <form id="managed" action='config.php?type=tool&amp;display=epm_devices' method='POST'>
	{loop name="list"}
        <tr class="headerRow">
            <td align='center' width="5%"><div id="demo"><img src="assets/endpointman/images/circle_{if condition="$value.status.status === TRUE"}green{else}red{/if}.png" alt="{$value.status.ip}:{$value.status.port}"><input type="checkbox" name="selected[]" value="{$value.id}"></div></td>
            <td align='center' width='11%'>{$value.mac}</td>
            <td width="13%" align='center'>{$value.name}</td>
            <td width="14%" align='center'>{$value.model}</td>
            <td width="10%" align='center'><div id="demo"><a><img src="assets/endpointman/images/expand.png" id="img2rowGroup{$value.master_id}" onclick="toggleDisplay(document.getElementById('devList'),'rowGroup{$value.master_id}')" title="Click to Expand Line Information"></a></div></td>
            <td width="19%" align='center'><div id="demo"><a><img src="assets/endpointman/images/expand.png" id="img3rowGroup{$value.master_id}" onclick="toggleDisplay(document.getElementById('devList'),'rowGroup{$value.master_id}')" title="Click to Expand Line Information"></a></div></td>
            <td align='center' width='15%'>{$value.template_name}</td>
            <!--<td align='center'><div id="demo"><a href="#" onclick="submit_stype('edit',{$value.id});"><img src='assets/endpointman/images/edit.png' ALT='<?php echo _('Edit')?>' title='Edit Device' border='0'></a></div></td>-->
            <td align='center' width='9%'><div id="demo"><a href="#" onclick="submit_wtype('edit',{$value.id});"><img src='assets/endpointman/images/edit.png' ALT='<?php echo _('Edit')?>' title='Edit Device' border='0'></a></div></td>
            <td align='center' width='7%'><div id="demo"><a href="#" onclick="delete_device({$value.id});"><img src='assets/endpointman/images/delete.png' ALT='<?php echo _('Delete')?>' title='Delete Device' border='0'></a></div></td>
        </tr>
        {loop name="value.line"}
        <tr class="rowGroup{$value.master_id} toggle_all" id="{$value.master_id}" style="display:none;">
            <td align='center' ></td>
            <td align='center' width='11%'></td>
            <td width="13%" align='center'></td>
            <td width="14%" align='center'></td>
            <td width="10%" align='center'>{$value.line}</td>
            <td width="19%" align='center'>{$value.ext} - {$value.description}</td>
            <td align='center' width='15%'></td>
            <td align='center' width='9%'></td>
            <td></td>
            <td align='center' width='7%'><div id="demo"><a href="#" onclick="submit_wtype('delete_line',{$value.luid});"><img src='assets/endpointman/images/delete.png' ALT='<?php echo _('Delete')?>' title='Delete Line' border='0'></a></div></td>
        </tr>
        {/loop}
	{/loop}
</table>

<hr>
<center>
    <h4>
        <?php echo _('Selected Phone(s) Options')?>
    </h4>
</center>
<table width='90%' align='center'>
    <tr>
        <td width="26%" align='center'><input type="submit" name="button_delete_selected_phones" onclick="submit_managed('delete_selected_phones');" value="<?php echo ('Delete Selected Phones')?>"></td>
        <td width="26%" align='center'><input type="submit" name="button_rebuild_selected" onclick="submit_managed('rebuild_selected_phones');" value="<?php echo _('Rebuild Configs for Selected Phones')?>"><br /><input type="checkbox" name="reboot">Reboot Phones</td>
        <td width="32%" align='center'><?php echo _('Change Selected Phones to')?>: <br /><?php echo _('Brand')?>:<select name="brand_list_selected" id="brand_list_selected">
                {loop name="brand_ava"}
                <option value="{$value.value}" {if condition="isset($value.selected)"}selected{/if}>{$value.text}</option>
                {/loop}
            </select> <?php echo _('Model')?>: <select name="model_list_selected" id="model_list_selected"><option></option></select><br /><input type="submit" name="button_update_phones" onclick="submit_managed('change_brand');" value="<?php echo _('Update Phones')?>"><br /><input type="checkbox" name="reboot_change">Reboot Phones</td>
    </tr>
</table>
</form>
<hr>
<center>
    <h4><?php echo _('Global Phone Options')?></h4>
</center>
<table width='90%' align='center'>
    <tr>
        <td align='center'>
            <form action='' name='globalmanaged' id='globalmanaged' method='POST'>
                <input type='Submit' name='button_rebuild_configs_for_all_phones' onclick="submit_global('rebuild_configs_for_all_phones');" value='<?php echo _('Rebuild Configs for All Phones')?>'>
                       <br />
                <input type="checkbox" name="reboot">Reboot Phones
            </form>
        </td>
        <td align='center'>
                <form action='' name='globalmanaged2' id='globalmanaged2' method='POST'><select name="rb_brand">
                {loop name="brand_ava"}
                            <option value="{$value.value}">{$value.text}</option>
                {/loop}
                </select><br/>
                <input type='Submit' name='button_reboot_this_brand' onclick="submit_global2('reboot_brand');" value='<?php echo _('Reboot This Brand')?>'></form>
        </td>
        <td align='center'>
            <form action='' name='globalmanaged3' id='globalmanaged3' method='POST'><?php echo _('Reconfigure all')?> (products)<br/> <select name="product_select" id="product_select">
            {loop name="product_list"}
                        <option value="{$value.value}">{$value.text}</option>
            {/loop}
                    </select><br/> <?php echo _('with')?>
                    <label>
                        <select name="template_selector" id="template_selector">
                            <option></option>
                        </select>
                        <input type="submit" name="button_rebuild_reboot" onclick="submit_global3('rebuild_reboot');" value="<?php echo _('Rebuild')?>"><br /><input type="checkbox" name="reboot">Reboot Phones
                    </label>
            </td>
        <td align='center'>
            <form action='' name='globalmanaged4' id='globalmanaged4' method='POST'><?php echo _('Reconfigure all')?> (models)<br/> <select name="model_select" id="model_select">
            {loop name="model_list"}
                        <option value="{$value.value}">{$value.text}</option>
            {/loop}
                    </select><br/> <?php echo _('with')?>
                    <label>
                        <select name="model_template_selector" id="model_template_selector">
                            <option></option>
                        </select>
                        <input type="submit" name="button_rebuild_reboot" onclick="submit_global3('mrebuild_reboot');" value="<?php echo _('Rebuild')?>"><br /><input type="checkbox" name="reboot">Reboot Phones
                    </label>
            </td>
            
    </tr>
</table>
</form>

{if condition="!isset($disable_help)"}
<script>
    $("#demo img[title]").tooltip();
</script>
{/if}
{include="global_footer"}