[20959] improvement: Better history log on request for approval / notification

Sigurd Nes <[email protected]> Wed, 13 Jan 2010 19:15:51 +0000
Newsgroups gmane.comp.web.phpgroupware.cvs
Message-ID <[email protected]>
Revision: 20959
          http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=20959
Author:   sigurdne
Date:     2010-01-13 19:15:51 +0000 (Wed, 13 Jan 2010)
Log Message:
-----------
improvement: Better history log on request for approval / notification

Modified Paths:
--------------
    people/sigurdne/modules/property/trunk/inc/class.boproject.inc.php
    people/sigurdne/modules/property/trunk/inc/class.boworkorder.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soproject.inc.php
    people/sigurdne/modules/property/trunk/inc/class.soworkorder.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uiproject.inc.php
    people/sigurdne/modules/property/trunk/inc/class.uiworkorder.inc.php

Modified: people/sigurdne/modules/property/trunk/inc/class.boproject.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boproject.inc.php	2010-01-13 19:13:40 UTC (rev 20958)
+++ people/sigurdne/modules/property/trunk/inc/class.boproject.inc.php	2010-01-13 19:15:51 UTC (rev 20959)
@@ -490,6 +490,8 @@
 					case 'SO': $type = lang('Initial Status'); break;
 					case 'S': $type = lang('Status changed'); break;
 					case 'SC': $type = lang('Status confirmed'); break;
+					case 'AP': $type = lang('Ask for approval'); break;
+					case 'ON': $type = lang('Owner notified'); break;
 					default: break;
 				}
 

Modified: people/sigurdne/modules/property/trunk/inc/class.boworkorder.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.boworkorder.inc.php	2010-01-13 19:13:40 UTC (rev 20958)
+++ people/sigurdne/modules/property/trunk/inc/class.boworkorder.inc.php	2010-01-13 19:15:51 UTC (rev 20959)
@@ -520,6 +520,8 @@
 					case 'SO': $type = lang('Initial Status'); break;
 					case 'S': $type = lang('Status changed'); break;
 					case 'SC': $type = lang('Status confirmed'); break;
+					case 'AP': $type = lang('Ask for approval'); break;
+					case 'ON': $type = lang('Owner notified'); break;
 					default: break;
 				}
 

Modified: people/sigurdne/modules/property/trunk/inc/class.soproject.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soproject.inc.php	2010-01-13 19:13:40 UTC (rev 20958)
+++ people/sigurdne/modules/property/trunk/inc/class.soproject.inc.php	2010-01-13 19:15:51 UTC (rev 20959)
@@ -446,10 +446,10 @@
 //echo substr($sql,strripos($sql,'from'));
 			if($GLOBALS['phpgw_info']['server']['db_type']=='postgres')
 			{
-				$sql2 = 'SELECT count(*) FROM (SELECT fm_project.id ' . substr($sql,strripos($sql,'from'))  . ' GROUP BY fm_project.id) as cnt';
+				$sql2 = 'SELECT count(*) as cnt FROM (SELECT fm_project.id ' . substr($sql,strripos($sql,'from'))  . ' GROUP BY fm_project.id) as cnt';
 				$this->db->query($sql2,__LINE__,__FILE__);
 				$this->db->next_record();
-				$this->total_records = $this->db->f(0);
+				$this->total_records = $this->db->f('cnt');
 			}
 			else
 			{
@@ -984,9 +984,14 @@
 					$historylog_workorder	= CreateObject('property.historylog','workorder');
 				}
 
-				if($old_status != $project['status'] && $close_workorders)
+				if($old_status != $project['status'])
 				{
 					$historylog->add('S',$project['id'],$project['status'], $old_status);
+					$receipt['notice_owner'][]=lang('Status changed') . ': ' . $project['status'];
+				}
+				else if($old_status != $project['status'] && $close_workorders)
+				{
+					$historylog->add('S',$project['id'],$project['status'], $old_status);
 
 					$this->db->query("UPDATE fm_workorder SET status='closed' WHERE project_id = {$project['id']}",__LINE__,__FILE__);
 

Modified: people/sigurdne/modules/property/trunk/inc/class.soworkorder.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.soworkorder.inc.php	2010-01-13 19:13:40 UTC (rev 20958)
+++ people/sigurdne/modules/property/trunk/inc/class.soworkorder.inc.php	2010-01-13 19:15:51 UTC (rev 20959)
@@ -494,10 +494,10 @@
 //_debug_array($sql);
 			if($GLOBALS['phpgw_info']['server']['db_type']=='postgres')
 			{
-				$sql2 = 'SELECT count(*) FROM (SELECT fm_workorder.id ' . substr($sql,strripos($sql,'from'))  . ') as cnt';
+				$sql2 = 'SELECT count(*) as cnt FROM (SELECT fm_workorder.id ' . substr($sql,strripos($sql,'from'))  . ') as cnt';
 				$this->db->query($sql2,__LINE__,__FILE__);
 				$this->db->next_record();
-				$this->total_records = $this->db->f('count');//$this->db->f('0');
+				$this->total_records = $this->db->f('cnt');//$this->db->f('0');
 			}
 			else
 			{

Modified: people/sigurdne/modules/property/trunk/inc/class.uiproject.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.uiproject.inc.php	2010-01-13 19:13:40 UTC (rev 20958)
+++ people/sigurdne/modules/property/trunk/inc/class.uiproject.inc.php	2010-01-13 19:15:51 UTC (rev 20959)
@@ -1055,23 +1055,18 @@
 					}
 
 					if ( isset($GLOBALS['phpgw_info']['server']['smtp_server']) 
-						&& $GLOBALS['phpgw_info']['server']['smtp_server']
-						&& $config->config_data['project_approval'] )
+						&& $GLOBALS['phpgw_info']['server']['smtp_server'] )
+//						&& $config->config_data['project_approval'] )
 					{
+						$historylog	= CreateObject('property.historylog','project');
 						if (!is_object($GLOBALS['phpgw']->send))
 						{
 							$GLOBALS['phpgw']->send = CreateObject('phpgwapi.send');
 						}
 
-
 						$action_params['responsible'] = $_account_id;
 							$from_name=$GLOBALS['phpgw_info']['user']['fullname'];
 							$from_email=$GLOBALS['phpgw_info']['user']['preferences']['property']['email'];
-							$headers = "Return-Path: <". $from_email .">\r\n";
-							$headers .= "From: " . $from_name . "<" . $from_email .">\r\n";
-							$headers .= "Bcc: " . $from_name . "<" . $from_email .">\r\n";
-							$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
-							$headers .= "MIME-Version: 1.0\r\n";
 
 						$subject = lang(Approval).": ". $id;
 						$message = '<a href ="http://' . $GLOBALS['phpgw_info']['server']['hostname'] . $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiproject.edit','id'=> $id)).'">' . lang('project %1 needs approval',$id) .'</a>';
@@ -1107,14 +1102,14 @@
 							}
 							else
 							{
+										$historylog->add('AP', $id, lang('%1 is notified',$_address));
 										$receipt['message'][]=array('msg'=>lang('%1 is notified',$_address));
 									}
 								}
 							}
 						}
 
-						if (isset($receipt['notice_owner']) && is_array($receipt['notice_owner']) 
-						 && isset($GLOBALS['phpgw_info']['user']['preferences']['property']['notify_project_owner']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['notify_project_owner'] == 1)
+						if (isset($receipt['notice_owner']) && is_array($receipt['notice_owner']) )
 						{
 							if($this->account!=$values['coordinator'] && $config->config_data['mailnotification'])
 							{
@@ -1145,6 +1140,7 @@
 								}
 								else
 								{
+									$historylog->add('ON', $id, lang('%1 is notified',$to));
 									$receipt['message'][]=array('msg'=>lang('%1 is notified',$to));
 								}
 							}

Modified: people/sigurdne/modules/property/trunk/inc/class.uiworkorder.inc.php
===================================================================
--- people/sigurdne/modules/property/trunk/inc/class.uiworkorder.inc.php	2010-01-13 19:13:40 UTC (rev 20958)
+++ people/sigurdne/modules/property/trunk/inc/class.uiworkorder.inc.php	2010-01-13 19:15:51 UTC (rev 20959)
@@ -869,6 +869,7 @@
 					if (! $receipt['error'])
 					{
 						$id = $receipt['id'];
+						$historylog	= CreateObject('property.historylog','workorder');
 					}
 					$function_msg = lang('Edit Workorder');
 //----------files
@@ -911,11 +912,6 @@
 					{
 						$coordinator_name=$GLOBALS['phpgw_info']['user']['fullname'];
 						$coordinator_email=$GLOBALS['phpgw_info']['user']['preferences']['property']['email'];
-						$headers = "Return-Path: <". $coordinator_email .">\r\n";
-						$headers .= "From: " . $coordinator_name . "<" . $coordinator_email .">\r\n";
-						$headers .= "Bcc: " . $coordinator_name . "<" . $coordinator_email .">\r\n";
-						$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
-						$headers .= "MIME-Version: 1.0\r\n";
 
 						$subject = lang(Approval).": ". $id;
 						$message = '<a href ="http://' . $GLOBALS['phpgw_info']['server']['hostname'] . $GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 'property.uiworkorder.edit', 'id'=> $values['project_id'])).'">' . lang('Workorder %1 needs approval',$id) .'</a>';
@@ -948,6 +944,7 @@
 									$rcpt = $GLOBALS['phpgw']->send->msg('email', $_address, $subject, stripslashes($message), '', $cc, $bcc, $coordinator_email, $coordinator_name, 'html');
 									if($rcpt)
 									{
+										$historylog->add('AP', $id, lang('%1 is notified',$_address));
 										$receipt['message'][]=array('msg'=>lang('%1 is notified',$_address));
 									}
 
@@ -998,8 +995,8 @@
 					$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 'property.uiworkorder.view', 'id'=>$id));
 				}
 				if (isset($receipt['notice_owner']) && is_array($receipt['notice_owner'])
-				 && $config->config_data['mailnotification'] 
-				 && isset($GLOBALS['phpgw_info']['user']['preferences']['property']['notify_project_owner']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['notify_project_owner'])
+				 && $config->config_data['mailnotification'])
+//				 && isset($GLOBALS['phpgw_info']['user']['preferences']['property']['notify_project_owner']) && $GLOBALS['phpgw_info']['user']['preferences']['property']['notify_project_owner'])
 				{
 					if($this->account!=$project['coordinator'] && $config->config_data['workorder_approval'])
 					{
@@ -1030,6 +1027,7 @@
 						}
 						else
 						{
+							$historylog->add('ON', $id, lang('%1 is notified',$to));
 							$receipt['message'][]=array('msg'=>lang('%1 is notified',$to));
 						}
 					}