Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1. ad_page_contract {
  2. } {
  3. {return_url "/"}
  4. {mode ""}
  5. {title ""}
  6. {available_date ""}
  7. {type_of_transaction ""}
  8. {type_of_property ""}
  9. {price ""}
  10. {taxes ""}
  11. {room_qty ""}
  12. {lavatory_qty ""}
  13. {bathroom_qty ""}
  14. {floors_qty ""}
  15. {surface ""}
  16. {announcer ""}
  17. {description ""}
  18. {charac_required ""}
  19. {charac_opt_arc ""}
  20. {charac_opt_vic ""}
  21. {charac_opt_gen ""}
  22. {status ""}
  23. upload_file:trim,optional
  24. upload_file.tmpfile:tmpfile,optional
  25. }
  26.  
  27. set page_title "Create Annonce [ad_conn instance_name]"
  28. set context [list [list "." "Annonces"] "Create"]
  29.  
  30.  
  31. template::head::add_javascript -src "resources/js/create_annonce_form.js" -order 1
  32.  
  33. if {[string equal $mode "save"]} {
  34.  
  35.  
  36. set myform [ns_getform]
  37. if {[string equal "" $myform]} {
  38. ns_log Notice "No Form was submited"
  39. } else {
  40. ns_log Notice "FORM"
  41. ns_set print $myform
  42. for {set i 0} {$i < [ns_set size $myform]} {incr i} {
  43. set varname [ns_set key $myform $i]
  44. set varvalue [ns_set value $myform $i]
  45. if {[string match {cat_*} $varname]} {
  46. #set varname [lindex [split $varname "_"] 1]
  47. #lappend lchars "$varname $varvalue"
  48. }
  49. }
  50. }
  51.  
  52.  
  53.  
  54.  
  55. set available_date1 "[string trim $available_date]"
  56. set available_date2 "[string map {. -} $available_date1]"
  57. set available_date3 "[template::util::date::get_property year $available_date2] [template::util::date::get_property month $available_date2] [template::util::date::get_property \
  58. day $available_date2]"
  59.  
  60.  
  61. set annonce_id [1c_annonces::annonce::add \
  62. -title $title \
  63. -type_of_transaction $type_of_transaction \
  64. -type_of_property $type_of_property \
  65. -price $price \
  66. -taxes $taxes \
  67. -available_date $available_date \
  68. -room_qty $room_qty \
  69. -lavatory_qty $lavatory_qty \
  70. -bathroom_qty $bathroom_qty \
  71. -floors_qty $floors_qty \
  72. -surface $surface \
  73. -type_of_announcer $announcer \
  74. -description $description \
  75. -charac_req $charac_required \
  76. -charac_opt_gen $charac_opt_gen \
  77. -charac_opt_arc $charac_opt_arc \
  78. -charac_opt_vic $charac_opt_vic \
  79. -status $status]
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. if {[lindex $upload_file 0] ne ""} {
  87. ns_log Notice "UPDLOAD FILE"
  88. ns_log Notice "$upload_file"
  89. ns_log Notice "$upload_file.tmpfile"
  90.  
  91.  
  92.  
  93. set path [ad_tmpnam]
  94. file mkdir $path
  95.  
  96.  
  97.  
  98. # More flexible parameter design could be:
  99. # zip {unzip -jd {out_path} {in_file}} tar {tar xf {in_file} {out_path}} tgz {tar xzf {in_file} {out_path}}
  100.  
  101. set upload_files [list]
  102. set upload_tmpfiles [list]
  103.  
  104. foreach file [glob -nocomplain "$path/*"] {
  105. lappend upload_files [file tail $file]
  106. lappend upload_tmpfiles $file
  107. }
  108.  
  109. set mime_type ""
  110.  
  111.  
  112.  
  113. # ns_log notice "file_add mime_type='${mime_type}'"
  114. set i 0
  115. set number_upload_files [llength $upload_files]
  116. foreach upload_file $upload_files tmpfile $upload_tmpfiles {
  117. set file_id [db_nextval "acs_object_id_seq"]
  118. set folder_id $annonce_id
  119. set this_file_id $file_id
  120. set this_title $title
  121. set mime_type [cr_filename_to_mime_type -create -- $upload_file]
  122. # upload a new file
  123. # if the user choose upload from the folder view
  124. # and the file with the same name already exists
  125. # we create a new revision
  126.  
  127. if {$this_title eq ""} {
  128. set this_title $upload_file
  129. }
  130.  
  131. set existing_item_id [fs::get_item_id -name $upload_file -folder_id $folder_id]
  132.  
  133.  
  134.  
  135.  
  136. if {$existing_item_id ne ""} {
  137. # file with the same name already exists in this folder
  138. if { [parameter::get -parameter "BehaveLikeFilesystemP" -package_id [ad_conn package_id]] } {
  139. # create a new revision -- in effect, replace the existing file
  140. set this_file_id $existing_item_id
  141. permission::require_permission \
  142. -object_id $this_file_id \
  143. -party_id $user_id \
  144. -privilege write
  145. } else {
  146. # create a new file by altering the filename of the
  147. # uploaded new file (append "-1" to filename)
  148. set extension [file extension $upload_file]
  149. set root [string trimright $upload_file $extension]
  150. append new_name $root "-$this_file_id" $extension
  151. set upload_file $new_name
  152. }
  153. }
  154.  
  155.  
  156. # ns_log Notice "$upload_file \ $this_file_id \n $tmpfile \n"
  157.  
  158. fs::add_file \
  159. -name $upload_file \
  160. -item_id $this_file_id \
  161. -parent_id $annonce_id \
  162. -tmp_filename $tmpfile \
  163. -creation_user [ad_conn user_id] \
  164. -creation_ip [ad_conn peeraddr] \
  165. -title "fileannonce-${annonce_id}-${file_id}" \
  166. -description "$this_title - $annonce_id - $this_file_id" \
  167. -package_id [1c_annonces::get_fs_package_id] \
  168. -mime_type $mime_type
  169.  
  170.  
  171. file delete $tmpfile
  172. incr i
  173.  
  174.  
  175. }
  176. file delete $upload_file.tmpfile
  177.  
  178.  
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement