[dev] Re: [horde] Shares Lists and url parameter.

Damian Alejandro Fernandez Sosa damlists at cnba.uba.ar
Wed Dec 18 01:31:33 PST 2002


I consolidate all display_calendars  code in one place.


I hope that I understand you and this is that you want

all the display_calendars code is in one place and I update the prefs
only when I change something.



If you like this code, let me know so I make this in nag and mnemo also.




I think we must to modify kronolith,nag and mnemo to "share"  this code
in only one funcion to mantain it better.

Let me know if you agree with that.




On Mon, 2002-12-16 at 00:13, Chuck Hagenbuch wrote:
> Quoting Damian Alejandro Fernandez Sosa <damlists@cnba.uba.ar>:
> 
> > Ok, no problem, please tell me how you imagine them they must to work
> 
> There's no need to add a function to Share.php for this, and it didn't 
> belong there; it also ignored the Horde::getFormData() function and wasn't 
> magic_quotes_gpc safe. The base.php patches just seemed like they should be 
> able to be consolidated with other code there, instead of creating yet more 
> mess.
> 
> -chuck
> 
> --
> Charles Hagenbuch, <chuck@horde.org>
> "People ask me all the time what it will be like living without otters."
>  - Google, thanks to Harpers



===================================================================
RCS file: /repository/kronolith/lib/base.php,v
retrieving revision 1.70
diff -u -r1.70 base.php
--- base.php    17 Dec 2002 17:37:52 -0000      1.70
+++ base.php    18 Dec 2002 04:24:50 -0000
@@ -71,18 +71,11 @@
 require_once HORDE_BASE . '/lib/Share.php';
 $GLOBALS['shares'] = &Horde_Share::singleton($registry->getApp());

-// Update the preference for what calendars to display. If the user
-// doesn't have any selected calendars for view then fall back to some
-// available calendar.
-$GLOBALS['display_calendars'] =
unserialize($GLOBALS['prefs']->getValue('display_cals'));
-if (($d_cal = Horde::getFormData('display_cal')) !== null) {
-    if (in_array($d_cal, $GLOBALS['display_calendars'])) {
-        $key = array_search($d_cal, $GLOBALS['display_calendars']);
-        unset($GLOBALS['display_calendars'][$key]);
-    } else {
-        $GLOBALS['display_calendars'][] = $d_cal;
-    }
-}
+
+
+
+
+

 $GLOBALS['display_remote_calendars'] =
unserialize($GLOBALS['prefs']->getValue('display_remote_cals'));
 if (is_array(Horde::getFormData('remote_cals'))) {
@@ -93,33 +86,78 @@
     $GLOBALS['prefs']->setValue('display_remote_cals',
serialize(array()));
 }

-// Make sure all shares exists now to save on checking later.
-$_temp = $GLOBALS['display_calendars'];
+
+
+
+
+$updated=false;
+if ( ( $_tempshares = Horde::getFormData('showShare') ) != null ){
+       foreach ($_tempshares as $id) {
+               $_tempcals[]=$id;
+       }
+
+}
+else{
+       // Get the preferences
+       $_tempcals =
unserialize($GLOBALS['prefs']->getValue('display_cals'));
+       if (($d_cal = Horde::getFormData('display_cal')) !== null) {
+               // You click in the combo box to show/hide a calendar
+           $updated=true;
+           if (in_array($d_cal, $_tempcals)) {
+               // You hide this calendar
+             $key = array_search($d_cal, $_tempcals);
+               unset($_tempcals[$key]);
+           } else {
+               // You show this calendar
+               $_tempcals[] = $d_cal;
+           }
+       }
+
+
+       if (count($_tempcals) == 0) {
+       // If we don't have any calendars to show....
+           $cals = Kronolith::listCalendars(true);
+           // Get My calendars and if I have'nt any calendar create one
+           if (!count($cals) && Auth::getAuth()) {
+               $updated=true;
+               // Create a personal calendar
+               $_tempcals = array(Auth::getAuth());
+
+               // If this share doesn't exist then create it.
+               if (!$GLOBALS['shares']->exists(Auth::getAuth())) {
+                   $share =
&$GLOBALS['shares']->newShare(Auth::getAuth());
+                   $share->setOwner(Auth::getAuth(), false);
+                   $share->setShareName(_("My Calendar"), false);
+                   $GLOBALS['shares']->addShare($share);
+               }
+           }
+       }
+}
+
+
+// Make sure all the calendars selected are valid
+// if a calendar is not valid don't punt in
+// $GLOBALS['display_calendars'}
 $_all = Kronolith::listCalendars();
 $GLOBALS['display_calendars'] = array();
-foreach ($_temp as $id) {
+foreach ($_tempcals as $id) {
     if (isset($_all[$id])) {
-        $GLOBALS['display_calendars'][] = $id;
+            $GLOBALS['display_calendars'][] = $id;
+    }
+    else{
+           $updated=true;
     }
 }
-$GLOBALS['prefs']->setValue('display_cals',
serialize($GLOBALS['display_calendars']));

-if (count($GLOBALS['display_calendars']) == 0) {
-    $cals = Kronolith::listCalendars(true);
-    if (!count($cals) && Auth::getAuth()) {
-        /* Create a personal calendar */
-        $GLOBALS['display_calendars'] = array(Auth::getAuth());
-
-        /* If this share doesn't exist then create it. */
-        if (!$GLOBALS['shares']->exists(Auth::getAuth())) {
-            $share = &$GLOBALS['shares']->newShare(Auth::getAuth());
-            $share->setOwner(Auth::getAuth(), false);
-            $share->setShareName(_("My Calendar"), false);
-            $GLOBALS['shares']->addShare($share);
-        }
-        $GLOBALS['prefs']->setValue('display_cals',
serialize($GLOBALS['display_calendars']));
-    }
+
+if ( $updated ){
+       // Only update the prefs if the preferences are changed
+       $GLOBALS['prefs']->setValue('display_cals',
serialize($GLOBALS['display_calendars']));
 }
+
+
+
+

 // Create a calendar backend object.
 $GLOBALS['calendar'] =
&Kronolith_Driver::factory($conf['calendar']['driver'],

-------------- next part --------------
A non-text attachment was scrubbed...
Name: base.diff
Type: text/x-patch
Size: 4309 bytes
Desc: not available
Url : http://lists.horde.org/archives/dev/attachments/20021218/f233da62/base.bin


More information about the dev mailing list