Skip to content

Commit

Permalink
Release v3.4.2
Browse files Browse the repository at this point in the history
    - Thay đổi lại cách thức thực hiện truy vấn SQL -> hạn chế lỗi SQL Injection ✓
    - Fix lỗi bị lag khi thực hiện thêm, sửa, xóa với các mục có nhiều dữ liệu ✓
    - Fix lỗi không cài đặt được ở 1 số máy ✓
    - Fix lỗi không hiện công thức toán khi làm bài ✓
    - Rewrite URL ✓
    - Thêm upload ảnh cho nội dung câu hỏi ✓
    - Tối ưu lại một số code ✓
  • Loading branch information
meesudzu committed Mar 27, 2019
1 parent b7ac5cf commit 2a9521b
Show file tree
Hide file tree
Showing 98 changed files with 3,419 additions and 30 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ v3.4.2 (27/03/2019)
- Fix lỗi không cài đặt được ở 1 số máy ✓
- Fix lỗi không hiện công thức toán khi làm bài ✓
- Rewrite URL ✓
- Tối ưu lại một số code ✗
- Thêm upload ảnh trong nội dung câu hỏi ✓
- Tối ưu lại một số code ✓
- Thêm comment cho các hàm phục vụ cho việc bảo trì, nâng cấp ✗

v3.4.1 (17/03/2019)
Expand Down
1 change: 1 addition & 0 deletions GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Nếu đã kiểm tra lại và vẫn lỗi, bạn có thể mở file config/connect.php sửa trực tiếp kết nối trong đó,
hoặc liên hệ báo lỗi tới email: [email protected]

- Sửa URL trang web trong config/config.php
- Sửa tài khoản gửi email quên mật khẩu tại /controllers/controller_login.php dòng 127, 128

- Tài khoản mặc định:
Expand Down
1 change: 1 addition & 0 deletions resource/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ class Config
const EMAIL = "[email protected]";
const RELEASE = "27/03/2019";
const TIMEZONE = "Asia/Bangkok";
const APP_URL = "http://localhost/";
}
20 changes: 19 additions & 1 deletion resource/controllers/controller_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Mail: [email protected]
**/

require_once('core/Base.php');
require_once('config/config.php');
require_once('models/model_admin.php');
require_once('views/view_admin.php');
//load thư viện PhpSpreadSheet
Expand Down Expand Up @@ -1001,13 +1003,29 @@ public function submit_update_avatar()
$duoi = explode('.', $_FILES['file']['name']);
$duoi = $duoi[(count($duoi)-1)];
if ($duoi === 'jpg' || $duoi === 'png') {
if (move_uploaded_file($_FILES['file']['tmp_name'], 'res/img/avatar/'.$this->info['username'].'_' . $_FILES['file']['name'])) {
if (move_uploaded_file($_FILES['file']['tmp_name'], 'upload/avatar/'.$this->info['username'].'_' . $_FILES['file']['name'])) {
$avatar = $this->info['username'] .'_' . $_FILES['file']['name'];
$update = $this->update_avatar($avatar, $this->info['username']);
}
}
}
}
public function uploadImage()
{
if (isset($_FILES['file'])) {
$base = new Base();
$res = array();
$path = 'upload/question_images/';
$upload = $base->uploadImage($_FILES['file'],$path);
if($upload != false) {
$res['url'] = Config::APP_URL . $path . $upload;
$res['stt'] = true;
}
else
$res['stt'] = false;
echo json_encode($res);
}
}
public function delete_check_students()
{
$result = array();
Expand Down
2 changes: 1 addition & 1 deletion resource/controllers/controller_student.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function submit_update_avatar()
$duoi = explode('.', $_FILES['file']['name']);
$duoi = $duoi[(count($duoi)-1)];
if ($duoi === 'jpg' || $duoi === 'png') {
if (move_uploaded_file($_FILES['file']['tmp_name'], 'res/img/avatar/'.$this->info['username'].'_' . $_FILES['file']['name'])) {
if (move_uploaded_file($_FILES['file']['tmp_name'], 'upload/avatar/'.$this->info['username'].'_' . $_FILES['file']['name'])) {
$avatar = $this->info['username'] .'_' . $_FILES['file']['name'];
$update = $this->update_avatar($avatar, $this->info['username']);
}
Expand Down
2 changes: 1 addition & 1 deletion resource/controllers/controller_teacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function submit_update_avatar()
$duoi = explode('.', $_FILES['file']['name']);
$duoi = $duoi[(count($duoi)-1)];
if ($duoi === 'jpg' || $duoi === 'png') {
if (move_uploaded_file($_FILES['file']['tmp_name'], 'res/img/avatar/'.$this->info['username'].'_' . $_FILES['file']['name'])) {
if (move_uploaded_file($_FILES['file']['tmp_name'], 'upload/avatar/'.$this->info['username'].'_' . $_FILES['file']['name'])) {
$avatar = $this->info['username'] .'_' . $_FILES['file']['name'];
$update = $this->update_avatar($avatar, $this->info['username']);
}
Expand Down
46 changes: 46 additions & 0 deletions resource/core/Base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* Base Function
* @author: Nong Van Du (Dzu)
* Mail: [email protected]
**/

class Base
{
public function __construct()
{

}
public function uploadImage($file, $path)
{
$expl = explode('.', $file['name']);
$ext = $expl[(count($expl)-1)];
$name = $this->convertString($expl[0]);
$hash = md5(time());
if ($ext === 'jpg' || $ext === 'png' || $ext === 'jpeg') {
$new_name = $hash .'_' . $name . '.' . $ext;
if (move_uploaded_file($file['tmp_name'], $path . $new_name)) {
return $new_name;
} else {
return false;
}
}

}
public function convertString($str) {
$str = trim(mb_strtolower($str));
$str = preg_replace('/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/', 'a', $str);
$str = preg_replace('/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/', 'e', $str);
$str = preg_replace('/(ì|í|ị|ỉ|ĩ)/', 'i', $str);
$str = preg_replace('/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/', 'o', $str);
$str = preg_replace('/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/', 'u', $str);
$str = preg_replace('/(ỳ|ý|ỵ|ỷ|ỹ)/', 'y', $str);
$str = preg_replace('/(đ)/', 'd', $str);
$str = preg_replace('/[^a-z0-9-\s]/', '', $str);
$str = preg_replace('/([\s]+)/', '-', $str);
return $str;
}
}

?>
1 change: 1 addition & 0 deletions resource/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ function step_error()
echo "Tài khoản mặc định: <b>admin</b><br />";
echo "Mật khẩu: <b>123456</b> <br />";
echo "Vui lòng đăng nhập và đổi mật khẩu ngay sau khi đăng nhập. <br />";
echo "Sửa URL trang web trong config/config.php <br />";
echo 'Mọi thông tin chi tiết, hỗ trợ, góp ý, báo lỗi,<br />';
echo"vui lòng liên hệ <span class='pass'>[email protected]</span> hoặc trực tiếp trang chính thức sản phẩm <a href='https://github.com/meesudzu/trac-nghiem-online'>TẠI ĐÂY</a>
<br /><br />";
Expand Down
Binary file added resource/res/img/image_btn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions resource/res/js/add_question.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,47 @@ $(function() {
});
});

function upload_image() {
$('#uploading').removeClass('hidden');
var file_data = $('#file').prop('files')[0];
var type = file_data.type;
var size = file_data.size;
var match = ["image/png", "image/jpg", "image/jpeg"];
if ((type == match[0] && size < 2048000) || (type == match[1] && size < 2048000) || (type == match[2] && size < 2048000)) {
var form_data = new FormData();
form_data.append('file', file_data);
$.ajax({
url: 'index.php?action=uploadImage',
dataType: 'text',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function(result) {
var json_data = jQuery.parseJSON(result);
if(json_data.stt) {
$('#div-url').removeClass('hidden');
$('.help').css('color', 'green').text("Thành công");
$('#file').val('');
$('#url').val(json_data.url);
$('#uploading').addClass('hidden');
} else {
$('#div-url').addClass('hidden');
$('.help').css('color', 'red').text("Thất bại");
$('#file').val('');
$('#url').val('');
$('#uploading').addClass('hidden');
}
}
});
} else {
$('.help').css('color', 'red').text('Chỉ được upload file JPG, PNG nhỏ hơn 2mb');
$('#file').val('');
$('#uploading').addClass('hidden');
}
}

function submit_add_question(data) {
data[0]['value'] = CKEDITOR.instances.question_detail.getData();
data[1]['value'] = CKEDITOR.instances.answer_a.getData();
Expand Down
2 changes: 1 addition & 1 deletion resource/res/js/admins_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function show_list_admins(data) {
var tr = $('<tr class="fadeIn" id="admin-' + data[i].admin_id + '"></tr>');
tr.append('<td class=""><p><label><input type="checkbox" name="checkbox_students" class="checkbox" onchange="check_box();" value="' + data[i].admin_id + '" /><span></span></label></p></td>');
tr.append('<td class="">' + data[i].admin_id + '</td>');
tr.append('<td class=""><img src="res/img/avatar/' + data[i].avatar + '" alt="avatar" class="avatar" /></td>');
tr.append('<td class=""><img src="upload/avatar/' + data[i].avatar + '" alt="avatar" class="avatar" /></td>');
tr.append('<td class="">' + data[i].name + '</td>');
tr.append('<td class="">' + data[i].username + '</td>');
tr.append('<td class="">' + data[i].email + '</td>');
Expand Down
41 changes: 41 additions & 0 deletions resource/res/js/edit_question.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,45 @@ function submit_edit_question(data) {
$('#preload').addClass('hidden');
};
$.post(url, data, success);
}

function upload_image() {
$('#uploading').removeClass('hidden');
var file_data = $('#file').prop('files')[0];
var type = file_data.type;
var size = file_data.size;
var match = ["image/png", "image/jpg", "image/jpeg"];
if ((type == match[0] && size < 2048000) || (type == match[1] && size < 2048000) || (type == match[2] && size < 2048000)) {
var form_data = new FormData();
form_data.append('file', file_data);
$.ajax({
url: 'index.php?action=uploadImage',
dataType: 'text',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function(result) {
var json_data = jQuery.parseJSON(result);
if(json_data.stt) {
$('#div-url').removeClass('hidden');
$('.help').css('color', 'green').text("Thành công");
$('#file').val('');
$('#url').val(json_data.url);
$('#uploading').addClass('hidden');
} else {
$('#div-url').addClass('hidden');
$('.help').css('color', 'red').text("Thất bại");
$('#file').val('');
$('#url').val('');
$('#uploading').addClass('hidden');
}
}
});
} else {
$('.help').css('color', 'red').text('Chỉ được upload file JPG, PNG nhỏ hơn 2mb');
$('#file').val('');
$('#uploading').addClass('hidden');
}
}
8 changes: 7 additions & 1 deletion resource/res/js/questions_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ $(function() {
var instance = M.Modal.getInstance(elem);
instance.open();
});
$("form").on('submit', function(event) {
event.preventDefault();
});
});

function check_box() {
Expand Down Expand Up @@ -167,6 +170,9 @@ function get_list_questions() {
$('.modal').modal();
$('select').select();
$('body').attr('style', 'overflow: auto;');
$("form").on('submit', function(event) {
event.preventDefault();
});
}

function question_edit_button(data) {
Expand Down Expand Up @@ -196,4 +202,4 @@ function submit_del_question(data) {
$('#preload').addClass('hidden');
};
$.post(url, data, success);
}
}
8 changes: 7 additions & 1 deletion resource/res/js/students_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ $(function() {
var instance = M.Modal.getInstance(elem);
instance.open();
});
$("form").on('submit', function(event) {
event.preventDefault();
});
});

function check_box() {
Expand Down Expand Up @@ -142,7 +145,7 @@ function get_list_students() {
"targets":2,
"render": function(data)
{
return '<img src="res/img/avatar/' + data + '" alt="avatar" class="avatar" />';
return '<img src="upload/avatar/' + data + '" alt="avatar" class="avatar" />';
}
},
{
Expand Down Expand Up @@ -204,6 +207,9 @@ function get_list_students() {
$('.modal').modal();
$('select').select();
$('body').attr('style', 'overflow: auto;');
$("form").on('submit', function(event) {
event.preventDefault();
});
}

function student_edit_button(data) {
Expand Down
2 changes: 1 addition & 1 deletion resource/res/js/teachers_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function show_list_teachers(data) {
var tr = $('<tr class="fadeIn" id="teacher-' + data[i].teacher_id + '"></tr>');
tr.append('<td class=""><p><label><input type="checkbox" name="checkbox_students" class="checkbox" onchange="check_box();" value="' + data[i].teacher_id + '" /><span></span></label></p></td>');
tr.append('<td class="">' + data[i].teacher_id + '</td>');
tr.append('<td class=""><img src="res/img/avatar/' + data[i].avatar + '" alt="avatar" class="avatar" /></td>');
tr.append('<td class=""><img src="upload/avatar/' + data[i].avatar + '" alt="avatar" class="avatar" /></td>');
tr.append('<td class="">' + data[i].name + '</td>');
tr.append('<td class="">' + data[i].username + '</td>');
tr.append('<td class="">' + data[i].email + '</td>');
Expand Down
3 changes: 2 additions & 1 deletion resource/res/libs/ckeditor/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ CKEDITOR.editorConfig = function(config) {

// The default plugins included in the basic setup define some buttons that
// are not needed in a basic editor. They are removed here.
config.removeButtons = 'Cut,Copy,Paste,Undo,Redo,Anchor,Underline,Strike,Subscript,Superscript';
config.removeButtons = 'Anchor,Link,Unlink';

// Dialog windows are also simplified.
config.removeDialogTabs = 'link:advanced';
Expand All @@ -74,6 +74,7 @@ CKEDITOR.editorConfig = function(config) {
config.extraPlugins = 'floatpanel';
config.extraPlugins = 'panel';
config.extraPlugins = 'listblock';
config.extraPlugins = 'image';
config.entities_latin = false;
config.basicEntities = false;
config.entities = false;
Expand Down
Loading

0 comments on commit 2a9521b

Please sign in to comment.