Source for file DBMS_FIELD_STATUS_CONFARR_SELECT.phpclass

Documentation is available at DBMS_FIELD_STATUS_CONFARR_SELECT.phpclass

  1. <?php
  2. /**
  3.   * Class file DBMS_FIELD_STATUS_CONFARR_SELECT.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms_field
  7.   * @category   int
  8.   *
  9.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  10.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  11.   *
  12.   * @version $Id:$
  13.   */
  14.  
  15.     pcf_require_class('DBMS_FIELD_GLOBALARRSELECTLIST',"db/frmClasses/");
  16.  
  17.  
  18. /**
  19.   * Class DBMS_FIELD_STATUS_CONFARR_SELECT
  20.   *
  21.   * @project    Open CSP-Management
  22.   * @package    dbms_field
  23.   * @category   int
  24.   *
  25.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  26.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  27.   *
  28.   * @since      pk-03-12-16
  29.   *
  30.   * @version    pk-05-08-02
  31.   * @version    $Id:$
  32.   *
  33.   * @todo       only checked when form is shown no check is done for
  34.   *              this::slashedValue() and this::getValue() needs a major
  35.   *              change in the dbms function calls
  36.   *
  37.   ***/
  38.     /**
  39.       * source file of the class
  40.       *
  41.       * @var string $classSrcFile 
  42.       * @since pk-06-07-24
  43.       ***/
  44.     var $classSrcFile=__FILE__;
  45.  
  46.     /**
  47.       * @var string $className 
  48.       ***/
  49.     var $className       = "SelectGlobalStatusArr";
  50.  
  51.     // ###########################################################
  52.     // OBJECT (CONST) VAR DECLARATION
  53.     // ###########################################################
  54.  
  55.     /**
  56.       * @var string $grpKey index to look for the group
  57.       ***/
  58.     var $grpKey          = "GROUP";
  59.     /**
  60.       * @var string $iconKey index to look for the icon
  61.       ***/
  62.     var $iconKey         = "ICON";
  63.     /**
  64.       * @var string $requireValueKey index to look for the required value
  65.       ***/
  66.     var $requireValueKey = "REQVAL";
  67.  
  68.     // ###########################################################
  69.     // FIELD DEFINITION DATA METHODS
  70.     // ###########################################################
  71.  
  72.     /**
  73.       * returns an array of field to bie shown in the edit form
  74.       * by using editTbl_echoForm
  75.       *
  76.       * the array is in the form:
  77.       *
  78.       * <code>
  79.       * [_sectionName_]
  80.       *      [TITLE] -> string
  81.       *      [_rowName_]
  82.       *         [FLDLAB]  (complete html code with <td></td>)
  83.       *         [FLDVAL] (complete html code with <td></td>)
  84.       * </code>
  85.       *
  86.       * @param boolean $debug 
  87.       *
  88.       * @returns array
  89.       *
  90.       * @since pk-06-07-24
  91.       *
  92.       ***/
  93.     function editTbl_getFieldEditArr($debug=FALSE{
  94.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_DBSELECTLIST::editTbl_getFieldEditArr","",0);
  95.         $a_ret=parent::editTbl_getFieldEditArr($debug);
  96.  
  97.         unset($a_ret['SELECT']['FLD_LSTVALS'])// unset parent field as it is of no use here
  98.  
  99.         $a_ret['STATUSARR']=array(
  100.             'TITLE'=>"Status Einstellungen/Berechtigungen",
  101.             'ISHIDDEN' => FALSE,
  102.             'FLD_GRPKEY'=>array(
  103.                 'FLDLAB'=>"GROUP INDEX",
  104.                 'FLDVAL'=>"<input name=\"grpKey\" value=\"".$this->grpKey."\" size=\"40\">"
  105.             ),
  106.             'FLD_ICONKEY'=>array(
  107.                 'FLDLAB'=>"REQUIRE VALUE INDEX",
  108.                 'FLDVAL'=>"<input name=\"requireValueKey\" value=\"".$this->requireValueKey."\" size=\"40\">"
  109.             ),
  110.             'FLD_REQUIREDKEY'=>array(
  111.                 'FLDLAB'=>"ICON INDEX",
  112.                 'FLDVAL'=>"<input name=\"iconKey\" value=\"".$this->iconKey."\" size=\"40\">"
  113.             ),
  114.         );
  115.  
  116.         return $a_ret;
  117.     }
  118.  
  119.     /**
  120.       * @return boolean 
  121.       *
  122.       * @version pk-05-08-02
  123.       *
  124.       ***/
  125.     function save({
  126.         $ret parent::save();
  127.         $this->grpKey           =$_POST['grpKey'];
  128.         $this->iconKey          =$_POST['iconKey'];
  129.         $this->requireValueKey  =$_POST['requireValueKey'];
  130.  
  131.         return $ret;
  132.     }
  133.  
  134.     ###################################
  135.  
  136.     /**
  137.       * returns if we have to check the array for group and required value
  138.       *
  139.       * @param int $mode 
  140.       *
  141.       * @return boolean; 
  142.       *
  143.       * @since pk-05-08-02
  144.       *
  145.       ***/
  146.     function globalArrIsToCheck($mode,$debug{
  147.         if ($debugecho "<p><b>DBMS_FIELD_STATUS_CONFARR_SELECT::globalArrIsToCheck($mode)</b> (".get_class($this).")</p>\n";
  148.         switch($mode{
  149.             case FRM_MODE_NEW:
  150.             case FRM_MODE_EDIT:
  151.             case FRM_MODE_HIDDEN:
  152.                 return TRUE;            // input fields -> we need to check
  153.             case FRM_MODE_LIST:
  154.             case FRM_MODE_READONLY:
  155.                 return FALSE;           // no need to check for readonly modes
  156.             default:
  157.                 if ($debugecho "<p>UNKNOWN MODE$mode</p>";
  158.                 return TRUE;
  159.         }
  160.     }
  161.  
  162.     /**
  163.       * returns if the user is member of the grpKey groups
  164.       *
  165.       * @param array $globalValArr the subarray in the global array
  166.       * @param boolean $debug 
  167.       *
  168.       * @return boolean 
  169.       *
  170.       * @since pk-05-08-02
  171.       * @version pk-06-07-24
  172.       *
  173.       ***/
  174.     function check_globalArrGroup($globalValArr,$debug=FALSE{
  175.         if ($debugecho "<p><b>DBMS_FIELD_STATUS_CONFARR_SELECT::check_globalArrGroup(...)</b> (".get_class($this).")</p>";
  176.  
  177.         if (empty($this->grpKey)) return TRUE// group net set -> no check
  178.  
  179.         if (!isset($globalValArr[$this->grpKey])) {
  180.             // we do not have a group key in the array => return TRUE
  181.             return TRUE;
  182.         }
  183.  
  184.         if (is_array($globalValArr[$this->grpKey])) {
  185.             // we have an array of groups which are allowed
  186.             foreach($globalValArr[$this->grpKeyas $i_GrpId{
  187.                 if ($GLOBALS['USER']->isGroupMember($i_GrpId)) return TRUE// user is member
  188.             }
  189.             // still here -> no group found
  190.             return FALSE;
  191.         else {
  192.             // we have a single value
  193.             // use intval to have public (0) if no group is set
  194.             return $GLOBALS['USER']->isGroupMember(intval($globalValArr[$this->grpKey]));
  195.         }
  196.     }
  197.  
  198.     /**
  199.       * returns if the global array $arrName as the required value
  200.       *
  201.       * @param array $globalValArr 
  202.       * @param string $arrName 
  203.       * @param boolean $debug 
  204.       *
  205.       * @return boolean 
  206.       *
  207.       * @since pk-05-08-02
  208.       * @version pk-06-07-24
  209.       *
  210.       ***/
  211.     function check_globalArrReqValue($globalValArr,$arrName="DBVAL",$debug=FALSE{
  212.         if ($debugecho "<p><b>DBMS_FIELD_STATUS_CONFARR_SELECT::check_globalArrReqValue(...)</b> (".get_class($this).")</p>";
  213.  
  214.         if (empty($this->requireValueKey)) return TRUE// no requireValueKey set -> no check
  215.  
  216.         if (!isset($globalValArr[$this->requireValueKey])) // <pk-06-07-24>
  217.             // we do not have a require value key in the array => return TRUE
  218.             return TRUE;
  219.         }
  220.  
  221.         global ${$arrName};
  222.  
  223.         if ($debugecho "<p>Global Array (\$".$arrName."):</p><pre>".print_r(${$arrName}[$this->myName])."</pre>";
  224.         if (is_array($globalValArr[$this->requireValueKey])) {
  225.             foreach($globalValArr[$this->requireValueKeyas $chkVal{
  226.                 if ($chkVal==${$arrName}[$this->myName]return TRUE;   // value found
  227.             }
  228.             // still here -> value not found
  229.             return FALSE;
  230.         else if (!empty($globalValArr[$this->requireValueKey])) {
  231.             if ($globalValArr[$this->requireValueKey]==${$arrName}[$this->myName]return TRUE;
  232.             else return FALSE;
  233.         else {
  234.             return TRUE;
  235.         }
  236.     }
  237.  
  238.     /**
  239.       * returns an array of allowed values
  240.       *
  241.       * if mode is FRM_MODE_EDIT, FRM_MODE_NEW or FRM_MODE_HIDDEN
  242.       * for eache array ellement is checkt if
  243.       * the curent user ($GLOBALS['USER'])
  244.       * is member of the group (ID specified by
  245.       * $this::grpKey)
  246.       *
  247.       * @example config include file
  248.       *
  249.       *  Setting fixed Number:
  250.       *  <code>
  251.       *      $GLOBALS['CMS']['PAGESTATE'][0]=array(
  252.       *          ...
  253.       *          'GROUP'=>0):
  254.       *  </code>
  255.       *
  256.       *  Setting to a variable (note the value when the conf file is included is checked
  257.       *  <code>
  258.       *      $GLOBALS['CMS']['PAGESTATE'][1]=array(
  259.       *          ...
  260.       *          'GROUP'=>$GLOBALS['GROUPS']['CMSAUTHOR']);
  261.       *  </code>
  262.       *
  263.       *  you can also reference to a global var
  264.       *  <code>
  265.       *      $GLOBALS['CMS']['PAGESTATE'][1]=array(
  266.       *          ...
  267.       *          'GROUP'=><b>&</b>$GLOBALS['GROUPS']['AKT_PROJADMIN']
  268.       *  </code>
  269.       *
  270.       *  or simply set to an array
  271.       *  <code>
  272.       *      $GLOBALS['CMS']['PAGESTATE'][1]=array(
  273.       *          ...
  274.       *          'GROUP'=>array(1,2));
  275.       *  </code>
  276.       *
  277.       * @param string $arrName 
  278.       * @param bool $debug 
  279.       * @parma int $mode
  280.       *
  281.       * @return array 
  282.       *
  283.       * @version pk-05-08-03
  284.       *
  285.       * @var array $a_globalArr 
  286.       * @var mixed $key 
  287.       * @var array $a_globalValArr 
  288.       * @var boolean $b_SetValue 
  289.       *
  290.       ***/
  291.     function setMyValues($arrName="DBVAL",$debug=FALSE,$mode=FRM_MODE_EDIT{
  292.         $debug=($debug || $this->fldDebug);
  293.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_STATUS_CONFARR_SELECT::setMyValues()");
  294.  
  295.         global ${$arrName}// <pk-05-08-03 />
  296.         
  297.         $this->allowNull = False// to have the first state selected if no value is submitted    
  298.         $this->myValues     = array();
  299.         
  300.         switch(True)  // <pk-08-12-18>
  301.         {
  302.             case strstr($this->arrName,"CHAPTERSTATE"):
  303.                 pcf_require_class('CMS_CHAPTER_STATE',"cms/chapter/");
  304.                 $arr_states CMS_CHAPTER_STATE::getAllStates();
  305.                 foreach($arr_states as &$obj_state)
  306.                 {
  307.                     if ($obj_state->curUserIsInGroup(intval(${$arrName}['PROJ_ID'])))
  308.                     {
  309.                            $this->myValues[$obj_state->getId()$obj_state->getName();
  310.                        }
  311.                 }
  312.                 break;
  313.             default:
  314.                 if ((!empty($this->subKey)) && ($a_globalArr=$this->getGlobalValArr($debug)) && (is_array($a_globalArr))) {
  315.                     $this->myValues=array()// <pk-06-10-04 />
  316.                     foreach($a_globalArr as $key => $a_globalValArr{
  317.                         if ($debugecho "<p>Checking: ".$a_globalValArr[$this->subKey]." ($key)</p><blockquote>";
  318.                         if (is_array($a_globalValArr)) {
  319.                             $b_SetValue=FALSE;
  320.                             if (isset(${$arrName}[$this->myName]&& (${$arrName}[$this->myName== $key)) // <pk-05-08-03 />
  321.                                 // no need to check as we already have this state
  322.                                 $b_SetValue=TRUE;
  323.                             else if ($this->globalArrIsToCheck($mode,$debug)) {
  324.                                 if ($this->check_globalArrReqValue($a_globalValArr,$arrName,$debug)) {
  325.                                     if ($this->check_globalArrGroup($a_globalValArr,$debug)) {
  326.                                         $b_SetValue=TRUE;
  327.                                     }
  328.                                 }
  329.                             else {
  330.                                 $b_SetValue=TRUE;
  331.                             }
  332.         
  333.                             if ($b_SetValue{
  334.                                 if ($debugecho "<p>Setting Value: ".$a_globalValArr[$this->subKey]." ($key)</p>";
  335.                                 if (($mode==FRM_MODE_LIST&& (!empty($a_globalValArr[$this->iconKey]))) {
  336.                                     if ($debug{echo "<blockquote>ICON SET<pre>$key ".$this->iconKey."\n";print_r($a_globalValArr);echo "</pre><p>".$a_globalValArr[$this->iconKey]."</blockquote>";}
  337.                                     $this->myValues[$key]="<img src=\"".$a_globalValArr[$this->iconKey]."\" border=\"0\" align=\"middle\" alt=\"".$a_globalValArr[$this->subKey]."\">";
  338.                                 else {
  339.                                     if (!empty($a_globalValArr[$this->subKey])) {
  340.                                         $this->myValues[$key]=$a_globalValArr[$this->subKey];
  341.                                     else {
  342.                                         $this->myValues[$key]=$key;
  343.                                     }
  344.                                 }
  345.                             }
  346.                         }
  347.                         if ($debugecho "</blockquote>";
  348.                     }
  349.                     if ($debugecho "<blockquote>myValues:<pre>".print_r($this->myValues,TRUE)."</pre><hr /></blockquote>";
  350.                 else {
  351.                     if ($debugecho "<p>subKey NOT SET </p>";
  352.                 }
  353.           }            
  354.     }
  355.  
  356.     /**
  357.       * returns a string with the options
  358.       * if
  359.       *
  360.       * calls setMyValues to be sure $this->myValues is set correkt
  361.       *
  362.       * @param array $aValArr   array of selected values
  363.       * @param bool $addNULL    add the null option (for search)
  364.       * @param bool $debug 
  365.       *
  366.       * @return string 
  367.       *
  368.       * @since pk-05-02-17
  369.       *
  370.       ***/
  371.     function getOptionList($aValArr,$addNULL=FALSE,$debug=FALSE{
  372.        $debug=($debug || $this->fldDebug);
  373.         if ($debug{
  374.             echo "<p><b>DBMS_FIELD_STATUS_CONFARR_SELECT::getOptionList(\$aValArr,$addNULL,...)</b> (".get_class($this)."/".$this->myName.")</p>";
  375.             echo "<blockquote><p>\$aValArr</p><pre>".print_r($aValArr,TRUE)."</pre></blockquote>";
  376.         }
  377.         $this->setMyValues($this->myDataArrName,$debug);
  378.         $ret="";
  379.  
  380.         if ($addNULL{
  381.             $ret.="\t<option value=\"\">".$this->nullLabel."</option>\n";
  382.         }
  383.         if ($debugecho "<pre>".print_r($this->myValues,TRUE)."</pre>";
  384.         if (is_array($this->myValues)) {
  385.             reset($this->myValues);
  386.             while(list($key,$val)=each($this->myValues)) {
  387.                 $ret.="\t<option value=\"$key\"";
  388.                 if ((!empty($key)) && in_array($key,$aValArr)) {
  389.                     $ret .= " selected";
  390.                     unset($aValArr[$key]);
  391.                 }
  392.                 $ret.=">$val</option>\n";
  393.             }
  394.         }
  395.         if ($this->notInLstValues{
  396.             foreach($aValArr as $s_value{
  397.                 if (!empty($s_value)) $ret.="<option value=\"$s_value\" selected>$s_value</option>\n";
  398.             }
  399.         }
  400.         return $ret;
  401.     }
  402.  
  403.     /**
  404.       *
  405.       * returns the html code for the readonly field
  406.       *
  407.       * @param mixed $aValue 
  408.       * @param string $arrName 
  409.       * @param boolean $debug 
  410.       *
  411.       * @returns string
  412.       *
  413.       * @version pk-04-09-08
  414.       * @version pk-05-08-02 bugifx
  415.       *
  416.       ***/
  417.     function getScreenValue($aValue,$arrName="DBVAL",$debug=FALSE{
  418.         $debug=($debug || $this->fldDebug);
  419.         if ($debugecho "<hr /><p><b>DBMS_FIELD_STATUS_CONFARR_SELECT::getScreenValue($aValue,$arrName,...)</b></p>";
  420.  
  421.         $this->setMyValues($arrName,$debug,FRM_MODE_READONLY);
  422.         return parent::getScreenValue($aValue,$arrName,$debug)// <pk-05-08-02 />
  423.     }
  424.  
  425.     /**
  426.       * returns a html select with all values (distinct) where $aValue
  427.       * is selected
  428.       *
  429.       * NOTE only works on database fields
  430.       *
  431.       * @param mixed $aValue 
  432.       * @param string $arrName 
  433.       * @param string $selTagAdd added into <select ...>
  434.       * @param string $whereCond added to query ($s_query="SELECT ... FROM TABLE ".$whereCond)
  435.       *
  436.       * @return string 
  437.       *
  438.       * @since pk-05-10-20
  439.       *
  440.       * @todo object value tables
  441.       *
  442.       * @var $a_globalValArr 
  443.       ***/
  444.     function getTableValSelect(&$aValue,$arrName="",$selTagAdd="",$whereCond="",$nullLabel="",$debug=FALSE{
  445.         $debug=($debug || $this->fldDebug);
  446.         if ($debugecho "<p><b>DBMS_FIELD::getTableValSelect(aValue=".$aValue.",arrName=".$arrName.")</b> (".get_class($this).")</p>\n";
  447.  
  448.         if ((!empty($this->subKey)) && ($a_globalArr=$this->getGlobalValArr($debug)) && (is_array($a_globalArr))) {
  449.             if (!empty($arrName)) {
  450.                 $s_selName=$arrName."[".$this->myName."]";
  451.             else {
  452.                 $s_selName=$this->myName;
  453.             }
  454.             $ret="\n<select name=\"".$s_selName."\" ".$selTagAdd.">\n";
  455.             if (!empty($nullLabel)) {
  456.                 $ret.="\t<option value=\"\">".$nullLabel."</option>\n";
  457.             else if ($this->searchGroup_allowAll{
  458.                 $ret.="\t<option value=\"\">--- ??? ---</option>\n";
  459.             }
  460.             foreach($a_globalArr as $key => $a_globalValArr{
  461.                 $s_query ="SELECT COUNT(*) FROM ".$this->myTable;
  462.                 if (!empty($whereCond)) {
  463.                     $s_query.=$whereCond;
  464.                     $s_query.=" AND ".$this->myName."=".$GLOBALS['USRDB']->qs_getSlashedValue($key);
  465.                 else {
  466.                     $s_query.=" WHERE ".$this->myName."=".$GLOBALS['USRDB']->qs_getSlashedValue($key);
  467.                 }
  468.                 if ($debugecho "<p>".$s_query."</p>";
  469.                 if ($i_nofEntries=intval($GLOBALS['USRDB']->quickQuery($s_query,0))) {
  470.                     $ret.= "\t<option value=\"".$key."\"";
  471.                     if ((empty($nullLabel)) && (!$this->searchGroup_allowAll&& (empty($aValue))) {
  472.                         // no null Label -> we have to set the $aValue called by ref
  473.                         $aValue=$key;
  474.                     }
  475.                     if (strval($aValue)===(strval($key))) {
  476.                         if ($debugecho " <b>SELECTED</b>";
  477.                         $ret.= " selected";
  478.                     }
  479.  
  480.                     if (!empty($a_globalValArr[$this->subKey])) {
  481.                         $ret.=">".$a_globalValArr[$this->subKey]."</option>";
  482.                     else {
  483.                         $ret.=">".$key."</option>";
  484.                     }
  485.                 }
  486.             }
  487.             $ret.="\n</select>";
  488.         }
  489.  
  490.         return $ret;
  491.     }
  492.  
  493.  
  494. // end class DBMS_FIELD_GLOBALARRSELECTLIST
  495. ?>

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