/**
  * Init company based on subdomain
  *
  * @access public
  * @param string
  * @return null
  * @throws Error
  */
 private function initCompany()
 {
     $company = Companies::getOwnerCompany();
     if (!$company instanceof Company) {
         throw new OwnerCompanyDnxError();
     }
     // if
     // check the cache if available
     $owner = null;
     if (GlobalCache::isAvailable()) {
         $owner = GlobalCache::get('owner_company_creator', $success);
     }
     if (!$owner instanceof User) {
         $owner = $company->getCreatedBy();
         // Update cache if available
         if ($owner instanceof User && GlobalCache::isAvailable()) {
             GlobalCache::update('owner_company_creator', $owner);
         }
     }
     if (!$owner instanceof User) {
         throw new AdministratorDnxError();
     }
     // if
     $this->setCompany($company);
 }
 /**
  * Init company based on subdomain
  *
  * @access public
  * @param string
  * @return null
  * @throws Error
  */
 private function initCompany()
 {
     $company = Companies::getOwnerCompany();
     if (!$company instanceof Company) {
         throw new OwnerCompanyDnxError();
     }
     // if
     if (!$company->getCreatedBy() instanceof User) {
         throw new AdministratorDnxError();
     }
     // if
     $this->setCompany($company);
 }
 /**
  * Init company based on subdomain
  *
  * @access public
  * @param string
  * @return null
  * @throws Error
  */
 private function initCompany()
 {
     trace(__FILE__, 'initCompany()');
     $company = Companies::getOwnerCompany();
     trace(__FILE__, 'initCompany() - company check');
     if (!$company instanceof Company) {
         throw new OwnerCompanyDnxError();
     }
     // if
     trace(__FILE__, 'initCompany() - admin check');
     if (!$company->getCreatedBy() instanceof User) {
         throw new AdministratorDnxError();
     }
     // if
     trace(__FILE__, 'initCompany() - setCompany()');
     $this->setCompany($company);
 }
Example #4
0
/**
 * Tells whether a user can assign a task to another user or company in a workspace.
 * 
 * @param $user User to which to check permissions
 * @param $workspace
 * @param $assignee
 * @return boolean
 */
function can_assign_task(User $user, Project $workspace, $assignee)
{
    if (!$assignee instanceof User && !$assignee instanceof Company) {
        return true;
    }
    if ($assignee instanceof Company) {
        $company = $assignee;
    } else {
        if ($assignee->getId() == $user->getId()) {
            return true;
        }
        // alow user to assign to himself
        $company = $assignee->getCompany();
    }
    $is_owner = $company->getId() == Companies::getOwnerCompany()->getId();
    $permissions = ProjectUsers::getByUserAndProject($workspace, $user);
    if ($permissions instanceof ProjectUser) {
        if ($is_owner) {
            if ($permissions->getCanAssignToOwners()) {
                return true;
            }
        } else {
            if ($permissions->getCanAssignToOther()) {
                return true;
            }
        }
    }
    $groups = GroupUsers::getGroupsByUser($user->getId());
    if (is_array($groups) && count($groups) > 0) {
        //user belongs to at least one group
        foreach ($groups as $group) {
            $permissions = ProjectUsers::getByUserAndProject($workspace, $group);
            if ($permissions instanceof ProjectUser) {
                if ($is_owner) {
                    if ($permissions->getCanAssignToOwners()) {
                        return true;
                    }
                } else {
                    if ($permissions->getCanAssignToOther()) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 /**
  * Finish the installation - create owner company and administrator
  *
  * @param void
  * @return null
  */
 function complete_installation()
 {
     if (Companies::getOwnerCompany() instanceof Company) {
         die('Owner company already exists');
         // Somebody is trying to access this method even if the user already exists
     }
     // if
     $this->setLayout('complete_install');
     $form_data = array_var($_POST, 'form');
     tpl_assign('form_data', $form_data);
     if (array_var($form_data, 'submitted') == 'submitted') {
         try {
             $admin_password = trim(array_var($form_data, 'admin_password'));
             $admin_password_a = trim(array_var($form_data, 'admin_password_a'));
             if (trim($admin_password) == '') {
                 throw new Error(lang('password value required'));
             }
             // if
             if ($admin_password != $admin_password_a) {
                 throw new Error(lang('passwords dont match'));
             }
             // if
             DB::beginWork();
             Users::delete();
             // clear users table
             Companies::delete();
             // clear companies table
             // Create the administrator user
             $administrator = new User();
             $administrator->setId(1);
             $administrator->setUsername(array_var($form_data, 'admin_username'));
             $administrator->setEmail(array_var($form_data, 'admin_email'));
             $administrator->setPassword($admin_password);
             $administrator->setIsAdmin(true);
             $administrator->setAutoAssign(true);
             $administrator->save();
             // Create the contact for administrator
             $administrator_contact = new Contact();
             $administrator_contact->setId(1);
             $administrator_contact->setCompanyId(1);
             $administrator_contact->setEmail(array_var($form_data, 'admin_email'));
             $administrator_contact->setUserId($administrator->getId());
             $administrator_contact->setDisplayName($administrator->getUsername());
             $administrator_contact->save();
             // Create a company
             $company = new Company();
             $company->setId(1);
             $company->setClientOfId(0);
             $company->setName(array_var($form_data, 'company_name'));
             $company->setCreatedById(1);
             $company->save();
             DB::commit();
             $this->redirectTo('access', 'login');
         } catch (Exception $e) {
             tpl_assign('error', $e);
             DB::rollback();
         }
         // try
     }
     // if
 }
 /**
  * Finish the installation - create owner company and administrator
  *
  * @param void
  * @return null
  */
 function complete_installation()
 {
     if (Companies::getOwnerCompany() instanceof Company) {
         die('Owner company already exists');
         // Somebody is trying to access this method even if the user already exists
     }
     // if
     $form_data = array_var($_POST, 'form');
     tpl_assign('form_data', $form_data);
     if (array_var($form_data, 'submited') == 'submited') {
         try {
             $admin_password = trim(array_var($form_data, 'admin_password'));
             $admin_password_a = trim(array_var($form_data, 'admin_password_a'));
             if (trim($admin_password) == '') {
                 throw new Error(lang('password value required'));
             }
             // if
             if ($admin_password != $admin_password_a) {
                 throw new Error(lang('passwords dont match'));
             }
             // if
             DB::beginWork();
             Users::delete();
             // clear users table
             Companies::delete();
             // clear companies table
             // Create the administrator user
             $administrator = new User();
             $administrator->setId(1);
             $administrator->setCompanyId(1);
             $administrator->setUsername(array_var($form_data, 'admin_username'));
             $administrator->setEmail(array_var($form_data, 'admin_email'));
             $administrator->setPassword($admin_password);
             $administrator->setCanEditCompanyData(true);
             $administrator->setCanManageConfiguration(true);
             $administrator->setCanManageSecurity(true);
             $administrator->setCanManageWorkspaces(true);
             $administrator->setCanManageContacts(true);
             $administrator->setCanManageTemplates(true);
             $administrator->setCanManageReports(true);
             $administrator->setCanManageTime(true);
             $administrator->setCanAddMailAccounts(true);
             $administrator->setAutoAssign(false);
             $administrator->setPersonalProjectId(1);
             $administrator->setType('admin');
             $administrator->save();
             $group = new Group();
             $group->setName('administrators');
             $group->setAllPermissions(true);
             $group->setId(Group::CONST_ADMIN_GROUP_ID);
             $group->save();
             $group_user = new GroupUser();
             $group_user->setGroupId(Group::CONST_ADMIN_GROUP_ID);
             $group_user->setUserId($administrator->getId());
             $group_user->save();
             $project = new Project();
             $project->setId(1);
             $project->setP1(1);
             $project->setName(new_personal_project_name($administrator->getUsername()));
             $project->setDescription(lang('files'));
             $project->setCreatedById($administrator->getId());
             $project->save();
             $project_user = new ProjectUser();
             $project_user->setProjectId($project->getId());
             $project_user->setUserId($administrator->getId());
             $project_user->setCreatedById($administrator->getId());
             $project_user->setAllPermissions(true);
             $project_user->save();
             // Create a company
             $company = new Company();
             $company->setId(1);
             $company->setClientOfId(0);
             $company->setName(array_var($form_data, 'company_name'));
             $company->setCreatedById(1);
             $company->save();
             DB::commit();
             $this->redirectTo('access', 'login');
         } catch (Exception $e) {
             tpl_assign('error', $e);
             DB::rollback();
         }
         // try
     }
     // if
 }