2013-07-08 11:31:17 +02:00
< ? php
class ModelSaasLdap extends Model
{
public function get () {
2013-07-12 11:14:09 +02:00
$query = $this -> db -> query ( " SELECT id, description, ldap_type, ldap_host, ldap_base_dn, ldap_bind_dn FROM " . TABLE_LDAP . " ORDER BY description ASC " );
2013-07-08 11:31:17 +02:00
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 ; }
2013-07-12 11:14:09 +02:00
$query = $this -> db -> query ( " INSERT INTO " . TABLE_LDAP . " (description, ldap_host, ldap_base_dn, ldap_bind_dn, ldap_bind_pw, ldap_type) VALUES (?,?,?,?,?,?) " , array ( $arr [ 'description' ], $arr [ 'ldap_host' ], $arr [ 'ldap_base_dn' ], $arr [ 'ldap_bind_dn' ], $arr [ 'ldap_bind_pw' ], $arr [ 'ldap_type' ]));
2013-07-08 11:31:17 +02:00
$rc = $this -> db -> countAffected ();
2013-07-12 11:14:09 +02:00
LOGGER ( " add ldap entry: " . $arr [ 'description' ] . " / " . $arr [ 'ldap_type' ] . " / " . $arr [ 'ldap_host' ] . " / " . $arr [ 'ldap_base_dn' ] . " (rc= $rc ) " );
2013-07-08 11:31:17 +02:00
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 );
2013-07-12 11:14:09 +02:00
$query = $this -> db -> query ( " SELECT ldap_type, 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 ));
2013-07-08 11:31:17 +02:00
2013-07-12 11:14:09 +02:00
if ( $query -> num_rows > 0 ) { return array ( $query -> row [ 'ldap_type' ], $query -> row [ 'ldap_host' ], $query -> row [ 'ldap_base_dn' ], $query -> row [ 'ldap_bind_dn' ], $query -> row [ 'ldap_bind_pw' ]); }
2013-07-08 11:31:17 +02:00
return array ();
}
}
?>