Home Private Messages Search
CPG Dragonfly™ CMS stopsoftwarepatents.eu petition banner
Toggle Content
 
Forums ⇒ DragonflyCMS ⇒ Add-Ons & Blocks ⇒ Some jQuery functionality for DF modules


Some jQuery functionality for DF modules
Need help creating a block or add-on, or you have created or modified a block/add-on that works in Dragonfly CMS and it meets the CPG Security Requirements? Do you have feedback about a specific add-on? Here is the place to post. Read the announcements here first!.
Go to page 1, 2  Next
Post new topic    Reply to topic    Printer Friendly Page     Forum Index ⇒  Add-Ons & Blocks

View previous topic :: View next topic  
Author Message
Kendle
500+ Posts Club
500+ Posts Club

Offline Offline
Joined: Dec 16, 2004
Posts: 552

PostPosted: Mon Jun 28, 2010 8:30 pm
Post subject: Some jQuery functionality for DF modules

I've packaged a little class I've just developed for adding some limited jQuery functionality to DragonFly modules.

jQuery is a javascript framework for adding so-called Web 2.0 features to websites. (see http://jquery.com/) This class supports 3 jQuery functions / widgets, namely :-

Date Time Picker

These functions create a pop-up calendar from which a user can select a date and attaches it to a date entry field in a form. The user enters the date in their own local timezone and it is converted to GMT for storage in the database. There are functions provided which will display a stored GMT date / time to the user in their local timezone.

Tabs

The tab functions allow content to be presented in a tabbed display, with the contents of each tab being produced on-demand via an AJAX call to another page in the module (or some other page somewhere else).

Tooltips

Tooltips work like DragonFly's own help boxes except the content of the box is provided on-demand via an AJAX call to another page in the module (or some other page somewhere else).




In action

I've recently been working on a site for an online gaming organisation called Urban Zone. Here are some pages which show some of this functionaility in action :-

http://www.urban-zone.org/dragonfly/index.php?name=Competition&event=2

See the tabs part way down the page. Clicking a tab loads content via an AJAX call (to another page in the module, which doesn't call "header.php" and is therefore just content).

Check the "Fixtures" and "Teams" tabs, where you'll see a little magnifying glass icon. Hover over this and a box pops up containing more stuff loaded on demand via an AJAX call.

Also on the Calendar page :-

http://www.urban-zone.org/dragonfly/index.php?name=Competition&file=calendar

Hovering over the time produces a pop-up showing details of a match.

I can't really show you the date function because that's used in data entry forms which you won't see as a guest to the site.




Installation

Get the package from the Download section on my website :-

http://www.cmsdreams.co.uk/index.php?name=Downloads&file=details&id=7

Upload the contents of this package 'as is' to your DragonFly website.




Customisation

The HTML generated by the jQuery scripts in this package use the jQuery CSS framework. You can download other CSS files and associated images from

http://jqueryui.com/

You can either create your own theme using jQuery's ThemeRoller application

http://jqueryui.com/themeroller/

Or download an existing theme from their gallery

http://jqueryui.com/themeroller/#themeGallery

Once you're ready to download a theme click the "Download" button and on the page that appears select version 1.7.3 (which is for jQuery 1.3.x) and then click the "Download" button again. This class does not support the just released (at time of writing) 1.4.x jQuery series.

From the .zip file you download upload the following files to your website

/css/custom-theme/images ---> /themes/YOURTHEME/images
/css/custom-theme/jquery-ui-1.7.3.custom.css ---> themes/YOURTHEME

Note: the CSS file goes in the theme folder, NOT /themes/YOURTHEME/style because the image locations in the CSS are url(images/) not url(../images/) and this will save you a lot of editing.




Date Time Picker

In your module declare an instance of the class :-

PHP:

$jQ
= new jquery();

Then initialise the date time picker functions :-

PHP:

$jQ
->date(true, true, true, 15);

This function takes the following parameters :-

$europe
true = use European date format (dd-mm-yyyy)
false = use American date format (mm-dd-yyyy)
default = true

$usestr
true = supply and return dates as a string YYYY-MM-DD HH:MM
false = supply and return dates as a UNIX timestamp
default = true

$usetim
true = add a drop down list of times
false = use dates only
default = true

$timseg
if $usetim is true how far apart should the times be? eg: if this value is 15 (default) the drop-down will contain values 00:00, 00:15, 00:30, 00:45, 01:00, 01:15, ... etc,
default = 15

To ensure the necessary javascript is included you must then call :-

PHP:

$jQ
->header();

Note: You must do _all_ the above before including "header.php" in your code.

To add a date / time picker to your form :-

PHP:

echo $jQ->date_field($fieldname, $value);

$fieldname = the name of the form field
$value = an initial value for this field

example :-

PHP:

echo '
<form name="MyForm" action="'
.getlink().'">
Date : '
.$jQ->date_field('MyDate',$datetime).'
<input type="submit" value="Submit" />
</form>
'
;

To retrieve the date entered by the user :-

PHP:

$var
= $jQ->date_input($fieldname);

$fieldname = the name used to create the field above

example :-

PHP:

$datetime
= $jQ->date_input('MyDate');

There are some additional functions provided :-

PHP:

echo $jQ->date_current();

returns the current GMT date / time

PHP:

echo $jQ->date_toLocal($gmtdatetime);

converts a GMT date/time to the user's local timezone

PHP:

echo $jQ->date_toGMT($localdatetime);

converts a date in the user's local timezone to GMT

PHP:

echo $jQ->date_display($datetime, $format);

displays a GMT date / time to the user in their local timezone, and formats it according to $format if suppplied (or the date format specified in their website account if not)




Tabs

In your module declare an instance of the class :-

PHP:

$jQ
= new jquery();

Then initialise the tabs functions :-

PHP:

$jQ
->tabs($tabname, $selected);

$tabname = the id of the "div" to contain the tabs
$selected = the number of the tab to start with (from zero)

example :-

PHP:

$jQ
->tabs('MyTabs', 1);

To ensure the necessary javascript is included you must then call :-

PHP:

$jQ
->header();

Note: You must do _all_ the above before including "header.php" in your code.

To add a tab :-

PHP:

$jQ
->tabs_addTab($id, $label, $url);

$id = the id of the tab (anything that would go in an id="" attribute)
$label = the text to appear in the tab
$url = the page from which to get the content of the tab

example :-

PHP:

$jQ
->tabs_addTab( 'tab1', 'Tab 1', getlink('&file=tab1') );
$jQ->tabs_addTab( 'tab2', 'Tab 2', getlink('&file=tab2') );
$jQ->tabs_addTab( 'tab3', 'Tab 3', getlink('&file=tab3') );

To display the tabs once they've all been specified :-

PHP:

echo $jQ->tabs_showTabs();

This will output the following HTML :-

Code::
<div id="MyTabs">
  <ul>
    <li><a href="index.php?name=MyModule&file=tab1" title="Tab 1"><span>Tab 1</span></a></li>
    <li><a href="index.php?name=MyModule&file=tab2" title="Tab 2"><span>Tab 2</span></a></li>
    <li><a href="index.php?name=MyModule&file=tab3" title="Tab 3"><span>Tab 3</span></a></li>
  </ul>
</div>




Tooltips

In your module declare an instance of the class :-

PHP:

$jQ
= new jquery();

Then initialise the tooltip functions :-

PHP:

$jQ
->tips($width);

$width = the width, in pixels, of the tooltip

example :-

PHP:

$jQ
->tips(500);

To ensure the necessary javascript is included you must then call :-

PHP:

$jQ
->header();

Note: You must do _all_ the above before including "header.php" in your code.

To add a tooltip :-

PHP:

echo $jQ->tips_showTip($title, $url, $label);

$title = text to appear in the title bar of the tooltip
$url = the page from which to get the content of the tooltip
$label = if supplied this will be the link that hovering over causes the tooltip to be displayed. if this is not supplied a small magnifying glass icon is used.

example :-

PHP:

echo $jQ->tips_showTip( 'My Tooltip', getlink('&file=tip1') );

_________________
Gaming League / Cup - www.leaguecms.co.uk :: Other DragonFly modules - www.cmsdreams.co.uk

Kendle's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Back to top
View user's profile Visit poster's website
Eestlane
I18N / L10N Lead Dev
I18N / L10N Lead Dev

Offline Offline
Joined: Apr 06, 2005
Posts: 1404
Location: Estonia
PostPosted: Mon Jun 28, 2010 8:46 pm
Post subject: Re: Some jQuery functionality for DF modules

Seems cool, thanks for sharing!


Eestlane's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.0.63/5.0.67/5.2.8/9.2.1
Back to top
View user's profile Send e-mail Visit poster's website
earth
Heavy poster
Heavy poster

Offline Offline
Joined: Mar 01, 2006
Posts: 268

PostPosted: Mon Jun 28, 2010 9:24 pm
Post subject: Re: Some jQuery functionality for DF modules

Kendle thanks, this is one of those DF things, that will help keep us all around, and attract more and I look forward to attempting some implementing this!

ty

_________________
dfaddons.com

earth's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
OS/Apache/Mysql/php/9.2.X/
Back to top
View user's profile Visit poster's website Photo Gallery
NanoCaiordo
Developer
Developer

Offline Offline
Joined: Jun 29, 2004
Posts: 3878
Location: Melbourne, AU
PostPosted: Tue Jun 29, 2010 1:00 am
Post subject: Re: Some jQuery functionality for DF modules

Just to point out that our framework already support ajax tabs, you can also use the same tabs without ajax (just add an anchor to activate ajax).
DragonflyCMS 10 already start using it in some admin pages.
Fully customizable from css.

_________________
.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Linux 64bit / Apache 2.2 / PHP 5.4 / MySQL 5.5.22 / v9, v10
Linux 32bit / Apache 2.2 / PHP 5.3.10 / MySQL 5.5.22 / v9, v10
Windows 64bit / IIS 7.5 / PHP 5.3.10 / MySQL 5.5.22 / v9, v10


NanoCaiordo's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
mixed
Back to top
View user's profile Visit poster's website Photo Gallery
earth
Heavy poster
Heavy poster

Offline Offline
Joined: Mar 01, 2006
Posts: 268

PostPosted: Tue Jun 29, 2010 1:26 pm
Post subject: Re: Some jQuery functionality for DF modules

How would or do we do, an ajax login box that can put in the nav bar?

I looked at some of the widgets and stuff yesterday and tried to do a simple one, however figured, someone who is up on this, could just post up an example of how to do this feature, if it is not that hard to do and one could show us all here, or in another thread, how to do it!

_________________
dfaddons.com

earth's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
OS/Apache/Mysql/php/9.2.X/
Back to top
View user's profile Visit poster's website Photo Gallery
Kendle
500+ Posts Club
500+ Posts Club

Offline Offline
Joined: Dec 16, 2004
Posts: 552

PostPosted: Tue Jun 29, 2010 1:44 pm
Post subject: Re: Some jQuery functionality for DF modules

Strictly speaking you don't need an "AJAX" login box with DF. Any form on any page that "POSTS" "ulogin" and "user_password" will cause the values entered to be authenticated and the page they were on reloaded.

If you mean a modal stype pop-up dialog, then that's easy with jQuery and I could add it to this class, I just haven't because I don't need it myself at the moment.

_________________
Gaming League / Cup - www.leaguecms.co.uk :: Other DragonFly modules - www.cmsdreams.co.uk

Kendle's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Back to top
View user's profile Visit poster's website
earth
Heavy poster
Heavy poster

Offline Offline
Joined: Mar 01, 2006
Posts: 268

PostPosted: Tue Jun 29, 2010 4:19 pm
Post subject: Re: Some jQuery functionality for DF modules

Kendle wrote:
Strictly speaking you don't need an "AJAX" login box with DF. Any form on any page that "POSTS" "ulogin" and "user_password" will cause the values entered to be authenticated and the page they were on reloaded.

If you mean a modal stype pop-up dialog, then that's easy with jQuery and I could add it to this class, I just haven't because I don't need it myself at the moment.
thanks, and yes a pop up that would when you hover over the link, appear, to login or out, accordingly and the link to the pop up, would change to logout once logged in and then to logout would be rollover popup and select the logout option, same as a the block, just does not show, until needed and always static location.

Know you like redesign theme and how it shows the login in the header, as that is a little much for guest and visitors, to see all the time imho, unless of course they need to create an account and login for some reasons, and a hover over jquery ajax pop up be nice, as I think phpbb and vB both have something like this, more or less.

Is there a way to set the delay time to not be so laggy, as in the example on the match signup, there was maybe a 1 sec delay, and be nice if it was a tad faster and the loading image rotating, smaller and the window open without any delays, so could hover over things fast and see tool tips or content without any waiting....

Private messages be another one we can work on later, as in a new pop up on new pm, that is ajax jquery and when you hover over the links can do a little more.

In the module would be, on index page of pms, you could pull the contents of each pm up, so you do not have to click on each one to see what is in it, as it gets confusing we all know, when they are all titled re: whatever and not sure what pm has the details that are desired, so a hover over the pm with the body showing up, be one we all love, to have, and please if you do not, let us know!@!@

_________________
dfaddons.com

earth's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
OS/Apache/Mysql/php/9.2.X/
Back to top
View user's profile Visit poster's website Photo Gallery
Kendle
500+ Posts Club
500+ Posts Club

Offline Offline
Joined: Dec 16, 2004
Posts: 552

PostPosted: Tue Jun 29, 2010 6:13 pm
Post subject: Re: Some jQuery functionality for DF modules

OK, what I should've said was, I could add a modal style login box, but I'm not because I don't need one. I'm sharing this simply because I made it and figured someone else might have a use for it, I wasn't looking for things to do. Smile

earth wrote:

Is there a way to set the delay time to not be so laggy, as in the example on the match signup, there was maybe a 1 sec delay, and be nice if it was a tad faster and the loading image rotating, smaller and the window open without any delays, so could hover over things fast and see tool tips or content without any waiting....

The waiting time is due to the fact it's AJAX, a new page is called and database queries executed. The content arrives only as fast as the server can deliver it (so "no" in other words).

earth wrote:

Private messages be another one we can work on later...

No chance I'm going to play with core DF functionality, so that's a non-starter (though of course if AJAX was suported in the DF core this is just the sort of thing I'd expect it to be used for).

_________________
Gaming League / Cup - www.leaguecms.co.uk :: Other DragonFly modules - www.cmsdreams.co.uk

Kendle's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Back to top
View user's profile Visit poster's website
earth
Heavy poster
Heavy poster

Offline Offline
Joined: Mar 01, 2006
Posts: 268

PostPosted: Tue Jun 29, 2010 10:22 pm
Post subject: Re: Some jQuery functionality for DF modules

totally understand Kendle, will be brushing up on it a little and see what we can do on this end, thanks again, for everything!

_________________
dfaddons.com

earth's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
OS/Apache/Mysql/php/9.2.X/
Back to top
View user's profile Visit poster's website Photo Gallery
earth
Heavy poster
Heavy poster

Offline Offline
Joined: Mar 01, 2006
Posts: 268

PostPosted: Sun Jul 04, 2010 12:15 pm
Post subject: Re: Some jQuery functionality for DF modules

Have been trying to get it to work with phoenix account plus module and it is using jquery as well, it seems and like to have both these combined and functioning together, if possible.

Have added your lines to the modules/pm/index.php and themes/default/pm/index_body.html *thanks for the clear defined changes)

Thought for sure could do this one, without bothering you again, as it is maybe conflicting with account+ and getting this error

Code::
$("a.cluetip").cluetip is not a function
[Break on this error] $('a.cluetip').cluetip({width:640}); 
line 26




I will post the two files modified for your viewing, as I did not seem to think any other files needed to be modified, however could be wrong.

_________________
dfaddons.com

earth's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
OS/Apache/Mysql/php/9.2.X/
Back to top
View user's profile Visit poster's website Photo Gallery
earth
Heavy poster
Heavy poster

Offline Offline
Joined: Mar 01, 2006
Posts: 268

PostPosted: Sun Jul 04, 2010 12:15 pm
Post subject: Re: Some jQuery functionality for DF modules

index.php
PHP:
<?php
/*********************************************
CPG Dragonfly™ CMS
********************************************
Copyright © 2004 - 2009 by CPG-Nuke Dev Team
dragonflycms.org

Dragonfly is released under the terms and conditions
of the GNU GPL version 2 or any later version
Original copyright : (C) 2001 The phpBB Group

$Source: /cvs/html/modules/Private_Messages/index.php,v $
$Revision: 9.26 $
$Author: nanocaiordo $
$Date: 2007/12/12 12:54:27 $
**********************************************/
if (!defined('CPG_NUKE')) { exit; }
/*CMSD*/ require_once(CORE_PATH.'classes/jquery.php');
/*CMSD*/ $jQ = new jquery();
/*CMSD*/ $jQ->tips(640);
/*CMSD*/ $jQ->header();
require_once(
'modules/'.$module_name.'/init.inc');
get_lang('Your_Account');
$pagetitle .= _Private_MessagesLANG;
if (
file_exists('themes/'.$CPG_SESS['theme'].'/style/account.css')) {
$modheader .= '<link rel="stylesheet" href="themes/'.$CPG_SESS['theme'].'/style/account.css" media="all" />';
} else {
$modheader .= '<link rel="stylesheet" href="themes/default/style/account.css" media="all" />';
}
$modheader .= '<script src="includes/javascript/jquery.js" type="text/javascript"></script>';
$modheader .= '<script src="includes/javascript/jquery.corner.js" type="text/javascript"></script>';
$modheader .= '
<script type="text/javascript">
$(document).ready(function() {
$("div.logi").corner("15px");
});
</script>
'
;
global
$SESS;
if (isset(
$_GET['folder'])){
switch($_GET['folder']){
case 'inbox':
$pagetitle .= ' '._BC_DELIM.' '._TB_PRIVMSGS_INBOX;
break;
case 'sentbox':
$pagetitle .= ' '._BC_DELIM.' '._TB_PRIVMSGS_SENTBOX;
break;
case 'outbox':
$pagetitle .= ' '._BC_DELIM.' '._TB_PRIVMSGS_OUTBOX;
break;
case 'savebox':
$pagetitle .= ' '._BC_DELIM.' '._TB_PRIVMSGS_SAVEBOX;
break;
default:
}
}

# Start main
if ( $mode == 'newpm' ) {
# PM popup
$gen_simple_header = TRUE;
$page_title .= _PRIVMSGING;
require_once('includes/phpBB/page_header.php');
if (is_user()) {
if ($userdata['user_new_privmsg']) {
$l_new_message = ( $userdata['user_new_privmsg'] == 1 ) ? _YOUNEWPM : _YOUNEWPMS;
} else {
$l_new_message = _YOUNONEWPM;
}
$l_new_message .= '<br /><br />'.sprintf(_CLICKVIEWPM, '<a href="'.getlink('Private_Messages&amp;folder=inbox').'" onclick="jump_to_inbox();return false;" target="_blank">', '</a>');
} else {
$l_new_message = _LOGINCHECKPM;
}
$template->assign_vars(array(
'L_CLOSE_WINDOW' => _CLOSEWINDOW,
'L_MESSAGE' => $l_new_message)
);
$template->set_filenames(array('body' => 'private_msgs/popup.html'));
require_once('includes/phpBB/page_tail.php');
} else if (
$mode == 'read' ) {
require_once('modules/'.$module_name.'/read.php');
} else if ( (
$delete && $mark_list ) || $delete_all ) {
require_once('modules/'.$module_name.'/delete.php');
} else if (
$save && $mark_list && $folder != 'savebox' && $folder != 'outbox' ) {
if (sizeof($mark_list)) {
require_once('modules/'.$module_name.'/save.php');
}
} else if (
$submit || $refresh || $mode != '') {
if (!$board_config['allow_html']) {
$html_on = 0;
} else {
$html_on = intval(($submit || $refresh) ? empty($_POST['disable_html']) : $userdata['user_allowhtml']);
}
if (!$board_config['allow_bbcode']) {
$bbcode_on = 0;
} else {
$bbcode_on = intval(($submit || $refresh) ? empty($_POST['disable_bbcode']) : $userdata['user_allowbbcode']);
}
if (!$board_config['allow_smilies']) {
$smilies_on = 0;
} else {
$smilies_on = intval(($submit || $refresh) ? empty($_POST['disable_smilies']) : $userdata['user_allowsmile']);
}
$attach_sig = ($submit || $refresh) ? intval(!empty($_POST['attach_sig'])) : $userdata['user_attachsig'];
$user_sig = ($userdata['user_sig'] != '' && $board_config['allow_sig']) ? $userdata['user_sig'] : '';

if ( $submit && $mode != 'edit' ) {
# Flood control
list($last_post_time) = $db->sql_ufetchrow("SELECT MAX(privmsgs_date) FROM ".$prefix."_bbprivmsgs
WHERE privmsgs_from_userid="
.$userdata['user_id'], SQL_NUM);
if ((gmtime() - $last_post_time) < $board_config['flood_interval']) {
message_die(GENERAL_MESSAGE, _FLOODERROR);
}
}

if ($submit) {
if ( !empty($_POST['username']) ) {
$to_username = $_POST['username'];
$sql = "SELECT user_id, user_notify_pm, user_email, user_lang, user_active FROM ".$user_prefix."_users
WHERE username = '"
.Fix_Quotes($to_username)."' AND user_id > 1";
$result = $db->sql_query($sql);
if ($db->sql_numrows($result)<1) {
$error = TRUE;
$error_msg = _NOSUCHUSER;
}
$to_userdata = $db->sql_fetchrow($result);
} else {
$error = TRUE;
$error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' )._NOTOUSER;
}
$privmsg_subject = trim(strip_tags($_POST['subject']));
if ( empty($privmsg_subject) ) {
$error = TRUE;
$error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' )._EMPTYSUBJECT;
}
if ( !empty($_POST['message']) ) {
if ( !$error ) {
$privmsg_message = message_prepare(((isset($_POST['quick_quote']) && !empty($_POST['quick_quote'])) ? $_POST['quick_quote'] : '').$_POST['message'], $html_on, $bbcode_on);
}
} else {
$error = TRUE;
$error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' )._EMPTYMESSAGE;
}
}

if ($submit && !$error)
{
# Has admin prevented user from sending PM's?
if (!$userdata['user_allow_pm']) {
$message = _CANNOTSENDPM;
message_die(GENERAL_MESSAGE, $message);
}
$msg_time = gmtime();
if ($mode != 'edit') {
# See if recipient is at their inbox limit
$sql = "SELECT COUNT(privmsgs_id) AS inbox_items, MIN(privmsgs_date) AS oldest_post_time
FROM "
.$prefix."_bbprivmsgs
WHERE ( privmsgs_type = "
.PRIVMSGS_NEW_MAIL."
OR privmsgs_type = "
.PRIVMSGS_READ_MAIL."
OR privmsgs_type = "
.PRIVMSGS_UNREAD_MAIL." )
AND privmsgs_to_userid = "
.$to_userdata['user_id'];
$result = $db->sql_query($sql);
$sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : '';
if ( $inbox_info = $db->sql_fetchrow($result) ) {
if ( $inbox_info['inbox_items'] >= $board_config['max_inbox_privmsgs'] ) {
$sql = "SELECT privmsgs_id FROM ".$prefix."_bbprivmsgs
WHERE ( privmsgs_type = "
.PRIVMSGS_NEW_MAIL."
OR privmsgs_type = "
.PRIVMSGS_READ_MAIL."
OR privmsgs_type = "
.PRIVMSGS_UNREAD_MAIL." )
AND privmsgs_date = "
.$inbox_info['oldest_post_time']."
AND privmsgs_to_userid = "
.$to_userdata['user_id'];
$result = $db->sql_query($sql);
$old_privmsgs_id = $db->sql_fetchrow($result);
$old_privmsgs_id = $old_privmsgs_id['privmsgs_id'];
$db->sql_query("DELETE $sql_priority FROM ".$prefix."_bbprivmsgs
WHERE privmsgs_id = $old_privmsgs_id"
);
$db->sql_query("DELETE $sql_priority FROM ".$prefix."_bbprivmsgs_text
WHERE privmsgs_text_id = $old_privmsgs_id"
);
}
}

$db->sql_query("INSERT INTO ".$prefix."_bbprivmsgs
(privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip, privmsgs_enable_html, privmsgs_enable_bbcode, privmsgs_enable_smilies, privmsgs_attach_sig)
VALUES
("
.PRIVMSGS_NEW_MAIL.", '".Fix_Quotes($privmsg_subject)."', ".$userdata['user_id'].", ".$to_userdata['user_id'].", $msg_time, ".$userinfo['user_ip'].", $html_on, $bbcode_on, $smilies_on, $attach_sig)");
$privmsg_sent_id = $db->sql_nextid('privmsgs_id');
$db->sql_query("INSERT INTO ".$prefix."_bbprivmsgs_text
(privmsgs_text_id, privmsgs_text)
VALUES
($privmsg_sent_id, '"
.Fix_Quotes($privmsg_message)."')");
} else {
$db->sql_query("UPDATE ".$prefix."_bbprivmsgs
SET privmsgs_type = "
.PRIVMSGS_NEW_MAIL.", privmsgs_subject = '".Fix_Quotes($privmsg_subject)."', privmsgs_from_userid = ".$userdata['user_id'].", privmsgs_to_userid = ".$to_userdata['user_id'].", privmsgs_date = $msg_time, privmsgs_ip = '".$userinfo['user_ip']."', privmsgs_enable_html = $html_on, privmsgs_enable_bbcode = $bbcode_on, privmsgs_enable_smilies = $smilies_on, privmsgs_attach_sig = $attach_sig
WHERE privmsgs_id = $privmsg_id"
);
$db->sql_query("UPDATE ".$prefix."_bbprivmsgs_text
SET privmsgs_text = '"
.Fix_Quotes($privmsg_message)."'
WHERE privmsgs_text_id = $privmsg_id"
);
}

if ( $mode != 'edit' )
{
# Add to the users new pm counter
$sql = "UPDATE ".$user_prefix."_users
SET user_new_privmsg = user_new_privmsg + 1, user_last_privmsg = "
.gmtime()."
WHERE user_id = "
.$to_userdata['user_id'];
$status = $db->sql_query($sql);
unset($_SESSION['CPG_USER']);

if ( $to_userdata['user_notify_pm'] && !empty($to_userdata['user_email']) && $to_userdata['user_active'] )
{
require_once('includes/phpBB/emailer.php');
$emailer = new emailer();

$emailer->from($board_config['board_email']);
$emailer->replyto($board_config['board_email']);

$emailer->use_template('privmsg_notify', $to_userdata['user_lang']);
$emailer->email_address($to_userdata['user_email']);
$emailer->set_subject(_NEWPMARRIVED);

$emailer->assign_vars(array(
'USERNAME' => $to_username,
'SITENAME' => $board_config['sitename'],
'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n".$board_config['board_email_sig']) : '',
'U_INBOX' => getlink('&amp;folder=inbox', true, true)
)
);

$emailer->send();
$emailer->reset();
}
}
url_refresh(getlink('&folder=inbox'));
$msg = _MESSAGESENT.'<br /><br />'.sprintf(_CLICKRETURNINBOX, '<a href="'.getlink('&amp;folder=inbox').'">', '</a> ').'<br /><br />'.sprintf(_CLICKRETURNINDEX, '<a href="'.$mainindex.'">', '</a>');
message_die(GENERAL_MESSAGE, $msg);
}
else if ($preview || $refresh || $error)
{
# If we're previewing or refreshing then obtain the data passed to
# the script, process it a little, do some checks where neccessary, etc.
$to_username = ( isset($_POST['username']) ) ? trim(strip_tags($_POST['username'])) : '';
$privmsg_subject = ( isset($_POST['subject']) ) ? trim(strip_tags($_POST['subject'])) : '';
$privmsg_message = ( isset($_POST['message']) ) ? trim($_POST['message']) : '';
$privmsg_message = preg_replace('#<textarea>#si', '&lt;textarea&gt;', $privmsg_message);

# Do mode specific things
if ($mode == 'post') {
$page_title = _POSTNEWPM;
$user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : '';
}
else if ($mode == 'reply') {
$page_title = _POSTREPLYPM;
$user_sig = ( $userdata['user_sig'] != '' && $board_config['allow_sig'] ) ? $userdata['user_sig'] : '';
}
else if ($mode == 'edit') {
$page_title = _EDITPM;
$sql = "SELECT u.user_id, u.user_sig
FROM "
.$prefix."_bbprivmsgs pm, ".$user_prefix."_users u
WHERE pm.privmsgs_id = $privmsg_id
AND u.user_id = pm.privmsgs_from_userid"
;
$result = $db->sql_query($sql);
if ($postrow = $db->sql_fetchrow($result) ) {
if ( $userdata['user_id'] != $postrow['user_id'] ) {
message_die(GENERAL_MESSAGE, _EDITOWNPOSTS);
}
$user_sig = ( $postrow['user_sig'] != '' && $board_config['allow_sig'] ) ? $postrow['user_sig'] : '';
}
}
}
else
{
if ( !$privmsg_id && ( $mode == 'reply' || $mode == 'edit' || $mode == 'quote' ) ) {
message_die(GENERAL_ERROR, _NOPOSTID);
}

if ( !empty($_GET[POST_USERS_URL]) )
{
$user_id = intval($_GET[POST_USERS_URL]);
$result = $db->sql_query("SELECT username FROM ".$user_prefix."_users
WHERE user_id = $user_id AND user_id > 1"
);
if ( $row = $db->sql_fetchrow($result) ) {
$to_username = $row['username'];
} else {
$error = TRUE;
$error_msg = _NPSUCHUSER;
}
}

if ( $mode == 'edit' )
{
$result = $db->sql_query("SELECT pm.*, pmt.privmsgs_text, u.username, u.user_id, u.user_sig
FROM "
.$prefix."_bbprivmsgs pm, ".$prefix."_bbprivmsgs_text pmt, ".$user_prefix."_users u
WHERE pm.privmsgs_id = $privmsg_id
AND pmt.privmsgs_text_id = pm.privmsgs_id
AND pm.privmsgs_from_userid = "
.$userdata['user_id']."
AND ( pm.privmsgs_type = "
.PRIVMSGS_NEW_MAIL."
OR pm.privmsgs_type = "
.PRIVMSGS_UNREAD_MAIL." )
AND u.user_id = pm.privmsgs_to_userid"
);
if (!($privmsg = $db->sql_fetchrow($result))) {
url_redirect(getlink('&amp;folder='.$folder, true));
}
$privmsg_subject = $privmsg['privmsgs_subject'];
$privmsg_message = $privmsg['privmsgs_text'];
$privmsg_message = str_replace('<br />', "\n", $privmsg_message);
$privmsg_message = preg_replace('#</textarea>#si', '&lt;/textarea&gt;', $privmsg_message);
$user_sig = ( $board_config['allow_sig'] ) ? (($privmsg['privmsgs_type'] == PRIVMSGS_NEW_MAIL) ? $user_sig : $privmsg['user_sig']) : '';
$to_username = $privmsg['username'];
$to_userid = $privmsg['user_id'];
}
else if ( $mode == 'reply' || $mode == 'quote' )
{
$result = $db->sql_query("SELECT pm.privmsgs_subject, pm.privmsgs_date, pmt.privmsgs_text, u.username, u.user_id
FROM "
.$prefix."_bbprivmsgs pm, ".$prefix."_bbprivmsgs_text pmt, ".$user_prefix."_users u
WHERE pm.privmsgs_id = $privmsg_id
AND pmt.privmsgs_text_id = pm.privmsgs_id
AND pm.privmsgs_to_userid = "
.$userdata['user_id']."
AND u.user_id = pm.privmsgs_from_userid"
);

if (!($privmsg = $db->sql_fetchrow($result))) {
url_redirect(getlink('&amp;folder='.$folder, true));
}

$privmsg_subject = ( ( !preg_match('/^Re:/', $privmsg['privmsgs_subject']) ) ? 'Re: ' : '' ).$privmsg['privmsgs_subject'];

$to_username = $privmsg['username'];
$to_userid = $privmsg['user_id'];

if ( $mode == 'quote' )
{
$privmsg_message = $privmsg['privmsgs_text'];
$privmsg_message = str_replace('<br />', "\n", $privmsg_message);
$privmsg_message = preg_replace('#</textarea>#si', '&lt;/textarea&gt;', $privmsg_message);
$msg_date = create_date($board_config['default_dateformat'], $privmsg['privmsgs_date']);
$privmsg_message = '[quote="'.$to_username.'"]'.$privmsg_message.'[/quote]';
$mode = 'reply';
}
}
}

# Has admin prevented user from sending PM's?
if ( !$userdata['user_allow_pm'] && $mode != 'edit' ) {
$message = _CANNOTSENDPM;
message_die(GENERAL_MESSAGE, $message);
}

# Start output, first preview, then errors then post form
if ( $mode == 'post' ) {
$pagetitle .= ' '._BC_DELIM.' '._SENDNEWPM;
} else if ( $mode == 'reply' ) {
$pagetitle .= ' '._BC_DELIM.' '._REPLYTOPM;
} else if ( $mode == 'edit' ) {
$pagetitle .= ' '._BC_DELIM.' '._EDITMESSAGE;
}
define('HEADER_INC', TRUE);
require_once('header.php');
OpenTable();

if ($preview && !$error) {
$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);

$preview_message = message_prepare($privmsg_message, $html_on, $bbcode_on);
$privmsg_message = preg_replace($html_entities_match, $html_entities_replace, $privmsg_message);

# Finalise processing as per viewtopic
if (!$html_on || !$board_config['allow_html'] || !$userdata['user_allowhtml']) {
if ($user_sig != '') {
$user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $user_sig);
}
}

if ($attach_sig && $user_sig != '') {
require_once('includes/nbbcode.php');
$user_sig = decode_bbcode($user_sig, 1, false);
}

if ($bbcode_on) {
$preview_message = decode_bbcode($preview_message, 1);
}

if ( $attach_sig && $user_sig != '' ) {
$preview_message = $preview_message.'<br /><br />_________________<br />'.$user_sig;
}
if ( count($orig_word) ) {
$preview_subject = preg_replace($orig_word, $replacement_word, $privmsg_subject);
$preview_message = preg_replace($orig_word, $replacement_word, $preview_message);
} else {
$preview_subject = $privmsg_subject;
}

if ( $smilies_on ) {
$preview_message = set_smilies($preview_message);
}

$preview_message = make_clickable($preview_message);

$s_hidden_fields = '<input type="hidden" name="folder" value="'.$folder.'" />';
$s_hidden_fields .= '<input type="hidden" name="mode" value="'.$mode.'" />';

if ( isset($privmsg_id) ) {
$s_hidden_fields .= '<input type="hidden" name="p" value="'.$privmsg_id.'" />';
}

$template->assign_vars(array(
'TOPIC_TITLE' => $preview_subject,
'POST_SUBJECT' => $preview_subject,
'MESSAGE_TO' => $to_username,
'MESSAGE_FROM' => $userdata['username'],
'POST_DATE' => create_date($board_config['default_dateformat'], gmtime()),
'PREVIEW_MESSAGE' => $preview_message,
'MESSAGE' => $preview_message, // for old template system
'S_HIDDEN_FIELDS' => $s_hidden_fields,
'L_SUBJECT' => _SUBJECT,
'L_DATE' => _DATE,
'L_FROM' => _FROM,
'L_TO' => _TO,
'L_PREVIEW' => _PREVIEW,
'L_POSTED' => _POSTEDPM)
);
}

# Start error handling
if ($error) {
$template->assign_vars(array('ERROR_MESSAGE' => $error_msg));
} else {
$template->assign_vars(array('ERROR_MESSAGE' => ''));
}

# Enable extensions in posting_body
$template->assign_block_vars('switch_privmsg', array());

# HTML toggle selection
if ( $board_config['allow_html'] ) {
$html_status = _HTMLON;
$template->assign_block_vars('switch_html_checkbox', array());
} else {
$html_status = _HTMLOFF;
}

# BBCode toggle selection
if ( $board_config['allow_bbcode'] ) {
$bbcode_status = _BBCODEON;
$template->assign_block_vars('switch_bbcode_checkbox', array());
} else {
$bbcode_status = _BBCODEOFF;
}

# Smilies toggle selection
if ( $board_config['allow_smilies'] ) {
$smilies_status = _SMILIESON;
$template->assign_block_vars('switch_smilies_checkbox', array());
} else {
$smilies_status = _SMILIESOFF;
}

# Signature toggle selection - only show if the user has a signature
if ( $user_sig != '' ) {
$template->assign_block_vars('switch_signature_checkbox', array());
}

if ( $mode == 'reply' ) { $mode = 'post'; }

$s_hidden_fields = '<input type="hidden" name="folder" value="'.$folder.'" />';
$s_hidden_fields .= '<input type="hidden" name="mode" value="'.$mode.'" />';
if ( $mode == 'edit' ) {
$s_hidden_fields .= '<input type="hidden" name="p" value="'.$privmsg_id.'" />';
}

# Send smilies to template
generate_smilies('inline', '-10');

$privmsg_subject = preg_replace($html_entities_match, $html_entities_replace, (isset($privmsg_subject)?$privmsg_subject:''));
$privmsg_subject = str_replace('"', '&quot;', $privmsg_subject);

$template->assign_vars(array(
'S_MENU' => member_menu(),
'S_PREVIEW_BOX' => ($preview && !$error),
'SUBJECT' => $privmsg_subject,
'USERNAME' => preg_replace($html_entities_match, $html_entities_replace, (isset($to_username)?$to_username:'')),
'MESSAGE' => isset($privmsg_message)?$privmsg_message:'',
'HTML_STATUS' => $html_status,
'SMILIES_STATUS' => $smilies_status,
'BBCODE_STATUS' => sprintf($bbcode_status, '<a href="'.getlink('Forums&amp;file=faq&amp;mode=bbcode').'" target="_phpbbcode">', '</a>'),
'FORUM_NAME' => _PM,
'BBCODE_TABLE' => bbcode_table('message', 'post', 1),
'SMILES_TABLE' => smilies_table('inline', 'message', 'post'),
'L_EMOTICONS' => _EMOTICONS,
# 'BOX_NAME' => $l_box_name,

'L_USERNAME' => _TOUSER,
'L_GO' => _GO,
'L_SUBJECT' => _SUBJECT,
'L_MESSAGE_BODY' => _MESSAGEBODY,
'L_OPTIONS' => _OPTIONSPM,
'L_SPELLCHECK' => _SPELLCHECK,
'L_PREVIEW' => _PREVIEW,
'L_SUBMIT' => _SUBMIT,
'L_CANCEL' => _CANCEL,
'L_POST_A' => $pagetitle,
'L_FIND_USERNAME' => _FINDAUSERNAME,
'L_FIND' => _FIND,
'L_DISABLE_HTML' => _DISABLEHTML,
'L_DISABLE_BBCODE' => _DISABLEBBCODE,
'L_DISABLE_SMILIES' => _DISABLESMILIES,
'L_ATTACH_SIGNATURE' => _ATTACHSIG,
'L_EMPTY_MESSAGE' => _EMPTYMESSAGE,

'S_HTML_CHECKED' => ( !$html_on ) ? ' checked="checked"' : '',
'S_BBCODE_CHECKED' => ( !$bbcode_on ) ? ' checked="checked"' : '',
'S_SMILIES_CHECKED' => ( !$smilies_on ) ? ' checked="checked"' : '',
'S_SIGNATURE_CHECKED' => ( $attach_sig ) ? ' checked="checked"' : '',
'S_HIDDEN_FORM_FIELDS' => $s_hidden_fields,
'S_POST_ACTION' => getlink(),
'S_FORM_ENCTYPE' => ' enctype="multipart/form-data" accept-charset="utf-8"',
'U_SEARCH_USER' => getlink('Forums&amp;file=search&amp;mode=searchuser&amp;popup=1', true, true),
'U_VIEW_FORUM' => getlink()
));

$template->set_filenames(array('body' => 'private_msgs/posting_body.html'));
$template->display('body');

CloseTable();
return;
}

# Update unread status
$db->sql_query("UPDATE ".$user_prefix."_users
SET user_unread_privmsg = user_unread_privmsg + user_new_privmsg, user_new_privmsg = 0, user_last_privmsg = "
.$CPG_SESS['session_start']."
WHERE user_id = "
.$userdata['user_id']);

$db->sql_query("UPDATE ".$prefix."_bbprivmsgs
SET privmsgs_type = "
.PRIVMSGS_UNREAD_MAIL."
WHERE privmsgs_type = "
.PRIVMSGS_NEW_MAIL."
AND privmsgs_to_userid = "
.$userdata['user_id']);

# Reset PM counters
$userdata['user_new_privmsg'] = 0;
$userdata['user_unread_privmsg'] = ( $userdata['user_new_privmsg'] + $userdata['user_unread_privmsg'] );
unset(
$_SESSION['CPG_USER']);

# Generate page
if ($mode == '') {
define('HEADER_INC', TRUE);
require_once('header.php');
OpenTable();
}

$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);

# New message
$post_new_mesg_url = '<a href="'.getlink('&amp;mode=post').'"><img src="'.$images['post_new'].'" alt="'._SENDNEWPM.'" /></a>';

# General SQL to obtain messages
$sql_tot = "SELECT COUNT(privmsgs_id) AS total FROM ".$prefix."_bbprivmsgs ";
$sql = "SELECT pm.privmsgs_type, pm.privmsgs_id, pm.privmsgs_date, pm.privmsgs_subject, u.user_id, u.username
FROM "
.$prefix."_bbprivmsgs pm, ".$user_prefix."_users u ";
switch (
$folder)
{
case 'inbox':
$sql_tot .= 'WHERE privmsgs_to_userid = '.$userdata['user_id'].'
AND ( privmsgs_type = '
.PRIVMSGS_NEW_MAIL.'
OR privmsgs_type = '
.PRIVMSGS_READ_MAIL.'
OR privmsgs_type = '
.PRIVMSGS_UNREAD_MAIL.' )';

$sql .= 'WHERE pm.privmsgs_to_userid = '.$userdata['user_id'].'
AND u.user_id = pm.privmsgs_from_userid
AND ( pm.privmsgs_type = '
.PRIVMSGS_NEW_MAIL.'
OR pm.privmsgs_type = '
.PRIVMSGS_READ_MAIL.'
OR privmsgs_type = '
.PRIVMSGS_UNREAD_MAIL.' )';
break;

case 'outbox':
$sql_tot .= 'WHERE privmsgs_from_userid = '.$userdata['user_id'].'
AND ( privmsgs_type = '
.PRIVMSGS_NEW_MAIL.'
OR privmsgs_type = '
.PRIVMSGS_UNREAD_MAIL.' )';

$sql .= 'WHERE pm.privmsgs_from_userid = '.$userdata['user_id'].'
AND u.user_id = pm.privmsgs_to_userid
AND ( pm.privmsgs_type = '
.PRIVMSGS_NEW_MAIL.'
OR privmsgs_type = '
.PRIVMSGS_UNREAD_MAIL.' )';
break;

case 'sentbox':
$sql_tot .= 'WHERE privmsgs_from_userid = '.$userdata['user_id'].'
AND privmsgs_type = '
.PRIVMSGS_SENT_MAIL;

$sql .= 'WHERE pm.privmsgs_from_userid = '.$userdata['user_id'].'
AND u.user_id = pm.privmsgs_to_userid
AND pm.privmsgs_type = '
.PRIVMSGS_SENT_MAIL;
break;

case 'savebox':
$sql_tot .= 'WHERE ( ( privmsgs_to_userid = '.$userdata['user_id'].'
AND privmsgs_type = '
.PRIVMSGS_SAVED_IN_MAIL.' )
OR ( privmsgs_from_userid = '
.$userdata['user_id'].'
AND privmsgs_type = '
.PRIVMSGS_SAVED_OUT_MAIL.') )';

$sql .= 'WHERE u.user_id = pm.privmsgs_from_userid
AND ( ( pm.privmsgs_to_userid = '
.$userdata['user_id'].'
AND pm.privmsgs_type = '
.PRIVMSGS_SAVED_IN_MAIL.' )
OR ( pm.privmsgs_from_userid = '
.$userdata['user_id'].'
AND pm.privmsgs_type = '
.PRIVMSGS_SAVED_OUT_MAIL.' ) )';
break;

default:
message_die(GENERAL_MESSAGE, _NOSUCHFOLDER);
break;
}

# Show messages over previous x days/months
$msg_days = 0;
if (
$submit_msgdays && (!empty($_POST['msgdays']) || !empty($_GET['msgdays']))) {
$msg_days = (!empty($_POST['msgdays'])) ? intval($_POST['msgdays']) : intval($_GET['msgdays']);
$min_msg_time = gmtime() - ($msg_days * 86400);

$limit_msg_time_total = " AND privmsgs_date > $min_msg_time";
$limit_msg_time = " AND pm.privmsgs_date > $min_msg_time ";

if (!empty($_POST['msgdays'])) {
$start = 0;
}
} else {
$limit_msg_time_total = $limit_msg_time = '';
$post_days = 0;
}

$sql .= $limit_msg_time." ORDER BY pm.privmsgs_date DESC
LIMIT $start, "
.$board_config['topics_per_page'];
$sql_all_tot = $sql_tot;
$sql_tot .= $limit_msg_time_total;

# Get messages
$result = $db->sql_query($sql_tot);
$pm_total = ($row = $db->sql_fetchrow($result)) ? $row['total'] : 0;

$result = $db->sql_query($sql_all_tot);
$pm_all_total = ($row = $db->sql_fetchrow($result)) ? $row['total'] : 0;

# Build select box
$previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
$previous_days_text = array(_ALLPOSTS, _1DAY, _7DAYS, _2WEEKS, _1MONTH, _3MONTHS, _6MONTHS, _1YEAR);

$select_msg_days = '';
for (
$i = 0; $i < count($previous_days); $i++) {
$selected = ( $msg_days == $previous_days[$i] ) ? ' selected="selected"' : '';
$select_msg_days .= '<option value="'.$previous_days[$i].'"'.$selected.'>'.$previous_days_text[$i].'</option>';
}

# Define correct icons
switch ($folder)
{
case 'inbox':
$l_box_name = _INBOX;
break;
case 'outbox':
$l_box_name = _TB_PRIVMSGS_OUTBOX;
break;
case 'savebox':
$l_box_name = _TB_PRIVMSGS_SAVEBOX;
break;
case 'sentbox':
$l_box_name = _TB_PRIVMSGS_SENTBOX;
break;
}
$post_pm = getlink('&amp;mode=post');
$post_pm_img = '<a href="'.$post_pm.'"><img src="'.$images['pm_postmsg'].'" alt="'._POSTNEWPM.'" /></a>';
$post_pm = '<a href="'.$post_pm.'">'._POSTNEWPM.'</a>';

# Output data for inbox status
$l_box_size_status = $inbox_limit_img_length = $inbox_limit_pct = '';
if (
$folder != 'outbox') {
$inbox_limit_pct = ( $board_config['max_'.$folder.'_privmsgs'] > 0 ) ? round(( $pm_all_total / $board_config['max_'.$folder.'_privmsgs'] ) * 100) : 100;
$inbox_limit_img_length = ( $board_config['max_'.$folder.'_privmsgs'] > 0 ) ? round(( $pm_all_total / $board_config['max_'.$folder.'_privmsgs'] ) * $board_config['privmsg_graphic_length']) : $board_config['privmsg_graphic_length'];
$inbox_limit_remain = ( $board_config['max_'.$folder.'_privmsgs'] > 0 ) ? $board_config['max_'.$folder.'_privmsgs'] - $pm_all_total : 0;
$template->assign_block_vars('switch_box_size_notice', array());
switch ($folder) {
case 'inbox':
$l_box_size_status = sprintf(_INBOXSIZE, $inbox_limit_pct);
break;
case 'sentbox':
$l_box_size_status = sprintf(_SENTBOXSIZE, $inbox_limit_pct);
break;
case 'savebox':
$l_box_size_status = sprintf(_SAVEBOXSIZE, $inbox_limit_pct);
break;
}
}

# Dump vars to template
$template->assign_vars(array(
'BOX_NAME' => $l_box_name,
'BOX_SIZE_STATUS' => $l_box_size_status,

'POST_PM_IMG' => $post_pm_img,
'POST_PM' => $post_pm,

'INBOX_LIMIT_IMG_WIDTH' => $inbox_limit_img_length,
'INBOX_LIMIT_PERCENT' => $inbox_limit_pct,

'T_TD_COLOR2' => $bgcolor4,

'L_GO' => _GO,
'L_INBOX' => _INBOX,
'L_OUTBOX' => _TB_PRIVMSGS_OUTBOX,
'L_SENTBOX' => _TB_PRIVMSGS_SENTBOX,
'L_SAVEBOX' => _SAVEDPM,
'L_MARK' => _MARKPM,
'L_FLAG' => _FLAGPM,
'L_SUBJECT' => _SUBJECT,
'L_DATE' => _DATE,
'L_DISPLAY_MESSAGES' => _DISPLAYPREVIOUSPM,
'L_FROM_OR_TO' => ( $folder == 'inbox' || $folder == 'savebox' ) ? _FROM : _TO,
'L_MARK_ALL' => _MARKALLPMS,
'L_UNMARK_ALL' => _UNMARKALLPMS,
'L_DELETE_MARKED' => _DELETEMARKED,
'L_DELETE_ALL' => _DELETEALL,
'L_SAVE_MARKED' => _SAVEMARKED,

'S_PRIVMSGS_ACTION' => getlink('&amp;folder='.$folder),
'S_HIDDEN_FIELDS' => '',
'S_POST_NEW_MSG' => $post_new_mesg_url,
'S_SELECT_MSG_DAYS' => $select_msg_days,
'S_MENU' => member_menu()
)
);

# Okay, let's build the correct folder
$result = $db->sql_query($sql);
if (
$row = $db->sql_fetchrow($result)) {
$i = 0;
do {
$privmsg_id = $row['privmsgs_id'];

$flag = $row['privmsgs_type'];

$icon_flag = ( $flag == PRIVMSGS_NEW_MAIL || $flag == PRIVMSGS_UNREAD_MAIL ) ? $images['pm_unreadmsg'] : $images['pm_readmsg'];
$icon_flag_alt = ( $flag == PRIVMSGS_NEW_MAIL || $flag == PRIVMSGS_UNREAD_MAIL ) ? _UNREADPM : _READPM;

$msg_userid = $row['user_id'];
$msg_username = $row['username'];
$msg_subject = $row['privmsgs_subject'];

$u_from_user_profile = getlink('Your_Account&amp;profile='.$msg_userid);

if (count($orig_word)) {
$msg_subject = preg_replace($orig_word, $replacement_word, $msg_subject);
}
$u_subject = getlink('&amp;folder='.$folder.'&amp;mode=read&amp;p='.$privmsg_id);
$msg_date = create_date($board_config['default_dateformat'], $row['privmsgs_date']);

if ($flag == PRIVMSGS_NEW_MAIL && $folder == 'inbox') {
$msg_subject = '<b>'.$msg_subject.'</b>';
$msg_date = '<b>'.$msg_date.'</b>';
$msg_username = '<b>'.$msg_username.'</b>';
}

$row_color = ( !($i % 2) ) ? $bgcolor2 : $bgcolor1;
$row_class = ( !($i % 2) ) ? 'row1' : 'row2';
$i++;

$template->assign_block_vars('listrow', array(
'ROW_COLOR' => $row_color,
'ROW_CLASS' => $row_class,
'FROM' => $msg_username,
'SUBJECT' => $msg_subject,
'DATE' => $msg_date,
'PRIVMSG_FOLDER_IMG' => $jQ->tips_showTip($icon_flag_alt, getlink('&file=message_popup&folder='.$folder.'&p='.$privmsg_id), '<img src="'.$icon_flag.'" alt="'.$icon_flag_alt.'" title="'.$icon_flag_alt.'" border="0" />'),
'L_PRIVMSG_FOLDER_ALT' => $icon_flag_alt,
'S_MARK_ID' => $privmsg_id,
'U_READ' => $u_subject,
'U_FROM_USER_PROFILE' => $u_from_user_profile)
);
}
while ($row = $db->sql_fetchrow($result));

$template->assign_vars(array(
'PAGINATION' => pm_pagination('Private_Messages&amp;folder='.$folder, $pm_total, $board_config['topics_per_page'], $start),
'PAGE_NUMBER' => sprintf(_PMPAGEOF, ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $pm_total / $board_config['topics_per_page'] )),
'L_GOTO_PAGE' => _GOTOPAGE)
);
} else {
$template->assign_vars(array(
'L_NO_MESSAGES' => _NOPMFOLDER,
'PAGINATION' => '',
'PAGE_NUMBER' => sprintf(_PMPAGEOF, 1, 1))
);
$template->assign_block_vars('switch_no_messages', array() );
}
if (
$mode == '') {
$template->set_filenames(array('body' => 'private_msgs/index_body.html'));
$template->display('body');
CloseTable();
}
index_body.html

PHP:

_________________
dfaddons.com

earth's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
OS/Apache/Mysql/php/9.2.X/
Back to top
View user's profile Visit poster's website Photo Gallery
earth
Heavy poster
Heavy poster

Offline Offline
Joined: Mar 01, 2006
Posts: 268

PostPosted: Sun Jul 04, 2010 12:17 pm
Post subject: Re: Some jQuery functionality for DF modules

index_body.html

Code::
<script type="text/javascript">
<!--
// Should really check the browser to stop this whining ...
function select_switch(status)
{
	for (i = 0; i < document.privmsg_list.length; i++)
	{
		document.privmsg_list.elements[i].checked = status;
	}
}
//-->
</script>

<table border="0" cellspacing="0" cellpadding="0" align="center" width="100%">
  <tr>
    <td valign="top" align="center" width="100%">
      <table style="height:40px;" cellspacing="2" cellpadding="2" border="0">
        <tr valign="middle">
          <td>{INBOX_IMG}</td>
          <td><span class="cattitle">{INBOX} &nbsp;</span></td>
          <td>{SENTBOX_IMG}</td>
          <td><span class="cattitle">{SENTBOX} &nbsp;</span></td>
          <td>{OUTBOX_IMG}</td>
          <td><span class="cattitle">{OUTBOX} &nbsp;</span></td>
          <td>{SAVEBOX_IMG}</td>
          <td><span class="cattitle">{SAVEBOX} &nbsp;</span></td>
        </tr>
      </table>
    </td>
    <td align="right">
      <!-- BEGIN switch_box_size_notice -->
      <table width="175" cellspacing="1" cellpadding="2" border="0" class="bodyline">
        <tr>
          <td colspan="3" class="row1" style="white-space:nowrap; width:100%;"><span class="gensmall">{BOX_SIZE_STATUS}</span></td>
        </tr>
        <tr>
          <td align="left" colspan="3" class="row2" style="width:100%;">
            <table cellspacing="0" cellpadding="1" border="0">
              <tr>
                <td style="background:{T_TD_COLOR2};"><img src="images/spacer.gif" width="{INBOX_LIMIT_IMG_WIDTH}" height="8" alt="{INBOX_LIMIT_PERCENT}" /></td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td style="width:33%;" class="row1"><span class="gensmall">0%</span></td>
          <td style="width:34%;" align="center" class="row1"><span class="gensmall">50%</span></td>
          <td style="width:33%;" align="right" class="row1"><span class="gensmall">100%</span></td>
        </tr>
      </table>
      <!-- END switch_box_size_notice -->
    </td>
  </tr>
</table>

<br clear="all" />

<form method="post" name="privmsg_list" action="{S_PRIVMSGS_ACTION}" {I18N}>
  <table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
    <tr>
      <td align="left" valign="middle">{POST_PM_IMG}</td>
      <td align="right" style="white-space:nowrap;"><span class="gensmall">{L_DISPLAY_MESSAGES}:
        <select name="msgdays">{S_SELECT_MSG_DAYS}
        </select>
        <input type="submit" value="{L_GO}" name="submit_msgdays" class="liteoption" />
        </span></td>
    </tr>
  </table>

  <table border="0" cellpadding="3" cellspacing="1" width="100%" class="forumline">
    <tr>
      <th class="thCornerL" style="white-space:nowrap; height:25px; width:5%;">&nbsp;{L_FLAG}&nbsp;</th>
      <th class="thTop" style="white-space:nowrap; width:55%;">&nbsp;{L_SUBJECT}&nbsp;</th>
      <th class="thTop" style="white-space:nowrap; width:20%;">&nbsp;{L_FROM_OR_TO}&nbsp;</th>
      <th class="thTop" style="white-space:nowrap; width:15%;">&nbsp;{L_DATE}&nbsp;</th>
      <th class="thCornerR" style="white-space:nowrap; width:5%;">&nbsp;{L_MARK}&nbsp;</th>
    </tr>
    <!-- BEGIN listrow -->
    <tr>
      <!-- start remove CMSDreams -->
      <!-- <td class="{listrow.ROW_CLASS}" style="width:5%;" align="center" valign="middle"><img src="{listrow.PRIVMSG_FOLDER_IMG}" width="19" height="18" alt="{listrow.L_PRIVMSG_FOLDER_ALT}" title="{listrow.L_PRIVMSG_FOLDER_ALT}" /></td> -->
      <!-- end remove CMSDreams -->
      <!-- start add CMSDreams -->
      <td class="{listrow.ROW_CLASS}" style="width:5%;" align="center" valign="middle">{listrow.PRIVMSG_FOLDER_IMG}</td>
      <!-- end add CMSDreams -->
      <td style="width:55%;" valign="middle" class="{listrow.ROW_CLASS}"><span class="topictitle">&nbsp;<a href="{listrow.U_READ}" class="topictitle">{listrow.SUBJECT}</a></span></td>
      <td style="width:20%;" valign="middle" align="center" class="{listrow.ROW_CLASS}"><span class="name">&nbsp;<a href="{listrow.U_FROM_USER_PROFILE}" class="name">{listrow.FROM}</a></span></td>
      <td style="width:15%;" align="center" valign="middle" class="{listrow.ROW_CLASS}"><span class="postdetails">{listrow.DATE}</span></td>
      <td style="width:5%;" align="center" valign="middle" class="{listrow.ROW_CLASS}"><span class="postdetails">
        <input type="checkbox" name="mark[]2" value="{listrow.S_MARK_ID}" />
        </span></td>
    </tr>
    <!-- END listrow -->
    <!-- BEGIN switch_no_messages -->
    <tr>
      <td class="row1" colspan="5" align="center" valign="middle"><span class="gen">{L_NO_MESSAGES}</span></td>
    </tr>
    <!-- END switch_no_messages -->
    <tr>
      <td class="catBottom" colspan="5" align="right" style="height:28px;"> {S_HIDDEN_FIELDS}
        <input type="submit" name="save" value="{L_SAVE_MARKED}" class="mainoption" />
        &nbsp;
        <input type="submit" name="delete" value="{L_DELETE_MARKED}" class="liteoption" />
        &nbsp;
        <input type="submit" name="deleteall" value="{L_DELETE_ALL}" class="liteoption" />
      </td>
    </tr>
  </table>

  <table width="100%" cellspacing="2" border="0" align="center" cellpadding="2">
    <tr>
      <td align="left" valign="middle"><span class="nav">{POST_PM_IMG}</span></td>
      <td align="left" valign="middle" width="100%"><span class="nav">{PAGE_NUMBER}</span></td>
      <td align="right" valign="top" style="white-space:nowrap;"><b><span class="gensmall"><a href="javascript:select_switch(true);" class="gensmall">{L_MARK_ALL}</a> :: <a href="javascript:select_switch(false);" class="gensmall">{L_UNMARK_ALL}</a></span></b><br /><span class="nav">{PAGINATION}<br /></span></td>
    </tr>
  </table>
</form>

_________________
dfaddons.com

earth's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
OS/Apache/Mysql/php/9.2.X/
Back to top
View user's profile Visit poster's website Photo Gallery
Kendle
500+ Posts Club
500+ Posts Club

Offline Offline
Joined: Dec 16, 2004
Posts: 552

PostPosted: Tue Jul 13, 2010 2:49 pm
Post subject: Re: Some jQuery functionality for DF modules

Added a new function for including the CKEditor WYSIWYG rich text editor in modules.

As before initialise the class

PHP:

$jQ
= new jquery();

Initialise the text editor functions

PHP:

$jQ
->text($html, $toolbar, $skin);

where :-

$html

true - allow user to enter HTML and use the CKEditor WYSIWYG editor
false - do not allow the user to enter HTML and use the standard BBCode editor

$toolbar = the toolbar to use if using CKEditor, valid options are :-

Full - everything
Basic - hardly anything

$skin = the skin to use with the CKEditor, valid options are :-

kama - default
office2003 - an Office 2003 appearance
v2 - retro FCKEditor skin

note 1 :-

allowing untrusted users to enter HTML is a "very bad idea", so please ensure the $html flag is tested against some condition before setting it to true, for example :-

PHP:

$jQ
->text( is_admin() );

this would present a standard bbcode editor for ordinary users and a CKEditor WYSIWYG editor for admins.

note 2 :-

if using the CKEditor WYSIWYG editor you can create your own toolbars and skins and use them by providing the appropriate parameters :-

PHP:

$jQ
->text( is_admin(), 'MyToolBar', 'MySkin' );

for help on creating your own toolbars and skins refer to the CKEditor document pages :-

docs.cksource.com

To ensure the necessary javascript is included you must then call :-

PHP:

$jQ
->header();

Note: You must do the above before including "header.php" in your code.

To add an editor to a form :-

PHP:

$jQ
->text_field($id, $text, $form, $cols, $rows);

$id = the id / name of the input field
$text = the starting text value of the field
$form = the name of the form (only required for bbcode)
$cols = the width of the textarea (only required for bbcode)
$rows = the height of the textarea (only required for bbcode)

example :-

PHP:

echo '
<form action="'
.getlink().'" method="post">
Text '
.$jQ->text_field('MyText').'
<input type="submit" value="Submit" />
</form>
'
;

There is no separate function to retrieve the text posted as it's returned in $_POST like any other form field, i.e. if you created a field as described above, you would retrieve the value in your module with :-

PHP:

$mytext
= Fix_Quotes($_POST['MyText']);

To display text :-

PHP:

$jQ
->text_display($text);

$text = the text to display

note :- this function does not strip HTML if there is any included in $text. It is your responsibility as the module developer to sanitise $text prior to display, or prior to saving in the database if applicable.

In fact all this function does is use decode_bb_all(), however I've included it should you wish to implement some form of HTML sanitisation.

_________________
Gaming League / Cup - www.leaguecms.co.uk :: Other DragonFly modules - www.cmsdreams.co.uk

Kendle's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Back to top
View user's profile Visit poster's website
Eestlane
I18N / L10N Lead Dev
I18N / L10N Lead Dev

Offline Offline
Joined: Apr 06, 2005
Posts: 1404
Location: Estonia
PostPosted: Tue Jul 13, 2010 6:08 pm
Post subject: Re: Some jQuery functionality for DF modules

That wysiwyg editor looks really nice.


Eestlane's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Linux/2.0.63/5.0.67/5.2.8/9.2.1
Back to top
View user's profile Send e-mail Visit poster's website
Kendle
500+ Posts Club
500+ Posts Club

Offline Offline
Joined: Dec 16, 2004
Posts: 552

PostPosted: Wed Jul 14, 2010 2:11 pm
Post subject: Re: Some jQuery functionality for DF modules

How about an AJAX powered commenting system ?

Comments

To avoid spreading similar files throughout your website the comment system places some of it's files in the modules/Comment folder. To use these files the Comment "module' has to be installed and activated as if it were any other module, even though it's not a real module as such.

In your module declare an instance of the class :-

PHP:

$jQ
= new jquery();

Then initialise the comment functions :-

PHP:

$jQ
->cmmt( array('KEY' => $VALUE) );

This function takes the following parameters :-

CMMT_QUOTE : true = enable the quote option, false = disable the quote option

default = true

CMMT_REPLY : true = enable the reply option, false = disable the reply option

default = true

CMMT_DELETE : true = enable comments to be physically deleted, false = flag comments as deleted but retain in the table

default = false

CMMT_SPACER : percentage by which to indent nested replies. this is cumulative, so if the first level of replies were indented 5% (default) any replies to the reply would be 10% (5 * 2), and any replies to the reply to the reply would be 15% (5 * 3) etc.

default = 5

CMMT_MAXNEST : the maximum number of times nested replies can be indented

default = 10

CMMT_COLS : the number of characters wide the text input box will be

default = 60

CMMT_ROWS : the number of lines high the text input box will be

default = 15

Parameters are passed as an array of key => value pairs, like so :-

PHP:

$jQ
->cmmt(array(
'CMMT_QUOTE' => true,
'CMMT_REPLY' => true,
'CMMT_SPACER' => 3,
'CMMT_MAXNEST' => 20
));

The order in which the parameters are listed is not important, and they are all optional as default values will be used for any that are missing.

Note:-

CMMT_DELETE cannot be true if CMMT_REPLY is also true, as the Class doesn't physically delete nested replies.

It could of course do so, but I took the view it would not be appropriate for a user to be able to delete other people's posts just because they're replies to his/hers.

Also, if I made it so nested replies were re-linked to the parent of the reply being deleted they could be out of context, i.e. it might not make sense if the replies appeared to be replying to something other than the comment they were originally replying to.

So you need to decide whether to allow people to reply to other comments by clicking a 'reply' option and having them nested beneath the comment they're replying to.

If you do, deleted comments will not physically be deleted from the table, however they will not be visible to anyone, they will just be replaced with text such as "this comment has been deleted".

If you want deleted comments to be physically deleted you can't use the reply feature, or have the option of un-deleting them either.

To ensure the necessary javascript is included you must then call :-

PHP:

$jQ
->header();

Note: You must do the above before including "header.php" in your code.

To add a comment box to your module you must first create a link to your module like so :-

PHP:

$jQ
->cmmt_link($mod, $link, $page, $key1, $key2);

$mod : the name of your module. whatever's stored in the global $module_name will be used if this is not supplied.

$link : whatever you would put in getlink() to load the page the comments are to be added to, for example :- "&file=MyFile&id=$id"

$page : in order to add comments to more than one page / file in your module you can specify a page number (0 if not used).

$key1 : the primary record ID number of the table you wish to link the comments to.

$key2 : the secondary record ID number of the table you wish to link the comments to (0 if not used).

To then display a comment box in your module :-

PHP:

$jQ
->cmmt_display();

To delete all comments associated with the linked module record

PHP:

$jQ
->cmmt_delete();

To count comments associated with the linked module record

PHP:

$jQ
->cmmt_count();

To retrieve the total comments associated with the linked module

PHP:

$jQ
->cmmt_total();

So, in a few lines of code you can add a commenting system to your module and instead of the traditional "enter comment" -> "POST data to website" -> "page reload" mechanism the page never reloads, new comments just appear in the correct place.

_________________
Gaming League / Cup - www.leaguecms.co.uk :: Other DragonFly modules - www.cmsdreams.co.uk

Kendle's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic    Reply to topic    Printer Friendly Page    Forum Index ⇒  Add-Ons & Blocks
Page 1 of 2
All times are GMT
Go to page 1, 2  Next



Jump to:  


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


 
   Toggle Content User Info

Welcome Anonymous

Nickname
Password
(Register)

   Toggle Content Last CVS commits
· Fixed .ico Expires header.
· Removed domain name from cookies so subdomains wont access them anymore.
· CSS and JS, case insensitives.
· CSS and JS, send correct HTTP 1.1 headers and fixed issues where themes and...
· Further security class improvements.
· 301 redirects on LEO changes
· Option to force 3xx http status codes
· Validate googlebot.com and google.com crawlers.
· CCBot
· Rss with etag and atom.

read more...

   Toggle Content Community

Support for DragonflyCMS in a other languages:

Deutsch
Español

   Toggle Content X-links
UltraEdit Browse Happy logo Firefox MySQL PostgreSQL Valid CSS! Valid XHTML 1.0! Unicode Encoded Badge NukeBiz Resources Raven DragonflyCMS Dedicated Now InsideSupport Lampe Berger

You are seeing squares or questionmarks on this page?

All content of this website is copyrighted by the Creative Commons NC-SA
The logos and trademarks used on this site are the property of their respective owners
We are not responsible for comments posted by our users, as they are the property of the poster.
Our server runs on a P3 1.2GHz with 512MB RAM with no accelerators
Support GoPHP5.org
Interactive software released under GNU GPL, Code Credits, Privacy Policy