From 91b0c37877959acaafb91e5335ebcd351e6ad4b1 Mon Sep 17 00:00:00 2001 From: Miles Lott Date: Mon, 5 Feb 2001 05:38:26 +0000 Subject: [PATCH] Move parsecard's functions to functions.inc.php and basically remove call to parsecard.php --- addressbook/inc/functions.inc.php | 236 +++++++++++++++++++++++ addressbook/parsecard.php | 299 ++---------------------------- addressbook/vcardin.php | 46 +++-- 3 files changed, 273 insertions(+), 308 deletions(-) diff --git a/addressbook/inc/functions.inc.php b/addressbook/inc/functions.inc.php index b994cf9027..89eac71129 100755 --- a/addressbook/inc/functions.inc.php +++ b/addressbook/inc/functions.inc.php @@ -370,4 +370,240 @@ $t->pparse("out","form"); } //end form function + function parsevcard($filename,$access) + { + global $phpgw; + global $phpgw_info; + + $vcard = fopen($filename, "r"); + if (!$vcard) // Make sure we have a file to read. + { + fclose($vcard); + return FALSE; + } + + // Keep running through this to support vcards + // with multiple entries. + while (!feof($vcard)) + { + if(!empty($varray)) + unset($varray); + + // Make sure our file is a vcard. + // I should deal with empty line at the + // begining of the file. Those will fail here. + $vline = fgets($vcard,20); + $vline = strtolower($vline); + if(strcmp("begin:vcard", substr($vline, 0, strlen("begin:vcard")) ) != 0) + { + fclose($vcard); + return FALSE; + } + + // Write the vcard into an array. + // You can have multiple vcards in one file. + // I only deal with halve of that. :) + // It will only return values from the 1st vcard. + $varray[0] = "begin"; + $varray[1] = "vcard"; + $i=2; + while(!feof($vcard) && strcmp("end:vcard", strtolower(substr($vline, 0, strlen("end:vcard"))) ) !=0 ) + { + $vline = fgets($vcard,4096); + // Check for folded lines and escaped colons '\:' + $la = explode(":", $vline); + + if (count($la) > 1) + { + $varray[$i] = strtolower($la[0]); + $i++; + + for($j=1;$j<=count($la);$j++) + { + $varray[$i] .= $la[$j]; + } + $i++; + } else { // This is the continuation of a folded line. + $varray[$i-1] .= $la[0]; + } + } + + fillab($varray,$access); // Add this entry to the addressbook before + // moving on to the next one. + + } // while(!feof($vcard)) + + fclose($vcard); + return TRUE; + } + + + function fillab($varray,$access) + { + global $phpgw; + global $phpgw_info; + + $i=0; + while($i < count($varray)) // incremented by 2 + { + $k = explode(";",$varray[$i]); // Key + $v = explode(";",$varray[$i+1]); // Values + for($h=0;$h 1) + { + $notes .= $v[0] . "\n"; + for($j=1;$jadd($phpgw_info["user"]["account_id"],$fields); + } + ?> diff --git a/addressbook/parsecard.php b/addressbook/parsecard.php index a62972b788..852b6abe9d 100644 --- a/addressbook/parsecard.php +++ b/addressbook/parsecard.php @@ -13,295 +13,18 @@ /* $Id$ */ - $phpgw_info["flags"] = array("currentapp" => "addressbook", "enable_addressbook_class" => True, "noheader" => True, "nonavbar" => True); + $phpgw_info["flags"] = array("currentapp" => "addressbook", + "enable_contact_class" => True, + "noheader" => True, "nonavbar" => True); include("../header.inc.php"); + if($access == "group") + $access = $n_groups; + //echo $access . "
"; -// parse a vcard and fill the address book with it. -function parsevcard($filename,$access) -{ - global $phpgw; - global $phpgw_info; - - $vcard = fopen($filename, "r"); - if (!$vcard) // Make sure we have a file to read. - { - fclose($vcard); - return FALSE; - } - - - // Keep runnig through this to support vcards - // with multiple entries. - while (!feof($vcard)) - { - if(!empty($varray)) - unset($varray); - - // Make sure our file is a vcard. - // I should deal with empty line at the - // begining of the file. Those will fail here. - $vline = fgets($vcard,20); - $vline = strtolower($vline); - if(strcmp("begin:vcard", substr($vline, 0, strlen("begin:vcard")) ) != 0) - { - fclose($vcard); - return FALSE; - } - - // Write the vcard into an array. - // You can have multiple vcards in one file. - // I only deal with halve of that. :) - // It will only return values from the 1st vcard. - $varray[0] = "begin"; - $varray[1] = "vcard"; - $i=2; - while(!feof($vcard) && strcmp("end:vcard", strtolower(substr($vline, 0, strlen("end:vcard"))) ) !=0 ) - { - $vline = fgets($vcard,4096); - // Check for folded lines and escaped colons '\:' - $la = explode(":", $vline); - - -//if (ereg("\:",$vline)) -//{ -// // Oh, no.... Horrible disaster.... -// // Yell. -// echo "

"; -// echo "DANGER WILL ROBINSON!!!!!!!!!!
"; -// echo "This just broke. Really.
"; -// echo "

"; -//} - - - // DANGER Will Robinson!!!!!!! - // I don't check for escaped colons here. - // '\:' These would cause horrible disaster.. - // Fix this situation. Check if the last character - // of the line is \ If it is, you've found one. - if (count($la) > 1) - { - $varray[$i] = strtolower($la[0]); - $i++; - - for($j=1;$j<=count($la);$j++) - { - $varray[$i] .= $la[$j]; - } - $i++; - } - else // This is the continuation of a folded line. - { - $varray[$i-1] .= $la[0]; - } - } - - fillab($varray,$access); // Add this entry to the addressbook before - // moving on to the next one. - - } // while(!feof($vcard)) - - fclose($vcard); - return TRUE; -} - - -function fillab($varray,$access) -{ - global $phpgw; - global $phpgw_info; - - $i=0; - while($i < count($varray)) // incremented by 2 - { - $k = explode(";",$varray[$i]); // Key - $v = explode(";",$varray[$i+1]); // Values - for($h=0;$h 1) - { - $notes .= $v[0] . "\n"; - for($j=1;$j"; -//echo "First Name: " . $firstname . "
"; -//echo "Last Name: " . $lastname . "
"; -//echo "Home Phone: " .$hphone . "
"; -//echo "Cell Phone: " . $mphone . "
"; -//echo "Work Phone: " . $wphone . "
"; -//echo "Fax: " . $fax . "
"; -//echo "Email: " . $email . "
"; -//echo "Organization: " . $company . "
"; -//echo "Address:
"; -//echo $address2 . "
" . $street ."
"; -//echo $city . " " . $state . " " . $zip . "
"; -//echo "Notes: " . $notes . "
"; - - - if($phpgw_info["apps"]["timetrack"]["enabled"]) { - $sql = "insert into addressbook (ab_owner,ab_access,ab_firstname,ab_lastname,ab_title,ab_email," - . "ab_hphone,ab_wphone,ab_fax,ab_pager,ab_mphone,ab_ophone,ab_street,ab_address2,ab_city," - . "ab_state,ab_zip,ab_bday," - . "ab_notes,ab_company_id) values ('" . $phpgw_info["user"]["account_id"] . "','$access','" - . addslashes($firstname). "','" - . addslashes($lastname) . "','" - . addslashes($title) . "','" - . addslashes($email) . "','" - . addslashes($hphone) . "','" - . addslashes($wphone) . "','" - . addslashes($fax) . "','" - . addslashes($pager) . "','" - . addslashes($mphone) . "','" - . addslashes($ophone) . "','" - . addslashes($street) . "','" - . addslashes($address2) . "','" - . addslashes($city) . "','" - . addslashes($state) . "','" - . addslashes($zip) . "','" - . addslashes($bday) . "','" - . addslashes($notes) . "','" - . addslashes($company). "')"; - } else { - $sql = "insert into addressbook (ab_owner,ab_access,ab_firstname,ab_lastname,ab_title,ab_email," - . "ab_hphone,ab_wphone,ab_fax,ab_pager,ab_mphone,ab_ophone,ab_street,ab_address2,ab_city," - . "ab_state,ab_zip,ab_bday," - . "ab_notes,ab_company) values ('" . $phpgw_info["user"]["account_id"] . "','$access','" - . addslashes($firstname). "','" - . addslashes($lastname) . "','" - . addslashes($title) . "','" - . addslashes($email) . "','" - . addslashes($hphone) . "','" - . addslashes($wphone) . "','" - . addslashes($fax) . "','" - . addslashes($pager) . "','" - . addslashes($mphone) . "','" - . addslashes($ophone) . "','" - . addslashes($street) . "','" - . addslashes($address2) . "','" - . addslashes($city) . "','" - . addslashes($state) . "','" - . addslashes($zip) . "','" - . addslashes($bday) . "','" - . addslashes($notes) . "','" - . addslashes($company). "')"; - } - $phpgw->db->query($sql); -} - -if($access == "group") - $access = $n_groups; -//echo $access . "
"; - -parsevcard($filename,$access); -// Delete the temp file. -unlink($filename); -unlink($filename . ".info"); -Header("Location: " . $phpgw->link($phpgw_info["server"]["webserver_url"] . "/addressbook/", - "cd=14")); - -// End of php. + parsevcard($filename,$access); + // Delete the temp file. + unlink($filename); + unlink($filename . ".info"); + Header("Location: " . $phpgw->link($phpgw_info["server"]["webserver_url"] . "/addressbook/", "cd=14")); ?> diff --git a/addressbook/vcardin.php b/addressbook/vcardin.php index 0df5f53d12..cab372ca87 100644 --- a/addressbook/vcardin.php +++ b/addressbook/vcardin.php @@ -30,28 +30,34 @@ if ($action == "Load Vcard"){ $uploaddir = $phpgw_info["server"]["temp_dir"] . $sep . $phpgw_info["user"]["sessionid"] . $sep; if ($action == "Load Vcard") { - if($uploadedfile == "none" || $uploadedfile == "") - { - Header("Location: " . $phpgw->link($phpgw_info["server"]["webserver_url"] . + if($uploadedfile == "none" || $uploadedfile == "") { + Header("Location: " . $phpgw->link($phpgw_info["server"]["webserver_url"] . "/addressbook/vcardin.php","action=GetFile")); - } - else - { - srand((double)microtime()*1000000); - $random_number = rand(100000000,999999999); - $newfilename = md5("$uploadedfile, $uploadedfile_name, " . $phpgw_info["user"]["sessionid"] - . time() . getenv("REMOTE_ADDR") . $random_number ); + } else { + srand((double)microtime()*1000000); + $random_number = rand(100000000,999999999); + $newfilename = md5("$uploadedfile, $uploadedfile_name, " . $phpgw_info["user"]["sessionid"] + . time() . getenv("REMOTE_ADDR") . $random_number ); - copy($uploadedfile, $uploaddir . $newfilename); - $ftp = fopen($uploaddir . $newfilename . ".info","w"); - fputs($ftp,"$uploadedfile_type\n$uploadedfile_name\n"); - fclose($ftp); - // This has to be non-interactive in case of a multi-entry vcard. - Header("Location: " . $phpgw->link($phpgw_info["server"]["webserver_url"] . - "/addressbook/parsecard.php","filename=" . $uploaddir . $newfilename . - "&access=" . $access . "&n_groups=" . $phpgw->accounts->array_to_string($access,$n_groups) - )); - } + copy($uploadedfile, $uploaddir . $newfilename); + $ftp = fopen($uploaddir . $newfilename . ".info","w"); + fputs($ftp,"$uploadedfile_type\n$uploadedfile_name\n"); + fclose($ftp); + + // This has to be non-interactive in case of a multi-entry vcard. + $filename = $uploaddir . $newfilename; + $n_groups = $phpgw->accounts->array_to_string($access,$n_groups); + + if($access == "group") + $access = $n_groups; + //echo $access . "
"; + + parsevcard($filename,$access); + // Delete the temp file. + unlink($filename); + unlink($filename . ".info"); + Header("Location: " . $phpgw->link($phpgw_info["server"]["webserver_url"] . "/addressbook/", "cd=14")); + } } if (! file_exists($phpgw_info["server"]["temp_dir"] . $sep . $phpgw_info["user"]["sessionid"]))