template.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. #include <config.h>
  11. #endif
  12. /*
  13. * template.c: The actual HTML templates in a static variable
  14. *
  15. * All blame to Mike McCool
  16. */
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include "libadmin/libadmin.h"
  21. NSAPI_PUBLIC char *
  22. helpJavaScriptForTopic(char *topic)
  23. {
  24. char *tmp;
  25. char line[BIG_LINE];
  26. char *server = "admserv";
  27. char *type;
  28. int typeLen;
  29. /* Get the server type, without the instance name into type */
  30. tmp = strchr(server, '-');
  31. typeLen = tmp - server;
  32. type = (char *)MALLOC(typeLen + 1);
  33. type[typeLen] = '\0';
  34. while (typeLen--) {
  35. type[typeLen] = server[typeLen];
  36. }
  37. util_snprintf(line, BIG_LINE,
  38. "if ( top.helpwin ) {"
  39. " top.helpwin.focus();"
  40. " top.helpwin.infotopic.location='%s/%s/admin/tutor?!%s';"
  41. "} else {"
  42. " window.open('%s/%s/admin/tutor?%s', '" INFO_IDX_NAME "_%s', " HELP_WIN_OPTIONS ");}",
  43. getenv("SERVER_URL"), server, topic,
  44. getenv("SERVER_URL"), server, topic,
  45. type);
  46. FREE(type);
  47. return (STRDUP(line));
  48. }
  49. NSAPI_PUBLIC char *
  50. helpJavaScript()
  51. {
  52. char *tmp, *sn;
  53. tmp = STRDUP(getenv("SCRIPT_NAME"));
  54. if (strlen(tmp) > (unsigned)BIG_LINE)
  55. tmp[BIG_LINE - 2] = '\0';
  56. sn = strrchr(tmp, '/');
  57. if (sn)
  58. *sn++ = '\0';
  59. FREE(tmp);
  60. return helpJavaScriptForTopic(sn);
  61. }