Support images master
authorJoey Schulze <joey@infodrom.org>
Sun, 6 Mar 2011 21:40:48 +0000 (22:40 +0100)
committerJoey Schulze <joey@infodrom.org>
Sun, 6 Mar 2011 21:40:48 +0000 (22:40 +0100)
Save an image when adding new items
Display the image in a new popup
Scale the image if it is larger than 60% of the window size

work_geraete.php

index 08d99d4..d52f9c2 100644 (file)
@@ -1,5 +1,91 @@
 <?php
 
+$style[] = <<<EOC
+div#photo_name {
+  background: #DDD;
+}
+EOC;
+
+$jscode[] = <<<EOC
+var photoPopup = false;
+
+function photoLoad_callback(data)
+{
+  if (data == false) {
+    photoPopup.closePopup();
+    return;
+  }
+
+  var source = document.getElementById('source');
+  if (!source) return false;
+
+  var width = data.width;
+  var height = data.height;
+
+  maxWidth = Math.floor(RicoUtil.windowWidth() / 100 * 60);
+  maxHeight = Math.floor(RicoUtil.windowHeight() / 100 * 60);
+
+  var factor = false;
+  if (width > maxWidth) {
+    factor = maxWidth / width;
+    if ((height * factor) > maxHeight)
+      factor = maxHeight / height;
+  } else
+    if ((height * factor) > maxHeight)
+      factor = maxHeight / height;
+
+  if (factor) {
+    width = Math.floor(width * factor);
+    height = Math.floor(height * factor);
+  }
+
+  var photo = document.getElementById('photo');
+  photo.height = height;
+  photo.width = width;
+
+  photo.src = 'ajax/ajax.php?source='+source.innerHTML+'&func=file&name=photo&id=' + data.id;
+
+  var name = document.getElementById('photo_name');
+  name.innerHTML = data.name;
+
+  var x = photoPopup.divPopup.style.left.substr(0,photoPopup.divPopup.style.left.length-2);
+  var y = photoPopup.divPopup.style.top.substr(0,photoPopup.divPopup.style.top.length-2);
+
+  if (x == 0 || y == 0) {
+    x = Math.floor(RicoUtil.windowWidth()/2 - width/2);
+    y = Math.floor(RicoUtil.windowHeight()/2 - height/2);
+  }
+
+  photoPopup.openPopup(x,y);
+}
+
+function photoLoad(id)
+{
+  var source = document.getElementById('source');
+  if (!source) return false;
+
+  var parms = 'source=' + source.innerHTML + '&callback=photo&id=' + id;
+  ajax_request('function', parms, photoLoad_callback);
+}
+
+function show(id)
+{
+  if (!photoPopup) {
+    var options = {
+    hideOnClick: true,
+    canDragFunc: true};
+    photoPopup = new Rico.Popup(options);
+    photoPopup.createWindow('<b>Photo</b>','','auto','auto');
+
+    photoPopup.contentDiv.style.backgroundColor = '#FFFFFF';
+    photoPopup.contentDiv.style.color = '#000000';
+    photoPopup.contentDiv.innerHTML = '<img id="photo" src="" height="" width="" /><div id="photo_name"></div>';
+  }
+
+  photoLoad(id);
+}
+EOC;
+
 $mask = array(
              'table' => 'work_geraete',
              'title' => 'Ger√§testammdaten',
@@ -42,6 +128,13 @@ $mask = array(
                                            'specs' => "filterUI: 't'",
                                            'visible' => false,
                                            ),
+                             'photo' => array(
+                                           'name' => 'Photo',
+                                           'width' => 30,
+                                           'specs' => "ClassName: 'aligncenter', canSort: false",
+                                           'control' => "new Rico.TableColumn.link('javascript:show({0})')",
+                                           'sql' => "'<img src=\"images/icons/download.gif\" title=\"Photo anzeigen\" border=\"0\">'",
+                                           ),
                              ),
              'edit' => array(
                              'name' => array(
@@ -93,19 +186,55 @@ $mask = array(
                                            'size' => 8,
                                            'null' => true,
                                            ),
-/*
                              'path_photo' => array(
                                            'name' => 'Foto',
                                            'type' => 'file',
                                            'path' => 'werkstatt',
                                            'sql' => false,
                                            ),
-*/
                              'comment' => array(
                                            'name' => 'Bemerkung',
                                            'type' => 'textarea',
                                            ),
                              ),
+             'callbacks' => array(
+                                  'photo' => photo_details,
+                             ),
+             'files' => array(
+                              'photo' => download,
+                              ),
              );
 
+function photo_details()
+{
+  global $mask;
+
+  $sql = sprintf("SELECT path_photo,name FROM work_geraete WHERE id = %d", $_POST['id']);
+
+  $sth = pg_query($sql);
+  $row = pg_fetch_assoc($sth);
+
+  if ($row['path_photo'] == NULL) return false;
+
+  $fname = $_SESSION['sys']['basedir'] . 'archive/' . $mask['edit']['path_photo']['path'] . '/' . $row['path_photo'];
+
+  if (!is_file($fname)) return false;
+
+  $imgsize = getimagesize($fname);
+
+  $data = array('id' => $_POST['id'],
+               'width' => $imgsize[0],
+               'height' => $imgsize[1],
+               'name' => $row['name']);
+
+  return $data;
+}
+
+function download()
+{
+  global $mask;
+
+  download_file($mask['table'],'path_photo',$mask['edit']['path_photo']['path'],$_GET['id']);
+}
+
 ?>