Location: PHPKode > projects > Opensheet > opensheet/users_ldap_add.php
<?php
ini_set('display_errors','1');
error_reporting(E_ALL);
session_start();



include ('start.php');
require ('functions/base.functions.php');
include ('classes/global.class.php');


		set_lang($_SESSION['lang']);
			$login_type = new users();
		if ($_SESSION['permissions']['admin'] !== "1"){
		Header("Location: timesheet.php");
					exit();

		}
if(isset($_POST['add_users']) && isset($_POST['start'])){
	$query = new Users;
	foreach ($_POST['ad_user'] as $login=>$value){
		foreach($value as $name=>$email){
			$query->addUser($login,$name,'0','Y',$email,'Y','',$_POST['start']);
		}
	}
	Header("Location: users_ldap_add.php");
					exit();
}
		
		
		
		?><!-- Headers -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/jqueryslidemenu.css" />
<link rel="stylesheet" href="js/addons/pager/jquery.tablesorter.pager.css" type="text/css" media="print, projection, screen" />
<link rel="stylesheet" href="css/themes/blue/style.css" type="text/css" media="print, projection, screen" />

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
<script type="text/javascript" src="js/jqueryslidemenu.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.pager.js"></script>

<!--[if lte IE 7]>
<style type="text/css">
html .jqueryslidemenu{height: 1%;} /*Holly Hack for IE7 and below*/
</style>
<![endif]-->
<script type="text/javascript">
$(document).ready(function() { 
	    $(".tablesorter") 
	    .tablesorter({widthFixed: true, widgets: ['zebra']}) 
	    .tablesorterPager({container: $(".pager")}); 
	}); 

</script>


<title>Add Users from AD</title>


</head>
<body>
<?php 		
include ('include/menu.settings.inc.html');
		
		$settings = new getSetting();
		
		$ldaphost = $settings->getValue('ldap_host');
	 	$ldapuser = $settings->getValue('ldap_user');
		$ldappassword = $settings->getValue('ldap_passwd');
		$ldapconn = ldap_connect($ldaphost);  ## resource $link_identifier
		$ldapbind = ldap_bind($ldapconn,$ldapuser,$ldappassword); 
		$dc=$settings->getValue('ldap_dc'); #resource $result_identifier
		$justthese = array('samaccountname','objectclass'); # we ll get from ad only this
		$filter="(CN=*)";
		$search=ldap_search($ldapconn, $dc,$filter,$justthese);
		$info = ldap_get_entries($ldapconn, $search);


		$logins = array();
		foreach(rCountRemover($info) as $key=>$value)
	{   
		if ( $value['objectclass']['1'] == 'person') {
			$logins[] = $value['samaccountname']['0'];
		}
	}

		# we need array only with users who not in a base
	$user = new Users;
	foreach($logins as $key=>$value){
	$uid = $user->loginToUid($value);
		if(!isset($uid)){
			$new_logins[] = $value;
		}
		
	}


		$justthese = array('displayname','mail','useraccountcontrol');
		foreach($new_logins as $key=>$value){
			$filter = "(CN=$value)";
			$search=ldap_search($ldapconn, $dc,$filter,$justthese);
			$info = ldap_get_entries($ldapconn, $search);
			$array_ad_users[$value]['email'] = $info['0']['mail']['0'];
			$array_ad_users[$value]['login'] = $value;
			$array_ad_users[$value]['real_name'] = $info['0']['displayname']['0'];
			
				}
		ldap_unbind($ldapconn);
		
		?>
<div>
<form method='POST' action=''>
<table class="tablesorter" cellspacing="1" style="width:80%;">
<thead>
<tr>
<th style="width:55%;"><?php echo gettext('User name');?></th>
<th style="width:15%;"><?php echo gettext('login');?></th>
<th style="width:15%;"><?php echo gettext('email');?></th>
<th style="width:15%;"><?php echo gettext('action');?></th>
</tr>
</thead>
<tbody>

<?php 

foreach($array_ad_users as $login=>$value){
?>


<tr>
<td><?php echo $value['real_name'];?></td>
<td><?php echo $value['login'];?></td>
<td><?php echo $value['email'];?></td>
<td><input type='checkbox' value='<?php echo $value['email'];?>' name='ad_user[<?php echo $value['login'];?>][<?php echo $value['real_name'];?>]'></input></td>
</tr>	
	
	
<?php 	
}
?></tbody></table>
</div>
<div id="pager" class="pager">
	
		<img src="js/addons/pager/icons/first.png" class="first"/>
		<img src="js/addons/pager/icons/prev.png" class="prev"/>
		<input type="text" class="pagedisplay"/>
		<img src="js/addons/pager/icons/next.png" class="next"/>
		<img src="js/addons/pager/icons/last.png" class="last"/>
		<select class="pagesize">
			<option selected="selected"  value="20">20</option>
			<option  value="40">40</option>
			<option  value="60">60</option>
		</select>
	
</div>


 <input type="hidden" name='start' value="<?php echo date('Y-m-j');	?>">
 <center><input type="submit" name='add_users' value="<?php echo gettext('GO');?>" ></input></center>
		
		
		<?php 
include ('end.php');


?>
Return current item: Opensheet