X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Fedit_user_form.ml;h=ef3866fcf7f407da2ff1c53bd85b0bb33832b270;hb=d2de471ff7e79c1d6096bd8132aad80258852cdd;hp=7a2e63f32225a0eea0b3be0a52f895f7ea71c461;hpb=b90e3f4f9f352bd21d797d08729540e77b9ce72f;p=cocanwiki.git diff --git a/scripts/edit_user_form.ml b/scripts/edit_user_form.ml index 7a2e63f..ef3866f 100644 --- a/scripts/edit_user_form.ml +++ b/scripts/edit_user_form.ml @@ -1,7 +1,22 @@ -(* COCANWIKI scripts. +(* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: edit_user_form.ml,v 1.1 2004/09/08 12:45:38 rich Exp $ + * $Id: edit_user_form.ml,v 1.12 2006/12/06 09:46:57 rich Exp $ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. *) open Apache @@ -13,40 +28,49 @@ open Cocanwiki open Cocanwiki_template open Cocanwiki_date -let template = get_template "edit_user_form.html" +let run r (q : cgi) dbh hostid _ _ = + let template = get_template r dbh hostid "edit_user_form.html" in -let run r (q : cgi) (dbh : Dbi.connection) (hostid, _, _) _ = - let userid = int_of_string (q#param "userid") in + let userid = Int32.of_string (q#param "userid") in - let sth = - dbh#prepare_cached + let rows = + PGSQL(dbh) "select u.name, u.email, u.registration_date, - u.can_edit, u.can_manage_users, - (select count(*) from pages where logged_user = u.id), + u.can_edit, u.can_manage_users, u.can_manage_contacts, + u.can_manage_site, u.can_edit_global_css, u.can_import_mail, + u.can_edit_macros, + (select count(*) from pages where logged_user = u.id)::int4, (select count(*) from pages - where logged_user = u.id and url_deleted is null) - from users u where u.hostid = ? and u.id = ?" in - sth#execute [`Int hostid; `Int userid]; - - let name, email, registration_date, can_edit, can_manage_users, nr_edits, - nr_edits_live = - match sth#fetch1 () with - [`String name; (`Null | `String _) as email; - `Date registration_date; - `Bool can_edit; `Bool can_manage_users; - `Int nr_edits; `Int nr_edits_live] -> - name, email, registration_date, can_edit, can_manage_users, - nr_edits, nr_edits_live - | _ -> assert false in - - template#set "userid" (string_of_int userid); + where logged_user = u.id and url_deleted is null)::int4 + from users u where u.hostid = $hostid and u.id = $userid" in + + let name, email, registration_date, can_edit, can_manage_users, + can_manage_contacts, can_manage_site, can_edit_global_css, + can_import_mail, can_edit_macros, nr_edits, nr_edits_live = + match rows with + | [name, email, registration_date, + can_edit, can_manage_users, can_manage_contacts, + can_manage_site, can_edit_global_css, + can_import_mail, can_edit_macros, + nr_edits, nr_edits_live] -> + name, email, registration_date, can_edit, can_manage_users, + can_manage_contacts, can_manage_site, can_edit_global_css, + can_import_mail, can_edit_macros, nr_edits, nr_edits_live + | _ -> assert false in + + template#set "userid" (Int32.to_string userid); template#set "name" name; - template#set "email" (match email with `Null -> "" | `String s -> s); + template#set "email" (match email with None -> "" | Some s -> s); template#set "registration_date" (printable_date' registration_date); template#conditional "can_edit" can_edit; template#conditional "can_manage_users" can_manage_users; - template#set "nr_edits" (string_of_int nr_edits); - template#set "nr_edits_live" (string_of_int nr_edits_live); + template#conditional "can_manage_contacts" can_manage_contacts; + template#conditional "can_manage_site" can_manage_site; + template#conditional "can_edit_global_css" can_edit_global_css; + template#conditional "can_import_mail" can_import_mail; + template#conditional "can_edit_macros" can_edit_macros; + template#set "nr_edits" (Int32.to_string (Option.get nr_edits)); + template#set "nr_edits_live" (Int32.to_string (Option.get nr_edits_live)); q#template template