From 89c174dcbc0298713a72dfa6a745c17db6ae133b Mon Sep 17 00:00:00 2001 From: skeeter Date: Sun, 11 Feb 2001 02:38:50 +0000 Subject: [PATCH] now works with new api - beginnings of ACL support --- calendar/edit_entry.php | 71 +++++++++++++-------- calendar/edit_entry_handler.php | 4 +- calendar/inc/class.calendar.inc.php | 2 +- calendar/month.php | 34 +++++----- calendar/view.php | 6 +- calendar/week.php | 96 +++++++++++++++++++---------- 6 files changed, 135 insertions(+), 78 deletions(-) diff --git a/calendar/edit_entry.php b/calendar/edit_entry.php index 90c2c05c8b..9a8494e4d2 100755 --- a/calendar/edit_entry.php +++ b/calendar/edit_entry.php @@ -17,7 +17,7 @@ $phpgw_info["flags"] = array("currentapp" => "calendar", "enable_nextmatchs_class" => True); include("../header.inc.php"); - + $sb = CreateObject("phpgwapi.sbox"); $cal_info = CreateObject('calendar.calendar_item'); @@ -36,6 +36,12 @@ $hourformat = "H"; } + if(!isset($owner)) { + $owner = $phpgw_info['user']['account_id']; + } else { + $owner = $phpgw_info['user']['account_id']; + } + if ($id > 0) { $cal = $phpgw->calendar->getevent(intval($id)); $cal_info = $cal[0]; @@ -48,12 +54,12 @@ $cal_info->rpt_end = $cal_info->datetime + 86400; } } else if(isset($readsess)) { - $cal_info = $phpgw->common->appsession(); - if(!$cal_info->owner) $cal_info->owner = $phpgw_info["user"]["account_id"]; + $cal_info = $phpgw->common->appsession('entry','calendar'); + if(!$cal_info->owner) $cal_info->owner = $owner; $can_edit = true; } else { $cal_info->id = 0; - $cal_info->owner = $phpgw_info["user"]["account_id"]; + $cal_info->owner = $owner; $can_edit = true; if (!isset($day) || !$day) @@ -170,35 +176,50 @@ display_item(lang("Access"),$sb->getAccessList("cal[access]",$cal_info->access)); // Groups - $db2 = $phpgw->db; - $db2->query("SELECT account_lid FROM phpgw_accounts WHERE account_id=".$cal_info->owner,__LINE__,__FILE__); - $db2->next_record(); - $user_groups = $phpgw->accounts->read_group_names($db2->f("account_lid")); - + $user_groups = $phpgw->accounts->memberships(intval($owner)); display_item(lang("Groups"),$sb->getGroups($user_groups,$cal_info->groups,"cal[groups][]")); // Participants - $db2 = $phpgw->db; - $db2->query("select account_id,account_lastname,account_firstname,account_lid " - . "from phpgw_accounts where account_status !='L' and " - . "account_id != ".$phpgw_info["user"]["account_id"]." " - . "and account_permissions like '%:calendar:%' " - . "order by account_lastname,account_firstname,account_lid"); + $accounts = $phpgw->acl->get_ids_for_location('run',1,'calendar'); + $users = Array(); + for($i=0;$iaccounts->get_type($accounts[$i])) { + case 'u' : + if($accounts[$i] != $owner && !$users[$accounts[$i]]) { + $users[$accounts[$i]] = $phpgw->common->grab_owner_name($accounts[$i]); + } + break; + case 'g' : + $group_members = $phpgw->acl->get_ids_for_location($accounts[$i],1,'phpgw_group'); + while($group_members && $user = each($group_members)) { + if($user[1] != $owner && !$users[$user[1]]) { + $users[$user[1]] = $phpgw->common->grab_owner_name($user[1]); + } + } + break; + } + } - if ($db2->num_rows() > 50) + $num_users = count($users); + if ($num_users > 50) { $size = 15; - else if ($db2->num_rows() > 5) + } else if ($num_users > 5) { $size = 5; - else - $size = $db2->num_rows(); + } else { + $size = $num_users; + } $str = ""; display_item(lang("Participants"),$str); diff --git a/calendar/edit_entry_handler.php b/calendar/edit_entry_handler.php index 31680154e6..9617f4b4d0 100755 --- a/calendar/edit_entry_handler.php +++ b/calendar/edit_entry_handler.php @@ -83,7 +83,7 @@ $cal_info->edatetime = mktime($cal_info->end_hour,$cal_info->end_minute,0,$cal_info->end_month,$cal_info->end_day,$cal_info->end_year) - ((60 * 60) * $phpgw_info["user"]["preferences"]["common"]["tz_offset"]); $cal_info->rpt_end = mktime(12,0,0,$cal_info->rpt_month,$cal_info->rpt_day,$cal_info->rpt_year) - ((60 * 60) * $phpgw_info["user"]["preferences"]["common"]["tz_offset"]); - $cal_info = $phpgw->common->appsession($cal_info); + $phpgw->common->appsession('entry','calendar',$cal_info); $datetime_check = validate($cal_info); if ($phpgw_info["user"]["preferences"]["common"]["timeformat"] == "12") { if ($cal_info->hour >= 12) { @@ -97,7 +97,7 @@ $cal_info->edatetime += ((60 * 60) * $phpgw_info["user"]["preferences"]["common"]["tz_offset"]); $overlapping_events = $phpgw->calendar->overlap($cal_info->datetime,$cal_info->edatetime,$cal_info->participants,$cal_info->groups,$cal_info->owner,$cal_info->id); } else { - $cal_info = $phpgw->common->appsession(); + $cal_info = $phpgw->common->appsession('entry','calendar'); } if($datetime_check) { diff --git a/calendar/inc/class.calendar.inc.php b/calendar/inc/class.calendar.inc.php index 6800d64dd2..73f80373f8 100755 --- a/calendar/inc/class.calendar.inc.php +++ b/calendar/inc/class.calendar.inc.php @@ -1574,7 +1574,7 @@ $calendar->description = htmlspecialchars(stripslashes($db2->f("cal_description"))); if($db2->f("cal_group")) { $groups = explode(',',$db2->f("cal_group")); - for($j=1;$jgroups[] = $groups[$j]; } } diff --git a/calendar/month.php b/calendar/month.php index a9e2a16872..a72290c92d 100755 --- a/calendar/month.php +++ b/calendar/month.php @@ -61,36 +61,38 @@ $view = "month"; - $phpgw->template->set_file(array("index_t" => "index.tpl")); + $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); - $phpgw->template->set_block("index_t","index"); + $p->set_file(array("index_t" => "index.tpl")); + + $p->set_block("index_t","index"); if ($friendly) { - $phpgw->template->set_var("printer_friendly",""); + $p->set_var("printer_friendly",""); } else { - $phpgw->template->set_var("printer_friendly",""); + $p->set_var("printer_friendly",""); } - $phpgw->template->set_var("bg_text",$phpgw_info["theme"]["bg_text"]); + $p->set_var("bg_text",$phpgw_info["theme"]["bg_text"]); - $phpgw->template->set_var("small_calendar_prev",$phpgw->calendar->mini_calendar(1,$prev["month"],$prev["year"],"day.php")); + $p->set_var("small_calendar_prev",$phpgw->calendar->mini_calendar(1,$prev["month"],$prev["year"],"day.php")); $m = mktime(2,0,0,$thismonth,1,$thisyear); - $phpgw->template->set_var("month_identifier",lang(strftime("%B",$m)) . " " . $thisyear); - $phpgw->template->set_var("username",$phpgw->common->grab_owner_name($owner)); - $phpgw->template->set_var("small_calendar_next",$phpgw->calendar->mini_calendar(1,$next["month"],$next["year"],"day.php")); + $p->set_var("month_identifier",lang(strftime("%B",$m)) . " " . $thisyear); + $p->set_var("username",$phpgw->common->grab_owner_name($owner)); + $p->set_var("small_calendar_next",$phpgw->calendar->mini_calendar(1,$next["month"],$next["year"],"day.php")); flush(); - $phpgw->template->set_var("large_month",$phpgw->calendar->display_large_month($thismonth,$thisyear,True,$owner)); + $p->set_var("large_month",$phpgw->calendar->display_large_month($thismonth,$thisyear,True,$owner)); if (!$friendly) { $param = 'year='.$thisyear.'&month='.$thismonth.'&friendly=1&filter='.$filter; - $phpgw->template->set_var("print","link("",$param)."\" TARGET=\"cal_printer_friendly\" onMouseOver=\"window." + $p->set_var("print","link("",$param)."\" TARGET=\"cal_printer_friendly\" onMouseOver=\"window." . "status = '" . lang("Generate printer-friendly version"). "'\">[". lang("Printer Friendly") . "]"); - $phpgw->template->parse("out","index_t"); - $phpgw->template->pparse("out","index_t"); + $p->parse("out","index_t"); + $p->pparse("out","index_t"); } else { - $phpgw->template->set_var("print",""); - $phpgw->template->parse("out","index_t"); - $phpgw->template->pparse("out","index_t"); + $p->set_var("print",""); + $p->parse("out","index_t"); + $p->pparse("out","index_t"); } $phpgw->common->phpgw_footer(); ?> diff --git a/calendar/view.php b/calendar/view.php index e6899adb4d..7bbe3435ce 100755 --- a/calendar/view.php +++ b/calendar/view.php @@ -16,7 +16,7 @@ $phpgw_info["flags"] = array("currentapp" => "calendar", "enable_nextmatchs_class" => True); include("../header.inc.php"); - +$debugme = "on"; if ($id < 1) { echo lang("Invalid entry id."); $phpgw->common->phpgw_exit(); @@ -106,9 +106,9 @@ $cal_grps = ""; for($i=0;$igroups);$i++) { if($i>0) $cal_grps .= "
"; - $db->query("SELECT group_name FROM groups WHERE group_id=".$cal_info->groups[$i],__LINE__,__FILE__); + $db->query("SELECT account_lid FROM phpgw_accounts WHERE account_id=".$cal_info->groups[$i],__LINE__,__FILE__); $db->next_record(); - $cal_grps .= $db->f("group_name"); + $cal_grps .= $db->f("account_lid"); } display_item(lang("Groups"),$cal_grps); } diff --git a/calendar/week.php b/calendar/week.php index 0d941ff2cb..9887e2fd49 100755 --- a/calendar/week.php +++ b/calendar/week.php @@ -52,19 +52,51 @@ } if(!isset($owner)) { $owner = 0; } - unset($owner); if(!isset($owner) || !$owner) { - $id = $phpgw_info["user"]["userid"]; - $fn = $phpgw_info["user"]["firstname"]; - $ln = $phpgw_info["user"]["lastname"]; - $owner = 0; + $owner = $phpgw_info['user']['account_id']; } else { - $phpgw->db->query("SELECT account_lid,account_firstname,account_lastname FROM accounts WHERE account_id=$owner"); - $phpgw->db->next_record(); - $id = $phpgw->db->f("account_lid"); - $fn = $phpgw->db->f("account_firstname"); - $ln = $phpgw->db->f("account_lastname"); + $grants = $phpgw->acl->get_location_list_for_id('calendar',PHPGW_ACL_READ,$owner); + $memberships = $phpgw->accounts->memberships($phpgw_info['user']['account_id']); + while($grants && $granted = each($grants)){ + if($granted[1] == 'u_'.$phpgw_info['user']['account_id']){ + $can_read = True; + break; + }else{ + reset($memberships); + while($group = each($memberships)) { + if($granted[1] == 'g_'.$group[1]['account_id']){ + $can_read = True; + break 2; + } + } + } + } +// if(!$can_read){ +// $my_groups = $phpgw->accounts->memberships($phpgw_info['user']['account_id']); +// $their_groups = $phpgw->accounts->memberships($owner); +// for($j=0;$j\n"; +// if($can_read){ break; } +// for($k=0;$k\n"; +// if($can_read){ break 2; } +// if($my_groups[$j] == $their_groups[$k]){ +//echo 'Match Group ('.$my_groups[$j]['account_name'].') '.$my_groups[$j]['account_id']."
\n"; +// $users = $phpgw->acl->get_ids_for_location('g_'.$my_groups[$j]['account_id'],PHPGW_ACL_READ,'calendar'); +// for($l=0;$lcalendar->splitdate(mktime(2,0,0,$thismonth,$thisday + 7,$thisyear)); @@ -80,25 +112,27 @@ } $first = $phpgw->calendar->splitdate($phpgw->calendar->get_weekday_start($thisyear, $thismonth, $thisday) + $start); $last = $phpgw->calendar->splitdate($first["raw"] + 518400); - $phpgw->template->set_file(array("week_t" => "week.tpl")); - $phpgw->template->set_block("week_t","week"); + $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); + $p->set_file(array("week_t" => "week.tpl")); + + $p->set_block("week_t","week"); if ($friendly) { - $phpgw->template->set_var("printer_friendly",""); + $p->set_var("printer_friendly",""); } else { - $phpgw->template->set_var("printer_friendly",""); + $p->set_var("printer_friendly",""); } - $phpgw->template->set_var("bg_text",$phpgw_info["theme"]["bg_text"]); + $p->set_var("bg_text",$phpgw_info["theme"]["bg_text"]); - $phpgw->template->set_var("small_calendar_prev",$phpgw->calendar->mini_calendar($thisday,$prevmonth["month"],$prevmonth["year"],"day.php")); + $p->set_var("small_calendar_prev",$phpgw->calendar->mini_calendar($thisday,$prevmonth["month"],$prevmonth["year"],"day.php")); if (!$friendly) { - $phpgw->template->set_var("prev_week_link","link("week.php","year=".$prev["year"]."&month=".$prev["month"]."&day=".$prev["day"])."\"><<"); + $p->set_var("prev_week_link","link("week.php","year=".$prev["year"]."&month=".$prev["month"]."&day=".$prev["day"])."\"><<"); } else { - $phpgw->template->set_var("prev_week_link","<<"); + $p->set_var("prev_week_link","<<"); } - $phpgw->template->set_var("small_calendar_this",$phpgw->calendar->mini_calendar($thisday,$thismonth,$thisyear,"day.php")); + $p->set_var("small_calendar_this",$phpgw->calendar->mini_calendar($thisday,$thismonth,$thisyear,"day.php")); $week_id = lang(strftime("%B",$first["raw"]))." ".$first["day"]; if($first["month"] <> $last["month"] && $first["year"] <> $last["year"]) $week_id .= ", ".$first["year"]; @@ -106,27 +140,27 @@ if($first["month"] <> $last["month"]) $week_id .= lang(strftime("%B",$last["raw"]))." "; $week_id .= $last["day"].", ".$last["year"]; - $phpgw->template->set_var("week_identifier",$week_id); - $phpgw->template->set_var("username",$phpgw->common->display_fullname($id,$fn,$ln)); + $p->set_var("week_identifier",$week_id); + $p->set_var("username",$phpgw->common->grab_owner_name($owner)); if (!$friendly) { - $phpgw->template->set_var("next_week_link","link("week.php","year=".$next["year"]."&month=".$next["month"]."&day=".$next["day"])."\">>>"); + $p->set_var("next_week_link","link("week.php","year=".$next["year"]."&month=".$next["month"]."&day=".$next["day"])."\">>>"); } else { - $phpgw->template->set_var("next_week_link",">>"); + $p->set_var("next_week_link",">>"); } - $phpgw->template->set_var("small_calendar_next",$phpgw->calendar->mini_calendar($thisday,$nextmonth["month"],$nextmonth["year"],"day.php")); - $phpgw->template->set_var("week_display",$phpgw->calendar->display_large_week($thisday,$thismonth,$thisyear,true,$owner)); + $p->set_var("small_calendar_next",$phpgw->calendar->mini_calendar($thisday,$nextmonth["month"],$nextmonth["year"],"day.php")); + $p->set_var("week_display",$phpgw->calendar->display_large_week($thisday,$thismonth,$thisyear,true,$owner)); if (!$friendly) { $param = 'year='.$thisyear.'&month='.$thismonth.'&friendly=1&filter='.$filter; - $phpgw->template->set_var("print","link("",$param)."\" TARGET=\"cal_printer_friendly\" onMouseOver=\"window." + $p->set_var("print","link("",$param)."\" TARGET=\"cal_printer_friendly\" onMouseOver=\"window." . "status = '" . lang("Generate printer-friendly version"). "'\">[". lang("Printer Friendly") . "]"); - $phpgw->template->parse("out","week_t"); - $phpgw->template->pparse("out","week_t"); + $p->parse("out","week_t"); + $p->pparse("out","week_t"); } else { - $phpgw->template->set_var("print",""); - $phpgw->template->parse("out","week_t"); - $phpgw->template->pparse("out","week_t"); + $p->set_var("print",""); + $p->parse("out","week_t"); + $p->pparse("out","week_t"); } $phpgw->common->phpgw_footer(); ?>