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

  class messageStack extends tableBlock {
    var $size = 0;

    function messageStack() {
      global $messageToStack;

      $this->errors = array();

      if (tep_session_is_registered('messageToStack')) {
        for ($i = 0, $n = sizeof($messageToStack); $i < $n; $i++) {
          $this->add($messageToStack[$i]['text'], $messageToStack[$i]['type']);
        }
        tep_session_unregister('messageToStack');
      }
    }

    function add($message, $type = 'error') {

	  // liczba losowa zeby kazde okno mialo unikalne ID
	  $liczba = rand(1,10000);
	  // sprawdza wielkosc tablicy z komunikatami bledow
	  $an=sizeof($this->errors);
	  // tworzy kod do wstawienia
	  $okno = '
	        <script type=\'text/javascript\' language=\'javascript\'>
			document.getElementById(\'blad\').style.display=\'block\';
			document.getElementById(\'pop_overlay\').style.display = \'block\';
			document.getElementById(\'ekran\').style.display = \'block\';
			function close_div' . $liczba . '() {
			document.getElementById(\'pop_window' . $liczba . '\').innerHTML = \'\';';
			// do okna pierwszego wstawia dodatkowy kod ktory spowoduje znikniecie warstw
			if ($an == 0) {		
				$okno .= 'document.getElementById(\'pop_overlay\').style.display = \'none\';
			              document.getElementById(\'blad\').style.display = \'none\';
			              document.getElementById(\'ekran\').style.display = \'none\';';
			}
	        $okno .= '
			}	
			document.getElementById(\'ekran\').innerHTML += unescape("<div id=\'pop_window' . $liczba . '\' style=\'display:block;position:absolute; top:250px; left:50%; margin-left:-175px; font-size:20px; z-index:9999;\'>"+
			   "<table style=\'background-color:#ffffff;border:1px solid #000000;\' width=\'350px\' cellpadding=\'5\' cellspacing=\'0\'><tr><td style=\'background-color: #333344;border-bottom: 2px solid #000000;border-top: 1px solid #78A3F2;border-left: 1px solid #78A3F2;border-right: 1px solid #204095;\' align=\'center\'>"+
			   "<table width=\'98%\' border=\'0\' cellpadding=\'0\' cellspacing=\'0\'><tr><td width=\'50%\' align=\'left\' style=\'font: bold 13px tahoma,arial, sans-serif; color:#ffffff\'>UWAGA<%2Ftd><td width=\'50%\' align=\'right\'>"+
			   "<img src=\'popupbox/close.gif\' border=\'0\' style=\'cursor:pointer\' onclick=\'javascript:close_div' . $liczba . '();\'><%2Ftd><%2Ftr><%2Ftable><%2Ftd><%2Ftr><tr><td>"+				
			   "<center><p style=\'font: bold 17px tahoma,arial, sans-serif; color:#FF0000\'>Komunikat<%2Fp><%2Fcenter>"+				
			   "<center><p style=\'font: normal 11px tahoma,arial, sans-serif; color:#616161\'>' . $message . '<%2Fp><%2Fcenter><br>&nbsp;"+			
			   "<input type=\'button\' value=\'Zamknij\' onclick=\'javascript:close_div' . $liczba . '();\'>"+
			   "<%2Ftd><%2Ftr><%2Ftable><%2Fdiv>");
			</script>'; 
			
      if ($type == 'error') {
        $this->errors[] = array('params' => '', 'text' => $okno);
      } elseif ($type == 'warning') {
        $this->errors[] = array('params' => '', 'text' => $okno);
      } elseif ($type == 'success') {
        $this->errors[] = array('params' => '', 'text' => $okno);
      } else {
        $this->errors[] = array('params' => '', 'text' => $okno);
      }

      $this->size++;			
    } 
	
    function add_session($message, $type = 'error') {
      global $messageToStack;

      if (!tep_session_is_registered('messageToStack')) {
        tep_session_register('messageToStack');
        $messageToStack = array();
      }

      $messageToStack[] = array('text' => $message, 'type' => $type);
    }

    function reset() {
      $this->errors = array();
      $this->size = 0;
    }

    function output() {
      $this->table_data_parameters = 'class="messageBox"';
	  $this->table_cellpadding = '0';	  
      return $this->tableBlock($this->errors,"true");
    }
  }
?>