<?php
/*
###################################################################################
  Bigware Shop 2.3
  Release Datum: 23.08.2015
  
  Bigware Shop
  http://www.bigware.de

  Copyright (c) 2015 Bigware LTD
  (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
  (c) 2015	Bigware LTD

  Copyrightvermerke duerfen nicht entfernt werden.
  ------------------------------------------------------------------------
  Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
  der GNU General Public License, wie von der Free Software Foundation
  veroeffentlicht, weitergeben und/oder modifizieren, entweder gemaess Version 2 
  der Lizenz oder (nach Ihrer Option) jeder spaeteren Version.
  Die Veroeffentlichung dieses Programms erfolgt in der Hoffnung, dass es Ihnen
  von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne die
  implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FUER EINEN
  BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
  
  Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
  Programm erhalten haben. Falls nicht, schreiben Sie an die Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

  Infos:
  ------------------------------------------------------------------------
  Der Bigware Shop wurde vor vielen Jahren bereits aus dem bekannten Shopsystem osCommerce
  weiter- und neuentwickelt.
  Der Bigware Shop legt im hohen Masse Wert auf Bedienerfreundlichkeit, beinhaltet eine leichte
  Installation, viele neue professionelle Werkzeuge und zeichnet sich aus durch eine grosse 
  Community, die bei Problemen weiterhelfen kann.
  
  Der Bigware Shop ist auf jedem System lauffaehig, welches eine PHP Umgebung
  (ab PHP 4.1.3) und mySQL zur Verfuegung stellt und auf Linux basiert.
 
  Hilfe erhalten Sie im Forum auf www.bigware.de 
  
  -----------------------------------------------------------------------
  
 ##################################################################################




*/
?>
<?php 
  require('load_this/load_bigware_11.php'); 
  $display_tva_over = false;
  $display_tva_up = false; 
  $display_model = true; 
  $display_producer = false; 
  $display_picture = false; 
  $display_quantity = true; 
  $display_tax = true; 
  $display_weight = true; 
  $display_statut = true;  
  $modify_name = true;
  $modify_model = true;
 ($row_by_page) ? define('MAX_SHOW_ROW_BY_PAGE' , $row_by_page ) : $row_by_page = MAX_SHOW_SEARCH_RESULTS; define('MAX_SHOW_ROW_BY_PAGE' , MAX_SHOW_SEARCH_RESULTS ); 
    $tax_class_array = array(array('id' => '0', 'text' => NO_TAX_TEXT));
    $tax_class_query = go_db_query("select tax_class_id, tax_class_title from " . DB_TBL_TAX_CLASS . " order by tax_class_title");
    while ($tax_class = go_db_fetch_array($tax_class_query)) {
      $tax_class_array[] = array('id' => $tax_class['tax_class_id'],
                                 'text' => $tax_class['tax_class_title']);
    } 
	$producers_array = array(array('id' => '0', 'text' => NO_PRODUCER));
	$producers_query = go_db_query("select producers_id, producers_name from " . DB_TBL_PRODUCERS . " order by producers_name");
	while ($producers = go_db_fetch_array($producers_query)) {
		$producers_array[] = array('id' => $producers['producers_id'],
		'text' => $producers['producers_name']);
	} 
function producers_list(){
	global $producer;
	
	$producers_query = go_db_query("select m.producers_id, m.producers_name from " . DB_TBL_PRODUCERS . " m order by m.producers_name ASC");
	$return_string = '<select name="producer" onChange="this.form.submit();">';
	$return_string .= '<option value="' . 0 . '">' . TEXT_ALL_PRODUCERS . '</option>';
	while($producers = go_db_fetch_array($producers_query)){
		$return_string .= '<option value="' . $producers['producers_id'] . '"';
		if($producer && $producers['producers_id'] == $producer) $return_string .= ' SELECTED';
		$return_string .= '>' . $producers['producers_name'] . '</option>';
	}
	$return_string .= '</select>';
	return $return_string;
}
  switch ($_GET['action']) {
    case 'update' :
      $count_update=0;
      $item_updated = array();
	  	if($_POST['item_new_model']){
		   foreach($_POST['item_new_model'] as $id => $new_model) {
			 if (trim($_POST['item_new_model'][$id]) != trim($_POST['item_old_model'][$id])) {
			   $count_update++;
			   $item_updated[$id] = 'updated';
			   go_db_query("UPDATE " . DB_TBL_ITEMS . " SET items_model='" . $new_model . "' WHERE items_id=$id");
			 }
		   }
		}
	  	if($_POST['item_new_name']){
		   foreach($_POST['item_new_name'] as $id => $new_name) {
			  
			 if (trim($_POST['item_new_name'][$id]) != trim($_POST['item_old_name'][$id])) {
			   $count_update++;
			   $item_updated[$id] = 'updated';  
			   go_db_query("UPDATE " . DB_TBL_ITEMS_DESCRIPTION . " SET items_name='" . $new_name . "' WHERE items_id=$id and language_id=" . $languages_id);
			 }
		   }
		}
				
	  	if($_POST['item_new_price']){
		   foreach($_POST['item_new_price'] as $id => $new_price) {
			 if ($_POST['item_new_price'][$id] != $_POST['item_old_price'][$id] && $_POST['update_price'][$id] == 'yes') {
			   $count_update++;
			   $item_updated[$id] = 'updated';
			   go_db_query("UPDATE " . DB_TBL_ITEMS . " SET items_price=$new_price WHERE items_id=$id");
				 		
		$attendees_group_query = go_db_query("select distinct attendees_group_id, attendees_group_name, attendees_group_discount from attendees_groups where attendees_group_id != '" . 0 . "' order by attendees_group_id");
		while ($attendees_group = go_db_fetch_array($attendees_group_query)) {
		 if (go_db_num_rows($attendees_group_query) > 0) {
     $characteristics_query = go_db_query("select attendees_group_id, attendees_group_price, items_price from " . DB_TBL_ITEMS_GROUPS . " where items_id = '" . $id . "' and attendees_group_id = '" . $attendees_group['attendees_group_id'] . "' order by attendees_group_id");
     $characteristics = go_db_fetch_array($characteristics_query);
		 $query_discount = go_db_query("select discount from " . DB_TBL_GROUPS_TO_CATEGORIES . " where attendees_group_id = " . $attendees_group['attendees_group_id'] ." and categories_id=" . $current_category_id ."");
		 $query_discount_result = go_db_fetch_array($query_discount);
		 if (is_null($query_discount_result['discount'])) {
		 $ricarico = $attendees_group['attendees_group_discount'];
		 } else {
		 $ricarico = $query_discount_result['discount'];
		 }       
			 }
       
			 $pricek = $new_price ; 
  	if ($pricek > 0){			 
  		if (B2B == 'true') {	
  		 if ($ricarico > 0) $newprice = $pricek+($pricek/100)*$ricarico;
  		 if ($ricarico == 0) $newprice = $pricek;
   			}
  	  if (B2B == 'false') {
  	   if ($ricarico > 0) $newprice = $pricek-($pricek/100)*$ricarico;
  		 if ($ricarico == 0) $newprice = $pricek;
   			}
  	 } else {
  	 $newprice = 0;
  	 } 
    if ($characteristics['attendees_group_id'] == NULL ) { 
		go_db_query("INSERT INTO "  . DB_TBL_ITEMS_GROUPS . " (attendees_group_id, attendees_group_price, items_id, items_price) values (". $attendees_group['attendees_group_id'] . ", " . $newprice . ", " . $id . ", " . $pricek . ")");  				
		} else {
		go_db_query("UPDATE "  . DB_TBL_ITEMS_GROUPS . " SET attendees_group_price=". $newprice ." WHERE attendees_group_id=". $characteristics['attendees_group_id'] ." AND items_id=". $id ."");
		}						
				$count_update++;
			  $item_updated[$id] = 'updated';								
		
		  }
			 }
		    }
		     }
		if($_POST['item_new_weight']){
		   foreach($_POST['item_new_weight'] as $id => $new_weight) {
			 if ($_POST['item_new_weight'][$id] != $_POST['item_old_weight'][$id]) {
			   $count_update++;
			   $item_updated[$id] = 'updated';
			   go_db_query("UPDATE " . DB_TBL_ITEMS . " SET items_weight=$new_weight WHERE items_id=$id");
			 }
		   }
		}
		if($_POST['item_new_quantity']){
		   foreach($_POST['item_new_quantity'] as $id => $new_quantity) {
			 if ($_POST['item_new_quantity'][$id] != $_POST['item_old_quantity'][$id]) {
			   $count_update++;
			   $item_updated[$id] = 'updated';
			   go_db_query("UPDATE " . DB_TBL_ITEMS . " SET items_quantity=$new_quantity WHERE items_id=$id");
			 }
		   }
		}
		if($_POST['item_new_producer']){
		   foreach($_POST['item_new_producer'] as $id => $new_producer) {
			 if ($_POST['item_new_producer'][$id] != $_POST['item_old_producer'][$id]) {
			   $count_update++;
			   $item_updated[$id] = 'updated';
			   go_db_query("UPDATE " . DB_TBL_ITEMS . " SET producers_id=$new_producer WHERE items_id=$id");
			 }
		   }
		}
		if($_POST['item_new_picture']){
		   foreach($_POST['item_new_picture'] as $id => $new_picture) {
			 if ($_POST['item_new_picture'][$id] != $_POST['item_old_picture'][$id]) {
			   $count_update++;
			   $item_updated[$id] = 'updated';
			   go_db_query("UPDATE " . DB_TBL_ITEMS . " SET items_picture='" . $new_picture . "' WHERE items_id=$id");
			 }
		   }
		}
	   	if($_POST['item_new_status']){
		   	foreach($_POST['item_new_status'] as $id => $new_status) {
			 	if ($_POST['item_new_status'][$id] != $_POST['item_old_status'][$id]) {
			   	$count_update++;
			   	$item_updated[$id] = 'updated';
			   	go_set_item_status($id, $new_status);
			 	}
		   	}
		}
	   	if($_POST['item_new_tax']){
		   	foreach($_POST['item_new_tax'] as $id => $new_tax_id) {
			 	if ($_POST['item_new_tax'][$id] != $_POST['item_old_tax'][$id]) {
			   	$count_update++;
			   	$item_updated[$id] = 'updated';
			   	go_db_query("UPDATE " . DB_TBL_ITEMS . " SET items_tax_class_id=$new_tax_id WHERE items_id=$id");
			 	}
		   	}
		}
     $count_item = array_count_values($item_updated);
     if ($count_item['updated'] > 0) $messageStack->add($count_item['updated'].' '.TEXT_ITEMS_UPDATED . " $count_update " . TEXT_QTY_UPDATED, 'success');
     break;
     case 'calcul' :
      if ($_POST['spec_price']) $preview_global_price = 'true';
     break;
 } 
     if($info_back && $info_back!="-") {
       $infoback = explode('-',$info_back);
       $sort_by = $infoback[0];
       $page =  $infoback[1];
       $current_category_id = $infoback[2];
       $row_by_page = $infoback[3];
	   $producer = $infoback[4];
     } 
   $row_bypage_array = array(array());
   for ($i = 10; $i <=300 ; $i=$i+10) {
      $row_bypage_array[] = array('id' => $i,
                                  'text' => $i);
   }
##// Let's start displaying page with forms .$items['items_id'].
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<script language="javascript" src="load_this/menu.js"></script>
<script language="javascript" src="load_this/general.js"></script>
<link rel="stylesheet" type="text/css" href="load_this/style.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php require(FOLDER_RELATIV_INCLUDES . 'load_bigware_9.php'); ?>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td width="<?php echo FRAME_WIDTH; ?>" valign="top"></td>
<!-- body_text //-->
<td width="100%" valign="top">
  <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td>
         <table border="0" width="100%" cellspacing="0" cellpadding="0">
            <tr>
             <td class="pageGeneralsign" colspan="3" valign="top"><?php echo ABOVE_TITLE; ?></td></tr>
		 </table></td></tr>
      <tr><td align="center">
		   <table width="90%" cellspacing="0" cellpadding="0" border="1" bgcolor="#F3F9FB" bordercolor="#D1E7EF" height="100"><tr align="center"><td valign="middle">
				<table width="100%" cellspacing="0" cellpadding="0" border="0">
					<tr><td height="5"></td></tr>
					<tr align="center">
						<td class="smalltext"><?php echo go_fetch_form('row_by_page', 'main_bigware_99.php', '', 'get'); echo go_fetch_hidden_field( 'producer', $producer); echo go_fetch_hidden_field( 'bigPfad', $current_category_id);?></td>
						<td class="smallText"><?php echo TEXT_MAXI_ROW_BY_PAGE . '&nbsp;&nbsp;' . go_fetch_pull_down_menu('row_by_page', $row_bypage_array, $row_by_page, 'onChange="this.form.submit();"'); ?></form></td>
						<?php echo go_fetch_form('categorie', 'main_bigware_99.php', '', 'get'); echo go_fetch_hidden_field( 'row_by_page', $row_by_page); echo go_fetch_hidden_field( 'producer', $producer); ?>
						<td class="smallText" align="center" valign="top"><?php echo SHOW_CATEGORIES . '&nbsp;&nbsp;' . go_fetch_pull_down_menu('bigPfad', go_get_category_tree(), $current_category_id, 'onChange="this.form.submit();"'); ?></td></form>
						<?php echo go_fetch_form('producers', 'main_bigware_99.php', '', 'get'); echo go_fetch_hidden_field( 'row_by_page', $row_by_page); echo go_fetch_hidden_field( 'bigPfad', $current_category_id);?>
						<td class="smallText" align="center" valign="top"><?php echo SHOW_PRODUCERS . '&nbsp;&nbsp' . producers_list(); ?></td></form>	
					</tr>
				</table>
				<table width="100%" cellspacing="0" cellpadding="0" border="0">
					<tr align="center">
						<td align="center">
						  	<table border="0" cellspacing="0">
							   <form name="spec_price" <?php echo 'action="' . go_href_link('main_bigware_99.php', go_get_all_get_parameter(array('action', 'info', 'bigID')) . "action=calcul&page=$page&sort_by=$sort_by&bigPfad=$current_category_id&row_by_page=$row_by_page&producer=$producer" , 'NONSSL') . '"'; ?> method="post">
									 <tr>
									   	<td class="smallText"  align="center" valign="middle" nowrap> <?php echo TEXT_INPUT_SPEC_PRICE; ?></td>
									   	<td align="center" valign="middle"> <?php echo go_fetch_inputfeld('spec_price',0,'size="5"'); ?> </td>
									   	<td class="smalltext" align="center" valign="middle"><?php
										 if ($preview_global_price != 'true') {
												echo '&nbsp;&nbsp;' . go_picture_submit('button_preview.gif', PICTURE_PREVIEW, "page=$page&sort_by=$sort_by&bigPfad=$current_category_id&row_by_page=$row_by_page&producer=$producer");
										 } else echo '&nbsp;&nbsp;<a href="' . go_href_link('main_bigware_99.php', "page=$page&sort_by=$sort_by&bigPfad=$current_category_id&row_by_page=$row_by_page&producer=$producer") . '">' . go_picture_button('button_cancel.gif', PICTURE_CANCEL) . '</a>';?></td>
									 	<td class="smalltext" align="center" valign="middle"><?php echo '&nbsp;&nbsp;&nbsp;&nbsp;' . go_fetch_checkbox_field('marge','yes','','no'); echo '&nbsp;' . TEXT_INSERT; ?></td>
									 </tr>
									 <tr>
									   	<td class="smalltext" align="center" valign="middle" colspan="3" nowrap>
											<?php if ($preview_global_price != 'true') {
														 echo TEXT_SPEC_PRICE_INFO1 ;
												  } else echo TEXT_SPEC_PRICE_INFO2;?>
									   	</td>
									 </tr>
								</form>
							</table>
						</td>	
					</tr>
					<tr><td height="5"></td></tr>
				</table>
			</td></tr></table>
			<br>
			<table width="100%" cellspacing="0" cellpadding="0" border="0">
					<tr align="center">
						<form name="update" method="POST" action="<?php echo "$PHP_SELF?action=update&page=$page&sort_by=$sort_by&bigPfad=$current_category_id&row_by_page=$row_by_page&producer=$producer"; ?>">						
						<td align="right" valign="middle">
						<?php echo '</a><a href="' . go_href_link(NAME_OF_FILE_CATEGORIES, 'bigPfad=' . $bigPfad . '&action=new_item') . '">' . go_picture_button('button_new_item.gif', PICTURE_NEW_ITEM) . '</a>&nbsp;&nbsp;';?>
						<?php echo go_picture_submit('button_update.gif', PICTURE_UPDATE, "action=update&bigPfad=$current_category_id&page=$page&sort_by=$sort_by&row_by_page=$row_by_page");?></td>
					</tr>
			</table>
		</td>
      </tr>
	  <tr>
        <td><table border="1" width="100%" cellspacing="0" cellpadding="0" style="border-collapse: collapse" id="AutoNumber1">
          <tr>
            <td valign="top"><table border="1" width="100%" cellspacing="0" cellpadding="2" style="border-collapse: collapse">
              <tr class="tbUPCountData">
                <td class="tbUPDataInside" align="left" valign="middle">
                  <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="tbUPCountData">
                     <td class="tbUPDataInside" align="right" valign="middle">
                     <?php if($display_model)echo "<td class=\"tbUPDataInside\" align=\"center\" valign=\"middle\">"  .DB_TBL_ABOVE_MODEL ."</td>" ;?>
                    </tr>
                  </table>
                </td>
                <td class="tbUPDataInside" align="left" valign="middle">
                  <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="tbUPCountData">
                     <td class="tbUPDataInside" align="right" valign="middle">
                     <?php echo "<td class=\"tbUPDataInside\" align=\"center\" valign=\"middle\">" . DB_TBL_ABOVE_ITEMS . "</td>" ; ?>
                    </tr>
                  </table>
                </td>
                <td class="tbUPDataInside" align="center" valign="middle">
                  <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="tbUPCountData">
                     <td class="tbUPDataInside" align="right" valign="middle">
                     <?php if($display_statut)echo "<td class=\"tbUPDataInside\" align=\"center\" valign=\"middle\">" . DB_TBL_ABOVE_STATUS . "<br>off/on</td>" ; ?>
                    </tr>
                  </table>
                </td>
                <td class="tbUPDataInside" align="center" valign="middle">
                  <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="tbUPCountData">
                     <td class="tbUPDataInside" align="right" valign="middle">
                     <?php if($display_weight)echo "<td class=\"tbUPDataInside\" align=\"center\" valign=\"middle\">" . DB_TBL_ABOVE_WEIGHT . "</td>" ; ?>
                    </tr>
                  </table>
                </td>
                <td class="tbUPDataInside" align="center" valign="middle">
                  <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="tbUPCountData">
                     <td class="tbUPDataInside" align="right" valign="middle">
                     <?php if($display_quantity)echo "<td class=\"tbUPDataInside\" align=\"center\" valign=\"middle\">" . DB_TBL_ABOVE_QUANTITY . "</td>" ; ?>
                    </tr>
                  </table>
                </td>
        				<td class="tbUPDataInside" align="center" valign="middle">
                  <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="tbUPCountData">
                     <td class="tbUPDataInside" align="right" valign="middle">
                     <?php if($display_picture)echo "<td class=\"tbUPDataInside\" align=\"center\" valign=\"middle\">" . DB_TBL_ABOVE_PICTURE . "</td>" ; ?>
                    </tr>
                  </table>
                </td>
        				<td class="tbUPDataInside" align="center" valign="middle">
                  <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="tbUPCountData">
                     <td class="tbUPDataInside" align="right" valign="middle">
                     <?php if($display_producer)echo "<td class=\"tbUPDataInside\" align=\"center\" valign=\"middle\">" . DB_TBL_ABOVE_PRODUCERS . "</td>" ; ?>
                    </tr>
                  </table>
                </td>
                <td class="tbUPDataInside" align="center" valign="middle">
				<?php 
				echo  DB_TBL_ABOVE_PRICE ; 
				$attendees_group_query2 = go_db_query("select distinct attendees_group_name from attendees_groups where attendees_group_id != '" . 0 . "' order by attendees_group_id");
    			while ($attendees_group2 = go_db_fetch_array($attendees_group_query2)) {
					 if (go_db_num_rows($attendees_group_query2) > 0) {
						echo "<td class=\"tbUPDataInside\" align=\"center\" valign=\"middle\">" . $attendees_group2['attendees_group_name'] ."</td>";
				}
				}
				?> 
				<td class="tbUPDataInside" align="center" valign="middle">
                <?php if($display_tax)echo DB_TBL_ABOVE_TAX  ; ?> </td>
                <td class="tbUPDataInside" align="center" valign="middle"></td>
                <td class="tbUPDataInside" align="center" valign="middle"></td>
              </tr>
          <tr class="datatableRow">
<?php 
     $specials_array = array();
     $specials_query = go_db_query("select p.items_id from " . DB_TBL_ITEMS . " p, " . DB_TBL_SPECIALS . " s where s.items_id = p.items_id");
     while ($specials = go_db_fetch_array($specials_query)) {
       $specials_array[] = $specials['items_id'];
     } 
     if ($sort_by && !preg_match('/order by/',$sort_by)) $sort_by = 'order by '.$sort_by ; 
     $origin = 'main_bigware_99.php'."?info_back=$sort_by-$page-$current_category_id-$row_by_page-$producer"; 
     $split_page = $page;
     if ($split_page > 1) $rows = $split_page * MAX_SHOW_ROW_BY_PAGE - MAX_SHOW_ROW_BY_PAGE; 
  if ($current_category_id == 0){
  	if($producer){  
    	$items_query_raw = "select p.items_id, p.items_percentage, p.items_picture, p.items_model, pd.items_name, p.items_status, p.items_weight, p.items_quantity, p.producers_id, p.items_price, p.items_tax_class_id from  " . DB_TBL_ITEMS . " p, " . DB_TBL_ITEMS_DESCRIPTION .  " pd where p.items_id = pd.items_id and pd.language_id = '$languages_id' and p.producers_id = " . $producer . " ORDER BY p.items_model ";
  	}else{
		$items_query_raw = "select p.items_id, p.items_percentage, p.items_picture, p.items_model, pd.items_name, p.items_status, p.items_weight, p.items_quantity, p.producers_id, p.items_price, p.items_tax_class_id from  " . DB_TBL_ITEMS . " p, " . DB_TBL_ITEMS_DESCRIPTION .  " pd where p.items_id = pd.items_id and pd.language_id = '$languages_id' ORDER BY p.items_model ";	
	}
  } else {  
 	if($producer){ 
	 	$items_query_raw = "select p.items_id, p.items_percentage, p.items_picture, p.items_model, pd.items_name, p.items_status, p.items_weight, p.items_quantity, p.producers_id, p.items_price, p.items_tax_class_id from  " . DB_TBL_ITEMS . " p, " . DB_TBL_ITEMS_DESCRIPTION .  " pd, " . DB_TBL_ITEMS_TO_CATEGORIES . " pc where p.items_id = pd.items_id and pd.language_id = '$languages_id' and p.items_id = pc.items_id and pc.categories_id = '" . $current_category_id . "' and p.producers_id = " . $producer . " ORDER BY p.items_model";
  	}else{
		$items_query_raw = "select p.items_id, p.items_percentage, p.items_picture, p.items_model, pd.items_name, p.items_status, p.items_weight, p.items_quantity, p.producers_id, p.items_price, p.items_tax_class_id from  " . DB_TBL_ITEMS . " p, " . DB_TBL_ITEMS_DESCRIPTION .  " pd, " . DB_TBL_ITEMS_TO_CATEGORIES . " pc where p.items_id = pd.items_id and pd.language_id = '$languages_id' and p.items_id = pc.items_id and pc.categories_id = '" . $current_category_id . "' ORDER BY p.items_model ";
	}
  } 
  $items_split = new splitPageResults($split_page, MAX_SHOW_ROW_BY_PAGE, $items_query_raw, $items_query_numrows);
  $items_query = go_db_query($items_query_raw);
  while ($items = go_db_fetch_array($items_query)) {
    $rows++;
    if (strlen($rows) < 2) {
      $rows = '0' . $rows;
    } 
    if ($_POST['spec_price']){
      $flag_spec = 'true' ;
      if (substr($_POST['spec_price'],-1) == '%') {
	  	if($_POST['marge'] && substr($_POST['spec_price'],0,1) != '-'){
			$valeur = (1 - (preg_replace("/%/", "", $_POST['spec_price']) / 100));
			$price = sprintf("%01.2f", round($items['items_price'] / $valeur,2));
		}else{
        	$price = sprintf("%01.2f", round($items['items_price'] + (($spec_price / 100) * $items['items_price']),2));
      	}
	  } else $price = sprintf("%01.2f", round($items['items_price'] + $spec_price,2));
    } else $price = $items['items_price'] ; 
		if($flag_spec){echo '<tr class="tbCountData" onmouseover="'; if($display_tva_over){echo 'display_ttc(\'display\', ' . $price . ', ' . $tax_rate['tax_rate'] . ');';} echo 'this.className=\'tbCountDataOver\';this.style.cursor=\'hand\'" onmouseout="'; if($display_tva_over){echo 'display_ttc(\'delete\');';} echo 'this.className=\'tbCountData\'">'; }else{ echo '<tr class="tbCountData" onmouseover="'; if($display_tva_over){echo 'display_ttc(\'display\', ' . $items['items_price'] . ', ' . $tax_rate['tax_rate'] . ');';} echo 'this.className=\'tbCountDataOver\';this.style.cursor=\'hand\'" onmouseout="'; if($display_tva_over){echo 'display_ttc(\'delete\', \'\', \'\', 0);';} echo 'this.className=\'tbCountData\'">';}
		if($display_model){if($modify_model)echo "<td class=\"smallText\" align=\"center\"><input type=\"text\" size=\"6\" name=\"item_new_model[".$items['items_id']."]\" value=\"".$items['items_model']."\"></td>\n";else echo "<td class=\"smallText\" align=\"left\">" . $items['items_model'] . "</td>\n";}else{ echo "<td class=\"smallText\" align=\"left\">";}
        if($modify_name){ echo "<td class=\"smallText\" align=\"center\">".go_fetch_inputfeld('item_new_name['.$items['items_id'].']',$items['items_name'])."</td>\n";}else echo "<td class=\"smallText\" align=\"left\">".$items['items_name']."</td>\n"; 
		if($display_statut){
			if ($items['items_status'] == '1') {
			 echo "<td class=\"smallText\" align=\"center\"><input  type=\"radio\" name=\"item_new_status[".$items['items_id']."]\" value=\"0\" ><input type=\"radio\" name=\"item_new_status[".$items['items_id']."]\" value=\"1\" checked ></td>\n";
			} else {
			 echo "<td class=\"smallText\" align=\"center\"><input type=\"radio\" style=\"background-color: #EEEEEE\" name=\"item_new_status[".$items['items_id']."]\" value=\"0\" checked ><input type=\"radio\" style=\"background-color: #EEEEEE\" name=\"item_new_status[".$items['items_id']."]\" value=\"1\"></td>\n";
			}
		}else{
			echo "<td class=\"smallText\" align=\"center\"></td>";
		}	
        if($display_weight)echo "<td class=\"smallText\" align=\"center\"><input type=\"text\" size=\"5\" name=\"item_new_weight[".$items['items_id']."]\" value=\"".$items['items_weight']."\"></td>\n";else echo "<td class=\"smallText\" align=\"center\"></td>";
        if($display_quantity)echo "<td class=\"smallText\" align=\"center\"><input type=\"text\" size=\"3\" name=\"item_new_quantity[".$items['items_id']."]\" value=\"".$items['items_quantity']."\"></td>\n";else echo "<td class=\"smallText\" align=\"center\"></td>";
		if($display_picture)echo "<td class=\"smallText\" align=\"center\"><input type=\"text\" size=\"8\" name=\"item_new_picture[".$items['items_id']."]\" value=\"".$items['items_picture']."\"></td>\n";else echo "<td class=\"smallText\" align=\"center\"></td>";
		if($display_producer)echo "<td class=\"smallText\" align=\"center\">".go_fetch_pull_down_menu("item_new_producer[".$items['items_id']."]\"", $producers_array, $items['producers_id'])."</td>\n";else echo "<td class=\"smallText\" align=\"center\"></td>"; 
        if ( in_array($items['items_id'],$specials_array)) {
            echo "<td class=\"smallText\" align=\"center\">&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"text\" size=\"6\" name=\"item_new_price[".$items['items_id']."]\" value=\"".$items['items_price']."\" disabled >&nbsp;<a href=\"".go_href_link (NAME_OF_FILE_SPECIALS, 'sID='.$items['items_id'])."\">". go_picture(FOLDER_RELATIV_ICONS .'change.gif', PICTURE_INSERT) . "</a></td>\n";
        } elseif ($items['items_percentage'] == '0'){
				echo "<td class=\"smallText\" align=\"center\">&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"text\" size=\"6\" name=\"item_new_price[".$items['items_id']."]\" value=\"".$items['items_price']."\" disabled >&nbsp;<a href=\"".go_href_link (NAME_OF_FILE_CATEGORIES, 'bigID='.$items['items_id'].'&bigPfad='.$categories_items[0].'&action=new_item')."\">". go_picture(FOLDER_RELATIV_ICONS .'locked.gif', PICTURE_LOCKED) . "</a></td>\n";
				} else { 
            if ($flag_spec == 'true') {
                   echo "<td class=\"smallText\" align=\"center\">&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"text\" size=\"6\" name=\"item_new_price[".$items['items_id']."]\" ";  echo " value=\"".$price ."\">".go_fetch_checkbox_field('update_price['.$items['items_id'].']','yes','checked','no')."</td>\n";
            } else { echo "<td class=\"smallText\" align=\"center\">&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"text\" size=\"6\" name=\"item_new_price[".$items['items_id']."]\" ";  echo " value=\"".$price ."\">".go_fetch_hidden_field('update_price['.$items['items_id'].']','yes'). "</td>\n";}
        } 
    $attendees_group_query2 = go_db_query("select distinct attendees_group_id, attendees_group_name, attendees_group_discount from attendees_groups where attendees_group_id != '" . 0 . "' order by attendees_group_id");
    $header = false;
    while ($attendees_group = go_db_fetch_array($attendees_group_query2)) {
    if (!$header) {
      $header = true;
		 }
		 if (go_db_num_rows($attendees_group_query2) > 0) {
       $characteristics_query2 = go_db_query("select attendees_group_id, attendees_group_price from " . DB_TBL_ITEMS_GROUPS . " where items_id = '" .$items['items_id']. "' and attendees_group_id = '" . $attendees_group['attendees_group_id'] . "' order by attendees_group_id");
     } else {
         echo "<td class=\"smallText\" align=\"center\"> NI </td>\n";
				 $characteristics2 = array('attendees_group_id' => 'new');
       }
			 if ($characteristics2 = go_db_fetch_array($characteristics_query2)) { 
			  $price2 = $characteristics2['attendees_group_price'];
				if ($price2 >0) {
				echo "<td class=\"smallText\" align=\"center\">". $price2. "</td>\n";
				} else {
				 	echo "<td class=\"smallText\" align=\"center\"> NI </td>\n"; 
		}
	 }
	 } 
	 if($display_tax)
	 {
	 $tax_query = go_db_query("select tax_rates_id, tax_rate, tax_description from " . DB_TBL_TAX_RATES . " order by tax_rate");
	 $tax_string = '<select name="item_new_tax['.$items['items_id'].']">';
	 while($tax = go_db_fetch_array($tax_query)){
		$tax_string .= '<option value="' . $tax['tax_rates_id'] . '"'; 
		if($items['items_tax_class_id']  == $tax['tax_rates_id']) $tax_string .= ' SELECTED';
		$tax_string .= '>' . $tax['tax_description'] . '</option>';
	 }
	 $tax_string .= '</select>';
	 echo "<td class=\"smallText\" align=\"center\">". $tax_string . "</td>\n";
	 } 
    echo "<td class=\"smallText\" align=\"center\"><a href=\"".go_href_link (NAME_OF_FILE_CATEGORIES, 'bigID='.$items['items_id'].'&action=new_item_preview&read=only&sort_by='.$sort_by.'&page='.$split_page.'&origin='.$origin)."\">". go_picture(FOLDER_RELATIV_ICONS .'preview.gif', PICTURE_PREVIEW) ."</a></td>\n"; 
		echo "<td class=\"smallText\" align=\"center\"><a href=\"".go_href_link (NAME_OF_FILE_CATEGORIES, 'bigID='.$items['items_id'].'&bigPfad='.$categories_items[0].'&action=new_item')."\">". go_picture(FOLDER_RELATIV_ICONS .'change.gif', PICTURE_CHANGE) ."</a></td>\n"; 
		if($modify_name) echo go_fetch_hidden_field('item_old_name['.$items['items_id'].'] ',$items['items_name']);
        if($modify_model) echo go_fetch_hidden_field('item_old_model['.$items['items_id'].'] ',$items['items_model']);
		echo go_fetch_hidden_field('item_old_status['.$items['items_id'].']',$items['items_status']);
        echo go_fetch_hidden_field('item_old_quantity['.$items['items_id'].']',$items['items_quantity']);
		echo go_fetch_hidden_field('item_old_picture['.$items['items_id'].']',$items['items_picture']);
        echo go_fetch_hidden_field('item_old_producer['.$items['items_id'].']',$items['producers_id']);
		echo go_fetch_hidden_field('item_old_weight['.$items['items_id'].']',$items['items_weight']);
        echo go_fetch_hidden_field('item_old_price['.$items['items_id'].']',$items['items_price']);
		echo go_fetch_hidden_field('item_old_price2['.$items['items_id'].']',$items['items_price']);
		echo go_fetch_hidden_field('item_old_tax['.$items['items_id'].']',$items['items_tax_class_id']); 
        echo go_fetch_hidden_field('item_old_tax['.$items['items_id'].']',$items['items_tax_class_id']); 
        echo go_fetch_hidden_field( 'row_by_page', $row_by_page);
        echo go_fetch_hidden_field( 'sort_by', $sort_by);
        echo go_fetch_hidden_field( 'page', $split_page);
     }
    echo "</table>\n";
?>
          </td>
        </tr>
       </table></td>
      </tr>
<tr>
<td align="right">
<?php 
		echo '</a><a href="' . go_href_link(NAME_OF_FILE_CATEGORIES, 'bigPfad=' . $bigPfad . '&action=new_item') . '">' . go_picture_button('button_new_item.gif', PICTURE_NEW_ITEM) . '</a>&nbsp;&nbsp;';
	  echo '<a href="javascript:window.print()">' . go_picture_button('button_print.gif', CHANGE) . '</a>&nbsp;&nbsp;';
      echo go_picture_submit('button_update.gif', PICTURE_UPDATE);
      echo '&nbsp;&nbsp;<a href="' . go_href_link('main_bigware_99.php',"row_by_page=$row_by_page") . '">' . go_picture_button('button_cancel.gif', PICTURE_CANCEL) . '</a>';
?></td>
</tr>
</form>
            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
                <td class="smallText" valign="top"><?php echo $items_split->display_count($items_query_numrows, MAX_SHOW_ROW_BY_PAGE, $split_page, TEXT_SHOW_NUMBER_OF_ITEMS);  ?></td>
                <td class="smallText" align="right"><?php echo $items_split->display_links($items_query_numrows, MAX_SHOW_ROW_BY_PAGE, MAX_SHOW_PAGE_LINKS, $split_page, '&bigPfad='. $current_category_id .'&sort_by='.$sort_by . '&row_by_page=' . $row_by_page); ?></td>
            </table></td>
          </tr>
        </table></td>
      </tr>
    </table>
<!-- body_text_eof //-->
<!-- footer //-->
<?php require(FOLDER_RELATIV_INCLUDES . 'load_bigware_7.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(FOLDER_RELATIV_INCLUDES . 'load_bigware_6.php'); ?>
