Advertisement
Guest User

Untitled

a guest
Apr 9th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.09 KB | None | 0 0
  1. <?php
  2. include('simple_html_dom.php');
  3.  
  4. $username = $_POST['username'];
  5. $password = $_POST['password'];
  6. $login_url = "https://studentportal.unpar.ac.id/home/index.login.submit.php";
  7. $cas_login_url = "https://cas.unpar.ac.id/login?service=https%3A%2F%2Fstudentportal.unpar.ac.id%2Flogin.submit.php";
  8. $cas_url = "https://cas.unpar.ac.id";
  9.  
  10. $ch = curl_init();
  11.  
  12. /** GET TOKEN **/
  13. curl_setopt($ch, CURLOPT_URL, $login_url);
  14. 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");
  15. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  16. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  17. curl_setopt($ch, CURLINFO_HEADER_OUT, true);
  18. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  19. curl_setopt($ch, CURLOPT_POST, 1);
  20. curl_setopt($ch, CURLOPT_POSTFIELDS, "Submit=Login");
  21. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname( __FILE__ ) . '/cookie');
  22. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname( __FILE__ ) . '/cookiejar');
  23.  
  24. $output = curl_exec($ch);
  25. $html = str_get_html($output);
  26.  
  27. /** LOGIN CAS **/
  28. $action_url = $html->find("form", 0)->attr["action"];
  29. $lt = $html->find("input[name=lt]", 0)->attr["value"];
  30. $execution = $html->find("input[name=execution]", 0)->attr["value"];
  31. $eventId = $html->find("input[name=_eventId]", 0)->attr["value"];
  32.  
  33. $data = ("username=$username&password=$password&lt=$lt&execution=$execution&_eventId=$eventId");
  34.  
  35. // $ch = curl_init();
  36. curl_setopt($ch, CURLOPT_URL, $cas_url . $action_url);
  37. 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");
  38. curl_setopt($ch, CURLOPT_POST, 1);
  39. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  40. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  41. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  42. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname( __FILE__ ) . '/cookie');
  43. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname( __FILE__ ) . '/cookiejar');
  44. $output = curl_exec($ch);
  45. $html = str_get_html($output);
  46.  
  47. if($html->find("p[class=student-npm]") == null){
  48. header("Location: index.php");
  49. exit;
  50. }
  51.  
  52. $npm = $html->find("p[class=student-npm]", 0)->text();
  53. $npm = str_replace(" / AKTIF", "", $npm); //20123730007 / AKTIF
  54.  
  55. /** LOAD JADWAL **/
  56. // curl_setopt($ch, CURLOPT_URL, "https://studentportal.unpar.ac.id/includes/jadwal.aktif.php");
  57. // 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");
  58. // $output = curl_exec($ch);
  59. // $html = str_get_html($output);
  60.  
  61. //POST https://studentportal.unpar.ac.id/includes/jadwal.kuliah.php
  62. //data: npm, thn_akd, sem_akd
  63. // $thn_akd_html = $html->find("select[id=tahun_akd_sec]");
  64. // $thn_akds = [];
  65. // foreach($thn_akd_html as $thn_akd_data){
  66. // $thn_akds[] = [
  67. // 'thn_akd' => '',
  68. // 'sem_akd' => '',
  69. // ];
  70. // }
  71.  
  72. /** GET URL SEMESTER LALU **/
  73. $data = "npm=$npm&thn_akd=2015&sem_akd=2";
  74. curl_setopt($ch, CURLOPT_URL, "https://studentportal.unpar.ac.id/includes/jadwal.kuliah.php");
  75. 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");
  76. curl_setopt($ch, CURLOPT_POST, 1);
  77. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  78. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  79. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  80. curl_setopt($ch, CURLOPT_COOKIEFILE, dirname( __FILE__ ) . '/cookie');
  81. curl_setopt($ch, CURLOPT_COOKIEJAR, dirname( __FILE__ ) . '/cookiejar');
  82. $output = curl_exec($ch);
  83. $html = str_get_html($output);
  84.  
  85. $kuliah_html = $html->find("table[class=portal-full-table]", 0)->find("tr");
  86. $kuliah = [];
  87. $ct = 0;
  88. for($i = 2; $i < count($kuliah_html)-1; $i++){
  89. if($kuliah_html[$i]->find("td") != null){
  90. $date = str_replace(".", ":", $kuliah_html[$i]->find("td", 8)->text());
  91. $date = explode("-", $date);
  92. $kuliah[$ct] = [
  93. "kode" => $kuliah_html[$i]->find("td", 1)->text(),
  94. "matkul" => $kuliah_html[$i]->find("td", 2)->text(),
  95. "sks" => $kuliah_html[$i]->find("td", 3)->text(),
  96. "kelas" => $kuliah_html[$i]->find("td", 4)->text(),
  97. "dosen" => $kuliah_html[$i]->find("td", 5)->text(),
  98. "hari" => $kuliah_html[$i]->find("td", 7)->text(),
  99. "waktu" => $kuliah_html[$i]->find("td", 8)->text(),
  100. "ruang" => $kuliah_html[$i]->find("td", 9)->text(),
  101. ];
  102. if($kuliah[$ct]["kode"] == ""){
  103. $kuliah[$ct]["kode"] = $kuliah[$ct - 1]["kode"];
  104. }
  105. if($kuliah[$ct]["matkul"] == ""){
  106. $kuliah[$ct]["matkul"] = $kuliah[$ct - 1]["matkul"];
  107. }
  108. $kuliah[$ct]["title"] = $kuliah[$ct]["matkul"];
  109. switch($kuliah_html[$i]->find("td", 7)->text()){
  110. case "Senin":
  111. $kuliah[$ct]["start"] = "2016-02-08T$date[0]:00";
  112. $kuliah[$ct]["end"] = "2016-02-08T$date[1]:00";
  113. break;
  114. case "Selasa":
  115. $kuliah[$ct]["start"] = "2016-02-09T$date[0]:00";
  116. $kuliah[$ct]["end"] = "2016-02-09T$date[1]:00";
  117. break;
  118. case "Rabu":
  119. $kuliah[$ct]["start"] = "2016-02-10T$date[0]:00";
  120. $kuliah[$ct]["end"] = "2016-02-10T$date[1]:00";
  121. break;
  122. case "Kamis":
  123. $kuliah[$ct]["start"] = "2016-02-11T$date[0]:00";
  124. $kuliah[$ct]["end"] = "2016-02-11T$date[1]:00";
  125. break;
  126. case "Jumat":
  127. $kuliah[$ct]["start"] = "2016-02-12T$date[0]:00";
  128. $kuliah[$ct]["end"] = "2016-02-12T$date[1]:00";
  129. break;
  130. case "Sabtu":
  131. $kuliah[$ct]["start"] = "2016-02-13T$date[0]:00";
  132. $kuliah[$ct]["end"] = "2016-02-13T$date[1]:00";
  133. break;
  134. case "":
  135. $kuliah[$ct]["start"] = "2016-02-08T$date[0]:00";
  136. $kuliah[$ct]["end"] = "2016-02-08T$date[1]:00";
  137. break;
  138. }
  139. $ct++;
  140. }
  141. }
  142. $kuliah = json_encode($kuliah);
  143. ?>
  144.  
  145. <!DOCTYPE>
  146. <!DOCTYPE html>
  147. <html>
  148. <head>
  149. <meta charset="utf-8">
  150. <title></title>
  151. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
  152. <script type="text/javascript" src="http://fullcalendar.io/js/fullcalendar-2.6.0/lib/moment.min.js"></script>
  153. <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.6.0/fullcalendar.min.js"></script>
  154. <script type="text/javascript">
  155. $(document).ready(function(){
  156. $("#calendar").fullCalendar({
  157. defaultView: "agendaWeek",
  158. minTime: "07:00:00",
  159. maxTime: "19:00:00",
  160. events: <?php echo $kuliah ?>
  161. });
  162. })
  163. </script>
  164. <link rel="stylesheet" href="http://fullcalendar.io/js/fullcalendar-2.6.0/fullcalendar.css">
  165. </head>
  166. <body>
  167. <div class="" id="calendar">
  168.  
  169. </div>
  170. </body>
  171. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement