]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Users/reassignUserRecords.php
Release 6.2.0
[Github/sugarcrm.git] / modules / Users / reassignUserRecords.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 global $mod_strings;
40 $mod_strings_users = $mod_strings;
41
42 global $current_user;
43 if(!is_admin($current_user)
44     && !is_admin_for_module($GLOBALS['current_user'],'Users')
45   ){
46         sugar_die("You cannot access this page.");
47 }
48
49 global $locale;
50
51 $return_module = isset($_REQUEST['return_module']) ? $_REQUEST['return_module'] : '';
52 $return_action = isset($_REQUEST['return_action']) ? $_REQUEST['return_action'] : '';
53 $return_id = isset($_REQUEST['return_id']) ? $_REQUEST['return_id'] : '';
54 if(!empty($return_module))
55     $cancel_location = "index.php?module=".$return_module."&action=".$return_action."&record=".$return_id;
56 else 
57     $cancel_location = "index.php?module=Users&action=index";
58                 
59 echo "<h2 class='moduleTitle' style=\"margin-bottom:0px;\">{$mod_strings_users['LBL_REASS_SCRIPT_TITLE']}</h2>";
60
61 // Include Metadata for processing
62 require_once("modules/Users/metadata/reassignScriptMetadata.php");
63 if(file_exists("custom/modules/Users/reassignScriptMetadata_override.php")){
64         include("custom/modules/Users/reassignScriptMetadata_override.php");
65 }
66
67 if(!empty($_GET['record'])){
68         unset($_SESSION['reassignRecords']);
69         $_SESSION['reassignRecords']['fromuser'] = $_GET['record'];
70 }
71
72 if(!isset($_POST['fromuser']) && !isset($_GET['execute'])){
73 ///////////////////// BEGIN STEP 1 - Select users/modules /////////////////////////
74         $exclude_modules = array(
75                 "ImportMap",
76                 "UsersLastImport",
77                 "Dashboard",
78                 "SavedSearch",
79                 "UserPreference",
80             "SugarFavorites",
81         );
82
83         if(isset($_GET['clear']) && $_GET['clear'] == 'true'){
84                 unset($_SESSION['reassignRecords']);
85         }
86 ?>
87 <form method=post action="index.php?module=Users&action=reassignUserRecords" name='EditView' id='EditView'>
88 <table cellspacing='1' cellpadding='1' border='0'>
89 <tr>
90     <td><?php echo $mod_strings_users['LBL_REASS_DESC_PART1']."<BR><br>"?></td>
91 </tr>
92 <tr>
93 <td>
94 <input type=submit class="button" value="<?php echo $mod_strings_users['LBL_REASS_BUTTON_CONTINUE']; ?>" name=steponesubmit>
95 &nbsp;<input type=button class="button" value="<?php echo $mod_strings_users['LBL_REASS_BUTTON_CLEAR']; ?>" onclick='clearCurrentRecords();'>
96 <input type=button class="button" value="<?php echo $app_strings['LBL_CANCEL_BUTTON_LABEL']; ?>" onclick='document.location="<?php echo $cancel_location ?>"'>
97 </td>
98 </tr>
99 </table>
100 <table border='0' cellspacing='0' cellpadding='0'  class='edit view'>
101 <tr>
102 <td>
103 <BR>
104 <?php echo $mod_strings_users['LBL_REASS_USER_FROM']; ?>
105 <BR>
106 <select name="fromuser" id='fromuser'>
107 <?php
108 $active_users = get_user_array(FALSE);
109 $inactive_users = get_user_array(FALSE, "Inactive");
110 $all_users = array_merge($active_users, $inactive_users);
111 // sb - issue with php array_merge causing array index '1' to change to '0'
112 if(isset($all_users[0])){
113         $all_users[1] = 'admin';
114         unset($all_users[0]);
115 }
116 asort($all_users);
117 echo get_select_options_with_id($all_users, isset($_SESSION['reassignRecords']['fromuser']) ? $_SESSION['reassignRecords']['fromuser'] : '');
118 ?>
119 </select>
120 <BR>
121 <BR>
122 <?php echo $mod_strings_users['LBL_REASS_USER_TO']; ?>
123 <BR>
124 <select name="touser" id="touser">
125 <?php
126 if(isset($_SESSION['reassignRecords']['fromuser']) && isset($all_users[$_SESSION['reassignRecords']['fromuser']]))
127 {
128         unset($all_users[$_SESSION['reassignRecords']['fromuser']]);
129 }
130
131 echo get_select_options_with_id($all_users, isset($_SESSION['reassignRecords']['touser']) ? $_SESSION['reassignRecords']['touser'] : '');
132 ?>
133 </select>
134 <?php
135 ?>
136 <BR>
137 <?php echo $mod_strings_users['LBL_REASS_MOD_REASSIGN']; ?>
138 <BR>
139 <select size="6" name='modules[]' multiple="true" id='modulemultiselect' onchange="updateDivDisplay(this);">
140 <?php
141 if(!isset($_SESSION['reassignRecords']['assignedModuleListCache'])){
142         $beanListDup = $beanList;
143         foreach($beanListDup as $m => $p){
144                 if(empty($beanFiles[$p])){
145                         unset($beanListDup[$m]);
146                 }
147                 else{
148                         require_once($beanFiles[$p]);
149                         $obj = new $p();
150                         if( !isset($obj->field_defs['assigned_user_id']) ||
151                                 (
152                                         isset($obj->field_defs['assigned_user_id']) &&
153                                         isset($obj->field_defs['assigned_user_id']['source']) &&
154                                         $obj->field_defs['assigned_user_id']['source'] == "non-db"
155                                 )
156                           )
157                         {
158                                 unset($beanListDup[$m]);
159                         }
160                 }
161         }
162         $beanListDup = array_diff($beanListDup, $exclude_modules);
163         
164         //Leon bug 20739
165         $beanListDupDisp=array() ;
166         foreach($beanListDup as $m => $p){
167                 $beanListDupDisp[$app_list_strings['moduleList'][$m]]=$p;
168         }
169         $_SESSION['reassignRecords']['assignedModuleListCache'] = $beanListDup;
170         $_SESSION['reassignRecords']['assignedModuleListCacheDisp'] = $beanListDupDisp;
171 }
172 $beanListDup = array_flip($_SESSION['reassignRecords']['assignedModuleListCache']);
173 $beanListFlip = array_flip($_SESSION['reassignRecords']['assignedModuleListCacheDisp']);
174 asort($beanListFlip);
175 $selected = array();
176 if(!empty($_SESSION['reassignRecords']['modules'])){
177         foreach($_SESSION['reassignRecords']['modules'] as $mod => $arr)
178                 $selected[] = $mod;
179 }
180 echo get_select_options_with_id($beanListFlip, $selected);
181 ?>
182 </select>
183 <BR>
184 </td>
185 </tr>
186 <tr>
187 <td>
188 <?php
189 foreach($moduleFilters as $modFilter => $fieldArray){
190         $display = (!empty($fieldArray['display_default']) && $fieldArray['display_default'] == true ? "block" : "none");
191         //Leon bug 20739
192         $t_mod_strings=return_module_language($GLOBALS['current_language'], $modFilter);
193         echo "<div id=\"reassign_{$GLOBALS['beanList'][$modFilter]}\" style=\"display:$display\">\n";
194         echo "<h5 style=\"padding-left:0px; margin-bottom:4px;\">{$app_list_strings['moduleList'][$modFilter]} ", " {$mod_strings_users['LBL_REASS_FILTERS']}</h5>\n";
195         foreach($fieldArray['fields'] as $meta){
196                 $multi = "";
197                 $name = (!empty($meta['name']) ? $meta['name'] : "");
198                 $size = (!empty($meta['size']) ? "size=\"{$meta['size']}\"" : "");
199                 //Leon bug 20739
200                 echo $t_mod_strings[$meta['vname']] ."\n<BR>\n";
201                 switch($meta['type']){
202                         case "text":
203                                 $tag = "input";
204                                 break;
205                         case "multiselect":
206                                 $multi = "multiple=\"true\"";
207                                 $name .= "[]";
208                                 // NO BREAK - Continue into select
209                         case "select": 
210                                 $tag = "select";
211                                 $sel = '';
212                                 if(!empty($_SESSION['reassignRecords']['filters'][$meta['name']])){
213                                         $sel = $_SESSION['reassignRecords']['filters'][$meta['name']];
214                                 }
215                                 $extra = get_select_options_with_id($meta['dropdown'], $sel);
216                                 $extra .= "\n</select>";
217                                 break;
218                         default:
219                                 //echo "Skipping field {$meta['name']} since the type is not supported<BR>";
220                                 continue;
221                 }
222                 echo "<$tag $size name=\"$name\" $multi>\n$extra";
223                 echo "<BR>\n";
224         }
225         echo "</div>\n";
226 }
227 ?>
228 </td>
229 </tr>
230 </table>
231 <table cellspacing='1' cellpadding='1' border='0'>
232 <tr>
233 <td>
234 <input type=submit class="button" value="<?php echo $mod_strings_users['LBL_REASS_BUTTON_CONTINUE']; ?>" name=steponesubmit>
235 &nbsp;<input type=button class="button" value="<?php echo $mod_strings_users['LBL_REASS_BUTTON_CLEAR']; ?>" onclick='clearCurrentRecords();'>
236 <input type=button class="button" value="<?php echo $app_strings['LBL_CANCEL_BUTTON_LABEL']; ?>" onclick='document.location="<?php echo $cancel_location ?>"'>
237 </td>
238 </tr>
239 </table>
240 </form>
241
242 <?php
243 ///////////////////// END STEP 1 - Select users/modules /////////////////////////
244 }
245 else if(!isset($_GET['execute'])){
246 ///////////////////// BEGIN STEP 2 - Confirm Selections /////////////////////////
247         if(empty($_POST['modules'])){
248                 sugar_die($mod_strings_users['ERR_REASS_SELECT_MODULE']);
249         }
250         if($_POST['fromuser'] == $_POST['touser']){
251                 sugar_die($mod_strings_users['ERR_REASS_DIFF_USERS']);
252         }
253         
254         global $current_user;
255         // Set the from and to user names so that we can display them in the results
256         $fromusername = $_POST['fromuser'];
257         $tousername = $_POST['touser'];
258         
259         $query = "select user_name, id from users where id in ('{$_POST['fromuser']}', '{$_POST['touser']}')";
260         $res = $GLOBALS['db']->query($query);
261         while($row = $GLOBALS['db']->fetchByAssoc($res)){
262                 if($row['id'] == $_POST['fromuser'])
263                         $fromusername = $row['user_name'];
264                 if($row['id'] == $_POST['touser'])
265                         $tousername = $row['user_name'];
266         }
267         echo "{$mod_strings_users['LBL_REASS_DESC_PART2']}\n";
268         echo "<form action=\"index.php?module=Users&action=reassignUserRecords&execute=true\" method=post>\n";
269         echo "<BR>{$mod_strings_users['LBL_REASS_NOTES_TITLE']}\n";
270         echo "<ul>\n";
271         echo "<li>* {$mod_strings_users['LBL_REASS_NOTES_ONE']}\n";
272         echo "<li>* {$mod_strings_users['LBL_REASS_NOTES_TWO']}\n";
273         echo "<li>* {$mod_strings_users['LBL_REASS_NOTES_THREE']}\n";
274         echo "</ul>\n";
275         $help_img = SugarThemeRegistry::current()->getImage('helpInline','border="0" onmouseout="return nd();" onmouseover="return overlib(\''.$mod_strings['LBL_REASS_VERBOSE_HELP'].'\', FGCLASS, \'olFgClass\', CGCLASS, \'olCgClass\', BGCLASS, \'olBgClass\', TEXTFONTCLASS, \'olFontClass\', CAPTIONFONTCLASS, \'olCapFontClass\', CLOSEFONTCLASS, \'olCloseFontClass\');"');
276         echo "<BR><input type=checkbox name=verbose> {$mod_strings_users['LBL_REASS_VERBOSE_OUTPUT']}".$help_img."<BR>\n";
277         unset($_SESSION['reassignRecords']['modules']);
278         $beanListFlip = array_flip($_SESSION['reassignRecords']['assignedModuleListCache']);
279         foreach($_POST['modules'] as $module){
280                 if(!array_key_exists($module, $beanListFlip)){
281                         //echo "$module not found as key in \$beanListFlip. Skipping $module.<BR>";
282                         continue;
283                 }
284                 $p_module = $beanListFlip[$module];
285                 
286                 require_once($beanFiles[$module]);
287                 $object = new $module();
288                 if(empty($object->table_name)){
289 //                      echo "<h5>Could not find the database table for $p_module.</h5>";
290                         continue;
291                 }
292                 
293                 echo "<h5>{$mod_strings_users['LBL_REASS_ASSESSING']} {$app_list_strings['moduleList'][$p_module]}</h5>";
294                 
295                 echo "<table border='0' cellspacing='0' cellpadding='0'  class='detail view'>\n";
296                 echo "<tr>\n";
297                 echo "<td>\n";
298                 
299                 $q_select = "select id";
300                 $q_update = "update ";
301                 $q_set = " set assigned_user_id = '{$_POST['touser']}', ".
302                               "date_modified = '".TimeDate::getInstance()->nowDb()."', ".
303                               "modified_user_id = '{$current_user->id}' ";
304                 $q_tables   = " {$object->table_name} ";
305                 $q_where  = "where {$object->table_name}.deleted=0 and {$object->table_name}.assigned_user_id = '{$_POST['fromuser']}' ";
306
307                 // Process conditions based on metadata
308                 if(isset($moduleFilters[$p_module]['fields']) && is_array($moduleFilters[$p_module]['fields'])){
309                         $custom_added = false;
310                         foreach($moduleFilters[$p_module]['fields'] as $meta){
311                                 if(!empty($_POST[$meta['name']]))
312                                         $_SESSION['reassignRecords']['filters'][$meta['name']] = $_POST[$meta['name']];
313                                 $is_custom = isset($meta['custom_table']) && $meta['custom_table'] == true;
314                                 if($is_custom && !$custom_added){
315                                         $q_tables .= "inner join {$object->table_name}_cstm on {$object->table_name}.id = {$object->table_name}_cstm.id_c ";
316                                         $custom_added = true;
317                                 }
318                                 $addcstm = ($is_custom ? "_cstm" : "");
319                                 switch($meta['type']){
320                                         case "text":
321                                         case "select":
322                                                 $q_where .= " and {$object->table_name}{$addcstm}.{$meta['dbname']} = '{$_POST[$meta['name']]}' ";
323                                                 break;
324                                         case "multiselect":
325                                                 if(empty($_POST[$meta['name']])){
326                                                         continue;
327                                                 }
328                                                 $in_string = "";
329                                                 $empty_check = "";
330                                                 foreach($_POST[$meta['name']] as $onevalue){
331                                                         if(empty($onevalue))
332                                                                 $empty_check .= " OR {$object->table_name}{$addcstm}.{$meta['dbname']} is null ";
333                                                         $in_string .= "'$onevalue', ";
334                                                 }
335                                                 $in_string = substr($in_string, 0, count($in_string) - 3);
336                                                 $q_where .= " and ({$object->table_name}{$addcstm}.{$meta['dbname']} in ($in_string) $empty_check)";
337                                                 break;
338                                         default:
339                                                 //echo "Skipping field {$meta['name']} since the type is not supported<BR>";
340                                                 continue;
341                                                 break;
342                                 }
343                         }
344                 }
345                 $query = "$q_select from $q_tables $q_where";
346                 $countquery = "select count(*) AS count from $q_tables $q_where";
347                 $updatequery = "$q_update $q_tables $q_set $q_where";
348                 
349                 $_SESSION['reassignRecords']['fromuser'] = $_POST['fromuser'];
350                 $_SESSION['reassignRecords']['touser'] = $_POST['touser'];
351                 $_SESSION['reassignRecords']['fromusername'] = $fromusername;
352                 $_SESSION['reassignRecords']['tousername'] = $tousername;
353                 $_SESSION['reassignRecords']['modules'][$module]['query'] = $query;
354                 $_SESSION['reassignRecords']['modules'][$module]['update'] = $updatequery;
355                 
356                 $res = $GLOBALS['db']->query($countquery);
357                 $row = $GLOBALS['db']->fetchByAssoc($res);
358                 
359                 echo "{$row['count']} {$mod_strings_users['LBL_REASS_RECORDS_FROM']} {$app_list_strings['moduleList'][$p_module]} {$mod_strings_users['LBL_REASS_WILL_BE_UPDATED']}\n<BR>\n";
360                 echo "<input type=checkbox name={$module}_workflow> {$mod_strings_users['LBL_REASS_WORK_NOTIF_AUDIT']}<BR>\n";
361                 echo "</td></tr></table>\n";
362         }
363         
364         echo "<BR><input type=button class=\"button\" value=\"{$mod_strings_users['LBL_REASS_BUTTON_GO_BACK']}\" onclick='document.location=\"index.php?module=Users&action=reassignUserRecords\"'>\n";
365         echo "&nbsp;<input type=submit class=\"button\" value=\"{$mod_strings_users['LBL_REASS_BUTTON_CONTINUE']}\">\n";
366         echo "&nbsp;<input type=button class=\"button\" value=\"{$mod_strings_users['LBL_REASS_BUTTON_RESTART']}\" onclick='document.location=\"index.php?module=Users&action=reassignUserRecords&clear=true\"'>\n";
367         
368         echo "</form>\n";
369         
370         // debug
371         //print_r($_SESSION['reassignRecords']);
372 ///////////////////// END STEP 2 - Confirm Selections /////////////////////////
373 }
374 /////////////////// BEGIN STEP 3 - Execute reassignment ///////////////////////
375 else if(isset($_GET['execute']) && $_GET['execute'] == true){
376         $fromuser = $_SESSION['reassignRecords']['fromuser'];
377         $touser = $_SESSION['reassignRecords']['touser'];
378         $fromusername = $_SESSION['reassignRecords']['fromusername'];
379         $tousername = $_SESSION['reassignRecords']['tousername'];
380         
381         $beanListFlip = array_flip($_SESSION['reassignRecords']['assignedModuleListCache']);
382
383         foreach($_SESSION['reassignRecords']['modules'] as $module => $queries){
384                 $p_module = $beanListFlip[$module];
385                 $workflow = false;
386                 if(isset($_POST[$module."_workflow"]) && $_POST[$module."_workflow"] = "on")
387                         $workflow = true;
388                 
389                 $query = $workflow ? $queries['query'] : $queries['update'];
390                 
391                 echo "<h5>{$mod_strings_users['LBL_PROCESSING']} {$app_list_strings['moduleList'][$p_module]}</h5>";
392                 
393                 $res = $GLOBALS['db']->query($query, true);
394                 
395                 //echo "<i>Workflow and Notifications <b>".($workflow ? "enabled" : "disabled")."</b> for this module record reassignment</i>\n<BR>\n";
396                 echo "<table border='0' cellspacing='0' cellpadding='0'  class='detail view'>\n";
397                 echo "<tr>\n";
398                 echo "<td>\n";
399                 if(! $workflow){
400                         $affected_rows = $GLOBALS['db']->getAffectedRowCount();
401                         echo "{$mod_strings_users['LBL_UPDATE_FINISH']}: $affected_rows {$mod_strings_users['LBL_AFFECTED']}<BR>\n";
402                 }
403                 else{
404                         $successarr = array();
405                         $failarr = array();
406                         
407                         require_once($beanFiles[$module]);
408                         while($row = $GLOBALS['db']->fetchByAssoc($res)){
409                                 $bean = new $module();
410                                 if(empty($row['id'])){
411                                         continue;
412                                 }
413                                 $bean->retrieve($row['id']);
414                                 
415                                 // So that we don't create new blank records.
416                                 if(!isset($bean->id)){
417                                         continue;
418                                 }                               
419                                 $bean->assigned_user_id = $touser;
420                                 
421                                 if($bean->save()){
422                                         $linkname = "record with id {$bean->id}";
423                                         if(!empty($bean->name)){
424                                                 $linkname = $bean->name;
425                                         }
426                                         else if(!empty($bean->last_name)){
427                                                 $linkname = $locale->getLocaleFormattedName($bean->first_name, $bean->last_name);
428                                         }
429                                         else if(!empty($bean->document_name)){
430                                                 $linkname = $bean->document_name;
431                                         }
432                                         $successstr = "{$mod_strings_users['LBL_REASS_SUCCESS_ASSIGN']} {$bean->object_name} \"<i><a href=\"index.php?module={$bean->module_dir}&action=DetailView&record={$bean->id}\">$linkname</a></i>\" {$mod_strings_users['LBL_REASS_FROM']} $fromusername {$mod_strings_users['LBL_REASS_TO']} $tousername";
433                                         $successarr[] = $successstr;
434                                 }
435                                 else{
436                                         $failarr[] = "{$mod_strings_users['LBL_REASS_FAILED_SAVE']} \"<i><a href=\"index.php?module={$bean->module_dir}&action=DetailView&record={$bean->id}\">$linkname</a></i>\".";
437                                 }
438                         }
439                         
440                         if(isset($_POST['verbose']) && $_POST['verbose'] == "on"){
441                                 echo "<h5>{$mod_strings_users['LBL_REASS_THE_FOLLOWING']} {$app_list_strings['moduleList'][$p_module]} {$mod_strings_users['LBL_REASS_HAVE_BEEN_UPDATED']}</h5>\n";
442                                 foreach($successarr as $ord){
443                                         echo "$ord\n<BR>\n";
444                                 }
445                                 if(empty($successarr))
446                                         echo "{$mod_strings_users['LBL_REASS_NONE']}\n<BR>\n";
447                                 
448                                 echo "<h5>{$mod_strings_users['LBL_REASS_THE_FOLLOWING']} {$app_list_strings['moduleList'][$p_module]} {$mod_strings_users['LBL_REASS_CANNOT_PROCESS']}</h5>\n";
449                                 foreach($failarr as $failure){
450                                         echo $failure."\n<BR>\n";
451                                 }
452                                 if(empty($failarr))
453                                         echo "{$mod_strings_users['LBL_REASS_NONE']}\n<BR>\n";
454                         }
455                         else{
456                                 echo "{$mod_strings_users['LBL_REASS_UPDATE_COMPLETE']}\n<BR>\n";
457                                 echo "&nbsp;&nbsp;".count($successarr)." {$mod_strings_users['LBL_REASS_SUCCESSFUL']}\n<BR>\n";
458                                 echo "&nbsp;&nbsp;".count($failarr)." {$mod_strings_users['LBL_REASS_FAILED']}\n";
459                         }
460                         echo "<BR>\n";
461                 }
462                 echo "</td></tr></table>\n";
463         }
464
465         echo "<BR><input type=button class=\"button\" value=\"{$mod_strings_users['LBL_REASS_BUTTON_RETURN']}\" onclick='document.location=\"index.php?module=Users&action=reassignUserRecords\"'>\n";
466
467 /////////////////// END STEP 3 - Execute reassignment ///////////////////////
468 }
469 ?>
470 <script type="text/javascript" src="include/javascript/sugar_grp_overlib.js"></script>
471 <script type="text/javascript">
472
473 function clearCurrentRecords()
474 {
475     var callback = {
476                 success: function(){
477                     document.getElementById('fromuser').selectedIndex = 0;
478                     document.getElementById('touser').selectedIndex = 0;
479                     document.getElementById('modulemultiselect').selectedIndex = -1;
480                     updateDivDisplay(document.getElementById('modulemultiselect'));
481                 }
482             };
483             
484     YAHOO.util.Connect.asyncRequest('POST', 'index.php?module=Users&action=clearreassignrecords&to_pdf=1', callback, null);
485 }
486
487 var allselected = [];
488 function updateDivDisplay(multiSelectObj){
489     for(var i = 0; i < multiSelectObj.options.length; i++){
490         if(multiSelectObj.options[i].selected != allselected[i]){
491             allselected[i] = multiSelectObj.options[i].selected;
492             
493             if(allselected[i]){
494                 theElement = document.getElementById('reassign_'+multiSelectObj.options[i].value);
495                 if(theElement != null){
496                     theElement.style.display = 'block';
497                 }
498             }
499             else{
500                 theElement = document.getElementById('reassign_'+multiSelectObj.options[i].value);
501                 if(theElement != null){
502                     theElement.style.display = 'none';
503                 }
504             }
505         }
506     } 
507 }
508 <?php
509 if(!isset($_POST['fromuser']) && !isset($_GET['execute'])){
510 ?>
511 updateDivDisplay(document.getElementById('modulemultiselect'));
512 <?php
513 }
514 ?>
515 </script>