";
$even = true;
if($this->sugarbean->object_name == 'Contact'){
$html .= "$lang_sync {$GLOBALS['app_strings']['LBL_NONE']} {$GLOBALS['app_list_strings']['checkbox_dom']['2']} {$GLOBALS['app_list_strings']['checkbox_dom']['1']} ";
$even = false;
}
if($this->sugarbean->object_name == 'User' && (!isset($this->sugarbean->module_dir) || $this->sugarbean->module_dir == 'Employees')){
$this->sugarbean->field_defs['status']['massupdate'] = false;
$this->sugarbean->field_defs['employee_status']['type'] = 'enum';
$this->sugarbean->field_defs['employee_status']['massupdate'] = true;
$this->sugarbean->field_defs['employee_status']['options'] = 'employee_status_dom';
}
if($this->sugarbean->object_name == 'InboundEmail'){
$this->sugarbean->field_defs['status']['type'] = 'enum';
$this->sugarbean->field_defs['status']['options'] = 'user_status_dom';
}
static $banned = array('date_modified'=>1, 'date_entered'=>1, 'created_by'=>1, 'modified_user_id'=>1, 'deleted'=>1,);
foreach($this->sugarbean->field_defs as $field){
if(!isset($banned[$field['name']]) && (!isset($field['massupdate']) || !empty($field['massupdate']))){
$newhtml = '';
if($even){
$newhtml .= "";
}
if(isset($field['vname'])){
$displayname = translate($field['vname']);
}else{
$displayname = '';
}
if(isset($field['type']) && $field['type'] == 'relate' && isset($field['id_name']) && $field['id_name'] == 'assigned_user_id')
$field['type'] = 'assigned_user_name';
if(isset($field['custom_type']))$field['type'] = $field['custom_type'];
if(isset($field['type']))
{
switch($field["type"]){
case "relate":
// bug 14691: avoid laying out an empty cell in the
$handleRelationship = $this->handleRelationship($displayname, $field);
if ($handleRelationship != '') {
$even = !$even;
$newhtml .= $handleRelationship;
}
break;
case "parent":$even = !$even; $newhtml .=$this->addParent($displayname, $field); break;
case "contact_id":$even = !$even; $newhtml .=$this->addContactID($displayname, $field["name"]); break;
case "assigned_user_name":$even = !$even; $newhtml .= $this->addAssignedUserID($displayname, $field["name"]); break;
case "account_id":$even = !$even; $newhtml .= $this->addAccountID($displayname, $field["name"]); break;
case "account_name":$even = !$even; $newhtml .= $this->addAccountID($displayname, $field["id_name"]); break;
case "bool": $even = !$even; $newhtml .= $this->addBool($displayname, $field["name"]); break;
case "enum":
case "multienum":
if(!empty($field['isMultiSelect'])){
$even = !$even; $newhtml .= $this->addStatusMulti($displayname, $field["name"], translate($field["options"])); break;
}else if(!empty($field['options'])) {
$even = !$even; $newhtml .= $this->addStatus($displayname, $field["name"], translate($field["options"])); break;
}else if(!empty($field['function'])){
$functionValue = $this->getFunctionValue($this->sugarbean, $field);
$even = !$even; $newhtml .= $this->addStatus($displayname, $field["name"], $functionValue); break;
}
break;
case "datetime":
case "date":$even = !$even; $newhtml .= $this->addDate($displayname, $field["name"]); break;
}
}
if($even){
$newhtml .="";
}else{
$should_use = true;
}
if(!in_array($newhtml, array('', ' ', ' ', ' '))){
$html.=$newhtml;
}
}
}
if ($this->sugarbean->object_name == 'Contact' ||
$this->sugarbean->object_name == 'Account' ||
$this->sugarbean->object_name == 'Lead' ||
$this->sugarbean->object_name == 'Prospect') {
$html .= "$lang_optout_primaryemail {$GLOBALS['app_strings']['LBL_NONE']} {$GLOBALS['app_list_strings']['checkbox_dom']['2']} {$GLOBALS['app_list_strings']['checkbox_dom']['1']} ";
}
$html .="
";
if($should_use){
return $html;
}else{
if($this->sugarbean->ACLAccess('Delete', true)){
return "";
}else{
return '';
}
}
}
function getFunctionValue($focus, $vardef){
$function = $vardef['function'];
if(is_array($function) && isset($function['name'])){
$function = $vardef['function']['name'];
}else{
$function = $vardef['function'];
}
if(!empty($vardef['function']['returns']) && $vardef['function']['returns'] == 'html'){
if(!empty($vardef['function']['include'])){
require_once($vardef['function']['include']);
}
return $function($focus, $vardef['name'], '', 'MassUpdate');
}else{
return $function($focus, $vardef['name'], '', 'MassUpdate');
}
}
/**
* Returns end of the massupdate form
*/
function endMassUpdateForm(){
return '';
}
/**
* Decides which popup HTML code is needed for mass updating
* @param displayname Name to display in the popup window
* @param field name of the field to update
*/
function handleRelationship($displayname, $field)
{
$ret_val = '';
if(isset($field['module']))
{
switch($field['module'])
{
case 'Accounts':
$ret_val = $this->addAccountID($displayname, $field['name'], $field['id_name']);
break;
case 'Contacts':
$ret_val = $this->addGenericModuleID($displayname, $field['name'], $field['id_name'], "Contacts");
break;
case 'Releases':
$ret_val = $this->addGenericModuleID($displayname, $field['name'], $field['id_name'], "Releases");
break;
default:
break;
}
}
return $ret_val;
}
/**
* Add a parent selection popup window
* @param displayname Name to display in the popup window
* @param field_name name of the field
*/
function addParent($displayname, $field){
global $app_strings, $app_list_strings;
///////////////////////////////////////
///
/// SETUP POPUP
$popup_request_data = array(
'call_back_function' => 'set_return',
'form_name' => 'MassUpdate',
'field_to_name_array' => array(
'id' => "parent_id",
'name' => "parent_name",
),
);
$json = getJSONobj();
$encoded_popup_request_data = $json->encode($popup_request_data);
//
///////////////////////////////////////
$change_parent_button = " ";
$parent_type = $field['parent_type'];
$types = get_select_options_with_id($app_list_strings[$parent_type], '');
//BS Fix Bug 17110
$pattern = "/\n/";
$types = preg_replace($pattern, "", $types);
// End Fix
return '' . $displayname . "
";
}
/**
* Add a generic module popup selection popup window HTML code.
* Currently supports Contact and Releases
* @param displayname Name to display in the popup window
* @param varname name of the variable
* @param id_name name of the id in vardef
* @param mod_type name of the module, either "Contact" or "Releases" currently
*/
function addGenericModuleID($displayname, $varname, $id_name='', $mod_type){
global $app_strings;
if(empty($id_name))
$id_name = strtolower($mod_type)."_id";
///////////////////////////////////////
///
/// SETUP POPUP
$popup_request_data = array(
'call_back_function' => 'set_return',
'form_name' => 'MassUpdate',
'field_to_name_array' => array(
'id' => "{$id_name}",
'name' => "{$varname}",
),
);
$json = getJSONobj();
$encoded_popup_request_data = $json->encode($popup_request_data);
//
///////////////////////////////////////
return "$displayname ";
}
/**
* Add Account selection popup window HTML code
* @param displayname Name to display in the popup window
* @param varname name of the variable
* @param id_name name of the id in vardef
*/
function addAccountID($displayname, $varname, $id_name=''){
global $app_strings;
$json = getJSONobj();
if(empty($id_name))
$id_name = "account_id";
///////////////////////////////////////
///
/// SETUP POPUP
$popup_request_data = array(
'call_back_function' => 'set_return',
'form_name' => 'MassUpdate',
'field_to_name_array' => array(
'id' => "{$id_name}",
'name' => "{$varname}",
),
);
$encoded_popup_request_data = $json->encode($popup_request_data);
//
///////////////////////////////////////
$qsParent = array( 'method' => 'query',
'modules' => array('Accounts'),
'group' => 'or',
'field_list' => array('name', 'id'),
'populate_list' => array('parent_name', 'parent_id'),
'conditions' => array(array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')),
'order' => 'name',
'limit' => '30',
'no_match_text' => $app_strings['ERR_SQS_NO_MATCH']
);
$qsParent['populate_list'] = array('mass_'. $varname, 'mass_' . $id_name);
$html = '' . $displayname . " \n"
. ' \n";
$html .= '';
return $html;
}
/**
* Add AssignedUser popup window HTML code
* @param displayname Name to display in the popup window
* @param varname name of the variable
*/
function addAssignedUserID($displayname, $varname){
global $app_strings;
$json = getJSONobj();
$popup_request_data = array(
'call_back_function' => 'set_return',
'form_name' => 'MassUpdate',
'field_to_name_array' => array(
'id' => 'assigned_user_id',
'user_name' => 'assigned_user_name',
),
);
$encoded_popup_request_data = $json->encode($popup_request_data);
$qsUser = array( 'method' => 'get_user_array', // special method
'field_list' => array('user_name', 'id'),
'populate_list' => array('assigned_user_name', 'assigned_user_id'),
'conditions' => array(array('name'=>'user_name','op'=>'like_custom','end'=>'%','value'=>'')),
'limit' => '30','no_match_text' => $app_strings['ERR_SQS_NO_MATCH']);
$qsUser['populate_list'] = array('mass_assigned_user_name', 'mass_assigned_user_id');
$html = <<$displayname
EOQ;
$html .= '';
return $html;
}
/**
* Add Status selection popup window HTML code
* @param displayname Name to display in the popup window
* @param varname name of the variable
* @param options array of options for status
*/
function addStatus($displayname, $varname, $options){
global $app_strings, $app_list_strings;
// cn: added "mass_" to the id tag to diffentieate from the status id in StoreQuery
$html = ''.$displayname.' ';
if(is_array($options)){
if(!isset($options['']) && !isset($options['0'])){
$new_options = array();
$new_options[''] = '';
foreach($options as $key=>$value) {
$new_options[$key] = $value;
}
$options = $new_options;
}
$options = get_select_options_with_id($options, '');
$html .= ''.$options.' ';
}else{
$html .= $options;
}
$html .= ' ';
return $html;
}
/**
* Add Status selection popup window HTML code
* @param displayname Name to display in the popup window
* @param varname name of the variable
* @param options array of options for status
*/
function addBool($displayname, $varname){
global $app_strings, $app_list_strings;
return $this->addStatus($displayname, $varname, $app_list_strings['checkbox_dom']);
}
function addStatusMulti($displayname, $varname, $options){
global $app_strings, $app_list_strings;
if(!isset($options['']) && !isset($options['0'])){
$new_options = array();
$new_options[''] = '';
foreach($options as $key=>$value) {
$new_options[$key] = $value;
}
$options = $new_options;
}
$options = get_select_options_with_id($options, '');
// cn: added "mass_" to the id tag to diffentieate from the status id in StoreQuery
$html = ''.$displayname.'
'.$options.' ';
return $html;
}
/**
* Add Date selection popup window HTML code
* @param displayname Name to display in the popup window
* @param varname name of the variable
*/
function addDate($displayname, $varname){
global $timedate;
$userformat = '('. $timedate->get_user_date_format().')';
$cal_dateformat = $timedate->get_cal_date_format();
global $app_strings, $app_list_strings, $theme;
$javascriptend = <<
Calendar.setup ({
inputField : "${varname}jscal_field", daFormat : "$cal_dateformat", ifFormat : "$cal_dateformat", showsTime : false, button : "${varname}jscal_trigger", singleClick : true, step : 1
});
EOQ;
$html = <<$displayname
$userformat
$javascriptend
EOQ;
return $html;
}
function date_to_dateTime($field, $value) {
global $timedate;
//Check if none was set
if (isset($this->sugarbean->field_defs[$field]['group'])) {
$group = $this->sugarbean->field_defs[$field]['group'];
if (isset($this->sugarbean->field_defs[$group."_flag"]) && isset($_POST[$group."_flag"])
&& $_POST[$group."_flag"] == 1) {
return "";
}
}
$oldDateTime = $this->sugarbean->$field;
$oldTime = split(" ", $oldDateTime);
if (isset($oldTime[1])) {
$oldTime = $oldTime[1];
} else {
$oldTime = $timedate->to_display_time($timedate->get_gmt_db_datetime());
}
$value = split(" ", $value);
$value = $value[0];
return $value." ".$oldTime;
}
function checkClearField($field, $value) {
if ($value == 1 && strpos($field, '_flag')) {
$fName = substr($field, -5);
if (isset($this->sugarbean->field_defs[$field]['group'])) {
$group = $this->sugarbean->field_defs[$field]['group'];
if (isset($this->sugarbean->field_defs[$group])) {
$_POST[$group] = "";
}
}
}
}
function generateSearchWhere($module, $query) {//this function is similar with function prepareSearchForm() in view.list.php
$seed = loadBean($module);
$this->use_old_search = true;
if(file_exists('modules/'.$module.'/SearchForm.html')){
if(file_exists('modules/' . $module . '/metadata/SearchFields.php')) {
require_once('include/SearchForm/SearchForm.php');
$searchForm = new SearchForm($module, $seed);
}
elseif(!empty($_SESSION['export_where'])) { //bug 26026, sometimes some module doesn't have a metadata/SearchFields.php, the searchfrom is generated in the ListView.php.
//So currently massupdate will not gernerate the where sql. It will use the sql stored in the SESSION. But this will cause bug 24722, and it cannot be avoided now.
$where = $_SESSION['export_where'];
$whereArr = explode (" ", trim($where));
if ($whereArr[0] == trim('where')) {
$whereClean = array_shift($whereArr);
}
$this->where_clauses = implode(" ", $whereArr);
return;
}
else {
$this->where_clauses = '';
return;
}
}
else{
$this->use_old_search = false;
require_once('include/SearchForm/SearchForm2.php');
if (file_exists('custom/modules/'.$module.'/metadata/searchdefs.php'))
{
require_once('custom/modules/'.$module.'/metadata/searchdefs.php');
}
elseif (!empty($metafiles[$module]['searchdefs']))
{
require_once($metafiles[$module]['searchdefs']);
}
elseif (file_exists('modules/'.$module.'/metadata/searchdefs.php'))
{
require_once('modules/'.$module.'/metadata/searchdefs.php');
}
if(!empty($metafiles[$module]['searchfields']))
require_once($metafiles[$module]['searchfields']);
elseif(file_exists('modules/'.$module.'/metadata/SearchFields.php'))
require_once('modules/'.$module.'/metadata/SearchFields.php');
if(empty($searchdefs) || empty($searchFields)) {
$this->where_clauses = ''; //for some modules, such as iframe, it has massupdate, but it doesn't have search function, the where sql should be empty.
return;
}
$searchForm = new SearchForm($seed, $module);
$searchForm->setup($searchdefs, $searchFields, 'include/SearchForm/tpls/SearchFormGeneric.tpl');
}
$searchForm->populateFromArray(unserialize(base64_decode($query)));
$where_clauses = $searchForm->generateSearchWhere(true, $module);
if (count($where_clauses) > 0 )$this->where_clauses = '('. implode(' ) AND ( ', $where_clauses) . ')';
$GLOBALS['log']->info("MassUpdate Where Clause: {$this->where_clauses}");
}
}
?>