From 5bd117dd6db9e1ea27404970faf0a94490fce994 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Thu, 19 Jan 2012 16:04:39 +0100 Subject: [PATCH] UI fixes in contact editor and address book dialog. Error checking in ajax methods. Localize menu entry. --- apps/contacts/ajax/addproperty.php | 5 +- apps/contacts/ajax/getdetails.php | 3 +- apps/contacts/ajax/setproperty.php | 2 +- apps/contacts/lib/app.php | 14 ++++- apps/contacts/photo.php | 55 +++++++++++++------ apps/contacts/templates/part.addcardform.php | 2 +- .../templates/part.chooseaddressbook.php | 4 +- 7 files changed, 58 insertions(+), 27 deletions(-) diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php index 0050f5f49a..f016820ce5 100644 --- a/apps/contacts/ajax/addproperty.php +++ b/apps/contacts/ajax/addproperty.php @@ -35,7 +35,7 @@ $name = $_POST['name']; $value = $_POST['value']; if(!is_array($value)){ $value = trim($value); - if(!$value && in_array($name, array('TEL', 'EMAIL', 'ORG'))) { + if(!$value && in_array($name, array('TEL', 'EMAIL', 'ORG', 'BDAY', 'NICKNAME'))) { OC_JSON::error(array('data' => array('message' => $l->t('Cannot add empty property.')))); exit(); } @@ -72,6 +72,7 @@ foreach ($parameters as $key=>$element) { $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key,$element); } } +$checksum = md5($vcard->children[$line]->serialize()); if(!OC_Contacts_VCard::edit($id,$vcard->serialize())) { OC_JSON::error(array('data' => array('message' => $l->t('Error adding contact property.')))); @@ -88,4 +89,4 @@ $tmpl->assign('phone_types',$phone_types); $tmpl->assign('property',OC_Contacts_VCard::structureProperty($property,$line)); $page = $tmpl->fetchPage(); -OC_JSON::success(array('data' => array( 'page' => $page ))); +OC_JSON::success(array('data' => array( 'checksum' => $checksum, 'page' => $page ))); diff --git a/apps/contacts/ajax/getdetails.php b/apps/contacts/ajax/getdetails.php index 8cc0f9cbb0..4819916f4c 100644 --- a/apps/contacts/ajax/getdetails.php +++ b/apps/contacts/ajax/getdetails.php @@ -28,6 +28,7 @@ OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); $id = $_GET['id']; +$new = isset($_GET['new']) ? true : false; $vcard = OC_Contacts_App::getContactVCard( $id ); -OC_Contacts_App::renderDetails($id, $vcard); +OC_Contacts_App::renderDetails($id, $vcard, $new); diff --git a/apps/contacts/ajax/setproperty.php b/apps/contacts/ajax/setproperty.php index e0cd70236c..cdc6d34c52 100644 --- a/apps/contacts/ajax/setproperty.php +++ b/apps/contacts/ajax/setproperty.php @@ -95,4 +95,4 @@ $tmpl->assign('phone_types',$phone_types); $tmpl->assign('property',OC_Contacts_VCard::structureProperty($vcard->children[$line],$line)); $page = $tmpl->fetchPage(); -OC_JSON::success(array('data' => array( 'page' => $page, 'line' => $line, 'oldchecksum' => $_POST['checksum'] ))); +OC_JSON::success(array('data' => array( 'page' => $page, 'line' => $line, 'checksum' => $checksum, 'oldchecksum' => $_POST['checksum'] ))); diff --git a/apps/contacts/lib/app.php b/apps/contacts/lib/app.php index 00a830d5e5..bc1e4974b3 100644 --- a/apps/contacts/lib/app.php +++ b/apps/contacts/lib/app.php @@ -18,16 +18,26 @@ class OC_Contacts_App{ * @param int $id of contact * @param Sabre_VObject_Component $vcard to render */ - public static function renderDetails($id, $vcard){ + public static function renderDetails($id, $vcard, $new=false){ $property_types = self::getAddPropertyOptions(); $adr_types = self::getTypesOfProperty('ADR'); $phone_types = self::getTypesOfProperty('TEL'); + $upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize')); + $post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size')); + $maxUploadFilesize = min($upload_max_filesize, $post_max_size); + + $freeSpace=OC_Filesystem::free_space('/'); + $freeSpace=max($freeSpace,0); + $maxUploadFilesize = min($maxUploadFilesize ,$freeSpace); $details = OC_Contacts_VCard::structureContact($vcard); $name = $details['FN'][0]['value']; - $tmpl = new OC_Template('contacts','part.details'); + $t = $new ? 'part.contact' : 'part.details'; + $tmpl = new OC_Template('contacts',$t); $tmpl->assign('details',$details); $tmpl->assign('id',$id); + $tmpl->assign( 'uploadMaxFilesize', $maxUploadFilesize); + $tmpl->assign( 'uploadMaxHumanFilesize', OC_Helper::humanFileSize($maxUploadFilesize)); $tmpl->assign('property_types',$property_types); $tmpl->assign('adr_types',$adr_types); $tmpl->assign('phone_types',$phone_types); diff --git a/apps/contacts/photo.php b/apps/contacts/photo.php index 60dd81140b..478ef829ca 100644 --- a/apps/contacts/photo.php +++ b/apps/contacts/photo.php @@ -26,7 +26,9 @@ OC_Util::checkLoggedIn(); OC_Util::checkAppEnabled('contacts'); $id = $_GET['id']; - +if(isset($GET['refresh'])) { + header("Cache-Control: no-cache, no-store, must-revalidate"); +} $l10n = new OC_L10N('contacts'); $card = OC_Contacts_VCard::find( $id ); @@ -42,28 +44,45 @@ if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){ } $content = OC_VObject::parse($card['carddata']); - +$image = new OC_Image(); // invalid vcard if( is_null($content)){ - echo $l10n->t('This card is not RFC compatible.'); + $image->loadFromFile('img/person_large.png'); + header('Content-Type: '.$image->mimeType()); + $image(); + //echo $l10n->t('This card is not RFC compatible.'); exit(); -} -// Photo :-) -foreach($content->children as $child){ - if($child->name == 'PHOTO'){ - $mime = 'image/jpeg'; - foreach($child->parameters as $parameter){ - if( $parameter->name == 'TYPE' ){ - $mime = $parameter->value; +} else { + // Photo :-) + foreach($content->children as $child){ + if($child->name == 'PHOTO'){ + $mime = 'image/jpeg'; + foreach($child->parameters as $parameter){ + if( $parameter->name == 'TYPE' ){ + $mime = $parameter->value; + } } + if($image->loadFromBase64($child->value)) { + header('Content-Type: '.$mime); + $image(); + exit(); + } else { + $image->loadFromFile('img/person_large.png'); + header('Content-Type: '.$image->mimeType()); + $image(); + } + //$photo = base64_decode($child->value); + //header('Content-Type: '.$mime); + //header('Content-Length: ' . strlen($photo)); + //echo $photo; + //exit(); } - $photo = base64_decode($child->value); - header('Content-Type: '.$mime); - header('Content-Length: ' . strlen($photo)); - echo $photo; - exit(); } } +$image->loadFromFile('img/person_large.png'); +header('Content-Type: '.$image->mimeType()); +$image(); +/* // Logo :-/ foreach($content->children as $child){ if($child->name == 'PHOTO'){ @@ -80,6 +99,6 @@ foreach($content->children as $child){ exit(); } } - +*/ // Not found :-( -echo $l10n->t('This card does not contain a photo.'); +//echo $l10n->t('This card does not contain a photo.'); diff --git a/apps/contacts/templates/part.addcardform.php b/apps/contacts/templates/part.addcardform.php index 53b32188dd..11457ff269 100644 --- a/apps/contacts/templates/part.addcardform.php +++ b/apps/contacts/templates/part.addcardform.php @@ -94,7 +94,7 @@
- +
diff --git a/apps/contacts/templates/part.chooseaddressbook.php b/apps/contacts/templates/part.chooseaddressbook.php index ba008837f0..90894220ef 100644 --- a/apps/contacts/templates/part.chooseaddressbook.php +++ b/apps/contacts/templates/part.chooseaddressbook.php @@ -12,8 +12,8 @@ for($i = 0; $i < count($option_addressbooks); $i++){ } ?> - - t('New Address Book') ?> + + t('New Address Book') ?>