diff --git a/html/exhibition/application/controllers/Project.php b/html/exhibition/application/controllers/Project.php index abea58f6dbd5a5b16bea9ac5f16c9dfe3ade85bd..6ca2df0b3a70b84cfa51df2a4f9badc316d781f3 100644 --- a/html/exhibition/application/controllers/Project.php +++ b/html/exhibition/application/controllers/Project.php @@ -90,6 +90,7 @@ class project extends Exhibition_Controller { public function insert_project(){ $data['message'] = true; $name = $this->input->post('name'); + $name_en = $this->input->post('name_en'); $year = $this->input->post('year'); $graduation = $this->input->post('graduation'); $company = $this->input->post('company'); @@ -124,11 +125,11 @@ class project extends Exhibition_Controller { if($data['message'] == true){ if($graduation == 2){ - $max_id = $this->project->insert_project_cluster($name, $year, $company, $select, $path.$image_logo, $path.$image_cover); + $max_id = $this->project->insert_project_cluster($name, $name_en, $year, $company, $select, $path.$image_logo, $path.$image_cover); }else if($graduation == 3){ - $max_id = $this->project->insert_project_team($name, $year, $company, $select, $path.$image_logo, $path.$image_cover); + $max_id = $this->project->insert_project_team($name, $name_en, $year, $company, $select, $path.$image_logo, $path.$image_cover); }else{ - $max_id = $this->project->insert_project_instructor($name, $year, $company, $select, $path.$image_logo, $path.$image_cover); + $max_id = $this->project->insert_project_instructor($name, $name_en, $year, $company, $select, $path.$image_logo, $path.$image_cover); } foreach ($tags as $tag){ @@ -209,6 +210,7 @@ class project extends Exhibition_Controller { $data['message'] = true; $id = $this->input->post('id'); $name = $this->input->post('name'); + $name_en = $this->input->post('name_en'); $year = $this->input->post('year'); $graduation = $this->input->post('graduation'); $company = $this->input->post('company'); @@ -239,11 +241,11 @@ class project extends Exhibition_Controller { } if($data['message'] == true){ if($graduation == 2){ - $this->project->update_project_cluster($name, $year, $company, $select, $path.$image_logo, $path.$image_cover, $id); + $this->project->update_project_cluster($name, $name_en, $year, $company, $select, $path.$image_logo, $path.$image_cover, $id); }else if($graduation == 3){ - $this->project->update_project_team($name, $year, $company, $select, $path.$image_logo, $path.$image_cover, $id); + $this->project->update_project_team($name, $name_en, $year, $company, $select, $path.$image_logo, $path.$image_cover, $id); }else{ - $this->project->update_project_instructor($name, $year, $company, $select, $path.$image_logo, $path.$image_cover, $id); + $this->project->update_project_instructor($name, $name_en, $year, $company, $select, $path.$image_logo, $path.$image_cover, $id); } $this->project_tag->delete_project_tag_by_id($id); foreach ($tags as $tag){ @@ -296,6 +298,23 @@ class project extends Exhibition_Controller { } echo json_encode($data); } + + function check_folder_exist(){ + $data['message'] = true; + $year = $this->input->post('year'); + $graduation = $this->input->post('graduation'); + $select_text = $this->input->post('select_text'); + $path_save_image = ''; + if($graduation != 4){ + $path_save_image = getcwd().'/project/year_'.$year.'/y'.$graduation.'/'.$select_text.'/'; + }else{ + $path_save_image = getcwd().'/project/year_'.$year.'/y'.$graduation.'/'.$_SESSION['student_id'].'/'; + } + if(file_exists($path_save_image)){ + $data['message'] = false; + } + echo json_encode($data); + } } diff --git a/html/exhibition/application/models/project/Da_project.php b/html/exhibition/application/models/project/Da_project.php index 1c89a6bfe2540562896ccdf01a29d1653de8aef7..95471e6e57b8fa3b613f9a94913c238385e8bb51 100644 --- a/html/exhibition/application/models/project/Da_project.php +++ b/html/exhibition/application/models/project/Da_project.php @@ -18,10 +18,11 @@ class Da_project extends Exhibition_Model $this->db->query($sql, [$status, $id]); } - public function insert_project_cluster($name, $year, $company, $select, $image_logo, $image_cover){ + public function insert_project_cluster($name, $name_en, $year, $company, $select, $image_logo, $image_cover){ $sql = "INSERT INTO {$this->db_name}.project ( - name, + name_th, + name_en, image_logo, image_cover, date, @@ -29,15 +30,16 @@ class Da_project extends Exhibition_Model company_id, cluster_id ) - VALUES (?,?,?,?,?,?,?);"; - $this->db->query($sql, [$name, $image_logo, $image_cover, $year, 1, $company, $select]); + VALUES (?,?,?,?,?,?,?,?);"; + $this->db->query($sql, [$name, $name_en, $image_logo, $image_cover, $year, 1, $company, $select]); return $this->db->insert_id(); } - public function insert_project_team($name, $year, $company, $select, $image_logo, $image_cover){ + public function insert_project_team($name, $name_en, $year, $company, $select, $image_logo, $image_cover){ $sql = "INSERT INTO {$this->db_name}.project ( - name, + name_th, + name_en, image_logo, image_cover, date, @@ -45,15 +47,16 @@ class Da_project extends Exhibition_Model company_id, team_id ) - VALUES (?,?,?,?,?,?,?);"; - $this->db->query($sql, [$name, $image_logo, $image_cover, $year, 1, $company, $select]); + VALUES (?,?,?,?,?,?,?,?);"; + $this->db->query($sql, [$name, $name_en, $image_logo, $image_cover, $year, 1, $company, $select]); return $this->db->insert_id(); } - public function insert_project_instructor($name, $year, $company, $select, $image_logo, $image_cover){ + public function insert_project_instructor($name, $name_en, $year, $company, $select, $image_logo, $image_cover){ $sql = "INSERT INTO {$this->db_name}.project ( - name, + name_th, + name_en, image_logo, image_cover, date, @@ -61,44 +64,47 @@ class Da_project extends Exhibition_Model company_id, instructor_id ) - VALUES (?,?,?,?,?,?,?);"; - $this->db->query($sql, [$name, $image_logo, $image_cover, $year, 1, $company, $select]); + VALUES (?,?,?,?,?,?,?,?);"; + $this->db->query($sql, [$name, $name_en, $image_logo, $image_cover, $year, 1, $company, $select]); return $this->db->insert_id(); } - public function update_project_cluster($name, $year, $company, $select, $image_logo, $image_cover, $id){ + public function update_project_cluster($name, $name_en, $year, $company, $select, $image_logo, $image_cover, $id){ $sql = "UPDATE {$this->db_name}.project - SET name = ? + SET name_th = ? + ,name_en = ? ,image_logo = ? ,image_cover = ? ,date = ? ,company_id = ? ,cluster_id = ? WHERE project_id = ?"; - $this->db->query($sql, [$name, $image_logo, $image_cover, $year, $company, $select, $id]); + $this->db->query($sql, [$name, $name_en, $image_logo, $image_cover, $year, $company, $select, $id]); } - public function update_project_team($name, $year, $company, $select, $image_logo, $image_cover, $id){ + public function update_project_team($name, $name_en, $year, $company, $select, $image_logo, $image_cover, $id){ $sql = "UPDATE {$this->db_name}.project - SET name = ? + SET name_th = ? + ,name_en = ? ,image_logo = ? ,image_cover = ? ,date = ? ,company_id = ? ,team_id = ? WHERE project_id = ?"; - $this->db->query($sql, [$name, $image_logo, $image_cover, $year, $company, $select, $id]); + $this->db->query($sql, [$name, $name_en, $image_logo, $image_cover, $year, $company, $select, $id]); } - public function update_project_instructor($name, $year, $company, $select, $image_logo, $image_cover, $id){ + public function update_project_instructor($name, $name_en, $year, $company, $select, $image_logo, $image_cover, $id){ $sql = "UPDATE {$this->db_name}.project - SET name = ? + SET name_th = ? + ,name_en = ? ,image_logo = ? ,image_cover = ? ,date = ? ,company_id = ? ,instructor_id = ? WHERE project_id = ?"; - $this->db->query($sql, [$name, $image_logo, $image_cover, $year, $company, $select, $id]); + $this->db->query($sql, [$name, $name_en, $image_logo, $image_cover, $year, $company, $select, $id]); } } diff --git a/html/exhibition/application/views/project/v_project_create.php b/html/exhibition/application/views/project/v_project_create.php index 2e2cac795365e0e5745fb1ba39ff2506f5e38737..37cfe210f2da84f1a8ae853c9bf51cc3be45454e 100644 --- a/html/exhibition/application/views/project/v_project_create.php +++ b/html/exhibition/application/views/project/v_project_create.php @@ -97,7 +97,7 @@ label{ <div class="col-md-3 required"> <div class="form-group has-success"> <label class="form-label">ปี </label> - <input type="text" class="form-control" name="datepicker" id="datepicker" /> + <input type="text" class="form-control" name="datepicker" id="datepicker" onchange="check_folder_exist()" /> </div> </div> <div class="col-md-3 required"> @@ -113,7 +113,7 @@ label{ <div class="col-md-6 required" id="cluster"> <div class="form-group"> <label class="form-label">มกุล </label> - <select class="form-control select-require" id="cluster_select"> + <select class="form-control select-require" id="cluster_select" onchange="check_folder_exist()"> <option value="" selected disabled>กรุณาเลือกมกุล</option> <?php foreach($clusters as $cluster){ ?> <option value="<?php echo $cluster->cluster_id ?>"><?php echo $cluster->name ?></option> @@ -124,7 +124,7 @@ label{ <div class="col-md-6 required" id="team"> <div class="form-group"> <label class="form-label">ทีม </label> - <select class="form-control select-require" id="team_select"> + <select class="form-control select-require" id="team_select" onchange="check_folder_exist()"> <option value="" selected disabled>กรุณาเลือกทีม</option> <?php foreach($teams as $team){ ?> <option value="<?php echo $team->team_id ?>"><?php echo $team->name ?></option> @@ -135,7 +135,7 @@ label{ <div class="col-md-6 required" id="instructor"> <div class="form-group"> <label class="form-label">อาจารย์ที่ปรึกษา </label> - <select class="form-control select-require" id="instructor_select"> + <select class="form-control select-require" id="instructor_select" onchange="check_folder_exist()"> <option value="" selected disabled>กรุณาเลือกอาจารย์ที่ปรึกษา</option> <?php foreach($instructors as $instructor){ ?> <option value="<?php echo $instructor->instructor_id ?>"><?php echo $instructor->name ?></option> @@ -144,6 +144,11 @@ label{ </div> </div> </div> + <div class="row p-t-20 center" style="display: none;" id="error_floder"> + <div class="col-md-12" style="text-align: center; color:red"> + ข้อมูลมกุลหรือทีมที่เลือกได้ถูกสร้างขึ้นมาแล้ว + </div> + </div> <div class="row p-t-20 center"> <div class="col-md-6 required"> <div class="form-group has-success"> @@ -179,7 +184,7 @@ label{ <div class="col-md-6"> <div class="form-group has-success"> <label class="form-label">ชื่อโปรเจกต์/โครงงาน/โครงการ (EN)</label> - <input type="text" class="form-control" id="project_name"> + <input type="text" class="form-control" id="project_name_en"> </div> </div> </div> @@ -689,6 +694,7 @@ function insert_projecct(){ let tags = []; tags = $('#muti').val(); let name = $('#project_name').val(); + let name_en = $('#project_name_en').val(); let select let select_text for(data of data_result){ @@ -741,6 +747,7 @@ function insert_projecct(){ url: "<?php echo site_url().'/Project/insert_project'; ?>", data: { 'name': name, + 'name_en': name_en, 'year': year, 'graduation': graduation, 'company': company, @@ -795,7 +802,7 @@ function cancel_create_project(){ } $("input[type=text]").focusout(function(){ - str = $(this).val().trim(); + str = $(this).val() if(str === ''){ $(this).attr('class','form-control is-invalid'); }else{ @@ -804,11 +811,66 @@ $("input[type=text]").focusout(function(){ }); $("select").focusout(function(){ - str = $(this).val().trim(); + str = $(this).val() if(str === ''){ $(this).attr('class','custom-select is-invalid'); }else{ $(this).removeClass('is-invalid'); } }); + +function check_folder_exist(){ + let year = $('#datepicker').val() + let graduation = $('#graduation').val() + let select + let select_text + if(graduation == 2){ + select = $('#cluster_select').val() + select_text = $("#cluster_select option:selected").text(); + }else if(graduation == 3){ + select = $('#team_select').val() + select_text = $("#team_select option:selected").text(); + }else if(graduation == 4){ + select =$('#instructor_select').val() + } + console.log(select) + if(year != '' && graduation != '' && select != null){ + $.ajax({ + type: 'post', + url: "<?php echo site_url().'/Project/check_folder_exist'; ?>", + data: { + 'year': year, + 'graduation': graduation, + 'select': select, + 'select_text': select_text, + }, + dataType: 'json', + success: function(data) { + if(data['message'] == false){ + document.getElementById('error_floder').style.display = 'block' + $('#datepicker').attr('class','form-control is-invalid'); + $('#graduation').attr('class','form-control is-invalid'); + if(graduation == 2){ + $('#cluster_select').attr('class','form-control is-invalid'); + }else if(graduation == 3){ + $('#team_select').attr('class','form-control is-invalid'); + }else if(graduation == 4){ + $('#instructor_select').attr('class','form-control is-invalid'); + } + }else{ + document.getElementById('error_floder').style.display = 'none' + $('#datepicker').removeClass('is-invalid'); + $('#graduation').removeClass('is-invalid'); + if(graduation == 2){ + $('#cluster_select').removeClass('is-invalid'); + }else if(graduation == 3){ + $('#team_select').removeClass('is-invalid'); + }else if(graduation == 4){ + $('#instructor_select').removeClass('is-invalid'); + } + } + } + }); + } +} </script> diff --git a/html/exhibition/application/views/project/v_project_edit.php b/html/exhibition/application/views/project/v_project_edit.php index ff301c20d255bd1d5fd2f4950591871699aba024..435858d959ef18a1fdafc79974485db6f2eb24a6 100644 --- a/html/exhibition/application/views/project/v_project_edit.php +++ b/html/exhibition/application/views/project/v_project_edit.php @@ -177,13 +177,13 @@ label{ <div class="col-md-6 required"> <div class="form-group has-success"> <label class="form-label">ชื่อโปรเจกต์/โครงงาน/โครงการ </label> - <input type="text" class="form-control" id="project_name" value="<?php echo $project->name ?>"> + <input type="text" class="form-control" id="project_name" value="<?php echo $project->name_th ?>"> </div> </div> <div class="col-md-6"> <div class="form-group has-success"> <label class="form-label">Project Name</label> - <input type="text" class="form-control" id="project_name" value="<?php echo $project->name ?>"> + <input type="text" class="form-control" id="project_name_en" value="<?php echo $project->name_en ?>"> </div> </div> </div> @@ -847,6 +847,7 @@ function update_projecct(){ let tags = []; tags = $('#muti').val(); let name = $('#project_name').val(); + let name_en = $('#project_name_en').val(); let select let select_text for(data of data_result){ @@ -899,6 +900,7 @@ function update_projecct(){ data: { 'id' : '<?php echo $project->project_id ?>', 'name': name, + 'name_en': name_en, 'year': year, 'graduation': graduation, 'company': company,