var type_view = 0;
function open_member()
{
    var txt = "select * from `cata` where `active_cata` = '0'";
    $('.form-control').val('');
    get_select_cata(txt,"id_cata_memebr");
    $('#modal_member').modal('show');
}
function member()
{
 	var txt = `<div class="row">
				<button style="font-size:25px;background-color:#fff;border-radius:50%" type="button" class="btn btn-outline-success btn-floating waves-effect waves-light btn-large" onclick="open_member()" >
				 +  
				</button>
				  <table id="Table1" class="mdl-data-table dataTable" cellspacing="0" width="100%">
				   <thead style="">
						  <tr>
							  <th>م</th>
							  <th>اسم الاشتراك</th>
							  <th>طريقة الحضور</th>
							  <th>المبلغ</th>
							  <th></th>
						  </tr>
					  </thead>
						<tbody>

						</tbody>
				  </table>
			   </div>`;
    $('#pg_body').html(txt);
    
    var dataTable = $('#Table1').DataTable( {
                columnDefs: [
        {
            targets: [ 0, 1, 2 ],
            className: 'mdl-data-table__cell--non-numeric'
    }],
        "processing": true,
        "serverSide": true,
        "ajax":{
            url :"model/class/member.php",
            type: "post",  
            dataType:"JSON",
            error: function(){
                
            }
        }
    } );
	$('#Table1').DataTable();
	get_page();
}
function radio_btn(s)
{
	if(s == 0)
	{
		type_view = 0;
		$('#count_div').show(1000);
		$('#date_div').hide(1000);
		$('#price_div').show(1000);
	}
	if(s == 1)
	{
		type_view = 1;
		$('#count_div').hide(1000);
		$('#date_div').show(1000);
		$('#price_div').show(1000);		
	}
	if(s == 2)
	{
		type_view = 2;
		$('#count_div').show(1000);
		$('#date_div').show(1000);
		$('#price_div').show(1000);		
	}
	if(s == 3)
	{
		type_view = 0;
		$('#count_div').show(1000);
		$('#date_div').hide(1000);
		$('#price_div').show(1000);
	}
	if(s == 4)
	{
		type_view = 1;
		$('#count_div').hide(1000);
		$('#date_div').show(1000);
		$('#price_div').show(1000);		
	}
	if(s == 5)
	{
		type_view = 2;
		$('#count_div').show(1000);
		$('#date_div').show(1000);
		$('#price_div').show(1000);		
	}
}
function get_member(id)
{
    id_type_page = id;
    get_select_cata("select * from `cata` where `active_cata` = '0'","id_cata_memebr");
    var txt = "select * from `member` where `id_member` = '"+id+"' ";
	$.ajax({
		url:"model/class/class.php",
		type:"POST",
		dataType:"JSON",
        data:{txt:txt,type:1},
        async:false,
		success:function(data)
		{
			$('#name_member').val(data[0].name_member);
			$('#price_member').val(data[0].price_game);
			if(data[0].type_member == 0)
			{
				$('#count_member').val(data[0].count_game);
				$('#r1').prop("checked",true);
				radio_btn(3);
			}
			if(data[0].type_member == 1)
			{
				$('#date_member').val(data[0].date_game);
				radio_btn(4);
				$('#r2').prop("checked",true);
			}
			if(data[0].type_member == 2)
			{
				$('#date_member').val(data[0].date_game);
				$('#count_member').val(data[0].count_game);
				radio_btn(5);
				$('#r3').prop("checked",true);
            }
            push_option(data[0].id_cata,"id_cata_memebr","modal_member")
            
            
        }
	});
}

function save_member()
{
    var price_member = $('#price_member').val();
    var name = $('#name_member').val();
    var id_cata = $('#id_cata_memebr').val();
    if(type_view == 0)
    {
        var count_member = $('#count_member').val();
        var date_member = "d";
    }
    if(type_view == 1)
    {
        var count_member = "";
        var date_member = $('#date_member').val();
    }
    if(type_view == 2)
    {
        var count_member = $('#count_member').val();
        var date_member = $('#date_member').val();
    }
    if(id_type_page == 0)
    {
        var txt = "INSERT INTO `member`(`name_member`, `type_member`, `count_game`, `price_game`, `date_game`,`id_cata`)VALUES('"+name+"','"+type_view+"','"+count_member+"','"+price_member+"','"+date_member+"','"+id_cata+"')";
    }else{
        var txt = "UPDATE `member` SET `name_member`='"+name+"',`type_member`='"+type_view+"',`count_game`='"+count_member+"',`price_game`='"+price_member+"',`date_game`='"+date_member+"',`id_cata` = '"+id_cata+"' WHERE `id_member`='"+id_type_page+"'";
    }
	$.ajax({
		url:"model/class/class.php",
		type:"POST",
		dataType:"JSON",
		data:{type:0,txt:txt},
		success:function()
		{
			success();
		}
	});
}