]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Emails/ListViewGroup.php
Release 6.4.0
[Github/sugarcrm.git] / modules / Emails / ListViewGroup.php
1 <?php
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.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description:  TODO: To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46
47
48
49
50
51
52 require_once('modules/MySettings/StoreQuery.php');
53
54 global $app_strings;
55 global $app_list_strings;
56 global $mod_strings;
57 global $urlPrefix;
58 global $currentModule;
59
60 global $theme;
61 global $focus_list; // focus_list is the means of passing data to a ListView.
62
63 $focus                          = new Email();
64 $header_text            = '';
65 $where                          = '';
66 $type                           = '';
67 $assigned_user_id       = '';
68 $group                          = '';
69 $search_adv                     = '';
70 $whereClauses           = array();
71 $error                          = '';
72
73 ///////////////////////////////////////////////////////////////////////////////
74 ////
75 ////    SEARCH FORM FUNCTIONALITY
76 ////    SEARCH QUERY GENERATION
77 $storeQuery = new StoreQuery();
78
79 if(!isset($_REQUEST['query'])){
80         //_pp('loading: '.$currentModule.'Group');
81         //_pp($current_user->user_preferences[$currentModule.'GroupQ']);
82         $storeQuery->loadQuery($currentModule.'Group');
83         $storeQuery->populateRequest();
84 } else {
85         //_pp($current_user->user_preferences[$currentModule.'GroupQ']);
86         //_pp('saving: '.$currentModule.'Group');
87         $storeQuery->saveFromGet($currentModule.'Group');
88 }
89
90 if(isset($_REQUEST['query'])) {
91         // we have a query
92         if(isset($_REQUEST['email_type']))                              $email_type = $_REQUEST['email_type'];
93         if(isset($_REQUEST['assigned_to']))                             $assigned_to = $_REQUEST['assigned_to'];
94         if(isset($_REQUEST['status']))                                  $status = $_REQUEST['status'];
95         if(isset($_REQUEST['name']))                                    $name = $_REQUEST['name'];
96         if(isset($_REQUEST['contact_name']))                    $contact_name = $_REQUEST['contact_name'];
97         
98         if(isset($email_type) && $email_type != "")             $whereClauses['emails.type'] = "emails.type = '".$GLOBALS['db']->quote($email_type)."'";
99         if(isset($assigned_to) && $assigned_to != "")   $whereClauses['emails.assigned_user_id'] = "emails.assigned_user_id = '".$GLOBALS['db']->quote($assigned_to)."'";
100         if(isset($status) && $status != "")                             $whereClauses['emails.status'] = "emails.status = '".$GLOBALS['db']->quote($status)."'";
101         if(isset($name) && $name != "")                                 $whereClauses['emails.name'] = "emails.name like '".$GLOBALS['db']->quote($name)."%'";
102         if(isset($contact_name) && $contact_name != '') {
103                 $contact_names = explode(" ", $contact_name);
104                 foreach ($contact_names as $name) {
105                         $whereClauses['contacts.name'] = "(contacts.first_name like '".$GLOBALS['db']->quote($name)."%' OR contacts.last_name like '".$GLOBALS['db']->quote($name)."%')";
106                 }
107         }
108
109         $focus->custom_fields->setWhereClauses($whereClauses);
110         
111         $GLOBALS['log']->info("Here is the where clause for the list view: $where");
112 } // end isset($_REQUEST['query'])
113
114
115
116 ////    OUTPUT GENERATION
117
118 if (!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') {
119         // ASSIGNMENTS pre-processing
120         $email_type_sel = '';
121         $assigned_to_sel = '';
122         $status_sel = '';
123         if(isset($_REQUEST['email_type']))              $email_type_sel = $_REQUEST['email_type'];
124         if(isset($_REQUEST['assigned_to']))             $assigned_to_sel = $_REQUEST['assigned_to'];
125         if(isset($_REQUEST['status']))                  $status_sel = $_REQUEST['status'];
126         if(isset($_REQUEST['search']))                  $search_adv = $_REQUEST['search'];
127
128         // drop-downs values
129         $r = $focus->db->query("SELECT id, user_name FROM users WHERE deleted = 0 AND status = 'Active' OR users.is_group = 1 ORDER BY status");
130         $users[] = '';
131         while($a = $focus->db->fetchByAssoc($r)) {
132                 $users[$a['id']] = $a['user_name'];
133         }
134         
135         $email_types[] = '';
136         $email_types = array_merge($email_types, $app_list_strings['dom_email_types']);
137         $email_status[] = '';
138         $email_status = array_merge($email_status, $app_list_strings['dom_email_status']);
139         $types                  = get_select_options_with_id($email_types, $email_type_sel);
140         $assigned_to    = get_select_options_with_id($users, $assigned_to_sel);
141         $email_status   = get_select_options_with_id($email_status, $status_sel);
142         
143         // ASSIGNMENTS AND OUTPUT
144         $search_form = new XTemplate ('modules/Emails/SearchFormGroupInbox.html');
145         $search_form->assign('MOD', $mod_strings);
146         $search_form->assign('APP', $app_strings);
147         $search_form->assign('ADVANCED_SEARCH_PNG', SugarThemeRegistry::current()->getImage('advanced_search','border="0"', null,null,'.gif',$app_strings['LNK_ADVANCED_SEARCH']));
148         $search_form->assign('BASIC_SEARCH_PNG', SugarThemeRegistry::current()->getImage('basic_search','border="0"', null,null,'.gif',$app_strings['LNK_BASIC_SEARCH']));
149         $search_form->assign('TYPE_OPTIONS', $types);
150         $search_form->assign('ASSIGNED_TO_OPTIONS', $assigned_to);
151         $search_form->assign('STATUS_OPTIONS', $email_status);
152         $search_form->assign('ADV_URL', $_SERVER['REQUEST_URI']);
153         $search_form->assign('SEARCH_ADV', $search_adv);
154         $search_form->assign('SEARCH_ACTION', 'ListViewGroup');
155
156         if(isset($_REQUEST['name']))                    $search_form->assign('NAME', $_REQUEST['name']);
157         if(isset($_REQUEST['contact_name']))    $search_form->assign('CONTACT_NAME', $_REQUEST['contact_name']);
158         if(isset($current_user_only))                   $search_form->assign('CURRENT_USER_ONLY', "checked");
159
160         // adding custom fields:
161         $focus->custom_fields->populateXTPL($search_form, 'search' );
162         
163         if(!empty($get['assigned_user_id'])) {
164                 $search_form->assign('ASSIGNED_USER_ID', $get['assigned_user_id']);
165         }
166         $search_form->assign('JAVASCRIPT', $focus->u_get_clear_form_js());
167 }
168 ////    END SEARCH FORM FUNCTIONALITY
169 ////    
170 ///////////////////////////////////////////////////////////////////////////////
171
172
173
174 ///////////////////////////////////////////////////////////////////////////////
175 ////    NAVIGATION HACK
176 $_SESSION['emailStartAction'] = ''; // empty this value to allow new writes
177 ////    END NAVIGATION HACK
178 ///////////////////////////////////////////////////////////////////////////////
179
180
181
182 ///////////////////////////////////////////////////////////////////////////////
183 ////
184 ////    INBOX FUNCTIONALITY
185 // for Inbox
186 $r = $focus->db->query('SELECT count(id) AS c FROM users WHERE users.is_group = 1 AND deleted = 0');
187 $a = $focus->db->fetchByAssoc($r);
188
189 $or = 'emails.assigned_user_id IN (\'abc\''; // must have a dummy entry to force group inboxes to not show personal emails
190 if($a['c'] > 0) {
191         
192         $r = $focus->db->query('SELECT id FROM users WHERE users.is_group = 1 AND deleted = 0');
193         while($a = $focus->db->fetchByAssoc($r)) {
194                 $or .= ',\''.$a['id'].'\'';
195         }
196 }
197 $or .= ') ';
198 $whereClauses['emails.assigned_user_id'] = $or;
199 $whereClauses['emails.type'] = 'emails.type = \'inbound\'';
200
201 $display_title = $mod_strings['LBL_LIST_TITLE_GROUP_INBOX'];
202 ////    END INBOX FUNCTIONALITY
203 ////
204 ///////////////////////////////////////////////////////////////////////////////
205
206
207
208 ///////////////////////////////////////////////////////////////////////////////
209 ////    OUTPUT
210 ///////////////////////////////////////////////////////////////////////////////
211
212 echo getClassicModuleTitle("Emails", array($mod_strings['LBL_MODULE_TITLE'].$display_title), true); 
213 // admin-edit
214 if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){      
215         $header_text = "&nbsp;<a href='index.php?action=index&module=DynamicLayout&from_action=SearchForm&from_module=".$_REQUEST['module'] ."'>".SugarThemeRegistry::current()->getImage("EditLayout","border='0' align='bottom'",null,null,'.gif',$mod_strings['LBL_EDIT_LAYOUT'])."</a>";
216 }
217 // search form
218 echo get_form_header($mod_strings['LBL_SEARCH_FORM_TITLE']. $header_text, "", false);
219 // ADVANCED SEARCH
220 if(isset($_REQUEST['search']) && $_REQUEST['search'] == 'advanced') {
221         $search_form->parse('adv');
222         $search_form->out('adv');
223
224 } else {
225         $search_form->parse('main');
226         $search_form->out('main');
227 }
228 echo $focus->rolloverStyle; // for email previews
229 if(!empty($_REQUEST['error'])) {
230         $error = $app_list_strings['dom_email_errors'][$_REQUEST['error']];     
231 }
232 //_pp($where);
233 if(!empty($assigned_to_sel)) {
234         $whereClauses['emails.assigned_user_id'] = 'emails.assigned_user_id = \''.$assigned_to_sel.'\'';
235 }
236
237 //_pp($whereClauses);
238
239 // CONSTRUCT WHERE STRING FROM WHERECLAUSE ARRAY
240 foreach($whereClauses as $clause) {
241         if($where != '') {
242                 $where .= ' AND ';
243         }
244         $where .= $clause;
245 }
246 //echo $focus->quickCreateJS();
247
248 $ListView = new ListView();
249 // group distributionforms
250 echo $focus->distributionForm($where);
251
252 $ListView->shouldProcess = true;
253 $ListView->show_mass_update = true;
254 $ListView->show_mass_update_form = false;
255 $ListView->initNewXTemplate( 'modules/Emails/ListViewGroupInbox.html',$mod_strings);
256 $ListView->xTemplateAssign('ATTACHMENT_HEADER', SugarThemeRegistry::current()->getImage('attachment',"","","",'.gif',$mod_strings['LBL_ATTACHMENT']));
257 $ListView->xTemplateAssign('ERROR', $error);
258 $ListView->xTemplateAssign('CHECK_MAIL',$focus->checkInbox('group'));
259 $ListView->setHeaderTitle($display_title . $header_text );
260 $ListView->setQuery($where, '', 'date_sent, date_entered DESC', 'EMAIL');
261 $ListView->setAdditionalDetails();
262 $ListView->processListView($focus, 'main', 'EMAIL');
263
264 ?>