? 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 29 Mar 2007 22:02:40 -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) );"); 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 29 Mar 2007 22:02:41 -0000 @@ -989,7 +989,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 +1010,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("
\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('

Create new profile

', array('!create-profile-url' => url('admin/settings/tinymce/add'))); } else { + $output = ''; drupal_set_message(t('No profiles found. Click here to create a new profile.', 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("
\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 +1167,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 s.name + FROM {tinymce_settings} s + WHERE s.priority = ( + SELECT MAX(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); }