<|start_filename|>js/student_sx.js<|end_filename|>
function update() {
    if (!validUpdate()) {
        return;
    }


    jQuery.ajax({
        type: 'POST',
        url: '/libsystem/student/student/update.php',
        cache: false,
        data: {
                    idss: $.trim($("#update_sno").val()),
                    bname: $.trim($("#update_sname").val()),
                    password: $.trim($("#update_password").val()),
                    passwordNew: $.trim($("#update_password_new").val()),
                    phone: $.trim($("#update_phone").val()),
                    mail: $.trim($("#update_mail").val())
        },
        success: function (data) {
            if (data == 1) {
                showInfo("操作成功");
            } else if (data == 0) {
                showInfo("操作失败，请重试");
            } else if (data == 1) {
                showInfo("此学号不存在");
            } else if (data == 2) {
                showInfo("原密码不正确");
            } else {
                showInfo("操作失败，请重试");
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            showInfo("操作失败，请重试");
        }
    });
}

function validUpdate() {
    var flag = true;

    var update_sname = $.trim($("#update_sname").val());
    if (update_sname == "") {
        $("#update_sname").parent().parent().addClass("has-error");
        $("#update_sname").next().text("请输入用户名称");
        flag = false;
    } else if (update_sname.length > 50) {
        $("#update_sname").parent().parent().addClass("has-error");
        $("#update_sname").next().text("用户名称长度不能大于50");
        flag = false;
    } else {
        $("#update_sname").parent().parent().removeClass("has-error");
        $("#update_sname").next().text("");
    }

    var update_password = $.trim($("#update_password").val());
    if (update_password == "") {
        $("#update_password").parent().parent().addClass("has-error");
        $("#update_password").next().text("请输入密码");
        flag = false;
    } else {
        $("#update_password").parent().parent().removeClass("has-error");
        $("#update_password").next().text("");
    }

    var update_password_new = $.trim($("#update_password_new").val());
    if (update_password_new == "") {
        $("#update_password_new").parent().parent().addClass("has-error");
        $("#update_password_new").next().text("请输入新密码");
        flag = false;
    } else if (update_password_new.length > 20) {
        $("#update_password_new").parent().parent().addClass("has-error");
        $("#update_password_new").next().text("新密码长度不能大于20");
        flag = false;
    } else {
        $("#update_password_new").parent().parent().removeClass("has-error");
        $("#update_password_new").next().text("");
    }

    var update_password_confirm = $.trim($("#update_password_confirm").val());
    if (update_password_confirm == "") {
        $("#update_password_confirm").parent().parent().addClass("has-error");
        $("#update_password_confirm").next().text("请输入确认密码");
        flag = false;
    } else if (update_password_confirm.length > 20) {
        $("#update_password_confirm").parent().parent().addClass("has-error");
        $("#update_password_confirm").next().text("新密码长度不能大于20");
        flag = false;
    } else if (update_password_new != update_password_confirm) {
        $("#update_password_confirm").parent().parent().addClass("has-error");
        $("#update_password_confirm").next().text("确认密码与新密码不一致");
        flag = false;
    } else {
        $("#update_password_confirm").parent().parent().removeClass("has-error");
        $("#update_password_confirm").next().text("");
    }

    return flag;
}

function showInfo(msg) {
    $("#div_info").text(msg);
    $("#modal_info").modal('show');
}

<|start_filename|>js/student.js<|end_filename|>
var table;
$(function () {
    table = $('#data_list').DataTable({
        "ajax": {
            "url": "/libsystem/admin/student/list.php",
            "type": "POST",
            "data": function (d) {
                return {
                    "rno": $('#query_rno').val(),
                    "rname": $('#query_rname').val()
                };
            }
        },
        "columns": [
            {"data": "rno"},
            {"data": "rname"},
            {"data": "password"},
            {"data": null}
        ],
        columnDefs: [
            {
                targets: 3,
                render: function (a, b, c, d) {
                    return "<button type='button' class='btn btn-xs btn-success' id='btn_edit' onclick='showUpdate(\"" + c.id + "\")'>详细</button>&nbsp" +
                        "<button type='button' class='btn btn-xs btn-danger' id='btn_edit' onclick='showDel(\"" + c.id + "\")'>删除</button>";
                }
            }
        ],
    });
});

function query() {
    table.ajax.reload();
}

function showAdd() {
    $('#modal_add').modal('show');
}

function add() {
    if (!validAdd()) {
        return;
    }

    var param = {
        sno: $.trim($("#add_sno").val()),
        sname: $.trim($("#add_sname").val()),
        password: $.trim($("#add_password").val()),
        type: $.trim($("#add_type").val()),
        phone: $.trim($("#add_phone").val()),
        mail: $.trim($("#add_mail").val())
    }

    jQuery.ajax({
        type: 'POST',
        url: '/libsystem/admin/student/save.php',
        cache: false,
        data: {
            sno: $.trim($("#add_sno").val()),
            sname: $.trim($("#add_sname").val()),
            password: $.trim($("#add_password").val()),
            type: $.trim($("#add_type").val()),
            phone: $.trim($("#add_phone").val()),
            mail: $.trim($("#add_mail").val())
            },
        success: function (data) {
            if (data == 1) {
                $('#modal_add').modal('hide');
                showInfo("操作成功");
                table.ajax.reload();
            } else if (data == 0) {
                showInfo("操作失败，请重试");
            } else if (data == -1) {
                showInfo("此学号已存在，请重新输入");
            } else {
                showInfo("操作失败，请重试");
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            showInfo("操作失败，请重试");
        }
    });
}

function showUpdate(id) {
    jQuery.ajax({
        type: 'POST',
        url: '/libsystem/admin/student/findById.php',
        cache: false,
        data: {id: id},
        success: function (data) {
            var datas= eval("("+data+")");
            $("#update_id").val(datas.id);
            $("#update_sno").val(datas.sno);
            $("#update_sname").val(datas.sname);
            $("#update_password").val(<PASSWORD>);
            $("#update_type").val(datas.type);
            $("#update_phone").val(datas.phone);
            $("#update_mail").val(datas.mail);
            $("#update_booknum").val(datas.booknum);
            $('#modal_update').modal('show');
        },
        error: function (jqXHR, textStatus, errorThrown) {
            showInfo("操作失败，请重试");
        }
    });
}

function update() {
    if (!validUpdate()) {
        return;
    }

    var param = {
        id: $.trim($("#update_id").val()),
        sno: $.trim($("#update_sno").val()),
        sname: $.trim($("#update_sname").val()),
        password: $.trim($("#update_password").val()),
        type: $.trim($("#update_type").val()),
        mail: $.trim($("#update_mail").val()),
        phone: $.trim($("#update_phone").val())
    }

    jQuery.ajax({
        type: 'POST',
        url: '/libsystem/admin/student/update.php',
        cache: false,
        data: param,
        success: function (data) {
            if (data) {
                $('#modal_update').modal('hide');
                showInfo("操作成功");
                table.ajax.reload();
            } else {
                showInfo("操作失败，请重试");
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            showInfo("操作失败，请重试");
        }
    });
}

function showDel(id) {
    $('#modal_delete').modal('show');
    $('#delete_id').val(id);
}

function del() {
    jQuery.ajax({
        type: 'POST',
        url: '/libsystem/admin/student/delete.php',
        cache: false,
        data: {
            id: $('#delete_id').val()
        },
        success: function (data) {
            if (data) {
                $('#modal_delete').modal('hide');
                table.ajax.reload();
            } else {
                showInfo("操作失败，请重试");
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            showInfo("操作失败，请重试");
        }
    });
}

function validAdd() {
    var flag = true;

    var add_sno = $.trim($("#add_sno").val());
    if (add_sno == "") {
        $("#add_sno").parent().parent().addClass("has-error");
        $("#add_sno").next().text("请输入管理员编号");
        flag = false;
    } else if (add_sno.length > 20) {
        $("#add_sno").parent().parent().addClass("has-error");
        $("#add_sno").next().text("管理员编号长度不能大于20");
        flag = false;
    } else if (isNaN(add_sno)){
        $("#add_sno").parent().parent().addClass("has-error");
        $("#add_sno").next().text("学生编号只能全部为数字");
        flag = false;
    } else {
        $("#add_sno").parent().parent().removeClass("has-error");
        $("#add_sno").next().text("");
    }

    var add_sname = $.trim($("#add_sname").val());
    if (add_sname == "") {
        $("#add_sname").parent().parent().addClass("has-error");
        $("#add_sname").next().text("请输入姓名");
        flag = false;
    } else if (add_sname.length > 50) {
        $("#add_sname").parent().parent().addClass("has-error");
        $("#add_sname").next().text("管理员名称长度不能大于50");
        flag = false;
    } else {
        $("#add_sname").parent().parent().removeClass("has-error");
        $("#add_sname").next().text("");
    }

    var add_password = $.trim($("#add_password").val());
    if (add_password == "") {
        $("#add_password").parent().parent().addClass("has-error");
        $("#add_password").next().text("请输入密码");
        flag = false;
    } else if (add_password.length > 20) {
        $("#add_password").parent().parent().addClass("has-error");
        $("#add_password").next().text("密码长度不能大于20");
        flag = false;
    } else {
        $("#add_password").parent().parent().removeClass("has-error");
        $("#add_password").next().text("");
    }
    var add_type = $.trim($("#add_type").val());
    if(add_type == "") {
        $("#add_type").parent().parent().addClass("has-error");
        $("#add_type").next().text("请输入邮箱");
        flag = false;
    } else {
        $("#add_type").parent().parent().removeClass("has-error");
        $("#add_type").next().text("");
    }
    var add_email= $.trim($("#add_mail").val());
    if (add_email == "") {
        $("#add_mail").parent().parent().addClass("has-error");
        $("#add_mail").next().text("请输入邮箱");
        flag = false;
    } else if (!isEmail(add_email)) {
        $("#add_mail").parent().parent().addClass("has-error");
        $("#add_mail").next().text("邮箱地址不合法");
        flag = false;
    } else {
        $("#add_mail").parent().parent().removeClass("has-error");
        $("#add_mail").next().text("");
    }

    var add_phone= $.trim($("#add_phone").val());
    if (add_email == "") {
        $("#add_phone").parent().parent().addClass("has-error");
        $("#add_phone").next().text("请输入手机号");
        flag = false;
    } else if (!isPhone(add_phone)) {
        $("#add_phone").parent().parent().addClass("has-error");
        $("#add_phone").next().text("手机号不合法");
        flag = false;
    } else {
        $("#add_phone").parent().parent().removeClass("has-error");
        $("#add_phone").next().text("");
    }

    return flag;
}

function validUpdate() {
    var flag = true;

    var update_sname = $.trim($("#update_sname").val());
    if (update_sname == "") {
        $("#update_sname").parent().parent().addClass("has-error");
        $("#update_sname").next().text("请输入管理员名称");
        flag = false;
    } else if (update_sname.length > 50) {
        $("#update_sname").parent().parent().addClass("has-error");
        $("#update_sname").next().text("管理员名称长度不能大于50");
        flag = false;
    } else {
        $("#update_sname").parent().parent().removeClass("has-error");
        $("#update_sname").next().text("");
    }

    var update_password = $.trim($("#update_password").val());
    if (update_password == "") {
        $("#update_password").parent().parent().addClass("has-error");
        $("#update_password").next().text("请输入密码");
        flag = false;
    } else if (update_password.length > 20) {
        $("#update_password").parent().parent().addClass("has-error");
        $("#update_password").next().text("密码长度不能大于20");
        flag = false;
    } else {
        $("#update_password").parent().parent().removeClass("has-error");
        $("#update_password").next().text("");
    }

    return flag;
}

function showInfo(msg) {
    $("#div_info").text(msg);
    $("#modal_info").modal('show');
}

<|start_filename|>js/book-type.js<|end_filename|>
var table;
$(function () {
    table = $('#data_list').DataTable({
        "ajax": {
            "url": "/libsystem/admin/bookType/list.php",
            "type": "POST",
            "data": function (d) {
                return {
                    "tname": $('#query_tname').val()
                };
            }
        },
        "columns": [
            {"data": "tname"},
            {"data": null}
        ],
        columnDefs: [
            {
                targets: 1,
                render: function (a, b, c, d) {
                    return "<button type='button' class='btn btn-xs btn-warning' id='btn_edit' onclick='showUpdate(\"" + c.id + "\")'>修改</button>&nbsp" +
                        "<button type='button' class='btn btn-xs btn-danger' id='btn_edit' onclick='showDel(\"" + c.id + "\")'>删除</button>";
                }
            }
        ],
    });
});

function query() {
    table.ajax.reload();
}

function showAdd() {
    $('#modal_add').modal('show');
}

function add() {
    if (!validAdd()) {
        return;
    }

    jQuery.ajax({
        type: 'POST',
        url: '/libsystem/admin/bookType/save.php',
        cache: false,
        data: {
            tname: $.trim($("#add_tname").val())
        },
        success: function (data) {
            if (data == 1) {
                $('#modal_add').modal('hide');
                showInfo("操作成功");
                table.ajax.reload();
            } else if (data == 0) {
                showInfo("操作失败，请重试");
            } else if (data == -1) {
                showInfo("分类名称已存在，请重新输入");
            } else {
                showInfo("操作失败，请重试");
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            showInfo("操作失败，请重试");
        }
    });
}

function showUpdate(id) {
    jQuery.ajax({
        type: 'POST',
        url: '/libsystem/admin/bookType/findById.php',
        cache: false,
        data: {id: id},
        success: function (data) {
            var datas=eval("("+data+")");
            $("#update_id").val(id);
            $("#update_tname").val(datas.tname);
            $("#modal_update").modal("show");
        },
        error: function (jqXHR, textStatus, errorThrown) {
            showInfo("操作失败，请重试");
        }
    });
}

function update() {
    if (!validUpdate()) {
        return;
    }

    jQuery.ajax({
        type: 'POST',
        url: '/libsystem/admin/bookType/update.php',
        cache: false,
        data: {
            id: $.trim($("#update_id").val()),
            tname: $.trim($("#update_tname").val())
        },
        success: function (data) {
            if (data == 1) {
                $('#modal_update').modal('hide');
                showInfo("操作成功");
                table.ajax.reload();
            } else if (data == 0) {
                showInfo("操作失败，请重试");
            } else if (data == -1) {
                showInfo("分类名称已存在，请重新输入");
            } else {
                showInfo("操作失败，请重试");
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            showInfo("操作失败，请重试");
        }
    });
}

function showDel(id) {
    $('#modal_delete').modal('show');
    $('#delete_id').val(id);
}

function del() {
    jQuery.ajax({
        type: 'POST',
        url: '/libsystem/admin/bookType/delete.php',
        cache: false,
        data: {
            id: $('#delete_id').val()
        },
        success: function (data) {
            if (data) {
                $('#modal_delete').modal('hide');
                table.ajax.reload();
            } else {
                showInfo("操作失败，请重试");
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            showInfo("操作失败，请重试");
        }
    });
}

function validAdd() {
    var flag = true;

    var add_tname = $.trim($("#add_tname").val());
    if (update_tname == "") {
        $("#update_tname").parent().parent().addClass("has-error");
        $("#update_tname").next().text("请输入分类名称");
        flag = false;
    } else if (update_tname.length > 20) {
        $("#update_tname").parent().parent().addClass("has-error");
        $("#update_tname").next().text("分类名称长度不能大于20");
        flag = false;
    } else {
        $("#update_tname").parent().parent().removeClass("has-error");
        $("#update_tname").next().text("");
    }

    return flag;
}

function validUpdate() {
    var flag = true;

    var update_tname = $.trim($("#update_tname").val());
    if (update_tname == "") {
        $("#update_tname").parent().parent().addClass("has-error");
        $("#update_tname").next().text("请输入分类名称");
        flag = false;
    } else if (update_tname.length > 20) {
        $("#update_tname").parent().parent().addClass("has-error");
        $("#update_tname").next().text("分类名称长度不能大于20");
        flag = false;
    } else {
        $("#update_tname").parent().parent().removeClass("has-error");
        $("#update_tname").next().text("");
    }

    return flag;
}

function showInfo(msg) {
    $("#div_info").text(msg);
    $("#modal_info").modal('show');
}

<|start_filename|>js/borrow.js<|end_filename|>
var table;
$(function () {
    table = $('#data_list').DataTable({
        "ajax": {
            "url": "/libsystem/admin/borrow/list.php",
            "type": "POST",
            "cache": false,
            "data": function (d) {
                return {
                    "sno": $("#borrow_sno").val(),
                };
            }
        },
        "columns": [
            {"data": "bno"},
            {"data": "bname"},
            {"data": "author"},
            {"data": "price"},
            {"data": "sno"},
            {"data": "sname"},
            {"data": "timeout"},
            {"data": null},
            {"data": null},
            {"data": null}
        ],
        columnDefs: [
            {
                targets: 6,
                render: function (a, b, c, d) {
                    return c.bdate;
                }
            },
            {
                targets: 7,
                render: function (a, b, c, d) {
                    return c.rdate;
                }
            },
            {
                targets: 8,
                render: function (a, b, c, d) {
                    return c.timeout;
                }
            },
            {
                targets: 9,
                render: function (a, b, c, d) {
                     return "<button type='button' class='btn btn-xs btn-warning' id='btn_rent' onclick='showDel(\"" + c.id + "\")'>短信提醒</button>&nbsp";
                }
            }
        ]
    });
});

function borrowBook() {
    if (!validBorrow()) {
        return;
    }

    jQuery.ajax({
        type: 'POST',
        url: '/libsystem/admin/borrow/save.php',
        cache: false,
        data: {
            bno: $.trim($("#borrow_bno").val()),
            sno: $.trim($("#borrow_sno").val()) 
        },
        success: function (data) {
            if (data == 1) {
                showInfo("操作成功");
                table.ajax.reload();
            } else if (data == 0) {
                showInfo("操作失败，请重试");
            } else if (data == -1) {
                showInfo("此学号不存在");
            } else if (data == -2) {
                showInfo("此图书编号不存在");
            } else if (data == -3) {
                showInfo("此图书在馆数量不足");
            } else if (data == -4) {
                showInfo("您已经借阅此书，不能重复借阅");
            } else if (data == -5) {
                showInfo("您的借阅图书已达上限");
            }else{
                showInfo("操作失败，请重试");
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            showInfo("操作失败，请重试");
        }
    });
}

function validBorrow() {
    var flag = true;

    var borrow_sno = $.trim($("#borrow_sno").val());
    if (borrow_sno == "") {
        $("#borrow_sno").parent().parent().addClass("has-error");
        $("#borrow_sno").next().text("请输入学号");
        $("#borrow_sno").next().show();
        flag = false;
    } else if (borrow_sno.length > 20) {
        $("#borrow_sno").parent().parent().addClass("has-error");
        $("#borrow_sno").next().text("学号长度不能大于20");
        $("#borrow_sno").next().show();
        flag = false;
    } else {
        $("#borrow_sno").parent().parent().removeClass("has-error");
        $("#borrow_sno").next().text("");
        $("#borrow_sno").next().hide();
    }

    var borrow_bno = $.trim($("#borrow_bno").val());
    if (borrow_bno == "") {
        $("#borrow_bno").parent().parent().addClass("has-error");
        $("#borrow_bno").next().text("请输入图书编号");
        $("#borrow_bno").next().show();
        flag = false;
    } else if (borrow_bno.length > 20) {
        $("#borrow_bno").parent().parent().addClass("has-error");
        $("#borrow_bno").next().text("图书编号长度不能大于20");
        $("#borrow_bno").next().show();
        flag = false;
    } else {
        $("#borrow_bno").parent().parent().removeClass("has-error");
        $("#borrow_bno").next().text("");
        $("#borrow_bno").next().hide();
    }

    return flag;
}
function sendSMS() {
    jQuery.ajax({
        type: 'POST',
        url: '/libsystem/SMS/sendSMS.php',
        cache: false,
        data: {
            id: $('#delete_id').val()
        },
        success: function (data) {
            if (data) {
                showInfo("发送成功。");
            } else {
                showInfo("操作失败，请重试");
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            showInfo("操作失败，请重试");
        }
    });
}
function showDel(id) {
    $('#modal_delete').modal('show');
    $('#delete_id').val(id);
}
function showInfo(msg) {
    $("#div_info").text(msg);
    $("#modal_info").modal('show');
}
function query() {
    table.ajax.reload();
}

<|start_filename|>js/borrow-info.js<|end_filename|>
var table;
$(function () {
    table = $('#data_list').DataTable({
        "ajax": {
            "url": "/libsystem/admin/borrowInfo/list.php",
            "type": "POST",
            "data": function (d) {
                return {
                    "bno": $("#query_bno").val(),
                    "bname": $("#query_bname").val(),
                    "sno": $("#query_sno").val(),
                    "sname": $("#query_sname").val()
                };
            }
        },
        "columns": [
            {"data": "bno"},
            {"data": "bname"},
            {"data": "author"},
            {"data": "price"},
            {"data": "sno"},
            {"data": "sname"},
            {"data": "timeout"},
            {"data": null},
            {"data": null}
        ],
        columnDefs: [
            {
                targets: 6,
                render: function (a, b, c, d) {
                    return c.bdate;
                }
            },
            {
                targets: 7,
                render: function (a, b, c, d) {
                    return c.rdate;
                }
            },
            {
                targets: 8,
                render: function (a, b, c, d) {
                    return c.timeout;
                }
            }
        ]
    });
});

function query() {
    table.ajax.reload();
}

<|start_filename|>js/login.js<|end_filename|>
$(function () {
    $('#login_submit').click(function () {
        var role = $("#role").val();
        if (!validLogin()) {
            return;
        }

        $.ajax({
            type: 'POST',
            url: '/libsystem/login/index.php',
            cache: false,
            data: {
                username: $.trim($("#username").val()),
                password: $.trim($("#password").val()),
            },
            success: function (data) {
                if (data == 1) {
                    window.location.href = "/libsystem/student";
                } else if (data == 9){//管理员
                    window.location.href = "/libsystem/admin";
                } else if (data == 0) {
                    showInfo("登录失败，请重试");
                } else if (data == -1) {
                    showInfo("账号不存在");
                } else if (data == -2) {
                    showInfo("密码错误");
                } else {
                    showInfo("登录失败，请重试");
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                showInfo("登录失败，请重试");
            }
        });
    });

    var alert = $('.alert');
    var formWidth = $('.bootstrap-admin-login-form').innerWidth();
    var alertPadding = parseInt($('.alert').css('padding'));
    if (isNaN(alertPadding)) {
        alertPadding = parseInt($(alert).css('padding-left'));
    }
    $('.alert').width(formWidth - 2 * alertPadding);
});

function validLogin() {
    var flag = true;

    var username = $.trim($("#username").val());
    if (username == "") {
        $('#username').parent().addClass("has-error");
        $('#username').next().text("请输入账号");
        $("#username").next().show();
        flag = false;
    } else if (username.length > 20) {
        $("#username").parent().addClass("has-error");
        $("#username").next().text("账号长度不能大于20");
        $("#username").next().show();
        flag = false;
    } else {
        $('#username').parent().removeClass("has-error");
        $('#username').next().text("");
        $("#username").next().hide();
    }

    var password = $.trim($("#password").val());
    if (password == "") {
        $('#password').parent().addClass("has-error");
        $('#password').next().text("请输入密码");
        $("#password").next().show();
        flag = false;
    } else if (password.length > 20) {
        $("#password").parent().addClass("has-error");
        $("#password").next().text("密码长度不能大于20");
        $("#password").next().show();
        flag = false;
    } else {
        $('#password').parent().removeClass("has-error");
        $('#password').next().text("");
        $("#password").next().hide();
    }
    return flag;
}


function isEmail(str){
       var reg = /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
       return reg.test(str);
}
function isPhone(str){ 
    var reg = /^1[34578]\d{9}$/;
    return reg.test(str);
}

function validReg() {
    var flag = true;

    var add_bno = $.trim($("#add_bno").val());
    if (add_bno == "") {
        $("#add_bno").parent().parent().addClass("has-error");
        $("#add_bno").next().text("请输入用户编号");
        flag = false;
    } else if (add_bno.length > 10) {
        $("#add_bno").parent().parent().addClass("has-error");
        $("#add_bno").next().text("用户编码长度不能大于10");
        flag = false;
    } else {
        $("#add_bno").parent().parent().removeClass("has-error");
        $("#add_bno").next().text("");
    }

    var add_bname = $.trim($("#add_bname").val());
    if (add_bname == "") {
        $("#add_bname").parent().parent().addClass("has-error");
        $("#add_bname").next().text("请输入读者姓名");
        flag = false;
    } else if (add_bname.length > 10) {
        $("#add_bname").parent().parent().addClass("has-error");
        $("#add_bname").next().text("读者姓名长度不能大于10");
        flag = false;
    } else {
        $("#add_bname").parent().parent().removeClass("has-error");
        $("#add_bname").next().text("");
    }


    var add_password= $.trim($("#add_password").val());
    if (add_password == "") {
        $("#add_password").parent().parent().addClass("has-error");
        $("#add_password").next().text("请输入密码");
        flag = false;
    } else if (add_password.length > 16) {
        $("#add_password").parent().parent().addClass("has-error");
        $("#add_password").next().text("密码长度不能大于16");
        flag = false;
    } else {
        $("#add_password").parent().parent().removeClass("has-error");
        $("#add_password").next().text("");
    }
    //OK
    var add_email= $.trim($("#add_email").val());
    if (add_email == "") {
        $("#add_email").parent().parent().addClass("has-error");
        $("#add_email").next().text("请输入邮箱");
        flag = false;
    } else if (!isEmail(add_email)) {
        $("#add_email").parent().parent().addClass("has-error");
        $("#add_email").next().text("邮箱地址不合法");
        flag = false;
    } else {
        $("#add_email").parent().parent().removeClass("has-error");
        $("#add_email").next().text("");
    }

    var add_phone= $.trim($("#add_phone").val());
    if (add_email == "") {
        $("#add_phone").parent().parent().addClass("has-error");
        $("#add_phone").next().text("请输入手机号");
        flag = false;
    } else if (!isPhone(add_phone)) {
        $("#add_phone").parent().parent().addClass("has-error");
        $("#add_phone").next().text("手机号不合法");
        flag = false;
    } else {
        $("#add_phone").parent().parent().removeClass("has-error");
        $("#add_phone").next().text("");
    }
    var add_tid = $.trim($("#add_tid").val());
    if (add_tid == "") {
        $("#add_tid").parent().parent().addClass("has-error");
        $("#add_tid").next().text("请选择所属部门");
        flag = false;
    } else {
        $("#add_tid").parent().parent().removeClass("has-error");
        $("#add_tid").next().text("");
    }

    var add_brief = $.trim($("#add_brief").val());
    if (add_brief.length > 500) {
        $("#add_brief").parent().parent().addClass("has-error");
        $("#add_brief").next().text("简介长度不能大于500");
        flag = false;
    } else {
        $("#add_brief").parent().parent().removeClass("has-error");
        $("#add_brief").next().text("");
    }

    return flag;
}

function showInfo(msg) {
    $("#div_info").text(msg);
    $("#modal_info").modal('show');
}

function reg() {
    if (!validReg()) {
        return;
    }
    jQuery.ajax({
        type: 'POST',
        url: '/libsystem/login/register.php',
        cache: false,
        data: {
            bno: $.trim($("#add_bno").val()),
            name: $.trim($("#add_bname").val()),
            password: $.trim($("#add_password").val()),
            email: $.trim($("#add_email").val()),
            phone: $.trim($("#add_phone").val()),
            department: $.trim($("#add_tid").val())        
        },
        success: function (data) {
            if (data == 1) {
                $('#modal_add').modal('hide');
                showInfo("操作成功");
            } else if (data == 0) {
                showInfo("操作失败，请重试");
            } else if (data == -1) {
                showInfo("此用户编号已存在，请重新输入");
            } else {
                showInfo("操作失败，请重试");
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            showInfo("操作失败，请重试");
        }
    });
}


<|start_filename|>js/student_s.js<|end_filename|>
var table;
$(function () {
    table = $('#data_list').DataTable({
        "ajax": {
            "url": "/libsystem/student/book/list.php",
            "type": "POST",
            "data": function (d) {
                return {
                    "bno": $('#query_bno').val(),
                    "bname": $('#query_bname').val()
                };
            }
        },
        "columns": [
            {"data": "bno"},
            {"data": "bname"},
            {"data": "tname"},
            {"data": "author"},
            {"data": "price"},
            {"data": "total"},
            {"data": "remain"},
            {"data": "cdate"},
            {"data": null}
        ],
        columnDefs: [
            {
                targets: 7,
                render: function (a, b, c, d) {
                    return (new Date(c.cdate)).format('yyyy-MM-dd');
                }
            },
            {
                targets: 8,
                render: function (a, b, c, d) {
                    return "<button type='button' class='btn btn-xs btn-warning' id='btn_rent' onclick='borrowBook(\"" + c.id + "\")'>借阅</button>&nbsp" + "<button type='button' class='btn btn-xs btn-success' id='btn_detail' onclick='showDetail(\"" + c.id + "\")'>查看</button>";
                }
            }
        ]
    });
});

function query() {
    table.ajax.reload();
}

function borrowBook(id) {
    jQuery.ajax({
        type: 'POST',
        url: '/libsystem/admin/borrow/save.php',
        cache: false,
        data: {
            bno: id,
            sno: -1 
        },
        success: function (data) {
            if (data == 1) {
                showInfo("操作成功");
                table.ajax.reload();
            } else if (data == 0) {
                showInfo("操作失败，请重试");
            } else if (data == -1) {
                showInfo("此学号不存在");
            } else if (data == -2) {
                showInfo("此图书编号不存在");
            } else if (data == -3) {
                showInfo("此图书在馆数量不足");
            } else if (data == -4) {
                showInfo("您已经借阅此书，不能重复借阅");
            } else if (data == -5) {
                showInfo("您的借阅图书已达上限");
            }else{
                showInfo("操作失败，请重试");
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            showInfo("操作失败，请重试");
        }
    });
}

function showDetail(id) {
    jQuery.ajax({
        type: 'POST',
        url: '/libsystem/student/book/findById.php',
        cache: false,
        data: {id: id},
        success: function (data) {
            var data=eval("("+data+")");
            $("#detail_bno").val(data.bno);
            $("#detail_bname").val(data.bname);
            $("#detail_author").val(data.author);
            $("#detail_price").val(data.price);
            $("#detail_total").val(data.total);
            $("#detail_remain").val(data.remain);
            $("#detail_brief").val(data.brief);
            $("#detail_tid").val(data.tid);
            $('#modal_detail').modal('show');
        },
        error: function (jqXHR, textStatus, errorThrown) {
            showInfo("操作失败，请重试");
        }
    });
}
function showInfo(msg) {
    $("#div_info").text(msg);
    $("#modal_info").modal('show');
}