/** * @param &Array data * @param String securityMode * @param &Array next * @param &Array prev * @param Boolean onDash */ function getNextPrevRecordKeys(&$data, $securityMode, &$next, &$prev, $onDash = false) { $next = array(); $prev = array(); if (@$_SESSION[$this->sessionPrefix . "_noNextPrev"]) { return; } $prevExpr = ""; $nextExpr = ""; $where_next = ""; $where_prev = ""; $order_next = ""; $order_prev = ""; require_once getabspath('classes/orderclause.php'); $orderClause = new OrderClause($this); $orderClause->init(); if (!$this->pSet->hasListPage() || !count($orderClause->fieldsList)) { $orderClause->adjustFiledList(); } if (!count($orderClause->fieldsList)) { $_SESSION[$this->sessionPrefix . "_noNextPrev"] = 1; return; } $query = $this->pSet->getQueryObject(); if ($query === null) { return; } // make next & prev ORDER BY strings for ($i = 0; $i < count($orderClause->fieldsList); $i++) { $field = $orderClause->fieldsList[$i]; if (!$this->pSet->GetFieldByIndex($field->fieldIndex)) { continue; } $order_next = $order_next == "" ? " ORDER BY " : $order_next . ","; $order_prev = $order_prev == "" ? " ORDER BY " : $order_prev . ","; $order_next .= $field->fieldIndex . " " . $field->orderDirection; $order_prev .= $field->fieldIndex . " " . ($field->orderDirection == "DESC" ? "ASC" : "DESC"); } // make next & prev where expressions $tail = ""; for ($i = 0; $i < count($orderClause->fieldsList); $i++) { $field = $orderClause->fieldsList[$i]; $fieldName = $this->pSet->GetFieldByIndex($field->fieldIndex); if (!$fieldName) { continue; } if (!$query->HasGroupBy()) { $fullName = $this->getFieldSQLDecrypt($fieldName); } else { $fullName = $this->connection->addFieldWrappers($fieldName); } $asc = $field->orderDirection == "ASC"; if (!is_null($data[$fieldName])) { // current field value is not null $value = $this->cipherer->MakeDBValue($fieldName, $data[$fieldName], "", true); $nextExpr = $fullName . ($asc ? ">" : "<") . $value; $prevExpr = $fullName . ($asc ? "<" : ">") . $value; if (!$asc) { $nextExpr .= " or " . $fullName . " IS NULL"; } else { $prevExpr .= " or " . $fullName . " IS NULL"; } if ($i < count($orderClause->fieldsList) - 1) { $nextExpr .= " or " . $fullName . "=" . $value; $prevExpr .= " or " . $fullName . "=" . $value; } } else { $nextExpr = ""; $prevExpr = ""; // current field value is null if ($asc) { $nextExpr = $fullName . " IS NOT NULL"; } else { $prevExpr = $fullName . " IS NOT NULL"; } if ($i < count($orderClause->fieldsList) - 1) { if ($nextExpr != "") { $nextExpr .= " or "; } $nextExpr .= $fullName . " IS NULL"; if ($prevExpr != "") { $prevExpr .= " or "; } $prevExpr .= $fullName . " IS NULL"; } } if ($nextExpr == "") { $nextExpr = " 1=0 "; } if ($prevExpr == "") { $prevExpr = " 1=0 "; } // append expression to where clause if ($i > 0) { $where_next .= " AND "; $where_prev .= " AND "; } $where_next .= "(" . $nextExpr; $where_prev .= "(" . $prevExpr; $tail .= ")"; } $where_next = $where_next . $tail; $where_prev = $where_prev . $tail; if ($where_next == "" or $order_next == "" or $where_prev == "" or $order_prev == "") { $_SESSION[$this->sessionPrefix . "_noNextPrev"] = 1; return; } $where = $_SESSION[$this->sessionPrefix . "_where"]; if ($onDash && $this->searchClauseObj->bIsUsedSrch) { $whereComponents = $this->getWhereComponents(); $where = SecuritySQL($securityMode, $this->tName); $where = whereAdd($where, $whereComponents["searchWhere"]); $_SESSION[$this->sessionPrefix . "_where"] = $where; } elseif (!$onDash && !strlen($where)) { $where = SecuritySQL($securityMode, $this->tName); } $where = whereAdd($where, $query->Where()->toSql($query)); $joinFromPart = $_SESSION[$this->sessionPrefix . "_joinFromPart"]; $query->ReplaceFieldsWithDummies($this->pSet->getBinaryFieldsIndices()); if (!$query->HasGroupBy()) { $where_next = whereAdd($where_next, $where); $where_prev = whereAdd($where_prev, $where); $sql_next = $query->toSql($where_next, $order_next, null, false, $joinFromPart); $sql_prev = $query->toSql($where_prev, $order_prev, null, false, $joinFromPart); } else { $having = $_SESSION[$this->sessionPrefix . "_having"]; if ($onDash && $this->searchClauseObj->bIsUsedSrch) { $whereComponents = $this->getWhereComponents(); $having = whereAdd($having, $whereComponents["searchHaving"]); $_SESSION[$this->sessionPrefix . "_having"] = $having; } $having = whereAdd($having, $query->Having()->toSql($query)); $sql = "select * from (" . $query->toSql($where, "", $having, false, $joinFromPart) . ") prevnextquery"; $sql_next = $sql . " WHERE " . $where_next . $order_next; $sql_prev = $sql . " WHERE " . $where_prev . $order_prev; } if ($this->connection->dbType != nDATABASE_MSSQLServer) { //return to actual list page if ($prevExpr == " 1=0 ") { $_SESSION[$this->sessionPrefix . "_pagenumber"] = 1; } else { $pageSQL = "select count(*) from (" . $sql_prev . ") tcount"; $pageRow = $this->connection->query($pageSQL)->fetchNumeric(); $currentRow = $pageRow[0]; if ($this->pageSize > 0) { $pageSize = $this->pageSize; } else { $pageSize = $this->pSet->getInitialPageSize(); } $this->myPage = floor($currentRow / $pageSize) + 1; $_SESSION[$this->sessionPrefix . "_pagenumber"] = $this->myPage; } } $tKeys = $this->pSet->getTableKeys(); // add record count options $sql_next = applyDBrecordLimit($sql_next, 1, $this->connection->dbType); $sql_prev = applyDBrecordLimit($sql_prev, 1, $this->connection->dbType); $next = $this->getKeysDataForPrevNext($sql_next, $tKeys); $prev = $this->getKeysDataForPrevNext($sql_prev, $tKeys); }
/** * Read current values from the database * @return Array The current record data */ public function getCurrentRecordInternal() { if (!is_null($this->data)) { return $this->data; } $strWhereClause = ""; $orderClause = ""; $keysSet = $this->checkKeysSet(); if ($keysSet) { $strWhereClause = KeyWhere($this->keys); } elseif ($this->mode == VIEW_DASHBOARD) { $whereComponents = $this->getWhereComponents(); $strWhereClause = $whereComponents["searchWhere"]; } else { $orderClause = $this->getOrderByClause(); $strWhereClause = $_SESSION[$this->sessionPrefix . "_where"]; } if ($this->pSet->getAdvancedSecurityType() != ADVSECURITY_ALL) { $strWhereClause = whereAdd($strWhereClause, SecuritySQL("Search", $this->tName)); } $strSQL = $this->gQuery->gSQLWhere($strWhereClause); if (!$keysSet) { $strSQL = applyDBrecordLimit($strSQL . $orderClause, 1, $this->connection->dbType); } $strSQLbak = $strSQL; $strWhereClauseBak = $strWhereClause; if ($this->eventsObject->exists("BeforeQueryView")) { $this->eventsObject->BeforeQueryView($strSQL, $strWhereClause, $this); } if ($strSQLbak == $strSQL && $strWhereClauseBak != $strWhereClause) { // user didn't change the query string but changed $strWhereClause $strSQL = $this->gQuery->gSQLWhere($strWhereClause); if (!$keysSet) { $strSQL = applyDBrecordLimit($strSQL . $orderClause, 1, $this->connection->dbType); } } LogInfo($strSQL); $fetchedArray = $this->connection->query($strSQL)->fetchAssoc(); $this->data = $this->cipherer->DecryptFetchedArray($fetchedArray); if (!$keysSet) { $this->keys = $this->getKeysFromData($this->data); $this->setKeysForJs(); } if (sizeof($this->data) && $this->eventsObject->exists("ProcessValuesView")) { $this->eventsObject->ProcessValuesView($this->data, $this); } return $this->data; }
/** * Read current values from the database * @return Array The current record data */ public function getCurrentRecordInternal() { if (!is_null($this->cachedRecord)) { return $this->cachedRecord; } $keysSet = $this->checkKeysSet(); $orderClause = ""; $havingClause = ""; if (!$keysSet) { $orderClause = $this->getOrderByClause(); if ($this->mode == EDIT_DASHBOARD) { $whereComponents = $this->getWhereComponents(); $havingClause = $whereComponents["searchHaving"]; } } $strWhereClause = $this->getWhereClause(false); $strSQL = $this->gQuery->gSQLWhere($strWhereClause, $havingClause); if (!$keysSet) { $strSQL = applyDBrecordLimit($strSQL . $orderClause, 1, $this->connection->dbType); } $strSQLbak = $strSQL; $strWhereClauseBak = $strWhereClause; // Before Query event if ($this->eventsObject->exists("BeforeQueryEdit")) { $this->eventsObject->BeforeQueryEdit($strSQL, $strWhereClause, $this); } if ($strSQLbak == $strSQL && $strWhereClauseBak != $strWhereClause) { $strSQL = $this->gQuery->gSQLWhere($strWhereClause, $havingClause); if (!$keysSet) { $strSQL = applyDBrecordLimit($strSQL . $orderClause, 1, $this->connection->dbType); } } LogInfo($strSQL); $fetchedArray = $this->connection->query($strSQL)->fetchAssoc(); $this->cachedRecord = $this->cipherer->DecryptFetchedArray($fetchedArray); if (!$keysSet) { $this->keys = $this->getKeysFromData($this->cachedRecord); $this->setKeysForJs(); } if (!$this->cachedRecord && $this->mode == EDIT_SIMPLE) { return $this->cachedRecord; } foreach ($this->getPageFields() as $fName) { if (@$_POST["a"] != "edited" && $this->pSet->getAutoUpdateValue($fName) !== "") { $this->cachedRecord[$fName] = $this->pSet->getAutoUpdateValue($fName); } } if ($this->readEditValues) { foreach ($this->getPageFields() as $fName) { $editFormat = $this->pSet->getEditFormat($fName); if ($editFormat == EDIT_FORMAT_DATABASE_FILE && $editFormat != EDIT_FORMAT_DATABASE_IMAGE && $editFormat != EDIT_FORMAT_FILE && !$this->pSet->isReadonly($fName)) { $this->cachedRecord[$fName] = $this->newRecordData[$fName]; } } } if ($this->eventsObject->exists("ProcessValuesEdit")) { $this->eventsObject->ProcessValuesEdit($this->cachedRecord, $this); } return $this->cachedRecord; }