Index: openacs-4/packages/ams/tcl/mobile-number-widget-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ams/tcl/mobile-number-widget-procs.tcl,v diff -u -N -r1.4 -r1.5 --- openacs-4/packages/ams/tcl/mobile-number-widget-procs.tcl 14 Jan 2007 11:36:27 -0000 1.4 +++ openacs-4/packages/ams/tcl/mobile-number-widget-procs.tcl 23 Jan 2007 14:38:14 -0000 1.5 @@ -7,8 +7,6 @@ } namespace eval template::util::mobile_number {} -namespace eval template::util::aim {} -namespace eval template::util::skype {} ad_proc -public template::util::mobile_number { command args } { Dispatch procedure for the mobile_number object @@ -19,17 +17,28 @@ ad_proc -public template::util::mobile_number::create { {itu_id {}} {national_number {}} + {area_city_code {}} {subscriber_number {}} + {extension {}} + {sms_enabled_p {}} {best_contact_time {}} + {location {}} + {phone_type_id {}} } { - return [list $itu_id $national_number $subscriber_number $best_contact_time] + return [list $itu_id $national_number $area_city_code $subscriber_number $extension $sms_enabled_p $best_contact_time] } + ad_proc -public template::util::mobile_number::html_view { {itu_id {}} {national_number {}} + {area_city_code {}} {subscriber_number {}} + {extension {}} + {sms_enabled_p {}} {best_contact_time {}} + {location {}} + {phone_type_id {}} } { set mobile_number "" if { [parameter::get_from_package_key -parameter "ForceCountryCodeOneFormatting" -package_key "ams" -default "0"] } { @@ -40,6 +49,9 @@ set mobile_number ${national_number} if { [exists_and_not_null mobile_number] } { append mobile_number "-" } } + append mobile_number $area_city_code + if { [exists_and_not_null mobile_number] } { append mobile_number "-" } + append mobile_number "$subscriber_number" # Now prepare the returned html @@ -58,6 +70,31 @@ } } +ad_proc -public template::util::mobile_number::text_view { + {itu_id {}} + {national_number {}} + {area_city_code {}} + {subscriber_number {}} + {extension {}} + {sms_enabled_p {}} + {best_contact_time {}} + {location {}} + {phone_type_id {}} +} { + set mobile_number "" + if { [parameter::get_from_package_key -parameter "ForceCountryCodeOneFormatting" -package_key "ams" -default "0"] } { + if { $national_number != "1" } { + set mobile_number "[_ ams.international_dial_code]${national_number}-" + } + } else { + set mobile_number ${national_number} + if { [exists_and_not_null mobile_number] } { append mobile_number "-" } + } + append mobile_number "$subscriber_number" + + return $mobile_number +} + ad_proc -public template::util::mobile_number::acquire { type { value "" } } { Create a new mobile_number value with some predefined value Basically, create and set the mobile_number value @@ -86,27 +123,32 @@ set itu_id [template::util::mobile_number::get_property itu_id $mobile_number_list] set national_number [template::util::mobile_number::get_property national_number $mobile_number_list] + set area_city_code [template::util::mobile_number::get_property area_city_code $mobile_number_list] set subscriber_number [template::util::mobile_number::get_property subscriber_number $mobile_number_list] + set extension [template::util::mobile_number::get_property extension $mobile_number_list] + set sms_enabled_p [template::util::mobile_number::get_property sms_enabled_p $mobile_number_list] set best_contact_time [template::util::mobile_number::get_property best_contact_time $mobile_number_list] + set location [template::util::mobile_number::get_property location $mobile_number_list] + set phone_type_id [template::util::mobile_number::get_property phone_type_id $mobile_number_list] if { ![parameter::get_from_package_key -parameter "ForceCountryCodeOneFormatting" -package_key "ams" -default "0"] } { # the number is not required to be formatted in a country code one friendly way # we need to verify that the number does not contain invalid characters - set mobile_number_temp "$itu_id$national_number$subscriber_number$best_contact_time" + set mobile_number_temp "$itu_id$national_number$area_city_code$subscriber_number$extension$sms_enabled_p$best_contact_time" regsub -all " " $mobile_number_temp "" mobile_number_temp - if { ![regexp {^([0-9]|x|-|\+|\)|\(){1,}$} $mobile_number_temp match mobile_number_temp] } { + if { ![regexp {^([0-9]|x|-|\+|/|\)|\(){1,}$} $mobile_number_temp match mobile_number_temp] } { set message [_ ams.lt_Mobile_numbers_must_only_contain] } } else { # we have a number in country code one that must follow certain formatting guidelines # the template::data::transform::mobile_number proc will have already seperated # the entry from a single entry field into the appropriate values if its formatted - # correctly. This means that if values exist for national_number + # correctly. This means that if values exist for area_city_code and national_number # the number was formatted correctly. If not we need to reply with a message that lets # users know how they are supposed to format numbers. - if { ![exists_and_not_null national_number] } { + if { ![exists_and_not_null area_city_code] || ![exists_and_not_null national_number] } { set message [_ ams.lt_Mobile_numbers_in_country_code] } } @@ -126,8 +168,13 @@ # if in the future somebody wants a widget with many individual fields this will be necessary set itu_id [ns_queryget $element_id.itu_id] set national_number [ns_queryget $element_id.national_number] + set area_city_code [ns_queryget $element_id.area_city_code] set subscriber_number [ns_queryget $element_id.subscriber_number] + set extension [ns_queryget $element_id.extension] + set sms_enabled_p [ns_queryget $element_id.sms_enabled_p] set best_contact_time [ns_queryget $element_id.best_contact_time] + set location [ns_queryget $element_id.location] + set phone_type_id [ns_queryget $element_id.phone_type_id] # we need to seperate out the returned value into individual elements for a single box entry widget set number [string trim [ns_queryget $element_id.summary_number]] @@ -152,14 +199,17 @@ # The number is not in a valid format we pass on the # subscriber number for validation errors. set subscriber_number $number + } else { + # if there was an extension we need to remove the "X" from it + regsub -all {^x} $extension {} extension } } if { [empty_string_p $subscriber_number] } { # We need to return the empty list in order for form builder to think of it # as a non-value in case of a required element. return [list] } else { - return [list [list $itu_id $national_number $subscriber_number $best_contact_time]] + return [list [list $itu_id $national_number $area_city_code $subscriber_number $extension $sms_enabled_p $best_contact_time $location $phone_type_id]] } } @@ -170,8 +220,13 @@ @param mobile_number_list the mobile_number list to modify @@ -182,24 +237,44 @@ set itu_id [template::util::mobile_number::get_property itu_id $mobile_number_list] set national_number [template::util::mobile_number::get_property national_number $mobile_number_list] + set area_city_code [template::util::mobile_number::get_property area_city_code $mobile_number_list] set subscriber_number [template::util::mobile_number::get_property subscriber_number $mobile_number_list] + set extension [template::util::mobile_number::get_property extension $mobile_number_list] + set sms_enabled_p [template::util::mobile_number::get_property sms_enabled_p $mobile_number_list] set best_contact_time [template::util::mobile_number::get_property best_contact_time $mobile_number_list] + set location [template::util::mobile_number::get_property location $mobile_number_list] + set phone_type_id [template::util::mobile_number::get_property phone_type_id $mobile_number_list] switch $what { itu_id { - return [list $value $national_number $subscriber_number $best_contact_time] + return [list $value $national_number $area_city_code $subscriber_number $extension $sms_enabled_p $best_contact_time $location $phone_type_id] } national_number { - return [list $itu_id $value $subscriber_number $best_contact_time] + return [list $itu_id $value $area_city_code $subscriber_number $extension $sms_enabled_p $best_contact_time $location $phone_type_id] } + area_city_code { + return [list $itu_id $national_number $value $subscriber_number $extension $sms_enabled_p $best_contact_time $location $phone_type_id] + } subscriber_number { - return [list $itu_id $national_number $value $best_contact_time] + return [list $itu_id $national_number $area_city_code $value $extension $sms_enabled_p $best_contact_time $location $phone_type_id] } + extension { + return [list $itu_id $national_number $area_city_code $subscriber_number $value $sms_enabled_p $best_contact_time $location $phone_type_id] + } + sms_enabled_p { + return [list $itu_id $national_number $area_city_code $subscriber_number $extension $value $best_contact_time $location $phone_type_id] + } best_contact_time { - return [list $itu_id $national_number $subscriber_number $value] + return [list $itu_id $national_number $area_city_code $subscriber_number $extension $sms_enabled_p $value $location $phone_type_id] } + location { + return [list $itu_id $national_number $area_city_code $subscriber_number $extension $sms_enabled_p $best_contact_time $value $phone_type_id] + } + phone_type_id { + return [list $itu_id $national_number $area_city_code $subscriber_number $extension $sms_enabled_p $best_contact_time $location $value] + } default { - error "Parameter supplied to util::mobile_number::set_property 'what' must be one of: 'itu_id', 'subscriber_number', 'national_number', 'best_contact_time'. You specified: '$what'." + error "Parameter supplied to util::mobile_number::set_property 'what' must be one of: 'itu_id', 'subscriber_number', 'national_number', 'area_city_code', 'extension', 'sms_enabled_p', 'best_contact_time', 'location', 'phone_type_id'. You specified: '$what'." } } } @@ -227,21 +302,41 @@ national_number { return [lindex $mobile_number_list 1] } - subscriber_number { + area_city_code { return [lindex $mobile_number_list 2] } - best_contact_time { + subscriber_number { return [lindex $mobile_number_list 3] } + extension { + return [lindex $mobile_number_list 4] + } + sms_enabled_p { + return [lindex $mobile_number_list 5] + } + best_contact_time { + return [lindex $mobile_number_list 6] + } + location { + return [lindex $mobile_number_list 7] + } + phone_type_id { + return [lindex $mobile_number_list 8] + } html_view { set itu_id [template::util::mobile_number::get_property itu_id $mobile_number_list] set subscriber_number [template::util::mobile_number::get_property subscriber_number $mobile_number_list] set national_number [template::util::mobile_number::get_property national_number $mobile_number_list] + set area_city_code [template::util::mobile_number::get_property area_city_code $mobile_number_list] + set extension [template::util::mobile_number::get_property extension $mobile_number_list] + set sms_enabled_p [template::util::mobile_number::get_property sms_enabled_p $mobile_number_list] set best_contact_time [template::util::mobile_number::get_property best_contact_time $mobile_number_list] - return [template::util::mobile_number::html_view $itu_id $national_number $subscriber_number $best_contact_time] + set location [template::util::mobile_number::get_property location $mobile_number_list] + set phone_type_id [template::util::mobile_number::get_property phone_type_id $mobile_number_list] + return [template::util::mobile_number::html_view $itu_id $national_number $area_city_code $subscriber_number $extension $sms_enabled_p $best_contact_time $location $phone_type_id] } default { - error "Parameter supplied to util::mobile_number::get_property 'what' must be one of: 'itu_id', 'subscriber_number', 'national_number', 'best_contact_time'. You specified: '$what'." + error "Parameter supplied to util::mobile_number::get_property 'what' must be one of: 'itu_id', 'subscriber_number', 'national_number', 'area_city_code', 'extension', 'sms_enabled_p', 'best_contact_time', 'location', 'phone_type_id'. You specified: '$what'." } } @@ -260,10 +355,12 @@ # array set attributes $tag_attributes if { [info exists element(value)] } { + set itu_id [template::util::mobile_number::get_property itu_id $element(value)] set national_number [template::util::mobile_number::get_property national_number $element(value)] set subscriber_number [template::util::mobile_number::get_property subscriber_number $element(value)] set best_contact_time [template::util::mobile_number::get_property best_contact_time $element(value)] + } else { set itu_id {} set subscriber_number {} @@ -281,10 +378,19 @@ append summary_number "011-$national_number" } } + if { [exists_and_not_null area_city_code] } { + if { [exists_and_not_null summary_number] } { append summary_number "-" } + append summary_number $area_city_code + } if { [exists_and_not_null subscriber_number] } { if { [exists_and_not_null summary_number] } { append summary_number "-" } append summary_number $subscriber_number } + if { [exists_and_not_null extension] } { + if { [exists_and_not_null summary_number] } { append summary_number "x" } + append summary_number $extension + } +# set summary_number "$national_number\-$area_city_code\-$subscriber_number\x$extension" append output "" } else { @@ -301,267 +407,3 @@ return $output } -ad_proc -public template::util::aim::status_img { - -username:required -} { -# connecting to the server can be really slow, so we reutrn a url that will load in the broswer -# but not slow the loading of a page overall - - # Connect to AOL server -# set url [socket "big.oscar.aol.com" 80] - # Send request -# puts $url "GET /$username?on_url=online&off_url=offline HTTP/1.0\n\n" -# set counter 0 - # While page not completely read -# while { ![eof $url] } { - # Read page -# set page [read $url 256] -# incr counter - # If we reach 10 attempts with no answer, consider the user offline -# if { $counter > 10 } { -# set page "offline" -# break -# } -# } - - # If no time out, response will be formatted as: - # HTTP/1.1 302 Redirection Location:online IMG SRC=online - # or - # HTTP/1.1 302 Redirection Location:online IMG SRC=offline - # Search for word offline, if present then user is offline, else user is online - -# set status [string first "offline" $page] -# if { $status >= 0 } { -# set status "offline" -# } else { -# set status "online" -# } -# close $url -# return status - return "" -} - -ad_proc -private template::util::skype::status { - -username:required - -response_type:required - {-image_type "balloon"} - {-language "en"} - {-char_set "utf"} -} { - This procedure would query the skypeweb database for the status of the provided username. For this procedure to retun the user status, the user should allow his status to be shown on the web in the privacy menu in thier Skype application. This procedure should not be called by the user, instead use the wrapper procedures status_txt, status_xml, status_num, and status_img, unless if you want the raw unprocessed result as it returns from the server. For more information consult the SkypeWeb Technical Whitepaper. - - @param username The username to check the status for. - @param response_type - Must be one of the following: - - @param image_type - If response_type is of type image, then image_type specifies the type of image to be returned. Available image types are: - - @param language The ISO code for the language that the status should be returned in. If specified language is not available, status would be returned in enlgish. Would only have meaning if response_type is txt. - @param char_set The character set the status should be encoded in. Must be either utf (UTF-8) or iso (ISO-8859-1). Would only have meaning if response_type is txt. -} { - #Set base URI - set uri "http://mystatus.skype.com" - - #If response_type is image, add to URI the image type to return - if { $response_type == "img" } { - switch $image_type { - "balloon" {set image_type "balloon"} - "big_classic" {set image_type "bigclassic"} - "small_classic" {set image_type "smallclassic"} - "small_icon" {set image_type "smallicon"} - "medium_icon" {set image_type "mediumicon"} - "dropdown_white_bg" {set image_type "dropdown-white"} - "dropdown_transparent_bg" {set image_type "dropdown-trans"} - default {set image_type "balloon"} - } - set uri ${uri}/$image_type - } - - #To avoid ambiguity, escape the . in a username, then add it to the URI - regsub -all {\.} $username {%2E} username - set uri ${uri}/$username - - #If response_type is not an image, append it to the URI - if { $response_type != "img" } { - set uri ${uri}.$response_type - } - - #If response_type is txt, check for language and character set. - if { $response_type == "txt" } { - - #If language is specified, check for its availablity and add it to the URI - if { ![empty_string_p $language] } { - string tolower $language - switch $language { - "en" {set language "en"} - "de" {set language "de"} - "fr" {set language "fr"} - "it" {set language "it"} - "pl" {set language "pl"} - "ja" {set language "ja"} - "pt" {set language "pt"} - "pt/br" {set language "pt-br"} - "se" {set language "se"} - "zh" {set language "zh-cn"} - "cn" {set language "zh-cn"} - "zh/cn" {set language "zh-cn"} - "hk" {set language "zh-tw"} - "tw" {set language "zh-tw"} - "zh/tw" {set language "zh-tw"} - default {set language "en"} - } - set uri ${uri}.$language - } - - #If char_set is specified append it to the URI - if { ![empty_string_p $char_set] } { - string tolower $char_set - switch $char_set { - "utf" {set char_set "utf8"} - "iso" {set char_set "latin1"} - default {set char_set "utf8"} - } - set uri ${uri}.$char_set - } - } - - #By now, the uri is fully formatted and contains all the data required. - - if { $response_type eq "img" } { - set status $uri - } else { - #Get user status - set status [ns_httpget $uri] - } - - return $status -} - -ad_proc -public template::util::skype::status_txt { - -username:required - {-language ""} - {-char_set ""} -} { - This procedure is a wrapper procedure for template::util::skype::status, and should be used to get a text of the use status. - - @param username The username to check the status for. - @param language The ISO code for the language that the status should be returned in. If specified language is not available, status would be returned in enlgish. Defaults to english. - @param char_set The character set the status should be encoded in. Must be either utf (UTF-8) or iso (ISO-8859-1). - - @see template::util::skype::status -} { - return [template::util::skype::status -username $username -response_type "txt" -language $language -char_set $char_set] -} - -ad_proc -public template::util::skype::status_num { - -username:required -} { - This procedure is a wrapper procedure for template::util::skype::status. Will get a number code from the skypeweb server, and will decode it and return a text representation of the status. - - @param username The username to check the status for. - - @see template::util::skype::status -} { - set status [template::util::skype::status -username $username -response_type "num"] - - switch $status { - 0 {set status "Unknown"} - 1 {set status "Offline"} - 2 {set status "Online"} - 3 {set status "Away"} - 4 {set status "Not Available"} - 5 {set status "Do Not Disturb"} - 6 {set status "Invisible"} - 7 {set status "Skype Me"} - } - return $status -} - -ad_proc -public template::util::skype::status_xml { - -username:required - {-language} -} { - This procedure is a wrapper procedure for template::util::skype::status. Will get an XML response, and will parse it and return a text representation of the status. - - @param username The username to check the status for. - @param language The ISO code for the language that the status should be returned in. If specified language is not available, status would be returned in enlgish. Defaults to english. - - @see template::util::skype::status -} { - set status [template::util::skype::status -username $username -response_type "xml"] - - #Parse XML response - set document [dom parse $status] - set root [$document documentElement] - set node [$root firstChild] - set node [$node firstChild] - set nodelist [$node selectNodes /rdf/status/presence/text()] - - if { [empty_string_p $language] } { - set language "en" - } - switch $language { - string tolower $language - "en" {set status [lindex $nodelist 1]} - "fr" {set status [lindex $nodelist 2]} - "de" {set status [lindex $nodelist 3]} - "ja" {set status [lindex $nodelist 4]} - "zh" {set status [lindex $nodelist 5]} - "cn" {set status [lindex $nodelist 5]} - "zh/cn" {set status [lindex $nodelist 5]} - "hk" {set status [lindex $nodelist 6]} - "tw" {set status [lindex $nodelist 6]} - "zh/tw" {set status [lindex $nodelist 6]} - "pt" {set status [lindex $nodelist 7]} - "pt/br" {set status [lindex $nodelist 8]} - "it" {set status [lindex $nodelist 9]} - "es" {set status [lindex $nodelist 10]} - "pl" {set status [lindex $nodelist 11]} - "se" {set status [lindex $nodelist 12]} - default {set status [lindex $nodelist 1]} - } - return $status -} - -ad_proc -public template::util::skype::status_img { - -username:required - {-image_type ""} -} { - This procedure is a wrapper procedure for template::util::skype::status, and should be used to get an image of the users status. - - @param username The username to check the status for. - @param image_type - image_type specifies the type of image to be returned. Defaults to balloon. Available image types are: - - - @see template::util::skype::status -} { - #The status image url for a png image - set uri [template::util::skype::status -username $username -response_type "img" -image_type $image_type] - - return "" -} -