Advertisement
Guest User

Untitled

a guest
May 7th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 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.  
  112. for($i = 0; $i < count($kuliah_html)-1; $i++){
  113. if($kuliah_html[$i]->find("td") != null){
  114. $date = str_replace(".", ":", $kuliah_html[$i]->find("td", 8)->text());
  115. $date = explode("-", $date);
  116.  
  117. //set pake tanda & biar jadi reference variable array, jadi codingnya ga usah banyak diulang-ulang
  118. if ($kuliah_html[$i]->find("td", 7)->text() == "Senin") {
  119. $tmpHari = &$senin;
  120. }else if ($kuliah_html[$i]->find("td", 7)->text() == "Selasa") {
  121. $tmpHari = &$selasa;
  122. }else if ($kuliah_html[$i]->find("td", 7)->text() == "Rabu") {
  123. $tmpHari = &$rabu;
  124. }else if ($kuliah_html[$i]->find("td", 7)->text() == "Kamis") {
  125. $tmpHari = &$kamis;
  126. }else if ($kuliah_html[$i]->find("td", 7)->text() == "Jumat") {
  127. $tmpHari = &$jumat;
  128. }else if ($kuliah_html[$i]->find("td", 7)->text() == "Sabtu") {
  129. $tmpHari = &$sabtu;
  130. }
  131.  
  132. //jadiin waktu sebagai key dari arraynya, nanti tinggal sort pake fungsinya php
  133. $waktu = $kuliah_html[$i]->find("td", 8)->text();
  134.  
  135. $tmpHari[$waktu] = [
  136. "kode" => $kuliah_html[$i]->find("td", 1)->text(),
  137. "matkul" => $kuliah_html[$i]->find("td", 2)->text(),
  138. "sks" => $kuliah_html[$i]->find("td", 3)->text(),
  139. "kelas" => $kuliah_html[$i]->find("td", 4)->text(),
  140. "dosen" => $kuliah_html[$i]->find("td", 5)->text(),
  141. "hari" => $kuliah_html[$i]->find("td", 7)->text(),
  142. "waktu" => $waktu,
  143. "ruang" => $kuliah_html[$i]->find("td", 9)->text(),
  144. ];
  145. }
  146. }
  147.  
  148. //sorting by key
  149. ksort($senin);
  150. ksort($selasa);
  151. ksort($rabu);
  152. ksort($kamis);
  153. ksort($jumat);
  154. ksort($sabtu);
  155.  
  156. echo "<pre>";
  157. print_r($senin);
  158. print_r($selasa);
  159. print_r($rabu);
  160. print_r($kamis);
  161. print_r($jumat);
  162. print_r($sabtu);
  163.  
  164. exit;
  165. //silahkan tampilkan sesuai selera Anda!
  166. ?>
  167.  
  168. <!DOCTYPE html>
  169. <html>
  170. <head>
  171. <meta charset="utf-8">
  172. <title></title>
  173. <link rel="stylesheet" href="bootstrap.css" charset="utf-8">
  174. <link rel="stylesheet" href="custom.css" charset="utf-8">
  175. <link rel="stylesheet" href="http://fullcalendar.io/js/fullcalendar-2.6.0/fullcalendar.css">
  176. </head>
  177. <body>
  178. <div class="container-fluid content">
  179. <div class="row">
  180. <div class="img-student col-xs-4">
  181. <?php echo "<img src=$base_url" . "$photo_url>"; ?>
  182. </div>
  183. <div class="col-xs-8">
  184. <?php
  185. echo "<h3>" . $name . "</h3>";
  186. echo "<h4>" . $npm . "</h4>";
  187. echo "<h5>" . $semester . "</h5>";
  188. ?>
  189. </div>
  190. </div>
  191. <div class="row">
  192. <div class="col-xs-12">
  193. <br>
  194. <?php
  195. echo "<table class='table table-striped table-condensed text-center'>";
  196. echo "<thead>";
  197. echo "<th class='text-center'>Kode Matakuliah</th>";
  198. echo "<th class='text-center'>Nama Matakuliah</th>";
  199. echo "<th class='text-center'>Sks</th>";
  200. echo "</thead>";
  201. echo "<tbody>";
  202. for ($i=0; $i < count($jadwal_kuliah); $i++) {
  203. echo "<tr>";
  204. echo "<td>";
  205. echo $jadwal_kuliah[$i]['kode'];
  206. echo "</td>";
  207. echo "<td>";
  208. echo $jadwal_kuliah[$i]['matkul'];
  209. echo "</td>";
  210. echo "<td>";
  211. echo $jadwal_kuliah[$i]['sks'];
  212. echo "</td>";
  213. echo "</tr>";
  214. }
  215. echo "</tbody>";
  216. echo "</table>";
  217. ?>
  218. </div>
  219. </div>
  220. <div class="row">
  221. <div class="col-xs-12">
  222. <?php
  223. echo $selasa;
  224. echo '<h3>Jadwal Kuliah</h3>';
  225. echo '<h5>Senin</h5>';
  226. echo "<table class='table table-striped table-condensed text-center'>";
  227. echo "<tbody>";
  228. for ($i=0; $i < count($senin); $i++) {
  229. echo "<tr>";
  230. echo "<td>";
  231. echo $senin[$i]['kode'];
  232. echo "</td>";
  233. echo "<td>";
  234. echo $senin[$i]['matkul'];
  235. echo "</td>";
  236. echo "</tr>";
  237. }
  238. echo "</tbody>";
  239. echo "</table>";
  240. echo '<h5>Selasa</h5>';
  241. echo "<table class='table table-striped table-condensed text-center'>";
  242. echo "<tbody>";
  243. for ($i=0; $i < count($selasa); $i++) {
  244. echo "<tr>";
  245. echo "<td>";
  246. echo $selasa[$i]['kode'];
  247. echo "</td>";
  248. echo "<td>";
  249. echo $selasa[$i]['matkul'];
  250. echo "</td>";
  251. echo "<td>";
  252. echo $selasa[$i]['sks'];
  253. echo "</td>";
  254. echo "</tr>";
  255. }
  256. echo "</tbody>";
  257. echo "</table>";
  258. ?>
  259. </div>
  260. </div>
  261. </div>
  262. </body>
  263. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
  264. <!-- <script type="text/javascript" src="http://fullcalendar.io/js/fullcalendar-2.6.0/lib/moment.min.js"></script>
  265. <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.6.1/fullcalendar.min.js"></script> -->
  266. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement