Browse Source

Allow underscores in nicknames by changing id used in forms, add more labels for easy checkbox clicking, add compose to selected button

pdontthink 17 years ago
parent
commit
0b941500a8

+ 52 - 6
src/addressbook.php

@@ -34,6 +34,7 @@ require_once(SM_PATH . 'functions/forms.php');
 sqgetGlobalVar('addaddr',       $addaddr,       SQ_POST);
 sqgetGlobalVar('addaddr',       $addaddr,       SQ_POST);
 sqgetGlobalVar('editaddr',      $editaddr,      SQ_POST);
 sqgetGlobalVar('editaddr',      $editaddr,      SQ_POST);
 sqgetGlobalVar('deladdr',       $deladdr,       SQ_POST);
 sqgetGlobalVar('deladdr',       $deladdr,       SQ_POST);
+sqgetGlobalVar('compose_to',    $compose_to,    SQ_POST);
 sqgetGlobalVar('sel',           $sel,           SQ_POST);
 sqgetGlobalVar('sel',           $sel,           SQ_POST);
 sqgetGlobalVar('oldnick',       $oldnick,       SQ_POST);
 sqgetGlobalVar('oldnick',       $oldnick,       SQ_POST);
 sqgetGlobalVar('backend',       $backend,       SQ_POST);
 sqgetGlobalVar('backend',       $backend,       SQ_POST);
@@ -115,14 +116,14 @@ if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'P
             $orig_sel = $sel;
             $orig_sel = $sel;
             sort($sel);
             sort($sel);
 
 
-            /* The selected addresses are identidied by "nickname_backend". *
+            /* The selected addresses are identified by "backend_nickname". *
              * Sort the list and process one backend at the time            */
              * Sort the list and process one backend at the time            */
             $prevback  = -1;
             $prevback  = -1;
             $subsel    = array();
             $subsel    = array();
             $delfailed = false;
             $delfailed = false;
 
 
             for ($i = 0 ; (($i < sizeof($sel)) && !$delfailed) ; $i++) {
             for ($i = 0 ; (($i < sizeof($sel)) && !$delfailed) ; $i++) {
-                list($snick, $sbackend) = explode('_', $sel[$i]);
+                list($sbackend, $snick) = explode('_', $sel[$i], 2);
 
 
                 /* When we get to a new backend, process addresses in *
                 /* When we get to a new backend, process addresses in *
                  * previous one.                                      */
                  * previous one.                                      */
@@ -156,6 +157,47 @@ if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'P
                 $defselected  = $orig_sel;
                 $defselected  = $orig_sel;
             }
             }
 
 
+        /************************************************
+         * Compose to selected address(es)              *
+         ************************************************/
+        } else if ((!empty($compose_to)) && sizeof($sel) > 0) {
+            $orig_sel = $sel;
+            sort($sel);
+
+            // The selected addresses are identified by "backend_nickname"
+            $lookup_failed = false;
+            $send_to = '';
+
+            for ($i = 0 ; (($i < sizeof($sel)) && !$lookup_failed) ; $i++) {
+                list($sbackend, $snick) = explode('_', $sel[$i], 2);
+
+                $data = $abook->lookup($snick, $sbackend);
+
+                if (!$data) {
+                    $formerror = $abook->error;
+                    $lookup_failed = true;
+                    break;
+                } else {
+                    $addr = $abook->full_address($data);
+                    if (!empty($addr))
+                        $send_to .= $addr . ', ';
+                }
+            }
+
+
+            if ($lookup_failed || empty($send_to)) {
+                $showaddrlist = true;
+                $defselected  = $sel;
+            }
+
+
+            // send off to compose screen
+            else {
+                $send_to = trim($send_to, ', ');
+                header('Location: ' . $base_uri . 'src/compose.php?send_to=' . rawurlencode($send_to));
+                exit;
+            }
+
         } else {
         } else {
 
 
             /***********************************************
             /***********************************************
@@ -170,7 +212,7 @@ if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'P
                         $defselected = $sel;
                         $defselected = $sel;
                     } else {
                     } else {
                         $abortform = true;
                         $abortform = true;
-                        list($enick, $ebackend) = explode('_', current($sel));
+                        list($ebackend, $enick) = explode('_', current($sel), 2);
                         $olddata = $abook->lookup($enick, $ebackend);
                         $olddata = $abook->lookup($enick, $ebackend);
                         // Test if $olddata really contains anything and return an error message if it doesn't
                         // Test if $olddata really contains anything and return an error message if it doesn't
                         if (!$olddata) {
                         if (!$olddata) {
@@ -219,9 +261,10 @@ if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'P
                     $formerror = _("Please select address that you want to edit");
                     $formerror = _("Please select address that you want to edit");
                     $showaddrlist = true;
                     $showaddrlist = true;
                 } /* end of edit stage detection */
                 } /* end of edit stage detection */
-            } /* !empty($editaddr)                  - Update/modify address */
-        } /* (!empty($deladdr)) && sizeof($sel) > 0 - Delete address(es) */
-    } /* !empty($addaddr['nickname'])               - Add new address */
+            } /* !empty($editaddr)                     - Update/modify address */
+        } /* (!empty($deladdr)) && sizeof($sel) > 0    - Delete address(es) 
+          or (!empty($compose_to)) && sizeof($sel) > 0 - Compose to address(es) */
+    } /* !empty($addaddr['nickname'])                  - Add new address */
 
 
     // Some times we end output before forms are printed
     // Some times we end output before forms are printed
     if($abortform) {
     if($abortform) {
@@ -271,6 +314,9 @@ if ($showaddrlist) {
 //FIXME: Remove HTML from here!
 //FIXME: Remove HTML from here!
     echo addForm($form_url, 'post', 'address_book_form');
     echo addForm($form_url, 'post', 'address_book_form');
     
     
+    $oTemplate->assign('compose_new_win', $compose_new_win);
+    $oTemplate->assign('compose_height', $compose_height);
+    $oTemplate->assign('compose_width', $compose_width);
     $oTemplate->assign('addresses', $addresses);
     $oTemplate->assign('addresses', $addresses);
     $oTemplate->assign('current_backend', $current_backend);
     $oTemplate->assign('current_backend', $current_backend);
     $oTemplate->assign('backends', $list_backends);
     $oTemplate->assign('backends', $list_backends);

+ 6 - 1
templates/default/addrbook_addedit.tpl

@@ -5,6 +5,7 @@
  * Display the form elements to add/edit an entry in the address book
  * Display the form elements to add/edit an entry in the address book
  * 
  * 
  * The following variables are available in this template:
  * The following variables are available in this template:
+ *      $current_backend - integer containing backend currently displayed.
  *      $edit       - boolean TRUE if we are editing an existing address.
  *      $edit       - boolean TRUE if we are editing an existing address.
  *                    FALSE if the form is blank for adding a new address.
  *                    FALSE if the form is blank for adding a new address.
  *      $writable_backends - array of address book backends that can be written
  *      $writable_backends - array of address book backends that can be written
@@ -60,6 +61,7 @@ $formname = $edit ? 'editaddr' : 'addaddr';
     if (is_array($values['Email'])) {
     if (is_array($values['Email'])) {
         echo '<select name="'.$formname.'[email]" id="email">'."\n";
         echo '<select name="'.$formname.'[email]" id="email">'."\n";
         foreach ($values['Email'] as $email) {
         foreach ($values['Email'] as $email) {
+//FIXME: htmlspecialchars should not be needed inside any template files - I think values are already sanitized by the time they get here
             echo '<option value="'.htmlspecialchars($email).'">'.htmlspecialchars($email).'</option>'."\n";
             echo '<option value="'.htmlspecialchars($email).'">'.htmlspecialchars($email).'</option>'."\n";
         }
         }
         echo '</select>'."\n";
         echo '</select>'."\n";
@@ -105,7 +107,10 @@ $formname = $edit ? 'editaddr' : 'addaddr';
    <select name="backend" id="backend">
    <select name="backend" id="backend">
     <?php
     <?php
         foreach ($writable_backends as $id=>$name) {
         foreach ($writable_backends as $id=>$name) {
-            echo '<option value="'.$id.'">'.htmlspecialchars($name).'</option>'."\n";
+//FIXME: htmlspecialchars should not be needed inside any template files - I think values are already sanitized by the time they get here
+            echo '<option value="' . $id
+               . ($current_backend == $id ? '" selected="selected"' : '"')
+               . '>' . htmlspecialchars($name) . '</option>' . "\n";
         }
         }
     ?>
     ?>
    </select>
    </select>

+ 17 - 12
templates/default/addressbook_list.tpl

@@ -5,6 +5,10 @@
  * Template for the basic address book list
  * Template for the basic address book list
  * 
  * 
  * The following variables are available in this template:
  * The following variables are available in this template:
+ *      $compose_new_win - whether or not the user prefs are set to compose
+ *                         messages in a popup window
+ *      $compose_width   - width of popup compose window if needed
+ *      $compose_height  - height of popup compose window if needed
  *      $current_backend - integer containing backend currently displayed.
  *      $current_backend - integer containing backend currently displayed.
  *      $abook_select    - string containing HTML to display the address book
  *      $abook_select    - string containing HTML to display the address book
  *                         selection drop down
  *                         selection drop down
@@ -55,28 +59,29 @@ $colspan = $abook_has_extra_field ? 6 : 5;
 <div id="addressList">
 <div id="addressList">
 <table cellspacing="0">
 <table cellspacing="0">
  <tr>
  <tr>
-  <td colspan=<?php echo '"'.$colspan.'"'; ?> class="header1">
+  <td colspan="<?php echo $colspan; ?>" class="header1">
    <?php echo $source['BackendSource']; ?>
    <?php echo $source['BackendSource']; ?>
   </td>
   </td>
  </tr>
  </tr>
  <tr>
  <tr>
   <td colspan="3" class="abookButtons">
   <td colspan="3" class="abookButtons">
-   <input type="submit" value=<?php echo '"'._("Edit Selected").'"'; ?> name="editaddr" id="editaddr" />
-   <input type="submit" value=<?php echo '"'._("Delete Selected").'"'; ?> name="deladdr" id="deladdr" />
+   <input type="submit" value="<?php echo _("Edit Selected"); ?>" name="editaddr" id="editaddr" />
+   <input type="submit" value="<?php echo _("Delete Selected"); ?>" name="deladdr" id="deladdr" />
+   <input type="submit" value="<?php echo _("Compose to Selected") . ($javascript_on && $compose_new_win ? '" onclick="var send_to = \'\'; var f = document.forms.length; var i = 0; var grab_next_hidden = \'\'; while (i < f) { var e = document.forms[i].elements.length; var j = 0; while (j < e) { if (document.forms[i].elements[j].type == \'checkbox\' && document.forms[i].elements[j].checked) { var pos = document.forms[i].elements[j].value.indexOf(\'_\'); if (pos >= 1) { grab_next_hidden = document.forms[i].elements[j].value; } } else if (document.forms[i].elements[j].type == \'hidden\' && grab_next_hidden == document.forms[i].elements[j].name) { if (send_to != \'\') { send_to += \', \'; } send_to += document.forms[i].elements[j].value; } j++; } i++; } if (send_to != \'\') { comp_in_new(\''. $base_uri . 'src/compose.php?send_to=\' + send_to, ' . $compose_width . ', ' . $compose_height . '); } return false;"' : '"'); ?> name="compose_to" id="compose_to" />
    <?php if (!empty($plugin_output['address_book_navigation'])) echo $plugin_output['address_book_navigation']; ?>
    <?php if (!empty($plugin_output['address_book_navigation'])) echo $plugin_output['address_book_navigation']; ?>
   </td>
   </td>
-  <td colspan=<?php echo '"'.($colspan - 3).'"'; ?> class="abookSwitch">
+  <td colspan="<?php echo ($colspan - 3); ?>" class="abookSwitch">
    <?php
    <?php
     if (count($backends) > 0) {
     if (count($backends) > 0) {
         ?>
         ?>
    <select name="new_bnum">
    <select name="new_bnum">
     <?php
     <?php
         foreach ($backends as $id=>$name) {
         foreach ($backends as $id=>$name) {
-            echo '<option value="'.$id.'"'.($id==$current_backend ? ' selected="selected"' : '').'>'.$name.'</option>'."\n";
+            echo '<option value="' . $id . '"' . ($id == $current_backend ? ' selected="selected"' : '') . '>' . $name . '</option>' . "\n";
         }
         }
     ?>
     ?>
    </select>
    </select>
-   <input type="submit" value=<?php echo '"'._("Change").'"'; ?> name="change_abook" id="change_abook" />
+   <input type="submit" value="<?php echo _("Change"); ?>" name="change_abook" id="change_abook" />
         <?php
         <?php
     } else {
     } else {
         echo '&nbsp;';
         echo '&nbsp;';
@@ -102,14 +107,14 @@ $colspan = $abook_has_extra_field ? 6 : 5;
         echo '<tr><td class="abookEmpty" colspan="'.$colspan.'">'._("Address book is empty").'</td></tr>'."\n";
         echo '<tr><td class="abookEmpty" colspan="'.$colspan.'">'._("Address book is empty").'</td></tr>'."\n";
     }
     }
     foreach ($source['Addresses'] as $contact) {
     foreach ($source['Addresses'] as $contact) {
-        $id = $contact['NickName'] .'_'. $current_backend;
+        $id = $current_backend . '_' . $contact['NickName'];
         ?>
         ?>
- <tr class=<?php echo '"'.($count%2 ? 'even' : 'odd').'"'; ?>>
+ <tr class="<?php echo ($count%2 ? 'even' : 'odd'); ?>">
   <td class="abookField" style="width:1%"><?php echo ($source['BackendWritable'] ? '<input type="checkbox" name="sel[' . $count . ']" value="'.$id.'" id="'.$id.'" ' . (!empty($plugin_output['address_book_checkbox_extra']) ? $plugin_output['address_book_checkbox_extra'] : '') . ' />' : ''); ?></td>
   <td class="abookField" style="width:1%"><?php echo ($source['BackendWritable'] ? '<input type="checkbox" name="sel[' . $count . ']" value="'.$id.'" id="'.$id.'" ' . (!empty($plugin_output['address_book_checkbox_extra']) ? $plugin_output['address_book_checkbox_extra'] : '') . ' />' : ''); ?></td>
-  <td class="abookField" style="width:15%"><label for=<?php echo '"'.$id.'"'; ?>><?php echo $contact['NickName']; ?></label></td>
-  <td class="abookField"><?php echo $contact['FullName']; ?></td>
-  <td class="abookField"><?php echo composeLink($contact); ?></td>
-  <td class="abookField"><?php echo $contact['Info']; ?></td>
+  <td class="abookField" style="width:15%"><label for="<?php echo $id . '">' . $contact['NickName']; ?></label></td>
+  <td class="abookField"><label for="<?php echo $id . '">' . $contact['FullName']; ?></label></td>
+  <td class="abookField"><input type="hidden" name="<?php echo $id; ?>" value="<?php echo rawurlencode($contact['FullAddress']); ?>" /><?php echo composeLink($contact); ?></td>
+  <td class="abookField"><label for="<?php echo $id . '">' . $contact['Info']; ?></label></td>
         <?php 
         <?php 
         if ($abook_has_extra_field) {
         if ($abook_has_extra_field) {
             echo '<td class="abookField">'.$contact['Extra'].'</td>'."\n";
             echo '<td class="abookField">'.$contact['Extra'].'</td>'."\n";