? tinymce
Index: tinymce.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tinymce/tinymce.install,v
retrieving revision 1.6.2.7
diff -u -p -r1.6.2.7 tinymce.install
--- tinymce.install	25 Feb 2007 20:02:44 -0000	1.6.2.7
+++ tinymce.install	30 Mar 2007 14:21:10 -0000
@@ -18,6 +18,7 @@ function tinymce_install() {
       db_query("CREATE TABLE {tinymce_settings} (
                 name varchar(128) NOT NULL default '',
                 settings text NOT NULL default '',
+                priority tinyint(3) unsigned NOT NULL default '0',
                 PRIMARY KEY (name)
                ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
   
@@ -32,6 +33,7 @@ function tinymce_install() {
       db_query("CREATE TABLE {tinymce_settings} (
                 name varchar(128) NOT NULL default '',
                 settings text NOT NULL default '',
+                priority smallint NOT NULL default '0',
                 PRIMARY KEY (name)
                );");
      
@@ -44,6 +46,26 @@ function tinymce_install() {
    }
 }
 
+/**
+ * Implementation of hook_update_N().
+ */
 function tinymce_update_1() {
   return _system_update_utf8(array('tinymce_settings', 'tinymce_role'));
 }
+
+/**
+ * Implementation of hook_update_N().
+ */
+function tinymce_update_2() {
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {tinymce_settings} ADD priority tinyint(3) unsigned NOT NULL default '0'");
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("ALTER TABLE {tinymce_settings} ADD COLUMN priority smallint NOT NULL default '0'");
+      break;
+  }
+  return $ret;
+}
+
Index: tinymce.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tinymce/tinymce.module,v
retrieving revision 1.90.4.16
diff -u -p -r1.90.4.16 tinymce.module
--- tinymce.module	25 Feb 2007 20:02:44 -0000	1.90.4.16
+++ tinymce.module	30 Mar 2007 14:21:11 -0000
@@ -84,7 +84,17 @@ function tinymce_process_textarea($eleme
   // Since tinymce_config() makes a db hit, only call it when we're pretty sure
   // we're gonna render tinymce.
   if (!$profile_name) {
-    $profile_name = db_result(db_query('SELECT s.name FROM {tinymce_settings} s INNER JOIN {tinymce_role} r ON r.name = s.name WHERE r.rid IN (%s)', implode(',', array_keys($user->roles))));
+    $profile_name = db_result(db_query("
+      SELECT name
+      FROM {tinymce_settings}
+      WHERE priority = (
+        SELECT MIN(s.priority)
+        FROM {tinymce_settings} s
+        INNER JOIN {tinymce_role} r
+        ON r.name = s.name
+        WHERE r.rid IN (%s)
+      )
+    ", implode(',', array_keys($user->roles))));
   }
   $profile = tinymce_profile_load($profile_name);
   $init = tinymce_config($profile);
@@ -989,7 +999,7 @@ function tinymce_profile_load($name = ''
 
   if (!$profiles) {
     $roles = user_roles();
-    $result = db_query('SELECT * FROM {tinymce_settings}');
+    $result = db_query('SELECT * FROM {tinymce_settings} ORDER BY priority');
     while ($data = db_fetch_object($result)) {
       $data->settings = unserialize($data->settings);
       $result2 = db_query("SELECT rid FROM {tinymce_role} WHERE name = '%s'", $data->name);
@@ -1010,22 +1020,79 @@ function tinymce_profile_load($name = ''
  * Controller for tinymce profiles.
  */
 function tinymce_profile_overview() {
-  $output = '';
-
   $profiles = tinymce_profile_load();
-  if ($profiles) {
-    $roles = user_roles();
-    $header = array(t('Profile'), t('Roles'), t('Operations'));
-    foreach ($profiles as $p) {
-      $rows[] = array(array('data' => $p->name, 'valign' => 'top'), array('data' => implode("<br />\n", $p->rids)), array('data' => l(t('edit'), 'admin/settings/tinymce/edit/'. urlencode($p->name)) . ' '. l(t('delete'), 'admin/settings/tinymce/delete/'. urlencode($p->name)), 'valign' => 'top'));
-    }
-    $output .= theme('table', $header, $rows);
+  if (!empty($profiles)) {
+    $output = drupal_get_form('tinymce_form_profile_overview', $profiles);
     $output .= t('<p><a href="!create-profile-url">Create new profile</a></p>', array('!create-profile-url' => url('admin/settings/tinymce/add')));
   }
   else {
+    $output = '';
     drupal_set_message(t('No profiles found. Click here to <a href="!create-profile-url">create a new profile</a>.', array('!create-profile-url' => url('admin/settings/tinymce/add'))));
   }
+  return $output;
+}
+
+function tinymce_form_profile_overview($profiles) {
+  $form = array();
+  $count = count($profiles);
+  $option = 0;
+  while ($option < $count) {
+    $options[] = ++$option;
+  }
+  foreach ($profiles as $p) {
+    $form['profile']['#tree'] = TRUE;
+    $form['profile'][$p->name] = array(
+      '#type' => 'select',
+      '#options' => $options,
+      '#default_value' => db_result(db_query("SELECT priority FROM {tinymce_settings} WHERE name = '%s'", $p->name)),
+    );
+  }
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Sort'),
+  );
+  return $form;
+}
 
+function tinymce_form_profile_overview_validate($form_id, $form_values) {
+  foreach ($form_values['profile'] as $profile => $priority) {
+    if (!is_numeric($priority)) {
+      form_set_error($form_values['profile'][$profile], t('Priority must be a numeric value.'));
+    }
+  }
+}
+
+function tinymce_form_profile_overview_submit($form_id, $form_values) {
+  foreach ($form_values['profile'] as $profile => $priority) {
+    db_query("UPDATE {tinymce_settings} SET priority = %d WHERE name = '%s'", $priority, $profile);
+  }
+}
+
+function theme_tinymce_form_profile_overview($form) {
+  $header = array(t('Priority'), t('Profile'), t('Roles'), t('Operations'));
+  $rows = array();
+  $profiles = tinymce_profile_load();
+  foreach ($profiles as $p) {
+    $rows[] = array(
+      array(
+        'data' => drupal_render($form['profile'][$p->name]),
+        'valign' => 'top',
+      ),
+      array(
+        'data' => $p->name,
+        'valign' => 'top',
+      ),
+      array(
+        'data' => implode("<br />\n", $p->rids),
+      ),
+      array(
+        'data' => l(t('edit'), 'admin/settings/tinymce/edit/'. urlencode($p->name)) .' '. l(t('delete'), 'admin/settings/tinymce/delete/'. urlencode($p->name)),
+        'valign' => 'top',
+      ),
+    );
+  }
+  $output = theme('table', $header, $rows);
+  $output .= drupal_render($form);
   return $output;
 }
 
@@ -1110,7 +1177,17 @@ function _tinymce_page_match($edit) {
 }
 
 function tinymce_user_get_profile($account) {
-  $profile_name = db_result(db_query('SELECT s.name FROM {tinymce_settings} s INNER JOIN {tinymce_role} r ON r.name = s.name WHERE r.rid IN (%s)', implode(',', array_keys($account->roles))));
+  $profile_name = db_result(db_query("
+    SELECT name
+    FROM {tinymce_settings}
+    WHERE priority = (
+      SELECT MIN(s.priority)
+      FROM {tinymce_settings} s
+      INNER JOIN {tinymce_role} r
+      ON r.name = s.name
+      WHERE r.rid IN (%s)
+    )
+  ", implode(',', array_keys($account->roles))));
   if ($profile_name){
     return tinymce_profile_load($profile_name);
   }
