ソースを参照

:bug: 新建课程时间错误

visuddhinanda 5 年 前
コミット
b52739dfc8

+ 44 - 2
app/course/my_couse.js

@@ -44,8 +44,15 @@ function course_validate_form(thisform) {
 
 function course_list() {}
 
-function time_init() {
-	let lessonTime = new Date(parseInt($("#form_datetime").val()));
+function time_init(time = 0) {
+	//time=0 input time
+	//time != 0 now
+	let lessonTime;
+	if (time == 0) {
+		lessonTime = new Date(parseInt($("#form_datetime").val()));
+	} else {
+		lessonTime = new Date();
+	}
 	let month = lessonTime.getMonth() + 1;
 	month = month > 9 ? month : "0" + month;
 	let d = lessonTime.getDate();
@@ -90,3 +97,38 @@ function lesson_update() {
 		},
 	});
 }
+
+function lesson_insert() {
+	const date = new Date();
+	$("#lesson_timezone").val(date.getTimezoneOffset());
+	$.ajax({
+		type: "POST", //方法类型
+		dataType: "json", //预期服务器返回的数据类型
+		url: "../course/my_lesson_insert.php", //url
+		data: $("#lesson_new").serialize(),
+		success: function (result) {
+			console.log(result); //打印服务端返回的数据(调试用)
+			if (result.status == 0) {
+				alert(result.message);
+				window.open("../course/my_course_index.php?course=" + result.course_id);
+			} else {
+				alert(result.message);
+			}
+		},
+		error: function (data, status) {
+			alert(status + ":" + data.responseText);
+			switch (status) {
+				case "timeout":
+					break;
+				case "error":
+					break;
+				case "notmodified":
+					break;
+				case "parsererror":
+					break;
+				default:
+					break;
+			}
+		},
+	});
+}

+ 4 - 2
app/course/my_lesson_edit.php

@@ -88,8 +88,9 @@ echo '<div id="userfilelist">';
     echo '<div style="flex:8;"><textarea name="summary" style="height:6em;">'.$lesson_info["summary"].'</textarea></div>';
     echo '</div>';
 
+
     echo '<div style="display:flex;">';
-    echo '<div style="flex:2;">'.$_local->gui->introduction.'</div>';
+    echo '<div style="flex:2;">'.$_local->gui->time_arrange.'</div>';
     echo '<div style="flex:8;">';
     $strDate = date("Y-m-d",$lesson_info["date"]/1000);
     $strTime = date("H:i",$lesson_info["date"]/1000);
@@ -99,7 +100,8 @@ echo '<div id="userfilelist">';
     echo $_local->gui->date.':<div id="form_date"></div>';
     echo $_local->gui->time.':<div id="form_time"></div>';
     echo $_local->gui->duration.':<input type="time" name="duration" value="'.$strDuration.'"/>';
-    echo '</div></div>';
+    echo '</div>';
+    echo '</div>';
 
     echo '<div style="display:flex;">';
     echo '<div style="flex:2;">'.$_local->gui->notice_live.'</div>';

+ 11 - 3
app/course/my_lesson_insert.php

@@ -13,10 +13,19 @@ $query = "INSERT INTO lesson (id, course_id,  live, replay, title,  subtitle ,
 				 VALUES (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
 
 $sth = $PDO->prepare($query);
+
+/*
 $data = strtotime($_POST["lesson_date"]);
 $time = strtotime($_POST["lesson_time"]) - strtotime("today");
 $datatime = ($data+$time)*1000;
 $duration = strtotime($_POST["duration"]) - strtotime("today");
+*/
+
+$data = strtotime($_POST["lesson_date"]);
+$time = strtotime($_POST["lesson_time"]) - strtotime("today");
+$timezone = $_POST["lesson_timezone"];
+$datatime = ($data+$time+$timezone*60)*1000;
+$duration = strtotime($_POST["duration"]) - strtotime("today");
 
 $sth->execute(array(UUID::v4(), $_POST["course_id"] , $_POST["live"] , $_POST["replay"] ,$_POST["title"] , $_POST["subtitle"]  , $datatime  , $duration  , $_COOKIE["userid"] , $_POST["tag"] ,$_POST["summary"] , 1, $_POST["cover"] ,$_POST["teacher"] , $_POST["attachment"] , $_POST["lang"] , $_POST["speech_lang"] ,mTime() , mTime() ,  mTime() ));
 $respond=array("status"=>0,"message"=>"");
@@ -24,12 +33,11 @@ if (!$sth || ($sth && $sth->errorCode() != 0)) {
 	$error = PDO_ErrorInfo();
 	$respond['status']=1;
 	$respond['message']=$error[2];
-	echo "<div style=''>Lesson 数据添加失败:{$error[2]}</div>";
 }
 else{
 	$respond['status']=0;
 	$respond['message']="成功";
-	echo "<div style=''>Lesson 数据添加成功</div>";
+	$respond['course_id']=$_POST["course_id"];
 }
-//echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+echo json_encode($respond, JSON_UNESCAPED_UNICODE);
 ?>

+ 1 - 1
app/course/my_lesson_list.php

@@ -31,7 +31,7 @@ echo '</div>';
 		<span class="icon_btn_div">
 			<span class="icon_btn_tip"><?php echo $_local->gui->new_lesson;?></span>
 			<button id="file_share" type="button" class="icon_btn"  title=" ">
-			<a href="../course/my_course_index.php?course=<?php echo $course_info["id"] ?>&op=newlesson">
+			<a href="../course/my_lesson_new.php?course=<?php echo $course_info["id"] ?>&op=newlesson">
                 <svg style="" t="1601520759574" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7839" width="200" height="200">
                     <path d="M192 256h640v320H192z" p-id="7840"></path>
                     <path d="M832 192.5v447.29H192V192.5h640m0-64H192c-35.35 0-64 28.65-64 64v447.29c0 35.35 28.65 64 64 64h640c35.35 0 64-28.65 64-64V192.5c0-35.35-28.65-64-64-64z" p-id="7841">

+ 59 - 14
app/course/my_lesson_new.php

@@ -1,3 +1,33 @@
+<?php
+require_once '../studio/index_head.php';
+?>
+<body id="file_list_body" onLoad="course_list()">
+
+	<script language="javascript" src="../course/my_couse.js"></script>
+	<script language="javascript" src="../ucenter/name_selector.js"></script>
+	<script >
+	var gCurrPage="course";
+	</script>
+
+	<style>
+	#course {
+		background-color: var(--btn-border-color);
+		
+	}
+	#course:hover{
+		background-color: var(--btn-border-color);
+		color: var(--btn-color);
+		cursor:auto;
+	}
+	</style>
+
+	<?php
+	require_once '../studio/index_tool_bar.php';
+	?>
+		
+	<div class="index_inner" style="    margin-left: 18em;margin-top: 5em;">
+		<div id="course_list"  class="file_list_block">
+
 <div class="tool_bar">
 <?php
 require_once "../path.php";
@@ -24,7 +54,7 @@ echo '</div>';
 
 ?>
 
-<form action="../course/my_course_index.php" method="POST">
+<form  id="lesson_new" action="##" method="POST">
 <input type="hidden" name="course" value="<?php echo $_GET["course"];?>" />
 <input type="hidden" name="op" value="insert" />
 <input type="hidden" name="course_id" value="<?php echo $_GET["course"];?>" />
@@ -65,14 +95,22 @@ echo '</div>';
         <div style="flex:2;"><?php echo $_local->gui->notice_live ?></div>
         <div style="flex:8;"><textarea  name="live"  style="height:6em;"></textarea></div>
     </div>
-    <div style="display:flex;">
-        <div style="flex:2;"><?php echo $_local->gui->time_arrange ?></div>
-        <div style="flex:8;">
-        <?php echo $_local->gui->date ?>:<input type="date" name="lesson_date" value=""/>
-        <?php echo $_local->gui->time ?>:<input type="time" name="lesson_time" value="08:00"/>
-        <?php echo $_local->gui->duration ?>: <input type="time" name="duration" value="01:00"/>
-        </div>
-    </div>
+
+    <?php
+    echo '<div style="display:flex;">';
+    echo '<div style="flex:2;">'.$_local->gui->time_arrange.'</div>';
+    echo '<div style="flex:8;">';
+    echo "<div style='display:flex;'>";
+    echo '<input type="hidden" id="form_datetime" name="form_time" value="'.time().'"/>';
+    echo '<input type="hidden" id="lesson_timezone" name="lesson_timezone" value=""/>';
+    echo '<div><div>'.$_local->gui->date.'</div><div id="form_date"></div></div>';
+    echo '<div><div>'.$_local->gui->time.'</div><div id="form_time"></div></div>';
+    echo  '<div><div>'.$_local->gui->duration.'</div><input type="time" name="duration" value="01:00"/></div>';
+    echo '</div>';
+    echo '</div>';
+    echo '</div>';
+    ?>
+
     <div style="display:flex;">
     <div style="flex:2;"><?php echo $_local->gui->record_replay ?></div>
     <div style="flex:8;"><textarea name="replay" style="height:6em;"></textarea></div>
@@ -102,11 +140,18 @@ echo '</div>';
     </div>
     </div> 
 </div>
-
-
-<input type="submit" value="<?php echo $_local->gui->submit ?>">
 </form>
-
+<button onclick="lesson_insert()"><?php echo $_local->gui->submit ?></button>
 <script>
     name_selector_init("teacher_id",{input_id:"form_teacher"});
-</script>
+    time_init(1);
+</script>
+
+
+</div>
+		
+        </div>
+        
+    <?php
+    require_once '../studio/index_foot.php';
+    ?>

+ 2 - 1
app/course/my_lesson_update.php

@@ -13,12 +13,13 @@ PDO_Execute($query,array(mTime(),mTime(),$course_id));
 
 $query="UPDATE lesson SET title = ? , subtitle = ? , date = ? , duration = ? , live = ? , replay = ? , summary = ? , teacher = ?  , receive_time= ?  , modify_time= ?   where  id = ?  ";
 $sth = $PDO->prepare($query);
+
 $data = strtotime($_POST["lesson_date"]);
 $time = strtotime($_POST["lesson_time"]) - strtotime("today");
 $timezone = $_POST["lesson_timezone"];
 $datatime = ($data+$time+$timezone*60)*1000;
-
 $duration = strtotime($_POST["duration"]) - strtotime("today");
+
 $sth->execute(array($_POST["title"] , $_POST["subtitle"] ,$datatime, $duration , $_POST["live"] , $_POST["replay"] , $_POST["summary"] ,  $_POST["teacher"] ,  mTime() , mTime() , $_POST["lesson"]));
 $respond=array("status"=>0,"message"=>"");
 if (!$sth || ($sth && $sth->errorCode() != 0)) {