phpBMS

root/trunk/phpbms/modules/base/ical.php

Revision 308, 5.5 KB (checked in by brieb, 5 years ago)

Implements #180 - ical format for event list.
Fixes #181 - repeating notes/task/events completely rewritten. All repeatable items will need to be recreated.
Fixes #182 - Cross platform menu problems
Reformatted CSS to be compliant
Re formatted list screen columns and groupings. 0.9 Will completely reenter these. Any administrtive changes will need to be reimplemented.
Implemented mochikit like javascript. This will be an ongoing conversion to make the system more stable and standards compliant.
Fixed minor bugs in recurring invoices.
Recoded help screen.

Line 
1<?php
2class ical {
3
4        var $db;
5        var $userinfo = array();
6        var $vEvents = array();
7
8        function ical($db,$userid){
9                $this->db = $db;
10               
11                $this->_getUserInfo($userid);
12               
13        }
14
15        function verifyUser($hash){
16                return (md5("phpBMS".$this->userinfo["firstname"].$this->userinfo["lastname"].$this->userinfo["id"].$this->userinfo["decpass"]) == $hash);
17        }
18       
19        function _toCalDate($sqldate){
20                $phpDate = stringToDate($sqldate,"SQL");
21                return date("Ymd",$phpDate);
22        }
23       
24        function _toCalTime($sqltime){
25                $phpTime = stringToTime($sqltime,"24 Hour");
26                return date("His",$phpTime);
27        }
28
29        function _getUserInfo($userid){
30       
31                $querystatement = "SELECT id,firstname,lastname, DECODE(password,'".ENCRYPTION_SEED."') as decpass FROM users WHERE id=".((int) $userid);
32                $queryresult = $this->db->query($querystatement);
33
34                $this->userinfo = $this->db->fetchArray($queryresult);
35       
36        }//end method
37       
38       
39        function _sendHeaders(){
40                header( 'Content-Type: text/calendar; charset=utf-8' );
41                header("Content-Disposition: inline; filename=phpBMScalendar.ics");                     
42        }
43       
44        function _startCal(){
45?>BEGIN:VCALENDAR
46VERSION:2.0
47PRODID:-//phpBMS v0.81//EN
48X-WR-CALNAME:<?php echo APPLICATION_NAME; ?> For user <?php echo $this->userinfo["firstname"]." ".$this->userinfo["lastname"]."\n"?>
49CALSCALE:GREGORIAN
50METHOD:PUBLISH
51<?php
52        }
53       
54       
55        function addEvents($startdate,$enddate = NULL){
56                $querystatement = "SELECT id, subject, content, startdate, starttime, enddate, endtime,
57                                                        DATE_FORMAT(creationdate,'%Y%m%dT%H%i%sZ') AS creationdate, location,
58                                                        DATE_FORMAT(modifieddate,'%Y%m%dT%H%i%sZ') AS modifieddate,
59                                                        repeating, repeatevery, repeattype, repeateachlist, repeatontheday, repeatontheweek, repeattimes,
60                                                        repeatuntil
61                                                        FROM notes
62                                                        WHERE (notes.private = 0 OR notes.createdby=".$this->userinfo["id"].") AND notes.type='EV' AND
63                                                        (startdate <= '".datetoString($startdate,"SQL")."'";
64                if($enddate)
65                        $querystatement .= " AND enddate >= '".datetoString($startdate,"SQL")."'";
66               
67                $querystatement .= " OR repeating = 1)";
68
69                $queryresult = $this->db->query($querystatement);
70
71                while($therecord = $this->db->fetchArray($queryresult))
72                        $this->vEvents[] = $therecord;
73
74        }//end method
75       
76       
77        function  _showEvents(){
78                foreach($this->vEvents as $event){
79?>BEGIN:VEVENT
80CREATED:<?php echo $event["creationdate"]."\n"?>
81LAST-MODIFIED:<?php echo $event["modifieddate"]."\n"?>
82DTSTAMP:<?php echo $event["creationdate"]."\n"?>
83UID:
84 <?php echo "BB-".$event["id"]."\n"?>
85SUMMARY:<?php echo $event["subject"]."\n"?>
86DTSTART:<?php 
87        echo $this->_toCalDate($event["startdate"]);
88        if($event["starttime"])
89                echo "T".$this->_toCalTime($event["starttime"])."\n";
90        else
91                echo "T000000"."\n";
92 ?>
93DTEND:<?php 
94        echo $this->_toCalDate($event["enddate"]);
95        if($event["starttime"])
96                echo "T".$this->_toCalTime($event["endtime"])."\n";
97        else
98                echo "T000000"."\n";
99               
100        if($event["location"])echo "LOCATION:".$event["location"]."\n";
101        if($event["content"])echo "DESCRIPTION:".str_replace("\n","",$event["content"])."\n";
102       
103        if($event["repeating"]){               
104                $rrule = "RRULE:FREQ=".strtoupper($event["repeattype"]).";INTERVAL=".$event["repeatevery"].";";
105               
106                switch($event["repeattype"]){
107
108                        case "Weekly":
109                                $rrule .= "BYDAY=";
110                                $bydayArray = explode("::",$event["repeateachlist"]);
111                                foreach($bydayArray as $day){
112                                        $tempday = ($day != 7)?($day+1):(1);
113                                        $rrule .= strtoupper(substr(nl_langinfo(constant("ABDAY_".$tempday)), 0 ,2)).", ";
114                                }
115                               
116                                $rrule = substr($rrule,0,(strlen($rrule)-2) ).";";
117                                break;
118                       
119                        case "Monthly":
120                                if($event["repeateachlist"]){
121                                        $rrule .= "BYMONTHDAY=";
122                                        $bydayArray = explode("::",$event["repeateachlist"]);
123                               
124                                        foreach($bydayArray as $day)
125                                                $rrule .=  $day.", ";
126                                                                                       
127                                        $rrule = substr($rrule,0,(strlen($rrule)-2) ).";";
128                                } else {
129                                        if($event["repeatontheweek"] == 5)
130                                                $event["repeatontheweek"] = -1;
131
132                                        $tempday = ($event["repeatontheday"] != 7)?($event["repeatontheday"]+1):(1);
133
134                                        $rrule .= "BYDAY=".$event["repeatontheweek"].strtoupper(substr(nl_langinfo(constant("ABDAY_".$tempday)), 0 ,2)).";";
135                                }//end if
136                                break;
137                       
138                        case "Yearly":
139                                $rrule .= "BYMONTH=";
140                                $bymonthArray = explode("::",$event["repeateachlist"]);
141
142                                foreach($bymonthArray as $month)
143                                        $rrule .=  $month.", ";
144                                       
145                                $rrule = substr($rrule,0,(strlen($rrule)-2) ).";";
146                                if($event["repeatontheday"]){
147                                        if($event["repeatontheweek"] == 5)
148                                                $event["repeatontheweek"] = -1;
149
150                                        $tempday = ($event["repeatontheday"] != 7)?($event["repeatontheday"]+1):(1);
151
152                                        $rrule .= "BYDAY=".$event["repeatontheweek"].strtoupper(substr(nl_langinfo(constant("ABDAY_".$tempday)), 0 ,2)).";";
153                                }//endif
154                                break;
155                               
156                }//endcase
157               
158                if($event["repeattimes"])
159                        $rrule .= "COUNT=".$event["repeattimes"].";";
160                elseif($event["repeatuntil"])
161                        $rrule = "UNTIL=".$this->_toCalDate($event["repeatuntil"])."T000000;";
162               
163                echo substr($rrule,0,strlen($rrule)-1)."\n";           
164        }//endif repeating
165 ?>
166END:VEVENT
167<?php
168                }//endforeach
169        }//end method
170       
171       
172        function showCalendar(){
173                $this->_sendHeaders();
174
175                $this->_startCal();
176               
177                $this->_showEvents();
178               
179                $this->_endCal();
180        }
181       
182       
183        function _endCal(){
184?>END:VCALENDAR
185<?php
186        }//end methdo
187       
188}//end class
189
190//==============================================================================================================
191if (isset($_GET["u"]) && isset($_GET["h"]) && !isset($dontProcess)){
192        $loginNoKick=true;
193        $loginNoDisplayError=true;
194
195        include("../../include/session.php");
196       
197        $theCal = new ical($db,$_GET["u"]);
198       
199        if($theCal->verifyUser($_GET["h"]))
200       
201        $theCal->addEvents(strtotime("-1 month",mktime(0,0,0)));
202       
203        $theCal->showCalendar();
204
205}
206?>
Note: See TracBrowser for help on using the browser.
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.