1<?php
2/**
3* Finestra per la gestione dei link dalla scheda
4* Viene aperta in popup dal file {@link scheda.php}
5*
6* @package VFront
7* @author Mario Marcello Verona <marcelloverona@gmail.com>
8* @copyright 2007-2010 M.Marcello Verona
9* @version 0.96 $Id: add.link.php 880 2010-12-14 12:43:47Z marciuz $
10* @license http://www.gnu.org/licenses/gpl.html GNU Public License
11*/
12
13// Imposto l'esecuzione massima in 10 minuti
14ini_set('max_execution_time',600);
15
16
17include("./inc/conn.php");
18include("./inc/layouts.php");
19include("./inc/func.comuni.php");
20include("./inc/func.frontend.php");
21
22
23
24proteggi(1);
25
26
27
28
29/**
30 * Funzione di parsing del link.
31 * Controlla la validità del link e qualora non sia espresso un suffisso valido come http:// o https://
32 * se sovreascrive il contenuto
33 *
34 * @param string $user_link
35 * @todo La funzione è da scrivere, attualmente restituisce la stringa così com'è
36 * @return string
37 */
38function parse_link($user_link){
39
40	return $user_link;
41}
42
43
44
45
46######################################################################
47#
48#	CASO ELIMINA ALLEGATO
49#
50
51
52if(isset($_GET['del'])){
53
54	$id_da_eliminare=str_replace(_BASE64_PASSFRASE,'',base64_decode($_GET['del']));
55
56	$id_da_eliminare=intval($id_da_eliminare);
57
58	// elimino dal DB
59	$q_del=$vmsql->query("DELETE FROM "._TABELLA_LINK." WHERE codicelink=$id_da_eliminare");
60
61	$test_del_db= ($vmsql->affected_rows($q_del)==1) ? true:false;
62
63
64	if($test_del_db){
65		header("Location: ".$_SERVER['PHP_SELF']."?t=".$_GET['t']."&id=".$_GET['id']."&az=del&feed=ok");
66
67	}
68	else{
69		header("Location: ".$_SERVER['PHP_SELF']."?t=".$_GET['t']."&id=".$_GET['id']."&az=del&feed=ko");
70	}
71
72	exit;
73}
74
75
76#
77#
78######################################################################
79
80
81
82#######################################################################
83#
84#	CASO UPLOAD ESEGUITO
85#
86
87if(count($_POST['links'])>0){
88
89	$tabella = preg_replace("'[\W]+'","",trim($_POST['t']));
90	$id = preg_replace("'[\W]+'","",trim($_POST['id']));
91
92
93	$success=0;
94
95	for($i=0;$i<count($_POST['links']);$i++){
96
97		$sql_ins="INSERT into "._TABELLA_LINK." (tipoentita,codiceentita,link)
98				 VALUES('$tabella','$id','".$_POST['links'][$i]."')";
99
100		$q_ins=$vmsql->query($sql_ins);
101		if($vmsql->affected_rows($q_ins)==1){
102			$success++;
103		}
104	}
105
106	if(count($_POST['links'])==$success){
107
108		header("Location: ".$_SERVER['PHP_SELF']."?t=".$_POST['t']."&id=".$_POST['id']."&feed=ok");
109		exit;
110	}
111	else{
112		header("Location: ".$_SERVER['PHP_SELF']."?t=".$_POST['t']."&id=".$_POST['id']."&feed=ko");
113	}
114
115
116	exit;
117}
118########################################################################
119
120
121
122
123
124
125
126
127
128
129
130
131
132########################################################################
133#
134#	VISTA PAGINA - QUERY DI RICERCA LINK
135#
136
137
138
139
140# CASO SPECIALE NEW:
141// L'utente ha cliccato su allegato quando ancora il record non era salvato..
142if($_GET['id']=='new'){
143
144	$msg=_("To inset a link, first save the new record, and then insert the link.");
145	openErrorGenerico(_('You cannont insert a link until you have first saved the new record'),false,$msg,'popup');
146	exit;
147}
148
149if($_GET['id']=='ric'){
150
151	$msg=_("You are in the middle of a search. Complete or cancel  the search before inserting the link.");
152	openErrorGenerico(_('You cannot insert a link while in search mode'),false,$msg,'popup');
153	exit;
154}
155
156$tabella = preg_replace("'[\W]+'","",trim($_GET['t']));
157$id = preg_replace("'[\W]+'","",trim($_GET['id']));
158
159// PRENDI IMPOSTAZIONI ALLEGATI PER TABELLA/REGISTO
160$info_tab=prendi_info_tabella($tabella, "permetti_link_ins, permetti_link_del");
161
162$link_ins=$info_tab['permetti_link_ins'];
163$link_del=$info_tab['permetti_link_del'];
164
165
166if(!is_tabella($tabella) || $id==''){
167
168	openErrorGenerico(_('Request error'),false);
169	exit;
170}
171
172
173
174
175// CERCA ALLEGATI PER QUESTA TABELLA
176$qa=$vmsql->query("SELECT * FROM "._TABELLA_LINK."
177				WHERE tipoentita='$tabella'
178				AND codiceentita='$id'
179				ORDER BY link, lastdata");
180
181$num_link=$vmsql->num_rows($qa);
182
183$matrice_info_link=$vmsql->fetch_assoc_all($qa);
184
185
186
187
188
189
190
191
192
193
194
195
196
197$files = array('sty/linguette.css','sty/admin.css','js/clona_link.js','sty/attach.css');
198
199$INIZIO_LAYOUT= openLayout1("Link",$files,'popup');
200
201echo str_replace("<body>","<body onload=\"self.focus();\">",$INIZIO_LAYOUT);
202
203echo "<img src=\"./img/network.gif\" style=\"float: left;\" alt=\""._('link management')."\" />\n";
204
205echo "<h1 style=\"font-size:1.6em;\">"._('Link for record')." <span class=\"var\">".$_GET['id']."</span> "._('of table')." <span class=\"var\">".$_GET['t']."</span></h1>";
206
207echo "<br style=\"clear:left;\" />";
208
209
210
211$JS_aggiorna= (isset($_GET['feed']) && $_GET['feed']=='ok') ?  'window.opener.richiediAL();' : "";
212
213
214
215	// prendi aree tematiche
216	/*$q_aree=$vmsql->query("SELECT codiceAreatematica, descAreatematica FROM areatematica ORDER BY descAreatematica");
217
218	$SELECT = "\t<select name=\"area[]\">\n";
219
220	while($RS=$vmsql->fetch_assoc($q_aree)){
221		$areetematiche[$RS['codiceAreatematica']]=$RS['descAreatematica'];
222		$SELECT.="\t\t<option value=\"".$RS['codiceAreatematica']."\">".$RS['descAreatematica']."</option>\n";
223	}
224
225	$SELECT.="\t</select>\n";
226	*/
227
228
229
230	echo "
231	<script type=\"text/javascript\">
232
233		$JS_aggiorna
234
235		var divs = new Array('link','nuovilink');
236
237		var nuoviLink=0;
238
239		function eti(ido){
240
241			for (var i in divs){
242				document.getElementById('cont-eti-'+divs[i]).style.display='none';
243				document.getElementById('li-'+divs[i]).className='disattiva';
244			}
245
246			// attiva il selezionato
247			document.getElementById('cont-eti-'+ido).style.display='';
248			document.getElementById('li-'+ido).className='attiva';
249
250		}
251
252
253	</script>
254	";
255
256
257	echo "
258<div id=\"contenitore-variabili\">
259	<div id=\"box-etichette\">
260
261		<ul class=\"eti-var-gr\">
262
263
264			<li onclick=\"eti('link');\" id=\"li-link\" class=\"attiva\">"._('Link')."</li>
265			", ($link_ins) ? "<li onclick=\"eti('nuovilink');\" id=\"li-nuovilink\" class=\"disattiva\">"._('Add link')."</li>" : "","
266
267		</ul>
268
269	</div>";
270
271
272	// LINGUETTA NUOVO FLUSSO
273	echo "
274	<div class=\"cont-eti\" id=\"cont-eti-link\" >
275
276		<p>"._('Link for this record:')." <strong>$num_link</strong></p>
277
278		<hr class=\"light2\" />
279		";
280
281
282		// MOSTRA GLI ALLEGATI
283		for($i=0;$i<count($matrice_info_link);$i++){
284
285			$elimina= ($link_del) ? " - <span class=\"fakelink-rosso\" onclick=\"if(confirm('"._('Do you really want to cancel this link?')."')){ window.location='".$_SERVER['PHP_SELF']."?t=$tabella&amp;id=$id&amp;del=".base64_encode($matrice_info_link[$i]['codicelink']._BASE64_PASSFRASE)."';}\" >"._('Delete')."</span>" : "";
286
287			echo "
288			<div class=\"link\">
289				<p><a href=\"".parse_link($matrice_info_link[$i]['link'])."\">".$matrice_info_link[$i]['link']."</a> $elimina<br />
290				".
291//			"<span class=\"grigio\">Area: ".$areetematiche[$matrice_info_link[$i]['codiceAreaTematica']]."</span>".
292			"</p>
293			</div>\n";
294		}
295
296
297
298
299	echo "
300	</div>
301	";
302
303
304
305
306	// LINGUETTA AMMINISTRAZIONE FLUSSI
307
308	if($link_ins){
309
310	echo "
311	<div class=\"cont-eti\" id=\"cont-eti-nuovilink\" style=\"display:none;\">
312		<br />
313		";
314
315
316	?>
317	<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" >
318			<div>
319				<div id="contenitore-link"><div><input type="text" name="links[]" size="68" value="http://" /><?php echo $SELECT; ?>
320				<span onclick="rimuovi_link(this);" class="fakelink" style="font-size:0.7em;"><?php echo _('remove');?></span><br /></div></div>
321
322				<span onclick="clona_link();" class="fakelink"><?php echo _('Add another link');?></span><br /><br /><br />
323
324
325				<input type="hidden" name="t" value="<?php echo $tabella;?>" />
326				<input type="hidden" name="id" value="<?php echo $id;?>" />
327
328				<input type="submit" name="aggiungi" value="  <?php echo _('Send');?>  " onclick="submit();this.value='<?php echo _('Please wait...');?>';this.disabled=true;"  />
329
330			</div>
331		</form>
332
333<?php
334
335
336		echo "</div>\n";
337	} //-- fine clausola diritti nuovi inserimenti
338
339
340echo "</div><!-- fine contenitore -->\n\n";
341
342
343
344
345echo closeLayout1();
346?>