diff --git a/html/exhi/application/controllers/General.php b/html/exhi/application/controllers/General.php index 67af59ae09aed4b64f8070af591b27f86574f6cb..afb32866eb727ad8da3bc16902d65f57826b98bd 100644 --- a/html/exhi/application/controllers/General.php +++ b/html/exhi/application/controllers/General.php @@ -41,6 +41,13 @@ class general extends Exhibition_Controller echo json_encode($data); } + public function get_trend() + { + $this->load->model('general/M_general', 'trend'); + $data['trend'] = $this->trend->get_trend()->result(); + echo json_encode($data); + } + public function get_project_2() { $year = $_GET['year']; diff --git a/html/exhi/application/controllers/Login.php b/html/exhi/application/controllers/Login.php index 47d438495f048108e306c5cdf561566da28954a6..07da0776f92ce7c13f633a8bb00aee5ab3547c8b 100644 --- a/html/exhi/application/controllers/Login.php +++ b/html/exhi/application/controllers/Login.php @@ -1,23 +1,24 @@ <?php -defined('BASEPATH') OR exit('No direct script access allowed'); +defined('BASEPATH') or exit('No direct script access allowed'); require_once dirname(__FILE__) . '/Exhibition_Controller.php'; -use Google\Client as GoogleClient; +use Google\Client as GoogleClient; use Google\Service\Oauth2; -class Login extends Exhibition_Controller { +class Login extends Exhibition_Controller +{ - public function logout() + public function logout() { session_unset(); redirect('login/show_login'); } - public function show_login() + public function show_login() { - $this->output('login/v_login'); + // $this->output('login/v_login'); } public function show_login_fail() @@ -25,75 +26,71 @@ class Login extends Exhibition_Controller { $this->output('login/v_login_fail'); } - public function check_login() + public function check_login() { $data['message'] = false; - $email = $this->input->post('email'); - $password = $this->input->post('password'); - if(strlen($password) > 1){ + $email = $this->input->post('email'); + $password = $this->input->post('password'); + if (strlen($password) > 1) { $this->load->model('user/M_user', 'user'); $user = $this->user->check_login($email, md5($password))->result(); if (count($user) == 1) { - $_SESSION['first_name'] = $user[0]->first_name; - $_SESSION['last_name'] = $user[0]->last_name; - $_SESSION['email'] = $user[0]->email; - $_SESSION['user_id'] = $user[0]->user_id; - $_SESSION['role'] = $user[0]->role; - if($user[0]->role == 1){ - $data['type'] = 1; - } - else if($user[0]->role == 2){ - $data['type'] = 2; - } + $_SESSION['first_name'] = $user[0]->first_name; + $_SESSION['last_name'] = $user[0]->last_name; + $_SESSION['email'] = $user[0]->email; + $_SESSION['user_id'] = $user[0]->user_id; + $_SESSION['role'] = $user[0]->role; + if ($user[0]->role == 1) { + $data['type'] = 1; + } else if ($user[0]->role == 2) { + $data['type'] = 2; + } $data['message'] = true; } } - echo json_encode($data); + echo json_encode($data); } - public function login_google(){ + public function login_google() + { $client = new GoogleClient(); - $client->setApplicationName('Online Exhibition'); - $client->setClientId('916442378358-fd6q5fubouldl7mghapjqsf5cnoh6lvg.apps.googleusercontent.com'); - $client->setClientSecret('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'); - $client->setRedirectUri('http://localhost/exhi/index.php/Login/login_google'); - $client->addScope(['https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile']); - if($code = $this->input->get('code')){ - $token = $client->fetchAccessTokenWithAuthCode($code); - $client->setAccessToken($token); - $oauth = new Oauth2($client); - $user_info = $oauth->userinfo->get(); - $data['name'] = $user_info->name; - $data['email'] = $user_info->email; - $data['image'] = $user_info->picture; - $this->load->model('user/M_user', 'user'); - $data['message'] = true; - if($user = $this->user->get_user_by_email($user_info->email)->row()){ - $_SESSION['first_name'] = $user->first_name; - $_SESSION['last_name'] = $user->last_name; - $_SESSION['email'] = $user->email; - $_SESSION['user_id'] = $user->user_id; - $_SESSION['role'] = $user->role; - $_SESSION['student_id'] = $user->student_id; - if($user->role == 1){ - $data['type'] = 1; - redirect('Project/show_project_manage_user'); - }else if($user->role == 2){ - $data['type'] = 2; - redirect('User/show_user_manage'); - } - }else{ - $data['message'] = false; - redirect('login/show_login_fail'); + $client->setApplicationName('Online Exhibition'); + $client->setClientId('916442378358-fd6q5fubouldl7mghapjqsf5cnoh6lvg.apps.googleusercontent.com'); + $client->setClientSecret('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'); + $client->setRedirectUri('http://localhost/exhi/index.php/Login/login_google'); + $client->addScope(['https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile']); + if ($code = $this->input->get('code')) { + $token = $client->fetchAccessTokenWithAuthCode($code); + $client->setAccessToken($token); + $oauth = new Oauth2($client); + $user_info = $oauth->userinfo->get(); + $data['name'] = $user_info->name; + $data['email'] = $user_info->email; + $data['image'] = $user_info->picture; + $this->load->model('user/M_user', 'user'); + $data['message'] = true; + if ($user = $this->user->get_user_by_email($user_info->email)->row()) { + $_SESSION['first_name'] = $user->first_name; + $_SESSION['last_name'] = $user->last_name; + $_SESSION['email'] = $user->email; + $_SESSION['user_id'] = $user->user_id; + $_SESSION['role'] = $user->role; + $_SESSION['student_id'] = $user->student_id; + if ($user->role == 1) { + $data['type'] = 1; + redirect('Project/show_project_manage_user'); + } else if ($user->role == 2) { + $data['type'] = 2; + redirect('User/show_user_manage'); } - - }else{ - $url = $client->createAuthUrl(); - header('Location:'.filter_var($url,FILTER_SANITIZE_URL)); + } else { + $data['message'] = false; + redirect('login/show_login_fail'); } + } else { + $url = $client->createAuthUrl(); + header('Location:' . filter_var($url, FILTER_SANITIZE_URL)); + } } } - - - diff --git a/html/exhi/application/models/general/M_general.php b/html/exhi/application/models/general/M_general.php index 431bf5818f1b420fec752a0516d8d440f31e1e27..9aa210b005f65ba98dce08ad939d4c774f440090 100644 --- a/html/exhi/application/models/general/M_general.php +++ b/html/exhi/application/models/general/M_general.php @@ -16,10 +16,17 @@ class M_general extends Da_general { $sql = "SELECT (SELECT COUNT(project_id) FROM project WHERE status = 1) AS all_project, - (SELECT COUNT(project_id) FROM project WHERE status = 1 AND date = 2022) AS by_year, - (SELECT COUNT(project_id) FROM project WHERE status = 1 AND cluster_id != 0 AND date = 2022) AS cluster, - (SELECT COUNT(project_id) FROM project WHERE status = 1 AND team_id != 0 AND date = 2022) AS team, - (SELECT COUNT(project_id) FROM project WHERE status = 1 AND team_id = 0 AND cluster_id = 0 AND date = 2022) AS project;"; + (SELECT COUNT(project_id) FROM project WHERE status = 1 AND date = $year) AS by_year, + (SELECT COUNT(project_id) FROM project WHERE status = 1 AND cluster_id != 0 AND date = $year) AS cluster, + (SELECT COUNT(project_id) FROM project WHERE status = 1 AND team_id != 0 AND date = $year) AS team, + (SELECT COUNT(project_id) FROM project WHERE status = 1 AND team_id = 0 AND cluster_id = 0 AND date = $year) AS project;"; + $query = $this->db->query($sql); + return $query; + } + + public function get_trend() + { + $sql = "SELECT * FROM project ORDER BY project_id DESC LIMIT 4"; $query = $this->db->query($sql); return $query; } diff --git a/html/exhi/application/views/general/v_general_home.php b/html/exhi/application/views/general/v_general_home.php index 6e742a31572269fba6cefb3f555eb268a043ae5d..3330ea03e2e597f1d5e23985996dc112c7c2422c 100644 --- a/html/exhi/application/views/general/v_general_home.php +++ b/html/exhi/application/views/general/v_general_home.php @@ -243,6 +243,11 @@ </select> <br><br> </div> + <div> + <h5><b>ผลงานที่เพิ่มล่าสุด</b></h5> + </div> + <div class="row" id="trend"> + </div> <div class="row justify-content-center"> <div class="col-12 col-sm-6 col-md-3"> <div class="info-box"> @@ -444,6 +449,7 @@ <script> $(document).ready(function() { get_project_year(); + get_trend(); $("#muti").select2().select2() var year = document.getElementById("year").value; $('#project_2').attr('href', '<?php echo site_url() . "/General/show_project_2" ?>?y=' + year); @@ -509,6 +515,42 @@ }) } + function get_trend() { + $.ajax({ + type: 'get', + url: "<?php echo site_url() . '/General/get_trend'; ?>", + data: {}, + dataType: 'json', + success: function(data) { + console.log(data) + create_trend(data.trend) + } + }) + } + + function create_trend(data) { + let html = ''; + data.forEach((row, index) => { + html += `<a href="<?php echo site_url() . '/General/show_select/' ?>` + row.project_id + `" class="col-md-3">`; + html += `<div class="card card-widget widget-user">`; + html += `<div class="widget-user-header text-white" style="background: url('<?php echo base_url() ?>` + row.image_cover + `') center center;">`; + html += `</div>`; + html += `<div class="widget-user-image">`; + html += `<img class="img-circle" src="<?php echo base_url() ?>` + row.image_logo + `" alt="User Avatar">`; + html += `</div>`; + html += `<div class="card-body">`; + html += `<h5 class="description-header"><b>` + row.pj_name + `</b></h5><br>`; + html += `<div class="description-block">`; + html += `<h5 class="description-header">` + row.first_name + ' ' + row.last_name + `</h5>`; + html += `<h5 class="description-header">` + row.student_id + `</h5>`; + html += `</div>`; + html += `</div>`; + html += `</div>`; + html += `</a>`; + }) + document.getElementById('trend').innerHTML = html; + } + function create_num_product(data, year) { let thai_year = parseInt(year) + 543; let selectDiv_2 = document.querySelector('#num_project_2') diff --git a/html/exhi/application/views/general/v_project_2.php b/html/exhi/application/views/general/v_project_2.php index ee6d5ee53a80d306d963fb3ab41dfa46b43a888c..22908dd516e6ac7c812e49f258c25e6ab944b066 100644 --- a/html/exhi/application/views/general/v_project_2.php +++ b/html/exhi/application/views/general/v_project_2.php @@ -113,9 +113,9 @@ let html = ''; data.forEach((row, index) => { - html += `<a href="<?php echo site_url() . '/General/show_project_2?' ?> ` + row.project_id + `" class="col-md-4">`; + html += `<a href="<?php echo site_url() . '/General/show_select/' ?>` + row.project_id + `" target="_blank" class="col-md-4">`; html += `<div class="info-box mb-3">`; - html += `<span class="info-box-icon bg-info elevation-1"><img src=""></img></span>`; + html += `<span class="info-box-icon bg-info elevation-1"><img src="<?php echo base_url() ?>` + row.image_logo + `""></img></span>`; html += `<div class="info-box-content">`; html += `<span class="info-box-text">` + row.ct_name + `</span>`; html += `<span class="info-box-text">` + row.pj_name + `</span>`; diff --git a/html/exhi/application/views/general/v_project_3.php b/html/exhi/application/views/general/v_project_3.php index 523e5218313d109c7975eb30d018e19e55eaa3b3..c9cbd49c04284dabdc5fa0cc4aeff658aa9394ef 100644 --- a/html/exhi/application/views/general/v_project_3.php +++ b/html/exhi/application/views/general/v_project_3.php @@ -101,9 +101,9 @@ let html = ''; data.forEach((row, index) => { - html += `<a href="<?php echo site_url() . '/General/show_project_2?' ?> ` + row.project_id + `" class="col-md-4">`; + html += `<a href="<?php echo site_url() . '/General/show_select/' ?>` + row.project_id + `" target="_blank" class="col-md-4">`; html += `<div class="info-box mb-3">`; - html += `<span class="info-box-icon bg-info elevation-1"><img src=""></img></span>`; + html += `<span class="info-box-icon bg-info elevation-1"><img src="<?php echo base_url() ?>` + row.image_logo + `"></img></span>`; html += `<div class="info-box-content">`; html += `<span class="info-box-text">` + row.t_name + `</span>`; html += `<span class="info-box-text">` + row.pj_name + `</span>`; diff --git a/html/exhi/application/views/general/v_project_4.php b/html/exhi/application/views/general/v_project_4.php index 9bdf7a893f75a9e37c057fcf3ba051dc11c2d71d..d963ac310c51d1cacd667736a6091032a15a8432 100644 --- a/html/exhi/application/views/general/v_project_4.php +++ b/html/exhi/application/views/general/v_project_4.php @@ -170,12 +170,12 @@ function create_project(data) { let html = ''; data.forEach((row, index) => { - html += `<a href="<?php echo site_url() . '/General/show_project_4' ?>" class="col-md-2">`; + html += `<a href="<?php echo site_url() . '/General/show_select/' ?>` + row.project_id + `" target="_blank" class="col-md-2">`; html += `<div class="card card-widget widget-user">`; - html += `<div class="widget-user-header text-white" style="background: url('` + row.image_cover + `') center center;">`; + html += `<div class="widget-user-header text-white" style="background: url('<?php echo base_url() ?>` + row.image_cover + `') center center;">`; html += `</div>`; html += `<div class="widget-user-image">`; - html += `<img class="img-circle" src="` + row.image_logo + `" alt="User Avatar">`; + html += `<img class="img-circle" src="<?php echo base_url() ?>` + row.image_logo + `" alt="User Avatar">`; html += `</div>`; html += `<div class="card-body">`; html += `<h5 class="description-header"><b>` + row.pj_name + `</b></h5><br>`;