Removed the content of function header2 in pdf_report.inc to a separate file, header2...
[fa-stable.git] / update_db.php
1 <?php
2 //ini_set("display_errors", "on");
3 $path_to_root = ".";
4 include_once($path_to_root. "/admin/db/maintenance_db.inc");
5 include_once($path_to_root. "/includes/db/connect_db.inc");
6 include_once($path_to_root. "/includes/ui/ui_view.inc");
7 include_once($path_to_root. "/includes/ui/ui_input.inc");
8
9 $js = get_js_png_fix();
10 $js .= get_js_set_focus("user");
11 $image = $path_to_root."/themes/default/images/logo_frontaccounting.png";
12 $title = "Update All Company Databases";
13
14 function get_js_set_focus($name)
15 {
16         $js = "\n<script type=\"text/javascript\">\n"
17                 . "<!--\n"
18                 . "function setFocus()\n"
19                 . "{\n"
20                 . "     document.forms[0].$name.focus();\n"
21                 . "}\n"
22                 . "-->\n"
23                 . "</script>\n";
24         return $js;
25 }
26
27 function display_error($msg, $center=true)
28 {
29     echo "<center><table border='1' cellpadding='3' cellspacing='0' style='border-collapse: collapse' bordercolor='#CC3300' width='50%'>
30       <tr>
31         <td  " . ($center?"align='center' ":"") . " width='100%' bgcolor='#ffcccc'><font color='#dd2200'>$msg</font></td>
32       </tr>
33     </table></center><br>\n";
34 }
35
36 function display_notification($msg, $center=true)
37 {
38     echo "<center><table border='1' cellpadding='3' cellspacing='0' style='border-collapse: collapse' bordercolor='#33cc00' width='50%'>
39       <tr>
40         <td " . ($center?"align='center' ":"") . " width='100%' bgcolor='#ccffcc'><font color='#007700'>$msg</font></td>
41       </tr>
42     </table></center><br>\n";
43 }
44
45
46 function db_open($conn)
47 {
48         $db = mysql_connect($conn["host"] ,$conn["dbuser"], $conn["dbpassword"]);
49         if (!$db)
50                 return false;
51         if (!mysql_select_db($conn["dbname"], $db))
52                 return false;
53         return $db;
54 }
55
56 echo "<html dir='ltr' >\n";
57 echo "<head><title>$title</title>\n";
58 echo "<meta http-equiv='Content-type' content='text/html'; charset='iso-8859-1'>\n";
59 echo "<link href='$path_to_root/themes/default/default.css' rel='stylesheet' type='text/css' />\n";
60 echo $js;
61 echo "</head> \n";
62 echo "<body style='background-color:#f9f9f9;' onload='setFocus();'>";
63
64 echo "<br><br><br><br>";
65 echo "<table align='center' width='50%' cellpadding=3 border=1 bordercolor='#cccccc' style='border-collapse: collapse'>\n";
66 echo "<tr><td align='center' valign='bottom'><img src='$image' alt='FrontAccounting' width='250' height='50' onload='fixPNG(this)' border='0' /></td></tr>\n";
67 echo "</table>\n";
68
69 echo "<br><br>";
70 echo "<center><span class='headingtext'>$title</span></center>\n";
71 echo "<br>";
72
73 if (isset($_POST["submit"]))
74 {
75         if (!isset($_FILES['uploadfile']['tmp_name']) || !is_uploaded_file($_FILES['uploadfile']['tmp_name']))
76         {
77                 display_error("You must select an SQL script for update");;
78         }
79         else
80         {
81                 include_once($path_to_root."/config_db.php");
82                 if (!isset($_POST['user']) || !isset($_POST['passwd']) || $_POST['user'] == "")
83                 {
84                         display_error("You must select a user name and an optional password");
85                 }
86                 else
87                 {
88                         foreach($db_connections as $id => $conn)
89                         {
90                                 $conn['dbuser'] = $_POST['user'];
91                                 $conn['dbpassword'] = $_POST['passwd'];
92                                 if (!($db = db_open($conn)))
93                                 {
94                                         display_error("Wrong user name or password - ".mysql_error());
95                                 }
96                                 else
97                                 {
98                                         if (!db_import($_FILES['uploadfile']['tmp_name'], $conn))
99                                                 display_error("Bad SQL file or you have already updated the company: "
100                                                         . $id . " " . $conn['name']." - ".mysql_error());
101                                         else
102                                                 display_notification("Database has been updated for company: "
103                                                         . $id . " " .  $conn['name']);
104                                 }
105                         }
106                 }
107         }
108 }
109 if (!isset($_POST['passwd']))
110         $_POST['passwd'] = "";
111
112 echo "<form enctype='multipart/form-data' method='post' action='".$_SERVER['PHP_SELF']."'>\n";
113
114 echo "<table align='center' width='50%' cellpadding=3 border=1 bordercolor='#cccccc' style='border-collapse: collapse'>\n";
115
116 text_row_ex("Database User", "user", 20);
117 label_row("Password", "<input name='passwd' type='password' value='".$_POST['passwd']."' />");
118 label_row("Upload Script", "<input name='uploadfile' type='file'>");
119 submit_row("submit", "Update");
120
121 echo "</table>\n";;
122
123 echo "<br><br>";
124 echo "<center><span>Choose from Database update scripts in SQL folder. No Datase is updated without a script.</span></center>\n";
125 echo "<br>";
126
127 echo "</form>\n";
128
129 echo "</body></html>\n";
130 ?>