function lastUser() { $db = new DBHandler(); $stmt = $db->query("SELECT u.id, u.username, u.email, u.publicEmail, u.active FROM `user` u order by id DESC limit 5;"); $data = ""; while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $data = $data . $row[0] . "," . $row[1] . "," . $row[2] . "," . $row[3] . "," . $row[4] . ";"; } $stmt->closeCursor(); echo $data; }
private function get_db_instance() { //define( 'ROOT_DIR', dirname(__FILE__) ); require_once dirname(__FILE__) . '/../connect.php'; // Require needed classes $dbh = new DBHandler(); // Create DBHandler // Check if database connection established successfully if ($dbh->getInstance() === null) { die("Fatal error : no database connection"); } return $dbh; }
/** * Retrieve a DBHandler instance * * @return $instance; */ public static function getInstance() { if (!self::$instance) { self::$instance = new PDO("mysql:host=" . self::DB_SERVER . ";dbname=" . self::DB_DATABASE, self::DB_SERVER_USERNAME, self::DB_SERVER_PASSWORD); self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } return self::$instance; }
function checkIfUserRegistered($uname) { if (DBHandler::checkIfUserRegistered($uname)) { $_SESSION['registered'] = 1; redirectUser('entries.php'); } else { showRegistrationForm(); } }
function registerUser($keys, $values) { $msg = DBHandler::registerUser($_SESSION['uname'], $keys, $values); if ($msg == '1') { $_SESSION['registered'] = 1; redirectUser('entries.php'); } else { redirectUser('register.php'); } }
/** * Constructor * * @param object Id $id * @param array $config * @return void * @access public * @since 10/4/07 */ public function __construct(Id $id, array $config, DBHandler $dbc, $idMgr) { $this->id = $id; $this->config = $config; $this->dbc = $dbc; $this->idMgr = $idMgr; switch ($this->config['db_type']) { case MYSQL: $dbClass = "MySQLDatabase"; break; case POSTGRESQL: $dbClass = "PostgreSQLDatabase"; break; default: throw new ConfigurationErrorException('Unknown database type \'' . $this->config['db_type'] . '\'.'); } $this->dbIndex = $dbc->addDatabase(new $dbClass($this->config['host'], $this->config['db'], $this->config['user'], $this->config['password'])); $this->dbc->pConnect($this->dbIndex); $this->createRecordStructures(); }
function loginUser($uname, $pwd) { if (DBHandler::checkLogin($uname, $pwd)) { $_SESSION['isLoggedIn'] = 1; $_SESSION['uname'] = $uname; redirectUser('register.php'); } else { $_SESSION['loginerror'] = "Invalid Login"; redirectUser('login.php'); } }
public function getByID($id, $fields = NULL, $safe_fields = false) { if (is_null($fields)) { $fields = $this->default_fields; $safe_fields = true; } $fields = DBHandler::createFieldString($fields, "", $safe_fields); $res = $this->dbh->query("SELECT {$fields} FROM organization_user WHERE organization_id = ? AND id = ?", array($this->organization_id, $id)); if (is_array($res) && count($res)) { return $res[0]; } }
/** * Returns testcase given its hash * * @return TestCase */ function getTestCaseByHash($testCaseHash) { $this->dbHandler = DBHandler::getInstance(); $sql = "SELECT * FROM testcase\n WHERE id = " . $this->dbHandler->quote($testCaseHash); $result = $this->dbHandler->query($sql); if ($result) { $result->setFetchMode(PDO::FETCH_OBJ); $row = $result->fetch(); return new TestCase($row->filename, null, $testCaseHash); } return; }
function main() { echo "In main\n"; _make_conf(); // read conf $conf_file = './my_first.conf'; $conf = read_conf($conf_file); print "got conf\n"; // db connect //$dbh = db_connect($conf['database']); $dbh = new DBHandler($conf['database']); if ($dbh) { print "Connected to " . $dbh->get_host() . "\n"; } insert_department($dbh); get_all_departments($dbh); update_department($dbh); get_specific_departments($dbh); get_one_department($dbh); get_all_departments_two($dbh); delete_department($dbh); get_departments_keyed($dbh); }
/** * Installs tables with default user * @param $db_type */ public function install($db_type) { $f3 = \Base::instance(); $db_type = strtoupper($db_type); if ($db = DBHandler::instance()->get($db_type)) { $f3->set('DB', $db); } else { $f3->error(256, 'no valid Database Type specified'); } // setup the models \Model\User::setup(); \Model\Payload::setup(); \Model\Webot::setup(); // create demo admin user $user = new \Model\User(); $user->load(array('username = ?', 'mth3l3m3nt')); if ($user->dry()) { $user->username = '******'; $user->name = 'Framework Administrator'; $user->password = '******'; $user->email = '*****@*****.**'; $user->save(); //migrate payloads successfully $payload_file = $f3->ROOT . $f3->BASE . '/db_dump_optional/mth3l3m3nt_payload'; if (file_exists($payload_file)) { $payload = new \Model\Payload(); $payload_file_data = $f3->read($payload_file); $payloadarray = json_decode($payload_file_data, true); foreach ($payloadarray as $payloaddata) { $payload->pName = $payloaddata['pName']; $payload->pType = $payloaddata['pType']; $payload->pCategory = $payloaddata['pCategory']; $payload->pDescription = $payloaddata['pDescription']; $payload->payload = $payloaddata['payload']; $payload->save(); //ensures values set to null before continuing update $payload->reset(); } //migtate payloads \Flash::instance()->addMessage('Payload StarterPack: ,' . 'All Starter Pack Payloads added New database', 'success'); } else { \Flash::instance()->addMessage('Payload StarterPack: ,' . 'StarterPack Database not Found no payloads installed ', 'danger'); } \Flash::instance()->addMessage('Admin User created,' . ' username: mth3l3m3nt, password: mth3l3m3nt', 'success'); } \Flash::instance()->addMessage('New Database Setup Completed', 'success'); }
} //handles all pagination \Template::instance()->extend('pagebrowser', '\\Pagination::renderTag'); \Template\FooForms::init(); if (isset($writeableErr)) { header('Content-Type: text;'); die(implode("\n", $writeableErr)); } //Initialize some F3 Settings $f3->set('FLASH', Flash::instance()); $web = Web::instance(); //Database Setup From our Config Class Instance $cfg = Config::instance(); $f3->set('CONFIG', $cfg); if ($cfg->ACTIVE_DB) { $f3->set('DB', DBHandler::instance()->get($cfg->ACTIVE_DB)); } else { $f3->error(500, 'Sorry, but there is no active DB setup.'); } /////////////// // frontend // /////////////// $f3->route(array('GET /', 'GET /@page', 'GET /payloads', 'GET /page/@page'), 'Controller\\Payload->getList'); // view single $f3->route(array('GET /payload/@id'), 'Controller\\Payload->viewSingle'); $f3->route(array('GET /payload/search'), 'Controller\\Payload->search_frontend'); /////////////// // backend // /////////////// if (\Controller\Auth::isLoggedIn()) { // general CRUD operations
<?php $DBHandler = parse_ini_file($root_dir . '/config/database.ini', true); $firstHost = $DBHandler["firstDB"]["host"]; $firstLogin = $DBHandler["firstDB"]["login"]; $firstPassword = $DBHandler["firstDB"]["password"]; $secondHost = $DBHandler["secondDB"]["host"]; $secondLogin = $DBHandler["secondDB"]["login"]; $secondPassword = $DBHandler["secondDB"]["password"]; require_once $root_dir . '/config/bootstrap.php'; $dbHandlerOgicom = new DBHandler($secondHost, $secondLogin, $secondPassword); $ogicomHandler = $dbHandlerOgicom->getDb(); $dbHandlerLinuxPl = new DBHandler($firstHost, $firstLogin, $firstPassword); $linuxPlHandler = $dbHandlerLinuxPl->getDb(); /* using Singleton $linuxPlDbHandler=bothDbHandler::getInstance('linuxPl', $firstHost, $firstLogin, $firstPassword); $ogicomDbHandler=bothDbHandler::getInstance('ogicom', $secondHost, $secondLogin, $secondPassword); */
/** * Adding Middle Layer to authenticate every request * Checking if the request has valid api key in the 'Authorization' header */ function authenticate(\Slim\Route $route) { // Getting request headers $headers = apache_request_headers(); $response = array(); $app = \Slim\Slim::getInstance(); // Verifying Authorization Header if (isset($headers['Authorization'])) { $db = new DBHandler(); // get the api key $apikey = $headers['Authorization']; // validating api key if (!$db->isValidApiKey($apikey)) { // api key is not present in users table $response["error"] = true; $response["message"] = "Zugriff verweigert! Falscher API-Key!"; echoRespnse(401, $response); $app->stop(); } else { global $userid; // get user primary key id $user = $db->getUserId($apikey); if ($user != NULL) { $userid = $user; } } } else { // api key is missing in header $response["error"] = true; $response["message"] = "Zugriff verweigert! API-Key fehlt!"; echoRespnse(400, $response); $app->stop(); } }
public function saveOutbox($lead, $data, $txnId) { if ($data) { $db = new DBHandler(); $db->connect(); $pdo = $db->getConnection(); $msg_type = isset($data["msg_type"]) ? $data["msg_type"] : ""; $mobile = isset($data["mobile"]) ? $data["mobile"] : ""; $network = isset($data["network"]) ? $data["network"] : ""; $shortcode = isset($data["shortcode"]) ? $data["shortcode"] : ""; $date_received = isset($data["date_received"]) ? $data["date_received"] : ""; $channel = isset($data["channel"]) ? $data["channel"] : ""; $message_id = isset($data["message_id"]) ? $data["message_id"] : ""; $message = isset($data["message"]) ? $data["message"] : ""; $full_msg = isset($data["full_msg"]) ? $data["full_msg"] : ""; $msg_status = isset($data["msg_status"]) ? $data["msg_status"] : ""; $status = isset($data["status"]) ? $data["status"] : ""; $id = $lead ? $lead['id'] : 0; $query = "INSERT INTO `sms_outbox` ( message_type, mobile_number, network, shortcode, date_received, channel, message_id, message, full_msg, msg_status, status)\n VALUES ( :message_type, :mobile_number, :network, :shortcode, :date_received, :channel, :message_id, :message, :full_msg, :msg_status, :status);"; $sql = $pdo->prepare($query); $result = $sql->execute(array(":message_type" => $msg_type, ":mobile_number" => $mobile, ":network" => $network, ":shortcode" => $shortcode, ":date_received" => $date_received, ":channel" => $channel, ":message_id" => $message_id, ":message" => $message, ":full_msg" => $full_msg, ":msg_status" => $msg_status, ":status" => $status)); $sql1 = "UPDATE `tnf_leads`\n SET contact=?\n WHERE transaction_id=?"; $query1 = $pdo->prepare($sql1); $query1->execute(array($mobile, $txnId)); return $result; } }
} if (!isset($_SESSION['log'])) { if (isset($_POST['login']) and isset($_POST['password'])) { $userLogin = trim(htmlspecialchars($_POST['login'])); $userPassword = trim(htmlspecialchars($_POST['password'])); $dbHandlerLinuxPl = new DBHandler($firstHost, $firstLogin, $firstPassword); $dbResult = $dbHandlerLinuxPl->getUserData($userLogin, $userPassword); $resNumb = $dbResult->rowCount(); if ($resNumb > 0) { $finalResult = $dbResult->fetch(PDO::FETCH_ASSOC); $_SESSION['log'] = 1; $dbResult->closeCursor(); } else { header('Location:templates/signin2.html'); } } else { $userLogin = $_POST['login']; $userPassword = $_POST['password']; $dbHandlerLinuxPl = new DBHandler($firstHost, $firstLogin, $firstPassword); $dbResult = $dbHandlerLinuxPl->getUserData($userLogin, $userPassword); $resNumb = $dbResult->rowCount(); if ($resNumb > 0) { $finalResult = $dbResult->fetch(PDO::FETCH_ASSOC); $_SESSION['log'] = 1; $dbResult->closeCursor(); } else { header('Location:templates/signIn.html'); } } } unset($dbHandlerLinuxPl);
if ($res == USER_CREATE_FAILED) { $response = array("error" => true, "message" => "Oops! An error occurred while registering"); echoResponse(200, $response); } else { if ($res == USER_ALREADY_EXISTED) { $response["error"] = true; $response["message"] = "Sorry, this email already existed"; echoResponse(200, $response); } } } }); $app->post('/login', function () use($app) { $json = $app->request->getBody(); $input = json_decode($json, true); $db = new DBHandler(); $res = $db->login($input); if ($res == -1) { $response = array("error" => true, "message" => "Login Failed"); echoResponse(201, $response); } else { $response["error"] = false; $response["message"] = "Success"; $response["data"] = $res; echoResponse(200, $response); } }); /** * Get all timeline events * method GET * params - none
<?php include 'admin_header.php'; ?> <?php include_once $_SERVER['DOCUMENT_ROOT'] . "/tnfraceapp/src/Utility/Constant.php"; include_once ROOT_DIR . "/src/Database/DBHandler.php"; $db = new DBHandler(); $db->connect(); $data = $db->getAllPromoContestants(); ?> <div class="row"> <div class="large-11 large-centered columns promoContent"> <?php include 'includes/admin_panelhead.php'; ?> <div class="panel panel-content raceDetails"> <?php include 'includes/admin_head.php'; ?> <ul class="tabs" data-tab> <li class="tab-title active"><a href="#pending" id="clickPanel">Pending</a></li> <li class="tab-title"><a href="#approved" id="clickPanel">Approved</a></li> <li class="tab-title"><a href="#rejected" id="clickPanel">Rejected</a></li> </ul> <div class="tabs-content">
<?php include_once $_SERVER['DOCUMENT_ROOT'] . "/tnfraceapp/src/Utility/Constant.php"; include_once ROOT_DIR . "/src/Database/DBHandler.php"; if (isset($_POST) && $_SERVER['REQUEST_METHOD'] == 'POST') { $db = new DBHandler(); $db->connect(); if ($db->isConnected()) { if ($_POST['id']) { $d = $db->retrieveEntryById($_POST['id']); if ($d) { $ctr = $d['views']; $ctr++; $db->updatePromoContestantViews($_POST['id'], $ctr); echo json_encode($ctr); exit; } else { echo json_encode(0); exit; } } else { echo json_encode(-1); exit; } } else { exit; } } else { if (isset($_SERVER['HTTP_REFERER'])) { header('Location: ' . $_SERVER['HTTP_REFERER']); } else {
<?php include_once "../php/DBHandler.php"; include_once "../php/Scheduler.php"; include_once "../php/ProcessHandler.php"; /*Haendler inizialesierung*/ $bts_handler = new DBHandler(); $bts_handler->connect(); $bts_handler->delete_old(); $bts_scheduler = new Scheduler(); $bts_ProcessHandler = new ProcessHandler(); $bts_ProcessHandler->setDummyProcessArray($bts_handler->get_processes()); /*Fuer Fehlerabfrage benoetigte Member*/ $fehlerDummy = ''; $fehlerRandom = ''; $fehlerRR = ''; $fehlerScheduler = ''; $fehler = false; $openTab = 1; /*Standart ueberpruefung erleichtern*/ function ueberpruefung($value) { return isset($_POST[$value]) && !is_array($_POST[$value]) && $_POST[$value] != ''; } if (isset($_POST['senden'])) { if ($_POST['senden'] == 'Speichern') { if (!(ueberpruefung('name') && strlen($_POST['name']) > 0 && strlen($_POST['name']) < 11)) { $fehlerDummy .= '<a>Bitte geben Sie einen Namen ein.</a><br />'; $fehler = true; } if (!(ueberpruefung('cpulaufzeit') && $_POST['cpulaufzeit'] + 0 > 0 && $_POST['cpulaufzeit'] + 0 < 501)) {
<?php include_once "../../../../src/Database/DBHandler.php"; $db = new DBHandler(); $db->connect(); if ($db->isConnected()) { $params = array("action" => "Logout", "module" => "TNF Microsite " . $_COOKIE['branch'], "content" => "", 'ip' => $_SERVER['REMOTE_ADDR']); $db->updateLogs($_COOKIE['user_id'], $params, $_COOKIE['userfname'], $_COOKIE['userlname']); } unset($_COOKIE); setcookie("user_id", null, -1, "/admin"); setcookie("user", null, -1, "/admin"); setcookie("userfname", null, -1, "/admin"); setcookie("userlname", null, -1, "/admin"); setcookie("branch", null, -1, "/admin"); setcookie("level", null, -1, "/admin"); header('Location: http://' . $_SERVER['HTTP_HOST']); exit;
<?php session_start(); require_once 'DBHandler.php'; require_once 'AuthHandler.php'; require_once 'connectionInfo.private.php'; $dbHandler = new DBHandler($host, $user, $password, $db); $authHandler = new AuthHandler($dbHandler); ?> <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>User Notes</title> <link rel="stylesheet" href="notes.css"/> </head> <body> <header class="header"> <?php // ================================================================================================================ // LOGIN if (isset($_POST['username']) && isset($_POST['password'])) { // try to log in. if ($authHandler->loginUser($_POST['username'], $_POST['password'])) { echo "<div class='notification success'>Hi " . $authHandler->getUserName() . ", you are now logged in!</div>"; } else { echo "<div class='notification error'>We're sorry, but the log in failed. Is the password correct?</div>"; } } // LOGOUT
/** * Constructor * * @return confElement */ function confElement($userId) { $this->dbHandler = DBHandler::getInstance(); $this->userId = $userId; }
<?php include_once "../../../../src/Utility/Constant.php"; include_once "../../../../src/Database/DBHandler.php"; if (isset($_POST) && $_SERVER['REQUEST_METHOD'] == 'POST') { $db = new DBHandler(); $db->connect(); if ($db->isConnected()) { $data = $db->retrieveByCode($_POST['coupon']); if ($data != false) { echo json_encode($data); exit; } else { echo 0; exit; } } else { exit; } }
<?php namespace directory; require 'DBHandler.php'; require 'vendor/autoload.php'; //if (session_status() === PHP_SESSION_ACTIVE) ? TRUE : FALSE; session_start(); $_SESSION['id'] = $_GET['userID']; $servername = 'localhost'; $dbname = 'directory'; $dBUsername = '******'; $dBPassword = ''; $dbConn = new DBHandler("mysql:host={$servername};dbname={$dbname}", $dBUsername, $dBPassword); $dbConn->connect(); $command = "SELECT * from Employee where User_Name LIKE :username"; $params = array(":username" => $_GET['userID']); $result = $dbConn->executeWithReturn($command, $params); foreach ($result as $res) { } $command = "SELECT Name, Family_Name, User_Name, Photo from Employee"; $params = array(); $result2 = $dbConn->executeWithReturn($command, $params); foreach ($result2 as $res2) { } $command = "SELECT * from Social_Network where UserID LIKE :userID"; $params = array(":userID" => $_GET['userID']); $result3 = $dbConn->executeWithReturn($command, $params); foreach ($result3 as $res3) { } $command = "SELECT * from Membership where Username LIKE :userID";
/** * Constructor of the class * * @param User $user The connected user * * @return Void */ function __construct(User $user) { $this->user = $user; $this->dbHandler = DBHandler::getInstance(); }
<?php session_start(); include 'Database/DBHandler.php'; include 'Mailer/MailerHandler.php'; include 'Spreadsheet/SpreadsheetHandler.php'; if (isset($_POST) && !empty($_POST)) { $db = new DBHandler(); $db->connect(); $mail = new MailerHandler(); $ss = new SpreadsheetHandler(); if ($_POST['leaseType'] == 'short-term') { $result = $db->insertBookingLead($_POST); $mailRes = $mail->sendBookingNotif($_POST); $ssRes = $ss->addBookingLeads($_POST); } elseif ($_POST['leaseType'] == 'long-term') { $result = $db->insertAppointmentLead($_POST); $mailRes = $mail->sendAppointmentNotif($_POST); $ssRes = $ss->addAppointmentLeads($_POST); } if ($result == 1) { echo json_encode(1); } else { echo json_decode(-1); } $_SESSION['thank-you'] = 1; } else { header("Location: " . get_site_url()); }
/** * Retreives testCases hashs from db for given testSuite * * @param TestSuite $testSuite Target test suite to populate * * @return Array */ function getTestCasesHashs($testSuite) { $this->dbHandler = DBHandler::getInstance(); $sql = "SELECT id FROM testcase WHERE testsuite_id like '%" . $testSuite->getTestSuiteName() . "%'"; $result = $this->dbHandler->query($sql); if ($result && $result->rowCount() > 0) { return $result->fetchAll(PDO::FETCH_COLUMN, 0); } return array(); }
<?php session_start(); use views\helpers\PathHelper; require_once dirname(dirname(dirname(__FILE__))) . '/views/helpers/PathHelper.php'; $path = new PathHelper(); require_once $path->getModelPath() . 'DBHandler.php'; require_once $path->getModelPath() . 'AuthHandler.php'; require_once $path->getConfigPath() . 'connectionInfo.private.php'; $dbHandler = new DBHandler($host, $user, $password, $db); $authHandler = new AuthHandler($dbHandler); if (isset($_POST['title']) && isset($_POST['content'])) { if ($id = $dbHandler->insertNote($_POST['title'], $_POST['content'], $authHandler->getUserId())) { $result = array("id" => $id, "title" => $_POST['title'], "content" => $_POST['content']); } else { header("HTTP/1.1 501 Could not modify object"); $result = array("error" => "An error occurred saving your note."); } } else { // title and content were not set header("HTTP/1.1 502 Empty parameter set"); $result = array("error" => "Please provide a title and content for your note."); } header("Content-Type: application/json; charset=UTF-8"); echo json_encode($result);
<?php use views\helpers\PathHelper; session_start(); require_once dirname(__FILE__) . '/app/views/helpers/PathHelper.php'; $path = new PathHelper(); require_once $path->getModelPath() . 'DBHandler.php'; require_once $path->getModelPath() . 'AuthHandler.php'; require_once $path->getConfigPath() . 'connectionInfo.private.php'; $dbHandler = new DBHandler($host, $user, $password, $db); $authHandler = new AuthHandler($dbHandler); ?> <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>User Notes</title> <link rel="shortcut icon" type="image/x-icon" href="<?php echo $path->getAssetPath(); ?> /favicon.ico"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"> <link rel="stylesheet" href="<?php echo $path->getAssetPath(); ?> /css/notes.css"/> </head> <body> <header class="header"> <?php