<? global $vis_language; ?>
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title"><? echo $vis_language['TXTITILATTACHRELATIONSHIP']; ?></h4>
        </div>
        <div class="modal-body">
            <? if($relationship_details!=-1){?>
            <div class="row" id="relationships_list">
                <div class="col-sm-12">
                 <table class="table b-t b-light m-b-none" id="table_relation">
                      <thead class="table_head">
                          <tr>
                              <th><?= $vis_language['TXTITILRELATIONSHIP']; ?></th>
                              <th><?= $vis_language['TXTITILINVERSERELATIONSHIP']; ?></th>
                          </tr>
                      </thead>
                      <tbody>
                  	  <? for($i=0;$i<count($relationship_details);$i++){ ?>                       
							 <tr>
                                 <td><a href="javascript:void(0);" onclick="get_ci_attach(<?= $relationship_details[$i]['relation_id'];?>,'0');"><?= ucfirst($relationship_details[$i]['forward']);?></a></td>
                             <!--</tr>
                             <tr>-->
                                 <td><a href="javascript:void(0);" onclick="get_ci_attach(<?= $relationship_details[$i]['relation_id'];?>,'1');"><?= ucfirst($relationship_details[$i]['inverse']);?></a></td>
                             </tr>
                      <? }?>
                      </tbody>
                  </table>
                  <script type="application/javascript">$(document).ready(function() {$("#table_relation").dataTable({ "sScrollY":  ( 0.6 * $(window).height() ),"bPaginate": false, "bJQueryUI": true, "bScrollCollapse": true, "bAutoWidth": "100%", "scrollX": true, "sScrollXInner": "100%","bFilter": false,"bInfo": false,"ordering": false});});</script> 
              </div>
            </div>
            <div class="row" id="vis_attach_ci">
            </div>
            <? }else{
                 include(VIS_PATH_TEMPLATE.'no_record_yet.php');
               }?>
        </div>
        <div class="modal-footer" id="button_list" style="display:none;">
			<a class="btn btn-default" data-dismiss="modal"><? echo $vis_language['TXTCANCEL']; ?></a>
            <a class="btn btn-default" onclick="show_relation_list();"><? echo $vis_language['TXTBACK']; ?></a>
            <a class="btn btn-primary" onclick="$(this).visExecution('submit_form',{'vis_module':'cmdb', 'vis_operation':'attach_new_relationships', 'vis_form':'vis_relationships_form'});"><? echo $vis_language['TXTATTACH']; ?></a>
        </div>
    </div>
</div>
<script>
function get_ci_attach(relation_id,relation_type){
		$('#vis_attach_ci').show();
		$('#vis_attach_ci').visExecution('load_operations',{'vis_module':'cmdb', 'vis_operation':'get_cmdb_relation_ci', 'vis_action':'details',  'vis_assets_id':'<? echo $operation['vis_assets_id']; ?>','vis_relation_id':''+relation_id+'','vis_relation_type':''+relation_type+''});
		$('#relationships_list').hide();
		$('#button_list').show();
}
function show_relation_list(){
		$('#relationships_list').show();
		$('#button_list').hide();
		$('#vis_attach_ci').hide();

}
</script>
