Esempio n. 1
0
 /**
  * Add an error.
  *
  * This function is used by both builtin PHP functions and Coders.
  * Only the first two parameters is needed if adding an error through code.
  * @param string Error
  * @param string Description
  */
 public static function add($one, $two = false, $three = false, $four = false, $five = false)
 {
     if (self::shouldAdd($one, $two, $three, $four, $five)) {
         self::$adding = true;
         if (!is_numeric($one) && !$three && !$four && !$five) {
             self::addBE($one, $two);
         } else {
             self::addPHP($one, $two, $three, $four, $five);
         }
         self::$adding = false;
     }
 }
 public function get($name = false, $type = BackendLock::LOCK_CUSTOM, $expire = null, $password = null)
 {
     if (empty($password)) {
         if (Component::isActive('BackendError')) {
             BackendError::add('Missing BackendSystemLock Password', 'No password was supplied for the system lock named ' . $name);
         }
         return null;
     }
     $result = parent::get($name, $type, $expire);
     if ($result) {
         ConfigValue::set('LockPassword_' . $this->array['name'], $password);
     }
 }
Esempio n. 3
0
 public static function hook_output($output)
 {
     //TODO Attach HTTP Error codes and descriptions to these errors
     if (!is_array($output)) {
         BackendError::add('Google Chart Error', 'Invalid Output');
         return false;
     }
     $type = array_key_exists('type', $output) ? $output['type'] : Backend::get('ChartType', 'simple_line');
     if (!method_exists('GChartView', $type)) {
         BackendError::add('Google Chart Error', 'Invalid Chart Type');
         return false;
     }
     if (!array_key_exists('data', $output)) {
         $output = array('data' => $output);
     }
     if (!is_array($output['data']) || !count($output['data'])) {
         BackendError::add('Google Chart Error', 'Invalid Output Data');
         return false;
     }
     $params = array();
     $title = array_key_exists('title', $output) ? $output['title'] : Backend::get('ChartTitle', false);
     if ($title) {
         $params['chtt'] = $title;
     }
     $url = self::$type($output, $params);
     if (Controller::$debug) {
         echo '<img src="' . $url . '">';
         var_dump($params);
         var_dump($output);
         $dont_kill = Controller::getVar('dont_kill');
         if (empty($dont_kill)) {
             die;
         }
     }
     $recache = Controller::getVar('recache') ? true : false;
     debug_header('Recache - ' . $recache);
     $image = curl_request($url, array(), array('cache' => $recache ? 1 : 60 * 60, 'bypass_ssl' => 1));
     if (Controller::$debug) {
         var_dump('Image:', $image);
     }
     if (!$image) {
         BackendError::add('Google Chart Error', 'Could not get image');
         return false;
     }
     $filename = Backend::get('ChartFilename', false);
     if (!$filename) {
         $filename = class_name(Controller::$area) . class_name(Controller::$action);
         if (Controller::$action == 'read' && !empty(Controller::$parameters[0])) {
             $filename .= Controller::$parameters[0];
         }
     }
     if (Controller::$debug) {
         var_dump('Filename:', $filename);
     }
     header('Content-Disposition: inline; filename="' . $filename . '.png"');
     return $image;
 }
Esempio n. 4
0
 public static function __exception_handler($exception)
 {
     if (Controller::$debug) {
         $trace = array_reverse($exception->getTrace());
         echo '<ol>';
         foreach ($trace as $item) {
             echo '<li>';
             if (isset($item['file'])) {
                 echo $item['file'];
             }
             if (isset($item['line'])) {
                 echo '(' . $item['line'] . ') called ';
             }
             if (isset($item['class'])) {
                 echo '<strong>' . $item['class'] . '</strong>->';
             }
             if (isset($item['function'])) {
                 echo '<i>' . $item['function'] . '</i>';
             }
             echo '</li>';
         }
         echo '</ol>';
     }
     echo "Uncaught exception: ", $exception->getMessage(), ' in ', $exception->getFile(), ' line ', $exception->getLine(), "\n";
     if (Component::isActive('BackendError')) {
         BackendError::add($exception->getCode(), "Uncaught exception: " . $exception->getMessage(), $exception->getFile(), $exception->getLine());
     }
     //Execution ends here
 }
Esempio n. 5
0
 public function getSelectSQL($options = array())
 {
     //Check the DB Connection
     $this->error_msg = false;
     if (!$this->checkConnection()) {
         if (class_exists('BackendError', false)) {
             BackendError::add(get_class($this) . ': DB Connection Error', 'getSelectSQL');
         }
         $this->error_msg = 'DB Connection Error';
         return false;
     }
     $mode = array_key_exists('mode', $options) ? $options['mode'] : 'list';
     $query = new SelectQuery($this, array('connection' => $this->db));
     //Fields
     $fields = array_key_exists('fields', $options) ? $options['fields'] : array();
     if (empty($fields)) {
         $query->field("`{$this->meta['table']}`.*");
     } else {
         $query->field($fields);
     }
     //Joins
     $joins = array_key_exists('joins', $options) ? $options['joins'] : array();
     if (count($joins)) {
         foreach ($joins as $join) {
             if (is_array($join)) {
                 $query->joinArray($join);
             }
         }
     }
     $q_params = array();
     if (!empty($options['conditions'])) {
         $query->filter($options['conditions']);
     }
     //Mode specific
     $limit = false;
     switch ($mode) {
         case 'object':
         case 'array':
         case 'full_object':
             if (!empty($this->meta['id'])) {
                 $query->filter("`{$this->meta['table']}`.`{$this->meta['id_field']}` = :{$this->meta['table']}_id");
                 $q_params[":{$this->meta['table']}_id"] = $this->meta['id'];
             } else {
                 $query->limit(empty($limit) ? 1 : $limit);
             }
             break;
         case 'list':
             if (array_key_exists('limit', $options) && $options['limit'] != 'all') {
                 $query->limit($options['limit']);
             }
             break;
     }
     //Parameters
     if (array_key_exists('parameters', $options)) {
         if (is_array($options['parameters'])) {
             $q_params = array_merge($q_params, $options['parameters']);
         } else {
             $q_params[] = $options['parameters'];
         }
     } else {
         if (!empty($this->meta['parameters'])) {
             if (is_array($this->meta['parameters'])) {
                 $q_params = array_merge($q_params, $this->meta['parameters']);
             } else {
                 $q_params[] = $parameters;
             }
         }
     }
     //Filters
     if (array_key_exists('filters', $options)) {
         $query->filter($options['filters']);
     } else {
         if (!empty($this->meta['filters'])) {
             $query->filter($this->meta['filters']);
         }
     }
     //Order
     if (array_key_exists('order', $options)) {
         $query->order($options['order']);
     } else {
         if (!empty($this->meta['order'])) {
             $query->order($this->meta['order']);
         }
     }
     //Group
     if (array_key_exists('group', $options)) {
         $query->group($options['group']);
     } else {
         if (!empty($this->meta['group'])) {
             $query->group($this->meta['group']);
         }
     }
     //Check Ownership
     if (array_key_exists('owner_id', $this->meta['fields'])) {
         if ($user = BackendUser::check()) {
             if (!in_array('superadmin', $user->roles)) {
                 $query->filter("`{$this->meta['table']}`.`owner_id` = :owner_id");
                 $q_params[':owner_id'] = $user->id;
             }
         }
     }
     return array($query, $q_params);
 }
Esempio n. 6
0
 public function execute(array $parameters = array(), array $options = array())
 {
     $toret = false;
     $this->error_msg = false;
     $this->error_code = 0;
     if (empty($this->query)) {
         $this->last_stmt = false;
         $this->query = $this->buildQuery();
     }
     if ($this->checkConnection() && !empty($this->query)) {
         $parameters = array_merge($this->parameters, $parameters);
         //Check if we've already executed this query, and that the parameters are the same
         $check_cache = array_key_exists('check_cache', $options) ? $options['check_cache'] : true;
         if ($check_cache && $this->last_stmt && !count(array_diff_assoc($parameters, $this->last_params))) {
             if (Controller::$debug >= 2) {
                 var_dump('Executing Cached statement');
             }
             $toret = $this->last_stmt;
         } else {
             $stmt = $this->connection->prepare($this->query);
             if ($stmt) {
                 $this->last_stmt = $stmt;
                 $this->last_params = $parameters;
                 if ($stmt->execute($parameters)) {
                     $toret = $stmt;
                 } else {
                     $error_info = $stmt->errorInfo();
                     if ($error_info[0] == 'HY093') {
                         $error_info[1] = 'HY093';
                         $error_info[2] = 'Invalid Parameters passed to statement';
                     }
                     $verbose_error = array('Query::execute Error:');
                     if (!empty($error_info[2])) {
                         $verbose_error[] = $error_info[2];
                     }
                     if (!empty($error_info[1])) {
                         $verbose_error[] = '(' . $error_info[1] . ')';
                     }
                     $verbose_error = implode(' ', $verbose_error);
                     if (Component::isActive('BackendError') && empty($options['dont_moan'])) {
                         BackendError::add($verbose_error, 'execute');
                     }
                     if (Controller::$debug) {
                         print_stacktrace();
                         echo 'Error Info:';
                         var_dump($error_info);
                         if (Controller::$debug >= 2) {
                             echo 'Query:<pre>' . PHP_EOL . $stmt->queryString . '</pre>';
                         }
                         $this->error_msg = $verbose_error;
                     } else {
                         $this->error_msg = 'Error executing statement';
                         if (!empty($error_info[1])) {
                             $this->error_msg .= '(' . $error_info[1] . ')';
                         }
                     }
                     $this->error_code = $error_info[1];
                 }
             } else {
                 $this->error_msg = 'Could not prepare statement';
             }
         }
     } else {
         $this->error_msg = 'Could not execute query';
     }
     return $toret;
 }
Esempio n. 7
0
 public static function whoops($title = 'Whoops!', $extra = 'Looks like something went wrong...')
 {
     self::$whoopsed = true;
     if (is_array($extra)) {
         $code_hint = array_key_exists('code_hint', $extra) ? $extra['code_hint'] : false;
         $message = array_key_exists('message', $extra) ? $extra['message'] : false;
     } else {
         if (is_numeric($extra)) {
             $code_hint = $extra;
             $message = 'Looks like something went wrong...';
         } else {
             $code_hint = false;
             $message = $extra;
         }
     }
     if (Component::isActive('BackendError')) {
         BackendError::add($title, $message);
     }
     if (is_callable(array(self::$view, 'whoops'))) {
         call_user_func_array(array(self::$view, 'whoops'), array($title, $message, $code_hint));
     } else {
         if (self::$view instanceof View) {
             self::$view->whoops($title, $message, $code_hint);
         }
     }
     if (array_key_exists('debug', self::$query_vars)) {
         var_dump($title, $message);
         print_stacktrace();
     }
 }