public function actionNew()
 {
     $model = new Component();
     if (isset($_POST['Component'])) {
         $model->attributes = $_POST['Component'];
         if ($model->save(false)) {
             $this->redirect(Yii::app()->createUrl('/admin/compontent/index'));
         }
     }
     $this->render('componentAdd', array('model' => $model));
 }
 public function save_edit()
 {
     if (!isset($_SESSION['logged'])) {
         return call('pages', 'home');
     } else {
         if (!isset($_GET['code'])) {
             return call('pages', 'error', 2);
         }
         $post_data = $_POST;
         Component::save($post_data, $_GET['code']);
         return call('components', 'index');
     }
 }
 public function importExcelToMysql($filePath, $fields = array(), $model = null, $startingRow = 2)
 {
     $objPHPExcel = PHPExcel_IOFactory::load($filePath);
     foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
         //field validation
         $fieldValidate = array();
         for ($col = 0; $col < count($fields); ++$col) {
             $val = $worksheet->getCellByColumnAndRow($fields[$col]['col'], 1)->getValue();
             $fieldValidate[$fields[$col]['name']] = $val;
         }
         $validated = FALSE;
         if ($fieldValidate['satker_code'] == 'Kode Satker' and $fieldValidate['activity_code'] == 'Kode Kegiatan' and $fieldValidate['output_code'] == 'Kode Output' and $fieldValidate['suboutput_code'] == 'Kode Suboutput' and $fieldValidate['code'] == 'Kode Komponen' and $fieldValidate['name'] == 'Uraian Komponen') {
             $validated = TRUE;
         }
         //end of validation
         if ($validated == TRUE) {
             $highestRow = $worksheet->getHighestRow();
             $isSuccess = FALSE;
             //check if RKAKL data subcomponent already removed, but app master data already realize
             $this->validateRemovedData($filePath, $fields, $worksheet, $highestRow, $startingRow);
             for ($row = $startingRow; $row <= $highestRow; ++$row) {
                 $attributes = array();
                 for ($col = 0; $col < count($fields); ++$col) {
                     $val = $worksheet->getCellByColumnAndRow($fields[$col]['col'], $row)->getValue();
                     $attributes[$fields[$col]['name']] = $val;
                 }
                 $suboutputcode = trim($attributes['satker_code'], " \t\n\r\v") . '.' . trim($attributes['activity_code'], " \t\n\r\v") . '.' . trim($attributes['output_code'], " \t\n\r\v") . '.' . trim($attributes['suboutput_code'], " \t\n\r\v");
                 $code = $suboutputcode . '.' . trim($attributes['code'], " \t\n\r\v");
                 $recorded = Component::model()->find(array('condition' => "code='{$code}'"));
                 if ($attributes['satker_code'] != NULL and $attributes['activity_code'] != NULL and $attributes['output_code'] != NULL and $attributes['suboutput_code'] != NULL and $attributes['code'] != NULL and $attributes['name'] != NULL) {
                     if ($recorded) {
                         $recorded->attributes = $attributes;
                         $satkerCode = isset($attributes['satker_code']) ? trim($attributes['satker_code'], " \t\n\r\v") : NULL;
                         $activityCode = isset($attributes['activity_code']) ? trim($attributes['activity_code'], " \t\n\r\v") : NULL;
                         $outputCode = isset($attributes['output_code']) ? trim($attributes['output_code'], " \t\n\r\v") : NULL;
                         $suboutputCode = isset($attributes['suboutput_code']) ? trim($attributes['suboutput_code'], " \t\n\r\v") : NULL;
                         $subcomponentCode = isset($attributes['code']) ? trim($attributes['code'], " \t\n\r\v") : NULL;
                         //set value
                         $recorded->satker_code = $satkerCode;
                         $recorded->activity_code = $satkerCode . '.' . $activityCode;
                         $recorded->output_code = $satkerCode . '.' . $activityCode . '.' . $outputCode;
                         $recorded->suboutput_code = $satkerCode . '.' . $activityCode . '.' . $outputCode . '.' . $suboutputCode;
                         $recorded->code = $satkerCode . '.' . $activityCode . '.' . $outputCode . '.' . $suboutputCode . '.' . $subcomponentCode;
                         if ($recorded->update()) {
                             $isSuccess = TRUE;
                         }
                     } else {
                         $model = new Component();
                         $model->attributes = $attributes;
                         $satkerCode = isset($attributes['satker_code']) ? trim($attributes['satker_code'], " \t\n\r\v") : NULL;
                         $activityCode = isset($attributes['activity_code']) ? trim($attributes['activity_code'], " \t\n\r\v") : NULL;
                         $outputCode = isset($attributes['output_code']) ? trim($attributes['output_code'], " \t\n\r\v") : NULL;
                         $suboutputCode = isset($attributes['suboutput_code']) ? trim($attributes['suboutput_code'], " \t\n\r\v") : NULL;
                         $componentCode = isset($attributes['code']) ? trim($attributes['code'], " \t\n\r\v") : NULL;
                         //set value
                         $model->satker_code = $satkerCode;
                         $model->activity_code = $satkerCode . '.' . $activityCode;
                         $model->output_code = $satkerCode . '.' . $activityCode . '.' . $outputCode;
                         $model->suboutput_code = $satkerCode . '.' . $activityCode . '.' . $outputCode . '.' . $suboutputCode;
                         $model->code = $satkerCode . '.' . $activityCode . '.' . $outputCode . '.' . $suboutputCode . '.' . $componentCode;
                         if ($model->save()) {
                             $isSuccess = TRUE;
                         }
                     }
                 }
             }
             if ($isSuccess) {
                 unlink($filePath);
                 Yii::app()->user->setFlash('success', "File berhasil diimport ke dalam master");
                 $this->redirect(array('index'));
             } else {
                 unlink($filePath);
                 Yii::app()->user->setFlash('error', "Mohon masukkan data secara lengkap.");
             }
         } else {
             unlink($filePath);
             Yii::app()->user->setFlash('error', "Pastikan file yang Anda upload sudah benar!");
             $this->redirect(array('import'));
         }
     }
 }
Esempio n. 4
0
 function save()
 {
     $this->filter_access('Component', 'roled_add', 'components/index');
     $component = new Component();
     $component->comp_name = $this->input->post('comp_name');
     $component->comp_type = $this->input->post('comp_type');
     if ($component->save()) {
         $this->session->set_flashdata('message', 'Component successfully created!');
         redirect('components/');
     } else {
         // Failed
         $component->error_message('custom', 'Component Name required');
         $msg = $component->error->custom;
         $this->session->set_flashdata('message', $msg);
         redirect('components/add');
     }
 }