<div class="table-responsive">
    <table class="table table-hover table-bordered personal-task" id="edit_user_details">
        <tr>
            <th></th>
            <th>Portal</th>
            <th>User Group</th>
        </tr>
        <?php
        $sql_query = "Select * from blskymine_nia_hr_main.erp_mas_portal where auth_needed='Y' ORDER BY portal_name asc";
        $model_mas_portal = Yii::app()->db->createCommand($sql_query)->queryAll();
        if (!empty($model_mas_portal)) {
            foreach ($model_mas_portal as $i => $each) {
                $checked = $id = '';
                $model_user_group_id='';
                if ($model['hr_connected_employee_id'] > 0) {
                    $SQL = "SELECT mas_portal_id,user_group_id,id, isActive FROM blskymine_nia_hr_main.view_user_details  WHERE hr_connected_employee_id='" . $model['hr_connected_employee_id'] . "' AND username ='" . $model['username'] . "' AND mas_portal_id='" . $each['id'] . "'";
                    $data_sql = Yii::app()->db->createCommand($SQL)->queryRow();
                    if (!empty($data_sql)) {
                        $model_user_group_id = $data_sql['user_group_id'];
                        if ($data_sql['isActive'] == "N") {
                            $checked = '';
                        } else {
                            $checked = 'checked';
                        }
                        $id = $data_sql['id'];
                    }
                }
                ?>
                <tr>
                    <td><input type="checkbox" name="arraycid[]" <?php echo $checked ?> value="<?php echo $each['id']; ?>">
                    </td>
                    <td>
                        <?php echo CHtml::HiddenField('MasUser[' . $i . '][id]', $id); ?>
                        <?php echo CHtml::HiddenField('MasUser[' . $i . '][portal_id]', $each['id']); ?>
                        <?php echo CHtml::HiddenField('MasUser[' . $i . '][data_base_name]', $each['database_name']); ?>
                        <?php echo CHtml::HiddenField('MasUser[' . $i . '][user_table_name]', $each['user_table_name']); ?>
                        <?php echo CHtml::HiddenField('MasUser[' . $i . '][portal_name]', $each['portal_name']); ?>
                        <?php echo $each['portal_name']; ?>
                    </td>
                    <?php
                    $sql_query_usergrp = "Select * from " . $each['user_group_database_name'] . "." . $each['user_group_table_name'] . " where isActive='Y' and id>1";
                    $model_usergrp = Yii::app()->db->createCommand($sql_query_usergrp)->queryAll();
                    $m = 0;
                    $usergrp_details = [];
                    foreach ($model_usergrp as $k => $id) {
                        $usergrp_details[$m]['id'] = $id['id'];
                        $usergrp_details[$m]['group_name'] = $id['group_name'];
                        $m++;
                    }
                    ?>
                    <td>

                        <?php echo CHtml::dropdownlist('MasUser[' . $i . '][user_group_id]', $model_user_group_id, CHtml::listData($usergrp_details, 'id', 'group_name'), array('class' => 'form-control', 'empty' => 'Select')); ?>
                    </td>

                </tr>
                <?php
            }
        }
        ?>
    </table>
</div>
