isAdminForModule('Users') ){ sugar_die("You cannot access this page."); } global $locale; $return_module = isset($_REQUEST['return_module']) ? $_REQUEST['return_module'] : ''; $return_action = isset($_REQUEST['return_action']) ? $_REQUEST['return_action'] : ''; $return_id = isset($_REQUEST['return_id']) ? $_REQUEST['return_id'] : ''; if(!empty($return_module)) $cancel_location = "index.php?module=".$return_module."&action=".$return_action."&record=".$return_id; else $cancel_location = "index.php?module=Users&action=index"; echo "

{$mod_strings_users['LBL_REASS_SCRIPT_TITLE']}

"; // Include Metadata for processing require_once("modules/Users/metadata/reassignScriptMetadata.php"); if(file_exists("custom/modules/Users/reassignScriptMetadata_override.php")){ include("custom/modules/Users/reassignScriptMetadata_override.php"); } if(!empty($_GET['record'])){ unset($_SESSION['reassignRecords']); $_SESSION['reassignRecords']['fromuser'] = $_GET['record']; } if(!isset($_POST['fromuser']) && !isset($_GET['execute'])){ ///////////////////// BEGIN STEP 1 - Select users/modules ///////////////////////// $exclude_modules = array( "ImportMap", "UsersLastImport", "Dashboard", "SavedSearch", "UserPreference", "SugarFavorites", 'OAuthKey', 'OAuthToken', ); if(isset($_GET['clear']) && $_GET['clear'] == 'true'){ unset($_SESSION['reassignRecords']); } ?>

"?>
 








$fieldArray){ $display = (!empty($fieldArray['display_default']) && $fieldArray['display_default'] == true ? "block" : "none"); //Leon bug 20739 $t_mod_strings=return_module_language($GLOBALS['current_language'], $modFilter); echo "
\n"; echo "
{$app_list_strings['moduleList'][$modFilter]} ", " {$mod_strings_users['LBL_REASS_FILTERS']}
\n"; foreach($fieldArray['fields'] as $meta){ $multi = ""; $name = (!empty($meta['name']) ? $meta['name'] : ""); $size = (!empty($meta['size']) ? "size=\"{$meta['size']}\"" : ""); //Leon bug 20739 echo $t_mod_strings[$meta['vname']] ."\n
\n"; switch($meta['type']){ case "text": $tag = "input"; break; case "multiselect": $multi = "multiple=\"true\""; $name .= "[]"; // NO BREAK - Continue into select case "select": $tag = "select"; $sel = ''; if(!empty($_SESSION['reassignRecords']['filters'][$meta['name']])){ $sel = $_SESSION['reassignRecords']['filters'][$meta['name']]; } $extra = get_select_options_with_id($meta['dropdown'], $sel); $extra .= "\n"; break; default: //echo "Skipping field {$meta['name']} since the type is not supported
"; continue; } echo "<$tag $size name=\"$name\" $multi>\n$extra"; echo "
\n"; } echo "
\n"; } ?>
 
query($query); while($row = $GLOBALS['db']->fetchByAssoc($res)){ if($row['id'] == $_POST['fromuser']) $fromusername = $row['user_name']; if($row['id'] == $_POST['touser']) $tousername = $row['user_name']; } echo "{$mod_strings_users['LBL_REASS_DESC_PART2']}\n"; echo "
\n"; echo "
{$mod_strings_users['LBL_REASS_NOTES_TITLE']}\n"; echo "\n"; $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\');"'); echo "
{$mod_strings_users['LBL_REASS_VERBOSE_OUTPUT']}".$help_img."
\n"; unset($_SESSION['reassignRecords']['modules']); $beanListFlip = array_flip($_SESSION['reassignRecords']['assignedModuleListCache']); foreach($_POST['modules'] as $module){ if(!array_key_exists($module, $beanListFlip)){ //echo "$module not found as key in \$beanListFlip. Skipping $module.
"; continue; } $p_module = $beanListFlip[$module]; require_once($beanFiles[$module]); $object = new $module(); if(empty($object->table_name)){ // echo "
Could not find the database table for $p_module.
"; continue; } echo "
{$mod_strings_users['LBL_REASS_ASSESSING']} {$app_list_strings['moduleList'][$p_module]}
"; echo "\n"; echo "\n"; echo "
\n"; $q_select = "select id"; $q_update = "update "; $q_set = " set assigned_user_id = '{$_POST['touser']}', ". "date_modified = '".TimeDate::getInstance()->nowDb()."', ". "modified_user_id = '{$current_user->id}' "; $q_tables = " {$object->table_name} "; $q_where = "where {$object->table_name}.deleted=0 and {$object->table_name}.assigned_user_id = '{$_POST['fromuser']}' "; // Process conditions based on metadata if(isset($moduleFilters[$p_module]['fields']) && is_array($moduleFilters[$p_module]['fields'])){ $custom_added = false; foreach($moduleFilters[$p_module]['fields'] as $meta){ if(!empty($_POST[$meta['name']])) $_SESSION['reassignRecords']['filters'][$meta['name']] = $_POST[$meta['name']]; $is_custom = isset($meta['custom_table']) && $meta['custom_table'] == true; if($is_custom && !$custom_added){ $q_tables .= "inner join {$object->table_name}_cstm on {$object->table_name}.id = {$object->table_name}_cstm.id_c "; $custom_added = true; } $addcstm = ($is_custom ? "_cstm" : ""); switch($meta['type']){ case "text": case "select": $q_where .= " and {$object->table_name}{$addcstm}.{$meta['dbname']} = '{$_POST[$meta['name']]}' "; break; case "multiselect": if(empty($_POST[$meta['name']])){ continue; } $in_string = ""; $empty_check = ""; foreach($_POST[$meta['name']] as $onevalue){ if(empty($onevalue)) $empty_check .= " OR {$object->table_name}{$addcstm}.{$meta['dbname']} is null "; $in_string .= "'$onevalue', "; } $in_string = substr($in_string, 0, count($in_string) - 3); $q_where .= " and ({$object->table_name}{$addcstm}.{$meta['dbname']} in ($in_string) $empty_check)"; break; default: //echo "Skipping field {$meta['name']} since the type is not supported
"; continue; break; } } } $query = "$q_select from $q_tables $q_where"; $countquery = "select count(*) AS count from $q_tables $q_where"; $updatequery = "$q_update $q_tables $q_set $q_where"; $_SESSION['reassignRecords']['fromuser'] = $_POST['fromuser']; $_SESSION['reassignRecords']['touser'] = $_POST['touser']; $_SESSION['reassignRecords']['fromusername'] = $fromusername; $_SESSION['reassignRecords']['tousername'] = $tousername; $_SESSION['reassignRecords']['modules'][$module]['query'] = $query; $_SESSION['reassignRecords']['modules'][$module]['update'] = $updatequery; $res = $GLOBALS['db']->query($countquery); $row = $GLOBALS['db']->fetchByAssoc($res); 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
\n"; echo " {$mod_strings_users['LBL_REASS_WORK_NOTIF_AUDIT']}
\n"; echo "
\n"; } echo "
\n"; echo " \n"; echo " \n"; echo "
\n"; // debug //print_r($_SESSION['reassignRecords']); ///////////////////// END STEP 2 - Confirm Selections ///////////////////////// } /////////////////// BEGIN STEP 3 - Execute reassignment /////////////////////// else if(isset($_GET['execute']) && $_GET['execute'] == true){ $fromuser = $_SESSION['reassignRecords']['fromuser']; $touser = $_SESSION['reassignRecords']['touser']; $fromusername = $_SESSION['reassignRecords']['fromusername']; $tousername = $_SESSION['reassignRecords']['tousername']; $beanListFlip = array_flip($_SESSION['reassignRecords']['assignedModuleListCache']); foreach($_SESSION['reassignRecords']['modules'] as $module => $queries){ $p_module = $beanListFlip[$module]; $workflow = false; if(isset($_POST[$module."_workflow"]) && $_POST[$module."_workflow"] = "on") $workflow = true; $query = $workflow ? $queries['query'] : $queries['update']; echo "
{$mod_strings_users['LBL_PROCESSING']} {$app_list_strings['moduleList'][$p_module]}
"; $res = $GLOBALS['db']->query($query, true); //echo "Workflow and Notifications ".($workflow ? "enabled" : "disabled")." for this module record reassignment\n
\n"; echo "\n"; echo "\n"; echo "
\n"; if(! $workflow){ $affected_rows = $GLOBALS['db']->getAffectedRowCount(); echo "{$mod_strings_users['LBL_UPDATE_FINISH']}: $affected_rows {$mod_strings_users['LBL_AFFECTED']}
\n"; } else{ $successarr = array(); $failarr = array(); require_once($beanFiles[$module]); while($row = $GLOBALS['db']->fetchByAssoc($res)){ $bean = new $module(); if(empty($row['id'])){ continue; } $bean->retrieve($row['id']); // So that we don't create new blank records. if(!isset($bean->id)){ continue; } $bean->assigned_user_id = $touser; if($bean->save()){ $linkname = "record with id {$bean->id}"; if(!empty($bean->name)){ $linkname = $bean->name; } else if(!empty($bean->last_name)){ $linkname = $locale->getLocaleFormattedName($bean->first_name, $bean->last_name); } else if(!empty($bean->document_name)){ $linkname = $bean->document_name; } $successstr = "{$mod_strings_users['LBL_REASS_SUCCESS_ASSIGN']} {$bean->object_name} \"module_dir}&action=DetailView&record={$bean->id}\">$linkname\" {$mod_strings_users['LBL_REASS_FROM']} $fromusername {$mod_strings_users['LBL_REASS_TO']} $tousername"; $successarr[] = $successstr; } else{ $failarr[] = "{$mod_strings_users['LBL_REASS_FAILED_SAVE']} \"module_dir}&action=DetailView&record={$bean->id}\">$linkname\"."; } } if(isset($_POST['verbose']) && $_POST['verbose'] == "on"){ echo "
{$mod_strings_users['LBL_REASS_THE_FOLLOWING']} {$app_list_strings['moduleList'][$p_module]} {$mod_strings_users['LBL_REASS_HAVE_BEEN_UPDATED']}
\n"; foreach($successarr as $ord){ echo "$ord\n
\n"; } if(empty($successarr)) echo "{$mod_strings_users['LBL_REASS_NONE']}\n
\n"; echo "
{$mod_strings_users['LBL_REASS_THE_FOLLOWING']} {$app_list_strings['moduleList'][$p_module]} {$mod_strings_users['LBL_REASS_CANNOT_PROCESS']}
\n"; foreach($failarr as $failure){ echo $failure."\n
\n"; } if(empty($failarr)) echo "{$mod_strings_users['LBL_REASS_NONE']}\n
\n"; } else{ echo "{$mod_strings_users['LBL_REASS_UPDATE_COMPLETE']}\n
\n"; echo "  ".count($successarr)." {$mod_strings_users['LBL_REASS_SUCCESSFUL']}\n
\n"; echo "  ".count($failarr)." {$mod_strings_users['LBL_REASS_FAILED']}\n"; } echo "
\n"; } echo "
\n"; } echo "
\n"; /////////////////// END STEP 3 - Execute reassignment /////////////////////// } ?>