function getPermissionsForProjectUser(ProjectUser $project_user)
 {
     $permissions = array();
     $pups = ProjectUserPermissions::findAll(array('conditions' => '`project_id` = ' . $project_user->getProjectId() . ' and `user_id` = ' . $project_user->getUserId()));
     if (is_array($pups)) {
         foreach ($pups as $pup) {
             $permissions[] = Permissions::getPermissionString($pup->getPermissionId());
         }
     }
     //if
     return $permissions;
 }
 /**
  *
  * @param array $user
  * @param integer $project_id
  * @param array $roles 
  */
 public function addRoles($users, $project_id, $roles)
 {
     foreach ($users as $user_id => $value) {
         foreach ($roles as $role_id => $value) {
             $item = new ProjectUser();
             $item->user_id = $user_id;
             $item->project_id = $project_id;
             $item->role_id = $role_id;
             $item->save();
         }
     }
 }
 public static function onFailure($exception, $job)
 {
     ResqueUtil::log('[OnFailure]Job ' . CJSON::encode($job->payload['args'][0]['email']) . ' failed with exception ' . $exception);
     $userId = $job->payload['args'][0]['id'];
     User::model()->deleteByPk($userId);
     RoleUser::model()->deleteAllByAttributes(array('user' => $userId));
     ProjectUser::model()->deleteAllByAttributes(array('user' => $userId));
     Validation::model()->deleteAllByAttributes(array('code' => $job->payload['args'][0]['code']));
 }
Esempio n. 4
0
 public function addProjectUser(ProjectUser $l)
 {
     $this->collProjectUsers[] = $l;
     $l->setsfGuardUser($this);
 }
Esempio n. 5
0
// must be valid deadline or empty
$formattedDeadline = strtotime($deadline);
if ($formattedDeadline === false && $deadline != '') {
    $json = array('error' => 'Deadline must be a valid date or empty.');
    exit(json_encode($json));
}
// format deadline for MYSQL
$formattedDeadline = $formattedDeadline != '' ? date("Y-m-d H:i:s", $formattedDeadline) : null;
// format private
$private = empty($private) ? 0 : 1;
// create the project
$project = new Project(array('creator_id' => Session::getUserID(), 'title' => $title, 'slug' => '', 'pitch' => $pitch, 'specs' => $specs, 'rules' => $rules, 'status' => Project::STATUS_PRE_PRODUCTION, 'deadline' => $formattedDeadline, 'private' => $private));
$project->save();
// generate slug from project title/ID
$slug = toAscii($title);
$slug = $project->getID() . '-' . $slug;
// save new slug
$project->setSlug($slug);
$project->save();
// add creator as ProjectUser
$pu = new ProjectUser(array('project_id' => $project->getID(), 'user_id' => Session::getUserID(), 'relationship' => ProjectUser::CREATOR));
$pu->save();
// log it
$logEvent = new Event(array('event_type_id' => 'create_project', 'project_id' => $project->getID(), 'user_1_id' => Session::getUserID()));
$logEvent->save();
// send us back
//$successURL = Url::project($project->getID());
$successURL = Url::peopleInvite($project->getID());
Session::setMessage('Project created! Now you need some members.');
$json = array('success' => '1', 'successUrl' => $successURL);
echo json_encode($json);
 /**
  * Show permission update form
  *
  * @param void
  * @return null
  */
 function permissions()
 {
     if (!active_project()->canChangePermissions(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectToUrl(active_project()->getOverviewUrl());
     }
     // if
     $project_init = array_var($_GET, 'project_init');
     tpl_assign('project_init', $project_init);
     tpl_assign('project_users', active_project()->getUsers(false));
     tpl_assign('project_companies', active_project()->getCompanies());
     tpl_assign('user_projects', logged_user()->getProjects());
     $permissions = PermissionManager::getPermissionsText();
     tpl_assign('permissions', $permissions);
     $companies = array(owner_company());
     $clients = owner_company()->getClientCompanies();
     if (is_array($clients)) {
         $companies = array_merge($companies, $clients);
     }
     // if
     tpl_assign('companies', $companies);
     if (array_var($_POST, 'process') == 'process') {
         try {
             DB::beginWork();
             active_project()->clearCompanies();
             active_project()->clearUsers();
             $companies = array(owner_company());
             $client_companies = owner_company()->getClientCompanies();
             if (is_array($client_companies)) {
                 $companies = array_merge($companies, $client_companies);
             }
             // if
             foreach ($companies as $company) {
                 // Company is selected!
                 if (array_var($_POST, 'project_company_' . $company->getId()) == 'checked') {
                     // Owner company is automaticly included so it does not need to be in project_companies table
                     if (!$company->isOwner()) {
                         $project_company = new ProjectCompany();
                         $project_company->setProjectId(active_project()->getId());
                         $project_company->setCompanyId($company->getId());
                         $project_company->save();
                     }
                     // if
                     $users = $company->getUsers();
                     if (is_array($users)) {
                         $counter = 0;
                         foreach ($users as $user) {
                             $user_id = $user->getId();
                             $counter++;
                             if (array_var($_POST, "project_user_{$user_id}") == 'checked') {
                                 $project_user = new ProjectUser();
                                 $project_user->setProjectId(active_project()->getId());
                                 $project_user->setUserId($user_id);
                                 foreach ($permissions as $permission => $permission_text) {
                                     // Owner company members have all permissions
                                     $permission_value = $company->isOwner() ? true : array_var($_POST, 'project_user_' . $user_id . '_' . $permission) == 'checked';
                                     $setter = 'set' . Inflector::camelize($permission);
                                     $project_user->{$setter}($permission_value);
                                 }
                                 // if
                                 $project_user->save();
                             }
                             // if
                         }
                         // foreach
                     }
                     // if
                 }
                 // if
             }
             // foreach
             DB::commit();
             flash_success(lang('success update project permissions'));
             if ($project_init) {
                 $this->redirectToUrl(active_project()->getEditUrl(active_project()->getOverviewUrl()));
             } else {
                 $this->redirectTo('project_settings', 'users');
             }
             // if
         } catch (Exception $e) {
             DB::rollback();
             flash_error(lang('error update project permissions'));
             $this->redirectTo('project_settings', 'permissions');
         }
         // try
     }
     // if
 }
 /**
  * Add user
  *
  * @access public
  * @param void
  * @return null
  */
 function add()
 {
     $this->setTemplate('add_user');
     $company = Companies::findById(get_id('company_id'));
     if (!$company instanceof Company) {
         flash_error(lang('company dnx'));
         $this->redirectTo('administration');
     }
     // if
     if (!User::canAdd(logged_user(), $company)) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     $user = new User();
     $user_data = array_var($_POST, 'user');
     if (!is_array($user_data)) {
         $user_data = array('password_generator' => 'random', 'company_id' => $company->getId(), 'timezone' => $company->getTimezone());
         // array
     }
     // if
     $projects = $company->getProjects();
     $permissions = PermissionManager::getPermissionsText();
     tpl_assign('user', $user);
     tpl_assign('company', $company);
     tpl_assign('projects', $projects);
     tpl_assign('permissions', $permissions);
     tpl_assign('user_data', $user_data);
     if (is_array(array_var($_POST, 'user'))) {
         $user->setFromAttributes($user_data);
         $user->setCompanyId($company->getId());
         try {
             // Generate random password
             if (array_var($user_data, 'password_generator') == 'random') {
                 $password = substr(sha1(uniqid(rand(), true)), rand(0, 25), 13);
                 // Validate user input
             } else {
                 $password = array_var($user_data, 'password');
                 if (trim($password) == '') {
                     throw new Error(lang('password value required'));
                 }
                 // if
                 if ($password != array_var($user_data, 'password_a')) {
                     throw new Error(lang('passwords dont match'));
                 }
                 // if
             }
             // if
             $user->setPassword($password);
             if (config_option('check_email_unique', '1') == '1') {
                 if (!$user->validateUniquenessOf('email')) {
                     throw new Error(lang('email address is already used'));
                 }
             }
             DB::beginWork();
             $user->save();
             ApplicationLogs::createLog($user, null, ApplicationLogs::ACTION_ADD);
             if (is_array($projects)) {
                 foreach ($projects as $project) {
                     if (array_var($user_data, 'project_permissions_' . $project->getId()) == 'checked') {
                         $relation = new ProjectUser();
                         $relation->setProjectId($project->getId());
                         $relation->setUserId($user->getId());
                         foreach ($permissions as $permission => $permission_text) {
                             $permission_value = array_var($user_data, 'project_permission_' . $project->getId() . '_' . $permission) == 'checked';
                             $user->setProjectPermission($project, $permission, $permission_value);
                         }
                         // foreach
                         $relation->save();
                     }
                     // if
                 }
                 // foreach
             }
             // if
             DB::commit();
             // Send notification...
             try {
                 if (array_var($user_data, 'send_email_notification')) {
                     Notifier::newUserAccount($user, $password);
                 }
                 // if
             } catch (Exception $e) {
             }
             // try
             // Add task to Welcome project...
             try {
                 if (array_var($user_data, 'add welcome task')) {
                     $task_data = array('text' => lang('welcome task text', $user->getName(), get_url('account', 'edit')), 'due date' => DateTimeValueLib::now() + 7 * 24 * 60 * 60, 'assigned_to_company_id' => $user->getCompanyId(), 'assigned_to_user_id' => $user->getId());
                     $task_list = ProjectTaskLists::instance()->findById(2, true);
                     DB::beginWork();
                     $task = new ProjectTask();
                     $task->setFromAttributes($task_data);
                     $task_list->attachTask($task);
                     $task->save();
                     DB::commit();
                 }
                 // if
             } catch (Exception $e) {
                 DB::rollback();
             }
             // try
             flash_success(lang('success add user', $user->getDisplayName()));
             $projects = $company->getProjects();
             if (is_array($projects) || count($projects)) {
                 $this->redirectToUrl(get_url('account', 'update_permissions', $user->getId()));
                 // Continue to permissions page
             }
             // if
             $this->redirectToUrl($company->getViewUrl());
         } catch (Exception $e) {
             DB::rollback();
             tpl_assign('error', $e);
         }
         // try
     }
     // if
 }
Esempio n. 8
0
function create_user($user_data, $permissionsString)
{
    $user = new User();
    $user->setUsername(array_var($user_data, 'username'));
    $user->setDisplayName(array_var($user_data, 'display_name'));
    $user->setEmail(array_var($user_data, 'email'));
    $user->setCompanyId(array_var($user_data, 'company_id'));
    $user->setType(array_var($user_data, 'type'));
    $user->setTimezone(array_var($user_data, 'timezone'));
    if (!logged_user() instanceof User || can_manage_security(logged_user())) {
        $user->setCanEditCompanyData(array_var($user_data, 'can_edit_company_data'));
        $user->setCanManageSecurity(array_var($user_data, 'can_manage_security'));
        $user->setCanManageWorkspaces(array_var($user_data, 'can_manage_workspaces'));
        $user->setCanManageConfiguration(array_var($user_data, 'can_manage_configuration'));
        $user->setCanManageContacts(array_var($user_data, 'can_manage_contacts'));
        $user->setCanManageTemplates(array_var($user_data, 'can_manage_templates'));
        $user->setCanManageReports(array_var($user_data, 'can_manage_reports'));
        $user->setCanManageTime(array_var($user_data, 'can_manage_time'));
        $user->setCanAddMailAccounts(array_var($user_data, 'can_add_mail_accounts'));
        $other_permissions = array();
        Hook::fire('add_user_permissions', $user, $other_permissions);
        foreach ($other_permissions as $k => $v) {
            $user->setColumnValue($k, array_var($user_data, $k));
        }
    }
    if (array_var($user_data, 'password_generator', 'random') == 'random') {
        // Generate random password
        $password = UserPasswords::generateRandomPassword();
    } else {
        // Validate input
        $password = array_var($user_data, 'password');
        if (trim($password) == '') {
            throw new Error(lang('password value required'));
        }
        // if
        if ($password != array_var($user_data, 'password_a')) {
            throw new Error(lang('passwords dont match'));
        }
        // if
    }
    // if
    $user->setPassword($password);
    $user->save();
    $user_password = new UserPassword();
    $user_password->setUserId($user->getId());
    $user_password->setPasswordDate(DateTimeValueLib::now());
    $user_password->setPassword(cp_encrypt($password, $user_password->getPasswordDate()->getTimestamp()));
    $user_password->password_temp = $password;
    $user_password->save();
    if (array_var($user_data, 'autodetect_time_zone', 1) == 1) {
        set_user_config_option('autodetect_time_zone', 1, $user->getId());
    }
    if ($user->getType() == 'admin') {
        if ($user->getCompanyId() != owner_company()->getId() || logged_user() instanceof User && !can_manage_security(logged_user())) {
            // external users can't be admins or logged user has no rights to create admins => set as Normal
            $user->setType('normal');
        } else {
            $user->setAsAdministrator(true);
        }
    }
    /* create contact for this user*/
    if (array_var($user_data, 'create_contact', 1)) {
        // if contact with same email exists take it, else create new
        $contact = Contacts::getByEmail($user->getEmail(), true);
        if (!$contact instanceof Contact) {
            $contact = new Contact();
            $contact->setEmail($user->getEmail());
        } else {
            if ($contact->isTrashed()) {
                $contact->untrash();
            }
        }
        $contact->setFirstname($user->getDisplayName());
        $contact->setUserId($user->getId());
        $contact->setTimezone($user->getTimezone());
        $contact->setCompanyId($user->getCompanyId());
        $contact->save();
    } else {
        $contact_id = array_var($user_data, 'contact_id');
        $contact = Contacts::findById($contact_id);
        if ($contact instanceof Contact) {
            // user created from a contact
            $contact->setUserId($user->getId());
            $contact->save();
        } else {
            // if contact with same email exists use it as user's contact, without changing it
            $contact = Contacts::getByEmail($user->getEmail(), true);
            if ($contact instanceof Contact) {
                $contact->setUserId($user->getId());
                if ($contact->isTrashed()) {
                    $contact->untrash();
                }
                $contact->save();
            }
        }
    }
    $contact = $user->getContact();
    if ($contact instanceof Contact) {
        // update contact data with data entered for this user
        $contact->setCompanyId($user->getCompanyId());
        if ($contact->getEmail() != $user->getEmail()) {
            // make user's email the contact's main email address
            if ($contact->getEmail2() == $user->getEmail()) {
                $contact->setEmail2($contact->getEmail());
            } else {
                if ($contact->getEmail3() == $user->getEmail()) {
                    $contact->setEmail3($contact->getEmail());
                } else {
                    if ($contact->getEmail2() == "") {
                        $contact->setEmail2($contact->getEmail());
                    } else {
                        $contact->setEmail3($contact->getEmail());
                    }
                }
            }
        }
        $contact->setEmail($user->getEmail());
        $contact->save();
    }
    if (!$user->isGuest()) {
        /* create personal project or assing the selected*/
        //if recived a personal project assing this
        //project as personal project for this user
        $new_project = null;
        $personalProjectId = array_var($user_data, 'personal_project', 0);
        $project = Projects::findById($personalProjectId);
        if (!$project instanceof Project) {
            $project = new Project();
            $wname = new_personal_project_name($user->getUsername());
            $project->setName($wname);
            $wdesc = Localization::instance()->lang(lang('personal workspace description'));
            if (!is_null($wdesc)) {
                $project->setDescription($wdesc);
            }
            $project->setCreatedById($user->getId());
            $project->save();
            //Save to set an ID number
            $project->setP1($project->getId());
            //Set ID number to the first project
            $project->save();
            $new_project = $project;
        }
        $user->setPersonalProjectId($project->getId());
        $project_user = new ProjectUser();
        $project_user->setProjectId($project->getId());
        $project_user->setUserId($user->getId());
        $project_user->setCreatedById($user->getId());
        $project_user->setAllPermissions(true);
        $project_user->save();
        /* end personal project */
    }
    $user->save();
    ApplicationLogs::createLog($user, null, ApplicationLogs::ACTION_ADD);
    //TODO - Make batch update of these permissions
    if ($permissionsString && $permissionsString != '') {
        $permissions = json_decode($permissionsString);
    } else {
        $permissions = null;
    }
    if (is_array($permissions) && (!logged_user() instanceof User || can_manage_security(logged_user()))) {
        foreach ($permissions as $perm) {
            if (ProjectUser::hasAnyPermissions($perm->pr, $perm->pc)) {
                if (!$personalProjectId || $personalProjectId != $perm->wsid) {
                    $relation = new ProjectUser();
                    $relation->setProjectId($perm->wsid);
                    $relation->setUserId($user->getId());
                    $relation->setCheckboxPermissions($perm->pc, $user->isGuest() ? false : true);
                    $relation->setRadioPermissions($perm->pr, $user->isGuest() ? false : true);
                    $relation->save();
                }
            }
        }
    }
    // if
    if ($new_project instanceof Project && logged_user() instanceof User && logged_user()->isProjectUser($new_project)) {
        evt_add("workspace added", array("id" => $new_project->getId(), "name" => $new_project->getName(), "color" => $new_project->getColor()));
    }
    // Send notification...
    try {
        if (array_var($user_data, 'send_email_notification')) {
            Notifier::newUserAccount($user, $password);
        }
        // if
    } catch (Exception $e) {
    }
    // try
    return $user;
}
 /**
  * Edit project
  *
  * @param void
  * @return null
  */
 function edit()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_project');
     $project = Projects::findById(get_id());
     if (!$project instanceof Project) {
         flash_error(lang('project dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$project->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $project_data = array_var($_POST, 'project');
     if (!is_array($project_data)) {
         $project_data = array('name' => $project->getName(), 'description' => $project->getDescription(), 'show_description_in_overview' => $project->getShowDescriptionInOverview(), 'color' => 0);
         // array
     }
     // if
     $projects = logged_user()->getActiveProjects();
     tpl_assign('project', $project);
     tpl_assign('projects', $projects);
     tpl_assign('project_data', $project_data);
     tpl_assign('billing_amounts', $project->getBillingAmounts());
     tpl_assign('subject_matter_experts', ProjectContacts::getContactsByProject($project));
     if (is_array(array_var($_POST, 'project'))) {
         if (array_var($project_data, 'parent_id') == $project->getId()) {
             flash_error(lang("workspace own parent error"));
             ajx_current("empty");
             return;
         }
         if (!isset($project_data['parent_id'])) {
             $project_data['parent_id'] = $project->getParentId();
         }
         $project->setFromAttributes($project_data);
         try {
             DB::beginWork();
             if (array_var($project_data, 'parent_id') != $project->getParentId()) {
                 if ($project->getParentWorkspace() instanceof Project && !logged_user()->isProjectUser($project->getParentWorkspace())) {
                     flash_error(lang('no access permissions'));
                     ajx_current("empty");
                     return;
                 }
                 // if
                 $parent = Projects::findById(array_var($project_data, 'parent_id'));
                 if ($parent) {
                     if (!$project->canSetAsParentWorkspace($parent)) {
                         flash_error(lang('error cannot set workspace as parent', $parent->getName()));
                         ajx_current("empty");
                         return;
                     }
                 }
                 $project->setParentWorkspace($parent);
             }
             $project->save();
             /* Billing */
             WorkspaceBillings::clearByProject($project);
             $billings = array_var($project_data, 'billing', null);
             if ($billings) {
                 foreach ($billings as $billing_id => $billing) {
                     if ($billing['update'] && $billing['value'] && $billing['value'] != 0) {
                         $wb = new WorkspaceBilling();
                         $wb->setProjectId($project->getId());
                         $wb->setBillingId($billing_id);
                         $value = $billing['value'];
                         if (strpos($value, ',') && !strpos($value, '.')) {
                             $value = str_replace(',', '.', $value);
                         }
                         $wb->setValue($value);
                         $wb->save();
                     }
                 }
             }
             /* Project contacts */
             if (can_manage_contacts(logged_user())) {
                 ProjectContacts::clearByProject($project);
                 $contacts = array_var($project_data, 'contacts', null);
                 if ($contacts) {
                     foreach ($contacts as $contact_data) {
                         $contact = Contacts::findById($contact_data['contact_id']);
                         if ($contact instanceof Contact) {
                             $pc = new ProjectContact();
                             $pc->setProjectId($project->getId());
                             $pc->setContactId($contact_data['contact_id']);
                             $pc->setRole($contact_data['role']);
                             $pc->save();
                         }
                     }
                 }
             }
             /* <permissions> */
             $permissions = null;
             $permissionsString = array_var($_POST, 'permissions');
             if ($permissionsString && $permissionsString != '') {
                 $permissions = json_decode($permissionsString);
             }
             if (is_array($permissions) && count($permissions) > 0) {
                 //Clear old modified permissions
                 $ids = array();
                 foreach ($permissions as $perm) {
                     $ids[] = $perm->wsid;
                 }
                 ProjectUsers::clearByProject($project, implode(',', $ids));
                 //Add new permissions
                 //TODO - Make batch update of these permissions
                 foreach ($permissions as $perm) {
                     if (ProjectUser::hasAnyPermissions($perm->pr, $perm->pc)) {
                         $relation = new ProjectUser();
                         $relation->setProjectId($project->getId());
                         $relation->setUserId($perm->wsid);
                         $relation->setCheckboxPermissions($perm->pc, $relation->getUserOrGroup()->isGuest() ? false : true);
                         $relation->setRadioPermissions($perm->pr, $relation->getUserOrGroup()->isGuest() ? false : true);
                         $relation->save();
                     }
                     //endif
                     //else if the user has no permissions at all, he is not a project_user. ProjectUser is not created
                 }
                 //end foreach
             }
             // if
             /* </permissions> */
             $object_controller = new ObjectController();
             $object_controller->add_custom_properties($project);
             ApplicationLogs::createLog($project, null, ApplicationLogs::ACTION_EDIT, false, true);
             DB::commit();
             if (logged_user()->isProjectUser($project)) {
                 $workspace_info = $this->get_workspace_info($project);
                 evt_add("workspace edited", $workspace_info);
             }
             flash_success(lang('success edit project', $project->getName()));
             ajx_current("back");
             return;
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     }
     // if
 }
 /**
  * Edit group
  *
  * @param void
  * @return null
  */
 function edit_group()
 {
     $this->setTemplate('add_group');
     if (!can_manage_security(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $group = Groups::findById(get_id());
     if (!$group instanceof Group) {
         flash_error(lang('group dnx'));
         $this->redirectTo('administration', 'groups');
     }
     // if
     if (logged_user()->isAdministrator()) {
         $projects = Projects::getAll();
     } else {
         $projects = null;
     }
     $permissions = ProjectUsers::getNameTextArray();
     $group_data = array_var($_POST, 'group');
     if (!is_array($group_data)) {
         $group_data = array('name' => $group->getName(), 'can_edit_company_data' => $group->getCanEditCompanyData(), 'can_manage_security' => $group->getCanManageSecurity(), 'can_manage_workspaces' => $group->getCanManageWorkspaces(), 'can_manage_configuration' => $group->getCanManageConfiguration(), 'can_manage_contacts' => $group->getCanManageContacts(), 'can_manage_templates' => $group->getCanManageTemplates(), 'can_manage_reports' => $group->getCanManageReports(), 'can_manage_time' => $group->getCanManageTime(), 'can_add_mail_accounts' => $group->getCanAddMailAccounts());
         // array
     }
     // if
     $users = GroupUsers::getUsersByGroup($group->getId());
     if ($users) {
         foreach ($users as $usr) {
             $group_data['user[' . $usr->getId() . ']'] = true;
         }
     }
     tpl_assign('group', $group);
     tpl_assign('group_data', $group_data);
     tpl_assign('permissions', $permissions);
     tpl_assign('projects', $projects);
     if (is_array(array_var($_POST, 'group'))) {
         $group->setFromAttributes($group_data);
         if (array_var($group_data, "can_edit_company_data") != 'checked') {
             $group->setCanEditCompanyData(false);
         }
         if (array_var($group_data, "can_manage_security") != 'checked') {
             $group->setCanManageSecurity(false);
         }
         if (array_var($group_data, "can_manage_configuration") != 'checked') {
             $group->setCanManageConfiguration(false);
         }
         if (array_var($group_data, "can_manage_workspaces") != 'checked') {
             $group->setCanManageWorkspaces(false);
         }
         if (array_var($group_data, "can_manage_contacts") != 'checked') {
             $group->setCanManageContacts(false);
         }
         if (array_var($group_data, "can_manage_templates") != 'checked') {
             $group->setCanManageTemplates(false);
         }
         if (array_var($group_data, "can_manage_reports") != 'checked') {
             $group->setCanManageReports(false);
         }
         if (array_var($group_data, "can_manage_time") != 'checked') {
             $group->setCanManageTime(false);
         }
         if (array_var($group_data, "can_add_mail_accounts") != 'checked') {
             $group->setCanAddMailAccounts(false);
         }
         try {
             DB::beginWork();
             //set permissions
             $permissionsString = array_var($_POST, 'permissions');
             if ($permissionsString && $permissionsString != '') {
                 $permissions = json_decode($permissionsString);
             }
             if (is_array($permissions) && count($permissions) > 0) {
                 //Clear old modified permissions
                 $ids = array();
                 foreach ($permissions as $perm) {
                     $ids[] = $perm->wsid;
                 }
                 ProjectUsers::clearByUser($group, implode(',', $ids));
                 //Add new permissions
                 //TODO - Make batch update of these permissions
                 foreach ($permissions as $perm) {
                     if (ProjectUser::hasAnyPermissions($perm->pr, $perm->pc)) {
                         $relation = new ProjectUser();
                         $relation->setProjectId($perm->wsid);
                         $relation->setUserId($group->getId());
                         $relation->setCheckboxPermissions($perm->pc);
                         $relation->setRadioPermissions($perm->pr);
                         $relation->save();
                     }
                     //endif
                     //else if the user has no permissions at all, he is not a project_user. ProjectUser is not created
                 }
                 //end foreach
             }
             // if
             $group->save();
             GroupUsers::clearByGroup($group);
             if (array_var($_POST, 'user')) {
                 foreach (array_var($_POST, 'user') as $user_id => $val) {
                     if ($val == 'checked' && is_numeric($user_id) && Users::findById($user_id) instanceof User) {
                         $gu = new GroupUser();
                         $gu->setGroupId($group->getId());
                         $gu->setUserId($user_id);
                         $gu->save();
                     }
                 }
             }
             ApplicationLogs::createLog($group, null, ApplicationLogs::ACTION_EDIT);
             DB::commit();
             flash_success(lang('success edit group', $group->getName()));
             ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             tpl_assign('error', $e);
         }
         // try
     }
     // if
 }
 /**
  * Show update permissions page
  *
  * @param void
  * @return null
  */
 function update_permissions()
 {
     $user = Users::findById(get_id());
     if (!$user instanceof User) {
         flash_error(lang('user dnx'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     if (!$user->canUpdatePermissions(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     $company = $user->getCompany();
     if (!$company instanceof Company) {
         flash_error(lang('company dnx'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     $projects = $company->getProjects();
     if (!is_array($projects) || !count($projects)) {
         flash_error(lang('no projects owned by company'));
         $this->redirectToReferer($company->getViewUrl());
     }
     // if
     $permissions = ProjectUsers::getNameTextArray();
     $redirect_to = array_var($_GET, 'redirect_to');
     if (trim($redirect_to) == '' || !is_valid_url($redirect_to)) {
         $redirect_to = $user->getCardUrl();
     }
     // if
     tpl_assign('user', $user);
     tpl_assign('company', $company);
     tpl_assign('projects', $projects);
     tpl_assign('permissions', $permissions);
     tpl_assign('redirect_to', $redirect_to);
     if (array_var($_POST, 'submitted') == 'submitted') {
         DB::beginWork();
         foreach ($projects as $project) {
             $relation = ProjectUsers::findById(array('project_id' => $project->getId(), 'user_id' => $user->getId()));
             // findById
             if (array_var($_POST, 'project_permissions_' . $project->getId()) == 'checked') {
                 if (!$relation instanceof ProjectUser) {
                     $relation = new ProjectUser();
                     $relation->setProjectId($project->getId());
                     $relation->setUserId($user->getId());
                 }
                 // if
                 foreach ($permissions as $permission => $permission_text) {
                     $permission_value = array_var($_POST, 'project_permission_' . $project->getId() . '_' . $permission) == 'checked';
                     $setter = 'set' . Inflector::camelize($permission);
                     $relation->{$setter}($permission_value);
                 }
                 // foreach
                 $relation->save();
             } else {
                 if ($relation instanceof ProjectUser) {
                     $relation->delete();
                 }
                 // if
             }
             // if
         }
         // if
         DB::commit();
         flash_success(lang('success user permissions updated'));
         $this->redirectToUrl($redirect_to);
     }
     // if
 }
Esempio n. 12
0
 /**
  * Save project
  * 
  * $template is used when project is created to indicate wether project is 
  * being created from template or not
  *
  * @param Project $template
  * @return boolean
  */
 function save($template = null)
 {
     $modified_fields = $this->modified_fields;
     $is_new = $this->isNew();
     event_trigger('on_before_save_project', array('project' => &$this));
     $save = parent::save();
     if ($save && !is_error($save)) {
         if ($is_new) {
             // Add leader to project
             $project_user = new ProjectUser();
             $project_user->setProjectId($this->getId());
             $project_user->setUserId($this->getLeaderId());
             $project_user->save();
             clean_project_permissions_cache($this);
             event_trigger('on_project_created', array(&$this, &$template));
         } else {
             clean_project_permissions_cache($this);
             event_trigger('on_project_updated', array(&$this));
         }
         // if
         if (in_array('name', $modified_fields) || in_array('overview', $modified_fields)) {
             $content = $this->getName();
             if ($overview = $this->getOverview()) {
                 $content .= "\n\n" . $overview;
             }
             // if
             search_index_set($this->getId(), 'Project', $content);
         }
         // if
     }
     // if
     return $save;
 }
Esempio n. 13
0
 public function handleNewApplicant($position_id, $user_id)
 {
     $position = ProjectPositionPeer::retrieveByPK($position_id);
     $user = sfGuardUserPeer::retrieveByPK($user_id);
     // Alert the project owner of the application
     $profile = $this->getSfGuardUserRelatedByOwnerId()->getProfile();
     $profile->addHistoryEvent('New application for project "' . $this->getTitle() . '"', $user->getProfile()->getFullName() . ' has applied for a project you currently own. ' . ucfirst($user->getProfile()->getGenderSubject()) . ' would like to join your project as "' . $position->getTitle() . '". Please review the application using the applicaiton manager found on the project\'s page.', 'projects');
     $message = array();
     $message["from"] = $user->getId();
     $message["to"] = $this->getOwnerId();
     $message["owner"] = $this->getOwnerId();
     $message["folder"] = "inbox";
     $message["parent"] = null;
     $message["subject"] = 'New application for project "' . $this . '"';
     $message["text"] = $user->getProfile()->getFullName() . ' has applied for a project you currently own. ' . ucfirst($user->getProfile()->getGenderSubject()) . ' would like to join your project as "' . $position->getTitle() . '". Please review the application using the applicaiton manager found on the project\'s page.';
     $options = array();
     $options["copyTo"] = "none";
     $projectUser = new ProjectUser();
     $projectUser->setUserId($user->getId());
     $projectUser->setPositionId($position->getId());
     $projectUser->setStatus(sfConfig::get('app_project_user_status_pending'));
     // Status(3): pending review
     $projectUser->save();
     MessagePeer::sendSimpleMessage($message, $options);
 }
Esempio n. 14
0
<?php

require_once "../../global.php";
$soup = new Soup();
if (Session::isLoggedIn()) {
    // dashboard
    $yourProjects = ProjectUser::getProjectsByUserID(Session::getUserID());
    $publicProjects = Project::getPublicProjects(Session::getUserID(), 10);
    // projects to join
    //$user = User::load(Session::getUserID());
    $events = Event::getDashboardEvents(Session::getUserID(), 10);
    // $updates = Update::getByUserID($user->getID());
    // $discussions = Discussion::getByUserID($user->getID());
    $invitations = Invitation::getByUserID(Session::getUserID());
    $unrespondedInvites = Invitation::getByUserID(Session::getUserID(), null, false);
    $yourTasks = Task::getYourTasks(Session::getUserID());
    $soup->set('yourProjects', $yourProjects);
    $soup->set('publicProjects', $publicProjects);
    //$soup->set('user', $user);
    $soup->set('events', $events);
    // $soup->set('updates', $updates);
    // $soup->set('discussions', $discussions);
    $soup->set('invitations', $invitations);
    $soup->set('unrespondedInvites', $unrespondedInvites);
    $soup->set('tasks', $yourTasks);
    $soup->render('site/page/dashboard');
} else {
    // home page
    $events = Event::getHomeEvents(10);
    $soup->set('events', $events);
    $soup->render('site/page/home');
Esempio n. 15
0
function formatUserLink($userID = null, $projectID = null)
{
    if ($userID == null) {
        return null;
    }
    $user = User::load($userID);
    $formatted = '<a href="' . Url::user($userID) . '">' . $user->getUsername() . '</a>';
    // add star to trusted users
    if ($projectID != null) {
        if (ProjectUser::isTrusted($userID, $projectID) || ProjectUser::isCreator($userID, $projectID)) {
            $formatted .= '<a href="' . Url::help() . '#help-roles" title="trusted member">*</a>';
        }
    }
    return $formatted;
}
Esempio n. 16
0
<?php

require_once "../../global.php";
$slug = Filter::text($_GET['slug']);
$project = Project::getProjectFromSlug($slug);
// kick us out if slug invalid or not organizer/creator
if ($project == null) {
    header('Location: ' . Url::error());
    exit;
} elseif (!Session::isAdmin() && !$project->isTrusted(Session::getUserID()) && !$project->isCreator(Session::getUserID())) {
    header('Location: ' . Url::error());
    exit;
}
//do not allow banned members to access project
$isBanned = ProjectUser::isBanned(Session::getUserID(), $project->getID());
if ($isBanned) {
    header('Location: ' . Url::error());
    exit;
}
$yourTasks = Task::getYourTasks(Session::getUserID(), $project->getID());
$soup = new Soup();
$soup->set('project', $project);
$soup->set('yourTasks', $yourTasks);
$soup->render('project/page/taskNew');
Esempio n. 17
0
 public function getTrustedUsernames($term = null)
 {
     return ProjectUser::getTrustedUsernames($this->id, $term);
 }
 /**
  * Add a new user to a project.
  *
  * @param string $email An email address.
  * @param string $role  One of User::ROLE_ADMIN or User::ROLE_VIEWER.
  *
  * @return ProjectUser
  */
 public function addUser($email, $role)
 {
     $body = ['email' => $email, 'role' => $role];
     return ProjectUser::create($body, $this->getLink('access'), $this->client);
 }
Esempio n. 19
0
 public function executeApply()
 {
     $this->forward404Unless($this->getUser()->isAuthenticated(), 'User not logged in, unable to apply for project position');
     $user = $this->getUser()->getProfile();
     $position = ProjectPositionPeer::retrieveByUuid($this->getRequestParameter('position'));
     $this->forward404Unless($position, 'Position not found, unable to apply for position');
     $projectUser = new ProjectUser();
     $projectUser->setUserId($user->getUserId());
     $projectUser->setPositionId($position->getId());
     $projectUser->setStatus(sfConfig::get('app_project_user_status_pending'));
     // Status(3): pending review
     $projectUser->save();
     // Alert the project owner of the application
     $profile = $position->getProject()->getSfGuardUserRelatedByOwnerId()->getProfile();
     $profile->addHistoryEvent('New application for project "' . $position->getProject() . '"', $this->getUser()->getProfile() . ' has applied for a project you currently own. ' . ucfirst($profile->getGenderSubject()) . ' would like to join your project as "' . $position->getTitle() . '". Please review the application using the applicaiton manager found on the project\'s page.', 'projects');
     $this->position = $position;
     $this->projectUser = $projectUser;
 }
Esempio n. 20
0
<?php

require_once "../../global.php";
$userName = Filter::text($_GET['un']);
$user = User::loadByUsername($userName);
// make sure user exists
if ($user === null) {
    header('Location: ' . Url::error());
    exit;
}
$events = Event::getUserEvents($user->getID(), 10);
//$tasks = Task::getByUserID($user->getID(), null, false);
$projects = ProjectUser::getProjectsByUserID($user->getID());
$soup = new Soup();
$soup->set('user', $user);
$soup->set('events', $events);
//$soup->set('tasks', $tasks);
$soup->set('projects', $projects);
$soup->render('site/page/user');
Esempio n. 21
0
 function createWorkspace($ws_name, $parentWS_ids = null)
 {
     try {
         DB::beginWork();
         $color = rand(0, 24);
         $project_data = array('name' => $ws_name, 'description' => '', 'show_description_in_overview' => false, 'color' => $color);
         $project = new Project();
         $project->setFromAttributes($project_data);
         $project->save();
         $permission_columns = ProjectUsers::getPermissionColumns();
         $auto_assign_users = owner_company()->getAutoAssignUsers();
         // We are getting the list of auto assign users. If current user is not in the list
         // add it. He's creating the project after all...
         if (is_array($auto_assign_users)) {
             $auto_assign_logged_user = false;
             foreach ($auto_assign_users as $user) {
                 if ($user->getId() == logged_user()->getId()) {
                     $auto_assign_logged_user = true;
                 }
             }
             // if
             if (!$auto_assign_logged_user) {
                 $auto_assign_users[] = logged_user();
             }
         } else {
             $auto_assign_users[] = logged_user();
         }
         // if
         $project->clearUsers();
         foreach ($auto_assign_users as $user) {
             $project_user = new ProjectUser();
             $project_user->setProjectId($project->getId());
             $project_user->setUserId($user->getId());
             if (is_array($permission_columns)) {
                 foreach ($permission_columns as $permission) {
                     $project_user->setColumnValue($permission, true);
                 }
             }
             // if
             $project_user->save();
         }
         // foreach
         $this->setParents($project, $parentWS_ids);
         $id_parent = $project->getPID($project->getDepth() - 1);
         $proj_id = $project->getId();
         ImportLogger::instance()->log("Workspace created: {$proj_id} {$ws_name} [{$id_parent}]");
         print "Workspace created: {$proj_id} {$ws_name} [{$id_parent}]\r\n";
         DB::commit();
     } catch (Exception $e) {
         print "ERROR: {$e}\r\n";
         DB::rollback();
     }
     return $proj_id;
 }
Esempio n. 22
0
        // deadline
        $deadline = $p->getDeadline();
        $deadline = empty($deadline) ? '--' : formatTimeTag($deadline);
        echo '<td class="deadline">' . $deadline . '</td>';
        // members
        $members = count($p->getAllMembers()) + 1;
        echo '<td class="members"><a href="' . Url::people($p->getID()) . '">' . $members . '</a></td>';
        // role
        if (!is_null($user)) {
            $relationship = '';
            if (ProjectUser::isCreator($user->getID(), $p->getID())) {
                $relationship = 'creator';
            } elseif (ProjectUser::isTrusted($user->getID(), $p->getID())) {
                $relationship = 'trusted member';
            } elseif (ProjectUser::isMember($user->getID(), $p->getID())) {
                $relationship = 'member';
            } elseif (ProjectUser::isFollower($user->getID(), $p->getID())) {
                $relationship = 'follower';
            }
            echo '<td class="role">' . $relationship . '</td>';
        }
        echo '</tr>';
    }
    ?>
</table>
<?php 
} else {
    echo '<p>(none)</p>';
}
$fork->endBlockSet();
$fork->render('site/partial/panel');
Esempio n. 23
0
<?php

require_once "../../global.php";
$slug = Filter::text($_GET['slug']);
$filter = Filter::text($_GET['filter']);
$project = Project::getProjectFromSlug($slug);
// kick us out if slug invalid
if ($project == null) {
    header('Location: ' . Url::error());
    exit;
}
// if private project, limit access to invited users, members, and admins
// and exclude banned members
if ($project->getPrivate()) {
    if (!Session::isAdmin() && !$project->isCreator(Session::getUserID())) {
        if (!$project->isInvited(Session::getUserID()) && !$project->isMember(Session::getUserID()) && !$project->isTrusted(Session::getUserID()) || ProjectUser::isBanned(Session::getUserID(), $project->getID())) {
            header('Location: ' . Url::error());
            exit;
        }
    }
}
$projectID = $project->getID();
// page number, if any
if (empty($_GET['page'])) {
    $page = 1;
} else {
    $page = Filter::numeric($_GET['page']);
}
define('EVENTS_PER_PAGE', 10);
// how many events per page
switch ($filter) {
Esempio n. 24
0
        $body = "<p>" . formatUserLink(Session::getUserID()) . ' trusted you in the project ' . formatProjectLink($project->getID()) . '.</p>';
        $email = array('to' => $u->getEmail(), 'subject' => '[' . PIPELINE_NAME . '] Trusted in the project ' . $project->getTitle(), 'message' => $body);
        // send email
        Email::send($email);
    }
    // send us back
    $user = User::load($userID);
    Session::setMessage($user->getUsername() . ' is now trusted.');
    $json = array('success' => '1');
    echo json_encode($json);
    // --- UNTRUST MEMBER --- //
} elseif ($action == 'untrust') {
    // get user
    $userID = Filter::numeric($_POST['userID']);
    // get project user
    $pu = ProjectUser::find($userID, $project->getID());
    // untrust the user
    $pu->setRelationship(ProjectUser::MEMBER);
    $pu->save();
    // log it
    $logEvent = new Event(array('event_type_id' => 'untrust_member', 'project_id' => $project->getID(), 'user_1_id' => Session::getUserID(), 'user_2_id' => $userID));
    $logEvent->save();
    // send notification email, if enabled
    $u = User::load($userID);
    if ($u->getNotifyTrustProject()) {
        // compose email
        $body = "<p>" . formatUserLink(Session::getUserID()) . ' untrusted you in the project ' . formatProjectLink($project->getID()) . '.</p>';
        $email = array('to' => $u->getEmail(), 'subject' => '[' . PIPELINE_NAME . '] Untrusted in the project ' . $project->getTitle(), 'message' => $body);
        // send email
        Email::send($email);
    }
Esempio n. 25
0
 public function addProjectUser(ProjectUser $l)
 {
     $this->collProjectUsers[] = $l;
     $l->setProjectPosition($this);
 }
 /**
  * Create and attach a user account to the contact
  * 
  * @access public
  * @param void
  * @return null
  */
 function add_user_account()
 {
     $this->setTemplate('add_user_to_contact');
     $contact = Contacts::findById(get_id());
     if (!$contact instanceof Contact) {
         flash_error(lang('contact dnx'));
         $this->redirectTo('dashboard', 'contacts');
     }
     // if
     if (!$contact->canAddUserAccount(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectTo('dashboard', 'contacts');
     }
     // if
     if ($contact->hasUserAccount()) {
         flash_error(lang('contact already has user'));
         $this->redirectToUrl($contact->getCardUrl());
     }
     $user = new User();
     $company = $contact->getCompany();
     $user_data = array_var($_POST, 'user');
     if (!is_array($user_data)) {
         $user_data = array('email' => $contact->getEmail(), 'password_generator' => 'random', 'timezone' => $company->getTimezone());
         // array
     }
     // if
     $projects = $company->getProjects();
     $permissions = PermissionManager::getPermissionsText();
     tpl_assign('contact', $contact);
     tpl_assign('user', $user);
     tpl_assign('company', $company);
     tpl_assign('projects', $projects);
     tpl_assign('permissions', $permissions);
     tpl_assign('user_data', $user_data);
     if (is_array(array_var($_POST, 'user'))) {
         $user->setFromAttributes($user_data);
         try {
             // Generate random password
             if (array_var($user_data, 'password_generator') == 'random') {
                 $password = substr(sha1(uniqid(rand(), true)), rand(0, 25), 13);
                 // Validate user input
             } else {
                 $password = array_var($user_data, 'password');
                 if (trim($password) == '') {
                     throw new Error(lang('password value required'));
                 }
                 // if
                 if ($password != array_var($user_data, 'password_a')) {
                     throw new Error(lang('passwords dont match'));
                 }
                 // if
             }
             // if
             $user->setPassword($password);
             $granted = 0;
             if (logged_user()->isAdministrator()) {
                 $user->setIsAdmin(array_var($user_data, 'is_admin'));
                 $user->setAutoAssign(array_var($user_data, 'auto_assign'));
                 $granted = trim(array_var($user_data, 'can_manage_projects')) == '1' ? 1 : 0;
             } else {
                 $user->setIsAdmin(0);
                 $user->setAutoAssign(0);
             }
             DB::beginWork();
             $user->save();
             $user->setPermission(PermissionManager::CAN_MANAGE_PROJECTS, $granted);
             $contact->setUserId($user->getId());
             $contact->save();
             ApplicationLogs::createLog($user, null, ApplicationLogs::ACTION_ADD);
             if (is_array($projects)) {
                 foreach ($projects as $project) {
                     if (array_var($user_data, 'project_permissions_' . $project->getId()) == 'checked') {
                         $relation = new ProjectUser();
                         $relation->setProjectId($project->getId());
                         $relation->setUserId($user->getId());
                         foreach ($permissions as $permission => $permission_text) {
                             $permission_value = array_var($user_data, 'project_permission_' . $project->getId() . '_' . $permission) == 'checked';
                             $setter = 'set' . Inflector::camelize($permission);
                             $relation->{$setter}($permission_value);
                         }
                         // foreach
                         $relation->save();
                     }
                     // if
                 }
                 // forech
             }
             // if
             DB::commit();
             // Send notification...
             try {
                 if (array_var($user_data, 'send_email_notification')) {
                     Notifier::newUserAccount($user, $password);
                 }
                 // if
             } catch (Exception $e) {
             }
             // try
             flash_success(lang('success add user', $user->getDisplayName()));
             $this->redirectToUrl($company->getViewUrl());
             // Translate to profile page
         } catch (Exception $e) {
             DB::rollback();
             tpl_assign('error', $e);
         }
         // try
     }
     // if
 }
 /**
  * Show update permissions page
  *
  * @param void
  * @return null
  */
 function update_permissions()
 {
     $user = Users::findById(get_id());
     if (!$user instanceof User) {
         flash_error(lang('user dnx'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     if (!$user->canUpdatePermissions(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     $company = $user->getCompany();
     if (!$company instanceof Company) {
         flash_error(lang('company dnx'));
         $this->redirectToReferer(get_url('dashboard'));
     }
     // if
     $projects = $company->getProjects();
     if (!is_array($projects) || !count($projects)) {
         flash_error(lang('no projects owned by company'));
         $this->redirectToReferer($company->getViewUrl());
     }
     // if
     $permissions = PermissionManager::getPermissionsText();
     $redirect_to = array_var($_GET, 'redirect_to');
     if (trim($redirect_to) == '' || !is_valid_url($redirect_to)) {
         $redirect_to = $user->getCardUrl();
     }
     // if
     tpl_assign('user', $user);
     tpl_assign('company', $company);
     tpl_assign('projects', $projects);
     tpl_assign('permissions', $permissions);
     tpl_assign('redirect_to', $redirect_to);
     if (array_var($_POST, 'submitted') == 'submitted') {
         DB::beginWork();
         ProjectUsers::clearByUser($user);
         foreach ($projects as $project) {
             $permission_count = 0;
             $permission_all = array_var($_POST, 'project_permissions_' . $project->getId() . '_all') == 'checked';
             foreach ($permissions as $permission_name => $permission_text) {
                 $permission_value = $permission_all || array_var($_POST, 'project_permission_' . $project->getId() . '_' . $permission_name) == 'checked';
                 if ($permission_value) {
                     $permission_count++;
                 }
                 $user->setProjectPermission($project, $permission_name, $permission_value);
             }
             // foreach
             if ($permission_count > 0) {
                 $relation = new ProjectUser();
                 $relation->setProjectId($project->getId());
                 $relation->setUserId($user->getId());
                 $relation->save();
             }
         }
         // if
         DB::commit();
         flash_success(lang('success user permissions updated'));
         $this->redirectToUrl($redirect_to);
     }
     // if
 }
Esempio n. 28
0
                }
            }
        }
        Session::setMessage('You edited this task.');
        $json = array('success' => '1', 'successUrl' => Url::task($task->getID()));
        echo json_encode($json);
    } else {
        $json = array('error' => 'No changes were detected.');
        exit(json_encode($json));
    }
} elseif ($action == 'accept') {
    // join user to project, if they're not already
    $pu = ProjectUser::find(Session::getUserID(), $project->getID());
    if (empty($pu)) {
        // not a project member yet, so make them one
        $pu = new ProjectUser(array('project_id' => $project->getID(), 'user_id' => Session::getUserID(), 'relationship' => ProjectUser::MEMBER));
        $pu->save();
        // log it
        $logEvent = new Event(array('event_type_id' => 'join_project', 'project_id' => $project->getID(), 'user_1_id' => Session::getUserID()));
        $logEvent->save();
    } elseif ($project->isFollower(Session::getUserID())) {
        // convert follower to member
        $pu->setRelationship(ProjectUser::MEMBER);
        $pu->save();
        // log it
        $logEvent = new Event(array('event_type_id' => 'join_project', 'project_id' => $project->getID(), 'user_1_id' => Session::getUserID()));
        $logEvent->save();
    }
    // accept the task
    $accepted = new Accepted(array('creator_id' => Session::getUserID(), 'project_id' => $project->getID(), 'task_id' => $taskID, 'status' => Accepted::STATUS_PROGRESS));
    $accepted->save();
Esempio n. 29
0
    /**
    * Return if user can manage projects
    *
    * @access public
    * @return boolean
    */
    function canManageProjects() {
      trace(__FILE__,'canManageProjects()');

      $permission = PermissionManager::CAN_MANAGE_PROJECTS;
      
      $project_user = new ProjectUser();
      $project_user->setUserId($this->getId());
      $project_user->setProjectId(0);

      $value = in_array($permission,$project_user->getPermissions()) ? true : false;
      return $value;
    } // canManageProjects
 /**
  * Show update permissions page
  *
  * @param void
  * @return null
  */
 function update_permissions()
 {
     $user = Users::findById(get_id());
     if (!$user instanceof User) {
         flash_error(lang('user dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$user->canUpdatePermissions(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $company = $user->getCompany();
     if (!$company instanceof Company) {
         flash_error(lang('company dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (logged_user()->isAdministrator()) {
         $projects = Projects::getAll();
     } else {
         $projects = null;
     }
     $permissions = ProjectUsers::getNameTextArray();
     $redirect_to = array_var($_GET, 'redirect_to');
     if (trim($redirect_to) == '' || !is_valid_url($redirect_to)) {
         $redirect_to = $user->getCardUrl();
     }
     // if
     $user_data = array_var($_POST, 'user');
     if (!is_array($user_data)) {
         $user_data = array('can_edit_company_data' => $user->getCanEditCompanyData(), 'can_manage_security' => $user->getCanManageSecurity(), 'can_manage_workspaces' => $user->getCanManageWorkspaces(), 'can_manage_configuration' => $user->getCanManageConfiguration(), 'can_manage_contacts' => $user->getCanManageContacts(), 'can_manage_templates' => $user->getCanManageTemplates(), 'can_manage_reports' => $user->getCanManageReports(), 'can_manage_time' => $user->getCanManageTime(), 'can_add_mail_accounts' => $user->getCanAddMailAccounts());
         // array
         Hook::fire('add_user_permissions', $user, $user_data);
     }
     // if
     tpl_assign('user_data', $user_data);
     tpl_assign('user', $user);
     tpl_assign('company', $company);
     tpl_assign('projects', $projects);
     tpl_assign('permissions', $permissions);
     tpl_assign('redirect_to', $redirect_to);
     if (array_var($_POST, 'submitted') == 'submitted') {
         $user_data = array_var($_POST, 'user');
         if (!is_array($user_data)) {
             $user_data = array();
         }
         try {
             DB::beginWork();
             $permissionsString = array_var($_POST, 'permissions');
             if ($permissionsString && $permissionsString != '') {
                 $permissions = json_decode($permissionsString);
             }
             if (is_array($permissions) && count($permissions) > 0) {
                 //Clear old modified permissions
                 $ids = array();
                 foreach ($permissions as $perm) {
                     $ids[] = $perm->wsid;
                 }
                 ProjectUsers::clearByUser($user, implode(',', $ids));
                 //Add new permissions
                 //TODO - Make batch update of these permissions
                 foreach ($permissions as $perm) {
                     if (ProjectUser::hasAnyPermissions($perm->pr, $perm->pc)) {
                         $relation = new ProjectUser();
                         $relation->setProjectId($perm->wsid);
                         $relation->setUserId($user->getId());
                         $relation->setCheckboxPermissions($perm->pc, $user->isGuest() ? false : true);
                         $relation->setRadioPermissions($perm->pr, $user->isGuest() ? false : true);
                         $relation->save();
                     }
                     //endif
                     //else if the user has no permissions at all, he is not a project_user. ProjectUser is not created
                 }
                 //end foreach
             }
             // if
             $user->setCanEditCompanyData(false);
             $user->setCanManageSecurity(false);
             $user->setCanManageConfiguration(false);
             $user->setCanManageWorkspaces(false);
             $user->setCanManageContacts(false);
             $user->setCanManageTemplates(false);
             $user->setCanManageReports(false);
             $user->setCanManageTime(false);
             $user->setCanAddMailAccounts(false);
             $other_permissions = array();
             Hook::fire('add_user_permissions', $user, $other_permissions);
             foreach ($other_permissions as $k => $v) {
                 $user->setColumnValue($k, false);
             }
             $user->setFromAttributes($user_data);
             $user->setUpdatedOn(DateTimeValueLib::now());
             $user->save();
             DB::commit();
             flash_success(lang('success user permissions updated'));
             ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
     }
     // if
 }