public function checkDestination()
 {
     if ($this->method === 'mail') {
         if (empty($this->destination_email)) {
             $this->addError('destination_email', 'Destination email address can not be empty.');
             return false;
         }
     } else {
         if ($this->method === 'ftp') {
             if (!$this->destination_ip_port) {
                 $this->addError('destination_ip_port', 'Destination ip port can\'t be empty.');
             }
             if (!$this->destination_ip_folder) {
                 $this->destination_ip_folder = '';
             }
             //$this->destination_ip_folder = '//'. $this->destination_ip_folder;
             $res = explode('/', $this->destination_ip_folder);
             $str = '';
             if ($res) {
                 foreach ($res as $value) {
                     if ($value) {
                         $str .= $value . '/';
                     }
                 }
             }
             //			$this->destination_ip_folder = $str ? $str : '/';
             $this->destination_ip_folder = $str;
             $long = ip2long($this->destination_ip);
             if ($long == -1 || $long === false) {
                 $this->addError('destination_ip', 'Destination ip address is invalid.');
                 return false;
             }
         } else {
             if ($this->method === 'local_folder') {
                 $matches = array();
                 if (!preg_match('/^[A-Z,a-z,0-9,_,\\.\\s,-]{0,255}$/', $this->destination_local_folder, $matches)) {
                     $this->addError('destination_local_folder', 'Destination Local Folder is invalid.');
                     return false;
                 }
                 $criteria = new CDbCriteria();
                 $criteria->compare('destination_local_folder', $this->destination_local_folder);
                 if (!$this->isNewRecord) {
                     $criteria->addNotInCondition('ex_schedule_destination_id', [$this->ex_schedule_destination_id]);
                 }
                 $destinations = ScheduleTypeReportDestination::model()->findAll($criteria);
                 if (count($destinations) > 0) {
                     $this->addError('destination_local_folder', 'Such folder is already used.');
                     return false;
                 }
                 if (!$this->getErrors()) {
                     $scheduleTypeReportProcessed = new ScheduleTypeReportProcessed();
                     $path = $scheduleTypeReportProcessed->getFileDir() . DIRECTORY_SEPARATOR . $this->destination_local_folder;
                     if (!file_exists($path)) {
                         if (@mkdir($path, 0777, true) === false) {
                             $this->addError('destination_local_folder', 'Can\'t create directory.');
                             return false;
                         }
                     }
                 }
             }
         }
     }
 }
 public static function getHistory($schedule_id, $page_size = 15)
 {
     $criteria = new CDbCriteria();
     $criteria->alias = "t1";
     $criteria->condition = "t1.ex_schedule_id = {$schedule_id}";
     $criteria->order = "check_period_start DESC";
     $criteria->with = array('send_log.destination');
     $strp = new ScheduleTypeReportProcessed();
     $count = $strp->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = $page_size;
     $pages->pageVar = 'page';
     $pages->applyLimit($criteria);
     $historyResult = $strp->findAll($criteria);
     $historyArrResult = array();
     if (!is_null($historyResult)) {
         foreach ($historyResult as $historyItem) {
             $historyArrResult[] = $historyItem->attributes;
         }
     }
     return array('pages' => $pages, 'result' => $historyResult);
 }
Example #3
0
 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']);
     }
 }
 /**
  * @param $uids array
  * @param bool $sent true| false
  * @return array
  */
 public function findByUIDsWithDestinations($uids, $sent = false)
 {
     $criteria = new CDbCriteria();
     $criteria->alias = "t1";
     $criteria->join = '
      LEFT JOIN `' . ScheduleTypeReportProcessed::model()->tableName() . '` `t2` on `t1`.`ex_schedule_processed_id`=`t2`.`ex_schedule_processed_id`
      LEFT JOIN `' . ScheduleTypeReport::model()->tableName() . '` `t3` on `t2`.`ex_schedule_id`=`t3`.`ex_schedule_id`
     ';
     $criteria->with = array('report_processed.ex_schedule_report', 'destination');
     if ($sent == false) {
         $sent_condition = ' AND `t1`.`sent`="0"';
     }
     if ($sent == true) {
         $sent_condition = ' AND `t1`.`sent`="1"';
     }
     if (count($uids)) {
         foreach ($uids as $uid) {
             $res = ScheduleTypeReportProcessed::parseUID($uid['report_uid']);
             $criteria->addCondition('(`t2`.`check_period_start`="' . $res['check_period_start'] . '"
                                 AND `t3`.`ex_schedule_ident`="' . $res['ex_schedule_ident'] . '"
                                 ' . $sent_condition . ')', 'OR');
         }
         $result = $this->findAll($criteria);
         if (!is_null($result)) {
             foreach ($result as &$item) {
                 if (is_object($item->report_processed->ex_schedule_report) && is_object($item->report_processed)) {
                     $item->report_processed->setUniqueID($item->report_processed->ex_schedule_report->ex_schedule_ident);
                 }
             }
             $UIDsArray = $this->getUIDsArray($result);
             return array('result' => $result, 'uids' => $UIDsArray);
         }
     }
     return array('result' => array(), 'uids' => array());
 }
Example #5
0
 protected function serverStep04()
 {
     $sendData = $this->msStatus();
     if ($this->messageData['ms_status_processed'] == 1 && $this->messageData['ms_status'] == "master") {
         $scheduleTypeReportProcessed = new ScheduleTypeReportProcessed();
         $uids = array();
         foreach ($this->messageData['not_searched_reports'] as $uidItem) {
             $uids[] = $uidItem['report_uid'];
         }
         // master has not uid like this;
         $unSynchronizedReports = $scheduleTypeReportProcessed->findByUIDs($uids, 0);
         if (!is_null($unSynchronizedReports)) {
             foreach ($unSynchronizedReports['result'] as $reportItem) {
                 if ($reportItem->aging_time < time()) {
                     $reportItem->is_synchronized = 2;
                     // could not synchronize
                     $reportItem->save();
                 }
             }
         }
     }
     $this->createServerMessage('01', 1, 'SERVER ANSWER 04 (END)' . time());
 }