2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM 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: Bean class for the users_last_import table
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 ********************************************************************************/
46 require_once('modules/Import/Forms.php');
48 class UsersLastImport extends SugarBean
54 public $assigned_user_id;
55 public $import_module;
61 * Set the default settings from Sugarbean
63 public $module_dir = 'Import';
64 public $table_name = "users_last_import";
65 public $object_name = "UsersLastImport";
66 public $column_fields = array(
73 public $new_schema = true;
74 public $additional_column_fields = Array();
79 public function __construct()
85 * Extends SugarBean::listviewACLHelper
89 public function listviewACLHelper()
91 $array_assign = parent::listviewACLHelper();
93 if ( !ACLController::moduleSupportsACL('Accounts')
94 || ACLController::checkAccess('Accounts', 'view', $is_owner) ) {
95 $array_assign['ACCOUNT'] = 'a';
98 $array_assign['ACCOUNT'] = 'span';
100 return $array_assign;
104 * Delete all the records for a particular user
106 * @param string $user_id user id of the user doing the import
108 public function mark_deleted_by_user_id(
112 $query = "DELETE FROM $this->table_name
113 WHERE assigned_user_id = '$user_id'";
114 $this->db->query($query,true,"Error marking last imported records deleted: ");
118 * Undo a single record
120 * @param string $id specific users_last_import id to undo
122 public function undoById(
126 global $current_user;
128 $query1 = "SELECT bean_id, bean_type
129 FROM users_last_import
130 WHERE assigned_user_id = '$current_user->id'
134 $result1 = $this->db->query($query1);
138 while ( $row1 = $this->db->fetchByAssoc($result1))
139 $this->_deleteRecord($row1['bean_id'],$row1['bean_type']);
147 * @param string $module module being imported into
149 public function undo(
153 global $current_user;
155 $query1 = "SELECT bean_id, bean_type
156 FROM users_last_import
157 WHERE assigned_user_id = '$current_user->id'
158 AND import_module = '$module'
161 $result1 = $this->db->query($query1);
165 while ( $row1 = $this->db->fetchByAssoc($result1))
166 $this->_deleteRecord($row1['bean_id'],$row1['bean_type']);
172 * Deletes a record in a bean
177 protected function _deleteRecord(
185 if ( !( $focus instanceof $module) ) {
186 require_once($GLOBALS['beanFiles'][$module]);
187 $focus = new $module;
190 $result = $this->db->query(
191 "DELETE FROM {$focus->table_name}
192 WHERE id = '{$bean_id}'"
196 // Bug 26318: Remove all created e-mail addresses ( from jchi )
197 $result2 = $this->db->query(
198 "SELECT email_address_id
199 FROM email_addr_bean_rel
200 WHERE email_addr_bean_rel.bean_id='{$bean_id}'
201 AND email_addr_bean_rel.bean_module='{$focus->module_dir}'");
203 "DELETE FROM email_addr_bean_rel
204 WHERE email_addr_bean_rel.bean_id='{$bean_id}'
205 AND email_addr_bean_rel.bean_module='{$focus->module_dir}'"
208 while ( $row2 = $this->db->fetchByAssoc($result2)) {
209 if ( !$this->db->getOne(
210 "SELECT email_address_id
211 FROM email_addr_bean_rel
212 WHERE email_address_id = '{$row2['email_address_id']}'") )
214 "DELETE FROM email_addresses
215 WHERE id = '{$row2['email_address_id']}'");
218 if ($focus->hasCustomFields())
220 "DELETE FROM {$focus->table_name}_cstm
221 WHERE id_c = '{$bean_id}'");
225 * Get a list of bean types created in the import
227 * @param string $module module being imported into
229 public static function getBeansByImport(
233 global $current_user;
235 $query1 = "SELECT DISTINCT bean_type
236 FROM users_last_import
237 WHERE assigned_user_id = '$current_user->id'
238 AND import_module = '$module'
241 $result1 = $GLOBALS['db']->query($query1);
243 return array($module);
245 $returnarray = array();
246 while ( $row1 = $GLOBALS['db']->fetchByAssoc($result1))
247 $returnarray[] = $row1['bean_type'];