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 */ 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 */ 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['PHPSESSID']); $query = base64_encode(serialize($_REQUEST)); $bean = loadBean($_REQUEST['module']); $order_by_name = $bean->module_dir.'2_'.strtoupper($bean->object_name).'_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($_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 */ function handleMassUpdate(){ require_once('include/formbase.php'); global $current_user, $db, $disable_date_format, $timedate; 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; } $email_address_id = ''; if (!empty($_POST['optout_primary'])) { $optout_flag_value = 0; if ($_POST['optout_primary'] == 'true') { $optout_flag_value = 1; } // if 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']; break; } // if } // foreach } // if } // if } // if $newbean->save($check_notify); if (!empty($email_address_id)) { $query = "UPDATE email_addresses SET opt_out = {$optout_flag_value} where id = '{$emailAddressRow['email_address_id']}'"; $GLOBALS['db']->query($query); } // 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 */ function getMassUpdateForm( $hideDeleteIfNoFieldsAvailable = false ) { global $app_strings; global $current_user; 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; }else{ //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; } } 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'); }else{ return call_user_func($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'])) { 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 */ 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 */ function addInputType($displayname, $varname){ //letrium ltd $displayname = addslashes($displayname); $html = <<$displayname EOQ; return $html; } /** * Add a generic widget to lookup Users. * @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 addUserName($displayname, $varname, $id_name='', $mod_type){ 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' => "{$id_name}", "$reportsDisplayName" => "{$varname}", ), ); $json = getJSONobj(); $encoded_popup_request_data = $json->encode($popup_request_data); $qsName = array( 'form' => 'MassUpdate', 'method' => 'get_user_array', 'modules' => array("{$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 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); $qsName = array( 'form' => 'MassUpdate', 'method' => 'query', 'modules' => array("{$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); $img = SugarThemeRegistry::current()->getImageURL("id-ff-select.png"); // /////////////////////////////////////// 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 */ 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( '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); $img = SugarThemeRegistry::current()->getImageURL("id-ff-select.png"); $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( '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'); $img = SugarThemeRegistry::current()->getImageURL("id-ff-select.png"); $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 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 */ 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_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 */ function addDate($displayname, $varname){ global $timedate; //letrium ltd $displayname = addslashes($displayname); $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, weekNumbers:false }); EOQ; $jscalendarImage = SugarThemeRegistry::current()->getImageURL('jscalendar.gif'); $html = <<$displayname {$app_strings[ $userformat $javascriptend EOQ; return $html; } function addRadioenumItem($name, $value, $output) { $_output = ''; $_output .= '