-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbInsMess.php
More file actions
68 lines (49 loc) · 1.66 KB
/
dbInsMess.php
File metadata and controls
68 lines (49 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
//require_once('auth.php');
require_once('config.php');
$projectID=$_POST['project_id'];
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
// Seleziono prima il db lingue e le ciclo
$query="SELECT * FROM `language`";
$result = mysql_query($query);
$vettore_risposta = array();
if ($result) {
$count=0;
while($row = mysql_fetch_array($result)){
if ($count==0)
$parent=NULL;
if ($count==1){
$parent=mysql_insert_id();
// Inserisco anche l'associazione col progetto dopo aver ottenuto il primo ID di messaggio
$query3="INSERT INTO `translation`.`projectAssoc` ( `projID` , `parent.message.ID` )
VALUES ( '".$projectID."', '".$parent."');";
$result3 = mysql_query($query3);
}
$query2="INSERT INTO `translation`.`messages` (`id`, `message`, `languageID`, `parent.mess.ID`)
VALUES (NULL, '', '".$row['id']."', '".$parent."')";
// Controllo per la stampa del NULL al parent
if ($parent==NULL)
$query2="INSERT INTO `translation`.`messages` (`id`, `message`, `languageID`, `parent.mess.ID`)
VALUES (NULL, '', '".$row['id']."', NULL)";
else
$query2="INSERT INTO `translation`.`messages` (`id`, `message`, `languageID`, `parent.mess.ID`)
VALUES (NULL, '', '".$row['id']."', '".$parent."')";
//echo $query2;
$result2 = mysql_query($query2);
$messaggi[$count++] = array( "lang_id" => $row['id'], "mess_id" => mysql_insert_id() );
}
echo json_encode($messaggi);
}
else
echo "-1";
mysql_close($link);
?>