Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
option_list.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_attribute.inc';
19 
20 define('SQ_OPTION_LIST_DELIMITER_UNIX', "\n");
21 define('SQ_OPTION_LIST_DELIMITER_WINDOWS', "\r\n");
22 define('SQ_OPTION_LIST_DELIMITER_MAC', "\n");
23 
39 {
40 
41 
48  var $delimiter = SQ_OPTION_LIST_DELIMITER_WINDOWS;
49 
50 
58  function Asset_Attribute_Option_List($attributeid=0, $value=NULL, $delimiter=SQ_OPTION_LIST_DELIMITER_WINDOWS)
59  {
60  // As per Bug #2950, asset_attribute.inc passes a third parameter as an array
61  // Check if delimiter is *NOT* an array, and set it as a delimiter
62  if (!is_array($delimiter)) {
63  $this->delimiter = $delimiter;
64  }
65 
66  $this->Asset_Attribute($attributeid, $value);
67  $this->_edit_params['width'] = '';
68 
69  }//end constructor
70 
71 
80  function setEditParams(&$node)
81  {
82  if (!parent::setEditParams($node)) return FALSE;
83  if (isset($node->attributes()->allow_reorder)) {
84  if (strtolower($node->attributes()->allow_reorder) == 'no') {
85  $this->_edit_params['allow_reorder'] = FALSE;
86  } else {
87  $this->_edit_params['allow_reorder'] = TRUE;
88  }//end if
89  }//end if
90  return TRUE;
91 
92  }//end setEditParams()
93 
94 
105  function paint($prefix, $read_only=FALSE, $use_delimiter=TRUE)
106  {
107  $allow_reorder = array_get_index($this->_edit_params, 'allow_reorder', TRUE);
108 
109  $prefix = str_replace(':','_',$prefix); // handle shadow assets
110  if (!$use_delimiter) {
111  $value = @unserialize($this->value);
112  } else {
113  $value = explode($this->delimiter, $this->value);
114  }//end if
115  if (!is_array($value) && empty($value)) {
116  // If empty, give it a blank option
117  $value = Array('0'=>'');
118  }//end if
119 
120  if (!$read_only) {
121  ?>
122  <div id="option-list-<?php echo $prefix; ?>">
123  <?php
124  $order = 0;
125 
126  // Find the last key for the next empty options
127  $temp_value = $value;
128  end($temp_value);
129  $last_number = key($temp_value);
130  $next_number = '0';
131  if (empty($value)) {
132  $next_number = '0';
133  } else if ($last_number >= 0) {
134  $next_number = $last_number + 1;
135  }//end if
136 
137  foreach ($value as $k => $v) {
138  $v = htmlspecialchars($v);
139  ?>
140  <input type="text" name="<?php echo $prefix; ?>_options[]" value="<?php echo $v; ?>" id="<?php echo $prefix; ?>_options[<?php echo $order; ?>]" <?php echo ($this->_edit_params['width'] ? 'size="'.$this->_edit_params['width'].'"' : ''); ?> /><button type="button" tabindex="99999" class="delete-button">&nbsp;</button>
141  <?php
142  if ($allow_reorder) {
143  if ($order !=0) {
144  $this->_printMoveUpButton($order, $prefix);
145  }
146  $this->_printMoveDownButton($order, $prefix);
147  }//end if
148  ?><br />
149  <?php
150  $order++;
151  }
152  for ($i = $next_number; $i < ($next_number + 2); $i++) {
153  ?>
154  <input type="text" name="<?php echo $prefix; ?>_options[]" id="<?php echo $prefix; ?>_options[<?php echo $order; ?>]" <?php echo ($this->_edit_params['width'] ? 'size="'.$this->_edit_params['width'].'"' : ''); ?> /><button type="button" tabindex="99999" class="delete-button">&nbsp;</button>
155  <?php
156  if ($allow_reorder) {
157  $this->_printMoveUpButton($order, $prefix);
158  if ($i < ($next_number + 1)) {
159  $this->_printMoveDownButton($order, $prefix);
160  }
161  }//end if
162  ?>
163  <br />
164  <?php
165  $order++;
166  }
167  ?>
168  </div>
169  <script type="text/javascript" src="<?php echo sq_web_path('lib'); ?>/js/edit.js"></script>
170  <script type="text/javascript">
171  <?php
172  // Yeesh... this is hackish but this essentially (attempts to)
173  // correct the lack of delete-button class in front-end
174  // asset builder creation
175  if (!SQ_IN_BACKEND && !SQ_IN_LIMBO) {
176  ?>
177  buttons = document.getElementsByTagName('BUTTON');
178  for (i = 0; i < buttons.length; i++) {
179  if (buttons[i].className == 'delete-button') {
180  with (buttons[i].style) {
181  backgroundImage = 'url(<?php echo sq_web_path('lib') ?>/web/images/icons/delete.png)';
182  backgroundPosition = '50% 50%';
183  backgroundRepeat = 'no-repeat';
184  width = '16px';
185  height = '16px';
186  backgroundColor = 'transparent';
187  border = '0px';
188  cursor = 'pointer';
189  }
190  }
191  }
192  <?php
193  }
194  ?>
195  var optionItemPrefix = '<?php echo $prefix; ?>';
196  // attach the event handlers
197  var optionList = document.getElementById('option-list-<?php echo $prefix; ?>');
198  var inputs = optionList.getElementsByTagName('INPUT');
199  for (var j=0; j < inputs.length; j++) {
200  <?php if ($allow_reorder) { ?>
201  inputs[j].onfocus = expandListFn;
202  <?php } else { ?>
203  inputs[j].onfocus = noreorderExpandListFn;
204  <?php } ?>
205  }
206  var buttons = optionList.getElementsByTagName('BUTTON');
207  for (var j=0; j < buttons.length; j++) {
208  <?php if ($allow_reorder) { ?>
209  buttons[j].onclick = deleteRowFn;
210  <?php } else { ?>
211  buttons[j].onclick = noreorderDeleteRowFn;
212  <?php } ?>
213  }
214 
215  lastOrder = <?php echo $order; ?>;
216  </script>
217  <?php
218  } else {
219  if (!empty($value)) {
220  echo '<ul><li>'.implode('</li><li>', $value).'</li></ul>';
221  } else {
222  echo translate('not_set');
223  }//end if
224  }//end if
225 
226  }//end paint()
227 
228 
238  function _printMoveDownButton($order, $prefix)
239  {
240  ?>
241  <a href="#" style="cursor:pointer;" onclick="listMoveDown(this, document.getElementById('option-list-<?php echo $prefix; ?>'));return false;" tabindex="99999" name="movedown" id="<?php echo $prefix; ?>_options[<?php echo $order; ?>]"><script type="text/javascript">sq_print_icon("<?php echo sq_web_path('lib').'/web/images/icons/down_arrow.png' ?>", "16", "16", "Move Down");</script></a>
242  <?php
243 
244  }//end _printMoveDownButton()
245 
246 
256  function _printMoveUpButton($order, $prefix)
257  {
258  ?>
259  <a href="#" style="cursor:pointer;" onclick="listMoveUp(this, document.getElementById('option-list-<?php echo $prefix; ?>'));return false;" tabindex="99999" name="moveup" id="<?php echo $prefix; ?>_options[<?php echo $order; ?>]"><script type="text/javascript">sq_print_icon("<?php echo sq_web_path('lib').'/web/images/icons/up_arrow.png' ?>", "16", "16", "Move Up");</script></a>
260  <?php
261 
262  }//end _printMoveUpButton()
263 
264 
274  function process($prefix, $use_delimiter=TRUE)
275  {
276  $prefix = str_replace(':','_',$prefix); // handle shadow assets
277  if (!isset($_REQUEST[$prefix.'_options'])) return;
278  $value = $_REQUEST[$prefix.'_options'];
279  foreach ($value as $i => $v) {
280  if ($v == '') unset($value[$i]);
281  }
282 
283  if (!$use_delimiter) {
284  $processed_value = serialize($value);
285  } else {
286  $processed_value = implode($this->delimiter,$value);
287  }//end if
288  $this->processed = $this->setValue($processed_value);
289 
290  }//end process()
291 
292 
300  {
301 
302  $option_array = explode($this->delimiter, $this->value);
303  $option_xml = '';
304  foreach ($option_array as $option) {
305  $option_xml .= '<option><![CDATA['.$option.']]></option>';
306  }
307  $xml = '<value>'.$option_xml.'</value>';
308 
309  return $xml;
310 
311  }//end exportContentsToXML()
312 
313 
314 }//end class
315 
316 ?>