diff options
22 files changed, 548 insertions, 52 deletions
diff --git a/apps/calendar/export.php b/apps/calendar/export.php index 3e93a1ad618..1647bf14a99 100644 --- a/apps/calendar/export.php +++ b/apps/calendar/export.php @@ -6,33 +6,33 @@ * See the COPYING-README file. */ -require_once ("../../lib/base.php"); +require_once ('../../lib/base.php'); OC_Util::checkLoggedIn(); OC_Util::checkAppEnabled('calendar'); -$cal = isset($_GET["calid"]) ? $_GET["calid"] : NULL; -$event = isset($_GET["eventid"]) ? $_GET["eventid"] : NULL; +$cal = isset($_GET['calid']) ? $_GET['calid'] : NULL; +$event = isset($_GET['eventid']) ? $_GET['eventid'] : NULL; if(isset($cal)){ $calendar = OC_Calendar_Calendar::findCalendar($cal); - if($calendar["userid"] != OC_User::getUser()){ + if($calendar['userid'] != OC_User::getUser()){ OC_JSON::error(); exit; } $calobjects = OC_Calendar_Object::all($cal); - header("Content-Type: text/Calendar"); - header("Content-Disposition: inline; filename=calendar.ics"); + header('Content-Type: text/Calendar'); + header('Content-Disposition: inline; filename=' . $calendar['displayname'] . '.ics'); for($i = 0;$i <= count($calobjects); $i++){ - echo $calobjects[$i]["calendardata"] . "\n"; + echo $calobjects[$i]['calendardata'] . '\n'; } }elseif(isset($event)){ - $data = OC_Calendar_Object::find($_GET["eventid"]); - $calendarid = $data["calendarid"]; + $data = OC_Calendar_Object::find($_GET['eventid']); + $calendarid = $data['calendarid']; $calendar = OC_Calendar_Calendar::findCalendar($calendarid); - if($calendar["userid"] != OC_User::getUser()){ + if($calendar['userid'] != OC_User::getUser()){ OC_JSON::error(); exit; } - header("Content-Type: text/Calendar"); - header("Content-Disposition: inline; filename=" . $data["summary"] . ".ics"); - echo $data["calendardata"]; + header('Content-Type: text/Calendar'); + header('Content-Disposition: inline; filename=' . $data['summary'] . '.ics'); + echo $data['calendardata']; } ?> diff --git a/apps/contacts/README.tanghus b/apps/contacts/README.tanghus new file mode 100644 index 00000000000..28043063fcc --- /dev/null +++ b/apps/contacts/README.tanghus @@ -0,0 +1,22 @@ +As I like to run regular, automated backups of my PIM data I looked into an +easy way of getting the direct link to an address book, and noticed the +elegant way it was possible in the calendar, where you can click on the +'Calendars' button and download it directly. +I modified the export.php script for the contacts app and can now run backups +with wget and http authentication. Hence the name 'tanghus_remote_backup' for +this branch. +Then I implemented the nice popup window function to get an UI for it and one +thing lead to another: + +As for the Calendar app there's a js popup for address book activation, CardDAV link, export, +edit, delete and add address books. + +When making changes to the address books the contact list is updated to show the +contacts in the active address book(s). + +When an address book is activated the setting is saved using OC_Preferences::setValue(). + +Most of the code is copy/paste from the Calendar and Contacts apps ;-) + +Tested with fresh clone from git@gitorious.org:~tanghus/owncloud/tanghus-owncloud.git, removed +database and config.php.
\ No newline at end of file diff --git a/apps/contacts/ajax/activation.php b/apps/contacts/ajax/activation.php new file mode 100644 index 00000000000..f4a2c94a148 --- /dev/null +++ b/apps/contacts/ajax/activation.php @@ -0,0 +1,22 @@ +<?php +/** + * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net> + * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once ("../../../lib/base.php"); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('contacts'); +$bookid = $_POST['bookid']; +OC_Contacts_Addressbook::setActive($bookid, $_POST['active']); +$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 new file mode 100644 index 00000000000..36acb9af391 --- /dev/null +++ b/apps/contacts/ajax/addbook.php @@ -0,0 +1,21 @@ +<?php +/** + * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../lib/base.php'); +$l10n = new OC_L10N('contacts'); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('contacts'); +$book = array( + 'id' => 'new', + 'displayname' => '', +); +$tmpl = new OC_Template('contacts', 'part.editaddressbook'); +$tmpl->assign('new', true); +$tmpl->assign('addressbook', $book); +$tmpl->printPage(); +?> diff --git a/apps/contacts/ajax/chooseaddressbook.php b/apps/contacts/ajax/chooseaddressbook.php new file mode 100644 index 00000000000..b0a10bb3118 --- /dev/null +++ b/apps/contacts/ajax/chooseaddressbook.php @@ -0,0 +1,16 @@ +<?php +/** + * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../lib/base.php'); +$l10n = new OC_L10N('contacts'); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('contacts'); + +$output = new OC_TEMPLATE("contacts", "part.chooseaddressbook"); +$output -> printpage(); +?> diff --git a/apps/contacts/ajax/contacts.php b/apps/contacts/ajax/contacts.php new file mode 100644 index 00000000000..b34cf414249 --- /dev/null +++ b/apps/contacts/ajax/contacts.php @@ -0,0 +1,34 @@ +<?php +/** + * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +function contacts_namesort($a,$b){ + return strcasecmp($a['fullname'],$b['fullname']); +} + +require_once('../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('contacts'); + +$addressbooks = OC_Contacts_Addressbook::active(OC_User::getUser()); +$contacts = array(); +foreach( $addressbooks as $addressbook ){ + $addressbookcontacts = OC_Contacts_VCard::all($addressbook['id']); + foreach( $addressbookcontacts as $contact ){ + if(is_null($contact['fullname'])){ + continue; + } + $contacts[] = $contact; + } +} +usort($contacts,'contacts_namesort'); +$tmpl = new OC_TEMPLATE("contacts", "part.contacts"); +$tmpl->assign('contacts', $contacts); +$page = $tmpl->fetchPage(); + +OC_JSON::success(array('data' => array( 'page' => $page ))); +?> diff --git a/apps/contacts/ajax/createaddressbook.php b/apps/contacts/ajax/createaddressbook.php new file mode 100644 index 00000000000..f94ad34e8dc --- /dev/null +++ b/apps/contacts/ajax/createaddressbook.php @@ -0,0 +1,26 @@ +<?php +/** + * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net> + * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once('../../../lib/base.php'); + +$l10n = new OC_L10N('contacts'); + +// Check if we are a user +OC_JSON::checkLoggedIn(); +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_App::getAddressbook($bookid); +$tmpl = new OC_Template('contacts', 'part.chooseaddressbook.rowfields'); +$tmpl->assign('addressbook', $addressbook); +OC_JSON::success(array( + 'page' => $tmpl->fetchPage(), + 'addressbook' => $addressbook, +)); diff --git a/apps/contacts/ajax/deletebook.php b/apps/contacts/ajax/deletebook.php index 3ede17ab886..a89c00575e9 100644 --- a/apps/contacts/ajax/deletebook.php +++ b/apps/contacts/ajax/deletebook.php @@ -23,11 +23,13 @@ // Init owncloud require_once('../../../lib/base.php'); +$l10n = new OC_L10N('contacts'); // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); -$id = $_GET['id']; +//$id = $_GET['id']; +$id = $_POST['id']; $addressbook = OC_Contacts_App::getAddressbook( $id ); OC_Contacts_Addressbook::delete($id); diff --git a/apps/contacts/ajax/editaddressbook.php b/apps/contacts/ajax/editaddressbook.php new file mode 100644 index 00000000000..ced673ce807 --- /dev/null +++ b/apps/contacts/ajax/editaddressbook.php @@ -0,0 +1,18 @@ +<?php +/** + * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../lib/base.php'); +$l10n = new OC_L10N('contacts'); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('contacts'); +$addressbook = OC_Contacts_App::getAddressbook($_GET['bookid']); +$tmpl = new OC_Template("contacts", "part.editaddressbook"); +$tmpl->assign('new', false); +$tmpl->assign('addressbook', $addressbook); +$tmpl->printPage(); +?> diff --git a/apps/contacts/ajax/updateaddressbook.php b/apps/contacts/ajax/updateaddressbook.php new file mode 100644 index 00000000000..516736cc502 --- /dev/null +++ b/apps/contacts/ajax/updateaddressbook.php @@ -0,0 +1,26 @@ +<?php +/** + * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once('../../../lib/base.php'); + +$l10n = new OC_L10N('contacts'); + +// Check if we are a user +OC_JSON::checkLoggedIn(); +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_App::getAddressbook($bookid); +$tmpl = new OC_Template('contacts', 'part.chooseaddressbook.rowfields'); +$tmpl->assign('addressbook', $addressbook); +OC_JSON::success(array( + 'page' => $tmpl->fetchPage(), + 'addressbook' => $addressbook, +)); diff --git a/apps/contacts/css/styles.css b/apps/contacts/css/styles.css index f351589fe12..048f4cf9d2d 100644 --- a/apps/contacts/css/styles.css +++ b/apps/contacts/css/styles.css @@ -1,3 +1,4 @@ +#chooseaddressbook {margin-right: 170px; float: right; font-size: 12px;} #contacts_details_name { font-weight:bold;font-size:1.1em;margin-left:25%;} #contacts_details_photo { margin:.5em 0em .5em 25%; } diff --git a/apps/contacts/export.php b/apps/contacts/export.php new file mode 100644 index 00000000000..fd2d7da1750 --- /dev/null +++ b/apps/contacts/export.php @@ -0,0 +1,39 @@ +<?php +/** + * Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +require_once ("../../lib/base.php"); +OC_Util::checkLoggedIn(); +OC_Util::checkAppEnabled('contacts'); +$book = isset($_GET['bookid']) ? $_GET['bookid'] : NULL; +$contact = isset($_GET['contactid']) ? $_GET['contactid'] : NULL; +if(isset($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=' . str_replace(' ', '_', $addressbook['displayname']) . '.vcf'); + for($i = 0;$i <= count($cardobjects); $i++){ + echo $cardobjects[$i]['carddata']; + //echo '\r\n'; + } +}elseif(isset($contact)){ + $data = OC_Contacts_App::getContactObject($contact); + $addressbookid = $data['addressbookid']; + $addressbook = OC_Contacts_App::getAddressbook($addressbookid); + if($addressbook['userid'] != OC_User::getUser()){ + OC_JSON::error(); + exit; + } + header('Content-Type: text/directory'); + header('Content-Disposition: inline; filename=' . $data['fullname'] . '.vcf'); + echo $data['carddata']; +} +?> diff --git a/apps/contacts/index.php b/apps/contacts/index.php index de7b56dd1ae..235e025cd82 100644 --- a/apps/contacts/index.php +++ b/apps/contacts/index.php @@ -21,7 +21,7 @@ */ function contacts_namesort($a,$b){ - return strcmp($a['name'],$b['name']); + return strcmp($a['fullname'],$b['fullname']); } // Init owncloud @@ -31,17 +31,8 @@ require_once('../../lib/base.php'); OC_Util::checkLoggedIn(); OC_Util::checkAppEnabled('contacts'); -// Check if the user has an addressbook -$addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser()); -if( count($addressbooks) == 0){ - OC_Contacts_Addressbook::add(OC_User::getUser(),'default','Default Address Book'); - $addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser()); -} -$prefbooks = OC_Preferences::getValue(OC_User::getUser(),'contacts','openaddressbooks',null); -if(is_null($prefbooks)){ - $prefbooks = $addressbooks[0]['id']; - OC_Preferences::setValue(OC_User::getUser(),'contacts','openaddressbooks',$prefbooks); -} +// Get active address books. This creates a default one if none exists. +$addressbooks = OC_Contacts_Addressbook::active(OC_User::getUser()); // Load the files we need OC_App::setActiveNavigationEntry( 'contacts_index' ); @@ -51,17 +42,15 @@ $id = isset( $_GET['id'] ) ? $_GET['id'] : null; // sort addressbooks (use contactsort) usort($addressbooks,'contacts_namesort'); -// Addressbooks to load -$openaddressbooks = explode(';',$prefbooks); $contacts = array(); -foreach( $openaddressbooks as $addressbook ){ - $addressbookcontacts = OC_Contacts_VCard::all($addressbook); +foreach( $addressbooks as $addressbook ){ + $addressbookcontacts = OC_Contacts_VCard::all($addressbook['id']); foreach( $addressbookcontacts as $contact ){ if(is_null($contact['fullname'])){ continue; } - $contacts[] = array( 'name' => $contact['fullname'], 'id' => $contact['id'] ); + $contacts[] = $contact; } } @@ -74,6 +63,13 @@ if( !is_null($id)/* || count($contacts)*/){ $details = OC_Contacts_VCard::structureContact($vcard); } +// Include Style and Script +OC_Util::addScript('contacts','interface'); +OC_Util::addStyle('contacts','styles'); +OC_Util::addStyle('contacts','formtastic'); +OC_Util::addScript('', 'jquery.multiselect'); +OC_Util::addStyle('', 'jquery.multiselect'); + $adr_types = OC_Contacts_App::getTypesOfProperty('ADR'); $phone_types = OC_Contacts_App::getTypesOfProperty('TEL'); diff --git a/apps/contacts/js/interface.js b/apps/contacts/js/interface.js index eb81e872682..02470d5a767 100644 --- a/apps/contacts/js/interface.js +++ b/apps/contacts/js/interface.js @@ -1,3 +1,118 @@ +Contacts={ + UI:{ + showCardDAVUrl:function(username, bookname){ + $('#carddav_url').val(totalurl + '/' + username + '/' + bookname); + $('#carddav_url').show(); + $('#carddav_url_close').show(); + }, + Addressbooks:{ + overview:function(){ + if($('#chooseaddressbook_dialog').dialog('isOpen') == true){ + $('#chooseaddressbook_dialog').dialog('moveToTop'); + }else{ + $('#dialog_holder').load(OC.filePath('contacts', 'ajax', 'chooseaddressbook.php'), function(){ + $('#chooseaddressbook_dialog').dialog({ + width : 600, + close : function(event, ui) { + $(this).dialog('destroy').remove(); + } + }); + }); + } + }, + activation:function(checkbox, bookid) + { + $.post(OC.filePath('contacts', 'ajax', 'activation.php'), { bookid: bookid, active: checkbox.checked?1:0 }, + function(data) { + /* + * Arguments: + * data.status + * data.bookid + * data.active + */ + if (data.status == 'success'){ + checkbox.checked = data.active == 1; + Contacts.UI.Contacts.update(); + } + }); + }, + newAddressbook:function(object){ + var tr = $(document.createElement('tr')) + .load(OC.filePath('contacts', 'ajax', 'addbook.php')); + $(object).closest('tr').after(tr).hide(); + /* TODO: Shouldn't there be some kinda error checking here? */ + }, + editAddressbook:function(object, bookid){ + var tr = $(document.createElement('tr')) + .load(OC.filePath('contacts', 'ajax', 'editaddressbook.php') + "?bookid="+bookid); + $(object).closest('tr').after(tr).hide(); + }, + deleteAddressbook:function(bookid){ + var check = confirm("Do you really want to delete this address book?"); + if(check == false){ + return false; + }else{ + $.post(OC.filePath('contacts', 'ajax', 'deletebook.php'), { id: bookid}, + function(data) { + if (data.status == 'success'){ + $('#chooseaddressbook_dialog').dialog('destroy').remove(); + Contacts.UI.Contacts.update(); + Contacts.UI.Addressbooks.overview(); + } else { + alert('Error: ' + data.message); + } + }); + } + }, + submit:function(button, bookid){ + var displayname = $("#displayname_"+bookid).val(); + var active = $("#edit_active_"+bookid+":checked").length; + var description = $("#description_"+bookid).val(); + + var url; + if (bookid == 'new'){ + url = OC.filePath('contacts', 'ajax', 'createaddressbook.php'); + }else{ + url = OC.filePath('contacts', 'ajax', 'updateaddressbook.php'); + } + $.post(url, { id: bookid, name: displayname, active: active, description: description }, + function(data){ + if(data.status == 'success'){ + $(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(); + } + }, + Contacts:{ + update:function(){ + $.getJSON('ajax/contacts.php',{},function(jsondata){ + if(jsondata.status == 'success'){ + $('#contacts').html(jsondata.data.page); + } + else{ + alert(jsondata.data.message); + } + }); + /* + var contactlist = $('#contacts'); + var contacts = contactlist.children('li').get(); + //alert(contacts); + contacts.sort(function(a, b) { + var compA = $(a).text().toUpperCase(); + var compB = $(b).text().toUpperCase(); + return (compA < compB) ? -1 : (compA > compB) ? 1 : 0; + }) + $.each(contacts, function(idx, itm) { contactlist.append(itm); }); + */ + } + } + } +} + $(document).ready(function(){ /*------------------------------------------------------------------------- * Event handlers @@ -79,6 +194,11 @@ $(document).ready(function(){ return false; }); + $('#chooseaddressbook').click(function(){ + Contacts.UI.Addressbooks.overview(); + return false; + }); + $('#contacts_newcontact').click(function(){ $.getJSON('ajax/showaddcard.php',{},function(jsondata){ if(jsondata.status == 'success'){ diff --git a/apps/contacts/lib/addressbook.php b/apps/contacts/lib/addressbook.php index 87477ed7ed4..7d55a00d601 100644 --- a/apps/contacts/lib/addressbook.php +++ b/apps/contacts/lib/addressbook.php @@ -44,7 +44,7 @@ class OC_Contacts_Addressbook{ * @return array */ public static function all($uid){ - $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE userid = ?' ); + $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE userid = ? ORDER BY displayname' ); $result = $stmt->execute(array($uid)); $addressbooks = array(); @@ -141,11 +141,99 @@ class OC_Contacts_Addressbook{ } /** + * @brief Get active addressbooks for a user. + * @param integer $uid User id. If null current user will be used. + * @return array + */ + 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::all($uid); + if(count($addressbooks) == 0){ + OC_Contacts_Addressbook::add($uid,'default','Default Address Book'); + $addressbooks = OC_Contacts_Addressbook::all($uid); + } + $prefbooks = $addressbooks[0]['id']; + OC_Preferences::setValue($uid,'contacts','openaddressbooks',$prefbooks); + } + return explode(';',$prefbooks); + } + + /** + * @brief Returns the list of active addressbooks for a specific user. + * @param string $uid + * @return array + */ + public static function active($uid){ + $active = self::activeIds($uid); + $addressbooks = array(); + /** FIXME: Is there a way to prepare a statement 'WHERE id IN ([range])'? + */ + foreach( $active as $aid ){ + $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_addressbooks WHERE id = ? ORDER BY displayname' ); + $result = $stmt->execute(array($aid,)); + + while( $row = $result->fetchRow()){ + $addressbooks[] = $row; + } + } + + return $addressbooks; + } + + /** + * @brief Activates an addressbook + * @param integer $id + * @param integer $name + * @return boolean + */ + public static function setActive($id,$active){ + // Need these ones for checking uri + //$addressbook = self::find($id); + + if(is_null($id)){ + $id = 0; + } + + $openaddressbooks = self::activeIds(); + if($active) { + if(!in_array($id, $openaddressbooks)) { + $openaddressbooks[] = $id; + } + } else { + if(in_array($id, $openaddressbooks)) { + unset($openaddressbooks[array_search($id, $openaddressbooks)]); + } + } + sort($openaddressbooks, SORT_NUMERIC); + // FIXME: I alway end up with a ';' prepending when imploding the array..? + OC_Preferences::setValue(OC_User::getUser(),'contacts','openaddressbooks',implode(';', $openaddressbooks)); + + return true; + } + + /** + * @brief Checks if an addressbook is active. + * @param integer $id ID of the address book. + * @return boolean + */ + public static function isActive($id){ + //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()); + } + + /** * @brief removes an address book * @param integer $id * @return boolean */ public static function delete($id){ + self::setActive($id, false); $stmt = OC_DB::prepare( 'DELETE FROM *PREFIX*contacts_addressbooks WHERE id = ?' ); $stmt->execute(array($id)); diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index a573f40f7d9..7285761fd58 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -47,15 +47,15 @@ class OC_Contacts_VCard{ * ['carddata'] */ public static function all($id){ - $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ?' ); + $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? ORDER BY fullname' ); $result = $stmt->execute(array($id)); - $addressbooks = array(); + $cards = array(); while( $row = $result->fetchRow()){ - $addressbooks[] = $row; + $cards[] = $row; } - return $addressbooks; + return $cards; } /** diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php index 649c4807dd5..8592ffe1c4c 100644 --- a/apps/contacts/templates/index.php +++ b/apps/contacts/templates/index.php @@ -1,16 +1,14 @@ -<?php // Include Style and Script -OC_Util::addScript('contacts','interface'); -OC_Util::addStyle('contacts','styles'); -OC_Util::addStyle('contacts','formtastic'); -?> - +<script type='text/javascript'> + var totalurl = '<?php echo OC_Helper::linkTo('contacts', 'carddav.php', null, true); ?>/addressbooks'; +</script> <div id="controls"> <form> <input type="button" id="contacts_newcontact" value="<?php echo $l->t('Add Contact'); ?>"> + <input type="button" id="chooseaddressbook" value="<?php echo $l->t('Address Books'); ?>"> </form> </div> <div id="leftcontent" class="leftcontent"> - <ul> + <ul id="contacts"> <?php echo $this->inc("part.contacts"); ?> </ul> </div> @@ -24,3 +22,9 @@ OC_Util::addStyle('contacts','formtastic'); } ?> </div> +<!-- Dialogs --> +<div id="dialog_holder"></div> +<div id="parsingfail_dialog" title="Parsing Fail"> + <?php echo $l->t("There was a fail, while parsing the file."); ?> +</div> +<!-- End of Dialogs --> diff --git a/apps/contacts/templates/part.chooseaddressbook.php b/apps/contacts/templates/part.chooseaddressbook.php new file mode 100644 index 00000000000..ba008837f0e --- /dev/null +++ b/apps/contacts/templates/part.chooseaddressbook.php @@ -0,0 +1,24 @@ +<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::all(OC_User::getUser()); +for($i = 0; $i < count($option_addressbooks); $i++){ + echo "<tr>"; + $tmpl = new OC_Template('contacts', 'part.chooseaddressbook.rowfields'); + $tmpl->assign('addressbook', $option_addressbooks[$i]); + $tmpl->assign('active', OC_Contacts_Addressbook::isActive($option_addressbooks[$i]['id'])); + $tmpl->printpage(); + echo "</tr>"; +} +?> +<tr> + <td colspan="5"> + <a href="#" onclick="Contacts.UI.Addressbooks.newAddressbook(this);"><?php echo $l->t('New Address Book') ?></a> + </td> +</tr> +<tr> + <td colspan="5"> + <p style="margin: 0 auto;width: 90%;"><input style="display:none;width: 90%;float: left;" type="text" id="carddav_url" onmouseover="$('#carddav_url').select();" title="<?php echo $l->t("CardDav Link"); ?>"><img id="carddav_url_close" style="height: 20px;vertical-align: middle;display: none;" src="../../core/img/actions/delete.svg" alt="close" onclick="$('#carddav_url').hide();$('#carddav_url_close').hide();"/></p> + </td> +</tr> +</table> diff --git a/apps/contacts/templates/part.chooseaddressbook.rowfields.php b/apps/contacts/templates/part.chooseaddressbook.rowfields.php new file mode 100644 index 00000000000..f612e39ecaf --- /dev/null +++ b/apps/contacts/templates/part.chooseaddressbook.rowfields.php @@ -0,0 +1,5 @@ +<?php + + echo "<td width=\"20px\"><input id=\"active_" . $_['addressbook']["id"] . "\" type=\"checkbox\" onClick=\"Contacts.UI.Addressbooks.activation(this, " . $_['addressbook']["id"] . ")\"" . (OC_Contacts_Addressbook::isActive($_['addressbook']["id"]) ? ' checked="checked"' : '') . "></td>"; + echo "<td><label for=\"active_" . $_['addressbook']["id"] . "\">" . $_['addressbook']["displayname"] . "</label></td>"; + echo "<td width=\"20px\"><a href=\"#\" onclick=\"Contacts.UI.showCardDAVUrl('" . OC_User::getUser() . "', '" . $_['addressbook']["uri"] . "');\" title=\"" . $l->t("CardDav Link") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/public.svg\"></a></td><td width=\"20px\"><a href=\"export.php?bookid=" . $_['addressbook']["id"] . "\" title=\"" . $l->t("Download") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/download.svg\"></a></td><td width=\"20px\"><a href=\"#\" title=\"" . $l->t("Edit") . "\" class=\"action\" onclick=\"Contacts.UI.Addressbooks.editAddressbook(this, " . $_['addressbook']["id"] . ");\"><img class=\"svg action\" src=\"../../core/img/actions/rename.svg\"></a></td><td width=\"20px\"><a href=\"#\" onclick=\"Contacts.UI.Addressbooks.deleteAddressbook('" . $_['addressbook']["id"] . "');\" title=\"" . $l->t("Delete") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/delete.svg\"></a></td>"; diff --git a/apps/contacts/templates/part.contacts.php b/apps/contacts/templates/part.contacts.php index 6664a3671ac..8d89e9c7ad1 100644 --- a/apps/contacts/templates/part.contacts.php +++ b/apps/contacts/templates/part.contacts.php @@ -1,3 +1,3 @@ <?php foreach( $_['contacts'] as $contact ): ?> - <li data-id="<?php echo $contact['id']; ?>"><a href="index.php?id=<?php echo $contact['id']; ?>"><?php echo $contact['name']; ?></a> </li> + <li book-id="<?php echo $contact['addressbookid']; ?>" data-id="<?php echo $contact['id']; ?>"><a href="index.php?id=<?php echo $contact['id']; ?>"><?php echo $contact['fullname']; ?></a> </li> <?php endforeach; ?> diff --git a/apps/contacts/templates/part.editaddressbook.php b/apps/contacts/templates/part.editaddressbook.php new file mode 100644 index 00000000000..cb1371731b1 --- /dev/null +++ b/apps/contacts/templates/part.editaddressbook.php @@ -0,0 +1,31 @@ +<?php +/** + * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +?> +<td id="<?php echo $_['new'] ? 'new' : 'edit' ?>addressbook_dialog" title="<?php echo $_['new'] ? $l->t("New Address Book") : $l->t("Edit Address Book"); ?>" colspan="6"> +<table width="100%" style="border: 0;"> +<tr> + <th><?php echo $l->t('Displayname') ?></th> + <td> + <input id="displayname_<?php echo $_['addressbook']['id'] ?>" type="text" value="<?php echo $_['addressbook']['displayname'] ?>"> + </td> +</tr> +<?php if (!$_['new']): ?> +<tr> + <td></td> + <td> + <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> + </td> +</tr> +<?php endif; ?> +</table> +<input style="float: left;" type="button" onclick="Contacts.UI.Addressbooks.submit(this, <?php echo $_['new'] ? "'new'" : $_['addressbook']['id'] ?>);" value="<?php echo $_['new'] ? $l->t("Save") : $l->t("Submit"); ?>"> +<input style="float: left;" type="button" onclick="Contacts.UI.Addressbooks.cancel(this, <?php echo $_['new'] ? "'new'" : $_['addressbook']['id'] ?>);" value="<?php echo $l->t("Cancel"); ?>"> +</td> diff --git a/index.php b/index.php index 2d759d68d7d..9bd460be353 100644 --- a/index.php +++ b/index.php @@ -100,14 +100,15 @@ else { $error = true; } } - // The user is already authenticated using Apaches AuthType Basic... very usable in combination with LDAP - elseif(isset($_SERVER["PHP_AUTH_USER"]) && isset($_SERVER["PHP_AUTH_PW"])){ - if (OC_User::login($_SERVER["PHP_AUTH_USER"],$_SERVER["PHP_AUTH_PW"])) { - OC_User::unsetMagicInCookie(); - OC_Util::redirectToDefaultPage(); - }else{ - $error = true; - } + // The user is already authenticated using Apaches AuthType Basic... very usable in combination with LDAP + elseif(isset($_SERVER["PHP_AUTH_USER"]) && isset($_SERVER["PHP_AUTH_PW"])){ + if (OC_User::login($_SERVER["PHP_AUTH_USER"],$_SERVER["PHP_AUTH_PW"])) { + //OC_Log::write('core',"Logged in with HTTP Authentication",OC_Log::DEBUG); + OC_User::unsetMagicInCookie(); + OC_Util::redirectToDefaultPage(); + }else{ + $error = true; } + } OC_Template::printGuestPage('', 'login', array('error' => $error, 'redirect' => isset($_REQUEST['redirect_url'])?$_REQUEST['redirect_url']:'' )); } |