/**
  * View for <param  type="private" class="cbpaidParamsExt" method="data">...
  *
  * @param  string              $value                  Stored Data of Model Value associated with the element
  * @param  ParamsInterface     $pluginParams           Main settigns parameters of the plugin
  * @param  string              $name                   Name attribute
  * @param  CBSimpleXMLElement  $param                  This XML node
  * @param  string              $control_name           Name of the control
  * @param  string              $control_name_name      css id-encode of the names of the controls surrounding this node
  * @param  boolean             $view                   TRUE: view, FALSE: edit
  * @param  cbpaidTable         $modelOfData            Data of the Model corresponding to this View
  * @param  cbpaidTable[]       $modelOfDataRows        Displayed Rows if it is a table
  * @param  int                 $modelOfDataRowsNumber  Total Number of rows
  * @return null|string
  */
 public function data($value, &$pluginParams, $name, &$param, $control_name, $control_name_name, $view, &$modelOfData, &$modelOfDataRows, &$modelOfDataRowsNumber)
 {
     global $_CB_database;
     $data = $param->getElementByPath('data');
     if ($data) {
         $dataTable = $data->attributes('table');
         if (!$dataTable) {
             if (is_object($modelOfData) && $modelOfData instanceof TableInterface) {
                 $dataTable = $modelOfData->getTableName();
             } elseif (is_object($modelOfData) && isset($modelOfData->_tbl)) {
                 $dataTable = $modelOfData->_tbl;
             } else {
                 $dataTable = null;
             }
         }
         $xmlsql = new XmlQuery($_CB_database, $dataTable, $pluginParams);
         $xmlsql->setExternalDataTypeValues('modelofdata', $modelOfData);
         $xmlsql->process_orderby($data->getElementByPath('orderby'));
         // <data><orderby><field> fields
         $xmlsql->process_fields($param);
         // <data><rows><field> fields
         $xmlsql->process_where($data->getElementByPath('where'));
         // <data><where><column> fields
         $value = $xmlsql->queryloadResult();
         // get the value
         if ($view) {
             if ($value === null) {
                 $value = $param->attributes('default');
             }
             return htmlspecialchars($value);
         } else {
             return '<input name="' . $control_name_name . '" type="text" id="' . $control_name_name . '" value="' . htmlspecialchars($value) . '"' . $this->_title($param) . ' />';
         }
     }
     return null;
 }
Example #2
0
	/**
	 * checks if there is an <attributes> extension in a <param> and sets attributes depending on any other param type
	 *
	 * @param  CBSimpleXMLElement  $param         (modified by adding attributes from <attributes>)
	 * @param  string              $control_name
	 * @param  boolean            $view            true if view only, false if editable
	 */
	function extendParamAttributes( &$param, $control_name = 'params', $view = true ) {
		$attributes											=	$param->getElementByPath( 'attributes' );
		if ( $attributes ) {
			foreach ( $attributes->children() as $attr ) {
				if ( $attr->name() == 'attribute' ) {
					$attName								=	$attr->attributes( 'name' );
					$attSeparator							=	$attr->attributes( 'separator' );
					$attTransform							=	$attr->attributes( 'transform' );
					$attMode								=	$attr->attributes( 'mode' );
					$replacements							=	false;
					if ( ( $attMode == null ) || ( ( $attMode == 'edit' ) && ! $view ) || ( ( $attMode == 'show' ) && $view ) ) {
						$attrArray							=	array();
						if ( $attName ) {
							foreach ( $attr->children() as $dataAttr ) {
								if ( $dataAttr->name() == 'param' ) {
									$this->extendParamAttributes( $dataAttr, $control_name );
									$result					=	$this->renderParam( $dataAttr, $control_name, true, 'table' );
									$attrArray[$attName][]	=	$result[1];
								} elseif ( $dataAttr->name() == 'replaces' ) {
									self::_substituteChildTexts( $dataAttr, null, null, $this );
									$replacements			=	true;
								} elseif ( $dataAttr->name() == 'data' ) {
									// keep silent here for now here as it was used only for decoration		//TODO CB 2.0: remove this
								} else {
									trigger_error( sprintf( 'attributes/attribute child tag "%s" name="%s" of param with name="%s" is not supported, only param is.', $dataAttr->name(), $dataAttr->attributes('name'), $param->attributes('name') ), E_USER_WARNING );
								}
							}
							if ( $replacements ) {
								$attrArray					=	self::_substituteChildTexts( $attrArray );
							}
							foreach ( $attrArray as $attK => $attV ) {
								if ( $attTransform == 'raw' ) {
									$param->addAttribute( $attK, implode( $attSeparator, $attV ) );
								} else {
									$param->addAttribute( $attK, htmlspecialchars( implode( $attSeparator, $attV ) ) );
								}
							}
						}
					}
				}
			}
		}
		
	}
 /**
  * Loads fields-params XML (backend use only!)
  * also sets $this->_fieldXML and $this->_specific
  *
  * @return boolean              TRUE if success, FALSE if not existant
  */
 function _loadFieldParamsXML()
 {
     if ($this->_fieldXml === null) {
         if ($this->_loadXML()) {
             $fieldsParamsXML =& $this->_xml->getElementByPath('fieldsparams');
             if ($fieldsParamsXML) {
                 $fieldTypeSpecific =& $fieldsParamsXML->getChildByNameAttr('field', 'type', $this->_field->type);
                 if ($fieldTypeSpecific) {
                     // <fieldsparams><field type="date"><params><param ....
                     $this->_fieldXml =& $fieldTypeSpecific;
                     $this->_specific = true;
                 } else {
                     // <fieldsparams><field type="other_types"><params><param ....
                     $nonSpecific =& $fieldsParamsXML->getChildByNameAttr('field', 'type', 'other_types');
                     if ($nonSpecific) {
                         $this->_fieldXml =& $nonSpecific;
                         $this->_specific = false;
                     }
                 }
             }
         }
     }
     return $this->_fieldXml !== null;
 }
 /**
  * installs a field for plugin
  *
  * @param  int                 $pluginid    id of the plugin creating the field
  * @param  CBSimpleXMLElement  $field
  * @return int|false     fieldid or False on error
  */
 function installField($pluginid, $tabid, $field)
 {
     global $_CB_database, $_PLUGINS;
     // Check to see if plugin tab already exists in db
     $_CB_database->setQuery("SELECT fieldid FROM #__comprofiler_fields WHERE name = '" . $field->attributes('name') . "'");
     $fieldid = $_CB_database->loadResult();
     $row = new moscomprofilerFields($_CB_database);
     $row->name = $field->attributes('name');
     $row->pluginid = $pluginid;
     $row->tabid = $tabid;
     $row->type = $field->attributes('type');
     $row->calculated = (int) $field->attributes('calculated');
     if (!$fieldid) {
         $row->title = $field->attributes('title');
         $row->description = trim($field->attributes('description'));
         $row->ordering = 99;
         $row->registration = $field->attributes('registration');
         $row->profile = $field->attributes('profile');
         $row->readonly = $field->attributes('readonly');
         $row->params = $field->attributes('params');
     }
     $dbTable =& $field->getElementByPath('database/table');
     if ($dbTable) {
         $table = $dbTable->attributes('name');
     } else {
         $table = $field->attributes('table');
     }
     if ($table) {
         $row->table = $table;
     } else {
         $row->table = '#__comprofiler';
     }
     // if the field type is unknown, suppose it's a field type of the plugin:
     $fieldTypePluginId = $_PLUGINS->getUserFieldPluginId($row->type);
     if (!$fieldTypePluginId) {
         // and register it so that the XML file for custom type can be found for store:
         $_PLUGINS->registerUserFieldTypes(array($row->type => 'CBfield_' . $row->type), $pluginid);
     }
     if (!$row->store($fieldid)) {
         $this->setError(1, 'SQL error on field store2' . ': ' . $row->getError());
         return false;
     }
     if (!$fieldid) {
         $fieldid = $_CB_database->insertid();
     }
     return $fieldid;
 }