예제 #1
0
 /**
  * Download SensorData
  *
  * @access public
  * @return void
  */
 public function download()
 {
     if ($this->input->post()) {
         $data["dateFrom"] = $this->input->post("from");
         $data["dateTo"] = $this->input->post("to");
         $data["interval"] = $this->input->post("interval");
         $data["download"] = true;
         if ($this->input->post("region")) {
             $data["region"] = $this->input->post("region");
             $data["station"] = null;
             $data["measurement"] = null;
             $data["multiple"] = true;
         }
         if ($this->input->post("station")) {
             $data["region"] = null;
             $data["station"] = $this->input->post("station");
             $data["measurement"] = $this->input->post("measurement");
             $data["multiple"] = false;
         }
         $result = (new Source($data))->get($this->_user);
         if (is_array($result)) {
             GlobalHelper::outputCsv("export-stations", $result, $data["station"]);
             exit;
         } else {
             redirect("/graph");
         }
     } else {
         redirect("/graph");
     }
 }
예제 #2
0
 public static function commentNewsletter($id)
 {
     $data = App\Models\commentNewsletter::where(['newsletter_id' => $id, 'status' => 1]);
     if ($data->count() > 0) {
         $return = "";
         foreach ($data->get() as $key => $value) {
             $url = '';
             $return .= '<li class="media">
             <div class="post-comment" style="padding-left: 5px;">
                 <a class="pull-left" href="#">
                     <img class="media-object" style="max-height:127px;max-width:137px;" src="' . self::checkImageCommentar($value->created_by) . '" alt="">
                 </a>
                 <div class="media-body">
                     <span><i class="fa fa-user"></i>Posted by <a href="#">' . $value->created_by . '</a></span>
                     <p>' . GlobalHelper::softTrim($value->comment, 79) . '</p>
                     <ul class="nav navbar-nav post-nav">
                         <li><a href="#"><i class="fa fa-clock-o"></i>' . GlobalHelper::formatDate($value->created_at, 'd F Y') . '</a></li>
                         <!-- <li><a href="#"><i class="fa fa-reply"></i>Reply</a></li> -->
                     </ul>
                 </div>
             </div>
         </li>';
         }
         return $return;
     } else {
         return "<label style='text-align:center'>Belum Ada Komentar</label>";
     }
 }
 public static function createNewSweepstake($sweepstakeId)
 {
     $sweepstakeUrl = GlobalHelper::generateRandomString(10);
     mkdir(self::getEndSweepstakeBaseDir() . $sweepstakeUrl);
     file_put_contents(self::getEndSweepstakeBaseDir() . $sweepstakeUrl . "/index.php", self::getSweepstakeIndexContent($sweepstakeId));
     return $sweepstakeUrl;
 }
 public static function getView($model)
 {
     if (!GlobalHelper::isRequestAjax()) {
         return self::getHTMLResponse($model);
     } else {
         return self::getAjaxResponse($model);
     }
 }
 public function edit($id, $data)
 {
     $this->sweepstakeId = $id;
     $keys = array_keys($_FILES);
     if (count($keys) == 1) {
         $fileName = GlobalHelper::saveUploadedFile($keys[0], Config::getDataFileDir(), GlobalHelper::generateRandomString(10));
         if (is_null($fileName)) {
             $this->setError("file upload problem");
             return false;
         }
         $data["share_image"] = Config::getDataFileUrl() . $fileName;
     }
     $this->setCurrentState(self::$STATE__FINISH_SAVE);
     Sweepstake_table::updateSweepstake($this->sweepstakeId, $data);
     return true;
 }
예제 #6
0
파일: Command.php 프로젝트: lina1/walle-web
 /**
  * 执行远程目标机器命令
  *
  * @param $command
  * @return bool
  */
 public final function runRemoteCommand($command)
 {
     $this->log = '';
     $needTTY = ' -T ';
     foreach (GlobalHelper::str2arr($this->getConfig()->hosts) as $remoteHost) {
         $localCommand = 'ssh ' . $needTTY . ' -p ' . $this->getHostPort($remoteHost) . ' -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ' . $this->getConfig()->release_user . '@' . $this->getHostName($remoteHost);
         $remoteCommand = str_replace('"', '\\"', trim($command));
         $localCommand .= ' " ' . $remoteCommand . ' " ';
         static::log('Run remote command ' . $remoteCommand);
         $log = $this->log;
         $this->status = $this->runLocalCommand($localCommand);
         $this->log = $log . (($log ? PHP_EOL : '') . $remoteHost . ' : ' . $this->log);
         if (!$this->status) {
             return false;
         }
     }
     return true;
 }
예제 #7
0
 /**
  * 执行远程目标机器命令
  *
  * @param string  $command
  * @param integer $delay 每台机器延迟执行post_release任务间隔, 不推荐使用, 仅当业务无法平滑重启时使用
  * @return bool
  */
 public final function runRemoteCommand($command, $delay = 0)
 {
     $this->log = '';
     $needTTY = '-T';
     foreach (GlobalHelper::str2arr($this->getConfig()->hosts) as $remoteHost) {
         $localCommand = sprintf('ssh %s -p %d -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=false %s@%s %s', $needTTY, $this->getHostPort($remoteHost), escapeshellarg($this->getConfig()->release_user), escapeshellarg($this->getHostName($remoteHost)), escapeshellarg($command));
         if ($delay > 0) {
             // 每台机器延迟执行post_release任务间隔, 不推荐使用, 仅当业务无法平滑重启时使用
             static::log(sprintf('Sleep: %d s', $delay));
             sleep($delay);
         }
         static::log('Run remote command ' . $command);
         $log = $this->log;
         $this->status = $this->runLocalCommand($localCommand);
         $this->log = $log . (($log ? PHP_EOL : '') . $remoteHost . ' : ' . $this->log);
         if (!$this->status) {
             return false;
         }
     }
     return true;
 }
 public function getView($userRequest)
 {
     $userResponse = new FrameworkResponse();
     if (GlobalHelper::isRequestAjax()) {
         // json result for ajax call
         $json = array();
         $userRequest->setTemplatePlace("main");
         $placeResponse = FrameworkModuleManager::getModuleViewForTemplateArea(clone $userRequest);
         // if modules are more than one, then view separater is FrameworkModuleManager::$destMod_ModSeparator
         if ($placeResponse->getStatus() == FrameworkResponse::$STATUS__READY) {
             $json[] = $placeResponse->getJson();
         } else {
             //ete modulneric inch vor mek@ asuma sax normal chi orinak problem ka kam STATUS__CHANGE_TEMPLATE, miangamic @ndhatum enq u et veradarznum enq verev
             return $placeResponse;
         }
         $userResponse->setStatus(FrameworkResponse::$STATUS__READY);
         $userResponse->setHtml(json_encode($json));
     } else {
         //mixed html, script, import response for simple request
         $import = "";
         $script = "";
         $html = "<div align='center'>";
         $userRequest->setTemplatePlace("main");
         $placeResponse = FrameworkModuleManager::getModuleViewForTemplateArea(clone $userRequest);
         if ($placeResponse->getStatus() == FrameworkResponse::$STATUS__READY) {
             $html .= $placeResponse->getHtml();
             $import .= $placeResponse->getImport();
             $script .= $placeResponse->getScript();
         } else {
             //ete modulneric inch vor mek@ asuma sax normal chi orinak problem ka kam STATUS__CHANGE_TEMPLATE, miangamic @ndhatum enq u et veradarznum enq verev
             return $placeResponse;
         }
         $html .= "</div>";
         $userResponseView = "<html><head>" . $import . "<script>var _CURRENT_TEMPLATE_ID = '" . self::getTemplateId() . "';</script></head><body style='padding: 0px; margin: 0px;'>" . $html . "<script>" . $script . "</script></body></html>";
         $userResponse->setStatus(FrameworkResponse::$STATUS__READY);
         $userResponse->setHtml($userResponseView);
     }
     return $userResponse;
 }
예제 #9
0
 public static function outputCsv($fileName, $assocData = array())
 {
     $zipFile = '/tmp/' . $fileName . '.zip';
     $zip = new ZipArchive();
     if ($zip->open($zipFile, ZipArchive::CREATE) !== true) {
         throw new Exception("Cannot open zip archive");
     }
     if (is_array($assocData) && !empty($assocData)) {
         foreach ($assocData as $data) {
             if (!isset($data["data"])) {
                 continue;
             }
             $fp = fopen('php://output', 'w');
             if (!$fp) {
                 throw new Exception("Unable to open output buffer");
             }
             ob_start();
             $names = [];
             $types = [];
             foreach ($data["header"] as $column) {
                 $names[] = GlobalHelper::translate($column);
                 $types[] = GlobalHelper::meaningOf($column);
             }
             fputcsv($fp, $names);
             fputcsv($fp, $types);
             foreach ($data['data'] as $values) {
                 fputcsv($fp, $values);
             }
             $string = ob_get_contents();
             $zip->addFromString($data['station']->getName() . ".csv", $string);
             ob_clean();
             fclose($fp);
         }
     }
     $zip->close();
     if (file_exists($zipFile)) {
         header('Pragma: public');
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Cache-Control: private', false);
         header('Content-Type: application/zip');
         header('Content-Disposition: attachment;filename=' . $fileName . '.zip');
         header('Content-Length: ' . filesize($zipFile));
         header("Content-Transfer-Encoding: binary");
         readfile($zipFile);
         ob_flush();
         unlink($zipFile);
     } else {
         throw new Exception("The zip file couldn't handle this much data.");
     }
 }
 protected function modListener__editSweepstake($userRequest)
 {
     if (!GlobalHelper::isRequestAjax()) {
         $this->model->startEdit($userRequest->getHttpRequestParam("sweepstakeId"));
     }
 }
예제 #11
0
 public function get()
 {
     echo json_encode(["url" => GlobalHelper::getforeCastMap($this->input->post("country"))]);
     exit;
 }
 protected function modListener_SweepstakeApp_registerInvitePublish($userRequest)
 {
     if (GlobalHelper::isRequestAjax()) {
         $this->model->registerFacebookInvite($userRequest->getHttpRequestParam("sweepstakeId"), $userRequest->getHttpRequestParam("userId"), $userRequest->getHttpRequestParam("wayId"), json_decode($userRequest->getHttpRequestParam("toUsers"), true));
     }
 }
 public function registerEnter($sweepstakeId, $fbUserId, $comeWayId, $fbUserData)
 {
     $this->setCurrentState(self::$STATE__REGISTER_ENTER);
     $data = $fbUserData;
     $data["fb_user_id"] = $fbUserId;
     $this->userId = FbUser_table::setUser($fbUserId, $data);
     $this->sweepstakeId = $sweepstakeId;
     $fList = "";
     for ($i = 0; $i < count($fbUserData["friends"]); $i++) {
         $fList .= ", '" . $fbUserData["friends"][$i]["id"] . "'";
     }
     if ($fList != "") {
         $fList = substr($fList, 1);
     }
     $sweepstakeData = $this->getSweepstakeData();
     if ($sweepstakeData["bonus_enter_type"] == "0" && $fList != "") {
         SweepstakeUser_table::addPointsByFbUsers($fList, $this->sweepstakeId, $sweepstakeData["bonus_point"]);
     } else {
         if ($comeWayId != "" && $comeWayId != "0") {
             $data = SweepstakeUser_table::getSweepstakeUser(array("sweepstake_id" => $this->sweepstakeId, "user_id" => $this->userId));
             if (count($data) == 0 || $data[0]["come_way"] == "" || $data[0]["come_way"] == "0") {
                 SweepstakeUser_table::addPointByPublishWay($comeWayId, $this->sweepstakeId, $sweepstakeData["bonus_point"]);
             }
         }
     }
     SweepstakeUser_table::registerEnter($this->userId, $this->sweepstakeId, array("come_way" => $comeWayId, "ip" => GlobalHelper::getClientIp()));
     SweepstakeStatistics_table::registerEnter($this->sweepstakeId);
     $fbUserData = FbUser_table::getUser($this->userId);
     mail($fbUserData["email"], "welcome to " . $sweepstakeData["title"], $sweepstakeData["welcome_message"], "Content-type: text/html; charset=UTF-8");
 }