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 ********************************************************************************/
52 require_once('modules/MySettings/StoreQuery.php');
55 global $app_list_strings;
58 global $currentModule;
61 global $focus_list; // focus_list is the means of passing data to a ListView.
67 $assigned_user_id = '';
70 $whereClauses = array();
73 ///////////////////////////////////////////////////////////////////////////////
75 //// SEARCH FORM FUNCTIONALITY
76 //// SEARCH QUERY GENERATION
77 $storeQuery = new StoreQuery();
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();
85 //_pp($current_user->user_preferences[$currentModule.'GroupQ']);
86 //_pp('saving: '.$currentModule.'Group');
87 $storeQuery->saveFromGet($currentModule.'Group');
90 if(isset($_REQUEST['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'];
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)."%')";
109 $focus->custom_fields->setWhereClauses($whereClauses);
111 $GLOBALS['log']->info("Here is the where clause for the list view: $where");
112 } // end isset($_REQUEST['query'])
116 //// OUTPUT GENERATION
118 if (!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') {
119 // ASSIGNMENTS pre-processing
120 $email_type_sel = '';
121 $assigned_to_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'];
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");
131 while($a = $focus->db->fetchByAssoc($r)) {
132 $users[$a['id']] = $a['user_name'];
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);
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');
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");
160 // adding custom fields:
161 $focus->custom_fields->populateXTPL($search_form, 'search' );
163 if(!empty($get['assigned_user_id'])) {
164 $search_form->assign('ASSIGNED_USER_ID', $get['assigned_user_id']);
166 $search_form->assign('JAVASCRIPT', $focus->u_get_clear_form_js());
168 //// END SEARCH FORM FUNCTIONALITY
170 ///////////////////////////////////////////////////////////////////////////////
174 ///////////////////////////////////////////////////////////////////////////////
176 $_SESSION['emailStartAction'] = ''; // empty this value to allow new writes
177 //// END NAVIGATION HACK
178 ///////////////////////////////////////////////////////////////////////////////
182 ///////////////////////////////////////////////////////////////////////////////
184 //// INBOX FUNCTIONALITY
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);
189 $or = 'emails.assigned_user_id IN (\'abc\''; // must have a dummy entry to force group inboxes to not show personal emails
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'].'\'';
198 $whereClauses['emails.assigned_user_id'] = $or;
199 $whereClauses['emails.type'] = 'emails.type = \'inbound\'';
201 $display_title = $mod_strings['LBL_LIST_TITLE_GROUP_INBOX'];
202 //// END INBOX FUNCTIONALITY
204 ///////////////////////////////////////////////////////////////////////////////
208 ///////////////////////////////////////////////////////////////////////////////
210 ///////////////////////////////////////////////////////////////////////////////
212 echo getClassicModuleTitle("Emails", array($mod_strings['LBL_MODULE_TITLE'].$display_title), true);
214 if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){
215 $header_text = " <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>";
218 echo get_form_header($mod_strings['LBL_SEARCH_FORM_TITLE']. $header_text, "", false);
220 if(isset($_REQUEST['search']) && $_REQUEST['search'] == 'advanced') {
221 $search_form->parse('adv');
222 $search_form->out('adv');
225 $search_form->parse('main');
226 $search_form->out('main');
228 echo $focus->rolloverStyle; // for email previews
229 if(!empty($_REQUEST['error'])) {
230 $error = $app_list_strings['dom_email_errors'][$_REQUEST['error']];
233 if(!empty($assigned_to_sel)) {
234 $whereClauses['emails.assigned_user_id'] = 'emails.assigned_user_id = \''.$assigned_to_sel.'\'';
237 //_pp($whereClauses);
239 // CONSTRUCT WHERE STRING FROM WHERECLAUSE ARRAY
240 foreach($whereClauses as $clause) {
246 //echo $focus->quickCreateJS();
248 $ListView = new ListView();
249 // group distributionforms
250 echo $focus->distributionForm($where);
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');