Exemplo n.º 1
0
	/**
	 * @param Array keys
	 * @param Boolean forLookup
	 * @param String _table
	 * @param String _field
	 * @param String pageType
	 * @return Array
	 */
	public function GetAddedDataLookupQuery($keys, $forLookup, $_table, $_field, $pageType)
	{	
		$lookupMainSettings = getLookupMainTableSettings($this->tName, $_table, $_field, $pageType);
		if(!$lookupMainSettings)
			return array();

		global $conn;		
		$LookupSQL = "";
		$mainField = $_field;	
		$mainTable = $lookupMainSettings->getTableName();
		$linkFieldName = $lookupMainSettings->getLinkField($mainField);
		$dispfield = $lookupMainSettings->getDisplayField($mainField);
		
		$nLookupType = $lookupMainSettings->getLookupType($mainField);
		if($nLookupType == LT_QUERY)
		{
			if($lookupMainSettings->getCustomDisplay($mainField))
				$this->pSet->getSQLQuery()->AddCustomExpression($dispfield, $this->pSet, $mainTable, $mainField);
			$lookupQueryObj = $this->pSet->getSQLQuery()->CloneObject();
		}
		else
		{
			$LookupSQL = "select ";
			$LookupSQL .= GetFullFieldName($linkFieldName, $this->tName, true);
			if($linkFieldName != $dispfield)
				$LookupSQL .= "," . $this->pSet->getLWDisplayField($mainField, true);
			$LookupSQL.=" from ".AddTableWrappers($this->strOriginalTableName);
		}
			
		$data = 0;
		$lookupIndexes = array("linkFieldIndex" => 0, "displayFieldIndex" => 0);
		if(count($keys))
		{
			$where = KeyWhere($keys);
			if($nLookupType == LT_QUERY)
				$LookupSQL = $lookupQueryObj->toSql(whereAdd($lookupQueryObj->m_where->toSql($lookupQueryObj), $where));
			else 
				$LookupSQL.=" where ".$where;
			$lookupIndexes = GetLookupFieldsIndexes($lookupMainSettings, $mainField);
			LogInfo($LookupSQL);
			if($forLookup)
			{
				$rs=db_query($LookupSQL,$conn);
				$data = $this->cipherer->DecryptFetchedArray($rs);
			}
			else if($LookupSQL)
			{
				$rs = db_query($LookupSQL,$conn);
				$data = db_fetch_numarray($rs);
				$data[$lookupIndexes["linkFieldIndex"]] = $this->cipherer->DecryptField($linkFieldName, $data[$lookupIndexes["linkFieldIndex"]]);
				if($nLookupType == LT_QUERY)
					$data[$lookupIndexes["displayFieldIndex"]] = $this->cipherer->DecryptField($dispfield, $data[$lookupIndexes["displayFieldIndex"]]);		
			}
		}

		return array($data, array("linkField" => $linkFieldName, "displayField" => $dispfield
			, "linkFieldIndex" => $lookupIndexes["linkFieldIndex"], "displayFieldIndex" => $lookupIndexes["displayFieldIndex"]));
	}	
 public function ViewLookupWizardField($field, $container, $pageObject)
 {
     parent::ViewControl($field, $container, $pageObject);
     $this->lookupPSet = null;
     $this->cipherer = null;
     $this->lookupQueryObj = null;
     $this->displayFieldIndex = 0;
     $this->linkFieldIndex = 1;
     $this->LookupSQL = "";
     if ($this->container->pSet->getEditFormat($field) != EDIT_FORMAT_LOOKUP_WIZARD) {
         $this->pSet = new ProjectSettings($this->container->pSet->_table);
         //	set view page
         $this->pSet->setPage($this->container->pageType);
         //	set edit page
         $this->pSet->setPage($this->container->pSet->getPageTypeByFieldEditFormat($field, EDIT_FORMAT_LOOKUP_WIZARD));
     } else {
         $this->pSet = $this->container->pSet;
     }
     $this->nLookupType = $this->pSet->getLookupType($this->field);
     $this->lookupTable = $this->pSet->getLookupTable($this->field);
     $this->setLookupConnection();
     $this->displayFieldName = $this->pSet->getDisplayField($this->field);
     $this->linkFieldName = $this->pSet->getLinkField($this->field);
     $this->linkAndDisplaySame = $this->displayFieldName == $this->linkFieldName;
     if ($this->nLookupType == LT_QUERY) {
         $this->lookupPSet = new ProjectSettings($this->lookupTable, $this->container->pageType);
         $this->cipherer = new RunnerCipherer($this->lookupTable);
         $this->lookupQueryObj = $this->lookupPSet->getSQLQuery()->CloneObject();
         if ($this->pSet->getCustomDisplay($this->field)) {
             $this->lookupQueryObj->AddCustomExpression($this->displayFieldName, $this->lookupPSet, $this->pSet->_table, $this->field);
         }
         $this->lookupQueryObj->ReplaceFieldsWithDummies($this->lookupPSet->getBinaryFieldsIndices());
         $lookupIndexes = GetLookupFieldsIndexes($this->pSet, $this->field);
         $this->displayFieldIndex = $lookupIndexes["displayFieldIndex"];
         $this->linkFieldIndex = $lookupIndexes["linkFieldIndex"];
     } else {
         $this->cipherer = new RunnerCipherer($this->pSet->_table);
         $this->LookupSQL = "SELECT ";
         $this->LookupSQL .= RunnerPage::sqlFormattedDisplayField($this->field, $this->lookupConnection, $this->pSet);
         $this->LookupSQL .= ", " . $this->lookupConnection->addFieldWrappers($this->pSet->getLinkField($this->field));
         $this->LookupSQL .= " FROM " . $this->lookupConnection->addTableWrappers($this->lookupTable) . " WHERE ";
     }
     $this->localControlsContainer = new ViewControlsContainer($this->pSet, $this->container->pageType, $pageObject);
     $this->localControlsContainer->isLocal = true;
 }
Exemplo n.º 3
0
function GetAddedDataLookupQuery($pageObject, $keys, $forLookup)
{
    global $conn, $strTableName, $strOriginalTableName;
    $LookupSQL = "";
    $linkfield = "";
    $dispfield = "";
    $noBlobReplace = false;
    $lookupFieldName = "";
    if ($LookupSQL && $nLookupType != LT_QUERY) {
        $LookupSQL .= " from " . AddTableWrappers($strOriginalTableName);
    }
    $data = 0;
    $lookupIndexes = array("linkFieldIndex" => 0, "displayFieldIndex" => 0);
    if (count($keys)) {
        $where = KeyWhere($keys);
        if ($nLookupType == LT_QUERY) {
            $LookupSQL = $lookupQueryObj->toSql(whereAdd($lookupQueryObj->m_where->toSql($lookupQueryObj), $where));
        } else {
            $LookupSQL .= " where " . $where;
        }
        $lookupIndexes = GetLookupFieldsIndexes($lookupPSet, $lookupFieldName);
        LogInfo($LookupSQL);
        if ($forLookup) {
            $rs = db_query($LookupSQL, $conn);
            $data = $pageObject->cipherer->DecryptFetchedArray($rs);
        } else {
            if ($LookupSQL) {
                $rs = db_query($LookupSQL, $conn);
                $data = db_fetch_numarray($rs);
                $data[$lookupIndexes["linkFieldIndex"]] = $pageObject->cipherer->DecryptField($linkFieldName, $data[$lookupIndexes["linkFieldIndex"]]);
                if ($nLookupType == LT_QUERY) {
                    $data[$lookupIndexes["displayFieldIndex"]] = $pageObject->cipherer->DecryptField($dispfield, $data[$lookupIndexes["displayFieldIndex"]]);
                }
            }
        }
    }
    return array($data, array("linkField" => $linkFieldName, "displayField" => $dispfield, "linkFieldIndex" => $lookupIndexes["linkFieldIndex"], "displayFieldIndex" => $lookupIndexes["displayFieldIndex"]));
}
Exemplo n.º 4
0
            $LookupSQL = $lookupQueryObj->toSql(whereAdd($lookupQueryObj->m_where->toSql($lookupQueryObj), $strLookupWhere), strlen($lookupOrderBy) ? ' ORDER BY ' . $lookupOrderBy : null);
        } else {
            $LookupSQL = $LookupSQLTable . " where " . $strLookupWhere;
            if (!$gSettings->isLookupUnique($f) || nDATABASE_Access != $lookupConnection->dbType) {
                if ($lookupOrderBy) {
                    $LookupSQL .= " ORDER BY " . $lookupOrderBy;
                }
            }
        }
    }
    if (strlen(GetLWWhere($f, $pageType, $strTableName))) {
        $hasWhere = true;
    }
    break;
}
$lookupIndexes = GetLookupFieldsIndexes($gSettings, $lookupField);
$linkFieldIndex = $lookupIndexes["linkFieldIndex"];
$displayFieldIndex = $lookupIndexes["displayFieldIndex"];
if ($lookupConnection) {
    $qResult = $lookupConnection->query($LookupSQL);
    while ($data = $qResult->fetchNumeric()) {
        if ($LookupType == LT_QUERY && $gSettings->isLookupUnique($lookupField)) {
            if (!isset($uniqueArray)) {
                $uniqueArray = array();
            }
            if (in_array($data[$displayFieldIndex], $uniqueArray)) {
                continue;
            }
            $uniqueArray[] = $data[$displayFieldIndex];
        }
        $data[$linkFieldIndex] = $cipherer->DecryptField($lookupField, $data[$linkFieldIndex]);
Exemplo n.º 5
0
 /**
  * @param Boolean forLookup
  * @param String mainTableShortName
  * @param String mainField
  * @param String pageType
  * @return Array
  */
 protected function GetAddedDataLookupQuery($forLookup, $mainTableShortName, $mainField, $pageType)
 {
     $lookupMainSettings = getLookupMainTableSettings($this->tName, $mainTableShortName, $mainField, $pageType);
     if (!$lookupMainSettings) {
         return array();
     }
     $LookupSQL = "";
     $mainTable = $lookupMainSettings->getTableName();
     $linkFieldName = $lookupMainSettings->getLinkField($mainField);
     $dispfield = $lookupMainSettings->getDisplayField($mainField);
     if ($lookupMainSettings->getCustomDisplay($mainField)) {
         $this->pSet->getSQLQuery()->AddCustomExpression($dispfield, $this->pSet, $mainTable, $mainField);
     }
     $lookupQueryObj = $this->pSet->getSQLQuery()->CloneObject();
     $data = array();
     $lookupIndexes = array("linkFieldIndex" => 0, "displayFieldIndex" => 0);
     if (count($this->keys)) {
         $where = KeyWhere($this->keys);
         $LookupSQL = $lookupQueryObj->toSql(whereAdd($lookupQueryObj->m_where->toSql($lookupQueryObj), $where));
         $lookupIndexes = GetLookupFieldsIndexes($lookupMainSettings, $mainField);
         LogInfo($LookupSQL);
         if ($forLookup) {
             $data = $this->cipherer->DecryptFetchedArray($this->connection->query($LookupSQL)->fetchAssoc());
         } else {
             if ($LookupSQL) {
                 $data = $this->connection->query($LookupSQL)->fetchNumeric();
                 $data[$lookupIndexes["linkFieldIndex"]] = $this->cipherer->DecryptField($linkFieldName, $data[$lookupIndexes["linkFieldIndex"]]);
                 $data[$lookupIndexes["displayFieldIndex"]] = $this->cipherer->DecryptField($dispfield, $data[$lookupIndexes["displayFieldIndex"]]);
             }
         }
     }
     return array($data, array("linkField" => $linkFieldName, "displayField" => $dispfield, "linkFieldIndex" => $lookupIndexes["linkFieldIndex"], "displayFieldIndex" => $lookupIndexes["displayFieldIndex"]));
 }
Exemplo n.º 6
0
function loadSelectContent($pageType, $childFieldName, $parentVal, $doCategoryFilter = true, $childVal = "", $initialLoad = true)
{
    global $conn, $LookupSQL, $strTableName;
    $pSet = new ProjectSettings($strTableName, $pageType);
    $response = array();
    $lookupType = $pSet->getLookupType($childFieldName);
    $isUnique = $pSet->isLookupUnique($childFieldName);
    if ($pSet->useCategory($childFieldName) && $doCategoryFilter) {
        if ($lookupType == LT_QUERY) {
            $lookupTable = $pSet->getLookupTable($childFieldName);
            $cipherer = new RunnerCipherer($lookupTable);
            $tempParentVal = $cipherer->MakeDBValue($pSet->getCategoryControl($childFieldName), $parentVal, "", $lookupTable, true);
        } else {
            $tempParentVal = make_db_value($childFieldName, $parentVal);
        }
        if ($tempParentVal === "null") {
            return $response;
        }
    }
    $LookupSQL = buildLookupSQL($pageType, $childFieldName, $strTableName, $parentVal, $childVal, $doCategoryFilter, $pSet->fastType($childFieldName) && $initialLoad);
    $lookupIndexes = GetLookupFieldsIndexes($pSet, $childFieldName);
    $rs = db_query($LookupSQL, $conn);
    if (!$pSet->fastType($childFieldName)) {
        while ($data = db_fetch_numarray($rs)) {
            if ($lookupType == LT_QUERY && $isUnique) {
                if (!isset($uniqueArray)) {
                    $uniqueArray = array();
                }
                if (in_array($data[$lookupIndexes["displayFieldIndex"]], $uniqueArray)) {
                    continue;
                }
                $uniqueArray[] = $data[$lookupIndexes["displayFieldIndex"]];
            }
            $response[] = $data[$lookupIndexes["linkFieldIndex"]];
            $response[] = $data[$lookupIndexes["displayFieldIndex"]];
        }
    } else {
        $data = db_fetch_numarray($rs);
        //	one record only
        if ($data && (strlen($childVal) || !db_fetch_numarray($rs))) {
            $response[] = $data[$lookupIndexes["linkFieldIndex"]];
            $response[] = $data[$lookupIndexes["displayFieldIndex"]];
        }
    }
    return $response;
}
Exemplo n.º 7
0
 public function fillLookupFieldsIndexes()
 {
     $lookupIndexes = GetLookupFieldsIndexes($this->localPSet, $this->field);
     $this->linkFieldIndex = $lookupIndexes["linkFieldIndex"];
     $this->displayFieldIndex = $lookupIndexes["displayFieldIndex"];
 }
Exemplo n.º 8
0
 /**
  * Get for the dependent lookup an array containing the link field values with even indices
  * and the corresponding displayed values with odd indices
  *
  * @intellisense
  * @param String parentVal
  * @param String childVal
  * @param Boolean doCategoryFilter
  * @param Boolean initialLoad
  * @return Array
  */
 public function loadLookupContent($parentVal, $childVal = "", $doCategoryFilter = true, $initialLoad = true)
 {
     $response = array();
     $pSet = $this->pageObject->pSetEdit;
     if ($this->bUseCategory && $doCategoryFilter) {
         if ($this->lookupType == LT_QUERY) {
             $tempParentVal = $this->ciphererDisplay->MakeDBValue($pSet->getCategoryControl($this->field), $parentVal, "", true);
         } else {
             $tempParentVal = make_db_value($this->field, $parentVal);
         }
         if ($tempParentVal === "null" || 0 == strlen($parentVal)) {
             return $response;
         }
     }
     $LookupSQL = $this->getLookupSQL($parentVal, $childVal, $doCategoryFilter, $this->LCType == LCT_AJAX && $initialLoad);
     $lookupIndexes = GetLookupFieldsIndexes($pSet, $this->field);
     $qResult = $this->lookupConnection->query($LookupSQL);
     if ($this->LCType !== LCT_AJAX || $this->multiselect) {
         $isUnique = $pSet->isLookupUnique($this->field);
         while ($data = $qResult->fetchNumeric()) {
             if ($this->lookupType == LT_QUERY && $isUnique) {
                 if (!isset($uniqueArray)) {
                     $uniqueArray = array();
                 }
                 if (in_array($data[$lookupIndexes["displayFieldIndex"]], $uniqueArray)) {
                     continue;
                 }
                 $uniqueArray[] = $data[$lookupIndexes["displayFieldIndex"]];
             }
             $response[] = $data[$lookupIndexes["linkFieldIndex"]];
             $response[] = $data[$lookupIndexes["displayFieldIndex"]];
         }
     } else {
         $data = $qResult->fetchNumeric();
         // one record only
         if ($data && (strlen($childVal) || !$qResult->fetchNumeric())) {
             $response[] = $data[$lookupIndexes["linkFieldIndex"]];
             $response[] = $data[$lookupIndexes["displayFieldIndex"]];
         }
     }
     return $response;
 }
Exemplo n.º 9
0
 /**
  * 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"];
 }