Esempio n. 1
0
 function query($query)
 {
     global $config;
     // разбираем запрос
     $type = $this->parseQuery($query);
     // выполняем запрос
     try {
         $result = $this->link->query($query);
         // получаем результаты
         if (in_array($type, array('SELECT', 'SHOW'))) {
             $result->setFetchMode(PDO::FETCH_OBJ);
             while ($row = $result->fetch()) {
                 $res[] = $row;
             }
         } elseif (in_array($type, array('INSERT'))) {
             $res[] = $this->link->lastInsertId();
         }
         // увеличиваем счетчик запросов
         $this->callsCount++;
         // если дебаг включен то добавляем запрос в лог
         if ($config['debug'] == true) {
             $this->callsDebug[] = $query;
         }
     } catch (PDOException $e) {
         errorHandler(0, array($e->getMessage(), $query), __FILE__, __LINE__);
     }
     return isset($res) ? $res : NULL;
 }
Esempio n. 2
0
 function shutDownHandler()
 {
     $lastError = error_get_last();
     if (isset($lastError) && $lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING)) {
         errorHandler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']);
     }
 }
Esempio n. 3
0
/**
 * Checks for a fatal error, work around for set_error_handler not working on fatal errors.
 */
function check_for_fatal()
{
    $error = error_get_last();
    if ($error["type"] == E_ERROR) {
        errorHandler($error["type"], $error["message"], $error["file"], $error["line"]);
    }
}
Esempio n. 4
0
 public function actionBulkCreate(array $names = array(), $parentId = 0, $vocabularyId = 0)
 {
     $vocabularyId = CPropertyValue::ensureInteger($vocabularyId);
     if (!$vocabularyId) {
         return errorHandler()->log('Missing Vocabulary Id');
     }
     foreach ($names as $catName) {
         $catName = trim($catName);
         if ($catName == '') {
             continue;
         }
         $model = new Term('single_save');
         $model->v_id = $vocabularyId;
         $model->name = $catName;
         $model->alias = Utility::createAlias($model, $model->name);
         $model->state = Term::STATE_ACTIVE;
         $model->parentId = $parentId;
         if (!$model->save()) {
             $this->result->fail(ERROR_HANDLING_DB, 'save category failed');
         } else {
             if ($model->parentId) {
                 $relation = TermHierarchy::model()->findByAttributes(array('term_id' => $model->id));
                 if (!is_object($relation)) {
                     $relation = new TermHierarchy();
                     $relation->term_id = $model->id;
                 }
                 $relation->parent_id = $model->parentId;
                 if (!$relation->save()) {
                     Yii::log(CVarDumper::dumpAsString($relation->getErrors()), CLogger::LEVEL_ERROR);
                 }
             }
         }
     }
 }
Esempio n. 5
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         if (($id = $this->get('id', null)) !== null) {
             $ids = is_numeric($id) ? array($id) : explode(',', $id);
             // delete one or multiple objects given the list of object IDs
             $result = $this->api('XUser.AdminUserGroup.delete', array('ids' => $ids));
             if (errorHandler()->getException() == null) {
                 // only redirect user to the admin page if it is not an AJAX request
                 if (!Yii::app()->request->isAjaxRequest) {
                     $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
                 } else {
                     echo 'Items are deleted successfully';
                 }
             } else {
                 // redirecting with error carried ot the redirected page
                 if (!Yii::app()->request->isAjaxRequest) {
                     user()->setFlashErrors(errorHander()->getErrors());
                     $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
                 } else {
                     //This won't work for grid as its jquery.gridview.js alert ajax content
                     //echo errorHandler()->getErrorMessages();
                     echo errorHandler()->getException()->message;
                 }
             }
         } else {
             throw new CHttpException(400, Yii::t('Xpress.XUserGroup', 'Cannot delete item with the given ID.'));
         }
     } else {
         throw new CHttpException(400, Yii::t('Xpress.XUserGroup', 'Invalid request. Please do not repeat this request again.'));
     }
 }
Esempio n. 6
0
 public function actionChangePassword($oldPassword, $newPassword, $confirmPassword)
 {
     $model = app()->user->UserModel;
     $model->passwordOld = $oldPassword;
     $model->password = $newPassword;
     $model->confirmPassword = $confirmPassword;
     $model->setScenario('change_password');
     if (!$model->validate('passwordOld', 'password', 'confirmPassword')) {
         errorHandler()->log(new XException($model, 0));
         $this->result = false;
         return false;
     }
     $user = app()->user->UserModel->find('id=:id AND password=:password', array(':id' => app()->user->id, ':password' => md5($model->passwordOld)));
     if (is_null($user)) {
         $model->addError('passwordOld', 'Old Password is wrong');
         errorHandler()->log(new XException($model, 0));
         $this->result = false;
         return false;
     }
     if ($model->passwordOld == $model->password) {
         $model->addError('password', 'New Password is the same with Old Password');
         errorHandler()->log(new XException($model, 0));
         $this->result = false;
         return false;
     }
     app()->user->UserModel->updateByPk(app()->user->id, array('password' => md5($model->password)));
     $this->result = true;
 }
Esempio n. 7
0
 public function actionDelete(array $ids)
 {
     $deleted = array();
     foreach ($ids as $id) {
         $model = Module::model()->findByPk($id);
         /**
         * TODO: Check related data if this Module is deletable
         * This can be done in onBeforeDelete or here or in hooks
         *
         if (Related::model()->count("module_id = {$id}") > 0)
         {
             errorHandle()->log(new XException(Yii::t('Admin.Module',"Cannot delete Module ID={$id} as it has related class data."));
         }
         else
         */
         try {
             $deleted[] = $model->PrimaryKey;
             $model->delete();
         } catch (CException $ex) {
             array_pop($deleted);
             errorHandler()->log(new XException($ex->getMessage(), $ex->getCode()));
         }
     }
     return $this->result = $deleted;
 }
Esempio n. 8
0
 public function actionDelete($authItemName)
 {
     $authItemName = trim($authItemName);
     if ($authItemName == '') {
         return $this->result = errorHandler()->logException(null, -1, 'XUSER_ERR_ROLE_NAME_EMPTY', array('message' => 'Role name is empty'));
     }
     $authItem = AuthItem::model()->find('name=:name', array(':name' => $authItemName));
     if (!is_object($authItem)) {
         return $this->result = errorHandler()->logException(null, -1, 'XUSER_ERR_ROLE_NOT_FOUND', array('message' => 'Role is not found'));
     }
     // check if this role is system role
     if ($authItem->is_system == true) {
         return $this->result = errorHandler()->logException(null, -1, 'XUSER_ERR_ROLE_CANNOT_DELETE_BECAUSE_SYSTEM', array('message' => 'Cannot delete this role as it is a system role'));
     }
     // check if this role is assigned to any user
     $sql = 'SELECT COUNT(userid) FROM "' . SITE_ID . '_authassignment" WHERE itemname = \'' . $authItem->name . '\'';
     $count = app()->db->createCommand($sql)->queryScalar();
     if ($count > 0) {
         return $this->result = errorHandler()->logException(null, -1, 'XUSER_ERR_ROLE_CANNOT_DELETE_BECAUSE_ASSIGNED', array('message' => "Cannot delete this role as it's assigned to users"));
     }
     // delete the role
     if (!$authItem->delete()) {
         return $this->result = errorHandler()->logException(null, -1, 'XUSER_ERR_ROLE_DELETE_FAILED', array('message' => 'Deleting the role has been failed'));
     }
     return $this->result = array('result' => null, 'returnCode' => 1);
 }
Esempio n. 9
0
 public function init()
 {
     if ($this->id == '') {
         throw errorHandler()->logException(null, -1, 'XPRESS_XDATATABLE_INVALID_ID', array('message' => 'XDataTable requires a specific id'));
     }
     $this->registerJs();
 }
Esempio n. 10
0
 function query($Query_String)
 {
     if (defined('DB_TUNNEL')) {
         $opts = array('http' => array('method' => 'POST', 'header' => 'Content-Type: application/binary, Content-Transfer-Encoding: base64', 'content' => base64_encode(gzcompress($Query_String))));
         $result = file_get_contents(DB_TUNNEL, false, stream_context_create($opts));
         $result = gzuncompress(base64_decode($result));
         $result = json_decode($result, true);
         return array('data' => $result, 'ptr' => 0);
     }
     $this->connect();
     $type = explode(' ', $Query_String);
     $type = strtoupper($type[0]);
     global $acl;
     if (in_array($type, array('SELECT', 'DESCRIBE', 'SHOW')) && !in_array('view', $acl) || in_array($type, array('INSERT', 'CREATE')) && !in_array('add', $acl) || in_array($type, array('UPDATE', 'ALTER')) && !in_array('edit', $acl) || in_array($type, array('DELETE', 'DROP', 'TRUNCATE')) && !in_array('delete', $acl)) {
         ob_clean();
         global $lex, $user, $errorHandlerLatch;
         $errorHandlerLatch = true;
         //$yield = $Query_String;
         //die($Query_String);
         require_once 'templates/error_401.php';
     }
     $this->Query_ID = mysqli_query($this->Link_ID, $Query_String);
     $this->Row = 0;
     $this->Errno = mysqli_errno($this->Link_ID);
     $this->Error = mysqli_error($this->Link_ID);
     if (!$this->Query_ID) {
         $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
         $i = 0;
         while (substr($backtrace[$i]['file'], strlen($backtrace[$i]['file']) - 23) == 'interfaces/database.php') {
             $i += 1;
         }
         errorHandler(1, $this->Error . '<br/><pre>' . str_replace(array('FROM', 'WHERE', 'AND', 'ORDER'), array('<br/>FROM', '<br/>WHERE', '<br/> &nbsp; AND', '<br/>ORDER'), $Query_String) . '</pre>', $backtrace[$i]['file'], $backtrace[$i]['line']);
     }
     return $this->Query_ID;
 }
Esempio n. 11
0
function fatalErrorShutdownHandler()
{
    $last_error = error_get_last();
    if ($last_error['type'] === E_ERROR) {
        // fatal error
        errorHandler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
    }
}
Esempio n. 12
0
function fatalErrorHandler()
{
    $types = array(E_ERROR, E_PARSE);
    $err = error_get_last();
    if (in_array($err['type'], $types)) {
        errorHandler($err['type'], $err['message'], $err['file'], $err['line']);
    }
}
Esempio n. 13
0
function deleteBlog($DB, $bid)
{
    $stmt = $DB->prepare("DELETE FROM blog WHERE blogId=?");
    if (!$stmt->bind_param('i', $bid)) {
        return errorHandler("deleteBlog failed to bind parameter", 503);
    }
    return $stmt;
}
Esempio n. 14
0
function updateUserPassword($DB, $uid, $passwordHash)
{
    $stmt = $DB->prepare("UPDATE user SET userHash=? WHERE userId=?");
    if (!$stmt->bind_param('si', $passwordHash, $uid)) {
        return errorHandler("updateList failed to bind parameter", 503);
    }
    return $stmt;
}
Esempio n. 15
0
function deletePage($DB, $pid)
{
    $stmt = $DB->prepare("DELETE FROM staticPage WHERE staticPageId=?");
    if (!$stmt->bind_param('i', $pid)) {
        return errorHandler("deletePage failed to bind parameter", 503);
    }
    return $stmt;
}
Esempio n. 16
0
function deleteComment($DB, $cid)
{
    $stmt = $DB->prepare("DELETE FROM comment WHERE commentId=?");
    if (!$stmt->bind_param('i', $cid)) {
        return errorHandler("deleteComment failed to bind parameter", 503);
    }
    return $stmt;
}
Esempio n. 17
0
function htmlErrorHandler($errno, $errstr, $errfile, $errline)
{
    if (!$GLOBALS['_show_silenced'] && !error_reporting() || $errno == 2048) {
        return;
    }
    echo '<pre>';
    errorHandler($errno, $errstr, $errfile, $errline);
    echo '</pre>';
}
Esempio n. 18
0
 public function callMethod($className, $classMethod, $methodArguments = NULL)
 {
     // если класс не создан, либо не является объектом то ошибку
     if (!isset($this->objects[$className]) || !is_object($this->objects[$className])) {
         errorHandler(0, $className . ' Class not registred (called method: ' . $classMethod . ' with argument ' . $methodArguments, __FILE__, __LINE__);
     } else {
         return $this->objects[$className]->{$classMethod}($methodArguments);
     }
 }
function assert_failure($file, $line, $message)
{
    $debug = debug_backtrace(false);
    foreach ($debug as $file) {
        if ($file['file'] && stripos($file['file'], 'sphinxapi.0.99.php') === false) {
            errorHandler(E_WARNING, "[Sphinx] Assertion sur " . $file['function'] . " : " . $message, $file['file'], $file['line'], $errcontext);
            break;
        }
    }
}
Esempio n. 20
0
 public function actionDelete(array $ids)
 {
     foreach ($ids as $id) {
         $model = AdminUserGroup::model()->findByPk($id);
         if (is_null($model)) {
             errorHandler()->log(Yii::t('AdminUserGroup.Api', 'Admin User Group not found.'));
             continue;
         }
         if (AdminUser::model()->count('user_group_id=:groupId', array(':groupId' => $model->id)) > 0) {
             errorHandler()->log(Yii::t('AdminUserGroup.Api', 'This group has user. Cannot delete.'));
             continue;
         }
         $model->delete();
     }
     return $this->result;
 }
Esempio n. 21
0
function errorHandler_fatal($buffer) {
	/*if (ereg("(error</b>:)(.+)(<br)", $buffer, $regs) ) {
	    $err = preg_replace("/<.*?>/","",$regs[2]);
	    error_log($err);
	    return "ERROR CAUGHT check log file";
	  }
	  return $buffer;*/
	$error = @error_get_last();
	if($error && ($error['type'] & error_reporting()) && ($error['message'] != "")) {
		//  return ($error['message'] == "") . ', ' . $error['type'] . ' [' . $error['message'] . '] ' . $error['file']. ' ' . $error['line'] . '; ';
	    $err = errorHandler($error['type'], $error['message'], $error['file'], $error['line'], false, true);
		return $err ? $err : '???';
	} else
		return $buffer;
	
}
Esempio n. 22
0
function fatalHandler()
{
    $number = 0;
    $message = 'Unknown message';
    $file = 'Unknown file';
    $line = 0;
    $unknown = 3;
    $error = error_get_last();
    if (!is_null($error)) {
        $number = $error['type'];
        $message = $error['message'];
        $file = $error['file'];
        $line = $error['line'];
        $unknown = 2;
    }
    errorHandler($number, $message, $file, $line, $unknown);
}
Esempio n. 23
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         if (($id = $this->get('id', null)) !== null) {
             $ids = is_numeric($id) ? array($id) : explode(',', $id);
             // delete one or multiple objects given the list of object IDs
             $result = $this->api('XUser.User.delete', array('ids' => $ids));
             if (errorHandler()->getException() == null && !Yii::app()->request->isAjaxRequest) {
                 // only redirect user to the admin page if it is not an AJAX request
                 $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
             }
         } else {
             throw new CHttpException(400, Yii::t('Xpress.XUserGroup', 'Cannot delete item with the given ID.'));
         }
     } else {
         throw new CHttpException(400, Yii::t('Xpress.XUserGroup', 'Invalid request. Please do not repeat this request again.'));
     }
 }
Esempio n. 24
0
 public function actionDelete(array $ids)
 {
     foreach ($ids as $id) {
         $model = UserGroup::model()->findByPk($id);
         /**
         * TODO: Check related data if this UserGroup is deletable
         * This can be done in onBeforeDelete or here or in extensions
         *
         if (Related::model()->count("UserGroupId = {$id}") > 0)
             $this->result->fail(ERROR_VIOLATING_BUSINESS_RULES, Yii::t('XUser.UserGroup',"Cannot delete UserGroup ID={$id} as it has related class data."));
         else
         */
         try {
             $model->delete();
         } catch (CException $ex) {
             errorHandler()->log(new XException($ex->getMessage(), $ex->getCode()));
         }
     }
     return $this->result;
 }
Esempio n. 25
0
 /**
  * Database authentication with checking of user status to support account activation
  * which use Status as Role
  */
 public function authenticate()
 {
     $user = user()->getUserModel();
     $criteria = new CDbCriteria();
     $criteria->condition = user()->UsernameField . ' ILIKE :username OR ' . user()->EmailField . ' ILIKE :username';
     $criteria->params = array(':username' => $this->username);
     //        $criteria->addSearchCondition(user()->UsernameField, $this->username, false, 'AND','ILIKE');
     $this->user = $user->find($criteria);
     if (is_null($this->user)) {
         errorHandler()->log(new XException('Your username is invalid', self::ERROR_USERNAME_INVALID));
     } elseif ($this->user->Attributes[user()->PasswordField] != md5($this->password)) {
         errorHandler()->log(new XException('Invalid username or password.', self::ERROR_PASSWORD_INVALID));
     } elseif (($errMsg = $this->user->validateStatus()) !== TRUE) {
         errorHandler()->log(new XException($errMsg, self::ERROR_STATUS_INVALID));
     } else {
         $this->errorCode = self::ERROR_NONE;
         foreach (user()->UserStatefulFields as $field) {
             $this->setState($field, $this->user->Attributes[$field]);
         }
     }
     return $this->user;
 }
Esempio n. 26
0
 /**
  * To be moved to authController
  */
 public function actionLogin()
 {
     if (!user()->isGuest) {
         errorHandler()->log(new XException('Try to login while you are not a guest.', 0));
         user()->logout();
     }
     $user = new LoginForm();
     if (Yii::app()->request->isPostRequest) {
         $user->attributes = $_POST['LoginForm'];
         $ret = $this->api('Xpress.User.login', array('email' => $user->login, 'password' => $user->password, 'remember' => $user->remember));
         if ($ret === true) {
             $url = user()->returnUrl;
             if (empty($url)) {
                 if (!$url) {
                     $url = $this->createUrl('/Admin/default');
                 }
             }
             $this->redirect($url);
         }
     }
     $this->layout = '//layouts/master';
     $this->render('login', array('user' => $user));
 }
Esempio n. 27
0
 protected function saveData($module, $v, $propertyModule, $propertyClassName)
 {
     // check it is action create or update
     if (isset($_POST['Term']['id']) && !empty($_POST['Term']['id'])) {
         $action = 'update';
     } else {
         $action = 'create';
     }
     $model = $this->controller->api('Xpress.Term.save', array('attributes' => $_POST['Term']));
     if (errorHandler()->getException() == null) {
         if (empty($propertyClassName) === false) {
             $_POST[$propertyClassName]['term_id'] = $model->id;
             $this->controller->api($propertyModule . '.' . $propertyClassName . '.save', array('attributes' => $_POST[$propertyClassName]));
         }
         $this->controller->message = Yii::t('Xpress', 'Item has been saved successfully.');
         if ($action == 'update') {
             $this->controller->redirect($this->controller->createUrl('update', array('id' => $model->id, 'v' => $v, 'm' => $module)));
         } else {
             Yii::app()->user->setFlash('category_just_added', $model->id);
             $this->controller->redirect($this->controller->createUrl('create', array('v' => $v, 'm' => $module)));
         }
     }
     return $model;
 }
Esempio n. 28
0
function shutdownHandler()
{
    if (is_null($e = error_get_last()) === false) {
        errorHandler($e['type'], $e['message'], $e['file'], $e['line']);
    }
}
Esempio n. 29
0
<?php

//setup login. if it has no time, or time is older than 1 day, logout
if (!isset($_SESSION['time'])) {
    //|| $_SESSION['time'] > (time() + (24*60*60)){
    return errorHandler('unauthorized', 401);
} else {
    $USER->id = $_SESSION['userId'];
    $USER->name = $_SESSION['userName'];
    $result = array();
    $result['userid'] = $USER->id;
    echo json_encode($result);
}
Esempio n. 30
0
            ob_end_clean();
            if ($yield == ' ') {
                die;
            }
            $errline = strpos($yield, 'on line') + 8;
            if ($errline == 8) {
                errorHandler(0, $yield, '', '');
            } else {
                $errfile = strpos($yield, ' in ') + 4;
                $errno = strpos($yield, ':');
                $errstr = $yield;
                // trim(substr($yield, $errno+1, $errfile-$errno-5));
                $errno = trim(substr($yield, 0, $errno));
                $errfile = trim(substr($yield, $errfile, strpos($yield, ' ', $errfile) - $errfile));
                $errline = trim(substr($yield, $errline, strpos($yield, ' ', $errline) - $errline));
                errorHandler($errno, $errstr, $errfile, $errline);
            }
            die;
        }
    }
});
if (ON_ERROR == 'DISPLAY') {
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
} else {
    if (ON_ERROR == 'IGNORE') {
        ini_set('display_errors', 0);
        ini_set('display_startup_errors', 0);
        error_reporting(0);
    }