Exemple #1
0
/**
 * Add new admin action
 * @param int $admins_id
 * @return string
 */
function addNewAdmin($admins_id = 0) {

	if ($admins_id && !isset($_POST['_form_submit'])){
		$_SESSION['admin']['uedit'] = $admins_id;
		$db = new DBConnection();
		$query = 'SELECT * FROM ul_logins WHERE id='.($admins_id+0).'';
		$res = $db->rq($query);
		foreach ($db->fetch($res) as $RowName => $RowValue){
			$FormFieldName = str_replace('adm_', '', $RowName);
			$_POST[$FormFieldName] = $RowValue;
		}
        
        $now = new \DateTime();
        $column = new \DateTime($_POST['block_expires']);
        if ($column > $now) {
            $_POST['status'] = 0;
        }
        else {
            $_POST['status'] = 1;
        }
        
        unset($_POST['password']);
        
		$db->close();
	}
	
	$view = new App\View\View('admin/add');
    $view->admin_id = $admins_id;
    $view->data = $_POST;
        
	return $view->render();
}
 /**
  * Parse an XML database file and output the corresponding SQL statements.
  * See lib/pkp/dtd/xmlSchema.dtd for the format of the XML files.
  */
 function execute()
 {
     require_once './lib/pkp/lib/adodb/adodb-xmlschema.inc.php';
     if (in_array($this->command, array('print', 'save'))) {
         // Don't connect to actual database (so parser won't build upgrade XML)
         $conn = new DBConnection(Config::getVar('database', 'driver'), null, null, null, null, true, Config::getVar('i18n', 'connection_charset'));
         $dbconn = $conn->getDBConn();
     } else {
         // Create or upgrade existing database
         $dbconn =& DBConnection::getConn();
     }
     $schema = new adoSchema($dbconn);
     $dict =& $schema->dict;
     $dict->SetCharSet(Config::getVar('i18n', 'database_charset'));
     if ($this->type == 'schema') {
         // Parse XML schema files
         $sql = $schema->parseSchema($this->inputFile);
         switch ($this->command) {
             case 'execute':
                 $schema->ExecuteSchema();
                 break;
             case 'save':
             case 'save_upgrade':
                 $schema->SaveSQL($this->outputFile);
                 break;
             case 'print':
             case 'print_upgrade':
             default:
                 echo @$schema->PrintSQL('TEXT') . "\n";
                 break;
         }
     } else {
         if ($this->type == 'data') {
             // Parse XML data files
             $dataXMLParser = new DBDataXMLParser();
             $dataXMLParser->setDBConn($dbconn);
             $sql = $dataXMLParser->parseData($this->inputFile);
             switch ($this->command) {
                 case 'execute':
                     $schema->addSQL($sql);
                     $schema->ExecuteSchema();
                     break;
                 case 'save':
                 case 'save_upgrade':
                     $schema->addSQL($sql);
                     $schema->SaveSQL($this->outputFile);
                     break;
                 case 'print':
                 case 'print_upgrade':
                 default:
                     $schema->addSQL($sql);
                     echo @$schema->PrintSQL('TEXT') . "\n";
                     break;
             }
             $schema->destroy();
             $dataXMLParser->destroy();
         }
     }
 }
 /**
  * Returns the fragment SQL string
  *
  * @param   rdbms.DBConnection conn
  * @return  string
  * @throws  rdbms.SQLStateException
  */
 public function asSql(DBConnection $conn)
 {
     $s = '';
     foreach ($this->projections as $e) {
         $s .= 0 != strlen($e['alias']) ? $conn->prepare(', %c as %l', $e['projection']->asSql($conn), $e['alias']) : $conn->prepare(', %c', $e['projection']->asSql($conn));
     }
     return substr($s, 1);
 }
 /**
  * Executes an SQL SELECT statement
  *
  * @param   rdbms.DBConnection conn
  * @param   rdbms.Peer peer
  * @param   rdbms.join.Joinprocessor jp optional
  * @param   bool buffered default TRUE
  * @return  rdbms.ResultSet
  */
 public function executeSelect(DBConnection $conn, Peer $peer, $jp = null, $buffered = true)
 {
     $statement = preg_replace('/object\\(([^\\)]+)\\)/i', '$1.' . implode(', $1.', array_keys($peer->types)), $this->statement);
     if ($buffered) {
         return $conn->query($statement, ...$this->arguments);
     } else {
         return $conn->open($statement, ...$this->arguments);
     }
 }
Exemple #5
0
function addLog($log_area = '', $log_section = '', $log_user = '', $log_admin = '', $log_details = '')
{
    $user_ip = GetHostByName($_SERVER["REMOTE_ADDR"]);
    $db = new DBConnection();
    $query = 'INSERT INTO logs SET 
	log_area="' . $log_area . '",log_section="' . $log_section . '",log_user="******",log_admin="' . $log_admin . '",log_details="' . $log_details . '", 
	log_date="' . date('Y-m-d H:i:s', CUSTOMTIME) . '", log_ip="' . $user_ip . '"';
    $db->rq($query);
}
 /**
  * @covers DBConnection::DBConnection
  * @covers DBConnection::initCustomDBConnection
  * @covers DBConnection::initConn
  */
 public function testInitCustomDBConnection()
 {
     $this->setTestConfiguration(self::CONFIG_PGSQL);
     $conn = new DBConnection('sqlite', 'localhost', 'ojs', 'ojs', 'ojs', true, false, false);
     $dbConn = $conn->getDBConn();
     self::assertType('ADODB_sqlite', $dbConn);
     $conn->disconnect();
     unset($conn);
 }
Exemple #7
0
		public static function getSurveyById($id) {
			if(!is_int($id)) {
				throw new Exception('Given ID is not integer');
			}
			$table = "lime_survey_" . $id;
			$con = new DBConnection();
			$rs = $con->executeQuery("SELECT * FROM " . $table);			
			return $rs;
		}
Exemple #8
0
function addNewAdvisor($users_advisors_id=0) {
	if ($users_advisors_id&&!$_POST['_form_submit']){
		$_SESSION['admin']['uedit']=$users_advisors_id;
		$db=new DBConnection();
		$query='SELECT * FROM users_advisors WHERE users_advisors_id='.($users_advisors_id+0).'';
		$res=$db->rq($query);
		foreach ($db->fetch($res) as $RowName=>$RowValue){
			$FormFieldName=str_replace('advisor_', '', $RowName);
			$_POST[$FormFieldName]=$RowValue;
		}
		$db->close();
	}
	
	$pcontent='';
	$pcontent.='
<div class="mainHolder">
<div class="hintHolder ui-state-default"><b>'.(($users_advisors_id>0)?'Editing':'Creating New').' Advisor</b></div> 
<script type="text/javascript" src="../js/jquery.validate.js"></script>
<script type="text/javascript" src="js/forms/advisors.js"></script>
<form name="addNewAdvisor" method="POST" id="MainForms" action="">
<fieldset class="mainFormHolder">
	<legend>User information</legend>
	<div class="formsLeft">REF:</div>
	<div class="formsRight">
		<input class="text-input" type="text" name="ref" id="ref" value="'.$_POST['ref'].'" />
	</div>
	<br />
	<div class="formsLeft">Names:</div>
	<div class="formsRight">
		<input class="text-input" name="names" id="names" value="'.$_POST['names'].'" />
	</div>
	<br />
	<div class="formsLeft">Firm:</div>
	<div class="formsRight">
		<input class="text-input" name="firm" id="firm" value="'.$_POST['firm'].'" />
	</div>
	<br />
	<div class="formsLeft">Contacts:</div>
	<div class="formsRight">
		<input class="text-input" name="contacts" id="contacts" value="'.$_POST['contacts'].'" />
	</div>
	<input type="hidden" name="_form_submit" value="1" />
	<input type="submit" name="_submit" value="'.getLang('sform_savebtn').'" class="submitBtn ui-state-default" />
	';
	if ($users_advisors_id){
		$pcontent.='
	<input type="hidden" name="advid" value="'.$users_advisors_id.'">
	<input type="button" name="_delete" value="'.getLang('sform_delbtn').'" class="submitBtn ui-state-default" onclick="if(confirm(\'Are you sure you want to delete this advisor?\')) location=\'?action=delete&advid='.($_POST['users_advisors_id']+0).'\';" />';
	}
	$pcontent.='
	<input type="button" name="_cancel" value="'.getLang('sform_backbtn').'" class="submitBtn ui-state-default" onclick="location=\'users_advisors.php\';" />
	</fieldset>
</form>
</div>';
	return $pcontent;
}
function getAssignedAssociateName($username)
{
    $db = new DBConnection();
    $q = "call getAssociate(:assigned)";
    $stmt = $db->prepare($q);
    //    $stmt->setFetchMode(PDO::FETCH_CLASS, 'User');
    $stmt->execute(array(':assigned' => $username));
    $associate = $stmt->fetch(PDO::FETCH_OBJ);
    return $associate->a_name;
}
function hasTasks($m_id)
{
    $db = new DBConnection();
    $q = "call checktaskonmain(:mid)";
    $stmt = $db->prepare($q);
    //    $stmt->setFetchMode(PDO::FETCH_OBJ);
    $stmt->execute(array('mid' => $m_id));
    $havetask = $stmt->fetchColumn();
    return $havetask;
}
Exemple #11
0
 /**
  * Class constructor
  *
  * @param string $readWriteMode "read", "write" or "admin"
  * @throws ControllerException
  */
 public function __construct($readWriteMode = 'write')
 {
     try {
         $dbc = new DBConnection($readWriteMode);
         $this->_dbh = $dbc->getConnection();
         $this->_dbh->autocommit(TRUE);
     } catch (Exception $e) {
         throw new ControllerException('Problem connecting to database: ' . $this->_dbh->error);
     }
 }
Exemple #12
0
function getUserFromCookie()
{
    $db = new DBConnection();
    $q = "call getassociate(:username)";
    $stmt = $db->prepare($q);
    $userac = htmlEntities2($_COOKIE["UserName"]);
    //    $stmt->setFetchMode(PDO::FETCH_CLASS, 'User');
    $stmt->execute(array(':username' => $userac));
    $user = $stmt->fetch(PDO::FETCH_OBJ);
    $_SESSION["UserName"] = $user;
}
Exemple #13
0
 public function update($id)
 {
     $values = [];
     $columns = [];
     foreach (static::$columns as $column) {
         $values[':' . $column] = $this->{$column};
         $columns[] = $column . '=:' . $column;
     }
     $sql = 'UPDATE' . ' ' . static::$table . ' ' . 'SET' . ' ' . implode(',', $columns) . ' ' . 'WHERE id=:id';
     echo $sql;
     $res = new DBConnection();
     $res->query($sql, $id, $values);
 }
Exemple #14
0
function getCalendarByRange($id)
{
    try {
        $db = new DBConnection();
        $db->getConnection();
        $sql = "select * from `jqcalendar` where `id` = " . $id;
        $handle = mysql_query($sql);
        //echo $sql;
        $row = mysql_fetch_object($handle);
    } catch (Exception $e) {
    }
    return $row;
}
Exemple #15
0
function getwebsitepages($websiteid)
{
    $viewpage = new Website();
    $res = $viewpage->fetchwebpages($websiteid);
    $db = new DBConnection();
    $pagearr = array();
    $count = 0;
    while ($pagerow = $db->fetch_assoc($res)) {
        if (empty($pagecontent)) {
            $pagearr[$count] = $pagerow['page_id'];
            $count++;
        }
    }
    return $pagearr;
}
Exemple #16
0
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new DBConnection();
     }
     return self::$_instance;
 }
Exemple #17
0
 static function connect()
 {
     self::$db = new mysqli(Conf::$DB_HOST, Conf::$DB_USER, Conf::$DB_PASSWORD, Conf::$DB_SELECT, Conf::$DB_PORT);
     if (self::$db->connect_errno) {
         die('Erreur de connexion (' . self::$db->connect_errno . ') ' . self::$db->connect_error);
     }
 }
 /**
  * Execute the command
  */
 function execute()
 {
     $stderr = fopen('php://stdout', 'w');
     $locales = AppLocale::getAllLocales();
     $dbConn = DBConnection::getConn();
     foreach ($locales as $locale => $localeName) {
         fprintf($stderr, "Checking {$localeName}...\n");
         $oldTemplatesText = $this->fetchFileVersion('ojs', "locale/{$locale}/emailTemplates.xml", $this->oldTag);
         $newTemplatesText = $this->fetchFileVersion('ojs', "locale/{$locale}/emailTemplates.xml", $this->newTag);
         if ($oldTemplatesText === false || $newTemplatesText === false) {
             fprintf($stderr, "Skipping {$localeName}; could not fetch.\n");
             continue;
         }
         $oldEmails = $this->parseEmails($oldTemplatesText);
         $newEmails = $this->parseEmails($newTemplatesText);
         foreach ($oldEmails['email_text'] as $oi => $junk) {
             $key = $junk['attributes']['key'];
             $ni = null;
             foreach ($newEmails['email_text'] as $ni => $junk) {
                 if ($key == $junk['attributes']['key']) {
                     break;
                 }
             }
             if ($oldEmails['subject'][$oi]['value'] != $newEmails['subject'][$ni]['value']) {
                 echo "UPDATE email_templates_default_data SET subject='" . $dbConn->escape($newEmails['subject'][$ni]['value']) . "' WHERE key='" . $dbConn->escape($key) . "' AND locale='" . $dbConn->escape($locale) . "' AND subject='" . $dbConn->escape($oldEmails['subject'][$oi]['value']) . "';\n";
             }
             if ($oldEmails['body'][$oi]['value'] != $newEmails['body'][$ni]['value']) {
                 echo "UPDATE email_templates_default_data SET body='" . $dbConn->escape($newEmails['body'][$ni]['value']) . "' WHERE key='" . $dbConn->escape($key) . "' AND locale='" . $dbConn->escape($locale) . "' AND body='" . $dbConn->escape($oldEmails['body'][$oi]['value']) . "';\n";
             }
         }
     }
     fclose($stderr);
 }
Exemple #19
0
 public static function getInstance()
 {
     if (!self::$m_pInstance) {
         self::$m_pInstance = new DBConnection();
     }
     return self::$m_pInstance;
 }
 /**
  * Gets the computers of the asked lab
  */
 public static function GetComputersByLab($lab_id)
 {
     $sql = "select * from Computers where LabID = " . $lab_id . " order by X1, Y1;";
     $results = DBConnection::ExecuteSelectQuery($sql);
     $computers = self::GetArrayFromDBTable($results);
     return $computers;
 }
 /**
  * @copydoc GridHandler::loadData()
  */
 protected function loadData($request, $filter)
 {
     $dbconn = DBConnection::getConn();
     $dbServerInfo = $dbconn->ServerInfo();
     $serverInfo = array('admin.server.platform' => Core::serverPHPOS(), 'admin.server.phpVersion' => Core::serverPHPVersion(), 'admin.server.apacheVersion' => function_exists('apache_get_version') ? apache_get_version() : __('common.notAvailable'), 'admin.server.dbDriver' => Config::getVar('database', 'driver'), 'admin.server.dbVersion' => empty($dbServerInfo['description']) ? $dbServerInfo['version'] : $dbServerInfo['description']);
     return $serverInfo;
 }
Exemple #22
0
 public static function getInstance($hostname = 'localhost', $databasename = 'smsempresa', $username = '******', $password = '')
 {
     if (!isset(self::$instance)) {
         self::$instance = new PDO('mysql:host=localhost;dbname=smsempresa', 'root', '');
     }
     return self::$instance;
 }
Exemple #23
0
 public static function getInstance()
 {
     if (DBConnection::$instance == null) {
         DBConnection::$instance = new DBConnection();
     }
     return DBConnection::$instance;
 }
Exemple #24
0
 public function logApiCall($log)
 {
     $values['call_time'] = date('d-m-Y H:i:s');
     //Get caller ip
     if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
         $ip = $_SERVER['HTTP_CLIENT_IP'];
     } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
     } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
         $ip = $_SERVER['REMOTE_ADDR'];
     } else {
         $ip = "not known";
     }
     $values['caller_ip'] = $ip;
     //Verplicht in $log!
     $values['url'] = $log['url'];
     $values['data'] = json_encode($log['data']);
     $values['response_code'] = $log['response_code'];
     unset($log['response']['code']);
     if ($log['response_code'] !== 200) {
         $values['response'] = $log['response']['db_code'];
     }
     $db = new DBConnection();
     $db->insert($values)->into("api_calls")->execute();
 }
Exemple #25
0
 public function __construct($id = NULL)
 {
     $this->db = DBConnection::getConnection();
     if ($id == NULL) {
         $this->new = TRUE;
     } else {
         $id = $this->db->quote($id);
         $query = "SELECT * FROM {$this->sourceTab} WHERE ID={$id}";
         try {
             $res = $this->db->query($query);
             if ($res->rowCount() != 1) {
                 $this->valid = FALSE;
             } else {
                 $info = $res->fetch(PDO::FETCH_ASSOC);
                 $this->nid = $info['NID'];
                 $this->id = $info['ID'];
                 $this->password = $info["PASSWORD"];
                 $this->salt = $info["SALT"];
                 $this->valid = $info["VALID"];
                 $this->admin = $info["ADMIN"];
             }
         } catch (Exception $e) {
             throw new Exception("Impossible to Execute Query that retrieve an user: " . $e->getMessage());
         }
     }
 }
 private function __construct($config)
 {
     self::$failSilently = $config['failSilently'];
     self::$parentCalledFromPost = $config['parentCalledFromPost'];
     $dsn = sprintf('mysql:dbname=%s;host=%s;', $config['database'], $config['hostname']);
     self::$_instance = new PDO($dsn, $config['username'], $config['password']);
 }
 /**
  * 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();
 }
Exemple #28
0
 public static function init($host, $user, $pw, $db)
 {
     self::$connection = DBConnection::getInstance("main");
     if (!self::$connection->isOpen()) {
         self::$connection->init($host, $user, $pw, $db);
     }
 }
 /**
  * @copydoc GridHandler::loadData()
  */
 protected function loadData($request, $filter)
 {
     $dbconn = DBConnection::getConn();
     $dbServerInfo = $dbconn->ServerInfo();
     $serverInfo = array('admin.server.platform' => PHP_OS, 'admin.server.phpVersion' => phpversion(), 'admin.server.apacheVersion' => $_SERVER['SERVER_SOFTWARE'], 'admin.server.dbDriver' => Config::getVar('database', 'driver'), 'admin.server.dbVersion' => empty($dbServerInfo['description']) ? $dbServerInfo['version'] : $dbServerInfo['description']);
     return $serverInfo;
 }
Exemple #30
0
 public static function instantiate()
 {
     if (!isset(self::$instance)) {
         $class = __CLASS__;
         self::$instance = new $class();
     }
     return self::$instance;
 }