1<?php
2
3/*
4=======================================================
5	PHP
6=======================================================
7*/
8
9require_once('security.php');
10
11if( $_SERVER['REQUEST_METHOD'] == 'POST' )
12{
13	if( $_URL['exe'] === 'save' )
14	{
15		foreach( $_POST as $post_element)
16		{
17			$data = explode(',', $post_element);
18
19			if( $data[1] === 'static' )
20			{
21				// Name not empty
22				if($nbfunctions->not_empty($data[2]))
23					$dbxml_links->set($data[0], $data[2], $data[3]);
24			}
25			elseif( $data[1] === 'dynamic' )
26			{
27				// Name not empty
28				if($nbfunctions->not_empty($data[2]))
29					$dbxml_links->add($data[2], $data[3]);
30			}
31		}
32	}
33	elseif( $_URL['exe'] === 'delete' )
34	{
35		$dbxml_links->delete( $_GET['idcat'] );
36	}
37
38	// Commit :D
39	if( !$dbxml_links->flag_error() )
40	{
41		$dbxml_links->savetofile();
42
43		if( !$dbxml_links->flag_error() )
44		{
45			$_FLAG['msj'] = $_LANG['THE_CHANGES_SAVED_SUCCESS'];
46			$_FLAG['success'] = true;
47		}
48	}
49
50	// Check for errors
51	if( $dbxml_links->flag_error() )
52	{
53		$_FLAG['msj'] = $_LANG[ $dbxml_links->flag_i18n() ];
54		$_FLAG['error'] = true;
55	}
56}
57
58/*
59=======================================================
60	HTML
61=======================================================
62*/
63
64	echo '<div id="main">';
65
66	$html->banner_success_error($_FLAG['msj'], $_FLAG['success'], $_FLAG['error']);
67
68	echo '<div class="container_box_default">';
69
70	echo '<div class="container_title_default">'.$_LANG['MANAGE_LINKS'].'</div>';
71
72	echo '<form method="post">';
73
74	echo '
75			<input type="hidden" id="exe" name="exe" />
76			<input type="hidden" name="token" value="'.$login->get_token().'" />
77	';
78
79	echo '<div id="js_container">';
80
81	$links = $dbxml_links->get_all();
82	foreach($links as $link)
83	{
84		echo '
85			<div class="link_box" info_id="'.$link['id'].'">
86
87				<input type="hidden" id="data_'.$link['id'].'" name="data_'.$link['id'].'" />
88				<input type="hidden" id="type_'.$link['id'].'" value="static" />
89
90				<div class="container_form_box_float">
91					<div class="container_title_fields">'.$_LANG['NAME'].'</div>
92					<input type="text" class="textbox_xsmall" id="name_'.$link['id'].'" value="'.$link['name'].'"/>
93				</div>
94
95				<div class="container_form_box_float">
96					<div class="container_title_fields">'.$_LANG['URL'].'</div>
97					<input type="text" class="textbox_medium" id="url_'.$link['id'].'" value="'.$link['url'].'"/>
98				</div>
99
100				<div class="container_form_box_float" style="padding-top: 6px;">
101					<input type="button" class="border_round_3px button_default button_delete" info_id="'.$link['id'].'" info_step="0" value="'.$_LANG['DELETE'].'"/>
102				</div>
103
104				<br class="clearfloat" />
105			</div>
106		';
107	}
108
109	echo '</div>'; // END <div id="js_container">
110
111	// BUTTONS
112	echo '
113			<div class="container_form_buttons">
114				<input type="button" value="'.$_LANG['SAVE'].'"				class="border_round_3px button_default"	id="js_button_save" />
115				<input type="button" value="'.$_LANG['ADD'].'"				class="border_round_3px button_default"	id="js_button_add" />
116				<input type="button" value="'.$_LANG['CANCEL'].'"			class="border_round_3px button_cancel"		id="js_button_cancel" />
117			</div>
118	';
119
120	echo '</form>';
121
122	echo '</div>'; // END <div class="container_box_default">
123
124	echo '</div>'; // END <div id="main">
125
126?>
127
128<script type='text/javascript'>
129
130/*
131=======================================================
132	JAVASCRIPT : VARS
133=======================================================
134*/
135
136var tmp_id = <?php echo $dbxml_links->get_autoinc(); ?>;
137
138/*
139=======================================================
140	JAVASCRIPT : FUNCTIONS
141=======================================================
142*/
143
144// Save links
145function submit_form()
146{
147	$.each( $(".link_box"), function(index, value)
148	{
149		var id = $(this).attr("info_id");
150		var type = $("#type_"+id).val();
151		var name = $("#name_"+id).val();
152		var url = $("#url_"+id).val();
153
154		$("#data_"+id).attr("value",id+","+type+","+name+","+url);
155	});
156
157	$("#exe").attr("value","save");
158	$("form").attr("action","");
159	$("form").submit();
160
161	return false;
162}
163
164/*
165=======================================================
166	JAVASCRIPT : EVENTS
167=======================================================
168*/
169
170$(document).ready(function(){
171
172	// Event - Click - Button save
173	$("#js_button_save").click(
174		function()
175		{
176			submit_form();
177		}
178	);
179
180	// Event - Click - Button cancel
181	$("#js_button_cancel").click(
182		function()
183		{
184			window.location = "./index.php";
185		}
186	);
187
188	// Event - Click - Button add new link
189	$("#js_button_add").click(
190		function()
191		{
192			var template = '';
193			template += '<div class="link_box" info_id="'+tmp_id+'" >';
194			template += '	<input type="hidden" id="data_'+tmp_id+'" name="data_'+tmp_id+'">';
195			template += '	<input type="hidden" id="type_'+tmp_id+'" value="dynamic">';
196			template += '	<div class="container_form_box_float">';
197			template += '		<div class="container_title_fields"><?php echo $_LANG['NAME'] ?></div>';
198			template += '		<input type="text" class="textbox_xsmall" id="name_'+tmp_id+'" >';
199			template += '	</div>';
200			template += '	<div class="container_form_box_float">';
201			template += '		<div class="container_title_fields"><?php echo $_LANG['URL'] ?></div>';
202			template += '		<input type="text" class="textbox_medium" id="url_'+tmp_id+'" value="http://">';
203			template += '	</div>';
204			template += '	<div class="container_form_box_float" style="padding-top: 6px;">';
205			template += '		<input type="button" class="border_round_3px button_default button_delete" info_id="'+tmp_id+'" value="<?php echo $_LANG['DELETE'] ?>">';
206			template += '	</div>';
207			template += '	<br class="clearfloat">';
208			template += '</div>';
209
210			$("#js_container").append(template);
211
212			tmp_id+=1;
213		}
214	);
215
216	// Event - Click - Button delete
217	$(".button_delete").live("click",
218		function()
219		{
220			var button = $(this);
221			var id = button.attr("info_id");
222			var type = $("#type_"+id).val();
223			var step = button.attr("info_step");
224
225			if(type=="dynamic")
226			{
227				$(".link_box[info_id=\""+id+"\"]").fadeOut('slow', function() { $(this).remove(); });
228
229				tmp_id-=1;
230			}
231			else
232			{
233				if( step == "1" )
234				{
235					$("#exe").attr("value","delete");
236					$("form").attr("action","?pag=list&idcat="+id);
237					$("form").submit();
238				}
239				else
240				{
241					button.fadeOut(500, function() {
242						 button.attr("value","<?php echo $_LANG['SURE'] ?>");
243						 button.attr("info_step","1");
244						 button.css("background","#E32B2B");
245						 button.css("color","#FFFFFF");
246						 button.css("border-color", "#AD2727");
247					}).fadeIn(500);
248				}
249			}
250		}
251	);
252});
253
254</script>
255