Пример #1
0
 /**
  * Add a message to session.
  *
  *
  * @param mixed  $message Message or array of message strings
  * @param string $class   Tells XSL/CSS which type of message this is
  */
 public function addMessage($message, $class = 'alert alert-info')
 {
     if (session_status() == PHP_SESSION_NONE) {
         return false;
     }
     if (!isset($_SESSION['messages'])) {
         $_SESSION['messages'] = array();
     }
     if (is_object($message)) {
         $message = (string) $message;
     }
     $message = (array) $message;
     foreach ($message as &$v) {
         $msgObj = new stdClass();
         $msgObj->item = (string) $v;
         $msgObj->type = $class;
         $_SESSION['messages'][] = $msgObj;
     }
     Debug::__print($_SESSION['messages']);
 }
Пример #2
0
 public function __printNode(\DOMNode $node)
 {
     // Needs debugs enabled
     if (error_reporting() != E_ALL) {
         return false;
     }
     $iterator = new DOMRecursiveIterator($node);
     $decorated = new DOMRecursiveDecoratorStringAsCurrent($iterator);
     $tree = new RecursiveTreeIterator($decorated);
     $output = array();
     foreach ($tree as $v) {
         $v = trim(str_replace("\n", '', $v));
         $checkEmpty = str_replace('|', '', $v);
         $checkEmpty = str_replace('-', '', $checkEmpty);
         $checkEmpty = str_replace(' ', '', $checkEmpty);
         if (!empty($v) && !empty($checkEmpty)) {
             $output[] = $v . '>';
         }
     }
     Debug::__print($output);
 }
Пример #3
0
 /**
  * Executes a prepared query.
  *
  * After this, you can use resultset as you would have called it via DB::execute().
  *
  *
  * @uses   DB
  */
 public function execute()
 {
     if ($this->stmt) {
         try {
             $this->stmt->execute();
             unset($this->fields);
             if ($this->stmt->columnCount()) {
                 $this->rows = $this->stmt->fetchAll(PDO::FETCH_OBJ);
             } else {
                 $this->rows = array();
             }
             $this->index = 0;
             $this->recordCount = count($this->rows);
             $this->column = 1;
         } catch (Exception $e) {
             Debug::__print($this->stmt);
             throw new DB_Exception('Executing a prepared query failed.', 0, $e);
         }
         DB::$querycount++;
     } else {
         throw new DB_Exception('Program attempted to execute query twice.');
     }
     return $this;
 }
Пример #4
0
 /**
  * Insert/update row.
  */
 public function save()
 {
     if (is_numeric($this->lateload)) {
         $this->_byID();
     }
     if ($this->modified === false) {
         return;
     }
     if (!isset($this->data->{$this->primaryKey})) {
         $this->data->{$this->primaryKey} = null;
     }
     $fields = $values = $updates = '';
     foreach ($this->data as $key => $val) {
         $fields[$key] = '?';
     }
     if (!is_numeric($this->data->{$this->primaryKey})) {
         $query = "\n                INSERT INTO {$this->struct} (`" . implode('`,`', array_keys($fields)) . '`)
             VALUES (' . implode(',', $fields) . ')';
         if ($this->db->properties['db_server'] === 'postgres') {
             $query .= " RETURNING {$this->primaryKey}";
         }
     } else {
         $query = "\n                UPDATE {$this->struct}\n                SET `" . implode('` = ?,`', array_keys($fields)) . "` = ?\n                WHERE {$this->primaryKey} = ?";
     }
     unset($fields);
     $stmt = $this->db->prepare($query);
     foreach ($this->data as $val) {
         $stmt->set($val);
     }
     if (is_numeric($this->data->{$this->primaryKey})) {
         $stmt->set((int) $this->data->{$this->primaryKey});
     }
     try {
         $stmt->execute();
     } catch (PDOException $e) {
         Debug::__print($e->getMessage());
     }
     if (!is_numeric($this->data->{$this->primaryKey})) {
         $this->data->{$this->primaryKey} = (int) $this->db->properties['db_server'] === 'postgres' ? $stmt->fetchColumn() : $this->db->lastInsertID();
     }
     return $this->data->{$this->primaryKey};
 }