';
}
- elseif(isset($_POST['create']))
+
+ return print enano_json_encode(array(
+ 'mode' => 'success'
+ ));
+ }
+
+ // $template->preload_js(array('l10n', 'jquery', 'jquery-ui'));
+ // $template->add_header('');
+
+ // $template->header();
+
+ if(isset($_POST['save']))
+ {
+ // Write the new block order to the database
+ // The only way to do this is with tons of queries (one per block + one select query at the start to count everything) but afaik its safe...
+ // Anyone know a better way to do this?
+ $q = $db->sql_query('SELECT item_order,item_id,sidebar_id FROM '.table_prefix.'sidebar ORDER BY sidebar_id ASC, item_order ASC;');
+ if ( !$q )
{
- switch((int)$_POST['type'])
- {
- case BLOCK_WIKIFORMAT:
- $content = $_POST['wikiformat_content'];
- break;
- case BLOCK_TEMPLATEFORMAT:
- $content = $_POST['templateformat_content'];
- break;
- case BLOCK_HTML:
- $content = $_POST['html_content'];
- break;
- case BLOCK_PHP:
- $content = $_POST['php_content'];
- break;
- case BLOCK_PLUGIN:
- $content = $_POST['plugin_id'];
- break;
- }
-
- if ( defined('ENANO_DEMO_MODE') )
+ $db->_die('The sidebar order data could not be selected.');
+ }
+ $orders = Array();
+ while($row = $db->fetchrow())
+ {
+ $orders[] = Array(
+ count($orders),
+ $row['item_id'],
+ $row['sidebar_id'],
+ );
+ }
+ $db->free_result();
+
+ // We now have an array with each sidebar ID in its respective order. Explode the order string in $_POST['order_(left|right)'] and use it to build a set of queries.
+ $ol = explode(',', $_POST['order_left']);
+ $odr = explode(',', $_POST['order_right']);
+ $om = array_merge($ol, $odr);
+ unset($ol, $odr);
+ $queries = Array();
+ foreach($orders as $k => $v)
+ {
+ $queries[] = 'UPDATE '.table_prefix.'sidebar SET item_order='.intval($om[$k]).' WHERE item_id='.intval($v[1]).';';
+ }
+ foreach($queries as $sql)
+ {
+ $q = $db->sql_query($sql);
+ if(!$q)
{
- // Sanitize the HTML
- $content = sanitize_html($content, true);
- }
-
- if ( defined('ENANO_DEMO_MODE') && intval($_POST['type']) == BLOCK_PHP )
- {
- echo '
' . $lang->get('sbedit_err_demo_php_disable') . '
';
- $_POST['php_content'] = '?><Nulled>';
- $content = $_POST['php_content'];
- }
-
- // Get the value of item_order
-
- $q = $db->sql_query('SELECT * FROM '.table_prefix.'sidebar WHERE sidebar_id='.intval($_POST['sidebar_id']).';');
- if(!$q) $db->_die('The order number could not be selected');
- $io = $db->numrows();
-
- $db->free_result();
-
- $q = 'INSERT INTO '.table_prefix.'sidebar(block_name, block_type, sidebar_id, block_content, item_order) VALUES ( \''.$db->escape($_POST['title']).'\', \''.$db->escape($_POST['type']).'\', \''.$db->escape($_POST['sidebar_id']).'\', \''.$db->escape($content).'\', '.$io.' );';
- $result = $db->sql_query($q);
- if(!$result)
- {
- echo $db->get_error();
- $template->footer();
+ $t = $db->get_error();
+ echo $t;
+
exit;
}
+ }
+ $cache->purge('anon_sidebar');
+ echo '