* Licensed under the GNU GPL. For full terms see the file COPYING. * * Main routine for directory window: Search Form + Search Results * * @package directory * @subpackage main * @version $Id: directory.php,v 1.37 2007/01/05 10:50:24 avel Exp $ * @copyright (c) 1999-2004 Alexandros Vellis */ include_once ('config.php'); if($ldq_standalone) { include_once ('standalone/standalone.php'); } else { $public_mode = false; 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/"); include_once (SM_PATH . 'include/validate.php'); include_once (SM_PATH . 'include/load_prefs.php'); } } sqgetGlobalVar('language', $language, SQ_GET); if(!isset($language)) { $language = $lang_iso = getPref($data_dir, $username, 'language'); } $ldq_lang = substr($lang_iso, 0, 2); $charset = $languages[$lang_iso]['CHARSET']; mb_internal_encoding($charset); $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($ldq_support_eduperson) { include_once(DIR_PATH . 'include/eduorg.inc.php'); include_once(DIR_PATH . 'include/eduorg_html.inc.php'); } if(isset($ldq_custom) && !(empty($ldq_custom)) && file_exists(DIR_PATH . "include/custom/$ldq_custom.php")) { include_once (DIR_PATH . "include/custom/$ldq_custom.php"); } if($ldq_support_eduperson) { include_once(DIR_PATH . 'include/eduorg.inc.php'); include_once(DIR_PATH . 'include/eduorg_html.inc.php'); } /* * ============ Variable import ============ */ $PHP_SELF = strip_tags($_SERVER['PHP_SELF']); $self = basename($PHP_SELF); if(isset($_POST['ldq_searchfor'])) { $ldq_searchfor = $_POST['ldq_searchfor']; } else { $ldq_searchfor = $ldq_enable_searchfor[0]; } sqgetGlobalVar('ldq_searchby', $ldq_searchby, SQ_POST); sqgetGlobalVar('ldq_comparetype', $ldq_comparetype, SQ_POST); sqgetGlobalVar('ldq_querystr', $ldq_querystr, SQ_POST); sqgetGlobalVar('ldq_querystr_simple', $ldq_querystr_simple, SQ_POST); sqgetGlobalVar('ldq_affiliation', $ldq_affiliation, SQ_POST); sqgetGlobalVar('ldq_title', $ldq_title, SQ_POST); if(isset($_POST['ldq_sortby'])) { $ldq_sortby = $_POST['ldq_sortby']; } else { $ldq_sortby = $ldq_searchattrs[0]; } sqgetGlobalVar('Submit_Button', $Submit_Button, SQ_POST); sqgetGlobalVar('popup', $popup, SQ_FORM); sqgetGlobalVar('formname', $formname, SQ_FORM); sqgetGlobalVar('inputname', $inputname, SQ_FORM); if(isset($_GET['mode'])) { $mode = $_GET['mode']; } elseif(isset($_SESSION['ldq_mode'])) { $mode = $_SESSION['ldq_mode']; } else { $mode = $ldq_default_mode; } $_SESSION['ldq_mode'] = $mode; /* Try to find out if we are submitting a form. In IE6, * when pressing enter, the default submit button does not get * through to $_POST like in all sane browsers. */ if((isset($_POST['search']) || isset($_POST['ldq_querystr'][0]) || isset($_POST['ldq_querystr_simple'])) && !isset($_GET['add']) && !isset($_GET['less'])) { $search_requested = true; } else { $search_requested = false; } if(isset($_POST['searchform'])) { $searchform = $_POST['searchform']; } elseif(isset($_GET['searchform'])) { $searchform = $_GET['searchform']; } else { $searchform = 'yes'; } if(isset($_GET['add']) || isset($_GET['less'])) { $searchform = 'yes'; } sqgetGlobalVar('browseorgdn', $browseorgdn, SQ_GET); sqgetGlobalVar('affiliates', $affiliates, SQ_GET); $directory_output_type = getPref($data_dir, $username, "directory_output_type"); $compose_new_win = getPref($data_dir, $username, 'compose_new_win'); if(!$ldq_standalone) { $location = get_location(); } directory_LoadPrefs(); if (isset($_POST['add']) || isset($_GET['add']) ) { $rows = sizeof($ldq_querystr) + 1; } elseif ( isset($_POST['less']) || isset($_GET['less']) ) { $rows = sizeof($ldq_querystr) - 1; } elseif (isset($ldq_querystr)) { $rows = sizeof($ldq_querystr); } else { $rows = 1; } if(isset($_GET['showrestrict'])) { $show_restrict = $_GET['showrestrict']; } else { if($ldq_standalone) { $show_restrict = 0; } else { $show_restrict = 1; } } if(isset($_POST['restrict'])) { $restrict = $_POST['restrict']; } elseif(isset($_GET['restrict'])) { $restrict = $_GET['restrict']; $show_restrict = 0; } else { $restrict = array('*'); } if(!$ldq_support_eduperson) { $show_restrict = 0; } /* --- Cache OrgUnitDNs ----- */ if($ldq_support_eduperson) { if(isset($_SESSION['orgs'])) { $orgs = $_SESSION['orgs']; $orgs3 = $_SESSION['orgs3']; } else { /* Orgs Not cached into session. */ global $orgs, $orgs3; cache_orgunitdns(); } } /* ---------- Gather together attributes that are to be displayed. --------- */ $attributes = array(); if(!isset($directory_output_type)) { /* Put defaults */ $directory_output_type = $directory_default_output_type; $attributes = $ldq_default_attrs; } if($public_mode == true && isset($ldq_enable_attrs_public) ) { $ldq_enable_attrs = $ldq_enable_attrs_public; } foreach($ldq_enable_attrs as $attr) { $Var = "directory_showattr_" . $attr; if(isset($$Var) && $$Var == '1') { $attributes[] = $attr; } } /* ============== Catch common errors here ============== */ if ($search_requested && (empty($ldq_querystr[0]) && empty($ldq_querystr_simple) ) ) { $error[] = _("You have to define at least one search term."); } /** -------- Perform search & echo results ---------- */ if ( ($search_requested && (isset($ldq_querystr) || isset($ldq_querystr_simple) ) || isset($browseorgdn)) && !isset($error)) { /** Convert search string to UTF-8 because that's what LDAP understands. */ if(strtoupper($charset) != "UTF-8") { if(isset($ldq_querystr_simple)) { $ldq_querystr_simple_utf = directory_escape_ldap_string(directory_string_convert($ldq_querystr_simple, $charset, "UTF-8")); } elseif(isset($ldq_querystr)) { for($i=0; $i 0 ) ) { break; } switch ($ldq_comparetype[$i]) { case 'is': $ldq_tfilter[$i] = $ldq_querystr_utf[$i]; break; case 'contains': default: $ldq_tfilter[$i] = "*$ldq_querystr_utf[$i]*"; break; } if ($ldq_tfilter[$i] == '***') { $ldq_tfilter[$i] = "*"; } if($ldq_searchby[$i] == 'mail' && $ldq_enablemailalternate == true ) { $ldq_filter[$i] = '|(mail='.$ldq_tfilter[$i].')(mailAlternateAddress='.$ldq_tfilter[$i].')'; } else { $ldq_filter[$i] = $ldq_searchby[$i] . '=' . $ldq_tfilter[$i]; } } } if(sizeof($ldq_filter) == 1){ $ldq_finalfilter = $ldq_filter[0]; } else { $ldq_finalfilter = '&'; for($i=0; $i 1) { $restrict_filter = '|'; for($k=0;$k$extra_filter"; if (!($ldq_result2 = ldap_search($ldq_ldap, $ldq_base, $extra_filter, $extra_search_attributes, 0, $ldq_maxres, $ldq_timeout))) { echo "Second level search failed."; } $ldq_entry2 = ldap_get_entries ($ldq_ldap, $ldq_result2); $follow = array(); for($k=0; $k<$ldq_entry2['count']; $k++) { $attr = 'cn'; $attr_lang = $attr.';lang-'.$ldq_lang; if(isset($ldq_entry2[$k][$attr_lang])) { $follow[$ldq_entry2[$k]['dn']] = directory_string_convert($ldq_entry2[$k][$attr_lang][0], "UTF-8", $charset); } else { $follow[$ldq_entry2[$k]['dn']] = directory_string_convert($ldq_entry2[$k][$attr][0], "UTF-8", $charset); } } // echo "
\nRESULTS:\n"; print_r($follow); echo "
"; } } */ ldap_close($ldq_ldap); } /* Foreach LDAP Server */ /* This flag is used to mark that the produced page contains results. This is * for the case that we want to hide results from search engines. */ $resultPage = true; } /* Search is set */ /* * ============== Presentation: Page Header ============== */ if(isset($popup)) { $wintitle = _("Directory"); $js = ''; if(isset($popup) && (isset($ldq_querystr) || isset($ldq_querystr_simple) || isset($browseorgdn))) { /* Note: Remove type="" if it does bad... */ $js = '"; } $prev = sq_bindtextdomain ('squirrelmail', SM_PATH . 'locale'); textdomain ('squirrelmail'); displayHtmlHeader($wintitle, $js); } else { if($ldq_standalone) { // displayPageHeader() from standalone/page_header.php has an extra argument, $xtra_head $xtra_head = ''; // which we use to disable google indexing and caching of search results. if(isset($resultPage)) { $xtra_head = ''; } displayPageHeader($color, _("Directory Service"), $searchform, 'onLoad="initItems();"', $xtra_head); } else { $prev = sq_bindtextdomain ('squirrelmail', SM_PATH . 'locale'); textdomain ('squirrelmail'); displayPageHeader($color, "None", ''); } } $prev = sq_bindtextdomain ('directory', DIR_PATH . 'locale'); textdomain ('directory'); if($ldq_support_eduperson) { echo '"; } directory_print_all_sections_start(); /** ============= Error message, if exists ============= */ if(isset($error)) { directory_print_section_start( _("Error Encountered") ); echo ''; foreach($error as $e) { echo '

'.$e.'

'; } echo ''; directory_print_section_end(); } /* ================ Print search form ================ */ if($searchform == 'yes') { directory_print_section_start(''. _("Directory Service") . ' - ' . _("Search") . ' - '.directory_navbar().''); echo '
'; if($ldq_standalone) { echo ''; } echo ''; if($mode == DIR_SIMPLE) { /* Simple Form */ echo ''; echo ' '. ''; } else { echo ''; } if(!isset($ldq_searchby)) { $ldq_searchby = array('cn'); } for($i=0; $i<$rows; $i++ ) { /* Start row */ echo ''; } /** Restrict option */ if($ldq_restrict_ou && $ldq_support_eduperson) { echo "\n" . '' . ''; } /* Affiliation + Titles filter; a set of two select boxes. Display only if * $titles is set and eduPerson mode is enabled. */ if(isset($titles) && $ldq_support_eduperson) { echo ''. ''; } else { /* Display a simpler titles list, if $titles is defined. For * non-eduPerson setups. */ echo ''. ''; } /* Sort By */ echo ''. ''; /* Submit */ echo '
'. '' . _("Search For") . ': '. ''. '
'. '
' . ' '; } else { /* Advanced Form */ /* objectclass the user wants to search in */ if(sizeof($ldq_enable_searchfor) > 1) { echo '' . _("Search For") . ':
'; if ($i == 0) { echo '' . _("Criteria") . ': '; } else { echo _("and"); } /* attribute the user wants to search by */ echo ''; echo ''; /* type of search (is|contains) */ echo ''; /* search string */ echo ''; echo '
'; /* End row */ echo '
'. _("Restrict:") .''; if($show_restrict) { echo ''; } else { foreach($restrict as $no=>$dn) { echo ''; echo '=> '. $orgs[$dn]['struct'].' '.$orgs[$dn]['text'].'
'; } echo '=> '. ''; if($ldq_standalone) { echo ''. _("Choose Multiple Organizational Units") . ''; } else { echo ''. _("Clear") . ''; } echo '
'; } echo '
' . _("Affiliation") . ':"; /* Title filter */ echo '  ' . _("Title") . ': '. '' . '
' . _("Title") . ':' . '
' . _("Sort By:") . '" . '
' . ' '; if($rows > 1) { if($ldq_standalone) { echo ''; } else { echo ''; } } if($i<5) { if($ldq_standalone) { echo ''; } else { echo ''; } } echo ' '; } /* End advanced mode. */ if(isset($popup)) { echo ' '; echo ' '; } if(!empty($formname)) { echo ' '; } if(!empty($inputname)) { echo ' '; } echo '
'; echo "
"; directory_print_section_end(); } /* =============== Display Results =============== */ if(isset($ldq_entry)) { for ($ldq_lds=0 ; $ldq_lds < count($ldap_server) ; $ldq_lds++) { if(!isset($ldq_entry[$ldq_lds])) { continue; } if(isset($ldap_server[$ldq_lds]['name;lang-'.$ldq_lang])) { $ldq_server_description = $ldap_server[$ldq_lds]['name;lang-'.$ldq_lang]; } else { $ldq_server_description = $ldap_server[$ldq_lds]['name']; } directory_print_section_start( _("Search Results") . ' - ' . $ldq_server_description); if(isset($noentries)) { echo '

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

'; } if(isset($restrict) && !in_array('*', $restrict)) { echo '

' . _("Search restricted to the following organizational units:") . '

    '; foreach($restrict as $re) { echo '
  • ' . $orgs[$re]['struct'] . ' ' .$orgs[$re]['text'] . '
  • '; } echo '
'; } if(isset($toomanyresults)) { echo '

'; echo _("Warning: Too many results were found, a partial list follows."); echo '
'; echo _("You may redefine your search to get more specific results.") . '


'; } if($directory_output_type=='multitable') { directory_dispresultsMulti ($attributes, $ldq_entry[$ldq_lds], $ldq_sortby); } else { /* "onetable" */ directory_dispresultsSingle ($attributes, $ldq_entry[$ldq_lds], $ldq_sortby); } directory_print_section_end(); } } directory_print_all_sections_end(); echo ''; ?>