--- bbb.module	2011-01-10 10:38:38.000000000 -0500
+++ bbb.module	2011-02-11 16:57:03.868491999 -0500
@@ -8,7 +8,7 @@
  *
  * @author
  * Stefan Auditor <stefan.auditor@erdfisch.de>
- * 
+ *
  * TODO:
  * - Add 'start meeting' button
  * - Rework waiting page
@@ -52,7 +52,7 @@ function bbb_permission() {
   return array(
     'administer big blue button' => array(
       'title' => t('Administer BigBlueButton'),
-      'description' => t('Allow administration of BigBlueButton')  
+      'description' => t('Allow administration of BigBlueButton')
     ),
   //TODO:
   //    'start meetings',
@@ -252,7 +252,7 @@ function bbb_form_alter(&$form, &$form_s
         '#title' => t('Display meeting status on node'),
         '#default_value' => variable_get('bbb_content_type_show_status_' . $form['#node_type']->type, FALSE),
       );
-      
+
       $form['bbb']['bbb_content_type_welcome'] = array(
         '#title' => t('Welcome message'),
         '#type' => 'textfield',
@@ -292,62 +292,64 @@ function bbb_form_alter(&$form, &$form_s
   }
 
   // Node edit form
-  $node_type = $form['#type']['#value'];
-  if (drupal_substr($form_id, (drupal_strlen($form_id) - 10), 10) == '_node_form' &&
-      bbb_is_meeting_type($node_type) &&
-      user_access('administer big blue button')) {
-    if (is_numeric($form['nid']['#value'])) {
-      $meeting = bbb_get_meeting($form['nid']['#value']);
-    }
+  if (array_key_exists('#node_edit_form',$form)) {
+    $node_type = $form['type']['#value'];
+    if (drupal_substr($form_id, (drupal_strlen($form_id) - 10), 10) == '_node_form' &&
+        bbb_is_meeting_type($node_type) &&
+        user_access('administer big blue button')) {
+      if (is_numeric($form['nid']['#value'])) {
+        $meeting = bbb_get_meeting($form['nid']['#value']);
+      }
 
-    $form['bbb'] = array(
-      '#title' => t('Meeting settings'),
-      '#type' => 'fieldset',
-      '#description' => t("The following settings maybe changed until the meeting first starts."),
-      '#collapsible' => TRUE,
-      '#collapsed' => TRUE,
-      '#tree' => TRUE,
-    );
-    $form['bbb']['welcome'] = array(
-      '#title' => t('Welcome message'),
-      '#type' => 'textfield',
-      '#default_value' => variable_get('bbb_content_type_welcome_' . $node_type, ''),
-      '#maxlength' => 255,
-      '#description' => t('A welcome message that gets displayed on the chat window when the participant joins. You can include keywords (%%CONFNAME%%, %%DIALNUM%%, %%CONFNUM%%) which will be substituted automatically.'),
-      '#attributes' => $meeting->meetingID ? array('disabled' => 'disabled') : array(),
-    );
-    $form['bbb']['dialNumber'] = array(
-      '#title' => t('Dial number'),
-      '#type' => 'textfield',
-      '#default_value' => variable_get('bbb_content_type_dialNumber_' . $node_type, ''),
-      '#maxlength' => 32,
-      '#description' => t('The dial access number that participants can call in using regular phone.'),
-      '#attributes' => $meeting->meetingID ? array('disabled' => 'disabled') : array(),
-    );
-    $form['bbb']['moderatorPW'] = array(
-      '#title' => t('Moderator password'),
-      '#type' => 'textfield',
-      '#default_value' => variable_get('bbb_content_type_moderatorPW_' . $node_type, ''),
-      '#maxlength' => 32,
-      '#description' => t('The password that will be required for moderators to join the meeting or for certain administrative actions (i.e. ending a meeting).'),
-      '#attributes' => $meeting->meetingID ? array('disabled' => 'disabled') : array(),
-    );
-    $form['bbb']['attendeePW'] = array(
-      '#title' => t('Attendee password'),
-      '#type' => 'textfield',
-      '#default_value' => variable_get('bbb_content_type_attendeePW_' . $node_type, ''),
-      '#maxlength' => 32,
-      '#description' => t('The password that will be required for attendees to join the meeting.'),
-      '#attributes' => $meeting->meetingID ? array('disabled' => 'disabled') : array(),
-    );
-    $form['bbb']['logoutURL'] = array(
-      '#title' => t('Logout URL'),
-      '#type' => 'textfield',
-      '#default_value' => variable_get('bbb_content_type_logoutURL_' . $node_type, ''),
-      '#maxlength' => 255,
-      '#description' => t('The URL that the Big Blue Button client will go to after users click the OK button on the <em>You have been logged out message</em>.'),
-      '#attributes' => $meeting->meetingID ? array('disabled' => 'disabled') : array(),
-    );
+      $form['bbb'] = array(
+        '#title' => t('Meeting settings'),
+        '#type' => 'fieldset',
+        '#description' => t("The following settings maybe changed until the meeting first starts."),
+        '#collapsible' => TRUE,
+        '#collapsed' => TRUE,
+        '#tree' => TRUE,
+      );
+      $form['bbb']['welcome'] = array(
+        '#title' => t('Welcome message'),
+        '#type' => 'textfield',
+        '#default_value' => variable_get('bbb_content_type_welcome_' . $node_type, ''),
+        '#maxlength' => 255,
+        '#description' => t('A welcome message that gets displayed on the chat window when the participant joins. You can include keywords (%%CONFNAME%%, %%DIALNUM%%, %%CONFNUM%%) which will be substituted automatically.'),
+        '#attributes' => !empty($meeting->meetingID) ? array('disabled' => 'disabled') : array(),
+      );
+      $form['bbb']['dialNumber'] = array(
+        '#title' => t('Dial number'),
+        '#type' => 'textfield',
+        '#default_value' => variable_get('bbb_content_type_dialNumber_' . $node_type, ''),
+        '#maxlength' => 32,
+        '#description' => t('The dial access number that participants can call in using regular phone.'),
+        '#attributes' => !empty($meeting->meetingID) ? array('disabled' => 'disabled') : array(),
+      );
+      $form['bbb']['moderatorPW'] = array(
+        '#title' => t('Moderator password'),
+        '#type' => 'textfield',
+        '#default_value' => variable_get('bbb_content_type_moderatorPW_' . $node_type, ''),
+        '#maxlength' => 32,
+        '#description' => t('The password that will be required for moderators to join the meeting or for certain administrative actions (i.e. ending a meeting).'),
+        '#attributes' => !empty($meeting->meetingID) ? array('disabled' => 'disabled') : array(),
+      );
+      $form['bbb']['attendeePW'] = array(
+        '#title' => t('Attendee password'),
+        '#type' => 'textfield',
+        '#default_value' => variable_get('bbb_content_type_attendeePW_' . $node_type, ''),
+        '#maxlength' => 32,
+        '#description' => t('The password that will be required for attendees to join the meeting.'),
+        '#attributes' => !empty($meeting->meetingID) ? array('disabled' => 'disabled') : array(),
+      );
+      $form['bbb']['logoutURL'] = array(
+        '#title' => t('Logout URL'),
+        '#type' => 'textfield',
+        '#default_value' => variable_get('bbb_content_type_logoutURL_' . $node_type, ''),
+        '#maxlength' => 255,
+        '#description' => t('The URL that the Big Blue Button client will go to after users click the OK button on the <em>You have been logged out message</em>.'),
+        '#attributes' => !empty($meeting->meetingID) ? array('disabled' => 'disabled') : array(),
+      );
+    }
   }
 }
 
@@ -406,8 +408,8 @@ function bbb_node_view($node, $view_mode
 
 function bbb_node_load($nodes, $types) {
   foreach($nodes as $node) {
-    if (bbb_is_meeting_type($nodes[$node->nid]->type)) {
-      $nodes[$node->nid]->bbb = bbb_get_meeting($nodes[$node->nid]->nid);
+    if (bbb_is_meeting_type($node->type)) {
+      $node->bbb = bbb_get_meeting($node->nid);
     }
   }
 }
@@ -495,9 +497,9 @@ function bbb_is_meeting_owner($nid, $acc
   }
   $sql = "SELECT COUNT(nid) FROM {bbb_meetings} bm
            INNER JOIN {node} n ON bm.nid = n.nid
-           WHERE n.uid = %d
-             AND nid = %d";
-  $owner = db_result(db_query($sql, $account->uid, $nid));
+           WHERE n.uid = :uid
+             AND nid = :nid";
+  $owner = db_result(db_query($sql, array(':uid'=>$account->uid, ':nid' =>$nid)));
   return $owner ? TRUE : FALSE;
 }
 
@@ -619,7 +621,7 @@ function bbb_store_meeting($node, $param
  * Delete meeting
  */
 function bbb_delete_meeting($nid) {
-  return db_query("DELETE FROM {bbb_meetings} WHERE nid = %d", $nid);
+  return db_query("DELETE FROM {bbb_meetings} WHERE nid = :nid", array(':nid'=>$nid));
 }
 
 /* Menu Callbacks */
@@ -668,9 +670,9 @@ function bbb_meeting_attend($node) {
     return node_show($node, NULL);
   }
   $variables = array(
-  	'meeting' => $meeting, 
-  	'mode' => $mode, 
-  	'height' => BBB_DISPLAY_HEIGHT, 
+  	'meeting' => $meeting,
+  	'mode' => $mode,
+  	'height' => BBB_DISPLAY_HEIGHT,
   	'width' => BBB_DISPLAY_WIDTH
   );
   return theme('bbb_meeting', $variables);
@@ -689,16 +691,16 @@ function bbb_meeting_moderate($node) {
   $meeting = bbb_get_meeting($node->nid);
 
   $params = array(
-    'meetingID' => $meeting->meetingID,
-    'password' => $meeting->moderatorPW,
+    'meetingID' => $meeting->meetingid,
+    'password' => $meeting->moderatorpw,
   );
+
   $status = bbb_api_getMeetingInfo($params);
 
   if ($status->hasBeenForciblyEnded == 'true') {
     drupal_set_message('The meeting has been terminated and is not available for reopening.');
     drupal_goto('node/' . $node->nid);
-  } 
-
+  }
   drupal_set_title($node->title);
   // Implicitly create meeting
   if (empty($meeting->initialized)) {
@@ -711,9 +713,9 @@ function bbb_meeting_moderate($node) {
     bbb_redirect($node, $mode);
   }
   $variables = array(
-  	'meeting' => $meeting, 
-  	'mode' => $mode, 
-  	'height' => BBB_DISPLAY_HEIGHT, 
+  	'meeting' => $meeting,
+  	'mode' => $mode,
+  	'height' => BBB_DISPLAY_HEIGHT,
   	'width' => BBB_DISPLAY_WIDTH
   );
   return theme('bbb_meeting', $variables);
