Source for file OCSP_FRMCONTR_LIST.phpclass

Documentation is available at OCSP_FRMCONTR_LIST.phpclass

  1. <?php
  2. /**
  3.   * Class file OCSP_FRMCONTR_LIST.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    forms
  7.   * @category   dbms_form
  8.   *
  9.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  10.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  11.   *
  12.   * @since  pk-07-07-02
  13.   * 
  14.   * @version $Id: OCSP_FRMCONTR_LIST.phpclass,v 1.23 2008/11/30 13:35:29 pitlinz Exp $
  15.   * 
  16.   */
  17.  
  18. // -----------------------------------------------------
  19. // requirements
  20. // -----------------------------------------------------
  21.  
  22.     pcf_require_class('OCSP_FRMCONTR',"db/forms/");
  23.     pcf_require_class('OCSP_TEMPLATE',"common/");
  24.  
  25. /**
  26.   * class OCSP_FRMCONTR_LIST
  27.   *
  28.   * @project    Open CSP-Management
  29.   * @package    forms
  30.   * @category   dbms_form
  31.   *
  32.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  33.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  34.   *
  35.   * @since  pk-07-07-02
  36.   *
  37.   */
  38. {
  39.  
  40.     /*** Aggregations: */
  41.  
  42.  
  43.     /*** Compositions: */
  44.  
  45.  
  46.     /*** Attributes: */
  47.  
  48.     /**
  49.       * @var array $lstTables 
  50.       *  array(
  51.       *      'TABLE'=string
  52.       *      'COLS'=>array()
  53.       *      'KEYS'=array()
  54.       *))
  55.       * @access protected
  56.       */
  57.     protected $lstTables=array();
  58.  
  59.     /**
  60.       * @var array $lstObjValCols 
  61.       * @access protected
  62.       */
  63.     protected $lstObjValCols=array();
  64.  
  65.  
  66.     /**
  67.       * @var string $lstQuery (without limit,offset and order)
  68.       * @access protected
  69.       */
  70.     protected $lstQuery="";
  71.  
  72.     /**
  73.       * @var array $myListValues 
  74.       * @access protected
  75.       */
  76.     protected $myListValues=array();
  77.  
  78.     /**
  79.       * @var double $listLoadTS 
  80.       * @access protected
  81.       */
  82.     protected $listLoadTS=0;
  83.  
  84.     /**
  85.       * @var double $lstObjValTS 
  86.       * @access protected
  87.       */
  88.     protected $lstObjValTS=0;
  89.  
  90.     /**
  91.       * @var int $myListIdx 
  92.       * @access protected
  93.       */
  94.     protected $myListIdx=0;
  95.  
  96.     /**
  97.       * @var int $lst_limit 
  98.       * @access protected
  99.       */
  100.     protected $lst_limit=0;
  101.  
  102.     /**
  103.       * @var int $lst_offset 
  104.       * @access protected
  105.       */
  106.     protected $lst_offset=0;
  107.  
  108.     /**
  109.      * url for (auto)pageing
  110.      *
  111.      * @var string 
  112.      */
  113.     protected $lst_pageingUrl = "";
  114.     
  115.     /**
  116.       * @var array $lst_groupValues 
  117.       * @access protected
  118.       */
  119.     protected $lst_groupValues;
  120.  
  121.     /**
  122.       * @var string $lst_orderBy 
  123.       * @access protected
  124.       */
  125.     protected $lst_orderBy="";
  126.  
  127.     // commands & events
  128.     /**
  129.       * @var string $tbl_sortLink 
  130.       * @access protected
  131.       */
  132.     protected $tbl_sortLink="";
  133.  
  134.     /**
  135.       * an array with a java event as key and a js-function template
  136.       *
  137.       * @example
  138.       *      $myRowCmds['onClick']="alert('\$*COLNAME$')";
  139.       *      will output &lt;tr onClick="alert('VALUE OF $this->curRow[$COLNAME]')" &gt;
  140.       *
  141.       *  NOTE: avoid " in PARAM as the generated code is enclosed by "
  142.       *
  143.       * @var array $myRowCmds 
  144.       * @access protected
  145.       */
  146.     protected $myRowCmds=array();
  147.  
  148.     /** array of command templates for each row
  149.       * $tbl_rowBtnCmds[CMDNAME]=CMDTMPLATE
  150.       *
  151.       * it will generate a button - column as follows:
  152.       *
  153.       * &lt;td&gt&lta pcf_tmpl_parse(CMDTMPLATE,$this->curRow) &gt; $this->myView->getButtonImgTag(CMDNMAE) &lt;a&gt;
  154.       *
  155.       *
  156.       * @var array $tbl_rowBtnCmds 
  157.       * @access protected
  158.       */
  159.     protected $tbl_rowBtnCmds=array();
  160.  
  161.     /**
  162.       * @var array $tbl_footerCmds 
  163.       * @access protected
  164.       */
  165.     protected $tbl_footerCmds=array();
  166.  
  167.  
  168.     /**
  169.      * @var string $myListKey 
  170.      */
  171.     protected $myListKey = "";
  172.     
  173.     
  174.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  175.     // init methods
  176.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  177.  
  178.  
  179.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  180.     // getter/setter methods
  181.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  182.  
  183.     /**
  184.      * @param string $aKey 
  185.      */
  186.     public function setListKey($aKey)
  187.     {
  188.         $this->myListKey = $aKey;
  189.     }
  190.     
  191.     /**
  192.      * @return string 
  193.      */
  194.     public function getListKey()
  195.     {
  196.         return $this->myListKey;
  197.     }
  198.     
  199.     /**
  200.       * @param boolean $debug 
  201.       * @return int 
  202.       */
  203.     function getOffset($debug=False)
  204.     {
  205.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getOffset()");
  206.         return $this->lst_offset;
  207.     }
  208.  
  209.     /**
  210.       * @param int $offset 
  211.       */
  212.     function setOffset($offset)
  213.     {
  214.         $this->lst_offset=$offset;
  215.     }
  216.  
  217.     /**
  218.       * @return int 
  219.       */
  220.     function getLimit()
  221.     {
  222.         return $this->lst_limit;
  223.     }
  224.  
  225.     /**
  226.       * @param int $limit 
  227.       */
  228.     function setLimit($limit)
  229.     {
  230.         $this->lst_limit=intval($limit);
  231.     }
  232.  
  233.     /**
  234.      * returns the unfiltered list sql statement
  235.      * 
  236.      * if $this->lstQuery is empty the query is generated out of the form
  237.      *
  238.      * @param boolean $debug 
  239.      * 
  240.      * @return string 
  241.      * 
  242.      * @since pk-08-01-19
  243.      * 
  244.      */
  245.     function getListQuery($debug=False)
  246.     {
  247.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getListQuery()");
  248.         if (!empty($this->lstQuery))
  249.         {
  250.             if ($debugechoDebugLine(__FILE__,__LINE__,"returning already set: " $this->lstQuery);
  251.             return $this->lstQuery;
  252.             
  253.             // <<<< return <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  254.             
  255.         }
  256.                 
  257.         if ($debugechoDebugLine(__FILE__,__LINE__,"the form has: ".sizeof($this->lstTables)." tables");
  258.         
  259.         if (sizeof($this->lstTables)==1)
  260.         {
  261.             $arr_keys=array_keys($this->lstTables);
  262.             $this->lstQuery="SELECT * FROM ".$arr_keys[0];
  263.             return $this->lstQuery;
  264.             
  265.             // <<<< return <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  266.             
  267.         else if ($obj_tblObj=$this->myForm->getMyTblObj()) {
  268.             
  269.             $str_query ="SELECT * FROM ".$obj_tblObj->getMyTable();
  270.             $arr_joinCols=$this->myForm->getJoinCols();
  271.  
  272.             if ($debugechoDebugLine(__FILE__,__LINE__,"<p>JoinCols: </p><pre>".print_r($arr_joinCols,TRUE)."</pre>");
  273.             foreach($this->lstTables as $str_tbl => $arr_tblDef)
  274.             {
  275.                 if ($str_tbl != $obj_tblObj->getMyTable())
  276.                 {
  277.                     foreach($arr_joinCols as $str_col => $arr_tableJoinCols)
  278.                     {
  279.                         echoDebugLine(__FILE__,__LINE__,"<p>\$arr_joinColsstrong$str_col</strong><pre>".print_r($arr_tableJoinCols,TRUE)."</pre>");
  280.                     }
  281.                     echoDebugLine(__FILE__,__LINE__,"<p><strong>$str_tbl</strong><pre>".print_r($arr_tblDef,TRUE)."</pre>");
  282.                 }
  283.             }
  284.             echo $str_query;
  285.             ocsp_logError(__FILE__,__LINE__,"@TODO the form (".get_class($this->myForm)." ID ".$this->myForm->getId().") has: ".sizeof($this->lstTables)." tables");
  286.  
  287.         else {
  288.             $arr_keys=array();
  289.             foreach($this->lstTables as $str_tbl => $arr_tblDef)
  290.             {
  291.                 if ($this->myDBObj->tblExists($str_tbl))
  292.                 {
  293.                     $arr_keys[$str_tbl]=$this->myDBObj->getPrimaryKeys($str_tbl);
  294.                 }
  295.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<p><strong>$str_tbl</strong><pre>".print_r($arr_tblDef,TRUE)."</pre>");
  296.             }
  297.  
  298.             $str_query ="SELECT * FROM ".$this->myForm->getMastertable();
  299.             unset($arr_keys[$this->myForm->getMastertable()]);
  300.  
  301.             // try to bild join
  302.             
  303.             $int_maxLoops=sizeof($arr_keys)*sizeof($arr_keys);
  304.             $arr_cols=$this->myDBObj->getDBTblDesc($this->myForm->getMastertable());
  305.             if ($debugechoDebugLine(__FILE__,__LINE__,"<pre>".print_r($arr_keys,TRUE)."\ncols:\n".print_r($arr_cols,TRUE)."</pre>");
  306.             
  307.             while(sizeof($arr_keys&& is_array($arr_keys&& intval($int_maxLoops))
  308.             {
  309.                 foreach($arr_keys as $str_tbl => $arr_keys)
  310.                 {
  311.                     if (is_array($arr_keys))
  312.                     {
  313.                         $b_tblAdded=False;
  314.                         reset($arr_keys);
  315.                         while(!$b_tblAdded && (list(,$str_keyeach($arr_keys)))
  316.                         {
  317.                             if (isset($arr_cols[$str_key]))
  318.                             {
  319.                                 $str_query.=" JOIN $str_tbl USING($str_key)";
  320.                                 unset($arr_keys[$str_tbl]);
  321.                                 $b_tblAdded=True;
  322.                             }
  323.                         }
  324.                     }
  325.                 }
  326.                 $int_maxLoops--;
  327.             }
  328.             if ($debugechoDebugLine(__FILE__,__LINE__,"ListQuery$str_query");
  329.             $this->lstQuery=$str_query;
  330.             return $this->lstQuery;
  331.             
  332.             // <<<< return <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  333.             
  334.             
  335.         }        
  336.         return NULL;                
  337.     }
  338.     
  339.     /**
  340.      * returns the where condition for the filter
  341.      * 
  342.      * you have to prepend "WHERE" OR "AND" to the returned string
  343.      *
  344.      * @param boolean $debug 
  345.      * @return string 
  346.      * 
  347.      * @since pk-08-06-26
  348.      * @version pk-08-10-01 if filter value is an array -> make or statement
  349.      * 
  350.      */
  351.     public function getFilterWhere($debug=False)
  352.     {
  353.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getFilterWhere()");
  354.         $this->getDBObj();
  355.         
  356.         $str_conditions "";
  357.         $str_whereAnd="";
  358.         foreach($this->myFilter as $str_col => $m_val)
  359.         {
  360.             if (substr($str_col,0,1)=="?")
  361.             {
  362.                 $str_conditions .= $str_whereAnd $m_val;
  363.             else if (substr($str_col,0,1== "~"{
  364.                    $str_conditions .= $str_whereAnd substr($str_col,1" " $this->myDBObj->qs_getLikeStmt($m_val,False,False,$debug);
  365.             else if (is_array($m_val)) // <pk-08-10-01>
  366.                 $str_orSep "";
  367.                 $str_orCondition "";
  368.                 foreach($m_val as $m_orVal)
  369.                 {
  370.                     $str_orCondition .= $str_orSep $str_col "=" $this->myDBObj->qs_getSlashedValue($m_orVal);
  371.                     $str_orSep " OR ";
  372.                 }
  373.                 if (!empty($str_orCondition))
  374.                 {
  375.                     $str_conditions .= $str_whereAnd "(" $str_orCondition ")";
  376.                 else {
  377.                     $str_conditions .= $str_whereAnd "1=1"// to avoid errors for empty conditions
  378.                 }                                        
  379.             else {
  380.                 $str_conditions .= $str_whereAnd $str_col "=" $this->myDBObj->qs_getSlashedValue($m_val);
  381.               }
  382.             $str_whereAnd=" AND ";
  383.         }
  384.         
  385.           return $str_conditions;
  386.     }
  387.     
  388.     /**
  389.       * sets a query for the list elements
  390.       * @param string 
  391.       */
  392.     function setListQuery($aSqlStatement)
  393.     {
  394.         $this->lstQuery=$aSqlStatement;
  395.     }
  396.  
  397.     /**
  398.       * @param boolean $debug 
  399.       * @return string 
  400.       */
  401.     function getOrderBy($debug=False)
  402.     {
  403.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getOrderBy()");
  404.         return $this->lst_orderBy;
  405.     }
  406.  
  407.     /**
  408.       * @param string $orderStr 
  409.       */
  410.     function setOrderBy($orderStr)
  411.     {
  412.         $this->lst_orderBy=$orderStr;
  413.     }
  414.  
  415.     // row buttons (right)
  416.     /**
  417.       * @return int (the size of $this->tbl_rowBtnCmds)
  418.       * @access public
  419.       */
  420.     function getNofBtnCols()
  421.     {
  422.         return sizeof($this->tbl_rowBtnCmds);
  423.     }
  424.  
  425.     /**
  426.       * adds a button command to the end of a row
  427.       *
  428.       * @param string $aCmd 
  429.       * @param string $aTmpl 
  430.       */
  431.     function addCmdButton($aCmd,$aTmpl)
  432.     {
  433.         $this->tbl_rowBtnCmds[$aCmd]=$aTmpl;
  434.     }
  435.  
  436.     /**
  437.      * returns the row command button array
  438.      *
  439.      * @param int $pos // -1: left; 1: right (default); 0: both
  440.      * @return array 
  441.      * 
  442.      * @since pk-08-06-02
  443.      */
  444.     function getCmdButtons($pos=0)
  445.     {
  446.         if (!intval($pos))
  447.         {
  448.             return $this->tbl_rowBtnCmds;
  449.         else if (intval($pos0{
  450.             $arr_ret array();
  451.             foreach($this->tbl_rowBtnCmds as $arr_btn)
  452.             {
  453.                 if (isset($arr_btn['POS']&& (intval($arr_btn['POS']0))
  454.                 {
  455.                     $arr_ret[$arr_btn;
  456.                 }
  457.             }
  458.             return $arr_ret;
  459.         else {
  460.             $arr_ret array();
  461.             foreach($this->tbl_rowBtnCmds as $arr_btn)
  462.             {            
  463.                 if (!isset($arr_btn['POS']|| (intval($arr_btn['POS']> -1))
  464.                 {
  465.                     $arr_ret[$arr_btn;
  466.                 }
  467.             }
  468.             return $arr_ret;
  469.         }
  470.         
  471.         
  472.         
  473.     }
  474.     
  475.     /**
  476.       * tr code is generated as follows
  477.       * <code>
  478.       *     echo "&lt;tr $event=\"".pcf_escape_doubleQuote(pcf_tmpl_parse($jsCmd)."\"&gt;";
  479.       * </code>
  480.       *
  481.       * note sending $event twice overwrites the older setting
  482.       *
  483.       * @param string $event 
  484.       * @param string $jsCmd 
  485.       */
  486.     function setRowCmd($event,$jsCmd)
  487.     {
  488.         $this->myRowCmds[$event]=$jsCmd;
  489.     }
  490.  
  491.     
  492.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  493.     // list db methods
  494.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  495.  
  496.     /**
  497.       * @return boolean if the list values have been loaded
  498.       */
  499.     public function valuesAreLoaded()
  500.     {
  501.         return ($this->listLoadTS > time()-ini_get('max_execution_time'));
  502.     }
  503.     
  504.     /**
  505.      * sets the loaded values as invalide
  506.      *
  507.      * @since pk-08-11-26
  508.      */
  509.     public function invalidateValues()
  510.     {
  511.         $this->listLoadTS = 0;
  512.     }
  513.    
  514.     /**
  515.       * @return mixed (False if the list rows have not been loaded else the size of $this->myListValues)
  516.       */
  517.     function getNofListRows()
  518.     {
  519.         if ($this->valuesAreLoaded())
  520.         {
  521.             return sizeof($this->myListValues);
  522.         else {
  523.             return False;
  524.         }
  525.     }
  526.     
  527.     /**
  528.       * @param boolean $debug 
  529.       */
  530.     function initList($debug=False)
  531.     {
  532.         if (!pcf_is_instance_of($this->myView,'OCSP_FRMVIEW'))
  533.         {
  534.             $this->myView=$this->myForm->getListView(NULL,$debug);
  535.         }
  536.  
  537.         $this->listLoadTS=0;
  538.  
  539.         $arr_flds=$this->myView->getFields($debug);
  540.         foreach($arr_flds as &$objField)
  541.         {
  542.             $objField->setControll($this);
  543.             $arr_fldDesc=$objField->getdbDesc();
  544.  
  545.             $str_tbl=$objField->getTable();
  546.             if (!empty($str_tbl))
  547.             {
  548.                 if (substr($str_tbl,0,8)=="OBJVALS_")
  549.                 {
  550.                     $this->lstObjValCols[$str_tbl][]=$objField->getName();
  551.                 else {
  552.                     if (!isset($this->lstTables[$objField->getTable()]))
  553.                     {
  554.                         $this->lstTables[$objField->getTable()]=array('TABLE'=>$objField->getTable());
  555.                     }
  556.                     if (isset($arr_fldDesc['COLNAME']))
  557.                     {
  558.                         $this->lstTables[$objField->getTable()]['COLS'][]=$arr_fldDesc['COLNAME'];
  559.                         if (isset($arr_fldDesc['PRIMARY_KEY']&& ($arr_fldDesc['PRIMARY_KEY']))
  560.                         {
  561.                             $this->lstTables[$objField->getTable()]['PK'][]=$arr_fldDesc['COLNAME'];
  562.                         }
  563.                     }
  564.                 }
  565.             }
  566.         }
  567.  
  568.         if ($arr_groups=$this->myForm->get_listGroups())
  569.         {
  570.             foreach(array_keys($arr_groupsas $str_col)
  571.             {
  572.                 $this->lst_groupValues[$str_col]=NULL;
  573.             }
  574.         }
  575.  
  576.     }
  577.  
  578.     /**
  579.       * @param string $tbl 
  580.       * @param array $fieldNames 
  581.       * @param boolean $debug 
  582.       *
  583.       * @todo OCSP_FRMCONTR_LIST::loadListObjectValues() replace inline SQL
  584.       *
  585.       * @return boolean 
  586.       */
  587.     function loadListObjectValues($debug=False)
  588.     {
  589.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::loadListObjectValues()");
  590.         if (sizeof($this->myListValues1)
  591.         {
  592.             return False;
  593.         }
  594.         if (sizeof($this->lstObjValCols))
  595.         {
  596.             foreach($this->lstObjValCols as $str_tbl => $arr_cols)
  597.             {
  598.                 $str_dbTbl=substr($str_tbl,8);
  599.                 if (!isset($this->lstTables[$str_dbTbl]['PK']))
  600.                 {
  601.                     $this->lstObjValCols[$str_tbl]['LOADED']=False;
  602.                     continue;
  603.                 }
  604.                 if (sizeof($arr_cols1)
  605.                 {
  606.                     $this->lstObjValCols[$str_tbl]['LOADED']=False;
  607.                     continue;
  608.                 }
  609.                 $arr_pkCol=$this->lstTables[$str_dbTbl]['PK'];
  610.                 if (sizeof($arr_pkCol1)
  611.                 {
  612.                     $this->lstObjValCols[$str_tbl]['LOADED']=False;
  613.                     continue;
  614.                 }
  615.  
  616.                 $b_singleKey=(sizeof($arr_pkCol== 1);
  617.                 if (!$b_singleKey)
  618.                 {
  619.                     ocsp_logError(__FILE__,__LINE__,$str_dbTbl." has more then 1 private key columns code not implemented");
  620.                     $this->lstObjValCols[$str_tbl]['LOADED']=False;
  621.                     continue;
  622.                 }
  623.  
  624.                 $str_query="SELECT CONCAT(".$str_dbTbl."_OV.OV_NAME,'|',".$str_dbTbl.".".$arr_pkCol[0].") AS OV_IDX";
  625.                 $char_sep=',';
  626.  
  627.                 $str_query.=$char_sep.$str_dbTbl."_OV.".$arr_pkCol[0];
  628.                 $str_query.=$char_sep."OV_NAME,OV_VALUE FROM ".$str_dbTbl."_OV,".$str_dbTbl;
  629.                 if ($debugechoDebugLine(__FILE__,__LINE__,"OV fields: <pre>".print_r($arr_cols,TRUE)."</pre>");
  630.                 $str_query.=" WHERE ".$this->myDBObj->qs_getWhereIn('OV_NAME',$arr_cols);
  631.  
  632.                 $arr_pkValues=array();
  633.                 foreach($arr_pkCol as $str_pkName)
  634.                 {
  635.                     $str_query.=" AND ".$str_dbTbl."_OV.".$str_pkName."=".$str_dbTbl.".".$str_pkName;
  636.                 }
  637.  
  638.                 if (sizeof($this->myFilter))
  639.                 {
  640.                     foreach($this->myFilter as $str_col => $m_val)
  641.                     {
  642.                         $str_query.=" AND ".$str_dbTbl.".".$str_col."=".$this->myDBObj->qs_getSlashedValue($m_val);
  643.                     }
  644.                 }
  645.  
  646.                 if ($debugechoDebugLine(__FILE__,__LINE__,"querry for objectvalues: <br />".$str_query);
  647.  
  648.                 if ($arr_objValues=$this->myDBObj->queryArray($str_query,0,-1))
  649.                 {
  650.                     foreach($this->myListValues as $i_idx => $arr_values)
  651.                     {
  652.                         foreach($arr_cols as $str_col)
  653.                         {
  654.                             if (isset($arr_objValues[$str_col."|".$arr_values[$arr_pkCol[0]]]['OV_VALUE']))
  655.                             {
  656.                                 $this->myListValues[$i_idx][$str_col]=$arr_objValues[$str_col."|".$arr_values[$arr_pkCol[0]]]['OV_VALUE'];
  657.                             else {
  658.                                 $this->myListValues[$i_idx][$str_col]=NULL;
  659.                             }
  660.                         }
  661.                     }
  662.                     $this->lstObjValCols[$str_tbl]['LOADED']=TRUE;
  663.                     $this->lstObjValTS=time();
  664.                 else {
  665.                     ocsp_logError(__FILE__,__LINE__,"no objectvalues found with query: <br />".$str_query,E_NOTICE);
  666.                     $this->lstObjValCols[$str_tbl]['LOADED']=False;
  667.                 }
  668.             }
  669.         }
  670.     }
  671.             
  672.     /**
  673.       * loads the list values from the database to $this->myListValues
  674.       * an always sets $this->listLoadTS to time()
  675.       *
  676.       * @param boolean $debug 
  677.       * @param boolean $forceReload 
  678.       * 
  679.       * @return int number of rows found or False
  680.       *
  681.       * @todo OCSP_FRMCONTR_LIST::loadListValues() replace inline SQL
  682.       * 
  683.       * @version pk-08-01-19 use $this->getListQuery to set $this->lstQuery
  684.       * @version pk-08-02-15 ~ => LIKE filter type added
  685.       * @version pk-08-06-26
  686.       * @version pk-08-11-26 $forceReload added
  687.       */
  688.     function loadListValues($debug=False,$forceReload=False)
  689.     {
  690.         if($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::loadListValues()","ListQuery: ".$this->lstQuery."<br />Filter: <pre>".print_r($this->myFilter,TRUE)."</pre>");
  691.  
  692.         if ($this->valuesAreLoaded(&& !$forceReload{
  693.             if ($debugechoDebugLine(__FILE__,__LINE__,"ValuesAreLoaded");
  694.             return True;
  695.         }
  696.  
  697.         $this->getDBObj($debug);        // ensure $this->myDBObj is set
  698.         $this->getListQuery($debug);    // ensure $this->lstQuery is set 
  699.         
  700.         if (!empty($this->lstQuery))
  701.         {
  702.             $str_query=$this->lstQuery;
  703.             if (sizeof($this->myFilter))
  704.             {
  705.                 if (stristr($str_query,"where"))
  706.                 {
  707.                     $str_query.=" AND (";
  708.                 else {
  709.                     $str_query.=" WHERE (";
  710.                 }
  711.                    // <pk-08-06-26>
  712.                   $str_query .= $this->getFilterWhere($debug")";
  713.                 // </pk-08-06-26>                  
  714.             }
  715.             if ($this->getOrderBy())
  716.             {
  717.                 $str_query.=" ORDER BY ".$this->getOrderBy();
  718.             }
  719.             if (intval($this->getLimit()))
  720.             {
  721.                 $str_query.=" LIMIT ".intval($this->getOffset()).",".(intval($this->getLimit()));
  722.             
  723.             if ($debugechoDebugLine(__FILE__,__LINE__,"List Query is set to: <br /><strong>".$this->lstQuery."</strong>".str_replace($this->lstQuery,"",$str_query));
  724.             $this->myListIdx=0;
  725.             $this->listLoadTS=time();
  726.  
  727.             if ($debugechoDebugLine(__FILE__,__LINE__,"listquery: " $str_query);
  728.             if ($this->myListValues=$this->myDBObj->queryArray($str_query,-1,-1,TRUE,$debug))
  729.             {
  730.                 return sizeof($this->myListValues);
  731.             else {
  732.                 if ($debugocsp_logError(__FILE__,__LINE__,'list has no values');
  733.                 return 0;
  734.             }
  735.         else {
  736.             if ($debugechoDebugLine(__FILE__,__LINE__,"\$this->lstQuery is empty");
  737.             return False;
  738.         }
  739.         return False;
  740.     }
  741.  
  742.     /**
  743.       * @return array $this->myListValues
  744.       * @since pk-07-09-16
  745.       */
  746.     function getListValues()
  747.     {
  748.         return $this->myListValues;
  749.     }
  750.  
  751.     /**
  752.       * @param boolean $debug 
  753.       * @return array 
  754.       */
  755.     function getListRow($debug=False)
  756.     {
  757.         if($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getListRow()","Index: ".$this->myListIdx);
  758.  
  759.         if ($this->listLoadTS < time()-ini_get('max_execution_time'))
  760.         {
  761.             if ($debugechoDebugLine(__FILE__,__LINE__,time()-ini_get('max_execution_time'));
  762.             $this->loadListValues($debug);
  763.         }
  764.  
  765.         if (isset($this->myListValues[$this->myListIdx]))
  766.         {
  767.             $this->curRow=&$this->myListValues[$this->myListIdx++];
  768.             if ($obj_tblObj=$this->getMyForm()->getMyTblObj(True,$debug))
  769.             {
  770.                 if ($this->lstObjValTS)
  771.                 {
  772.                     $obj_tblObj->setDBVal($this->curRow,$debug);
  773.                 else {
  774.                     $obj_tblObj->setDBRow($this->curRow,TRUE,$debug);
  775.                 }
  776.                 if (!empty($this->userCanShowMethod&& method_exists($obj_tblObj,$this->userCanShowMethod))
  777.                 {
  778.                     eval("\$b_canShow=\$obj_tblObj->".$this->userCanShowMethod."(\$debug);");
  779.                     if (!$b_canShowreturn $this->getListRow($debug);
  780.                 }
  781.                 if ($this->lstObjValTS)
  782.                 {
  783.                     $this->curRow=array_merge($this->curRow,$obj_tblObj->getDBVal());
  784.                 else {
  785.                     $this->curRow=array_merge($this->curRow,$obj_tblObj->getDBRow(False,$debug));
  786.                 }
  787.             }
  788.             return $this->curRow;
  789.         else {
  790.             return NULL;
  791.         }
  792.     }
  793.  
  794.     /**
  795.       * checks the listgroups for the current row and calls
  796.       * $this->myView->getGroupRow if it's to do
  797.       *
  798.       * @param boolean $debug 
  799.       *
  800.       * @return string 
  801.       */
  802.     function getListGroups($debug)
  803.     {
  804.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getListGroups()");
  805.  
  806.         $str_ret="";
  807.         $b_toChange=False;
  808.         if (is_array($this->lst_groupValues))
  809.         {
  810.             foreach($this->lst_groupValues as $str_col => $mix_value)
  811.             {
  812.                 if (isset($this->curRow[$str_col]))
  813.                 {
  814.                     if (($b_toChange|| ($this->curRow[$str_col!= $mix_value))
  815.                     {
  816.                         $b_toChange=TRUE// change each following group
  817.                         $str_ret.=$this->myView->getGroupRow($str_col,$this->curRow,$debug);
  818.                         $this->lst_groupValues[$str_col]=$this->curRow[$str_col];
  819.                     }
  820.                 }
  821.             }
  822.         }
  823.         return $str_ret;
  824.     }
  825.  
  826.     /**
  827.      * returns the total number of rows
  828.      *
  829.      * @param boolean $debug 
  830.      * 
  831.      * @return int 
  832.      * 
  833.      * @since pk-08-05-30
  834.      */
  835.     function getNofTotalRows($debug=False)
  836.     {
  837.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getNofTotalRows()");
  838.         $this->getDBObj($debug);        // ensure $this->myDBObj is set
  839.         $this->getListQuery($debug);    // ensure $this->lstQuery is set 
  840.         
  841.         if (!empty($this->lstQuery))
  842.         {
  843.             $str_query=$this->lstQuery;
  844.             if (sizeof($this->myFilter))
  845.             {
  846.                 if (stristr($str_query,"where"))
  847.                 {
  848.                     $str_query.=" AND (";
  849.                 else {
  850.                     $str_query.=" WHERE (";
  851.                 }
  852.                 $str_whereAnd="";
  853.                 foreach($this->myFilter as $str_col => $m_val)
  854.                 {
  855.                     if (substr($str_col,0,1)=="?")
  856.                     {
  857.                         $str_query .= $str_whereAnd $m_val;
  858.                     else if (substr($str_col,0,1== "~"{
  859.                         $str_query .= $str_whereAnd substr($str_col,1" " $this->myDBObj->qs_getLikeStmt($m_val,False,False,$debug);
  860.                     else {
  861.                         $str_query .= $str_whereAnd $str_col "=" $this->myDBObj->qs_getSlashedValue($m_val);
  862.                     }
  863.                     $str_whereAnd=" AND ";
  864.                 }
  865.                 $str_query.=")";
  866.             }
  867.             
  868.             $int_fromPos stripos($str_query,'FROM');
  869.             $str_query "SELECT COUNT(*) " substr($str_query,($int_fromPos -1));
  870.             
  871.             if ($debugechoDebugLine(__FILE__,__LINE__,"Query: " $str_query);
  872.             
  873.             return intval($this->myDBObj->getOne($str_query));
  874.             
  875.         else {
  876.             if ($debugechoDebugLine(__FILE__,__LINE__,"No ListQuery");
  877.             return 0;
  878.         }
  879.     }
  880.  
  881.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  882.     // controll elementes
  883.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  884.  
  885.     // table tag <table ...>
  886.  
  887.     /**
  888.       * @param boolean $debug 
  889.       * @return string the table id
  890.       * @access public
  891.       */
  892.     function getTableId($debug=False)
  893.     {
  894.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getTableId()");
  895.         return "tbl_".$this->myForm->getName();
  896.     }
  897.  
  898.     /**
  899.       * @param boolean $debug 
  900.       * @return string 
  901.       * @access public
  902.       */
  903.     function getTableEvents($debug=False)
  904.     {
  905.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getTableId()");
  906.         return "";
  907.     }
  908.  
  909.     // header
  910.  
  911.     /**
  912.       * @param boolean $debug 
  913.       * @return string 
  914.       * @access public
  915.       */
  916.     function getHeadRowEvents($debug=False)
  917.     {
  918.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getHeadRowEvents()");
  919.         return "";
  920.     }
  921.  
  922.     /**
  923.       * @param DBMS_FIELD $objField 
  924.       * @param boolean $debug 
  925.       * @return string 
  926.       * @access public
  927.       */
  928.     function getHeadColEvents(&$objField,$debug=False)
  929.     {
  930.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getHeadColEvents()");
  931.         if ($this->tbl_sortLink)
  932.         {
  933.             $str_link=$this->parseFieldTmpl($objField,$this->tbl_sortLink);
  934.             return " ondblclick=\"document.location=\"".$str_link.";\"";
  935.         }
  936.     }
  937.  
  938.     // footer --------------------------------------
  939.     
  940.     /**
  941.      * pageing is tourned on if the $_GET['offset'] and $_GET['limit'] are set
  942.      *
  943.      * @return boolean 
  944.      * 
  945.      * @since pk-08-11-21
  946.      */
  947.     public function checkAutopageing($debug=False)
  948.     {        
  949.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::checkAutopageing()");
  950.         if (isset($_GET['offset']&& isset($_GET['limit']))
  951.         {
  952.             if ($debugechoDebugLine(__FILE__,__LINE__,"offset & limit found");
  953.             if (isset($_SERVER['HTTP_X_REQUESTED_WITH']&& ($_SERVER['HTTP_X_REQUESTED_WITH'== 'XMLHttpRequest'))
  954.             {
  955.                 // jOCSP.load()
  956.                 if ($debugechoDebugLine(__FILE__,__LINE__,"Ajax request: <pre>" print_r($_GET,True"</pre>");
  957.                 return isset($_GET['inToDiv']);
  958.             else {
  959.                 
  960.                 return True;
  961.             }
  962.         }
  963.         return False;
  964.     }
  965.     
  966.     /**
  967.      * returns the html code for the pageing back button
  968.      *
  969.      * @return string 
  970.      */
  971.     public function getPageingBackButton($debug=False)
  972.     {    
  973.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getPageingBackButton()");    
  974.         pcf_require_class('OCSP_AJAX',"ajax/");
  975.         
  976.         if (OCSP_AJAX::isAjaxCall(&& !OCSP_AJAX::isjOCSPLoad())
  977.         {
  978.             if ($debugechoDebugLine(__FILE__,__LINE__,"ajax call not supported");
  979.             return "";
  980.         }
  981.         
  982.         $str_url (empty($this->lst_pageingUrl$_SERVER["REQUEST_URI"$this->lst_pageingUrl);        
  983.         $int_offset ((($this->lst_offset - $this->lst_limit0($this->lst_offset - $this->lst_limit0);
  984.         
  985.         $str_url pcf_HTML_changeURI_GetValue($str_url,'offset',$int_offset);
  986.         
  987.         $str_return "<div style=\"float:left;display:block;width:30px;height:28px;\"><a ";
  988.         if (OCSP_AJAX::isjOCSPLoad())
  989.         {
  990.             $str_return .= "onclick=\"jOCSP.load('{$_GET['inToDiv']}','{$str_url}');\"";
  991.         else {
  992.             $str_return .= "href=\"{$str_url}\"";
  993.         }
  994.         
  995.         $str_return .= "><img src=\"" OCSP_CONF::getInstance()->getValue('SYSIMGURL'"icons-22x22/1leftarrow.gif\" class=\"button\" alt=\"back\" title=\"" t_admin('Zurück'"\" /></a>";
  996.         $str_return .= "</div>";
  997.         return $str_return;
  998.     }
  999.     
  1000.     public function getPageingNext()
  1001.     {
  1002.         pcf_require_class('OCSP_AJAX',"ajax/");
  1003.         
  1004.         if (OCSP_AJAX::isAjaxCall(&& !OCSP_AJAX::isjOCSPLoad())
  1005.         {
  1006.             return "";
  1007.         }
  1008.         
  1009.         $str_url (empty($this->lst_pageingUrl$_SERVER["REQUEST_URI"$this->lst_pageingUrl);        
  1010.         $int_offset $this->lst_offset + $this->lst_limit;
  1011.         
  1012.         $str_url pcf_HTML_changeURI_GetValue($str_url,'offset',$int_offset);
  1013.         
  1014.         $str_return "<div style=\"float:right;display:block;width:30px;height:28px;text-align:right;\"><a ";
  1015.         if (OCSP_AJAX::isjOCSPLoad())
  1016.         {
  1017.             $str_return .= "onclick=\"jOCSP.load('{$_GET['inToDiv']}','{$str_url}');\"";
  1018.         else {
  1019.             $str_return .= "href=\"{$str_url}\"";
  1020.         }
  1021.         
  1022.         $str_return .= "><img src=\"" OCSP_CONF::getInstance()->getValue('SYSIMGURL'"icons-22x22/1rightarrow.gif\" class=\"button\" alt=\"next\" title=\"" t_admin('Weiter'"\" /></a>";
  1023.         $str_return .= "</div>";
  1024.         return $str_return;
  1025.     }    
  1026.     
  1027.     /**
  1028.       * @param boolean $debug 
  1029.       * @return string 
  1030.       * @access public
  1031.       */
  1032.     function getFooterLinks($debug=False)
  1033.     {
  1034.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getTableFooter()",print_r($this->tbl_footerCmds,True));
  1035.                 
  1036.         $str_ret "";
  1037.         
  1038.         if ($this->checkAutopageing($debug))
  1039.         {
  1040.             $str_ret .= $this->getPageingBackButton();
  1041.             $str_ret .= $this->getPageingNext();
  1042.         }
  1043.         
  1044.         if (sizeof($this->tbl_footerCmds))
  1045.         {
  1046.             foreach($this->tbl_footerCmds as $str_name => $str_link)
  1047.             {
  1048.                 $str_ret.=$str_link;
  1049.             }
  1050.         }
  1051.         if (OCSP_OBJ::currentUser()->isGroupMember(_OCSP_GROUP_DBMS_))
  1052.         {
  1053.             $str_ret .= "
  1054.                 <a href=\"" OCSP_CONF::getInstance()->getValue('ADMINURL'"dbms/form.php?FRM_ID=" $this->getMyForm()->getId("\" title=\"" t_admin('Formular bearbeiten'"\">
  1055.                     <img src=\"" OCSP_CONF::getInstance()->getValue('SYSIMGURL'"icons-22x22/editConstruct.gif\" class=\"button\" /> 
  1056.                 </a> 
  1057.             ";
  1058.         }
  1059.         return $str_ret;
  1060.     }
  1061.  
  1062.     public function addFooterCommand($aName,$htmlTag)
  1063.     {
  1064.         $this->tbl_footerCmds[$aName$htmlTag;
  1065.     }
  1066.  
  1067.     /**
  1068.      * sets the footer cmd array
  1069.      * 
  1070.      * NOTE: overwrites existing commands
  1071.      * 
  1072.      * command array:
  1073.      * - name
  1074.      * - html code
  1075.      * 
  1076.      * @param array $footerCmd 
  1077.      * @param boolean $debug 
  1078.      */
  1079.     function setFooterCmdArr($footerCmd,$debug=False)
  1080.     {
  1081.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::setFooterCmdArr()");
  1082.         $this->tbl_footerCmds=$footerCmd;
  1083.     }    
  1084.     
  1085.     // row and cols
  1086.  
  1087.     function getRowId($debug=False)
  1088.     {
  1089.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getRowId()");
  1090.         $str_ret="trId";
  1091.                 
  1092.         foreach($this->lstTables as $arr_tblDesc)
  1093.         {
  1094.             if (isset($arr_tblDesc['PK']&& is_array($arr_tblDesc['PK']))
  1095.             {
  1096.                 foreach($arr_tblDesc['PK'as $str_colName)
  1097.                 $str_ret.="_".$str_colName."-".$this->curRow[$str_colName];
  1098.             }
  1099.         }
  1100.         return $str_ret;
  1101.     }
  1102.  
  1103.     /**
  1104.       * @param boolean $debug 
  1105.       * @return string 
  1106.       * @access public
  1107.       *
  1108.       * @requires __OCSP_PHPINCPATH__."common/pcf_templates.phpinc";
  1109.       *
  1110.       */
  1111.     function getRowCmd($debug=False)
  1112.     {
  1113.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getRowCmd()");
  1114.         $str_ret="";
  1115.         if (is_array($this->myRowCmds&& sizeof($this->myRowCmds))
  1116.         {
  1117.             foreach($this->myRowCmds as $str_event => $str_cmd)
  1118.             {
  1119.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<p><strong>{$str_event}</strong></p>");                
  1120.                 $str_ret.=" ".$str_event."=\"".pcf_escape_doubleQuote(OCSP_TEMPLATE::parse($str_cmd,$this->curRow,$debug))."\"";
  1121.             }
  1122.         }
  1123.         return $str_ret;
  1124.     }
  1125.  
  1126.     /**
  1127.       * @param DBMS_FIELD $objField 
  1128.       * @param boolean $debug 
  1129.       * @return string 
  1130.       */
  1131.     function getColCmd($objField,$debug=False)
  1132.     {
  1133.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getColCmd()");
  1134.         return "";
  1135.     }
  1136.  
  1137.     /**
  1138.       * @param DBMS_FIELD $objField 
  1139.       * @param boolean $debug 
  1140.       * @return string 
  1141.       */
  1142.     function getColLink($objField,$debug=False)
  1143.     {
  1144.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getColLink()");
  1145.         if ($arr_lnk=$objField->getListLinkArr())
  1146.         {
  1147.             if ((isset($arr_lnk['A'])) && (!empty($arr_lnk['A'])))
  1148.             {
  1149.                 return "<a " OCSP_TEMPLATE::parse($arr_lnk['A'],$this->curRow">";
  1150.             }
  1151.         }
  1152.         return "";
  1153.     }
  1154.  
  1155.     /**
  1156.       * @param DBMS_FIELD $objField 
  1157.       * @param boolean $debug 
  1158.       * @return string 
  1159.       */
  1160.     function getColLinkEnd($objField,$debug=False)
  1161.     {
  1162.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getColLinkEnd()");
  1163.         if ($arr_lnk=$objField->getListLinkArr())
  1164.         {
  1165.             if ((isset($arr_lnk['A'])) && (!empty($arr_lnk['A']))) {
  1166.                 return "</a>";
  1167.             }
  1168.         }
  1169.         return "";
  1170.     }
  1171.  
  1172.     /**
  1173.       * @param string $outerElem 
  1174.       * @param string $linkElem 
  1175.       * @param boolean $debug 
  1176.       * @return string 
  1177.       */
  1178.     function getRowButtons($outerElem="td",$linkElem="a",$debug=False)
  1179.     {
  1180.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_LIST::getRowButton()");
  1181.         $str_ret="";
  1182.         if (sizeof($this->tbl_rowBtnCmds)) {
  1183.             foreach($this->tbl_rowBtnCmds as $str_cmd => $str_tmpl)
  1184.             {
  1185.                 $str_ret.="<{$outerElem}><{$linkElem} OCSP_TEMPLATE::parse($str_tmpl,$this->curRow">";
  1186.                 $str_ret.=$this->myView->getButtonImgTag($str_cmd,$debug)."</{$linkElem}></{$outerElem}>";
  1187.             }
  1188.         }
  1189.         return $str_ret;
  1190.     }
  1191.  
  1192.  
  1193. // end of OCSP_FRMCONTR_LIST
  1194. ?>

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