function load_admin_tab (link,tab){ var statusElem = document.getElementById(tab) ; $.ajax({ url: link, // указываем URL и beforeSend: function( xhr ) { statusElem.innerHTML="Please, wait..."; }, success: function (data, textStatus) { // вешаем свой обработчик на функцию success statusElem.innerHTML=data; } }); } function show_admin(admin_type){ $.ajax({ url: "TAB_administration.php", async:false, data: { action: "show_admin_by_type", admin_type: admin_type }, type:'post', success: function (data, textStatus) { $("#admin_tab").html(data); initialize_admin_datatables(admin_type); } }); } $.widget( "ui.autocomplete", $.ui.autocomplete, { options: { renderItem: null, renderMenu: null, resizeMenu:null, }, _renderItem: function( ul, item ) { if ( $.isFunction( this.options.renderItem ) ) return this.options.renderItem( ul, item ); else return this._super( ul, item ); }, _renderMenu: function( ul, items ) { if ( $.isFunction( this.options.renderMenu ) ) { this.options.renderMenu( ul, items ); } this._super( ul, items ); }, _resizeMenu: function(){ this.menu.element.outerWidth( 'auto' ); }, }); function initialize_admin_datatables(table){ if ( $.fn.dataTable.isDataTable( "#"+table+"_table" ) ) { table = $( "#"+table+"_table" ).DataTable(); table.destroy(); } $("#"+table+"_table").dataTable({ "displayLength": -1, "lengthMenu": [[15, 25, 50, -1], [15, 25, 50, "All"]], "searching": true, "ordering": false, "info": false, "autoWidth": true, "columnDefs": [ { "width": "20%", "targets": 1 }, { "width": "10%", "targets": 2 }, { "width": "2%", "targets": 0 }, { "width": "5%", "targets": 4 }, { "width": "5%", "targets": 5 }, { "class": "details-control", "targets": 0 } ], "fnDrawCallback":function(){ tds=$("#"+table+"_table tbody").find('td.details-control').not('td.details-control:last'); tds.off(); tds.bind('click', function () { bind_open_child_admin(table,$(this)); }); }, }); $( "#"+table+"_table" ).DataTable().on( 'order.dt search.dt', function () { $( "#"+table+"_table" ).DataTable().column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) { cell.innerHTML = i+1; } ); } ).draw(); $('.new_feis_city').autocomplete({ minLength: 1, autoFocus: true, source: function( request, response ) { element=this.element; var term = request.term; $.ajax({ url: "../teacher/actions.php", dataType: "json", data: { term: request.term, flag:'get_cities', }, success: function( data ) { response( data ); } }); }, select: function( event, ui ) { $('.new_feis_city').attr('name',ui.item.id); } }); $('.new_feis_date').datepicker({ "dateFormat": "yy-mm-dd" , changeMonth: true, changeYear: true, }); bind_org_surname_autocomplete(table); if (table=='teachers'){ bind_org_school_autocomplete(); } $(".group_select").chosen({ placeholder_text_multiple: "Выберите группы", }) $('.group_select').on('change', function(evt, params) { selectlistid=$(this).attr('id'); if (params.selected!=undefined){ $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "add_to_group", group_id:params.selected, chosen_ids:selectlistid+"#", }, success: function( data ) { console.log(data); } }); } if (params.deselected!=undefined){ $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "remove_from_group", group_id:params.deselected, chosen_ids:selectlistid+"#", }, success: function( data ) { console.log(data); } }); } }); $('#group_select_all').on('change', function(evt, params) { array=$('.teachers_checkbox:checked'); chosen_ids=""; for (i=0;i"); thistd.nextAll().eq(3).html(""); row=thistd.parent(); thistable=row.parents('table').DataTable(); var rowdata=new Array(); rowdata[0]=""; rowdata[1]=""; rowdata[2]=""; rowdata[3]=""; rowdata[4]=""; rowdata[5]=""; rowdata[6]=""; newrow=thistable.row.add(rowdata).draw().nodes().to$(); newrow.children('td:eq(4)').css('text-align','center'); newrow.children('td:eq(5)').css('text-align','center'); bind_org_surname_autocomplete(type); } }); }, }) } function bind_org_school_autocomplete(){ $('.new_teachers_school').autocomplete({ minLength: 2, autoFocus: true, source: function( request, response ) { element=this.element; var term = request.term; $.ajax({ url: "search_schools.php", dataType: "json", data: { term: request.term, }, success: function( data ) { response( data ); } }); }, select: function( event, ui ) { element.attr('id',ui.item.id); }, }) } function save_new_teacher(element){ surname=$(".new_teachers_surname").val(); name=$(".new_teachers_name").val(); email=$(".new_teachers_email").val(); school_id=$(".new_teachers_school").attr('id'); $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "add_new_teacher", surname:surname, name:name, email:email, school_id:school_id, }, success: function( data ) { id=data; thistd=element.parents('tr'); $(".new_teachers_surname").parent().html(surname); $(".new_teachers_name").parent().html(name); $(".new_teachers_email").parent().html(email); $(".new_teachers_school").parent().css('text-align','center'); $(".new_teachers_school").parent().html(""); element.parent().html(""); row=thistd.parent(); thistable=row.parents('table').DataTable(); var rowdata=new Array(); rowdata[0]=""; rowdata[1]=""; rowdata[2]=""; rowdata[3]=""; rowdata[4]=""; rowdata[5]=""; rowdata[6]=""; newrow=thistable.row.add(rowdata).draw().nodes().to$(); newrow.children('td:eq(4)').css('text-align','center'); newrow.children('td:eq(5)').css('text-align','center'); bind_org_surname_autocomplete('teachers'); bind_org_school_autocomplete(); } }); } function delete_orgs(elem,org_id){ if (confirm("Вы уверены?")){ row=elem.parents('tr'); table=row.parents('table').DataTable(); table.row(row).remove().draw(); $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "delete_orgs", id:org_id, }, }); } } function delete_teachers(elem,teacher_id){ if (confirm("Вы уверены?")){ row=elem.parents('tr'); table=row.parents('table').DataTable(); table.row(row).remove().draw(); $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "delete_teachers", id:teacher_id, }, }); } } function add_feis(elem){ row=elem.parents('tr'); table=row.parents('table').DataTable(); feisname=row.children('td:eq(1)'); city=row.children('td:eq(2)'); date=row.children('td:eq(3)'); if ((feisname.children('input').val()!="") && (city.children('input').val()!="") && (date.children('input').val()!="")){ $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "add_feis", name: feisname.children('input').val(), city: city.children('input').attr('name'), date: date.children('input').val(), }, success: function( data ) { if (data!=""){ feisname.html(feisname.children('input').val()); city.html(city.children('input').val()); date.html(date.children('input').val()); elem.attr('value',"Править"); elem.off(); elem.on('click', function(event) { edit_feis($(this),data) }); row.children('td:eq(5)').html("'"); var rowdata=new Array(); rowdata[0]=""; rowdata[1]=""; rowdata[2]=""; rowdata[3]=""; rowdata[4]=""; rowdata[5]=""; rowdata[6]=""; newrow=table.row.add(rowdata).draw().nodes().to$(); newrow.children('td:eq(3)').css('text-align','center'); newrow.children('td:eq(4)').css('text-align','center'); newrow.children('td:eq(5)').css('text-align','center'); $('.new_feis_date').datepicker({ "dateFormat": "yy-mm-dd" , changeMonth: true, changeYear: true, }); $('.new_feis_city').autocomplete({ minLength: 1, autoFocus: true, source: function( request, response ) { element=this.element; var term = request.term; $.ajax({ url: "../teacher/actions.php", dataType: "json", data: { term: request.term, flag:'get_cities', }, success: function( data ) { response( data ); } }); }, }); } } }); } } function add_city(elem){ row=elem.parents('tr'); table=row.parents('table').DataTable(); cityname=row.children('td:eq(1)'); if ((cityname.children('input').val()!="")){ $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "add_city", name: cityname.children('input').val(), }, success: function( data ) { if (data!=""){ cityname.html(cityname.children('input').val()); // elem.attr('value',"Править"); // elem.off(); // elem.on('click', function(event) { edit_city($(this),data) }); row.children('td:eq(3)').html(""); row.children('td:eq(4)').html(""); var rowdata=new Array(); rowdata[0]=""; rowdata[1]=""; rowdata[2]=""; rowdata[3]=""; rowdata[4]=""; rowdata[5]=""; newrow=table.row.add(rowdata).draw().nodes().to$(); newrow.children('td:eq(3)').css('text-align','center'); newrow.children('td:eq(4)').css('text-align','center'); } } }); } } function add_country(elem){ row=elem.parents('tr'); table=row.parents('table').DataTable(); countryname=row.children('td:eq(1)'); if ((countryname.children('input').val()!="")){ $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "add_country", name: countryname.children('input').val(), }, success: function( data ) { if (data!=""){ countryname.html(countryname.children('input').val()); // elem.attr('value',"Править"); // elem.off(); // elem.on('click', function(event) { edit_country($(this),data) }); row.children('td:eq(3)').html(""); row.children('td:eq(4)').html(""); var rowdata=new Array(); rowdata[0]=""; rowdata[1]=""; rowdata[2]=""; rowdata[3]=""; rowdata[4]=""; rowdata[5]=""; newrow=table.row.add(rowdata).draw().nodes().to$(); newrow.children('td:eq(3)').css('text-align','center'); newrow.children('td:eq(4)').css('text-align','center'); } } }); } } function add_school(elem){ row=elem.parents('tr'); table=row.parents('table').DataTable(); schoolname=row.children('td:eq(1)'); org=row.children('td:eq(2)'); org_cell=org.html(); if ((schoolname.children('input').val()!="")){ $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "add_school", name: schoolname.children('input').val(), organization_id: org.children('select').val(), }, success: function( data ) { if (data!=""){ schoolname.html(schoolname.children('input').val()); row.children('td:eq(2)').html("0"); row.children('td:eq(2)').css('text-align','left'); row.children('td:eq(4)').html(''); row.children('td:eq(4)').html(""); row.children('td:eq(4)').css('text-align','center'); row.children('td:eq(5)').html(""); row.children('td:eq(5)').css('text-align','center'); var rowdata=new Array(); rowdata[0]=""; rowdata[1]=""; rowdata[2]=org_cell; rowdata[3]=""; rowdata[4]=""; rowdata[5]=""; newrow=table.row.add(rowdata).draw().nodes().to$(); newrow.children('td:eq(2)').css('text-align','left'); newrow.children('td:eq(3)').css('text-align','center'); newrow.children('td:eq(4)').css('text-align','center'); } } }); } } function edit_feis(elem,feis_id){ elem.removeAttr('onclick'); elem.off(); elem.attr('value',"Сохранить"); row=elem.parents('tr'); feisname=row.children('td:eq(1)'); feisname.html(""); city=row.children('td:eq(2)'); city.html("").children('input').autocomplete({ minLength: 1, autoFocus: true, source: function( request, response ) { element=this.element; var term = request.term; $.ajax({ url: "../teacher/actions.php", dataType: "json", data: { term: request.term, flag:'get_cities', }, success: function( data ) { response( data ); } }); }, }); date=row.children('td:eq(3)'); date.html("").children('input').datepicker({ "dateFormat": "yy-mm-dd" , changeMonth: true, changeYear: true, }); elem.attr('value',"Сохранить").on( "click", function(event) { $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "save_feis_edit", name: feisname.children('input').val(), city: city.children('input').val(), date: date.children('input').val(), feis_id:feis_id, }, success: function (data, textStatus) { elem.attr('value',"Править"); feisname.html(feisname.children('input').val()); city.html(city.children('input').val()); date.html(date.children('input').val()); elem.on('click', function(event) { edit_feis($(this),feis_id) }); } }); }); } function edit_school(elem,school_id){ elem.removeAttr('onclick'); elem.off(); elem.attr('value',"Сохранить"); row=elem.parents('tr'); schoolname=row.children('td:eq(1)'); schoolname.html(""); code=row.children('td:eq(3)'); code.html(""); elem.attr('value',"Сохранить").on( "click", function(event) { $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "save_school_edit", schoolname: schoolname.children('input').val(), code: code.children('input').val(), school_id:school_id, }, success: function (data, textStatus) { elem.attr('value',"Править"); schoolname.html(schoolname.children('input').val()); code.html(code.children('input').val()); elem.on('click', function(event) { edit_school($(this),feis_id) }); } }); }); } function edit_city(elem,city_id){ elem.removeAttr('onclick'); elem.off(); elem.attr('value',"Сохранить"); row=elem.parents('tr'); cityname=row.children('td:eq(1)'); cityname.html(""); elem.attr('value',"Сохранить").on( "click", function(event) { $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "save_city_edit", name: name.children('input').val(), city_id: city_id, }, success: function (data, textStatus) { elem.attr('value',"Править"); name.html(name.children('input').val()); elem.on('click', function(event) { edit_city($(this),city_id) }); } }); }); } function edit_country(elem,country_id){ elem.removeAttr('onclick'); elem.off(); elem.attr('value',"Сохранить"); row=elem.parents('tr'); countryname=row.children('td:eq(1)'); cuntryname.html(""); elem.attr('value',"Сохранить").on( "click", function(event) { $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "save_country_edit", countryname: name.children('input').val(), country_id: country_id, }, success: function (data, textStatus) { elem.attr('value',"Править"); countryname.html(countryname.children('input').val()); elem.on('click', function(event) { edit_country($(this),country_id) }); } }); }); } function remove_feis(elem,feis_id){ if (confirm("Вы уверены?")){ row=elem.parents('tr'); table=row.parents('table').DataTable(); table.row(row).remove().draw(); $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "remove_feis", feis_id:feis_id, }, }); } } function delete_city(elem,city_id){ if (confirm("Вы уверены?")){ row=elem.parents('tr'); table=row.parents('table').DataTable(); table.row(row).remove().draw(); $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "delete_city", city_id:city_id, }, }); } } function delete_country(elem,country_id){ if (confirm("Вы уверены?")){ row=elem.parents('tr'); table=row.parents('table').DataTable(); table.row(row).remove().draw(); $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "delete_country", country_id:country_id, }, }); } } function delete_school(elem,school_id){ if (confirm("Вы уверены?")){ row=elem.parents('tr'); table=row.parents('table').DataTable(); table.row(row).remove().draw(); $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "delete_school", school_id:school_id, }, }); } } function add_users(elem){ // ДОДЕЛАТЬ row=elem.parents('tr'); table=row.parents('table').DataTable(); surname=row.children('td:eq(1)'); name=row.children('td:eq(2)'); email=row.children('td:eq(3)'); $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "add_new_org", surname: surname.children('input').val(), name: name.children('input').val(), email: email.children('input').val(), }, success: function( data ) { surname.html(surname.children('input').val()); name.html(name.children('input').val()); email.html(email.children('input').val()); row.children('td:eq(4)').html(""); row.children('td:eq(5)').html(""); var rowdata=new Array(); rowdata[0]=""; rowdata[1]=""; rowdata[2]=""; rowdata[3]=""; rowdata[4]=""; rowdata[5]=""; newrow=table.row.add(rowdata).draw().nodes().to$(); newrow.children('td:eq(4)').css('text-align','center'); newrow.children('td:eq(5)').css('text-align','center'); bind_org_surname_autocomplete(); } }); } function new_password(elem,user_id){ elem.attr("value","Выслано"); $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "send_new_password", user_id:user_id, }, }); } function add_group(elem){ row=elem.parents('tr'); table=row.parents('table').DataTable(); groupname=row.children('td:eq(1)'); if ((groupname.children('input').val()!="")){ $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "add_group", name: groupname.children('input').val(), }, success: function( data ) { if (data!=""){ groupname.html(groupname.children('input').val()); row.children('td:eq(3)').html(""); row.children('td:eq(4)').html(""); var rowdata=new Array(); rowdata[0]=""; rowdata[1]=""; rowdata[2]=""; rowdata[3]=""; rowdata[4]=""; rowdata[5]=""; newrow=table.row.add(rowdata).draw().nodes().to$(); newrow.children('td:eq(3)').css('text-align','center'); newrow.children('td:eq(4)').css('text-align','center'); } } }); } } function delete_group(elem,group_id){ if (confirm("Вы уверены?")){ row=elem.parents('tr'); table=row.parents('table').DataTable(); table.row(row).remove().draw(); $.ajax({ url: "actions.php", async:false, type:"post", data: { action: "delete_group", group_id:group_id, }, }); } } function populate_select(){ alert(); }