/** * Render select company box * * @param integer $selected ID of selected company * @param array $attributes Additional attributes * @return string */ function select_company($name, $selected = null, $attributes = null, $allow_none = true, $check_permissions = false) { if (!$check_permissions) { $companies = Companies::findAll(array('order' => 'client_of_id ASC, name ASC')); } else { $companies = Companies::getVisibleCompanies(logged_user(), "`id` <> " . owner_company()->getId()); if (logged_user()->isMemberOfOwnerCompany() || owner_company()->canAddUser(logged_user())) { // add the owner company $companies = array_merge(array(owner_company()), $companies); } } if ($allow_none) { $options = array(option_tag(lang('none'), 0)); } else { $options = array(); } if (is_array($companies)) { foreach ($companies as $company) { $option_attributes = $company->getId() == $selected ? array('selected' => 'selected') : null; $company_name = $company->getName(); //if($company->isOwner()) $company_name .= ' (' . lang('owner company') . ')'; $options[] = option_tag($company_name, $company->getId(), $option_attributes); } // foreach } // if return select_box($name, $options, $attributes); }
private function get_ext_values($field, $manager = null) { $values = array(array('id' => '', 'name' => '-- ' . lang('select') . ' --')); if ($field == 'company_id' || $field == 'assigned_to_company_id') { $companies = Companies::getVisibleCompanies(logged_user()); foreach ($companies as $company) { $values[] = array('id' => $company->getId(), 'name' => $company->getName()); } } else { if ($field == 'user_id' || $field == 'created_by_id' || $field == 'updated_by_id' || $field == 'assigned_to_user_id' || $field == 'completed_by_id') { $users = Users::getVisibleUsers(logged_user()); foreach ($users as $user) { $values[] = array('id' => $user->getId(), 'name' => $user->getDisplayName()); } } else { if ($field == 'milestone_id') { $milestones = ProjectMilestones::getActiveMilestonesByUser(logged_user()); foreach ($milestones as $milestone) { $values[] = array('id' => $milestone->getId(), 'name' => $milestone->getName()); } } else { if ($field == 'workspace') { $workspaces = logged_user()->getWorkspaces(false, 0); foreach ($workspaces as $ws) { $values[] = array('id' => $ws->getId(), 'name' => $ws->getName()); } } else { if ($field == 'tag') { $tags = Tags::getTagNames(); foreach ($tags as $tag) { $values[] = array('id' => $tag['name'], 'name' => $tag['name']); } } else { if ($field == 'object_subtype') { $object_types = ProjectCoTypes::findAll(array('conditions' => !is_null($manager) ? "`object_manager`='{$manager}'" : "")); foreach ($object_types as $object_type) { $values[] = array('id' => $object_type->getId(), 'name' => $object_type->getName()); } } } } } } } return $values; }
function export_to_csv_file() { $this->setTemplate('csv_export'); $type = array_var($_GET, 'type', array_var($_SESSION, 'import_type', 'contact')); //type of import (contact - company) tpl_assign('import_type', $type); if (!isset($_SESSION['import_type']) || $type != $_SESSION['import_type'] && $type != '') { $_SESSION['import_type'] = $type; } if ($type == 'contact') { $checked_fields = array_var($_POST, 'check_contact'); } else { $checked_fields = array_var($_POST, 'check_company'); } if (is_array($checked_fields)) { $titles = ''; $imp_type = array_var($_SESSION, 'import_type', 'contact'); if ($imp_type == 'contact') { $field_names = Contacts::getContactFieldNames(); foreach ($checked_fields as $k => $v) { if (isset($field_names["contact[{$k}]"]) && $v == 'checked') { $titles .= $field_names["contact[{$k}]"] . ','; } } $titles = substr_utf($titles, 0, strlen_utf($titles) - 1) . "\n"; } else { $field_names = Companies::getCompanyFieldNames(); foreach ($checked_fields as $k => $v) { if (isset($field_names["company[{$k}]"]) && $v == 'checked') { $titles .= $field_names["company[{$k}]"] . ','; } } $titles = substr_utf($titles, 0, strlen_utf($titles) - 1) . "\n"; } $filename = rand() . '.tmp'; $handle = fopen(ROOT . '/tmp/' . $filename, 'wb'); fwrite($handle, $titles); $project = active_project(); if ($project instanceof Project) { $pids = $project->getAllSubWorkspacesQuery(true); } $wsConditions = null; $tag_str = null; $tag = array_var($_GET, 'active_tag'); if (array_var($_SESSION, 'import_type', 'contact') == 'contact') { if (isset($pids)) { $wsConditions = Contacts::getWorkspaceString($pids); } if (isset($tag) && $tag && $tag != '') { $tag_str = " EXISTS (SELECT * FROM `" . TABLE_PREFIX . "tags` `t` WHERE `tag` = " . DB::escape($tag) . " AND `co`.`id` = `t`.`rel_object_id` AND `t`.`rel_object_manager` = 'Contacts') "; } $conditions = $wsConditions ? $wsConditions . ($tag_str ? " AND {$tag_str}" : '') : $tag_str; $conditions .= ($conditions == "" ? "" : " AND ") . "`archived_by_id` = 0" . ($conditions ? " AND {$conditions}" : ""); $contacts = Contacts::instance()->getAllowedContacts($conditions); foreach ($contacts as $contact) { fwrite($handle, $this->build_csv_from_contact($contact, $checked_fields) . "\n"); } } else { if (isset($pids)) { $wsConditions = Companies::getWorkspaceString($pids); } if (isset($tag) && $tag && $tag != '') { $tag_str = " EXISTS (SELECT * FROM `" . TABLE_PREFIX . "tags` `t` WHERE `tag` = " . DB::escape($tag) . " AND `" . TABLE_PREFIX . "companies`.`id` = `t`.`rel_object_id` AND `t`.`rel_object_manager` = 'Companies') "; } $conditions = $wsConditions ? $wsConditions . ($tag_str ? " AND {$tag_str}" : '') : $tag_str; $conditions .= ($conditions == "" ? "" : " AND ") . "`archived_by_id` = 0" . ($conditions ? " AND {$conditions}" : ""); $companies = Companies::getVisibleCompanies(logged_user(), $conditions); foreach ($companies as $company) { fwrite($handle, $this->build_csv_from_company($company, $checked_fields) . "\n"); } } fclose($handle); $_SESSION['contact_export_filename'] = $filename; flash_success($imp_type == 'contact' ? lang('success export contacts') : lang('success export companies')); } else { unset($_SESSION['contact_export_filename']); return; } }