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 var $disable_custom_fields = true;
67 public $column_fields = array(
74 public $new_schema = true;
75 public $additional_column_fields = Array();
80 public function __construct()
86 * Extends SugarBean::listviewACLHelper
90 public function listviewACLHelper()
92 $array_assign = parent::listviewACLHelper();
94 if ( !ACLController::moduleSupportsACL('Accounts')
95 || ACLController::checkAccess('Accounts', 'view', $is_owner) ) {
96 $array_assign['ACCOUNT'] = 'a';
99 $array_assign['ACCOUNT'] = 'span';
101 return $array_assign;
105 * Delete all the records for a particular user
107 * @param string $user_id user id of the user doing the import
109 public function mark_deleted_by_user_id(
113 $query = "DELETE FROM $this->table_name
114 WHERE assigned_user_id = '$user_id'";
115 $this->db->query($query,true,"Error marking last imported records deleted: ");
119 * Undo a single record
121 * @param string $id specific users_last_import id to undo
123 public function undoById(
127 global $current_user;
129 $query1 = "SELECT bean_id, bean_type
130 FROM users_last_import
131 WHERE assigned_user_id = '$current_user->id'
135 $result1 = $this->db->query($query1);
139 while ( $row1 = $this->db->fetchByAssoc($result1))
140 $this->_deleteRecord($row1['bean_id'],$row1['bean_type']);
148 * @param string $module module being imported into
150 public function undo(
154 global $current_user;
156 $query1 = "SELECT bean_id, bean_type
157 FROM users_last_import
158 WHERE assigned_user_id = '$current_user->id'
159 AND import_module = '$module'
162 $result1 = $this->db->query($query1);
166 while ( $row1 = $this->db->fetchByAssoc($result1))
167 $this->_deleteRecord($row1['bean_id'],$row1['bean_type']);
173 * Deletes a record in a bean
178 protected function _deleteRecord(
186 if ( !( $focus instanceof $module) ) {
187 require_once($GLOBALS['beanFiles'][$module]);
188 $focus = new $module;
191 $result = $this->db->query(
192 "DELETE FROM {$focus->table_name}
193 WHERE id = '{$bean_id}'"
197 // Bug 26318: Remove all created e-mail addresses ( from jchi )
198 $result2 = $this->db->query(
199 "SELECT email_address_id
200 FROM email_addr_bean_rel
201 WHERE email_addr_bean_rel.bean_id='{$bean_id}'
202 AND email_addr_bean_rel.bean_module='{$focus->module_dir}'");
204 "DELETE FROM email_addr_bean_rel
205 WHERE email_addr_bean_rel.bean_id='{$bean_id}'
206 AND email_addr_bean_rel.bean_module='{$focus->module_dir}'"
209 while ( $row2 = $this->db->fetchByAssoc($result2)) {
210 if ( !$this->db->getOne(
211 "SELECT email_address_id
212 FROM email_addr_bean_rel
213 WHERE email_address_id = '{$row2['email_address_id']}'") )
215 "DELETE FROM email_addresses
216 WHERE id = '{$row2['email_address_id']}'");
219 if ($focus->hasCustomFields())
221 "DELETE FROM {$focus->table_name}_cstm
222 WHERE id_c = '{$bean_id}'");
226 * Get a list of bean types created in the import
228 * @param string $module module being imported into
230 public static function getBeansByImport(
234 global $current_user;
236 $query1 = "SELECT DISTINCT bean_type
237 FROM users_last_import
238 WHERE assigned_user_id = '$current_user->id'
239 AND import_module = '$module'
242 $result1 = $GLOBALS['db']->query($query1);
244 return array($module);
246 $returnarray = array();
247 while ( $row1 = $GLOBALS['db']->fetchByAssoc($result1))
248 $returnarray[] = $row1['bean_type'];