]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - install/UserDemoData.php
Release 6.4.0
[Github/sugarcrm.git] / install / UserDemoData.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
41 class UserDemoData {
42         var $_user;
43         var $_large_scale_test;
44         var $guids = array(
45                 'jim'   => 'seed_jim_id',
46                 'sarah' => 'seed_sarah_id',
47                 'sally' => 'seed_sally_id',
48                 'max'   => 'seed_max_id',
49                 'will'  => 'seed_will_id',
50                 'chris' => 'seed_chris_id',
51         /*
52          * Pending fix of demo data mechanism
53                 'jim'   => 'jim00000-0000-0000-0000-000000000000',
54                 'sarah' => 'sarah000-0000-0000-0000-000000000000',
55                 'sally' => 'sally000-0000-0000-0000-000000000000',
56                 'max'   => 'max00000-0000-0000-0000-000000000000',
57                 'will'  => 'will0000-0000-0000-0000-000000000000',
58                 'chris' => 'chris000-0000-0000-0000-000000000000',
59         */
60         );
61
62         /**
63          * Constructor for creating user demo data
64          */
65         function UserDemoData($seed_user, $large_scale_test = false)
66         {
67                 // use a seed user so it does not have to be known which file to
68                 // include the User class from
69                 $this->_user = $seed_user;
70                 $this->_large_scale_test = $large_scale_test;
71         }
72
73         /**
74          *
75          */
76         function create_demo_data()
77         {
78                 global $current_language;
79                 global $sugar_demodata;
80                 foreach($sugar_demodata['users'] as $v)
81                 {
82                         $this->_create_seed_user($v['id'], $v['last_name'], $v['first_name'], $v['user_name'], $v['title'], $v['is_admin'], $v['reports_to'], $v['reports_to_name'], $v['email']);
83
84                 }
85                 if($this->_large_scale_test) {
86                         $user_list = $this->_seed_data_get_user_list();
87                         foreach($user_list as $user_name)
88                         {
89                                 $this->_quick_create_user($user_name);
90                         }
91                 }
92         }
93
94
95         /**
96          *  Create a user in the seed data.
97          */
98         function _create_seed_user($id, $last_name, $first_name, $user_name,
99                 $title, $is_admin, $reports_to, $reports_to_name, $email)
100         {
101         $u = new User();
102
103                 $u->id=$id;
104                 $u->new_with_id = true;
105                 $u->last_name = $last_name;
106                 $u->first_name = $first_name;
107                 $u->user_name = $user_name;
108                 $u->title = $title;
109                 $u->status = 'Active';
110                 $u->employee_status = 'Active';
111                 $u->is_admin = $is_admin;
112                 //$u->user_password = $u->encrypt_password($user_name);
113                 $u->user_hash = strtolower(md5($user_name));
114                 $u->reports_to_id = $reports_to;
115                 $u->reports_to_name = $reports_to_name;
116                 //$u->email1 = $email;
117                 $u->emailAddress->addAddress($email, true);
118                 $u->emailAddress->addAddress("reply.".$email, false, true);
119                 $u->emailAddress->addAddress("alias.".$email);
120
121                 // bug 15371 tyoung set a user preference so that Users/DetailView.php can find something without repeatedly querying the db in vain
122                 $u->setPreference('max_tabs','7');
123                 $u->savePreferencesToDB();
124
125
126                 $u->picture = $this->_copy_user_image($id);
127
128                 $u->save();
129         }
130
131         /**
132          *
133          */
134         function _seed_data_get_user_list()
135         {
136                 $users = Array();
137 //bug 28138 todo
138                 $users[] = "north";
139                 $users[] = "south";
140                 $users[] = "east";
141                 $users[] = "west";
142                 $users[] = "left";
143                 $users[] = "right";
144                 $users[] = "in";
145                 $users[] = "out";
146                 $users[] = "fly";
147                 $users[] = "walk";
148                 $users[] = "crawl";
149                 $users[] = "pivot";
150                 $users[] = "money";
151                 $users[] = "dinero";
152                 $users[] = "shadow";
153                 $users[] = "roof";
154                 $users[] = "sales";
155                 $users[] = "pillow";
156                 $users[] = "feather";
157
158                 return $users;
159         }
160
161         /**
162          *
163          */
164         function _quick_create_user($name)
165         {
166                 global $sugar_demodata;
167                 if (!$this->_user->retrieve($name.'_id'))
168                 {
169                         $this->_create_seed_user("{$name}_id", $name, $name, $name,
170                                 $sugar_demodata['users'][0]['title'], $sugar_demodata['users'][0]['is_admin'], "seed_jim_id", $sugar_demodata['users'][0]['last_name'].", ".$sugar_demodata['users'][0]['first_name'], $sugar_demodata['users'][0]['email']);
171                 }
172         }
173
174         function _copy_user_image($id) {
175                 global $sugar_config;
176                 $picture_file = create_guid();
177                 $file = "include/images/".$id.".gif";
178                 $newfile = "upload://$picture_file";
179                 if (!copy($file, $newfile)) {
180                         global $app_strings;
181                 $GLOBALS['log']->fatal(string_format($app_strings['ERR_FILE_NOT_FOUND'], array($file)));
182
183                 }
184                 return $picture_file;
185         }
186
187 }
188 ?>