<?php
/**
 * Open Source - Content Managment System
 * Next Generation v2
 * @Coder:  Mutzii
 * @copyright  Copyright (c) 2012-2013 by Mutzii
 * File: profil.modul.php
 */

class profil extends Modul
{

   public function onEnable()
   {
      $API = $this->getInstance()->getAPI("auktion");
      
	  if($this->isWebsite("profil")){
	  
	       
	
		   $config        = "";
		   $profil_liste  = ""; 
		   $config_top    = "";
		   $language_list = "";
		   
		   if(isset($_POST['ChangePassword'])){   
		      if(isset($_POST['password'])){
			    if(!empty($_POST['password'])){
			         $API->ChangePassword($_POST['password']);
				}
			  }
		   }
		   
		   if(isset($_POST['changelanguage'])){
		     if(isset($_POST['language'])){
			 
                 $lang = $this->getInstance()->getAPI("language");
       		     $lang->setUserLanguage($lang->getLoginUser(),$_POST['language']);
						  
		     }
		   }
		   
		   
		   
	   
		   if(isset($_GET['nav'])){
		   
		        		   
		         if(!empty($_GET['nav'])){
				        $config = $this->config($_GET['nav']);
					 
					 if($_GET['nav'] == 1){
												  
						  $profil_liste = $API->getTableEntryByName("auktion",$API->getLoginUser());
						  $config_top = $this->config_top();
											
					 }
					 
					 
					 if($_GET['nav'] == 2){
												  
						  $profil_liste = $API->getTableEntryByName("lagerhaus",$API->getLoginUser());
						  $config_top = $this->config_top();
						
						
					 }
					 
					 if($_GET['nav'] == 3){

						$profil_liste = $API->getTableEntryByName("postfach",$API->getLoginUser());
						$config_top = $this->config_top();						
					 }
					 
					 
					 if($_GET['nav'] == 4){
						
						 $this->getInstance()->setContent($this->getInstance()->getTempDir(),$this->getInstance()->getTempError());
						 $content = $this->getInstance()->getContent();
						 $content->ReadFile('profil_settings'.$this->getInstance()->getContentFormat());
						 $profil_liste = $content->ContentToString();
						 
						 /* Langugage List */
						 
						 $SQL   = $this->getInstance()->getSQL();
						 $query = $SQL->select("language_list");
						 $result= $SQL->query($query);
						 
						 $lang     = $this->getInstance()->getAPI("language");
						 $user_id  = $lang->getUserIdLanguage($lang->getLoginUser());
						 
						 while($daten = mysql_fetch_object($result)){
						 
						  if(strcmp($daten->index,$user_id) == false){
						     
							  $language_list .= '	
							   <option name="language" value="'.$daten->index.'" selected>'.$daten->language.'</option>
							';
						 		  
						  }else{
						  					  
							  $language_list .= '	
							   <option name="language" value="'.$daten->index.'">'.$daten->language.'</option>
							 ';
						  }
						 
						 }
						 
											
					 }
				 
				 
				 
				 
				 }
		   
		   
		   }
		   
		   $money     = $API->getPlayerMoney($API->getLoginUser());
		   $avatar    = $API->getAvatarImage($API->getLoginUser());
	       $auktionen = $API->DatenbankCounter("auktion",$API->getLoginUser());
		   $postfach  = $API->DatenbankCounter("postfach",$API->getLoginUser());
           $lager     = $API->DatenbankCounter("lagerhaus",$API->getLoginUser());
		   
   
	  	$array = array( 
	      "{money}" =>  $money,
		  "{avatar}" => $avatar,
		  "{auktionen}" => $auktionen,
		  "{postfach}" => $postfach,
		  "{lager}"    => $lager,
		  "{config}"   => $config,
		  "{profil_liste}" => $profil_liste,
		  "{config_top}"  => $config_top,
		  "{select_language_list}" => $language_list
		 );
	  
	  
	    $this->getPlaceHolder()->fill($array);
	  }
   
   
   }
   
   public function config_top()
   {
      $config_top = '
	  

		  <div id="skal">
		  <div class="psdg-top-left" style="width:129px; text-align:left; padding-left: 24px;">Item </div>
<div class="psdg-top-center">{#list_id}</div>
<div class="psdg-top-center">{#list_stack}</div>
<div class="psdg-top-center">{#list_price}</div>
<div class="psdg-top-center">{#list_solo_price}</div>
<div class="psdg-top-center">{#list_ench}</div>
<div class="psdg-top-center">{#list_seller}</div>
<div class="psdg-top-center">{#list_aid}</div>
<div class="psdg-top-center">{#list_action}</div>

	  </div>
	  ';
   
      return $config_top;
   }
   
   
   public function config($navigation){
   
      switch($navigation)
	  {
	   case 1:
	     $config = "{#menu2}";
	   break;
	   case 2:
	     $config = "{#menu3}";
	   break;
	   case 3:
	     $config = "{#menu4}";
	   break;
	   case 4:
	     $config = "{#menu5}";
	   break;  
	   default:
	      $config = "";
	   break;
	  }
   
     return $config;
   }
   
   
   public function onDisable(){}
   public function isWebsite($site){
           
         if($this->getInstance()->getLogin()->Login()){
             if($this->getInstance()->LoginStatus() == 3){
                if($this->getInstance()->getIndexContent() == $site){
                      return true;
                }
             }
         }

       return false;
    }
	

   
}




?>