<?php
// Set flag that this is a parent file
	defined('_FEXEC') or die();
  	$server_date = getServerDate(true);
	$current_date=getServerDate();  	  	
  	$suID=isset($HTTP_GET_VARS['pID'])?$HTTP_GET_VARS['pID']:$HTTP_POST_VARS['product_id'];
	$check_ID = (isset ($HTTP_GET_VARS['chk_ID']) ? $HTTP_GET_VARS['chk_ID'] : 0);
  	$subscription_id=$suID;
  	$sucPath=isset($HTTP_POST_VARS['cPath'])?$HTTP_POST_VARS['cPath']:'0';
  	$cID=isset($HTTP_GET_VARS['cID'])?$HTTP_GET_VARS['cID']:$HTTP_POST_VARS['cPath'];
  	$current_category_id = $sucPath;
  	$action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');
  	$current_subscription_category_id = tep_db_prepare_input($HTTP_POST_VARS['cPath']);  
	//echo $action;if($action=='edit') exit;
	//if($suID>0 && $action!=""){
	if($action!=""){
		$categories=array();	
		if($HTTP_GET_VARS['cID']>0){
		 $categories_query = tep_db_query("select c.parent_id,c.subscription_categories_id, cd.subscription_categories_name, c.subscription_categories_image, c.sort_order, c.date_added, c.last_modified from  ".TABLE_SUBSCRIPTION_CATEGORIES."  c,  ".TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION."  cd where c.subscription_categories_id = cd.subscription_categories_id and cd.language_id = '" . $languages_id . "' and c.subscription_categories_id='".(int)$cID."' order by c.sort_order, cd.subscription_categories_name");
		 if(tep_db_num_rows($categories_query)>0){
			$categories=tep_db_fetch_array($categories_query);
			$cInfo=new objectInfo($categories);
		 }
	    }
		$subscription_query = tep_db_query("select sd.subscription_id,sd.subscription_name, sd.subscription_description,s.subscription_costs,date_format(s.subscription_date_added,'%Y-%m-%d') as subscription_date_added, date_format(s.subscription_last_modified,'%Y-%m-%d') as subscription_last_modified,s.subscription_status,s.subscription_image from " . TABLE_SUBSCRIPTIONS . " s, " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " sd where s.subscription_id = '" . (int)$suID . "' and s.subscription_id = sd.subscription_id and sd.language_id = '" . (int)$languages_id . "'");		 
		if(tep_db_num_rows($subscription_query)>0){
			$product = tep_db_fetch_array($subscription_query);
			$pInfo = new objectInfo($product);
		} 
		if($action=='edit_category' && !$HTTP_GET_VARS['cID'] && $check_ID>0){
		$products_query = tep_db_query("select count(*) as total from ".TABLE_SUBSCRIPTIONS." p, ".TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES." p2c where p.subscription_id = p2c.subscription_id and p2c.subscription_categories_id = '" . $check_ID . "'");			 		
		$products=tep_db_fetch_array($products_query);							
		 if($products['total']<=0){
			echo 'new^';
			$action='edit_product';
		 }
	    }	  			
		$languages = tep_get_languages();			
	  	if($action=='file_upload'){				
	 	$sql_data_array=array();
		 if($HTTP_POST_VARS['action_type']=="new_category" || $HTTP_POST_VARS['action_type']=="edit_category"){
			 $categories = new upload('subscription_categories_image');
			 $categories->set_destination(DIR_FS_CATALOG_IMAGES);
			 if ($categories->parse() && $categories->save()) $categories_filename=$categories->filename;
			 if($HTTP_POST_VARS['action_type']=='new_category' && $categories_filename!=''){
					$sql_data_array=array('subscription_categories_image'=>$categories_filename,'date_added'=>$server_date,'parent_id'=>($HTTP_POST_VARS['main_category']=='Y')?0:$HTTP_POST_VARS['cPath']);
					tep_db_perform(TABLE_SUBSCRIPTION_CATEGORIES, $sql_data_array);
					$insert_id=tep_db_insert_id();
					echo $insert_id;
					for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
						$insert_sql_data = array(
							'subscription_categories_id' => $insert_id,
							'language_id' => $languages[$i]['id']);	
						tep_db_perform(TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION, $insert_sql_data);		
					}
			}else if($HTTP_POST_VARS['action_type']=='edit_category' && $categories_filename!='') tep_db_query("update " . TABLE_SUBSCRIPTION_CATEGORIES . " set subscription_categories_image = '" . $categories_filename . "' where subscription_categories_id = '" . tep_db_input($HTTP_POST_VARS['cPath']) . "'");			  			 				
		}else if($HTTP_POST_VARS['action_type']=="new" || $HTTP_POST_VARS['action_type']=="edit" ){
			 $subscription_image = new upload('subscription_image');
			 $subscription_image->set_destination(DIR_FS_CATALOG_IMAGES);
			 if ($subscription_image->parse() && $subscription_image->save())
			 if($HTTP_POST_VARS['action_type']=="new" && $subscription_image->filename!=''){
				    $sql_data_array=array('subscription_image'=>$subscription_image->filename,'subscription_date_added'=>$server_date);				    
				    tep_db_perform(TABLE_SUBSCRIPTIONS, $sql_data_array);
				    $products_id=tep_db_insert_id();
					echo $products_id;
					for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {				    						
		              $language_id=$languages[$i]['id'];	
		              $insert_sql_data = array('subscription_id' => $products_id,
		                                       'language_id' => $language_id);		
											   
		              tep_db_perform(TABLE_SUBSCRIPTIONS_DESCRIPTION, $insert_sql_data);            
					}
			}else if($HTTP_POST_VARS['action_type']=='edit' && $subscription_image->filename!='' )
				tep_db_query("update ".TABLE_SUBSCRIPTIONS." set subscription_image='".$subscription_image->filename."' where subscription_id='".(int)$suID."'");
		 }	    					
	  	}else if($action=='get_category_details'){
 			$product_categories=tep_db_query("select date_format(c.date_added,'%Y-%m-%d') as date_added,date_format(c.last_modified,'%Y-%m-%d') as last_modified,cd.subscription_categories_id,cd.subscription_categories_name,c.sort_order,c.subscription_categories_image from ".TABLE_SUBSCRIPTION_CATEGORIES."  c, ".TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION." cd where c.subscription_categories_id=cd.subscription_categories_id and cd.language_id='".(int)$languages_id."' and c.subscription_categories_id='".(int)$cID."'");
			if(tep_db_num_rows($product_categories)>0) $product=tep_db_fetch_array($product_categories);
 			echo get_category_details($product);
	    }else if($action=='edit_category'){
	  		echo '<table width="100%" border="0" cellspacing="1" cellpadding="1" class="openContent">'.(($check_ID==0 && !$HTTP_GET_VARS['cID'])?'<tr class="openContent_top"><td class="main" align="right"  colspan="'.(count($languages)+1).'"><input type="image" border="0"  src="images/template/img_savel.gif">&nbsp;<a style="cursor:pointer" onClick="do_close_new_category();"><img src="images/template/img_closel.gif" alt="close"></a>&nbsp;</td>':'').'</tr>';?>			
 	  	   <tr><td colspan="2" align="right"></td></tr>
 	  	   <?php if($cInfo->subscription_categories_id<=0) { ?> <tr>
 	  	   			<td colspan="2">
 	  	   				<table border="0" cellspacing="0" cellpadding="0" width="100%">
 	  	   					<tr>
 	  	   						<td width="150" class="main" nowrap="nowrap">&nbsp;&nbsp;<?php echo tep_draw_checkbox_field('main_category','Y').'&nbsp;'.TEXT_MAIN_CATEGORIES;?></td>	
			   				</tr>
 	  	   				</table>
 	  	   			</td>
 	  	   		</tr>
 	  	   <?php  } ?>
		  	<tr><td colspan="2">
		  		<table border="0" cellspacing="3" cellpadding="3" width="100%">
		  			<tr>
		  			<td>
		  				<table border="0" cellspacing="3" cellpadding="3" width="100%">
						   <?php $n=sizeof($languages);
				   			 for ($i=0; $i<$n; $i++) {
							?>
					          <tr>
					            <td class="main"><?php if ($i == 0) echo TEXT_EDIT_SUBSCRIPTION_CATEGORIES_NAME; ?></td>
					            <td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('categories_name[' . $languages[$i]['id'] . ']', (($subscription_categories_name[$languages[$i]['id']]) ? stripslashes($subscription_categories_name[$languages[$i]['id']]) : tep_get_subscription_category_name($cInfo->subscription_categories_id, $languages[$i]['id'])),'maxlength="32"'); ?></td>
					          </tr>
					        <?php } ?>
					      </table>  			        
			        <td>
           		 	<table border="0" cellspacing="3" cellpadding="3" width="100%"> 	
			           <?php  for ($i=0; $i<$n; $i++) { ?>
			          	  <tr>
			            	<td class="main"><?php if ($i == 0) echo TEXT_EDIT_SUBSCRIPTION_CATEGORIES_HEADING_TITLE; ?></td>
			            	<td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('categories_heading_title[' . $languages[$i]['id'] . ']', (($subscription_categories_name[$languages[$i]['id']]) ? stripslashes($subscription_categories_name[$languages[$i]['id']]) : tep_get_subscription_category_title($cInfo->subscription_categories_id, $languages[$i]['id'])),'maxlength="64"'); ?></td>
			          	  </tr>
			           <?php } ?>
           		   </table>
	       	   	  </td>	  
	       	   	  </tr>      		  	          
	        	</table>	        	
	       	   </td>
	        </tr>	          	           	            	 
          	  	<tr>
            		<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          	  	</tr>          	
          	 <tr>
          	 <td colspan="2">
          	 	<div style='width:100%;height:100%;overflow:auto;'>
           		<table border="0" cellspacing="3" cellpadding="3" width="100%">
           		  <tr>           		              		 	            		 	   
		          	<?php  for ($i=0; $i<$n; $i++) { ?> 	
		          	  <td>          	  
		          	  <table border="0" cellspacing="3" cellpadding="3" width="100%">
		          	   <tr>
		                <td class="main" valign="top" width="180"><?php if ($i == 0) echo TEXT_EDIT_SUBSCRIPTION_CATEGORIES_DESCRIPTION; ?></td>
		            	 <td>
		            		<table border="0" cellspacing="0" cellpadding="0">
				              <tr>
				                <td class="main" valign="top"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?>&nbsp;</td>
				                <td class="main"><?php echo tep_draw_textarea_field('subscription_categories_description[' . $languages[$i]['id'] . ']', 'soft', '70', '15', (($subscription_categories_description[$languages[$i]['id']]) ? stripslashes($subscription_categories_description[$languages[$i]['id']]) : tep_get_subscription_category_description($cInfo->subscription_categories_id, $languages[$i]['id']))); ?></td>
				              </tr>
		            		</table>
		            	  </td>
		          	    </tr>
		          	   </table>
		          	  </td>
				<?php } ?>				
			  </tr>   			  
			 </table>
			</div>
		   </td>
		 </tr>		           
		 <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
         </tr>          
		 <tr>
			  <td valign="top" width="100%">
				  <table border="0" cellspacing="0" cellpadding="0" width="100%">
					  <tr>
						<td class="main" valign="top" width="20%" align="right"><?php echo TEXT_EDIT_SUBSCRIPTION_CATEGORIES_IMAGE; ?></td>
						<td class="main" valign="top" align="left" width="30%"><?php echo tep_draw_separator('pixel_trans.gif','10','1') . tep_draw_file_field('subscription_categories_image') . '<br>' . tep_draw_separator('pixel_trans.gif', '10', '1') . '&nbsp;' . $cInfo->subscription_categories_image; ?></td>
						<td class="main" valign="top" width="10%" align="center"><?php echo tep_draw_separator('pixel_trans.gif','',''); ?></td>
						<td class="main" valign="top" width="40%" align="left"><?Php echo TEXT_CATEGORY_SORT_ORDER . tep_draw_separator('pixel_trans.gif','10','1') . tep_draw_input_field('subscripiton_categories_sortorder',$cInfo->sort_order,' onKeyPress="return keyRestrict(event)" size=3 maxlength="3"');?></td>
					  </tr>			
				  </table>
			  </td>
	   </tr>
	  <tr>
		<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
	  </tr>       	
	</table>   
<?php }else if($action=='update_category'){   		
			$categories_id = $cID;
			$current_category_id=(int)$HTTP_POST_VARS['cPath'];
			//$sort_order=$cInfo->sort_order;
			$sort_order=$HTTP_POST_VARS['subscripiton_categories_sortorder'];
			$sort_query=tep_db_query("select max(sort_order) as sort_order from ".TABLE_SUBSCRIPTION_CATEGORIES);
			if($HTTP_POST_VARS['subscripiton_categories_sortorder']<=0 && tep_db_num_rows($sort_query)>0){
				$sort=tep_db_fetch_array($sort_query);
				$sort_order = $sort['sort_order']+1;
			}
			if($HTTP_POST_VARS['action_type']=='new_category' && $HTTP_POST_VARS['main_category']=='Y') {
				echo 'new_main_category^';
				$current_category_id=0;
			}else echo $HTTP_POST_VARS['action_type'].'^';
			$sql_data_array = array('sort_order' => $sort_order);
			if (!$HTTP_GET_VARS['cID']) {
				$insert_sql_data = array(
					'parent_id' => $current_category_id,
					'date_added' => $server_date
				);
				$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
				tep_db_perform(TABLE_SUBSCRIPTION_CATEGORIES, $sql_data_array);
				$insert_id = tep_db_insert_id();												
			} elseif ($HTTP_GET_VARS['cID']>0) {
				$update_sql_data = array('last_modified' => $server_date);
				$sql_data_array = array_merge($sql_data_array, $update_sql_data);
				tep_db_perform(TABLE_SUBSCRIPTION_CATEGORIES, $sql_data_array, 'update', 'subscription_categories_id = \'' . $categories_id . '\'');							
			}  // top if closing bracket					
			for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
				$categories_name_array = str_replace("|||","&",$HTTP_POST_VARS['categories_name']);
				$categories_title_array = $HTTP_POST_VARS['categories_heading_title'];
				$categories_description_array = $HTTP_POST_VARS['subscription_categories_description'];							
				$language_id = $languages[$i]['id'];
				$sql_data_array = array('subscription_categories_name' => tep_db_prepare_input($categories_name_array[$language_id]),'subscription_categories_heading_title'=>tep_db_prepare_input($categories_title_array[$language_id]),'subscription_categories_description'=>tep_db_prepare_input($categories_description_array[$language_id]));				
				if (!$HTTP_GET_VARS['cID']) {
					$insert_sql_data = array(
						'subscription_categories_id' => $insert_id,
						'language_id' => $languages[$i]['id']
					);
					$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
					tep_db_perform(TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION, $sql_data_array);
				} elseif ($HTTP_GET_VARS['cID']>0) {
					$insert_id=$HTTP_GET_VARS['cID'];
					tep_db_perform(TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION, $sql_data_array, 'update', 'subscription_categories_id = \'' . $insert_id . '\' and language_id = \'' . $languages[$i]['id'] . '\'');					
				}
			}
			if($HTTP_POST_VARS['action_type']=='new_category') echo $insert_id.'{}'.$categories_name_array[$languages_id].'{}'.$current_category_id;
	 		else if($HTTP_POST_VARS['action_type']=='edit_category'){
				echo $categories_id.'{}'.$categories_name_array[$languages_id].'{}';								
 				echo get_category_details($categories);
			} 
	  tep_reset_seo_cache('subscriptions');	  
      }else if($action=='delete_category'){
			$contents='<table width="100%" class="openContent" border="0" cellspacing="5" cellpadding="5"><tr><td width="10" align="right">'.tep_image('images/template/img_trash.gif').'</td><td class="main" colspan="4"><b>' . TEXT_DELETE_SUBSCRIPTION_CATEGORY_INTRO . '</b></td></tr><tr>';
			$contents.='<tr><td></td><td class="main">' . $cInfo->subscription_categories_name . '</td></tr>';
			$category_childs = tep_childs_in_subscription_category_count($cInfo->subscription_categories_id);
			$category_products =tep_subscription_in_subscription_category_count($cInfo->subscription_categories_id);
			if ($category_childs > 0) $contents.='<tr><td></td><td class="main">' . sprintf(TEXT_DELETE_WARNING_CHILDS, $category_childs).'</td></tr>';
			if ($category_products > 0) $contents.='<tr><td></td><td class="main">'. sprintf(TEXT_DELETE_WARNING_SUBSCRIPTION, $category_products).'</td></tr>';
			$contents.='<tr><td colspan="2">'.tep_draw_separator('pixel_trans.gif', '1', '10').'</td></tr></table>';
			echo $contents;
	  }else if($action=='delete_category_confirm'){
	  	  if ($HTTP_GET_VARS['cID']) {
				$subscription_categories_id = tep_db_prepare_input($HTTP_GET_VARS['cID']);
				$subscription_categories = tep_get_subscription_category_tree($subscription_categories_id, '', '0', '', true);
				$subscription = array();
				$subscription_delete = array();
				for ($i=0, $n=sizeof($subscription); $i<$n; $i++) {
					$subscription_ids_query = tep_db_query("SELECT subscription_id from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_categories_id = '" . (int)$subscription_categories[$i]['id'] . "'");
					while ($events_ids = tep_db_fetch_array($events_ids_query)) 
						$events[$event_ids['subscription_id']]['subscription_categories'][] = $events_categories[$i]['id'];					
				}
				reset($subscription);
				while (list($key, $value) = each($subscription)) {
					$subscription_category_ids = '';
					for ($i=0, $n=sizeof($value['subscription_categories']); $i<$n; $i++)
						$subscription_category_ids .= "'" . (int)$value['subscription_categories'][$i] . "', ";
					$subscription_category_ids = substr($subscription_category_ids, 0, -2);
					$check_query = tep_db_query("SELECT count(*) as total from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_id = '" . (int)$key . "' and subscription_categories_id not in (" . $subscription_category_ids . ")");
					$check = tep_db_fetch_array($check_query);
					if ($check['total'] < '1') 
						$subscription_delete[$key] = $key;
				}
				// removing categories can be a lengthy process
				tep_set_time_limit(0);
				for ($i=0, $n=sizeof($subscription_categories); $i<$n; $i++) 
					tep_remove_subscription_category($subscription_categories[$i]['id']);				
				reset($subscription_delete);
				while (list($key) = each($subscription_delete)) 
					tep_remove_subscription($key);
			echo 'delete_category_success^'.$subscription_categories_id;		
		}	
	  tep_reset_seo_cache('subscriptions');
	  }else if($action=='move_category'){			
			$contents='<table width="100%"  border="0" cellspacing="5" cellpadding="5" class="openContent"><tr><td width="10" class="main">'.tep_image('images/template/img_move.gif').'</td><td class="main" colspan="4"><b>' . sprintf(TEXT_MOVE_SUBSCRIPTION_CATEGORIES_INTRO, $cInfo->subscription_categories_name) . '</b></td></tr><tr>';
			$contents.='<tr><td></td><td class="main" align="left">' . sprintf(TEXT_MOVE, $cInfo->subscription_categories_name) . '&nbsp;' . tep_draw_pull_down_menu('move_to_subscription_category_id', tep_get_subscription_category_tree('0', '',$cID), $current_category_id).'</td></tr>';
			$contents.='<tr><td colspan="2">'.tep_draw_separator('pixel_trans.gif', '1', '10').'</td></tr></table>';						
			echo $contents;
	 }else if($action=='move_category_confirm'){				
			if ($cID  && ($cID != $HTTP_POST_VARS['move_to_subscription_category_id'])){				
				$subscription_categories_id = $cID;
				$new_parent_id = tep_db_prepare_input($HTTP_POST_VARS['move_to_subscription_category_id']);											
				
				$path = explode('_', tep_get_generated_subscription_category_path_ids($new_parent_id));
				
				if (in_array($subscription_categories_id, $path)) {
					echo 'move_category_failure^'.$subscription_categories_id;
				} else {
					tep_db_query("update " . TABLE_SUBSCRIPTION_CATEGORIES . " set parent_id = '" . (int)$new_parent_id . "', last_modified ='". $server_date ."' where subscription_categories_id = '" . (int)$subscription_categories_id . "'");
					echo 'move_category_success^'.$new_parent_id;
				}
			}  // top if closing bracket	
	  }else if($action=='get_details'){  	  		  							
			echo_get_details();
	  }else if($action=='setflag' && $HTTP_GET_VARS['pID'])	  	 					
						tep_set_subscription_status($HTTP_GET_VARS['pID'], (int)$HTTP_GET_VARS['flag']);														  
	  else if($action=='delete_product'){
		 	$subscription_delete_string.="<table border='0' cellspacing='2' cellpadding='2' width='100%'><tr><td width='17' align='center'>".tep_image('images/icons/delete_blue.gif').'</td>';
		 	$subscription_delete_string.='<td width="500" align="left" class="inner_title">'.TEXT_INFO_HEADING_DELETE_SUBSCRIPTION . '</td></tr>';
		 	$subscription_delete_string.='<tr><td></td><td width="500" align="left" class="main">'.TEXT_DELETE_SUBSCRIPTION_INTRO. '</td></tr>';
		 	$subscription_delete_string.='<tr><td></td><td width="500" align="left" class="main"><b>'.$pInfo->subscription_name. '</b></td></tr>';				      
		 	$subscription_delete_string.='<tr><td></td><td width="500" align="left" class="main"><b>';
	        $product_categories = tep_generate_subscription_category_path($pInfo->subscription_id, 'subscription');
	        for ($i = 0, $n = sizeof($product_categories); $i < $n; $i++) {
	          $category_path = '';
	          for ($j = 0, $k = sizeof($product_categories[$i]); $j < $k; $j++) {
	            $category_path .= $product_categories[$i][$j]['text'] . '&nbsp;&gt;&nbsp;';
	          }
	          $category_path = substr($category_path, 0, -16);
	          $subscription_delete_string .= tep_draw_checkbox_field('subscription_categories[]', $product_categories[$i][sizeof($product_categories[$i])-1]['id'], true) . '&nbsp;' . $category_path . '<br>';
	        }
	        $subscription_delete_string = substr($subscription_delete_string, 0, -4);
	        $subscription_delete_string.='</b></td></tr>';
			$subscription_delete_string.='<tr><td colspan="2">'.tep_draw_separator('pixel_trans.gif',50,10).'</td></tr></table>';
	        echo $subscription_delete_string;  
		tep_reset_seo_cache('subscriptions');             
	 	}else if($action=='delete_confirm'){
		 	 if (isset($HTTP_POST_VARS['subscription_categories']) && is_array($HTTP_POST_VARS['subscription_categories'])) {
					$subscription_id = tep_db_prepare_input($HTTP_GET_VARS['pID']);
					$subscription_categories = $HTTP_POST_VARS['subscription_categories'];
					for ($i=0, $n=sizeof($subscription_categories); $i<$n; $i++) {
						tep_db_query("delete from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_id = '" . (int)$subscription_id . "' and subscription_categories_id = '" . (int)$subscription_categories[$i] . "'");
					}
					$subscription_categories_query = tep_db_query("SELECT count(*) as total from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_id = '" . (int)$subscription_id . "'");
					$subscription_categories = tep_db_fetch_array($subscription_categories_query);			
					if ($subscription_categories['total'] == '0'){
						tep_remove_subscription($subscription_id);
					}
				}
				echo 'delete_success^' . $HTTP_GET_VARS['cID'];
		tep_reset_seo_cache('subscriptions');
		}else if($action=='move_product'){			
			$move_to .="<table border='0' cellspacing='2' cellpadding='2' width='100%'><tr><td width='17' align='center'>".tep_image('images/template/img_move.gif').'</td>';
			$move_to .='<td width="500" align="left" class="inner_title">'.TEXT_INFO_HEADING_MOVE_PRODUCT . '</td></tr>';  
			$move_to .='<tr><td></td><td width="500" align="left" class="main">'. TEXT_INFO_CURRENT_CATEGORIES.'&nbsp;&nbsp;'.'<b>'.tep_output_generated_subscription_category_path($pInfo->subscription_id, 'subscription'). '</b></td></tr>';
			$move_to .='<tr><td></td><td width="500" align="left" class="main">'. sprintf(TEXT_MOVE_SUBSCRIPTION_INTRO, $pInfo->subscription_name). '</td></tr>'; 
			$move_to .= '<tr><td></td><td width="500" align="left" class="main">'. TEXT_MOVE_TO.tep_draw_separator('pixel_trans.gif',50,10) . tep_draw_pull_down_menu('move_to_category_id', tep_get_subscription_category_tree(), $current_category_id). '</td></tr>';
			$move_to .= '<tr><td colspan="2">'.tep_draw_separator('pixel_trans.gif',50,10).'</td></tr></table>';
			echo $move_to;
		}else if($action=='move_confirm'){			
			$subscription_id = tep_db_prepare_input($HTTP_GET_VARS['pID']);
			$new_parent_id = tep_db_prepare_input($HTTP_POST_VARS['move_to_category_id']);
				if ($new_parent_id!=0)
				{
					$duplicate_check_query = tep_db_query("SELECT count(*) as total from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_id = '" . (int)$subscription_id . "' and subscription_categories_id = '" . (int)$new_parent_id . "'");
					$duplicate_check = tep_db_fetch_array($duplicate_check_query);
					if ($duplicate_check['total'] < 1) tep_db_query("update " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " set subscription_categories_id = '" . (int)$new_parent_id . "' where subscription_id = '" . (int)$subscription_id . "' and subscription_categories_id = '" . (int)$cID . "'");
				}
				echo 'move_success^'.$new_parent_id;        		
		}else if($action=='copy_product'){	 		
	 		$copy_to .='<table  border="0" cellpadding="2" cellspacing="2" width="98%"><tr><td width="1%" align="center">'.tep_image('images/template/img_copy.gif').'</td>';
			$copy_to .= '<td width="40%" align="left" class="inner_title">'.TEXT_INFO_HEADING_COPY_PRODUCT . '</td><td></td></tr>'; 
			$copy_to .= '<tr><td width="5%" ></td><td width="40%" align="left" class="main">'.TEXT_INFO_CURRENT_CATEGORIES .'&nbsp;&nbsp;'.'<b>'.tep_output_generated_subscription_category_path($pInfo->subscription_id, 'subscription'). '</b></td><td></td></tr>';
			$copy_to .= '<tr><td width="5%"></td><td colspan="2" align="left" class="main">'.TEXT_INFO_COPY_TO_INTRO. '</td><td></td></tr>'; 
			$copy_to .= '<tr><td width="5%" ></td><td width="45%" align="left" class="main">'.TEXT_COPY_TO .tep_draw_separator('pixel_trans.gif',50,10) . tep_draw_pull_down_menu('categories_id', tep_get_subscription_category_tree(), $current_category_id).  '</td><td></td></tr>';	
			$copy_to .= '<tr><td width="5%"></td><td width="40%" align="left" class="main">'.TEXT_HOW_TO_COPY . tep_draw_separator('pixel_trans.gif',47,10) . tep_draw_radio_field('copy_as', 'link', true,'','onclick="javascript:show_duplicate(\'link\');"') . ' ' . TEXT_COPY_AS_LINK . '<br>'.tep_draw_separator('pixel_trans.gif','90','10') . tep_draw_radio_field('copy_as', 'duplicate','','','onclick="javascript:show_duplicate(\'dup\');"') . ' ' . TEXT_COPY_AS_DUPLICATE . '</td><td class="main" style="display:none" id="dub_prd"><br>' . TEXT_COPY_ATTRIBUTES . '&nbsp;' . tep_draw_radio_field('copy_attributes', 'copy_attributes_yes', true) . ' ' . TEXT_COPY_ATTRIBUTES_YES . '&nbsp;' . tep_draw_radio_field('copy_attributes', 'copy_attributes_no') . ' ' . TEXT_COPY_ATTRIBUTES_NO . '</td></tr>'; 
			$copy_to .= '<tr><td colspan="2">'.tep_draw_separator('pixel_trans.gif',50,10).'</td></tr></table>';
			echo $copy_to;
		}else if($action=='copy_confirm'){			
			$subscription_categories_id = $HTTP_POST_VARS['categories_id'];
			$error="";
			if ($HTTP_POST_VARS['copy_as'] == 'link') { 
				if ($subscription_categories_id != $current_subscription_category_id) { 
					$check_query = tep_db_query("SELECT count(*) as total from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_id = '" . (int)$suID . "' and subscription_categories_id = '" . (int)$subscription_categories_id . "'");
					$check = tep_db_fetch_array($check_query);
					if ($check['total'] < '1') tep_db_query("insert into " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " (subscription_id, subscription_categories_id) values ('" . (int)$suID . "', '" . (int)$subscription_categories_id . "')");						
				} else  $error=ERROR_CANNOT_LINK_TO_SAME_SUBSCRIPTION_CATEGORY;			
			} elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
					$subscription_query = tep_db_query("SELECT subscription_image, subscription_date_available, subscription_status, subscription_tax_class_id,subscription_costs,subscription_type,"
												. "subscription_group,subscription_conditions,subscription_pending_period,subscription_renewal_start,subscription_renewal_end,"
												. "subscription_packing_slip,subscription_free_trial,subscription_free_days,emarketing_on_renewal,wallet_payment,periodic_payment,"
												. "periodic_days,periodic_type,deliveries,deliveries_name,deliveries_perday,"
												. "subscription_start_date,subscription_finish_date,subscription_period,subscription_date_type,subscription_latest_start_date  "
												. " from " . TABLE_SUBSCRIPTIONS . " where subscription_id = '" . (int)$suID . "'");
					$subscription = tep_db_fetch_array($subscription_query);
					
					tep_db_query("insert into " . TABLE_SUBSCRIPTIONS . " (subscription_image, subscription_date_added,subscription_date_available, subscription_status, subscription_tax_class_id,subscription_costs,subscription_type,"
								. "subscription_group,subscription_conditions,subscription_pending_period,subscription_renewal_start,subscription_renewal_end,"
								. "subscription_packing_slip,subscription_free_trial,subscription_free_days,emarketing_on_renewal,wallet_payment,periodic_payment,periodic_days,periodic_type,deliveries,deliveries_name,deliveries_perday,"
								. "subscription_start_date,subscription_finish_date,subscription_period,subscription_date_type,subscription_latest_start_date "
								. " ) values ('" . tep_db_input($subscription['subscription_image']) . "',  now(), '" . tep_db_input($subscription['subscription_date_available']) . "', '" . tep_db_input($subscription['subscription_status'])
								. "', '" . tep_db_input($subscription['subscription_tax_class_id']) . "', '" . tep_db_input($subscription['subscription_costs'])
								. "', '" . tep_db_input($subscription['subscription_type']) . "', '" . tep_db_input($subscription['subscription_group'])
								. "', '" . tep_db_input($subscription['subscription_conditions']) . "', '" . tep_db_input($subscription['subscription_pending_period']) . "', '" . tep_db_input($subscription['subscription_renewal_start'])
								. "', '" . tep_db_input($subscription['subscription_renewal_end'])	. "', '" . tep_db_input($subscription['subscription_packing_slip']) 
								. "', '" . tep_db_input($subscription['subscription_free_trial'])	. "', '" . tep_db_input($subscription['subscription_free_days']) 
								. "', '" . tep_db_input($subscription['emarketing_on_renewal'])	. "','" . tep_db_input($subscription['wallet_payment'])
								. "','" . tep_db_input($subscription['periodic_payment']) . "','" . tep_db_input($subscription['periodic_days']) 
								. "','" . tep_db_input($subscription['periodic_type']) . "','" .tep_db_input($subscription['deliveries'])
								. "','" . tep_db_input($subscription['deliveries_name']) . "','". tep_db_input($subscription['deliveries_perday'])
								."','" . tep_db_input($subscription['subscription_start_date']) . "','" . tep_db_input($subscription['subscription_finish_date'])
								. "','" . tep_db_input($subscription['subscription_period']) . "','" . tep_db_input($subscription['subscription_date_type'])
								. "','" . tep_db_input($subscription['subscription_latest_start_date']) . "')");
					$dup_subscription_id = tep_db_insert_id();
					$description_query = tep_db_query("SELECT language_id, subscription_name, subscription_description,subscription_url from " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " where subscription_id = '" . (int)$suID . "'");
					while ($description = tep_db_fetch_array($description_query)) {
						tep_db_query("insert into " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " (subscription_id, language_id, subscription_name, subscription_description, subscription_url, subscription_viewed) values ('" . 
									(int)$dup_subscription_id . "', '" . (int)$description['language_id'] . "', '" . tep_db_input($description['subscription_name']) . "', '" . tep_db_input($description['subscription_description']) . "', '" . 
									tep_db_input($description['subscription_url']) . "', '0')");
					}
					tep_db_query("insert into " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " (subscription_id, subscription_categories_id) values ('" . (int)$dup_subscription_id . "', '" . (int)$subscription_categories_id . "')");
				}
				if($error!="") echo 'copy_error^'.$error;
		  		else echo "copy_success^".$subscription_categories_id;
			}else if($action=='update_product'){
					if ($HTTP_POST_VARS['action_type'] == 'new') echo $HTTP_POST_VARS['action_type'] . '_product^';
					if ($HTTP_GET_VARS['pID']) $subscription_id = tep_db_prepare_input($HTTP_GET_VARS['pID']);
						if($HTTP_POST_VARS['subscription_categories_ids_assign'])
							$HTTP_POST_VARS['subscription_categories_ids']=split(",",$HTTP_POST_VARS['subscription_categories_ids_assign']);
						if($HTTP_POST_VARS['subscription_date_type_assign']) $HTTP_POST_VARS['subscription_date_type']=$HTTP_POST_VARS['subscription_date_type_assign'];
						$subscription_date_available = tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS['subscription_date_available']));											
						$subscription_finish_date = (isset($HTTP_POST_VARS["subscription_finish_date"])?tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS["subscription_finish_date"])):'0000-00-00');
						$subscription_start_date = (isset($HTTP_POST_VARS["subscription_start_date"])?tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS["subscription_start_date"])):'0000-00-00');
						$subscription_latest_start_date = (($HTTP_POST_VARS["subscription_latest_start_date"])?tep_convert_date_raw(tep_db_prepare_input($HTTP_POST_VARS["subscription_latest_start_date"])):'');
						if(!$subscription_latest_start_date) $subscription_latest_start_date='0000-00-00';												
						$subscription_period = (isset($HTTP_POST_VARS["subscription_period"])?$HTTP_POST_VARS["subscription_period"]:0);
						$subscription_date_type = (isset($HTTP_POST_VARS["subscription_date_type"])?$HTTP_POST_VARS["subscription_date_type"]:'F');
						if($subscription_date_type=='F')$subscription_latest_start_date='0000-00-00';
						$subscription_group=(isset($HTTP_POST_VARS["subscription_group"])?$HTTP_POST_VARS["subscription_group"]:'');
						$subscription_type=(isset($HTTP_POST_VARS["subscription_type"])?$HTTP_POST_VARS["subscription_type"]:'T');
						$support_minutes=0;
						//subscription type
							$deliveries=isset($HTTP_POST_VARS['txt_deliveries'])?$HTTP_POST_VARS['txt_deliveries']:0; 
							$deliveries_name=(int)isset($HTTP_POST_VARS['txt_deliveries_name'])?$HTTP_POST_VARS['txt_deliveries_name']:'Deliveries'; 
							if($subscription_type=='C')	$deliveries_perday=(int)isset($HTTP_POST_VARS['txt_perday'])?$HTTP_POST_VARS['txt_perday']:0;
							if($subscription_type=='P') $support_minutes=(int)$HTTP_POST_VARS['support_minutes'];
						//subscription type
						$emarketing_on_renewal='S';
						$emarketing_on_renewal=(($HTTP_POST_VARS['emarket_renew_continue']=='1')?'C':'S');
						//free trial
						$subscription_free_trial=(($HTTP_POST_VARS["subscription_free_trial"]!="")?$HTTP_POST_VARS["subscription_free_trial"]:'N');
						$subscription_free_days=1;
						if ($subscription_free_trial=='Y') $subscription_free_days=(int)$HTTP_POST_VARS["subscription_free_days"];
						$wallet_payment=(($HTTP_POST_VARS["wallet_payment"]!='')?$HTTP_POST_VARS["wallet_payment"]:'N');
						$periodic_payment=(($HTTP_POST_VARS["periodic_payment"]!="")?$HTTP_POST_VARS["periodic_payment"]:'N');
						$periodic_days=0;
						if ($periodic_payment=='Y') $periodic_days=(int)$HTTP_POST_VARS["periodic_days"];
						$periodic_type=(isset($HTTP_POST_VARS['periodic_type'])?$HTTP_POST_VARS['periodic_type']:'A');
						$pack_slip_content="";
						if($HTTP_POST_VARS['pack_slip']==true)	
							$pack_slip_content=tep_db_prepare_input($HTTP_POST_VARS['message_text']);
							
					    $subscription_cost_net=$HTTP_POST_VARS['subscription_costs_net'];
						if($subscription_cost_net=='') $subscription_cost_net='0';
						
						if($deliveries_perday=='') $deliveries_perday='0';
						
						$sql_data_array = array('subscription_date_available' => $subscription_date_available,
												'subscription_status' => tep_db_prepare_input($HTTP_POST_VARS['subscription_status']),
												'subscription_conditions'=>tep_db_prepare_input($HTTP_POST_VARS['subscription_conditions']),
												'subscription_costs'=>tep_db_prepare_input($subscription_cost_net),
												'subscription_type'=>tep_db_prepare_input($subscription_type),
												'subscription_tax_class_id'=>tep_db_prepare_input($HTTP_POST_VARS['subscription_tax_class_id']),
												'subscription_renewal_start'=>tep_db_prepare_input($HTTP_POST_VARS['subscription_renewal_start']),
												'subscription_renewal_end'=>tep_db_prepare_input($HTTP_POST_VARS['subscription_renewal_end']),
												'subscription_pending_period'=>tep_db_prepare_input($HTTP_POST_VARS['subscription_pending_period']),												
												'subscription_group'=>tep_db_prepare_input($subscription_group),
												'subscription_packing_slip'=>$pack_slip_content,
												'subscription_free_trial'=>$subscription_free_trial,
												'emarketing_on_renewal'=>$emarketing_on_renewal,
												'subscription_free_days'=>$subscription_free_days,
												'wallet_payment'=>$wallet_payment,
												'periodic_payment'=>$periodic_payment,
												'periodic_days'=>$periodic_days,
												'periodic_type'=>$periodic_type,
												'deliveries'=>(int)$deliveries,
												'deliveries_name'=>$deliveries_name,
												'deliveries_perday'=>(int)$deliveries_perday,
												'subscription_start_date'=>$subscription_start_date,
												'subscription_finish_date'=>$subscription_finish_date,
												'subscription_latest_start_date'=>$subscription_latest_start_date,
												'subscription_period'=>$subscription_period,
												'subscription_date_type'=>$subscription_date_type,
												'support_minutes'=>$support_minutes
												);	
						//change the stored subs Added line 463 - 473 by sobi
						if($subscription_type=="M")
						{
						    $query=tep_db_query("select sc.subscription_categories_id as cat_id,s.subscription_id as id from " .TABLE_SUBSCRIPTIONS ." s," . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " sc where s.subscription_id=sc.subscription_id and  s.subscription_type='M'");
							if(tep_db_num_rows($query)>0)
							{
								$row=tep_db_fetch_array($query);
								echo 'change_prev_subs^data_'.$row['id'].'_' . $row['cat_id'] .'#';
								tep_db_query("update " . TABLE_SUBSCRIPTIONS . " set  subscription_type='B' where subscription_type='M'");												
							}
						}
						if (!$HTTP_GET_VARS['pID']) {
							$insert_sql_data = array('subscription_date_added' => $server_date);						
							$sql_data_array = array_merge($sql_data_array, $insert_sql_data);						
							tep_db_perform(TABLE_SUBSCRIPTIONS, $sql_data_array);
							$subscription_id = tep_db_insert_id();
						} elseif ($HTTP_GET_VARS['pID']) {
							$update_sql_data = array('subscription_last_modified' => $server_date);						
							$sql_data_array = array_merge($sql_data_array, $update_sql_data);						
							tep_db_perform(TABLE_SUBSCRIPTIONS, $sql_data_array, 'update', "subscription_id = '" . (int)$subscription_id . "'");							
							tep_db_query("delete from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_id = '". (int)$subscription_id . "'");
				        }
						# create loop here to insert rows for multiple categories
						$differ_category_found=true;
						$selected_subscription_catids = $HTTP_POST_VARS['subscription_categories_ids'];
						if ($selected_subscription_catids)
						{
							foreach ($selected_subscription_catids as $current_subscription_category_id)
							{	
								if($sucPath==$current_subscription_category_id) $differ_category_found=false;
								if($sucPath!=$current_subscription_category_id) $differ_category=$current_subscription_category_id;
								tep_db_query("insert into " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " (subscription_id, subscription_categories_id) values ('" . $subscription_id . "', '" . $current_subscription_category_id . "')");
								$sucPath=$current_subscription_category_id;
							}
						}

						$languages = tep_get_languages();
						for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
							$language_id = $languages[$i]['id'];
							$sql_data_array = array('subscription_name' => tep_db_prepare_input($HTTP_POST_VARS['subscription_name'][$language_id]),
													'subscription_description' => tep_db_prepare_input($HTTP_POST_VARS['subscription_description'][$language_id]),
													'subscription_url' => tep_db_prepare_input($HTTP_POST_VARS['subscription_url'][$language_id]));							
							if (!$HTTP_GET_VARS['pID']) {
								$insert_sql_data = array('subscription_id' => $subscription_id,
														 'language_id' => $language_id);							
								$sql_data_array = array_merge($sql_data_array, $insert_sql_data);							
								tep_db_perform(TABLE_SUBSCRIPTIONS_DESCRIPTION, $sql_data_array);
							} elseif ($HTTP_GET_VARS['pID'])
								tep_db_perform(TABLE_SUBSCRIPTIONS_DESCRIPTION, $sql_data_array, 'update', "subscription_id = '" . (int)$subscription_id . "' and language_id = '" . (int)$language_id . "'");
						}				
					if($differ_category_found) echo 'diff_category^'.$differ_category.'#';
					echo_get_details();																			
			}else if($action=='edit_product'){
		      if($HTTP_GET_VARS['pID']>0) echo 'edit^';		
				
		      $subscription=array(); 								
			  $subscription_query = tep_db_query("SELECT sud.subscription_name, sud.subscription_description, sud.subscription_url, su.subscription_id, su.subscription_image, " .
										   "su.subscription_date_added,su.emarketing_on_renewal, su.subscription_last_modified, date_format(su.subscription_date_available, '%Y-%m-%d') " .
										   "as subscription_date_available, su.subscription_status, su.subscription_tax_class_id, su.subscription_costs, " .
										   "su.subscription_pending_period,su.subscription_renewal_start,su.subscription_renewal_end,su.subscription_free_trial,su.subscription_free_days, " .
										   "su.subscription_type,su.subscription_group,su.subscription_conditions,su.subscription_packing_slip, ".
										   "su.wallet_payment,su.periodic_payment,su.periodic_days,su.periodic_type,su.deliveries,su.deliveries_name,su.deliveries_perday,su.subscription_date_type, " .
										   "su.subscription_start_date,su.subscription_finish_date,su.subscription_latest_start_date,su.subscription_period,su.support_minutes from " . 
											TABLE_SUBSCRIPTIONS . " su, " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " sud where su.subscription_id=sud.subscription_id " .
										   " and su.subscription_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and sud.language_id = '" . (int)$languages_id . "'");
			  if(tep_db_num_rows($subscription_query)>0) $subscription = tep_db_fetch_array($subscription_query);		
			  $suInfo=new objectInfo($subscription);
			#get tax descriptions to display in tax selection
			$tax_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
			$tax_class_query = tep_db_query("SELECT tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_title");
			while ($tax_class = tep_db_fetch_array($tax_class_query)) {
			  $tax_class_array[] = array('id' => $tax_class['tax_class_id'],
										 'text' => $tax_class['tax_class_title']);
			} 			
			$status_array=array(array('id'=>1,'text'=>TEXT_HIDE_NONE),
								array('id'=>0,'text'=>TEXT_HIDE_ALWAYS));
																
			if (!isset($suInfo->subscription_status)) $suInfo->subscription_status = '1';					
			$merge_fields=array(array("id"=>"NA","text"=>DELI_NA),
								array("id"=>"CT","text"=>DELI_CT),
								array("id"=>"CC","text"=>DELI_CC),
								array("id"=>"CE","text"=>DELI_CE),
								array("id"=>"CP","text"=>DELI_CP),
								array("id"=>"CU","text"=>DELI_CU)
								);
		# get selected categories		
		$subscription_categories_query_selected = tep_db_query("SELECT subscription_categories_id from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_id = '" . (int)$HTTP_GET_VARS['pID'] . "'");
		$subscription_categories_array_selected = array(array('id' => ''));
		$sel_cat = $cID;
		if (!$sel_cat && $check_ID)  $sel_cat = $check_ID;
		$subscription_categories_array_selected = array (array ('id' => $sel_cat));
		if ($action == 'edit_product' && $HTTP_GET_VARS['pID']) {
				while ($subscription_categories = tep_db_fetch_array($subscription_categories_query_selected)) 
		  			$subscription_categories_array_selected[] = array('id' => $subscription_categories['subscription_categories_id']);					
		}
		$subscription_categories_array = array(array('id' => '', 'text' => TEXT_NONE));

		$language_id = 1;
		$subscription_categories_array = tep_get_subscription_category_tree(); 
		// get selected groups
		$subscription_groups_query = tep_db_query("SELECT subscription_group_name from " . TABLE_SUBSCRIPTIONS_GROUP);
		$subscription_groups_array = array(array('id' => '','text'=>''));
		while ($subscription_groups = tep_db_fetch_array($subscription_groups_query)) {

		  $subscription_groups_array[] = array('id' => $subscription_groups['subscription_group_name'],'text'=>$subscription_groups['subscription_group_name']);
		}
		
		
		//get wallet periodic type
		$wallet_periodic_fields=array(array("id"=>"A","text"=>TEXT_AFTER_SUBSCRIPTION),
								array("id"=>"B","text"=>TEXT_BEFORE_SUBSCRIPTION)
								)	
								
		?>
		<table border="0" width="100%" cellspacing="0" cellpadding="2">		  
		  <?php	  tep_content_title_top("Categories");  ?>		  
		  <tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		  </tr>
			<tr>
				<td>
				<table border=0 cellpadding="0" cellspacing="0">
					<tr>
						<td class="main" width="150" valign="top"><?php echo TEXT_SUBSCRIPTION_CATEGORIES; ?></td>
						<td>
						<?php 
						$categories_query_selected = tep_db_query("select subscription_categories_id from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_id = '" . $HTTP_GET_VARS['pID'] . "'");
						$category_selected=array();
						 while ($categories = tep_db_fetch_array($categories_query_selected)) 
						 	$category_selected[]=array('id'=>$categories['subscription_categories_id']);

						$category_array=array();
						$cat_query = tep_db_query("select cd.subscription_categories_name,cd.subscription_categories_id from " . TABLE_SUBSCRIPTION_CATEGORIES . " c," . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " cd where c.subscription_categories_id=cd.subscription_categories_id and cd.language_id='" . $language_id  ."'" );
						while($cat_array=tep_db_fetch_array($cat_query))
							$category_array[]=array('id'=>$cat_array['subscription_categories_id'],'text'=>$cat_array['subscription_categories_name']);

						 ?>
						</td>
						<td valign="top"><?php echo tep_draw_mselect_checkbox('subscription_categories_ids[]',$category_array,$category_selected); ?></td>
						<td class="main" width="200">&nbsp;</td>
					</tr>
				</table>
				</td>
			</tr>
			<tr>
				<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
			</tr>
			<tr>
				<td>
				<table border="0" cellspacing="0" cellpadding="2" width="100%">				
					<tr>
						<td>
						<table border=0 cellpadding="0" cellspacing="0">
							<tr>
								<td class="main" width="150" valign="top"><?php echo TEXT_SUBSCRIPTION_STATUS; ?></td>
								<td class="main" width="200" valign="top"><?php 
								$status_array=array(array('id'=>1,'text'=>TEXT_HIDE_NONE),
													array('id'=>0,'text'=>TEXT_HIDE_ALWAYS));								
								echo tep_draw_pull_down_menu('subscription_status', $status_array, $suInfo->subscription_status); ?></td>
								<?php $_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);?>
								<td class="main" width="150" valign="top"><?php echo TEXT_SUBSCRIPTION_DATE_AVAILABLE; ?><br><small>(<?php echo $date_format;?>)</small></td>
								<td class="main" width="200" valign="top"><?php echo tep_draw_input_field("subscription_date_available",(tep_not_null($suInfo->subscription_date_available)?format_date($suInfo->subscription_date_available):format_date($server_date)),"size=10",false,'text',false);?>
								<a href="javascript:show_calendar('new_product.subscription_date_available',null,null,'<?php echo $date_format;?>');"
							       onmouseover="window.status='Date Picker';return true;"
							       onmouseout="window.status='';return true;"><img border="none" src="images/icon_calendar.gif"/>  
							    </a>
							</tr>
						</table>
						</td>
					</tr>
					 <?php tep_content_title_bottom(); ?>
					<tr>
						<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
					</tr>
					<?php tep_content_title_top("General"); ?>
					<tr>
						<td>
						<table border="0" cellpadding="4" cellspacing="0" >
							<tr>
								<td>
								<table border="0" cellpadding="0" cellspacing="0">
									<?php
									for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
									?>
											<tr>
												<td class="main" width="150"><?php if ($i == 0) echo TEXT_SUBSCRIPTION_NAME; ?></td>
												<td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('subscription_name[' . $languages[$i]['id'] . ']', (isset($subscription_name[$languages[$i]['id']]) ? $subscription_name[$languages[$i]['id']] : tep_get_subscription_name($suInfo->subscription_id, $languages[$i]['id'])),'maxlength="64"'); ?></td>
											</tr>
									<?php
									}
									?>
								</table>
								</td>
							</tr>
						<tr>
							<td>
							<table border="0" cellpadding="0" cellspacing="0">
								<?php
								for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
								?>
									<tr>
										<td class="main" valign="top" width="150"><?php if ($i == 0) echo TEXT_SUBSCRIPTION_DESCRIPTION; ?></td>
										<td>
										<table border="0" cellspacing="0" cellpadding="0">
											<tr>
												<td class="main" valign="top"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?>&nbsp;</td>
												<td class="main"><?php echo tep_draw_textarea_field('subscription_description[' . $languages[$i]['id'] . ']', 'soft', '80', '24', (isset($subscription_description[$languages[$i]['id']]) ? $subscription_description[$languages[$i]['id']] : tep_get_subscription_description($suInfo->subscription_id, $languages[$i]['id'])),'id="subscription_description[' . $languages[$i]['id'] . ']"'); ?></td>
											</tr>
										</table>
										</td>
									</tr>
								<?php
								}
								?>
							</table>
							</td>
						</tr>
						<tr>
							<td width="100%">
							<table border="0" cellpadding="0" cellspacing="0" >
								<?php
								for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
								?>
									<tr>
										<td class="main" width="120"><?php if ($i == 0) echo TEXT_SUBSCRIPTION_URL . '<br><small>' . TEXT_SUBSCRIPTION_URL_WITHOUT_HTTP . '</small>'; ?></td>
										<td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '&nbsp;' . tep_draw_input_field('subscription_url[' . $languages[$i]['id'] . ']', (isset($subscription_url[$languages[$i]['id']]) ? $subscription_url[$languages[$i]['id']] : tep_get_subscription_url($suInfo->subscription_id, $languages[$i]['id'])),'maxlength="255"'); 
											 echo '&nbsp;&nbsp;'.TEXT_SUBSCRIPTION_IMAGE .'&nbsp;&nbsp;'. tep_draw_file_field('subscription_image') . '<br>'. tep_draw_separator('pixel_trans.gif',340,10) . $suInfo->subscription_image . tep_draw_hidden_field('subscription_previous_image', $suInfo->subscription_image); ?></td>
									</tr>
								<?php
								}
								?>
								<tr>
									<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>		  
								<tr>
									<td class="main" width="120"><?php echo TEXT_SUBSCRIPTION_TYPE; ?></td>
									<td>
										<?php $type_array=array(
																array('id'=>'B','text'=>TEXT_SUBSCRIPTION_BASIC),																
																array('id'=>'C','text'=>TEXT_SUBSCRIPTION_CASUAL),
																array('id'=>'S','text'=>TEXT_SUBSCRIPTION_SEASONAL),
																array('id'=>'P','text'=>TEXT_SUBSCRIPTION_SUPPORT),
																array('id'=>'M','text'=>TEXT_SUBSCRIPTION_MEMBERSHIP)); //Added line 703-708 by sobi
										 $get_member_query=tep_db_query("select subscription_id from " . TABLE_SUBSCRIPTIONS . " where subscription_type='M'");
										 if(tep_db_num_rows($get_member_query)>0){
										 	$alert_error=($suInfo->subscription_type!='')?$suInfo->subscription_type:'B';
										 }
										 else
										 	$alert_error='';
										?>
										<table border="0" cellspacing="0" cellpadding="0" width="85%">
											<tr>
												<td  class="main"><?php echo tep_draw_pull_down_menu('subscription_type',$type_array,$suInfo->subscription_type,'onchange=javascript:do_subscription_type("' . $alert_error. '")');?></td>
												<td class="main" align="left">
													<span id="box_deliveries" style="display:none">
														<?php echo '&nbsp;&nbsp;'.tep_draw_input_field('txt_deliveries',$suInfo->deliveries,'onKeyPress="return keyRestrict(event)" size="3" maxlength="6"');
															  echo ' ' . tep_draw_input_field('txt_deliveries_name',$suInfo->deliveries_name,' onKeyPress="return keyRestrict(event)" size="3" maxlength="20"');
														 ?>
													</span>
													<span align="left" id="box_support" style="display:none;">
													 <?php echo tep_draw_input_field('support_minutes',$suInfo->support_minutes,'onKeyPress="return keyRestrict(event)" size="3" maxlength="2"').' '.TEXT_MINS;?>
													</span>
												</td>
												<td class="main" align="left" width="120">
													<div id="box_perday" style="display:none">
														<?php echo '&nbsp;'.TEXT_PER .'  '. tep_draw_input_field('txt_perday',$suInfo->deliveries_perday,'onKeyPress="return keyRestrict(event)" size="3" maxlength="6"') .'  '. TEXT_DAY;?>
													</div>
												</td>												
											</tr>	
											
											<script language="javascript">do_subscription_type();</script>			
										</table>	
									</td>									
								</tr>
								<tr>
									<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
								<tr>
									<td valign="top" class="main">
										<?php echo TEXT_SUBSCRIPTION_DATE_TYPE;?>
									</td>
									<td class="main" valign="top">
										<?php 
											$sub_date_type = '';
											if($suInfo->subscription_date_type == "")$sub_date_type = 'F';
											else $sub_date_type = $suInfo->subscription_date_type;
											echo tep_draw_radio_field("subscription_date_type",'F',($sub_date_type=='F')?true:false,'',' onchange=javascript:do_subscription_date_type() ') . TEXT_FIXED. '&nbsp;';
											echo tep_draw_radio_field("subscription_date_type",'L',($sub_date_type=='L')?true:false,'',' onchange=javascript:do_subscription_date_type() ') . TEXT_FLEXIBLE . '&nbsp;';
											echo tep_draw_radio_field('subscription_date_type','P',($sub_date_type=='P')?true:false,'',' onchange=javascript:do_subscription_date_type() ') . TEXT_PREDEFINED. tep_draw_separator('pixel_trans.gif',70,10);
											echo TEXT_SUBSCRIPTION_PERIOD . '&nbsp;&nbsp;' . tep_draw_input_field('subscription_period',(tep_not_null($suInfo->subscription_period)?$suInfo->subscription_period:'1'),' onKeyPress="return keyRestrict(event)" size=3 maxlength=11 id="subscription_period" onblur="check_input(true)"') . "&nbsp;" . TEXT_DAY;
										?>
									</td>
								</tr>
								<tr>
									<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
								</tr>
							</table>
							
							<table border="0" cellpadding="0" cellspacing="0" >
								<tr>
									<?php
										echo '<input type="hidden" name="currend_date" id="currend_date" value="' . date(EVENTS_DATE_FORMAT)  . '">';
									?>
									<td class="main" width="80" valign="top" align="left">
										<?php echo TEXT_SUBSCRIPTION_START_DATE;?>
									</td>
									<td class="main" width="50" valign="top" align="left">
									<?php
										 echo tep_draw_input_field("subscription_start_date",(tep_not_null($suInfo->subscription_start_date)?format_date($suInfo->subscription_start_date):format_date($current_date)),"size=10 onblur='check_input(true)'",false,'text',false)."&nbsp;&nbsp;";
									?>
									</td>
									<td class="main" width="30" valign="top" align="left">
									<a href="javascript:show_calendar('new_product.subscription_start_date',null,null,'<?php echo $date_format;?>');"
									   onmouseover="window.status='Date Picker';return true;"
									   onmouseout="window.status='';return true;" onBlur="check_input(true)"><div id="subscription_start_date_icon" name="subscription_start_date_icon" style="display:block"><img border="none" src="images/icon_calendar.gif"/></div>
									</a>
									</td>
									<td class="main" width="80" valign="top" align="left">
										<?php echo TEXT_SUBSCRIPTION_FINISH_DATE;  ?>
									</td>
									<td class="main" width="50" valign="top" align="left">
									<?php 
										echo tep_draw_input_field("subscription_finish_date",(tep_not_null($suInfo->subscription_finish_date)?format_date($suInfo->subscription_finish_date):format_date($current_date)),"size=10 onblur='check_input(true)'",false,'text',false)."&nbsp;&nbsp;";
									?>
									</td>
									<td width="30" valign="top" align="left">
										<a href="javascript:show_calendar('new_product.subscription_finish_date',null,null,'<?php echo $date_format;?>');"
									   onmouseover="window.status='Date Picker';return true;"
									   onmouseout="window.status='';return true;" onBlur="check_input(true)"><div id="subscription_begins_date_icon" name="subscription_begins_date_icon" style="display:block"><img border="none" src="images/icon_calendar.gif"/></div>
									</a>
									</td>
										
									<td id="fixed_date" style="display:none" >
										<table border="0"  cellpadding="0" cellspacing="0" width="100%">
											<tr>
											   <td class="main" width="200" valign="top" align="left" id="latest"   >
													<?php  echo TEXT_SUBSCRIPTION_LATEST_START_DATE; ?>
												</td>
												<td width="50" valign="top" align="left">
													<?php echo tep_draw_input_field("subscription_latest_start_date",(tep_not_null($suInfo->subscription_latest_start_date)?format_date($suInfo->subscription_latest_start_date):format_date($current_date)),"size=10 onblur='check_input(true)'",false,'text',false)."&nbsp;&nbsp;";?>
												</td>
												<td valign="top" align="left">								
													<a href="javascript:show_calendar('new_product.subscription_latest_start_date',null,null,'<?php echo $date_format;?>');"
													   onmouseover="window.status='Date Picker';return true;"
													   onmouseout="window.status='';return true;" onBlur="check_input(true)"><div id="subscription_begins_date_icon" name="subscription_begins_date_icon" style="display:block"><img border="none" src="images/icon_calendar.gif"/></div>
													</a>
												</td>
											</tr>
											</table>
									</td>	
								</tr>
							</table>
							<script language="javascript" type="text/javascript">
								do_subscription_date_type();
							</script>
							</td>
						</tr>
					</table>
					</td>
				</tr>
					<?php tep_content_title_bottom(); 
						  tep_content_title_top("Fees"); 
					 ?>
					<tr>
						<td>
						<table border=0 cellpadding="4" cellspacing="0" width="100%">
							<tr>
								<td class="main" width="26%"><?php echo TEXT_SUBSCRIPTION_TAX_CLASS .tep_draw_separator('pixel_trans.gif',20,10).tep_draw_pull_down_menu('subscription_tax_class_id', $tax_class_array, $suInfo->subscription_tax_class_id, 'onchange="updateGross()"') ; ?></td>
								<td class="main" width="34%"><?php 
								$price=$suInfo->subscription_costs;
			           	 		if(strpos($price,".") && substr($price,strpos($price,"."))<=0) $price=(int)$price;
								echo TEXT_SUBSCRIPTION_FEES_NET_INFO .tep_draw_separator('pixel_trans.gif',20,10). tep_draw_input_field('subscription_costs_net', $price, 'onKeyUp="updateGross()"') ; ?></td>
								<td class="main" width="40%"><?php echo TEXT_SUBSCRIPTION_FEES_GROSS_INFO .tep_draw_separator('pixel_trans.gif',20,10). tep_draw_input_field('subscription_costs_gross', $suInfo->subscription_costs, 'OnKeyUp="updateNet()"'); ?></td>
							</tr>
						</table>	
							<tr>
							<td align=left class="tableHeading" width="100%"><?php echo tep_draw_checkbox_field('pack_slip',true,($suInfo->subscription_packing_slip)?true:false ,'','onclick=javascript:(this.checked)?document.getElementById(\'slip_mess\').style.display="":document.getElementById(\'slip_mess\').style.display="none"').' '.TITLE_GROUP_PACKING_SLIP;?></td>
							</tr>
						</td>
					</tr>	
					<?php tep_content_title_bottom(); ?> 				
				<tr>
					<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
				</tr>
				<tr>
					<td>
					<table border=0 cellpadding="0" cellspacing="0" width="50%" id="slip_mess" <?php echo ($suInfo->subscription_packing_slip=='')?'style="display:none"':'';?>>
						<tr>
							<td class="main" valign="top">
								<?php 
										echo tep_draw_textarea_field('message_text','soft','50','10',$suInfo->subscription_packing_slip,'style="height:100"');
								?>
							</td>
							<td valign="top" align=center class="main">
								<?php 
									   echo tep_draw_pull_down_menu('merge_fields',$merge_fields,'','style="height:100" size=5 ondblClick="AddField()"');

								?>
							</td>
						</tr>
					</table>
					</td>
				</tr>	  
			</table>
			</td>
		</tr>	
		
		<?php tep_content_title_top("Conditions"); ?>
		<tr>
			<td>
			<table border="0" cellspacing="0" cellpadding="4"  width="100%">
				
				<tr>
					<td class="main" width="140"><?php echo TEXT_SUBSCRIPTION_GROUP;?></td>
					<td class="main"><?php echo tep_draw_pull_down_menu("subscription_group",$subscription_groups_array,$suInfo->subscription_group);?></td>
				</tr>
				<tr>
					<td class="main" width="140" valign="top"><?php echo TEXT_SUBSCRIPTION_CONDITIONS;?></td>
					<td class="main"><?php echo tep_draw_textarea_field("subscription_conditions",'wrap',50,5,$suInfo->subscription_conditions);?></td>
				</tr>
				<tr>
					<td class="main" width="140"><?php echo TEXT_SUBSCRIPTION_PENDING_PERIOD;?></td>
					<td  class="main"><?php echo tep_draw_input_field("subscription_pending_period",$suInfo->subscription_pending_period,'onKeyPress="return keyRestrict(event)" size="3" maxlength="6"');
							  echo tep_draw_separator('pixel_trans.gif',130,10) . TEXT_SUBSCRIPTION_RENEWAL_START .'&nbsp;&nbsp;' ;	
							  echo tep_draw_separator('pixel_trans.gif',20,10).tep_draw_input_field("subscription_renewal_start",(tep_not_null($suInfo->subscription_renewal_start) ? $suInfo->subscription_renewal_start:'0'),' onKeyPress="return keyRestrict(event)" size="3" maxlength="6"').'&nbsp;' . TEXT_SUBSCRIPTION_DAYS;?>
					</td>
				</tr>
				<tr>
					<td class="main" width="140"><?php echo TEXT_FREE_TRIAL;?></td>
					<td class="main" valign="top">
					<?php 
						echo tep_draw_checkbox_field('subscription_free_trial','Y',($suInfo->subscription_free_trial=='Y'?true:false)) . '&nbsp;&nbsp;';
						echo TEXT_FREE_DAYS . '&nbsp;&nbsp;' . tep_draw_input_field("subscription_free_days",$suInfo->subscription_free_days,' onKeyPress="return keyRestrict(event)" size="3" maxlength="6"');
						echo tep_draw_separator('pixel_trans.gif',80,10) . TEXT_SUBSCRIPTION_RENEWAL_END . '&nbsp;&nbsp;';
						echo tep_draw_separator('pixel_trans.gif',28,10).tep_draw_input_field("subscription_renewal_end",(tep_not_null($suInfo->subscription_renewal_end) ? $suInfo->subscription_renewal_end:'0'),' onKeyPress="return keyRestrict(event)" size="3" maxlength="6"') . '&nbsp;' . TEXT_SUBSCRIPTION_DAYS;
					?>
					</td>
				</tr>
				<tr>
					<td class="main" width="140"><?php echo TEXT_WALLET_PAYMENT ?></td>
					<td class="main" valign="top">
					<?php echo tep_draw_checkbox_field('wallet_payment','Y',($suInfo->wallet_payment=='Y'?true:false),'','onclick="set_action(1);"');
						  echo  tep_draw_separator('pixel_trans.gif',180,10) . EMARKETING_RENEWAL . '&nbsp;&nbsp;';
						  echo  tep_draw_radio_field("emarket_renew_continue",'1',($suInfo->emarketing_on_renewal=='C')?true:false) . TEXT_CONTINUE. '&nbsp;' . tep_draw_radio_field("emarket_renew_continue",'0',($suInfo->emarketing_on_renewal=='S')?true:false) . TEXT_STOP;
					 ?>
					</td>
					
				</tr>
				<tr>
					<td class="main" width="140"><?php echo TEXT_PERIODIC_PAYMENT;?></td>
					<td class="main"valign="top">
					<?php 
						echo tep_draw_checkbox_field('periodic_payment','Y',($suInfo->periodic_payment=='Y'?true:false),'','onclick="set_action(2);"') . '&nbsp;&nbsp;';
						echo TEXT_PERIODIC . '&nbsp;&nbsp;' . tep_draw_input_field("periodic_days",(tep_not_null($suInfo->periodic_days) ? $suInfo->periodic_days:'1'),' onKeyPress="return keyRestrict(event)" size="3" maxlength="6"' .'  '.($suInfo->periodic_payment=='Y'?'enabled':'disabled')) . '&nbsp;&nbsp;';

						echo TEXT_DAYS . '&nbsp;&nbsp;';
					    echo tep_draw_pull_down_menu('periodic_type',$wallet_periodic_fields,$suInfo->periodic_type,($suInfo->periodic_payment=='Y'?'enabled':'disabled'));
					?>
					
					</td>
				</tr>
				
			</table>
			</td>
		</tr>
		<?php tep_content_title_bottom(); ?>
		<tr>
			<td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
		</tr>
		<tr align="right"><td colspan="10" width='1200' align='right'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href='javascript:expand_category(0,1,0)'><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</td></tr>		
		<?php 
		echo tep_draw_hidden_field('subscription_date_added', (($suInfo->date_added) ? $suInfo->date_added : getServerDate())); 
		?>			
	</table>	
	<?php
	 }
	exit;
	}
   function echo_get_details(){
   	 global $currencies,$languages_id,$subscription_id,$cID,$HTTP_GET_VARS;
   	 $str_vals="";
     $product_categories = tep_db_query("select cd.subscription_categories_id,cd.subscription_categories_name from " . TABLE_SUBSCRIPTION_CATEGORIES . " c," . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " cd where c.subscription_categories_id=cd.subscription_categories_id and cd.language_id='" . (int) $languages_id . "' and c.subscription_categories_id='" . (int) $cID . "'");
	 if (tep_db_num_rows($product_categories) > 0) {
		$categories = tep_db_fetch_array($product_categories);
		while (list (, $vals) = each($categories)) 
			$str_vals .= $vals . '{}';
	 }
	 //$check_sql = "select count(*) as count from " . TABLE_SUBSCRIPTIONS . " s," . TABLE_ORDERS . " o," . TABLE_ORDERS_PRODUCTS . " op where o.orders_id=op.orders_id and op.products_type='S' and s.subscription_id=op.products_id and s.subscription_id=" . $subscription_id;
	 //$check_query = tep_db_query($check_sql);
	 //$check_result = tep_db_fetch_array($check_query);
     $subscription_query = tep_db_query("select sd.subscription_id,sd.subscription_name, sd.subscription_description,s.subscription_tax_class_id,s.subscription_costs,date_format(s.subscription_date_added,'%Y-%m-%d') as subscription_date_added, date_format(s.subscription_last_modified,'%Y-%m-%d') as subscription_last_modified,s.subscription_status,s.subscription_image,s.subscription_type from " . TABLE_SUBSCRIPTIONS . " s, " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " sd where s.subscription_id = '" . (int)$subscription_id. "' and s.subscription_id = sd.subscription_id and sd.language_id = '" . (int)$languages_id . "'");
	 if(tep_db_num_rows($subscription_query)>0){
	  $product = tep_db_fetch_array($subscription_query);
	  while(list($key,$vals)=each($product)){	
	  if($key=='subscription_name')
	  {
	  	if($product['subscription_type']=="M")
			$vals.=	'&nbsp;<font color="green">(' . TEXT_SUBSCRIPTION_MEMBERSHIP . ')</font>';														
	  	}
		if($key=='subscription_description')								
	 		$vals = str_replace("\n","", $vals).'{}1';	 	 						 			
		if($key=='subscription_tax_class_id'){
			$tax_id = $vals;
			continue;
		}
		if($key=='subscription_type')
			continue;
		if($key=='subscription_costs')			 		
		$vals = $currencies->format(tep_add_tax($vals,tep_get_tax_rate($tax_id)));			 		
		$str_vals.=$vals."{}";
		if($key=='subscription_image') $str_vals.="{}"; 
	//	 $str_vals.=tep_draw_hidden_field('is_order',$check_result['count']);
	  }
    }else $str_vals="No Record Found";
	 echo (($HTTP_POST_VARS['action_type'] == 'new') ? '' : 'get_details^') . $str_vals;
   }
      
