[ Index ]
 

Code source de IMP H3 (4.1.5)

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/templates/prefs/ -> sourceselect.inc (source)

   1  <?php
   2  if ($registry->hasMethod('contacts/sources')) {
   3      $selected = explode("\t", $prefs->getValue('search_sources'));
   4      $readable = $registry->call('contacts/sources');
   5      $writeable = $registry->call('contacts/sources', true);
   6  
   7      $nbReadSources = count(array_keys($readable));
   8      $nbWriteSources = count(array_keys($writeable));
   9  
  10      if (count($selected) == 1 && empty($selected[0])) {
  11          $selected = array();
  12      }
  13  
  14      if ($nbReadSources == 1) {
  15          // Only one source, no need to display the selection widget
  16          $selected = array_keys($readable);
  17          $readSelect = '';
  18      }
  19  
  20      $prefSelect = '';
  21      foreach ($selected as $source) {
  22          if (!empty($readable[$source])) {
  23              $prefSelect .= '<option value="' . $source . '">' . $readable[$source] . "</option>\n";
  24          }
  25      }
  26  
  27      $readSelect = '';
  28      if (!is_a($readable, 'PEAR_Error') && is_array($readable)) {
  29          foreach (array_diff(array_keys($readable), $selected) as $source) {
  30              $readSelect .= '<option value="' . $source . '">' . $readable[$source] . "</option>\n";
  31          }
  32      }
  33  
  34      if (!is_a($writeable, 'PEAR_Error') && is_array($writeable)) {
  35          $writeSelect = '<option value="">' . _("None") . '</option>' . "\n";
  36          $writeSource = '';
  37          foreach ($writeable as $source => $name) {
  38              $sel = $prefs->getValue('add_source') == $source ? ' selected="selected"' : '';
  39              $writeSelect .= '<option value="' . $source . '"' . "$sel>" . $name . "</option>\n";
  40              $writeSource = $source;
  41          }
  42      }
  43  
  44      $selected_fields = array();
  45      $search_field_pref = $prefs->getValue('search_fields');
  46      if (!empty($search_field_pref)) {
  47          $selected_fields = explode("\n", $prefs->getValue('search_fields'));
  48          foreach ($selected_fields as $field) {
  49              $field = trim($field);
  50              if (!empty($field)) {
  51                  $tmp = explode("\t", $field);
  52                  if (count($tmp) > 1) {
  53                      $source = array_splice($tmp, 0, 1);
  54                      $selected_fields[$source[0]] = $tmp;
  55                  }
  56              }
  57          }
  58      }
  59  
  60      $search_fields = array();
  61      if (!is_a($readable, 'PEAR_Error') && is_array($readable)) {
  62          foreach (array_keys($readable) as $source) {
  63              $search_fields[$source] = $registry->call('contacts/fields', $source);
  64          }
  65      }
  66  
  67      $js = "var searchFields = new Array();\n";
  68      $source_count = 0;
  69      foreach ($search_fields as $source => $fields) {
  70          $js .= "searchFields[$source_count] = new Array();\n";
  71          $js .= "searchFields[$source_count][0] = '$source';\n";
  72  
  73          $field_count = 1;
  74          foreach ($fields as $field) {
  75              if ($field['search']) {
  76                  $marked = isset($selected_fields[$source]) && in_array($field['name'], $selected_fields[$source]) ? 'true' : 'false';
  77                  $js .= "searchFields[$source_count][$field_count] = new Array('" . $field['name'] . "', '" . $field['label'] . "', $marked);\n";
  78                  $field_count++;
  79              }
  80          }
  81  
  82          $source_count++;
  83      }
  84  }
  85  ?>
  86  
  87  <?php if (!$prefs->isLocked('search_sources') && (!empty($readSelect) || !empty($prefSelect))): ?>
  88  <script type="text/javascript">
  89  <!--
  90  function deselectHeaders()
  91  {
  92      document.prefs.unselected_search_sources[0].selected = false;
  93      document.prefs.selected_search_sources[0].selected = false;
  94  }
  95  
  96  function resetHidden()
  97  {
  98      var tmp = '';
  99      for (i = 1; i < document.prefs.selected_search_sources.length; i++) {
 100          tmp += document.prefs.selected_search_sources[i].value;
 101          if (i < document.prefs.selected_search_sources.length - 1)
 102              tmp += "\t";
 103      }
 104  
 105      document.prefs.search_sources.value = tmp;
 106  }
 107  
 108  function addSource()
 109  {
 110      for (i = 1; i < document.prefs.unselected_search_sources.length; i++) {
 111          if (document.prefs.unselected_search_sources[i].selected) {
 112              document.prefs.selected_search_sources[document.prefs.selected_search_sources.length] = new Option(document.prefs.unselected_search_sources[i].text, document.prefs.unselected_search_sources[i].value);
 113              document.prefs.unselected_search_sources[i] = null;
 114              i--;
 115          }
 116      }
 117  
 118      resetHidden();
 119  }
 120  
 121  function removeSource()
 122  {
 123      for (i = 1; i < document.prefs.selected_search_sources.length; i++) {
 124          if (document.prefs.selected_search_sources[i].selected) {
 125              document.prefs.unselected_search_sources[document.prefs.unselected_search_sources.length] = new Option(document.prefs.selected_search_sources[i].text, document.prefs.selected_search_sources[i].value)
 126              document.prefs.selected_search_sources[i] = null;
 127              i--;
 128          }
 129      }
 130  
 131      resetHidden();
 132  }
 133  
 134  function moveSourceUp()
 135  {
 136      var sel = document.prefs.selected_search_sources.selectedIndex;
 137  
 138      if (sel == -1 || document.prefs.selected_search_sources.length <= 2) return;
 139  
 140      // deselect everything but the first selected item
 141      document.prefs.selected_search_sources.selectedIndex = sel;
 142  
 143      if (sel == 1) {
 144          tmp = document.prefs.selected_search_sources[sel];
 145          document.prefs.selected_search_sources[sel] = null;
 146          document.prefs.selected_search_sources[document.prefs.selected_search_sources.length] = tmp;
 147          document.prefs.selected_search_sources.selectedIndex = document.prefs.selected_search_sources.length - 1;
 148      } else {
 149          tmp = new Array();
 150  
 151          for (i = 1; i < document.prefs.selected_search_sources.length; i++) {
 152              tmp[i - 1] = new Option(document.prefs.selected_search_sources[i].text, document.prefs.selected_search_sources[i].value)
 153          }
 154  
 155          for (i = 0; i < tmp.length; i++) {
 156              if (i + 1 == sel - 1) {
 157                  document.prefs.selected_search_sources[i + 1] = tmp[i + 1];
 158              } else if (i + 1 == sel) {
 159                  document.prefs.selected_search_sources[i + 1] = tmp[i - 1];
 160              } else {
 161                  document.prefs.selected_search_sources[i + 1] = tmp[i];
 162              }
 163          }
 164  
 165          document.prefs.selected_search_sources.selectedIndex = sel - 1;
 166      }
 167  
 168      resetHidden();
 169  }
 170  
 171  function moveSourceDown()
 172  {
 173      var sel = document.prefs.selected_search_sources.selectedIndex;
 174  
 175      if (sel == -1 || document.prefs.selected_search_sources.length <= 2) return;
 176  
 177      // deselect everything but the first selected item
 178      document.prefs.selected_search_sources.selectedIndex = sel;
 179  
 180      if (sel == document.prefs.selected_search_sources.length - 1) {
 181          tmp = new Array();
 182  
 183          for (i = 1; i < document.prefs.selected_search_sources.length; i++) {
 184              tmp[i - 1] = new Option(document.prefs.selected_search_sources[i].text, document.prefs.selected_search_sources[i].value)
 185          }
 186  
 187          document.prefs.selected_search_sources[1] = tmp[tmp.length - 1];
 188          for (i = 0; i < tmp.length - 1; i++) {
 189              document.prefs.selected_search_sources[i + 2] = tmp[i];
 190          }
 191  
 192          document.prefs.selected_search_sources.selectedIndex = 1;
 193      } else {
 194          tmp = new Array();
 195  
 196          for (i = 1; i < document.prefs.selected_search_sources.length; i++) {
 197              tmp[i - 1] = new Option(document.prefs.selected_search_sources[i].text, document.prefs.selected_search_sources[i].value)
 198          }
 199  
 200          for (i = 0; i < tmp.length; i++) {
 201              if (i + 1 == sel) {
 202                  document.prefs.selected_search_sources[i + 1] = tmp[i + 1];
 203              } else if (i + 1 == sel + 1) {
 204                  document.prefs.selected_search_sources[i + 1] = tmp[i - 1];
 205              } else {
 206                  document.prefs.selected_search_sources[i + 1] = tmp[i];
 207              }
 208          }
 209  
 210          document.prefs.selected_search_sources.selectedIndex = sel + 1;
 211      }
 212  
 213      resetHidden();
 214  }
 215  
 216  <?php echo $js ?>
 217  
 218  var selectedIndex = false;
 219  var selectedValue = false;
 220  var nbSources = <?php echo $nbReadSources ?>;
 221  <?php if ($nbReadSources == 1): ?>
 222  selectedIndex = 1;
 223  selectedValue = "<?php echo $selected[0] ?>";
 224  <?php endif; ?>
 225  
 226  function updateSearchFields()
 227  {
 228      var f = document.prefs;
 229      <?php if ($nbReadSources > 1): ?>
 230      selectedIndex = f.selected_search_sources.selectedIndex;
 231      <?php endif; ?>
 232      var fieldString = '';
 233  
 234      while (f.search_fields.length > 0) {
 235          f.search_fields.options[f.search_fields.length-1] = null;
 236      }
 237  
 238      if (selectedIndex < 1) {
 239          return;
 240      }
 241  
 242      <?php if ($nbReadSources > 1): ?>
 243      selectedValue = f.selected_search_sources.options[selectedIndex].value;
 244      <?php endif; ?>
 245  
 246      for (var i = 0; i < searchFields.length; i++) {
 247          if (i > 0) {
 248              fieldString += "\n";
 249          }
 250          fieldString += searchFields[i][0];
 251          for (var j = 1; j < searchFields[i].length; j++) {
 252              if (searchFields[i][j][2]) {
 253                  fieldString += "\t" + searchFields[i][j][0];
 254              }
 255  
 256              if (searchFields[i][0] == selectedValue) {
 257                  f.search_fields.options[f.search_fields.length] = new Option(searchFields[i][j][1], searchFields[i][j][0]);
 258                  if (searchFields[i][j][2]) {
 259                      f.search_fields.options[f.search_fields.length - 1].selected = true;
 260                  }
 261              }
 262          }
 263      }
 264  
 265      f.search_fields_string.value = fieldString;
 266  }
 267  
 268  function changeSearchFields()
 269  {
 270      var f = document.prefs;
 271      <?php if ($nbReadSources > 1): ?>
 272      selectedIndex = f.selected_search_sources.selectedIndex;
 273      selectedValue = f.selected_search_sources.options[selectedIndex].value;
 274      <?php endif; ?>
 275  
 276      for (var i = 0; i < searchFields.length; i++) {
 277          if (searchFields[i][0] == selectedValue) {
 278              for (var j = 1; j < searchFields[i].length; j++) {
 279                  searchFields[i][j][2] = f.search_fields.options[j - 1].selected;
 280              }
 281              updateSearchFields();
 282              return;
 283          }
 284      }
 285  }
 286  
 287  // -->
 288  </script>
 289  
 290  <br />
 291  <input type="hidden" name="search_sources" value="<?php echo implode("\t", $selected) ?>" />
 292  <?php if ($nbReadSources > 1): ?>
 293  <?php echo _("Choose the order of address books to search when expanding addresses.") ?><br />
 294  <table>
 295   <tr>
 296    <td>
 297     <select name="unselected_search_sources" multiple="multiple" size="5" width="20" onchange="deselectHeaders()">
 298      <option value=""><?php echo _("Available Address books:") ?></option>
 299      <?php echo $readSelect ?>
 300     </select>
 301    </td>
 302    <td>
 303     <a href="" onclick="addSource(); return false;"><?php echo Horde::img(isset($GLOBALS['nls']['rtl'][$GLOBALS['language']]) ? 'lhand.png' : 'rhand.png', _("Add source"), null, $registry->getImageDir('horde')) ?></a>
 304     <br />
 305     <a href="" onclick="removeSource(); return false;"><?php echo Horde::img(isset($GLOBALS['nls']['rtl'][$GLOBALS['language']]) ? 'rhand.png' : 'lhand.png', _("Remove source"), null, $registry->getImageDir('horde')) ?></a>
 306    </td>
 307    <td>
 308     <select name="selected_search_sources" multiple="multiple" size="5" width="20" onchange="deselectHeaders();updateSearchFields();">
 309      <option value=""><?php echo _("Selected Address books:") ?></option>
 310      <?php echo $prefSelect ?>
 311     </select>
 312    </td>
 313    <td>
 314     <a href="" onclick="moveSourceUp(); return false;"><?php echo Horde::img('nav/up.png', _("Move up"), null, $registry->getImageDir('horde')) ?></a>
 315     <br />
 316     <a href="" onclick="moveSourceDown(); return false;"><?php echo Horde::img('nav/down.png', _("Move down"), null, $registry->getImageDir('horde')) ?></a>
 317    </td>
 318   </tr>
 319  </table>
 320  
 321  <?php echo _("Click on one of your selected address books and then select all fields to search.") ?><br />
 322  <?php else: ?>
 323  <?php echo _("Select all fields to search when expanding addresses.") ?><br />
 324  <?php endif; ?>
 325  
 326  <?php echo _("To select multiple fields, hold down the Control (PC) or Command (Mac) while clicking.") ?><br />
 327  <input type="hidden" name="search_fields_string" />
 328  <table>
 329   <tr>
 330    <td>
 331     <select name="search_fields" multiple="multiple" size="5" width="20" onchange="changeSearchFields()">
 332      <option><?php echo str_repeat('&nbsp;', 50) ?></option>
 333     </select>
 334    </td>
 335   </tr>
 336  </table>
 337  
 338  <script type="text/javascript">
 339  <!--
 340  updateSearchFields();
 341  // -->
 342  </script>
 343  
 344  <?php endif; ?>
 345  
 346  
 347  <?php if (!$prefs->isLocked('add_source') && !empty($writeSelect)): ?>
 348  
 349    <?php echo _("Choose the address book to use when adding addresses.") ?><br />
 350    <br />
 351    <select name="add_source"><?php echo $writeSelect ?></select>
 352  
 353  <?php endif; ?>


Généré le : Thu Nov 29 12:30:07 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics