public function actionCreate2()
 {
     $model = new Jadwal();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Jadwal'])) {
         $model->attributes = $_POST['Jadwal'];
         //$sql = "SELECT nilai.NIM AS NIM,registrasi.SEM AS SEM FROM nilai JOIN registrasi ON nilai.`NIM` = registrasi.`NIM` WHERE KODE_MK LIKE '$model->KODE_MK' AND registrasi.`TA` = '$model->TA' AND registrasi.`KELAS` LIKE '$model->KELAS'";
         $sql = "SELECT DISTINCT(nilai.NIM),nilai.`SEM` FROM nilai JOIN registrasi ON nilai.`NIM` = registrasi.`NIM` WHERE KODE_MK LIKE '{$model->KODE_MK}' AND registrasi.`TA` = {$model->TA} AND registrasi.`KELAS` LIKE '{$model->KELAS}'";
         $list = Yii::app()->db->createCommand($sql)->queryAll();
         $sql_pengajar = "SELECT * FROM pengajar WHERE TA LIKE '{$model->TA}' AND ID_KUR LIKE '{$model->ID_KUR}' AND KODE_MK LIKE '{$model->KODE_MK}' ORDER BY ROLE ASC";
         $list_pengajar = Yii::app()->db->createCommand($sql_pengajar)->queryAll();
         $model->PIC = $list_pengajar[0]['DOSEN_ID'];
         foreach ($list as $s) {
             $daftarhadir = new BeritaAcaraDaftarHadir();
             $daftarhadir->ID_KUR = $model->ID_KUR;
             $daftarhadir->KODE_MK = $model->KODE_MK;
             $daftarhadir->NIM = $s['NIM'];
             $daftarhadir->SEM = $s['SEM'];
             $daftarhadir->SESSION = $model->SESSION;
             $daftarhadir->WEEK = $model->WEEK;
             $daftarhadir->TA = $model->TA;
             $daftarhadir->KELAS = $model->KELAS;
             $daftarhadir->START_TIME = $this->start_time($daftarhadir->SESSION);
             $daftarhadir->END_TIME = $this->end_time($daftarhadir->SESSION);
             $daftarhadir->TANGGAL = $model->TANGGAL;
             if ($daftarhadir->validate()) {
                 $daftarhadir->save();
             } else {
                 echo CHtml::errorSummary($daftarhadir);
             }
         }
         $kuliah = new BeritaAcaraKuliah();
         $kuliah->WEEK = $model->WEEK;
         $kuliah->SESSION = $model->SESSION;
         $kuliah->TA = $model->TA;
         $kuliah->ID_KUR = $model->ID_KUR;
         $kuliah->KODE_MK = $model->KODE_MK;
         $kuliah->KELAS = $model->KELAS;
         $kuliah->TANGGAL = $model->TANGGAL;
         $kuliah->START_TIME = $this->start_time($model->SESSION);
         $kuliah->END_TIME = $this->end_time($model->SESSION);
         $kuliah->TOPIK = $model->TOPIK;
         $kuliah->RUANGAN = $model->RUANGAN;
         $kuliah->AKTIFITAS = $model->AKTIFITAS;
         $kuliah->PIC = $model->PIC;
         $kuliah->SEM = $list[0]['SEM'];
         $kuliah->TIPE_KULIAH = 1;
         $kuliah->METODE = $model->METODE;
         $kuliah->ALAT_BANTU = $model->ALAT_BANTU;
         if ($kuliah->validate()) {
             $kuliah->save();
         } else {
             echo CHtml::errorSummary($kuliah);
         }
         $model->START_TIME = $kuliah->START_TIME;
         $model->END_TIME = $kuliah->END_TIME;
         $model->save();
         $this->redirect(array('view', 'id' => $model->ID));
     }
     $this->render('create2', array('model' => $model));
 }
 public function actionCreatejadwal($kbk)
 {
     $model = new MJadwal();
     $djadwal = new DJadwal();
     $kbkmodel = RefKbk::model()->findByPk($kbk);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['MJadwal'])) {
         $model->attributes = $_POST['MJadwal'];
         if ($model->save()) {
             if (isset($_POST['DJadwal'])) {
                 for ($i = 0; $i < 8; $i++) {
                     if (!isset($_POST["formsesi{$i}"])) {
                         echo $i;
                         $detail = new DJadwal();
                         $detail->KODE_MK = $_POST['DJadwal'][$i]['KODE_MK'];
                         $detail->RUANGAN = $_POST['DJadwal'][$i]['RUANGAN'];
                         $detail->AKTIFITAS = $_POST['DJadwal'][$i]['AKTIFITAS'];
                         $detail->SESSION = $i + 1;
                         $detail->ID_JADWAL = $model->ID;
                         $detail->START_TIME = $this->start_time($i + 1);
                         $detail->END_TIME = $this->end_time($i + 1);
                         // MAHASISWA
                         $sql = "SELECT DISTINCT(nilai.NIM),nilai.`SEM` FROM nilai JOIN registrasi ON nilai.`NIM` = registrasi.`NIM` WHERE KODE_MK LIKE \n'{$detail->KODE_MK}' AND registrasi.`TA` = {$model->TA} AND registrasi.`KELAS` LIKE '{$model->KELAS}'";
                         $list = Yii::app()->db->createCommand($sql)->queryAll();
                         //PENGAJAR
                         $sql_pengajar = "SELECT * FROM pengajar WHERE TA LIKE '{$model->TA}' AND ID_KUR LIKE '{$model->ID_KUR}' AND KODE_MK LIKE '{$detail->KODE_MK}' ORDER BY ROLE ASC";
                         $list_pengajar = Yii::app()->db->createCommand($sql_pengajar)->queryAll();
                         $detail->PIC = $list_pengajar[0]['DOSEN_ID'];
                         if ($detail->validate()) {
                             $detail->save();
                             foreach ($list as $s) {
                                 $daftarhadir = new BeritaAcaraDaftarHadir();
                                 $daftarhadir->ID_DETAIL_JADWAL = $detail->ID;
                                 $daftarhadir->NIM = $s['NIM'];
                                 if ($daftarhadir->validate()) {
                                     $daftarhadir->save();
                                 } else {
                                     echo CHtml::errorSummary($daftarhadir);
                                 }
                             }
                             $kuliah = new BeritaAcaraKuliah();
                             $kuliah->ID_DETAIL_JADWAL = $detail->ID;
                             $kuliah->TIPE_KULIAH = 1;
                             if ($kuliah->validate()) {
                                 $kuliah->save();
                             } else {
                                 echo CHtml::errorSummary($kuliah);
                             }
                         } else {
                             echo CHtml::errorSummary($detail);
                         }
                     }
                 }
             }
             $this->redirect(array('view', 'id' => $model->ID));
         } else {
             echo CHtml::errorSummary($model);
         }
     }
     $this->render('createjadwal', array('model' => $model, 'djadwal' => $djadwal, 'kbk' => $kbkmodel));
 }