Here is a link to my page:
http://freebies4real.com/f4rtest21212/
It is not saving the column order when i arrange it… why?
My index.php file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Testing!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="testing" />
<meta name="keywords" content="blah" />
<meta name="description" content="blah" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1/prototype.js"></script>
<script type="text/javascript" src="assets/js/scriptaculous.js"></script>
<script type="text/javascript" src="assets/js/portal.js"></script>
<script type="text/javascript">
var settings = {'column-1' : ['block-1','block-2'],
'column-2' : ['block-3'],
'column-3' : ['block-4']};
var options = { portal : 'columns',
editorEnabled : true, };
var data = {};
var portal;
Event.observe(window, 'load', function() {
portal = new Portal(settings, options, data);
});
</script>
<link rel="stylesheet" href="assets/css/style.css" type="text/css" media="screen" />
<link rel="stylesheet" href="assets/css/portal.css" type="text/css" media="screen" />
</head>
<body>
<div style="padding-bottom:5px;width:728px;height:90px">
<script type="text/javascript"><!--
google_ad_client = "pub-0714236485040063";
/* 728x90, opprettet 14.08.08 */
google_ad_slot = "8581783445";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div id="wrapper">
<h1>Imma try and incorporate to vbulletin</h1>
<p></p>
<div style="clear:both;"></div>
<hr />
<div id="columns">
<div id="column-1" class="column menu"></div>
<div id="column-2" class="column blocks"></div>
<div id="column-3" class="column sidebar"></div>
<div class="portal-column" id="portal-column-block-list" style="display: none;">
<div class="block" id="block-1">
<h1 class="draghandle">Block 1</h1>
<p>Block 1 data</p>
</div>
<div class="block" id="block-2">
<h1 class="draghandle">Block 2</h1>
<p>Block 2 data</p>
</div>
<div class="block" id="block-3">
<h1 class="draghandle">Block 3</h1>
<p>Block 3 data</p>
</div>
<div class="block" id="block-4">
<h1 class="draghandle">Block 4</h1>
<p>Block 4 data</p>
</div>
</div>
</div>
<div style="clear:both;"></div>
<div style="clear:both;"></div>
<hr style="margin-top: 40px;" />
<div style="clear:both;"></div>
<div id="browser-support">
Supported browsers: Just about all of them: IE6, IE7, IE8, FireFox, Safari, Chrome, Opera and more.
</div>
<div style="clear:both;"></div>
</div>
</body>
</html>
My save.php file:
<?
/*
--
-- Table structure for table `blocks`
--
CREATE TABLE `blocks` (
`unique_id` int(11) NOT NULL auto_increment,
`block_id` varchar(255) NOT NULL default '',
`column_id` varchar(255) NOT NULL default '',
`order_id` int(11) NOT NULL default '0',
PRIMARY KEY (`unique_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
--
-- Dumping data for table `blocks`
--
INSERT INTO `blocks` VALUES(1, 'block-1', 'column-1', 0);
INSERT INTO `blocks` VALUES(2, 'block-3', 'column-2', 0);
INSERT INTO `blocks` VALUES(3, 'block-2', 'column-3', 0);
INSERT INTO `blocks` VALUES(4, 'block-4', 'column-2', 1);
*/
/* connect to mysql */
$link = mysql_connect('localhost', 'db_username', 'password') or die('DB Connection failed');
mysql_select_db('database');
$data = $_POST;
foreach ($data as $row)
{
/* split up in segments */
$segments = explode(':', $row);
/* define the column */
$column_id = $segments[0];
/* the blocks */
$blocks = explode(',', $segments[1]);
/* we take each block */
foreach ($blocks as $order_id => $block_id)
{
/* check if the block is already present in the database */
$block_exists = mysql_fetch_row(mysql_query("SELECT * FROM blocks WHERE block_id = '{$block_id}'"));
/* if not, we insert it */
if ($block_exists == FALSE)
{
if (empty($block_id)) return;
//mysql_query("INSERT INTO blocks (block_id, column_id, order_id) VALUES ('{$block_id}', '{$column_id}', {$order_id})");
echo "Moved block: {$block_id} to column: {$column_id} and updated rank to: {$order_id}<br />";
}
/* or else we update it */
else
{
if (empty($block_id)) return;
//mysql_query("UPDATE blocks SET block_id = '{$block_id}', column_id = '{$column_id}', order_id = {$order_id} WHERE unique_id = ".$block_exists[0]);
echo "Moved block: {$block_id} to column: {$column_id} and updated rank to: {$order_id}<br />";
}
}
}
?>
My Get_Blocks.php file:
<?
/* connect to mysql */
$link = mysql_connect('localhost', 'db_username', 'password') or die('DB Connection failed');
mysql_select_db('database');
/* you could customize this function to get blocks for a specific page or something */
function getBlocks() {
/* get blocks and order by columns */
$blocks = mysql_query("SELECT * FROM blocks ORDER BY order_id ASC");
$columns = array();
while($block = mysql_fetch_array($blocks, MYSQL_ASSOC))
{
$columns[$block['column_id']][] = $block;
}
/* create settings array in javascript style */
$settings = array();
$block_data = array();
foreach ($columns as $column_name => $blocks)
{
$block_to_settings = array();
foreach ($blocks as $block)
{
$block_to_settings[] = '\\''.$block['block_id'].'\\'';
}
$settings[] = '\\''.$column_name.'\\'' . ':[' . implode(',', $block_to_settings).']';
}
return implode(',', $settings);
}
?>