Source for file DBMS_FIELD_ORDERNR.phpclass

Documentation is available at DBMS_FIELD_ORDERNR.phpclass

  1. <?php
  2. /**
  3.   * Class file DBMS_FIELD_ORDERNR.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms_field
  7.   * @category   int
  8.   *
  9.   * @author     Peter Krebs <p.krebs@lvus.at>
  10.   * @copyright  (c) 2002-2005 by LVUS <http://www.lvus.at>
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   ***/
  14.  
  15. pcf_require_class('DBMS_FIELD_INT',dirname(__FILE__"/");
  16.  
  17. /**
  18.   * Class DBMS_FIELD_ORDERNR
  19.   *
  20.   * @project    Open CSP-Management
  21.   * @package    dbms_field
  22.   * @category   int
  23.   *
  24.   * @author     Peter Krebs <p.krebs@lvus.at>
  25.   * @copyright  (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
  26.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  27.   *
  28.   ***/
  29.     var $className     = "OrderNumber";
  30.  
  31.     /**
  32.       * @var string $orderKeyFlds   a comma seperated list of fields to add in the where claus of getNewOrderNr
  33.       ***/
  34.     var $orderKeyFlds  = "";
  35.  
  36.     /**
  37.       * @var bool $showArrows 
  38.       * @since pk-04-05-25
  39.       ***/
  40.     var $showArrows = FALSE;    /* <pk 04-05-27 to be compatible with old projects /> */
  41.  
  42.  
  43.     /**
  44.       * @var string $downArgTmpl 
  45.       * @since pk-04-12-21
  46.       ***/
  47.     var $downArgTmpl = "";
  48.  
  49.     /**
  50.       * @var string $upArgTmpl 
  51.       * @since pk-04-12-21
  52.       ***/
  53.     var $upArgTmpl = "";
  54.  
  55.     /**
  56.       * @var string $moveToArgTmpl 
  57.       * @since pk-04-12-21
  58.       ***/
  59.     var $moveToArgTmpl = "";
  60.  
  61.     /**
  62.       * source file of the class
  63.       *
  64.       * @var string $classSrcFile 
  65.       * @since pk-05-01-20
  66.       ***/
  67.     var $classSrcFile=__FILE__;
  68.  
  69.     /**
  70.       * do not link with edit in lists
  71.       *
  72.       * @since pk-06-01-30
  73.       ***/
  74.     var $lstDisableLinks=TRUE;
  75.  
  76.     // ###########################################################
  77.     // OBJECT SETTINGS METHODS
  78.     // ###########################################################
  79.  
  80.  
  81.     // ###########################################################
  82.     // FIELD DEFINITION DATA METHODS
  83.     // ###########################################################
  84.  
  85.     /**
  86.       * returns an array of field to bie shown in the edit form
  87.       * by using editTbl_echoForm
  88.       *
  89.       * the array is in the form:
  90.       *
  91.       * <code>
  92.       * [_sectionName_]
  93.       *      [TITLE] -> string
  94.       *      [_rowName_]
  95.       *         [FLDLAB]  (complete html code with <td></td>)
  96.       *         [FLDVAL] (complete html code with <td></td>)
  97.       * </code>
  98.       *
  99.       * @param boolean $debug 
  100.       *
  101.       * @returns array
  102.       *
  103.       * @since pk-06-07-22
  104.       *
  105.       ***/
  106.     function editTbl_getFieldEditArr($debug=FALSE{
  107.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_INT::editTbl_getFieldEditArr","",0);
  108.         $a_ret=parent::editTbl_getFieldEditArr($debug);
  109.  
  110.         unset($a_ret['LAYOUT']['UNIT']);
  111.         unset($a_ret['VALCHECKS']['NULL2ZERO']);
  112.  
  113.         $a_ret['SORTFLDDEF']=array(
  114.             'TITLE'         =>"Sortfeld Eigenschanften",
  115.             'HIDDENFIELD'   =>"",
  116.             'ISHIDDEN'      =>FALSE,
  117.             'SORTKEY'=>array(
  118.                 'FLDLAB'=>"Schlusselfelder",
  119.                 'FLDVAL'=>"<input name=\"orderKeyFlds\" type=\"input\" value=\"".$this->orderKeyFlds."\" size=\"30\">"
  120.             ),
  121.             'SHOWARROWS'=>array(
  122.                 'FLDLAB'=>"<a href=\"#\" onClick=\"alert('Pfeile in der Liste anzeigen')\">Pfeile:</a>",
  123.                 'FLDVAL'=>"<input name=\"showArrows\" type=\"checkbox\" value=\"1\" ".($this->showArrows ? "checked" "").">"
  124.             ),
  125.             'MOVEDOWN'=>array(
  126.                 'FLDLAB'=>"Move Down ARGS: <a href=\"".$GLOBALS['PROJECT']['SYSTEMURL']."help/templatevars.html\" target=\"_blank\">?</a>",
  127.                 'FLDVAL'=>"<input name=\"downArgTmpl\" type=\"input\" value=\"".htmlspecialchars($this->downArgTmpl)."\" size=\"30\">"
  128.             ),
  129.             'MOVEUP'=>array(
  130.                 'FLDLAB'=>"Move Up ARGS: <a href=\"".$GLOBALS['PROJECT']['SYSTEMURL']."help/templatevars.html\" target=\"_blank\">?</a>",
  131.                 'FLDVAL'=>"<input name=\"upArgTmpl\" type=\"input\" value=\"".htmlspecialchars($this->upArgTmpl)."\" size=\"30\">"
  132.             ),
  133.             'MOVEPOS'=>array(
  134.                 'FLDLAB'=>"Move to positon ARGS: <a href=\"".$GLOBALS['PROJECT']['SYSTEMURL']."help/templatevars.html\" target=\"_blank\">?</a>",
  135.                 'FLDVAL'=>"<input name=\"moveToArgTmpl\" type=\"input\" value=\"".htmlspecialchars($this->moveToArgTmpl)."\" size=\"30\">&amp;NEWPOS=xxx"
  136.             )
  137.         );
  138.  
  139.         return $a_ret;
  140.     }
  141.  
  142.     /**
  143.       * echos the filed definition form
  144.       *
  145.       * @param boolean $showSize obsulet
  146.       * @param boolean $showUnit obsulet
  147.       * @param boolean $showNull obsulet
  148.       *
  149.       * @deprecated since pk-06-07-22
  150.       *
  151.       ***/
  152.     function editTblForm($showSize=FALSE,$showUnit=TRUE,$showNull=TRUE{
  153.         $a_FieldEditArr=$this->editTbl_getFieldEditArr($debug);
  154.         $this->editTbl_echoForm($a_FieldEditArr,$debug);
  155.     }
  156.     ###############################
  157.  
  158.     /**
  159.       * save the filed definition form
  160.       *
  161.       * @returns boolean
  162.       *
  163.       ***/
  164.     function save({
  165.         $ret=parent::save();
  166.  
  167.         $this->orderKeyFlds=$_POST['orderKeyFlds'];
  168.         $this->showArrows=intval($_POST['showArrows']TRUE FALSE;
  169.         $this->downArgTmpl=$_POST['downArgTmpl'];
  170.         $this->upArgTmpl=$_POST['upArgTmpl'];
  171.         $this->moveToArgTmpl=$_POST['moveToArgTmpl'];
  172.         $this->size=4;
  173.         $this->lstDisableLinks=TRUE;    // <pk-06-01-30 />
  174.  
  175.         return $ret;
  176.     }
  177.  
  178.  
  179.     /**
  180.       * returns if the list cell can be linked with the ['EDIT'] link
  181.       *
  182.       * @returns boolean
  183.       *
  184.       * @since pk-06-01-30
  185.       ***/
  186.     function lstLinksDisabled({
  187.         return TRUE;
  188.     }
  189.  
  190.     // ###########################################################
  191.     // OBJECT DATA METHODS
  192.     // ###########################################################
  193.  
  194.     /**
  195.       * returns the htmlcode for the move down button
  196.       *
  197.       * @param int $aValue 
  198.       * @param bool $debug 
  199.       *
  200.       * @return string 
  201.       *
  202.       * @since pk-05-01-03
  203.       *
  204.       ***/
  205.     function getDownLink($aValue=NULL,$debug=FALSE{
  206.         if ($debugecho "<p><b>DBMS_FIELD_ORDERNR::getDownLink($aValue,...)</b> (".$this->myName."/".get_class($this).")</p>";
  207.  
  208.         if (empty($this->myDataArrName)) $this->myDataArrName="DBVAL";
  209.         global ${$this->myDataArrName};
  210.  
  211.         if ($debugecho "<blockquote>";
  212.         if (!isset($GLOBALS['ORDERNR'][$this->myDataArrName][$this->myName]||
  213.             !intval($GLOBALS['ORDERNR'][$this->myDataArrName][$this->myName])) // <pk-06-07-22 /> E_ALL
  214.             $maxNr=intval($this->getNewOrderNr($this->myDataArrName,$debug))-1;
  215.             $GLOBALS['ORDERNR'][$this->myDataArrName][$this->myName]=$maxNr;
  216.         else {
  217.             $maxNr=$GLOBALS['ORDERNR'][$this->myDataArrName][$this->myName];
  218.         }
  219.  
  220.         if ($debugecho "<p>MAX Nr.: ".$maxNr."</p></blockquote>";
  221.  
  222.         if (intval($aValue >= $maxNr)) {
  223.             if ($debugecho "<p><blockquote>First Row (".$aValue.")</blockquote></p>";
  224.             return "";
  225.         }
  226.  
  227.         if (!empty($this->downArgTmpl)) {
  228.             $link=$_SERVER['SCRIPT_NAME']."?";
  229.             require_once __OCSP_PHPINCPATH__."common/pcf_templates.phpinc";
  230.             if ($debugecho "<blockquote><p>Tmplate:</p><pre>".htmlspecialchars(print_r($this->downArgTmpl,TRUE))."</pre>";
  231.             $link.=pcf_tmpl_parse($this->downArgTmpl,${$this->myDataArrName},$debug);
  232.             if ($debugecho "</blockquote>";
  233.         else {
  234.             $link=pcf_HTML_changeURI_GetValue($_SERVER['REQUEST_URI'],"cmd","down");
  235.         }
  236.  
  237.         if (!empty($aValue)) $link=pcf_HTML_changeURI_GetValue($link,$this->myName,$aValue,$debug);
  238.  
  239.         if ($debugecho "<p>LINK:</p><pre>".htmlspecialchars($link)."</pre>";
  240.  
  241.         $ret ="<a href=\"".pcf_HTML_getEncodedURI($link)."\">"// <pk-06-10-19 />
  242.         $ret.="<img src=\"".$GLOBALS['PROJECT']['SYSIMGURL']."icons-16x16/down10x16.gif\" border=\"0\" alt=\"down\" align=\"middle\"  class=\"button\"></a>";
  243.  
  244.         return $ret;
  245.     }
  246.  
  247.     /**
  248.       * returns the htmlcode for the move up button
  249.       * only if $this->upArgTmpl is not empty
  250.       *
  251.       * @param int $aValue
  252.       * @param bool $debug
  253.       *
  254.       * @return string
  255.       *
  256.       * @since pk-05-01-03
  257.       *
  258.       **/
  259.     function getUpLink($aValue=NULL,$debug=FALSE{
  260.         if ($debugecho "<p><b>DBMS_FIELD_ORDERNR::getUpLink($aValue,...)</b> (".$this->myName."/".get_class($this).")</p>";
  261.         if ((!empty($this->upArgTmpl)) && (intval($aValue1)) {
  262.             $link=$_SERVER['SCRIPT_NAME']."?";
  263.             require_once __OCSP_PHPINCPATH__."common/pcf_templates.phpinc";
  264.  
  265.             if (empty($this->myDataArrName)) $this->myDataArrName="DBVAL";
  266.             global ${$this->myDataArrName};
  267.             $link.=pcf_tmpl_parse($this->upArgTmpl,${$this->myDataArrName});
  268.             if (!empty($aValue)) $link=pcf_HTML_changeURI_GetValue($link,$this->myName,$aValue);
  269.  
  270.             $ret ="<a href=\"".pcf_HTML_getEncodedURI($link)."\">"// <pk-06-10-19 />
  271.             $ret.="<img src=\"".$GLOBALS['PROJECT']['SYSIMGURL']."icons-16x16/up10x16.gif\" border=\"0\" alt=\"up\" class=\"button\" align=\"middle\"></a>";
  272.  
  273.             return $ret;
  274.         else {
  275.             return "";
  276.         }
  277.     }
  278.  
  279.     /**
  280.       * returns the htmlcode for the "move to position"
  281.       * only if $this->moveToArgTmpl is not empty otherwise $aValue is returned
  282.       *
  283.       * @param int $aValue
  284.       * @param bool $debug
  285.       *
  286.       * @return string
  287.       *
  288.       * @since pk-06-02-23
  289.       *
  290.       **/
  291.     function getMoveToLink($aValue=NULL,$debug=FALSE{
  292.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_ORDERNR::getMoveToLink()","",0);
  293.         if (!empty($this->moveToArgTmpl)) {
  294.             $link=$_SERVER['SCRIPT_NAME']."?";
  295.             require_once __OCSP_PHPINCPATH__."common/pcf_templates.phpinc";
  296.  
  297.             if (empty($this->myDataArrName)) $this->myDataArrName="DBVAL";
  298.             global ${$this->myDataArrName};
  299.             $link.=pcf_tmpl_parse($this->moveToArgTmpl,${$this->myDataArrName});
  300.  
  301.             $s_ret ="<a href=\"javascript:{if (newPos=prompt('Neue Position')) {document.location.href='".$link."&NEWPOS='+newPos;}}\" title=\"neu positionieren\">";
  302.             $s_ret.=$aValue."</a>";
  303.             return $s_ret;
  304.         else {
  305.             return $aValue;
  306.         }
  307.     }
  308.  
  309.     // ###########################################################
  310.     // OBJECT HTML FORM METHODS
  311.     // ###########################################################
  312.  
  313.  
  314.     /**
  315.       * returns the html code for the field value input / show
  316.       * adds $this->myName to ${$this->myDataArrName}['_DBMS_FIELDS']
  317.       *
  318.       * @param int $mode
  319.       * @param mixed $aValue
  320.       * @param boolean $debug
  321.       *
  322.       * @returns string
  323.       *
  324.       * @since pk-05-01-03
  325.       * @version pk-06-01-30
  326.       *
  327.       **/
  328.     function getFieldTag($mode,$aValue=NULL,$debug=FALSE{
  329.         $debug=($debug || $this->fldDebug);
  330.         if ($debugecho "<p><b>DBMS_FIELD_ORDERNR::getFieldTag($mode,$aValue,...)</b> (".get_class($this).")";
  331.  
  332.         if ($mode == FRM_MODE_LIST && $this->showArrows{
  333.             if ($debugecho "<blockquote>";
  334.             $s_style="style=\"border:0px;margin:0px;padding:0px;\" ";
  335.             $ret="<table ".$s_style." cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr>";
  336.             $ret.="<td ".$s_style." align=\"right\">".$this->getMoveToLink(intval($aValue),$debug)."&nbsp;</td>";
  337.             $ret.="<td ".$s_style." width=\"10\">".$this->getUpLink($aValue,$debug)."</td>";
  338.             $ret.="<td ".$s_style." width=\"10\">".$this->getDownLink($aValue,$debug)."</td>";
  339.             $ret.="</tr></table>";
  340.             if ($debugecho "</blockquote>";
  341.             return $ret;
  342.         else {
  343.             return parent::getFieldTag($mode,$aValue,$debug);
  344.         }
  345.     }
  346.  
  347.  
  348.     /**
  349.       * returns a empty link to not link the field
  350.       *
  351.       * @param mixed $aValue value of the db field
  352.       * @param string $arrName  name of the GLOBAL array holding the row values
  353.       *
  354.       * @return string empty if no link is to show a <a href=...url..> if the field is linked
  355.       *
  356.       * @version pk-04-05-26
  357.       *
  358.       **/
  359.     function getListLink($aValue,$arrName="DBVAL"{
  360.         $this->linkrequested=TRUE;
  361.         return "";
  362.  
  363.     }
  364.  
  365.     // ###########################################################
  366.     // OBJECT VALUE CHECK METHODS
  367.     // ###########################################################
  368.  
  369.     /**
  370.       * selects a new order number from the database
  371.       *
  372.       * NOTE: this is not save because no locking happens
  373.       *
  374.       * uses $arrName as global variable to get the key fields
  375.       * if it is not set $_GET is tried also
  376.       *
  377.       * @param  string  $arrName
  378.       * @param  bool    $debug
  379.       *
  380.       * @return int
  381.       *
  382.       * @version pk-03-12-13
  383.       *
  384.       **/
  385.     function getNewOrderNr($arrName,$debug=FALSE{
  386.         if ($debug || $this->fldDebugecho "<hr><p><b>DBMS_FIELD_ORDERNR::getNewOrderNr($arrName,$debug)</b> (".get_class($this)." | ".$this->myName.")</p>";
  387.         global ${$arrName};
  388.         
  389.         if (!$obj_db $this->myForm->getDBObj())
  390.         {
  391.             throw new Exception(_OCSP_EXCEP_NODBCONN_);
  392.             return false;
  393.         }
  394.  
  395.         $query="SELECT ".$obj_db->qs_ifNullStmt("MAX(".$this->myName.")",0);
  396.         $query.=" FROM ".$this->myTable;
  397.         if (!empty($this->orderKeyFlds)) {
  398.             $where=" WHERE ";
  399.             $keyArr=explode(",",$this->orderKeyFlds);
  400.             if ($debug || $this->fldDebug{echo "<pre>";print_r($keyArr);echo "</pre>"}
  401.             foreach($keyArr as $key => $val{
  402.                 if (isset(${$arrName}[$val])) {
  403.                     $query.=$where.$val."=".$obj_db->qs_getSlashedValue(${$arrName}[$val]);
  404.                     $where=" AND ";
  405.                 else if (isset($_GET[$val])) {
  406.                     $query.=$where.$val."=".$obj_db->qs_getSlashedValue($_GET[$val]);
  407.                     $where=" AND ";
  408.                 }
  409.             }
  410.         }
  411.         if ($debug || $this->fldDebug{echo "<pre>".$this->orderKeyFlds."\n$query</pre>";}
  412.         $nr=intval($obj_db->quickQuery($query,0));
  413.         if ($debug || $this->fldDebug{echo "<pre>Returns:".(intval($nr)+1)."</pre>";}
  414.         return intval($nr)+1;
  415.     }
  416.  
  417.     /**
  418.       * checks if aValue is set.
  419.       * if not a new order number is created
  420.       * if aValue == $this->defaultValue a new order number is created (pk-03-12-13)
  421.       *
  422.       * @param  string  $aValue     the value
  423.       * @param  array   $err        error array
  424.       * @param  string  $arrName    name of the array to access fieldsarray  gloabl ${$arrName}
  425.       * @param  bool    $debug
  426.       *
  427.       * @return string
  428.       *
  429.       * @since   pk-03-12-13
  430.       * @version pk-03-12-13
  431.       *
  432.       **/
  433.     function getValue($aValue,&$err,$arrName="DBVAL",$debug=FALSE{
  434.         if ($debugecho "<hr><p><b>DBMS_FIELD_ORDERNR::getValue($aValue,$err,$arrName,$debug)</b> (".get_class($this)." | ".$this->myName.")</p>";
  435.         if (!intval($aValue|| ($aValue==$this->defaultValue)) {
  436.             $aValue=$this->getNewOrderNr($arrName,$debug);
  437.         }
  438.  
  439.         return $aValue;
  440.     }
  441.  
  442.  
  443.     /**
  444.       * add slashes to the value from getValue to add it to a sql command
  445.       *
  446.       * @param  string  $aValue     the value
  447.       * @param  array   $err        error array
  448.       * @param  string  $arrName    name of the global array to access field gloabl ${$arrName}
  449.       * @param  bool    $debug
  450.       *
  451.       * @return string
  452.       *
  453.       * @version pk-03-12-13
  454.       *
  455.       **/
  456.     function slashedValue($aValue,&$err,$arrName="DBVAL",$debug=FALSE{
  457.         if ($debugecho "<hr><p><b>DBMS_FIELD_ORDERNR::slashedValue($aValue,$err,$arrName,$debug)</b> (".get_class($this)."/".$this->myName.")</p>";
  458.         return parent::slashedValue($this->getValue($aValue,$err,$arrName,$debug),$err,$arrName,$debug);
  459.     }
  460.  
  461. // end class DBMS_FIELD_ORDERNR
  462. ?>

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