Explorar o código

支持course封面

visuddhinanda %!s(int64=5) %!d(string=hai) anos
pai
achega
68e499676d

+ 9 - 2
app/course/index.php

@@ -88,6 +88,7 @@ include "../pcdl/html_head.php";
 	</div>
 
     <script>
+
 	$.get("../course/course_list.php",function(data,status){
         let arrData = JSON.parse(data);
         let html_complete="";
@@ -95,8 +96,11 @@ include "../pcdl/html_head.php";
 		
         for (const iterator of arrData) {
 			let html="";
-            html += '<div class="card" style="display:flex;margin:1em;padding:10px;">';
-            html += '<div style="flex:7;">';
+			html += '<div class="card" style="display:flex;margin:1em;padding:10px;">';
+			html += '<div style="flex:3;max-width:15em;">';
+			html += '<img src="../../tmp/images/course/'+iterator.id+'.jpg" alt="cover" width="200" height="200">'
+            html += '</div>';
+            html += '<div style="flex:7;padding:5px;">';
             html +=  '<div class="title" style="padding-bottom:5px;font-size:110%;font-weight:600;"><a href="../course/course.php?id='+iterator.id+'">'+iterator.title+'</a></div>';
 			html += '<div class="summary"  style="padding-bottom:5px;">'+iterator.subtitle+'</div>';
 			let summary = "";
@@ -119,6 +123,9 @@ include "../pcdl/html_head.php";
         }
 		$("#course_list_complete").html(html_complete);
 		$("#course_list_ongoing").html(html_ongoing);
+		$("img").one("error", function(){  
+    	$(this).attr("src", "../../tmp/images/course/default.jpg");   
+	});
 	});
 	</script>	
 

+ 20 - 8
app/course/my_course_edit.php

@@ -66,8 +66,8 @@ echo '</div>';
 echo '<div style="display:flex;">';
 
 echo '<div style="flex:8;padding:0 0.8em;">';
-echo '<form id="course_update" action="##"   method="POST">';
-echo '<input type="hidden" name="course" value="'.$course_info["id"].'" />';
+echo '<form id="course_update" action="##"   method="POST" enctype="multipart/form-data">';
+echo '<input type="hidden" id="course_id" name="course" value="'.$course_info["id"].'" />';
 echo '<input type="hidden" name="op" value="update" />';
 echo '<div id="userfilelist">';
 
@@ -81,7 +81,7 @@ echo '<div id="userfilelist">';
     echo '<div style="display:flex;">';
     echo '<div style="flex:2;">'.$_local->gui->language_select.'</div>';
     echo '<div id="teacher_id" style="flex:8;">';
-    echo '<input  type="input" name="lang" value="'.$course_info["lang"].'" />';
+    echo '<input  type="input" id="lang" name="lang" value="'.$course_info["lang"].'" />';
     echo '</div>';
     echo '</div>'; 
 
@@ -96,22 +96,22 @@ echo '<div id="userfilelist">';
 
     echo '<div style="display:flex;">';
     echo '<div style="flex:2;">'.$_local->gui->sub_title.'</div>';
-    echo '<div style="flex:8;"><input type="input" name = "subtitle" value="'.$course_info["subtitle"].'" /></div>';
+    echo '<div style="flex:8;"><input type="input" id = "subtitle" name = "subtitle" value="'.$course_info["subtitle"].'" /></div>';
     echo '</div>';
 
     echo '<div style="display:flex;">';
     echo '<div style="flex:2;">'.$_local->gui->introduction.'</div>';
-    echo '<div style="flex:8;"><textarea name="summary" style="height:6em;">'.$course_info["summary"].'</textarea></div>';
+    echo '<div style="flex:8;"><textarea id="summary" name="summary" style="height:6em;">'.$course_info["summary"].'</textarea></div>';
     echo '</div>';
 
     echo '<div style="display:flex;">';
     echo '<div style="flex:2;">'.$_local->gui->tag.'</div>';
-    echo '<div style="flex:8;"><input type="input" name = "tag" value="'.$course_info["tag"].'" /></div>';
+    echo '<div style="flex:8;"><input type="input" id = "tag" name = "tag" value="'.$course_info["tag"].'" /></div>';
     echo '</div>';
 
     echo '<div style="display:flex;">';
     echo '<div style="flex:2;">'.$_local->gui->attachment.'</div>';
-    echo '<div style="flex:8;"><input type="input" name = "attachment" value="'.$course_info["attachment"].'" /></div>';
+    echo '<div style="flex:8;"><input type="input" id = "attachment" name = "attachment" value="'.$course_info["attachment"].'" /></div>';
     echo '</div>';
 
     echo '<div style="display:flex;">';
@@ -121,7 +121,7 @@ echo '<div id="userfilelist">';
                        array("id"=>20,"string"=>$_local->gui->not_started),
                        array("id"=>30,"string"=>$_local->gui->in_progress),
                        array("id"=>40,"string"=>$_local->gui->already_over));
-    echo "<select name = 'status'>";
+    echo "<select id = 'status'  name = 'status'>";
     foreach ($arrStatus as $key => $value) {
         # code...
 
@@ -132,6 +132,18 @@ echo '<div id="userfilelist">';
         echo " value='{$value["id"]}'>{$value["string"]}</option>";
     }
     echo "</select>";
+    echo "<div class='cover'>";
+    $cover_file  = _DIR_IMAGES_COURSE_."/".$course_info["id"].".jpg";
+    if(!file_exists(_DIR_IMAGES_COURSE_."/".$course_info["id"].".jpg")){
+            $cover_file = _DIR_IMAGES_COURSE_A_."/default.jpg";
+        
+    }
+    else{
+            $cover_file = _DIR_IMAGES_COURSE_A_."/".$course_info["id"].".jpg";
+        }
+    echo '<img src="'.$cover_file.'" alt="cover" width="200" height="200">';
+    echo "</div>";
+    echo '<div><input type="file" name="cover" id="cover_file" /></div> ';
     echo '</div>';
     echo '</div>';
 echo '</div>';

+ 32 - 2
app/course/my_course_update.php

@@ -3,14 +3,44 @@ require_once "../path.php";
 require_once "../public/_pdo.php";
 require_once '../public/function.php';
 
-global $PDO;
+$respond=array("status"=>0,"message"=>"");
+//处理文件上传
+
+if(isset($_FILES["cover"])){
+	if ((($_FILES["cover"]["type"] == "image/gif")
+	|| ($_FILES["cover"]["type"] == "image/jpeg")
+	|| ($_FILES["cover"]["type"] == "image/png"))
+	&& ($_FILES["cover"]["size"] < 2000000))
+	{
+	if ($_FILES["cover"]["error"] > 0)
+		{
+			$respond['status']=1;
+			$respond['message']=$_FILES["cover"]["error"];
+		}
+	else
+		{
+		move_uploaded_file($_FILES["cover"]["tmp_name"],
+		_DIR_IMAGES_COURSE_."/" . $_POST["course"].".jpg");
+		}
+	}
+	else
+	{
+	echo "Invalid file";
+	$respond['status']=1;
+	$respond['message']="Invalid file";
+	}	
+}
+
+
+//处理文件上传结束
+
 PDO_Connect("sqlite:"._FILE_DB_COURSE_);
 
 $query="UPDATE course SET  title = ? , subtitle = ? ,  summary = ? , teacher = ?  , tag = ?  , lang = ?  , attachment = ? , status = ? , receive_time = ?  , modify_time = ?   where  id = ?  ";
 $sth = $PDO->prepare($query);
 
 $sth->execute(array( $_POST["title"] , $_POST["subtitle"] ,  $_POST["summary"] ,   $_POST["teacher"]  ,  $_POST["tag"] ,  $_POST["lang"] , $_POST["attachment"] ,$_POST["status"] , mTime() , mTime() , $_POST["course"]));
-$respond=array("status"=>0,"message"=>"");
+
 if (!$sth || ($sth && $sth->errorCode() != 0)) {
 	$error = PDO_ErrorInfo();
 	$respond['status']=1;

+ 18 - 1
app/course/my_couse.js

@@ -134,11 +134,28 @@ function lesson_insert() {
 }
 
 function course_update() {
+	//let data = $("#course_update").serialize();
+	let files = $("#cover_file").prop("files");
+	let data = new FormData();
+	data.append("course", $("#course_id").val());
+	data.append("teacher", $("#form_teacher").val());
+	data.append("lang", $("#lang").val());
+	data.append("title", $("#form_title").val());
+	data.append("subtitle", $("#subtitle").val());
+	data.append("summary", $("#summary").val());
+	data.append("tag", $("#tag").val());
+	data.append("attachment", $("#attachment").val());
+	data.append("status", $("#status").val());
+	data.append("cover", files[0]);
+
 	$.ajax({
 		type: "POST", //方法类型
 		dataType: "json", //预期服务器返回的数据类型
 		url: "../course/my_course_update.php", //url
-		data: $("#course_update").serialize(),
+		data: data,
+		cache: false,
+		processData: false,
+		contentType: false,
 		success: function (result) {
 			console.log(result); //打印服务端返回的数据(调试用)
 			alert(result.message);

+ 6 - 0
app/install/step1.php

@@ -32,6 +32,12 @@ $dir[]=_DIR_PALI_CSV_;
 $dir[]=_DIR_TEMP_;
 $dir[]=_DIR_LOG_;
 
+$dir[]=_DIR_IMAGES_;
+$dir[]=_DIR_IMAGES_ARTICLE_;
+$dir[]=_DIR_IMAGES_COLLECTION_;
+$dir[]=_DIR_IMAGES_COURSE_;
+$dir[]=_DIR_IMAGES_LESSON_;
+
 foreach($dir as $onedir){
 	echo '<div style="padding:10px;margin:5px;border-bottom: 1px solid gray;display:flex;">';
 	echo '<div style="flex:7;">'.$onedir.'</div>';

+ 7 - 0
app/path.php

@@ -8,6 +8,13 @@ define("_DIR_PALICANON_PALITEXT_" , __DIR__."/../tmp/appdata/palicanon/pali_text
 define("_DIR_PALICANON_WBW_" , __DIR__."/../tmp/appdata/palicanon/wbw");
 define("_DIR_PALICANON_TRAN_" , __DIR__."/../tmp/appdata/palicanon/translate");
 
+define("_DIR_IMAGES_" , __DIR__."/../tmp/images");
+define("_DIR_IMAGES_ARTICLE_" , __DIR__."/../tmp/images/article");
+define("_DIR_IMAGES_COLLECTION_" , __DIR__."/../tmp/images/collection");
+define("_DIR_IMAGES_COURSE_" , __DIR__."/../tmp/images/course");
+define("_DIR_IMAGES_COURSE_A_" , "../../tmp/images/course");
+define("_DIR_IMAGES_LESSON_" , __DIR__."/../tmp/images/lesson");
+
 //pali canon db file 语料库
 define("_FILE_DB_RESRES_INDEX_"  , __DIR__."/../tmp/appdata/palicanon/res.db3");
 define("_FILE_DB_PALITEXT_" , __DIR__."/../tmp/appdata/palicanon/pali_text.db3");