Jump to content

[SOLVED] Help With Associating Model Number With Database


gaspower

Recommended Posts

Hello,

 

Below I have included a portion of code from a file that takes a csv file that contains a polygon coordinates and part number (199,31,282,32,269,115,205,114,ABC10136). The problem is that I have changed the parts numbers from C10136 to ABC10136. When using prior C10136, it would import with no errors, now that I am trying to import with ABC10136, I get the error product with such a model does not exist?? Can someone please guide me to where I can change in the code so I can use ABC10136.

 

Thank you JR

 

require('includes/application_top.php');

  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();

  $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');

  if (tep_not_null($action)) {
    switch ($action) {
      case 'bulk_insert':
                   $target = "temp/";
                   $target = $target . basename($_FILES['uploaded']['name']) ;
			   $file_name = basename($_FILES['uploaded']['name']);
                   $ok=1;
                   if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
                   {
				$messageStack->add("The file ".$file_name . " has been uploaded", 'error');
				$image_maps_id = $HTTP_GET_VARS['iID'];
				$handle = fopen($target,"r");
				$num =0;
				while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
/*
					$top_right_x = $data[0];
					if(!$top_right_x)
						break;
					$top_right_y = $data[1];
					$bottom_left_x = $data[2];
					$bottom_left_y = $data[3];
					$product_model = $data[4];
*/
// new upload should take it as follows
//                        $map_type = $data[0];
                        $coord1_x = $data[0];
                        $coord1_y = $data[1];
                        $coord2_x = $data[2];
                        $coord2_y = $data[3];
                        $coord3_x = $data[4];
                        $coord3_y = $data[5];
                        $coord4_x = $data[6];
                        $coord4_y = $data[7];
                        $coord5_x = $data[8];
                        $coord5_y = $data[9];
                        $coord6_x = $data[10];
                        $coord6_y = $data[11];
					$product_model = $data[12];
// check for rectangle will be the fifth point wil not be a number
// check for circle will be the fourth point will not be a number
// otherwise it will be a polygon .. check for 0,0 point.
					if(!is_numeric($data[3])) // circle
					{
					 $map_type = 3;
					 $product_model = $data[3];
					 $coord2_y = -999999;
					 $coord3_x = -999999;
					 $coord3_y = -999999;
					 $coord4_x = -999999;
					 $coord4_y = -999999;
					 $coord5_x = -999999;
					 $coord5_y = -999999;
					 $coord6_x = -999999;
					 $coord6_y = -999999;	
					 echo "<br> this is a circle";	 
					}	
					elseif(!is_numeric($data[4]))
					{
					 $map_type =1;
					 $product_model = $data[4];
					 $coord3_x = -999999;
					 $coord3_y = -999999;
					 $coord4_x = -999999;
					 $coord4_y = -999999;
					 $coord5_x = -999999;
					 $coord5_y = -999999;
					 $coord6_x = -999999;
					 $coord6_y = -999999;						 
					 echo "<br> this is a rectagle";
					}
					else // polygon
					{
					  $map_type =2;
					if(!is_numeric($data[6]))  // has 3 points
					 {
					 $product_model = $data[6];
					 $coord4_x = -999999;
					 $coord4_y = -999999;
					 $coord5_x = -999999;
					 $coord5_y = -999999;
					 $coord6_x = -999999;
					 $coord6_y = -999999;						 
					 }
					 if(!is_numeric($data[8])) // has 4 points
					 {
					  $product_model = $data[8];
					  $coord5_x = -999999;
					  $coord5_y = -999999;
					  $coord6_x = -999999;
					  $coord6_y = -999999;						   						 
					 }
					 elseif(!is_numeric($data[10])) // has 5 points
					 {
					  $product_model = $data[10];
					  $coord6_x = -999999;
					  $coord6_y = -999999;							 
					 }
					 elseif(!is_numeric($data[12])) // has 6 points
					 {
					  $product_model = $data[12];						 
					 }					
					 echo "<br> this is a polygon";
					}						                        					
				  /* find the products_id */
				 $products_id_q = tep_db_query("select products_id from ". TABLE_PRODUCTS . " where products_model = '". $product_model ."'");
				 //$products_id_arr_chk = tep_db_fetch_array($products_id_q);					 
				if(tep_db_num_rows($products_id_q) == 0)
				{
					$messageStack->add("Product with such a product model: ". $product_model . " does not exist. Please check !!", 'error');
				}
				else
				 while($products_id_arr = tep_db_fetch_array($products_id_q))
					{
					 $products_id = $products_id_arr['products_id'];
					 //check if the value exists
//						 $image_coord_exist = tep_db_query('select image_maps_id from '.TABLE_IMAGE_MAPS_TO_PRODUCTS . ' where image_maps_id = '. $image_maps_id .' and products_id = '. $products_id . ' and top_right_x = ' . $top_right_x . ' and top_right_y = ' . $top_right_y . ' and bottom_left_x = '. $bottom_left_x . ' and bottom_left_y = '. $bottom_left_y);
// modified code for the value existing check.. 
					 $image_coord_exist = tep_db_query('select image_maps_id from '.TABLE_IMAGE_MAPS_TO_PRODUCTS . ' where map_type = '. $map_type .' and coord1_x = '. $coord1_x . ' and coord1_y = ' . $coord1_y .' and coord2_x = '. $coord2_x . ' and coord2_y = ' . $coord2_y .' and coord3_x = '. $coord3_x . ' and coord3_y = ' . $coord3_y .' and coord4_x = '. $coord4_x . ' and coord4_y = ' . $coord4_y .' and coord5_x = '. $coord5_x . ' and coord5_y = ' . $coord5_y .' and coord6_x = '. $coord6_x . ' and coord6_y = ' . $coord6_y . ' and image_maps_id = '. $image_maps_id .' and products_id = '. $products_id);

					 $image_coord_exist_arr = tep_db_fetch_array($image_coord_exist);
					 if(!$image_coord_exist_arr) // insert if the coord doesnot exist
						{
						 // find the new coordinate id
						 $image_map_coord_id_count_q = tep_db_query("select count(image_map_coord_id) val from ". TABLE_IMAGE_MAPS_TO_PRODUCTS );
						 $image_map_coord_id_count_v = tep_db_fetch_array($image_map_coord_id_count_q);
						 if($image_map_coord_id_count_v['val'] == 0)
							{
						   $image_map_coord_id = 1;
							}
						 else
							{
						 $image_map_coord_id_q = tep_db_query("select max(image_map_coord_id) val from ". TABLE_IMAGE_MAPS_TO_PRODUCTS );
						 $image_map_coord_id_v = tep_db_fetch_array($image_map_coord_id_q);
						 $image_map_coord_id = (int)$image_map_coord_id_v['val'] + 1;
						}
						echo $map_type;
						 $sql_data_array = array('image_map_coord_id' => $image_map_coord_id,
												 'image_maps_id' =>$image_maps_id,
												 'products_id' => $products_id,
/*													 'top_right_x' =>  $top_right_x,
												 'top_right_y' =>  $top_right_y,
												 'bottom_left_x' =>  $bottom_left_x,
												 'bottom_left_y' =>  $bottom_left_y, */
												 'map_type' => $map_type,
												 'coord1_x' => $coord1_x,
												 'coord1_y' => $coord1_y,
												 'coord2_x' => $coord2_x,
												 'coord2_y' => $coord2_y,
												 'coord3_x' => $coord3_x,
												 'coord3_y' => $coord3_y,
												 'coord4_x' => $coord4_x,
												 'coord4_y' => $coord4_y,
												 'coord5_x' => $coord5_x,
												 'coord5_y' => $coord5_y,
												 'coord6_x' => $coord6_x,
												 'coord6_y' => $coord6_y,
												 'status' => 1,		 
												 'coord_date_added' => 'now()',
												 'coord_last_modified' => 'now()'
												  );
						  tep_db_perform(TABLE_IMAGE_MAPS_TO_PRODUCTS, $sql_data_array); 
						  $num ++;
						}
						else
						{
                              $messageStack->add("Product with such a product model: ". $product_model . " already exists. Please check !!", 'error');
						}
					}
				}
				fclose($handle);
								   }
                   else {
				$messageStack->add("Sorry, there was a problem uploading your file.", 'error');
                   }
			   break;
      case 'setflag':
        if ( ($HTTP_GET_VARS['flag'] == '0') || ($HTTP_GET_VARS['flag'] == '1') ) {
          if (isset($HTTP_GET_VARS['pID'])) {
            tep_set_coord_status($HTTP_GET_VARS['pID'], $HTTP_GET_VARS['flag'],$HTTP_GET_VARS['iID']);
          }
        }
        tep_redirect(tep_href_link(FILENAME_IMAGE_MAPS, 'iID=' . $HTTP_GET_VARS['iID'] . '&pID=' . $HTTP_GET_VARS['pID']. '&type=coord'));
        break;
      case 'insert_image_map':
      case 'update_image_map':
        if (isset($HTTP_POST_VARS['iID'])) 
	{
	   $image_maps_id = tep_db_prepare_input($HTTP_POST_VARS['iID']);	   
	   $image_maps_id = $HTTP_POST_VARS['iID'];
	}
	elseif(isset($HTTP_GET_VARS['iID']))
	{
	   $image_maps_id = tep_db_prepare_input($HTTP_GET_VARS['iID']);	   
	   $image_maps_id = $HTTP_GET_VARS['iID'];
	}

        if($action == 'insert_image_map')
	{
	  $image_map_q = tep_db_query("select max(image_maps_id) val from ". TABLE_IMAGE_MAPS );
	  $image_map_v = tep_db_fetch_array($image_map_q);
	  $image_maps_id = (int)$image_map_v['val'] + 1;
	}
        $sort_order = tep_db_prepare_input($HTTP_POST_VARS['sort_order']);

        $sql_data_array = array('sort_order' => $sort_order);

        if ($action == 'insert_image_map') {
          $insert_sql_data = array('image_maps_id' => $image_maps_id,
		                       'parent_id' => '0',
                                   'date_added' => 'now()');

          $sql_data_array = array_merge($sql_data_array, $insert_sql_data);

          tep_db_perform(TABLE_IMAGE_MAPS, $sql_data_array);
        } elseif ($action == 'update_image_map') {
          $update_sql_data = array('last_modified' => 'now()');

          $sql_data_array = array_merge($sql_data_array, $update_sql_data);

          tep_db_perform(TABLE_IMAGE_MAPS, $sql_data_array, 'update', "image_maps_id = '" . (int)$image_maps_id . "'");
        }

        $languages = tep_get_languages();
        for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
	  $sql_data_array =array();
	  $insert_sql_data = array();
          $image_maps_title_array = $HTTP_POST_VARS['image_maps_title'];

          $language_id = $languages[$i]['id'];

          $sql_data_array = array('image_maps_title' => tep_db_prepare_input($image_maps_title_array[$language_id]));
//tep_db_query("the new value is ".tep_db_prepare_input($image_maps_title_array[$language_id]));
          if ($action == 'insert_image_map') {
            $insert_sql_data = array('image_maps_id' => $image_maps_id,
                                     'language_id' => $languages[$i]['id']);

            $sql_data_array = array_merge($sql_data_array, $insert_sql_data);

            tep_db_perform(TABLE_IMAGE_MAPS_DESCRIPTION, $sql_data_array);
          } elseif ($action == 'update_image_map') {
            tep_db_perform(TABLE_IMAGE_MAPS_DESCRIPTION, $sql_data_array, 'update', "image_maps_id = '" . (int)$image_maps_id . "' and language_id = '" . (int)$language_id . "'");
          }
        }

        $maps_main_image = new upload('maps_main_image');
        $maps_main_image->set_destination(DIR_FS_CATALOG_IMAGES);

        if ($maps_main_image->parse() && $maps_main_image->save()) {
          tep_db_query("update " . TABLE_IMAGE_MAPS . " set maps_main_image = '" . tep_db_input($maps_main_image->filename) . "' where image_maps_id = '" . (int)$image_maps_id . "'");
        }
        tep_redirect(tep_href_link(FILENAME_IMAGE_MAPS),'type=IM');
        break;
      case 'delete_image_map_confirm':
        if (isset($HTTP_POST_VARS['iID'])) $image_maps_id = tep_db_prepare_input($HTTP_POST_VARS['iID']);
        if (isset($HTTP_GET_VARS['iID'])) $image_maps_id = tep_db_prepare_input($HTTP_GET_VARS['iID']);
	if($image_maps_id)
	{
//			 tep_db_query("get something from somwhere ". $image_maps_id);
  	    tep_remove_image_map($image_maps_id);
	}
        tep_redirect(tep_href_link(FILENAME_IMAGE_MAPS),'type=IM');
        break;
      case 'delete_coord_confirm':
        if (isset($HTTP_GET_VARS['pID'])) {		   
  		   $coord_id =  tep_db_prepare_input($HTTP_GET_VARS['pID']);
           tep_db_query("delete from " . TABLE_IMAGE_MAPS_TO_PRODUCTS . " where image_map_coord_id = '" . (int)$coord_id . "'");
       }
           tep_redirect(tep_href_link(FILENAME_IMAGE_MAPS, 'iID=' . $HTTP_GET_VARS['iID']. '&type=coord'));
        break;
      
      case 'insert_coord':
      case 'update_coord':
//        if (isset($HTTP_POST_VARS['right_top_x']) || isset($HTTP_POST_VARS['right_top_y']) || isset($HTTP_POST_VARS['left_bottom_x']) || isset($HTTP_POST_VARS['left_bottom_y'])) {
//          $action = 'new_coord';
  //      } else {
          if (isset($HTTP_GET_VARS['pID'])) $image_map_coord_id = tep_db_prepare_input($HTTP_GET_VARS['pID']);
	  if (isset($HTTP_GET_VARS['iID'])) $image_maps_id = tep_db_prepare_input($HTTP_GET_VARS['iID']);
//		  tep_db_query("select soemthign from somewhere ".$image_maps_id);
          $sql_data_array = array('image_maps_id' =>$image_maps_id,
			                      'products_id' => tep_db_prepare_input($HTTP_POST_VARS['products_id']),
/*			                      'top_right_x' =>  tep_db_prepare_input($HTTP_POST_VARS['top_right_x']),
		                      'top_right_y' =>  tep_db_prepare_input($HTTP_POST_VARS['top_right_y']),
		                      'bottom_left_x' =>  tep_db_prepare_input($HTTP_POST_VARS['bottom_left_x']),
		                      'bottom_left_y' =>  tep_db_prepare_input($HTTP_POST_VARS['bottom_left_y']),*/
							  'map_type' => tep_db_prepare_input($HTTP_POST_VARS['map_type']),
							  'coord1_x' => tep_db_prepare_input($HTTP_POST_VARS['coord1_x']),
							  'coord1_y' => tep_db_prepare_input($HTTP_POST_VARS['coord1_y']),
							  'coord2_x' => tep_db_prepare_input($HTTP_POST_VARS['coord2_x']),
							  'coord2_y' => tep_db_prepare_input($HTTP_POST_VARS['coord2_y']),
							  'coord3_x' => tep_db_prepare_input($HTTP_POST_VARS['coord3_x']),
							  'coord3_y' => tep_db_prepare_input($HTTP_POST_VARS['coord3_y']),
							  'coord4_x' => tep_db_prepare_input($HTTP_POST_VARS['coord4_x']),
							  'coord4_y' => tep_db_prepare_input($HTTP_POST_VARS['coord4_y']),
							  'coord5_x' => tep_db_prepare_input($HTTP_POST_VARS['coord5_x']),
							  'coord5_y' => tep_db_prepare_input($HTTP_POST_VARS['coord5_y']),
							  'coord6_x' => tep_db_prepare_input($HTTP_POST_VARS['coord6_x']),
							  'coord6_y' => tep_db_prepare_input($HTTP_POST_VARS['coord6_y']),
		                      'status' => tep_db_prepare_input($HTTP_POST_VARS['products_status'])
		                      );
          if($action == 'insert_coord')
	  {
	   $image_map_coord_id_q = tep_db_query("select max(image_map_coord_id) val from ". TABLE_IMAGE_MAPS_TO_PRODUCTS );
	   $image_map_coord_id_v = tep_db_fetch_array($image_map_coord_id_q);
	   $image_map_coord_id = (int)$image_map_coord_id_v['val'] + 1;
	  }
          if ($action == 'insert_coord') {
            $insert_sql_data = array( 'image_map_coord_id' => $image_map_coord_id,
			                      'coord_date_added' => 'now()');
            $sql_data_array = array_merge($sql_data_array, $insert_sql_data);
            tep_db_perform(TABLE_IMAGE_MAPS_TO_PRODUCTS, $sql_data_array);
          } elseif ($action == 'update_coord') {
            $update_sql_data = array('coord_last_modified' => 'now()');
            $sql_data_array = array_merge($sql_data_array, $update_sql_data);
            tep_db_perform(TABLE_IMAGE_MAPS_TO_PRODUCTS, $sql_data_array, 'update', "image_map_coord_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and image_maps_id = '" . (int)$HTTP_GET_VARS['iID'] . "'");
          }         
          tep_redirect(tep_href_link(FILENAME_IMAGE_MAPS, 'iID=' . $image_maps_id . '&pID=' . $image_map_coord_id.'&type=coord'));
//        }
        break;     
    }
  }

// check if the catalog image directory exists
  if (is_dir(DIR_FS_CATALOG_IMAGES)) {
    if (!is_writeable(DIR_FS_CATALOG_IMAGES)) $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_NOT_WRITEABLE, 'error');
  } else {
    $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_DOES_NOT_EXIST, 'error');
  }
?>
<!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">
<script language="javascript" src="includes/general.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onload="SetFocus();">
<div id="spiffycalendar" class="text"></div>
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- 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">
<?php
  if ($action == 'new_coord') {/*
	'image_maps_id' => tep_db_prepare_input($HTTP_POST_VARS['iID']),
			                      'products_id' => tep_db_prepare_input($HTTP_POST_VARS['products_id']),
		                      'right_top_x' =>  tep_db_prepare_input($HTTP_POST_VARS['right_top_x']),
		                      'right_top_y' =>  tep_db_prepare_input($HTTP_POST_VARS['right_top_y']),
		                      'left_bottom_x' =>  tep_db_prepare_input($HTTP_POST_VARS['left_bottom_x']),
		                      'left_bottom_y' =>  tep_db_prepare_input($HTTP_POST_VARS['left_bottom_y']),
		                      'status' =>  '1'*/
    $parameters = array(
	               'products_id' => '',
/*                       'top_right_x' => '',
                       'top_right_y' => '',
                       'bottom_left_x' => '',
                       'bottom_left_y' => '',*/
				   'map_type' =>'',
				   'coord1_x' =>'',
				   'coord1_y' =>'',
				   'coord2_x' =>'',
				   'coord2_y' =>'',
				   'coord3_x' =>'',
				   'coord3_y' =>'',
				   'coord4_x' =>'',
				   'coord4_y' =>'',
				   'coord5_x' =>'',
				   'coord5_y' =>'',
				   'coord6_x' =>'',
				   'coord6_y' =>'',
                       'status' => '',
                       'coord_date_added' => '',
                       'coord_last_modified' => '',
                       'image_maps_id' => '');

    $pInfo = new objectInfo($parameters);

    if (isset($HTTP_GET_VARS['pID']) && empty($HTTP_POST_VARS)) {
	$coords_query = tep_db_query( "select im2p.image_map_coord_id, im2p.image_maps_id, im2p.products_id, im2p.map_type, im2p.coord1_x,im2p.coord1_y, im2p.coord2_x,im2p.coord2_y, im2p.coord3_x,im2p.coord3_y, im2p.coord4_x,im2p.coord4_y, im2p.coord5_x,im2p.coord5_y, im2p.coord6_x,im2p.coord6_y, im2p.status,im2p.coord_date_added, im2p.coord_last_modified, imd.image_maps_title,p.products_model from ". TABLE_IMAGE_MAPS_TO_PRODUCTS ." im2p, " . TABLE_IMAGE_MAPS_DESCRIPTION . " imd, ". TABLE_PRODUCTS . " p where p.products_id = im2p.products_id and imd.image_maps_id = im2p.image_maps_id and language_id = '". (int)$languages_id . "' and im2p.image_map_coord_id = " . (int)$HTTP_GET_VARS['pID']);
        $coord = tep_db_fetch_array($coords_query);

        $pInfo->objectInfo($coord);
    } elseif (tep_not_null($HTTP_POST_VARS)) {
      $pInfo->objectInfo($HTTP_POST_VARS);
    }

    $languages = tep_get_languages();

    if (!isset($pInfo->products_status)) $pInfo->products_status = '1';
    switch ($pInfo->products_status) {
      case '0': $in_status = false; $out_status = true; break;
      case '1':
      default: $in_status = true; $out_status = false;
    }
?>

  <?php echo tep_draw_form('new_coord', FILENAME_IMAGE_MAPS, 'iID=' . $HTTP_GET_VARS['iID'] . (isset($HTTP_GET_VARS['pID']) ? '&pID=' . $HTTP_GET_VARS['pID'] : '') . '&action=new_coord_preview', 'post', 'enctype="multipart/form-data"'); ?>
    <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo sprintf(TEXT_NEW_PRODUCT_COORD, "in ".$pInfo->image_maps_title); ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></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">
          <tr>
            <td class="main" align="right"><?php echo TEXT_COORD_STATUS; ?></td>
            <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_radio_field('products_status', '1', $in_status) . ' ' . TEXT_COORD_AVAILABLE . ' ' . tep_draw_radio_field('products_status', '0', $out_status) . ' ' . TEXT_COORD_NOT_AVAILABLE; ?></td>
          </tr>			
          <tr>
            <td colspan="1"><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td>
          </tr>
          <tr>
            <td class="main" align="right"><?php echo TEXT_COORD_PRODUCT_SELECT; ?> </td>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.