Example #1
0
function installMysqli($host, $user, $pass, $dbname)
{
    $sqls = getSqls("mysql");
    $db = new mysqli($host, $user, $pass);
    $db->query("CREATE DATABASE {$dbname}");
    $db->select_db($dbname);
    if (is_array($sqls)) {
        foreach ($sqls as $query) {
            $db->query($query);
        }
    }
    Jf::$Db = new mysqli($host, $user, $pass, $dbname);
    Jf::$Rbac->reset(true);
}
Example #2
0
 static function sqlMysqli($Query)
 {
     $debug_backtrace = debug_backtrace();
     if (isset($debug_backtrace[3]) && $debug_backtrace[3]['function'] == 'pathId') {
         if (!self::$groupConcatLimitChanged) {
             $success = self::$Db->query("SET SESSION group_concat_max_len = 1000000");
             if ($success) {
                 self::$groupConcatLimitChanged = true;
             }
         }
     }
     $args = func_get_args();
     if (count($args) == 1) {
         $result = self::$Db->query($Query);
         if ($result === true) {
             return true;
         }
         if ($result && $result->num_rows) {
             $out = array();
             while (null != ($r = $result->fetch_array(MYSQLI_ASSOC))) {
                 $out[] = $r;
             }
             return $out;
         }
         return null;
     } else {
         if (!($preparedStatement = self::$Db->prepare($Query))) {
             trigger_error("Unable to prepare statement: {$Query}, reason: " . self::$Db->error);
         }
         array_shift($args);
         // remove $Query from args
         $a = array();
         foreach ($args as $k => &$v) {
             $a[$k] =& $v;
         }
         $types = str_repeat("s", count($args));
         // all params are
         // strings, works well on
         // MySQL
         // and SQLite
         array_unshift($a, $types);
         call_user_func_array(array($preparedStatement, 'bind_param'), $a);
         $preparedStatement->execute();
         $type = substr(trim(strtoupper($Query)), 0, 6);
         if ($type == "INSERT") {
             $res = self::$Db->insert_id;
             if ($res == 0) {
                 return self::$Db->affected_rows;
             }
             return $res;
         } elseif ($type == "DELETE" or $type == "UPDATE" or $type == "REPLAC") {
             return self::$Db->affected_rows;
         } elseif ($type == "SELECT") {
             // fetching all results in a 2D array
             $metadata = $preparedStatement->result_metadata();
             $out = array();
             $fields = array();
             if (!$metadata) {
                 return null;
             }
             while (null != ($field = $metadata->fetch_field())) {
                 $fields[] =& $out[$field->name];
             }
             call_user_func_array(array($preparedStatement, "bind_result"), $fields);
             $output = array();
             $count = 0;
             while ($preparedStatement->fetch()) {
                 foreach ($out as $k => $v) {
                     $output[$count][$k] = $v;
                 }
                 $count++;
             }
             $preparedStatement->free_result();
             return $count == 0 ? null : $output;
         } else {
             return null;
         }
     }
 }
Example #3
0
     fclose($handle);
     unset($handle);
     $handle = fopen(RSA_PUBLIC_KEY_FILE, 'w');
     $data = $keypair['publickey'];
     fwrite($handle, $data);
     fclose($handle);
     unset($handle);
 } else {
     exit('Critical error while installing ! Unable to write to /app/crypto/ !');
 }
 //---------------------------------------------------------+
 // Creating Database Schema
 require "./sql/full.php";
 //---------------------------------------------------------+
 // Creating System Permissions
 Jf::$Db = $dbh;
 $rbac = new PhpRbac\Rbac();
 $perms = array();
 $handle = opendir(MODS_DIR);
 if ($handle) {
     // Foreach modules
     while (false !== ($entry = readdir($handle))) {
         // Dump specific directories
         if ($entry != "." && $entry != "..") {
             $module = $entry;
             // Exceptions
             if ($module != 'login') {
                 // Get Module Pages
                 $pages = Core_Reflection::getModulePublicPages($module);
                 if (!empty($pages)) {
                     // Create Page Access Permission
Example #4
0
File: full.php Project: voxter/rbac
 /**
  * Adds a child to the beginning of a node's children
  *
  * @param Array $FieldValueArray key-paired field-values to insert
  * @param string $ConditionString of the parent node
  * @param string $Rest optional, rest of variables to fill in placeholders of condition string, one variable for each ? in condition
  * @return Integer ChildID
  */
 function insertChildData($FieldValueArray = array(), $ConditionString = null, $Rest = null)
 {
     $this->lock();
     //Find the Sibling
     $Arguments = func_get_args();
     array_shift($Arguments);
     //first argument, the array
     array_shift($Arguments);
     if ($ConditionString) {
         $ConditionString = "WHERE {$ConditionString}";
     }
     $Query = "SELECT {$this->right()} AS `Right`, {$this->left()} AS `Left`" . " FROM {$this->table()} {$ConditionString}";
     array_unshift($Arguments, $Query);
     $Parent = call_user_func_array("Jf::sql", $Arguments);
     $Parent = $Parent[0];
     if ($Parent == null) {
         $Parent["Left"] = $Parent["Right"] = 0;
     }
     Jf::sql("UPDATE {$this->table()} SET {$this->right()} = {$this->right()} + 2 WHERE {$this->right()} >= ?", $Parent["Right"]);
     Jf::sql("UPDATE {$this->table()} SET {$this->left()} = {$this->left()} + 2 WHERE {$this->left()} > ?", $Parent["Right"]);
     $FieldsString = $ValuesString = "";
     $Values = array();
     if ($FieldValueArray) {
         foreach ($FieldValueArray as $k => $v) {
             $FieldsString .= ",";
             $FieldsString .= "`" . $k . "`";
             $ValuesString .= ",?";
             $Values[] = $v;
         }
     }
     $Query = "INSERT INTO {$this->table()} ({$this->left()},{$this->right()} {$FieldsString}) " . "VALUES(?,? {$ValuesString})";
     array_unshift($Values, $Parent["Right"] + 1);
     array_unshift($Values, $Parent["Right"]);
     array_unshift($Values, $Query);
     $Res = call_user_func_array("Jf::sql", $Values);
     $this->unlock();
     return $Res;
 }
Example #5
0
 /**
  * Remove all role-user relations
  * mostly used for testing
  *
  * @param boolean $Ensure
  *            must set to true or throws an Exception
  * @return number of deleted relations
  */
 function resetAssignments($Ensure = false)
 {
     if ($Ensure !== true) {
         throw new \Exception("You must pass true to this function, otherwise it won't work.");
         return;
     }
     $res = Jf::sql("DELETE FROM {$this->tablePrefix()}userroles");
     $Adapter = get_class(Jf::$Db);
     if ($this->isMySql()) {
         Jf::sql("ALTER TABLE {$this->tablePrefix()}userroles AUTO_INCREMENT =1 ");
     } elseif ($this->isSQLite()) {
         Jf::sql("delete from sqlite_sequence where name=? ", $this->tablePrefix() . "_userroles");
     } else {
         throw new \Exception("Rbac can not reset table on this type of database: {$Adapter}");
     }
     $this->assign("root", 1);
     return $res;
 }
Example #6
0
 /**
  * Retrives the full tree including Depth field.
  *
  * @return 2DArray Rowset
  */
 function fullTree()
 {
     $Res = Jf::sql("SELECT node.*, (COUNT(parent.{$this->id()}) - 1) AS Depth\n            FROM {$this->table()} AS node,\n            {$this->table()} AS parent\n            WHERE node.{$this->left()} BETWEEN parent.{$this->left()} AND parent.{$this->right()}\n            GROUP BY node.{$this->id()}\n            ORDER BY node.{$this->left()}");
     return $Res;
 }
Example #7
0
<?php

require_once __DIR__ . '/core/Jf.php';
require_once __DIR__ . '/Rbac.php';
Jf::$Db = Core_DBH::getDBH();