Example #1
0
 /**
  * @see DBManager::query()
  */
 public function query($sql, $dieOnError = false, $msg = '', $suppress = false)
 {
     // Flag if there are odd number of single quotes
     //if((substr_count($sql, "'") & 1))
     //$GLOBALS['log']->error("SQL statement[" . $sql . "] has odd number of single quotes.");
     $sql = $this->appendN($sql);
     parent::countQuery($sql);
     //$GLOBALS['log']->info('Query:' . $sql);
     $this->checkConnection();
     $this->query_time = microtime(true);
     if ($suppress) {
     } else {
         $result = @mssql_query($sql, $this->database);
     }
     //echo $this->database;
     if (!$result) {
         // awu Bug 10657: ignoring mssql error message 'Changed database context to' - an intermittent
         // 				  and difficult to reproduce error. The message is only a warning, and does
         //				  not affect the functionality of the query
         $sqlmsg = mssql_get_last_message();
         $sqlpos = strpos($sqlmsg, 'Changed database context to');
         if ($dieOnError) {
             //if ($sqlpos !== false)
             // if sqlmsg has 'Changed database context to', just log it
             //$GLOBALS['log']->debug(mssql_get_last_message() . ": " . $sql );
             //else
             ts_die('<span style="display:none">SQL Error : Line 126</span>');
         } else {
             ts_die('<span style="display:none">SQL Error : Line 126</span>');
             _last_message();
         }
         // $GLOBALS['log']->fatal(mssql_get_last_message() . ": " . $sql );
     }
     $this->lastmysqlrow = -1;
     $this->query_time = microtime(true) - $this->query_time;
     //$GLOBALS['log']->info('Query Execution Time:'.$this->query_time);
     $this->checkError($msg . ' Query Failed:' . $sql . '::', $dieOnError);
     return $result;
 }
Example #2
0
$cla_module = $_GET['module'];
$cla_action = $_GET['action'];
//echo "m: ".$cla_module." - ac: ".$cla_action."<br>";
//include($admin_dir.'ntk-header.php');
require_once 'include/init.admin.inc.php';
if ($no_body != 'true' && $cla->no_body() != true) {
    require_once admin_dir . 'header.php';
}
if (is_login()) {
    if (is_admin()) {
        //echo $cla_module ." - ".$cla_action;
        if (is_file(admin_dir . "classes/" . $cla_module . "/{$cla_action}.php")) {
            require_once admin_dir . "classes/" . $cla_module . "/{$cla_action}.php";
        } else {
            header("location:do?module=Error&action=ViewError&err=1&md=" . $cla_module . "&mdact=" . $cla_action);
            ts_die("Error: Action <a href=do?module=" . $cla_module . "&action=" . $cla_action . ">" . $cla_action . "</a> does not exist.");
        }
    } else {
        $cla->error();
        if ($cla_module == 'Error') {
            require_once admin_dir . "classes/" . $cla_module . "/{$cla_action}.php";
        } else {
            require_once admin_dir . "classes/Login/Login.class.php";
            require_once admin_dir . "classes/Login/signin.php";
        }
    }
} else {
    require_once admin_dir . "classes/Login/Login.class.php";
    require_once admin_dir . "classes/Login/signin.php";
}
if ($no_body != 'true') {
Example #3
0
 /**
  * @see DBManager::connect()
  */
 public function connect(array $configOptions = null, $dieOnError = false)
 {
     global $sugar_config;
     if (is_null($configOptions)) {
         $configOptions = $sugar_config['dbconfig'];
     }
     if ($sugar_config['dbconfigoption']['persistent'] == true) {
         $this->database = @mysql_pconnect($configOptions['db_host_name'], $configOptions['db_user_name'], $configOptions['db_password']);
     }
     if (!$this->database) {
         $this->database = mysql_connect($configOptions['db_host_name'], $configOptions['db_user_name'], $configOptions['db_password']) or ts_die("1Could not connect to server " . $configOptions['db_host_name'] . " as " . $configOptions['db_user_name'] . "." . mysql_error());
         // Do not pass connection information because we have not connected yet
         if ($this->database && $sugar_config['dbconfigoption']['persistent'] == true) {
             $_SESSION['administrator_error'] = "<b>Severe Performance Degradation: Persistent Database Connections " . "not working.  Please set \$sugar_config['dbconfigoption']['persistent'] to false " . "in your config.php file</b>";
         }
     }
     @mysql_select_db($configOptions['db_name']) or ts_die("Unable to select database: " . mysql_error($this->database));
     // cn: using direct calls to prevent this from spamming the Logs
     $charset = "SET CHARACTER SET utf8";
     if (isset($sugar_config['dbconfigoption']['collation']) && !empty($sugar_config['dbconfigoption']['collation'])) {
         $charset .= " COLLATE {$sugar_config['dbconfigoption']['collation']}";
     }
     mysql_query($charset, $this->database);
     // no quotes around "[charset]"
     mysql_query("SET NAMES 'utf8'", $this->database);
     $this->iDB = $configOptions['db_name'];
     $this->iHost = $configOptions['db_host_name'];
     $this->iUser = $configOptions['db_user_name'];
     $this->iPwd = $configOptions['db_password'];
     if ($this->checkError('Could Not Connect:', $dieOnError)) {
         ts_die("connected to db");
     }
     //$GLOBALS['log']->info("Connect:".$this->database);
 }
Example #4
0
 /**
  * @see DBManager::connect()
  */
 public function connect(array $configOptions = null, $dieOnError = false)
 {
     global $ts_config;
     if (is_null($configOptions)) {
         $configOptions = $ts_config['dbconfig'];
     }
     //SET DATEFORMAT to 'YYYY-MM-DD''
     ini_set('mssql.datetimeconvert', '0');
     //set the text size and textlimit to max number so that blob columns are not truncated
     ini_set('mssql.textlimit', '2147483647');
     ini_set('mssql.textsize', '2147483647');
     //set the connections parameters
     $connect_param = '';
     $configOptions['db_host_instance'] = trim($configOptions['db_host_instance']);
     if (empty($configOptions['db_host_instance'])) {
         $connect_param = $configOptions['db_host_name'];
     } else {
         $connect_param = $configOptions['db_host_name'] . "\\" . $configOptions['db_host_instance'];
     }
     //create persistent connection
     if ($ts_config['dbconfigoption']['persistent'] == true) {
         $this->database = @mssql_pconnect($connect_param, $configOptions['db_user_name'], $configOptions['db_password']);
     }
     //if no persistent connection created, then create regular connection
     if (!$this->database) {
         $this->database = mssql_connect($connect_param, $configOptions['db_user_name'], $configOptions['db_password']) or ts_die("Could not connect to server " . $configOptions['db_host_name'] . " as " . $configOptions['db_user_name'] . ".");
         if ($this->database && $ts_config['dbconfigoption']['persistent'] == true) {
             $_SESSION['administrator_error'] = "<B>Severe Performance Degradation: Persistent Database Connections " . "not working.  Please set \$ts_config['dbconfigoption']['persistent'] to false in your " . "config.php file</B>";
         }
     }
     //make sure connection exists
     if (!$this->database) {
         ts_die("Unable to establish connection");
     }
     //select database
     //Adding sleep and retry for mssql connection. We have come across scenarios when
     //an error is thrown.' Unable to select database'. Following will try to connect to
     //mssql db maximum number of 5 times at the interval of .2 second. If can not connect
     //it will throw an Unable to select database message.
     if (!@mssql_select_db($configOptions['db_name'], $this->database)) {
         $connected = false;
         for ($i = 0; $i < 5; $i++) {
             usleep(200000);
             if (@mssql_select_db($configOptions['db_name'], $this->database)) {
                 $connected = true;
                 break;
             }
         }
         if (!$connected) {
             ts_die("Unable to select database");
         }
     }
     // if($this->checkError('Could Not Connect:', $dieOnError))
     //$GLOBALS['log']->info("connected to db");
     // $GLOBALS['log']->info("Connect:".$this->database);
 }
Example #5
0
 /**
  * Checks for database not being connected
  *
  * @param  string $msg        message to prepend to the error message
  * @param  bool   $dieOnError true if we want to die immediately on error
  * @return bool
  */
 public function checkError($msg = '', $dieOnError = false)
 {
     if (!isset($this->database)) {
         if ($this->dieOnError || $dieOnError) {
             ts_die($msg . "Database Is Not Connected");
         } else {
             $this->last_error = $msg . "Database Is Not Connected";
         }
         return true;
     }
     return false;
 }
Example #6
0
 /**
  * @see DBManager::connect()
  */
 public function connect(array $configOptions = null, $dieOnError = false)
 {
     global $sugar_config;
     if (is_null($configOptions)) {
         $configOptions = $sugar_config['dbconfig'];
     }
     if (!isset($this->database)) {
         //mysqli connector has a separate parameter for port.. We need to separate it out from the host name
         $dbhost = $configOptions['db_host_name'];
         $dbport = null;
         $pos = strpos($configOptions['db_host_name'], ':');
         if ($pos !== false) {
             $dbhost = substr($configOptions['db_host_name'], 0, $pos);
             $dbport = substr($configOptions['db_host_name'], $pos + 1);
         }
         $this->database = mysqli_connect($dbhost, $configOptions['db_user_name'], $configOptions['db_password'], $configOptions['db_name'], $dbport) or ts_die("1Could not connect to server " . $dbhost . " as " . $configOptions['db_user_name'] . ". port " . $dbport . ". " . mysqli_connect_error());
     }
     @mysqli_select_db($this->database, $configOptions['db_name']) or ts_die("Unable to select database: " . mysqli_connect_error());
     // cn: using direct calls to prevent this from spamming the Logs
     mysqli_query($this->database, "SET CHARACTER SET utf8");
     // no quotes around "[charset]"
     mysqli_query($this->database, "SET NAMES 'utf8'");
     if ($this->checkError('Could Not Connect:', $dieOnError)) {
         ts_die("connected to db");
     }
 }
Example #7
0
 function role()
 {
     global $cla_module;
     /*---------------------------------------------*/
     if ($this->dont_check_user != true && $_SESSION[_PLATFORM_]["CLA"]["isAdmin"] != 1) {
         $RoleData = $_SESSION[_PLATFORM_]["CLA"]['RoleData'];
         //print_r($RoleData);
         if (array_key_exists($cla_module, $RoleData)) {
             if ($_SERVER['QUERY_STRING'] != '') {
             }
             $_SESSION[_PLATFORM_]["AUTO"]['REDIRECT'] = 'do?' . $_SERVER['QUERY_STRING'];
         } else {
             header('location:do?module=Error&err=530');
             ts_die('You do not  have permission to view this page');
         }
     }
     /*---------------------------------------------*/
 }
Example #8
0
 function out_return($bname)
 {
     global $focus;
     if (isset($focus)) {
         global $action;
         if ($focus && is_subclass_of($focus, 'SugarBean') && !$focus->ACLAccess($action)) {
             ACLController::displayNoAccess(true);
             ts_die('');
             return;
         }
     }
     return $this->text($bname);
 }
Example #9
0
 /**
  * @see DBManager::query()
  */
 public function query($sql, $dieOnError = false, $msg = '', $suppress = false)
 {
     global $app_strings;
     // Flag if there are odd number of single quotes
     // if ((substr_count($sql, "'") & 1))
     //$GLOBALS['log']->error("SQL statement[" . $sql . "] has odd number of single quotes.");
     $this->countQuery($sql);
     //$GLOBALS['log']->info('Query:' . $sql);
     $this->checkConnection();
     $this->query_time = microtime(true);
     if ($suppress) {
     } else {
         $result = @sqlsrv_query($this->database, $sql);
     }
     // the sqlsrv driver will sometimes return false from sqlsrv_query()
     // on delete queries, so we'll also check to see if we get an error
     // message as well.
     // see this forum post for more info
     // http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3685918&SiteID=1
     if (!$result && $this->_getLastErrorMessages() != '') {
         // awu Bug 10657: ignoring mssql error message 'Changed database context to' - an intermittent
         // 				  and difficult to reproduce error. The message is only a warning, and does
         //				  not affect the functionality of the query
         $sqlmsg = $this->_getLastErrorMessages();
         $sqlpos = strpos($sqlmsg, 'Changed database context to');
         $sqlpos2 = strpos($sqlmsg, 'Warning:');
         if ($sqlpos !== false || $sqlpos2 !== false) {
             //$GLOBALS['log']->debug($sqlmsg . ": " . $sql );
         } else {
             //$GLOBALS['log']->fatal($sqlmsg . ": " . $sql );
             if ($dieOnError) {
                 ts_die('<span style="display:none">SQL Error : Line 127</span>');
             } else {
                 ts_die('<span style="display:none">SQL Error : Line 127</span>');
                 //echo 'SQL Error : ' . $sqlmsg;
             }
         }
     }
     $this->lastmysqlrow = -1;
     $this->query_time = microtime(true) - $this->query_time;
     //$GLOBALS['log']->info('Query Execution Time:'.$this->query_time);
     $this->checkError($msg . ' Query Failed:' . $sql . '::', $dieOnError);
     // fetch all the returned rows into an the resultsCache
     if (is_resource($result)) {
         $i = 0;
         while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
             $this->_resultsCache[$this->_lastResultsCacheKey][$i++] = $row;
         }
         sqlsrv_free_stmt($result);
         return $this->_lastResultsCacheKey++;
     } else {
         return $result;
     }
 }