<?php
/*
######################      CWB\     #######################
############################################################
CWB PRO			$Name: release_version1_0_03112006 $
Revision		$Revision: 1.3 $
Author			$Author: lvalics $
Created 03/01/03        $Date: 2006/11/03 11:55:17 $
Writed by               GraFX (webmaster@grafxsoftware.com)
Scripts Home:           http://www.grafxsoftware.com
############################################################
*/
// deschide un session
	header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
	session_start();
	//session_regenerate_id();
	include_once("./config.inc.php");
	if (!isset($_SESSION['session_lang']))
	{
		$session_lang = $LANG;
        $_SESSION['session_lang']=$session_lang;
	}
	else
     	$session_lang=$_SESSION['session_lang'];// end if
	include_once(INDEX_PATH."cls_fast_template.php");
	$NEWLANG = $session_lang;
	include_once(INCLUDE_LANGUAGE_PATH.$NEWLANG.".inc.php");

	include_once(INCLUDE_PATH."cls_string.php");
	include_once(INCLUDE_PATH."cls_universal_mailsender.php");
	include_once(INCLUDE_PATH."cls_miniFile.php");
	include_once(INCLUDE_PATH."cls_pages.php");
    include_once(INCLUDE_ADMIN_PATH."cls_arrays.php");
	
	$stringutil = new String("nope");
	$all_url_vars = array();
	$all_url_vars = $stringutil->parse_all();

	
if ($all_url_vars['action']!="form")
{
	$ft = new FastTemplate(TEMPLATE_PATH);
	$ft->define(array("main"=>"template_index.html", "content"=>"subscribe.html"));
	$ft->assign("KEYWORDS","");
	$ft->assign("SITE_NAME", CONF_SITE_NAME );
	$ft->assign("TITLE_TAG",LANG_TITLETAG_SUBSCRIBE);
	$ft->assign("LANG", $NEWLANG);
	
	 $mf=new MiniFile("bd.php");
	 $data=$mf->getArray();	
	
	 $page = new Pages($all_url_vars['page']);	
		
	 $first=$page->getFirstElement();
     
	if(file_exists(INDEX_PATH."images/".$all_url_vars['page'].".gif"))
	$ft->assign("TITLE_TAG_IMG", CONF_INDEX_URL."images/".$all_url_vars['page']);
	else
	$ft->assign("TITLE_TAG_IMG", CONF_INDEX_URL."images/spacer");
	
	 unset($data[$first]);
	 
	 $order_arr =
  			array(
   				array('title','a'),  
    		);

       $data = arfsort( $data, $order_arr);
	
	 $ft->define_dynamic("up","main");
	 $ft->define_dynamic("down","main");
	 
	 $ft->assign("URL_TYPE", "index.php");	
	 $ft->assign("TITLE_PAGES", LANG_HOME);
     $ft->parse("UP",".up");

     foreach( $data as $key =>$value){
     if(NONSEO==0)
	 $ft->assign("URL_TYPE", "index.php?page=".$key);	
	 else
	 $ft->assign("URL_TYPE", "index.php/".$key."/");
	 $ft->assign("TITLE_PAGES", $data[$key]["title"]);
	 
	 $ft->parse("UP",".up");
	 }


	 $ft->assign("URL_TYPE", "index.php");	
	 $ft->assign("TITLE_PAGES", LANG_HOME);
     $ft->parse("DOWN",".down");

     foreach( $data as $key =>$value){
	 if(NONSEO==0)
	 $ft->assign("URL_TYPE", "index.php?page=".$key);	
	 else
	 $ft->assign("URL_TYPE", "index.php/".$key."/");	
	 
	 $ft->assign("TITLE_PAGES", $data[$key]["title"]);
	 
	 $ft->parse("DOWN",".down");
	 }

	
	/* Captcha modification BEGIN
		If gd library isn't installed, no image generated
	*/
	
	if(IMAGE_NEEDED==1 && function_exists("imagecreate"))
	{
		$ft->assign("INDEX_URL", CONF_INDEX_URL);
		$ft->assign("GD_LIBRARY","1");
	}
	else
		$ft->assign("GD_LIBRARY","0");

	/* Captcha modification BEGIN
		If typed key does't match with the text dispalyed on image then: error message
	*/
	if(!empty($all_url_vars["message"]))	
		$ft->assign("MESSAGE","<font color=\"red\">".LANG_ERROR_DOESNTMATCH."</font>");
	/* Captcha modification END */
		
	$ft->multiple_assign_define("LANG_");
	$ft->multiple_assign_define("CONF_");
	$ft->parse("BODY", array("content","main"));
	$ft->showDebugInfo(ERROR_DEBUG);
	$ft->FastPrint();
	$ft->clear_all();
}
else
if ($all_url_vars['action']=="form")
{
	
	if(!isset($_SESSION["session_nr_attemps"]))
		$nr_attemps = 0;
	else	
		$nr_attemps = $_SESSION["session_nr_attemps"];
	$_SESSION["session_nr_attemps"] = $nr_attemps + 1;
	/* Captcha modification 
		if Nr of letter sending attemps > 3 then the browser must be restarted
	*/	
	if($_SESSION["session_nr_attemps"]>3)
	{
		$ft = new FastTemplate(TEMPLATE_PATH);
		$ft->define(array("main"=>"template_index.html", "content"=>"confirm.html"));
		$ft->assign("KEYWORDS","");
		$ft->assign("SITE_NAME", CONF_SITE_NAME );
		$ft->assign("TITLE_TAG",LANG_TITLETAG_CONTACT);
		
			 $mf=new MiniFile("bd.php");
			 $data=$mf->getArray();	
			
			 $page = new Pages($all_url_vars['page']);	
				
			 $first=$page->getFirstElement();
			 
		
			 unset($data[$first]);
			 
			 $order_arr =
					array(
						array('title','a'),  
					);
		
			   $data = arfsort( $data, $order_arr);
			
			 $ft->define_dynamic("up","main");
			 $ft->define_dynamic("down","main");
			 
			 $ft->assign("URL_TYPE", "index.php");	
			 $ft->assign("TITLE_PAGES", LANG_HOME);
			 $ft->parse("UP",".up");
		
			 foreach( $data as $key =>$value){
			 if(NONSEO==0)
			 $ft->assign("URL_TYPE", "index.php?page=".$key);	
			 else
			 $ft->assign("URL_TYPE", "index.php/".$key."/");
			 $ft->assign("TITLE_PAGES", $data[$key]["title"]);
			 
			 $ft->parse("UP",".up");
			 }
		
		
			 $ft->assign("URL_TYPE", "index.php");	
			 $ft->assign("TITLE_PAGES", LANG_HOME);
			 $ft->parse("DOWN",".down");
		
			 foreach( $data as $key =>$value){
			 if(NONSEO==0)
			 $ft->assign("URL_TYPE", "index.php?page=".$key);	
			 else
			 $ft->assign("URL_TYPE", "index.php/".$key."/");	
			 
			 $ft->assign("TITLE_PAGES", $data[$key]["title"]);
			 
			 $ft->parse("DOWN",".down");
			 }
	
		$ft->assign("TEXT", LANG_ERROR_NRATTEMPS);		
		$ft->multiple_assign_define("LANG_");
		$ft->multiple_assign_define("CONF_");
		$ft->parse("BODY", array("content","main"));
		$ft->showDebugInfo(ERROR_DEBUG); 
		$ft->FastPrint();		
		exit;	
	}// if nr_attemps > 3
	
	if(IMAGE_NEEDED==1 && $_SESSION["verify_image"]!=$all_url_vars["image_text"])
	{
		header("Location: subscribe.php?message=".LANG_ERROR_DOESNTMATCH);		
	}
	else
	{
		
		//$message = $all_url_vars['mesaj'] . "<br />".LANG_CONTACTINFO_YOURPHONENR.": ".$all_url_vars["phone"];
		$message .= "<br /> ".LANG_NAME.":".$all_url_vars['name'];
		$message .= "<br /> ".LANG_FROM." ".CONF_SITE_NAME;
		$from = $all_url_vars['emailad'];
	
		$to = "";
		$subject = "";
		$headers = "";
		$subject = "";
	
	
	
	
	
		//mail to user
	
	
	     $subject = $all_url_vars['subject'];
	
		$univMail= new UniversalMailSender("2");
		// setting up the to address
		$univMail->setToAddress($all_url_vars['emailad'], $all_url_vars['emailad']);
		// setting up from address
		$univMail->setFromAddress(EMAIL_NAME, EMAIL_NAME);
		// setting up subject
		$univMail->setSubject($subject);
		// setting up from text message if the type is text message
		$univMail->setTextMessage($message);
		// setting up from text message if the type is html message
		$univMail->setHtmlMessage($message);
	

	//mail to admin
	
		$univMail= new UniversalMailSender("2");
		// setting up the to address
		$univMail->setToAddress(EMAIL_INREG, EMAIL_NAME);
		// setting up from address
		$univMail->setFromAddress($from, $from);
		// setting up subject
		$univMail->setSubject($subject);
		// setting up from text message if the type is text message
		$univMail->setTextMessage($message);
		// setting up from text message if the type is html message
		$univMail->setHtmlMessage($message);
		// sending the mail; returns an error message
		$ok=$univMail->SendMail();
	
		if (strcmp($ok,"")<>0)
		{	
			//raspuns
			$ft = new FastTemplate(TEMPLATE_PATH);
			$ft->define(array("main"=>"template_index.html", "content"=>"confirm.html"));
			$ft->assign("KEYWORDS","");
			$ft->assign("SITE_NAME", CONF_SITE_NAME );
			$ft->assign("TITLE_TAG",LANG_TITLETAG_CONTACT);
			 $mf=new MiniFile("bd.php");
			 $data=$mf->getArray();	
			
			 $page = new Pages($all_url_vars['page']);	
				
			 $first=$page->getFirstElement();
			 
		
			 unset($data[$first]);
			 
			 $order_arr =
					array(
						array('title','a'),  
					);
		
			   $data = arfsort( $data, $order_arr);
			
			 $ft->define_dynamic("up","main");
			 $ft->define_dynamic("down","main");
			 
			 $ft->assign("URL_TYPE", "index.php");	
			 $ft->assign("TITLE_PAGES", LANG_HOME);
			 $ft->parse("UP",".up");
		
			 foreach( $data as $key =>$value){
			 if(NONSEO==0)
			 $ft->assign("URL_TYPE", "index.php?page=".$key);	
			 else
			 $ft->assign("URL_TYPE", "index.php/".$key."/");
			 $ft->assign("TITLE_PAGES", $data[$key]["title"]);
			 
			 $ft->parse("UP",".up");
			 }
		
		
			 $ft->assign("URL_TYPE", "index.php");	
			 $ft->assign("TITLE_PAGES", LANG_HOME);
			 $ft->parse("DOWN",".down");
		
			 foreach( $data as $key =>$value){
			 if(NONSEO==0)
			 $ft->assign("URL_TYPE", "index.php?page=".$key);	
			 else
			 $ft->assign("URL_TYPE", "index.php/".$key."/");	
			 
			 $ft->assign("TITLE_PAGES", $data[$key]["title"]);
			 
			 $ft->parse("DOWN",".down");
			 }
			
			
			 $mf2=new MiniFile("subscribe.php");
			 $data_users=$mf2->getArray();	
			
			 $temp_array[]=$all_url_vars['name'];
			 $temp_array[]=$all_url_vars['emailad'];
			 $data_users[]=$temp_array;
			 
			 $mf2->setArray($data_users);	
			 $mf2->save();
			
			$ft->assign("TEXT", LANG_CONFIRM_SUBSCRIBE."<br /><br /><a href='index.php'>".LANG_BACKTO_HOMEPAGE."</a>");		
			$ft->multiple_assign_define("LANG_");
			$ft->multiple_assign_define("CONF_");
			$ft->parse("BODY", array("content","main"));
			$ft->showDebugInfo(ERROR_DEBUG);
			// print str_replace("meta","contact.php?aa=1325272",$ft->fetch());
			$ft->FastPrint();
		} // end if ($ok)
		else
		{		
			//raspuns
			$ft = new FastTemplate(TEMPLATE_PATH);
			$ft->define(array("main"=>"template_index.html", "content"=>"confirm.html"));
			$ft->assign("KEYWORDS","");	
			$ft->assign("SITE_NAME", CONF_SITE_NAME );		
			$ft->assign("TITLE_TAG",LANG_TITLETAG_CONTACT);
			$ft->assign("TEXT", LANG_ERROR_DURING_SENDING."<br /><br /><a href='subscribe.php'>".LANG_TRY_AGAIN."</a>");		
			 $mf=new MiniFile("bd.php");
			 $data=$mf->getArray();	
			
			 $page = new Pages($all_url_vars['page']);	
				
			 $first=$page->getFirstElement();
			 
		
			 unset($data[$first]);
			 
			 $order_arr =
					array(
						array('title','a'),  
					);
		
			   $data = arfsort( $data, $order_arr);
			
			 $ft->define_dynamic("up","main");
			 $ft->define_dynamic("down","main");
			 
			 $ft->assign("URL_TYPE", "index.php");	
			 $ft->assign("TITLE_PAGES", LANG_HOME);
			 $ft->parse("UP",".up");
		
			 foreach( $data as $key =>$value){
			 if(NONSEO==0)
			 $ft->assign("URL_TYPE", "index.php?page=".$key);	
			 else
			 $ft->assign("URL_TYPE", "index.php/".$key."/");
			 $ft->assign("TITLE_PAGES", $data[$key]["title"]);
			 
			 $ft->parse("UP",".up");
			 }
		
		
			 $ft->assign("URL_TYPE", "index.php");	
			 $ft->assign("TITLE_PAGES", LANG_HOME);
			 $ft->parse("DOWN",".down");
		
			 foreach( $data as $key =>$value){
			 if(NONSEO==0)
			 $ft->assign("URL_TYPE", "index.php?page=".$key);	
			 else
			 $ft->assign("URL_TYPE", "index.php/".$key."/");	
			 
			 $ft->assign("TITLE_PAGES", $data[$key]["title"]);
			 
			 $ft->parse("DOWN",".down");
			 }
			
			$ft->multiple_assign_define("LANG_");
			$ft->multiple_assign_define("CONF_");
			$ft->parse("BODY", array("content","main"));
			$ft->showDebugInfo(ERROR_DEBUG);
			$ft->FastPrint();
		}// end else
	
}
}// end action==form
?>