--- C:\Documents and Settings\Aldo\Local Settings\Temp\TCV8ac5.tmp\flexinode_admin.1.5.2.3.module	Fri Apr 20 12:27:21 2007
+++ D:\drupal cvs\4.7.x\contributions\modules\flexinode\flexinode_admin.module	Fri Apr 20 12:28:27 2007
@@ -20,15 +20,13 @@
         <li>create a flexinode content type at <a href="%admin-node-types" title="administer content types to add a flexinode"> administer &gt;&gt; content &gt;&gt; content types</a> and select <strong>add content type</strong>.</li>
         <li><a href="%node-add" title="create a new flexinode type">create content &gt;&gt; add type.</a></li>
         <li>administer flexinode at <a href="%admin-settings-flexinode">administer &gt;&gt; settings &gt;&gt; flexinode</a>.</li>
-        ', array('%admin-node-types' => url('admin/node/types'), '%node-add' => url('node/add'), '%admin-settings-flexinode' => url('admin/settings/flexinode'))) .'</ul>';
+        ', array('%admin-node-types' => url('admin/settings/content-types/flexinode/add'), '%node-add' => url('node/add'), '%admin-settings-flexinode' => url('admin/settings/flexinode_miniview'))) .'</ul>';
         $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%flexinode">Flexinode page</a>.', array('%flexinode' => 'http://www.drupal.org/handbook/modules/flexinode/')) .'</p>';
       return $output;
     case 'admin/modules#description':
       return t('Allows administrators to define their own content types.');
-    case 'admin/node/types':
-      return t('You may manage your own content types here. These will all have a "title" field to start off, and contain additional fields that you specify. Choose the "add content type" tab to add a new type. Make a selection below to edit an existing type or field. To delete a field or entire content type, first open the editing form for that field or type.');
-    case 'admin/node/type':
-      return t('Once you create a content type here you will be able to add additional fields to it on the "content types" tab.');
+    case 'admin/settings/content-types/flexinode/add':
+      return t('Once you create a content type here you will be able to add additional fields to it on the "edit content types" tab.');
   }
 
   $output = '';
@@ -54,28 +52,29 @@
 
     // admin menu items
     $items[] = array(
-      'path' => 'admin/node/types',
-      'title' => t('content types'),
-      'callback' => 'flexinode_admin_page_admin',
+      'path' => 'admin/settings/content-types/overview',
+      'title' => t('list'),
       'access' => $admin_access,
-      'type' => MENU_LOCAL_TASK,
+      'type' => MENU_DEFAULT_LOCAL_TASK,
+      'weight' => -1,
       );
     $items[] = array(
-      'path' => 'admin/node/type',
+      'path' => 'admin/settings/content-types/flexinode/add',
       'title' => t('add content type'),
       'callback' => 'flexinode_admin_content_type_form',
       'access' => $admin_access,
       'type' => MENU_LOCAL_TASK,
+      'weight' => 1,
       );
     $items[] = array(
-      'path' => 'admin/node/type/delete',
+      'path' => 'admin/settings/content-types/flexinode/delete',
       'title' => t('delete content type'),
       'callback' => 'flexinode_admin_confirm_delete_content_type',
       'access' => $admin_access,
       'type' => MENU_CALLBACK,
       );
     $items[] = array(
-      'path' => 'admin/node/field',
+      'path' => 'admin/settings/content-types/flexinode/field',
       'title' => t('edit fields'),
       'callback' => 'flexinode_admin_admin_field',
       'access' => $admin_access,
@@ -93,51 +92,78 @@
   return $items;
 }
 
-/**
- * MENU CALLBACKS
- */
-/**
- * Menu callback; presents an overview of all admin-defined content types.
- */
-function flexinode_admin_page_admin($ctype_id = NULL) {
-  $content_types = flexinode_content_types();
-
-  $output = '';
+function flexinode_admin_form_alter($form_id, &$form) {
+  if(preg_match('/^flexinode-(\d*?)_node_settings$/',$form_id,$matches)>0) {
+    $ctype_id = $matches[1];
+    $ctype = flexinode_load_content_type($ctype_id);
 
-  foreach ($content_types as $ctype) {
-    $ctype = flexinode_load_content_type($ctype->ctype_id);
-    $ctype->links[] = l(t('edit'), 'admin/node/type/'. $ctype->ctype_id);
-    $ctype->links[] = l(t('settings'), 'admin/settings/content-types/flexinode-'. $ctype->ctype_id);
+    $form['flexinode_settings'] = array(
+      '#type' => 'fieldset', 
+      '#title' => t('Content-type settings'),
+      '#weight' => -5,
+    );
 
+    $form['flexinode_settings']['ctype_id'] = array(
+      '#type' => 'hidden', 
+      '#value' => $ctype_id,
+    );
 
-    $ctype->controls = flexinode_admin_field_select($ctype->ctype_id);
+    $form['flexinode_settings']['name'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Content type name'),
+      '#default_value' => $ctype->name,
+      '#size' => 60,
+      '#maxlength' => 128,
+      '#required' => TRUE,
+    );
+    $form['flexinode_settings']['description'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Description'),
+      '#default_value' => $ctype->description,
+      '#size' => 60,
+      '#maxlength' => 128,
+      '#description' => t('A one-line description of the content type.'),
+    );
 
+    $fields = array();
     foreach ($ctype->fields as $field) {
-      $ctype->fieldlist[] = $field->label . ' (' . l(t('edit field'), 'admin/node/field/' . $field->field_id) .')';
+      $fields[] = $field->label . ' (' . l(t('edit field'), 'admin/settings/content-types/flexinode/field/' . $field->field_id) .')';
     }
+    $form['flexinode_settings']['fields']['current'] = array(
+      '#type' => 'markup',
+      '#value' => theme('item_list', $fields, t('Field list')),
+    );
 
-    $output .= theme('flexinode_type', $ctype);
-    $first = FALSE;
-  }
+    $form['flexinode_settings']['fields']['field_type'] = array(
+      '#type' => 'select',
+      '#options' => flexinode_admin_field_select_options(),
+    );
+    $form['flexinode_settings']['fields']['add'] = array(
+      '#type' => 'submit',
+      '#value' => t('Add field'),
+    );
 
-  if (strlen($output) == 0) {
-    $output = '<p>'. t('No flexinode content types have been defined. You can <a href="%url">add a new content type</a>.', array('%url' => url('admin/node/type'))) .'</p>';
-  }
 
-  drupal_add_js('misc/collapse.js');
-  return $output;
+    $form['buttons']['delete'] = array(
+      '#type' => 'submit', 
+      '#value' => t('Delete'),
+    );
+
+    $form['#submit'] = array('flexinode_admin_content_type_form_submit' => array()) + (array)$form['#submit'];
+    $form['#validate'] = array('flexinode_admin_content_type_form_validate' => array()) + (array)$form['#validate'];
+  }
 }
 
 /**
+ * MENU CALLBACKS
+ */
+
+/**
  * Menu callback; presents a form to edit an existing field in a content type.
  */
 function flexinode_admin_admin_field($field_id = NULL) {
   $op = $_POST['op'];
 
-  $crumbs = drupal_get_breadcrumb();
-  $crumbs[] = l('content types', 'admin/node/types');
-  drupal_set_breadcrumb($crumbs);
-
   switch ($op) {
     case t('Add field'):
       $field_id = $_POST['edit']['field_type'];
@@ -146,15 +172,20 @@
     case t('Confirm'):
       $field = flexinode_load_field($field_id);
       flexinode_admin_delete_field($field);
-      drupal_goto('admin/node/types/'. $field->ctype_id);
+      drupal_goto('admin/settings/content-types/flexinode-'. $field->ctype_id);
       break;
     case t('Delete'):
       $field = flexinode_load_field($field_id);
       $output = flexinode_admin_confirm_delete_field($field);
       break;
-    case t('More'):
     default:
-      $output = flexinode_admin_field_form($field_id);
+      if(is_numeric(arg(6))) {
+        $output = flexinode_admin_field_form(arg(5), arg(6));
+      } elseif(is_numeric(arg(5))) { 
+        $output = flexinode_admin_field_form(arg(5));
+      } else {
+        drupal_not_found();
+      }
       break;
   }
 
@@ -237,15 +268,10 @@
 /**
  * Render a form for the editing of a content type.
  */
-function flexinode_admin_content_type_form($ctype_id = NULL) {
-  if ($ctype_id) {
-    $ctype = flexinode_load_content_type($ctype_id);
-  }
-
+function flexinode_admin_content_type_form() {
   $form['name'] = array(
     '#type' => 'textfield',
     '#title' => t('Content type name'),
-    '#default_value' => $ctype->name,
     '#size' => 60,
     '#maxlength' => 128,
     '#required' => TRUE,
@@ -253,7 +279,6 @@
   $form['description'] = array(
     '#type' => 'textfield',
     '#title' => t('Description'),
-    '#default_value' => $ctype->description,
     '#size' => 60,
     '#maxlength' => 128,
     '#description' => t('A one-line description of the content type.'),
@@ -261,10 +286,6 @@
   $form['ctype_id'] = array('#type' => 'hidden', '#value' => $ctype_id);
   $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
 
-  if ($ctype_id) {
-    $form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
-  }
-
   return drupal_get_form('flexinode_admin_content_type_form', $form);
 }
 
@@ -281,9 +302,14 @@
  * flexinode_content_type_form hook_submit callback function.
  */
 function flexinode_admin_content_type_form_submit($form_id, $edit) {
-  if($_POST['op'] == t('Delete')) {
-    drupal_goto('admin/node/type/delete/'. $edit['ctype_id']);
-  }
+  switch($_POST['op']) {
+  case t('Delete'):
+    drupal_goto('admin/settings/content-types/flexinode/delete/'. $edit['ctype_id']);
+    break;
+  case t('Add field'):
+    drupal_goto('admin/settings/content-types/flexinode/field/'.$edit['field_type'].'/'.$edit['ctype_id']);
+    break;
+  default:
   if ($edit['ctype_id']) {
     $ctype_id = $edit['ctype_id'];
 
@@ -296,14 +322,15 @@
   else {
     $ctype_id = db_next_id('{flexinode_ctype}');
 
-    db_query("INSERT INTO {flexinode_type} (name, description, ctype_id) VALUES ('%s', '%s', %d)", $edit['name'], $edit['description'], $ctype_id);
+      db_query("INSERT INTO {flexinode_type} (name, description, ctype_id) VALUES ('%s', '%s', '%s')", $edit['name'], $edit['description'], $ctype_id);
 
     drupal_set_message(t('created new content type "%name".', array('%name' => $edit['name'])));
   }
 
   // update the cached "create content" menu
   menu_rebuild();
-  drupal_goto('admin/node/types/'. $ctype_id);
+    //drupal_goto('admin/settings/content-types/flexinode-'. $ctype_id);
+  }
 }
 
 /**
@@ -312,7 +339,7 @@
 function flexinode_admin_confirm_delete_content_type($ctype_id) {
   if($_POST['op'] == t('Confirm')) {
     flexinode_admin_delete_content_type($ctype_id);
-    drupal_goto('admin/node/types');
+    drupal_goto('admin/settings/content-types');
   }
 
   $ctype = flexinode_load_content_type($ctype_id);
@@ -324,7 +351,7 @@
     '#type' => 'hidden',
     '#value' =>  $ctype->name,
     );
-  return confirm_form('flexinode_confirm_delete_content_type', $form, t('Are you sure you want to delete the content type "%name"? All nodes of this type will be lost.', array('%name' => $ctype->name)), 'admin/node/type/'. $ctype_id);
+  return confirm_form('flexinode_confirm_delete_content_type', $form, t('Are you sure you want to delete the content type "%name"? All nodes of this type will be lost.', array('%name' => $ctype->name)), 'admin/settings/content-types/flexinode/add/'. $ctype_id);
 }
 
 /**
@@ -332,6 +359,8 @@
  */
 function flexinode_admin_delete_content_type($ctype_id) {
   // TODO: Delete files as appropriate.
+  $ctype = flexinode_load_content_type($ctype_id);
+
   db_query('DELETE FROM {flexinode_type} WHERE ctype_id = %d', $ctype_id);
   db_query('DELETE FROM {flexinode_field} WHERE ctype_id = %d', $ctype_id);
   $result = db_query("SELECT nid FROM {node} WHERE type = '%s'", 'flexinode-' . $ctype_id);
@@ -340,7 +369,7 @@
   }
   db_query("DELETE FROM {node} WHERE type = '%s'", 'flexinode-' . $ctype_id);
 
-  drupal_set_message(t('deleted content type'));
+  drupal_set_message(t('deleted content type "%type"',array('%type' => $ctype->name)));
 
   // update the cached "create content" menu
   menu_rebuild();
@@ -356,10 +385,11 @@
 function flexinode_admin_field_form($field_id, $ctype_id = NULL) {
   if(is_numeric($field_id)) {
     $field = flexinode_load_field($field_id);
+    $ctype_id = $field->ctype_id;
   }
   else {
     $field->field_type = $field_id;
-    $ctype_id = $_POST['edit']['ctype_id'];
+    if(!is_numeric($ctype_id)) $ctype_id = $_POST['edit']['ctype_id'];
   }
   $form['label'] = array(
     '#type' => 'textfield',
@@ -416,8 +446,6 @@
     '#value' => $field->field_type,
     );
 
-  $form['#action'] = url('admin/node/field/'. $field_id);
-
   if ($field->field_id) {
     $form['delete'] = array(
       '#type' => 'submit',
@@ -442,30 +470,7 @@
  */
 function flexinode_admin_field_form_submit($form_id, $edit) {
   flexinode_admin_save_field($edit);
-  drupal_goto('admin/node/types/'. $edit['ctype_id']);
-}
-
-/**
- * Builds and returns the field select form.
- */
-function flexinode_admin_field_select($ctype_id = NULL) {
-  $form = $options = array();
-
-  $form['#action'] = url('admin/node/field');
-  $form['#redirect'] = FALSE;
-  $form['field_type'] = array(
-    '#type' => 'select',
-    '#options' => flexinode_admin_field_select_options(),
-    );
-  $form['ctype_id'] = array(
-    '#type' => 'hidden',
-    '#default_value' => $ctype_id,
-    );
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Add field'),
-    );
-  return drupal_get_form('flexinode_admin_field_select', $form);
+  drupal_goto('admin/settings/content-types/flexinode-'. $edit['ctype_id']);
 }
 
 /**
@@ -512,7 +517,7 @@
  * Generate a confirmation page prior to deleting a custom field.
  */
 function flexinode_admin_confirm_delete_field($field) {
-  return confirm_form('delete_field', array(), t('Are you sure you want to delete field "%name"? All data in this field will be lost.', array('%name' => $field->label)), 'admin/node/field/'. $field->field_id);
+  return confirm_form('delete_field', array(), t('Are you sure you want to delete field "%name"? All data in this field will be lost.', array('%name' => $field->label)), 'admin/settings/content-types/flexinode/field/'. $field->field_id);
 }
 
 /**
@@ -523,19 +528,5 @@
   db_query('DELETE FROM {flexinode_field} WHERE field_id = %d', $field->field_id);
   db_query('DELETE FROM {flexinode_data} WHERE field_id = %d', $field->field_id);
 
-  drupal_set_message(t('deleted field %name', array('%name' => $field->label)));
+  drupal_set_message(t('deleted field "%name"', array('%name' => $field->label)));
 }
-
-
-/**
- * THEME FUNCTIONS
-**/
-function theme_flexinode_type($type) {
-  $output = "<div><fieldset class=\"collapsible\"><legend>". $type->name ."</legend>\n";
-  $output .= "  <p class=\"description\">". $type->description ." (". theme('links', $type->links) .")</p>\n";
-  $output .= "  <p class=\"fields\">\n";
-  $output .= theme('item_list', $type->fieldlist, t('Field list'));
-  $output .= $type->controls ."</p>\n";
-  $output .= "</fieldset></div>\n";
-  return $output;
-}
\ No newline at end of file
