<?php
/*
  www.oscGold.com (C) Kamelia-Net Jacek Krysiak
  modul oscGold wer 4.0
*/
?>

<?php
if ($messageStack->size('wishlist') > 0) {
  echo $messageStack->output('wishlist');
}
$szerokosc = ALLPROD_IMAGE_WIDTH+10;
$wysokosc = ALLPROD_IMAGE_HEIGHT+10;

echo tep_draw_form('wishlist_form', tep_href_link(FILENAME_WISHLIST_PUBLIC, 'public_id='.$public_id));
echo '<input type="hidden" value="" name="przycisk" id="przycisk">';

?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">

  <!-- Naglowek BOF -->
  <tr>
    <td>
      <?php
      $info_box_contents = array();
      $info_box_contents[] = array('text' => $customer['customers_firstname'] . sprintf(HEADING_TITLE2_WISHLIST));
      new contentBoxHeading($info_box_contents);
      ?>
    </td>
  </tr>
  <tr>
    <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '1'); ?></td>
  </tr>
  <!-- Naglowek EOF -->


  <?php
  /*******************************************************************
  ****** QUERY THE DATABASE FOR THE CUSTOMERS WISHLIST PRODUCTS ******
  *******************************************************************/

  $wishlist_query_raw = "select * from " . TABLE_WISHLIST . " where customers_id = '" . $public_id . "'";
  $wishlist_split = new splitPageResults($wishlist_query_raw, MAX_DISPLAY_WISHLIST_PRODUCTS);
  $wishlist_query = tep_db_query($wishlist_split->sql_query);
  ?>
  <!-- customer_wishlist //-->
  <?php

  if (tep_db_num_rows($wishlist_query)) {

    if ($wishlist_split > 0 && (PREV_NEXT_BAR_LOCATION == '1' || PREV_NEXT_BAR_LOCATION == '3')) {
      ?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '5'); ?></td>
      </tr>
      <tr>
        <td>
          <table border="0" width="100%" cellspacing="0" cellpadding="2">
            <tr>
              <td class="smallText"><?php echo $wishlist_split->display_count(TEXT_DISPLAY_NUMBER_OF_WISHLIST); ?></td>
              <td align="right" class="smallText"><?php echo TEXT_RESULT_PAGE . ' ' . $wishlist_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>
            </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '5'); ?></td>
      </tr>
      <?php
    }
    ?>

    <tr>
      <td>

        <table border="0" width="100%" cellspacing="0" cellpadding="3" class="productListing">
          <tr>
            <td class="productListing-heading"><?php echo BOX_TEXT_PRODUCT; ?></td>
            <td class="productListing-heading" align="right"><?php echo BOX_TEXT_SELECT; ?></td>
          </tr>

          <?php
          /*******************************************************************
          ***** LOOP THROUGH EACH PRODUCT ID TO DISPLAY IN THE WISHLIST ******
          *******************************************************************/
          $i = 0;
          while ($wishlist = tep_db_fetch_array($wishlist_query)) {
            $wishlist_id = tep_get_prid($wishlist['products_id']);

            $products_query = tep_db_query("select pd.products_id, pd.products_name, pd.products_description, p.products_image, p.products_price, p.products_status, p.products_tax_class_id, p.products_quantity, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from (" . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd) left join " . TABLE_SPECIALS . " s on (p.products_id = s.products_id) where pd.products_id = '" . $wishlist_id . "' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' order by products_name");
            $products = tep_db_fetch_array($products_query);

            if (($i/2) == floor($i/2)) {
              $class = "productListing-even";
            } else {
              $class = "productListing-odd";
            }

            ?>
            <tr class="<?php echo $class; ?>">
              <td colspan="2">
                <table width="100%" border="0" cellpadding="0" cellspacing="3">
                  <tr>
                    <td rowspan="2" valign="top" class="productListing-data" align="left" width="<?php echo $szerokosc; ?>">
                      <?php
                      echo tep_image(DIR_WS_IMAGES . $products['products_image'], $products['products_name'], ALLPROD_IMAGE_WIDTH, ALLPROD_IMAGE_HEIGHT,'',$wysokosc,$szerokosc,$products['products_id'],tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $wishlist['products_id'], 'NONSSL'),true);
                      ?>
                    </td>
                    <td valign="top" class="productListing-data" align="left" height="40">
                      <b><a href="<?php echo tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $wishlist['products_id'], 'NONSSL'); ?>"><?php echo $products['products_name']; ?></a></b>
                      <?php

                      /*******************************************************************
                      ******** THIS IS THE WISHLIST CODE FOR PRODUCT ATTRIBUTES  *********
                      *******************************************************************/
                      $attributes_addon_price = 0;

                      // Now get and populate product attributes
                      $att_name = "";
                      $wishlist_products_attributes_query = tep_db_query("select products_options_id as po, products_options_value_id as pov from " . TABLE_WISHLIST_ATTRIBUTES . " where customers_id='" . $public_id . "' and products_id = '" . $wishlist['products_id'] . "'");
                      while ($wishlist_products_attributes = tep_db_fetch_array($wishlist_products_attributes_query)) {
                        // We now populate $id[] hidden form field with product attributes
                        echo tep_draw_hidden_field('id['.$wishlist['products_id'].']['.$wishlist_products_attributes['po'].']', $wishlist_products_attributes['pov']);
                        $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix
                                      from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
                                      where pa.products_id = '" . $wishlist_id . "'
                                       and pa.options_id = '" . $wishlist_products_attributes['po'] . "'
                                       and pa.options_id = popt.products_options_id
                                       and pa.options_values_id = '" . $wishlist_products_attributes['pov'] . "'
                                       and pa.options_values_id = poval.products_options_values_id
                                       and popt.language_id = '" . $languages_id . "'
                                       and poval.language_id = '" . $languages_id . "'");
                        $attributes_values = tep_db_fetch_array($attributes);
                        if ($attributes_values['price_prefix'] == '+') {
                          $attributes_addon_price += $attributes_values['options_values_price'];
                        } else if($attributes_values['price_prefix'] == '-') {
                          $attributes_addon_price -= $attributes_values['options_values_price'];
                        }
                        $att_name .= " (" . $attributes_values['products_options_name'] . ": " . $attributes_values['products_options_values_name'] . ") ";

                        echo '<br /><small><i> ' . $attributes_values['products_options_name'] . ': ' . $attributes_values['products_options_values_name'] . '</i></small>';
                        $att_price = $wishlist->wishlist_attributes_price($wishlist_id, $attributes_values['options_values_price']);
                        if ($attributes_values['price_prefix'] == '+') {
                          $attributes_price = $attributes_price + $att_price;
                        } else {
                          $attributes_price = $attributes_price - $att_price;
                        }
                      }

                      /*******************************************************************
                      ******* CHECK TO SEE IF PRODUCT HAS BEEN ADDED TO THEIR CART *******
                      *******************************************************************/
                      if($cart->in_cart($wishlist_id)) {
                        echo '<br><font color="#FF0000"><b>' . TEXT_ITEM_IN_CART . '</b></font>';
                      }

                      /*******************************************************************
                      ********** CHECK TO SEE IF PRODUCT IS NO LONGER AVAILABLE **********
                      *******************************************************************/
                      if($products['products_status'] == 0) {
                        echo '<br><span class="markProductOutOfStock">' . TEXT_ITEM_NOT_AVAILABLE . '</span>';
                      }

                      /*******************************************************************
                      ********** SPRAWDZENIE CZY PRODUKTOW JEST POWYZEJ 0 ****************
                      *******************************************************************/
                      if ( $products['products_quantity'] == 0 || $products['products_quantity'] < 0 ) {
                        echo '<br><span class="markProductOutOfStock">' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . '</span>';
                      }
                      $i++;
                      echo '<input type="hidden" name="prod_att[]" value="' . $att_name . '" />';
                      ?>
                    </td>
                    <?php
                    if (DISPLAY_PRICE_BRUTTO_NETTO == 'true') {
                      $display_nb = 1;
                    } else {
                      $display_nb = 0;
                    }

                    //TotalB2B start
                    $query_special_prices_hide_result = SPECIAL_PRICES_HIDE;
                    $special_hide = $query_special_prices_hide_result;

                    if ($new_price = tep_get_products_special_price($products['products_id']) ) {
                      $listing_org['products_price'] = tep_xppp_getproductprice($products['products_id']);
                      $products['products_price'] = $new_price;
                      $cena = $products['products_price'] + $attributes_price;
                      $cena_org = $listing_org['products_price'] + $attributes_price;

                      if ($products['products_price'] > 0) {
                        if ($special_hide == 'false') {
                          $query_price_to_guest_result = ALLOW_GUEST_TO_SEE_PRICES;
                          if ((($query_price_to_guest_result=='true') && !(tep_session_is_registered('customer_id'))) || ((tep_session_is_registered('customer_id')))) {
                            $products_price = '<span class="smallText"><s>' . $currencies->display_price($products['products_id'], $cena_org, tep_get_tax_rate($products['products_tax_class_id'])) . '</s></span><br><span class="productSpecialPrice">' . $currencies->display_price_nodiscount($products['products_id'], $cena,tep_get_tax_rate($products['products_tax_class_id']),1,$display_nb) .'</span>';
                          } else {
                            $products_price = '<span class="Cena">' . PRICES_LOGGED_IN_TEXT . '</span>';
                          }
                        } else {
                          $products_price = '<span class="Cena">' . $currencies->display_price($products['products_id'], $cena_org, tep_get_tax_rate($products['products_tax_class_id']),1,$display_nb) .'</span>';
                        }
                      } else {
                        $products_price = '<span class="smallText"><b>'.TEMPORARY_NO_PRICE.'</b></span>';
                      }
                    } else {
                      $products['products_price'] = tep_xppp_getproductprice($products['products_id']);
                      $cena = $products['products_price'] + $attributes_price;
                      if ($products['products_price'] > 0) {
                        $products_price = '<span class="Cena">' . $currencies->display_price($products['products_id'],$cena,tep_get_tax_rate($products['products_tax_class_id']),1,$display_nb).'</span>';
                      } else {
                        $products_price = '<span class="smallText"><b>'.TEMPORARY_NO_PRICE.'</b></span>';
                      }
                    }
                    //TotalB2B end & TotalB2B end
                    ?>

                    <td valign="top" class="productListing-data" align="right"><?php echo $products_price; ?></td>
                    <td valign="top" class="productListing-data" align="center" rowspan="2" height="100%" width="40">
                      <table border="0" cellpadding="0" cellspacing="0" style="height:100%;">
                        <tr>
                          <td align="center" valign="top" class="main" height="50">
                            <?php

                            /*******************************************************************
                            * PREVENT THE ITEM FROM BEING ADDED TO CART IF NO LONGER AVAILABLE *
                            *******************************************************************/
                            if ( $products['products_quantity'] > 0 ) {
                              if ($products['products_price'] > 0) {
                                echo '<input type="hidden" name="add_wishprod[]" value="' . $wishlist[products_id] . '">';
                                echo tep_image_submit('shopping_cart.gif', ADD_TO_CART, 'onClick="document.getElementById(\'przycisk\').value=\''.$wishlist[products_id].'\';"');
                              }
                            } else {
                              if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {
                                echo ''.tep_image_button('shopping_cart_sold.gif').'';
                              } else if ( (STOCK_CHECK == 'false') && (STOCK_ALLOW_CHECKOUT != 'true') ) {
                                echo ''.tep_image_button('shopping_cart_sold.gif').'';
                              } else {
                                echo '<input type="hidden" name="add_wishprod[]" value="' . $wishlist[products_id] . '">';
                                echo tep_image_submit('shopping_cart.gif', ADD_TO_CART, 'onClick="document.getElementById(\'przycisk\').value=\''.$wishlist[products_id].'\';"');
                              }
                            }
                            ?>
                          </td>
                        </tr>
                      </table>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2" class="main" valign="top">
                      <?php echo osc_trunc_string(strip_tags($products['products_description']), 200, 1); ?>
                    </td>
                  </tr>
                </table>
              </td>
            </tr>
            <?php
          }
          ?>
        </table>

      </td>
    </tr>

    <?php
    if ($wishlist_split > 0 && (PREV_NEXT_BAR_LOCATION == '2' || PREV_NEXT_BAR_LOCATION == '3')) {
      ?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '5'); ?></td>
      </tr>
      <tr>
        <td>
          <table border="0" width="100%" cellspacing="0" cellpadding="2">
            <tr>
              <td class="smallText"><?php echo $wishlist_split->display_count(TEXT_DISPLAY_NUMBER_OF_WISHLIST); ?></td>
              <td align="right" class="smallText"><?php echo TEXT_RESULT_PAGE . ' ' . $wishlist_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>
            </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '5'); ?></td>
      </tr>
      <?php
    }
  } else { // Nothing in the customers wishlist
    ?>
    <tr>
      <td>
        <table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td>
              <table border="0" width="100%" cellspacing="0" cellpadding="0">
                <tr>
                  <td class="main"><?php echo BOX_TEXT_NO_ITEMS;?></td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </td>
    </tr>
    <?php
  }
  ?>
  <tr>
   <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '3'); ?></td>
  </tr>
  <tr>
    <td>
     <table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
      <tr class="infoBoxContents">
       <td>
        <table border="0" width="100%" cellspacing="0" cellpadding="2">
         <tr>
          <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
          <td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>
          <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
         </tr>
        </table>
       </td>
      </tr>
     </table>
    </td>
  </tr>
</table>
<!-- customer_wishlist_eof //-->
</form>