[3733] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * CalDAV Server - handle PUT method on VCARD content-types |
---|
| 4 | * |
---|
| 5 | * @package davical |
---|
| 6 | * @subpackage caldav |
---|
| 7 | * @author Andrew McMillan <andrew@morphoss.com> |
---|
| 8 | * @copyright Morphoss Ltd |
---|
| 9 | * @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later |
---|
| 10 | */ |
---|
| 11 | dbg_error_log("PUT", "method handler vcard"); |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | require_once('DAVResource.php'); |
---|
| 15 | require_once('vComponent.php'); |
---|
| 16 | |
---|
| 17 | if ( ! ini_get('open_basedir') && (isset($c->dbg['ALL']) || (isset($c->dbg['put']) && $c->dbg['put'])) ) { |
---|
| 18 | $fh = fopen('/tmp/PUT.txt','w'); |
---|
| 19 | if ( $fh ) { |
---|
| 20 | fwrite($fh,$request->raw_post); |
---|
| 21 | fclose($fh); |
---|
| 22 | } |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | $lock_opener = $request->FailIfLocked(); |
---|
| 26 | |
---|
| 27 | $dest = new DAVResource($request->path); |
---|
| 28 | |
---|
| 29 | $container = $dest->FetchParentContainer(); |
---|
| 30 | if ( ! $dest->Exists() ) { |
---|
| 31 | if ( $container->IsPrincipal() ) { |
---|
| 32 | $request->DoResponse(403,translate('A DAViCal principal collection may only contain collections')); |
---|
| 33 | } |
---|
| 34 | if ( ! $container->Exists() ) { |
---|
| 35 | $request->DoResponse( 409, translate('Destination collection does not exist') ); |
---|
| 36 | } |
---|
| 37 | $container->NeedPrivilege('DAV::bind'); |
---|
| 38 | } |
---|
| 39 | else { |
---|
| 40 | // if ( $dest->IsCollection() ) { |
---|
| 41 | // if ( ! isset($c->readonly_webdav_collections) || $c->readonly_webdav_collections ) { |
---|
| 42 | // $request->DoResponse(403,translate('You may not PUT to a collection URL')); |
---|
| 43 | // } |
---|
| 44 | // $request->DoResponse(403,translate('PUT on a collection is only allowed for text/calendar content against a calendar collection')); |
---|
| 45 | // } |
---|
| 46 | $dest->NeedPrivilege('DAV::write-content'); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | if ( isset($request->etag_none_match) && $request->etag_none_match != '*' && $dest->Exists() ) { |
---|
| 50 | $request->DoResponse(412); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | //if ( isset($request->etag_if_match) && $request->etag_if_match != $dest->unique_tag() ) { |
---|
| 54 | // $request->DoResponse(412); |
---|
| 55 | //} |
---|
| 56 | |
---|
| 57 | //$collection_id = $container->GetProperty('collection_id'); |
---|
| 58 | |
---|
| 59 | //$qry = new AwlQuery(); |
---|
| 60 | //$qry->Begin(); |
---|
| 61 | |
---|
| 62 | $etag = md5($request->raw_post); |
---|
| 63 | //$params = array( |
---|
| 64 | // ':user_no' => $dest->GetProperty('user_no'), |
---|
| 65 | // ':dav_name' => $dest->bound_from(), |
---|
| 66 | // ':etag' => $etag, |
---|
| 67 | // ':dav_data' => $request->raw_post, |
---|
| 68 | // ':session_user' => $session->user_no |
---|
| 69 | //); |
---|
| 70 | //if ( $dest->Exists() ) { |
---|
| 71 | // $sql = 'UPDATE caldav_data SET caldav_data=:dav_data, dav_etag=:etag, logged_user=:session_user, |
---|
| 72 | // modified=current_timestamp, user_no=:user_no, caldav_type=\'VCARD\' WHERE dav_name=:dav_name'; |
---|
| 73 | // $response_code = 200; |
---|
| 74 | // $qry->QDo( $sql, $params ); |
---|
| 75 | // |
---|
| 76 | // $qry->QDo("SELECT dav_id FROM caldav_data WHERE dav_name = :dav_name ", array(':dav_name' => $params[':dav_name']) ); |
---|
| 77 | //} |
---|
| 78 | //else { |
---|
| 79 | // $sql = 'INSERT INTO caldav_data ( user_no, dav_name, dav_etag, caldav_data, caldav_type, logged_user, created, modified, collection_id ) |
---|
| 80 | // VALUES( :user_no, :dav_name, :etag, :dav_data, \'VCARD\', :session_user, current_timestamp, current_timestamp, :collection_id )'; |
---|
| 81 | // $params[':collection_id'] = $collection_id; |
---|
| 82 | // $response_code = 201; |
---|
| 83 | // $qry->QDo( $sql, $params ); |
---|
| 84 | // |
---|
| 85 | // $qry->QDo("SELECT currval('dav_id_seq') AS dav_id" ); |
---|
| 86 | //} |
---|
| 87 | //$row = $qry->Fetch(); |
---|
| 88 | |
---|
| 89 | require_once('vcard.php'); |
---|
| 90 | |
---|
| 91 | $vcard = new vCard( $request->raw_post ); |
---|
| 92 | $response_code=$vcard->Write_expresso( $container->GetProperty('user_no'),$dest->Exists() ); |
---|
| 93 | |
---|
| 94 | //$qry->QDo("SELECT write_sync_change( $collection_id, $response_code, :dav_name)", array(':dav_name' => $dest->bound_from() ) ); |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | //if ( !$qry->QDo('COMMIT') ) rollback(500); |
---|
| 98 | |
---|
| 99 | header('ETag: "'. $etag . '"' ); |
---|
| 100 | //if ( $response_code == 200 ) $response_code = 204; |
---|
| 101 | $request->DoResponse( $response_code ); |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | |
---|