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

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