piler/webui/model/domain/domain.php

124 lines
3.3 KiB
PHP
Raw Normal View History

2012-02-08 23:14:28 +01:00
<?php
class ModelDomainDomain extends Model {
2013-09-18 22:59:51 +02:00
public function count_mydomains() {
$query = $this->db->query("SELECT count(*) AS num FROM " . TABLE_DOMAIN);
return $query->row['num'];
}
public function getDomains($s = '') {
2013-07-08 11:31:17 +02:00
$data = array();
2013-02-11 20:24:19 +01:00
if($s) {
$query = $this->db->query("SELECT domain, mapped, ldap_id FROM " . TABLE_DOMAIN . " WHERE domain LIKE ? ORDER BY domain ASC", array('%' . $s . '%'));
} else {
$query = $this->db->query("SELECT domain, mapped, ldap_id FROM " . TABLE_DOMAIN . " ORDER BY domain ASC");
}
2012-02-08 23:14:28 +01:00
2013-07-08 11:31:17 +02:00
if(isset($query->rows)) {
foreach($query->rows as $q) {
2013-02-11 20:24:19 +01:00
2013-07-08 11:31:17 +02:00
$ldap = '';
if($q['ldap_id'] > 0) {
$query2 = $this->db->query("SELECT description FROM " . TABLE_LDAP . " WHERE id=?", array($q['ldap_id']));
if(isset($query2->row)) { $ldap = $query2->row['description']; }
}
$data[] = array('domain' => $q['domain'], 'mapped' => $q['mapped'], 'ldap' => $ldap);
}
}
return $data;
2012-02-08 23:14:28 +01:00
}
2013-07-23 22:44:34 +02:00
public function get_mapped_domains() {
$data = array();
$query = $this->db->query("SELECT DISTINCT mapped FROM " . TABLE_DOMAIN . " ORDER BY mapped ASC");
if(isset($query->rows)) {
foreach($query->rows as $q) {
array_push($data, $q['mapped']);
}
}
return $data;
}
2013-01-05 16:42:36 +01:00
public function get_domains_by_string($s = '', $page = 0, $page_len = PAGE_LEN) {
$from = (int)$page * (int)$page_len;
if(strlen($s) < 1) { return array(); }
$query = $this->db->query("SELECT domain FROM `" . TABLE_DOMAIN . "` WHERE domain LIKE ? ORDER BY domain ASC LIMIT " . (int)$from . ", " . (int)$page_len, array($s . "%") );
if(isset($query->rows)) { return $query->rows; }
return array();
}
2013-07-12 15:02:50 +02:00
public function get_your_all_domains_by_email($email = '') {
$data = array();
if($email == '') { return $data; }
$a = explode("@", $email);
$query = $this->db->query("SELECT domain FROM " . TABLE_DOMAIN . " WHERE mapped IN (SELECT mapped FROM " . TABLE_DOMAIN . " WHERE domain=?)", array($a[1]));
if(isset($query->rows)) {
foreach ($query->rows as $q) {
array_push($data, $q['domain']);
}
}
return $data;
}
2012-02-08 23:14:28 +01:00
public function deleteDomain($domain = '') {
if($domain == "") { return 0; }
$query = $this->db->query("DELETE FROM " . TABLE_DOMAIN . " WHERE domain=?", array($domain));
$rc = $this->db->countAffected();
LOGGER("remove domain: $domain (rc=$rc)");
return $rc;
}
2013-07-08 11:31:17 +02:00
public function addDomain($domain = '', $mapped = '', $ldap_id = 0) {
2012-02-08 23:14:28 +01:00
if($domain == "" || $mapped == "") { return 0; }
2013-10-16 15:26:16 +02:00
$query = $this->db->query("INSERT INTO " . TABLE_DOMAIN . " (domain, mapped, ldap_id) VALUES (?,?,?)", array($mapped, $mapped, $ldap_id));
2012-02-08 23:14:28 +01:00
$domains = explode("\n", $domain);
foreach ($domains as $domain) {
$domain = rtrim($domain);
2013-07-08 11:31:17 +02:00
$query = $this->db->query("INSERT INTO " . TABLE_DOMAIN . " (domain, mapped, ldap_id) VALUES (?,?,?)", array($domain, $mapped, $ldap_id));
2012-02-08 23:14:28 +01:00
$rc = $this->db->countAffected();
LOGGER("add domain: $domain (rc=$rc)");
if($rc != 1){ return 0; }
}
return 1;
}
}
?>