Files
PHPApp/include/Cms.php

224 lines
5.2 KiB
PHP

<?php
require_once('./include/Cms.php');
require_once('./include/Mssql.php');
require_once('./include/Mysql.php');
require_once('./include/PdoSqlsrv.php');
require_once('./include/Sqlsrv.php');
class Cms extends cust_conf
{
// public $endPoint = array( "studioml" => "192.168.2.205:8080", "cliente" => "172.16.30.5:8080");
/**
* @var Mssql|Sqlsrv|PdoSqlsrv
*/
private $db;
/************** public at the moment *************/
private $queryString;
/**
* dbConfig constructor.
*/
public function __construct()
{
$key = $this->getAzienda();
$settings = array(
"hostName" => $this->db_hostname[$key],
"userName" => $this->db_username[$key],
"password" => $this->db_password[$key],
"dbName" => $this->db_name[$key]);
/*** initial name dbConfig ********/
$availableDrivers = self::getAvailableDrivers();
if (in_array("pdosqlsrv", $availableDrivers)) {
$this->db = new PdoSqlsrv($settings);
}elseif (in_array("mssql", $availableDrivers)) {
$this->db = new Mssql($settings);
/*************** put PDO first at the end of the test ***************/
} else { /* sqlsrv */
$this->db = new Sqlsrv($settings);
}
}
public static function getAvailableDrivers()
{
$drivers = array("mssql");
if (extension_loaded("sqlsrv")) {
$drivers[] = "sqlsrv";
}
if (class_exists("PDO") && in_array("sqlsrv", PDO::getAvailableDrivers())) {
$drivers[] = "pdosqlsrv";
}
return $drivers;
}
function query($Query_String)
{
$this->db->connect();
$this->db->query($Query_String);
$this->queryString = $Query_String;
$this->Row = 0;
if (!$this->queryString)
$this->halt("Invalid SQL: " . $Query_String);
if ($this->db->query($Query_String)){
return true;
};
}
function next_record()
{
return $this->db->next_record();
}
/*************** functions not present in PDO.Sqlsrv class ***************************/
function seek($pos)
{
$status = mssql_data_seek($this->Query_ID, $pos);
if ($status)
$this->Row = $pos;
return;
}
function affected_rows()
{
return mssql_affected_rows($this->Link_ID);
}
function rs2Array()
{
return mssql_fetch_array($this->Query_ID);
}
/**************************************************************************************/
function num_rows($startFromZero_pdoOnly=true)
{
return $this->db->num_rows($startFromZero_pdoOnly);
}
function num_fields()
{
return $this->db->num_fields();
}
function field_name($column)
{
return $this->db->field_name($column);
}
function field_type($column)
{
return $this->db->field_type($column);
}
function nf()
{
return $this->db->num_rows();
}
function np()
{
print $this->db->num_rows();
}
function f($Name)
{
return $this->db->Record[$Name];
}
/*function p($Name)
{
print $this->db->Record[$Name];
}*/
function halt($msg)
{
printf("</td></tr></table><b>Database error:</b> %s<br>\n", $msg);
printf("<b>MsSQL Error</b>: %s (%s)<br>\n");
die("Session stopped.");
}
function rewindRs()
{
$this->Row = 0;
return;
}
public function getHostname()
{
return $this->db_hostname[$this->getAzienda()];
}
/*public function getDbname()
{
return $this->db_name[$this->getAzienda()];
}*/
public function getDbnameWEB()
{
return $this->db_nameWEB[$this->getAzienda()];
}
public function getUtenteDb()
{
return $this->db_username[$this->getAzienda()];
}
public function getPasswordDb()
{
return $this->db_password[$this->getAzienda()];
}
public function getUtenteWEB()
{
return $this->web_username[$this->getAzienda()];
}
/*
public function getPasswordWEB()
{
return $this->web_password[$this->getAzienda()];
}
public function getEndpoint()
{
return $this->endPoint[$this->getAzienda()];
}*/
public function getRelImgPath()
{
return $this->relative_img_path[$this->getAzienda()];
}
/*public function getAzienda()
{
$nome_file = "nome_azienda.txt";
// SALE FINO A 3 LIVELLI PER CERCARE IL FILE
for ($i = 1; $i <= 3; $i++) {
$nome_file = "../$nome_file";
if (file_exists($nome_file))
// $nome_file = "../$nome_file";
break;
}
if (file_exists($nome_file)) {
$var = fopen($nome_file, "r");
$azienda = fread($var, filesize($nome_file));
fclose($var);
switch ($azienda) {
case "STUDIOML":
return "studioml";
break;
default:
return "cliente";
}
} else
return "cliente";
}*/
}