<?php
/*
  $Id: quick_ad_products.php,v 1.2 2003/06/04 17:44:34 HRB Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com
        
  This version was contributed by Mathieu (contact@mathieueylert.com)

  (http://www.oscommerce-fr.info/forums)

  Copyright (c) 2002 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');

//// Tax Row
    $tax_class_array = array();
    $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']);
    }
	
////Info Row pour le champ fabriquant
	$manufacturers_array = array(array('id' => '0', 'text' => NO_MANUFACTURER));
	$manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");
	while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
		$manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],
		'text' => $manufacturers['manufacturers_name']);
	}


##// Uptade database
  switch ($HTTP_GET_VARS['action']) {
    case 'add' :
		$products_added = 0;
		
		for ($i = 1; $i <= MAX_PRODUCTS; $i++) {
			$valid = false; $product_exist = false;
			if($HTTP_POST_VARS['product_name'][$i]){
				foreach($HTTP_POST_VARS['product_name'][$i] as $id => $product_language_name){	
					if($product_language_name != ''){
						if(!$product_exist){
							if(strrchr($HTTP_POST_VARS['product_image'][$i], '\\'))$image = substr(strrchr(trim(stripslashes($HTTP_POST_VARS['product_image'][$i])), '\\'), 1);else $image = substr(strrchr(trim(stripslashes($HTTP_POST_VARS['product_image'][$i])), '/'), 1);
							tep_db_query("INSERT INTO " . TABLE_PRODUCTS . " (products_quantity, products_model, products_image, products_price, products_weight, products_status, products_tax_class_id, manufacturers_id) VALUES (" . $HTTP_POST_VARS['product_quantity'][$i] . ", '" . $HTTP_POST_VARS['product_model'][$i] . "', '" . $image . "', " . $HTTP_POST_VARS['product_price'][$i] . ", " . $HTTP_POST_VARS['product_weight'][$i] . ", ". $HTTP_POST_VARS['product_status'][$i] . ", " . $HTTP_POST_VARS['product_tax'][$i] . ", " . $HTTP_POST_VARS['product_manufacturer'][$i] . ");");
							$products_id_query = tep_db_query("SELECT products_id from " . TABLE_PRODUCTS . " WHERE products_quantity=" . $HTTP_POST_VARS['product_quantity'][$i] ." and products_model='" . $HTTP_POST_VARS['product_model'][$i] ."' and products_price=" . $HTTP_POST_VARS['product_price'][$i] . " and products_weight=" . $HTTP_POST_VARS['product_weight'][$i] . " and products_image='" . $image . "' and products_status=" . $HTTP_POST_VARS['product_status'][$i] . " and products_tax_class_id=" . $HTTP_POST_VARS['product_tax'][$i] . " and manufacturers_id=" . $HTTP_POST_VARS['product_manufacturer'][$i] . ";");
							$products_id = tep_db_fetch_array($products_id_query);
							tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_CATEGORIES . " VALUES ('" . $products_id['products_id'] . "', '" . $HTTP_POST_VARS['product_categories'][$i] . "');");
						}
						tep_db_query("INSERT INTO " . TABLE_PRODUCTS_DESCRIPTION . " (products_id, language_id, products_name, products_description) VALUES ('" . $products_id['products_id'] . "', '" . $HTTP_POST_VARS['languages'][$i][$id] . "', '" . $product_language_name . "', '" . $HTTP_POST_VARS['product_description'][$i][$id] . "');");
	
						$product_exist = true;
						$valid = true;
					}
				}
			}
			if($valid)$products_added++;
		}
		$messageStack->add($products_added . ' ' . TEXT_PRODUCTS_ADDED , 'success');
    break;
  }

##// Let's start displaying page with forms
?>
<!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>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<script language="javascript">
<!--
var browser_family;
var up = 1;

if (document.all && !document.getElementById)
  browser_family = "dom2";
else if (document.layers)
  browser_family = "ns4";
else if (document.getElementById)
  browser_family = "dom2";
else
  browser_family = "other";

function display_ttc(action, prix, taxe, up){
  if(action == 'display'){
  	if(up != 1)
  	valeur = Math.round((prix + (taxe / 100) * prix) * 100) / 100;
  }else{
  	if(action == 'keyup'){
		valeur = Math.round((parseFloat(prix) + (taxe / 100) * parseFloat(prix)) * 100) / 100;
	}else{
	 valeur = '0';
	}	
  }
  switch (browser_family){
    case 'dom2':
	  document.getElementById('descDiv').innerHTML = 'TTC : '+valeur;
      break;
    case 'ie4':
      document.all.descDiv.innerHTML = 'TTC : '+valeur;
      break;
    case 'ns4':
      document.descDiv.document.descDiv_sub.document.write(valeur);
      document.descDiv.document.descDiv_sub.document.close();
      break;
    case 'other':
      break;
  }
}
-->
</script>

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
        </table></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="pageHeading" colspan="3" valign="top"><?php echo HEADING_TITLE . "<br><br>"; ?></td>
			</tr>
		 </table></td></tr>
      <tr><td align="center">
			<table width="100%" cellspacing="0" cellpadding="0" border="0">
					<tr align="center">
						<form name="add" method="POST" action="<?php echo "$PHP_SELF?action=add"; ?>">
						<td class="smalltext" align="middle"><?php echo WARNING_MESSAGE; ?> </td>
						<?php echo "<td class=\"pageHeading\" align=\"right\">" . '<script language="javascript"><!--
							switch (browser_family)
							{
							case "dom2":
							case "ie4":
							 document.write(\'<div id="descDiv">\');
							 break;
							default:
							 document.write(\'<ilayer id="descDiv"><layer id="descDiv_sub">\');
					   	  	 break;
							}
							-->
							</script>' . "</td>\n"; 
						?>
						<td align="right" valign="middle"><?php echo tep_image_submit('button_update.gif', IMAGE_UPDATE, "action=add");?></td>
					</tr>
			</table>
		</td>
      </tr>
	  <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent" align="left" valign="middle">
                  <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="dataTableHeadingRow">
                     <?php echo "<td class=\"dataTableHeadingContent\" align=\"center\" valign=\"middle\">"  .TABLE_HEADING_MODEL ."</td>"; ?>
                    </tr>
                  </table>
                </td>
                <td class="dataTableHeadingContent" align="middle" valign="middle">
                  <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="dataTableHeadingRow">
                     <?php echo "<td class=\"dataTableHeadingContent\" align=\"center\" valign=\"middle\">"  .TABLE_HEADING_PRODUCTS ."</td>"; ?>
                    </tr>
                  </table>
                </td>
                <td class="dataTableHeadingContent" align="center" valign="middle">
                  <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="dataTableHeadingRow">
                     <?php echo "<td class=\"dataTableHeadingContent\" align=\"center\" valign=\"middle\">"  .TABLE_HEADING_STATUS ."</td>"; ?>
                    </tr>
                  </table>
                </td>
                <td class="dataTableHeadingContent" align="center" valign="middle">
                   <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="dataTableHeadingRow">
                     <?php echo "<td class=\"dataTableHeadingContent\" align=\"center\" valign=\"middle\">"  .TABLE_HEADING_WEIGHT ."</td>"; ?>
                    </tr>
                  </table>
                </td>
                <td class="dataTableHeadingContent" align="center" valign="middle">
                   <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="dataTableHeadingRow">
                     <?php echo "<td class=\"dataTableHeadingContent\" align=\"center\" valign=\"middle\">"  .TABLE_HEADING_QUANTITY ."</td>"; ?>
                    </tr>
                  </table>
                </td>
				<td class="dataTableHeadingContent" align="center" valign="middle">
                   <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="dataTableHeadingRow">
                     <?php echo "<td class=\"dataTableHeadingContent\" align=\"center\" valign=\"middle\">"  .TABLE_HEADING_IMAGE ."</td>"; ?>
                    </tr>
                  </table>
                </td>
				<td class="dataTableHeadingContent" align="center" valign="middle">
                   <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="dataTableHeadingRow">
                     <?php echo "<td class=\"dataTableHeadingContent\" align=\"center\" valign=\"middle\">"  .TABLE_HEADING_MANUFACTURERS ."</td>"; ?>
                    </tr>
                  </table>
                </td>
				<td class="dataTableHeadingContent" align="center" valign="middle">
                   <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="dataTableHeadingRow">
                     <?php echo "<td class=\"dataTableHeadingContent\" align=\"center\" valign=\"middle\">"  .TABLE_HEADING_CATEGORIES ."</td>"; ?>
                    </tr>
                  </table>
                </td>
				<td class="dataTableHeadingContent" align="center" valign="middle">
                   <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="dataTableHeadingRow">
                     <?php echo "<td class=\"dataTableHeadingContent\" align=\"center\" valign=\"middle\">"  .TABLE_HEADING_PRICE ."</td>"; ?>
                    </tr>
                  </table>
                </td>
                <td class="dataTableHeadingContent" align="center" valign="middle">
                   <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="dataTableHeadingRow">
                     <?php echo "<td class=\"dataTableHeadingContent\" align=\"center\" valign=\"middle\">"  .TABLE_HEADING_TAX ."</td>"; ?>
                    </tr>
                  </table>
                </td>
              </tr>
          <tr class="datatableRow">
<?php
  for ($i = 1; $i <= MAX_PRODUCTS; $i++) {
		echo '<tr class="dataTableRow" onmouseover="this.className=\'dataTableRowOver\';this.style.cursor=\'hand\'" onmouseout="'; if(DISPLAY_TVA_OVER == 'true'){echo 'display_ttc(\'delete\');';} echo 'this.className=\'dataTableRow\'">';
		echo "<td class=\"smallText\" align=\"center\"><input type=\"text\" size=\"10\" name=\"product_model[".$i."]\"></td>\n";
        // The name in all languages.
		echo "<td class=\"smallText\" align=\"center\">";
		echo '<table border="0" cellspacing="0" cellpadding="0">';
		$languages_query = tep_db_query("select languages_id, name, image, directory from " . TABLE_LANGUAGES . " order by sort_order ASC");
		while($languages = tep_db_fetch_array($languages_query)){
			echo '<tr class="dataTableRow" onmouseover="this.className=\'dataTableRowOver\';this.style.cursor=\'hand\'" onmouseout="this.className=\'dataTableRow\'"><td class="smallText" align="center">';
			echo "<input type=\"text\" size=\"25\" name=\"product_name[".$i."][".$languages['languages_id']."]\">" . ' ' . tep_image(DIR_WS_CATALOG_LANGUAGES . $languages['directory'] . '/images/' . $languages['image'], $languages['name']) . "    <input type=\"text\" size=\"25\" name=\"product_description[".$i."][".$languages['languages_id']."]\">" . ' ' . tep_image(DIR_WS_CATALOG_LANGUAGES . $languages['directory'] . '/images/' . $languages['image'], $languages['name']);
			echo tep_draw_hidden_field('languages['.$i.']['.$languages['languages_id'] . ']',$languages['languages_id']);
			echo '</td></tr>';
		}
		echo "</table></td>\n";
		
		echo "<td class=\"smallText\" align=\"center\"><input  type=\"radio\" name=\"product_status[".$i."]\" value=\"0\" ><input type=\"radio\" name=\"product_status[".$i."]\" value=\"1\" checked ></td>\n";
        echo "<td class=\"smallText\" align=\"center\"><input type=\"text\" size=\"4\" name=\"product_weight[".$i."]\" value=0.00></td>\n";
        echo "<td class=\"smallText\" align=\"center\"><input type=\"text\" size=\"2\" name=\"product_quantity[".$i."]\" value=0></td>\n";
		echo "<td class=\"smallText\" align=\"center\">" . tep_draw_file_field('product_image['.$i.']') . " </td>\n";
		echo "<td class=\"smallText\" align=\"center\">" . tep_draw_pull_down_menu("product_manufacturer[".$i."]", $manufacturers_array, $products['manufacturers_id'])."</td>\n";
		echo "<td class=\"smallText\" align=\"center\">" . tep_draw_pull_down_menu("product_categories[".$i."]", tep_get_category_tree());
		echo "<td class=\"smallText\" align=\"center\">    <input type=\"text\" size=\"6\" name=\"product_price[".$i."]\" value=0.0000 "; if(DISPLAY_TVA_UP == 'true'){ echo "onKeyUp=\"display_ttc('keyup', this.value" . ", " . ALL_INCLUDED_TAX_VALUE . ", 1);\"";} echo "></td>\n";
		echo "<td class=\"smallText\" align=\"center\">" . tep_draw_pull_down_menu("product_tax[".$i."]", $tax_class_array, $products['products_tax_class_id'])."</td>\n";
  }
  echo "</table>\n";
?>
	</td>
  </tr>
  <tr>
	 <td align="right">
		<?php
				echo tep_image_submit('button_update.gif', IMAGE_UPDATE);
				echo '  <a href="' . tep_href_link(FILENAME_QUICK_ADD_PRODUCTS) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
		?>
	 </td>
  </tr>
  </form>
        </table>
      </tr>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->
  </tr>
</table>

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
