zm
2020-09-17 38a128735a457efa5f29ab5dca6068c4727d9f6e
教师端添加,上传专题课功能(按知识点)
3 files modified
292 ■■■■ changed files
we254/addons/fy_teacher/mobile/index/edit.php 105 ●●●●● patch | view | raw | blame | history
we254/addons/fy_teacher/template/mobile/index/display.html 4 ●●●● patch | view | raw | blame | history
we254/addons/fy_teacher/template/mobile/index/edit.html 183 ●●●● patch | view | raw | blame | history
we254/addons/fy_teacher/mobile/index/edit.php
@@ -82,6 +82,111 @@
        message("(VIP)课程折扣的百分比和固定金额只能二选一");
    }
    // 知识点课
    if($type=="5"){
        $data['lesson_type']            = 5;
        $data['knowledge_pid']            = intval($_GPC['know_pid']);
        $data['knowledge_id']            = intval($_GPC['know_cid']);
        $know_parent_name                = trim($_GPC['know_parent_name']);
        $know_name                        = trim($_GPC['know_name']);
        if(empty($data['knowledge_pid'])){
            message("请选择专题!");
        }
        if($data['knowledge_pid']=="-1" && empty($know_parent_name)){
            message("请输入要添加的专题名称!");
        }
        if($data['knowledge_pid']=="-1" && empty($know_name)){
            message("请输入要添加的知识点名称!");
        }
        if($data['knowledge_pid']!="-1" && empty($data['knowledge_id'])){
            message("请选择知识点!");
        }
        if($data['knowledge_id']=="-1" && empty($know_name)){
            message("请输入要添加的知识点名称!");
        }
        // 先插入添加的专题和知识点
        if($data['knowledge_pid']=="-1" ){
            // 验证要添加的专题名称是否已经存在
            $know_parent = pdo_get("fy_lesson_knowledge_point", array('catalog_id_1'=>$data['pid'],'catalog_id_2'=>$data['cid'],'name'=>$know_parent_name, 'parentid'=>0));
            if($know_parent){
                message("已经存在要添加的专题名称【{$know_parent_name}】。");
            }
            // 添加专题
            $know = array(
                'uniacid'      => $_W['uniacid'],
                'name'         => $know_parent_name,
                'ico'          => "",
                'link'           => "",
                'link_pc'       => "",
                'parentid'     => 0,
                'displayorder' => 0,
                'is_hot'       => 0,
                'is_show'       => 1,
                'search_show'  => 1,
                'addtime'      => time(),
                'catalog_id_1' => $data['pid'],
                'catalog_id_2' => $data['cid'],
                'teacher_created_flag' => 1,
                'created_by' => $_SESSION[$uniacid.'_teacher_id']
            );
            pdo_insert("fy_lesson_knowledge_point", $know);
            $new_know_pid = pdo_insertid();
            if($new_know_pid){
                // 添加知识点
                $know['name'] = $know_name;
                $know['parentid'] = $new_know_pid;
                pdo_insert("fy_lesson_knowledge_point", $know);
                $new_know_cid = pdo_insertid();
            }
            // 成功添加专题和知识点时,将新的专题和知识点ID添加到课程中
            if($new_know_pid && $new_know_cid){
                $data['knowledge_pid'] = $new_know_pid;
                $data['knowledge_id'] = $new_know_cid;
            }else{
                message("添加专题知识点失败,请联系管理员!");
            }
        }elseif($data['knowledge_id']=="-1" ){
            // 验证要添加的专题名称是否已经存在
            $know_child = pdo_get("fy_lesson_knowledge_point", array('catalog_id_1'=>$data['pid'],'catalog_id_2'=>$data['cid'],'name'=>$know_name, 'parentid'=>$data['knowledge_pid']));
            if($know_child){
                message("已经存在要添加的知识点名称【{$know_name}】。");
            }
            // 在原有的专题下,只添加知识点
            $know = array(
                'uniacid'      => $_W['uniacid'],
                'name'         => $know_name,
                'ico'          => "",
                'link'           => "",
                'link_pc'       => "",
                'parentid'     => $data['knowledge_pid'],
                'displayorder' => 0,
                'is_hot'       => 0,
                'is_show'       => 1,
                'search_show'  => 1,
                'addtime'      => time(),
                'catalog_id_1' => $data['pid'],
                'catalog_id_2' => $data['cid'],
                'teacher_created_flag' => 1,
                'created_by' => $_SESSION[$uniacid.'_teacher_id']
            );
            // 添加知识点
            pdo_insert("fy_lesson_knowledge_point", $know);
            $new_know_cid = pdo_insertid();
            // 成功知识点时,将知识点ID添加到课程中
            if($new_know_cid){
                $data['knowledge_id'] = $new_know_cid;
            }else{
                message("添加知识点失败,请联系管理员!");
            }
        }
    }
    if(empty($id)){
        $res = pdo_insert($this->table_lesson_parent, $data);
        $id = pdo_insertid();
we254/addons/fy_teacher/template/mobile/index/display.html
@@ -8,7 +8,7 @@
            <input type="hidden" name="do" value="index" />
            <input type="hidden" name="op" value="display" />
            <ul class="search" style="padding-left:10px;">
                <li> <a class="button border-yellow icon-plus-square-o" href="{php echo $this->createMobileUrl('index', array('op'=>'edit','type'=>5));}"> 知识点课程</a> </li>
                <li> <a class="button border-yellow icon-plus-square-o" href="{php echo $this->createMobileUrl('index', array('op'=>'edit','type'=>5));}"> 专题课程</a> </li>
                <li> <a class="button border-green icon-plus-square-o" href="{php echo $this->createMobileUrl('index', array('op'=>'edit','type'=>1));}"> 普通课程</a> </li>
                 {if pdo_tableexists('fy_lesson_plugin_live_chatroom') && $config['add_live_lesson']}
                <li> <a class="button border-blue icon-plus-square-o" href="{php echo $this->createMobileUrl('index', array('op'=>'editLive'));}"> 直播课程</a> </li>
@@ -81,7 +81,7 @@
                    <a class="button border-blue" href="{php echo $this->createMobileUrl('index', array('op'=>'document','pid'=>$item['id']));}"><span class="icon-list"></span> 课件</a>
                    {if $item['lesson_type']!=3}
                    <a class="button border-gray" href="{php echo $this->createMobileUrl('index', array('op'=>'edit','id'=>$item['id'],'refurl'=>$_W['siteurl']));}"><span class="icon-edit"></span> 编辑</a>
                    <a class="button border-gray" href="{php echo $this->createMobileUrl('index', array('op'=>'edit','id'=>$item['id'],'refurl'=>$_W['siteurl'],'type'=>$item['lesson_type']));}"><span class="icon-edit"></span> 编辑</a>
                    {elseif $item['lesson_type']==3}
                        <a class="button border-yellow" href="{php echo $this->createMobileUrl('index', array('op'=>'transform','pid'=>$item['id']));}" onclick="return confirm('转为普通课程后,您需要上传视频并发布章节,确认操作?');return false;"><span class="icon-refresh"></span> 转为普通课程</a>
                        <a class="button border-gray" href="{php echo $this->createMobileUrl('index', array('op'=>'editLive','id'=>$item['id'],'refurl'=>$_W['siteurl']));}"><span class="icon-edit"></span> 编辑</a>
we254/addons/fy_teacher/template/mobile/index/edit.html
@@ -57,7 +57,12 @@
<div class="panel admin-panel">
    <div class="panel-head"><strong><span class="icon-pencil-square-o"></span> {if $id>0}{编辑普通课程}{else}添加普通课程{/if}</strong></div>
    {if $type == '5'}
        <div class="panel-head"><strong><span class="icon-pencil-square-o"></span> {if $id>0}{编辑专题课程}{else}添加专题课程{/if}</strong></div>
    {else}
        <div class="panel-head"><strong><span class="icon-pencil-square-o"></span> {if $id>0}{编辑普通课程}{else}添加普通课程{/if}</strong></div>
    {/if}
    <div class="body-content">
        <form method="post" id="lesson-form" class="form-x" enctype="multipart/form-data" onsubmit="return checkForm()">
            <div class="form-group">
@@ -96,10 +101,16 @@
                        {loop $knowList $item}
                        <option value="{$item['id']}">{$item['name']}</option>
                        {/loop}
                        <option value="-1">+添加新专题</option>
                    </select>
                    <select name="know_cid" class="input category-input" id="know_child">
                        <option value="">请选择知识点</option>
                    </select>
                </div>
            </div>
            <div class="form-group" id="add_know_div" style="display: none;">
                <div class="label"></div>
                <div class="field" id="knowdiv">
                </div>
            </div>
            {/if}
@@ -476,6 +487,21 @@
        }
    });
});
<?php if($type=='5'){ ?>
    $("#category_child").change(function(){
        var cid = $(this).children('option:selected').val();
        var ajaxurl = "{php echo $this->createMobileUrl('index', array('op'=>'edit','type'=>5));}";
        $.get(ajaxurl, {cid: cid }, function (data) {
                if (data.length > 0) {
                    know = JSON.parse(data);
                    renderKnow();
                    document.getElementById("know_parent").onchange();
                }
            });
    });
<?php } ?>
function uploadImage(){
    $("#uploadDiv").show();
    $("#imgDiv").hide();
@@ -506,16 +532,58 @@
    return false;
}
$("#category_child").change(function(){
    var cid = $(this).children('option:selected').val();
    var ajaxurl = "{php echo $this->createMobileUrl('index', array('op'=>'edit','type'=>5));}";
    $.get(ajaxurl, {cid: cid }, function (data) {
            if (data.length > 0) {
                know = JSON.parse(data);
                renderKnow();
                document.getElementById("know_parent").onchange();
            }
        });
//添加专题&知识点
function addKnowParent() {
    if($("#add_know").length>0){
        $("#add_know").empty();
    }
    if($("#add_know_parent").length>0){
        $("#add_know_parent").show();
    }else{
        var spec_html = '';
        $("#knowdiv").empty();
        spec_html += '<div id="add_know_parent" class="input-group w60">';
        spec_html += '    <span class="input-group-addon">专题名称</span>';
        spec_html += '    <input type="text" class="input" id="know_parent_name" name="know_parent_name">';
        spec_html += '    <span class="input-group-addon">知识点名称</span>';
        spec_html += '    <input type="text" class="input" id="know_name" name="know_name">';
        spec_html += '</div>';
        $("#knowdiv").append(spec_html);
    }
    $("#know_child").hide();
}
//添加知识点
function addKnow() {
    if($("#add_know_parent").length>0){
        $("#add_know_parent").empty();
    }
    if($("#add_know").length>0){
        $("#add_know").show();
    }else{
        var spec_html = '';
        $("#knowdiv").empty();
        spec_html += '<div id="add_know" class="input-group w60">';
        spec_html += '    <span class="input-group-addon">知识点名称</span>';
        spec_html += '    <input type="text" class="input" id="know_name" name="know_name">';
        spec_html += '</div>';
        $("#knowdiv").append(spec_html);
    }
    $("#know_child").hide();
}
// 知识点下拉列表选择变化时
$("#know_child").change(function(){
    var know_cid = $(this).children('option:selected').val();
    // -1时为:添加新知识点
    if(know_cid == -1){
        addKnow();
        $("#add_know_div").show();
    }else{
        $("#add_know_div").hide();
    }
});
//添加规格按钮
@@ -571,39 +639,50 @@
    var chtml = '<option value="0">请选择专题</option>';
    if(know.length==0){
        $("#know_parent").html(chtml);
        return;
    }
    var know_pid = {php echo $lesson['knowledge_pid']?$lesson['knowledge_pid']:0};
    for(var i in know){
        if(know[i].id==know_pid){
            chtml += '<option value="' + know[i].id+'" selected>' + know[i].name + '</option>';
        }else{
            chtml += '<option value="' + know[i].id+'">' + know[i].name + '</option>';
    }else{
        var know_pid = {php echo $lesson['knowledge_pid']?$lesson['knowledge_pid']:0};
        for(var i in know){
            if(know[i].id==know_pid){
                chtml += '<option value="' + know[i].id+'" selected>' + know[i].name + '</option>';
            }else{
                chtml += '<option value="' + know[i].id+'">' + know[i].name + '</option>';
            }
        }
    }
    }
    chtml += '<option value="-1">+添加新专题</option>';
    $("#know_parent").html(chtml);
}
function renderKnowChild(id){
    var chtml = '<option value="0">请选择知识点</option>';
    if(id==0){
    // id=-1为选择添加新专题时,否则为具体的专题
    if(id == -1){
        addKnowParent();
        $("#know_child").hide();
        $("#add_know_div").show();
    }else{
        $("#know_child").show();
        $("#add_know_div").hide();
        var chtml = '<option value="0">请选择知识点</option>';
        if(id==0){
            $("#know_child").html(chtml);
        }else{
            var cid = {php echo $lesson['knowledge_id']?$lesson['knowledge_id']:0};
            for(var i in know){
                if(know[i].id==id){
                    var child = know[i].child;
                    for(var j in child){
                        if(child[j].id==cid){
                            chtml += '<option value="' + child[j].id+'" selected>' + child[j].name + '</option>';
                        }else{
                            chtml += '<option value="' + child[j].id+'">' + child[j].name + '</option>';
                        }
                    }
                }
            }
        }
        chtml += '<option value="-1">+添加知识点</option>';
        $("#know_child").html(chtml);
        return;
    }
    var cid = {php echo $lesson['cid']?$lesson['cid']:0};
    for(var i in know){
        if(know[i].id==id){
            var child = know[i].child;
            for(var j in child){
                if(child[j].id==cid){
                    chtml += '<option value="' + child[j].id+'" selected>' + child[j].name + '</option>';
                }else{
                    chtml += '<option value="' + child[j].id+'">' + child[j].name + '</option>';
                }
            }
            $("#know_child").html(chtml);
        }
    }
    }
}
function checkForm(){
@@ -615,6 +694,34 @@
        alert('请选择课程分类');
        return false;
    }
    <?php if($type=='5'){ ?>
        if($("#know_parent option:selected").val()=='0' || $("#know_parent option:selected").val()==''){
            alert('请选择专题');
            $("#know_parent").focus();
            return false;
        }
        if($("#know_parent option:selected").val()!='-1' &&($("#know_child option:selected").val()=='0' || $("#know_child option:selected").val()=='')){
            alert('请选择知识点');
            $("#know_child").focus();
            return false;
        }
        if($("#know_parent option:selected").val()=='-1' && $("#know_parent_name").val()==''){
            alert('请输入要添加专题的名称');
            $("#know_parent_name").focus();
            return false;
        }
        if($("#know_parent option:selected").val()=='-1' && $("#know_name").val()==''){
            alert('请输入要添加知识点的名称');
            $("#know_name").focus();
            return false;
        }
        if($("#know_child option:selected").val()=='-1' && $("#know_name").val()==''){
            alert('请输入要添加知识点的名称');
            $("#know_name").focus();
            return false;
        }
    <?php } ?>
    if($("input[name=images]").val()==''){
        alert('请上传课程封面');
        return false;