$this->conf_type_load();
# Connect
- try {
- $this->conn = new PDO($this->pdo,$this->user,$this->password,$this->options);
- #if (isset($this->pdo_error)) $this->conn->setAttribute($this->pdo_error[0], $this->pdo_error[1]);
+ if ($fct = $this->conf_type('_connect')) {
+ $this->conn = $fct($this);
- } catch (PDOException $e) {
- $msg = 'Connection failed:';
+ } else {
- foreach(['name','host','file'] as $p) {
- if (!empty($this->$p)) $msg .= " $p=".$this->$p;
- }
+ try {
+ $this->conn = new PDO($this->pdo,$this->user,$this->password,$this->options);
+ #if (isset($this->pdo_error)) $this->conn->setAttribute($this->pdo_error[0], $this->pdo_error[1]);
- $msg .= "\n ".$e->getMessage();
- #throw new Exception($msg, (int)$e->getCode());
- self::bye($msg);
- }
+ } catch (PDOException $e) {
+ $msg = 'Connection failed:';
- if (empty($this->conn)) {
- $this->bye("Connection failed: ".$this->pdo_info());
- return false;
- }
+ foreach(['name','host','file'] as $p) {
+ if (!empty($this->$p)) $msg .= " $p=".$this->$p;
+ }
- # Create functions
- foreach ((array)$this->conf_type('sqliteCreateFunction') as $name => $fct) {
- if (is_array($fct)) {
- $this->conn->sqliteCreateFunction($name,$fct[0],$fct[1]);
- } else {
- $this->conn->sqliteCreateFunction($name,$fct);
+ $msg .= "\n ".$e->getMessage();
+ #throw new Exception($msg, (int)$e->getCode());
+ self::bye($msg);
+ }
+
+ if (empty($this->conn)) {
+ $this->bye("Connection failed: ".$this->pdo_info());
+ return false;
}
- }
+ # Create functions
+ foreach ((array)$this->conf_type('sqliteCreateFunction') as $name => $fct) {
+ if (is_array($fct)) {
+ $this->conn->sqliteCreateFunction($name,$fct[0],$fct[1]);
+ } else {
+ $this->conn->sqliteCreateFunction($name,$fct);
+ }
+ }
+
+ }
$this->method('connect');
return true;
// >> Define
define('TABLE_INDENT',NB_EOL ? "\t" : "");
-define('TABLE_CSV_SEP',Table::p('sep',"\t"));
+define('TABLE_CSV_SEP',Db::p('sep',"\t"));
if (!defined('TABLE_TEMPLATE')) define('TABLE_TEMPLATE',dirname(__FILE__).'/../../../share/templates');
}
public function rows(&$opt=[],$opt_by_val=null) {
+ if ($opt_by_val !== null) $opt = $opt_by_val;
+# NB 29.01.18 if ($fct = $this->db()->conf_type('_table_rows')) {
+# NB 29.01.18 return $fct($opt);
+# NB 29.01.18 }
#
# Db type change
#
#
$this->create_temporary();
- if ($opt_by_val !== null) $opt = $opt_by_val;
-
if (isset($opt['format']) and $opt['format']==='') {
$format = '';
} else {
public function rows_begin_xml() {
return ''
.'<?xml version="1.0" encoding="utf-8"?>'.NB_EOL #<?
- .'<rows name="'.$this->name.'" database="'.$this->db()->name.'" database-type="'.$this->db()->conf_type('type').'">'.NB_EOL
+ .'<rows name="'.$this->name.'" database="'.$this->db()->name.'" database-type="'.$this->db()->type.'">'.NB_EOL
;
}
--- /dev/null
+<?php
+if (!class_exists('Db')) {
+ echo "Hi there! I'm just a plugin, not much I can do when called directly.\n";
+ exit;
+}
+$DB_TYPES['ldap'] = [
+ 'quote_name' => '',
+ 'quote' => function($v) { return $v; },
+ '_connect' => function($db) {
+ require_once(NB_ROOT.'/lib/php/ldap.php');
+
+ $db->ldap = new Ldap([
+ 'host' => $this->host,
+ 'user' => $this->user,
+ 'password' => $this->password,
+ ]);
+
+ return $db->ldap->connect();
+ },
+];
+?>
return $new;
}
- public function conn($exit=true) {
+ public function connect($exit=true) {
if ($this->conn) return $this->conn;
if (!$this->conn = @ldap_connect($this->host)) return self::bye("Could not connect to LDAP server");
public function search($o=[]) {
- $conn = $this->conn();
+ $conn = $this->connect();
if (!isset($o['dn'])) $o['dn'] = true;
if (!isset($o['base'])) $o['base'] = null;
} # < ldap_search
public function add($dn,$data) {
- $conn = $this->conn();
+ $conn = $this->connect();
+ debug($dn);
return ldap_add($conn, $dn . ',' . $this->base, $data);
+# NB 29.01.18 return ldap_mod_add($conn, $dn . ',' . $this->base, $data);
}
public function update($dn,$data) {
-# NB 28.01.18 return ldap_mod_add($this->conn(), $dn . ',' . $this->base, $data);
- return ldap_mod_replace($this->conn(), $dn . ',' . $this->base, $data);
+# NB 28.01.18 return ldap_mod_add($this->connect(), $dn . ',' . $this->base, $data);
+ return ldap_mod_replace($this->connect(), $dn . ',' . $this->base, $data);
}
public function delete($dn) {
- return ldap_delete($this->conn(), $dn);
+ return ldap_delete($this->connect(), $dn);
/*
foreach ($ldap->search([
'base' => $this->user,
require_once(NB_ROOT.'/lib/php/ldap.php');
#debug($GLOBALS['DBQ_LDAP']);
+ $dn = join(',',$attrs);
$ldap = new Ldap($GLOBALS['DBQ_LDAP']);
if ($table == 'add') {
$this->deniedUnless($this->perm >= self::WRITE);
- $rows = (int)$ldap->add($attrs,$_POST);
+ $rows = (int)$ldap->add($dn,$_POST);
} elseif ($table == 'update') {
$this->deniedUnless($this->perm >= self::WRITE);
- $rows = (int)$ldap->update($attrs,$_POST);
+ $rows = (int)$ldap->update($dn,$_POST);
} elseif ($table == 'rm') {
$this->deniedUnless($this->perm >= self::DELETE);
- $rows = (int)$ldap->delete($attrs,$_POST);
+ $rows = (int)$ldap->delete($dn,$_POST);
} else { // ls
$this->deniedUnless($this->perm >= self::READ);