Exemplo n.º 1
0
 function index()
 {
     $tasksUserId = array_var($_GET, 'tu');
     if (is_null($tasksUserId)) {
         $tasksUserId = user_config_option('TM tasks user filter', logged_user()->getId());
     } else {
         if (user_config_option('TM tasks user filter') != $tasksUserId) {
             set_user_config_option('TM tasks user filter', $tasksUserId, logged_user()->getId());
         }
     }
     $timeslotsUserId = array_var($_GET, 'tsu');
     if (is_null($timeslotsUserId)) {
         $timeslotsUserId = user_config_option('TM user filter', 0);
     } else {
         if (user_config_option('TM user filter') != $timeslotsUserId) {
             set_user_config_option('TM user filter', $timeslotsUserId, logged_user()->getId());
         }
     }
     $showTimeType = array_var($_GET, 'stt');
     if (is_null($showTimeType)) {
         $showTimeType = user_config_option('TM show time type', 0);
     } else {
         if (user_config_option('TM show time type') != $showTimeType) {
             set_user_config_option('TM show time type', $showTimeType, logged_user()->getId());
         }
     }
     $start = array_var($_GET, 'start', 0);
     $limit = 20;
     $tasksUser = Contacts::findById($tasksUserId);
     $timeslotsUser = Contacts::findById($timeslotsUserId);
     //Active tasks view
     $open_timeslots = Timeslots::instance()->listing(array("extra_conditions" => " AND end_time = '" . EMPTY_DATETIME . "' AND contact_id = " . $tasksUserId))->objects;
     $tasks = array();
     foreach ($open_timeslots as $open_timeslot) {
         $task = ProjectTasks::findById($open_timeslot->getRelObjectId());
         if ($task instanceof ProjectTask && !$task->isCompleted() && !$task->isTrashed() && !$task->isArchived()) {
             $tasks[] = $task;
         }
     }
     ProjectTasks::populateTimeslots($tasks);
     //Timeslots view
     $total = 0;
     switch ($showTimeType) {
         case 0:
             //Show only timeslots added through the time panel
             $result = Timeslots::getGeneralTimeslots(active_context(), $timeslotsUser, $start, $limit);
             $timeslots = $result->objects;
             $total = $result->total;
             break;
         default:
             throw new Error('Unrecognised TM show time type: ' . $showTimeType);
     }
     //Get Users Info
     $users = array();
     $context = active_context();
     if (!can_manage_time(logged_user())) {
         if (can_add(logged_user(), $context, Timeslots::instance()->getObjectTypeId())) {
             $users = array(logged_user());
         }
     } else {
         if (logged_user()->isMemberOfOwnerCompany()) {
             $users = Contacts::getAllUsers();
         } else {
             $users = logged_user()->getCompanyId() > 0 ? Contacts::getAllUsers(" AND `company_id` = " . logged_user()->getCompanyId()) : array(logged_user());
         }
         $tmp_users = array();
         foreach ($users as $user) {
             if (can_add($user, $context, Timeslots::instance()->getObjectTypeId())) {
                 $tmp_users[] = $user;
             }
         }
         $users = $tmp_users;
     }
     //Get Companies Info
     if (logged_user()->isMemberOfOwnerCompany() || logged_user()->isAdminGroup()) {
         $companies = Contacts::getCompaniesWithUsers();
     } else {
         $companies = array();
         if (logged_user()->getCompanyId() > 0) {
             $companies[] = logged_user()->getCompany();
         }
     }
     $required_dimensions = DimensionObjectTypeContents::getRequiredDimensions(Timeslots::instance()->getObjectTypeId());
     $draw_inputs = !$required_dimensions || count($required_dimensions) == 0;
     if (!$draw_inputs) {
         $ts_ots = DimensionObjectTypeContents::getDimensionObjectTypesforObject(Timeslots::instance()->getObjectTypeId());
         $context = active_context();
         foreach ($context as $sel) {
             if ($sel instanceof Member) {
                 foreach ($ts_ots as $ts_ot) {
                     if ($sel->getDimensionId() == $ts_ot->getDimensionId() && $sel->getObjectTypeId() == $ts_ot->getDimensionObjectTypeId()) {
                         $draw_inputs = true;
                         break;
                     }
                 }
                 if ($draw_inputs) {
                     break;
                 }
             }
         }
     }
     tpl_assign('draw_inputs', $draw_inputs);
     tpl_assign('selected_user', logged_user()->getId());
     tpl_assign('timeslots', $timeslots);
     tpl_assign('tasks', $tasks);
     if (count($tasks) > 0) {
         tpl_assign('all_users', Contacts::getAllUsers());
     }
     tpl_assign('users', $users);
     tpl_assign('start', $start);
     tpl_assign('limit', $limit);
     tpl_assign('total', $total);
     tpl_assign('companies', $companies);
     ajx_set_no_toolbar(true);
 }
Exemplo n.º 2
0
/**
 * Return true if $user can add an object of type $object_type_id in $member. False otherwise.
 *
 * @param Contact $user
 * @param array $context
 * @param $object_type_id
 * @return boolean
 */
function can_add(Contact $user, $context, $object_type_id, &$notAllowedMember = '')
{
    if ($user->isGuest()) {
        return false;
    }
    $membersInContext = 0;
    $can_add = false;
    $required_dimensions_ids = DimensionObjectTypeContents::getRequiredDimensions($object_type_id);
    $dimensions_in_context = array();
    $no_required_dimensions = count($required_dimensions_ids) == 0;
    foreach ($required_dimensions_ids as $id) {
        $dimensions_in_context[$id] = false;
    }
    $contact_pg_ids = ContactPermissionGroups::getPermissionGroupIdsByContactCSV($user->getId(), false);
    if (is_array($context)) {
        foreach ($context as $selection) {
            $sel_dimension = $selection instanceof Dimension ? $selection : ($selection instanceof Member ? $selection->getDimension() : null);
            if ($sel_dimension instanceof Dimension && $sel_dimension->getOptions(1) && isset($sel_dimension->getOptions(1)->hidden) && $sel_dimension->getOptions(1)->hidden) {
                continue;
            }
            //$can_add = false;
            if ($selection instanceof Member) {
                $membersInContext++;
                if (can_add_to_member($user, $selection, $context, $object_type_id)) {
                    //if ($no_required_dimensions) return true;
                    $dimension_id = $selection->getDimensionId();
                    $can_add = true;
                    $dimensions_in_context[$dimension_id] = true;
                } else {
                    $notAllowedMember = $selection->getName();
                    return false;
                }
            }
            // Revoke explicty permission
            if ($can_add && !$no_required_dimensions) {
                foreach ($dimensions_in_context as $key => $value) {
                    $dim = Dimensions::getDimensionById($key);
                    if (!$value && $dim->getDefinesPermissions() && $dim->deniesAllForContact($contact_pg_ids)) {
                        $can_add = false;
                    }
                }
            }
        }
    }
    // All dimensions in 'all'.
    // If The object has no required dimensions, and no dimensions are selected: CAN ADD = True
    if ($no_required_dimensions && !$membersInContext) {
        $can_add = true;
    }
    // All dimensions in 'all'.
    // if there are required dimensions and no members selected then show correct error message.
    if (!$no_required_dimensions && !$membersInContext && !$can_add) {
        $dim_names = array();
        $required_dimensions = Dimensions::findAll(array('conditions' => 'id IN (' . implode(',', $required_dimensions_ids) . ')'));
        foreach ($required_dimensions as $dim) {
            $dim_names[] = $dim->getName();
        }
        $notAllowedMember = "-- req dim --" . implode(",", $dim_names);
    }
    return $can_add;
}
Exemplo n.º 3
0
 function canBeDeleted(&$error_message)
 {
     $childs = $this->getAllChildren();
     if (MemberPropertyMembers::isMemberAssociated($this->getId())) {
         $error_message = lang("cannot delete member is associated");
         return false;
     }
     $continue_check = false;
     if (count($childs) == 0) {
         $continue_check = true;
     } else {
         if ($this->getParentMemberId() > 0) {
             $child_ots = DimensionObjectTypeHierarchies::getAllChildrenObjectTypeIds($this->getDimensionId(), $this->getParentMember()->getObjectTypeId(), false);
         }
         foreach ($childs as $child) {
             // check if child can be put in the parent (or root)
             if ($this->getParentMemberId() == 0) {
                 $dim_ot = DimensionObjectTypes::findOne(array("conditions" => array("`dimension_id` = ? AND `object_type_id` = ?", $this->getDimensionId(), $child->getObjectTypeId())));
                 if (!$dim_ot->getIsRoot()) {
                     $error_message = lang("cannot delete member cannot be root");
                     return false;
                 }
             } else {
                 if (!in_array($child->getObjectTypeId(), $child_ots)) {
                     $error_message = lang("cannot delete member childs cannot be moved to parent");
                     return false;
                 }
             }
         }
         $continue_check = true;
     }
     if (!$continue_check) {
         return false;
     } else {
         $child_ids = $this->getAllChildrenIds();
         $child_ids[] = $this->getId();
         $child_ids_str = implode(",", $child_ids);
         $objects_in_member = ObjectMembers::instance()->findAll(array('conditions' => 'member_id = ' . $this->getId()));
         if (!$objects_in_member || count($objects_in_member) == 0) {
             return true;
         } else {
             $more_conditions = "";
             if (Plugins::instance()->isActivePlugin('core_dimensions')) {
                 $person_dim = Dimensions::findByCode('feng_persons')->getId();
                 $more_conditions = " AND member_id NOT IN (SELECT id FROM " . TABLE_PREFIX . "members WHERE dimension_id={$person_dim})";
             }
             $object_id_condition = $this->getObjectId() > 0 ? " AND o.id <> " . $this->getObjectId() : "";
             foreach ($objects_in_member as $om) {
                 $obj_members = ObjectMembers::findAll(array("conditions" => array("`object_id` = ? AND `is_optimization` = 0 AND member_id IN ({$child_ids_str}) AND EXISTS (SELECT o.id FROM " . TABLE_PREFIX . "objects o WHERE o.id = ? AND o.trashed_by_id=0 {$object_id_condition})" . $more_conditions, $om->getObjectId(), $om->getObjectId())));
                 if (count($obj_members) >= 1) {
                     $error_message = lang("cannot delete member has objects");
                     return false;
                 }
                 $db_res = DB::execute("SELECT object_type_id FROM " . TABLE_PREFIX . "objects WHERE id=" . $om->getObjectId());
                 $row = $db_res->fetchRow();
                 if ($row && array_var($row, 'object_type_id')) {
                     $req_dim_ids = DimensionObjectTypeContents::getRequiredDimensions(array_var($row, 'object_type_id'));
                     if (in_array($this->getDimensionId(), $req_dim_ids)) {
                         $error_message = lang("cannot delete member is required for objects");
                         return false;
                     }
                 }
             }
         }
     }
     return true;
 }
Exemplo n.º 4
0
/**
 * Return true if $user can add an object of type $object_type_id in $member. False otherwise.
 *
 * @param Contact $user
 * @param array $context
 * @param $object_type_id
 * @return boolean
 */
function can_add(Contact $user, $context, $object_type_id, &$notAllowedMember = '')
{
    if ($user->isGuest()) {
        return false;
    }
    $membersInContext = 0;
    $can_add = false;
    $required_dimensions_ids = DimensionObjectTypeContents::getRequiredDimensions($object_type_id);
    $dimensions_in_context = array();
    $no_required_dimensions = count($required_dimensions_ids) == 0;
    foreach ($required_dimensions_ids as $id) {
        $dimensions_in_context[$id] = false;
    }
    $enabled_dimensions = config_option('enabled_dimensions');
    $contact_pg_ids = ContactPermissionGroups::getPermissionGroupIdsByContactCSV($user->getId(), false);
    if (is_array($context)) {
        foreach ($context as $selection) {
            $sel_dimension = $selection instanceof Dimension ? $selection : ($selection instanceof Member ? $selection->getDimension() : null);
            //$can_add = false;
            if ($selection instanceof Member) {
                $dimension = $selection->getDimension();
                if (!$dimension->getDefinesPermissions() || !in_array($dimension->getId(), $enabled_dimensions)) {
                    continue;
                }
                $membersInContext++;
                if (can_add_to_member($user, $selection, $context, $object_type_id)) {
                    //if ($no_required_dimensions) return true;
                    $dimension_id = $selection->getDimensionId();
                    $can_add = true;
                    $dimensions_in_context[$dimension_id] = true;
                } else {
                    $notAllowedMember = $selection->getName();
                    return false;
                }
            }
            // Revoke explicty permission
            if ($can_add && !$no_required_dimensions) {
                foreach ($dimensions_in_context as $key => $value) {
                    $dim = Dimensions::getDimensionById($key);
                    if (!$value && $dim->getDefinesPermissions() && $dim->deniesAllForContact($contact_pg_ids)) {
                        $can_add = false;
                    }
                }
            }
        }
    }
    // All dimensions in 'all'.
    // If The object has no required dimensions, and no dimensions are selected: check for contact_member_permissions with member_id=0
    if ($no_required_dimensions && $membersInContext == 0) {
        $mailot = ObjectTypes::findByName('mail');
        if ($mailot instanceof ObjectType && $mailot->getId() == $object_type_id) {
            $can_add = true;
        } else {
            $can_add = false;
            if (config_option('let_users_create_objects_in_root') && $contact_pg_ids != '' && ($user->isAdminGroup() || $user->isExecutive() || $user->isManager())) {
                $cmp = ContactMemberPermissions::findOne(array('conditions' => 'member_id=0 AND object_type_id=' . $object_type_id . ' AND permission_group_id IN (' . $contact_pg_ids . ')'));
                $can_add = $cmp instanceof ContactMemberPermission && $cmp->getCanWrite();
            }
        }
    }
    // All dimensions in 'all'.
    // if there are required dimensions and no members selected then show correct error message.
    if (!$no_required_dimensions && $membersInContext == 0 && !$can_add) {
        $dim_names = array();
        $required_dimensions = Dimensions::findAll(array('conditions' => 'id IN (' . implode(',', $required_dimensions_ids) . ')'));
        foreach ($required_dimensions as $dim) {
            $dim_names[] = $dim->getName();
        }
        $notAllowedMember = "-- req dim --" . implode(",", $dim_names);
    }
    return $can_add;
}