public static function getList($ex_schedule_id) { return ScheduleTypeReportDestination::model()->findAllByAttributes(array('ex_schedule_id' => $ex_schedule_id)); }
<?php $dest_types = ScheduleTypeReportDestination::getTypes(); ?> <div class="middlewide"> <div class="middlenarrow"> <h1><?php // echo It::t('home_schedule', 'title'); ?> Station Type Report Generation </h1> <?php echo CHtml::beginForm($this->createUrl('site/StationTypeDataExport'), 'post'); ?> <input type="hidden" name="ex_schedule_id" value="<?php echo $scheduleTypeReportForm->ex_schedule_id; ?> " /> <?php echo CHtml::errorSummary($scheduleTypeReportForm); ?> <table class="formtable"> <tr> <td> <?php echo CHtml::activeDropDownList($scheduleTypeReportForm, 'report_type', ScheduleTypeReport::getReportType(), array('style' => 'width: 50px;')); ?> </td>
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)); }
public function deliverReport() { $this->_logger->log(__METHOD__); if (count($this->data) == 0) { return false; } ini_set('memory_limit', '-1'); $this->_logger->log(__METHOD__, array('ex_schedule_id' => $this->schedule_type_report->ex_schedule_id)); $this->_logger->log(__METHOD__ . ' :' . print_r($this->schedule_type_report, 1)); $destinations = ScheduleTypeReportDestination::getList($this->schedule_type_report->ex_schedule_id); $total = count($destinations); $this->_logger->log(__METHOD__, array('destination_count' => $total)); //$this->_logger->log(__METHOD__ . ' :'. print_r($destinations,1)); $file_path = $this->schedule_type_report_processed->full_file_name; // $report_type = strtoupper($this->schedule_info->report_type); $file_name = $this->schedule_type_report_processed->check_period_start . '-' . $this->schedule_type_report_processed->check_period_end . '.' . $this->schedule_type_report->report_format; //$this->schedule_type_report->report_format; $report_type = $this->schedule_type_report->report_type; //$this->schedule_type_report_processed->file_content; if (count($destinations) > 0) { foreach ($destinations as $i => $destination) { if ($destination->method === 'mail') { $this->_logger->log(__METHOD__, array('destination' => $i + 1, 'report_type' => $report_type, 'method' => $destination->method, 'email' => $destination->destination_email)); $mail_params = array('station_id_code' => $this->schedule_type_report->station_type, 'actuality_time' => $this->schedule_type_report->created, 'schedule_period' => Yii::app()->params['schedule_generation_period'][$this->schedule_type_report->period], 'report_file_name' => $file_name, 'link' => '', 'report_type' => $report_type); $subject = Yii::t('letter', 'scheduled_report_mail_subject', $mail_params, null, 'en'); $settings = Settings::model()->findByPk(1); $mailSender = new mailSender('odss_reports', $mail_params); $sendResult = $mailSender->setAttachments(array(array('file_path' => $file_path, 'file_name' => $file_name)))->setRecipient($destination->destination_email)->setFrom($settings->mail__sender_address, $settings->mail__sender_name)->setSubject($subject)->setHtmlBody()->send(); $this->_logger->log(__METHOD__ . ' $sendResult: ' . $sendResult); $this->_logger->log(__METHOD__ . ' Message send with attached file'); $this->_logger->log(__METHOD__ . ' Deliver via mail DONE.'); } else { if ($destination->method === 'ftp') { // use it if you have some superstition about "../" // $fileCopier = new FileCopier; // $file_path = $fileCopier->rmPathSteps($file_path); $ftpClient = new FtpClient(); $errors = $ftpClient->connect($destination->destination_ip, $destination->destination_ip_port)->login($destination->destination_ip_user, $destination->destination_ip_password)->setFolder($destination->destination_ip_folder)->openLocalFile($file_path)->upload($file_name)->closeLocalFile()->getErrors(); $this->_logger->log(__METHOD__ . " ftp errors:" . print_r($errors, 1)); $this->_logger->log(__METHOD__ . ' Deliver via ftp DONE.'); } else { if ($destination->method === 'local_folder') { $this->_logger->log(__METHOD__, array('destination' => $i + 1, 'report_type' => $report_type, 'method' => $destination->method, 'destination_folder' => $destination->destination_local_folder)); $destinationPath = $this->schedule_type_report_processed->getFileDir() . DIRECTORY_SEPARATOR . $destination->destination_local_folder; $this->_logger->log(__METHOD__ . ' $file_path: ' . $file_path); $this->_logger->log(__METHOD__ . ' $destinationPath: ' . $destinationPath); $this->_logger->log(__METHOD__ . ' $file_name: ' . $file_name); $fileCopier = new FileCopier(); $errors = $fileCopier->copy($file_path, $destinationPath . DIRECTORY_SEPARATOR . $file_name)->getErrors(); $this->_logger->log(__METHOD__ . print_r($errors, 1)); $this->_logger->log(__METHOD__ . ' Deliver to local folder DONE.'); } } } } } $this->_logger->log(__METHOD__ . ' Delivery completed.'); }
public function actionDeleteScheduleTypeDestination() { $ex_schedule_id = isset($_REQUEST['sid']) ? intval($_REQUEST['sid']) : null; $destination_id = isset($_REQUEST['did']) ? intval($_REQUEST['did']) : null; $return = array('ok' => 0); if ($ex_schedule_id && $destination_id) { $res = ScheduleTypeReportDestination::model()->deleteAllByAttributes(array('ex_schedule_id' => $ex_schedule_id, 'ex_schedule_destination_id' => $destination_id)); if ($res) { $return['ok'] = 1; } } print json_encode($return); CApplication::end(); }