if(permission("products","read")==FALSE){
header("Location: ".$GLOBALS['rootRel']."admin/401.php");
exit;
}
$productsPerPage = 25;
// grishick advanced_file_manager mod START -->
$add_file_mgr_config = fetchDbConfig("advanced_file_manager");
$rootFileFolder = $GLOBALS['rootDir']."/files/uploads";
$fileFolder = "../../files/uploads";
if($ccAdminData[0]['isSuper']==0) {
$rootFileFolder.="/aff".$ccAdminData[0]['adminId'];
$fileFolder.="/aff".$ccAdminData[0]['adminId'];
if(!is_dir($rootFileFolder)) {
$old = umask(0);
mkdir($rootFileFolder, 0777);
umask($old);
}
}
// grishick advanced_file_manager mod END -->
if(isset($_GET['action']) && $_GET['action']=="gbase"){
$db = new db();
$query = "SELECT * FROM ".$glob['dbprefix']."CubeCart_inventory INNER JOIN ".$glob['dbprefix']."CubeCart_category on ".$glob['dbprefix']."CubeCart_inventory.cat_id = ".$glob['dbprefix']."CubeCart_category.cat_id ".$whereClause." ORDER BY name ASC";
$results = $db->select($query);
if($results==TRUE) {
$googleBaseContent = "product_url\tname\tdescription\timage_url\tprice\r\n";
for($i=0; $i<count($results); $i++){
$salePrice = salePrice($results[$i]['price'], $results[$i]['sale_price']);
if($salePrice > 0){
$price = $salePrice;
} else {
$price = $results[$i]['price'];
}
$name = str_replace(array(" ","\t","\r","\n","\0","\x0B","
"),"",strip_tags($results[$i]['name']));
$name = str_replace(" ","",$name);
$desc = str_replace(array(" ","\t","\r","\n","\0","\x0B","
"),"",strip_tags($results[$i]['description']));
$desc = str_replace(" ","",$desc);
// SEO friendly mod
if($config['sef'] == 0) {
$googleBaseContent .= $glob['storeURL']."/index.php?act=viewProd&productId=".$results[$i]['productId']."\t".$name."\t".$desc;
} else {
include_once("../../includes/sef_urls.inc.php");
$googleBaseContent .= $glob['storeURL']. "/" . sef_get_base_url(). generateProductUrl($results[$i]['productId'])."\t".$name."\t".$desc;
}
// SEO friendly mod
if($results[$i]['image']){
$googleBaseContent .= "\t".$glob['storeURL']."/images/uploads/".$results[$i]['image'];
} else {
$googleBaseContent .= "\t".$glob['storeURL']."/skins/".$config['skinDir']."/styleImages/nophoto.gif";
}
$googleBaseContent .= "\t".$price."\r\n";
}
$filename = "GoogleBaseFeed_";
$contentLength = strlen($googleBaseContent);
$content = $googleBaseContent;
$filename .= date("dMy").".txt";
header('Pragma: private');
header('Cache-control: private, must-revalidate');
header("Content-Disposition: attachment; filename=".$filename);
header("Content-type: text/plain");
header("Content-type: application/octet-stream");
header("Content-length: ".$contentLength);
header("Content-Transfer-Encoding: binary");
echo $content;
exit;
}
} elseif(isset($_GET['delete']) && $_GET["delete"]>0){
// delete product
$where = "productId=".$db->mySQLSafe($_GET["delete"]);
$delete = $db->delete($glob['dbprefix']."CubeCart_inventory", $where);
// delete coresponding product reviews
$del_rev = $_GET["delete"] ;
$delete2 = "DELETE FROM ".($glob['dbprefix']."cubecart_store_comments WHERE product_id=$del_rev");
$del= mysql_query($delete2);
// set categories -1
$cats = $db->select("SELECT cat_id FROM ".$glob['dbprefix']."CubeCart_cats_idx WHERE productId=".$db->mySQLSafe($_GET["delete"]));
if($cats==TRUE){
for($i=0;$i<count($cats);$i++){
$db->categoryNos($cats[$i]['cat_id'], "-");
}
}
// delete category index
$where = "productId=".$db->mySQLSafe($_GET["delete"]);
$deleteIdx = $db->delete($glob['dbprefix']."CubeCart_cats_idx", $where);
unset($record);
// delete product options
$record['product'] = $db->mySQLSafe($_GET["delete"]);
$where = "product=".$db->mySQLSafe($_GET["delete"]);
$deleteOps = $db->delete($glob['dbprefix']."CubeCart_options_bot", $where);
unset($record);
if($delete == TRUE){
$msg = "<p class='infoText'>".$lang['admin']['products']['delete_success']."</p>";
} else {
$msg = "<p class='warnText'>".$lang['admin']['products']['delete_fail']."</p>";
}
} elseif(isset($_POST['productId'])) {
// generate product code
if(empty($_POST['productCode'])){
$chars = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N",
"O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3",
"4","5","6","7","8","9","0");
$max_chars = count($chars) - 1;
srand((double)microtime()*1000000);
for($i = 0; $i < 5; $i++){
$randChars = ($i == 0) ? $chars[rand(0, $max_chars)] : $randnum . $chars[rand(0, $max_chars)];
}
$record["productCode"] = $db->mySQLSafe(strtoupper(substr($_POST['name'],0,3)).$randChars.$_POST['cat_id']);
} else {
$record["productCode"] = $db->mySQLSafe($_POST['productCode']);
}
$record["name"] = $db->mySQLSafe($_POST['name']);
$record["cat_id"] = $db->mySQLSafe($_POST['cat_id']);
$record["description"] = $db->mySQLSafe($_POST['FCKeditor']);
$record["image"] = $db->mySQLSafe($_POST['imageName']);
$record["price"] = $db->mySQLSafe($_POST['price']);
$record["sale_price"] = $db->mySQLSafe($_POST['sale_price']);
$record["stock_level"] = $db->mySQLSafe($_POST['stock_level']);
$record["useStockLevel"] = $db->mySQLSafe($_POST['useStockLevel']);
$record["digital"] = $db->mySQLSafe($_POST['digital']);
// grishick advanced_file_manager mod START -->
if($add_file_mgr_config['status']==1) {
$record["digitalDir"] = $db->mySQLSafe($rootFileFolder.$_POST['digitalDir']);
} else {
// grishick advanced_file_manager mod END -->
$record["digitalDir"] = $db->mySQLSafe($_POST['digitalDir']);
// grishick advanced_file_manager mod START -->
}
// grishick advanced_file_manager mod END -->
$record["prodWeight"] = $db->mySQLSafe($_POST['prodWeight']);
$record["taxType"] = $db->mySQLSafe($_POST['taxType']);
$record["showFavorites"] = $db->mySQLSafe($_POST['showFavorites']);
$record["showFeatured"] = $db->mySQLSafe($_POST['showFeatured']);
/* <rf> search engine friendly url mod */
if($config['seftags']) {
$record["prod_metatitle"] = $db->mySQLSafe($_POST['prod_metatitle']);
$record["prod_metadesc"] = $db->mySQLSafe($_POST['prod_metadesc']);
$record["prod_metakeywords"] = $db->mySQLSafe($_POST['prod_metakeywords']);
if($config['sefcustomurl'] == 1) $record["prod_sefurl"] = $db->mySQLSafe($_POST['prod_sefurl']);
}
/* <rf> end mod */
// if image is a JPG check thumbnail doesn't exist and if not make one
$imageFormat = strtoupper(ereg_replace(".*\.(.*)$","\\1",$_POST['imageName']));
if($imageFormat == "JPG" || $imageFormat == "JPEG" || $imageFormat == "PNG" || ($imageFormat == "GIF" && $config['gdGifSupport']==1)){
if(file_exists($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName'])){
@chmod($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName'], 0775);
unlink($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName']);
}
$thumb=new thumbnail($GLOBALS['rootDir']."/images/uploads/".$_POST['imageName']);
$thumb->size_auto($config['gdthumbSize']);
$thumb->jpeg_quality($config['gdquality']);
$thumb->save($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName']);
}
if(isset($_POST['productId']) && $_POST['productId']>0) {
$where = "productId=".$db->mySQLSafe($_POST['productId']);
$update = $db->update($glob['dbprefix']."CubeCart_inventory", $record, $where);
unset($record, $where);
// update category count
if($_POST['oldCatId']!==$_POST['cat_id']){
// set old category -1 IF IT WAS IN THERE BEFORE
$numOldCat = $db->numrows("SELECT * FROM ".$glob['dbprefix']."CubeCart_cats_idx WHERE cat_id = ".$db->mySQLSafe($_POST['oldCatId'])." AND productId = ".$db->mySQLSafe($_POST['productId']));
if($numOldCat>0){
$db->categoryNos($_POST['oldCatId'], "-");
}
// set new category +1 IF IT WAS NOT IN THERE BEFORE
$numNewCat = $db->numrows("SELECT * FROM ".$glob['dbprefix']."CubeCart_cats_idx WHERE cat_id = ".$db->mySQLSafe($_POST['cat_id'])." AND productId = ".$db->mySQLSafe($_POST['productId']));
if($numNewCat == 0) {
$db->categoryNos($_POST['cat_id'], "+");
}
// delete old idx
$where = "productId = ".$db->mySQLSafe($_POST['productId'])." AND cat_id = ".$db->mySQLSafe($_POST['oldCatId']);
$deleteIdx = $db->delete($glob['dbprefix']."CubeCart_cats_idx", $where);
unset($record);
// delete new index if it was added as an extra before
$where = "productId = ".$db->mySQLSafe($_POST['productId'])." AND cat_id = ".$db->mySQLSafe($_POST['cat_id']);
$deleteIdx = $db->delete($glob['dbprefix']."CubeCart_cats_idx", $where);
unset($record);
// add new idx
$record['productId'] = $db->mySQLSafe($_POST['productId']);
$record['cat_id'] = $db->mySQLSafe($_POST['cat_id']);
$insertIdx = $db->insert($glob['dbprefix']."CubeCart_cats_idx", $record);
unset($record);
}
if($update == TRUE){
$msg = "<p class='infoText'>'".$_POST['name']."' ".$lang['admin']['products']['update_successful']."</p>";
} else {
$msg = "<p class='warnText'>".$lang['admin']['products']['update_fail']."</p>";
}
// start mod: Text Input Fields for Products, by Estelle
$text_input_mod = fetchDbConfig("Text_Input_Mod");
if ($text_input_mod && $text_input_mod['status']) {
include("../includes/estelles_mod_store/text_input_mod.admin1.inc.php");
}
// end mod: Text Input Fields for Products, by Estelle