Suggested update to print function

Talk about new features for CMSMS and modules.
Post Reply
Glenn

Suggested update to print function

Post by Glenn »

I think this change in the print function is a little more elegant than the way it is currently implemented.

The way the print function works now is if you choose the showbutton option you get the same button on the actual web page as well as on the printable page, and they both do the same thing -- bring up another popup (if you use that option) or bring up another printable page--ad infinitum. If you use text instead of the button you get "Print this page," which is NOT what that link actually does. Instead, it brings up a "printable version" of the page -- ad infinitum.

So my suggestion (and rough solution below) is to make the first block of text say "Printable Version" which, when cliked, brings up the printable version, and the text on the printable version page says "Print" which, when clicked, brings up the print dialog box.

if you use "showbutton" then the first button brings up the ptintable version and the second brings up the print dialog.

Here's how I changed it:

line 23-24:

Code: Select all

	global $gCms;

	$text = 'Printable Version';
	$print = 'Print';
lines 55-76:

Code: Select all

	if (isset($params["showbutton"]))
	{
		if ($_GET['print'])
			{
				return '<a href="javascript:window.print();"><img src="'.$gCms->config['root_url'].'/images/cms/printbutton.gif" alt="'.$text.'"/></a>';
			}
		else
			{
				return '<a href="'.$gCms->config['root_url'].'/index.php?page='.$gCms->variables['content_id'].'&print=true' . $goback . $js . '"'. $target . '><img src="'.$gCms->config['root_url'].'/images/cms/printbutton.gif" alt="'.$text.'"/></a>';
			}
	}
	else
	{
		if ($_GET['print'])
			{
				return '<a href="javascript:window.print();">'.$print.'</a>';
			}
		else
			{
				return '<a href="'.$gCms->config['root_url'].'/index.php?page='.$gCms->variables['content_id'].'&print=true' . $goback . $js . '"'. $target . '>'.$text.'</a>';
			}
	}
I also edited the help section so that the english actually makes sense:

Code: Select all

                <li><em>(optional)</em>goback - Set to "false" and in print page you won't see the "Go Back" button.</li>
                <li><em>(optional)</em>popup - Set to "true" and printable page will by opened in new window.</li>
                <li><em>(optional)</em>script - Set to "true" and printable page will automatically bring up the print dialog box using javascript.</li>
                <li><em>(optional)</em>showbutton - Set to "true" and will show a printer graphic instead of a text link.</li>
Finally, there's an issue with the CSS. Currently the content is wrapped only in the body tag, which in the default templates uses text-align: center so that everything on the printable page is center-aligned. Can you add a parameter like divid="" so you manually choose a style to wrap {content} in?

Thanks!
Glenn

Even better still...

Post by Glenn »

This is even more elegant (haven't figured out the css issue yet):

if you use script="true" the printable version still comes up but the print dialog box comes up automatically. Eliminate the text link or button on the printable version like this:

Top of function.print.php:

Code: Select all

	global $gCms;

	$text = 'Printable Version';
	$print = 'Print This Page';
	$printbut = '<img src="'.$gCms->config['root_url'].'/images/cms/printbutton.gif" alt="'.$text.'"/>';
body:

Code: Select all

	
if (isset($params["showbutton"]))
	{
		if ($_GET['print']) 
			{
				//This is the printable version
				return '<a href="javascript:window.print();">'.$printbut.'</a>';
			}
		else
			{
				//This is the actual web page
				return '<a href="'.$gCms->config['root_url'].'/index.php?page='.$gCms->variables['content_id'].'&print=true' . $goback . $js . '"'. $target . '><img src="'.$gCms->config['root_url'].'/images/cms/printbutton.gif" alt="'.$text.'"/></a>';
			}
	}
	else
	{
		if ($_GET['print'])
			{
				//This is the printable version
				return '<a href="javascript:window.print();">'.$print.'</a>';
			}
		else
			{
				//This is the actual web page
				return '<a href="'.$gCms->config['root_url'].'/index.php?page='.$gCms->variables['content_id'].'&print=true' . $goback . $js . '"'. $target . '>'.$text.'</a>';
			}
	}
Post Reply

Return to “Feature ideas”