@@ -258,7 +258,7 @@ public function saveLink(request $request)
258258 $ suffix = $ request ->input ('suffix ' );
259259 $ nickname = $ request ->input ('nickname ' );
260260 $ organization = $ request ->input ('organization ' );
261- $ title = $ request ->input ('title ' );
261+ $ vtitle = $ request ->input ('vtitle ' );
262262 $ role = $ request ->input ('role ' );
263263 $ workUrl = $ request ->input ('work_url ' );
264264 $ email = $ request ->input ('email ' );
@@ -279,33 +279,42 @@ public function saveLink(request $request)
279279 $ workAddressZip = $ request ->input ('work_address_zip ' );
280280 $ workAddressCountry = $ request ->input ('work_address_country ' );
281281
282- // Create a new vCard instance
283- $ vCard = new VCard ();
282+ // Create an array with all the input fields
283+ $ data = [
284+ 'prefix ' => $ request ->input ('prefix ' ),
285+ 'first_name ' => $ request ->input ('first_name ' ),
286+ 'middle_name ' => $ request ->input ('middle_name ' ),
287+ 'last_name ' => $ request ->input ('last_name ' ),
288+ 'suffix ' => $ request ->input ('suffix ' ),
289+ 'nickname ' => $ request ->input ('nickname ' ),
290+ 'organization ' => $ request ->input ('organization ' ),
291+ 'vtitle ' => $ request ->input ('vtitle ' ),
292+ 'role ' => $ request ->input ('role ' ),
293+ 'work_url ' => $ request ->input ('work_url ' ),
294+ 'email ' => $ request ->input ('email ' ),
295+ 'work_email ' => $ request ->input ('work_email ' ),
296+ 'home_phone ' => $ request ->input ('home_phone ' ),
297+ 'work_phone ' => $ request ->input ('work_phone ' ),
298+ 'cell_phone ' => $ request ->input ('cell_phone ' ),
299+ 'home_address_label ' => $ request ->input ('home_address_label ' ),
300+ 'home_address_street ' => $ request ->input ('home_address_street ' ),
301+ 'home_address_city ' => $ request ->input ('home_address_city ' ),
302+ 'home_address_state ' => $ request ->input ('home_address_state ' ),
303+ 'home_address_zip ' => $ request ->input ('home_address_zip ' ),
304+ 'home_address_country ' => $ request ->input ('home_address_country ' ),
305+ 'work_address_label ' => $ request ->input ('work_address_label ' ),
306+ 'work_address_street ' => $ request ->input ('work_address_street ' ),
307+ 'work_address_city ' => $ request ->input ('work_address_city ' ),
308+ 'work_address_state ' => $ request ->input ('work_address_state ' ),
309+ 'work_address_zip ' => $ request ->input ('work_address_zip ' ),
310+ 'work_address_country ' => $ request ->input ('work_address_country ' ),
311+ ];
284312
285- // Set the personal information
286- $ vCard ->addName ($ lastName , $ firstName , $ middleName , $ prefix , $ suffix );
287- $ vCard ->addRole ($ role );
313+ // Convert the array to JSON format
314+ $ json = json_encode ($ data );
288315
289- // Set the organization information
290- $ vCard ->addCompany ($ organization );
291- $ vCard ->addJobtitle ($ title );
292- $ vCard ->addUrl ($ workUrl );
293-
294- // Set the phone numbers
295- $ vCard ->addPhoneNumber ($ homePhone , 'HOME ' );
296- $ vCard ->addPhoneNumber ($ workPhone , 'WORK ' );
297- $ vCard ->addPhoneNumber ($ cellPhone , 'CELL ' );
298-
299- // Set the email addresses
300- $ vCard ->addEmail ($ email , 'HOME ' );
301- $ vCard ->addEmail ($ workEmail , 'WORK ' );
302-
303- // Set the addresses
304- $ vCard ->addAddress ($ homeAddressStreet , null , null , $ homeAddressCity , $ homeAddressState , $ homeAddressZip , $ homeAddressCountry , 'HOME ' , $ homeAddressLabel );
305- $ vCard ->addAddress ($ workAddressStreet , null , null , $ workAddressCity , $ workAddressState , $ workAddressZip , $ workAddressCountry , 'WORK ' , $ workAddressLabel );
306-
307- // Generate the vCard file content
308- $ LinkURL = $ vCard ->getOutput ();
316+ // Set the JSON as the variable $links->link, or null if the JSON is empty
317+ $ LinkURL = $ json ? $ json : null ;
309318
310319 $ OrigLink ->update ([
311320 'link ' => $ LinkURL ,
@@ -383,33 +392,42 @@ public function saveLink(request $request)
383392 $ workAddressZip = $ request ->input ('work_address_zip ' );
384393 $ workAddressCountry = $ request ->input ('work_address_country ' );
385394
386- // Create a new vCard instance
387- $ vCard = new VCard ();
388-
389- // Set the personal information
390- $ vCard ->addName ($ lastName , $ firstName , $ middleName , $ prefix , $ suffix );
391- $ vCard ->addRole ($ role );
392-
393- // Set the organization information
394- $ vCard ->addCompany ($ organization );
395- $ vCard ->addJobtitle ($ vtitle );
396- $ vCard ->addUrl ($ workUrl );
397-
398- // Set the phone numbers
399- $ vCard ->addPhoneNumber ($ homePhone , 'HOME ' );
400- $ vCard ->addPhoneNumber ($ workPhone , 'WORK ' );
401- $ vCard ->addPhoneNumber ($ cellPhone , 'CELL ' );
395+ // Create an array with all the input fields
396+ $ data = [
397+ 'prefix ' => $ request ->input ('prefix ' ),
398+ 'first_name ' => $ request ->input ('first_name ' ),
399+ 'middle_name ' => $ request ->input ('middle_name ' ),
400+ 'last_name ' => $ request ->input ('last_name ' ),
401+ 'suffix ' => $ request ->input ('suffix ' ),
402+ 'nickname ' => $ request ->input ('nickname ' ),
403+ 'organization ' => $ request ->input ('organization ' ),
404+ 'vtitle ' => $ request ->input ('vtitle ' ),
405+ 'role ' => $ request ->input ('role ' ),
406+ 'work_url ' => $ request ->input ('work_url ' ),
407+ 'email ' => $ request ->input ('email ' ),
408+ 'work_email ' => $ request ->input ('work_email ' ),
409+ 'home_phone ' => $ request ->input ('home_phone ' ),
410+ 'work_phone ' => $ request ->input ('work_phone ' ),
411+ 'cell_phone ' => $ request ->input ('cell_phone ' ),
412+ 'home_address_label ' => $ request ->input ('home_address_label ' ),
413+ 'home_address_street ' => $ request ->input ('home_address_street ' ),
414+ 'home_address_city ' => $ request ->input ('home_address_city ' ),
415+ 'home_address_state ' => $ request ->input ('home_address_state ' ),
416+ 'home_address_zip ' => $ request ->input ('home_address_zip ' ),
417+ 'home_address_country ' => $ request ->input ('home_address_country ' ),
418+ 'work_address_label ' => $ request ->input ('work_address_label ' ),
419+ 'work_address_street ' => $ request ->input ('work_address_street ' ),
420+ 'work_address_city ' => $ request ->input ('work_address_city ' ),
421+ 'work_address_state ' => $ request ->input ('work_address_state ' ),
422+ 'work_address_zip ' => $ request ->input ('work_address_zip ' ),
423+ 'work_address_country ' => $ request ->input ('work_address_country ' ),
424+ ];
402425
403- // Set the email addresses
404- $ vCard ->addEmail ($ email , 'HOME ' );
405- $ vCard ->addEmail ($ workEmail , 'WORK ' );
426+ // Convert the array to JSON format
427+ $ json = json_encode ($ data );
406428
407- // Set the addresses
408- $ vCard ->addAddress ($ homeAddressStreet , null , null , $ homeAddressCity , $ homeAddressState , $ homeAddressZip , $ homeAddressCountry , 'HOME ' , $ homeAddressLabel );
409- $ vCard ->addAddress ($ workAddressStreet , null , null , $ workAddressCity , $ workAddressState , $ workAddressZip , $ workAddressCountry , 'WORK ' , $ workAddressLabel );
410-
411- // Generate the vCard file content
412- $ links ->link = $ vCard ->getOutput ();
429+ // Set the JSON as the variable $links->link, or null if the JSON is empty
430+ $ links ->link = $ json ? $ json : null ;
413431
414432 $ links ->button_id = 96 ;
415433 }else {
@@ -487,14 +505,38 @@ public function vcard(request $request)
487505 // Find the link with the specified ID
488506 $ link = Link::findOrFail ($ linkId );
489507
490- // Set the response headers to indicate that a VCard file should be downloaded
508+ $ json = $ link ->link ;
509+
510+ // Decode the JSON to a PHP array
511+ $ data = json_decode ($ json , true );
512+
513+ // Create a new vCard object
514+ $ vcard = new VCard ();
515+
516+ // Set the vCard properties from the $data array
517+ $ vcard ->addName ($ data ['last_name ' ], $ data ['first_name ' ], $ data ['middle_name ' ], $ data ['prefix ' ], $ data ['suffix ' ]);
518+ $ vcard ->addCompany ($ data ['organization ' ]);
519+ $ vcard ->addJobtitle ($ data ['vtitle ' ]);
520+ $ vcard ->addRole ($ data ['role ' ]);
521+ $ vcard ->addEmail ($ data ['email ' ]);
522+ $ vcard ->addPhoneNumber ($ data ['home_phone ' ], 'HOME ' );
523+ $ vcard ->addPhoneNumber ($ data ['work_phone ' ], 'WORK ' );
524+ $ vcard ->addPhoneNumber ($ data ['cell_phone ' ], 'CELL ' );
525+ $ vcard ->addAddress ($ data ['home_address_street ' ], '' , $ data ['home_address_city ' ], $ data ['home_address_state ' ], $ data ['home_address_zip ' ], $ data ['home_address_country ' ], 'HOME ' );
526+ $ vcard ->addAddress ($ data ['work_address_street ' ], '' , $ data ['work_address_city ' ], $ data ['work_address_state ' ], $ data ['work_address_zip ' ], $ data ['work_address_country ' ], 'WORK ' );
527+
528+ // Generate the vCard file contents
529+ $ file_contents = $ vcard ->getOutput ();
530+
531+ // Set the file headers for download
491532 $ headers = [
492- 'Content-Type ' => 'text/vcard ' ,
493- 'Content-Disposition ' => 'attachment; filename="vcard .vcf" ' ,
533+ 'Content-Type ' => 'text/x- vcard ' ,
534+ 'Content-Disposition ' => 'attachment; filename="contact .vcf" '
494535 ];
536+
537+ // Return the file download response
538+ return response ()->make ($ file_contents , 200 , $ headers );
495539
496- // Return the link's content as a downloadable file
497- return Response::make ($ link ->link , 200 , $ headers );
498540 }
499541
500542 //Show link, click number, up link in links page
0 commit comments