*/ /** Define's and includes */ include_once('config.php'); if($ldq_standalone) { include_once('standalone/standalone.php'); } else { $public_mode = false; $logged_in = true; if (file_exists('../../include/init.php')) { include_once('../../include/init.php'); define('DIR_PATH', SM_PATH . "plugins/directory/"); } else if (file_exists('../../include/validate.php')) { define('SM_PATH', "../../"); define('DIR_PATH', SM_PATH . "plugins/directory/"); require_once (SM_PATH . 'include/validate.php'); include_once (SM_PATH . 'include/load_prefs.php'); } $language = $lang_iso = getPref($data_dir, $username, 'language'); } $prev = sq_bindtextdomain ('directory', DIR_PATH . 'locale'); textdomain ('directory'); include_once (DIR_PATH . "include/html.php"); include_once (DIR_PATH . "include/javascript.php"); include_once (DIR_PATH . "include/functions.php"); include_once (DIR_PATH . 'include/mailto.php'); include_once (DIR_PATH . "include/constants.php"); include_once (DIR_PATH . "include/display.php"); if(isset($ldq_custom) && !(empty($ldq_custom)) && file_exists(DIR_PATH . "custom/$ldq_custom.php")) { include_once (DIR_PATH . "custom/$ldq_custom.php"); } /* ------------- Variable import ------------- */ $compose_new_win = getPref($data_dir, $username, 'compose_new_win'); if(!$ldq_standalone) { $location = get_location(); } directory_LoadPrefs(); sqgetGlobalVar('printform', $printform, SQ_GET); sqgetGlobalVar('showvertical', $showvertical, SQ_GET); if($ldq_standalone) { displayPageHeader($color, _("Your Profile") . ' - ' . _("Directory Service")); } else { $prev = sq_bindtextdomain ('squirrelmail', SM_PATH . 'locale'); textdomain ('squirrelmail'); displayPageHeader($color, "None"); } $prev = sq_bindtextdomain ('directory_editprofile', DIR_PATH . 'locale'); textdomain ('directory_editprofile'); include_once (DIR_PATH . "include/edit.php"); include_once (DIR_PATH . "schemas/descriptions.php"); $ldq_lang = substr($lang_iso, 0, 2); $charset = $languages[$lang_iso]['CHARSET']; mb_internal_encoding($charset); $showprofile = true; if(!isset($showvertical)) { $showvertical = false; } if(!isset($printform)) { $printform = false; } else { if($printform) { $showprofile = false; } } /* ------------------ User validation ------------------ */ if(isset($_POST['loginsubmit'])) { $login_username = $_POST['login_username']; $login_password = $_POST['login_password']; $ldq_lds = 0; $ldq_Server = $ldap_server[$ldq_lds]['host']; $ldq_Port = $ldap_server[$ldq_lds]['port']; $ldq_base = $ldap_server[$ldq_lds]['base']; $ldq_maxres = $ldap_server[$ldq_lds]['maxrows']; $ldq_timeout = $ldap_server[$ldq_lds]['timeout']; if(isset($ldap_server[$ldq_lds]['binddn'])) { $ldq_bind_dn = $ldap_server[$ldq_lds]['binddn']; } if(isset($ldap_server[$ldq_lds]['bindpw'])) { $ldq_pass = $ldap_server[$ldq_lds]['bindpw']; } if(isset($ldap_server[$ldq_lds]['writedn'])) { $ldq_write_dn = $ldap_server[$ldq_lds]['writedn']; } else { $ldq_bind_dn = $ldap_server[$ldq_lds]['binddn']; } if(isset($ldap_server[$ldq_lds]['writepw'])) { $ldq_write_pass = $ldap_server[$ldq_lds]['writepw']; } else { $ldq_pass = $ldap_server[$ldq_lds]['bindpw']; } if (!($ldq_ldap=ldap_connect($ldq_Server,$ldq_Port))) { echo ("Could not connect to LDAP server " . $ldq_Server); exit; } if(isset($ldq_bind_dn)) { if (!ldap_bind($ldq_ldap, $ldq_bind_dn, $ldq_pass)) { echo ("Unable to bind to LDAP server
\n"); exit; } } $ldq_filter = '(uid='.$login_username.')'; $ldq_tattr = array('uid', 'userpassword'); /** Perform search! */ if (!($ldq_result = ldap_search($ldq_ldap, $ldq_base, $ldq_filter, $ldq_tattr, 0, $ldq_maxres, $ldq_timeout))) { echo '

' . _("No entries found.") . '

'; } $entry = ldap_get_entries ($ldq_ldap, $ldq_result); sanitize_entry_array($entry); ldap_close($ldq_ldap); if($entry['count'] != 1 ) { $logged_in = false; } else { $dn = $entry[0]['dn']; $ldap_password=substr($entry[0]['userpassword'][0], 7); if($ldap_password == crypt($login_password,$ldap_password)) { $logged_in = true; $_SESSION['logged_in'] = true; $username = $login_username; $_SESSION['username'] = $login_username; } else { $logged_in = false; } } } /* ---------- Login Form --------- */ if(!$logged_in) { echo '

' . _("Your Profile") . ' - ' . _("Directory Service") . '

'; directory_print_all_sections_start(); if(isset($_POST['loginsubmit'])) { directory_print_section_start( _("Error Encountered") ); echo ''. '

'. _("Login Failed: Unknown User or Password Incorrect."). ''; directory_print_section_end(); } directory_print_section_start(_("Login")); echo '

'; if(isset($_GET['loggedout'])) { echo _("Successfully logged out. You can login again below:"); } else { echo _("To update your profile, you must first login:"); } echo '

'. _("Username") . '
'. _("Password") . '
'; directory_print_section_end(); if(isset($editprofile_url) && !empty($editprofile_url)) { directory_print_section_start(_("Attributes that need to be approved first")); echo '

' . sprintf( _("If you would like to change other important attributes of your profile, you need to make an application through the User Services."), $editprofile_url) . '

'; directory_print_section_end(); directory_print_all_sections_end(); } echo ''; exit; } /* ---------- Validation and Catch common errors here ------------- */ if (isset($_POST['submitchanges'])) { $newinfo = $_POST['myprofile']; /* Convert every single string to UTF-8 */ foreach($newinfo as $attr => $ni) { if(!is_array($ni)) { $newinfo[$attr] = directory_string_convert($newinfo[$attr], $charset, "UTF-8"); } } /* Validation of labeleduri attributes */ if(isset($newinfo['labeleduri'])) { $unsetcount = 0; for($i=0; $i 1 && $unsetcount == sizeof($newinfo['labeleduri'])) { $info_del['labeleduri'] = array(); } if(isset($labeleduri_tmp)) { if($nonempty == true) { // echo "heh? "; } else { // echo "OK... newinfo['labeleduri'] = ". print_r($labeleduri_tmp); $newinfo['labeleduri'] = $labeleduri_tmp; } } } /* Validation of attributes with 'posvals' */ foreach($newinfo as $attr => $ni) { foreach($editprofile_langs as $l) { if($l != 'en') { $a = $attr.';lang-'.$l; } else { $a = $attr; } if(isset($ni[$a]) && isset($ldq_attributes[$attr]['posvals'])) { for($i=0; $i\n"); exit; } } /** --- Gather attributes to ask LDAP --- */ $ask_attrs = array_merge($ldq_editable_attrs, $ldq_enable_attrs, $ldq_searchattrs); $ask_attrs = array_unique($ask_attrs); foreach ($ask_attrs as $attr) { if(isset($ldq_attributes[$attr]['disabled']) && $ldq_attributes[$attr]['disabled'] == true) { continue; } $ldq_tattr[] = $attr; /** Additional attributes */ if (isset($ldq_attributes[$attr]['additional_attrs']) && is_array($ldq_attributes[$attr]['additional_attrs']) ) { foreach($ldq_attributes[$attr]['additional_attrs'] as $additional) { $ldq_tattr[] = $additional; } } } $ldq_tattr[] = 'uid'; if(!empty($ldq_privacy_attribute)) { $ldq_tattr[] = $ldq_privacy_attribute; } if(!empty($ldq_privacy_attribute_internal)) { $ldq_tattr[] = $ldq_privacy_attribute_internal; } $ldq_tattr = array_unique($ldq_tattr); $ldq_searchfor = 'people'; if(isset($ldq_searchobjs[$ldq_searchfor]['rdn'])) { $ldq_base = $ldq_searchobjs[$ldq_searchfor]['rdn'] . ',' . $ldq_base; } $ldq_filter = '(uid='.$username.')'; /** Perform search! */ if (!($ldq_result = ldap_search($ldq_ldap, $ldq_base, $ldq_filter, $ldq_tattr, 0, $ldq_maxres, $ldq_timeout))) { echo '

' . _("No entries found.") . '

'; } $entry = ldap_get_entries ($ldq_ldap, $ldq_result); sanitize_entry_array($entry); $dn = $entry[0]['dn']; /* ---------- Perform Changes, if any. ---------- */ if(isset($_POST['submitchanges']) && !isset($error)) { $ask_attrs = array_merge($ldq_editable_attrs, $ldq_editable_attrs); $ask_attrs = array_unique($ask_attrs); foreach($ldq_editable_attrs as $attr) { foreach($editprofile_langs as $l) { if($l != 'en') { $a = $attr.';lang-'.$l; } else { $a = $attr; } if(isset($newinfo[$a])) { if ( (!isset($entry[0][$a]) && !empty($newinfo[$a])) || (isset($entry[0][$a])) && !empty($newinfo[$a]) && (!is_array($newinfo[$a]) && $newinfo[$a] != $entry[0][$a][0]) ) { //echo "New / Changed Attribute: $a = ".print_r($newinfo[$a], true)."
"; $info[$a] = $newinfo[$a]; } if(is_array($newinfo[$a])) { //echo "Array Attribute: $a = "; print_r($newinfo[$a]); echo "
"; $info[$a] = $newinfo[$a]; } if( isset($entry[0][$a]) && $entry[0][$a]['count']>0 && empty($newinfo[$a])) { //echo "Deleted Attribute: ".$a."
"; $info_del[$a] = array(); } } else { if( isset($entry[0][$a]) && $entry[0][$a]['count']>0 ) { //echo "Deleted array Attribute: ".$a."
"; $info_del[$a] = array(); } } } } if( (isset($info) && sizeof($info)>0) || (isset($info_del) && sizeof($info_del)>0) ) { ldap_bind($ldq_ldap, $ldq_write_dn, $ldq_write_pass); /* echo "
";
        echo " DEBUG: ldap_modify($ldq_ldap, $dn, ";
        @print_r($info);
        echo " DEBUG: ldap_mod_del($ldq_ldap, $dn, ";
        @print_r($info_del);
        echo "
"; */ if(isset($info) && !(ldap_modify($ldq_ldap, $dn, $info))) { $update_error = true; $error = _("Could not update your entry on the Directory Server."); } if(isset($info_del) && !(ldap_mod_del($ldq_ldap, $dn, $info_del))) { $update_error = true; $error = _("Could not update your entry on the Directory Server."); } if(!isset($update_error)) { directory_print_all_sections_start(); directory_print_section_start(_("Your Profile")); echo '
'. _("Your details have been successfully modified on the Directory Server."). '

'. _("Return to Directory Profile Edit Page") . '

'. '
'; directory_print_section_end(); directory_print_all_sections_end(); echo ''; exit; } } } ldap_close($ldq_ldap); /* ====================== Presentation Logic ====================== */ /* ---------- Print Page Header ---------- */ directory_print_all_sections_start(); /* ---------- Print Error message if it exists ---------- */ if(isset($error)) { directory_print_section_start( _("Error Encountered") ); echo '

'. $error . ''; directory_print_section_end(); } /* -------------- print edit form ----------------- */ if($showprofile == true) { directory_print_section_start(_("Your Profile")); echo '

'. _("This page shows how your profile looks to people who browse the Directory Service, and allows you to edit or hide certain attributes from Internet or Campus users.") . '

' ; echo '
' . _("Proceed to Edit Profile") . '
'; if($ldq_standalone) { echo '

' . _("If you have finished editing, please logout for security reasons.") . '

'; } $attributes = array_merge($ldq_enable_attrs, $ldq_searchattrs); $attributes = array_unique($attributes); echo '

' . _("Currently your entry in the Directory looks like this:") . ' '; if($showvertical) { echo '' . _("(Show in vertical tables)"); } else { echo '' . _("(Show in horizontal tables, to compare easily)"); } echo '

'; echo '

' . _("Public - Internet Users") . '

'; $prev = sq_bindtextdomain ('directory', DIR_PATH . 'locale'); textdomain ('directory'); $ldq_privacy_attribute = 'uoaprivate'; if($showvertical) { directory_dispresultsSingle($attributes, $entry, 'cn'); } else { directory_dispresultsMulti($attributes, $entry, 'cn'); } $prev = sq_bindtextdomain ('directory_editprofile', DIR_PATH . 'locale'); textdomain ('directory_editprofile'); echo '

' . _("University Members") . '

'; $prev = sq_bindtextdomain ('directory', DIR_PATH . 'locale'); textdomain ('directory'); $ldq_privacy_attribute = 'uoaprivateinternal'; if($showvertical) { directory_dispresultsSingle($attributes, $entry, 'cn'); } else { directory_dispresultsMulti($attributes, $entry, 'cn'); } $prev = sq_bindtextdomain ('directory_editprofile', DIR_PATH . 'locale'); textdomain ('directory_editprofile'); echo '
' . _("Proceed to Edit Profile") . '
'; directory_print_section_end(); } /* Show profile */ if($printform == true) { echo '
'; /* Freely editable attributes -- will be committed to LDAP at once. */ directory_print_section_start(_("Freely Editable Attributes")); echo '

' . _("The following attributes can be freely changed to reflect your preferences.") . '

'; echo '
' . ' '. _("Please note well: You MUST set the English value for the changes to take effect."). '
'; echo ''; directory_print_editable_attributes($ldq_editable_attrs, $entry); echo '
'; directory_print_section_end(); /* Submit */ echo ' ' . ' ' . ' '. '

 
'; /* Link to some other application form, if it exists. */ if(isset($editprofile_url) && !empty($editprofile_url)) { directory_print_section_start(_("Attributes that need to be approved first")); echo '

' . sprintf( _("If you would like to change other important attributes of your profile, you need to make an application through the User Services."), $editprofile_url) . '

'; directory_print_section_end(); } } /* echo form end */ directory_print_all_sections_end(); echo ''; echo '';