summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BitThemes.php83
-rw-r--r--admin/admin_layout_inc.php11
-rw-r--r--admin/admin_layout_overview_inc.php8
-rw-r--r--modules_inc.php10
-rw-r--r--templates/admin_layout.tpl3
-rw-r--r--templates/admin_layout_overview.tpl6
6 files changed, 91 insertions, 30 deletions
diff --git a/BitThemes.php b/BitThemes.php
index 9eb34c9..b06d5fa 100644
--- a/BitThemes.php
+++ b/BitThemes.php
@@ -369,6 +369,31 @@ class BitThemes extends BitBase {
}
/**
+ * fix postional data in database using increments of 10 to make it easy for inserting new modules
+ *
+ * @access public
+ * @return void
+ */
+ function fixPositions( $pLayout = NULL ) {
+ $layouts = $this->getAllLayouts();
+
+ // if we only want to fix the positions of a given layout, strip down the hash
+ if( !empty( $pLayout ) && !empty( $layouts[$pLayout] )) {
+ $layouts = array( $layouts[$pLayout] );
+ }
+
+ foreach( $layouts as $layout ) {
+ foreach( $layout as $column ) {
+ $i = 5;
+ foreach( $column as $module ) {
+ $this->mDb->query( "UPDATE `".BIT_DB_PREFIX."themes_layouts` SET pos=? WHERE module_id=?", array( $i, $module['module_id'] ));
+ $i += 5;
+ }
+ }
+ }
+ }
+
+ /**
* get a brief summary of set layouts
*
* @access public
@@ -381,10 +406,27 @@ class BitThemes extends BitBase {
$module['module_groups'] = $this->parseGroups( $module['groups'] );
$layouts[$module['layout']][$module['layout_area']][] = $module;
}
+ ksort( $layouts );
return $layouts;
}
/**
+ * expungeLayout
+ *
+ * @param array $pLayout
+ * @access public
+ * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ */
+ function expungeLayout( $pLayout = NULL ) {
+ $bindVars;
+ if( !empty( $pLayout )) {
+ $whereSql = "WHERE layout=?";
+ $bindVars[] = $pLayout;
+ }
+ $this->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."themes_layouts` $whereSql", $bindVars );
+ }
+
+ /**
* transform groups string to handy array
*
* @param array $pParseString either space separated list of groups or serialised array
@@ -505,20 +547,7 @@ class BitThemes extends BitBase {
*/
function moveModuleUp( $pModuleId ) {
if( @BitBase::verifyId( $pModuleId )) {
- // first we get next module we want to swap with
- $moduleData = $this->getModuleData( $pModuleId );
- $query = "SELECT MAX(`module_id`) FROM `".BIT_DB_PREFIX."themes_layouts` WHERE `layout`=? AND `layout_area`=? AND `pos`<=? AND `module_id`<>?";
- $swapModuleId = $this->mDb->getOne( $query, array( $moduleData['layout'], $moduleData['layout_area'], $moduleData['pos'], $moduleData['module_id'] ));
- if( $moduleSwap = $this->getModuleData( $swapModuleId )) {
- if( $moduleData['pos'] == $moduleSwap['pos'] ) {
- $query = "UPDATE `".BIT_DB_PREFIX."themes_layouts` SET `pos`=`pos`-1 WHERE `module_id`=?";
- $result = $this->mDb->query( $query, array( $moduleData['module_id'] ));
- } else {
- $query = "UPDATE `".BIT_DB_PREFIX."themes_layouts` SET `pos`=? WHERE `module_id`=?";
- $result = $this->mDb->query( $query, array( $moduleSwap['pos'], $moduleData['module_id'] ));
- $result = $this->mDb->query( $query, array( $moduleData['pos'], $moduleSwap['module_id'] ));
- }
- }
+ $this->moveModule( $pModuleId, 'up' );
}
return( count( $this->mErrors ) == 0 );
}
@@ -532,13 +561,35 @@ class BitThemes extends BitBase {
*/
function moveModuleDown( $pModuleId ) {
if( @BitBase::verifyId( $pModuleId )) {
+ $this->moveModule( $pModuleId, 'down' );
+ }
+ return( count( $this->mErrors ) == 0 );
+ }
+
+ /**
+ * generic function to move module up or down
+ *
+ * @param array $pModuleId
+ * @param string $pOrientation
+ * @access public
+ * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ */
+ function moveModule( $pModuleId, $pDirection = 'down' ) {
+ if( @BitBase::verifyId( $pModuleId )) {
// first we get next module we want to swap with
$moduleData = $this->getModuleData( $pModuleId );
- $query = "SELECT MIN(`module_id`) FROM `".BIT_DB_PREFIX."themes_layouts` WHERE `layout`=? AND `layout_area`=? AND `pos`>=? AND `module_id`<>?";
+ if( $pDirection == 'up' ) {
+ $pos_check = 'AND `pos`<=?';
+ $pos_set = 'SET `pos`=`pos`-1';
+ } else {
+ $pos_check = 'AND `pos`>=?';
+ $pos_set = 'SET `pos`=`pos`+1';
+ }
+ $query = "SELECT MAX(`module_id`) FROM `".BIT_DB_PREFIX."themes_layouts` WHERE `layout`=? AND `layout_area`=? $pos_check AND `module_id`<>?";
$swapModuleId = $this->mDb->getOne( $query, array( $moduleData['layout'], $moduleData['layout_area'], $moduleData['pos'], $moduleData['module_id'] ));
if( $moduleSwap = $this->getModuleData( $swapModuleId )) {
if( $moduleData['pos'] == $moduleSwap['pos'] ) {
- $query = "UPDATE `".BIT_DB_PREFIX."themes_layouts` SET `pos`=`pos`+1 WHERE `module_id`=?";
+ $query = "UPDATE `".BIT_DB_PREFIX."themes_layouts` $pos_set WHERE `module_id`=?";
$result = $this->mDb->query( $query, array( $moduleData['module_id'] ));
} else {
$query = "UPDATE `".BIT_DB_PREFIX."themes_layouts` SET `pos`=? WHERE `module_id`=?";
diff --git a/admin/admin_layout_inc.php b/admin/admin_layout_inc.php
index 6e1ca6b..c82492d 100644
--- a/admin/admin_layout_inc.php
+++ b/admin/admin_layout_inc.php
@@ -1,5 +1,5 @@
<?php
-// $Header: /cvsroot/bitweaver/_bit_themes/admin/admin_layout_inc.php,v 1.2 2007/04/04 18:07:15 squareing Exp $
+// $Header: /cvsroot/bitweaver/_bit_themes/admin/admin_layout_inc.php,v 1.3 2007/04/12 14:26:22 squareing Exp $
// Initialization
require_once( '../../bit_setup_inc.php' );
@@ -27,6 +27,10 @@ if( !empty( $_REQUEST['update_modules'] ) && is_array( $_REQUEST['modules'] )) {
}
}
+if( !empty( $_REQUEST['fix_pos'] )) {
+ $gBitThemes->fixPositions( $_REQUEST['module_package'] );
+}
+
if( !empty( $_REQUEST['module_name'] ) ) {
$fAssign['name'] = $_REQUEST['module_name'];
$gBitSmarty->assign( 'fAssign', $fAssign );
@@ -117,9 +121,8 @@ if( $processForm == 'Hide' ) {
$gBitThemes->storeModule( $fAssign );
}
-$sortedPackages = $gBitSystem->mPackages;
-asort( $sortedPackages );
-$gBitSmarty->assign( 'sortedPackages', $sortedPackages );
+// this will sort the layout selection dropdown
+ksort( $gBitSystem->mPackages );
$gBitSmarty->assign( 'module_package', $_REQUEST['module_package'] );
$layoutHash = array(
diff --git a/admin/admin_layout_overview_inc.php b/admin/admin_layout_overview_inc.php
index e8e9af3..8059ac9 100644
--- a/admin/admin_layout_overview_inc.php
+++ b/admin/admin_layout_overview_inc.php
@@ -6,6 +6,14 @@ if( !empty( $_REQUEST['update_modules'] ) && is_array( $_REQUEST['modules'] )) {
}
}
+if( !empty( $_REQUEST['fix_pos'] )) {
+ $gBitThemes->fixPositions();
+}
+
+if( !empty( $_REQUEST['remove_layout'] )) {
+ $gBitThemes->expungeLayout( $_REQUEST['remove_layout'] );
+}
+
if( isset( $_REQUEST['module_id'] ) && !empty( $_REQUEST['move_module'] )) {
if( isset( $_REQUEST['move_module'] )) {
switch( $_REQUEST['move_module'] ) {
diff --git a/modules_inc.php b/modules_inc.php
index a22536d..f97a1a8 100644
--- a/modules_inc.php
+++ b/modules_inc.php
@@ -1,6 +1,6 @@
<?php
/**
- * @version $Header: /cvsroot/bitweaver/_bit_themes/modules_inc.php,v 1.2 2007/04/03 14:10:54 squareing Exp $
+ * @version $Header: /cvsroot/bitweaver/_bit_themes/modules_inc.php,v 1.3 2007/04/12 14:26:21 squareing Exp $
* @package kernel
* @subpackage functions
*/
@@ -65,13 +65,7 @@ if( $gBitThemes->mLayout && empty( $gHideModules )) {
$replace[1] = " ";
$r['title'] = ( !empty( $r['title'] ) ? tra( $r['title'] ) : tra( ucfirst( preg_replace( $pattern, $replace, $r['module_rsrc'] ))));
}
- /* This was the old and now deprecated assignment stuff.
- $gBitSmarty->assign_by_ref( 'moduleTitle', $r['module_title'] );
- $gBitSmarty->assign_by_ref( 'module_rows', $module_rows = $r['module_rows'] );
- $gBitSmarty->assign_by_ref( 'module_id', $r["module_id"] );
- $gBitSmarty->assign_by_ref( 'module_layout', $r["layout"] );
- $gBitSmarty->assign_by_ref( 'moduleParams', $moduleParams = $r );
- */
+
// moduleParams are extracted in BitSmarty::getSiblingAttachments() and passed on the the module php file
$gBitSmarty->assign_by_ref( 'moduleParams', $moduleParams = $r );
// assign the custom module title
diff --git a/templates/admin_layout.tpl b/templates/admin_layout.tpl
index 60c6110..6dd5d4c 100644
--- a/templates/admin_layout.tpl
+++ b/templates/admin_layout.tpl
@@ -35,6 +35,7 @@
<div class="submit">
<input type="submit" name="update_modules" value="{tr}Update Module Settings{/tr}" />
+ <input type="submit" name="fix_pos" value="{tr}Adjust module positions{/tr}" />
</div>
{/form}
@@ -44,7 +45,6 @@
{formlabel label="Create Customized layout for" for="module_package"}
{forminput}
<select name="module_package" id="module_package" onchange="this.form.submit();">
- <option value="home" {if $module_package == 'home'}selected="selected"{/if}>{tr}User Homepages{/tr}</option>
{foreach key=name item=package from=$gBitSystem->mPackages}
{if $package.installed and ($package.activatable or $package.tables)}
<option value="{$name}" {if $module_package == $name}selected="selected"{/if}>
@@ -56,6 +56,7 @@
</option>
{/if}
{/foreach}
+ <option value="home" {if $module_package == 'home'}selected="selected"{/if}>{tr}User Homepages{/tr}</option>
</select>
<noscript>
diff --git a/templates/admin_layout_overview.tpl b/templates/admin_layout_overview.tpl
index 65bc4c8..025e70b 100644
--- a/templates/admin_layout_overview.tpl
+++ b/templates/admin_layout_overview.tpl
@@ -5,7 +5,10 @@
<input type="hidden" name="page" value="{$page}" />
{foreach from=$layouts item=layout key=module_package}
- <h1>{tr}Current Layout of '{if !$module_package || $module_package=='kernel'}Site Default{else}{$module_package|capitalize}{/if}'{/tr}</h1>
+ <h1>
+ {tr}Current Layout of '{if !$module_package || $module_package=='kernel'}Site Default{else}{$module_package|capitalize}{/if}'{/tr}
+ &nbsp; {smartlink ititle="Remove this Layout" ibiticon="icons/edit-delete" page=$page remove_layout=$module_package ionclick="return confirm('{tr}Are you sure you want to remove this layout? This can not be undone.{/tr}')"}
+ </h1>
<table style="width:100%" cellpadding="5" cellspacing="0" border="0">
<tr>
@@ -38,6 +41,7 @@
<div class="submit">
<input type="submit" name="update_modules" value="{tr}Update Module Settings{/tr}" />
+ <input type="submit" name="fix_pos" value="{tr}Adjust module positions{/tr}" />
</div>
{/form}
{/strip}