Exemplo n.º 1
0
 public function actionIndex()
 {
     //registering js file
     Yii::app()->clientScript->registerScriptFile(Yii::app()->assetManager->publish(Yii::getPathOfAlias('application.modules.export.assets') . '/js/jquery-ui.1.10.4.js'));
     $models = Yii::app()->controller->module->allowedModels;
     if ($models == NULL) {
         foreach (glob('./protected/models/*.php') as $filename) {
             $modelname = str_replace(array("./protected/models/", ".php"), "", $filename);
             $models[$modelname]['label'] = $modelname;
         }
     }
     $modelsArray = array();
     foreach ($models as $mindex => $smodel) {
         $modelsArray[$mindex] = isset($smodel['label']) ? $smodel['label'] : $mindex;
     }
     if (isset($_POST['export-database'])) {
         if (isset($_POST['reqColumns']) and count($_POST['reqColumns']) > 0) {
             $model = $_POST['model'];
             $format = 'csv';
             if (in_array($model, array_keys($modelsArray))) {
                 $export = new Export();
                 if (!$export->exportdb($format, $model, $_POST['reqColumns'])) {
                     $this->redirect(array('index'));
                 }
             } else {
                 Yii::app()->user->setFlash('exporterror', 'You are not allowed to access this model !!');
                 $this->redirect(array('index'));
             }
         } else {
             Yii::app()->user->setFlash('exporterror', 'Choose columns to export !!');
             $this->redirect(array('index'));
         }
     }
     $this->render('index', array('modelsArray' => $modelsArray));
 }