[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /*+********************************************************************************** 3 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 4 * ("License"); You may not use this file except in compliance with the License 5 * The Original Code is: vtiger CRM Open Source 6 * The Initial Developer of the Original Code is vtiger. 7 * Portions created by vtiger are Copyright (C) vtiger. 8 * All Rights Reserved. 9 ************************************************************************************/ 10 11 12 /** 13 * Functions that need-rewrite / to be eliminated. 14 */ 15 16 class Vtiger_Deprecated { 17 18 static function getFullNameFromQResult($result, $row_count, $module) { 19 global $adb; 20 $rowdata = $adb->query_result_rowdata($result, $row_count); 21 $entity_field_info = getEntityFieldNames($module); 22 $fieldsName = $entity_field_info['fieldname']; 23 $name = ''; 24 if ($rowdata != '' && count($rowdata) > 0) { 25 $name = self::getCurrentUserEntityFieldNameDisplay($module, $fieldsName, $rowdata ); 26 } 27 $name = textlength_check($name); 28 return $name; 29 } 30 31 static function getFullNameFromArray($module, $fieldValues) { 32 $entityInfo = getEntityFieldNames($module); 33 $fieldsName = $entityInfo['fieldname']; 34 $displayName = self::getCurrentUserEntityFieldNameDisplay($module, $fieldsName, $fieldValues); 35 return $displayName; 36 } 37 38 static function getCurrentUserEntityFieldNameDisplay($module, $fieldsName, $fieldValues) { 39 global $current_user; 40 if(!is_array($fieldsName)) { 41 return $fieldValues[$fieldsName]; 42 } else { 43 $accessibleFieldNames = array(); 44 foreach($fieldsName as $field) { 45 if($module == 'Users' || getColumnVisibilityPermission($current_user->id, $field, $module) == '0') { 46 $accessibleFieldNames[] = $fieldValues[$field]; 47 } 48 } 49 if(count($accessibleFieldNames) > 0) { 50 return implode(' ', $accessibleFieldNames); 51 } 52 } 53 return ''; 54 } 55 56 static function getBlockId($tabid, $label) { 57 global $adb; 58 $query = "select blockid from vtiger_blocks where tabid=? and blocklabel = ?"; 59 $result = $adb->pquery($query, array($tabid, $label)); 60 $noofrows = $adb->num_rows($result); 61 62 $blockid = ''; 63 if ($noofrows == 1) { 64 $blockid = $adb->query_result($result, 0, "blockid"); 65 } 66 return $blockid; 67 } 68 69 static function getParentTab() { 70 return ''; 71 72 /*global $log, $default_charset; 73 $log->debug("Entering getParentTab() method ..."); 74 if (!empty($_REQUEST['parenttab'])) { 75 if (self::checkParentTabExists($_REQUEST['parenttab'])) { 76 return vtlib_purify($_REQUEST['parenttab']); 77 } else { 78 return self::getParentTabFromModule($_REQUEST['module']); 79 } 80 } else { 81 return self::getParentTabFromModule($_REQUEST['module']); 82 }*/ 83 } 84 85 static function getParentTabFromModule($module) { 86 return ''; 87 88 /* 89 global $adb; 90 if (file_exists('tabdata.php') && (filesize('tabdata.php') != 0) && file_exists('parent_tabdata.php') && (filesize('parent_tabdata.php') != 0)) { 91 include('tabdata.php'); 92 include('parent_tabdata.php'); 93 $tabid = $tab_info_array[$module]; 94 foreach ($parent_child_tab_rel_array as $parid => $childArr) { 95 if (in_array($tabid, $childArr)) { 96 $parent_tabname = $parent_tab_info_array[$parid]; 97 break; 98 } 99 } 100 return $parent_tabname; 101 } else { 102 $sql = "select vtiger_parenttab.* from vtiger_parenttab inner join vtiger_parenttabrel on vtiger_parenttabrel.parenttabid=vtiger_parenttab.parenttabid inner join vtiger_tab on vtiger_tab.tabid=vtiger_parenttabrel.tabid where vtiger_tab.name=?"; 103 $result = $adb->pquery($sql, array($module)); 104 $tab = $adb->query_result($result, 0, "parenttab_label"); 105 return $tab; 106 }*/ 107 } 108 109 /*static function checkParentTabExists($parenttab) { 110 global $adb; 111 112 if (file_exists('parent_tabdata.php') && (filesize('parent_tabdata.php') != 0)) { 113 include('parent_tabdata.php'); 114 if (in_array($parenttab, $parent_tab_info_array)) 115 return true; 116 else 117 return false; 118 } else { 119 120 $result = "select 1 from vtiger_parenttab where parenttab_label = ?"; 121 $noofrows = $adb->num_rows($result); 122 if ($noofrows > 0) 123 return true; 124 else 125 return false; 126 } 127 }*/ 128 129 static function copyValuesFromRequest($focus) { 130 if (isset($_REQUEST['record'])) { 131 $focus->id = $_REQUEST['record']; 132 } 133 if (isset($_REQUEST['mode'])) { 134 $focus->mode = $_REQUEST['mode']; 135 } 136 foreach ($focus->column_fields as $fieldname => $val) { 137 if (isset($_REQUEST[$fieldname])) { 138 if (is_array($_REQUEST[$fieldname])) 139 $value = $_REQUEST[$fieldname]; 140 else 141 $value = trim($_REQUEST[$fieldname]); 142 $focus->column_fields[$fieldname] = $value; 143 } 144 } 145 } 146 147 static function createModuleMetaFile() { 148 global $adb; 149 150 $sql = "select * from vtiger_tab"; 151 $result = $adb->pquery($sql, array()); 152 $num_rows = $adb->num_rows($result); 153 $result_array = Array(); 154 $seq_array = Array(); 155 $ownedby_array = Array(); 156 157 for ($i = 0; $i < $num_rows; $i++) { 158 $tabid = $adb->query_result($result, $i, 'tabid'); 159 $tabname = $adb->query_result($result, $i, 'name'); 160 $presence = $adb->query_result($result, $i, 'presence'); 161 $ownedby = $adb->query_result($result, $i, 'ownedby'); 162 $result_array[$tabname] = $tabid; 163 $seq_array[$tabid] = $presence; 164 $ownedby_array[$tabid] = $ownedby; 165 } 166 167 //Constructing the actionname=>actionid array 168 $actionid_array = Array(); 169 $sql1 = "select * from vtiger_actionmapping"; 170 $result1 = $adb->pquery($sql1, array()); 171 $num_seq1 = $adb->num_rows($result1); 172 for ($i = 0; $i < $num_seq1; $i++) { 173 $actionname = $adb->query_result($result1, $i, 'actionname'); 174 $actionid = $adb->query_result($result1, $i, 'actionid'); 175 $actionid_array[$actionname] = $actionid; 176 } 177 178 //Constructing the actionid=>actionname array with securitycheck=0 179 $actionname_array = Array(); 180 $sql2 = "select * from vtiger_actionmapping where securitycheck=0"; 181 $result2 = $adb->pquery($sql2, array()); 182 $num_seq2 = $adb->num_rows($result2); 183 for ($i = 0; $i < $num_seq2; $i++) { 184 $actionname = $adb->query_result($result2, $i, 'actionname'); 185 $actionid = $adb->query_result($result2, $i, 'actionid'); 186 $actionname_array[$actionid] = $actionname; 187 } 188 189 $filename = 'tabdata.php'; 190 191 if (file_exists($filename)) { 192 if (is_writable($filename)) { 193 if (!$handle = fopen($filename, 'w+')) { 194 echo "Cannot open file ($filename)"; 195 exit; 196 } 197 require_once ('modules/Users/CreateUserPrivilegeFile.php'); 198 $newbuf = ''; 199 $newbuf .="<?php\n\n"; 200 $newbuf .="\n"; 201 $newbuf .= "//This file contains the commonly used variables \n"; 202 $newbuf .= "\n"; 203 $newbuf .= "\$tab_info_array=" . constructArray($result_array) . ";\n"; 204 $newbuf .= "\n"; 205 $newbuf .= "\$tab_seq_array=" . constructArray($seq_array) . ";\n"; 206 $newbuf .= "\n"; 207 $newbuf .= "\$tab_ownedby_array=" . constructArray($ownedby_array) . ";\n"; 208 $newbuf .= "\n"; 209 $newbuf .= "\$action_id_array=" . constructSingleStringKeyAndValueArray($actionid_array) . ";\n"; 210 $newbuf .= "\n"; 211 $newbuf .= "\$action_name_array=" . constructSingleStringValueArray($actionname_array) . ";\n"; 212 $newbuf .= "?>"; 213 fputs($handle, $newbuf); 214 fclose($handle); 215 } else { 216 echo "The file $filename is not writable"; 217 } 218 } else { 219 echo "The file $filename does not exist"; 220 } 221 } 222 223 static function createModuleGroupMetaFile() { 224 global $adb; 225 $sql = "select parenttabid,parenttab_label from vtiger_parenttab where visible=0 order by sequence"; 226 $result = $adb->pquery($sql, array()); 227 $num_rows = $adb->num_rows($result); 228 $result_array = Array(); 229 for ($i = 0; $i < $num_rows; $i++) { 230 $parenttabid = $adb->query_result($result, $i, 'parenttabid'); 231 $parenttab_label = $adb->query_result($result, $i, 'parenttab_label'); 232 $result_array[$parenttabid] = $parenttab_label; 233 } 234 235 $filename = 'parent_tabdata.php'; 236 237 if (file_exists($filename)) { 238 if (is_writable($filename)) { 239 if (!$handle = fopen($filename, 'w+')) { 240 echo "Cannot open file ($filename)"; 241 exit; 242 } 243 require_once ('modules/Users/CreateUserPrivilegeFile.php'); 244 $newbuf = ''; 245 $newbuf .="<?php\n\n"; 246 $newbuf .="\n"; 247 $newbuf .= "//This file contains the commonly used variables \n"; 248 $newbuf .= "\n"; 249 $newbuf .= "\$parent_tab_info_array=" . constructSingleStringValueArray($result_array) . ";\n"; 250 $newbuf .="\n"; 251 252 $parChildTabRelArray = Array(); 253 254 foreach ($result_array as $parid => $parvalue) { 255 $childArray = Array(); 256 //$sql = "select * from vtiger_parenttabrel where parenttabid=? order by sequence"; 257 // vtlib customization: Disabling the tab item based on presence 258 $sql = "select * from vtiger_parenttabrel where parenttabid=? 259 and tabid in (select tabid from vtiger_tab where presence in (0,2)) order by sequence"; 260 // END 261 $result = $adb->pquery($sql, array($parid)); 262 $num_rows = $adb->num_rows($result); 263 $result_array = Array(); 264 for ($i = 0; $i < $num_rows; $i++) { 265 $tabid = $adb->query_result($result, $i, 'tabid'); 266 $childArray[] = $tabid; 267 } 268 $parChildTabRelArray[$parid] = $childArray; 269 } 270 $newbuf .= "\n"; 271 $newbuf .= "\$parent_child_tab_rel_array=" . constructTwoDimensionalValueArray($parChildTabRelArray) . ";\n"; 272 $newbuf .="\n"; 273 $newbuf .="\n"; 274 $newbuf .="\n"; 275 $newbuf .= "?>"; 276 fputs($handle, $newbuf); 277 fclose($handle); 278 } else { 279 echo "The file $filename is not writable"; 280 } 281 } else { 282 echo "The file $filename does not exist"; 283 } 284 } 285 286 static function getTemplateDetails($templateid) { 287 global $adb; 288 $returndata = Array(); 289 $result = $adb->pquery("select body, subject from vtiger_emailtemplates where templateid=?", array($templateid)); 290 $returndata[] = $templateid; 291 $returndata[] = $adb->query_result($result, 0, 'body'); 292 $returndata[] = $adb->query_result($result, 0, 'subject'); 293 return $returndata; 294 } 295 296 static function getAnnouncements() { 297 global $adb; 298 $sql = " select * from vtiger_announcement inner join vtiger_users on vtiger_announcement.creatorid=vtiger_users.id"; 299 $sql.=" AND vtiger_users.is_admin='on' AND vtiger_users.status='Active' AND vtiger_users.deleted = 0"; 300 $result = $adb->pquery($sql, array()); 301 for ($i = 0; $i < $adb->num_rows($result); $i++) { 302 $announce = getUserFullName($adb->query_result($result, $i, 'creatorid')) . ' : ' . $adb->query_result($result, $i, 'announcement') . ' '; 303 if ($adb->query_result($result, $i, 'announcement') != '') 304 $announcement.=$announce; 305 } 306 307 return $announcement; 308 } 309 310 static function getModuleTranslationStrings($language, $module) { 311 static $cachedModuleStrings = array(); 312 313 if(!empty($cachedModuleStrings[$module])) { 314 return $cachedModuleStrings[$module]; 315 } 316 $newStrings = Vtiger_Language_Handler::getModuleStringsFromFile($language, $module); 317 $cachedModuleStrings[$module] = $newStrings['languageStrings']; 318 319 return $cachedModuleStrings[$module]; 320 } 321 322 static function getTranslatedCurrencyString($str) { 323 global $app_currency_strings; 324 if (isset($app_currency_strings) && isset($app_currency_strings[$str])) { 325 return $app_currency_strings[$str]; 326 } 327 return $str; 328 } 329 330 static function getIdOfCustomViewByNameAll($module) { 331 global $adb; 332 333 static $cvidCache = array(); 334 if (!isset($cvidCache[$module])) { 335 $qry_res = $adb->pquery("select cvid from vtiger_customview where viewname='All' and entitytype=?", array($module)); 336 $cvid = $adb->query_result($qry_res, 0, "cvid"); 337 $cvidCache[$module] = $cvid; 338 } 339 return isset($cvidCache[$module])? $cvidCache[$module] : '0'; 340 } 341 342 static function SaveTagCloudView($id = "") { 343 global $adb; 344 $tag_cloud_status = $_REQUEST['tagcloudview']; 345 if ($tag_cloud_status == "true") { 346 $tag_cloud_view = 0; 347 } else { 348 $tag_cloud_view = 1; 349 } 350 if ($id == '') { 351 $tag_cloud_view = 1; 352 } else { 353 $query = "update vtiger_homestuff set visible = ? where userid=? and stufftype='Tag Cloud'"; 354 $adb->pquery($query, array($tag_cloud_view, $id)); 355 } 356 } 357 358 static function clearSmartyCompiledFiles($path = null) { 359 global $root_directory; 360 if ($path == null) { 361 $path = $root_directory . 'test/templates_c/'; 362 } 363 if(file_exists($path) && is_dir($path)){ 364 $mydir = @opendir($path); 365 while (false !== ($file = readdir($mydir))) { 366 if ($file != "." && $file != ".." && $file != ".svn") { 367 //chmod($path.$file, 0777); 368 if (is_dir($path . $file)) { 369 chdir('.'); 370 clear_smarty_cache($path . $file . '/'); 371 //rmdir($path.$file) or DIE("couldn't delete $path$file<br />"); // No need to delete the directories. 372 } else { 373 // Delete only files ending with .tpl.php 374 if (strripos($file, '.tpl.php') == (strlen($file) - strlen('.tpl.php'))) { 375 unlink($path . $file) or DIE("couldn't delete $path$file<br />"); 376 } 377 } 378 } 379 } 380 @closedir($mydir); 381 } 382 383 } 384 385 static function getSmartyCompiledTemplateFile($template_file, $path = null) { 386 global $root_directory; 387 if ($path == null) { 388 $path = $root_directory . 'test/templates_c/'; 389 } 390 $mydir = @opendir($path); 391 $compiled_file = null; 392 while (false !== ($file = readdir($mydir)) && $compiled_file == null) { 393 if ($file != "." && $file != ".." && $file != ".svn") { 394 //chmod($path.$file, 0777); 395 if (is_dir($path . $file)) { 396 chdir('.'); 397 $compiled_file = get_smarty_compiled_file($template_file, $path . $file . '/'); 398 //rmdir($path.$file) or DIE("couldn't delete $path$file<br />"); // No need to delete the directories. 399 } else { 400 // Check if the file name matches the required template fiel name 401 if (strripos($file, $template_file . '.php') == (strlen($file) - strlen($template_file . '.php'))) { 402 $compiled_file = $path . $file; 403 } 404 } 405 } 406 } 407 @closedir($mydir); 408 return $compiled_file; 409 } 410 411 static function postApplicationMigrationTasks() { 412 self::clearSmartyCompiledFiles(); 413 self::createModuleMetaFile(); 414 self::createModuleMetaFile(); 415 } 416 417 static function checkFileAccessForInclusion($filepath) { 418 global $root_directory; 419 // Set the base directory to compare with 420 $use_root_directory = $root_directory; 421 if (empty($use_root_directory)) { 422 $use_root_directory = realpath(dirname(__FILE__) . '/../../.'); 423 } 424 425 $unsafeDirectories = array('storage', 'cache', 'test'); 426 427 $realfilepath = realpath($filepath); 428 429 /** Replace all \\ with \ first */ 430 $realfilepath = str_replace('\\\\', '\\', $realfilepath); 431 $rootdirpath = str_replace('\\\\', '\\', $use_root_directory); 432 433 /** Replace all \ with / now */ 434 $realfilepath = str_replace('\\', '/', $realfilepath); 435 $rootdirpath = str_replace('\\', '/', $rootdirpath); 436 437 $relativeFilePath = str_replace($rootdirpath, '', $realfilepath); 438 $filePathParts = explode('/', $relativeFilePath); 439 440 if (stripos($realfilepath, $rootdirpath) !== 0 || in_array($filePathParts[0], $unsafeDirectories)) { 441 die("Sorry! Attempt to access restricted file."); 442 } 443 } 444 445 /** Function to check the file deletion within the deletable (safe) directories*/ 446 static function checkFileAccessForDeletion($filepath) { 447 global $root_directory; 448 // Set the base directory to compare with 449 $use_root_directory = $root_directory; 450 if (empty($use_root_directory)) { 451 $use_root_directory = realpath(dirname(__FILE__) . '/../../.'); 452 } 453 454 $safeDirectories = array('storage', 'cache', 'test'); 455 456 $realfilepath = realpath($filepath); 457 458 /** Replace all \\ with \ first */ 459 $realfilepath = str_replace('\\\\', '\\', $realfilepath); 460 $rootdirpath = str_replace('\\\\', '\\', $use_root_directory); 461 462 /** Replace all \ with / now */ 463 $realfilepath = str_replace('\\', '/', $realfilepath); 464 $rootdirpath = str_replace('\\', '/', $rootdirpath); 465 466 $relativeFilePath = str_replace($rootdirpath, '', $realfilepath); 467 $filePathParts = explode('/', $relativeFilePath); 468 469 if (stripos($realfilepath, $rootdirpath) !== 0 || !in_array($filePathParts[0], $safeDirectories)) { 470 die("Sorry! Attempt to access restricted file."); 471 } 472 473 } 474 475 /** Function to check the file access is made within web root directory. */ 476 static function checkFileAccess($filepath) { 477 if (!self::isFileAccessible($filepath)) { 478 die("Sorry! Attempt to access restricted file."); 479 } 480 } 481 482 /** 483 * function to return whether the file access is made within vtiger root directory 484 * and it exists. 485 * @global String $root_directory vtiger root directory as given in config.inc.php file. 486 * @param String $filepath relative path to the file which need to be verified 487 * @return Boolean true if file is a valid file within vtiger root directory, false otherwise. 488 */ 489 static function isFileAccessible($filepath) { 490 global $root_directory; 491 // Set the base directory to compare with 492 $use_root_directory = $root_directory; 493 if (empty($use_root_directory)) { 494 $use_root_directory = realpath(dirname(__FILE__) . '/../../.'); 495 } 496 497 $realfilepath = realpath($filepath); 498 499 /** Replace all \\ with \ first */ 500 $realfilepath = str_replace('\\\\', '\\', $realfilepath); 501 $rootdirpath = str_replace('\\\\', '\\', $use_root_directory); 502 503 /** Replace all \ with / now */ 504 $realfilepath = str_replace('\\', '/', $realfilepath); 505 $rootdirpath = str_replace('\\', '/', $rootdirpath); 506 507 if (stripos($realfilepath, $rootdirpath) !== 0) { 508 return false; 509 } 510 return true; 511 } 512 513 static function getSettingsBlockId($label) { 514 global $adb; 515 $blockid = ''; 516 $query = "select blockid from vtiger_settings_blocks where label = ?"; 517 $result = $adb->pquery($query, array($label)); 518 $noofrows = $adb->num_rows($result); 519 if ($noofrows == 1) { 520 $blockid = $adb->query_result($result, 0, "blockid"); 521 } 522 return $blockid; 523 } 524 525 static function getSqlForNameInDisplayFormat($input, $module, $glue = ' ') { 526 $entity_field_info = Vtiger_Functions::getEntityModuleInfoFieldsFormatted($module); 527 $fieldsName = $entity_field_info['fieldname']; 528 if(is_array($fieldsName)) { 529 foreach($fieldsName as $key => $value) { 530 $formattedNameList[] = $input[$value]; 531 } 532 $formattedNameListString = implode(",'" . $glue . "',", $formattedNameList); 533 } else { 534 $formattedNameListString = $input[$fieldsName]; 535 } 536 $sqlString = "CONCAT(" . $formattedNameListString . ")"; 537 return $sqlString; 538 } 539 540 static function getModuleSequenceNumber($module, $recordId) { 541 global $adb; 542 switch ($module) { 543 case "Invoice": 544 $res = $adb->query("SELECT invoice_no FROM vtiger_invoice WHERE invoiceid = $recordId"); 545 $moduleSeqNo = $adb->query_result($res, 0, 'invoice_no'); 546 break; 547 case "PurchaseOrder": 548 $res = $adb->query("SELECT purchaseorder_no FROM vtiger_purchaseorder WHERE purchaseorderid = $recordId"); 549 $moduleSeqNo = $adb->query_result($res, 0, 'purchaseorder_no'); 550 break; 551 case "Quotes": 552 $res = $adb->query("SELECT quote_no FROM vtiger_quotes WHERE quoteid = $recordId"); 553 $moduleSeqNo = $adb->query_result($res, 0, 'quote_no'); 554 break; 555 case "SalesOrder": 556 $res = $adb->query("SELECT salesorder_no FROM vtiger_salesorder WHERE salesorderid = $recordId"); 557 $moduleSeqNo = $adb->query_result($res, 0, 'salesorder_no'); 558 break; 559 } 560 return $moduleSeqNo; 561 } 562 563 static function getModuleFieldTypeOfDataInfos($tables, $tabid='') { 564 $result = array(); 565 if (!empty($tabid)) { 566 $module = Vtiger_Functions::getModuleName($tabid); 567 $fieldInfos = Vtiger_Functions::getModuleFieldInfos($tabid); 568 foreach ($fieldInfos as $name => $field) { 569 if (($field['displaytype'] == '1' || $field['displaytype'] == '3') && 570 ($field['presence'] == '0' || $field['presence'] == '2')) { 571 572 $label = Vtiger_Functions::getTranslatedString($field['fieldlabel'], $module); 573 $result[$name] = array($label => $field['typeofdata']); 574 } 575 } 576 } else { 577 throw new Exception('Field lookup by table no longer supported'); 578 } 579 580 return $result; 581 } 582 583 static function return_app_list_strings_language($language, $module='Vtiger') { 584 $strings = Vtiger_Language_Handler::getModuleStringsFromFile($language, $module); 585 return $strings['languageStrings']; 586 } 587 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |