Index: mobile_tools.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mobile_tools/mobile_tools.install,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 mobile_tools.install
--- mobile_tools.install	28 Oct 2009 03:28:35 -0000	1.1.2.3
+++ mobile_tools.install	16 Jun 2010 13:30:53 -0000
@@ -2,23 +2,21 @@
 // $Id: mobile_tools.install,v 1.1.2.3 2009/10/28 03:28:35 tdrycker Exp $
 /**
  * @file
- *  Mobile Tools installation 
- */ 
+ *  Mobile Tools installation
+ */
 function mobile_tools_install() {
-  drupal_install_schema('mobile_tools');
 }
 
 
 
 function mobile_tools_uninstall() {
-  $query = "SELECT * FROM {mobile_tools_roles_relations}";
-  $result = db_query($query);
-  while ($item = db_fetch_object($result)) {
-    db_query("DELETE FROM {role} WHERE rid = %d", $item->mrid);
+  $result = db_query("SELECT * FROM {mobile_tools_roles_relations}");
+  foreach ($result as $item) {
+    db_delete('role')
+      ->condition('rid', $item->mrid)
+      ->execute();
   }
-  variable_del('default_main_nodes');
-  variable_del('default_main_nodes_original');
-  drupal_uninstall_schema('mobile_tools'); 
+  variable_del('default_nodes_main_mobile');
 }
 
 
@@ -38,5 +36,5 @@ function mobile_tools_schema() {
       )
     ),
   );
-  return $schema; 
-}
\ No newline at end of file
+  return $schema;
+}
Index: mobile_tools.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mobile_tools/mobile_tools.module,v
retrieving revision 1.15.2.48
diff -u -p -r1.15.2.48 mobile_tools.module
--- mobile_tools.module	28 Apr 2010 20:21:47 -0000	1.15.2.48
+++ mobile_tools.module	16 Jun 2010 13:30:54 -0000
@@ -6,24 +6,24 @@
  * - User Agent detection ('mobile' or 'desktop')
  * - automatic redirection towards mobile site or user notification by means of a block message or drupal_set_message
  * - Adding a mobile context to the permission system
- * - Adding a mobile context to theming (= theme switching or seperate configuration for desktop and )     
- *  
+ * - Adding a mobile context to theming (= theme switching or seperate configuration for desktop and )
+ *
  * For more documentation and examples please go to http://drupal.org/node/459686
- */ 
- 
- /* The default messages being displayed to the users . these can be overwritten in 
+ */
+
+ /* The default messages being displayed to the users . these can be overwritten in
   * the configuration panel
-  */    
+  */
  define('MOBILE_NOTIFICATION', '<a href="">Mobile View</a>');
  define('DESKTOP_NOTIFICATION', '<a href="">Regular View</a>');
  include(dirname(__FILE__) . '/mobile_tools_roles.inc');
- 
- /*****************                                   
+
+ /*****************
   * Drupal hooks  *
-  *****************/     
+  *****************/
  /**
  * Implementation of hook_help($section).
- */ 
+ */
 function mobile_tools_help($path, $arg) {
   switch ($path) {
       case 'admin/help#mobile_tools':
@@ -36,35 +36,35 @@ function mobile_tools_help($path, $arg) 
  */
 function mobile_tools_perm() {
   return array('configure Mobile Tools');
-} 
+}
 /**
  * Implementation of hook_menu().
- */ 
+ */
 function mobile_tools_menu() {
-  $items['admin/settings/mobile-tools'] = array(
+  $items['admin/config/mobile-tools'] = array(
     'title' => 'Mobile Tools',
     'description' => t('Configure the detection of the mobile client and the appropriate actions.'),
     'access arguments' => array('configure Mobile Tools'),
     'page callback' => 'drupal_get_form',
     'page arguments' => array('mobile_tools_configuration_form'),
     'type' => MENU_NORMAL_ITEM,
-  );  
-  $items['admin/settings/mobile-tools/device-detection'] = array(
+  );
+  $items['admin/config/mobile-tools/device-detection'] = array(
     'title' => 'Notification / redirection',
     'description' => 'Configure the detection of the mobile client and the appropriate actions (notifications or redirection)',
     'access arguments' => array('configure Mobile Tools'),
     'type' => MENU_DEFAULT_LOCAL_TASK,
     'weight' => -4,
-  );  
-  $items['admin/settings/mobile-tools/themes'] = array(
+  );
+  $items['admin/config/mobile-tools/themes'] = array(
     'title' => 'Theme Switching',
     'page arguments' => array('mobile_tools_themes_configuration_form'),
     'page callback' => 'drupal_get_form',
     'access arguments' => array('configure Mobile Tools'),
     'type' => MENU_LOCAL_TASK,
     'weight' => 0,
-  );  
-  $items['admin/settings/mobile-tools/roles'] = array(
+  );
+  $items['admin/config/mobile-tools/roles'] = array(
     'title' => 'Mobile roles',
     'page arguments' => array('mobile_tools_roles_configuration_form'),
     'page callback' => 'drupal_get_form',
@@ -72,7 +72,7 @@ function mobile_tools_menu() {
     'type' => MENU_LOCAL_TASK,
     'weight' => 0,
   );
-  $items['admin/settings/mobile-tools/ext'] = array(
+  $items['admin/config/mobile-tools/ext'] = array(
     'title' => 'External modules',
     'page arguments' => array('mobile_tools_external_modules_configuration_form'),
     'page callback' => 'drupal_get_form',
@@ -85,13 +85,13 @@ function mobile_tools_menu() {
     'description' => t('Redirect to the mobile site.'),
     'access callback' => TRUE,
     'page callback' => 'mobile_tools_redirect',
-    'type' => MENU_CALLBACK_ITEM,
-  ); 
+    'type' => MENU_CALLBACK,
+  );
   return $items;
-} 
+}
 /**
  * Implementation of hook_exit();
- */ 
+ */
 function mobile_tools_exit() {
   // FIX ME: check what cases don't need this. Bad for performance
   if (variable_get('mobile-tools-theme-switch', '') == 'mobile-tools-mobile-device') {
@@ -100,22 +100,22 @@ function mobile_tools_exit() {
 }
 /**
  *  Implementation of hook_boot().
- */ 
+ */
 function mobile_tools_boot() {
   global $conf, $user, $base_url;
   $_SESSION['mobile-tools-mobile-device'] = mobile_tools_is_mobile_device();
   $_SESSION['mobile-tools-site-type'] = mobile_tools_is_mobile_site();
   // First redirect if needed
-  mobile_tools_redirection_boot();  
+  mobile_tools_redirection_boot();
   // Secondly do the theme switch
-  $theme_switched = mobile_tools_themes_boot(); 
-  
+  $theme_switched = mobile_tools_themes_boot();
+
   if (variable_get('mobile_tools_enable_roles', 0) ) {
     mobile_tools_roles_boot();  // assigns the user the mobile role
   }
   if ($_SESSION['mobile-tools-site-type'] == 'mobile' || $theme_switched) {
-    $conf['default_nodes_main'] = variable_get('default_nodes_main_mobile', 5);
-  } 
+    $conf['default_nodes_main'] = variable_get('default_nodes_main_mobile', 10);
+  }
 }
 
 /******************************
@@ -123,10 +123,10 @@ function mobile_tools_boot() {
  ******************************/
  /**
  * Configuration form for the mobile device detection, redirection and notification
- * 
+ *
  * @return
- *   The configuration form   
- */ 
+ *   The configuration form
+ */
 function mobile_tools_configuration_form() {
   global $base_url;
   $form['mobile_tools_configuration'] = array(
@@ -135,7 +135,7 @@ function mobile_tools_configuration_form
     '#description' => 'Enter the mobile and desktop url for your site. If both urls are equal there will be no redirection, but only theme switching. Go to "theme switching" to configure the theme',
     '#collapsible' => TRUE,
   );
-  
+
   $form['mobile_tools_configuration']['mobile_tools_mobile_url'] = array(
     '#type' => 'textfield',
     '#title' => t('Mobile URL'),
@@ -151,13 +151,13 @@ function mobile_tools_configuration_form
     '#collapsible' => TRUE,
     '#default_value' => variable_get('mobile_tools_desktop_url', $base_url)
   );
-  
+
  $form['mobile_tools_redirection'] = array(
     '#type' => 'fieldset',
     '#title' => t('Redirection options'),
-    '#collapsible' => TRUE,  
+    '#collapsible' => TRUE,
   );
-  
+
   $form['mobile_tools_redirection']['mobile_tools_redirect'] = array(
     '#type' => 'checkbox',
     '#title' => t('Enable automatic redirection of the mobile user'),
@@ -167,28 +167,28 @@ function mobile_tools_configuration_form
     will set a cookie that remembers that the user does not want to be redirected. To undo, send the user to /gomobile. The module will redirect
     the user to the mobile site and reset the cookie!',
   );
-  
+
   $form['mobile_tools_redirection']['mobile_tools_cookie_session'] = array (
     '#type' => 'textfield',
     '#title' => 'Redirection cookie lifetime (seconds)',
     '#description' => t('This field is only used when using the nomobile=true setting. This is the lifetime of the cookie that determines how long the session is remembered. Choose 0 for only the session.'),
     '#default_value' => variable_get('mobile_tools_cookie_session', 3600*24*30),
   );
-  
+
   $form['mobile_tools_redirection']['mobile_tools_redirect_exceptions_type'] = array(
   	'#type' => 'radios',
     '#title' => 'exception type',
     '#options' => array('not-redirect' => 'Do not redirect from the following pages', 'only-redirect' => 'Do only redirect from the following pages' ),
     '#default_value' => variable_get('mobile_tools_redirect_exceptions_type', 'not-redirect'),
   );
-  
+
   $form['mobile_tools_redirection']['mobile_tools_redirect_exceptions'] = array(
   	'#type' => 'textarea',
     '#title' => 'redirection exceptions',
     '#description' => t('Give the paths to pages that should not be redirected. Put each path on a seperate line. The \'*\' character is a wildcard.'),
     '#default_value' => variable_get('mobile_tools_redirect_exceptions', ''),
   );
-  
+
   $form['mobile_tools_notification'] = array(
     '#type' => 'fieldset',
     '#title' => t('Mobile Tools block message options'),
@@ -208,14 +208,14 @@ function mobile_tools_configuration_form
     '#title' => t('On the desktops site'),
     '#rows' => 2,
     '#default_value' => variable_get('desktop_notification', DESKTOP_NOTIFICATION),
-  ); 
-  
+  );
+
   $form['extra'] = array(
     '#type' => 'fieldset',
     '#title' => 'extra',
     '#collapsible' => TRUE,
   );
-  
+
 
   $form['extra']['default_nodes_main_mobile'] = array(
       '#type' => 'select',
@@ -244,7 +244,7 @@ function mobile_tools_configuration_form
 
 /**
  * Configuration of external modules
- *  
+ *
  */
 function mobile_tools_external_modules_configuration_form() {
   $form['mobile_tools_detection'] = array(
@@ -267,7 +267,7 @@ function mobile_tools_external_modules_c
     '#options' => _mobile_tools_external('site-type-detection'),
     '#description' => 'This option is only used when your Drupal site is used for both the mobile as desktop version of the site.'
   );
-  
+
   $device_capability =  _mobile_tools_external('device-capability');
   $mess = '';
   if (count($device_capability) == 0) {
@@ -282,23 +282,24 @@ function mobile_tools_external_modules_c
     '#description' => t('The mobile tools module gives an abstract api in order to get capabilities of the mobile devices. These capability can be fetched by calling mobile_tools_devicecapability($capability). Capability can be for example "is_wireless_device". A full range of parameters can be found on !wurfl you need at least one capability module (like !wurfl2) to use this functionality', array('!wurfl' => l('http://wurfl.sourceforge.net/help_doc.php', 'http://wurfl.sourceforge.net/help_doc.php'), '!wurfl2' => l('http://drupal.org/project/wurfl', 'http://drupal.org/project/wurfl')))
   );
   return system_settings_form($form);
-} 
+}
 
 /**
  * Configuration form for configuring the mobile context in the theming system
- */ 
+ */
 function mobile_tools_themes_configuration_form() {
   $themes = mobile_tools_list_theme_names();
   $prefix = '';
+  $warning = '';
   if (count($themes) == 0) {
     $warning = '<div class="message error">You must enable themes in order to use theme switching</div>';
-  }   
+  }
 
   $form['mobile_tools_theme_configuration'] = array(
     '#type' => 'fieldset',
     '#title' => 'Theming configuration',
     '#collapsible' => TRUE,
-    '#description' => t('You can assign a variation of your current theme to all mobile users . this allows you to configure your theme 
+    '#description' => t('You can assign a variation of your current theme to all mobile users . this allows you to configure your theme
     specific for mobile users. See !url for more information on this configuration. In order to use this functionality
     you will have to manually create a second *.info file in your theme directory.', array('!url' => l('help', 'help'))),
     '#suffix' => t('If enabled, !configure the settings of your mobile theme and manage the !blocks layout', array('!configure' => l('configure', 'admin/build/themes'), '!blocks' => l('blocks', 'admin/build/block'))) .'<br>',
@@ -331,7 +332,7 @@ function mobile_tools_themes_configurati
         '#type' => 'fieldset',
         '#title' => $group_title,
         '#collapsible' => TRUE,
-        
+
       );
       $form['mobile_tools_theme_configuration'][$mobile_detection_module . '_' . $group][$mobile_detection_module . '_' . $group . '_enable'] = array(
         '#type' => 'checkbox',
@@ -346,49 +347,49 @@ function mobile_tools_themes_configurati
          '#options' => $themes,
          '#description' => t('Select your mobile theme. See <a href="">help</a> for information on the name'),
       );
-     } 
+     }
    }
    return system_settings_form($form);
 }
 /**
  * Helper function to return the configuration options
- */ 
+ */
 function mobile_tools_configuration_options($configuration) {
   switch ($configuration) {
     case 'device handling':
       $options = array(
-        'nothing' => t('Do nothing, just provide the $_SESSION[\'mobile_device\'] variable'), 
-        'redirect' => t('Automatic redirection to mobile or desktop site'), 
+        'nothing' => t('Do nothing, just provide the $_SESSION[\'mobile_device\'] variable'),
+        'redirect' => t('Automatic redirection to mobile or desktop site'),
       //  'notification' => t('Display a block notification with link to mobile site'),
-      //  'theme-switch' => t('Switch the theme when a mobile user visits the site (only 1 url for both mobile and desktop url). Enable and configure the mobile theme !here', array('!here' => l('here', 'admin/settings/mobile-tools/themes'))),
+      //  'theme-switch' => t('Switch the theme when a mobile user visits the site (only 1 url for both mobile and desktop url). Enable and configure the mobile theme !here', array('!here' => l('here', 'admin/config/mobile-tools/themes'))),
       );
     break;
     case 'site type':
       $options =  array(
-        'mobile' => t('Only the mobile site'),  
-        'desktop' => t('only the deskop site'), 
+        'mobile' => t('Only the mobile site'),
+        'desktop' => t('only the deskop site'),
         'mobile-desktop' => t('for both mobile and desktop site'),
       );
     break;
-  }  
+  }
   return $options;
 }
 
 /**
  *  Helper function to return the options for definition of the Drupal usage
- */ 
+ */
 function mobile_tools_site_type_options() {
-  $options = array('mobile' => t('Only the mobile site'),  'desktop' => t('only the deskop site'), 'mobile-desktop' => t('for both mobile and desktop site'));  
+  $options = array('mobile' => t('Only the mobile site'),  'desktop' => t('only the deskop site'), 'mobile-desktop' => t('for both mobile and desktop site'));
   return $options;
-} 
+}
 
 /*****************************************
  * Helper functions for device detection *
- *****************************************/ 
+ *****************************************/
 /**
  * Being called in the hook_boot() implementation
- * This function is in charge of device detection, redirection or displaying a notification 
- */ 
+ * This function is in charge of device detection, redirection or displaying a notification
+ */
 function mobile_tools_redirection_boot() {
  global $base_url;
  //only consider redirectoin if the mobile url and the destkop url are different
@@ -400,24 +401,24 @@ function mobile_tools_redirection_boot()
    if (isset($_GET['nomobile'])) {
      if (strtolower($_GET['nomobile']) == 'true') {
         $redirect = 'FALSE';
-        setCookie('mt_redirect', 'false', variable_get('mobile_tools_cookie_lifetime', $session_time) , '/'); 
-      } 
+        setCookie('mt_redirect', 'false', variable_get('mobile_tools_cookie_lifetime', $session_time) , '/');
+      }
       elseif (strtolower($_GET['nomobile']) == 'false') {
         $redirect = 'TRUE';
         setCookie('mt_redirect', 'true', variable_get('mobile_tools_cookie_lifetime',$session_time) , '/');
       }
-   } 
+   }
    else {
       // keep cookie if set, else set to true (default)
       if (!isset($_COOKIE['mt_redirect'])) {
         $redirect = TRUE;
         setCookie('mt_redirect', 'true', $session_time, '/' );
-      } 
+      }
       else {
         $redirect = $_COOKIE['mt_redirect'];
       }
     }
-    
+
     $pages = variable_get('mobile_tools_redirect_exceptions', '');
     $page_match = FALSE;
     if(isset($_GET['q']) && $pages != '') {
@@ -434,14 +435,14 @@ function mobile_tools_redirection_boot()
      if (variable_get('mobile_tools_redirect_exceptions', 0) == 'only-redirect') {
         $page_match = !$page_match;
      }
-    // Redirections 
+    // Redirections
     if (variable_get('mobile_tools_redirect', FALSE) && $redirect == 'true' && !$page_match) {
       // The case where a mobile user is accessing the desktop site
       if ($_SESSION['mobile-tools-mobile-device']['type'] == 'mobile' && $_SESSION['mobile-tools-site-type'] == 'desktop') {
           $destination = mobile_tools_get_redirect_url();
           mobile_tools_goto($destination);
-      // The case where a desktop user is accessing the mobile site 
-      } 
+      // The case where a desktop user is accessing the mobile site
+      }
       elseif ($_SESSION['mobile-tools-mobile-device']['type'] == 'desktop' && $_SESSION['mobile-tools-site-type'] == 'mobile') {
          $destination =  variable_get('mobile_tools_desktop_url', $base_url);
          mobile_tools_goto($destination);
@@ -456,9 +457,9 @@ function mobile_tools_redirection_boot()
 function mobile_tools_load_modules() {
   $device_detection = variable_get('mobile-tools-device-detection', 'mobile_tools');
   if ($device_detection != 'mobile_tools') {
-    drupal_load('module', $device_detection); 
-  } 
-} 
+    drupal_load('module', $device_detection);
+  }
+}
 
 /**
  *
@@ -468,18 +469,18 @@ function mobile_tools_is_mobile_device()
   drupal_load('module', $device_detection);
   if ($device_detection != 'mobile_tools') {
     return module_invoke($device_detection, 'is_mobile_device');
-  } 
+  }
   else {
     return _mobile_tools_is_mobile_device();
   }
-} 
+}
 /**
  *  Implementation of hook_is_mobile_device()
- */ 
+ */
 function _mobile_tools_is_mobile_device() {
   $mobile_browser   = array('type' => 'desktop', 'group' => ''); // set mobile browser as FALSE till we can prove otherwise
   if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
-	    $user_agent = $_SERVER['HTTP_USER_AGENT']; 
+	    $user_agent = $_SERVER['HTTP_USER_AGENT'];
 	  } else {
 	    return FALSE;
 	  }
@@ -490,8 +491,8 @@ function _mobile_tools_is_mobile_device(
 	  } else {
 	  	$accept = '';
 	  }
-  
-  switch (TRUE) { 
+
+  switch (TRUE) {
     case (FALSE !== stripos($user_agent, 'ipad'));
       $mobile_browser = array('type' => 'desktop', 'group' => 'ipad');
       break;
@@ -512,7 +513,7 @@ function _mobile_tools_is_mobile_device(
     break; // break out and skip the rest if we've had a match on blackberry
     case (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|pda|psp|treo)/i',$user_agent)); // check if any of the values listed create a match on the user agent - these are some of the most common terms used in agents to identify them as being mobile devices - the i at the end makes it case insensitive
       $mobile_browser = array('type' => 'mobile', 'group' => ''); // set mobile browser to TRUE
-    break; // break out and skip the rest if we've preg_match on the user agent returned TRUE 
+    break; // break out and skip the rest if we've preg_match on the user agent returned TRUE
     case ((strpos($accept,'text/vnd.wap.wml')>0)||(strpos($accept,'application/vnd.wap.xhtml+xml')>0)); // is the device showing signs of support for text/vnd.wap.wml or application/vnd.wap.xhtml+xml
       $mobile_browser = array('type' => 'mobile', 'group' => ''); // set mobile browser to TRUE
     break; // break out and skip the rest if we've had a match on the content accept headers
@@ -520,12 +521,12 @@ function _mobile_tools_is_mobile_device(
       $mobile_browser = array('type' => 'mobile', 'group' => ''); // set mobile browser to TRUE
     break; // break out and skip the final step if we've had a return TRUE on the mobile specfic headers
     case (in_array(strtolower(substr($user_agent,0,4)),array('1207'=>'1207','3gso'=>'3gso','4thp'=>'4thp','501i'=>'501i','502i'=>'502i','503i'=>'503i','504i'=>'504i','505i'=>'505i','506i'=>'506i','6310'=>'6310','6590'=>'6590','770s'=>'770s','802s'=>'802s','a wa'=>'a wa','acer'=>'acer','acs-'=>'acs-','airn'=>'airn','alav'=>'alav','asus'=>'asus','attw'=>'attw','au-m'=>'au-m','aur '=>'aur ','aus '=>'aus ','abac'=>'abac','acoo'=>'acoo','aiko'=>'aiko','alco'=>'alco','alca'=>'alca','amoi'=>'amoi','anex'=>'anex','anny'=>'anny','anyw'=>'anyw','aptu'=>'aptu','arch'=>'arch','argo'=>'argo','bell'=>'bell','bird'=>'bird','bw-n'=>'bw-n','bw-u'=>'bw-u','beck'=>'beck','benq'=>'benq','bilb'=>'bilb','blac'=>'blac','c55/'=>'c55/','cdm-'=>'cdm-','chtm'=>'chtm','capi'=>'capi','comp'=>'comp','cond'=>'cond','craw'=>'craw','dall'=>'dall','dbte'=>'dbte','dc-s'=>'dc-s','dica'=>'dica','ds-d'=>'ds-d','ds12'=>'ds12','dait'=>'dait','devi'=>'devi','dmob'=>'dmob','doco'=>'doco','dopo'=>'dopo','el49'=>'el49','erk0'=>'erk0','esl8'=>'esl8','ez40'=>'ez40','ez60'=>'ez60','ez70'=>'ez70','ezos'=>'ezos','ezze'=>'ezze','elai'=>'elai','emul'=>'emul','eric'=>'eric','ezwa'=>'ezwa','fake'=>'fake','fly-'=>'fly-','fly_'=>'fly_','g-mo'=>'g-mo','g1 u'=>'g1 u','g560'=>'g560','gf-5'=>'gf-5','grun'=>'grun','gene'=>'gene','go.w'=>'go.w','good'=>'good','grad'=>'grad','hcit'=>'hcit','hd-m'=>'hd-m','hd-p'=>'hd-p','hd-t'=>'hd-t','hei-'=>'hei-','hp i'=>'hp i','hpip'=>'hpip','hs-c'=>'hs-c','htc '=>'htc ','htc-'=>'htc-','htca'=>'htca','htcg'=>'htcg','htcp'=>'htcp','htcs'=>'htcs','htct'=>'htct','htc_'=>'htc_','haie'=>'haie','hita'=>'hita','huaw'=>'huaw','hutc'=>'hutc','i-20'=>'i-20','i-go'=>'i-go','i-ma'=>'i-ma','i230'=>'i230','iac'=>'iac','iac-'=>'iac-','iac/'=>'iac/','ig01'=>'ig01','im1k'=>'im1k','inno'=>'inno','iris'=>'iris','jata'=>'jata','java'=>'java','kddi'=>'kddi','kgt'=>'kgt','kgt/'=>'kgt/','kpt '=>'kpt ','kwc-'=>'kwc-','klon'=>'klon','lexi'=>'lexi','lg g'=>'lg g','lg-a'=>'lg-a','lg-b'=>'lg-b','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-f'=>'lg-f','lg-g'=>'lg-g','lg-k'=>'lg-k','lg-l'=>'lg-l','lg-m'=>'lg-m','lg-o'=>'lg-o','lg-p'=>'lg-p','lg-s'=>'lg-s','lg-t'=>'lg-t','lg-u'=>'lg-u','lg-w'=>'lg-w','lg/k'=>'lg/k','lg/l'=>'lg/l','lg/u'=>'lg/u','lg50'=>'lg50','lg54'=>'lg54','lge-'=>'lge-','lge/'=>'lge/','lynx'=>'lynx','leno'=>'leno','m1-w'=>'m1-w','m3ga'=>'m3ga','m50/'=>'m50/','maui'=>'maui','mc01'=>'mc01','mc21'=>'mc21','mcca'=>'mcca','medi'=>'medi','meri'=>'meri','mio8'=>'mio8','mioa'=>'mioa','mo01'=>'mo01','mo02'=>'mo02','mode'=>'mode','modo'=>'modo','mot '=>'mot ','mot-'=>'mot-','mt50'=>'mt50','mtp1'=>'mtp1','mtv '=>'mtv ','mate'=>'mate','maxo'=>'maxo','merc'=>'merc','mits'=>'mits','mobi'=>'mobi','motv'=>'motv','mozz'=>'mozz','n100'=>'n100','n101'=>'n101','n102'=>'n102','n202'=>'n202','n203'=>'n203','n300'=>'n300','n302'=>'n302','n500'=>'n500','n502'=>'n502','n505'=>'n505','n700'=>'n700','n701'=>'n701','n710'=>'n710','nec-'=>'nec-','nem-'=>'nem-','newg'=>'newg','neon'=>'neon','netf'=>'netf','noki'=>'noki','nzph'=>'nzph','o2 x'=>'o2 x','o2-x'=>'o2-x','opwv'=>'opwv','owg1'=>'owg1','opti'=>'opti','oran'=>'oran','p800'=>'p800','pand'=>'pand','pg-1'=>'pg-1','pg-2'=>'pg-2','pg-3'=>'pg-3','pg-6'=>'pg-6','pg-8'=>'pg-8','pg-c'=>'pg-c','pg13'=>'pg13','phil'=>'phil','pn-2'=>'pn-2','ppc;'=>'ppc;','pt-g'=>'pt-g','palm'=>'palm','pana'=>'pana','pire'=>'pire','pock'=>'pock','pose'=>'pose','psio'=>'psio','qa-a'=>'qa-a','qc-2'=>'qc-2','qc-3'=>'qc-3','qc-5'=>'qc-5','qc-7'=>'qc-7','qc07'=>'qc07','qc12'=>'qc12','qc21'=>'qc21','qc32'=>'qc32','qc60'=>'qc60','qci-'=>'qci-','qwap'=>'qwap','qtek'=>'qtek','r380'=>'r380','r600'=>'r600','raks'=>'raks','rim9'=>'rim9','rove'=>'rove','s55/'=>'s55/','sage'=>'sage','sams'=>'sams','sc01'=>'sc01','sch-'=>'sch-','scp-'=>'scp-','sdk/'=>'sdk/','se47'=>'se47','sec-'=>'sec-','sec0'=>'sec0','sec1'=>'sec1','semc'=>'semc','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','sk-0'=>'sk-0','sl45'=>'sl45','slid'=>'slid','smb3'=>'smb3','smt5'=>'smt5','sp01'=>'sp01','sph-'=>'sph-','spv '=>'spv ','spv-'=>'spv-','sy01'=>'sy01','samm'=>'samm','sany'=>'sany','sava'=>'sava','scoo'=>'scoo','send'=>'send','siem'=>'siem','smar'=>'smar','smit'=>'smit','soft'=>'soft','sony'=>'sony','t-mo'=>'t-mo','t218'=>'t218','t250'=>'t250','t600'=>'t600','t610'=>'t610','t618'=>'t618','tcl-'=>'tcl-','tdg-'=>'tdg-','telm'=>'telm','tim-'=>'tim-','ts70'=>'ts70','tsm-'=>'tsm-','tsm3'=>'tsm3','tsm5'=>'tsm5','tx-9'=>'tx-9','tagt'=>'tagt','talk'=>'talk','teli'=>'teli','topl'=>'topl','tosh'=>'tosh','up.b'=>'up.b','upg1'=>'upg1','utst'=>'utst','v400'=>'v400','v750'=>'v750','veri'=>'veri','vk-v'=>'vk-v','vk40'=>'vk40','vk50'=>'vk50','vk52'=>'vk52','vk53'=>'vk53','vm40'=>'vm40','vx98'=>'vx98','virg'=>'virg','vite'=>'vite','voda'=>'voda','vulc'=>'vulc','wapj'=>'wapj','wapp'=>'wapp','wapu'=>'wapu','wapm'=>'wapm','wig '=>'wig ','wapi'=>'wapi','wapr'=>'wapr','wapv'=>'wapv','wapy'=>'wapy','wapa'=>'wapa','waps'=>'waps','wapt'=>'wapt','winc'=>'winc','winw'=>'winw','wonu'=>'wonu','x700'=>'x700','xda2'=>'xda2','xdag'=>'xdag','yas-'=>'yas-','your'=>'your','zte-'=>'zte-','zeto'=>'zeto','acs-'=>'acs-','alav'=>'alav','alca'=>'alca','amoi'=>'amoi','aste'=>'aste','audi'=>'audi','avan'=>'avan','benq'=>'benq','bird'=>'bird','blac'=>'blac','blaz'=>'blaz','brew'=>'brew','brvw'=>'brvw','bumb'=>'bumb','ccwa'=>'ccwa','cell'=>'cell','cldc'=>'cldc','cmd-'=>'cmd-','dang'=>'dang','doco'=>'doco','eml2'=>'eml2','eric'=>'eric','fetc'=>'fetc','hipt'=>'hipt','http'=>'http','ibro'=>'ibro','idea'=>'idea','ikom'=>'ikom','inno'=>'inno','ipaq'=>'ipaq','jbro'=>'jbro','jemu'=>'jemu','java'=>'java','jigs'=>'jigs','kddi'=>'kddi','keji'=>'keji','kyoc'=>'kyoc','kyok'=>'kyok','leno'=>'leno','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-g'=>'lg-g','lge-'=>'lge-','libw'=>'libw','m-cr'=>'m-cr','maui'=>'maui','maxo'=>'maxo','midp'=>'midp','mits'=>'mits','mmef'=>'mmef','mobi'=>'mobi','mot-'=>'mot-','moto'=>'moto','mwbp'=>'mwbp','mywa'=>'mywa','nec-'=>'nec-','newt'=>'newt','nok6'=>'nok6','noki'=>'noki','o2im'=>'o2im','opwv'=>'opwv','palm'=>'palm','pana'=>'pana','pant'=>'pant','pdxg'=>'pdxg','phil'=>'phil','play'=>'play','pluc'=>'pluc','port'=>'port','prox'=>'prox','qtek'=>'qtek','qwap'=>'qwap','rozo'=>'rozo','sage'=>'sage','sama'=>'sama','sams'=>'sams','sany'=>'sany','sch-'=>'sch-','sec-'=>'sec-','send'=>'send','seri'=>'seri','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','siem'=>'siem','smal'=>'smal','smar'=>'smar','sony'=>'sony','sph-'=>'sph-','symb'=>'symb','t-mo'=>'t-mo','teli'=>'teli','tim-'=>'tim-','tosh'=>'tosh','treo'=>'treo','tsm-'=>'tsm-','upg1'=>'upg1','upsi'=>'upsi','vk-v'=>'vk-v','voda'=>'voda','vx52'=>'vx52','vx53'=>'vx53','vx60'=>'vx60','vx61'=>'vx61','vx70'=>'vx70','vx80'=>'vx80','vx81'=>'vx81','vx83'=>'vx83','vx85'=>'vx85','wap-'=>'wap-','wapa'=>'wapa','wapi'=>'wapi','wapp'=>'wapp','wapr'=>'wapr','webc'=>'webc','whit'=>'whit','winw'=>'winw','wmlb'=>'wmlb','xda-'=>'xda-',))); // check against a list of trimmed user agents to see if we find a match
-       if (!ereg("w3c_css_validator", strtolower($user_agent))) {        
+       if (!ereg("w3c_css_validator", strtolower($user_agent))) {
        		$mobile_browser = array('type' => 'mobile', 'group' => ''); // set mobile browser to TRUE
        }
     break; // break even though it's the last statement in the switch so there's nothing to break away from but it seems better to include it than exclude it
-  } // ends the switch 
-  
+  } // ends the switch
+
    $result = $mobile_browser;
    return $result;
 }
@@ -536,29 +537,29 @@ function _mobile_tools_is_mobile_device(
  */
 function mobile_tools_devicecapability($capability) {
    return module_invoke(variable_get('mobile-tools-device-capability', 'wurfl'), 'devicecapability', $capability);
-}  
+}
 
 /**
  * Calling the device groups, check first if third party module registered
- * for doing the device detection 
+ * for doing the device detection
  */
 function mobile_tools_device_groups() {
   $device_detection = variable_get('mobile-tools-device-detection', 'mobile_tools');
   if ($device_detection != 'mobile_tools') {
     return module_invoke($device_detection, 'device_groups');
-  } 
+  }
   else {
     return _mobile_tools_device_groups();
   }
-}  
+}
 /**
  *  implementation of the hook_device_groups()
  *  This function returns the different device groups where this module can make a distinction for. This can be used
- *  to select different themes for different device groups.   
+ *  to select different themes for different device groups.
  */
 function _mobile_tools_device_groups() {
 return array('iphone'=>'iPhone', 'ipod'=>'iPod', 'ipad'=>'iPad', 'android'=>'Android', 'opera_mini'=>'Opera Mini', 'blackberry'=>'BlackBerry');
-} 
+}
 
 /*****************************************
  * Helper function for user notification *
@@ -566,8 +567,8 @@ return array('iphone'=>'iPhone', 'ipod'=
 /**
  * Implementation of hook_block()
  * Provides the blocks that can be used to show a message to the user to go to the
- * mobile or desktop version.  
- */ 
+ * mobile or desktop version.
+ */
 function mobile_tools_block($op = 'list',  $delta = 0, $edit = array()) {
    switch ($op) {
     case 'list':
@@ -577,30 +578,30 @@ function mobile_tools_block($op = 'list'
       break;
     case 'view':
         $block['content'] = _mobile_tools_message();
-        return $block;        
+        return $block;
       break;
    }
-} 
+}
 
 /**
  *  Helper function returning the configurable message for the notification
- */ 
+ */
 function _mobile_tools_message() {
   if (variable_get('mobile_tools_mobile_url', '') != variable_get('mobile_tools_desktop_url', '')) {
     if ($_SESSION['mobile-tools-site-type']  == 'mobile' ) {
       return variable_get('mobile_notification', MOBILE_NOTIFICATION);
-    } 
+    }
     else {
       return variable_get('desktop_notification', DESKTOP_NOTIFICATION);
     }
-  } 
+  }
   else {
    if ($_SESSION['mobile-tools-mobile-device']['type']  == 'mobile' ) {
       return variable_get('mobile_notification', MOBILE_NOTIFICATION);
-    } 
+    }
     else {
       return variable_get('desktop_notification', DESKTOP_NOTIFICATION);
-    } 
+    }
   }
 }
 /****************************************
@@ -608,8 +609,8 @@ function _mobile_tools_message() {
 /****************************************/
 /**
  * Being called in the hook_init() implementation
- * This function is in charge of changing to the mobile theme 
- */ 
+ * This function is in charge of changing to the mobile theme
+ */
 function mobile_tools_themes_boot() {
   global $conf;
   if (variable_get('mobile-tools-theme-switch', '') == 'mobile-tools-mobile-device') {
@@ -623,7 +624,7 @@ function mobile_tools_themes_boot() {
     if (variable_get($mobile_detection_module . '_' . $group . '_enable', '') == 1) {
       $conf['theme_default'] = variable_get($mobile_detection_module . '_' . $group . '_theme', $conf['theme_default']);
       return TRUE;
-    } 
+    }
     else {
       $conf['theme_default'] = variable_get('mobile_tools_theme_name', $conf['theme_default']);
       return TRUE;
@@ -634,7 +635,7 @@ function mobile_tools_themes_boot() {
 
 /**
  * Function returning the available themes
- */ 
+ */
 function mobile_tools_list_theme_names() {
   global $conf;
   $themes = list_themes();
@@ -642,11 +643,11 @@ function mobile_tools_list_theme_names()
   foreach ($themes as $key => $value ) {
     if ($value->status == 1 ) {
       $list[] = $key;
-    }    
+    }
   }
   if (count($list) == 0) {
     return array();
-  } 
+  }
   else {
     return array_combine($list, $list);
   }
@@ -654,11 +655,11 @@ function mobile_tools_list_theme_names()
 
 /**********************************************************
  * Helper function to integrate with third party modules  *
- **********************************************************/ 
+ **********************************************************/
 /**
- *  Help function that retrieves the modules that implement the 
- *  hook_is_mobile_device() or hook_is_mobile_site() hooks. 
- */  
+ *  Help function that retrieves the modules that implement the
+ *  hook_is_mobile_device() or hook_is_mobile_site() hooks.
+ */
 function _mobile_tools_external($type) {
   switch ($type) {
     case 'device-detection':
@@ -672,20 +673,19 @@ function _mobile_tools_external($type) {
       $modules = mobile_tools_get_module_names(module_implements('devicecapability'));
       unset($modules['mobile_tools']);
     break;
-  }  
+  }
   return $modules;
-} 
+}
 /**
  * return the human readable name of the modules
- */ 
+ */
 function mobile_tools_get_module_names($array) {
   $output = array();
   foreach ($array as $module) {
-    $query = "SELECT * FROM {system} WHERE type = '%s' AND name = '%s'";
-    $result = db_query($query, 'module', $module);
-    $item = db_fetch_object($result);
-    $info = unserialize($item->info);
-    $output[$module] = $info['name']; 
+    if ($item = db_query("SELECT * FROM {system} WHERE type = :type AND name = :name", array(':type' => 'module', ':name' => $module))->fetchObject()) {
+      $info = unserialize($item->info);
+      $output[$module] = $info['name'];
+    }
   }
   return $output;
 }
@@ -693,23 +693,23 @@ function mobile_tools_get_module_names($
 
 /*****************************************************************************
  * Helper function to detect if site is being served as mobile or as destkop *
- ***************************************************************************** 
+ *****************************************************************************
 /**
  *  Detection of the site type . the values comes out the configuration form.
- */ 
+ */
 function mobile_tools_is_mobile_site() {
   $site_detection = variable_get('mobile-tools-site-type-detection', 'mobile_tools');
   drupal_load('module', $site_detection);
    if ($site_detection == 'mobile_tools') {
       return _mobile_tools_site_detection();;
-   } 
+   }
    else {
-      return module_invoke($site_detection, 'is_mobile_site'); 
+      return module_invoke($site_detection, 'is_mobile_site');
    }
 }
 
 function _mobile_tools_site_detection() {
-  global $base_url;    
+  global $base_url;
    $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
     // first check if the url is a m.* or .mobi url. This is robuts
   $server_domain_elements = explode('.', $host);
@@ -728,23 +728,23 @@ function _mobile_tools_site_detection() 
   $desktop = variable_get('mobile_tools_desktop_url', $base_url);
   $desktop_url = parse_url($desktop);
   $desktop_url['host'] = mobile_tools_prepare_url($desktop_url['host']);
-  
+
   if (!array_key_exists('path', $desktop_url)) {
     $desktop_url['path'] = '';
   }
   if (!array_key_exists('path', $mobile_url)) {
     $mobile_url['path'] = '';
-  }  
-   
+  }
+
   $server_name = mobile_tools_prepare_url($_SERVER['SERVER_NAME']);
   // Check domain first
-  if ($mobile_url['host'] == $server_name && $desktop_url['host'] != $server_name) {      
+  if ($mobile_url['host'] == $server_name && $desktop_url['host'] != $server_name) {
     return 'mobile';
-  } 
+  }
   elseif ($mobile_url['host'] != $server_name && $desktop_url['host'] == $server_name) {
     return 'desktop';
-  } 
-  
+  }
+
   // find longest url
   $longest_url = strlen($mobile) > strlen($desktop) ? $mobile : $desktop ;
   $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
@@ -752,22 +752,22 @@ function _mobile_tools_site_detection() 
   $pos = strpos($uri, preg_replace('{/$}', '', $longest_url));
   if ($pos === FALSE) {
     return $longest_url == $mobile ? 'desktop' : 'mobile';
-  } 
+  }
   else {
     return $longest_url == $mobile ? 'mobile' : 'desktop';
   }
 }
 /**
  *  This function does some kind of normalisation of the urls when there is no subdomain available in the url
- *  e.g. domain.com becomes www.domain.com . this is because sometimes both www.domain.com and domain.com are the same 
- */ 
+ *  e.g. domain.com becomes www.domain.com . this is because sometimes both www.domain.com and domain.com are the same
+ */
 function mobile_tools_prepare_url($url) {
   $_url = parse_url($url);
   $_url = $url['host'];
   $_url = explode(".", $_url);
   if (count($_url) == 2) {
     return 'www'. implode("."  , $_url);
-  } 
+  }
   else {
     return $url;
   }
@@ -776,17 +776,16 @@ function mobile_tools_prepare_url($url) 
 
 /**
  * Altering the form for theme configuration to indicate that the theme is being used
- * as a mobile theme. 
- */ 
+ * as a mobile theme.
+ */
 function mobile_tools_form_alter(&$form, $form_state, $form_id) {
+  dsm($form_id);
   switch ($form_id) {
      case 'user_admin_role':
-      $query = "SELECT COUNT(*) as count FROM {mobile_tools_roles_relations} WHERE mrid = %d";
-      $result = db_query($query, arg(4));
-      $item= db_fetch_object($result);
+      $item = db_query("SELECT COUNT(*) as count FROM {mobile_tools_roles_relations} WHERE mrid = :mrid", array(':mrid' => arg(5)))->fetchObject();
       if (isset($item)) {
         if ($item->count == 0) {
-          $form['mobile_tools_configure_role_'. arg(4)] = array(
+          $form['mobile_tools_configure_role_'. arg(5)] = array(
             '#type' => 'checkbox',
             '#title' => t('Create a mobile context for this user role'),
             '#default_value' => TRUE,
@@ -796,24 +795,24 @@ function mobile_tools_form_alter(&$form,
             '#type' => 'hidden',
             '#value' => 'desktop'
           );
-        } 
+        }
         else {
           $form['mobile_tools_role_type'] = array(
             '#type' => 'hidden',
             '#value' => 'mobile'
           );
         }
-      $form['#submit'][] = 'mobile_tools_roles_configuration_submit';
+        $form['#submit'][] = 'mobile_tools_roles_configuration_submit';
       }
       break;
     case 'user_profile_form':
         // We make sure that the mobile roles are not being displayed
         $mobile_roles = mobile_tools_mobile_user_roles();
         foreach($mobile_roles as $rid => $role) {
-          unset($form['account']['roles']['#options'][$rid]);
+         unset($form['account']['roles']['#options'][$rid]);
         }
       break;
-    case 'node_configure':
+    case 'system_site_information_settings':
       $form['default_nodes_main_mobile'] = array(
             '#type' => 'select',
             '#title' => t('Number of posts on main page for the mobile version'),
@@ -836,22 +835,17 @@ function mobile_tools_form_alter(&$form,
                 ),
             '#description' => t('The default maximum number of posts to display per page on overview pages such as the main page (on Mobile).'),
         );
-         $form['#submit'][] = 'mobile_tools_node_configuration_submit';
-  } 
-//
+  }
 }
 
-function mobile_tools_node_configuration_submit($form) {
-  variable_set('default_nodes_main_original', $form['#post']['default_nodes_main']);
-}
 
 /**
  * Helper function to assist in making a mobile url (m.*) from a given url
- * 
+ *
  * @parm $url
  *  orginal url
  * @return
- *  the mobile url     
+ *  the mobile url
  */
 function mobile_tools_create_mobile_url($url) {
   $url_parsed = parse_url($url);
@@ -863,21 +857,21 @@ function mobile_tools_create_mobile_url(
   if (count($url) == 3 ) {
     $url[0] = 'm';
     return 'http://'. implode('.', $url)  . $url_parsed['path'];
-  } 
+  }
   elseif (count($url) == 2) {
     return 'http://m.'. implode('.', $url)  . $url_parsed['path'];
-  } 
+  }
   else {
     return 'http://'.  implode('.', $url)  . $url_parsed['path'] .'/mobile';
   }
-}  
- 
+}
+
 
 
 
 /**
  *  To be implemented: create a list of non-compatible modules
- */ 
+ */
 function mobile_tools_compatibility() {
   return array(
     'themekey',
@@ -887,9 +881,9 @@ function mobile_tools_compatibility() {
 }
 
 /**
- *  Redirection to the mobile site while updating the $_SESSION variable to retain the last 
- *  chosen option 
- */ 
+ *  Redirection to the mobile site while updating the $_SESSION variable to retain the last
+ *  chosen option
+ */
 function mobile_tools_redirect() {
   drupal_goto(variable_get('mobile_tools_mobile_url', ''), 'nomobile=true');
 }
@@ -936,23 +930,23 @@ function mobile_tools_ctools_plugin_dire
 }
 
 /**
- * Creation of the redirect url. Special care to create the correct url that will 
- * cause the Global Redirect module not to redirect!  
- */ 
+ * Creation of the redirect url. Special care to create the correct url that will
+ * cause the Global Redirect module not to redirect!
+ */
 function mobile_tools_get_redirect_url() {
   include_once './includes/bootstrap.inc';
   drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
-  // special Siruna delimitor 
+  // special Siruna delimitor
   // collect query parameters
    if(drupal_is_front_page()) {
     return variable_get('mobile_tools_mobile_url', '');
    }
-  
+
   $query = array();
   foreach ($_GET as $key => $value) {
     if ($key != 'q') {
       $query[] =  $key . '=' . $value;
-    }    
+    }
   }
   $query = (count($query) > 0) ? implode('&', $query) : '';
   //create the path and reassemble
Index: mobile_tools_roles.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mobile_tools/Attic/mobile_tools_roles.inc,v
retrieving revision 1.1.2.7
diff -u -p -r1.1.2.7 mobile_tools_roles.inc
--- mobile_tools_roles.inc	26 Apr 2010 20:14:41 -0000	1.1.2.7
+++ mobile_tools_roles.inc	16 Jun 2010 13:30:54 -0000
@@ -2,14 +2,14 @@
 // $Id: mobile_tools_roles.inc,v 1.1.2.7 2010/04/26 20:14:41 tdrycker Exp $
 /**
  * Being called in the hook_init() implementation
- * This function is in charge of changing the user role 
- */ 
+ * This function is in charge of changing the user role
+ */
 function mobile_tools_roles_boot() {
   global $user;
   $roles = $user->roles;
 //count the number of mobile roles... must be bigger then 1
-  $item = db_fetch_object(db_query("SELECT COUNT(*) as count FROM {mobile_tools_roles_relations}"));
-   if ($item->count > 0) {
+  $item = db_query("SELECT COUNT(*) as count FROM {mobile_tools_roles_relations}")->fetchObject();
+   if (isset($item) && $item->count > 0) {
     foreach ($roles as $key => $value) {
       $role = mobile_tools_roles_info(array('id' => $key));
       if ($role->type == 'desktop' && $role->has_sibling == 1 && ($_SESSION['mobile-tools-site-type'] == 'mobile' || ($_SESSION['mobile-tools-mobile-device']['type'] == 'mobile' && variable_get('mobile-tools-theme-switch', FALSE) == 'mobile-tools-mobile-device'))) {
@@ -22,8 +22,8 @@ function mobile_tools_roles_boot() {
 
 /**
  *  Implementation of the user_load function to assure that the right role is being assigned to the user.
- *  This is the same actions as in the hook_init() method 
- */ 
+ *  This is the same actions as in the hook_init() method
+ */
 function mobile_tools_user($op, &$edit, &$account, $category = NULL) {
   if(variable_get('mobile_tools_enable_roles', 0)) {
     switch ($op) {
@@ -43,20 +43,19 @@ function mobile_tools_user($op, &$edit, 
 }
 /**
  * @file
- * Contains the functionality to add mobile user roles 
+ * Contains the functionality to add mobile user roles
  *
- */  
- 
+ */
+
  /**
  * Configuration form for configuring the mobile context in the permission system
- */  
+ */
 function mobile_tools_roles_configuration_form() {
-  global $base_url;
   $form['mobile_tools_settings'] = array(
     '#type' => 'fieldset',
     '#title' => t('Mobile Tools settings'),
     '#collapsible' => TRUE,
-    '#description' => t('The Mobile Tools module allows the creation of a mobile version of each role . these mobile versions of each role will be assigned to the mobile user. In the !url configuration panel, you can assign permissions to the mobile user.', array('!url' => l('permissions', $base_url .'/admin/user/permissions'))),
+    '#description' => t('The Mobile Tools module allows the creation of a mobile version of each role . these mobile versions of each role will be assigned to the mobile user. In the !url configuration panel, you can assign permissions to the mobile user.', array('!url' => l('permissions', 'admin/people/permissions'))),
   );
   $form['mobile_tools_settings']['mobile_tools_enable_roles'] = array(
     '#type' => 'checkbox',
@@ -70,19 +69,19 @@ function mobile_tools_roles_configuratio
     '#title' => t('Mobile roles'),
     '#collapsible' => TRUE,
     '#description' => t('Enable or disable the mobile version of each user role. When no mobile role is created, the user will
-    keep it\'s normal role . the settings can also be configured in the !roles configuration section', array('!roles' => l('roles', 'admin/user/roles'))),
+    keep it\'s normal role . the settings can also be configured in the !roles configuration section', array('!roles' => l('roles', 'admin/people/permissions/roles'))),
     '#suffix' => mobile_tools_roles_overview()
   );
-  
+
   $result = db_query("SELECT * FROM {role}");
-  while ($item = db_fetch_object($result)) {
+  foreach ($result as $item) {
     $role = mobile_tools_roles_info(array('id' => $item->rid));
     if ($role->type == 'desktop') {
       $form['mobile_tools_roles']['mobile_tools_role_'. $item->rid] = array(
         '#type' => 'checkbox',
         '#title' => $item->name,
         '#default_value' => ($role->has_sibling) ? TRUE : FALSE,
-        '#description' => t('Enabling will create the %role role . the name can be changed afterwards in the !roles settings page', array('%role' => $role->name .' (Mobile)', '!role' =>  l('roless', 'admin/user/roles'))),
+        '#description' => t('Enabling will create the %role role . the name can be changed afterwards in the !roles settings page', array('%role' => $role->name .' (Mobile)', '!role' =>  l('roless', 'admin/people/permissions/roles'))),
       );
     }
   }
@@ -91,28 +90,27 @@ function mobile_tools_roles_configuratio
 }
 
 function mobile_tools_roles_overview() {
-  $query = "SELECT * FROM {mobile_tools_roles_relations}";
-  $result = db_query($query);
+  $output = '';
+  $result = db_query("SELECT * FROM {mobile_tools_roles_relations}");
   $rows = array();
-  while ($item = db_fetch_object($result)) {
-    $query = "SELECT * FROM {role} WHERE rid = %d";
-    $result1 = db_query($query, $item->rid);
-    $result2 = db_query($query, $item->mrid);
-    $rows[] = array(db_fetch_object($result1)->name, db_fetch_object($result2)->name);
+  foreach ($result as $item) {
+    $result1 = db_query("SELECT * FROM {role} WHERE rid = :rid", array(':rid' => $item->rid))->fetchObject();
+    $result2 = db_query("SELECT * FROM {role} WHERE rid = :rid", array(':rid' => $item->mrid))->fetchObject();
+    $rows[] = array($result1->name, $result2->name);
   }
   $headers = array("original role", "mobile role");
   if (count($rows) == 0) {
     $output .= '<div class="message">No Mobile roles were assigned</div>';
-  } 
+  }
   else {
-    $output .= theme('table', $headers, $rows);
-    $output .= '<br>'. t('Configure the !permissions', array('!permissions' => l('permissions', 'admin/user/permissions'))) .'<br />';
+    $output .= theme('table', array('header' => $headers, 'rows' => $rows));
+    $output .= '<br>'. t('Configure the !permissions', array('!permissions' => l('permissions', 'admin/people/permissions'))) .'<br />';
   }
   return $output;
 }
 /**
  * Helper function to return the desktop user roles
- */ 
+ */
 function mobile_tools_user_roles() {
   //$roles = array('none');
   $roles = user_roles();
@@ -145,71 +143,69 @@ function mobile_tools_mobile_user_roles(
  * Function helping in getting information for each role:
  * @param $identifier
  *  array('id' => id) or array('name' => name)
- *   
+ *
  * @return
- *    a $role object with the folowing info 
+ *    a $role object with the folowing info
  *  $role->id
- * $role->name 
+ * $role->name
  * $role->type = mobile/desktop
  * $role->sibling[id]
- * $role->sibling[name]  
+ * $role->sibling[name]
  */
  function mobile_tools_roles_info($identifier) {
   if (array_key_exists('id', $identifier)) {
-    $query = "SELECT * FROM {role} WHERE rid = %d";
-    $result = db_query($query, $identifier['id']);
-    $name = db_fetch_object($result)->name;
+    $result = db_query("SELECT * FROM {role} WHERE rid = :rid", array(':rid' => $identifier['id']))->fetchObject();
+    $name = $result->name;
     $rid = $identifier['id'];
-  } 
+  }
   elseif (array_key_exists('name', $identifier)) {
-    $query = "SELECT * FROM {role} WHERE name = '%s'";
-    $result = db_query($query, $identifier['name']);
-    $rid = db_fetch_object($result)->rid;
-    $name = $identifier['name'];    
-  } 
+    $result = db_query("SELECT * FROM {role} WHERE name = :name", array(':name' => $identifier['name']))->fetchObject();
+    $rid = $result->rid;
+    $name = $identifier['name'];
+  }
   $role->id = $rid;
   $role->name = $name;
-  $query = "SELECT COUNT(*) as count, mrid FROM {mobile_tools_roles_relations} WHERE rid = %d GROUP BY mrid";
-  $result = db_query($query, $rid);
-  $item = db_fetch_object($result);
- 
-  if ($item->count != 0) {
+  $result = db_query("SELECT COUNT(*) as count, mrid FROM {mobile_tools_roles_relations} WHERE rid = :rid GROUP BY mrid", array(':rid' => $rid))->fetchObject();
+  $item = $result;
+
+  if (isset($item->count) && $item->count != 0) {
     $role->type = 'desktop';
     $role->has_sibling = 1;
-    $result = db_query("SELECT * FROM {role} WHERE rid = %d", $item->mrid);
-    $sibling = db_fetch_object($result);
-  } 
+    $result = db_query("SELECT * FROM {role} WHERE rid = :rid", array(':rid' => $item->mrid))->fetchObject();
+    $sibling = $result;
+  }
   else {
-    $result = db_query("SELECT COUNT(*) as count, rid FROM {mobile_tools_roles_relations} WHERE mrid = %d GROUP BY rid", $rid);
-    $item = db_fetch_object($result); 
-    if ($item->count == 0) {
+    $result = db_query("SELECT COUNT(*) as count, rid FROM {mobile_tools_roles_relations} WHERE mrid = :rid GROUP BY rid", array(':rid' => $rid))->fetchObject();
+    $item = $result;
+    if (!isset($item->count) || $item->count == 0) {
       $role->has_sibling = 0;
       $role->type = 'desktop';
-    } 
+    }
     else {
       $role->type = 'mobile';
       $role->has_sibling = 1;
-      $result = db_query("SELECT * FROM {role} WHERE rid = %d", $item->rid);
-      $sibling = db_fetch_object($result);
+      $result = db_query("SELECT * FROM {role} WHERE rid = :rid", array(':rid' => $item->rid))->fetchObject();
+      $sibling = $result;
     }
   }
-  $role->sibling['id'] = $sibling->rid;
-  $role->sibling['name'] = $sibling->name ;
+  if (isset($sibling)) {
+    $role->sibling['id'] = $sibling->rid;
+    $role->sibling['name'] = $sibling->name ;
+  }
   return $role;
-} 
+}
 
 /**
  * Submit function for the mobile tools / mobile roles configuration page
- *  
- */ 
-function mobile_tools_roles_settings_submit($form) {
-  $query = "SELECT * FROM {role}";
-  $result = db_query($query);
+ *
+ */
+function mobile_tools_roles_settings_submit($form, &$form_state) {
+  $result = db_query("SELECT * FROM {role}");
 
-  while ($item = db_fetch_object($result)) {
+  foreach ($result as $item) {
     $role = mobile_tools_roles_info(array('id' => $item->rid));
     if ($role->type == 'desktop') {
-      $choice = $form['#post']['mobile_tools_role_'. $item->rid]['#value'];
+      $choice = $form_state['values']['mobile_tools_role_'. $item->rid];
       if ($role->has_sibling == 1 && $choice== 0) { // DELETE
         mobile_tools_edit_mobile_role('delete', $role);
       }
@@ -222,44 +218,57 @@ function mobile_tools_roles_settings_sub
 
 /**
  * Submit handler for the roles configuration form. It organises the mobile context for each user role.
- *  
- */ 
-function mobile_tools_roles_configuration_submit($form) {
-  $role = mobile_tools_roles_info(array('id' => $form['rid']['#value']));  
-  switch ($form['#post']['op']) {
+ *
+ */
+function mobile_tools_roles_configuration_submit($form, &$form_state) {
+  dsm($form_state);
+  $role = mobile_tools_roles_info(array('id' => $form_state['values']['rid']));
+  switch ($form_state['values']['op']) {
     case 'Save role':
-      if ($role->has_sibling == 1 && $form['#post']['mobile_tools_configure_role_'. $form['rid']['#value']] == FALSE && $role->type == 'desktop') {
+      if ($role->has_sibling == 1 && $form_state['values']['mobile_tools_configure_role_' . $form_state['values']['rid']] == FALSE && $role->type == 'desktop') {
         mobile_tools_edit_mobile_role('delete', $role);
-      } 
-      elseif ($role->has_sibbling == FALSE &&  $form['#post']['mobile_tools_configure_role_'. $form['rid']['#value']] == TRUE && $role->type == 'desktop') {
+      }
+      elseif ($role->has_sibbling == FALSE &&  $form_state['values']['mobile_tools_configure_role_' . $form_state['values']['rid']] == TRUE && $role->type == 'desktop') {
         mobile_tools_edit_mobile_role('add', $role);
-      } 
+      }
     break;
     case 'Delete role':
       if ($role->type == 'mobile') {
         $role = mobile_tools_roles_info(array('id' => $role->sibling['id']));
       }
-      mobile_tools_edit_mobile_role('delete', $role); 
-  } 
+      mobile_tools_edit_mobile_role('delete', $role);
+  }
 }
 
 /**
  * Function helping in saving and deleting the mobile roles
  * @param $op
- *  the operation that has to be performed: 'delete' will delete the mobile role, 'add' will add the mobile role.  
+ *  the operation that has to be performed: 'delete' will delete the mobile role, 'add' will add the mobile role.
  * @param $role
- *  the $role object of the normal role (the already existing non-mobile role) 
+ *  the $role object of the normal role (the already existing non-mobile role)
  */
 function mobile_tools_edit_mobile_role($op, $role) {
   switch ($op) {
     case 'delete':
-      db_query('DELETE FROM {role} WHERE rid = %d', $role->sibling['id']);
-      db_query('DELETE FROM {mobile_tools_roles_relations} WHERE mrid = %d', $role->sibling['id']);
+      db_delete('role')
+        ->condition('rid', $role->sibling['id'])
+        ->execute();
+      db_delete('mobile_tools_roles_relations')
+        ->condition('mrid', $role->sibling['id'])
+        ->execute();
     break;
     case 'add':
-     
-      $result = db_query("INSERT INTO {role} (name) VALUES ('%s')", $role->name .' (Mobile)');
-      db_query("INSERT INTO {mobile_tools_roles_relations} (rid, mrid) VALUES (%d, %d)", $role->id, db_last_insert_id('role', 'rid'));
-    break;  
+
+      $mrid = db_insert("role")
+        ->fields(array(
+          'name' => $role->name .' (Mobile)',
+        ))
+        ->execute();
+      db_insert('mobile_tools_roles_relations')
+        ->fields(array(
+          'rid' => $role->id,
+          'mrid' => $mrid,
+        ))->execute();
+    break;
   }
-}
\ No newline at end of file
+}
