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

  class messageStack extends tableBox {

// class constructor
    function messageStack() {
      global $messageToStack;

      $this->messages = array();

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

// class methods
    function add($class, $message, $type = 'error',$rozmiar = '350px') {

	  // liczba losowa zeby kazde okno mialo unikalne ID
	  $liczba = rand(1,10000);
	  // sprawdza wielkosc tablicy z komunikatami bledow
	  $an=sizeof($this->messages);
	  // tworzy kod do wstawienia
	  $okno = '
	        <script type=\'text/javascript\' language=\'javascript\'>
			hidden_flash(\'ukryj\');
			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\';
						  hidden_flash(\'pokaz\');';
			}
	        $okno .= '		
			}	
			document.getElementById(\'ekran\').innerHTML +=  unescape("<div id=\'pop_window' . $liczba . '\' style=\'display:block;position:absolute; top:210px; left:50%; margin-left:-'.($rozmiar/2).'px; font-size:20px; z-index:9999;\'>"+
			   "<table style=\'background-color:#ffffff;border:1px solid #000000;\' width=\''.$rozmiar.'\' 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\'>'.TEXT_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\'>'.TEXT_KOMUNIKAT.'<%2Fp><%2Fcenter>"+				
			   "<center><p style=\'font: normal 11px tahoma,arial, sans-serif; color:#616161\'>' . $message . '<%2Fp><%2Fcenter><br>&nbsp;"+			
			   "<input type=\'button\' value=\''.TEXT_ZAMKNIJ.'\' onclick=\'javascript:close_div' . $liczba . '();\'>"+
			   "<%2Ftd><%2Ftr><%2Ftable><%2Fdiv>");
			</script>';		
	
      if ($type == 'error') {
        $this->messages[] = array('params' => '', 'class' => $class, 'text' => $okno);
      } elseif ($type == 'warning') {
        $this->messages[] = array('params' => '', 'class' => $class, 'text' => $okno);
      } elseif ($type == 'success') {
        $this->messages[] = array('params' => '', 'class' => $class, 'text' => $okno);
      } else {
        $this->messages[] = array('params' => '', 'class' => $class, 'text' => $okno);
      }
    }	

    function add_session($class, $message, $type = 'error') {
      global $messageToStack;

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

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

    function reset() {
      $this->messages = array();
    }

    function output($class) {
      $this->table_data_parameters = 'class="messageBox"';
	  $this->table_cellpadding = '0';	  

      $output = array();
      for ($i=0, $n=sizeof($this->messages); $i<$n; $i++) {
        if ($this->messages[$i]['class'] == $class) {
          $output[] = $this->messages[$i];
        }
      }
      return $this->tableBox($output);
    }

    function size($class) {
      $count = 0;

      for ($i=0, $n=sizeof($this->messages); $i<$n; $i++) {
        if ($this->messages[$i]['class'] == $class) {
          $count++;
        }
      }

      return $count;
    }
  }
?>
