function make_url($url_normal, $url_rewritten_part1, $title = "", $url_rewritten_part2 = "")
{
    if (URL_REWRITE) {
        $url = $url_rewritten_part1 . clean_subject_urlrewrite($title) . $url_rewritten_part2;
    } else {
        $url = $url_normal;
    }
    return $url;
}
function pagination($new_pagination, $start, $count, $total, $range = 0, $link = "", $seo_root_link = "", $a = "-", $seo_catid = "", $b = "-page-", $c = "-", $seo_subject = "", $seo_end = '.html')
{
    // Pimped
    global $locale;
    $pagination = $new_pagination == true ? "page=" : "rowstart=";
    $seo_subject = clean_subject_urlrewrite($seo_subject);
    if ($link == "") {
        $link = FUSION_SELF . "?";
    }
    if (URL_REWRITE && $seo_root_link != "") {
        $link = $seo_root_link . $a . $seo_catid;
    }
    $pg_cnt = ceil($total / $count);
    if ($pg_cnt <= 1) {
        return "";
    }
    $idx_back = $start - $count;
    $idx_next = $start + $count;
    $cur_page = ceil(($start + 1) / $count);
    $res = $locale['global_092'] . " " . $cur_page . $locale['global_093'] . $pg_cnt . ": ";
    if ($idx_back >= 0) {
        if ($cur_page > $range + 1) {
            $res .= URL_REWRITE && $seo_root_link != "" ? "<a href='" . $link . $c . $seo_subject . $seo_end . "'>1</a>..." : "<a href='" . $link . "'>1</a>...";
            // Pimped
        }
    }
    $idx_fst = max($cur_page - $range, 1);
    $idx_lst = min($cur_page + $range, $pg_cnt);
    if ($range == 0) {
        $idx_fst = 1;
        $idx_lst = $pg_cnt;
    }
    for ($i = $idx_fst; $i <= $idx_lst; $i++) {
        $offset_page = ($i - 1) * $count;
        if ($i == $cur_page) {
            $res .= "<span><strong>" . $i . "</strong></span>";
        } else {
            $oi = $new_pagination == true ? $i : $offset_page;
            // Pimped
            $res .= URL_REWRITE && $seo_root_link != "" ? "<a href='" . $link . $b . $oi . $c . $seo_subject . $seo_end . "'>" . $i . "</a>" : "<a href='" . $link . $pagination . $oi . "'>" . $i . "</a>";
            // Pimped
        }
    }
    if ($idx_next < $total) {
        if ($cur_page < $pg_cnt - $range) {
            $oi = $new_pagination == true ? $pg_cnt : ($pg_cnt - 1) * $count;
            // Pimped
            $res .= URL_REWRITE && $seo_root_link != "" ? "...<a href='" . $link . $b . $oi . $c . $seo_subject . $seo_end . "'>" . $pg_cnt . "</a>\n" : "...<a href='" . $link . $pagination . $oi . "'>" . $pg_cnt . "</a>\n";
            // Pimped
        }
    }
    return "<div class='pagenav'>\n" . $res . "</div>\n";
}
function jump_to_forum($forum_id)
{
    global $fdata, $testaccess;
    $jump_list = "";
    $sel = "";
    $result = dbquery("SELECT f.forum_id, f.forum_parent, f2.forum_name AS forum_cat_name FROM " . DB_FORUMS . " f\r\n\tLEFT JOIN " . DB_FORUMS . " f2 ON f2.forum_id=f.forum_id\r\n\tWHERE " . groupaccess('f.forum_access', $testaccess) . " AND f2.forum_parent='{$forum_id}'");
    while ($data = dbarray($result)) {
        if (URL_REWRITE) {
            $value = $data['forum_id'] . "-" . clean_subject_urlrewrite($data['forum_cat_name']);
        } else {
            $value = $data['forum_id'];
        }
        // Pimped for make_url (for javascript
        $sel = $data['forum_id'] == $fdata['forum_id'] ? " selected='selected'" : "";
        // Pimped: --> Forum-Cats and make_url (for javascript)
        $jump_list .= "<option value='" . $value . "'{$sel}>&nbsp;&nbsp;-" . $data['forum_cat_name'] . "</option>\n";
    }
    return $jump_list;
}
function showratings($rating_type, $rating_item_id, $rating_link, $seo_link_root = "", $seo_link_subject = "")
{
    // Pimped: url-rewrite
    global $settings, $locale, $userdata;
    if (URL_REWRITE && $seo_link_root != "") {
        $seo_link = $seo_link_root . clean_subject_urlrewrite($seo_link_subject) . ".html";
    }
    // Pimped
    if ($settings['ratings_enabled'] == "1") {
        if (iMEMBER) {
            $d_rating = dbarray(dbquery("SELECT rating_vote,rating_datestamp FROM " . DB_RATINGS . " WHERE rating_item_id='" . $rating_item_id . "' AND rating_type='" . $rating_type . "' AND rating_user='******'user_id'] . "'"));
            if (isset($_POST['post_rating'])) {
                if (isnum($_POST['rating']) && $_POST['rating'] > 0 && $_POST['rating'] < 6 && !isset($d_rating['rating_vote'])) {
                    $result = dbquery("INSERT INTO " . DB_RATINGS . " (rating_item_id, rating_type, rating_user, rating_vote, rating_datestamp, rating_ip) VALUES ('{$rating_item_id}', '{$rating_type}', '" . $userdata['user_id'] . "', '" . $_POST['rating'] . "', '" . time() . "', '" . USER_IP . "')");
                }
                if (URL_REWRITE && $seo_link_root != "") {
                    redirect($seo_link);
                } else {
                    redirect($rating_link);
                }
                // Pimped
            } elseif (isset($_POST['remove_rating'])) {
                $result = dbquery("DELETE FROM " . DB_RATINGS . " WHERE rating_item_id='{$rating_item_id}' AND rating_type='{$rating_type}' AND rating_user='******'user_id'] . "'");
                if (URL_REWRITE && $seo_link_root != "") {
                    redirect($seo_link);
                } else {
                    redirect($rating_link);
                }
                // Pimped
            }
        }
        $ratings = array(5 => $locale['r120'], 4 => $locale['r121'], 3 => $locale['r122'], 2 => $locale['r123'], 1 => $locale['r124']);
        opentable($locale['r100']);
        if (!iMEMBER) {
            echo "<div style='text-align:center'>" . $locale['r104'] . "</div>\n";
        } elseif (isset($d_rating['rating_vote'])) {
            echo "<div style='text-align:center'>\n";
            echo "<form name='removerating' method='post' action='" . (URL_REWRITE && $seo_link_root != "" ? $seo_link : $rating_link) . "'>\n";
            // Pimped
            echo sprintf($locale['r105'], $ratings[$d_rating['rating_vote']], showdate("longdate", $d_rating['rating_datestamp'])) . "<br /><br />\n";
            echo "<input type='submit' name='remove_rating' value='" . $locale['r102'] . "' class='button' />\n";
            echo "</form>\n</div>\n";
        } else {
            echo "<div style='text-align:center'>\n";
            echo "<form name='postrating' method='post' action='" . (URL_REWRITE && $seo_link_root != "" ? $seo_link : $rating_link) . "'>\n";
            // Pimped
            echo $locale['r106'] . ": <select name='rating' class='textbox'>\n";
            echo "<option value='0'>" . $locale['r107'] . "</option>\n";
            foreach ($ratings as $rating => $rating_info) {
                echo "<option value='" . $rating . "'>{$rating_info}</option>\n";
            }
            echo "</select>\n";
            echo "<input type='submit' name='post_rating' value='" . $locale['r103'] . "' class='button' />\n";
            echo "</form>\n</div>";
        }
        echo "<hr />";
        $tot_votes = dbcount("(rating_item_id)", DB_RATINGS, "rating_item_id='" . $rating_item_id . "' AND rating_type='" . $rating_type . "'");
        if ($tot_votes) {
            echo "<table cellpadding='0' cellspacing='1' class='tbl-border center'>\n";
            foreach ($ratings as $rating => $rating_info) {
                $num_votes = dbcount("(rating_item_id)", DB_RATINGS, "rating_item_id='" . $rating_item_id . "' AND rating_type='" . $rating_type . "' AND rating_vote='" . $rating . "'");
                $pct_rating = number_format(100 / $tot_votes * $num_votes);
                if ($num_votes == 0) {
                    $votecount = "[" . $locale['r108'] . "]";
                } elseif ($num_votes == 1) {
                    $votecount = "[1 " . $locale['r109'] . "]";
                } else {
                    $votecount = "[" . $num_votes . " " . $locale['r110'] . "]";
                }
                $class = $rating % 2 == 0 ? "tbl1" : "tbl2";
                echo "<tr>\n";
                echo "<td class='{$class}'>" . $rating_info . "</td>\n";
                echo "<td width='250' class='{$class}'><img src='" . get_image("pollbar") . "' alt='" . $rating_info . "' height='12' width='" . $pct_rating . "%' class='poll' /></td>\n";
                echo "<td class='{$class}'>" . $pct_rating . "%</td>\n";
                echo "<td class='{$class}'>" . $votecount . "</td>\n";
                echo "</tr>\n";
            }
            echo "</table>\n";
        } else {
            echo "<div style='text-align:center'>" . $locale['r101'] . "</div>\n";
        }
        closetable();
    }
}
function makecommentnav($start, $count, $total, $range = 0, $link, $seo_root_link = "", $a = "-", $seo_catid = "", $b = "-page-", $rowstart = "", $d = "-cstart-", $c = "-", $seo_subject = "")
{
    global $locale;
    $seo_subject = clean_subject_urlrewrite($seo_subject);
    if (URL_REWRITE && $seo_root_link != "") {
        $link = $seo_root_link . $a . $seo_catid . $b . $rowstart;
    }
    $pg_cnt = ceil($total / $count);
    if ($pg_cnt <= 1) {
        return "";
    }
    $idx_back = $start - $count;
    $idx_next = $start + $count;
    $cur_page = ceil(($start + 1) / $count);
    $res = $locale['global_092'] . " " . $cur_page . $locale['global_093'] . $pg_cnt . ": ";
    if ($idx_back >= 0) {
        if ($cur_page > $range + 1) {
            if (URL_REWRITE && $seo_root_link != "") {
                $res .= "<a href='" . $link . $c . $seo_subject . ".html'>1</a>...";
            } else {
                $res .= "<a href='" . $link . "c_start=0'>1</a>";
            }
            if ($cur_page != $range + 2) {
                $res .= "...";
            }
        }
    }
    $idx_fst = max($cur_page - $range, 1);
    $idx_lst = min($cur_page + $range, $pg_cnt);
    if ($range == 0) {
        $idx_fst = 1;
        $idx_lst = $pg_cnt;
    }
    for ($i = $idx_fst; $i <= $idx_lst; $i++) {
        $offset_page = ($i - 1) * $count;
        if ($i == $cur_page) {
            $res .= "<span><strong>" . $i . "</strong></span>";
        } else {
            if (URL_REWRITE && $seo_root_link != "") {
                $res .= "<a href='" . $link . $d . $offset_page . $c . $seo_subject . ".html'>" . $i . "</a>";
            } else {
                $res .= "<a href='" . $link . "c_start=" . $offset_page . "'>" . $i . "</a>";
            }
        }
    }
    if ($idx_next < $total) {
        if ($cur_page < $pg_cnt - $range) {
            if ($cur_page != $pg_cnt - $range - 1) {
                $res .= "...";
            }
            if (URL_REWRITE && $seo_root_link != "") {
                $res .= "...<a href='" . $link . $d . ($pg_cnt - 1) * $count . $c . $seo_subject . ".html'>" . $pg_cnt . "</a>\n";
            } else {
                $res .= "<a href='" . $link . "c_start=" . ($pg_cnt - 1) * $count . "'>" . $pg_cnt . "</a>\n";
            }
        }
    }
    return "<div class='pagenav'>\n" . $res . "</div>\n";
}
 if (check_admin_pass(isset($_POST['admin_password']) ? stripinput($_POST['admin_password']) : "")) {
     if (isset($_POST['page_id']) && isnum($_POST['page_id'])) {
         $result = dbquery("UPDATE " . DB_CUSTOM_PAGES . " SET page_title='{$page_title}', page_access='{$page_access}', page_content='{$page_content}', page_keywords='{$page_keywords}', page_allow_comments='{$comments}', page_allow_ratings='{$ratings}' WHERE page_id='" . $_POST['page_id'] . "'");
         if ($settings['enable_tags']) {
             update_tags($_POST['page_id'], "C", $tag_name);
         }
         // Pimped: tag
         log_admin_action("admin-1", "admin_custompage_edited", "", "", $page_title . " (ID: " . $_POST['page_id'] . ")");
     } else {
         $result = dbquery("INSERT INTO " . DB_CUSTOM_PAGES . " (page_title, page_access, page_content, page_keywords, page_allow_comments, page_allow_ratings) VALUES ('{$page_title}', '{$page_access}', '{$page_content}', '{$page_keywords}', '{$comments}', '{$ratings}')");
         $page_id = mysql_insert_id();
         log_admin_action("admin-1", "admin_custompage_added", "", "", $page_title . " (ID: " . $page_id . ")");
         if (isset($_POST['add_link'])) {
             $data = dbarray(dbquery("SELECT link_order FROM " . DB_SITE_LINKS . " ORDER BY link_order DESC LIMIT 1"));
             $link_order = $data['link_order'] + 1;
             $result = dbquery("INSERT INTO " . DB_SITE_LINKS . " (link_name, link_url, link_seo_url,link_visibility, link_position, link_window, link_order) VALUES ('{$page_title}', 'viewpage.php?page_id={$page_id}', 'page-" . $page_id . "-" . clean_subject_urlrewrite($page_title) . ".html', '{$page_access}', '1', '0', '{$link_order}')");
             // Pimped SEO Url added
             if ($settings['enable_tags']) {
                 $id = mysql_insert_id();
                 // Pimped: tag
                 insert_tags($id, "C", $tag_name);
                 // Pimped: tag
             }
         }
     }
     set_admin_pass(isset($_POST['admin_password']) ? stripinput($_POST['admin_password']) : "");
     if (isset($_POST['page_id']) && isnum($_POST['page_id'])) {
         redirect(FUSION_SELF . $aidlink . "&status=su&pid=" . $_POST['page_id'], true);
     } else {
         redirect(FUSION_SELF . $aidlink . "&status=sn&pid=" . $page_id, true);
     }