]> andersk Git - moira.git/blobdiff - regtape/employee.dc
Initial revision
[moira.git] / regtape / employee.dc
index cfd198392e7e9c5b815e9860e6e0228d7d3ce1b0..b271163a809affca4ff70325a8881efa6ffc1085 100644 (file)
@@ -5,8 +5,8 @@
 #include <strings.h>
 #include <ctype.h>
 #include <sys/time.h>
-#include <sms.h>
-#include <sms_app.h>
+#include <moira.h>
+#include <moira_site.h>
 
 
 ##define WHO 11859             /* root */
 
 #define LEN_ID 9
 #define LEN_NAME 30
-#define LEN_OFFICE 12
+#define LEN_OFFICE 24
 #define LEN_PHONE 12
 #define LEN_PHONE2 12
-#define LEN_DEPT 19
-#define LEN_TITLE 49
-#define LEN_USERNAME 29
+#define LEN_DEPT 20
+#define LEN_TITLE 50
+#define LEN_USERNAME 30
 #define LEN_HOST 55
 
 
 struct entry {
+    char *name;
     char *last;
     char *first;
     char *middle;
@@ -61,6 +62,7 @@ struct entry {
     char *dept;
     char *address;
     char *phone;
+    char *phone2;
     char *email;
 };
 
@@ -103,6 +105,9 @@ char **argv;
        exit(1);
     }
 
+    setlinebuf(stdout);
+    setlinebuf(stderr);
+
 ##  ingres sms
 ##  range of u is users
 
@@ -137,67 +142,83 @@ struct entry *get_next_entry(in)
 FILE *in;
 {
     static struct entry e;
-    static char buf[BUFSIZ], mid[16], eid[16], email[256], phone[13];
-    int ends_sr, ends_jr, ends_iii, ends_iv;
+    static char buf[BUFSIZ], mid[16], eid[16], email[256];
+    static char name[LEN_NAME+1], sname[LEN_NAME+1], id[LEN_ID+1];
+    static char office[LEN_OFFICE+1], phone[LEN_PHONE+1], phone2[LEN_PHONE2+1];
+    static char dept[LEN_DEPT+1], title[LEN_TITLE+1], username[LEN_USERNAME+1];
+    static char host[LEN_HOST+1];
+    int ends_sr, ends_jr, ends_iii, ends_iv, ends_ii, ends_v;
     char *p;
 
     if (fgets(buf, sizeof(buf), in) == NULL)
       return((struct entry *)NULL);
-    buf[LEN_NAME] = 0;
-    p = index(&buf[LOC_NAME], ',');
+
+    strncpy(id, &buf[LOC_ID], LEN_ID); id[LEN_ID] = 0;
+    strncpy(name, &buf[LOC_NAME], LEN_NAME); name[LEN_NAME] = 0;
+    strncpy(office, &buf[LOC_OFFICE], LEN_OFFICE); office[LEN_OFFICE] = 0;
+    strncpy(phone, &buf[LOC_PHONE], LEN_PHONE); phone[LEN_PHONE] = 0;
+    strncpy(phone2, &buf[LOC_PHONE2], LEN_PHONE2); phone2[LEN_PHONE2] = 0;
+    strncpy(dept, &buf[LOC_DEPT], LEN_DEPT); dept[LEN_DEPT] = 0;
+    strncpy(title, &buf[LOC_TITLE], LEN_TITLE); title[LEN_TITLE] = 0;
+    strncpy(username, &buf[LOC_USERNAME], LEN_USERNAME); username[LEN_USERNAME] = 0;
+    strncpy(host, &buf[LOC_HOST], LEN_HOST); host[LEN_HOST] = 0;
+
+    strcpy(sname, name);
+    e.name = strtrim(sname);
+    p = index(name, ',');
     if (p)
       *p = 0;
-    e.last = strtrim(&buf[LOC_NAME]);
+    e.last = strtrim(name);
     if (p) {
-       e.first = p + 3;
+       p++;
+       while (isspace(*p))
+         p++;
+       e.first = p;
        if (p = index(e.first, ' ')) {
            *p = 0;
+           e.first = strtrim(e.first);
            e.middle = strtrim(p + 1);
-       } else
-         e.middle = "";
-    } else
-      e.first = "";
-    e.first = strtrim(e.first);
-    ends_sr = ends_jr = ends_iii = ends_iv = 0;
+       } else {
+           e.first = strtrim(e.first);
+           e.middle = "";
+       }
+    } else {
+       e.first = "";
+       e.middle = "";
+    }
+    ends_sr = ends_jr = ends_iii = ends_iv = ends_ii = ends_v = 0;
     LookForSt(e.last);
     LookForO(e.last);
-    LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
-    LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
+    LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv,
+                   &ends_ii, &ends_v);
+    LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv,
+                   &ends_ii, &ends_v);
     FixCase(e.last);
     FixCase(e.first);
     FixCase(e.middle);
 
-    strncpy(mid, buf, LEN_ID);
-    e.id = mid;
+    e.id = id;
     e.eid = eid;
     EncryptID(e.eid, e.id, e.first, e.last);
 
-    e.address = &buf[LOC_OFFICE];
-    e.address[LEN_OFFICE] = 0;
-    e.address = strtrim(e.address);
-    e.phone = phone;
-    strncpy(phone, &buf[LOC_PHONE], LEN_PHONE);
-    e.phone = strtrim(e.phone);
-    e.dept = &buf[LOC_DEPT];
-    e.dept[LEN_DEPT] = 0;
-    e.dept = strtrim(e.dept);
-    e.title = &buf[LOC_TITLE];
-    e.title[LEN_TITLE] = 0;
-    e.title = strtrim(e.title);
+    e.address = strtrim(office);
+    e.phone = strtrim(phone);
+    e.phone2 = strtrim(phone2);
+    e.dept = strtrim(dept);
+    e.title = strtrim(title);
 
     e.class = "MITS";
     if (!strcmp(e.dept, "PROJECT ATHENA"))
       e.class = "STAFF";
-    else if (substr(e.title, "PROF"))
+    else if (substr(e.title, "PROF") || substr(e.title, "LECTURE"))
       e.class = "FACULTY";
     else if (!strcmp(e.title, "VISITING SCIENTIST"))
       e.class = "VSCIENTI";
 
-    strncpy(email, &buf[LOC_USERNAME], LEN_USERNAME);
-    strtrim(email);
-    if (buf[LOC_HOST] == '@')
-      strncat(email, &buf[LOC_HOST], LEN_HOST);
-    e.email = strtrim(email);
+    strcpy(email, strtrim(username));
+    if (host[0] == '@')
+      strncat(email, strtrim(host));
+    e.email = email;
 
     return(&e);
 }
@@ -208,29 +229,50 @@ struct entry *e;
 ##{
     int changed, nochange;
     char buf[BUFSIZ], *from, *to;
-##  char *first, *last, *eid;
-##  char class[9], oaddr[17], ophone[17], dept[17];
-##  int id;
+##  char *first, *last, *eid, *sid, *name, *title, *phone2, *rdept, *rtitle;
+##  char *raddr, *rhphone, *rophone;
+##  char class[9], oaddr[25], ophone[17], dept[128];
+##  int id, status;
 
     first = e->first;
+    if (strlen(first) > 16)
+      first[16] = 0;
     last = e->last;
+    if (strlen(last) > 16)
+      last[16] = 0;
     eid = e->eid;
+    sid = e->id;
     id = 0;
+
+    /* Get user info */
 ##  repeat retrieve (id = u.users_id, class = u.mit_year, oaddr = u.office_addr,
-##           ophone = u.office_phone, dept = u.mit_dept)
-##     where u.#last = @last and u.#first = @first and u.mit_id = @eid
+##           ophone = u.office_phone, dept = u.mit_dept, status = u.#status)
+##     where u.#last = @last and u.#first = @first and u.mit_id = @sid
     if (id == 0) {
-       newuser(e);
-       return;
+##     repeat retrieve (id = u.users_id, class = u.mit_year, 
+##                      oaddr = u.office_addr, ophone = u.office_phone,
+##                      dept = u.mit_dept, status = u.#status)
+##             where u.#last = @last and u.#first = @first and u.mit_id = @eid
+       if (id == 0) {
+           newuser(e);
+           return;
+       }
     }
-    if (strcmp(e->class, strtrim(class)) && strcmp(class, "STAFF")) {
+
+    if (strcmp(e->class, strtrim(class)) &&
+       strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
        com_err(whoami, 0, "updating class for %s %s from %s to %s",
                first, last, class, e->class);
+       if (status == US_NOT_ALLOWED && !strcmp(e->class, "FACULTY"))
+         status = US_NO_LOGIN_YET;
+       if (status == US_ENROLL_NOT_ALLOWED && !strcmp(e->class, "FACULTY"))
+         status = US_ENROLLED;
        strcpy(class, e->class);
-##     repeat replace u (mit_year = @class,
+##     repeat replace u (mit_year = @class, #status = @status,
 ##                modtime = "now", modby = WHO, modwith = PROG)
 ##         where u.users_id = @id
     }
+
     changed = nochange = 0;
     strcpy(buf, e->address);
     while (to = index(buf, ','))
@@ -238,7 +280,7 @@ struct entry *e;
     while (to = index(buf, ':'))
       *to = ';';
     if (newfinger) {
-       if (oaddr[0] == ' ') {
+       if (oaddr[0] == ' ' && buf[0]) {
            strncpy(oaddr, buf, 16);
            oaddr[16] = 0;
            changed++;
@@ -271,6 +313,7 @@ struct entry *e;
        ophone[16] = 0;
     }
     FixCase(e->dept);
+    FixCase(e->title);
     if (newfinger) {
        if (dept[0] == ' ') {
            strncpy(dept, e->dept, 12);
@@ -283,14 +326,28 @@ struct entry *e;
        strncpy(dept, e->dept, 12);
        dept[12] = 0;
     }
+    sid = e->id;
+    name = e->name;
+    rdept = e->dept;
+    rtitle = e->title;
+    raddr = e->address;
+    rhphone = e->phone;
+    rophone = e->phone2;
     if (changed) {
        com_err(whoami, 0, "updating finger for %s %s", first, last);
 ##     repeat replace u (office_addr = @oaddr,
 ##                office_phone = @ophone, #mit_dept = @dept,
-##                fmodtime = "now", fmodby = WHO, fmodwith = PROG)
+##                fmodtime = "now", fmodby = WHO, fmodwith = PROG,
+##                xname = @name, xdept = @rdept, xtitle = @rtitle,
+##                xaddress = @raddr, xphone1 = @rhphone, xphone2 = @rophone,
+##                xmodtime = date("now"), mit_id = @sid)
+##         where u.users_id = @id
+    } else {
+##     repeat replace u (xname = @name, xdept = @rdept, xtitle = @rtitle,
+##                xaddress = @raddr, xphone1 = @rhphone, xphone2 = @rophone,
+##                xmodtime = date("now"), mit_id = @sid)
 ##         where u.users_id = @id
-    } else if (nochange)
-      com_err(whoami, 0, "NOT updating finger for %s %s", first, last);
+    }
 ##}
 
 
@@ -299,11 +356,12 @@ struct entry *e;
 ##{
     char *from, *to;
 ##  int id, uid, st;
-##  char *last, *first, *class, *middle, login[9], *eid, fullname[65];
-##  char oaddr[81], ophone[13], dept[13];
-
+##  char *last, *first, *class, *middle, login[9], *sid, fullname[65];
+##  char oaddr[81], ophone[17], dept[128], *name, *title, phone2[17];
+##  char *rdept, *rhphone, *rophone;
 
     strncpy(oaddr, e->address, 16);
+    oaddr[16] = 0;
     while (to = index(oaddr, ','))
       *to = ';';
     while (to = index(oaddr, ':'))
@@ -316,38 +374,51 @@ struct entry *e;
        from++;
     }
     *to = 0;
+    FixCase(e->dept);
     strncpy(dept, e->dept, 12);
+    dept[12] = 0;
     
-    id = set_next_object_id("users_id");
-    uid = set_next_object_id("uid");
+    id = set_next_object_id("users_id", 0);
+    uid = set_next_object_id("uid", 1);
     sprintf(login, "#%d", uid);
     last = e->last;
     first = e->first;
     middle = e->middle;
-    eid = e->eid;
     class = e->class;
     if (*middle)
       sprintf(fullname, "%s %s %s", first, middle, last);
     else
       sprintf(fullname, "%s %s", first, last);
     st = US_NOT_ALLOWED;
-    if (!strcmp(e->class, "FACULTY"))
+    if (!strcmp(e->class, "FACULTY") || !strcmp(e->class, "STAFF"))
       st = US_NO_LOGIN_YET;
-    
+
+    sid = e->id;
+    name = e->name;
+    rdept = e->dept;
+    title = e->title;
+    rhphone = e->phone;
+    rophone = e->phone2;
+
+
 ##  append users (#login = login, users_id = id, #uid = uid, shell = "/bin/csh",
 ##               #last = last, #first = first, #middle = middle, status = st,
-##               #mit_id = eid, #mit_year = class,
+##               #mit_id = sid, #mit_year = class,
 ##               modtime = "now", modby = WHO, modwith = PROG,
 ##               #fullname = fullname, office_addr = oaddr,
 ##               office_phone = ophone, #mit_dept = dept,
 ##               fmodtime = "now", fmodby = WHO, fmodwith = PROG,
-##               potype = "NONE")
-    com_err(whoami, 0, "adding user %s %s", e->first, e->last);
+##               potype = "NONE",
+##               xname = name, xdept = rdept, xtitle = title,
+##               xaddress = oaddr, xphone1 = rhphone, xphone2 = rophone,
+##               xmodtime = date("now"))
+
 ##}
 
 
-set_next_object_id(object)
+set_next_object_id(object, limit)
     char *object;
+    int limit;
 ##{
 ##  char *name;
 ##  int rowcount, exists, value;
@@ -369,7 +440,7 @@ set_next_object_id(object)
     }
     while (exists) {
        value++;
-       if (value > MAX_ID_VALUE)
+       if (limit && value > MAX_ID_VALUE)
            value = MIN_ID_VALUE;
 ##     retrieve (exists = any(users.name where users.name = value))
     }
This page took 0.046906 seconds and 4 git commands to generate.