mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-08 06:51:58 +01:00
61 lines
1.8 KiB
PHP
61 lines
1.8 KiB
PHP
<?php
|
|
|
|
class ModelSaasLdap extends Model
|
|
{
|
|
|
|
public function get() {
|
|
|
|
$query = $this->db->query("SELECT id, description, ldap_host, ldap_base_dn, ldap_bind_dn FROM " . TABLE_LDAP . " ORDER BY description ASC");
|
|
|
|
if($query->num_rows > 0) { return $query->rows; }
|
|
|
|
return array();
|
|
}
|
|
|
|
|
|
public function delete($id = 0, $description = '') {
|
|
if($id == 0) { return 0; }
|
|
|
|
$query = $this->db->query("DELETE FROM " . TABLE_LDAP . " WHERE id=?", array($id));
|
|
|
|
$rc = $this->db->countAffected();
|
|
|
|
LOGGER("remove ldap entry: #$id, $description (rc=$rc)");
|
|
|
|
return $rc;
|
|
}
|
|
|
|
|
|
public function add($arr = array()) {
|
|
if(!isset($arr['description']) || !isset($arr['ldap_host'])) { return 0; }
|
|
|
|
$query = $this->db->query("INSERT INTO " . TABLE_LDAP . " (description, ldap_host, ldap_base_dn, ldap_bind_dn, ldap_bind_pw) VALUES (?,?,?,?,?)", array($arr['description'], $arr['ldap_host'], $arr['ldap_base_dn'], $arr['ldap_bind_dn'], $arr['ldap_bind_pw']));
|
|
|
|
$rc = $this->db->countAffected();
|
|
|
|
LOGGER("add ldap entry: " . $arr['description'] . " / " . $arr['ldap_host'] . " / " . $arr['ldap_base_dn'] . " (rc=$rc)");
|
|
|
|
if($rc == 1){ return 1; }
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
public function get_ldap_params_by_email($email = '') {
|
|
$domain = '';
|
|
|
|
if($email == '') { return array(); }
|
|
|
|
list($l,$d) = explode("@", $email);
|
|
|
|
$query = $this->db->query("SELECT ldap_host, ldap_base_dn, ldap_bind_dn, ldap_bind_pw from " . TABLE_DOMAIN . " as d, " . TABLE_LDAP . " as l where d.ldap_id=l.id and d.domain=?", array($d));
|
|
|
|
if($query->num_rows > 0) { return array($query->row['ldap_host'], $query->row['ldap_base_dn'], $query->row['ldap_bind_dn'], $query->row['ldap_bind_pw']); }
|
|
|
|
return array();
|
|
}
|
|
|
|
}
|
|
|
|
?>
|