summaryrefslogtreecommitdiffstats
path: root/admin/survey/classes/class.SurveyVariablesProfiles.php
blob: eafd63fd1be65c4c94144820cdf6d907a022224c (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
<?php
/**
 * Created on 10.04.2013
 *
 * @author: Gorazd Veselič
 *
 * @desc: za shranjevanje in nalaganje profilov variabel za posamezno anketo
 *
 * Profil -1 je rezerviran za sejo
 * Profil 0 je rezerviran za privzet profil - Vse vrednosti
 *
 */
DEFINE ('SVP_DEFAULT_PROFILE', 0);
if (!defined(NEW_LINE)) define(NEW_LINE, "\n");

class SurveyVariablesProfiles
{
	static private $sid = null; 						# id ankete
	static private $availableProfiles = array(); 		# array kamor shranimo vse doseglijive  profile
	static private $profiles = array(); 				# array kamor shranimo podatke o trenutnem profilu
	static private $currentId = SVP_DEFAULT_PROFILE;	# trenutno izbran profil
	static private $SDF = null;							# trenutno izbran profil
	
	
	/** Inicializacija
	 * $uid=null še je posledica starega classa Je potrebno povsod zamenjat Init funkcijo
	*/
	static function Init($sid) {
		global $global_user_id;
		
		self::$sid = $sid;

		#inicializiramo class za datoteke
		self::$SDF = SurveyDataFile::get_instance();
		self::$SDF->init($sid);
		
		#polovimo vse profile
		self::getProfiles();
		
		#inicaliziramo nastavitve uporabnika
		SurveyUserSetting :: getInstance()->Init($sid, $global_user_id);
		self::$currentId = self:: getCurentProfileId();
	}

	static function setCurrentProfileId($pid)
	{
		if (isset(self::$profiles[$pid])){
			self::$currentId = $pid;
		}
		else{
			self::$currentId = SVP_DEFAULT_PROFILE;
		}
	} 
	
	static function getProfiles() {
		global $lang;
		
		# če imamo sejo preberemo iz seje
		if ( isset($_SESSION['variables_profile'][self::$sid])) 
		{
			self::$profiles[-1] = $_SESSION['variables_profile'][self::$sid];
		}
		#dodamo profil vse variable
		$svp_av = self::$SDF->getSurveyVariables();
		$all_variables = array();
		if (count($svp_av) > 0)
		{
			foreach($svp_av AS $v_id => $seq) 
			{
				$all_variables[] = $v_id;
			}
		}
		$variables = serialize($all_variables);
		self::$profiles[SVP_DEFAULT_PROFILE] = array('id'=>SVP_DEFAULT_PROFILE, 'name'=>$lang['srv_all_vars'].' *', 'variables'=>$variables);

		# preberemo še profile iz baze
		$stringSelect = "SELECT id, name, variables FROM srv_variable_profiles WHERE sid = '".self::$sid."'";
		$sqlQuery = sisplet_query($stringSelect);
		while (list($id,$name,$variables) = mysqli_fetch_row($sqlQuery))
		{
			self::$profiles[$id] = array('id'=>$id,
										'name'=>$name,
										'variables'=>$variables);
		}
	}

	/** Trenutno izbran profil
	 *
	 */
	static function getCurentProfileId()	{
		
		# poiscemo privzet profil
		$_dvp = SurveyUserSetting :: getInstance()->getSettings('default_variable_profile');
		self::$currentId = $_dvp;
		
		if ($_dvp == null || !isset(self::$profiles[self::$currentId])) {
			$_dvp = SVP_DEFAULT_PROFILE;
			self::$currentId = $_dvp;
			self::setDefaultProfile(self::$currentId);
		}
		
		return (int)self::$currentId;
	}

	static function getSystemDefaultProfile() {
		return (int)SVP_DEFAULT_PROFILE;
	}

	static function checkDefaultProfile($dvp=0) {
		// preverimo ali izbran privzet profil obstaja
		if ($dvp == -1) { //preverimo sejo
			if ( isset($_SESSION['variables_profile'][self::$sid]) ) {
				return $_SESSION['variables_profile'][self::$sid]['id'];
			} else { // morali bi imeti sejo pa je ni, zato nastavimo na privzetega (1)
				$dvp = SVP_DEFAULT_PROFILE;
			}
		}

		if ($dvp > 0 ) {
			$stringSelect = "SELECT id FROM srv_variable_profiles WHERE id = '".$dvp."'";
			$sqlSelect = sisplet_query($stringSelect);

			if (mysqli_num_rows($sqlSelect) > 0)  {// profil obstaja
				$rowSelect = mysqli_fetch_assoc($sqlSelect);
				return $rowSelect['id'];
			}
		}

		# ce ne izberemo osnovni profil
		return SVP_DEFAULT_PROFILE;
	}

	/**
	 *
	 * Enter description here ...
	 * @param $pid 				- profil ID
	 * @param $ignoreInspect	- ce je profil inspect, in ga moramo ignorirat potem vrnemo prazn array
	 */
	static function getProfileVariables($pid = null, $ignoreInspect=false)
	{
		if ($pid === null)
		{
			$pid = self::getCurentProfileId();
		}
		
		if ($ignoreInspect == true) 
		{
			return array();
		}

		# ce profil ni inspect ali ce ga ne ignoriramone vrnemo variable
		$variables = isset(self::$profiles[$pid]['variables']) ? unserialize(self::$profiles[$pid]['variables']) : null;
		if (is_array($variables)) 
		{
			$result=array();
			if (count($variables) > 0)
			{
				foreach ($variables AS $key => $variable)
				{
					$result[$variable] = $variable;
				}
			}
			return $result;
		}
		else 
		{
			return array();
		}
		return array();
	}

	
	public function getProfileName($pid) {
		return self::$profiles[$pid]['name'];
	}
	
	/**
	 *
	 * @param $ignoreInspect	- ce je profil inspect, in ga moramo ignorirat
	 */
	static function DisplayLink($ignoreInspect=false,$hideAdvanced = true) {
		global $lang;
		$izbranProfil = self::checkDefaultProfile(self::$currentId);

		$css = ($izbranProfil == SVP_DEFAULT_PROFILE ? ' gray' : '');

		if ($hideAdvanced == false || $css != ' gray') {
			echo '<li>';
			echo '  <span class="'.$css.'"  onclick="displayVariableProfile();" title="'.$lang['srv_filtri'].'">'.$lang['srv_filtri'].'</span>';
			echo '</li>';

		}
	}

	/**
	 * @param $ignoreInspect	- ce je profil inspect, in ga moramo ignorirat potem vrnemo prazn array
	 */
	static function getProfileString($ignoreInspect = false) {
		global $lang;

		$pid = self::checkDefaultProfile(self::$currentId);
		if ($ignoreInspect == true) {
			return;
		}

		$svp_pv = self::getProfileVariables($pid);
		$svp_av = self::$SDF->getSurveyVariables();

		if (count($svp_pv) > 0 && count($svp_pv) != count($svp_av)) {
			$vars = array();
			foreach ($svp_pv AS $vkey => $variable) {
				$variable_data = self::$SDF->getHeaderVariable($variable);
				$vars[] = $variable_data['variable'];
			}
				
			$variable_label = implode(', ',$vars);

			echo '<div id="variableProfileNote" class="filter_box">';

            echo '  <div class="header">';
			echo '      <span class="semi-bold">'.$lang['srv_profile_variables_is_filtred'].'</span>';
            
            echo '  <div class="icons">';
			echo '          <span class="faicon edit" onclick="displayVariableProfile();" title="'.$lang['srv_profile_edit'].'"></span>';
			echo '          <span class="faicon delete" onclick="removeVariableProfile();" title="'.$lang['srv_profile_remove'].'"></span>';
            echo '  </div>';

            echo '  </div>';
			

            echo '  <div class="content">';
			echo '      <span class="floatLeft">'.$variable_label.'</span>';
            echo '  </div>';

            echo '</div>';

			return true;
		}
		return false;
	}

	static function chooseProfile($pid){

		# če smo izbrali drug profil resetiramo še profil profilov na trenutne nastavitve
		SurveyUserSetting :: getInstance()->saveSettings('default_profileManager_pid', '0');
		
		if(isset(self::$profiles[$pid])) 
		{
			SurveyUserSetting :: getInstance()->saveSettings('default_variable_profile', $pid);
		}
		else
		{
			SurveyUserSetting :: getInstance()->saveSettings('default_variable_profile', SVP_DEFAULT_PROFILE);
		}
	}
	
	static function ajax() {

		$pid = isset($_POST['pid']) ? $_POST['pid'] : null;

		if ($_POST['podstran'] == 'monitoring') {
			self::$monitoring = true; self::refreshAvailableProfiles();
		};

		switch ($_GET['a']) {
			case 'displayProfile':
				self::displayProfiles($pid);

				break;
			case 'changeProfile':
				self::displayProfiles($pid);
				break;
			case 'chooseProfile':
				self::chooseProfile($pid);
				break;
			case 'saveProfile':
				self::saveProfile();
				break;
			case 'saveNewProfile':
				$new_id = self :: newProfileVariables();
				break;
			case 'renameProfile':
				$updated = self::renameVariableProfile($pid,$_POST['name']);
			break;
			case 'deleteProfile':
				self::deleteVariableProfile($pid);
			break;
		}
	}


	static function displayProfiles ($cvp = null) {
		global $lang;

		$pid = isset($_POST['pid']) ? $_POST['pid'] : null;

		$popUp = new PopUp();
		$popUp->setId('div_variable_profiles');
		$popUp->setHeaderText($lang['srv_spremenljivke_settings']);

		#vsebino shranimo v buffer
		ob_start();

        echo '<div class="popup_close"><a href="#" onClick="$(\'#fade\').fadeOut(\'slow\');$(\'#fullscreen\').fadeOut(\'slow\').html(\'\'); return false;">✕</a></div>';

		if ($cvp == null)
			$cvp = self::$currentId;

		$svp_ap = self::$profiles;
		$svp_pv = self :: getProfileVariables($cvp);
		$svp_av = self::$SDF->getSurveyVariables();

		if ( self::$currentId != SVP_DEFAULT_PROFILE ) {
			echo '<div id="not_default_setting" class="popup_note red">';
			echo $lang['srv_not_default_setting'];
			echo '</div>';
		}


        echo '<div class="popup_main with_menu">';
        

		echo '<div class="variable_profile_holder popup_left">';

		echo '	<div id="variable_profile" class="list select">';
		foreach ($svp_ap as $key => $value) {
		
			echo '<div class="list-item option'.($cvp==$value['id']?' active':'').'" value="'.$value['id'].'" '.($cvp==$value['id'] ? '' : ' onclick="changeVariableProfile(\''.$value['id'].'\');"').'>';
			
			echo $value['name'];
			
			if($cvp == $value['id']){

                echo '<div class="profile_icons">';
                
				// izbriši
				if ((int)$cvp != 0){
                    echo ' <a href="#" onclick="variableProfileAction(\'deleteAsk\'); return false;" value="'.$lang['srv_delete_profile'].'"><span class="faicon delete_circle icon-orange_link floatRight" style="margin-top:1px;"></span></a>'."\n";
				}
				// preimenuj
				if ((int)$cvp != 0){
                    echo ' <a href="#" onclick="variableProfileAction(\'renameAsk\'); return false;" value="'.$lang['srv_rename_profile'].'"><span class="faicon edit icon-as_link floatRight spaceRight"></span></a>'."\n";
				}
                
                echo '</div>';
			}
			
			echo '</div>';
		}
		echo '	</div>';
		
		echo '</div>';
		

		echo '<div id="vp_list" class="popup_right">';

		$empty = count($svp_pv) == 0;
		echo '<div id="vp_list_ul" class="settings_block">';
		if (count($svp_av) > 0){

			foreach($svp_av as $key => $variabla){
				$_name = self::$SDF->getVariableName($key);
				$checked = ($empty || in_array($key, $svp_pv));

				echo '<div class="setting_line">';
				echo '  <input type="checkbox" '.($checked?' checked="checekd"':'').' name="vp_list_li" value="'.$key.'" id="variable_'.$key.'" onchange="variableProfileCheckboxChange(this);">';
				echo '  <label for="variable_'.$key.'">'.limitString($_name).'</label>';
                echo '</div>';
			}
		}
		echo '</div>';

		// izberi / odznaci vse
		echo '<div class="settings_block">';
		echo '  <div class="setting_line">';
		echo '      <a href="#" onClick="variableProfileSelectAll(1); return false;">'.$lang['srv_select_all'].'</a> / <a href="#" onClick="variableProfileSelectAll(0); return false;">'.$lang['srv_deselect_all'].'</a>';
		echo '  </div>';
		echo '</div>';

		echo '</div>';


        echo '</div>';

        
		// cover Div
		echo '<div id="variableProfileCoverDiv"></div>';

		// div za shranjevanje novega profila
		echo '<div id="newProfile">';

		echo '<div class="setting_holder">';

        echo '<div class="setting_item">';
        echo '<label>'.$lang['srv_missing_profile_name'].':</label>';
		echo '<input id="newProfileName" name="newProfileName" type="text" class="text large"  />';
        echo '</div>';
        echo '</div>';

        echo '<div class="button_holder">';

		$button = new PopUpButton($lang['srv_cancel']);
		echo $button -> setFloat('right')
		-> addAction('onClick','variableProfileAction(\'newCancel\'); return false;');
		
		$button = new PopUpButton($lang['srv_save_profile']);
		echo $button -> setFloat('right')
		->setButtonColor('orange')
		-> addAction('onClick','variableProfileAction(\'newSave\'); return false;');

        echo '</div>';

		echo '</div>';

		// div za preimenovanje
		echo '<div id="renameProfileDiv">';

		echo '<div class="setting_holder">';

        echo '<div class="setting_item">';
        echo '<label>'.$lang['srv_missing_profile_name'].':</label>';
		echo '<input id="renameProfileName" name="renameProfileName" type="text" value="'.$svp_ap[$cvp]['name'].'" class="text large"  />';
		echo '<input id="renameProfileId" type="hidden" value="'.$pid.'"  />';
        echo '</div>';
        echo '</div>';

        echo '<div class="button_holder">';

		$button = new PopUpButton($lang['srv_cancel']);
		echo $button -> setFloat('right')
		-> addAction('onClick','variableProfileAction(\'renameCancel\'); return false;');
		
		$button = new PopUpButton($lang['srv_rename_profile_yes']);
		echo $button -> setFloat('right')
		->setButtonColor('orange')
		-> addAction('onClick','variableProfileAction(\'renameProfile\'); return false;');

		echo '</div>';
		
		echo '</div>';

		// div za brisanje
		echo '<div id="deleteProfileDiv">';
		
		echo $lang['srv_missing_profile_delete_confirm'].': <span class="semi-bold">'.$svp_ap[$cvp]['name'].'</span>?';
		echo '<input id="deleteProfileId" type="hidden" value="'.$pid.'"  />';

        echo '<div class="button_holder">';

		$button = new PopUpButton($lang['srv_cancel']);
		echo $button -> setFloat('right')
		-> addAction('onClick','variableProfileAction(\'deleteCancel\'); return false;');
		
		$button = new PopUpButton($lang['srv_delete_profile_yes']);
		echo $button -> setFloat('right')
		->setButtonColor('orange')
		-> addAction('onClick','variableProfileAction(\'deleteConfirm\'); return false;');
		
		echo '</div>';
		
		echo '</div>';

		$content = ob_get_clean();
		#dodamo vsebino
		$popUp->setContent($content);

        # dodamo gumb Preklici
		$button = new PopUpCancelButton();
		$popUp->addButton($button);

		# gumb shrani
		if ((int)$cvp != 0){
			$button = new PopUpButton($lang['srv_save_profile']);
			$button->addAction('onClick','variableProfileAction(\'save\'); return false;');
			$popUp->addButton($button);
		}
		
		# gumb shrani kot now
		$button = new PopUpButton($lang['srv_new_profile_name']);
		$button->addAction('onClick','variableProfileAction(\'newName\'); return false;');
		$popUp->addButton($button);
		
        # gumb izberi
		$button = new PopUpButton($lang['srv_choose_profile']);
		$button -> setFloat('right')
		->setButtonColor('orange')
		-> addAction('onClick','variableProfileAction(\'choose\'); return false;');
		$popUp->addButton($button);

		echo $popUp;
	}


	static function setProfileVariables($pid, $variables)
	{
		global $lang;
		# če je pid < 1 ga shranimo v sejo
		if ($pid < 1)
		{
			$pid = -1;
			session_start();
		
			# nastavimo kot sejo
			$_SESSION['variables_profile'][self::$sid] = array(
					'id' => "$pid",
					'name' => $lang['srv_missing_profile_temp'],
					'variables' => $variables);
		
					self::$profiles[$pid] = $_SESSION['variables_profile'][self::$sid];
					session_commit();
					
		} 
		else 
		{
			$updateString = "UPDATE srv_variable_profiles SET variables = '".$variables."' WHERE id='".$pid."' AND sid = '". self::$sid."'";
			$sqlupdate = sisplet_query($updateString) or die(mysqli_error($GLOBALS['connect_db']));
			self::$profiles[$pid]['variables'] = $variables;
		}
		
		//echo $pid;
		return $pid;
	}
	
	static function saveProfile()
	{
		global $lang;

		$pid = $_POST['pid'];
		$strArray = explode("&",$_POST['vp_list_li']);

		$variables = array();
		foreach ($strArray as $item)
		{
			$array = explode("=", $item);
			$variables[] = $array[1];
		}
		$variables = serialize($variables);
		
		return self::setProfileVariables($pid, $variables);
	}
	
	
	static function newProfileVariables() {
		global $lang;
		
		$profileId = -1;
		$numrows = -1;
		
		$profileName = $_POST['name'];
		if (empty($profileName))
		{
			$profileName = $lang['srv_new_profile_name'];
		}
		
		# ime profila preverima ali obstaja
		do 
		{ # preverimo ali ime že obstaja
			$selectSqlProfile = "SELECT id FROM srv_variable_profiles WHERE name = '".$profileName."' AND sid = '".self::$sid."'";
			$sqlProfileSetting = sisplet_query($selectSqlProfile);
			$numrows = mysqli_num_rows($sqlProfileSetting);
			if ($numrows != 0) 
			{ # ime že obstaja zgeneriramo novo
				srand(time());
				$profileName .= rand(0, 9);
			}
		} 
		while ($numrows != 0);
		
		$strArray = explode("&",$_POST['vp_list_li']);
		$variables = array();
		foreach ($strArray as $item) {
			$array = explode("=", $item);
			$variables[] = $array[1];
		}
		$variables = serialize($variables);

		$stringInsert = "INSERT INTO srv_variable_profiles (sid,name,variables) " .
						"VALUES ('".self::$sid."','".$profileName."','".$variables."')";
		sisplet_query($stringInsert);
		$insertId = mysqli_insert_id($GLOBALS['connect_db']);

		# osvežimo profile
		self::getProfiles();
		
		#nastavimo privzetega
		self::chooseProfile($insertId);
		
		echo $insertId;
		
		return $insertId;
	
	}
	
	function deleteVariableProfile($pid) {
		if ($pid < 0 ) 
		{ // seja -
			session_start();
			unset($_SESSION['variables_profile'][self::$sid]);
			unset(self::$profiles[$pid]);
			session_commit();
		} 
		else if( $pid > 0) 
		{
			$deleteString = "DELETE FROM srv_variable_profiles WHERE id='".$pid."' AND sid = '". self::$sid."'";
			$sqlDelete = sisplet_query($deleteString);
			unset(self::$profiles[$pid]);
		}
		$pid = SVP_DEFAULT_PROFILE;
		
		return self::chooseProfile($pid);
	}
	
	
	function renameVariableProfile($profileId, $newProfileName) {
		global $lang;
		
		$sqlInsert = -1;
		if ( !empty($profileId) && (int)$profileId > 0) 
		{
			if ( $newProfileName == null || $newProfileName == "" ) 
			{
				$newProfileName = $lang['srv_new_profile_name'];
			}
	
			$numrows = -1;
			do { // preverimo ali ime že obstaja
				$selectSqlProfile = "SELECT id FROM srv_variable_profiles WHERE name = '".$newProfileName."' AND sid = '".self::$sid."'";
				$sqlProfileSetting = sisplet_query($selectSqlProfile);
	
				$numrows = mysqli_num_rows($sqlProfileSetting);
				if ($numrows != 0) { // ime že obstaja zgeneriramo novo
					srand(time());
					$newProfileName .= rand(0, 9);
				}
			} while ($numrows != 0);
				
			$updateString = "UPDATE srv_variable_profiles SET name = '".$newProfileName."' WHERE id = '".$profileId."' AND sid = '".self::$sid."'";
			$sqlInsert = sisplet_query($updateString);
		}
		
		return $sqlInsert;
	}
	
	/** Nastavimo profil kot zacasen inspect
	 *
	 * Enter description here ...
	 * @param $variables
	 */
	function setProfileInspect($variables) {
		global $lang;
	
		# nastavimo kot sejo
		$pid = -1;
		
		if (is_array($variables))
		{
			$variables = serialize($variables);
		}
		
		self::$profiles[$pid] = array('id'=>$pid, 'name'=>$lang['srv_inspect_temp_profile'], 'variables'=>$variables);
		session_start();
		$_SESSION['variables_profile'][self::$sid] = self::$profiles[$pid];
		session_commit();
		# dodoamo še v class
		self::setDefaultProfile($pid);
	}
	
	/** old class compatibility **/
	static function setDefaultProfile($pid) {
		self::chooseProfile($pid);
	}
	/** old class compatibility **/
	static function setDefaultProfileId($pid) {
		self::chooseProfile($pid);
	}
	
	/** preveri obstoj profila in vrne enak id če obstaja, če ne vrne id privzetega profila
	 *
	 * @param unknown_type $pid
	 * @return unknown
	 */
	function checkProfileExist($pid)
	{
		if (isset(self::$profiles[$pid]))
		{
			return true;
		}
		return false;
	}
	
}

function limitString($input, $limit = 100) {
	
	// Return early if the string is already shorter than the limit
	if(strlen($input) < $limit) {
		return $input;
	}

	$regex = "/(.{1,$limit})\b/";
	preg_match($regex, $input, $matches);
	
	return $matches[1].'...';
}

?>