Back to index

webcit  8.12-dfsg
roomviews.c
Go to the documentation of this file.
00001 /*
00002  * Lots of different room-related operations.
00003  */
00004 
00005 #include "webcit.h"
00006 #include "webserver.h"
00007 
00008 char *viewdefs[VIEW_MAX];
00009 
00010 /*
00011  * This table defines which views may be selected as the
00012  * default view for a room at the time of its creation.
00013  */
00014 ROOM_VIEWS allowed_default_views[VIEW_MAX] = {
00015        1, /* VIEW_BBS              Bulletin board */
00016        1, /* VIEW_MAILBOX   Mailbox summary */
00017        1, /* VIEW_ADDRESSBOOK      Address book */
00018        1, /* VIEW_CALENDAR  Calendar */
00019        1, /* VIEW_TASKS     Tasks */
00020        1, /* VIEW_NOTES     Notes */
00021        1, /* VIEW_WIKI             Wiki */
00022        0, /* VIEW_CALBRIEF  Brief Calendar */
00023        0, /* VIEW_JOURNAL   Journal */
00024        0, /* VIEW_DRAFTS    Drafts */
00025        1  /* VIEW_BLOG             Blog */
00026 };
00027 
00028 /*
00029  * Given the default view for a room, this table defines
00030  * which alternate views may be selected by the user.
00031  */
00032 ROOM_VIEWS exchangeable_views[VIEW_MAX][VIEW_MAX] = {
00033        { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },      /* bulletin board */
00034        { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },      /* mailbox summary */
00035        { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },      /* address book */
00036        { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },      /* calendar */
00037        { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },      /* tasks */
00038        { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },      /* notes */
00039        { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 },      /* wiki */
00040        { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 },      /* brief calendar */
00041        { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },      /* journal */
00042        { 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1 },      /* drafts */
00043        { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 }       /* blog */
00044 };
00045 
00046 /*
00047  * Initialize the viewdefs with localized strings
00048  */
00049 void initialize_viewdefs(void) {
00050        viewdefs[VIEW_BBS]          = _("Bulletin Board");
00051        viewdefs[VIEW_MAILBOX]             = _("Mail Folder");
00052        viewdefs[VIEW_ADDRESSBOOK]  = _("Address Book");
00053        viewdefs[VIEW_CALENDAR]            = _("Calendar");
00054        viewdefs[VIEW_TASKS]        = _("Task List");
00055        viewdefs[VIEW_NOTES]        = _("Notes List");
00056        viewdefs[VIEW_WIKI]         = _("Wiki");
00057        viewdefs[VIEW_CALBRIEF]            = _("Calendar List");
00058        viewdefs[VIEW_JOURNAL]             = _("Journal");
00059        viewdefs[VIEW_DRAFTS]              = _("Drafts");
00060        viewdefs[VIEW_BLOG]         = _("Blog");
00061 }
00062 
00063 
00064 void tmplput_ROOM_COLLECTIONTYPE(StrBuf *Target, WCTemplputParams *TP) 
00065 {
00066        folder *Folder = (folder *)CTX;
00067        
00068        switch(Folder->view) {
00069        case VIEW_CALENDAR:
00070               StrBufAppendBufPlain(Target, HKEY("vevent"), 0);
00071               break;
00072        case VIEW_TASKS:
00073               StrBufAppendBufPlain(Target, HKEY("vtodo"), 0);
00074               break;
00075        case VIEW_ADDRESSBOOK:
00076               StrBufAppendBufPlain(Target, HKEY("vcard"), 0);
00077               break;
00078        case VIEW_NOTES:
00079               StrBufAppendBufPlain(Target, HKEY("vnotes"), 0);
00080               break;
00081        case VIEW_JOURNAL:
00082               StrBufAppendBufPlain(Target, HKEY("vjournal"), 0);
00083               break;
00084        case VIEW_WIKI:
00085               StrBufAppendBufPlain(Target, HKEY("wiki"), 0);
00086               break;
00087        }
00088 }
00089 
00090 
00091 
00092 int ConditionalRoomHasGroupdavContent(StrBuf *Target, WCTemplputParams *TP)
00093 {
00094        folder *Folder = (folder *)CTX;
00095 
00096        syslog(0, "-> %s: %d\n", ChrPtr(Folder->name), Folder->view);
00097 
00098        return ((Folder->view == VIEW_CALENDAR) || 
00099               (Folder->view == VIEW_TASKS) || 
00100               (Folder->view == VIEW_ADDRESSBOOK) ||
00101               (Folder->view == VIEW_NOTES) ||
00102               (Folder->view == VIEW_JOURNAL) );
00103 }
00104 
00105 
00106 
00107 
00108 int ConditionalIsRoomtype(StrBuf *Target, WCTemplputParams *TP)
00109 {
00110        wcsession *WCC = WC;
00111 
00112        if ((WCC == NULL) ||
00113            (TP->Tokens->nParameters < 3))
00114        {
00115               return ((WCC->CurRoom.view < VIEW_BBS) || 
00116                      (WCC->CurRoom.view > VIEW_MAX));
00117        }
00118 
00119        return WCC->CurRoom.view == GetTemplateTokenNumber(Target, TP, 2, VIEW_BBS);
00120 }
00121 
00122 
00123 void tmplput_CurrentRoomViewString(StrBuf *Target, WCTemplputParams *TP) 
00124 {
00125        wcsession *WCC = WC;
00126        StrBuf *Buf;
00127 
00128        if ((WCC == NULL) ||
00129            (WCC->CurRoom.defview >= VIEW_MAX) || 
00130            (WCC->CurRoom.defview < VIEW_BBS))
00131        {
00132               LogTemplateError(Target, "Token", ERR_PARM2, TP,
00133                              "Roomview [%ld] not valid\n", 
00134                              (WCC != NULL)? 
00135                              WCC->CurRoom.defview : -1);
00136               return;
00137        }
00138 
00139        Buf = NewStrBufPlain(_(viewdefs[WCC->CurRoom.defview]), -1);
00140        StrBufAppendTemplate(Target, TP, Buf, 0);
00141        FreeStrBuf(&Buf);
00142 }
00143 
00144 void tmplput_RoomViewString(StrBuf *Target, WCTemplputParams *TP) 
00145 {
00146        long CheckThis;
00147        StrBuf *Buf;
00148 
00149        CheckThis = GetTemplateTokenNumber(Target, TP, 0, 0);
00150        if ((CheckThis >= VIEW_MAX) || (CheckThis < VIEW_BBS))
00151        {
00152               LogTemplateError(Target, "Token", ERR_PARM2, TP,
00153                              "Roomview [%ld] not valid\n", 
00154                              CheckThis);
00155               return;
00156        }
00157 
00158        Buf = NewStrBufPlain(_(viewdefs[CheckThis]), -1);
00159        StrBufAppendTemplate(Target, TP, Buf, 0);
00160        FreeStrBuf(&Buf);
00161 }
00162 
00163 
00164 
00165 int ConditionalIsAllowedDefaultView(StrBuf *Target, WCTemplputParams *TP)
00166 {
00167        wcsession *WCC = WC;
00168        long CheckThis;
00169        
00170        if (WCC == NULL)
00171               return 0;
00172 
00173        CheckThis = GetTemplateTokenNumber(Target, TP, 2, 0);
00174        if ((CheckThis >= VIEW_MAX) || (CheckThis < VIEW_BBS))
00175        {
00176               LogTemplateError(Target, "Conditional", ERR_PARM2, TP,
00177                              "Roomview [%ld] not valid\n", 
00178                              CheckThis);
00179               return 0;
00180        }
00181 
00182        return allowed_default_views[CheckThis] != 0;
00183 }
00184 
00185 int ConditionalThisRoomDefView(StrBuf *Target, WCTemplputParams *TP)
00186 {
00187        wcsession *WCC = WC;
00188        long CheckThis;
00189 
00190        if (WCC == NULL)
00191               return 0;
00192 
00193        CheckThis = GetTemplateTokenNumber(Target, TP, 2, 0);
00194        return CheckThis == WCC->CurRoom.defview;
00195 }
00196 
00197 int ConditionalThisRoomCurrView(StrBuf *Target, WCTemplputParams *TP)
00198 {
00199        wcsession *WCC = WC;
00200        long CheckThis;
00201 
00202        if (WCC == NULL)
00203               return 0;
00204 
00205        CheckThis = GetTemplateTokenNumber(Target, TP, 2, 0);
00206        return CheckThis == WCC->CurRoom.view;
00207 }
00208 
00209 int ConditionalThisRoomHaveView(StrBuf *Target, WCTemplputParams *TP)
00210 {
00211        wcsession *WCC = WC;
00212        long CheckThis;
00213        
00214        if (WCC == NULL)
00215               return 0;
00216 
00217        CheckThis = GetTemplateTokenNumber(Target, TP, 2, 0);
00218        if ((CheckThis >= VIEW_MAX) || (CheckThis < VIEW_BBS))
00219        {
00220               LogTemplateError(Target, "Conditional", ERR_PARM2, TP,
00221                              "Roomview [%ld] not valid\n", 
00222                              CheckThis);
00223               return 0;
00224        }
00225 
00226        return exchangeable_views [WCC->CurRoom.defview][CheckThis] ;
00227 }
00228 
00229 void tmplput_ROOM_VIEW(StrBuf *Target, WCTemplputParams *TP) 
00230 {
00231        folder *Folder = (folder *)CTX;
00232        StrBufAppendPrintf(Target, "%d", Folder->view);
00233 }
00234 void tmplput_ROOM_DEFVIEW(StrBuf *Target, WCTemplputParams *TP) 
00235 {
00236        folder *Folder = (folder *)CTX;
00237        StrBufAppendPrintf(Target, "%d", Folder->defview);
00238 }
00239 
00240 
00241 void tmplput_CurrentRoomDefView(StrBuf *Target, WCTemplputParams *TP) 
00242 {
00243        wcsession *WCC = WC;
00244 
00245        StrBufAppendPrintf(Target, "%d", WCC->CurRoom.defview);
00246 }
00247 
00248 void 
00249 InitModule_ROOMVIEWS
00250 (void)
00251 {
00252        initialize_viewdefs();
00253 
00254        RegisterNamespace("THISROOM:VIEW_STRING", 0, 1, tmplput_CurrentRoomViewString, NULL, CTX_NONE);
00255        RegisterNamespace("ROOM:VIEW_STRING", 1, 2, tmplput_RoomViewString, NULL, CTX_NONE);
00256 
00257        RegisterConditional(HKEY("COND:ALLOWED_DEFAULT_VIEW"), 0, ConditionalIsAllowedDefaultView, CTX_NONE);
00258        RegisterConditional(HKEY("COND:THISROOM:DEFAULT_VIEW"), 0, ConditionalThisRoomDefView, CTX_NONE);
00259        RegisterNamespace("THISROOM:DEFAULT_VIEW", 0, 0, tmplput_CurrentRoomDefView, NULL, CTX_NONE);
00260        RegisterNamespace("ROOM:INFO:DEFVIEW", 0, 1, tmplput_ROOM_DEFVIEW, NULL, CTX_ROOMS);
00261 
00262        RegisterConditional(HKEY("COND:ROOM:TYPE_IS"), 0, ConditionalIsRoomtype, CTX_NONE);
00263 
00264        RegisterConditional(HKEY("COND:THISROOM:HAVE_VIEW"), 0, ConditionalThisRoomHaveView, CTX_NONE);
00265        RegisterConditional(HKEY("COND:ROOM:dav_CONTENT"), 0, ConditionalRoomHasGroupdavContent, CTX_ROOMS);
00266 
00267        RegisterConditional(HKEY("COND:THISROOM:CURR_VIEW"), 0, ConditionalThisRoomCurrView, CTX_NONE);
00268        RegisterNamespace("ROOM:INFO:VIEW", 0, 1, tmplput_ROOM_VIEW, NULL, CTX_ROOMS);
00269 
00270        RegisterNamespace("ROOM:INFO:COLLECTIONTYPE", 0, 1, tmplput_ROOM_COLLECTIONTYPE, NULL, CTX_ROOMS);
00271 
00272 
00273 
00274 }