Advertisement
Guest User

Untitled

a guest
May 7th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.13 KB | None | 0 0
  1. <?php
  2. include('simple_html_dom.php');
  3.  
  4. $username = $_POST['username'];
  5. $password = $_POST['password'];
  6. $base_url = "https://studentportal.unpar.ac.id/";
  7. $login_url = "https://studentportal.unpar.ac.id/home/index.login.submit.php";
  8. $cas_login_url = "https://cas.unpar.ac.id/login?service=https%3A%2F%2Fstudentportal.unpar.ac.id%2Flogin.submit.php";
  9. $cas_url = "https://cas.unpar.ac.id";
  10.  
  11. $ch = curl_init();
  12.  
  13. /** GET TOKEN **/
  14. curl_setopt($ch, CURLOPT_URL, $login_url);
  15. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36");
  16. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  17. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  18. curl_setopt($ch, CURLINFO_HEADER_OUT, true);
  19. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  20. curl_setopt($ch, CURLOPT_POST, 1);
  21. curl_setopt($ch, CURLOPT_POSTFIELDS, "Submit=Login");
  22. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname( __FILE__ ) . '/cookie');
  23. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname( __FILE__ ) . '/cookiejar');
  24.  
  25. $output = curl_exec($ch);
  26. $html = str_get_html($output);
  27.  
  28. /** LOGIN CAS **/
  29. $action_url = $html->find("form", 0)->attr["action"];
  30. $lt = $html->find("input[name=lt]", 0)->attr["value"];
  31. $execution = $html->find("input[name=execution]", 0)->attr["value"];
  32. $eventId = $html->find("input[name=_eventId]", 0)->attr["value"];
  33.  
  34. $data = ("username=$username&password=$password&lt=$lt&execution=$execution&_eventId=$eventId");
  35.  
  36. // $ch = curl_init();
  37. curl_setopt($ch, CURLOPT_URL, $cas_url . $action_url);
  38. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36");
  39. curl_setopt($ch, CURLOPT_POST, 1);
  40. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  41. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  42. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  43. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname( __FILE__ ) . '/cookie');
  44. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname( __FILE__ ) . '/cookiejar');
  45. $output = curl_exec($ch);
  46. $home = str_get_html($output);
  47.  
  48. if($home->find("p[class=student-npm]") == null){
  49.     header("Location: index.php");
  50.     exit;
  51. }
  52.  
  53. $npm = $home->find("p[class=student-npm]", 0)->text();
  54. $npm = str_replace(" / AKTIF", "", $npm);
  55. $name = $home->find("p[class=student-name]", 0)->text();
  56. $semester = $home->find(".main-info-semester", 0)->text();
  57. $semester = str_replace(" : KULIAH", "", $semester);
  58. $photo_url = $home->find("img", 0)->src;
  59.  
  60. //ambil table jadwal yang sedang diambil semester tersebut
  61. $jadwal = $home->find("table[class=portal-full-table]", 0)->find("tr");
  62. $jadwal_kuliah = [];
  63. $countJadwal = 0;
  64.  
  65. for ($i=2; $i < count($jadwal); $i++) {
  66.     $jadwal_kuliah[$countJadwal] = [
  67.         "kode" => $jadwal[$i]->find("td", 1)->text(),
  68.         "matkul" => $jadwal[$i]->find("td", 2)->text(),
  69.         "sks" => $jadwal[$i]->find("td", 3)->text(),
  70.     ];
  71.     $countJadwal++;
  72. }
  73.  
  74. /** LOAD JADWAL **/
  75. // curl_setopt($ch, CURLOPT_URL, "https://studentportal.unpar.ac.id/includes/jadwal.aktif.php");
  76. // curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36");
  77. // $output = curl_exec($ch);
  78. // $html = str_get_html($output);
  79.  
  80. //POST https://studentportal.unpar.ac.id/includes/jadwal.kuliah.php
  81. //data: npm, thn_akd, sem_akd
  82. // $thn_akd_html = $html->find("select[id=tahun_akd_sec]");
  83. // $thn_akds = [];
  84. // foreach($thn_akd_html as $thn_akd_data){
  85. //     $thn_akds[] = [
  86. //         'thn_akd' => '',
  87. //         'sem_akd' => '',
  88. //     ];
  89. // }
  90.  
  91. /** GET URL SEMESTER LALU **/
  92. $data = "npm=$npm&thn_akd=2015&sem_akd=2";
  93. curl_setopt($ch, CURLOPT_URL, "https://studentportal.unpar.ac.id/includes/jadwal.kuliah.php");
  94. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36");
  95. curl_setopt($ch, CURLOPT_POST, 1);
  96. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  97. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  98. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  99. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname( __FILE__ ) . '/cookie');
  100. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname( __FILE__ ) . '/cookiejar');
  101. $output = curl_exec($ch);
  102. $html = str_get_html($output);
  103.  
  104. $kuliah_html = $html->find("table[class=portal-full-table]", 0)->find("tr");
  105. $senin = [];
  106. $selasa = [];
  107. $rabu = [];
  108. $kamis = [];
  109. $jumat = [];
  110. $sabtu = [];
  111. $ctsenin = 0;
  112. $ctselasa = 0;
  113. $ctrabu = 0;
  114. $ctkamis = 0;
  115. $ctjumat = 0;
  116. $ctsabtu = 0;
  117. for($i = 0; $i < count($kuliah_html)-1; $i++){
  118.     if($kuliah_html[$i]->find("td") != null){
  119.         $date = str_replace(".", ":", $kuliah_html[$i]->find("td", 8)->text());
  120.         $date = explode("-", $date);
  121.         if ($kuliah_html[$i]->find("td", 7)->text() == "Senin") {
  122.             $senin[$ctsenin] = [
  123.                 "kode" => $kuliah_html[$i]->find("td", 1)->text(),
  124.                 "matkul" => $kuliah_html[$i]->find("td", 2)->text(),
  125.                 "sks" => $kuliah_html[$i]->find("td", 3)->text(),
  126.                 "kelas" => $kuliah_html[$i]->find("td", 4)->text(),
  127.                 "dosen" => $kuliah_html[$i]->find("td", 5)->text(),
  128.                 "hari" => $kuliah_html[$i]->find("td", 7)->text(),
  129.                 "waktu" => $kuliah_html[$i]->find("td", 8)->text(),
  130.                 "ruang" => $kuliah_html[$i]->find("td", 9)->text(),
  131.             ];
  132.             $ctsenin++;
  133.         }
  134.     }
  135. }
  136. for($i = 2; $i < count($kuliah_html)-1; $i++){
  137.     if($kuliah_html[$i]->find("td") != null){
  138.         $date = str_replace(".", ":", $kuliah_html[$i]->find("td", 8)->text());
  139.         $date = explode("-", $date);
  140.         if ($kuliah_html[$i]->find("td", 7)->text() == "Selasa") {
  141.             $selasa[$ctselasa] = [
  142.                 "kode" => $kuliah_html[$i]->find("td", 1)->text(),
  143.                 "matkul" => $kuliah_html[$i]->find("td", 2)->text(),
  144.                 "sks" => $kuliah_html[$i]->find("td", 3)->text(),
  145.                 "kelas" => $kuliah_html[$i]->find("td", 4)->text(),
  146.                 "dosen" => $kuliah_html[$i]->find("td", 5)->text(),
  147.                 "hari" => $kuliah_html[$i]->find("td", 7)->text(),
  148.                 "waktu" => $kuliah_html[$i]->find("td", 8)->text(),
  149.                 "ruang" => $kuliah_html[$i]->find("td", 9)->text(),
  150.             ];
  151.             $ctselasa++;
  152.         }
  153.     }
  154. }
  155. ?>
  156.  
  157. <!DOCTYPE html>
  158. <html>
  159.     <head>
  160.         <meta charset="utf-8">
  161.         <title></title>
  162.         <link rel="stylesheet" href="bootstrap.css" charset="utf-8">
  163.         <link rel="stylesheet" href="custom.css" charset="utf-8">
  164.         <link rel="stylesheet" href="http://fullcalendar.io/js/fullcalendar-2.6.0/fullcalendar.css">
  165.     </head>
  166.     <body>
  167.         <div class="container-fluid content">
  168.             <div class="row">
  169.                 <div class="img-student col-xs-4">
  170.                     <?php echo "<img src=$base_url" . "$photo_url>"; ?>
  171.                 </div>
  172.                 <div class="col-xs-8">
  173.                     <?php
  174.                         echo "<h3>" . $name . "</h3>";
  175.                         echo "<h4>" . $npm . "</h4>";
  176.                         echo "<h5>" . $semester . "</h5>";
  177.                     ?>
  178.                 </div>
  179.             </div>
  180.             <div class="row">
  181.                 <div class="col-xs-12">
  182.                     <br>
  183.                     <?php
  184.                         echo "<table class='table table-striped table-condensed text-center'>";
  185.                             echo "<thead>";
  186.                                 echo "<th class='text-center'>Kode Matakuliah</th>";
  187.                                 echo "<th class='text-center'>Nama Matakuliah</th>";
  188.                                 echo "<th class='text-center'>Sks</th>";
  189.                             echo "</thead>";
  190.                             echo "<tbody>";
  191.                             for ($i=0; $i < count($jadwal_kuliah); $i++) {
  192.                                 echo "<tr>";
  193.                                     echo "<td>";
  194.                                         echo $jadwal_kuliah[$i]['kode'];
  195.                                     echo "</td>";
  196.                                     echo "<td>";
  197.                                         echo $jadwal_kuliah[$i]['matkul'];
  198.                                     echo "</td>";
  199.                                     echo "<td>";
  200.                                         echo $jadwal_kuliah[$i]['sks'];
  201.                                     echo "</td>";
  202.                                 echo "</tr>";
  203.                             }
  204.                             echo "</tbody>";
  205.                         echo "</table>";
  206.                     ?>
  207.                 </div>
  208.             </div>
  209.             <div class="row">
  210.                 <div class="col-xs-12">
  211.                     <?php
  212.                     echo $selasa;
  213.                         echo '<h3>Jadwal Kuliah</h3>';
  214.                         echo '<h5>Senin</h5>';
  215.                         echo "<table class='table table-striped table-condensed text-center'>";
  216.                             echo "<tbody>";
  217.                                 for ($i=0; $i < count($senin); $i++) {
  218.                                     echo "<tr>";
  219.                                         echo "<td>";
  220.                                              echo $senin[$i]['kode'];
  221.                                         echo "</td>";
  222.                                         echo "<td>";
  223.                                             echo $senin[$i]['matkul'];
  224.                                         echo "</td>";
  225.                                     echo "</tr>";
  226.                                 }
  227.                             echo "</tbody>";
  228.                         echo "</table>";
  229.                         echo '<h5>Selasa</h5>';
  230.                         echo "<table class='table table-striped table-condensed text-center'>";
  231.                             echo "<tbody>";
  232.                                 for ($i=0; $i < count($selasa); $i++) {
  233.                                     echo "<tr>";
  234.                                         echo "<td>";
  235.                                             echo $selasa[$i]['kode'];
  236.                                         echo "</td>";
  237.                                         echo "<td>";
  238.                                             echo $selasa[$i]['matkul'];
  239.                                         echo "</td>";
  240.                                         echo "<td>";
  241.                                             echo $selasa[$i]['sks'];
  242.                                         echo "</td>";
  243.                                     echo "</tr>";
  244.                                 }
  245.                             echo "</tbody>";
  246.                         echo "</table>";
  247.                     ?>
  248.                 </div>
  249.             </div>
  250.         </div>
  251.     </body>
  252.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
  253.     <!-- <script type="text/javascript" src="http://fullcalendar.io/js/fullcalendar-2.6.0/lib/moment.min.js"></script>
  254.     <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.6.1/fullcalendar.min.js"></script> -->
  255. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement