<?php
$total_selected = 0;
if(isset($data['list']) && !empty($data['list'])){
    foreach($data['list'] as $pkey1 => $pl1){
        foreach($pl1 as $pkey2 => $pl2){
            if(in_array($pkey2, $data['selected'])){
                $total_selected++;
            }
        }
    }
}  
$is_member_checked = false;
$client_assignment_member_id = $data['member_id'];
if($client_assignment_member_id > 0){
    $total_selected++;
    $is_member_checked = true;
}

if($data['is_own_client_checked']){
    $total_selected++;
}

if($this->request->params['action'] == 'clientonboarding'){
    $total_selected = 0;
}

?>
<span class="multiselect-native-select">
    
    <div class="btn-group" style="width: 160px;">
            <button type="button" class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" title="Assign To" style="width: 235px; overflow: hidden; text-overflow: ellipsis;" aria-expanded="true">
                <span class="multiselect-selected-text selected-text-<?php echo $data['client_id'];?>"><?php echo $total_selected > 0 ? $total_selected:'No';?> selected</span> 
                <b class="caret"></b>
            </button> 
<!--        is_own_client_disabled-->
        <ul class="multiselect-container dropdown-menu">
            <?php if(isset($data['list']) && !empty($data['list'])){ ?>
                <?php foreach($data['list'] as $key1 => $l1){ ?>
                    <li class="multiselect-item multiselect-group">
                        <a href="javascript:void(0);">
                            <label style="padding:3px 20px 3px 20px"><b> <?php echo $key1; ?></b></label>
                        </a>
                    </li>
                    <?php foreach($l1 as $key2 => $l2){ ?>
                    <li class="<?php echo (in_array($key2, $data['selected']) || ($key2 == 0 && $is_member_checked)) && $this->request->params['action'] != 'clientonboarding' ? 'active':'';?>">
                        <a tabindex="0">
                            <label class="checkbox" style="font-weight:400;">
                                <input  name="reference_ids[]" type="checkbox" class="<?php echo $data['class'][$key1];?> <?php echo $data['class'][$key1];?>" onclick="assignMultipleClient(this,'<?php echo $data['client_id'];?>','<?php echo $data['client_name'];?>','<?php echo $data['class'][$key1];?>')" <?php echo (in_array($key2, $data['selected']) || ($key2 == 0 && $is_member_checked)) && $this->request->params['action'] != 'clientonboarding' ? 'checked':'';?> value="<?php echo $key2;?>"/>
                                <?php echo $l2; ?>
                            </label>
                        </a>
                    </li>
                    <?php } ?>
                <?php } ?>
            <?php } ?>
        </ul>
    </div>
</span>