PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.3.13
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.3.13
1.17.9 1.17.8 1.17.7 1.17.6 1.17.5 1.17.4 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.11 1.3.12 1.3.13 1.3.14 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 143 releases
erp / modules / crm / crm.php

crm.php in ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce 1.3.13, at modules/crm/crm.php

406 lines 18.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WeDevs\ERP\CRM;
3
4 use WeDevs\ERP\Framework\Traits\Hooker;
5
6 /**
7 * The HRM Class
8 *
9 * This is loaded in `init` action hook
10 */
11 class Customer_Relationship {
12
13 use Hooker;
14
15 /**
16 * Initializes the WeDevs_ERP() class
17 *
18 * Checks for an existing WeDevs_ERP() instance
19 * and if it doesn't find one, creates it.
20 */
21 public static function init() {
22 static $instance = false;
23
24 if ( ! $instance ) {
25 $instance = new self();
26 }
27
28 return $instance;
29 }
30
31 /**
32 * Kick-in the class
33 *
34 * @return void
35 */
36 public function __construct() {
37 // prevent duplicate loading
38 if ( did_action( 'erp_crm_loaded' ) ) {
39 return;
40 }
41
42 // Define constants
43 $this->define_constants();
44
45 // Include required files
46 $this->includes();
47
48 // Initialize the classes
49 $this->init_classes();
50
51 // Initialize the action hooks
52 $this->init_actions();
53
54 // Initialize the filter hooks
55 $this->init_filters();
56
57 // Trigger after CRM module loaded
58 do_action( 'erp_crm_loaded' );
59 }
60
61 /**
62 * Define the plugin constants
63 *
64 * @return void
65 */
66 private function define_constants() {
67 define( 'WPERP_CRM_FILE', __FILE__ );
68 define( 'WPERP_CRM_PATH', dirname( __FILE__ ) );
69 define( 'WPERP_CRM_VIEWS', dirname( __FILE__ ) . '/views' );
70 define( 'WPERP_CRM_JS_TMPL', WPERP_CRM_VIEWS . '/js-templates' );
71 define( 'WPERP_CRM_ASSETS', plugins_url( '/assets', __FILE__ ) );
72 }
73
74 /**
75 * Include the required files
76 *
77 * @return void
78 */
79 private function includes() {
80 require_once WPERP_CRM_PATH . '/includes/actions-filters.php';
81 require_once WPERP_CRM_PATH . '/includes/functions-localize.php';
82 require_once WPERP_CRM_PATH . '/includes/functions-customer.php';
83 require_once WPERP_CRM_PATH . '/includes/functions-dashboard.php';
84 require_once WPERP_CRM_PATH . '/includes/functions-reporting.php';
85 require_once WPERP_CRM_PATH . '/includes/functions-capabilities.php';
86 require_once WPERP_CRM_PATH . '/includes/contact-forms/class-contact-forms-integration.php';
87
88 // cli command
89 if ( defined('WP_CLI') && WP_CLI ) {
90 include WPERP_CRM_PATH . '/includes/cli/commands.php';
91 }
92 }
93
94 /**
95 * Init classes
96 *
97 * @return void
98 */
99 private function init_classes() {
100 if ( is_admin() ) {
101 new Ajax_Handler();
102 new Form_Handler();
103 new Admin_Menu();
104 new User_Profile();
105 new Emailer();
106 new Admin_Dashboard();
107 }
108
109 Subscription::instance();
110 }
111
112 /**
113 * Initialize WordPress action hooks
114 *
115 * @return void
116 */
117 private function init_actions() {
118 $this->action( 'admin_enqueue_scripts', 'admin_scripts' );
119 $this->action( 'admin_footer', 'load_js_template', 10 );
120 }
121
122 /**
123 * Initialize WordPress filter hooks
124 *
125 * @return void
126 */
127 private function init_filters() {
128
129 }
130
131 /**
132 * Enqueue admin scripts
133 *
134 * @since 1.0.0
135 * @since 1.2.2 Remove other select2 sources from contact groups page
136 *
137 * @param string $hook
138 *
139 * @return void
140 */
141 public function admin_scripts( $hook ) {
142 $hook = str_replace( sanitize_title( __( 'CRM', 'erp' ) ) , 'crm', $hook );
143
144 $crm_pages = [
145 'toplevel_page_erp-sales',
146 'crm_page_erp-sales-customers',
147 'crm_page_erp-sales-companies',
148 'crm_page_erp-sales-schedules',
149 'crm_page_erp-sales-activities',
150 'erp-settings_page_erp-settings',
151 'crm_page_erp-sales-contact-groups',
152 'crm_page_erp-sales-reports'
153 ];
154
155 if ( ! in_array( $hook , $crm_pages ) ) {
156 return;
157 }
158
159 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '';
160
161 wp_enqueue_media();
162 wp_enqueue_style( 'erp-tiptip' );
163 wp_enqueue_script( 'erp-tiptip' );
164 wp_enqueue_script( 'erp-vuejs', false, [ 'jquery', 'erp-script' ], false, true );
165 wp_enqueue_script( 'erp-vue-table', WPERP_CRM_ASSETS . "/js/vue-table$suffix.js", array( 'erp-vuejs', 'jquery' ), date( 'Ymd' ), true );
166
167 wp_enqueue_style( 'email-attachment', WPERP_CRM_ASSETS . "/css/email-attachment.css", array(), false );
168
169 $localize_script = apply_filters( 'erp_crm_localize_script', array(
170 'ajaxurl' => admin_url( 'admin-ajax.php' ),
171 'nonce' => wp_create_nonce( 'wp-erp-crm-nonce' ),
172 'popup' => array(
173 'customer_title' => __( 'Add New Customer', 'erp' ),
174 'customer_update_title' => __( 'Edit Customer', 'erp' ),
175 'customer_social_title' => __( 'Customer Social Profile', 'erp' ),
176 'customer_assign_group' => __( 'Add to Contact groups', 'erp' ),
177 ),
178 'add_submit' => __( 'Add New', 'erp' ),
179 'update_submit' => __( 'Update', 'erp' ),
180 'save_submit' => __( 'Save', 'erp' ),
181 'customer_upload_photo' => __( 'Upload Photo', 'erp' ),
182 'customer_set_photo' => __( 'Set Photo', 'erp' ),
183 'confirm' => __( 'Are you sure?', 'erp' ),
184 'delConfirmCustomer' => __( 'Are you sure to delete?', 'erp' ),
185 'delConfirm' => __( 'Are you sure to delete this?', 'erp' ),
186 'checkedConfirm' => __( 'Select atleast one group', 'erp' ),
187 'contact_exit' => __( 'Already exists as a contact or company', 'erp' ),
188 'make_contact_text' => __( 'This user already exists! Do you want to make this user as a', 'erp' ),
189 'wpuser_make_contact_text' => __( 'This is wp user! Do you want to create this user as a', 'erp' ),
190 'create_contact_text' => __( 'Create new', 'erp' ),
191 'current_user_id' => get_current_user_id(),
192 'successfully_created_wpuser' => __( 'WP User created successfully', 'erp' ),
193 ) );
194
195 $contact_actvity_localize = apply_filters( 'erp_crm_contact_localize_var', [
196 'ajaxurl' => admin_url( 'admin-ajax.php' ),
197 'nonce' => wp_create_nonce( 'wp-erp-crm-customer-feed' ),
198 'current_user_id' => get_current_user_id(),
199 'isAdmin' => current_user_can( 'manage_options' ),
200 'isCrmManager' => current_user_can( 'erp_crm_manager' ),
201 'isAgent' => current_user_can( 'erp_crm_agent' ),
202 'confirm' => __( 'Are you sure?', 'erp' ),
203 'date_format' => get_option( 'date_format' ),
204 'timeline_feed_header' => apply_filters( 'erp_crm_contact_timeline_feeds_header', '' ),
205 'timeline_feed_body' => apply_filters( 'erp_crm_contact_timeline_feeds_body', '' ),
206 ] );
207
208 if ( 'crm_page_erp-sales-schedules' == $hook ) {
209 wp_enqueue_style( 'erp-timepicker' );
210 wp_enqueue_script( 'erp-timepicker' );
211 wp_enqueue_script( 'underscore' );
212 wp_enqueue_script( 'erp-trix-editor' );
213 wp_enqueue_style( 'erp-trix-editor' );
214 }
215
216 if ( 'crm_page_erp-sales-activities' == $hook ) {
217 wp_enqueue_script( 'underscore' );
218 wp_enqueue_script( 'erp-vuejs' );
219 wp_enqueue_style( 'erp-nprogress' );
220 wp_enqueue_script( 'erp-nprogress' );
221 wp_enqueue_script( 'wp-erp-crm-vue-component', WPERP_CRM_ASSETS . "/js/crm-components.js", array( 'erp-nprogress', 'erp-script', 'erp-vuejs', 'underscore', 'erp-select2', 'erp-tiptip' ), date( 'Ymd' ), true );
222
223 do_action( 'erp_crm_load_contact_vue_scripts' );
224
225 wp_enqueue_script( 'wp-erp-crm-vue-customer', WPERP_CRM_ASSETS . "/js/crm-app$suffix.js", array( 'wp-erp-crm-vue-component', 'erp-nprogress', 'erp-script', 'erp-vuejs', 'underscore', 'erp-select2', 'erp-tiptip' ), date( 'Ymd' ), true );
226 wp_enqueue_script( 'post' );
227
228 $contact_actvity_localize['isActivityPage'] = true;
229 wp_localize_script( 'wp-erp-crm-vue-component', 'wpCRMvue', $contact_actvity_localize );
230 }
231
232 // if it's an customer page
233 if ( ( 'crm_page_erp-sales-customers' == $hook || 'crm_page_erp-sales-companies' == $hook ) ) {
234 wp_enqueue_style( 'erp-timepicker' );
235 wp_enqueue_script( 'erp-timepicker' );
236 wp_enqueue_script( 'erp-vuejs' );
237 wp_enqueue_script( 'erp-trix-editor' );
238 wp_enqueue_style( 'erp-trix-editor' );
239 wp_enqueue_script( 'underscore' );
240 wp_enqueue_style( 'erp-nprogress' );
241 wp_enqueue_script( 'erp-nprogress' );
242 wp_enqueue_script( 'wp-erp-crm-vue-component', WPERP_CRM_ASSETS . "/js/crm-components.js", array( 'erp-nprogress', 'erp-script', 'erp-vuejs', 'underscore', 'erp-select2', 'erp-tiptip' ), date( 'Ymd' ), true );
243
244 do_action( 'erp_crm_load_contact_vue_scripts' );
245
246 if ( isset( $_GET['action'] ) && $_GET['action'] == 'view' ) {
247 wp_enqueue_script( 'wp-erp-crm-vue-customer', WPERP_CRM_ASSETS . "/js/crm-app$suffix.js", array( 'erp-nprogress', 'erp-script', 'erp-vuejs', 'underscore', 'erp-select2', 'erp-tiptip' ), date( 'Ymd' ), true );
248 }
249
250 wp_localize_script( 'wp-erp-crm-vue-component', 'wpCRMvue', $contact_actvity_localize );
251 wp_enqueue_script( 'post' );
252 }
253
254 if ( 'erp-settings_page_erp-settings' == $hook && isset( $_GET['tab'] ) && $_GET['tab'] == 'erp-crm' ) {
255 wp_enqueue_script( 'erp-trix-editor' );
256 wp_enqueue_style( 'erp-trix-editor' );
257 }
258
259 if( 'toplevel_page_erp-sales' == $hook ) {
260 wp_enqueue_script( 'jquery' );
261 wp_enqueue_script( 'erp-flotchart' );
262 wp_enqueue_script( 'erp-flotchart-time' );
263 wp_enqueue_script( 'erp-flotchart-axislables' );
264 wp_enqueue_script( 'erp-flotchart-orerbars' );
265 wp_enqueue_script( 'erp-flotchart-tooltip' );
266 }
267
268 if ( 'crm_page_erp-sales-customers' == $hook ) {
269 $customer = new Contact( null, 'contact' );
270 $localize_script['customer_empty'] = $customer->to_array();
271 $localize_script['statuses'] = erp_crm_customer_get_status_count( 'contact' );
272 $localize_script['contact_type'] = 'contact';
273 $localize_script['life_stages'] = erp_crm_get_life_stages_dropdown_raw();
274 $localize_script['searchFields'] = erp_crm_get_serach_key( 'contact' );
275 $localize_script['saveAdvanceSearch'] = erp_crm_get_save_search_item( [ 'type' => 'contact' ] );
276 $localize_script['isAdmin'] = current_user_can( 'manage_options' );
277 $localize_script['isCrmManager'] = current_user_can( 'erp_crm_manager' );
278 $localize_script['isAgent'] = current_user_can( 'erp_crm_agent' );
279
280 $country = \WeDevs\ERP\Countries::instance();
281 wp_localize_script( 'erp-script', 'wpErpCountries', $country->load_country_states() );
282 }
283
284 if ( 'crm_page_erp-sales-companies' == $hook ) {
285 $customer = new Contact( null, 'company' );
286 $localize_script['customer_empty'] = $customer->to_array();
287 $localize_script['statuses'] = erp_crm_customer_get_status_count( 'company' );
288 $localize_script['contact_type'] = 'company';
289 $localize_script['life_stages'] = erp_crm_get_life_stages_dropdown_raw();
290 $localize_script['searchFields'] = erp_crm_get_serach_key( 'company' );
291 $localize_script['saveAdvanceSearch'] = erp_crm_get_save_search_item( [ 'type' => 'company' ] );
292 $localize_script['isAdmin'] = current_user_can( 'manage_options' );
293 $localize_script['isCrmManager'] = current_user_can( 'erp_crm_manager' );
294 $localize_script['isAgent'] = current_user_can( 'erp_crm_agent' );
295
296 $country = \WeDevs\ERP\Countries::instance();
297 wp_localize_script( 'erp-script', 'wpErpCountries', $country->load_country_states() );
298 }
299
300 wp_localize_script( 'erp-vue-table', 'wpVueTable', [
301 'ajaxurl' => admin_url( 'admin-ajax.php' ),
302 'nonce' => wp_create_nonce( 'wp-erp-vue-table' )
303 ] );
304
305 wp_enqueue_script( 'erp-crm', WPERP_CRM_ASSETS . "/js/crm$suffix.js", array( 'erp-script', 'erp-timepicker' ), date( 'Ymd' ), true );
306 wp_enqueue_script( 'erp-crm-contact', WPERP_CRM_ASSETS . "/js/crm-contacts$suffix.js", array( 'erp-vue-table', 'erp-script', 'erp-vuejs', 'underscore', 'erp-tiptip', 'jquery', 'erp-select2' ), date( 'Ymd' ), true );
307 wp_localize_script( 'erp-crm', 'wpErpCrm', $localize_script );
308 wp_localize_script( 'erp-crm-contact', 'wpErpCrm', $localize_script );
309
310 $pages_hooks = [
311 'toplevel_page_erp-sales', 'crm_page_erp-sales-schedules', 'crm_page_erp-sales-activities',
312 'crm_page_erp-sales-customers', 'crm_page_erp-sales-customers', 'crm_page_erp-sales-companies',
313 'erp-settings_page_erp-settings', 'crm_page_erp-sales-contact-groups'
314 ];
315
316 if ( in_array( $hook , $pages_hooks ) ) {
317 erp_remove_other_select2_sources();
318 }
319
320 // Report
321 if ( $hook === 'crm_page_erp-sales-reports' && isset( $_GET['type'] ) && $_GET['type'] === 'growth-report' ) {
322 wp_enqueue_script( 'erp-crm-chart', WPERP_CRM_ASSETS . "/js/chart$suffix.min.js", array(), date( 'Ymd' ), true );
323 wp_enqueue_script( 'erp-crm-report', WPERP_CRM_ASSETS . "/js/report$suffix.js", array(), date( 'Ymd' ), true );
324 }
325 }
326
327 /**
328 * Load all js template in footer
329 *
330 * @since 1.0
331 *
332 * @return void
333 */
334 public function load_js_template() {
335 global $current_screen;
336 $hook = str_replace( sanitize_title( __( 'CRM', 'erp' ) ) , 'crm', $current_screen->base );
337
338 switch ( $hook ) {
339
340 case 'crm_page_erp-sales-customers':
341 case 'crm_page_erp-sales-companies':
342
343 erp_get_js_template( WPERP_CRM_JS_TMPL . '/new-customer.php', 'erp-crm-new-contact' );
344 erp_get_js_template( WPERP_CRM_JS_TMPL . '/make-wp-user.php', 'erp-make-wp-user' );
345 erp_get_js_template( WPERP_CRM_JS_TMPL . '/new-bulk-contact-group.php', 'erp-crm-new-bulk-contact-group' );
346 erp_get_vue_component_template( WPERP_CRM_JS_TMPL . '/save-search-fields.php', 'erp-crm-save-search-item' );
347
348 if ( isset( $_GET['action'] ) && $_GET['action'] == 'view' ) {
349 erp_get_js_template( WPERP_CRM_JS_TMPL . '/new-assign-company.php', 'erp-crm-new-assign-company' );
350 erp_get_js_template( WPERP_CRM_JS_TMPL . '/customer-social.php', 'erp-crm-customer-social' );
351 erp_get_js_template( WPERP_CRM_JS_TMPL . '/customer-feed-edit.php', 'erp-crm-customer-edit-feed' );
352 erp_get_js_template( WPERP_CRM_JS_TMPL . '/new-subscriber-contact.php', 'erp-crm-assign-subscriber-contact' );
353 erp_get_vue_component_template( WPERP_CRM_JS_TMPL . '/timeline-new-note.php', 'erp-crm-timeline-feed-new-note' );
354 erp_get_vue_component_template( WPERP_CRM_JS_TMPL . '/timeline-email.php', 'erp-crm-timeline-feed-email' );
355 erp_get_vue_component_template( WPERP_CRM_JS_TMPL . '/timeline-log-activity.php', 'erp-crm-timeline-feed-log-activity' );
356 erp_get_vue_component_template( WPERP_CRM_JS_TMPL . '/timeline-task.php', 'erp-crm-timeline-feed-task-note' );
357 erp_get_vue_component_template( WPERP_CRM_JS_TMPL . '/customer-newnote.php', 'erp-crm-new-note-template' );
358 erp_get_vue_component_template( WPERP_CRM_JS_TMPL . '/customer-log-activity.php', 'erp-crm-log-activity-template' );
359 erp_get_vue_component_template( WPERP_CRM_JS_TMPL . '/customer-email-note.php', 'erp-crm-email-note-template' );
360 erp_get_vue_component_template( WPERP_CRM_JS_TMPL . '/customer-schedule-note.php', 'erp-crm-schedule-note-template' );
361 erp_get_vue_component_template( WPERP_CRM_JS_TMPL . '/customer-tasks-note.php', 'erp-crm-tasks-note-template' );
362
363 do_action( 'erp_crm_load_vue_js_template' );
364 }
365
366 break;
367
368 case 'crm_page_erp-sales-contact-groups':
369 erp_get_js_template( WPERP_CRM_JS_TMPL . '/new-contact-group.php', 'erp-crm-new-contact-group' );
370 if( isset($_GET['groupaction']) && $_GET['groupaction'] == 'view-subscriber'){
371 erp_get_js_template( WPERP_CRM_JS_TMPL . '/new-subscriber-contact.php', 'erp-crm-assign-subscriber-contact' );
372 }
373 break;
374
375 case 'toplevel_page_erp-sales':
376 erp_get_js_template( WPERP_CRM_JS_TMPL . '/single-schedule-details.php', 'erp-crm-single-schedule-details' );
377 break;
378
379 case 'crm_page_erp-sales-activities':
380 erp_get_vue_component_template( WPERP_CRM_JS_TMPL . '/timeline-new-note.php', 'erp-crm-timeline-feed-new-note' );
381 erp_get_vue_component_template( WPERP_CRM_JS_TMPL . '/timeline-email.php', 'erp-crm-timeline-feed-email' );
382 erp_get_vue_component_template( WPERP_CRM_JS_TMPL . '/timeline-log-activity.php', 'erp-crm-timeline-feed-log-activity' );
383 erp_get_vue_component_template( WPERP_CRM_JS_TMPL . '/timeline-task.php', 'erp-crm-timeline-feed-task-note' );
384
385 do_action( 'erp_crm_load_vue_js_template' );
386
387 break;
388
389 case 'crm_page_erp-sales-schedules':
390 erp_get_js_template( WPERP_CRM_JS_TMPL . '/single-schedule-details.php', 'erp-crm-single-schedule-details' );
391 erp_get_js_template( WPERP_CRM_JS_TMPL . '/customer-add-schedules.php', 'erp-crm-customer-schedules');
392 break;
393
394 case 'erp-settings_page_erp-settings':
395 if ( isset( $_GET['tab'] ) && $_GET['tab'] == 'erp-crm' ) {
396 erp_get_js_template( WPERP_CRM_JS_TMPL . '/new-save-replies.php', 'erp-crm-new-save-replies' );
397 }
398 break;
399
400 default:
401 # code...
402 break;
403 }
404 }
405 }
406