public function actionScheduleTypeDownload()
 {
     $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
     if ((int) $id) {
         $report = new ScheduleTypeReportProcessed();
         $reportResult = $report->with('ex_schedule_report')->findByPk($id);
         $reportResult->file_content;
         $extension = $reportResult->ex_schedule_report->report_format;
         $file_name = $reportResult->check_period_start . ' - ' . $reportResult->check_period_end;
         $report_string = !empty($reportResult->file_content) ? $reportResult->file_content : '';
         $file_name .= '.' . $extension;
         It::downloadFile($report_string, $file_name);
     } else {
         $this->redirect($_SERVER['HTTP_REFERER']);
     }
 }
    public function createExport()
    {
        TimezoneWork::set('UTC');
        $tablesArray = array();
        $settingsArray = array();
        $settingsArray['user_settings'] = false;
        $settingsArray['common_settings'] = false;
        // users and access tables
        if ($this->user_settings) {
            $userTable = Yii::app()->db->createCommand()->select('
                                            u.user_id,
                                            u.email,
                                            u.username,
                                            u.password,
                                            u.role,
                                            u.timezone_id,
                                            u.created,
                                            u.updated
                                        ')->from('user u')->queryAll();
            $tablesArray['user'] = $userTable;
            $access_userTable = Yii::app()->db->createCommand()->select('
                                            au.id,
                                            au.user_id,
                                            au.action_id,

                                        ')->from('access_user au')->queryAll();
            $tablesArray['access_user'] = $access_userTable;
            $access_globalTable = Yii::app()->db->createCommand()->select('
                                            ag.id,
                                            ag.controller,
                                            ag.action,
                                            ag.enable,
                                            ag.description,

                                        ')->from('access_global ag')->queryAll();
            $tablesArray['access_global'] = $access_globalTable;
            $settingsArray['user_settings'] = true;
        }
        $settingsTable = Settings::model()->findAll();
        $tablesArray['settings'] = self::modelDataToArray($settingsTable);
        //        $configTable = Yii::app()->db->createCommand()
        //            ->select('c.config_id, c.key, c.label, c.value, c.default, c.type')
        //            ->from('config c')
        //            ->queryAll();
        //        $tablesArray['config'] = $configTable;
        $station = Yii::app()->db->createCommand()->select('
                                                            s.station_id,
                                                            s.display_name,
                                                            s.station_id_code,
                                                            s.station_number,
                                                            s.station_type,
                                                            s.logger_type,
                                                            s.communication_type,
                                                            s.communication_port,
                                                            s.communication_esp_ip,
                                                            s.communication_esp_port,
                                                            s.details,
                                                            s.status_message_period,
                                                            s.event_message_period,
                                                            s.timezone_id,
                                                            s.timezone_offset,
                                                            s.wmo_block_number,
                                                            s.wmo_member_state_id,
                                                            s.wmo_station_number,
                                                            s.wmo_originating_centre,
                                                            s.national_aws_number,
                                                            s.lat,
                                                            s.lng,
                                                            s.altitude,
                                                            s.magnetic_north_offset,
                                                            s.country_id,
                                                            s.city_id,
                                                            s.awos_msg_source_folder,
                                                            s.icao_code,
                                                            s.phone_number,
                                                            s.sms_message,
                                                            s.station_gravity,
                                                            s.created,
                                                            s.updated
                                                            ')->from('station  s')->queryAll();
        $tablesArray['station'] = $station;
        $station_groupTable = Yii::app()->db->createCommand()->select('
                                                                        sg.group_id,
                                                                        sg.name
                                                            ')->from('station_group sg')->queryAll();
        $tablesArray['station_group'] = $station_groupTable;
        $station_group_destinationTable = Yii::app()->db->createCommand()->select('
                                                                        sgd.group_destination_id,
                                                                        sgd.group_id,
                                                                        sgd.station_id
                                                            ')->from('station_group_destination sgd')->queryAll();
        $tablesArray['station_group_destination'] = $station_group_destinationTable;
        $station_calculationTable = Yii::app()->db->createCommand()->select('
                                                                        sc.calculation_id,
                                                                        sc.station_id,
                                                                        sc.handler_id,
                                                                        sc.formula,
                                                                        sc.created,
                                                                        sc.updated
                                                            ')->from('station_calculation sc')->queryAll();
        $tablesArray['station_calculation'] = $station_calculationTable;
        $station_calculation_variableTable = Yii::app()->db->createCommand()->select('
                                                                        scv.calculation_variable_id,
                                                                        scv.calculation_id,
                                                                        scv.variable_name,
                                                                        scv.sensor_feature_id,
                                                                        scv.created,
                                                                        scv.updated
                                                            ')->from('station_calculation_variable scv')->queryAll();
        $tablesArray['station_calculation_variable'] = $station_calculation_variableTable;
        $station_sensorTable = Yii::app()->db->createCommand()->select('
                                                                        ss.station_sensor_id,
                                                                        ss.station_id,
                                                                        ss.sensor_id_code,
                                                                        ss.display_name,
                                                                        ss.created,
                                                                        ss.updated,
                                                                        ss.handler_id
                                                            ')->from('station_sensor ss')->queryAll();
        $tablesArray['station_sensor'] = $station_sensorTable;
        $station_sensor_featureTable = Yii::app()->db->createCommand()->select('
                                                                      ssf.sensor_feature_id,
                                                                      ssf.sensor_id,
                                                                      ssf.feature_code,
                                                                      ssf.feature_display_name,
                                                                      ssf.feature_constant_value,
                                                                      ssf.measurement_type_code,
                                                                      ssf.metric_id,
                                                                      ssf.is_main,
                                                                      ssf.filter_max,
                                                                      ssf.filter_min,
                                                                      ssf.filter_diff,
                                                                      ssf.has_filters,
                                                                      ssf.has_filter_min,
                                                                      ssf.has_filter_max,
                                                                      ssf.has_filter_diff,
                                                                      ssf.is_constant,
                                                                      ssf.is_cumulative,
                                                                      ssf.created,
                                                                      ssf.updated
                                                            ')->from('station_sensor_feature ssf')->queryAll();
        $tablesArray['station_sensor_feature'] = $station_sensor_featureTable;
        $sensor_handler_defaultTable = Yii::app()->db->createCommand()->select('
                                                                      sh.handler_id,
                                                                      sh.handler_id_code,
                                                                      sh.display_name,
                                                                      sh.handler_default_display_name,
                                                                      sh.default_prefix,
                                                                      sh.aws_panel_display_position,
                                                                      sh.aws_panel_show,
                                                                      sh.aws_single_display_position,
                                                                      sh.aws_single_group,
                                                                      sh.aws_station_uses,
                                                                      sh.rain_station_uses,
                                                                      sh.awa_station_uses,
                                                                      sh.flags,
                                                                      sh.start_time,
                                                                      sh.created,
                                                                      sh.updated
                                                            ')->from('sensor_handler sh')->queryAll();
        $tablesArray['sensor_handler'] = $sensor_handler_defaultTable;
        $sensor_handler_default_featureTable = Yii::app()->db->createCommand()->select('
                                                                    shdf.handler_feature_id,
                                                                    shdf.handler_id,
                                                                    shdf.feature_code,
                                                                    shdf.aws_panel_show,
                                                                    shdf.feature_constant_value,
                                                                    shdf.metric_id,
                                                                    shdf.filter_max,
                                                                    shdf.filter_min,
                                                                    shdf.filter_diff,
                                                                    shdf.created,
                                                                    shdf.updated
                                                            ')->from('sensor_handler_default_feature shdf')->queryAll();
        $tablesArray['sensor_handler_default_feature'] = $sensor_handler_default_featureTable;
        $schedule_reportTable = Yii::app()->db->createCommand()->select('
                                                                    sr.schedule_id,
                                                                    sr.report_type,
                                                                    sr.station_id,
                                                                    sr.send_like_attach,
                                                                    sr.send_email_together,
                                                                    sr.period,
                                                                    sr.report_format,
                                                                    sr.last_scheduled_run_fact,
                                                                    sr.last_scheduled_run_planned,
                                                                    sr.created,
                                                                    sr.updated
                                                            ')->from('schedule_report sr')->queryAll();
        $tablesArray['schedule_report'] = $schedule_reportTable;
        $schedule_report_to_stationTable = Yii::app()->db->createCommand()->select('
                                                                    srts.id,
                                                                    srts.schedule_id,
                                                                    srts.station_id
                                                            ')->from('schedule_report_to_station srts')->queryAll();
        $tablesArray['schedule_report_to_station'] = $schedule_report_to_stationTable;
        $schedule_report_destinationTable = Yii::app()->db->createCommand()->select('
                                                                    srd.schedule_destination_id,
                                                                    srd.schedule_id,
                                                                    srd.method,
                                                                    srd.destination_email,
                                                                    srd.destination_local_folder,
                                                                    srd.destination_ip,
                                                                    srd.destination_ip_port,
                                                                    srd.destination_ip_folder,
                                                                    srd.destination_ip_user,
                                                                    srd.destination_ip_password
                                                            ')->from('schedule_report_destination srd')->queryAll();
        $tablesArray['schedule_report_destination'] = $schedule_report_destinationTable;
        $ex_schedule_reportTable = Yii::app()->db->createCommand()->from('ex_schedule_report esr')->queryAll();
        $tablesArray['ex_schedule_report'] = $ex_schedule_reportTable;
        $ex_schedule_report_destinationTable = Yii::app()->db->createCommand()->from('ex_schedule_report_destination esrd')->queryAll();
        $tablesArray['ex_schedule_report_destination'] = $ex_schedule_report_destinationTable;
        //        $ex_schedule_report_processedTable = Yii::app()->db->createCommand()
        //                                                            ->from('ex_schedule_report_processed esrp')
        //                                                            ->queryAll();
        //        $tablesArray['ex_schedule_report_processed'] = $ex_schedule_report_processedTable;
        //        $ex_schedule_send_logTable = Yii::app()->db->createCommand()
        //
        //                                                            ->from('ex_schedule_send_log essl')
        //                                                            ->queryAll();
        //        $tablesArray['ex_schedule_send_log'] = $ex_schedule_send_logTable;
        $settingsArray['common_settings'] = true;
        $resultArray['config'] = $settingsArray;
        $resultArray['data'] = $tablesArray;
        $result = serialize($resultArray);
        $additional = "";
        if ($settingsArray['user_settings']) {
            $additional = "_users";
        }
        $fileName = 'settings_export' . $additional . '_' . date('Y_m_d_H_i_s') . '.conf';
        It::downloadFile($result, $fileName, 'text/conf');
    }
Beispiel #3
0
 public function actionScheduleDownload()
 {
     $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
     $process = ScheduleReportProcessed::model()->with('ScheduleReportToStation.realStation')->with('ScheduleReportToStation.schedule_report')->findByPk($id);
     if (!$process) {
         $this->redirect($_SERVER['HTTP_REFERER']);
     }
     $station = $process->ScheduleReportToStation->realStation;
     $schedule = $process->ScheduleReportToStation->schedule_report;
     $file_name = $station->station_id_code . '_' . strtoupper($schedule->report_type) . '_' . gmdate('Y-m-d_Hi', strtotime($process->check_period_end ? $process->check_period_end : $process->created)) . '.' . $schedule->report_format;
     $file_path = dirname(Yii::app()->request->scriptFile) . DIRECTORY_SEPARATOR . "files" . DIRECTORY_SEPARATOR . "schedule_reports" . DIRECTORY_SEPARATOR . $id;
     $report_string = file_exists($file_path) ? file_get_contents($file_path) : ($report_string = '');
     It::downloadFile($report_string, $file_name);
 }
Beispiel #4
0
 public function createExport()
 {
     $return_string = "";
     $sql = "SELECT\n                       `t1`.`measuring_timestamp` AS `TxDateTime`,\n                       `t4`.`station_id_code` AS `StationId`, \n                       `t4`.`display_name` AS `StationDisplayName`,\n                       `t3`.`sensor_id_code` AS `SensorId`, \n                       `t3`.`display_name` AS `SensorDisplayName`, \n                       \n                       `t1`.`period` AS `MeasurementPeriod`,\n                       `t1`.`sensor_feature_value` AS `Value`,\n                       `t5`.`short_name` AS `Metric`,\n                       `t8`.`value` AS `DewPoint`,\n                       `t11`.`value` AS `PressureMSL`,\n                       \n                       `t12`.`handler_id_code`,\n                       `t4`.`magnetic_north_offset`\n\n                 FROM `" . SensorData::model()->tableName() . "` t1\n                 LEFT JOIN `" . StationSensorFeature::model()->tableName() . "`          `t2`    ON `t2`.`sensor_feature_id` = `t1`.`sensor_feature_id`\n                 LEFT JOIN `" . StationSensor::model()->tableName() . "`                 `t3`    ON `t3`.`station_sensor_id` = `t2`.`sensor_id`\n                 LEFT JOIN `" . Station::model()->tableName() . "`                       `t4`    ON `t4`.`station_id` = `t1`.`station_id`\n                 LEFT JOIN `" . RefbookMetric::model()->tableName() . "`                 `t5`    ON `t5`.`metric_id` = `t2`.`metric_id`\n\n                 LEFT JOIN `" . StationCalculation::model()->tableName() . "`            `t6`    ON (`t6`.`station_id` = `t1`.`station_id` AND `t6`.`handler_id` = 1)\n                 LEFT JOIN `" . StationCalculationVariable::model()->tableName() . "`    `t7`    ON (`t7`.`sensor_feature_id` = `t2`.`sensor_feature_id` AND `t7`.`calculation_id` = `t6`.`calculation_id`)\n                 LEFT JOIN `" . StationCalculationData::model()->tableName() . "`        `t8`    ON (`t8`.`calculation_id` = `t7`.`calculation_id` AND `t8`.`listener_log_id` = `t1`.`listener_log_id`)\n\n                 LEFT JOIN `" . StationCalculation::model()->tableName() . "`            `t9`    ON (`t9`.`station_id` = `t1`.`station_id` AND `t9`.`handler_id` = 2)\n                 LEFT JOIN `" . StationCalculationVariable::model()->tableName() . "`    `t10`   ON (`t10`.`sensor_feature_id` = `t2`.`sensor_feature_id` AND `t10`.`calculation_id` = `t9`.`calculation_id`)\n                 LEFT JOIN `" . StationCalculationData::model()->tableName() . "`        `t11`   ON (`t11`.`calculation_id` = `t10`.`calculation_id` AND `t11`.`listener_log_id` = `t1`.`listener_log_id`)\n\n                 LEFT JOIN `" . SensorDBHandler::model()->tableName() . "`               `t12`   ON `t12`.`handler_id` = `t3`.`handler_id`\n\n                 WHERE `t1`.`station_id` IN (" . implode(',', $this->station_id) . ")\n                   AND `t1`.`measuring_timestamp` >= FROM_UNIXTIME(" . $this->start_timestamp . ") \n                   AND `t1`.`measuring_timestamp` <= FROM_UNIXTIME(" . $this->end_timestamp . ")\n                   AND `t2`.`is_main` = 1\n                   AND `t1`.`is_m` = '0'\n                 ORDER BY `t1`.`measuring_timestamp` DESC, `t4`.`station_id_code`, `t3`.`sensor_id_code`";
     $res = CStubActiveRecord::getDbConnect(true)->createCommand($sql)->queryAll();
     if ($res) {
         foreach ($res as $key => $value) {
             $handler_obj = SensorHandler::create($value['handler_id_code']);
             $res[$key]['Value'] = $handler_obj->applyOffset($res[$key]['Value'], $res[$key]['magnetic_north_offset']);
             $res[$key]['Value'] = $handler_obj->formatValue($res[$key]['Value'], $res[$key]['feature_code']);
             unset($res[$key]['magnetic_north_offset']);
             unset($value['handler_id_code']);
             unset($res[$key]['feature_code']);
         }
         $return_string .= "\"AWS Stations:\"\n" . It::prepareStringCSV($res);
     }
     $sql = "SELECT\n                        `t1`.`measuring_timestamp` AS `TxDateTime`,\n                        `t3`.`station_id_code` AS `StationId`, \n                        `t3`.`display_name` AS `StationDisplayName`,\n                        `t2`.`sensor_id_code` AS `SensorId`, \n                        `t2`.`display_name` AS `SensorDisplayName`,  \n                        (`t1`.`sensor_value` * `t1`.`bucket_size`) AS `Value`,\n                        `t4`.`short_name` AS `Metric`                        \n                 FROM `" . SensorDataMinute::model()->tableName() . "` t1\n                 LEFT JOIN `" . StationSensor::model()->tableName() . "` t2 ON t2.station_sensor_id = t1.sensor_id\n                 LEFT JOIN `" . Station::model()->tableName() . "` t3 ON t3.station_id = t1.station_id\n                 LEFT JOIN `" . RefbookMetric::model()->tableName() . "` t4 ON t4.metric_id = t1.metric_id\n                     \n                 WHERE `t1`.`station_id` IN (" . implode(',', $this->station_id) . ")\n                   AND `t1`.`measuring_timestamp` >= FROM_UNIXTIME(" . $this->start_timestamp . ") \n                   AND `t1`.`measuring_timestamp` <= FROM_UNIXTIME(" . $this->end_timestamp . ")\n                   AND `t1`.`is_tmp` = 0\n                 ORDER BY t1.measuring_timestamp DESC, t3.station_id_code, t2.sensor_id_code\n                ";
     $res = CStubActiveRecord::getDbConnect(true)->createCommand($sql)->queryAll();
     if ($res) {
         $return_string .= "\n\n\"RG Stations:\"\n" . It::prepareStringCSV($res);
     }
     It::downloadFile($return_string, 'export__' . date('Y-m-d_Hi') . '.csv', 'text/csv');
 }
 public function makeExport()
 {
     $return_string = "\"Messages History\"\n\nChoosed filters:\n\n";
     if ($this->types) {
         $subtypes = array();
         if (in_array('failed', $this->types)) {
             $subtypes[] = "Failed";
         }
         if (in_array('warning', $this->types)) {
             $subtypes[] = "Warning";
         }
         if (in_array('successfull', $this->types)) {
             $subtypes[] = "Successfull";
         }
         if ($this->types && in_array('not_processed_yet', $this->types)) {
             $subtypes[] = "Not procecessed yet";
         }
         $return_string .= "* Types " . implode(' OR ', $subtypes);
     }
     if ($this->date_from || $this->date_to) {
         $return_string .= "\n* Message was added into DB in period ";
         if ($this->date_from) {
             $return_string .= " from: " . date('Y-m-d H:i:s', strtotime($this->date_from . ' ' . $this->time_from));
         }
         if ($this->date_to) {
             if ($this->date_from) {
                 $return_string .= ' and';
             }
             $return_string .= ' Before ' . date('Y-m-d H:i:s', strtotime($this->date_to . ' ' . $this->time_to));
         }
     }
     $res = $this->prepareList(0);
     if (!$res['list']) {
         $return_string .= "\n\nList is empty";
     } else {
         $prepared_res = array();
         foreach ($res['list'] as $key => $value) {
             $prepared_res[] = array('Message' => $value['message'], 'Added' => $value['created'], 'St Id' => $value['station_id_code'] ? $value['station_id_code'] : 'Unknown', 'St Name' => $value['station_id_code'] ? $value['display_name'] : 'Unknown', 'St Type' => $value['station_id_code'] ? $value['station_type'] : 'No', 'Has Errors?' => $value['errors'] ? 'Fatal errors. Was not processed.' : 'No', 'Has Warnings?' => $value['warnings'] ? 'Data from some sensors were not processed.' : 'No', 'Errors Description' => addslashes($value['errors'] ? implode(' ; ', $value['errors']) : 'No'), 'Warnings Description' => addslashes($value['warnings'] ? implode(' ; ', $value['warnings']) : 'No'));
         }
         $return_string .= "\n\n" . It::prepareStringCSV($prepared_res);
     }
     It::downloadFile($return_string, 'export_history__' . date('Y-m-d_Hi') . '.csv', 'text/csv');
 }
 /**
  * Send command on station by SMS
  */
 public function actionSendSMSCommand()
 {
     $form = new SMSCommandSendForm();
     /**
      * Update sms status
      */
     if (isset($_GET['view_id']) || isset($_GET['sms_command_id'])) {
         if (isset($_GET['view_id'])) {
             $form->setSMS(SMSCommand::model()->findByPk($_GET['view_id']));
         }
         if (isset($_GET['sms_command_id'])) {
             $form->setSMS(SMSCommand::model()->findByPk($_GET['sms_command_id']));
         }
         if (Yii::app()->request->isAjaxRequest) {
             return $this->renderPartial('__sms_command_status', ['sms' => $form->getSMS()]);
         }
     }
     /**
      * Delete sms
      */
     if (isset($_GET['delete_id'])) {
         SMSCommand::model()->deleteByPk($_GET['delete_id']);
     }
     /**
      * Create sms
      */
     if (isset($_POST['SMSCommandSendForm'])) {
         if ($_POST['send']) {
             $form->setScenario($form::SCENARIO_SEND);
             $form->setAttributes($_POST['SMSCommandSendForm']);
             if ($form->validate()) {
                 $form->getSMS()->setAttributes($form->getAttributes());
                 if ($form->getSMS()->save()) {
                     $form = (new SMSCommandSendForm())->setSMS(SMSCommand::model()->findByPk($form->getSMS()->sms_command_id));
                     Yii::app()->user->setFlash('SendSMSCommandForm_success', "Command send!");
                 }
             }
         }
     }
     /**
      * Grid
      */
     if (isset($_POST['date_range'])) {
         if (preg_match("/([\\d]{1,2})\\/([\\d]{1,2})\\/([\\d]{2,4})/i", $_POST['SMSCommand']['updated_from'], $matches1)) {
             $dateFromViewFormat = $matches1[0];
             $dateFrom = $matches1[3] . '-' . $matches1[1] . '-' . $matches1[2] . ' 00:00:00';
             Yii::app()->request->cookies['dateFrom'] = new CHttpCookie('dateFrom', $dateFromViewFormat);
             Yii::app()->request->cookies['from_date'] = new CHttpCookie('from_date', $dateFrom);
         } else {
             unset(Yii::app()->request->cookies['dateFrom']);
             unset(Yii::app()->request->cookies['from_date']);
         }
         if (preg_match("/([\\d]{1,2})\\/([\\d]{1,2})\\/([\\d]{2,4})/i", $_POST['SMSCommand']['updated_to'], $matches2)) {
             $dateToViewFormat = $matches2[0];
             $dateTo = $matches2[3] . '-' . $matches2[1] . '-' . $matches2[2] . ' 23:59:59';
             Yii::app()->request->cookies['dateTo'] = new CHttpCookie('dateTo', $dateToViewFormat);
             Yii::app()->request->cookies['to_date'] = new CHttpCookie('to_date', $dateTo);
         } else {
             unset(Yii::app()->request->cookies['dateTo']);
             unset(Yii::app()->request->cookies['to_date']);
         }
     }
     if (isset($_GET['reset'])) {
         unset(Yii::app()->request->cookies['dateFrom']);
         unset(Yii::app()->request->cookies['dateTo']);
         unset(Yii::app()->request->cookies['from_date']);
         unset(Yii::app()->request->cookies['to_date']);
     }
     $SMSCommand = new SMSCommand();
     $SMSCommand->unsetAttributes();
     $SMSCommand->from_date = Yii::app()->request->cookies['from_date'];
     $SMSCommand->to_date = Yii::app()->request->cookies['to_date'];
     if ($_GET['SMSCommand']) {
         $SMSCommand->attributes = $_GET['SMSCommand'];
     }
     $dataProvider = $SMSCommand->search();
     //csv
     if ($_GET['getcsv']) {
         $items = $dataProvider->model->findAll($dataProvider->criteria);
         if (!is_null($items)) {
             $data = array();
             foreach ($items as $item) {
                 $dataItem = $item->getAttributes();
                 $data[] = $dataItem;
             }
             $ECSVExporter = new ECSVExporter($data);
             It::downloadFile($ECSVExporter->getString(), 'csv.csv', 'text/csv');
             exit;
         }
     }
     return $this->render('send_sms_command', ['form' => $form, 'dataProvider' => $dataProvider, 'dateFrom' => Yii::app()->request->cookies['dateFrom'], 'dateTo' => Yii::app()->request->cookies['dateTo']]);
 }