tName = $this->pageObject->tName;
if($this->pageObject->tableBasedSearchPanelAdded)
$this->tName = $this->pageObject->searchTableName;
$this->format = EDIT_FORMAT_TEXT_FIELD;
if($pageObject->pageType == PAGE_LIST || !$pageObject->isPageTableBased())
$this->lookupPageType = PAGE_SEARCH;
else
$this->lookupPageType = $pageObject->pageType;
$this->lookupTable = $this->pageObject->pSetEdit->getLookupTable($this->field);
$this->lookupType = $this->pageObject->pSetEdit->getLookupType($this->field);
if($this->lookupType == LT_QUERY)
$this->lookupPSet = new ProjectSettings($this->lookupTable);
$this->displayFieldName = $this->pageObject->pSetEdit->getDisplayField($this->field);
$this->linkFieldName = $this->pageObject->pSetEdit->getLinkField($this->field);
$this->linkAndDisplaySame = $this->displayFieldName == $this->linkFieldName;
$this->ciphererLink = new RunnerCipherer($this->tName);
if($this->lookupType == LT_QUERY)
$this->ciphererDisplay = new RunnerCipherer($this->lookupTable);
else
$this->ciphererDisplay = $this->ciphererLink;
$this->LCType = $this->pageObject->pSetEdit->lookupControlType($this->field);
$this->multiselect = $this->pageObject->pSetEdit->multiSelect($this->field);
$this->lwLinkField = $this->pageObject->pSetEdit->getLWLinkField($this->field);
$this->lwDisplayFieldWrapped = $this->pageObject->pSetEdit->getLWDisplayField($this->field, true);
$this->customDisplay = $this->pageObject->pSetEdit->getCustomDisplay($this->field);
// The number of rows in a multiline lookup
$this->lookupSize = $this->pageObject->pSetEdit->selectSize($this->field);
$this->bUseCategory = $this->pageObject->pSetEdit->useCategory($this->field);
}
/**
* Create a CSS rule specifying the control's width
* @param Number widthPx
* @return String
*/
function makeWidthStyle($widthPx)
{
if( $this->LCType !== LCT_DROPDOWN )
return parent::makeWidthStyle( $widthPx );
if( 0 == $widthPx )
return "";
return "width: ".( $widthPx + 7 )."px";
}
/**
* Add control JS files to page object
*/
function addJSFiles()
{
if( $this->multiselect && ( $this->LCType == LCT_DROPDOWN && $this->lookupSize == 1 || $this->LCType == LCT_AJAX || $this->LCType == LCT_LIST ) )
$this->pageObject->AddJSFile("include/chosen/chosen.jquery.js");
}
/**
* Add control CSS files to page object
*/
function addCSSFiles()
{
if( $this->multiselect && ( $this->LCType == LCT_DROPDOWN && $this->lookupSize == 1 || $this->LCType == LCT_AJAX || $this->LCType == LCT_LIST ) )
$this->pageObject->AddCSSFile("include/chosen/chosen.css");
}
/**
* This function need to bypass buildControl function of this class. It calls from LookupTextField class only.
*/
function parentBuildControl($value, $mode, $fieldNum, $validate, $additionalCtrlParams, $data)
{
parent::buildControl($value, $mode, $fieldNum, $validate, $additionalCtrlParams, $data);
}
/**
* Get the control's settings and build its HTML markup
*/
function buildControl($value, $mode, $fieldNum, $validate, $additionalCtrlParams, $data)
{
parent::buildControl($value, $mode, $fieldNum, $validate, $additionalCtrlParams, $data);
global $conn;
$this->conn = $conn;
$this->alt = ($mode == MODE_INLINE_EDIT || $mode == MODE_INLINE_ADD) && $this->is508 ? ' alt="'.runner_htmlspecialchars($this->strLabel).'" ' : "";
$suffix = "_".GoodFieldName($this->field)."_".$this->id;
$this->clookupfield = "display_value".($fieldNum ? $fieldNum : '').$suffix;
$this->openlookup = "open_lookup".$suffix;
$this->cfield = "value".$suffix;
$this->ctype = "type".$suffix;
if($fieldNum)
{
$this->cfield = "value".$fieldNum.$suffix;
$this->ctype = "type".$fieldNum.$suffix;
}
$this->categoryFieldId = GoodFieldName( $this->pageObject->pSetEdit->getCategoryControl($this->field) );
$this->isLinkFieldEncrypted = $this->ciphererLink->isFieldPHPEncrypted($this->field);
$this->horizontalLookup = $this->pageObject->pSetEdit->isHorizontalLookup($this->field);
$this->strLookupWhere = GetLWWhere($this->field, $this->lookupPageType, $this->tName);
// alter "add on the fly" settings
$strPerm = GetUserPermissions($this->lookupTable);
if( strpos($strPerm,"A") !== false && $this->LCType != LCT_LIST && $mode != MODE_SEARCH )
{
$this->addnewitem = $this->pageObject->pSetEdit->isAllowToAdd($this->field);
$advancedadd = !$this->pageObject->pSetEdit->isSimpleAdd($this->field);
if(!$advancedadd || $this->pageObject->pageType == PAGE_REGISTER)
$this->addnewitem = false;
}
// prepare multi-select attributes
$this->multiple = $this->multiselect ? " multiple" : "";
$this->postfix = $this->multiselect ? "[]" : "";
if( $this->multiselect )
$avalue = splitvalues($value);
else
$avalue = array((string)$value);
$searchOption = $additionalCtrlParams["option"];
// build the control
if( $this->lookupType == LT_LISTOFVALUES )
{
$this->buildListOfValues($avalue, $value, $mode, $searchOption);
}
else
{
// build a table-based lookup
$this->isDisplayFieldEncrypted = ($this->lookupType == LT_QUERY || $this->linkAndDisplaySame)
&& $this->ciphererDisplay->isFieldPHPEncrypted($this->lookupType == LT_QUERY ? $this->displayFieldName : $this->field);
if( $this->LCType == LCT_AJAX || $this->LCType == LCT_LIST )
{
$this->buildAJAXLookup($avalue, $value, $mode, $searchOption);
}
else
{
$this->buildClassicLookup($avalue, $value, $mode, $searchOption);
}
}
$this->buildControlEnd($validate);
}
/**
* Get indexes of link and display fields
*/
public function fillLookupFieldsIndexes()
{
$lookupIndexes = GetLookupFieldsIndexes($this->pageObject->pSetEdit, $this->field);
$this->linkFieldIndex = $lookupIndexes["linkFieldIndex"];
$this->displayFieldIndex = $lookupIndexes["displayFieldIndex"];
}
/**
* Build HTML markup fo the 'List of values' lookup field
*/
public function buildListOfValues($avalue, $value, $mode, $searchOption)
{
// read lookup values
$arr = $this->pageObject->pSetEdit->getLookupValues($this->field);
$dropDownHasSimpleBox = $this->LCType == LCT_DROPDOWN && !$this->multiselect && $mode == MODE_SEARCH;
$optionContains = $dropDownHasSimpleBox && $this->isSearchOpitonForSimpleBox( $searchOption );
// print Type control to allow selecting nothing
if( $this->multiselect )
echo '';
switch($this->LCType)
{
case LCT_DROPDOWN:
$dataAttr = $selectClass = '';
if( $dropDownHasSimpleBox )
{
$dataAttr = ' data-usesuggests="true"';
$selectClass = $optionContains ? ' class="rnr-hiddenControlSubelem" ' : '';
$simpleBoxClass = $optionContains ? '' : ' class="rnr-hiddenControlSubelem" ';
$simpleBoxStyle = $this->getWidthStyleForAdditionalControl();
echo '';
}
echo '";
break;
case LCT_CBLIST:
echo '
';
$spacer = '
';
if($this->horizontalLookup)
$spacer = ' ';
$i = 0;
foreach($arr as $opt)
{
echo 'alt.' name="'.$this->cfield.$this->postfix.'" value="'
.runner_htmlspecialchars($opt).'"';
$res = array_search((string)$opt, $avalue);
if(!($res === NULL || $res === FALSE))
echo ' checked="checked" ';
echo '/>';
echo ' '.runner_htmlspecialchars($opt).''.$spacer;
$i++;
}
echo '
';
break;
case LCT_RADIO:
$spacer = $this->horizontalLookup ? " " : "
";
echo '';
$i = 0;
foreach($arr as $opt)
{
$checked = "";
if($opt == $value)
$checked = ' checked="checked" ';
echo 'alt.' name="radio_'.$this->cfieldname.'" '.$checked.' value="'.runner_htmlspecialchars($opt).'">'
.' '
.runner_htmlspecialchars($opt).''.$spacer;
$i++;
}
break;
}
}
/**
* Build the markup for the 'Edit box with AJAX popup' or 'List page with search' lookup field
* @param Array avalue An array of the control values
* @param String value A control's value string representation
* @param String mode The control's mode (MODE_INLINE_EDIT, MODE_INLINE_ADD)
* @param String searchOption The control's search option
*/
public function buildAJAXLookup($avalue, $value, $mode, $searchOption)
{
if( $this->multiselect )
{
$this->buildMultiselectAJAXLookup($avalue, $value, $mode, $searchOption);
return;
}
$listSearchHasSimpleBox = $mode == MODE_SEARCH && $this->isAdditionalControlRequired();
$optionContains = $this->isSearchOpitonForSimpleBox( $searchOption );
$dataAttr = '';
if( $this->LCType == LCT_AJAX && $optionContains )
$dataAttr = ' data-simple-search-mode="true" ';
$listOptionContains = $listSearchHasSimpleBox && $optionContains;
if($this->bUseCategory)
{
$valueAttr = '';
if( $this->LCType == LCT_AJAX && $optionContains || $this->LCType == LCT_LIST && $listOptionContains )
$valueAttr = ' value="'.runner_htmlspecialchars($value).'"';
// dependent ajax-lookup control
$inputParams = 'categoryId="'.$this->categoryFieldId.'" autocomplete="off" id="'.$this->clookupfield.'" '.$valueAttr.' name="'.$this->clookupfield.'" '.$this->inputStyle;
$inputParams.= $this->LCType == LCT_LIST && !$listOptionContains ? 'readonly': '';
echo '';
if($this->LCType == LCT_LIST)
{
$dataAttr = $listSearchHasSimpleBox ? ' data-usesuggests="true"' : '';
$visibility = $listOptionContains ? ' style="visibility: hidden;"' : '';
echo ' '.mlang_message("SELECT_LIST").'';
}
echo '';
if( $this->addnewitem )
echo " ".mlang_message("ADD_NEW")."";
return;
}
// get the initial value
$lookup_value = "";
$lookupSQL = $this->getLookupSQL("", $value, false, true);
$this->fillLookupFieldsIndexes();
$rs_lookup = db_query($lookupSQL, $this->conn);
if( $data = db_fetch_numarray($rs_lookup) )
{
if($this->isDisplayFieldEncrypted)
$lookup_value = $this->ciphererDisplay->DecryptField($this->lookupType == LT_QUERY
? $this->displayFieldName : $this->field, $data[ $this->displayFieldIndex ]);
else
$lookup_value = $data[ $this->displayFieldIndex ];
}
elseif( strlen($this->strLookupWhere) )
{
// try w/o WHERE expression
$lookupSQL = $this->getLookupSQL("", $value, false, true, false, false);
$rs_lookup = db_query($lookupSQL, $this->conn);
if($data = db_fetch_numarray($rs_lookup))
{
if($this->isDisplayFieldEncrypted)
$lookup_value = $this->ciphererDisplay->DecryptField($this->lookupType == LT_QUERY
? $this->displayFieldName : $this->field, $data[ $this->displayFieldIndex ]);
else
$lookup_value = $data[ $this->displayFieldIndex ];
}
}
// build the regular ajax-lookup control
if( $this->LCType == LCT_AJAX && !strlen($lookup_value) && ($this->pageObject->pSetEdit->isfreeInput($this->field) || $this->lookupPageType == PAGE_SEARCH)
|| $this->LCType == LCT_LIST && $listOptionContains )
{
$lookup_value = $value;
}
$inputParams = 'autocomplete="off" id="'.$this->clookupfield.'" name="'.$this->clookupfield.'" '.$this->inputStyle.$this->alt;
$inputParams.= ' value="'.runner_htmlspecialchars($lookup_value).'"';;
if( $this->LCType == LCT_LIST && !$listOptionContains )
$inputParams.= ' readonly ';
echo '';
if( $this->LCType == LCT_LIST )
{
$dataAttr = $listSearchHasSimpleBox ? ' data-usesuggests="true"' : '';
$visibility = $listOptionContains ? ' style="visibility: hidden;"' : '';
echo ' '.mlang_message("SELECT_LIST").'';
}
echo '';
if( $this->addnewitem )
echo " ".mlang_message("ADD_NEW")."";
}
/**
* Build a multiselect control html markup to apply JS 'chosen' plugin
* @param Array avalue An array of the control values
* @param String value A control's value string representation
* @param String mode The control's mode (MODE_INLINE_EDIT, MODE_INLINE_ADD)
* @param String searchOption The control's search option
*/
protected function buildMultiselectAJAXLookup($avalue, $value, $mode, $searchOption)
{
echo '';
if( $this->LCType == LCT_LIST )
echo ' '.mlang_message("SELECT_LIST").'';
if( $this->addnewitem )
echo " ".mlang_message("ADD_NEW")."";
}
/**
* Build the control's 'option' elements. If the link and displayed fields are not the same
* a db query is used to retrieve displayed values corresponding to the link values ($avalue)
* @param Array avalue An array of the control values
* @param String value A control's value string representation
* @param String mode The control's mode (MODE_INLINE_EDIT, MODE_INLINE_ADD)
* @param String searchOption The control's search option
*/
protected function buildMultiselectAJAXLookupRows($avalue, $value, $mode, $searchOption)
{
$this->fillLookupFieldsIndexes();
if( $this->linkAndDisplaySame || $this->lookupPageType == PAGE_SEARCH )
{
foreach($avalue as $mKey => $mValue)
{
$data = array();
$data[ $this->linkFieldIndex ] = $mValue;
$data[ $this->displayFieldIndex ] = $mValue;
$this->buildLookupRow( $mode, $data, ' selected', $mKey );
}
return;
}
$lookupSQL = $this->getLookupSQL("", $value, false, true);
$rs = db_query( $lookupSQL, $this->conn );
$options = 0;
while( $data = db_fetch_numarray($rs) )
{
$this->decryptDataRow( $data );
if( array_search( $data[ $this->linkFieldIndex ], $avalue ) !== FALSE )
{
$this->buildLookupRow( $mode, $data, ' selected', $options );
$options++;
}
}
// try the same query w/o WHERE clause if options were not found
if( $options == 0 && strlen($value) && $mode == MODE_EDIT && strlen($this->strLookupWhere) )
{
$lookupSQL = $this->getLookupSQL("", $value, false, true, false, false, true);
$rs = db_query( $lookupSQL, $this->conn );
if( $data = db_fetch_numarray($rs) )
{
$this->decryptDataRow( $data );
$this->buildLookupRow( $mode, $data, ' selected', $options );
}
}
}
/**
* Build HTML markup for the 'dropdown box', 'checkbox list' or 'radio button' lookup field
* @param Array avalue
* @param String value
* @param String mode
* @param String searchOption
*/
public function buildClassicLookup($avalue, $value, $mode, $searchOption)
{
$dropDownHasSimpleBox = $this->LCType == LCT_DROPDOWN && $mode == MODE_SEARCH && $this->isAdditionalControlRequired();
$optionContains = $dropDownHasSimpleBox && $this->isSearchOpitonForSimpleBox( $searchOption );
if( $this->multiselect ) // print Type control to allow selecting nothing
echo '';
if($this->bUseCategory)
{
// dependent classic lookup
switch ($this->LCType)
{
case LCT_CBLIST:
echo '';
echo '';
echo '
';
break;
case LCT_RADIO:
echo '';
echo '';
echo '
';
break;
case LCT_DROPDOWN:
$dataAttr = $selectClass = '';
if( $dropDownHasSimpleBox )
{
$dataAttr = ' data-usesuggests="true"';
$selectClass = $optionContains ? ' class="rnr-hiddenControlSubelem" ' : '';
$simpleBoxClass = $optionContains ? '' : ' class="rnr-hiddenControlSubelem" ';
$simpleBoxStyle = $this->getWidthStyleForAdditionalControl();
echo '';
}
echo '';
break;
}
if( $this->addnewitem )
echo " ".mlang_message("ADD_NEW")."";
return;
}
$lookupSQL = $this->getLookupSQL("", "", false);
$rs = db_query($lookupSQL, $this->conn);
$this->fillLookupFieldsIndexes();
// simple classic lookup
if($this->LCType == LCT_DROPDOWN)
{
$dataAttr = $selectClass = '';
if( $dropDownHasSimpleBox )
{
$dataAttr = ' data-usesuggests="true"';
$selectClass = $optionContains ? ' class="rnr-hiddenControlSubelem" ' : '';
$simpleBoxClass = $optionContains ? '' : ' class="rnr-hiddenControlSubelem" ';
$simpleBoxStyle = $this->getWidthStyleForAdditionalControl();
echo '';
}
echo '