Index: trunk/calendar/inc/hourReport.php
===================================================================
--- trunk/calendar/inc/hourReport.php	(revision 581)
+++ trunk/calendar/inc/hourReport.php	(revision 602)
@@ -81,15 +81,4 @@
 	$_SESSION['calendar']['server']['db_type']
 );
-$user_id = $_SESSION['calendar']['user']['account_id'];
-
-function ldapName($uid){
-	$connection = $GLOBALS['phpgw']->common->ldapConnect();
-	$justthese = array("cn");
-	$search = ldap_search($connection, $GLOBALS['phpgw_info']['server']['ldap_context'], "uidNumber=" . $uid, $justthese);
-	$result = ldap_get_entries($connection, $search);
-	ldap_close($connection);
-	return $result[0]['cn'][0];
-}
-
 
 if (IsSet($_POST['CAT'])){
@@ -107,13 +96,34 @@
 	if ($_POST['CAL'][0] != 'run')
 		$user_id = $_POST['CAL'][0];
+
+	foreach ($_POST['CAL'] as $cal_uid){
+		$found = false;	
+		foreach($_SESSION['calendar']['cals'] as $grant)
+			if ($cal_uid == $grant['value'])
+				$found = true;
+			if (!$found){
+				echo "Permission denied, cal. id:".$cal_uid."<br>";
+				return;
+			}
+		}
+
+
 	foreach($_POST['CAT'] as $catid)
 		if(!$db->query("select cal_id,title,description,datetime,edatetime from phpgw_cal where ".(!$_POST['NORM']?"cal_type = 'H' and":" is_public = 1 and ")." owner = ".$user_id." and (category like '%,".$catid.",%' or category like '%,".$catid."' or category like '".$catid.",%' or category = '".$catid."')".(IsSet($initDate)?" and datetime > ".$initDate:""))){
-			print("Query failed");
+			print("<br>Query failed at host:<br>".$_SESSION['calendar']['server']['db_user']."@".$_SESSION['calendar']['server']['db_host'].":".$_SESSION['calendar']['server']['db_port']."<br>");
 			return;
 		}
-		else
-			while($db->next_record())
-				$result_[] = $db->row();
-
+		else{
+			while($db->next_record()){
+				$entry = $db->row();
+				$repeated = false;
+				foreach($result_ as $value){
+					if ($value['cal_id'] == $entry['cal_id'])
+						$repeated = true;
+				}
+				if(!$repeated)
+					$result_[] = $entry;
+			}
+		}
 	echo "<div id='MainDiv' style='display: none;'>";
 	foreach($result_ as $ind => $entry){
@@ -124,22 +134,4 @@
 }
 
-$cat_query="select cat_id,cat_name from phpgw_categories where cat_appname = 'calendar' and (cat_owner = ".$user_id;
-foreach($GLOBALS['phpgw']->accounts->membership() as $idx => $group){
-	$cat_query = $cat_query.' or cat_owner = '.$group['account_name'];
-}
-$cat_query = $cat_query.')';
-if (!$db->query($cat_query))
-	print("Query failed");
-else
-	while($db->next_record())
-		$categories[] = $db->row();
-
-if (!$db->query("select acl_account from phpgw_acl where acl_appname  = 'calendar' and acl_location = ".$user_id))
-	print("Query failed");
-else
-	while($db->next_record())
-		$userCals[] = $db->row();
-
-
 $self = $_SERVER['PHP_SELF'];
 print("<table><tbody><tr><td>");
@@ -147,12 +139,10 @@
 print("Categoria(s):<br></td><td>");
 print("<select name=\"CAT[]\" multiple>");
-foreach($categories as $entry)
-	print("<option value=\"".$entry['cat_id']."\">".$entry['cat_name']."</option>");
+print($_SESSION['calendar']['categories']);
 print("</select></td></tr><tr><td>");
 print("Incluir ocorr&ecirc;ncias do tipo normal:</td><td><input name=\"NORM\" type=\"checkbox\"></input><br></td></tr>");
 print("<tr><td>Usuario:</td><td><select name=\"CAL[]\" multiple>");
-print("<option value=\"".$user_id."\">Minha agenda</option>");
-foreach($userCals as $ind => $entry)
-	print("<option value=\"".$entry['acl_account']."\">".ldapName($entry['acl_account'])."</option>");
+foreach($_SESSION['calendar']['cals'] as $grant)
+	print(!strstr($grant['value'],'g_')?'<option value="'.$grant['value'].'">'.$grant['name'].'</option>':"");
 print("</td></tr><tr><td>Apartir da data: dd/mm/aaaa<br>(caso todas deixar em branco):</td><td><input name=\"DAT\" type=\"text\"></input></td></tr>");
 print("</td></tr></tbody></table><br><input value=\"Fazer consulta\" type=\"submit\"><br></form>");
Index: trunk/calendar/inc/class.uicalendar.inc.php
===================================================================
--- trunk/calendar/inc/class.uicalendar.inc.php	(revision 583)
+++ trunk/calendar/inc/class.uicalendar.inc.php	(revision 602)
@@ -358,5 +358,8 @@
 		function printer_friendly($body,$app_header='')
 		{	
-			
+			$_SESSION['calendar']['categories'] = $this->cat->formated_list('select','all',$this->bo->cat_id,'True');
+			if((!isset($GLOBALS['phpgw_info']['server']['deny_user_grants_access']) || !$GLOBALS['phpgw_info']['server']['deny_user_grants_access']) && count($this->bo->grants) > 0)
+				$_SESSION['calendar']['cals'] = $this->bo->list_cals();
+
 			if($this->bo->printer_friendly)
 			{	
@@ -4859,4 +4862,5 @@
 			}
 			$p->set_var('delete_button',$delete_button);
+			$p->set_var('alert_msg',lang('Required field (category) is empty'));
 
 			if ($this->bo->return_to)
