diff --git a/apps/calendar/css/style.css b/apps/calendar/css/style.css index 0204f2fc12f..6555c25a767 100644 --- a/apps/calendar/css/style.css +++ b/apps/calendar/css/style.css @@ -17,6 +17,8 @@ #editentry_dialog {display: none;} #parsingfail_dialog{display: none;} +#loading { display: none; left: 40%; position: fixed; top: 4.4em; z-index: 100; } + #calendar_holder {position: relative;bottom: 0; right: 0; left: 0; top: 3em;} .fc-content{padding:2px 4px;} #listview {margin: 0; padding: 10px; background: #EEEEEE;} diff --git a/apps/calendar/export.php b/apps/calendar/export.php index 9b3ea5005d6..ce1a4aa046f 100644 --- a/apps/calendar/export.php +++ b/apps/calendar/export.php @@ -6,25 +6,25 @@ * 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_App::getCalendar($cal); $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'); foreach($calobjects as $calobject){ - echo $calobject["calendardata"] . "\n"; + echo $calobject['calendardata'] . '\n'; } }elseif(isset($event)){ - $data = OC_Calendar_App::getEventObject($_GET["eventid"]); - $calendarid = $data["calendarid"]; + $data = OC_Calendar_App::getEventObject($_GET['eventid']); + $calendarid = $data['calendarid']; $calendar = OC_Calendar_App::getCalendar($calendarid); - 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/calendar/js/calendar.js b/apps/calendar/js/calendar.js index c3644b53704..6e0a450f6a8 100644 --- a/apps/calendar/js/calendar.js +++ b/apps/calendar/js/calendar.js @@ -8,7 +8,15 @@ Calendar={ UI:{ + loading: function(isLoading){ + if (isLoading){ + $('#loading').show(); + }else{ + $('#loading').hide(); + } + }, startEventDialog:function(){ + Calendar.UI.loading(false); $('.tipsy').remove(); $('#calendar_holder').fullCalendar('unselect'); Calendar.UI.lockTime(); @@ -41,6 +49,7 @@ Calendar={ // TODO: save event $('#event').dialog('destroy').remove(); }else{ + Calendar.UI.loading(true); $('#dialog_holder').load(OC.filePath('calendar', 'ajax', 'neweventform.php'), {start:start, end:end, allday:allday?1:0}, Calendar.UI.startEventDialog); } }, @@ -50,13 +59,16 @@ Calendar={ // TODO: save event $('#event').dialog('destroy').remove(); }else{ + Calendar.UI.loading(true); $('#dialog_holder').load(OC.filePath('calendar', 'ajax', 'editeventform.php') + '?id=' + id, Calendar.UI.startEventDialog); } }, submitDeleteEventForm:function(url){ var post = $( '#event_form' ).serialize(); $('#errorbox').empty(); + Calendar.UI.loading(true); $.post(url, post, function(data){ + Calendar.UI.loading(false); if(data.status == 'success'){ $('#calendar_holder').fullCalendar('removeEvents', $('#event_form input[name=id]').val()); $('#event').dialog('destroy').remove(); @@ -69,8 +81,10 @@ Calendar={ validateEventForm:function(url){ var post = $( "#event_form" ).serialize(); $("#errorbox").empty(); + Calendar.UI.loading(true); $.post(url, post, function(data){ + Calendar.UI.loading(false); if(data.status == "error"){ var output = missing_field + ":
"; if(data.title == "true"){ @@ -107,8 +121,10 @@ Calendar={ }, moveEvent:function(event, dayDelta, minuteDelta, allDay, revertFunc){ $('.tipsy').remove(); + Calendar.UI.loading(true); $.post(OC.filePath('calendar', 'ajax', 'moveevent.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, allDay: allDay?1:0, lastmodified: event.lastmodified}, function(data) { + Calendar.UI.loading(false); if (data.status == 'success'){ event.lastmodified = data.lastmodified; console.log("Event moved successfully"); @@ -120,8 +136,10 @@ Calendar={ }, resizeEvent:function(event, dayDelta, minuteDelta, revertFunc){ $('.tipsy').remove(); + Calendar.UI.loading(true); $.post(OC.filePath('calendar', 'ajax', 'resizeevent.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, lastmodified: event.lastmodified}, function(data) { + Calendar.UI.loading(false); if (data.status == 'success'){ event.lastmodified = data.lastmodified; console.log("Event resized successfully"); @@ -210,6 +228,7 @@ Calendar={ if($('#choosecalendar_dialog').dialog('isOpen') == true){ $('#choosecalendar_dialog').dialog('moveToTop'); }else{ + Calendar.UI.loading(true); $('#dialog_holder').load(OC.filePath('calendar', 'ajax', 'choosecalendar.php'), function(){ $('#choosecalendar_dialog').dialog({ width : 600, @@ -217,13 +236,16 @@ Calendar={ $(this).dialog('destroy').remove(); } }); + Calendar.UI.loading(false); }); } }, activation:function(checkbox, calendarid) { + Calendar.UI.loading(true); $.post(OC.filePath('calendar', 'ajax', 'activation.php'), { calendarid: calendarid, active: checkbox.checked?1:0 }, function(data) { + Calendar.UI.loading(false); if (data.status == 'success'){ checkbox.checked = data.active == 1; if (data.active == 1){ @@ -520,6 +542,7 @@ $(document).ready(function(){ } }); }, + loading: Calendar.UI.loading, eventSources: eventSources }); $('#oneweekview_radio').click(function(){ diff --git a/apps/calendar/templates/calendar.php b/apps/calendar/templates/calendar.php index 2003b7efc49..13bc8bc1bb1 100755 --- a/apps/calendar/templates/calendar.php +++ b/apps/calendar/templates/calendar.php @@ -19,6 +19,7 @@ var missing_field_dberror = 't('There was a database fail') ?>'; var totalurl = '/calendars'; +
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 @@ + + * Copyright (c) 2011 Bart Visscher + * 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 @@ + + * 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 @@ + + * 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 @@ + + * 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 @@ + + * Copyright (c) 2011 Bart Visscher + * 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 @@ + + * 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 @@ + + * 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..f961767a0d6 100644 --- a/apps/contacts/css/styles.css +++ b/apps/contacts/css/styles.css @@ -1,3 +1,4 @@ +#chooseaddressbook {margin-right: 170px; float: right;} #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 @@ + + * 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 58ddc74f532..a6af54c8789 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'); + $property_types = OC_Contacts_App::getAddPropertyOptions(); $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..6f2f34225de 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(); @@ -140,12 +140,98 @@ class OC_Contacts_Addressbook{ return true; } + /** + * @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 = null){ + 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){ + 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 @@ - - +
+
-
    +
      inc("part.contacts"); ?>
@@ -24,3 +22,9 @@ OC_Util::addStyle('contacts','formtastic'); } ?>
+ +
+
+ t("There was a fail, while parsing the file."); ?> +
+ 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 @@ +
"> + +"; + $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 ""; +} +?> + + + + + + +
+ t('New Address Book') ?> +
+

">

+
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 @@ +"; + echo ""; + echo "t("CardDav Link") . "\" class=\"action\">t("Download") . "\" class=\"action\">t("Edit") . "\" class=\"action\" onclick=\"Contacts.UI.Addressbooks.editAddressbook(this, " . $_['addressbook']["id"] . ");\">t("Delete") . "\" class=\"action\">"; 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 @@ -
  • +
  • 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 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +?> +t("Edit Address Book"); ?>" colspan="6"> + + + + + + + + + + + +
    t('Displayname') ?> + +
    + > + +
    +);" value="t("Save") : $l->t("Submit"); ?>"> +);" value="t("Cancel"); ?>"> + 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']:'' )); }