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