summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2011-12-16 17:42:07 +0100
committerThomas Tanghus <thomas@tanghus.net>2011-12-16 17:42:07 +0100
commitfeeb0c742a57eb542f6e904dd4c8b5310bcc066a (patch)
tree8d422f84371d865dcdcdc60d95d4c3fcccd8b8e2 /apps
parent59ad0a6c9c9862792ec92f9ab53dfc30d54867fa (diff)
downloadnextcloud-server-feeb0c742a57eb542f6e904dd4c8b5310bcc066a.tar.gz
nextcloud-server-feeb0c742a57eb542f6e904dd4c8b5310bcc066a.zip
Misc. changes after review by bartv.
Diffstat (limited to 'apps')
-rw-r--r--apps/contacts/ajax/activation.php7
-rw-r--r--apps/contacts/ajax/addbook.php4
-rw-r--r--apps/contacts/ajax/chooseaddressbook.php4
-rw-r--r--apps/contacts/ajax/contacts.php8
-rw-r--r--apps/contacts/ajax/createaddressbook.php2
-rw-r--r--apps/contacts/ajax/editaddressbook.php6
-rw-r--r--apps/contacts/ajax/showaddcard.php2
-rw-r--r--apps/contacts/ajax/updateaddressbook.php2
-rw-r--r--apps/contacts/export.php11
-rw-r--r--apps/contacts/index.php2
-rw-r--r--apps/contacts/js/interface.js2
-rw-r--r--apps/contacts/lib/addressbook.php23
-rw-r--r--apps/contacts/lib/hooks.php2
-rw-r--r--apps/contacts/templates/index.php2
-rw-r--r--apps/contacts/templates/part.chooseaddressbook.php2
-rw-r--r--apps/contacts/templates/part.editaddressbook.php2
16 files changed, 38 insertions, 43 deletions
diff --git a/apps/contacts/ajax/activation.php b/apps/contacts/ajax/activation.php
index 49aaac97287..f4a2c94a148 100644
--- a/apps/contacts/ajax/activation.php
+++ b/apps/contacts/ajax/activation.php
@@ -8,16 +8,15 @@
*/
require_once ("../../../lib/base.php");
-if(!OC_USER::isLoggedIn()) {
- die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
-}
+OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
$bookid = $_POST['bookid'];
OC_Contacts_Addressbook::setActive($bookid, $_POST['active']);
-$book = OC_Contacts_Addressbook::find($bookid);
+$book = OC_Contacts_App::getAddressbook($bookid);
/* is there an OC_JSON::error() ? */
OC_JSON::success(array(
'active' => OC_Contacts_Addressbook::isActive($bookid),
'bookid' => $bookid,
+ 'book' => $book,
));
diff --git a/apps/contacts/ajax/addbook.php b/apps/contacts/ajax/addbook.php
index d8e5a0ecd59..36acb9af391 100644
--- a/apps/contacts/ajax/addbook.php
+++ b/apps/contacts/ajax/addbook.php
@@ -8,9 +8,7 @@
require_once('../../../lib/base.php');
$l10n = new OC_L10N('contacts');
-if(!OC_USER::isLoggedIn()) {
- die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
-}
+OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
$book = array(
'id' => 'new',
diff --git a/apps/contacts/ajax/chooseaddressbook.php b/apps/contacts/ajax/chooseaddressbook.php
index f74b580eae7..b0a10bb3118 100644
--- a/apps/contacts/ajax/chooseaddressbook.php
+++ b/apps/contacts/ajax/chooseaddressbook.php
@@ -8,9 +8,7 @@
require_once('../../../lib/base.php');
$l10n = new OC_L10N('contacts');
-if(!OC_USER::isLoggedIn()) {
- die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
-}
+OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
$output = new OC_TEMPLATE("contacts", "part.chooseaddressbook");
diff --git a/apps/contacts/ajax/contacts.php b/apps/contacts/ajax/contacts.php
index 3c3bb5fe955..b34cf414249 100644
--- a/apps/contacts/ajax/contacts.php
+++ b/apps/contacts/ajax/contacts.php
@@ -7,16 +7,14 @@
*/
function contacts_namesort($a,$b){
- return strcmp($a['fullname'],$b['fullname']);
+ return strcasecmp($a['fullname'],$b['fullname']);
}
require_once('../../../lib/base.php');
-if(!OC_USER::isLoggedIn()) {
- die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
-}
+OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$addressbooks = OC_Contacts_Addressbook::activeAddressbooks(OC_User::getUser());
+$addressbooks = OC_Contacts_Addressbook::active(OC_User::getUser());
$contacts = array();
foreach( $addressbooks as $addressbook ){
$addressbookcontacts = OC_Contacts_VCard::all($addressbook['id']);
diff --git a/apps/contacts/ajax/createaddressbook.php b/apps/contacts/ajax/createaddressbook.php
index 8fec07ebcae..f94ad34e8dc 100644
--- a/apps/contacts/ajax/createaddressbook.php
+++ b/apps/contacts/ajax/createaddressbook.php
@@ -17,7 +17,7 @@ OC_JSON::checkAppEnabled('contacts');
$userid = OC_User::getUser();
$bookid = OC_Contacts_Addressbook::add($userid, $_POST['name'], null);
OC_Contacts_Addressbook::setActive($bookid, 1);
-$addressbook = OC_Contacts_Addressbook::find($bookid);
+$addressbook = OC_Contacts_App::getAddressbook($bookid);
$tmpl = new OC_Template('contacts', 'part.chooseaddressbook.rowfields');
$tmpl->assign('addressbook', $addressbook);
OC_JSON::success(array(
diff --git a/apps/contacts/ajax/editaddressbook.php b/apps/contacts/ajax/editaddressbook.php
index abdad09dea0..ced673ce807 100644
--- a/apps/contacts/ajax/editaddressbook.php
+++ b/apps/contacts/ajax/editaddressbook.php
@@ -8,11 +8,9 @@
require_once('../../../lib/base.php');
$l10n = new OC_L10N('contacts');
-if(!OC_USER::isLoggedIn()) {
- die("<script type=\"text/javascript\">document.location = oc_webroot;</script>");
-}
+OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
-$addressbook = OC_Contacts_Addressbook::find($_GET['bookid']);
+$addressbook = OC_Contacts_App::getAddressbook($_GET['bookid']);
$tmpl = new OC_Template("contacts", "part.editaddressbook");
$tmpl->assign('new', false);
$tmpl->assign('addressbook', $addressbook);
diff --git a/apps/contacts/ajax/showaddcard.php b/apps/contacts/ajax/showaddcard.php
index 92e24216c5e..54592c89c0d 100644
--- a/apps/contacts/ajax/showaddcard.php
+++ b/apps/contacts/ajax/showaddcard.php
@@ -30,7 +30,7 @@ OC_JSON::checkAppEnabled('contacts');
$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
-$addressbooks = OC_Contacts_Addressbook::allAddressbooks(OC_USER::getUser());
+$addressbooks = OC_Contacts_Addressbook::all(OC_USER::getUser());
$tmpl = new OC_Template('contacts','part.addcardform');
$tmpl->assign('addressbooks',$addressbooks);
$tmpl->assign('adr_types',$adr_types);
diff --git a/apps/contacts/ajax/updateaddressbook.php b/apps/contacts/ajax/updateaddressbook.php
index 011dfc35d1a..516736cc502 100644
--- a/apps/contacts/ajax/updateaddressbook.php
+++ b/apps/contacts/ajax/updateaddressbook.php
@@ -17,7 +17,7 @@ OC_JSON::checkAppEnabled('contacts');
$bookid = $_POST['id'];
OC_Contacts_Addressbook::edit($bookid, $_POST['name'], null);
OC_Contacts_Addressbook::setActive($bookid, $_POST['active']);
-$addressbook = OC_Contacts_Addressbook::find($bookid);
+$addressbook = OC_Contacts_App::getAddressbook($bookid);
$tmpl = new OC_Template('contacts', 'part.chooseaddressbook.rowfields');
$tmpl->assign('addressbook', $addressbook);
OC_JSON::success(array(
diff --git a/apps/contacts/export.php b/apps/contacts/export.php
index 4a1e7a172d4..fd2d7da1750 100644
--- a/apps/contacts/export.php
+++ b/apps/contacts/export.php
@@ -12,21 +12,22 @@ OC_Util::checkAppEnabled('contacts');
$book = isset($_GET['bookid']) ? $_GET['bookid'] : NULL;
$contact = isset($_GET['contactid']) ? $_GET['contactid'] : NULL;
if(isset($book)){
- $addressbook = OC_Contacts_Addressbook::find($book);
+ $addressbook = OC_Contacts_App::getAddressbook($book);
if($addressbook['userid'] != OC_User::getUser()){
OC_JSON::error();
exit;
}
$cardobjects = OC_Contacts_VCard::all($book);
header('Content-Type: text/directory');
- header('Content-Disposition: inline; filename=' . $addressbook['displayname'] . '.vcf');
+ header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $addressbook['displayname']) . '.vcf');
for($i = 0;$i <= count($cardobjects); $i++){
- echo trim($cardobjects[$i]['carddata']) . '\n';
+ echo $cardobjects[$i]['carddata'];
+ //echo '\r\n';
}
}elseif(isset($contact)){
- $data = OC_Contacts_VCard::find($contact);
+ $data = OC_Contacts_App::getContactObject($contact);
$addressbookid = $data['addressbookid'];
- $addressbook = OC_Contacts_Addressbook::find($addressbookid);
+ $addressbook = OC_Contacts_App::getAddressbook($addressbookid);
if($addressbook['userid'] != OC_User::getUser()){
OC_JSON::error();
exit;
diff --git a/apps/contacts/index.php b/apps/contacts/index.php
index cbd1dee1d91..235e025cd82 100644
--- a/apps/contacts/index.php
+++ b/apps/contacts/index.php
@@ -32,7 +32,7 @@ OC_Util::checkLoggedIn();
OC_Util::checkAppEnabled('contacts');
// Get active address books. This creates a default one if none exists.
-$addressbooks = OC_Contacts_Addressbook::activeAddressbooks(OC_User::getUser());
+$addressbooks = OC_Contacts_Addressbook::active(OC_User::getUser());
// Load the files we need
OC_App::setActiveNavigationEntry( 'contacts_index' );
diff --git a/apps/contacts/js/interface.js b/apps/contacts/js/interface.js
index f9539e8f363..02470d5a767 100644
--- a/apps/contacts/js/interface.js
+++ b/apps/contacts/js/interface.js
@@ -1,5 +1,4 @@
Contacts={
- space:' ',
UI:{
showCardDAVUrl:function(username, bookname){
$('#carddav_url').val(totalurl + '/' + username + '/' + bookname);
@@ -82,6 +81,7 @@ Contacts={
$(button).closest('tr').prev().html(data.page).show().next().remove();
}
});
+ Contacts.UI.Contacts.update();
},
cancel:function(button, bookid){
$(button).closest('tr').prev().show().next().remove();
diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php
index 23c0b106462..7d55a00d601 100644
--- a/apps/contacts/lib/addressbook.php
+++ b/apps/contacts/lib/addressbook.php
@@ -43,7 +43,7 @@ class OC_Contacts_Addressbook{
* @param string $uid
* @return array
*/
- public static function allAddressbooks($uid){
+ public static function all($uid){
$stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE userid = ? ORDER BY displayname' );
$result = $stmt->execute(array($uid));
@@ -62,7 +62,7 @@ class OC_Contacts_Addressbook{
*/
public static function allWherePrincipalURIIs($principaluri){
$uid = self::extractUserID($principaluri);
- return self::allAddressbooks($uid);
+ return self::all($uid);
}
/**
@@ -85,7 +85,7 @@ class OC_Contacts_Addressbook{
* @return insertid
*/
public static function add($userid,$name,$description){
- $all = self::allAddressbooks($userid);
+ $all = self::all($userid);
$uris = array();
foreach($all as $i){
$uris[] = $i['uri'];
@@ -145,16 +145,16 @@ class OC_Contacts_Addressbook{
* @param integer $uid User id. If null current user will be used.
* @return array
*/
- public static function activeAddressbookIds($uid){
+ public static function activeIds($uid){
if(is_null($uid)){
$uid = OC_User::getUser();
}
$prefbooks = OC_Preferences::getValue($uid,'contacts','openaddressbooks',null);
if(is_null($prefbooks)){
- $addressbooks = OC_Contacts_Addressbook::allAddressbooks($uid);
+ $addressbooks = OC_Contacts_Addressbook::all($uid);
if(count($addressbooks) == 0){
OC_Contacts_Addressbook::add($uid,'default','Default Address Book');
- $addressbooks = OC_Contacts_Addressbook::allAddressbooks($uid);
+ $addressbooks = OC_Contacts_Addressbook::all($uid);
}
$prefbooks = $addressbooks[0]['id'];
OC_Preferences::setValue($uid,'contacts','openaddressbooks',$prefbooks);
@@ -167,8 +167,8 @@ class OC_Contacts_Addressbook{
* @param string $uid
* @return array
*/
- public static function activeAddressbooks($uid){
- $active = self::activeAddressbookIds($uid);
+ public static function active($uid){
+ $active = self::activeIds($uid);
$addressbooks = array();
/** FIXME: Is there a way to prepare a statement 'WHERE id IN ([range])'?
*/
@@ -198,7 +198,7 @@ class OC_Contacts_Addressbook{
$id = 0;
}
- $openaddressbooks = self::activeAddressbookIds();
+ $openaddressbooks = self::activeIds();
if($active) {
if(!in_array($id, $openaddressbooks)) {
$openaddressbooks[] = $id;
@@ -221,7 +221,10 @@ class OC_Contacts_Addressbook{
* @return boolean
*/
public static function isActive($id){
- return in_array($id, self::activeAddressbookIds());
+ //if(defined("DEBUG") && DEBUG) {
+ OC_Log::write('contacts','OC_Contacts_Addressbook::isActive('.$id.'):'.in_array($id, self::activeIds()),OC_Log::DEBUG);
+ //}
+ return in_array($id, self::activeIds());
}
/**
diff --git a/apps/contacts/lib/hooks.php b/apps/contacts/lib/hooks.php
index 356ae26df97..155cf40f914 100644
--- a/apps/contacts/lib/hooks.php
+++ b/apps/contacts/lib/hooks.php
@@ -30,7 +30,7 @@ class OC_Contacts_Hooks{
* @return array
*/
public function deleteUser($parameters) {
- $addressbooks = OC_Contacts_Addressbook::allAddressbooks($parameters['uid']);
+ $addressbooks = OC_Contacts_Addressbook::all($parameters['uid']);
foreach($addressbooks as $addressbook) {
OC_Contacts_Addressbook::delete($addressbook['id']);
diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php
index 44505031c64..8592ffe1c4c 100644
--- a/apps/contacts/templates/index.php
+++ b/apps/contacts/templates/index.php
@@ -1,5 +1,5 @@
<script type='text/javascript'>
- var totalurl = '<?php echo OC_Helper::linkTo('apps/contacts', 'carddav.php', null, true); ?>/addressbooks';
+ var totalurl = '<?php echo OC_Helper::linkTo('contacts', 'carddav.php', null, true); ?>/addressbooks';
</script>
<div id="controls">
<form>
diff --git a/apps/contacts/templates/part.chooseaddressbook.php b/apps/contacts/templates/part.chooseaddressbook.php
index 9574903cf95..ba008837f0e 100644
--- a/apps/contacts/templates/part.chooseaddressbook.php
+++ b/apps/contacts/templates/part.chooseaddressbook.php
@@ -1,7 +1,7 @@
<div id="chooseaddressbook_dialog" title="<?php echo $l->t("Choose active Address Books"); ?>">
<table width="100%" style="border: 0;">
<?php
-$option_addressbooks = OC_Contacts_Addressbook::allAddressbooks(OC_User::getUser());
+$option_addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser());
for($i = 0; $i < count($option_addressbooks); $i++){
echo "<tr>";
$tmpl = new OC_Template('contacts', 'part.chooseaddressbook.rowfields');
diff --git a/apps/contacts/templates/part.editaddressbook.php b/apps/contacts/templates/part.editaddressbook.php
index 4e63ce5ec17..cb1371731b1 100644
--- a/apps/contacts/templates/part.editaddressbook.php
+++ b/apps/contacts/templates/part.editaddressbook.php
@@ -18,7 +18,7 @@
<tr>
<td></td>
<td>
- <input id="edit_active_<?php echo $_['addressbook']['id'] ?>" type="checkbox"<?php echo $_['addressbook']['active'] ? ' checked="checked"' : '' ?>>
+ <input id="edit_active_<?php echo $_['addressbook']['id'] ?>" type="checkbox"<?php echo OC_Contacts_Addressbook::isActive($_['addressbook']['id']) ? ' checked="checked"' : '' ?>>
<label for="edit_active_<?php echo $_['addressbook']['id'] ?>">
<?php echo $l->t('Active') ?>
</label>