} } $ws_ot_id = ObjectTypes::findByName('workspace')->getId(); $pg_array = logged_user()->getPermissionGroupIds(); $current_member_cond = $parent instanceof Member ? "AND parent_member_id=" . $parent->getId() : ""; $members = Members::findAll(array('limit' => $limit, 'order' => "depth, name", 'conditions' => "object_type_id={$ws_ot_id} {$current_member_cond} AND archived_by_id=0 AND EXISTS (\r\n\t\t\tSELECT cmp.member_id FROM " . TABLE_PREFIX . "contact_member_permissions cmp WHERE cmp.member_id=" . TABLE_PREFIX . "members.id AND cmp.permission_group_id IN (" . implode(',', $pg_array) . "))")); if ($parent instanceof Member && count($members) < $limit) { $tmp_ids = array(); foreach ($members as $m) { $tmp_ids[] = $m->getId(); } $extra_conds = "AND archived_by_id=0 AND EXISTS (\r\n\t\t\tSELECT cmp.member_id FROM " . TABLE_PREFIX . "contact_member_permissions cmp WHERE cmp.member_id=" . TABLE_PREFIX . "members.id AND cmp.permission_group_id IN (" . implode(',', $pg_array) . "))"; $childs = $parent->getAllChildren(true, 'name', $extra_conds); foreach ($childs as $ch) { if (in_array($ch->getId(), $tmp_ids)) { continue; } if ($ch->getObjectTypeId() == $ws_ot_id && count($members) <= $limit) { $members[] = $ch; } if (count($members) >= $limit) { break; } } } $total = count($members); if (is_array($members) && count($members) > 0 || can_manage_dimension_members(logged_user())) { $data_ws = $members; include_once 'template.php'; } }
/** * Check if specific user can delete this messages * * @access public * @param Contact $contact * @return boolean */ function canDelete(Contact $contact) { return can_manage_dimension_members($contact); }
function buildMemberList($all_members, $dimension, $allowed_member_type_ids, $allowed_object_type_ids, $item_object, $object_type_id, $return_only_name = false) { $dot_array = array(); // Dimension Object Types array (cache) $membersset = array(); foreach ($all_members as $m) { $membersset[$m->getId()] = true; } $members = array(); foreach ($all_members as $m) { /* @var $m Member */ // if ($m->getArchivedById() > 0) continue; if ($object_type_id != null) { $selectable = in_array($m->getObjectTypeId(), $allowed_object_type_ids) ? true : false; if ($selectable && isset($item_object)) { if (!$item_object->canAdd(logged_user(), array($m))) { continue; } } } else { $selectable = true; } if (count($allowed_member_type_ids) && !in_array($m->getObjectTypeId(), $allowed_member_type_ids)) { continue; } $tempParent = $m->getParentMemberId(); //check if have parent member id from Contact Member Cache if (isset($m->cached_parent_member_id)) { $tempParent = $m->cached_parent_member_id; } else { if (!logged_user()->isAdministrator()) { $x = $m; while ($x instanceof Member && !isset($membersset[$tempParent])) { $tempParent = $x->getParentMemberId(); if ($x->getParentMemberId() == 0) { break; } $x = $x->getParentMember(); } if (!$x instanceof Member) { $tempParent = 0; } } else { $tempParent = $m->getParentMemberId(); } } $memberOptions = ''; // SET member options (dimension object types table) // CHeck dot cache, if not set goto database and add to cache if (empty($dot_array[$dimension->getId()]) || empty($dot_array[$dimension->getId()][$m->getObjectTypeId()])) { $dot = DimensionObjectTypes::instance()->findOne(array("conditions" => "dimension_id = " . $dimension->getId() . " AND object_type_id = " . $m->getObjectTypeId())); if ($dot instanceof DimensionObjectType) { if (empty($dot_array['dimension_id'])) { $dot_array[$dimension->getId()] = array(); } $dot_array[$dimension->getId()][$m->getObjectTypeId()] = $dot; } } if (!empty($dot_array[$dimension->getId()]) || $dot_array[$dimension->getId()][$m->getObjectTypeId()] instanceof DimensionObjectType) { $dot = $dot_array[$dimension->getId()][$m->getObjectTypeId()]; if ($dot) { $memberOptions = $dot->getOptions(true); } } if ($return_only_name) { $path = trim($m->getPath()); $member = array("id" => $m->getId(), "name" => $m->getName(), "path" => $path, "depth" => $m->getDepth(), "to_show" => $m->getName() . ($path != "" ? " ({$path})" : ""), "dim" => $m->getDimensionId(), "ico" => "ico-color" . $m->getColor() . " " . $m->getIconClass()); } else { //Do not use contact member cache for superadmins if (!logged_user()->isAdministrator()) { //check childs from contact member cache $childsIds = ContactMemberCaches::getAllChildrenIdsFromCache(logged_user()->getId(), $m->getId()); } else { $childsIds = $m->getAllChildrenIds(false, null, ""); } $totalChilds = count($childsIds); $haveChilds = $totalChilds > 0 ? true : false; /* @var $m Member */ $additional_member_class = ""; Hook::fire('additional_member_node_class', $m, $additional_member_class); $member = array("id" => $m->getId(), "color" => $m->getMemberColor(), "name" => clean($m->getName()), "text" => clean($m->getName()), "leaf" => true, "parent" => $tempParent, "realParent" => $m->getParentMemberId(), "object_id" => $m->getObjectId(), "options" => $memberOptions, "depth" => $m->getDepth(), "cls" => $additional_member_class, "iconCls" => "ico-color" . $m->getColor() . " " . $m->getIconClass(), "selectable" => isset($selectable) ? $selectable : false, "dimension_id" => $m->getDimensionId(), "object_type_id" => $m->getObjectTypeId(), "expandable" => $haveChilds, "realTotalChilds" => $totalChilds, "allow_childs" => $m->allowChilds()); // Member Actions if (can_manage_dimension_members(logged_user())) { $editUrl = ''; // If member has an object linked, take object edit url if ($ot = ObjectTypes::findById($m->getObjectTypeId())) { if ($handler = $ot->getHandlerClass()) { eval("\$itemClass = {$handler}::instance()->getItemClass();"); if ($itemClass) { $instance = new $itemClass(); $instance->setId($m->getObjectId()); $instance->setObjectId($m->getObjectId()); if ($instance instanceof Contact) { if ($ot->getName() == 'company') { $instance->setIsCompany(1); } } $editUrl = $instance->getEditUrl(); } } } // Take default membewr edit url if not overwitten if (!$editUrl) { $editUrl = get_url('member', 'edit', array('id' => $m->getId())); } $member['actions'] = array(array('url' => $editUrl, 'text' => '', 'iconCls' => 'ico-edit', 'class' => 'action-edit')); } } $members[] = $member; } // re-sort by parent and name $tmp_members = array(); foreach ($members as $m) { $tmp_members[str_pad(array_var($m, 'depth'), 20, "0", STR_PAD_LEFT) . strtolower(array_var($m, 'name')) . array_var($m, 'id')] = $m; } ksort($tmp_members, SORT_STRING); $members = $tmp_members; return $members; }
function unarchive() { if (!can_manage_dimension_members(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $member = Members::findById(get_id()); if (!$member instanceof Member) { flash_error(lang('member dnx')); ajx_current("empty"); return; } if (get_id('user')) { $user = Contacts::findById($get_id('user')); } else { $user = logged_user(); } if (!$user instanceof Contact) { ajx_current("empty"); return; } try { DB::beginWork(); set_time_limit(0); $count = $member->unarchive($user); evt_add("reload dimension tree", $member->getDimensionId()); ajx_current("back"); flash_success(lang('success unarchive member', $member->getName(), $count)); DB::commit(); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); ajx_current("empty"); } }
function save_permission_group() { ajx_current("empty"); if (!can_manage_dimension_members(logged_user())) { flash_error(lang('no access permissions')); return; } $member = Members::findById(array_var($_REQUEST, 'member_id')); if (!$member instanceof Member) { flash_error(lang('member dnx')); return; } $members = array($member); // if apply to submembers is checked get submembers verifying logged user permissions if (array_var($_REQUEST, 'apply_submembers') > 0) { $dimension = $member->getDimension(); $pg_ids_str = implode(',', logged_user()->getPermissionGroupIds()); $extra_conditions = ""; if (!$dimension->hasAllowAllForContact($pg_ids_str)) { $extra_conditions = " AND EXISTS (SELECT cmp.member_id FROM " . TABLE_PREFIX . "contact_member_permissions cmp \r\n\t\t\t\t\tWHERE cmp.member_id=" . TABLE_PREFIX . "members.id AND cmp.permission_group_id IN (" . $pg_ids_str . "))"; } $childs = $member->getAllChildren(true, null, $extra_conditions); $members = array_merge($members, $childs); } $pg_id = array_var($_REQUEST, 'pg_id'); $permissions = array_var($_REQUEST, 'perms'); $all_permissions = array(); foreach ($members as $member) { $all_permissions[$member->getId()] = json_decode($permissions); foreach ($all_permissions[$member->getId()] as &$perm) { $perm->m = $member->getId(); } } $all_permissions_str = json_encode(array_flat($all_permissions)); $_POST['permissions'] = $all_permissions_str; try { DB::beginWork(); $_POST['root_perm_genid'] = 'dummy_root_perm_genid'; save_user_permissions_background(logged_user(), $pg_id, false, array(), true); $null = null; Hook::fire('after_save_member_permissions_for_pg', $_REQUEST, $null); DB::commit(); flash_success(lang("permissions successfully saved")); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); } }
$icons[] = array('ico' => 'ico-large-configuration', 'url' => get_url('administration', 'configuration'), 'name' => lang('configuration'), 'extra' => ''); $icons[] = array('ico' => 'ico-large-tools', 'url' => get_url('administration', 'tools'), 'name' => lang('administration tools'), 'extra' => ''); /*FIXME if (!defined('ALLOW_UPGRADING') || ALLOW_UPGRADING) { $icons[] = array( 'ico' => 'ico-large-upgrade', 'url' => get_url('administration', 'upgrade'), 'name' => lang('upgrade'), 'extra' => '', ); }*/ if (!defined('ALLOW_CONFIGURING_CRON') || ALLOW_CONFIGURING_CRON) { $icons[] = array('ico' => 'ico-large-cron', 'url' => get_url('administration', 'cron_events'), 'name' => lang('cron events'), 'extra' => ''); } $icons[] = array('ico' => 'ico-large-tabs', 'url' => get_url('administration', 'tabs'), 'name' => lang('tabs'), 'extra' => ''); } if (can_manage_dimension_members(logged_user())) { $icons[] = array('ico' => 'ico-large-workspace', 'url' => get_url('administration', 'edit_members'), 'name' => lang('dimensions'), 'extra' => ''); } if (can_manage_security(logged_user()) && Plugins::instance()->isActivePlugin('income')) { $icons[] = array('ico' => 'ico-large-invoice', 'url' => get_url('income', 'administration'), 'name' => lang('income'), 'extra' => ''); } if (defined("PLUGIN_MANAGER") && PLUGIN_MANAGER && can_manage_plugins(logged_user())) { $icons[] = array('ico' => 'ico-large-plugins', 'url' => get_url('plugin', 'index'), 'name' => lang('plugins'), 'extra' => ''); } Hook::fire('render_administration_icons', null, $icons); if (count($icons > 0)) { } ?> <div class="coInputHeader"> <div class="coInputHeaderUpperRow">
/** * Add/edit Dimension Members * * @access public * @param void * @return null */ function edit_members() { if (!can_manage_dimension_members(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $dimensions = Dimensions::findAll(array('conditions' => '`is_manageable` = 1')); $members = array(); $logged_user_pgs = implode(',', logged_user()->getPermissionGroupIds()); foreach ($dimensions as $dim) { //if ($dim->deniesAllForContact($logged_user_pgs)) continue; $allows_all = $dim->hasAllowAllForContact($logged_user_pgs); $root_members = Members::findAll(array('conditions' => array('`dimension_id`=? AND `parent_member_id`=0', $dim->getId()), 'order' => '`name` ASC')); foreach ($root_members as $mem) { if ($dim->getDefinesPermissions() && !$allows_all) { if (!$mem->canBeReadByContact($logged_user_pgs, logged_user())) { continue; } } $members[$dim->getId()][] = $mem; $members[$dim->getId()] = array_merge($members[$dim->getId()], $mem->getAllChildrenSorted()); } } tpl_assign('members', $members); tpl_assign('dimensions', $dimensions); }
/** * Add/edit Dimension Members * * @access public * @param void * @return null */ function edit_members() { if (!can_manage_dimension_members(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $dimensions = Dimensions::findAll(array('conditions' => '`is_manageable` = 1')); $members = array(); foreach ($dimensions as $dim) { $dimensions = Dimensions::findAll(array('conditions' => '`is_manageable` = 1')); $members = array(); foreach ($dimensions as $dim) { $root_members = Members::findAll(array('conditions' => array('`dimension_id`=? AND `parent_member_id`=0', $dim->getId()), 'order' => '`name` ASC')); foreach ($root_members as $mem) { $members[$dim->getId()][] = $mem; $members[$dim->getId()] = array_merge($members[$dim->getId()], $mem->getAllChildrenSorted()); } } } tpl_assign('members', $members); tpl_assign('dimensions', $dimensions); }
function buildMemberList($all_members, $dimension, $allowed_member_type_ids, $allowed_object_type_ids, $item_object, $object_type_id, $return_only_name=false) { $dot_array = array(); // Dimension Object Types array (cache) $membersset = array(); foreach ($all_members as $m) { $membersset[$m->getId()] = true; } $members = array(); foreach ($all_members as $m) { /* @var $m Member */ if ($m->getArchivedById() > 0) continue; if ($object_type_id != null){ $selectable = in_array($m->getObjectTypeId(), $allowed_object_type_ids) ? true : false; if ($selectable && isset($item_object)) { if (! $item_object->canAdd(logged_user(), array($m)) ) continue; } }else{ $selectable = true ; } if ( count($allowed_member_type_ids) && !in_array($m->getObjectTypeId(), $allowed_member_type_ids) ) { continue; } $tempParent = $m->getParentMemberId(); $x = $m; while ($x instanceof Member && !isset($membersset[$tempParent])) { $tempParent = $x->getParentMemberId(); if ($x->getParentMemberId() == 0) break; $x = $x->getParentMember(); } if (!$x instanceof Member) { $tempParent = 0; } $memberOptions = ''; // SET member options (dimension object types table) // CHeck dot cache, if not set goto database and add to cache if ( empty($dot_array[$dimension->getId()]) || empty ($dot_array[$dimension->getId()][$m->getObjectTypeId()]) ) { $dot = DimensionObjectTypes::instance()->findOne(array("conditions" =>"dimension_id = ".$dimension->getId() ." AND object_type_id = ".$m->getObjectTypeId())); if ($dot instanceof DimensionObjectType){ if (empty($dot_array['dimension_id'])) { $dot_array[$dimension->getId()] = array(); } $dot_array[$dimension->getId()][$m->getObjectTypeId()] = $dot; } } if ( !empty($dot_array[$dimension->getId()]) || ($dot_array[$dimension->getId()][$m->getObjectTypeId()]) instanceof DimensionObjectType ) { $dot = $dot_array[$dimension->getId()][$m->getObjectTypeId()]; $memberOptions = $dot->getOptions(true); } if ($return_only_name) { $path = trim($m->getPath()); $member = array( "id" => $m->getId(), "name" => $m->getName(), "path" => $path, "to_show" => $m->getName() . ($path != "" ? " ($path)" : ""), "dim" => $m->getDimensionId(), "ico" => $m->getIconClass(), ); } else { /* @var $m Member */ $member = array( "id" => $m->getId(), "name" => clean($m->getName()), "parent" => $tempParent, "realParent" => $m->getParentMemberId(), "object_id" => $m->getObjectId(), "options" => $memberOptions, "depth" => $m->getDepth(), "iconCls" => $m->getIconClass(), "selectable" => isset($selectable) ? $selectable : false, "dimension_id" => $m->getDimensionId(), "object_type_id" => $m->getObjectTypeId(), "allow_childs" => $m->allowChilds() ); // Member Actions if (can_manage_dimension_members(logged_user())){ $editUrl = ''; // If member has an object linked, take object edit url if ($ot = ObjectTypes::findById($m->getObjectTypeId())) { if ($handler = $ot->getHandlerClass() ){ eval ("\$itemClass = $handler::instance()->getItemClass();"); if ($itemClass) { $instance = new $itemClass(); $instance->setId($m->getObjectId()); $instance->setObjectId($m->getObjectId()); if ($instance instanceof Contact) { if ($ot->getName() == 'company') $instance->setIsCompany(1); } $editUrl = $instance->getEditUrl(); } } } // Take default membewr edit url if not overwitten if (!$editUrl) { $editUrl = get_url('member', 'edit', array('id'=> $m->getId())); } $member['actions'] = array(array( 'url' => $editUrl, 'text' => '', 'iconCls' => 'ico-edit', 'class' => 'action-edit' )); } } $members[] = $member; } // re-sort by parent and name $tmp_members = array(); foreach ($members as $m) { $tmp_members[array_var($m, 'parent') . strtolower(array_var($m, 'name')) . array_var($m, 'id')] = $m; } ksort($tmp_members, SORT_STRING); $members = $tmp_members; return $members ; }
function buildMemberList($all_members, $dimension, $allowed_member_type_ids, $allowed_object_type_ids, $item_object, $object_type_id) { $dot_array = array(); // Dimensio Object Types array (cache) $start_time = microtime(1); $membersset = array(); foreach ($all_members as $m) { $membersset[$m->getId()] = true; } $members = array(); foreach ($all_members as $m) { /* @var $m Member */ if ($m->getArchivedById() > 0) { continue; } if ($object_type_id != null) { $selectable = in_array($m->getObjectTypeId(), $allowed_object_type_ids) ? true : false; if ($selectable && isset($item_object)) { if (!$item_object->canAdd(logged_user(), array($m))) { continue; } } } else { $selectable = true; } if (count($allowed_member_type_ids) && !in_array($m->getObjectTypeId(), $allowed_member_type_ids)) { continue; } $tempParent = $m->getParentMemberId(); $x = $m; while ($x instanceof Member && !isset($membersset[$tempParent])) { $tempParent = $x->getParentMemberId(); $x = $x->getParentMember(); } if (!$x instanceof Member) { $tempParent = 0; } $memberOptions = ''; // SET member options (dimension object types table) // CHeck dot cache, if not set goto database and add to cache if (empty($dot_array[$dimension->getId()]) || empty($dot_array[$dimension->getId()][$m->getObjectTypeId()])) { if ($dot = DimensionObjectTypes::instance()->findOne(array("conditions" => "\n\t\t\t\t\tdimension_id = " . $dimension->getId() . " AND\n\t\t\t\t\tobject_type_id = " . $m->getObjectTypeId()))) { if (empty($dot_array['dimension_id'])) { $dot_array[$dimension->getId()] = array(); } $dot_array[$dimension->getId()][$m->getObjectTypeId()] = $dot; } } if (!empty($dot_array[$dimension->getId()]) || $dot_array[$dimension->getId()][$m->getObjectTypeId()] instanceof DimensionObjectType) { $dot = $dot_array[$dimension->getId()][$m->getObjectTypeId()]; $memberOptions = $dot->getOptions(true); } /* @var $m Member */ $member = array("id" => $m->getId(), "name" => clean($m->getName()), "parent" => $tempParent, "realParent" => $m->getParentMemberId(), "object_id" => $m->getObjectId(), "options" => $memberOptions, "depth" => $m->getDepth(), "iconCls" => $m->getIconClass(), "selectable" => isset($selectable) ? $selectable : false, "dimension_id" => $m->getDimensionId(), "object_type_id" => $m->getObjectTypeId(), "allow_childs" => $m->allowChilds()); // Member Actions if (can_manage_dimension_members(logged_user())) { $editUrl = ''; // If member has an object linked, take object edit url if ($otid = $m->getObjectTypeId()) { if ($ot = ObjectTypes::findById($otid)) { if ($handler = $ot->getHandlerClass()) { eval("\$itemClass = {$handler}::instance()->getItemClass();"); if ($itemClass) { $instance = new $itemClass(); $instance->setId($m->getObjectId()); $instance->setObjectId($m->getObjectId()); if ($instance) { $editUrl = $instance->getEditUrl(); } } } } } // Take default membewr edit url if not overwitten if (!$editUrl) { $editUrl = get_url('member', 'edit', array('id' => $m->getId())); } $member['actions'] = array(array('url' => $editUrl, 'text' => '', 'iconCls' => 'ico-edit')); } $members[] = $member; } return $members; }
$add_ctx_members = true; $context = active_context(); if(isset($context)){ foreach ($context as $selection) { if ($selection instanceof Dimension && $selection->getCode() == 'workspaces') { $add_ctx_members = false; } else if ($selection instanceof Member && $selection->getObjectTypeId() == Workspaces::instance()->getObjectTypeId()) { $allowed_members[] = $selection->getId(); $selected_ws = $selection->getId(); } } } $extra_conditions = " AND parent_member_id " . ($add_ctx_members && count($allowed_members) > 0 ? "IN (". implode(",", $allowed_members) .")" : "=0"); $workspaces = $dim_controller->initial_list_dimension_members($ws_dimension->getId(), null, null, false, $extra_conditions, $total, true); $parent = null; $context = active_context(); foreach ($context as $selection) { if ($selection instanceof Member && $selection->getDimensionId() == $ws_dimension->getId()) { $parent = $selection; break; } } if ((is_array($workspaces) && count($workspaces) > 0) || can_manage_dimension_members(logged_user())) { $data_ws = $workspaces; include_once 'template.php'; }