sugarbean = $sugar; } /** * get the massupdate form * @param bool boolean need to execute the massupdate form or not * @param multi_select_popup booleanif it is a multi-select value */ public function getDisplayMassUpdateForm($bool, $multi_select_popup = false) { require_once('include/formbase.php'); if (!$multi_select_popup) { $form = '
' . "\n"; } else { $form = '' . "\n"; } if ($bool) { $form .= '' . "\n"; } else { $form .= '' . "\n"; } $form .= getAnyToForm('mu', true); if (!$multi_select_popup) { $form .= "
\n"; } return $form; } /** * returns the mass update's html form header * @param multi_select_popup boolean if it is a mult-select or not */ public function getMassUpdateFormHeader($multi_select_popup = false) { global $sugar_version; global $sugar_config; global $current_user; unset($_REQUEST['current_query_by_page']); unset($_REQUEST[session_name()]); unset($_REQUEST[session_name()]); $query = json_encode($_REQUEST); if (!isset($_REQUEST['module'])) { LoggerManager::getLogger()->warn('Undefined index: module'); } $bean = loadBean(isset($_REQUEST['module']) ? $_REQUEST['module'] : null); if (!isset($bean->module_dir)) { LoggerManager::getLogger()->warn('module_dir is not set for bean'); } if (!isset($bean->object_name)) { LoggerManager::getLogger()->warn('object_name is not set for bean'); } $order_by_name = (isset($bean->module_dir) ? $bean->module_dir : null).'2_'.strtoupper(isset($bean->object_name) ? $bean->object_name : null).'_ORDER_BY' ; $lvso = isset($_REQUEST['lvso'])?$_REQUEST['lvso']:""; $request_order_by_name = isset($_REQUEST[$order_by_name])?$_REQUEST[$order_by_name]:""; $action = isset($_REQUEST['action'])?$_REQUEST['action']:""; $module = isset($_REQUEST['module'])?$_REQUEST['module']:""; if ($multi_select_popup) { $tempString = ''; } else { $tempString = "
\n" . "\n" . "\n" . "\n" . "\n" . "\n" . "\n" . "\n" . "\n" . "\n" . "\n"; } // cn: bug 9103 - MU navigation in emails is broken if (!isset($_REQUEST['module'])) { LoggerManager::getLogger()->warn('Undefined index: module'); } if (isset($_REQUEST['module']) && $_REQUEST['module'] == 'Emails') { $type = ""; // determine "type" - inbound, archive, etc. if (isset($_REQUEST['type'])) { $type = $_REQUEST['type']; } // determine owner $tempString .=<< eoq; } return $tempString; } /** * Executes the massupdate form * @param displayname Name to display in the popup window * @param varname name of the variable */ public function handleMassUpdate() { require_once('include/formbase.php'); global $current_user, $db, $disable_date_format, $timedate, $app_list_strings; foreach ($_POST as $post => $value) { if (is_array($value)) { if (empty($value)) { unset($_POST[$post]); } } elseif (strlen($value) == 0) { if (isset($this->sugarbean->field_defs[$post]) && $this->sugarbean->field_defs[$post]['type'] == 'radioenum' && isset($_POST[$post])) { $_POST[$post] = ''; } else { unset($_POST[$post]); } } if (is_string($value) && isset($this->sugarbean->field_defs[$post])) { if (($this->sugarbean->field_defs[$post]['type'] == 'bool' || ( !empty($this->sugarbean->field_defs[$post]['custom_type']) && $this->sugarbean->field_defs[$post]['custom_type'] == 'bool' )) ) { if (strcmp($value, '2') == 0) { $_POST[$post] = 0; } if (!empty($this->sugarbean->field_defs[$post]['dbType']) && strcmp( $this->sugarbean->field_defs[$post]['dbType'], 'varchar' ) == 0 ) { if (strcmp($value, '1') == 0) { $_POST[$post] = 'on'; } if (strcmp($value, '2') == 0) { $_POST[$post] = 'off'; } } } if (($this->sugarbean->field_defs[$post]['type'] == 'radioenum' && isset($_POST[$post]) && strlen($value) == 0) || ($this->sugarbean->field_defs[$post]['type'] == 'enum' && $value == '__SugarMassUpdateClearField__') // Set to '' if it's an explicit clear ) { $_POST[$post] = ''; } if ($this->sugarbean->field_defs[$post]['type'] == 'bool') { $this->checkClearField($post, $value); } if ($this->sugarbean->field_defs[$post]['type'] == 'date' && !empty($_POST[$post])) { $_POST[$post] = $timedate->to_db_date($_POST[$post], false); } if ($this->sugarbean->field_defs[$post]['type'] == 'datetime' && !empty($_POST[$post])) { $_POST[$post] = $timedate->to_db($this->date_to_dateTime($post, $value)); } if ($this->sugarbean->field_defs[$post]['type'] == 'datetimecombo' && !empty($_POST[$post])) { $_POST[$post] = $timedate->to_db($_POST[$post]); } } } //We need to disable_date_format so that date values for the beans remain in database format //notice we make this call after the above section since the calls to TimeDate class there could wind up //making it's way to the UserPreferences objects in which case we want to enable the global date formatting //to correctly retrieve the user's date format preferences $old_value = $disable_date_format; $disable_date_format = true; if (!empty($_REQUEST['uid'])) { $_POST['mass'] = explode(',', $_REQUEST['uid']); } // coming from listview elseif (isset($_REQUEST['entire']) && empty($_POST['mass'])) { if (empty($order_by)) { $order_by = ''; } // TODO: define filter array here to optimize the query // by not joining the unneeded tables $query = $this->sugarbean->create_new_list_query( $order_by, $this->where_clauses, array(), array(), 0, '', false, $this, true, true ); $result = $db->query($query, true); $new_arr = array(); while ($val = $db->fetchByAssoc($result, false)) { array_push($new_arr, $val['id']); } $_POST['mass'] = $new_arr; } if (isset($_POST['mass']) && is_array($_POST['mass']) && $_REQUEST['massupdate'] == 'true') { $count = 0; foreach ($_POST['mass'] as $id) { if (empty($id)) { continue; } if (isset($_POST['Delete'])) { $this->sugarbean->retrieve($id); if ($this->sugarbean->ACLAccess('Delete')) { $this->sugarbean->mark_deleted($id); } } else { if ($this->sugarbean->object_name == 'Contact' && isset($_POST['Sync'])) { // special for contacts module if ($_POST['Sync'] == 'true') { $this->sugarbean->retrieve($id); if ($this->sugarbean->ACLAccess('Save')) { if ($this->sugarbean->object_name == 'Contact') { $this->sugarbean->contacts_users_id = $current_user->id; $this->sugarbean->save(false); } } } elseif ($_POST['Sync'] == 'false') { $this->sugarbean->retrieve($id); if ($this->sugarbean->ACLAccess('Save')) { if ($this->sugarbean->object_name == 'Contact') { if (!isset($this->sugarbean->users)) { $this->sugarbean->load_relationship('user_sync'); } $this->sugarbean->contacts_users_id = null; $this->sugarbean->user_sync->delete($this->sugarbean->id, $current_user->id); } } } } //end if for special Contact handling if ($count++ != 0) { //Create a new instance to clear values and handle additional updates to bean's 2,3,4... $className = get_class($this->sugarbean); $this->sugarbean = new $className(); } $this->sugarbean->retrieve($id); if ($this->sugarbean->ACLAccess('Save')) { $_POST['record'] = $id; $_GET['record'] = $id; $_REQUEST['record'] = $id; $newbean = $this->sugarbean; $old_reports_to_id = null; if (!empty($_POST['reports_to_id']) && $newbean->reports_to_id != $_POST['reports_to_id']) { $old_reports_to_id = empty($newbean->reports_to_id) ? 'null' : $newbean->reports_to_id; } $check_notify = false; if (isset($this->sugarbean->assigned_user_id)) { $old_assigned_user_id = $this->sugarbean->assigned_user_id; if (!empty($_POST['assigned_user_id']) && ($old_assigned_user_id != $_POST['assigned_user_id']) && ($_POST['assigned_user_id'] != $current_user->id) ) { $check_notify = true; } } //Call include/formbase.php, but do not call retrieve again populateFromPost('', $newbean, true, true); $newbean->save_from_post = false; if (!isset($_POST['parent_id'])) { $newbean->parent_type = null; } // get primary address id $email_address_id = ''; $email_address_value = array(); if (isset($this->sugarbean->emailAddress)) { if (!empty($this->sugarbean->emailAddress->addresses)) { foreach ($this->sugarbean->emailAddress->addresses as $key => $emailAddressRow) { if ($emailAddressRow['primary_address'] == '1') { $email_address_id = $emailAddressRow['email_address_id']; $email_address_value = $emailAddressRow; break; } // if } // foreach } // if } // if $setOptOutPrimaryEmailAddress = false; if (!empty($_POST['optout_primary'])) { $setOptOutPrimaryEmailAddress = true; $optout_flag_value = 0; if ($_POST['optout_primary'] == 'true') { $optout_flag_value = 1; } // if } // if $setOptInPrimaryEmailAddress = false; if (!empty($_POST['optin_primary'])) { $setOptInPrimaryEmailAddress = true; $optin_flag_value = false; if ($_POST['optin_primary'] === 'true') { $optin_flag_value = true; } // if } // if // Fix for issue 1549: mass update the cases, and change the state value from open to close, // Status value can still display New, Assigned, Pending Input (even though it should not) foreach ($newbean->field_name_map as $field_name) { if (isset($field_name['type']) && $field_name['type'] == 'dynamicenum') { if (isset($field_name['parentenum']) && $field_name['parentenum'] != '') { $parentenum_name = $field_name['parentenum']; // Updated parent field value. $parentenum_value = $newbean->$parentenum_name; $dynamic_field_name = $field_name['name']; // Dynamic field set value. list($dynamic_field_value) = explode('_', $newbean->$dynamic_field_name); if ($parentenum_value != $dynamic_field_value) { // Change to the default value of the correct value set. $defaultValue = ''; foreach ($app_list_strings[$field_name['options']] as $key => $value) { if (strpos($key, $parentenum_value) === 0) { $defaultValue = $key; break; } } $newbean->$dynamic_field_name = $defaultValue; } } } } $newbean->save($check_notify); if (!empty($email_address_id)) { /** @var EmailAddress $primaryEmailAddress */ $primaryEmailAddress = BeanFactory::getBean('EmailAddresses', $email_address_id); if ($setOptOutPrimaryEmailAddress) { $primaryEmailAddress->opt_out = (bool)$optout_flag_value; } if ($setOptInPrimaryEmailAddress) { if ($optin_flag_value === true) { $primaryEmailAddress->OptIn(); } else { $primaryEmailAddress->resetOptIn(); } } $primaryEmailAddress->save(); } // if if (!empty($old_reports_to_id) && method_exists($newbean, 'update_team_memberships')) { $old_id = $old_reports_to_id == 'null' ? '' : $old_reports_to_id; } } } } } $disable_date_format = $old_value; } /** * Displays the massupdate form */ public function getMassUpdateForm( $hideDeleteIfNoFieldsAvailable = false ) { global $app_strings; global $current_user; $configurator = new Configurator(); $sugar_config = $configurator->config; if ($this->sugarbean->bean_implements('ACL') && (!ACLController::checkAccess( $this->sugarbean->module_dir, 'edit', true ) || !ACLController::checkAccess($this->sugarbean->module_dir, 'massupdate', true)) ) { return ''; } $lang_delete = translate('LBL_DELETE'); $lang_update = translate('LBL_UPDATE'); $lang_confirm = translate('NTC_DELETE_CONFIRMATION_MULTIPLE'); $lang_sync = translate('LBL_SYNC_CONTACT'); $lang_oc_status = translate('LBL_OC_STATUS'); $lang_unsync = translate('LBL_UNSYNC'); $lang_archive = translate('LBL_ARCHIVE'); $lang_optout_primaryemail = $app_strings['LBL_OPT_OUT_FLAG_PRIMARY']; $field_count = 0; $html = ""; $html .= << function toggleMassUpdateForm(){ document.getElementById('massupdate_form').style.display = 'none'; } EOJS; if ($field_count > 0) { return $html; } //If no fields are found, render either a form that still permits Mass Update deletes or just display a message that no fields are available $html = ""; } else { $html .= $app_strings['LBL_NO_MASS_UPDATE_FIELDS_AVAILABLE'] . ""; } return $html; } public 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 call_user_func($function, $focus, $vardef['name'], '', 'MassUpdate'); } return call_user_func($function, $focus, $vardef['name'], '', 'MassUpdate'); } /** * Returns end of the massupdate form */ public 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 */ public function handleRelationship($displayname, $field) { $ret_val = ''; if (isset($field['module'])) { if ($field['name'] == 'reports_to_name' && ($field['module'] == 'Users' || $field['module'] == 'Employee')) { return $this->addUserName($displayname, $field['name'], $field['id_name'], $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 'Users': $ret_val = $this->addGenericModuleID($displayname, $field['name'], $field['id_name'], "Users"); break; case 'Employee': $ret_val = $this->addGenericModuleID($displayname, $field['name'], $field['id_name'], "Employee"); break; case 'Releases': $ret_val = $this->addGenericModuleID($displayname, $field['name'], $field['id_name'], "Releases"); break; default: if (!empty($field['massupdate'])) { $ret_val = $this->addGenericModuleID( $displayname, $field['name'], $field['id_name'], $field['module'] ); } 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 */ public 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); $qsName = array( 'form' => 'MassUpdate', 'method' => 'query', 'modules' => array("Accounts"), 'group' => 'or', 'field_list' => array('name', 'id'), 'populate_list' => array("mass_parent_name", "mass_parent_id"), 'conditions' => array(array('name' => 'name', 'op' => 'like_custom', 'end' => '%', 'value' => '')), 'limit' => '30', 'no_match_text' => $app_strings['ERR_SQS_NO_MATCH'] ); $qsName = $json->encode($qsName); // /////////////////////////////////////// $change_parent_button = ""; $parent_type = $field['parent_type']; $parent_types = $app_list_strings[$parent_type]; $disabled_parent_types = ACLController::disabledModuleList($parent_types, false, 'list'); foreach ($disabled_parent_types as $disabled_parent_type) { unset($parent_types[$disabled_parent_type]); } $types = get_select_options_with_id($parent_types, ''); //BS Fix Bug 17110 $pattern = "/\n/"; $types = preg_replace($pattern, "", $types); // End Fix $json = getJSONobj(); $disabled_parent_types = $json->encode($disabled_parent_types); return <<{$displayname}
$change_parent_button
EOHTML; } /** * Add a generic input type='text' field * @param displayname Name to display in the popup window * @param field_name name of the field */ public function addInputType($displayname, $varname) { //letrium ltd $displayname = addslashes($displayname); $html = <<$displayname EOQ; return $html; } /** * Add a generic widget to lookup Users ** @param string $displayname Name to display in the popup window * @param string $varname name of the variable * @param string $id_name name of the id in vardef * @param string $mod_type name of the module, either "Contact" or "Releases" currently * @return string */ public function addUserName($displayname, $varname, $id_name, $mod_type = null) { global $app_strings; if (empty($id_name)) { $id_name = strtolower($mod_type) . "_id"; } /////////////////////////////////////// /// /// SETUP POPUP $reportsDisplayName = showFullName() ? 'name' : 'user_name'; $popup_request_data = array( 'call_back_function' => 'set_return', 'form_name' => 'MassUpdate', 'field_to_name_array' => array( 'id' => (string)($id_name), (string)$reportsDisplayName => (string)($varname), ), ); $json = getJSONobj(); $encoded_popup_request_data = $json->encode($popup_request_data); $qsName = array( 'form' => 'MassUpdate', 'method' => 'get_user_array', 'modules' => array((string)($mod_type)), 'group' => 'or', 'field_list' => array('user_name', 'id'), 'populate_list' => array("mass_{$varname}", "mass_{$id_name}"), 'conditions' => array(array('name' => 'name', 'op' => 'like_custom', 'end' => '%', 'value' => '')), 'limit' => '30', 'no_match_text' => $app_strings['ERR_SQS_NO_MATCH'] ); $qsName = $json->encode($qsName); // /////////////////////////////////////// return <<$displayname   EOHTML; } /** * Add a generic module popup selection popup window HTML code. * Currently supports Contact and Releases ** @param string $displayname Name to display in the popup window * @param string $varname Name of the variable * @param string $id_name Name of the id in vardef * @param string $mod_type Name of the module, either "Contact" or "Releases" currently * @return string */ public function addGenericModuleID($displayname, $varname, $id_name, $mod_type = null) { 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' => (string)($id_name), 'name' => (string)($varname), ), ); $json = getJSONobj(); $encoded_popup_request_data = $json->encode($popup_request_data); $qsName = array( 'form' => 'MassUpdate', 'method' => 'query', 'modules' => array((string)($mod_type)), 'group' => 'or', 'field_list' => array('name', 'id'), 'populate_list' => array("mass_{$varname}", "mass_{$id_name}"), 'conditions' => array(array('name' => 'name', 'op' => 'like_custom', 'end' => '%', 'value' => '')), 'limit' => '30', 'no_match_text' => $app_strings['ERR_SQS_NO_MATCH'] ); $qsName = $json->encode($qsName); // /////////////////////////////////////// return <<$displayname EOHTML; } /** * 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 */ public 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' => (string)($id_name), 'name' => (string)($varname), ), ); $encoded_popup_request_data = $json->encode($popup_request_data); // /////////////////////////////////////// $qsParent = array( 'form' => 'MassUpdate', '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 */ public 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( 'form' => 'MassUpdate', '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 */ public function addStatus($displayname, $varname, $options) { global $app_strings, $app_list_strings; // cn: added "mass_" to the id tag to differentiate 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_separate_key( $options, $options, '__SugarMassUpdateClearField__', true ); $html .= ''; } 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 */ public function addBool($displayname, $varname) { global $app_strings, $app_list_strings; return $this->addStatus($displayname, $varname, $app_list_strings['checkbox_dom']); } public 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_separate_key($options, $options, '', true); ; // cn: added "mass_" to the id tag to differentiate from the status id in StoreQuery $html = '' . $displayname . ' '; return $html; } /** * Add Date selection popup window HTML code * @param displayname Name to display in the popup window * @param varname name of the variable */ public function addDate($displayname, $varname) { global $timedate, $app_strings, $app_list_strings, $theme, $current_user; //letrium ltd $displayname = addslashes($displayname); $userformat = '(' . $timedate->get_user_date_format() . ')'; $cal_dateformat = $timedate->get_cal_date_format(); $cal_fdow = $current_user->get_first_day_of_week() ? $current_user->get_first_day_of_week() : '0'; $javascriptend = << Calendar.setup ({ inputField : "${varname}jscal_field", daFormat : "$cal_dateformat", ifFormat : "$cal_dateformat", showsTime : false, button : "${varname}jscal_trigger", singleClick : true, step : 1, startWeekday: $cal_fdow, weekNumbers:false }); EOQ; $html = <<$displayname  $userformat $javascriptend EOQ; return $html; } public function addRadioenumItem($name, $value, $output) { $_output = ''; $_output .= '