Move search templates to separate directory.
authorJan Schneider <jan@horde.org>
Wed, 9 Jun 2010 17:31:09 +0000 (19:31 +0200)
committerJan Schneider <jan@horde.org>
Mon, 5 Jul 2010 10:34:43 +0000 (12:34 +0200)
turba/search.php
turba/templates/browse/search.inc [deleted file]
turba/templates/browse/search_criteria.inc [deleted file]
turba/templates/browse/search_vbook.inc [deleted file]
turba/templates/search/advanced.inc [new file with mode: 0644]
turba/templates/search/basic.inc [new file with mode: 0644]
turba/templates/search/header.inc [new file with mode: 0644]
turba/templates/search/vbook.inc [new file with mode: 0644]

index 5a71ad7..8769e91 100644 (file)
@@ -8,6 +8,7 @@
  * did not receive this file, see http://www.horde.org/licenses/asl.php.
  *
  * @author Chuck Hagenbuch <chuck@horde.org>
+ * @author Jan Schneider <jan@horde.org>
  */
 
 /**
@@ -75,7 +76,8 @@ Horde_Registry::appInit('turba');
 if (Horde_Util::getFormData('search_mode')) {
     $_SESSION['turba']['search_mode'] = Horde_Util::getFormData('search_mode');
 }
-if (!isset($_SESSION['turba']['search_mode'])) {
+if (!isset($_SESSION['turba']['search_mode']) ||
+    !in_array($_SESSION['turba']['search_mode'], array('basic', 'advanced'))) {
     $_SESSION['turba']['search_mode'] = 'basic';
 }
 
@@ -188,11 +190,9 @@ Horde::addScriptFile('effects.js', 'horde');
 Horde::addScriptFile('redbox.js', 'horde');
 require TURBA_TEMPLATES . '/common-header.inc';
 require TURBA_TEMPLATES . '/menu.inc';
-require TURBA_TEMPLATES . '/browse/search.inc';
-if ($_SESSION['turba']['search_mode'] == 'advanced') {
-    require TURBA_TEMPLATES . '/browse/search_criteria.inc';
-}
-require TURBA_TEMPLATES . '/browse/search_vbook.inc';
+require TURBA_TEMPLATES . '/search/header.inc';
+require TURBA_TEMPLATES . '/search/' . $_SESSION['turba']['search_mode'] . '.inc';
+require TURBA_TEMPLATES . '/search/vbook.inc';
 if (isset($view) && is_object($view)) {
     require TURBA_TEMPLATES . '/browse/javascript.inc';
     require TURBA_TEMPLATES . '/browse/header.inc';
diff --git a/turba/templates/browse/search.inc b/turba/templates/browse/search.inc
deleted file mode 100644 (file)
index 83188bb..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-<?php
-/* Build the directory sources select widget. */
-$source_options = '';
-$criteria_options = '';
-$js_criteria = "var criteriaOptions = [];\n"
-    . "var shareSources = [];\n";
-
-$source_count = 0;
-foreach (Turba::getAddressBooks() as $key => $entry) {
-    $js_criteria .= "criteriaOptions[$source_count] = []\n"
-        . "criteriaOptions[$source_count][0] = '$key';\n";
-
-    /* Build the criteria select widget. */
-    $field_count = 1;
-    foreach ($entry['search'] as $field) {
-        $js_criteria .= "criteriaOptions[$source_count][$field_count] = ['$field', '" . $GLOBALS['attributes'][$field]['label'] . "'];\n";
-        if ($key == $source) {
-            $selected = ($criteria == $field) ? ' selected="selected"' : '';
-            $criteria_options .= "<option value=\"$field\"$selected>" .
-                htmlspecialchars($GLOBALS['attributes'][$field]['label']) . "</option>\n";
-        }
-        $field_count++;
-    }
-
-    $selected = ($key == $source) ? ' selected="selected"' : '';
-    $source_options .= "<option value=\"$key\"$selected>"
-        . htmlspecialchars($entry['title']) . "</option>\n";
-
-    $unique_source = $key;
-    $source_count++;
-
-    /* Remember vbooks and sources that are using shares. */
-    if ($entry['type'] != 'vbook') {
-        $js_criteria .= "shareSources['$key'] = true;\n";
-    } else {
-        $js_criteria .= "shareSources['$key'] = false;\n";
-    }
-}
-
-/* Build search mode tabs. */
-$sUrl = Horde::applicationUrl('search.php');
-$vars = Horde_Variables::getDefaultVariables();
-$tabs = new Horde_Ui_Tabs('search_mode', $vars);
-$tabs->addTab(_("Basic Search"), $sUrl, 'basic');
-$tabs->addTab(_("Advanced Search"), $sUrl, 'advanced');
-echo $tabs->render($_SESSION['turba']['search_mode']);
-
-?>
-<div class="text" style="padding:1em">
-<form name="directory_search" action="search.php" method="get" onsubmit="RedBox.loading(); return true;">
-<?php echo Horde_Util::formInput() ?>
-<?php if ($source_count == 1): ?>
- <input type="hidden" name="source" value="<?php echo $unique_source ?>" />
-<?php endif; ?>
-
-<?php if ($_SESSION['turba']['search_mode'] == 'basic'): ?>
-<script type="text/javascript">
-<?php echo $js_criteria ?>
-function updateCriteria()
-{
-    var f = document.directory_search;
-    if (!f.source.options) {
-        return;
-    }
-
-    while (f.criteria.length > 0) {
-        f.criteria.options[f.criteria.length - 1] = null;
-    }
-
-    var index = f.source.selectedIndex;
-    if (!index) {
-        index = 0;
-    }
-
-    for (var i = 0; i < criteriaOptions.length; i++) {
-        if (criteriaOptions[i][0] == f.source.options[index].value) {
-            for (var j = 1; j < criteriaOptions[i].length; j++) {
-                f.criteria.options[f.criteria.length] = new Option(criteriaOptions[i][j][1], criteriaOptions[i][j][0]);
-            }
-            f.criteria.selectedIndex = 0;
-            if ($('vbook-form')) {
-                if (shareSources[criteriaOptions[i][0]] == true) {
-                    Element.show('vbook-form');
-                } else {
-                    Element.hide('vbook-form');
-                }
-            }
-            return;
-        }
-    }
-}
-Event.observe(window, 'load', updateCriteria);
-</script>
-
-<?php if ($source_count > 1): ?>
- <strong><?php echo Horde::label('source', _("From")) ?></strong>
- <select id="source" name="source" onchange="updateCriteria();">
-  <?php echo $source_options ?>
- </select>
-<?php endif; ?>
-
- <strong><?php echo Horde::label('criteria', _("Find")) ?></strong>
- <select id="criteria" name="criteria">
-  <?php echo $criteria_options ?>
- </select>
-
- <strong><?php echo Horde::label('val', _("Matching")) ?></strong>
- <input type="text" size="30" id="val" name="val" value="<?php echo htmlspecialchars($val) ?>" />
- <input class="button" type="submit" name="search" value="<?php echo _("Search") ?>" />
-
-<?php else: ?>
-
-<table cellspacing="5" width="100%">
- <tr>
-  <td>&nbsp;</td>
-  <td>
-   <input type="submit" class="button" name="search" value="<?php echo _("Search") ?>" />
-   <input type="reset" class="button" name="reset" value="<?php echo _("Reset to Defaults") ?>" />
-  </td>
- </tr>
- <?php if ($source_count > 1): ?>
- <tr>
-  <td class="rightAlign"><strong><?php echo Horde::label('source', _("Address Book")) ?></strong></td>
-  <td class="leftAlign">
-   <select id="source" name="source" onchange="directory_search.submit()">
-    <?php echo $source_options ?>
-   </select>
-  </td>
- </tr>
- <?php endif; ?>
-<?php endif; ?>
diff --git a/turba/templates/browse/search_criteria.inc b/turba/templates/browse/search_criteria.inc
deleted file mode 100644 (file)
index 931fe61..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-foreach ($map as $name => $v) {
-    if (substr($name, 0, 2) != '__') {
-?>
- <tr>
-  <td width="1%" class="nowrap rightAlign" ><strong><?php echo Horde::label($name, $GLOBALS['attributes'][$name]['label']) ?></strong></td>
-  <td class="leftAlign"><input type="text" size="30" id="<?php echo $name ?>" name="<?php echo $name ?>" value="<?php echo isset($criteria[$name]) ? htmlspecialchars($criteria[$name]) : '' ?>" /></td>
- </tr>
-<?php
-    }
-}
-?>
-</table>
diff --git a/turba/templates/browse/search_vbook.inc b/turba/templates/browse/search_vbook.inc
deleted file mode 100644 (file)
index 087fdcb..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<?php if (!empty($_SESSION['turba']['has_share'])): ?>
- <div id="vbook-form"<?php if (is_a($driver, 'Turba_Driver_vbook')) echo ' style="display:none"' ?>>
-  <input type="checkbox" id="save-vbook" name="save_vbook" />
-  <strong><?php echo Horde::label('save-vbook', _("Save search as a virtual address book?")) ?></strong>
-
-  <?php echo Horde::label('vbook_name', _("Name:")) ?>
-  <input type="text" id="vbook_name" name="vbook_name" />
-  <script type="text/javascript">
-  Event.observe($('vbook_name'), 'keyup', function() {
-      $('save-vbook').checked = $F('vbook_name') ? true : false;
-  });
-  </script>
- </div>
-<?php endif; ?>
-</form>
-</div>
-<br />
diff --git a/turba/templates/search/advanced.inc b/turba/templates/search/advanced.inc
new file mode 100644 (file)
index 0000000..b173e33
--- /dev/null
@@ -0,0 +1,31 @@
+<table cellspacing="5" width="100%">
+ <tr>
+  <td>&nbsp;</td>
+  <td>
+   <input type="submit" class="button" name="search" value="<?php echo _("Search") ?>" />
+   <input type="reset" class="button" name="reset" value="<?php echo _("Reset to Defaults") ?>" />
+  </td>
+ </tr>
+ <?php if ($source_count > 1): ?>
+ <tr>
+  <td class="rightAlign"><strong><?php echo Horde::label('source', _("Address Book")) ?></strong></td>
+  <td class="leftAlign">
+   <select id="source" name="source" onchange="directory_search.submit()">
+    <?php echo $source_options ?>
+   </select>
+  </td>
+ </tr>
+<?php endif; ?>
+<?php
+foreach ($map as $name => $v) {
+    if (substr($name, 0, 2) != '__') {
+?>
+ <tr>
+  <td width="1%" class="nowrap rightAlign" ><strong><?php echo Horde::label($name, $GLOBALS['attributes'][$name]['label']) ?></strong></td>
+  <td class="leftAlign"><input type="text" size="30" id="<?php echo $name ?>" name="<?php echo $name ?>" value="<?php echo isset($criteria[$name]) ? htmlspecialchars($criteria[$name]) : '' ?>" /></td>
+ </tr>
+<?php
+    }
+}
+?>
+</table>
diff --git a/turba/templates/search/basic.inc b/turba/templates/search/basic.inc
new file mode 100644 (file)
index 0000000..f20cc85
--- /dev/null
@@ -0,0 +1,53 @@
+<script type="text/javascript">
+<?php echo $js_criteria ?>
+function updateCriteria()
+{
+    var f = document.directory_search;
+    if (!f.source.options) {
+        return;
+    }
+
+    while (f.criteria.length > 0) {
+        f.criteria.options[f.criteria.length - 1] = null;
+    }
+
+    var index = f.source.selectedIndex;
+    if (!index) {
+        index = 0;
+    }
+
+    for (var i = 0; i < criteriaOptions.length; i++) {
+        if (criteriaOptions[i][0] == f.source.options[index].value) {
+            for (var j = 1; j < criteriaOptions[i].length; j++) {
+                f.criteria.options[f.criteria.length] = new Option(criteriaOptions[i][j][1], criteriaOptions[i][j][0]);
+            }
+            f.criteria.selectedIndex = 0;
+            if ($('vbook-form')) {
+                if (shareSources[criteriaOptions[i][0]] == true) {
+                    Element.show('vbook-form');
+                } else {
+                    Element.hide('vbook-form');
+                }
+            }
+            return;
+        }
+    }
+}
+Event.observe(window, 'load', updateCriteria);
+</script>
+
+<?php if ($source_count > 1): ?>
+ <strong><?php echo Horde::label('source', _("From")) ?></strong>
+ <select id="source" name="source" onchange="updateCriteria();">
+  <?php echo $source_options ?>
+ </select>
+<?php endif; ?>
+
+ <strong><?php echo Horde::label('criteria', _("Find")) ?></strong>
+ <select id="criteria" name="criteria">
+  <?php echo $criteria_options ?>
+ </select>
+
+ <strong><?php echo Horde::label('val', _("Matching")) ?></strong>
+ <input type="text" size="30" id="val" name="val" value="<?php echo htmlspecialchars($val) ?>" />
+ <input class="button" type="submit" name="search" value="<?php echo _("Search") ?>" />
diff --git a/turba/templates/search/header.inc b/turba/templates/search/header.inc
new file mode 100644 (file)
index 0000000..b3a1a4e
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+/* Build the directory sources select widget. */
+$source_options = '';
+$criteria_options = '';
+$js_criteria = "var criteriaOptions = [];\n"
+    . "var shareSources = [];\n";
+
+$source_count = 0;
+foreach (Turba::getAddressBooks() as $key => $entry) {
+    $js_criteria .= "criteriaOptions[$source_count] = []\n"
+        . "criteriaOptions[$source_count][0] = '$key';\n";
+
+    /* Build the criteria select widget. */
+    $field_count = 1;
+    foreach ($entry['search'] as $field) {
+        $js_criteria .= "criteriaOptions[$source_count][$field_count] = ['$field', '" . $GLOBALS['attributes'][$field]['label'] . "'];\n";
+        if ($key == $source) {
+            $selected = ($criteria == $field) ? ' selected="selected"' : '';
+            $criteria_options .= "<option value=\"$field\"$selected>" .
+                htmlspecialchars($GLOBALS['attributes'][$field]['label']) . "</option>\n";
+        }
+        $field_count++;
+    }
+
+    $selected = ($key == $source) ? ' selected="selected"' : '';
+    $source_options .= "<option value=\"$key\"$selected>"
+        . htmlspecialchars($entry['title']) . "</option>\n";
+
+    $unique_source = $key;
+    $source_count++;
+
+    /* Remember vbooks and sources that are using shares. */
+    if ($entry['type'] != 'vbook') {
+        $js_criteria .= "shareSources['$key'] = true;\n";
+    } else {
+        $js_criteria .= "shareSources['$key'] = false;\n";
+    }
+}
+
+/* Build search mode tabs. */
+$sUrl = Horde::applicationUrl('search.php');
+$vars = Horde_Variables::getDefaultVariables();
+$tabs = new Horde_Ui_Tabs('search_mode', $vars);
+$tabs->addTab(_("Basic Search"), $sUrl, 'basic');
+$tabs->addTab(_("Advanced Search"), $sUrl, 'advanced');
+echo $tabs->render($_SESSION['turba']['search_mode']);
+
+?>
+<div class="text" style="padding:1em">
+<form name="directory_search" action="search.php" method="get" onsubmit="RedBox.loading(); return true;">
+<?php echo Horde_Util::formInput() ?>
+<?php if ($source_count == 1): ?>
+ <input type="hidden" name="source" value="<?php echo $unique_source ?>" />
+<?php endif; ?>
diff --git a/turba/templates/search/vbook.inc b/turba/templates/search/vbook.inc
new file mode 100644 (file)
index 0000000..087fdcb
--- /dev/null
@@ -0,0 +1,17 @@
+<?php if (!empty($_SESSION['turba']['has_share'])): ?>
+ <div id="vbook-form"<?php if (is_a($driver, 'Turba_Driver_vbook')) echo ' style="display:none"' ?>>
+  <input type="checkbox" id="save-vbook" name="save_vbook" />
+  <strong><?php echo Horde::label('save-vbook', _("Save search as a virtual address book?")) ?></strong>
+
+  <?php echo Horde::label('vbook_name', _("Name:")) ?>
+  <input type="text" id="vbook_name" name="vbook_name" />
+  <script type="text/javascript">
+  Event.observe($('vbook_name'), 'keyup', function() {
+      $('save-vbook').checked = $F('vbook_name') ? true : false;
+  });
+  </script>
+ </div>
+<?php endif; ?>
+</form>
+</div>
+<br />