[ 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 class Vtiger_Util_Helper { 12 /** 13 * Function used to transform mulitiple uploaded file information into useful format. 14 * @param array $_files - ex: array( 'file' => array('name'=> array(0=>'name1',1=>'name2'), 15 * array('type'=>array(0=>'type1',2=>'type2'), 16 * ...); 17 * @param type $top 18 * @return array array( 'file' => array(0=> array('name'=> 'name1','type' => 'type1'), 19 * array(1=> array('name'=> 'name2','type' => 'type2'), 20 * ...); 21 */ 22 public static function transformUploadedFiles(array $_files, $top = TRUE) { 23 $files = array(); 24 foreach($_files as $name=>$file) { 25 if($top) $subName = $file['name']; 26 else $subName = $name; 27 28 if(is_array($subName)) { 29 foreach(array_keys($subName) as $key) { 30 $files[$name][$key] = array( 31 'name' => $file['name'][$key], 32 'type' => $file['type'][$key], 33 'tmp_name' => $file['tmp_name'][$key], 34 'error' => $file['error'][$key], 35 'size' => $file['size'][$key], 36 ); 37 $files[$name] = self::transformUploadedFiles($files[$name], FALSE); 38 } 39 }else { 40 $files[$name] = $file; 41 } 42 } 43 return $files; 44 } 45 46 /** 47 * Function parses date into readable format 48 * @param <Date Time> $dateTime 49 * @return <String> 50 */ 51 public static function formatDateDiffInStrings($dateTime) { 52 // http://www.php.net/manual/en/datetime.diff.php#101029 53 $currentDateTime = date('Y-m-d H:i:s'); 54 55 $seconds = strtotime($currentDateTime) - strtotime($dateTime); 56 57 if ($seconds == 0) return vtranslate('LBL_JUSTNOW'); 58 if ($seconds > 0) { 59 $prefix = ''; 60 $suffix = ' '. vtranslate('LBL_AGO'); 61 } else if ($seconds < 0) { 62 $prefix = vtranslate('LBL_DUE') . ' '; 63 $suffix = ''; 64 $seconds = -($seconds); 65 } 66 67 $minutes = floor($seconds/60); 68 $hours = floor($minutes/60); 69 $days = floor($hours/24); 70 $months = floor($days/30); 71 72 if ($seconds < 60) return $prefix . self::pluralize($seconds, "LBL_SECOND") . $suffix; 73 if ($minutes < 60) return $prefix . self::pluralize($minutes, "LBL_MINUTE") . $suffix; 74 if ($hours < 24) return $prefix . self::pluralize($hours, "LBL_HOUR") . $suffix; 75 if ($days < 30) return $prefix . self::pluralize($days, "LBL_DAY") . $suffix; 76 if ($months < 12) return $prefix . self::pluralize($months, "LBL_MONTH") . $suffix; 77 if ($months > 11) return $prefix . self::pluralize(floor($days/365), "LBL_YEAR") . $suffix; 78 } 79 80 /** 81 * Function returns singular or plural text 82 * @param <Number> $count 83 * @param <String> $text 84 * @return <String> 85 */ 86 public static function pluralize($count, $text) { 87 return $count ." ". (($count == 1) ? vtranslate("$text") : vtranslate("$text}S")); 88 } 89 90 /** 91 * Function to make the input safe to be used as HTML 92 */ 93 public static function toSafeHTML($input) { 94 global $default_charset; 95 return htmlentities($input, ENT_QUOTES, $default_charset); 96 } 97 98 /** 99 * Function that will strip all the tags while displaying 100 * @param <String> $input - html data 101 * @return <String> vtiger6 displayable data 102 */ 103 public static function toVtiger6SafeHTML($input) { 104 $allowableTags = '<a><br>'; 105 return strip_tags($input, $allowableTags); 106 } 107 /** 108 * Function to validate the input with given pattern. 109 * @param <String> $string 110 * @param <Boolean> $skipEmpty Skip the check if string is empty. 111 * @return <String> 112 * @throws AppException 113 */ 114 public static function validateStringForSql($string, $skipEmpty=true) { 115 if (vtlib_purifyForSql($string, $skipEmpty)) { 116 return $string; 117 } 118 return false; 119 } 120 121 /** 122 * Function Checks the existence of the record 123 * @param <type> $recordId - module recordId 124 * returns 1 if record exists else 0 125 */ 126 public static function checkRecordExistance($recordId){ 127 global $adb; 128 $query = 'Select deleted from vtiger_crmentity where crmid=?'; 129 $result = $adb->pquery($query, array($recordId)); 130 return $adb->query_result($result, 'deleted'); 131 } 132 133 /** 134 * Function to parses date into string format 135 * @param <Date> $date 136 * @param <Time> $time 137 * @return <String> 138 */ 139 public static function formatDateIntoStrings($date, $time = false) { 140 $currentUser = Users_Record_Model::getCurrentUserModel(); 141 $dateTimeInUserFormat = Vtiger_Datetime_UIType::getDisplayDateTimeValue($date . ' ' . $time); 142 143 list($dateInUserFormat, $timeInUserFormat) = explode(' ', $dateTimeInUserFormat); 144 list($hours, $minutes, $seconds) = explode(':', $timeInUserFormat); 145 146 $displayTime = $hours .':'. $minutes; 147 if ($currentUser->get('hour_format') === '12') { 148 $displayTime = Vtiger_Time_UIType::getTimeValueInAMorPM($displayTime); 149 } 150 151 $today = Vtiger_Date_UIType::getDisplayDateValue(date('Y-m-d H:i:s')); 152 $tomorrow = Vtiger_Date_UIType::getDisplayDateValue(date('Y-m-d H:i:s', strtotime('tomorrow'))); 153 154 if ($dateInUserFormat == $today) { 155 $formatedDate = vtranslate('LBL_TODAY'); 156 if ($time) { 157 $formatedDate .= ' '. vtranslate('LBL_AT') .' '. $displayTime; 158 } 159 } elseif ($dateInUserFormat == $tomorrow) { 160 $formatedDate = vtranslate('LBL_TOMORROW'); 161 if ($time) { 162 $formatedDate .= ' '. vtranslate('LBL_AT') .' '. $displayTime; 163 } 164 } else { 165 /** 166 * To support strtotime() for 'mm-dd-yyyy' format the seperator should be '/' 167 * For more referrences 168 * http://php.net/manual/en/datetime.formats.date.php 169 */ 170 if ($currentUser->get('date_format') === 'mm-dd-yyyy') { 171 $dateInUserFormat = str_replace('-', '/', $dateInUserFormat); 172 } 173 174 $date = strtotime($dateInUserFormat); 175 $formatedDate = vtranslate('LBL_'.date('D', $date)) . ' ' . date('d', $date) . ' ' . vtranslate('LBL_'.date('M', $date)); 176 if (date('Y', $date) != date('Y')) { 177 $formatedDate .= ', '.date('Y', $date); 178 } 179 } 180 return $formatedDate; 181 } 182 183 /** 184 * Function to replace spaces with under scores 185 * @param <String> $string 186 * @return <String> 187 */ 188 public static function replaceSpaceWithUnderScores($string) { 189 return str_replace(' ', '_', $string); 190 } 191 192 public static function getRecordName ($recordId, $checkDelete=false) { 193 $adb = PearDatabase::getInstance(); 194 195 $query = 'SELECT label from vtiger_crmentity where crmid=?'; 196 if($checkDelete) { 197 $query.= ' AND deleted=0'; 198 } 199 $result = $adb->pquery($query,array($recordId)); 200 201 $num_rows = $adb->num_rows($result); 202 if($num_rows) { 203 return $adb->query_result($result,0,'label'); 204 } 205 return false; 206 } 207 208 /** 209 * Function to parse dateTime into Days 210 * @param <DateTime> $dateTime 211 * @return <String> 212 */ 213 public static function formatDateTimeIntoDayString($dateTime) { 214 $currentUser = Users_Record_Model::getCurrentUserModel(); 215 $dateTimeInUserFormat = Vtiger_Datetime_UIType::getDisplayDateTimeValue($dateTime); 216 217 list($dateInUserFormat, $timeInUserFormat) = explode(' ', $dateTimeInUserFormat); 218 list($hours, $minutes, $seconds) = explode(':', $timeInUserFormat); 219 220 $displayTime = $hours .':'. $minutes; 221 if ($currentUser->get('hour_format') === '12') { 222 $displayTime = Vtiger_Time_UIType::getTimeValueInAMorPM($displayTime); 223 } 224 225 /** 226 * To support strtotime() for 'mm-dd-yyyy' format the seperator should be '/' 227 * For more referrences 228 * http://php.net/manual/en/datetime.formats.date.php 229 */ 230 if ($currentUser->get('date_format') === 'mm-dd-yyyy') { 231 $dateInUserFormat = str_replace('-', '/', $dateInUserFormat); 232 } 233 234 $date = strtotime($dateInUserFormat); 235 //Adding date details 236 $formatedDate = vtranslate('LBL_'.date('D', $date)). ', ' .vtranslate('LBL_'.date('M', $date)). ' ' .date('d', $date). ', ' .date('Y', $date); 237 //Adding time details 238 $formatedDate .= ' ' .vtranslate('LBL_AT'). ' ' .$displayTime; 239 240 return $formatedDate; 241 } 242 243 /** 244 * Function to get picklist key for a picklist 245 */ 246 public static function getPickListId($fieldName){ 247 $pickListIds = array('opportunity_type' => 'opptypeid', 248 'sales_stage' => 'sales_stage_id', 249 'rating' => 'rating_id', 250 'ticketpriorities' => 'ticketpriorities_id', 251 'ticketseverities' => 'ticketseverities_id', 252 'ticketstatus' => 'ticketstatus_id', 253 'ticketcategories' => 'ticketcategories_id', 254 'salutationtype' => 'salutationid', 255 'faqstatus' => 'faqstatus_id', 256 'faqcategories' => 'faqcategories_id', 257 'recurring_frequency'=> 'recurring_frequency_id', 258 'payment_duration' => 'payment_duration_id', 259 'language' => 'id', 260 'recurringtype' => 'recurringeventid', 261 'duration_minutes' => 'minutesid' 262 ); 263 if(array_key_exists($fieldName, $pickListIds)){ 264 return $pickListIds[$fieldName]; 265 } 266 return $fieldName.'id'; 267 } 268 269 /** 270 * Function which will give the picklist values for a field 271 * @param type $fieldName -- string 272 * @return type -- array of values 273 */ 274 public static function getPickListValues($fieldName) { 275 $cache = Vtiger_Cache::getInstance(); 276 if($cache->getPicklistValues($fieldName)) { 277 return $cache->getPicklistValues($fieldName); 278 } 279 $db = PearDatabase::getInstance(); 280 281 $primaryKey = Vtiger_Util_Helper::getPickListId($fieldName); 282 $query = 'SELECT '.$primaryKey.', '.$fieldName.' FROM vtiger_'.$fieldName.' order by sortorderid'; 283 $values = array(); 284 $result = $db->pquery($query, array()); 285 $num_rows = $db->num_rows($result); 286 for($i=0; $i<$num_rows; $i++) { 287 //Need to decode the picklist values twice which are saved from old ui 288 $values[$db->query_result($result,$i,$primaryKey)] = decode_html(decode_html($db->query_result($result,$i,$fieldName))); 289 } 290 $cache->setPicklistValues($fieldName, $values); 291 return $values; 292 } 293 294 /** 295 * Function gets the CRM's base Currency information 296 * @return Array 297 */ 298 public static function getBaseCurrency() { 299 $db = PearDatabase::getInstance(); 300 $result = $db->pquery('SELECT * FROM vtiger_currency_info WHERE defaultid < 0', array()); 301 if($db->num_rows($result)) return $db->query_result_rowdata($result, 0); 302 } 303 304 /** 305 * Function to get role based picklist values 306 * @param <String> $fieldName 307 * @param <Integer> $roleId 308 * @return <Array> list of role based picklist values 309 */ 310 public static function getRoleBasedPicklistValues($fieldName, $roleId) { 311 $db = PearDatabase::getInstance(); 312 313 $query = "SELECT $fieldName 314 FROM vtiger_$fieldName 315 INNER JOIN vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_$fieldName.picklist_valueid 316 WHERE roleid=? and picklistid in (select picklistid from vtiger_picklist) order by sortorderid"; 317 $result = $db->pquery($query, array($roleId)); 318 $picklistValues = Array(); 319 if($db->num_rows($result) > 0) { 320 while ($row = $db->fetch_array($result)) { 321 //Need to decode the picklist values twice which are saved from old ui 322 $picklistValues[] = decode_html(decode_html($row[$fieldName])); 323 } 324 } 325 return $picklistValues; 326 } 327 328 /** 329 * Function to sanitize the uploaded file name 330 * @param <String> $fileName 331 * @param <Array> $badFileExtensions 332 * @return <String> sanitized file name 333 */ 334 public static function sanitizeUploadFileName($fileName, $badFileExtensions) { 335 $fileName = preg_replace('/\s+/', '_', $fileName);//replace space with _ in filename 336 $fileName = rtrim($fileName, '\\/<>?*:"<>|'); 337 338 $fileNameParts = explode('.', $fileName); 339 $countOfFileNameParts = count($fileNameParts); 340 $badExtensionFound = false; 341 342 for ($i=0; $i<$countOfFileNameParts; $i++) { 343 $partOfFileName = $fileNameParts[$i]; 344 if(in_array(strtolower($partOfFileName), $badFileExtensions)) { 345 $badExtensionFound = true; 346 $fileNameParts[$i] = $partOfFileName . 'file'; 347 } 348 } 349 350 $newFileName = implode('.', $fileNameParts); 351 if ($badExtensionFound) { 352 $newFileName .= ".txt"; 353 } 354 return $newFileName; 355 } 356 357 /** 358 * Function to get maximum upload size 359 * @return <Float> maximum upload size 360 */ 361 public static function getMaxUploadSize() { 362 return ceil(vglobal('upload_maxsize') / (1024 * 1024)); 363 } 364 365 /** 366 * Function to get Owner name for ownerId 367 * @param <Integer> $ownerId 368 * @return <String> $ownerName 369 */ 370 public static function getOwnerName($ownerId) { 371 $cache = Vtiger_Cache::getInstance(); 372 if ($cache->hasOwnerDbName($ownerId)) { 373 return $cache->getOwnerDbName($ownerId); 374 } 375 376 $ownerModel = Users_Record_Model::getInstanceById($ownerId, 'Users'); 377 $userName = $ownerModel->get('user_name'); 378 $ownerName = ''; 379 if ($userName) { 380 $ownerName = $userName; 381 } else { 382 $ownerModel = Settings_Groups_Record_Model::getInstance($ownerId); 383 if(!empty($ownerModel)) { 384 $ownerName = $ownerModel->getName(); 385 } 386 } 387 if(!empty($ownerName)) { 388 $cache->setOwnerDbName($ownerId, $ownerName); 389 } 390 return $ownerName; 391 } 392 393 /** 394 * Function decodes the utf-8 characters 395 * @param <String> $string 396 * @return <String> 397 */ 398 public static function getDecodedValue($string) { 399 return html_entity_decode($string, ENT_COMPAT, 'UTF-8'); 400 } 401 402 public static function getActiveAdminCurrentDateTime() { 403 global $default_timezone; 404 $admin = Users::getActiveAdminUser(); 405 $adminTimeZone = $admin->time_zone; 406 @date_default_timezone_set($adminTimeZone); 407 $date = date('Y-m-d H:i:s'); 408 @date_default_timezone_set($default_timezone); 409 return $date; 410 } 411 /** 412 * Function to get Creator of this record 413 * @param <Integer> $recordId 414 * @return <Integer> 415 */ 416 public static function getCreator($recordId) { 417 $cache = Vtiger_Cache::getInstance(); 418 if ($cache->hasCreator($recordId)) { 419 return $cache->getCreator($recordId); 420 } 421 422 $db = PearDatabase::getInstance(); 423 $result = $db->pquery('SELECT smcreatorid FROM vtiger_crmentity WHERE crmid = ?', array($recordId)); 424 $creatorId = $db->query_result($result, 0, 'smcreatorid'); 425 426 if ($creatorId) { 427 $cache->setCreator($recordId, $creatorId); 428 } 429 return $creatorId; 430 } 431 432 433 /** 434 * Function to get the datetime value in user preferred hour format 435 * @param <DateTime> $dateTime 436 * @param <Vtiger_Users_Model> $userObject 437 * @return <String> date and time with hour format 438 */ 439 public static function convertDateTimeIntoUsersDisplayFormat($dateTime, $userObject = null) { 440 require_once 'includes/runtime/LanguageHandler.php'; 441 require_once 'includes/runtime/Globals.php'; 442 if ($userObject) { 443 $userModel = Users_Privileges_Model::getInstanceFromUserObject($userObject); 444 } else { 445 $userModel = Users_Privileges_Model::getCurrentUserModel(); 446 } 447 448 $date = new DateTime($dateTime); 449 $dateTimeField = new DateTimeField($date->format('Y-m-d H:i:s')); 450 451 $date = $dateTimeField->getDisplayDate($userModel); 452 $time = $dateTimeField->getDisplayTime($userModel); 453 454 if($userModel->get('hour_format') == '12') { 455 $time = Vtiger_Time_UIType::getTimeValueInAMorPM($time); 456 } 457 458 return $date . ' ' .$time; 459 } 460 461 /** 462 * Function to get the time value in user preferred hour format 463 * @param <Time> $time 464 * @param <Vtiger_Users_Model> $userObject 465 * @return <String> time with hour format 466 */ 467 public static function convertTimeIntoUsersDisplayFormat($time, $userObject = null) { 468 require_once 'includes/runtime/LanguageHandler.php'; 469 require_once 'includes/runtime/Globals.php'; 470 if ($userObject) { 471 $userModel = Users_Privileges_Model::getInstanceFromUserObject($userObject); 472 } else { 473 $userModel = Users_Privileges_Model::getCurrentUserModel(); 474 } 475 476 if($userModel->get('hour_format') == '12') { 477 $time = Vtiger_Time_UIType::getTimeValueInAMorPM($time); 478 } 479 480 return $time; 481 } 482 483 /*** 484 * Function to get the label of the record 485 * @param <Integer> $recordId - id of the record 486 * @param <Boolean> $ignoreDelete - false if you want to get label for deleted records 487 */ 488 public static function getLabel($recordId , $ignoreDelete=true){ 489 $db = PearDatabase::getInstance(); 490 $query = 'SELECT label from vtiger_crmentity WHERE crmid=?'; 491 if($ignoreDelete) { 492 $query .= ' AND deleted=0'; 493 } 494 $result = $db->pquery($query,array($recordId)); 495 $name = ''; 496 if($db->num_rows($result) > 0) { 497 $name = $db->query_result($result,0,'label'); 498 } 499 return $name; 500 } 501 502 /** 503 * Function gets the CRM's base Currency information according to user preference 504 * @return Array 505 */ 506 public static function getCurrentInfoOfUser() { 507 $db = PearDatabase::getInstance(); 508 $currentUser = Users_Record_Model::getCurrentUserModel(); 509 $result = $db->pquery('SELECT * FROM vtiger_currency_info WHERE id = ?', array($currentUser->get('currency_id'))); 510 if($db->num_rows($result)) return $db->query_result_rowdata($result, 0); 511 } 512 513 public static function getGroupsIdsForUsers($userId) { 514 vimport('~~/include/utils/GetUserGroups.php'); 515 516 $userGroupInstance = new GetUserGroups(); 517 $userGroupInstance->getAllUserGroups($userId); 518 return $userGroupInstance->user_groups; 519 } 520 521 public static function transferListSearchParamsToFilterCondition($listSearchParams, $moduleModel) { 522 if(empty($listSearchParams)) { 523 $listSearchParams = array(); 524 } 525 $advFilterConditionFormat = array(); 526 $glueOrder = array('and','or'); 527 $groupIterator = 0; 528 foreach($listSearchParams as $groupInfo){ 529 if(empty($groupInfo)){ 530 continue; 531 } 532 $groupConditionInfo = array(); 533 $groupColumnsInfo = array(); 534 $groupConditionGlue = $glueOrder[$groupIterator]; 535 foreach($groupInfo as $fieldSearchInfo){ 536 $advFilterFieldInfoFormat = array(); 537 $fieldName = $fieldSearchInfo[0]; 538 $operator = $fieldSearchInfo[1]; 539 $fieldValue = $fieldSearchInfo[2]; 540 $fieldInfo = $moduleModel->getField($fieldName); 541 542 //Request will be having in terms of AM and PM but the database will be having in 24 hr format so converting 543 //Database format 544 545 if($fieldInfo->getFieldDataType() == "time") { 546 $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue); 547 } 548 549 if($fieldName == 'date_start' || $fieldName == 'due_date' || $fieldInfo->getFieldDataType() == "datetime" ) { 550 $dateValues = explode(',', $fieldValue); 551 //Indicate whether it is fist date in the between condition 552 $isFirstDate = true; 553 foreach($dateValues as $key => $dateValue) { 554 $dateTimeCompoenents = explode(' ', $dateValue); 555 if(empty($dateTimeCompoenents[1])) { 556 if($isFirstDate) 557 $dateTimeCompoenents[1] = '00:00:00'; 558 else 559 $dateTimeCompoenents[1] = '23:59:59'; 560 561 } 562 $dateValue = implode(' ',$dateTimeCompoenents); 563 $dateValues[$key] = $dateValue; 564 $isFirstDate = false; 565 } 566 $fieldValue = implode(',',$dateValues); 567 } 568 569 $advFilterFieldInfoFormat['columnname'] = $fieldInfo->getCustomViewColumnName(); 570 $advFilterFieldInfoFormat['comparator'] = $operator; 571 $advFilterFieldInfoFormat['value'] = $fieldValue; 572 $advFilterFieldInfoFormat['column_condition'] = $groupConditionGlue; 573 $groupColumnsInfo[] = $advFilterFieldInfoFormat; 574 } 575 $noOfConditions = count($groupColumnsInfo); 576 //to remove the last column condition 577 $groupColumnsInfo[$noOfConditions-1]['column_condition'] = ''; 578 $groupConditionInfo['columns'] = $groupColumnsInfo; 579 $groupConditionInfo['condition'] = 'and'; 580 $advFilterConditionFormat[] = $groupConditionInfo; 581 $groupIterator++; 582 } 583 //We aer removing last condition since this condition if there is next group and this is the last group 584 unset($advFilterConditionFormat[count($advFilterConditionFormat)-1]['condition']); 585 return $advFilterConditionFormat; 586 587 } 588 589 /*** 590 * Function to set the default calendar activity types for new user 591 * @param <Integer> $userId - id of the user 592 */ 593 public static function setCalendarDefaultActivityTypesForUser($userId) { 594 $db = PearDatabase::getInstance(); 595 $userEntries = $db->pquery('SELECT 1 FROM vtiger_calendar_user_activitytypes WHERE userid=?', array($userId)); 596 $activityIds = array(); 597 if($db->num_rows($userEntries) <= 0) { 598 $queryResult = $db->pquery('SELECT id, defaultcolor FROM vtiger_calendar_default_activitytypes', array()); 599 $numRows = $db->num_rows($queryResult); 600 for ($i = 0; $i < $numRows; $i++) { 601 $row = $db->query_result_rowdata($queryResult, $i); 602 $activityIds[$row['id']] = $row['defaultcolor']; 603 } 604 605 foreach($activityIds as $activityId=>$color) { 606 $db->pquery('INSERT INTO vtiger_calendar_user_activitytypes (id, defaultid, userid, color) VALUES (?,?,?,?)', array($db->getUniqueID('vtiger_calendar_user_activitytypes'), $activityId, $userId, $color)); 607 } 608 } 609 610 } 611 612 public static function getAllSkins(){ 613 return array('alphagrey' => '#666666', 'softed' => '#1560BD', 'bluelagoon'=> '#204E81', 614 'nature' => '#008D4C', 'woodspice' => '#C19803', 'orchid' => '#C65479', 615 'firebrick'=> '#E51400', 'twilight' => '#404952', 'almond' => '#894400'); 616 } 617 618 public static function isUserDeleted($userid) { 619 $db = PearDatabase::getInstance(); 620 $result = $db->pquery('SELECT deleted FROM vtiger_users WHERE id = ? AND (status=? OR deleted=?)', array($userid, 'Inactive', 1)); 621 $count = $db->num_rows($result); 622 if($count > 0) 623 return true; 624 625 return false; 626 } 627 628 /* 629 * Function used to get default value based on data type 630 * @param $dataType - data type of field 631 * @return returns default value for data type if match case found 632 * else returns empty string 633 */ 634 function getDefaultMandatoryValue($dataType) { 635 $value; 636 switch ($dataType) { 637 case 'date': 638 $dateObject = new DateTime(); 639 $value = DateTimeField::convertToUserFormat($dateObject->format('Y-m-d')); 640 break; 641 case 'time' : 642 $value = '00:00:00'; 643 break; 644 case 'boolean': 645 $value = false; 646 break; 647 case 'email': 648 $value = '??@??.??'; 649 break; 650 case 'url': 651 $value = '???.??'; 652 break; 653 case 'integer': 654 $value = 0; 655 break; 656 case 'double': 657 $value = 00.00; 658 break; 659 case 'currency': 660 $value = 0.00; 661 break; 662 default : 663 $value = '?????'; 664 break; 665 } 666 return $value; 667 } 668 public static function checkDbUTF8Support($conn) { 669 global $db_type; 670 if($db_type == 'pgsql') 671 return true; 672 $dbvarRS = $conn->Execute("show variables like '%_database' "); 673 $db_character_set = null; 674 $db_collation_type = null; 675 while(!$dbvarRS->EOF) { 676 $arr = $dbvarRS->FetchRow(); 677 $arr = array_change_key_case($arr); 678 switch($arr['variable_name']) { 679 case 'character_set_database' : $db_character_set = $arr['value']; break; 680 case 'collation_database' : $db_collation_type = $arr['value']; break; 681 } 682 // If we have all the required information break the loop. 683 if($db_character_set != null && $db_collation_type != null) break; 684 } 685 return (stristr($db_character_set, 'utf8') && stristr($db_collation_type, 'utf8')); 686 } 687 }
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 |