Changeset d1d2c4f in github


Ignore:
Timestamp:
Jan 8, 2006 2:15:44 AM (7 years ago)
Author:
svncommit <devs@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
d4ab311
Parents:
3baec23
Message:

adding files and modifications for public ldap search

Files:
7 added
8 edited

Legend:

Unmodified
Added
Removed
  • config/main.inc.php.dist

    r3baec23 rd1d2c4f  
    132132$rcmail_config['mail_header_delimiter'] = "\r\n"; 
    133133 
     134// public ldap servers to search for contacts 
     135$rcmail_config['ldap_public'] = false; 
     136 
     137/** example config for Verisign directory 
     138$rcmail_config['ldap_public']['Verisign'] = array('hosts'         => array('directory.verisign.com'), 
     139                                                  'port'          => 389, 
     140                                                  'base_dn'       => '', 
     141                                                  'search_fields' => array('mail', 'cn'), 
     142                                                  'name_field'    => 'cn', 
     143                                                  'mail_field'    => 'mail', 
     144                                                  'scope'         => 'sub', 
     145                                                  'fuzzy_search'  => 0); 
     146**/ 
     147 
    134148 
    135149/***** these settings can be overwritten by user's preferences *****/ 
  • index.php

    r15a9d1c rd1d2c4f  
    11<?php 
    2  
    32/* 
    43 +-----------------------------------------------------------------------+ 
     
    282281  if ($_action=='list' && $_GET['_remote']) 
    283282    include('program/steps/addressbook/list.inc'); 
     283 
     284  if ($_action=='ldappublicsearch') 
     285    include('program/steps/addressbook/ldapsearchform.inc'); 
    284286  } 
    285287 
  • program/include/main.inc

    r15a9d1c rd1d2c4f  
    925925        'contactdetails' => 'rcmail_contact_details', 
    926926        'contacteditform' => 'rcmail_contact_editform', 
     927        'ldappublicsearch' => 'rcmail_ldap_public_search_form', 
     928        'ldappublicaddresslist' => 'rcmail_ldap_public_list', 
    927929 
    928930        // USER SETTINGS 
     
    11111113 
    11121114 
    1113 function rcube_table_output($attrib, $sql_result, $a_show_cols, $id_col) 
     1115function rcube_table_output($attrib, $table_data, $a_show_cols, $id_col) 
    11141116  { 
    11151117  global $DB; 
     
    11291131   
    11301132  $c = 0; 
    1131   while ($sql_result && ($sql_arr = $DB->fetch_assoc($sql_result))) 
    1132     { 
    1133     $zebra_class = $c%2 ? 'even' : 'odd'; 
    1134  
    1135     $table .= sprintf('<tr id="rcmrow%d" class="contact '.$zebra_class.'">'."\n", $sql_arr[$id_col]); 
    1136  
    1137     // format each col 
    1138     foreach ($a_show_cols as $col) 
     1133 
     1134  if (!is_array($table_data))  
     1135    { 
     1136    while ($table_data && ($sql_arr = $DB->fetch_assoc($table_data))) 
    11391137      { 
    1140       $cont = rep_specialchars_output($sql_arr[$col]); 
    1141           $table .= '<td class="'.$col.'">' . $cont . "</td>\n"; 
     1138      $zebra_class = $c%2 ? 'even' : 'odd'; 
     1139 
     1140      $table .= sprintf('<tr id="rcmrow%d" class="contact '.$zebra_class.'">'."\n", $sql_arr[$id_col]); 
     1141 
     1142      // format each col 
     1143      foreach ($a_show_cols as $col) 
     1144        { 
     1145        $cont = rep_specialchars_output($sql_arr[$col]); 
     1146            $table .= '<td class="'.$col.'">' . $cont . "</td>\n"; 
     1147        } 
     1148 
     1149      $table .= "</tr>\n"; 
     1150      $c++; 
    11421151      } 
    1143  
    1144     $table .= "</tr>\n"; 
    1145     $c++; 
     1152    } 
     1153  else  
     1154    { 
     1155    foreach ($table_data as $row_data) 
     1156      { 
     1157      $zebra_class = $c%2 ? 'even' : 'odd'; 
     1158 
     1159      $table .= sprintf('<tr id="rcmrow%d" class="contact '.$zebra_class.'">'."\n", $row_data[$id_col]); 
     1160 
     1161      // format each col 
     1162      foreach ($a_show_cols as $col) 
     1163        { 
     1164        $cont = rep_specialchars_output($row_data[$col]); 
     1165            $table .= '<td class="'.$col.'">' . $cont . "</td>\n"; 
     1166        } 
     1167 
     1168      $table .= "</tr>\n"; 
     1169      $c++; 
     1170      } 
    11461171    } 
    11471172 
     
    14211446 
    14221447 
    1423  
    14241448function rcube_timer() 
    14251449  { 
     
    14431467  } 
    14441468 
    1445  
    14461469?> 
  • program/js/app.js

    r15a9d1c rd1d2c4f  
    161161 
    162162      case 'addressbook': 
    163         var contacts_list = this.gui_objects.contactslist; 
     163        var contacts_list      = this.gui_objects.contactslist; 
     164        var ldap_contacts_list = this.gui_objects.ldapcontactslist; 
     165 
    164166        if (contacts_list) 
    165167          this.init_contactslist(contacts_list); 
    166168       
     169        if (ldap_contacts_list) 
     170          this.init_ldapsearchlist(ldap_contacts_list); 
     171 
    167172        this.set_page_buttons(); 
    168173           
     
    173178          this.enable_command('save', true); 
    174179       
    175         this.enable_command('list', 'add', true); 
     180        this.enable_command('list', 'add', 'ldappublicsearch', true); 
    176181        break; 
    177182 
     
    373378 
    374379 
     380  // get all contact rows from HTML table and init each row 
     381  this.init_ldapsearchlist = function(ldap_contacts_list) 
     382    { 
     383    if (ldap_contacts_list && ldap_contacts_list.tBodies[0]) 
     384      { 
     385      this.ldap_contact_rows = new Array(); 
     386 
     387      var row; 
     388      for(var r=0; r<ldap_contacts_list.tBodies[0].childNodes.length; r++) 
     389        { 
     390        row = ldap_contacts_list.tBodies[0].childNodes[r]; 
     391        this.init_table_row(row, 'ldap_contact_rows'); 
     392        } 
     393      } 
     394 
     395    // alias to common rows array 
     396    this.list_rows = this.ldap_contact_rows; 
     397    }; 
     398 
     399 
    375400  // make references in internal array and set event handlers 
    376401  this.init_table_row = function(row, array_name) 
     
    549574      case 'add': 
    550575        if (this.task=='addressbook') 
    551           this.load_contact(0, 'add'); 
     576          if (!window.frames[this.env.contentframe].rcmail) 
     577            this.load_contact(0, 'add'); 
     578          else 
     579            { 
     580            if (window.frames[this.env.contentframe].rcmail.selection.length) 
     581              this.add_ldap_contacts(); 
     582            else 
     583              this.load_contact(0, 'add'); 
     584            } 
    552585        else if (this.task=='settings') 
    553586          { 
     
    683716          //location.href = this.env.comm_path+'&_action=show&_uid='+this.env.prev_uid+'&_mbox='+this.env.mailbox; 
    684717        break; 
    685  
     718       
     719       
    686720      case 'compose': 
    687721        var url = this.env.comm_path+'&_action=compose'; 
     
    700734          else 
    701735            { 
    702             for (var n=0; n<this.selection.length; n++) 
    703               a_cids[a_cids.length] = this.selection[n]; 
     736            if (!window.frames[this.env.contentframe].rcmail.selection.length) 
     737              { 
     738              for (var n=0; n<this.selection.length; n++) 
     739                a_cids[a_cids.length] = this.selection[n]; 
     740              } 
     741            else 
     742              { 
     743              var frameRcmail = window.frames[this.env.contentframe].rcmail; 
     744              // get the email address(es) 
     745              for (var n=0; n<frameRcmail.selection.length; n++) 
     746                a_cids[a_cids.length] = frameRcmail.ldap_contact_rows[frameRcmail.selection[n]].obj.cells[1].innerHTML; 
     747              } 
    704748            } 
    705  
    706749          if (a_cids.length) 
    707750            url += '&_to='+a_cids.join(','); 
    708751          else 
    709752            break; 
     753             
    710754          } 
    711755        else if (props) 
    712756           url += '&_to='+props; 
     757         
     758        // don't know if this is necessary... 
     759        url = url.replace(/&_framed=1/, ""); 
    713760 
    714761        this.set_busy(true); 
    715         location.href = url; 
    716         break;       
     762 
     763        // need parent in case we are coming from the contact frame 
     764        parent.window.location.href = url; 
     765        break;     
    717766 
    718767      case 'send': 
     
    778827        this.add_contact(props); 
    779828        break; 
     829       
     830 
     831      // ldap search 
     832      case 'ldappublicsearch': 
     833        if (this.gui_objects.ldappublicsearchform)  
     834          this.gui_objects.ldappublicsearchform.submit(); 
     835        else  
     836          this.ldappublicsearch(command); 
     837        break;  
    780838 
    781839 
     
    9551013  this.click_row = function(e, id) 
    9561014    { 
    957     var ctrl = this.check_ctrlkey(e); 
     1015    var shift = this.check_shiftkey(e); 
    9581016     
    9591017    // don't do anything (another action processed before) 
     
    9651023     
    9661024    if (!this.drag_active && this.in_selection_before==id) 
    967       this.select(id, (ctrl && this.task!='settings')); 
     1025      { 
     1026      this.select(id, (shift && this.task!='settings')); 
     1027      } 
    9681028     
    9691029    this.drag_start = false; 
     
    9711031         
    9721032    // row was double clicked 
    973     if (this.task=='mail' && this.list_rows && this.list_rows[id].clicked && !ctrl) 
     1033    if (this.task=='mail' && this.list_rows && this.list_rows[id].clicked && !shift) 
    9741034      { 
    9751035      this.show_message(id); 
     
    9781038    else if (this.task=='addressbook') 
    9791039      { 
    980       if (this.selection.length==1 && this.env.contentframe) 
     1040      if (this.contact_rows && this.selection.length==1) 
     1041        { 
    9811042        this.load_contact(this.selection[0], 'show', true); 
    982       else if (this.task=='addressbook' && this.list_rows && this.list_rows[id].clicked) 
     1043        // change the text for the add contact button 
     1044        var links = parent.document.getElementById('abooktoolbar').getElementsByTagName('A'); 
     1045        for (i = 0; i < links.length; i++) 
     1046          { 
     1047          var onclickstring = new String(links[i].onclick); 
     1048          if (onclickstring.search('\"add\"') != -1) 
     1049            links[i].title = this.env.newcontact; 
     1050          } 
     1051        } 
     1052      else if (this.contact_rows && this.contact_rows[id].clicked) 
    9831053        { 
    9841054        this.load_contact(id, 'show'); 
    9851055        return false; 
    9861056        } 
     1057      else if (this.ldap_contact_rows && !this.ldap_contact_rows[id].clicked) 
     1058        { 
     1059        // clear selection 
     1060        parent.rcmail.clear_selection(); 
     1061 
     1062        // disable delete 
     1063        parent.rcmail.set_button('delete', 'pas'); 
     1064 
     1065        // change the text for the add contact button 
     1066        var links = parent.document.getElementById('abooktoolbar').getElementsByTagName('A'); 
     1067        for (i = 0; i < links.length; i++) 
     1068          { 
     1069          var onclickstring = new String(links[i].onclick); 
     1070          if (onclickstring.search('\"add\"') != -1) 
     1071            links[i].title = this.env.addcontact; 
     1072          } 
     1073        } 
     1074      // handle double click event 
     1075      else if (this.ldap_contact_rows && this.selection.length==1 && this.ldap_contact_rows[id].clicked) 
     1076        this.command('compose', this.ldap_contact_rows[id].obj.cells[1].innerHTML); 
    9871077      else if (this.env.contentframe) 
    9881078        { 
     
    10021092    return false; 
    10031093    }; 
    1004  
    10051094 
    10061095 
     
    19202009    }; 
    19212010   
     2011   
     2012  // load ldap search form 
     2013  this.ldappublicsearch = function(action) 
     2014    { 
     2015    var add_url = ''; 
     2016    var target = window; 
     2017    if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) 
     2018      { 
     2019      add_url = '&_framed=1'; 
     2020      target = window.frames[this.env.contentframe]; 
     2021      document.getElementById(this.env.contentframe).style.visibility = 'inherit'; 
     2022      } 
     2023    else 
     2024      return false;  
     2025 
     2026 
     2027    if (action == 'ldappublicsearch') 
     2028      target.location.href = this.env.comm_path+'&_action='+action+add_url; 
     2029    }; 
     2030  
     2031  // add ldap contacts to address book 
     2032  this.add_ldap_contacts = function() 
     2033    { 
     2034    if (window.frames[this.env.contentframe].rcmail) 
     2035      { 
     2036      var frame = window.frames[this.env.contentframe]; 
     2037 
     2038      // build the url 
     2039      var url    = '&_framed=1'; 
     2040      var emails = '&_emails='; 
     2041      var names  = '&_names='; 
     2042      var end    = ''; 
     2043      for (var n=0; n<frame.rcmail.selection.length; n++) 
     2044        { 
     2045        end = n < frame.rcmail.selection.length - 1 ? ',' : ''; 
     2046        emails += frame.rcmail.ldap_contact_rows[frame.rcmail.selection[n]].obj.cells[1].innerHTML + end; 
     2047        names  += frame.rcmail.ldap_contact_rows[frame.rcmail.selection[n]].obj.cells[0].innerHTML + end; 
     2048        } 
     2049        
     2050      frame.location.href = this.env.comm_path + '&_action=save&_framed=1' + emails + names; 
     2051      } 
     2052    return false; 
     2053    } 
     2054   
    19222055 
    19232056 
  • program/localization/en/labels.inc

    r15a9d1c rd1d2c4f  
    144144 
    145145$labels['newcontact']     = 'Create new contact card'; 
     146$labels['addcontact']     = 'Add selected contact to your addressbook'; 
    146147$labels['deletecontact']  = 'Delete selected contacts'; 
    147148$labels['composeto']      = 'Compose mail to'; 
     
    150151$labels['export']         = 'Export'; 
    151152 
     153$labels['ldappublicsearchname']    = 'Contact name'; 
     154$labels['ldappublicsearchtype'] = 'Exact match?'; 
     155$labels['ldappublicserverselect'] = 'Select servers'; 
     156$labels['ldappublicsearchfield'] = 'Search on'; 
     157$labels['ldappublicsearchform'] = 'Look for a contact'; 
     158$labels['ldappublicsearch'] = 'Search'; 
    152159 
    153160// settings 
  • program/localization/en/messages.inc

    r977a295e rd1d2c4f  
    7979$messages['notsentwarning'] = 'Message has not been sent. Do you want to discard your message?'; 
    8080 
     81$messages['notsentwarning'] = 'Message has not been sent. Do you want to discard your message?'; 
     82 
     83$messages['noldapserver'] = 'Please select an ldap server to search'; 
     84 
     85$messages['nocontactsreturned'] = 'No contacts were found'; 
     86 
     87$messages['nosearchname'] = 'Please enter a contact name or email address'; 
    8188 
    8289?> 
  • program/steps/addressbook/func.inc

    r1cded85 rd1d2c4f  
    8282  $javascript .= sprintf("%s.set_env('current_page', %d);\n", $JS_OBJECT_NAME, $CONTACTS_LIST['page']); 
    8383  $javascript .= sprintf("%s.set_env('pagecount', %d);\n", $JS_OBJECT_NAME, ceil($rowcount/$CONFIG['pagesize'])); 
     84  $javascript .= "rcmail.set_env('newcontact', '" . rcube_label('newcontact') . "');"; 
    8485  //$javascript .= sprintf("%s.set_env('contacts', %s);", $JS_OBJECT_NAME, array2js($a_js_message_arr)); 
    8586   
  • program/steps/addressbook/save.inc

    r1cded85 rd1d2c4f  
    2020*/ 
    2121 
    22  
    23 $a_save_cols = array('name', 'firstname', 'surname', 'email'); 
    24  
    25  
    2622// check input 
    27 if (empty($_POST['_name']) || empty($_POST['_email'])) 
     23if ((empty($_POST['_name']) || empty($_POST['_email'])) && empty($_GET['_framed'])) 
    2824  { 
    2925  show_message('formincomplete', 'warning'); 
     
    3228  } 
    3329 
     30// setup some vars we need 
     31$a_save_cols = array('name', 'firstname', 'surname', 'email'); 
     32$contacts_table = get_table_name('contacts'); 
    3433 
    3534// update an existing contact 
     
    4948  if (sizeof($a_write_sql)) 
    5049    { 
    51     $DB->query("UPDATE ".get_table_name('contacts')." 
     50    $DB->query("UPDATE $contacts_table 
    5251                SET    changed=now(), ".join(', ', $a_write_sql)." 
    5352                WHERE  contact_id=? 
     
    7170      $a_js_cols = array(); 
    7271   
    73       $sql_result = $DB->query("SELECT * FROM ".get_table_name('contacts')." 
     72      $sql_result = $DB->query("SELECT * FROM $contacts_table 
    7473                                WHERE  contact_id=? 
    7574                                AND    user_id=? 
     
    105104  { 
    106105  $a_insert_cols = $a_insert_values = array(); 
    107    
     106 
    108107  // check for existing contacts 
    109   $sql_result = $DB->query("SELECT 1 FROM ".get_table_name('contacts')." 
    110                             WHERE  user_id=? 
    111                             AND    email=? 
    112                             AND    del<>1", 
    113                            $_SESSION['user_id'], 
    114                            $_POST['_email']); 
     108  $sql = "SELECT 1 FROM $contacts_table 
     109          WHERE  user_id = {$_SESSION['user_id']} 
     110          AND del <> '1' "; 
     111 
     112  // get email and name, build sql for existing user check 
     113  if (isset($_GET['_emails']) && isset($_GET['_names'])) 
     114    { 
     115    $sql   .= "AND email IN ("; 
     116    $emails = explode(',', $_GET['_emails']); 
     117    $names  = explode(',', $_GET['_names']); 
     118    $count  = count($emails); 
     119    $n = 0; 
     120    foreach ($emails as $email) 
     121      { 
     122      $end  = (++$n == $count) ? '' : ','; 
     123      $sql .= $DB->quote(strip_tags($email)) . $end; 
     124      } 
     125    $sql .= ")"; 
     126    $ldap_form = true;  
     127    } 
     128  else if (isset($_POST['_email']))  
     129    $sql  .= "AND email = " . $DB->quote(strip_tags($_POST['_email'])); 
     130 
     131  $sql_result = $DB->query($sql); 
    115132 
    116133  // show warning message 
     
    118135    { 
    119136    show_message('contactexists', 'warning'); 
    120     $_action = 'add'; 
     137 
     138    if ($ldap_form) 
     139      rcmail_overwrite_action('ldappublicsearch'); 
     140    else 
     141      rcmail_overwrite_action('add'); 
     142 
    121143    return; 
    122144    } 
    123145 
    124   foreach ($a_save_cols as $col) 
    125     { 
    126     $fname = '_'.$col; 
    127     if (!isset($_POST[$fname])) 
    128       continue; 
    129      
    130     $a_insert_cols[] = $col; 
    131     $a_insert_values[] = $DB->quote(strip_tags($_POST[$fname])); 
    132     } 
    133      
    134   if (sizeof($a_insert_cols)) 
    135     { 
    136     $DB->query("INSERT INTO ".get_table_name('contacts')." 
     146  if ($ldap_form) 
     147    { 
     148    $n = 0;  
     149    foreach ($emails as $email)  
     150      { 
     151      $DB->query("INSERT INTO $contacts_table  
     152                 (user_id, name, email) 
     153                 VALUES ({$_SESSION['user_id']}," . $DB->quote(strip_tags($names[$n++])) . "," .  
     154                                      $DB->quote(strip_tags($email)) . ")"); 
     155      $insert_id[] = $DB->insert_id(); 
     156      } 
     157    } 
     158  else 
     159    { 
     160    foreach ($a_save_cols as $col) 
     161      { 
     162      $fname = '_'.$col; 
     163      if (!isset($_POST[$fname])) 
     164        continue; 
     165     
     166      $a_insert_cols[] = $col; 
     167      $a_insert_values[] = $DB->quote(strip_tags($_POST[$fname])); 
     168      } 
     169     
     170    if (sizeof($a_insert_cols)) 
     171      { 
     172      $DB->query("INSERT INTO $contacts_table 
    137173                (user_id, changed, del, ".join(', ', $a_insert_cols).") 
    138174                VALUES (?, now(), 0, ".join(', ', $a_insert_values).")", 
    139175                $_SESSION['user_id']); 
    140176                        
    141     $insert_id = $DB->insert_id(get_sequence_name('contacts')); 
     177      $insert_id = $DB->insert_id(get_sequence_name('contacts')); 
     178      } 
    142179    } 
    143180     
    144181  if ($insert_id) 
    145182    { 
    146     $_action = 'show'; 
    147     $_GET['_cid'] = $insert_id; 
    148  
    149     if ($_POST['_framed']) 
     183    if (!$ldap_form) 
     184      { 
     185      $_action = 'show'; 
     186      $_GET['_cid'] = $insert_id; 
     187 
     188      if ($_POST['_framed']) 
     189        { 
     190        // add contact row or jump to the page where it should appear 
     191        $commands = sprintf("if(parent.%s)parent.", $JS_OBJECT_NAME); 
     192        $sql_result = $DB->query("SELECT * FROM $contacts_table 
     193                                  WHERE  contact_id=? 
     194                                  AND    user_id=?", 
     195                                  $insert_id, 
     196                                  $_SESSION['user_id']); 
     197        $commands .= rcmail_js_contacts_list($sql_result, $JS_OBJECT_NAME); 
     198 
     199        $commands .= sprintf("if(parent.%s)parent.%s.select('%d');\n", 
     200                             $JS_OBJECT_NAME,  
     201                             $JS_OBJECT_NAME, 
     202                             $insert_id); 
     203       
     204        // update record count display 
     205        $commands .= sprintf("if(parent.%s)parent.%s.set_rowcount('%s');\n", 
     206                             $JS_OBJECT_NAME,  
     207                             $JS_OBJECT_NAME, 
     208                             rcmail_get_rowcount_text()); 
     209 
     210        $OUTPUT->add_script($commands); 
     211        } 
     212 
     213      // show confirmation 
     214      show_message('successfullysaved', 'confirmation');       
     215      } 
     216    else  
    150217      { 
    151218      // add contact row or jump to the page where it should appear 
    152       $commands = sprintf("if(parent.%s)parent.", $JS_OBJECT_NAME); 
    153       $sql_result = $DB->query("SELECT * FROM ".get_table_name('contacts')." 
    154                                 WHERE  contact_id=? 
    155                                 AND    user_id=?", 
    156                                 $insert_id, 
    157                                 $_SESSION['user_id']); 
    158       $commands .= rcmail_js_contacts_list($sql_result, $JS_OBJECT_NAME); 
    159  
     219      $commands = ''; 
     220      foreach ($insert_id as $id)  
     221        { 
     222        $sql_result = $DB->query("SELECT * FROM $contacts_table 
     223                                  WHERE  contact_id = $id 
     224                                  AND    user_id    = {$_SESSION['user_id']}"); 
     225         
     226        $commands .= sprintf("if(parent.%s)parent.", $JS_OBJECT_NAME); 
     227        $commands .= rcmail_js_contacts_list($sql_result, $JS_OBJECT_NAME); 
     228        $last_id = $id; 
     229        } 
     230 
     231      // display the last insert id 
    160232      $commands .= sprintf("if(parent.%s)parent.%s.select('%d');\n", 
    161                            $JS_OBJECT_NAME,  
    162                            $JS_OBJECT_NAME, 
    163                            $insert_id); 
    164        
     233                            $JS_OBJECT_NAME,  
     234                            $JS_OBJECT_NAME, 
     235                            $last_id); 
     236 
    165237      // update record count display 
    166238      $commands .= sprintf("if(parent.%s)parent.%s.set_rowcount('%s');\n", 
     
    170242 
    171243      $OUTPUT->add_script($commands); 
    172        
    173       // show confirmation 
    174       show_message('successfullysaved', 'confirmation');       
    175       } 
     244      rcmail_overwrite_action('ldappublicsearch'); 
     245      } 
     246 
     247    // show confirmation 
     248    show_message('successfullysaved', 'confirmation');       
    176249    } 
    177250  else 
     
    183256  } 
    184257 
    185  
    186258?> 
Note: See TracChangeset for help on using the changeset viewer.