PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/smarty2/plugins/function.init.php

http://zoop.googlecode.com/
PHP | 94 lines | 80 code | 13 blank | 1 comment | 8 complexity | 4ca0f0455438329b755cd23d0ba60079 MD5 | raw file
 1<?php
 2function smarty_function_init($params, &$smarty)
 3{
 4	$modules = isset($params['type']) ? $params['type'] : array('dnd', 'ajax', 'input');
 5	
 6	foreach($modules as $thisModule)
 7	{
 8		GuiInit::$thisModule();
 9	}
10}
11
12class GuiInit
13{
14	function dnd()
15	{
16		
17	}
18	
19	function ajax()
20	{
21		
22	}
23	
24	function input()
25	{
26?>
27<script>
28function GuiValidateForm()
29{
30	var ok = true;
31	var message = 'Please correct the following mistakes in the form:\n';
32
33	var constraints = document.getElementsByTagName("constraint");
34//	var names = {};
35	for(var i = 0; i < constraints.length; i++)
36	{
37		var res = GuiCheckConstraint(constraints[i]);
38		if(!res['ok'])
39		{
40			ok = false;
41			message += "\n" + res['message'];
42			var onemessage = res['message'];
43		}
44		else
45			var onemessage = '';
46		
47		var status = document.getElementById('gui_status_' + constraints[i].name);
48		
49		if(status && onemessage)
50			status.innerText = onemessage;
51	}
52
53	if(!ok)
54	{
55		alert(message);
56		return false;
57	}
58
59	return true;
60}
61
62function GuiCheckConstraint(constraint)
63{
64	var res = {ok: true, message: ''};
65
66	switch(constraint.type)
67	{
68		case 'minlen':
69		var input = document.getElementById(constraint.name);
70		if(input.value.length < constraint.value)
71		{
72			res['ok'] = false;
73			res['message'] = constraint.inline;
74		}
75		break;
76		case 'sameas':
77		var input = document.getElementById(constraint.name);
78		var input2 = document.getElementById(constraint.value);
79		if(input.value != input2.value)
80		{
81			res['ok'] = false;
82			res['message'] = constraint.inline;
83		}
84		break;
85		default:
86		throw "Bad constraint type";
87		break;
88	}
89	return res;
90}
91</script>
92<?php
93	}
94}