DocMGR PHP Cross Reference Groupware Applications

Source: /lib/customforms.php - 607 lines - 18791 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*************************************************************************    
   4  //        FILE: customforms.php
   5  //
   6  // DESCRIPTION: Functions for creating Custom HTML form fields
   7  //              for entering information.
   8  //      
   9  //              Inlcudes forms for entering 
  10  //              Phone Numbers, Dates/Date Ranges, Time, Dropdown boxes
  11  //              ,and Checkboxes for employees
  12  //    CREATION
  13  //        DATE: 04-19-2006
  14  //
  15  //
  16  //     HISTORY:
  17  //
  18  //
  19  *************************************************************************/
  20  function phone($title,$name,$value,$format) {
  21  
  22      $posname = $name."_cursorpos";
  23  
  24      $string .= "<input type=hidden name=\"".$posname."\" id=\"".$posname."\">";
  25      
  26      if ($format=="table") $string .= "<tr><td align=right>";    
  27      
  28      $string .= "<div class=\"formHeader\">".$title."</div>";
  29  
  30      if ($format=="table") $string .= "</td><td>";    
  31  
  32      $value = trim($value);
  33  
  34      //tack on some spaces if there's no area code
  35      if (strlen($value)==7) $value = "   ".$value;
  36  
  37      if ($value) {
  38          
  39          /*  Split up the string form_home_phone string */
  40          
  41          $phone1_value = substr($value,0,3);
  42          $phone2_value = substr($value,3,3);
  43          $phone3_value = substr($value,6,4);
  44  
  45      }
  46  
  47      if (defined("READONLY")) {
  48          if ($phone3_value) $string .= "(".$phone1_value.") ".$phone2_value."-".$phone3_value;
  49      }
  50      else {    
  51          $string .= "    (<input  class=\"textbox\" type=text size=\"3\" MAXLENGTH=\"3\" name=\"".$name."1\" id=\"".$name."1\" \n";
  52          if (defined("KEYBOARD_FIRST_FIELD")) $string .= " onFocus=\"cursorStore('".$name."1');\" \n";
  53          $string .= "     value=\"".$phone1_value."\" 
  54                  onKeyDown=\"phoneJump(null,'".$name."1',null,'".$posname."','store');\"
  55                  onKeyUp=\"phoneJump(null,'".$name."1','".$name."2','".$posname."','set');\"
  56                  >) \n";
  57  
  58          $string .= "    <input  class=\"textbox\" type=text size=\"3\" MAXLENGTH=\"3\" name=\"".$name."2\" id=\"".$name."2\"";
  59          if (defined("KEYBOARD_FIRST_FIELD")) $string .= " onFocus=\"cursorStore('".$name."2');\"";
  60          $string .= "     value=\"".$phone2_value."\" 
  61                  onKeyDown=\"phoneJump(null,'".$name."2',null,'".$posname."','store');\"
  62                  onKeyUp=\"phoneJump('".$name."1','".$name."2','".$name."3','".$posname."','set');\"
  63                  >-";
  64  
  65          $string .= "    <input  class=\"textbox\" type=text size=\"4\" MAXLENGTH=\"4\" name=\"".$name."3\" id=\"".$name."3\"";
  66          if (defined("KEYBOARD_FIRST_FIELD")) $string .= " onFocus=\"cursorStore('".$name."3');\"";
  67           $string .= "     value=\"".$phone3_value."\" 
  68                  onKeyDown=\"phoneJump(null,'".$name."3',null,'".$posname."','store');\"
  69                  onKeyUp=\"phoneJump('".$name."2','".$name."3',null,'".$posname."','set');\"
  70                  >";
  71  
  72      }
  73  
  74      if ($format=="table") $string .= "        </td></tr> ";
  75      
  76      return $string;
  77      
  78  }
  79  /************************************************************************
  80  *************************************************************************/
  81  function createDropdown($optionArray) {
  82  
  83      $table = $optionArray["table"];                //the table we are querying
  84      $fieldName = $optionArray["fieldName"];        //the field name which is display in the dropdown
  85      $fieldValue = $optionArray["fieldValue"];    //the value of the dropdown option if diff from fieldName
  86      $limitField = $optionArray["limitField"];    //record limiter for teh query
  87      $limitValue = $optionArray["limitValue"];    //value we limit records to
  88      $value = $optionArray["value"];                //value of existing entry
  89      $name = $optionArray["name"];                //name of the form
  90      $conn = $optionArray["conn"];                //sql conn resource id
  91      $size = $optionArray["size"];                //size of the dropdown
  92      $nullValue = $optionArray["nullValue"];        //0 entry for dd
  93      $order = $optionArray["order"];                //order by
  94      $change = $optionArray["change"];            //dropdown change value
  95  
  96      if ($change) $changeValue = "onChange=\"".$change.";\"";
  97  
  98      //the fields we are looking for
  99      $query = $fieldName;
 100      if ($fieldValue) $query .= ",".$fieldValue;
 101  
 102      if (!$fieldValue) $fieldValue = $fieldName;
 103  
 104      $sql = "SELECT $query FROM $table";
 105      if ($limitField) $sql .= " WHERE $limitField = $limitValue ";
 106      if ($order) $sql .= " ORDER BY $order";
 107  
 108      $ddInfo = total_result($conn,$sql);
 109  
 110      $string = "<select name=\"".$name."\" id=\"".$name."\" size=\"".$size."\" ".$changeValue.">";
 111  
 112      if ($nullValue) $string .= "<option value=\"0\">".$nullValue;
 113  
 114      for ($row=0;$row<count($ddInfo[$fieldName]);$row++) {
 115  
 116          if ($value==$ddInfo[$fieldValue][$row]) $selected = " SELECTED ";
 117          else $selected = null;
 118  
 119          $string .= "<option value=\"".$ddInfo[$fieldValue][$row]."\" ".$selected.">".$ddInfo[$fieldName][$row];
 120  
 121      }
 122  
 123      $string .= "</select>";
 124  
 125      return $string;
 126  
 127  }
 128  /************************************************************************
 129  *************************************************************************/
 130  function dropdownGenerate($formInfo) {
 131  
 132      $conn = $formInfo["conn"];
 133      
 134      if (!$formInfo["form_id"]) $formInfo["form_id"] = $formInfo["form_name"];
 135      if (!$formInfo["form_size"]) $formInfo["form_size"] = "1";    
 136      if (!$formInfo["table"]) $formInfo["table"] = $formInfo["form_name"];
 137  
 138      $sql = "SELECT * FROM ".$formInfo["table"];
 139  
 140      if ($formInfo["filter"]) $sql .= " WHERE ".$formInfo["filter"];
 141  
 142      $sql .= " ORDER BY id";
 143  
 144      $list = total_result($conn,$sql);
 145  
 146      $content .= "<div class=\"formHeader\">";
 147      $content .= $formInfo["name"];
 148      $content .= "</div>";
 149  
 150      $content .= "<select     name=\"".$formInfo["form_name"]."\" 
 151                  id=\"".$formInfo["form_id"]."\" 
 152                  size=\"".$formInfo["form_size"]."\"";
 153  
 154      if ($formInfo["change"]) $content .= " onChange=\"".$formInfo["change"].";\" ";
 155      if ($formInfo["class"]) $content .= " class=\"".$formInfo["class"]."\" ";
 156  
 157      $content .= ">";
 158  
 159      for ($row=0;$row<count($formInfo["extraId"]);$row++) {
 160      
 161          if ($formInfo["cur_value"]==$formInfo["extraId"][$row]) $selected = " SELECTED ";
 162          else $selected = null;
 163  
 164          $content .= "<option ".$selected." value=\"".$formInfo["extraId"][$row]."\">".$formInfo["extraName"][$row];
 165  
 166      }
 167  
 168      for ($row=0;$row<count($list["id"]);$row++) {
 169  
 170          if ($formInfo["cur_value"]==$list["id"][$row]) $selected = " SELECTED ";
 171          else $selected = null;
 172  
 173          $content .= "<option ".$selected." value=\"".$list["id"][$row]."\">".$list["name"][$row];
 174  
 175      }
 176  
 177      $content .= "</select>";
 178  
 179      return $content;
 180  
 181  }
 182  /************************************************************************
 183  *************************************************************************/
 184  function dateRange($name) {
 185  
 186      $content .= "From&nbsp;";
 187      $content .= dateFormSelect(null,$name."Begin",null);
 188          $content .= "&nbsp;&nbsp;";
 189          $content .= "To&nbsp;";
 190      $content .= dateFormSelect(null,$name."End",null);
 191                          
 192      return $content;
 193  
 194  }
 195  /************************************************************************
 196  *************************************************************************/
 197  function timeForm($formInfo) {
 198  
 199      $content = "<div class=\"formHeader\">";
 200      $content .= $formInfo["name"];
 201      $content .= "</div>";
 202  
 203      $time = explode(":",$formInfo["cur_value"]);
 204  
 205      $hour = $time[0];
 206      $minute = $time[1];
 207  
 208      if ($hour>="12") $pmSelect = " SELECTED ";
 209      else $amSelect = " SELECTED ";;
 210  
 211      if ($hour>12) $hour = $hour - 12;
 212  
 213      $name = $formInfo["form_name"];
 214  
 215      if (!$formInfo["form_id"]) $formInfo["form_id"] = $formInfo["form_name"];
 216  
 217      $content .= "<input     type=text 
 218                  size=2 
 219                  maxlength=2 
 220                  name=\"".$formInfo["form_name"]."Hour\" 
 221                  id=\"".$formInfo["form_id"]."Hour\"
 222                  value=\"".$hour."\"
 223                  onKeyUp=\"dateJump('".$name."Hour','".$name."Minute');\"
 224                  >";
 225      $content .= ":";
 226      $content .= "<input     type=text 
 227                  size=2
 228                  maxlength=2 
 229                  name=\"".$formInfo["form_name"]."Minute\" 
 230                  id=\"".$formInfo["form_id"]."Minute\"
 231                  value=\"".$minute."\"
 232                  onKeyUp=\"dateJump('".$name."Minute','".$name."Period');\"
 233                  >";
 234      $content .= "&nbsp;";
 235      $content .= "<select     name=\"".$formInfo["form_name"]."Period\"
 236                  id=\"".$formInfo["form_name"]."Period\"
 237                  size=1>";
 238  
 239      $content .= "<option value=\"am\" ".$amSelect.">A.M.";
 240      $content .= "<option value=\"pm\" ".$pmSelect.">P.M.";
 241      $content .= "</select>";
 242      
 243      return $content;
 244  
 245  }
 246  /************************************************************************
 247  *************************************************************************/
 248  function stateForm($conn,$name,$curValue,$disabled = null) {
 249  
 250      $sql = "SELECT * FROM state ORDER BY abbr";
 251      $list = list_result($conn,$sql);
 252      
 253      if ($disabled) $disabled = " DISABLED ";
 254      
 255      $str = "<select name=\"".$name."\" id=\"".$name."\" size=1 $disabled>
 256          <option value=\"\">Select State
 257          ";
 258      
 259      for ($i=0;$i<$list["count"];$i++) {
 260      
 261          if ($list[$i]["abbr"]==$curValue) $select = " SELECTED ";
 262          else $select = NULL;
 263      
 264          $str .= "<option value=\"".$list[$i]["abbr"]."\" ".$select.">".$list[$i]["abbr"]."\n";
 265          
 266      }
 267      
 268      $str .= "</select>\n";
 269      
 270      return $str;
 271  
 272  }
 273  /************************************************************************
 274  *************************************************************************/
 275  function countryForm($conn,$name,$curValue,$disabled = null) {
 276  
 277      $sql = "SELECT * FROM country";
 278      $list = list_result($conn,$sql);
 279      
 280      if ($disabled) $disabled = " DISABLED ";
 281      
 282      $str = "<select name=\"".$name."\" id=\"".$name."\" size=1 $disabled style=\"width:150px\">
 283          <option value=\"\">Select Country
 284          ";
 285      
 286      for ($i=0;$i<$list["count"];$i++) {
 287      
 288          if ($list[$i]["id"]==$curValue) $select = " SELECTED ";
 289          else $select = NULL;
 290      
 291          $str .= "<option value=\"".$list[$i]["id"]."\" ".$select.">".$list[$i]["printable_name"]."\n";
 292          
 293      }
 294      
 295      $str .= "</select>\n";
 296      
 297      return $str;
 298  
 299  }
 300  /************************************************************************
 301  *************************************************************************/
 302  function salutationForm($conn,$name,$curValue,$disabled = null) {
 303  
 304      $sql = "SELECT * FROM salutation";
 305      $list = list_result($conn,$sql);
 306      
 307      if ($disabled) $disabled = " DISABLED ";
 308      
 309      $str = "<select name=\"".$name."\" id=\"".$name."\" size=1 $disabled style=\"width:150px\">
 310          <option value=\"\">Select Salutation
 311          ";
 312      
 313      for ($i=0;$i<$list["count"];$i++) {
 314      
 315          if ($list[$i]["id"]==$curValue) $select = " SELECTED ";
 316          else $select = NULL;
 317      
 318          $str .= "<option value=\"".$list[$i]["id"]."\" ".$select.">".$list[$i]["name"]."\n";
 319          
 320      }
 321      
 322      $str .= "</select>\n";
 323      
 324      return $str;
 325  
 326  }
 327  /************************************************************************
 328  *************************************************************************/
 329  function dateDisplay($prefix,$header,$date) {
 330  
 331      if (!$date) $date = date("Y-m-d");
 332  
 333      $dateArray = explode("-",$date);
 334      $monthValue = $dateArray[1];
 335      $dayValue = $dateArray[2];
 336      $yearValue = $dateArray[0];
 337  
 338      $string = "<div class=\"formHeader\">".$header."</div>
 339              <SELECT name=\"".$prefix."_month\" id=\"".$prefix."_month\" onChange=\"fixDay('".$prefix."');\">
 340              ";
 341  
 342      for ($row=1;$row<=12;$row++) {
 343          if ($monthValue == $row) $selected = " SELECTED ";
 344          else $selected = null;
 345          $string .= "<option value=".$row." ".$selected.">".date("M",mktime(0,0,0,$row,1,0));
 346      }
 347  
 348      $string .= "</SELECT>
 349                  &nbsp;
 350                  <select name=\"".$prefix."_day\" id=\"".$prefix."_day\">";
 351  
 352      for ($row=1;$row<=31;$row++) {
 353              if ($dayValue == $row) $selected = " SELECTED ";
 354              else $selected = null;
 355              $string .= "<OPTION value=\"".$row."\" ".$selected.">".$row;
 356      }
 357  
 358  
 359      $string .= "</SELECT>
 360                  &nbsp;
 361                  <SELECT name=\"".$prefix."_year\">
 362                  ";
 363  
 364      $date_loop=date(Y)-1;
 365      $date_loop_end=$date_loop+3;
 366  
 367      for ($row=$date_loop;$row<$date_loop_end;$row++) {
 368              if ($yearValue == $row) $selected = " SELECTED ";
 369              else $selected = null;
 370              $string .= "<OPTION value=\"".$row."\" ".$selected.">".$row;
 371      }
 372  
 373      $string .= "</select>";
 374  
 375      return $string;
 376  
 377  }
 378  /************************************************************************
 379  *************************************************************************/
 380  function dateForm($title,$name,$value) {
 381  
 382      if (defined("DATE_FORMAT")) $layout = DATE_FORMAT;
 383      else $layout = "mm/dd/yyyy";
 384      $layout = strtoupper($layout);
 385  
 386      if ($title) $string .= "<div class=\"formHeader\">".$title."</div>";
 387  
 388      $value = trim($value);
 389  
 390      if ($value) $value = date_view($value,"slash");
 391  
 392      $string .= "<input     class=\"textbox\" 
 393                      type=text 
 394                      name=\"".$name."\" 
 395                      id=\"".$name."\" 
 396                      value=\"".$value."\"
 397                      >";
 398  
 399      return $string;
 400      
 401  }
 402  /************************************************************************
 403  //loads a date form with a popup calendar select
 404  *************************************************************************/
 405  function dateFormSelect($header,$formName,$formValue,$readonly = null,$event = null,$formHeader = null) {
 406  
 407      //assemble our form
 408      $str = null;
 409      
 410      if ($header) {
 411  
 412          if (!$formHeader) $formHeader = "formHeader";
 413  
 414          $str = "<div class=\"formHeader\">
 415              ".$header."
 416            </div>
 417            ";
 418    }
 419          
 420    $str .= "
 421          <input type=text size=10 ".$readonly." name=\"".$formName."\" id=\"".$formName."\" ".$event." value=\"".$formValue."\">
 422  
 423          <script type=\"text/javascript\">
 424      new Picker.Date(ge('".$formName."'), {
 425            timePicker: false,
 426                  positionOffset: {x: 5, y: 0},   
 427                        pickerClass: 'datepicker_vista',
 428                              useFadeInOut: !Browser.ie
 429                                  });
 430                                  </script>
 431          ";
 432  
 433      return $str;
 434  
 435  }
 436  /************************************************************************
 437  *************************************************************************/
 438  function dateTimeFormSelect($header,$formName,$formValue,$readonly="READONLY") {
 439  
 440      //extend the form name to the name of our button
 441      $btnName = $formName."Btn";
 442  
 443      //assemble our form
 444      $str = "<div class=\"formHeader\">
 445          ".$header."
 446          </div>
 447          <input type=text size=20 ".$readonly." name=\"".$formName."\" id=\"".$formName."\" value=\"".$formValue."\">
 448          <input type=button name=\"".$btnName."\" id=\"".$btnName."\" value=\"...\">
 449          ";
 450  
 451      //call our js function and setup loaders
 452      $str .= jsCalLoad();
 453      $str .= jsCalSetup($formName,$btnName,1);
 454  
 455      return $str;
 456  
 457  }
 458  /************************************************************************
 459  //loads the required javascript files for our calendar to work
 460  *************************************************************************/
 461  function jsCalLoad() {
 462  
 463      //get out if this has already been loaded
 464      if (defined("JSCAL_LOADED")) return false;
 465  
 466      //make sure this doesn't get loaded again
 467      define("JSCAL_LOADED","1");
 468  
 469      $str = "
 470        <!-- calendar stylesheet -->
 471        <link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"javascript/calendar/skins/aqua/theme.css\" title=\"Aqua\" >
 472  
 473        <!-- main calendar program -->
 474        <script type=\"text/javascript\" src=\"javascript/calendar/calendar.js\"></script>
 475  
 476        <!-- language for the calendar -->
 477        <script type=\"text/javascript\" src=\"javascript/calendar/lang/calendar-en.js\"></script>
 478  
 479        <!-- the following script defines the Calendar.setup helper function, which makes
 480         adding a calendar a matter of 1 or 2 lines of code. -->
 481        <script type=\"text/javascript\" src=\"javascript/calendar/calendar-setup.js\"></script>
 482  
 483      ";
 484      
 485      return $str;
 486      
 487  }
 488  /************************************************************************
 489  //sets up the calendar to work with a specific input field or id, which
 490  //is passed as the first parameter
 491  *************************************************************************/
 492  function jsCalSetup($formName,$btnName,$showTime = null) {
 493  
 494      //get our date format from the define if set
 495      if (defined("DATE_FORMAT")) $dateFormat = strtolower(DATE_FORMAT);
 496      else $dateFormat = "mm/dd/yyyy";
 497  
 498      //rewrite our php format to work with javascript
 499      $dateFormat = str_replace("mm","%m",$dateFormat);
 500      $dateFormat = str_replace("dd","%d",$dateFormat);
 501      $dateFormat = str_replace("yyyy","%Y",$dateFormat);
 502  
 503      //allow time selection as well if desired
 504      if ($showTime) {
 505          $setupStr = "ifFormat       :    \"".$dateFormat." %I:%M %p\",       // format of the input field\n";
 506              $setupStr .= "showsTime      :    true,            // will display a time selector\n";
 507      }
 508      else {
 509          $setupStr = "ifFormat    :    \"".$dateFormat."\",\n";
 510      }
 511  
 512      //output our setup string
 513      $str = "
 514  
 515      <script type=\"text/javascript\">
 516          Calendar.setup({
 517              inputField         :    \"".$formName."\",      // id of the input field
 518          ".$setupStr."
 519              button             :    \"".$btnName."\",   // trigger for the calendar (button ID)
 520              singleClick        :    true,           // double-click mode
 521              step               :    1                // show all years in drop-down boxes (instead of every other year as default)
 522          });
 523      </script>
 524  
 525      ";
 526      
 527      return $str;
 528  
 529      /* other options for the calendar
 530      */
 531  
 532  }
 533  /*********************************************************
 534  *********************************************************/
 535  function functionMenu($tableName,$nameList,$functionList) {
 536  
 537      if (BROWSER=="gecko") $leave = "onBlur=\"document.getElementById('".$tableName."').style.visibility='hidden';\"";
 538      else $leave="onMouseLeave=\"hideFunctionMenu('".$tableName."',event);\"";
 539  
 540      $string = "<div id=\"".$tableName."\" ".$leave." 
 541              style=\"visibility:hidden;position:absolute\" 
 542              class=\"functionMenu\">  ";
 543  
 544      for ($row=0;$row<count($nameList);$row++) {
 545  
 546          $id = $tableName."Cell".$row;
 547  
 548          $string .= "
 549              <div id=\"".$id."\" class=\"functionMenuCell\"
 550                      onMouseOver=\"changeStyle('".$id."','highlight');\"
 551                      onMouseOut=\"changeStyle('".$id."','normal');\"
 552                      unselectable=\"on\"
 553                      onclick=\"".$functionList[$row].";\"
 554                      >
 555                  ".$nameList[$row]."
 556              </div>
 557              ";
 558      }
 559  
 560      $string .= "</table></div>";
 561  
 562      return $string;
 563  
 564  }
 565  
 566  /***********************************************************
 567    createPermCheckbox
 568    Displays a checkbox form with all permissions that
 569    can be set for a user
 570  ***********************************************************/
 571  function createPermCheckbox($bitValue) {
 572  
 573    $permArray = $_SESSION["definePermArray"];
 574  
 575    for ($row=0;$row<count($permArray["name"]);$row++) {
 576  
 577      $bitSet = bitCal($permArray["bitpos"][$row]);
 578  
 579      //only display the permissions our user is already allowed
 580      if (bitset_compare(BITSET,$bitSet,ADMIN)) {
 581  
 582        if ($bitValue & $bitSet) $checked = " CHECKED ";
 583        else $checked = null;
 584  
 585        $permlang = "_PERM_".$permArray["define_name"][$row];
 586  
 587        if (defined($permlang)) $permText = constant($permlang);
 588        else $permText = $permArray["name"][$row];
 589  
 590        $permString .= "<li style=\"list-style-type:none\">";
 591        $permString .= "<input  type=checkbox
 592                                name=\"perm[]\"
 593                                id=\"perm[]\"
 594                                value=\"".bitCal($permArray["bitpos"][$row])."\"
 595                                ".$checked."
 596                                >&nbsp;";
 597        $permString .= $permText;
 598        $permString .= "</li>";
 599  
 600      }
 601  
 602    }
 603  
 604    return $permString;
 605  }
 606  
 607  //END FILE

title

Description

title

Description

title

Description

title

title

Body