* templatize user editing
authorWilfried Göesgens <willi@citadel.org>
Sun, 28 Sep 2008 21:23:10 +0000 (21:23 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sun, 28 Sep 2008 21:23:10 +0000 (21:23 +0000)
* swap order of DoTemplate to be more intuitive
* add missing break on error to EvaluateConditional
* add date printing functions (unfinishded)

webcit/http_datestring.c
webcit/notes.c
webcit/static/t/userlist_detailview.html [new file with mode: 0644]
webcit/subst.c
webcit/useredit.c
webcit/webcit.h

index 33f57846414fbcc6a3cd4101fa0f70d2a09f7643..d4c69bf6c250506d534db938977b737c028cd839 100644 (file)
@@ -64,4 +64,25 @@ void http_datestring(char *buf, size_t n, time_t xtime) {
 }
 
 
+void tmplput_nowstr(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       time_t now;
+       now = time(NULL);
+       StrEscAppend(Target, NULL, asctime(localtime(&now)), 0, 0);
+}
+void tmplput_nowno(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       time_t now;
+       now = time(NULL);
+       StrBufAppendPrintf(Target, "%l", now);
+}
+
+void 
+InitModule_DATE
+(void)
+{
+       RegisterNamespace("DATE:NOW:STR", 1, 2, tmplput_nowstr, CTX_NONE);
+       RegisterNamespace("DATE:NOW:NO", 1, 2, tmplput_nowno, CTX_NONE);
+}
+
 /*@}*/
index 58e9bc8508de379f4bfa4ea40ee7e4aa216c8e6c..d08b0777fca208e7e9d9a3900bbaaa17e42a0488 100644 (file)
@@ -347,7 +347,7 @@ void display_note(long msgnum, int unread) {
        if (v) {
 //             display_vnote_div(v);
                DoTemplate(HKEY("vnoteitem"),
-                          v, WC->WBuf, CTX_VNOTE);
+                          WC->WBuf, v, CTX_VNOTE);
                        
 
                /* uncomment these lines to see ugly debugging info 
diff --git a/webcit/static/t/userlist_detailview.html b/webcit/static/t/userlist_detailview.html
new file mode 100644 (file)
index 0000000..b0e5e9e
--- /dev/null
@@ -0,0 +1,42 @@
+<?=("head")>
+<?=("important_msg")>
+<?ICONBAR>
+<div id="banner">
+  <h1><?_("Edit user account: ")><?USERLIST:USERNAME("X")></h1>
+</div>
+<div id="content" class="service">
+<div class="fix_scrollbar_bug">
+<table class="useredit_background"><tr><td>
+<form method="POST" action="edituser">
+<input type="hidden" name="username" value="<?USERLIST:USERNAME("X")>">
+<input type="hidden" name="is_new" value="<?BSTR("is_new")>">
+<input type="hidden" name="usernum" value="<?USERLIST:UID>">
+<input type="hidden" name="nonce" value="<?NONCE>"> 
+<input type="hidden" name="flags" value="<?USERLIST:FLAGS>">
+<center><table>
+<tr><td><?_("User name:")></td><td><input type="text" name="newname" value="<?USERLIST:USERNAME("X")>" maxlength="63"></td></tr>
+<tr><td><?_("Password")></td><td><input type="password" name="password" value="<?USERLIST:PASSWD("X")>" maxlength="20"></td></tr>
+<tr><td><?_("Permission to send Internet mail")></td><td><input type="checkbox" name="inetmail" value="yes" <?%("COND:USERLIST:FLAG:USE_INTERNET", 1, 1, 1, "checked", "")>></td></tr>
+<tr><td><?_("Number of logins")></td><td><input type="text" name="timescalled" value="<?USERLIST:NLOGONS>" maxlength="6"></td></tr>
+<tr><td><?_("Messages submitted")></td><td><input type="text" name="msgsposted" value="<?USERLIST:NPOSTS>" maxlength="6"></td></tr>
+<tr><td><?_("Access level")></td><td><select name="axlevel">
+        <option <?%("COND:USERACCESS", 1, 1, 0, 'selected="selected"', "")> value="0">0 - <?_("Deleted")></option>
+        <option <?%("COND:USERACCESS", 1, 1, 1, 'selected="selected"', "")> value="1">1 - <?_("New User")></option>
+        <option <?%("COND:USERACCESS", 1, 1, 2, 'selected="selected"', "")> value="2">2 - <?_("Problem User")></option>
+        <option <?%("COND:USERACCESS", 1, 1, 3, 'selected="selected"', "")> value="3">3 - <?_("Local User")></option>
+        <option <?%("COND:USERACCESS", 1, 1, 4, 'selected="selected"', "")> value="4">4 - <?_("Network User")></option>
+        <option <?%("COND:USERACCESS", 1, 1, 5, 'selected="selected"', "")> value="5">5 - <?_("Preferred User")></option>
+        <option <?%("COND:USERACCESS", 1, 1, 6, 'selected="selected"', "")> value="6">6 - <?_("Aide")></option>
+</select></td></tr>
+<tr><td><?_("User ID number")></td><td><input type="text" name="usernum" value="<?USERLIST:UID>" maxlength="7"></td></tr>
+<tr><td><?_("Date and time of last login")></td><td><select name="lastcall">
+  <option selected value="<?USERLIST:LASTLOGON:NO>"><?USERLIST:LASTLOGON:STR></option>
+  <option value="<?TIME:NOW:NO>"><?TIME:NOW:STR></option>
+</select></td></tr>
+<tr><td><?_("Auto-purge after this many days")></td><td><input type="text" name="purgedays" value="<?USERLIST:DAYSTILLPURGE>" maxlength="5"></td></tr>
+</table>
+<input type="submit" name="ok_button" value="<?_("Save changes")>">&nbsp; <input type="submit" name="cancel" value="<?_("Cancel")>"><br /><br /></form>
+</center>
+</td></tr></table></div>
+<?=("trailing")>
index d5297d14c89f88a1c12b37ffff965adcae5ddf36..6ede4a74cbc9c9c93d713df2c268caef8d4c6417 100644 (file)
@@ -815,6 +815,7 @@ int EvaluateConditional(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmp
                        ChrPtr(pTmpl->FileName),
                        Token->Line,
                        ChrPtr(Token->FlatToken));
+               return 0;
        }
            
        Cond = (ConditionalStruct *) vConditional;
@@ -1150,7 +1151,7 @@ const char* PrintTemplate(void *vSubst)
  * \brief Display a variable-substituted template
  * \param templatename template file to load
  */
-void DoTemplate(const char *templatename, long len, void *Context, StrBuf *Target, int ContextType) 
+void DoTemplate(const char *templatename, long len, StrBuf *Target, void *Context, int ContextType) 
 {
        HashList *Static;
        HashList *StaticLocal;
@@ -1383,7 +1384,7 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
                        It->DoSubTemplate(SubBuf, vContext, Tokens);
                DoTemplate(Tokens->Params[1]->Start,
                           Tokens->Params[1]->len,
-                          vContext, SubBuf, 
+                          SubBuf, vContext,
                           It->ContextType);
                        
                StrBufAppendBuf(Target, SubBuf, 0);
@@ -1472,19 +1473,19 @@ void tmpl_do_boxed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Con
                StrBuf *Headline = NewStrBuf();
                DoTemplate(Tokens->Params[1]->Start, 
                           Tokens->Params[1]->len,
-                          Context, 
                           Headline, 
+                          Context, 
                           ContextType);
                SVPutBuf("BOXTITLE", Headline, 0);
        }
        
-       DoTemplate(HKEY("beginbox"), Context, Target, ContextType);
+       DoTemplate(HKEY("beginbox"), Target, Context, ContextType);
        DoTemplate(Tokens->Params[0]->Start, 
                   Tokens->Params[0]->len,
-                  Context, 
                   Target, 
+                  Context, 
                   ContextType);
-       DoTemplate(HKEY("endbox"), Context, Target, ContextType);
+       DoTemplate(HKEY("endbox"), Target, Context, ContextType);
 }
 
 void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
@@ -1500,8 +1501,8 @@ void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Co
                if (Tokens->Params[i * 2]->len > 0) {
                        DoTemplate(Tokens->Params[i * 2]->Start, 
                                   Tokens->Params[i * 2]->len,
-                                  Context,
                                   TabNames[i],
+                                  Context,
                                   ContextType);
                }
                else { 
@@ -1516,8 +1517,8 @@ void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Co
 
                DoTemplate(Tokens->Params[i * 2 + 1]->Start, 
                           Tokens->Params[i * 2 + 1]->len,
-                          Context, 
                           Target,
+                          Context, 
                           ContextType);
                StrEndTab(Target, i, nTabs);
        }
index 19cbbf001dd7276e05c5f6c30f0fab8532666253..f016b2e21df45ed5c61f8be932f701caa3b3306d 100644 (file)
@@ -102,16 +102,46 @@ void select_user_to_edit(char *message, char *preselect)
 
 
 typedef struct _UserListEntry {
-       StrBuf *UserName;
-       int AccessLevel;
        int UID;
-       StrBuf *LastLogon;
-       time_t LastLogonT;
+       int AccessLevel;
        int nLogons;
        int nPosts;
+
+       StrBuf *UserName;
        StrBuf *Passvoid;
+       StrBuf *LastLogon;
+       time_t LastLogonT;
+       /* Just available for Single users to view: */
+       unsigned int Flags;
+       int DaysTillPurge;
 } UserListEntry;
 
+
+UserListEntry* NewUserListOneEntry(StrBuf *SerializedUser)
+{
+       UserListEntry *ul;
+
+       if (StrLength(SerializedUser) < 8) 
+               return NULL;
+
+       ul = (UserListEntry*) malloc(sizeof(UserListEntry));
+       ul->UserName = NewStrBuf();
+       ul->LastLogon = NewStrBuf();
+       ul->Passvoid = NewStrBuf();
+
+       StrBufExtract_token(ul->UserName, SerializedUser, 0, '|');
+       StrBufExtract_token(ul->Passvoid, SerializedUser, 1, '|');
+       ul->Flags = (unsigned int)StrBufExtract_long(SerializedUser, 2, '|');
+       ul->nLogons = StrBufExtract_int(SerializedUser, 3, '|');
+       ul->nPosts = StrBufExtract_int(SerializedUser, 4, '|');
+       ul->AccessLevel = StrBufExtract_int(SerializedUser, 5, '|');
+       ul->UID = StrBufExtract_int(SerializedUser, 6, '|');
+       StrBufExtract_token(ul->LastLogon, SerializedUser, 7, '|');
+       /// TODO: ul->LastLogon -> ulLastLogonT
+       ul->DaysTillPurge = StrBufExtract_int(SerializedUser, 8, '|');
+       return ul;
+}
+
 void DeleteUserListEntry(void *vUserList)
 {
        UserListEntry *ul = (UserListEntry*) vUserList;
@@ -141,7 +171,8 @@ UserListEntry* NewUserListEntry(StrBuf *SerializedUserList)
        ul->nLogons = StrBufExtract_int(SerializedUserList, 4, '|');
        ul->nPosts = StrBufExtract_int(SerializedUserList, 5, '|');
        StrBufExtract_token(ul->Passvoid, SerializedUserList, 6, '|');
-
+       ul->Flags = 0;
+       ul->DaysTillPurge = -1;
        return ul;
 }
 
@@ -353,12 +384,17 @@ void tmplput_USERLIST_UID(StrBuf *Target, int nArgs, WCTemplateToken *Token, voi
        StrBufAppendPrintf(Target, "%d", ul->UID, 0);
 }
 
-void tmplput_USERLIST_LastLogon(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+void tmplput_USERLIST_LastLogonNo(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
 {
        UserListEntry *ul = (UserListEntry*) Context;
 
        StrBufAppendBuf(Target, ul->LastLogon, 0);
 }
+void tmplput_USERLIST_LastLogonStr(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       UserListEntry *ul = (UserListEntry*) Context;
+       StrEscAppend(Target, NULL, asctime(localtime(&ul->LastLogonT)), 0, 0);
+}
 
 void tmplput_USERLIST_nLogons(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
 {
@@ -374,6 +410,20 @@ void tmplput_USERLIST_nPosts(StrBuf *Target, int nArgs, WCTemplateToken *Token,
        StrBufAppendPrintf(Target, "%d", ul->nPosts, 0);
 }
 
+void tmplput_USERLIST_Flags(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       UserListEntry *ul = (UserListEntry*) Context;
+
+       StrBufAppendPrintf(Target, "%d", ul->Flags, 0);
+}
+
+void tmplput_USERLIST_DaysTillPurge(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
+{
+       UserListEntry *ul = (UserListEntry*) Context;
+
+       StrBufAppendPrintf(Target, "%d", ul->DaysTillPurge, 0);
+}
+
 int ConditionalUser(WCTemplateToken *Tokens, void *Context, int ContextType)
 {
        UserListEntry *ul = (UserListEntry*) Context;
@@ -386,7 +436,23 @@ int ConditionalUser(WCTemplateToken *Tokens, void *Context, int ContextType)
        else 
                return 0;
 }
+
+int ConditionalFlagINetEmail(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       UserListEntry *ul = (UserListEntry*) Context;
+       return (ul->Flags & US_INTERNET) != 0;
+}
+
+int ConditionalUserAccess(WCTemplateToken *Tokens, void *Context, int ContextType)
+{
+       UserListEntry *ul = (UserListEntry*) Context;
+
+       if (Tokens->Params[3]->Type == TYPE_LONG)
+               return (Tokens->Params[3]->lvalue == ul->AccessLevel);
+       else
+               return 0;
+}
+
 /**
  * \brief Locate the message number of a user's vCard in the current room
  * \param username the plaintext name of the user
@@ -504,9 +570,47 @@ void display_edit_address_book_entry(char *username, long usernum) {
 }
 
 
+void display_edituser(char *supplied_username, int is_new) {
+       UserListEntry* UL;
+       StrBuf *Buf;
+       char error_message[1024];
+       char MajorStatus;
+       char username[256];
+
+       if (supplied_username != NULL) {
+               safestrncpy(username, supplied_username, sizeof username);
+       }
+       else {
+               safestrncpy(username, bstr("username"), sizeof username);
+       }
+
+       Buf = NewStrBuf();
+       serv_printf("AGUP %s", username);
+       StrBuf_ServGetln(Buf);
+       MajorStatus = ChrPtr(Buf)[0];
+       StrBufCutLeft(Buf, 4);
+       if (MajorStatus != '2') {
+               ///TODO ImportantMessage
+               sprintf(error_message,
+                       "<img src=\"static/error.gif\" align=center>"
+                       "%s<br /><br />\n", ChrPtr(Buf));
+               select_user_to_edit(error_message, username);
+               FreeStrBuf(&Buf);
+               return;
+       }
+       else {
+               UL = NewUserListOneEntry(Buf);
+               output_headers(1, 0, 0, 0, 1, 0);
+               DoTemplate(HKEY("userlist_detailview"), NULL, (void*) UL, CTX_USERLIST);
+               end_burst();
+               
+       }
+       FreeStrBuf(&Buf);
+}
+
 
 
-/**
+/* *
  * \brief Edit a user.  
  * If supplied_username is null, look in the "username"
  * web variable for the name of the user to edit.
@@ -515,7 +619,7 @@ void display_edit_address_book_entry(char *username, long usernum) {
  * to send the user to the vCard editor next.
  * \param supplied_username user to look up or NULL if to search in the environment
  * \param is_new should we create the user?
- */
+ * /
 void display_edituser(char *supplied_username, int is_new) {
        char buf[1024];
        char error_message[1024];
@@ -687,7 +791,7 @@ void display_edituser(char *supplied_username, int is_new) {
        wDumpContent(1);
 
 }
-
+*/
 
 /**
  * \brief do the backend operation of the user edit on the server
@@ -833,13 +937,21 @@ InitModule_USEREDIT
        WebcitAddUrlHandler(HKEY("edituser"), edituser, 0);
        WebcitAddUrlHandler(HKEY("create_user"), create_user, 0);
 
-       RegisterNamespace("USERLIST:USERNAME",  0, 1, tmplput_USERLIST_UserName, CTX_USERLIST);
-       RegisterNamespace("USERLIST:ACCLVLNO",  0, 0, tmplput_USERLIST_AccessLevelNo, CTX_USERLIST);
-       RegisterNamespace("USERLIST:ACCLVLSTR", 0, 0, tmplput_USERLIST_AccessLevelStr, CTX_USERLIST);
-       RegisterNamespace("USERLIST:UID",       0, 0, tmplput_USERLIST_UID, CTX_USERLIST);
-       RegisterNamespace("USERLIST:LASTLOGON", 0, 0, tmplput_USERLIST_LastLogon, CTX_USERLIST);
-       RegisterNamespace("USERLIST:NLOGONS",   0, 0, tmplput_USERLIST_nLogons, CTX_USERLIST);
-       RegisterNamespace("USERLIST:NPOSTS",    0, 0, tmplput_USERLIST_nPosts, CTX_USERLIST);
+       RegisterNamespace("USERLIST:USERNAME",      0, 1, tmplput_USERLIST_UserName, CTX_USERLIST);
+       RegisterNamespace("USERLIST:ACCLVLNO",      0, 0, tmplput_USERLIST_AccessLevelNo, CTX_USERLIST);
+       RegisterNamespace("USERLIST:ACCLVLSTR",     0, 0, tmplput_USERLIST_AccessLevelStr, CTX_USERLIST);
+       RegisterNamespace("USERLIST:UID",           0, 0, tmplput_USERLIST_UID, CTX_USERLIST);
+       RegisterNamespace("USERLIST:LASTLOGON:STR", 0, 0, tmplput_USERLIST_LastLogonStr, CTX_USERLIST);
+       RegisterNamespace("USERLIST:LASTLOGON:NO",  0, 0, tmplput_USERLIST_LastLogonNo, CTX_USERLIST);
+       RegisterNamespace("USERLIST:NLOGONS",       0, 0, tmplput_USERLIST_nLogons, CTX_USERLIST);
+       RegisterNamespace("USERLIST:NPOSTS",        0, 0, tmplput_USERLIST_nPosts, CTX_USERLIST);
+                                                   
+       RegisterNamespace("USERLIST:FLAGS",         0, 0, tmplput_USERLIST_Flags, CTX_USERLIST);
+       RegisterNamespace("USERLIST:DAYSTILLPURGE", 0, 0, tmplput_USERLIST_DaysTillPurge, CTX_USERLIST);
+
+       RegisterConditional(HKEY("COND:USERNAME"),  0,    ConditionalUser, CTX_USERLIST);
+       RegisterConditional(HKEY("COND:USERACCESS"), 0,   ConditionalUserAccess, CTX_USERLIST);
+       RegisterConditional(HKEY("COND:USERLIST:FLAG:USE_INTERNET"), 0, ConditionalFlagINetEmail, CTX_USERLIST);
 
        RegisterConditional(HKEY("COND:USERNAME"), 0, ConditionalUser, CTX_USERLIST);
        RegisterIterator("USERLIST", 0, NULL, iterate_load_userlist, NULL, DeleteHash, CTX_USERLIST);
index 9ba816a3c5c43c1e33aa73eeb144b60069849d28..9c1a0583bbea768c25684c0618d3a94e6f6b5612 100644 (file)
@@ -352,8 +352,8 @@ void SVCallback(char *keyname, size_t keylen,  WCHandlerFunc fcn_ptr);
 void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref);
 #define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c)
 
-void DoTemplate(const char *templatename, long len, void *Context, StrBuf *Target, int ContextType);
-#define do_template(a, b) DoTemplate(a, sizeof(a) -1, b, NULL, 0);
+void DoTemplate(const char *templatename, long len, StrBuf *Target, void *Context, int ContextType);
+#define do_template(a, b) DoTemplate(a, sizeof(a) -1, NULL, b, 0);
 void url_do_template(void);
 
 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup);