YAP  2.5
 All Data Structures Namespaces Files Functions Variables
CYap_Table.php
Go to the documentation of this file.
1 <?PHP
14 /*
15  * +-------------------------------------------------------------------------+
16  * | Yap, Version 2.5.0 |
17  * +-------------------------------------------------------------------------+
18  * | Copyright (c) 2003-2013 Andrioli Darvin |
19  * | Email <darvin (inside) andrioli (dot) com> |
20  * | Web http://www.andrioli.com/en/yap.html |
21  * | Download http://www.phpclasses.org/browse.html/package/1391.html |
22  * | |
23  * +-------------------------------------------------------------------------+
24  * | This library is free software; you can redistribute it and/or modify |
25  * | it under the terms of the GNU Lesser General Public License as |
26  * | published by the Free Software Foundation; either version 2 of the |
27  * | License, or (at your option) any later version. |
28  * | |
29  * | This library is distributed in the hope that it will be useful, but |
30  * | WITHOUT ANY WARRANTY; without even the implied warranty of |
31  * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
32  * | Lesser General Public License for more details. |
33  * | |
34  * | You should have received a copy of the GNU Lesser General Public |
35  * | License along with this library; if not, write to the Free Software |
36  * | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
37  * +-------------------------------------------------------------------------+
38  */
43 {
44 
45 
76 var $Lang;
89 
91 {
92 $this->Lang=parse_ini_file($Lang);
93 $this->CurrentCol=-1;
94 $this->PendingRow=false;
95 $this->PendingHeader=false;
96 $this->EchoText=true;
97 $this->HtmlCode='';
98 $this->colSpecial['MODIFY']=99;
99 $this->colSpecial['DELETE']=99;
100 $this->colSpecial['DETAIL']=99;
101 }
102 
111 function LoadFormats($fmt)
112 {
113 $this->formats=$fmt;
114 }
115 
121 function BeginTable()
122 {
123 $this->Out("<table border=1 align=center>");
124 $this->CurrentCol=-1;
125 $this->PendingRow=false;
126 $this->PendingHeader=false;
127 }
133 function HeaderStart()
134 {
135 $text='';
136 if($this->PendingRow)
137  trigger_error('You cannot start an header after a normal row',E_USER_ERROR );
138  // Start the new row
139 $text.='<tr>';
140 $this->Out($text);
141 $this->CurrentCol=-1;
142 $this->PendingHeader=true;
143 }
144 
152 function HeaderCell($Href,$Label,$offset=-1)
153 {
154 if(!$this->PendingHeader)
155  trigger_error('You cannot write an header cell without start the header',E_USER_ERROR);
156 if($offset>-1)
157  {
158  while((++$this->CurrentCol)<$offset)
159  $this->out('<th>&nbsp;</th>');
160  }
161 else
162  $this->CurrentCol++;
163 $text="<a href='" . $Href ."'>".$Label."</a>";
164 $this->out('<th>'.$text.'</th>');
165 }
166 
172 function HeaderClose()
173 {
174 if($this->PendingRow)
175  trigger_error('You cannot close an header after a normal row',E_USER_ERROR );
176 $this->PendingHeader=false;
177 $this->Out("</tr>\n");
178 }
179 
180 
186 function NewRow()
187 {
188 $text='';
189 if($this->PendingRow)
190  {
191  // Close the previous row
192  $text="</tr>\n";
193  }
194 // Start the new row
195 $text.='<tr>';
196 $this->Out($text);
197 $this->CurrentCol=-1;
198 $this->PendingRow=true;
199 }
200 
201 
213 function Cell($txt_in,$FieldName,$offset=-1,$fmt='NONE')
214 {
215 if(!$this->PendingRow)
216  trigger_error('You cannot write a cell without start the row',E_USER_ERROR);
217 if($offset>-1)
218  {
219  while((++$this->CurrentCol)<$offset)
220  $this->out('<td>&nbsp;</td>');
221  }
222 else
223  $this->CurrentCol++;
224 
225 if(array_key_exists($fmt,$this->formats))
226  {
227  eval($this->formats[$fmt]);
228  $this->out('<td>'.$txt_out.'</td>');
229  }
230 else
231  trigger_error('Unknown format name: '.$fmt,E_USER_ERROR);
232 
233 switch($FieldName)
234  {
235  case 'DETAIL':
236  case 'MODIFY':
237  case 'DELETE':
238  $this->colSpecial[$FieldName]=$this->CurrentCol;
239  break;
240  }
241 }
242 
243 function SpecialCell($link,$type,$offset=-1)
244 {
245 if($link!='')
246  {
247  switch($type)
248  {
249  case 'MODIFY':
250  $text='<a href='.$link.' onMouseOver="YapToolTip(\''.$this->Lang['TipModify'].'\')" onMouseOut="YapToolTip()" >'.$this->Lang['Modify'].'</a>';
251  break;
252  case 'DELETE':
253  $text='<a href='.$link.' onMouseOver="YapToolTip(\''.$this->Lang['TipRemove'].'\')" onMouseOut="YapToolTip()" >'.$this->Lang['Remove'].'</a>';
254  break;
255  case 'DETAIL':
256  $text='<a href='.$link.' onMouseOver="YapToolTip(\''.$this->Lang['TipDetail'].'\')" onMouseOut="YapToolTip()" >'.$this->Lang['Detail'].'</a>';
257  break;
258  }
259  }
260 else
261  $text='&nbsp;';
262 $this->Cell($text,$type,$offset);
263 }
264 
270 function AddRowCell($link)
271 {
272 $this->NewRow();
273 $col=99;
274 $col=($this->colSpecial['MODIFY']<$this->colSpecial['DELETE'])?$this->colSpecial['MODIFY']:$this->colSpecial['DELETE'];
275 $col=($col<$this->colSpecial['DETAIL'])?$col:$this->colSpecial['DETAIL'];
276 $col=($col==99)?0:$col;
277 $text='<a href='.$link.' onMouseOver="YapToolTip(\''.$this->Lang['TipNewRow'].'\')" onMouseOut="YapToolTip()" >'.$this->Lang['NewRow'].'</a>';
278 $this->Cell($text,'ADDROW',$col);
279 }
280 
281 function EndTable()
282 {
283 $this->Out("</tr></table>");
284 }
285 
286 function FlushCode()
287 {
288 print $this->HtmlCode;
289 }
296 function Out($text)
297 {
298 if($this->EchoText)
299  print $text;
300 else
301  $this->HtmlCode.=$text;
302 }
303 
304 }
305 
310 class CYap_DetailView
311 {
312 
313 
319 var $CurrentCol;
324 var $PendingRow;
329 var $PendingHeader;
334 var $EchoText;
339 var $HtmlCode;
344 var $Lang;
351 var $formats;
356 function CYap_DetailView($Lang)
357 {
358 $this->Lang=parse_ini_file($Lang);
359 $this->CurrentCol=-1;
360 $this->PendingRow=false;
361 $this->PendingHeader=false;
362 $this->EchoText=true;
363 $this->HtmlCode='';
364 }
373 function LoadFormats($fmt)
374 {
375 $this->formats=$fmt;
376 }
377 
383 function BeginTable()
384 {
385 $this->Out("<table border=1 align=center>");
386 $this->CurrentCol=-1;
387 $this->PendingRow=false;
388 $this->PendingHeader=false;
389 }
395 function HeaderStart()
396 {
397 $text="
398  <tr>
399  <th>".$this->Lang['Field']."</th>
400  <th width=20>&nbsp</th>
401  <th>".$this->Lang['Value']."</th>
402  </tr>";
403 if($this->PendingRow)
404  trigger_error('You cannot start an header after a normal row',E_USER_ERROR );
405  // Start the new row
406 $this->Out($text);
407 $this->PendingHeader=false;
408 }
409 
420 function Cell($label='', $txt_in='',$FieldName,$fmt='NONE')
421 {
422 $this->CurrentCol++;
423 if(array_key_exists($fmt,$this->formats))
424  {
425  eval($this->formats[$fmt]);
426  $this->out('<tr><td><b>'.$label.'</b></td><td></td><td align=center>'.$txt_out.'</td></tr>');
427  }
428 else
429  trigger_error('Unknown format name: '.$fmt,E_USER_ERROR);
430 }
431 
436 function EndTable()
437 {
438 $this->Out("</table>");
439 }
440 
449 function FlushCode()
450 {
451 print $this->HtmlCode;
452 }
459 function Out($text)
460 {
461 if($this->EchoText)
462  print $text;
463 else
464  $this->HtmlCode.=$text;
465 }
466 
467 }
468 ?>