Splash page: list of open items

Previous: complain(): Returning error messages ] [ Top: The procdef manager ] [ Next: list: Displaying the procdef directory ]

The page displayed when no command is given is the splash page. If we go from the example in the UI mockup, then we want to show open versions owned by the current user, and a folder-like system of items which are editable by the current user. Lots of permissions involved here.

So anyway, this page is the reason I spun off the user module. No surprise there.
 
printf ("Content-type: text/html\n\n");
printf ("<html><head><title>WFTK PDM works in progress</title></head>\n");
printf ("<body bgcolor=\"ffffff\">\n");
printf ("<h2>Open process definition</h2><hr>\n");
printf ("<font size=+1>Work in progress</font>\n");

xml = user_list (current_user, "wftkpdm", NULL, "edit");
See Loading the repository index from index.xml
holder = xml_firstelem (xml);
while (holder) {
   strcpy (sbuf, xml_attrval (holder, "object"));
   mark = strrchr (sbuf, '_');
   if (mark) {
      *mark++ = '\0';
   } else {
      mark = "";
   }
   item = xml_firstelem (directory);
   while (item) {
      if (!strcmp (xml_attrval (item, "id"), sbuf)) {
         xml_set (holder, "title", xml_attrval (item, "title"));
         break;
      }
      item = xml_nextelem (item);
   }
   if (!strcmp ("", xml_attrval (holder, "title"))) {
      xml_set (holder, "title", xml_attrval (holder, "object"));
   }
   holder = xml_nextelem (holder);
}

/* Here we'll sort things.  Later. */

printf ("<form action=\"%s?command=delete\" method=POST>\n", xml_attrval (environment, "SCRIPT_NAME"));
holder = xml_firstelem (xml);
while (holder) {
   if (!strcmp (holder->name, "object")) {
      strcpy (sbuf, xml_attrval (holder, "object"));
      mark = strrchr (sbuf, '_');
      if (mark) {
         *mark++ = '\0';
      } else {
         mark = "";
      }
      printf ("&nbsp;&nbsp;&nbsp;<input type=checkbox name=\"itemver_%s_%s\">&nbsp;", sbuf, mark);
      printf ("<a href=\"%s?command=edit&item=%s&ver=%s\">%s</a>",
              xml_attrval (environment, "SCRIPT_NAME"), sbuf, mark,
              xml_attrval (holder, "title"));
      printf (" (ver '%s')
\n", mark); } holder = xml_nextelem (holder); } xml_free (xml); printf ("<input type=submit value=\"Delete selected working versions\">\n"); printf ("</form>\n"); printf ("<p>\n"); printf ("<font size=+1>Process definitions</font>\n"); holder = xml_create ("temp"); xml = xml_create ("temp"); show_list (current_user, "workflow", NULL, "view"); xml_free (holder); xml_free (xml); printf ("</body></html>\n");


show_list: Showing lists of permitted objects
Here's a little recursive function to build up lists of objects that we have permission to, in a folder format which reflects the structure of group-includes. It assumes that the directory is already loaded. It makes use of the global 'holder' to mark items as already displayed, and 'xml' to track which subfolders it's already displayed (the latter serves to prevent problems should we have a cycle in our folder structure.)
 
void show_list (XML * for_whom, const char * class, const char * object, const char * permission)
{
   XML * list;
   XML * listee;
   XML * item;
   XML * included;

   list = user_list (for_whom, class, object, permission);
   listee = xml_firstelem (list);
   while (listee) {
      item = xml_firstelem (directory);
      while (item) {
         if (!strcmp ("object", listee->name) &&
             !strcmp (xml_attrval (item, "id"), xml_attrval (listee, "object"))) {
            if (strcmp ("", xml_attrval (holder, xml_attrval (item, "id")))) {
               xml_set (listee, "invalid", "yep");
               break;
            }
            xml_set (holder, xml_attrval (item, "id"), "!");
            xml_set (listee, "title", xml_attrval (item, "title"));
            break;
         }
         item = xml_nextelem (item);
      }
      if (!strcmp ("", xml_attrval (listee, "title"))) {
         xml_set (listee, "invalid", "yep");
      }
      listee = xml_nextelem (listee);
   }

   /* Here we'll sort things.  Later. */

   printf ("<ul>\n");
   listee = xml_firstelem (list);
   while (listee) {
      if (!strcmp ("group-include", listee->name)) {
         if (!strcmp ("", xml_attrval (xml, xml_attrval (listee, "name")))) {
            xml_set (xml, xml_attrval (listee, "name"), "!");
            included = group_get (xml_attrval (listee, "name"));
            if (included) {
               printf ("<li> Via group <i>%s</i>:\n", xml_attrval (included, "name"));
               show_list (included, class, object, permission);
               xml_free (included);
            }
         }
      } else if (!strcmp ("", xml_attrval (listee, "invalid"))) {
         printf ("<li> <a href=\"%s?command=view&item=%s\">%s</a>\n",
                 xml_attrval (environment, "SCRIPT_NAME"), xml_attrval (listee, "object"),
                 xml_attrval (listee, "title"));
      }
      listee = xml_nextelem (listee);
   }
   xml_free (list);
   printf ("</ul>\n");
}
Previous: complain(): Returning error messages ] [ Top: lpml alpha ] [ Next: list: Displaying the procdef directory ]


This code and documentation are released under the terms of the GNU license. They are additionally copyright (c) 2000, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license.