D7 delete page in page builder mod

Someone wanted a mod that will delete a page in pagebuilder. I wrote a quickie mod during my lunch. PM me if you want to test it.

I will post a tutorial instead. Hold on, give me a second.

Updating my BoonexNerd.net site.
Quote · 17 Dec 2009

It's free or if you want to show some appreciation please donate to the Canadian Cancer Society. If you can show me your donation receipt (whatever amount) I will send you the Alert Pay mod I am working on. That one is free as well but you will get a first hand preview of it.

*If the link didn't work try this one http://www.cancer.ca/

Updating my BoonexNerd.net site.
Quote · 17 Dec 2009

Hand it over!  I like delete buttons.

My opinions expressed on this site, in no way represent those of Boonex or Boonex employees.
Quote · 17 Dec 2009

jt does this work on 6 and 7?

When a GIG is not enough --> Terabyte Dolphin Technical Support - Server Management and Support
Quote · 17 Dec 2009

jt does this work on 6 and 7?

d7 only at this time.

I think someone made one. Deano, was it you? I know you had your utilities - very handy too.

Updating my BoonexNerd.net site.
Quote · 17 Dec 2009

jt, on the bill pay, the link you posted dont work, goes to an about:blank. hit me with a link and i will contribute to your payment mod.

Regards,

DosDawg

When a GIG is not enough --> Terabyte Dolphin Technical Support - Server Management and Support
Quote · 17 Dec 2009

jt does this work on 6 and 7?

d7 only at this time.

I think someone made one. Deano, was it you? I know you had your utilities - very handy too.


Nope not me. Not part of my tools mod.

https://www.deanbassett.com
Quote · 17 Dec 2009

The page template that drives the pageBuilder.php file is pbuilder_cpanel.html.

In this template, you can add buttons next to the Add Column, Add Page and Go buttons. This template also controls how new pages are added.

Here's what it looks like:

<div class="adm-db-control-panel">
<div class="adm-pb-cp-item">
<form name="pageSelector" method="get" action="__url__">
<bx_text:_adm_txt_pb_page />
<select class="form_input_select" name="Page" onchange="if (this.value && this.value != 'none') this.form.submit()">
<bx_repeat:pages>
<option value="__value__" __selected__>__title__</option>
</bx_repeat:pages>
</select>
<input type="submit" value="<bx_text:_adm_btn_Go />" />
</form>
</div>

<div class="adm-pb-cp-item-right">
<div class="button_wrapper">
<input type="button" value="<bx_text:_adm_btn_add_page />" class="form_input_submit" onclick="javascript:createNewBuilderPage()" />
<div class="button_wrapper_close">&nbsp;</div>
</div>
</div>


<div class="adm-pb-cp-item-right">
<div class="button_wrapper">
<input type="button" value="<bx_text:_adm_btn_add_column />" id="addColumnButton" class="form_input_submit" onclick="javascript:oPB.addColumn()" disabled="disabled" />
<div class="button_wrapper_close">&nbsp;</div>
</div>
</div>
<div class="clear_both">&nbsp;</div>
<script type="text/javascript" language="javascript">
<!--
function createNewBuilderPage() {
var sNewPage = prompt('<bx_text:_adm_txt_pb_enter_name_of_new_page />', 'New Page');
if(sNewPage != undefined && $.trim(sNewPage) != '')
window.location = '__url__?create_new=true&Page=' + encodeURIComponent( sNewPage );
}
-->
</script>
</div>

This part will list the pages that are available for editing:

<bx_repeat:pages>
<option value="__value__" __selected__>__title__</option>
</bx_repeat:pages>

You notice the keys being used. Those are derived from the following:

[more info about keys and tokens in d7 and how they differ from d6]


This part will allow you to add a button to the top of the page. You can use this as a starting template:

<div class="adm-pb-cp-item-right">
<div class="button_wrapper">
<input type="button" value="<bx_text:_adm_btn_add_page />" class="form_input_submit" onclick="javascript:createNewBuilderPage()" />
<div class="button_wrapper_close">&nbsp;</div>
</div>
</div>

Notice the onClick JavaScript. Further down it calls the following function:

<script type="text/javascript" language="javascript">
<!--
function createNewBuilderPage() {
var sNewPage = prompt('<bx_text:_adm_txt_pb_enter_name_of_new_page />', 'New Page');
if(sNewPage != undefined && $.trim(sNewPage) != '')
window.location = '__url__?create_new=true&Page=' + encodeURIComponent( sNewPage );
}
-->
</script>

You can use this same approach to add an action to you any button you add. For example, let's say we wanted to add a Delete button. Before, you can just drag out the contents of the page in page builder and the page would automatically disappear. For Dolphin 7, we have to detete directory from the database.

Before we can delete a page, we have to understand how exactly a page is created via the admin panel and in the backend. So here are my notes:

1. In Page Builder click the Add Page button.
2. A dialog box appears where you can enter the name of your page.
3. Once you hit the OK button, a series of actions take place, The first being the function createNewBuilderPage() is fired. It then passes a querystring containing two values. They are:

create_new=true&Page=' + encodeURIComponent( sNewPage );

The name/value pair create_new=true just tells the action page the mode that we're going to use. In this case, we want to creat a new page, hence the true value.

The Page name/value pair first encodes the page name that was entered so it's a form that we can pass over to the action page.

In my example, I used "James Test Page" to create a page. When it hits the action page it adds an entry in the following tables:

sys_page_compose_pages - Fields list: Name, Title, Order, System

Once you add a column and content, a new entry is made in the following table:


sys_page_compose - Fields list: ID, Page, PageWidth, Desc, Caption, Column, Order, Func, Content, DesignBox, ColWidth, Visible, MinWidth

In effect, James-Test-Page becomes the name of the page within the database. That would be the name you would reference when you need to delete the page.

If we were to do a search for "James-Test-Page" it will pull up the tables

sys_page_compose
sys_page_compose_pages

This makes sense as it should match the tables where the page entries were made.

Now that we know how pages are made, we now know what parts of the tables we need to work with in order delete a page.


HOW TO DELETE A PAGE
Earlier we looked at how pages were made. The action page used for adding pages is called:

BxDolPageViewAdmin.php

It's located in the inc/classes folder.

This page takes the passed values and then manipulates the database. It's activated when the Add Page button is pressed which then fires the function createNewBuilderPage(). That function, remember looks like this:

function createNewBuilderPage() {
var sNewPage = prompt('<bx_text:_adm_txt_pb_enter_name_of_new_page />', 'New Page');
if(sNewPage != undefined && $.trim(sNewPage) != '')
window.location = '__url__?create_new=true&Page=' + encodeURIComponent( sNewPage );
}

So what we need to do is to add a delete page action? See below.


---



Here's the complete code for the pbuilder_cpanel.html page:

<div class="adm-db-control-panel">
<div class="adm-pb-cp-item">
<form name="pageSelector" method="get" action="__url__">
<bx_text:_adm_txt_pb_page />
<select id="pageValue" class="form_input_select" name="Page" onchange="if (this.value && this.value != 'none') this.form.submit()">
<bx_repeat:pages>
<option value="__value__" __selected__>__title__</option>
</bx_repeat:pages>
</select>
<input type="submit" value="<bx_text:_adm_btn_Go />" />
</form>
</div>


<div class="adm-pb-cp-item-right">
<div class="button_wrapper">
<input type="button" value="Delete This Page" class="form_input_submit" onclick="javascript:deleteCurrentPage()" />
<div class="button_wrapper_close">&nbsp;</div>
</div>
</div>


<div class="adm-pb-cp-item-right">
<div class="button_wrapper">
<input type="button" value="<bx_text:_adm_btn_add_page />" class="form_input_submit" onclick="javascript:createNewBuilderPage()" />
<div class="button_wrapper_close">&nbsp;</div>
</div>
</div>


<div class="adm-pb-cp-item-right">
<div class="button_wrapper">
<input type="button" value="<bx_text:_adm_btn_add_column />" id="addColumnButton" class="form_input_submit" onclick="javascript:oPB.addColumn()" disabled="disabled" />
<div class="button_wrapper_close">&nbsp;</div>
</div>
</div>
<div class="clear_both">&nbsp;</div>
<script type="text/javascript" language="javascript">
<!--
function createNewBuilderPage() {
var sNewPage = prompt('<bx_text:_adm_txt_pb_enter_name_of_new_page />', 'New Page');
if(sNewPage != undefined && $.trim(sNewPage) != '')
window.location = '__url__?create_new=true&Page=' + encodeURIComponent( sNewPage );
}

function deleteCurrentPage() {
page2Delete = document.getElementById("pageValue").value;
window.location = '__url__?delete_page=true&Page=' + page2Delete;
}
-->
</script>


</div>



Here's where you  put the code for the BxDolPageViewAdmin.php file:

<?php
/***************************************************************************
*                            Dolphin Smart Community Builder
*                              -------------------
*     begin                : Mon Mar 23 2006
*     copyright            : (C) 2007 BoonEx Group
*     website              : http://www.boonex.com
* This file is part of Dolphin - Smart Community Builder
*
* Dolphin is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the
* License, or  any later version.
*
* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Dolphin,
* see license.txt file; if not, write to marketing@boonex.com
***************************************************************************/

require_once( BX_DIRECTORY_PATH_ROOT . 'plugins/Services_JSON.php' );

class BxDolPageViewAdmin {
var $aPages = array();
var $oPage;
var $sPage_db; //name of current page, used form database manipulations
var $sDBTable; //used database table
var $bAjaxMode = false;
var $aTitles; // array containing aliases of pages

function BxDolPageViewAdmin( $sDBTable, $sCacheFile ) {


//jt note - Delete Page START --------------------------------------------------------------------//
if ($_GET['delete_page'] == 'true') {   

//set up connection to MySql server
$jt_dbHost = DATABASE_HOST;
$jt_dbLogin = DATABASE_USER;
$jt_dbPass = DATABASE_PASS;
$jt_db = DATABASE_NAME;

//$Name = "Test-Page";
$Name = $_GET['Page'];

$connection=mysql_connect("$jt_dbHost","$jt_dbLogin","$jt_dbPass") or die("Couldn't connect to the server.");                      

//select the database
$db=mysql_select_db("$jt_db", $connection) or die("Couldn't select a database.");
mysql_query("DELETE FROM `sys_page_compose_pages` WHERE `sys_page_compose_pages`.`Name` = '" . $Name . "' LIMIT 1",$connection);
mysql_query("DELETE FROM `sys_page_compose` WHERE `sys_page_compose`.`Page` = '" . $Name . "' LIMIT 1",$connection);

mysql_close($connection);
}
//jt note - Delete Page END --------------------------------------------------------------------//



$GLOBALS['oAdmTemplate']->addJsTranslation(array(
'_adm_pbuilder_Reset_page_warning',
'_adm_pbuilder_Column_non_enough_width_warn',
'_adm_pbuilder_Column_delete_confirmation',
'_adm_pbuilder_Add_column',
'_adm_pbuilder_Want_to_delete'
));

....lots of code below....

Updating my BoonexNerd.net site.
Quote · 17 Dec 2009

Very well done. Thank You

https://dolphin-techs.com - Skype: Dolphin Techs
Quote · 17 Dec 2009

Whoa!  That's complicated.  Looking at all that code makes my head hurt.

My opinions expressed on this site, in no way represent those of Boonex or Boonex employees.
Quote · 17 Dec 2009

Nice work James, but I really think there needs to be some safeguards in place for such a powerful feature. Could you build something like this into the function?

Delete

My opinions expressed on this site, in no way represent those of Boonex or Boonex employees.
Quote · 17 Dec 2009

I know this is an old post, but I am still on 7.01. I tried this mod and when I added the code to  BxDolPageViewAdmin.php all I get is a blank white page when trying to access the page so I can never see if the delete button is there.

Any ideas?

Quote · 2 Jun 2011

have you cleared your cache files after  from ftp  don't remove the htaccess file in the cache map.

Kids first
Quote · 2 Jun 2011

 

I know this is an old post, but I am still on 7.01. I tried this mod and when I added the code to  BxDolPageViewAdmin.php all I get is a blank white page when trying to access the page so I can never see if the delete button is there.

Any ideas?

Blank white pages usally indicates a error has occured. Check PHP error logs on the server or enable display_error in your php.ini so you can find out whats happening.


https://www.deanbassett.com
Quote · 2 Jun 2011
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.