1<?php
2
3class ButtonBrokenImageBox extends BrokenImgBox {
4  var $_field_name;
5  var $_field_value;
6  var $_action_url;
7
8  function ButtonBrokenImageBox($width, $height, $alt, $field, $value, $action_url) {
9    $this->BrokenImgBox($width, $height, $alt);
10
11    $this->_field_name  = $field;
12    $this->_field_value = $value;
13    $this->set_action_url($action_url);
14  }
15
16  function readCSS(&$state) {
17    parent::readCSS($state);
18
19    $this->_readCSS($state,
20                    array(CSS_HTML2PS_FORM_ACTION));
21  }
22
23  function set_action_url($action_url) {
24    $this->_action_url = $action_url;
25  }
26
27  function show(&$driver) {
28    $status = parent::show($driver);
29
30    global $g_config;
31    if ($g_config['renderforms']) {
32      $driver->field_pushbuttonimage($this->get_left_padding(),
33                                     $this->get_top_padding(),
34                                     $this->get_width()  + $this->get_padding_left() + $this->get_padding_right(),
35                                     $this->get_height() + $this->get_padding_top()  + $this->get_padding_bottom(),
36                                     $this->_field_name,
37                                     $this->_field_value,
38                                     $this->_action_url);
39    };
40
41    return $status;
42  }
43}
44
45class ButtonImageBox extends ImgBox {
46  var $_field_name;
47  var $_field_value;
48  var $_action_url;
49
50  function ButtonImageBox($img, $field, $value, $action_url) {
51    $this->ImgBox($img);
52
53    $this->_field_name  = $field;
54    $this->_field_value = $value;
55    $this->set_action_url($action_url);
56  }
57
58  function readCSS(&$state) {
59    parent::readCSS($state);
60
61    $this->_readCSS($state,
62                    array(CSS_HTML2PS_FORM_ACTION));
63  }
64
65  function set_action_url($action_url) {
66    $this->_action_url = $action_url;
67  }
68
69  function show(&$driver) {
70    $status = parent::show($driver);
71
72    global $g_config;
73    if ($g_config['renderforms']) {
74      $driver->field_pushbuttonimage($this->get_left_padding(),
75                                     $this->get_top_padding(),
76                                     $this->get_width()  + $this->get_padding_left() + $this->get_padding_right(),
77                                     $this->get_height() + $this->get_padding_top()  + $this->get_padding_bottom(),
78                                     $this->_field_name,
79                                     $this->_field_value,
80                                     $this->_action_url);
81    };
82
83    return $status;
84  }
85
86  function &create(&$root, &$pipeline) {
87    $name  = $root->get_attribute('name');
88    $value = $root->get_attribute('value');
89
90    $url_autofix = new AutofixUrl();
91    $src = $url_autofix->apply(trim($root->get_attribute("src")));
92
93    $src_img = ImageFactory::get($pipeline->guess_url($src), $pipeline);
94    if (is_null($src_img)) {
95      error_log(sprintf("Cannot open image at '%s'", $src));
96
97      if ($root->has_attribute('width')) {
98        $width = px2pt($root->get_attribute('width'));
99      } else {
100        $width = px2pt(BROKEN_IMAGE_DEFAULT_SIZE_PX);
101      };
102
103      if ($root->has_attribute('height')) {
104        $height = px2pt($root->get_attribute('height'));
105      } else {
106        $height = px2pt(BROKEN_IMAGE_DEFAULT_SIZE_PX);
107      };
108
109      $alt = $root->get_attribute('alt');
110
111      $css_state =& $pipeline->get_current_css_state();
112      $box =& new ButtonBrokenImagebox($width, $height, $alt, $name, $value,
113                                       $css_state->get_property(CSS_HTML2PS_FORM_ACTION));
114      $box->readCSS($css_state);
115      return $box;
116    };
117
118    $css_state =& $pipeline->get_current_css_state();
119    $box =& new ButtonImageBox($src_img, $name, $value,
120                               $css_state->get_property(CSS_HTML2PS_FORM_ACTION));
121    $box->readCSS($css_state);
122    $box->_setupSize();
123
124    return $box;
125  }
126}
127
128?>