<?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));
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' => sprintf(HEADING_TITLE_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
  if (is_array($wishlist->wishID) && !empty($wishlist->wishID)) {
    reset($wishlist->wishID);
    ?>
    <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
          $i = 0;
          while (list($wishlist_id, ) = each($wishlist->wishID)) {

            $product_id = tep_get_prid($wishlist_id);
            $products_query = tep_db_query("select pd.products_id, pd.products_name, pd.products_description, p.products_image, p.products_quantity, p.products_status, p.products_price, p.products_tax_class_id, 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 pd.products_id = s.products_id where pd.products_id = '" . $product_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_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_id, 'NONSSL'); ?>"><?php echo $products['products_name']; ?></a></b>
                      <input type="hidden" name="prod_link[]" value="<?php echo tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $wishlist_id, 'NONSSL'); ?>" />
                      <input type="hidden" name="prod_name[]" value="<?php echo $products['products_name']; ?>" />
                      <?php

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

                      // Now get and populate product attributes
                      $att_name = "";
                      if (isset($wishlist->wishID[$wishlist_id]['attributes'])) {
                        $attributes_price = 0;
                        while (list($option, $value) = each($wishlist->wishID[$wishlist_id]['attributes'])) {
                          echo tep_draw_hidden_field('id[' . $wishlist_id . '][' . $option . ']', $value);
                          $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 = '" . $option . "'
                                               and pa.options_id = popt.products_options_id
                                               and pa.options_values_id = '" . $value . "'
                                               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;
                          }
                        } // end while attributes for product
                      }

                      /*******************************************************************
                      ******* 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 *
                            *******************************************************************/
							// sprawdzanie czy nie sa ceny po zalogowaniu
							if (((ALLOW_GUEST_TO_SEE_PRICES=='true') && !(tep_session_is_registered('customer_id'))) || ((tep_session_is_registered('customer_id')))) {
								$rtak = true;
							   } else {
							    $rtak = false;
							}
							if ($rtak == true) {
								if ( $products['products_quantity'] > 0) {
								  if ($products['products_price'] > 0) {
									echo '<input type="hidden" name="add_wishprod[]" value="' . $wishlist_id . '">';
									echo tep_image_submit('shopping_cart.gif', ADD_TO_CART, 'onClick="document.getElementById(\'przycisk\').value=\''.$wishlist_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_id . '">';
									echo tep_image_submit('shopping_cart.gif', ADD_TO_CART, 'onClick="document.getElementById(\'przycisk\').value=\''.$wishlist_id.'\';"');
								  }
								}
							}
                            ?>
                          </td>
                        </tr>
                        <tr>
                          <td align="center" valign="middle" class="main" height="50">
                            <?php
                            echo '<a href="' . tep_href_link(FILENAME_WISHLIST, 'action=remove_wishlist&products_id='.$wishlist_id, 'NONSSL') . '">'.tep_image(DIR_WS_TEMPLATES . 'images/misc/kosz.gif').'</a>';
                            ?>
                          </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>

    <tr>
      <td>
        <fieldset>
        <legend><?php echo TEXT_EMAIL; ?></legend>
          <table border="0">
            <tr>
              <td>
              <table border="0" width="100%" cellspacing="0" cellpadding="2">
                <?php
                /*******************************************************************
                *********** CODE TO SPECIFY HOW MANY EMAILS TO DISPLAY *************
                *******************************************************************/
                if(!tep_session_is_registered('customer_id')) {
                  ?>
                  <tr>
                    <td class="main"><?php echo WISHLIST_EMAIL_TEXT_GUEST; ?></td>
                  </tr>
                  <tr>
                    <td align="center">
                      <table border="0" width="90%" cellspacing="0" cellpadding="2">
                        <tr>
                          <td class="main" colspan="2" align="left">
                            <table cellpadding="2" cellspacing="0">
                              <tr>
                                <td colspan="2"><?php echo $guest_errors; ?></td>
                              </tr>
                              <tr>
                                <td class="main"><?php echo TEXT_YOUR_NAME_WISHLIST; ?></td>
                                <td class="main"><?php echo tep_draw_input_field('your_name', $your_name,' size="30"'); ?></td>
                              </tr>
                              <tr>
                                <td class="main"><?php echo TEXT_YOUR_EMAIL; ?></td>
                                <td class="main"><?php echo tep_draw_input_field('your_email', $your_email,' size="30"'); ?></td>
                              </tr>
                            </table>
                          </td>
                        </tr>
                      </table>
                    </td>
                  </tr>
                  <?php
                } else {
                  ?>
                  <tr>
                    <td class="main"><?php echo WISHLIST_EMAIL_TEXT; ?></td>
                  </tr>
                  <?php
                }
                ?>          
                <tr>
                  <td align="center">
                    <table border="0" width="90%" cellspacing="2" cellpadding="2">
                      <tr>
                        <td colspan="2"><?php echo $email_errors; ?></td>
                      </tr>
                      <?php

                      $email_counter = 0;
                      while($email_counter < DISPLAY_WISHLIST_EMAILS) {
                        ?>
                        <tr>
                          <td class="main"><?php echo TEXT_NAME_WISHLIST; ?>&nbsp;&nbsp;<?php echo tep_draw_input_field('friend[]', $friend[$email_counter],' size="25"'); ?></td>
                          <td class="main"><?php echo TEXT_EMAIL; ?>&nbsp;&nbsp;<?php echo tep_draw_input_field('email[]', $email[$email_counter],' size="25"'); ?></td>
                        </tr>
                        <?php
                        $email_counter++;
                      }
                      ?>
                      <tr>
                        <td colspan="2"><?php echo $message_error; ?></td>
                      </tr>
                      <tr>
                        <td colspan="2" class="main"><?php echo  TEXT_MESSAGE; ?></td>
                      </tr>                      
                      <tr>
                        <td colspan="2" class="main"><?php echo tep_draw_textarea_field('message', 'soft', 90, 5); ?></td>
                      </tr>
                      <tr>
                          <td colspan="2" align="left"><?php echo tep_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE, 'name="email_prod" value="email_prod"'); ?></td>
                      </tr>                      
                    </table>
                  </td>
                </tr>
              </table>
              </td>
            </tr>
          </table>
        </fieldset>
      </td>
    </tr>

    <?php
  } else { // Nothing in the customers wishlist
    ?>
    <tr>
      <td>
        <table border="0" width="100%" cellspacing="0" cellpadding="2" class="TableFrame">
          <tr>
            <td>
              <table border="0" width="100%" cellspacing="0" cellpadding="5">
                <tr>
                  <td class="main"><?php echo BOX_TEXT_NO_ITEMS;?></td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </td>
    </tr>
    <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_back.gif', IMAGE_BUTTON_BACK) . '</a>'; ?></td>
            <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
           </tr>
          </table>
       </td>
        </tr>
       </table>
      </td>
    </tr>
    <?php
  }
  ?>
</table>
<!-- customer_wishlist_eof //-->
</form>