[ 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 * TODO need to organize into classes based on functional grouping. 13 */ 14 15 class Vtiger_Functions { 16 17 static function userIsAdministrator($user) { 18 return (isset($user->is_admin) && $user->is_admin == 'on'); 19 } 20 21 static function currentUserJSDateFormat($localformat) { 22 global $current_user; 23 if ($current_user->date_format == 'dd-mm-yyyy') { 24 $dt_popup_fmt = "%d-%m-%Y"; 25 } elseif ($current_user->date_format == 'mm-dd-yyyy') { 26 $dt_popup_fmt = "%m-%d-%Y"; 27 } elseif ($current_user->date_format == 'yyyy-mm-dd') { 28 $dt_popup_fmt = "%Y-%m-%d"; 29 } 30 return $dt_popup_fmt; 31 } 32 33 /** 34 * This function returns the date in user specified format. 35 * limitation is that mm-dd-yyyy and dd-mm-yyyy will be considered same by this API. 36 * As in the date value is on mm-dd-yyyy and user date format is dd-mm-yyyy then the mm-dd-yyyy 37 * value will be return as the API will be considered as considered as in same format. 38 * this due to the fact that this API tries to consider the where given date is in user date 39 * format. we need a better gauge for this case. 40 * @global Users $current_user 41 * @param Date $cur_date_val the date which should a changed to user date format. 42 * @return Date 43 */ 44 static function currentUserDisplayDate($value) { 45 global $current_user; 46 $dat_fmt = $current_user->date_format; 47 if ($dat_fmt == '') { 48 $dat_fmt = 'dd-mm-yyyy'; 49 } 50 $date = new DateTimeField($value); 51 return $date->getDisplayDate(); 52 } 53 54 static function currentUserDisplayDateNew() { 55 global $log, $current_user; 56 $date = new DateTimeField(null); 57 return $date->getDisplayDate($current_user); 58 } 59 60 // i18n 61 static function getTranslatedString($str, $module = '') { 62 return Vtiger_Language_Handler::getTranslatedString($str, $module); 63 } 64 65 // CURRENCY 66 protected static $userIdCurrencyIdCache = array(); 67 68 static function userCurrencyId($userid) { 69 global $adb; 70 if (!isset(self::$userIdCurrencyIdCache[$userid])) { 71 $result = $adb->pquery('SELECT id,currency_id FROM vtiger_users', array()); 72 while ($row = $adb->fetch_array($result)) { 73 self::$userIdCurrencyIdCache[$row['id']] = 74 $row['currency_id']; 75 } 76 } 77 return self::$userIdCurrencyIdCache[$userid]; 78 } 79 80 protected static $currencyInfoCache = array(); 81 82 protected static function getCurrencyInfo($currencyid) { 83 global $adb; 84 if (!isset(self::$currencyInfoCache[$currencyid])) { 85 $result = $adb->pquery('SELECT * FROM vtiger_currency_info', array()); 86 while ($row = $adb->fetch_array($result)) { 87 self::$currencyInfoCache[$row['id']] = $row; 88 } 89 } 90 return self::$currencyInfoCache[$currencyid]; 91 } 92 93 static function getCurrencyName($currencyid, $show_symbol = true) { 94 $currencyInfo = self::getCurrencyInfo($currencyid); 95 if ($show_symbol) { 96 return sprintf("%s : %s", Vtiger_Deprecated::getTranslatedCurrencyString($currencyInfo['currency_name']), $currencyInfo['currency_symbol']); 97 } 98 return $currencyInfo['currency_name']; 99 } 100 101 static function getCurrencySymbolandRate($currencyid) { 102 $currencyInfo = self::getCurrencyInfo($currencyid); 103 $currencyRateSymbol = array( 104 'rate' => $currencyInfo['conversion_rate'], 105 'symbol'=>$currencyInfo['currency_symbol'] 106 ); 107 return $currencyRateSymbol; 108 } 109 110 // MODULE 111 protected static $moduleIdNameCache = array(); 112 protected static $moduleNameIdCache = array(); 113 protected static $moduleIdDataCache = array(); 114 115 protected static function getBasicModuleInfo($mixed) { 116 $id = $name = NULL; 117 if (is_numeric($mixed)) $id = $mixed; 118 else $name = $mixed; 119 $reload = false; 120 if ($name) { 121 if (!isset(self::$moduleNameIdCache[$name])) {$reload = true;} 122 } else if ($id) { 123 if (!isset(self::$moduleIdNameCache[$id])) {$reload = true;} 124 } 125 if ($reload) { 126 global $adb; 127 $result = $adb->pquery('SELECT tabid, name, ownedby FROM vtiger_tab', array()); 128 while ($row = $adb->fetch_array($result)) { 129 self::$moduleIdNameCache[$row['tabid']] = $row; 130 self::$moduleNameIdCache[$row['name']] = $row; 131 } 132 } 133 return $id ? self::$moduleIdNameCache[$id] : self::$moduleNameIdCache[$name]; 134 } 135 136 static function getModuleData($mixed) { 137 $id = $name = NULL; 138 if (is_numeric($mixed)) $id = $mixed; 139 else $name = (string)$mixed; 140 $reload = false; 141 142 if ($name && !isset(self::$moduleNameIdCache[$name])) {$reload = true;} 143 else if ($id && !isset(self::$moduleIdNameCache[$id])) {$reload = true;} 144 else { 145 if (!$id) $id = self::$moduleNameIdCache[$name]['tabid']; 146 if (!isset(self::$moduleIdDataCache[$id])) { $reload = true; } 147 } 148 149 if ($reload) { 150 global $adb; 151 $result = $adb->pquery('SELECT * FROM vtiger_tab', array()); 152 while ($row = $adb->fetch_array($result)) { 153 self::$moduleIdNameCache[$row['tabid']] = $row; 154 self::$moduleNameIdCache[$row['name']] = $row; 155 self::$moduleIdDataCache[$row['tabid']] = $row; 156 } 157 if ($name && isset(self::$moduleNameIdCache[$name])) { 158 $id = self::$moduleNameIdCache[$name]['tabid']; 159 } 160 } 161 return $id ? self::$moduleIdDataCache[$id] : NULL; 162 } 163 164 static function getModuleId($name) { 165 $moduleInfo = self::getBasicModuleInfo($name); 166 return $moduleInfo ? $moduleInfo['tabid'] : NULL; 167 } 168 169 static function getModuleName($id) { 170 $moduleInfo = self::getBasicModuleInfo($id); 171 return $moduleInfo ? $moduleInfo['name'] : NULL; 172 } 173 174 static function getModuleOwner($name) { 175 $moduleInfo = self::getBasicModuleInfo($name); 176 return $moduleInfo ? $moduleInfo['ownedby'] : NULL; 177 } 178 179 protected static $moduleEntityCache = array(); 180 181 static function getEntityModuleInfo($mixed) { 182 $name = NULL; 183 if (is_numeric($mixed)) $name = self::getModuleName ($mixed); 184 else $name = $mixed; 185 186 if ($name && !isset(self::$moduleEntityCache[$name])) { 187 global $adb; 188 $result = $adb->pquery('SELECT fieldname,modulename,tablename,entityidfield,entityidcolumn from vtiger_entityname', array()); 189 while ($row = $adb->fetch_array($result)) { 190 self::$moduleEntityCache[$row['modulename']] = $row; 191 } 192 } 193 194 return isset(self::$moduleEntityCache[$name])? 195 self::$moduleEntityCache[$name] : NULL; 196 } 197 198 static function getEntityModuleSQLColumnString($mixed) { 199 $data = array(); 200 $info = self::getEntityModuleInfo($mixed); 201 if ($info) { 202 $data['tablename'] = $info['tablename']; 203 $fieldnames = $info['fieldname']; 204 if (strpos(',', $fieldnames) !== false) { 205 $fieldnames = sprintf("concat(%s)", implode(",' ',", explode(',', $fieldnames))); 206 } 207 $data['fieldname'] = $fieldnames; 208 } 209 return $data; 210 } 211 212 static function getEntityModuleInfoFieldsFormatted($mixed) { 213 $info = self::getEntityModuleInfo($mixed); 214 $fieldnames = $info ? $info['fieldname'] : NULL; 215 if ($fieldnames && stripos($fieldnames, ',') !== false) { 216 $fieldnames = explode(',', $fieldnames); 217 } 218 $info['fieldname'] = $fieldnames; 219 return $info; 220 } 221 222 // MODULE RECORD 223 protected static $crmRecordIdMetadataCache = array(); 224 225 protected static function getCRMRecordMetadata($mixedid) { 226 global $adb; 227 228 $multimode = is_array($mixedid); 229 230 $ids = $multimode ? $mixedid : array($mixedid); 231 $missing = array(); 232 foreach ($ids as $id) { 233 if ($id && !isset(self::$crmRecordIdMetadataCache[$id])) { 234 $missing[] = $id; 235 } 236 } 237 238 if ($missing) { 239 $sql = sprintf("SELECT crmid, setype, label FROM vtiger_crmentity WHERE %s", implode(' OR ', array_fill(0, count($missing), 'crmid=?'))); 240 $result = $adb->pquery($sql, $missing); 241 while ($row = $adb->fetch_array($result)) { 242 self::$crmRecordIdMetadataCache[$row['crmid']] = $row; 243 } 244 } 245 246 $result = array(); 247 foreach ($ids as $id) { 248 if (isset(self::$crmRecordIdMetadataCache[$id])) { 249 $result[$id] = self::$crmRecordIdMetadataCache[$id]; 250 } else { 251 $result[$id] = NULL; 252 } 253 } 254 255 return $multimode? $result : array_shift($result); 256 } 257 258 static function getCRMRecordType($id) { 259 $metadata = self::getCRMRecordMetadata($id); 260 return $metadata ? $metadata['setype'] : NULL; 261 } 262 263 static function getCRMRecordLabel($id, $default='') { 264 $metadata = self::getCRMRecordMetadata($id); 265 return $metadata ? $metadata['label'] : $default; 266 } 267 268 static function getUserRecordLabel($id, $default='') { 269 $labels = self::getCRMRecordLabels('Users', $id); 270 return isset($labels[$id])? $labels[$id] : $default; 271 } 272 273 static function getGroupRecordLabel($id, $default='') { 274 $labels = self::getCRMRecordLabels('Groups', $id); 275 return isset($labels[$id])? $labels[$id] : $default; 276 } 277 278 static function getCRMRecordLabels($module, $ids) { 279 if (!is_array($ids)) $ids = array($ids); 280 281 if ($module == 'Users' || $module == 'Groups') { 282 // TODO Cache separately? 283 return self::computeCRMRecordLabels($module, $ids); 284 } else { 285 $metadatas = self::getCRMRecordMetadata($ids); 286 $result = array(); 287 foreach ($metadatas as $data) { 288 $result[$data['crmid']] = $data['label']; 289 } 290 return $result; 291 } 292 } 293 294 static function updateCRMRecordLabel($module, $id, $label) { 295 global $adb; 296 $labelInfo = self::computeCRMRecordLabels($module, $id); 297 if ($labelInfo) { 298 $label = decode_html($labelInfo[$id]); 299 $adb->pquery('UPDATE vtiger_crmentity SET label=? WHERE crmid=?', array($label, $id)); 300 self::$crmRecordIdMetadataCache[$id] = array( 301 'setype' => $module, 302 'crmid' => $id, 303 'label' => $labelInfo[$id] 304 ); 305 } 306 } 307 308 static function getOwnerRecordLabel($id) { 309 $result = self::getOwnerRecordLabels($id); 310 return $result ? array_shift($result) : NULL; 311 } 312 313 static function getOwnerRecordLabels($ids) { 314 if (!is_array($ids)) $ids = array($ids); 315 316 $nameList = array(); 317 if ($ids) { 318 $nameList = self::getCRMRecordLabels('Users', $ids); 319 $groups = array(); 320 $diffIds = array_diff($ids, array_keys($nameList)); 321 if ($diffIds) { 322 $groups = self::getCRMRecordLabels('Groups', array_values($diffIds)); 323 } 324 if ($groups) { 325 foreach ($groups as $id => $label) { 326 $nameList[$id] = $label; 327 } 328 } 329 } 330 331 return $nameList; 332 } 333 334 static function computeCRMRecordLabels($module, $ids) { 335 global $adb; 336 337 if (!is_array($ids)) $ids = array($ids); 338 339 if ($module == 'Events') { 340 $module = 'Calendar'; 341 } 342 343 if ($module) { 344 $entityDisplay = array(); 345 346 if ($ids) { 347 348 if ($module == 'Groups') { 349 $metainfo = array('tablename' => 'vtiger_groups','entityidfield' => 'groupid','fieldname' => 'groupname'); 350 } else if ($module == 'DocumentFolders') { 351 $metainfo = array('tablename' => 'vtiger_attachmentsfolder','entityidfield' => 'folderid','fieldname' => 'foldername'); 352 } else { 353 $metainfo = self::getEntityModuleInfo($module); 354 } 355 356 $table = $metainfo['tablename']; 357 $idcolumn = $metainfo['entityidfield']; 358 $columns = explode(',', $metainfo['fieldname']); 359 360 // NOTE: Ignore field-permission check for non-admin (to compute record label). 361 $columnString = count($columns) < 2? $columns[0] : 362 sprintf("concat(%s)", implode(",' ',", $columns)); 363 364 $sql = sprintf('SELECT '. implode(',',$columns).', %s AS id FROM %s WHERE %s IN (%s)', 365 $idcolumn, $table, $idcolumn, generateQuestionMarks($ids)); 366 367 $result = $adb->pquery($sql, $ids); 368 369 while ($row = $adb->fetch_array($result)) { 370 $labelValues = array(); 371 foreach($columns as $columnName) { 372 $labelValues[] = $row[$columnName]; 373 } 374 $entityDisplay[$row['id']] = implode(' ',$labelValues); 375 } 376 } 377 378 return $entityDisplay; 379 } 380 } 381 382 protected static $groupIdNameCache = array(); 383 384 static function getGroupName($id) { 385 global $adb; 386 if (!self::$groupIdNameCache[$id]) { 387 $result = $adb->pquery('SELECT groupid, groupname FROM vtiger_groups'); 388 while ($row = $adb->fetch_array($result)) { 389 self::$groupIdNameCache[$row['groupid']] = $row['groupname']; 390 } 391 } 392 $result = array(); 393 if (isset(self::$groupIdNameCache[$id])) { 394 $result[] = decode_html(self::$groupIdNameCache[$id]); 395 $result[] = $id; 396 } 397 return $result; 398 } 399 400 protected static $userIdNameCache = array(); 401 402 static function getUserName($id) { 403 global $adb; 404 if (!self::$userIdNameCache[$id]) { 405 $result = $adb->pquery('SELECT id, user_name FROM vtiger_users'); 406 while ($row = $adb->fetch_array($result)) { 407 self::$userIdNameCache[$row['id']] = $row['user_name']; 408 } 409 } 410 return (isset(self::$userIdNameCache[$id])) ? self::$userIdNameCache[$id] : NULL; 411 } 412 413 protected static $moduleFieldInfoByNameCache = array(); 414 415 static function getModuleFieldInfos($mixed) { 416 global $adb; 417 418 $moduleInfo = self::getBasicModuleInfo($mixed); 419 $module = $moduleInfo['name']; 420 421 if ($module && !isset(self::$moduleFieldInfoByNameCache[$module])) { 422 $result = 423 ($module == 'Calendar')? 424 $adb->pquery('SELECT * FROM vtiger_field WHERE tabid=? OR tabid=?', array(9, 16)) : 425 $adb->pquery('SELECT * FROM vtiger_field WHERE tabid=?', array(self::getModuleId($module))); 426 427 self::$moduleFieldInfoByNameCache[$module] = array(); 428 while ($row = $adb->fetch_array($result)) { 429 self::$moduleFieldInfoByNameCache[$module][$row['fieldname']] = $row; 430 } 431 } 432 return isset(self::$moduleFieldInfoByNameCache[$module]) ? self::$moduleFieldInfoByNameCache[$module] : NULL; 433 } 434 435 static function getModuleFieldInfoWithId($fieldid) { 436 global $adb; 437 $result = $adb->pquery('SELECT * FROM vtiger_field WHERE fieldid=?', array($fieldid)); 438 return ($adb->num_rows($result))? $adb->fetch_array($result) : NULL; 439 } 440 441 static function getModuleFieldInfo($moduleid, $mixed) { 442 $field = NULL; 443 if (empty($moduleid) && is_numeric($mixed)) { 444 $field = self::getModuleFieldInfoWithId($mixed); 445 } else { 446 $fieldsInfo = self::getModuleFieldInfos($moduleid); 447 if ($fieldsInfo) { 448 if (is_numeric($mixed)) { 449 foreach ($fieldsInfo as $name => $row) { 450 if ($row['fieldid'] == $mixed) { 451 $field = $row; 452 break; 453 } 454 } 455 } else { 456 $field = isset($fieldsInfo[$mixed]) ? $fieldsInfo[$mixed] : NULL; 457 } 458 } 459 } 460 return $field; 461 } 462 463 static function getModuleFieldId($moduleid, $mixed, $onlyactive=true) { 464 $field = self::getModuleFieldInfo($moduleid, $mixed, $onlyactive); 465 466 if ($field) { 467 if ($onlyactive && ($field['presence'] != '0' && $field['presence'] != '2')) { 468 $field = NULL; 469 } 470 } 471 return $field ? $field['fieldid'] : false; 472 } 473 474 475 // Utility 476 static function formatDecimal($value){ 477 $fld_value = explode('.', $value); 478 if($fld_value[1] != ''){ 479 $fld_value = rtrim($value, '0'); 480 $value = rtrim($fld_value, '.'); 481 } 482 return $value; 483 } 484 485 static function fromHTML($string, $encode=true) { 486 if (is_string($string)) { 487 if (preg_match('/(script).*(\/script)/i', $string)) { 488 $string = preg_replace(array('/</', '/>/', '/"/'), array('<', '>', '"'), $string); 489 } 490 } 491 return $string; 492 } 493 494 static function fromHTML_FCK($string) { 495 if (is_string($string)) { 496 if (preg_match('/(script).*(\/script)/i', $string)) { 497 $string = str_replace('script', '', $string); 498 } 499 } 500 return $string; 501 } 502 503 static function fromHTML_Popup($string, $encode = true) { 504 $popup_toHtml = array( 505 '"' => '"', 506 "'" => ''', 507 ); 508 //if($encode && is_string($string))$string = html_entity_decode($string, ENT_QUOTES); 509 if ($encode && is_string($string)) { 510 $string = addslashes(str_replace(array_values($popup_toHtml), array_keys($popup_toHtml), $string)); 511 } 512 return $string; 513 } 514 515 static function br2nl($str) { 516 $str = preg_replace("/(\r\n)/", "\\r\\n", $str); 517 $str = preg_replace("/'/", " ", $str); 518 $str = preg_replace("/\"/", " ", $str); 519 return $str; 520 } 521 522 static function suppressHTMLTags($string) { 523 return preg_replace(array('/</', '/>/', '/"/'), array('<', '>', '"'), $string); 524 } 525 526 static function getInventoryTermsAndCondition() { 527 global $adb; 528 $sql = "select tandc from vtiger_inventory_tandc"; 529 $result = $adb->pquery($sql, array()); 530 $tandc = $adb->query_result($result, 0, "tandc"); 531 return $tandc; 532 } 533 534 static function initStorageFileDirectory() { 535 $filepath = 'storage/'; 536 537 $year = date('Y'); 538 $month = date('F'); 539 $day = date('j'); 540 $week = ''; 541 542 if (!is_dir($filepath . $year)) { 543 //create new folder 544 mkdir($filepath . $year); 545 } 546 547 if (!is_dir($filepath . $year . "/" . $month)) { 548 //create new folder 549 mkdir($filepath . "$year/$month"); 550 } 551 552 if ($day > 0 && $day <= 7) 553 $week = 'week1'; 554 elseif ($day > 7 && $day <= 14) 555 $week = 'week2'; 556 elseif ($day > 14 && $day <= 21) 557 $week = 'week3'; 558 elseif ($day > 21 && $day <= 28) 559 $week = 'week4'; 560 else 561 $week = 'week5'; 562 563 if (!is_dir($filepath . $year . "/" . $month . "/" . $week)) { 564 //create new folder 565 mkdir($filepath . "$year/$month/$week"); 566 } 567 568 $filepath = $filepath . $year . "/" . $month . "/" . $week . "/"; 569 570 return $filepath; 571 } 572 573 static function validateImage($file_details) { 574 global $app_strings; 575 $file_type_details = explode("/", $file_details['type']); 576 $filetype = $file_type_details['1']; 577 if (!empty($filetype)) 578 $filetype = strtolower($filetype); 579 if (($filetype == "jpeg" ) || ($filetype == "png") || ($filetype == "jpg" ) || ($filetype == "pjpeg" ) || ($filetype == "x-png") || ($filetype == "gif") || ($filetype == 'bmp')) { 580 $saveimage = 'true'; 581 } else { 582 $saveimage = 'false'; 583 $_SESSION['image_type_error'] .= "<br> <b>" . $file_details[name] . "</b>" . $app_strings['MSG_IS_NOT_UPLOADED']; 584 } 585 return $saveimage; 586 } 587 588 static function getMergedDescription($description, $id, $parent_type) { 589 global $current_user; 590 $token_data_pair = explode('$', $description); 591 $emailTemplate = new EmailTemplate($parent_type, $description, $id, $current_user); 592 $description = $emailTemplate->getProcessedDescription(); 593 $tokenDataPair = explode('$', $description); 594 $fields = Array(); 595 for ($i = 1; $i < count($token_data_pair); $i+=2) { 596 $module = explode('-', $tokenDataPair[$i]); 597 $fields[$module[0]][] = $module[1]; 598 } 599 if (is_array($fields['custom']) && count($fields['custom']) > 0) { 600 $description = self::getMergedDescriptionCustomVars($fields, $description); 601 } 602 return $description; 603 } 604 605 static function getMergedDescriptionCustomVars($fields, $description) { 606 foreach ($fields['custom'] as $columnname) { 607 $token_data = '$custom-' . $columnname . '$'; 608 $token_value = ''; 609 switch ($columnname) { 610 case 'currentdate': $token_value = date("F j, Y"); 611 break; 612 case 'currenttime': $token_value = date("G:i:s T"); 613 break; 614 } 615 $description = str_replace($token_data, $token_value, $description); 616 } 617 return $description; 618 } 619 620 static function getSingleFieldValue($tablename, $fieldname, $idname, $id) { 621 global $adb; 622 $fieldval = $adb->query_result($adb->pquery("select $fieldname from $tablename where $idname = ?", array($id)), 0, $fieldname); 623 return $fieldval; 624 } 625 626 static function getRecurringObjValue() { 627 $recurring_data = array(); 628 if (isset($_REQUEST['recurringtype']) && $_REQUEST['recurringtype'] != null && $_REQUEST['recurringtype'] != '--None--') { 629 if (!empty($_REQUEST['date_start'])) { 630 $startDate = $_REQUEST['date_start']; 631 } 632 if (!empty($_REQUEST['calendar_repeat_limit_date'])) { 633 $endDate = $_REQUEST['calendar_repeat_limit_date']; 634 $recurring_data['recurringenddate'] = $endDate; 635 } elseif (isset($_REQUEST['due_date']) && $_REQUEST['due_date'] != null) { 636 $endDate = $_REQUEST['due_date']; 637 } 638 if (!empty($_REQUEST['time_start'])) { 639 $startTime = $_REQUEST['time_start']; 640 } 641 if (!empty($_REQUEST['time_end'])) { 642 $endTime = $_REQUEST['time_end']; 643 } 644 645 $recurring_data['startdate'] = $startDate; 646 $recurring_data['starttime'] = $startTime; 647 $recurring_data['enddate'] = $endDate; 648 $recurring_data['endtime'] = $endTime; 649 650 $recurring_data['type'] = $_REQUEST['recurringtype']; 651 if ($_REQUEST['recurringtype'] == 'Weekly') { 652 if (isset($_REQUEST['sun_flag']) && $_REQUEST['sun_flag'] != null) 653 $recurring_data['sun_flag'] = true; 654 if (isset($_REQUEST['mon_flag']) && $_REQUEST['mon_flag'] != null) 655 $recurring_data['mon_flag'] = true; 656 if (isset($_REQUEST['tue_flag']) && $_REQUEST['tue_flag'] != null) 657 $recurring_data['tue_flag'] = true; 658 if (isset($_REQUEST['wed_flag']) && $_REQUEST['wed_flag'] != null) 659 $recurring_data['wed_flag'] = true; 660 if (isset($_REQUEST['thu_flag']) && $_REQUEST['thu_flag'] != null) 661 $recurring_data['thu_flag'] = true; 662 if (isset($_REQUEST['fri_flag']) && $_REQUEST['fri_flag'] != null) 663 $recurring_data['fri_flag'] = true; 664 if (isset($_REQUEST['sat_flag']) && $_REQUEST['sat_flag'] != null) 665 $recurring_data['sat_flag'] = true; 666 } 667 elseif ($_REQUEST['recurringtype'] == 'Monthly') { 668 if (isset($_REQUEST['repeatMonth']) && $_REQUEST['repeatMonth'] != null) 669 $recurring_data['repeatmonth_type'] = $_REQUEST['repeatMonth']; 670 if ($recurring_data['repeatmonth_type'] == 'date') { 671 if (isset($_REQUEST['repeatMonth_date']) && $_REQUEST['repeatMonth_date'] != null) 672 $recurring_data['repeatmonth_date'] = $_REQUEST['repeatMonth_date']; 673 else 674 $recurring_data['repeatmonth_date'] = 1; 675 } 676 elseif ($recurring_data['repeatmonth_type'] == 'day') { 677 $recurring_data['repeatmonth_daytype'] = $_REQUEST['repeatMonth_daytype']; 678 switch ($_REQUEST['repeatMonth_day']) { 679 case 0 : 680 $recurring_data['sun_flag'] = true; 681 break; 682 case 1 : 683 $recurring_data['mon_flag'] = true; 684 break; 685 case 2 : 686 $recurring_data['tue_flag'] = true; 687 break; 688 case 3 : 689 $recurring_data['wed_flag'] = true; 690 break; 691 case 4 : 692 $recurring_data['thu_flag'] = true; 693 break; 694 case 5 : 695 $recurring_data['fri_flag'] = true; 696 break; 697 case 6 : 698 $recurring_data['sat_flag'] = true; 699 break; 700 } 701 } 702 } 703 if (isset($_REQUEST['repeat_frequency']) && $_REQUEST['repeat_frequency'] != null) 704 $recurring_data['repeat_frequency'] = $_REQUEST['repeat_frequency']; 705 706 $recurObj = RecurringType::fromUserRequest($recurring_data); 707 return $recurObj; 708 } 709 } 710 711 static function getTicketComments($ticketid) { 712 global $adb; 713 $moduleName = getSalesEntityType($ticketid); 714 $commentlist = ''; 715 $sql = "SELECT commentcontent FROM vtiger_modcomments WHERE related_to = ?"; 716 $result = $adb->pquery($sql, array($ticketid)); 717 for ($i = 0; $i < $adb->num_rows($result); $i++) { 718 $comment = $adb->query_result($result, $i, 'commentcontent'); 719 if ($comment != '') { 720 $commentlist .= '<br><br>' . $comment; 721 } 722 } 723 if ($commentlist != '') 724 $commentlist = '<br><br>' . getTranslatedString("The comments are", $moduleName) . ' : ' . $commentlist; 725 return $commentlist; 726 } 727 728 static function generateRandomPassword() { 729 $salt = "abcdefghijklmnopqrstuvwxyz0123456789"; 730 srand((double) microtime() * 1000000); 731 $i = 0; 732 while ($i <= 7) { 733 $num = rand() % 33; 734 $tmp = substr($salt, $num, 1); 735 $pass = $pass . $tmp; 736 $i++; 737 } 738 return $pass; 739 } 740 741 static function getTagCloudView($id = "") { 742 global $adb; 743 if ($id == '') { 744 $tag_cloud_status = 1; 745 } else { 746 $query = "select visible from vtiger_homestuff where userid=? and stufftype='Tag Cloud'"; 747 $tag_cloud_status = $adb->query_result($adb->pquery($query, array($id)), 0, 'visible'); 748 } 749 750 if ($tag_cloud_status == 0) { 751 $tag_cloud_view = 'true'; 752 } else { 753 $tag_cloud_view = 'false'; 754 } 755 return $tag_cloud_view; 756 } 757 758 static function transformFieldTypeOfData($table_name, $column_name, $type_of_data) { 759 $field = $table_name . ":" . $column_name; 760 //Add the field details in this array if you want to change the advance filter field details 761 762 static $new_field_details = Array( 763 //Contacts Related Fields 764 "vtiger_contactdetails:accountid" => "V", 765 "vtiger_contactsubdetails:birthday" => "D", 766 "vtiger_contactdetails:email" => "V", 767 "vtiger_contactdetails:secondaryemail" => "V", 768 //Potential Related Fields 769 "vtiger_potential:campaignid" => "V", 770 //Account Related Fields 771 "vtiger_account:parentid" => "V", 772 "vtiger_account:email1" => "V", 773 "vtiger_account:email2" => "V", 774 //Lead Related Fields 775 "vtiger_leaddetails:email" => "V", 776 "vtiger_leaddetails:secondaryemail" => "V", 777 //Documents Related Fields 778 "vtiger_senotesrel:crmid" => "V", 779 //Calendar Related Fields 780 "vtiger_seactivityrel:crmid" => "V", 781 "vtiger_seactivityrel:contactid" => "V", 782 "vtiger_recurringevents:recurringtype" => "V", 783 //HelpDesk Related Fields 784 "vtiger_troubletickets:parent_id" => "V", 785 "vtiger_troubletickets:product_id" => "V", 786 //Product Related Fields 787 "vtiger_products:discontinued" => "C", 788 "vtiger_products:vendor_id" => "V", 789 "vtiger_products:parentid" => "V", 790 //Faq Related Fields 791 "vtiger_faq:product_id" => "V", 792 //Vendor Related Fields 793 "vtiger_vendor:email" => "V", 794 //Quotes Related Fields 795 "vtiger_quotes:potentialid" => "V", 796 "vtiger_quotes:inventorymanager" => "V", 797 "vtiger_quotes:accountid" => "V", 798 //Purchase Order Related Fields 799 "vtiger_purchaseorder:vendorid" => "V", 800 "vtiger_purchaseorder:contactid" => "V", 801 //SalesOrder Related Fields 802 "vtiger_salesorder:potentialid" => "V", 803 "vtiger_salesorder:quoteid" => "V", 804 "vtiger_salesorder:contactid" => "V", 805 "vtiger_salesorder:accountid" => "V", 806 //Invoice Related Fields 807 "vtiger_invoice:salesorderid" => "V", 808 "vtiger_invoice:contactid" => "V", 809 "vtiger_invoice:accountid" => "V", 810 //Campaign Related Fields 811 "vtiger_campaign:product_id" => "V", 812 //Related List Entries(For Report Module) 813 "vtiger_activityproductrel:activityid" => "V", 814 "vtiger_activityproductrel:productid" => "V", 815 "vtiger_campaigncontrel:campaignid" => "V", 816 "vtiger_campaigncontrel:contactid" => "V", 817 "vtiger_campaignleadrel:campaignid" => "V", 818 "vtiger_campaignleadrel:leadid" => "V", 819 "vtiger_cntactivityrel:contactid" => "V", 820 "vtiger_cntactivityrel:activityid" => "V", 821 "vtiger_contpotentialrel:contactid" => "V", 822 "vtiger_contpotentialrel:potentialid" => "V", 823 "vtiger_pricebookproductrel:pricebookid" => "V", 824 "vtiger_pricebookproductrel:productid" => "V", 825 "vtiger_seactivityrel:crmid" => "V", 826 "vtiger_seactivityrel:activityid" => "V", 827 "vtiger_senotesrel:crmid" => "V", 828 "vtiger_senotesrel:notesid" => "V", 829 "vtiger_seproductsrel:crmid" => "V", 830 "vtiger_seproductsrel:productid" => "V", 831 "vtiger_seticketsrel:crmid" => "V", 832 "vtiger_seticketsrel:ticketid" => "V", 833 "vtiger_vendorcontactrel:vendorid" => "V", 834 "vtiger_vendorcontactrel:contactid" => "V", 835 "vtiger_pricebook:currency_id" => "V", 836 ); 837 838 //If the Fields details does not match with the array, then we return the same typeofdata 839 if (isset($new_field_details[$field])) { 840 $type_of_data = $new_field_details[$field]; 841 } 842 return $type_of_data; 843 } 844 845 static function getPickListValuesFromTableForRole($tablename, $roleid) { 846 global $adb; 847 $query = "select $tablename from vtiger_$tablename inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_$tablename.picklist_valueid where roleid=? and picklistid in (select picklistid from vtiger_picklist) order by sortid"; 848 $result = $adb->pquery($query, array($roleid)); 849 $fldVal = Array(); 850 while ($row = $adb->fetch_array($result)) { 851 $fldVal [] = $row[$tablename]; 852 } 853 return $fldVal; 854 } 855 856 static function getActivityType($id) { 857 global $adb; 858 $query = "select activitytype from vtiger_activity where activityid=?"; 859 $res = $adb->pquery($query, array($id)); 860 $activity_type = $adb->query_result($res, 0, "activitytype"); 861 return $activity_type; 862 } 863 864 static function getInvoiceStatus($id) { 865 global $adb; 866 $result = $adb->pquery("SELECT invoicestatus FROM vtiger_invoice where invoiceid=?", array($id)); 867 $invoiceStatus = $adb->query_result($result,0,'invoicestatus'); 868 return $invoiceStatus; 869 } 870 871 static function mkCountQuery($query) { 872 // Remove all the \n, \r and white spaces to keep the space between the words consistent. 873 // This is required for proper pattern matching for words like ' FROM ', 'ORDER BY', 'GROUP BY' as they depend on the spaces between the words. 874 $query = preg_replace("/[\n\r\s]+/"," ",$query); 875 876 //Strip of the current SELECT fields and replace them by "select count(*) as count" 877 // Space across FROM has to be retained here so that we do not have a clash with string "from" found in select clause 878 $query = "SELECT count(*) AS count ".substr($query, stripos($query,' FROM '),strlen($query)); 879 880 //Strip of any "GROUP BY" clause 881 if(stripos($query,'GROUP BY') > 0) 882 $query = substr($query, 0, stripos($query,'GROUP BY')); 883 884 //Strip of any "ORDER BY" clause 885 if(stripos($query,'ORDER BY') > 0) 886 $query = substr($query, 0, stripos($query,'ORDER BY')); 887 888 return $query; 889 } 890 891 /** Function to get unitprice for a given product id 892 * @param $productid -- product id :: Type integer 893 * @returns $up -- up :: Type string 894 */ 895 static function getUnitPrice($productid, $module='Products') { 896 $adb = PearDatabase::getInstance(); 897 if($module == 'Services') { 898 $query = "select unit_price from vtiger_service where serviceid=?"; 899 } else { 900 $query = "select unit_price from vtiger_products where productid=?"; 901 } 902 $result = $adb->pquery($query, array($productid)); 903 $unitpice = $adb->query_result($result,0,'unit_price'); 904 return $unitpice; 905 } 906 }
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 |