Permalink
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
timerec3public/ldap.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
101 lines (85 sloc)
3.5 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Suche nach Mitarbeiter</title> | |
<meta charset="utf-8"> | |
<link rel="stylesheet" type="text/css" href="style.css"> | |
<link rel="shortcut icon" href="favicon.ico"> | |
</head> | |
<body> | |
<?php | |
//sucht mitarbeiter aus LDAP, und gibt name und email an timerec zurück. mit auswahlfeld bei ungenauer suche | |
session_start(); | |
if(!$_SESSION['userid']){ | |
session_destroy(); | |
include('login.php'); | |
exit; | |
} | |
//var_dump($_POST); | |
if(isset($_POST['search']) && ($_SESSION['userarray']['admin'])){ | |
$term = $_POST['search']; | |
if($term == '' || $term == ' '){ | |
echo "<h3>kein Suchwort angegeben</h3> | |
<button onclick='history.go(-1)'>zurück</button>"; | |
exit; | |
} | |
/* set_time_limit(30); | |
error_reporting(E_ALL); | |
ini_set('error_reporting', E_ALL); | |
ini_set('display_errors',1); */ | |
// config | |
$script = 'search'; | |
include('ldapconnect.php'); | |
$filter = array("uid", "cn", "mail", "sn"); //sn für sortierung mit holen | |
// connect | |
$ldapconn = ldap_connect($ldapserver) or die("Could not connect to LDAP server."); | |
//ohne gehts nicht | |
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3); | |
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0); | |
if($ldapconn) { | |
// binding to ldap server | |
$ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass) or die ("Error trying to bind: ".ldap_error($ldapconn)); | |
// verify binding | |
if ($ldapbind) { | |
$result = ldap_search($ldapconn,$ldaptree, "(cn=*$term*)", $filter) or die ("Error in search query: ".ldap_error($ldapconn)); | |
$data = ldap_get_entries($ldapconn, $result); | |
echo "<div id='content'> | |
<button form='centered_form' type='submit' name='abort' value='1'><< abbrechen</button> | |
<form id='centered_form' action='ma-data-editor.php' method='post'> | |
<h3>Ergebnis</h3> | |
<div>Sortiert nach Nachname</div> | |
<select name='ldapresult' class='searchresult select' size=24 onclick='this.form.submit()'>"; | |
foreach($data as $index=>$object){ //ldap ergebnis auswerten | |
if(gettype($index) == "integer"){ //count feld überspringen | |
$namesplit = array_reverse(explode(" ", $object['cn'][0])); //nachname, 2. vorname, 1. vorname | |
$splitted_name = $namesplit[0].";".$namesplit[count($namesplit)-1]; | |
$value = $splitted_name.";".$object['uid'][0].";".$object['mail'][0]; //nachname, vorname, uid, email | |
$extracted_data[$splitted_name] = $value; | |
} | |
} | |
ksort($extracted_data); //array nach key (also sn -> nachname) sortieren | |
foreach($extracted_data as $value){ | |
$name = explode(';', $value); | |
echo "<option value='$value'>$name[0], $name[1]</option>"; | |
} | |
echo "</select> | |
</form>"; | |
// print number of entries found | |
//echo "Term: $term<br>"; | |
//echo "Number of entries found: " . ldap_count_entries($ldapconn, $result); | |
} else { | |
echo "LDAP bind failed..."; | |
} | |
} | |
echo "</div>"; | |
// all done? clean up | |
ldap_close($ldapconn); | |
}else{ | |
echo "<h3>keine Adminrechte oder keine Suchparameter angegeben!</h3> | |
<button onclick='history.go(-1)'>zurück</button>"; | |
echo "</div>"; | |
exit; | |
} | |
?> | |
</body> | |
</html> |