scrigo.js.php 27.8 KB
Newer Older
1
<?php
2 3 4 5 6 7 8 9 10
session_start();
include '../../lib/config.inc.php';
header('Content-Type: text/javascript; charset=utf-8'); // the config file sets the content type header so we have to override it here!
require_once '../../lib/app.inc.php';
$lang = (isset($_SESSION['s']['language']) && $_SESSION['s']['language'] != '')?$_SESSION['s']['language']:'en';
include_once ISPC_ROOT_PATH.'/web/strengthmeter/lib/lang/'.$lang.'_strengthmeter.lng';

$app->uses('ini_parser,getconf');
$server_config_array = $app->getconf->get_global_config();
11
?>
mcramer's avatar
mcramer committed
12 13 14 15 16
var pageFormChanged = false;
var tabChangeWarningTxt = '';
var tabChangeDiscardTxt = '';
var tabChangeWarning = false;
var tabChangeDiscard = false;
17 18 19 20
var requestsRunning = 0;
var indicatorPaddingH = -1;
var indicatorPaddingW = -1;
var indicatorCompleted = false;
Marius Cramer's avatar
Marius Cramer committed
21
var registeredHooks = new Array();
22 23
redirect = '';

24
function reportError(request) {
25 26
	/* Error reporting is disabled by default as some browsers like safari
	   sometimes throw errors when a ajax request is delayed even if the
27
	   ajax request worked. */
28

29 30 31
	/*alert(request);*/
}

Marius Cramer's avatar
Marius Cramer committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45
function registerHook(name, callback) {
    if(!registeredHooks[name]) registeredHooks[name] = new Array();
    var newindex = registeredHooks[name].length;
    registeredHooks[name][newindex] = callback;
}

function callHook(name, params) {
    if(!registeredHooks[name]) return;
    for(var i = 0; i < registeredHooks[name].length; i++) {
        var callback = registeredHooks[name][i];
        callback(name, params);
    }
}

46 47 48 49
function resetFormChanged() {
    pageFormChanged = false;
}

50
function showLoadIndicator() {
51 52
    document.body.style.cursor = 'wait';

53 54 55
<?php
if($server_config_array['misc']['use_loadindicator'] == 'y'){
?>
56
    requestsRunning += 1;
57

58 59 60 61 62 63 64 65 66
    if(requestsRunning < 2) {
        var indicator = jQuery('#ajaxloader');
        if(indicator.length < 1) {
            indicator = jQuery('<div id="ajaxloader" style="display: none;"></div>');
            indicator.appendTo('body');
        }
        var parent = jQuery('#content');
        if(parent.length < 1) return;
        indicatorCompleted = false;
67

68 69 70 71 72 73 74 75
        var atx = parent.offset().left + 150; //((parent.outerWidth(true) - indicator.outerWidth(true)) / 2);
        var aty = parent.offset().top + 150;
        indicator.css( {'left': atx, 'top': aty } ).fadeIn('fast', function() {
            // check if loader should be hidden immediately
            indicatorCompleted = true;
            if(requestsRunning < 1) $(this).fadeOut('fast', function() { $(this).hide();});
        });
    }
76 77 78
<?php
}
?>
79 80 81
}

function hideLoadIndicator() {
82 83
    document.body.style.cursor = '';

84 85 86 87 88 89 90 91
    requestsRunning -= 1;
    if(requestsRunning < 1) {
        requestsRunning = 0; // just for the case...
        if(indicatorCompleted == true) jQuery('#ajaxloader').fadeOut('fast', function() { jQuery('#ajaxloader').hide(); } );
    }
}

function onAfterContentLoad() {
92 93 94
<?php
if($server_config_array['misc']['use_combobox'] == 'y'){
?>
95
    $('#pageContent').find("select").combobox();
96 97 98
<?php
}
?>
99
	callHook('onAfterContentLoad');
100 101
}

102
function loadContentRefresh(pagename) {
103

104
  if(document.getElementById('refreshinterval').value > 0) {
105
	var pageContentObject2 = jQuery.ajax({	type: "GET",
106
											url: pagename,
107
											data: "refresh="+document.getElementById('refreshinterval').value,
108
											dataType: "html",
109 110 111
											beforeSend: function() {
												showLoadIndicator();
											},
112
											success: function(data, textStatus, jqXHR) {
113
                                                hideLoadIndicator();
114
												jQuery('#pageContent').html(jqXHR.responseText);
115
                                                onAfterContentLoad();
mcramer's avatar
mcramer committed
116
                                                pageFormChanged = false;
117 118
											},
											error: function() {
119
                                                hideLoadIndicator();
120
												reportError('Ajax Request was not successful.'+pagename);
cfoe's avatar
cfoe committed
121
											}
122
										});
123
  	setTimeout( "loadContentRefresh('"+pagename+"&refresh="+document.getElementById('refreshinterval').value+"')", document.getElementById('refreshinterval').value*1000*60 );
124 125 126
  }
}

127
function capp(module, redirect) {
128 129
	var submitFormObj = jQuery.ajax({		type: "GET",
											url: "capp.php",
130
											data: "mod="+module+((redirect != undefined) ? '&redirect='+redirect : ''),
131
											dataType: "html",
132 133 134
											beforeSend: function() {
												showLoadIndicator();
											},
135 136 137 138 139
											success: function(data, textStatus, jqXHR) {
												if(jqXHR.responseText != '') {
													if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
														var parts = jqXHR.responseText.split(':');
														loadContent(parts[1]);
140 141 142
													} else if (jqXHR.responseText.indexOf('URL_REDIRECT:') > -1) {
														var newUrl= jqXHR.responseText.substr(jqXHR.responseText.indexOf('URL_REDIRECT:') + "URL_REDIRECT:".length);
														document.location.href = newUrl;
143
													} else {
144
														//alert(jqXHR.responseText);
145 146 147
													}
												}
												loadMenus();
148
                                                hideLoadIndicator();
149 150
											},
											error: function() {
151
                                                hideLoadIndicator();
152
												reportError('Ajax Request was not successful.'+module);
cfoe's avatar
cfoe committed
153
											}
154
									});
155 156 157 158 159 160 161 162 163 164 165 166 167 168
}

function submitLoginForm(formname) {
    //* Validate form. TODO: username and password with strip();
    var frm = document.getElementById(formname);
    var userNameObj = frm.username;
    if(userNameObj.value == ''){
        userNameObj.focus();
        return;
    }
    var passwordObj = frm.passwort;
    if(passwordObj.value == ''){
        passwordObj.focus();
        return;
169
    }
170

171 172 173 174
	$('#dummy_username').val(userNameObj.value);
	$('#dummy_passwort').val(passwordObj.value);
	$('#dummy_login_form').submit();

175
	var submitFormObj = jQuery.ajax({		type: "POST",
176 177
											url: "content.php",
											data: jQuery('#'+formname).serialize(),
178
											dataType: "html",
179 180 181
											beforeSend: function() {
												showLoadIndicator();
											},
182 183 184 185 186 187 188 189 190 191 192
											success: function(data, textStatus, jqXHR) {
												if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
													var parts = jqXHR.responseText.split(':');
													//alert(parts[1]);
													loadContent(parts[1]);
													//redirect = parts[1];
													//window.setTimeout('loadContent(redirect)', 1000);
												} else if (jqXHR.responseText.indexOf('LOGIN_REDIRECT:') > -1) {
													// Go to the login page
													document.location.href = 'index.php';
												} else {
193
													jQuery('#pageContent').html(jqXHR.responseText);
194
                                                    onAfterContentLoad();
mcramer's avatar
mcramer committed
195
                                                    pageFormChanged = false;
196 197
												}
												loadMenus();
198
                                                hideLoadIndicator();
199 200
											},
											error: function() {
201
                                                hideLoadIndicator();
202
												reportError('Ajax Request was not successful.110');
cfoe's avatar
cfoe committed
203
											}
204
									});
205 206 207 208 209
	/*
	if(redirect != '') {
		loadContent(redirect);
		redirect = '';
	}
210
	document.getElementById('footer').innerHTML = 'Powered by <a href="http://www.ispconfig.org" target="_blank">ISPConfig</a>';
211
	*/
212

213 214
}

215
function submitForm(formname,target) {
216
	var submitFormObj = jQuery.ajax({		type: "POST",
217 218
											url: target,
											data: jQuery('#'+formname).serialize(),
219
											dataType: "html",
220 221 222
											beforeSend: function() {
												showLoadIndicator();
											},
223 224 225 226 227 228 229 230
											success: function(data, textStatus, jqXHR) {
												if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
													var parts = jqXHR.responseText.split(':');
													//alert(parts[1]);
													loadContent(parts[1]);
													//redirect = parts[1];
													//window.setTimeout('loadContent(redirect)', 1000);
												} else {
231
													jQuery('#pageContent').html(jqXHR.responseText);
232
                                                    onAfterContentLoad();
mcramer's avatar
mcramer committed
233
                                                    pageFormChanged = false;
234
												}
235
                                                hideLoadIndicator();
236 237
											},
											error: function(jqXHR, textStatus, errorThrown) {
238
                                                hideLoadIndicator();
239 240
												var parts = jqXHR.responseText.split(':');
												reportError('Ajax Request was not successful. 111');
cfoe's avatar
cfoe committed
241
											}
242
									});
243 244 245 246 247 248 249 250
	/*
	if(redirect != '') {
		loadContent(redirect);
		redirect = '';
	}
	*/
}

251
function submitFormConfirm(formname,target,confirmation) {
252
	var successMessage = arguments[3];
253
	if(window.confirm(confirmation)) {
254
		var submitFormObj = jQuery.ajax({	type: "POST",
255 256 257
											url: target,
											data: jQuery('#'+formname).serialize(),
											dataType: "html",
258 259 260
											beforeSend: function() {
												showLoadIndicator();
											},
261
											success: function(data, textStatus, jqXHR) {
262
												if(successMessage) alert(successMessage);
263 264 265 266 267 268 269 270
												if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
													var parts = jqXHR.responseText.split(':');
													//alert(parts[1]);
													loadContent(parts[1]);
													//redirect = parts[1];
													//window.setTimeout('loadContent(redirect)', 1000);
												} else {
													jQuery('#pageContent').html(jqXHR.responseText);
271
                                                    onAfterContentLoad();
mcramer's avatar
mcramer committed
272
                                                    pageFormChanged = false;
273
												}
274
                                                hideLoadIndicator();
275 276
											},
											error: function(jqXHR, textStatus, errorThrown) {
277
                                                hideLoadIndicator();
278 279
												var parts = jqXHR.responseText.split(':');
												reportError('Ajax Request was not successful. 111');
cfoe's avatar
cfoe committed
280
											}
281 282 283 284
									});
	}
}

285
function submitUploadForm(formname,target) {
286 287
	var handleResponse = function(loadedFrame) {
		var response, responseStr = loadedFrame.contentWindow.document.body.innerHTML;
288

289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
		try {
			response = JSON.parse(responseStr);
		} catch(e) {
			response = responseStr;
		}
		var msg = '';
		var okmsg = jQuery('#OKMsg',response).html();
		if(okmsg){
			msg = '<div id="OKMsg">'+okmsg+'</div>';
		}
		var errormsg = jQuery('#errorMsg',response).html();
		if(errormsg){
			msg = msg+'<div id="errorMsg">'+errormsg+'</div>';
		}
		return msg;
304

305
    };
306

307 308
	var frame_id = 'ajaxUploader-iframe-' + Math.round(new Date().getTime() / 1000);
	jQuery('body').after('<iframe width="0" height="0" style="display:none;" name="'+frame_id+'" id="'+frame_id+'"/>');
309
	jQuery('input[type="file"]').closest("form").attr({target: frame_id, action: target}).submit();
310 311 312 313 314
	jQuery('#'+frame_id).load(function() {
        var msg = handleResponse(this);
		jQuery('#errorMsg').remove();
		jQuery('#OKMsg').remove();
		jQuery('input[name="id"]').before(msg);
315
		jQuery(this).remove();
316 317
      });

318 319 320 321 322 323 324 325 326
	/*
	if(redirect != '') {
		loadContent(redirect);
		redirect = '';
	}
	*/
}

function loadContent(pagename) {
mcramer's avatar
mcramer committed
327
  var params = arguments[1];
328
  var pageContentObject2 = jQuery.ajax({	type: "GET",
329
											url: pagename,
mcramer's avatar
mcramer committed
330
                                            data: (params ? params : null),
331
											dataType: "html",
332
											beforeSend: function() {
333
												showLoadIndicator();
334
											},
335 336 337 338 339 340 341 342
											success: function(data, textStatus, jqXHR) {
												if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
													var parts = jqXHR.responseText.split(':');
													loadContent(parts[1]);
												} else if (jqXHR.responseText.indexOf('URL_REDIRECT:') > -1) {
													var newUrl= jqXHR.responseText.substr(jqXHR.responseText.indexOf('URL_REDIRECT:') + "URL_REDIRECT:".length);
													document.location.href = newUrl;
												} else {
343 344 345 346
													//document.getElementById('pageContent').innerHTML = jqXHR.responseText;
													//var reponse = jQuery(jqXHR.responseText);
													//var reponseScript = reponse.filter("script");
													//jQuery.each(reponseScript, function(idx, val) { eval(val.text); } );
347

348
													jQuery('#pageContent').html(jqXHR.responseText);
349
                                                    onAfterContentLoad();
mcramer's avatar
mcramer committed
350
                                                    pageFormChanged = false;
351
												}
352
                                                hideLoadIndicator();
353 354
											},
											error: function() {
355
                                                hideLoadIndicator();
356
												reportError('Ajax Request was not successful. 113');
cfoe's avatar
cfoe committed
357
											}
358
									});
359 360 361 362
}


function loadInitContent() {
363
	var pageContentObject = jQuery.ajax({	type: "GET",
364 365
											url: "content.php",
											data: "s_mod=login&s_pg=index",
366
											dataType: "html",
367 368 369
											beforeSend: function() {
												showLoadIndicator();
											},
370 371 372 373 374
											success: function(data, textStatus, jqXHR) {
												if(jqXHR.responseText.indexOf('HEADER_REDIRECT:') > -1) {
													var parts = jqXHR.responseText.split(":");
													loadContent(parts[1]);
												} else {
375
													jQuery('#pageContent').html(jqXHR.responseText);
376
                                                    onAfterContentLoad();
mcramer's avatar
mcramer committed
377
                                                    pageFormChanged = false;
378
												}
379
                                                hideLoadIndicator();
380 381
											},
											error: function() {
382
                                                hideLoadIndicator();
383
												reportError('Ajax Request was not successful. 114');
cfoe's avatar
cfoe committed
384
											}
385
										});
386

387 388 389 390 391 392 393
  loadMenus();
  keepalive();
  setTimeout("setFocus()",1000);

}

function setFocus() {
394
	try {
395
		jQuery('form#pageForm').find('input[name="username"]').focus();
396 397
	} catch (e) {
	}
398 399 400 401
}


function loadMenus() {
402
  var sideNavObject = jQuery.ajax({			type: "GET",
403 404
											url: "nav.php",
											data: "nav=side",
405
											dataType: "html",
406 407 408
											beforeSend: function() {
												showLoadIndicator();
											},
409
											success: function(data, textStatus, jqXHR) {
410
                                                hideLoadIndicator();
411
												jQuery('#sideNav').html(jqXHR.responseText);
412 413
											},
											error: function() {
414
                                                hideLoadIndicator();
415
												reportError('Ajax Request was not successful. 115');
cfoe's avatar
cfoe committed
416
											}
417
									});
418 419

  var topNavObject = jQuery.ajax({			type: "GET",
420 421
											url: "nav.php",
											data: "nav=top",
422
											dataType: "html",
423 424 425
											beforeSend: function() {
												showLoadIndicator();
											},
426
											success: function(data, textStatus, jqXHR) {
427
                                                hideLoadIndicator();
428
												jQuery('#topNav').html(jqXHR.responseText);
429 430
											},
											error: function(o) {
431
                                                hideLoadIndicator();
432
												reportError('Ajax Request was not successful. 116');
cfoe's avatar
cfoe committed
433
											}
434
								});
435 436 437

}

438
function changeTab(tab,target,force) {
439 440
	//document.forms[0].next_tab.value = tab;
	document.pageForm.next_tab.value = tab;
441

442 443 444
    var idel = jQuery('form#pageForm').find('[name="id"]');
    var id = null;
    if(idel.length > 0) id = idel.val();
445
    if(tabChangeDiscard == 'y' && !force) {
446
        if((idel.length < 1 || id) && (pageFormChanged == false || window.confirm(tabChangeDiscardTxt))) {
mcramer's avatar
mcramer committed
447
            var next_tab = tab;
448 449
            if(id) loadContent(target, {'next_tab': next_tab, 'id': id});
            else loadContent(target, {'next_tab': next_tab});
mcramer's avatar
mcramer committed
450 451 452 453 454 455 456 457 458
        } else {
            return false;
        }
    } else {
        if(id && tabChangeWarning == 'y' && pageFormChanged == true) {
            if(window.confirm(tabChangeWarningTxt)) {
                submitForm('pageForm', target);
            } else {
                var next_tab = tab;
459 460
                if(id) loadContent(target, {'next_tab': next_tab, 'id': id});
                else loadContent(target, {'next_tab': next_tab});
mcramer's avatar
mcramer committed
461 462 463 464 465
            }
        } else {
            submitForm('pageForm',target);
        }
    }
466
}
467

468 469 470 471 472 473
function del_record(link,confirmation) {
  if(window.confirm(confirmation)) {
          loadContent(link);
  }
}

474 475 476 477 478 479
function confirm_action(link,confirmation) {
  if(window.confirm(confirmation)) {
          loadContent(link);
  }
}

480
function loadContentInto(elementid,pagename) {
481
  var pageContentObject2 = jQuery.ajax({	type: "GET",
482
											url: pagename,
483
											dataType: "html",
484 485 486
											beforeSend: function() {
//												showLoadIndicator();
											},
487
											success: function(data, textStatus, jqXHR) {
488
//                                                hideLoadIndicator();
489
												jQuery('#'+elementid).html(jqXHR.responseText);
490 491
											},
											error: function() {
492
//                                                hideLoadIndicator();
493
												reportError('Ajax Request was not successful. 118');
cfoe's avatar
cfoe committed
494
											}
495
										});
496 497
}

498
function loadOptionInto(elementid,pagename) {
499
	var pageContentObject2 = jQuery.ajax({	type: "GET",
500
											url: pagename,
501
											dataType: "html",
502 503 504
											beforeSend: function() {
//												showLoadIndicator();
											},
505
											success: function(data, textStatus, jqXHR) {
506
//                                                hideLoadIndicator();
507 508 509 510 511 512 513 514 515 516 517 518 519
												var teste = jqXHR.responseText;
												var elemente = teste.split('#');
												el=document.getElementById(elementid);
												el.innerHTML='';
												for (var i = 0; i < elemente.length; ++i){

													var foo2 = document.createElement("option");
													foo2.appendChild(document.createTextNode(elemente[i]));
													foo2.value=elemente[i];
													el.appendChild(foo2);
												}
											},
											error: function() {
520
//                                                hideLoadIndicator();
521
												reportError('Ajax Request was not successful. 119');
cfoe's avatar
cfoe committed
522
											}
523
										});
524 525
}

526
function keepalive() {
527
	var pageContentObject3 = jQuery.ajax({	type: "GET",
528
											url: "keepalive.php",
529
											dataType: "html",
530 531 532 533 534
											success: function(data, textStatus, jqXHR) {
												setTimeout( keepalive, 1000000 );
											},
											error: function() {
												reportError('Session expired. Please login again.');
cfoe's avatar
cfoe committed
535
											}
536
										});
537 538 539 540
  	//setTimeout( keepalive, 1000000 );
}


541 542 543 544 545 546 547
<?php
$min_password_length = 5;
if(isset($server_config_array['misc']['min_password_length'])) {
	$min_password_length = $app->functions->intval($server_config_array['misc']['min_password_length']);
}
?>
var pass_minimum_length = <?php echo $min_password_length; ?>;
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
var pass_messages = new Array();

var pass_message = new Array();
pass_message['text'] = "<?php echo $wb['password_strength_0_txt']?>";
pass_message['color'] = "#d0d0d0";
pass_messages[0] = pass_message;

var pass_message = new Array();
pass_message['text'] = "<?php echo $wb['password_strength_1_txt']?>";
pass_message['color'] = "red";
pass_messages[1] = pass_message;

var pass_message = new Array();
pass_message['text'] = "<?php echo $wb['password_strength_2_txt']?>";
pass_message['color'] = "yellow";
pass_messages[2] = pass_message;

var pass_message = new Array();
pass_message['text'] = "<?php echo $wb['password_strength_3_txt']?>";
pass_message['color'] = "#00ff00";
pass_messages[3] = pass_message;

var pass_message = new Array();
pass_message['text'] = "<?php echo $wb['password_strength_4_txt']?>";
pass_message['color'] = "green";
pass_messages[4] = pass_message;

var pass_message = new Array();
pass_message['text'] = "<?php echo $wb['password_strength_5_txt']?>";
pass_message['color'] = "green";
pass_messages[5] = pass_message;

function pass_check(password) {
	var length = password.length;
	var points = 0;
	if (length < pass_minimum_length) {
		pass_result(0);
		return;
	}
587

588 589 590 591
	if (length < 5) {
		pass_result(1);
		return;
	}
592

593 594 595
	if (pass_contains(password, "ABCDEFGHIJKLNMOPQRSTUVWXYZ")) {
		points += 1;
	}
596

597 598 599
	if (pass_contains(password, "0123456789")) {
		points += 1;
	}
600

601 602 603
	if (pass_contains(password, "`~!@#$%^&*()_+|\=-[]}{';:/?.>,<\" ")) {
		points += 1;
	}
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
	if (points == 0) {
		if (length >= 5 && length <=6) {
			pass_result(1);
		} else if (length >= 7 && length <=8) {
			pass_result(2);
		} else {
			pass_result(3);
		}
	} else if (points == 1) {
		if (length >= 5 && length <=6) {
			pass_result(2);
		} else if (length >= 7 && length <=10) {
			pass_result(3);
		} else {
			pass_result(4);
		}
	} else if (points == 2) {
		if (length >= 5 && length <=8) {
			pass_result(3);
		} else if (length >= 9 && length <=10) {
			pass_result(4);
		} else {
			pass_result(5);
		}
	} else if (points == 3) {
		if (length >= 5 && length <=6) {
			pass_result(3);
		} else if (length >= 7 && length <=8) {
			pass_result(4);
		} else {
			pass_result(5);
		}
	} else if (points >= 4) {
		if (length >= 5 && length <=6) {
			pass_result(4);
		} else {
			pass_result(5);
		}
	}
}



function pass_result(points, message) {
	if (points == 0) {
		width = 10;
	} else {
		width = points*20;
	}
	document.getElementById("passBar").innerHTML = '<div style="float:left; height: 10px; padding:0px; background-color: ' + pass_messages[points]['color'] + '; width: ' + width + 'px;" />';
	document.getElementById("passText").innerHTML = pass_messages[points]['text'];
}
function pass_contains(pass, check) {
	for (i = 0; i < pass.length; i++) {
		if (check.indexOf(pass.charAt(i)) > -1) {
			return true;
		}
	}
	return false;
}

666
var new_tpl_add_id = 0;
667
function addAdditionalTemplate(){
668 669 670 671
    var tpl_add = jQuery('#template_additional').val();
    var addTemplate = jQuery('#tpl_add_select').val().split('|',2);
	var addTplId = addTemplate[0];
	var addTplText = addTemplate[1];
672
	if(addTplId > 0) {
673 674 675 676 677 678 679 680 681 682
        var newVal = tpl_add.split('/');
        new_tpl_add_id += 1;
        var delbtn = jQuery('<a href="#"></a>').attr('class', 'button icons16 icoDelete').click(function(e) {
            e.preventDefault();
            delAdditionalTemplate($(this).parent().attr('rel'));
        });
        newVal[newVal.length] = 'n' + new_tpl_add_id + ':' + addTplId;
	    jQuery('<li>' + addTplText + '</li>').attr('rel', 'n' + new_tpl_add_id).append(delbtn).appendTo('#template_additional_list ul');
	    jQuery('#template_additional').val(newVal.join('/'));
	    alert('additional template ' + addTplText + ' added to customer');
683
	} else {
684
	    alert('no additional template selcted');
685 686 687
	}
}

688 689 690 691 692 693 694
function delAdditionalTemplate(tpl_id){
    var tpl_add = jQuery('#template_additional').val();
	if(tpl_id) {
        // new style
		var $el = jQuery('#template_additional_list ul').find('li[rel="' + tpl_id + '"]').eq(0); // only the first
        var addTplText = $el.text();
        $el.remove();
695

696 697 698 699 700 701 702 703 704 705 706
		var oldVal = tpl_add.split('/');
		var newVal = new Array();
        for(var i = 0; i < oldVal.length; i++) {
            var tmp = oldVal[i].split(':', 2);
            if(tmp.length == 2 && tmp[0] == tpl_id) continue;
            newVal[newVal.length] = oldVal[i];
        }
        jQuery('#template_additional').val(newVal.join('/'));
		alert('additional template ' + addTplText + ' deleted from customer');
    } else if(tpl_add != '') {
        // old style
707 708 709
		var addTemplate = document.getElementById('tpl_add_select').value.split('|',2);
		var addTplId = addTemplate[0];
		var addTplText = addTemplate[1];
710 711 712 713 714 715 716 717 718

		jQuery('#template_additional_list ul').find('li:not([rel])').each(function() {
            var text = jQuery(this).text();
            if(text == addTplText) {
                jQuery(this).remove();
                return false;
            }
            return this;
        });
719

720
		var newVal = tpl_add;
721 722
        var repl = new RegExp('(^|\/)' + addTplId + '(\/|$)');
		newVal = newVal.replace(repl, '');
723
		newVal = newVal.replace('//', '/');
724
		jQuery('#template_additional').val(newVal);
725 726 727 728
		alert('additional template ' + addTplText + ' deleted from customer');
  } else {
  	alert('no additional template selcted');
  }
729

730
}
731 732 733 734 735 736 737 738 739 740 741

function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}
742

743
function password(minLength, special){
744 745 746
	var iteration = 0;
	var password = "";
	var randomNumber;
747 748 749
	minLength = minLength || 10;
	var maxLength = minLength + 5;
	var length = getRandomInt(minLength, maxLength);
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
	if(special == undefined){
		var special = false;
	}
	while(iteration < length){
		randomNumber = (Math.floor((Math.random() * 100)) % 94) + 33;
		if(!special){
			if ((randomNumber >=33) && (randomNumber <=47)) { continue; }
			if ((randomNumber >=58) && (randomNumber <=64)) { continue; }
			if ((randomNumber >=91) && (randomNumber <=96)) { continue; }
			if ((randomNumber >=123) && (randomNumber <=126)) { continue; }
		}
		iteration++;
		password += String.fromCharCode(randomNumber);
	}
	return password;
}

767 768 769 770 771 772 773
<?php
$min_password_length = 10;
if(isset($server_config_array['misc']['min_password_length'])) {
	$min_password_length = $app->functions->intval($server_config_array['misc']['min_password_length']);
}
?>

Falko Timme's avatar
Falko Timme committed
774
function generatePassword(passwordFieldID, repeatPasswordFieldID){
775 776 777 778
	var oldPWField = jQuery('#'+passwordFieldID);
	var newPWField = oldPWField.clone();
	newPWField.attr('type', 'text').attr('id', 'tmp'+passwordFieldID).insertBefore(oldPWField);
	oldPWField.remove();
779
	var pword = password(<?php echo $min_password_length ?>, false);
Falko Timme's avatar
Falko Timme committed
780 781
	jQuery('#'+repeatPasswordFieldID).val(pword);
	newPWField.attr('id', passwordFieldID).val(pword).trigger('keyup');
782
}
783

784 785
var funcDisableClick = function(e) { e.preventDefault(); return false; };

786 787 788 789 790 791 792
function checkPassMatch(pwField1,pwField2){
    var rpass = jQuery('#'+pwField2).val();
    var npass = jQuery('#'+pwField1).val();
    if(npass!= rpass) {
		jQuery('#confirmpasswordOK').hide();
        jQuery('#confirmpasswordError').show();
		jQuery('button.positive').attr('disabled','disabled');
793 794 795 796 797 798
        jQuery('.tabbox_tabs ul li a').each(function() {
            var $this = $(this);
            $this.data('saved_onclick', $this.attr('onclick'));
            $this.removeAttr('onclick');
            $this.click(funcDisableClick);
        });
799 800 801 802 803
        return false;
    } else {
		jQuery('#confirmpasswordError').hide();
        jQuery('#confirmpasswordOK').show();
		jQuery('button.positive').removeAttr('disabled');
804 805 806 807 808
		jQuery('.tabbox_tabs ul li a').each(function() {
            var $this = $(this);
            $this.unbind('click', funcDisableClick);
            if($this.data('saved_onclick') && !$this.attr('onclick')) $this.attr('onclick', $this.data('saved_onclick'));
        });
809 810 811
    }
}

812 813 814 815
function getRandomInt(min, max){
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

816 817 818 819 820
jQuery('.addPlaceholder').live("click", function(){
	var placeholderText = jQuery(this).text();
	var template = jQuery(this).siblings(':input');
	template.insertAtCaret(placeholderText);
});
821 822 823 824 825 826

jQuery('.addPlaceholderContent').live("click", function(){
	var placeholderContentText = jQuery(this).find('.addPlaceholderContent').text();
	var template2 = jQuery(this).siblings(':input');
	template2.insertAtCaret(placeholderContentText);
});
827

828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
jQuery.fn.extend({
	insertAtCaret: function(myValue){
		return this.each(function(i) {
			if (document.selection) {
				//For browsers like Internet Explorer
				this.focus();
				sel = document.selection.createRange();
				sel.text = myValue;
				this.focus();
			} else if (this.selectionStart || this.selectionStart == '0') {
				//For browsers like Firefox and Webkit based
				var startPos = this.selectionStart;
				var endPos = this.selectionEnd;
				var scrollTop = this.scrollTop;
				this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length);
				this.focus();
				this.selectionStart = startPos + myValue.length;
				this.selectionEnd = startPos + myValue.length;
				this.scrollTop = scrollTop;
			} else {
				this.value += myValue;
				this.focus();
			}
		})
	}
});