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");
7 $js = get_js_png_fix();
8 $js .= get_js_set_focus("user");
9 $image = $path_to_root."/themes/default/images/logo_frontaccounting.png";
10 $title = "Update All Company Databases";
12 function get_js_png_fix()
14 $js = "<script type=\"text/javascript\">\n"
15 . "function fixPNG(myImage)\n"
17 . " var arVersion = navigator.appVersion.split(\"MSIE\")\n"
18 . " var version = parseFloat(arVersion[1])\n"
19 . " if ((version >= 5.5) && (version < 7) && (document.body.filters))\n"
21 . " var imgID = (myImage.id) ? \"id='\" + myImage.id + \"' \" : \"\"\n"
22 . " var imgClass = (myImage.className) ? \"class='\" + myImage.className + \"' \" : \"\"\n"
23 . " var imgTitle = (myImage.title) ?\n"
24 . " \"title='\" + myImage.title + \"' \" : \"title='\" + myImage.alt + \"' \"\n"
25 . " var imgStyle = \"display:inline-block;\" + myImage.style.cssText\n"
26 . " var strNewHTML = \"<span \" + imgID + imgClass + imgTitle\n"
27 . " + \" style=\\\"\" + \"width:\" + myImage.width\n"
28 . " + \"px; height:\" + myImage.height\n"
29 . " + \"px;\" + imgStyle + \";\"\n"
30 . " + \"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader\"\n"
31 . " + \"(src=\'\" + myImage.src + \"\', sizingMethod='scale');\\\"></span>\"\n"
32 . " myImage.outerHTML = strNewHTML\n"
39 function get_js_set_focus($name)
41 $js = "\n<script type=\"text/javascript\">\n"
43 . "function setFocus()\n"
45 . " document.forms[0].$name.focus();\n"
52 function display_error($msg, $center=true)
54 echo "<center><table border='1' cellpadding='3' cellspacing='0' style='border-collapse: collapse' bordercolor='#CC3300' width='50%'>
56 <td " . ($center?"align='center' ":"") . " width='100%' bgcolor='#ffcccc'><font color='#dd2200'>$msg</font></td>
58 </table></center><br>\n";
61 function display_notification($msg, $center=true)
63 echo "<center><table border='1' cellpadding='3' cellspacing='0' style='border-collapse: collapse' bordercolor='#33cc00' width='50%'>
65 <td " . ($center?"align='center' ":"") . " width='100%' bgcolor='#ccffcc'><font color='#007700'>$msg</font></td>
67 </table></center><br>\n";
71 function db_open($conn)
73 $db = mysql_connect($conn["host"] ,$conn["dbuser"], $conn["dbpassword"]);
76 if (!mysql_select_db($conn["dbname"], $db))
81 echo "<html dir='ltr' >\n";
82 echo "<head><title>$title</title>\n";
83 echo "<meta http-equiv='Content-type' content='text/html'; charset='iso-8859-1'>\n";
84 echo "<link href='$path_to_root/themes/default/default.css' rel='stylesheet' type='text/css' />\n";
87 echo "<body style='background-color:#f9f9f9;' onload='setFocus();'>";
89 echo "<br><br><br><br>";
90 echo "<table align='center' width='50%' cellpadding=3 border=1 bordercolor='#cccccc' style='border-collapse: collapse'>\n";
91 echo "<tr><td align='center' valign='bottom'><img src='$image' alt='FrontAccounting' width='250' height='50' onload='fixPNG(this)' border='0' /></td></tr>\n";
95 echo "<center><span class='headingtext'>$title</span></center>\n";
98 if (isset($_POST["submit"]))
100 if (!isset($_FILES['uploadfile']['tmp_name']) || !is_uploaded_file($_FILES['uploadfile']['tmp_name']))
102 display_error("You must select an SQL script for update");;
106 include_once($path_to_root."/config_db.php");
107 if (!isset($_POST['user']) || !isset($_POST['passwd']) || $_POST['user'] == "")
109 display_error("You must select a user name and an optional password");
113 foreach($db_connections as $id => $conn)
115 $conn['dbuser'] = $_POST['user'];
116 $conn['dbpassword'] = $_POST['passwd'];
117 if (!($db = db_open($conn)))
119 display_error("Wrong user name or password - ".mysql_error());
123 if (!db_import($_FILES['uploadfile']['tmp_name'], $conn))
124 display_error("Bad SQL file or you have already updated the company: "
125 . $id . " " . $conn['name']." - ".mysql_error());
127 display_notification("Database has been updated for company: "
128 . $id . " " . $conn['name']);
134 if (!isset($_POST['passwd']))
135 $_POST['passwd'] = "";
136 if (!isset($_POST['user']))
139 echo "<form enctype='multipart/form-data' method='post' action='".$_SERVER['PHP_SELF']."'>\n";
141 echo "<table align='center' width='50%' cellpadding=3 border=1 bordercolor='#cccccc' style='border-collapse: collapse'>\n";
143 echo "<tr><td>Database User</td><td><input type='text' name='user' value='".$_POST['user']."' size='20' /></td></tr>";
144 echo "<tr><td>Password</td><td><input name='passwd' type='password' value='".$_POST['passwd']."' /></td></tr>";
145 echo "<tr><td>Upload Script</td><td><input name='uploadfile' type='file' /></td></tr>";
146 echo "<tr><td> </td><td><input type='submit' class='inputsubmit' name='submit' value='Update' /></td></tr>";
151 echo "<center><span>Choose from Database update scripts in SQL folder. No Datase is updated without a script.</span></center>\n";
156 echo "</body></html>\n";