Commit 066a02c7 authored by Frank Bergmann's avatar Frank Bergmann

- added portrait editing

parent 45bf6f55
# /packages/intranet-core/www/users/portrait-erase.tcl
#
# Copyright (C) 1998-2004 various parties
# The code is based on ArsDigita ACS 3.4
#
# 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.
ad_page_contract {
erase's a user's portrait (NULLs out columns in the database)
the key here is to null out portrait_upload_date, which is
used by pages to determine portrait existence
@author philg@mit.edu
@creation_date September 28, 1999 (his friggin' 36th birthday)
} {
user_id:integer,notnull
}
ad_maybe_redirect_for_registration
set admin_user_id [ad_verify_and_get_user_id]
if ![im_is_user_site_wide_or_intranet_admin $admin_user_id] {
ad_return_error "Unauthorized" "You're not a member of the site-wide administration group"
return
}
db_dml delete_portrait {
delete from general_portraits
where on_what_id = :user_id
and on_which_table = 'USERS'
}]
ad_returnredirect "one?user_id=$user_id"
# /packages/intranet-core/www/users/portrait.tcl
#
# Copyright (C) 1998-2004 various parties
# The code is based on ArsDigita ACS 3.4
#
# 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.
ad_page_contract {
offers an admin the option to delete a user's portrait
@author philg@mit.edu
@author frank.bergmann@project-open.com
} {
user_id:integer,notnull
}
set user_info [db_0or1row user_info {
select first_names, last_name
from users
where user_id = :user_id
}]
db_0or1row portrait_p {
select
portrait_id,
portrait_upload_date,
portrait_comment,
portrait_original_width,
portrait_original_height,
portrait_client_file_name
from general_portraits
where on_what_id = :user_id
and on_which_table = 'USERS'
}]
if { [empty_string_p $first_names] && [empty_string_p $last_name] } {
ad_return_error "Portrait Unavailable" "We couldn't find a portrait (or this user)"
return
}
if { ! $portrait_p } {
ad_return_complaint 1 "<li>You shouldn't have gotten here; we don't have a portrait on file for this person."
return
}
if { ![empty_string_p $portrait_original_width] && ![empty_string_p $portrait_original_height] } {
set widthheight "width=$portrait_original_width height=$portrait_original_height"
} else {
set widthheight ""
}
set page_content "[ad_admin_header "Portrait of $first_names $last_name"]
<h2>Portrait of $first_names $last_name</h2>
[ad_admin_context_bar [list "one.tcl?[export_url_vars user_id]" "One User"] "Portrait"]
<hr>
<br>
<br>
<center>
<img $widthheight src=\"/shared/portrait-bits?[export_url_vars portrait_id]\">
</center>
<br>
<br>
<ul>
<li>Comment:
<blockquote>
$portrait_comment
</blockquote>
<li>Uploaded: [util_AnsiDatetoPrettyDate $portrait_upload_date]
<li>Original Name: $portrait_client_file_name
<p>
<li><a href=\"portrait-erase?user_id=$user_id\">erase</a>
</ul>
[ad_admin_footer]
"
doc_return 200 text/html $page_content
ad_page_contract {
writes portrait comment to database
@author mbryzek@arsdigita.com
@creation-date 22 Jun 2000
@cvs-id $Id$
} {
{ description "" }
{ user_id "" }
{ return_url "" }
}
set current_user_id [ad_maybe_redirect_for_registration]
if [empty_string_p $user_id] {
set user_id $current_user_id
}
# Check the permissions that the current_user has on user_id
im_user_permissions $current_user_id $user_id view read write admin
if {!$write} {
ad_returncomplaint 1 "<li>You have insufficient permissions to modify comments of this user."
return
}
if { [string length $description] > 4000 } {
ad_return_complaint 1 "Your portrait comment can only be 4000 characters long."
return
}
db_dml unused "
update cr_revisions
set description=:description
where revision_id = (select live_revision
from acs_rels a, cr_items c
where a.object_id_two = c.item_id
and a.object_id_one = :user_id
and a.rel_type = 'user_portrait_rel')"
if { ![empty_string_p $return_url] } {
ad_returnredirect $return_url
} else {
ad_returnredirect [ad_pvt_home]
}
<master>
<property name="title">#acs-subsite.lt_Edit_comment_for_the_#</property>
<property name="context">@context;noquote@</property>
<form method="post" action="comment-edit-2.tcl">
@export_vars;noquote@
#acs-subsite.Story_behind_photo#:<br />
<textarea rows="6" cols="50" wrap="soft" name="description">
@description@
</textarea>
<p><center>
<input type="submit" value="#acs-subsite.Save_comment#" />
</center></p>
</form>
ad_page_contract {
screen to edit the comment associated with a user's portrait
@author mbryzek@arsdigita.com
@creation-date 22 Jun 2000
@cvs-id $Id$
} {
{return_url "" }
{user_id ""}
} -properties {
context:onevalue
export_vars:onevalue
description:onevalue
first_names:onevalue
last_name:onevalue
}
set current_user_id [ad_maybe_redirect_for_registration]
if [empty_string_p $user_id] {
set user_id $current_user_id
}
# Check the permissions that the current_user has on user_id
im_user_permissions $current_user_id $user_id view read write admin
if {!$write} {
ad_returncomplaint 1 "<li>You have insufficient permissions to modify comments of this user."
return
}
if ![db_0or1row user_info "select
first_names,
last_name
from persons
where person_id = :user_id"] {
ad_return_error "Account Unavailable" "We can't find you (user #$user_id) in the users table. Probably your account was deleted for some reason."
return
}
if ![db_0or1row portrait_info "
select description
from cr_revisions
where revision_id = (select live_revision
from cr_items c, acs_rels a
where c.item_id = a.object_id_two
and a.object_id_one = :user_id
and a.rel_type = 'user_portrait_rel')"] {
ad_return_complaint 1 "<li>You shouldn't have gotten here; we don't have a portrait on file for you."
return
}
db_release_unused_handles
set context [list [list "./" "Your Portrait"] "Edit comment"]
set export_vars [export_form_vars user_id return_url]
ad_page_contract {
erase's a user's portrait (NULLs out columns in the database)
the key here is to null out live_revision, which is
used by pages to determine portrait existence
@cvs-id $Id$
} {
{return_url "" }
{user_id ""}
}
set current_user_id [ad_maybe_redirect_for_registration]
if [empty_string_p $user_id] {
set user_id $current_user_id
}
# Check the permissions that the current_user has on user_id
im_user_permissions $current_user_id $user_id view read write admin
if {!$write} {
ad_returncomplaint 1 "<li>You have insufficient permissions to erase a portrait for this user."
return
}
db_dml portrait_delete "update cr_items
set live_revision = NULL
where item_id = (
select object_id_two
from acs_rels
where object_id_one = :user_id
and rel_type = 'user_portrait_rel')"
if [empty_string_p $return_url] {
set return_url "/pvt/home"
}
ad_returnredirect $return_url
<master>
<property name="title">#acs-subsite.Erase_Portrait#</property>
<property name="context">@context;noquote@</property>
<p>#acs-subsite.lt_Sure_erase_user_por#</p>
<form method="get" action="erase-2">
@export_vars;noquote@
<center>
<input type="submit" value="#acs-subsite.Yes_I_am_sure#" />
</center>
ad_page_contract {
Erases a portrait
@cvs-id $Id$
} {
{return_url "" }
{user_id ""}
} -properties {
context:onevalue
export_vars:onevalue
}
set current_user_id [ad_maybe_redirect_for_registration]
if [empty_string_p $user_id] {
set user_id $current_user_id
}
# Check the permissions that the current_user has on user_id
im_user_permissions $current_user_id $user_id view read write admin
if {!$write} {
ad_returncomplaint 1 "<li>You have insufficient permissions to erase a portrait for this user."
return
}
if {$admin} {
set context [list [list "./?user_id=$user_id" "User's Portrait"] "Erase"]
} else {
set context [list [list "./" "Your Portrait"] "Erase"]
}
set export_vars [export_form_vars user_id return_url]
<?xml version="1.0"?>
<queryset>
<rdbms><type>oracle</type><version>8.1.6</version></rdbms>
<fullquery name="create_item">
<querytext>
begin
:1 := content_item.new(
name => :name,
creation_ip => :creation_ip);
end;
</querytext>
</fullquery>
<fullquery name="create_rel">
<querytext>
begin
:1 := acs_rel.new (
rel_type => 'user_portrait_rel',
object_id_one => :user_id,
object_id_two => :item_id);
end;
</querytext>
</fullquery>
<fullquery name="create_revision">
<querytext>
begin
:1 := content_revision.new(
title => :title,
description => :portrait_comment,
text => 'not_important',
mime_type => :guessed_file_type,
item_id => :item_id,
creation_user => :user_id,
creation_ip => :creation_ip
);
update cr_items
set live_revision = :1
where item_id = :item_id;
end;
</querytext>
</fullquery>
<fullquery name="update_photo">
<querytext>
update cr_revisions
set content = empty_blob()
where revision_id = :revision_id
returning content into :1
</querytext>
</fullquery>
<fullquery name="update_photo_info">
<querytext>
update cr_revisions
set description = :portrait_comment,
publish_date = sysdate,
mime_type = :guessed_file_type,
title = :title
where revision_id = :revision_id
</querytext>
</fullquery>
</queryset>
<?xml version="1.0"?>
<queryset>
<rdbms><type>postgresql</type><version>7.1</version></rdbms>
<fullquery name="create_item">
<querytext>
select content_item__new(
varchar :name,
null,
null,
null,
now(),
null,
null,
:creation_ip,
'content_item',
'content_revision',
null,
null,
'text/plain',
null,
null
)
</querytext>
</fullquery>
<fullquery name="create_rel">
<querytext>
select acs_rel__new (
null,
'user_portrait_rel',
:user_id,
:item_id,
null,
null,
null
)
</querytext>
</fullquery>
<fullquery name="create_revision">
<querytext>
declare
v_revision_id integer;
begin
v_revision_id := content_revision__new(
:title,
:portrait_comment,
now(),
:guessed_file_type,
null,
null,
:item_id,
null,
now(),
:user_id,
:creation_ip
);
update cr_items
set live_revision = v_revision_id
where item_id = :item_id;
return v_revision_id;
end;
</querytext>
</fullquery>
<fullquery name="update_photo">
<querytext>
update cr_revisions
set lob = [set __lob_id [db_string get_lob_id "select empty_lob()"]]
where revision_id = :revision_id
</querytext>
</fullquery>
<fullquery name="update_photo_info">
<querytext>
update cr_revisions
set description = :portrait_comment,
publish_date = now(),
mime_type = :guessed_file_type,
title = :title
where revision_id = :revision_id
</querytext>
</fullquery>
</queryset>
ad_page_contract {
adds (or replaces) a user's portrait
@author philg@mit.edu
@creation-date 26 Sept 1999
@cvs-id $Id$
} {
upload_file
{user_id ""}
{portrait_comment ""}
{return_url ""}
{title ""}
}
set current_user_id [ad_maybe_redirect_for_registration]
if [empty_string_p $user_id] {
set user_id $current_user_id
}
# Check the permissions that the current_user has on user_id
im_user_permissions $current_user_id $user_id view read write admin
if {!$write} {
ad_returncomplaint 1 "<li>You have insufficient permissions to upload a portrait for this user."
return
}
set exception_text ""
set exception_count 0
if { ![info exists upload_file] || [empty_string_p $upload_file] } {
append exception_text "<li>Please specify a file to upload\n"
incr exception_count
} else {
# this stuff only makes sense to do if we know the file exists
set tmp_filename [ns_queryget upload_file.tmpfile]
set file_extension [string tolower [file extension $upload_file]]
# remove the first . from the file extension
regsub "\." $file_extension "" file_extension
set guessed_file_type [ns_guesstype $upload_file]
set n_bytes [file size $tmp_filename]
# check to see if this is one of the favored MIME types,
# e.g., image/gif or image/jpeg
if { ![empty_string_p [ad_parameter AcceptablePortraitMIMETypes "user-info"]] && [lsearch [ad_parameter AcceptablePortraitMIMETypes "user-info"] $guessed_file_type] == -1 } {
incr exception_count
append exception_text "<li>Your image wasn't one of the acceptable MIME types: [ad_parameter AcceptablePortraitMIMETypes "user-info"]"
}
# strip off the C:\directories... crud and just get the file name
if ![regexp {([^/\\]+)$} $upload_file match client_filename] {
# couldn't find a match
set client_filename $upload_file
}
if { ![empty_string_p [ad_parameter MaxPortraitBytes "user-info"]] && $n_bytes > [ad_parameter MaxPortraitBytes "user-info"] } {
append exception_text "<li>Your file is too large. The publisher of [ad_system_name] has chosen to limit portraits to [util_commify_number [ad_parameter MaxPortraitBytes "user-info"]] bytes. You can use PhotoShop or the GIMP (free) to shrink your image.\n"
incr exception_count
}
}
if { $exception_count > 0 } {
ad_return_complaint $exception_count $exception_text
return
}
set what_aolserver_told_us ""
if { $file_extension == "jpeg" || $file_extension == "jpg" } {
catch { set what_aolserver_told_us [ns_jpegsize $tmp_filename] }
} elseif { $file_extension == "gif" } {
catch { set what_aolserver_told_us [ns_gifsize $tmp_filename] }
}
# the AOLserver jpegsize command has some bugs where the height comes
# through as 1 or 2
if { ![empty_string_p $what_aolserver_told_us] && [lindex $what_aolserver_told_us 0] > 10 && [lindex $what_aolserver_told_us 1] > 10 } {
set original_width [lindex $what_aolserver_told_us 0]
set original_height [lindex $what_aolserver_told_us 1]
} else {
set original_width ""
set original_height ""
}
## The portrait is ready. Let's now figure out how to insert into the system
set creation_ip [ad_conn peeraddr]
set name "portrait-of-user-$user_id"
set create_item "
begin
:1 := content_item.new(
name => :name,
creation_ip => :creation_ip);
end;"
set create_rel "
begin
:1 := acs_rel.new (
rel_type => 'user_portrait_rel',
object_id_one => :user_id,
object_id_two => :item_id);
end;
"
set create_revision "
begin
:1 := content_revision.new(
title => :title,
description => :portrait_comment,
text => 'not_important',
mime_type => :guessed_file_type,
item_id => :item_id,
creation_user => :user_id,
creation_ip => :creation_ip
);
update cr_items
set live_revision = :1
where item_id = :item_id;
end;"
set update_photo "
update cr_revisions
set content = empty_blob()
where revision_id = :revision_id
returning content into :1
"
set upload_image_info "
insert into images
(image_id, width, height)
values
(:revision_id, :original_width, :original_height)
"
# let's figure out if this person has a portrait yet
if { ![db_0or1row get_item_id "select object_id_two as item_id
from acs_rels
where object_id_one = :user_id
and rel_type = 'user_portrait_rel'"] } {
# The user doesn't have a portrait relation yet
db_transaction {
set item_id [db_exec_plsql create_item $create_item]
set rel_id [db_exec_plsql create_rel $create_rel]
set revision_id [db_exec_plsql create_revision $create_revision]
db_dml update_photo $update_photo -blob_files [list $tmp_filename]
db_dml upload_image_info $upload_image_info
}
} else {
#already has a portrait, so all we have to do is to make a new revision for it
#Let's check if a current revision exists:
if {![db_0or1row get_revision_id "select live_revision as revision_id
from cr_items
where item_id = :item_id"] || [empty_string_p $revision_id]} {
# It's an insert rather than an update
db_transaction {
set revision_id [db_exec_plsql create_revision $create_revision]
db_dml update_photo $update_photo -blob_files [list $tmp_filename]
db_dml upload_image_info $upload_image_info
}
} else {
# it's merely an update
db_transaction {
db_dml update_photo $update_photo -blob_files [list $tmp_filename]
db_dml update_image_info "
update images
set width = :original_width, height = :original_height
where image_id = :revision_id"
db_dml update_photo_info "
update cr_revisions
set description = :portrait_comment,
publish_date = sysdate,
mime_type = :guessed_file_type,
title = :title
where revision_id = :revision_id"
}
}
}
if { [exists_and_not_null return_url] } {
ad_returnredirect $return_url
} else {
ad_returnredirect [ad_pvt_home]
}
<?xml version="1.0"?>
<queryset>
<fullquery name="get_item_id">
<querytext>
select object_id_two as item_id
from acs_rels
where object_id_one = :user_id
and rel_type = 'user_portrait_rel'
</querytext>
</fullquery>
<fullquery name="upload_image_info">
<querytext>
insert into images
(image_id, width, height)
values
(:revision_id, :original_width, :original_height)
</querytext>
</fullquery>
<fullquery name="get_revision_id">
<querytext>
select live_revision as revision_id
from cr_items
where item_id = :item_id
</querytext>
</fullquery>
<fullquery name="update_image_info">
<querytext>
update images
set width = :original_width, height = :original_height
where image_id = :revision_id
</querytext>
</fullquery>
</queryset>
<master>
<property name=title>#acs-subsite.Upload_Portrait#</property>
<property name="context">@context;noquote@</property>
#acs-subsite.lt_How_would_you_like_the#
<p>
#acs-subsite.lt_Upload_your_favorite#
<blockquote>
<form enctype=multipart/form-data method=POST action="upload-2">
@export_vars;noquote@
<table>
<tr>
<td valign=top align=right>#acs-subsite.Filename#: </td>
<td>
<input type=file name=upload_file size=20><br>
<font size=-1>#acs-subsite.lt_Use_the_Browse_button#</font>
</td>
</tr>
<tr>
<td valign=top align=right>#acs-subsite.Story_Behind_Photo#
<br>
<font size=-1>#acs-subsite.optional#</font>
</td>
<td><textarea rows=6 cols=50 wrap=soft name=portrait_comment>
</textarea>
</td>
</tr>
</table>
<p>
<center>
<input type=submit value="Upload">
</center>
</blockquote>
</form>
ad_page_contract {
Uploading user portraits
@cvs-id $Id$
} {
{user_id ""}
{return_url ""}
} -properties {
first_names:onevalue
last_name:onevalue
context:onevalue
export_vars:onevalue
}
set current_user_id [ad_maybe_redirect_for_registration]
set subsite_id [ad_conn subsite_id]
if [empty_string_p $user_id] {
set user_id $current_user_id
}
# Check the permissions that the current_user has on user_id
im_user_permissions $current_user_id $user_id view read write admin
if {!$write} {
ad_returncomplaint 1 "<li>You have insufficient permissions to upload a portrait for this user."
return
}
if ![db_0or1row name "select
first_names, last_name
from persons
where person_id=:user_id"] {
ad_return_error "Account Unavailable" "We can't find you (user #$user_id) in the users table. Probably your account was deleted for some reason."
return
}
if {$admin} {
set context [list [list "./?user_id=$user_id" "User's Portrait"] "Upload Portrait"]
} else {
set context [list [list "./?return_url=$return_url" "Your Portrait"] "Upload Portrait"]
}
set export_vars [export_form_vars user_id return_url]
ad_return_template
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
</td> </td>
<td valign=top> <td valign=top>
<%= $portrait_html %>
<%= $projects_html %> <%= $projects_html %>
<%= [im_component_bay right] %> <%= [im_component_bay right] %>
</td> </td>
......
...@@ -383,6 +383,111 @@ if {!$admin} { ...@@ -383,6 +383,111 @@ if {!$admin} {
# ---------------------------------------------------------------
# Portrait
# ---------------------------------------------------------------
set subsite_url [subsite::get_element -element url]
set export_vars [export_url_vars user_id return_url]
if {![db_0or1row get_item_id "
select
live_revision as revision_id,
item_id
from
acs_rels a,
cr_items c
where
a.object_id_two = c.item_id
and a.object_id_one = :user_id
and a.rel_type = 'user_portrait_rel'"]
|| [empty_string_p $revision_id]
} {
# The user doesn't have a portrait yet
set portrait_p 0
} else {
set portrait_p 1
}
if [catch {db_1row get_picture_info "
select
i.width,
i.height,
cr.title,
cr.description,
cr.publish_date
from
images i,
cr_revisions cr
where
i.image_id = cr.revision_id
and image_id = :revision_id
"} errmsg] {
# There was an error obtaining the picture information
set portrait_p 0
}
# Check if there was a portrait
if {![exists_and_not_null publish_date]} {
set portrait_p 0
}
set portrait_alt "Portrait of $first_names $last_name"
if {$portrait_p} {
if { ![empty_string_p $width] && ![empty_string_p $height] } {
set widthheight "width=$width height=$height"
} else {
set widthheight ""
}
set portrait_gif "<img $widthheight src=\"/shared/portrait-bits.tcl?$export_vars\" alt=\"$portrait_alt\">"
} else {
set portrait_gif [im_gif anon_portrait $portrait_alt]
set description "No portrait for <br>\n$first_names $last_name."
if {$admin} { append description "<br>\nPlease upload a portrait."}
}
set portrait_admin "
<li><a href=\"/intranet/users/portrait/upload?return_url=$return_url\">Upload portrait</a></li>
<li><a href=\"/intranet/users/portrait/erase?$export_vars\">Delete portrait</a></li>\n"
if {$portrait_p} {
append portrait_admin "
<li><a href=\"/intranet/users/portrait/comment-edit?$export_vars\">Edit comments about you</a></li>\n"
}
if {!$admin} { set portrait_admin "" }
if {$admin && "" == $description} {
set description "
No comments about $first_names $last_name.<br>
Please click above to add a short comment.
"
}
set portrait_html "
<table border=0 cellspacing=1 cellpadding=1>
<tr valign=top>
<td>
$portrait_gif <br>
</td>
<td>
$portrait_admin <br>
<blockquote>$description</blockquote>
</td>
</tr>
</table>
"
set portrait_html [im_table_with_title "Portrait" $portrait_html]
# --------------------------------------------------------------- # ---------------------------------------------------------------
# User-Navbar # User-Navbar
# --------------------------------------------------------------- # ---------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment