- Timestamp:
- 08/08/12 15:53:29 (12 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoCalendar/docs/caldav-DELETE.php.diff
r6431 r6962 15 15 + $dav_name = explode('/', $dav_resource->GetProperty('dav_name')); 16 16 + 17 + DAViCalAdapter::delete($dav_resource->GetProperty('caldav_data') ,array('owner' => $dav_resource->GetProperty('username') , 'calendarName' => $dav_name[ (count($dav_name)-3) ] ) .'/'. $dav_name[ (count($dav_name)-2) ]);17 + DAViCalAdapter::delete($dav_resource->GetProperty('caldav_data') ,array('owner' => $dav_resource->GetProperty('username') , 'calendarName' => $dav_name[ (count($dav_name)-3) ] .'/'. $dav_name[ (count($dav_name)-2) ])); 18 18 + } 19 19 +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -
trunk/prototype/modules/calendar/interceptors/DAViCalAdapter.php
r6528 r6962 52 52 { 53 53 if( Config::module('useCaldav' , 'expressoCalendar') ) 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 </D:acl>"; 76 77 78 79 80 54 { 55 $calendar = Controller::read( array( 'concept' => 'calendar' , 'id' => $params['calendar'] )); 56 57 if($params['user'] !== '0') 58 { 59 $user = Controller::read( array( 'concept' => 'user' , 'id' => $params['user'] )); 60 $xmUser = '<D:href>'.Config::service( 'CalDAV' , 'url' ).'/'.$user['uid'].'/</D:href>'; 61 } 62 else 63 $xmUser = '<D:authenticated/>'; 64 65 $xml ="<?xml version=\"1.0\" encoding=\"utf-8\" ?> 66 <D:acl xmlns:D=\"DAV:\"> 67 <D:ace> 68 <D:principal> 69 ".$xmUser." 70 </D:principal> 71 <D:grant> 72 ".self::acltToXML($params['acl'])." 73 </D:grant> 74 </D:ace> 75 </D:acl>"; 76 77 ob_start(); 78 require_once ROOTPATH.'/plugins/davicalCliente/caldav-client-v2.php'; 79 $cal = new CalDAVClient( Config::service( 'CalDAV' , 'url' ).'/'.$calendar['location'].'/', Config::me( 'uid' ), Config::me( 'password' )); 80 $cal->DoXMLRequest('ACL', $xml); 81 81 self::setReadCurrentUserPrivilege(Config::service( 'CalDAV' , 'url' ).'/'.substr($calendar['location'] , 0 , (strpos ( $calendar['location'] , '/' ) + 1 ) )); 82 83 82 ob_end_clean(); 83 } 84 84 } 85 85 … … 87 87 { 88 88 if( Config::module('useCaldav' , 'expressoCalendar') ) 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 89 { 90 $permision = Controller::read( array( 'concept' => 'calendarToPermission' , 'id' => $params['id'] )); 91 $calendar = Controller::read( array( 'concept' => 'calendar' , 'id' => $permision['calendar'] )); 92 93 if($permision['user'] !== '0') 94 { 95 $user = Controller::read( array( 'concept' => 'user' , 'id' => $permision['user'] )); 96 $xmUser = '<D:href>'.Config::service( 'CalDAV' , 'url' ).'/'.$user['uid'].'/</D:href>'; 97 } 98 else 99 $xmUser = '<D:authenticated/>'; 100 101 $xml ="<?xml version=\"1.0\" encoding=\"utf-8\" ?> 102 <D:acl xmlns:D=\"DAV:\"> 103 <D:ace> 104 <D:principal> 105 ".$xmUser." 106 </D:principal> 107 <D:grant> 108 ".self::acltToXML($params['acl'])." 109 </D:grant> 110 </D:ace> 111 </D:acl>"; 112 113 ob_start(); 114 require_once ROOTPATH.'/plugins/davicalCliente/caldav-client-v2.php'; 115 $cal = new CalDAVClient( Config::service( 'CalDAV' , 'url' ).'/'.$calendar['location'].'/', Config::me( 'uid' ), Config::me( 'password' )); 116 116 $cal->DoXMLRequest('ACL', $xml); 117 117 self::setReadCurrentUserPrivilege(Config::service( 'CalDAV' , 'url' ).'/'.substr($calendar['location'] , 0 ,(strpos ( $calendar['location'] , '/' ) + 1 ) )); 118 119 120 118 ob_end_clean(); 119 120 } 121 121 } 122 122 … … 128 128 129 129 $xml ="<?xml version=\"1.0\" encoding=\"utf-8\" ?> 130 131 132 133 134 135 136 137 138 139 130 <D:acl xmlns:D=\"DAV:\"> 131 <D:ace> 132 <D:principal> 133 <D:authenticated /> 134 </D:principal> 135 <D:grant> 136 <D:privilege><D:read-current-user-privilege-set/></D:privilege> 137 </D:grant> 138 </D:ace> 139 </D:acl>"; 140 140 ob_start(); 141 141 require_once ROOTPATH.'/plugins/davicalCliente/caldav-client-v2.php'; … … 147 147 private static function acltToXML($acls) 148 148 { 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 }181 149 $array = array(); 150 $acls = str_split($acls); 151 152 foreach ($acls as &$acl) 153 switch ($acl) 154 { 155 case CALENDAR_ACL_WRITE: 156 $array[] = "<D:privilege><D:bind/></D:privilege>"; 157 $array[] = "<D:privilege><D:write-properties/></D:privilege>"; 158 $array[] = "<D:privilege><D:write-content/></D:privilege>"; 159 $array[] = "<D:privilege><D:unlock/></D:privilege>"; 160 $array[] = "<D:privilege><D:schedule-deliver/></D:privilege>"; 161 $array[] = "<D:privilege><D:schedule-send/></D:privilege>"; 162 break; 163 case CALENDAR_ACL_READ: 164 $array[] = "<D:privilege><D:read /></D:privilege>"; 165 $array[] = "<D:privilege><D:schedule-query-freebusy /></D:privilege>"; 166 $array[] = "<D:privilege><D:read-free-busy /></D:privilege>"; 167 break; 168 case CALENDAR_ACL_REMOVE: 169 $array[] = "<D:privilege><D:unbind/></D:privilege>"; 170 break; 171 case CALENDAR_ACL_SHARED: 172 $array[] = "<D:privilege><D:write-acl/></D:privilege>"; 173 $array[] = "<D:privilege><D:read-acl/></D:privilege>"; 174 $array[] = "<D:privilege><D:read-current-user-privilege-set/></D:privilege>"; 175 break; 176 case CALENDAR_ACL_BUSY: 177 $array[] = "<D:privilege><D:schedule-query-freebusy/></D:privilege>"; 178 $array[] = "<D:privilege><D:read-free-busy/></D:privilege>"; 179 break; 180 } 181 return implode("\n", $array); 182 182 } 183 183 184 184 static function import($data , $params = false) 185 185 { 186 $user = Controller::find(array('concept' => 'user' , 'service' => 'OpenLDAP' ),false,array('filter' => array('=','uid',$params['owner']) ));186 $user = Controller::find(array('concept' => 'user' , 'service' => 'OpenLDAP' ),false,array('filter' => array('=','uid',$params['owner']) , 'notExternal' => true)); 187 187 $params['owner'] = $user[0]['id']; 188 188 … … 214 214 215 215 static function delete($data , $params = false) 216 { 217 $user = Controller::find(array('concept' => 'user' , 'service' => 'OpenLDAP' ),false,array('filter' => array('=','uid',$params['owner']))); 216 { 217 218 $user = Controller::find(array('concept' => 'user' , 'service' => 'OpenLDAP' ),false,array('filter' => array('=','uid',$params['owner']) , 'notExternal' => true)); 219 218 220 $params['owner'] = $user[0]['id']; 219 221 … … 255 257 foreach ($toDelete as $v) 256 258 { 257 $even = Controller::find(array('concept' => 'schedulable') , false , array ( 'filter' => array('AND', array('=' , ' uid' , $v ), array('=' , 'calendar' , $params['calendar']))) );259 $even = Controller::find(array('concept' => 'schedulable') , false , array ( 'filter' => array('AND', array('=' , 'calendar' , $params['calendar']) , array('=' , 'uid' , $v ) ) ) ); 258 260 if(is_array($even) && count($even) > 0 ) 259 261 Controller::delete(array('concept' => 'schedulable' , 'id' => $even[0]['id'])); … … 264 266 static function move($origem , $destino , $owner) 265 267 { 266 $user = Controller::find(array('concept' => 'user' , 'service' => 'OpenLDAP' ),false,array('filter' => array('=','uid',$owner) ));268 $user = Controller::find(array('concept' => 'user' , 'service' => 'OpenLDAP' ),false,array('filter' => array('=','uid',$owner) , 'notExternal' => true)); 267 269 $owner = $user[0]['id']; 268 270 … … 341 343 342 344 static function mkcalendar($location , $name, $description ) 343 { 345 { 344 346 ob_start(); 345 347 require_once ROOTPATH.'/plugins/davicalCliente/caldav-client-v2.php'; -
trunk/prototype/services/PostgreSQL.php
r6528 r6962 52 52 $map = Config::get($uri['concept'], 'PostgreSQL.mapping'); 53 53 54 55 56 57 58 54 $criteria = ($criteria !== false) ? $this->parseCriteria ( $criteria , $map) : ''; 55 56 $justthese = self::parseJustthese($justthese, $map); 57 58 return $this->execSql( 'SELECT '.$justthese['select'].' FROM '. (Config::get($uri['concept'],'PostgreSQL.concept')) .' '.$criteria ); 59 59 } 60 60 … … 63 63 $map = Config::get($uri['concept'], 'PostgreSQL.mapping'); 64 64 $justthese = self::parseJustthese($justthese, $map); 65 $criteria = ($criteria !== false) ? $this->parseCriteria ( $criteria , $map , ' WHERE '.$map['id'].' = \''. addslashes( $uri['id'] ).'\'') : ' WHERE '.$map['id'].' = \''.addslashes( $uri['id'] ).'\'';65 $criteria = ($criteria !== false) ? $this->parseCriteria ( $criteria , $map , ' WHERE '.$map['id'].' = \''.pg_escape_string( $uri['id'] ).'\'') : ' WHERE '.$map['id'].' = \''.pg_escape_string( $uri['id'] ).'\''; 66 66 67 67 return $this->execSql( 'SELECT '.$justthese['select'].' FROM '. (Config::get($uri['concept'],'PostgreSQL.concept')) .$criteria , true ); 68 68 } 69 69 70 70 public function deleteAll ( $uri, $justthese = false, $criteria = false ){ 71 71 $map = Config::get($uri['concept'], 'PostgreSQL.mapping'); 72 73 72 if(!self::parseCriteria ( $criteria , $map)) return false; //Validador para não apagar tabela inteira 73 return $this->execSql( 'DELETE FROM '.(Config::get($uri['concept'],'PostgreSQL.concept')).' '.self::parseCriteria ( $criteria ,$map) ); 74 74 } 75 75 76 76 public function delete ( $uri, $justthese = false, $criteria = false ){ 77 77 if(!isset($uri['id']) && !is_int($uri['id'])) return false; //Delete chamado apenas passando id inteiros 78 79 $criteria = ($criteria !== false) ? $this->parseCriteria ( $criteria , $map , ' WHERE '.$map['id'].' = \''.addslashes( $uri['id'] ).'\'') : ' WHERE '.$map['id'].' = \''.addslashes( $uri['id'] ).'\'';80 78 $map = Config::get($uri['concept'], 'PostgreSQL.mapping'); 79 $criteria = ($criteria !== false) ? $this->parseCriteria ( $criteria , $map , ' WHERE '.$map['id'].' = \''.pg_escape_string( $uri['id'] ).'\'') : ' WHERE '.$map['id'].' = \''.pg_escape_string( $uri['id'] ).'\''; 80 return $this->execSql('DELETE FROM '.(Config::get($uri['concept'],'PostgreSQL.concept')).$criteria); 81 81 } 82 82 83 83 public function replace ( $uri, $data, $criteria = false ){ 84 84 $map = Config::get($uri['concept'], 'PostgreSQL.mapping'); 85 86 } 87 85 return $this->execSql('UPDATE '.(Config::get($uri['concept'],'PostgreSQL.concept')).' '. self::parseUpdateData( $data ,$map).' '.self::parseCriteria($criteria , $map)); 86 } 87 88 88 public function update ( $uri, $data, $criteria = false ){ 89 89 $map = Config::get($uri['concept'], 'PostgreSQL.mapping'); 90 $criteria = ($criteria !== false) ? $this->parseCriteria ( $criteria , $map , ' WHERE '.$map['id'].' = \''.addslashes( $uri['id'] ).'\'') : ' WHERE '.$map['id'].' = \''.addslashes( $uri['id'] ).'\'';91 92 93 } 94 95 public function create ( $uri, $data ){ 96 90 $criteria = ($criteria !== false) ? $this->parseCriteria ( $criteria , $map , ' WHERE '.$map['id'].' = \''.pg_escape_string( $uri['id'] ).'\'') : ' WHERE '.$map['id'].' = \''.pg_escape_string( $uri['id'] ).'\''; 91 92 return $this->execSql('UPDATE '.(Config::get($uri['concept'],'PostgreSQL.concept')).' '. self::parseUpdateData( $data ,$map).$criteria); 93 } 94 95 public function create ( $uri, $data ){ 96 return $this->execSql( 'INSERT INTO '.(Config::get($uri['concept'],'PostgreSQL.concept')).' '.self::parseInsertData( $data , $uri['concept'] ), true ); 97 97 } 98 98 99 99 public function execSql( $sql, $unique = false ) 100 100 { 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 101 if(!$this->con) $this->open( $this->config ); 102 103 $rs = pg_query( $this->con, $sql ); 104 105 switch( pg_num_rows( $rs ) ) 106 { 107 case -1: 108 $this->error = pg_last_error ( $this->con ); 109 return( false ); 110 111 case 0: 112 return( pg_affected_rows( $rs ) ? true : array() ); 113 114 default: 115 $return = array(); 116 117 while( $row = pg_fetch_assoc( $rs ) ) 118 $return[] = $row; 119 120 return( $unique ? $return[0] : $return ); 121 } 122 122 } 123 123 … … 125 125 //@DEPRECATED 126 126 public function execResultSql( $sql, $unique = false ){ 127 127 return $this->execSql( $sql, $unique ); 128 128 } 129 129 130 130 public function begin( $uri ) { 131 131 132 133 132 if(!$this->con) 133 $this->open( $this->config ); 134 134 135 135 $this->error = false; 136 136 pg_query($this->con, "BEGIN WORK"); 137 137 } 138 138 139 139 public function commit($uri ) { 140 140 141 142 143 144 145 146 147 148 149 150 151 141 if( $this->error !== false ) 142 { 143 $error = $this->error; 144 $this->error = false; 145 146 throw new Exception( $error ); 147 } 148 149 pg_query($this->con, "COMMIT"); 150 151 return( true ); 152 152 } 153 153 154 154 public function rollback( $uri ){ 155 155 156 156 pg_query($this->con, "ROLLBACK"); 157 157 } 158 158 159 159 public function open ( $config ){ 160 160 161 161 $this->config = $config; 162 162 … … 168 168 $rs .= ( isset($this->config['port']) && $this->config['port'] ) ? ' port='.$this->config['port'] : '' ; 169 169 170 171 172 173 174 170 if($this->con = pg_connect( $rs )) 171 return $this->con; 172 173 throw new Exception('It was not possible to enable the target connection!'); 174 //$this->con = pg_connect('host='.$config['host'].' user='.$config['user'].' password='.$config['password'].' dbname='.$config['dbname'].' options=\'--client_encoding=UTF8\''); 175 175 } 176 176 177 177 public function close(){ 178 178 179 179 pg_close($this->con); 180 180 181 181 $this->con = false; … … 188 188 189 189 private static function parseInsertData( $data , $concept){ 190 190 191 191 $map = Config::get($concept, 'PostgreSQL.mapping'); 192 192 193 194 195 196 193 $ind = array(); 194 $val = array(); 195 196 foreach ($data as $i => $v){ 197 197 if(!isset($map[$i])) continue; 198 198 199 200 $val[] = '\''.addslashes($v).'\'';201 202 return '('.implode(',', $ind).') VALUES ('.implode(',', $val).') RETURNING '.$map['id'].' as id';203 } 204 199 $ind[] = $map[$i]; 200 $val[] = '\''.pg_escape_string($v).'\''; 201 } 202 return '('.implode(',', $ind).') VALUES ('.implode(',', $val).') RETURNING '.$map['id'].' as id'; 203 } 204 205 205 private static function parseUpdateData( $data , &$map){ 206 207 208 206 207 $d = array(); 208 foreach ($data as $i => $v) 209 209 { 210 210 if(!isset($map[$i])) continue; 211 211 212 $d[] = $map[$i].' = \''. addslashes($v).'\'';212 $d[] = $map[$i].' = \''.pg_escape_string ($v).'\''; 213 213 } 214 215 214 215 return 'SET '.implode(',', $d); 216 216 } 217 217 218 218 private static function parseCriteria( $criteria , &$map , $query = '' ){ 219 220 221 222 223 224 *[0] 'OR',225 *[1] array( 'OR', array( array( '=', 'campo', 'valor' ) ),226 *[2] array( '=', 'campo' , 'valor' ),227 *[3] array( 'IN', 'campo', array( '1' , '2' , '3' ) )228 *)229 230 *array( '=' , 'campo' , 'valor' )231 219 220 if( isset($criteria["filter"]) && $criteria["filter"] !== NULL ) 221 { 222 /* 223 * ex: array ( 224 * [0] 'OR', 225 * [1] array( 'OR', array( array( '=', 'campo', 'valor' ) ), 226 * [2] array( '=', 'campo' , 'valor' ), 227 * [3] array( 'IN', 'campo', array( '1' , '2' , '3' ) ) 228 * ) 229 * OR 230 * array( '=' , 'campo' , 'valor' ) 231 */ 232 232 $query .= ($query === '') ? 'WHERE ('.self::parseFilter( $criteria['filter'] , $map).')' : ' AND ('.self::parseFilter( $criteria['filter'] , $map).')'; 233 234 235 236 * 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 233 } 234 /* 235 * ex: array( 'table1' => 'table2' , 'table1' => 'table2') 236 * 237 */ 238 if( isset($criteria["join"]) ) 239 { 240 foreach ($criteria["join"] as $i => $v) 241 $query .= ' AND '.$i.' = '.$v.' '; 242 } 243 244 if( isset($criteria["group"]) ) 245 { 246 $query .= ' GROUP BY '.( is_array($criteria["group"]) ? implode(', ', $criteria["group"]) : $criteria["group"] ).' '; 247 } 248 249 if( isset($criteria["order"]) ) 250 { 251 //Verificar se os atributos para o ORDER BY serao ordenados em ordem decrescente [DESC] 252 $orderDesc = ( isset($criteria["orderDesc"]) && count($criteria["order"]) == count($criteria["orderDesc"]) ) ? $criteria["orderDesc"] : false; 253 254 $query .= ' ORDER BY '.self::parseOrder( $criteria["order"], $map, $orderDesc ).' '; 255 256 } 257 258 if( isset($criteria["limit"]) ) 259 { 260 $query .= ' LIMIT '. $criteria["limit"] .' '; 261 } 262 if( isset($criteria["offset"]) ) 263 { 264 $query .= ' OFFSET '. $criteria["offset"] .' '; 265 } 266 267 return $query; 268 268 } 269 269 270 270 private static function parseFilter( $filter ,&$map){ 271 271 272 273 274 275 276 277 278 279 280 272 if( !is_array( $filter ) || count($filter) <= 0) return null; 273 274 $op = self::parseOperator( array_shift( $filter ) ); 275 276 if( is_array($filter[0]) ) 277 { 278 $nested = array(); 279 280 foreach( $filter as $i => $f ) 281 281 if( $n = self::parseFilter( $f , $map)) 282 282 $nested[] = $n; 283 283 284 284 285 286 285 return (count($nested) > 0 ) ? '('.implode( ' '.$op.' ', $nested ).')' : ''; 286 } 287 287 288 288 if(!isset($map[$filter[0]])) return ''; … … 290 290 $filter[0] = $map[$filter[0]]; 291 291 292 293 294 295 296 297 298 299 300 301 302 303 return( $filter[0].' '.$op[0]." ($igPrefix'".implode( "'$igSuffix,$igPrefix'", array_map("addslashes" , $filter[1]) )."'$igSuffix)" );304 305 return( $filter[0].' '.$op[0]." $igPrefix'".$op[1].addslashes( $filter[1] ).$op[2]."'$igSuffix" );292 $igSuffix = $igPrefix = ''; 293 294 if( strpos( $op[0], 'i' ) === 0 ) 295 { 296 $op[0] = substr( $op[0], 1 ); 297 $filter[0] = 'upper("'.$filter[0].'")'; 298 $igPrefix = 'upper('; 299 $igSuffix = ')'; 300 } 301 302 if( is_array($filter[1]) ) 303 return( $filter[0].' '.$op[0]." ($igPrefix'".implode( "'$igSuffix,$igPrefix'", array_map("pg_escape_string" , $filter[1]) )."'$igSuffix)" ); 304 305 return( $filter[0].' '.$op[0]." $igPrefix'".$op[1].pg_escape_string( $filter[1] ).$op[2]."'$igSuffix" ); 306 306 } 307 307 308 308 private static function parseOperator( $op ){ 309 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 310 switch(strtolower($op)) 311 { 312 case 'and': 313 case 'or': return( $op ); 314 case 'in': return array( $op ); 315 case '!in': return array( 'NOT IN' ); 316 case '^': return array( 'like', '%', '' ); 317 case '$': return array( 'like', '', '%' ); 318 case '*': return array( 'like', '%', '%' ); 319 case 'i^': return array( 'ilike', '%', '' ); 320 case 'i$': return array( 'ilike', '', '%' ); 321 case 'i*': return array( 'ilike', '%', '%' ); 322 default : return array( $op, '', '' ); 323 } 324 324 } 325 325 … … 352 352 $order = array( $order ); 353 353 354 355 356 357 358 359 360 361 362 363 364 354 //Caso seja feita ordenacao em ordem descrescente 355 //concatenar DESC em cada atributo 356 if($orderDesc !== false){ 357 if(!is_array($orderDesc)){ 358 $orderDesc = array( $orderDesc ); 359 } 360 361 for($i=0; $i<count($order); $i++){ 362 $order[$i] .= ($orderDesc[$i] === true) ? ' DESC' : ''; 363 } 364 } 365 365 366 366 $return = array();
Note: See TracChangeset
for help on using the changeset viewer.