source: sandbox/calendar/ajax_calendar/expressoCalendar/inc/hourReport.php @ 632

Revision 632, 6.1 KB checked in by niltonneto, 12 years ago (diff)

Modulo calendar_new renomeado para expressoCalendar

Line 
1<?php
2$phpgw_flags = Array(
3        'currentapp'    =>      'calendar',
4        'noappheader'   =>      True,
5        'noappfooter'   =>      True,
6        'nofooter'      =>      True
7);
8$GLOBALS['phpgw_info']['flags'] = $phpgw_flags;
9
10include('../../header.inc.php');
11$_SESSION['calendar']['user'] = $GLOBALS['phpgw_info']['user'];
12$_SESSION['calendar']['server'] = $GLOBALS['phpgw_info']['server'];
13define('PHPGW_API_INC','../../phpgwapi/inc');
14include_once(PHPGW_API_INC.'/class.db.inc.php');
15$page_content = <<<PAGE
16<HTML><HEAD></HEAD><BODY>
17<SCRIPT type="text/javascript">
18var Total = 0;
19        function show_table(){
20                var MainDiv = document.getElementById('MainDiv');
21                var showTable = document.createElement('TABLE');
22                var trLine = document.createElement('TR');
23                var tdVal = document.createElement('TD');
24                tdVal.innerHTML = "Titulo";
25                trLine.appendChild(tdVal);
26                tdVal = document.createElement('TD');
27                tdVal.innerHTML = "Descricao";
28                trLine.appendChild(tdVal);
29                tdVal = document.createElement('TD');
30                tdVal.innerHTML = "Horas";
31                trLine.appendChild(tdVal);
32                trLine.style.background = "#DDD";
33                showTable.appendChild(trLine);
34
35                var Eelement = MainDiv.firstChild;
36                while (Eelement){
37                        trLine = document.createElement('TR');
38                        tdVal = document.createElement('TD');
39                        tdVal.innerHTML = Eelement.childNodes[0].innerHTML;
40                        trLine.appendChild(tdVal);
41                        tdVal = document.createElement('TD');
42                        tdVal.innerHTML = Eelement.childNodes[1].innerHTML;
43                        trLine.appendChild(tdVal);
44                        tdVal = document.createElement('TD');
45                        Total += (Eelement.childNodes[3].innerHTML-Eelement.childNodes[2].innerHTML)/3600;
46                        tdVal.innerHTML = ((Eelement.childNodes[3].innerHTML-Eelement.childNodes[2].innerHTML)/3600).toFixed(1);
47                        trLine.appendChild(tdVal);
48                        showTable.appendChild(trLine);
49                        Eelement = Eelement.nextSibling;
50
51                }
52                trLine = document.createElement('TR');
53                tdVal = document.createElement('TD');
54                tdDes =  document.createElement('TD');
55                tdDes.innerHTML = "Total";
56                tdDes.align = "left";
57                tdVal.innerHTML = Total.toFixed(1);
58                trLine.style.background = "#FFF";
59                trLine.appendChild(tdDes);
60                trLine.appendChild(document.createElement('TD'));
61                trLine.appendChild(tdVal);
62                showTable.appendChild(trLine);
63                showTable.className = "calendar_print_main";
64                MainDiv.parentNode.appendChild(showTable);
65        }
66</SCRIPT>
67PAGE;
68echo $page_content;
69$db = new db();
70$db->Halt_On_Error = 'no';
71$db->connect(
72        $_SESSION['calendar']['server']['db_name'],
73        $_SESSION['calendar']['server']['db_host'],
74        $_SESSION['calendar']['server']['db_port'],
75        $_SESSION['calendar']['server']['db_user'],
76        $_SESSION['calendar']['server']['db_pass'],
77        $_SESSION['calendar']['server']['db_type']
78);
79$user_id = $_SESSION['calendar']['user']['account_id'];
80
81function ldapName($uid){
82        $connection = $GLOBALS['phpgw']->common->ldapConnect();
83        $justthese = array("cn");
84        $search = ldap_search($connection, $GLOBALS['phpgw_info']['server']['ldap_context'], "uidNumber=" . $uid, $justthese);
85        $result = ldap_get_entries($connection, $search);
86        ldap_close($connection);
87        return $result[0]['cn'][0];
88}
89
90
91if (IsSet($_POST['CAT'])){
92        if (!preg_match("/[a-zA-Z0-9]+/i",$_POST['CAT'][0])){
93                echo "Invalid entry:".$_POST['CAT'][0];
94                return false;
95        }
96        if (strlen($_POST['DAT']) > 0 && !preg_match("/[0123][0-9].[01][0-9].[12][90][0-9][0-9]$/i",$_POST['DAT'])){
97                echo "Invalid entry:".$_POST['DAT'];
98                return false;
99        }
100
101        if (IsSet($_POST['DAT']))
102                $initDate = mktime(null,null,null,substr($_POST['DAT'],3,2),substr($_POST['DAT'],0,2),substr($_POST['DAT'],6,4));
103        if ($_POST['CAL'][0] != 'run')
104                $user_id = $_POST['CAL'][0];
105        foreach($_POST['CAT'] as $catid)
106                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:""))){
107                        print("Query failed");
108                        return;
109                }
110                else
111                        while($db->next_record())
112                                $result_[] = $db->row();
113
114        echo "<div id='MainDiv' style='display: none;'>";
115        foreach($result_ as $ind => $entry){
116                echo "<div id=\"entry_".$ind."\"><div id=\"title_".$ind."\">".$entry['title']."</div><div id=\"description_".$ind."\">".$entry['description']."</div><div id=\"datetime_".$ind."\">".$entry['datetime']."</div><div id=\"edatetime_".$ind."\">".$entry['edatetime']."</div></div>";
117        }
118        echo "</div><script type=\"text/javascript\"> show_table();</script>";
119        return;
120}
121
122$cat_query="select cat_id,cat_name from phpgw_categories where cat_appname = 'calendar' and (cat_owner = ".$user_id;
123foreach($GLOBALS['phpgw']->accounts->membership() as $idx => $group){
124        $cat_query = $cat_query.' or cat_owner = '.$group['account_name'];
125}
126$cat_query = $cat_query.')';
127if (!$db->query($cat_query))
128        print("Query failed");
129else
130        while($db->next_record())
131                $categories[] = $db->row();
132
133if (!$db->query("select acl_account from phpgw_acl where acl_appname  = 'calendar' and acl_location = ".$user_id))
134        print("Query failed");
135else
136        while($db->next_record())
137                $userCals[] = $db->row();
138
139
140$self = $_SERVER['PHP_SELF'];
141print("<table><tbody><tr><td>");
142print("<form id=\"form1\" method=\"post\" action=\"$self\">");
143print("Categoria(s):<br></td><td>");
144print("<select name=\"CAT[]\" multiple>");
145foreach($categories as $entry)
146        print("<option value=\"".$entry['cat_id']."\">".$entry['cat_name']."</option>");
147print("</select></td></tr><tr><td>");
148print("Incluir ocorr&ecirc;ncias do tipo normal:</td><td><input name=\"NORM\" type=\"checkbox\"></input><br></td></tr>");
149print("<tr><td>Usuario:</td><td><select name=\"CAL[]\" multiple>");
150print("<option value=\"".$user_id."\">Minha agenda</option>");
151foreach($userCals as $ind => $entry)
152        print("<option value=\"".$entry['acl_account']."\">".ldapName($entry['acl_account'])."</option>");
153print("</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>");
154print("</td></tr></tbody></table><br><input value=\"Fazer consulta\" type=\"submit\"><br></form>");
155print("</BODY></HTML>");
156?>
Note: See TracBrowser for help on using the repository browser.