aboutsummaryrefslogtreecommitdiff
path: root/h-source/Application/Include/myFunctions.php
blob: 5cceaea0a155906621912ce1eb2cf17159770b85 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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
279
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
391
392
393
394
395
396
397
398
399
400
401
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
428
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
472
473
474
475
476
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
522
523
524
525
526
527
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
606
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
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
<?php

// h-source, a web software to build a community of people that want to share their hardware information.
// Copyright (C) 2010  Antonio Gallo (h-source-copyright.txt)
//
// This file is part of h-source
//
// h-source is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// h-source is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with h-source.  If not, see <http://www.gnu.org/licenses/>.

if (!defined('EG')) die('Direct access not allowed!');

function encodeUrl($url)
{
	$url = str_replace(' ','-',$url);
	$url = str_replace('.','-',$url);
	$url = str_replace('[','-',$url);
	$url = str_replace(']','-',$url);
	$url = str_replace('(','-',$url);
	$url = str_replace(')','-',$url);
	$url = str_replace('/','-',$url);
	$url = str_replace('@','-at-',$url);
	$url = str_replace('?','-',$url);
	
// 	$temp = null;
// 	for ($i=0;$i<strlen($url); $i++)
// 	{
// 		if (strcmp($url[$i],' ') === 0)
// 		{
// 			$temp .= '-';
// 		}
// 		else
// 		{
// 			if (preg_match('/^[a-zA-Z0-9\-]$/',$url[$i])) $temp .= $url[$i];
// 		}
// 	}

// 	$url = urlencode($url);
// 	$url = urlencode($url);
	return $url;
}

function titleForRedirect($title)
{
	return html_entity_decode(encodeUrl($title),ENT_QUOTES,DEFAULT_CHARSET);
}

// function encodeUrl($url)
// {
// 	$url = str_replace(' ','-',$url);
// 	$url = str_replace('[','-',$url);
// 	$url = str_replace(']','-',$url);
// 	$url = str_replace('(','-',$url);
// 	$url = str_replace(')','-',$url);
// 	$url = str_replace('/','-',$url);
// 	$url = str_replace('@','-at-',$url);
// 	$url = urlencode($url);
// // 	$url = html_entity_decode($url, ENT_QUOTES);
// // 	$url = xml_encode($url);
// 	return $url;
// }


function smartDate($uglyDate = null, $lang = 'en')
{
	switch ($lang)
	{
		case 'en':
			$smDate =  date('H:i, d F Y',strtotime($uglyDate));
			break;
		default:
			$smDate = date('H:i, d F Y',strtotime($uglyDate));
	}
	return $smDate;
}

function pubDateFormat($uglyDate = null)
{
	return date('r',strtotime($uglyDate));
}

function sanitizeString($string)
{
	$string = preg_match('/^[a-zA-Z0-9\-\_\.\+\s]+$/',$string) ? sanitizeAll($string) : 'undef';
	return $string;
}

function sanitizeAlphanum($string)
{
	$string = ctype_alnum($string) ? sanitizeAll($string) : 'undef';
	return $string;
}

function sanitizePciid($string)
{
	$string = preg_match('/^[a-zA-Z0-9]{4}(\:)[a-zA-Z0-9]{4}$/',$string) ? sanitizeAll($string) : '0';
	return $string;
}

function getOrderByClause($string)
{
	switch ($string)
	{
		case 'last-inserted':
			$orderBy = 'hardware.id_hard desc';
			break;
		case 'alphabetically':
			$orderBy = 'model';
			break;
		case 'alphabetically-desc':
			$orderBy = 'model desc';
			break;
		case 'compatibility':
			$orderBy = 'compatibility';
			break;
		case 'undef':
			$orderBy = 'hardware.id_hard desc';
			break;
		default:
			$orderBy = 'hardware.id_hard desc';
	}
	
	return $orderBy;
}

//remove empty elements
function removeEmptyStrings($oArray)
{
	$nArray = array();
	foreach ($oArray as $oValue)
	{
		if (strcmp($oValue,'') !== 0)
		{
			$nArray[] = $oValue;
		}
	}
	return $nArray;
}

function diff($old, $new)
{
	$maxlen = 0;
	foreach($old as $oindex => $ovalue)
	{
			$nkeys = array_keys($new, $ovalue);
// 			echo memory_get_peak_usage(true)."<br />";
			foreach($nkeys as $nindex)
			{
					$matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ?
							$matrix[$oindex - 1][$nindex - 1] + 1 : 1;
					if($matrix[$oindex][$nindex] > $maxlen)
					{
							$maxlen = $matrix[$oindex][$nindex];
							$omax = $oindex + 1 - $maxlen;
							$nmax = $nindex + 1 - $maxlen;
					}
			}
	}
	if($maxlen == 0) return array(array('d'=>$old, 'i'=>$new));
	return array_merge(
			diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)),
			array_slice($new, $nmax, $maxlen),
			diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)));
}

function htmlDiff($old, $new)
{
	$old = str_replace("\r\n"," \r\n ",$old);
	$new = str_replace("\r\n"," \r\n ",$new);

	$ret = null;
	$diff = diff(removeEmptyStrings(explode(' ', $old)),removeEmptyStrings(explode(' ', $new)));
	foreach($diff as $k)
	{
			if(is_array($k))
					$ret .= (!empty($k['d'])?"<del>".implode(' ',$k['d'])."</del> ":'').
							(!empty($k['i'])?"<ins>".implode(' ',$k['i'])."</ins> ":'');
			else $ret .= $k . ' ';
	}
	return $ret;
}


function applyBreaks($values,$fields)
{
	$fieldsArray = explode(',',$fields);
	
	foreach ($fieldsArray as $field)
	{
		if (array_key_exists($field,$values))
		{
			$values[$field] = nl2br($values[$field]);
		}
	}
	return $values;
}


function getLinkToUser($user)
{
	if (strstr($user,'__'))
	{
		return str_replace('__',null,$user);
	}
	else
	{
		return "<a href='http://".DOMAIN_NAME."/meet/user/".Lang::$current."/$user'>$user</a>";
	}
}

$decodeCounter = 0;
$decodeAnotherTime = false;

//decode the text of the wiki
function decodeWikiText($string)
{
	global $decodeAnotherTime;
	global $decodeCounter;

	$decodeCounter++;
	
	$decodeAnotherTime = false;
	
	$string = preg_replace('/(\[hr\])/', '<hr />',$string);

	$string = preg_replace_callback('/(\[\[)(.*?)\|(.*?)(\]\])/', 'linkToInternalPageWithText' ,$string);

	$string = preg_replace_callback('/(\[\[)(.*?)(\]\])/', 'linkToInternalPage' ,$string);
	
	$string = preg_replace_callback('/(\[a\])(.*?)(\[\/a\])/', 'linkTo',$string);

	$string = preg_replace_callback('/(\[a\])(.*?)\|(.*?)(\[\/a\])/', 'linkToWithText',$string);

	$string = preg_replace_callback('/(\[notebook\])([0-9]*?)(\[\/notebook\])/s', 'linkToNotebook',$string);
	
	$string = preg_replace_callback('/(\[wifi\])([0-9]*?)(\[\/wifi\])/s', 'linkToWifi',$string);
	
	$string = preg_replace_callback('/(\[videocard\])([0-9]*?)(\[\/videocard\])/s', 'linkToVideocard',$string);
	
	$string = preg_replace('/(\[b\])(.*?)(\[\/b\])/s', '<b>${2}</b>',$string);
	
	$string = preg_replace('/(\[u\])(.*?)(\[\/u\])/s', '<u>${2}</u>',$string);
	
	$string = preg_replace('/(\[i\])(.*?)(\[\/i\])/s', '<i>${2}</i>',$string);
	
	$string = preg_replace('/(\[del\])(.*?)(\[\/del\])/s', '<del>${2}</del>',$string);

	$string = preg_replace_callback('/(\[\*\])(.*?)(\[\/\*\])/s', 'createItem',$string);

	$string = preg_replace_callback('/(\[list\])(.*?)(\[\/list\])/s', 'createList',$string);

	$string = preg_replace_callback('/(\[enum\])(.*?)(\[\/enum\])/s', 'createEnum',$string);

	$string = preg_replace('/(\[code\])(.*?)(\[\/code\])/s', '<pre class="code_pre">${2}</pre>',$string);
	
	$string = preg_replace('/(\[p\])(.*?)(\[\/p\])/s', '<p>${2}</p>',$string);

	$string = preg_replace_callback('/(\[)(h)(1|2|3)(\])(.*?)(\[\/)(h)(1|2|3)(\])/s', 'createHeadGeneric',$string);
	
	$string = preg_replace_callback('/(\[tab )(lang=)([^\s]+)(\s*\])(.*?)(\[\/tab\])/s', 'createTabs',$string);

	$string = preg_replace_callback('/(__TOC__)/s', 'createToc',$string);
	
	$string = preg_replace('/(\[lang\])(.*?)(\[\/lang\])/s', '<div class="div_lang">${2}</div>',$string);

	$string = preg_replace('/(\{\{)/s', '[',$string);

	$string = preg_replace('/(\}\})/s', ']',$string);

	if ($decodeAnotherTime and $decodeCounter<=30)
	{
		return decodeWikiText(Toc::render().Tabs::render().$string);
	}
	else
	{
		return Toc::render().Tabs::render().$string;
	}
}

//create the list of the tabs in the description entry
function createTabs($match)
{
	$label = Lang::getLabel($match[3]);
	Tabs::$tabList[] = "<li class='desc_tabs ".$match[3]."'><a href='#".$match[3]."'>".$label."</a></li>\n";
	Tabs::$htmlList[] = "<div class='separation_line'>$label</div>\n<div class='description_tabs_page' id='".$match[3]."'>".$match[5]."</div>\n";
	return null;
}

//create the HTM Lof the tabs in the description entry
class Tabs
{
	public static $tabList = array();
	public static $htmlList = array();

	public static function render()
	{
		$html = null;
		if (count(self::$tabList) > 0)
		{
			$html .= "<div class='description_tabs'>\n";
			$html .= "<noscript><div class='noscript_notice'>".gtext("you need javascript enabled in order to correctly use the language's tabs (see below)")."</div></noscript>\n";
			$html .= "<ul class='desc_menu'>\n";
			foreach (self::$tabList as $label)
			{
				$html .= $label;
			}
			$html .= "</ul>\n<div id='description_tabs_content'>\n";
			foreach (self::$htmlList as $content)
			{
				$html .= $content;
			}
			$html .= "</div>\n</div>\n";
		}
		self::$tabList = array();
		self::$htmlList = array();
		return $html;
	}

}

function checkUrl($url)
{
	$match = '/^http(s)?\:\/\/(www\.)?[a-zA-Z0-9\-\_]+(\.[a-zA-Z0-9\-\_]+)*\.(com|net|it|info|org|eu|uk|ca|us|cl)((\/[a-zA-Z0-9\_\.\-\:\+]+)*(\/([a-zA-Z0-9\_\:\-\.\+]+\.(php|html|htm|asp|aspx|jsp|cgi))?)?)?(\?([a-zA-Z0-9\_\-\+\s]+\=[a-zA-Z0-9\_\-\s\+\&amp;]+)+)?(#[a-zA-Z0-9\_\-\+\s]+)?([\s]*)?$/';
	
	if (preg_match($match,$url))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function vitalizeUrl($string)
{
	if (checkUrl($string))
	{
		return "<a title = '".$string."' href='".$string."'>".$string."</a>";
	}
	return $string;
}

function linkTo($match)
{
	if (checkUrl($match[2]))
	{
		return "<a title = '".$match[2]."' href='".$match[2]."'>".$match[2]."</a>";
	}
	else
	{
		return $match[0];
	}
}

function createNode($match,$hnodeTag,$htmlTagBegin,$htmlTagEng)
{
	$numb = strlen($hnodeTag);
	global $decodeAnotherTime;

	if (strstr($match[2],$hnodeTag))
	{
		$string = substr($match[0],$numb);
		$string = decodeWikiText($string);
		$decodeAnotherTime = true;
		return $hnodeTag.$string;
	}
	else
	{
		return $htmlTagBegin.$match[2].$htmlTagEng;
	}
}

function createToc($match)
{
	Toc::create();
	return null;
}

//table of contents
class Toc
{

	public static $links = array();
	public static $level = 1;
	
	private static $html = null;
	
	public function create()
	{
		$c=0;
		foreach (self::$links as $link)
		{
			if ((int)substr($link,0,1) === 1)
			{
				break;
			}
			$c++;
		}

		self::$links = array_slice(self::$links,$c);

		$res = array();
		
		if (count(self::$links) > 0)
		{
			self::$links[] = '1fine';

			$res[] = "<div class='tables_of_contents'><div class='tables_of_contents_title'>".gtext("Table of contents")."</div><ul>";
			foreach (self::$links as $link)
			{
				$startChar = (int)substr($link,0,1);

				if (strcmp(self::$level,$startChar) === 0)
				{
					$res[] = "<li><a href='#".substr($link,1)."'>".substr($link,1)."</a></li>";
				}
				else if ($startChar > self::$level)
				{
					$diff = (int)$startChar - (int)self::$level;
					if ($diff !== 1)
					{
						return null;
					}
					
					self::$level = $startChar;
					$res[] = "<ul><li><a href='#".substr($link,1)."'>".substr($link,1)."</a></li>";
				}
				else
				{
					$diff = (int)self::$level - (int)$startChar;

					for ($i=0;$i<$diff;$i++)
					{
						$res[] = "</ul>";
					}
					self::$level = $startChar;
					$res[] = "<li><a href='#".substr($link,1)."'>".substr($link,1)."</a></li>";
				}
			}
			array_pop($res);
			$res[] = "</ul></div>";
		}
		self::$links = array();
		self::$html = implode('',$res);
	}

	public function render()
	{
		echo self::$html;
	}
}

//create h1, h2, h3 ($level=1,2,3)
function createHead($match,$level)
{
	Toc::$links[] = $level.$match[5];

	return "<div id='".$match[5]."' class='div_h$level'>".$match[5]."</div>";
}

//create <h1></h1>,<h2></h2>,<h3></h3>
function createHeadGeneric($match)
{
	if (strcmp($match[3],'1') === 0)
	{
		return createHead($match,'1');
	}
	else if (strcmp($match[3],'2') === 0)
	{
		return createHead($match,'2');
	}
	else
	{
		return createHead($match,'3');
	}
}

//create <li></li>
function createItem($match)
{
	return createNode($match,'[*]',"<li>","</li>");
}

//create <ul></ul>
function createList($match)
{
	return createNode($match,'[list]',"<ul>","</ul>");
}

//create <ol></ol>
function createEnum($match)
{
	return createNode($match,'[enum]',"<ol>","</ol>");
}

function linkToInternalPage($match)
{
	return "<a title = '".$match[2]."' href='http://".DOMAIN_NAME."/wiki/page/".Lang::$current."/".encodeUrl($match[2])."'>".$match[2]."</a>";
}

function linkToInternalPageWithText($match)
{
	return "<a title = '".$match[2]."' href='http://".DOMAIN_NAME."/wiki/page/".Lang::$current."/".encodeUrl($match[2])."'>".$match[3]."</a>";
}

function linkToWithText($match)
{
	if (checkUrl($match[2]))
	{
		
		return "<a title = '".$match[2]."' href='".$match[2]."'>".$match[3]."</a>";
	}
	else
	{
		return $match[0];
	}
}

//create the link to the wiki page of the notebook
function linkToNotebook($match)
{
	$hardware = new HardwareModel();
	$clean['id_hard'] = (int)$match[2];
	$name = encodeUrl($hardware->getTheModelName($clean['id_hard']));
	$href = "HTTP://".DOMAIN_NAME."/notebooks/view/".Lang::$current."/".$clean['id_hard']."/$name";
	return (strcmp($name,'') !== 0) ? "<a title = 'link to notebook $name:  $href' href='$href'>".$name."</a>" : $match[0];
}

//create the link to the wiki page of the wifi
function linkToWifi($match)
{
	$hardware = new HardwareModel();
	$clean['id_hard'] = (int)$match[2];
	$name = encodeUrl($hardware->getTheModelName($clean['id_hard']));
	$href = "HTTP://".DOMAIN_NAME."/wifi/view/".Lang::$current."/".$clean['id_hard']."/$name";
	return (strcmp($name,'') !== 0) ? "<a title = 'link to wifi card $name:  $href' href='$href'>".$name."</a>" : $match[0];
}

//create the link to the wiki page of the videocard
function linkToVideocard($match)
{
	$hardware = new HardwareModel();
	$clean['id_hard'] = (int)$match[2];
	$name = encodeUrl($hardware->getTheModelName($clean['id_hard']));
	$href = "HTTP://".DOMAIN_NAME."/videocards/view/".Lang::$current."/".$clean['id_hard']."/$name";
	return (strcmp($name,'') !== 0) ? "<a title = 'link to video card $name:  $href' href='$href'>".$name."</a>" : $match[0];
}

function getUserName($id_user = 0)
{
	$clean['id_user'] = (int)$id_user;
	$u = new UsersModel();
	return $u->getUser($clean['id_user']);
}

function getMotivation($row,$controller)
{
	if (strcmp($row['deletion']['object'],'duplication') === 0)
	{
		$clean['id_hard'] = (int)$row['deletion']['id_duplicate'];
		$hardware = new HardwareModel();
		$name = encodeUrl($hardware->getTheModelName($clean['id_hard']));
		return "<b>duplication</b> of the model having id <b><a href='http://".DOMAIN_NAME."/".$controller."/view/".Lang::$current."/".$clean['id_hard']."/".$name."'>".$clean['id_hard']."</a></b>";
	}
	else
	{
		return "<b>".$row['deletion']['object']."</b>";
	}
}

//get the text in the right language
function gtext($string)
{
	if (isset(Lang::$i18n[Lang::$current][$string]))
	{
		return Lang::$i18n[Lang::$current][$string];
	}
	return $string;
}

function singular($string)
{
	if (isset(Lang::$singular[Lang::$current][$string]))
	{
		return Lang::$singular[Lang::$current][$string];
	}
	return $string;
}

function plural($string)
{
	if (isset(Lang::$plural[Lang::$current][$string]))
	{
		return Lang::$plural[Lang::$current][$string];
	}
	return $string;
}

//get the hardware info from the talk id
function getHardwareInfoFromTalkId($id = 0)
{
	$clean['id'] = (int)$id;
	$talk = new TalkModel();
	$res = $talk->select('hardware.type,hardware.id_hard')->from('hardware inner join talk')->using('id_hard')->where(array('id_talk'=>$clean['id']))->send();
	return count($res) > 0 ? $res[0]['hardware'] : null;
}

//get hardware info from id
function getHardwareInfoFromId($id = 0)
{
	$clean['id'] = (int)$id;
	$hw = new HardwareModel();
	$res = $hw->select()->where(array('id_hard'=>$clean['id']))->send();
	$controller = 'home/index/en';
	$model = '';
	if (count($res) > 0)
	{
		$controller = Hardware::getControllerFromType($res[0]['hardware']['type']);
		$controller = strcmp($controller,'') !== 0 ? $controller : 'home/index/en';
		$model = $res[0]['hardware']['model'];
	}
	
	return array('controller'=>$controller,'model'=>$model);
}

//get the wiki page info from the talk id
function getWikiPageInfoFromTalkId($id = 0)
{
	$clean['id'] = (int)$id;
	$talk = new WikitalkModel();
	$res = $talk->select('wiki.id_wiki')->from('wiki inner join wiki_talk')->using('id_wiki')->where(array('id_talk'=>$clean['id']))->send();
	return count($res) > 0 ? $res[0]['wiki']['id_wiki'] : '';
}

//get the issue info from the message id
function getIssueNumberFromMessageId($id = 0)
{
	$clean['id'] = (int)$id;
	$mess = new MessagesModel();
	$res = $mess->select('issues.id_issue')->from('issues inner join messages')->using('id_issue')->where(array('id_mes'=>$clean['id']))->toList('issues.id_issue')->send();
	return count($res) > 0 ? $res[0] : '';
}

//get thw wiki name from the id
function getWikiNameFromId($id = 0)
{
	$clean['id'] = (int)$id;
	$wiki = new WikiModel();
	$name = $wiki->getTheModelName($clean['id']);
	return $name;
}

//return the URL to the moderated object page
function goToModeratedItem( $row = array() )
{
	$url = null;
	
	switch ($row['type'])
	{
		case 'message':
			$url = 'issues/view/'.Lang::$current.'/'.getIssueNumberFromMessageId($row['id']).'#message-'.$row['id'];
			break;
		case 'talk':
			$hardInfo = getHardwareInfoFromTalkId($row['id']);
			if (isset($hardInfo))
			{
				$controller = Hardware::$typeToController[$hardInfo['type']];
				$url = $controller.'/talk/'.Lang::$current.'/'.$hardInfo['id_hard'].'#talk-'.$row['id'];
			}
			else
			{
				$url = 'last/modactions/'.Lang::$current;
			}
			break;
		case 'user':
			$url = 'meet/user/'.Lang::$current.'/'.getUserName($row['id']);
			break;
		case 'issue':
			$url = 'issues/view/'.Lang::$current.'/'.$row['id'];
			break;
		case 'issue_del':
			$url = 'issues/view/'.Lang::$current.'/'.$row['id'];
			break;
		case 'wiki_talk':
			$url = 'wiki/talk/'.Lang::$current.'/'.getWikiPageInfoFromTalkId($row['id']).'#wiki-talk-'.$row['id'];
			break;
		case 'page':
			$url = 'wiki/page/'.Lang::$current.'/'.encodeUrl(getWikiNameFromId($row['id']));
			break;
		case 'page_del':
			$url = 'wiki/page/'.Lang::$current.'/'.encodeUrl(getWikiNameFromId($row['id']));
			break;
		case 'device':
			$hardInfo = getHardwareInfoFromId($row['id']);
			$url = $hardInfo['controller'].'/view/'.Lang::$current.'/'.$row['id'].'/'.encodeUrl($hardInfo['model']);
			break;
		case 'device_app':
			$hardInfo = getHardwareInfoFromId($row['id']);
			$url = $hardInfo['controller'].'/view/'.Lang::$current.'/'.$row['id'].'/'.encodeUrl($hardInfo['model']);
			break;
		case 'device_cl':
			$hardInfo = getHardwareInfoFromId($row['id']);
			$url = $hardInfo['controller'].'/view/'.Lang::$current.'/'.$row['id'].'/'.encodeUrl($hardInfo['model']);
			break;
		case 'message_ins':
			$url = 'issues/view/'.Lang::$current.'/'.getIssueNumberFromMessageId($row['id']).'#message-'.$row['id'];
			break;
		case 'wiki_talk_ins':
			$url = 'wiki/talk/'.Lang::$current.'/'.getWikiPageInfoFromTalkId($row['id']).'#wiki-talk-'.$row['id'];
			break;
		case 'issue_ins':
			$url = 'issues/view/'.Lang::$current.'/'.$row['id'];
			break;
		case 'talk_ins':
			$hardInfo = getHardwareInfoFromTalkId($row['id']);
			if (isset($hardInfo))
			{
				$controller = Hardware::$typeToController[$hardInfo['type']];
				$url = $controller.'/talk/'.Lang::$current.'/'.$hardInfo['id_hard'].'#talk-'.$row['id'];
			}
			else
			{
				$url = 'last/modactions/'.Lang::$current;
			}
			break;
		case 'hardware':
			$hardInfo = getHardwareInfoFromId($row['id']);
			$url = $hardInfo['controller'].'/view/'.Lang::$current.'/'.$row['id'].'/'.encodeUrl($hardInfo['model']);
			break;
		case 'wiki':
			$url = 'wiki/page/'.Lang::$current.'/'.encodeUrl(getWikiNameFromId($row['id']));
			break;
	}
	return 'http://'.DOMAIN_NAME.'/'.$url;
}

function getUrlsFromIdHard($id_hard)
{
	$clean['id_hard'] = (int)$id_hard;
	
	$urlView = "http://".DOMAIN_NAME;
	$urlTalk = "http://".DOMAIN_NAME;
	$deviceName = null;
	
	$hard = new HardwareModel();
	$res = $hard->select('type,model')->where(array('id_hard'=>$clean['id_hard']))->send();
	if (count($res) > 0)
	{
		$urlView = "http://".DOMAIN_NAME."/".Hardware::$typeToController[$res[0]['hardware']['type']]."/view/".Lang::$current."/".$clean['id_hard']."/".encodeUrl($res[0]['hardware']['model']);
		
		$urlTalk = "http://".DOMAIN_NAME."/".Hardware::$typeToController[$res[0]['hardware']['type']]."/talk/".Lang::$current."/".$clean['id_hard'];

		$deviceName = $res[0]['hardware']['model'];
	}
	
	return array('urlView'=>$urlView,'urlTalk'=>$urlTalk,'modelName'=>$deviceName);
	
}

function getDiffArray($associativeArray, $oldArray, $newArray)
{
	$diffArray = array();
	foreach ($associativeArray as $field => $label)
	{
		if (array_key_exists($field,$oldArray) and array_key_exists($field,$newArray))
		{
			$diffArray[$label] = htmlDiff($oldArray[$field], $newArray[$field]);
		}
	}
	return $diffArray;
}