Advertisement
anandarifkiy

Untitled

Aug 7th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.51 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Homepage extends CI_Controller {
  5.  
  6. function __construct(){
  7. date_default_timezone_set('ASIA/JAKARTA');
  8. parent::__construct();
  9. $this->load->model(array('Peserta_model','Modul_model','Training_model','Materi_model','Quiz_model','Jawaban_model','Result_model'));
  10. $this->load->helper(array('form','url','file'));
  11. $this->load->library(array('pagination'));
  12.  
  13. if($this->uri->segment(2) != 'startquiz'){
  14. if($this->uri->segment(2) != 'submit'){
  15. if($this->session->userdata('quizend') != NULL){
  16. redirect(base_url('homepage/startquiz/'.$this->session->userdata('quizslug')));
  17. }
  18. }
  19. }
  20. }
  21.  
  22. function index()
  23. {
  24. $where = array(
  25. 'unique_code' => $this->session->userdata('unique_code')
  26. );
  27. if($this->session->userdata('status') == 'login'){
  28. $data = array(
  29. 'profile' => $this->Peserta_model->select_where($where)->result(),
  30. 'banner' => 'Welcome',
  31. 'course' => $this->Modul_model->select()->result(),
  32. 'content' => 'client/pages/v_dashboard'
  33. );
  34. $this->load->view('client/layout/wrapper',$data);
  35. }else{
  36. $data['course'] = $this->Modul_model->select()->result();
  37. $this->load->view('client/pages/v_homepage',$data);
  38. }
  39. }
  40.  
  41. function mycourses()
  42. {
  43. $where = array(
  44. 'unique_code' => $this->session->userdata('unique_code')
  45. );
  46.  
  47. $profile = $this->Peserta_model->select_where($where)->result();
  48. foreach ($profile as $p) {
  49. $id_peserta = $p->id_peserta;
  50. }
  51.  
  52. $mycourses = $this->Training_model->mycourses($id_peserta)->result();
  53.  
  54. if($this->session->userdata('status') == 'login'){
  55. $data = array(
  56. 'profile' => $profile,
  57. 'banner' => 'My Courses',
  58. 'course' => $mycourses,
  59. 'content' => 'client/pages/v_mycourses'
  60. );
  61. $this->load->view('client/layout/wrapper',$data);
  62. }else{
  63. $data['course'] = $this->Modul_model->select()->result();
  64. $this->load->view('client/pages/v_homepage',$data);
  65. }
  66. }
  67.  
  68. function contact(){
  69. $where = array(
  70. 'unique_code' => $this->session->userdata('unique_code')
  71. );
  72. if($this->session->userdata('status') == 'login'){
  73. $data['profile'] = $this->Peserta_model->select_where($where)->result();
  74. $this->load->view('client/pages/v_contact',$data);
  75. }else{
  76. $data['profile'] = FALSE;
  77. $this->load->view('client/pages/v_contact',$data);
  78. }
  79.  
  80. }
  81.  
  82. function login(){
  83. $email = $this->input->post('email');
  84. $password = $this->input->post('pass');
  85. $where = array(
  86. 'email' => $email,
  87. 'pass' => md5($password),
  88. 'status' => '1'
  89. );
  90. $cek = $this->Peserta_model->select_where($where)->num_rows();
  91.  
  92. if($cek > 0){
  93. $data['session'] = $this->Peserta_model->select_where($where)->result();
  94. foreach ($data['session'] as $s) {
  95. $unique_code = $s->unique_code;
  96. }
  97. $data_session = array(
  98. 'unique_code' => $unique_code,
  99. 'status' => "login"
  100. );
  101.  
  102. $this->session->set_userdata($data_session);
  103. redirect(base_url());
  104. }else{
  105. redirect(base_url());
  106. }
  107. }
  108.  
  109. function login2(){
  110. $id_modul = $this->input->post('id_modul');
  111. $function = $this->input->post('function');
  112. $email = $this->input->post('email');
  113. $password = $this->input->post('pass');
  114. $where = array(
  115. 'email' => $email,
  116. 'pass' => md5($password),
  117. 'status' => '1'
  118. );
  119. $cek = $this->Peserta_model->select_where($where)->num_rows();
  120.  
  121. if($cek > 0){
  122. $data['session'] = $this->Peserta_model->select_where($where)->result();
  123. foreach ($data['session'] as $s) {
  124. $unique_code = $s->unique_code;
  125. }
  126. $data_session = array(
  127. 'unique_code' => $unique_code,
  128. 'status' => "login"
  129. );
  130. $this->session->set_userdata($data_session);
  131. }
  132.  
  133. if(strlen($id_modul) == 150){
  134. redirect(base_url('homepage'));
  135. }elseif($function == 'startcourse'){
  136. redirect(base_url('homepage/startcourse/'.$id_modul));
  137. }elseif($function == 'joincourse'){
  138. redirect(base_url('homepage/joincourse/'.$id_modul));
  139. }
  140. }
  141.  
  142.  
  143. function logout(){
  144. $this->session->sess_destroy();
  145. redirect(base_url());
  146. }
  147.  
  148. function register(){
  149. $email = $this->input->post('email');
  150. $password = md5($this->input->post('password'));
  151. $namalengkap = $this->input->post('namalengkap');
  152. $gender = $this->input->post('gender');
  153. $tgl = $this->input->post('tgl');
  154. $alamat = $this->input->post('alamat');
  155. $telepon = $this->input->post('telepon');
  156. $tempatlahir = $this->input->post('tempatlahir');
  157.  
  158. $length = 150;
  159. $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  160. $charactersLength = strlen($characters);
  161. $unique_kode = '';
  162.  
  163. for ($i = 0; $i < $length; $i++) {
  164. $unique_kode .= $characters[rand(0, $charactersLength - 1)];
  165. }
  166.  
  167. $config['protocol'] = 'smtp';
  168. $config['smtp_host'] = 'ssl://smtp.googlemail.com';
  169. $config['smtp_port'] = 465;
  170. $config['mailtype'] = 'html';
  171. $config['smtp_user'] = 'ananda.rifkiy33@gmail.com';
  172. $config['smtp_pass'] = 'helloworld:)';
  173.  
  174. // Load email library and passing configured values to email library
  175. $this->load->library('email', $config);
  176. $this->email->set_newline("\r\n");
  177.  
  178. // Sender email address
  179. $this->email->from('ananda.rifkiy33@gmail.com', 'Ananda Rifkiy Hasan');
  180. // Receiver email address
  181. $this->email->to($email);
  182. // Subject of email
  183. $this->email->subject('Verification GTC EduSite');
  184. // Message in email
  185. $message = '<html>
  186. <link href="https://fonts.googleapis.com/css?family=Lato:700%7CMontserrat:400,600" rel="stylesheet">
  187. <body style="font-family:"Montserrat", sans-serif;">
  188. <center>
  189. <div style="border: 1px solid black;padding: 20px;border-radius: 10px">
  190. <h3>GTC EduSite</h3>
  191. <p>Terimakasih sudah mendaftar. Tinggal satu tahap lagi untuk mengakses akun anda.</p>
  192. <a href=http://localhost/gtclearning/homepage/verification/'.$unique_kode.'><button style="border:none;padding:12px 20px 12px 20px; background-color: green;color: white">Verifikasi Email</button></a>
  193. </div>
  194. </center>
  195. </body>
  196. </html>';
  197. $this->email->message($message);
  198.  
  199. if ($this->email->send()) {
  200. $data = array(
  201. 'email' => $email,
  202. 'pass' => $password,
  203. 'nama' => $namalengkap,
  204. 'gender' => $gender,
  205. 'tempatlahir' => $tempatlahir,
  206. 'ttl' => $tgl,
  207. 'alamat' => $alamat,
  208. 'telp' => $telepon,
  209. 'unique_code' => $unique_kode,
  210. 'status' => '0',
  211. 'img' => ''
  212. );
  213. $this->Peserta_model->input($data);
  214. redirect(base_url('homepage/success'));
  215. } else {
  216. $data['alert'] ='Gagal';
  217. }
  218.  
  219. }
  220.  
  221. function success(){
  222. $this->load->view('client/pages/v_verifikasi');
  223. }
  224.  
  225. function verification($code){
  226. $where = array(
  227. 'unique_code' => $code);
  228. $data = array(
  229. 'status' => '1');
  230. $this->Peserta_model->update($where,$data);
  231. $data['pesan'] = 'true';
  232. $this->load->view('client/pages/v_login',$data);
  233. }
  234.  
  235. function detailcourse($slug){
  236.  
  237. $where = array(
  238. 'unique_code' => $this->session->userdata('unique_code')
  239. );
  240. $profile = $this->Peserta_model->select_where($where)->result();
  241. foreach ($profile as $p) {
  242. $id_peserta = $p->id_peserta;
  243. }
  244.  
  245.  
  246. $where = array('slug' => $slug);
  247.  
  248. $modul = $this->Modul_model->select_where($where)->result();
  249.  
  250. foreach ($modul as $m) {
  251. $id_modul = $m->id_modul;
  252. }
  253.  
  254. $banner = $this->Modul_model->select_where($where)->row('nama');
  255.  
  256. $category = $this->Modul_model->select_where($where)->row('category');
  257.  
  258. $relatedcourse= $this->Modul_model->relatedcourse($category)->result();
  259.  
  260. if($this->session->userdata('status') == 'login'){
  261. $where = array(
  262. 'id_modul' => $id_modul,
  263. 'id_peserta' => $id_peserta);
  264.  
  265. $cekjoin = $this->Training_model->select_where($where)->num_rows();
  266. }else{
  267. $cekjoin = 0;
  268. }
  269. $data = array(
  270. 'profile' => $profile,
  271. 'banner' => $banner,
  272. 'modul' => $modul,
  273. 'cekjoin' => $cekjoin,
  274. 'related' => $relatedcourse,
  275. 'content' => 'client/pages/v_detailcourse'
  276. );
  277. $this->load->view('client/layout/wrapper',$data);
  278. }
  279.  
  280. function showregister(){
  281. $this->load->view('client/pages/v_register');
  282. }
  283.  
  284. function startcourse($slug){
  285. if($this->session->userdata('status') == 'login'){
  286. $where = array(
  287. 'unique_code' => $this->session->userdata('unique_code'));
  288. $profile = $this->Peserta_model->select_where($where)->result();
  289. $id_peserta = $this->Peserta_model->select_where($where)->row('id_peserta');
  290. $where = array(
  291. 'slug' => $slug);
  292.  
  293. $banner = $this->Modul_model->select_where($where)->row('nama');
  294. $course = $this->Modul_model->selectcourse($slug)->result();
  295. $where = 'test.id_test = result.id_test';
  296. $kondisi = 1;
  297. if($this->Modul_model->selectcourse($slug)->num_rows() > 0){
  298. foreach ($course as $c) {
  299. if($kondisi == 1){
  300. $x = 'and';
  301. }else{
  302. $x = 'or';
  303. }
  304. $where .= ' '.$x.' result.id_peserta = '.$id_peserta.' and test.id_materi = '.$c->id_materi;
  305. $kondisi++;
  306. }
  307. if($this->Result_model->join_test($where)->num_rows() == 0){
  308. $nilai = FALSE;
  309. }else{
  310. $nilai = $this->Result_model->join_test($where)->result();
  311. }
  312.  
  313. }else{
  314. $nilai = FALSE;
  315. }
  316.  
  317. $data = array(
  318. 'content' => 'client/pages/v_course',
  319. 'course' => $course,
  320. 'banner' => $banner,
  321. 'nilai' => $nilai,
  322. 'nilai2' => $nilai,
  323. 'profile' => $profile
  324. );
  325. $this->load->view('client/layout/wrapper',$data);
  326. }else{
  327. $this->load->view('client/pages/v_login');
  328. }
  329. }
  330.  
  331. function coursecatalog(){
  332. if($this->uri->segment(3) == ''){
  333. $category = 'all';
  334. }else{
  335. $category = $this->uri->segment(3);
  336. }
  337.  
  338. $limit_per_page = 4;
  339. if($this->uri->segment(4) == 0){
  340. $start_index = 0;
  341. }else{
  342. $start_index = $this->uri->segment(4) * 4 - 4;
  343. }
  344. $total_records = $this->Modul_model->countrow($category);
  345. if ($total_records > 0)
  346. {
  347. // get current page records
  348. $results = $this->Modul_model->get_current_page_records($category,$limit_per_page, $start_index)->result();
  349.  
  350. $config['base_url'] = base_url() . 'homepage/coursecatalog/'.$category;
  351. $config['total_rows'] = $total_records;
  352. $config['per_page'] = $limit_per_page;
  353. $config["uri_segment"] = 4;
  354. $config['num_links'] = 2;
  355. $config['use_page_numbers'] = TRUE;
  356. $config['reuse_query_string'] = TRUE;
  357.  
  358. $config['full_tag_open'] = '<nav><ul class="pagination" style="margin-top:0px">';
  359.  
  360. $config['full_tag_close'] = '</ul></nav>';
  361.  
  362. $config['first_link'] = 'First';
  363. $config['first_tag_open'] = '<li>';
  364. $config['first_tag_close'] = '</li>';
  365.  
  366. $config['last_link'] = 'Last';
  367. $config['last_tag_open'] = '<li>';
  368. $config['last_tag_close'] = '</li>';
  369.  
  370. $config['next_link'] = 'Next';
  371. $config['next_tag_open'] = '<li>';
  372. $config['next_tag_close'] = '</li>';
  373.  
  374. $config['prev_link'] = 'Prev';
  375. $config['prev_tag_open'] = '<li>';
  376. $config['prev_tag_close'] = '</li>';
  377.  
  378. $config['cur_tag_open'] = '<li class="active"><a style="border-color:#ff791f;background-color:#ff791f;">';
  379. $config['cur_tag_close'] = '</a></li>';
  380.  
  381. $config['num_tag_open'] = '<li>';
  382. $config['num_tag_close'] = '</li>';
  383.  
  384. $this->pagination->initialize($config);
  385. // build paging links
  386. $links = $this->pagination->create_links();
  387. }
  388.  
  389.  
  390. $where = array(
  391. 'unique_code' => $this->session->userdata('unique_code')
  392. );
  393. $profile = $this->Peserta_model->select_where($where)->result();
  394. $category = $this->Modul_model->selectcategory()->result();
  395. $recentpost= $this->Modul_model->recentpost($category)->result();
  396. $data = array(
  397. 'profile' => $profile,
  398. 'banner' => 'Course Catalog',
  399. 'results' => $results,
  400. 'links' => $links,
  401. 'category' => $category,
  402. 'recentpost'=> $recentpost,
  403. 'content' => 'client/pages/v_coursecatalog'
  404. );
  405. $this->load->view('client/layout/wrapper',$data);
  406. }
  407.  
  408. function showprofile(){
  409. $where = array(
  410. 'unique_code' => $this->session->userdata('unique_code')
  411. );
  412. $profile = $this->Peserta_model->select_where($where)->result();
  413. $category = $this->Modul_model->selectcategory()->result();
  414.  
  415. $data = array(
  416. 'profile' => $profile,
  417. 'banner' => 'Profile',
  418. 'content' => 'client/pages/v_profile'
  419. );
  420.  
  421. $this->load->view('client/layout/wrapper',$data);
  422. }
  423.  
  424. function editprofile($unique_code){
  425. $where = array(
  426. 'unique_code' => $this->session->userdata('unique_code')
  427. );
  428. $profile = $this->Peserta_model->select_where($where)->result();
  429. $data = array(
  430. 'profile' => $profile,
  431. 'banner' => 'Edit Profile',
  432. 'content' => 'Client/Pages/v_editprofile'
  433. );
  434. $this->load->view('client/layout/wrapper',$data);
  435. }
  436.  
  437. function updateprofile($unique_code){
  438. $id = $unique_code;
  439.  
  440. $data = array(
  441. 'nama' => $this->input->post('namalengkap'),
  442. 'gender' => $this->input->post('gender'),
  443. 'tempatlahir' => $this->input->post('tempatlahir'),
  444. 'ttl' => $this->input->post('tgl'),
  445. 'alamat' => $this->input->post('alamat'),
  446. 'telp' => $this->input->post('telepon'),
  447. 'kantor' => $this->input->post('kantor'),
  448. 'alamat_kantor' => $this->input->post('alamat_kantor'),
  449. 'telp_kantor' => $this->input->post('telepon_kantor'),
  450. 'biografi' => $this->input->post('biografi')
  451. );
  452.  
  453. $where = array('unique_code' => $id);
  454.  
  455. $this->Peserta_model->update($where,$data);
  456. redirect(base_url('homepage/showprofile'));
  457. }
  458.  
  459. function editphoto(){
  460. $status = '';
  461. if ($this->uri->segment(3) == 'failed'){
  462. $status = $this->uri->segment(3);
  463. }
  464. $where = array(
  465. 'unique_code' => $this->session->userdata('unique_code')
  466. );
  467. $content = array(
  468. 'title' => 'Profile',
  469. 'banner' => 'Edit Foto',
  470. 'status' => $status,
  471. 'content' => 'Client/Pages/v_editphotoprofile',
  472. 'profile' => $this->Peserta_model->select_where($where)->result());
  473. $this->load->view('Client/Layout/Wrapper',$content);
  474. }
  475.  
  476. function uploadphoto(){
  477. $nama = $this->input->post('code');
  478. $where = array( 'id_peserta' => $nama );
  479. $cekfoto = $this->Peserta_model->select_where($where)->result();
  480. foreach ($cekfoto as $c) {
  481. $hasil = $c->img;
  482. }
  483. if($hasil == ""){
  484. $config['upload_path'] = './assets/profile_photos/';
  485. $config['allowed_types'] = 'jpg|jpeg|png';
  486. $config['max_size'] = '2048';
  487. $config['max_width'] = '4048';
  488. $config['max_height'] = '4048';
  489. $config['file_name'] = $nama;
  490. $this->load->library('upload',$config);
  491. if(! $this->upload->do_upload('berkas')){
  492.  
  493. echo "error";
  494. }else{
  495. $gbr = $this->upload->data();
  496. $format = str_replace('image', '',$gbr['file_type']);
  497. $where = array('id_peserta' => $nama);
  498. $data = array(
  499. 'img' => $gbr['file_name']);
  500. $this->Peserta_model->insert_img($where,$data);
  501. redirect(base_url('homepage/showprofile'));
  502. }
  503. }else{
  504. unlink('./assets/profile_photos/'.$hasil);
  505. $config['upload_path'] = './assets/profile_photos/';
  506. $config['allowed_types'] = 'jpg|jpeg|png';
  507. $config['max_size'] = '2048';
  508. $config['max_width'] = '4048';
  509. $config['max_height'] = '4048';
  510. $config['file_name'] = $nama;
  511. $this->load->library('upload',$config);
  512. if(! $this->upload->do_upload('berkas')){
  513. $where = array('id_peserta' => $nama);
  514. $data = array(
  515. 'img' => '');
  516. $this->Peserta_model->insert_img($where,$data);
  517. redirect(base_url('homepage/editphoto/failed'));
  518. }else{
  519. $gbr = $this->upload->data();
  520. $format = str_replace('image', '',$gbr['file_type']);
  521. $where = array('id_peserta' => $nama);
  522. $data = array(
  523. 'img' => $gbr['file_name']);
  524. $this->Peserta_model->insert_img($where,$data);
  525. redirect(base_url('homepage/showprofile'));
  526. }
  527. }
  528. }
  529.  
  530. function joincourse($course){
  531. if($this->session->userdata('status') == 'login'){
  532. $peserta = $this->session->userdata('unique_code');
  533. $where = array('unique_code' => $peserta);
  534. $id_peserta = $this->Peserta_model->select_where($where)->row('id_peserta');
  535. $where = array('slug' => $course);
  536. $id_modul = $this->Modul_model->select_where($where)->row('id_modul');
  537. $where = array(
  538. 'id_modul' => $id_modul,
  539. 'id_peserta'=> $id_peserta
  540. );
  541. $cekjoin = $this->Training_model->select_where($where)->result();
  542. if($cekjoin == 1){
  543. redirect(base_url('homepage/startcourse/'.$course));
  544. }
  545.  
  546. $where = array(
  547. 'unique_code' => $peserta);
  548. $data = $this->Peserta_model->select_where($where)->result();
  549. foreach ($data as $peserta) {
  550. $id_peserta = $peserta->id_peserta;
  551. }
  552.  
  553. $where = array(
  554. 'slug' => $course);
  555. $data = $this->Modul_model->select_where($where)->result();
  556. if($this->Modul_model->select_where($where)->num_rows() == 0){
  557. redirect('homepage/coursecatalog/');
  558. }
  559. foreach ($data as $modul) {
  560. $id_modul = $modul->id_modul;
  561. }
  562. //generate codejoin
  563. $length = 30;
  564. $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  565. $charactersLength = strlen($characters);
  566. $unique_kode = '';
  567. for ($i = 0; $i < $length; $i++) {
  568. $unique_kode .= $characters[rand(0, $charactersLength - 1)];
  569. }
  570.  
  571. $data = array(
  572. 'id_modul' => $id_modul,
  573. 'id_peserta'=> $id_peserta,
  574. 'code' => $unique_kode);
  575. $this->Training_model->input($data);
  576. //data email
  577.  
  578. $where = array('id_modul' => $id_modul);
  579. $namamodul = $this->Modul_model->select_where($where)->row('nama'); //nama modul yang di join oleh peserta
  580. $where = array('id_peserta' => $id_peserta);
  581. $namapeserta= $this->Peserta_model->select_where($where)->row('nama'); //nama peserta yang join
  582. $where = array(
  583. 'modul.id_trainer = trainer.id_trainer and modul.slug =' => $course
  584. );
  585. $email = $this->Modul_model->join_trainer($where)->row('email'); //email trainer
  586. echo $email.$namapeserta.$namamodul;
  587.  
  588. $config['protocol'] = 'smtp';
  589. $config['smtp_host'] = 'ssl://smtp.googlemail.com';
  590. $config['smtp_port'] = 465;
  591. $config['mailtype'] = 'html';
  592. $config['smtp_user'] = 'ananda.rifkiy33@gmail.com';
  593. $config['smtp_pass'] = 'helloworld:)';
  594.  
  595. // Load email library and passing configured values to email library
  596. $this->load->library('email', $config);
  597. $this->email->set_newline("\r\n");
  598.  
  599. // Sender email address
  600. $this->email->from('ananda.rifkiy33@gmail.com', 'Ananda Rifkiy Hasan');
  601. // Receiver email address
  602. $this->email->to($email);
  603. // Subject of email
  604. $this->email->subject('Join Course');
  605. // Message in email
  606. $message = '<html>
  607. <link href="https://fonts.googleapis.com/css?family=Lato:700%7CMontserrat:400,600" rel="stylesheet">
  608. <body style="font-family:"Montserrat", sans-serif;">
  609. <center>
  610. <div style="border: 1px solid black;padding: 20px;border-radius: 10px">
  611. <h3>GTC EduSite</h3>
  612. <p><b>'.$namapeserta.'</b>. telah bergabung di course <b>'.$namamodul.'</b></p>
  613. <a href=http://localhost/gtclearning/trainer/detailpeserta/'.$unique_kode.'><button style="border:none;padding:12px 20px 12px 20px; background-color: green;color: white">View</button></a>
  614. </div>
  615. </center>
  616. </body>
  617. </html>';
  618. $this->email->message($message);
  619.  
  620. if ($this->email->send()) {
  621. redirect('homepage/startcourse/'.$course);
  622. }
  623. }else{
  624. $this->load->view('client/pages/v_login');
  625. }
  626. }
  627.  
  628. function quizoverview($slug){
  629. if($this->session->userdata('status') == 'login'){
  630. $where = array(
  631. 'unique_code' => $this->session->userdata('unique_code')
  632. );
  633. $profile = $this->Peserta_model->select_where($where)->result();
  634. $where = array(
  635. 'slug' => $slug);
  636. $id_materi = $this->Materi_model->select_where($where)->row('id_materi');
  637. $namamodul = $this->Materi_model->select_modul($id_materi)->row('namamodul');
  638. $where = array(
  639. 'id_materi' => $id_materi);
  640. $soal = $this->Quiz_model->select_where($where)->row('id_test');
  641. $quiz= $this->Quiz_model->cekquiz($id_materi);
  642.  
  643. $data = array(
  644. 'profile' => $profile,
  645. 'banner' => "Start Quiz",
  646. 'namamodul' => $namamodul,
  647. 'quiz' => $quiz,
  648. 'content' => 'client/pages/v_konfirmasiquiz'
  649. );
  650. $this->load->view('client/layout/wrapper',$data);
  651.  
  652.  
  653. }
  654. }
  655.  
  656. function startquiz($slug){
  657.  
  658. $where = array(
  659. 'unique_code' => $this->session->userdata('unique_code')
  660. );
  661. $profile = $this->Peserta_model->select_where($where)->result();
  662. $id_peserta = $this->Peserta_model->select_where($where)->row('id_peserta');
  663. $soal = $this->Quiz_model->getsoal($slug)->result();
  664. $where = array('slug' => $slug);
  665. $id_materi = $this->Materi_model->select_where($where)->row('id_materi');
  666. $where = array('id_materi' => $id_materi);
  667.  
  668. $id_test = $this->Quiz_model->select_where($where)->row('id_test'); //id_test
  669.  
  670. $where = array(
  671. 'id_test' => $id_test,
  672. 'id_peserta' => $id_peserta
  673. );
  674. if($this->Result_model->select_where($where)->num_rows() > 0){
  675. redirect(base_url());
  676. }
  677. $where = array('id_test' => $id_test);
  678. $waktu = $this->Quiz_model->select_where($where)->row('waktu');
  679.  
  680. //start session
  681. if($this->session->userdata('quizend') == ''){
  682. $newdata = array(
  683. 'quizslug' => $slug,
  684. 'quizend' => date('M j, Y H:i:s',strtotime('+'.$waktu.' minutes'))
  685. );
  686. $this->session->set_userdata($newdata);
  687. }
  688.  
  689.  
  690. $data = array(
  691. 'profile' => $profile,
  692. 'banner' => "Start Quiz",
  693. 'soal' => $soal,
  694. 'content' => 'client/pages/v_startquiz'
  695. );
  696. $this->load->view('client/layout/wrapper',$data);
  697. }
  698.  
  699. function submit(){
  700. $this->session->unset_userdata(array('quizslug','quizend'));
  701. $where = array(
  702. 'unique_code' => $this->session->userdata('unique_code')
  703. );
  704. $profile = $this->Peserta_model->select_where($where)->result();
  705. $id_peserta = $this->Peserta_model->select_where($where)->row('id_peserta'); //id_peserta
  706. $slug = $this->input->post('slug');
  707. $where = array('slug' => $slug);
  708. $id_materi = $this->Materi_model->select_where($where)->row('id_materi');
  709. $where = array('id_materi' => $id_materi);
  710.  
  711. $id_test = $this->Quiz_model->select_where($where)->row('id_test'); //id_test
  712.  
  713. $length = 15;
  714. $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  715. $charactersLength = strlen($characters);
  716. $unique_kode = '';
  717.  
  718. for ($i = 0; $i < $length; $i++) {
  719. $unique_kode .= $characters[rand(0, $charactersLength - 1)]; //code
  720. }
  721.  
  722. $data = array(
  723. 'id_test' => $id_test,
  724. 'id_peserta' => $id_peserta,
  725. 'code' => $unique_kode
  726. );
  727.  
  728. $this->Result_model->input($data);
  729. $where = array(
  730. 'id_test' => $id_test,
  731. 'id_peserta'=> $id_peserta
  732. );
  733. $id_result = $this->Result_model->select_where($where)->row('id_result');
  734.  
  735. $soal = $this->Quiz_model->getsoal($slug)->result();
  736. foreach ($soal as $s) {
  737. $data = array(
  738. 'id_result' => $id_result,
  739. 'id_soal' => $s->id_soal,
  740. 'jawaban' => $this->input->post('jawaban'.$s->id_soal)
  741. );
  742. $this->Jawaban_model->input($data);
  743. }
  744. redirect(base_url('homepage/quizresult'));
  745. }
  746.  
  747. function quizresult(){
  748. $where = array(
  749. 'unique_code' => $this->session->userdata('unique_code')
  750. );
  751. $profile = $this->Peserta_model->select_where($where)->result();
  752. $data = array(
  753. 'profile' => $profile,
  754. 'banner' => 'Result',
  755. 'content' => 'client/pages/v_xquiz'
  756. );
  757. $this->load->view('client/layout/wrapper',$data);
  758. }
  759.  
  760. function time(){
  761.  
  762.  
  763.  
  764. $this->session->set_userdata($newdata);
  765. echo $this->session->userdata('quizend');
  766. }
  767. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement