diff options
58 files changed, 1210 insertions, 1310 deletions
diff --git a/admin_dependencies_chk/settings.php b/admin_dependencies_chk/settings.php index de2f97aa7..34028056d 100644 --- a/admin_dependencies_chk/settings.php +++ b/admin_dependencies_chk/settings.php @@ -51,7 +51,7 @@ $modules[] =array( 'message'=> $l->t('The program mp3info is useful to discover ID3 tags of your music files')); $modules[] =array( - 'status' => OC_Helper::canExecute("ldap_bind") ? 'ok' : 'error', + 'status' => function_exists("ldap_bind") ? 'ok' : 'error', 'part'=> 'php-ldap', 'modules'=> array('user_ldap'), 'message'=> $l->t('The php-ldap module is needed connect to your ldap server')); diff --git a/bookmarks/bookmarksHelper.php b/bookmarks/bookmarksHelper.php index 44d4235b9..ac512fbc2 100644 --- a/bookmarks/bookmarksHelper.php +++ b/bookmarks/bookmarksHelper.php @@ -56,6 +56,9 @@ function getURLMetadata($url) { } $metadata['url'] = $url; + if (!function_exists('curl_init')){ + return $metadata; + } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @@ -66,4 +69,4 @@ function getURLMetadata($url) { $metadata['title'] = htmlspecialchars_decode(@$match[1]); return $metadata; -}
\ No newline at end of file +} diff --git a/calendar/ajax/activation.php b/calendar/ajax/activation.php index 89239f217..72882496a 100644 --- a/calendar/ajax/activation.php +++ b/calendar/ajax/activation.php @@ -13,5 +13,8 @@ if(!OC_USER::isLoggedIn()) { OC_JSON::checkAppEnabled('calendar'); $calendarid = $_POST['calendarid']; OC_Calendar_Calendar::setCalendarActive($calendarid, $_POST['active']); -$cal = OC_Calendar_Calendar::findCalendar($calendarid); -echo $cal['active']; +$calendar = OC_Calendar_Calendar::findCalendar($calendarid); +OC_JSON::success(array( + 'active' => $calendar['active'], + 'eventSource' => OC_Calendar_Calendar::getEventSourceInfo($calendar), +)); diff --git a/calendar/ajax/changeview.php b/calendar/ajax/changeview.php index b396ff494..ef05c7cd4 100644 --- a/calendar/ajax/changeview.php +++ b/calendar/ajax/changeview.php @@ -7,10 +7,9 @@ */ 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('calendar'); $currentview = $_GET["v"]; OC_Preferences::setValue(OC_USER::getUser(), "calendar", "currentview", $currentview); +OC_JSON::success(); ?> diff --git a/calendar/ajax/createcalendar.php b/calendar/ajax/createcalendar.php index 3fb2e8398..325a5ec35 100644 --- a/calendar/ajax/createcalendar.php +++ b/calendar/ajax/createcalendar.php @@ -20,4 +20,7 @@ OC_Calendar_Calendar::setCalendarActive($calendarid, 1); $calendar = OC_Calendar_Calendar::findCalendar($calendarid); $tmpl = new OC_Template('calendar', 'part.choosecalendar.rowfields'); $tmpl->assign('calendar', $calendar); -OC_JSON::success(array('data' => $tmpl->fetchPage())); +OC_JSON::success(array( + 'page' => $tmpl->fetchPage(), + 'eventSource' => OC_Calendar_Calendar::getEventSourceInfo($calendar), +)); diff --git a/calendar/ajax/editevent.php b/calendar/ajax/editevent.php index 3abf4de98..46feb0684 100644 --- a/calendar/ajax/editevent.php +++ b/calendar/ajax/editevent.php @@ -34,7 +34,14 @@ if($errarr){ OC_JSON::error(); exit; } - $vcalendar = Sabre_VObject_Reader::read($data['calendardata']); + $vcalendar = OC_Calendar_Object::parse($data['calendardata']); + + $last_modified = $vcalendar->VEVENT->__get('LAST-MODIFIED'); + if($last_modified && $_POST['lastmodified'] != $last_modified->getDateTime()->format('U')){ + OC_JSON::error(array('modified'=>true)); + exit; + } + OC_Calendar_Object::updateVCalendarFromRequest($_POST, $vcalendar); $result = OC_Calendar_Object::edit($id, $vcalendar->serialize()); if ($data['calendarid'] != $cal) { diff --git a/calendar/ajax/editeventform.php b/calendar/ajax/editeventform.php index 34d6c657c..63c729340 100644 --- a/calendar/ajax/editeventform.php +++ b/calendar/ajax/editeventform.php @@ -26,7 +26,7 @@ if($calendar['userid'] != OC_User::getUser()){ echo $l10n->t('Wrong calendar'); exit; } -$object = Sabre_VObject_Reader::read($data['calendardata']); +$object = OC_Calendar_Object::parse($data['calendardata']); $vevent = $object->VEVENT; $dtstart = $vevent->DTSTART; $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); @@ -63,9 +63,16 @@ foreach($categories as $category){ } $repeat = isset($vevent->CATEGORY) ? $vevent->CATEGORY->value : ''; $description = isset($vevent->DESCRIPTION) ? $vevent->DESCRIPTION->value : ''; +$last_modified = $vevent->__get('LAST-MODIFIED'); +if ($last_modified){ + $lastmodified = $last_modified->getDateTime()->format('U'); +}else{ + $lastmodified = 0; +} $tmpl = new OC_Template('calendar', 'part.editevent'); $tmpl->assign('id', $id); +$tmpl->assign('lastmodified', $lastmodified); $tmpl->assign('calendar_options', $calendar_options); $tmpl->assign('category_options', $category_options); $tmpl->assign('repeat_options', $repeat_options); diff --git a/calendar/ajax/events.php b/calendar/ajax/events.php new file mode 100644 index 000000000..9a2ba8806 --- /dev/null +++ b/calendar/ajax/events.php @@ -0,0 +1,84 @@ +<?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'); +require_once('../../../3rdparty/when/When.php'); + +function addoutput($event, $vevent, $return_event){ + $return_event['id'] = (int)$event['id']; + $return_event['title'] = $event['summary']; + $return_event['description'] = isset($vevent->DESCRIPTION)?$vevent->DESCRIPTION->value:''; + $last_modified = $vevent->__get('LAST-MODIFIED'); + if ($last_modified){ + $lastmodified = $last_modified->getDateTime()->format('U'); + }else{ + $lastmodified = 0; + } + $return_event['lastmodified'] = (int)$lastmodified; + return $return_event; +} + +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); + +$start = DateTime::createFromFormat('U', $_GET['start']); +$end = DateTime::createFromFormat('U', $_GET['end']); + +$events = OC_Calendar_Object::allInPeriod($_GET['calendar_id'], $start, $end); +$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone", "Europe/London"); +$return = array(); +foreach($events as $event){ + $object = OC_Calendar_Object::parse($event['calendardata']); + $vevent = $object->VEVENT; + $dtstart = $vevent->DTSTART; + $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); + $return_event = array(); + $start_dt = $dtstart->getDateTime(); + $start_dt->setTimezone(new DateTimeZone($user_timezone)); + $end_dt = $dtend->getDateTime(); + $end_dt->setTimezone(new DateTimeZone($user_timezone)); + if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE){ + $return_event['allDay'] = true; + }else{ + $return_event['allDay'] = false; + } + //Repeating Events + if($event['repeating'] == 1){ + $duration = (double) $end_dt->format('U') - (double) $start_dt->format('U'); + $r = new When(); + $r->recur((string) $start_dt->format('Ymd\THis'))->rrule((string) $vevent->RRULE); + while($result = $r->next()){ + if($result->format('U') > $_GET['end']){ + break; + } + if($return_event['allDay'] == true){ + $return_event['start'] = $result->format('Y-m-d'); + $return_event['end'] = date('Y-m-d', $result->format('U') + $duration--); + }else{ + $return_event['start'] = $result->format('Y-m-d H:i:s'); + $return_event['end'] = date('Y-m-d H:i:s', $result->format('U') + $duration); + } + $return[] = addoutput($event, $vevent, $return_event); + } + }else{ + $return_event = array(); + if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE){ + $return_event['allDay'] = true; + $return_event['start'] = $start_dt->format('Y-m-d'); + $end_dt->modify('-1 sec'); + $return_event['end'] = $end_dt->format('Y-m-d'); + }else{ + $return_event['start'] = $start_dt->format('Y-m-d H:i:s'); + $return_event['end'] = $end_dt->format('Y-m-d H:i:s'); + $return_event['allDay'] = false; + } + $return[] = addoutput($event, $vevent, $return_event); + } +} +OC_JSON::encodedPrint($return); +?>
\ No newline at end of file diff --git a/calendar/ajax/guesstimezone.php b/calendar/ajax/guesstimezone.php new file mode 100755 index 000000000..a3594498b --- /dev/null +++ b/calendar/ajax/guesstimezone.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. + */ +function make_array_out_of_xml ($xml){ + $returnarray = array(); + $xml = (array)$xml ; + foreach ($xml as $property => $value){ + $value = (array)$value; + if(!isset($value[0])){ + $returnarray[$property] = make_array_out_of_xml($value); + }else{ + $returnarray[$property] = trim($value[0]); + } + } + return $returnarray; +} +require_once ("../../../lib/base.php"); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); +$l = new OC_L10N('calendar'); +$lat = $_GET['lat']; +$long = $_GET['long']; +$geolocation = file_get_contents('http://ws.geonames.org/timezone?lat=' . $lat . '&lng=' . $long); +//Information are by Geonames (http://www.geonames.org) and licensed under the Creative Commons Attribution 3.0 License +$geoxml = simplexml_load_string($geolocation); +$geoarray = make_array_out_of_xml($geoxml); +if(isset($geoarray['timezone']['timezoneId']) && $geoarray['timezone']['timezoneId'] != ''){ + OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'timezone', $geoarray['timezone']['timezoneId']); + $message = array('message'=> $l->t('New Timezone:') . $geoarray['timezone']['timezoneId']); + OC_JSON::success($message); +}else{ + OC_JSON::error(); +} + +?>
\ No newline at end of file diff --git a/calendar/ajax/moveevent.php b/calendar/ajax/moveevent.php index e2b777969..6b315a392 100644 --- a/calendar/ajax/moveevent.php +++ b/calendar/ajax/moveevent.php @@ -1,6 +1,6 @@ <?php /** - * Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de> + * 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. @@ -11,93 +11,49 @@ OC_JSON::checkLoggedIn(); $data = OC_Calendar_Object::find($_POST["id"]); $calendarid = $data["calendarid"]; $cal = $calendarid; -$id = $_POST["id"]; +$id = $_POST['id']; $calendar = OC_Calendar_Calendar::findCalendar($calendarid); -if(OC_User::getUser() != $calendar["userid"]){ +if(OC_User::getUser() != $calendar['userid']){ OC_JSON::error(); exit; } -$newdate = $_POST["newdate"]; -$caldata = array(); -//modified part of editeventform.php -$object = Sabre_VObject_Reader::read($data['calendardata']); -$vevent = $object->VEVENT; +$allday = $_POST['allDay']; +$delta = new DateInterval('P0D'); +$delta->d = $_POST['dayDelta']; +$delta->i = $_POST['minuteDelta']; + +$vcalendar = OC_Calendar_Object::parse($data['calendardata']); +$vevent = $vcalendar->VEVENT; + +$last_modified = $vevent->__get('LAST-MODIFIED'); +if($last_modified && $_POST['lastmodified'] != $last_modified->getDateTime()->format('U')){ + OC_JSON::error(); + exit; +} + $dtstart = $vevent->DTSTART; $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); -switch($dtstart->getDateType()) { - case Sabre_VObject_Element_DateTime::LOCALTZ: - case Sabre_VObject_Element_DateTime::LOCAL: - $startdate = $dtstart->getDateTime()->format('d-m-Y'); - $starttime = $dtstart->getDateTime()->format('H:i'); - $enddate = $dtend->getDateTime()->format('d-m-Y'); - $endtime = $dtend->getDateTime()->format('H:i'); - $allday = false; - break; - case Sabre_VObject_Element_DateTime::DATE: - $startdate = $dtstart->getDateTime()->format('d-m-Y'); - $starttime = '00:00'; - $dtend->getDateTime()->modify('-1 day'); - $enddate = $dtend->getDateTime()->format('d-m-Y'); - $endtime = '23:59'; - $allday = true; - break; +$start_type = $dtstart->getDateType(); +$end_type = $dtend->getDateType(); +if ($allday && $start_type != Sabre_VObject_Element_DateTime::DATE){ + $start_type = $end_type = Sabre_VObject_Element_DateTime::DATE; + $dtend->setDateTime($dtend->getDateTime()->modify('+1 day'), $end_type); } -$caldata["title"] = isset($vevent->SUMMARY) ? $vevent->SUMMARY->value : ''; -$caldata["location"] = isset($vevent->LOCATION) ? $vevent->LOCATION->value : ''; -$caldata["categories"] = array(); -if (isset($vevent->CATEGORIES)){ - $caldata["categories"] = explode(',', $vevent->CATEGORIES->value); - $caldata["categories"] = array_map('trim', $categories); +if (!$allday && $start_type == Sabre_VObject_Element_DateTime::DATE){ + $start_type = $end_type = Sabre_VObject_Element_DateTime::LOCALTZ; } -foreach($caldata["categories"] as $category){ - if (!in_array($category, $category_options)){ - array_unshift($category_options, $category); - } -} -$caldata["repeat"] = isset($vevent->CATEGORY) ? $vevent->CATEGORY->value : ''; -$caldata["description"] = isset($vevent->DESCRIPTION) ? $vevent->DESCRIPTION->value : ''; -//end part of editeventform.php -$startdatearray = explode("-", $startdate); -$starttimearray = explode(":", $starttime); -$startunix = mktime($starttimearray[0], $starttimearray[1], 0, $startdatearray[1], $startdatearray[0], $startdatearray[2]); -$enddatearray = explode("-", $enddate); -$endtimearray = explode(":", $endtime); -$endunix = mktime($endtimearray[0], $endtimearray[1], 0, $enddatearray[1], $enddatearray[0], $enddatearray[2]); -$difference = $endunix - $startunix; -if(strlen($newdate) > 10){ - $newdatestringarray = explode("-", $newdate); - if($newdatestringarray[1] == "allday"){ - $allday = true; - $newdatestringarray[1] = "00:00"; - }else{ - if($allday == true){ - $difference = 3600; - } - $allday = false; - } -}else{ - $newdatestringarray = array(); - $newdatestringarray[0] = $newdate; - $newdatestringarray[1] = $starttime; -} -$newdatearray = explode(".", $newdatestringarray[0]); -$newtimearray = explode(":", $newdatestringarray[1]); -$newstartunix = mktime($newtimearray[0], $newtimearray[1], 0, $newdatearray[1], $newdatearray[0], $newdatearray[2]); -$newendunix = $newstartunix + $difference; -if($allday == true){ - $caldata["allday"] = true; -}else{ - unset($caldata["allday"]); -} -$caldata["from"] = date("d-m-Y", $newstartunix); -$caldata["fromtime"] = date("H:i", $newstartunix); -$caldata["to"] = date("d-m-Y", $newendunix); -$caldata["totime"] = date("H:i", $newendunix); -//modified part of editevent.php -$vcalendar = Sabre_VObject_Reader::read($data["calendardata"]); -OC_Calendar_Object::updateVCalendarFromRequest($caldata, $vcalendar); +$dtstart->setDateTime($dtstart->getDateTime()->add($delta), $start_type); +$dtend->setDateTime($dtend->getDateTime()->add($delta), $end_type); +unset($vevent->DURATION); + +$now = new DateTime(); +$last_modified = new Sabre_VObject_Element_DateTime('LAST-MODIFIED'); +$last_modified->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); +$vevent->__set('LAST-MODIFIED', $last_modified); + +$dtstamp = new Sabre_VObject_Element_DateTime('DTSTAMP'); +$dtstamp->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); +$vevent->DTSTAMP = $dtstamp; $result = OC_Calendar_Object::edit($id, $vcalendar->serialize()); -OC_JSON::success(); -//end part of editevent.php -?>
\ No newline at end of file +OC_JSON::success(array('lastmodified'=>(int)$now->format('U'))); diff --git a/calendar/ajax/neweventform.php b/calendar/ajax/neweventform.php index 9d4dcfa2e..588d36487 100644 --- a/calendar/ajax/neweventform.php +++ b/calendar/ajax/neweventform.php @@ -15,43 +15,35 @@ if(!OC_USER::isLoggedIn()) { } OC_JSON::checkAppEnabled('calendar'); -$calendar_options = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); -$category_options = OC_Calendar_Object::getCategoryOptions($l10n); -$repeat_options = OC_Calendar_Object::getRepeatOptions($l10n); -$startday = substr($_GET['d'], 0, 2); -$startmonth = substr($_GET['d'], 2, 2); -$startyear = substr($_GET['d'], 4, 4); -$starttime = $_GET['t']; -$allday = $starttime == 'allday'; -if($starttime != 'undefined' && !is_nan($starttime) && !$allday){ - $startminutes = '00'; -}elseif($allday){ - $starttime = '0'; - $startminutes = '00'; -}else{ - $starttime = date('G'); - - $startminutes = date('i'); +if (!isset($_POST['start'])){ + OC_JSON::error(); + die; } +$start = $_POST['start']; +$end = $_POST['end']; +$allday = $_POST['allday']; -$datetimestamp = mktime($starttime, $startminutes, 0, $startmonth, $startday, $startyear); -$duration = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'duration', "60"); -$datetimestamp = $datetimestamp + ($duration * 60); -$endmonth = date("m", $datetimestamp); -$endday = date("d", $datetimestamp); -$endyear = date("Y", $datetimestamp); -$endtime = date("G", $datetimestamp); -$endminutes = date("i", $datetimestamp); - +if (!$end){ + $duration = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'duration', '60'); + $end = $start + ($duration * 60); +} +$start = new DateTime('@'.$start); +$end = new DateTime('@'.$end); +$timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', 'Europe/London'); +$start->setTimezone(new DateTimeZone($timezone)); +$end->setTimezone(new DateTimeZone($timezone)); +$calendar_options = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); +$category_options = OC_Calendar_Object::getCategoryOptions($l10n); +$repeat_options = OC_Calendar_Object::getRepeatOptions($l10n); $tmpl = new OC_Template('calendar', 'part.newevent'); $tmpl->assign('calendar_options', $calendar_options); $tmpl->assign('category_options', $category_options); -$tmpl->assign('startdate', $startday . '-' . $startmonth . '-' . $startyear); -$tmpl->assign('starttime', ($starttime <= 9 ? '0' : '') . $starttime . ':' . $startminutes); -$tmpl->assign('enddate', $endday . '-' . $endmonth . '-' . $endyear); -$tmpl->assign('endtime', ($endtime <= 9 ? '0' : '') . $endtime . ':' . $endminutes); +$tmpl->assign('startdate', $start->format('d-m-Y')); +$tmpl->assign('starttime', $start->format('H:i')); +$tmpl->assign('enddate', $end->format('d-m-Y')); +$tmpl->assign('endtime', $end->format('H:i')); $tmpl->assign('allday', $allday); $tmpl->printpage(); ?> diff --git a/calendar/ajax/resizeevent.php b/calendar/ajax/resizeevent.php new file mode 100644 index 000000000..28a185411 --- /dev/null +++ b/calendar/ajax/resizeevent.php @@ -0,0 +1,49 @@ +<?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. + */ +error_reporting(E_ALL); +require_once('../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +$data = OC_Calendar_Object::find($_POST["id"]); +$calendarid = $data["calendarid"]; +$cal = $calendarid; +$id = $_POST['id']; +$calendar = OC_Calendar_Calendar::findCalendar($calendarid); +if(OC_User::getUser() != $calendar['userid']){ + OC_JSON::error(); + exit; +} + +$delta = new DateInterval('P0D'); +$delta->d = $_POST['dayDelta']; +$delta->i = $_POST['minuteDelta']; + +$vcalendar = OC_Calendar_Object::parse($data['calendardata']); +$vevent = $vcalendar->VEVENT; + +$last_modified = $vevent->__get('LAST-MODIFIED'); +if($last_modified && $_POST['lastmodified'] != $last_modified->getDateTime()->format('U')){ + OC_JSON::error(); + exit; +} + +$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); +$end_type = $dtend->getDateType(); +$dtend->setDateTime($dtend->getDateTime()->add($delta), $end_type); +unset($vevent->DURATION); + +$now = new DateTime(); +$last_modified = new Sabre_VObject_Element_DateTime('LAST-MODIFIED'); +$last_modified->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); +$vevent->__set('LAST-MODIFIED', $last_modified); + +$dtstamp = new Sabre_VObject_Element_DateTime('DTSTAMP'); +$dtstamp->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); +$vevent->DTSTAMP = $dtstamp; + +$result = OC_Calendar_Object::edit($id, $vcalendar->serialize()); +OC_JSON::success(array('lastmodified'=>$now->format('U'))); diff --git a/calendar/ajax/updatecalendar.php b/calendar/ajax/updatecalendar.php index a81644ded..e99ca16e2 100644 --- a/calendar/ajax/updatecalendar.php +++ b/calendar/ajax/updatecalendar.php @@ -20,4 +20,7 @@ OC_Calendar_Calendar::setCalendarActive($calendarid, $_POST['active']); $calendar = OC_Calendar_Calendar::findCalendar($calendarid); $tmpl = new OC_Template('calendar', 'part.choosecalendar.rowfields'); $tmpl->assign('calendar', $calendar); -OC_JSON::success(array('data' => $tmpl->fetchPage())); +OC_JSON::success(array( + 'page' => $tmpl->fetchPage(), + 'eventSource' => OC_Calendar_Calendar::getEventSourceInfo($calendar), +)); diff --git a/calendar/appinfo/app.php b/calendar/appinfo/app.php index 2dc01eab0..5675e624d 100644 --- a/calendar/appinfo/app.php +++ b/calendar/appinfo/app.php @@ -21,3 +21,5 @@ OC_App::addNavigationEntry( array( 'name' => $l->t('Calendar'))); OC_App::registerPersonal('calendar', 'settings'); + +require_once('apps/calendar/lib/search.php');
\ No newline at end of file diff --git a/calendar/css/style.css b/calendar/css/style.css index 80d29ca89..0204f2fc1 100644 --- a/calendar/css/style.css +++ b/calendar/css/style.css @@ -17,19 +17,12 @@ #editentry_dialog {display: none;} #parsingfail_dialog{display: none;} -#calendar_holder {height: 100%; width: 100%;} -#onedayview, #oneweekview, #fourweeksview, #onemonthview, #listview {display: none; position: absolute;bottom: 0; right: 0; left: 160px; top: 80px;} -#onedayview table {margin: 0; padding: 0; width: 100%; height: 100%; border-spacing:1px; background: #EEEEEE;} -#oneweekview table {margin: 0; padding: 0; width: 100%; height: 100%; border-spacing:1px; background: #EEEEEE;} -#fourweeksview table {margin: 0; padding: 0; width: 100%; height: 100%; border-spacing:1px; background: #EEEEEE;overflow: hidden;} -#onemonthview table {margin: 0; padding: 0; width: 100%; height: 100%; border-spacing:1px; background: #EEEEEE;} +#calendar_holder {position: relative;bottom: 0; right: 0; left: 0; top: 3em;} +.fc-content{padding:2px 4px;} #listview {margin: 0; padding: 10px; background: #EEEEEE;} #listview #more_before, #listview #more_after {border: 1px solid #1a1a1a; width:25em;padding: 3px;text-align: center;} #listview #events {width:25em;padding: 4px;} #listview #events .day {width:auto;padding-left:10px;border-bottom: 2px solid #EEEEEE;text-align:left;} -#fourweeksview .calw{vertical-align: middle;text-align: center;width: 50px;} - -#sysbox{display: none;} .actions {height: 33px; min-width: 800px;} .controls {min-width: 800px;} @@ -60,3 +53,75 @@ button.category{margin:0 3px;} .calendar-colorpicker-color{display:inline-block;width:20px;height:20px;margin-right:2px;cursor:pointer;border:2px solid transparent;} .calendar-colorpicker-color.active{border:2px solid black;} + +.fc-list-table +{ + margin: 10px; + border-style: hidden; + border-width: 10px; + padding: 10px; + vertical-align: top; + width: 100%; +} +.fc-list-table tr:hover +{ + color: #0000FF; + background-color: #CCFFCC; +} + + +.fc-list-date +{ + margin: 16px; + white-space: nowrap; + text-align: left; + width: 100%; + background-color: #808080; + color: #FFFFFF; + font-weight: bold; + font-family: Arial, Helvetica, sans-serif; +} +.fc-list-time +{ + text-align: center; + white-space: nowrap; + width: 1%; +} + +.fc-list-event +{ + text-align: left; +} + +.fc-list-event .fc-event-title +{ + cursor: pointer; +} +.tipsy-event .tipsy-inner{ +background-color:#0098E4; +border:2px solid #1d2d44; +max-width:400px; +padding:0; +} +.tipsy-event .tipsy-arrow-s{ +border-top-color:#1d2d44; +} +.tipsy-event .tipsy-arrow-n{ +border-bottom-color:#1d2d44; +} +.tipsy-event .summary, +.tipsy-event .timespan, +.tipsy-event .description{ +padding:0 8px; +} +.tipsy-event .summary{ +background-color:#1d2d44; +font-size:1.2em; +font-weight:bold; +text-align:left; +padding:0 8px 2px; +} +.tipsy-event .description{ +line-height:1.2; +margin-bottom:4px; +} diff --git a/calendar/index.php b/calendar/index.php index 8b8ac7295..3313750d5 100644 --- a/calendar/index.php +++ b/calendar/index.php @@ -10,15 +10,36 @@ require_once ('../../lib/base.php'); OC_Util::checkLoggedIn(); OC_Util::checkAppEnabled('calendar'); // Create default calendar ... -$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); +$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1); if( count($calendars) == 0){ OC_Calendar_Calendar::addCalendar(OC_User::getUser(),'Default calendar'); - $calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser()); + $calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1); } -OC_UTIL::addScript('calendar', 'calendar'); -OC_UTIL::addStyle('calendar', 'style'); -OC_UTIL::addScript('', 'jquery.multiselect'); -OC_UTIL::addStyle('', 'jquery.multiselect'); -OC_APP::setActiveNavigationEntry('calendar_index'); -$output = new OC_TEMPLATE('calendar', 'calendar', 'user'); -$output -> printPage(); +$eventSources = array(); +foreach($calendars as $calendar){ + $eventSources[] = OC_Calendar_Calendar::getEventSourceInfo($calendar); +} +//Fix currentview for fullcalendar +if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'month') == "oneweekview"){ + OC_Preferences::setValue(OC_USER::getUser(), "calendar", "currentview", "agendaWeek"); +} +if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'month') == "onemonthview"){ + OC_Preferences::setValue(OC_USER::getUser(), "calendar", "currentview", "month"); +} +if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'month') == "listview"){ + OC_Preferences::setValue(OC_USER::getUser(), "calendar", "currentview", "list"); +} + +OC_Util::addScript('3rdparty/fullcalendar', 'fullcalendar'); +OC_Util::addStyle('3rdparty/fullcalendar', 'fullcalendar'); +if(OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone") == null){ + OC_UTIL::addScript('calendar', 'geo'); +} +OC_Util::addScript('calendar', 'calendar'); +OC_Util::addStyle('calendar', 'style'); +OC_Util::addScript('', 'jquery.multiselect'); +OC_Util::addStyle('', 'jquery.multiselect'); +OC_App::setActiveNavigationEntry('calendar_index'); +$tmpl = new OC_Template('calendar', 'calendar', 'user'); +$tmpl->assign('eventSources', $eventSources); +$tmpl->printPage();
\ No newline at end of file diff --git a/calendar/js/calendar.js b/calendar/js/calendar.js index 2917d9f91..005e359f8 100644 --- a/calendar/js/calendar.js +++ b/calendar/js/calendar.js @@ -8,261 +8,10 @@ Calendar={ space:' ', - firstdayofweek: '', - weekend: '', - Date:{ - normal_year_cal: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], - leap_year_cal: [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], - calw:function() { - var dayofweek = this.current.getDay(); - if(dayofweek == 0) { - dayofweek = 7; - } - var calw = Math.floor((this.doy() - dayofweek) / 7) + 1; - return calw; - }, - - doy:function() { - var cal = this.getnumberofdays(this.current.getFullYear()); - var doy = 0; - for(var i = 0; i < this.current.getMonth(); i++) { - doy = doy + cal[i]; - } - doy = doy + this.current.getDate(); - return doy; - }, - - getnumberofdays:function(year) { - if(this.checkforleapyear(year) == true) { - var cal = this.leap_year_cal; - } else { - var cal = this.normal_year_cal; - } - return cal; - }, - - checkforleapyear:function(year2check) { - if((year2check / 600) == Math.floor(year2check / 400)) { - return true; - } - if((year2check / 4) == Math.floor(year2check / 4)) { - if((year2check / 100) == Math.floor(year2check / 100)) { - return false; - } - return true; - } - return false; - }, - - current:new Date(), - forward_day:function(){ - this.current.setDate(this.current.getDate()+1); - }, - - forward_week:function(){ - this.current.setDate(this.current.getDate()+7); - }, - - forward_month:function(){ - this.current.setMonth(this.current.getMonth()+1); - }, - - backward_day:function(){ - this.current.setDate(this.current.getDate()-1); - }, - - backward_week:function(){ - this.current.setDate(this.current.getDate()-7); - }, - - backward_month:function(){ - this.current.setMonth(this.current.getMonth()-1); - }, - - }, UI:{ - weekdays: '', - formatDayShort:function(day){ - if (typeof(day) == 'undefined'){ - day = Calendar.Date.current.getDay(); - } - return this.dayshort[day]; - }, - formatDayLong:function(day){ - if (typeof(day) == 'undefined'){ - day = Calendar.Date.current.getDay(); - } - return this.daylong[day]; - }, - formatMonthShort:function(month){ - if (typeof(month) == 'undefined'){ - month = Calendar.Date.current.getMonth(); - } - return this.monthshort[month]; - }, - formatMonthLong:function(month){ - if (typeof(month) == 'undefined'){ - month = Calendar.Date.current.getMonth(); - } - return this.monthlong[month]; - }, - formatDate:function(date){ - return date[0] + '-' + date[1] + '-' + date[2]; - }, - formatTime:function(date){ - return date[3] + ':' + date[4]; - }, - updateView:function() { - this.current.removeEvents(); - this.current.renderCal(); - this.current.showEvents(); - }, - currentview:'none', - setCurrentView:function(view){ - if (view == this.currentview){ - return; - } - $('#'+this.currentview).hide(); - $('#'+this.currentview + "_radio").removeClass('active'); - this.currentview = view; - //sending ajax request on every change view - $("#sysbox").load(OC.filePath('calendar', 'ajax', 'changeview.php') + "?v="+view); - //not necessary to check whether the response is true or not - switch(view) { - case "onedayview": - this.current = this.OneDay; - break; - case "oneweekview": - this.current = this.OneWeek; - break; - case "fourweeksview": - this.current = this.FourWeeks; - break; - case "onemonthview": - this.current = this.OneMonth; - break; - case "listview": - this.current = this.List; - break; - default: - alert('Unknown view:'+view); - break; - } - $(document).ready(function() { - $('#'+Calendar.UI.currentview).show(); - $('#'+Calendar.UI.currentview + "_radio") - .addClass('active'); - Calendar.UI.updateView() - }); - }, - drageventid: '', - updateDate:function(direction){ - if(direction == 'forward' && this.current.forward) { - this.current.forward(); - if(Calendar.Date.current.getMonth() == 11){ - this.loadEvents(Calendar.Date.current.getFullYear() + 1); - } - this.updateView(); - } - if(direction == 'backward' && this.current.backward) { - this.current.backward(); - if(Calendar.Date.current.getMonth() == 0){ - this.loadEvents(Calendar.Date.current.getFullYear() - 1); - } - this.updateView(); - } - }, - events:[], - loadEvents:function(year){ - if( typeof (year) == 'undefined') { - this.events = []; - year = Calendar.Date.current.getFullYear(); - } - if( typeof (this.events[year]) == "undefined") { - this.events[year] = [] - } - $.getJSON(OC.filePath('calendar', 'ajax', 'getcal.php') + "?year=" + year, function(jsondata, status) { - if(status == "nosession") { - alert("You are not logged in. That can happen if you don't use owncloud for a long time."); - document.location(oc_webroot); - } - if(status == "parsingfail" || typeof (jsondata) == "undefined") { - $.ready(function() { - $( "#parsingfail_dialog" ).dialog(); - }); - } else { - if (typeof(jsondata[year]) != 'undefined'){ - Calendar.UI.calendars = jsondata['calendars']; - Calendar.UI.events[year] = jsondata[year]; - } - $(document).ready(function() { - Calendar.UI.updateView(); - }); - } - }); - window.setTimeout("Calendar.UI.loadEvents(" + year + ")", 120000); - }, - getEventsForDate:function(date){ - var day = date.getDate(); - var month = date.getMonth(); - var year = date.getFullYear(); - if( typeof (this.events[year]) == "undefined") { - this.loadEvents(year); - return false; - } - if( typeof (this.events[year][month]) == "undefined") { - return false; - } - if( typeof (this.events[year][month][day]) == "undefined") { - return false; - } - return this.events[year][month][day]; - }, - createEventsForDate:function(date, week){ - events = this.getEventsForDate(date); - if (!events) { - return; - } - var weekday = (date.getDay()+7-Calendar.firstdayofweek)%7; - if( typeof (events["allday"]) != "undefined") { - var eventnumber = 1; - var eventcontainer = this.current.getEventContainer(week, weekday, "allday"); - while( typeof (events["allday"][eventnumber]) != "undefined") { - this.addEventLabel(eventcontainer, events['allday'][eventnumber]); - eventnumber++; - } - } - for(var time = 0; time <= 23; time++) { - if( typeof (events[time]) != "undefined") { - var eventnumber = 1; - var eventcontainer = this.current.getEventContainer(week, weekday, time); - while( typeof (events[time][eventnumber]) != "undefined") { - this.addEventLabel(eventcontainer, events[time][eventnumber]); - eventnumber++; - } - } - } - }, - addEventLabel:function(eventcontainer, event){ - var event_holder = this.current.createEventLabel(event) - .addClass('event') - .data('event_info', event) - .hover(this.createEventPopup, - this.hideEventPopup) - .draggable({ - drag: function() { - Calendar.UI.drageventid = event.id; - } - }) - .click(this.editEvent); - var color = this.calendars[event['calendarid']]['color']; - if (color){ - event_holder.css('background-color', color) - .addClass('colored'); - } - eventcontainer.append(event_holder); - }, startEventDialog:function(){ + $('.tipsy').remove(); + $('#calendar_holder').fullCalendar('unselect'); Calendar.UI.lockTime(); $( "#from" ).datepicker({ dateFormat : 'dd-mm-yy' @@ -284,30 +33,20 @@ Calendar={ } }); }, - newEvent:function(selector, time){ - var date_info = $(selector).data('date_info'); - var dayofmonth = date_info.getDate(); - var month = date_info.getMonth(); - var year = date_info.getFullYear(); - if(dayofmonth <= 9){ - dayofmonth = '0' + dayofmonth; - } - month++; - if(month <= 9){ - month = '0' + month; + newEvent:function(start, end, allday){ + start = Math.round(start.getTime()/1000); + if (end){ + end = Math.round(end.getTime()/1000); } - var date = String(dayofmonth) + String(month) + String(year); if($('#event').dialog('isOpen') == true){ // TODO: save event $('#event').dialog('destroy').remove(); }else{ - $('#dialog_holder').load(OC.filePath('calendar', 'ajax', 'neweventform.php') + '?d=' + date + '&t=' + time, Calendar.UI.startEventDialog); + $('#dialog_holder').load(OC.filePath('calendar', 'ajax', 'neweventform.php'), {start:start, end:end, allday:allday?1:0}, Calendar.UI.startEventDialog); } }, - editEvent:function(event){ - event.stopPropagation(); - var event_data = $(this).data('event_info'); - var id = event_data.id; + editEvent:function(calEvent, jsEvent, view){ + var id = calEvent.id; if($('#event').dialog('isOpen') == true){ // TODO: save event $('#event').dialog('destroy').remove(); @@ -316,14 +55,14 @@ Calendar={ } }, submitDeleteEventForm:function(url){ - var post = $( "#event_form" ).serialize(); - $("#errorbox").empty(); + var post = $( '#event_form' ).serialize(); + $('#errorbox').empty(); $.post(url, post, function(data){ if(data.status == 'success'){ + $('#calendar_holder').fullCalendar('removeEvents', $('#event_form input[name=id]').val()); $('#event').dialog('destroy').remove(); - Calendar.UI.loadEvents(); } else { - $("#errorbox").html("Deletion failed"); + $('#errorbox').html(t('calendar', 'Deletion failed')); } }, "json"); @@ -334,27 +73,27 @@ Calendar={ $.post(url, post, function(data){ if(data.status == "error"){ - var output = "Missing fields: <br />"; + var output = missing_field + ": <br />"; if(data.title == "true"){ - output = output + "Title<br />"; + output = output + missing_field_title + "<br />"; } if(data.cal == "true"){ - output = output + "Calendar<br />"; + output = output + missing_field_calendar + "<br />"; } if(data.from == "true"){ - output = output + "From Date<br />"; + output = output + missing_field_fromdate + "<br />"; } if(data.fromtime == "true"){ - output = output + "From Time<br />"; + output = output + missing_field_fromtime + "<br />"; } if(data.to == "true"){ - output = output + "To Date<br />"; + output = output + missing_field_todate + "<br />"; } if(data.totime == "true"){ - output = output + "To Time<br />"; + output = output + missing_field_totime + "<br />"; } if(data.endbeforestart == "true"){ - output = "The event ends before it starts!"; + output = output + missing_field_startsbeforeends + "!<br/>"; } if(data.dberror == "true"){ output = "There was a database fail!"; @@ -363,65 +102,54 @@ Calendar={ } else if(data.status == 'success'){ $('#event').dialog('destroy').remove(); - Calendar.UI.loadEvents(); + $('#calendar_holder').fullCalendar('refetchEvents'); } },"json"); }, - moveevent:function(eventid, newstartdate){ - $.post(OC.filePath('calendar', 'ajax', 'moveevent.php'), { id: eventid, newdate: newstartdate}, + moveEvent:function(event, dayDelta, minuteDelta, allDay, revertFunc){ + $('.tipsy').remove(); + $.post(OC.filePath('calendar', 'ajax', 'moveevent.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, allDay: allDay?1:0, lastmodified: event.lastmodified}, + function(data) { + if (data.status == 'success'){ + event.lastmodified = data.lastmodified; + console.log("Event moved successfully"); + }else{ + revertFunc(); + $('#calendar_holder').fullCalendar('refetchEvents'); + } + }); + }, + resizeEvent:function(event, dayDelta, minuteDelta, revertFunc){ + $('.tipsy').remove(); + $.post(OC.filePath('calendar', 'ajax', 'resizeevent.php'), { id: event.id, dayDelta: dayDelta, minuteDelta: minuteDelta, lastmodified: event.lastmodified}, function(data) { - console.log("Event moved successfully"); + if (data.status == 'success'){ + event.lastmodified = data.lastmodified; + console.log("Event resized successfully"); + }else{ + revertFunc(); + $('#calendar_holder').fullCalendar('refetchEvents'); + } }); }, showadvancedoptions:function(){ $("#advanced_options").css("display", "block"); $("#advanced_options_button").css("display", "none"); }, - createEventPopup:function(e){ - var popup = $(this).data('popup'); - if (!popup){ - var event = $(this).data('event_info'); - popup = $(document.createElement('div')); - $(this).data('popup', popup).append(popup); - popup.addClass('popup') - popup.addClass('event_popup') - .html(Calendar.UI.getEventPopupText(event)); - } - popup.css('left', -(popup.width() - $(this).width())/2) - .show(); - }, - hideEventPopup:function(){ - $(this).data('popup').hide(); - }, getEventPopupText:function(event){ - var startdate = this.formatDate(event.startdate) - var starttime = this.formatTime(event.startdate) - var enddate = this.formatDate(event.enddate) - var endtime = this.formatTime(event.enddate) - if (event.allday){ - var timespan = startdate; - if (event.startdate[2] != parseInt(event.enddate[2])-1){ - timespan += ' - ' + enddate; - } + if (event.allDay){ + var timespan = $.fullCalendar.formatDates(event.start, event.end, 'ddd d MMMM[ yyyy]{ -[ddd d] MMMM yyyy}', {monthNamesShort: monthNamesShort, monthNames: monthNames, dayNames: dayNames, dayNamesShort: dayNamesShort}); //t('calendar', "ddd d MMMM[ yyyy]{ -[ddd d] MMMM yyyy}") }else{ - var start = startdate + ' ' + starttime; - if (startdate == enddate){ - var end = endtime; - }else{ - var end = enddate + ' ' + endtime; - } - var timespan = start + ' - ' + end; + var timespan = $.fullCalendar.formatDates(event.start, event.end, 'ddd d MMMM[ yyyy] ' + defaulttime + '{ -[ ddd d MMMM yyyy]' + defaulttime + '}', {monthNamesShort: monthNamesShort, monthNames: monthNames, dayNames: dayNames, dayNamesShort: dayNamesShort}); //t('calendar', "ddd d MMMM[ yyyy] HH:mm{ -[ ddd d MMMM yyyy] HH:mm}") + // Tue 18 October 2011 08:00 - 16:00 } - return '<span class="timespan">' + timespan + '</span>' - + ' ' - + '<span class="summary">' + event.description + '</span>'; - }, - addDateInfo:function(selector, date){ - $(selector).data('date_info', date); - }, - switch2Today:function(){ - Calendar.Date.current = new Date(); - Calendar.UI.updateView(); + var html = + '<div class="summary">' + event.title + '</div>' + + '<div class="timespan">' + timespan + '</div>'; + if (event.description){ + html += '<div class="description">' + event.description + '</div>'; + } + return html; }, lockTime:function(){ if($('#allday_checkbox').is(':checked')) { @@ -441,54 +169,41 @@ Calendar={ $('#caldav_url').show(); $("#caldav_url_close").show(); }, - deleteCalendar:function(calid){ - var check = confirm("Do you really want to delete this calendar?"); - if(check == false){ - return false; - }else{ - $.post(OC.filePath('calendar', 'ajax', 'deletecalendar.php'), { calendarid: calid}, - function(data) { - Calendar.UI.loadEvents(); - $('#choosecalendar_dialog').dialog('destroy').remove(); - Calendar.UI.Calendar.overview(); - }); - } - }, - initscroll:function(){ + initScroll:function(){ if(window.addEventListener) - document.addEventListener('DOMMouseScroll', Calendar.UI.scrollcalendar); + document.addEventListener('DOMMouseScroll', Calendar.UI.scrollCalendar); //}else{ - document.onmousewheel = Calendar.UI.scrollcalendar; + document.onmousewheel = Calendar.UI.scrollCalendar; //} }, - scrollcalendar:function(event){ + scrollCalendar:function(event){ + $('.tipsy').remove(); var direction; if(event.detail){ if(event.detail < 0){ - direction = "top"; + direction = 'top'; }else{ - direction = "down"; + direction = 'down'; } } if (event.wheelDelta){ if(event.wheelDelta > 0){ - direction = "top"; + direction = 'top'; }else{ - direction = "down"; + direction = 'down'; } } - if(Calendar.UI.currentview == "onemonthview"){ - if(direction == "down"){ - Calendar.UI.updateDate("forward"); - }else{ - Calendar.UI.updateDate("backward"); - } - }else if(Calendar.UI.currentview == "oneweekview"){ - if(direction == "down"){ - Calendar.UI.updateDate("forward"); - }else{ - Calendar.UI.updateDate("backward"); - } + var scroll = $(document).scrollTop(), + doc_height = $(document).height(), + win_height = $(window).height(); + if(direction == 'down' && win_height == (doc_height - scroll)){ + $('#calendar_holder').fullCalendar('next'); + $(document).scrollTop(0); + event.preventDefault(); + }else if (direction == 'top' && scroll == 0) { + $('#calendar_holder').fullCalendar('prev'); + $(document).scrollTop(win_height); + event.preventDefault(); } }, Calendar:{ @@ -510,8 +225,14 @@ Calendar={ { $.post(OC.filePath('calendar', 'ajax', 'activation.php'), { calendarid: calendarid, active: checkbox.checked?1:0 }, function(data) { - checkbox.checked = data == 1; - Calendar.UI.loadEvents(); + if (data.status == 'success'){ + checkbox.checked = data.active == 1; + if (data.active == 1){ + $('#calendar_holder').fullCalendar('addEventSource', data.eventSource); + }else{ + $('#calendar_holder').fullCalendar('removeEventSource', data.eventSource.url); + } + } }); }, newCalendar:function(object){ @@ -526,6 +247,46 @@ Calendar={ function(){Calendar.UI.Calendar.colorPicker(this)}); $(object).closest('tr').after(tr).hide(); }, + deleteCalendar:function(calid){ + var check = confirm("Do you really want to delete this calendar?"); + if(check == false){ + return false; + }else{ + $.post(OC.filePath('calendar', 'ajax', 'deletecalendar.php'), { calendarid: calid}, + function(data) { + if (data.status == 'success'){ + var url = 'ajax/events.php?calendar_id='+calid; + $('#calendar_holder').fullCalendar('removeEventSource', url); + $('#choosecalendar_dialog').dialog('destroy').remove(); + Calendar.UI.Calendar.overview(); + } + }); + } + }, + submit:function(button, calendarid){ + var displayname = $("#displayname_"+calendarid).val(); + var active = $("#edit_active_"+calendarid+":checked").length; + var description = $("#description_"+calendarid).val(); + var calendarcolor = $("#calendarcolor_"+calendarid).val(); + + var url; + if (calendarid == 'new'){ + url = "ajax/createcalendar.php"; + }else{ + url = "ajax/updatecalendar.php"; + } + $.post(url, { id: calendarid, name: displayname, active: active, description: description, color: calendarcolor }, + function(data){ + if(data.status == 'success'){ + $(button).closest('tr').prev().html(data.page).show().next().remove(); + $('#calendar_holder').fullCalendar('removeEventSource', data.eventSource.url); + $('#calendar_holder').fullCalendar('addEventSource', data.eventSource); + } + }, 'json'); + }, + cancel:function(button, calendarid){ + $(button).closest('tr').prev().show().next().remove(); + }, colorPicker:function(container){ // based on jquery-colorpicker at jquery.webspirited.com var obj = $('.colorpicker', container); @@ -551,429 +312,233 @@ Calendar={ position: 'absolute', left: -10000 }); - }, - submit:function(button, calendarid){ - var displayname = $("#displayname_"+calendarid).val(); - var active = $("#edit_active_"+calendarid+":checked").length; - var description = $("#description_"+calendarid).val(); - var calendarcolor = $("#calendarcolor_"+calendarid).val(); + } + } + } +} +$.fullCalendar.views.list = ListView; +function ListView(element, calendar) { + var t = this; - var url; - if (calendarid == 'new'){ - url = "ajax/createcalendar.php"; - }else{ - url = "ajax/updatecalendar.php"; - } - $.post(url, { id: calendarid, name: displayname, active: active, description: description, color: calendarcolor }, - function(data){ - if(data.error == "true"){ - }else{ - $(button).closest('tr').prev().html(data.data).show().next().remove(); - Calendar.UI.loadEvents(); - } - }, 'json'); - }, - cancel:function(button, calendarid){ - $(button).closest('tr').prev().show().next().remove(); - }, - },/* - OneDay:{ - forward:function(){ - Calendar.Date.forward_day(); - }, - backward:function(){ - Calendar.Date.backward_day(); - }, - removeEvents:function(){ - $("#onedayview .calendar_row").empty(); - }, - renderCal:function(){ - $("#datecontrol_date").val(Calendar.UI.formatDayShort() + Calendar.space + Calendar.Date.current.getDate() + Calendar.space + Calendar.UI.formatMonthShort() + Calendar.space + Calendar.Date.current.getFullYear()); - $("#onedayview_today").html(Calendar.UI.formatDayLong() + Calendar.space + Calendar.Date.current.getDate() + Calendar.space + Calendar.UI.formatMonthShort()); - Calendar.UI.addDateInfo('#onedayview_today', new Date(Calendar.Date.current)); - }, - showEvents:function(){ - Calendar.UI.createEventsForDate(Calendar.Date.current, 0); - }, - getEventContainer:function(week, weekday, when){ - return $("#onedayview ." + when); - }, - createEventLabel:function(event){ - var time = ''; - if (!event['allday']){ - time = '<strong>' + Calendar.UI.formatTime(event['startdate']) + ' - ' + Calendar.UI.formatTime(event['enddate']) + '</strong> '; - } - return $(document.createElement('p')) - .html(time + event['description']) - }, - },*/ - OneWeek:{ - forward:function(){ - Calendar.Date.forward_week(); - }, - backward:function(){ - Calendar.Date.backward_week(); - }, - removeEvents:function(){ - for( i = 0; i <= 6; i++) { - $("#oneweekview ." + Calendar.UI.weekdays[i]).empty(); - } - $("#oneweekview .thisday").removeClass("thisday"); - }, - renderCal:function(){ - $("#datecontrol_date").val(Calendar.UI.cw_label + ": " + Calendar.Date.calw()); - var dates = this.generateDates(); - var today = new Date(); - for(var i = 0; i <= 6; i++){ - $("#oneweekview th." + Calendar.UI.weekdays[i]).html(Calendar.UI.formatDayShort((i+Calendar.firstdayofweek)%7) + Calendar.space + dates[i].getDate() + Calendar.space + Calendar.UI.formatMonthShort(dates[i].getMonth())); - $("#oneweekview td." + Calendar.UI.weekdays[i] + ".allday").attr('title', dates[i].getDate() + "." + String(parseInt(dates[i].getMonth()) + 1) + "." + dates[i].getFullYear() + "-" + "allday"); - $("#oneweekview td." + Calendar.UI.weekdays[i] + ".allday").droppable({ - drop: function() { - Calendar.UI.moveevent(Calendar.UI.drageventid, this.title); - Calendar.UI.loadEvents(); - } - }); - for(var ii = 0;ii <= 23; ii++){ - $("#oneweekview td." + Calendar.UI.weekdays[i] + "." + String(ii)).attr('title', dates[i].getDate() + "." + String(parseInt(dates[i].getMonth()) + 1) + "." + dates[i].getFullYear() + "-" + String(ii) + ":00"); - $("#oneweekview td." + Calendar.UI.weekdays[i] + "." + String(ii)).droppable({ - drop: function() { - Calendar.UI.moveevent(Calendar.UI.drageventid, this.title); - Calendar.UI.loadEvents(); - } - }); - } - if(dates[i].getDate() == today.getDate() && dates[i].getMonth() == today.getMonth() && dates[i].getFullYear() == today.getFullYear()){ - $("#oneweekview ." + Calendar.UI.weekdays[i]).addClass("thisday"); - } - Calendar.UI.addDateInfo('#oneweekview th.' + Calendar.UI.weekdays[i], dates[i]); - } - }, - showEvents:function(){ - var dates = this.generateDates(); - for(var weekday = 0; weekday <= 6; weekday++) { - Calendar.UI.createEventsForDate(dates[weekday], 0); - } - }, - getEventContainer:function(week, weekday, when){ - return $("#oneweekview ." + Calendar.UI.weekdays[weekday] + "." + when); - }, - createEventLabel:function(event){ - var time = ''; - if (!event['allday']){ - time = '<strong>' + Calendar.UI.formatTime(event['startdate']) + ' - ' + Calendar.UI.formatTime(event['enddate']) + '</strong> '; - } - return $(document.createElement('p')) - .html(time + event['description']) - }, - generateDates:function(){ - var dates = new Array(); - var date = new Date(Calendar.Date.current) - var dayofweek = date.getDay(); - if(dayofweek == 0) { - dayofweek = 7; - } - if(Calendar.firstdayofweek > dayofweek){ - date.setDate(date.getDate() - dayofweek + Calendar.firstdayofweek - 7); - }else{ - date.setDate(date.getDate() - dayofweek + Calendar.firstdayofweek); - } - for(var i = 0; i <= 6; i++) { - dates[i] = new Date(date) - date.setDate(date.getDate() + 1); - } - return dates; - }, - },/* - FourWeeks:{ - forward:function(){ - Calendar.Date.forward_week(); - }, - backward:function(){ - Calendar.Date.backward_week(); - }, - removeEvents:function(){ - $('#fourweeksview .day.thisday').removeClass('thisday'); - $('#fourweeksview .day .events').empty(); - }, - renderCal:function(){ - var calw1 = Calendar.Date.calw(); - var calw2 = calw1 + 1; - var calw3 = calw1 + 2; - var calw4 = calw1 + 3; - switch(calw1) { - case 50: - calw4 = 1; - break; - case 51: - calw3 = 1; - calw4 = 2; - break; - case 52: - calw2 = 1; - calw3 = 2; - calw4 = 3; - break; - } - var calwplusfour = calw4; - var dates = this.generateDates(); - var week = 1; - var weekday = 0; - var today = new Date(); - for(var i = 0; i <= 27; i++){ - var dayofmonth = dates[i].getDate(); - var month = dates[i].getMonth(); - var year = dates[i].getFullYear(); - $("#fourweeksview .week_" + week + " ." + Calendar.UI.weekdays[weekday] + " .dateinfo").html(dayofmonth + Calendar.space + Calendar.UI.formatMonthShort(month)); - if(dayofmonth == today.getDate() && month == today.getMonth() && year == today.getFullYear()){ - $("#fourweeksview .week_" + week + " ." + Calendar.UI.weekdays[weekday]).addClass('thisday'); - } - Calendar.UI.addDateInfo('#fourweeksview .week_' + week + ' .' + Calendar.UI.weekdays[weekday], dates[i]); - if(weekday == 6){ - weekday = 0; - week++; - }else{ - weekday++; - } - } - $("#fourweeksview .week_1 .calw").html(calw1); - $("#fourweeksview .week_2 .calw").html(calw2); - $("#fourweeksview .week_3 .calw").html(calw3); - $("#fourweeksview .week_4 .calw").html(calw4); - $("#datecontrol_date").val(Calendar.UI.cws_label + ": " + Calendar.Date.calw() + " - " + calwplusfour); - }, - showEvents:function(){ - var dates = this.generateDates(); - var weekdaynum = 0; - var weeknum = 1; - for(var i = 0; i <= 27; i++) { - Calendar.UI.createEventsForDate(dates[i], weeknum); - if(weekdaynum == 6){ - weekdaynum = 0; - weeknum++; - }else{ - weekdaynum++; - } - } - }, - getEventContainer:function(week, weekday, when){ - return $("#fourweeksview .week_" + week + " .day." + Calendar.UI.weekdays[weekday] + " .events"); - }, - createEventLabel:function(event){ - var time = ''; - if (!event['allday']){ - time = '<strong>' + Calendar.UI.formatTime(event['startdate']) + '</strong> '; - } - return $(document.createElement('p')) - .html(time + event['description']) - }, - generateDates:function(){ - var dates = new Array(); - var date = new Date(Calendar.Date.current) - var dayofweek = date.getDay(); - if(dayofweek == 0) { - dayofweek = 7; - } - date.setDate(date.getDate() - dayofweek + 1); - for(var i = 0; i <= 27; i++) { - dates[i] = new Date(date) - date.setDate(date.getDate() + 1); - } - return dates; - }, - },*/ - OneMonth:{ - forward:function(){ - Calendar.Date.forward_month(); - }, - backward:function(){ - Calendar.Date.backward_month(); - }, - removeEvents:function(){ - $('#onemonthview .day.thisday').removeClass('thisday'); - $('#onemonthview .day .events').empty(); - }, - renderCal:function(){ - $("#datecontrol_date").val(Calendar.UI.formatMonthLong() + Calendar.space + Calendar.Date.current.getFullYear()); - var cal = Calendar.Date.getnumberofdays(Calendar.Date.current.getFullYear()); - var monthview_dayofweek = Calendar.Date.current.getDay(); - var monthview_dayofmonth = Calendar.Date.current.getDate(); - for(var i = monthview_dayofmonth; i > 1; i--) { - if(monthview_dayofweek == 0) { - monthview_dayofweek = 6; - } else { - monthview_dayofweek--; - } - } - $("#onemonthview .week_5").hide(); - $("#onemonthview .week_6").hide(); - this.rows = monthview_dayofweek + cal[Calendar.Date.current.getMonth()]; - this.rows = this.rows / 7; - this.rows = Math.ceil(this.rows); - var dates = this.generateDates(); - var week = 1; - var weekday = 0; - var today = new Date(); - for(var i = 0; i <= 41; i++){ - var dayofmonth = dates[i].getDate(); - var month = dates[i].getMonth(); - var year = dates[i].getFullYear(); - $("#onemonthview .week_" + week + " ." + Calendar.UI.weekdays[weekday] + " .dateinfo").html(dayofmonth + Calendar.space + Calendar.UI.formatMonthShort(month)); - $("#onemonthview .week_" + week + " ." + Calendar.UI.weekdays[weekday]).attr('title', dayofmonth + "." + String(parseInt(month) + 1) + "." + year); - $("#onemonthview .week_" + week + " ." + Calendar.UI.weekdays[weekday]).droppable({ - drop: function() { - Calendar.UI.moveevent(Calendar.UI.drageventid, this.title); - Calendar.UI.loadEvents(); - } - }); - if(dayofmonth == today.getDate() && month == today.getMonth() && year == today.getFullYear()){ - $("#onemonthview .week_" + week + " ." + Calendar.UI.weekdays[weekday]).addClass('thisday'); - } - Calendar.UI.addDateInfo('#onemonthview .week_' + week + ' .' + Calendar.UI.weekdays[weekday], dates[i]); - if(weekday == 6){ - weekday = 0; - week++; - }else{ - weekday++; - } - } - if(this.rows == 4){ - for(var i = 1;i <= 6;i++){ - $("#onemonthview .week_" + String(i)).height("23%"); - } - } - if(this.rows == 5) { - $("#onemonthview .week_5").show(); - for(var i = 1;i <= 6;i++){ - $("#onemonthview .week_" + String(i)).height("18%"); - } - } - if(this.rows == 6) { - $("#onemonthview .week_5").show(); - $("#onemonthview .week_6").show(); - for(var i = 1;i <= 6;i++){ - $("#onemonthview .week_" + String(i)).height("14%"); - } - } - }, - showEvents:function(){ - var dates = this.generateDates(); - var weekdaynum = 0; - var weeknum = 1; - for(var i = 0; i <= 41; i++) { - Calendar.UI.createEventsForDate(dates[i], weeknum); - if(weekdaynum == 6){ - weekdaynum = 0; - weeknum++; - }else{ - weekdaynum++; - } - } - }, - getEventContainer:function(week, weekday, when){ - return $("#onemonthview .week_" + week + " .day." + Calendar.UI.weekdays[weekday] + " .events"); - }, - createEventLabel:function(event){ - var time = ''; - if (!event['allday']){ - time = '<strong>' + Calendar.UI.formatTime(event['startdate']) + '</strong> '; - } - return $(document.createElement('p')) - .html(time + event['description']) - }, - generateDates:function(){ - var dates = new Array(); - var date = new Date(Calendar.Date.current) - date.setDate(1); - var dayofweek = date.getDay(); - if(dayofweek == 0) { - dayofweek = 7; - this.rows++; - } - if(Calendar.firstdayofweek > dayofweek){ - date.setDate(date.getDate() - dayofweek + Calendar.firstdayofweek - 7); - }else{ - date.setDate(date.getDate() - dayofweek + Calendar.firstdayofweek); - } - for(var i = 0; i <= 41; i++) { - dates[i] = new Date(date) - date.setDate(date.getDate() + 1); + // imports + jQuery.fullCalendar.views.month.call(t, element, calendar); + var opt = t.opt; + var trigger = t.trigger; + var eventElementHandlers = t.eventElementHandlers; + var reportEventElement = t.reportEventElement; + var formatDate = calendar.formatDate; + var formatDates = calendar.formatDates; + var addDays = $.fullCalendar.addDays; + var cloneDate = $.fullCalendar.cloneDate; + function skipWeekend(date, inc, excl) { + inc = inc || 1; + while (!date.getDay() || (excl && date.getDay()==1 || !excl && date.getDay()==6)) { + addDays(date, inc); + } + return date; + } + + // overrides + t.name='list'; + t.render=render; + t.renderEvents=renderEvents; + t.setHeight=setHeight; + t.setWidth=setWidth; + t.clearEvents=clearEvents; + + function setHeight(height, dateChanged) { + } + + function setWidth(width) { + } + + function clearEvents() { + this.reportEventClear(); + } + + // main + function sortEvent(a, b) { + return a.start - b.start; + } + + function render(date, delta) { + if (!t.start){ + t.start = addDays(cloneDate(date, true), -7); + t.end = addDays(cloneDate(date, true), 7); + } + if (delta) { + if (delta < 0){ + addDays(t.start, -7); + if (!opt('weekends')) { + skipWeekend(t.start, delta < 0 ? -1 : 1); } - return dates; - }, - }, - List:{ - removeEvents:function(){ - this.eventContainer = $('#listview #events').empty(); - this.startdate = new Date(); - this.enddate = new Date(); - this.enddate.setDate(this.enddate.getDate()); - }, - renderCal:function(){ - var today = new Date(); - $('#datecontrol_date').val(this.formatDate(Calendar.Date.current)); - }, - showEvents:function(){ - this.renderMoreBefore(); - this.renderMoreAfter(); - }, - formatDate:function(date){ - return Calendar.UI.formatDayShort(date.getDay()) - + Calendar.space - + date.getDate() - + Calendar.space - + Calendar.UI.formatMonthShort(date.getMonth()) - + Calendar.space - + date.getFullYear(); - }, - createDay:function(date) { - return $(document.createElement('div')) - .addClass('day') - .html(this.formatDate(date)); - }, - renderMoreBefore:function(){ - var date = Calendar.UI.List.startdate; - for(var i = 0; i <= 13; i++) { - if (Calendar.UI.getEventsForDate(date)) { - Calendar.UI.List.dayContainer=Calendar.UI.List.createDay(date); - Calendar.UI.createEventsForDate(date, 0); - Calendar.UI.List.eventContainer.prepend(Calendar.UI.List.dayContainer); - } - date.setDate(date.getDate()-1); + }else{ + addDays(t.end, 7); + if (!opt('weekends')) { + skipWeekend(t.end, delta < 0 ? -1 : 1); } - var start = Calendar.UI.List.formatDate(date); - $('#listview #more_before').html(String(Calendar.UI.more_before).replace('{startdate}', start)); - }, - renderMoreAfter:function(){ - var date = Calendar.UI.List.enddate; - for(var i = 0; i <= 13; i++) { - if (Calendar.UI.getEventsForDate(date)) { - Calendar.UI.List.dayContainer=Calendar.UI.List.createDay(date); - Calendar.UI.createEventsForDate(date, 0); - Calendar.UI.List.eventContainer.append(Calendar.UI.List.dayContainer); - } - date.setDate(date.getDate()+1); + } + } + t.title = formatDates( + t.start, + t.end, + opt('titleFormat', 'week') + ); + t.visStart = cloneDate(t.start); + t.visEnd = cloneDate(t.end); + } + + function eventsOfThisDay(events, theDate) { + var start = cloneDate(theDate, true); + var end = addDays(cloneDate(start), 1); + var retArr = new Array(); + for (i in events) { + var event_end = t.eventEnd(events[i]); + if (events[i].start < end && event_end >= start) { + retArr.push(events[i]); + } + } + return retArr; + } + + function renderEvent(event) { + if (event.allDay) { //all day event + var time = opt('allDayText'); + } + else { + var time = formatDates(event.start, event.end, opt('timeFormat', 'agenda')); + } + var classes = ['fc-event', 'fc-list-event']; + classes = classes.concat(event.className); + if (event.source) { + classes = classes.concat(event.source.className || []); + } + var html = '<tr>' + + '<td> </td>' + + '<td class="fc-list-time">' + + time + + '</td>' + + '<td> </td>' + + '<td class="fc-list-event">' + + '<span id="list' + event.id + '"' + + ' class="' + classes.join(' ') + '"' + + '>' + + '<span class="fc-event-title">' + + event.title + + '</span>' + + '</span>' + + '</td>' + + '</tr>'; + return html; + } + + function renderDay(date, events) { + var dayRows = $('<tr>' + + '<td colspan="4" class="fc-list-date">' + + '<span>' + + formatDate(date, opt('titleFormat', 'day')) + + '</span>' + + '</td>' + + '</tr>'); + for (i in events) { + var event = events[i]; + var eventElement = $(renderEvent(event)); + triggerRes = trigger('eventRender', event, event, eventElement); + if (triggerRes === false) { + eventElement.remove(); + }else{ + if (triggerRes && triggerRes !== true) { + eventElement.remove(); + eventElement = $(triggerRes); } - var end = Calendar.UI.List.formatDate(date); - $('#listview #more_after').html(String(Calendar.UI.more_after).replace('{enddate}', end)); - }, - getEventContainer:function(week, weekday, when){ - return this.dayContainer; - }, - createEventLabel:function(event){ - var time = ''; - if (!event['allday']){ - time = Calendar.UI.formatTime(event['startdate']) + ' - ' + Calendar.UI.formatTime(event['enddate']) + ' '; + $.merge(dayRows, eventElement); + eventElementHandlers(event, eventElement); + reportEventElement(event, eventElement); + } + } + return dayRows; + } + + function renderEvents(events, modifiedEventId) { + events = events.sort(sortEvent); + + var table = $('<table class="fc-list-table"></table>'); + var total = events.length; + if (total > 0) { + var date = cloneDate(t.visStart); + while (date <= t.visEnd) { + var dayEvents = eventsOfThisDay(events, date); + if (dayEvents.length > 0) { + table.append(renderDay(date, dayEvents)); } - return $(document.createElement('p')) - .html(time + event['description']) - }, + date=addDays(date, 1); + } } + + this.element.html(table); } } $(document).ready(function(){ - $('#listview #more_before').click(Calendar.UI.List.renderMoreBefore); - $('#listview #more_after').click(Calendar.UI.List.renderMoreAfter); - Calendar.UI.initscroll(); + Calendar.UI.initScroll(); + $('#calendar_holder').fullCalendar({ + header: false, + firstDay: 1, + editable: true, + defaultView: defaultView, + timeFormat: { + agenda: agendatime, + '': defaulttime + }, + titleFormat: { + list: 'yyyy/MMM/d dddd' + }, + axisFormat: defaulttime, + monthNames: monthNames, + monthNamesShort: monthNamesShort, + dayNames: dayNames, + dayNamesShort: dayNamesShort, + allDayText: allDayText, + viewDisplay: function(view) { + $('#datecontrol_date').html(view.title); + $.get(OC.filePath('calendar', 'ajax', 'changeview.php') + "?v="+view.name); + }, + selectable: true, + selectHelper: true, + select: Calendar.UI.newEvent, + eventClick: Calendar.UI.editEvent, + eventDrop: Calendar.UI.moveEvent, + eventResize: Calendar.UI.resizeEvent, + eventRender: function(event, element) { + element.tipsy({ + className: 'tipsy-event', + opacity: 0.9, + gravity:$.fn.tipsy.autoBounds(150, 's'), + fade:true, + delayIn: 400, + html:true, + title:function() { + return Calendar.UI.getEventPopupText(event); + } + }); + }, + eventSources: eventSources + }); + $('#oneweekview_radio').click(function(){ + $('#calendar_holder').fullCalendar('changeView', 'agendaWeek'); + }); + $('#onemonthview_radio').click(function(){ + $('#calendar_holder').fullCalendar('changeView', 'month'); + }); + $('#listview_radio').click(function(){ + $('#calendar_holder').fullCalendar('changeView', 'list'); + }); + $('#today_input').click(function(){ + $('#calendar_holder').fullCalendar('today'); + }); + $('#datecontrol_left').click(function(){ + $('#calendar_holder').fullCalendar('prev'); + }); + $('#datecontrol_right').click(function(){ + $('#calendar_holder').fullCalendar('next'); + }); }); -//event vars -Calendar.UI.loadEvents(); diff --git a/calendar/js/geo.js b/calendar/js/geo.js new file mode 100755 index 000000000..acea17c02 --- /dev/null +++ b/calendar/js/geo.js @@ -0,0 +1,20 @@ +/** + * 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. + */ +if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition(function(position) { + $.getJSON(OC.filePath('calendar', 'ajax', 'guesstimezone.php?lat=' + position.coords.latitude + '&long=' + position.coords.longitude + ''), + function(data){ + if (data.status == 'success'){ + $('#notification').html(data.message); + $('#notification').slideDown(); + window.setTimeout(function(){$('#notification').slideUp();}, 5000); + }else{ + console.log('Can\'t set new timezone.'); + } + }); + }); +}
\ No newline at end of file diff --git a/calendar/l10n/xgettextfiles b/calendar/l10n/xgettextfiles index 4cc636436..27b8e4571 100644 --- a/calendar/l10n/xgettextfiles +++ b/calendar/l10n/xgettextfiles @@ -1,7 +1,11 @@ ../appinfo/app.php +../lib/object.php ../templates/calendar.php +../templates/part.choosecalendar.php +../templates/part.choosecalendar.rowfields.php +../templates/part.editcalendar.php ../templates/part.editevent.php -../templates/part.eventinfo.php +../templates/part.eventform.php +../templates/part.import.php ../templates/part.newevent.php -../templates/part.choosecalendar.php -../js/calendar.js +../templates/settings.php
\ No newline at end of file diff --git a/calendar/lib/calendar.php b/calendar/lib/calendar.php index f6d40aa53..3db439809 100644 --- a/calendar/lib/calendar.php +++ b/calendar/lib/calendar.php @@ -240,4 +240,12 @@ class OC_Calendar_Calendar{ 'ecc255', // dark yellow ); } + public static function getEventSourceInfo($calendar){ + return array( + 'url' => 'ajax/events.php?calendar_id='.$calendar['id'], + 'backgroundColor' => '#'.$calendar['calendarcolor'], + 'borderColor' => '#888', + 'textColor' => 'black', + ); + } } diff --git a/calendar/lib/object.php b/calendar/lib/object.php index 33871cd31..58d46ce6a 100644 --- a/calendar/lib/object.php +++ b/calendar/lib/object.php @@ -31,6 +31,34 @@ class OC_Calendar_Object{ } /** + * @brief Returns all objects of a calendar between $start and $end + * @param integer $id + * @param DateTime $start + * @param DateTime $end + * @return array + * + * The objects are associative arrays. You'll find the original vObject + * in ['calendardata'] + */ + public static function allInPeriod($id, $start, $end){ + $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*calendar_objects WHERE calendarid = ?' + .' AND ((startdate >= ? AND startdate <= ? AND repeating = 0)' + .' OR (startdate <= ? AND repeating = 1))' ); + $start = self::getUTCforMDB($start); + $end = self::getUTCforMDB($end); + $result = $stmt->execute(array($id, + $start, $end, + $end)); + + $calendarobjects = array(); + while( $row = $result->fetchRow()){ + $calendarobjects[] = $row; + } + + return $calendarobjects; + } + + /** * @brief Returns an object * @param integer $id * @return associative array @@ -279,6 +307,7 @@ class OC_Calendar_Object{ */ public static function parse($data){ try { + Sabre_VObject_Reader::$elementMap['LAST-MODIFIED'] = 'Sabre_VObject_Element_DateTime'; $calendar = Sabre_VObject_Reader::read($data); return $calendar; } catch (Exception $e) { @@ -398,7 +427,7 @@ class OC_Calendar_Object{ $errarr['endbeforestart'] = 'true'; $errnum++; } - if($fromday == $today && $frommonth == $tomonth && $fromyear == $toyear){ + if(!$allday && $fromday == $today && $frommonth == $tomonth && $fromyear == $toyear){ list($tohours, $tominutes) = explode(':', $request['totime']); list($fromhours, $fromminutes) = explode(':', $request['fromtime']); if($tohours < $fromhours){ @@ -453,9 +482,11 @@ class OC_Calendar_Object{ $categories = isset($request["categories"]) ? $request["categories"] : null; $allday = isset($request["allday"]); $from = $request["from"]; - $fromtime = $request["fromtime"]; $to = $request["to"]; - $totime = $request["totime"]; + if (!$allday){ + $fromtime = $request['fromtime']; + $totime = $request['totime']; + } $description = $request["description"]; //$repeat = $request["repeat"]; /*switch($request["repeatfreq"]){ diff --git a/calendar/lib/search.php b/calendar/lib/search.php new file mode 100644 index 000000000..41faf49a5 --- /dev/null +++ b/calendar/lib/search.php @@ -0,0 +1,26 @@ +<?php +class OC_Search_Provider_Calendar extends OC_Search_Provider{ + function search($query){ + $calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1); + if(count($calendars)==0 || !OC_App::isEnabled('calendar')){ + //return false; + } + $results=array(); + $searchquery=array(); + if(substr_count($query, ' ') > 0){ + $searchquery = explode(' ', $query); + }else{ + $searchquery[] = $query; + } + foreach($calendars as $calendar){ + $objects = OC_Calendar_Object::all($calendar['id']); + foreach($objects as $object){ + if(substr_count(strtolower($object['summary']), strtolower($query)) > 0){//$name,$text,$link,$type + $results[]=new OC_Search_Result($object['summary'],'','#','Cal.'); + } + } + } + return $results; + } +} +new OC_Search_Provider_Calendar();
\ No newline at end of file diff --git a/calendar/templates/calendar.php b/calendar/templates/calendar.php index 317bb17dd..2003b7efc 100644..100755 --- a/calendar/templates/calendar.php +++ b/calendar/templates/calendar.php @@ -1,217 +1,50 @@ -<?php -$hours24 = array( - 'allday' => $l->t('All day'), - 0 => '0', - 1 => '1', - 2 => '2', - 3 => '3', - 4 => '4', - 5 => '5', - 6 => '6', - 7 => '7', - 8 => '8', - 9 => '9', - 10 => '10', - 11 => '11', - 12 => '12', - 13 => '13', - 14 => '14', - 15 => '15', - 16 => '16', - 17 => '17', - 18 => '18', - 19 => '19', - 20 => '20', - 21 => '21', - 22 => '22', - 23 => '23', -); -$hoursampm = array( - 'allday' => $l->t('All day'), - 0 => '12 a.m.', - 1 => '1 a.m.', - 2 => '2 a.m.', - 3 => '3 a.m.', - 4 => '4 a.m.', - 5 => '5 a.m.', - 6 => '6 a.m.', - 7 => '7 a.m.', - 8 => '8 a.m.', - 9 => '9 a.m.', - 10 => '10 a.m.', - 11 => '11 a.m.', - 12 => '12 p.m.', - 13 => '1 p.m.', - 14 => '2 p.m.', - 15 => '3 p.m.', - 16 => '4 p.m.', - 17 => '5 p.m.', - 18 => '6 p.m.', - 19 => '7 p.m.', - 20 => '8 p.m.', - 21 => '9 p.m.', - 22 => '10 p.m.', - 23 => '11 p.m.', -); -if(OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'timeformat', "24") == "24"){ - $hours = $hours24; -}else{ - $hours = $hoursampm; -} -$weekdaynames = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); -$dayforgenerator = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'firstdayofweek', "1"); -$weekdays = array(); -for($i = 0;$i <= 6; $i++){ - $weekdays[$i] = $weekdaynames[$dayforgenerator]; - if($dayforgenerator == 6){ - $dayforgenerator = 0; - }else{ - $dayforgenerator++; - } -} -$weekendjson = OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'weekend', '{"Monday":"false","Tuesday":"false","Wednesday":"false","Thursday":"false","Friday":"false","Saturday":"true","Sunday":"true"}'); -$weekend = json_decode($weekendjson, true); -$weekenddays = array("sunday"=>$weekend["Sunday"], "monday"=>$weekend["Monday"], "tuesday"=>$weekend["Tuesday"], "wednesday"=>$weekend["Wednesday"], "thursday"=>$weekend["Thursday"], "friday"=>$weekend["Friday"], "saturday"=>$weekend["Saturday"]); -?> - <script type="text/javascript"> - <?php - echo "var weekdays = new Array('".$weekdays[0]."','".$weekdays[1]."','".$weekdays[2]."','".$weekdays[3]."','".$weekdays[4]."','".$weekdays[5]."','".$weekdays[6]."');\n"; - ?> - Calendar.UI.weekdays = weekdays; - Calendar.UI.daylong = new Array("<?php echo $l -> t("Sunday");?>", "<?php echo $l -> t("Monday");?>", "<?php echo $l -> t("Tuesday");?>", "<?php echo $l -> t("Wednesday");?>", "<?php echo $l -> t("Thursday");?>", "<?php echo $l -> t("Friday");?>", "<?php echo $l -> t("Saturday");?>"); - Calendar.UI.dayshort = new Array("<?php echo $l -> t("Sun.");?>", "<?php echo $l -> t("Mon.");?>", "<?php echo $l -> t("Tue.");?>", "<?php echo $l -> t("Wed.");?>", "<?php echo $l -> t("Thu.");?>", "<?php echo $l -> t("Fri.");?>", "<?php echo $l -> t("Sat.");?>"); - Calendar.UI.monthlong = new Array("<?php echo $l -> t("January");?>", "<?php echo $l -> t("February");?>", "<?php echo $l -> t("March");?>", "<?php echo $l -> t("April");?>", "<?php echo $l -> t("May");?>", "<?php echo $l -> t("June");?>", "<?php echo $l -> t("July");?>", "<?php echo $l -> t("August");?>", "<?php echo $l -> t("September");?>", "<?php echo $l -> t("October");?>", "<?php echo $l -> t("November");?>", "<?php echo $l -> t("December");?>"); - Calendar.UI.monthshort = new Array("<?php echo $l -> t("Jan.");?>", "<?php echo $l -> t("Feb.");?>", "<?php echo $l -> t("Mar.");?>", "<?php echo $l -> t("Apr.");?>", "<?php echo $l -> t("May.");?>", "<?php echo $l -> t("Jun.");?>", "<?php echo $l -> t("Jul.");?>", "<?php echo $l -> t("Aug.");?>", "<?php echo $l -> t("Sep.");?>", "<?php echo $l -> t("Oct.");?>", "<?php echo $l -> t("Nov.");?>", "<?php echo $l -> t("Dec.");?>"); - Calendar.UI.cw_label = "<?php echo $l->t("Week");?>"; - Calendar.UI.cws_label = "<?php echo $l->t("Weeks");?>"; - Calendar.UI.more_before = String('<?php echo $l->t('More before {startdate}') ?>'); - Calendar.UI.more_after = String('<?php echo $l->t('More after {enddate}') ?>'); - Calendar.firstdayofweek = parseInt("<?php echo OC_Preferences::getValue( OC_User::getUser(), 'calendar', 'firstdayofweek', "1"); ?>"); - //use last view as default on the next - Calendar.UI.setCurrentView("<?php echo OC_Preferences::getValue(OC_USER::getUser(), "calendar", "currentview", "onemonthview") ?>"); - var totalurl = "<?php echo OC_Helper::linkTo('calendar', 'caldav.php', null, true) . '/calendars'; ?>"; + <script type='text/javascript'> + var defaultView = '<?php echo OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'month') ?>'; + var eventSources = <?php echo json_encode($_['eventSources']) ?>; + var dayNames = <?php echo json_encode($l->tA(array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'))) ?>; + var dayNamesShort = <?php echo json_encode($l->tA(array('Sun.', 'Mon.', 'Tue.', 'Wed.', 'Thu.', 'Fri.', 'Sat.'))) ?>; + var monthNames = <?php echo json_encode($l->tA(array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'))) ?>; + var monthNamesShort = <?php echo json_encode($l->tA(array('Jan.', 'Feb.', 'Mar.', 'Apr.', 'May.', 'Jun.', 'Jul.', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.'))) ?>; + var agendatime = '<?php echo ((int) OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timeformat', '24') == 24 ? 'HH:mm' : 'hh:mm tt'); ?>{ - <?php echo ((int) OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timeformat', '24') == 24 ? 'HH:mm' : 'hh:mm tt'); ?>}'; + var defaulttime = '<?php echo ((int) OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timeformat', '24') == 24 ? 'HH:mm' : 'hh:mm tt'); ?>'; + var allDayText = '<?php echo $l->t('All day') ?>'; + var missing_field = '<?php echo $l->t('Missing fields') ?>'; + var missing_field_title = '<?php echo $l->t('Title') ?>'; + var missing_field_calendar = '<?php echo $l->t('Calendar') ?>'; + var missing_field_fromdate = '<?php echo $l->t('From Date') ?>'; + var missing_field_fromtime = '<?php echo $l->t('From Time') ?>'; + var missing_field_todate = '<?php echo $l->t('To Date') ?>'; + var missing_field_totime = '<?php echo $l->t('To Time') ?>'; + var missing_field_startsbeforeends = '<?php echo $l->t('The event ends before it starts') ?>'; + var missing_field_dberror = '<?php echo $l->t('There was a database fail') ?>'; + var totalurl = '<?php echo OC_Helper::linkTo('apps/calendar', 'caldav.php', null, true); ?>/calendars'; </script> - <div id="sysbox"></div> <div id="controls"> <div> <form> <div id="view"> - <!-- <input type="button" value="1 <?php echo $l->t('Day');?>" id="onedayview_radio" onclick="Calendar.UI.setCurrentView('onedayview');"/> --> - <input type="button" value="<?php echo $l->t('Week');?>" id="oneweekview_radio" onclick="Calendar.UI.setCurrentView('oneweekview');"/> - <!-- <input type="button" value="4 <?php echo $l->t('Weeks');?>" id="fourweeksview_radio" onclick="Calendar.UI.setCurrentView('fourweeksview');"/> --> - <input type="button" value="<?php echo $l->t('Month');?>" id="onemonthview_radio" onclick="Calendar.UI.setCurrentView('onemonthview');"/> - <input type="button" value="<?php echo $l->t('List');?>" id="listview_radio" onclick="Calendar.UI.setCurrentView('listview');"/> + <input type="button" value="<?php echo $l->t('Week');?>" id="oneweekview_radio"/> + <input type="button" value="<?php echo $l->t('Month');?>" id="onemonthview_radio"/> + <input type="button" value="<?php echo $l->t('List');?>" id="listview_radio"/> </div> </form> <form> <div id="choosecalendar"> - <input type="button" id="today_input" value="<?php echo $l->t("Today");?>" onclick="Calendar.UI.switch2Today();"/> + <input type="button" id="today_input" value="<?php echo $l->t("Today");?>"/> <input type="button" id="choosecalendar_input" value="<?php echo $l->t("Calendars");?>" onclick="Calendar.UI.Calendar.overview();" /> </div> </form> <form> <div id="datecontrol"> - <input type="button" value=" < " id="datecontrol_left" onclick="Calendar.UI.updateDate('backward');"/> - <input id="datecontrol_date" type="button" value=""/> - <input type="button" value=" > " id="datecontrol_right" onclick="Calendar.UI.updateDate('forward');"/> + <input type="button" value=" < " id="datecontrol_left"/> + <span class="button" id="datecontrol_date"></span> + <input type="button" value=" > " id="datecontrol_right"/> </div> </form> </div> </div> + <div id="notification" style="display:none;"></div> <div id="calendar_holder"> - <div id="onedayview"> - <table> - <thead> - <tr> - <th class="calendar_time"><?php echo $l->t("Time");?></th> - <th id="onedayview_today" class="calendar_row" onclick="Calendar.UI.newEvent('#onedayview_today');"></th> - </tr> - </thead> - <tbody> -<?php foreach($hours as $time => $time_label): ?> - <tr> - <td class="calendar_time"><?php echo $time_label ?></td> - <td class="calendar_row <?php echo $time ?>" onclick="Calendar.UI.newEvent('#onedayview_today', '<?php echo $time ?>');"></td> - </tr> -<?php endforeach; ?> - </tbody> - </table> - </div> - <div id="oneweekview"> - <table> - <thead> - <tr> - <th class="calendar_time"><?php echo $l->t("Time");?></th> -<?php foreach($weekdays as $weekdaynr => $weekday): ?> - <th class="calendar_row <?php echo $weekday ?> <?php echo $weekenddays[$weekday] == "true" ? 'weekend_thead' : '' ?>" onclick="Calendar.UI.newEvent('#oneweekview th.<?php echo $weekday ?>');"></th> -<?php endforeach; ?> - </tr> - </thead> - <tbody> -<?php foreach($hours as $time => $time_label): ?> - <tr> - <td class="calendar_time"><?php echo $time_label?></td> -<?php foreach($weekdays as $weekdaynr => $weekday): ?> - <td class="<?php echo $weekday ?> <?php echo $time ?> calendar_row <?php echo $weekenddays[$weekday] == "true" ? 'weekend_row' : '' ?>" onclick="Calendar.UI.newEvent('#oneweekview th.<?php echo $weekday ?>', '<?php echo $time ?>');"></td> -<?php endforeach; ?> - </tr> -<?php endforeach; ?> - </tbody> - </table> - </div> - <div id="fourweeksview"> - <table> - <thead> - <tr> - <th class="calendar_row calw"><?php echo $l -> t("Week");?></th> -<?php foreach($weekdays as $weekdaynr => $weekday): ?> - <th class="calendar_row <?php echo $weekdaynr > 4 ? 'weekend_thead' : '' ?>"><?php echo $l->t(ucfirst($weekday)) ?></th> -<?php endforeach; ?> - </tr> - </thead> - <tbody> -<?php foreach(range(1, 4) as $week): ?> - <tr class="week_<?php echo $week ?>"> - <td class="calw"></td> -<?php foreach($weekdays as $weekdaynr => $weekday): ?> - <td class="day <?php echo $weekday ?> <?php echo $weekdaynr > 4 ? 'weekend' : '' ?>" onclick="Calendar.UI.newEvent('#fourweeksview .week_<?php echo $week ?> .<?php echo $weekday ?>')"> - <div class="dateinfo"></div> - <div class="events"></div> - </td> -<?php endforeach; ?> - </tr> -<?php endforeach; ?> - </tbody> - </table> - </div> - <div id="onemonthview"> - <table> - <thead> - <tr> -<?php foreach($weekdays as $weekdaynr => $weekday): ?> - <th class="calendar_row <?php echo $weekenddays[$weekday] == "true" ? 'weekend_thead' : '' ?> <?php echo $weekday ?>"><?php echo $l->t(ucfirst($weekday));?></th> -<?php endforeach; ?> - </tr> - </thead> - <tbody> -<?php foreach(range(1, 6) as $week): ?> - <tr class="week_<?php echo $week ?>"> -<?php foreach($weekdays as $weekdaynr => $weekday): ?> - <td class="day <?php echo $weekday ?> <?php echo $weekenddays[$weekday] == "true" ? 'weekend' : '' ?>" onclick="Calendar.UI.newEvent('#onemonthview .week_<?php echo $week ?> .<?php echo $weekday ?>')"> - <div class="dateinfo"></div> - <div class="events"></div> - </td> -<?php endforeach; ?> - </tr> -<?php endforeach; ?> - </tbody> - </table> - </div> - <div id="listview"> - <div id="more_before"></div> - <div id="events"></div> - <div id="more_after"></div> - </div> </div> <!-- Dialogs --> <div id="dialog_holder"></div> diff --git a/calendar/templates/part.choosecalendar.rowfields.php b/calendar/templates/part.choosecalendar.rowfields.php index db0c71252..a789be45a 100644 --- a/calendar/templates/part.choosecalendar.rowfields.php +++ b/calendar/templates/part.choosecalendar.rowfields.php @@ -1,4 +1,4 @@ <?php echo "<td width=\"20px\"><input id=\"active_" . $_['calendar']["id"] . "\" type=\"checkbox\" onClick=\"Calendar.UI.Calendar.activation(this, " . $_['calendar']["id"] . ")\"" . ($_['calendar']["active"] ? ' checked="checked"' : '') . "></td>"; echo "<td><label for=\"active_" . $_['calendar']["id"] . "\">" . $_['calendar']["displayname"] . "</label></td>"; - echo "<td width=\"20px\"><a href=\"#\" onclick=\"Calendar.UI.showCalDAVUrl('" . OC_User::getUser() . "', '" . $_['calendar']["uri"] . "');\" title=\"" . $l->t("CalDav Link") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/public.svg\"></a></td><td width=\"20px\"><a href=\"export.php?calid=" . $_['calendar']["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=\"Calendar.UI.Calendar.edit(this, " . $_['calendar']["id"] . ");\"><img class=\"svg action\" src=\"../../core/img/actions/rename.svg\"></a></td><td width=\"20px\"><a href=\"#\" onclick=\"Calendar.UI.deleteCalendar('" . $_['calendar']["id"] . "');\" title=\"" . $l->t("Delete") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/delete.svg\"></a></td>"; + echo "<td width=\"20px\"><a href=\"#\" onclick=\"Calendar.UI.showCalDAVUrl('" . OC_User::getUser() . "', '" . $_['calendar']["uri"] . "');\" title=\"" . $l->t("CalDav Link") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/public.svg\"></a></td><td width=\"20px\"><a href=\"export.php?calid=" . $_['calendar']["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=\"Calendar.UI.Calendar.edit(this, " . $_['calendar']["id"] . ");\"><img class=\"svg action\" src=\"../../core/img/actions/rename.svg\"></a></td><td width=\"20px\"><a href=\"#\" onclick=\"Calendar.UI.Calendar.deleteCalendar('" . $_['calendar']["id"] . "');\" title=\"" . $l->t("Delete") . "\" class=\"action\"><img class=\"svg action\" src=\"../../core/img/actions/delete.svg\"></a></td>"; diff --git a/calendar/templates/part.editevent.php b/calendar/templates/part.editevent.php index ae969f2dc..b3acfc4a0 100644 --- a/calendar/templates/part.editevent.php +++ b/calendar/templates/part.editevent.php @@ -1,6 +1,7 @@ <div id="event" title="<?php echo $l->t("Edit an event");?>"> <form id="event_form"> <input type="hidden" name="id" value="<?php echo $_['id'] ?>"> + <input type="hidden" name="lastmodified" value="<?php echo $_['lastmodified'] ?>"> <?php echo $this->inc("part.eventform"); ?> <div style="width: 100%;text-align: center;color: #FF1D1D;" id="errorbox"></div> <span id="actions"> diff --git a/calendar/templates/part.eventform.php b/calendar/templates/part.eventform.php index 8588b9168..dfa5fb8c7 100644 --- a/calendar/templates/part.eventform.php +++ b/calendar/templates/part.eventform.php @@ -13,9 +13,7 @@ <select id="category" name="categories[]" multiple="multiple" title="<?php echo $l->t("Select category") ?>"> <?php if (!isset($_['categories'])) {$_['categories'] = array();} - foreach($_['category_options'] as $category){ - echo '<option value="' . $category . '"' . (in_array($category, $_['categories']) ? ' selected="selected"' : '') . '>' . $category . '</option>'; - } + echo html_select_options($_['category_options'], $_['categories'], array('combine'=>true)); ?> </select></td> <th width="75px"> <?php echo $l->t("Calendar");?>:</th> @@ -23,9 +21,7 @@ <select style="width:140px;" name="calendar"> <?php if (!isset($_['calendar'])) {$_['calendar'] = false;} - foreach($_['calendar_options'] as $calendar){ - echo '<option value="' . $calendar['id'] . '"' . ($_['calendar'] == $calendar['id'] ? ' selected="selected"' : '') . '>' . $calendar['displayname'] . '</option>'; - } + echo html_select_options($_['calendar_options'], $_['calendar'], array('value'=>'id', 'label'=>'displayname')); ?> </select></td> </tr> @@ -66,9 +62,7 @@ <select name="repeat" style="width:350px;"> <?php if (isset($_['repeat_options'])) { - foreach($_['repeat_options'] as $id => $label){ - echo '<option value="' . $id . '"' . ($_['repeat'] == $id ? ' selected="selected"' : '') . '>' . $label . '</option>'; - } + echo html_select_options($_['repeat_options'], $_['repeat']); } ?> </select></td> diff --git a/contacts/ajax/addcard.php b/contacts/ajax/addcard.php index 0cecd3bdc..dd5b90651 100644 --- a/contacts/ajax/addcard.php +++ b/contacts/ajax/addcard.php @@ -68,11 +68,16 @@ foreach( $add as $propname){ } $id = OC_Contacts_VCard::add($aid,$vcard->serialize()); +$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); +$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); + $details = OC_Contacts_VCard::structureContact($vcard); $name = $details['FN'][0]['value']; $tmpl = new OC_Template('contacts','part.details'); $tmpl->assign('details',$details); $tmpl->assign('id',$id); +$tmpl->assign('adr_types',$adr_types); +$tmpl->assign('phone_types',$phone_types); $page = $tmpl->fetchPage(); OC_JSON::success(array('data' => array( 'id' => $id, 'name' => $name, 'page' => $page ))); diff --git a/contacts/ajax/getdetails.php b/contacts/ajax/getdetails.php index 0e76de61a..260fb53a6 100644 --- a/contacts/ajax/getdetails.php +++ b/contacts/ajax/getdetails.php @@ -51,10 +51,22 @@ if(is_null($vcard)){ exit(); } +$property_types = array( + 'ADR' => $l10n->t('Address'), + 'TEL' => $l10n->t('Telephone'), + 'EMAIL' => $l10n->t('Email'), + 'ORG' => $l10n->t('Organization'), +); +$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); +$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); + $details = OC_Contacts_VCard::structureContact($vcard); $tmpl = new OC_Template('contacts','part.details'); $tmpl->assign('details',$details); $tmpl->assign('id',$id); +$tmpl->assign('property_types',$property_types); +$tmpl->assign('adr_types',$adr_types); +$tmpl->assign('phone_types',$phone_types); $page = $tmpl->fetchPage(); OC_JSON::success(array('data' => array( 'id' => $id, 'page' => $page ))); diff --git a/contacts/ajax/setproperty.php b/contacts/ajax/setproperty.php index 18e008724..c9102c4a2 100644 --- a/contacts/ajax/setproperty.php +++ b/contacts/ajax/setproperty.php @@ -70,6 +70,9 @@ $vcard->children[$line]->setValue($value); // Add parameters $postparameters = isset($_POST['parameters'])?$_POST['parameters']:array(); +if ($vcard->children[$line]->name == 'TEL' && !array_key_exists('TYPE', $postparameters)){ + $postparameters['TYPE']=''; +} for($i=0;$i<count($vcard->children[$line]->parameters);$i++){ $name = $vcard->children[$line]->parameters[$i]->name; if(array_key_exists($name,$postparameters)){ @@ -77,7 +80,14 @@ for($i=0;$i<count($vcard->children[$line]->parameters);$i++){ unset($vcard->children[$line]->parameters[$i]); } else{ - $vcard->children[$line]->parameters[$i]->value = $postparameters[$name]; + unset($vcard->children[$line][$name]); + $values = $postparameters[$name]; + if (!is_array($values)){ + $values = array($values); + } + foreach($values as $value){ + $vcard->children[$line]->add($name, $value); + } } unset($postparameters[$name]); } @@ -94,7 +104,12 @@ $checksum = md5($vcard->children[$line]->serialize()); OC_Contacts_VCard::edit($id,$vcard->serialize()); +$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); +$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); + $tmpl = new OC_Template('contacts','part.property'); +$tmpl->assign('adr_types',$adr_types); +$tmpl->assign('phone_types',$phone_types); $tmpl->assign('property',OC_Contacts_VCard::structureProperty($vcard->children[$line],$line)); $page = $tmpl->fetchPage(); diff --git a/contacts/ajax/showaddcard.php b/contacts/ajax/showaddcard.php index 2f534f0fe..98367758f 100644 --- a/contacts/ajax/showaddcard.php +++ b/contacts/ajax/showaddcard.php @@ -29,9 +29,14 @@ $l10n = new OC_L10N('contacts'); OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); +$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); +$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); + $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); +$tmpl->assign('phone_types',$phone_types); $page = $tmpl->fetchPage(); OC_JSON::success(array('data' => array( 'page' => $page ))); diff --git a/contacts/ajax/showsetproperty.php b/contacts/ajax/showsetproperty.php index 6188f4773..2ec4b89b8 100644 --- a/contacts/ajax/showsetproperty.php +++ b/contacts/ajax/showsetproperty.php @@ -61,11 +61,15 @@ if(is_null($line)){ exit(); } +$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); +$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); $tmpl = new OC_Template('contacts','part.setpropertyform'); $tmpl->assign('id',$id); $tmpl->assign('checksum',$checksum); $tmpl->assign('property',OC_Contacts_VCard::structureProperty($vcard->children[$line])); +$tmpl->assign('adr_types',$adr_types); +$tmpl->assign('phone_types',$phone_types); $page = $tmpl->fetchPage(); OC_JSON::success(array('data' => array( 'page' => $page ))); diff --git a/contacts/css/formtastic.css b/contacts/css/formtastic.css index 629c22073..fede92b61 100644 --- a/contacts/css/formtastic.css +++ b/contacts/css/formtastic.css @@ -94,16 +94,14 @@ This stylesheet forms part of the Formtastic Rails Plugin /* INPUTS --------------------------------------------------------------------------------------------------*/ .formtastic .inputs { - overflow:hidden; /* clear containing floats */ -} - -.formtastic .input { - overflow:hidden; /* clear containing floats */ padding:0.5em 0; /* padding and negative margin juggling is for Firefox */ margin-top:-0.5em; margin-bottom:1em; } +.formtastic .input { +} + /* LEFT ALIGNED LABELS --------------------------------------------------------------------------------------------------*/ diff --git a/contacts/css/styles.css b/contacts/css/styles.css index 68f843b7a..f351589fe 100644 --- a/contacts/css/styles.css +++ b/contacts/css/styles.css @@ -3,16 +3,22 @@ #contacts_deletecard {position:absolute;top:15px;right:0;} #contacts_details_list { list-style:none; } -#contacts_details_list li { overflow:hidden; } -#contacts_details_list li p.contacts_property_name { width:25%; float:left;text-align:right;padding-right:0.3em; } -#contacts_details_list li p.contacts_property_data, #contacts_details_list li ul.contacts_property_data { width:72%; overflow:hidden; } -#contacts_addproperty, #contacts_addproperty_button { margin-left:25%; } +#contacts_details_list li { overflow:visible; } +#contacts_details_list li p.contacts_property_name { width:25%; float:left;text-align:right;padding-right:0.3em;color:#666; } +#contacts_details_list li p.contacts_property_data, #contacts_details_list li ul.contacts_property_data { width:72%;float:left; } +#contacts_setproperty_button { margin-left:25%; } -.contacts_property_data ul, .contacts_property_data ol { list-style:none; } +.contacts_property_data ul, ol.contacts_property_data { list-style:none; } .contacts_property_data li { overflow: hidden; } .contacts_property_data li label { width:20%; float:left; text-align:right;padding-right:0.3em; } +.contacts_property_data input { float:left; } .contacts_property_data li input { width:70%;overflow:hidden; } +.chzn-container { margin:3px 0 0; } +.chzn-container .chzn-choices { border-radius: 0.5em; } +.chzn-container.chzn-container-active .chzn-choices { border-bottom-left-radius: 0;border-bottom-right-radius: 0; } +.chzn-container .chzn-drop { border-bottom-left-radius: 0.5em;border-bottom-right-radius: 0.5em; } + /* Form setup ----------------------------------------------------------------*/ /* .forme {} */ /* .forme ul, .forme ol { list-style:none; } */ diff --git a/contacts/index.php b/contacts/index.php index 7e93d6183..29d41d3c4 100644 --- a/contacts/index.php +++ b/contacts/index.php @@ -75,8 +75,14 @@ if( !is_null($id) || count($contacts)){ $details = OC_Contacts_VCard::structureContact($vcard); } +$l10n = new OC_L10N('contacts'); +$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR'); +$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL'); + // Process the template $tmpl = new OC_Template( 'contacts', 'index', 'user' ); +$tmpl->assign('adr_types',$adr_types); +$tmpl->assign('phone_types',$phone_types); $tmpl->assign('addressbooks', $addressbooks); $tmpl->assign('contacts', $contacts); $tmpl->assign('details', $details ); diff --git a/contacts/js/interface.js b/contacts/js/interface.js index 9270297f3..ba1c0e536 100644 --- a/contacts/js/interface.js +++ b/contacts/js/interface.js @@ -56,14 +56,15 @@ $(document).ready(function(){ $('#contacts_addpropertyform #contacts_fieldpart').remove(); $('#contacts_addpropertyform #contacts_generic').remove(); if($(this).val() == 'ADR'){ - $('#contacts_addresspart').clone().insertBefore($('#contacts_addpropertyform input[type="submit"]')); + $('#contacts_addresspart').clone().insertAfter($('#contacts_addpropertyform .contacts_property_name')); } else if($(this).val() == 'TEL'){ - $('#contacts_phonepart').clone().insertBefore($('#contacts_addpropertyform input[type="submit"]')); + $('#contacts_phonepart').clone().insertAfter($('#contacts_addpropertyform .contacts_property_name')); } else{ - $('#contacts_generic').clone().insertBefore($('#contacts_addpropertyform input[type="submit"]')); + $('#contacts_generic').clone().insertAfter($('#contacts_addpropertyform .contacts_property_name')); } + $('#contacts_addpropertyform .contacts_property_data select').chosen(); }); $('#contacts_addpropertyform input[type="submit"]').live('click',function(){ @@ -82,7 +83,8 @@ $(document).ready(function(){ $.getJSON('ajax/showaddcard.php',{},function(jsondata){ if(jsondata.status == 'success'){ $('#rightcontent').data('id',''); - $('#rightcontent').html(jsondata.data.page); + $('#rightcontent').html(jsondata.data.page) + .find('select').chosen(); } else{ alert(jsondata.data.message); @@ -111,7 +113,8 @@ $(document).ready(function(){ var checksum = $(this).parents('li').first().data('checksum'); $.getJSON('ajax/showsetproperty.php',{'id': id, 'checksum': checksum },function(jsondata){ if(jsondata.status == 'success'){ - $('.contacts_property[data-checksum="'+checksum+'"]').html(jsondata.data.page); + $('.contacts_property[data-checksum="'+checksum+'"]').html(jsondata.data.page) + .find('select').chosen(); } else{ alert(jsondata.data.message); @@ -148,10 +151,12 @@ $(document).ready(function(){ $('.contacts_property').live('mouseenter',function(){ - $(this).find('span').show(); + $(this).find('span[data-use]').show(); }); $('.contacts_property').live('mouseleave',function(){ - $(this).find('span').hide(); + $(this).find('span[data-use]').hide(); }); + + $('#contacts_addcardform select').chosen(); }); diff --git a/contacts/lib/vcard.php b/contacts/lib/vcard.php index adfa32b6f..4865fae76 100644 --- a/contacts/lib/vcard.php +++ b/contacts/lib/vcard.php @@ -95,10 +95,15 @@ class OC_Contacts_VCard{ $card = self::parse($data); if(!is_null($card)){ + // VCARD must have a version + $hasversion = false; foreach($card->children as $property){ if($property->name == 'FN'){ $fn = $property->value; } + elseif($property->name == 'VERSION'){ + $hasversion = true; + } elseif(is_null($uri) && $property->name == 'UID' ){ $uri = $property->value.'.vcf'; } @@ -109,6 +114,11 @@ class OC_Contacts_VCard{ $card->add(new Sabre_VObject_Property('UID',$uid)); $data = $card->serialize(); }; + // Add version if needed + if(!$hasversion){ + $card->add(new Sabre_VObject_Property('VERSION','3.0')); + $data = $card->serialize(); + } } else{ // that's hard. Creating a UID and not saving it @@ -286,7 +296,13 @@ class OC_Contacts_VCard{ $property = new Sabre_VObject_Property( $name, $value ); $parameternames = array_keys($parameters); foreach($parameternames as $i){ - $property->parameters[] = new Sabre_VObject_Parameter($i,$parameters[$i]); + $values = $parameters[$i]; + if (!is_array($values)){ + $values = array($values); + } + foreach($values as $value){ + $property->add($i, $value); + } } $vcard->add($property); @@ -342,7 +358,17 @@ class OC_Contacts_VCard{ $parameter->name = 'PREF'; $parameter->value = '1'; } - $temp['parameters'][$parameter->name] = $parameter->value; + if ($property->name == 'TEL' && $parameter->name == 'TYPE'){ + if (isset($temp['parameters'][$parameter->name])){ + $temp['parameters'][$parameter->name][] = $parameter->value; + } + else{ + $temp['parameters'][$parameter->name] = array($parameter->value); + } + } + else{ + $temp['parameters'][$parameter->name] = $parameter->value; + } } return $temp; } @@ -362,4 +388,24 @@ class OC_Contacts_VCard{ return null; } } + public static function getTypesOfProperty($l, $prop){ + switch($prop){ + case 'ADR': + return array( + 'WORK' => $l->t('Work'), + 'HOME' => $l->t('Home'), + ); + case 'TEL': + return array( + 'HOME' => $l->t('Home'), + 'CELL' => $l->t('Mobile'), + 'WORK' => $l->t('Work'), + 'TEXT' => $l->t('Text'), + 'VOICE' => $l->t('Voice'), + 'FAX' => $l->t('Fax'), + 'VIDEO' => $l->t('Video'), + 'PAGER' => $l->t('Pager'), + ); + } + } } diff --git a/contacts/templates/part.addcardform.php b/contacts/templates/part.addcardform.php index a596ad816..627053547 100644 --- a/contacts/templates/part.addcardform.php +++ b/contacts/templates/part.addcardform.php @@ -7,9 +7,7 @@ <li class="input stringish"> <label class="label" for="id"><?php echo $l->t('Group'); ?></label> <select name="id" size="1"> - <?php foreach($_['addressbooks'] as $addressbook): ?> - <option value="<?php echo $addressbook['id']; ?>"><?php echo $addressbook['displayname']; ?></option> - <?php endforeach; ?> + <?php echo html_select_options($_['addressbooks'], null, array('value'=>'id', 'label'=>'displayname')); ?> </select> </li> </ol> @@ -45,15 +43,8 @@ </li> <li class="fragment"> <label for="tel_type"><?php echo $l->t('Type'); ?></label> - <select id="TEL" name="parameters[TEL][TYPE]" size="1"> - <option value="home"><?php echo $l->t('Home'); ?></option> - <option value="cell" selected="selected"><?php echo $l->t('Mobile'); ?></option> - <option value="work"><?php echo $l->t('Work'); ?></option> - <option value="text"><?php echo $l->t('Text'); ?></option> - <option value="voice"><?php echo $l->t('Voice'); ?></option> - <option value="fax"><?php echo $l->t('Fax'); ?></option> - <option value="video"><?php echo $l->t('Video'); ?></option> - <option value="pager"><?php echo $l->t('Pager'); ?></option> + <select id="TEL" name="parameters[TEL][TYPE][]" multiple="multiple"> + <?php echo html_select_options($_['phone_types'], 'CELL') ?> </select> </li> </ol> @@ -67,8 +58,7 @@ <li class="input"> <label class="label" for="adr_type"><?php echo $l->t('Type'); ?></label> <select id="adr_type" name="parameters[ADR][TYPE]" size="1"> - <option value="work"><?php echo $l->t('Work'); ?></option> - <option value="home" selected="selected"><?php echo $l->t('Home'); ?></option> + <?php echo html_select_options($_['adr_types'], 'HOME') ?> </select> </li> <li class="input stringish"> diff --git a/contacts/templates/part.details.php b/contacts/templates/part.details.php index e9fa8356e..f6d69005a 100644 --- a/contacts/templates/part.details.php +++ b/contacts/templates/part.details.php @@ -27,24 +27,21 @@ <input type="hidden" name="id" value="<?php echo $_['id']; ?>"> <p class="contacts_property_name"> <select name="name" size="1"> - <option value="ADR"><?php echo $l->t('Address'); ?></option> - <option value="TEL"><?php echo $l->t('Telephone'); ?></option> - <option value="EMAIL" selected="selected"><?php echo $l->t('Email'); ?></option> - <option value="ORG"><?php echo $l->t('Organization'); ?></option> + <?php echo html_select_options($_['property_types'], 'EMAIL') ?> </select> + <br> + <input id="contacts_addproperty_button" type="submit" value="<?php echo $l->t('Add'); ?>"> </p> <p class="contacts_property_data" id="contacts_generic"> <input type="text" name="value" value=""> - </p><br> - <input id="contacts_addproperty_button" type="submit" value="<?php echo $l->t('Add'); ?>"> + </p> </form> <div id="contacts_addcontactsparts" style="display:none;"> <ul class="contacts_property_data" id="contacts_addresspart"> <li> <label for="adr_type"><?php echo $l->t('Type'); ?></label> <select id="adr_type" name="parameters[TYPE]" size="1"> - <option value="work"><?php echo $l->t('Work'); ?></option> - <option value="home" selected="selected"><?php echo $l->t('Home'); ?></option> + <?php echo html_select_options($_['adr_types'], 'HOME') ?> </select> </li> <li> @@ -78,15 +75,8 @@ </ul> <p class="contacts_property_data" id="contacts_phonepart"> <input type="text" name="value" value=""> - <select name="parameters[TYPE]" size="1"> - <option value="home"><?php echo $l->t('Home'); ?></option> - <option value="cell" selected="selected"><?php echo $l->t('Mobile'); ?></option> - <option value="work"><?php echo $l->t('Work'); ?></option> - <option value="text"><?php echo $l->t('Text'); ?></option> - <option value="voice"><?php echo $l->t('Voice'); ?></option> - <option value="fax"><?php echo $l->t('Fax'); ?></option> - <option value="video"><?php echo $l->t('Video'); ?></option> - <option value="pager"><?php echo $l->t('Pager'); ?></option> + <select name="parameters[TYPE][]" multiple="multiple" data-placeholder="<?php echo $l->t('Type') ?>"> + <?php echo html_select_options($_['phone_types'], 'CELL') ?> </select> </p> <p class="contacts_property_data" id="contacts_generic"> diff --git a/contacts/templates/part.property.php b/contacts/templates/part.property.php index 4bc3a4d85..afef43112 100644 --- a/contacts/templates/part.property.php +++ b/contacts/templates/part.property.php @@ -23,8 +23,20 @@ <p class="contacts_property_name"><?php echo $l->t('Phone'); ?></p> <p class="contacts_property_data"> <?php echo $_['property']['value']; ?> - <?php if(isset($_['property']['parameters']['TYPE'])): ?> - (<?php echo $l->t(ucwords(str_replace('cell','mobile',strtolower($_['property']['parameters']['TYPE'])))); ?>) + <?php if(isset($_['property']['parameters']['TYPE']) && !empty($_['property']['parameters']['TYPE'])): ?> +<?php + $types = array(); + foreach($_['property']['parameters']['TYPE'] as $type): + if (isset($_['phone_types'][strtoupper($type)])){ + $types[]=$_['phone_types'][strtoupper($type)]; + } + else{ + $types[]=$l->t(ucwords(strtolower($type))); + } + endforeach; + $label = join(' ', $types); +?> + (<?php echo $label; ?>) <?php endif; ?> <span style="display:none;" data-use="edit"><img class="svg action" src="<?php echo image_path('', 'actions/rename.svg'); ?>" /></span> <span style="display:none;" data-use="delete"><img class="svg action" src="<?php echo image_path('', 'actions/delete.svg'); ?>" /></span> @@ -34,7 +46,16 @@ <?php echo $l->t('Address'); ?> <?php if(isset($_['property']['parameters']['TYPE'])): ?> <br> - (<?php echo $l->t(ucwords($_['property']['parameters']['TYPE'])); ?>) +<?php + $type = $_['property']['parameters']['TYPE']; + if (isset($_['adr_types'][strtoupper($type)])){ + $label=$_['adr_types'][strtoupper($type)]; + } + else{ + $label=$l->t(ucwords(strtolower($type))); + } +?> + (<?php echo $label; ?>) <?php endif; ?> </p> <p class="contacts_property_data"> diff --git a/contacts/templates/part.setpropertyform.php b/contacts/templates/part.setpropertyform.php index eb8a67a8a..f216a55f5 100644 --- a/contacts/templates/part.setpropertyform.php +++ b/contacts/templates/part.setpropertyform.php @@ -1,10 +1,15 @@ -<li class="contacts_property_edit" data-checksum="<?php echo $_['property']['checksum']; ?>"> <form id="contacts_setpropertyform"> <input type="hidden" name="checksum" value="<?php echo $_['property']['checksum']; ?>"> <input type="hidden" name="id" value="<?php echo $_['id']; ?>"> <?php if($_['property']['name']=='ADR'): ?> <p class="contacts_property_name"><label for="adr_pobox"><?php echo $l->t('Address'); ?></label></p> <ol class="contacts_property_data" id="contacts_addresspart"> + <li class="input"> + <label class="label" for="adr_type"><?php echo $l->t('Type'); ?></label> + <select id="adr_type" name="parameters[TYPE]" size="1"> + <?php echo html_select_options($_['adr_types'], strtoupper($_['property']['parameters']['TYPE'])) ?> + </select> + </li> <li> <label for="adr_pobox"><?php echo $l->t('PO Box'); ?></label> <input id="adr_pobox" type="text" name="value[0]" value="<?php echo $_['property']['value'][0] ?>"> @@ -36,7 +41,10 @@ </ol> <?php elseif($_['property']['name']=='TEL'): ?> <p class="contacts_property_name"><label for="tel"><?php echo $l->t('Phone'); ?></label></p> - <p class="contacts_property_data"><input id="tel" type="phone" name="value" value="<?php echo $_['property']['value']; ?>"></p> + <p class="contacts_property_data"><input id="tel" type="phone" name="value" value="<?php echo $_['property']['value'] ?>"> + <select id="tel_type<?php echo $_['property']['checksum'] ?>" name="parameters[TYPE][]" multiple="multiple" data-placeholder="<?php echo $l->t('Type') ?>"> + <?php echo html_select_options($_['phone_types'], isset($_['property']['parameters']['TYPE'])?$_['property']['parameters']['TYPE']:'') ?> + </select></p> <?php elseif($_['property']['name']=='EMAIL'): ?> <p class="contacts_property_name"><label for="email"><?php echo $l->t('Email'); ?></label></p> <p class="contacts_property_data"><input id="email" type="text" name="value" value="<?php echo $_['property']['value']; ?>"></p> @@ -44,6 +52,5 @@ <p class="contacts_property_name"><label for="org"><?php echo $l->t('Organization'); ?></label></p> <p class="contacts_property_data"><input id="org" type="text" name="value" value="<?php echo $_['property']['value']; ?>"></p> <?php endif; ?> - <input id="contacts_setproperty_button" type="submit" value="<?php echo $l->t('Edit'); ?>"> + <input id="contacts_setproperty_button" type="submit" value="<?php echo $l->t('Update'); ?>"> </form> -</li> diff --git a/external/ajax/seturls.php b/external/ajax/seturls.php index c8e977545..e994385a1 100644 --- a/external/ajax/seturls.php +++ b/external/ajax/seturls.php @@ -8,16 +8,16 @@ require_once('../../../lib/base.php'); OC_Util::checkAdminUser(); -if(isset($_POST['s1name'])) OC_Config::setValue( 'external-site1name', $_POST['s1name'] ); -if(isset($_POST['s1url'])) OC_Config::setValue( 'external-site1url', $_POST['s1url'] ); -if(isset($_POST['s2name'])) OC_Config::setValue( 'external-site2name', $_POST['s2name'] ); -if(isset($_POST['s2url'])) OC_Config::setValue( 'external-site2url', $_POST['s2url'] ); -if(isset($_POST['s3name'])) OC_Config::setValue( 'external-site3name', $_POST['s3name'] ); -if(isset($_POST['s3url'])) OC_Config::setValue( 'external-site3url', $_POST['s3url'] ); -if(isset($_POST['s4name'])) OC_Config::setValue( 'external-site4name', $_POST['s4name'] ); -if(isset($_POST['s4url'])) OC_Config::setValue( 'external-site4url', $_POST['s4url'] ); -if(isset($_POST['s5name'])) OC_Config::setValue( 'external-site5name', $_POST['s5name'] ); -if(isset($_POST['s5url'])) OC_Config::setValue( 'external-site5url', $_POST['s5url'] ); +if(isset($_POST['s1name'])) OC_Appconfig::setValue( 'external','site1name', $_POST['s1name'] ); +if(isset($_POST['s1url'])) OC_Appconfig::setValue( 'external','site1url', $_POST['s1url'] ); +if(isset($_POST['s2name'])) OC_Appconfig::setValue( 'external','site2name', $_POST['s2name'] ); +if(isset($_POST['s2url'])) OC_Appconfig::setValue( 'external','site2url', $_POST['s2url'] ); +if(isset($_POST['s3name'])) OC_Appconfig::setValue( 'external','site3name', $_POST['s3name'] ); +if(isset($_POST['s3url'])) OC_Appconfig::setValue( 'external','site3url', $_POST['s3url'] ); +if(isset($_POST['s4name'])) OC_Appconfig::setValue( 'external','site4name', $_POST['s4name'] ); +if(isset($_POST['s4url'])) OC_Appconfig::setValue( 'external','site4url', $_POST['s4url'] ); +if(isset($_POST['s5name'])) OC_Appconfig::setValue( 'external','site5name', $_POST['s5name'] ); +if(isset($_POST['s5url'])) OC_Appconfig::setValue( 'external','site5url', $_POST['s5url'] ); echo 'true'; diff --git a/external/appinfo/app.php b/external/appinfo/app.php index df14954d8..0f536cbf4 100644 --- a/external/appinfo/app.php +++ b/external/appinfo/app.php @@ -25,13 +25,13 @@ OC_APP::registerAdmin('external','settings'); OC_App::register( array( 'order' => 70, 'id' => 'external', 'name' => 'External' )); -if(OC_Config::getValue( "external-site1name", '' )<>'') OC_App::addNavigationEntry( array( 'id' => 'external_index1', 'order' => 80, 'href' => OC_Helper::linkTo( 'external', 'index.php' ).'?id=1', 'icon' => OC_Helper::imagePath( 'external', 'external.png' ), 'name' => OC_Config::getValue( "external-site1name", '' ))); +if(OC_Appconfig::getValue( "external","site1name", '' )<>'') OC_App::addNavigationEntry( array( 'id' => 'external_index1', 'order' => 80, 'href' => OC_Helper::linkTo( 'external', 'index.php' ).'?id=1', 'icon' => OC_Helper::imagePath( 'external', 'external.png' ), 'name' => OC_Appconfig::getValue( "external","site1name", '' ))); -if(OC_Config::getValue( "external-site2name", '' )<>'') OC_App::addNavigationEntry( array( 'id' => 'external_index2', 'order' => 80, 'href' => OC_Helper::linkTo( 'external', 'index.php' ).'?id=2', 'icon' => OC_Helper::imagePath( 'external', 'external.png' ), 'name' => OC_Config::getValue( "external-site2name", '' ))); +if(OC_Appconfig::getValue( "external","site2name", '' )<>'') OC_App::addNavigationEntry( array( 'id' => 'external_index2', 'order' => 80, 'href' => OC_Helper::linkTo( 'external', 'index.php' ).'?id=2', 'icon' => OC_Helper::imagePath( 'external', 'external.png' ), 'name' => OC_Appconfig::getValue( "external","site2name", '' ))); -if(OC_Config::getValue( "external-site3name", '' )<>'') OC_App::addNavigationEntry( array( 'id' => 'external_index3', 'order' => 80, 'href' => OC_Helper::linkTo( 'external', 'index.php' ).'?id=3', 'icon' => OC_Helper::imagePath( 'external', 'external.png' ), 'name' => OC_Config::getValue( "external-site3name", '' ))); +if(OC_Appconfig::getValue( "external","site3name", '' )<>'') OC_App::addNavigationEntry( array( 'id' => 'external_index3', 'order' => 80, 'href' => OC_Helper::linkTo( 'external', 'index.php' ).'?id=3', 'icon' => OC_Helper::imagePath( 'external', 'external.png' ), 'name' => OC_Appconfig::getValue( "external","site3name", '' ))); -if(OC_Config::getValue( "external-site4name", '' )<>'') OC_App::addNavigationEntry( array( 'id' => 'external_index4', 'order' => 80, 'href' => OC_Helper::linkTo( 'external', 'index.php' ).'?id=4', 'icon' => OC_Helper::imagePath( 'external', 'external.png' ), 'name' => OC_Config::getValue( "external-site4name", '' ))); +if(OC_Appconfig::getValue( "external","site4name", '' )<>'') OC_App::addNavigationEntry( array( 'id' => 'external_index4', 'order' => 80, 'href' => OC_Helper::linkTo( 'external', 'index.php' ).'?id=4', 'icon' => OC_Helper::imagePath( 'external', 'external.png' ), 'name' => OC_Appconfig::getValue( "external","site4name", '' ))); -if(OC_Config::getValue( "external-site5name", '' )<>'') OC_App::addNavigationEntry( array( 'id' => 'external_index5', 'order' => 80, 'href' => OC_Helper::linkTo( 'external', 'index.php' ).'?id=5', 'icon' => OC_Helper::imagePath( 'external', 'external.png' ), 'name' => OC_Config::getValue( "external-site5name", '' ))); +if(OC_Appconfig::getValue( "external","site5name", '' )<>'') OC_App::addNavigationEntry( array( 'id' => 'external_index5', 'order' => 80, 'href' => OC_Helper::linkTo( 'external', 'index.php' ).'?id=5', 'icon' => OC_Helper::imagePath( 'external', 'external.png' ), 'name' => OC_Appconfig::getValue( "external","site5name", '' ))); diff --git a/external/index.php b/external/index.php index 116e16d90..86b19abc1 100644 --- a/external/index.php +++ b/external/index.php @@ -35,7 +35,7 @@ if(isset($_GET['id'])){ $id=$_GET['id']; $id = (int) $id; - $url=OC_Config::getValue( "external-site".$id."url", '' ); + $url=OC_Appconfig::getValue( "external","site".$id."url", '' ); OC_App::setActiveNavigationEntry( 'external_index'.$id ); $tmpl = new OC_Template( 'external', 'frame', 'user' ); diff --git a/external/settings.php b/external/settings.php index ad33c16e1..3e0c34251 100644 --- a/external/settings.php +++ b/external/settings.php @@ -6,17 +6,17 @@ OC_Util::addScript( "external", "admin" ); $tmpl = new OC_Template( 'external', 'settings'); - $tmpl->assign('s1name',OC_Config::getValue( "external-site1name", '' )); - $tmpl->assign('s2name',OC_Config::getValue( "external-site2name", '' )); - $tmpl->assign('s3name',OC_Config::getValue( "external-site3name", '' )); - $tmpl->assign('s4name',OC_Config::getValue( "external-site4name", '' )); - $tmpl->assign('s5name',OC_Config::getValue( "external-site5name", '' )); + $tmpl->assign('s1name',OC_Appconfig::getValue( "external","site1name", '' )); + $tmpl->assign('s2name',OC_Appconfig::getValue( "external","site2name", '' )); + $tmpl->assign('s3name',OC_Appconfig::getValue( "external","site3name", '' )); + $tmpl->assign('s4name',OC_Appconfig::getValue( "external","site4name", '' )); + $tmpl->assign('s5name',OC_Appconfig::getValue( "external","site5name", '' )); - $tmpl->assign('s1url',OC_Config::getValue( "external-site1url", '' )); - $tmpl->assign('s2url',OC_Config::getValue( "external-site2url", '' )); - $tmpl->assign('s3url',OC_Config::getValue( "external-site3url", '' )); - $tmpl->assign('s4url',OC_Config::getValue( "external-site4url", '' )); - $tmpl->assign('s5url',OC_Config::getValue( "external-site5url", '' )); + $tmpl->assign('s1url',OC_Appconfig::getValue( "external","site1url", '' )); + $tmpl->assign('s2url',OC_Appconfig::getValue( "external","site2url", '' )); + $tmpl->assign('s3url',OC_Appconfig::getValue( "external","site3url", '' )); + $tmpl->assign('s4url',OC_Appconfig::getValue( "external","site4url", '' )); + $tmpl->assign('s5url',OC_Appconfig::getValue( "external","site5url", '' )); return $tmpl->fetchPage(); ?> diff --git a/files_sharing/ajax/getitem.php b/files_sharing/ajax/getitem.php index 075ec043e..d9df4abe9 100644 --- a/files_sharing/ajax/getitem.php +++ b/files_sharing/ajax/getitem.php @@ -1,5 +1,5 @@ <?php -$RUNTIME_NOAPPS = true; +//$RUNTIME_NOAPPS = true; require_once('../../../lib/base.php'); OC_JSON::checkAppEnabled('files_sharing'); diff --git a/files_sharing/ajax/setpermissions.php b/files_sharing/ajax/setpermissions.php index 7ee8f0e57..200202c70 100644 --- a/files_sharing/ajax/setpermissions.php +++ b/files_sharing/ajax/setpermissions.php @@ -1,5 +1,5 @@ <?php -$RUNTIME_NOAPPS = true; +//$RUNTIME_NOAPPS = true; require_once('../../../lib/base.php'); OC_JSON::checkAppEnabled('files_sharing'); diff --git a/files_sharing/ajax/share.php b/files_sharing/ajax/share.php index d1f509943..9b10260da 100644 --- a/files_sharing/ajax/share.php +++ b/files_sharing/ajax/share.php @@ -1,5 +1,5 @@ <?php -$RUNTIME_NOAPPS = true; +//$RUNTIME_NOAPPS = true; require_once('../../../lib/base.php'); OC_JSON::checkAppEnabled('files_sharing'); diff --git a/files_sharing/ajax/unshare.php b/files_sharing/ajax/unshare.php index a19a85cfd..d8a72a00e 100644 --- a/files_sharing/ajax/unshare.php +++ b/files_sharing/ajax/unshare.php @@ -1,5 +1,5 @@ <?php -$RUNTIME_NOAPPS = true; +//$RUNTIME_NOAPPS = true; require_once('../../../lib/base.php'); OC_JSON::checkAppEnabled('files_sharing'); diff --git a/files_sharing/ajax/userautocomplete.php b/files_sharing/ajax/userautocomplete.php index 21516c3d0..9d971fb62 100644 --- a/files_sharing/ajax/userautocomplete.php +++ b/files_sharing/ajax/userautocomplete.php @@ -1,5 +1,5 @@ <?php -$RUNTIME_NOAPPS = true; +//$RUNTIME_NOAPPS = true; require_once('../../../lib/base.php'); diff --git a/files_sharing/js/share.js b/files_sharing/js/share.js index 4056d693b..4457dddbe 100644 --- a/files_sharing/js/share.js +++ b/files_sharing/js/share.js @@ -224,7 +224,7 @@ function addUser(uid_shared_with, permissions, parentFolder) { var user = '<li data-uid_shared_with="'+uid_shared_with+'">'; user += '<a href="" class="unshare" style="display:none;"><img class="svg" alt="Unshare" src="'+OC.imagePath('core','actions/delete')+'"/></a>'; user += uid_shared_with; - user += '<input type="checkbox" name="permissions" id="'+uid_shared_with+'" class="permissions" "+checked+" />'; + user += '<input type="checkbox" name="permissions" id="'+uid_shared_with+'" class="permissions" '+checked+' />'; user += '<label for="'+uid_shared_with+'" '+style+'>can edit</label>'; user += '</li>'; } diff --git a/files_texteditor/js/editor.js b/files_texteditor/js/editor.js index 828839cbc..c3c051944 100644 --- a/files_texteditor/js/editor.js +++ b/files_texteditor/js/editor.js @@ -4,7 +4,6 @@ function setEditorSize(){ } function getFileExtension(file){ - // Extracts the file extension from the full filename var parts=file.split('.'); return parts[parts.length-1]; } @@ -12,6 +11,7 @@ function getFileExtension(file){ function setSyntaxMode(ext){ // Loads the syntax mode files and tells the editor var filetype = new Array(); + // Todo finish these filetype["h"] = "c_cpp"; filetype["c"] = "c_cpp"; filetype["cpp"] = "c_cpp"; @@ -56,14 +56,18 @@ function showControls(filename){ $('#controls').append(html); $('#editorbar').fadeIn('slow'); var breadcrumbhtml = '<div class="crumb svg" id="breadcrumb_file" style="background-image:url("../core/img/breadcrumb.png")"><p>'+filename+'</p></div>'; - $('.actions').before(breadcrumbhtml); - $('.actions').before(savebtnhtml); + $('.actions').before(breadcrumbhtml).before(savebtnhtml); }); } function bindControlEvents(){ - $("#editor_save").die('click', doFileSave).live('click', doFileSave); - $('#editor_close').live('click', hideFileEditor); + $("#editor_save").die('click',doFileSave).live('click',doFileSave); + $('#editor_close').die('click',hideFileEditor).live('click',hideFileEditor); +} + +function editorIsShown(){ + // Not working as intended. Always returns true. + return is_editor_shown; } function updateSessionFileHash(path){ @@ -73,20 +77,17 @@ function updateSessionFileHash(path){ if(jsondata.status=='failure'){ alert('Failed to update session file hash.'); } - }, - "json"); -} + }, "json");} -var editor_is_saving = false; function doFileSave(){ - if(is_editor_shown){ - editor_is_saving = true; + if(editorIsShown()){ + $("#editor_save").die('click',doFileSave); $('#editor_save').after('<img id="saving_icon" src="'+OC.filePath('core','img','loading.gif')+'"></img>'); var filecontents = window.aceEditor.getSession().getValue(); var dir = $('#editor').attr('data-dir'); var file = $('#editor').attr('data-filename'); $.post(OC.filePath('files_texteditor','ajax','savefile.php'), { filecontents: filecontents, file: file, dir: dir },function(jsondata){ - + if(jsondata.status == 'failure'){ var answer = confirm(jsondata.data.message); if(answer){ @@ -95,10 +96,10 @@ function doFileSave(){ $('#saving_icon').remove(); $('#editor_save').after('<p id="save_result" style="float: left">Saved!</p>') setTimeout(function() { - $('#save_result').fadeOut('slow',function(){ - $(this).remove(); - editor_is_saving = false; - }); + $('#save_result').fadeOut('slow',function(){ + $(this).remove(); + $("#editor_save").live('click',doFileSave); + }); }, 2000); } else { @@ -107,25 +108,25 @@ function doFileSave(){ $('#editor_save').after('<p id="save_result" style="float: left">Failed!</p>'); setTimeout(function() { $('#save_result').fadeOut('slow',function(){ - $(this).remove(); - editor_is_saving = false; + $(this).remove(); + $("#editor_save").live('click',doFileSave); }); }, 2000); } }, 'json'); } - else { + else { // Don't save! $('#saving_icon').remove(); // Temporary measure until we get a tick icon $('#editor_save').after('<p id="save_result" style="float: left">Saved!</p>'); setTimeout(function() { $('#save_result').fadeOut('slow',function(){ - $(this).remove(); - editor_is_saving = false; + $(this).remove(); + $("#editor_save").live('click',doFileSave); }); }, 2000); - } + } } else if(jsondata.status == 'success'){ // Success @@ -133,19 +134,25 @@ function doFileSave(){ // Temporary measure until we get a tick icon $('#editor_save').after('<p id="save_result" style="float: left">Saved!</p>'); setTimeout(function() { - $('#save_result').fadeOut('slow',function(){ - $(this).remove(); - editor_is_saving = false; - }); + $('#save_result').fadeOut('slow',function(){ + $(this).remove(); + $("#editor_save").live('click',doFileSave); + }); }, 2000); } }, 'json'); - window.aceEditor.focus(); + giveEditorFocus(); + } else { + return; } }; +function giveEditorFocus(){ + window.aceEditor.focus(); +}; + function showFileEditor(dir,filename){ - if(!is_editor_shown){ + if(!editorIsShown()){ // Loads the file editor and display it. var data = $.ajax({ url: OC.filePath('files','ajax','download.php')+'?files='+encodeURIComponent(filename)+'&dir='+encodeURIComponent(dir), @@ -175,26 +182,23 @@ function showFileEditor(dir,filename){ } function hideFileEditor(){ - if(is_editor_shown){ - $('#editor').attr('editorshown','false'); - // Fade out controls - $('#editor_close').fadeOut('slow'); - // Fade out the save button - $('#editor_save').fadeOut('slow'); - // Fade out breadcrumb - $('#breadcrumb_file').fadeOut('slow', function(){ $(this).remove();}); - // Fade out editor - $('#editor').fadeOut('slow', function(){ - $('#editor_close').remove(); - $('#editor_save').remove(); - $('#editor').remove(); - var editorhtml = '<div id="editor"></div>'; - $('table').after(editorhtml); - $('.actions,#file_access_panel').fadeIn('slow'); - $('table').fadeIn('slow'); - }); - is_editor_shown = false; - } + // Fade out controls + $('#editor_close').fadeOut('slow'); + // Fade out the save button + $('#editor_save').fadeOut('slow'); + // Fade out breadcrumb + $('#breadcrumb_file').fadeOut('slow', function(){ $(this).remove();}); + // Fade out editor + $('#editor').fadeOut('slow', function(){ + $('#editor_close').remove(); + $('#editor_save').remove(); + $('#editor').remove(); + var editorhtml = '<div id="editor"></div>'; + $('table').after(editorhtml); + $('.actions,#file_access_panel').fadeIn('slow'); + $('table').fadeIn('slow'); + }); + is_editor_shown = false; } // Keyboard Shortcuts @@ -205,25 +209,18 @@ function checkForCtrlKey(e){ } function checkForSaveKeyPress(e){ - if(!editor_is_saving){ if(e.which == 17 || e.which == 91) ctrlBtn=true; if(e.which == 83 && ctrlBtn == true) { e.preventDefault(); - doFileSave(); + $('#editor_save').trigger('click'); return false; } - } else { - e.preventDefault(); - } } -// Sets the correct size of the editor window $(window).resize(function() { setEditorSize(); }); - var is_editor_shown = false; - $(document).ready(function(){ if(typeof FileActions!=='undefined'){ FileActions.register('text','Edit','',function(filename){ @@ -243,7 +240,6 @@ $(document).ready(function(){ a.click(function(){ var file=text.split('/').pop(); var dir=text.substr(0,text.length-file.length-1); - // TODO this will only work in the files app. showFileEditor(dir,file); }); } @@ -252,5 +248,4 @@ $(document).ready(function(){ // Binds the save keyboard shortcut events $(document).unbind('keyup').bind('keyup',checkForCtrlKey).unbind('keydown').bind('keydown',checkForSaveKeyPress); - - }); +}); diff --git a/media/css/music.css b/media/css/music.css index 67d560751..a6738058b 100644 --- a/media/css/music.css +++ b/media/css/music.css @@ -31,7 +31,8 @@ div.jp-volume-bar-value { background:#ccc; width:0; height:0.4em; } #collection li { padding-right:10px; } #searchresults input.play, #searchresults input.add { float:left; height:1em; width:1em; } #collection tr.collapsed td.album, #collection tr.collapsed td.title { color:#ddd; } -a.expander { float:right; padding:0 1em; } +td.artist img, td.artist a, td.album img, td.album a { float: left; } +td.artist a.expander, td.album a.expander { float:right; padding:0 1em; } tr.active td { background-color:#eee; font-weight:bold; } tr td { border-top:1px solid #eee; height:2.2em; } tr .artist img { vertical-align:middle; } diff --git a/media/lib_ampache.php b/media/lib_ampache.php index 0ad84d668..bc1f85304 100644 --- a/media/lib_ampache.php +++ b/media/lib_ampache.php @@ -128,7 +128,7 @@ class OC_MEDIA_AMPACHE{ $albums=count(OC_MEDIA_COLLECTION::getAlbums($artist['artist_id'])); $songs=count(OC_MEDIA_COLLECTION::getSongs($artist['artist_id'])); $id=$artist['artist_id']; - $name=utf8_decode(htmlentities($artist['artist_name'])); + $name=htmlentities($artist['artist_name'], ENT_COMPAT, 'UTF-8'); echo("\t<artist id='$id'>\n"); echo("\t\t<name>$name</name>\n"); echo("\t\t<albums>$albums</albums>\n"); @@ -142,10 +142,10 @@ class OC_MEDIA_AMPACHE{ if(!$artistName){ $artistName=OC_MEDIA_COLLECTION::getArtistName($album['album_artist']); } - $artistName=utf8_decode(htmlentities($artistName)); + $artistName=htmlentities($artistName, ENT_COMPAT, 'UTF-8'); $songs=count(OC_MEDIA_COLLECTION::getSongs($album['album_artist'],$album['album_id'])); $id=$album['album_id']; - $name=utf8_decode(htmlentities($album['album_name'])); + $name=htmlentities($album['album_name'], ENT_COMPAT, 'UTF-8'); $artist=$album['album_artist']; echo("\t<album id='$id'>\n"); echo("\t\t<name>$name</name>\n"); @@ -163,10 +163,10 @@ class OC_MEDIA_AMPACHE{ if(!$albumName){ $albumName=OC_MEDIA_COLLECTION::getAlbumName($song['song_album']); } - $artistName=utf8_decode(htmlentities($artistName)); - $albumName=utf8_decode(htmlentities($albumName)); + $artistName=htmlentities($artistName, ENT_COMPAT, 'UTF-8'); + $albumName=htmlentities($albumName, ENT_COMPAT, 'UTF-8'); $id=$song['song_id']; - $name=utf8_decode(htmlentities($song['song_name'])); + $name=htmlentities($song['song_name'], ENT_COMPAT, 'UTF-8'); $artist=$song['song_artist']; $album=$song['song_album']; echo("\t<song id='$id'>\n"); diff --git a/media/lib_scanner.php b/media/lib_scanner.php index ef63cea45..c2bea2d83 100644 --- a/media/lib_scanner.php +++ b/media/lib_scanner.php @@ -93,6 +93,7 @@ class OC_MEDIA_SCANNER{ } if(!self::$getID3){ self::$getID3=@new getID3(); + self::$getID3->encoding='UTF-8'; } $data=@self::$getID3->analyze($file); getid3_lib::CopyTagsToComments($data); @@ -105,21 +106,18 @@ class OC_MEDIA_SCANNER{ $artist='unknown'; }else{ $artist=stripslashes($data['comments']['artist'][0]); - $artist=utf8_encode($artist); } if(!isset($data['comments']['album'])){ OC_Log::write('media',"error reading album tag in '$file'",OC_Log::WARN); $album='unknown'; }else{ $album=stripslashes($data['comments']['album'][0]); - $album=utf8_encode($album); } if(!isset($data['comments']['title'])){ OC_Log::write('media',"error reading title tag in '$file'",OC_Log::WARN); $title='unknown'; }else{ $title=stripslashes($data['comments']['title'][0]); - $title=utf8_encode($title); } $size=$data['filesize']; $track=(isset($data['comments']['track']))?$data['comments']['track'][0]:0; @@ -150,4 +148,4 @@ class OC_MEDIA_SCANNER{ $ext=substr($filename,strrpos($filename,'.')+1); return $ext=='mp3' || $ext=='flac' || $ext=='m4a' || $ext=='ogg' || $ext=='oga'; } -}
\ No newline at end of file +} diff --git a/user_ldap/appinfo/app.php b/user_ldap/appinfo/app.php index 7906241f7..3261708f5 100644 --- a/user_ldap/appinfo/app.php +++ b/user_ldap/appinfo/app.php @@ -26,7 +26,10 @@ require_once('apps/user_ldap/user_ldap.php'); OC_APP::registerAdmin('user_ldap','settings'); // define LDAP_DEFAULT_PORT -define("OC_USER_BACKEND_LDAP_DEFAULT_PORT", 389); +define('OC_USER_BACKEND_LDAP_DEFAULT_PORT', 389); + +// define OC_USER_BACKEND_LDAP_DEFAULT_DISPLAY_NAME +define('OC_USER_BACKEND_LDAP_DEFAULT_DISPLAY_NAME', 'uid'); // register user backend OC_User::useBackend( "LDAP" ); diff --git a/user_ldap/settings.php b/user_ldap/settings.php index 8dbd3c046..1f2d8ed9a 100644 --- a/user_ldap/settings.php +++ b/user_ldap/settings.php @@ -20,11 +20,21 @@ * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ -$params = array('ldap_host', 'ldap_port', 'ldap_dn', 'ldap_password', 'ldap_base', 'ldap_filter'); +$params = array('ldap_host', 'ldap_port', 'ldap_dn', 'ldap_password', 'ldap_base', 'ldap_filter', 'ldap_display_name', 'ldap_tls', 'ldap_nocase'); -foreach($params as $param){ - if(isset($_POST[$param])){ - OC_Appconfig::setValue('user_ldap', $param, $_POST[$param]); +if ($_POST) { + foreach($params as $param){ + if(isset($_POST[$param])){ + OC_Appconfig::setValue('user_ldap', $param, $_POST[$param]); + } + elseif('ldap_tls' == $param) { + // unchecked checkboxes are not included in the post paramters + OC_Appconfig::setValue('user_ldap', $param, 0); + } + elseif('ldap_nocase' == $param) { + OC_Appconfig::setValue('user_ldap', $param, 0); + } + } } @@ -38,4 +48,7 @@ foreach($params as $param){ // ldap_port has a default value $tmpl->assign( 'ldap_port', OC_Appconfig::getValue('user_ldap', 'ldap_port', OC_USER_BACKEND_LDAP_DEFAULT_PORT)); +// ldap_display_name has a default value +$tmpl->assign( 'ldap_display_name', OC_Appconfig::getValue('user_ldap', 'ldap_display_name', OC_USER_BACKEND_LDAP_DEFAULT_DISPLAY_NAME)); + return $tmpl->fetchPage(); diff --git a/user_ldap/templates/settings.php b/user_ldap/templates/settings.php index 32e1b29da..2abb0b472 100644 --- a/user_ldap/templates/settings.php +++ b/user_ldap/templates/settings.php @@ -1,12 +1,17 @@ <form id="ldap" action="#" method="post"> <fieldset class="personalblock"> <legend><strong>LDAP</strong></legend> - <p><label for="ldap_host">Host<input type="text" id="ldap_host" name="ldap_host" value="<?php echo $_['ldap_host']; ?>"></label> - <label for="ldap_port">Port</label><input type="text" id="ldap_port" name="ldap_port" value="<?php echo $_['ldap_port']; ?>" /></p> - <p><label for="ldap_dn">Name</label><input type="text" id="ldap_dn" name="ldap_dn" value="<?php echo $_['ldap_dn']; ?>" /> - <label for="ldap_password">Password</label><input type="password" id="ldap_password" name="ldap_password" value="<?php echo $_['ldap_password']; ?>" /></p> - <p><label for="ldap_base">Base</label><input type="text" id="ldap_base" name="ldap_base" value="<?php echo $_['ldap_base']; ?>" /> - <label for="ldap_filter">Filter (use %uid placeholder)</label><input type="text" id="ldap_filter" name="ldap_filter" value="<?php echo $_['ldap_filter']; ?>" /></p> + <p><label for="ldap_host"><?php echo $l->t('Host');?><input type="text" id="ldap_host" name="ldap_host" value="<?php echo $_['ldap_host']; ?>"></label> + <label for="ldap_port"><?php echo $l->t('Port');?></label><input type="text" id="ldap_port" name="ldap_port" value="<?php echo $_['ldap_port']; ?>" /></p> + <p><label for="ldap_dn"><?php echo $l->t('Name');?></label><input type="text" id="ldap_dn" name="ldap_dn" value="<?php echo $_['ldap_dn']; ?>" /> + <label for="ldap_password"><?php echo $l->t('Password');?></label><input type="password" id="ldap_password" name="ldap_password" value="<?php echo $_['ldap_password']; ?>" /> + <small><?php echo $l->t('Leave both empty for anonymous bind for search, then bind with users credentials.');?></small></p> + <p><label for="ldap_base"><?php echo $l->t('Base');?></label><input type="text" id="ldap_base" name="ldap_base" value="<?php echo $_['ldap_base']; ?>" /> + <label for="ldap_filter"><?php echo $l->t('Filter (use %%uid placeholder)');?></label><input type="text" id="ldap_filter" name="ldap_filter" value="<?php echo $_['ldap_filter']; ?>" /></p> + <p><label for="ldap_display_name"><?php echo $l->t('Display Name Field');?></label><input type="text" id="ldap_display_name" name="ldap_display_name" value="<?php echo $_['ldap_display_name']; ?>" /> + <small><?php echo $l->t('Currently the display name field needs to be the same you matched %%uid against in the filter above, because ownCloud doesn\'t distinguish between user id and user name.');?></small></p> + <p><input type="checkbox" id="ldap_tls" name="ldap_tls" value="1"<?php if ($_['ldap_tls']) echo ' checked'; ?>><label for="ldap_tls"><?php echo $l->t('Use TLS');?></label></p> + <p><input type="checkbox" id="ldap_nocase" name="ldap_nocase" value="1"<?php if ($_['ldap_nocase']) echo ' checked'; ?>><label for="ldap_nocase"><?php echo $l->t('Case insensitve LDAP server (Windows)');?></label></p> <input type="submit" value="Save" /> </fieldset> </form> diff --git a/user_ldap/user_ldap.php b/user_ldap/user_ldap.php index 1154efc17..106240e74 100644 --- a/user_ldap/user_ldap.php +++ b/user_ldap/user_ldap.php @@ -33,6 +33,9 @@ class OC_USER_LDAP extends OC_User_Backend { protected $ldap_password; protected $ldap_base; protected $ldap_filter; + protected $ldap_tls; + protected $ldap_nocase; + protected $ldap_display_name; function __construct() { $this->ldap_host = OC_Appconfig::getValue('user_ldap', 'ldap_host',''); @@ -41,13 +44,16 @@ class OC_USER_LDAP extends OC_User_Backend { $this->ldap_password = OC_Appconfig::getValue('user_ldap', 'ldap_password',''); $this->ldap_base = OC_Appconfig::getValue('user_ldap', 'ldap_base',''); $this->ldap_filter = OC_Appconfig::getValue('user_ldap', 'ldap_filter',''); + $this->ldap_tls = OC_Appconfig::getValue('user_ldap', 'ldap_tls', 0); + $this->ldap_nocase = OC_Appconfig::getValue('user_ldap', 'ldap_nocase', 0); + $this->ldap_display_name = OC_Appconfig::getValue('user_ldap', 'ldap_display_name', OC_USER_BACKEND_LDAP_DEFAULT_DISPLAY_NAME); if( !empty($this->ldap_host) && !empty($this->ldap_port) - && !empty($this->ldap_dn) - && !empty($this->ldap_password) + && ((!empty($this->ldap_dn) && !empty($this->ldap_password)) || (empty($this->ldap_dn) && empty($this->ldap_password))) && !empty($this->ldap_base) && !empty($this->ldap_filter) + && !empty($this->ldap_display_name) ) { $this->configured = true; @@ -63,9 +69,10 @@ class OC_USER_LDAP extends OC_User_Backend { private function getDs() { if(!$this->ds) { $this->ds = ldap_connect( $this->ldap_host, $this->ldap_port ); - if(ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3)) - if(ldap_set_option($this->ds, LDAP_OPT_REFERRALS, 0)) - ldap_start_tls($this->ds); + if(ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3)) + if(ldap_set_option($this->ds, LDAP_OPT_REFERRALS, 0)) + if($this->ldap_tls) + ldap_start_tls($this->ds); } // login @@ -88,15 +95,16 @@ class OC_USER_LDAP extends OC_User_Backend { return false; // get dn - $filter = str_replace("%uid", $uid, $this->ldap_filter); + $filter = str_replace('%uid', $uid, $this->ldap_filter); $sr = ldap_search( $this->getDs(), $this->ldap_base, $filter ); $entries = ldap_get_entries( $this->getDs(), $sr ); - if( $entries["count"] == 0 ) + if( $entries['count'] == 0 ) return false; - return $entries[0]["dn"]; + return $entries[0]['dn']; } + public function checkPassword( $uid, $password ) { if(!$this->configured){ return false; @@ -107,7 +115,28 @@ class OC_USER_LDAP extends OC_User_Backend { if (!@ldap_bind( $this->getDs(), $dn, $password )) return false; - return $uid; + + if($this->ldap_nocase) { + $filter = str_replace('%uid', $uid, $this->ldap_filter); + $sr = ldap_search( $this->getDs(), $this->ldap_base, $filter ); + $entries = ldap_get_entries( $this->getDs(), $sr ); + if( $entries['count'] == 1 ) { + foreach($entries as $row) { + $ldap_display_name = strtolower($this->ldap_display_name); + if(isset($row[$ldap_display_name])) { + return $row[$ldap_display_name][0]; + } + } + } + else { + return $uid; + } + + } + else { + return $uid; + } + } public function userExists( $uid ) { @@ -117,6 +146,37 @@ class OC_USER_LDAP extends OC_User_Backend { $dn = $this->getDn($uid); return !empty($dn); } + + public function getUsers() + { + if(!$this->configured) + return false; + + // connect to server + $ds = $this->getDs(); + if( !$ds ) + return false; + + // get users + $filter = 'objectClass=person'; + $sr = ldap_search( $this->getDs(), $this->ldap_base, $filter ); + $entries = ldap_get_entries( $this->getDs(), $sr ); + if( $entries['count'] == 0 ) + return false; + else { + $users = array(); + foreach($entries as $row) { + // TODO ldap_get_entries() seems to lower all keys => needs review + $ldap_display_name = strtolower($this->ldap_display_name); + if(isset($row[$ldap_display_name])) { + $users[] = $row[$ldap_display_name][0]; + } + } + // TODO language specific sorting of user names + sort($users); + return $users; + } + } } |