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-2011 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 ********************************************************************************/
58 // Case is used to store customer information.
59 class aCase extends Basic {
60 var $field_name_map = array();
65 var $modified_user_id;
66 var $assigned_user_id;
77 var $modified_by_name;
89 var $assigned_user_name;
92 var $table_name = "cases";
93 var $rel_account_table = "accounts_cases";
94 var $rel_contact_table = "contacts_cases";
95 var $module_dir = 'Cases';
96 var $object_name = "Case";
97 var $importable = true;
98 /** "%1" is the case_number, for emails
99 * leave the %1 in if you customize this
100 * YOU MUST LEAVE THE BRACKETS AS WELL*/
101 var $emailSubjectMacro = '[CASE:%1]';
103 // This is used to retrieve related fields from form posts.
104 var $additional_column_fields = Array('bug_id', 'assigned_user_name', 'assigned_user_id', 'contact_id', 'task_id', 'note_id', 'meeting_id', 'call_id', 'email_id');
106 var $relationship_fields = Array('account_id'=>'accounts', 'bug_id' => 'bugs',
107 'task_id'=>'tasks', 'note_id'=>'notes',
108 'meeting_id'=>'meetings', 'call_id'=>'calls', 'email_id'=>'emails',
113 global $sugar_config;
114 if(!$sugar_config['require_accounts']){
115 unset($this->required_fields['account_name']);
118 $this->setupCustomFields('Cases');
119 foreach ($this->field_defs as $field) {
120 $this->field_name_map[$field['name']] = $field;
124 var $new_schema = true;
130 function get_summary_text()
132 return "$this->name";
135 function listviewACLHelper(){
136 $array_assign = parent::listviewACLHelper();
138 if(!empty($this->account_id)){
140 if(!empty($this->account_id_owner)){
141 global $current_user;
142 $is_owner = $current_user->id == $this->account_id_owner;
145 if(!ACLController::moduleSupportsACL('Accounts') || ACLController::checkAccess('Accounts', 'view', $is_owner)){
146 $array_assign['ACCOUNT'] = 'a';
148 $array_assign['ACCOUNT'] = 'span';
151 return $array_assign;
154 function save_relationship_changes($is_update)
156 parent::save_relationship_changes($is_update);
158 if (!empty($this->contact_id)) {
159 $this->set_case_contact_relationship($this->contact_id);
163 function set_case_contact_relationship($contact_id)
165 global $app_list_strings;
166 $default = $app_list_strings['case_relationship_type_default_key'];
167 $this->load_relationship('contacts');
168 $this->contacts->add($contact_id,array('contact_role'=>$default));
171 function fill_in_additional_list_fields()
173 parent::fill_in_additional_list_fields();
174 /*// Fill in the assigned_user_name
175 //$this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
177 $account_info = $this->getAccount($this->id);
178 $this->account_name = $account_info['account_name'];
179 $this->account_id = $account_info['account_id'];*/
182 function fill_in_additional_detail_fields()
184 parent::fill_in_additional_detail_fields();
185 // Fill in the assigned_user_name
186 $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
188 $this->created_by_name = get_assigned_user_name($this->created_by);
189 $this->modified_by_name = get_assigned_user_name($this->modified_user_id);
191 if(!empty($this->id)) {
192 $account_info = $this->getAccount($this->id);
193 if(!empty($account_info)) {
194 $this->account_name = $account_info['account_name'];
195 $this->account_id = $account_info['account_id'];
201 /** Returns a list of the associated contacts
202 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
203 * All Rights Reserved..
204 * Contributor(s): ______________________________________..
206 function get_contacts()
208 $this->load_relationship('contacts');
209 $query_array=$this->contacts->getQuery(true);
211 //update the select clause in the retruned query.
212 $query_array['select']="SELECT contacts.id, contacts.first_name, contacts.last_name, contacts.title, contacts.email1, contacts.phone_work, contacts_cases.contact_role as case_role, contacts_cases.id as case_rel_id ";
215 foreach ($query_array as $qstring) {
216 $query.=' '.$qstring;
218 $temp = Array('id', 'first_name', 'last_name', 'title', 'email1', 'phone_work', 'case_role', 'case_rel_id');
219 return $this->build_related_list2($query, new Contact(), $temp);
222 function get_list_view_data(){
223 global $current_language;
224 $app_list_strings = return_app_list_strings_language($current_language);
226 $temp_array = $this->get_list_view_array();
227 $temp_array['NAME'] = (($this->name == "") ? "<em>blank</em>" : $this->name);
228 $temp_array['PRIORITY'] = empty($this->priority)? "" : $app_list_strings['case_priority_dom'][$this->priority];
229 $temp_array['STATUS'] = empty($this->status)? "" : $app_list_strings['case_status_dom'][$this->status];
230 $temp_array['ENCODED_NAME'] = $this->name;
231 $temp_array['CASE_NUMBER'] = $this->case_number;
232 $temp_array['SET_COMPLETE'] = "<a href='index.php?return_module=Home&return_action=index&action=EditView&module=Cases&record=$this->id&status=Closed'>".SugarThemeRegistry::current()->getImage("close_inline","title=".translate('LBL_LIST_CLOSE','Cases')." border='0'")."</a>";
233 //$temp_array['ACCOUNT_NAME'] = $this->account_name; //overwrites the account_name value returned from the cases table.
238 builds a generic search based on the query string using or
239 do not include any $this-> because this is called on without having the class instantiated
241 function build_generic_where_clause ($the_query_string) {
242 $where_clauses = Array();
243 $the_query_string = $this->db->quote($the_query_string);
244 array_push($where_clauses, "cases.name like '$the_query_string%'");
245 array_push($where_clauses, "accounts.name like '$the_query_string%'");
247 if (is_numeric($the_query_string)) array_push($where_clauses, "cases.case_number like '$the_query_string%'");
251 foreach($where_clauses as $clause)
253 if($the_where != "") $the_where .= " or ";
254 $the_where .= $clause;
257 if($the_where != ""){
258 $the_where = "(".$the_where.")";
264 function set_notification_body($xtpl, $case)
266 global $app_list_strings;
268 $xtpl->assign("CASE_SUBJECT", $case->name);
269 $xtpl->assign("CASE_PRIORITY", (isset($case->priority) ? $app_list_strings['case_priority_dom'][$case->priority]:""));
270 $xtpl->assign("CASE_STATUS", (isset($case->status) ? $app_list_strings['case_status_dom'][$case->status]:""));
271 $xtpl->assign("CASE_DESCRIPTION", $case->description);
276 function bean_implements($interface){
278 case 'ACL':return true;
283 function save($check_notify = FALSE){
284 return parent::save($check_notify);
288 * retrieves the Subject line macro for InboundEmail parsing
291 function getEmailSubjectMacro() {
292 global $sugar_config;
293 return (isset($sugar_config['inbound_email_case_subject_macro']) && !empty($sugar_config['inbound_email_case_subject_macro'])) ?
294 $sugar_config['inbound_email_case_subject_macro'] : $this->emailSubjectMacro;
297 function getAccount($case_id){
298 if(empty($case_id)) return array();
299 $ret_array = array();
300 $query = "SELECT acc.id, acc.name from accounts acc, cases where acc.id = cases.account_id and cases.id = '" . $case_id . "' and cases.deleted=0 and acc.deleted=0";
301 $result = $this->db->query($query,true," Error filling in additional detail fields: ");
303 // Get the id and the name.
304 $row = $this->db->fetchByAssoc($result);
307 $ret_array['account_name'] = stripslashes($row['name']);
308 $ret_array['account_id'] = $row['id'];
311 $ret_array['account_name'] = '';
312 $ret_array['account_id'] = '';