Misc. changes after review by bartv.
This commit is contained in:
parent
59ad0a6c9c
commit
feeb0c742a
|
@ -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,
|
||||
));
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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']);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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' );
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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']);
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue