Simple Groupware PHP Cross Reference Groupware Applications

Source: /src/ext/js/functions.js - 1706 lines - 55952 bytes - Summary - Text - Print

   1  /**************************************************************************\
   2      * Simple Groupware 0.743                                                   *
   3      * http://www.simple-groupware.de                                           *
   4      * Copyright (C) 2002-2012 by Thomas Bley                                   *
   5      * ------------------------------------------------------------------------ *
   6      *  This program is free software; you can redistribute it and/or           *
   7      *  modify it under the terms of the GNU General Public License Version 2   *
   8      *  as published by the Free Software Foundation; only version 2            *
   9      *  of the License, no later version.                                       *
  10      *                                                                          *
  11      *  This program is distributed in the hope that it will be useful,         *
  12      *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
  13      *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
  14      *  GNU General Public License for more details.                            *
  15      *                                                                          *
  16      *  You should have received a copy of the GNU General Public License       *
  17      *  Version 2 along with this program; if not, write to the Free Software   *
  18      *  Foundation, Inc., 59 Temple Place - Suite 330, Boston,                  *
  19      *  MA  02111-1307, USA.                                                    *
  20      \**************************************************************************/
  21  
  22  var hpane = 0;
  23  var vpane = 0;
  24  var pane = 0.52;
  25  var pane2 = 0.27;
  26  var tree_width = 235;
  27  var tree_min = 180;
  28  var tree_scroll_pos = 0;
  29  var pane_timer = null;
  30  var refresh_timer = null;
  31  var screen_width = return_width();
  32  var smenu = 0;
  33  var menu = 0;
  34  var mbuffer = "";
  35  var smenu_buffer = "";
  36  var mtrigger = null;
  37  var mtimer = null;
  38  var mleft = (typeof(css_conf) != "undefined" && css_conf.direction) ? "right" : "left";
  39  var keys_timer = null;
  40  var keys_hl = null;
  41  var pending_request = 0;
  42  
  43  if (top != window && top.getObj("login_iframe")) {
  44    top.getObj("login_iframe").src = "about:blank";
  45    top.hide("login");
  46    top.setTimeout( function(){
  47      top.show("login_reminder");
  48      top.set_val("password", "");
  49      top.getObj("password").focus();
  50    }, sys.session_time*1000);
  51    if (window.sys.username!=top.sys.username) top.location.href = top.location.href;
  52  } else if (!iframe && sys.session_time && sys.username != "anonymous") {
  53    setTimeout( function() { clearTimeout(refresh_timer); show("login_reminder"); getObj("password").focus(); },sys.session_time*1000);
  54  }
  55  
  56  if (iframe && !popup && window==top.window && document.location.href.indexOf("&iframe=1")!=-1) {
  57    document.location.href = document.location.href.replace("&iframe=1","");
  58  }
  59  
  60  var re = /tree_scroll_pos=(.*?)&tree_width=(.*?)&pane=(.*?)&pane2=(.*?)~/;
  61  if ((m = re.exec(document.cookie))) {
  62    tree_scroll_pos = m[1];
  63    tree_width = m[2];
  64    if (tree_width <= tree_min) tree_width = tree_min + 6;
  65    pane = m[3];
  66    pane2 = m[4];
  67  } else {
  68    if (screen_width>1024) tree_width = 250;
  69  }
  70  window.onbeforeunload = function(){
  71    if (form_changed(getObj("asset_form"))) return "";
  72  };
  73  if (sys.is_mobile) window.onload = start;
  74  else if (document.addEventListener) document.addEventListener( "DOMContentLoaded", start, false );
  75  else {
  76    document.attachEvent("onreadystatechange", function(){
  77      if ( document.readyState != "complete" ) return;
  78      start();
  79    });
  80  }
  81  
  82  function getElementsByClassName(name) {
  83    var a = [];
  84    var elems = document.getElementsByTagName("*");
  85    var pattern = new RegExp("(^|\\s)"+name+"(\\s|$)");
  86    for (var i=0,j=elems.length; i<j; i++) {
  87      if (pattern.test(elems[i].className)) a.push(elems[i]);
  88    }
  89    return a;
  90  }
  91  
  92  function hide_layout() {
  93    if (sys.menu_autohide) {
  94      top_menu(false);
  95      getObj("main").onmouseover = function(event) {
  96        if (is_nested_target(event, this)) return;
  97        top_menu(false);
  98      }
  99      getObj("main").onmouseout = function(event) {
 100        if (!event) event = window.event;
 101        if (is_nested_target(event, this)) return;
 102        if (event.clientY < 10 && event.clientX < 600) top_menu(true);
 103      }
 104    }
 105    if (sys.tree_autohide) {
 106      if (document.location.href.indexOf("&folder=")==-1) tree(false);
 107      getObj("content").onmouseover = function(event) {
 108        if (is_nested_target(event, this)) return;
 109        tree(false);
 110      }
 111      getObj("content").onmouseout = function(event) {
 112        if (!event) event = window.event;
 113        if (is_nested_target(event, this)) return;
 114        if (event.clientX < 10 && event.clientX!=-1) tree(true);
 115  } } }
 116  
 117  function is_nested_target(event, obj) {
 118    if (!event) event = window.event;
 119    var target = event.target || event.srcElement;
 120    if (in_array(target.tagName, ["INPUT", "TEXTAREA", "LABEL", "A", "IMG"])) return true;
 121    if (!event.relatedTarget && event.fromElement) {
 122      event.relatedTarget = (event.type=="mouseover") ? event.fromElement : event.toElement;
 123    }
 124    var parent = event.relatedTarget;
 125    while (parent && parent !== obj) parent = parent.parentNode;
 126    if (parent === obj) return true;
 127    return false;
 128  }
 129  
 130  function tree(show) {
 131    if (!getObj("tree")) return;
 132    if (show) {
 133      tree_width = 235;
 134      show2("tree");
 135    } else {
 136      tree_width = -2;
 137      hide("tree");
 138    }
 139    resizeit();
 140  }
 141  
 142  function top_menu(show) {
 143    if (!getObj("menu")) return;
 144    if (show) {
 145      show2("menu");
 146      show2("sgslogo");
 147    } else {
 148      hide("menu");
 149      hide("sgslogo");
 150    }
 151    resizeit();
 152  }
 153  
 154  function drag_handler(event, params, text_image) {
 155    if (!event) event = window.event;
 156    if (!event.dataTransfer) return;
 157  
 158    var dt = event.dataTransfer;
 159    dt.effectAllowed = "copyMove";
 160    if (event.ctrlKey) dt.effectAllowed = "copy";
 161    dt.setData("Text", JSON.stringify(params));
 162  
 163    if (!dt.setDragImage) return;
 164    var elem = document.createElement("div");
 165    elem.style.fontSize = "40px";
 166    elem.style.backgroundColor = "#FFFFFF";
 167    elem.innerHTML = text_image;
 168    document.body.appendChild(elem);
 169    dt.setDragImage(elem, -10, 0);
 170  }
 171  
 172  function drop_tree(event) {
 173    if (!event) event = window.event;
 174    var mode = "cut";
 175    var dt = event.dataTransfer;
 176    if (dt.dropEffect == "copy" || dt.effectAllowed == "copy") mode = "copy";
 177    
 178    var params = dt.getData("Text");
 179    if (params=="") return;
 180    params = JSON.parse(params);
 181  
 182    var type = params["type"];
 183    if (type=="asset") {
 184      if (!rights.write_folder) mode = "copy";
 185      ajax("asset_ccp",[params["folder"], params["view"], params["items"], attr(this, "rel"), mode], locate_folder);
 186    }
 187    if (type=="folder" && sys_confirm("{t}Really apply the changes ?{/t}")) {
 188      ajax("folder_ccp",[params["items"], attr(this, "rel"), mode], locate_folder);
 189    }
 190  }
 191  
 192  function cancel(e) {
 193    if (e) e.stopPropagation(); else window.event.cancelBubble = true;
 194  }
 195  
 196  function keys(ev) {
 197    if (!ev) ev = window.event;
 198    if (!ev.altKey || ev.shiftKey || ev.ctrlKey) return;
 199    if (ev.keyCode > 47 && ev.keyCode < 58) {
 200      change_tab("tab", attr("accesskey"+(ev.keyCode-48), "rel"));
 201      return;
 202    }
 203    if (keys_timer!=null) clearTimeout(keys_timer);
 204    if (keys_hl!=null) css(keys_hl,"backgroundColor", "");
 205  
 206    if (ev.keyCode=="38" || ev.keyCode=="40" || ev.keyCode=="33" || ev.keyCode=="34") {
 207      var objs = getObjs(".drop_tree");
 208      for (var i=0; i<objs.length; i++) {
 209        var find = keys_hl ? attr(keys_hl, "rel") : tfolder;
 210        if (attr(objs[i], "rel")!=find) continue;
 211        if (ev.keyCode=="38") offset = i-1;
 212          else if (ev.keyCode=="40") offset = i+1;
 213          else if (ev.keyCode=="33") offset = i-10;
 214          else offset = i+10;
 215        if (offset<0) offset=0;
 216        if (offset>=objs.length) offset = objs.length-1;
 217        keys_hl = objs[offset];
 218        if (!keys_hl) return;
 219        css(keys_hl,"backgroundColor", css_conf.bg_red_over);
 220        auto_scroll_tree(keys_hl);
 221        keys_timer = setTimeout(function(){ locate_folder(escape(attr(keys_hl, "rel"))); }, 600);
 222        break;
 223  } } }
 224  
 225  function start() {
 226    if (!sys.browser) return;
 227    if (!popup && !iframe && !preview && tree_visible) drawmenu();
 228    if (debug_js) eval(unescape(document.location.hash.substring(1)));
 229    if (sys.menu_autohide || sys.tree_autohide) hide_layout();
 230    var objs = document.getElementsByTagName("textarea");
 231    for (var i=0; i<objs.length; i++) {
 232      objs[i].onfocus = textarea_autosize;
 233      objs[i].onkeyup = textarea_autosize;
 234      objs[i].onfocus();
 235    }
 236    resizeit();
 237    setTimeout(refreshit, sys.folder_refresh*1000);
 238  
 239    objs = getObjs(".mover");
 240    for (var i=0; i<objs.length; i++) {
 241      if (!attr(objs[i],"rel")) continue;
 242      objs[i].onmouseover = function(event){
 243        cancel(event);
 244        css(".asset_"+attr(this,"rel"),"backgroundColor",css_conf.bg_green);
 245      };
 246      objs[i].onmouseout = function(){
 247        var id = attr(this,"rel");
 248        var obj = getObj("check_"+id);
 249        if (obj && obj.checked) color = css_conf.bg_red; else color = "";
 250        css(".asset_"+id,"backgroundColor",color);
 251      };
 252    }
 253    objs = getObjs(".mdown");
 254    for (var i=0; i<objs.length; i++) {
 255      if (!attr(objs[i],"rel")) continue;
 256      objs[i].onmousedown = function(event){
 257        if (is_nested_target(event, this)) return;
 258        var id = attr(this,"rel");
 259        show2("view_buttons");
 260        var obj = getObj("check_"+id);
 261        if (obj) obj.checked = !obj.checked;
 262        if (obj && obj.checked) color = css_conf.bg_red; else color = "";
 263        css(".asset_"+id,"backgroundColor",color);
 264      };
 265      if (dblclick && !iframe) objs[i].ondblclick = function(){
 266        locate("index.php?folder="+escape(tfolder)+"&view="+dblclick+"&item[]="+attr(this,"rel"));
 267      };
 268    }
 269    if (!preview && !iframe) {
 270      objs = getObjs(".hide_fields");
 271      for (var i=0; i<objs.length; i++) {
 272        objs[i].onmouseover = function(event){
 273          css(this.getElementsByTagName("a"), "visibility", "visible");
 274        };
 275        objs[i].onmouseout = function(event){
 276          css(this.getElementsByTagName("a"), "visibility", "hidden");
 277        };
 278      }
 279    }
 280    objs = getObjs(".drag_asset");
 281    for (var i=0; i<objs.length; i++) {
 282      objs[i].draggable = "true";
 283      objs[i].ondragstart = function(event){
 284        var params = {"folder":tfolder, "view":tview, "type":"asset"};
 285        params["items"] = assets_get_selected(true);
 286        var item = attr(this,"rel");
 287        if (params["items"].join(" ").indexOf(item)==-1) params["items"].push(item);
 288        drag_handler(event, params, params["items"].join(", "));
 289      }
 290      objs[i].onmousedown = cancel;
 291    }
 292    document.onkeydown=keys;
 293    bind_drop_tree();
 294    bind_drop_files();
 295    auto_scroll_tree(tfolder);
 296    var objs = getObjs(".onload");
 297    for (var i=0; i<objs.length; i++) {
 298      objs[i].func = new Function("", attr(objs[i], "onload"));
 299      objs[i].func();
 300    }
 301  }
 302  
 303  function auto_scroll_tree(obj) {
 304    var tree_def = getObj("tree_def");
 305    if (!tree_def) return;
 306  
 307    var pos = findPosY(obj) - findPosY(tree_def) - 20;
 308    if (pos < tree_def.scrollTop) tree_def.scrollTop = pos;
 309  
 310    var pos = findPosY(obj) - return_height() + 40;
 311    if (pos > tree_def.scrollTop) tree_def.scrollTop = pos;
 312    save_cookie();  
 313  }
 314  
 315  function bind_drop_files() {
 316    // HTML5 drag and drop file upload
 317    if (!/Firefox|Chrome|Safari/.test(navigator.userAgent)) return;
 318    document.ondragover = document.ondrop = function(event){ event.preventDefault(); };
 319    show(".file_upload_text");
 320    var objs = getObjs(".file_upload");
 321    for (var i=0; i<objs.length; i++) {
 322      objs[i].ondragenter = function(){ css(this,"backgroundColor",css_conf.bg_red_over); };
 323      objs[i].ondragleave = function(event){
 324        if (is_nested_target(event, this)) return;
 325        css(this,"backgroundColor","");
 326      };
 327    }
 328  }
 329  
 330  function bind_drop_tree() {
 331    var objs = getObjs(".drop_tree");
 332    for (var i=0; i<objs.length; i++) {
 333      objs[i].draggable = "true";
 334      objs[i].ondragenter = function(){ auto_scroll_tree(this); css(this,"backgroundColor", css_conf.bg_red_over); return false; };
 335      objs[i].ondragleave = function(event){
 336        if (is_nested_target(event, this)) return;
 337        css(this,"backgroundColor", "");
 338      };
 339      objs[i].ondragover = function(){ return false; };
 340      objs[i].ondrop = drop_tree;
 341      objs[i].ondragstart = function(event){
 342        drag_handler(event, {"type":"folder", "items":attr(this,"rel")}, this.innerHTML.replace(/<img.*?>/g,""));
 343      };
 344    }
 345  }
 346  
 347  function ______G_E_N_E_R_A_L______() {}
 348  
 349  function print_r(value) {
 350    alert(JSON.stringify(value));
 351  }
 352  
 353  function getObj(id) {
 354    return document.getElementById(id);
 355  }
 356  
 357  function getObjs(val) {
 358    if (!val) return [];
 359    if (typeof(val)=="string") {
 360      if (val.charAt(0)==".") {
 361        // IE
 362        if (!document.getElementsByClassName) document.getElementsByClassName = getElementsByClassName;
 363        objs = document.getElementsByClassName(val.substring(1));
 364      } else {
 365        objs = [getObj(val)];
 366      }
 367    } else if (val.length) {
 368      objs = val;
 369    } else {
 370      objs = [val];
 371    }
 372    return objs;
 373  }
 374  
 375  function form_values(class_name) {
 376    var params = {};
 377    var objs = getObjs(class_name);
 378    if (objs.length==0 || !objs[0]) return params;
 379    for (var i=0; i<objs.length; i++) {
 380      if (!objs[i].id) continue;
 381      var id = objs[i].id;
 382      if (!params[id]) params[id] = [];
 383      params[id].push(val(objs[i]));
 384    }
 385    return params;
 386  }
 387  
 388  function form_changed(form) {
 389    if (!form) return false;
 390    for (var i=0; i < form.elements.length; i++) {
 391      var elem = form.elements[i];
 392      var type = elem.type;
 393      if (!elem.name) continue;
 394      if (type=="checkbox" || type=="radio") {
 395        if (elem.checked != elem.defaultChecked) return true;
 396      } else if (type=="hidden" || type=="password" || type=="text" || type=="textarea") {
 397        if (elem.value != elem.defaultValue) return true;
 398      } else if (type=="select-one") {
 399        if (!elem.options[elem.selectedIndex].defaultSelected) return true;
 400      } else if (type=="select-multiple") {
 401        for (var j=0; j < elem.options.length; j++) {
 402          if (elem.options[j].selected != elem.options[j].defaultSelected) return true;
 403    } } }
 404    return false;
 405  }
 406  
 407  function val(obj) {
 408    if (typeof(obj)=="string") obj = getObj(obj);
 409    if (!obj) return "";
 410    if (obj.type=="checkbox" || obj.type=="radio") {
 411      if (obj.checked) return obj.value; return "";
 412    }
 413    if (obj.options) {
 414      if (!obj.multiple) {
 415        if (obj.selectedIndex == -1) return "";
 416        return obj.options[obj.selectedIndex].value;
 417      } else {
 418        var arr = [];
 419        for (var i=0; i<obj.options.length; i++) {
 420          arr.push(obj.options[i].value);
 421        }
 422        return arr.join("|");
 423      }
 424    }
 425    return obj.value;
 426  }
 427  
 428  function _selectbox_find(obj, key) {
 429    if (!obj.options || obj.options.length==0) return -1;
 430    for (var i=0; i<obj.options.length; i++) {
 431      if (obj.options[i].value == key) return i;
 432    }
 433    return -1;
 434  }
 435    
 436  function set_val(obj, val) {
 437    if (typeof(obj)=="string") obj = getObj(obj);
 438    if (!obj) return;
 439    if (obj.type=="checkbox" || obj.type=="radio") {
 440      obj.checked = val ? true : false;
 441    } else if (obj.options) {
 442      if (val=="") {
 443        if (obj.multiple) obj.options.length = 0; else obj.selectedIndex = -1;
 444        return;
 445      }
 446      if (obj.multiple && val.indexOf("|")!=-1) {
 447        val = val.split("|");
 448        for (var i=0; i<val.length; i++) set_val(obj, val[i]);
 449      } else {
 450        var index = _selectbox_find(obj, val);
 451        if (index == -1) {
 452          index = obj.options.length;
 453          obj.options[index] = new Option(val,val);
 454        }
 455        if (!obj.multiple) obj.options[index].selected = true;
 456      }
 457    } else obj.value = val;
 458  }
 459  
 460  function attr(obj,name) {
 461    if (typeof(obj)=="string") obj = getObj(obj);
 462    if (!obj) return "";
 463    return obj.getAttribute(name);
 464  }
 465  function css(obj, name, value, delay) {
 466    var objs = getObjs(obj);
 467    if (objs.length==0 || !objs[0]) return;
 468    for (var i=0; i<objs.length; i++) objs[i].style[name]=value;
 469    if (typeof(delay)!="undefined") setTimeout(function(){ css(obj, name, ''); },delay);
 470  }
 471  function set_attr(obj, name, value) {
 472    var objs = getObjs(obj);
 473    if (objs.length==0 || !objs[0]) return;
 474    for (var i=0; i<objs.length; i++) {
 475      if (name.indexOf("on")==0 || name=="value") {
 476        objs[i][name] = value;
 477      } else {
 478        objs[i].setAttribute(name, value);
 479  } } }
 480  
 481  function add_style(selector, style) {
 482    var objs = getObj("content").getElementsByTagName("iframe");
 483    if (objs.length > 0) {
 484      for (var i=0; i<objs.length; i++) {
 485        if (!objs[i].contentWindow) continue;
 486        var css = objs[i].contentWindow.document.styleSheets[0];
 487        if (!css) continue;
 488        css_conf.insertRule(selector + "{"+style+"}", 0);
 489        objs[i].contentWindow.resizeit();
 490    } }
 491    document.styleSheets[0].insertRule(selector + "{"+style+"}", 0);
 492  }
 493  
 494  function _getSize(width) {
 495    var myWidth = 0, myHeight = 0;
 496    if (typeof(window.innerWidth) == "number") {
 497      myWidth = window.innerWidth;
 498      myHeight = window.innerHeight;
 499    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
 500      myWidth = document.body.clientWidth;
 501      myHeight = document.body.clientHeight;
 502    } else if (self.screen.height && self.screen.width) {
 503      myWidth = self.screen.width;
 504      myHeight = self.screen.height;
 505    }
 506    if (width) return myWidth; else return myHeight;
 507  }
 508  
 509  function return_height() {
 510    return _getSize(0);
 511  }
 512  
 513  function return_width() {
 514    return _getSize(1);
 515  }
 516  
 517  function getFirstParentByName(node,tag) {
 518    while (node.tagName && node.tagName.toLowerCase()!=tag) node = node.parentNode;
 519    return node;
 520  }
 521  
 522  function getmykey(ev) {
 523    if (!ev) return null;
 524    if (typeof(ev.which)=="undefined") return window.event.keyCode;
 525    return ev.which;
 526  }
 527  
 528  function findPosY(obj) {
 529    if (typeof(obj)=="string") obj = getObj(obj);
 530    var curtop = 0;
 531    if (obj.offsetParent) {
 532      while (obj.offsetParent) {
 533        curtop += obj.offsetTop;
 534        obj = obj.offsetParent;
 535      }
 536    } else if (obj.y) curtop += obj.y;
 537    return curtop;
 538  }
 539  
 540  function findPosX(obj) {
 541    if (typeof(obj)=="string") obj = getObj(obj);
 542    var curtop = 0;
 543    if (obj.offsetParent) {
 544      while (obj.offsetParent) {
 545        curtop += obj.offsetLeft;
 546        obj = obj.offsetParent;
 547      }
 548    } else if (obj.x) curtop += obj.x;
 549    return curtop;
 550  }
 551  
 552  function getRequestObject() {
 553    return (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest());
 554  }
 555  
 556  function show(obj) {
 557    css(obj,"display","inline");
 558  }
 559  function show2(obj) {
 560    css(obj,"display","");
 561  }
 562  function hide(obj) {
 563    css(obj,"display","none");
 564  }
 565  function showhide(obj) {
 566    if (typeof(obj)=="string") obj = getObj(obj);
 567    if (!obj) return false;
 568    if (obj.style.display=="none") {
 569      show2(obj);
 570      return true;
 571    } else hide(obj);
 572    return false;
 573  }
 574  function showhide_inline(obj) {
 575    if (typeof(obj)=="string") obj = getObj(obj);
 576    if (!obj) return false;
 577    if (obj.style.display=="none") {
 578      show(obj);
 579      return true;
 580    } else hide(obj);
 581    return false;
 582  }
 583  function check_bold(obj) {
 584    setTimeout(function(){ getFirstParentByName(obj,"tr").style.fontWeight="normal";},1000);
 585  }
 586  
 587  function doclick(field) {
 588    field = getObj(field);
 589    if (field.dispatchEvent) {
 590      var e = document.createEvent("MouseEvents");
 591      e.initEvent("click", true, true);
 592      field.dispatchEvent(e);
 593    } else field.click();
 594  }
 595  
 596  function showhide_tree(obj) {
 597    if (showhide(obj)) tree_scroll(-1); else tree_scroll(0);
 598    focus_form(obj);
 599  }
 600  
 601  function focus_form(obj) {
 602    if (typeof(obj)=="string") obj = getObj(obj);
 603    if (!obj) return;
 604    var objs = obj.getElementsByTagName("form");
 605    if (objs.length > 0) {
 606      var elems = objs[0].elements;
 607      for (var i=0; i<elems.length; i++) {
 608        if (elems[i].type != "hidden" && elems[i].type != "checkbox" && elems[i].name != "") {
 609          elems[i].focus();
 610          break;
 611  } } } }
 612  
 613  function set_html(obj,txt) {
 614    if (!obj) return;
 615    if (typeof(obj)=="string") obj = getObj(obj);
 616    obj.innerHTML = txt;
 617  }
 618  function append_html(obj,txt) {
 619    if (typeof(obj)=="string") obj = getObj(obj);
 620    obj.innerHTML += txt;
 621  }
 622  
 623  function remove_trans(str) {
 624    return str.replace(new RegExp("{t"+"}|{/t"+"}","g"), "");
 625  }
 626  
 627  function sys_alert(str) {
 628    str = remove_trans(str);
 629    var result = "";
 630    while (str.length > 0) {
 631      var pos = str.indexOf("\n");
 632      if (pos == -1 || pos > 120) pos = 120;
 633      result += str.substring(0, pos+1)+"\n";
 634      str = str.substring(pos+1);
 635    }
 636    alert(result);
 637  }
 638  
 639  function sys_confirm(str) {
 640    return confirm(remove_trans(str));
 641  }
 642  
 643  function html_escape(str) {
 644    return str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
 645  }
 646  
 647  function open_window(address,name,width,height) {
 648    var _top = Math.floor((screen.height - height) / 2);
 649    var _left = Math.floor((screen.width - width) / 2);
 650    var loc = "no";
 651    var menu = "no";
 652    var scrollbars = "no";
 653    if (width>640) {
 654      loc = "yes";
 655      scrollbars = "yes";
 656    }
 657    var wname = name;
 658    if (window.name == wname) wname += Math.random();
 659    var my_win = window.open(address,wname.replace(".",""),"location="+loc+",scrollbars="+scrollbars+",resizable=yes,width="+width+",height="+height);
 660    try {
 661      my_win.moveTo(_left,_top);
 662      my_win.resizeTo(width,height);
 663    } catch (e) {} // ie7
 664    my_win.name = name;
 665    return my_win;
 666  }
 667  
 668  function locate(str) {
 669    if (str.indexOf("norefer.php")==-1 && iframe) str += "&iframe=1";
 670    if (popup) str += "&popup=1";
 671    document.location = str;
 672  }
 673  function locate_folder(folder) {
 674    if (pending_request>0) return;
 675    locate("index.php?folder="+folder); // unicode: no escape
 676  }
 677  function alert_ok(data) {
 678    sys_alert("{t}Item successfully created.{/t}");
 679  }
 680  function search() {
 681    var url = "index.php?folder="+escape(tfolder)+"&view=search&module="+val("search_module")+"&search="+val("search_query");
 682    var filters = [];
 683    var user = val("search_user");
 684    if (user) filters.push("lastmodifiedby|eq|"+user);
 685    var modified = val("search_modified_value");
 686    if (modified) filters.push("lastmodified|"+val("search_modified")+"|"+modified);
 687    if (filters.length>0) url += "&filters="+filters.join("||");
 688    var similar = getObj("search_similar");
 689    if (similar && similar.checked) url += "&similar=1";
 690    var subfolders = getObj("search_subfolders");
 691    if (subfolders && !subfolders.checked) url += "&subfolders=0";
 692    locate(url);
 693  }
 694  
 695  function nWin(address) {
 696    open_window(address,"custom_"+Math.random(),920,600);
 697  }
 698  
 699  function neWin(address) {
 700    open_window(address+"&folder2="+escape(tfolder)+"&view2="+tview,"custom_"+Math.random(),840,600);
 701  }
 702  
 703  function sWin(address) {
 704    locate(address+"&folder2="+escape(tfolder)+"&view2="+tview);
 705  }
 706  
 707  function log(val) {
 708    var obj = top.window.getObj("tconsole");
 709    if (!obj) return;
 710    obj.value = (obj.value.split("\n").length)+": "+(window.name)+": "+val+"\n"+obj.value;
 711    top.window.getObj("console").style.display = "inline";
 712  }
 713  
 714  function in_array(val,arr) {
 715    for (var i=0; i<arr.length; i++) if (arr[i]==val) return true;
 716    return false;
 717  }
 718  
 719  function has_flash() {
 720    if (navigator.plugins["Shockwave Flash"]) return;
 721    try {
 722      if (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) return;
 723    } catch (e) {}
 724    document.write(remove_trans("{t}Flash plugin not installed.{/t}"));
 725  }
 726  
 727  function ______I_N_I_T______() {}
 728  
 729  function display_images() {
 730    var objs = getObj("content").getElementsByTagName("img");
 731    if (objs.length==0) return;
 732    for (var i=0; i<objs.length; i++) {
 733      if (objs[i].src=="" && objs[i].title!="" && objs[i].title.indexOf("ext/norefer.php?")==0) objs[i].src = objs[i].title;
 734    }
 735  }
 736  
 737  function save_cookie() {
 738    tree_scroll_pos = getObj("tree_def").scrollTop;
 739    document.cookie = "tree_scroll_pos="+tree_scroll_pos+"&tree_width="+tree_width+"&pane="+pane+"&pane2="+pane2+"~";
 740  }
 741  
 742  function notify(str, warn) {
 743    if (str=="") return;
 744    if (sys.menu_autohide) {
 745      set_attr("notification2", "class", "tabstyle"+(warn?" red":""));
 746      set_html("notification2", remove_trans("{t}Notification{/t}: "+str));
 747    } else {
 748      set_attr("notification", "class", "menu_notification"+(warn?" red":""));
 749      set_html("notification", remove_trans("{t}Notification{/t}: "+str));
 750    }
 751  }
 752  
 753  function refreshit() {
 754    if (iframe || popup || schema_mode) return;
 755    ajax("folder_has_changed", [tfolder, sys_time], function(result) {
 756      if (result) {
 757        notify('{t}Folder has changed.{/t} <a href="index.php?folder='+escape(tfolder)+'&view='+tview+'">({t}Refresh{/t})</a>');
 758        document.title = remove_trans("({t}Changed{/t}) ") + document.title;
 759      } else {
 760        refresh_timer = setTimeout(refreshit, sys.folder_refresh*1000);
 761      }
 762    });
 763  }
 764  
 765  function resizeit() {
 766    var height = return_height();
 767    var width = return_width();
 768  
 769    if (sys.is_mobile) css(".vertical","display",width<=320 ? "none" : "inline");
 770  
 771    if ((iframe || preview) && typeof(parent.window)!="unknown" && window.name!="pane" && window.name!="pane2") {
 772      var obj = parent.window.getObj(window.name);
 773      if (obj != null) {
 774        var height_main = getObj("main").clientHeight;
 775        var obj_iframe = obj;
 776        if (obj_iframe.tagName.toLowerCase()!="iframe") obj_iframe = obj.getElementsByTagName("iframe")[0];
 777        if (height_main > 10) {
 778          obj_iframe.style.height = height_main+"px";
 779          return;
 780    } } }
 781    if (iframe && (window.name=="pane" || window.name=="pane2")) {
 782      show2("pane_close");
 783      hide("tab_spacer");
 784    }
 785    if (sys.browser.no_scrollbar) return;
 786    
 787    var content_def = getObj("content_def");
 788    var tree_frame = getObj("tree_frame");
 789    
 790    if (tree_frame) {
 791      var height_obj = findPosY(tree_frame);
 792      var tree_def = getObj("tree_def");
 793      tree_frame.style.height = (height-height_obj-1)+"px";
 794      tree_def.style.height = (height-height_obj-1)+"px";
 795  
 796      var pane_width = 0;
 797      if (vpane > 1) {
 798        pane_width = Math.floor(width*pane2);
 799        getObj("pane2").style.width = (pane_width-4)+"px";
 800      }
 801      content_def.style.width = (width-tree_width-pane_width-4)+"px";
 802      if (getObj("tree").style.display!="none") tree_def.style.width = tree_width+"px";
 803      if (vpane > 1 && hpane > 1) getObj("pane").style.width = content_def.style.width;
 804    }
 805  
 806    var fixed_footer = getObj("fixed_footer");
 807    if (content_def) {
 808      var height_obj = findPosY(content_def);
 809      var content_def_table = getObj("content_def_table");
 810      var height2 = height;
 811      if (fixed_footer) height2 -= fixed_footer.offsetHeight;
 812      if (hpane > 1) height2 = Math.floor(height*pane);
 813      if (!sys.is_mobile) content_def.style.height = (height2-height_obj-1)+"px";
 814      content_def_table.style.height = (height2-height_obj-1)+"px";
 815    }
 816    
 817    var height2 = fixed_footer ? fixed_footer.offsetHeight+1 : 0;
 818    if (hpane > 1) {
 819      var obj_pane = getObj("pane");
 820       obj_pane.style.height = (height-findPosY(obj_pane)-height2)+"px";
 821    }
 822    if (vpane > 1) {
 823      var obj_pane = getObj("pane2");
 824      obj_pane.style.height = (height-findPosY(obj_pane)-height2)+"px";
 825    }
 826    if (tree_frame) {
 827      tree_scroll(tree_scroll_pos);
 828    }
 829  }
 830  
 831  function ______O_T_H_E_R_S______() {}
 832  
 833  function switch_wrap(field_w, event) {
 834    if (is_nested_target(event, this)) return;
 835    var field = field_w.getElementsByTagName("div");
 836    if (field.length==0) return;
 837    field = field[0];
 838    if (field.style.overflow=="hidden") {
 839      field.style.overflow="visible";
 840      var len = field.innerHTML.replace(/<img.*?>/g,"  ").replace(/&.*?;/g," ").replace(/<script>.*?<\/script>|<.*?>/g,"").length;
 841      if (field.parentNode.offsetWidth < (len*7)) field.parentNode.style.width=(len*7)+"px";
 842    }
 843  }
 844  
 845  function change_tab(classname,id) {
 846    set_attr("."+classname,"class",classname+" tabstyle");
 847    set_attr(classname+id,"class",classname+" tabstyle2");
 848    css("."+classname+"2","display","none");
 849    css("."+classname+"2"+id,"display","");
 850    css(getObjs("."+classname+"2"),"marginBottom",id?"0px":"2px");
 851    
 852    if (/MSIE/.test(navigator.userAgent)) {
 853      set_attr("."+classname,"className",classname+" tabstyle");
 854      set_attr(classname+id,"className",classname+" tabstyle2");
 855    }
 856    if (iframe) resizeit();
 857  }
 858  
 859  function portal_change(id,size) {
 860    var obj = getFirstParentByName(getObj(id),"tr");
 861    var objs = obj.getElementsByTagName("iframe");
 862    if (objs.length==0) return;
 863    for (var i=0; i<objs.length; i++) {
 864        if (objs[i].offsetHeight+size > 0) objs[i].style.height = (objs[i].offsetHeight+size)+"px";
 865      if (!objs[i].contentWindow) continue;
 866      try {
 867        if (size<0) {
 868          objs[i].contentWindow.hide(".tfields");
 869        } else {
 870          objs[i].contentWindow.show2(".tfields");
 871        }
 872      } catch (e) {}
 873    }
 874  }
 875  
 876  function portal_refresh(id,time,init) {
 877    var obj = getObj(id);
 878    if (obj && obj.src!="about:blank" && time!=0) {
 879      if (!init && (sys.username=="anonymous" || getObj("login_reminder").style.display!="inline")) {
 880        obj.src = obj.src;
 881      }
 882      if (time < 10) time = 10;
 883      setTimeout(function(){ portal_refresh(id,time,0); },time*1000);
 884    }
 885  }
 886  
 887  function file_preview_change(id,size) {
 888    var obj = getObj(id);
 889    if (obj.offsetHeight+size > 0) obj.style.height = (obj.offsetHeight+size)+"px";
 890  }
 891  
 892  function file_func(operation, id, field, subitem) {
 893    ajax(operation, [tfolder, id, field, subitem], locate_folder);
 894  }
 895  
 896  function searchbox(obj) {
 897    if (obj.value==remove_trans("{t}Search{/t}")) obj.value = "";
 898    if (obj.value==remove_trans("{t}Other{/t}")) obj.value = "";
 899  }
 900  
 901  function searchbox2(obj) {
 902    if (obj.value=="") obj.value = remove_trans("{t}Search{/t}");
 903  }
 904  
 905  function ______G_U_I__G_R_I_D______() {}
 906  
 907  function asset_filter_submit() {
 908    var result = "";
 909    var fields = getObjs(".filter_field");
 910    var values = getObjs(".filter_value");
 911    var types = getObjs(".filter_type");
 912    for (var i=0; i<values.length; i++) {
 913      if (values[i].value=="") values[i].value = " ";
 914      result += "||"+fields[i].value+"|"+types[i].value+"|"+values[i].value;
 915    }
 916    locate("index.php?folder="+escape(tfolder)+"&view="+tview+"&filters="+result.substring(2));
 917  }
 918  
 919  function assets_get_selected(array) {
 920    var items=[];
 921    var objs = getObjs(".asset_check");
 922    for (var i=0; i<objs.length; i++) {
 923      var id = objs[i].value;
 924      if (getObj("check_"+id).checked) items.push(id);
 925    }
 926    if (array) return items;
 927    var result = "";
 928    for (var i=0; i<items.length; i++) result += "&item[]="+escape(items[i]);
 929    return result;
 930  }
 931  
 932  function asset_form_submit(action) {
 933    locate(action + assets_get_selected(false));
 934  }
 935  
 936  function asset_form_link(action) {
 937    return action + assets_get_selected(false);
 938  }
 939  
 940  function asset_action(mode, timeout) {
 941    if (mode=="cut" || mode=="copy") {
 942      func = "asset_cutcopy";
 943      callback = function() { mselectall(true); };
 944    } else if (mode=="paste") {
 945      func = "asset_paste";
 946      callback = locate_folder;
 947    } else {
 948      func = "asset_delete";
 949      callback = locate_folder;
 950    }
 951    ajax(func, [tfolder, tview, assets_get_selected(true), mode], callback, timeout);
 952  }
 953  
 954  function asset_form_selected() {
 955    if (assets_get_selected(false)=="") {
 956      sys_alert("{t}No dataset selected.{/t}");
 957      return false;
 958    }
 959    return true;
 960  }
 961  
 962  function mselectall(checked) {
 963    var objs = getObjs(".asset_check");
 964    for (var i=0; i<objs.length; i++) {
 965      var id = objs[i].value;
 966      getObj("check_"+id).checked = !checked;
 967      if (getObj("check_"+id).checked) color = css_conf.bg_red; else color = "";
 968      css(".asset_"+id,"backgroundColor",color);
 969    }
 970  }
 971  
 972  function mselectallkey() {
 973    var obj = getObj("itemall");
 974    mselectall(obj.checked);
 975    obj.checked = !obj.checked;
 976  }
 977  
 978  function customize_field() {
 979    var params={};
 980    params["module"] = ftype;
 981    params["field"] = val("cust_field");
 982  
 983    var action = val("cust_field_action");
 984    if (action=="hidden") params["hidden"] = 1;
 985    else if (action=="hiddenin") params["hiddenin"] = tview;
 986    else if (action=="notinall") params["notinall"] = 1;
 987    else if (action=="rename") params["displayname"] = val("cust_field_name");
 988    else {
 989        params["displayname"] = val("cust_field_name");
 990        params["fbefore"] = params["field"];
 991        params["field"] = val("cust_field_name").replace(/[^a-z0-9_]/ig, "");
 992        params["simple_type"] = action;
 993    }
 994    if (getObj("cust_field_folder").checked) params["ffolder"] = tfolder;
 995  
 996    if (params["field"]=="" || action=="") return;
 997    if (action=="rename" && params["displayname"]=="") return;
 998  
 999    ajax("sgsml_customizer::ajax_get_field", [params["module"], params["field"]], function(data) {
1000      if (data.length==0) data = {};
1001      for (var key in params) data[key] = params[key];
1002      ajax("asset_insert", ["~sys_custom_fields", "new", data], ajax_locate_folder);
1003    });
1004  }
1005  
1006  function ______G_U_I__T_R_E_E______() {}
1007  
1008  function tree_drag_resize(event) {
1009    if (getObj("tree").style.display=="none") return;
1010    cancel(event);
1011    if (!event) event = window.event;
1012    var screen_width = return_width();
1013    tree_width = event.clientX+6;
1014    if (css_conf.direction) tree_width = screen_width-tree_width+12;
1015    if (tree_width > screen_width*0.5) tree_width = screen_width*0.5;
1016    save_cookie();
1017    if (tree_width < tree_min) tree_showhide(); else resizeit();
1018  }
1019  
1020  function tree_selectall(checked) {
1021    var objs = getObj("tcategories").getElementsByTagName("input");
1022    if (objs.length>0) {
1023      for (var i1=0; i1<objs.length; i1++) {
1024        if (typeof(objs[i1].checked) != "undefined") objs[i1].checked = checked;
1025  } } }
1026  
1027  function tree_refresh(id) {
1028    var obj = getObj(id);
1029    obj.style.display = "none";
1030    obj.innerHTML = "";
1031    ajax("tree_close", [id], function(data) { tree_open(id); });
1032  }
1033  
1034  function tree_open(id) {
1035    var obj = getObj(id);
1036    var obj2 = getObj(id+"_img");
1037    if (obj.innerHTML.length > 0) {
1038      obj2.src = "ext/icons/plus.gif";
1039      obj.style.display = "none";
1040      obj.innerHTML = "";
1041      ajax("tree_close", [id], null);
1042    } else {
1043      ajax("tree_open", [id], function(data) {
1044        var out = "";
1045        for (i in data.children) {
1046          var img = "plus";
1047          var item = data.children[i];
1048          if (!item.id) continue;
1049          item.id = html_escape(item.id);
1050          item.fdescription = item.id.replace(/^.+:\d+\//, "") + " " + item.fdescription;
1051          out += "<div class='drop_tree' rel='"+html_escape(item.id)+"' title='"+html_escape(item.fdescription)+"' style='white-space:nowrap;'>";
1052          for (j=0; j <= data.level; j++) out += "<img src='ext/icons/line.gif'>";
1053          if (item.ffcount + item.mp == 0) img = "line";
1054          out += "<a onclick='tree_open(\""+item.id+"\");'><img id='"+item.id+"_img' src='ext/icons/"+img+".gif'></a>&nbsp;";
1055          out += "<a href='index.php?folder="+item.id+"' "+(item.id==tfolder?"style='font-weight:bold;'":"")+">";
1056  
1057          if (item.icon) {
1058            out += "<a href='index.php?folder="+item.id+"' "+(item.id==tfolder?"style='font-weight:bold;'":"")+"><img src='ext/modules/"+item.icon+"'> ";
1059          } else if (css_conf.tree_icons) {
1060            if (item.anchor && item.anchor.indexOf("_")==-1) icon = "anchor_"+item.anchor; else icon = item.ftype;
1061            out += "<a href='index.php?folder="+item.id+"' "+(item.id==tfolder?"style='font-weight:bold;'":"")+"><img src='ext/modules/"+icon+".png'> ";
1062          } else {
1063            if (css_conf.bg_light_blue=="#B6BDD2")
1064              out += "<img src='ext/icons/folder1.gif'> ";
1065            else
1066              out += "<img src='images.php?image=folder1&color="+css_conf.bg_light_blue.replace("#","")+"'> ";
1067          }
1068          out += html_escape(item.ftitle)+"&nbsp;";
1069          if (item.fcount > 0) out += "("+item.fcount+")";
1070          out += "</a></div><div id='"+item.id+"' style='display:none;'></div>";
1071        }
1072        if (out!="") obj2.src = "ext/icons/minus.gif"; else obj2.src = "ext/icons/line.gif";
1073        show(obj);
1074        obj.innerHTML = out;
1075        bind_drop_tree();
1076      });
1077    }
1078  }
1079  
1080  function tree_showhide() {
1081    showhide("tree");
1082    showhide("tree_button");
1083    if (getObj("tree").style.display!="none") {
1084      tree_width = 235;
1085      save_cookie();
1086    } else tree_width = -2;
1087    resizeit();
1088  }
1089  
1090  function tree_folder_info() {
1091    tree_scroll(0);
1092    var obj = getObj("tree_info");
1093    ajax("folder_info", [tfolder], function(data) {
1094      obj.innerHTML = remove_trans(data);
1095      show2("tree_info");
1096    });
1097  }
1098  
1099  function tree_folder_mountpoint() {
1100    tree_scroll(0);
1101    var obj = getObj("tree_info");
1102    ajax("folder_mountpoint", [tfolder], function(data) {
1103      obj.innerHTML = remove_trans(data);
1104      show2("tree_info");
1105      mountpoint_parse(attr("tree_mountpoint_form","rel"));
1106    });
1107  }
1108  
1109  function tree_folder_options() {
1110    tree_scroll(0);
1111    var obj = getObj("tree_info");
1112    ajax("folder_options", [tfolder], function(data) {
1113      obj.innerHTML = remove_trans(data);
1114      show2("tree_info");
1115      getObj("frenametitle").focus();
1116    });
1117  }
1118  
1119  function tree_scroll(pos) {
1120    if (pos==-1) getObj("tree_def").scrollTop = getObj("tree_def").scrollHeight;
1121      else getObj("tree_def").scrollTop = pos;
1122  }
1123  
1124  function tree_categories_save() {
1125    var folders = [];
1126    var objs = getObj("tcategories").getElementsByTagName("input");
1127    for (var i=0; i<objs.length; i++) {
1128      if (objs[i].name=="folders[]" && objs[i].checked) folders.push(objs[i].value);
1129    }
1130    ajax("tree_set_folders", [tfolder,folders],locate_folder);
1131    return false;
1132  }
1133  
1134  function tree_categories() {
1135    tree_scroll(0);
1136    var obj = getObj("tree_info");
1137    ajax("tree_get_category", [ftype,tfolder,tfolders], function(data) {
1138      obj.innerHTML = remove_trans(data);
1139      show2("tree_info");
1140    });
1141  }
1142  
1143  function ______G_U_I__C_A_L_E_N_D_A_R______() {}
1144  
1145  var calendars = [];
1146  function calendar(obj_target,time,callback) {
1147    obj_target = getObj(obj_target);
1148    this.popup_open = calendar_popup;
1149    if (!obj_target || !obj_target.id) {
1150      alert("Error calling the calendar: no target control specified");
1151      return;
1152    }
1153    this.target = obj_target;
1154    this.time_comp = time;
1155    this.year_scroll = true;
1156    this.id = calendars.length;
1157    this.NUM_WEEKSTART = cal_firstday;
1158    calendars[this.id] = this;
1159    this.popup_open();
1160    if (callback) this.callback=true; else this.callback=false;
1161  }
1162  
1163  function calendar_popup(str_datetime) {
1164    if (!str_datetime) str_datetime = this.target.value; else this.dt_selected = this.dt_current;
1165    getObj("calendar").style.left = ((return_width()-200)/2)+"px";
1166    getObj("calendar").style.display = "inline";
1167    getObj("calendar_iframe").src="ext/lib/calendar/calendar.php?datetime="+str_datetime+"&id="+this.id;
1168  }
1169  
1170  function calendar_changed() {
1171    var url = "../../../index.php?today="+val("datebox");
1172    locate(url);
1173  }
1174  
1175  function ______G_U_I__M_O_U_N_T_P_O_I_N_T______() {}
1176  
1177  function mountpoint_build() {
1178    var proto = getObj("mount_proto").value+":";
1179    var user = _mountpoint_escape(getObj("mount_user").value);
1180    var pass = _mountpoint_escape(getObj("mount_pass").value);
1181    var port = getObj("mount_port").value;
1182    var enc = getObj("mount_enc").value;
1183    var host = getObj("mount_host").value;
1184    var path = getObj("mount_path").value;
1185  
1186    var re = /^(imap|fs|pmwiki|ldap|cifs|gdocs)/;
1187    if (m = re.exec(proto) && path!="" && path.charAt(path.length-1)!="/") path += "/";
1188    var options = _mountpoint_escape(getObj("mount_options").value);
1189    var vals = user+(pass?":"+pass:":")+(port?":"+port:":")+(enc?":"+enc:":")+(options?":"+options:":")+"@";
1190    if (proto.length<2 || (!host && !path)) {
1191      return "";
1192    } else {
1193      if (host.length==0) vals = "";
1194      if (host.length>0 && (path.length==0 || path.charAt(0)!="/")) path = "/"+path;
1195      return proto+vals+host+path;
1196    }
1197  }
1198  
1199  function _mountpoint_escape(str) {
1200    return str.replace(/:/g,"==").replace(/@/g,"%%");
1201  }
1202  
1203  function _mountpoint_unescape(str) {
1204    return str.replace(/%%/g,"@").replace(/==/g,":");
1205  }
1206  
1207  function mountpoint_parse(mountpoint) {
1208    var re = /^(imap|smtp|pop3|ldap|cifs|gdocs):([^:@]*):?([^:@]*):?([^:@]*):?([^:@]*):?([^:@]*)(@[^\/]*)?\/(.*?)$/;
1209    if ((m = re.exec(mountpoint))) {
1210      getObj("mount_proto").value = m[1];
1211      var user = "";
1212      var pass = "";
1213      var options = "";
1214      if (m[2] && m[3]) {
1215        user = _mountpoint_unescape(m[2]);
1216        pass = _mountpoint_unescape(m[3]);
1217      }
1218      if (m[6]) options = _mountpoint_unescape(m[6]);
1219      getObj("mount_user").value = user;
1220      getObj("mount_pass").value = pass;
1221      getObj("mount_port").value = m[4];
1222      getObj("mount_enc").value = m[5];
1223      getObj("mount_options").value = options;
1224      var host = m[2];
1225      if (m[7]) host = m[7].substr(1);
1226      getObj("mount_host").value = host;
1227      getObj("mount_path").value = m[8];
1228      mountpoint_show(m[1]);
1229    } else {
1230      re = /([^:]*):(.*)/;
1231      if ((m = re.exec(mountpoint))) {
1232        getObj("mount_proto").value = m[1];
1233        getObj("mount_path").value = m[2];
1234          mountpoint_show(m[1]);
1235  } } }
1236  
1237  function mountpoint_show(proto) {
1238    var re = /^(imap|smtp|pop3|ldap|cifs|gdocs)$/;
1239    if (re.exec(proto)) {
1240      show2("mount_auth");
1241      show2("mount_details");
1242      if (proto=="gdocs") {
1243        set_val("mount_host", "docs.google.com");
1244        set_attr(".mp2", "value", "");  
1245        hide("mount_details");
1246      }
1247    } else {
1248      hide("mount_auth");
1249      hide("mount_details");
1250      set_attr(".mp", "value", "");  
1251    }
1252  }
1253  
1254  function ______G_U_I__P_R_E_V_I_E_W__P_A_N_E______() {}
1255  
1256  function show_pane() {
1257    hpane++;
1258    if (hpane>1) {
1259     show2("content_pane");
1260     resizeit();
1261    }
1262  }
1263  
1264  function hidepane(name) {
1265    if (name=="pane") {
1266      hpane=1;
1267      hide("content_pane");
1268    } else {
1269      vpane=1;
1270      hide("content_pane2");
1271    }
1272    resizeit();
1273  }
1274  
1275  function show_pane2() {
1276    vpane++;
1277    if (vpane>1) {
1278     show2("content_pane2");
1279     resizeit();
1280    }
1281  }
1282  
1283  function stop_drag() {
1284    var obj = getObj("pane");
1285    if (obj) obj.style.visibility="";
1286    document.onmousemove=null;
1287    document.onmouseup=null;
1288    document.onmousedown=null;
1289    document.onselectstart=null;
1290  }
1291  
1292  function start_drag(func) {
1293    getObj("tree").style.width="auto"; // IE
1294    document.onmousemove=func;
1295    document.onmouseup=stop_drag;
1296    document.onmousedown=function(){return false;}
1297    document.onselectstart=function(){return false;}
1298  }
1299  
1300  function resize_pane2(event) {
1301    cancel(event);
1302    if (!event) event = window.event;
1303    getObj("pane2").style.visibility="hidden";
1304    pane2 = 1-event.clientX/return_width();
1305    if (pane2 > 0.5 || pane2 < 0.15) {
1306      pane2=0.27;
1307      hidepane("pane2");
1308    } else resizeit();
1309    if (pane_timer!=null) clearTimeout(pane_timer);
1310    pane_timer = setTimeout(function(){ getObj("pane2").style.visibility=""; },250);
1311    save_cookie();
1312    return false;
1313  }
1314  
1315  function resize_pane(event) {
1316    cancel(event);
1317    if (!event) event = window.event;
1318    getObj("pane").style.visibility="hidden";
1319    pane = event.clientY/return_height()-0.005;
1320    if (pane > 0.9 || pane < 0.25) {
1321      pane=0.53;
1322      hidepane("pane");
1323    } else resizeit();
1324    if (pane_timer!=null) clearTimeout(pane_timer);
1325    pane_timer = setTimeout(function(){ getObj("pane").style.visibility=""; },250);
1326    save_cookie();
1327    return false;
1328  }
1329  
1330  function ______A_J_A_X______() {}
1331  
1332  function asset_update(data, id) {
1333    if (typeof(id)=="object") {
1334      for (var i=0; i<id.length; i++) asset_update(data, id[i]);
1335      return;
1336    }
1337    ajax("asset_update", [tfolder, "edit", data, id], ajax_locate_folder);
1338  }
1339  
1340  function asset_update_confirm(data, id, message) {
1341    if (typeof(message)=="undefined") message = "{t}Really apply the changes ?{/t}";
1342    if (sys_confirm(message)) asset_update(data, id);
1343  }
1344  
1345  function asset_insert(data) {
1346    ajax("asset_insert", [tfolder, "new", data], ajax_locate_folder);
1347  }
1348  
1349  var prompt_value = "";
1350  function asset_insert_prompt(fields, field_names) {
1351    fields = fields.split("|");
1352    field_names = field_names.split("|");
1353    var info = "\n\n{t}Line break{/t}: \\n\n{t}Comma{/t}: \\k\n{t}Separate fields{/t}: ,\n{t}Separate values{/t}: |\n\n";
1354    prompt_value = prompt(remove_trans("{t}Quick add{/t}: "+field_names.join(", ")+info), prompt_value);
1355    var data = {};
1356    var values = prompt_value.split(",");
1357    for (var i=0; i<values.length; i++) {
1358      if (!fields[i]) {
1359        fields[i] = values[i].split(":")[0].replace(/^\s+|\s+$/g,""); // trim
1360        values[i] = values[i].split(":")[1];
1361      }
1362      if (values[i] != null) data[fields[i]] = values[i].replace(/\\k/g,",").replace(/\\n/g,"\n").replace(/^\s+|\s+$/g,""); // trim
1363    }
1364    asset_insert(data);
1365  }
1366  
1367  function get_loading(func) {
1368    var elem = document.createElement("div");
1369    elem.innerHTML = '<img src="ext/images/loading.gif" title="'+func+'"/>';
1370    elem.style.display = "none";
1371    if (getObj("loading")) getObj("loading").appendChild(elem); else return null;
1372    return elem;
1373  }
1374  
1375  function ajax(func, params, callback, timeout) {
1376    if (typeof(navigator.onLine)!="undefined" && !navigator.onLine) return;
1377    if (typeof(timeout)=="undefined") timeout = 10000;
1378    var xmlhttp = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
1379    xmlhttp.open("POST", "ajax.php?function="+escape(func), true);
1380    xmlhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
1381    xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
1382    pending_request++;
1383    var timer = setTimeout(function() {
1384      timer = null;
1385      xmlhttp.abort();
1386      sys_alert("{t}Error doing request to xmlhttp{/t}: {t}timeout{/t} "+func);
1387    }, timeout);
1388    var image = get_loading(func);
1389    var loading = setTimeout(function() { show(image); }, 750);
1390    xmlhttp.onreadystatechange = function() {
1391      if (xmlhttp.readyState == 4) {
1392        pending_request--;
1393        if (loading != null) clearTimeout(loading);
1394        hide(image);
1395        if (timer != null) clearTimeout(timer); else return;
1396        var result = xmlhttp.responseText;
1397        try {
1398          if (xmlhttp.status==0 && result=="") return;
1399          if (xmlhttp.status==200 && result!="") {
1400            if (callback!=null) callback(JSON.parse(result));
1401          } else sys_alert("{t}Ajax Error{/t}: "+func+" "+xmlhttp.status+" "+xmlhttp.statusText+"\n"+(result!=""?result:"{t}no result{/t}"));
1402        } catch (e) {
1403          if (result.length > 0) {
1404            if (e == "SyntaxError: parseJSON") e = "";
1405            if (e) error = e.name+": "+e.message; else error = "";
1406            if (!debug) trace = "\n"+JSON.stringify(e); else trace = "";
1407            sys_alert("{t}Error{/t}: "+error+"\n"+result+"\n"+func+trace);
1408    } } } }
1409    xmlhttp.send(JSON.stringify(params));
1410  }
1411  
1412  // https://developer.mozilla.org/en/Using_files_from_web_applications
1413  function ajax_binary(func, file, params, callback, callback_progress) {
1414    if (typeof(navigator.onLine)!="undefined" && !navigator.onLine) return;
1415    var xmlhttp = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
1416    if (callback_progress!=null) {
1417      xmlhttp.upload.onprogress = callback_progress;
1418      xmlhttp.upload.onload = callback_progress;
1419    }
1420    xmlhttp.open("PUT", "ajax.php?function="+escape(func)+"&params="+JSON.stringify(params), true);
1421    xmlhttp.setRequestHeader("Content-Type", "application/octet-stream; charset=utf-8");
1422    xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
1423    xmlhttp.onreadystatechange = function() {
1424      if (xmlhttp.readyState == 4) {
1425        var result = xmlhttp.responseText;
1426        try {
1427          if (xmlhttp.status==200 && result!="") {
1428            var js = JSON.parse(result);
1429            if (callback!=null) callback(js);
1430          } else sys_alert("{t}Ajax Error{/t}: "+func+" "+xmlhttp.status+" "+xmlhttp.statusText+"\n"+(result!=""?result:"{t}no result{/t}"));
1431        } catch (e) {
1432          if (result.length > 0) {
1433            if (e == "SyntaxError: parseJSON") e = "";
1434            if (e) error = e.name+": "+e.message; else error = "";
1435            sys_alert("{t}Error{/t}: "+error+"\n"+result+"\n"+func);
1436    } } } }
1437    xmlhttp.send(file);
1438  }
1439  
1440  function ajax_locate_folder(data) {
1441    if (typeof(data) != "object") {
1442      locate_folder(tfolder);
1443      return;
1444    }
1445    var output = "";
1446    for (i in data) {
1447      for (j in data[i]) {
1448        output += data[i][j][0] + ": " + data[i][j][1] + "\n";
1449      }
1450    }
1451    sys_alert(output);
1452  }
1453  
1454  var call_autosize=[];
1455  function textarea_autosize(event) {
1456    if ((call_autosize[this.id]>2 && getmykey(event)!=13) || attr(this,"rel")=="no_resize") return;
1457    if (typeof(this.clone)=="undefined") {
1458      this.clone = document.createElement("textarea");
1459      this.clone.style.width = this.clientWidth+"px";
1460      this.clone.style.position = "absolute";
1461      this.clone.style.left = -9999;
1462      this.clone.disabled = true;
1463      this.parentNode.insertBefore(this.clone,this);
1464    }
1465    this.clone.style.width = this.clientWidth+"px";
1466    this.clone.value = this.value;
1467    this.style.height = Math.max(64,Math.min(return_height()-160, this.clone.scrollHeight+44))+"px";
1468    call_autosize[this.id]++;
1469    setTimeout(function(){ call_autosize[this.id] = 0; }, 2500);
1470  }
1471  
1472  function ______M_E_N_U______() {}
1473  
1474  function menuover(obj) {
1475    if (mtrigger!=null) menuopen(obj);
1476    obj.className = "menu_item2";
1477  }
1478  function menuout(obj) {
1479    obj.className = "menu_item";
1480  }
1481  function menuopen(obj) {
1482    if (mtimer!=null) clearTimeout(mtimer);
1483    if (obj.id=="menu") return;
1484    var menu = getObj(obj.id.replace("item",""));
1485    if (menu && (mtrigger==null || mtrigger.id!=menu.id)) {
1486      if (mtrigger!=null) hide(mtrigger);
1487      mtrigger = menu;
1488      show2(menu);
1489    } else if (!menu && mtrigger!=null) {
1490      mtriggerclose();
1491    }
1492  }
1493  function menuclose() {
1494    mtimer = setTimeout("mtriggerclose()",250);
1495  }
1496  function mtriggerclose() {
1497    if (mtrigger!=null) {
1498      hide(mtrigger);
1499      mtrigger = null;
1500    }
1501  }
1502  
1503  function menu_begin() {
1504    mbuffer += '<table id="menu" class="menu" cellspacing="2" cellpadding="0" onmouseout="menuclose();" onmouseover="menuopen(this);"><tr>';
1505  }
1506  function menu_end() {
1507    mbuffer += "</tr></table>"+smenu_buffer;
1508  }
1509  function menuitem(name) {
1510    mbuffer += '<td id="menuitem'+menu+'" class="menu_item" style="width:85px;" onmouseover="menuover(this);" onmouseout="menuout(this);" onclick="menuopen(this);">'+remove_trans(name)+'</td>';
1511    menu++;
1512  }
1513  function menubutton(name,ref,accesskey,style) {
1514    var html = "";
1515    var hint = "";
1516    if (typeof(style)=="undefined") style="width:85px;";
1517    if (typeof(accesskey)!="undefined") {
1518      html = "<a onclick='"+ref.replace(/'/g, "&quot;")+"' href='#' accesskey='"+accesskey+"'></a>";
1519      hint = "[Alt-"+accesskey+"]";
1520    }
1521    mbuffer += '<td id="menuitem'+menu+'" class="menu_item" style="'+style+'" onmouseover="menuover(this);" onmouseout="menuout(this);" onclick="'+ref+'" title="'+hint+'">'+remove_trans(name)+html+'</td>';
1522    menu++;
1523    smenu++
1524  }
1525  function smenu_begin() {
1526    smenu_buffer += '<table onmouseover="menuopen(this);" onmouseout="menuclose();" id="menu'+smenu+'" class="submenu" cellspacing="0" cellpadding="0" style="display:none;'+mleft+':'+(smenu*90)+'px;">';
1527    smenu++
1528  }
1529  function smenu_end() {
1530    smenu_buffer += '</table>';
1531  }
1532  function smenuitem(name,ref,accesskey) {
1533    var html = "";
1534    var hint = "";
1535    if (typeof(accesskey)!="undefined") {
1536        html = "<a onclick='"+ref.replace(/'/g, "&quot;")+"' href='#' accesskey='"+accesskey+"'></a>";
1537      hint = "[Alt-"+accesskey+"]";
1538    }
1539    smenu_buffer += '<tr><td id="menuitem0" class="menu_item" style="padding-'+mleft+': 6px;" onmouseover="menuover(this);" onmouseout="menuout(this);" onclick="menuclose(); '+(ref!=""?ref:"")+'" title="'+hint+'">'+remove_trans(name)+html+'</td></tr>';
1540  }
1541  function smenu_home() {
1542    if (sys.username!="anonymous" && !sys.is_superadmin) {
1543      smenuitem("{t}Change settings{/t}","locate('index.php?find=asset|simple_sys_users|1|username="+sys.username+"&view=changepwd')");
1544      smenu_hr();
1545      smenuitem("{t}Home{/t}","locate('"+sys.home+"')", "h");
1546    } else if (sys.is_superadmin) {
1547      smenuitem("{t}Change settings{/t}","locate('index.php?action_sys=edit_setup')");
1548      smenu_hr();
1549      smenuitem("{t}Administration{/t}","locate('"+sys.home+"')", "h");
1550      smenuitem("{t}Backup current folder{/t}","sWin('index.php?action_sys=backup');");
1551    } else {
1552      smenuitem("{t}Home{/t}","locate('index.php?folder=1')","h");
1553    }
1554  }
1555  function smenu_history() {
1556    if (hist!="") {
1557      for (var i=0; i<hist.length; i++) {
1558        if (hist[i].length!=3) continue;
1559        var title = hist[i][0];
1560        if (hist[i][2]!="" && hist[i][2]!="display") title += " &nbsp;("+hist[i][2]+")";
1561        smenuitem(title,"locate('index.php?folder="+escape(hist[i][1])+"&view="+hist[i][2]+"')");
1562      }
1563    } else smenuitem("{t}Empty{/t}","");
1564  }
1565  function smenu_hr() {
1566    smenu_buffer += '<tr><td><div style="margin-top:3px; margin-bottom:3px; border-top: 1px solid '+css_conf.color_light_grey+';"><none></div></td></tr>';
1567  }
1568  function folder_delete() {
1569    if (sys_confirm('{t}Really delete ?{/t}') && sys_confirm('{t}Really delete ALL subfolders ?{/t}')) {
1570      ajax("folder_delete", [tfolder], locate_folder);
1571    }
1572  }
1573  function tree_applyrights() {
1574    if (sys_confirm("{t}Really apply rights to subfolders ?{/t}")) {
1575      ajax("folder_applyrights", [tfolder], function(data) {
1576        if (data) sys_alert("{t}Item successfully updated.{/t}");
1577          else sys_alert("{t}Item not found.{/t}");
1578      });
1579    }
1580  }
1581  
1582  function drawmenu() {
1583    menu_begin();
1584  
1585    menuitem("{t}Main menu{/t}");
1586    smenu_begin();
1587    smenu_home();
1588    smenu_hr();
1589    smenuitem("{t}Print{/t}","neWin('index.php?print=1')");
1590    smenuitem("{t}Print all{/t}","neWin('index.php?print=1&print_all=1')");
1591    smenu_hr();
1592    if (tree_visible) smenuitem("{t}Minimize{/t}","sWin('index.php?tree=minimize')");
1593      else smenuitem("{t}Maximize{/t}","sWin('index.php?tree=maximize')");
1594    smenu_hr();
1595    smenuitem("{t}Collapse tree{/t}","sWin('index.php?tree=closeall')");
1596    smenuitem("{t}Reset view{/t}","sWin('index.php?reset_view=true')");
1597    smenuitem("{t}Close session{/t}","sWin('index.php?logout&session_clean')");
1598    smenu_hr();
1599    smenuitem("{t}Offline sync{/t}","sWin('offline.php?')");
1600    smenu_end();
1601  
1602    if (sys.username!="anonymous" && !sys.is_superadmin) {
1603      menuitem("{t}Create new{/t}");
1604      smenu_begin();
1605      var quick_create = {
1606        emails:"{t}E-mail{/t}", calendar:"{t}Appointment{/t}", tasks:"{t}Task{/t}",
1607        contactactivities:"{t}Contact activity{/t}", contacts:"{t}Contact{/t}",
1608        passwords:"{t}Password{/t}", bookmarks:"{t}Bookmark{/t}", notes:"{t}Note{/t}",
1609        files:"{t}File{/t}", gallery:"{t}Photo{/t}", spreadsheets:"{t}Spreadsheet{/t}",
1610        graphviz:"{t}Diagram{/t}", htmldocs:"{t}HTML document{/t}", cms:"{t}Web page{/t}"
1611      }
1612      for (var type in quick_create) {
1613        if (sys.disabled_modules[type]) continue;
1614        var icon = "";
1615        if (sys_style=="core_tree_icons") icon += "<img src='ext/modules/"+type+".png'>&nbsp; &nbsp;";
1616        smenuitem(icon+quick_create[type],"sWin('index.php?folder=^home_"+sys.username+"/!"+type+"&view=new')");
1617      }
1618      smenu_end();
1619    }
1620    
1621    menuitem("{t}Folder{/t}");
1622    smenu_begin();
1623    if (sys.username!="anonymous") {
1624      smenuitem("{t}Add to offline folders{/t}","ajax('folder_add_offline',[tfolder,tview,tfolder_name],alert_ok);");
1625    }
1626    if (rights.write_folder && isdbfolder) {
1627      smenu_hr();
1628      smenuitem("{t}Move{/t}: {t}Up{/t}","ajax('folder_moveup',[tfolder],locate_folder)");
1629      smenuitem("{t}Move{/t}: {t}Down{/t}","ajax('folder_movedown',[tfolder],locate_folder)");
1630    }
1631    if (!no_folder_operations && rights.write_folder) {
1632      if (isdbfolder) {
1633        smenu_hr();
1634        smenuitem("{t}Cut{/t}","ajax('folder_cut',[tfolder],null)");
1635        smenuitem("{t}Copy{/t}","ajax('folder_copy',[tfolder],null)");
1636        smenuitem("{t}Paste{/t}","ajax('folder_paste',[tfolder],locate_folder,30000)");
1637      }
1638      smenu_hr();
1639      smenuitem("{t}Delete incl subfolders{/t}","folder_delete()");
1640    }
1641    if (rights.admin && isdbfolder) {
1642      smenu_hr();
1643      smenuitem("{t}Rights{/t}: {t}Show{/t}","sWin('index.php?view=rights')");
1644      smenuitem("{t}Rights{/t}: {t}Edit{/t}","sWin('index.php?view=rights_edit')","0");
1645      smenuitem("{t}Apply rights to subfolders{/t}","tree_applyrights()");
1646    }
1647    if (rights.write_folder && isdbfolder) {
1648      smenu_hr();
1649      smenuitem("{t}Merge folders permanently{/t}","tree_categories()");
1650    }
1651    if (!no_folder_operations && rights.write_folder) {
1652      smenu_hr();
1653      smenuitem("{t}Options{/t}","tree_folder_options()");
1654    }
1655    if (!no_folder_operations && isdbfolder && ((rights.write_folder && !sys.mountpoint_admin) || rights.admin_folder)) {
1656      smenuitem("{t}Mountpoint{/t}","tree_folder_mountpoint()");
1657    }
1658    smenuitem("{t}Info{/t}","tree_folder_info()");
1659    smenu_end();
1660  
1661    menuitem("{t}History{/t}");
1662    smenu_begin();
1663    smenu_history();
1664    smenu_end();
1665  
1666    menuitem("{t}Im-/Export{/t}");
1667    smenu_begin();
1668    if (rights.write) {
1669      smenuitem("Simple Groupware {t}Import{/t}","sWin('import.php?folder="+escape(tfolder)+"')");
1670      smenu_hr();
1671    }
1672    smenuitem("Simple Spreadsheet","neWin('index.php?export=sss')");
1673    smenuitem("ExtJS {t}Table{/t}","neWin('ext/lib/extjs/index.php?title='+escape(tfolder_name)+'&items='+assets_get_selected(true).join(','))");
1674    smenuitem("HTML","neWin('index.php?export=html')");
1675    smenuitem("HTML ({t}vertical{/t})","neWin('index.php?export=html_vertical')");
1676    smenuitem("CSV","sWin('index.php?export=csv')");
1677    smenuitem("{t}Spreadsheet{/t}","sWin('index.php?export=calc')");
1678    smenuitem("{t}Text Document{/t}","sWin('index.php?export=writer')");
1679    smenuitem("XML","sWin('index.php?export=xml')");
1680    smenuitem("RSS","sWin('index.php?export=rss')");
1681    smenuitem("iCalendar","sWin('index.php?export=icalendar')");
1682    smenuitem("vCard","sWin('index.php?export=vcard')");
1683    smenuitem("LDIF","sWin('index.php?export=ldif')");
1684    smenu_end();
1685  
1686    menuitem("{t}Theme{/t}");
1687    smenu_begin();
1688    var styles = {
1689      core:"core", core_tree_icons:"core tree icons",    contrast:"contrast", water:"water", lake:"lake",
1690      beach:"beach", paradise:"paradise", earth:"earth", sunset:"sunset", nature:"nature", desert:"desert",
1691      blackwhite:"black / white", rtl:"right-to-left"
1692    }
1693    for (var style in styles) {
1694      var checked = "";
1695      if (sys_style==style) checked = "&gt; ";
1696      smenuitem(checked+"simple "+styles[style],"sWin('index.php?style="+style+"')");
1697    }
1698    smenu_end();
1699  
1700    menubutton("{t}Help{/t}","nWin('cms.php?page=Help')");
1701    menubutton("&nbsp;{t}Login/-out{/t} <img src='ext/icons/logout.gif' title='{t}Login/-out{/t}'/>&nbsp;","sWin('index.php?logout')", "l", "");
1702    mbuffer += '<td><span id="notification"></span></td>';
1703    menu_end();
1704    getObj("menu").innerHTML = mbuffer;
1705    if (warning) notify(warning, true); else notify(notification);
1706  }

title

Description

title

Description

title

Description

title

title

Body