<?php

// users & clienttypes & servers - right selectboxes
$clienttypes_assoc = array();
$users_assoc = array();
$user_status_assoc = array();
$servers_assoc = array();
$company = NE_Registry::getCompany();
if ($company->supports('products')) {
    foreach ($clienttypes as $id_clienttype) {
        if (array_key_exists($id_clienttype, $allClienttypes)) {
            $clienttypes_assoc[$id_clienttype] = $allClienttypes[$id_clienttype];
        }
    }
    asort($clienttypes_assoc);    
}    
foreach ($users as $id_user) {
    if (array_key_exists($id_user, $allUsers)) {
        $users_assoc[$id_user] = $allUsers[$id_user];
    }
}

foreach ($user_status as $v) {
    if (array_key_exists($v, $allUserStatus)) {
        $user_status_assoc[$v] = $allUserStatus[$v];
    }
}
if ($company->supports('products')) {
    foreach ($servers as $id_server) {
        if (array_key_exists($id_server, $allServers)) {
            $servers_assoc[$id_server] = $allServers[$id_server];
        }
    }
    asort($servers_assoc);    
}
asort($users_assoc);
asort($user_status_assoc);


?>
<tr>
    <td>
        <table>
            <tr id="permission1" class="primarycolor">
                <td><?php echo $this->lang('Visible to all logged-in users'); ?>:</td>
                <td>
                    <input type="checkbox" name="visible" value="1" <?php if ($visible) echo 'checked="checked"'; ?>>
                </td>
            </tr>
        </table>
    </td>
    <td>
        <table>
            <tr id="permission2" class="primarycolor">
                <td><?php echo $this->lang('Visible to guests in public section'); ?>:</td>
                <td>
                    <input type="checkbox" name="public" value="1" <?php if ($public) echo 'checked="checked"'; ?>>
                </td>
            </tr>
        </table>
    </td>
</tr>
<?php if ($company->supports('products')) { ?>
    <tr id="permission3" class="secondarycolor">
        <td><?php echo $this->lang('Visible to client types'); ?>:<br>
            <?php echo NE_Lib::returnPopUpString($this->lang('Client types will be automatically inherited from upper categories. You can add more of them by using these select boxes.'), $this->settings); ?></td>
        <td>
            <table>
            <tr>
                <td>
                    <select id="clienttypes1" multiple="multiple" size="10" style="width: 150px;"><?php echo SugoLibTemplate::htmlOptions($allClienttypes); ?></select>
                </td>
                <td valign="top"><input type="button" class="button_small" value="<?php echo $this->lang('Add'); ?>" onclick="selectboxAdd('clienttypes1', 'clienttypes2');this.blur();"></td>
                <td>
                    <select name="clienttypes[]" id="clienttypes2" multiple="multiple" size="10" style="width: 150px;"><?php echo SugoLibTemplate::htmlOptions($clienttypes_assoc); ?></select>
                </td>
                <td valign="top"><input type="button" class="button_medium" value="<?php echo $this->lang('Delete'); ?>" onclick="selectboxRemove('clienttypes2');this.blur();"></td>
            </tr>
            </table>
        </td>
    </tr>
<?php } ?>
<tr id="permission4" class="primarycolor">
    <td><?php echo $this->lang('Visible to users'); ?>:<br>
        <?php echo NE_Lib::returnPopUpString($this->lang('Users will be automatically inherited from upper categories. You can add more of them by using these select boxes.'), $this->settings); ?></td>
    <td>
        <table>
        <tr>
            <td>
                <select id="users1" multiple="multiple" size="10" style="width: 150px;"><?php echo SugoLibTemplate::htmlOptions($allUsers); ?></select>
            </td>
            <td valign="top"><input type="button" class="button_small" value="<?php echo $this->lang('Add'); ?>" onclick="selectboxAdd('users1', 'users2');this.blur();"></td>
            <td>
                <select name="users[]" id="users2" multiple="multiple" size="10" style="width: 150px;"><?php echo SugoLibTemplate::htmlOptions($users_assoc); ?></select>
            </td>
            <td valign="top"><input type="button" class="button_medium" value="<?php echo $this->lang('Delete'); ?>" onclick="selectboxRemove('users2');this.blur();"></td>
        </tr>
        </table>
    </td>
</tr>
<tr id="permission5" class="secondarycolor">
    <td><?php echo $this->lang('Restrict by user status'); ?>:<br>
        <?php echo NE_Lib::returnPopUpString($this->lang('If none selected there is no restriction depending on status, if selected, then only users with selected status will have access'), $this->settings); ?></td>
    <td>
        <table>
        <tr>
            <td>
                <select id="user_status1" multiple="multiple" size="5" style="width: 150px;"><?php echo SugoLibTemplate::htmlOptions($this->user->getPossibleStatuses()); ?></select>
            </td>
            <td valign="top"><input type="button" class="button_small" value="<?php echo $this->lang('Add'); ?>" onclick="selectboxAdd('user_status1', 'user_status2');this.blur();"></td>
            <td>
                <select name="user_status[]" id="user_status2" multiple="multiple" size="5" style="width: 150px;"><?php echo SugoLibTemplate::htmlOptions($user_status_assoc); ?></select>
            </td>
            <td valign="top"><input type="button" class="button_medium" value="<?php echo $this->lang('Delete'); ?>" onclick="selectboxRemove('user_status2');this.blur();"></td>
        </tr>
        </table>
    </td>
</tr>
<?php if ($company->supports('products')) { ?>
    <tr id="permission6" class="primarycolor">
        <td><?php echo $this->lang('Visible to servers'); ?>:<br>
            <?php echo NE_Lib::returnPopUpString($this->lang('Servers will be automatically inherited from upper categories. You can add more of them by using these select boxes.'), $this->settings); ?></td>
        <td>
            <table>
            <tr>
                <td>
                    <select id="servers1" multiple="multiple" size="10" style="width: 150px;"><?php echo SugoLibTemplate::htmlOptions($allServers); ?></select>
                </td>
                <td valign="top"><input type="button" class="button_small" value="<?php echo $this->lang('Add'); ?>" onclick="selectboxAdd('servers1', 'servers2');this.blur();"></td>
                <td>
                    <select name="servers[]" id="servers2" multiple="multiple" size="10" style="width: 150px;"><?php echo SugoLibTemplate::htmlOptions($servers_assoc); ?></select>
                </td>
                <td valign="top"><input type="button" class="button_medium" value="<?php echo $this->lang('Delete'); ?>" onclick="selectboxRemove('servers2');this.blur();"></td>
            </tr>
            </table>
        </td>
    </tr>
<?php } ?>
