<?
include ("include_config.inc");
include ("include_profile_name.inc");
include ("include_project_name.inc");
include ("include_log_file.inc");
include ("include_delete_task.inc");
include ("include_delete_project.inc");
include ("include_delete_profile.inc");
include ("include_update_user.inc");
include ("include_delete_user.inc");
include ("include_list_user.inc");
include ("include_state_name.inc");
include ("include_user_name.inc");
include ("include_workload_project.inc");
include ("include_dates_project.inc");
include ("include_display_comment.inc");
include ("include_button.inc");
if ( isset( $HTTP_COOKIE_VARS[$g_string_cookie] ) ) {
$g_string_cookie_val = $HTTP_COOKIE_VARS[$g_string_cookie];
write_log_user ($filename_log, "Cookie created 1.1: ".$g_string_cookie." -- ".$g_string_cookie_val);
}
if ( isset( $HTTP_COOKIE_VARS[$g_project_cookie] ) ) {
$g_project_cookie_val = $HTTP_COOKIE_VARS[$g_project_cookie];
write_log_user ($filename_log, "Cookie created 2.1: ".$g_project_cookie." -- ".$g_project_cookie_val);
}
/* check the login for user */
login_cookie_check();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Your tasks - Update from LDAP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<? include ("include_css.inc"); ?>
<script src="main.js" type="text/javascript"></script>
<script src="tasks.js" type="text/javascript"></script>
<script src="nav.js" type="text/javascript"></script>
</head>
<BODY onload="init()">
<table align="center">
<tr><td>
<?
include ("include_main.inc");
?>
<?php
write_log_user ($filename_log, "Beginning of update from LDAP.");
#set_time_limit(300);
/* database connection */
$link= mysql_connect($g_hostname, $g_db_username, $g_db_password) or die("could not connect");
$result_link = mysql_select_db($g_database_name);
/* read of the user connected */
$connected_user = user_connected();
$profile_connected_user = user_profile($connected_user);
$name_connected_user = user_name($connected_user,$g_database_name);
$name_profile_connected_user = profile_name($profile_connected_user);
display_connected_user($name_connected_user,$name_profile_connected_user);
write_log_user ($filename_log, "Update from LDAP.");
global $g_ldap_server, $g_ldap_root_dn, $g_ldap_search;
if( $ldap == 1 ) {
#update of data
$is_comment = "Number of users updated: ".$data;
$tab = explode( ":", $data_alias);
$tab1 = explode( ":", $data_mail);
$tab2 = explode( ":", $data_name);
$tab3 = explode( ":", $data_firstname);
$tab4 = explode( ":", $data_phone);
$tab5 = explode( ":", $data_mobile);
$tab6 = explode( ":", $data_address);
$tab7 = explode( ":", $data_city);
$tab8 = explode( ":", $data_country);
for ($k=0; $k<$data; $k++) {
$query_select = "SELECT NAME from USER where NAME='$tab[$k]'";
$result_select = mysql($g_database_name,$query_select) or $error_select = mysql_error();
if (!$error_select) {
$total_rows = mysql_numrows($result_select);
if ( $total_rows == 0 ) {
#creation of the user
if ($profil_code == "") $profil_code = 3; #user stand by
if ($project_code == "") $project_code = 'NULL';
if ($mobility == "") $mobility = 'NULL';
$result = mysql("$g_database_name","SELECT USERID FROM USER order by USERID ASC");
$total_rows = mysql_numrows($result);
$userid = mysql_result($result,$total_rows-1,USERID);
$userid = $userid + 1;
$password= MD5($password_null);
$query_add= "INSERT INTO USER (USERID,NAME,PASSWORD,COOKIE_STRING,SURNAME,EMAIL,PHONE,ADDRESS,TOWN,COUNTRY,PROJECT_CODE,PROFIL_CODE,CREATION_USER_DATE,MATRICULE,USERNAME,MOBILITY_CODE)
VALUES ($userid,'$tab[$k]','$password','$userid','$tab3[$k]','$tab1[$k]','$tab4[$k]','$tab6[$k]','$tab7[$k]','$tab8[$k]',$project_code,$profil_code,NOW(),'NULL','$tab2[$k]',$mobility)" ;
mysql_query($query_add) or $mysql_eval_error_add = mysql_error();
if ($mysql_eval_error_add) {
$is_comment = $is_comment."<br> Error insert for user: ".$tab[$k];
}
} else {
#update of the user
if ( $tab[$k] == "") continue;
if ( $tab1[$k] == "") $tab1[$k] = 'NULL';
if ( $tab2[$k] == "") $tab2[$k] = 'NULL';
if ( $tab3[$k] == "") $tab3[$k] = 'NULL';
if ( $tab4[$k] == "") $tab4[$k] = $tab5[$k];
if ( $tab4[$k] == "") $tab4[$k] = 'NULL';
if ( $tab6[$k] == "") $tab6[$k] = 'NULL';
if ( $tab7[$k] == "") $tab7[$k] = 'NULL';
if ( $tab8[$k] == "") $tab8[$k] = 'NULL';
$query_update = "UPDATE USER SET
EMAIL='$tab1[$k]',
USERNAME ='$tab2[$k]',
SURNAME = '$tab3[$k]',
PHONE = '$tab4[$k]',
ADDRESS = '$tab6[$k]',
TOWN = '$tab7[$k]',
COUNTRY = '$tab8[$k]'
where NAME='$tab[$k]'";
$result = mysql($g_database_name,$query_update) or $error_update = mysql_error();
if ($error_update) {
$is_comment = $is_comment."<br> Error update for user: ".$tab[$k];
}
}
} else {
$is_comment = $is_comment."<br> Error select for user: ".$tab[$k];
}
}
mysql_query("COMMIT");
write_log_user ($filename_log, "LDAP : ".$is_comment);
display_comment( $is_comment);
$ldap = 0;
}
if ( $g_use_ldap == "OFF" ) {
write_log_user ($filename_log, "LDAP : connection not allowed.");
$is_comment = "<br>LDAP : connection not allowed.";
display_comment( $is_comment);
} else {
if ( $global_search == "" ) {
$filter0 = $g_ldap_search;
} else {
$filter0 = $global_search;
}
if ( $search == 1) {
$ds = ldap_connect( $g_ldap_server );
$is_comment = "LDAP connect result is ".$ds."";
write_log_user ($filename_log, "LDAP : ".$is_comment);
if ($ds) {
$r=ldap_bind($ds); // this is an "anonymous" bind, typically
// read-only access
write_log_user ($filename_log, "LDAP : Bind result is ".$r."");
// Search surname entry
$justthese = array( "cn", "sn", "alias", "mail", "mobile", "phone", "street", "c", "l");
$filter="(&($filter0)(|(sn=$person*)(alias=$person*)(cn=$person*)))";
$sr=ldap_search($ds, $g_ldap_root_dn, $filter, $justthese);
write_log_user ($filename_log, "LDAP : Search result is ".$sr."");
write_log_user ($filename_log, "LDAP : Number of entires returned is ".ldap_count_entries($ds,$sr)."");
$info = ldap_get_entries($ds, $sr);
$counter = $info["count"];
write_log_user ($filename_log, "LDAP : Data for ". $counter." items returned:");
#$entry = ldap_first_entry($ds, $sr);
#$attrs = ldap_get_attributes($ds, $sr);
#$counter = $attrs["count"];
write_log_user ($filename_log, "LDAP : ".$counter ." attributes held for this entry.");
} else {
write_log_user ($filename_log, "LDAP : Unable to connect to LDAP server.");
$is_comment = "<br>Unable to connect to LDAP server.";
display_comment( $is_comment);
$search = 0;
}
}
}
?>
<form method="post" name="list_ldap">
<input type="hidden" name="ldap" value="1">
<input type="hidden" name="search">
<table align="center" cellpadding="0" cellspacing="0">
<TR>
<TD class="title">Users retrieved from LDAP</TD>
<td> </td>
<? echo $corner_left; ?>
<TD class="title2"></TD>
<? echo $corner_right; ?>
<td> </td>
<? echo $corner_left; ?>
<TD class="title2">Nb users :</TD>
<? echo $corner_right; ?>
<td> </td>
<? echo $corner_left; ?>
<TD class="title2"><? echo $info["count"]; ?></TD>
<? echo $corner_right; ?>
<td> </td>
<?
/* management of the display list */
if ($start == "") $start =0;
if ($start + $g_display_limit > $info["count"] OR $start < $info["count"] ) {
$previous=$start - $g_display_limit;
if ($previous >= 0) {
?>
<td class="next-previous">
<?
$update_from_ldap_path = $g_path."update_from_ldap.php?search=1&start=".$previous."&person=".$person."&global_search=".$global_search;
$view_gif = $g_icon_path."previous.gif";
echo "<a href='$update_from_ldap_path'><img src='$view_gif' border='0'></a>";
?>
</td>
<td> </td>
<? }
}
if ($start - $g_display_limit < $info["count"] ) {
$next=$start + $g_display_limit;
if ($next < $info["count"] ) {
?>
<td class="next-previous">
<?
$update_from_ldap_path = $g_path."update_from_ldap.php?search=1&start=".$next."&person=".$person."&global_search=".$global_search;
$view_gif = $g_icon_path."next.gif";
echo "<a href='$update_from_ldap_path'><img src='$view_gif' border='0'></a>";
?>
</td>
<? }
}
?>
</TR>
</table>
<br>
<?
echo "<table class='around' border=1 align='center' cellspacing='2' cellpadding='2'>";
echo "<tr><td class='title' colspan='9'>Update from LDAP</td></tr>";
echo "<tr>";
echo "<td class='input' colspan='3'>Name, Commun name, Alias filter</td><td colspan='2'><input type='text' name='person' value=".$person."></input>";
echo "</td>";
echo "<td class='input'>Global filtere</td>";
echo "<td><input type='text' name='global_search' value=".$filter0."></input>";
echo "</td>";
echo "<td>";
button("Search","Search with filter","list_ldap_search();");
echo "</td>";
echo "</tr>";
if ( $search == 1) {
echo "<br>";
echo "<tr>";
echo "<td class='list'>Alias</td><td class='list'>Surname</td><td class='list'>Firstname</td>";
echo "<td class='list'>Email</td><td class='list'>Phone</td><td class='list'>Mobile phone</td>";
echo "<td class='list'>Address</td><td class='list'>City</td><td class='list'>Country</td>";
echo "</tr>";
#display the results
$count=0;
$i =0 + $start;
$data_mail = "";
$data_alias = "";
$data_name = "";
$data_country = "";
$data_address = "";
$data=0;
while ( $i < $info["count"] ){
$data = $data +1;
$alias = "";
$sn= "";
$cn= "";
$mail= "";
$phone= "";
$mobile= "";
$street= "";
$city= "";
$country= "";
$counter_pair = $counter_pair +1;
$pair_counter = $counter_pair/2;
if ( is_int($pair_counter) ) {
$class_pair = "class='input'";
} else {
$class_pair = "";
}
echo "<tr>";
$val = $info[$i][$j]; ;
write_log_user ($filename_log, "LDAP 1: ". $val." is: ". $info[$i][$val] ."");
$var = $info[$i][$val];
$sn = $info[$i]["sn"][0];
if ( $data == 0 ) {
$data_name = $sn;
} else {
$data_name = $sn.":".$data_name;
}
$cn_a = $info[$i]["cn"][0];
$test1 = explode( " ", $cn_a);
$cn = $test1[0];
if ( $data == 0 ) {
$data_firstname = $cn;
} else {
$data_firstname = $cn.":".$data_firstname;
}
$mail = $info[$i]["mail"][0];
if ( $data == 0 ) {
$data_mail = $mail;
} else {
$data_mail = $mail.":".$data_mail;
}
$phone = $info[$i]["phone"][0];
if ( $data == 0 ) {
$data_phone = $phone;
} else {
$data_phone= $phone.":".$data_phone;
}
$street = $info[$i]["street"][0];
if ( $data == 0 ) {
$data_address= $street;
} else {
$data_address= $street.":".$data_address;
}
$alias = $info[$i]["alias"][0];
if ( $data == 0 ) {
$data_alias= $alias;
} else {
$data_alias= $alias.":".$data_alias;
}
$mobile = $info[$i]["mobile"][0];
if ( $data == 0 ) {
$data_mobile= $mobile;
} else {
$data_mobile= $mobile.":".$data_mobile;
}
$country = $info[$i]["c"][0];
if ( $data == 0 ) {
$data_country= $country;
} else {
$data_country= $country.":".$data_country;
}
$city = $info[$i]["l"][0];
if ( $data == 0 ) {
$data_city = $city;
} else {
$data_city = $city.":".$data_city ;
}
echo "<td $class_pair>".$alias."</td>";
echo "<td $class_pair>".$sn."</td>";
echo "<td $class_pair>".$cn."</td>";
echo "<td $class_pair>".$mail."</td>";
echo "<td $class_pair>".$phone."</td>";
echo "<td $class_pair>".$mobile."</td>";
echo "<td $class_pair>".$street."</td>";
echo "<td $class_pair>".$city."</td>";
echo "<td $class_pair>".$country."</td>";
echo "</tr>";
$count = $count + 1;
$i = $i + 1;
if ($count > $g_display_limit -1 ) $i = $info["count"] +1; /* in order to exit */
}
}
echo "</table>";
if ( $search == 1 ) {
write_log_user ($filename_log, "LDAP : Closing connection");
ldap_close($ds);
#set_time_limit(0);
}
?>
</td>
</tr>
</table>
<br>
<table align="center">
<tr>
<? if ( $profile_connected_user == 1) {
echo "<td>";
$path_update = $g_path."update_from_ldap.php?ldap=1&start=".$start."&data=".$data."&data_mail=".$data_mail."&data_alias=".$data_alias."&data_name=".$data_name."&data_firstname=".$data_firstname."&data_phone=".$data_phone."&data_mobile=".$data_mobile."&data_address=".$data_address."&data_city=".$data_city."&data_country=".$data_country;
echo "<a href='$path_update'>";
button("Update","Display all the retrieved users from LDAP in order to update them");
echo "</a>";
echo "</td>";
} ?>
<td>
<img src="<? echo $g_icon_path;?>question.gif" ALT="Help" onClick="show_comment_screen('Help','Update users from LDAP',51,'');">
</td>
<? if ( right_user($connected_user,13) ){ ?>
<td>
<a href=<? echo $g_file_log_directory; ?> title="Log data" > <img src="<? echo $g_icon_path;?>see.gif" border="0"> </a>
</td>
<? } ?>
</tr>
</table>
</form>
<?
include ("include_bottom.inc");
?>
</BODY>
</HTML>