/** * @param $post_id */ function save_meta_values($post_id, $post) { $meta_fields = $this->get_meta_fields(); if (isset($_POST['post_ID']) && !empty($_REQUEST['rtbiz_is_staff_member']) && 'yes' == $_REQUEST['rtbiz_is_staff_member']) { $users = rtbiz_get_wp_user_for_contact($_POST['post_ID']); if (empty($users[0])) { $primary_email = rtbiz_get_entity_meta($_POST['post_ID'], self::$primary_email_key, true); $userid = email_exists($primary_email); if (rtbiz_is_primary_email_unique($primary_email, $_POST['post_ID']) && !is_wp_error($userid) && !p2p_connection_exists($this->post_type . '_to_user', array('to' => $userid))) { rtbiz_connect_contact_to_user($_POST['post_ID'], $userid); } else { update_user_meta(get_current_user_id(), Rtbiz_Entity::$meta_key_prefix . 'wp_user_not_connected_' . $_POST['post_ID'], true); } } } if (isset($_POST['contact_meta'][self::$primary_email_key]) && empty($_POST['contact_meta'][self::$primary_email_key])) { update_user_meta(get_current_user_id(), Rtbiz_Entity::$meta_key_prefix . 'empty_primary_email_' . $_POST['post_ID'], true); } else { delete_user_meta(get_current_user_id(), Rtbiz_Entity::$meta_key_prefix . 'empty_primary_email_' . $_POST['post_ID']); } foreach ($meta_fields as $field) { if (isset($_POST['contact_meta'][$field['key']]) && !empty($_POST['contact_meta'][$field['key']])) { if ($field['key'] == self::$primary_email_key) { if (!rtbiz_is_primary_email_unique($_POST['contact_meta'][$field['key']], $_POST['post_ID'])) { update_user_meta(get_current_user_id(), Rtbiz_Entity::$meta_key_prefix . 'unique_primary_email_' . $_POST['post_ID'], true); continue; } else { delete_user_meta(get_current_user_id(), Rtbiz_Entity::$meta_key_prefix . 'unique_primary_email_' . $_POST['post_ID']); } } $contact_meta[$field['key']] = $_POST['contact_meta'][$field['key']]; if (isset($field['is_multiple']) && $field['is_multiple']) { $oldmeta = self::get_meta($post_id, $field['key']); foreach ($oldmeta as $ometa) { self::delete_meta($post_id, $field['key'], $ometa); } foreach ($contact_meta[$field['key']] as $nmeta) { if ('' == $nmeta) { continue; } self::add_meta($post_id, $field['key'], $nmeta); } } else { self::update_meta($post_id, $field['key'], $_POST['contact_meta'][$field['key']]); } } else { $oldmeta = self::get_meta($post_id, $field['key']); foreach ($oldmeta as $ometa) { self::delete_meta($post_id, $field['key'], $ometa); } } } Rtbiz_Contact_Profile_Access::save($post_id, null); parent::save_meta_values($post_id, $post); }
public static function ui($post) { if (rtbiz_get_contact_post_type() == $post->post_type) { $meta_fields = rtbiz_get_contact_meta_fields(); } elseif (rtbiz_get_company_post_type() == $post->post_type) { $meta_fields = rtbiz_get_company_meta_fields(); } do_action('rtbiz_before_render_meta_fields', $meta_fields); if (empty($meta_fields)) { return false; } ?> <div id="rtbiz-additional-detail-meta-box"> <?php $category = array_unique(wp_list_pluck($meta_fields, 'category')); $cathtml = array(); foreach ($category as $key => $value) { $cathtml[$value]['title'] = '<div><h3 class="rtbiz-category-title">' . __($value) . __(' information:') . ' </h3> </div>'; } $cathtml['other']['title'] = '<div><h3 class="rtbiz-category-title">' . __('Other information:') . '</h3></div>'; $other_flag = false; $is_our_team_mate = false; $postid = $post; if (is_object($post)) { $postid = $post->ID; } $wp_user = rtbiz_get_wp_user_for_contact($postid); //get wp user $cap = rtbiz_get_access_role_cap(RTBIZ_TEXT_DOMAIN, 'author'); if (!empty($wp_user[0])) { $is_our_team_mate = user_can($wp_user[0], $cap); } foreach ($meta_fields as $field) { ob_start(); $field = apply_filters('rtbiz_entity_fields_loop_single_field', $field); if (!$is_our_team_mate) { if (isset($field['hide_for_client']) && $field['hide_for_client']) { continue; } } if (isset($field['is_datepicker']) && $field['is_datepicker']) { $values = Rtbiz_Entity::get_meta($post->ID, $field['key'], true); ?> <script> jQuery(document).ready(function ($) { $(document).on('focus', ".datepicker", function () { $(this).datepicker({ 'dateFormat': 'dd/mm/yy', changeMonth: true, changeYear: true }); }); }); </script> <p class="rtbiz-form-group"><?php if (isset($field['label'])) { ?> <label for="<?php echo isset($field['id']) ? '' . $field['id'] . '' : ''; ?> "> <?php echo $field['label']; ?> </label><?php } ?> <input type="text" <?php echo isset($field['name']) ? 'name="' . $field['name'] . '"' : ''; echo isset($field['id']) ? 'id="' . $field['id'] . '"' : ''; ?> value='<?php echo $values; ?> ' <?php echo isset($field['class']) ? 'class="datepicker ' . $field['class'] . '"' : 'class="datepicker"'; ?> > <br/><span></span> </p> <?php } else { if (isset($field['is_multiple']) && $field['is_multiple']) { $values = Rtbiz_Entity::get_meta($post->ID, $field['key']); ?> <p class="rtbiz-form-group"><?php if (isset($field['label'])) { ?> <label for="<?php echo isset($field['id']) ? '' . $field['id'] . '' : ''; ?> "> <?php echo $field['label']; ?> </label><?php } ?> <input <?php echo isset($field['type']) ? 'type="' . $field['type'] . '"' : ''; ?> <?php echo isset($field['name']) ? 'name="' . $field['name'] . '"' : ''; ?> <?php echo isset($field['class']) ? 'class="' . $field['class'] . '"' : ''; ?> > <button data-type='<?php echo $field['type']; ?> ' type='button' class='button button-primary add-multiple'> + </button> <br/><span></span><?php foreach ($values as $value) { ?> <input <?php echo isset($field['type']) ? 'type="' . $field['type'] . '"' : ''; echo isset($field['name']) ? 'name="' . $field['name'] . '"' : ''; ?> value='<?php echo $value; ?> ' <?php echo isset($field['class']) ? 'class="second-multiple-input ' . $field['class'] . '"' : 'class="second-multiple-input"'; ?> > <button type='button' class='button delete-multiple'> -</button><?php } ?> </p> <?php } else { if (isset($field['type']) && 'textarea' == $field['type']) { $values = Rtbiz_Entity::get_meta($post->ID, $field['key'], true); ?> <p class="rtbiz-form-group"><?php if (isset($field['label'])) { ?> <label for="<?php echo isset($field['id']) ? '' . $field['id'] . '' : ''; ?> "><?php echo $field['label']; ?> </label> <?php } ?> <textarea <?php echo isset($field['name']) ? 'name="' . $field['name'] . '"' : ''; echo isset($field['id']) ? 'id="' . $field['id'] . '"' : ''; echo isset($field['class']) ? 'class="' . $field['class'] . '"' : ''; ?> > <?php echo $values; ?> </textarea> <br/><span></span> </p> <?php } else { if (isset($field['type']) && 'user_group' == $field['type']) { $user_id = Rtbiz_Entity::get_meta($post->ID, $field['key'], true); if (empty($user_id)) { continue; } ?> <p class="rtbiz-form-group"><?php call_user_func($field['data_source'], new WP_User($user_id)); ?> </p><?php } else { if (isset($field['type']) && 'checkbox' == $field['type']) { $values = Rtbiz_Entity::get_meta($post->ID, $field['key'], true); ?> <p class="rtbiz-form-group rtbiz-form-checkbox"> <label for="<?php echo isset($field['id']) ? '' . $field['id'] . '' : ''; ?> "> <input value='yes' <?php echo 'yes' == $values ? 'checked' : ''; ?> type='checkbox' <?php echo isset($field['name']) ? 'name="' . $field['name'] . '"' : ''; echo isset($field['id']) ? 'id="' . $field['id'] . '"' : ''; echo isset($field['class']) ? 'class="' . $field['class'] . '"' : ''; ?> /><?php echo $field['text']; ?> </label> <br/><span></span> </p> <?php } else { $values = Rtbiz_Entity::get_meta($post->ID, $field['key'], true); ?> <p class="rtbiz-form-group"><?php if (isset($field['label'])) { ?> <label for="<?php echo isset($field['id']) ? '' . $field['id'] . '' : ''; ?> "><?php echo $field['label']; ?> </label><?php } ?> <input <?php echo isset($field['type']) ? 'type="' . $field['type'] . '"' : ''; echo isset($field['name']) ? 'name="' . $field['name'] . '"' : ''; echo isset($field['id']) ? 'id="' . $field['id'] . '"' : ''; ?> value='<?php echo $values; ?> ' <?php echo isset($field['class']) ? 'class="' . $field['class'] . '"' : ''; ?> > <br/><span></span> </p> <?php } } } } } $tmphtml = ob_get_clean(); if (!isset($cathtml[$field['category']]['fields'])) { $cathtml[$field['category']]['fields'] = ''; } if (isset($field['category'])) { $cathtml[$field['category']]['fields'] .= $tmphtml; } else { $cathtml['other']['fields'] .= $tmphtml; $other_flag = true; } } $printimpload = array(); if (isset($cathtml['Contact'])) { $printimpload[] = $cathtml['Contact']; unset($cathtml['Contact']); } if (isset($cathtml['Social'])) { $printimpload[] = $cathtml['Social']; unset($cathtml['Social']); } if (isset($cathtml['HR'])) { if ($is_our_team_mate) { $printimpload[] = $cathtml['HR']; } unset($cathtml['HR']); } foreach ($cathtml as $key => $value) { if ('other' == $key) { if (true == $other_flag) { $printimpload[] = $value; } } else { $printimpload[] = $value; } } $filter = function ($category) { return $category['title'] . '<div class="rtbiz-category-group">' . $category['fields'] . '</div>'; }; $printimpload = array_map($filter, $printimpload); echo implode('<div class="add-gap-div"><hr></div>', $printimpload); ?> </div> <?php do_action('rtbiz_after_render_meta_fields', $post, $post->post_type); wp_nonce_field('rtbiz_additional_details_metabox', 'rtbiz_additional_details_metabox_nonce'); if (rtbiz_get_contact_post_type() == $post->post_type) { /* @var $rtbiz_contact Rtbiz_Contact */ global $rtbiz_contact; $rtbiz_contact->print_metabox_js($post); } elseif (rtbiz_get_company_post_type() == $post->post_type) { /* @var $rtbiz_company Rtbiz_Company */ global $rtbiz_company; $rtbiz_company->print_metabox_js($post); } do_action('print_metabox_js', $post, $post->post_type); }
function rtbiz_get_module_team_users($team_id, $category_slug = '', $module_key = '') { global $rtbiz_contact; $team = get_term_by('id', $team_id, Rtbiz_Teams::$slug); $args = array(Rtbiz_Teams::$slug => $team->slug, 'post_type' => $rtbiz_contact->post_type, 'post_status' => 'any', 'nopaging' => true); /*if ( ! empty( $category_slug ) ) { $args = array_merge( $args, array( Rtbiz_Contact::$user_category_taxonomy => $category_slug ) ); }*/ $contacts = get_posts($args); $contact_ids = array(); foreach ($contacts as $contact) { // module filter if (!empty($module_key)) { $pp = get_post_meta($contact->ID, 'rtbiz_profile_permissions', true); if (isset($pp[$module_key]) && 0 == intval($pp[$module_key])) { continue; } } $contact_ids[] = $contact->ID; } if (!empty($contact_ids)) { return rtbiz_get_wp_user_for_contact($contact_ids); } return array(); }
public static function save($contact_id, $post) { global $rtbiz_acl_model; $user = rtbiz_get_wp_user_for_contact($contact_id); if (empty($user)) { return; } $profile_permissions = array(); if (!empty($_REQUEST['rtbiz_is_staff_member']) && 'yes' == $_REQUEST['rtbiz_is_staff_member']) { if (isset($_REQUEST['rtbiz_profile_permissions']) && is_array($_REQUEST['rtbiz_profile_permissions'])) { $teams = wp_get_post_terms($contact_id, Rtbiz_Teams::$slug); $module_permissions = get_site_option('rtbiz_acl_module_permissions'); $profile_permissions = $_REQUEST['rtbiz_profile_permissions']; $old_profile_permissions = get_post_meta($contact_id, 'rtbiz_profile_permissions', true); //if helpdesk exist rtbiz & helpdesk permission are same and rtbiz acl is hidden if (is_plugin_active('rtbiz-helpdesk/rtbiz-helpdesk.php')) { $profile_permissions[RTBIZ_TEXT_DOMAIN] = $profile_permissions[RTBIZ_HD_TEXT_DOMAIN]; $_REQUEST['rtbiz_profile_permissions'][RTBIZ_TEXT_DOMAIN] = $profile_permissions[RTBIZ_TEXT_DOMAIN]; } foreach ($profile_permissions as $module_Key => $module_permission) { if (empty($old_profile_permissions[$module_Key])) { $old_profile_permissions[$module_Key] = ''; } $old_permission_len = strlen($old_profile_permissions[$module_Key]); $isOldPermission = isset($old_profile_permissions[$module_Key]); switch ($module_permission) { case 0: if (0 == strlen($module_permission)) { // Group Level permission $module_permission = !empty($module_permissions) ? $module_permissions[$module_Key] : array(); //check if old permission is group level if ($isOldPermission && 0 == $old_permission_len) { //get old group and its old permission from custom table $where = array('userid' => $user[0]->ID, 'module' => $module_Key); $old_group_permission = $rtbiz_acl_model->get_acl($where); if (!empty($old_group_permission)) { $old_group = array_unique(wp_list_pluck($old_group_permission, 'groupid')); $old_group_permission = array_unique(wp_list_pluck($old_group_permission, 'permission')); } else { $old_group = array(); $old_group_permission = array(); } foreach ($teams as $team) { // find index is current group exist in old group list $position = array_search($team->term_id, $old_group); //check if group permission is already exist or not if (strlen($position) > 0) { // check id group permission update or not if ($module_permission[$team->term_id] != $old_group_permission[$position]) { // update group level permission $data = array('permission' => $module_permission[$team->term_id]); $where = array('userid' => $user[0]->ID, 'module' => $module_Key, 'groupid' => $team->term_id); $rtbiz_acl_model->update_acl($data, $where); } } else { // add new group level permission $data = array('userid' => $user[0]->ID, 'module' => $module_Key, 'groupid' => $team->term_id, 'permission' => $module_permission[$team->term_id]); $rtbiz_acl_model->add_acl($data); } } //if group remove from customer profile remove access if (!empty($teams)) { $new_group = array_unique(wp_list_pluck($teams, 'term_id')); } else { $new_group = array(); } $group_removed = array_diff($old_group, $new_group); if (!empty($group_removed)) { // remove group level acl foreach ($group_removed as $group) { $where = array('userid' => $user[0]->ID, 'groupid' => $group, 'module' => $module_Key); $rtbiz_acl_model->remove_acl($where); } } } else { //check if old permission is profile level permission if ($isOldPermission && 0 != $old_permission_len) { // remove old profile level permission $where = array('userid' => $user[0]->ID, 'module' => $module_Key); $rtbiz_acl_model->remove_acl($where); } // Add new group level permission foreach ($teams as $team) { $data = array('userid' => $user[0]->ID, 'module' => $module_Key, 'groupid' => $team->term_id, 'permission' => $module_permission[$team->term_id]); $rtbiz_acl_model->add_acl($data); } } } else { // No Role //remove all permission if ($isOldPermission) { $where = array('userid' => $user[0]->ID, 'module' => $module_Key); $rtbiz_acl_model->remove_acl($where); } } break; case 10: case 20: case 30: //check if old permission is profile level permission || 0 != $old_permission_len means profile level permission already set if ($isOldPermission && 0 != $old_permission_len && 0 != $old_profile_permissions[$module_Key]) { //check if profile level permission changed if ($module_permission != $old_profile_permissions[$module_Key]) { $data = array('permission' => $module_permission); $where = array('userid' => $user[0]->ID, 'module' => $module_Key, 'groupid' => 0); $rtbiz_acl_model->update_acl($data, $where); } } else { // remove old group level permission if already set if ($isOldPermission && 0 == $old_permission_len) { $where = array('userid' => $user[0]->ID, 'module' => $module_Key); $rtbiz_acl_model->remove_acl($where); } // Add new profile level permission $data = array('userid' => $user[0]->ID, 'module' => $module_Key, 'groupid' => 0, 'permission' => $module_permission); $rtbiz_acl_model->add_acl($data); } break; } } } } else { $where = array('userid' => $user[0]->ID); $rtbiz_acl_model->remove_acl($where); } update_post_meta($contact_id, 'rtbiz_profile_permissions', $profile_permissions); update_post_meta($contact_id, 'rtbiz_is_staff_member', $_REQUEST['rtbiz_is_staff_member']); }