2025-04-22 03:10:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\PHP\Student;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use App\Models\PHP\TaskSubmission;
|
|
|
|
|
use App\Models\PHP\UserCheck;
|
|
|
|
|
|
|
|
|
|
class WelcomeController extends Controller
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
function result_add(){
|
|
|
|
|
$a = 2;
|
|
|
|
|
$b = 3;
|
|
|
|
|
echo $result = $a * $b;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function result_test(){
|
|
|
|
|
|
|
|
|
|
$uname = DB::select("SELECT * FROM users
|
|
|
|
|
WHERE name COLLATE utf8mb4_general_ci IN (SELECT userid FROM php_user_submits) ");
|
|
|
|
|
|
|
|
|
|
if (!empty($uname)) {
|
|
|
|
|
$firstUser = reset($uname); // Get the first element of the array
|
|
|
|
|
$sess_name = isset($firstUser->name) ? $firstUser->name : ''; // Access the 'name' property of the first user
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$task = DB::table('php_submits_submission')->where('username', "$sess_name")->first();
|
|
|
|
|
$username = $task->username;
|
|
|
|
|
$userfile = $task->userfile;
|
|
|
|
|
$ket = htmlspecialchars($task->ket);
|
|
|
|
|
$sql = DB::select("SELECT
|
|
|
|
|
*
|
|
|
|
|
FROM
|
|
|
|
|
php_submits_submission a
|
|
|
|
|
LEFT JOIN php_testing_rule b ON a.testing_type = b.testing_name
|
|
|
|
|
WHERE
|
|
|
|
|
a.username COLLATE utf8mb4_general_ci = '$username'
|
|
|
|
|
ORDER BY
|
|
|
|
|
a.id DESC
|
|
|
|
|
LIMIT 1;
|
|
|
|
|
|
|
|
|
|
");
|
|
|
|
|
$row = $sql[0];
|
2025-05-07 15:02:06 +00:00
|
|
|
$html2 = htmlspecialchars($row->ket);
|
2025-04-22 03:10:07 +00:00
|
|
|
$test = str_replace(array("\r\n","\r","\n"," "),"",$html2);
|
|
|
|
|
$result_content2 = str_replace(array("\r\n","\r"," "),"", $test);
|
2025-05-07 08:14:29 +00:00
|
|
|
|
2025-05-07 15:02:06 +00:00
|
|
|
|
2025-04-22 03:10:07 +00:00
|
|
|
|
|
|
|
|
/* $actual = storage_path("app/private/{$username}/{$userfile}");
|
|
|
|
|
$php_output = shell_exec("PHP $actual 2>&1");
|
|
|
|
|
$test = str_replace(array("\r\n","\r","\n"," "),"",highlight_string($php_output));
|
|
|
|
|
*/
|
|
|
|
|
return view('php.student.task.result_submssion_task',[
|
2025-05-07 15:02:06 +00:00
|
|
|
'result_up' => $html2,
|
2025-04-22 03:10:07 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// echo "$value == $sess_name";
|
|
|
|
|
|
2025-05-07 15:02:06 +00:00
|
|
|
}
|
|
|
|
|
function result_test_output(){
|
|
|
|
|
$uname = DB::select("SELECT * FROM users
|
|
|
|
|
WHERE name COLLATE utf8mb4_general_ci IN (SELECT userid FROM php_user_submits) ");
|
|
|
|
|
|
|
|
|
|
if (!empty($uname)) {
|
|
|
|
|
$firstUser = reset($uname); // Get the first element of the array
|
|
|
|
|
$sess_name = isset($firstUser->name) ? $firstUser->name : ''; // Access the 'name' property of the first user
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$task = DB::table('php_submits_submission')->where('username', "$sess_name")->first();
|
|
|
|
|
$username = $task->username;
|
|
|
|
|
|
|
|
|
|
$sql = DB::select("SELECT
|
|
|
|
|
*
|
|
|
|
|
FROM
|
|
|
|
|
php_submits_submission a
|
|
|
|
|
LEFT JOIN php_testing_rule b ON a.testing_type = b.testing_name
|
|
|
|
|
WHERE
|
|
|
|
|
a.username COLLATE utf8mb4_general_ci = '$username'
|
|
|
|
|
ORDER BY
|
|
|
|
|
a.id DESC
|
|
|
|
|
LIMIT 1;
|
|
|
|
|
|
|
|
|
|
");
|
|
|
|
|
$row = $sql[0];
|
|
|
|
|
$userfile = $row->userfile;
|
|
|
|
|
$ket = htmlspecialchars($row->ket);
|
|
|
|
|
$html2 = htmlspecialchars($row->output);
|
|
|
|
|
$test = str_replace(array("\r\n","\r","\n"," "),"",$html2);
|
|
|
|
|
$result_content2 = str_replace(array("\r\n","\r"," "),"", $test);
|
|
|
|
|
|
|
|
|
|
$studentFile = storage_path("app/public/uploads/$username/$userfile");
|
|
|
|
|
//$studentFile = storage_path("app/public/uploads/$val/GuideA1.php");
|
|
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
|
include ($studentFile);
|
|
|
|
|
$studentOutput = ob_get_clean();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$result_content = str_replace(array("\r\n", "\r", "\n", " "), "", $studentOutput);
|
|
|
|
|
|
|
|
|
|
return view('php.student.task.result_submssion_task', [
|
2025-05-08 00:47:00 +00:00
|
|
|
'result_up' => $studentOutput,
|
2025-05-07 15:02:06 +00:00
|
|
|
]);
|
|
|
|
|
ob_end_clean();
|
|
|
|
|
// echo "$value == $sess_name";
|
|
|
|
|
|
2025-04-22 03:10:07 +00:00
|
|
|
}
|
|
|
|
|
function get_session(){
|
|
|
|
|
if (Auth::check()) {
|
|
|
|
|
$value = Auth::user()->name;
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|