Fixed company subdirs creation during upgrade and company addition.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 4 Dec 2008 14:20:40 +0000 (14:20 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 4 Dec 2008 14:20:40 +0000 (14:20 +0000)
CHANGELOG.txt
admin/create_coy.php
admin/db/maintenance_db.inc
update.html
update_db.php

index 37a23099e9e131bdcd2834affb3e6efc816dbce4..c9a1606ab0c8ecd7243c34d19122f1f6dfe87ea3 100644 (file)
@@ -19,6 +19,14 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+04-Dec-2008 Janusz Dobrowolski
+# Check write permissions and create per company subdirectory structure.
+$ /update.html
+  /update_db.php
+# Fixed index.php files in new company dirs.
+$ /admin/create_coy.php
+  /admin/db/maintenance_db.inc
+
 04-Dec-2008 Joe Hunt
 # [0000095] Inbalance double entry on Documents
 $ /gl/includes/db/gl_db_trans.inc
index 8324fa7d9d5a638789bbc1391df7914288db4ef9..50dcca0f7eac15fea79ecb8e5a63efde8d626539 100644 (file)
@@ -137,19 +137,10 @@ function handle_submit()
        {
                return false;
        }
-       $index = "<?php\nheader(\"Location: ../../index.php\");\n?>";
 
        if ($new)
        {
-           $cdir = $comp_path.'/'.$id;
-           @mkdir($cdir);
-           save_to_file($cdir.'/'.'index.php', 0, $index);
-
-           foreach($comp_subdirs as $dir)
-           {
-                       @mkdir($cdir.'/'.$dir);
-                       save_to_file($cdir.'/'.$dir.'/'.'index.php', 0, $index);
-           }
+               create_comp_dirs("$comp_path/$id", $comp_subdirs);
        }
        return true;
 }
index c40c4ef637aa77f58887b7d57924bab150c89b3e..21236b620589ecda6cdf139b36ddc0df9e898435 100644 (file)
@@ -632,5 +632,21 @@ function save_to_file($backupfile, $zip, $fileData)
     }
 }
 
-
+function create_comp_dirs($comp_path, $comp_subdirs)
+{
+               $index = "<?php\nheader(\"Location: ../index.php\");\n?>";
+           $cdir = $comp_path;
+           @mkdir($cdir);
+               $f = @fopen("$cdir/index.php", "wb");
+               @fwrite($f, $index);
+               @fclose($f);
+
+           foreach($comp_subdirs as $dir)
+           {
+                       @mkdir($cdir.'/'.$dir);
+                       $f = @fopen("$cdir/$dir/index.php", "wb");
+                       @fwrite($f, $index);
+                       @fclose($f);
+           }
+}
 ?>
\ No newline at end of file
index cc0bb64d2f8530852bd3e2d7e5ff045c516ce658..5a87aafd2b4da3c9d7e8c162163a5e47c1740291 100644 (file)
@@ -38,7 +38,7 @@ these files too. </li>
       <li>Upload all the new files.
       </li>
       <li>Restore the files mentioned in #1. Be <strong>careful</strong> with
-        <strong>config.db</strong>. Look into variances. There might be new variables in
+        <strong>config.php</strong>. Look into variances. There might be new variables in
 the new version. It might be easier to <em>manually change your former values in
 the new file</em>.
       </li>
@@ -53,7 +53,7 @@ password and choose the update script from the local harddisk.</li>
 do this, before entering FrontAccounting!
 Enter the database user and the password and choose the alter.sql
 script. &nbsp;Do the same for the alter2.sql script. If you have
-already updated release 2.0 Beta, you can just run the alter2.sql script.<br />You must also manuelly ensure that you have write permission to the new folder /company/0.<br /></strong><strong>There are no database changes during a major and minor release. Like from 2.0 to 2.0.1 - 2.0.5 .</strong></li>
+already updated release 2.0 Beta, you can just run the alter2.sql script.<br />You must also manuelly ensure that you have write permission to the new folder /company .<br /></strong><strong>There are no database changes during a major and minor release. Like from 2.0 to 2.0.1 - 2.0.5 .</strong></li>
 </ul>
 
 <p>&nbsp;</p>
index 26c14ee5fc1f4e5246c83de37dd812a8931fa128..4ebbbc7450cc003e339dca07b39741974e8e66f2 100644 (file)
@@ -9,6 +9,8 @@ $js .= get_js_set_focus("user");
 $image = $path_to_root."/themes/default/images/logo_frontaccounting.png";
 $title = "Update All Company Databases";
 
+$comp_subdirs = array('images', 'pdf_files', 'backup','js_cache');
+
 function get_js_png_fix()
 {
        $js = "<script type=\"text/javascript\">\n"
@@ -97,7 +99,17 @@ echo "<br>";
 
 if (isset($_POST["submit"]))
 {
-       if (!isset($_FILES['uploadfile']['tmp_name']) || !is_uploaded_file($_FILES['uploadfile']['tmp_name']))
+       $perms_ok = is_writable($path_to_root.'/company') && is_writable($path_to_root.'/company/0');
+       $checkdirs = $comp_subdirs;
+       foreach ($checkdirs as $dir) {
+               $perms_ok &= is_writable($path_to_root.'/company/0/'.$dir);
+       }
+
+       if (!$perms_ok) {
+               display_error("'System 'company' directory or any of its subdirectories 
+                       is not writable.<br> Change webserver access permissions to those 
+                       directories.");
+       } elseif (!isset($_FILES['uploadfile']['tmp_name']) || !is_uploaded_file($_FILES['uploadfile']['tmp_name']))
        {
                display_error("You must select an SQL script for update");;
        }
@@ -127,6 +139,11 @@ if (isset($_POST["submit"]))
                                                display_notification("Database has been updated for company: "
                                                        . $id . " " .  $conn['name']);
                                }
+                               $cdir = "$path_to_root/company/$id";
+                               if (!file_exists($cdir))
+                               {
+                                       create_comp_dirs($cdir, $comp_subdirs);
+                               }
                        }
                }
        }
@@ -135,7 +152,7 @@ if (!isset($_POST['passwd']))
        $_POST['passwd'] = "";
 if (!isset($_POST['user']))
        $_POST['user'] = "";
-
+       
 echo "<form enctype='multipart/form-data' method='post' action='".$_SERVER['PHP_SELF']."'>\n";
 
 echo "<table align='center' width='50%' cellpadding=3 border=1 bordercolor='#cccccc' style='border-collapse: collapse'>\n";