| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! $is_crm_activated && ! $is_hrm_activated ) { |
| 4 |
return; |
| 5 |
} |
| 6 |
|
| 7 |
$page = '?page=erp-tools&tab=import&action=download_sample'; |
| 8 |
$nonce = 'erp-emport-export-sample-nonce'; |
| 9 |
$csv_sample_url = wp_nonce_url( $page, $nonce ); |
| 10 |
|
| 11 |
$users = []; |
| 12 |
$life_stages = []; |
| 13 |
$groups = []; |
| 14 |
|
| 15 |
if ( $is_crm_activated ) { |
| 16 |
$life_stages = erp_crm_get_life_stages_dropdown_raw(); |
| 17 |
$crm_users = erp_crm_get_crm_user(); |
| 18 |
|
| 19 |
foreach ( $crm_users as $user ) { |
| 20 |
$users[ $user->ID ] = $user->display_name . ' <' . $user->user_email . '>'; |
| 21 |
} |
| 22 |
|
| 23 |
$contact_groups = erp_crm_get_contact_groups( [ 'number' => '-1' ] ); |
| 24 |
|
| 25 |
$groups = ['' => __( '— Select Group —', 'erp' )]; |
| 26 |
foreach ( $contact_groups as $group ) { |
| 27 |
$groups[ $group->id ] = $group->name; |
| 28 |
} |
| 29 |
} |
| 30 |
?> |
| 31 |
<div class="postbox"> |
| 32 |
<div class="inside"> |
| 33 |
<h3><?php _e( 'Import CSV', 'erp' ); ?></h3> |
| 34 |
|
| 35 |
<form method="post" action="<?php echo $csv_sample_url; ?>" enctype="multipart/form-data" id="import_form"> |
| 36 |
|
| 37 |
<table class="form-table"> |
| 38 |
<tbody> |
| 39 |
<tr> |
| 40 |
<th> |
| 41 |
<label for="type"><?php _e( 'Type', 'erp' ); ?></label> |
| 42 |
</th> |
| 43 |
<td> |
| 44 |
<select name="type" id="type"> |
| 45 |
<?php foreach ( $import_export_types as $key => $value ) { ?> |
| 46 |
<option value="<?php echo $key; ?>"><?php _e( $value, 'erp' ); ?></option> |
| 47 |
<?php } ?> |
| 48 |
</select> |
| 49 |
<p class="description"><?php _e( 'Select item type to import.', 'erp' ); ?></p> |
| 50 |
</td> |
| 51 |
</tr> |
| 52 |
<tr> |
| 53 |
<th> |
| 54 |
<label for="type"><?php _e( 'CSV File', 'erp' ); ?> <span class="required">*</span></label> |
| 55 |
</th> |
| 56 |
<td> |
| 57 |
<input type="file" name="csv_file" id="csv_file" /> |
| 58 |
<p class="description"><?php _e( 'Upload a csv file.', 'erp' ); ?></p> |
| 59 |
<p id="download_sample_wrap"> |
| 60 |
<input type="hidden" value="<?php echo $csv_sample_url; ?>" /> |
| 61 |
<button class="button button-primary"> Download Sample CSV</button> |
| 62 |
</p> |
| 63 |
</td> |
| 64 |
</tr> |
| 65 |
</tbody> |
| 66 |
<tbody id="crm_contact_lifestage_owner_wrap"> |
| 67 |
<tr> |
| 68 |
<th> |
| 69 |
<label for="contact_owner"><?php _e( 'Contact Owner', 'erp' ); ?></label> |
| 70 |
</th> |
| 71 |
<td> |
| 72 |
<select name="contact_owner" id="contact_owner"> |
| 73 |
<?php |
| 74 |
$current_user = get_current_user_id(); |
| 75 |
echo erp_html_generate_dropdown( $users, $current_user ); |
| 76 |
?> |
| 77 |
</select> |
| 78 |
<p class="description"><?php _e( 'Contact owner for contact.', 'erp' ); ?></p> |
| 79 |
</td> |
| 80 |
</tr> |
| 81 |
<tr> |
| 82 |
<th> |
| 83 |
<label for="life_stage"><?php _e( 'Life Stage', 'erp' ); ?></label> |
| 84 |
</th> |
| 85 |
<td> |
| 86 |
<select name="life_stage" id="life_stage"> |
| 87 |
<?php echo erp_html_generate_dropdown( $life_stages ); ?> |
| 88 |
</select> |
| 89 |
<p class="description"><?php _e( 'Life stage for contact.', 'erp' ); ?></p> |
| 90 |
</td> |
| 91 |
</tr> |
| 92 |
<tr> |
| 93 |
<th> |
| 94 |
<label for="contact_group"><?php _e( 'Contact Group', 'erp' ); ?></label> |
| 95 |
</th> |
| 96 |
<td> |
| 97 |
<select name="contact_group"> |
| 98 |
<?php echo erp_html_generate_dropdown( $groups ); ?> |
| 99 |
</select> |
| 100 |
<p class="description"><?php _e( 'Imported contacts will be subscribed in selected group.', 'erp' ); ?></p> |
| 101 |
</td> |
| 102 |
</tr> |
| 103 |
</tbody> |
| 104 |
|
| 105 |
<tbody id="fields_container" style="display: none;"> |
| 106 |
|
| 107 |
</tbody> |
| 108 |
</table> |
| 109 |
|
| 110 |
<?php wp_nonce_field( 'erp-import-export-nonce' ); ?> |
| 111 |
<?php submit_button( __( 'Import', 'erp' ), 'primary', 'erp_import_csv' ); ?> |
| 112 |
</form> |
| 113 |
</div><!-- .inside --> |
| 114 |
</div><!-- .postbox --> |
| 115 |
|
| 116 |
<?php if ( $is_crm_activated ) { ?> |
| 117 |
<div class="postbox"> |
| 118 |
<div class="inside"> |
| 119 |
<h3><?php _e( 'Import Users into CRM', 'erp' ); ?></h3> |
| 120 |
|
| 121 |
<form method="post" action="<?php echo admin_url( 'admin.php?page=erp-tools' ); ?>" enctype="multipart/form-data" id="users_import_form"> |
| 122 |
|
| 123 |
<?php |
| 124 |
global $wp_roles; |
| 125 |
delete_option( 'erp_users_to_contacts_import_attempt' ); |
| 126 |
delete_option( 'erp_users_to_contacts_import_exists' ); |
| 127 |
|
| 128 |
$roles = $wp_roles->get_names(); |
| 129 |
$default_role = get_option( 'default_role', '' ); |
| 130 |
?> |
| 131 |
<table class="form-table"> |
| 132 |
<tbody> |
| 133 |
<tr> |
| 134 |
<th> |
| 135 |
<label for="user_role"><?php _e( 'User Role', 'erp' ); ?></label> |
| 136 |
</th> |
| 137 |
<td> |
| 138 |
<select name="user_role" class="erp-select2" id="user_role" multiple="true"> |
| 139 |
<?php echo erp_html_generate_dropdown( $roles, $default_role ); ?> |
| 140 |
</select> |
| 141 |
<p class="description"><?php _e( 'Selected user role are considered to import.', 'erp' ); ?></p> |
| 142 |
</td> |
| 143 |
</tr> |
| 144 |
<tr> |
| 145 |
<th> |
| 146 |
<label for="contact_owner"><?php _e( 'Contact Owner', 'erp' ); ?></label> |
| 147 |
</th> |
| 148 |
<td> |
| 149 |
<select name="contact_owner" id="contact_owner"> |
| 150 |
<?php |
| 151 |
$current_user = get_current_user_id(); |
| 152 |
echo erp_html_generate_dropdown( $users, $current_user ); |
| 153 |
?> |
| 154 |
</select> |
| 155 |
<p class="description"><?php _e( 'Contact owner for contact.', 'erp' ); ?></p> |
| 156 |
</td> |
| 157 |
</tr> |
| 158 |
<tr> |
| 159 |
<th> |
| 160 |
<label for="life_stage"><?php _e( 'Life Stage', 'erp' ); ?></label> |
| 161 |
</th> |
| 162 |
<td> |
| 163 |
<select name="life_stage" id="life_stage"> |
| 164 |
<?php echo erp_html_generate_dropdown( $life_stages ); ?> |
| 165 |
</select> |
| 166 |
<p class="description"><?php _e( 'Life stage for contact.', 'erp' ); ?></p> |
| 167 |
</td> |
| 168 |
</tr> |
| 169 |
<tr> |
| 170 |
<th> |
| 171 |
<label for="contact_group"><?php _e( 'Contact Group', 'erp' ); ?></label> |
| 172 |
</th> |
| 173 |
<td> |
| 174 |
<select name="contact_group"> |
| 175 |
<?php echo erp_html_generate_dropdown( $groups ); ?> |
| 176 |
</select> |
| 177 |
<p class="description"><?php _e( 'Imported contacts will be subscribed in selected group.', 'erp' ); ?></p> |
| 178 |
</td> |
| 179 |
</tr> |
| 180 |
</tbody> |
| 181 |
</table> |
| 182 |
<br /> |
| 183 |
<div id="import-status-indicator" class="erp-progress-status-indicator" style="display: none;"> |
| 184 |
<div class="status"> |
| 185 |
<span id="progress-total">100%</span> |
| 186 |
</div> |
| 187 |
<div class="progress"> |
| 188 |
<progress id="progressbar-total" max="100" value="0"></progress> |
| 189 |
</div> |
| 190 |
<div class="status"> |
| 191 |
<span id="completed-total"></span> |
| 192 |
<span id="failed-total"></span> |
| 193 |
</div> |
| 194 |
</div> |
| 195 |
|
| 196 |
<?php wp_nonce_field( 'erp-import-export-nonce' ); ?> |
| 197 |
<?php submit_button( __( 'Import', 'erp' ), 'primary', 'erp_import_users' ); ?> |
| 198 |
</form> |
| 199 |
</div><!-- .inside --> |
| 200 |
</div><!-- .postbox --> |
| 201 |
<?php |
| 202 |
} |
| 203 |
?> |
| 204 |
|