--- C:/webroot-/sites/all/modules/linksdb-5.x-1.x-dev/linksdb/linksdb.module	Tue May 15 14:03:49 2007
+++ C:/webroot/sites/all/modules/linksdb-5.x-1.x-dev/linksdb/linksdb.module	Sat Feb 02 14:22:36 2008
@@ -15,6 +15,8 @@
   switch ($section) {
     case 'admin/help#linksdb':
       return "<h3>" . t('Links Module') . "</h3><p>" . t('This module allows you to maintain a database of links') . "</p>";
+    case 'links':
+      return variable_get('linksdb_message', t('A selection of useful links'));
   }
 }
 function linksdb_perm() {
@@ -36,7 +38,7 @@
    
 	$items[] = array(
 		'path' => 'links',
-		'title' => t('links'),
+		'title' => t('Links'),
 		'callback' => 'linksdb_display',
 		'access' => user_access('access content'), 
 	);
@@ -89,6 +91,13 @@
 		'access' => user_access('manage links'),
 	);
 	$items[] = array(
+		'path' => 'links/import',
+		'title' => t('import from text'),
+		'callback' => 'linksdb_import',
+		'type' => MENU_LOCAL_TASK,
+		'access' => user_access('manage links'),
+	);
+	$items[] = array(
 		'path' => 'links/category/edit',
 		'callback' => 'linksdb_categories_edit',
 		'type' => MENU_CALLBACK,
@@ -671,5 +680,83 @@
 		'#default_value' => variable_get('linksdb_show_report', 1),
 		'#description' => t('Show or hide the link to report a link as dead'),
 	);
+	$form['linksdb_message'] = array(
+		'#type' => 'textarea',
+		'#title' => t('Message'),
+		'#default_value' => variable_get('linksdb_message', t('A selection of useful links')),
+		'#description' => t('A message to show at the top of the links page'),
+	);
+	
+	
 	return system_settings_form($form);
+}
+
+function linksdb_import() {
+	return drupal_get_form('linksdb_import_form');
+}
+
+function linksdb_import_form() {
+	$form = array();
+
+		$form["text"] = array(
+			'#type' => 'textarea',
+			'#title' => 'Import text',
+			'#description' => 'Paste in text that contains the links to import.  It should be in the following format:<br /> &lt;cat&gt;Category Title<br />http://linkurl.com|link Title<br />http://anotherlink.com|another title',
+		);
+		
+		$form['import'] = array(
+			'#type' => 'submit',
+			'#value' => t('Import'),
+		);
+	return $form;
+}
+
+function linksdb_import_form_validate($form_id, $form_values) {
+
+}
+
+function linksdb_import_form_submit($form_id, $form_values) {
+  $lines = explode("\r\n",$form_values['text']);
+  
+  $category = '';
+  
+  //category insert query example
+  //insert into links_categories(name,collapsed,shown,parent) values('new cat2',0,10,0),('new cat3',0,10,0)
+  
+  $catSql = "insert into {links_categories}(id,name,collapsed,shown,parent) values(%d,'%s',0,10,0)";
+  
+  $linkSql = "insert into links_links(name,url,category) values('%s','%s',%d)";
+
+  $result = db_query("SELECT max(id) from {links_categories}");
+  $catId = db_result($result);
+    
+  drupal_set_message(print_r($lines,true));
+  
+  //$categories = array();    
+  //process categories
+  foreach ($lines as $line)
+  {
+    if (substr($line,0,5) == "<cat>")
+    {
+      //a category
+      $catId++;
+      $category = substr($line,5,strlen($line));
+      $result = db_query($catSql,$catId,$category); 
+      drupal_set_message("category found: $category");
+      drupal_set_message($result);
+    }
+    else 
+    {
+      $values = explode('|',$line);
+      //a link
+      //$values[0] - url
+      //$values[1] - name
+      $result = db_query($linkSql,$values[1],$values[0],$catId);
+      drupal_set_message('url result: ' . $result);
+    }
+  }
+  
+  //db_query("SELECT id,name from {links_categories} where name = %s",
+  //drupal_set_message(print_r($categories,true));
+  
 }
