function sqlCount($table) { $r = mysql_query("SELECT COUNT(*) FROM " . $table); if (!$r) { die("SQL Error: " . mysql_errno() . ": " . mysql_error()); } return sqlResult($r, 0); }
function sessionRead($session_id) { $sql = "SELECT data FROM market_session WHERE session_id='" . $session_id . "'"; if (sqlQuery($sql, $res, EXT_DEBUG)) { return sqlResult($res, 0); } return ''; }
function assignNavigationValues(&$sql, $layout = 'default', $start = 0, $show = 10, $limit = 0, $javascript = false, $group = false, $absolute = false) { if (preg_match('@\\d+@', $_GET['show'])) { $show = $_GET['show']; } if (preg_match('@\\d+@', $_GET['page'])) { $start = ($_GET['page'] - 1) * $show; } if (isset($_GET['start']) && preg_match('@\\d+@', $_GET['start'])) { $start = $_GET['start']; } if ($limit && $show > $limit) { $show = $limit; } if (!$show) { $show = 10; } if ($start < 0) { $start = 0; } $start = floor($start / $show) * $show; if (preg_match('@^SELECT@', $sql)) { $sig = md5($sql . $_GET['group']); $sqp =& $this->getRef('Sql_Parser'); $sqp->parseSQL($sql); if ($_SESSION['NAV.Vars']['NAV.Sig'] == $sig) { $total = $_SESSION['NAV.Vars']['NAV.Total']; $stotal = $_SESSION['NAV.Vars']['NAV.STotal']; // Group on parent_id if ($group && $_GET['group'] && !$_GET['gid'] && !$_GET['expand']) { if (strstr($sqp->sql['FROM'], ' ')) { $table = substr($sqp->sql['FROM'], 0, strpos($sqp->sql['FROM'], ' ')); } else { $table = $sqp->sql['FROM']; } $sqp->sql['WHERE'] .= " AND " . $table . ".parent_id=''"; $sql = $sqp->getSQL(); } } else { $count_sql = $this->getCountSql($sqp); if (sqlQuery($count_sql, $res)) { $total = sqlResult($res, 0); if ($_GET['gid'] && preg_match('@UNION@', $sql)) { $total++; } } // Group on parent_id if ($group && $_GET['group'] && !$_GET['gid'] && !$_GET['expand']) { if (strstr($sqp->sql['FROM'], ' ')) { $table = substr($sqp->sql['FROM'], 0, strpos($sqp->sql['FROM'], ' ')); } else { $table = $sqp->sql['FROM']; } $sqp->sql['WHERE'] .= " AND " . $table . ".parent_id=''"; $count_sql = $this->getCountSql($sqp); if (sqlQuery($count_sql, $res)) { $stotal = $total; $total = sqlResult($res, 0); } $sql = $sqp->getSQL(); } } $_SESSION['NAV.Vars']['NAV.Sig'] = $sig; $_SESSION['NAV.Vars']['NAV.Total'] = $total; $_SESSION['NAV.Vars']['NAV.STotal'] = $stotal; if ($start > $total) { $start = 0; } // Modify the sql $sql .= " LIMIT {$start}, {$show}"; } else { if (preg_match('@^\\d+$@', $sql)) { $total = $sql; } else { $this->raiseError(MARKET_ERROR_WARNING, 'assignNavigationValues(): wrong datatype for first argument', __FILE__, __LINE__); $total = 0; } } if ($start > $total) { $start = 0; } // First if ($start == 0) { $first = -1; } // Previous if (($previous = $start - $show) < 0) { $previous = 0; } // Next if (($next = $start + $show) >= $total) { $next = -1; $end = $total; } else { $end = $start + $show; } // Last if (($last = floor(($total - 1) / $show) * $show) <= $start) { $last = -1; } $lng =& $this->getRef('Lang'); // Found if ($total == 0) { $found = '0 ' . $lng->strs['items_total']; } else { if ($total == 1) { if ($stotal) { if ($stotal == 1) { $found = '1 ' . $lng->strs['item_total'] . ' ' . $lng->strs['in']; } else { $found = $stotal . ' ' . $lng->strs['items_total'] . ' ' . $lng->strs['in']; } $found .= ' 1 ' . $lng->strs['set']; } else { $found = '1 ' . $lng->strs['item_total']; } } else { if ($stotal) { $found = MARKET_Filter::marketNumber($stotal) . ' ' . $lng->strs['items_total'] . ' ' . $lng->strs['in'] . ' ' . MARKET_Filter::marketNumber($total) . ' ' . $lng->strs['sets'] . ' [' . $lng->strs['sets'] . ' ' . ($start + 1) . ' - ' . $end . ']'; } else { if ($show == 1) { $found = MARKET_Filter::marketNumber($total) . ' ' . $lng->strs['items_total'] . ' [' . ($start + 1) . ']'; } else { $found = MARKET_Filter::marketNumber($total) . ' ' . $lng->strs['items_total'] . ' [' . ($start + 1) . ' - ' . $end . ']'; } } } } $req =& $this->getRef('Request'); // Pages $num_of_pages = ceil($total / $show); if ($num_of_pages) { $pagesx = ''; $page_num = floor($start / $show); // Previous if ($first == -1 || $start == 0) { $pages = '<span class="disabled prev_page">' . $lng->strs['Previous'] . '</span><span class="gap"> </span> '; $this->assignGlobal('PAGESX.Previous', '<span class="disabled prev_page">« ' . substr($lng->strs['Previous'], 4) . '</span> '); } else { $href = $javascript ? "javascript:rIU('start', '" . $previous . "')" : ($absolute ? '{MARKET.WebDir}/' : '') . $req->replaceInUrl('start', $previous); $pages = '<a class="previous_page" href="' . $href . '">' . $lng->strs['Previous'] . '</a><span class="gap"> </span> '; $this->assignGlobal('PAGESX.Previous', '<a class="previous_page" href="' . $href . '">« ' . substr($lng->strs['Previous'], 4) . '</a> '); } if ($page_num < 4) { $start_from = 1; $up_to = $page_num == 3 ? 6 : 5; } else { // First $href = $javascript ? "javascript:rIU('start', '0')" : ($absolute ? '{MARKET.WebDir}/' : '') . $req->replaceInUrl('start', 0); if ($num_of_pages != 5) { $pages .= '<a class="first_page" href="' . $href . '">1<span class="ellipsis">...</span></a> '; $pagesx .= '<a href="' . $href . '">1</a> <span class="gap">…</span> '; } if ($page_num > $num_of_pages - 5) { $start_from = $page_num == $num_of_pages - 4 ? $num_of_pages - 5 : $num_of_pages - 4; $up_to = $num_of_pages; } else { $start_from = $page_num - 1; $up_to = $page_num + 3; } } for ($i = $start_from; $i <= $up_to; $i++) { if ($i <= $num_of_pages) { if ($i == $page_num + 1) { $pages .= '<span class="current_page">[' . $i . ']</span> '; $pagesx .= '<span class="current">' . $i . '</span> '; } else { $href = $javascript ? "javascript:rIU('start', '" . ($i - 1) * $show . "')" : ($absolute ? '{MARKET.WebDir}/' : '') . $req->replaceInUrl('start', ($i - 1) * $show); $pages .= '<a class="some_page" href="' . $href . '">' . $i . '</a> '; $pagesx .= '<a href="' . $href . '">' . $i . '</a> '; } } } // Last if ($up_to < $num_of_pages - 1) { $href = $javascript ? "javascript:rIU('start', '" . ($num_of_pages - 1) * $show . "')" : ($absolute ? '{MARKET.WebDir}/' : '') . $req->replaceInUrl('start', ($num_of_pages - 1) * $show); $pages .= '<a class="last_page" href="' . $href . '"><span class="ellipsis">...</span>' . $num_of_pages . '</a> '; $pagesx .= '<span class="gap">…</span> <a href="' . $href . '">' . $num_of_pages . '</a> '; } $this->assignGlobal('PAGESX.Pages', $pagesx); // Next if ($last == -1) { $pages .= '<span class="gap"> </span><span class="disabled next_page">' . $lng->strs['Next'] . '</span>'; $this->assignGlobal('PAGESX.Next', '<span class="disabled next_page">' . substr($lng->strs['Next'], 0, -4) . ' »</span> '); } else { $href = $javascript ? "javascript:rIU('start', '" . $next . "')" : ($absolute ? '{MARKET.WebDir}/' : '') . $req->replaceInUrl('start', $next); $pages .= '<span class="gap"> </span><a class="next_page" href="' . $href . '">' . $lng->strs['Next'] . '</a>'; $this->assignGlobal('PAGESX.Next', '<a class="next_page" href="' . $href . '">' . substr($lng->strs['Next'], 0, -4) . ' »</a> '); } $this->loadTemplate($layout . '/navigation', MARKET_INDIRECT_CALL); $this->parseTemplate('foo', 'pagesx'); } if ($layout) { $rels = ''; if ($first == -1) { $this->assignGlobal(array('NAV.Lnk_First' => '<a class="disabled"><i>' . $lng->strs['First'] . '</i></a>', 'NAV.Lnk_Previous' => '<a class="disabled"><i>' . $lng->strs['Previous'] . '</i></a>')); } else { $href1 = $javascript ? "javascript:rIU('start', '0');" : ($absolute ? '{MARKET.WebDir}/' : '') . $req->replaceInUrl('start', 0); $href2 = $javascript ? "javascript:rIU('start', '" . $previous . "');" : ($absolute ? '{MARKET.WebDir}/' : '') . $req->replaceInUrl('start', $previous); $this->assignGlobal(array('NAV.Lnk_First' => '<a href="' . $href1 . '"><i>' . $lng->strs['First'] . '</i></a>', 'NAV.Lnk_Previous' => '<a href="' . $href2 . '"><i>' . $lng->strs['Previous'] . '</i></a>')); $rels .= '<link rel="first" href="' . ($absolute ? '{MARKET.WebDir}/' : '') . $req->replaceInUrl('start', 0) . '" />' . "\n"; $rels .= '<link rel="previous" href="' . ($absolute ? '{MARKET.WebDir}/' : '') . $req->replaceInUrl('start', $previous) . '" />' . "\n"; } if ($last == -1) { $this->assignGlobal(array('NAV.Lnk_Next' => '<a class="disabled"><i>' . $lng->strs['Next'] . '</i></a>', 'NAV.Lnk_Last' => '<a class="disabled"><i>' . $lng->strs['Last'] . '</i></a>')); } else { $href1 = $javascript ? "javascript:rIU('start', '" . $next . "');" : ($absolute ? '{MARKET.WebDir}/' : '') . $req->replaceInUrl('start', $next); $href2 = $javascript ? "javascript:rIU('start', '" . $last . "');" : ($absolute ? '{MARKET.WebDir}/' : '') . $req->replaceInUrl('start', $last); $this->assignGlobal(array('NAV.Lnk_Next' => '<a href="' . $href1 . '"><i>' . $lng->strs['Next'] . '</i></a>', 'NAV.Lnk_Last' => '<a href="' . $href2 . '"><i>' . $lng->strs['Last'] . '</i></a>')); $rels .= '<link rel="next" href="' . ($absolute ? '{MARKET.WebDir}/' : '') . $req->replaceInUrl('start', $next) . '" />' . "\n"; $rels .= '<link rel="last" href="' . ($absolute ? '{MARKET.WebDir}/' : '') . $req->replaceInUrl('start', $last) . '" />' . "\n"; } if ($group) { if ($_GET['group']) { $href = $javascript ? "javascript:rIU('group', '0');" : ($absolute ? '{MARKET.WebDir}/' : '') . $req->replaceInUrl('group', '0'); $this->assignGlobal('NAV.Group', '<span id="group"><a class="selected" href="' . $href . '"><i>' . $lng->strs['Group'] . '</i></a></span>'); } else { if ($_GET['version_history'] || is_object($sqp) && !preg_match('@parent_id@', $sqp->sql['SELECT'])) { $this->assignGlobal('NAV.Group', '<span id="group"><a class="disabled"><i>' . $lng->strs['Group'] . '</i></a></span>'); } else { $href = $javascript ? "javascript:rIU('group', '1');" : ($absolute ? '{MARKET.WebDir}/' : '') . $req->replaceInUrl('group', '1'); $this->assignGlobal('NAV.Group', '<span id="group"><a href="' . $href . '"><i>' . $lng->strs['Group'] . '</i></a></span>'); } } } $this->assignGlobal('PAGE.Rels', $rels); $this->loadTemplate($layout . '/navigation', MARKET_INDIRECT_CALL); $this->parseTemplate('foo', 'toolbar'); } $this->assignGlobal(array('NAV.Start' => $start + 1, 'NAV.Page' => $page_num + 1, 'NAV.End' => $end, 'NAV.Found' => $found, 'NAV.Show' => $show, 'NAV.Total' => $total, 'NAV.Previous' => $previous, 'NAV.Next' => $next, 'NAV.Last' => $last, 'NAV.Pages' => $pages)); // Next Page if ($next != -1) { $this->assignGlobal('NAV.NextPage', $page_num + 2); } else { $this->assignGlobal('NAV.NextPage', 1); } return array($start, $show, $total, $end); }