Skip to content

Commit dbab3a6

Browse files
committed
Fixed vcard edit
Removed file upload from form
1 parent 0155d96 commit dbab3a6

File tree

3 files changed

+136
-90
lines changed

3 files changed

+136
-90
lines changed

app/Http/Controllers/UserController.php

Lines changed: 98 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -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

resources/views/components/pageitems/vcard-form.blade.php

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,52 @@
22

33
<select style="display:none" name="button" class="form-control"><option class="button button-default email" value="vcard">Vcard</option></select>
44

5-
{{-- @php
6-
$vcard = new VCard($link_url);
5+
@php
6+
// Decode the JSON string to a PHP object
7+
$data = json_decode($link_url);
78
8-
$prefix = $vcard->getPrefix();
9-
$firstName = $vcard->getFirstName();
10-
$middleName = $vcard->getMiddleName();
11-
$lastName = $vcard->getLastName();
12-
$suffix = $vcard->getSuffix();
13-
$organization = $vcard->getOrganization();
14-
$title = $vcard->getTitle();
15-
$role = $vcard->getRole();
16-
$workUrl = $vcard->getUrl();
17-
$email = $vcard->getEmail();
18-
$workEmail = $vcard->getWorkEmail();
19-
$homePhone = $vcard->getHomePhone();
20-
$workPhone = $vcard->getWorkPhone();
21-
$cellPhone = $vcard->getCellPhone();
22-
$homeAddressLabel = $vcard->getHomeAddressLabel();
23-
$homeAddressStreet = $vcard->getHomeAddressStreet();
24-
$homeAddressCity = $vcard->getHomeAddressCity();
25-
$homeAddressState = $vcard->getHomeAddressRegion();
26-
$homeAddressZip = $vcard->getHomeAddressPostalCode();
27-
$homeAddressCountry = $vcard->getHomeAddressCountry();
28-
$workAddressLabel = $vcard->getWorkAddressLabel();
29-
$workAddressStreet = $vcard->getWorkAddressStreet();
30-
$workAddressCity = $vcard->getWorkAddressCity();
31-
$workAddressState = $vcard->getWorkAddressRegion();
32-
$workAddressZip = $vcard->getWorkAddressPostalCode();
33-
$workAddressCountry = $vcard->getWorkAddressCountry();
34-
@endphp --}}
9+
// Assign the values to the variables
10+
$prefix = $data->prefix;
11+
$firstName = $data->first_name;
12+
$middleName = $data->middle_name;
13+
$lastName = $data->last_name;
14+
$suffix = $data->suffix;
15+
$nickname = $data->nickname;
16+
$organization = $data->organization;
17+
$vtitle = $data->vtitle;
18+
$role = $data->role;
19+
$workUrl = $data->work_url;
20+
$email = $data->email;
21+
$workEmail = $data->work_email;
22+
$homePhone = $data->home_phone;
23+
$workPhone = $data->work_phone;
24+
$cellPhone = $data->cell_phone;
25+
$homeAddressLabel = $data->home_address_label;
26+
$homeAddressStreet = $data->home_address_street;
27+
$homeAddressCity = $data->home_address_city;
28+
$homeAddressState = $data->home_address_state;
29+
$homeAddressZip = $data->home_address_zip;
30+
$homeAddressCountry = $data->home_address_country;
31+
$workAddressLabel = $data->work_address_label;
32+
$workAddressStreet = $data->work_address_street;
33+
$workAddressCity = $data->work_address_city;
34+
$workAddressState = $data->work_address_state;
35+
$workAddressZip = $data->work_address_zip;
36+
$workAddressCountry = $data->work_address_country;
37+
38+
@endphp
3539

3640
<label for='title' class='form-label'>Custom Title</label>
3741
<input type='text' name='link_title' value='{{ $link_title }}' class='form-control' />
3842
<span class='small text-muted'>Leave blank for default title</span><br>
39-
{{$link_url}}
40-
<br><h5>Upload existing file</h5>
43+
44+
{{-- <br><h5>Upload existing file</h5>
4145
<div class="form-group col-lg-8">
4246
<label>Vcard</label>
4347
<input type="file" accept="text/vcard" class="form-control-file" name="vcard">
44-
</div>
48+
</div> --}}
4549

46-
<br><h4>Name</h4>
50+
<br><br><h4>Name</h4>
4751
<label for='prefix' class='form-label'>Prefix</label>
4852
<input type='text' name='prefix' value='{{$prefix ?? ''}}' class='form-control'/>
4953
<br>

resources/views/studio/links.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
@if(!empty($link->link) and $button->name != "vcard")
9191
<br /><a title='{{$link->link}}' href="{{ $link->link}}" target="_blank" class="ml-4 text-muted small">{{Str::limit($link->link, 75 )}}</a>
9292
@elseif(!empty($link->link) and $button->name == "vcard")
93-
<br /><a href="{{ url('vcard/'.$link->id) }}" target="_blank" class="ml-4 text-muted small">Download</a>
93+
<br /><a href="{{ url('vcard/'.$link->id) }}" target="_blank" class="ml-4 small">Download</a>
9494

9595
@endif
9696

0 commit comments

Comments
 (0)