";
//show product's rating
if ($a[8] > 0)
{
if ($brief)
$out .= "
";
else
$out .= "
";
$out .= " ";
for ($i=0; $i";
for ( ; $i < 5; $i++) $out .= "";
if (!$brief) $out .= " ($a[8] ".VOTES_FOR_ITEM_STRING.")";
$out .= "
";
if ($brief)
$out .= "
";
}
$out .= "
";
$q = db_query("SELECT count(*) FROM ".DISCUSSIONS_TABLE." WHERE productID=$product_id") or die (db_error());
$k = db_fetch_row($q); $k = $k[0];
if (!$brief) $out .= "".DISCUSS_ITEM_LINK." ($k ".POSTS_FOR_ITEM_STRING.")
";
$out .= "
";
//add 2 cart link in case product is in stock
if ($a[6] > 0) $out .= "";
else $out .= " ";
$out .= "
";
$q1 = db_query("select optionID, name from ".PRODUCT_OPTIONS_TABLE."") or die (db_error());
while ($row = db_fetch_row($q1))
if ($row[1]!="")
{
$q = db_query("select option_value from ".PRODUCT_OPTIONS_VALUES_TABLE." where productID=$product_id AND optionID=$row[0]") or die (db_error());
$val = db_fetch_row($q);
if ($val && $val[0]!="")
{
$out .= "$row[1]: $val[0] ";
}
}
$out .= "
";
};
$out .= "
";
//now show description (brief or else)
$out .= "
";
//related products
if (!$brief) {
$q = db_query("SELECT count(*) FROM ".RELATED_PRODUCTS_TABLE." WHERE Owner=$product_id") or die (db_error());
$cnt = db_fetch_row($q);
if ($cnt[0] > 0)
{
$q = db_query("SELECT productID FROM ".RELATED_PRODUCTS_TABLE." WHERE Owner=$product_id") or die (db_error());
// show related products in table
$out .= "
\n
\n
".STRING_RELATED_ITEMS.": ";
$out .= "
";
while ($row = db_fetch_row($q))
{
$p = db_query("SELECT productID, name, Price FROM ".PRODUCTS_TABLE." WHERE productID=$row[0] AND Price>0") or die (db_error());
if ($r = db_fetch_row($p))
{
$out .= "
\n";
} //showSubCategories
function categoryIndexInArray(&$list, $id)
{
//search for index of category with categoryID=$id at array $list
$j = 0;
while ($j\n";
$out .= "\n";
}
else //make a link
{
$out .= "\n";
}
}
//process subcategories
if ($level+1";
$out .= str_replace("<","<",$list[$i][1])."\n"; //w -- parent of current category
$out .= "\n";
//show products
showproducts($list[$i][0], $level, &$out);
//process all subcategories
pricessCategories(&$list, $list[$i][0],$level+1,&$out);
}
} //pricessCategories
function showproducts($cid, $level, &$out) //show products of selected category in the pricelist
{
$q = db_query("SELECT count(*) FROM ".PRODUCTS_TABLE." WHERE categoryID=$cid") or die (db_error());
$cnt = db_fetch_row($q);
if ($cnt[0] > 0) $out .= "";
$q = db_query("SELECT productID, name, Price FROM ".PRODUCTS_TABLE." WHERE categoryID=$cid AND Price>0") or die (db_error());
while ($row = db_fetch_row($q))
{
$out .= "
";
}
} //showproducts
// -------------------------INITIALIZATION-----------------------------//
session_start();
//select new language?
if (isset($new_language))
{
$current_language = $new_language;
session_register("current_language");
}
include("cfg/settings.inc.php");
include("functions.php");
include("language_list.php");
if (!isset($current_language) ||
$current_language<0 || $current_language>count($lang_list))
$current_language = 0; //set default language
if (isset($lang_list[$current_language]) && file_exists($lang_list[$current_language]->filename))
include($lang_list[$current_language]->filename); //include current language file
else
{
die("ERROR: Couldn't find language file!
Click here to use default language");
}
//connect to the database
db_connect(DB_HOST,DB_USER,DB_PASS) or die (db_error());
db_select_db(DB_NAME) or die (db_error());
//$output is the main output buffer.
//include template file (it is set in the language file)
$output = implode("",file($lang_list[$current_language]->template));
//authorized access check
include("checklogin.php");
//currencies file
include("cfg/currency.inc.php");
//# of selected currency
if (!isset($current_currency)) $current_currency = 0;
//load all categories to array $cats to avoid multiple queries
$cats = array();
$i=0;
$q = db_query("SELECT categoryID, name, parent, products_count, description, picture FROM ".CATEGORIES_TABLE." where categoryID<>0 ORDER BY name") or die (db_error());
while ($row = db_fetch_row($q)) $cats[$i++] = $row;
if (!isset($categoryID)) $categoryID = 0;
if (!isset($vote_completed)) $vote_completed = array();
if (!isset($offset)) $offset=0;
//checking for proper $offset init
if ($offset<0 || $offset%$products_count) $offset=0;
// -----------------------------------------------------------------//
if (isset($logout)) //user logout
{
unset($log);
session_unregister("log");
session_unregister("pass");
header("Location: index.php");
}
else
if (isset($enter) && !isset($log)) //user login
{
$q = db_query("SELECT cust_password FROM ".CUSTOMERS_TABLE." WHERE Login='$user_login'") or die (db_error());
$row = db_fetch_row($q);
//serching for user in the database
if (($row) && (!strcmp(trim($row[0]),stripslashes($user_pw))))
{
//yes. start new session
$log = $user_login;
$pass = stripslashes($user_pw);
session_register("log"); //$log -- authorized user login
session_register("pass");
moveCartFromSession2DB();
//update prefered currency
db_query("UPDATE ".CUSTOMERS_TABLE." SET default_currency=$current_currency WHERE Login='$log'") or die (db_error());
//is it admin?
if (!isset($order))
if (!strcmp($log,ADMIN_LOGIN))
header("Location: admin.php");
else
{
$z = "";
if (isset($productID)) $z="?productID=$productID";
else
if (isset($categoryID)) $z="?categoryID=$categoryID";
header("Location: index.php$z");
}
}
else //login error
$wrongLoginOrPw = 1;
}
if (isset($subscribe) && !strcmp($subscribe,"true") && isset($email)) //subscribe for the news
{
db_set_identity(MAILING_LIST_TABLE);
db_query("INSERT INTO ".MAILING_LIST_TABLE." (Email) VALUES ('$email')") or die (db_error());
$z = "";
if (isset($productID)) $z="&productID=$productID";
else
if (isset($categoryID)) $z="&categoryID=$categoryID";
header("Location: index.php?subscribe=done$z");
}
if (isset($killuser) && isset($log) && strcmp($log, ADMIN_LOGIN)) //terminate user account
{
db_query("DELETE FROM ".CUSTOMERS_TABLE." WHERE Login='$log'") or die (db_error());
db_query("DELETE FROM ".SHOPPING_CARTS_TABLE." WHERE customer_login='$log'") or die (db_error()); //clear his/her cart
unset($log);
unset($pass);
session_unregister("log");
session_unregister("pass");
session_unregister("order_step");
$order_step=0;
header("Location: index.php?kill_successful=1");
}
if (isset($vote)) //vote for product
{
if (!isset($vote_completed[$vote]) && isset($mark) && $mark)
$q = db_query("UPDATE ".PRODUCTS_TABLE." SET customers_rating=(customers_rating*customer_votes+$mark)/(customer_votes+1), customer_votes=customer_votes+1 WHERE productID=".$vote) or die (db_error());
$productID = $vote;
$vote_completed[$vote] = 1;
session_register("vote_completed");
}
if (isset($productID)) //to rollout categories navigation table
{
$q = db_query("SELECT categoryID FROM ".PRODUCTS_TABLE." WHERE productID=$productID") or die (db_error());
$r = db_fetch_row($q);
if ($r) $categoryID = $r[0];
}
if (isset($searchstring)) //make a simple search
{
$products_search = array();
$cats_search = array();
$g_search_count = 0;
//explode string to a set separate of words
$searchstring = trim(str_replace("'","",stripslashes($searchstring)));
$search = explode(" ",$searchstring);
$result=array();
$r = array();
$i = 0;
$k = 0;
if ($searchstring)
{
//searching for categories
$s = "SELECT categoryID, name FROM ".CATEGORIES_TABLE." WHERE categoryID<>0 and name LIKE '%".$search[0]."%' ";
for ($i=1; $i$g_search_count) $offset = 0;
$q = db_query($s_search."ORDER BY customers_rating DESC") or die (db_error());
$i = 0;
while ($row = db_fetch_row($q))
{
if ($i >= $offset && $i < $offset+$products_count)
$products_search[] = $row;
$i++;
}
}
}
if (isset($change_c) && isset($change_currency)) //change currency type
{
$current_currency = $change_currency;
session_register("current_currency");
//make changes in the database if user is authorized
if (isset($log))
db_query("UPDATE ".CUSTOMERS_TABLE." SET default_currency=$change_currency WHERE Login='$log'") or die (db_error());
header("Location: index.php");
}
if (isset($add_topic) && isset($productID)) // add post to the product discussion
{
db_set_identity(DISCUSSIONS_TABLE);
db_query("INSERT INTO ".DISCUSSIONS_TABLE." (productID, Author, Body, add_time, Topic) VALUES ($productID, '$nick','$body','".get_current_time()."','$topic')") or die (db_error());
header("Location: index.php?productID=$productID&discuss=yes");
}
if (isset($remove_topic) && isset($productID) && isset($log) && !strcmp($log, ADMIN_LOGIN)) // delete topic in the discussion
{
db_query("DELETE FROM ".DISCUSSIONS_TABLE." WHERE DID=$remove_topic") or die (db_error());
header("Location: index.php?productID=$productID&discuss=yes");
}
// ---------------------- TEMPLATE PARSER --------------------//
// {TITLE} //
$r = array(); $r[0] = "";
if (isset($categoryID) && !isset($productID) && $categoryID>0)
{
$q = db_query("SELECT name FROM ".CATEGORIES_TABLE." WHERE categoryID<>0 and categoryID=$categoryID") or die (db_error());
$r = db_fetch_row($q); $out = str_replace("\"","'",$r[0]." - ".$shopname);
$output = str_replace("{TITLE}", $out, $output);
}
else if (isset($productID) && $productID>0)
{
$q = db_query("SELECT name FROM ".PRODUCTS_TABLE." WHERE productID=$productID") or die (db_error());
$r = db_fetch_row($q); $out = str_replace("\"","'",$r[0]." - ".$shopname);
$output = str_replace("{TITLE}", $out, $output);
}
else $output = str_replace("{TITLE}", "$shopname", $output);
// {META} //
$r = array(); $r[0] = "";
if (isset($categoryID) && !isset($productID) && $categoryID>0)
{
$q = db_query("SELECT name, description FROM ".CATEGORIES_TABLE." WHERE categoryID<>0 and categoryID=$categoryID") or die (db_error());
$r = db_fetch_row($q); $out = str_replace("\"","'",$r[0].", ".$r[1]);
$output = str_replace("{META}", $out, $output);
}
else if (isset($productID) && $productID>0)
{
$q = db_query("SELECT name, brief_description FROM ".PRODUCTS_TABLE." WHERE productID=$productID") or die (db_error());
$r = db_fetch_row($q); $out = str_replace("\"","'",$r[0].", ".$r[1]);
$output = str_replace("{META}", $out, $output);
}
else $output = str_replace("{META}", "$shopname, powered by Shop-Script", $output);
// {REGISTER/HOME} //
if (isset($log)) //link to "My account" page
{
$out = "".MY_ACCOUNT_LINK."";
}
else //link to the registration
{
$out = "".REGISTER_LINK."";
}
$output = str_replace("{REGISTER/HOME}", $out, $output);
// {LANGUAGE} //
$out = "\n";
$output = str_replace("{LANGUAGE}", $out, $output);
// {CURRENCY} //
if (count($currency_name) > 1)
$out = "".CHANGE_CURRENCY_LINK."";
else $out = "";
$output = str_replace("{CURRENCY}", $out, $output);
// {AUTHORIZATION} //
if (!isset($log)) { //login form
// !!! NOTICE THAT YOU SHOULD PLACE SYMBOL \ BEFORE SYMBOL " !!! //
$out = "
".STRING_AUTHORIZATION."
";
}
else // logout link
{
// !!! NOTICE THAT YOU SHOULD PLACE SYMBOL \ BEFORE SYMBOL " !!! //
$out = "
";
}
$output = str_replace("{AUTHORIZATION}", $out, $output);
// {SEARCH} //
// search form
// !!! NOTICE THAT YOU SHOULD PLACE SYMBOL \ BEFORE SYMBOL " !!! //
$tmp = isset($searchstring) ? $searchstring : "";
$out = "
".ADVANCED_SEARCH_LINK."
";
$output = str_replace("{SEARCH}", $out, $output);
// {SHOPPING_CART} //
// !!! NOTICE THAT YOU SHOULD PLACE SYMBOL \ BEFORE SYMBOL " !!! //
$out = "
";
$output = str_replace("{SHOPPING_CART}", $out, $output);
// {CATEGORIES} //
$path = calculatePath(&$cats, $categoryID); //path from root to selected category
$out = processCategories(&$cats,0,$path,$categoryID,"");
$output = str_replace("{CATEGORIES}", $out, $output);
// {NEWS} //
$q = db_query("SELECT NID, add_date, Body, add_stamp FROM ".NEWS_TABLE." ORDER BY add_stamp DESC") or die (db_error());
$out = "";
$output = str_replace("{NEWS}", $out, $output);
// {VOTING} //
$out = "";
$out .= "
\n
\n
\n";
if (!isset($save_voting_results)) { //main voting form
$f = file("cfg/voting.txt");
$r = file("cfg/voting_results.txt");
$m = $r[0] ? $r[0] : 0;
$m = max($m, 1);
for ($i=0; $i";
$out .= "
\n";
$out .= "
$f[0]
\n
\n";
for ($i=1; $i\n";
if (isset($productID)) $out .= "";
if (isset($categoryID)) $out .= "";
if (isset($currency)) $out .= "";
if (isset($user_details)) $out .= "";
if (isset($aux_page)) $out .= "";
if (isset($show_price)) $out .= "";
if (isset($register)) $out .= "";
if (isset($adv_search)) $out .= "";
if (isset($searchstring)) $out .= "";
if (isset($order)) $out .= "";
if (isset($check_order)) $out .= "";
$out .= "\n";
}
else {
//vote and show results
$f = file("cfg/voting.txt");
//increase votes value
if (!($r = file("cfg/voting_results.txt")))
{
$r = array();
for ($i=0; $i 0)
{
$out .= "
\n";
//place categories into 2 columns
$q = db_query("SELECT categoryID FROM ".CATEGORIES_TABLE." WHERE categoryID<>0 and parent=0 ORDER BY name") or die (db_error());
$rr = array();
while ($row = db_fetch_row($q)) $rr[] = $row;
$k = count($rr);
if ($k%2 == 0) $tmp = 0;
else $tmp = 1;
$out .= "
\n";
for ($i=0; $i<$k; $i++) {
$tmp = $i%2;
if (!$tmp) $out .= "
\n";
//show special offers
$c = 2; //show 2 products in each row
$q = db_query("SELECT productID, name, picture, Price FROM ".PRODUCTS_TABLE." WHERE show_as_special_offer=1 AND picture<>'' AND enabled=1 AND Price>0 AND categoryID>0 AND in_stock>0 ORDER BY show_as_special_offer DESC, customers_rating DESC, name") or die (db_error());
$i = 0;
$out .= "
\n
";
while (($row = db_fetch_row($q)))
if (file_exists("products_pictures/$row[2]"))
{
if ($i % $c == 0 && $i != 0) $out .= "