[632] | 1 | <?php |
---|
| 2 | define('PHPGW_API_INC','../../phpgwapi/inc'); |
---|
| 3 | include_once(PHPGW_API_INC.'/class.db.inc.php'); |
---|
| 4 | |
---|
| 5 | class bocalendar |
---|
| 6 | { |
---|
| 7 | var $db; |
---|
| 8 | function bocalendar() |
---|
| 9 | { |
---|
| 10 | $this->db = new db(); |
---|
| 11 | $this->db->Halt_On_Error = 'no'; |
---|
| 12 | $this->db->connect( |
---|
| 13 | $_SESSION['calendar']['server']['db_name'], |
---|
| 14 | $_SESSION['calendar']['server']['db_host'], |
---|
| 15 | $_SESSION['calendar']['server']['db_port'], |
---|
| 16 | $_SESSION['calendar']['server']['db_user'], |
---|
| 17 | $_SESSION['calendar']['server']['db_pass'], |
---|
| 18 | $_SESSION['calendar']['server']['db_type'] |
---|
| 19 | ); |
---|
[696] | 20 | $this -> user_id = $_SESSION['calendar']['user']['account_id']; |
---|
| 21 | $this -> cat_id = 0; |
---|
[632] | 22 | } |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | var $public_functions = array( |
---|
| 26 | 'requestTodayCal' => True |
---|
| 27 | ); |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | // Return the events of current Day |
---|
| 31 | function requestDayCal ($dayTime) { |
---|
| 32 | $day = getdate($dayTime); |
---|
[696] | 33 | $query = ("SELECT * FROM phpgw_cal where ".($this->cat_id>0?"(category=".$this->cat_id.") and":"")."(owner = '".$this->user_id."') and ((datetime > ".mktime(0,0,0,$day['mon'],$day['mday'],$day['year'])." and datetime < ".(mktime(0,0,0,$day['mon'],($day['mday']+1),$day['year'])).") or (edatetime > ".mktime(0,0,0,$day['mon'],$day['mday'],$day['year'])." and edatetime < ".(mktime(0,0,0,$day['mon'],$day['mday']+1,$day['year']))."))"); |
---|
[632] | 34 | if (!$this->db->query($query)) |
---|
| 35 | return false; |
---|
| 36 | |
---|
| 37 | while($this->db->next_record()) |
---|
| 38 | $result[] = $this->db->row(); |
---|
| 39 | return $result; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | function changeEvent ($calId,$field,$value) { |
---|
| 43 | $query = ("UPDATE phpgw_cal SET ".$field."=".$value." WHERE cal_id = ".$calId.";"); |
---|
| 44 | |
---|
| 45 | if (!$this->db->query($query)) |
---|
| 46 | return "<false>DB out of service or internal error</false>"; |
---|
| 47 | |
---|
| 48 | return "<true ></true >"; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | // Return the events of current Day |
---|
| 52 | function requestWeekCal ($dayTime) { |
---|
| 53 | // Performing SQL query |
---|
[696] | 54 | $query = "SELECT cal_id, title, description, datetime, edatetime FROM phpgw_cal where ".($this->cat_id>0?"(category=".$this->cat_id.") and":"")." (owner = '".$this->user_id."') and ((datetime > ".$dayTime." and datetime < ".($dayTime+604800).") or (edatetime > ".$dayTime." and edatetime < ".($dayTime+604800)."))"; |
---|
[632] | 55 | if (!$this->db->query($query)) |
---|
| 56 | return false; |
---|
| 57 | |
---|
| 58 | while($this->db->next_record()) |
---|
| 59 | $result[] = $this->db->row(); |
---|
| 60 | |
---|
| 61 | return $result; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | function requestDetailsEvent($id) { |
---|
| 65 | // Performing SQL query |
---|
| 66 | $query = "SELECT title, description, datetime, edatetime, groups, location FROM phpgw_cal where (owner = '".$this->user_id."') and (cal_id = ".$id.")"; |
---|
| 67 | if (!$this->db->query($query)) |
---|
| 68 | return false; |
---|
| 69 | |
---|
| 70 | while($this->db->next_record()) |
---|
| 71 | $result[] = $this->db->row(); |
---|
| 72 | |
---|
| 73 | return $result; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | // Return the events of current month |
---|
| 77 | function requestMonthCal ($dayTime) { |
---|
| 78 | // Performing SQL query |
---|
| 79 | $day = getdate($dayTime); |
---|
[920] | 80 | $query = "SELECT cal_id, title, description, datetime, edatetime FROM phpgw_cal where ".($this->cat_id>0?"(category=".$this->cat_id.") and":"")." (owner = '".$this->user_id."') and ((datetime > ".mktime(0,0,0,$day['mon'],$day['mday'],$day['year'])." and datetime < ".mktime(0,0,0,$day['mon']+1,$day['mday'],$day['year']).") or (edatetime > ".mktime(0,0,0,$day['mon'],$day['mday'],$day['year'])." and edatetime < ".mktime(0,0,0,$day['month']+1,$day['day'],$day['year']).")) order by datetime"; |
---|
[632] | 81 | if (!$this->db->query($query)) |
---|
| 82 | return false; |
---|
| 83 | |
---|
| 84 | while($this->db->next_record()) |
---|
| 85 | $result[] = $this->db->row(); |
---|
| 86 | |
---|
| 87 | return $result; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | // Return the events of current Year |
---|
| 91 | function requestYearCal ($dayTime) { |
---|
| 92 | // Performing SQL query |
---|
[696] | 93 | $query = "SELECT cal_id, title, description, datetime, edatetime FROM phpgw_cal where ".($this->cat_id>0?"(category=".$this->cat_id.") and":"")." (owner = '".$this->user_id."') and ((datetime > ".$dayTime." and datetime < ".($dayTime+31104000).") or (edatetime > ".$dayTime." and edatetime < ".($dayTime+2592000)."))"; |
---|
[632] | 94 | if (!$this->db->query($query)) |
---|
| 95 | return false; |
---|
| 96 | |
---|
| 97 | while($this->db->next_record()) |
---|
| 98 | $result[] = $this->db->row(); |
---|
| 99 | |
---|
| 100 | return $result; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | function insertEvent ($datetime, $edatetime, $title, $description, $location) |
---|
| 104 | { |
---|
| 105 | //Discover the event id |
---|
| 106 | $query = "SELECT max(cal_id) FROM phpgw_cal"; |
---|
| 107 | if (!$this->db->query($query)) |
---|
| 108 | return false; |
---|
| 109 | |
---|
| 110 | while($this->db->next_record()) |
---|
| 111 | $id = $this->db->row(); |
---|
| 112 | |
---|
| 113 | // Performing SQL insert query |
---|
| 114 | $query = "INSERT INTO phpgw_cal VALUES (".($id['max']+1).", '".$_SESSION['calendar']['user']['email']."', ".$this->user_id.", null, null, ".$datetime.", ".time().",".$edatetime.", 2, 'E', 0, '".$title."', '".$description."', '".$location."', 0, null)"; |
---|
| 115 | if ($this->db->query($query)){ |
---|
| 116 | $query = "INSERT INTO phpgw_cal_user VALUES (".($id['max']+1).", ".$this->user_id.", 'A', 'u')"; |
---|
| 117 | if ($this->db->query($query)){ |
---|
| 118 | $return = "true "; |
---|
| 119 | $return .= ";".($id['max']+1); |
---|
| 120 | } else { |
---|
| 121 | $return = "false"; |
---|
| 122 | $return .= ";Query failed: " . pg_last_error(); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | } |
---|
| 126 | else{ |
---|
| 127 | $return = "false"; |
---|
| 128 | $return .= ";Query failed: " . pg_last_error(); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | return $return; |
---|
| 132 | |
---|
| 133 | } |
---|
| 134 | function removeEventById($id){ |
---|
| 135 | $query = "DELETE from phpgw_cal where cal_id = ".$id; |
---|
| 136 | |
---|
| 137 | if ($this->db->query($query)){ |
---|
| 138 | $query = "DELETE from phpgw_cal_user where cal_id = ".$id; |
---|
| 139 | if ($this->db->query($query)) |
---|
| 140 | $return = "true "; |
---|
| 141 | else |
---|
| 142 | { |
---|
| 143 | $return = "false"; |
---|
| 144 | $return .= ";Query failed: " . pg_last_error(); |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | else{ |
---|
| 148 | $return = "false"; |
---|
| 149 | $return .= ";Query failed: " . pg_last_error(); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | return $return; |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | ?> |
---|