/usr/share/php/Horde/Form/Action/ConditionalSetValue.php is in php-horde-form 2.0.12-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <?php
/**
* Horde_Form_Action_ConditionalSetValue is a Horde_Form_Action that
* sets the value of one Horde_Form variable based on the value of the
* variable the action is attached to.
*
* Copyright 2002-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @package Form
*/
class Horde_Form_Action_ConditionalSetValue extends Horde_Form_Action {
/**
* Which JS events should trigger this action?
*
* @var array
*/
var $_trigger = array('onchange', 'onload');
function getActionScript($form, $renderer, $varname)
{
return 'map(\'' . $renderer->_genID($varname, false) . "', '" . $renderer->_genID($this->getTarget(), false) . '\');';
}
function setValues(&$vars, $sourceVal, $arrayVal = false)
{
$map = $this->_params['map'];
$target = $this->getTarget();
if ($arrayVal) {
$i = 0;
if (is_array($sourceVal)) {
foreach ($sourceVal as $val) {
if (!empty($map[$val])) {
$vars->set($target, $map[$val], $i);
}
$i++;
}
}
} else {
if (!empty($map[$sourceVal])) {
$vars->set($target, $map[$sourceVal]);
}
}
}
function printJavaScript()
{
$this->_printJavaScriptStart();
$map = $this->_params['map'];
?>
var _map = [<?php
$i = 0;
foreach ($map as $val) {
if ($i > 0) {
echo ', ';
}
echo '"' . $val . '"';
$i++;
}?>];
function map(sourceId, targetId)
{
var newval;
var source = document.getElementById(sourceId);
var element = document.getElementById(targetId);
if (element) {
if (_map[source.selectedIndex]) {
newval = _map[source.selectedIndex];
replace = true;
} else {
newval = '';
replace = false;
for (i = 0; i < _map.length; i++) {
if (element.value == _map[i]) {
replace = true;
break;
}
}
}
if (replace) {
element.value = newval;
}
}
}<?php
$this->_printJavaScriptEnd();
}
}
|