<?php

// users & clienttypes & servers - right selectboxes
$clienttypes_assoc = array();
$users_assoc = array();
$user_status_assoc = array();
$servers_assoc = array();

foreach ($clienttypes as $id_clienttype) {
    if (array_key_exists($id_clienttype, $allClienttypes)) {
        $clienttypes_assoc[$id_clienttype] = $allClienttypes[$id_clienttype];
    }
}
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];
    }
}
foreach ($servers as $id_server) {
    if (array_key_exists($id_server, $allServers)) {
        $servers_assoc[$id_server] = $allServers[$id_server];
    }
}

asort($clienttypes_assoc);
asort($users_assoc);
asort($user_status_assoc);
asort($servers_assoc);

?>
<tr id="permission1" class="primarycolor">
    <td><?php echo lang('Visible to everyone'); ?>:</td>
    <td>
        <input type="checkbox" name="visible" value="1" <?php if ($visible) echo 'checked="checked"'; ?>>
    </td>
</tr>
<tr id="permission2" class="secondarycolor">
    <td><?php echo lang('Visible to client types'); ?>:<br>
        <?php echo ReturnPopUpString(lang('Client types will be automatically inherited from upper categories. You can add more of them by using these select boxes.')); ?></td>
    <td>
        <table>
        <tr>
            <td>
                <select id="clienttypes1" multiple="multiple" size="10" style="width: 150px;"><?php echo Template::htmlOptions($allClienttypes); ?></select>
            </td>
            <td valign="top"><input type="button" class="button_small" value="<?php echo lang('Add'); ?>" onclick="selectboxAdd('clienttypes1', 'clienttypes2');this.blur();"></td>
            <td>
                <select name="clienttypes[]" id="clienttypes2" multiple="multiple" size="10" style="width: 150px;"><?php echo Template::htmlOptions($clienttypes_assoc); ?></select>
            </td>
            <td valign="top"><input type="button" class="button_medium" value="<?php echo lang('Delete'); ?>" onclick="selectboxRemove('clienttypes2');this.blur();"></td>
        </tr>
        </table>
    </td>
</tr>
<tr id="permission3" class="primarycolor">
    <td><?php echo lang('Visible to users'); ?>:<br>
        <?php echo ReturnPopUpString(lang('Users will be automatically inherited from upper categories. You can add more of them by using these select boxes.')); ?></td>
    <td>
        <table>
        <tr>
            <td>
                <select id="users1" multiple="multiple" size="10" style="width: 150px;"><?php echo Template::htmlOptions($allUsers); ?></select>
            </td>
            <td valign="top"><input type="button" class="button_small" value="<?php echo lang('Add'); ?>" onclick="selectboxAdd('users1', 'users2');this.blur();"></td>
            <td>
                <select name="users[]" id="users2" multiple="multiple" size="10" style="width: 150px;"><?php echo Template::htmlOptions($users_assoc); ?></select>
            </td>
            <td valign="top"><input type="button" class="button_medium" value="<?php echo lang('Delete'); ?>" onclick="selectboxRemove('users2');this.blur();"></td>
        </tr>
        </table>
    </td>
</tr>
<?php if (!isset($editingCategory) || !$editingCategory): ?>
<tr id="permission4" class="secondarycolor">
    <td><?php echo lang('Restrict by user status'); ?>:<br>
        <?php echo ReturnPopUpString(lang('If none selected there is no restriction depending on status, if selected, then only users with selected status will have access')); ?></td>
    <td>
        <table>
        <tr>
            <td>
                <select id="user_status1" multiple="multiple" size="5" style="width: 150px;"><?php echo Template::htmlOptions(getAllUserStatus()); ?></select>
            </td>
            <td valign="top"><input type="button" class="button_small" value="<?php echo 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 Template::htmlOptions($user_status_assoc); ?></select>
            </td>
            <td valign="top"><input type="button" class="button_medium" value="<?php echo lang('Delete'); ?>" onclick="selectboxRemove('user_status2');this.blur();"></td>
        </tr>
        </table>
    </td>
</tr>
<?php endif; ?>
<tr id="permission5" class="primarycolor">
    <td><?php echo lang('Visible to servers'); ?>:<br>
        <?php echo ReturnPopUpString(lang('Servers will be automatically inherited from upper categories. You can add more of them by using these select boxes.')); ?></td>
    <td>
        <table>
        <tr>
            <td>
                <select id="servers1" multiple="multiple" size="10" style="width: 150px;"><?php echo Template::htmlOptions($allServers); ?></select>
            </td>
            <td valign="top"><input type="button" class="button_small" value="<?php echo lang('Add'); ?>" onclick="selectboxAdd('servers1', 'servers2');this.blur();"></td>
            <td>
                <select name="servers[]" id="servers2" multiple="multiple" size="10" style="width: 150px;"><?php echo Template::htmlOptions($servers_assoc); ?></select>
            </td>
            <td valign="top"><input type="button" class="button_medium" value="<?php echo lang('Delete'); ?>" onclick="selectboxRemove('servers2');this.blur();"></td>
        </tr>
        </table>
    </td>
</tr>
