function _submit($stationTag = null) { if ($stationTag === null) { trace("brata missing stationId", __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(400, "missing stationId"); // doesn't return } $station = Station::getFromTag($stationTag); if ($station === false) { trace("brata can't find station stationTag=" . $stationTag, __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(404, "can't find station stationTag=" . $stationTag); // doesn't return } $json = json_getObjectFromRequest("POST"); // won't return if an error happens json_checkMembers("message,team_id", $json); $team = Team::getFromPin($json['team_id']); if ($team === false) { trace("can't find team from team " . $json['team_id']); rest_sendBadRequestResponse(404, "can't find team pin=" . $json['team_id']); } $stationType = new StationType($station->get('typeId'), -1); if ($stationType === false) { trace("can't find station type stationTag = " . $stationTag, __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(500, "can't find station type stationTag=" . $stationTag); } try { $xxxData = XXXData::factory($stationType->get('typeCode')); $msg = $xxxData->brataSubmit($json['message'], $team, $station, $stationType); json_sendObject(array('message' => $msg)); } catch (InternalError $ie) { rest_sendBadRequestResponse($ie->getCode(), $ie->getMessage()); } }
function _edit($OID = 0, $CID = 0) { loginRequireMgmt(); if (!loginCheckPermission(USER::MGMT_STATION)) { redirect("errors/401"); } $item = "Station"; $urlPrefix = "mgmt_station"; $object = new Station(); $object->retrieve($OID, $CID); if (!$object->exists()) { $data['body'][] = "<p>{$item} Not Found!</p>"; } else { $fdata['form_heading'] = "Edit {$item}"; $fdata['object'] = $object; $fdata['actionUrl'] = myUrl("{$urlPrefix}/ops_update"); $fdata['actionLabel'] = "Submit"; $fdata['cancelUrl'] = myUrl("{$urlPrefix}/manage"); $fdata['cancelLabel'] = "Cancel"; $form = View::do_fetch(VIEW_PATH . "{$urlPrefix}/form.php", $fdata); $data['head'][] = View::do_fetch(VIEW_PATH . "{$urlPrefix}/form_js.php"); $data['body'][] = "<h2>Edit {$item}</h2>"; $data['body'][] = $form; } View::do_dump(VIEW_PATH . 'layouts/mgmtlayout.php', $data); }
function _ops_delete($OID = 0, $CID = 0) { $OID = max(0, intval($OID)); $CID = max(0, intval($CID)); $msg = ''; loginRequireMgmt(); if (!loginCheckPermission(USER::MGMT_STATION)) { redirect("errors/401"); } $itemName = "Station"; $urlPrefix = "mgmt_station"; $object = new Station($OID, $CID); if (!$object->exists()) { $msg = "{$itemName} not found!"; } else { transactionBegin(); if ($object->delete()) { transactionCommit(); $msg = "{$itemName} deleted!"; } else { TransactionRollback(); $msg = "{$itemName} delete failed!"; } } redirect("{$urlPrefix}/manage", $msg); }
public function postSavestation() { $station = new Station(); $station->district_id = Input::get('district_id'); $station->name = Input::get('name'); $station->code = Input::get('code'); $station->save(); return Response::json($station); }
static function getAllRPIAsHTMLOptions($itemSelected = -1) { $object = new Station(); $aray = $object->retrieve_many("tag like ? or tag like ? or tag like ?", array("cts%", "hmb%", "cpa%")); $options = ""; foreach ($aray as $item) { $selected = $item->get('tag') == $itemSelected ? "selected" : ""; $options .= '<option value=' . $item->get('tag') . ' ' . $selected . '>' . $item->get("tag"); } return $options; }
/** * Create a station within a country * * @access public * @param int $id (country id) * @return void */ public function create() { $station = new Station(); if ($this->input->post("device_id")) { $station->populate($this->input->post()); if ($station->save()) { Notification::set(Stations::SUCCESS, "The station has been added"); redirect("/stations/"); } } $this->data["regions"] = (new Region())->load(); $this->data["station"] = $station; $this->load->view("stations/create", $this->data); }
public function isEqual(StationState $stationState) { if ($stationState->availableBikes != $this->availableBikes) { return false; } if ($stationState->freeSlots != $this->freeSlots) { return false; } if ($stationState->statusCode != $this->statusCode) { return false; } if ($stationState->station->getId() != $this->station->getId()) { return false; } return true; }
public function init() { $this->getFromMemory(); $criteria = new CDbCriteria(); $criteria->order = "communication_port asc, communication_type asc"; $stations = Station::model()->findAll($criteria); if (count($stations) > 0) { foreach ($stations as $station) { switch ($station->communication_type) { case 'direct': case 'sms': $connection_type = $station->communication_port; break; case 'tcpip': $connection_type = $station->communication_esp_ip . ':' . $station->communication_esp_port; break; case 'gprs': $connection_type = 'poller:' . $station->station_id_code; break; case 'server': $connection_type = 'tcp:' . $station->communication_esp_ip . ':' . $station->communication_esp_port; break; } $this->all_sources[$connection_type] = $connection_type; } } return parent::init(); }
function _ops_update_score() { $OID = max(0, intval($_POST['OID'])); $CID = max(0, intval($_POST['CID'])); $msg = ""; loginRequireMgmt(); if (!loginCheckPermission(USER::MGMT_TEAM)) { redirect("errors/401"); } $itemName = "Team"; $urlPrefix = "mgmt_team"; $object = new Team(); if ($OID) { $object->retrieve($OID, $CID); if (!$object->exists()) { $msg = "{$itemName} not found!"; } else { transactionBegin(); if ($object->updateTotalScore()) { Event::createEvent(EVENT::TYPE_EDIT, $object, Station::getRegistrationStation(), 0, $_POST); // just put the post data into the event transactionCommit(); $msg = "{$itemName} updated!"; } else { transactionRollback(); $msg = "{$itemName} update failed"; } } } else { $msg = "attempting to create team from ops_update_score which is not supported"; } redirect("{$urlPrefix}/manage", $msg); }
function _make_html_table($table, $item, $urlPrefix, $n, &$data) { $dbh = getdbh(); //pagination $stmt = $dbh->query("SELECT count(OID) total FROM {$table}"); $total = $stmt->fetchColumn(); $limit = $GLOBALS['pagination']['per_page']; $data['body'][] = '<p>Showing records ' . ($n + 1) . ' to ' . min($total, $n + $limit) . ' of ' . $total . '</p>'; $data['body'][] = pagination::makePagination($n, $total, myUrl("{$urlPrefix}/manage"), $GLOBALS['pagination']); //table $fields = "type,tag"; $stmt = $dbh->query("SELECT OID,CID,typeId,tag FROM {$table} LIMIT {$n},{$limit}"); if ($stmt === false) { var_dump($dbh->errorInfo()); return; } $tablearr[] = explode(',', $fields); while ($rs = $stmt->fetch(PDO::FETCH_ASSOC)) { $OID = $rs['OID']; $CID = $rs['CID']; $row = null; foreach ($tablearr[0] as $f) { if ($f == "type") { $row[] = Station::getTypeAsText($rs['typeId']); } else { $row[] = htmlspecialchars($rs[$f]); } } $row[] = '<a href="' . myUrl("{$urlPrefix}/edit/{$OID}/{$CID}") . '">Edit</a> | ' . '<a href="javascript:jsconfirm(\'Really Delete ' . $item . '?\',\'' . myUrl("{$urlPrefix}/ops_delete/{$OID}/{$CID}") . '\')">Delete</a>'; $tablearr[] = $row; } $data['body'][] = table::makeTable($tablearr); $data['head'][] = '<script type="text/javascript" src="' . myUrl('js/jsconfirm.js') . '"></script>'; }
/** * Return station list aws, rain * * @return array */ public function getStations() { if (!$this->stations) { $this->stations = Station::prepareStationList(['aws', 'rain'], false); } return $this->stations; }
/** * @access protected * @param Station $station * @param Array $data * @return void */ protected function _debug(Station $station, $data) { require APPPATH . "models/Sources/Measurements.php"; $measurements = new Measurements(); $columns = $measurements->_default_columns; $final = []; $data['station'] = $station->getId(); $data['multiple'] = false; $data['download'] = false; foreach ($columns as $column => $value) { $data['measurement'] = $value['name']; $source = new Source($data); $res = $source->get(); if (isset($res[0]['data'])) { $result[$value["name"]] = count($res[0]['data']); } else { $result[$value["name"]] = 0; } } $region = (new Region())->findById($station->getRegionId()); $final['rows'] = json_encode($result); $final['station'] = $station->getName(); $final['region'] = $region->getName(); $final['created'] = (new DateTime())->format("Y-m-d H:i:s"); $this->_addContent($station->getId(), $final); }
function getStation() { $station = Station::model()->findByPk($this->message_obj->station_id); if ($station) { $this->_station = $station; } }
function _start_challenge($stationTag = null) { if ($stationTag === null) { rest_sendBadRequestResponse(400, "missing station Tag"); // doesn't return } $station = Station::getFromTag($stationTag); if ($station === false) { rest_sendBadRequestResponse(404, "can find station stationTag=" . $stationTag); // doesn't return } $stationType = new StationType($station->get('typeId'), -1); if ($stationType === false) { trace("can't find station type stationTag = " . $stationTag, __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(500, "can't find station type stationTag=" . $stationTag); } $json = json_getObjectFromRequest("POST"); json_checkMembers("team_id,message", $json); $teamPIN = $json['team_id']; $team = Team::getFromPin($teamPIN); if ($team === false) { trace("_start_challenge can't find team teamPin=" . $teamPIN, __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(404, "team not found PIN=" . $teamPIN); // doesn't return } try { $xxxData = XXXData::factory($stationType->get('typeCode')); $msg = $xxxData->startChallenge($team, $station, $stationType); json_sendObject(array('message' => $msg)); } catch (InternalError $ie) { rest_sendBadRequestResponse($ie->getCode(), $ie->getMessage()); } }
public function init() { if ($this->current_controller == 'site' && $this->current_action != 'login') { $total_rain_stations = Station::getTotal('rain'); $total_aws_stations = Station::getTotal('aws'); } $this->data = array('admin' => array('stations' => array("label" => "admin_stations", 'items' => array('stationsave' => array("label" => "admin_create_station"), 'stations' => array("label" => 'admin_stations'), 'stationgroups' => array("label" => 'admin_station_groups'))), 'connections' => array("label" => "admin_connections_connections", 'items' => array('connections' => array("label" => 'admin_connections_connections'), 'connectionslog' => array("label" => 'admin_connections_log'), 'xmllog' => array("label" => 'admin_connections_xmllog'))), 'importmsg' => array("label" => "admin_import_data", 'items' => array('importmsg' => array("label" => 'admin_import_message'), 'importxml' => array("label" => 'admin_import_xml'))), 'msggeneration' => array("label" => "admin_msg_generation", 'items' => array()), 'awsfiltered' => array("label" => "admin_aws_filtered_data", 'items' => array()), 'forwardlist' => array("label" => "message_forwarding_list", 'items' => array()), 'users' => array("label" => "superadmin_users", "items" => array('users' => array('label' => 'superadmin_users'), 'user' => array('label' => 'superadmin_user'))), 'heartbeatreports' => array("label" => "superadmin_heartbeatreport", 'items' => array()), 'sendsmscommand' => array("label" => "superadmin_sendsmscommand", 'items' => array('smscommandsetup' => array("label" => "sms setup", 'items' => array()))), 'setupsensors' => array("label" => "admin_setup", "items" => array('setupsensors' => array("label" => 'admin_setup_setup_sensors'), 'setupother' => array("label" => 'admin_setup_other_settings'), 'dbsetup' => array("label" => 'admin_setup_db_setup'), 'mailsetup' => array("label" => 'admin_setup_mail_setup'), 'dbbackup' => array(), 'checkcomstatus' => array(), 'dbexport' => array(), 'dbexporthistory' => array()))), 'superadmin' => array('users' => array("label" => "superadmin_users", "items" => array('users' => array('label' => 'superadmin_users'), 'user' => array('label' => 'superadmin_user'))), 'access' => array("label" => "superadmin_access", "items" => array('access' => array('label' => 'superadmin_access'), 'accessedit' => array('label' => 'superadmin_accessedit'))), 'syncsettings' => array("label" => "superadmin_syncsettings", "items" => array()), 'longdbsetup' => array("label" => "superadmin_longdb", "items" => array('longdbsetup' => array('label' => 'superadmin_longdbsetup'), 'longdbtask' => array('label' => 'superadmin_longdbtask'))), 'heartbeatreport' => array("label" => "superadmin_heartbeatreport", 'items' => array()), 'config' => array("label" => "superadmin_config", 'items' => array()), 'metrics' => array("label" => "superadmin_metrics", 'items' => array()), 'awsformat' => array("label" => "AWS Format", 'items' => array()), 'exportadminssettings' => array("label" => "admin_import_export_admins_settings", 'items' => array()))); if ($total_aws_stations) { $this->data['site']['awspanel'] = array("label" => "home_aws_panel", 'items' => array()); $this->data['site']['awspanelold'] = array("label" => "home_aws_panel", 'items' => array()); $this->data['site']['awssingle'] = array("label" => "home_aws_single", 'items' => array()); $this->data['site']['awsgraph'] = array("label" => "home_aws_graph", 'items' => array()); $this->data['site']['awstable'] = array("label" => "home_aws_table", 'items' => array()); } if ($total_rain_stations) { $this->data['site']['rgpanel'] = array("label" => "home_rg_panel", 'items' => array()); $this->data['site']['rgtable'] = array("label" => "home_rg_table", 'items' => array()); $this->data['site']['rggraph'] = array("label" => "home_rg_graph", 'items' => array()); } if ($total_aws_stations || $total_rain_stations) { $this->data['site']['msghistory'] = array("label" => "home_msg_history", 'items' => array()); $this->data['site']['export'] = array("label" => "home_export", 'items' => array()); } if ($total_aws_stations) { $this->data['site']['schedule'] = array("label" => "home_schedule", "items" => array('schedule' => array(), 'schedulehistory' => array())); $this->data['site']['stationtypedataexport'] = array("label" => "ODSS export", "items" => array('stationtypedatahistory' => array(), 'schedulehistory' => array())); } $this->data['site']['login'] = array("items" => array()); }
public function init() { $sql = "SELECT `station_id`, CONCAT(`station_id_code`, ' - ', `display_name`) AS `name`\n FROM `" . Station::model()->tableName() . "`\n WHERE `station_type` = 'rain' ORDER BY `station_id_code` "; $stations = CStubActiveRecord::getDbConnect(true)->createCommand($sql)->queryAll(); if ($stations) { $this->stations = CHtml::listData($stations, 'station_id', 'name'); } $this->getFromMemory(); return parent::init(); }
public function generateMessage() { $station = Station::model()->findByPk($this->station_id); $command = 'C'; $command .= $station->station_id_code; $command .= $this->sms_command_code; $command .= implode($this->sms_command_params ? $this->sms_command_params : []); $command .= It::prepareCRC($command); $command = '@' . $command . '$'; return $command; }
public static function selectExpo($expoId) { $stations = Station::selectExpo($expoId); $stationjobs = array(); foreach ($stations as $station) { $stationJob = new StationJob(); $stationJob->setStation($station); $jobs = Job::selectStation($station->expoid, $station->stationid); $stationJob->setJob($jobs[0]); $stationjobs[] = $stationJob; } return $stationjobs; }
function findNearestStations2($location) { global $markers; $debug = false; // the list of stations to return $stations = array(); $maxDist = 0; foreach ($markers as $marker) { $currentStation = new Station($marker, distance2Loc($location, $marker)); if (count($stations) == 3) { $maxDist = max($stations[0]->getDistance(), $stations[1]->getDistance(), $stations[2]->getDistance()); } if (count($stations) < 3) { $stations[] = $currentStation; if (count($stations) < 3) { continue; } } if ($maxDist > $currentStation->getDistance()) { //Find station with maxDist $i = 0; for (; $i < count($stations); $i++) { if ($stations[$i]->getDistance() == $maxDist) { break; } } //Replace station with maxDist with currentStation $stations[$i] = $currentStation; } } if ($debug) { echo "end stations:<br/>\n"; print_r($stations); echo "<br/>\n"; } // this array should be the three closest stations return $stations; }
/** * Takes a JSON-LD station element and transforms it into the style of the old API */ private static function transformNewToOldStyle($newstation, $lang) { $station = new Station(); $id = str_replace("http://irail.be/stations/NMBS/", "", $newstation->{"@id"}); $station->id = "BE.NMBS." . $id; //old-style iRail ids $station->locationX = $newstation->longitude; $station->locationY = $newstation->latitude; $station->{"@id"} = $newstation->{"@id"}; if (isset($newstation->{"alternative"})) { foreach ($newstation->{"alternative"} as $alternatives) { if ($alternatives->{"@language"} == strtolower($lang)) { $station->name = $alternatives->{"@value"}; } } } $station->standardname = $newstation->name; if (!isset($station->name)) { $station->name = $station->standardname; } $station->setHID($id); return $station; }
function _cpaMeasure($stationTag = null) { if ($stationTag === null) { rest_sendBadRequestResponse(400, "missing station Tag"); // doesn't return } $station = Station::getFromTag($stationTag); if ($station === false) { rest_sendBadRequestResponse(404, "can find station stationTag=" . $stationTag); // doesn't return } $stationType = new StationType($station->get('typeId'), -1); if ($stationType === false) { trace("can't find station type stationTag = " . $stationTag, __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(500, "can't find station type stationTag=" . $stationTag); } $json = json_getObjectFromRequest("POST"); json_checkMembers("team_id,message", $json); $teamPIN = $json['team_id']; $team = Team::getFromPin($teamPIN); if ($team === false) { trace("_cpaMeasure can't find team teamPin=" . $teamPIN, __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(404, "team not found PIN=" . $teamPIN); // doesn't return } $stationId = $station->get('OID'); $parms = null; // compute challenge parameters into a message switch ($stationType->get('typeCode')) { case StationType::STATION_TYPE_CPA: $random = new CPAData(); $parms = $random->getItemsToMeasure(); trace("CPA measure generated for team " . $teamPIN . " this data " . print_r($parms, true)); // record the challenge data randomly generated $team->setChallengeData($parms); break; default: trace("_cpaMeasure can't find station tyecode=" . $teamPIN, __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(404, "station tyecode not found =" . $stationType->get('typeCode')); // doesn't return } if (Event::createEvent(Event::TYPE_START, $team, $station, 0) === false) { trace("create event failed", __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(500, "database create failed"); } $msg = $team->expandMessage("PA is trying to escape. Quickly measure [fence=[label]] [building=[label]] and scan Start QR Code.", $parms); trace("message before decode {$msg}", __FILE__, __LINE__, __METHOD__); $msg = $team->encodeText($msg); json_sendObject(array('message' => $msg)); }
function _ops_loaddb() { $urlPrefix = "mgmt_cts_data"; $item = "CTSData"; if (isset($_FILES['csv_file']) && is_uploaded_file($_FILES['csv_file']['tmp_name'])) { // open the csv file for reading $file_path = $_FILES['csv_file']['tmp_name']; $handle = fopen($file_path, 'r'); try { transactionBegin(); $o = new CTSData(); if ($o->truncateTable() === false) { throw new Exception("error on truncate of {$item}"); } while (($data = fgetcsv($handle, 1000, ',')) !== FALSE) { if (count($data) != 8) { throw new Exception("wrong number of value in {$item} record"); } $o = new CTSData(); $station = Station::getFromTag($data[0]); if ($station === false) { throw new Exception("could not find station " . $data[0]); } $o->set('stationId', $station->get('OID')); $o->set('_1st', $data[1]); $o->set('_2nd', $data[2]); $o->set('_3rd', $data[3]); $o->set('_4th', $data[4]); $o->set('_5th', $data[5]); $o->set('tolerance', $data[6]); if ($o->create() === false) { throw new Execption("Can't create {$item} object"); } } transactionCommit(); $msg = "Load {$item} completed"; } catch (Exception $e) { transactionRollback(); $msg = "caught exception " . $e->getMessage(); } // delete csv file unlink($file_path); } else { $msg = "error no file uploaded"; } redirect("{$urlPrefix}/manage", $msg); }
public function prepareTypes() { $types = array(); $types[0] = 'Messages from AWS or RG ("$....@")'; $station_types = array(); $station_timezones = array(); $sql = "SELECT * FROM `" . Station::model()->tableName() . "` WHERE `station_type` = 'rain' ORDER BY `station_id_code` "; $res = Yii::app()->db->createCommand($sql)->queryAll(); if ($res) { foreach ($res as $key => $value) { $types[$value['station_id']] = "LOG from RG: " . $value['station_id_code'] . " (" . $value['display_name'] . ")"; $station_types[$value['station_id']] = $value['station_type']; $station_timezones[$value['station_id']] = $value['timezone_id']; } } return array('source_types' => $types, 'station_types' => $station_types, 'station_timezones' => $station_timezones); }
public function init() { $cur_time = strtotime(date('Y-m-d H:i:s')); $some_time_ago = $cur_time - 7200; $this->all_stations = Station::getList('all', false); $this->date_from = date('m/d/Y', $some_time_ago); $this->date_to = date('m/d/Y', $cur_time); $this->time_from = date('H:i', $some_time_ago); $this->time_to = date('H:i', $cur_time); $this->interval = 30; if ($this->all_stations) { foreach ($this->all_stations as $key => $value) { $this->stations[$value['station_id']] = $value['station_id_code'] . ' ' . $value['display_name']; } } $this->do_import = 0; $this->station_id = $this->all_stations[0]['station_id']; return parent::init(); }
function _join($stationTag = null) { try { if ($stationTag === false) { trace("stationTag not present", __FILE__, __LINE__, __METHOD__); throw new RestException(400, "stationTag not present"); } $station = Station::getFromTag($stationTag); if ($station === false) { trace("_join station not found stationTag=" . $stationTag, __FILE__, __LINE__, __METHOD__); throw new RestException(500, "station not found stationTag=" . $stationTag); } trace("tag=" . $stationTag . " station OID=" . $station->get('OID'), __FILE__, __LINE__, __METHOD__); $json = json_getObjectFromRequest("POST"); // if ($json === NULL) return; json_checkMembers("message_version,station_type,station_url", $json); $rpi = RPI::getFromStationId($station->get('OID')); if ($rpi === false) { // output $rpi = new RPI(); $rpi->set('stationId', $station->get('OID')); $rpi->set_contact_data($stationTag, $json); if ($rpi->create() === false) { trace("create failed", __FILE__, __LINE__, __METHOD__); throw new RestException(500, "join create failed"); } } else { $rpi->set_contact_data($stationTag, $json); if ($rpi->update() === false) { trace("update failed", __FILE__, __LINE__, __METHOD__); throw new RestException(500, "join update failed"); } } rest_sendSuccessResponse(202, "Accepted", "{$stationTag} has joined M"); } catch (RestException $e) { rest_sendBadRequestResponse($e->statusCode, $e->statusMsg); // doesn't return } }
function actionIndex() { ini_set('memory_limit', '-1'); print 'Checking `listener_log` table upgrade....<br/>'; $sql = "SHOW COLUMNS FROM `" . ListenerLog::model()->tableName() . "` LIKE 'is_last'"; $res = Yii::app()->db->createCommand($sql)->queryAll(); if (!$res) { print '<br/><br/>Checked - requires update.<br/><br/>Attention! Script going to make small update to your database.... Please, be patient, don\'t use system before script is completed.'; $sql = "ALTER TABLE `" . ListenerLog::model()->tableName() . "` ADD `is_last` tinyint(1) NOT NULL DEFAULT '0' AFTER `is_processed`"; Yii::app()->db->createCommand($sql)->query(); $sql = "SELECT * FROM `" . Station::model()->tableName() . "`"; $stations = Yii::app()->db->createCommand($sql)->queryAll(); if ($stations) { foreach ($stations as $key => $value) { ListenerLog::updateIsLastForStation($value['station_id']); } } print '<br><br>.....<br><br>Done!. <br/><br/>You can continue work with <a href="' . It::baseUrl() . '">Delairco</a>'; } else { print '<br/>Checked - doesn\'t require update. <br/><br/>You can continue work with <a href="' . It::baseUrl() . '">Delairco</a>'; } }
public function init() { preg_match('/^POLLER\\:([a-zA-Z0-9]{1,5})$/i', $this->source, $matches); $station = Station::model()->findByAttributes(array('station_id_code' => strtoupper($matches[1]))); if (is_null($station)) { $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ': Station is not found', array('station_code' => strtoupper($matches[1]))); return false; } else { $this->_connector = new TcpIpPollerConnector($this->_logger, $station, 60); if (Yii::app()->params['sms_params']['enabled'] === true) { $phpSerial = new PhpSerial($this->_logger); $this->_smsMessageSender = new SmsMessageSender($this->_logger, $this->listener, $phpSerial, Yii::app()->params['com_connect_params'], Yii::app()->params['sms_params']['serial_port'], $station->phone_number, $station->sms_message); } else { $this->_logger->log(__CLASS__ . ' ' . __METHOD__ . ' Reset SMS message is disabled'); } } // $this->_connector = new TcpIpServerConnector($this->_logger, $matches[1], $matches[2], $matches[3]); $this->_logger->log(__CLASS__ . ' ' . __METHOD__); $this->settings = Settings::model()->find(); $this->synchronization = new Synchronization(); return true; }
function _ops_update() { $OID = max(0, intval($_POST['OID'])); $CID = max(0, intval($_POST['CID'])); $msg = ''; loginRequireMgmt(); if (!loginCheckPermission(USER::MGMT_STATION)) { redirect("errors/401"); } $itemName = "Station"; $urlPrefix = "mgmt_station"; $object = new Station(); if ($OID) { $object->retrieve($OID, $CID); if (!$object->exists()) { $msg = "{$itemName} not found!"; } else { transactionBegin(); $object->merge($_POST); if ($object->update()) { transactionCommit(); $msg = "{$itemName} updated!"; } else { transactionRollback(); $msg = "{$itemName} update failed"; } } } else { $object->merge($_POST); transactionBegin(); if ($object->create()) { transactionCommit(); $msg = "{$itemName} created!"; } else { transactionRollback(); $msg = "{$itemName} Create failed"; } } redirect("{$urlPrefix}/manage", $msg); }
function _register() { $json = json_getObjectFromRequest("POST"); json_checkMembers("team_id,message", $json); $teamPIN = $json['team_id']; if ($teamPIN === null) { trace("missing PIN", __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(400, "missing team PIN"); // doesn't return } $team = Team::getFromPin($teamPIN); if ($team === false) { trace("_can't find team PIN=" . $teamPIN, __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(404, "missing can't find team PIN=" . $teamPIN); // doesn't return } // we are assuming that the QR code won't include the station tag. $station = Station::getRegistrationStation(); if ($station === false) { trace("can't find registration station", __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(500, "can't find registration station"); } $points = 3; if (Event::createEvent(Event::TYPE_REGISTER, $team, $station, $points) === false) { trace("createEvent Fails", __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(500, "could not create event object"); } $stationType = StationType::getFromTypeCode($station->get('tag')); trace("registration complete", __FILE__, __LINE__, __METHOD__); $team->endChallenge(); // clear any stale challenge data $team->_updateScore($stationType, $points); $msg = $team->expandMessage($stationType->get('instructions'), null); $msg = $team->encodeText($msg); json_sendObject(array('message' => $msg)); }
/** * Listado de usuarios imetos * @param type $is_admin is boolean * @param type $userid is number */ public static function users_list($is_admin = false, $userid = 0) { //$enum_tipos_usuarios=getEnumOptions('usuarios', 'usertype'); if ($users = User::getAll($is_admin)) { echo "\n <h1>Listado de usuarios iMetos</h1>\n <table class=\"table table-striped table-hover table-bordered table-condensed\">\n <tr> \n <th> </th>\n <th>Usuario</th>\n <th>Mails</th>\n </tr>"; foreach ($users as $user) { echo "\n <tr>\n <td align=\"center\">\n <a class=\"link-tabla\" href=\"javascript:borrar_usuario('{$user->getId()}');\">\n <i class=\"fa fa-trash\"></i>\n </a> "; if ($user->getEnableFTP()) { echo " <a class=\"link-tabla\" href=\"javascript:realizar_informe('{$user->getUserFTP()}');\" title=\"Revisar sondas detenidas\">\n <i class=\"fa fa-terminal\"></i>\n </a> "; } echo " <a class=\"link-tabla\" href=\"javascript:mostrar_ocultar('conf_usuario_{$user->getId()}');\" title=\"Configuración de usuario\">\n <i class=\"fa fa-user\"></i>\n </a> "; echo " <a class=\"link-tabla\" href=\"javascript:mostrar_ocultar('conf_exporta_{$user->getId()}');\" title=\"Configuración de estaciones\">\n <i class=\"fa fa-pencil\"></i>\n </a>"; echo " </td>\n <td>{$user->getUsername()}</td>\n <td>{$user->getEmails()}</td>\n </tr>\n <tr>\n <td colspan=\"6\">\n <div id=\"conf_usuario_{$user->getId()}\" style=\"display:none\">\n <form name=\"user_edit\" method=\"post\" action=\"/users/edit/{$user->getId()}\">"; User::formulario_editar_usuario($user); echo " <div class=\"panel-body\" style=\"text-align:right\">\n <div class=\"form-group\">\n <button type=\"submit\" name=\"save_user\" class=\"btn btn-default\"><i class=\"fa fa-floppy-o\" aria-hidden=\"true\"></i> Guardar usuario</button> \n <button type=\"button\" name=\"close\" class=\"btn btn-default\" onClick=\"javascript:mostrar_ocultar('conf_usuario_{$user->getId()}');\"><i class=\"fa fa-times\" aria-hidden=\"true\"></i> Cerrar</button> \n </div>\n </div>\n </form>"; echo " </div>\n <div class=\"conf_exporta\" id=\"conf_exporta_{$user->getId()}\" style=\"display:none\">"; // si esta habilitado muestra info de estaciones if ($user->getEnableMySQL()) { $BD = new IMETOS($user->getIdMySQL(), $user->getServerMySQL(), $user->getDatabaseMySQL(), $user->getUserMySQL(), $user->getPasswMySQL()); if ($stations = Station::getAll($BD, $user->getId())) { Station::listAll($BD, $stations, $user); } } echo " </div> <!-- cierre de div conf_exporta -->\n </td>\n </tr>"; } echo "</table>"; } else { echo "No se pudo cargar los usuarios<br>"; } }