| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
// Check if we're in edit mode (client object exists and has a valid ID) |
| 8 |
$is_edit_mode = false; |
| 9 |
if (isset($client) && $client instanceof \EasyInvoice\Models\Client) { |
| 10 |
$client_id = $client->getId(); |
| 11 |
$is_edit_mode = ($client_id > 0); |
| 12 |
} |
| 13 |
|
| 14 |
$form_id = $is_edit_mode ? 'edit-client-form' : 'add-client-form'; |
| 15 |
$submit_text = $is_edit_mode ? __('Save Changes', 'easy-invoice') : __('Save Client', 'easy-invoice'); |
| 16 |
|
| 17 |
// Add unique prefixes to prevent ID conflicts |
| 18 |
$field_prefix = $is_edit_mode ? 'edit-' : 'add-'; |
| 19 |
?> |
| 20 |
|
| 21 |
<form id="<?php echo esc_attr($form_id); ?>"> |
| 22 |
<?php if ($is_edit_mode): ?> |
| 23 |
<input type="hidden" id="<?php echo $field_prefix; ?>client-id" name="client_id" value="<?php echo esc_attr($client->getId()); ?>"> |
| 24 |
<?php endif; ?> |
| 25 |
|
| 26 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6"> |
| 27 |
<div> |
| 28 |
<label for="<?php echo $field_prefix; ?>client-business-name" class="block text-sm font-medium text-gray-700"><?php _e('Business/Client Name', 'easy-invoice'); ?> *</label> |
| 29 |
<input type="text" id="<?php echo $field_prefix; ?>client-business-name" name="business_client_name" required |
| 30 |
value="<?php echo $is_edit_mode ? esc_attr($client->getBusinessClientName()) : ''; ?>" |
| 31 |
class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"> |
| 32 |
</div> |
| 33 |
<div> |
| 34 |
<label for="<?php echo $field_prefix; ?>client-email" class="block text-sm font-medium text-gray-700"><?php _e('Email', 'easy-invoice'); ?> *</label> |
| 35 |
<input type="email" id="<?php echo $field_prefix; ?>client-email" name="email" required |
| 36 |
value="<?php echo $is_edit_mode ? esc_attr($client->getEmail()) : ''; ?>" |
| 37 |
class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"> |
| 38 |
</div> |
| 39 |
<div> |
| 40 |
<label for="<?php echo $field_prefix; ?>client-phone" class="block text-sm font-medium text-gray-700"><?php _e('Phone', 'easy-invoice'); ?></label> |
| 41 |
<input type="text" id="<?php echo $field_prefix; ?>client-phone" name="phone" |
| 42 |
value="<?php echo $is_edit_mode ? esc_attr($client->getPhone()) : ''; ?>" |
| 43 |
class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"> |
| 44 |
</div> |
| 45 |
<div> |
| 46 |
<label for="<?php echo $field_prefix; ?>client-username" class="block text-sm font-medium text-gray-700"><?php _e('Username', 'easy-invoice'); ?> *</label> |
| 47 |
<input type="text" id="<?php echo $field_prefix; ?>client-username" name="username" required |
| 48 |
value="<?php echo $is_edit_mode ? esc_attr($client->getUsername()) : ''; ?>" |
| 49 |
class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"> |
| 50 |
</div> |
| 51 |
<div> |
| 52 |
<label for="<?php echo $field_prefix; ?>client-password" class="block text-sm font-medium text-gray-700"> |
| 53 |
<?php echo $is_edit_mode ? __('New Password', 'easy-invoice') : __('Password', 'easy-invoice') . ' *'; ?> |
| 54 |
</label> |
| 55 |
<div class="mt-1 relative"> |
| 56 |
<input type="password" id="<?php echo $field_prefix; ?>client-password" name="password" |
| 57 |
<?php echo $is_edit_mode ? '' : 'required'; ?> |
| 58 |
placeholder="<?php echo $is_edit_mode ? __('Leave blank to keep current password', 'easy-invoice') : ''; ?>" |
| 59 |
class="block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm pr-24"> |
| 60 |
<div class="absolute inset-y-0 right-0 pr-3 flex items-center space-x-2"> |
| 61 |
<button type="button" id="<?php echo $field_prefix; ?>generate-password" class="text-sm font-medium text-indigo-600 hover:text-indigo-500"><?php _e('Generate', 'easy-invoice'); ?></button> |
| 62 |
<button type="button" id="<?php echo $field_prefix; ?>show-password" class="text-gray-500 hover:text-gray-700"> |
| 63 |
<i class="fas fa-eye"></i> |
| 64 |
</button> |
| 65 |
</div> |
| 66 |
</div> |
| 67 |
</div> |
| 68 |
<div> |
| 69 |
<label for="<?php echo $field_prefix; ?>client-first-name" class="block text-sm font-medium text-gray-700"><?php _e('First Name', 'easy-invoice'); ?></label> |
| 70 |
<input type="text" id="<?php echo $field_prefix; ?>client-first-name" name="first_name" |
| 71 |
value="<?php echo $is_edit_mode ? esc_attr($client->getFirstName()) : ''; ?>" |
| 72 |
class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"> |
| 73 |
</div> |
| 74 |
<div> |
| 75 |
<label for="<?php echo $field_prefix; ?>client-last-name" class="block text-sm font-medium text-gray-700"><?php _e('Last Name', 'easy-invoice'); ?></label> |
| 76 |
<input type="text" id="<?php echo $field_prefix; ?>client-last-name" name="last_name" |
| 77 |
value="<?php echo $is_edit_mode ? esc_attr($client->getLastName()) : ''; ?>" |
| 78 |
class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"> |
| 79 |
</div> |
| 80 |
</div> |
| 81 |
|
| 82 |
<div class="mb-6"> |
| 83 |
<label for="<?php echo $field_prefix; ?>client-address" class="block text-sm font-medium text-gray-700"><?php _e('Address', 'easy-invoice'); ?></label> |
| 84 |
<textarea id="<?php echo $field_prefix; ?>client-address" name="address" rows="3" |
| 85 |
class="block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"><?php echo $is_edit_mode ? wp_kses_post($client->getAddress()) : ''; ?></textarea> |
| 86 |
</div> |
| 87 |
|
| 88 |
<div class="mb-6"> |
| 89 |
<label for="<?php echo $field_prefix; ?>client-extra-info" class="block text-sm font-medium text-gray-700"><?php _e('Extra Info', 'easy-invoice'); ?></label> |
| 90 |
<textarea id="<?php echo $field_prefix; ?>client-extra-info" name="extra_info" rows="2" |
| 91 |
class="block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"><?php echo $is_edit_mode ? wp_kses_post($client->getExtraInfo()) : ''; ?></textarea> |
| 92 |
</div> |
| 93 |
|
| 94 |
<div class="mb-6"> |
| 95 |
<label for="<?php echo $field_prefix; ?>client-website" class="block text-sm font-medium text-gray-700"><?php _e('Website', 'easy-invoice'); ?></label> |
| 96 |
<input type="url" id="<?php echo $field_prefix; ?>client-website" name="website" |
| 97 |
value="<?php echo $is_edit_mode ? esc_attr($client->getWebsite()) : ''; ?>" |
| 98 |
class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"> |
| 99 |
</div> |
| 100 |
|
| 101 |
<div class="mt-5 flex justify-end space-x-3"> |
| 102 |
<?php if ($is_edit_mode): ?> |
| 103 |
<a href="?page=easy-invoice-clients" class="bg-white py-2 px-4 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"> |
| 104 |
<?php _e('Cancel', 'easy-invoice'); ?> |
| 105 |
</a> |
| 106 |
<?php else: ?> |
| 107 |
<button type="button" id="<?php echo $field_prefix; ?>cancel-add-client" class="bg-white py-2 px-4 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"> |
| 108 |
<?php _e('Cancel', 'easy-invoice'); ?> |
| 109 |
</button> |
| 110 |
<?php endif; ?> |
| 111 |
<button type="submit" id="<?php echo $field_prefix; ?>save-client-btn" class="bg-indigo-600 py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"> |
| 112 |
<?php echo esc_html($submit_text); ?> |
| 113 |
</button> |
| 114 |
</div> |
| 115 |
</form> |