summaryrefslogtreecommitdiff
path: root/fs_selfservice/fri/includes/display.php
blob: 41d8dc5f0f6072269dd2d88fbbd2810000df6815 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php

/**
 * @file
 * Functions common to display
 */

/**
  * Display 
  */
class Display {

  /**
   * display constructor 
   */
  function Display() {
  }

  /**
   * display text header
   *
   * @param $text
   *   Header text to display
   */
  function displayHeaderText($text) {

    $ret = "<h2>" . $text . "</h2>
            <br>";

    return $ret;
  }

  /**
   * displays header line 
   */
  function displayLine() {

    $ret = "
      <div id='line'>
        <div class='spacer'></div>
        <div class='spacer'></div>
      </div>
      <br>";

    return $ret;
  }
}  

/**
  * DisplaySearch  
  */
class DisplaySearch extends Display {

  /**
   * Constructor
   */
  function DisplaySearch() {
  }

  /**
   * displays search controls
   *
   * @param $align
   *   where to align the control
   * @param $q
   *   search query
   * @param $focus
   *   whether to focus control on this block
   */
  function displaySearchBlock($align,$m,$q,$url_opts,$focus) {

    // align
    if ($align=='center') {
      $alignText = "class='bar_center'";
    }
    else {
      $alignText = "class='bar_left'";
    }

    // url options
    foreach ($url_opts as $key => $value) {
      $option_text .= "<input type=hidden name=" . $key . " value=" . $value . ">";
    }

    // build
    $ret .= "<div " . $alignText . ">
               <form class='bar' action='" . $_SESSION['ARI_ROOT'] . "' method='GET' name='search'>
                 <input type=hidden name=m value=" . $m . ">	
                 <input type=text name=q size=40 value='" . $q . "' maxlength=256>
                 " . $option_text . " 
                 <input type=hidden name=start value=0>	
                 <input type=submit name=btnS value='" . _("Search") . "'>
               </form>
             </div>";

    if ($focus=="true") {	// search block loaded twice usually so only allow javascript to be loaded on the top block
      $ret .= "<script type='text/javascript'> 
                 <!-- 
                 if (document.search) { 
                   document.search.q.focus(); 
                 } 
                 // -->                
               </script>";
    }

    return $ret;
  }

  /**
   * displays info bar
   *
   * @param $controls
   *   controls for the page on the bar
   * @param $q
   *   search query
   * @param $start
   *   start number of current page
   * @param $span
   *   number of items on current page
   * @param $total
   *   total number of records found by current search
   */
  function displayInfoBarBlock($controls,$q,$start,$span,$total) {

    if ($total<$span) { 
      $span = $total; 
    }
    $start_count = ($total>0)?$start+1:$start;
    $span_count = ($start+$span>$total)?$total:$start+$span;

    if ($controls) {
      $left_text = $controls;
    }
    elseif ($q != NULL) {
      $left_text = "<small><small>" . _("Searched for") . " <u>" . $q . "</u></small></small>";
    }

    if ($span<$total) {
      $right_text = "<small><small>" . sprintf(_("Results %d - %d of %d"),$start_count,$span_count,$total) . "</small></small>";
    } else {
      $right_text = "<small><small>" . sprintf(_("Results %d"),$total) . "</small></small>";
    }

    $ret .= "
      <table id='navbar' width='100%'>
        <tr>
          <td>
           " . $left_text . "
         </td>
         <td align='right'>
           " . $right_text ."
         </td>
       </tr>
     </table>";

    return $ret;
  }

  /**
   * displays navigation bar
   *
   * @param $q
   *   search query
   * @param $start
   *   start number of current page
   * @param $span
   *   number of items on current page
   * @param $total
   *   total number of records found by current search
   */
  function displayNavigationBlock($m,$q,$url_opts,$start,$span,$total) {

    $start = $start=='' ? 0 : $start ;
    $span = $span=='' ? 15 : $span ;

    $total_pages = ceil($total/$span);
    $start_page = floor($start/$span);

    // if more than ten pages start at this page minus ten otherwise start at zero
    $begin = ($start_page>10)?($start_page-10):0;
    // if more than ten pages then stop at this page plus ten otherwise stop at last page
    $end = ($start_page>8)?($start_page+10):10;

    // url
    $unicode_q = urlencode($q);  // encode search string

    foreach ($url_opts as $key => $value) {
      $option_text .= "&" . $key . "=" . $value;
    }

    $url = $_SESSION['ARI_ROOT'] . "?m=" . $m . "&q=" . $unicode_q . $option_text;

    // build
    if ($start_page!=0) {
      $start_page_text = "<a href='" . $url . "&start=0'><small>" . _("First") . "</a>&nbsp;</small>
			<a href=" . $url . "&start=" . ($start-$span) . "><small><</a>&nbsp;</small>";
    }

    for($next_page=$begin;($next_page<$total_pages)&&($next_page<$end);$next_page++) {
      if ($next_page == $start_page) {
          $middle_page_text .= "<small>" . ($next_page+1) . "&nbsp;</small>";
      } else {
          $middle_page_text .= "<a href='" . $url . "&start=" . ($next_page*$span) . "'><small>" . ($next_page+1) . "</a>&nbsp;</small>";
      }
    }
    if ( ($start_page != $total_pages-1)  && ($total != 0) ) {
          $end_page_text = "<a href='" . $url . "&start=" . ($start+$span) . "'><small>></a>&nbsp;</small>
                          <a href='" . $url . "&start=" . ($total_pages-1)*$span  . "'><small>" . _("Last") . "</a>&nbsp;</small>";
    }

    $ret .= "<div class='bar_center'>
              " . $start_page_text . "
              " . $middle_page_text . "
              " . $end_page_text . "
             </div>";

    return $ret;
  }
}  


?>