Added hook at the bottom named addressbook_bottom for import plugin.
[squirrelmail.git] / src / addressbook_csvimport.php
index 2fa1af87f44e75baba790f94de0b7c8f0e11ce1f..1dc1f1e29b52d5060bd6300c8628c19f4d3a41de 100644 (file)
@@ -1,30 +1,16 @@
 <?php
-/*
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU Library General Public License for more details.
- *
- *  You should have received a copy of the GNU Library General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-  /****************************************************************
-   **  
-   **  csvimport.php
-   **                  copyright 2000 Lewis Bergman - lbergman@abi.tconline.net
+  /**
+   **  addressbook_csvimport.php
+   **  
+   **  Copyright (c) 1999-2000 The SquirrelMail development team
+   **  Licensed under the GNU GPL. For full terms see the file COPYING.
    **                  
    **  Import csv files for address book
    **      This takes a comma delimited file uploaded from addressbook.php
    **      and allows the user to rearrange the field order to better
    **      fit the address book. A subset of data is manipulated to save time.
    **
-   ****************************************************************/
+   **/
 
 
    session_start();
@@ -45,7 +31,8 @@
       include("../functions/strings.php");
 
    include("../src/load_prefs.php");
-
+   
+/** commented out until a way to deal with file rnaming is figured out.
    displayPageHeader($color, "None");
 
    if (!isset($smusercsv) || $smusercsv == "none") {
       echo "</body></html>\n";
       exit;
    }
+**/
 
    /** 
     ** Script-wide vars. Used all over the place or something you might want to change later.
     ** $example -->Sets how many rows of user data the script will use to play with before final write.
     **   $abook ---->Setup the addressbook functions for Pallo's Addressbook.
+    **   $tabindex ->A starting value for the loop to assign a tabindex value for the generated text input fields.
+    **               As long as this value is greater than the number of static submit buttons all should work fine.
     **/
+   $tabindex = 10;
    $example = 6;
    $abook = addressbook_init(true, true);
 
@@ -81,7 +72,7 @@
    if($flag <= 1) {                                      // If first run of script, setup the filename to copy
       $tempfilename = ($username . (time()+2592000));
       $nameholder = $tempfilename;
-      if(copy($smusercsv, "$data_dir$tempfilename")) { // Set up variable to use in printing status
+      if(copy($smusercsv, "$attachment_dir$tempfilename")) {   // Set up variable to use in printing status
          $goodcopy = true;
       } else {
          $goodcopy = false;
           echo "   </TR>\n";
           echo "   <TR>\n";
           echo "      <TD>";
-          if(!$goodcopy && $flag == 0) {                       // print correct status of file copying
+          if(!$goodcopy && $flag == 0) {                                   // print correct status of file copying
              echo _("Failed to create working copy, Please try again.");
           } else {
              echo _("Created working copy, continuing with process...");
        echo "       <TD>", _("Arrange your data to fit the 5 address book fields. "), _("Do this by inserting the data's field number under the field for which you wish it to be included into the address book. "), _("For example: fields 5, 6, and 7 need to go into the info field 5. "), _("The boxes under field 5 would contain 5, 6, and 7 in seperate boxes. "), "</TD>\n";
        echo "   <TR>\n";
        echo "       <TD>", _("Submit Your reorganized data."), "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp", "\n";
-       echo "           <INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Submit\">", "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp\n";
+       echo "           <INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Submit\" TABINDEX=\"1\">", "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp\n";
        echo "           <INPUT TYPE=\"hidden\" NAME=\"flag\" VALUE=\"2\">\n";
        echo "           <INPUT TYPE=\"hidden\" NAME=\"nameholder\" VALUE=$nameholder>\n";
        echo "           <INPUT TYPE=\"hidden\" NAME=\"email\" VALUE=$email>\n";
        echo "           ", _("Erase entries and re-enter field numbers."), "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp", "\n";
-       echo "           <INPUT TYPE=reset VALUE=reset>\n";
+       echo "           <INPUT TYPE=reset VALUE=reset TABINDEX=\"2\">\n";
        echo "       </TD>\n";
        echo "   </TR>\n";
        echo "   <TR>\n";
        echo "       <TD>", _("View full set of imported records in their new format."), "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp\n";
-       echo "           <INPUT TYPE=\"submit\" NAME=\"all\" VALUE=\"Show all Records\">\n";
+       echo "           <INPUT TYPE=\"submit\" NAME=\"all\" VALUE=\"Show all Records\" TABINDEX=\"3\">\n";
        echo "           <INPUT TYPE=\"hidden\" NAME=\"submit\" VALUE=\"Submit\">";     
        echo "       </TD>";
        echo "   </TR>\n";
        echo "   <TR>\n";
        echo "       <TD>", _("Final approval. ");
        echo "           ", _("After reviewing the rearranged data for accuracy, click \"Finish\"."), "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp\n";
-       echo "           <INPUT TYPE=\"submit\" NAME=\"finish\" VALUE=\"Finish\">\n";
+       echo "           <INPUT TYPE=\"submit\" NAME=\"finish\" VALUE=\"Finish\" TABINDEX=\"4\">\n";
        echo "       </TD>";
        echo "   </TR>\n";
        echo "</TABLE>\n";
 
    // open the correct filename to work with
        if($flag <= 1) {                            // before submit
-          $fp = fopen("$data_dir$tempfilename", "r");
+          $fp = fopen("$attachment_dir$tempfilename", "r");
        } elseif($flag >= 2) {                      // after submit
-          $fp = fopen("$data_dir$nameholder", "r");
+          $fp = fopen("$attachment_dir$nameholder", "r");
        }
 
        echo "<CENTER><TABLE WIDTH=\"95%\" FRAME=\"void\" CELLSPACING=\"1\">\n";        // user's data table
    // This loop sets up a table of the data they uploaded to save time while the user rearranges it.
        $row = 0;
        do {
-          ($data = fgetcsv($fp, 4096));                
-          $cols = count($data);
+          ($data = fgetcsv($fp, 4096));
+          if(count($data) >= 5) {
+             $cols = count($data);
+          } else {
+             $cols = 5;
+          }            
+//        $cols = count($data);
           $row++;
           
           if($flag == 0 && !$finish) {                            // Table header on initial import
                echo "         <TD>", _("Field Number: "), "0", "<BR>\n";      // number the fields so they know what to put where
                reset($nickname);
                while(list($k,$v)=each($nickname)) {                           // print out the text boxes for this var
-                  echo"             <INPUT TYPE=text NAME=nickname[$k] MAXLENGTH=2 SIZE=2 VALUE=\"".$v."\"><BR>\n";
+                  echo"             <INPUT TYPE=text NAME=nickname[$k] MAXLENGTH=2 SIZE=2 TABINDEX=\"".$tabindex."\" VALUE=\"".$v."\"><BR>\n";
+                  $tabindex++;
                }
                echo "         </TD>\n";
                echo "         <TD>", _("Field Number: "), "1", "<BR>\n";      // number the fields so they know what to put where
                reset($firstname);
                while(list($k,$v)=each($firstname)) {                          // print out the text boxes for this var
-                  echo"             <INPUT TYPE=text NAME=firstname[$k] MAXLENGTH=2 SIZE=2 VALUE=\"".$v."\"><BR>\n";
+                  echo"             <INPUT TYPE=text NAME=firstname[$k] MAXLENGTH=2 SIZE=2 TABINDEX=\"".$tabindex."\" VALUE=\"".$v."\"><BR>\n";
+                  $tabindex++;
                }
                echo "         </TD>\n";
                echo "         <TD>", _("Field Number: "), "2", "<BR>\n";      // number the fields so they know what to put where
                reset($lastname);
                while(list($k,$v)=each($lastname)) {                           // print out the text boxes for this var
-                  echo"             <INPUT TYPE=text NAME=lastname[$k] MAXLENGTH=2 SIZE=2 VALUE=\"".$v."\"><BR>\n";
+                  echo"             <INPUT TYPE=text NAME=lastname[$k] MAXLENGTH=2 SIZE=2 TABINDEX=\"".$tabindex."\" VALUE=\"".$v."\"><BR>\n";
+                  $tabindex++;
                }
                echo "         </TD>\n";                                       // email isn't an array so no loop needed
                echo "         <TD>", _("Field Number: "), "3", "<BR>\n";      // number the fields so they know what to put where
-               echo "             <INPUT TYPE=text NAME=email MAXLENGTH=\"2\" SIZE=\"2\" VALUE=$email>\n";
+               echo "             <INPUT TYPE=text NAME=email MAXLENGTH=\"2\" SIZE=\"2\" TABINDEX=\"".$tabindex."\" VALUE=$email>\n";
+               $tabindex++;
                echo "         </TD>\n";
                echo "         <TD>", _("Field Number: "), "4", "<BR>\n";      // number the fields so they know what to put where
                reset($label);
                while(list($k,$v)=each($label)) {                               // print out the text boxes for this var
-                  echo"             <INPUT TYPE=text NAME=label[$k] MAXLENGTH=2 SIZE=2 VALUE=\"".$v."\"><BR>\n";
+                  echo"             <INPUT TYPE=text NAME=label[$k] MAXLENGTH=2 SIZE=2 TABINDEX=\"".$tabindex."\" VALUE=\"".$v."\"><BR>\n";
+                  $tabindex++;
                }
                echo "         </TD>\n";
 
 
    // Clean up after ourselves.
    if($finish) {
-      unlink ("$data_dir$tempfilename");
+      unlink ("$attachment_dir$tempfilename");
    }
    
 ?>