Index: H:/sites/drupal_schools/sites/all/modules/install_profile_api/crud.inc
===================================================================
--- H:/sites/drupal_schools/sites/all/modules/install_profile_api/crud.inc	(revision 71)
+++ H:/sites/drupal_schools/sites/all/modules/install_profile_api/crud.inc	(revision 72)
@@ -16,6 +16,7 @@
 
 /**
  * Add a user
+ * Note: must provide role array in key => value format, e.g., array($rid1 => '', $rid2 => '').
  */
 function install_add_user($username, $password, $email, $roles = array(), $status = 1) {
   user_save(
@@ -36,8 +37,7 @@
  * Add a new contact category, including recipients and so on
  */
 function install_contact_add_category($category, $recipients, $reply = '', $weight = 0, $selected = 0) {
-  $cid = db_next_id("{contact}_cid");
-  db_query("INSERT INTO {contact} (cid, category, recipients, reply, weight, selected) VALUES (%d, category = '%s', recipients = '%s', reply = '%s', weight = %d, selected = %d)", $cid, $category, $recipients, $reply, $weight, $selected);
+  db_query("INSERT INTO {contact} (category, recipients, reply, weight, selected) VALUES ('%s', '%s', '%s', %d, %d)", $category, $recipients, $reply, $weight, $selected);
 }
 
 /* --- PROFILE FUNCTIONS --- */
@@ -78,15 +78,30 @@
  * Add a role to the roles table.
  */
 function install_add_role($name) {
-  db_query("INSERT INTO {role} (name) VALUES ('%s')", $name);
-  return install_get_rid($name);
+	$result = db_result(db_query("SELECT 1 FROM {role} r WHERE r.name = '%s'", $name));
+	if (!$result) {
+	  db_query("INSERT INTO {role} (name) VALUES ('%s')", $name);
+ 		return install_get_rid($name);
+	}
+	else {
+		drupal_set_message("Role '$name' already exists - skipping...");
+	}
 }
 
 /**
  * Get the role id for the role name
  */
 function install_get_rid($name) {
-  return db_result(db_query("SELECT rid FROM {role} WHERE name ='%s' LIMIT 1", $name));
+	switch ($GLOBALS['db_type']) {
+    case 'mysqli':
+    case 'mysql':
+		case 'pgsql':
+		  return db_result(db_query("SELECT rid FROM {role} WHERE name ='%s' LIMIT 1", $name));
+			break;
+		case 'mssql':
+			return db_result(db_query("SELECT TOP 1 rid FROM {role} WHERE name = '%s'", $name));
+		break;
+	}	
 }
 
 /**
@@ -122,7 +137,16 @@
  */
 function install_menu_get_mid($path) {
   menu_rebuild(); // not sure if this is needed, but we've seen problems without it
-  return db_result(db_query("SELECT mid FROM {menu} WHERE path = '%s' LIMIT 1", $path));	
+	switch ($GLOBALS['db_type']) {
+    case 'mysqli':
+    case 'mysql':
+		case 'pgsql':
+  		return db_result(db_query("SELECT mid FROM {menu} WHERE path = '%s' LIMIT 1", $path));
+			break;
+		case 'mssql':
+			return db_result(db_query("SELECT TOP 1 mid FROM {menu} WHERE path = '%s'", $path));
+		break;
+	}
 }
 
 /**
@@ -130,7 +154,16 @@
  * @return	integer		The database ID of the root menu that matches the $title
  */
 function install_menu_get_root_menu($title) {
-  return db_result(db_query("SELECT mid FROM {menu} WHERE title = '%s' LIMIT 1", $title));	
+	switch ($GLOBALS['db_type']) {
+    case 'mysqli':
+    case 'mysql':
+		case 'pgsql':
+  		return db_result(db_query("SELECT mid FROM {menu} WHERE title = '%s' LIMIT 1", $title));
+			break;
+		case 'mssql':
+			return db_result(db_query("SELECT TOP 1 mid FROM {menu} WHERE title = '%s'", $title));
+		break;
+	}
 }
 
 /**
@@ -191,8 +224,14 @@
  */
 function install_tinymce_add_roles($name, $roles) {
   foreach ($roles as $role) {
-    db_query("INSERT INTO {tinymce_role} (name, rid) VALUES ('%s', %d)", $name, $role);
-  }
+		$result = db_result(db_query("SELECT 1 FROM {tinymce_role} tmr WHERE tmr.name = '%s'", $name));
+		if (!$result) {
+	    db_query("INSERT INTO {tinymce_role} (name, rid) VALUES ('%s', %d)", $name, $role);
+  	}
+		else {
+			drupal_set_message("TinyMCE role '$name' already exists - skipping...");
+		}
+	}
 }
 
 /**
@@ -201,7 +240,13 @@
  * @param	$settings	An associative array containing key value pairs
  */
 function install_tinymce_create_profile($name, $settings) {
-  db_query("INSERT INTO {tinymce_settings} (name, settings) VALUES ('%s', '%s')", $name, serialize($settings));
+	$result = db_result(db_query("SELECT 1 FROM {tinymce_settings} WHERE name = '%s'", $name));
+	if (!$result) {
+	  db_query("INSERT INTO {tinymce_settings} (name, settings) VALUES ('%s', '%s')", $name, serialize($settings));
+	}
+	else {
+		drupal_set_message("TinyMCE setting '$name' already exists - skipping...");
+	}
 }
 
 /* --- TAXONOMY --- */
@@ -212,9 +257,65 @@
  */
 function install_get_vid($name) {
   // not guaranteed to be unique, hence the LIMIT
-  return db_result(db_query("SELECT vid FROM {vocabulary} WHERE name = '%s' LIMIT 1", $name));
+	switch ($GLOBALS['db_type']) {
+    case 'mysqli':
+    case 'mysql':
+  		return db_result(db_query("SELECT vid FROM {vocabulary} WHERE name = '%s' LIMIT 1", $name));
+			break;
+		case 'mssql':
+			return db_result(db_query("SELECT TOP 1 vid FROM {vocabulary} WHERE name = '%s'", $name));
+		break;
+	}
 };
 
+/**
+ * Add a vocabulary
+ * @param $node_types Array of node types
+ * @param	$name	 A text string identifying the vocabulary
+ * @param $description	Description of the vocabulary
+ * @param $help	 Help text
+ * @param $relations ???
+ * @param $hierarchy ???
+ * @param $multiple	???
+ * @param $required  Bit field controlling whether the vocabulary is required on a node page
+ * @param $tags ???
+ * @param $module The module the vocabulary is part of
+ * @param $weight	Position/placement of vocabulary relative to other vocabularies
+ */
+function install_add_vocabulary($node_types, $name, $required = 0, $weight = 0, $multiple = 0, $description = '', $help = '', $relations = 0, $hierarchy = 0, $tags = 0, $module = 'taxonomy') {
+	$result = db_result(db_query("SELECT 1 FROM {vocabulary} WHERE name = '%s'", $name));
+	if (!$result) {
+	$vid = db_next_id('{vocabulary}_vid');
+		db_query("INSERT INTO {vocabulary} (vid, name, description, help, relations, hierarchy, multiple, required, tags, module, weight) VALUES (%d, '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', %d)", $vid, $name, $description, $help, $relations, $hierarchy, $multiple, $required, $tags, $module, $weight);
+		// assign vocabulary to desired node types
+		foreach ($node_types as $node_type) {
+			db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $vid, $node_type);
+		}
+	}
+	else {
+		drupal_set_message("Vocabulary '$name' already exists - skipping...");
+	}
+}
+
+/**
+ * Add a term
+ * @param	$vid	 Vocabulary id that this term is a child of
+ * @param $name	 Name of the term
+ * @param $description	Text that describes the term
+ * @param $weight  Position of term relative to other terms in a vocabulary
+ */
+function install_add_term($vid, $name, $weight = 0, $description = '', $parent = 0) {
+	$result = db_result(db_query("SELECT 1 FROM {term_data} WHERE name = '%s'", $name));
+	if (!$result) {	
+		$tid = db_next_id('{term_data}_tid');
+		db_query("INSERT INTO {term_data} (tid, vid, name, description, weight) VALUES (%d, %d, '%s', '%s', %d)", $tid, $vid, $name, $description, $weight);
+		db_query("INSERT INTO {term_hierarchy} (tid, parent) VALUES ($tid, $parent)"); 
+	}
+	else {
+		drupal_set_message("Term '$name' already exists - skipping...");
+	}		
+}
+
 /* --- FILTER --- */
 
 /**
@@ -311,4 +412,112 @@
 function install_admin_theme($theme) {
   variable_set('admin_theme', $theme);
 }
-  
\ No newline at end of file
+ 
+
+/* --- BLOCK --- */
+
+/**
+ * Example usage:
+ * // Set site theme
+ * install_add_block($menu_mid, 'garland', 0, 1, 'left', 'menu', array(1,2,3));
+ * install_update_block("mytheme");
+ */
+
+/**
+* Assign a custom menu to a block to make it active
+*	@param  $status  1 = active, 0 = hidden
+*	@param	$weight  If more than one block in a region, what position this block is to have
+*	@param  $reigon  Area where block is to appear
+*	@param  $custom  ???
+*	@param  $throttle  ???
+*	@param  $visibility  Whether the page is visible on listed, invisible on list, or hide and let individual users decide
+*	@param  $pages	Page(s) block is to appear on
+*	@param  $title	Block title
+*	@param  $theme  Theme block is to be used with
+*	@param  $delta  Menu id (mid) in the case of the menu module
+*	@param  $module	 The module that owns block
+*	@param  $rids An array of role ID(s)
+*/
+
+function install_add_block($delta, $theme, $weight = 0, $status = 1,  $region = 'left', $module = 'menu', $rids = FALSE, $custom = 0, $throttle = 0, $visibility = 0, $pages = '', $title = '') {
+	$result = db_result(db_query("SELECT 1 FROM {blocks} b WHERE b.theme = '%s' AND b.module = '%s' AND b.delta = '%s'", $theme, $module, $delta));
+	if (!$result) {
+	  db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, throttle, visibility, pages, title) VALUES ('%s','%s','%s', %d, %d, '%s', %d, %d, '%s', '%s')", $module, $delta, $theme, $status, $weight, $region, $throttle, $visibility, $pages, $title);
+		if ($rids) {
+			foreach ($rids as $role) {
+				if (!$result) {
+					db_query("INSERT INTO {blocks_roles} (module, delta, rid) VALUES ('%s', '%s', %d)", $module, $delta, $role);
+				}
+			}
+		}
+	}
+	else {
+		drupal_set_message("Block of delta '$delta' and module '$module' and theme '$theme', already exists - skipping...");
+	}
+		
+}
+
+///**
+// * Example usage:
+// * // Activate an existing block. For example, a block created automatically by a custom module.
+// * install_update_block($mid, 'menu', 'garland', 1);
+// */
+
+///**
+//* Update a block.
+//*	@param  $status	 active = 1, disabled = 0
+//*	@param  $reigon  area where block appears
+//*	@param  $theme	 theme block to be affected
+//*	@param  $delta	 in the case of the menu module, represents the mid
+//*	@param  $module	 module that owns this block
+//* @param  $pages	 page(s) for this block to be shown on - a string of page names delimited by spaces
+//* @param  $region  page area on which the block is to appear
+//*/
+//
+//function install_update_block($delta, $pages, $region, $module, $theme, $status) {
+//  db_query("UPDATE {blocks} SET status = %d, pages = '%s', region = '%s' WHERE delta = '%s' AND module = '%s' AND theme = '%s'", $status, $pages, $region, $delta, $module, $theme);
+//}
+
+/* --- NODE --- */
+
+/**
+ * Example usage:
+ * // Create a new page node(s)
+ * install_create_node($nodes);
+ * @param $nodes One or more associative array(s) that includes: path, title, body, teaser, uid, format, status, sticky, and type) - ex. = array('path' => 'about_us', 'title' => 'Title', 'body' => 'hi', 'teaser' => '', 'uid' => 1, 'format' => 1, 'status' => 1, 'sticky' => 0, 'type' => 'page'),
+ */
+
+function install_create_node($nodes) {
+	// create the nodes
+	foreach ($nodes as $node) {
+		// convert to object for node_save() compatibililty
+		$node = (object)$node;
+		node_save($node);
+		if ($node->path) {
+		// should probably get last INSERTed nid, but not sure how to reliably do this. 
+			$result = db_result(db_query("SELECT TOP 1 n.nid FROM {node} n WHERE n.title = '%s'", $node->title));
+			if ($result) {
+				path_set_alias('node/' . $result, $node->path);
+			}
+			else {
+				drupal_set_message('Something went wrong with installing the path for the following node: ' . $node->title . ' (path ==' . $node->path);
+			}
+		}
+	}
+}
+
+/* --- LDAP --- */
+
+/**
+	* Tested with ldap authentication module 5.x-1.3
+	* Simply inserts a record with LDAP/active directory information
+	*/
+function install_add_ldap($name, $server, $port, $basedn, $user_attr, $mail_attr, $binddn, $bindpw, $status = 1, $tls = 0, $encrypted = 0, $bindpw_clear = 0) {
+	$result = db_result(db_query("SELECT 1 FROM {ldapauth} lda WHERE lda.name = '%s'", $name));
+	if (!$result) {
+		db_query("INSERT INTO {ldapauth} (name, server, port, basedn, user_attr, mail_attr, binddn, bindpw, status, tls, encrypted, bindpw_clear) VALUES ('%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s')", $name, $server, $port, $basedn, $user_attr, $mail_attr, $binddn, $bindpw, $status, $tls, $encrypted, $bindpw_clear);	
+	}
+	else {
+		drupal_set_message("LDAP server setting already exists. Skipping...");
+	}
+}
\ No newline at end of file
