PhpLabWare version 0.3 
/ -> import.php

1  <?php
2 
3  // import.php - imports delimited data into phplabware tables
4  // import.php - author: Nico Stuurman <nicost@sourceforge.net>
5 
6    /***************************************************************************
7    * This script imports data into phplabware tables *
8    * *
9    * Copyright (c) 2001 by Nico Stuurman *
10    * ------------------------------------------------------------------------ *
11    * This program is free software; you can redistribute it and/or modify it *
12    * under the terms of the GNU General Public License as published by the *
13    * Free Software Foundation; either version 2 of the License, or (at your *
14    * option) any later version. *
15    \**************************************************************************/
16 
17 
18  require('include.php');
19  require('includes/db_inc.php');
20  require('includes/general_inc.php');
21  require('includes/tablemanage_inc.php');
22  include ('includes/defines_inc.php');
23 
24  $post_vars='delimiter,delimiter_type,quote,quote_type,tableid,nrfields,pkey,pkeypolicy,skipfirstline,tmpfile,ownerid,localfile';
25  globalize_vars($post_vars, $HTTP_POST_VARS);
26 
27  $permissions=$USER['permissions'];
28  $httptitle.=' Import data';
29  printheader($httptitle,false,$jsfile);
30  $tmpdir=$system_settings['tmpdir'];
31 
32  if (!($permissions & $SUPER)) {
33          navbar($USER['permissions']);
34          echo "<h3 align='center'><b>Sorry, this page is not for you</B></h3>";
35          printfooter($db,$USER);
36          exit;
37  }
38 
39  navbar($USER['permissions']);
40 
41  ////
42  //
43  function move ($fromfile, $tofile) {
44     // guess this won't work on Windows
45     `mv '$fromfile' '$tofile'`;
46      // but this should
47      if (!filesize($tofile))
48        copy($fromfile,$tofile);
49      return filesize($tofile);
50  }
51 
52  function mymktime($datestring) {
53     global $system_settings;
54 
55     if ($system_settings['dateformat']==1) {
56        $month=strtok($datestring,'/');
57        $day=strtok('/');
58        $year=strtok('/');
59     }
60     elseif ($system_settings['dateformat']==2) {
61        $month=strtok($datestring,' ');
62        $day=strtok(' ');
63        $year=strtok(' ');
64     }
65     elseif ($system_settings['dateformat']>=3) {
66        $day=strtok($datestring,' ');
67        $month=strtok(' ');
68        $year=strtok(' ');
69     }
70     return mktime(0,0,0,$month,$day,$year);
71  }
72 
73  ////
74  // !Upload files and enters then into table files
75  // files should be called file[] in HTTP_POST_FILES
76  // filetitle in HTTP_POST_VARS will be inserted in the title field of table files
77  // returns id of last uploaded file upon succes, false otherwise
78  function import_file ($db,$tableid,$id,$columnid,$columnname,$tmpfileid,$system_settings)
79  {
80     if (!$tmpfileid)
81        return false;
82     $table=get_cell($db,'tableoftables','tablename','id',$tableid);
83     $real_tablename=get_cell($db,'tableoftables','real_tablename','id',$tableid);
84 
85     if (!($db && $table && $id)) {
86        echo "Error in code: $db, $table, or $id is not defined.<br>";
87        return false;
88     }
89     if (isset($tmpfileid) && !$filedir=$system_settings['filedir']) {
90        echo "<h3><i>Filedir</i> was not set. The file was not uploaded. Please contact your system administrator</h3>";
91        return false;
92     }
93     $r=$db->Execute("SELECT name,mime,type FROM tmpfiles WHERE id=$tmpfileid");
94     if (!$r->fields[0])
95        return false;
96     if (!$fileid=$db->GenID("files_id_seq"))
97        return false;
98     $originalname=$r->fields['name'];
99     $mime=$r->fields['type'];
100     $filestype=$r->fields['type'];
101     $filesdir=$system_settings['tmpdir'].'/phplabwaredump/files/';
102     $tmplocation=$filesdir.$tmpfileid.'_'.$originalname;
103     $size=filesize($tmplocation);
104     $title=$$originalname;
105     if (!$title)
106        $title='NULL';
107     else
108        $title="'$title'";
109     $type=$filestype;
110     if (move($tmplocation,"$filedir/$fileid".'_'."$originalname")) {
111        $query="INSERT INTO files (id,filename,mime,size,title,tablesfk,ftableid,ftablecolumnid,type) VALUES ($fileid,'$originalname','$mime','$size',$title,'$tableid',$id,'$columnid','$filestype')";
112        $db->Execute($query);
113     }
114     else
115        $fileid=false;
116     return $fileid;
117  }
118 
119  ////
120  // !returns variable delimiter, based on delimiter_type (a POST variable)
121  function get_delimiter ($delimiter,$delimiter_type) {
122     if ($delimiter)
123        return $delimiter;
124     if ($delimiter_type=='space')
125        $delimiter=" ";
126     elseif ($delimiter_type=='tab')
127        $delimiter="\t";
128     elseif ($delimiter_type=='comma')
129        $delimiter=',';
130     elseif ($delimiter_type=='semi-colon')
131        $delimiter=';';
132     return $delimiter;
133  }
134   
135  ////
136  // !returns the string 'quote', based on quote_type (a POST variable)
137  function get_quote ($quote,$quote_type) {
138     if ($$quote)
139        return $$quote;
140     if ($quote_type=='doublequote')
141        $quote="\"";
142     elseif ($quote_type=='singlequote')
143        $quote="'";
144     elseif ($quote_type=='none')
145        $quote=false;
146     return $quote;
147  }
148 
149  ////
150  // !corrects problems in input data (Removes quotes around text,
151  // checks for ints and floats, quotes text
152  function check_input ($tableinfo, &$fields, $to_fields, $field_types, $field_datatypes, $nrfields)
153  {
154     global $db;
155 
156     for ($i=0;$i<$nrfields;$i++) {
157        if ($fields[$i]) {
158           // strip quotes semi-inteligently Can not use trim when php <4.1
159           if ($fields[$i]{0}==$fields[$i]{strlen($fields[$i])-1} &&
160               ($fields[$i]{0}=="\"" || $fields[$i]{0}=="'") )
161              $fields[$i]=substr($fields[$i],1,-1);
162           if ($field_datatypes[$i]=='pulldown') {
163              // see if we have this value already, otherwise make a new entry in the type table....
164               // &nbsp; is used as a place holder in output of phplabware. Unset the value if found
165               if ($fields[$i]=="&nbsp;")
166                  unset ($fields[$i]);
167               else {
168                  $Allfields=getvalues($db,$tableinfo,$to_fields[$i]);
169                  $rtemp=$db->Execute("SELECT id FROM {$Allfields[0]['ass_t']} WHERE typeshort='{$fields[$i]}'");
170                  if ($rtemp && $rtemp->fields[0]) {
171                     $fields[$i]=$rtemp->fields[0];
172                  }
173                  else { // insert this new value in the type table:
174                     $typeid=$db->GenId($Allfields[0]['ass_t'].'_id_seq');
175                     unset($rtemp);
176                     $rtemp=$db->Execute("INSERT INTO {$Allfields[0]['ass_t']} (id,type,typeshort,sortkey) VALUES ($typeid,'{$fields[$i]}','{$fields[$i]}','0')");
177                     if ($rtemp && $rtemp->fields[0]) {
178                        $fields[$i]=$rtemp->fields[0];
179                     }
180                  }
181               }
182           }
183           // for mpulldowns we have a problem since we do not have the new id yet
184 
185           if ($field_types[$i]=='int'){
186              $fields[$i]=(int)$fields[$i];
187           }
188           elseif($field_types[$i]=='id')
189              $fields[$i]=(int)$fields[$i];
190           elseif($field_types[$i]=='float')
191              $fields[$i]=(float)$fields[$i];
192           else
193              $fields[$i]=addslashes($fields[$i]);
194        }
195     }
196     //return $fields;
197  }
198            
199  ////
200  // !in quoted lines, empty fields are (sometimes) not quoted
201  // we try to deal nicely with those here
202  function check_line(&$line,$quote,$delimiter) {
203     if ($quote) {
204        // delimiters without quotes can be a problem, so add quotes to them
205        $newlength=1;
206        $length=0;
207        while ($newlength!=$length) {
208           $length=strlen($line);
209           $line=str_replace($quote.$delimiter.$delimiter,$quote.$delimiter.$quote.$quote.$delimiter,$line);
210           $newlength=strlen($line);
211        }
212        $newlength=1;
213        $length=0;
214        while ($newlength!=$length) {
215           $length=strlen($line);
216           $line=str_replace($delimiter.$delimiter.$quote,$delimiter.$quote.$quote.$delimiter.$quote,$line);
217           $newlength=strlen($line);
218        }
219        $line=substr($line,1,-1);
220     }
221  }
222 
223 
224  // do the final parsing (part 3)
225  if ($HTTP_POST_VARS['assign']=='Import Data') {
226     // set longer time-out
227     ini_set('max_execution_time','0');
228     // get description table name
229     $tableinfo=new tableinfo($db,false,$tableid);
230     $desc=$tableinfo->desname;
231     $table=$tableinfo->realname;
232     $table_label=$tableinfo->name;
233 
234     // Columns with datatype 'sequence' are going to be automatically updated:
235     // Here we query for them
236     $rseq=$db->Execute("SELECT columnname FROM $desc WHERE datatype='sequence'");
237 
238     if ($table_custom)
239        $table_link="$table_custom?".SID;
240     else
241        $table_link="general.php?tablename=$table_label"."&".SID;
242 
243     // fill the tmp table with file related data
244     if ($localfile) {
245         $dumpdir='phplabwaredump';
246         $filename=$dumpdir.'/dumpcontent.txt';
247         // read in table file and put into temp table
248         $tablefile=$dumpdir.'/files.txt';
249         $ft=fopen("$tmpdir/$tablefile",'r');
250         $columnnames=explode("\t",$firstline);
251         if ($ft) {
252            $firstline=chop(fgets($ft,1000000));
253            $columns=explode("\t",$firstline);
254            // create the table for temp file data
255            $db->Execute("CREATE TEMPORARY TABLE tmpfiles (
256                          id int UNIQUE NOT NULL,
257                          name TEXT,
258                          mime TEXT,
259                          size TEXT,
260                          type TEXT)");
261            // and file with data from file
262            $rs=$db->Execute("SELECT * FROM tmpfiles");
263            while (!feof($ft)) {
264               $line=chop(fgets($ft,1000000));
265               $columnvalues=explode("\t",$line);
266               foreach ($columns as $columnname) {
267                  list($t,$value)=each($columnvalues);
268                  $row[$columnname]=$value;
269               }
270               if ($line)
271                  $db->Execute($db->GetInsertSQL(&$rs,$row));
272           }
273        }
274     }
275 
276     // find out to which columns each parsed file text will be assigned to
277     // Array $to_fields contains the target column ids,
278     // Array $to_types contains the target column types
279     for ($i=0;$i<$nrfields;$i++) {
280        $the_field=$HTTP_POST_VARS["fields_$i"];
281        if (isset($the_field) && $the_field && $the_field!="") {
282           $to_fields[$i]=get_cell($db,$desc,'columnname','id',$the_field);
283           if ($to_fields[$i]=='id')
284              $id_chosen=true;
285           $to_types[$i]=get_cell($db,$desc,'type','id',$the_field);
286           $to_datatypes[$i]=get_cell($db,$desc,'datatype','id',$the_field);
287           // type checking and cleanup for database upload
288           // since we can have int(11) etc...
289           if ($to_datatypes[$i]=='file'){
290              // this has type int, but its value changed, so set to_type to text
291              $to_types[$i]='text';
292           }
293           elseif ($to_datatypes[$i]=='date'){
294              // this has type int (wrong!), set to_type to text
295              $to_types[$i]='text';
296           }
297           elseif (substr($to_types[$i],0,3)=='int'){
298              $to_types[$i]='int';
299              $fields[$i]=(int)$fields[$i];
300           }
301           // and float8...
302           elseif(substr($to_types[$i],0,5)=='float') {
303              $to_types[$i]='float';
304              $fields[$i]=(float)$fields[$i];
305           }
306           else
307              $fields[$i]=addslashes($fields[$i]);
308        }
309     }
310     // sanity check:
311     $freq_array=array_count_values($to_fields);
312     if (sizeof($freq_array) < sizeof($to_fields)) {
313         $error_string="<h3 align='center'>Some columns in the database were selected more than once. Please correct this and try again.</h3>";
314         $HTTP_POST_VARS['dataupload']='Continue';
315     }
316     // do the database upload
317     else {
318        $delimiter=get_delimiter($delimiter,$delimiter_type);
319        $quote=get_quote($quote,$quote_type);
320        $fh=fopen("$tmpdir/$tmpfile",'r');
321        if ($fh) {
322           $access=$system_settings['access'];
323           $lastmoddate=time();
324           $lastmodby=$USER['id'];
325           if ($skipfirstline=='yes')
326              $line=chop(fgets($fh,1000000));
327           // fgets should not need second parameter, but my php version does...
328           while ($line=chop(fgets($fh,1000000))) {
329              check_line($line,$quote,$delimiter);
330              
331              //$fields=check_input (explode($quote.$delimiter.$quote,$line),$to_types,$nrfields);
332              $fields=explode($quote.$delimiter.$quote,$line);
333              check_input ($tableinfo,$fields,$to_fields,$to_types,$to_datatypes,$nrfields);
334              $worthit=false;
335              unset($recordid);
336              // if there is a column being used as primary key, we do an SQL
337              // UPDATE, otherwise an insert
338              if (isset($pkey) && $pkey!="") {
339                 // check if we already had such a record
340                 $r=$db->Execute("SELECT id FROM $table WHERE $to_fields[$pkey]='$fields[$pkey]'");
341                 $recordid=$r->fields[0];
342              }
343              if (isset($recordid) && ($pkeypolicy=='overwrite' || $pkeypolicy=='onlyupdate')) {
344                 $query="UPDATE $table SET ";
345                 // import data from file into SQL statement
346                 for ($i=0; $i<$nrfields;$i++) {
347                    if ($to_fields[$i] && $to_datatypes[$i]!='file') {
348                       $worthit=true;
349                       $query.="$to_fields[$i]='$fields[$i]',";
350                    }
351                 }
352                 while ($rseq && !$rseq->EOF) {
353                    $rmax=$db->Execute("SELECT max(".$rseq->fields[0].") FROM $table");
354                    $vmax=$rmax->fields[0]+1;
355                    $query.=$rseq->fields[0]."='$vmax',";
356                    $rseq->MoveNext();
357                 }
358                 $rseq->MoveFirst();
359                 if ($worthit) {
360                    // strip last comma
361                    // $query.=" WHERE $to_fields[$pkey]='$fields[$pkey]'";
362                    // only the first record that matched will be modified
363                    // when doing an update we leave access and owner untouched
364                    $query.=" lastmoddate='$lastmoddate', lastmodby='$lastmodby' WHERE $to_fields[$pkey]='$fields[$pkey]'";
365                    if ($r=$db->Execute($query)) {
366                        $modified++;
367                        for ($i=0; $nrfields;$i++) {
368                           if ($to_datatypes[$i]=='file') {
369                              $fileids=explode(',',$fields[$i]);
370                              foreach ($fileids as $fileid)
371                           import_file ($db,$tableid,$recordid,$HTTP_POST_VARS["fields_$i"],$to_fields[$i],$fileid,$system_settings);
372                            }
373                        }
374                     }
375                 }
376              }
377 
378              // if there is no primary key set, we simply INSERT a new record
379              //if ( !(isset($pkey) || isset($recordid)) ) {
380           elseif ($pkeypolicy!='onlyupdate') {
381                 $query_start="INSERT INTO $table (";
382                 $query_end=" VALUES (";
383                 $newid=false;
384                 for ($i=0;$i<$nrfields;$i++) {
385                    if ($fields[$i] && $to_fields[$i] && $to_datatypes[$i]!='file') {
386                       // when importing a date field we'll have to suppress insertion of the date field or the SQL query will fail
387                       if ($to_fields[$i]=='date') {
388                          $newdate=true;
389                          $fields[$i]=mymktime($fields[$i]);
390                       }
391                       $worthit=true;
392                       $query_start.="$to_fields[$i],";
393                       $query_end.="'$fields[$i]',";
394                       if ($to_fields[$i]=="id")
395                          $newid=$fields[$i];
396                    }
397                 }
398                 while ($rseq && !$rseq->EOF) {
399                    $rmax=$db->Execute("SELECT max(".$rseq->fields[0].") FROM $table");
400                    $vmax=$rmax->fields[0]+1;
401                    $query_start.=$rseq->fields[0].",";
402                    $query_end.="'$vmax',";
403                    $rseq->MoveNext();
404                 }
405                 $rseq->MoveFirst();
406                 // delete last commas and combine into SQL INSERT query
407                 if ($worthit) {
408                    if (!$newid) {
409                       $id=$db->GenID($table."_id_seq");
410                       if ($id && $newdate)
411                          $query="$query_start id,access,lastmoddate,lastmodby,ownerid) $query_end '$id','$access','$lastmoddate','$lastmodby','$ownerid')";
412                       else
413                          $query="$query_start id,access,date,lastmoddate,lastmodby,ownerid) $query_end '$id','$access','$lastmoddate','$lastmoddate','$lastmodby','$ownerid')";
414                    }
415                    else {
416                       // let's make sure the 'next' id will be higher
417                       if ($newid)
418                          while ($id<$newid)
419                             $id=$db->GenID($table.'_id_seq');
420                       // check whether this id was used
421                       if (get_cell($db,$table,'id','id',$newid))
422                          $duplicateid++;
423                       if ($newdate)
424                       $query="$query_start access,lastmoddate,lastmodby,ownerid) $query_end '$access','$lastmoddate','$lastmodby','$ownerid')";
425                       else
426                          $query="$query_start access,date,lastmoddate,lastmodby,ownerid) $query_end '$access','$lastmoddate','$lastmoddate','$lastmodby','$ownerid')";
427                    }
428                    if ($r=$db->Execute($query)) {
429                        $inserted++;
430                        for ($i=0; $i<$nrfields;$i++) {
431                           if ($to_datatypes[$i]=='file') {
432                              $fileids=explode(',',$fields[$i]);
433                              foreach ($fileids as $fileid)
434                                 import_file ($db,$tableid,$id,$HTTP_POST_VARS["fields_$i"],$to_fields[$i],$fileid,$system_settings);
435                            }
436                        }
437                    }
438                 }
439              }
440           }
441           
442           // communicate results
443           if (!isset($inserted))
444              $inserted=0;
445           if (!isset($modified))
446              $modified=0;
447           if (!isset($duplicateid))
448              $duplicateid=0;
449           if ($inserted==1)
450              $inserted_text='record was';
451           else
452              $inserted_text='records were';
453           if ($modified==1)
454              $modified_text='record was';
455           else
456              $modified_text='records were';
457           if ($duplicateid==1)
458              $duplicate_text='record was';
459           else
460              $duplicate_text='records were';
461           echo "<h3 align='center'>$inserted $inserted_text inserted, and $modified $modified_text modified in Database <a href='$table_link'>$table_label</a></h3>";
462           if ($duplicateid)
463              echo "<h3 align='center'>$duplicateid $duplicate_text rejected because their ids have already been used.</h3>\n";
464 
465           fclose($fh);
466           unlink ("$tmpdir/$tmpfile");
467           printfooter();
468        }
469        exit();
470     }
471  }
472 
473 
474  // interpret uploaded file and get information for final parsing (part 2)
475  if ($HTTP_POST_VARS['dataupload']=='Continue') {
476     if ($error_string)
477        echo $error_string;
478     $filename=$HTTP_POST_FILES['datafile']['name'];
479     $delimiter=get_delimiter($delimiter,$delimiter_type);
480     $quote=get_quote($quote,$quote_type);
481     if ($delimiter && $tableid && $ownerid && ($filename || $tmpfile || $localfile) ) {
482        if (!$system_settings['filedir']) {
483           echo "<h3><i>Filedir</i> was not set. Please correct this first in <i>setup</i></h3>\n";
484           printfooter();
485           exit();
486        }
487        $tmpdir=$system_settings['tmpdir'];
488        if ($tmpfile || $localfile || move_uploaded_file($HTTP_POST_FILES['datafile']['tmp_name'],"$tmpdir/$filename")) {
489           if ($tmpfile)
490              $filename=$tmpfile;
491           // lcoalfiles can also have associated files packaged with them
492           if ($localfile) {
493               $dumpdir='phplabwaredump';
494               $filename=$dumpdir.'/dumpcontent.txt';
495           }
496           $fh=fopen("$tmpdir/$filename",'r');
497           if ($fh) {
498              $firstline=chop(fgets($fh,1000000));
499              check_line($firstline,$quote,$delimiter);
500              $fields=explode($quote.$delimiter.$quote,$firstline);
501              $secondline=chop(fgets($fh,1000000));
502              if ($quote) {
503                 check_line($secondline,$quote,$delimiter);
504              }
505              $fields2=explode($quote.$delimiter.$quote,$secondline);
506              $nrfields=sizeof($fields);
507              fclose($fh);
508           }
509           $tablename=get_cell($db,'tableoftables','tablename','id',$tableid);
510           echo "<h3 align='center'>Import Data(2): Assign fields to Columns of table <i>$tablename</i></h3>\n";
511           echo "<form method='post' id='procesdata' enctype='multipart/form-data' ";
512           $dbstring=$PHP_SELF;
513           echo "action='$dbstring?".SID."'>\n";
514           echo "<input type='hidden' name='tmpfile' value='$filename'>\n";
515    if ($localfile)
516              echo "<input type='hidden' name='localfile' value='true'>\n";
517           echo "<input type='hidden' name='tableid' value='$tableid'>\n";
518           echo "<input type='hidden' name='nrfields' value='$nrfields'>\n";
519           echo "<input type='hidden' name='delimiter_type' value='$delimiter_type'>\n";
520           echo "<input type='hidden' name='delimiter' value='$delimiter'>\n";
521           echo "<input type='hidden' name='quote_type' value='$quote_type'>\n";
522           echo "<input type='hidden' name='ownerid' value='$ownerid'>\n";
523           echo "<table align='center'>\n<tr>\n";
524           echo "<th>First line:</th>\n";
525           for($i=0;$i<$nrfields;$i++)
526              echo " <td align='center'>$fields[$i]</td>\n";
527           echo "</tr>\n";
528           echo "<th>Second line:</th>\n";
529           for($i=0;$i<$nrfields;$i++)
530              echo " <td align='center'>$fields2[$i]</td>\n";
531           echo "</tr>\n";
532           echo "<tr>\n <th>Assign to Column:</th>\n";
533           $desc=get_cell($db,'tableoftables','table_desc_name','id',$tableid);
534           $r=$db->Execute("SELECT label,id FROM $desc WHERE (display_record='Y' OR display_table='Y' OR columnname='id') AND datatype<>'sequence' ORDER BY sortkey");
535           for($i=0;$i<$nrfields;$i++) {
536              $menu=$r->GetMenu2("fields_$i");
537              echo " <td align='center'>$menu</td>\n";
538              $r->Move(0);
539           }
540           echo "</tr>\n<tr>\n <th>Primary Key:</th>\n";
541           for($i=0;$i<$nrfields;$i++)
542              echo " <td align='center'><input type='radio' name='pkey' value='$i'></td>\n";
543           echo " <td align='center'><input type='radio' name='pkey' value='' checked> (none)</td>\n";
544           echo "</tr>\n";
545           $colspan=$nrfields+2;
546           echo "</table>\n";
547 
548           echo "<br><table align='center'>\n";
549 
550           echo "<tr><th>Update/Overwrite policy</th>\n";
551           echo "<td colspan=3><input type='radio' name='pkeypolicy' value='overwrite'> Overwrite when primary key matches, otherwise add the new record</input><br>\n";
552           echo "<input type='radio' name='pkeypolicy' value='onlyupdate'> Overwrite when primary key matches, otherwise ignore the new record</input><br>\n";
553           echo "<input type='radio' name='pkeypolicy' value='skip' checked> Skip when primary key matches, otherwise add the new record</input></td></tr>\n";
554 
555           echo "<tr><th>Skip first line?</th>\n";
556           echo "<td><input type='radio' name='skipfirstline' value='yes'> Yes</input></td>\n";
557           echo "<td><input type='radio' name='skipfirstline' value='no' checked> no</input></td></tr>\n";
558 
559          // echo "<br><br>\n<table align='center>\n";
560          
561           echo "<tr><td colspan=5 align='center'><input type='submit' name='assign' value='Import Data'></input></td></tr>\n";
562           echo "</table>\n</form>\n<br>\n";
563 
564        }
565        else {
566           echo "<h3>Problems with file upload, please try again.</h3>\n";
567        }
568        printfooter();
569        exit();
570     }
571     else
572        $string="Please enter all fields";
573  }
574 
575 
576  // Page with file to be uploaded, delimiter, table, and owner (Part 1)
577  echo "<h3 align='center'>$string</h3>";
578  echo "<h3 align='center'>Import Data(1): Select File, delimiter, and Table to import data into</h3>\n";
579  echo "<form method='post' id='importdata' enctype='multipart/form-data' ";
580  $dbstring=$PHP_SELF;echo "action='$dbstring?".SID."'>\n";
581  echo "<table align='center' border='0' cellpadding='5' cellspacing='0'>\n";
582 
583  echo "<tr>\n";
584  echo "<th>File with data</th>\n";
585  echo "<th>Delimiter</th>\n";
586  echo "<th>Quotes around field</th>\n";
587  echo "<th>Table</th>\n";
588  echo "<th>Assign new records to:</th>\n";
589  echo "</tr>\n";
590 
591  echo "<tr><td><input type='file' name='datafile' value='' ><br>\n";
592  $localfile=$system_settings['tmpdir'].'/phplabwaredump/dumpcontent.txt';
593  if (file_exists($localfile))
594     echo "<b>Or:</b><input type='checkbox' name='localfile'> use $localfile";
595  echo "</td>\n";
596  echo "<td align='center'> <table><tr>
597     <td><input type='radio' name='delimiter_type' value='comma' checked> comma</td>
598     <td><input type='radio' name='delimiter_type' value='tab'> tab</td>
599     <td><input type='radio' name='delimiter_type' value='space'> space</td></tr>
600     <tr><td><input type='radio' name='delimiter_type' value='semi-colon'> ;</td>
601     <td colspan=2><input type='radio' name='delimiter_type' value='other'> other:
602     <input type='text' name='delimiter' value='$delimiter' size='2'></td></tr>
603     </table></td>\n";
604  echo "<td align='center'> <table><tr>
605     <td><input type='radio' name='quote_type' value='doublequote'> \"&nbsp;</td>
606     <td><input type='radio' name='quote_type' value='singlequote'> '&nbsp;</td>
607     <td><input type='radio' name='quote_type' value='none' checked> none</td></tr>
608     <tr><td>&nbsp;</td></tr>
609     </table></td>\n";
610  $query = "SELECT label,id FROM tableoftables where id>1000 ORDER BY sortkey";
611  $r=$db->Execute($query);
612  if ($r)
613     $menu=$r->GetMenu2("tableid",$tableid);
614  echo "<td>$menu</td>\n";
615  $query = "SELECT login,id FROM users";
616  $r=$db->Execute($query);
617  if ($r)
618     $menu2=$r->GetMenu2("ownerid",$ownerid);
619  echo "<td>$menu2</td>\n";
620  echo "</tr>\n";
621 
622  echo "<tr><td colspan='4' align='center'><input type='submit' name='dataupload' value='Continue'></td></tr>\n";
623 
624  echo "</table>\n";
625  echo "</form>\n";
626  printfooter($db,$USER);
627  ?>


Generated: Sun Oct 5 21:17:35 2003 SourceForge Logo Generated by PHPXref 0.2