Annotation of pkgsrc/databases/phpldapadmin/patches/patch-lib_PLAAttribute.php, revision 1.1
1.1 ! khorben 1: $NetBSD$
! 2:
! 3: --- lib/PLAAttribute.php.orig 2022-04-15 22:53:04.000000000 +0000
! 4: +++ lib/PLAAttribute.php
! 5: @@ -0,0 +1,917 @@
! 6: +<?php
! 7: +/**
! 8: + * Classes and functions for the template engine.
! 9: + *
! 10: + * @author The phpLDAPadmin development team
! 11: + * @package phpLDAPadmin
! 12: + */
! 13: +
! 14: +/**
! 15: + * Represents an attribute of a template.
! 16: + *
! 17: + * @package phpLDAPadmin
! 18: + * @subpackage Templates
! 19: + */
! 20: +class PLAAttribute {
! 21: + # Attribute Name
! 22: + public $name;
! 23: + # Source of this attribute definition
! 24: + protected $source;
! 25: +
! 26: + # Current and Old Values
! 27: + protected $oldvalues = array();
! 28: + protected $values = array();
! 29: +
! 30: + # MIN/MAX number of values
! 31: + protected $min_value_count = -1;
! 32: + protected $max_value_count = -1;
! 33: +
! 34: + # Is the attribute internal
! 35: + protected $internal = false;
! 36: + # Has the attribute been modified
! 37: + protected $modified = false;
! 38: + # Is the attribute being deleted because of an object class removal
! 39: + protected $forcedelete = false;
! 40: + # Is the attribute visible
! 41: + protected $visible = false;
! 42: + protected $forcehide = false;
! 43: + # Is the attribute modifiable
! 44: + protected $readonly = false;
! 45: + # LDAP attribute type MUST/MAY
! 46: + protected $ldaptype = null;
! 47: + # Attribute property type (eg password, select, multiselect)
! 48: + protected $type = '';
! 49: + # Attribute value to keep unique
! 50: + protected $unique = false;
! 51: +
! 52: + # Display parameters
! 53: + protected $display = '';
! 54: + protected $icon = '';
! 55: + protected $hint = '';
! 56: + # Helper details
! 57: + protected $helper = array();
! 58: + protected $helpervalue = array();
! 59: + # Onchange details
! 60: + protected $onchange = array();
! 61: + # Show spacer after this attribute is rendered
! 62: + protected $spacer = false;
! 63: + protected $verify = false;
! 64: +
! 65: + # Component size
! 66: + protected $size = 0;
! 67: + # Value max length
! 68: + protected $maxlength = 0;
! 69: + # Text Area sizings
! 70: + protected $cols = 0;
! 71: + protected $rows = 0;
! 72: +
! 73: + # Public for sorting
! 74: + public $page = 1;
! 75: + public $order = 255;
! 76: + public $ordersort = 255;
! 77: + public $rdn = false;
! 78: +
! 79: + # Schema Aliases for this attribute (stored in lowercase)
! 80: + protected $aliases = array();
! 81: +
! 82: + # Configuration for automatically generated values
! 83: + protected $autovalue = array();
! 84: + protected $postvalue = array();
! 85: +
! 86: + public function __construct($name,$values,$server_id,$source=null) {
! 87: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 88: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 89: +
! 90: + $server = $_SESSION[APPCONFIG]->getServer($server_id);
! 91: +
! 92: + $sattr = $server->getSchemaAttribute($name);
! 93: + if ($sattr) {
! 94: + $this->name = $sattr->getName(false);
! 95: + $this->setLDAPdetails($sattr);
! 96: +
! 97: + } else
! 98: + $this->name = $name;
! 99: +
! 100: + $this->source = $source;
! 101: +
! 102: + # XML attributes are shown by default
! 103: + switch ($source) {
! 104: + case 'XML': $this->show();
! 105: + $this->setXML($values);
! 106: +
! 107: + break;
! 108: +
! 109: + default:
! 110: + if (! isset($values['values']))
! 111: + debug_dump_backtrace('no index "values"',1);
! 112: +
! 113: + $this->initValue($values['values']);
! 114: + }
! 115: +
! 116: + # Should this attribute be hidden
! 117: + if ($server->isAttrHidden($this->name))
! 118: + $this->forcehide = true;
! 119: +
! 120: + # Should this attribute value be read only
! 121: + if ($server->isAttrReadOnly($this->name))
! 122: + $this->readonly = true;
! 123: +
! 124: + # Should this attribute value be unique
! 125: + if ($server->isAttrUnique($this->name))
! 126: + $this->unique = true;
! 127: + }
! 128: +
! 129: + /**
! 130: + * Return the name of the attribute.
! 131: + *
! 132: + * @param boolean $lower - Return the attribute in normal or lower case (default lower)
! 133: + * @param boolean $real - Return the real attribute name (with ;binary, or just the name)
! 134: + * @return string Attribute name
! 135: + */
! 136: + public function getName($lower=true,$real=false) {
! 137: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 138: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs,$this->name);
! 139: +
! 140: + if ($real)
! 141: + return $lower ? strtolower($this->name) : $this->name;
! 142: + else
! 143: + return $lower ? strtolower($this->real_attr_name()) : $this->real_attr_name();
! 144: + }
! 145: +
! 146: + public function getValues() {
! 147: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 148: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->values);
! 149: +
! 150: + return $this->values;
! 151: + }
! 152: +
! 153: + public function getOldValues() {
! 154: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 155: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->oldvalues);
! 156: +
! 157: + return $this->oldvalues;
! 158: + }
! 159: +
! 160: + public function getValueCount() {
! 161: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 162: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs,$this->values);
! 163: +
! 164: + return count($this->values);
! 165: + }
! 166: +
! 167: + public function getSource() {
! 168: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 169: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->source);
! 170: +
! 171: + return $this->source;
! 172: + }
! 173: +
! 174: + /**
! 175: + * Autovalue is called after the attribute is initialised, and thus the values from the ldap server will be set.
! 176: + */
! 177: + public function autoValue($new_val) {
! 178: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 179: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 180: +
! 181: + if ($this->values)
! 182: + return;
! 183: +
! 184: + $this->values = $new_val;
! 185: + }
! 186: +
! 187: + public function initValue($new_val) {
! 188: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 189: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 190: +
! 191: + if ($this->values || $this->oldvalues) {
! 192: + debug_dump(array('new_val'=>$new_val,'this'=>$this));
! 193: + debug_dump_backtrace('new and/or old values are set',1);
! 194: + }
! 195: +
! 196: + $this->values = $new_val;
! 197: + }
! 198: +
! 199: + public function clearValue() {
! 200: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 201: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 202: +
! 203: + $this->values = array();
! 204: + }
! 205: +
! 206: + public function setOldValue($val) {
! 207: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 208: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
! 209: +
! 210: + $this->oldvalues = $val;
! 211: + }
! 212: +
! 213: + public function setValue($new_val) {
! 214: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 215: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 216: +
! 217: + if ($this->values) {
! 218: + if ($this->values == $new_val)
! 219: + return;
! 220: +
! 221: + if ($this->oldvalues) {
! 222: + debug_dump($this);
! 223: + debug_dump_backtrace('old values are set',1);
! 224: + } else
! 225: + $this->oldvalues = $this->values;
! 226: + }
! 227: +
! 228: + if ($new_val == $this->values)
! 229: + return;
! 230: +
! 231: + $this->values = $new_val;
! 232: + $this->justModified();
! 233: + }
! 234: +
! 235: + public function addValue($new_val,$i=-1) {
! 236: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 237: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 238: +
! 239: + if ($i < 0)
! 240: + $i = $this->getValueCount();
! 241: +
! 242: + $old_val = $this->getValue($i);
! 243: + if (is_null($old_val) || ($old_val != $new_val))
! 244: + $this->justModified();
! 245: +
! 246: + $this->values[$i] = $new_val;
! 247: + }
! 248: +
! 249: + public function delValue($i=-1) {
! 250: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 251: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 252: +
! 253: + if ($i < 0)
! 254: + $this->setValue(array());
! 255: +
! 256: + if (! $this->hasBeenModified())
! 257: + $this->oldvalues = $this->values;
! 258: +
! 259: + if (isset($this->values[$i])) {
! 260: + unset($this->values[$i]);
! 261: + $this->values = array_values($this->values);
! 262: + $this->justModified();
! 263: + }
! 264: + }
! 265: +
! 266: + public function getValue($i) {
! 267: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 268: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 269: +
! 270: + if (isset($this->values[$i]))
! 271: + return $this->values[$i];
! 272: + else
! 273: + return null;
! 274: + }
! 275: +
! 276: + public function getOldValue($i) {
! 277: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 278: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 279: +
! 280: + if (isset($this->oldvalues[$i]))
! 281: + return $this->oldvalues[$i];
! 282: + else
! 283: + return null;
! 284: + }
! 285: +
! 286: + public function getMinValueCount() {
! 287: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 288: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->min_value_count);
! 289: +
! 290: + return $this->min_value_count;
! 291: + }
! 292: +
! 293: + public function setMinValueCount($min) {
! 294: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 295: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
! 296: +
! 297: + $this->min_value_count = $min;
! 298: + }
! 299: +
! 300: + public function getMaxValueCount() {
! 301: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 302: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->max_value_count);
! 303: +
! 304: + return $this->max_value_count;
! 305: + }
! 306: +
! 307: + public function setMaxValueCount($max) {
! 308: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 309: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
! 310: +
! 311: + $this->max_value_count = $max;
! 312: + }
! 313: +
! 314: + public function haveMoreValues() {
! 315: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 316: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 317: +
! 318: + if ($this->getMaxValueCount() < 0 || ($this->getValueCount() < $this->getMaxValueCount()))
! 319: + return true;
! 320: + else
! 321: + return false;
! 322: + }
! 323: +
! 324: + public function justModified() {
! 325: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 326: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 327: +
! 328: + $this->modified = true;
! 329: + }
! 330: +
! 331: + public function hasBeenModified() {
! 332: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 333: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->modified);
! 334: +
! 335: + return $this->modified;
! 336: + }
! 337: +
! 338: + public function isForceDelete() {
! 339: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 340: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->forcedelete);
! 341: +
! 342: + return $this->forcedelete;
! 343: + }
! 344: +
! 345: + public function setForceDelete() {
! 346: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 347: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 348: +
! 349: + $this->forcedelete = true;
! 350: + $this->oldvalues = $this->values;
! 351: + $this->values = array();
! 352: + $this->justModified();
! 353: + }
! 354: +
! 355: + public function isInternal() {
! 356: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 357: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->internal);
! 358: +
! 359: + return $this->internal;
! 360: + }
! 361: +
! 362: + public function setInternal() {
! 363: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 364: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
! 365: +
! 366: + $this->internal = true;
! 367: + }
! 368: +
! 369: + public function isRequired() {
! 370: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 371: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 372: +
! 373: + if ($this->getMinValueCount() > 0)
! 374: + return true;
! 375: + elseif ($this->ldaptype == 'must')
! 376: + return true;
! 377: + elseif ($this->isRDN())
! 378: + return true;
! 379: + else
! 380: + return false;
! 381: + }
! 382: +
! 383: + public function isMay() {
! 384: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 385: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 386: +
! 387: + if (($this->ldaptype == 'may') && ! $this->isRequired())
! 388: + return true;
! 389: + else
! 390: + return false;
! 391: + }
! 392: +
! 393: + public function setType($type) {
! 394: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 395: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
! 396: +
! 397: + $this->type = strtolower($type);
! 398: + }
! 399: +
! 400: + public function getType() {
! 401: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 402: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->type);
! 403: +
! 404: + return $this->type;
! 405: + }
! 406: +
! 407: + public function setLDAPtype($type) {
! 408: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 409: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
! 410: +
! 411: + $this->ldaptype = strtolower($type);
! 412: + }
! 413: +
! 414: + public function getLDAPtype() {
! 415: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 416: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->ldaptype);
! 417: +
! 418: + return $this->ldaptype;
! 419: + }
! 420: +
! 421: + public function setProperties($properties) {
! 422: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 423: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 424: +
! 425: + foreach ($properties as $index => $value) {
! 426: + if ($index == 'maxvalnb') {
! 427: + $this->setMaxValueCount($value);
! 428: + continue;
! 429: +
! 430: + } elseif ($index == 'minvalnb') {
! 431: + $this->setMinValueCount($value);
! 432: + continue;
! 433: +
! 434: + } elseif ($index == 'maxlength') {
! 435: + $this->setMinValueCount($value);
! 436: + continue;
! 437: +
! 438: + } elseif ($index == 'hidden') {
! 439: + $this->visible = $value;
! 440: + continue;
! 441: +
! 442: + } elseif (in_array($index,array('cols','rows'))) {
! 443: + # @todo To be implemented
! 444: + continue;
! 445: + }
! 446: +
! 447: + if (isset($this->$index))
! 448: + $this->$index = $value;
! 449: + else {
! 450: + debug_dump($this);
! 451: + debug_dump_backtrace(sprintf('Unknown property (%s) with value (%s) for (%s)',$index,$value,$this->getName()),1);
! 452: + }
! 453: + }
! 454: + }
! 455: +
! 456: + public function setRequired() {
! 457: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 458: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 459: +
! 460: + if ($this->getMinValueCount() <= 0)
! 461: + $this->setMinValueCount(1);
! 462: + }
! 463: +
! 464: + public function setOptional() {
! 465: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 466: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
! 467: +
! 468: + $this->setMinValueCount(0);
! 469: + }
! 470: +
! 471: + public function isReadOnly() {
! 472: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 473: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->readonly);
! 474: +
! 475: + return $this->readonly;
! 476: + }
! 477: +
! 478: + public function setReadOnly() {
! 479: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 480: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 481: +
! 482: + $this->readonly = true;
! 483: + }
! 484: +
! 485: + public function isMultiple() {
! 486: + return false;
! 487: + }
! 488: +
! 489: + public function isVisible() {
! 490: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 491: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 492: +
! 493: + return $this->visible && (! $this->forcehide);
! 494: + }
! 495: +
! 496: + public function hide() {
! 497: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 498: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 499: +
! 500: + $this->visible = false;
! 501: + }
! 502: +
! 503: + public function show() {
! 504: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 505: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 506: +
! 507: + $this->visible = true;
! 508: + }
! 509: +
! 510: + public function haveFriendlyName() {
! 511: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 512: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 513: +
! 514: + return $_SESSION[APPCONFIG]->haveFriendlyName($this);
! 515: + }
! 516: +
! 517: + public function getFriendlyName() {
! 518: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 519: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->display);
! 520: +
! 521: + if ($this->display)
! 522: + return $this->display;
! 523: + else
! 524: + return $_SESSION[APPCONFIG]->getFriendlyName($this);
! 525: + }
! 526: +
! 527: + public function setDescription($description) {
! 528: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 529: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
! 530: +
! 531: + $this->description = $description;
! 532: + }
! 533: +
! 534: + public function getDescription() {
! 535: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 536: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->description);
! 537: +
! 538: + return $this->description;
! 539: + }
! 540: +
! 541: + public function setIcon($icon) {
! 542: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 543: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
! 544: +
! 545: + $this->icon = $icon;
! 546: + }
! 547: +
! 548: + public function getIcon() {
! 549: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 550: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->icon);
! 551: +
! 552: + return $this->icon ? sprintf('%s/%s',IMGDIR,$this->icon) : '';
! 553: + }
! 554: +
! 555: + public function getHint() {
! 556: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 557: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->hint);
! 558: +
! 559: + return $this->hint;
! 560: + }
! 561: +
! 562: + public function setHint($hint) {
! 563: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 564: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
! 565: +
! 566: + $this->hint = $hint;
! 567: + }
! 568: +
! 569: + public function getMaxLength() {
! 570: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 571: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->maxlength);
! 572: +
! 573: + return $this->maxlength;
! 574: + }
! 575: +
! 576: + public function setMaxLength($maxlength) {
! 577: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 578: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
! 579: +
! 580: + $this->maxlength = $maxlength;
! 581: + }
! 582: +
! 583: + public function getSize() {
! 584: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 585: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->size);
! 586: +
! 587: + return $this->size;
! 588: + }
! 589: +
! 590: + public function setSize($size) {
! 591: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 592: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
! 593: +
! 594: + $this->size = $size;
! 595: + }
! 596: +
! 597: + public function getSpacer() {
! 598: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 599: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->spacer);
! 600: +
! 601: + return $this->spacer;
! 602: + }
! 603: +
! 604: + public function getPage() {
! 605: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 606: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->page);
! 607: +
! 608: + return $this->page;
! 609: + }
! 610: + public function setPage($page) {
! 611: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 612: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
! 613: +
! 614: + $this->page = $page;
! 615: + }
! 616: +
! 617: + public function getOnChange() {
! 618: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 619: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->onchange);
! 620: +
! 621: + return $this->onchange;
! 622: + }
! 623: +
! 624: + public function getHelper() {
! 625: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 626: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->helper);
! 627: +
! 628: + return $this->helper;
! 629: + }
! 630: +
! 631: + public function getHelperValue() {
! 632: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 633: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->helpervalue);
! 634: +
! 635: + return $this->helpervalue;
! 636: + }
! 637: +
! 638: + public function getVerify() {
! 639: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 640: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->verify);
! 641: +
! 642: + return $this->verify;
! 643: + }
! 644: +
! 645: + public function setRDN($rdn) {
! 646: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 647: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
! 648: +
! 649: + $this->rdn = $rdn;
! 650: + }
! 651: +
! 652: + /**
! 653: + * Return if this attribute is an RDN attribute
! 654: + *
! 655: + * @return boolean
! 656: + */
! 657: + public function isRDN() {
! 658: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 659: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs,$this->rdn);
! 660: +
! 661: + return $this->rdn;
! 662: + }
! 663: +
! 664: + /**
! 665: + * Capture all the LDAP details we are interested in
! 666: + *
! 667: + * @param sattr Schema Attribute
! 668: + */
! 669: + private function setLDAPdetails($sattr) {
! 670: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 671: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 672: +
! 673: + # By default, set this as a MAY attribute, later processing should make it a MUST attribute if it is.
! 674: + if (! $this->ldaptype)
! 675: + $this->ldaptype = 'may';
! 676: +
! 677: + # Store our Aliases
! 678: + foreach ($sattr->getAliases() as $alias)
! 679: + array_push($this->aliases,strtolower($alias));
! 680: +
! 681: + if ($sattr->getIsSingleValue())
! 682: + $this->setMaxValueCount(1);
! 683: + }
! 684: +
! 685: + /**
! 686: + * Return a list of aliases for this Attribute (as defined by the schema)
! 687: + * This list will be lowercase.
! 688: + */
! 689: + public function getAliases() {
! 690: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 691: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->aliases);
! 692: +
! 693: + return $this->aliases;
! 694: + }
! 695: +
! 696: + public function getAutoValue() {
! 697: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 698: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->autovalue);
! 699: +
! 700: + return $this->autovalue;
! 701: + }
! 702: +
! 703: + public function getPostValue() {
! 704: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 705: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->postvalue);
! 706: +
! 707: + return $this->postvalue;
! 708: + }
! 709: +
! 710: + public function setPostValue($postvalue) {
! 711: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 712: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs);
! 713: +
! 714: + $this->postvalue = $postvalue;
! 715: + }
! 716: +
! 717: + public function setXML($values) {
! 718: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 719: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 720: +
! 721: + # Mostly all the time, this should be an array
! 722: + if (is_array($values))
! 723: + foreach ($values as $index => $value)
! 724: + switch ($index) {
! 725: + # Helpers should be accompanied with a <post> attribute.
! 726: + case 'helper':
! 727: + if (! isset($values['post']) && ! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning'))
! 728: + system_message(array(
! 729: + 'title'=>sprintf('%s [<i>%s</i>]',_('Missing [post] setting in XML file'),$index),
! 730: + 'body'=>_('[helper] needs an accompanying [post] action.'),
! 731: + 'type'=>'warn'));
! 732: +
! 733: + if (isset($value['value']) && ! is_array($value['value']) && preg_match('/^=php\.(\w+)\((.*)\)$/',$value['value'],$matches)) {
! 734: + $this->helpervalue['function'] = $matches[1];
! 735: + $this->helpervalue['args'] = $matches[2];
! 736: +
! 737: + unset ($value['value']);
! 738: + }
! 739: +
! 740: + foreach ($value as $i => $detail) {
! 741: + if (! in_array($i,array('default','display','id','value'))) {
! 742: + if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning'))
! 743: + system_message(array(
! 744: + 'title'=>sprintf('%s [<i>%s</i>]',_('Unknown XML setting'),$i),
! 745: + 'body'=>sprintf('%s <small>[%s]</small>',_('Unknown XML type setting for helper will be ignored.'),$detail),
! 746: + 'type'=>'warn'));
! 747: +
! 748: + unset($value[$i]);
! 749: + }
! 750: + }
! 751: +
! 752: + $this->$index = $value;
! 753: +
! 754: + break;
! 755: +
! 756: + case 'hidden': $value ? $this->visible = false : $this->visible = true;
! 757: + break;
! 758: +
! 759: + case 'spacer': $value ? $this->$index = true : $this->$index = false;
! 760: + break;
! 761: +
! 762: + # Essentially, we ignore type, it is used to select an Attribute type in the Factory. But we'll generated a warning if there is an unknown type.
! 763: + case 'type':
! 764: + if (! in_array($value,array('password','multiselect','select','textarea')) && ! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning'))
! 765: + system_message(array(
! 766: + 'title'=>sprintf('%s [<i>%s</i>]',_('Unknown XML setting'),$index),
! 767: + 'body'=>sprintf('%s <small>[%s]</small>',_('Unknown XML type setting will be ignored.'),$value),
! 768: + 'type'=>'warn'));
! 769: +
! 770: + break;
! 771: +
! 772: + case 'post':
! 773: + if (preg_match('/^=php\.(\w+)\((.*)\)$/',$value,$matches)) {
! 774: + $this->postvalue['function'] = $matches[1];
! 775: + $this->postvalue['args'] = $matches[2];
! 776: +
! 777: + } else
! 778: + if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning'))
! 779: + system_message(array(
! 780: + 'title'=>sprintf('%s [<i>%s</i>]',_('Unknown XML setting'),$index),
! 781: + 'body'=>sprintf('%s <small>[%s]</small>',_('Unknown XML type setting will be ignored.'),$value),
! 782: + 'type'=>'warn'));
! 783: +
! 784: + case 'value':
! 785: + if (is_array($value))
! 786: + foreach ($value as $x => $y) {
! 787: + if (! $this->haveMoreValues()) {
! 788: + system_message(array(
! 789: + 'title'=>_('Automatically removed attribute values from template'),
! 790: + 'body'=>sprintf('%s <small>[%s]</small>',_('Template defines more values than can be accepted by attribute.'),$this->getName(true)),
! 791: + 'type'=>'warn'));
! 792: +
! 793: + $this->clearValue();
! 794: +
! 795: + break;
! 796: +
! 797: + } else
! 798: + $this->addValue($x,$y);
! 799: + }
! 800: +
! 801: + else
! 802: + # Check to see if the value is auto generated.
! 803: + if (preg_match('/^=php\.(\w+)\((.*)\)$/',$value,$matches)) {
! 804: + $this->autovalue['function'] = $matches[1];
! 805: + $this->autovalue['args'] = $matches[2];
! 806: +
! 807: + # We'll add a hint too
! 808: + if (! $this->hint)
! 809: + $this->hint = _('Automatically determined');
! 810: +
! 811: + } else
! 812: + $this->addValue($value);
! 813: +
! 814: + break;
! 815: +
! 816: + # Queries
! 817: + case 'ordersort':
! 818: +
! 819: + # Creation/Editing Templates
! 820: + case 'cols':
! 821: + case 'default':
! 822: + case 'display':
! 823: + case 'hint':
! 824: + case 'icon':
! 825: + case 'maxlength':
! 826: + case 'onchange':
! 827: + case 'order':
! 828: + case 'page':
! 829: + case 'readonly':
! 830: + case 'rows':
! 831: + case 'size':
! 832: + case 'values':
! 833: + case 'verify': $this->$index = $value;
! 834: + break;
! 835: +
! 836: + case 'max':
! 837: + if ($this->getMaxValueCount() == -1)
! 838: + $this->setMaxValueCount($value);
! 839: +
! 840: + default:
! 841: + if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning'))
! 842: + system_message(array(
! 843: + 'title'=>sprintf('%s [<i>%s</i>]',_('Unknown XML setting'),$index),
! 844: + 'body'=>sprintf('%s <small>[%s]</small>',_('Unknown attribute setting will be ignored.'),serialize($value)),
! 845: + 'type'=>'warn'));
! 846: + }
! 847: +
! 848: + elseif (is_string($values) && (strlen($values) > 0))
! 849: + $this->values = array($values);
! 850: + }
! 851: +
! 852: + /**
! 853: + * Display the values removed in an attribute.
! 854: + */
! 855: + public function getRemovedValues() {
! 856: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 857: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 858: +
! 859: + return array_diff($this->getOldValues(),$this->getValues());
! 860: + }
! 861: +
! 862: + /**
! 863: + * Display the values removed in an attribute.
! 864: + */
! 865: + public function getAddedValues() {
! 866: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 867: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 868: +
! 869: + return array_diff($this->getValues(),$this->getOldValues());
! 870: + }
! 871: +
! 872: + /**
! 873: + * Prunes off anything after the ";" in an attr name. This is useful for
! 874: + * attributes that may have ";binary" appended to their names. With
! 875: + * real_attr_name(), you can more easily fetch these attributes' schema
! 876: + * with their "real" attribute name.
! 877: + *
! 878: + * @param string $attr_name The name of the attribute to examine.
! 879: + * @return string
! 880: + */
! 881: + private function real_attr_name() {
! 882: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 883: + debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->name);
! 884: +
! 885: + return preg_replace('/;.*$/U','',$this->name);
! 886: + }
! 887: +
! 888: + /**
! 889: + * Does this attribute need supporting JS
! 890: + */
! 891: + public function needJS($type=null) {
! 892: + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
! 893: + debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
! 894: +
! 895: + if (is_null($type)) {
! 896: + foreach (array('focus','blur','validate') as $type)
! 897: + if ($this->needJS($type))
! 898: + return true;
! 899: +
! 900: + return false;
! 901: +
! 902: + } elseif ($type == 'focus') {
! 903: + # We dont have any focus javascript routines.
! 904: + return false;
! 905: +
! 906: + } elseif ($type == 'blur') {
! 907: + if ($this->onchange || $this->isRequired())
! 908: + return true;
! 909: + else
! 910: + return false;
! 911: +
! 912: + } elseif ($type == 'validate') {
! 913: + if ($this->isRequired())
! 914: + return true;
! 915: + else
! 916: + return false;
! 917: +
! 918: + } else
! 919: + debug_dump_backtrace(sprintf('Unknown JS request %s',$type),1);
! 920: + }
! 921: +}
! 922: +?>
CVSweb <webmaster@jp.NetBSD.org>