Cleaned up some of the comments ... removed vestiges of last year's doxygen experiment
[citadel.git] / webcit / useredit.c
index 19cbbf001dd7276e05c5f6c30f0fab8532666253..2446b3c2e9153964b22bbaf06ec291eedd8d2ca1 100644 (file)
@@ -1,21 +1,15 @@
 /*
  * $Id$
  */
-/**
- * \defgroup AdminTasks Administrative screen to add/change/delete user accounts
- * \ingroup CitadelConfig
- *
- */
-/*@{*/
 
 #include "webcit.h"
 #include "webserver.h"
 
 
 /**
- * \brief show a list of available users to edit them
- * \param message the header message???
- * \param preselect which user should be selected in the browser
+ *  show a list of available users to edit them
+ *  message the header message???
+ *  preselect which user should be selected in the browser
  */
 void select_user_to_edit(char *message, char *preselect)
 {/*
@@ -102,21 +96,47 @@ 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;
+       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->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, '|');
+       ul->LastLogonT = StrBufExtract_long(SerializedUser, 7, '|');
+       ul->DaysTillPurge = StrBufExtract_int(SerializedUser, 8, '|');
+       return ul;
+}
+
 void DeleteUserListEntry(void *vUserList)
 {
        UserListEntry *ul = (UserListEntry*) vUserList;
        FreeStrBuf(&ul->UserName);
-       FreeStrBuf(&ul->LastLogon);
        FreeStrBuf(&ul->Passvoid);
        free(ul);
 }
@@ -130,18 +150,17 @@ UserListEntry* NewUserListEntry(StrBuf *SerializedUserList)
 
        ul = (UserListEntry*) malloc(sizeof(UserListEntry));
        ul->UserName = NewStrBuf();
-       ul->LastLogon = NewStrBuf();
        ul->Passvoid = NewStrBuf();
 
        StrBufExtract_token(ul->UserName, SerializedUserList, 0, '|');
        ul->AccessLevel = StrBufExtract_int(SerializedUserList, 1, '|');
        ul->UID = StrBufExtract_int(SerializedUserList, 2, '|');
-       StrBufExtract_token(ul->LastLogon, SerializedUserList, 3, '|');
-       /// TODO: ul->LastLogon -> ulLastLogonT
+       ul->LastLogonT = StrBufExtract_long(SerializedUserList, 3, '|');
        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,11 +372,16 @@ 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);
+       StrBufAppendPrintf(Target,"%ld", ul->LastLogonT, 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 +398,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,11 +424,27 @@ 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
- * \param usernum the number of the user on the citadel server
+ *  Locate the message number of a user's vCard in the current room
+ *  username the plaintext name of the user
+ *  usernum the number of the user on the citadel server
  * \return the message id of his vcard
  */
 long locate_user_vcard(char *username, long usernum) {
@@ -461,9 +515,9 @@ TRYAGAIN:
 
 
 /**
- * \brief Display the form for editing a user's address book entry
- * \param username the name of the user
- * \param usernum the citadel-uid of the user
+ *  Display the form for editing a user's address book entry
+ *  username the name of the user
+ *  usernum the citadel-uid of the user
  */
 void display_edit_address_book_entry(char *username, long usernum) {
        char roomname[SIZ];
@@ -504,18 +558,56 @@ 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);
+       }
 
-/**
- * \brief Edit a user.  
+       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);
+}
+
+
+
+/* *
+ *  Edit a user.  
  * If supplied_username is null, look in the "username"
  * web variable for the name of the user to edit.
  * 
  * If "is_new" is set to nonzero, this screen will set the web variables
  * 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?
- */
+ *  supplied_username user to look up or NULL if to search in the environment
+ *  is_new should we create the user?
+ * /
 void display_edituser(char *supplied_username, int is_new) {
        char buf[1024];
        char error_message[1024];
@@ -687,10 +779,10 @@ void display_edituser(char *supplied_username, int is_new) {
        wDumpContent(1);
 
 }
-
+*/
 
 /**
- * \brief do the backend operation of the user edit on the server
+ *  do the backend operation of the user edit on the server
  */
 void edituser(void) {
        char message[SIZ];
@@ -761,8 +853,8 @@ void edituser(void) {
 }
 
 /*
- * \brief burge a user 
- * \param username the name of the user to remove
+ *  burge a user 
+ *  username the name of the user to remove
  */
 void delete_user(char *username) {
        char buf[SIZ];
@@ -784,7 +876,7 @@ void delete_user(char *username) {
 
 
 /**
- * \brief create a new user
+ *  create a new user
  * take the web environment username and create it on the citadel server
  */
 void create_user(void) {
@@ -833,15 +925,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);
 }
-/*@}*/