<header>
    <nav class="navbar navbar-default navbar-static-top" role="navigation">
        <ul class="nav navbar-nav">
            <li><a href="/count_form.php/?p=admin">Услуги</a></li>
            <li><a href="/count_form.php/?p=sub_quest">Вопросы</a></li>
            <li><a href="http://seo.artweb.ua/count_form.php/">Выйти</a></li>
        </ul>
    </nav>
</header>
<h1>Обновить услугу</h1>
<form id = "send-form" data-url="" action="" method="post">
    <div class="input-group">
        <span class="input-group-addon title-block-sizing">Услуга</span>
        <input type="text" data-reg="name" data-оbligatory="true" class="form-control input-sizing validate-input"  value="<?= isset($data['question']['text'])&&!empty($data['question']['text']) ? $data['question']['text'] : '' ?>" name="question_text">
    </div>

    <p>
        <label for="status">Инпут выбора</label>
        <select id="status" name="question_input_type">
            <option value="checkbox" <?= isset($data['question']['input_type'])&&!empty($data['question']['input_type'])&& $data['question']['input_type'] == 'checkbox' ? 'selected' : '' ?> >checkbox</option>
            <option value="radio" <?= isset($data['question']['input_type'])&&!empty($data['question']['input_type'])&& $data['question']['input_type'] == 'radio' ? 'selected' : '' ?>  >radio</option>
        </select>
    </p>

    <div class="input-group">
        <span class="input-group-addon title-block-sizing">Вес</span>
        <input type="text" data-reg="" data-оbligatory="true" class="form-control input-sizing validate-input" value="<?= isset($data['question']['weight'])&&!empty($data['question']['weight']) ? $data['question']['weight'] : '' ?>" name="question_weight">
    </div>

    <div class="input-group">
        <label><input type="checkbox" <?= isset($data['question']['status'])&&!empty($data['question']['status']) ? 'checked' : '' ?> data-оbligatory="true" value="1" name="question_status">Опубликован</label>
    </div>

    <div class="input-group">
        <label><input type="checkbox"  <?= isset($data['question']['required'])&&!empty($data['question']['required']) ? 'checked' : '' ?> data-оbligatory="true"   value="1" name="question_required">Активный</label>
    </div>

    <h2>Родительская услуга</h2>
    <div id="roleList">
        <input type="radio"  <?= isset($data['question']['parent_id'])&&!empty($data['question']['parent_id'])&& $data['question']['parent_id'] ==  '0'? 'checked' : '' ?>  class="main-role" name="question_parent_id" value="0" checked>Нет
        <?php
        function showRole($array,$data,$key){
        $num=count($array);
        for($i=0; $i<$num; $i++){
        if($array[$i]['parent_id']==$key){
        if($key == 0){?>
            <div><ul><li><label><input type="radio" class="main-role"  <?= isset($data['parent_id'])&&!empty($data['parent_id'])&& $array[$i]['id'] == $data['parent_id'] ? 'checked' : '' ?> name="question_parent_id" value="<?=$array[$i]['id']?>"><?=$array[$i]['text']?></label>
                        <?php
                        $key=$array[$i]['id'];
                        showRole($array,$data,$key);
                        $key = $array[$i]['parent_id'];
                        ?>
                    </li>
                </ul>
            </div>
        <?php } else { ?>
        <ul >
            <li><label><input type="radio"  <?= isset($data['question']['parent_id'])&&!empty($data['parent_id'])&& $array[$i]['id'] == $data['parent_id'] ? 'checked' : '' ?> name="question_parent_id" value="<?=$array[$i]['id']?>"><?=$array[$i]['text']?></label>
                <?php
                $key=$array[$i]['id'];
                showRole($array,$data,$key);
                $key = $array[$i]['parent_id'];
                echo "</li>";
                echo "</ul>";
                }
                }
                }
                }
                $key=0;
                showRole($data['data'],$data['question'], $key);?>
    </div>

    <p>
        <input type="submit" id="send-button" class="button_style" value="Сохранить">
    </p>
</form>
<script src="/count_form/js/validate.js"></script>