1: <?php
2: /**
3: * Document for geolib functions and class wrappers
4: *
5: * PHP Version 5.6
6: *
7: * @category GeolibFile
8: * @package Geolib
9: * @author Peter Pitchford <peter@geotonics.com>
10: * @license GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
11: * @link http://geotonics.com/#geolib
12: */
13:
14: /**
15: * Loads geolib PHP class files.
16: *
17: * @param string $class Name of class to load
18: *
19: * @return void
20: */
21: function geolib_autoloader($class)
22: {
23: $file=dirname(__FILE__)."/classes/" . $class . '.php';
24:
25: if (file_exists($file)) {
26: include $file;
27: }
28: }
29:
30: /**
31: * Create an HTML tag.
32: *
33: * @param string $tag tag name
34: * @param string $text Content of tag
35: * @param string $class Class attribute
36: * @param string $id Id attribute
37: * @param string $style Style attribute
38: * @param array $atts Any other attributes
39: *
40: * @return string HTML i tag
41: */
42: function geoTag($tag, $text, $class = null, $id = null, $style = null, $atts = null)
43: {
44: $GeoTag = new GeoTag($tag, $text, $class, $id, $style, $atts);
45: return $GeoTag->baseTag();
46: }
47:
48: /**
49: * Create HTML tag
50: *
51: * @param string|object $body HTML body tag or GeoBody object
52: * @param string|object $head A GeoHead object, usually from geoHead(). A string for the title can be used
53: * if no other head attributes are required.
54: * @param string $userSessionName Name of user session
55: * @param bool $tidyTag Determines whether to tidy up html with proper tabs
56: * @param bool $start A flag to indicte that this tag should only return
57: * the start tag and the content.
58: * This allows direct output of any other content before the end tag.
59: * @param string $doctype Doctype for this document
60: *
61: * @return string HTML document
62: */
63: function geoHtml($body = null, $head = null, $userSessionName = null, $tidyTag = null, $start = null, $doctype = null)
64: {
65: $page = new GeoHtml($body, $head, $userSessionName, $doctype, $start);
66: return $page->tag($tidyTag);
67: }
68:
69: /**
70: * Create an html head tag
71: *
72: * @param string $title Document title
73: * @param string|array $stylesheets Paths to document stylesheets. Can be 1 path or an array
74: * @param string|array $scripts Paths to document scripts. Can be either 1 path or an array
75: * @param string $styles Styles for style tag in head
76: * @param array $metas Content of metatags
77: * @param string|array $addlTags Any additional tags for head
78: * addlTags can be multi or non multi. Examples:
79: * array:$tags["script"][$script]=array("type"=>'text/script');
80: * $addlTags['link'][]=array("rel"=>'goback');
81: * $addlTags['link']=array("rel"=>'goback');
82: * @param string $media Media attribute
83: * @param string $addlHtml Any additional html for head
84: *
85: * @return string HTML head tag
86: */
87: function geoHead(
88: $title = null,
89: $stylesheets = null,
90: $scripts = null,
91: $styles = null,
92: $metas = null,
93: $addlTags = null,
94: $media = 'screen',
95: $addlHtml = null
96: ) {
97: return new GeoHead($title, $stylesheets, $scripts, $styles, $metas, $addlTags, $media, $addlHtml);
98: }
99: /**
100: * Create HTML body
101: *
102: * @param string $page Content of body tag
103: * @param string $class Class attribute
104: * @param string $onload Javascript to be run on page load
105: * @param string $style Style attribute
106: * @param string $id Id attribute
107: *
108: * @return string HTML body
109: */
110: function geoBody($page, $class = null, $onload = null, $style = null, $id = null)
111: {
112: return new GeoBody($page, $class, $onload, $style, $id);
113: }
114:
115: /**
116: * Create an link for javascript actions.
117: *
118: * @param string|array $src Path to javascript file
119: * @param string $text Javascript string
120: * @param string $type Type of script
121: *
122: * @return string HTML a tag
123: */
124: function geoScript($src = null, $text = null, $type = "text/javascript")
125: {
126: if (is_array($text)) {
127: foreach ($text as $onetext) {
128: $script .= geoScript($src, $onetext);
129: }
130:
131: return $script;
132: }
133:
134: $atts['type'] = $type;
135:
136: if ($src === true) {
137: $text = "jQuery(function($) {" . $text . "});";
138: } else {
139: $atts['src'] = $src;
140: }
141:
142: return geoTag("script", $text, null, null, null, $atts);
143: }
144:
145: /**
146: * Create noscript tag
147: *
148: * @param string $content Non javascript content
149: *
150: * @return noscript tag
151: */
152: function geoNoScript($content)
153: {
154: return geoTag('noscript', $content);
155: }
156:
157: /**
158: * Create an http link.
159: *
160: * @param string $link Link destination (with or without host)
161: * @param string $text Text of link
162: * @param string $title Title attribute
163: * @param string $target Target attribute
164: * @param string $class Class attribute
165: * @param string $id Id attribute
166: * @param array $atts Any other attributes
167: *
168: * @return string HTML a tag
169: */
170: function geoLink($link = null, $text = null, $title = null, $target = null, $class = null, $id = null, $atts = null)
171: {
172: $link = new GeoLink($link, $text, $title, $target, $class, $id, $atts);
173: return $link->tag();
174: }
175:
176:
177: /**
178: * Create HTML anchor
179: *
180: * @param string $name Anchor name (also given to id)
181: *
182: * @return string HTML anchor
183: */
184: function geoAnchor($name)
185: {
186: $link = new GeoLink();
187: $link->setAtt("name", $name);
188: $link->setAtt("id", $name);
189: return $link->tag();
190: }
191:
192: /**
193: * Create an link for javascript actions.
194: *
195: * @param string $text Text of link
196: * @param string $id Id attribute
197: * @param string $title Title attribute
198: * @param string $class Class attribute
199: * @param array $atts Any other attributes
200: * @param string $target Target attribute
201: *
202: * @return string HTML a tag
203: */
204: function geoJSLink($text = null, $id = null, $title = null, $class = null, $atts = null, $target = null)
205: {
206: if ($atts && !is_array($atts)) {
207: $newatts['onclick'] = $atts;
208: $atts = $newatts;
209: }
210: if ($class) {
211: $class .= " geoJsLink";
212: } else {
213: $class = "geoJsLink";
214: }
215:
216: $atts["class"]=$class;
217: $class=null;
218: $link = new GeoLink(null, $text, $title, $target, $class, $id, $atts);
219: return $link->tag();
220: }
221:
222: /**
223: * Create an absolute http link to a location on this local server.
224: *
225: * @param string $link Relative link destination (without host)
226: * @param string $text Text of link
227: * @param string $class Class attribute
228: * @param string $title Title attribute
229: * @param string $target Target attribute
230: * @param string $id Id attribute
231: * @param array $atts Any other attributes
232: *
233: * @return string HTML a tag
234: */
235: function geoAbsLink($link = null, $text = null, $class = null, $title = null, $target = null, $id = null, $atts = null)
236: {
237: $link = new GeoLink("http://" . $_SERVER["HTTP_HOST"] . $link, $text, $class, $target, $title, $id, $atts);
238: return $link->tag();
239: }
240:
241: /**
242: * Create an HTML select tag
243: *
244: * @param string $name Name of select tag
245: * @param array $options 1 or 2 dimensional array of options
246: * If 1 each row is $name=>$value
247: * If 2 each array is 0=>name 1=>value 2=>class
248: * @param string $selected name of selected option
249: * @param string $id id of select tag
250: * @param array|string|bool $atts attributes of select tag
251: * If array, is atts of select tag.
252: * If string, is a single default att
253: * If PHP true, att is onchange=>javascript to submit form
254: * @param string $size size att of select tag
255: * @param string $class class of select tag
256: * @param string $style style of select tag
257: *
258: * @return string HTML select tag
259: */
260: function geoSelect(
261: $name = "selectname",
262: $options = null,
263: $selected = null,
264: $id = null,
265: $atts = null,
266: $size = null,
267: $class = null,
268: $style = null
269: ) {
270: if ($options) {
271: $select = new GeoSelect($name, $options, $selected, $id, $atts, $size, $class, $style);
272: return $select->tag();
273: }
274: }
275:
276: /**
277: * Create an span div tag.
278: *
279: * @param string $text Content of span tag
280: * @param string $class Class attribute
281: * @param string $id Id attribute
282: * @param string $style Style attribute
283: * @param array $atts Any other attributes
284: *
285: * @return string HTML span tag
286: */
287: function span($text, $class = null, $id = null, $style = null, $atts = null)
288: {
289: $tagobj = new GeoTag('span', $text, $class, $id, $style, $atts);
290: return $tagobj->baseTag();
291: }
292:
293: /**
294: * Create an HTML div tag.
295: *
296: * @param string $text Content of div tag
297: * @param string $class Class attribute
298: * @param string $id Id attribute
299: * @param string $style Style attribute
300: * @param array $atts Any other attributes
301: *
302: * @return string HTML div tag
303: */
304: function div($text, $class = null, $id = null, $style = null, $atts = null)
305: {
306:
307: return geoTag('div', $text, $class, $id, $style, $atts);
308: }
309:
310:
311: /**
312: * Create an inline HTML tag.
313: *
314: * @param string $tagName Html tag
315: * @param string $text Content of div tag
316: * @param string $style Style attribute
317: * @param string $fontsize Font size
318: * @param string $margin Margin
319: * @param array $atts Any other attributes
320: *
321: * @return string HTML div tag
322: */
323: function itag($tagName = null, $text=null, $style = null, $fontsize = null, $margin = null, $atts = null)
324: {
325: if ($fontsize) {
326: $style="font-size:".$fontsize.";".$style;
327: }
328:
329: if ($margin || $margin===0) {
330: $style="margin:".$margin.";".$style;
331: }
332:
333: return geoTag($tagName, $text, null, null, $style, $atts);
334: }
335:
336: /**
337: * Create an inline HTML div tag.
338: *
339: * @param string $text Content of div tag
340: * @param string $style Style attribute
341: * @param string $fontsize Font size
342: * @param string $margin Margin
343: * @param array $atts Any other attributes
344: *
345: * @return string HTML div tag
346: */
347: function idiv($text, $style = null, $fontsize = null, $margin = null, $atts = null)
348: {
349: return itag("div", $text, $style, $fontsize, $margin, $atts);
350: }
351:
352: /**
353: * Create an inline HTML span tag.
354: *
355: * @param string $text Content of span tag
356: * @param string $style Style attribute
357: * @param string $fontsize Font size
358: * @param string $margin Margin
359: * @param array $atts Any other attributes
360: *
361: * @return string HTML span tag
362: */
363: function ispan($text, $style = null, $fontsize = null, $margin = null, $atts = null)
364: {
365: return itag("span", $text, $style, $fontsize, $margin, $atts);
366: }
367:
368: /**
369: * Create an HTML p tag.
370: *
371: * @param string $text Content of p tag
372: * @param string $class Class attribute
373: * @param string $id Id attribute
374: * @param string $style Style attribute
375: * @param array $atts Any other attributes
376: *
377: * @return string HTML p tag
378: */
379: function p($text, $class = null, $id = null, $style = null, $atts = null)
380: {
381: return geoTag('p', $text, $class, $id, $style, $atts);
382: }
383:
384: /**
385: * Create an HTML b tag.
386: *
387: * @param string $text Content of b tag
388: * @param string $class Class attribute
389: * @param string $id Id attribute
390: * @param string $style Style attribute
391: * @param array $atts Any other attributes
392: *
393: * @return string HTML b tag
394: */
395: function b($text, $class = null, $id = null, $style = null, $atts = null)
396: {
397: return geoTag('b', $text, $class, $id, $style, $atts);
398: }
399:
400:
401: /**
402: * Create an HTML i tag.
403: *
404: * @param string $text Content of i tag
405: * @param string $class Class attribute
406: * @param string $id Id attribute
407: * @param string $style Style attribute
408: * @param array $atts Any other attributes
409: *
410: * @return string HTML i tag
411: */
412: function i($text, $class = null, $id = null, $style = null, $atts = null)
413: {
414: return geoTag('i', $text, $class, $id, $style, $atts);
415: }
416: /**
417: * Create an HTML h1 tag.
418: *
419: * @param string $text Content of h1 tag
420: * @param string $class Class attribute
421: * @param string $id Id attribute
422: * @param string $style Style attribute
423: * @param array $atts Any other attributes
424: *
425: * @return string HTML h1 tag
426: */
427: function h1($text, $class = null, $id = null, $style = null, $atts = null)
428: {
429: return geoTag('h1', $text, $class, $id, $style, $atts);
430: }
431:
432: /**
433: * Create an HTML h2 tag.
434: *
435: * @param string $text Content of h2 tag
436: * @param string $class Class attribute
437: * @param string $id Id attribute
438: * @param string $style Style attribute
439: * @param array $atts Any other attributes
440: *
441: * @return string HTML h2 tag
442: */
443: function h2($text, $class = null, $id = null, $style = null, $atts = null)
444: {
445: return geoTag('h2', $text, $class, $id, $style, $atts);
446: }
447:
448: /**
449: * Create an HTML h3 tag.
450: *
451: * @param string $text Content of h3 tag
452: * @param string $class Class attribute
453: * @param string $id Id attribute
454: * @param string $style Style attribute
455: * @param array $atts Any other attributes
456: *
457: * @return string HTML h3 tag
458: */
459: function h3($text, $class = null, $id = null, $style = null, $atts = null)
460: {
461: return geoTag('h3', $text, $class, $id, $style, $atts);
462: }
463:
464: /**
465: * Create an HTML h4 tag.
466: *
467: * @param string $text Content of h4 tag
468: * @param string $class Class attribute
469: * @param string $id Id attribute
470: * @param string $style Style attribute
471: * @param array $atts Any other attributes
472: *
473: * @return string HTML h4 tag
474: */
475: function h4($text, $class = null, $id = null, $style = null, $atts = null)
476: {
477: return geoTag('h4', $text, $class, $id, $style, $atts);
478: }
479:
480: /**
481: * Create an HTML pre tag.
482: *
483: * @param string $text Content of pre tag
484: * @param string $class Class attribute
485: * @param string $id Id attribute
486: * @param string $style Style attribute
487: * @param array $atts Any other attributes
488: *
489: * @return string HTML pre field
490: */
491: function geoPre($text, $class = null, $id = null, $style = null, $atts = null)
492: {
493: return geoTag('pre', $text, $class, $id, $style, $atts);
494: }
495:
496: /**
497: * Create an HTML fieldset tag.
498: *
499: * @param string $html Content of fieldset tag
500: * @param string $legend HTML Content of legend tag
501: * @param string $class Class attribute
502: * @param string $legendClass Legend class attribute
503: * @param string $id Id attribute
504: * @param string $legendId Legend id attriute
505: * @param string $style Style attribute
506: * @param string $legendStyle Legend Style attribute
507: *
508: * @return string HTML password field
509: */
510: function geoFieldSet(
511: $html,
512: $legend = null,
513: $class = null,
514: $legendClass = null,
515: $id = null,
516: $legendId = null,
517: $style = null,
518: $legendStyle = null
519: ) {
520: return geoTag("fieldset", geoLegend($legend, $legendClass, $legendId, $legendStyle) . $html, $class, $id, $style);
521: }
522:
523: /**
524: * Create an HTML legend tag. This is usually not called directly.
525: * Use geoFieldSet to create a fieldset tag with a legend
526: *
527: * @param string $html Tag content
528: * @param string $class Class attribute
529: * @param string $id Id attribute
530: * @param string $style Style attribute
531: *
532: * @return string HTML password field
533: */
534: function geoLegend($html, $class, $id, $style)
535: {
536: return geoTag("legend", $html, $class, $id, $style);
537: }
538:
539:
540: /**
541: * Create tabs in source code (Can also be used to create any number of repetitions of any text)
542: *
543: * @param string $tabs Number of tabs
544: * @param string $text Value to use as tab
545: *
546: * @return string Text of tabs
547: */
548: function geoTabs($tabs = 1, $text = " ")
549: {
550: if ($text=== true) {
551: $text=" ";
552: }
553:
554: $tab='';
555:
556: for ($i=0; $i<$tabs; $i++) {
557: $tab.=$text;
558: }
559:
560: return $tab;
561: }
562:
563: /**
564: * Create an HTML img field. (for images)
565: *
566: * @param string $src Source (path) of image
567: * @param string $alt Alt attribut
568: * @param string $href Link destination, if link is desired.
569: * @param string $title Title attribute of link
570: * @param string $target Target attribute of link
571: * @param string $host Host of image
572: * @param string $id Id attribute
573: * @param string $class Class attribute
574: * @param string $style Style attribute
575: * @param array $atts Any other image atts.
576: * @param string $rel Image rel attribute of link
577: *
578: * @return string HTML img field
579: */
580: function geoImg(
581: $src,
582: $alt = '',
583: $href = null,
584: $title = null,
585: $target = null,
586: $host = null,
587: $id = null,
588: $class = null,
589: $style = null,
590: $atts = null,
591: $rel = null
592: ) {
593: $imgobj = new GeoImg($src, $alt, $href, $title, $target, $host, $id, $class, $style, $atts, $rel);
594: return $imgobj->tag();
595: }
596:
597: /**
598: * Create an HTML file upload field.
599: *
600: * @param string $fileName Name of file value which will contain the name of the selected file.
601: * @param string $id Id attribute
602: *
603: * @return string HTML file upload field
604: */
605: function geoUpload($fileName = "filename", $id = null)
606: {
607: return geoInput("file", $fileName, null, null, $id);
608: }
609:
610: /**
611: * Create an HTML form.
612: *
613: * @param string|array $inputs Form content. Can be a string or an array of strings.
614: * Strings can be input fields or elements that contain input fields.
615: * @param string $id Id attribute
616: * @param string||true $action Action attribute. Contains destination of form submit.
617: * If true, the action is the page that contains the form.
618: * @param string|array $atts Any other atts. If this is a string, it is assumed to be an onsubmit attribute
619: * The onsubmit attribute should contain javascript which will run when the form is submitted.
620: * @param string $class Class attribute
621: * @param string $style Style attribute
622: * @param string $enctype Enctype attribute
623: * @param string $target Target attribute
624: * @param boolean $method Method attribute
625: *
626: * @return string HTML form
627: */
628: function geoForm(
629: $inputs,
630: $id = null,
631: $action = null,
632: $atts = null,
633: $class = null,
634: $style = null,
635: $enctype = false,
636: $target = null,
637: $method = 'post'
638: ) {
639: if ($action===true) {
640: $url = parse_url($_SERVER["REQUEST_URI"]);
641: $action = $url["path"];
642: } elseif (!$action) {
643: $action=$_SERVER["REQUEST_URI"];
644: }
645:
646: // onsubmit is default, everything else requires an array
647: if (is_array($atts)) {
648: foreach ($atts as $name => $value) {
649: $atts[$name] = $value;
650: }
651: } else {
652: $atts=array("onsubmit" =>$atts);
653: }
654:
655: if ($enctype) {
656: $atts["enctype"] = "multipart/form-data";
657: }
658:
659: $atts["action"] = $action;
660: $atts["method"] = $method;
661:
662: if ($target) {
663: $atts["target"] = $target;
664: }
665:
666: if ($action == null) {
667: $action = $_SERVER["PHP_SELF"];
668: }
669:
670: return geoTag('form', div($inputs, 'geoForm'), $class, $id, $style, $atts);
671: }
672:
673: /**
674: * Create an HTML textarea field.
675: *
676: * @param string $name Name of value retured by this field
677: * @param string $value Value returned by this field
678: * @param string $class Class attribute
679: * @param string $id Id attribute
680: * @param string $style Style attribute
681: * @param string $rows Number of rows (can be overwritten with styles)
682: * @param string $cols Number of Columns (can be overwritten with styles)
683: * @param string|array $atts Any other atts. Can be string with "=" to indicate 1 attribute
684: *
685: * @return string HTML textarea field
686: */
687: function geoTextArea(
688: $name = null,
689: $value = null,
690: $class = null,
691: $id = null,
692: $style = null,
693: $rows = 10,
694: $cols = 25,
695: $atts = null
696: ) {
697:
698: if (!$id) {
699: $id = $name;
700: }
701:
702: $atts['name'] = $name;
703: $atts['rows'] = $rows;
704: $atts['cols'] = $cols;
705: return geoTag("textarea", $value, $class, $id, $style, $atts);
706: }
707:
708: /**
709: * Create an HTML text field.
710: *
711: * @param string $name Name of value retured by this field
712: * @param string $value Value returned by this field
713: * @param string $id Id attribute
714: * @param string $class Class attribute
715: * @param string|array $atts Any other atts. Can be string with "=" to indicate 1 attribute
716: * @param string $size Size attribute
717: * @param boolean $readonly Indicates that this field is readonly
718: * @param string $style Style attribute
719: *
720: * @return string HTML text field
721: */
722: function geoText(
723: $name = 'textinput',
724: $value = null,
725: $id = null,
726: $class = null,
727: $atts = null,
728: $size = null,
729: $readonly = null,
730: $style = null
731: ) {
732: if ($atts && !is_array($atts)) {
733: $newatts['maxlength'] = $atts;
734: $atts = $newatts;
735: }
736: $atts['size'] = $size;
737:
738: if ($readonly) {
739: $atts['readonly'] = 'readonly';
740: }
741:
742: return geoInput('text', $name, $value, $atts, $id, $class, $style);
743: }
744:
745: /**
746: * Create HTML hidden field or fields.
747: *
748: * @param string|array $name Name of value retured by this field.
749: * If name is a 3 dimensional array, this function returns a hidden fields for each array in the array.
750: * Each value in the array must be an array of arguments in the same order as the funciton's parameters.
751: * @param string $value Value returned by this field
752: * @param string $id Id attribute
753: * @param string|array $atts Any other atts. Can be string with "=" to indicate 1 attribute
754: * @param string $class Class attribute
755: *
756: * @return string HTML hidden field or fields
757: */
758: function geoHidden($name, $value = null, $id = null, $atts = null, $class = null)
759: {
760: $result = '';
761: if (is_array($name)) {
762: foreach ($name as $one) {
763: $result .= geoHidden(
764: Geo::Val($one[0]),
765: Geo::Val($one[1]),
766: Geo::Val($one[2]),
767: Geo::Val($one[3]),
768: Geo::Val($one[4])
769: );
770: }
771: return $result;
772: }
773: if (!$id) {
774: $id = true;
775: } elseif ($id === true) {
776: $id = null;
777: }
778:
779: return geoInput('hidden', $name, $value, $atts, $id, $class);
780: }
781:
782: /**
783: * Create an HTML password field.
784: *
785: * @param string $name Name of value retured by this field
786: * @param string $value Value returned by this field
787: * @param string $id Id attribute
788: * @param string|array $atts Any other atts. Can be string with "=" to indicate 1 attribute
789: * @param string $class Class attribute
790: *
791: * @return string HTML password field
792: */
793: function geoPassword($name, $value = null, $id = null, $atts = null, $class = null)
794: {
795: return geoInput('password', $name, $value, $atts, $id, $class);
796: }
797:
798: /**
799: * Create an HTML submit button.
800: *
801: * @param string $type Type if input element
802: * @param string $name Name of value retured by this field
803: * @param string $value Value returned by this field
804: * @param string|array $atts Any other atts. Can be string with "=" to indicate 1 attribute
805: * @param string $id Id attribute
806: * @param string $class Class attribute
807: * @param string $style Style attribute
808: *
809: * @return string HTML Submit Button
810: */
811: function geoInput($type = 'text', $name = null, $value = null, $atts = null, $id = null, $class = null, $style = null)
812: {
813: if ($atts && !is_array($atts)) {
814: $attsarr = explode("=", $atts);
815: $atts = array();
816: $atts[$attsarr[0]] = $attsarr[1];
817: }
818:
819: if (!$id && strpos($name, "[") === false) {
820: $id = $name;
821: } elseif ($id === true) {
822: $id = null;
823: }
824:
825: /*
826: // If value is true, use $_POST[$name]
827: if($value===true){
828: if(isset($_POST[$name])){
829: $value=$_POST[$name];
830: } else {
831: $value=null;
832: }
833: }
834: */
835:
836: $atts['name'] = $name;
837: $atts['type'] = $type;
838: $atts['value'] = $value;
839: return geoTag("input", $value, $class, $id, $style, $atts);
840: }
841:
842: /**
843: * Create an HTML checkbox.
844: *
845: * @param string $name Name of value retured by this field
846: * @param string $text Checkbox text
847: * @param bool $isChecked Indicates that this box is checked
848: * @param string $id Id attribute. To add labels to the text, you must add $id
849: * @param string $trueOrFalse Indicates type of return value
850: * Use 't' or 'f', in which cases checkbox value will return 't' or 'f'
851: * instead of true or null
852: * If 'f' is used, checkbox will reverse true for false.
853: * When using checkbox arrays (as in checkboxName[]), use $trueOrFalse for the value
854: * @param string $extLabel External label. To create an unattached label, pass a true variable as $extlabel
855: * and then use $extLabel as the label
856: * @param string $class Class attribute
857: *
858: * @return string HTML checkbox
859: */
860: function geoCheckbox(
861: $name,
862: $text = null,
863: $isChecked = null,
864: $id = null,
865: $trueOrFalse = null,
866: &$extLabel = null,
867: $class = null
868: ) {
869:
870: $atts = array();
871:
872: if ($trueOrFalse === true) {
873: // use t/f
874: $value = "t";
875: $false = geoHidden($name, 'f');
876:
877: if ($isChecked && $isChecked != 'f') {
878: // is checked is true
879: $isChecked = true; // make it true
880: } else {
881: $isChecked = '';
882: }
883:
884: } elseif ($trueOrFalse === false) {
885: // use reverse t/f
886: $value = "f";
887: $false = geoHidden($name, 't');
888: if ($isChecked && $isChecked != 'f') {
889: // is checked is true
890: $isChecked = ''; // make it false
891: } else {
892: $isChecked = true;
893: }
894:
895: } else {
896: $false = '';
897:
898: if ($trueOrFalse) {
899: $value = $trueOrFalse;
900: } else {
901: $value = true;
902: }
903: }
904: if ($isChecked) {
905: $atts['checked'] = 'checked';
906: }
907:
908: if (!$id) {
909: $id = $name;
910: }
911:
912: $result = geoInput('checkbox', $name, $value, $atts, $id, $class);
913:
914: if ($text) {
915: $label = geoLabel(" " . $text, $id, $class);
916: if ($extLabel) {
917: $extLabel = $label;
918: } else {
919: $result .= " " . $label;
920: }
921: } else {
922: $extLabel = '';
923: }
924:
925: return $false . $result;
926: }
927:
928: /**
929: * Create an HTML submit button.
930: *
931: * @param string $value Submit button text
932: * @param string $name Name of value retured by this field
933: * @param string $class Class attribute
934: * @param string $id Id attribute
935: * @param string|array $atts Any other atts. If string, will be used as "onclick" attribute
936: * @param string $style Style attribute
937: *
938: * @return string HTML Submit Button
939: */
940: function geoSubmit($value = "Submit", $name = null, $class = null, $id = null, $atts = null, $style = null)
941: {
942: if ($atts && !is_array($atts)) {
943: $atts2["onclick"] = $atts;
944: $atts = $atts2;
945: }
946:
947: // id behaves the opposite of geoInput();
948: if (!$id) {
949: $id = true;
950: } elseif ($id===true) {
951: $id=null;
952: }
953:
954:
955: return geoInput('submit', $name, $value, $atts, $id, $class, $style);
956: }
957:
958: /**
959: * Create an HTML image submit button.
960: *
961: * @param string $src Image path
962: * @param string $name Name of value returned by this field
963: * @param string $atts Any other atts. If string, will be used as "onclick" attribute
964: * @param array|string $id Id attribute
965: * @param string $class Class attribute
966: * @param string $style Style attribute
967: *
968: * @return string HTML image submit button
969: */
970: function geoImgSubmit($src, $name = null, $atts = null, $id = null, $class = null, $style = null)
971: {
972: if ($atts && !is_array($atts)) {
973: $atts["onclick"] = $atts;
974: }
975:
976: $atts['src'] = $src;
977: return geoInput('image', $name, null, $atts, $id, $class, $style);
978: }
979:
980: /**
981: * Create HTML button.
982: *
983: * @param string $value Value returned by this field
984: * @param string $id Id Attribute
985: * @param string $class Class Attribute
986: * @param array|string $atts Any other atts. If string, will be used as "onclick" attribute
987: * @param string $name Name of value retured by this field
988: * @param string $style Style attribute
989: *
990: * @return string HTML list item
991: */
992: function geoButton($value, $id = null, $class = null, $atts = null, $name = null, $style = null)
993: {
994: if ($atts && !is_array($atts)) {
995: $newatts['onclick'] = $atts;
996: $atts = $newatts;
997: }
998: return geoInput('button', $name, $value, $atts, $id, $class, $style);
999: }
1000:
1001: /**
1002: * Create a radio button.
1003: *
1004: * @param string $name Name of radio button group
1005: * @param string $id Id attribute
1006: * @param string $label Text of label
1007: * @param bool $isChecked Indicates that this element is selected
1008: * @param string $value Radio group will return this value if this element is selected
1009: * @param array $atts Any other attributes
1010: * @param string $class Class attribute
1011: * @param bool $isScale Indicates that the radio button and its label are returned in 2 divs,
1012: * instead of together in one line. This is handy for creating 1-10 scales
1013: *
1014: * @return string HTML list item
1015: */
1016: function geoRadio(
1017: $name,
1018: $id,
1019: $label = null,
1020: $isChecked = null,
1021: $value = null,
1022: $atts = null,
1023: $class = null,
1024: $isScale = null
1025: ) {
1026:
1027: if (!isset($value)) {
1028: $value = $id;
1029: }
1030:
1031: if ($isChecked || (isset($_POST[$name]) && $_POST[$name] == $value) || ($value === "default" && !$_POST[$name])) {
1032: $atts['checked'] = 'checked';
1033: }
1034:
1035: $radio[] = geoInput('radio', $name, $value, $atts, $id, $class);
1036:
1037: if ($label) {
1038: $radio[] = geoLabel($label, $id);
1039: }
1040:
1041: if ($isScale) {
1042: return div($radio);
1043: }
1044:
1045: return implode(" ", $radio);
1046:
1047: }
1048:
1049:
1050: /**
1051: * Create a group of radio button as an HTML string or list, or as an array
1052: * All radios in 1 group have the same name and different ids
1053: *
1054: * @param string $name Name of Radio group. Also becomes id, with added index.
1055: * @param array $titles An array of $values=>$titles
1056: * @param string $default Value of selected radio button
1057: * @param mixed $listClass If this value is supplied:
1058: * If true, function returns an array of radio buttons.
1059: * If string, function returns a list with this class.
1060: * @param string $break Value of HTML between buttons
1061: * If true, function returns an array of radio buttons.
1062: * @param string $origDefault Original default value (This item receives the "default" class)
1063: * @param string $inputClass Each radio input is given this class
1064: * @param bool $isScale Causes radiobuttons to be returned inside with "geoScale" class
1065: *
1066: * @return array, list or string of rsdio buttons
1067: */
1068: function geoRadios(
1069: $name,
1070: $titles,
1071: $default = null,
1072: $listClass = null,
1073: $break = null,
1074: $origDefault = null,
1075: $inputClass = null,
1076: $isScale = null
1077: ) {
1078:
1079: if ($titles) {
1080: foreach ($titles as $k => $title) {
1081: $inputClasses = array();
1082:
1083: if ($origDefault == $k) {
1084: $inputClasses[] = "default";
1085: }
1086:
1087: if ($inputClass) {
1088: $inputClasses[] = $inputClass;
1089: }
1090: if($listClass==true){
1091: $li=$k;
1092: } else {
1093: $li="li_".$name . "_" . $k;
1094: }
1095:
1096: $radios[]=geoRadio(
1097: $name,
1098: $name . "_" . $k,
1099: $title,
1100: geoIf(isset($default) && $default == $k),
1101: $k,
1102: null,
1103: geoIf($inputClasses, implode(" ", $inputClasses)),
1104: $isScale
1105: );
1106: }
1107: }
1108: if ($isScale) {
1109: return div($radios, 'geoScale') . div(null, null, null, 'clear:both');
1110: }
1111:
1112: if ($listClass === true || $break === true) {
1113: // no list, just return array
1114: geodb($radios,'radios');
1115: return $radios;
1116: }
1117:
1118: if ($listClass) {
1119: return geoList($radios, $listClass);
1120: }
1121:
1122: // return $break between each radio button
1123: return implode($break, $radios);
1124: }
1125:
1126:
1127: /**
1128: * Create HTML label.
1129: *
1130: * @param string $text Content of list item array to test
1131: * @param string $for For of label
1132: * @param string $class Id of label
1133: * @param string $id Style of label
1134: *
1135: * @return string HTML list item
1136: */
1137: function geoLabel($text, $for, $class = null, $id = null)
1138: {
1139: return geoTag("label", $text, $class, $id, null, array("for" => $for));
1140: }
1141:
1142:
1143: /**
1144: * Create HTML list item. (Usually not neccesary since geoList takes arrays of content values)
1145: *
1146: * @param string $text Content of list item
1147: * @param string $class Class of list item
1148: * @param string $id Id of list item
1149: * @param string $style Style of list item
1150: *
1151: * @return string HTML list item
1152: */
1153: function geoItem($text = null, $class = null, $id = null, $style = null)
1154: {
1155: $item = new GeoTag('li', $text, $class, $id, $style);
1156: return $item;
1157: }
1158:
1159:
1160: /**
1161: * Create HTML list or array of lists
1162: *
1163: * @param array $lists 1 or 2 dimensional array
1164: * A 2 dimensional array will result in a list for each array.
1165: * To have ids for each list item,
1166: * make item keys non integer, such as "item_3"
1167: * @param string $class List Class or classes
1168: * If lists is multidemensional:
1169: * If class is a string, it becomes the class for all lists.
1170: * If class is an array, each row is a class for 1 list
1171: * If lists is not multidementional
1172: * If class is a string, class is a list class.
1173: * If class is an array, each row becomes a class for 1 list item
1174: * @param string $id List id
1175: * @param integer $cols Number of columns. Break $lists into one list for each column
1176: * @param array $itemClasses Array of classes for each list item
1177: * @param string $style List Style
1178: * @param string $lt List type (either ul or ol) Default is ul
1179: * @param array $itemStyles Array of styles for each list item
1180: * @param array $listItemIds Array of ids for each list item
1181: *
1182: * @return HTML List tag
1183: */
1184: function geoList(
1185: $lists = null,
1186: $class = null,
1187: $id = null,
1188: $cols = 1,
1189: $itemClasses = null,
1190: $style = null,
1191: $lt = 'ul',
1192: $itemStyles = null,
1193: $listItemIds = null
1194: ) {
1195:
1196: if (!geoIsMultiArr($lists) && is_array($class)) {
1197: $itemClasses = $class;
1198: $class="";
1199: }
1200: $lists = geoMultiArr($lists);
1201: $allLists = '';
1202: foreach ($lists as $key => $list) {
1203: $list = new GeoList(
1204: $list,
1205: Geo::ifArr($class, $key),
1206: $id,
1207: Geo::ifArr($cols, $key),
1208: Geo::ifArr($style, $key),
1209: Geo::ifArr($lt, $key)
1210: );
1211: $allLists .= $list->tag($itemClasses, $listItemIds, $itemStyles);
1212: }
1213: return $allLists;
1214: }
1215: /**
1216: * Create inline HTML list or array of lists
1217: *
1218: * @param array $lists 1 or 2 dimensional array
1219: * A 2 dimensional array will result in a list for each array.
1220: * @param string $style List Style
1221: * @param string $fontSize Font Size
1222: * @param string $margin Margin
1223: * @param integer $cols Number of columns. Break $lists into one list for each column
1224: * @param array $itemStyles Array of styles for each list item
1225: * @param string $lt List type (either ul or ol) Default is ul
1226: *
1227: * @return string List tag
1228: */
1229: function geoIList(
1230: $lists = null,
1231: $styles = null,
1232: $fontsize = null,
1233: $margin = null,
1234: $cols = 1,
1235: $itemStyles = null,
1236: $lt = 'ul'
1237: ) {
1238: $styles=Geo::arr($styles);
1239:
1240: foreach($styles as $key=>$style){
1241: if ($fontsize) {
1242: $style="font-size:".$fontsize.";".$style;
1243: }
1244: if ($margin || $margin===0) {
1245: $style="margin:".$margin.";".$style;
1246: }
1247: $styles[$key]=$style;
1248: }
1249:
1250: $lists = geoMultiArr($lists);
1251: $allLists = '';
1252:
1253: foreach ($lists as $key => $list) {
1254: $list = new GeoList(
1255: $list,
1256: null,
1257: null,
1258: Geo::ifArr($cols, $key),
1259: Geo::ifArr($styles, $key),
1260: Geo::ifArr($lt, $key)
1261: );
1262: $allLists .= $list->tag(null, null, $itemStyles);
1263: }
1264: return $allLists;
1265: }
1266:
1267:
1268: /**
1269: * Test for Multidimensional array
1270: *
1271: * @param array $array array to test
1272: *
1273: * @return bool indicates a multidimensional array
1274: */
1275: function geoIsMultiArr($array)
1276: {
1277: return count($array) != count($array, 1);
1278: }
1279:
1280:
1281: /**
1282: * Checks value, create a 2 dimensional array if it isn't already a 2 dimensional array
1283: *
1284: * @param array $array Either a 1 or 2 dimensional array
1285: * @param string $name Key value for new 2 dimensional array
1286: *
1287: * @return array 2 dimensional array
1288: */
1289: function geoMultiArr($array, $name = "0")
1290: {
1291: if (geoIsMultiArr($array)) {
1292: return $array;
1293: }
1294:
1295: return array(
1296: $name => $array
1297: );
1298: }
1299: /**
1300: * Create an HTML table
1301: *
1302: * @param array $rows Text
1303: * @param string $class Table class
1304: * @param array $titles Optional first row as separate content array
1305: * @param string $titleClass Optional class of first row
1306: * @param array $rowClasses Classes for rows (each key must match $rows keys)
1307: * @param array $colClasses Classes for columns
1308: * @param string $id Table id
1309: * @param int $cellspacing Cellspacing for all table cells
1310: * @param int $cellpadding Cellpadding for all table cells
1311: *
1312: * @return object GeoTable Object
1313: */
1314: function geoTable(
1315: $rows,
1316: $class = null,
1317: $titles = null,
1318: $titleClass = null,
1319: $rowClasses = null,
1320: $colClasses = null,
1321: $id = null,
1322: $cellspacing = 0,
1323: $cellpadding = null
1324: ) {
1325:
1326: $tableobj = new GeoTable(
1327: $rows,
1328: $class,
1329: $rowClasses,
1330: $colClasses,
1331: $id,
1332: $cellspacing,
1333: $cellpadding
1334: );
1335:
1336: if ($titles) {
1337: if (!is_array($titles)) {
1338: $titles = explode(", ", $titles);
1339: }
1340:
1341: $tableobj->setTitles($titles);
1342:
1343: if ($titleClass) {
1344: $tableobj->setRowClass(0, $titleClass);
1345: }
1346:
1347: }
1348: if (!$class) {
1349: $tableobj->setAtt("border", 1);
1350: $tableobj->setAtt("cellpadding");
1351: }
1352: if ($colClasses) {
1353: $colClasses = Geo::arr($colClasses);
1354:
1355: foreach ($colClasses as $i => $colClass) {
1356: $tableobj->setColClass($i, $colClass);
1357: }
1358: }
1359:
1360: return $tableobj->tag();
1361: }
1362:
1363: // tags without end tags.
1364: /**
1365: * Create start tags
1366: *
1367: * @param string $tag Name of HTML tag
1368: * @param string $class Class attribute
1369: * @param string $id Id attribute
1370: * @param string $style Style attribute
1371: * @param array $atts Any other attributes
1372: *
1373: * @return string HTML Tag without the end tag
1374: */
1375: function geoStart($tag, $class = null, $id = null, $style = null, $atts = null)
1376: {
1377: $GeoTag = new GeoTag($tag, null, $class, $id, $style, $atts);
1378: return $GeoTag->baseTag(true);
1379: }
1380:
1381: /**
1382: * Create end tags
1383: *
1384: * @param array $tags tags to end
1385: *
1386: * @return string End tag
1387: */
1388: function geoEnd($tags = null)
1389: {
1390: $geoEnd = '';
1391: if (!$tags) {
1392: $tags = array(
1393: 'body',
1394: 'html'
1395: );
1396: }
1397:
1398: $tags = Geo::arr($tags);
1399:
1400: foreach ($tags as $tag) {
1401: $GeoTag = new GeoTag($tag);
1402: if ($tag == "body") {
1403: $geoEnd .= GeoDebug::vars();
1404: }
1405:
1406: $geoEnd .= $GeoTag->baseTag(null, true);
1407: }
1408: return $geoEnd;
1409: }
1410:
1411: /**
1412: * Formats debugging variables for display, prints result instead of returning result
1413: *
1414: * @param mixed $variable Any type of variable being debugged
1415: * @param string $name Name used for displaying debug variable
1416: * @param bool $isHtml Display strings as HTML. Default displays hightlighted HTML tags.
1417: *
1418: * @return void
1419: */
1420: function geovar($variable, $name = "Variable", $isHtml = null)
1421: {
1422: echo GeoDebug::trace($name, null, true, true);
1423: echo GeoDebug::vr($variable, $name, $isHtml);
1424:
1425: }
1426:
1427: /**
1428: * Allows inline test for value.
1429: * Can test constants but not undefined variables.
1430: *
1431: * @param mixed $var Variable to be tested for value
1432: * @param mixed $result1 Value to be returned if test is passed
1433: * @param mixed $result2 Value to be returns if test fails
1434: *
1435: * @return mixed Result of test
1436: */
1437: function geoif($var, $result1 = true, $result2 = null)
1438: {
1439: if ($var) {
1440: return $result1;
1441: }
1442:
1443: return $result2;
1444: }
1445:
1446: // Wrappers
1447:
1448: /**
1449: * Create a table cell for a geoWTable object. Allows use of function syntax instead of object-> syntax
1450: *
1451: * @param string $celltext Text
1452: * @param string $colspan Column span
1453: * @param string $rowspan Row span
1454: * @param string $class Class
1455: * @param string $valign Valign
1456: * @param string $style Style
1457: * @param string $id Id
1458: *
1459: * @return object GeoCell Object
1460: */
1461: function geoCell($celltext, $colspan = null, $rowspan = null, $class = null, $valign = null, $style = null, $id = null)
1462: {
1463: return new GeoCell($celltext, $colspan, $rowspan, $class, $valign, $style, $id);
1464: }
1465:
1466: /**
1467: * Adds content to debugging array
1468: *
1469: * @param mixed $variable Variable being debugged
1470: * @param string $name Name used for displaying debug variable
1471: * @param bool $addBacktrace Determines whether to add backtrace to debug display
1472: * @param bool $return Determines whether debugging content is displayed
1473: * or saved. Default is saved.
1474: * @param bool $noHighlight Display strings as HTML. Default displays HTML tags.
1475: * @param bool $always Always debug, even when not in debugging mode
1476: *
1477: * @return string debug content is formatted with HTML
1478: */
1479: function geoDb(
1480: $variable = null,
1481: $name = "debug",
1482: $addBacktrace = null,
1483: $return = null,
1484: $noHighlight = null,
1485: $always = null
1486: ) {
1487: return GeoDebug::db($variable, $name, $addBacktrace, $return, $noHighlight, $always, 1);
1488: }
1489:
1490:
1491: function geoTrace(
1492: $name = null,
1493: $level = 2,
1494: $return = null,
1495: $dontTraceFrom = null
1496: ){
1497: return geoDebug::trace($name, $level, $return, $dontTraceFrom);
1498: }
1499: