(no commit message)
[freeside.git] / fs_selfservice / fri / includes / display.php
1 <?php
2
3 /**
4  * @file
5  * Functions common to display
6  */
7
8 /**
9   * Display 
10   */
11 class Display {
12
13   /**
14    * display constructor 
15    */
16   function Display() {
17   }
18
19   /**
20    * display text header
21    *
22    * @param $text
23    *   Header text to display
24    */
25   function displayHeaderText($text) {
26
27     $ret = "<h2>" . $text . "</h2>
28             <br>";
29
30     return $ret;
31   }
32
33   /**
34    * displays header line 
35    */
36   function displayLine() {
37
38     $ret = "
39       <div id='line'>
40         <div class='spacer'></div>
41         <div class='spacer'></div>
42       </div>
43       <br>";
44
45     return $ret;
46   }
47 }  
48
49 /**
50   * DisplaySearch  
51   */
52 class DisplaySearch extends Display {
53
54   /**
55    * Constructor
56    */
57   function DisplaySearch() {
58   }
59
60   /**
61    * displays search controls
62    *
63    * @param $align
64    *   where to align the control
65    * @param $q
66    *   search query
67    * @param $focus
68    *   whether to focus control on this block
69    */
70   function displaySearchBlock($align,$m,$q,$url_opts,$focus) {
71
72     // align
73     if ($align=='center') {
74       $alignText = "class='bar_center'";
75     }
76     else {
77       $alignText = "class='bar_left'";
78     }
79
80     // url options
81     foreach ($url_opts as $key => $value) {
82       $option_text .= "<input type=hidden name=" . $key . " value=" . $value . ">";
83     }
84
85     // build
86     $ret .= "<div " . $alignText . ">
87                <form class='bar' action='" . $_SESSION['ARI_ROOT'] . "' method='GET' name='search'>
88                  <input type=hidden name=m value=" . $m . ">    
89                  <input type=text name=q size=40 value='" . $q . "' maxlength=256>
90                  " . $option_text . " 
91                  <input type=hidden name=start value=0> 
92                  <input type=submit name=btnS value='" . _("Search") . "'>
93                </form>
94              </div>";
95
96     if ($focus=="true") {       // search block loaded twice usually so only allow javascript to be loaded on the top block
97       $ret .= "<script type='text/javascript'> 
98                  <!-- 
99                  if (document.search) { 
100                    document.search.q.focus(); 
101                  } 
102                  // -->                
103                </script>";
104     }
105
106     return $ret;
107   }
108
109   /**
110    * displays info bar
111    *
112    * @param $controls
113    *   controls for the page on the bar
114    * @param $q
115    *   search query
116    * @param $start
117    *   start number of current page
118    * @param $span
119    *   number of items on current page
120    * @param $total
121    *   total number of records found by current search
122    */
123   function displayInfoBarBlock($controls,$q,$start,$span,$total) {
124
125     if ($total<$span) { 
126       $span = $total; 
127     }
128     $start_count = ($total>0)?$start+1:$start;
129     $span_count = ($start+$span>$total)?$total:$start+$span;
130
131     if ($controls) {
132       $left_text = $controls;
133     }
134     elseif ($q != NULL) {
135       $left_text = "<small><small>" . _("Searched for") . " <u>" . $q . "</u></small></small>";
136     }
137
138     if ($span<$total) {
139       $right_text = "<small><small>" . sprintf(_("Results %d - %d of %d"),$start_count,$span_count,$total) . "</small></small>";
140     } else {
141       $right_text = "<small><small>" . sprintf(_("Results %d"),$total) . "</small></small>";
142     }
143
144     $ret .= "
145       <table id='navbar' width='100%'>
146         <tr>
147           <td>
148            " . $left_text . "
149          </td>
150          <td align='right'>
151            " . $right_text ."
152          </td>
153        </tr>
154      </table>";
155
156     return $ret;
157   }
158
159   /**
160    * displays navigation bar
161    *
162    * @param $q
163    *   search query
164    * @param $start
165    *   start number of current page
166    * @param $span
167    *   number of items on current page
168    * @param $total
169    *   total number of records found by current search
170    */
171   function displayNavigationBlock($m,$q,$url_opts,$start,$span,$total) {
172
173     $start = $start=='' ? 0 : $start ;
174     $span = $span=='' ? 15 : $span ;
175
176     $total_pages = ceil($total/$span);
177     $start_page = floor($start/$span);
178
179     // if more than ten pages start at this page minus ten otherwise start at zero
180     $begin = ($start_page>10)?($start_page-10):0;
181     // if more than ten pages then stop at this page plus ten otherwise stop at last page
182     $end = ($start_page>8)?($start_page+10):10;
183
184     // url
185     $unicode_q = urlencode($q);  // encode search string
186
187     foreach ($url_opts as $key => $value) {
188       $option_text .= "&" . $key . "=" . $value;
189     }
190
191     $url = $_SESSION['ARI_ROOT'] . "?m=" . $m . "&q=" . $unicode_q . $option_text;
192
193     // build
194     if ($start_page!=0) {
195       $start_page_text = "<a href='" . $url . "&start=0'><small>" . _("First") . "</a>&nbsp;</small>
196                         <a href=" . $url . "&start=" . ($start-$span) . "><small><</a>&nbsp;</small>";
197     }
198
199     for($next_page=$begin;($next_page<$total_pages)&&($next_page<$end);$next_page++) {
200       if ($next_page == $start_page) {
201           $middle_page_text .= "<small>" . ($next_page+1) . "&nbsp;</small>";
202       } else {
203           $middle_page_text .= "<a href='" . $url . "&start=" . ($next_page*$span) . "'><small>" . ($next_page+1) . "</a>&nbsp;</small>";
204       }
205     }
206     if ( ($start_page != $total_pages-1)  && ($total != 0) ) {
207           $end_page_text = "<a href='" . $url . "&start=" . ($start+$span) . "'><small>></a>&nbsp;</small>
208                           <a href='" . $url . "&start=" . ($total_pages-1)*$span  . "'><small>" . _("Last") . "</a>&nbsp;</small>";
209     }
210
211     $ret .= "<div class='bar_center'>
212               " . $start_page_text . "
213               " . $middle_page_text . "
214               " . $end_page_text . "
215              </div>";
216
217     return $ret;
218   }
219 }  
220
221
222 ?>