2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 /*********************************************************************************
40 * Description: TODO: To be written.
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
47 require_once('modules/Audit/field_assoc.php');
49 class Audit extends SugarBean {
50 var $module_dir = "Audit";
51 var $object_name = "Audit";
54 // This is used to retrieve related fields from form posts.
55 var $additional_column_fields = Array();
61 var $new_schema = true;
63 function get_summary_text()
68 function create_export_query(&$order_by, &$where)
72 function fill_in_additional_list_fields()
76 function fill_in_additional_detail_fields()
80 function fill_in_additional_parent_fields()
84 function get_list_view_data()
88 function get_audit_link()
93 function get_audit_list()
96 global $focus, $genericAssocFieldsArray, $moduleAssocFieldsArray, $current_user, $timedate, $app_strings;
97 $audit_list = array();
98 if(!empty($_REQUEST['record'])) {
99 $result = $focus->retrieve($_REQUEST['record']);
101 if($result == null || !$focus->ACLAccess('', $focus->isOwner($current_user->id)))
103 sugar_die($app_strings['ERROR_NO_RECORD']);
107 if($focus->is_AuditEnabled()){
108 $order= ' order by '.$focus->get_audit_table_name().'.date_created desc' ;//order by contacts_audit.date_created desc
109 $query = "SELECT ".$focus->get_audit_table_name().".*, users.user_name FROM ".$focus->get_audit_table_name().", users WHERE ".$focus->get_audit_table_name().".created_by = users.id AND ".$focus->get_audit_table_name().".parent_id = '$focus->id'".$order;
111 $result = $focus->db->query($query);
112 // We have some data.
113 require('metadata/audit_templateMetaData.php');
114 $fieldDefs = $dictionary['audit']['fields'];
115 while (($row = $focus->db->fetchByAssoc($result))!= null) {
116 $temp_list = array();
118 foreach($fieldDefs as $field){
119 if(isset($row[$field['name']])) {
120 if(($field['name'] == 'before_value_string' || $field['name'] == 'after_value_string') &&
121 (array_key_exists($row['field_name'], $genericAssocFieldsArray) || (!empty($moduleAssocFieldsArray[$focus->object_name]) && array_key_exists($row['field_name'], $moduleAssocFieldsArray[$focus->object_name])) )
124 $temp_list[$field['name']] = Audit::getAssociatedFieldName($row['field_name'], $row[$field['name']]);
126 $temp_list[$field['name']] = $row[$field['name']];
129 if ($field['name'] == 'date_created') {
130 $temp_list[$field['name']]=$timedate->to_display_date_time($temp_list[$field['name']]);
132 if(($field['name'] == 'before_value_string' || $field['name'] == 'after_value_string') && ($row['data_type'] == "enum" || $row['data_type'] == "multienum"))
134 global $app_list_strings;
135 $enum_keys = unencodeMultienum($temp_list[$field['name']]);
136 $enum_values = array();
137 foreach($enum_keys as $enum_key) {
138 if(isset($focus->field_defs[$row['field_name']]['options'])) {
139 $domain = $focus->field_defs[$row['field_name']]['options'];
140 if(isset($app_list_strings[$domain][$enum_key]))
141 $enum_values[] = $app_list_strings[$domain][$enum_key];
144 if(!empty($enum_values)){
145 $temp_list[$field['name']] = implode(', ', $enum_values);
147 if($temp_list['data_type']==='date'){
148 $temp_list[$field['name']]=$timedate->to_display_date($temp_list[$field['name']], false);
151 elseif($field['name'] == 'field_name')
154 if(isset($focus->field_defs[$row['field_name']]['vname'])) {
155 $label = $focus->field_defs[$row['field_name']]['vname'];
156 $temp_list[$field['name']] = translate($label, $focus->module_dir);
162 $temp_list['created_by'] = $row['user_name'];
163 $audit_list[] = $temp_list;
169 function getAssociatedFieldName($fieldName, $fieldValue){
170 global $focus, $genericAssocFieldsArray, $moduleAssocFieldsArray;
172 if(!empty($moduleAssocFieldsArray[$focus->object_name]) && array_key_exists($fieldName, $moduleAssocFieldsArray[$focus->object_name])){
173 $assocFieldsArray = $moduleAssocFieldsArray[$focus->object_name];
176 else if(array_key_exists($fieldName, $genericAssocFieldsArray)){
177 $assocFieldsArray = $genericAssocFieldsArray;
183 $field_arr = $assocFieldsArray[$fieldName];
185 if(is_array($field_arr['select_field_name'])){
186 $count = count($field_arr['select_field_name']);
188 foreach($field_arr['select_field_name'] as $col){
197 $query .= $field_arr['select_field_name'];
200 $query .= " FROM ".$field_arr['table_name']." WHERE ".$field_arr['select_field_join']." = '".$fieldValue."'";
202 $result = $focus->db->query($query);
204 if($row = $focus->db->fetchByAssoc($result)){
205 if(is_array($field_arr['select_field_name'])){
207 foreach($field_arr['select_field_name'] as $col){
208 $returnVal .= $row[$col]." ";
213 return $row[$field_arr['select_field_name']];