2 //ini_set("display_errors", "on");
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");
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";
14 function get_js_set_focus($name)
16 $js = "\n<script type=\"text/javascript\">\n"
18 . "function setFocus()\n"
20 . " document.forms[0].$name.focus();\n"
27 function display_error($msg, $center=true)
29 echo "<center><table border='1' cellpadding='3' cellspacing='0' style='border-collapse: collapse' bordercolor='#CC3300' width='50%'>
31 <td " . ($center?"align='center' ":"") . " width='100%' bgcolor='#ffcccc'><font color='#dd2200'>$msg</font></td>
33 </table></center><br>\n";
36 function display_notification($msg, $center=true)
38 echo "<center><table border='1' cellpadding='3' cellspacing='0' style='border-collapse: collapse' bordercolor='#33cc00' width='50%'>
40 <td " . ($center?"align='center' ":"") . " width='100%' bgcolor='#ccffcc'><font color='#007700'>$msg</font></td>
42 </table></center><br>\n";
46 function db_open($conn)
48 $db = mysql_connect($conn["host"] ,$conn["dbuser"], $conn["dbpassword"]);
51 if (!mysql_select_db($conn["dbname"], $db))
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";
62 echo "<body style='background-color:#f9f9f9;' onload='setFocus();'>";
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";
70 echo "<center><span class='headingtext'>$title</span></center>\n";
73 if (isset($_POST["submit"]))
75 if (!isset($_FILES['uploadfile']['tmp_name']) || !is_uploaded_file($_FILES['uploadfile']['tmp_name']))
77 display_error("You must select an SQL script for update");;
81 include_once($path_to_root."/config_db.php");
82 if (!isset($_POST['user']) || !isset($_POST['passwd']) || $_POST['user'] == "")
84 display_error("You must select a user name and an optional password");
88 foreach($db_connections as $id => $conn)
90 $conn['dbuser'] = $_POST['user'];
91 $conn['dbpassword'] = $_POST['passwd'];
92 if (!($db = db_open($conn)))
94 display_error("Wrong user name or password - ".mysql_error());
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());
102 display_notification("Database has been updated for company: "
103 . $id . " " . $conn['name']);
109 if (!isset($_POST['passwd']))
110 $_POST['passwd'] = "";
112 echo "<form enctype='multipart/form-data' method='post' action='".$_SERVER['PHP_SELF']."'>\n";
114 echo "<table align='center' width='50%' cellpadding=3 border=1 bordercolor='#cccccc' style='border-collapse: collapse'>\n";
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");
124 echo "<center><span>Choose from Database update scripts in SQL folder. No Datase is updated without a script.</span></center>\n";
129 echo "</body></html>\n";