| [ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 /********************************************************************************* 3 * The contents of this file are subject to the SugarCRM Public License Version 1.1.2 4 * ("License"); You may not use this file except in compliance with the 5 * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL 6 * Software distributed under the License is distributed on an "AS IS" basis, 7 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for 8 * the specific language governing rights and limitations under the License. 9 * The Original Code is: SugarCRM Open Source 10 * The Initial Developer of the Original Code is SugarCRM, Inc. 11 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.; 12 * All Rights Reserved. 13 * Contributor(s): ______________________________________. 14 ********************************************************************************/ 15 /********************************************************************************* 16 * $Header$ 17 * Description: Includes generic helper functions used throughout the application. 18 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 19 * All Rights Reserved. 20 * Contributor(s): ______________________________________.. 21 ********************************************************************************/ 22 23 24 25 /** This function returns the name of the person. 26 * It currently returns "first last". It should not put the space if either name is not available. 27 * It should not return errors if either name is not available. 28 * If no names are present, it will return "" 29 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 30 * All Rights Reserved. 31 * Contributor(s): ______________________________________.. 32 */ 33 34 require_once ('include/database/PearDatabase.php'); 35 require_once ('include/ComboUtil.php'); //new 36 require_once ('include/utils/ListViewUtils.php'); 37 require_once ('include/utils/EditViewUtils.php'); 38 require_once ('include/utils/DetailViewUtils.php'); 39 require_once ('include/utils/CommonUtils.php'); 40 require_once ('include/utils/InventoryUtils.php'); 41 require_once ('include/utils/DeleteUtils.php'); 42 require_once ('include/utils/SearchUtils.php'); 43 require_once ('include/FormValidationUtil.php'); 44 45 /** Function to return a full name 46 * @param $row -- row:: Type integer 47 * @param $first_column -- first column:: Type string 48 * @param $last_column -- last column:: Type string 49 * @returns $fullname -- fullname:: Type string 50 * 51 */ 52 function return_name(&$row, $first_column, $last_column) 53 { 54 global $log; 55 $log->debug("Entering return_name(".$row.",".$first_column.",".$last_column.") method ..."); 56 $first_name = ""; 57 $last_name = ""; 58 $full_name = ""; 59 60 if(isset($row[$first_column])) 61 { 62 $first_name = stripslashes($row[$first_column]); 63 } 64 65 if(isset($row[$last_column])) 66 { 67 $last_name = stripslashes($row[$last_column]); 68 } 69 70 $full_name = $first_name; 71 72 // If we have a first name and we have a last name 73 if($full_name != "" && $last_name != "") 74 { 75 // append a space, then the last name 76 $full_name .= " ".$last_name; 77 } 78 // If we have no first name, but we have a last name 79 else if($last_name != "") 80 { 81 // append the last name without the space. 82 $full_name .= $last_name; 83 } 84 85 $log->debug("Exiting return_name method ..."); 86 return $full_name; 87 } 88 89 /** Function to return language 90 * @returns $languages -- languages:: Type string 91 * 92 */ 93 94 function get_languages() 95 { 96 global $log; 97 $log->debug("Entering get_languages() method ..."); 98 global $languages; 99 $log->debug("Exiting get_languages method ..."); 100 return $languages; 101 } 102 103 /** Function to return language 104 * @param $key -- key:: Type string 105 * @returns $languages -- languages:: Type string 106 * 107 */ 108 109 //seems not used 110 function get_language_display($key) 111 { 112 global $log; 113 $log->debug("Entering get_language_display(".$key.") method ..."); 114 global $languages; 115 $log->debug("Exiting get_language_display method ..."); 116 return $languages[$key]; 117 } 118 119 /** Function returns the user array 120 * @param $assigned_user_id -- assigned_user_id:: Type string 121 * @returns $user_list -- user list:: Type array 122 * 123 */ 124 125 function get_assigned_user_name(&$assigned_user_id) 126 { 127 global $log; 128 $log->debug("Entering get_assigned_user_name(".$assigned_user_id.") method ..."); 129 $user_list = &get_user_array(false,""); 130 if(isset($user_list[$assigned_user_id])) 131 { 132 $log->debug("Exiting get_assigned_user_name method ..."); 133 return $user_list[$assigned_user_id]; 134 } 135 136 $log->debug("Exiting get_assigned_user_name method ..."); 137 return ""; 138 } 139 140 /** Function returns the user key in user array 141 * @param $add_blank -- boolean:: Type boolean 142 * @param $status -- user status:: Type string 143 * @param $assigned_user -- user id:: Type string 144 * @param $private -- sharing type:: Type string 145 * @returns $user_array -- user array:: Type array 146 * 147 */ 148 149 //used in module file 150 function get_user_array($add_blank=true, $status="Active", $assigned_user="",$private="") 151 { 152 global $log; 153 $log->debug("Entering get_user_array(".$add_blank.",". $status.",".$assigned_user.",".$private.") method ..."); 154 global $current_user; 155 if(isset($current_user) && $current_user->id != '') 156 { 157 require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); 158 require('user_privileges/user_privileges_'.$current_user->id.'.php'); 159 } 160 static $user_array = null; 161 $module=$_REQUEST['module']; 162 163 if($user_array == null) 164 { 165 require_once ('include/database/PearDatabase.php'); 166 $db = new PearDatabase(); 167 $temp_result = Array(); 168 // Including deleted vtiger_users for now. 169 if (empty($status)) { 170 $query = "SELECT id, user_name from vtiger_users"; 171 } 172 else { 173 if($private == 'private') 174 { 175 $log->debug("Sharing is Private. Only the current user should be listed"); 176 $query = "select id as id,user_name as user_name from vtiger_users where id=".$current_user->id." and status='Active' union select vtiger_user2role.userid as id,vtiger_users.user_name as user_name from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like '".$current_user_parent_role_seq."::%' and status='Active' union select shareduserid as id,vtiger_users.user_name as user_name from vtiger_tmp_write_user_sharing_per inner join vtiger_users on vtiger_users.id=vtiger_tmp_write_user_sharing_per.shareduserid where status='Active' and vtiger_tmp_write_user_sharing_per.userid=".$current_user->id." and vtiger_tmp_write_user_sharing_per.tabid=".getTabid($module); 177 178 } 179 else 180 { 181 $log->debug("Sharing is Public. All vtiger_users should be listed"); 182 $query = "SELECT id, user_name from vtiger_users WHERE status='$status'"; 183 } 184 } 185 if (!empty($assigned_user)) { 186 $query .= " OR id='$assigned_user'"; 187 } 188 189 $query .= " order by user_name ASC"; 190 191 $result = $db->query($query, true, "Error filling in user array: "); 192 193 if ($add_blank==true){ 194 // Add in a blank row 195 $temp_result[''] = ''; 196 } 197 198 // Get the id and the name. 199 while($row = $db->fetchByAssoc($result)) 200 { 201 $temp_result[$row['id']] = $row['user_name']; 202 } 203 204 $user_array = &$temp_result; 205 } 206 207 $log->debug("Exiting get_user_array method ..."); 208 return $user_array; 209 } 210 211 /** Function skips executing arbitary commands given in a string 212 * @param $string -- string:: Type string 213 * @param $maxlength -- maximun length:: Type integer 214 * @returns $string -- escaped string:: Type string 215 * 216 */ 217 218 function clean($string, $maxLength) 219 { 220 global $log; 221 $log->debug("Entering clean(".$string.",". $maxLength.") method ..."); 222 $string = substr($string, 0, $maxLength); 223 $log->debug("Exiting clean method ..."); 224 return escapeshellcmd($string); 225 } 226 227 /** 228 * Copy the specified request variable to the member variable of the specified object. 229 * Do no copy if the member variable is already set. 230 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 231 * All Rights Reserved. 232 * Contributor(s): ______________________________________.. 233 */ 234 function safe_map($request_var, & $focus, $always_copy = false) 235 { 236 global $log; 237 $log->debug("Entering safe_map(".$request_var.",".$focus.",".$always_copy.") method ..."); 238 safe_map_named($request_var, $focus, $request_var, $always_copy); 239 $log->debug("Exiting safe_map method ..."); 240 } 241 242 /** 243 * Copy the specified request variable to the member variable of the specified object. 244 * Do no copy if the member variable is already set. 245 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 246 * All Rights Reserved. 247 * Contributor(s): ______________________________________.. 248 */ 249 function safe_map_named($request_var, & $focus, $member_var, $always_copy) 250 { 251 global $log; 252 $log->debug("Entering safe_map_named(".$request_var.",".$focus.",".$member_var.",".$always_copy.") method ..."); 253 if (isset($_REQUEST[$request_var]) && ($always_copy || is_null($focus->$member_var))) { 254 $log->debug("safe map named called assigning '{$_REQUEST[$request_var]}' to $member_var"); 255 $focus->$member_var = $_REQUEST[$request_var]; 256 } 257 $log->debug("Exiting safe_map_named method ..."); 258 } 259 260 /** This function retrieves an application language file and returns the array of strings included in the $app_list_strings var. 261 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 262 * All Rights Reserved. 263 * Contributor(s): ______________________________________.. 264 * If you are using the current language, do not call this function unless you are loading it for the first time */ 265 266 function return_app_list_strings_language($language) 267 { 268 global $log; 269 $log->debug("Entering return_app_list_strings_language(".$language.") method ..."); 270 global $app_list_strings, $default_language, $log, $translation_string_prefix; 271 $temp_app_list_strings = $app_list_strings; 272 $language_used = $language; 273 274 @include("include/language/$language.lang.php"); 275 if(!isset($app_list_strings)) 276 { 277 $log->warn("Unable to find the application language file for language: ".$language); 278 require("include/language/$default_language.lang.php"); 279 $language_used = $default_language; 280 } 281 282 if(!isset($app_list_strings)) 283 { 284 $log->fatal("Unable to load the application language file for the selected language($language) or the default language($default_language)"); 285 $log->debug("Exiting return_app_list_strings_language method ..."); 286 return null; 287 } 288 289 290 $return_value = $app_list_strings; 291 $app_list_strings = $temp_app_list_strings; 292 293 $log->debug("Exiting return_app_list_strings_language method ..."); 294 return $return_value; 295 } 296 297 /** This function retrieves an application language file and returns the array of strings included. 298 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 299 * All Rights Reserved. 300 * Contributor(s): ______________________________________.. 301 * If you are using the current language, do not call this function unless you are loading it for the first time */ 302 function return_application_language($language) 303 { 304 global $log; 305 $log->debug("Entering return_application_language(".$language.") method ..."); 306 global $app_strings, $default_language, $log, $translation_string_prefix; 307 $temp_app_strings = $app_strings; 308 $language_used = $language; 309 310 @include("include/language/$language.lang.php"); 311 if(!isset($app_strings)) 312 { 313 $log->warn("Unable to find the application language file for language: ".$language); 314 require("include/language/$default_language.lang.php"); 315 $language_used = $default_language; 316 } 317 318 if(!isset($app_strings)) 319 { 320 $log->fatal("Unable to load the application language file for the selected language($language) or the default language($default_language)"); 321 $log->debug("Exiting return_application_language method ..."); 322 return null; 323 } 324 325 // If we are in debug mode for translating, turn on the prefix now! 326 if($translation_string_prefix) 327 { 328 foreach($app_strings as $entry_key=>$entry_value) 329 { 330 $app_strings[$entry_key] = $language_used.' '.$entry_value; 331 } 332 } 333 334 $return_value = $app_strings; 335 $app_strings = $temp_app_strings; 336 337 $log->debug("Exiting return_application_language method ..."); 338 return $return_value; 339 } 340 341 /** This function retrieves a module's language file and returns the array of strings included. 342 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 343 * All Rights Reserved. 344 * Contributor(s): ______________________________________.. 345 * If you are in the current module, do not call this function unless you are loading it for the first time */ 346 function return_module_language($language, $module) 347 { 348 global $log; 349 $log->debug("Entering return_module_language(".$language.",". $module.") method ..."); 350 global $mod_strings, $default_language, $log, $currentModule, $translation_string_prefix; 351 352 if($currentModule == $module && isset($mod_strings) && $mod_strings != null) 353 { 354 // We should have already loaded the array. return the current one. 355 $log->debug("Exiting return_module_language method ..."); 356 return $mod_strings; 357 } 358 359 $temp_mod_strings = $mod_strings; 360 $language_used = $language; 361 362 @include("modules/$module/language/$language.lang.php"); 363 if(!isset($mod_strings)) 364 { 365 $log->warn("Unable to find the module language file for language: ".$language." and module: ".$module); 366 require("modules/$module/language/$default_language.lang.php"); 367 $language_used = $default_language; 368 } 369 370 if(!isset($mod_strings)) 371 { 372 $log->fatal("Unable to load the module($module) language file for the selected language($language) or the default language($default_language)"); 373 $log->debug("Exiting return_module_language method ..."); 374 return null; 375 } 376 377 // If we are in debug mode for translating, turn on the prefix now! 378 if($translation_string_prefix) 379 { 380 foreach($mod_strings as $entry_key=>$entry_value) 381 { 382 $mod_strings[$entry_key] = $language_used.' '.$entry_value; 383 } 384 } 385 386 $return_value = $mod_strings; 387 $mod_strings = $temp_mod_strings; 388 389 $log->debug("Exiting return_module_language method ..."); 390 return $return_value; 391 } 392 393 /*This function returns the mod_strings for the current language and the specified module 394 */ 395 396 function return_specified_module_language($language, $module) 397 { 398 global $log; 399 global $default_language, $translation_string_prefix; 400 401 @include("modules/$module/language/$language.lang.php"); 402 if(!isset($mod_strings)) 403 { 404 $log->warn("Unable to find the module language file for language: ".$language." and module: ".$module); 405 require("modules/$module/language/$default_language.lang.php"); 406 $language_used = $default_language; 407 } 408 409 if(!isset($mod_strings)) 410 { 411 $log->fatal("Unable to load the module($module) language file for the selected language($language) or the default language($default_language)"); 412 $log->debug("Exiting return_module_language method ..."); 413 return null; 414 } 415 416 $return_value = $mod_strings; 417 418 $log->debug("Exiting return_module_language method ..."); 419 return $return_value; 420 } 421 422 /** This function retrieves an application language file and returns the array of strings included in the $mod_list_strings var. 423 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 424 * All Rights Reserved. 425 * Contributor(s): ______________________________________.. 426 * If you are using the current language, do not call this function unless you are loading it for the first time */ 427 function return_mod_list_strings_language($language,$module) 428 { 429 global $log; 430 $log->debug("Entering return_mod_list_strings_language(".$language.",".$module.") method ..."); 431 global $mod_list_strings, $default_language, $log, $currentModule,$translation_string_prefix; 432 433 $language_used = $language; 434 $temp_mod_list_strings = $mod_list_strings; 435 436 if($currentModule == $module && isset($mod_list_strings) && $mod_list_strings != null) 437 { 438 $log->debug("Exiting return_mod_list_strings_language method ..."); 439 return $mod_list_strings; 440 } 441 442 @include("modules/$module/language/$language.lang.php"); 443 444 if(!isset($mod_list_strings)) 445 { 446 $log->fatal("Unable to load the application list language file for the selected language($language) or the default language($default_language)"); 447 $log->debug("Exiting return_mod_list_strings_language method ..."); 448 return null; 449 } 450 451 $return_value = $mod_list_strings; 452 $mod_list_strings = $temp_mod_list_strings; 453 454 $log->debug("Exiting return_mod_list_strings_language method ..."); 455 return $return_value; 456 } 457 458 /** This function retrieves a theme's language file and returns the array of strings included. 459 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 460 * All Rights Reserved. 461 * Contributor(s): ______________________________________.. 462 */ 463 function return_theme_language($language, $theme) 464 { 465 global $log; 466 $log->debug("Entering return_theme_language(".$language.",". $theme.") method ..."); 467 global $mod_strings, $default_language, $log, $currentModule, $translation_string_prefix; 468 469 $language_used = $language; 470 471 @include("themes/$theme/language/$current_language.lang.php"); 472 if(!isset($theme_strings)) 473 { 474 $log->warn("Unable to find the theme file for language: ".$language." and theme: ".$theme); 475 require("themes/$theme/language/$default_language.lang.php"); 476 $language_used = $default_language; 477 } 478 479 if(!isset($theme_strings)) 480 { 481 $log->fatal("Unable to load the theme($theme) language file for the selected language($language) or the default language($default_language)"); 482 $log->debug("Exiting return_theme_language method ..."); 483 return null; 484 } 485 486 // If we are in debug mode for translating, turn on the prefix now! 487 if($translation_string_prefix) 488 { 489 foreach($theme_strings as $entry_key=>$entry_value) 490 { 491 $theme_strings[$entry_key] = $language_used.' '.$entry_value; 492 } 493 } 494 495 $log->debug("Exiting return_theme_language method ..."); 496 return $theme_strings; 497 } 498 499 500 501 /** If the session variable is defined and is not equal to "" then return it. Otherwise, return the default value. 502 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 503 * All Rights Reserved. 504 * Contributor(s): ______________________________________.. 505 */ 506 function return_session_value_or_default($varname, $default) 507 { 508 global $log; 509 $log->debug("Entering return_session_value_or_default(".$varname.",". $default.") method ..."); 510 if(isset($_SESSION[$varname]) && $_SESSION[$varname] != "") 511 { 512 $log->debug("Exiting return_session_value_or_default method ..."); 513 return $_SESSION[$varname]; 514 } 515 516 $log->debug("Exiting return_session_value_or_default method ..."); 517 return $default; 518 } 519 520 /** 521 * Creates an array of where restrictions. These are used to construct a where SQL statement on the query 522 * It looks for the variable in the $_REQUEST array. If it is set and is not "" it will create a where clause out of it. 523 * @param &$where_clauses - The array to append the clause to 524 * @param $variable_name - The name of the variable to look for an add to the where clause if found 525 * @param $SQL_name - [Optional] If specified, this is the SQL column name that is used. If not specified, the $variable_name is used as the SQL_name. 526 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 527 * All Rights Reserved. 528 * Contributor(s): ______________________________________.. 529 */ 530 function append_where_clause(&$where_clauses, $variable_name, $SQL_name = null) 531 { 532 global $log; 533 $log->debug("Entering append_where_clause(".$where_clauses.",".$variable_name.",".$SQL_name.") method ..."); 534 if($SQL_name == null) 535 { 536 $SQL_name = $variable_name; 537 } 538 539 if(isset($_REQUEST[$variable_name]) && $_REQUEST[$variable_name] != "") 540 { 541 array_push($where_clauses, "$SQL_name like '$_REQUEST[$variable_name]%'"); 542 } 543 $log->debug("Exiting append_where_clause method ..."); 544 } 545 546 /** 547 * Generate the appropriate SQL based on the where clauses. 548 * @param $where_clauses - An Array of individual where clauses stored as strings 549 * @returns string where_clause - The final SQL where clause to be executed. 550 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 551 * All Rights Reserved. 552 * Contributor(s): ______________________________________.. 553 */ 554 function generate_where_statement($where_clauses) 555 { 556 global $log; 557 $log->debug("Entering generate_where_statement(".$where_clauses.") method ..."); 558 $where = ""; 559 foreach($where_clauses as $clause) 560 { 561 if($where != "") 562 $where .= " and "; 563 $where .= $clause; 564 } 565 566 $log->info("Here is the where clause for the list view: $where"); 567 $log->debug("Exiting generate_where_statement method ..."); 568 return $where; 569 } 570 571 /** 572 * A temporary method of generating GUIDs of the correct format for our DB. 573 * @return String contianing a GUID in the format: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee 574 * 575 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 576 * All Rights Reserved. 577 * Contributor(s): ______________________________________.. 578 */ 579 function create_guid() 580 { 581 global $log; 582 $log->debug("Entering create_guid() method ..."); 583 $microTime = microtime(); 584 list($a_dec, $a_sec) = explode(" ", $microTime); 585 586 $dec_hex = sprintf("%x", $a_dec* 1000000); 587 $sec_hex = sprintf("%x", $a_sec); 588 589 ensure_length($dec_hex, 5); 590 ensure_length($sec_hex, 6); 591 592 $guid = ""; 593 $guid .= $dec_hex; 594 $guid .= create_guid_section(3); 595 $guid .= '-'; 596 $guid .= create_guid_section(4); 597 $guid .= '-'; 598 $guid .= create_guid_section(4); 599 $guid .= '-'; 600 $guid .= create_guid_section(4); 601 $guid .= '-'; 602 $guid .= $sec_hex; 603 $guid .= create_guid_section(6); 604 605 $log->debug("Exiting create_guid method ..."); 606 return $guid; 607 608 } 609 610 /** Function to create guid section for a given character 611 * @param $characters -- characters:: Type string 612 * @returns $return -- integer:: Type integer`` 613 */ 614 function create_guid_section($characters) 615 { 616 global $log; 617 $log->debug("Entering create_guid_section(".$characters.") method ..."); 618 $return = ""; 619 for($i=0; $i<$characters; $i++) 620 { 621 $return .= sprintf("%x", rand(0,15)); 622 } 623 $log->debug("Exiting create_guid_section method ..."); 624 return $return; 625 } 626 627 /** Function to ensure length 628 * @param $string -- string:: Type string 629 * @param $length -- length:: Type string 630 */ 631 632 function ensure_length(&$string, $length) 633 { 634 global $log; 635 $log->debug("Entering ensure_length(".$string.",". $length.") method ..."); 636 $strlen = strlen($string); 637 if($strlen < $length) 638 { 639 $string = str_pad($string,$length,"0"); 640 } 641 else if($strlen > $length) 642 { 643 $string = substr($string, 0, $length); 644 } 645 $log->debug("Exiting ensure_length method ..."); 646 } 647 /* 648 function microtime_diff($a, $b) { 649 global $log; 650 $log->debug("Entering microtime_diff(".$a.",". $b.") method ..."); 651 list($a_dec, $a_sec) = explode(" ", $a); 652 list($b_dec, $b_sec) = explode(" ", $b); 653 $log->debug("Exiting microtime_diff method ..."); 654 return $b_sec - $a_sec + $b_dec - $a_dec; 655 } 656 */ 657 658 /** 659 * Return the display name for a theme if it exists. 660 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 661 * All Rights Reserved. 662 * Contributor(s): ______________________________________.. 663 */ 664 function get_theme_display($theme) { 665 global $log; 666 $log->debug("Entering get_theme_display(".$theme.") method ..."); 667 global $theme_name, $theme_description; 668 $temp_theme_name = $theme_name; 669 $temp_theme_description = $theme_description; 670 671 if (is_file("./themes/$theme/config.php")) { 672 @include("./themes/$theme/config.php"); 673 $return_theme_value = $theme_name; 674 } 675 else { 676 $return_theme_value = $theme; 677 } 678 $theme_name = $temp_theme_name; 679 $theme_description = $temp_theme_description; 680 681 $log->debug("Exiting get_theme_display method ..."); 682 return $return_theme_value; 683 } 684 685 /** 686 * Return an array of directory names. 687 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 688 * All Rights Reserved. 689 * Contributor(s): ______________________________________.. 690 */ 691 function get_themes() { 692 global $log; 693 $log->debug("Entering get_themes() method ..."); 694 if ($dir = @opendir("./themes")) { 695 while (($file = readdir($dir)) !== false) { 696 if ($file != ".." && $file != "." && $file != "CVS" && $file != "Attic" && $file != "akodarkgem" && $file != "bushtree" && $file != "coolblue" && $file != "Amazon" && $file != "busthree" && $file != "Aqua" && $file != "nature" && $file != "orange" && $file != "blue") { 697 if(is_dir("./themes/".$file)) { 698 if(!($file[0] == '.')) { 699 // set the initial theme name to the filename 700 $name = $file; 701 702 // if there is a configuration class, load that. 703 if(is_file("./themes/$file/config.php")) 704 { 705 require_once("./themes/$file/config.php"); 706 $name = $theme_name; 707 } 708 709 if(is_file("./themes/$file/header.php")) 710 { 711 $filelist[$file] = $name; 712 } 713 } 714 } 715 } 716 } 717 closedir($dir); 718 } 719 720 ksort($filelist); 721 $log->debug("Exiting get_themes method ..."); 722 return $filelist; 723 } 724 725 726 727 /** 728 * Create javascript to clear values of all elements in a form. 729 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 730 * All Rights Reserved. 731 * Contributor(s): ______________________________________.. 732 */ 733 function get_clear_form_js () { 734 global $log; 735 $log->debug("Entering get_clear_form_js () method ..."); 736 $the_script = <<<EOQ 737 <script type="text/javascript" language="JavaScript"> 738 <!-- Begin 739 function clear_form(form) { 740 for (j = 0; j < form.elements.length; j++) { 741 if (form.elements[j].type == 'text' || form.elements[j].type == 'select-one') { 742 form.elements[j].value = ''; 743 } 744 } 745 } 746 // End --> 747 </script> 748 EOQ; 749 750 $log->debug("Exiting get_clear_form_js method ..."); 751 return $the_script; 752 } 753 754 /** 755 * Create javascript to set the cursor focus to specific vtiger_field in a form 756 * when the screen is rendered. The vtiger_field name is currently hardcoded into the 757 * the function. 758 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 759 * All Rights Reserved. 760 * Contributor(s): ______________________________________.. 761 */ 762 function get_set_focus_js () { 763 global $log; 764 $log->debug("Entering set_focus() method ..."); 765 //TODO Clint 5/20 - Make this function more generic so that it can take in the target form and vtiger_field names as variables 766 $the_script = <<<EOQ 767 <script type="text/javascript" language="JavaScript"> 768 <!-- Begin 769 function set_focus() { 770 if (document.forms.length > 0) { 771 for (i = 0; i < document.forms.length; i++) { 772 for (j = 0; j < document.forms[i].elements.length; j++) { 773 var vtiger_field = document.forms[i].elements[j]; 774 if ((vtiger_field.type == "text" || vtiger_field.type == "textarea" || vtiger_field.type == "password") && 775 !field.disabled && (vtiger_field.name == "first_name" || vtiger_field.name == "name")) { 776 vtiger_field.focus(); 777 if (vtiger_field.type == "text") { 778 vtiger_field.select(); 779 } 780 break; 781 } 782 } 783 } 784 } 785 } 786 // End --> 787 </script> 788 EOQ; 789 790 $log->debug("Exiting get_set_focus_js method ..."); 791 return $the_script; 792 } 793 794 /** 795 * Very cool algorithm for sorting multi-dimensional arrays. Found at http://us2.php.net/manual/en/function.array-multisort.php 796 * Syntax: $new_array = array_csort($array [, 'col1' [, SORT_FLAG [, SORT_FLAG]]]...); 797 * Explanation: $array is the array you want to sort, 'col1' is the name of the column 798 * you want to sort, SORT_FLAGS are : SORT_ASC, SORT_DESC, SORT_REGULAR, SORT_NUMERIC, SORT_STRING 799 * you can repeat the 'col',FLAG,FLAG, as often you want, the highest prioritiy is given to 800 * the first - so the array is sorted by the last given column first, then the one before ... 801 * Example: $array = array_csort($array,'town','age',SORT_DESC,'name'); 802 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. 803 * All Rights Reserved. 804 * Contributor(s): ______________________________________.. 805 */ 806 function array_csort() { 807 global $log; 808 $log->debug("Entering array_csort() method ..."); 809 $args = func_get_args(); 810 $marray = array_shift($args); 811 $i = 0; 812 813 $msortline = "return(array_multisort("; 814 foreach ($args as $arg) { 815 $i++; 816 if (is_string($arg)) { 817 foreach ($marray as $row) { 818 $sortarr[$i][] = $row[$arg]; 819 } 820 } else { 821 $sortarr[$i] = $arg; 822 } 823 $msortline .= "\$sortarr[".$i."],"; 824 } 825 $msortline .= "\$marray));"; 826 827 eval($msortline); 828 $log->debug("Exiting array_csort method ..."); 829 return $marray; 830 } 831 832 /** Function to set default varibles on to the global variable 833 * @param $defaults -- default values:: Type array 834 */ 835 function set_default_config(&$defaults) 836 { 837 global $log; 838 $log->debug("Entering set_default_config(".$defaults.") method ..."); 839 840 foreach ($defaults as $name=>$value) 841 { 842 if ( ! isset($GLOBALS[$name]) ) 843 { 844 $GLOBALS[$name] = $value; 845 } 846 } 847 $log->debug("Exiting set_default_config method ..."); 848 } 849 850 $toHtml = array( 851 '"' => '"', 852 '<' => '<', 853 '>' => '>', 854 '& ' => '& ', 855 "'" => ''', 856 ); 857 858 /** Function to convert the given string to html 859 * @param $string -- string:: Type string 860 * @param $ecnode -- boolean:: Type boolean 861 * @returns $string -- string:: Type string 862 * 863 */ 864 function to_html($string, $encode=true){ 865 global $log; 866 $log->debug("Entering to_html(".$string.",".$encode.") method ..."); 867 global $toHtml; 868 if($encode && is_string($string)){//$string = htmlentities($string, ENT_QUOTES); 869 if (is_array($toHtml)) 870 $string = str_replace(array_keys($toHtml), array_values($toHtml), $string); 871 } 872 $log->debug("Exiting to_html method ..."); 873 return $string; 874 } 875 876 /** Function to get the assigned user name or group name 877 * @param $id -- user id:: Type integer 878 * @param $module -- module name:: Type string 879 * @returns $string -- string:: Type string 880 * 881 */ 882 883 //it seems the fun ction is not used 884 function get_assigned_user_or_group_name($id,$module) 885 { 886 global $log; 887 $log->debug("Entering get_assigned_user_or_group_name(".$id.",".$module.") method ..."); 888 global $adb; 889 890 //it might so happen that an entity is assigned to a group but at that time the group has no members. even in this case, the query should return a valid value and not just blank 891 892 if($module == 'Leads') 893 { 894 895 $sql="select (case when (user_name is null) then (vtiger_leadgrouprelation.groupname) else (user_name) end) as name from leads left join vtiger_users on vtiger_users.id= assigned_user_id left join vtiger_leadgrouprelation on vtiger_leadgrouprelation.leadid=leads.id where leads.deleted=0 and leads.id='". $id ."'"; 896 897 } 898 else if($module == 'Tasks') 899 { 900 $sql="select (case when (user_name is null) then (taskgrouprelation.groupname) else (user_name) end) as name from tasks left join vtiger_users on vtiger_users.id= assigned_user_id left join taskgrouprelation on taskgrouprelation.taskid=tasks.id where tasks.deleted=0 and tasks.id='". $id ."'"; 901 } 902 else if($module == 'Calls') 903 { 904 $sql="select (case when (user_name is null) then (callgrouprelation.groupname) else (user_name) end) as name from calls left join vtiger_users on vtiger_users.id= assigned_user_id left join callgrouprelation on callgrouprelation.callid=calls.id where calls.deleted=0 and calls.id='". $id ."'"; 905 } 906 907 $result = $adb->query($sql); 908 $tempval = $adb->fetch_row($result); 909 $log->debug("Exiting get_assigned_user_or_group_name method ..."); 910 return $tempval[0]; 911 } 912 913 /** Function to get the tabname for a given id 914 * @param $tabid -- tab id:: Type integer 915 * @returns $string -- string:: Type string 916 * 917 */ 918 919 function getTabname($tabid) 920 { 921 global $log; 922 $log->debug("Entering getTabname(".$tabid.") method ..."); 923 $log->info("tab id is ".$tabid); 924 global $adb; 925 $sql = "select tablabel from vtiger_tab where tabid='".$tabid."'"; 926 $result = $adb->query($sql); 927 $tabname= $adb->query_result($result,0,"tablabel"); 928 $log->debug("Exiting getTabname method ..."); 929 return $tabname; 930 931 } 932 933 /** Function to get the tab module name for a given id 934 * @param $tabid -- tab id:: Type integer 935 * @returns $string -- string:: Type string 936 * 937 */ 938 939 function getTabModuleName($tabid) 940 { 941 global $log; 942 $log->debug("Entering getTabModuleName(".$tabid.") method ..."); 943 if (file_exists('tabdata.php') && (filesize('tabdata.php') != 0)) 944 { 945 include ('tabdata.php'); 946 $tabname = array_search($tabid,$tab_info_array); 947 } 948 else 949 { 950 global $log; 951 $log->info("tab id is ".$tabid); 952 global $adb; 953 $sql = "select name from vtiger_tab where tabid='".$tabid."'"; 954 $result = $adb->query($sql); 955 $tabname= $adb->query_result($result,0,"name"); 956 } 957 $log->debug("Exiting getTabModuleName method ..."); 958 return $tabname; 959 } 960 961 /** Function to get column fields for a given module 962 * @param $module -- module:: Type string 963 * @returns $column_fld -- column field :: Type array 964 * 965 */ 966 967 function getColumnFields($module) 968 { 969 global $log; 970 $log->debug("Entering getColumnFields(".$module.") method ..."); 971 $log->info("in getColumnFields ".$module); 972 global $adb; 973 $column_fld = Array(); 974 $tabid = getTabid($module); 975 $sql = "select * from vtiger_field where tabid=".$tabid; 976 $result = $adb->query($sql); 977 $noofrows = $adb->num_rows($result); 978 for($i=0; $i<$noofrows; $i++) 979 { 980 $fieldname = $adb->query_result($result,$i,"fieldname"); 981 $column_fld[$fieldname] = ''; 982 } 983 $log->debug("Exiting getColumnFields method ..."); 984 return $column_fld; 985 } 986 987 /** Function to get a users's mail id 988 * @param $userid -- userid :: Type integer 989 * @returns $email -- email :: Type string 990 * 991 */ 992 993 function getUserEmail($userid) 994 { 995 global $log; 996 $log->debug("Entering getUserEmail(".$userid.") method ..."); 997 $log->info("in getUserEmail ".$userid); 998 999 global $adb; 1000 if($userid != '') 1001 { 1002 $sql = "select email1 from vtiger_users where id=".$userid; 1003 $result = $adb->query($sql); 1004 $email = $adb->query_result($result,0,"email1"); 1005 } 1006 $log->debug("Exiting getUserEmail method ..."); 1007 return $email; 1008 } 1009 1010 /** Function to get a userid for outlook 1011 * @param $username -- username :: Type string 1012 * @returns $user_id -- user id :: Type integer 1013 */ 1014 1015 //outlook security 1016 function getUserId_Ol($username) 1017 { 1018 global $log; 1019 $log->debug("Entering getUserId_Ol(".$username.") method ..."); 1020 $log->info("in getUserId_Ol ".$username); 1021 1022 global $adb; 1023 $sql = "select id from vtiger_users where user_name='".$username."'"; 1024 $result = $adb->query($sql); 1025 $num_rows = $adb->num_rows($result); 1026 if($num_rows > 0) 1027 { 1028 $user_id = $adb->query_result($result,0,"id"); 1029 } 1030 else 1031 { 1032 $user_id = 0; 1033 } 1034 $log->debug("Exiting getUserId_Ol method ..."); 1035 return $user_id; 1036 } 1037 1038 1039 /** Function to get a action id for a given action name 1040 * @param $action -- action name :: Type string 1041 * @returns $actionid -- action id :: Type integer 1042 */ 1043 1044 //outlook security 1045 1046 function getActionid($action) 1047 { 1048 global $log; 1049 $log->debug("Entering getActionid(".$action.") method ..."); 1050 global $adb; 1051 $log->info("get Actionid ".$action); 1052 $actionid = ''; 1053 if(file_exists('tabdata.php') && (filesize('tabdata.php') != 0)) 1054 { 1055 include ('tabdata.php'); 1056 $actionid= $action_id_array[$action]; 1057 } 1058 else 1059 { 1060 $query="select * from vtiger_actionmapping where actionname='".$action."'"; 1061 $result =$adb->query($query); 1062 $actionid=$adb->query_result($result,0,'actionid'); 1063 1064 } 1065 $log->info("action id selected is ".$actionid ); 1066 $log->debug("Exiting getActionid method ..."); 1067 return $actionid; 1068 } 1069 1070 /** Function to get a action for a given action id 1071 * @param $action id -- action id :: Type integer 1072 * @returns $actionname-- action name :: Type string 1073 */ 1074 1075 1076 function getActionname($actionid) 1077 { 1078 global $log; 1079 $log->debug("Entering getActionname(".$actionid.") method ..."); 1080 global $adb; 1081 1082 $actionname=''; 1083 1084 if (file_exists('tabdata.php') && (filesize('tabdata.php') != 0)) 1085 { 1086 include ('tabdata.php'); 1087 $actionname= $action_name_array[$actionid]; 1088 } 1089 else 1090 { 1091 1092 $query="select * from vtiger_actionmapping where actionid=".$actionid ." and securitycheck=0"; 1093 $result =$adb->query($query); 1094 $actionname=$adb->query_result($result,0,"actionname"); 1095 } 1096 $log->debug("Exiting getActionname method ..."); 1097 return $actionname; 1098 } 1099 1100 /** Function to get a assigned user id for a given entity 1101 * @param $record -- entity id :: Type integer 1102 * @returns $user_id -- user id :: Type integer 1103 */ 1104 1105 function getUserId($record) 1106 { 1107 global $log; 1108 $log->debug("Entering getUserId(".$record.") method ..."); 1109 $log->info("in getUserId ".$record); 1110 1111 global $adb; 1112 $user_id=$adb->query_result($adb->query("select * from vtiger_crmentity where crmid = ".$record),0,'smownerid'); 1113 $log->debug("Exiting getUserId method ..."); 1114 return $user_id; 1115 } 1116 1117 /** Function to get a user id or group id for a given entity 1118 * @param $record -- entity id :: Type integer 1119 * @returns $ownerArr -- owner id :: Type array 1120 */ 1121 1122 function getRecordOwnerId($record) 1123 { 1124 global $log; 1125 $log->debug("Entering getRecordOwnerId(".$record.") method ..."); 1126 1127 global $adb; 1128 $ownerArr=Array(); 1129 $query="select * from vtiger_crmentity where crmid = ".$record; 1130 $result=$adb->query($query); 1131 $user_id=$adb->query_result($result,0,'smownerid'); 1132 if($user_id != 0) 1133 { 1134 $ownerArr['Users']=$user_id; 1135 1136 } 1137 elseif($user_id == 0) 1138 { 1139 $module=$adb->query_result($result,0,'setype'); 1140 if($module == 'Leads') 1141 { 1142 $query1="select vtiger_groups.groupid from vtiger_leadgrouprelation inner join vtiger_groups on vtiger_groups.groupname = vtiger_leadgrouprelation.groupname where leadid=".$record; 1143 } 1144 elseif($module == 'Calendar' || $module == 'Emails') 1145 { 1146 1147 $query1="select vtiger_groups.groupid from vtiger_activitygrouprelation inner join vtiger_groups on vtiger_groups.groupname = vtiger_activitygrouprelation.groupname where activityid=".$record; 1148 } 1149 elseif($module == 'HelpDesk') 1150 { 1151 $query1="select vtiger_groups.groupid from vtiger_ticketgrouprelation inner join vtiger_groups on vtiger_groups.groupname = vtiger_ticketgrouprelation.groupname where ticketid=".$record; 1152 } 1153 elseif($module == 'Accounts') 1154 { 1155 $query1="select vtiger_groups.groupid from vtiger_accountgrouprelation inner join vtiger_groups on vtiger_groups.groupname = vtiger_accountgrouprelation.groupname where accountid=".$record; 1156 } 1157 elseif($module == 'Contacts') 1158 { 1159 $query1="select vtiger_groups.groupid from vtiger_contactgrouprelation inner join vtiger_groups on vtiger_groups.groupname = vtiger_contactgrouprelation.groupname where contactid=".$record; 1160 } 1161 elseif($module == 'Potentials') 1162 { 1163 $query1="select vtiger_groups.groupid from vtiger_potentialgrouprelation inner join vtiger_groups on vtiger_groups.groupname = vtiger_potentialgrouprelation.groupname where potentialid=".$record; 1164 } 1165 elseif($module == 'Quotes') 1166 { 1167 $query1="select vtiger_groups.groupid from vtiger_quotegrouprelation inner join vtiger_groups on vtiger_groups.groupname = vtiger_quotegrouprelation.groupname where quoteid=".$record; 1168 } 1169 elseif($module == 'PurchaseOrder') 1170 { 1171 $query1="select vtiger_groups.groupid from vtiger_pogrouprelation inner join vtiger_groups on vtiger_groups.groupname = vtiger_pogrouprelation.groupname where purchaseorderid=".$record; 1172 } 1173 elseif($module == 'SalesOrder') 1174 { 1175 $query1="select vtiger_groups.groupid from vtiger_sogrouprelation inner join vtiger_groups on vtiger_groups.groupname = vtiger_sogrouprelation.groupname where salesorderid=".$record; 1176 } 1177 elseif($module == 'Invoice') 1178 { 1179 $query1="select vtiger_groups.groupid from vtiger_invoicegrouprelation inner join vtiger_groups on vtiger_groups.groupname = vtiger_invoicegrouprelation.groupname where invoiceid=".$record; 1180 } 1181 elseif($module == 'Campaigns') 1182 { 1183 $query1="select vtiger_groups.groupid from vtiger_campaigngrouprelation inner join vtiger_groups on vtiger_groups.groupname = vtiger_campaigngrouprelation.groupname where campaignid=".$record; 1184 } 1185 1186 $result1=$adb->query($query1); 1187 $groupid=$adb->query_result($result1,0,'groupid'); 1188 $ownerArr['Groups']=$groupid; 1189 1190 } 1191 $log->debug("Exiting getRecordOwnerId method ..."); 1192 return $ownerArr; 1193 1194 } 1195 1196 /** Function to insert value to profile2field table 1197 * @param $profileid -- profileid :: Type integer 1198 */ 1199 1200 1201 function insertProfile2field($profileid) 1202 { 1203 global $log; 1204 $log->debug("Entering insertProfile2field(".$profileid.") method ..."); 1205 $log->info("in insertProfile2field ".$profileid); 1206 1207 global $adb; 1208 $adb->database->SetFetchMode(ADODB_FETCH_ASSOC); 1209 $fld_result = $adb->query("select * from vtiger_field where generatedtype=1 and displaytype in (1,2) and tabid != 29"); 1210 $num_rows = $adb->num_rows($fld_result); 1211 for($i=0; $i<$num_rows; $i++) 1212 { 1213 $tab_id = $adb->query_result($fld_result,$i,'tabid'); 1214 $field_id = $adb->query_result($fld_result,$i,'fieldid'); 1215 $adb->query("insert into vtiger_profile2field values (".$profileid.",".$tab_id.",".$field_id.",0,1)"); 1216 } 1217 $log->debug("Exiting insertProfile2field method ..."); 1218 } 1219 1220 /** Function to insert into default org field 1221 */ 1222 1223 function insert_def_org_field() 1224 { 1225 global $log; 1226 $log->debug("Entering insert_def_org_field() method ..."); 1227 global $adb; 1228 $adb->database->SetFetchMode(ADODB_FETCH_ASSOC); 1229 $fld_result = $adb->query("select * from vtiger_field where generatedtype=1 and displaytype in (1,2) and tabid != 29"); 1230 $num_rows = $adb->num_rows($fld_result); 1231 for($i=0; $i<$num_rows; $i++) 1232 { 1233 $tab_id = $adb->query_result($fld_result,$i,'tabid'); 1234 $field_id = $adb->query_result($fld_result,$i,'fieldid'); 1235 $adb->query("insert into vtiger_def_org_field values (".$tab_id.",".$field_id.",0,1)"); 1236 } 1237 $log->debug("Exiting insert_def_org_field() method ..."); 1238 } 1239 1240 /** Function to insert value to profile2field table 1241 * @param $fld_module -- field module :: Type string 1242 * @param $profileid -- profileid :: Type integer 1243 * @returns $result -- result :: Type string 1244 */ 1245 1246 function getProfile2FieldList($fld_module, $profileid) 1247 { 1248 global $log; 1249 $log->debug("Entering getProfile2FieldList(".$fld_module.",". $profileid.") method ..."); 1250 $log->info("in getProfile2FieldList ".$fld_module. ' vtiger_profile id is '.$profileid); 1251 1252 global $adb; 1253 $tabid = getTabid($fld_module); 1254 1255 $query = "select vtiger_profile2field.visible,vtiger_field.* from vtiger_profile2field inner join vtiger_field on vtiger_field.fieldid=vtiger_profile2field.fieldid where vtiger_profile2field.profileid=".$profileid." and vtiger_profile2field.tabid=".$tabid; 1256 $result = $adb->query($query); 1257 $log->debug("Exiting getProfile2FieldList method ..."); 1258 return $result; 1259 } 1260 1261 /** Function to insert value to profile2fieldPermissions table 1262 * @param $fld_module -- field module :: Type string 1263 * @param $profileid -- profileid :: Type integer 1264 * @returns $return_data -- return_data :: Type string 1265 */ 1266 1267 //added by jeri 1268 1269 function getProfile2FieldPermissionList($fld_module, $profileid) 1270 { 1271 global $log; 1272 $log->debug("Entering getProfile2FieldPermissionList(".$fld_module.",". $profileid.") method ..."); 1273 $log->info("in getProfile2FieldList ".$fld_module. ' vtiger_profile id is '.$profileid); 1274 1275 global $adb; 1276 $tabid = getTabid($fld_module); 1277 1278 $query = "select vtiger_profile2field.visible,vtiger_field.* from vtiger_profile2field inner join vtiger_field on vtiger_field.fieldid=vtiger_profile2field.fieldid where vtiger_profile2field.profileid=".$profileid." and vtiger_profile2field.tabid=".$tabid; 1279 $result = $adb->query($query); 1280 $return_data=array(); 1281 for($i=0; $i<$adb->num_rows($result); $i++) 1282 { 1283 $return_data[]=array($adb->query_result($result,$i,"fieldlabel"),$adb->query_result($result,$i,"visible"),$adb->query_result($result,$i,"uitype"),$adb->query_result($result,$i,"visible"),$adb->query_result($result,$i,"fieldid")); 1284 } 1285 $log->debug("Exiting getProfile2FieldPermissionList method ..."); 1286 return $return_data; 1287 } 1288 1289 /** Function to getProfile2allfieldsListinsert value to profile2fieldPermissions table 1290 * @param $mod_array -- mod_array :: Type string 1291 * @param $profileid -- profileid :: Type integer 1292 * @returns $profilelist -- profilelist :: Type string 1293 */ 1294 1295 function getProfile2AllFieldList($mod_array,$profileid) 1296 { 1297 global $log; 1298 $log->debug("Entering getProfile2AllFieldList(".$mod_array.",".$profileid.") method ..."); 1299 $log->info("in getProfile2AllFieldList vtiger_profile id is " .$profileid); 1300 1301 global $adb; 1302 $profilelist=array(); 1303 for($i=0;$i<count($mod_array);$i++) 1304 { 1305 $profilelist[key($mod_array)]=getProfile2FieldPermissionList(key($mod_array), $profileid); 1306 next($mod_array); 1307 } 1308 $log->debug("Exiting getProfile2AllFieldList method ..."); 1309 return $profilelist; 1310 } 1311 1312 /** Function to getdefaultfield organisation list for a given module 1313 * @param $fld_module -- module name :: Type string 1314 * @returns $result -- string :: Type object 1315 */ 1316 1317 //end of fn added by jeri 1318 1319 function getDefOrgFieldList($fld_module) 1320 { 1321 global $log; 1322 $log->debug("Entering getDefOrgFieldList(".$fld_module.") method ..."); 1323 $log->info("in getDefOrgFieldList ".$fld_module); 1324 1325 global $adb; 1326 $tabid = getTabid($fld_module); 1327 1328 $query = "select vtiger_def_org_field.visible,vtiger_field.* from vtiger_def_org_field inner join vtiger_field on vtiger_field.fieldid=vtiger_def_org_field.fieldid where vtiger_def_org_field.tabid=".$tabid; 1329 $result = $adb->query($query); 1330 $log->debug("Exiting getDefOrgFieldList method ..."); 1331 return $result; 1332 } 1333 1334 /** Function to getQuickCreate for a given tabid 1335 * @param $tabid -- tab id :: Type string 1336 * @param $actionid -- action id :: Type integer 1337 * @returns $QuickCreateForm -- QuickCreateForm :: Type boolean 1338 */ 1339 1340 function getQuickCreate($tabid,$actionid) 1341 { 1342 global $log; 1343 $log->debug("Entering getQuickCreate(".$tabid.",".$actionid.") method ..."); 1344 $module=getTabModuleName($tabid); 1345 $actionname=getActionname($actionid); 1346 $QuickCreateForm= 'true'; 1347 1348 $perr=isPermitted($module,$actionname); 1349 if($perr = 'no') 1350 { 1351 $QuickCreateForm= 'false'; 1352 } 1353 $log->debug("Exiting getQuickCreate method ..."); 1354 return $QuickCreateForm; 1355 1356 } 1357 1358 /** Function to getQuickCreate for a given tabid 1359 * @param $tabid -- tab id :: Type string 1360 * @param $actionid -- action id :: Type integer 1361 * @returns $QuickCreateForm -- QuickCreateForm :: Type boolean 1362 */ 1363 1364 function ChangeStatus($status,$activityid,$activity_mode='') 1365 { 1366 global $log; 1367 $log->debug("Entering ChangeStatus(".$status.",".$activityid.",".$activity_mode."='') method ..."); 1368 $log->info("in ChangeStatus ".$status. ' vtiger_activityid is '.$activityid); 1369 1370 global $adb; 1371 if ($activity_mode == 'Task') 1372 { 1373 $query = "Update vtiger_activity set status='".$status."' where activityid = ".$activityid; 1374 } 1375 elseif ($activity_mode == 'Events') 1376 { 1377 $query = "Update vtiger_activity set eventstatus='".$status."' where activityid = ".$activityid; 1378 } 1379 if($query) { 1380 $adb->query($query); 1381 } 1382 $log->debug("Exiting ChangeStatus method ..."); 1383 } 1384 1385 /** Function to set date values compatible to database (YY_MM_DD) 1386 * @param $value -- value :: Type string 1387 * @returns $insert_date -- insert_date :: Type string 1388 */ 1389 1390 function getDBInsertDateValue($value) 1391 { 1392 global $log; 1393 $log->debug("Entering getDBInsertDateValue(".$value.") method ..."); 1394 global $current_user; 1395 $dat_fmt = $current_user->date_format; 1396 if($dat_fmt == '') 1397 { 1398 $dat_fmt = 'dd-mm-yyyy'; 1399 } 1400 $insert_date=''; 1401 if($dat_fmt == 'dd-mm-yyyy') 1402 { 1403 list($d,$m,$y) = split('-',$value); 1404 } 1405 elseif($dat_fmt == 'mm-dd-yyyy') 1406 { 1407 list($m,$d,$y) = split('-',$value); 1408 } 1409 elseif($dat_fmt == 'yyyy-mm-dd') 1410 { 1411 list($y,$m,$d) = split('-',$value); 1412 } 1413 1414 if(!$y && !$m && !$d) { 1415 $insert_date = ''; 1416 } else { 1417 $insert_date=$y.'-'.$m.'-'.$d; 1418 } 1419 $log->debug("Exiting getDBInsertDateValue method ..."); 1420 return $insert_date; 1421 } 1422 1423 /** Function to get unitprice for a given product id 1424 * @param $productid -- product id :: Type integer 1425 * @returns $up -- up :: Type string 1426 */ 1427 1428 function getUnitPrice($productid) 1429 { 1430 global $log,$current_user; 1431 $currencyid=fetchCurrency($current_user->id); 1432 $rate_symbol = getCurrencySymbolandCRate($currencyid); 1433 $rate = $rate_symbol['rate']; 1434 $log->debug("Entering getUnitPrice(".$productid.") method ..."); 1435 $log->info("in getUnitPrice productid ".$productid); 1436 1437 global $adb; 1438 $query = "select unit_price from vtiger_products where productid=".$productid; 1439 $result = $adb->query($query); 1440 $up = $adb->query_result($result,0,'unit_price'); 1441 $up = convertFromDollar($up,$rate); 1442 $log->debug("Exiting getUnitPrice method ..."); 1443 return $up; 1444 } 1445 1446 /** Function to upload product image file 1447 * @param $mode -- mode :: Type string 1448 * @param $id -- id :: Type integer 1449 * @returns $ret_array -- return array:: Type array 1450 */ 1451 1452 function upload_product_image_file($mode,$id) 1453 { 1454 global $log; 1455 $log->debug("Entering upload_product_image_file(".$mode.",".$id.") method ..."); 1456 global $root_directory; 1457 $log->debug("Inside upload_product_image_file. The id is ".$id); 1458 $uploaddir = $root_directory ."/test/product/"; 1459 1460 $file_path_name = $_FILES['imagename']['name']; 1461 $file_name = basename($file_path_name); 1462 $file_name = $id.'_'.$file_name; 1463 $filetype= $_FILES['imagename']['type']; 1464 $filesize = $_FILES['imagename']['size']; 1465 1466 $ret_array = Array(); 1467 1468 if($filesize > 0) 1469 { 1470 1471 if(move_uploaded_file($_FILES["imagename"]["tmp_name"],$uploaddir.$file_name)) 1472 { 1473 1474 $upload_status = "yes"; 1475 $ret_array["status"] = $upload_status; 1476 $ret_array["file_name"] = $file_name; 1477 1478 1479 } 1480 else 1481 { 1482 $errorCode = $_FILES['imagename']['error']; 1483 $upload_status = "no"; 1484 $ret_array["status"] = $upload_status; 1485 $ret_array["errorcode"] = $errorCode; 1486 1487 1488 } 1489 1490 } 1491 else 1492 { 1493 $upload_status = "no"; 1494 $ret_array["status"] = $upload_status; 1495 } 1496 $log->debug("Exiting upload_product_image_file method ..."); 1497 return $ret_array; 1498 1499 } 1500 1501 /** Function to upload product image file 1502 * @param $id -- id :: Type integer 1503 * @param $deleted_array -- images to be deleted :: Type array 1504 * @returns $imagename -- imagelist:: Type array 1505 */ 1506 1507 function getProductImageName($id,$deleted_array='') 1508 { 1509 global $log; 1510 $log->debug("Entering getProductImageName(".$id.",".$deleted_array."='') method ..."); 1511 global $adb; 1512 $image_array=array(); 1513 $query = "select imagename from vtiger_products where productid=".$id; 1514 $result = $adb->query($query); 1515 $image_name = $adb->query_result($result,0,"imagename"); 1516 $image_array=explode("###",$image_name); 1517 $log->debug("Inside getProductImageName. The image_name is ".$image_name); 1518 if($deleted_array!='') 1519 { 1520 $resultant_image = array(); 1521 $resultant_image=array_merge(array_diff($image_array,$deleted_array)); 1522 $imagelists=implode('###',$resultant_image); 1523 $log->debug("Exiting getProductImageName method ..."); 1524 return $imagelists; 1525 } 1526 else 1527 { 1528 $log->debug("Exiting getProductImageName method ..."); 1529 return $image_name; 1530 } 1531 } 1532 1533 /** Function to get Contact images 1534 * @param $id -- id :: Type integer 1535 * @returns $imagename -- imagename:: Type string 1536 */ 1537 1538 function getContactImageName($id) 1539 { 1540 global $log; 1541 $log->debug("Entering getContactImageName(".$id.") method ..."); 1542 global $adb; 1543 $query = "select imagename from vtiger_contactdetails where contactid=".$id; 1544 $result = $adb->query($query); 1545 $image_name = $adb->query_result($result,0,"imagename"); 1546 $log->debug("Inside getContactImageName. The image_name is ".$image_name); 1547 $log->debug("Exiting getContactImageName method ..."); 1548 return $image_name; 1549 1550 } 1551 1552 /** Function to update sub total in inventory 1553 * @param $module -- module name :: Type string 1554 * @param $tablename -- tablename :: Type string 1555 * @param $colname -- colname :: Type string 1556 * @param $colname1 -- coluname1 :: Type string 1557 * @param $entid_fld -- entity field :: Type string 1558 * @param $entid -- entid :: Type integer 1559 * @param $prod_total -- totalproduct :: Type integer 1560 */ 1561 1562 function updateSubTotal($module,$tablename,$colname,$colname1,$entid_fld,$entid,$prod_total) 1563 { 1564 global $log; 1565 $log->debug("Entering updateSubTotal(".$module.",".$tablename.",".$colname.",".$colname1.",".$entid_fld.",".$entid.",".$prod_total.") method ..."); 1566 global $adb; 1567 //getting the subtotal 1568 $query = "select ".$colname.",".$colname1." from ".$tablename." where ".$entid_fld."=".$entid; 1569 $result1 = $adb->query($query); 1570 $subtot = $adb->query_result($result1,0,$colname); 1571 $subtot_upd = $subtot - $prod_total; 1572 1573 $gdtot = $adb->query_result($result1,0,$colname1); 1574 $gdtot_upd = $gdtot - $prod_total; 1575 1576 //updating the subtotal 1577 $sub_query = "update ".$tablename." set ".$colname."=".$subtot_upd.",".$colname1."=".$gdtot_upd." where ".$entid_fld."=".$entid; 1578 $adb->query($sub_query); 1579 $log->debug("Exiting updateSubTotal method ..."); 1580 } 1581 1582 /** Function to get Inventory Total 1583 * @param $return_module -- return module :: Type string 1584 * @param $id -- entity id :: Type integer 1585 * @returns $total -- total:: Type integer 1586 */ 1587 1588 function getInventoryTotal($return_module,$id) 1589 { 1590 global $log; 1591 $log->debug("Entering getInventoryTotal(".$return_module.",".$id.") method ..."); 1592 global $adb; 1593 if($return_module == "Potentials") 1594 { 1595 $query ="select vtiger_products.productname,vtiger_products.unit_price,vtiger_products.qtyinstock,vtiger_seproductsrel.* from vtiger_products inner join vtiger_seproductsrel on vtiger_seproductsrel.productid=vtiger_products.productid where crmid=".$id; 1596 } 1597 elseif($return_module == "Products") 1598 { 1599 $query="select vtiger_products.productid,vtiger_products.productname,vtiger_products.unit_price,vtiger_products.qtyinstock,vtiger_crmentity.* from vtiger_products inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_products.productid where vtiger_crmentity.deleted=0 and productid=".$id; 1600 } 1601 $result = $adb->query($query); 1602 $num_rows=$adb->num_rows($result); 1603 $total=0; 1604 for($i=1;$i<=$num_rows;$i++) 1605 { 1606 $unitprice=$adb->query_result($result,$i-1,'unit_price'); 1607 $qty=$adb->query_result($result,$i-1,'quantity'); 1608 $listprice=$adb->query_result($result,$i-1,'listprice'); 1609 if($listprice == '') 1610 $listprice = $unitprice; 1611 if($qty =='') 1612 $qty = 1; 1613 $total = $total+($qty*$listprice); 1614 } 1615 $log->debug("Exiting getInventoryTotal method ..."); 1616 return $total; 1617 } 1618 1619 /** Function to update product quantity 1620 * @param $product_id -- product id :: Type integer 1621 * @param $upd_qty -- quantity :: Type integer 1622 */ 1623 1624 function updateProductQty($product_id, $upd_qty) 1625 { 1626 global $log; 1627 $log->debug("Entering updateProductQty(".$product_id.",". $upd_qty.") method ..."); 1628 global $adb; 1629 $query= "update vtiger_products set qtyinstock=".$upd_qty." where productid=".$product_id; 1630 $adb->query($query); 1631 $log->debug("Exiting updateProductQty method ..."); 1632 1633 } 1634 1635 /** Function to get account information 1636 * @param $parent_id -- parent id :: Type integer 1637 * @returns $accountid -- accountid:: Type integer 1638 */ 1639 1640 function get_account_info($parent_id) 1641 { 1642 global $log; 1643 $log->debug("Entering get_account_info(".$parent_id.") method ..."); 1644 global $adb; 1645 $query = "select accountid from vtiger_potential where potentialid=".$parent_id; 1646 $result = $adb->query($query); 1647 $accountid=$adb->query_result($result,0,'accountid'); 1648 $log->debug("Exiting get_account_info method ..."); 1649 return $accountid; 1650 } 1651 1652 /** Function to get quick create form fields 1653 * @param $fieldlabel -- field label :: Type string 1654 * @param $uitype -- uitype :: Type integer 1655 * @param $fieldname -- field name :: Type string 1656 * @param $tabid -- tabid :: Type integer 1657 * @returns $return_field -- return field:: Type string 1658 */ 1659 1660 //for Quickcreate-Form 1661 1662 function get_quickcreate_form($fieldlabel,$uitype,$fieldname,$tabid) 1663 { 1664 global $log; 1665 $log->debug("Entering get_quickcreate_form(".$fieldlabel.",".$uitype.",".$fieldname.",".$tabid.") method ..."); 1666 $return_field =''; 1667 switch($uitype) 1668 { 1669 case 1: $return_field .=get_textField($fieldlabel,$fieldname); 1670 $log->debug("Exiting get_quickcreate_form method ..."); 1671 return $return_field; 1672 break; 1673 case 2: $return_field .=get_textmanField($fieldlabel,$fieldname,$tabid); 1674 $log->debug("Exiting get_quickcreate_form method ..."); 1675 return $return_field; 1676 break; 1677 case 6: $return_field .=get_textdateField($fieldlabel,$fieldname,$tabid); 1678 $log->debug("Exiting get_quickcreate_form method ..."); 1679 return $return_field; 1680 break; 1681 case 11: $return_field .=get_textField($fieldlabel,$fieldname); 1682 $log->debug("Exiting get_quickcreate_form method ..."); 1683 return $return_field; 1684 break; 1685 case 13: $return_field .=get_textField($fieldlabel,$fieldname); 1686 $log->debug("Exiting get_quickcreate_form method ..."); 1687 return $return_field; 1688 break; 1689 case 15: $return_field .=get_textcomboField($fieldlabel,$fieldname); 1690 $log->debug("Exiting get_quickcreate_form method ..."); 1691 return $return_field; 1692 break; 1693 case 16: $return_field .=get_textcomboField($fieldlabel,$fieldname); 1694 $log->debug("Exiting get_quickcreate_form method ..."); 1695 return $return_field; 1696 break; 1697 case 17: $return_field .=get_textwebField($fieldlabel,$fieldname); 1698 $log->debug("Exiting get_quickcreate_form method ..."); 1699 return $return_field; 1700 break; 1701 case 19: $return_field .=get_textField($fieldlabel,$fieldname); 1702 $log->debug("Exiting get_quickcreate_form method ..."); 1703 return $return_field; 1704 break; 1705 case 22: $return_field .=get_textmanField($fieldlabel,$fieldname,$tabid); 1706 $log->debug("Exiting get_quickcreate_form method ..."); 1707 return $return_field; 1708 break; 1709 case 23: $return_field .=get_textdateField($fieldlabel,$fieldname,$tabid); 1710 $log->debug("Exiting get_quickcreate_form method ..."); 1711 return $return_field; 1712 break; 1713 case 50: $return_field .=get_textaccField($fieldlabel,$fieldname,$tabid); 1714 $log->debug("Exiting get_quickcreate_form method ..."); 1715 return $return_field; 1716 break; 1717 case 51: $return_field .=get_textaccField($fieldlabel,$fieldname,$tabid); 1718 $log->debug("Exiting get_quickcreate_form method ..."); 1719 return $return_field; 1720 break; 1721 case 55: $return_field .=get_textField($fieldlabel,$fieldname); 1722 $log->debug("Exiting get_quickcreate_form method ..."); 1723 return $return_field; 1724 break; 1725 case 63: $return_field .=get_textdurationField($fieldlabel,$fieldname,$tabid); 1726 $log->debug("Exiting get_quickcreate_form method ..."); 1727 return $return_field; 1728 break; 1729 case 71: $return_field .=get_textField($fieldlabel,$fieldname); 1730 $log->debug("Exiting get_quickcreate_form method ..."); 1731 return $return_field; 1732 break; 1733 } 1734 } 1735 1736 /** Function to get quick create form fields 1737 * @param $label -- field label :: Type string 1738 * @param $name -- field name :: Type string 1739 * @param $tid -- tabid :: Type integer 1740 * @returns $form_field -- return field:: Type string 1741 */ 1742 1743 function get_textmanField($label,$name,$tid) 1744 { 1745 global $log; 1746 $log->debug("Entering get_textmanField(".$label.",".$name.",".$tid.") method ..."); 1747 $form_field=''; 1748 if($tid == 9) 1749 { 1750 $form_field .='<td>'; 1751 $form_field .= '<font color="red">*</font>'; 1752 $form_field .= $label.':<br>'; 1753 $form_field .='<input name="'.$name.'" id="QCK_T_'.$name.'" type="text" size="20" maxlength="" value=""></td>'; 1754 $log->debug("Exiting get_textmanField method ..."); 1755 return $form_field; 1756 } 1757 if($tid == 16) 1758 { 1759 $form_field .='<td>'; 1760 $form_field .= '<font color="red">*</font>'; 1761 $form_field .= $label.':<br>'; 1762 $form_field .='<input name="'.$name.'" id="QCK_E_'.$name.'" type="text" size="20" maxlength="" value=""></td>'; 1763 $log->debug("Exiting get_textmanField method ..."); 1764 return $form_field; 1765 } 1766 else 1767 { 1768 $form_field .='<td>'; 1769 $form_field .= '<font color="red">*</font>'; 1770 $form_field .= $label.':<br>'; 1771 $form_field .='<input name="'.$name.'" id="QCK_'.$name.'" type="text" size="20" maxlength="" value=""></td>'; 1772 $log->debug("Exiting get_textmanField method ..."); 1773 return $form_field; 1774 } 1775 1776 } 1777 1778 /** Function to get textfield for website field 1779 * @param $label -- field label :: Type string 1780 * @param $name -- field name :: Type string 1781 * @returns $form_field -- return field:: Type string 1782 */ 1783 1784 function get_textwebField($label,$name) 1785 { 1786 global $log; 1787 $log->debug("Entering get_textwebField(".$label.",".$name.") method ..."); 1788 1789 $form_field=''; 1790 $form_field .='<td>'; 1791 $form_field .= $label.':<br>http://<br>'; 1792 $form_field .='<input name="'.$name.'" id="QCK_'.$name.'" type="text" size="20" maxlength="" value=""></td>'; 1793 $log->debug("Exiting get_textwebField method ..."); 1794 return $form_field; 1795 1796 } 1797 1798 /** Function to get textfield 1799 * @param $label -- field label :: Type string 1800 * @param $name -- field name :: Type string 1801 * @returns $form_field -- return field:: Type string 1802 */ 1803 1804 function get_textField($label,$name) 1805 { 1806 global $log; 1807 $log->debug("Entering get_textField(".$label.",".$name.") method ..."); 1808 $form_field=''; 1809 if($name == "amount") 1810 { 1811 $form_field .='<td>'; 1812 $form_field .= $label.':(U.S Dollar:$)<br>'; 1813 $form_field .='<input name="'.$name.'" id="QCK_'.$name.'" type="text" size="20" maxlength="" value=""></td>'; 1814 $log->debug("Exiting get_textField method ..."); 1815 return $form_field; 1816 } 1817 else 1818 { 1819 1820 $form_field .='<td>'; 1821 $form_field .= $label.':<br>'; 1822 $form_field .='<input name="'.$name.'" id="QCK_'.$name.'" type="text" size="20" maxlength="" value=""></td>'; 1823 $log->debug("Exiting get_textField method ..."); 1824 return $form_field; 1825 } 1826 1827 } 1828 1829 /** Function to get account textfield 1830 * @param $label -- field label :: Type string 1831 * @param $name -- field name :: Type string 1832 * @param $tid -- tabid :: Type integer 1833 * @returns $form_field -- return field:: Type string 1834 */ 1835 1836 function get_textaccField($label,$name,$tid) 1837 { 1838 global $log; 1839 $log->debug("Entering get_textaccField(".$label.",".$name.",".$tid.") method ..."); 1840 1841 global $app_strings; 1842 1843 $form_field=''; 1844 if($tid == 2) 1845 { 1846 $form_field .='<td>'; 1847 $form_field .= '<font color="red">*</font>'; 1848 $form_field .= $label.':<br>'; 1849 $form_field .='<input name="account_name" type="text" size="20" maxlength="" id="account_name" value="" readonly><br>'; 1850 $form_field .='<input name="account_id" id="QCK_'.$name.'" type="hidden" value=""> <input title="'.$app_strings[LBL_CHANGE_BUTTON_TITLE].'" accessKey="'.$app_strings[LBL_CHANGE_BUTTON_KEY].'" type="button" tabindex="3" class="button" value="'.$app_strings[LBL_CHANGE_BUTTON_LABEL].'" name="btn1" LANGUAGE=javascript onclick=\'return window.open("index.php?module=Accounts&action=Popup&popuptype=specific&form=EditView&form_submit=false","test","width=600,height=400,resizable=1,scrollbars=1");\'></td>'; 1851 $log->debug("Exiting get_textaccField method ..."); 1852 return $form_field; 1853 } 1854 else 1855 { 1856 $form_field .='<td>'; 1857 $form_field .= $label.':<br>'; 1858 $form_field .='<input name="account_name" type="text" size="20" maxlength="" value="" readonly><br>'; 1859 $form_field .='<input name="'.$name.'" id="QCK_'.$name.'" type="hidden" value=""> <input title="'.$app_strings[LBL_CHANGE_BUTTON_TITLE].'" accessKey="'.$app_strings[LBL_CHANGE_BUTTON_KEY].'" type="button" tabindex="3" class="button" value="'.$app_strings[LBL_CHANGE_BUTTON_LABEL].'" name="btn1" LANGUAGE=javascript onclick=\'return window.open("index.php?module=Accounts&action=Popup&popuptype=specific&form=EditView&form_submit=false","test","width=600,height=400,resizable=1,scrollbars=1");\'></td>'; 1860 $log->debug("Exiting get_textaccField method ..."); 1861 return $form_field; 1862 } 1863 1864 } 1865 1866 /** Function to get combo field values 1867 * @param $label -- field label :: Type string 1868 * @param $name -- field name :: Type string 1869 * @returns $form_field -- return field:: Type string 1870 */ 1871 1872 function get_textcomboField($label,$name) 1873 { 1874 global $log; 1875 $log->debug("Entering get_textcomboField(".$label.",".$name.") method ..."); 1876 $form_field=''; 1877 if($name == "sales_stage") 1878 { 1879 $comboFieldNames = Array('leadsource'=>'leadsource_dom' 1880 ,'opportunity_type'=>'opportunity_type_dom' 1881 ,'sales_stage'=>'sales_stage_dom'); 1882 $comboFieldArray = getComboArray($comboFieldNames); 1883 $form_field .='<td>'; 1884 $form_field .= '<font color="red">*</font>'; 1885 $form_field .= $label.':<br>'; 1886 $form_field .='<select name="'.$name.'">'; 1887 $form_field .=get_select_options_with_id($comboFieldArray['sales_stage_dom'], ""); 1888 $form_field .='</select></td>'; 1889 $log->debug("Exiting get_textcomboField method ..."); 1890 return $form_field; 1891 1892 } 1893 if($name == "productcategory") 1894 { 1895 $comboFieldNames = Array('productcategory'=>'productcategory_dom'); 1896 $comboFieldArray = getComboArray($comboFieldNames); 1897 $form_field .='<td>'; 1898 $form_field .= $label.':<br>'; 1899 $form_field .='<select name="'.$name.'">'; 1900 $form_field .=get_select_options_with_id($comboFieldArray['productcategory_dom'], ""); 1901 $form_field .='</select></td>'; 1902 $log->debug("Exiting get_textcomboField method ..."); 1903 return $form_field; 1904 1905 } 1906 if($name == "ticketpriorities") 1907 { 1908 $comboFieldNames = Array('ticketpriorities'=>'ticketpriorities_dom'); 1909 $comboFieldArray = getComboArray($comboFieldNames); 1910 $form_field .='<td>'; 1911 $form_field .= $label.':<br>'; 1912 $form_field .='<select name="'.$name.'">'; 1913 $form_field .=get_select_options_with_id($comboFieldArray['ticketpriorities_dom'], ""); 1914 $form_field .='</select></td>'; 1915 $log->debug("Exiting get_textcomboField method ..."); 1916 return $form_field; 1917 } 1918 if($name == "activitytype") 1919 { 1920 $comboFieldNames = Array('activitytype'=>'activitytype_dom', 1921 'duration_minutes'=>'duration_minutes_dom'); 1922 $comboFieldArray = getComboArray($comboFieldNames); 1923 $form_field .='<td>'; 1924 $form_field .= $label.'<br>'; 1925 $form_field .='<select name="'.$name.'">'; 1926 $form_field .=get_select_options_with_id($comboFieldArray['activitytype_dom'], ""); 1927 $form_field .='</select></td>'; 1928 $log->debug("Exiting get_textcomboField method ..."); 1929 return $form_field; 1930 1931 1932 } 1933 if($name == "eventstatus") 1934 { 1935 $comboFieldNames = Array('eventstatus'=>'eventstatus_dom'); 1936 $comboFieldArray = getComboArray($comboFieldNames); 1937 $form_field .='<td>'; 1938 $form_field .= $label.'<br>'; 1939 $form_field .='<select name="'.$name.'">'; 1940 $form_field .=get_select_options_with_id($comboFieldArray['eventstatus_dom'], ""); 1941 $form_field .='</select></td>'; 1942 $log->debug("Exiting get_textcomboField method ..."); 1943 return $form_field; 1944 1945 1946 } 1947 if($name == "taskstatus") 1948 { 1949 $comboFieldNames = Array('taskstatus'=>'taskstatus_dom'); 1950 $comboFieldArray = getComboArray($comboFieldNames); 1951 $form_field .='<td>'; 1952 $form_field .= $label.'<br>'; 1953 $form_field .='<select name="'.$name.'">'; 1954 $form_field .=get_select_options_with_id($comboFieldArray['taskstatus_dom'], ""); 1955 $form_field .='</select></td>'; 1956 $log->debug("Exiting get_textcomboField method ..."); 1957 return $form_field; 1958 } 1959 1960 1961 1962 } 1963 1964 /** Function to get date field 1965 * @param $label -- field label :: Type string 1966 * @param $name -- field name :: Type string 1967 * @param $tid -- tabid :: Type integer 1968 * @returns $form_field -- return field:: Type string 1969 */ 1970 1971 1972 function get_textdateField($label,$name,$tid) 1973 { 1974 global $log; 1975 $log->debug("Entering get_textdateField(".$label.",".$name.",".$tid.") method ..."); 1976 global $theme; 1977 global $app_strings; 1978 global $current_user; 1979 1980 $ntc_date_format = $app_strings['NTC_DATE_FORMAT']; 1981 $ntc_time_format = $app_strings['NTC_TIME_FORMAT']; 1982 1983 $form_field=''; 1984 $default_date_start = date('Y-m-d'); 1985 $default_time_start = date('H:i'); 1986 $dis_value=getNewDisplayDate(); 1987 1988 if($tid == 2) 1989 { 1990 $form_field .='<td>'; 1991 $form_field .= '<font color="red">*</font>'; 1992 $form_field .= $label.':<br>'; 1993 $form_field .='<font size="1"><em old="ntc_date_format">('.$current_user->date_format.')</em></font><br>'; 1994 $form_field .='<input name="'.$name.'" size="12" maxlength="10" id="QCK_'.$name.'" type="text" value=""> '; 1995 $form_field .='<img src="themes/'.$theme.'/images/calendar.gif" id="jscal_trigger"></td>'; 1996 $log->debug("Exiting get_textdateField method ..."); 1997 return $form_field; 1998 1999 } 2000 if($tid == 9) 2001 { 2002 $form_field .='<td>'; 2003 $form_field .= '<font color="red">*</font>'; 2004 $form_field .= $label.':<br>'; 2005 $form_field .='<input name="'.$name.'" id="QCK_T_'.$name.'" tabindex="2" type="text" size="10" maxlength="10" value="'.$default_date_start.'"> '; 2006 $form_field.= '<img src="themes/'.$theme.'/images/calendar.gif" id="jscal_trigger_date_start"> '; 2007 $form_field.='<input name="time_start" id="task_time_start" tabindex="1" type="text" size="5" maxlength="5" type="text" value="'.$default_time_start.'"><br><font size="1"><em old="ntc_date_format">('.$current_user->date_format.')</em></font> <font size="1"><em>'.$ntc_time_format.'</em></font></td>'; 2008 $log->debug("Exiting get_textdateField method ..."); 2009 return $form_field; 2010 } 2011 if($tid == 16) 2012 { 2013 $form_field .='<td>'; 2014 $form_field .= '<font color="red">*</font>'; 2015 $form_field .= $label.':<br>'; 2016 $form_field .='<input name="'.$name.'" id="QCK_E_'.$name.'" tabindex="2" type="text" size="10" maxlength="10" value="'.$default_date_start.'"> '; 2017 $form_field.= '<img src="themes/'.$theme.'/images/calendar.gif" id="jscal_trigger_event_date_start"> '; 2018 $form_field.='<input name="time_start" id="event_time_start" tabindex="1" type="text" size="5" maxlength="5" type="text" value="'.$default_time_start.'"><br><font size="1"><em old="ntc_date_format">('.$current_user->date_format.')</em></font> <font size="1"><em>'.$ntc_time_format.'</em></font></td>'; 2019 $log->debug("Exiting get_textdateField method ..."); 2020 return $form_field; 2021 } 2022 2023 else 2024 { 2025 $form_field .='<td>'; 2026 $form_field .= '<font color="red">*</font>'; 2027 $form_field .= $label.':<br>'; 2028 $form_field .='<input name="'.$name.'" id="QCK_'.$name.'" type="text" size="10" maxlength="10" value="'.$default_date_start.'"> '; 2029 $form_field.= '<img src="themes/'.$theme.'/images/calendar.gif" id="jscal_trigger"> '; 2030 $form_field.='<input name="time_start" type="text" size="5" maxlength="5" type="text" value="'.$default_time_start.'"><br><font size="1"><em old="ntc_date_format">('.$current_user->date_format.')</em></font> <font size="1"><em>'.$ntc_time_format.'</em></font></td>'; 2031 $log->debug("Exiting get_textdateField method ..."); 2032 return $form_field; 2033 } 2034 2035 } 2036 2037 /** Function to get duration text field in activity 2038 * @param $label -- field label :: Type string 2039 * @param $name -- field name :: Type string 2040 * @param $tid -- tabid :: Type integer 2041 * @returns $form_field -- return field:: Type string 2042 */ 2043 2044 function get_textdurationField($label,$name,$tid) 2045 { 2046 global $log; 2047 $log->debug("Entering get_textdurationField(".$label.",".$name.",".$tid.") method ..."); 2048 $form_field=''; 2049 if($tid == 16) 2050 { 2051 2052 $comboFieldNames = Array('activitytype'=>'activitytype_dom', 2053 'duration_minutes'=>'duration_minutes_dom'); 2054 $comboFieldArray = getComboArray($comboFieldNames); 2055 2056 $form_field .='<td>'; 2057 $form_field .= $label.'<br>'; 2058 $form_field .='<input name="'.$name.'" id="QCK_'.$name.'" type="text" size="2" value="1"> '; 2059 $form_field .='<select name="duration_minutes">'; 2060 $form_field .=get_select_options_with_id($comboFieldArray['duration_minutes_dom'], ""); 2061 $form_field .='</select><br>(hours/minutes)<br></td>'; 2062 $log->debug("Exiting get_textdurationField method ..."); 2063 return $form_field; 2064 } 2065 } 2066 2067 /** Function to get email text field 2068 * @param $module -- module name :: Type name 2069 * @param $id -- entity id :: Type integer 2070 * @returns $hidden -- hidden:: Type string 2071 */ 2072 2073 //Added to get the parents list as hidden for Emails -- 09-11-2005 2074 function getEmailParentsList($module,$id) 2075 { 2076 global $log; 2077 $log->debug("Entering getEmailParentsList(".$module.",".$id.") method ..."); 2078 global $adb; 2079 if($module == 'Contacts') 2080 $focus = new Contacts(); 2081 if($module == 'Leads') 2082 $focus = new Leads(); 2083 2084 $focus->retrieve_entity_info($id,$module); 2085 $fieldid = 0; 2086 $fieldname = 'email'; 2087 if($focus->column_fields['email'] == '' && $focus->column_fields['yahooid'] != '') 2088 $fieldname = 'yahooid'; 2089 2090 $res = $adb->query("select * from vtiger_field where tabid = ".getTabid($module)." and fieldname='".$fieldname."'"); 2091 $fieldid = $adb->query_result($res,0,'fieldid'); 2092 2093 $hidden .= '<input type="hidden" name="emailids" value="'.$id.'@'.$fieldid.'|">'; 2094 $hidden .= '<input type="hidden" name="pmodule" value="'.$module.'">'; 2095 2096 $log->debug("Exiting getEmailParentsList method ..."); 2097 return $hidden; 2098 } 2099 2100 /** This Function returns the current status of the specified Purchase Order. 2101 * The following is the input parameter for the function 2102 * $po_id --> Purchase Order Id, Type:Integer 2103 */ 2104 function getPoStatus($po_id) 2105 { 2106 global $log; 2107 $log->debug("Entering getPoStatus(".$po_id.") method ..."); 2108 2109 global $log; 2110 $log->info("in getPoName ".$po_id); 2111 2112 global $adb; 2113 $sql = "select postatus from vtiger_purchaseorder where purchaseorderid=".$po_id; 2114 $result = $adb->query($sql); 2115 $po_status = $adb->query_result($result,0,"postatus"); 2116 $log->debug("Exiting getPoStatus method ..."); 2117 return $po_status; 2118 } 2119 2120 /** This Function adds the specified product quantity to the Product Quantity in Stock in the Warehouse 2121 * The following is the input parameter for the function: 2122 * $productId --> ProductId, Type:Integer 2123 * $qty --> Quantity to be added, Type:Integer 2124 */ 2125 function addToProductStock($productId,$qty) 2126 { 2127 global $log; 2128 $log->debug("Entering addToProductStock(".$productId.",".$qty.") method ..."); 2129 global $adb; 2130 $qtyInStck=getProductQtyInStock($productId); 2131 $updQty=$qtyInStck + $qty; 2132 $sql = "UPDATE vtiger_products set qtyinstock=$updQty where productid=".$productId; 2133 $adb->query($sql); 2134 $log->debug("Exiting addToProductStock method ..."); 2135 2136 } 2137 2138 /** This Function adds the specified product quantity to the Product Quantity in Demand in the Warehouse 2139 * @param int $productId - ProductId 2140 * @param int $qty - Quantity to be added 2141 */ 2142 function addToProductDemand($productId,$qty) 2143 { 2144 global $log; 2145 $log->debug("Entering addToProductDemand(".$productId.",".$qty.") method ..."); 2146 global $adb; 2147 $qtyInStck=getProductQtyInDemand($productId); 2148 $updQty=$qtyInStck + $qty; 2149 $sql = "UPDATE vtiger_products set qtyindemand=$updQty where productid=".$productId; 2150 $adb->query($sql); 2151 $log->debug("Exiting addToProductDemand method ..."); 2152 2153 } 2154 2155 /** This Function subtract the specified product quantity to the Product Quantity in Stock in the Warehouse 2156 * @param int $productId - ProductId 2157 * @param int $qty - Quantity to be subtracted 2158 */ 2159 function deductFromProductStock($productId,$qty) 2160 { 2161 global $log; 2162 $log->debug("Entering deductFromProductStock(".$productId.",".$qty.") method ..."); 2163 global $adb; 2164 $qtyInStck=getProductQtyInStock($productId); 2165 $updQty=$qtyInStck - $qty; 2166 $sql = "UPDATE vtiger_products set qtyinstock=$updQty where productid=".$productId; 2167 $adb->query($sql); 2168 $log->debug("Exiting deductFromProductStock method ..."); 2169 2170 } 2171 2172 /** This Function subtract the specified product quantity to the Product Quantity in Demand in the Warehouse 2173 * @param int $productId - ProductId 2174 * @param int $qty - Quantity to be subtract 2175 */ 2176 function deductFromProductDemand($productId,$qty) 2177 { 2178 global $log; 2179 $log->debug("Entering deductFromProductDemand(".$productId.",".$qty.") method ..."); 2180 global $adb; 2181 $qtyInStck=getProductQtyInDemand($productId); 2182 $updQty=$qtyInStck - $qty; 2183 $sql = "UPDATE vtiger_products set qtyindemand=$updQty where productid=".$productId; 2184 $adb->query($sql); 2185 $log->debug("Exiting deductFromProductDemand method ..."); 2186 2187 } 2188 2189 2190 /** This Function returns the current product quantity in stock. 2191 * The following is the input parameter for the function: 2192 * $product_id --> ProductId, Type:Integer 2193 */ 2194 function getProductQtyInStock($product_id) 2195 { 2196 global $log; 2197 $log->debug("Entering getProductQtyInStock(".$product_id.") method ..."); 2198 global $adb; 2199 $query1 = "select qtyinstock from vtiger_products where productid=".$product_id; 2200 $result=$adb->query($query1); 2201 $qtyinstck= $adb->query_result($result,0,"qtyinstock"); 2202 $log->debug("Exiting getProductQtyInStock method ..."); 2203 return $qtyinstck; 2204 2205 2206 } 2207 2208 /** This Function returns the current product quantity in demand. 2209 * @param int $product_id - ProductId 2210 * @return int $qtyInDemand - Quantity in Demand of a product 2211 */ 2212 function getProductQtyInDemand($product_id) 2213 { 2214 global $log; 2215 $log->debug("Entering getProductQtyInDemand(".$product_id.") method ..."); 2216 global $adb; 2217 $query1 = "select qtyindemand from vtiger_products where productid=".$product_id; 2218 $result = $adb->query($query1); 2219 $qtyInDemand = $adb->query_result($result,0,"qtyindemand"); 2220 $log->debug("Exiting getProductQtyInDemand method ..."); 2221 return $qtyInDemand; 2222 } 2223 2224 /** Function to seperate the Date and Time 2225 * This function accepts a sting with date and time and 2226 * returns an array of two elements.The first element 2227 * contains the date and the second one contains the time 2228 */ 2229 function getDateFromDateAndtime($date_time) 2230 { 2231 global $log; 2232 $log->debug("Entering getDateFromDateAndtime(".$date_time.") method ..."); 2233 $result = explode(" ",$date_time); 2234 $log->debug("Exiting getDateFromDateAndtime method ..."); 2235 return $result; 2236 } 2237 2238 2239 /** Function to get header for block in edit/create and detailview 2240 * @param $header_label -- header label :: Type string 2241 * @returns $output -- output:: Type string 2242 */ 2243 2244 function getBlockTableHeader($header_label) 2245 { 2246 global $log; 2247 $log->debug("Entering getBlockTableHeader(".$header_label.") method ..."); 2248 global $mod_strings; 2249 $label = $mod_strings[$header_label]; 2250 $output = $label; 2251 $log->debug("Exiting getBlockTableHeader method ..."); 2252 return $output; 2253 2254 } 2255 2256 2257 2258 /** Function to get the vtiger_table name from 'field' vtiger_table for the input vtiger_field based on the module 2259 * @param : string $module - current module value 2260 * @param : string $fieldname - vtiger_fieldname to which we want the vtiger_tablename 2261 * @return : string $tablename - vtiger_tablename in which $fieldname is a column, which is retrieved from 'field' vtiger_table per $module basis 2262 */ 2263 function getTableNameForField($module,$fieldname) 2264 { 2265 global $log; 2266 $log->debug("Entering getTableNameForField(".$module.",".$fieldname.") method ..."); 2267 global $adb; 2268 $tabid = getTabid($module); 2269 2270 $sql = "select tablename from vtiger_field where tabid=".$tabid." and columnname like '%".$fieldname."%'"; 2271 $res = $adb->query($sql); 2272 2273 $tablename = ''; 2274 if($adb->num_rows($res) > 0) 2275 { 2276 $tablename = $adb->query_result($res,0,'tablename'); 2277 } 2278 2279 $log->debug("Exiting getTableNameForField method ..."); 2280 return $tablename; 2281 } 2282 2283 /** Function to get parent record owner 2284 * @param $tabid -- tabid :: Type integer 2285 * @param $parModId -- parent module id :: Type integer 2286 * @param $record_id -- record id :: Type integer 2287 * @returns $parentRecOwner -- parentRecOwner:: Type integer 2288 */ 2289 2290 function getParentRecordOwner($tabid,$parModId,$record_id) 2291 { 2292 global $log; 2293 $log->debug("Entering getParentRecordOwner(".$tabid.",".$parModId.",".$record_id.") method ..."); 2294 $parentRecOwner=Array(); 2295 $parentTabName=getTabname($parModId); 2296 $relTabName=getTabname($tabid); 2297 $fn_name="get".$relTabName."Related".$parentTabName; 2298 $ent_id=$fn_name($record_id); 2299 if($ent_id != '') 2300 { 2301 $parentRecOwner=getRecordOwnerId($ent_id); 2302 } 2303 $log->debug("Exiting getParentRecordOwner method ..."); 2304 return $parentRecOwner; 2305 } 2306 2307 /** Function to get potential related accounts 2308 * @param $record_id -- record id :: Type integer 2309 * @returns $accountid -- accountid:: Type integer 2310 */ 2311 2312 function getPotentialsRelatedAccounts($record_id) 2313 { 2314 global $log; 2315 $log->debug("Entering getPotentialsRelatedAccounts(".$record_id.") method ..."); 2316 global $adb; 2317 $query="select accountid from vtiger_potential where potentialid=".$record_id; 2318 $result=$adb->query($query); 2319 $accountid=$adb->query_result($result,0,'accountid'); 2320 $log->debug("Exiting getPotentialsRelatedAccounts method ..."); 2321 return $accountid; 2322 } 2323 2324 /** Function to get email related accounts 2325 * @param $record_id -- record id :: Type integer 2326 * @returns $accountid -- accountid:: Type integer 2327 */ 2328 function getEmailsRelatedAccounts($record_id) 2329 { 2330 global $log; 2331 $log->debug("Entering getEmailsRelatedAccounts(".$record_id.") method ..."); 2332 global $adb; 2333 $query = "select vtiger_seactivityrel.crmid from vtiger_seactivityrel inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_seactivityrel.crmid where vtiger_crmentity.setype='Accounts' and activityid=".$record_id; 2334 $result = $adb->query($query); 2335 $accountid=$adb->query_result($result,0,'crmid'); 2336 $log->debug("Exiting getEmailsRelatedAccounts method ..."); 2337 return $accountid; 2338 } 2339 /** Function to get email related Leads 2340 * @param $record_id -- record id :: Type integer 2341 * @returns $leadid -- leadid:: Type integer 2342 */ 2343 2344 function getEmailsRelatedLeads($record_id) 2345 { 2346 global $log; 2347 $log->debug("Entering getEmailsRelatedLeads(".$record_id.") method ..."); 2348 global $adb; 2349 $query = "select vtiger_seactivityrel.crmid from vtiger_seactivityrel inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_seactivityrel.crmid where vtiger_crmentity.setype='Leads' and activityid=".$record_id; 2350 $result = $adb->query($query); 2351 $leadid=$adb->query_result($result,0,'crmid'); 2352 $log->debug("Exiting getEmailsRelatedLeads method ..."); 2353 return $leadid; 2354 } 2355 2356 /** Function to get HelpDesk related Accounts 2357 * @param $record_id -- record id :: Type integer 2358 * @returns $accountid -- accountid:: Type integer 2359 */ 2360 2361 function getHelpDeskRelatedAccounts($record_id) 2362 { 2363 global $log; 2364 $log->debug("Entering getHelpDeskRelatedAccounts(".$record_id.") method ..."); 2365 global $adb; 2366 $query="select parent_id from vtiger_troubletickets inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_troubletickets.parent_id where ticketid=".$record_id." and vtiger_crmentity.setype='Accounts'"; 2367 $result=$adb->query($query); 2368 $accountid=$adb->query_result($result,0,'parent_id'); 2369 $log->debug("Exiting getHelpDeskRelatedAccounts method ..."); 2370 return $accountid; 2371 } 2372 2373 /** Function to get Quotes related Accounts 2374 * @param $record_id -- record id :: Type integer 2375 * @returns $accountid -- accountid:: Type integer 2376 */ 2377 2378 function getQuotesRelatedAccounts($record_id) 2379 { 2380 global $log; 2381 $log->debug("Entering getQuotesRelatedAccounts(".$record_id.") method ..."); 2382 global $adb; 2383 $query="select accountid from vtiger_quotes where quoteid=".$record_id; 2384 $result=$adb->query($query); 2385 $accountid=$adb->query_result($result,0,'accountid'); 2386 $log->debug("Exiting getQuotesRelatedAccounts method ..."); 2387 return $accountid; 2388 } 2389 2390 /** Function to get Quotes related Potentials 2391 * @param $record_id -- record id :: Type integer 2392 * @returns $potid -- potid:: Type integer 2393 */ 2394 2395 function getQuotesRelatedPotentials($record_id) 2396 { 2397 global $log; 2398 $log->debug("Entering getQuotesRelatedPotentials(".$record_id.") method ..."); 2399 global $adb; 2400 $query="select potentialid from vtiger_quotes where quoteid=".$record_id; 2401 $result=$adb->query($query); 2402 $potid=$adb->query_result($result,0,'potentialid'); 2403 $log->debug("Exiting getQuotesRelatedPotentials method ..."); 2404 return $potid; 2405 } 2406 2407 /** Function to get Quotes related Potentials 2408 * @param $record_id -- record id :: Type integer 2409 * @returns $accountid -- accountid:: Type integer 2410 */ 2411 2412 function getSalesOrderRelatedAccounts($record_id) 2413 { 2414 global $log; 2415 $log->debug("Entering getSalesOrderRelatedAccounts(".$record_id.") method ..."); 2416 global $adb; 2417 $query="select accountid from vtiger_salesorder where salesorderid=".$record_id; 2418 $result=$adb->query($query); 2419 $accountid=$adb->query_result($result,0,'accountid'); 2420 $log->debug("Exiting getSalesOrderRelatedAccounts method ..."); 2421 return $accountid; 2422 } 2423 2424 /** Function to get SalesOrder related Potentials 2425 * @param $record_id -- record id :: Type integer 2426 * @returns $potid -- potid:: Type integer 2427 */ 2428 2429 function getSalesOrderRelatedPotentials($record_id) 2430 { 2431 global $log; 2432 $log->debug("Entering getSalesOrderRelatedPotentials(".$record_id.") method ..."); 2433 global $adb; 2434 $query="select potentialid from vtiger_salesorder where salesorderid=".$record_id; 2435 $result=$adb->query($query); 2436 $potid=$adb->query_result($result,0,'potentialid'); 2437 $log->debug("Exiting getSalesOrderRelatedPotentials method ..."); 2438 return $potid; 2439 } 2440 /** Function to get SalesOrder related Quotes 2441 * @param $record_id -- record id :: Type integer 2442 * @returns $qtid -- qtid:: Type integer 2443 */ 2444 2445 function getSalesOrderRelatedQuotes($record_id) 2446 { 2447 global $log; 2448 $log->debug("Entering getSalesOrderRelatedQuotes(".$record_id.") method ..."); 2449 global $adb; 2450 $query="select quoteid from vtiger_salesorder where salesorderid=".$record_id; 2451 $result=$adb->query($query); 2452 $qtid=$adb->query_result($result,0,'quoteid'); 2453 $log->debug("Exiting getSalesOrderRelatedQuotes method ..."); 2454 return $qtid; 2455 } 2456 2457 /** Function to get Invoice related Accounts 2458 * @param $record_id -- record id :: Type integer 2459 * @returns $accountid -- accountid:: Type integer 2460 */ 2461 2462 function getInvoiceRelatedAccounts($record_id) 2463 { 2464 global $log; 2465 $log->debug("Entering getInvoiceRelatedAccounts(".$record_id.") method ..."); 2466 global $adb; 2467 $query="select accountid from vtiger_invoice where invoiceid=".$record_id; 2468 $result=$adb->query($query); 2469 $accountid=$adb->query_result($result,0,'accountid'); 2470 $log->debug("Exiting getInvoiceRelatedAccounts method ..."); 2471 return $accountid; 2472 } 2473 /** Function to get Invoice related SalesOrder 2474 * @param $record_id -- record id :: Type integer 2475 * @returns $soid -- soid:: Type integer 2476 */ 2477 2478 function getInvoiceRelatedSalesOrder($record_id) 2479 { 2480 global $log; 2481 $log->debug("Entering getInvoiceRelatedSalesOrder(".$record_id.") method ..."); 2482 global $adb; 2483 $query="select salesorderid from vtiger_invoice where invoiceid=".$record_id; 2484 $result=$adb->query($query); 2485 $soid=$adb->query_result($result,0,'salesorderid'); 2486 $log->debug("Exiting getInvoiceRelatedSalesOrder method ..."); 2487 return $soid; 2488 } 2489 2490 2491 /** Function to get Days and Dates in between the dates specified 2492 * Portions created by vtiger are Copyright (C) vtiger. 2493 * All Rights Reserved. 2494 * Contributor(s): ______________________________________.. 2495 */ 2496 function get_days_n_dates($st,$en) 2497 { 2498 global $log; 2499 $log->debug("Entering get_days_n_dates(".$st.",".$en.") method ..."); 2500 $stdate_arr=explode("-",$st); 2501 $endate_arr=explode("-",$en); 2502 2503 $dateDiff = mktime(0,0,0,$endate_arr[1],$endate_arr[2],$endate_arr[0]) - mktime(0,0,0,$stdate_arr[1],$stdate_arr[2],$stdate_arr[0]);//to get dates difference 2504 2505 $days = floor($dateDiff/60/60/24)+1; //to calculate no of. days 2506 for($i=0;$i<$days;$i++) 2507 { 2508 $day_date[] = date("Y-m-d",mktime(0,0,0,date("$stdate_arr[1]"),(date("$stdate_arr[2]")+($i)),date("$stdate_arr[0]"))); 2509 } 2510 if(!isset($day_date)) 2511 $day_date=0; 2512 $nodays_dates=array($days,$day_date); 2513 $log->debug("Exiting get_days_n_dates method ..."); 2514 return $nodays_dates; //passing no of days , days in between the days 2515 }//function end 2516 2517 2518 /** Function to get the start and End Dates based upon the period which we give 2519 * Portions created by vtiger are Copyright (C) vtiger. 2520 * All Rights Reserved. 2521 * Contributor(s): ______________________________________.. 2522 */ 2523 function start_end_dates($period) 2524 { 2525 global $log; 2526 $log->debug("Entering start_end_dates(".$period.") method ..."); 2527 $st_thisweek= date("Y-m-d",mktime(0,0,0,date("n"),(date("j")-date("w")),date("Y"))); 2528 if($period=="tweek") 2529 { 2530 $st_date= date("Y-m-d",mktime(0,0,0,date("n"),(date("j")-date("w")),date("Y"))); 2531 $end_date = date("Y-m-d",mktime(0,0,0,date("n"),(date("j")-1),date("Y"))); 2532 $st_week= date("w",mktime(0,0,0,date("n"),date("j"),date("Y"))); 2533 if($st_week==0) 2534 { 2535 $start_week=explode("-",$st_thisweek); 2536 $st_date = date("Y-m-d",mktime(0,0,0,date("$start_week[1]"),(date("$start_week[2]")-7),date("$start_week[0]"))); 2537 $end_date = date("Y-m-d",mktime(0,0,0,date("$start_week[1]"),(date("$start_week[2]")-1),date("$start_week[0]"))); 2538 } 2539 $period_type="week"; 2540 $width="360"; 2541 } 2542 else if($period=="lweek") 2543 { 2544 $start_week=explode("-",$st_thisweek); 2545 $st_date = date("Y-m-d",mktime(0,0,0,date("$start_week[1]"),(date("$start_week[2]")-7),date("$start_week[0]"))); 2546 $end_date = date("Y-m-d",mktime(0,0,0,date("$start_week[1]"),(date("$start_week[2]")-1),date("$start_week[0]"))); 2547 $st_week= date("w",mktime(0,0,0,date("n"),date("j"),date("Y"))); 2548 if($st_week==0) 2549 { 2550 $start_week=explode("-",$st_thisweek); 2551 $st_date = date("Y-m-d",mktime(0,0,0,date("$start_week[1]"),(date("$start_week[2]")-14),date("$start_week[0]"))); 2552 $end_date = date("Y-m-d",mktime(0,0,0,date("$start_week[1]"),(date("$start_week[2]")-8),date("$start_week[0]"))); 2553 } 2554 $period_type="week"; 2555 $width="360"; 2556 } 2557 else if($period=="tmon") 2558 { 2559 $period_type="month"; 2560 $width="840"; 2561 $st_date = date("Y-m-d",mktime(0, 0, 0, date("m"), "01", date("Y"))); 2562 $end_date = date("Y-m-t"); 2563 2564 } 2565 else if($period=="lmon") 2566 { 2567 $st_date=date("Y-m-d",mktime(0,0,0,date("n")-1,date("1"),date("Y"))); 2568 $end_date = date("Y-m-d",mktime(0, 0, 1, date("n"), 0,date("Y"))); 2569 $period_type="month"; 2570 $start_month=date("d",mktime(0,0,0,date("n"),date("j"),date("Y"))); 2571 if($start_month==1) 2572 { 2573 $st_date=date("Y-m-d",mktime(0,0,0,date("n")-2,date("1"),date("Y"))); 2574 $end_date = date("Y-m-d",mktime(0, 0, 1, date("n")-1, 0,date("Y"))); 2575 } 2576 2577 $width="840"; 2578 } 2579 else 2580 { 2581 $curr_date=date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y"))); 2582 $today_date=explode("-",$curr_date); 2583 $lastday_date=date("Y-m-d",mktime(0,0,0,date("$today_date[1]"),date("$today_date[2]")-1,date("$today_date[0]"))); 2584 $st_date=$lastday_date; 2585 $end_date=$lastday_date; 2586 $period_type="yday"; 2587 $width="250"; 2588 } 2589 if($period_type=="yday") 2590 $height="160"; 2591 else 2592 $height="250"; 2593 $datevalues=array($st_date,$end_date,$period_type,$width,$height); 2594 $log->debug("Exiting start_end_dates method ..."); 2595 return $datevalues; 2596 }//function ends 2597 2598 2599 /** Function to get the Graph and vtiger_table format for a particular date 2600 based upon the period 2601 * Portions created by vtiger are Copyright (C) vtiger. 2602 * All Rights Reserved. 2603 * Contributor(s): ______________________________________.. 2604 */ 2605 function Graph_n_table_format($period_type,$date_value) 2606 { 2607 global $log; 2608 $log->debug("Entering Graph_n_table_format(".$period_type.",".$date_value.") method ..."); 2609 $date_val=explode("-",$date_value); 2610 if($period_type=="month") //to get the vtiger_table format dates 2611 { 2612 $table_format=date("j",mktime(0,0,0,date($date_val[1]),(date($date_val[2])),date($date_val[0]))); 2613 $graph_format=date("D",mktime(0,0,0,date($date_val[1]),(date($date_val[2])),date($date_val[0]))); 2614 } 2615 else if($period_type=="week") 2616 { 2617 $table_format=date("d/m",mktime(0,0,0,date($date_val[1]),(date($date_val[2])),date($date_val[0]))); 2618 $graph_format=date("D",mktime(0,0,0,date($date_val[1]),(date($date_val[2])),date($date_val[0]))); 2619 } 2620 else if($period_type=="yday") 2621 { 2622 $table_format=date("j",mktime(0,0,0,date($date_val[1]),(date($date_val[2])),date($date_val[0]))); 2623 $graph_format=$table_format; 2624 } 2625 $values=array($graph_format,$table_format); 2626 $log->debug("Exiting Graph_n_table_format method ..."); 2627 return $values; 2628 } 2629 2630 /** Function to get image count for a given product 2631 * @param $id -- product id :: Type integer 2632 * @returns count -- count:: Type integer 2633 */ 2634 2635 function getImageCount($id) 2636 { 2637 global $log; 2638 $log->debug("Entering getImageCount(".$id.") method ..."); 2639 global $adb; 2640 $image_lists=array(); 2641 $query="select imagename from vtiger_products where productid=".$id; 2642 $result=$adb->query($query); 2643 $imagename=$adb->query_result($result,0,'imagename'); 2644 $image_lists=explode("###",$imagename); 2645 $log->debug("Exiting getImageCount method ..."); 2646 return count($image_lists); 2647 2648 } 2649 2650 /** Function to get user image for a given user 2651 * @param $id -- user id :: Type integer 2652 * @returns $image_name -- image name:: Type string 2653 */ 2654 2655 function getUserImageName($id) 2656 { 2657 global $log; 2658 $log->debug("Entering getUserImageName(".$id.") method ..."); 2659 global $adb; 2660 $query = "select imagename from vtiger_users where id=".$id; 2661 $result = $adb->query($query); 2662 $image_name = $adb->query_result($result,0,"imagename"); 2663 $log->debug("Inside getUserImageName. The image_name is ".$image_name); 2664 $log->debug("Exiting getUserImageName method ..."); 2665 return $image_name; 2666 2667 } 2668 2669 /** Function to get all user images for displaying it in listview 2670 * @returns $image_name -- image name:: Type array 2671 */ 2672 2673 function getUserImageNames() 2674 { 2675 global $log; 2676 $log->debug("Entering getUserImageNames() method ..."); 2677 global $adb; 2678 $query = "select imagename from vtiger_users where deleted=0"; 2679 $result = $adb->query($query); 2680 $image_name=array(); 2681 for($i=0;$i<$adb->num_rows($result);$i++) 2682 { 2683 if($adb->query_result($result,$i,"imagename")!='') 2684 $image_name[] = $adb->query_result($result,$i,"imagename"); 2685 } 2686 $log->debug("Inside getUserImageNames."); 2687 if(count($image_name) > 0) 2688 { 2689 $log->debug("Exiting getUserImageNames method ..."); 2690 return $image_name; 2691 } 2692 } 2693 2694 /** Function to remove the script tag in the contents 2695 * Portions created by vtiger are Copyright (C) vtiger. 2696 * All Rights Reserved. 2697 * Contributor(s): ______________________________________.. 2698 */ 2699 function strip_selected_tags($text, $tags = array()) 2700 { 2701 $args = func_get_args(); 2702 $text = array_shift($args); 2703 $tags = func_num_args() > 2 ? array_diff($args,array($text)) : (array)$tags; 2704 foreach ($tags as $tag){ 2705 if(preg_match_all('/<'.$tag.'[^>]*>(.*)<\/'.$tag.'>/iU', $text, $found)){ 2706 $text = str_replace($found[0],$found[1],$text); 2707 } 2708 } 2709 2710 return $text; 2711 } 2712 2713 /** Function to check whether user has opted for internal mailer 2714 * @returns $int_mailer -- int mailer:: Type boolean 2715 */ 2716 function useInternalMailer() { 2717 global $current_user,$adb; 2718 return $adb->query_result($adb->query("select int_mailer from vtiger_mail_accounts where user_id='".$current_user->id."'"),0,"int_mailer"); 2719 } 2720 2721 /** 2722 * the function is like unescape in javascript 2723 * added by dingjianting on 2006-10-1 for picklist editor 2724 */ 2725 function utf8RawUrlDecode ($source) { 2726 $decodedStr = ""; 2727 $pos = 0; 2728 $len = strlen ($source); 2729 while ($pos < $len) { 2730 $charAt = substr ($source, $pos, 1); 2731 if ($charAt == '%') { 2732 $pos++; 2733 $charAt = substr ($source, $pos, 1); 2734 if ($charAt == 'u') { 2735 // we got a unicode character 2736 $pos++; 2737 $unicodeHexVal = substr ($source, $pos, 4); 2738 $unicode = hexdec ($unicodeHexVal); 2739 $entity = "&#". $unicode . ';'; 2740 $decodedStr .= utf8_encode ($entity); 2741 $pos += 4; 2742 } 2743 else { 2744 // we have an escaped ascii character 2745 $hexVal = substr ($source, $pos, 2); 2746 $decodedStr .= chr (hexdec ($hexVal)); 2747 $pos += 2; 2748 } 2749 } else { 2750 $decodedStr .= $charAt; 2751 $pos++; 2752 } 2753 } 2754 return $decodedStr; 2755 } 2756 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |