/** * Build menu * * @param Menu $menu * @param User $user * @return array */ function status_handle_on_build_menu(&$menu, &$user) { if ($user->isAdministrator() || $user->getSystemPermission('can_use_status_updates')) { $last_visit = UserConfigOptions::getValue('status_update_last_visited', $user); $menu->addToGroup(array(new MenuItem('status', lang('Status'), assemble_url('status_updates'), get_image_url('icon_menu.gif', STATUS_MODULE), StatusUpdates::countNewMessagesForUser($user, $last_visit))), 'main'); } // if }
/** * Return value of a given config option * * Output of this helper is not cleaned! * * @param array $params * @param Smarty $smarty * @return mixed */ function smarty_function_config_option($params, &$smarty) { $name = array_var($params, 'name'); if (empty($name)) { return new InvalidParamError('name', $name, '$name value is required'); } // if if (isset($params['user']) && instance_of($params['user'], 'User')) { return UserConfigOptions::getValue($name, $params['user']); // } elseif(isset($params['project']) && instance_of($params['project'], 'Project')) { // return ProjectConfigOptions::getValue($name, $params['project']); } elseif (isset($params['company']) && instance_of($params['company'], 'Company')) { return CompanyConfigOptions::getValue($name, $params['company']); } else { return ConfigOptions::getValue($name); } // if }
/** * Index * * @param voi * @return null */ function index() { require_once CALENDAR_MODULE_PATH . '/models/generators/ProjectCalendarGenerator.class.php'; $today = new DateTimeValue(time() + get_user_gmt_offset()); if ($this->request->get('month') && $this->request->get('year')) { $month = $this->request->get('month'); $year = $this->request->get('year'); } else { $month = $today->getMonth(); $year = $today->getYear(); } // if $first_weekday = UserConfigOptions::getValue('time_first_week_day', $this->logged_user); $generator = new ProjectCalendarGenerator($month, $year, $first_weekday); $generator->setProject($this->active_project); $generator->setData(Calendar::getProjectData($this->logged_user, $this->active_project, $month, $year)); $this->smarty->assign(array('month' => $month, 'year' => $year, 'calendar' => $generator, 'page_tab' => 'calendar', 'navigation_pattern' => Calendar::getProjectMonthUrl($this->active_project, '-YEAR-', '-MONTH-'))); }
/** * Calendar * * @param void * @return null */ function index() { require_once CALENDAR_MODULE_PATH . '/models/generators/DashboardCalendarGenerator.class.php'; if ($this->request->get('month') && $this->request->get('year')) { $month = $this->request->get('month'); $year = $this->request->get('year'); } else { $today = new DateTimeValue(time() + get_user_gmt_offset()); $month = $today->getMonth(); $year = $today->getYear(); } // if $first_weekday = UserConfigOptions::getValue('time_first_week_day', $this->logged_user); $generator = new DashboardCalendarGenerator($month, $year, $first_weekday); $generator->setData(Calendar::getActiveProjectsData($this->logged_user, $month, $year)); $this->smarty->assign(array('month' => $month, 'year' => $year, 'calendar' => $generator, 'navigation_pattern' => Calendar::getDashboardMonthUrl('-YEAR-', '-MONTH-'))); //BOF:mod 20110623 $tabs = new NamedList(); $tabs->add('dashboard', array('text' => 'Active Teams', 'url' => assemble_url('dashboard'))); $tabs->add('home_page', array('text' => 'Home Page', 'url' => assemble_url('goto_home_tab'))); $this->smarty->assign('page_tabs', $tabs); //EOF:mod 20110623 }
/** * Constructor * * @param void * @return AssignmentsController */ function __construct($request) { parent::__construct($request); $filter_id = $this->request->getId('filter_id'); if (!$filter_id) { $filter_id = UserConfigOptions::getValue('default_assignments_filter', $this->logged_user); } // if if ($filter_id) { $this->active_filter = AssignmentFilters::findById($filter_id); } // if if (!instance_of($this->active_filter, 'AssignmentFilter')) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $this->smarty->assign('active_filter', $this->active_filter); if (AssignmentFilter::canAdd($this->logged_user)) { $this->wireframe->addPageAction(lang('New Filter'), assemble_url('assignments_filter_add')); } // if $this->wireframe->addBreadCrumb(lang('Assignments'), assemble_url('assignments')); $this->wireframe->current_menu_item = 'assignments'; }
/** * Constructor * * @param Request $request * @return ApplicationController */ function __construct($request) { parent::__construct($request); // Set detault layout for application pages $this->setLayout(array('module' => SYSTEM_MODULE, 'layout' => 'wireframe')); // Get Smarty instance... We need it $this->smarty =& Smarty::instance(); // Load and init owner company $this->owner_company = get_owner_company(); if (instance_of($this->owner_company, 'Company')) { cache_set('owner_company', $this->owner_company); } else { $this->httpError(HTTP_ERR_NOT_FOUND, 'Owner company is not defined'); } // if $this->application =& application(); $this->authentication =& Authentication::instance(); $this->logged_user =& $this->authentication->provider->getUser(); $this->wireframe =& Wireframe::instance(); $this->wireframe->page_company = $this->owner_company; $this->theme_name = instance_of($this->logged_user, 'User') ? UserConfigOptions::getValue('theme', $this->logged_user) : ConfigOptions::getValue('theme'); $this->smarty->assign(array('root_url' => ROOT_URL, 'assets_url' => ASSETS_URL)); // Maintenance mode if (ConfigOptions::getValue('maintenance_enabled')) { if (instance_of($this->logged_user, 'User') && $this->logged_user->isAdministrator()) { $this->wireframe->addPageMessage(lang('System is in maintenance mode and can be used by administrators only. <a href=":url">Click here</a> to turn off maintenance mode', array('url' => assemble_url('admin_settings_maintenance'))), 'warning'); } else { $additional_error_info = ConfigOptions::getValue('maintenance_message'); if ($additional_error_info) { $additional_error_info .= "\n\n"; } // if $additional_error_info .= lang('When system is in maintenance mode, administrators can log in and access the system') . ": " . assemble_url('login'); $this->smarty->assign('additional_error_info', $additional_error_info); if ($this->restrict_access_in_maintenance_mode) { $this->httpError(503); } // if } // if } // if // Check permissions if ($this->login_required && !instance_of($this->logged_user, 'User')) { // If async don't redirect to loging, just server proper HTTP code if ($this->request->isAsyncCall()) { $this->httpError(HTTP_ERR_UNAUTHORIZED, null, true, true); // Not async? Redirect to login with extracted route data... } else { $params = array(); if ($request->matched_route != 'login') { $params['re_route'] = $request->matched_route; foreach ($this->request->url_params as $k => $v) { if ($k == 'module' || $k == 'controller' || $k == 'action') { continue; } // if $params["re_{$k}"] = $v; } // foreach } // if $this->redirectTo($this->login_route, $params); } // if } // if if (instance_of($this->logged_user, 'User') && !$this->logged_user->getSystemPermission('system_access')) { $this->authentication->provider->logUserOut(); $this->httpError(HTTP_ERR_FORBIDDEN); } // if $loaded_modules = $this->application->getModules(); $assets_query_string = 'v=' . $this->application->version . '&modules='; foreach ($loaded_modules as $loaded_module) { $assets_query_string .= $loaded_module->getName() . ','; } // foreach $this->smarty->assign(array('api_status' => API_STATUS, 'application' => $this->application, 'owner_company' => $this->owner_company, 'authentication' => $this->authentication, 'logged_user' => $this->logged_user, 'request' => $this->request, 'theme_name' => $this->theme_name, 'request_time' => $this->request_time, 'loaded_modules' => $this->application->getModules(), 'captcha_url' => ROOT_URL . '/captcha.php?id=' . md5(time()), 'assets_query_string' => $assets_query_string, 'js_disabled_url' => assemble_url('js_disabled'))); $this->smarty->assign_by_ref('wireframe', $this->wireframe); js_assign(array('homepage_url' => ROOT_URL, 'assets_url' => ASSETS_URL, 'indicator_url' => get_image_url('indicator.gif'), 'big_indicator_url' => get_image_url('indicator_big.gif'), 'ok_indicator_url' => get_image_url('ok_indicator.gif'), 'warning_indicator_url' => get_image_url('warning_indicator.gif'), 'error_indicator_url' => get_image_url('error_indicator.gif'), 'pending_indicator_url' => get_image_url('pending_indicator.gif'), 'url_base' => URL_BASE, 'keep_alive_interval' => KEEP_ALIVE_INTERVAL, 'refresh_session_url' => assemble_url('refresh_session'), 'jump_to_project_url' => assemble_url('jump_to_project_widget'), 'quick_add_url' => assemble_url('quick_add'), 'path_info_through_query_string' => PATH_INFO_THROUGH_QUERY_STRING, 'image_picker_url' => assemble_url('image_picker'), 'copyright_removed' => LICENSE_COPYRIGHT_REMOVED, 'custom_tabs_manager' => assemble_url('custom_tabs_manager'), 'add_milestone_url' => assemble_url('project_milestones_add', array('project_id' => '--PROJECT_ID--')), 'add_checklist_url' => assemble_url('project_checklists_add', array('project_id' => '--PROJECT_ID--')), 'add_discussion_url' => assemble_url('project_discussions_add', array('project_id' => '--PROJECT_ID--')), 'add_file_url' => assemble_url('project_files_upload', array('project_id' => '--PROJECT_ID--')), 'add_page_url' => assemble_url('project_pages_add', array('project_id' => '--PROJECT_ID--')), 'add_ticket_url' => assemble_url('project_tickets_add', array('project_id' => '--PROJECT_ID--')), 'add_timerecord_url' => assemble_url('project_time_add', array('project_id' => '--PROJECT_ID--')), 'attachment_rename_url' => assemble_url('attachment_rename', array('project_id' => '--PROJECT_ID--', 'attachment_id' => '--ATTACHMENT_ID--')), 'attachment_copy_to_url' => assemble_url('attachment_copy_to', array('project_id' => '--PROJECT_ID--', 'attachment_id' => '--ATTACHMENT_ID--')), 'attachment_move_to_url' => assemble_url('attachment_move_to', array('project_id' => '--PROJECT_ID--', 'attachment_id' => '--ATTACHMENT_ID--')), 'image_uploader_url' => assemble_url('image_uploader'), 'render_comments_url' => assemble_url('render_comments'), 'move_task_url' => assemble_url('project_task_move', array('project_id' => '--PROJECT_ID--', 'task_id' => '--TASK_ID--')), 'get_collection_url' => assemble_url('collection'), 'quick_task_reminder_url' => assemble_url('project_task_quickreminder', array('project_id' => '--PROJECT_ID--', 'task_id' => '--TASK_ID--')), 'convert_to_ticket_url' => assemble_url('project_object_convert_to_ticket', array('project_id' => '--PROJECT_ID--', 'object_id' => '--OBJECT_ID--')), 'convert_to_milestone_url' => assemble_url('project_object_convert_to_milestone', array('project_id' => '--PROJECT_ID--', 'object_id' => '--OBJECT_ID--')), 'convert_to_page_url' => assemble_url('project_object_convert_to_page', array('project_id' => '--PROJECT_ID--', 'object_id' => '--OBJECT_ID--')), 'snooze_task_url' => assemble_url('project_task_snooze', array('project_id' => '--PROJECT_ID--', 'task_id' => '--TASK_ID--')))); if ($this->logged_user) { $link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); if (!empty($_SESSION['pg_ttl'])) { mysql_query("update healingcrystals_user_visited_pages set title='" . mysql_real_escape_string($_SESSION['pg_ttl']) . "' where user_id='" . $this->logged_user->getId() . "' and access_time='" . date('Y-m-d H:i:s', $_SESSION['temp_time']) . "'"); } $current_url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $pos = strpos($_SERVER['QUERY_STRING'], '%2F'); if ($pos !== false) { $max_pages_count_per_user = 50; //require_once SMARTY_PATH . '/plugins/function.page_title.php'; //$current_page_title = smarty_function_page_title(array('default' => 'Projects')); //$current_page_title = PageConstruction::getPageTitle(); $_SESSION['temp_time'] = time(); mysql_query("insert into healingcrystals_user_visited_pages (user_id, page_url, title, access_time) values ('" . $this->logged_user->getId() . "', '" . $current_url . "', '', '" . date('Y-m-d H:i:s', $_SESSION['temp_time']) . "')"); //mysql_query("insert into healingcrystals_user_visited_pages (user_id, page_url, title, access_time) values ('" . $this->logged_user->getId() . "', '" . $current_url . "', '', now())"); $query = "select count(*) as count from healingcrystals_user_visited_pages where user_id='" . $this->logged_user->getId() . "'"; $result = mysql_query($query); $info = mysql_fetch_assoc($result); $current_count = $info['count']; if ($current_count > $max_pages_count_per_user) { $querries = array(); $query = "select * from healingcrystals_user_visited_pages where user_id='" . $this->logged_user->getId() . "' order by access_time limit 0, " . ($current_count - $max_pages_count_per_user); $result = mysql_query($query); while ($info = mysql_fetch_assoc($result)) { $querries[] = "delete from healingcrystals_user_visited_pages where user_id='" . $this->logged_user->getId() . "' and page_url='" . $info['page_url'] . "' and access_time='" . $info['access_time'] . "'"; } } foreach ($querries as $query) { mysql_query($query); } } $_SESSION['pg_ttl'] = ''; mysql_close($link); } }
/** * Return config option value * * @param string $name * @return mixed */ function getConfigValue($name) { return UserConfigOptions::getValue($name, $this); }
/** * Shows a assignments page * */ function assignments() { $filter_id = $this->request->getId('filter_id'); if (!$filter_id) { $filter_id = UserConfigOptions::getValue('default_assignments_filter', $this->logged_user); } // if if ($filter_id) { $active_filter = AssignmentFilters::findById($filter_id); } // if $page = $this->getPaginationPage(); $per_page = 15; $pagination = null; if (instance_of($active_filter, 'AssignmentFilter')) { list($assignments, $pagination) = AssignmentFilters::executeFilter($this->logged_user, $active_filter, true, $page, $per_page); } else { $assignments = array(); } // if $this->smarty->assign(array("objects" => $assignments, "page_title" => lang('Assignments'), 'grouped_filters' => AssignmentFilters::findGrouped($this->logged_user), "active_filter" => $active_filter, 'pagination' => $pagination, 'pagination_url' => assemble_url('mobile_access_assignments'))); }
/** * Return user GMT offset * * Return number of seconds that current user is away from the GMT. If user is * not logged in this function should return system offset * * @param User $user * @return integer */ function get_user_gmt_offset($user = null) { static $offset = array(); if (!instance_of($user, 'User')) { $user = get_logged_user(); } // if if (!instance_of($user, 'User')) { return get_system_gmt_offset(); } // if if (!isset($offset[$user->getId()])) { $timezone_offset = UserConfigOptions::getValue('time_timezone', $user); $dst = UserConfigOptions::getValue('time_dst', $user); $offset[$user->getId()] = $dst ? $timezone_offset + 3600 : $timezone_offset; } // if return $offset[$user->getId()]; }
/** * Initialize locale settings based on logged in user * * @param void * @return null */ function init_locale() { // Used when application is initialized from command line (we don't have // all the classes available) if (!class_exists('ConfigOptions') || !class_exists('UserConfigOptions')) { return true; } // if $logged_user =& get_logged_user(); $language_id = null; if (instance_of($logged_user, 'User')) { if (LOCALIZATION_ENABLED) { $language_id = UserConfigOptions::getValue('language', $logged_user); } // if $format_date = UserConfigOptions::getValue('format_date', $logged_user); $format_time = UserConfigOptions::getValue('format_time', $logged_user); } else { if (LOCALIZATION_ENABLED) { $language_id = ConfigOptions::getValue('language'); } // if $format_date = ConfigOptions::getValue('format_date'); $format_time = ConfigOptions::getValue('format_time'); } // if $language = new Language(); // Now load languages if (LOCALIZATION_ENABLED && $language_id) { $language = Languages::findById($language_id); if (instance_of($language, 'Language')) { $current_locale = $language->getLocale(); $GLOBALS['current_locale'] = $current_locale; $GLOBALS['current_locale_translations'] = array(); if ($current_locale != BUILT_IN_LOCALE) { setlocale(LC_ALL, $current_locale); // Set locale // workaround for tr, ku, az locales according to http://bugs.php.net/bug.php?id=18556 $current_locale_country = explode('.', $current_locale); $current_locale_country = strtolower($current_locale_country[0]); if (in_array($current_locale_country, array('tr_tr', 'ku', 'az_az'))) { setlocale(LC_CTYPE, BUILT_IN_LOCALE); } // if $GLOBALS['current_locale_translations'][$current_locale] = array(); $language->loadTranslations($current_locale); } // if } // if } // if $this->smarty->assign('current_language', $language); define('USER_FORMAT_DATETIME', "{$format_date} {$format_time}"); define('USER_FORMAT_DATE', $format_date); define('USER_FORMAT_TIME', $format_time); return true; }
/** * Send welcome message * * @param void * @return null */ function send_welcome_message() { if ($this->active_user->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_user->canSendWelcomeMessage($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $this->skip_layout = $this->request->isAsyncCall(); $welcome_message_data = $this->request->post('welcome_message'); if (!is_array($welcome_message_data)) { $welcome_message_data = array('message' => UserConfigOptions::getValue('welcome_message', $this->active_user)); } // if $this->smarty->assign('welcome_message_data', $welcome_message_data); if ($this->request->isSubmitted()) { $welcome_message = trim(array_var($welcome_message_data, 'message')); if ($welcome_message) { UserConfigOptions::setValue('welcome_message', $welcome_message, $this->active_user); } else { UserConfigOptions::removeValue('welcome_message', $this->active_user); } // if $password = make_password(11); $this->active_user->setPassword($password); $save = $this->active_user->save(); if ($save && !is_error($save)) { $welcome_message_sent = ApplicationMailer::send(array($this->active_user), 'system/new_user', array('created_by_id' => $this->logged_user->getId(), 'created_by_name' => $this->logged_user->getDisplayName(), 'created_by_url' => $this->logged_user->getViewUrl(), 'email' => $this->active_user->getEmail(), 'password' => $password, 'login_url' => assemble_url('login'), 'welcome_body' => $welcome_message ? nl2br(clean($welcome_message)) : '')); if ($welcome_message_sent) { $message = lang('Welcome message has been sent to :name', array('name' => $this->active_user->getDisplayName())); } else { $message = lang('Failed to send welcome message to :name. Please try again later', array('name' => $this->active_user->getDisplayName())); } // if if ($this->request->isAsyncCall()) { die($message); } else { flash_success($message); $this->redirectToUrl($this->active_user->getViewUrl()); } // if } else { if ($this->request->isAsyncCall()) { $this->httpError(HTTP_ERR_OPERATION_FAILED); } else { flash_error($message); $this->redirectToUrl($this->active_user->getViewUrl()); } // if } // if } // if }
/** * Render HTML editor * * @param array $params * @param string $content * @param Smarty $smarty * @param boolean $repeat * @return string */ function smarty_block_editor_field($params, $content, &$smarty, &$repeat) { static $ids = array(), $files_included = false; // if browser is ipad, we need to turn visual editor off if (USER_AGENT == USER_AGENT_IPAD) { $visual = false; } else { if (isset($params['visual'])) { $visual = array_var($params, 'visual', true, true); } else { $logged_user = $smarty->get_template_vars('logged_user'); if (instance_of($logged_user, 'User')) { $visual = UserConfigOptions::getValue('visual_editor', $logged_user); // if user is loaded $visual is set dependable of user config option } else { $visual = true; } // if } } // if $id = array_var($params, 'id'); if (empty($id)) { $counter = 1; do { $id = "visual_editor_{$counter}"; $counter++; } while (in_array($id, $ids)); } // if $ids[] = $id; $params['id'] = $id; //$hide_editor = array_var($params, 'hide_editor'); //if (empty($hide_editor)){ $params['mce_editable'] = true; //} if (!isset($params['auto_expand'])) { $params['auto_expand'] = 'yes'; } // if if ($visual && !$files_included) { $page =& PageConstruction::instance(); $disable_image_upload = array_var($params, 'disable_image_upload', false); $page->addScript(get_asset_url('javascript/tinymce/tiny_mce.js'), false); $page->addScript(get_asset_url('javascript/tinymce/tiny_mce_init.js'), false); echo "<script type='text/javascript'>"; if ($disable_image_upload) { echo "App.widgets.EditorImagePicker.disable_image_upload = true;"; } // if echo "</script>"; $files_included = true; } // if if (isset($params['class'])) { $classes = explode(' ', $params['class']); $classes[] = 'editor'; if (in_array('tiny_value_present', $classes) && !$visual) { $classes[] = 'required'; } // if $params['class'] = implode(' ', $classes); } else { $params['class'] = 'editor'; } // if $return_string = ''; if (!($variable_name = array_var($params, 'variable_name'))) { $name_parameter = array_var($params, 'name'); $variable_name = substr($name_parameter, 0, strrpos($name_parameter, '[')); } // if $variable_name .= '[inline_attachments][]'; $inline_attachments = array_var($params, 'inline_attachments'); if (is_foreachable($inline_attachments)) { foreach ($inline_attachments as $inline_attachment) { $return_string .= '<input type=hidden name="' . $variable_name . '" value="' . $inline_attachment . '" />' . "\n"; } // foreach } // if unset($params['inline_attachments']); unset($params['variable_name']); $params['inline_attachments_name'] = $variable_name; $return_string .= open_html_tag('textarea', $params) . clean($content) . '</textarea>'; return $return_string; }
/** * Prepare conditions based on filter settings * * @param User $user * @return string */ function prepareConditions($user) { $project_objects_table = TABLE_PREFIX . 'project_objects'; $assignments_table = TABLE_PREFIX . 'assignments'; $completable_types = get_completable_project_object_types(); $conditions = array(); // Selected projects filter if ($this->getProjectFilter() == PROJECT_FILTER_SELECTED) { $project_ids = $this->getProjectFilterData(); if ($project_ids) { $conditions[] = db_prepare_string("({$project_objects_table}.project_id IN (?))", array($project_ids)); $types_filter = ProjectUsers::getVisibleTypesFilter($user, null, $completable_types); if ($types_filter) { $conditions[] = $types_filter; } else { return false; // No access to any of the projects? } // if } // if } // if // All projects if (count($conditions) == 0) { $types_filter = ProjectUsers::getVisibleTypesFilter($user, array(PROJECT_STATUS_ACTIVE), $completable_types); if ($types_filter) { $conditions[] = $types_filter; } else { return false; // No access to any of the projects? } // if } // if // User filter switch ($this->getUserFilter()) { // Not assigned to anyone case USER_FILTER_NOT_ASSIGNED: $user_id = $user->getId(); $conditions[] = "({$assignments_table}.user_id IS NULL)"; break; // Logged user // Logged user case USER_FILTER_LOGGED_USER: $user_id = $user->getId(); $conditions[] = "({$assignments_table}.user_id = {$user_id})"; break; // Logged user is responsible // Logged user is responsible case USER_FILTER_LOGGED_USER_RESPONSIBLE: $user_id = $user->getId(); $conditions[] = "({$assignments_table}.user_id = {$user_id}) AND ({$assignments_table}.is_owner = 1)"; break; // All members of a specific company // All members of a specific company case USER_FILTER_COMPANY: $visible_user_ids = $user->visibleUserIds(); if (!is_foreachable($visible_user_ids)) { return false; } // if $company_id = $this->getUserFilterData(); if ($company_id) { $company = Companies::findById($company_id); if (instance_of($company, 'Company')) { $user_ids = Users::findUserIdsByCompany($company); if (is_foreachable($user_ids)) { foreach ($user_ids as $k => $v) { if (!in_array($v, $visible_user_ids)) { unset($user_ids[$k]); } // if } // if if (count($user_ids) > 0) { $imploded = implode(', ', $user_ids); $conditions[] = "({$assignments_table}.user_id IN ({$imploded}))"; } else { return false; } // if } // if } // if } // if break; // Selected users // Selected users case USER_FILTER_SELECTED: $visible_user_ids = $user->visibleUserIds(); if (!is_foreachable($visible_user_ids)) { return false; } // if $user_ids = $this->getUserFilterData(); if (is_foreachable($user_ids)) { foreach ($user_ids as $k => $v) { if (!in_array($v, $visible_user_ids)) { unset($user_ids[$k]); } // if } // foreach if (count($user_ids) > 0) { $imploded = implode(', ', $user_ids); $conditions[] = "({$assignments_table}.user_id IN ({$imploded}))"; } else { return false; } // if } // if break; } // switch $today = new DateValue(time() + get_user_gmt_offset($user)); // Calculate user timezone when determining today switch ($this->getDateFilter()) { // List late assignments case DATE_FILTER_LATE: $today_str = db_escape($today->toMySQL()); $conditions[] = "({$project_objects_table}.due_on < {$today_str})"; break; // List today assignments // List today assignments case DATE_FILTER_TODAY: $today_str = db_escape($today->toMySQL()); $conditions[] = "({$project_objects_table}.due_on = {$today_str})"; break; // List tomorrow assignments // List tomorrow assignments case DATE_FILTER_TOMORROW: $tomorrow = $today->advance(86400, false); $tomorrow_str = db_escape($tomorrow->toMySQL()); $conditions[] = "({$project_objects_table}.due_on = {$tomorrow_str})"; break; // List this week assignments // List this week assignments case DATE_FILTER_THIS_WEEK: $first_day_sunday = UserConfigOptions::getValue('time_first_week_day', $user) == 0; $week_start = $today->beginningOfWeek($first_day_sunday); $week_end = $today->endOfWeek($first_day_sunday); $week_start_str = db_escape($week_start->toMySQL()); $week_end_str = db_escape($week_end->toMySQL()); $conditions[] = "({$project_objects_table}.due_on >= {$week_start_str} AND {$project_objects_table}.due_on <= {$week_end_str})"; break; // List next week assignments // List next week assignments case DATE_FILTER_NEXT_WEEK: $first_day_sunday = UserConfigOptions::getValue('time_first_week_day', $user) == 0; $next_week = $today->advance(604800, false); $week_start = $next_week->beginningOfWeek($first_day_sunday); $week_end = $next_week->endOfWeek($first_day_sunday); $week_start_str = db_escape($week_start->toMySQL()); $week_end_str = db_escape($week_end->toMySQL()); $conditions[] = "({$project_objects_table}.due_on >= {$week_start_str} AND {$project_objects_table}.due_on <= {$week_end_str})"; break; // List this month assignments // List this month assignments case DATE_FILTER_THIS_MONTH: $month_start = DateTimeValue::beginningOfMonth($today->getMonth(), $today->getYear()); $month_end = DateTimeValue::endOfMonth($today->getMonth(), $today->getYear()); $month_start_str = db_escape($month_start->toMySQL()); $month_end_str = db_escape($month_end->toMySQL()); $conditions[] = "({$project_objects_table}.due_on >= {$month_start_str} AND {$project_objects_table}.due_on <= {$month_end_str})"; break; // List next month assignments // List next month assignments case DATE_FILTER_NEXT_MONTH: $month = $today->getMonth() + 1; $year = $today->getYear(); if ($month == 13) { $month = 1; $year += 1; } // if $month_start = DateTimeValue::beginningOfMonth($month, $year); $month_end = DateTimeValue::endOfMonth($month, $year); $month_start_str = db_escape($month_start->toMySQL()); $month_end_str = db_escape($month_end->toMySQL()); $conditions[] = "({$project_objects_table}.due_on >= {$month_start_str} AND {$project_objects_table}.due_on <= {$month_end_str})"; break; // Specific date // Specific date case DATE_FILTER_SELECTED_DATE: $date_from = $this->getDateFrom(); if (instance_of($date_from, 'DateTimeValue')) { $date_from_str = db_escape($date_from->toMySql()); $conditions[] = "({$project_objects_table}.due_on = {$date_from_str})"; } // if break; // Specific range // Specific range case DATE_FILTER_SELECTED_RANGE: $date_from = $this->getDateFrom(); $date_to = $this->getDateTo(); if (instance_of($date_from, 'DateValue') && instance_of($date_to, 'DateValue')) { $date_from_str = db_escape($date_from->toMySQL()); $date_to_str = db_escape($date_to->toMySQL()); $conditions[] = "({$project_objects_table}.due_on >= {$date_from_str} AND {$project_objects_table}.due_on <= {$date_to_str})"; } // if break; } // switch // Status filter switch ($this->getStatusFilter()) { case STATUS_FILTER_ACTIVE: $conditions[] = "({$project_objects_table}.completed_on IS NULL)"; break; case STATUS_FILTER_COMPLETED: $conditions[] = "({$project_objects_table}.completed_on IS NOT NULL)"; break; } // if // Additional filters $state = STATE_VISIBLE; $visibility = $user->getVisibility(); $conditions[] = "({$project_objects_table}.state >= {$state} AND {$project_objects_table}.visibility >= {$visibility})"; return implode(' AND ', $conditions); }
/** * Provide ajax functionality for menu badge * * @param void * @return void */ function count_new_messages() { $last_visit = UserConfigOptions::getValue('status_update_last_visited', $this->logged_user); echo StatusUpdates::countNewMessagesForUser($this->logged_user, $last_visit); die; }
/** * Prepare conditions based on report settings * * @param User $user * @param Project $project * @return string */ function prepareConditions($user, $project = null) { $project_objects_table = TABLE_PREFIX . 'project_objects'; $conditions = array(); // Project and type if (instance_of($project, 'Project')) { $conditions[] = db_prepare_string('project_id = ? AND type = ?', array($project->getId(), 'timerecord')); } else { $conditions[] = db_prepare_string('type = ?', array('timerecord')); } // if // User filter switch ($this->getUserFilter()) { // Anyone - This filter used to filter only time tracked from all // visible users, but that did not include deleted accounts. Fixed now // //case USER_FILTER_ANYBODY: // $visible_user_ids = $user->visibleUserIds(); // if(is_foreachable($visible_user_ids)) { // $conditions[] = "($project_objects_table.integer_field_1 IN (" . db_escape($visible_user_ids) . '))'; // } else { // return false; // not visible users // } // if // break; // Logged user case USER_FILTER_LOGGED_USER: $user_id = $user->getId(); $conditions[] = "({$project_objects_table}.integer_field_1 = {$user_id})"; break; // All members of a specific company // All members of a specific company case USER_FILTER_COMPANY: $visible_user_ids = $user->visibleUserIds(); if (!is_foreachable($visible_user_ids)) { return false; } // if $company_id = $this->getUserFilterData(); if ($company_id) { $company = Companies::findById($company_id); if (instance_of($company, 'Company')) { $user_ids = Users::findUserIdsByCompany($company); if (is_foreachable($user_ids)) { foreach ($user_ids as $k => $v) { if (!in_array($v, $visible_user_ids)) { unset($user_ids[$k]); } // if } // if if (count($user_ids) > 0) { $imploded = implode(', ', $user_ids); $conditions[] = "({$project_objects_table}.integer_field_1 IN ({$imploded}))"; } else { return false; } // if } // if } // if } // if break; // Selected users // Selected users case USER_FILTER_SELECTED: $visible_user_ids = $user->visibleUserIds(); if (!is_foreachable($visible_user_ids)) { return false; } // if $user_ids = $this->getUserFilterData(); if (is_foreachable($user_ids)) { foreach ($user_ids as $k => $v) { if (!in_array($v, $visible_user_ids)) { unset($user_ids[$k]); } // if } // foreach if (count($user_ids) > 0) { $imploded = implode(', ', $user_ids); $conditions[] = "({$project_objects_table}.integer_field_1 IN ({$imploded}))"; } else { return false; } // if } // if break; } // switch $today = new DateValue(time() + get_user_gmt_offset($user)); // Calculate user timezone when determining today switch ($this->getDateFilter()) { // List time records posted for today case DATE_FILTER_TODAY: $today_str = db_escape($today->toMySQL()); $conditions[] = "({$project_objects_table}.date_field_1 = {$today_str})"; break; // List next week records // List next week records case DATE_FILTER_LAST_WEEK: $first_day_sunday = UserConfigOptions::getValue('time_first_week_day', $user) == 0; $last_week = $today->advance(-604800, false); $week_start = $last_week->beginningOfWeek($first_day_sunday); $week_end = $last_week->endOfWeek($first_day_sunday); $week_start_str = db_escape($week_start->toMySQL()); $week_end_str = db_escape($week_end->toMySQL()); $conditions[] = "({$project_objects_table}.date_field_1 >= {$week_start_str} AND {$project_objects_table}.date_field_1 <= {$week_end_str})"; break; // List this week records // List this week records case DATE_FILTER_THIS_WEEK: $first_day_sunday = UserConfigOptions::getValue('time_first_week_day', $user) == 0; $week_start = $today->beginningOfWeek($first_day_sunday); $week_end = $today->endOfWeek($first_day_sunday); $week_start_str = db_escape($week_start->toMySQL()); $week_end_str = db_escape($week_end->toMySQL()); $conditions[] = "({$project_objects_table}.date_field_1 >= {$week_start_str} AND {$project_objects_table}.date_field_1 <= {$week_end_str})"; break; // List this month time records // List this month time records case DATE_FILTER_LAST_MONTH: $month = $today->getMonth() - 1; $year = $today->getYear(); if ($month == 0) { $month = 12; $year -= 1; } // if $month_start = DateTimeValue::beginningOfMonth($month, $year); $month_end = DateTimeValue::endOfMonth($month, $year); $month_start_str = db_escape($month_start->toMySQL()); $month_end_str = db_escape($month_end->toMySQL()); $conditions[] = "({$project_objects_table}.date_field_1 >= {$month_start_str} AND {$project_objects_table}.date_field_1 <= {$month_end_str})"; break; // Last month // Last month case DATE_FILTER_THIS_MONTH: $month_start = DateTimeValue::beginningOfMonth($today->getMonth(), $today->getYear()); $month_end = DateTimeValue::endOfMonth($today->getMonth(), $today->getYear()); $month_start_str = db_escape($month_start->toMySQL()); $month_end_str = db_escape($month_end->toMySQL()); $conditions[] = "({$project_objects_table}.date_field_1 >= {$month_start_str} AND {$project_objects_table}.date_field_1 <= {$month_end_str})"; break; // Specific date // Specific date case DATE_FILTER_SELECTED_DATE: $date_from = $this->getDateFrom(); if (instance_of($date_from, 'DateValue')) { $date_from_str = db_escape($date_from->toMySql()); $conditions[] = "({$project_objects_table}.date_field_1 = {$date_from_str})"; } // if break; // Specific range // Specific range case DATE_FILTER_SELECTED_RANGE: $date_from = $this->getDateFrom(); $date_to = $this->getDateTo(); if (instance_of($date_from, 'DateValue') && instance_of($date_to, 'DateValue')) { $date_from_str = db_escape($date_from->toMySQL()); $date_to_str = db_escape($date_to->toMySQL()); $conditions[] = "({$project_objects_table}.date_field_1 >= {$date_from_str} AND {$project_objects_table}.date_field_1 <= {$date_to_str})"; } // if break; } // switch // Billable filter switch ($this->getBillableFilter()) { case BILLABLE_FILTER_BILLABLE: $conditions[] = "({$project_objects_table}.integer_field_2 = '" . BILLABLE_STATUS_BILLABLE . "')"; break; case BILLABLE_FILTER_NOT_BILLABLE: $conditions[] = "({$project_objects_table}.integer_field_2 = '" . BILLABLE_STATUS_NOT_BILLABLE . "' OR {$project_objects_table}.integer_field_2 IS NULL)"; break; case BILLABLE_FILTER_BILLABLE_BILLED: $conditions[] = "({$project_objects_table}.integer_field_2 >= '" . BILLABLE_STATUS_BILLED . "')"; break; case BILLABLE_FILTER_PENDING_PAYMENT: $conditions[] = "({$project_objects_table}.integer_field_2 = '" . BILLABLE_STATUS_PENDING_PAYMENT . "')"; break; case BILLABLE_FILTER_BILLABLE_NOT_BILLED: $conditions[] = "({$project_objects_table}.integer_field_2 IN ('" . BILLABLE_STATUS_BILLABLE . "', '" . BILLABLE_STATUS_PENDING_PAYMENT . "'))"; break; } // switch // Additional filters $state = STATE_VISIBLE; $visibility = $user->getVisibility(); $conditions[] = "({$project_objects_table}.state >= {$state} AND {$project_objects_table}.visibility >= {$visibility})"; return implode(' AND ', $conditions); }