/** * Constructor * * @param Request $request * @return CompanyProfileController */ function __construct($request) { parent::__construct($request); $company_id = $this->request->getId('company_id'); if ($company_id) { $this->active_company = Companies::findById($company_id); } // if if (instance_of($this->active_company, 'Company')) { $this->wireframe->page_actions = array(); if (!$this->active_company->canView($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if if ($this->active_company->getIsArchived() && $this->logged_user->isPeopleManager()) { $this->wireframe->addBreadCrumb(lang('Archive'), assemble_url('people_archive')); } // if $this->wireframe->addBreadCrumb($this->active_company->getName(), $this->active_company->getViewUrl()); // Collect company tabs $tabs = new NamedList(); $tabs->add('overview', array('text' => str_excerpt($this->active_company->getName(), 25), 'url' => $this->active_company->getViewUrl())); $tabs->add('people', array('text' => lang('People'), 'url' => $this->active_company->getViewUrl())); $tabs->add('projects', array('text' => lang('Projects'), 'url' => $this->active_company->getViewUrl())); event_trigger('on_company_tabs', array(&$tabs, &$this->logged_user, &$this->active_company)); $this->smarty->assign(array('company_tabs' => $tabs, 'company_tab' => 'overview')); } else { $this->active_company = new Company(); } // if $this->smarty->assign(array('active_company' => $this->active_company)); }
/** * Return invoice company * * @param void * @return Company */ function getCompany() { if ($this->company === false) { $this->company = Companies::findById($this->getCompanyId()); } // if return $this->company; }
/** * Return relation company * * @param void * @return Company */ function getCompany() { if (is_null($this->company)) { $this->company = Companies::findById($this->getCompanyId()); } // if return $this->company; }
/** * Display company details * */ function company() { $current_company = Companies::findById($this->request->get('object_id')); if (!instance_of($current_company, 'Company')) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$current_company->isOwner() && !in_array($current_company->getId(), $this->logged_user->visibleCompanyIds())) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $users = $current_company->getUsers($this->logged_user->visibleUserIds()); if (!$current_company->isOwner()) { $projects = Projects::findByUserAndCompany($this->logged_user, $current_company); } $this->smarty->assign(array('current_company' => $current_company, 'current_company_users' => $users, 'current_company_projects' => $projects, "page_title" => $current_company->getName(), "page_back_url" => assemble_url('mobile_access_people'))); }
/** * Render content for select_users popup dialog * * @param void * @return null */ function select_users() { $company_id = $this->request->getId('company_id'); $company = null; if ($company_id) { $company = Companies::findById($company_id); } // if $project_id = $this->request->getId('project_id'); $project = null; if ($project_id) { $project = Projects::findById($project_id); } // if $exclude_user_ids = $this->request->get('exclude_user_ids'); if ($exclude_user_ids) { $exclude_user_ids = explode(',', $exclude_user_ids); } // if $selected_user_ids = $this->request->get('selected_user_ids'); if ($selected_user_ids) { $selected_user_ids = explode(',', $selected_user_ids); } // if if (is_foreachable($exclude_user_ids) && is_foreachable($selected_user_ids)) { foreach ($selected_user_ids as $k => $v) { if (in_array($v, $exclude_user_ids)) { unset($selected_user_ids[$k]); } // if } // foreach } // if if (is_foreachable($selected_user_ids)) { $selected_users = Users::findByIds($selected_user_ids); } else { $selected_users = null; } // if $grouped_users = Users::findForSelect($company, $project, $exclude_user_ids); $this->smarty->assign(array('widget_id' => $this->request->get('widget_id'), 'grouped_users' => $grouped_users, 'selected_users' => $selected_users, 'selected_users_cycle_name' => $this->request->get('widget_id') . '_select_users')); }
/** * Show billed / canceled company invoices * * @param void * @return null */ function company() { $status = $this->request->get('status') ? $this->request->get('status') : 'billed'; $company = null; $company_id = $this->request->getId('company_id'); if ($company_id) { $company = Companies::findById($company_id); } // if if (instance_of($company, 'Company')) { $this->wireframe->addBreadCrumb($company->getName(), assemble_url('company_invoices', array('company_id' => $company->getId()))); } else { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if ($status == 'canceled') { $invoices = group_invoices_by_currency(Invoices::findByCompany($company, array(INVOICE_STATUS_CANCELED), 'closed_on DESC')); } else { $invoices = group_invoices_by_currency(Invoices::findByCompany($company, array(INVOICE_STATUS_BILLED), 'closed_on DESC')); } // if $this->smarty->assign(array('company' => $company, 'invoices' => $invoices, 'status' => $status)); }
/** * Validate before save * * @param ValidationErrors $errors * @return null */ function validate(&$errors) { if ($this->validatePresenceOf('email', 5)) { if (is_valid_email($this->getEmail())) { if (!$this->validateUniquenessOf('email')) { $errors->addError(lang('Email address you provided is already in use'), 'email'); } // if } else { $errors->addError(lang('Email value is not valid'), 'email'); } // if } else { $errors->addError(lang('Email value is required'), 'email'); } // if if ($this->isNew()) { if (strlen(trim($this->raw_password)) < 3) { $errors->addError(lang('Minimal password length is 3 characters'), 'password'); } // if } else { if ($this->raw_password !== false && strlen(trim($this->raw_password)) < 3) { $errors->addError(lang('Minimal password length is 3 characters'), 'password'); } // if } // if $company_id = $this->getCompanyId(); if ($company_id) { $company = Companies::findById($company_id); if (!instance_of($company, 'Company')) { $errors->addError(lang('Selected company does not exist'), 'company_id'); } // if } else { $errors->addError(lang('Please select company'), 'company_id'); } // if if (!$this->validatePresenceOf('role_id')) { $errors->addError(lang('Role is required'), 'role_id'); } // if }
/** * Returns true if user can assign the task or an error string if not. * @param $user * @param $task * @param $company_id * @param $user_id * @return mixed */ function can_assign_task_to_company_user(User $user, ProjectTask $task, $company_id, $user_id) { if ($company_id != 0) { $workspace = $task->getProject(); if ($user_id != 0) { $assignee = Users::findById($user_id); if (!$assignee instanceof User) { return lang('error assign task user dnx'); } else { if (!can_assign_task($user, $workspace, $assignee)) { return lang('error assign task permissions user'); } } } else { $company = Companies::findById($company_id); if (!$company instanceof Company) { return lang('error assign task company dnx'); } else { if (!can_assign_task($user, $workspace, $company)) { return lang('error assign task permissions company'); } } } } return true; }
echo $companyId; ?> " class="company-users" <?php echo is_array($users) == true ? 'style ="margin-bottom: 10px;"' : ''; ?> > <?php if (is_array($users) && count($users)) { ?> <div onclick="og.subscribeCompany(this)" class="container-div company-name<?php echo $allChecked ? ' checked' : ''; ?> " onmouseout="og.rollOut(this,true)" onmouseover="og.rollOver(this)"> <?php $theCompany = Companies::findById($companyId); ?> <label for="<?php echo $genid; ?> notifyCompany<?php echo $theCompany->getId(); ?> " style="background: url('<?php echo $theCompany->getLogoUrl(); ?> ') no-repeat;"><?php echo clean($theCompany->getName()); ?> </label><br/> </div>
/** * Add user * * @access public * @param void * @return null */ function add() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $max_users = config_option('max_users'); if ($max_users && Users::count() >= $max_users) { flash_error(lang('maximum number of users reached error')); ajx_current("empty"); return; } $this->setTemplate('add_user'); $company = Companies::findById(get_id('company_id')); if (!$company instanceof Company) { $company = owner_company(); } // if if (!User::canAdd(logged_user(), $company)) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $user = new User(); $user_data = array_var($_POST, 'user'); if (!is_array($user_data)) { //if it is a new user $contact_id = get_id('contact_id'); $contact = Contacts::findById($contact_id); if ($contact instanceof Contact) { //if it will be created from a contact $user_data = array('username' => $this->generateUserNameFromContact($contact), 'display_name' => $contact->getFirstname() . $contact->getLastname(), 'email' => $contact->getEmail(), 'contact_id' => $contact->getId(), 'password_generator' => 'random', 'company_id' => $company->getId(), 'timezone' => $contact->getTimezone(), 'create_contact' => false, 'type' => 'normal', 'can_manage_time' => true); // array } else { // if it is new, and created from admin interface $user_data = array('password_generator' => 'random', 'company_id' => $company->getId(), 'timezone' => $company->getTimezone(), 'create_contact' => true, 'send_email_notification' => true, 'type' => 'normal', 'can_manage_time' => true); // array } } // if $permissions = ProjectUsers::getNameTextArray(); tpl_assign('user', $user); tpl_assign('company', $company); tpl_assign('permissions', $permissions); tpl_assign('user_data', $user_data); tpl_assign('billing_categories', BillingCategories::findAll()); if (is_array(array_var($_POST, 'user'))) { if (!array_var($user_data, 'createPersonalProject')) { $user_data['personal_project'] = 0; } try { DB::beginWork(); $user = $this->createUser($user_data, array_var($_POST, 'permissions')); $object_controller = new ObjectController(); $object_controller->add_custom_properties($user); DB::commit(); flash_success(lang('success add user', $user->getDisplayName())); ajx_current("back"); } catch (Exception $e) { DB::rollback(); ajx_current("empty"); flash_error($e->getMessage()); } // try } // if }
/** * Projects Arhive * * @param void * @return null */ function archive() { if ($this->request->isApiCall()) { $this->serveData(Projects::findByUser($this->logged_user), 'projects'); } // if $per_page = 10; $page = (int) $this->request->get('page'); if ($page < 1) { $page = 1; } // if if (!$this->logged_user->isOwner()) { $group_by = 'group'; } else { $group_by = $this->request->get('group_by'); if ($group_by != 'client') { $group_by = 'group'; } // if } // if $filter_by_status = $this->request->get('filter'); if (is_null($filter_by_status)) { $filter_by_status = 'all'; } // if switch ($filter_by_status) { case 'all': $statuses = array(PROJECT_STATUS_COMPLETED, PROJECT_STATUS_CANCELED, PROJECT_STATUS_PAUSED); break; case 'completed': $statuses = array(PROJECT_STATUS_COMPLETED); break; case 'paused': $statuses = array(PROJECT_STATUS_PAUSED); break; case 'canceled': $statuses = array(PROJECT_STATUS_CANCELED); break; default: $statuses = array(PROJECT_STATUS_COMPLETED, PROJECT_STATUS_CANCELED, PROJECT_STATUS_PAUSED); break; } // switch project status filter $this->smarty->assign(array('group_by' => $group_by, 'filter' => $filter_by_status)); if ($group_by == 'group') { $group = null; $group_id = $this->request->getId('group_id'); if ($group_id) { $group = ProjectGroups::findById($group_id); } // if if (instance_of($group, 'ProjectGroup')) { list($projects, $pagination) = Projects::paginateByUserAndGroup($this->logged_user, $group, $statuses, $page, $per_page, true); } else { list($projects, $pagination) = Projects::paginateByUser($this->logged_user, $statuses, $page, $per_page, true); } // if $this->smarty->assign(array('projects' => $projects, 'pagination' => $pagination, 'groups' => ProjectGroups::findAll($this->logged_user), 'selected_group' => $group)); } else { $company = null; $company_id = $this->request->getId('company_id'); if ($company_id) { $company = Companies::findById($company_id); } // if if (!instance_of($company, 'Company')) { $company = $this->owner_company; } // if list($projects, $pagination) = Projects::paginateByUserAndCompany($this->logged_user, $company, $statuses, $page, $per_page, true); $this->smarty->assign(array('projects' => $projects, 'pagination' => $pagination, 'companies' => Companies::findClients($this->logged_user), 'selected_company' => $company)); } // if }
/** * Return owner company * * @access public * @param void * @return Company */ function getCompany() { return Companies::findById($this->getCompanyId()); }
function get_company_data() { ajx_current("empty"); $id = array_var($_GET, 'id'); $company = Companies::findById($id); if ($company) { ajx_extra_data(array("id" => $company->getId(), "address" => $company->getAddress(), "state" => $company->getState(), "city" => $company->getCity(), "country" => $company->getCountry(), "zipcode" => $company->getZipcode(), "webpage" => $company->getHomepage(), "phoneNumber" => $company->getPhoneNumber(), "faxNumber" => $company->getFaxNumber())); } else { ajx_extra_data(array("id" => 0)); } }
/** * Delete company logo * * @param void * @return null */ function delete_logo() { if (!logged_user()->isAdministrator(owner_company())) { flash_error(lang('no access permissions')); $this->redirectTo('dashboard'); } // if $company = Companies::findById(get_id()); if (!$company instanceof Company) { flash_error(lang('company dnx')); $this->redirectToReferer(get_url('administration', 'clients')); } // if try { DB::beginWork(); $company->deleteLogo(); $company->save(); ApplicationLogs::createLog($company, null, ApplicationLogs::ACTION_EDIT); DB::commit(); flash_success(lang('success delete company logo')); } catch (Exception $e) { DB::rollback(); flash_error(lang('error delete company logo')); } // try $this->redirectToUrl($company->getEditLogoUrl()); }
/** * Return responsible company * * @access public * @param void * @return Company */ protected function getAssignedToCompany() { return Companies::findById($this->getAssignedToCompanyId()); }
function send_reports() { $company = Companies::findById(1); $lTime = time() + 60 * 60 * $company->getTimezone(); $dayOfWeek = date("l", $lTime); $footer = '<a href="' . externalUrl(ROOT_URL) . '">' . externalUrl(ROOT_URL) . "</a>"; $people = Reminders::findAll(array('conditions' => 'reports_enabled = 1 and report_day = "' . $dayOfWeek . '"')); if (is_array($people) && count($people)) { foreach ($people as $person) { tpl_assign('settings', $person); $user = Users::findById($person->getUserId()); tpl_assign('user', $user); $offset = 60 * 60 * $user->getTimezone(); tpl_assign('offset', $offset); $allProjects = $user->getProjects(); $emailBody = ''; $recipient = Notifier::prepareEmailAddress($user->getEmail(), $user->getDisplayName()); foreach ($allProjects as $project) { if ($project->isActive() || $project->getCompletedOn()->getLeftInDays() > -7) { tpl_assign('project', $project); $condition = 'project_id = ' . $project->getId(); $condition .= " and is_private = 0 and is_silent = 0"; if (!$person->getReportsIncludeEveryone()) { $condition .= ' and taken_by_id = ' . $user->getId(); } $logs = array(); if ($person->getReportsIncludeActivity()) { $condition .= " and created_on > Interval -7 day + now()"; $logs = ApplicationLogs::findAll(array('conditions' => $condition)); } tpl_assign('logs', $logs); $taskLists = $project->getAllTaskLists(); $emailTaskLists = array(); if (is_array($taskLists) && count($taskLists)) { foreach ($taskLists as $taskList) { $condition = 'task_list_id = ' . $taskList->getId(); if (!$person->getReportsIncludeEveryone()) { $condition .= " and assigned_to_user_id = " . $user->getId(); } $condition .= " and completed_on > Interval -7 day + now()"; $tasks = ProjectTasks::findAll(array('conditions' => $condition)); if (is_array($tasks) && count($tasks)) { $emailTaskLists[] = $taskList; } } } if (count($emailTaskLists) || count($logs)) { tpl_assign('taskLists', $emailTaskLists); $emailBody .= tpl_fetch(get_template_path('report_per_project', 'reminders')); if ($person->getReportsSummarizedBy()) { try { Notifier::sendEmail($recipient, $recipient, "[ProjectPier] - Project Report - " . $project->getObjectName(), $emailBody . $footer, 'text/html'); // send $emailBody = ''; } catch (Exception $e) { echo $e; } } } } } if (strlen($emailBody) && !$person->getReportsSummarizedBy()) { $time = time() + 60 * 60 * $user->getTimezone(); try { Notifier::sendEmail($recipient, $recipient, "[ProjectPier] - Activity Report - " . gmdate('Y/m/d', $time), $emailBody . $footer, 'text/html'); // send $emailBody = ''; } catch (Exception $e) { echo $e; } } } } }
/** * Send client address details * * @param void * @return void */ function company_details() { if (!$this->request->isAsyncCall()) { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if $client_id = $this->request->get('company_id'); $client_company = Companies::findById($client_id); if (!instance_of($client_company, 'Company')) { $this->httpError(HTTP_ERR_NOT_FOUND, ' '); } // if $company_address = CompanyConfigOptions::getValue('office_address', $client_company); echo $company_address; die; }
/** * Render assign to SELECT * @param string $list_name Name of the select control * @param Project $project Selected project, if NULL active project will be used * @param integer $selected ID of selected user * @param array $attributes Array of select box attributes, if needed * @return null */ function filter_assigned_to_select_box($list_name, $project = null, $selected = null, $attributes = null) { $logged_user = logged_user(); if ($project) { $project_ids = $project->getAllSubWorkspacesQuery(true, logged_user()); } else { $project_ids = logged_user()->getWorkspacesQuery(true); } $grouped_users = Users::getGroupedByCompanyFromProjectIds($project_ids); $options = array(option_tag(lang('anyone'), '0:0'), option_tag(lang('unassigned'), '-1:-1', '-1:-1' == $selected ? array('selected' => 'selected') : null)); if (is_array($grouped_users) && count($grouped_users)) { foreach ($grouped_users as $company_id => $users) { $company = Companies::findById($company_id); if (!$company instanceof Company) { continue; } // if $options[] = option_tag('--', '0:0'); // separator $option_attributes = $company->getId() . ':0' == $selected ? array('selected' => 'selected') : null; $options[] = option_tag($company->getName(), $company_id . ':0', $option_attributes); if (is_array($users)) { foreach ($users as $user) { $option_attributes = $company_id . ':' . $user->getId() == $selected ? array('selected' => 'selected') : null; $options[] = option_tag($user->getDisplayName() . ' : ' . $company->getName(), $company_id . ':' . $user->getId(), $option_attributes); } // foreach } // if } // foreach } // if return select_box($list_name, $options, $attributes); }
/** * Return verbose user filter data * * @param void * @return string */ function getVerboseUserFilterData() { if ($this->verbose_user_filter_data === false) { switch ($this->getUserFilter()) { case USER_FILTER_COMPANY: $company = Companies::findById($this->getUserFilterData()); if (instance_of($company, 'Company')) { $this->verbose_user_filter_data = $company->getName(); } // if break; case USER_FILTER_SELECTED: $user_ids = $this->getUserFilterData(); if (is_foreachable($user_ids)) { $users = Users::findByIds($user_ids); if (is_foreachable($users)) { $user_names = array(); foreach ($users as $user) { $user_names[] = $user->getDisplayName(); } // foreach $this->verbose_user_filter_data = implode(', ', $user_names); } // if } // if break; } // switch } // if return $this->verbose_user_filter_data; }
/** * Edit logged user profile. * Called with different POST format from "administration/users/edit user profile " and from "profile/edit my profile" * * @access public * @param void * @return null */ function edit_profile() { $user = Users::findById(get_id()); if (!$user instanceof User) { flash_error(lang('user dnx')); ajx_current("empty"); return; } // if $company = $user->getCompany(); if (!$company instanceof Company) { flash_error(lang('company dnx')); ajx_current("empty"); return; } // if if (!$user->canUpdateProfile(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $redirect_to = array_var($_GET, 'redirect_to'); if (trim($redirect_to) == '' || !is_valid_url($redirect_to)) { $redirect_to = $user->getCardUrl(); } // if tpl_assign('redirect_to', null); $user_data = array_var($_POST, 'user'); if (!is_array($user_data)) { $user_data = array('username' => $user->getUsername(), 'email' => $user->getEmail(), 'display_name' => $user->getDisplayName(), 'title' => $user->getTitle(), 'timezone' => $user->getTimezone(), 'auto_assign' => $user->getAutoAssign(), 'company_id' => $user->getCompanyId(), 'is_admin' => $user->isAdministrator(), 'type' => $user->getType()); // array } // if tpl_assign('user', $user); tpl_assign('company', $company); tpl_assign('user_data', $user_data); tpl_assign('billing_categories', BillingCategories::findAll()); if (is_array(array_var($_POST, 'user'))) { if (array_var($user_data, 'company_id') && !Companies::findById(array_var($user_data, 'company_id')) instanceof Company) { ajx_current("empty"); flash_error(lang("company dnx")); return; } try { DB::beginWork(); $user->setDisplayName(array_var($user_data, 'display_name')); $user->setEmail(array_var($user_data, 'email')); $user->setType(array_var($user_data, 'type')); $user->setTimezone(array_var($user_data, 'timezone')); $user->setTitle(array_var($user_data, 'title')); $user->setUpdatedOn(DateTimeValueLib::now()); if (logged_user()->isAdministrator()) { if ($user->getId() != 1) { // System admin cannot change it's company $user->setCompanyId(array_var($user_data, 'company_id')); } $user->setDefaultBillingId(array_var($user_data, 'default_billing_id')); $user->setUsername(array_var($user_data, 'username')); $project = Projects::findById(array_var($user_data, 'personal_project_id')); if ($project instanceof Project && $user->getPersonalProjectId() != $project->getId()) { $user->setPersonalProjectId($project->getId()); $project_user = ProjectUsers::findById(array('project_id' => $project->getId(), 'user_id' => $user->getId())); if (!$project_user) { $project_user = new ProjectUser(); $project_user->setUserId($user->getId()); $project_user->setProjectId($project->getId()); } $project_user->setAllPermissions(true); $project_user->save(); } } $user->save(); $autotimezone = array_var($user_data, 'autodetect_time_zone', null); if ($autotimezone !== null) { set_user_config_option('autodetect_time_zone', $autotimezone, $user->getId()); } $object_controller = new ObjectController(); $object_controller->add_custom_properties($user); if ($user->getId() != 1) { //System admin cannot change its own admin status if ($user->getType() == 'admin') { if ($user->getCompanyId() != owner_company()->getId()) { // external users can't be admins => set as Normal $user->setType('normal'); $user->setAsAdministrator(false); } else { $user->setAsAdministrator(true); } } else { $user->setAsAdministrator(false); } } DB::commit(); flash_success(lang('success update profile')); ajx_current("back"); ajx_add("overview-panel", "reload"); } catch (Exception $e) { DB::rollback(); ajx_current("empty"); flash_error($e->getMessage()); } // try } // if }
/** * Remove company from project * * @param void * @return null */ function remove_company() { if (!active_project()->canChangePermissions(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $project = Projects::findById(get_id('project_id')); if (!$project instanceof Project) { flash_error(lang('project dnx')); ajx_current("empty"); return; } // if $company = Companies::findById(get_id('company_id')); if (!$company instanceof Company) { flash_error(lang('company dnx')); ajx_current("empty"); return; } // if $project_company = ProjectCompanies::findById(array('project_id' => $project->getId(), 'company_id' => $company->getId())); if (!$project_company instanceof ProjectCompany) { flash_error(lang('company not on project')); ajx_current("empty"); return; } // if try { DB::beginWork(); $project_company->delete(); $users = ProjectUsers::getCompanyUsersByProject($company, $project); if (is_array($users)) { foreach ($users as $user) { $project_user = ProjectUsers::findById(array('project_id' => $project->getId(), 'user_id' => $user->getId())); if ($project_user instanceof ProjectUser) { $project_user->delete(); } } // foreach } // if DB::commit(); flash_success(lang('success remove company from project')); ajx_current("reload"); } catch (Exception $e) { DB::rollback(); flash_error(lang('error remove company from project')); ajx_current("empty"); } // try }
static function getExternalColumnValue($field, $id) { $value = ''; if ($field == 'company_id' || $field == 'assigned_to_company_id') { $company = Companies::findById($id); if ($company instanceof Company) { $value = $company->getName(); } } else { if ($field == 'user_id' || $field == 'created_by_id' || $field == 'updated_by_id' || $field == 'assigned_to_user_id' || $field == 'completed_by_id') { $user = Users::findById($id); if ($user instanceof User) { $value = $user->getUsername(); } } else { if ($field == 'milestone_id') { $milestone = ProjectMilestones::findById($id); if ($milestone instanceof ProjectMilestone) { $value = $milestone->getName(); } } else { if ($field == 'object_subtype') { $object_subtype = ProjectCoTypes::findById($id); if ($object_subtype instanceof ProjectCoType) { $value = $object_subtype->getName(); } } } } } return $value; }
/** * Toggle favorite status * * @param void * @return null */ function toggle_favorite() { if (!logged_user()->isAdministrator()) { flash_error('no access permisssions'); $this->redirectToReferer(get_url('dashboard')); } $company = Companies::findById(get_id()); if (!$company instanceof Company) { flash_error(lang('company dnx')); $this->redirectToReferer(get_url('administration')); } // if if ($company->isOwner()) { flash_error('no access permissions'); $this->redirectToReferer(get_url('dashboard')); } // if $company->setIsFavorite(!$company->isFavorite()); if (!$company->save()) { flash_error(lang('could not save info')); } $redirect_to = urldecode(array_var($_GET, 'redirect_to')); if (trim($redirect_to) == '' || !is_valid_url($redirect_to)) { $redirect_to = $company->getViewUrl(); } // if $this->redirectToUrl($redirect_to); }
/** * Return owner company * * @access public * @param void * @return Company */ function getCompany() { $company = Companies::findById($this->getCompanyId()); if ($company) { return $company; } return new Company(); }
<?php $genid = gen_id(); $assign_type = 0; //All if (isset($assigned_to_user_filter) && $assigned_to_user_filter > 0){ $assigned_to = Users::findById($assigned_to_user_filter); $assigned_to_me = $assigned_to->getId() == logged_user()->getId(); $assign_type = $assigned_to_me? 1 : 2; } else if (isset($assigned_to_company_filter) && $assigned_to_company_filter > 0){ $assigned_to = Companies::findById($assigned_to_company_filter); $assign_type = 3; } ?> <script> var cant_tips = 0; var tips_array = []; function addTip(div_id, title, bdy) { tips_array[cant_tips++] = new Ext.ToolTip({ target: div_id, html: bdy, title: title, hideDelay: 1500, closable: true }); } </script> <div id="<?php echo $genid ?>-db" style="padding:7px;">
/** * 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 }
/** * Render assign to SELECT * * @param string $list_name Name of the select control * @param Project $project Selected project, if NULL active project will be used * @param integer $selected ID of selected user * @param array $attributes Array of select box attributes, if needed * @return null */ function assign_to_select_box($list_name, $project = null, $selected = null, $attributes = null) { if (is_null($project)) { $project = active_project(); } // if if (!$project instanceof Project) { throw new InvalidInstanceError('$project', $project, 'Project'); } // if $logged_user = logged_user(); $can_assign_to_owners = $logged_user->isMemberOfOwnerCompany() || $logged_user->getProjectPermission($project, PermissionManager::CAN_ASSIGN_TO_OWNERS); $can_assign_to_other = $logged_user->isMemberOfOwnerCompany() || $logged_user->getProjectPermission($project, PermissionManager::CAN_ASSIGN_TO_OTHER); $grouped_users = $project->getUsers(true); $options = array(option_tag(lang('anyone'), '0:0')); if (is_array($grouped_users) && count($grouped_users)) { foreach ($grouped_users as $company_id => $users) { $company = Companies::findById($company_id); if (!$company instanceof Company) { continue; } // if // Check if $logged_user can assign task to members of this company if ($company_id != $logged_user->getCompanyId()) { if ($company->isOwner()) { if (!$can_assign_to_owners) { continue; } // if } else { if (!$can_assign_to_other) { continue; } // if } // if } // if $options[] = option_tag('--', '0:0'); // separator $option_attributes = $company->getId() . ':0' == $selected ? array('selected' => 'selected') : null; $options[] = option_tag($company->getName(), $company_id . ':0', $option_attributes); if (is_array($users)) { foreach ($users as $user) { $option_attributes = $company_id . ':' . $user->getId() == $selected ? array('selected' => 'selected') : null; $options[] = option_tag($company->getName() . ': ' . $user->getDisplayName(), $company_id . ':' . $user->getId(), $option_attributes); } // foreach } // if } // foreach } // if return select_box($list_name, $options, $attributes); }
/** * 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 = ProjectUsers::getNameTextArray(); 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); 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'; $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 }
/** * Add contact * * @access public * @param void * @return null */ function add() { $this->setTemplate('add_contact'); $company_id = get_id('company_id', null, 0); $company = Companies::findById($company_id); if (!Contact::canAdd(logged_user(), $company)) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('dashboard', 'index')); } // if $contact = new Contact(); $im_types = ImTypes::findAll(array('order' => '`id`')); $contact_data = array_var($_POST, 'contact'); if (!is_array($contact_data)) { $contact_data = array('company_id' => $company_id); // array } // if $user_data = array_var($contact_data, 'user'); if (!is_array($user_data)) { $user_data = array('password_generator' => 'random'); // array } // if tpl_assign('contact', $contact); tpl_assign('company', $company); tpl_assign('contact_data', $contact_data); tpl_assign('user_data', $user_data); tpl_assign('im_types', $im_types); $avatar = array_var($_FILES, 'new_avatar'); if (is_array($avatar) && isset($avatar['size']) && $avatar['size'] != 0) { try { if (!isset($avatar['name']) || !isset($avatar['type']) || !isset($avatar['size']) || !isset($avatar['tmp_name']) || !is_readable($avatar['tmp_name'])) { throw new InvalidUploadError($avatar, lang('error upload file')); } // if $valid_types = array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png'); $max_width = config_option('max_avatar_width', 50); $max_height = config_option('max_avatar_height', 50); if ($avatar['size']) { if (!in_array($avatar['type'], $valid_types) || !($image = getimagesize($avatar['tmp_name']))) { throw new InvalidUploadError($avatar, lang('invalid upload type', 'JPG, GIF, PNG')); } elseif (!$contact->setAvatar($avatar['tmp_name'], $max_width, $max_height, false)) { throw new Error($avatar, lang('error edit avatar')); $contact->setAvatarFile(''); } // if } // if } catch (Exception $e) { flash_error($e->getMessage()); } } else { $contact->setAvatarFile(''); } // if if (is_array(array_var($_POST, 'contact'))) { $contact->setFromAttributes($contact_data); try { // Company info if ($_POST['contact']['company']['what'] == 'existing') { $company_id = $_POST['contact']['company_id']; } else { $company = new Company(); $company->setName($_POST['contact']['company']['name']); $company->setTimezone($_POST['contact']['company']['timezone']); $company->setClientOfId(owner_company()->getId()); $company->save(); $company_id = $company->getId(); } // if $contact->setCompanyId($company_id); $contact->setUserId(0); $contact->save(); if (plugin_active('tags')) { $contact->setTagsFromCSV(array_var($contact_data, 'tags')); } $contact->clearImValues(); foreach ($im_types as $im_type) { $value = trim(array_var($contact_data, 'im_' . $im_type->getId())); if ($value != '') { $contact_im_value = new ContactImValue(); $contact_im_value->setContactId($contact->getId()); $contact_im_value->setImTypeId($im_type->getId()); $contact_im_value->setValue($value); $contact_im_value->setIsDefault(array_var($contact_data, 'default_im') == $im_type->getId()); $contact_im_value->save(); } // if } // foreach ApplicationLogs::createLog($contact, null, ApplicationLogs::ACTION_ADD); DB::commit(); flash_success(lang('success add contact', $contact->getDisplayName())); $this->redirectToUrl($contact->getCardUrl()); // Translate to profile page } catch (Exception $e) { DB::rollback(); tpl_assign('error', $e); } // try } // if }
} // foreach ?> </div> <div id="createdByFilters"> <strong><?php echo lang('reported by'); ?> :</strong> <?php $property_name = 'created_by_id'; $property_in_url = isset($params[$property_name]) ? $params[$property_name] : ""; // TODO make filter_links template more flexible so that it can be used with Users and not only text. echo '<a href="' . get_url('tickets', 'index', array_merge($params, array($property_name => ''))) . '" ' . ($property_in_url == "" ? 'class="selected"' : '') . '>' . lang('all') . '</a> '; foreach ($grouped_users as $company_id => $company_users) { $company = Companies::findById($company_id); echo '<strong>' . $company->getName() . '</strong>: '; foreach ($company_users as $user) { $user_id = $user->getId(); echo '<a href="' . get_url('tickets', 'index', array_merge($params, array($property_name => $user_id))) . '" ' . (preg_match("/^(.*,)?{$user_id}(,.*)?\$/", $property_in_url) ? 'class="selected"' : '') . '>' . $user->getDisplayName() . '</a> '; if (preg_match("/^(.*,)?{$user_id}(,.*)?\$/", $property_in_url)) { echo '<a href="' . get_url('tickets', 'index', array_merge($params, array($property_name => preg_replace(array("/^{$user_id},/", "/,{$user_id},/", "/,{$user_id}\$/", "/^{$user_id}\$/"), array('', ',', '', ''), $property_in_url)))) . '">-</a> '; } else { echo '<a href="' . get_url('tickets', 'index', array_merge($params, array($property_name => $property_in_url == "" ? $user_id : $property_in_url . ',' . $user_id))) . '">+</a> '; } // if } // foreach } // foreach ?>