<div id="users_roles_form">

    <?php echo form_open("auth/manage_role/" . $this->uri->segment(3) . '/' . $this->uri->segment(4), array('id' => strtolower($operation) . '_role', 'class' => 'form-horizontal confirm-before-leave')); ?>
     <div style="padding:0 30px;">

        <div id="formInfoMessage"></div>

        <div class="control-group required">
            <?php
            echo form_label('Role name', $id['id'], array('class' => 'control-label'));
            // edit role - do not allow user to change the name
            if ($op == 'edit')
            {
                $id['readonly'] = 'readonly';
            }
            echo '<div class="controls">'.form_input($id).'</div>';
            ?>
        </div>

         <div class="control-group required">
            <?php
            if ($uneditable) {
                $description['readonly'] = 'readonly';
            }
            echo form_label('Description', $description['name'], array('class' => 'control-label'));
            echo '<div class="controls">'.form_textarea($description).'</div>';
            ?>
        </div>

        <?php

        function get_array_from_string($value)
        {
            if (empty($value))
            {
                return null;
            }

            $value = str_replace(' ', '', $value);
            $arr = explode(',', $value);
            return $arr;
        }

        $partial_data = array();

        $partial_data['html_id']          = 'classes_inc_exc';
        $partial_data['embedded']         = true;
        $partial_data['doNotShowButtons'] = true;
        $partial_data['required']         = true;

        $partial_data['css_class']        = "input-cfexxlarge";

        $partial_data['fields']['left']['name'] = 'crxi';

        if (!empty($crxi['value']))
        {
            $partial_data['fields']['left']['values'] = get_array_from_string($crxi['value']);
        }


        $partial_data['fields']['right']['name'] = 'crxx';

        if (!empty($crxx['value']))
        {
            $partial_data['fields']['right']['values'] = get_array_from_string($crxx['value']);
        }
        ?>
        <br />
         <?php if (!$uneditable) { ?>
        <h4>Classes</h4>
        <div id="classes_inc_exc">
        <?php $this->load->view('widgets/contextfinder', $partial_data); ?>
        </div>
             <script>
                 document.getElementById('super_role_btn').removeAttribute('disabled')
             </script>
         <?php } else { ?>
             <script>
                 document.getElementById('super_role_btn').setAttribute('disabled', 'disabled')
             </script>
         <?php } ?>
        <?php
        $displayText = $operation;
        if ($operation == 'edit')
        {
            $displayText = "Update";
        }
        ?>
        <br />
        </div>


        <button style="display:none" type="submit" class="btn btn-large btn-primary role_btn" id="<?php echo strtolower($operation) . '_role_btn' ?>">
            Save
        </button>


        <?php echo form_close(); ?>

</div>

<script>
    processPageBeforeLeave();
</script>
