File: Mobile.php

package info (click to toggle)
horde3 3.1.3-4etch7
  • links: PTS
  • area: main
  • in suites: etch
  • size: 22,876 kB
  • ctags: 18,071
  • sloc: php: 75,151; xml: 2,979; sql: 1,069; makefile: 79; sh: 64
file content (1222 lines) | stat: -rw-r--r-- 36,411 bytes parent folder | download | duplicates (2)
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
<?php
/**
 * @package Horde_Mobile
 */
class Horde_Mobile_card extends Horde_Mobile_element {

    var $_name;
    var $_title;
    var $_form;
    var $_elements = array();
    var $_softkeys = array();

    /**
     * Constructor
     *
     * @param string $name   The name of this card. Can be used in anchor
     *                       links.
     * @param string $title  If a string is provided here, it will be displayed
     *                       in the HTML title bar, respectively somewhere on
     *                       the WAP display. Using a title you will normally
     *                       have to spend one of your few lines on your WAP
     *                       display. Consider that some WAP phones/SDK's and
     *                       handheld devices don't display the title at all.
     */
    function Horde_Mobile_card($name = null, $title = null)
    {
        $this->_name = $name;
        $this->_title = $title;
    }

    function &add(&$element)
    {
        static $linksetAdded;

        if (!is_a($element, 'Horde_Mobile_element')) {
            $error = PEAR::raiseError('Invalid element.');
            return $error;
        } elseif (is_a($element, 'Horde_Mobile_text') ||
                  is_a($element, 'Horde_Mobile_table') ||
                  is_a($element, 'Horde_Mobile_image') ||
                  is_a($element, 'Horde_Mobile_link') ||
                  is_a($element, 'Horde_Mobile_phone') ||
                  is_a($element, 'Horde_Mobile_rule')) {
            $block = &new Horde_Mobile_block($element);
            $this->_elements[] = &$block;
        } elseif (is_a($element, 'Horde_Mobile_block')) {
            $this->_elements[] = &$element;
        } elseif (is_a($element, 'Horde_Mobile_form')) {
            if (!empty($this->_form)) {
                $error = PEAR::raiseError('Cards may only contain one Form element.');
                return $error;
            }
            $this->_elements[] = &$element;
            $this->_form = &$element;
        } elseif (is_a($element, 'Horde_Mobile_linkset')) {
            if (!empty($linksetAdded)) {
                $error = PEAR::raiseError('Cards may only contain one Linkset element.');
                return $error;
            }
            $block = &new Horde_Mobile_block($element);
            $this->_elements[] = &$block;
            $linksetAdded = true;
        } else {
            $error = PEAR::raiseError('This element must be inside an appropriate container element.');
            return $error;
        }

        return $element;
    }

    function softkey($url, $label)
    {
        $this->_softkeys[] = array('url' => $url,
                                   'label' => $label);
    }

}

/**
 * Horde_Mobile::
 *
 * Horde API for generating Mobile content. Includes numerous utility
 * functions, generalized element classes, and renderers for markup
 * languages including WML, HDML, and CHTML.
 *
 * This class is the top level class of all Horde_Mobile classes. Your
 * page should consist of exactly one Horde_Mobile object. Appropriate
 * markup - Imode, WML, HDML, etc. - is generated by the appropriate
 * renderer object
 *
 * Do not overstuff Horde_Mobile objects. Remember that a lot of WAP
 * clients cannot handle more than about 1400 bytes of compiled data.
 *
 * Examples:
 *
 * $myPage = new Horde_Mobile();
 * $myPage = new Horde_Mobile('My WAP page');
 * $myPage = new Horde_Mobile('', 'center');
 *
 * // More stuff
 *
 * $myPage->add($myText);
 *
 * // More items
 *
 * $myPage->render();
 *
 * $Horde: framework/Mobile/Mobile.php,v 1.32.10.9 2006/06/26 06:27:23 selsky Exp $
 *
 * Copyright 2002-2006 Chuck Hagenbuch <chuck@horde.org>
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  Chuck Hagenbuch <chuck@horde.org>
 * @since   Horde 3.0
 * @package Horde_Mobile
 */
class Horde_Mobile extends Horde_Mobile_card {

    var $_title;
    var $_elements = array();
    var $_cards = array();
    var $_debug = false;

    // Decide whether the simulator device is to be used. Only affects
    // HTML browser output.
    var $_simulator = false;

    /**
     * Constructor
     *
     * @param string $title  If a string is provided here, it will be displayed
     *                       in the HTML title bar, respectively somewhere on
     *                       the WAP display. Using a title you will normally
     *                       have to spend one of your few lines on your WAP
     *                       display. Consider that some WAP phones/SDK's and
     *                       handheld devices don't display the title at all.
     * @param string $agent  If specified, use instead of HTTP_USER_AGENT.
     */
    function Horde_Mobile($title = null, $agent = null)
    {
        if (!is_null($title)) {
            $this->_title = $title;
        }

        require_once 'Horde/Browser.php';
        $browser = &Browser::singleton($agent);

        if ($browser->hasFeature('html')) {
            $ml = 'html';
        } elseif ($browser->hasFeature('wml')) {
            $ml = 'wml';
        } else {
            $ml = 'html';
        }

        require_once dirname(__FILE__) . '/Mobile/Renderer.php';
        $this->_renderer = &Horde_Mobile_Renderer::singleton($ml, $browser);
    }

    function &add(&$element)
    {
        if (is_a($element, 'Horde_Mobile_card')) {
            if (count($this->_elements)) {
                $error = PEAR::raiseError('You cannot mix Horde_Mobile_cards and other elements at the deck level.');
                return $error;
            }

            $this->_usingCards = true;
            $this->_cards[] = &$element;

            return $element;
        } else {
            if (count($this->_cards)) {
                $error = PEAR::raiseError('You cannot mix Horde_Mobile_cards and other elements at the deck level.');
                return $error;
            }

            return parent::add($element);
        }
    }

    /**
     * Activates the built-in device simulator on bigscreen browsers.
     * The device simulator is only fully-functional in Internet
     * Explorer, because the layout requires a scrollable table
     * element. Other browsers will fail to show content on pages
     * longer than a single screen.
     */
    function useSimulator()
    {
        $this->_simulator = true;
    }

    /**
     * Creates the page in the appropriate markup language. Depending
     * on the renderer type, HTML (pure HTML, handheldfriendly AvantGo
     * HTML, i-mode cHTML, MML), WML or HDML code is created.
     */
    function display()
    {
        $this->_renderer->render($this);
    }

}

/**
 * @package Horde_Mobile
 */
class Horde_Mobile_element {

    function Horde_Mobile_element()
    {
    }

    function get($attribute)
    {
        $attr = '_' . $attribute;
        if (isset($this->$attr)) {
            return $this->$attr;
        } else {
            return null;
        }
    }

    function set($attribute, $value)
    {
        $attr = '_' . $attribute;
        $this->$attr = $value;
    }

}

/**
 * @package Horde_Mobile
 */
class Horde_Mobile_formElement extends Horde_Mobile_element {

    var $_name;
    var $_value;
    var $_label;
    var $_size;
    var $_maxlength;
    var $_type;
    var $_format;
    var $_mode;

    /**
     * Set input mode/istyle for japanese MML/i-mode devices.
     *
     * @param string $mode  Input mode, one of:
     *                      'alpha' (default)
     *                      'katakana'
     *                      'hiragana'
     *                      'numeric'
     */
    function setMode($mode)
    {
        $this->_mode = $mode;

        // Map the mode into an appropriate format string, used for
        // WML and HDML. If a format string was provided earlier, it
        // will be overwritten.
        switch ($mode) {
        case 'hiragana':
        case 'katakana':
            $this->_format = '*M';
            break;

        case 'alpha':
            $this->_format = '*m';
            break;

        case 'numeric':
            $this->_format = '*N';
            break;
        }
    }

}

/**
 * This class defines a form with various possible input elements. The
 * input elements have to be defined as separate objects and are
 * linked to the form with a special "add" function. One Horde_Mobile
 * object can contain only one Horde_Mobile_form object.
 *
 * Examples:
 *
 * $myPage = new Horde_Mobile(...);
 *
 * $myForm = new Horde_Mobile_form("/mynextpage.wml");
 * $myText = new Horde_Mobile_text(...);
 * $myForm->add($myText);
 * $myInput = new Horde_Mobile_input(...);
 * $myForm->add($myInput);
 * $mySubmit = new Horde_Mobile_submit(...);
 * $myForm->add($mySubmit);
 *
 * $myPage->add($myForm);
 *
 * $myPage->render();
 *
 * @see Horde_Mobile_text
 * @see Horde_Mobile_image
 * @see Horde_Mobile_table
 * @see Horde_Mobile_input
 * @see Horde_Mobile_textarea
 * @see Horde_Mobile_select
 * @see Horde_Mobile_radio
 * @see Horde_Mobile_checkbox
 * @see Horde_Mobile_submit
 * @see Horde_Mobile_rule
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_form extends Horde_Mobile_element {

    var $_url;
    var $_method;
    var $_elements = array();

    /**
     * Constructor
     *
     * @param string $url       Address where the user input is sent to.
     * @param string $method    'post' (default) or 'get'.
     * @param boolean $session  Preserve the sesion id in the form? Defaults to true.
     */
    function Horde_Mobile_form($url, $method = 'post', $session = true)
    {
        $this->_url = $url;
        $this->_method = $method;

        if ($session && !array_key_exists(session_name(), $_COOKIE)) {
            $this->add(new Horde_Mobile_hidden(session_name(), session_id()));
        }
    }

    function &add(&$formElement)
    {
        if (is_a($formElement, 'Horde_Mobile_submit')) {
            $formElement->_form = &$this;
            $block = &new Horde_Mobile_block($formElement);
            $this->_elements[] = &$block;
        } elseif (is_a($formElement, 'Horde_Mobile_hidden') ||
                  is_a($formElement, 'Horde_Mobile_block')) {
            $this->_elements[] = &$formElement;
        } elseif (is_a($formElement, 'Horde_Mobile_formElement') ||
                  is_a($formElement, 'Horde_Mobile_text') ||
                  is_a($formElement, 'Horde_Mobile_table') ||
                  is_a($formElement, 'Horde_Mobile_rule') ||
                  is_a($formElement, 'Horde_Mobile_image')) {
            $block = &new Horde_Mobile_block($formElement);
            $this->_elements[] = &$block;
        } else {
            $error = PEAR::raiseError('Specified element cannot be inside a form.');
            return $error;
        }

        return $formElement;
    }

    function getDefaults()
    {
        $defaults = array();
        foreach ($this->_elements as $val) {
            switch (strtolower(get_class($val))) {
            case 'horde_mobile_hidden':
                $defaults[] = array('name' => $val->get('name'),
                                    'value' => $val->get('value'),
                                    'hidden' => true);
                break;

            case 'horde_mobile_block':
                foreach ($val->_elements as $bval) {
                    switch (strtolower(get_class($bval))) {
                    case 'horde_mobile_checkbox':
                        if ($bval->isChecked()) {
                            $defaults[] = array('name' => $bval->get('name'),
                                                'value' => $bval->get('value'));
                        }
                        break;

                    case 'horde_mobile_input':
                    case 'horde_mobile_textarea':
                    case 'horde_mobile_select':
                    case 'horde_mobile_radio':
                        $defaults[] = array('name' => $bval->get('name'),
                                            'value' => $bval->get('value'));
                        break;

                    case 'horde_mobile_hidden':
                        $defaults[] = array('name' => $bval->get('name'),
                                            'value' => $bval->get('value'),
                                            'hidden' => true);
                        break;

                    case 'horde_mobile_table':
                        foreach ($bval->_rows as $row) {
                            foreach ($row->_columns as $col) {
                                switch (strtolower(get_class($col))) {
                                case 'horde_mobile_checkbox':
                                    if ($col->isChecked()) {
                                        $defaults[] = array('name' => $bval->get('name'),
                                                            'value' => $bval->get('value'));
                                    }
                                    break;

                                case 'horde_mobile_input':
                                case 'horde_mobile_textarea':
                                case 'horde_mobile_select':
                                case 'horde_mobile_radio':
                                    $defaults[] = array('name' => $bval->get('name'),
                                                        'value' => $bval->get('value'));
                                    break;

                                case 'horde_mobile_hidden':
                                    $defaults[] = array('name' => $bval->get('name'),
                                                        'value' => $bval->get('value'),
                                                        'hidden' => true);
                                    break;
                                }
                            }
                        }
                        break;
                    }
                }
                break;
            }
        }

        return $defaults;
    }

    function getGetVars()
    {
        // Determine all elements that have to be submitted.
        $getvars = array();
        foreach ($this->_elements as $val) {
            switch (strtolower(get_class($val))) {
            case 'horde_mobile_block':
                foreach ($val->_elements as $bval) {
                    switch (strtolower(get_class($bval))) {
                    case 'horde_mobile_input':
                    case 'horde_mobile_hidden':
                    case 'horde_mobile_textarea':
                    case 'horde_mobile_select':
                    case 'horde_mobile_checkbox':
                    case 'horde_mobile_radio':
                        $getvars[] = $bval->get('name');
                        break;

                    case 'horde_mobile_table':
                        foreach ($bval->_rows as $row) {
                            foreach ($row->_columns as $col) {
                                switch (strtolower(get_class($col))) {
                                case 'horde_mobile_input':
                                case 'horde_mobile_hidden':
                                case 'horde_mobile_textarea':
                                case 'horde_mobile_select':
                                case 'horde_mobile_checkbox':
                                case 'horde_mobile_radio':
                                    $getvars[] = $col->get('name');
                                    break;
                                }
                            }
                        }
                        break;
                    }
                }
                break;
            }
        }

        return $getvars;
    }

}

/**
 * This class holds text-level elements for use in Horde_Mobile or
 * Horde_Mobile_form objects.
 *
 * Examples:
 *
 * $block = new Horde_Mobile_block("Hello WAP!");
 * $text = new Horde_Mobile_text("Welcome to Horde_Mobile", 'b');
 * $block->add($text);
 *
 * @see Horde_Mobile
 * @see Horde_Mobile_form
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_block extends Horde_Mobile_element {

    var $_elements = array();

    /**
     * Constructor.
     *
     * @param mixed $elements  Any elements (a single one or an array) to fill this block with.
     */
    function Horde_Mobile_block(&$elements)
    {
        if (!is_null($elements)) {
            if (!is_array($elements)) {
                $this->add($elements);
            } else {
                foreach ($elements as $element) {
                    $this->add($element);
                }
            }
        }
    }

    function &add(&$element)
    {
        if (!is_a($element, 'Horde_Mobile_element')) {
            $error = PEAR::raiseError('Invalid element.');
        } elseif (is_a($element, 'Horde_Mobile_text') ||
                  is_a($element, 'Horde_Mobile_table') ||
                  is_a($element, 'Horde_Mobile_image') ||
                  is_a($element, 'Horde_Mobile_formElement') ||
                  is_a($element, 'Horde_Mobile_link') ||
                  is_a($element, 'Horde_Mobile_linkset') ||
                  is_a($element, 'Horde_Mobile_phone') ||
                  is_a($element, 'Horde_Mobile_rule')) {
            $this->_elements[] = &$element;
            return $element;
        } else {
            $error = PEAR::raiseError('The element is not allowed inside a block.');
        }
        return $error;
    }

}

/**
 * This class inserts plain text into a Horde_Mobile_block or a
 * Horde_Mobile_row object.
 *
 * Examples:
 *
 * $myText1 = new Horde_Mobile_text("Hello WAP!");
 * $myText2 = new Horde_Mobile_text("Welcome to Horde_Mobile", 'b');
 * $myText3 = new Horde_Mobile_text("Good Morning", array('b', 'big'));
 *
 * @see Horde_Mobile_block
 * @see Horde_Mobile_row
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_text extends Horde_Mobile_element {

    var $_text = '';
    var $_attributes = array();
    var $_linebreaks = false;

    /**
     * Constructor
     * @param string $text       The text content of the element.
     * @param array $attributes  Text attributes. Any of:
     *   'b'
     *   'u'
     *   'i'
     *   'big'
     *   'small'
     */
    function Horde_Mobile_text($text, $attributes = array())
    {
        $this->_text = $text;
        if (!is_array($attributes)) {
            $attributes = array($attributes);
        }
        $this->_attributes = $attributes;
    }

}

/**
 * This class allows to insert bitmap images into a Horde_Mobile_block,
 * Horde_Mobile_form or Horde_Mobile_row object.
 *
 * Examples:
 *
 * $image = new Horde_Mobile_image('/path/to/image.wbmp',
 *                                 array('height' => 100, 'width' => 100));
 *
 * @see Horde_Mobile_block
 * @see Horde_Mobile_form
 * @see Horde_Mobile_row
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_image extends Horde_Mobile_element {

    var $_src = '';
    var $_attributes = array();

    /**
     * Constructor
     * @param string $src        The source location of the image.
     * @param array $attributes  Image attributes. Any of:
     *   'align'
     *   'alt'
     *   'height'
     *   'hspace'
     *   'vspace'
     *   'width'
     *   'class'
     *   'id'
     */
    function Horde_Mobile_image($src, $attributes = array())
    {
        $this->_src = $src;
        $this->_attributes = $attributes;
    }

}

/**
 * This class allows to insert tables into a Horde_Mobile or
 * Horde_Mobile_form object.
 *
 * Examples:
 *
 * $myTable = new Horde_Mobile_table();
 *
 * $row1 = new Horde_Mobile_row();
 * $row1->add($image1);
 * $row1->add($text1);
 * $myTable->add($row1);
 *
 * $row2 = new Horde_Mobile_row();
 * $row2->add($image2);
 * $row2->add($text2);
 * $myTable->add($row2);
 *
 * $myDeck->add($myTable);
 *
 * @see Horde_Mobile
 * @see Horde_Mobile_form
 * @see Horde_Mobile_row
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_table extends Horde_Mobile_element {

    var $_rows = array();
    var $_border = null;
    var $_padding = null;
    var $_spacing = null;

    /**
     * Adds a Horde_Mobile_row object to Horde_Mobile_table.
     *
     * @param Horde_Mobile_row $row  The row object to add.
     */
    function &add(&$row)
    {
        if (!is_a($row, 'Horde_Mobile_row')) {
            $error = PEAR::raiseError('Rows must be Horde_Mobile_row objects.');
            return $error;
        }

        $this->_rows[] = &$row;
        return $row;
    }

}

/**
 * This class defines the rows that a Horde_Mobile_table object
 * consists of.
 *
 * Examples:
 *
 * $image1 = new Horde_Mobile_image("my_image.wbmp", "my_image.png", ":-)");
 * $text1 = new Horde_Mobile_text("my text");
 * $row1 = new Horde_Mobile_row();
 * $row1->add($image1);
 * $row1->add();
 * $row1->add($text1);
 *
 * @see Horde_Mobile_table
 * @see Horde_Mobile_text
 * @see Horde_Mobile_image
 * @see Horde_Mobile_link
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_row extends Horde_Mobile_element {

    var $_columns = array();

    /**
     * Adds a column element to a Horde_Mobile_row object.
     *
     * @param Horde_Mobile_element $cellElement  Can be a Horde_Mobile_text
     *                                           object, a Horde_Mobile_image
     *                                           object, a Horde_Mobile_link
     *                                           object or null. The latter
     *                                           results in an empty cell.
     */
    function &add($cellElement = null)
    {
        if (is_object($cellElement)) {
            if (!is_a($cellElement, 'Horde_Mobile_text') &&
                !is_a($cellElement, 'Horde_Mobile_link') &&
                !is_a($cellElement, 'Horde_Mobile_image')) {
                $error = PEAR::raiseError('Table cells can only contain text, links, or images.');
                return $error;
            }
            $this->_columns[] = &$cellElement;
            return $cellElement;
        } elseif (!is_null($cellElement)) {
            $t = &new Horde_Mobile_text($cellElement);
            $this->_columns[] = &$t;
            return $t;
        } else {
            $this->_columns[] = &$cellElement;
            return $cellElement;
        }
    }

    function getColumnCount()
    {
        return count($this->_columns);
    }

}

/**
 * This class provides a text input field in a Horde_Mobile_form object.
 *
 * Examples:
 *
 * $myInput1 = new Horde_Mobile_input('cid', '', 'Customer ID');
 *
 * $myInput2 = new Horde_Mobile_input('cid', '', 'Customer ID', '*N');
 * $myInput2->set_size(6);
 * $myInput2->set_maxlength(6);
 *
 * $myInput3 = new Horde_Mobile_input('pw', '', 'Password', '*N');
 * $myInput3->set_size(8);
 * $myInput3->set_maxlength(8);
 * $myInput3->set_type('password');
 *
 * @see Horde_Mobile_form
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_input extends Horde_Mobile_formElement {

    /**
     * Constructor
     *
     * @param string $name    Variable in which the input is sent to the
     *                        destination URL.
     * @param string $value   Initial value that will be presented in the
     *                        input field.
     * @param string $label   Describes your input field on the surfer's
     *                        screen/display.
     * @param string $format  Input format code according to the WAP standard.
     *                        Allows the WAP user client e.g. to input only
     *                        digits and no characters. On an HTML generated
     *                        page this format has no significance.
     */
    function Horde_Mobile_input($name, $value, $label = '', $format = '*M')
    {
        $this->_name = $name;
        $this->_value = $value;
        $this->_label = $label;
        $this->_format = $format;
        $this->_type = 'text';
        $this->_mode = 'alpha';
    }

}

/**
 * This class provides an input textarea in a Horde_Mobile_form object.
 *
 * Examples:
 *
 * $myArea1 = new Horde_Mobile_textarea('fb', '', 'Feedback');
 * $myArea2 = new Horde_Mobile_textarea('msg', 'Enter message here ...', 'Message', 40, 5);
 *
 * @see Horde_Mobile_form
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_textarea extends Horde_Mobile_formElement {

    var $_rows;
    var $_cols;

    /**
     * Constructor.
     *
     * @param string $name   Variable in which the input is sent to the
     *                       destination URL.
     * @param string $value  Initial value that will be presented in the
     *                       textarea.
     * @param string $label  Describes your textarea on the surfer's
     *                       screen/display.
     * @param integer $rows  Rows.
     * @param integer $cols  Columns.
     */
    function Horde_Mobile_textarea($name, $value, $label, $rows = 3, $cols = 16)
    {
        $this->_name = $name;
        $this->_value = $value;
        $this->_label = $label;
        $this->_rows = $rows;
        $this->_cols = $cols;
        $this->_mode = 'alpha';
    }

}

/**
 * This class provides a select element in a Horde_Mobile_form object.
 * It allows to create optimized WML for WAP devices which are capable
 * to interprete the Openwave GUI extensions for WML 1.3. All other
 * WML devices receive WML 1.1 compatible markup code, which is quite
 * similar to the markup code created by the Horde_Mobile_radio class.
 *
 * Examples:
 *
 * $mySelect = new Horde_Mobile_select('color');
 * $mySelect->add('Blue', 'b');
 * $mySelect->add('Red', 'r', true);
 * $mySelect->add('Yellow', 'y');
 *
 * @see Horde_Mobile_form
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_select extends Horde_Mobile_formElement {

    var $_type;
    var $_options = array();

    /**
     * Constructor
     *
     * @param string $name  Variable in which the information about the
     *                      selected option is sent to the destination URL.
     * @param string $type  Type of select area:
     *                      'popup': popup the whole selection list
     *                      'spin':  rotate options on a WAP device screen (OW
     *                               1.3 GUI only).
     */
    function Horde_Mobile_select($name, $type = 'popup')
    {
        $this->_name = $name;
        $this->_type = $type;
        $this->_value = null;
    }

    /**
     * Adds one option to a Horde_Mobile_select object.
     *
     * @param string $label         Describes the option on the surfer's
     *                              screen/display.
     * @param string $value         Value sent in the "name" variable, if this
     *                              is the option selected.
     * @param boolean $is_selected  Allowed values are true or false.
     */
    function add($label, $value, $is_selected = false)
    {
        $this->_options[] = array('label' => $label,
                                  'value' => $value);

        if (is_null($this->_value) || $is_selected) {
            $this->_value = $value;
        }
    }

}

/**
 * This class provides a radio button element in a Horde_Mobile_form object.
 *
 * Examples:
 *
 * $myRadio = new Horde_Mobile_radio('country');
 * $myRadio->add('Finland', 'F');
 * $myRadio->add('Germany', 'G', true);
 * $myRadio->add('Sweden', 'S');
 *
 * @see Horde_Mobile_form
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_radio extends Horde_Mobile_formElement {

    var $_buttons = array();

    /**
     * Constructor
     *
     * @param string $name  Variable in which the information about the pressed button
     *                      is sent to the destination URL.
     */
    function Horde_Mobile_radio($name)
    {
        $this->_name = $name;
        $this->_value = null;
    }

    /**
     * Adds one radio button to a Horde_Mobile_radio object.
     *
     * @param string $label        Describes the radiobutton on the surfer's
     *                             screen/display.
     * @param string $value        Value sent in the "name" variable, if this
     *                             button is selected.
     * @param boolean $is_checked  Allowed values are true or false.
     */
    function add($label, $value, $is_checked = false)
    {
        $this->_buttons[] = array('label' => $label,
                                  'value' => $value);

        if (!$this->_value || ($is_checked)) {
            $this->_value = $value;
        }
    }

}

/**
 * This class provides a single checkbox element in a Horde_Mobile_form object.
 *
 * Examples:
 *
 * $myCheckbox = new Horde_Mobile_checkbox('agmt', 'yes', 'I agree');
 * $myCheckbox = new Horde_Mobile_checkbox('agmt', 'yes', 'I agree', false);
 * $myCheckbox = new Horde_Mobile_checkbox('agmt', 'yes', 'I agree', true);
 *
 * @note The first and second examples are identical.
 *
 * @see Horde_Mobile_form
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_checkbox extends Horde_Mobile_formElement {

    var $_checked;

    /**
     * Constructor
     *
     * @param string $name      Variable in which "value" is sent to the
     *                          destination URL, if the box is checked.
     * @param string $value     See name.
     * @param string $label     Describes the checkbox on the surfer's
     *                          screen/display.
     * @param boolean $checked  Allowed values are true or false.
     */
    function Horde_Mobile_checkbox($name, $value, $label, $checked = false)
    {
        $this->_name  = $name;
        $this->_value = $value;
        $this->_label = $label;
        $this->_checked = $checked;
    }

    function isChecked()
    {
        return $this->_checked;
    }

}

/**
 * This class provides hidden elements in Horde_Mobile_form objects.
 *
 * Examples:
 *
 * $hidden = new Horde_Mobile_hidden('internal_reference', '08154711');
 *
 * @see Horde_Mobile_form
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_hidden extends Horde_Mobile_formElement {

    /**
     * Constructor
     *
     * @param string $name   Variable in which $value is sent to the destination URL.
     * @param string $value  See name.
     */
    function Horde_Mobile_hidden($name, $value)
    {
        $this->_name = $name;
        $this->_value = $value;
    }

}

/**
 * This class provides a submit button for a Horde_Mobile_form object. One
 * Horde_Mobile_form object can contain only one Horde_Mobile_submit object.
 *
 * Examples:
 * $mySubmit = &new Horde_Mobile_submit('Submit');
 * $mySubmit = &new Horde_Mobile_submit('Submit', 'user_pressed');
 *
 * @see Horde_Mobile_form
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_submit extends Horde_Mobile_formElement {

    var $_form;

    /**
     * Constructor
     *
     * @param string $label  What's written on the button.
     * @param string $name   Variable in which "label" is sent to the
     *                       destination URL.
     */
    function Horde_Mobile_submit($label, $name = '')
    {
        $this->_label = $label;
        $this->_name = $name;
    }

}

/**
 * This class provides a link in a Horde_Mobile, Horde_Mobile_linkset or
 * Horde_Mobile_table object.
 *
 * Examples:
 *
 * $myPage = new Horde_Mobile(...);
 *
 * $myLink = new Horde_Mobile_link('Continue', '/mynextpage.wml');
 * $myPage->add($myLink);
 *
 * @see Horde_Mobile
 * @see Horde_Mobile_linkset
 * @see Horde_Mobile_table
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_link extends Horde_Mobile_element {

    var $_label;
    var $_url;
    var $_title;
    var $_accesskey;

    /**
     * Constructor
     *
     * @param string $label  Describes the link on the surfer's screen/display.
     * @param string $url    Next destination address. MUST be valid XML (&amp; instead of &, etc.).
     * @param string $title  If a string is provided here, it will be displayed
     *                       in the HTML browser status bar during
     *                       "MouseOver", respectively somewhere on the WAP
     *                       display. In order to work well with a broad range
     *                       of user agents, keep your title under 6
     *                       characters.
     */
    function Horde_Mobile_link($label, $url, $title = '')
    {
        $this->_label = $label;
        $this->_url = $url;
        $this->_title = $title;

        // No accesskey assigned by default; can be assigned later
        // from a Horde_Mobile_linkset object if required.
        $this->_accesskey = null;
    }

}

/**
 * This class provides a phone number in a Horde_Mobile object. If supported by
 * their mobile device, users can establish a voice connection to the
 * specified number.
 *
 * Examples:
 *
 * $myPhone = &new Horde_Mobile_phone('123-45678', 'CALL');
 * $myPage->add($myPhone);
 *
 * @see Horde_Mobile
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_phone extends Horde_Mobile_element {

    var $_label;
    var $_number;
    var $_title;

    /**
     * Constructor
     *
     * @param string $phone_number  Phone number to dial.
     * @param string $title         If a string is provided here, the call
     *                              button on a WAP/HDML device will be
     *                              enabled. In order to work well with
     *                              a broad range of user agents, keep your
     *                              title under 6 characters.
     */
    function Horde_Mobile_phone($phone_number, $title = '')
    {
        $this->_label = $phone_number;
        $this->_number = preg_replace('|\D|', '', $phone_number);
        $this->_title = $title;
    }

}

/**
 * This class defines a set of links. The links have to be defined as
 * separate Horde_Mobile_link objects and are attached to the linkset
 * with a special "add" function.  For WAP devices browser-dependent
 * WML code will be created. On all UP-browser-based WAP devices
 * linksets allow easier navigation through WML decks by using the
 * "onpick" WML option and therefore are improving the "usability" of
 * an application. Instead of painfully navigating through the links
 * "sports->football->results->today" the mobile user e.g. can press
 * "2431" on the keypad to enter his favorite deck. For all other WAP
 * devices normal <a> tags are created. One Horde_Mobile object can
 * contain only one linkset object.
 *
 * Examples:
 *
 * $myPage = new Horde_Mobile(...);
 *
 * $myLinkset = new Horde_Mobile_linkset();
 * $myLink1 = new Horde_Mobile_link("Phonebook", "/wap/phonebook.wml");
 * $myLinkset->add($myLink1);
 * $myLink2 = new Horde_Mobile_link("DateBook", "/wap/datebook.wml");
 * $myLinkset->add($myLink2);
 *
 * $myPage->add($myLinkset);
 *
 * $myPage->render();
 *
 * @see Horde_Mobile_link
 * @see Horde_Mobile
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_linkset extends Horde_Mobile_element {

    var $_elements;

    /**
     * Adds a Horde_Mobile_link object to Horde_Mobile_linkset.
     *
     * @param Horde_Mobile_link $link  The link object to add.
     *
     * @see Horde_Mobile_link
     */
    function &add(&$link)
    {
        if (!is_a($link, 'Horde_Mobile_link')) {
            $error = PEAR::raiseError('Links must be Horde_Mobile_link objects.');
            return $error;
        }

        $this->_elements[] = &$link;
        $link->set('accesskey', count($this->_elements));

        return $link;
    }

}

/**
 * This class will cause a horizontal rule to be drawn across the screen.  You
 * can use it to separate text paragraphs in Horde_Mobile or Horde_Mobile_form
 * objects.
 *
 * Examples:
 *
 * $myDefaultRule = new Horde_Mobile_rule();
 * $mySpecialRule = new Horde_Mobile_rule('60%', 4);
 *
 * $myPage->add($myDefaultRule);
 *
 * $myPage->add($mySpecialRule);
 *
 * @see Horde_Mobile
 * @see Horde_Mobile_form
 *
 * @package Horde_Mobile
 */
class Horde_Mobile_rule extends Horde_Mobile_element {

    var $_width;
    var $_size;

    /**
     * Constructor
     *
     * @param integer $width  Percentage of screen width or absolute value in
     *                        number of pixels (e.g. "50%", 100).
     * @param integer $size   Height of the line to be drawn in pixels.
     */
    function Horde_Mobile_rule($width = '', $size = '')
    {
        $this->_width = $width;
        $this->_size = $size;
    }

}