[ Index ]
 

Code source de phpMyAdmin 2.10.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/js/ -> functions.js (source)

   1  /* $Id: functions.js 10297 2007-04-17 16:43:24Z lem9 $ */
   2  
   3  /**
   4   * @var sql_box_locked lock for the sqlbox textarea in the querybox/querywindow
   5   */
   6  var sql_box_locked = false;
   7  
   8  /**
   9   * @var array holds elements which content should only selected once
  10   */
  11  var only_once_elements = new Array();
  12  
  13  /**
  14   * selects the content of a given object, f.e. a textarea
  15   *
  16   * @param   object  element     element of which the content will be selected
  17   * @param   var     lock        variable which holds the lock for this element
  18   *                              or true, if no lock exists
  19   * @param   boolean only_once   if true this is only done once
  20   *                              f.e. only on first focus
  21   */
  22  function selectContent( element, lock, only_once ) {
  23      if ( only_once && only_once_elements[element.name] ) {
  24          return;
  25      }
  26  
  27      only_once_elements[element.name] = true;
  28  
  29      if ( lock  ) {
  30          return;
  31      }
  32  
  33      element.select();
  34  }
  35  
  36  /**
  37   * Displays an confirmation box before to submit a "DROP DATABASE" query.
  38   * This function is called while clicking links
  39   *
  40   * @param   object   the link
  41   * @param   object   the sql query to submit
  42   *
  43   * @return  boolean  whether to run the query or not
  44   */
  45  function confirmLinkDropDB(theLink, theSqlQuery)
  46  {
  47      // Confirmation is not required in the configuration file
  48      // or browser is Opera (crappy js implementation)
  49      if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
  50          return true;
  51      }
  52  
  53      var is_confirmed = confirm(confirmMsgDropDB + '\n' + confirmMsg + ' :\n' + theSqlQuery);
  54      if (is_confirmed) {
  55          theLink.href += '&is_js_confirmed=1';
  56      }
  57  
  58      return is_confirmed;
  59  } // end of the 'confirmLinkDropDB()' function
  60  
  61  /**
  62   * Displays an confirmation box before to submit a "DROP/DELETE/ALTER" query.
  63   * This function is called while clicking links
  64   *
  65   * @param   object   the link
  66   * @param   object   the sql query to submit
  67   *
  68   * @return  boolean  whether to run the query or not
  69   */
  70  function confirmLink(theLink, theSqlQuery)
  71  {
  72      // Confirmation is not required in the configuration file
  73      // or browser is Opera (crappy js implementation)
  74      if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
  75          return true;
  76      }
  77  
  78      var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
  79      if (is_confirmed) {
  80          if ( typeof(theLink.href) != 'undefined' ) {
  81              theLink.href += '&is_js_confirmed=1';
  82          } else if ( typeof(theLink.form) != 'undefined' ) {
  83              theLink.form.action += '?is_js_confirmed=1';
  84          }
  85      }
  86  
  87      return is_confirmed;
  88  } // end of the 'confirmLink()' function
  89  
  90  
  91  /**
  92   * Displays an confirmation box before doing some action
  93   *
  94   * @param   object   the message to display
  95   *
  96   * @return  boolean  whether to run the query or not
  97   */
  98  function confirmAction(theMessage)
  99  {
 100      // TODO: Confirmation is not required in the configuration file
 101      // or browser is Opera (crappy js implementation)
 102      if (typeof(window.opera) != 'undefined') {
 103          return true;
 104      }
 105  
 106      var is_confirmed = confirm(theMessage);
 107  
 108      return is_confirmed;
 109  } // end of the 'confirmAction()' function
 110  
 111  
 112  /**
 113   * Displays an error message if a "DROP DATABASE" statement is submitted
 114   * while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before
 115   * sumitting it if required.
 116   * This function is called by the 'checkSqlQuery()' js function.
 117   *
 118   * @param   object   the form
 119   * @param   object   the sql query textarea
 120   *
 121   * @return  boolean  whether to run the query or not
 122   *
 123   * @see     checkSqlQuery()
 124   */
 125  function confirmQuery(theForm1, sqlQuery1)
 126  {
 127      // Confirmation is not required in the configuration file
 128      if (confirmMsg == '') {
 129          return true;
 130      }
 131  
 132      // The replace function (js1.2) isn't supported
 133      else if (typeof(sqlQuery1.value.replace) == 'undefined') {
 134          return true;
 135      }
 136  
 137      // js1.2+ -> validation with regular expressions
 138      else {
 139          // "DROP DATABASE" statement isn't allowed
 140          if (noDropDbMsg != '') {
 141              var drop_re = new RegExp('(^|;)\\s*DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
 142              if (drop_re.test(sqlQuery1.value)) {
 143                  alert(noDropDbMsg);
 144                  theForm1.reset();
 145                  sqlQuery1.focus();
 146                  return false;
 147              } // end if
 148          } // end if
 149  
 150          // Confirms a "DROP/DELETE/ALTER" statement
 151          //
 152          // TODO: find a way (if possible) to use the parser-analyser
 153          // for this kind of verification
 154          // For now, I just added a ^ to check for the statement at
 155          // beginning of expression
 156  
 157          var do_confirm_re_0 = new RegExp('^DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE)\\s', 'i');
 158          var do_confirm_re_1 = new RegExp('^ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
 159          var do_confirm_re_2 = new RegExp('^DELETE\\s+FROM\\s', 'i');
 160          if (do_confirm_re_0.test(sqlQuery1.value)
 161              || do_confirm_re_1.test(sqlQuery1.value)
 162              || do_confirm_re_2.test(sqlQuery1.value)) {
 163              var message      = (sqlQuery1.value.length > 100)
 164                               ? sqlQuery1.value.substr(0, 100) + '\n    ...'
 165                               : sqlQuery1.value;
 166              var is_confirmed = confirm(confirmMsg + ' :\n' + message);
 167              // drop/delete/alter statement is confirmed -> update the
 168              // "is_js_confirmed" form field so the confirm test won't be
 169              // run on the server side and allows to submit the form
 170              if (is_confirmed) {
 171                  theForm1.elements['is_js_confirmed'].value = 1;
 172                  return true;
 173              }
 174              // "DROP/DELETE/ALTER" statement is rejected -> do not submit
 175              // the form
 176              else {
 177                  window.focus();
 178                  sqlQuery1.focus();
 179                  return false;
 180              } // end if (handle confirm box result)
 181          } // end if (display confirm box)
 182      } // end confirmation stuff
 183  
 184      return true;
 185  } // end of the 'confirmQuery()' function
 186  
 187  
 188  /**
 189   * Displays an error message if the user submitted the sql query form with no
 190   * sql query, else checks for "DROP/DELETE/ALTER" statements
 191   *
 192   * @param   object   the form
 193   *
 194   * @return  boolean  always false
 195   *
 196   * @see     confirmQuery()
 197   */
 198  function checkSqlQuery(theForm)
 199  {
 200      var sqlQuery = theForm.elements['sql_query'];
 201      var isEmpty  = 1;
 202  
 203      // The replace function (js1.2) isn't supported -> basic tests
 204      if (typeof(sqlQuery.value.replace) == 'undefined') {
 205          isEmpty      = (sqlQuery.value == '') ? 1 : 0;
 206          if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
 207              isEmpty  = (theForm.elements['sql_file'].value == '') ? 1 : 0;
 208          }
 209          if (isEmpty && typeof(theForm.elements['sql_localfile']) != 'undefined') {
 210              isEmpty  = (theForm.elements['sql_localfile'].value == '') ? 1 : 0;
 211          }
 212          if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
 213              isEmpty  = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
 214          }
 215      }
 216      // js1.2+ -> validation with regular expressions
 217      else {
 218          var space_re = new RegExp('\\s+');
 219          if (typeof(theForm.elements['sql_file']) != 'undefined' &&
 220                  theForm.elements['sql_file'].value.replace(space_re, '') != '') {
 221              return true;
 222          }
 223          if (typeof(theForm.elements['sql_localfile']) != 'undefined' &&
 224                  theForm.elements['sql_localfile'].value.replace(space_re, '') != '') {
 225              return true;
 226          }
 227          if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined' &&
 228                  (theForm.elements['id_bookmark'].value != null || theForm.elements['id_bookmark'].value != '') &&
 229                  theForm.elements['id_bookmark'].selectedIndex != 0
 230                  ) {
 231              return true;
 232          }
 233          // Checks for "DROP/DELETE/ALTER" statements
 234          if (sqlQuery.value.replace(space_re, '') != '') {
 235              if (confirmQuery(theForm, sqlQuery)) {
 236                  return true;
 237              } else {
 238                  return false;
 239              }
 240          }
 241          theForm.reset();
 242          isEmpty = 1;
 243      }
 244  
 245      if (isEmpty) {
 246          sqlQuery.select();
 247          alert(errorMsg0);
 248          sqlQuery.focus();
 249          return false;
 250      }
 251  
 252      return true;
 253  } // end of the 'checkSqlQuery()' function
 254  
 255  
 256  /**
 257   * Check if a form's element is empty
 258   * should be
 259   *
 260   * @param   object   the form
 261   * @param   string   the name of the form field to put the focus on
 262   *
 263   * @return  boolean  whether the form field is empty or not
 264   */
 265  function emptyCheckTheField(theForm, theFieldName)
 266  {
 267      var isEmpty  = 1;
 268      var theField = theForm.elements[theFieldName];
 269      // Whether the replace function (js1.2) is supported or not
 270      var isRegExp = (typeof(theField.value.replace) != 'undefined');
 271  
 272      if (!isRegExp) {
 273          isEmpty      = (theField.value == '') ? 1 : 0;
 274      } else {
 275          var space_re = new RegExp('\\s+');
 276          isEmpty      = (theField.value.replace(space_re, '') == '') ? 1 : 0;
 277      }
 278  
 279      return isEmpty;
 280  } // end of the 'emptyCheckTheField()' function
 281  
 282  
 283  /**
 284   * Displays an error message if an element of a form hasn't been completed and
 285   * should be
 286   *
 287   * @param   object   the form
 288   * @param   string   the name of the form field to put the focus on
 289   *
 290   * @return  boolean  whether the form field is empty or not
 291   */
 292  function emptyFormElements(theForm, theFieldName)
 293  {
 294      var theField = theForm.elements[theFieldName];
 295      var isEmpty = emptyCheckTheField(theForm, theFieldName);
 296  
 297      if (isEmpty) {
 298          theForm.reset();
 299          theField.select();
 300          alert(errorMsg0);
 301          theField.focus();
 302          return false;
 303      }
 304  
 305      return true;
 306  } // end of the 'emptyFormElements()' function
 307  
 308  
 309  /**
 310   * Ensures a value submitted in a form is numeric and is in a range
 311   *
 312   * @param   object   the form
 313   * @param   string   the name of the form field to check
 314   * @param   integer  the minimum authorized value
 315   * @param   integer  the maximum authorized value
 316   *
 317   * @return  boolean  whether a valid number has been submitted or not
 318   */
 319  function checkFormElementInRange(theForm, theFieldName, message, min, max)
 320  {
 321      var theField         = theForm.elements[theFieldName];
 322      var val              = parseInt(theField.value);
 323  
 324      if (typeof(min) == 'undefined') {
 325          min = 0;
 326      }
 327      if (typeof(max) == 'undefined') {
 328          max = Number.MAX_VALUE;
 329      }
 330  
 331      // It's not a number
 332      if (isNaN(val)) {
 333          theField.select();
 334          alert(errorMsg1);
 335          theField.focus();
 336          return false;
 337      }
 338      // It's a number but it is not between min and max
 339      else if (val < min || val > max) {
 340          theField.select();
 341          alert(message.replace('%d', val));
 342          theField.focus();
 343          return false;
 344      }
 345      // It's a valid number
 346      else {
 347          theField.value = val;
 348      }
 349      return true;
 350  
 351  } // end of the 'checkFormElementInRange()' function
 352  
 353  
 354  function checkTableEditForm(theForm, fieldsCnt)
 355  {
 356      // TODO: avoid sending a message if user just wants to add a line
 357      // on the form but has not completed at least one field name
 358  
 359      var atLeastOneField = 0;
 360      var i, elm, elm2, elm3, val, id;
 361  
 362      for (i=0; i<fieldsCnt; i++)
 363      {
 364          id = "field_" + i + "_2";
 365          elm = getElement(id);
 366          if (elm.value == 'VARCHAR' || elm.value == 'CHAR') {
 367              elm2 = getElement("field_" + i + "_3");
 368              val = parseInt(elm2.value);
 369              elm3 = getElement("field_" + i + "_1");
 370              if (isNaN(val) && elm3.value != "") {
 371                  elm2.select();
 372                  alert(errorMsg1);
 373                  elm2.focus();
 374                  return false;
 375              }
 376          }
 377  
 378          if (atLeastOneField == 0) {
 379              id = "field_" + i + "_1";
 380              if (!emptyCheckTheField(theForm, id)) {
 381                  atLeastOneField = 1;
 382              }
 383          }
 384      }
 385      if (atLeastOneField == 0) {
 386          var theField = theForm.elements["field_0_1"];
 387          alert(errorMsg0);
 388          theField.focus();
 389          return false;
 390      }
 391  
 392      return true;
 393  } // enf of the 'checkTableEditForm()' function
 394  
 395  
 396  /**
 397   * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
 398   * checkboxes is consistant
 399   *
 400   * @param   object   the form
 401   * @param   string   a code for the action that causes this function to be run
 402   *
 403   * @return  boolean  always true
 404   */
 405  function checkTransmitDump(theForm, theAction)
 406  {
 407      var formElts = theForm.elements;
 408  
 409      // 'zipped' option has been checked
 410      if (theAction == 'zip' && formElts['zip'].checked) {
 411          if (!formElts['asfile'].checked) {
 412              theForm.elements['asfile'].checked = true;
 413          }
 414          if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
 415              theForm.elements['gzip'].checked = false;
 416          }
 417          if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
 418              theForm.elements['bzip'].checked = false;
 419          }
 420      }
 421      // 'gzipped' option has been checked
 422      else if (theAction == 'gzip' && formElts['gzip'].checked) {
 423          if (!formElts['asfile'].checked) {
 424              theForm.elements['asfile'].checked = true;
 425          }
 426          if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
 427              theForm.elements['zip'].checked = false;
 428          }
 429          if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
 430              theForm.elements['bzip'].checked = false;
 431          }
 432      }
 433      // 'bzipped' option has been checked
 434      else if (theAction == 'bzip' && formElts['bzip'].checked) {
 435          if (!formElts['asfile'].checked) {
 436              theForm.elements['asfile'].checked = true;
 437          }
 438          if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
 439              theForm.elements['zip'].checked = false;
 440          }
 441          if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
 442              theForm.elements['gzip'].checked = false;
 443          }
 444      }
 445      // 'transmit' option has been unchecked
 446      else if (theAction == 'transmit' && !formElts['asfile'].checked) {
 447          if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
 448              theForm.elements['zip'].checked = false;
 449          }
 450          if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
 451              theForm.elements['gzip'].checked = false;
 452          }
 453          if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
 454              theForm.elements['bzip'].checked = false;
 455          }
 456      }
 457  
 458      return true;
 459  } // end of the 'checkTransmitDump()' function
 460  
 461  
 462  /**
 463   * This array is used to remember mark status of rows in browse mode
 464   */
 465  var marked_row = new Array;
 466  
 467  /**
 468   * enables highlight and marking of rows in data tables
 469   *
 470   */
 471  function PMA_markRowsInit() {
 472      // for every table row ...
 473      var rows = document.getElementsByTagName('tr');
 474      for ( var i = 0; i < rows.length; i++ ) {
 475          // ... with the class 'odd' or 'even' ...
 476          if ( 'odd' != rows[i].className.substr(0,3) && 'even' != rows[i].className.substr(0,4) ) {
 477              continue;
 478          }
 479          // ... add event listeners ...
 480          // ... to highlight the row on mouseover ...
 481          if ( navigator.appName == 'Microsoft Internet Explorer' ) {
 482              // but only for IE, other browsers are handled by :hover in css
 483              rows[i].onmouseover = function() {
 484                  this.className += ' hover';
 485              }
 486              rows[i].onmouseout = function() {
 487                  this.className = this.className.replace( ' hover', '' );
 488              }
 489          }
 490          // Do not set click events if not wanted
 491          if (rows[i].className.search(/noclick/) != -1) {
 492              continue;
 493          }
 494          // ... and to mark the row on click ...
 495          rows[i].onmousedown = function() {
 496              var unique_id;
 497              var checkbox;
 498  
 499              checkbox = this.getElementsByTagName( 'input' )[0];
 500              if ( checkbox && checkbox.type == 'checkbox' ) {
 501                  unique_id = checkbox.name + checkbox.value;
 502              } else if ( this.id.length > 0 ) {
 503                  unique_id = this.id;
 504              } else {
 505                  return;
 506              }
 507  
 508              if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
 509                  marked_row[unique_id] = true;
 510              } else {
 511                  marked_row[unique_id] = false;
 512              }
 513  
 514              if ( marked_row[unique_id] ) {
 515                  this.className += ' marked';
 516              } else {
 517                  this.className = this.className.replace(' marked', '');
 518              }
 519  
 520              if ( checkbox && checkbox.disabled == false ) {
 521                  checkbox.checked = marked_row[unique_id];
 522              }
 523          }
 524  
 525          // ... and disable label ...
 526          var labeltag = rows[i].getElementsByTagName('label')[0];
 527          if ( labeltag ) {
 528              labeltag.onclick = function() {
 529                  return false;
 530              }
 531          }
 532          // .. and checkbox clicks
 533          var checkbox = rows[i].getElementsByTagName('input')[0];
 534          if ( checkbox ) {
 535              checkbox.onclick = function() {
 536                  // opera does not recognize return false;
 537                  this.checked = ! this.checked;
 538              }
 539          }
 540      }
 541  }
 542  window.onload=PMA_markRowsInit;
 543  
 544  /**
 545   * marks all rows and selects its first checkbox inside the given element
 546   * the given element is usaly a table or a div containing the table or tables
 547   *
 548   * @param    container    DOM element
 549   */
 550  function markAllRows( container_id ) {
 551      var rows = document.getElementById(container_id).getElementsByTagName('tr');
 552      var unique_id;
 553      var checkbox;
 554  
 555      for ( var i = 0; i < rows.length; i++ ) {
 556  
 557          checkbox = rows[i].getElementsByTagName( 'input' )[0];
 558  
 559          if ( checkbox && checkbox.type == 'checkbox' ) {
 560              unique_id = checkbox.name + checkbox.value;
 561              if ( checkbox.disabled == false ) {
 562                  checkbox.checked = true;
 563                  if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
 564                      rows[i].className += ' marked';
 565                      marked_row[unique_id] = true;
 566                  }
 567              }
 568          }
 569      }
 570  
 571      return true;
 572  }
 573  
 574  /**
 575   * marks all rows and selects its first checkbox inside the given element
 576   * the given element is usaly a table or a div containing the table or tables
 577   *
 578   * @param    container    DOM element
 579   */
 580  function unMarkAllRows( container_id ) {
 581      var rows = document.getElementById(container_id).getElementsByTagName('tr');
 582      var unique_id;
 583      var checkbox;
 584  
 585      for ( var i = 0; i < rows.length; i++ ) {
 586  
 587          checkbox = rows[i].getElementsByTagName( 'input' )[0];
 588  
 589          if ( checkbox && checkbox.type == 'checkbox' ) {
 590              unique_id = checkbox.name + checkbox.value;
 591              checkbox.checked = false;
 592              rows[i].className = rows[i].className.replace(' marked', '');
 593              marked_row[unique_id] = false;
 594          }
 595      }
 596  
 597      return true;
 598  }
 599  
 600  /**
 601   * Sets/unsets the pointer and marker in browse mode
 602   *
 603   * @param   object    the table row
 604   * @param   integer  the row number
 605   * @param   string    the action calling this script (over, out or click)
 606   * @param   string    the default background color
 607   * @param   string    the color to use for mouseover
 608   * @param   string    the color to use for marking a row
 609   *
 610   * @return  boolean  whether pointer is set or not
 611   */
 612  function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
 613  {
 614      var theCells = null;
 615  
 616      // 1. Pointer and mark feature are disabled or the browser can't get the
 617      //    row -> exits
 618      if ((thePointerColor == '' && theMarkColor == '')
 619          || typeof(theRow.style) == 'undefined') {
 620          return false;
 621      }
 622  
 623      // 1.1 Sets the mouse pointer to pointer on mouseover and back to normal otherwise.
 624      if (theAction == "over" || theAction == "click") {
 625          theRow.style.cursor='pointer';
 626      } else {
 627          theRow.style.cursor='default';
 628      }
 629  
 630      // 2. Gets the current row and exits if the browser can't get it
 631      if (typeof(document.getElementsByTagName) != 'undefined') {
 632          theCells = theRow.getElementsByTagName('td');
 633      }
 634      else if (typeof(theRow.cells) != 'undefined') {
 635          theCells = theRow.cells;
 636      }
 637      else {
 638          return false;
 639      }
 640  
 641      // 3. Gets the current color...
 642      var rowCellsCnt  = theCells.length;
 643      var domDetect    = null;
 644      var currentColor = null;
 645      var newColor     = null;
 646      // 3.1 ... with DOM compatible browsers except Opera that does not return
 647      //         valid values with "getAttribute"
 648      if (typeof(window.opera) == 'undefined'
 649          && typeof(theCells[0].getAttribute) != 'undefined') {
 650          currentColor = theCells[0].getAttribute('bgcolor');
 651          domDetect    = true;
 652      }
 653      // 3.2 ... with other browsers
 654      else {
 655          currentColor = theCells[0].style.backgroundColor;
 656          domDetect    = false;
 657      } // end 3
 658  
 659      // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
 660      if (currentColor.indexOf("rgb") >= 0)
 661      {
 662          var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
 663                                       currentColor.indexOf(')'));
 664          var rgbValues = rgbStr.split(",");
 665          currentColor = "#";
 666          var hexChars = "0123456789ABCDEF";
 667          for (var i = 0; i < 3; i++)
 668          {
 669              var v = rgbValues[i].valueOf();
 670              currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
 671          }
 672      }
 673  
 674      // 4. Defines the new color
 675      // 4.1 Current color is the default one
 676      if (currentColor == ''
 677          || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
 678          if (theAction == 'over' && thePointerColor != '') {
 679              newColor              = thePointerColor;
 680          }
 681          else if (theAction == 'click' && theMarkColor != '') {
 682              newColor              = theMarkColor;
 683              marked_row[theRowNum] = true;
 684              // Garvin: deactivated onclick marking of the checkbox because it's also executed
 685              // when an action (like edit/delete) on a single item is performed. Then the checkbox
 686              // would get deactived, even though we need it activated. Maybe there is a way
 687              // to detect if the row was clicked, and not an item therein...
 688              // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
 689          }
 690      }
 691      // 4.1.2 Current color is the pointer one
 692      else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
 693               && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
 694          if (theAction == 'out') {
 695              newColor              = theDefaultColor;
 696          }
 697          else if (theAction == 'click' && theMarkColor != '') {
 698              newColor              = theMarkColor;
 699              marked_row[theRowNum] = true;
 700              // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
 701          }
 702      }
 703      // 4.1.3 Current color is the marker one
 704      else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
 705          if (theAction == 'click') {
 706              newColor              = (thePointerColor != '')
 707                                    ? thePointerColor
 708                                    : theDefaultColor;
 709              marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
 710                                    ? true
 711                                    : null;
 712              // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
 713          }
 714      } // end 4
 715  
 716      // 5. Sets the new color...
 717      if (newColor) {
 718          var c = null;
 719          // 5.1 ... with DOM compatible browsers except Opera
 720          if (domDetect) {
 721              for (c = 0; c < rowCellsCnt; c++) {
 722                  theCells[c].setAttribute('bgcolor', newColor, 0);
 723              } // end for
 724          }
 725          // 5.2 ... with other browsers
 726          else {
 727              for (c = 0; c < rowCellsCnt; c++) {
 728                  theCells[c].style.backgroundColor = newColor;
 729              }
 730          }
 731      } // end 5
 732  
 733      return true;
 734  } // end of the 'setPointer()' function
 735  
 736  /*
 737   * Sets/unsets the pointer and marker in vertical browse mode
 738   *
 739   * @param   object    the table row
 740   * @param   integer   the column number
 741   * @param   string    the action calling this script (over, out or click)
 742   * @param   string    the default background Class
 743   * @param   string    the Class to use for mouseover
 744   * @param   string    the Class to use for marking a row
 745   *
 746   * @return  boolean  whether pointer is set or not
 747   *
 748   * @author Garvin Hicking <me@supergarv.de> (rewrite of setPointer.)
 749   */
 750  function setVerticalPointer(theRow, theColNum, theAction, theDefaultClass1, theDefaultClass2, thePointerClass, theMarkClass) {
 751      // 1. Pointer and mark feature are disabled or the browser can't get the
 752      //    row -> exits
 753      if ((thePointerClass == '' && theMarkClass == '')
 754          || typeof(theRow.style) == 'undefined') {
 755          return false;
 756      }
 757  
 758      var tagSwitch = null;
 759  
 760      // 2. Gets the current row and exits if the browser can't get it
 761      if (typeof(document.getElementsByTagName) != 'undefined') {
 762          tagSwitch = 'tag';
 763      } else if (typeof(document.getElementById('table_results')) != 'undefined') {
 764          tagSwitch = 'cells';
 765      } else {
 766          return false;
 767      }
 768  
 769      var theCells = null;
 770  
 771      if (tagSwitch == 'tag') {
 772          theRows     = document.getElementById('table_results').getElementsByTagName('tr');
 773          theCells    = theRows[1].getElementsByTagName('td');
 774      } else if (tagSwitch == 'cells') {
 775          theRows     = document.getElementById('table_results').rows;
 776          theCells    = theRows[1].cells;
 777      }
 778  
 779      // 3. Gets the current Class...
 780      var currentClass   = null;
 781      var newClass       = null;
 782  
 783      // 3.1 ... with DOM compatible browsers except Opera that does not return
 784      //         valid values with "getAttribute"
 785      if (typeof(window.opera) == 'undefined'
 786          && typeof(theCells[theColNum].getAttribute) != 'undefined') {
 787          currentClass = theCells[theColNum].className;
 788      } // end 3
 789  
 790      // 4. Defines the new Class
 791      // 4.1 Current Class is the default one
 792      if (currentClass == ''
 793          || currentClass.toLowerCase() == theDefaultClass1.toLowerCase()
 794          || currentClass.toLowerCase() == theDefaultClass2.toLowerCase()) {
 795          if (theAction == 'over' && thePointerClass != '') {
 796              newClass              = thePointerClass;
 797          } else if (theAction == 'click' && theMarkClass != '') {
 798              newClass              = theMarkClass;
 799              marked_row[theColNum] = true;
 800          }
 801      }
 802      // 4.1.2 Current Class is the pointer one
 803      else if (currentClass.toLowerCase() == thePointerClass.toLowerCase() &&
 804               (typeof(marked_row[theColNum]) == 'undefined' || !marked_row[theColNum]) || marked_row[theColNum] == false) {
 805              if (theAction == 'out') {
 806                  if (theColNum % 2) {
 807                      newClass              = theDefaultClass1;
 808                  } else {
 809                      newClass              = theDefaultClass2;
 810                  }
 811              }
 812              else if (theAction == 'click' && theMarkClass != '') {
 813                  newClass              = theMarkClass;
 814                  marked_row[theColNum] = true;
 815              }
 816      }
 817      // 4.1.3 Current Class is the marker one
 818      else if (currentClass.toLowerCase() == theMarkClass.toLowerCase()) {
 819          if (theAction == 'click') {
 820              newClass              = (thePointerClass != '')
 821                                    ? thePointerClass
 822                                    : ((theColNum % 2) ? theDefaultClass2 : theDefaultClass1);
 823              marked_row[theColNum] = false;
 824          }
 825      } // end 4
 826  
 827      // 5 ... with DOM compatible browsers except Opera
 828  
 829      if (newClass) {
 830          var c = null;
 831          var rowCnt = theRows.length;
 832          for (c = 0; c < rowCnt; c++) {
 833              if (tagSwitch == 'tag') {
 834                  Cells = theRows[c].getElementsByTagName('td');
 835              } else if (tagSwitch == 'cells') {
 836                  Cells = theRows[c].cells;
 837              }
 838  
 839              Cell  = Cells[theColNum];
 840  
 841              // 5.1 Sets the new Class...
 842              Cell.className = Cell.className.replace(currentClass, newClass);
 843          } // end for
 844      } // end 5
 845  
 846       return true;
 847   } // end of the 'setVerticalPointer()' function
 848  
 849  /**
 850   * Checks/unchecks all checkbox in given conainer (f.e. a form, fieldset or div)
 851   *
 852   * @param   string   container_id  the container id
 853   * @param   boolean  state         new value for checkbox (true or false)
 854   * @return  boolean  always true
 855   */
 856  function setCheckboxes( container_id, state ) {
 857      var checkboxes = document.getElementById(container_id).getElementsByTagName('input');
 858  
 859      for ( var i = 0; i < checkboxes.length; i++ ) {
 860          if ( checkboxes[i].type == 'checkbox' ) {
 861              checkboxes[i].checked = state;
 862          }
 863      }
 864  
 865      return true;
 866  } // end of the 'setCheckboxes()' function
 867  
 868  
 869  // added 2004-05-08 by Michael Keck <mail_at_michaelkeck_dot_de>
 870  //   copy the checked from left to right or from right to left
 871  //   so it's easier for users to see, if $cfg['ModifyAtRight']=true, what they've checked ;)
 872  function copyCheckboxesRange(the_form, the_name, the_clicked)
 873  {
 874      if (typeof(document.forms[the_form].elements[the_name]) != 'undefined' && typeof(document.forms[the_form].elements[the_name + 'r']) != 'undefined') {
 875          if (the_clicked !== 'r') {
 876              if (document.forms[the_form].elements[the_name].checked == true) {
 877                  document.forms[the_form].elements[the_name + 'r'].checked = true;
 878              }else {
 879                  document.forms[the_form].elements[the_name + 'r'].checked = false;
 880              }
 881          } else if (the_clicked == 'r') {
 882              if (document.forms[the_form].elements[the_name + 'r'].checked == true) {
 883                  document.forms[the_form].elements[the_name].checked = true;
 884              }else {
 885                  document.forms[the_form].elements[the_name].checked = false;
 886              }
 887         }
 888      }
 889  }
 890  
 891  
 892  // added 2004-05-08 by Michael Keck <mail_at_michaelkeck_dot_de>
 893  //  - this was directly written to each td, so why not a function ;)
 894  //  setCheckboxColumn(\'id_rows_to_delete' . $row_no . ''\');
 895  function setCheckboxColumn(theCheckbox){
 896      if (document.getElementById(theCheckbox)) {
 897          document.getElementById(theCheckbox).checked = (document.getElementById(theCheckbox).checked ? false : true);
 898          if (document.getElementById(theCheckbox + 'r')) {
 899              document.getElementById(theCheckbox + 'r').checked = document.getElementById(theCheckbox).checked;
 900          }
 901      } else {
 902          if (document.getElementById(theCheckbox + 'r')) {
 903              document.getElementById(theCheckbox + 'r').checked = (document.getElementById(theCheckbox +'r').checked ? false : true);
 904              if (document.getElementById(theCheckbox)) {
 905                  document.getElementById(theCheckbox).checked = document.getElementById(theCheckbox + 'r').checked;
 906              }
 907          }
 908      }
 909  }
 910  
 911  
 912  /**
 913    * Checks/unchecks all options of a <select> element
 914    *
 915    * @param   string   the form name
 916    * @param   string   the element name
 917    * @param   boolean  whether to check or to uncheck the element
 918    *
 919    * @return  boolean  always true
 920    */
 921  function setSelectOptions(the_form, the_select, do_check)
 922  {
 923      var selectObject = document.forms[the_form].elements[the_select];
 924      var selectCount  = selectObject.length;
 925  
 926      for (var i = 0; i < selectCount; i++) {
 927          selectObject.options[i].selected = do_check;
 928      } // end for
 929  
 930      return true;
 931  } // end of the 'setSelectOptions()' function
 932  
 933  /**
 934    * Inserts multiple fields.
 935    *
 936    */
 937  function insertValueQuery() {
 938      var myQuery = document.sqlform.sql_query;
 939      var myListBox = document.sqlform.dummy;
 940  
 941      if(myListBox.options.length > 0) {
 942          sql_box_locked = true;
 943          var chaineAj = "";
 944          var NbSelect = 0;
 945          for(var i=0; i<myListBox.options.length; i++) {
 946              if (myListBox.options[i].selected){
 947                  NbSelect++;
 948                  if (NbSelect > 1)
 949                      chaineAj += ", ";
 950                  chaineAj += myListBox.options[i].value;
 951              }
 952          }
 953  
 954          //IE support
 955          if (document.selection) {
 956              myQuery.focus();
 957              sel = document.selection.createRange();
 958              sel.text = chaineAj;
 959              document.sqlform.insert.focus();
 960          }
 961          //MOZILLA/NETSCAPE support
 962          else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
 963              var startPos = document.sqlform.sql_query.selectionStart;
 964              var endPos = document.sqlform.sql_query.selectionEnd;
 965              var chaineSql = document.sqlform.sql_query.value;
 966  
 967              myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
 968          } else {
 969              myQuery.value += chaineAj;
 970          }
 971          sql_box_locked = false;
 972      }
 973  }
 974  
 975  /**
 976    * listbox redirection
 977    */
 978  function goToUrl(selObj, goToLocation) {
 979      eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
 980  }
 981  
 982  /**
 983   * getElement
 984   */
 985  function getElement(e,f){
 986      if(document.layers){
 987          f=(f)?f:self;
 988          if(f.document.layers[e]) {
 989              return f.document.layers[e];
 990          }
 991          for(W=0;W<f.document.layers.length;W++) {
 992              return(getElement(e,f.document.layers[W]));
 993          }
 994      }
 995      if(document.all) {
 996          return document.all[e];
 997      }
 998      return document.getElementById(e);
 999  }
1000  
1001  /**
1002    * Refresh the WYSIWYG-PDF scratchboard after changes have been made
1003    */
1004  function refreshDragOption(e) {
1005      myid = getElement(e);
1006      if (myid.style.visibility == 'visible') {
1007          refreshLayout();
1008      }
1009  }
1010  
1011  /**
1012    * Refresh/resize the WYSIWYG-PDF scratchboard
1013    */
1014  function refreshLayout() {
1015          myid = getElement('pdflayout');
1016  
1017          if (document.pdfoptions.orientation.value == 'P') {
1018              posa = 'x';
1019              posb = 'y';
1020          } else {
1021              posa = 'y';
1022              posb = 'x';
1023          }
1024  
1025          myid.style.width = pdfPaperSize(document.pdfoptions.paper.value, posa) + 'px';
1026          myid.style.height = pdfPaperSize(document.pdfoptions.paper.value, posb) + 'px';
1027  }
1028  
1029  /**
1030    * Show/hide the WYSIWYG-PDF scratchboard
1031    */
1032  function ToggleDragDrop(e) {
1033      myid = getElement(e);
1034  
1035      if (myid.style.visibility == 'hidden') {
1036          init();
1037          myid.style.visibility = 'visible';
1038          myid.style.display = 'block';
1039          document.edcoord.showwysiwyg.value = '1';
1040      } else {
1041          myid.style.visibility = 'hidden';
1042          myid.style.display = 'none';
1043          document.edcoord.showwysiwyg.value = '0';
1044      }
1045  }
1046  
1047  /**
1048    * PDF scratchboard: When a position is entered manually, update
1049    * the fields inside the scratchboard.
1050    */
1051  function dragPlace(no, axis, value) {
1052      if (axis == 'x') {
1053          getElement("table_" + no).style.left = value + 'px';
1054      } else {
1055          getElement("table_" + no).style.top  = value + 'px';
1056      }
1057  }
1058  
1059  /**
1060   * Returns paper sizes for a given format
1061   */
1062  function pdfPaperSize(format, axis) {
1063      switch (format.toUpperCase()) {
1064          case '4A0':
1065              if (axis == 'x') return 4767.87; else return 6740.79;
1066              break;
1067          case '2A0':
1068              if (axis == 'x') return 3370.39; else return 4767.87;
1069              break;
1070          case 'A0':
1071              if (axis == 'x') return 2383.94; else return 3370.39;
1072              break;
1073          case 'A1':
1074              if (axis == 'x') return 1683.78; else return 2383.94;
1075              break;
1076          case 'A2':
1077              if (axis == 'x') return 1190.55; else return 1683.78;
1078              break;
1079          case 'A3':
1080              if (axis == 'x') return 841.89; else return 1190.55;
1081              break;
1082          case 'A4':
1083              if (axis == 'x') return 595.28; else return 841.89;
1084              break;
1085          case 'A5':
1086              if (axis == 'x') return 419.53; else return 595.28;
1087              break;
1088          case 'A6':
1089              if (axis == 'x') return 297.64; else return 419.53;
1090              break;
1091          case 'A7':
1092              if (axis == 'x') return 209.76; else return 297.64;
1093              break;
1094          case 'A8':
1095              if (axis == 'x') return 147.40; else return 209.76;
1096              break;
1097          case 'A9':
1098              if (axis == 'x') return 104.88; else return 147.40;
1099              break;
1100          case 'A10':
1101              if (axis == 'x') return 73.70; else return 104.88;
1102              break;
1103          case 'B0':
1104              if (axis == 'x') return 2834.65; else return 4008.19;
1105              break;
1106          case 'B1':
1107              if (axis == 'x') return 2004.09; else return 2834.65;
1108              break;
1109          case 'B2':
1110              if (axis == 'x') return 1417.32; else return 2004.09;
1111              break;
1112          case 'B3':
1113              if (axis == 'x') return 1000.63; else return 1417.32;
1114              break;
1115          case 'B4':
1116              if (axis == 'x') return 708.66; else return 1000.63;
1117              break;
1118          case 'B5':
1119              if (axis == 'x') return 498.90; else return 708.66;
1120              break;
1121          case 'B6':
1122              if (axis == 'x') return 354.33; else return 498.90;
1123              break;
1124          case 'B7':
1125              if (axis == 'x') return 249.45; else return 354.33;
1126              break;
1127          case 'B8':
1128              if (axis == 'x') return 175.75; else return 249.45;
1129              break;
1130          case 'B9':
1131              if (axis == 'x') return 124.72; else return 175.75;
1132              break;
1133          case 'B10':
1134              if (axis == 'x') return 87.87; else return 124.72;
1135              break;
1136          case 'C0':
1137              if (axis == 'x') return 2599.37; else return 3676.54;
1138              break;
1139          case 'C1':
1140              if (axis == 'x') return 1836.85; else return 2599.37;
1141              break;
1142          case 'C2':
1143              if (axis == 'x') return 1298.27; else return 1836.85;
1144              break;
1145          case 'C3':
1146              if (axis == 'x') return 918.43; else return 1298.27;
1147              break;
1148          case 'C4':
1149              if (axis == 'x') return 649.13; else return 918.43;
1150              break;
1151          case 'C5':
1152              if (axis == 'x') return 459.21; else return 649.13;
1153              break;
1154          case 'C6':
1155              if (axis == 'x') return 323.15; else return 459.21;
1156              break;
1157          case 'C7':
1158              if (axis == 'x') return 229.61; else return 323.15;
1159              break;
1160          case 'C8':
1161              if (axis == 'x') return 161.57; else return 229.61;
1162              break;
1163          case 'C9':
1164              if (axis == 'x') return 113.39; else return 161.57;
1165              break;
1166          case 'C10':
1167              if (axis == 'x') return 79.37; else return 113.39;
1168              break;
1169          case 'RA0':
1170              if (axis == 'x') return 2437.80; else return 3458.27;
1171              break;
1172          case 'RA1':
1173              if (axis == 'x') return 1729.13; else return 2437.80;
1174              break;
1175          case 'RA2':
1176              if (axis == 'x') return 1218.90; else return 1729.13;
1177              break;
1178          case 'RA3':
1179              if (axis == 'x') return 864.57; else return 1218.90;
1180              break;
1181          case 'RA4':
1182              if (axis == 'x') return 609.45; else return 864.57;
1183              break;
1184          case 'SRA0':
1185              if (axis == 'x') return 2551.18; else return 3628.35;
1186              break;
1187          case 'SRA1':
1188              if (axis == 'x') return 1814.17; else return 2551.18;
1189              break;
1190          case 'SRA2':
1191              if (axis == 'x') return 1275.59; else return 1814.17;
1192              break;
1193          case 'SRA3':
1194              if (axis == 'x') return 907.09; else return 1275.59;
1195              break;
1196          case 'SRA4':
1197              if (axis == 'x') return 637.80; else return 907.09;
1198              break;
1199          case 'LETTER':
1200              if (axis == 'x') return 612.00; else return 792.00;
1201              break;
1202          case 'LEGAL':
1203              if (axis == 'x') return 612.00; else return 1008.00;
1204              break;
1205          case 'EXECUTIVE':
1206              if (axis == 'x') return 521.86; else return 756.00;
1207              break;
1208          case 'FOLIO':
1209              if (axis == 'x') return 612.00; else return 936.00;
1210              break;
1211      } // end switch
1212  
1213      return 0;
1214  }


Généré le : Mon Nov 26 15:18:20 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics