Source for file DBMS_FIELD_MEDIAFILE_SELID.phpclass

Documentation is available at DBMS_FIELD_MEDIAFILE_SELID.phpclass

  1. <?php
  2. /**
  3.   * Class file DBMS_FIELD_MEDIAFILE_SELID.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms_field
  7.   * @category   int
  8.   *
  9.   * @author     Peter Krebs (pk) <p.krebs@lvus.at>
  10.   * @copyright  (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   * @since pk-05-10-10
  14.   *
  15.   ***/
  16.  
  17. require_once dirname(__FILE__)."/DBMS_FIELD_FOREIGNKEY.phpclass";
  18. require_once __OCSP_DEFAULTCONFPATH__."media.conf.phpinc";
  19.  
  20. /**
  21.   * handles foreign key fields
  22.   *
  23.   * @project    Open CSP-Management
  24.   * @package    dbms_field
  25.   * @category   int
  26.   *
  27.   * @author     Peter Krebs (pk) <p.krebs@lvus.at>
  28.   * @copyright  (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
  29.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  30.   *
  31.   * @since pk-05-10-10
  32.   *
  33.   ***/
  34.     /**
  35.       * overwrite parent settings
  36.       **/
  37.  
  38.     /**
  39.       * @staticvar string $className 
  40.       ***/
  41.     var $className          = "MEDIAFILE_SELID";
  42.     /**
  43.       * @var string $foreignTbl name of the media files table
  44.       ***/
  45.     var $foreignTbl         = "T_MED_FILES";
  46.     /**
  47.       * @var string $showField columnname or sql statement to use to show the
  48.       ***/
  49.     var $showField          = "MEF_NAME";
  50.     /**
  51.       * @var string $showField columnname or sql statement to use to show the
  52.       ***/
  53.     var $keyField           = "MEF_ID";
  54.     /**
  55.       * @var string $showField columnname or sql statement to use to show the
  56.       ***/
  57.     var $sortField          = "MIM_ID,MEF_NAME";
  58.  
  59.     /**
  60.       * source file of the class
  61.       *
  62.       * @var string $classSrcFile 
  63.       * @since pk-05-01-20
  64.       ***/
  65.     var $classSrcFile=__FILE__;
  66.  
  67.     /**
  68.       * @var int $mecRootId id of the root category
  69.       ***/
  70.     var $mecRootId=0;
  71.  
  72.     /**
  73.       * @var int $cur_mecId id currently selected (not stored to the db)
  74.       * @since pk-06-08-09
  75.       ***/
  76.     var $cur_mecId=0;
  77.  
  78.     /**
  79.       * @var boolean $allowNewMedia user can add media files if he has the rights for the category
  80.       ***/
  81.     var $allowNewMedia=TRUE;
  82.  
  83.     /**
  84.       * @var boolean $allowChangeCat allow to change into subcategories of $this::mecRootId
  85.       * @since pk-06-08-09
  86.       ***/
  87.     var $allowChangeCat=FALSE;
  88.  
  89.     /**
  90.       * @var boolean $allowNewSubCat allow to add new categories under $this::mecRootId
  91.       * @since pk-06-08-09
  92.       ***/
  93.     var $allowNewSubCat=FALSE;
  94.  
  95.     /**
  96.       * @var boolean $allowEditMedia user can edit the media files if he has the rights for the category
  97.       ***/
  98.     var $allowEditMedia=TRUE;
  99.  
  100.     /**
  101.       * returns an array of field to bie shown in the edit form
  102.       * by using editTbl_echoForm
  103.       *
  104.       * the array is in the form:
  105.       *
  106.       * <code>
  107.       * [_sectionName_]
  108.       *      [TITLE] -> string
  109.       *      [_rowName_]
  110.       *         [FLDLAB]  (complete html code with <td></td>)
  111.       *         [FLDVAL] (complete html code with <td></td>)
  112.       * </code>
  113.       *
  114.       * @param boolean $debug 
  115.       *
  116.       * @returns array
  117.       *
  118.       * @since pk-06-04-26
  119.       * @version pk-06-04-29
  120.       *
  121.       ***/
  122.     function editTbl_getFieldEditArr($debug=FALSE{
  123.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FOREIGNKEY::editTbl_getFieldEditArr","",0);
  124.         $a_ret=parent::editTbl_getFieldEditArr($debug);
  125.  
  126.         if (empty($this->showField)) $this->showField="MEF_NAME";
  127.         if (empty($this->sortField)) $this->sortField="MIM_ID,MEF_NAME";
  128.  
  129.         unset($a_ret['DBLOOKUP']['FLD_VALFLD']);
  130.         unset($a_ret['DBLOOKUP']['FLD_FRMRELOAD']);
  131.         $a_ret['DBLOOKUP']['FLD_FOREIGNTBL']['FLDVAL']="T_MED_FILES.MED_ID";
  132.         $a_ret['DBLOOKUP']['FLD_FOREIGNTBL']['FLDVAL'].="
  133.             <a onClick=\"
  134.                 var tblName=getSelectedOptionByName(document.forms['frmEdit'],'foreignTbl');
  135.                 if (tblName=='') {
  136.                     alert('W�hlen Sie zuerst eine Tabelle aus');
  137.                 } else {
  138.                     var link='".$GLOBALS['PROJECT']['ADMINURL']."phpmyadmin/tbl_properties_structure.php?db=".$GLOBALS['USRDB']->getMyDBName()."';
  139.                     link=link+'&table=T_MED_FILES';
  140.                     openLinkWnd(link);
  141.                 }
  142.             \" title=\"Tabelle in phpMyAdmin zeigen\">
  143.                 <img src=\"".$GLOBALS['OCSP']['SYSIMGURL']."icons-16x16/b_browse.png\" border=\"0\" class=\"button\">
  144.             </a>";
  145.         $a_ret['DBLOOKUP']['FLD_MEDIACAT']['FLDLAB'='Medienkategorie';
  146.         $a_ret['DBLOOKUP']['FLD_MEDIACAT']['FLDVAL'=$this->getCatSelectTree(NULL,0,"EDIT",FALSE,0,$debug);
  147.         $a_ret['DBLOOKUP']['FLD_MEDIACAT']['FLDVAL'].="
  148.                     <input type=\"checkbox\" name=\"allowChangeCat\" value=\"1\" ".($this->allowChangeCat ? "checked":"").">
  149.                     Wechesl in Unterkategorien zulassen.
  150.                     ";
  151.  
  152.         $a_ret['FTBL_POPUPS']=array(
  153.             'TITLE'=>"Bearbeiten/Hinzuf&uuml;gen",
  154.             'FLD_ALLOWNEWMED'=>array(
  155.                     'FLDLAB'=>'Neue Medien',
  156.                     'FLDVAL'=>"
  157.                         <input type=\"checkbox\" name=\"allowNewMedia\" value=\"1\"  ".($this->allowNewMedia  ? "checked" :"")."> ja, upload von Medien erlabuen.<br />
  158.                         <input type=\"checkbox\" name=\"allowNewSubCat\" value=\"1\" ".($this->allowNewSubCat ? "checked" :"")."> ja neue Medienkategorie erlauben"
  159.             ),
  160.             'FLD_NEWPUP'=>array(
  161.                 'FLDLAB'=>"Neuer Datensatz URL",
  162.                 'FLDVAL'=>"<input name=\"newUrl\" value=\"".$this->newUrl."\" size=\"40\">"
  163.             ),
  164.             'FLD_ALLOWEDITMED'=>array(
  165.                     'FLDLAB'=>'Medien bearbeiten',
  166.                     'FLDVAL'=>"<input type=\"checkbox\" name=\"allowEditMedia\" value=\"1\" ".($this->allowEditMedia ? "checked" :"")."> ja, bearbeiten von Medien erlabuen."
  167.             ),
  168.             'FLD_EDITPUP'=>array(
  169.                 'FLDLAB'=>"Datensatz bearbeiten URL",
  170.                 'FLDVAL'=>"<input name=\"editUrl\" value=\"".$this->editUrl."\" size=\"40\">"
  171.             ),
  172.             'FLD_PUPARGS'=>array(
  173.                 'FLDLAB'=>"Popup Arguments",
  174.                 'FLDVAL'=>'<input name="myURIQueryArrgs" value="'.$this->myURIQueryArrgs.'" size="40"><br />(durch Semicolon ";" getrennte Feldnamen)'
  175.             ),
  176.             'FLD_POPUPSIZE'=>array(
  177.                 'FLDLAB'=>"Popup Gr&ouml;&szlig;e",
  178.                 'FLDVAL'=>"
  179.                             width=<input  name=\"popupWndWidth\" value=\"".$this->popupWndWidth."\"  size=\"4\">&nbsp;
  180.                             height=<input name=\"popupWndHeight\"  value=\"".$this->popupWndHeight."\"  size=\"4\">
  181.                           "
  182.             )
  183.         );
  184.         return $a_ret;
  185.     }
  186.  
  187.  
  188.     /**
  189.       * save the filed definition form
  190.       *
  191.       * @return bool <code>parent::save()</code>
  192.       * @version pk-03-10-17
  193.       *
  194.       ***/
  195.     function save($debug=FALSE{
  196.         $ret=parent::save($debug);
  197.  
  198.         $this->foreignTbl           ="T_MED_FILES";
  199.         $this->keyField             ="MEF_ID";
  200.         $this->reloadFormOnChange   =FALSE;
  201.         $this->mecRootId            =intval($_POST['EDIT_MEC_ID_'.$this->myName]);
  202.  
  203.         $this->allowChangeCat       =(intval($_POST['allowChangeCat'])  TRUE FALSE);
  204.         $this->allowNewMedia        =(intval($_POST['allowNewMedia'])   TRUE FALSE);
  205.         $this->allowNewSubCat       =(intval($_POST['allowNewSubCat'])  TRUE FALSE);
  206.         $this->allowEditMedia       =(intval($_POST['allowEditMedia'])  TRUE FALSE);
  207.  
  208.         return $ret;
  209.     }
  210.  
  211.     // ###########################################
  212.  
  213.     /**
  214.       * returns the where part of to select the foreign Value
  215.       *
  216.       * @param string $arrName 
  217.       * @param string $append 
  218.       * @param boolean $debug 
  219.       * @param boolean $withWhereAnd 
  220.       *
  221.       * @returns string
  222.       *
  223.       * @version pk-06-08-08
  224.       * @version pk-07-02-08 bugfix with $append
  225.       *
  226.       ***/
  227.     function getWhereStmt($arrName="DBVAL",$append="",$debug=FALSE,$withWhereAnd=TRUE{
  228.         $debug=($debug || $this->fldDebug);
  229.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_MEDIAFILE_SELID::getWhereStmt()");
  230.  
  231.         if (!strstr($append,"MEF_ID")) {
  232.             if (!empty($append)) $append.=" AND"// <pk-07-02-08 />
  233.             $append.=" MEC_ID=".(intval($this->cur_mecIdintval($this->cur_mecIdintval($this->mecRootId))// <pk-07-02-08> use cur_mecId if is set
  234.         }
  235.         return parent::getWhereStmt($arrName,$append,$debug,$withWhereAnd);
  236.  
  237.     }
  238.     // ###########################################
  239.  
  240.  
  241.     /**
  242.       * returns the html code for category select tree
  243.       *
  244.       * @param int $aValue 
  245.       * @param int $catTreeRoot 
  246.       * @param string $arrName 
  247.       * @param boolean $reloadOnChange 
  248.       * @param int $mecId 
  249.       * @param boolean $debug 
  250.       *
  251.       * @return string 
  252.       *
  253.       ***/
  254.     function getCatSelectTree($aValue,$catTreeRoot=0,$arrName="DBVAL",$reloadOnChange=TRUE,$mecId=0,$debug=FALSE{
  255.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_MEDIAFILE_SELID::getCatSelectTree(ROOT: ".intval($catTreeRoot).")");
  256.  
  257.         require_once $GLOBALS['OCSP_MED']['PHPINCPATH']."MED_CATEGORY.phpclass";
  258.  
  259.         if (intval($mecId)) {
  260.             $i_mecId=intval($mecId);
  261.         else if (intval($aValue)) {
  262.             $i_mecId=intval($GLOBALS['USRDB']->quickQuery("SELECT MEC_ID FROM T_MED_FILES WHERE MEF_ID=".intval($aValue),0));
  263.         else {
  264.             $i_mecId=$this->mecRootId;
  265.         }
  266.  
  267.         $this->cur_mecId=$i_mecId// <pk-06-08-09 /> is used for generating queries
  268.  
  269.         if ($debugecho "<p style=\"padding-left: 20px;\">MEC_ID set to: ".$this->cur_mecId."</p>";
  270.  
  271.         $ret="\n<select ";
  272.         $ret.=" name=\"".$arrName."_MEC_ID_".$this->myName."\" size=\"1\" ";
  273.         $ret.=" onChange=\"document.forms['".$this->getMyFormName()."'].action='".$frmReloadURL."#".$this->myName."';document.forms['".$this->getMyFormName()."'].submit();\"";
  274.         $ret.=">\n";
  275.         if (!intval($this->mecRootId)) {
  276.             $ret.="<option value=\"\">Wurzel</option>\n";
  277.         }
  278.         $mecTree=new MED_CATEGORY();
  279.         $mecTree->populateTree(TRUE,FALSE);
  280.         if (intval($catTreeRoot)) {
  281.             $o_mecRoot=$mecTree->getNode(intval($catTreeRoot),FALSE);
  282.         else {
  283.             $o_mecRoot=NULL;
  284.         }
  285.         $ret.= $mecTree->getHTMLSelectOptionList($o_mecRoot,$i_mecId,FALSE);
  286.         $ret.="\n</select>";
  287.  
  288.         return $ret;
  289.     }
  290.  
  291.  
  292.     /**
  293.       * returns the html code for the add Button
  294.       *
  295.       * @param string $arrName 
  296.       * @param string $url 
  297.       *
  298.       * @returns string
  299.       *
  300.       * @since pk-04-08-31
  301.       * @version pk-05-03-17 getPopupLinkJs added -> rewrite
  302.       *
  303.       ***/
  304.     function getAddButton($arrName="",$url="",$debug=FALSE{
  305.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_MEDIAFILE_SELID::getAddButton()");
  306.  
  307.         require_once $GLOBALS['MED']['PHPINCPATH']."MED_CATEGORY_NODE.phpclass";
  308.  
  309.         $this->myDataArrName=$arrName;
  310.         global ${$arrName};
  311.         $i_mecId=(isset(${$arrName['MEC_ID']}intval(${$arrName['MEC_ID']}$this->mecRootId);
  312.         $i_mecId=(intval($this->cur_mecId$this->cur_mecId : $i_mecId);
  313.         $o_mecNode=new MED_CATEGORY_NODE($i_mecId);
  314.  
  315.         if ($o_mecNode->curUserCanUpload()) {
  316.             ${$arrName}['MEC_ID']=$o_mecNode->getId();
  317.             if (empty($this->myURIQueryArrgs)) {
  318.                 $this->myURIQueryArrgs="MEC_ID";
  319.             else if (!strstr($this->myURIQueryArrgs,"MEC_ID")) {
  320.                 $this->myURIQueryArrgs.=";MEC_ID";
  321.             }
  322.             $s_jsCmd=$this->getPopupLinkJs($GLOBALS['OCSP_MED']['CMS_WEBROOT']."file/newmedia.php",FRM_MODE_NEW,$debug);
  323.             $s_aName=$this->getMyFormName()."_".$this->myDataArrName."_".$this->myName;
  324.             $s_ret ="<a name=\"".$s_aName."\" href=\"#".$s_aName."\" onClick=\"".$s_jsCmd."\">";
  325.             $s_ret.="<img src=\"".$GLOBALS['PROJECT']['SYSIMGURL']."icons-16x16/filenew.gif\" border=\"0\" alt=\"hinzuf�gen\" class=\"button\">";
  326.             $s_ret.="</a>\n";
  327.             return $s_ret;
  328.         else {
  329.             return "";
  330.         }
  331.     }
  332.  
  333.     /**
  334.       * returns the html code for inputting the value
  335.       *
  336.       * @param mixed $aValue the value to set
  337.       * @param string $arrName 
  338.       * @param string $nameAdd  append something to name like "[VALUE]" for search forms
  339.       *
  340.       * @returns string
  341.       *
  342.       * @since pk-06-08-09
  343.       *
  344.       ***/
  345.     function getInputTag($aValue,$arrName="DBVAL",$nameAdd="",$debug=FALSE{
  346.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_MEDIAFILE_SELID::getInputTag()");
  347.  
  348.         if (!empty($arrName)) $this->setDataArrName($arrName);
  349.  
  350.         $s_ret="";
  351.         if ($this->allowChangeCat{
  352.             if (isset($_POST[$arrName."_MEC_ID_".$this->myName]&&  intval($_POST[$arrName."_MEC_ID_".$this->myName])) {
  353.                 // we have a reload of the form use the postet value
  354.                 $i_mecId=intval($_POST[$arrName."_MEC_ID_".$this->myName]);
  355.             else if (intval($aValue)) {
  356.                 $i_mecId=0// let getCatSelectTree find the category ID out of the value or the mecRootId
  357.             }
  358.             $s_ret.=$this->getCatSelectTree($aValue,$this->mecRootId,$arrName,TRUE,$i_mecId,$debug);
  359.         else {
  360.             if (!intval($this->mecRootId)) {
  361.                 // configuration error
  362.                 return "<p>CONFIGURATION ERROR: the field has no Category Root ID set</p>";
  363.             }
  364.             if (intval($aValue)) {
  365.                 $s_query="SELECT MEC_NAME FROM T_MED_CATEGORY c,T_MED_FILES f WHERE c.MEC_ID=f.MEC_ID and MEF_ID=".intval($aValue);
  366.                 if ($s_mecName=$GLOBALS[$this->get_gDBIDX()]->quickQuery($s_query,0)) {
  367.                     $s_ret.=$s_mecName;
  368.                 else  {
  369.                     $s_query="SELECT MEC_NAME FROM T_MED_CATEGORY WHERE MEC_ID=".intval($this->mecRootId);
  370.                     $s_ret.=$GLOBALS[$this->get_gDBIDX()]->quickQuery($s_query,0);
  371.                 }
  372.             }
  373.             $this->cur_mecId=intval($this->mecRootId)// <pk-06-08-09 /> is used for generating queries
  374.         }
  375.  
  376.         $s_ret.=$this->getSelect($aValue,$debug,$nameAdd);
  377.  
  378.         return $s_ret;
  379.     }
  380.  
  381.     // ###########################################################
  382.     // OBJECT VALUE CHECK/RETURN METHODS
  383.     // ###########################################################
  384.  
  385.  
  386.  
  387. }
  388. ?>

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