|
iTx Technologies offre gratuitement
|
||
[Vue sommaire] [Imprimer] [Vue textuelle]
1 <?php 2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 3 /********************************************************************************* 4 * SugarCRM is a customer relationship management program developed by 5 * SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc. 6 * 7 * This program is free software; you can redistribute it and/or modify it under 8 * the terms of the GNU General Public License version 3 as published by the 9 * Free Software Foundation with the addition of the following permission added 10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK 11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY 12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 13 * 14 * This program is distributed in the hope that it will be useful, but WITHOUT 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 * details. 18 * 19 * You should have received a copy of the GNU General Public License along with 20 * this program; if not, see http://www.gnu.org/licenses or write to the Free 21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 22 * 02110-1301 USA. 23 * 24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, 25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com. 26 * 27 * The interactive user interfaces in modified source and object code versions 28 * of this program must display Appropriate Legal Notices, as required under 29 * Section 5 of the GNU General Public License version 3. 30 * 31 * In accordance with Section 7(b) of the GNU General Public License version 3, 32 * these Appropriate Legal Notices must retain the display of the "Powered by 33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for 34 * technical reasons, the Appropriate Legal Notices must display the words 35 * "Powered by SugarCRM". 36 ********************************************************************************/ 37 38 /** 39 * Retrieve field data for a provided SugarBean. 40 * 41 * @param SugarBean $value -- The bean to retrieve the field information for. 42 * @return Array -- 'field'=> 'name' -- the name of the field 43 * 'type' -- the data type of the field 44 * 'label' -- the translation key for the label of the field 45 * 'required' -- Is the field required? 46 * 'options' -- Possible values for a drop down field 47 */ 48 function get_field_list(&$value, $translate=true){ 49 $list = array(); 50 51 if(!empty($value->field_defs)){ 52 53 foreach($value->field_defs as $var){ 54 if(isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type'])|| $var['type'] != 'relate'))continue; 55 $required = 0; 56 $options_dom = array(); 57 $options_ret = array(); 58 // Apparently the only purpose of this check is to make sure we only return fields 59 // when we've read a record. Otherwise this function is identical to get_module_field_list 60 if((isset($value->required_fields) && key_exists($var['name'], $value->required_fields)) || 61 (isset($var['required']) && $var['required'] == '1')){ 62 $required = 1; 63 } 64 if(isset($var['options'])){ 65 $options_dom = translate($var['options'], $value->module_dir); 66 if(!is_array($options_dom)) $options_dom = array(); 67 foreach($options_dom as $key=>$oneOption) 68 $options_ret[] = get_name_value($key,$oneOption); 69 } 70 71 if(!empty($var['dbType']) && $var['type'] == 'bool') { 72 $options_ret[] = get_name_value('type', $var['dbType']); 73 } 74 75 $entry = array(); 76 $entry['name'] = $var['name']; 77 $entry['type'] = $var['type']; 78 if($translate) { 79 $entry['label'] = isset($var['vname']) ? translate($var['vname'], $value->module_dir) : $var['name']; 80 } else { 81 $entry['label'] = isset($var['vname']) ? $var['vname'] : $var['name']; 82 } 83 $entry['required'] = $required; 84 $entry['options'] = $options_ret; 85 if(isset($var['default'])) { 86 $entry['default_value'] = $var['default']; 87 } 88 89 $list[$var['name']] = $entry; 90 } //foreach 91 } //if 92 93 if($value->module_dir == 'Bugs'){ 94 95 $seedRelease = new Release(); 96 $options = $seedRelease->get_releases(TRUE, "Active"); 97 $options_ret = array(); 98 foreach($options as $name=>$value){ 99 $options_ret[] = array('name'=> $name , 'value'=>$value); 100 } 101 if(isset($list['fixed_in_release'])){ 102 $list['fixed_in_release']['type'] = 'enum'; 103 $list['fixed_in_release']['options'] = $options_ret; 104 } 105 if(isset($list['release'])){ 106 $list['release']['type'] = 'enum'; 107 $list['release']['options'] = $options_ret; 108 } 109 if(isset($list['release_name'])){ 110 $list['release_name']['type'] = 'enum'; 111 $list['release_name']['options'] = $options_ret; 112 } 113 } 114 if(isset($value->assigned_user_name) && isset($list['assigned_user_id'])) { 115 $list['assigned_user_name'] = $list['assigned_user_id']; 116 $list['assigned_user_name']['name'] = 'assigned_user_name'; 117 } 118 119 120 121 122 123 124 if(isset($list['modified_user_id'])) { 125 $list['modified_by_name'] = $list['modified_user_id']; 126 $list['modified_by_name']['name'] = 'modified_by_name'; 127 } 128 if(isset($list['created_by'])) { 129 $list['created_by_name'] = $list['created_by']; 130 $list['created_by_name']['name'] = 'created_by_name'; 131 } 132 return $list; 133 } 134 135 function new_get_field_list($value, $translate=true) { 136 $module_fields = array(); 137 $link_fields = array(); 138 139 if(!empty($value->field_defs)){ 140 141 foreach($value->field_defs as $var){ 142 if(isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'non-db' &&$var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type'])|| $var['type'] != 'relate'))continue; 143 if ($var['source'] == 'non_db' && (isset($var['type']) && $var['type'] != 'link')) { 144 continue; 145 } 146 $required = 0; 147 $options_dom = array(); 148 $options_ret = array(); 149 // Apparently the only purpose of this check is to make sure we only return fields 150 // when we've read a record. Otherwise this function is identical to get_module_field_list 151 if((isset($value->required_fields) && key_exists($var['name'], $value->required_fields)) || 152 (isset($var['required']) && $var['required'] == '1')){ 153 $required = 1; 154 } 155 if(isset($var['options'])){ 156 $options_dom = translate($var['options'], $value->module_dir); 157 if(!is_array($options_dom)) $options_dom = array(); 158 foreach($options_dom as $key=>$oneOption) 159 $options_ret[] = get_name_value($key,$oneOption); 160 } 161 162 if(!empty($var['dbType']) && $var['type'] == 'bool') { 163 $options_ret[] = get_name_value('type', $var['dbType']); 164 } 165 166 $entry = array(); 167 $entry['name'] = $var['name']; 168 $entry['type'] = $var['type']; 169 if ($var['type'] == 'link') { 170 $entry['relationship'] = (isset($var['relationship']) ? $var['relationship'] : ''); 171 $entry['module'] = (isset($var['module']) ? $var['module'] : ''); 172 $entry['bean_name'] = (isset($var['bean_name']) ? $var['bean_name'] : ''); 173 $link_fields[$var['name']] = $entry; 174 } else { 175 if($translate) { 176 $entry['label'] = isset($var['vname']) ? translate($var['vname'], $value->module_dir) : $var['name']; 177 } else { 178 $entry['label'] = isset($var['vname']) ? $var['vname'] : $var['name']; 179 } 180 $entry['required'] = $required; 181 $entry['options'] = $options_ret; 182 if(isset($var['default'])) { 183 $entry['default_value'] = $var['default']; 184 } 185 $module_fields[$var['name']] = $entry; 186 } // else 187 } //foreach 188 } //if 189 190 if($value->module_dir == 'Bugs'){ 191 192 $seedRelease = new Release(); 193 $options = $seedRelease->get_releases(TRUE, "Active"); 194 $options_ret = array(); 195 foreach($options as $name=>$value){ 196 $options_ret[] = array('name'=> $name , 'value'=>$value); 197 } 198 if(isset($module_fields['fixed_in_release'])){ 199 $module_fields['fixed_in_release']['type'] = 'enum'; 200 $module_fields['fixed_in_release']['options'] = $options_ret; 201 } 202 if(isset($module_fields['release'])){ 203 $module_fields['release']['type'] = 'enum'; 204 $module_fields['release']['options'] = $options_ret; 205 } 206 if(isset($module_fields['release_name'])){ 207 $module_fields['release_name']['type'] = 'enum'; 208 $module_fields['release_name']['options'] = $options_ret; 209 } 210 } 211 if(isset($value->assigned_user_name) && isset($module_fields['assigned_user_id'])) { 212 $module_fields['assigned_user_name'] = $module_fields['assigned_user_id']; 213 $module_fields['assigned_user_name']['name'] = 'assigned_user_name'; 214 } 215 216 217 218 219 220 221 if(isset($module_fields['modified_user_id'])) { 222 $module_fields['modified_by_name'] = $module_fields['modified_user_id']; 223 $module_fields['modified_by_name']['name'] = 'modified_by_name'; 224 } 225 if(isset($module_fields['created_by'])) { 226 $module_fields['created_by_name'] = $module_fields['created_by']; 227 $module_fields['created_by_name']['name'] = 'created_by_name'; 228 } 229 230 return array('module_fields' => $module_fields, 'link_fields' => $link_fields); 231 } // fn 232 233 function setFaultObject($errorObject) { 234 global $soap_server_object; 235 $soap_server_object->fault($errorObject->getFaultCode(), $errorObject->getName(), '', $errorObject->getDescription()); 236 } // fn 237 238 function checkSessionAndModuleAccess($session, $login_error_key, $module_name, $access_level, $module_access_level_error_key, $errorObject) { 239 if(!validate_authenticated($session)){ 240 $errorObject->set_error('invalid_login'); 241 setFaultObject($errorObject); 242 return false; 243 } // if 244 245 global $beanList, $beanFiles; 246 if (!empty($module_name)) { 247 if(empty($beanList[$module_name])){ 248 $errorObject->set_error('no_module'); 249 setFaultObject($errorObject); 250 return false; 251 } // if 252 global $current_user; 253 if(!check_modules_access($current_user, $module_name, $access_level)){ 254 $errorObject->set_error('no_access'); 255 setFaultObject($errorObject); 256 return false; 257 } 258 } // if 259 return true; 260 } // fn 261 262 function checkACLAccess($bean, $viewType, $errorObject, $error_key) { 263 if(!$bean->ACLAccess($viewType)){ 264 $errorObject->set_error($error_key); 265 setFaultObject($errorObject); 266 return false; 267 } // if 268 return true; 269 } // fn 270 271 function get_name_value($field,$value){ 272 return array('name'=>$field, 'value'=>$value); 273 } 274 275 function get_user_module_list($user){ 276 global $app_list_strings, $current_language; 277 278 $app_list_strings = return_app_list_strings_language($current_language); 279 $modules = query_module_access_list($user); 280 ACLController :: filterModuleList($modules, false); 281 global $modInvisList, $modInvisListActivities; 282 283 foreach($modInvisList as $invis){ 284 $modules[$invis] = 'read_only'; 285 } 286 287 if(isset($modules['Calendar']) || $modules['Activities']){ 288 foreach($modInvisListActivities as $invis){ 289 $modules[$invis] = $invis; 290 } 291 } 292 293 $actions = ACLAction::getUserActions($user->id,true); 294 foreach($actions as $key=>$value){ 295 if($value['module']['access']['aclaccess'] < ACL_ALLOW_ENABLED){ 296 if ($value['module']['access']['aclaccess'] == ACL_ALLOW_DISABLED) { 297 unset($modules[$key]); 298 } else { 299 $modules[$key] = 'read_only'; 300 } // else 301 } else { 302 $modules[$key] = ''; 303 } // else 304 } // foreach 305 306 return $modules; 307 308 } 309 310 function check_modules_access($user, $module_name, $action='write'){ 311 if(!isset($_SESSION['avail_modules'])){ 312 $_SESSION['avail_modules'] = get_user_module_list($user); 313 } 314 if(isset($_SESSION['avail_modules'][$module_name])){ 315 if($action == 'write' && $_SESSION['avail_modules'][$module_name] == 'read_only'){ 316 if(is_admin($user))return true; 317 return false; 318 } 319 return true; 320 } 321 return false; 322 323 } 324 325 function get_name_value_list(&$value, $returnDomValue = false){ 326 global $app_list_strings; 327 $list = array(); 328 if(!empty($value->field_defs)){ 329 if(isset($value->assigned_user_name)) { 330 $list['assigned_user_name'] = get_name_value('assigned_user_name', $value->assigned_user_name); 331 } 332 333 334 335 336 337 if(isset($value->modified_by_name)) { 338 $list['modified_by_name'] = get_name_value('modified_by_name', $value->modified_by_name); 339 } 340 if(isset($value->created_by_name)) { 341 $list['created_by_name'] = get_name_value('created_by_name', $value->created_by_name); 342 } 343 foreach($value->field_defs as $var){ 344 if(isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type'])|| $var['type'] != 'relate')){ 345 346 if($value->module_dir == 'Emails' && (($var['name'] == 'description') || ($var['name'] == 'description_html') || ($var['name'] == 'from_addr_name') || ($var['name'] == 'reply_to_addr') || ($var['name'] == 'to_addrs_names') || ($var['name'] == 'cc_addrs_names') || ($var['name'] == 'bcc_addrs_names') || ($var['name'] == 'raw_source'))) { 347 348 } else { 349 continue; 350 } 351 } 352 353 if(isset($value->$var['name'])){ 354 $val = $value->$var['name']; 355 $type = $var['type']; 356 357 if(strcmp($type, 'date') == 0){ 358 $val = substr($val, 0, 10); 359 }elseif(strcmp($type, 'enum') == 0 && !empty($var['options']) && $returnDomValue){ 360 $val = $app_list_strings[$var['options']][$val]; 361 } 362 363 $list[$var['name']] = get_name_value($var['name'], $val); 364 } 365 } 366 } 367 return $list; 368 369 } 370 371 function filter_fields($value, $fields) { 372 global $invalid_contact_fields; 373 $filterFields = array(); 374 foreach($fields as $field){ 375 if (is_array($invalid_contact_fields)) { 376 if (in_array($field, $invalid_contact_fields)) { 377 continue; 378 } // if 379 } // if 380 if (isset($value->field_defs[$field])) { 381 $var = $value->field_defs[$field]; 382 if(isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type'])|| $var['type'] != 'relate')) { 383 384 continue; 385 } 386 } // if 387 $filterFields[] = $field; 388 } // foreach 389 return $filterFields; 390 } // fn 391 392 function get_name_value_list_for_fields($value, $fields) { 393 global $app_list_strings; 394 global $invalid_contact_fields; 395 396 $list = array(); 397 if(!empty($value->field_defs)){ 398 if(isset($value->assigned_user_name) && in_array('assigned_user_name', $fields)) { 399 $list['assigned_user_name'] = get_name_value('assigned_user_name', $value->assigned_user_name); 400 } 401 402 403 404 405 406 if(isset($value->modified_by_name) && in_array('modified_by_name', $fields)) { 407 $list['modified_by_name'] = get_name_value('modified_by_name', $value->modified_by_name); 408 } 409 if(isset($value->created_by_name) && in_array('created_by_name', $fields)) { 410 $list['created_by_name'] = get_name_value('created_by_name', $value->created_by_name); 411 } 412 413 $filterFields = filter_fields($value, $fields); 414 foreach($filterFields as $field){ 415 $var = $value->field_defs[$field]; 416 if(isset($value->$var['name'])){ 417 $val = $value->$var['name']; 418 $type = $var['type']; 419 420 if(strcmp($type, 'date') == 0){ 421 $val = substr($val, 0, 10); 422 }elseif(strcmp($type, 'enum') == 0 && !empty($var['options'])){ 423 $val = $app_list_strings[$var['options']][$val]; 424 } 425 426 $list[$var['name']] = get_name_value($var['name'], $val); 427 } // if 428 } // foreach 429 } // if 430 return $list; 431 432 } // fn 433 434 435 function array_get_name_value_list($array){ 436 $list = array(); 437 foreach($array as $name=>$value){ 438 439 $list[$name] = get_name_value($name, $value); 440 } 441 return $list; 442 443 } 444 445 function array_get_name_value_lists($array){ 446 $list = array(); 447 foreach($array as $name=>$value){ 448 $tmp_value=$value; 449 if(is_array($value)){ 450 $tmp_value = array(); 451 foreach($value as $k=>$v){ 452 $tmp_value[] = get_name_value($k, $v); 453 } 454 } 455 $list[] = get_name_value($name, $tmp_value); 456 } 457 return $list; 458 } 459 460 function name_value_lists_get_array($list){ 461 $array = array(); 462 foreach($list as $key=>$value){ 463 if(isset($value['value']) && isset($value['name'])){ 464 if(is_array($value['value'])){ 465 $array[$value['name']]=array(); 466 foreach($value['value'] as $v){ 467 $array[$value['name']][$v['name']]=$v['value']; 468 } 469 }else{ 470 $array[$value['name']]=$value['value']; 471 } 472 } 473 } 474 return $array; 475 } 476 477 function array_get_return_value($array, $module){ 478 479 return Array('id'=>$array['id'], 480 'module_name'=> $module, 481 'name_value_list'=>array_get_name_value_list($array) 482 ); 483 } 484 485 function get_return_value_for_fields($value, $module, $fields) { 486 global $module_name, $current_user; 487 $module_name = $module; 488 if($module == 'Users' && $value->id != $current_user->id){ 489 $value->user_hash = ''; 490 } 491 return Array('id'=>$value->id, 492 'module_name'=> $module, 493 'name_value_list'=>get_name_value_list_for_fields($value, $fields) 494 ); 495 } 496 497 function getRelationshipResults($bean, $link_field_name, $link_module_fields, $optional_where = '') { 498 global $beanList, $beanFiles; 499 $bean->load_relationship($link_field_name); 500 if (isset($bean->$link_field_name)) { 501 // get the query object for this link field 502 $query_array = $bean->$link_field_name->getQuery(true,array(),0,'',true); 503 $params = array(); 504 $params['joined_tables'] = $query_array['join_tables']; 505 506 // get the related module name and instantiate a bean for that. 507 $submodulename = $bean->$link_field_name->getRelatedModuleName(); 508 $submoduleclass = $beanList[$submodulename]; 509 require_once($beanFiles[$submoduleclass]); 510 511 $submodule = new $submoduleclass(); 512 $filterFields = filter_fields($submodule, $link_module_fields); 513 $relFields = $bean->$link_field_name->getRelatedFields(); 514 $roleSelect = ''; 515 516 if(!empty($relFields)){ 517 foreach($link_module_fields as $field){ 518 if(!empty($relFields[$field])){ 519 $roleSelect .= ', ' . $query_array['join_tables'][0] . '.'. $field; 520 } 521 } 522 } 523 // create a query 524 $subquery = $submodule->create_new_list_query('',$optional_where ,$filterFields,$params, 0,'', true,$bean); 525 $query = $subquery['select'].$roleSelect . $subquery['from'].$query_array['join']. $subquery['where']; 526 527 $result = $submodule->db->query($query, true); 528 $list = array(); 529 while($row = $submodule->db->fetchByAssoc($result)) { 530 $list[] = $row; 531 } 532 return array('rows' => $list, 'fields_set_on_rows' => $filterFields); 533 } else { 534 return false; 535 } // else 536 537 } // fn 538 539 function get_return_value_for_link_fields($bean, $module, $link_name_to_value_fields_array) { 540 global $module_name, $current_user; 541 $module_name = $module; 542 if($module == 'Users' && $bean->id != $current_user->id){ 543 $bean->user_hash = ''; 544 } 545 546 if (empty($link_name_to_value_fields_array) || !is_array($link_name_to_value_fields_array)) { 547 return array(); 548 } 549 550 $link_output = array(); 551 foreach($link_name_to_value_fields_array as $link_name_value_fields) { 552 if (!is_array($link_name_value_fields) || !isset($link_name_value_fields['name']) || !isset($link_name_value_fields['value'])) { 553 continue; 554 } 555 $link_field_name = $link_name_value_fields['name']; 556 $link_module_fields = $link_name_value_fields['value']; 557 if (is_array($link_module_fields) && !empty($link_module_fields)) { 558 $result = getRelationshipResults($bean, $link_field_name, $link_module_fields); 559 if (!$result) { 560 $link_output[] = array('name' => $link_field_name, 'records' => array()); 561 continue; 562 } 563 $list = $result['rows']; 564 $filterFields = $result['fields_set_on_rows']; 565 if ($list) { 566 $rowArray = array(); 567 foreach($list as $row) { 568 $nameValueArray = array(); 569 foreach ($filterFields as $field) { 570 $nameValue = array(); 571 if (isset($row[$field])) { 572 $nameValue['name'] = $field; 573 $nameValue['value'] = $row[$field]; 574 $nameValueArray[] = $nameValue; 575 } // if 576 } // foreach 577 $rowArray[] = $nameValueArray; 578 } // foreach 579 $link_output[] = array('name' => $link_field_name, 'records' => $rowArray); 580 } // if 581 } // if 582 } // foreach 583 return $link_output; 584 } // fn 585 586 /** 587 * 588 * @param String $module_name -- The name of the module that the primary record is from. This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method). 589 * @param String $module_id -- The ID of the bean in the specified module 590 * @param String $link_field_name - The relationship name for which to create realtionships. 591 * @param Array $related_ids -- The array of ids for which we want to create relationships 592 * @return true on success, false on failure 593 */ 594 function new_handle_set_relationship($module_name, $module_id, $link_field_name, $related_ids) { 595 global $beanList, $beanFiles; 596 597 if(empty($beanList[$module_name])) { 598 return false; 599 } // if 600 $class_name = $beanList[$module_name]; 601 require_once($beanFiles[$class_name]); 602 $mod = new $class_name(); 603 $mod->retrieve($module_id); 604 if(!$mod->ACLAccess('DetailView')){ 605 return false; 606 } 607 608 foreach($related_ids as $ids) { 609 $GLOBALS['log']->debug("ids = " . $ids ); 610 } 611 612 if ($mod->load_relationship($link_field_name)) { 613 $mod->$link_field_name->add($related_ids); 614 return true; 615 } else { 616 return false; 617 } 618 } 619 620 function new_handle_set_entries($module_name, $name_value_lists, $select_fields = FALSE) { 621 global $beanList, $beanFiles; 622 623 $ret_values = array(); 624 625 global $current_user; 626 $class_name = $beanList[$module_name]; 627 require_once($beanFiles[$class_name]); 628 $ids = array(); 629 $count = 1; 630 $total = sizeof($name_value_lists); 631 foreach($name_value_lists as $name_value_list){ 632 $seed = new $class_name(); 633 634 $seed->update_vcal = false; 635 foreach($name_value_list as $value){ 636 if($value['name'] == 'id'){ 637 $seed->retrieve($value['value']); 638 break; 639 } 640 } 641 642 foreach($name_value_list as $value) { 643 $val = $value['value']; 644 if($seed->field_name_map[$value['name']]['type'] == 'enum'){ 645 $vardef = $seed->field_name_map[$value['name']]; 646 if(isset($app_list_strings[$vardef['options']]) && !isset($app_list_strings[$vardef['options']][$value]) ) { 647 if ( in_array($val,$app_list_strings[$vardef['options']]) ){ 648 $val = array_search($val,$app_list_strings[$vardef['options']]); 649 } 650 } 651 } 652 $seed->$value['name'] = $val; 653 } 654 655 if($count == $total){ 656 $seed->update_vcal = false; 657 } 658 $count++; 659 660 //Add the account to a contact 661 if($module_name == 'Contacts'){ 662 $GLOBALS['log']->debug('Creating Contact Account'); 663 add_create_account($seed); 664 $duplicate_id = check_for_duplicate_contacts($seed); 665 if($duplicate_id == null){ 666 if($seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){ 667 $seed->save(); 668 if($seed->deleted == 1){ 669 $seed->mark_deleted($seed->id); 670 } 671 $ids[] = $seed->id; 672 } 673 } 674 else{ 675 //since we found a duplicate we should set the sync flag 676 if( $seed->ACLAccess('Save')){ 677 $seed = new $class_name(); 678 $seed->id = $duplicate_id; 679 $seed->contacts_users_id = $current_user->id; 680 $seed->save(); 681 $ids[] = $duplicate_id;//we have a conflict 682 } 683 } 684 } 685 else if($module_name == 'Meetings' || $module_name == 'Calls'){ 686 //we are going to check if we have a meeting in the system 687 //with the same outlook_id. If we do find one then we will grab that 688 //id and save it 689 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){ 690 if(empty($seed->id) && !isset($seed->id)){ 691 if(!empty($seed->outlook_id) && isset($seed->outlook_id)){ 692 //at this point we have an object that does not have 693 //the id set, but does have the outlook_id set 694 //so we need to query the db to find if we already 695 //have an object with this outlook_id, if we do 696 //then we can set the id, otherwise this is a new object 697 $order_by = ""; 698 $query = $seed->table_name.".outlook_id = '".$seed->outlook_id."'"; 699 $response = $seed->get_list($order_by, $query, 0,-1,-1,0); 700 $list = $response['list']; 701 if(count($list) > 0){ 702 foreach($list as $value) 703 { 704 $seed->id = $value->id; 705 break; 706 } 707 }//fi 708 }//fi 709 }//fi 710 $seed->save(); 711 $ids[] = $seed->id; 712 }//fi 713 } 714 else 715 { 716 if( $seed->ACLAccess('Save') && ($seed->deleted != 1 || $seed->ACLAccess('Delete'))){ 717 $seed->save(); 718 $ids[] = $seed->id; 719 } 720 } 721 722 // if somebody is calling set_entries_detail() and wants fields returned... 723 if ($select_fields !== FALSE) { 724 $ret_values[$count] = array(); 725 726 foreach ($select_fields as $select_field) { 727 if (isset($seed->$select_field)) { 728 $ret_values[$count][] = get_name_value($select_field, $seed->$select_field); 729 } 730 } 731 } 732 } 733 734 // handle returns for set_entries_detail() and set_entries() 735 if ($select_fields !== FALSE) { 736 return array( 737 'name_value_lists' => $ret_values, 738 ); 739 } 740 else { 741 return array( 742 'ids' => $ids, 743 ); 744 } 745 } 746 747 function get_return_value(&$value, $module, $returnDomValue = false){ 748 global $module_name, $current_user; 749 $module_name = $module; 750 if($module == 'Users' && $value->id != $current_user->id){ 751 $value->user_hash = ''; 752 } 753 return Array('id'=>$value->id, 754 'module_name'=> $module, 755 'name_value_list'=>get_name_value_list($value, $returnDomValue) 756 ); 757 } 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 function get_name_value_xml($val, $module_name){ 817 $xml = '<item>'; 818 $xml .= '<id>'.$val['id'].'</id>'; 819 $xml .= '<module>'.$module_name.'</module>'; 820 $xml .= '<name_value_list>'; 821 foreach($val['name_value_list'] as $name=>$nv){ 822 $xml .= '<name_value>'; 823 $xml .= '<name>'.htmlspecialchars($nv['name']).'</name>'; 824 $xml .= '<value>'.htmlspecialchars($nv['value']).'</value>'; 825 $xml .= '</name_value>'; 826 } 827 $xml .= '</name_value_list>'; 828 $xml .= '</item>'; 829 return $xml; 830 } 831 832 /* 833 function get_module_field_list(&$value){ 834 $list = array(); 835 if(!empty($value->field_defs)){ 836 foreach($value->field_defs as $var){ 837 $required = 0; 838 $options_dom = array(); 839 $translateOptions = false; 840 841 if(isset($value->required_fields) && key_exists($var['name'], $value->required_fields)){ 842 $required = 1; 843 } 844 if(isset($var['options'])){ 845 $options_dom = $var['options']; 846 $translateOptions = true; 847 } 848 if($value->module_dir == 'Bugs'){ 849 require_once('modules/Releases/Release.php'); 850 $seedRelease = new Release(); 851 $options = $seedRelease->get_releases(TRUE, "Active"); 852 if($var['name'] == 'fixed_in_release'){ 853 $var['type'] = 'enum'; 854 $translateOptions = false; 855 foreach($options as $name=>$avalue){ 856 $options_dom[$avalue] = $name; 857 } 858 } 859 if($var['name'] == 'release'){ 860 $var['type'] = 'enum'; 861 $translateOptions = false; 862 foreach($options as $name=>$avalue){ 863 $options_dom[$avalue] = $name; 864 } 865 } 866 } 867 $list[$var['name']] = array('name'=>$var['name'], 868 'type'=>$var['type'], 869 'label'=>translate($var['vname'], $value->module_dir), 870 'required'=>$required, 871 'options'=>get_field_options($options_dom, $translateOptions) ); 872 873 } 874 } 875 876 return $list; 877 } 878 */ 879 880 function new_get_return_module_fields($value, $module, $translate=true){ 881 global $module_name; 882 $module_name = $module; 883 $result = new_get_field_list($value, $translate); 884 return Array('module_name'=>$module, 885 'module_fields'=> $result['module_fields'], 886 'link_fields'=> $result['link_fields'], 887 ); 888 } 889 890 function get_return_module_fields(&$value, $module, &$error, $translate=true){ 891 global $module_name; 892 $module_name = $module; 893 return Array('module_name'=>$module, 894 'module_fields'=> get_field_list($value, $translate), 895 'error'=>get_name_value_list($value) 896 ); 897 } 898 899 function get_return_error_value($error_num, $error_name, $error_description){ 900 return Array('number'=>$error_num, 901 'name'=> $error_name, 902 'description'=> $error_description 903 ); 904 } 905 906 function filter_field_list(&$field_list, &$select_fields, $module_name){ 907 return filter_return_list($field_list, $select_fields, $module_name); 908 } 909 910 911 /** 912 * Filter the results of a list query. Limit the fields returned. 913 * 914 * @param Array $output_list -- The array of list data 915 * @param Array $select_fields -- The list of fields that should be returned. If this array is specfied, only the fields in the array will be returned. 916 * @param String $module_name -- The name of the module this being worked on 917 * @return The filtered array of list data. 918 */ 919 function filter_return_list(&$output_list, $select_fields, $module_name){ 920 921 for($sug = 0; $sug < sizeof($output_list) ; $sug++){ 922 if($module_name == 'Contacts'){ 923 global $invalid_contact_fields; 924 if(is_array($invalid_contact_fields)){ 925 foreach($invalid_contact_fields as $name=>$val){ 926 unset($output_list[$sug]['field_list'][$name]); 927 unset($output_list[$sug]['name_value_list'][$name]); 928 929 } 930 } 931 } 932 933 if( !empty($output_list[$sug]['name_value_list']) && is_array($output_list[$sug]['name_value_list']) && !empty($select_fields) && is_array($select_fields)){ 934 foreach($output_list[$sug]['name_value_list'] as $name=>$value) 935 if(!in_array($value['name'], $select_fields)){ 936 unset($output_list[$sug]['name_value_list'][$name]); 937 unset($output_list[$sug]['field_list'][$name]); 938 } 939 } 940 } 941 return $output_list; 942 } 943 944 function login_success(){ 945 global $current_language, $sugar_config, $app_strings, $app_list_strings; 946 $current_language = $sugar_config['default_language']; 947 $app_strings = return_application_language($current_language); 948 $app_list_strings = return_app_list_strings_language($current_language); 949 } 950 951 952 /* 953 * Given an account_name, either create the account or assign to a contact. 954 */ 955 function add_create_account(&$seed) 956 { 957 global $current_user; 958 $account_name = $seed->account_name; 959 $account_id = $seed->account_id; 960 $assigned_user_id = $current_user->id; 961 962 // check if it already exists 963 $focus = new Account(); 964 if( $focus->ACLAccess('Save')){ 965 $class = get_class($seed); 966 $temp = new $class(); 967 $temp->retrieve($seed->id); 968 if ((! isset($account_name) || $account_name == '')) 969 { 970 return; 971 } 972 if (!isset($seed->accounts)){ 973 $seed->load_relationship('accounts'); 974 } 975 976 if($seed->account_name = '' && isset($temp->account_id)){ 977 $seed->accounts->delete($seed->id, $temp->account_id); 978 return; 979 } 980 981 $arr = array(); 982 983 984 985 $query = "select id, deleted from {$focus->table_name} WHERE name='".$seed->db->quote($account_name)."'"; 986 $query .=" ORDER BY deleted ASC"; 987 $result = $seed->db->query($query) or sugar_die("Error selecting sugarbean: ".mysql_error()); 988 989 $row = $seed->db->fetchByAssoc($result, -1, false); 990 991 // we found a row with that id 992 if (isset($row['id']) && $row['id'] != -1) 993 { 994 // if it exists but was deleted, just remove it entirely 995 if ( isset($row['deleted']) && $row['deleted'] == 1) 996 { 997 $query2 = "delete from {$focus->table_name} WHERE id='". $seed->db->quote($row['id'])."'"; 998 $result2 = $seed->db->query($query2) or sugar_die("Error deleting existing sugarbean: ".mysql_error()); 999 } 1000 // else just use this id to link the contact to the account 1001 else 1002 { 1003 $focus->id = $row['id']; 1004 } 1005 } 1006 1007 // if we didnt find the account, so create it 1008 if (! isset($focus->id) || $focus->id == '') 1009 { 1010 $focus->name = $account_name; 1011 1012 if ( isset($assigned_user_id)) 1013 { 1014 $focus->assigned_user_id = $assigned_user_id; 1015 $focus->modified_user_id = $assigned_user_id; 1016 } 1017 $focus->save(); 1018 } 1019 1020 if($seed->accounts != null && $temp->account_id != null && $temp->account_id != $focus->id){ 1021 $seed->accounts->delete($seed->id, $temp->account_id); 1022 } 1023 1024 if(isset($focus->id) && $focus->id != ''){ 1025 $seed->account_id = $focus->id; 1026 } 1027 } 1028 } 1029 1030 function check_for_duplicate_contacts(&$seed){ 1031 1032 1033 if(isset($seed->id)){ 1034 return null; 1035 } 1036 1037 $query = ''; 1038 1039 $trimmed_email = trim($seed->email1); 1040 $trimmed_last = trim($seed->last_name); 1041 $trimmed_first = trim($seed->first_name); 1042 if(!empty($trimmed_email)){ 1043 1044 //obtain a list of contacts which contain the same email address 1045 $contacts = $seed->emailAddress->getBeansByEmailAddress($trimmed_email); 1046 if(count($contacts) == 0){ 1047 return null; 1048 }else{ 1049 foreach($contacts as $contact){ 1050 if(!empty($trimmed_last) && strcmp($trimmed_last, $contact->last_name) == 0){ 1051 if(!empty($trimmed_email) && strcmp($trimmed_email, $contact->email1) == 0){ 1052 if(!empty($trimmed_email)){ 1053 if(strcmp($trimmed_email, $contact->email1) == 0) 1054 return $contact->id; 1055 }else 1056 return $contact->id; 1057 } 1058 } 1059 } 1060 return null; 1061 } 1062 }else{ 1063 $query = "contacts.last_name = '$trimmed_last'"; 1064 $query .= " AND contacts.first_name = '$trimmed_first'"; 1065 $contacts = $seed->get_list('', $query); 1066 if (count($contacts) == 0){ 1067 return null; 1068 }else{ 1069 foreach($contacts['list'] as $contact){ 1070 if (empty($contact->email1)){ 1071 return $contact->id; 1072 } 1073 } 1074 return null; 1075 } 1076 } 1077 } 1078 1079 /* 1080 * Given a client version and a server version, determine if the right hand side(server version) is greater 1081 * 1082 * @param left the client sugar version 1083 * @param right the server version 1084 * 1085 * return true if the server version is greater or they are equal 1086 * false if the client version is greater 1087 */ 1088 function is_server_version_greater($left, $right){ 1089 if(count($left) == 0 && count($right) == 0){ 1090 return false; 1091 } 1092 else if(count($left) == 0 || count($right) == 0){ 1093 return true; 1094 } 1095 else if($left[0] == $right[0]){ 1096 array_shift($left); 1097 array_shift($right); 1098 return is_server_version_greater($left, $right); 1099 } 1100 else if($left[0] < $right[0]){ 1101 return true; 1102 } 1103 else 1104 return false; 1105 } 1106 1107 function getFile( $zip_file, $file_in_zip ){ 1108 global $sugar_config; 1109 $base_upgrade_dir = $sugar_config['upload_dir'] . "/upgrades"; 1110 $base_tmp_upgrade_dir = "$base_upgrade_dir/temp"; 1111 $my_zip_dir = mk_temp_dir( $base_tmp_upgrade_dir ); 1112 unzip_file( $zip_file, $file_in_zip, $my_zip_dir ); 1113 return( "$my_zip_dir/$file_in_zip" ); 1114 } 1115 1116 function getManifest( $zip_file ){ 1117 ini_set("max_execution_time", "3600"); 1118 return( getFile( $zip_file, "manifest.php" ) ); 1119 } 1120 1121 if(!function_exists("get_encoded")){ 1122 /*HELPER FUNCTIONS*/ 1123 function get_encoded($object){ 1124 return base64_encode(serialize($object)); 1125 } 1126 function get_decoded($object){ 1127 return unserialize(base64_decode($object)); 1128 1129 } 1130 1131 /** 1132 * decrypt a string use the TripleDES algorithm. This meant to be 1133 * modified if the end user chooses a different algorithm 1134 * 1135 * @param $string - the string to decrypt 1136 * 1137 * @return a decrypted string if we can decrypt, the original string otherwise 1138 */ 1139 function decrypt_string($string){ 1140 if(function_exists('mcrypt_cbc')){ 1141 1142 $focus = new Administration(); 1143 $focus->retrieveSettings(); 1144 $key = ''; 1145 if(!empty($focus->settings['ldap_enc_key'])){ 1146 $key = $focus->settings['ldap_enc_key']; 1147 } 1148 if(empty($key)) 1149 return $string; 1150 $buffer = $string; 1151 $key = substr(md5($key),0,24); 1152 $iv = "password"; 1153 return mcrypt_cbc(MCRYPT_3DES, $key, pack("H*", $buffer), MCRYPT_DECRYPT, $iv); 1154 }else{ 1155 return $string; 1156 } 1157 } 1158 1159 } 1160 1161 function canViewPath( $path, $base ){ 1162 $path = realpath( $path ); 1163 $base = realpath( $base ); 1164 return 0 !== strncmp( $path, $base, strlen( $base ) ); 1165 } 1166 /*END HELPER*/ 1167 1168 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
|
|
|
|