Index: extensions/theme_switch/trunk/theme_switch.inc.php
===================================================================
--- extensions/theme_switch/trunk/theme_switch.inc.php	(revision 7072)
+++ extensions/theme_switch/trunk/theme_switch.inc.php	(revision 7093)
@@ -4,5 +4,5 @@
 // | Theme switch plugin                                                   |
 // +-----------------------------------------------------------------------+
-// | Copyright(C) 2008      Pavel Budka                http://pbudka.co.cc |
+// | Copyright(C) 2010      Pavel Budka               http://budkovi.ic.cz |
 // +-----------------------------------------------------------------------+
 // | This program is free software; you can redistribute it and/or modify  |
@@ -22,26 +22,26 @@
 if (!defined('THEME_SWITCH_PATH'))
 define('THEME_SWITCH_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
+
 class theme_controler {
 static public function _switch()
 {
-  global $user, $template, $conf, $lang;
+  global $user, $template, $conf;
+
+  load_language('plugin.lang', dirname(__FILE__).'/');
+
   if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
-  $same = $user['template'].'/'.$user['theme'];
-  if ( isset( $_GET['theme']) and isset( $_GET['template']) )
+  $same = $user['theme'];
+  if ( isset( $_GET['theme']) ) 
   {
-    if ( !empty($_GET['theme']) and !empty($_GET['template']) and
-      file_exists( PHPWG_ROOT_PATH.'template/'.$_GET['template'].'/theme/'.$_GET['theme']) )
+    if ( !empty($_GET['theme']) and
+      file_exists( PHPWG_ROOT_PATH.'themes/'.$_GET['theme']) )
     {
       if (is_a_guest() or is_generic())
-      {
         setcookie( 'pwg_theme_switch', $_GET['theme'],
           time()+60*60*24*30, cookie_path() );
-        setcookie( 'pwg_template_switch', $_GET['template'],
-          time()+60*60*24*30, cookie_path() );
-      }
       else
       {
         $query = 'UPDATE '.USER_INFOS_TABLE.'
-        SET template = \''.$_GET['template'].'/'.$_GET['theme'].'\'
+        SET theme = \''.$_GET['theme'].'\'
         WHERE user_id = '.$user['id'].'
         ;';
@@ -49,5 +49,4 @@
       }
       $user['theme'] = $_GET['theme'];
-      $user['template'] = $_GET['template'];
     }
   }
@@ -56,11 +55,9 @@
   // Guest or generic members will use their cookied $user['template']/$user['theme'] !
   if ((is_a_guest() or is_generic())
-    and isset( $_COOKIE['pwg_theme_switch'] )
-    and isset( $_COOKIE['pwg_template_switch'] ) )
+    and isset( $_COOKIE['pwg_theme_switch'] ) )
   {
-    $user['template'] = $_COOKIE['pwg_template_switch'];
     $user['theme'] = $_COOKIE['pwg_theme_switch'];
   }
-}
+} // function _switch()
 
 static public function _flags()
@@ -69,21 +66,21 @@
 // Gif file name must be the same as theme's name and must be stored in sub directory named according to template's name.  
 {
-  global $user, $template, $lang;
+  global $user, $template, $conf, $lang;
   
   $available_theme = get_pwg_themes();
 
-  $url_starting = get_query_string_diff(array('template', 'theme'));
+  $url_starting = get_query_string_diff(array('theme'));
 
-  foreach ( $available_theme as $code ) {
-    $qlc_img =  'plugins/theme_switch/icons/' . $code . '.gif';
+  foreach ( $available_theme as $theme_id => $theme ) {
+    $qlc_img =  $conf['themes_dir'].'/'.$theme_id.'/'.'screenshot.png';
          
-    if (file_exists(PHPWG_ROOT_PATH.$qlc_img)) {
-      list($temp, $theme) = split('/',$code);
+    if (file_exists($qlc_img)) {
+      
       $qlc_url = str_replace(array('=&amp;','?&amp;'),array('&amp;','?'),
-                 add_url_params( $url_starting, array( 'template' => $temp, 'theme' => $theme  ) ));
+                 add_url_params( $url_starting, array( 'theme' => $theme_id )));
       if (isset($lang['theme']))
-        $qlc_alt = $lang['theme'].': '.ucwords( $code );
+        $qlc_alt = $lang['theme'].': '.ucwords( $theme );
       else
-        $qlc_alt = ucwords( $code );
+        $qlc_alt = ucwords( $theme );
       $qlc_title =  $qlc_alt;
       $qlc = array ( 
@@ -92,9 +89,9 @@
         'img' => $qlc_img,
         );
-      if ( $code !== $user['template'].'/'.$user['theme'])
-        $lsw['flags'][$code] = $qlc ;
+      if ( $theme_id !== $user['theme'])
+        $lsw['flags'][$theme_id] = $qlc ;
       else $lsw['Active'] = $qlc;
       }
-  }
+  } 
     
   $template->set_filename('theme_flags', dirname(__FILE__) . '/flags.tpl');
@@ -107,5 +104,5 @@
   $template->clear_assign('theme_switch');
   $template->concat( 'PLUGIN_INDEX_ACTIONS', $flags);
-}
+} // function _flags()
 
 static public function _select()
@@ -116,27 +113,37 @@
   
   $available_theme = get_pwg_themes();
-  $url_starting = get_query_string_diff(array('lang'));
+  $url_starting = get_query_string_diff(array('theme'));
   $options='<li><span class="property">
    <label for="template">'.$lang['theme'].'</label>
   </span>
   <select name="template" onchange="javasript:window.location=this.value">';
-  foreach ( $available_theme as $code )
+  foreach ( $available_theme as $theme_id => $theme )
   {
-    list($temp, $theme) = split('/',$code);
     $qlc_url = str_replace(array('=&amp;','?&amp;'),array('&amp;','?'),
-      add_url_params( $url_starting, array( 'template' => $temp, 'theme' => $theme  ) ));
+      add_url_params( $url_starting, array( 'theme' => $theme_id  ) ));
     
-    if ( $code == $user['template'].'/'.$user['theme'] )
+    if ( $theme_id == $user['theme'] )
       $tmp='" selected="selected">';
     else
       $tmp='">';
     $options=$options.'
-    <option label="'.$code.'" value="'.$qlc_url.$tmp.$code.'</option>';
+    <option label="'.$theme.'" value="'.$qlc_url.$tmp.$theme.'</option>';
   }
   $options=$options.'
   </select></li>';
   $template->concat( 'PLUGIN_INDEX_ACTIONS',$options);
-}
-}
+} //  function _select() 
+
+static public function _theme_admin($menu)
+// adds menu options for future configuration 
+{
+//  load_language('plugin.lang', dirname(__FILE__).'/');
+  array_push($menu, array('NAME' => 'Theme Switch',
+    'URL' => get_admin_plugin_menu_link(THEME_SWITCH_PATH.'admin/admin.php')));
+  return $menu;
+} // function _theme_admin()
+
+} // class theme_controler
+
   /* {html_head} usage function */
   /* See flags.tpl for example (due no catenation available) */
@@ -145,3 +152,4 @@
     { return file_exists( $path . $file); }
 }
+
 ?>
