Your IP : 216.73.216.90


Current Path : /home/semix18/public_html/optimum-wycena.pl/modules/Theme/
Upload File :
Current File : /home/semix18/public_html/optimum-wycena.pl/modules/Theme/admin.php

<?php

if (!defined('LOADED_AS_ADMIN_MODULE'))
{ 
		require_once('../../core/Dobi.php');  
		Dobi::exception('dobiExcDirectAccess', 1, '', 'direct');
}

class ThemeAdmin implements DobiAdminModule, action_add, action_show, action_config  
{
	
	private $theme_current_action_to_run;

	public function __construct($theme_current_action_to_run)
	{
		$this->themeA_current_action_to_run = $theme_current_action_to_run;
	}
	
	public function _defaultAction() 
	{
	    return $this->show();	 
	}
	
	public function _executeAction() 
	{
	    if (!Registry::getObject('session')->getUserAccess(LA_INSTALLERS))
	    {
	   		echo '<span style="font-weight: bold;">'._ACCESS_DENIED_.'</span> ' . _ACCESS_DENIED_MSG_;
			return;   
	    }
	   $go = $this->themeA_current_action_to_run;
	   $this->$go();	  
	}
	
	public function show()
	{
	    $themes = new theme();
	    
 		// 570px - il. komórek
 		echo '<div style="width: 570px; height: 20px" class="b4"> ' . _THEME_INSTALLED_LIST_ . ' </div>
		    <div class="table">
 	    	<div style="width: 110px;" class="top"> '._WORD_NAME_.' </div>
			<div style="width: 110px;" class="top"> '._WORD_AUTHOR_.' </div>
			<div style="width: 110px;" class="top"> '._WORD_VERSION_.' </div> 
			<div style="width: 125px;" class="top"> '._WORD_DEFAULT_.' </div>
			<div style="width: 110px;" class="top"> '._WORD_ACTION_.' </div>';	    

		if (count($themes->getInstalledAmount()) == 0)
		{
			echo '<div style="width: 569px;">'._THEME_NO_THEMES_.'</div>';
	 	}
		else
		{
			foreach ($themes->getInstalledList() as $theme_name)
			{
				$theme = new themeDetails( $theme_name );
				$theme->prepareInfo();
				$class = 'action4'; 
			    if ($theme->getValue('name') !== $themes->getDefaultTheme())
			    {
					$status = '<span style="color: red">'._WORD_NO_.'</span>';
					$active = 0; 
				}
				else 
				{
					$status = '<span style="color: green">'._WORD_YES_.'</span>';
					$active = 1;
					$class = 'action2';  
				}
				
				echo '<div style="width: 110px;" class="'.$class.'"> '. $theme_name .' </div>
					  <div style="width: 110px;" class="'.$class.'"> '. $theme->getValue('author') .' </div>
					  <div style="width: 110px;" class="'.$class.'"> '. $theme->getValue('version') .' </div> 
					  <div style="width: 125px;" class="'.$class.'"> '. $status .' </div>
					  <div style="width: 110px;" class="'.$class.'"> <a href="admin.php?module=Theme&action=config&theme='.$theme_name.'">'._WORD_SETTINGS_.'</a>
					  <a href="admin.php?module=Theme&action=details&theme='.$theme_name.'">'._WORD_DETAILS_.'</a>
				';		  
				if (!$active)
				{
						echo '
						<a href="admin.php?module=Theme&action=uninstall&theme='.$theme_name.'">'._WORD_UNINSTALL_.'</a>
						<a href="admin.php?module=Theme&action=active&theme='.$theme_name.'">'._THEME_SET_DEFAULT_.'</a>
						';  
				}														 
				echo '</div>';
				$theme = NULL;				  	
			}		  
		}
		echo '</div>';
	}
	
	public function add()
	{
		$themes = new theme();
 		// 570px - il. komórek
 		echo '<div style="width: 570px; height: 20px" class="b4"> '._THEME_READY_TO_INSTALL_.' </div>
		    <div class="table">
 	    	<div style="width: 145px;" class="top"> '._WORD_NAME_.' </div>
			<div style="width: 141px;" class="top"> '._WORD_AUTHOR_.' </div>
			<div style="width: 135px;" class="top"> '._WORD_VERSION_.' </div> 
			<div style="width: 145px;" class="top"> '._WORD_ACTION_.'</div>';	 		

		$invalid_themes = array();
		
		foreach ($themes->getNoInstalledList() as $theme_name)
		{
			$theme = new themeDetails( $theme_name );
		    if ($theme->isValid())
			{
				$theme->prepareInfo();
				echo '<div style="width: 145px;" class="action2"> '. $theme_name .' </div>
					  <div style="width: 141px;" class="action2"> '. $theme->getValue('author') .' </div>
					  <div style="width: 135px;" class="action2"> '. $theme->getValue('version') .' </div> 
					  <div style="width: 145px;" class="action2"><a href="admin.php?module=Theme&action=details&theme='.$theme_name.'">'._WORD_DETAILS_.'</a> 
					  <a href="admin.php?module=Theme&action=install&theme='.$theme_name.'">'._WORD_INSTALL_.'</a> </div>';				  
			}
			else $invalid_themes[] = $theme_name;
			$theme = NULL;	
		}	
				  
		if ($themes->getNoInstalledAmount() == 0 || $themes->getNoInstalledAmount() == count($invalid_themes))
		{
			echo '<div style="width: 569px;"> '._THEME_NO_THEMES_TO_INSTALL_.'</div>';
		}		
		echo '</div>';	
		echo '<div class="frame"><div style="width: 570px; margin: 20px 0px" class="b4"> '._THEME_NOT_READY_TO_INSTALL_.' </div>';

		if (count($invalid_themes) == 0) echo _WORD_NONE_;
		else
		{
			foreach ($invalid_themes as $invalid_theme)  
			{
				echo '<div class="block"">' . $invalid_theme . '</div>';  
			}
		}
		echo '</div>';
	}
	
	public function active()
	{
	  	$dataRequest = Registry::getObject('dataRequest');
		$theme = new theme();
	  	$error = Registry::getObject('error', new error());
	  	$error->addAction('show');
	  	$error->setTrueMessage(_THEME_ACTIVE_SUCC_);
	  	$error->setFalseMessage(_THEME_ACTIVE_FAIL_ . _ERRORS_OCCURRED_);	  			
			
        if (!$theme->isInstalled( $dataRequest->getValue('theme') ))
        {
			$error->addError(_THEME_NO_EXISTS_);   
		}
		if (!$error->errorExists())
		{
		    $dbUDECA = Registry::getObject( 'dbUDECA' ); 
			$dbUDECA->setMapper(false);
			$dbUDECA->updateConfValue('default_theme', $dataRequest->getValue('theme'));
			$dbUDECA->execute(); 
			$dbUDECA->clear(); 
		}
		$error->getErrors();	  
	}
	
	public function install()
	{
	 	$dataRequest = Registry::getObject('dataRequest');
		$theme = new themeDetails($dataRequest->getValue('theme')); 
	  	$error = Registry::getObject('error', new error());
	  	$error->addAction('add');
	  	$error->setTrueMessage(_THEME_INSTALL_SUCC_);
	  	$error->setFalseMessage(_THEME_INSTALL_FAIL_ . _THEME_FACED_ERRORS_);
		
		if (!$theme->isValid())
		{
			$error->addError(_THEME_INVALID_);  
		}		
		
		if ($theme->isInstalled( $theme->getValue('name')))
		{
			$error->addError(_THEME_EXISTS_);   
		}	
		if (!$error->errorExists())
		{
				$theme->prepareInfo();
				$style = $theme->getValue('style');
				$article_blocks = $theme->getValue('article_blocks');
				
				if (strpos( $style, '.css' ))
				{
					$style = str_replace('.css', '', $style);  
				}
				if (strpos( $article_blocks, '.php' ))
				{
					$article_blocks = str_replace('.php', '', $article_blocks);  
				}				
				$dbUDECA = Registry::getObject( 'dbUDECA' ); 	
				$dbUDECA->setMapper(false);	  
				$dbUDECA->insert( 'themes', 
							array(	'them_name'	  	  			   => 	$theme->getValue('name'),
									'them_style'	  	           => 	$style,
									'them_article_blocks'	  	   => 	$article_blocks,
									'them_center_blocks'	  	   => 	$theme->getValue('center_blocks'),
									'them_left_blocks'	  	       => 	$theme->getValue('left_blocks'),
									'them_right_blocks'	  	   	   => 	$theme->getValue('right_blocks'),
									'them_special_1_blocks'	  	   => 	$theme->getValue('special_1_blocks'),
									'them_special_2_blocks'	  	   => 	$theme->getValue('special_2_blocks'),
									'them_special_3_blocks'	  	   => 	$theme->getValue('special_3_blocks'),
									'them_special_4_blocks'	  	   => 	$theme->getValue('special_4_blocks'),
									'them_special_5_blocks'	  	   => 	$theme->getValue('special_5_blocks'),
									'them_special_6_blocks'	  	   => 	$theme->getValue('special_6_blocks'),
									'them_special_7_blocks'	  	   => 	$theme->getValue('special_7_blocks'),
									'them_special_8_blocks'	  	   => 	$theme->getValue('special_8_blocks')));  
				$dbUDECA->execute();
				$dbUDECA->clear();
				Registry::getObject('dbC')->updateCounter('themes');								
		}
		$error->getErrors();	  
	}
	
	public function uninstall()
	{
	 	$dataRequest = Registry::getObject('dataRequest');
		$theme = new themeDetails($dataRequest->getValue('theme')); 
	  	$error = Registry::getObject('error', new error());
	  	$error->addAction('show');
	  	$error->setTrueMessage(_THEME_UNINSTALL_SUCC_);
	  	$error->setFalseMessage(_THEME_UNINSTALL_FAIL_ . _ERRORS_OCCURRED_);	  	
	  	
		if (!$theme->isInstalled())
        {
			$error->addError(_THEME_NOT_INSTALLED_);   
		}		
		
		$dbUDECA = Registry::getObject('dbUDECA');
		$dbUDECA->setMapper(false);
		$dbUDECA->setWhere('them_name = "'.$dataRequest->getValue('theme').'"');	  
		$dbUDECA->delete('themes');  
		$dbUDECA->execute();
		Registry::getObject('dbC')->updateCounter('themes', -1);					
		$dbUDECA->clear();	
							  						
		$error->getErrors();	
	}
	
	public function details()
	{
	  	$dataRequest = Registry::getObject('dataRequest');
		if (!($theme_name = $dataRequest->getValue('theme')))
		{
			$theme_name = Registry::getObject('db')->getConfValue('default_theme');  
		}	  	
		$theme = new themeDetails($theme_name); 
		
		if ($theme->isValid())
		{
			$theme->prepareInfo();
			$www = str_replace('http://', '', $theme->getValue('www'));

		    $info_bool = config::getSettings('theme_bool_information');
						   
			foreach ($info_bool as $key)
			{
				if ($theme->getValue( $key )) 
				{
					$$key = '<span style="color: green;">'._WORD_YES_.'</span>';  
				}
				else $$key  = '<span style="color: red;">'._WORD_NO_.'</span>';;  
			}	
			
			echo '
		     <div class="frame">
			 <div style="width: 570px; margin: 0px 0px 10px 0px" class="b4"> '.$theme->getValue('name').' :: '._THEME_INFO_.' </div>			
			 <div class="info"><p>'._THEME_INFO_1_.'</p> '.$theme->getValue('name').'</div>
			 <div class="info"><p>'._THEME_INFO_2_.'</p> '.$theme->getValue('author').'</div>
			 <div class="info"><p>'._THEME_INFO_3_.'</p> '.$theme->getValue('version').'</div>
			 <div class="info"><p>'._THEME_INFO_4_.'</p> '.$theme->getValue('description').'</div>
			 <div class="info"><p>'._THEME_INFO_5_.'</p> <a href="mailto: '.$theme->getValue('contact').'">'.$theme->getValue('contact').'</a></div>
			 <div class="info"><p>'._THEME_INFO_6_.'</p> <a href="http://'.$www.'" target="_blank">'.$www.'</a></div>
			 <div class="info"><p>'._THEME_INFO_7_.'</p> '.$theme->getValue('style').'</div>
			 <div class="info"><p>'._THEME_INFO_8_.'</p> '.$theme->getValue('article_blocks').'</div>
			 <div class="info"><p>'._THEME_INFO_9_.'</p> '.$center_blocks.'</div>
			 <div class="info"><p>'._THEME_INFO_10_.'</p> '.$left_blocks.'</div>
			 <div class="info"><p>'._THEME_INFO_11_.'</p> '.$right_blocks.'</div>
			 <div class="info"><p>'._THEME_INFO_12_.'1: </p> '.$special_1_blocks.'</div>
			 <div class="info"><p>'._THEME_INFO_12_.'2: </p> '.$special_2_blocks.'</div>
			 <div class="info"><p>'._THEME_INFO_12_.'3: </p> '.$special_3_blocks.'</div>
			 <div class="info"><p>'._THEME_INFO_12_.'4: </p> '.$special_4_blocks.'</div>
			 <div class="info"><p>'._THEME_INFO_12_.'5: </p> '.$special_5_blocks.'</div>
			 <div class="info"><p>'._THEME_INFO_12_.'6: </p> '.$special_6_blocks.'</div>
			 <div class="info"><p>'._THEME_INFO_12_.'7: </p> '.$special_7_blocks.'</div>
			 <div class="info"><p>'._THEME_INFO_12_.'8: </p> '.$special_8_blocks.'</div>
			 </div>
			';	  
		}
		else
		{
	  		$error = Registry::getObject('error', new error());
	  		$error->addAction('show');
	  	    $error->setFalseMessage(_THEME_INFO_FAIL_);	  		
			$error->addError(_THEME_INVALID_);
			$error->getErrors();						  			 
		}  	
	}	

	public function config()
	{
	  	$dataRequest = Registry::getObject('dataRequest');
		if (!($theme_name = $dataRequest->getValue('theme')))
		{
			$theme_name = Registry::getObject('db')->getConfValue('default_theme');  
		}
		
		$theme = new themeDetails($theme_name);
		
        if (!$theme->isInstalled())
        {
          	$error = Registry::getObject('error', new error());
	    	$error->addAction('show');
	     	$error->setFalseMessage(_THEME_SHOW_FAIL_ ._ERRORS_OCCURRED_);
			$error->addError(_THEME_NOT_INSTALLED_);  
			$error->getErrors(); 
			return;
		}	
		$theme->prepareInfo();
			
		echo '<div class="frame">
			 <div style="width: 570px; margin: 0px 0px 10px 0px" class="b4"> '.$theme_name.' :: '._THEME_INFO_.' </div>			
			 <div class="info"><p>'._THEME_INFO_1_.'</p> '.$theme_name.'</div>
			 <div class="info"><p>'._THEME_INFO_2_.'</p> '.$theme->getValue('author').'</div>
			 <div class="info"><p>'._THEME_INFO_3_.'</p> '.$theme->getValue('version').'</div>
			 <div class="info"><p>'._THEME_INFO_4_.'</p> '.$theme->getValue('description').'</div>
			 <div class="info"><p>'._THEME_INFO_5_.'</p> <a href="mailto: '.$theme->getValue('contact').'">'.$theme->getValue('contact').'</a></div>
			 <div class="info"><p>'._THEME_INFO_6_.'</p> <a href="http://'.$theme->getValue('www').'" target="_blank">'.$theme->getValue('www').'</a></div>
			 </div>';	  
			
	    echo '<div class="form">';
		$form = new form('theme_edit', $dataRequest->getActionLink('save'));
	    $form->setSize(10);
	    $form->setMaxlen(255);
	    $form->fieldset('normal');
	    $form->legend(_THEME_EDIT_);
	    $form->addContent('<div class="help"><h4>'._WORD_HELP_.'</h4><p>'._HELP_1_.'</p><p>'._THEME_HELP_2_.'</p></div>');	    
     	$form->addContent('<div class="left">');

		$form->text(_THEME_INFO_7_, 'style', $theme->getValue('style'), 'required150', 'required150');
		$form->text(_THEME_INFO_8_, 'article_blocks', $theme->getValue('article_blocks'), 'required150', 'required150');
		$form->checkbox(_THEME_INFO_9_, 'center_blocks', 1, 'checkbox150', 'checkbox150', '', $theme->getValue('center_blocks'));
		$form->checkbox(_THEME_INFO_10_, 'left_blocks', 1, 'checkbox150', 'checkbox150', '', $theme->getValue('left_blocks'));
		$form->checkbox(_THEME_INFO_11_, 'right_blocks', 1, 'checkbox150', 'checkbox150', '', $theme->getValue('right_blocks'));
		$form->checkbox(_THEME_INFO_12_ . '1: ', 'special_1_blocks', 1, 'checkbox150', 'checkbox150', '', $theme->getValue('special_1_blocks'));
		$form->checkbox(_THEME_INFO_12_ . '2: ', 'special_2_blocks', 1, 'checkbox150', 'checkbox150', '', $theme->getValue('special_2_blocks'));
		$form->checkbox(_THEME_INFO_12_ . '3: ', 'special_3_blocks', 1, 'checkbox150', 'checkbox150', '', $theme->getValue('special_3_blocks'));
		$form->checkbox(_THEME_INFO_12_ . '4: ', 'special_4_blocks', 1, 'checkbox150', 'checkbox150', '', $theme->getValue('special_4_blocks'));
		$form->checkbox(_THEME_INFO_12_ . '5: ', 'special_5_blocks', 1, 'checkbox150', 'checkbox150', '', $theme->getValue('special_5_blocks'));
		$form->checkbox(_THEME_INFO_12_ . '6: ', 'special_6_blocks', 1, 'checkbox150', 'checkbox150', '', $theme->getValue('special_6_blocks'));
		$form->checkbox(_THEME_INFO_12_ . '7: ', 'special_7_blocks', 1, 'checkbox150', 'checkbox150', '', $theme->getValue('special_7_blocks'));
		$form->checkbox(_THEME_INFO_12_ . '8: ', 'special_8_blocks', 1, 'checkbox150', 'checkbox150', '', $theme->getValue('special_8_blocks'));
	    $form->addContent('</div>');	
		$form->addContent('<div class="submit">');
		$form->hidden('theme', $theme_name );
	    $form->submit(_WORD_UPDATE_, 'inputSubmit');
	    $form->reset(_WORD_CLEAR_, 'inputSubmit');
	    $form->addContent('</div>');		 	    
	    $form->eFieldset();
	    echo $form->getForm();			  
	    echo '</div>';
	}
	
	public function save()
	{
        $error = Registry::getObject('error', new error());
        $error->setRedirectTime( 4 );
	   	$error->addAction('show');
	    $error->setFalseMessage(_THEME_UPDATE_FAIL_ . _ERRORS_OCCURRED_);
	    $error->setTrueMessage(_THEME_UPDATE_SUCC_);
	    
		$dataRequest = Registry::getObject('dataRequest');
		$dbUDECA = Registry::getObject('dbUDECA');
		$dbUDECA->setMapper(true);
		$dbUDECA->mapper( IS_REQUIRED, array(0 => 'theme', 'style', 'article_blocks') );
		$dbUDECA->setWhere('them_name = "'.$dataRequest->getValue('theme').'"');
		
		if (strpos( $dataRequest->getValue('style'), '.css' ))
		{
			$dataRequest->setValue('style', str_replace('.css', '', $dataRequest->getValue('style')));  
		}
		if (strpos( $dataRequest->getValue('article_blocks'), '.php' ))
		{
			$dataRequest->setValue('article_blocks', str_replace('.php', '', $dataRequest->getValue('article_blocks')));  
		}
					    
	    $dbUDECA->update('themes', 
					  array(
					  		'them_style'            => $dataRequest->getValue('style'),
							'them_article_blocks'   => $dataRequest->getValue('article_blocks'),
							'them_center_blocks'    => $dataRequest->getValue('center_blocks'),
							'them_left_blocks'      => $dataRequest->getValue('left_blocks'),
							'them_right_blocks'     => $dataRequest->getValue('right_blocks'),
							'them_special_1_blocks' => $dataRequest->getValue('special_1_blocks'),
							'them_special_2_blocks' => $dataRequest->getValue('special_2_blocks'),
							'them_special_3_blocks' => $dataRequest->getValue('special_3_blocks'),
							'them_special_4_blocks' => $dataRequest->getValue('special_4_blocks'),
							'them_special_5_blocks' => $dataRequest->getValue('special_5_blocks'),
							'them_special_6_blocks' => $dataRequest->getValue('special_6_blocks'),
							'them_special_7_blocks' => $dataRequest->getValue('special_7_blocks'),
							'them_special_8_blocks' => $dataRequest->getValue('special_8_blocks')  		
					  ));
		$theme = new theme();			  
		if (!$theme->themeExists($dataRequest->getValue('theme')))
        {
			$error->addError(_THEME_NO_INSTALLED_);  
		}
		
		$dbUDECA->execute();
		$dbUDECA->clear();			  
		$error->getErrors(); 	  
	}
			
}

?>