From e505519d1a88687ef5272ba8b13476e9feeca203 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Wed, 27 Apr 2011 05:43:10 -0400
Subject: [PATCH] - Improve photo actions handling (set name of upload-photo, disable delete-photo according to photo existance), code cleanup

---
 program/steps/addressbook/func.inc |   45 ++++++++++++++++++++++++---------------------
 1 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index ed87cb1..837256f 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -557,31 +557,34 @@
 function rcmail_contact_photo($attrib)
 {
     global $CONTACTS, $CONTACT_COLTYPES, $RCMAIL, $CONFIG;
-    
+
+    if (!$CONTACT_COLTYPES['photo'])
+        return '';
+
     if ($result = $CONTACTS->get_result())
         $record = $result->first();
-    
+
     $photo_img = $attrib['placeholder'] ? $CONFIG['skin_path'] . $attrib['placeholder'] : 'program/blank.gif';
+    $RCMAIL->output->set_env('photo_placeholder', $photo_img);
     unset($attrib['placeholder']);
-    
-    if ($CONTACT_COLTYPES['photo']) {
-        $RCMAIL->output->set_env('photo_placeholder', $photo_img);
-        
-        if (strpos($record['photo'], 'http:') === 0)
-            $photo_img = $record['photo'];
-        else if ($record['photo'])
-            $photo_img = $RCMAIL->url(array('_action' => 'photo', '_cid' => $record['ID'], '_source' => $_REQUEST['_source']));
-        $img = html::img(array('src' => $photo_img, 'border' => 1, 'alt' => ''));
-        $content = html::div($attrib, $img);
-      
-        if ($RCMAIL->action == 'edit' || $RCMAIL->action == 'add') {
-            $RCMAIL->output->add_gui_object('contactphoto', $attrib['id']);
-            $hidden = new html_hiddenfield(array('name' => '_photo', 'id' => 'ff_photo'));
-            $content .= $hidden->show();
-        }
-  }
-  
-  return $content;
+
+    if (strpos($record['photo'], 'http:') === 0)
+        $photo_img = $record['photo'];
+    else if ($record['photo'])
+        $photo_img = $RCMAIL->url(array('_action' => 'photo', '_cid' => $record['ID'], '_source' => $_REQUEST['_source']));
+    else
+        $ff_value = '-del-'; // will disable delete-photo action
+
+    $img = html::img(array('src' => $photo_img, 'border' => 1, 'alt' => ''));
+    $content = html::div($attrib, $img);
+
+    if ($RCMAIL->action == 'edit' || $RCMAIL->action == 'add') {
+        $RCMAIL->output->add_gui_object('contactphoto', $attrib['id']);
+        $hidden = new html_hiddenfield(array('name' => '_photo', 'id' => 'ff_photo', 'value' => $ff_value));
+        $content .= $hidden->show();
+    }
+
+    return $content;
 }
 
 

--
Gitblit v1.9.1