1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8//this script may only be included - so its better to die if called directly.
9if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
10	header("location: index.php");
11	exit;
12}
13
14/**
15 * \brief Smarty {js_maxlength} function handler
16 *
17 * Creates javascript to add 'maxlength' functionality to a <textbox>
18 * Usage:
19 * {js_maxlength textarea=[string] maxlength=[int]}
20 *
21 * TODO would be great if it worked with array arguments
22 *
23 */
24
25function smarty_function_js_maxlength($params, $smarty)
26{
27	extract($params); // textarea=string maxlength=num
28
29	echo "\n<script type=\"text/javascript\">\n";
30	echo "<!--\n";
31
32	echo "function verifyForm(f){\n";
33	echo " var rtn=true;\n";
34	echo "  if ( f.$textarea.value.length > $maxlength ) {\n";
35	echo "    alert('" . tra("The text is") . " ' + (f.$textarea.value.length - $maxlength) + ' " . tra("character(s) too long - please edit it.") . "');\n";
36	echo "    rtn = false;\n";
37	echo "  }\n";
38	echo "  return rtn;\n";
39	echo "}\n";
40	echo "//-->\n";
41	echo "</script>\n";
42}
43