function actionCheckExtraUpdate()
 {
     ini_set('memory_limit', '-1');
     set_time_limit(0);
     //        $version = getConfigValue('version');
     $version = array();
     $method_name = 'm_' . $version['stage'] . '_' . $version['sprint'] . '_' . $version['update'];
     $form = new UpdateScriptForm();
     if (method_exists($form, $method_name)) {
         $form->{$method_name}(Yii::app()->db);
         It::memStatus('update__success');
     }
     $this->redirect($this->createUrl('update/index'));
     //print ('<script type="text/javascript"> setTimeout(function(){document.location.href="'.Yii::app()->controller->createUrl('update/index').'"}, 500)</script>');
 }
<?php

$importAdminsSettings->result_success === true ? It::memStatus('admin_imports_occurred_successfully') : "";
$importAdminsSettings->result_success === false ? It::memStatus('admin_import_was_fail') : "";
?>

<div class="middlenarrow" style="padding-top: -100px">

    <?php 
echo CHtml::errorSummary($importAdminsSettings);
?>

    <h1>Export settings</h1>
    <?php 
echo CHtml::beginForm($this->createUrl('superadmin/exportadminssettings'), 'post', array('id' => 'formexportadminssettings'));
?>
    <table class="">
        <tr>
            <td><?php 
echo CHtml::activeCheckBox($exportAdminsSettings, 'user_settings');
?>
 <?php 
echo CHtml::activeLabel($exportAdminsSettings, 'user_settings');
?>
</td>
        </tr>
    </table>
    <br/><br/>
    <?php 
echo CHtml::hiddenField('type', 'export');
?>
示例#3
0
 public function actionStationTypeDataExport()
 {
     /** @var ScheduleReport $form */
     /** @var ScheduleReportDestination[] $forms_d] */
     if (Yii::app()->request->isPostRequest) {
     }
     TimezoneWork::set('UTC');
     if (isset($_REQUEST['ex_schedule_id']) and (int) $_REQUEST['ex_schedule_id'] and isset($_REQUEST['active'])) {
         $scheduleTypeReportForm = ScheduleTypeReport::model()->findByPk(intval($_REQUEST['ex_schedule_id']));
         $scheduleTypeReportForm->setAttribute('active', $_REQUEST['active']);
         $scheduleTypeReportForm->save();
     }
     $scheduleTypeReportForm = new ScheduleTypeReport();
     if (isset($_REQUEST['ex_delete_id'])) {
         $scheduleTypeReportForm = ScheduleTypeReport::model()->findByPk(intval($_REQUEST['ex_delete_id']));
         if ($scheduleTypeReportForm && $scheduleTypeReportForm->delete()) {
             It::memStatus('schedule_deleted');
             $this->redirect($this->createUrl('site/StationTypeDataExport'));
         }
     }
     //		if (isset($_REQUEST['resend_schedule_id'])) {
     //            $form = ScheduleTypeReport::model()->findByPk(intval($_REQUEST['resend_schedule_id']));
     //        }
     if (isset($_REQUEST['ex_schedule_id']) and (int) $_REQUEST['ex_schedule_id'] and !isset($_REQUEST['active'])) {
         $scheduleTypeReportForm = ScheduleTypeReport::model()->findByPk(intval($_REQUEST['ex_schedule_id']));
     }
     if (isset($scheduleTypeReportForm)) {
         $scheduleTypeReportDestination = ScheduleTypeReportDestination::model()->findAllByAttributes(array('ex_schedule_id' => $scheduleTypeReportForm->ex_schedule_id));
     } else {
         $scheduleTypeReportDestination = array();
     }
     $valid = true;
     if (Yii::app()->request->isPostRequest && isset($_POST['ScheduleTypeReport'])) {
         $scheduleTypeReportForm->attributes = $_POST['ScheduleTypeReport'];
         $valid = $valid & $scheduleTypeReportForm->validate();
         if (isset($_POST['ScheduleTypeReportDestination'])) {
             foreach ($_POST['ScheduleTypeReportDestination'] as $key => $value) {
                 if ($value['ex_schedule_destination_id']) {
                     $scheduleTypeReportDestination[$key] = ScheduleTypeReportDestination::model()->findByPk($value['ex_schedule_destination_id']);
                 } else {
                     $scheduleTypeReportDestination[$key] = new ScheduleTypeReportDestination();
                 }
                 $scheduleTypeReportDestination[$key]->attributes = $value;
                 $valid = $valid & $scheduleTypeReportDestination[$key]->validate();
             }
         }
         if ($valid) {
             // $scheduleTypeReportForm->scenario='admin';
             $scheduleTypeReportForm->save(false);
             foreach ($scheduleTypeReportDestination as $key => $value) {
                 $scheduleTypeReportDestination[$key]->ex_schedule_id = $scheduleTypeReportForm->ex_schedule_id;
                 $scheduleTypeReportDestination[$key]->save();
             }
             //                foreach ($forms_s as $key => $value) {
             //                    $forms_s[$key]->schedule_id = $form->schedule_id;
             //                    $forms_s[$key]->save();
             //                }
             It::memStatus($scheduleTypeReportForm->isNewRecord ? 'schedule_added' : 'schedule_updated');
             $this->redirect($this->createUrl('site/StationTypeDataExport'));
         }
     }
     $str = new ScheduleTypeReport();
     $scheduleTypeReportProcessed = new ScheduleTypeReportProcessed();
     $scheduleTypesReports = $str->getList(10);
     $this->render('schedule_type_report', array('forms_d' => $scheduleTypeReportDestination, 'scheduleTypeReportForm' => $scheduleTypeReportForm, 'scheduleTypesReports' => $scheduleTypesReports, 'scheduleTypeReportProcessed' => $scheduleTypeReportProcessed));
 }
示例#4
0
 public function actionSchedule()
 {
     /** @var ScheduleReport $form */
     /** @var ScheduleReportDestination[] $forms_d] */
     $forms_s[] = new ScheduleReportToStation();
     if (isset($_REQUEST['delete_id'])) {
         $form = ScheduleReport::model()->findByPk(intval($_REQUEST['delete_id']));
         if ($form && $form->delete()) {
             It::memStatus('schedule_deleted');
             $this->redirect($this->createUrl('site/schedule'));
         }
     }
     if (isset($_REQUEST['resend_schedule_id'])) {
         $form = ScheduleReport::model()->findByPk(intval($_REQUEST['resend_schedule_id']));
     }
     if (isset($_REQUEST['schedule_id'])) {
         $form = ScheduleReport::model()->findByPk(intval($_REQUEST['schedule_id']));
     }
     if (isset($form)) {
         $forms_d = ScheduleReportDestination::model()->findAllByAttributes(array('schedule_id' => $form->schedule_id));
         $forms_s = ScheduleReportToStation::model()->findAllByAttributes(array('schedule_id' => $form->schedule_id));
     } else {
         $form = new ScheduleReport();
         $forms_d = array();
     }
     $valid = true;
     if (Yii::app()->request->isPostRequest && isset($_POST['ScheduleReport'])) {
         $form->attributes = $_POST['ScheduleReport'];
         $valid = $valid & $form->validate();
         if (isset($_POST['ScheduleReportDestination'])) {
             foreach ($_POST['ScheduleReportDestination'] as $key => $value) {
                 if ($value['schedule_destination_id']) {
                     $forms_d[$key] = ScheduleReportDestination::model()->findByPk($value['schedule_destination_id']);
                 } else {
                     $forms_d[$key] = new ScheduleReportDestination();
                 }
                 $forms_d[$key]->attributes = $value;
                 //schedule_destination_id
                 $valid = $valid & $forms_d[$key]->validate();
             }
         }
         if (isset($_POST['ScheduleReportToStation'])) {
             $forms_s = array();
             foreach ($_POST['ScheduleReportToStation'] as $key => $value) {
                 if ($value['id']) {
                     $forms_s[$key] = ScheduleReportToStation::model()->findByPk($value['id']);
                 } elseif ($value['remove_id']) {
                     $stationToRemove = ScheduleReportToStation::model()->findByPk($value['remove_id']);
                     $stationToRemove->delete();
                     unset($forms_s[$key]);
                     continue;
                 } else {
                     $forms_s[$key] = new ScheduleReportToStation();
                 }
                 $forms_s[$key]->attributes = $value;
                 //id
                 //                    $valid = $valid & $forms_s[$key]->validate();
             }
         }
         if ($valid) {
             $form->save(false);
             foreach ($forms_d as $key => $value) {
                 $forms_d[$key]->schedule_id = $form->schedule_id;
                 $forms_d[$key]->save();
             }
             foreach ($forms_s as $key => $value) {
                 $forms_s[$key]->schedule_id = $form->schedule_id;
                 $forms_s[$key]->save();
             }
             //
             It::memStatus($form->isNewRecord ? 'schedule_added' : 'schedule_updated');
             //                if ($form->isNewRecord)
             $this->redirect($this->createUrl('site/schedule'));
         }
     }
     $schedule_list = ScheduleReport::getScheduleList();
     $this->render('schedule_report', array('form' => $form, 'forms_d' => $forms_d, 'forms_s' => $forms_s, 'reportsList' => $schedule_list));
 }
 public function m_0_4_1()
 {
     @apache_setenv('no-gzip', 1);
     @ini_set('zlib.output_compression', 0);
     @ini_set('implicit_flush', 1);
     ini_set('memory_limit', '-1');
     //ob_start();
     $this->flushNotification('...Please wait... Updating is going on... DO NOT LEAVE THIS PAGE!');
     $this->flushNotification('<br/>...Going to add "is_last" fields to `listener_log` table...');
     $res = Yii::app()->db->createCommand("SHOW COLUMNS FROM `" . ListenerLog::model()->tableName() . "` LIKE 'is_last'")->queryAll();
     if (!$res) {
         Yii::app()->db->createCommand("ALTER TABLE `" . ListenerLog::model()->tableName() . "` ADD `is_last` tinyint(1) NOT NULL DEFAULT '0' AFTER `is_processed`")->query();
         Yii::app()->db->createCommand("COMMIT")->query();
         $stations = Yii::app()->db->createCommand("SELECT * FROM `" . Station::model()->tableName() . "`")->queryAll();
         if ($stations) {
             foreach ($stations as $key => $value) {
                 ListenerLog::updateIsLastForStation($value['station_id']);
             }
         }
         $this->flushNotification(' ... done');
     } else {
         $this->flushNotification(' ... not need');
     }
     $this->flushNotification('<br/>...Going to add "is_processing" column to `listener_log` table...');
     $res = Yii::app()->db->createCommand("SHOW COLUMNS FROM `" . ListenerLog::model()->tableName() . "` LIKE 'is_processing'")->queryAll();
     if (!$res) {
         Yii::app()->db->createCommand("ALTER TABLE `" . ListenerLog::model()->tableName() . "` ADD `is_processing` TINYINT(1) NOT NULL DEFAULT '0' AFTER `is_processed`")->query();
         Yii::app()->db->createCommand("COMMIT")->query();
         $this->flushNotification(' ... done');
     } else {
         $this->flushNotification(' ... not need');
     }
     // station
     $this->flushNotification('<br/><br/>Station table:');
     $this->flushNotification('<br/>...Going to update  "national_aws_number" field at `station` table...');
     $res = Yii::app()->db->createCommand("SHOW COLUMNS FROM `" . Station::model()->tableName() . "` LIKE 'national_aws_number'")->queryAll();
     if ($res[0]['Null'] == 'NO') {
         Yii::app()->db->createCommand("ALTER TABLE `station` CHANGE `national_aws_number` `national_aws_number`  int(11) DEFAULT '0'")->query();
         Yii::app()->db->createCommand("COMMIT")->query();
         $this->flushNotification(' ... done');
     } else {
         $this->flushNotification(' ... not need');
     }
     $this->flushNotification('<br/>...Going to add new column "country_id" to `station` table...');
     $res = Yii::app()->db->createCommand("SHOW COLUMNS FROM `" . Station::model()->tableName() . "` LIKE 'country_id'")->queryAll();
     if (!$res) {
         Yii::app()->db->createCommand("ALTER TABLE `station` ADD `country_id` int(11) NOT NULL DEFAULT '0' AFTER `magnetic_north_offset`")->query();
         Yii::app()->db->createCommand("COMMIT")->query();
         $this->flushNotification(' ... done');
     } else {
         $this->flushNotification(' ... already exists');
     }
     $this->flushNotification('<br/>...Going to add new column "city_id" to `station` table...');
     $res = Yii::app()->db->createCommand("SHOW COLUMNS FROM `" . Station::model()->tableName() . "` LIKE 'city_id'")->queryAll();
     if (!$res) {
         Yii::app()->db->createCommand("ALTER TABLE `station` ADD `city_id` int(11) NOT NULL DEFAULT '0' AFTER `country_id`")->query();
         Yii::app()->db->createCommand("COMMIT")->query();
         $this->flushNotification(' ... done');
     } else {
         $this->flushNotification(' ... already exists');
     }
     $this->flushNotification('<br/>...Going to add new column "timezone_offset" to `station` table...');
     $res = Yii::app()->db->createCommand("SHOW COLUMNS FROM `" . Station::model()->tableName() . "` LIKE 'timezone_offset'")->queryAll();
     if (!$res) {
         Yii::app()->db->createCommand("ALTER TABLE `station` ADD `timezone_offset` varchar(20) NOT NULL AFTER `timezone_id`")->query();
         Yii::app()->db->createCommand("COMMIT")->query();
         $this->flushNotification(' ... done');
     } else {
         $this->flushNotification(' ... already exists');
     }
     $this->flushNotification('<br/>...Going to update "timezone_offset" data in `station` table...');
     $sql = "SELECT `station_id`, `timezone_id` FROM `" . Station::model()->tableName() . "` WHERE `timezone_offset` = ''";
     $res = Yii::app()->db->createCommand($sql)->queryAll();
     if ($res) {
         foreach ($res as $key => $value) {
             $sql = "UPDATE `" . Station::model()->tableName() . "` SET `timezone_offset` = '" . TimezoneWork::getOffsetFromUTC($value['timezone_id'], 1) . "' WHERE `station_id` = '" . $value['station_id'] . "'";
             Yii::app()->db->createCommand($sql)->query();
         }
         Yii::app()->db->createCommand("COMMIT")->query();
         $this->flushNotification(' ... done');
     } else {
         $this->flushNotification(' ... not need');
     }
     $this->flushNotification('<br/>...Going to add new column "awos_msg_source_folder" to `station` table...');
     $res = Yii::app()->db->createCommand("SHOW COLUMNS FROM `" . Station::model()->tableName() . "` LIKE 'awos_msg_source_folder'")->queryAll();
     if (!$res) {
         Yii::app()->db->createCommand("ALTER TABLE `station` ADD `awos_msg_source_folder` TEXT CHARACTER SET ucs2 COLLATE ucs2_general_ci NOT NULL AFTER `city_id`")->query();
         Yii::app()->db->createCommand("COMMIT")->query();
         $this->flushNotification(' ... done');
     } else {
         $this->flushNotification(' ... already exists');
     }
     // Sensor Data
     $this->flushNotification('<br/>...Going to update `sensor_data` table\'s data...');
     Yii::app()->db->createCommand("UPDATE `sensor_data` SET `period` = 1440 WHERE `period` = 86400")->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     //Schedule report
     $this->flushNotification('<br/>...Going to create `schedule_report` table...');
     $tables = array();
     $res = Yii::app()->db->createCommand("SHOW TABLES")->queryAll();
     if ($res) {
         foreach ($res as $key => $value) {
             foreach ($value as $k1 => $v1) {
                 $tables[] = $v1;
             }
         }
     }
     if (!in_array('schedule_report', $tables)) {
         $sql = "CREATE TABLE `schedule_report` (\n                      `schedule_id` int(11) NOT NULL AUTO_INCREMENT,\n                      `report_type` varchar(50) NOT NULL DEFAULT 'synop' COMMENT 'synop, bufr',\n                      `station_id` int(11) NOT NULL,\n                      `period` int(11) NOT NULL DEFAULT '60' COMMENT 'in minutes',\n                      `method` varchar(20) NOT NULL DEFAULT 'email' COMMENT 'email, ftp',\n                      `destination_email` varchar(255) NOT NULL,\n                      `destination_ip` varchar(15) NOT NULL,\n                      `destination_ip_port` int(5) NOT NULL DEFAULT '21',\n                      `destination_ip_folder` varchar(255) NOT NULL DEFAULT '/',\n                      `destination_ip_user` varchar(255) NOT NULL,\n                      `destination_ip_password` varchar(255) NOT NULL,\n                      `report_format` varchar(20) NOT NULL DEFAULT 'csv' COMMENT 'txt, csv',\n                      `last_scheduled_run_fact` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n                      `last_scheduled_run_planned` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n                      `created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n                      `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n                      PRIMARY KEY (`schedule_id`)\n                    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
         Yii::app()->db->createCommand($sql)->query();
         Yii::app()->db->createCommand("COMMIT")->query();
         $this->flushNotification(' ... done');
     } else {
         $this->flushNotification(' ... already exists');
     }
     $this->flushNotification('<br/>...Going to create `schedule_report_processed` table...');
     if (!in_array('schedule_report_processed', $tables)) {
         $sql = "CREATE TABLE `schedule_report_processed` (\n                      `schedule_processed_id` int(11) NOT NULL AUTO_INCREMENT,\n                      `schedule_id` int(11) NOT NULL,\n                      `listener_log_id` int(11) NOT NULL,\n                      `is_processed` tinyint(1) NOT NULL DEFAULT '0',\n                      `report_string_initial` text NOT NULL,\n                      `report_string_changed` text NOT NULL,\n                      `serialized_report_problems` text NOT NULL,\n                      `serialized_report_errors` text NOT NULL,\n                      `serialized_report_explanations` text NOT NULL,\n                      `is_last` tinyint(1) NOT NULL DEFAULT '0',\n                      `created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n                      `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n                      PRIMARY KEY (`schedule_processed_id`),\n                      KEY `schedule_id` (`schedule_id`),\n                      KEY `listener_log_id` (`listener_log_id`),\n                      CONSTRAINT `schedule_report_processed_fk` FOREIGN KEY (`schedule_id`) REFERENCES `schedule_report` (`schedule_id`) ON DELETE CASCADE ON UPDATE NO ACTION,\n                      CONSTRAINT `schedule_report_processed_ibfk_1` FOREIGN KEY (`listener_log_id`) REFERENCES `listener_log` (`log_id`) ON DELETE CASCADE ON UPDATE NO ACTION\n                    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
         Yii::app()->db->createCommand($sql)->query();
         Yii::app()->db->createCommand("COMMIT")->query();
         $this->flushNotification(' ... done');
     } else {
         $this->flushNotification(' ... already exists');
     }
     // metrics
     $this->flushNotification('<br/><br/>New Metrics:');
     $this->flushNotification('<br/>...Going to add new metric "kJ/sq.m" ...');
     Yii::app()->db->createCommand("INSERT INTO `refbook_metric` (`metric_id`, `html_code`, `short_name`, `full_name`, `code`) VALUES ('21', 'kJ/sq.m', 'kJ/sq.m', 'Kilo Joule per square meter', 'kjoule_per_sq_meter')")->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     $this->flushNotification('<br/>...Going to add new metric "feet"...');
     Yii::app()->db->createCommand("INSERT INTO `refbook_metric` (`metric_id`, `html_code`, `short_name`, `full_name`, `code`) VALUES ('22', 'ft', 'ft', 'Feet', 'feet')")->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     $this->flushNotification('<br/>...Going to add new metric "km"...');
     Yii::app()->db->createCommand("INSERT INTO `refbook_metric` (`metric_id`,`html_code`,`short_name`,`full_name`,`code`) VALUES (23 , 'km', 'km', 'Kilometer', 'kilometer')")->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     $this->flushNotification('<br/>...Going to add new relation between "solar radiation" and "kj/sq.m"...');
     RefbookMeasurementTypeMetric::model()->deleteByPk(23);
     Yii::app()->db->createCommand("INSERT INTO `refbook_measurement_type_metric` (`measurement_type_metric_id`, `measurement_type_id`, `metric_id`, `is_main`) VALUES ('23', '9', '21', '0')")->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     $this->flushNotification('<br/>...Going to add new measuring type "Cloud Vertical Visibility"...');
     Yii::app()->db->createCommand("INSERT INTO `refbook_measurement_type` (`measurement_type_id`, `display_name`, `code`, `ord`) VALUES (16 ,'Cloud Vertical Visibility', 'cloud_vertical_visibility', '14')")->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     $this->flushNotification('<br/>...Going to add new measuring type "Cloud Height" ...');
     Yii::app()->db->createCommand("INSERT INTO `refbook_measurement_type` (`measurement_type_id`, `display_name`, `code`, `ord`) VALUES (17, 'Cloud Height', 'cloud_height', 15)")->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     $this->flushNotification('<br/>...Going to add new measuring type "Sea Level" ...');
     Yii::app()->db->createCommand("INSERT INTO `refbook_measurement_type` (`measurement_type_id`, `display_name`, `code`, `ord`) VALUES (18 , 'Sea Level (Mean, Sigma, Wave Hight)', 'sea_level', '16')")->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     $this->flushNotification('<br/>...Going to add relation between "Cloud Vertical Visibility" and "ft" ...');
     Yii::app()->db->createCommand("INSERT INTO `refbook_measurement_type_metric` (`measurement_type_metric_id`, `measurement_type_id`, `metric_id`, `is_main`) VALUES (24,16,22,1)")->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     $this->flushNotification('<br/>...Going to add new relation between "Cloud Vertical Visibility" and "meter"...');
     Yii::app()->db->createCommand("INSERT INTO `refbook_measurement_type_metric` (`measurement_type_metric_id`, `measurement_type_id`, `metric_id`, `is_main`) VALUES (25,16,11,0)")->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     $this->flushNotification('<br/>...Going to add new relation between "Cloud Height" and "ft"...');
     Yii::app()->db->createCommand("INSERT INTO `refbook_measurement_type_metric` (`measurement_type_metric_id`, `measurement_type_id`, `metric_id`, `is_main`) VALUES (26,17,22,1)")->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     $this->flushNotification('<br/>...Going to add new relation between "Cloud Height" and "meter"...');
     Yii::app()->db->createCommand("INSERT INTO `refbook_measurement_type_metric` (`measurement_type_metric_id`, `measurement_type_id`, `metric_id`, `is_main`) VALUES (27,17,11,0)")->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     $this->flushNotification('<br/>...Going to add new relation between "Visibility" and "meter"...');
     Yii::app()->db->createCommand("INSERT INTO `refbook_measurement_type_metric` (`measurement_type_metric_id`, `measurement_type_id`, `metric_id`, `is_main`) VALUES (28, 11, 11, 1)")->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     $this->flushNotification('<br/>...Going to add new relation between "Sea Level" and "meter"...');
     Yii::app()->db->createCommand("INSERT INTO `refbook_measurement_type_metric` (`measurement_type_metric_id`, `measurement_type_id`, `metric_id`, `is_main`) VALUES (29, 18, 11, 1)")->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     // sensor handler
     $this->flushNotification('<br/>...Going to add new column "awos_station_uses" to `sensor_handler` table...');
     $res = Yii::app()->db->createCommand("SHOW COLUMNS FROM `sensor_handler` LIKE 'awos_station_uses'")->queryAll();
     if (!$res) {
         $res = Yii::app()->db->createCommand("ALTER TABLE `sensor_handler` ADD `awos_station_uses` TINYINT( 1 ) NOT NULL DEFAULT '0'")->query();
         Yii::app()->db->createCommand("COMMIT")->query();
         $this->flushNotification(' ... done');
     } else {
         $this->flushNotification(' ... already exists');
     }
     $this->flushNotification('<br/>...Going to update `sensor_handler` table...');
     $sql = "UPDATE `sensor_handler` SET \n                `handler_id_code` = 'SeaLevelAWS',\n                `display_name` = 'Sea Level and Tide Data',\n                `description` = 'Handler \"Sea Level and Tide Data\" : Processes string like \"SL1XXXXYYYYZZZZ\", where <br/>SL1 - device Id; <br/>XXXX - Mean value;<br/>YYYY - Sigma value; <br/>ZZZZ - Wave Height <br/>Example: SL1179017900140 = SL1 sensor sent data: Mean value = 1.79, Sigma value = 1.79, Wave height = 140m.',\n                `default_prefix` = 'SL',\n                `aws_station_uses` = 1,\n                `rain_station_uses` = 0,\n                `awos_station_uses` = 0,\n                `aws_single_group` = 'sea_level'\n                WHERE `handler_id` = 13";
     Yii::app()->db->createCommand($sql)->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $sql = "UPDATE `sensor_handler` SET \n                `handler_id_code` = 'VisibilityAWS',\n                `display_name` = 'Visibility',\n                `description` = 'Handler \"Visibility\"',\n                `default_prefix` = 'VI',\n                `aws_station_uses` = 1,\n                `rain_station_uses` = 0,\n                `awos_station_uses` = 0,\n                `aws_single_group` = 'visibility'\n                WHERE `handler_id` = 14";
     Yii::app()->db->createCommand($sql)->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $sql = "UPDATE `sensor_handler` SET `handler_id_code` = 'CloudHeightAWS',\n                `display_name` = 'Cloud Height',\n                `description` = 'Handler \"Cloud Height\"',\n                `default_prefix` = 'CH',\n                `aws_station_uses` = 1,\n                `rain_station_uses` = 0,\n                `awos_station_uses` = 0,\n                `aws_single_group` = 'clouds'\n                WHERE `handler_id` = 15";
     Yii::app()->db->createCommand($sql)->query();
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     $this->flushNotification('<br/>...Going to update calculation_handler table...');
     $res = Yii::app()->db->createCommand("UPDATE `calculation_handler` SET `display_name` = 'Pressure Adjusted to MSL' WHERE `handler_id` = 2");
     Yii::app()->db->createCommand("COMMIT")->query();
     $this->flushNotification(' ... done');
     $bat_path = dirname(Yii::app()->request->scriptFile) . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'at' . DIRECTORY_SEPARATOR . 'schedule.bat';
     $schedule_bat_content = getConfigValue('php_exe_path') . " -f  " . dirname(Yii::app()->request->scriptFile) . DIRECTORY_SEPARATOR . "console.php schedule";
     file_put_contents($bat_path, $schedule_bat_content);
     exec('schtasks /create /sc minute /mo 1 /F /ru "SYSTEM" /tn delaircoScheduleScript /tr ' . $bat_path, $output);
     $values = getConfigValue('schedule');
     $values['each_minute_process_id'] = 'delaircoScheduleScript';
     InstallConfig::setConfigSection('schedule', $values);
     $values = getConfigValue('path');
     $values['site_url_for_console'] = It::baseUrl();
     InstallConfig::setConfigSection('path', $values);
     It::memStatus('update__success');
     $this->flushNotification('<script type="text/javascript"> setTimeout(function(){document.location.href="' . Yii::app()->controller->createUrl('update/index') . '"}, 10000)</script>');
 }
 public function actionMetrics()
 {
     $criteria = new CDbCriteria();
     $criteria->condition = "ord > 0";
     $criteria->order = "ord ASC";
     $meas_types = RefbookMeasurementType::model()->findAll($criteria);
     if ($meas_types) {
         foreach ($meas_types as $key => $value) {
             $sql = "SELECT `t1`.`metric_id`, CONCAT(`t2`.`html_code`, ' (', `t2`.`full_name`, ')') AS `name`, `t1`.`is_main`, `t1`.`measurement_type_metric_id`\n                        FROM `" . RefbookMeasurementTypeMetric::model()->tableName() . "` `t1`\n                        LEFT JOIN `" . RefbookMetric::model()->tableName() . "` `t2` ON `t2`.`metric_id` = `t1`.`metric_id`\n                        WHERE `t1`.`measurement_type_id` = '" . $value->measurement_type_id . "'";
             $meas_types[$key]->metrics_list = Yii::app()->db->createCommand($sql)->queryAll();
         }
     }
     if (Yii::app()->request->isPostRequest && isset($_POST['main_metric'])) {
         foreach ($_POST['main_metric'] as $key => $value) {
             if ($meas_types[$key]->metrics_list) {
                 foreach ($meas_types[$key]->metrics_list as $v1) {
                     $update = array('is_main' => $v1['metric_id'] == $value ? 1 : 0);
                     RefbookMeasurementTypeMetric::model()->updateByPk($v1['measurement_type_metric_id'], $update);
                 }
             }
         }
         StationSensorFeature::updateMetric();
         $DB = array('db' => CStubActiveRecord::getDbConnect(), 'db_long' => CStubActiveRecord::getDbConnect(true));
         foreach ($DB as $db) {
             $db->createCommand("DELETE FROM `" . ScheduleReportProcessed::model()->tableName() . "`")->query();
             $db->createCommand("DELETE FROM `" . ForwardedMessage::model()->tableName() . "`")->query();
             $db->createCommand("DELETE FROM `" . StationCalculationData::model()->tableName() . "`")->query();
             $db->createCommand("DELETE FROM `" . SeaLevelTrend::model()->tableName() . "`")->query();
             $db->createCommand("DELETE FROM `" . SensorDataMinute::model()->tableName() . "`")->query();
             $db->createCommand("DELETE FROM `" . SensorData::model()->tableName() . "`")->query();
             $db->createCommand("DELETE FROM `" . ListenerLog::model()->tableName() . "`")->query();
         }
         It::memStatus('admin_metrics_saved');
         $this->redirect($this->createUrl('superadmin/metrics'));
     }
     $this->render('metrics', array('meas_types' => $meas_types));
 }
示例#7
0
 public function actionAwsFiltered()
 {
     $delete = isset($_REQUEST['delete']) ? intval($_REQUEST['delete']) : null;
     if ($delete) {
         $obj = SensorData::model()->findByPk($delete);
         if ($obj) {
             $obj->delete();
             It::memStatus('admin_suspicious_value_was_deleted');
         }
     }
     $session = new CHttpSession();
     $session->open();
     $sess_name = 'awsfiltered_filter1';
     $fparams = $session[$sess_name];
     $fparams['showdata'] = false;
     if ($fparams['redirect'] == true or isset($_GET['page'])) {
         $fparams['showdata'] = true;
     }
     $stations = Station::getList("'aws','awos'", false);
     $time_pattern = "/^(\\d{1,2}):(\\d{1,2})\$/";
     if (!$fparams || isset($_POST['clear']) || isset($_POST['filter'])) {
         $cur_time = time();
         $some_time_ago = mktime(0, 0, 0, date('m', $cur_time), date('d', $cur_time), date('Y', $cur_time));
         $fparams = array('station_id' => $stations[0]['station_id'], 'date_from' => date('m/d/Y', $some_time_ago), 'date_to' => date('m/d/Y', $cur_time), 'time_from' => '00:00', 'time_to' => '23:59', 'order_field' => 'date', 'order_direction' => 'DESC');
     }
     if (isset($_POST['filter'])) {
         $fparams['station_id'] = intval($_POST['search']['station_id']);
         $fparams['date_from'] = $_POST['search']['date_from'];
         $fparams['date_to'] = $_POST['search']['date_to'];
         if (preg_match($time_pattern, $_POST['search']['time_from'])) {
             $fparams['time_from'] = $_POST['search']['time_from'];
         }
         if (preg_match($time_pattern, $_POST['search']['time_to'])) {
             $fparams['time_to'] = $_POST['search']['time_to'];
         }
     }
     if (isset($_REQUEST['of']) && in_array($_REQUEST['of'], array('stationid', 'date', 'sensorid', 'value'))) {
         if ($_REQUEST['of'] == $fparams['order_field']) {
             $fparams['order_direction'] = $fparams['order_direction'] == 'ASC' ? 'DESC' : 'ASC';
         } else {
             $fparams['order_direction'] = 'ASC';
         }
         $fparams['order_field'] = $_REQUEST['of'];
     }
     $session[$sess_name] = $fparams;
     if ($_POST || $_REQUEST['of']) {
         $fparams['showdata'] = true;
         $fparams['redirect'] = true;
         $session[$sess_name] = $fparams;
         $this->redirect($this->createUrl('admin/awsfiltered') . (isset($_GET['page']) ? 'page/' . $_GET['page'] : ''));
     } else {
         $fparams['redirect'] = false;
         $session[$sess_name] = $fparams;
     }
     /*----------- filter prepare -------------*/
     $sql_where = array();
     $sql_where[] = "`t1`.`is_m` = '0'";
     if ($fparams['date_from']) {
         $sql_where[] = "`t1`.`measuring_timestamp` >= '" . date('Y-m-d H:i:s', strtotime($fparams['date_from'] . ' ' . $fparams['time_from'])) . "'";
     }
     if ($fparams['date_to']) {
         $sql_where[] = "`t1`.`measuring_timestamp` <= '" . date('Y-m-d H:i:s', strtotime($fparams['date_to'] . ' ' . $fparams['time_to'])) . "'";
     }
     if ($fparams['station_id']) {
         $sql_where[] = "t1.station_id = '" . $fparams['station_id'] . "'";
     }
     $sql_where_str = count($sql_where) ? " AND " . implode(' AND ', $sql_where) . " " : "";
     if ($fparams['order_field'] == 'date') {
         $sql_order = "`t1`.`measuring_timestamp` " . $fparams['order_direction'];
     } elseif ($fparams['order_field'] == 'stationid') {
         $sql_order = "`t1`.`station_id` " . $fparams['order_direction'];
     } elseif ($fparams['order_field'] == 'sensorid') {
         $sql_order = "`t1`.`sensor_id` " . $fparams['order_direction'];
     } elseif ($fparams['order_field'] == 'value') {
         $sql_order = "CAST(`t1`.`sensor_feature_value` AS DECIMAL(15,4)) " . $fparams['order_direction'];
     } else {
         $sql_order = "`t1`.`measuring_timestamp` ";
     }
     /*----------- /end filter prepare --------*/
     if ($fparams['showdata']) {
         $sql_groupped = "SELECT `sensor_data_id`, `sensor_feature_id`, `measuring_timestamp`, CAST(`sensor_feature_value` AS DECIMAL(15,4)) as `sensor_feature_value`, `listener_log_id`\n                         FROM `" . SensorData::model()->tableName() . "`\n                         ORDER BY `measuring_timestamp` DESC\n                         LIMIT 1000";
         $sql = "SELECT `t1`.`sensor_data_id`\n                FROM " . SensorData::model()->tableName() . " `t1`\n                LEFT JOIN ({$sql_groupped}) `gt` ON `gt`.`sensor_feature_id` = `t1`.`sensor_feature_id` AND `gt`.`measuring_timestamp` < `t1`.`measuring_timestamp`\n                LEFT JOIN `" . StationSensorFeature::model()->tableName() . "` t2 ON t2.sensor_feature_id = t1.sensor_feature_id\n                LEFT JOIN `" . SensorDBHandlerDefaultFeature::model()->tableName() . "` t3 ON t3.feature_code LIKE t2.feature_code\n                WHERE (\n                        (t2.has_filter_max AND CAST(`t1`.`sensor_feature_value` AS DECIMAL(15,4)) >  (t3.filter_max * IF(t2.is_cumulative, t1.period/60, 1) ) )\n                        OR (t2.has_filter_min AND CAST(`t1`.`sensor_feature_value` AS DECIMAL(15,4)) < (t3.filter_min * IF(t2.is_cumulative, t1.period/60, 1) ))\n                        OR (t2.has_filter_diff AND `gt`.`sensor_data_id` > 0 AND ABS(CAST(`gt`.`sensor_feature_value` AS DECIMAL(15,4)) - CAST(`t1`.`sensor_feature_value` AS DECIMAL(15,4))) > (t3.filter_diff * IF(t2.is_cumulative, t1.period/60, 1)))\n                       )\n                  {$sql_where_str}\n                GROUP BY `t1`.`sensor_data_id`\n                LIMIT 1000";
         $total = count(Yii::app()->db->createCommand($sql)->queryColumn());
         $pages = new CPagination($total);
         $pages->pageSize = 20;
         //$pages->applyLimit($criteria);
         $sql = "SELECT `t1`.`sensor_data_id`, `t1`.`sensor_feature_id`, CAST(`t1`.`sensor_feature_value` AS DECIMAL(15,4)) as `sensor_feature_value`, `t1`.`measuring_timestamp`, t1.period,\n                       `gt`.`measuring_timestamp` AS `prev_measuring_timestamp`, `gt`.`listener_log_id` AS `prev_listener_log_id`,  CAST(`gt`.`sensor_feature_value` AS DECIMAL(15,4)) as `prev_sensor_feature_value`, `gt`.`sensor_data_id` as `prev_sensor_data_id`,\n                       `t5`.`filter_max`, `t5`.`filter_min`, `t5`.`filter_diff`, t2.has_filter_max, t2.has_filter_min, t2.has_filter_diff, t2.is_cumulative,\n                       `t3`.`sensor_id_code`,\n                       `t4`.`station_id_code`\n                FROM " . SensorData::model()->tableName() . " `t1`\n                LEFT JOIN ({$sql_groupped}) `gt` ON `gt`.`sensor_feature_id` = `t1`.`sensor_feature_id` AND `gt`.`measuring_timestamp` < `t1`.`measuring_timestamp`\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 = t1.sensor_id\n                LEFT JOIN `" . Station::model()->tableName() . "` t4 ON t4.station_id = t1.station_id\n                LEFT JOIN `" . SensorDBHandlerDefaultFeature::model()->tableName() . "` t5 ON t5.feature_code LIKE t2.feature_code\n                WHERE (\n                       (t2.has_filter_max AND CAST(`t1`.`sensor_feature_value` AS DECIMAL(15,4)) > (t5.filter_max * IF(t2.is_cumulative, t1.period/60, 1) ) )\n                       OR (t2.has_filter_min AND CAST(`t1`.`sensor_feature_value` AS DECIMAL(15,4)) < (t5.filter_min * IF(t2.is_cumulative, t1.period/60, 1) ))\n                       OR (t2.has_filter_diff AND `gt`.`sensor_data_id` > 0 AND ABS(CAST(`gt`.`sensor_feature_value` AS DECIMAL(15,4)) - CAST(`t1`.`sensor_feature_value` AS DECIMAL(15,4))) > (t5.filter_diff * IF(t2.is_cumulative, t1.period/60, 1) ))\n                      )\n                  {$sql_where_str}\n                GROUP BY `t1`.`sensor_data_id`\n                 HAVING  (\n                        (t2.has_filter_max AND CAST(`sensor_feature_value` AS DECIMAL(15,4)) > (t5.filter_max * IF(t2.is_cumulative, t1.period/60, 1) ) )\n                        OR (t2.has_filter_min AND CAST(`sensor_feature_value` AS DECIMAL(15,4)) < (t5.filter_min * IF(t2.is_cumulative, t1.period/60, 1) ))\n                        OR (t2.has_filter_diff AND prev_sensor_data_id > 0 AND ABS(CAST(`prev_sensor_feature_value` AS DECIMAL(15,4)) - CAST(`sensor_feature_value` AS DECIMAL(15,4))) > (t5.filter_diff * IF(t2.is_cumulative, t1.period/60, 1) ))\n\t\t\t            )\n                ORDER BY {$sql_order}\n                LIMIT " . $pages->currentPage * $pages->pageSize . ", " . $pages->pageSize;
         $list = Yii::app()->db->createCommand($sql)->queryAll();
         if ($list) {
             foreach ($list as $key => &$value) {
                 $multiplyer_str = '';
                 $multiplyer = 1;
                 if ($value['is_cumulative']) {
                     $multiplyer_str = $value['period'] != 60 ? ' * ' . $value['period'] . 'min/60' : '';
                     $multiplyer = $value['period'] / 60;
                 }
                 if (isset($value['has_filter_max']) && $value['sensor_feature_value'] > $value['filter_max'] * $multiplyer) {
                     $value['filter_reason'][] = array('main' => 'T1 > ' . $value['filter_max'] . $multiplyer_str);
                 }
                 if (isset($value['has_filter_min']) && $value['sensor_feature_value'] < $value['filter_min'] * $multiplyer) {
                     $value['filter_reason'][] = array('main' => 'T1 < ' . $value['filter_min'] . $multiplyer_str);
                 }
                 if (isset($value['prev_sensor_feature_value']) && isset($value['has_filter_diff']) && abs($value['sensor_feature_value'] - $value['prev_sensor_feature_value']) > $value['filter_diff'] * $multiplyer) {
                     $value['filter_reason'][] = array('main' => '|T1 - T0| > ' . $value['filter_diff'] . $multiplyer_str, 'extra' => '(Previous value: ' . $value['prev_sensor_feature_value'] . ' on ' . $value['prev_measuring_timestamp'] . ')');
                 }
             }
         }
         $this->render('awsfiltered', array('list' => $list, 'clean_page' => false, 'pages' => $pages, 'stations' => $stations, 'fparams' => $fparams));
     } else {
         $this->render('awsfiltered', array('list' => $list, 'clean_page' => true, 'stations' => $stations, 'fparams' => $fparams));
     }
 }