<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2007                                            */
/* http://www.php-maximus.org                                           */
/* dev@php-maximus.org                                                  */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
/* Portage Coppermine Photo Gallery                                     */
/************************************************************************/
if ( !defined("MAXIMUS") &&  !$cpg_block && !defined('INSTALL_PHP')) {
    die ("You can't access this file directly...");
}
//define('SILLY_SAFE_MODE', 1);

$CPG_VERSION = '1.4.0';
if (!$cpg_block) require_once("mainfile.php");
if (!defined('IN_COPPERMINE')) define('IN_COPPERMINE', true);

if (!isset($name)) $name = secure( $GLOBALS['name'], 'strip', 1 ); // postnuke

if (!isset($cpg_dir)) $cpg_dir = $name;
$CPG_M_DIR = "modules/" . $cpg_dir;
$CPG_URL = "modules.php?name=" . $cpg_dir;
$CPG_M_URL = $CPG_URL;
$CPG_PROFILE_URL = "modules.php?name=Forums&amp;file=profile&amp;mode=viewprofile&amp;u=";

global $CONFIG, $CURRENT_ALBUM_DATA, $CPG_URL, $cookie;
// language variables not declared global else where
global $lang_user_admin_menu, $lang_gallery_admin_menu, $lang_cat_list,
       $lang_get_pic_data,    $lang_pagetitle_php,      $lang_charset,
       $lang_text_dir,        $lang_byte_units,         $lang_day_of_week,
       $lang_month,           $lang_yes,                $lang_no,
       $lang_back,            $lang_continue,           $lang_info,
       $lang_error,           $album_date_fmt,          $lastcom_date_fmt,
       $lastup_date_fmt,      $lasthit_date_fmt,        $comment_date_fmt,
       $lang_picinfo,         $lang_album_admin_menu;
global $template_tab_display, $template_user_list_info_box, $template_album_admin_menu; // index.php
global $template_img_navbar,  $template_display_picture,    $template_image_rating,
       $template_image_comments, $template_add_your_comment; // displayimage.php
global $template_cpg_die, $template_msg_box; // functions.inc.php
global $template_ecard;                      // displayecard.php
global $template_edit_one_pic;               // editDesc.inc.php
global $field_user_id, $field_user_pass, $field_user_name, $field_user_email;
global $first_install_M_DIR,$CPG_PROFILE_URL,$meta_link, $admin_file;

    if (!defined('LOGOUT_URL')) {
        define('LOGOUT_URL', "modules.php?name=Your_Account&amp;op=logout");
        define('LOGIN_URL', "modules.php?name=Your_Account"); //&redirect=$name
        define('NEWUSER_URL', "modules.php?name=Your_Account&amp;op=new_user");
        define('ADDUSER_URL', "".$admin_file.".php?op=addUser");
        define('USERPROF_URL', "modules.php?name=Your_Account&amp;op=edituser");

    $module_name = $name;
    $field_user_regdate = "user_regdate";
    $field_user_avatar  = "user_avatar";
        $field_user_id    = "user_id";
        $field_user_name  = "username";
        $field_user_pass  = "user_password";
        $field_user_email = "user_email";

}

if (!defined('INSTALL_PHP')) {
    // load required settings for this install
  //  $result = $db->sql_fetchrow($db->sql_query("SELECT `prefix`, `dirname` FROM `cpg_installs` WHERE `dirname`='$cpg_dir'"));
  //  if (!$result || $result[1] != $cpg_dir) {
    //    $error = "The Coppermine module \"$cpg_dir\" isn't installed/upgraded yet. <br>Go to ";
     //   if (defined('IN_POSTNUKE')) $error .= "modules.php?op=modload&name=$cpg_dir&file=install to proceed.";
     //   else $error .= "modules.php?name=$cpg_dir&file=install to proceed.";
   //     die ($error);
  //  }
  //  $cpg_prefix = $result[0];

// $first_install_M_DIR gets the first installs module directory is used for language detection
// can be used for other file that are not required to be different between installs
//$result = $db->sql_fetchrow($db->sql_query("SELECT `dirname` FROM `cpg_installs` WHERE `cpg_id`='1'"));
//$first_install_M_DIR = "modules/" .$result[0];

    require($CPG_M_DIR . '/include/init.inc.php');

    if (!defined('NO_HEADER') && !defined('IN_POSTNUKE')) {
        // Set nice page title
        $pagetitle = "> ".$CONFIG['gallery_name'];
        $sql = "SELECT `value` FROM `".TABLE_CPG_CONFIG."` WHERE `name`='nice_titles'";
        $value = $db->sql_fetchrow($db->sql_query($sql));
        if ($value[0]) {
            $breadcrumb = array();
            if (is_numeric($album) && $album > 0) {
		$album = secure( $album, 'num', 1, 'sec' );
                $result = $GLOBALS['db']->sql_query("SELECT aid AS id, title, category AS parent FROM `".TABLE_CPG_ALBUMS."` WHERE `aid` = ".$album);
                if ($GLOBALS['db']->sql_numrows($result) > 0) {
                    $breadcrumb[] = $GLOBALS['db']->sql_fetchrow($result);
                    $GLOBALS['db']->sql_free($result);
                }
            }
            else if (is_numeric($cat) && $cat > 0) {
                if ($cat > FIRST_USER_CAT) {
                    $result = $GLOBALS['db']->sql_query("SELECT $field_user_name AS title FROM `".TABLE_USERS."` WHERE $field_user_id = " . ($cat - FIRST_USER_CAT));
                    if ($GLOBALS['db']->sql_numrows($result) != 0) {
                        $row = $GLOBALS['db']->sql_fetchrow($result);
                        $row['id'] = $cat;
                        $row['parent'] = 1;
                        $breadcrumb[] = $row;
                        $GLOBALS['db']->sql_free($result);
                    }
                }
                else {
		    $cat = secure( $cat, 'num', 1, 'sec' );
                    $result = $GLOBALS['db']->sql_query("SELECT cid as id, parent, namee AS title FROM `".TABLE_CPG_CATEGORIES."` WHERE `cid`='$cat'");
                    if ($GLOBALS['db']->sql_numrows($result) > 0) {
                        $breadcrumb[] = $GLOBALS['db']->sql_fetchrow($result);
                        $GLOBALS['db']->sql_free($result);
                    }
                }
            }
            get_breadcrumb($breadcrumb);
            foreach($breadcrumb as $crumb) {
                $pagetitle .= " > ".$crumb['title'];
            }
            if (!is_numeric($album)) switch ($album) {
                case 'lastup':
                case 'lastcom':
                case 'topn':
                case 'toprated':
                case 'search':
                case 'random':
                    $pagetitle .= " > ".$lang_meta_album_names[$album];
                    break;
            }else {
            //sorted by code
            }
            if ($pagetitle == "") $pagetitle = "> ".$CONFIG['gallery_name'];
        }
        else $pagetitle = "> ".$CONFIG['gallery_name'];
    }
}
