Ejemplo n.º 1
0
 /**
  * @desc returns the currently opened <code>DBConnection</code> instance or if none,
  * creates a new one
  * @return DBConnection the currently opened <code>DBConnection</code> instance
  */
 public static function get_db_connection()
 {
     if (self::$db_connection === null) {
         $data = self::load_config();
         self::init_factory($data['dbms']);
         self::$db_connection = self::new_db_connection();
         self::$db_connection->connect($data);
     }
     return self::$db_connection;
 }
 /**
  * Connect
  *
  * @param   bool reconnect default FALSE
  * @return  bool success
  * @throws  rdbms.SQLConnectException
  */
 public function connect($reconnect = FALSE)
 {
     if (is_resource($this->handle)) {
         return TRUE;
     }
     // Already connected
     if (!$reconnect && FALSE === $this->handle) {
         return FALSE;
     }
     // Previously failed connecting
     $this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECT, $reconnect));
     if ($this->flags & DB_PERSISTENT) {
         $this->handle = mssql_pconnect($this->dsn->getHost(), $this->dsn->getUser(), $this->dsn->getPassword());
     } else {
         $this->handle = mssql_connect($this->dsn->getHost(), $this->dsn->getUser(), $this->dsn->getPassword());
     }
     if (!is_resource($this->handle)) {
         $e = new SQLConnectException(trim(mssql_get_last_message()), $this->dsn);
         xp::gc(__FILE__);
         throw $e;
     }
     xp::gc(__FILE__);
     $this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECTED, $reconnect));
     return parent::connect();
 }
Ejemplo n.º 3
0
 static function fetchAll()
 {
     DBConnection::connect();
     $result = DBConnection::select('SELECT * FROM post');
     $posts = [];
     if ($result) {
         foreach ($result as $post) {
             array_push($posts, new Post($post->id, $post->title, false));
         }
     }
     return $posts;
 }
Ejemplo n.º 4
0
 static function fetchAll()
 {
     DBConnection::connect();
     $result = DBConnection::select('SELECT * FROM user');
     $users = [];
     if ($result) {
         foreach ($result as $user) {
             array_push($users, new User($user->id, $user->pseudo, false));
         }
     }
     return $users;
 }
Ejemplo n.º 5
0
 public static function getEvents()
 {
     $db = new DBConnection();
     $link = $db->connect();
     if ($link != null) {
         $query = "SELECT event_name,start_date,end_date,start_time FROM event";
         $result = $link->query($query);
         $result_array = array();
         $index = 0;
         while ($row = mysqli_fetch_assoc($result)) {
             $result_array[$index] = $row;
             $index = $index + 1;
         }
         $db->closeConnection();
         return $result_array;
     }
     $db->closeConnection();
     return null;
 }
Ejemplo n.º 6
0
 /**
  * Connect
  *
  * @param   bool reconnect default FALSE
  * @return  bool success
  * @throws  rdbms.SQLConnectException
  */
 public function connect($reconnect = FALSE)
 {
     if ($this->handle->connected) {
         return TRUE;
     }
     // Already connected
     if (!$reconnect && NULL === $this->handle->connected) {
         return FALSE;
     }
     // Previously failed connecting
     try {
         $this->handle->connect($this->dsn->getUser(), $this->dsn->getPassword());
         $this->_obs && $this->notifyObservers(new DBEvent(__FUNCTION__, $reconnect));
     } catch (IOException $e) {
         $this->handle->connected = NULL;
         $this->_obs && $this->notifyObservers(new DBEvent(__FUNCTION__, $reconnect));
         throw new SQLConnectException($e->getMessage(), $this->dsn);
     }
     return parent::connect();
 }
Ejemplo n.º 7
0
function InitPage($login)
{
    $page = $login;
    $lastPage = GetSessionVar('s_pageName');
    $User = GetSessionVar('User');
    if (empty($GLOBALS['page'])) {
        $GLOBALS['page'] = '';
    }
    if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], "login.php") == FALSE && strpos($_SERVER['REQUEST_URI'], "callback") == FALSE) {
        SetSessionVar('s_pageLast', $_SERVER['REQUEST_URI']);
    }
    $dbc = new DBConnection();
    global $dbh;
    $dbh = $dbc->connect();
    if ($login == "login" && !$User) {
        # Login required, but the User object isn't there.
        if (isset($_COOKIE[COOKIE_REMEMBER])) {
            # Try to fetch username from session
            require_once dirname(__FILE__) . "/../classes/system/session.class.php";
            $Session = new Session();
            if (!$Session->validate()) {
                exitTo("login.php");
            } else {
                $User = new User();
                $User->loadFromID($Session->_userid);
                SetSessionVar("User", $User);
            }
        } else {
            exitTo("login.php");
        }
    }
    $GLOBALS['g_PHPSELF'] = $GLOBALS['page'];
    $GLOBALS['g_PAGE'] = $page;
    if (isset($_SERVER['HTTP_HOST'])) {
        $GLOBALS['g_SITEURL'] = $_SERVER['HTTP_HOST'];
        $GLOBALS['g_SITENAME'] = substr($GLOBALS['g_SITEURL'], 0, strlen($GLOBALS['g_SITEURL']) - 4);
        $GLOBALS['g_TITLE'] = $GLOBALS['g_SITENAME'];
    }
    $GLOBALS['g_ERRSTRS'] = array("", "", "", "", "", "", "", "", "", "", "");
    $GLOBALS['DEBUG'] = "";
}
Ejemplo n.º 8
0
<?php

require_once "config/DBConnection.php";
$db = new DBConnection();
$conn = $db->connect();
$userId = $_GET['user_id'];
$pass = $_GET['password'];
//check connection first before doing query
$sql = "SELECT * FROM users WHERE user_id = '{$userId}' AND password = '******'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    $user = $result->fetch_object();
    $response = array('status' => 'ok', 'message' => 'Successfully Login!', 'user' => $user);
    echo json_encode($response);
    die;
}
echo json_encode(array('status' => 'error', 'message' => 'Login Failed!'));
$conn->close();
Ejemplo n.º 9
0
<?php

/*******************************************************************************
 * Copyright (c) 2007-2009 Intalio, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Antoine Toulme, Intalio Inc.
*******************************************************************************/
// this file should be included in the spec files.
// it will open a connection to a test database.
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once dirname(__FILE__) . "/../classes/system/dbconnection.class.php";
DBConnection::connect(dirname(__FILE__) . '/test.ini');
Ejemplo n.º 10
0
<?php

include 'src/DBConnection.php';
include 'src/Login.php';
$login = new Login();
if ($login->is_session()) {
    $login->redirect();
}
if (isset($_POST['submit'])) {
    if (!empty($_POST['username']) && !empty($_POST['password'])) {
        $dbObj = new DBConnection();
        $db = $dbObj->connect();
        $username = $_POST['username'];
        $password = $_POST['password'];
        $login->setDB($db);
        $login->setUsername($username);
        $login->setPassword($password);
        if ($login->verification()) {
            if ($login->createSession()) {
                $login->redirect();
            }
        } else {
            echo 'username / password is incorrect';
        }
    }
}
Ejemplo n.º 11
0
    $N = $sent[0];
    $K = $sent[1];
    $command = '/usr/bin/python /var/www/html/toyapp/toyapp-python/toyapp.py encrypt ' . $file_name . ' ' . $N . ' ' . $K;
    echo $command;
    //echo '<br />'.$command;
    //echo '<br />';
    #$result = #exec($command);#
    $result = json_decode(exec($command, $status), true);
    $size = sizeof($result);
    //print_r($result);
    $i = 0;
    require_once '../includes/shareholdersapi.inc';
    $shareholders = get_shareholders($sent[2]);
    //print_r($shareholders);
    require_once '../includes/DB_Abstraction.inc';
    $db_con = new DBConnection();
    $db_con->connect();
    foreach ($result as $pair) {
        $uid = $shareholders[$i]['uid'];
        $db_con->insert('secrets', 'fid,uid,secret', "{$sent['2']},'{$uid}','[{$pair['0']},{$pair['1']}]'");
        $i++;
        echo "<br />Secret {$i}: <input type='text' readonly='readonly' value='[{$pair['0']},{$pair['1']}]'/>";
    }
    //print_r($result);//. ' <br />';
    $db_con->update('file', "url='\\/toyapp\\/repo\\/{$fn}.enc',status=2", "fid={$sent['2']}");
    $db_con->disconnect();
    //unlink($file_name);
}
?>
</body>
</html>
Ejemplo n.º 12
0
include 'MembersCtrl.php';
include 'src/Appointment.php';
if (isset($_POST['submit'])) {
    $data = array('name' => $_POST['name'], 'address' => $_POST['address'], 'age' => $_POST['age'], 'gender' => $_POST['gender'], 'hospital' => $_POST['hospital'], 'speciality' => $_POST['speciality'], 'appointment' => $_POST['appointment'], 'date' => $_POST['date'], 'time' => $_POST['time'], 'phone' => $_POST['phone'], 'doctor' => $_POST['doctor'], 'age' => $_POST['age'], 'gender' => $_POST['gender'], 'address' => $_POST['address']);
    $pass = true;
    foreach ($data as $var => $value) {
        if (empty($value)) {
            echo $var . " is empty!";
            $pass = false;
            break;
        }
    }
    if ($pass) {
        $dbo = new DBConnection();
        $db = $dbo->connect();
        $appointment = new Appointment();
        $appointment->setDB($db);
        $appointment->setPatientUser($data['name']);
        $appointment->setDoctor($data['doctor']);
        $appointment->setDate($data['date']);
        $appointment->setTime($data['time']);
        $appointment->setSpeciality($data['speciality']);
        $appointment->setAppointmentType($data['appointment']);
        $appointment->setHospital($data['hospital']);
        $appointment->setMobile($data['phone']);
        $appointment->setAge($data['age']);
        $appointment->setGender($data['gender']);
        $appointment->setCurrentUser($members->getSessionUser());
        $appointment->setCurrentAddress($data['address']);
        if ($appointment->verification()) {
 /**
  * Connect
  *
  * @param   bool reconnect default FALSE
  * @return  bool success
  * @throws  rdbms.SQLConnectException
  */
 public function connect($reconnect = FALSE)
 {
     if ($this->handle->connected) {
         return TRUE;
     }
     // Already connected
     if (!$reconnect && NULL === $this->handle->connected) {
         return FALSE;
     }
     // Previously failed connecting
     $this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECT, $reconnect));
     try {
         $this->handle->connect($this->dsn->getUser(), $this->dsn->getPassword());
         $this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECTED, $reconnect));
     } catch (IOException $e) {
         $this->handle->connected = NULL;
         $this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECTED, $reconnect));
         throw new SQLConnectException($e->getMessage(), $this->dsn);
     }
     try {
         $this->handle->exec('set names LATIN1');
         // Figure out sql_mode and update formatter's escaperules accordingly
         // - See: http://bugs.mysql.com/bug.php?id=10214
         // - Possible values: http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
         // "modes is a list of different modes separated by comma (,) characters."
         $modes = array_flip(explode(',', this(this($this->handle->consume($this->handle->query("show variables like 'sql_mode'")), 0), 1)));
     } catch (IOException $e) {
         // Ignore
     }
     // NO_BACKSLASH_ESCAPES: Disable the use of the backslash character
     // (\) as an escape character within strings. With this mode enabled,
     // backslash becomes any ordinary character like any other.
     // (Implemented in MySQL 5.0.1)
     isset($modes['NO_BACKSLASH_ESCAPES']) && $this->formatter->dialect->setEscapeRules(array('"' => '""'));
     return parent::connect();
 }
 /**
  * Connect
  *
  * @param   bool reconnect default FALSE
  * @return  bool success
  * @throws  rdbms.SQLConnectException
  */
 public function connect($reconnect = FALSE)
 {
     if (is_resource($this->handle)) {
         return TRUE;
     }
     // Already connected
     if (!$reconnect && FALSE === $this->handle) {
         return FALSE;
     }
     // Previously failed connecting
     // Connect via local sockets if "." is passed. This will not work on
     // Windows with the mysqlnd extension (see PHP bug #48082: "mysql_connect
     // does not work with named pipes"). For mysqlnd, we default to mysqlx
     // anyways, so this works transparently.
     $host = $this->dsn->getHost();
     $ini = NULL;
     if ('.' === $host) {
         $sock = $this->dsn->getProperty('socket', NULL);
         if (0 === strncasecmp(PHP_OS, 'Win', 3)) {
             $connect = '.';
             if (NULL !== $sock) {
                 $ini = ini_set('mysql.default_socket');
                 ini_set('mysql.default_socket', substr($sock, 9));
                 // 9 = strlen("\\\\.\\pipe\\")
             }
         } else {
             $connect = NULL === $sock ? 'localhost' : ':' . $sock;
         }
     } else {
         if ('localhost' === $host) {
             $connect = '127.0.0.1:' . $this->dsn->getPort(3306);
             // Force TCP/IP
         } else {
             $connect = $host . ':' . $this->dsn->getPort(3306);
         }
     }
     $this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECT, $reconnect));
     if ($this->flags & DB_PERSISTENT) {
         $this->handle = mysql_pconnect($connect, $this->dsn->getUser(), $this->dsn->getPassword());
     } else {
         $this->handle = mysql_connect($connect, $this->dsn->getUser(), $this->dsn->getPassword(), $this->flags & DB_NEWLINK);
     }
     $this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECTED, $reconnect));
     $ini && ini_set('mysql.default_socket', $ini);
     if (!is_resource($this->handle)) {
         $e = new SQLConnectException('#' . mysql_errno() . ': ' . mysql_error(), $this->dsn);
         xp::gc(__FILE__);
         throw $e;
     }
     mysql_query('set names LATIN1', $this->handle);
     // Figure out sql_mode and update formatter's escaperules accordingly
     // - See: http://bugs.mysql.com/bug.php?id=10214
     // - Possible values: http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
     // "modes is a list of different modes separated by comma (,) characters."
     $modes = array_flip(explode(',', current(mysql_fetch_row(mysql_query("show variables like 'sql_mode'", $this->handle)))));
     // NO_BACKSLASH_ESCAPES: Disable the use of the backslash character
     // (\) as an escape character within strings. With this mode enabled,
     // backslash becomes any ordinary character like any other.
     // (Implemented in MySQL 5.0.1)
     isset($modes['NO_BACKSLASH_ESCAPES']) && $this->formatter->dialect->setEscapeRules(array('"' => '""'));
     return parent::connect();
 }
Ejemplo n.º 15
0
 public static function getMemberDetail($id)
 {
     $db = new DBConnection();
     $link = $db->connect();
     if ($link != null) {
         $query = "SELECT concat(first_name,\" \",last_name) AS name  , gender , email ,mobile   FROM member WHERE id ='" . $id . "'";
         $result = $link->query($query);
         $db->closeConnection();
         return $result;
     }
     $db->closeConnection();
     return null;
 }
Ejemplo n.º 16
0
require_once "classes/pages.class.php";
require_once "classes/blocks.class.php";
require_once "classes/controls.class.php";
require_once "classes/news.class.php";
require_once "classes/contacts.class.php";
require_once "classes/clients.class.php";
require_once "classes/services.class.php";
require_once "classes/portfolios.class.php";
require_once "classes/categories.class.php";
require_once "classes/phpmailer.class.php";
$conn = new DBConnection();
$mysql_hostname = DBVariables::$mysql_hostname;
$mysql_username = DBVariables::$mysql_username;
$mysql_password = DBVariables::$mysql_password;
$mysql_database = DBVariables::$mysql_database;
$conn->connect($mysql_hostname, $mysql_username, $mysql_password, $mysql_database);
$conn->debug = true;
/****************************************************************/
//Functions
/****************************************************************/
require_once "functions/pages.fun.php";
require_once "functions/blocks.fun.php";
require_once "functions/news.fun.php";
require_once "functions/clients.fun.php";
require_once "functions/categories.fun.php";
require_once "functions/portfolios.fun.php";
require_once "functions/services.fun.php";
require_once "functions/contacts.fun.php";
/****************************************************************/
GetCurrentNodeInformation();
if ($config["news"] > 0) {
Ejemplo n.º 17
0
 *
 * Contributors:
 *    Antoine Toulme, Intalio Inc. bug 248845: Refactoring generate1.php into different files with a functional approach
*******************************************************************************/
/*
 * Documentation: http://wiki.eclipse.org/Babel_/_Server_Tool_Specification#Outputs
 */
ini_set("memory_limit", "64M");
require dirname(__FILE__) . "/../system/backend_functions.php";
global $addon;
$context = $addon->callHook('context');
$work_dir = $addon->callHook('babel_working');
require dirname(__FILE__) . "/../system/dbconnection.class.php";
require dirname(__FILE__) . "/../system/feature.class.php";
$dbc = new DBConnection();
$dbh = $dbc->connect();
$work_context_dir = $work_dir . $context . "_site/";
$tmp_dir = $work_context_dir . "tmp/";
$output_dir = $work_context_dir . "output/";
$sites_dir = $work_context_dir . "sites/";
exec("rm -rf {$work_context_dir}*");
exec("mkdir -p {$output_dir}");
exec("mkdir -p {$sites_dir}");
//iterate over all the release trains
foreach (ReleaseTrain::all() as $train) {
    $features = array();
    // create a dedicated folder for each of them
    exec("mkdir -p {$sites_dir}/{$train->id}");
    // create the output folder for temporary artifacts
    $output_dir_for_train = "{$output_dir}/{$train->id}/";
    // iterate over each language
    if (is_session_active()) {
        //$shares = array($_POST['1'] , $_POST['2'], $_POST['3']);
        $shares = array();
        if (!empty($_POST['1'])) {
            array_push($shares, $_POST['1']);
        }
        if (!empty($_POST['2'])) {
            array_push($shares, $_POST['2']);
        }
        if (!empty($_POST['3'])) {
            array_push($shares, $_POST['3']);
        }
        //var_dump($shares);
        $reconstructed_secret = reconstruct($shares);
        $db = new DBConnection();
        $db->connect();
        $user = get_user_info();
        $secret = $db->query('secret', 'secret', "uid='{$user}'", null, null, null)[0]['secret'];
        $db->delete('secret', "uid='{$user}'");
        $db->disconnect();
        if ($secret == $reconstructed_secret) {
            echo "Secrets matching. Access granted.";
        } else {
            echo "{$secret} != {$reconstructed_secret}. Access denied";
        }
    } else {
        echo "fail";
    }
} else {
    echo "fail";
}
Ejemplo n.º 19
0
 function setDB()
 {
     $dbObj = new DBConnection();
     $this->db = $dbObj->connect();
 }
Ejemplo n.º 20
0
         // exit('Failed to remove database');
     }
 }
 // #2: install offiria database
 if ($canProceed && !$database->createDatabase($dbo, $db_name)) {
     $link = '';
     $link .= '<p>';
     $link .= 'This is a fresh install of Offiria, <b>' . $db_name . '</b> database will be removed (this action is not reversible)<br />';
     $query = "?{$variables}&remove_database=true";
     $link .= '<a href="' . $query . '">Confirm</a>';
     $link .= '</p>';
     $errorMessage = $link;
     $canProceed = false;
 }
 // update connection based on the new database created
 $dbo = DBConnection::connect($db_name, $db_host, $db_uname, $db_pw);
 if ($canProceed && !$database->populateDatabase($dbo, FRAMEWORK_SQL_FILEPATH)) {
     $canProceed = false;
     $errorMessage = 'Failed to install framework';
     // exit('Failed to install framework');
 }
 if ($canProceed && !$database->populateDatabase($dbo, OFFIRIA_SQL_FILEPATH)) {
     $canProceed = false;
     $errorMessage = 'Failed to install Offiria';
     // exit('Failed to install Offiria');
 }
 if ($canProceed && !$database->installPatches($dbo, PATCHES_SQL_FILEDIR)) {
     $canProceed = false;
     $errorMessage = 'Failed to update patches';
     // exit('Failed to update patches');
 }