<?
namespace admin\factory;

class SettingManager
{
	public function save()
	{
		global $db , $lang;

		$firm_name	= \System::saveString( \System::formGet( 'firm_name' ) );
		\admin\factory\SettingManager::saveParam( 'firm_name' , $firm_name );

		$street	= \System::saveString( \System::formGet( 'street' ) );
		\admin\factory\SettingManager::saveParam( 'street' , $street );

		$postal_code = \System::saveString( \System::formGet( 'postal_code' ) );
		\admin\factory\SettingManager::saveParam( 'postal_code' , $postal_code );

		$city = \System::saveString( \System::formGet( 'city' ) );
		\admin\factory\SettingManager::saveParam( 'city' , $city );

		$nip = \System::saveString( \System::formGet( 'nip' ) );
		\admin\factory\SettingManager::saveParam( 'nip' , $nip );

		$email	= \System::saveString( \System::formGet( 'email' ) );
		\admin\factory\SettingManager::saveParam( 'email' , $email );

		$phone	= \System::saveString( \System::formGet( 'phone' ) );
		\admin\factory\SettingManager::saveParam( 'phone' , $phone );

		$fax = \System::saveString( \System::formGet( 'fax' ) );
		\admin\factory\SettingManager::saveParam( 'fax' , $fax );

		$account = \System::saveString( \System::formGet( 'account' ) );
		\admin\factory\SettingManager::saveParam( 'account' , $account );

		$person	= \System::saveString( \System::formGet( 'person' ) );
		\admin\factory\SettingManager::saveParam( 'person' , $person );

		$admin_email = \System::saveString( \System::formGet( 'admin_email' ) );
		\admin\factory\SettingManager::saveParam( 'admin_email' , $admin_email );

		$email_host	= \System::saveString( \System::formGet( 'email_host' ) );
		\admin\factory\SettingManager::saveParam( 'email_host' , $email_host );

		$email_port	= \System::saveString( \System::formGet( 'email_port' ) );
		\admin\factory\SettingManager::saveParam( 'email_port' , $email_port );

		$email_login = \System::saveString( \System::formGet( 'email_login' ) );
		\admin\factory\SettingManager::saveParam( 'email_login' , $email_login );

		$email_password	= \System::saveString( \System::formGet( 'email_password' ) );
		\admin\factory\SettingManager::saveParam( 'email_password' , $email_password );

		$google_map_key	= \System::saveString( \System::formGet( 'google_map_key' ) );
		\admin\factory\SettingManager::saveParam( 'google_map_key' , $google_map_key );

		$user_register = \System::saveString( \System::formGet( 'user_register' ) );
		\admin\factory\SettingManager::saveParam( 'user_register' , $user_register );

		$contact_form = \System::saveString( \System::formGet( 'contact_form' ) );
		\admin\factory\SettingManager::saveParam( 'contact_form' , $contact_form );

		$visit_count = \System::saveString( \System::formGet( 'visit_count' ) );
		\admin\factory\SettingManager::saveParam( 'visit_count' , $visit_count );

    $register = \System::formGetInt( 'register' );
    \admin\factory\SettingManager::saveParam( 'register' , $register );

		\System::deleteCacheAdmin();
		\System::deleteCache();
    \System::setAlert( $lang -> getTrans( 'T_USTAWIENIA_ZAPISANE' ) );
	}

	public function saveParam( $param , $value )
	{
		global $db;

		$query = $db -> prepare( 'UPDATE pcms_settings SET value = :value WHERE param = :param' );
		$query -> bindValue( ':value' , $value , \PDO::PARAM_STR );
		$query -> bindValue( ':param' , $param , \PDO::PARAM_STR );
		$query -> execute();
		$query -> closeCursor();
	}
}
?>