Ejemplo n.º 1
0
 function import($invoice_common, $download)
 {
     include PHPGW_SERVER_ROOT . "/property/inc/import/{$GLOBALS['phpgw_info']['user']['domain']}/{$invoice_common['conv_type']}";
     $invoice = new import_conv();
     $buffer = $invoice->import($invoice_common, $download);
     if ($download) {
         $header = $invoice->header;
         $import = $invoice->import;
         $buffer = array('table' => $buffer, 'header' => $header, 'import' => $import);
     }
     return $buffer;
 }
 function import($tsvfile, $conv_type, $private, $fcat_id)
 {
     if ($conv_type == 'none') {
         return False;
     }
     include PHPGW_APP_INC . '/import/' . $conv_type;
     if ($private == '') {
         $private = 'public';
     }
     $row = 0;
     $buffer = array();
     $contacts = new import_conv();
     $buffer = $contacts->import_start_file($buffer);
     if ($tsvfile['type'] == 'application/zip') {
         if (!@function_exists('zip_open')) {
             return False;
         }
         $fp = $this->unzip($tsvfile['tmp_name'], $contacts->type);
     } else {
         $fp = fopen($tsvfile['tmp_name'], 'r');
     }
     if ($contacts->type == 'csv') {
         while ($data = fgetcsv($fp, 8000, ',')) {
             $num = count($data);
             $row++;
             if ($row == 1) {
                 $header = $data;
                 /* Changed here to ignore the header, set to our array
                 			while(list($lhs,$rhs) = each($contacts->import))
                 			{
                 				$header[] = $lhs;
                 			}
                 			*/
             } else {
                 $buffer = $contacts->import_start_record($buffer);
                 for ($c = 0; $c < $num; $c++) {
                     //Send name/value pairs along with the buffer
                     if ($contacts->import[$header[$c]] != '' && $data[$c] != '') {
                         $buffer = $contacts->import_new_attrib($buffer, $contacts->import[$header[$c]], $data[$c]);
                     }
                 }
                 $buffer = $contacts->import_end_record($buffer, $private);
             }
         }
     } elseif ($contacts->type == 'ldif') {
         while ($data = fgets($fp, 8000)) {
             $url = '';
             list($name, $value, $extra) = split(':', $data);
             $name = strtolower($name);
             if (substr($name, 0, 2) == 'dn') {
                 $buffer = $contacts->import_start_record($buffer);
             }
             $test = trim($value);
             if ($name && !empty($test) && $extra) {
                 // Probable url string
                 $url = $test;
                 $value = $extra;
             } elseif ($name && empty($test) && $extra) {
                 // Probable multiline encoding
                 $newval = base64_decode(trim($extra));
                 $value = $newval;
                 //echo $name.':'.$value;
             }
             if ($name && $value) {
                 $test = split(',mail=', $value);
                 if ($test[1]) {
                     $name = 'mail';
                     $value = $test[1];
                 }
                 if ($url) {
                     $name = 'homeurl';
                     $value = $url . ':' . $value;
                 }
                 //echo '<br>'.$j.': '.$name.' => '.$value;
                 if ($contacts->import[$name] != '' && $value != '') {
                     $buffer = $contacts->import_new_attrib($buffer, $contacts->import[$name], $value);
                 }
             } else {
                 $buffer = $contacts->import_end_record($buffer, $private);
             }
         }
     } else {
         $needToCallEndRecord = 0;
         while ($data = fgets($fp, 8000)) {
             $data = trim($data);
             // RB 2001/05/07 added for Lotus Organizer
             while (substr($data, -1) == '=') {
                 // '=' at end-of-line --> line to be continued with next line
                 $data = substr($data, 0, -1) . trim(fgets($fp, 8000));
             }
             if (strstr($data, ';ENCODING=QUOTED-PRINTABLE')) {
                 // RB 2001/05/07 added for Lotus Organizer
                 $data = quoted_printable_decode(str_replace(';ENCODING=QUOTED-PRINTABLE', '', $data));
             }
             list($name, $value) = explode(':', $data, 2);
             // RB 2001/05/09 to allow ':' in Values (not only in URL's)
             if (strtolower(substr($name, 0, 5)) == 'begin') {
                 $buffer = $contacts->import_start_record($buffer);
                 $needToCallEndRecord = 1;
             }
             if ($name && $value) {
                 reset($contacts->import);
                 while (list($fname, $fvalue) = each($contacts->import)) {
                     if (strstr(strtolower($name), $contacts->import[$fname])) {
                         $buffer = $contacts->import_new_attrib($buffer, $name, $value);
                     }
                 }
             } else {
                 $buffer = $contacts->import_end_record($buffer);
                 $needToCallEndRecord = 0;
             }
         }
         if ($needToCallEndRecord) {
             $buffer = $contacts->import_end_record($buffer);
         }
     }
     fclose($fp);
     $buffer = $contacts->import_end_file($buffer, $private, $fcat_id);
     return $buffer;
 }
Ejemplo n.º 3
0
 function import($tsvfile, $conv_type, $private, $fcat_id)
 {
     include PHPGW_APP_INC . '/import/' . $conv_type;
     if ($private == '') {
         $private = 'public';
     }
     $row = 0;
     $buffer = array();
     $contacts = new import_conv();
     $buffer = $contacts->import_start_file($buffer);
     $fp = fopen($tsvfile, 'r');
     if ($contacts->type == 'csv') {
         while ($data = fgetcsv($fp, 8000, ',')) {
             $num = count($data);
             $row++;
             if ($row == 1) {
                 $header = $data;
                 /* Changed here to ignore the header, set to our array
                 			while(list($lhs,$rhs) = each($contacts->import))
                 			{
                 				$header[] = $lhs;
                 			}
                 			*/
             } else {
                 $buffer = $contacts->import_start_record($buffer);
                 for ($c = 0; $c < $num; $c++) {
                     //Send name/value pairs along with the buffer
                     if ($contacts->import[$header[$c]] != '' && $data[$c] != '') {
                         $buffer = $contacts->import_new_attrib($buffer, $contacts->import[$header[$c]], $data[$c]);
                     }
                 }
                 $buffer = $contacts->import_end_record($buffer, $private);
             }
         }
     } elseif ($contacts->type == 'ldif') {
         while ($data = fgets($fp, 8000)) {
             $url = "";
             list($name, $value, $extra) = preg_split('/:/', $data);
             if (substr($name, 0, 2) == 'dn') {
                 $buffer = $contacts->import_start_record($buffer);
             }
             $test = trim($value);
             if ($name && !empty($test) && $extra) {
                 // Probable url string
                 $url = $test;
                 $value = $extra;
             } elseif ($name && empty($test) && $extra) {
                 // Probable multiline encoding
                 $newval = base64_decode(trim($extra));
                 $value = $newval;
                 //echo $name.':'.$value;
             }
             if ($name && $value) {
                 $test = preg_split('/,mail=/', $value);
                 if ($test[1]) {
                     $name = "mail";
                     $value = $test[1];
                 }
                 if ($url) {
                     $name = "homeurl";
                     $value = $url . ':' . $value;
                 }
                 //echo '<br />'.$j.': '.$name.' => '.$value;
                 if ($contacts->import[$name] != '' && $value != '') {
                     $buffer = $contacts->import_new_attrib($buffer, $contacts->import[$name], $value);
                 }
             } else {
                 $buffer = $contacts->import_end_record($buffer, $private);
             }
         }
     } else {
         while ($data = fgets($fp, 8000)) {
             $data = trim($data);
             // RB 2001/05/07 added for Lotus Organizer
             while (substr($data, -1) == '=') {
                 // '=' at end-of-line --> line to be continued with next line
                 $data = substr($data, 0, -1) . trim(fgets($fp, 8000));
             }
             if (strstr($data, 'BEGIN:VCARD')) {
                 // added for p800 vcards: problem if vcard starts with "<![CDATA["
                 $data = strstr($data, 'BEGIN:VCARD');
             }
             list($name, $value) = explode(':', $data, 2);
             // RB 2001/05/09 to allow ':' in Values (not only in URL's)
             if (strtolower(substr($name, 0, 5)) == 'begin') {
                 $buffer = $contacts->import_start_record($buffer);
             } elseif (strtolower(substr($name, 0, 3)) == 'end') {
                 $buffer = $contacts->import_end_record($buffer);
             } elseif ($name && $value) {
                 reset($contacts->import);
                 while (list($fname, $fvalue) = each($contacts->import)) {
                     if (strstr(strtolower($name), $contacts->import[$fname])) {
                         $buffer = $contacts->import_new_attrib($buffer, $name, $value);
                     }
                 }
             }
         }
     }
     fclose($fp);
     /* Delete the temp file. */
     unlink($tsvfile);
     $buffer = $contacts->import_end_file($buffer, $private, $fcat_id);
     return $buffer;
 }