array('name'=> array(0=>'name1',1=>'name2'), * array('type'=>array(0=>'type1',2=>'type2'), * ...); * @param type $top * @return array array( 'file' => array(0=> array('name'=> 'name1','type' => 'type1'), * array(1=> array('name'=> 'name2','type' => 'type2'), * ...); */ public static function transformUploadedFiles(array $_files, $top = TRUE) { $files = array(); foreach($_files as $name=>$file) { if($top) $subName = $file['name']; else $subName = $name; if(is_array($subName)) { foreach(array_keys($subName) as $key) { $files[$name][$key] = array( 'name' => $file['name'][$key], 'type' => $file['type'][$key], 'tmp_name' => $file['tmp_name'][$key], 'error' => $file['error'][$key], 'size' => $file['size'][$key], ); $files[$name] = self::transformUploadedFiles($files[$name], FALSE); } }else { $files[$name] = $file; } } return $files; } /** * Function parses date into readable format * @param $dateTime * @return */ public static function formatDateDiffInStrings($dateTime) { // http://www.php.net/manual/en/datetime.diff.php#101029 $currentDateTime = date('Y-m-d H:i:s'); $seconds = strtotime($currentDateTime) - strtotime($dateTime); if ($seconds == 0) return vtranslate('LBL_JUSTNOW'); if ($seconds > 0) { $prefix = ''; $suffix = ' '. vtranslate('LBL_AGO'); } else if ($seconds < 0) { $prefix = vtranslate('LBL_DUE') . ' '; $suffix = ''; $seconds = -($seconds); } $minutes = floor($seconds/60); $hours = floor($minutes/60); $days = floor($hours/24); $months = floor($days/30); if ($seconds < 60) return $prefix . self::pluralize($seconds, "LBL_SECOND") . $suffix; if ($minutes < 60) return $prefix . self::pluralize($minutes, "LBL_MINUTE") . $suffix; if ($hours < 24) return $prefix . self::pluralize($hours, "LBL_HOUR") . $suffix; if ($days < 30) return $prefix . self::pluralize($days, "LBL_DAY") . $suffix; if ($months < 12) return $prefix . self::pluralize($months, "LBL_MONTH") . $suffix; if ($months > 11) return $prefix . self::pluralize(floor($days/365), "LBL_YEAR") . $suffix; } /** * Function returns singular or plural text * @param $count * @param $text * @return */ public static function pluralize($count, $text) { return $count ." ". (($count == 1) ? vtranslate("$text") : vtranslate("${text}S")); } /** * Function to make the input safe to be used as HTML */ public static function toSafeHTML($input) { global $default_charset; return htmlentities($input, ENT_QUOTES, $default_charset); } /** * Function that will strip all the tags while displaying * @param $input - html data * @return vtiger6 displayable data */ public static function toVtiger6SafeHTML($input) { $allowableTags = '
'; return strip_tags($input, $allowableTags); } /** * Function to validate the input with given pattern. * @param $string * @param $skipEmpty Skip the check if string is empty. * @return * @throws AppException */ public static function validateStringForSql($string, $skipEmpty=true) { if (vtlib_purifyForSql($string, $skipEmpty)) { return $string; } return false; } /** * Function Checks the existence of the record * @param $recordId - module recordId * returns 1 if record exists else 0 */ public static function checkRecordExistance($recordId){ global $adb; $query = 'Select deleted from vtiger_crmentity where crmid=?'; $result = $adb->pquery($query, array($recordId)); return $adb->query_result($result, 'deleted'); } /** * Function to parses date into string format * @param $date * @param