Commit 528126e9 authored by Frank Bergmann's avatar Frank Bergmann

Added attendance management

parent 717d6121
......@@ -1668,6 +1668,94 @@ ad_proc -private im_rest_post_object_type_im_note {
}
# --------------------------------------------------------
# im_attendance_interval
#
ad_proc -private im_rest_post_object_type_im_attendance_interval {
{ -format "json" }
{ -rest_user_id 0 }
{ -rest_otype "" }
{ -rest_otype_pretty "Attendance" }
{ -rest_oid "" }
{ -content "" }
{ -debug 0 }
} {
Handler for POST calls on particular im_attendance_interval objects.
} {
ns_log Notice "im_rest_post_object_im_attendance_interval: rest_oid=$rest_oid"
# Permissions
set add_p [im_permission $rest_user_id "add_attendances"]
if {!$add_p} {
return [im_rest_error -format $format -http_status 403 -message "User #$rest_user_id does not have the right to create attendances"]
}
set creation_user $rest_user_id
set creation_ip [ad_conn peeraddr]
# Extract a key-value list of variables from JSON POST request
array set hash_array [im_rest_parse_json_content -rest_otype $rest_otype -format $format -content $content]
ns_log Notice "im_rest_post_object_type_$rest_otype: hash_array=[array get hash_array]"
# write hash values as local variables
foreach key [array names hash_array] {
set value $hash_array($key)
ns_log Notice "im_rest_post_object_type_$rest_otype: key=$key, value=$value"
set $key $value
}
# Check that all required variables are there
set required_vars {attendance_user_id attendance_start attendance_end attendance_status_id attendance_type_id}
foreach var $required_vars {
if {![info exists $var]} {
return [im_rest_error -format $format -http_status 406 -message "Variable '$var' not specified. The following variables are required: $required_vars"]
}
}
# Check for duplicate
set dup_sql "
select count(*)
from im_attendance_intervals
where attendance_user_id = :attendance_user_id and
attendance_start = :attendance_start and
attendance_end = :attendance_end
"
if {[db_string duplicates $dup_sql]} {
return [im_rest_error -format $format -http_status 406 -message "Duplicate $rest_otype_pretty: The attendance already exists for the specified object."]
}
if {[catch {
set rest_oid [db_string new_im_attendance_interval "
select im_attendance_interval__new (
null, -- attendance_id
:rest_otype, -- object_type
now(), -- creation_date
:creation_user,
:creation_ip,
null, -- context_id
:attendance_user_id,
:attendance_start,
:attendance_end,
:attendance_status_id,
:attendance_type_id,
:attendance_note
)
"]
} err_msg]} {
ns_log Error "Error creating $rest_otype: '$err_msg'"
return [im_rest_error -format $format -http_status 406 -message "Error creating $rest_otype_pretty: '$err_msg'."]
}
im_audit -user_id $rest_user_id -object_type $rest_otype -object_id $rest_oid -status_id $attendance_status_id -type_id $attendance_type_id -action after_create
set hash_array(rest_oid) $rest_oid
set hash_array(rel_id) $rest_oid
return [array get hash_array]
}
# --------------------------------------------------------
# Membership Relationshiop
......
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