Source for file DBMS_FIELD_SER_ARRAY.phpclass

Documentation is available at DBMS_FIELD_SER_ARRAY.phpclass

  1. <?php
  2. /**
  3.   * Class file DBMS_FIELD_SER_ARRAY.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms_field
  7.   * @category   string
  8.   *
  9.   * @author     Peter Krebs (pk)<p.krebs@lvus.at>
  10.   * @copyright  (c) 2002-2005 by LVUS <http://opencsp.lvu.at>
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   ***/
  14.  
  15. if (empty($GLOBALS['OCSP']['PHPFORMPATH'])) $GLOBALS['OCSP']['PHPFORMPATH']=dirname(__FILE__)."/";
  16.   
  17. if (!class_exists("DBMS_FIELD_SELECTLIST")) {
  18.     require_once dirname(__FILE__)."/DBMS_FIELD_SELECTLIST.phpclass";
  19. /**
  20.   * handle show readonly serilaized data in a table field
  21.   *
  22.   * this class can only be used for readonly fields
  23.   *
  24.   */
  25.     var $className       = "SerializedArray";
  26.     /**
  27.       * @var bool $showArrKeys show key,value par in a table
  28.       ***/
  29.     var $showArrKeys     = FALSE;
  30.     /**
  31.       * @var int $myValShowMode show mode (html-tag) of the value
  32.       * @version pk-03-10-10
  33.       ***/
  34.     var $myValShowMode=0;
  35.     /**
  36.       * @staticvar array $static_ValShowmodes values of show value mode
  37.       * @version pk-03-10-10
  38.       ***/
  39.     var $static_ValShowmodes=array(
  40.         0=>'asis',
  41.         1=>'pre',
  42.         2=>'textarea'
  43.     );
  44.  
  45.     /**
  46.         * source file of the class
  47.         *
  48.         * @var string $classSrcFile 
  49.         * @since pk-05-02-19
  50.         ***/
  51.     var $classSrcFile=__FILE__;    
  52.  
  53.     /**
  54.       * echos input form for field definition
  55.       *
  56.       * @version pk-03-10-10
  57.       *
  58.       * @todo input rows and cols for textarea mode
  59.       ***/
  60.     function editTblForm({
  61.         ?>
  62.             <tr>
  63.                 <td colspan="2" align="center" style="color:red"><b>ACHTUNG NUR READONLY VERWENDUNG</b></td>
  64.             </tr>
  65.         <?php
  66.         parent::editTblForm(FALSE,FALSE);
  67.         ?>
  68.             <tr>
  69.                 <td class="fldName">Keys Zeigen:</td>
  70.                 <td class="fldValue">
  71.                     <input name="showArrKeys" type="checkbox" <?php echo ($this->showArrKeys ? "checked" "")?> value="1"> Ja array Keys anzeigen
  72.                 </td>
  73.             </tr>
  74.             <tr>
  75.                 <td class="fldName">Value Anzeigemodus:</td>
  76.                 <td class="fldValue"><select name="myValShowMode" size="1">
  77.                     <?php
  78.                         foreach($this->static_ValShowmodes as $mode => $name{
  79.                             echo "<option value=\"".$mode."\" ";
  80.                             if ($this->myValShowMode == $modeecho " selected ";
  81.                             echo ">".$name."</option>";
  82.                         }
  83.                     ?>
  84.                 </select></td>
  85.             </tr>
  86.         <?php
  87.     }
  88.  
  89.     /**
  90.       * saves the field definition from $_POST array
  91.       *
  92.       * @version pk-03-10-10
  93.       ***/
  94.     function save({
  95.         $ret parent::save();
  96.  
  97.         $this->showArrKeys = (intval($_POST['showArrKeys']TRUE FALSE );
  98.         $this->myValShowMode = intval($_POST['myValShowMode']);
  99.  
  100.         return $ret;
  101.     }
  102.  
  103.     // ###################################
  104.  
  105.     /**
  106.       * echos the input html tag for the field
  107.       *
  108.       * the modes FRM_MODE_NEW and FRM_MODE_EDIT only returns FALSE
  109.       * no output is generated
  110.       *
  111.       * @param int $mode show mode of the field
  112.       * @param mixed $aValue value to show as field value
  113.       * @param string $arrName of the post array ($_POST[$arrName][$this->myName])
  114.       * @param bool $debug show debug info
  115.       * @return bool TRUE if a form field is echoed FALSE if there is no input to store
  116.       *
  117.       * @version pk-03-10-10
  118.       ***/
  119.     function writeField($mode,$aValue="",$arrName="DBVAL",$debug=FALSE{
  120.         switch($mode{
  121.             case FRM_MODE_READONLY:
  122.             case FRM_MODE_LIST:
  123.                 echo $this->getScreenValue($aValue,$arrName,$debug);
  124.                 return FALSE;
  125.             case FRM_MODE_NEW:      // no output
  126.             case FRM_MODE_EDIT:     // no output
  127.                 return FALSE;
  128.             default:
  129.                 return parent::writeField($mode,htmlspecialchars($val),$arrName);
  130.         }
  131.     }
  132.  
  133.     /**
  134.       * returns the html-code representation of $aValue
  135.       *
  136.       * if $aValue is an array a table code is returned
  137.       *
  138.       * @param mixed $aValue value of the field
  139.       * @param string $arrName name of the post array - not used
  140.       * @param bool $debug show debug information
  141.       * @return string html-code
  142.       *
  143.       * @version pk-03-10-10
  144.       ***/
  145.     function getScreenValue($aValue,$arrName="DBVAL",$debug=FALSE{
  146.         if (!empty($aValue)) {
  147.             $arr=@unserialize($aValue);
  148.             if (is_array($arr)) {
  149.  
  150.                 $ret="<table border='1' width='100%'>";
  151.  
  152.                 foreach($arr as $key => $val{
  153.                     $ret.="<tr>";
  154.                     if ($this->showArrKeys{
  155.                         $ret.="<td width='15%'><b>$key</b></td>";
  156.                     }
  157.                     $ret.="<td>";
  158.                     switch(intval($this->myValShowMode)) {
  159.                         case 1// pre
  160.                             $ret.="<pre>".htmlspecialchars($val."")."</pre>";   // $val."" to get string
  161.                             break;
  162.                         case 2// textarea
  163.                             $cols=25;
  164.                             $rows=ceil(strlen($val)/$cols);
  165.                             if ($rows 6$rows=6;
  166.                             $ret.="<textarea rows=\"".$rows."\" cols=\"".$cols."\" readonly class=\"pre\">";
  167.                             $ret.=htmlspecialchars($val."")// $val."" to get string
  168.                             $ret.="</textarea>";
  169.                             break;
  170.                         default:
  171.                             $ret.=htmlspecialchars($val."")// $val."" to get string
  172.                     }
  173.                     $ret.="</td>";
  174.                 }
  175.                 $ret.="</table>";
  176.                 return $ret;
  177.             else {
  178.                 return "";
  179.             }
  180.         else {
  181.             return "";
  182.         }
  183.     }
  184.  
  185. // end class DBMS_FIELD_ARRSELECTLIST
  186. ?>

Documentation generated on Thu, 08 Jan 2009 17:42:51 +0100 by phpDocumentor 1.4.0a2