Newer
Older
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
/**
* TODO need to organize into classes based on functional grouping.
*/
class Vtiger_Functions {
const LINK_TO_ANCHOR_TEXT_SYMBOL = '#';
static $supportedImageFormats = array('jpeg', 'png', 'jpg', 'pjpeg', 'x-png', 'gif', 'bmp', 'vnd.adobe.photoshop', 'tiff', 'svg+xml', 'x-eps', 'x-dwg', 'vnd.dwg', 'webp', 'x-ms-bmp', 'ico', 'vnd.microsoft.icon', 'x-icon');
static function userIsAdministrator($user) {
return (isset($user->is_admin) && $user->is_admin == 'on');
}
/**
* this function returns JS date format of current user
*
* return string
*/
public static function currentUserJSDateFormat()
{
$datePopupFormat = '';
$currentUser = Users_Record_Model::getCurrentUserModel();
switch ($currentUser->get('date_format')) {
case 'dd.mm.yyyy':
$datePopupFormat = '%d.%m.%Y';
break;
case 'mm.dd.yyyy':
$datePopupFormat = '%m.%d.%Y';
break;
case 'yyyy.mm.dd':
$datePopupFormat = '%Y.%m.%d';
break;
case 'dd/mm/yyyy':
$datePopupFormat = '%d/%m/%Y';
break;
case 'mm/dd/yyyy':
$datePopupFormat = '%m/%d/%Y';
break;
case 'yyyy/mm/dd':
$datePopupFormat = '%Y/%m/%d';
break;
case 'dd-mm-yyyy':
$datePopupFormat = '%d-%m-%Y';
break;
case 'mm-dd-yyyy':
$datePopupFormat = '%m-%d-%Y';
break;
case 'yyyy-mm-dd':
$datePopupFormat = '%Y-%m-%d';
break;
}
return $datePopupFormat;
}
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* This function returns the date in user specified format.
* limitation is that mm-dd-yyyy and dd-mm-yyyy will be considered same by this API.
* As in the date value is on mm-dd-yyyy and user date format is dd-mm-yyyy then the mm-dd-yyyy
* value will be return as the API will be considered as considered as in same format.
* this due to the fact that this API tries to consider the where given date is in user date
* format. we need a better gauge for this case.
* @global Users $current_user
* @param Date $cur_date_val the date which should a changed to user date format.
* @return Date
*/
static function currentUserDisplayDate($value) {
global $current_user;
$dat_fmt = $current_user->date_format;
if ($dat_fmt == '') {
$dat_fmt = 'dd-mm-yyyy';
}
$date = new DateTimeField($value);
return $date->getDisplayDate();
}
static function currentUserDisplayDateNew() {
global $log, $current_user;
$date = new DateTimeField(null);
return $date->getDisplayDate($current_user);
}
// i18n
static function getTranslatedString($str, $module='', $language='') {
return Vtiger_Language_Handler::getTranslatedString($str, $module, $language);
}
// CURRENCY
protected static $userIdCurrencyIdCache = array();
static function userCurrencyId($userid) {
global $adb;
if (!isset(self::$userIdCurrencyIdCache[$userid])) {
$result = $adb->pquery('SELECT id,currency_id FROM vtiger_users', array());
while ($row = $adb->fetch_array($result)) {
self::$userIdCurrencyIdCache[$row['id']] =
$row['currency_id'];
}
}
return self::$userIdCurrencyIdCache[$userid];
}
protected static $currencyInfoCache = array();
protected static function getCurrencyInfo($currencyid) {
global $adb;
if (!isset(self::$currencyInfoCache[$currencyid])) {
$result = $adb->pquery('SELECT * FROM vtiger_currency_info', array());
while ($row = $adb->fetch_array($result)) {
self::$currencyInfoCache[$row['id']] = $row;
}
}
return isset(self::$currencyInfoCache[$currencyid])? self::$currencyInfoCache[$currencyid] : null;
}
static function getCurrencyName($currencyid, $show_symbol = true) {
$currencyInfo = self::getCurrencyInfo($currencyid);
if ($show_symbol) {
return sprintf("%s : %s", Vtiger_Deprecated::getTranslatedCurrencyString($currencyInfo['currency_name']), $currencyInfo['currency_symbol']);
}
return $currencyInfo['currency_name'];
}
static function getCurrencySymbolandRate($currencyid) {
$currencyInfo = self::getCurrencyInfo($currencyid);
$currencyRateSymbol = array(
'rate' => $currencyInfo ? $currencyInfo['conversion_rate'] : 0,
'symbol'=>$currencyInfo ? $currencyInfo['currency_symbol'] : ""
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
);
return $currencyRateSymbol;
}
// MODULE
protected static $moduleIdNameCache = array();
protected static $moduleNameIdCache = array();
protected static $moduleIdDataCache = array();
protected static function getBasicModuleInfo($mixed) {
$id = $name = NULL;
if (is_numeric($mixed)) $id = $mixed;
else $name = $mixed;
$reload = false;
if ($name) {
if (!isset(self::$moduleNameIdCache[$name])) {$reload = true;}
} else if ($id) {
if (!isset(self::$moduleIdNameCache[$id])) {$reload = true;}
}
if ($reload) {
global $adb;
$result = $adb->pquery('SELECT tabid, name, ownedby FROM vtiger_tab', array());
while ($row = $adb->fetch_array($result)) {
self::$moduleIdNameCache[$row['tabid']] = $row;
self::$moduleNameIdCache[$row['name']] = $row;
}
}
if ($id && isset(self::$moduleIdNameCache[$id])) {
return self::$moduleIdNameCache[$id];
}
if ($name && isset(self::$moduleNameIdCache[$name])) {
return self::$moduleNameIdCache[$name];
}
return null;
}
static function getModuleData($mixed) {
$id = $name = NULL;
if (is_numeric($mixed)) $id = $mixed;
else $name = (string)$mixed;
$reload = false;
if ($name && !isset(self::$moduleNameIdCache[$name])) {$reload = true;}
else if ($id && !isset(self::$moduleIdNameCache[$id])) {$reload = true;}
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
if (!$id) $id = self::$moduleNameIdCache[$name]['tabid'];
if (!isset(self::$moduleIdDataCache[$id])) { $reload = true; }
}
if ($reload) {
global $adb;
$result = $adb->pquery('SELECT * FROM vtiger_tab', array());
while ($row = $adb->fetch_array($result)) {
self::$moduleIdNameCache[$row['tabid']] = $row;
self::$moduleNameIdCache[$row['name']] = $row;
self::$moduleIdDataCache[$row['tabid']] = $row;
}
if ($name && isset(self::$moduleNameIdCache[$name])) {
$id = self::$moduleNameIdCache[$name]['tabid'];
}
}
return $id ? self::$moduleIdDataCache[$id] : NULL;
}
static function getModuleId($name) {
$moduleInfo = self::getBasicModuleInfo($name);
return $moduleInfo ? $moduleInfo['tabid'] : NULL;
}
static function getModuleName($id) {
$moduleInfo = self::getBasicModuleInfo($id);
return $moduleInfo ? $moduleInfo['name'] : NULL;
}
static function getModuleOwner($name) {
$moduleInfo = self::getBasicModuleInfo($name);
return $moduleInfo ? $moduleInfo['ownedby'] : NULL;
}
protected static $moduleEntityCache = array();
static function getEntityModuleInfo($mixed) {
$name = NULL;
if (is_numeric($mixed)) $name = self::getModuleName ($mixed);
else $name = $mixed;
if ($name && !isset(self::$moduleEntityCache[$name])) {
global $adb;
$result = $adb->pquery('SELECT fieldname,modulename,tablename,entityidfield,entityidcolumn from vtiger_entityname', array());
while ($row = $adb->fetch_array($result)) {
self::$moduleEntityCache[$row['modulename']] = $row;
}
}
return isset(self::$moduleEntityCache[$name])?
self::$moduleEntityCache[$name] : NULL;
}
static function getEntityModuleSQLColumnString($mixed) {
$data = array();
$info = self::getEntityModuleInfo($mixed);
if ($info) {
$data['tablename'] = $info['tablename'];
$fieldnames = $info['fieldname'];
if (strpos(',', $fieldnames) !== false) {
$fieldnames = sprintf("concat(%s)", implode(",' ',", explode(',', $fieldnames)));
}
$data['fieldname'] = $fieldnames;
}
return $data;
}
static function getEntityModuleInfoFieldsFormatted($mixed) {
$info = self::getEntityModuleInfo($mixed);
$fieldnames = $info ? $info['fieldname'] : NULL;
if ($fieldnames && stripos($fieldnames, ',') !== false) {
$fieldnames = explode(',', $fieldnames);
}
$info['fieldname'] = $fieldnames;
return $info;
}
// MODULE RECORD
protected static $crmRecordIdMetadataCache = array();
protected static function getCRMRecordMetadata($mixedid) {
global $adb;
$multimode = is_array($mixedid);
$ids = $multimode ? $mixedid : array($mixedid);
$missing = array();
foreach ($ids as $id) {
if ($id && !isset(self::$crmRecordIdMetadataCache[$id])) {
$missing[] = $id;
}
}
if ($missing) {
$sql = sprintf("SELECT crmid, setype, label FROM vtiger_crmentity WHERE %s", implode(' OR ', array_fill(0, php7_count($missing), 'crmid=?')));
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
$result = $adb->pquery($sql, $missing);
while ($row = $adb->fetch_array($result)) {
self::$crmRecordIdMetadataCache[$row['crmid']] = $row;
}
}
$result = array();
foreach ($ids as $id) {
if (isset(self::$crmRecordIdMetadataCache[$id])) {
$result[$id] = self::$crmRecordIdMetadataCache[$id];
} else {
$result[$id] = NULL;
}
}
return $multimode? $result : array_shift($result);
}
static function getCRMRecordType($id) {
$metadata = self::getCRMRecordMetadata($id);
return $metadata ? $metadata['setype'] : NULL;
}
static function getCRMRecordLabel($id, $default='') {
$metadata = self::getCRMRecordMetadata($id);
return $metadata ? $metadata['label'] : $default;
}
static function getUserRecordLabel($id, $default='') {
$labels = self::getCRMRecordLabels('Users', $id);
return isset($labels[$id])? $labels[$id] : $default;
}
static function getGroupRecordLabel($id, $default='') {
$labels = self::getCRMRecordLabels('Groups', $id);
return isset($labels[$id])? $labels[$id] : $default;
}
static function getCRMRecordLabels($module, $ids) {
if (!is_array($ids)) $ids = array($ids);
if ($module == 'Users' || $module == 'Groups') {
// TODO Cache separately?
return self::computeCRMRecordLabels($module, $ids);
} else {
$metadatas = self::getCRMRecordMetadata($ids);
$result = array();
foreach ($metadatas as $data) {
$result[$data['crmid']] = $data['label'];
}
return $result;
}
}
static function updateCRMRecordLabel($module, $id) {
global $adb;
$labelInfo = self::computeCRMRecordLabels($module, $id);
if ($labelInfo) {
$label = decode_html($labelInfo[$id]);
$adb->pquery('UPDATE vtiger_crmentity SET label=? WHERE crmid=?', array($label, $id));
self::$crmRecordIdMetadataCache[$id] = array(
'setype' => $module,
'crmid' => $id,
'label' => $labelInfo[$id]
);
}
}
static function getOwnerRecordLabel($id) {
$result = self::getOwnerRecordLabels($id);
return $result ? array_shift($result) : NULL;
}
static function getOwnerRecordLabels($ids) {
if (!is_array($ids)) $ids = array($ids);
$nameList = array();
if ($ids) {
$nameList = self::getCRMRecordLabels('Users', $ids);
$groups = array();
$diffIds = array_diff($ids, array_keys($nameList));
if ($diffIds) {
$groups = self::getCRMRecordLabels('Groups', array_values($diffIds));
}
if ($groups) {
foreach ($groups as $id => $label) {
$nameList[$id] = $label;
}
}
}
return $nameList;
}
static function computeCRMRecordLabels($module, $ids) {
global $adb;
if (!is_array($ids)) $ids = array($ids);
if ($module == 'Events') {
$module = 'Calendar';
}
if ($module) {
$entityDisplay = array();
if ($ids) {
if ($module == 'Groups') {
$metainfo = array('tablename' => 'vtiger_groups','entityidfield' => 'groupid','fieldname' => 'groupname');
} else if ($module == 'DocumentFolders') {
$metainfo = array('tablename' => 'vtiger_attachmentsfolder','entityidfield' => 'folderid','fieldname' => 'foldername');
} else {
$metainfo = self::getEntityModuleInfo($module);
}
$table = $metainfo['tablename'];
$idcolumn = $metainfo['entityidfield'];
$columns = explode(',', $metainfo['fieldname']);
// NOTE: Ignore field-permission check for non-admin (to compute record label).
$columnString = php7_count($columns) < 2? $columns[0] :
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
sprintf("concat(%s)", implode(",' ',", $columns));
$sql = sprintf('SELECT '. implode(',',$columns).', %s AS id FROM %s WHERE %s IN (%s)',
$idcolumn, $table, $idcolumn, generateQuestionMarks($ids));
$result = $adb->pquery($sql, $ids);
if($result) {
while ($row = $adb->fetch_array($result)) {
$labelValues = array();
foreach($columns as $columnName) {
$labelValues[] = $row[$columnName];
}
$entityDisplay[$row['id']] = implode(' ',$labelValues);
}
}
}
return $entityDisplay;
}
}
protected static $groupIdNameCache = array();
static function getGroupName($id) {
global $adb;
if (!isset(self::$groupIdNameCache[$id]) || !self::$groupIdNameCache[$id]) {
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
$result = $adb->pquery('SELECT groupid, groupname FROM vtiger_groups');
while ($row = $adb->fetch_array($result)) {
self::$groupIdNameCache[$row['groupid']] = $row['groupname'];
}
}
$result = array();
if (isset(self::$groupIdNameCache[$id])) {
$result[] = decode_html(self::$groupIdNameCache[$id]);
$result[] = $id;
}
return $result;
}
protected static $userIdNameCache = array();
static function getUserName($id) {
global $adb;
if (!self::$userIdNameCache[$id]) {
$result = $adb->pquery('SELECT id, user_name FROM vtiger_users');
while ($row = $adb->fetch_array($result)) {
self::$userIdNameCache[$row['id']] = $row['user_name'];
}
}
return (isset(self::$userIdNameCache[$id])) ? self::$userIdNameCache[$id] : NULL;
}
static function getModuleFieldInfos($mixed) {
global $adb;
$moduleFieldInfo = array();
$moduleInfo = self::getBasicModuleInfo($mixed);
$module = $moduleInfo['name'];
if(Vtiger_Cache::get('ModuleFieldInfo',$module)){
return Vtiger_Cache::get('ModuleFieldInfo',$module);
}
if ($module) {
$result = $adb->pquery('SELECT * FROM vtiger_field WHERE tabid=?', array(self::getModuleId($module)));
while ($row = $adb->fetch_array($result)) {
$moduleFieldInfo[$module][$row['fieldname']] = $row;
}
if (isset($moduleFieldInfo[$module])) {
Vtiger_Cache::set('ModuleFieldInfo',$module,$moduleFieldInfo[$module]);
}
return isset($moduleFieldInfo[$module]) ? $moduleFieldInfo[$module] : NULL;
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
}
static function getModuleFieldInfoWithId($fieldid) {
global $adb;
$result = $adb->pquery('SELECT * FROM vtiger_field WHERE fieldid=?', array($fieldid));
return ($adb->num_rows($result))? $adb->fetch_array($result) : NULL;
}
static function getModuleFieldInfo($moduleid, $mixed) {
$field = NULL;
if (empty($moduleid) && is_numeric($mixed)) {
$field = self::getModuleFieldInfoWithId($mixed);
} else {
$fieldsInfo = self::getModuleFieldInfos($moduleid);
if ($fieldsInfo) {
if (is_numeric($mixed)) {
foreach ($fieldsInfo as $name => $row) {
if ($row['fieldid'] == $mixed) {
$field = $row;
break;
}
}
} else {
$field = isset($fieldsInfo[$mixed]) ? $fieldsInfo[$mixed] : NULL;
}
}
}
return $field;
}
static function getModuleFieldId($moduleid, $mixed, $onlyactive=true) {
$field = self::getModuleFieldInfo($moduleid, $mixed, $onlyactive);
if ($field) {
if ($onlyactive && ($field['presence'] != '0' && $field['presence'] != '2')) {
$field = NULL;
}
}
return $field ? $field['fieldid'] : false;
}
// Utility
static function formatDecimal($value){
$fld_value = $value;
if(strpos($value, '.')) {
$fld_value = rtrim($value, '0');
}
$value = rtrim($fld_value, '.');
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
return $value;
}
static function fromHTML($string, $encode=true) {
if (is_string($string)) {
if (preg_match('/(script).*(\/script)/i', $string)) {
$string = preg_replace(array('/</', '/>/', '/"/'), array('<', '>', '"'), $string);
}
}
return $string;
}
static function fromHTML_FCK($string) {
if (is_string($string)) {
if (preg_match('/(script).*(\/script)/i', $string)) {
$string = str_replace('script', '', $string);
}
}
return $string;
}
static function fromHTML_Popup($string, $encode = true) {
$popup_toHtml = array(
'"' => '"',
"'" => ''',
);
//if($encode && is_string($string))$string = html_entity_decode($string, ENT_QUOTES);
if ($encode && is_string($string)) {
$string = addslashes(str_replace(array_values($popup_toHtml), array_keys($popup_toHtml), $string));
}
return $string;
}
static function br2nl($str) {
$str = preg_replace("/(\r\n)/", "\\r\\n", $str);
$str = preg_replace("/'/", " ", $str);
$str = preg_replace("/\"/", " ", $str);
return $str;
}
static function suppressHTMLTags($string) {
return preg_replace(array('/</', '/>/', '/"/'), array('<', '>', '"'), $string);
}
static function getInventoryTermsAndCondition($moduleName) {
global $adb;
$sql = 'SELECT tandc FROM vtiger_inventory_tandc WHERE type = ?';
$result = $adb->pquery($sql, array($moduleName));
$tandc = $adb->query_result($result, 0, 'tandc');
return $tandc;
}
/**
* Function to get group permissions given to config.inc.php file
* @return type
*/
static function getGroupPermissionsFromConfigFile(){
$rootDirectory = vglobal('root_directory');
return exec("ls -l $rootDirectory/config.inc.php | awk 'BEGIN {OFS=\":\"}{print $3,$4}'");
}
static function initStorageFileDirectory() {
$filepath = 'storage/';
$year = date('Y');
$month = date('F');
$day = date('j');
$week = '';
$permissions = self::getGroupPermissionsFromConfigFile();
if (!is_dir($filepath . $year)) {
//create new folder
mkdir($filepath . $year);
$yearPath = $filepath.$year;
exec("chown -R $permissions $yearPath");
}
if (!is_dir($filepath . $year . "/" . $month)) {
//create new folder
$monthFilePath = "$year/$month";
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
$monthPath = $filepath.$monthFilePath;
mkdir($filepath . $monthFilePath);
exec("chown -R $permissions $monthPath");
}
if ($day > 0 && $day <= 7)
$week = 'week1';
elseif ($day > 7 && $day <= 14)
$week = 'week2';
elseif ($day > 14 && $day <= 21)
$week = 'week3';
elseif ($day > 21 && $day <= 28)
$week = 'week4';
else
$week = 'week5';
if (!is_dir($filepath . $year . "/" . $month . "/" . $week)) {
//create new folder
$weekFilePath = "$year/$month/$week";
$weekPath = $filepath . $weekFilePath;
mkdir($filepath . $weekFilePath );
exec("chown -R $permissions $weekPath");
}
$filepath = $filepath . $year . "/" . $month . "/" . $week . "/";
return $filepath;
}
static function validateImageMetadata($data, $short = true) {
if (is_array($data)) {
foreach ($data as $key => $value) {
$ok = self::validateImageMetadata($value, $short);
if (!$ok)
return false;
}
} else {
if (stripos($data, $short ? "<?" : "<?php") !== false) { // suspicious dynamic content
return false;
}
}
return true;
}
static function validateImage($file_details) {
global $app_strings;
$allowedImageFormats = Vtiger_Functions::$supportedImageFormats;
// Determine mime-types based on file-content for generic type (Outlook add-on).
if ($file_details['type'] == 'application/octet-stream' && function_exists('mime_content_type')) {
$file_details['type'] = mime_content_type($file_details['tmp_name']);
}
$mimeTypesList = array_merge($allowedImageFormats, array('x-ms-bmp')); //bmp another format
$file_type_details = explode("/", $file_details['type']);
$filetype = $file_type_details['1'];
if ($filetype) {
$filetype = strtolower($filetype);
}
Apparao G
committed
$saveimage = true;
if (!in_array($filetype, $allowedImageFormats)) {
Apparao G
committed
$saveimage = false;
root
committed
root
committed
//Checking the path of the file
root
committed
if ($saveimage) {
$fileExtensionPath = pathinfo($file_details['name'], PATHINFO_EXTENSION);
root
committed
if (!in_array(strtolower($fileExtensionPath), $allowedImageFormats)) {
root
committed
$saveimage = false;
}
}
root
committed
//checking the filename has dot character
root
committed
if ($saveimage) {
$firstCharacter = $file_details['name'][0];
if ($firstCharacter == '.') {
$saveimage = false;
}
}
Apparao G
committed
if ($saveimage) {
$mimeType = mime_content_type($file_details['tmp_name']);
$mimeTypeContents = explode('/', $mimeType);
if (!$file_details['size'] || strtolower($mimeTypeContents[0]) !== 'image' || !in_array($mimeTypeContents[1], $mimeTypesList)) {
Apparao G
committed
$saveimage = false;
$shortTagSupported = ini_get('short_open_tag') ? true : false;
Apparao G
committed
if ($saveimage) {
$tmpFileName = $file_details['tmp_name'];
if ($file_details['type'] == 'image/jpeg' || $file_details['type'] == 'image/tiff') {
$exifdata = @exif_read_data($file_details['tmp_name']);
if ($exifdata && !self::validateImageMetadata($exifdata, $shortTagSupported)) {
Apparao G
committed
$saveimage = false;
//131225968::remove sensitive information(like,GPS or camera information) from the image
Apparao G
committed
if ($saveimage && ($file_details['type'] == 'image/jpeg' ) && extension_loaded('gd') && function_exists('gd_info')) {
$img = imagecreatefromjpeg($tmpFileName);
imagejpeg($img, $tmpFileName);
}
}
}
Apparao G
committed
if ($saveimage) {
$imageContents = file_get_contents($tmpFileName);
if (stripos($imageContents, $shortTagSupported ? "<?" : "<?php") !== false) { // suspicious dynamic content.
Apparao G
committed
$saveimage = false;
Apparao G
committed
if (($filetype == 'svg+xml' || $mimeTypeContents[1] == 'svg+xml') && $saveimage) {
//remove malicious html attributes with its value from the contents.
$imageContents = purifyHtmlEventAttributes($imageContents, true);
$filePointer = fopen("$tmpFileName", "w");
fwrite($filePointer, $imageContents);
fclose($filePointer);
Apparao G
committed
if ($saveimage) {
/*
* File functions like filegroup(), fileowner(), filesize(), filetype(), fileperms() and few others,caches file information, we need to clear the cache so it will not return the cache value if we perform/call same function after updating the file
clearstatcache();
}
return $saveimage;
}
static function getMergedDescription($description, $id, $parent_type, $removeTags = false) {
global $current_user;
$token_data_pair = explode('$', $description);
$emailTemplate = new EmailTemplate($parent_type, $description, $id, $current_user);
$emailTemplate->removeTags = $removeTags;
$description = $emailTemplate->getProcessedDescription();
$tokenDataPair = explode('$', $description);
$fields = Array();
for ($i = 1; $i < php7_count($token_data_pair); $i++) {
if (count($module) < 2) {
// if not $module-fieldname$
continue;
}
if (!isset($fields[$module[0]])) {
$fields[$module[0]] = array();
}
if (isset($fields['custom']) && is_array($fields['custom']) && php7_count($fields['custom']) > 0) {
$description = self::getMergedDescriptionCustomVars($fields, $description,$id,$parent_type);
}
if(isset($fields['companydetails']) && is_array($fields['companydetails']) && php7_count($fields['companydetails']) > 0){
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
$description = self::getMergedDescriptionCompanyDetails($fields,$description);
}
//for merging record id merge tags(eg: $helpdesk-id$) with record values
if(is_array($fields) && !empty($fields)) {
foreach ($fields as $moduleName => $fields) {
if(in_array('id',$fields)) {
if(strtolower($parent_type) === $moduleName) {
$needle = "$$moduleName-id$";
$description = str_replace($needle,$id,$description);
}
}
}
}
return $description;
}
/**
* Function replaces all company merge tags will respective value.
* @param type $fields
* @param type $description
* @return type
*/
static function getMergedDescriptionCompanyDetails($fields, $description){
$companyModuleModel = Settings_Vtiger_CompanyDetails_Model::getInstance();
foreach($fields['companydetails'] as $columnname){
$token_data = '$companydetails-' . $columnname . '$';
$token_value = $companyModuleModel->get($columnname);
if(empty($token_value)){
$token_value = '';
}
$description = str_replace($token_data, $token_value, $description);
}
return $description;
}
static function getMergedDescriptionCustomVars($fields, $description, $recordId = '', $module = '') {
global $site_URL, $PORTAL_URL;
foreach ($fields['custom'] as $columnname) {
$token_data = '$custom-' . $columnname . '$';
$token_value = '';
switch ($columnname) {
case 'currentdate' : $token_value = date("F j, Y");
break;
case 'currenttime' : $token_value = date("G:i:s T");
break;
case 'siteurl' : $token_value = $site_URL;
break;
case 'portalurl' : $token_value = $PORTAL_URL;
break;
case 'crmdetailviewurl' : if($module !== 'Users') {
$token_value = $site_URL."/index.php?module=$module&view=Detail&record=$recordId";
} else {
$token_value = $token_data;
}
break;
}
if ($columnname !== 'viewinbrowser') {
$description = str_replace($token_data, $token_value, $description);
}
}
return $description;
}
static function getSingleFieldValue($tablename, $fieldname, $idname, $id) {
global $adb;
$fieldname = Vtiger_Util_Helper::validateStringForSql($fieldname);
$idname = Vtiger_Util_Helper::validateStringForSql($idname);
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
$fieldval = $adb->query_result($adb->pquery("select $fieldname from $tablename where $idname = ?", array($id)), 0, $fieldname);
return $fieldval;
}
static function getRecurringObjValue() {
$recurring_data = array();
if (isset($_REQUEST['recurringtype']) && $_REQUEST['recurringtype'] != null && $_REQUEST['recurringtype'] != '--None--') {
if (!empty($_REQUEST['date_start'])) {
$startDate = $_REQUEST['date_start'];
}
if (!empty($_REQUEST['calendar_repeat_limit_date'])) {
$endDate = $_REQUEST['calendar_repeat_limit_date'];
$recurring_data['recurringenddate'] = $endDate;
} elseif (isset($_REQUEST['due_date']) && $_REQUEST['due_date'] != null) {
$endDate = $_REQUEST['due_date'];
}
if (!empty($_REQUEST['time_start'])) {
$startTime = $_REQUEST['time_start'];
}
if (!empty($_REQUEST['time_end'])) {
$endTime = $_REQUEST['time_end'];
}
$recurring_data['startdate'] = $startDate;
$recurring_data['starttime'] = $startTime;
$recurring_data['enddate'] = $endDate;
$recurring_data['endtime'] = $endTime;
$recurring_data['type'] = $_REQUEST['recurringtype'];
if ($_REQUEST['recurringtype'] == 'Weekly') {
if (isset($_REQUEST['sun_flag']) && $_REQUEST['sun_flag'] != null)
$recurring_data['sun_flag'] = true;
if (isset($_REQUEST['mon_flag']) && $_REQUEST['mon_flag'] != null)
$recurring_data['mon_flag'] = true;
if (isset($_REQUEST['tue_flag']) && $_REQUEST['tue_flag'] != null)
$recurring_data['tue_flag'] = true;
if (isset($_REQUEST['wed_flag']) && $_REQUEST['wed_flag'] != null)
$recurring_data['wed_flag'] = true;
if (isset($_REQUEST['thu_flag']) && $_REQUEST['thu_flag'] != null)
$recurring_data['thu_flag'] = true;
if (isset($_REQUEST['fri_flag']) && $_REQUEST['fri_flag'] != null)
$recurring_data['fri_flag'] = true;
if (isset($_REQUEST['sat_flag']) && $_REQUEST['sat_flag'] != null)
$recurring_data['sat_flag'] = true;
}
elseif ($_REQUEST['recurringtype'] == 'Monthly') {
if (isset($_REQUEST['repeatMonth']) && $_REQUEST['repeatMonth'] != null)
$recurring_data['repeatmonth_type'] = $_REQUEST['repeatMonth'];
if ($recurring_data['repeatmonth_type'] == 'date') {
if (isset($_REQUEST['repeatMonth_date']) && $_REQUEST['repeatMonth_date'] != null)
$recurring_data['repeatmonth_date'] = $_REQUEST['repeatMonth_date'];
else
$recurring_data['repeatmonth_date'] = 1;
}
elseif ($recurring_data['repeatmonth_type'] == 'day') {
$recurring_data['repeatmonth_daytype'] = $_REQUEST['repeatMonth_daytype'];
switch ($_REQUEST['repeatMonth_day']) {
case 0 :
$recurring_data['sun_flag'] = true;
break;
case 1 :
$recurring_data['mon_flag'] = true;
break;
case 2 :
$recurring_data['tue_flag'] = true;
break;
case 3 :
$recurring_data['wed_flag'] = true;
break;
case 4 :
$recurring_data['thu_flag'] = true;
break;
case 5 :
$recurring_data['fri_flag'] = true;
break;
case 6 :
$recurring_data['sat_flag'] = true;
break;
}
}
}
if (isset($_REQUEST['repeat_frequency']) && $_REQUEST['repeat_frequency'] != null)
$recurring_data['repeat_frequency'] = $_REQUEST['repeat_frequency'];
$recurObj = RecurringType::fromUserRequest($recurring_data);
return $recurObj;
}
}
static function getTicketComments($ticketid) {
global $adb;
$moduleName = getSalesEntityType($ticketid);
$commentlist = '';
$sql = "SELECT commentcontent FROM vtiger_modcomments WHERE related_to = ?";
$result = $adb->pquery($sql, array($ticketid));
for ($i = 0; $i < $adb->num_rows($result); $i++) {
$comment = $adb->query_result($result, $i, 'commentcontent');
if ($comment != '') {
$commentlist .= '<br><br>' . $comment;
}
}
if ($commentlist != '')
$commentlist = '<br><br>' . getTranslatedString("The comments are", $moduleName) . ' : ' . $commentlist;
return $commentlist;
}
static function generateRandomPassword() {
$salt = "abcdefghijklmnopqrstuvwxyz0123456789";
srand((double) microtime() * 1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
static function getTagCloudView($id = "") {
global $adb;
if ($id == '') {
$tag_cloud_status = 1;
} else {
$query = "select visible from vtiger_homestuff where userid=? and stufftype='Tag Cloud'";
$res = $adb->pquery($query, array($id));
$tag_cloud_status = $adb->query_result($res, 0, 'visible');
}
if ($tag_cloud_status == 0) {
$tag_cloud_view = 'true';
} else {
$tag_cloud_view = 'false';
}
return $tag_cloud_view;
}
static function transformFieldTypeOfData($table_name, $column_name, $type_of_data) {
$field = $table_name . ":" . $column_name;
//Add the field details in this array if you want to change the advance filter field details
static $new_field_details = Array(
//Contacts Related Fields
"vtiger_contactdetails:accountid" => "V",
"vtiger_contactsubdetails:birthday" => "D",
"vtiger_contactdetails:email" => "V",
"vtiger_contactdetails:secondaryemail" => "V",
//Potential Related Fields
"vtiger_potential:campaignid" => "V",
//Account Related Fields
"vtiger_account:parentid" => "V",
"vtiger_account:email1" => "V",
"vtiger_account:email2" => "V",
//Lead Related Fields
"vtiger_leaddetails:email" => "V",
"vtiger_leaddetails:secondaryemail" => "V",
//Documents Related Fields
"vtiger_senotesrel:crmid" => "V",
//Calendar Related Fields
"vtiger_seactivityrel:crmid" => "V",
"vtiger_seactivityrel:contactid" => "V",
"vtiger_recurringevents:recurringtype" => "V",
//HelpDesk Related Fields
"vtiger_troubletickets:parent_id" => "V",
"vtiger_troubletickets:product_id" => "V",
//Product Related Fields
"vtiger_products:discontinued" => "C",
"vtiger_products:vendor_id" => "V",
"vtiger_products:parentid" => "V",
//Faq Related Fields