sproctor / php-calendar

PHP-Calendar
http://www.php-calendar.org/
Apache License 2.0
140 stars 67 forks source link

filter shown events by user/group/category #126

Open aa123aa1 opened 9 years ago

aa123aa1 commented 9 years ago

use 2.0 , http://localhost:1108/php-calendar/index.php?action=display_week&week=3&year=2015
, When different groups have different user, we want to refer to different users published in weekly content, how to add an option in the week list. First select the user group, and then select a user name, different groups of users appear to correspond to members of their own user groups, is not a member of their group is not displayed, choose a different user access is very useful, can more quickly know weekly working situation of each username .please how to add code to do it ? thanks. choose

aa123aa1 commented 9 years ago

Of course, at the same time, best can also add the above function in the monthly inside. This can quickly select access to users: event, if there are many user, or to choose a group and then select the user, or do not know what is the user's group, so you know his daily, weekly, monthly, fill in

aa123aa1 commented 9 years ago

display_week.php

<?php
/*
- Copyright 2013 Sean Proctor
  *
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
  *
-      http://www.apache.org/licenses/LICENSE-2.0
  *
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
  */

/*
   This file has the functions for the main displays of the calendar
*/

if ( !defined('IN_PHPC') ) {
       die("Hacking attempt");
}

// Full display for a month
function display_week()
{
    global $vars;

$heading_html = tag('tr'); $heading_html->add(tag('th',create_dropdown_listuser($userlist, $userlists), __p('Week', 'W'))); for($i = 0; $i < 7; $i++) { $d = ($i + day_of_week_start()) % 7; $heading_html->add(tag('th', day_name($d))); }

if(!isset($vars['week']) || !isset($vars['year'])) soft_error(__('Invalid date.'));

$week_of_year = $vars['week']; $year = $vars['year'];

$day_of_year = 1 + ($week_of_year - 1) * 7 - day_of_week(1, 1, $year); $from_stamp = mktime(0, 0, 0, 1, $day_of_year, $year); $start_month = date("n", $from_stamp); $start_year = date("Y", $from_stamp);

$last_day = $day_of_year + 6; $to_stamp = mktime(0, 0, 0, 1, $last_day, $year); $end_month = date("n", $to_stamp); $end_year = date("Y", $to_stamp);

$heading = month_name($start_month) . " $start_year"; if($end_month != $start_month) $heading .= " - " . month_name($end_month) . " $end_year";

return tag('', tag("div", attributes('id="phpc-summary-view"'), tag("div", attributes('id="phpc-summary-head"'), tag("div", attributes('id="phpc-summary-title"'), ''), tag("div", attributes('id="phpc-summary-author"'), ''), tag("div", attributes('id="phpc-summary-category"'), ''), tag("div", attributes('id="phpc-summary-time"'), '')), tag("div", attributes('id="phpc-summary-body"'), '')), tag('table', attributes('class="phpc-main phpc-calendar"'), tag('caption', $heading), tag('colgroup', tag('col', attributes('class="phpc-week"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')) ), tag('thead', $heading_html), create_week($week_of_year, $from_stamp, $to_stamp, $year)));


}

// creates a display for a particular week to be embedded in a month table
function create_week($week_of_year, $from_stamp, $to_stamp, $year) {
    global $phpcdb, $phpcid, $phpc_cal,$vars;

$start_day = date("j", $from_stamp); $start_month = date("n", $from_stamp); $start_year = date("Y", $from_stamp);

$max_events = $phpc_cal->events_max;

$results = $phpcdb->get_occurrences_by_date_range($phpcid, $from_stamp, $to_stamp); $days_events = array(); while($row = $results->fetch_assoc()) { $event = new PhpcOccurrence($row);

if(!$event->can_read())
    continue;

if(!empty($vars['uid']) && $vars['uid'] != $event->uid)
continue;

    if(!empty($vars['catid']) && $vars['catid'] != $event->catid)
continue;

    if(!empty($vars['gid']) && $vars['gid'] != $event->gid)
continue;

$end_stamp = mktime(0, 0, 0, $event->get_end_month(),
        $event->get_end_day(), $event->get_end_year());

$start_stamp = mktime(0, 0, 0, $event->get_start_month(),
        $event->get_start_day(),
        $event->get_start_year());

$diff = $from_stamp - $start_stamp;
if($diff > 0)
    $add_days = floor($diff / 86400);
else
    $add_days = 0;

// put the event in every day until the end
for(; ; $add_days++) {
    $stamp = mktime(0, 0, 0, $event->get_start_month(),
            $event->get_start_day() + $add_days,
            $event->get_start_year());

    if($stamp > $end_stamp || $stamp > $to_stamp)
        break;

    $key = date('Y-m-d', $stamp);
    if(!isset($days_events[$key]))
        $days_events[$key] = array();
    if(sizeof($days_events[$key]) == $max_events)
        $days_events[$key][] = false;
    if(sizeof($days_events[$key]) > $max_events)
        continue;
    $days_events[$key][] = $event;
}

} $week_table = tag('tbody');

$users = $phpcdb->get_users_with_permissions($phpcid); foreach ($users as $user) { $phpc_user = new PhpcUser($user); $group_list = array(); foreach($phpc_user->get_groups() as $group) { if($group['cid'] == $phpcid) $group_list[] = $group['name']; } $groups = implode(', ', $group_list);

}

$week_html = tag('tr', tag('th',user_list(),$user['username'], $week_of_year)); $week_table->add($week_html);

for($day_of_week = 0; $day_of_week < 7; $day_of_week++) { $day = $start_day + $day_of_week; $week_html->add(create_day($start_month, $day, $start_year, $days_events)); }

return $week_table;


}

function create_dropdown_listuser($title, $values, $attrs = false) {

global $users, $phpc_script, $phpcdb,$vars;

$list = tag('ul');

foreach($phpcdb->get_users() as $user) {

 $userslist = array($user->username);

foreach($phpcdb->get_groups() as $group) {

     $group_list = array($group->name);

       // $group_list[] = $group['name'];
}
$usergroup = implode(', ', $group_list);             
// $users = array(user_list());
$usersname = array(user_list(array("username" => $user->username)));
$usergroup = array(group_list(array("groups" => $group->groups)));

$useruid =array("uid" => $user->uid);                
$list->add(tag('li', tag('a', attrs("href=\"$key\""), $value)));

}

return tag('span', attrs('class="phpc-dropdown-list"'), tag('span', attrs('class="phpc-dropdown-list-header"'), tag('span', attrs('class="phpc-dropdown-list-title"'), $usergroup)), $usersname);


}

function user_list()
{
    global $phpc_script, $phpcdb;

$list = tag('ul');

$tbody = tag('tbody');

$tbody->add(tag('li', tag('th', __("Username"))

            ));
foreach($phpcdb->get_users() as $user) {
$group_list = array();

foreach($user->get_groups() as $group) {
    $group_list[] = $group['name'];
}
$groups = implode(', ', $group_list);

$tbody->add(tag('li', tag('a', attrs("href='$phpc_home_url?action=display_week&week=2&year=2015&uid={$user->uid}'", 'class="phpc-dropdown-list-title"'),$user->username)

            //tag('td', $groups),                                
            //array("uid" => $user->uid),

                    ));

}

return tag('table',attrs('class="phpc-main phpc-calendar"'),tag('caption',tag('span', attrs('class="phpc-dropdown-list"'),
    tag('span', attrs('class="phpc-dropdown-list-header"'),
        tag('span', attrs('class="phpc-dropdown-list-title"'),
        $tbody)),
    $list)));

}

function group_list()
{
    global $phpc_script, $phpcdb;
$tbody = tag('tbody');

$tbody->add(tag('tr', tag('th', __("Username"))

            ));
foreach($phpcdb->get_users() as $user) {
$group_list = array();
foreach($user->get_groups() as $group) {
    $group_list[] = $group['name'];
    $group_gid = $group['gid'];
}
$groups = implode(', ', $group_list);

$tbody->add(tag('tr', tag('a', attrs("href='$phpc_home_url?action=display_week&week=2&year=2015&gid={$group_gid}'", 'class="phpc-dropdown-list-title"'),$groups)

            //array("uid" => $user->uid),

                    ));

}

return tag('div', attributes('id="phpc-admin-users"'),tag('table',
        attributes('class="phpc-container"'),
    tag('caption', __('User List')), $tbody

            ));

}

// displays the day of the week and the following days of the week
function create_day($month, $day, $year, $days_events)
{
    global $phpc_script, $phpc_cal;

$date_class = 'ui-state-default'; if($day <= 0) { $month--; if($month < 1) { $month = 12; $year--; } $day += days_in_month($month, $year); $date_class .= ' phpc-shadow'; } elseif($day > days_in_month($month, $year)) { $day -= days_in_month($month, $year); $month++; if($month > 12) { $month = 1; $year++; } } else { $currentday = date('j'); $currentmonth = date('n'); $currentyear = date('Y');

// set whether the date is in the past or future/present
if($currentyear == $year && $currentmonth == $month
        && $currentday == $day) {
    $date_class .= ' ui-state-highlight';
}

}

$click = create_plain_link($day, 'display_day', $year, $month, $day); $date_tag = tag('div', attributes("class=\"phpc-date $date_class\"", "onclick=\"window.location.href='$click'\""), create_action_link_with_date($day, 'display_day', $year, $month, $day));

if($phpc_cal->can_write()) { $date_tag->add(create_action_link_with_date('+', 'event_form', $year, $month, $day, array('class="phpc-add"'))); }

$html_day = tag('td', $date_tag);

$stamp = mktime(0, 0, 0, $month, $day, $year);

$can_read = $phpc_cal->can_read(); $key = date('Y-m-d', $stamp); if(!$can_read || !array_key_exists($key, $days_events)) return $html_day;

$results = $days_events[$key]; if(empty($results)) return $html_day;

$html_events = tag('ul'); $html_day->add($html_events);

// Count the number of events foreach($results as $event) { if($event == false) { $event_html = tag('li', create_action_link_with_date(__("View Additional Events"), 'display_day', $year, $month, $day, array('class="phpc-date"'))); $html_events->add($event_html); break; }

// TODO - make sure we have permission to read the event

$subject = $event->get_subject();
if($event->get_start_timestamp() >= $stamp)
    $event_time = $event->get_time_string();
else
    $event_time = '(' . __('continued') . ')';
if(!empty($event_time))
    $title = "$event_time - $subject";
else
    $title = $subject;

$style = "";
if(!empty($event->text_color))
    $style .= "color: {$event->get_text_color()} !important;";
if(!empty($event->bg_color))
    $style .= "background: ".$event->get_bg_color()
        ." !important;";

$event_html = tag('li',
        create_occurrence_link($title, "display_event",
            $event->get_oid(),
            array("style=\"$style\"")));

$html_events->add($event_html);

}

return $html_day;


}

?>
aa123aa1 commented 9 years ago

i add some code in display_week.php , now can show group and usrname, but i can't let it display for choose in the pic.and i can't let someone username only display in him group .

aa123aa1 commented 9 years ago

Show only the same group of people belonging to their own events, other people don't show up, and to select user group and then display the user name of the order,

sproctor commented 1 year ago

My idea is to have the calendar be the basic unit of permission so this could be implemented using multiple calendars. One big flaw to this approach is that there's no easy way to group users to give them permission over multiple calendars. Part of the problem with that is there's no good way to assign permission to edit these groups that isn't global.

sproctor commented 1 year ago

It's been a long time since I've investigated the permissions here. Groups were just kind of tacked on. There's not a lot of benefit brought by them. I'm removing them for v3 until I figure out a good role for them.

One option is to have groups have an admin group. That would allow groups to scale to multiple calendars without necessarily being run by server admins.

I'm realizing this is very different from the request of this issue. I'm going to open a new issue for it.