antoniop
committed
on 07 Dec 18
Prettify code
openacs-4/.../file-storage/www/file-add.tcl (+20 -10)
30 30                 return
31 31             }
32 32         }
33 33         if {![info exists folder_id] || ![fs_folder_p $folder_id]} {
34 34             ad_complain "The specified parent folder is not valid."
35 35         }
36 36     }
37 37     max_size -requires {upload_file} {
38 38         set n_bytes [file size ${upload_file.tmpfile}]
39 39         set max_bytes [fs::max_upload_size]
40 40         if { $n_bytes > $max_bytes } {
41 41             ad_complain "Your file is larger than the maximum file size allowed on this system ([util_commify_number $max_bytes] bytes)"
42 42         }
43 43     }
44 44 }
45 45
46 46 set user_id [ad_conn user_id]
47 47 set package_id [ad_conn package_id]
48 48 set unpack_binary [util::which [string trim [parameter::get -parameter UnzipBinary]]]
49 49 set unpack_available_p [expr {$unpack_binary ne ""}]
50   # check for write permission on the folder or item
51 50
  51 # check for write permission on the folder or item
52 52 permission::require_permission \
53 53     -object_id $folder_id \
54 54     -party_id $user_id \
55 55     -privilege "write"
56 56
57 57 if {![ad_form_new_p -key file_id]} {
58 58     permission::require_permission \
59 59         -object_id $file_id \
60 60         -party_id $user_id \
61 61         -privilege "write"
62 62     set page_title [_ file-storage.Add_Revision]
63 63 } else {
64 64     set page_title [_ file-storage.Add_File]
65 65 }
66 66 set context [fs_context_bar_list -final $page_title $folder_id]
67 67
68 68 ad_form -html { enctype multipart/form-data } \
69 69     -export { folder_id lock_title_p name return_url } \
70 70     -form {
71 71         file_id:key
72           {upload_file:file {label \#file-storage.Upload_a_file\#} {html "size 30"}}
  72         {upload_file:file
  73             {label "#file-storage.Upload_a_file#"}
  74             {html "size 30"}
73 75         }
  76     }
74 77
75 78 if {[parameter::get -parameter AllowTextEdit -default 0]} {
76 79     if {[ad_form_new_p -key file_id]} {
77  
78 80         # To allow the creation of files
79 81         ad_form -extend -form {
80 82             {content_body:richtext(richtext),optional
81 83                 {label "Create a file"}
82 84                 {html "rows 20 cols 70" }
83 85                 {htmlarea_p 1}
84 86             }
85 87         }
86 88     } else {
87 89         # To make content editable
88 90         set mime_type [db_string get_mime_type {
89 91             select mime_type from fs_objects where object_id = :file_id
90 92         }]
91 93         if {$mime_type eq "text/html"} {
92 94             ad_form -extend -form {
93 95                 {edit_content:richtext(richtext),optional
94 96                     {label "Content"}
95 97                     {html "rows 20 cols 70" }
96 98                     {htmlarea_p 1}
97 99                 }
98 100                 {mime_type:text(hidden)
99 101                     {value $mime_type}
100 102                 }
101 103             }
102 104         }
103 105     }
104 106 }
105 107
106 108 if {$lock_title_p} {
107 109     ad_form -extend -form {
108           {title:text(hidden) {value $title}}
  110         {title:text(hidden)
  111             {value $title}
109 112         }
  113     }
110 114 } else {
111 115     ad_form -extend -form {
112           {title:text,optional {label \#file-storage.Title\#} {html {size 30}} }
  116         {title:text,optional
  117             {label "#file-storage.Title#"}
  118             {html {size 30}}
113 119         }
114 120     }
  121 }
115 122 ad_form -extend -form {
116       {description:text(textarea),optional {label \#file-storage.Description\#} {html "rows 5 cols 35"}}
  123     {description:text(textarea),optional
  124         {label "#file-storage.Description#"}
  125         {html "rows 5 cols 35"}
117 126     }
  127 }
118 128
119 129 if {[ad_form_new_p -key file_id] && $unpack_available_p } {
120 130     ad_form -extend -form {
121           {unpack_p:boolean(checkbox),optional \
122                {label \#file-storage.Multiple_files\#} \
123                {options { {\#file-storage.lt_This_is_a_ZIP\# t} }}
  131         {unpack_p:boolean(checkbox),optional
  132             {label "#file-storage.Multiple_files#"}
  133             {options {{"#file-storage.lt_This_is_a_ZIP#" t}}}
124 134         }
125 135     }
126 136 } else {
127 137     set unpack_p false
128 138 }
129 139
130 140 if { [parameter::get -parameter CategoriesP -package_id $package_id -default 0] } {
131 141     if { [info exists file_id] && $file_id ne "" } {
132 142         set categorized_object_id $file_id
133 143     } else {
134 144         # pre-populate with categories from the folder
135 145         set categorized_object_id $folder_id
136 146     }
137 147
138 148     category::ad_form::add_widgets \
139 149         -container_object_id $package_id \
140 150         -categorized_object_id $categorized_object_id \
141 151         -form_name file-add
142 152 }
143 153