Fixed vcard edit

Removed file upload from form
This commit is contained in:
Julian Prieber 2023-03-28 15:12:01 +02:00
parent 0155d96381
commit dbab3a64ef
3 changed files with 138 additions and 92 deletions

View File

@ -258,7 +258,7 @@ class UserController extends Controller
$suffix = $request->input('suffix');
$nickname = $request->input('nickname');
$organization = $request->input('organization');
$title = $request->input('title');
$vtitle = $request->input('vtitle');
$role = $request->input('role');
$workUrl = $request->input('work_url');
$email = $request->input('email');
@ -279,33 +279,42 @@ class UserController extends Controller
$workAddressZip = $request->input('work_address_zip');
$workAddressCountry = $request->input('work_address_country');
// Create a new vCard instance
$vCard = new VCard();
// Create an array with all the input fields
$data = [
'prefix' => $request->input('prefix'),
'first_name' => $request->input('first_name'),
'middle_name' => $request->input('middle_name'),
'last_name' => $request->input('last_name'),
'suffix' => $request->input('suffix'),
'nickname' => $request->input('nickname'),
'organization' => $request->input('organization'),
'vtitle' => $request->input('vtitle'),
'role' => $request->input('role'),
'work_url' => $request->input('work_url'),
'email' => $request->input('email'),
'work_email' => $request->input('work_email'),
'home_phone' => $request->input('home_phone'),
'work_phone' => $request->input('work_phone'),
'cell_phone' => $request->input('cell_phone'),
'home_address_label' => $request->input('home_address_label'),
'home_address_street' => $request->input('home_address_street'),
'home_address_city' => $request->input('home_address_city'),
'home_address_state' => $request->input('home_address_state'),
'home_address_zip' => $request->input('home_address_zip'),
'home_address_country' => $request->input('home_address_country'),
'work_address_label' => $request->input('work_address_label'),
'work_address_street' => $request->input('work_address_street'),
'work_address_city' => $request->input('work_address_city'),
'work_address_state' => $request->input('work_address_state'),
'work_address_zip' => $request->input('work_address_zip'),
'work_address_country' => $request->input('work_address_country'),
];
// Set the personal information
$vCard->addName($lastName, $firstName, $middleName, $prefix, $suffix);
$vCard->addRole($role);
// Convert the array to JSON format
$json = json_encode($data);
// Set the organization information
$vCard->addCompany($organization);
$vCard->addJobtitle($title);
$vCard->addUrl($workUrl);
// Set the phone numbers
$vCard->addPhoneNumber($homePhone, 'HOME');
$vCard->addPhoneNumber($workPhone, 'WORK');
$vCard->addPhoneNumber($cellPhone, 'CELL');
// Set the email addresses
$vCard->addEmail($email, 'HOME');
$vCard->addEmail($workEmail, 'WORK');
// Set the addresses
$vCard->addAddress($homeAddressStreet, null, null, $homeAddressCity, $homeAddressState, $homeAddressZip, $homeAddressCountry, 'HOME', $homeAddressLabel);
$vCard->addAddress($workAddressStreet, null, null, $workAddressCity, $workAddressState, $workAddressZip, $workAddressCountry, 'WORK', $workAddressLabel);
// Generate the vCard file content
$LinkURL = $vCard->getOutput();
// Set the JSON as the variable $links->link, or null if the JSON is empty
$LinkURL = $json ? $json : null;
$OrigLink->update([
'link' => $LinkURL,
@ -383,33 +392,42 @@ class UserController extends Controller
$workAddressZip = $request->input('work_address_zip');
$workAddressCountry = $request->input('work_address_country');
// Create a new vCard instance
$vCard = new VCard();
// Create an array with all the input fields
$data = [
'prefix' => $request->input('prefix'),
'first_name' => $request->input('first_name'),
'middle_name' => $request->input('middle_name'),
'last_name' => $request->input('last_name'),
'suffix' => $request->input('suffix'),
'nickname' => $request->input('nickname'),
'organization' => $request->input('organization'),
'vtitle' => $request->input('vtitle'),
'role' => $request->input('role'),
'work_url' => $request->input('work_url'),
'email' => $request->input('email'),
'work_email' => $request->input('work_email'),
'home_phone' => $request->input('home_phone'),
'work_phone' => $request->input('work_phone'),
'cell_phone' => $request->input('cell_phone'),
'home_address_label' => $request->input('home_address_label'),
'home_address_street' => $request->input('home_address_street'),
'home_address_city' => $request->input('home_address_city'),
'home_address_state' => $request->input('home_address_state'),
'home_address_zip' => $request->input('home_address_zip'),
'home_address_country' => $request->input('home_address_country'),
'work_address_label' => $request->input('work_address_label'),
'work_address_street' => $request->input('work_address_street'),
'work_address_city' => $request->input('work_address_city'),
'work_address_state' => $request->input('work_address_state'),
'work_address_zip' => $request->input('work_address_zip'),
'work_address_country' => $request->input('work_address_country'),
];
// Set the personal information
$vCard->addName($lastName, $firstName, $middleName, $prefix, $suffix);
$vCard->addRole($role);
// Convert the array to JSON format
$json = json_encode($data);
// Set the organization information
$vCard->addCompany($organization);
$vCard->addJobtitle($vtitle);
$vCard->addUrl($workUrl);
// Set the phone numbers
$vCard->addPhoneNumber($homePhone, 'HOME');
$vCard->addPhoneNumber($workPhone, 'WORK');
$vCard->addPhoneNumber($cellPhone, 'CELL');
// Set the email addresses
$vCard->addEmail($email, 'HOME');
$vCard->addEmail($workEmail, 'WORK');
// Set the addresses
$vCard->addAddress($homeAddressStreet, null, null, $homeAddressCity, $homeAddressState, $homeAddressZip, $homeAddressCountry, 'HOME', $homeAddressLabel);
$vCard->addAddress($workAddressStreet, null, null, $workAddressCity, $workAddressState, $workAddressZip, $workAddressCountry, 'WORK', $workAddressLabel);
// Generate the vCard file content
$links->link = $vCard->getOutput();
// Set the JSON as the variable $links->link, or null if the JSON is empty
$links->link = $json ? $json : null;
$links->button_id = 96;
}else{
@ -487,14 +505,38 @@ class UserController extends Controller
// Find the link with the specified ID
$link = Link::findOrFail($linkId);
// Set the response headers to indicate that a VCard file should be downloaded
$headers = [
'Content-Type' => 'text/vcard',
'Content-Disposition' => 'attachment; filename="vcard.vcf"',
];
$json = $link->link;
// Decode the JSON to a PHP array
$data = json_decode($json, true);
// Create a new vCard object
$vcard = new VCard();
// Set the vCard properties from the $data array
$vcard->addName($data['last_name'], $data['first_name'], $data['middle_name'], $data['prefix'], $data['suffix']);
$vcard->addCompany($data['organization']);
$vcard->addJobtitle($data['vtitle']);
$vcard->addRole($data['role']);
$vcard->addEmail($data['email']);
$vcard->addPhoneNumber($data['home_phone'], 'HOME');
$vcard->addPhoneNumber($data['work_phone'], 'WORK');
$vcard->addPhoneNumber($data['cell_phone'], 'CELL');
$vcard->addAddress($data['home_address_street'], '', $data['home_address_city'], $data['home_address_state'], $data['home_address_zip'], $data['home_address_country'], 'HOME');
$vcard->addAddress($data['work_address_street'], '', $data['work_address_city'], $data['work_address_state'], $data['work_address_zip'], $data['work_address_country'], 'WORK');
// Generate the vCard file contents
$file_contents = $vcard->getOutput();
// Set the file headers for download
$headers = [
'Content-Type' => 'text/x-vcard',
'Content-Disposition' => 'attachment; filename="contact.vcf"'
];
// Return the file download response
return response()->make($file_contents, 200, $headers);
// Return the link's content as a downloadable file
return Response::make($link->link, 200, $headers);
}
//Show link, click number, up link in links page

View File

@ -2,48 +2,52 @@
<select style="display:none" name="button" class="form-control"><option class="button button-default email" value="vcard">Vcard</option></select>
{{-- @php
$vcard = new VCard($link_url);
@php
// Decode the JSON string to a PHP object
$data = json_decode($link_url);
$prefix = $vcard->getPrefix();
$firstName = $vcard->getFirstName();
$middleName = $vcard->getMiddleName();
$lastName = $vcard->getLastName();
$suffix = $vcard->getSuffix();
$organization = $vcard->getOrganization();
$title = $vcard->getTitle();
$role = $vcard->getRole();
$workUrl = $vcard->getUrl();
$email = $vcard->getEmail();
$workEmail = $vcard->getWorkEmail();
$homePhone = $vcard->getHomePhone();
$workPhone = $vcard->getWorkPhone();
$cellPhone = $vcard->getCellPhone();
$homeAddressLabel = $vcard->getHomeAddressLabel();
$homeAddressStreet = $vcard->getHomeAddressStreet();
$homeAddressCity = $vcard->getHomeAddressCity();
$homeAddressState = $vcard->getHomeAddressRegion();
$homeAddressZip = $vcard->getHomeAddressPostalCode();
$homeAddressCountry = $vcard->getHomeAddressCountry();
$workAddressLabel = $vcard->getWorkAddressLabel();
$workAddressStreet = $vcard->getWorkAddressStreet();
$workAddressCity = $vcard->getWorkAddressCity();
$workAddressState = $vcard->getWorkAddressRegion();
$workAddressZip = $vcard->getWorkAddressPostalCode();
$workAddressCountry = $vcard->getWorkAddressCountry();
@endphp --}}
// Assign the values to the variables
$prefix = $data->prefix;
$firstName = $data->first_name;
$middleName = $data->middle_name;
$lastName = $data->last_name;
$suffix = $data->suffix;
$nickname = $data->nickname;
$organization = $data->organization;
$vtitle = $data->vtitle;
$role = $data->role;
$workUrl = $data->work_url;
$email = $data->email;
$workEmail = $data->work_email;
$homePhone = $data->home_phone;
$workPhone = $data->work_phone;
$cellPhone = $data->cell_phone;
$homeAddressLabel = $data->home_address_label;
$homeAddressStreet = $data->home_address_street;
$homeAddressCity = $data->home_address_city;
$homeAddressState = $data->home_address_state;
$homeAddressZip = $data->home_address_zip;
$homeAddressCountry = $data->home_address_country;
$workAddressLabel = $data->work_address_label;
$workAddressStreet = $data->work_address_street;
$workAddressCity = $data->work_address_city;
$workAddressState = $data->work_address_state;
$workAddressZip = $data->work_address_zip;
$workAddressCountry = $data->work_address_country;
@endphp
<label for='title' class='form-label'>Custom Title</label>
<input type='text' name='link_title' value='{{ $link_title }}' class='form-control' />
<span class='small text-muted'>Leave blank for default title</span><br>
{{$link_url}}
<br><h5>Upload existing file</h5>
{{-- <br><h5>Upload existing file</h5>
<div class="form-group col-lg-8">
<label>Vcard</label>
<input type="file" accept="text/vcard" class="form-control-file" name="vcard">
</div>
</div> --}}
<br><h4>Name</h4>
<br><br><h4>Name</h4>
<label for='prefix' class='form-label'>Prefix</label>
<input type='text' name='prefix' value='{{$prefix ?? ''}}' class='form-control'/>
<br>

View File

@ -90,7 +90,7 @@ if (isset($_COOKIE['LinkCount'])) {
@if(!empty($link->link) and $button->name != "vcard")
<br /><a title='{{$link->link}}' href="{{ $link->link}}" target="_blank" class="ml-4 text-muted small">{{Str::limit($link->link, 75 )}}</a>
@elseif(!empty($link->link) and $button->name == "vcard")
<br /><a href="{{ url('vcard/'.$link->id) }}" target="_blank" class="ml-4 text-muted small">Download</a>
<br /><a href="{{ url('vcard/'.$link->id) }}" target="_blank" class="ml-4 small">Download</a>
@endif