|
iTx Technologies offre gratuitement
|
||
[Vue sommaire] [Imprimer] [Vue textuelle]
1 <?php 2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 3 /** 4 * MassUpdate for ListViews 5 * 6 * SugarCRM is a customer relationship management program developed by 7 * SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc. 8 * 9 * This program is free software; you can redistribute it and/or modify it under 10 * the terms of the GNU General Public License version 3 as published by the 11 * Free Software Foundation with the addition of the following permission added 12 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK 13 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY 14 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 15 * 16 * This program is distributed in the hope that it will be useful, but WITHOUT 17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 19 * details. 20 * 21 * You should have received a copy of the GNU General Public License along with 22 * this program; if not, see http://www.gnu.org/licenses or write to the Free 23 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 24 * 02110-1301 USA. 25 * 26 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, 27 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com. 28 * 29 * The interactive user interfaces in modified source and object code versions 30 * of this program must display Appropriate Legal Notices, as required under 31 * Section 5 of the GNU General Public License version 3. 32 * 33 * In accordance with Section 7(b) of the GNU General Public License version 3, 34 * these Appropriate Legal Notices must retain the display of the "Powered by 35 * SugarCRM" logo. If the display of the logo is not reasonably feasible for 36 * technical reasons, the Appropriate Legal Notices must display the words 37 * "Powered by SugarCRM". 38 */ 39 40 41 42 /** 43 * MassUpdate class for updating multiple records at once 44 */ 45 require_once ('include/EditView/EditView2.php'); 46 class MassUpdate 47 { 48 /* 49 * internal sugarbean reference 50 */ 51 var $sugarbean = null; 52 53 /** 54 * set the sugar bean to its internal member 55 * @param sugar bean reference 56 */ 57 function setSugarBean($sugar) 58 { 59 $this->sugarbean = $sugar; 60 } 61 62 /** 63 * get the massupdate form 64 * @param bool boolean need to execute the massupdate form or not 65 * @param multi_select_popup booleanif it is a multi-select value 66 */ 67 function getDisplayMassUpdateForm($bool, $multi_select_popup = false) 68 { 69 70 require_once ('include/formbase.php'); 71 72 if(!$multi_select_popup) 73 $form = '<form action="index.php" method="post" name="displayMassUpdate" id="displayMassUpdate">' . "\n"; 74 else 75 $form = '<form action="index.php" method="post" name="MassUpdate" id="MassUpdate">' . "\n"; 76 77 if($bool) 78 { 79 $form .= '<input type="hidden" name="mu" value="false" />' . "\n"; 80 } 81 else 82 { 83 $form .= '<input type="hidden" name="mu" value="true" />' . "\n"; 84 } 85 86 $form .= getAnyToForm('mu', true); 87 if(!$multi_select_popup) $form .= "</form>\n"; 88 89 return $form; 90 } 91 /** 92 * returns the mass update's html form header 93 * @param multi_select_popup boolean if it is a mult-select or not 94 */ 95 function getMassUpdateFormHeader($multi_select_popup = false) 96 { 97 global $sugar_version; 98 global $sugar_config; 99 global $current_user; 100 101 $query = base64_encode(serialize($_REQUEST)); 102 103 $bean = loadBean($_REQUEST['module']); 104 $order_by_name = $bean->module_dir.'2_'.strtoupper($bean->object_name).'_ORDER_BY' ; 105 $lvso = isset($_REQUEST['lvso'])?$_REQUEST['lvso']:""; 106 $request_order_by_name = isset($_REQUEST[$order_by_name])?$_REQUEST[$order_by_name]:""; 107 if($multi_select_popup) 108 $tempString = ''; 109 else 110 $tempString = "<form action='index.php' method='post' name='MassUpdate' id='MassUpdate' onsubmit=\"return check_form('MassUpdate');\">\n" 111 . "<input type='hidden' name='return_action' value='{$_REQUEST['action']}' />\n" 112 . "<input type='hidden' name='return_module' value='{$_REQUEST['module']}' />\n" 113 . "<input type='hidden' name='massupdate' value='true' />\n" 114 . "<input type='hidden' name='delete' value='false' />\n" 115 . "<input type='hidden' name='merge' value='false' />\n" 116 . "<input type='hidden' name='current_query_by_page' value='{$query}' />\n" 117 . "<input type='hidden' name='module' value='{$_REQUEST['module']}' />\n" 118 . "<input type='hidden' name='action' value='MassUpdate' />\n" 119 . "<input type='hidden' name='lvso' value='{$lvso}' />\n" 120 . "<input type='hidden' name='{$order_by_name}' value='{$request_order_by_name}' />\n"; 121 122 // cn: bug 9103 - MU navigation in emails is broken 123 if($_REQUEST['module'] == 'Emails') { 124 $type = ""; 125 // determine "type" - inbound, archive, etc. 126 if (isset($_REQUEST['type'])) { 127 $type = $_REQUEST['type']; 128 } 129 // determine owner 130 $tempString .=<<<eoq 131 <input type='hidden' name='type' value="{$type}" /> 132 <input type='hidden' name='ie_assigned_user_id' value="{$current_user->id}" /> 133 eoq; 134 } 135 136 return $tempString; 137 } 138 139 /** 140 * Executes the massupdate form 141 * @param displayname Name to display in the popup window 142 * @param varname name of the variable 143 */ 144 function handleMassUpdate(){ 145 146 require_once ('include/formbase.php'); 147 global $current_user, $db; 148 149 /* 150 C.L. - Commented this out... not sure why it's here 151 if(!is_array($this->sugarbean) && $this->sugarbean->bean_implements('ACL') && !ACLController::checkAccess($this->sugarbean->module_dir, 'edit', true)) 152 { 153 154 } 155 */ 156 157 foreach($_POST as $post=>$value){ 158 if(is_array($value)){ 159 if(empty($value)){ 160 unset($_POST[$post]); 161 } 162 }elseif(strlen($value) == 0){ 163 unset($_POST[$post]); 164 } 165 if(is_string($value) 166 && isset($this->sugarbean->field_defs[$post]) && 167 ($this->sugarbean->field_defs[$post]['type'] == 'bool' 168 || (!empty($this->sugarbean->field_defs[$post]['custom_type']) && $this->sugarbean->field_defs[$post]['custom_type'] == 'bool' 169 ))){ 170 171 172 if(strcmp($value, '2') == 0)$_POST[$post] = 0; 173 if(!empty($this->sugarbean->field_defs[$post]['dbType']) && strcmp($this->sugarbean->field_defs[$post]['dbType'], 'varchar') == 0 ){ 174 if(strcmp($value, '1') == 0 )$_POST[$post] = 'on'; 175 if(strcmp($value, '2') == 0)$_POST[$post] = 'off'; 176 } 177 } 178 } 179 180 if(!empty($_REQUEST['uid'])) $_POST['mass'] = explode(',', $_REQUEST['uid']); // coming from listview 181 elseif(isset($_REQUEST['entire']) && empty($_POST['mass'])) { 182 if(empty($order_by))$order_by = ''; 183 $ret_array = create_export_query_relate_link_patch($_REQUEST['module'], $this->searchFields, $this->where_clauses); 184 $query = $this->sugarbean->create_export_query($order_by, $ret_array['where'], $ret_array['join']); 185 $result = $db->query($query,true); 186 $new_arr = array(); 187 while($val = $db->fetchByAssoc($result,-1,false)) 188 { 189 array_push($new_arr, $val['id']); 190 } 191 $_POST['mass'] = $new_arr; 192 } 193 194 if(isset($_POST['mass']) && is_array($_POST['mass']) && $_REQUEST['massupdate'] == 'true'){ 195 $count = 0; 196 197 198 199 200 201 202 203 foreach($_POST['mass'] as $id){ 204 if(empty($id)) { 205 continue; 206 } 207 if(isset($_POST['Delete'])){ 208 $this->sugarbean->retrieve($id); 209 if($this->sugarbean->ACLAccess('Delete')){ 210 //Martin Hu Bug #20872 211 if($this->sugarbean->object_name == 'EmailMan'){ 212 $query = "DELETE FROM emailman WHERE id = '" . $this->sugarbean->id . "'"; 213 $db->query($query); 214 } else { 215 216 217 218 219 220 221 222 223 224 225 $this->sugarbean->mark_deleted($id); 226 } 227 } 228 } 229 else { 230 if($this->sugarbean->object_name == 'Contact' && isset($_POST['Sync'])){ // special for contacts module 231 if($_POST['Sync'] == 'true') { 232 $this->sugarbean->retrieve($id); 233 if($this->sugarbean->ACLAccess('Save')){ 234 if($this->sugarbean->object_name == 'Contact'){ 235 236 $this->sugarbean->contacts_users_id = $current_user->id; 237 $this->sugarbean->save(false); 238 } 239 } 240 } 241 elseif($_POST['Sync'] == 'false') { 242 $this->sugarbean->retrieve($id); 243 if($this->sugarbean->ACLAccess('Save')){ 244 if($this->sugarbean->object_name == 'Contact'){ 245 if (!isset($this->sugarbean->users)) 246 { 247 $this->sugarbean->load_relationship('user_sync'); 248 } 249 $this->sugarbean->contacts_users_id = null; 250 $this->sugarbean->user_sync->delete($this->sugarbean->id, $current_user->id); 251 } 252 } 253 } 254 } //end if for special Contact handling 255 256 if($count++ != 0) { 257 //Create a new instance to clear values and handle additional updates to bean's 2,3,4... 258 $className = get_class($this->sugarbean); 259 $this->sugarbean = new $className(); 260 } 261 262 $this->sugarbean->retrieve($id); 263 264 foreach($_POST as $field=>$value){ 265 if (isset($this->sugarbean->field_defs[$field])) { 266 if($this->sugarbean->field_defs[$field]['type'] == 'datetime') { 267 $_POST[$field] = $this->date_to_dateTime($field, $value); 268 } 269 if ($this->sugarbean->field_defs[$field]['type'] == 'bool') { 270 $this->checkClearField($field, $value); 271 } 272 } 273 } 274 275 276 277 278 279 280 281 282 283 284 285 if($this->sugarbean->ACLAccess('Save')){ 286 $_POST['record'] = $id; 287 $_GET['record'] = $id; 288 $_REQUEST['record'] = $id; 289 $newbean=$this->sugarbean; 290 //Call include/formbase.php, but do not call retrieve again 291 populateFromPost('', $newbean, true); 292 $newbean->save_from_post = false; 293 if (!isset($_POST['parent_id'])) 294 $newbean->parent_type = null; 295 296 $check_notify = FALSE; 297 298 if (isset( $this->sugarbean->assigned_user_id)) { 299 $old_assigned_user_id = $this->sugarbean->assigned_user_id; 300 if (!empty($_POST['assigned_user_id']) 301 && ($old_assigned_user_id != $_POST['assigned_user_id']) 302 && ($_POST['assigned_user_id'] != $current_user->id)) { 303 $check_notify = TRUE; 304 } 305 } 306 $email_address_id = ''; 307 if (!empty($_POST['optout_primary'])) { 308 $optout_flag_value = 0; 309 if ($_POST['optout_primary'] == 'true') { 310 $optout_flag_value = 1; 311 } // if 312 if (isset($this->sugarbean->emailAddress)) { 313 if (!empty($this->sugarbean->emailAddress->addresses)) { 314 foreach($this->sugarbean->emailAddress->addresses as $key =>$emailAddressRow) { 315 if ($emailAddressRow['primary_address'] == '1') { 316 $email_address_id = $emailAddressRow['email_address_id']; 317 break; 318 } // if 319 } // foreach 320 } // if 321 322 } // if 323 } // if 324 $newbean->save($check_notify); 325 if (!empty($email_address_id)) { 326 $query = "UPDATE email_addresses SET opt_out = {$optout_flag_value} where id = '{$emailAddressRow['email_address_id']}'"; 327 $GLOBALS['db']->query($query); 328 329 } // if 330 } 331 } 332 } 333 334 335 336 337 338 339 340 } 341 342 } 343 /** 344 * Displays the massupdate form 345 */ 346 function getMassUpdateForm(){ 347 global $app_strings; 348 global $current_user; 349 350 if($this->sugarbean->bean_implements('ACL') && !ACLController::checkAccess($this->sugarbean->module_dir, 'edit', true)){ 351 return ''; 352 } 353 $lang_delete = translate('LBL_DELETE'); 354 $lang_update = translate('LBL_UPDATE'); 355 $lang_confirm= translate('NTC_DELETE_CONFIRMATION_MULTIPLE'); 356 $lang_sync = translate('LBL_SYNC_CONTACT'); 357 $lang_oc_status = translate('LBL_OC_STATUS'); 358 $lang_unsync = translate('LBL_UNSYNC'); 359 $lang_archive = translate('LBL_ARCHIVE'); 360 $lang_optout_primaryemail = $app_strings['LBL_OPT_OUT_FLAG_PRIMARY']; 361 362 363 364 // if(!isset($this->sugarbean->field_defs) || count($this->sugarbean->field_defs) == 0) { 365 // $html = "<table cellpadding='0' cellspacing='0' border='0' width='100%'><tr><td>"; 366 // 367 // if($this->sugarbean->ACLAccess('Delete', true) ){ 368 // $html .= "<input type='submit' name='Delete' value='{$lang_delete}' onclick=\"return confirm('{$lang_confirm}')\" class='button'>"; 369 // } 370 // $html .= "</td></tr></table>"; 371 // return $html; 372 // } 373 374 $should_use = false; 375 376 $html = "<div id='massupdate_form'>" . get_form_header($app_strings['LBL_MASS_UPDATE'], '', false); 377 $html .= "<table cellpadding='0' cellspacing='0' border='0' width='100%'><tr><td class='buttons'><input onclick='return sListView.send_mass_update(\"selected\", \"{$app_strings['LBL_LISTVIEW_NO_SELECTED']}\")' type='submit' id='update_button' name='Update' value='{$lang_update}' class='button'>"; 378 // TODO: allow ACL access for Delete to be set false always for users 379 // if($this->sugarbean->ACLAccess('Delete', true) && $this->sugarbean->object_name != 'User') { 380 // global $app_list_strings; 381 // $html .=" <input id='delete_button' type='submit' name='Delete' value='{$lang_delete}' onclick='return confirm(\"{$lang_confirm}\") && sListView.send_mass_update(\"selected\", \"{$app_strings['LBL_LISTVIEW_NO_SELECTED']}\", 1)' class='button'>"; 382 // } 383 384 // only for My Inbox views - to allow CSRs to have an "Archive" emails feature to get the email "out" of their inbox. 385 if($this->sugarbean->object_name == 'Email' 386 && (isset($_REQUEST['assigned_user_id']) && !empty($_REQUEST['assigned_user_id'])) 387 && (isset($_REQUEST['type']) && !empty($_REQUEST['type']) && $_REQUEST['type'] == 'inbound')) { 388 $html .=<<<eoq 389 <input type='button' name='archive' value="{$lang_archive}" class='button' onClick='setArchived();'> 390 <input type='hidden' name='ie_assigned_user_id' value="{$current_user->id}"> 391 <input type='hidden' name='ie_type' value="inbound"> 392 eoq; 393 } 394 395 $html .= "</td></tr></table><table cellpadding='0' cellspacing='0' border='0' width='100%' class='edit view' id='mass_update_table'><tr><td><table width='100%' border='0' cellspacing='0' cellpadding='0'>"; 396 397 $even = true; 398 if($this->sugarbean->object_name == 'Contact'){ 399 $html .= "<tr><td width='15%' scope='row'>$lang_sync</td><td width='35%' class='dataField'><select name='Sync'><option value=''>{$GLOBALS['app_strings']['LBL_NONE']}</option><option value='false'>{$GLOBALS['app_list_strings']['checkbox_dom']['2']}</option><option value='true'>{$GLOBALS['app_list_strings']['checkbox_dom']['1']}</option></select></td>"; 400 $even = false; 401 } 402 403 if($this->sugarbean->object_name == 'Employee'){ 404 $this->sugarbean->field_defs['employee_status']['type'] = 'enum'; 405 $this->sugarbean->field_defs['employee_status']['massupdate'] = true; 406 $this->sugarbean->field_defs['employee_status']['options'] = 'employee_status_dom'; 407 } 408 if($this->sugarbean->object_name == 'InboundEmail'){ 409 $this->sugarbean->field_defs['status']['type'] = 'enum'; 410 $this->sugarbean->field_defs['status']['options'] = 'user_status_dom'; 411 } 412 413 static $banned = array('date_modified'=>1, 'date_entered'=>1, 'created_by'=>1, 'modified_user_id'=>1, 'deleted'=>1,'modified_by_name'=>1,); 414 foreach($this->sugarbean->field_defs as $field){ 415 416 417 418 419 if(!isset($banned[$field['name']]) && (!isset($field['massupdate']) || !empty($field['massupdate']))){ 420 $newhtml = ''; 421 if($even){ 422 $newhtml .= "<tr>"; 423 } 424 if(isset($field['vname'])){ 425 $displayname = translate($field['vname']); 426 }else{ 427 $displayname = ''; 428 429 } 430 if(isset($field['type']) && $field['type'] == 'relate' && isset($field['id_name']) && $field['id_name'] == 'assigned_user_id') 431 $field['type'] = 'assigned_user_name'; 432 if(isset($field['custom_type']))$field['type'] = $field['custom_type']; 433 if(isset($field['type'])) 434 { 435 switch($field["type"]){ 436 case "relate": 437 // bug 14691: avoid laying out an empty cell in the <table> 438 $handleRelationship = $this->handleRelationship($displayname, $field); 439 if ($handleRelationship != '') { 440 $even = !$even; 441 $newhtml .= $handleRelationship; 442 } 443 break; 444 case "parent":$even = !$even; $newhtml .=$this->addParent($displayname, $field); break; 445 case "int": 446 if(!empty($field['massupdate']) && empty($field['auto_increment'])){ 447 $even = !$even; $newhtml .=$this->addInputType($displayname, $field); 448 } 449 break; 450 case "contact_id":$even = !$even; $newhtml .=$this->addContactID($displayname, $field["name"]); break; 451 case "assigned_user_name":$even = !$even; $newhtml .= $this->addAssignedUserID($displayname, $field["name"]); break; 452 case "account_id":$even = !$even; $newhtml .= $this->addAccountID($displayname, $field["name"]); break; 453 case "account_name":$even = !$even; $newhtml .= $this->addAccountID($displayname, $field["id_name"]); break; 454 case "bool": $even = !$even; $newhtml .= $this->addBool($displayname, $field["name"]); break; 455 case "enum": 456 case "multienum": 457 if(!empty($field['isMultiSelect'])){ 458 $even = !$even; $newhtml .= $this->addStatusMulti($displayname, $field["name"], translate($field["options"])); break; 459 }else if(!empty($field['options'])) { 460 $even = !$even; $newhtml .= $this->addStatus($displayname, $field["name"], translate($field["options"])); break; 461 }else if(!empty($field['function'])){ 462 $functionValue = $this->getFunctionValue($this->sugarbean, $field); 463 $even = !$even; $newhtml .= $this->addStatus($displayname, $field["name"], $functionValue); break; 464 } 465 break; 466 case "datetime": 467 case "date":$even = !$even; $newhtml .= $this->addDate($displayname, $field["name"]); break; 468 469 470 471 } 472 } 473 if($even){ 474 $newhtml .="</tr>"; 475 }else{ 476 $should_use = true; 477 } 478 if(!in_array($newhtml, array('<tr>', '</tr>', '<tr></tr>', '<tr><td></td></tr>'))){ 479 $html.=$newhtml; 480 } 481 } 482 } 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 if ($this->sugarbean->object_name == 'Contact' || 498 $this->sugarbean->object_name == 'Account' || 499 $this->sugarbean->object_name == 'Lead' || 500 $this->sugarbean->object_name == 'Prospect') { 501 502 $html .= "<tr><td width='15%' scope='row' class='dataLabel'>$lang_optout_primaryemail</td><td width='35%' class='dataField'><select name='optout_primary'><option value=''>{$GLOBALS['app_strings']['LBL_NONE']}</option><option value='false'>{$GLOBALS['app_list_strings']['checkbox_dom']['2']}</option><option value='true'>{$GLOBALS['app_list_strings']['checkbox_dom']['1']}</option></select></td></tr>"; 503 504 } 505 $html .="</table></td></tr></table></div>"; 506 507 508 if($should_use){ 509 return $html; 510 }else{ 511 if($this->sugarbean->ACLAccess('Delete', true)){ 512 return "<table cellpadding='0' cellspacing='0' border='0' width='100%'><tr><td><input type='submit' name='Delete' value='$lang_delete' onclick=\"return confirm('{$lang_confirm}')\" class='button'></td></tr></table>"; 513 }else{ 514 return ''; 515 } 516 } 517 } 518 519 function getFunctionValue($focus, $vardef){ 520 $function = $vardef['function']; 521 if(is_array($function) && isset($function['name'])){ 522 $function = $vardef['function']['name']; 523 }else{ 524 $function = $vardef['function']; 525 } 526 if(!empty($vardef['function']['returns']) && $vardef['function']['returns'] == 'html'){ 527 if(!empty($vardef['function']['include'])){ 528 require_once($vardef['function']['include']); 529 } 530 return $function($focus, $vardef['name'], '', 'MassUpdate'); 531 }else{ 532 return $function($focus, $vardef['name'], '', 'MassUpdate'); 533 } 534 } 535 536 /** 537 * Returns end of the massupdate form 538 */ 539 function endMassUpdateForm(){ 540 return '</form>'; 541 } 542 543 /** 544 * Decides which popup HTML code is needed for mass updating 545 * @param displayname Name to display in the popup window 546 * @param field name of the field to update 547 */ 548 function handleRelationship($displayname, $field) 549 { 550 $ret_val = ''; 551 if(isset($field['module'])) 552 { 553 switch($field['module']) 554 { 555 case 'Accounts': 556 $ret_val = $this->addAccountID($displayname, $field['name'], $field['id_name']); 557 break; 558 case 'Contacts': 559 $ret_val = $this->addGenericModuleID($displayname, $field['name'], $field['id_name'], "Contacts"); 560 break; 561 case 'Users': 562 $ret_val = $this->addGenericModuleID($displayname, $field['name'], $field['id_name'], "Users"); 563 break; 564 case 'Employee': 565 $ret_val = $this->addGenericModuleID($displayname, $field['name'], $field['id_name'], "Employee"); 566 break; 567 case 'Releases': 568 $ret_val = $this->addGenericModuleID($displayname, $field['name'], $field['id_name'], "Releases"); 569 break; 570 default: 571 if(!empty($field['massupdate'])){ 572 $ret_val = $this->addGenericModuleID($displayname, $field['name'], $field['id_name'], $field['module']); 573 } 574 break; 575 } 576 } 577 578 return $ret_val; 579 } 580 /** 581 * Add a parent selection popup window 582 * @param displayname Name to display in the popup window 583 * @param field_name name of the field 584 */ 585 function addParent($displayname, $field){ 586 global $app_strings, $app_list_strings; 587 588 /////////////////////////////////////// 589 /// 590 /// SETUP POPUP 591 592 $popup_request_data = array( 593 'call_back_function' => 'set_return', 594 'form_name' => 'MassUpdate', 595 'field_to_name_array' => array( 596 'id' => "parent_id", 597 'name' => "parent_name", 598 ), 599 ); 600 601 $json = getJSONobj(); 602 $encoded_popup_request_data = $json->encode($popup_request_data); 603 604 $qsName = array( 605 'form' => 'MassUpdate', 606 'method' => 'query', 607 'modules' => array("Accounts"), 608 'group' => 'or', 609 'field_list' => array('name', 'id'), 610 'populate_list' => array("mass_parent_name", "mass_parent_id"), 611 'conditions' => array(array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')), 612 'limit' => '30','no_match_text' => $app_strings['ERR_SQS_NO_MATCH']); 613 $qsName = $json->encode($qsName); 614 615 // 616 /////////////////////////////////////// 617 618 $change_parent_button = " <input title='".$app_strings['LBL_SELECT_BUTTON_TITLE']."' accessKey='".$app_strings['LBL_SELECT_BUTTON_KEY']."' type='button' class='button' value='".$app_strings['LBL_SELECT_BUTTON_LABEL'] 619 ."' name='button_parent_name' onclick='open_popup(document.MassUpdate.{$field['type_name']}.value, 600, 400, \"\", true, false, {$encoded_popup_request_data});' />"; 620 $parent_type = $field['parent_type']; 621 $parent_types = $app_list_strings[$parent_type]; 622 $disabled_parent_types = ACLController::disabledModuleList($parent_types,false, 'list'); 623 foreach($disabled_parent_types as $disabled_parent_type) 624 if($disabled_parent_type != $focus->parent_type) 625 unset($parent_types[$disabled_parent_type]); 626 $types = get_select_options_with_id($parent_types, ''); 627 //BS Fix Bug 17110 628 $pattern = "/\n<OPTION.*".$app_strings['LBL_NONE']."<\/OPTION>/"; 629 $types = preg_replace($pattern, "", $types); 630 // End Fix 631 632 $json = getJSONobj(); 633 $disabled_parent_types = $json->encode($disabled_parent_types); 634 635 return <<<EOHTML 636 <td width="15%" scope="row">{$displayname} </td> 637 <td> 638 <table width='100%' border='0' cellspacing='0' cellpadding='0'> 639 <tr> 640 <td valign='top'> 641 <select name='{$field['type_name']}' id='mass_{$field['type_name']}'> 642 $types 643 </select> 644 </td> 645 <td valign='top'> 646 <input name='{$field['id_name']}' id='mass_{$field['id_name']}' type='hidden' value=''> 647 <input name='parent_name' id='mass_parent_name' class='sqsEnabled' autocomplete='off' 648 type='text' value=''> 649 $change_parent_button 650 </td> 651 </tr> 652 </table> 653 </td> 654 <script type="text/javascript"> 655 <!-- 656 var disabledModules='{$disabled_parent_types}'; 657 if(typeof sqs_objects == 'undefined'){ 658 var sqs_objects = new Array; 659 } 660 sqs_objects['MassUpdate_parent_name'] = $qsName; 661 registerSingleSmartInputListener(document.getElementById('mass_parent_name')); 662 addToValidateBinaryDependency('MassUpdate', 'parent_name', 'alpha', false, '{$app_strings['ERR_SQS_NO_MATCH_FIELD']} {$app_strings['LBL_ASSIGNED_TO']}','parent_id'); 663 664 document.getElementById('mass_{$field['type_name']}').onchange = function() 665 { 666 document.MassUpdate.parent_name.value=""; 667 document.MassUpdate.parent_id.value=""; 668 669 new_module = document.forms["MassUpdate"].elements["parent_type"].value; 670 671 if(typeof(disabledModules[new_module]) != 'undefined') { 672 sqs_objects["MassUpdate_parent_name"]["disable"] = true; 673 document.forms["MassUpdate"].elements["parent_name"].readOnly = true; 674 } else { 675 sqs_objects["MassUpdate_parent_name"]["disable"] = false; 676 document.forms["MassUpdate"].elements["parent_name"].readOnly = false; 677 } 678 sqs_objects["MassUpdate_parent_name"]["modules"] = new Array(new_module); 679 enableQS(false); 680 681 checkParentType(document.MassUpdate.parent_type.value, document.MassUpdate.button_parent_name); 682 } 683 --> 684 </script> 685 EOHTML; 686 } 687 688 /** 689 * Add a generic input type='text' field 690 * @param displayname Name to display in the popup window 691 * @param field_name name of the field 692 */ 693 function addInputType($displayname, $varname){ 694 $html = <<<EOQ 695 <td scope="row" width="20%">$displayname</td> 696 <td class='dataField' width="30%"><input type="text" name='$varname' size="12" id='{$varname}' maxlength='10' value=""></td> 697 <script> addToValidate('MassUpdate','$varname','int',false,'$displayname');</script> 698 EOQ; 699 return $html; 700 701 } 702 /** 703 * Add a generic module popup selection popup window HTML code. 704 * Currently supports Contact and Releases 705 * @param displayname Name to display in the popup window 706 * @param varname name of the variable 707 * @param id_name name of the id in vardef 708 * @param mod_type name of the module, either "Contact" or "Releases" currently 709 */ 710 function addGenericModuleID($displayname, $varname, $id_name='', $mod_type){ 711 global $app_strings; 712 713 if(empty($id_name)) 714 $id_name = strtolower($mod_type)."_id"; 715 716 /////////////////////////////////////// 717 /// 718 /// SETUP POPUP 719 720 $popup_request_data = array( 721 'call_back_function' => 'set_return', 722 'form_name' => 'MassUpdate', 723 'field_to_name_array' => array( 724 'id' => "{$id_name}", 725 'name' => "{$varname}", 726 ), 727 ); 728 729 $json = getJSONobj(); 730 $encoded_popup_request_data = $json->encode($popup_request_data); 731 732 $qsName = array( 733 'form' => 'MassUpdate', 734 'method' => 'query', 735 'modules' => array("{$mod_type}"), 736 'group' => 'or', 737 'field_list' => array('name', 'id'), 738 'populate_list' => array("mass_{$varname}", "mass_{$id_name}"), 739 'conditions' => array(array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')), 740 'limit' => '30','no_match_text' => $app_strings['ERR_SQS_NO_MATCH']); 741 $qsName = $json->encode($qsName); 742 // 743 /////////////////////////////////////// 744 745 return <<<EOHTML 746 <td width='15%' scope='row' class='dataLabel'>$displayname</td> 747 <td width='35%' class='dataField'> 748 <input name='{$varname}' id='mass_{$varname}' class='sqsEnabled' autocomplete='off' type='text' value=''> 749 <input name='{$id_name}' id='mass_{$id_name}' type='hidden' value=''> 750 <input title='{$app_strings['LBL_SELECT_BUTTON_TITLE']}' 751 accessKey='{$app_strings['LBL_SELECT_BUTTON_KEY']}' 752 type='button' class='button' value='{$app_strings['LBL_SELECT_BUTTON_LABEL']}' name='button' 753 onclick='open_popup("$mod_type", 600, 400, "", true, false, {$encoded_popup_request_data});' 754 /> 755 </td> 756 <script type="text/javascript"> 757 <!-- 758 if(typeof sqs_objects == 'undefined'){ 759 var sqs_objects = new Array; 760 } 761 sqs_objects['MassUpdate_{$varname}'] = $qsName; 762 registerSingleSmartInputListener(document.getElementById('mass_{$varname}')); 763 addToValidateBinaryDependency('MassUpdate', '{$varname}', 'alpha', false, '{$app_strings['ERR_SQS_NO_MATCH_FIELD']} {$app_strings['LBL_ASSIGNED_TO']}','{$id_name}'); 764 --> 765 </script> 766 EOHTML; 767 } 768 /** 769 * Add Account selection popup window HTML code 770 * @param displayname Name to display in the popup window 771 * @param varname name of the variable 772 * @param id_name name of the id in vardef 773 */ 774 function addAccountID($displayname, $varname, $id_name=''){ 775 global $app_strings; 776 777 $json = getJSONobj(); 778 779 if(empty($id_name)) 780 $id_name = "account_id"; 781 782 /////////////////////////////////////// 783 /// 784 /// SETUP POPUP 785 786 $popup_request_data = array( 787 'call_back_function' => 'set_return', 788 'form_name' => 'MassUpdate', 789 'field_to_name_array' => array( 790 'id' => "{$id_name}", 791 'name' => "{$varname}", 792 ), 793 ); 794 795 $encoded_popup_request_data = $json->encode($popup_request_data); 796 797 // 798 /////////////////////////////////////// 799 800 $qsParent = array( 801 'form' => 'MassUpdate', 802 'method' => 'query', 803 'modules' => array('Accounts'), 804 'group' => 'or', 805 'field_list' => array('name', 'id'), 806 'populate_list' => array('parent_name', 'parent_id'), 807 'conditions' => array(array('name'=>'name','op'=>'like_custom','end'=>'%','value'=>'')), 808 'order' => 'name', 809 'limit' => '30', 810 'no_match_text' => $app_strings['ERR_SQS_NO_MATCH'] 811 ); 812 $qsParent['populate_list'] = array('mass_'. $varname, 'mass_' . $id_name); 813 814 $html = '<td scope="row">' . $displayname . " </td>\n" 815 . '<td><input class="sqsEnabled" type="text" autocomplete="off" id="mass_' . $varname .'" name="' . $varname . '" value="" /><input id="mass_' . $id_name . '" type="hidden" name="' 816 . $id_name . '" value="" /> <input type="button" name="btn1" class="button" title="' 817 . $app_strings['LBL_SELECT_BUTTON_LABEL'] . '" accesskey="' 818 . $app_strings['LBL_SELECT_BUTTON_KEY'] . '" value="' . $app_strings['LBL_SELECT_BUTTON_LABEL'] . '" onclick=' 819 . "'open_popup(\"Accounts\",600,400,\"\",true,false,{$encoded_popup_request_data});' /></td>\n"; 820 $html .= '<script type="text/javascript" language="javascript">if(typeof sqs_objects == \'undefined\'){var sqs_objects = new Array;}sqs_objects[\'MassUpdate_' . $varname . '\'] = ' . 821 $json->encode($qsParent) . '; registerSingleSmartInputListener(document.getElementById(\'mass_' . $varname . '\')); 822 addToValidateBinaryDependency(\'MassUpdate\', \''.$varname.'\', \'alpha\', false, \'' . $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_ACCOUNT'] . '\',\''.$id_name.'\'); 823 </script>'; 824 825 return $html; 826 } 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 /** 845 * Add AssignedUser popup window HTML code 846 * @param displayname Name to display in the popup window 847 * @param varname name of the variable 848 */ 849 function addAssignedUserID($displayname, $varname){ 850 global $app_strings; 851 852 $json = getJSONobj(); 853 854 $popup_request_data = array( 855 'call_back_function' => 'set_return', 856 'form_name' => 'MassUpdate', 857 'field_to_name_array' => array( 858 'id' => 'assigned_user_id', 859 'user_name' => 'assigned_user_name', 860 ), 861 ); 862 $encoded_popup_request_data = $json->encode($popup_request_data); 863 $qsUser = array( 864 'form' => 'MassUpdate', 865 'method' => 'get_user_array', // special method 866 'field_list' => array('user_name', 'id'), 867 'populate_list' => array('assigned_user_name', 'assigned_user_id'), 868 'conditions' => array(array('name'=>'user_name','op'=>'like_custom','end'=>'%','value'=>'')), 869 'limit' => '30','no_match_text' => $app_strings['ERR_SQS_NO_MATCH']); 870 871 $qsUser['populate_list'] = array('mass_assigned_user_name', 'mass_assigned_user_id'); 872 $html = <<<EOQ 873 <td width="15%" scope="row">$displayname</td> 874 <td ><input class="sqsEnabled" autocomplete="off" id="mass_assigned_user_name" name='assigned_user_name' type="text" value=""><input id='mass_assigned_user_id' name='assigned_user_id' type="hidden" value="" /> 875 <input title="{$app_strings['LBL_SELECT_BUTTON_TITLE']}" accessKey="{$app_strings['LBL_SELECT_BUTTON_KEY']}" type="button" class="button" value='{$app_strings['LBL_SELECT_BUTTON_LABEL']}' name=btn1 876 onclick='open_popup("Users", 600, 400, "", true, false, $encoded_popup_request_data);' /> 877 </td> 878 EOQ; 879 $html .= '<script type="text/javascript" language="javascript">if(typeof sqs_objects == \'undefined\'){var sqs_objects = new Array;}sqs_objects[\'MassUpdate_assigned_user_name\'] = ' . 880 $json->encode($qsUser) . '; registerSingleSmartInputListener(document.getElementById(\'mass_assigned_user_name\')); 881 addToValidateBinaryDependency(\'MassUpdate\', \'assigned_user_name\', \'alpha\', false, \'' . $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_ASSIGNED_TO'] . '\',\'assigned_user_id\'); 882 </script>'; 883 884 return $html; 885 } 886 /** 887 * Add Status selection popup window HTML code 888 * @param displayname Name to display in the popup window 889 * @param varname name of the variable 890 * @param options array of options for status 891 */ 892 function addStatus($displayname, $varname, $options){ 893 global $app_strings, $app_list_strings; 894 895 // cn: added "mass_" to the id tag to diffentieate from the status id in StoreQuery 896 $html = '<td scope="row" width="15%">'.$displayname.'</td><td>'; 897 if(is_array($options)){ 898 if(!isset($options['']) && !isset($options['0'])){ 899 $new_options = array(); 900 $new_options[''] = ''; 901 foreach($options as $key=>$value) { 902 $new_options[$key] = $value; 903 } 904 $options = $new_options; 905 } 906 $options = get_select_options_with_id($options, ''); 907 $html .= '<select id="mass_'.$varname.'" name="'.$varname.'">'.$options.'</select>'; 908 }else{ 909 $html .= $options; 910 } 911 $html .= '</td>'; 912 return $html; 913 } 914 915 /** 916 * Add Status selection popup window HTML code 917 * @param displayname Name to display in the popup window 918 * @param varname name of the variable 919 * @param options array of options for status 920 */ 921 function addBool($displayname, $varname){ 922 global $app_strings, $app_list_strings; 923 return $this->addStatus($displayname, $varname, $app_list_strings['checkbox_dom']); 924 } 925 function addStatusMulti($displayname, $varname, $options){ 926 global $app_strings, $app_list_strings; 927 928 if(!isset($options['']) && !isset($options['0'])){ 929 $new_options = array(); 930 $new_options[''] = ''; 931 foreach($options as $key=>$value) { 932 $new_options[$key] = $value; 933 } 934 $options = $new_options; 935 } 936 $options = get_select_options_with_id($options, ''); 937 938 // cn: added "mass_" to the id tag to diffentieate from the status id in StoreQuery 939 $html = '<td scope="row" width="15%">'.$displayname.'</td> 940 <td><select id="mass_'.$varname.'" name="'.$varname.'[]" size="5" MULTIPLE>'.$options.'</select></td>'; 941 return $html; 942 } 943 /** 944 * Add Date selection popup window HTML code 945 * @param displayname Name to display in the popup window 946 * @param varname name of the variable 947 */ 948 function addDate($displayname, $varname){ 949 global $timedate; 950 $userformat = '('. $timedate->get_user_date_format().')'; 951 $cal_dateformat = $timedate->get_cal_date_format(); 952 global $app_strings, $app_list_strings, $theme; 953 954 $javascriptend = <<<EOQ 955 <script type="text/javascript"> 956 Calendar.setup ({ 957 inputField : "$varname}jscal_field", daFormat : "$cal_dateformat", ifFormat : "$cal_dateformat", showsTime : false, button : "$varname}jscal_trigger", singleClick : true, step : 1, weekNumbers:false 958 }); 959 </script> 960 EOQ; 961 $jscalendarImage = SugarThemeRegistry::current()->getImageURL('jscalendar.gif'); 962 $html = <<<EOQ 963 <td scope="row" width="20%">$displayname</td> 964 <td class='dataField' width="30%"><input onblur="parseDate(this, '$cal_dateformat')" type="text" name='$varname' size="12" id='{$varname}jscal_field' maxlength='10' value=""> 965 <img src="$jscalendarImage" id="{$varname}jscal_trigger" align="absmiddle" title="{$app_strings['LBL_MASSUPDATE_DATE']}" alt='{$app_strings['LBL_MASSUPDATE_DATE']}'> <span class="dateFormat">$userformat</span> 966 $javascriptend</td> 967 <script> addToValidate('MassUpdate','$varname','date',false,'$displayname');</script> 968 EOQ; 969 return $html; 970 971 } 972 973 function date_to_dateTime($field, $value) { 974 global $timedate; 975 //Check if none was set 976 if (isset($this->sugarbean->field_defs[$field]['group'])) { 977 $group = $this->sugarbean->field_defs[$field]['group']; 978 if (isset($this->sugarbean->field_defs[$group."_flag"]) && isset($_POST[$group."_flag"]) 979 && $_POST[$group."_flag"] == 1) { 980 return ""; 981 } 982 } 983 984 $oldDateTime = $this->sugarbean->$field; 985 $oldTime = split(" ", $oldDateTime); 986 if (isset($oldTime[1])) { 987 $oldTime = $oldTime[1]; 988 } else { 989 $oldTime = $timedate->to_display_time($timedate->get_gmt_db_datetime()); 990 } 991 $value = split(" ", $value); 992 $value = $value[0]; 993 return $value." ".$oldTime; 994 } 995 996 function checkClearField($field, $value) { 997 if ($value == 1 && strpos($field, '_flag')) { 998 $fName = substr($field, -5); 999 if (isset($this->sugarbean->field_defs[$field]['group'])) { 1000 $group = $this->sugarbean->field_defs[$field]['group']; 1001 if (isset($this->sugarbean->field_defs[$group])) { 1002 $_POST[$group] = ""; 1003 } 1004 } 1005 } 1006 } 1007 1008 function generateSearchWhere($module, $query) {//this function is similar with function prepareSearchForm() in view.list.php 1009 $seed = loadBean($module); 1010 $this->use_old_search = true; 1011 if(file_exists('modules/'.$module.'/SearchForm.html')){ 1012 if(file_exists('modules/' . $module . '/metadata/SearchFields.php')) { 1013 require_once ('include/SearchForm/SearchForm.php'); 1014 $searchForm = new SearchForm($module, $seed); 1015 } 1016 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. 1017 //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. 1018 $where = $_SESSION['export_where']; 1019 $whereArr = explode (" ", trim($where)); 1020 if ($whereArr[0] == trim('where')) { 1021 $whereClean = array_shift($whereArr); 1022 } 1023 $this->where_clauses = implode(" ", $whereArr); 1024 return; 1025 } 1026 else { 1027 $this->where_clauses = ''; 1028 return; 1029 } 1030 } 1031 else{ 1032 $this->use_old_search = false; 1033 require_once ('include/SearchForm/SearchForm2.php'); 1034 if (file_exists('custom/modules/'.$module.'/metadata/searchdefs.php')) 1035 { 1036 require_once('custom/modules/'.$module.'/metadata/searchdefs.php'); 1037 } 1038 elseif (!empty($metafiles[$module]['searchdefs'])) 1039 { 1040 require_once($metafiles[$module]['searchdefs']); 1041 } 1042 elseif (file_exists('modules/'.$module.'/metadata/searchdefs.php')) 1043 { 1044 require_once('modules/'.$module.'/metadata/searchdefs.php'); 1045 } 1046 1047 1048 if(!empty($metafiles[$module]['searchfields'])) 1049 require_once($metafiles[$module]['searchfields']); 1050 elseif(file_exists('modules/'.$module.'/metadata/SearchFields.php')) 1051 require_once('modules/'.$module.'/metadata/SearchFields.php'); 1052 if(empty($searchdefs) || empty($searchFields)) { 1053 $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. 1054 return; 1055 } 1056 $searchForm = new SearchForm($seed, $module); 1057 $searchForm->setup($searchdefs, $searchFields, 'include/SearchForm/tpls/SearchFormGeneric.tpl'); 1058 } 1059 $searchForm->populateFromArray(unserialize(base64_decode($query))); 1060 $this->searchFields = $searchForm->searchFields; 1061 $where_clauses = $searchForm->generateSearchWhere(true, $module); 1062 if (count($where_clauses) > 0 ) { 1063 $this->where_clauses = '('. implode(' ) AND ( ', $where_clauses) . ')'; 1064 $GLOBALS['log']->info("MassUpdate Where Clause: {$this->where_clauses}"); 1065 } 1066 } 1067 } 1068 1069 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
|
|
|
|