Support images
[misc/hallinta-kostenrechnung] / work_geraete.php
1 <?php
2
3 $style[] = <<<EOC
4 div#photo_name {
5   background: #DDD;
6 }
7 EOC;
8
9 $jscode[] = <<<EOC
10 var photoPopup = false;
11
12 function photoLoad_callback(data)
13 {
14   if (data == false) {
15     photoPopup.closePopup();
16     return;
17   }
18
19   var source = document.getElementById('source');
20   if (!source) return false;
21
22   var width = data.width;
23   var height = data.height;
24
25   maxWidth = Math.floor(RicoUtil.windowWidth() / 100 * 60);
26   maxHeight = Math.floor(RicoUtil.windowHeight() / 100 * 60);
27
28   var factor = false;
29   if (width > maxWidth) {
30     factor = maxWidth / width;
31     if ((height * factor) > maxHeight)
32       factor = maxHeight / height;
33   } else
34     if ((height * factor) > maxHeight)
35       factor = maxHeight / height;
36
37   if (factor) {
38     width = Math.floor(width * factor);
39     height = Math.floor(height * factor);
40   }
41
42   var photo = document.getElementById('photo');
43   photo.height = height;
44   photo.width = width;
45
46   photo.src = 'ajax/ajax.php?source='+source.innerHTML+'&func=file&name=photo&id=' + data.id;
47
48   var name = document.getElementById('photo_name');
49   name.innerHTML = data.name;
50
51   var x = photoPopup.divPopup.style.left.substr(0,photoPopup.divPopup.style.left.length-2);
52   var y = photoPopup.divPopup.style.top.substr(0,photoPopup.divPopup.style.top.length-2);
53
54   if (x == 0 || y == 0) {
55     x = Math.floor(RicoUtil.windowWidth()/2 - width/2);
56     y = Math.floor(RicoUtil.windowHeight()/2 - height/2);
57   }
58
59   photoPopup.openPopup(x,y);
60 }
61
62 function photoLoad(id)
63 {
64   var source = document.getElementById('source');
65   if (!source) return false;
66
67   var parms = 'source=' + source.innerHTML + '&callback=photo&id=' + id;
68   ajax_request('function', parms, photoLoad_callback);
69 }
70
71 function show(id)
72 {
73   if (!photoPopup) {
74     var options = {
75     hideOnClick: true,
76     canDragFunc: true};
77     photoPopup = new Rico.Popup(options);
78     photoPopup.createWindow('<b>Photo</b>','','auto','auto');
79
80     photoPopup.contentDiv.style.backgroundColor = '#FFFFFF';
81     photoPopup.contentDiv.style.color = '#000000';
82     photoPopup.contentDiv.innerHTML = '<img id="photo" src="" height="" width="" /><div id="photo_name"></div>';
83   }
84
85   photoLoad(id);
86 }
87 EOC;
88
89 $mask = array(
90               'table' => 'work_geraete',
91               'title' => 'Gerätestammdaten',
92               'list' => array(
93                               'id' => array(
94                                             'name' => 'ID',
95                                             'visible' => false,
96                                             'sql' => 'id',
97                                             ),
98                               'name' => array(
99                                             'name' => 'Name',
100                                             'width' => 250,
101                                             'specs' => "filterUI: 't'",
102                                             ),
103                               'hersteller' => array(
104                                             'name' => 'Hersteller',
105                                             'width' => 180,
106                                             'specs' => "filterUI: 't'",
107                                             ),
108                               'baujahr' => array(
109                                             'name' => 'Baujahr',
110                                             'width' => 50,
111                                             'type' => 'number',
112                                             'specs' => "decPlaces: 0, canSort: false, filterUI: 's', thouSep: ''",
113                                             ),
114                               'anschaffung' => array(
115                                             'name' => 'Anschaffung',
116                                             'type' => 'date',
117                                             'width' => 70,
118                                             ),
119                               'preis' => array(
120                                             'name' => 'Preis',
121                                             'type' => 'number',
122                                             'specs' => "decPlaces: 2, ClassName: 'alignright', canSort: false",
123                                             'width' => 70,
124                                             ),
125                               'nummer' => array(
126                                             'name' => 'Gerätenummer',
127                                             'width' => 120,
128                                             'specs' => "filterUI: 't'",
129                                             'visible' => false,
130                                             ),
131                               'photo' => array(
132                                             'name' => 'Photo',
133                                             'width' => 30,
134                                             'specs' => "ClassName: 'aligncenter', canSort: false",
135                                             'control' => "new Rico.TableColumn.link('javascript:show({0})')",
136                                             'sql' => "'<img src=\"images/icons/download.gif\" title=\"Photo anzeigen\" border=\"0\">'",
137                                             ),
138                               ),
139               'edit' => array(
140                               'name' => array(
141                                             'name' => 'Name',
142                                             'type' => 'text',
143                                             'size' => 24,
144                                             'required' => true,
145                                             ),
146                               'hersteller' => array(
147                                             'name' => 'Hersteller',
148                                             'type' => 'text',
149                                             'size' => 24,
150                                             'required' => true,
151                                             ),
152                               'baujahr' => array(
153                                             'name' => 'Baujahr',
154                                             'type' => 'number',
155                                             'size' => 4,
156                                             'required' => true,
157                                             ),
158                               'lieferant' => array(
159                                             'name' => 'Lieferant',
160                                             'type' => 'select',
161                                             'options' => 'SELECT id,name AS text FROM lieferanten ORDER BY name',
162                                             'option_empty' => '-- select --',
163                                             'required' => true,
164                                             ),
165                               'preis' => array(
166                                             'name' => 'Preis',
167                                             'type' => 'decimal',
168                                             'size' => 10,
169                                             'required' => true,
170                                             ),
171                               'leistung' => array(
172                                             'name' => 'Leistung',
173                                             'type' => 'decimal',
174                                             'size' => 10,
175                                             'comment' => 'KW',
176                                             ),
177                               'nummer' => array(
178                                             'name' => 'Gerätenummer',
179                                             'type' => 'text',
180                                             'size' => 20,
181                                             'required' => true,
182                                             ),
183                               'anschaffung' => array(
184                                             'name' => 'Anschaffungsdatum',
185                                             'type' => 'date',
186                                             'size' => 8,
187                                             'null' => true,
188                                             ),
189                               'path_photo' => array(
190                                             'name' => 'Foto',
191                                             'type' => 'file',
192                                             'path' => 'werkstatt',
193                                             'sql' => false,
194                                             ),
195                               'comment' => array(
196                                             'name' => 'Bemerkung',
197                                             'type' => 'textarea',
198                                             ),
199                               ),
200               'callbacks' => array(
201                                    'photo' => photo_details,
202                               ),
203               'files' => array(
204                                'photo' => download,
205                                ),
206               );
207
208 function photo_details()
209 {
210   global $mask;
211
212   $sql = sprintf("SELECT path_photo,name FROM work_geraete WHERE id = %d", $_POST['id']);
213
214   $sth = pg_query($sql);
215   $row = pg_fetch_assoc($sth);
216
217   if ($row['path_photo'] == NULL) return false;
218
219   $fname = $_SESSION['sys']['basedir'] . 'archive/' . $mask['edit']['path_photo']['path'] . '/' . $row['path_photo'];
220
221   if (!is_file($fname)) return false;
222
223   $imgsize = getimagesize($fname);
224
225   $data = array('id' => $_POST['id'],
226                 'width' => $imgsize[0],
227                 'height' => $imgsize[1],
228                 'name' => $row['name']);
229
230   return $data;
231 }
232
233 function download()
234 {
235   global $mask;
236
237   download_file($mask['table'],'path_photo',$mask['edit']['path_photo']['path'],$_GET['id']);
238 }
239
240 ?>