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: 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($user_id)
111 $query = "DELETE FROM $this->table_name WHERE assigned_user_id = '$user_id'";
112 $this->db->query($query,true,"Error marking last imported records deleted: ");
116 * Undo a single record
118 * @param string $id specific users_last_import id to undo
120 public function undoById($id)
122 global $current_user;
124 $query1 = "SELECT bean_id, bean_type FROM users_last_import WHERE assigned_user_id = '$current_user->id'
125 AND id = '$id' AND deleted=0";
127 $result1 = $this->db->query($query1);
131 while ( $row1 = $this->db->fetchByAssoc($result1))
132 $this->_deleteRecord($row1['bean_id'],$row1['bean_type']);
140 * @param string $module module being imported into
142 public function undo($module)
144 global $current_user;
146 $query1 = "SELECT bean_id, bean_type FROM users_last_import WHERE assigned_user_id = '$current_user->id'
147 AND import_module = '$module' AND deleted=0";
149 $result1 = $this->db->query($query1);
153 while ( $row1 = $this->db->fetchByAssoc($result1))
154 $this->_deleteRecord($row1['bean_id'],$row1['bean_type']);
160 * Deletes a record in a bean
165 protected function _deleteRecord($bean_id,$module)
170 if ( !( $focus instanceof $module) ) {
171 require_once($GLOBALS['beanFiles'][$module]);
172 $focus = new $module;
175 $result = $this->db->query(
176 "DELETE FROM {$focus->table_name}
177 WHERE id = '{$bean_id}'"
181 // Bug 26318: Remove all created e-mail addresses ( from jchi )
182 $result2 = $this->db->query(
183 "SELECT email_address_id
184 FROM email_addr_bean_rel
185 WHERE email_addr_bean_rel.bean_id='{$bean_id}'
186 AND email_addr_bean_rel.bean_module='{$focus->module_dir}'");
188 "DELETE FROM email_addr_bean_rel
189 WHERE email_addr_bean_rel.bean_id='{$bean_id}'
190 AND email_addr_bean_rel.bean_module='{$focus->module_dir}'"
193 while ( $row2 = $this->db->fetchByAssoc($result2)) {
194 if ( !$this->db->getOne(
195 "SELECT email_address_id
196 FROM email_addr_bean_rel
197 WHERE email_address_id = '{$row2['email_address_id']}'") )
199 "DELETE FROM email_addresses
200 WHERE id = '{$row2['email_address_id']}'");
203 if ($focus->hasCustomFields())
205 "DELETE FROM {$focus->table_name}_cstm
206 WHERE id_c = '{$bean_id}'");
210 * Get a list of bean types created in the import
212 * @param string $module module being imported into
214 public static function getBeansByImport($module)
216 global $current_user;
218 $query1 = "SELECT DISTINCT bean_type FROM users_last_import WHERE assigned_user_id = '$current_user->id'
219 AND import_module = '$module' AND deleted=0";
221 $result1 = $GLOBALS['db']->query($query1);
223 return array($module);
225 $returnarray = array();
226 while ( $row1 = $GLOBALS['db']->fetchByAssoc($result1))
227 $returnarray[] = $row1['bean_type'];