Source for file DBMS_FIELD_PAGESELECT.phpclass

Documentation is available at DBMS_FIELD_PAGESELECT.phpclass

  1. <?php
  2. /**
  3.  * Class file DBMS_FIELD_PAGESELECT.phpclass
  4.  *
  5.  * @project    Open CSP-Management
  6.  * @package    dbms_field
  7.  * @category   int
  8.  *
  9.  * @author     Peter Krebs (pk)<pitlinz@users.sourceforge.net>
  10.  * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  11.  *
  12.  * @version pk-03-10-19
  13.  * @version pk-05-02-19
  14.  * @version $Id: DBMS_FIELD_PAGESELECT.phpclass,v 1.6 2008/08/12 08:22:38 pitlinz Exp $
  15.  */
  16.  
  17.  
  18. // --------------------------------------------------------
  19. // requirements
  20. // --------------------------------------------------------
  21.  
  22. pcf_require_class("DBMS_FIELD_FOREIGNKEY",dirname(__FILE__"/");
  23. pcf_require_class("CMS_PROJECT","cms/");
  24. pcf_require_class("CMS_MENU_NODE","cms/menu/");
  25. pcf_require_class("CMS_PAGE","cms/page/");
  26.  
  27. /**
  28.  * handels fields which are foreign keys to a page
  29.  *
  30.  * shows a select box to select pages
  31.  *
  32.  * @project    Open CSP-Management
  33.  * @package    dbms_field
  34.  * @category   int
  35.  *
  36.  * @author     Peter Krebs (pk)<pitlinz@users.sourceforge.net>
  37.  * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  38.  *
  39.  * @version pk-03-10-19
  40.  * @version pk-05-02-19
  41.  * @version $Id: DBMS_FIELD_PAGESELECT.phpclass,v 1.6 2008/08/12 08:22:38 pitlinz Exp $
  42.  *
  43.  */
  44. {
  45.  
  46.     // ---------------------------------------------------------------------------
  47.     // constants
  48.     // ---------------------------------------------------------------------------
  49.  
  50.     /**
  51.      * @constant string CLASS_SRC_FILE
  52.      */
  53.     const CLASS_SRC_FILE = __FILE__;
  54.  
  55.     // ---------------------------------------------------------------------------
  56.     // class (static)
  57.     // ---------------------------------------------------------------------------
  58.  
  59.     /*** class vars ------------------------------------------------------ */
  60.  
  61.     /**
  62.      * @staticvar array $ps_sprojSelectModes PRIVATE project select modes
  63.      ***/
  64.     protected static $ps_sprojSelectModes=array(
  65.                     '1' => array(
  66.                             'LABEL'     => "NUR IM PROJEKT (\${\$arrName})",
  67.                             'WITHPROJ'  => FALSE
  68.     ),
  69.                     '2' => array(
  70.                             'LABEL'     => "NUR GET PROJEKT (\$_GET['PROJ_ID'])",
  71.                             'WITHPROJ'  => FALSE
  72.     ),
  73.                     '3' => array(
  74.                             'LABEL'     => "ALLE PROJEKTE",
  75.                             'WITHPROJ'  => TRUE
  76.     )
  77.     );
  78.  
  79.     /*** class methods --------------------------------------------------- */
  80.  
  81.     // ---------------------------------------------------------------------------
  82.     // object vars
  83.     // ---------------------------------------------------------------------------
  84.  
  85.     /*** compostion --------------------------------------------------- */
  86.  
  87.     /**
  88.      * the current selected page
  89.      *
  90.      * @var CMS_PAGE 
  91.      */
  92.     protected $mySelectedPage = Null;
  93.  
  94.     /*** attributes --------------------------------------------------- */
  95.  
  96.     /**
  97.      * source file of the class
  98.      *
  99.      * @var string $classSrcFile 
  100.      * @since pk-05-01-11
  101.      ***/
  102.     protected $classSrcFile=__FILE__;
  103.  
  104.  
  105.     /**
  106.      * @staticvar string $lookupTable 
  107.      ***/
  108.     protected $lookupTable             = "T_CMS_PAGE p LEFT OUTER JOIN T_CMS_MENU m USING(MEN_ID)";
  109.     /**
  110.      * @staticvar string $$lookupShowField 
  111.      ***/
  112.     protected $lookupShowField        = "CONCAT(IFNULL(PAG_TITLE,'NO TITLE'),' (',PAG_ID,')')";
  113.     /**
  114.      * @staticvar string $lookupField 
  115.      ***/
  116.     protected $lookupField            = "PAG_ID";
  117.     /**
  118.      * @staticvar string $lookupSort 
  119.      ***/
  120.     protected $lookupSort              = "PAG_SORTORDER";
  121.     /**
  122.      * @staticvar string $nullLabel 
  123.      ***/
  124.     protected $nullLabel              = "STARTPAGE";
  125.     /**
  126.      * @staticvar string $whereAnd 
  127.      ***/
  128.     protected $whereAnd               = "";
  129.  
  130.  
  131.  
  132.     /**
  133.      * @var int $myProjSelectMode    add the project to the select list
  134.      ***/
  135.     protected $myProjSelectMode = 1;
  136.  
  137.     /**
  138.      * @var bool $showExpired         show expired pages
  139.      ***/
  140.     protected $showExpiredPages = FALSE;
  141.  
  142.  
  143.     /**
  144.      * @var boolean $showSysDefault 
  145.      * @since pk-05-09-05
  146.      ***/
  147.     protected $showSysDefault=TRUE;
  148.  
  149.  
  150.     // ---------------------------------------------------------------------------
  151.     // factory / construct
  152.     // ---------------------------------------------------------------------------
  153.  
  154.     // ---------------------------------------------------------------------------
  155.     // init
  156.     // ---------------------------------------------------------------------------
  157.  
  158.     // ---------------------------------------------------------------------------
  159.     // getter/setter
  160.     // ---------------------------------------------------------------------------
  161.      
  162.     /**
  163.      * returns the DOM id of the menu select
  164.      *
  165.      * @return string 
  166.      */
  167.     public function getMenuSelectId()
  168.     {
  169.         return "MENSEL_" $this->getDOMId();
  170.     }
  171.  
  172.     // ---------------------------------------------------------------------------
  173.     // dbms admin backoffice
  174.     // ---------------------------------------------------------------------------
  175.  
  176.  
  177.     /**
  178.      * returns an array of field to bie shown in the edit form
  179.      * by using editTbl_echoForm
  180.      *
  181.      * the array is in the form:
  182.      *
  183.      * <code>
  184.      * [_sectionName_]
  185.      *      [TITLE] -> string
  186.      *      [_rowName_]
  187.      *         [FLDLAB]  (complete html code with <td></td>)
  188.      *         [FLDVAL] (complete html code with <td></td>)
  189.      * </code>
  190.      *
  191.      * @param boolean $debug 
  192.      *
  193.      * @returns array
  194.      *
  195.      * @since pk-07-01-07
  196.      *
  197.      * @version pk-07-02-16
  198.      * @version pk-08-08-11
  199.      *
  200.      */
  201.     function editTbl_getFieldEditArr($debug=FALSE{
  202.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_PAGESELECT::editTbl_getFieldEditArr","",0);
  203.  
  204.         // <pk-07-02-16> set some default values
  205.         if (empty($this->nullLabel)) $this->nullLabel"STARTPAGE";
  206.  
  207.         $a_ret=parent::editTbl_getFieldEditArr($debug);
  208.         $this->whereAnd=str_replace("m.MEN_ID=p.MEN_ID","",$this->whereAnd)// remove old values eventually stored in the db
  209.  
  210.         unset($a_ret['SELECT']['FLD_MULTISEL']);
  211.  
  212.         $a_ret['DBLOOKUP']['FLD_LUTBL']['FLDVAL']=$this->lookupTable;
  213.         $a_ret['DBLOOKUP']['FLD_VALFLD']['FLDVAL']=$this->lookupField;
  214.         $a_ret['DBLOOKUP']['FLD_SHOWLSTSORT']['FLDVAL']="ORDER BY m.MEN_ID, PAG_SORTORDER,<input name=\"sortAdd\" value=\"".htmlspecialchars($this->sortAdd)."\" size=\"40\">";
  215.         unset($a_ret['DBLOOKUP']['PARENTFIELD']);
  216.         unset($a_ret['DBLOOKUP']['IDENTFIELD']);
  217.  
  218.         $a_ret['DBLOOKUP']['FLD_PROJECTSEL']['FLDLAB']="Projektanzeige: ";
  219.         $a_ret['DBLOOKUP']['FLD_PROJECTSEL']['FLDVAL']="<select name=\"myProjSelectMode\" size=\"1\">\n";
  220.         foreach(self::$ps_sprojSelectModes as $key => $val{
  221.             $a_ret['DBLOOKUP']['FLD_PROJECTSEL']['FLDVAL'].="\t<option value=\"$key\"";
  222.             if ($key == $this->myProjSelectMode$a_ret['DBLOOKUP']['FLD_PROJECTSEL']['FLDVAL'].="selected ";
  223.             $a_ret['DBLOOKUP']['FLD_PROJECTSEL']['FLDVAL'].=">".t_admin($val['LABEL'])."</option>\n";
  224.         }
  225.         $a_ret['DBLOOKUP']['FLD_PROJECTSEL']['FLDVAL'].="</select>\n";
  226.  
  227.         $a_ret['DBLOOKUP']['FLD_OUTDATEDPAGES']=array(
  228.             'FLDLAB'=>"Abgelaufene Seiten:",
  229.             'FLDVAL'=>"<input type=\"checkbox\" name=\"showExpiredPages\" value=\"1\" ".(($this->showExpiredPages"checked" "")." >Seiten mit Anzeigen bis &lt; jetzt nicht anzeigen"
  230.             );
  231.  
  232.             unset($a_ret['FTBL_POPUPS']);
  233.  
  234.             return $a_ret;
  235.     }
  236.  
  237.  
  238.     /**
  239.      * save the filed definition form
  240.      *
  241.      * @return bool <code>parent::save()</code>
  242.      *
  243.      * @version pk-03-10-22
  244.      * @version pk-07-02-16 allow set of some values
  245.      *
  246.      ***/
  247.     function save()
  248.     {
  249.         $ret parent::save();
  250.         $this->lookupTable        = "T_CMS_PAGE";
  251.         $this->lookupShowField    = "CONCAT(IFNULL(PAG_TITLE,'NO TITLE'),' (',PAG_ID,')')";
  252.         $this->lookupField        = "PAG_ID";
  253.  
  254.         if (!empty($this->sortAdd)) $this->lookupSort.=",".$this->sortAdd;
  255.  
  256.         /* <pk-03-10-19> */
  257.         $this->myProjSelectMode   = intval($_POST['myProjSelectMode']);
  258.         $this->showExpiredPages   = ((isset($_POST['showExpiredPages']&& intval($_POST['showExpiredPages'])) TRUE FALSE );
  259.         $this->showSysDefault     = ((isset($_POST['showSysDefault'])   && intval($_POST['showSysDefault'])) TRUEFALSE);
  260.         /* </pk-03-10-19> */
  261.  
  262.         $this->allowNullSelect    $this->allowNull;   /* <pk-03-10-22 /> */
  263.  
  264.         return $ret;
  265.     }
  266.  
  267.  
  268.     // -------------------------------------------------
  269.     // field value methods
  270.     // -------------------------------------------------
  271.  
  272.     /**
  273.      * returns the field value
  274.      *
  275.      * @param  string  $aValue     the value
  276.      * @param  array   $err        error array
  277.      * @param  string  $arrName    global data array name used for global ${$arrName}
  278.      * @param  bool    $debug 
  279.      *
  280.      * @return string 
  281.      *
  282.      * @since   pk-03-12-13
  283.      * @version pk-03-12-13
  284.      * @version pk-08-08-11
  285.      *
  286.      * @requires CMS_PAGE
  287.      */
  288.     function getValue($aValue,&$err,$arrName="DBVAL",$debug=FALSE{
  289.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_PAGESELECT::getValue($aValue[".$this->getKey()."])");
  290.  
  291.         if (intval($aValue))
  292.         {
  293.             if ($this->mySelectedPage = CMS_PAGE::getInstance(intval($aValue)))
  294.             {
  295.                 if (!$this->showExpiredPages)
  296.                 {
  297.                     if ($this->mySelectedPage->isExpired())
  298.                     {
  299.                         if ($debugechoDebugLine(__FILE__,__LINE__,"Page is expired");
  300.                         $err['ERROR']=True;
  301.                         $err[$this->myName]['MSG']=t_admin("Die Seite ist nicht mehr verfügbar");
  302.                         $err[$this->myName]['LABEL']=$this->label;
  303.                         
  304.                         return False;
  305.                     }
  306.                 }                
  307.                 return $this->mySelectedPage->getId();
  308.             }
  309.         }
  310.  
  311.         if ($this->allowNullSelect{
  312.             $ret="0";
  313.         else {
  314.             $err['ERROR']=True;
  315.             $err[$this->myName]['MSG']=(empty($this->nullErrMsg$this->label.": NULL_NOT_ALLOWED" $this->nullErrMsg);;
  316.             $err[$this->myName]['LABEL']=$this->label;
  317.             return False;
  318.         }
  319.     }
  320.  
  321.     // -------------------------------------------------
  322.     // html rendering methods
  323.     // -------------------------------------------------
  324.  
  325.     /**
  326.      * returns one page option
  327.      *
  328.      * @param int $aValue 
  329.      * @param CMS_PAGE $pagObj 
  330.      * @param boolean $debug 
  331.      *
  332.      * @return string (html)
  333.      */
  334.     protected function getPageOption($aValue,$pagObj,$debug)
  335.     {
  336.         $str_ret "<option value=\"" $pagObj->getId("\"";
  337.             
  338.         if ($pagObj->getId(== intval($aValue))
  339.         {
  340.             $str_ret .= " selected=\"selected\"";
  341.         }
  342.         $str_ret .= ">";
  343.         $str_ret .= $pagObj->getTitle(" (" $pagObj->getId(")";
  344.         $str_ret .= "</option>";
  345.  
  346.         return $str_ret;
  347.     }
  348.  
  349.     /**
  350.      * returns the page option list for a menu node
  351.      *
  352.      * @param CMS_MENU $menObj 
  353.      * @param boolean $debug 
  354.      *
  355.      * @return string (html)
  356.      *
  357.      */
  358.     protected function addPageOptList($aValue,$menObj,$debug=False)
  359.     {
  360.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_PAGESELECT::addPageObtList()");
  361.          
  362.         $str_ret "";
  363.         if (method_exists($menObj,'getPageList'))
  364.         {
  365.             if ($menObj->getId())
  366.             {
  367.                 $str_ret .= "<optgroup label=\"M: " $menObj->getTitle("\">";
  368.             
  369.  
  370.             if ($arr_pages $menObj->getPageList(False,False,$debug))
  371.             {
  372.                 foreach($arr_pages as $obj_page)
  373.                 {
  374.                     if (!$this->showExpiredPages)
  375.                     {
  376.                         $str_ret .= $this->getPageOption($aValue,$obj_page,$debug);
  377.                     else if ($obj_page->getId(== intval($aValue)) {
  378.                         $str_ret .= $this->getPageOption($aValue,$obj_page,$debug);
  379.                     else if (!$obj_page->isExpired()){
  380.                         $str_ret .= $this->getPageOption($aValue,$obj_page,$debug);
  381.                     }
  382.                 }
  383.             }
  384.  
  385.             if ($arr_children $menObj->getChildrenList())
  386.             {
  387.                 foreach($arr_children as $obj_node)
  388.                 {
  389.                     $str_ret .= $this->addPageOptList($aValue,$obj_node,$debug);
  390.                 }
  391.             }
  392.             
  393.             
  394.             if ($menObj->getId())
  395.             {
  396.                 $str_ret .= "</optgroup>";
  397.             }
  398.                 
  399.         }
  400.         return $str_ret;
  401.     }
  402.  
  403.  
  404.     /**
  405.      * returns the html code for the &lt;select&gt field
  406.      *
  407.      * @param mixed $aValue 
  408.      * @param boolean $debug 
  409.      */
  410.     protected function getFormFieldSelect($aValue,$debug=False)
  411.     {
  412.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_PAGESELECT::getFormFieldSelect");
  413.  
  414.         $arr_attributes $this->getFormFieldSelectAttributes($debug);
  415.  
  416.          
  417.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_PAGESELECT::getMenuSelect()");
  418.          
  419.         switch($this->myProjSelectMode)
  420.         {
  421.             case 1:
  422.                 global ${$this->myDataArrName};
  423.                 $arr_proj array(CMS_PROJECT::getInstance(intval(${$this->myDataArrName}['PROJ_ID'])));
  424.                 break;
  425.             case 2:
  426.                 if (isset($_POST['PROJ_ID']&& intval($_POST['PROJ_ID']))
  427.                 {
  428.                     $arr_proj array(CMS_PROJECT::getInstance(intval($_POST['PROJ_ID'])));
  429.                 else if (isset($_GET['PROJ_ID']&& intval($_GET['PROJ_ID'])) {
  430.                     $arr_proj array(CMS_PROJECT::getInstance(intval($_GET['PROJ_ID'])));
  431.                 else {
  432.                     $arr_proj array(CMS_PROJECT::factoryFromId(0,True));
  433.                 }
  434.                 break;
  435.             case 3:
  436.                 $arr_projRows OCSP_OBJ::defaultReadDBObj()->getArray('T_CMS_PROJECT',array(),0,0,'PROJ_SORTORDER');
  437.                 $arr_proj array();
  438.                 if (is_array($arr_projRows))
  439.                 {
  440.                     foreach($arr_projRows as $arr_row)
  441.                     {
  442.                         if (!CMS_PROJECT::isInstanced(intval($arr_row['PROJ_ID'])))
  443.                         {
  444.                             CMS_PROJECT::setInstance(CMS_PROJECT::factoryFromDBRow($arr_row,$debug),$debug);
  445.                         }
  446.                         $arr_proj[CMS_PROJECT::getInstance(intval($arr_row['PROJ_ID']));
  447.                     }
  448.                 }
  449.                 break;
  450.         }
  451.          
  452.         $str_tag "<select name=\"" $this->getInputName(."\" id=\"" $this->getDOMId("\"";
  453.         if (is_array($arr_attributes))
  454.         {
  455.             foreach($arr_attributes as $str_att => $str_val)
  456.             {
  457.                 $str_tag .= " " $str_att "=" $str_val;
  458.             }
  459.         }
  460.          
  461.         $str_tag .= ">";
  462.  
  463.         foreach($arr_proj as &$obj_proj)
  464.         {
  465.             //$debug=True;
  466.             if ($debugechoDebugLine(__FILE__,__LINE__,"<pre>" print_r($obj_proj->getDBVal(),True"</pre>");
  467.  
  468.             if (self::$ps_sprojSelectModes[$this->myProjSelectMode]['WITHPROJ'])
  469.             {
  470.                 $str_tag .= "<optgroup label=\"" t_admin('Projekt'": " $obj_proj->getName(."\" title=\"" $obj_proj->getTitle(" Id: " $obj_proj->getId("\">";
  471.             }
  472.                 
  473.             if ($obj_tree $obj_proj->getMenuTree(True,$debug))
  474.             {
  475.                 $obj_rootNode $obj_tree->getNode(0,True);
  476.                 $obj_rootNode->setMyProject($obj_proj);
  477.                     
  478.                 $str_tag .= $this->addPageOptList($aValue,$obj_rootNode,$debug);
  479.             }
  480.  
  481.  
  482.             if (self::$ps_sprojSelectModes[$this->myProjSelectMode]['WITHPROJ'])
  483.             {
  484.                 $str_tag .= "</optgroup>";
  485.             }
  486.  
  487.         }
  488.          
  489.          
  490.         return $str_tag;
  491.     }
  492.  
  493.  
  494.  
  495. // end of DMBS_FIELD_PAGESELECT
  496. ?>

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