2013-07-08 11:31:17 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
class ControllerLdapList extends Controller {
|
|
|
|
private $error = array();
|
|
|
|
|
|
|
|
public function index(){
|
|
|
|
|
|
|
|
$this->id = "content";
|
|
|
|
$this->template = "ldap/list.tpl";
|
|
|
|
$this->layout = "common/layout";
|
|
|
|
|
|
|
|
|
|
|
|
$request = Registry::get('request');
|
|
|
|
$db = Registry::get('db');
|
|
|
|
|
|
|
|
$this->load->model('saas/ldap');
|
|
|
|
|
|
|
|
$this->document->title = $this->data['text_ldap'];
|
|
|
|
|
|
|
|
|
|
|
|
$this->data['username'] = Registry::get('username');
|
|
|
|
|
|
|
|
|
|
|
|
$this->data['page'] = 0;
|
|
|
|
$this->data['page_len'] = get_page_length();
|
|
|
|
|
|
|
|
$this->data['total'] = 0;
|
|
|
|
|
|
|
|
$this->data['entries'] = array();
|
|
|
|
|
2013-07-23 22:44:34 +02:00
|
|
|
$this->data['id'] = -1;
|
|
|
|
|
|
|
|
$this->data['ldap_types'] = Registry::get('ldap_types');
|
|
|
|
|
|
|
|
if(isset($this->request->get['id'])) { $this->data['id'] = $this->request->get['id']; }
|
2013-07-08 11:31:17 +02:00
|
|
|
|
2013-08-24 13:53:14 +02:00
|
|
|
$this->data['search'] = '';
|
|
|
|
|
|
|
|
if(isset($this->request->post['search'])) { $this->data['search'] = $this->request->post['search']; }
|
|
|
|
else if(isset($this->request->get['search'])) { $this->data['search'] = $this->request->get['search']; }
|
|
|
|
|
|
|
|
|
2013-07-08 11:31:17 +02:00
|
|
|
/* check if we are admin */
|
|
|
|
|
|
|
|
if(Registry::get('admin_user') == 1) {
|
|
|
|
|
|
|
|
if($this->request->server['REQUEST_METHOD'] == 'POST') {
|
2013-08-14 23:40:52 +02:00
|
|
|
|
2013-07-08 11:31:17 +02:00
|
|
|
if($this->validate() == true) {
|
|
|
|
|
2013-07-23 22:44:34 +02:00
|
|
|
if(isset($this->request->post['id'])) {
|
|
|
|
if($this->model_saas_ldap->update($this->request->post) == 1) {
|
|
|
|
$this->data['x'] = $this->data['text_successfully_modified'];
|
|
|
|
} else {
|
|
|
|
$this->data['errorstring'] = $this->data['text_failed_to_modify'];
|
2013-08-14 23:40:52 +02:00
|
|
|
// set ldap ID to be the submitted id
|
|
|
|
if (isset($this->request->post['id'])) { $this->data['id'] = $this->request->post['id']; }
|
2013-07-23 22:44:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if($this->model_saas_ldap->add($this->request->post) == 1) {
|
|
|
|
$this->data['x'] = $this->data['text_successfully_added'];
|
|
|
|
} else {
|
|
|
|
$this->data['errorstring'] = $this->data['text_failed_to_add'];
|
|
|
|
}
|
2013-07-08 11:31:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-08-14 23:40:52 +02:00
|
|
|
$this->data['errorstring'] = $this->data['text_error_message'];
|
|
|
|
$this->data['errors'] = $this->error;
|
|
|
|
// set ldap ID to be the submitted id
|
|
|
|
if (isset($this->request->post['id'])) { $this->data['id'] = $this->request->post['id']; }
|
2013-07-08 11:31:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-24 13:53:14 +02:00
|
|
|
if($this->data['id'] != -1) {
|
2013-08-14 23:40:52 +02:00
|
|
|
$this->data['a'] = $this->model_saas_ldap->get($this->data['id']);
|
2013-08-24 13:53:14 +02:00
|
|
|
} else {
|
|
|
|
$this->data['entries'] = $this->model_saas_ldap->search($this->data['search']);
|
2013-07-23 22:44:34 +02:00
|
|
|
}
|
2013-08-14 23:40:52 +02:00
|
|
|
|
|
|
|
if ( isset($this->data['errorstring']) ) {
|
|
|
|
// use posted values if they differ from database values (ie - form was submitted but failed validation)
|
|
|
|
if (isset($this->request->post['ldap_type'])) { $this->data['a']['ldap_type'] = $this->request->post['ldap_type'];}
|
|
|
|
if (isset($this->request->post['description'])) { $this->data['a']['description'] = $this->request->post['description'];}
|
|
|
|
}
|
|
|
|
|
2013-07-08 11:31:17 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->template = "common/error.tpl";
|
|
|
|
$this->data['errorstring'] = $this->data['text_you_are_not_admin'];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->render();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function validate() {
|
2013-08-14 23:40:52 +02:00
|
|
|
// description is required and must be 1 or more characters in length to meet this
|
2013-07-08 11:31:17 +02:00
|
|
|
if(!isset($this->request->post['description']) || strlen($this->request->post['description']) < 1) {
|
2013-08-14 23:40:52 +02:00
|
|
|
$this->error['description'] = $this->data['text_field_required'];
|
2013-07-08 11:31:17 +02:00
|
|
|
}
|
2013-08-14 23:40:52 +02:00
|
|
|
// ldap_host is required and must be 1 or more characters in length to meet this
|
2013-07-08 11:31:17 +02:00
|
|
|
if(!isset($this->request->post['ldap_host']) || strlen($this->request->post['ldap_host']) < 1) {
|
2013-08-14 23:40:52 +02:00
|
|
|
$this->error['ldap_host'] = $this->data['text_field_required'];
|
2013-07-08 11:31:17 +02:00
|
|
|
}
|
2013-08-14 23:40:52 +02:00
|
|
|
// ldap_base_dn is required and must be 1 or more characters in length to meet this
|
2013-07-08 11:31:17 +02:00
|
|
|
if(!isset($this->request->post['ldap_base_dn']) || strlen($this->request->post['ldap_base_dn']) < 1) {
|
2013-08-14 23:40:52 +02:00
|
|
|
$this->error['ldap_base_dn'] = $this->data['text_field_required'];
|
2013-07-08 11:31:17 +02:00
|
|
|
}
|
2013-08-14 23:40:52 +02:00
|
|
|
// ldap_bind_dn is required and must be 1 or more characters in length to meet this
|
2013-07-08 11:31:17 +02:00
|
|
|
if(!isset($this->request->post['ldap_bind_dn']) || strlen($this->request->post['ldap_bind_dn']) < 1) {
|
2013-08-14 23:40:52 +02:00
|
|
|
$this->error['ldap_bind_dn'] = $this->data['text_field_required'];
|
2013-07-08 11:31:17 +02:00
|
|
|
}
|
2013-08-14 23:40:52 +02:00
|
|
|
// ldap_bind_pw is required and must be 1 or more characters in length to meet this
|
2013-07-08 11:31:17 +02:00
|
|
|
if(!isset($this->request->post['ldap_bind_pw']) || strlen($this->request->post['ldap_bind_pw']) < 1) {
|
2013-08-14 23:40:52 +02:00
|
|
|
$this->error['ldap_bind_pw'] = $this->data['text_field_required'];
|
2013-07-08 11:31:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->error) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|