Source for file CMS_CHAPTER_V2.phpclass

Documentation is available at CMS_CHAPTER_V2.phpclass

  1. <?php
  2. /**
  3.   * Class file CMS_CHAPTER_V2.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    cms
  7.   * @category   chapter
  8.   *
  9.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  10.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  11.   *
  12.   * @version $Id: CMS_CHAPTER_V2.phpclass,v 1.11 2008/08/11 08:37:38 pitlinz Exp $
  13.   */
  14.  
  15. /*
  16. require_once __OCSP_DEFAULTCONFPATH__."cms.conf.phpinc";
  17. require_once __OCSP_CMS_PHPINCPATH__."template/chapter/TMPL_CHAPTER_V3.phpclass";
  18. */
  19.  
  20.     // ---------------------------------------------------------
  21.     // requirements
  22.     // ---------------------------------------------------------
  23.  
  24.     pcf_require_class('CMS_CHAPTER',dirname(__FILE__"/");
  25.  
  26. /**
  27.   * Handels CMS Chapters
  28.   *
  29.   * @project    Open CSP-Management
  30.   * @package    cms
  31.   * @category   chapter
  32.   *
  33.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  34.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  35.   *
  36.   * @since   pk-03-12-14
  37.   *
  38.   * @version $Id: CMS_CHAPTER_V2.phpclass,v 1.11 2008/08/11 08:37:38 pitlinz Exp $
  39.   */
  40. class CMS_CHAPTER_V2 extends CMS_CHAPTER 
  41. {
  42.     // ---------------------------------------------------------------------------
  43.     // constants
  44.     // ---------------------------------------------------------------------------
  45.     
  46.     /**
  47.      * @constant string CLASS_SRC_FILE
  48.      */
  49.     const CLASS_SRC_FILE = __FILE__;
  50.     
  51.     /**
  52.       * @staticvar string $moduleKey 
  53.       * @since pk-05-07-20
  54.       ***/
  55.     var $moduleKey="CMS";
  56.  
  57.     /**
  58.       * @staticvar string $mytmplCol   the column name for the page template foreign key
  59.       ***/
  60.     var $myTmplCol="CTMP_ID";
  61.  
  62.     /**
  63.       * @staticvar string $myPageTmplCol   the column name for the page template foreign key
  64.       ***/
  65.     var $myPageTmplCol="PTMP_ID";
  66.  
  67.     /**
  68.       * @staticvar string $myTmplClass 
  69.       *  make sure the class file is included if you overwrite this
  70.       ***/
  71.     var $myTmplClass="TMPL_CHAPTER_V3";
  72.  
  73.  
  74.     /**
  75.       * @staticvar  string  $colPrevix   the column name for the chapter columns
  76.       ***/
  77.     var $colPrevix"CHA_";
  78.  
  79.  
  80.     /**
  81.       * @staticvar int $mySrcVersion 
  82.       ***/
  83.     var $mySrcVersion = "2";
  84.  
  85.     /**
  86.       * @var string $classSrcFile source file of the class
  87.       ***/
  88.     var $myClassSrcFile=__FILE__;
  89.  
  90.  
  91.     /**
  92.      * returns a the chapter object for chapter ID: $aId
  93.      *
  94.      * @param int $aId 
  95.      * @param boolean $debug 
  96.      * 
  97.      * @return CMS_CHAPTER_V2 
  98.      * 
  99.      * @since pk-08-01-15
  100.      */
  101.     static public function factoryFromId($aId,$debug=False
  102.     {
  103.         if ($debugechoDebugMethod(__FILE__,"static","CMS_CHAPTER_V2::factoryFromId()");
  104.         
  105.         $obj_ret new CMS_CHAPTER_V2();
  106.         
  107.         if (intval($aId))
  108.         {
  109.             $obj_ret->setId($aId);
  110.             $obj_ret->dbPopulate($debug);
  111.         }
  112.         
  113.         return $obj_ret;
  114.         
  115.     }
  116.     
  117.     /**
  118.       * cunstructor
  119.       *
  120.       * @param int $aId 
  121.       * @param string $gDBIDX 
  122.       * @param boolean $autoPopulate 
  123.       * @param boolean $debug 
  124.       *
  125.       ***/
  126.     function CMS_CHAPTER_V2($aId=0,$autoPopulate=TRUE,$debug=FALSE{      
  127.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_CHAPTER_V2::CMS_CHAPTER_V2($aId)");
  128.         $this->init($debug);
  129.  
  130.         $this->setId(intval($aId));
  131.         if (intval($aId)) {
  132.             if ($autoPopulate$this->dbPopulate($debug);
  133.         }
  134.     }
  135.     
  136.     /**
  137.      * returns a the chapter object for chapter ID: $aId
  138.      *
  139.      * @param int $aId 
  140.      * @param boolean $debug 
  141.      * 
  142.      * @return CMS_CHAPTER_V2 
  143.      * 
  144.      * @since pk-08-01-15
  145.      */
  146.     static public function CMS_CHAPTER_FROM_ID($aId,$debug=FALSE
  147.     {
  148.         return new CMS_CHAPTER_V2($aId,$debug);
  149.     }
  150.     
  151.     
  152.  
  153.     /**
  154.       * @param int $aId 
  155.       ***/
  156.     function setId($aId{
  157.         $this->db_SetKey($this->colPrevix."ID",intval($aId));
  158.     }
  159.  
  160.  
  161.     /**
  162.       * returns the class name of the object to store in the db
  163.       * overwrite in child classes
  164.       *
  165.       * @returns string
  166.       *
  167.       * @since pk-07-01-09
  168.       *
  169.       ***/
  170.     function getChapterTypeName({
  171.         return "CMS_CHAPTER_V2";
  172.     }
  173.  
  174.     /**
  175.       * @return int 
  176.       */
  177.     function getShowMode()
  178.     {
  179.         return intval($this->getDBField($this->colPrevix.'SHOWMODE'));
  180.     }
  181.  
  182.  
  183.     // ####################################################################
  184.     // db methods
  185.     // ####################################################################
  186.  
  187.     /**
  188.       * merges {$this->colPrevix."FIELDS"} with Object values
  189.       *
  190.       * @param bool $debug 
  191.       *
  192.       * @return int sizeof myObjVals
  193.       *
  194.       * @since pk-05-08-26
  195.       *
  196.       * @var array $a_fldArr 
  197.       * @var string $s_key 
  198.       * @var mixed $m_val 
  199.       *
  200.       ***/
  201.     function populateObjVals($debug=FALSE{
  202.         if ($debugecho "<hr><p><b>CMS_CHAPTER_V2::populateObjVals()</b> (".get_class($this).")</p>";
  203.  
  204.         parent::populateObjVals($debug);
  205.         if (!empty($this->{$this->colPrevix."FIELDS"})) {
  206.             // we have an old version where object values are stored
  207.             // serialized in column {$this->colPrevix."FIELDS"}
  208.             $a_fldArr=@unserialize($this->{$this->colPrevix."FIELDS"});
  209.             if ($debugecho "fldArr:<pre style=\"font-size:75%\">".nl2br(htmlspecialchars(print_r($a_fldArr,TRUE)))."</pre>";
  210.             if (is_array($a_fldArr)) {
  211.                 foreach($a_fldArr as $s_key => $m_val{
  212.                     if (!isset($this->myObjVals[$key])) {
  213.                         $this->setObjValValue($s_key,$m_val);
  214.                     }
  215.                 }
  216.             }
  217.             $this->myObjValsPopulateTS=time();
  218.             if ($debugecho "myObjVals:<pre style=\"font-size:75%\">".nl2br(htmlspecialchars(print_r($this->myObjVals,TRUE)))."</pre>";
  219.         }
  220.         return sizeof($this->myObjVals);
  221.     }
  222.  
  223.     /**
  224.       * inserts a new row to the table
  225.       * and checks SORTORDER
  226.       *
  227.       * @param string $gDBIDX Index of $GLOBALS to the db object
  228.       * @param bool   $debug  show debug info
  229.       *
  230.       * @return int   returns the autoIncFld ID if exists or 1 on success
  231.       *
  232.       * @version pk-05-08-26
  233.       * @version pk-07-01-09
  234.       *
  235.       ***/
  236.     function dbInsert($debug=FALSE{
  237.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_CHAPTER_V2::dbInsert()");
  238.  
  239.         if (!$this->getPageId())
  240.         {
  241.             return FALSE;
  242.         }
  243.             
  244.         if (!$this->getProjId())
  245.         {
  246.             $obj_page=$this->getMyPageObj($debug);
  247.             $this->setProjId($obj_page->getProjId());
  248.         }        
  249.         
  250.         if (!$this->getTmplId())
  251.         {
  252.             return FALSE;
  253.         }
  254.       
  255.         if (!intval($this->{$this->colPrevix."SORTORDER"})) {
  256.             $s_Query ="SELECT MAX(IFNULL(".$this->colPrevix."SORTORDER,0)) ";
  257.             $s_Query.="  FROM ".$this->myTable;
  258.             $s_Query.=" WHERE ".$this->myPageIdCol."=".$this->getPageId();
  259.             $this->{$this->colPrevix."SORTORDER"}=intval($GLOBALS[$gDBIDX]->quickQuery($s_Query,0)) 1;
  260.         }
  261.  
  262.         if (!intval($this->{$this->myPageTmplCol}&& (intval($this->getTmplId()))) {
  263.             $this->{$this->myPageTmplCol}=$this->getPageTmplId($debug);
  264.         }
  265.         
  266.         if (!$this->getProjId())
  267.         {
  268.             
  269.         }
  270.         
  271.  
  272.         $this->setDBField('CHA_CLASS',$this->getChapterTypeName());
  273.         $this->setDBField('CHA_CREATE_BY',$GLOBALS['USER']->getId());
  274.         $this->setDBField('CHA_CREATE_AT','CURRENT_TIMESTAMP');
  275.  
  276.         echoDebugLine(__FILE__,__LINE__,"Values: <pre>".print_r($this->getDBVal(),TRUE)."</pre>");
  277.         return parent::dbInsert($debug);
  278.     }
  279.  
  280.     /**
  281.       * replaces a row in the table
  282.       *
  283.       * if the object has not been populated (!$this->populateTS)
  284.       * FALSE is returned
  285.       *
  286.       * @param bool   $debug  show debug info
  287.       * @param boolean $ignorPopulated (if false the table MUST have been populated)
  288.       *
  289.       * @return bool 
  290.       *
  291.       * @version pk-07-01-09
  292.       ***/
  293.     function dbReplace($debug=FALSE,$ignorPopulated=FALSE{
  294.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_CHAPTER_V2::dbReplace()");
  295.  
  296.         $this->setDBField('CHA_CLASS',$this->getChapterTypeName());
  297.         $this->setDBField('CHA_LASTCHANGE_BY',$GLOBALS['USER']->getId());
  298.         $this->setDBField('CHA_LASTCHANGE_AT','CURRENT_TIMESTAMP');
  299.  
  300.         if (($this->hasObjVals&& (!empty($this->{$this->colPrevix."FIELDS"}))){
  301.             if ($this->myObjValsPopulateTS (time()-60)) $this->populateObjVals($debug);
  302.             unset($this->{$this->colPrevix."FIELDS"});
  303.         }
  304.         return parent::dbReplace($debug,$ignorPopulated);
  305.     }
  306.  
  307.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  308.     // template methods
  309.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  310.  
  311.     /**
  312.       * @return int 
  313.       ***/
  314.     function getTmplId({
  315.         return intval($this->{$this->myTmplCol});
  316.     }
  317.     
  318.     /**
  319.       * @param int $tmplId 
  320.       */
  321.     function setTmplId($tmplId{
  322.         $this->{$this->myTmplCol$tmplId;
  323.     }
  324.  
  325.     /**
  326.       * sets the templateobject;
  327.       *
  328.       * @param TMPL_CHAPTER $chatmpl; 
  329.       * @param boolean $debug 
  330.       *
  331.       ***/
  332.     function setTemplateObj(&$chatmpl,$debug=FALSE{
  333.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_CHAPTER_V2::setTemplateObj(...)");
  334.         parent::setMyTemplate($chatmpl);
  335.     }
  336.  
  337.     /**
  338.       * sets the TemplateObject by ID
  339.       *
  340.       * @param int $chaTmplId 
  341.       * @param boolean $debug 
  342.       *
  343.       * @return boolean 
  344.       *
  345.       * @var string $s_cmd 
  346.       * @var TMPL_CHAPTER_V3 $o_tmpl 
  347.       *
  348.       ***/
  349.     function setTemplateObjId($chaTmplId,$debug=FALSE{       
  350.         if ($debugecho "<p><b>CMS_CHAPTER_V2::setTemplateObjId($chaTmplId)</b> (".get_class($this).")</p>\n";
  351.  
  352.         if (!intval($chaTmplId)) return FALSE;
  353.  
  354.         if (is_object($this->myTemplate&& ($this->myTemplate->getId()==$chaTmplId)) {
  355.             // nothing to do we already have the template loaded
  356.             return TRUE;
  357.         }
  358.  
  359.         $o_tmpl=NULL;
  360.         $s_cmd="\$o_tmpl= new ".$this->myTmplClass."(".intval($chaTmplId).");";
  361.         if ($debugecho "<p>creating object: <br >\n\t".$s_cmd."</p>\n";
  362.  
  363.         eval($s_cmd);
  364.         if ((is_object($o_tmpl)) && ($o_tmpl->getId()==$chaTmplId)) {
  365.             $this->setTemplateObj($o_tmpl);
  366.             return TRUE;
  367.         }
  368.         return FALSE;
  369.     }
  370.  
  371.  
  372.  
  373.  
  374.     /**
  375.       * return the page template ID
  376.       *
  377.       * @param boolean $debug 
  378.       *
  379.       * @return int 
  380.       *
  381.       ***/
  382.     function getPageTmplId($debug=FALSE{
  383.         if ($debug{
  384.             echo "<p><b>CMS_CHAPTER_V2::getPageTmplId()</b> (".get_class($this).")</b>\n";
  385.             echo "<p>Checking Field: ".$this->myPageTmplCol.": ".intval($this->{$this->myPageTmplCol})."</p>";
  386.         }
  387.         if (intval($this->getDBField($this->myPageTmplCol))) return intval($this->getDBField($this->myPageTmplCol));
  388.  
  389.         if (!is_object($this->myTemplate)) {
  390.             if (!$this->setTemplateObjId($this->getTmplId(),$debug)) {
  391.                 return 0;
  392.             }
  393.         }
  394.  
  395.         return $this->myTemplate->getPTMPId($debug);
  396.     }
  397.  
  398.  
  399.     /**
  400.       * sets page filds used to identify the object
  401.       *
  402.       * @param  CMS_PAGE    $pagObj 
  403.       * @param  bool        $debug 
  404.       *
  405.       ***/
  406.     function setFromPageObj($pagObj,$debug=FALSE{
  407.         if (is_object($pagObj)) {
  408.             $this->setArray($pagObj->getDBVAL(),FALSE,TRUE,$debug);
  409.         }
  410.     }
  411.  
  412.  
  413.     /**
  414.       * returns a chapter input form not a database form
  415.       * as we have chapter fields not represented in the
  416.       * db model
  417.       *
  418.       * returns the form from the template
  419.       *
  420.       * @param int $mode 
  421.       * @param string $frmName 
  422.       * @param boolean $debug 
  423.       *
  424.       * @return DBMS_FORM 
  425.       *
  426.       * @version pk-06-02-17
  427.       *
  428.       * @var DMBS_FORM $frmObj 
  429.       ***/
  430.     function &dbGetForm($mode=0,$frmName="",$debug=FALSE)  {
  431.         if ($debugecho "<p><b>CMS_CHAPTER_V2::dbGetForm(MODE$mode,FORM$frmName,...)</b> (".get_class($this).")</p>\n";
  432.  
  433.         if (!is_object($this->myTemplate)) {
  434.             if (!$this->setTemplateObjId($this->getTmplId())) {
  435.                 $frmObj=parent::dbGetForm($mode,$frmName,$debug);
  436.             }
  437.         }
  438.  
  439.         $this->myTemplate->setConttable($this->myTable);
  440.         if ($frmObj=$this->myTemplate->getChapterForm($frmName,$debug)) {
  441.             if (!empty($this->myClassSrcFile)) {
  442.                 if ($debugecho "<p>myClassSrcFile=".$this->myClassSrcFile."</p>";
  443.                 $frmObj->myDBMS_TABLEOBJ_include=$this->myClassSrcFile;
  444.                 $frmObj->myDBMS_TABLEOBJ_class  =get_class($this);
  445.             }
  446.             if (($mode==FRM_MODE_NEW|| ($mode==FRM_MODE_EDIT)) {
  447.                 $frmObj->hideField('NLTP_ID');
  448.                 $frmObj->hideField('PTMP_ID');
  449.             }
  450.             $frmObj->hideField($this->colPrevix."FIELDS");
  451.         else {
  452.             $frmObj=parent::dbGetForm($mode,$frmName,$debug);
  453.         }
  454.  
  455.         $s_showModes=$this->myTemplate->getDBField("CTMP_ALLOWED_SHOWMODE");
  456.         if ((is_object($frmObj)) && (!empty($s_showModes))) {
  457.             require_once $GLOBALS['OCSP']['DBMSFLD_PATH']."DBMS_FIELD_DBLOOKUPSELECTLIST.phpclass";
  458.             $o_fld=&$frmObj->getField("CHA_SHOWMODE",$this->myTable,$debug);
  459.             if (!pcf_is_instance_of($o_fld,"DBMS_FIELD_DBLOOKUPSELECTLIST")) {
  460.                 $o_fld=pcf_castObject($o_fld,"DBMS_FIELD_DBLOOKUPSELECTLIST",$debug);
  461.             }
  462.             $o_fld->lookupTable "T_LOOKUP_CHA_SHOWMODE";
  463.             $o_fld->lookupShowField "CONCAT(LUP_VALUE,' (',LUP_KEY,')')";
  464.             $o_fld->lookupField "LUP_KEY";
  465.             $o_fld->lookupWhere "LUP_KEY IN (".$s_showModes.")";
  466.         }
  467.         return $frmObj;
  468.     }
  469.  
  470.      
  471.  
  472.     /**
  473.       * calls this::setFORMPOST() with this::dbGetForm() formular
  474.       *
  475.       *
  476.       * @param string   $arrName name of the post array
  477.       * @param bool     $debug show debug info
  478.       *
  479.       * @return bool 
  480.       *
  481.       ***/
  482.     function setPOSTVAL($arrName="",$debug=FALSE{
  483.         if ($debugecho "<hr><p><b>CMS_CHAPTER_V2::setPOSTVAL($frmObj,$dbval,$debug)</b> (".get_class($this).")</p>";
  484.  
  485.         if (empty($arrName)) $arrName=$_POST['FRMARRAYNAME'];
  486.  
  487.         if (is_array($_POST[$arrName])) {
  488.             if ($debugecho "<pre>".htmlspecialchars(print_r($_POST[$arrName],TRUE))."\n".print_r($_GET,TRUE)."</pre>";
  489.             $frmObj=NULL;
  490.             if ($this->setFORMPOST($frmObj,$_POST[$arrName],$debug,intval($_POST['FRMMODE']))) {
  491.                 $_POST[$arrName][$this->myTemplate->getPTMPColName()]=$this->myTemplate->getPTMPId()// if not submitted
  492.                 return TRUE;
  493.             }
  494.         }
  495.         if (is_object($this->myTemplate)) {
  496.             $_POST[$arrName][$this->myTemplate->getPTMPColName()]=$this->myTemplate->getPTMPId()// if not submitted
  497.         }
  498.         return FALSE;
  499.  
  500.     }
  501.  
  502.     /**
  503.       * sets post array with form checks
  504.       *
  505.       * @param  DBMS_FORM $frmObj      a formObj as ref
  506.       * @param  array     $dbVal       array with data
  507.       * @param  bool      $debug 
  508.       * @param int $frmMode 
  509.       *
  510.       * @return bool 
  511.       *
  512.       * @globalvar array $DBVAL
  513.       * @var array $a_frmFlds 
  514.       * @var string $s_fldName 
  515.       ***/
  516.     function setFORMPOST(&$frmObj,$dbval,$debug=FALSE,$frmMode=0{
  517.         if ($debugecho "<hr><p><b>CMS_CHAPTER_V2::setFORMPOST(\$frmObj,$dbval,$debug)</b> (".get_class($this).")</p><blockquote>";
  518.  
  519.         if (!intval($frmMode)) $frmMode =(($this->getId()) FRM_MODE_EDIT FRM_MODE_NEW );
  520.  
  521.         if (intval($dbval[$this->myTmplCol]&& ($this->getTmplId(!= intval($dbval[$this->myTmplCol]))) {
  522.             $this->setTemplateObjId(intval($dbval[$this->myTmplCol]),$debug);
  523.             $frmObj=$this->dbGetForm($frmMode,"",$debug);
  524.         else {
  525.             if ($debugecho "<p>\$dbval[".$this->myTmplCol."]=".$dbval[$this->myTmplCol]."</p>";
  526.         }
  527.  
  528.         if (!is_object($frmObj)) {
  529.             $frmObj=$this->dbGetForm($frmMode,"",$debug);
  530.         }
  531.         if ($debugecho get_class($this->myTemplate);
  532.         $dbval[$this->myTemplate->getPTMPColName()]=$this->myTemplate->getPTMPId();
  533.         if ($debugecho "</blockquote>";
  534.         if (parent::setFORMPOST($frmObj,$dbval,$debug)) // <pk-05-08-30>
  535.             $a_chapFlds=$frmObj->getValueArray($dbval,"CHAPTER",$arrName,$debug);
  536.             $this->setDBVal($a_chapFlds,$debug);
  537.             return TRUE;
  538.         // </pk-05-08-30>
  539.     }
  540.  
  541.  
  542.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  543.     /* sort methods                                                              */
  544.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  545.  
  546.     /**
  547.       * @return int 
  548.       ***/
  549.     function getSortOrder({
  550.         return intval($this->{$this->colPrevix."SORTORDER"});
  551.     }
  552.  
  553.     /**
  554.       * moves the chapter up (decrease sortorder)
  555.       * note autosaves sortorder
  556.       *
  557.       * @param boolean $debug 
  558.       *
  559.       * @since pk-05-08-03
  560.       *
  561.       * @var string $s_Query 
  562.       * @var array  $a_Row 
  563.       ***/
  564.     function sort_MoveUp($debug=FALSE{
  565.         if ($debugecho "<p><b>CMS_CHAPTER_V2::sort_MoveUp()</b> (".get_class($this).")</p>";
  566.         if (intval($this->{$this->colPrevix."SORTORDER"}1{
  567.             $s_Query "SELECT ".$this->colPrevix."ID AS IDCOL, ".$this->colPrevix."SORTORDER AS ORDERCOL";
  568.             $s_Query.= "  FROM ".$this->myTable;
  569.             $s_Query.= " WHERE ".$this->myPageIdCol."=".$this->getPageId();
  570.             $s_Query.= "   AND ".$this->colPrevix."SORTORDER <= ".$this->getSortOrder();
  571.             $s_Query.= "   AND ".$this->colPrevix."ID <> ".$this->getId();
  572.             $s_Query.= " ORDER BY ".$this->colPrevix."SORTORDER DESC";
  573.  
  574.             if ($debugecho "<p>".$s_Query."</p>";
  575.             if ($a_Row=$this->myDBObj->quickQuery($s_Query)) {
  576.                 // get only the first row
  577.  
  578.                 $this->{$this->colPrevix."SORTORDER"intval($a_Row['ORDERCOL']);
  579.                 $s_Query ="UPDATE ".$this->myTable." SET ".$this->colPrevix."SORTORDER=".$this->getSortOrder();
  580.                 $s_Query.=" WHERE ".$this->colPrevix."ID = ".$this->getId();
  581.                 if ($debugecho "<p>".$s_Query."</p>";
  582.                 $this->myDBObj->executeCmd($s_Query);
  583.  
  584.                 $s_Query ="UPDATE ".$this->myTable." SET ".$this->colPrevix."SORTORDER=".($this->getSortOrder()+1);
  585.                 $s_Query.=" WHERE ".$this->colPrevix."ID = ".$a_Row['IDCOL'];
  586.                 if ($debugecho "<p>".$s_Query."</p>";
  587.                 $this->myDBObj->executeCmd($s_Query);
  588.             }
  589.         }
  590.     }
  591.  
  592.     /**
  593.       * moves the chapter down (increase sortorder)
  594.       * note: autosaves sortorder
  595.       *
  596.       * @param boolean $debug 
  597.       *
  598.       * @since pk-05-08-03
  599.       *
  600.       * @var string $s_Query 
  601.       * @var array  $a_Row 
  602.       ***/
  603.     function sort_MoveDown($debug=FALSE{
  604.         if ($debugecho "<p><b>CMS_CHAPTER_V2::sort_MoveDown()</b> (".get_class($this).")</p>";
  605.         if (intval($this->{$this->colPrevix."SORTORDER"}1{
  606.             $s_Query "SELECT ".$this->colPrevix."ID AS IDCOL, ".$this->colPrevix."SORTORDER AS ORDERCOL";
  607.             $s_Query.= "  FROM ".$this->myTable;
  608.             $s_Query.= " WHERE ".$this->myPageIdCol."=".$this->getPageId();
  609.             $s_Query.= "   AND ".$this->colPrevix."SORTORDER >= ".$this->getSortOrder();
  610.             $s_Query.= "   AND ".$this->colPrevix."ID <> ".$this->getId();
  611.             $s_Query.= " ORDER BY ".$this->colPrevix."SORTORDER";
  612.  
  613.             if ($debugecho "<p>".$s_Query."</p>";
  614.             if ($a_Row=$this->myDBObj->quickQuery($s_Query)) {
  615.                 // get only the first row
  616.  
  617.                 $this->{$this->colPrevix."SORTORDER"$this->getSortOrder()+1;
  618.                 $s_Query ="UPDATE ".$this->myTable." SET ".$this->colPrevix."SORTORDER=".$this->getSortOrder();
  619.                 $s_Query.=" WHERE ".$this->colPrevix."ID = ".$this->getId();
  620.                 if ($debugecho "<p>".$s_Query."</p>";
  621.                 $this->myDBObj->executeCmd($s_Query);
  622.  
  623.                 $s_Query ="UPDATE ".$this->myTable." SET ".$this->colPrevix."SORTORDER=".($this->getSortOrder()-1);
  624.                 $s_Query.=" WHERE ".$this->colPrevix."ID = ".$a_Row['IDCOL'];
  625.                 if ($debugecho "<p>".$s_Query."</p>";
  626.                 $this->myDBObj->executeCmd($s_Query);
  627.             }
  628.         }
  629.     }
  630.  
  631.     /**
  632.       * moves the chapter to a position
  633.       * note: autosaves sortorder
  634.       *
  635.       * if $postion > last postion
  636.       * the object will be moved to the end
  637.       *
  638.       * @param int $position 
  639.       * @param boolean 
  640.       *
  641.       * @return int 
  642.       *
  643.       * @since pk-05-08-03
  644.       *
  645.       * @var int $i_ordNr 
  646.       * @var string $s_Query 
  647.       * @var DBMS_CURSOR $o_Cursor 
  648.       * @var array $a_Row 
  649.       *
  650.       ***/
  651.     function sort_MoveToPos($position,$debug=FALSE{
  652.         if ($debugecho "<p><b>CMS_CHAPTER_V2::sort_MoveToPos($position)</b> (".get_class($this).")</p>\n";
  653.  
  654.         if (!intval($position)) return FALSE// error illegal position
  655.         if ($this->getSortOrder(== intval($postion)) return $position// nothing to do
  656.  
  657.         $s_Query "SELECT ".$this->colPrevix."ID AS IDCOL, ".$this->colPrevix."SORTORDER AS ORDERCOL";
  658.         $s_Query.= "  FROM ".$this->myTable;
  659.         $s_Query.= " WHERE ".$this->myPageIdCol."=".$this->getPageId();
  660.         $s_Query.= "   AND ".$this->colPrevix."ID <> ".$this->getId();  // without me
  661.         $s_Query.= " ORDER BY ".$this->colPrevix."SORTORDER";
  662.  
  663.         $i_ordNr=1;
  664.         if ($o_Cursor=$this->myDBObj->query($s_Query)) {
  665.             while($a_Row $o_Cursor->fetchArrayFld()) {
  666.                 if ($i_ordNr == $position{
  667.                     // ok here i belong to
  668.                     $this->{$this->colPrevix."SORTORDER"}=$position;
  669.                     $i_ordNr++;
  670.                 }
  671.                 if (intval($a_Row['ORDERCOL']!= $i_ordNr{
  672.                     // we have to update
  673.                     $s_Query ="UPDATE ".$this->myTable." SET ".$this->colPrevix."SORTORDER=".$i_ordNr;
  674.                     $s_Query.=" WHERE ".$this->colPrevix."ID = ".$a_Row['IDCOL'];
  675.                     if ($debugecho "<p>".$s_Query."</p>";
  676.                     $this->myDBObj->executeCmd($s_Query);
  677.                 }
  678.                 $i_ordNr++;
  679.             }
  680.             if ($this->getSortOrder(!= intval($position)) {
  681.                 // i belong to the end
  682.                 $this->{$this->colPrevix."SORTORDER"}=$i_ordNr;
  683.             }
  684.  
  685.             // finaly save my own order position to the database
  686.             $s_Query ="UPDATE ".$this->myTable." SET ".$this->colPrevix."SORTORDER=".$this->getSortOrder();
  687.             $s_Query.=" WHERE ".$this->colPrevix."ID = ".$this->getId();
  688.             if ($debugecho "<p>".$s_Query."</p>";
  689.             $this->myDBObj->executeCmd($s_Query);
  690.             return $this->getSortOrder();
  691.         else {
  692.             return FALSE;
  693.         }
  694.     }
  695.  
  696.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  697.     // states and checks methods
  698.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  699.  
  700.  
  701.     /**
  702.       * checks if the user can edit the chapter
  703.       *
  704.       * @param int $mode 
  705.       * @param boolean $debug 
  706.       *
  707.       * @return boolean 
  708.       *
  709.       * @todo CMS_CHAPTER_V2::userCan() state check, showgroup check
  710.       *
  711.       ***/
  712.     function userCan($mode,$debug=FALSE{
  713.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_CHAPTER_V2::userCan($mode)");
  714.         $this->getMyPageObj();
  715.  
  716.         switch($mode)
  717.         {
  718.             case FRM_MODE_READONLY:
  719.                 return $this->myPageObj->curUserCanOpen($debug);
  720.             case FRM_MODE_NEW:
  721.                 return $this->myPageObj->curUserCanInsert($debug);
  722.             default:
  723.                 return $this->myPageObj->curUserCanEdit($debug);
  724.         }
  725.     }
  726.  
  727.     /**
  728.       * @return int 
  729.       */
  730.     function getState()
  731.     {
  732.         return intval($this->getDBField($this->colPrevix.'STATE'));
  733.     }
  734.  
  735.     /**
  736.       * sets the state and checks if the user is allow to do this
  737.       *
  738.       * @param int $stateId 
  739.       * @param boolean $autoSave 
  740.       * @param boolean $debug 
  741.       *
  742.       * @global array $OCSP_OBJ 
  743.       *
  744.       * @returns boolean
  745.       *
  746.       * @since pk-06-07-07
  747.       * @version pk-07-09-12
  748.       *
  749.       ***/
  750.     function setState($aState=0,$autoSave=FALSE,$debug=FALSE{
  751.         global $OCSP_OBJ;
  752.  
  753.         if ($debugechoDebugMethod(__FILE__,get_class($this),"setState($stateId)","",0);
  754.  
  755.         if (!$this->userCan(FRM_MODE_EDIT))
  756.         {
  757.             if ($debugechoDebugLine(__FILE__,__LINE__,"user not allowed to edit page");
  758.             return FALSE;
  759.         }
  760.  
  761.         if (isset($GLOBALS['OCSP_CMS']['CHAPTERSTATE'][intval($aState)]))
  762.         {
  763.             if (!($OCSP_OBJ['USER']->isGroupMember($GLOBALS['OCSP_CMS']['CHAPTERSTATE'][intval($aState)]['GROUP'])))
  764.             {
  765.                 if ($debugechoDebugLine(__FILE__,__LINE__,"user not allowed");
  766.                 return FALSE;
  767.             }
  768.             if ($this->getState(!= intval($aState))
  769.             {
  770.                 $this->setDBField($this->colPrevix."STATE",intval($aState));
  771.                 if ($autoSave && intval($this->getId()))
  772.                 {
  773.                     $this->dbSave();
  774.                 }
  775.                 return TRUE;
  776.             }
  777.         else {
  778.             ocsp_logError(__FILE__,__LINE__,"state $aState not defined",E_NOTICE);
  779.             return FALSE;
  780.         }
  781.     }
  782.  
  783.  
  784.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  785.     // output methods
  786.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  787.  
  788.     /**
  789.       * return the data array to use in the template
  790.       *
  791.       * @param boolean $fromFld 
  792.       * @param boolean $debug 
  793.       *
  794.       * @return array 
  795.       *
  796.       * @since pk-05-08-26
  797.       *
  798.       * @var array $a_fldLst 
  799.       * @var array $a_dataArr 
  800.       * @var array $s_arrName 
  801.       *
  802.       ***/
  803.     function getTemplateData($fromFld=TRUE,$debug=FALSE{
  804.         if ($debugecho "<p><b>CMS_CHAPTER_V2::getTemplateData(...)</b> (".get_class($this).")</p>";
  805.  
  806.         if (!is_object($this->myTemplate))             $this->getTemplateObj($debug);
  807.         if ($this->myObjValsPopulateTS (time()-60)) $this->populateObjVals($debug);
  808.  
  809.         $a_fldLst=$this->myTemplate->getFieldList($debug,FALSE)// ($debug=FALSE,$autoSave=TRUE)
  810.  
  811.         if ($fromFld{
  812.             $s_arrName="CHADATA".$this->getId()."_".$this->myTemplate->getId();
  813.             global ${$s_arrName};
  814.             $s_arrName=$this->getDBVAL();
  815.         }
  816.         $a_dataArr=array();
  817.         foreach($a_fldLst as $fldObj{
  818.             if ($fromFld{
  819.                 $a_dataArr[$fldObj->getName()]=$fld->getHtmlTag($this->getDBField($fldObj->getName(),$debug),$arrName,$debug);
  820.             else {
  821.                 $a_dataArr[$fldObj->getName()]=$this->getDBField($fldObj->getName(),$debug);
  822.             }
  823.         }
  824.  
  825.         return $adataArr;
  826.     }
  827.  
  828.  
  829.     /**
  830.       * returns the parsed chapter
  831.       *
  832.       * if $tmplVals is an array the return
  833.       * value is paresed with this
  834.       * -> you can use templates within the chapter value
  835.       *
  836.       * @param array $tmpldataArr 
  837.       * @param char $tmplVarSign 
  838.       * @param boolean $wysiwygPreView 
  839.       * @param boolean $debug 
  840.       *
  841.       * @return string 
  842.       *
  843.       * @var string $s_ret 
  844.       *
  845.       ***/
  846.     function getTag($tmplVals=NULL,$tmplVarSign='$',$wysiwygPreView=FALSE,$debug=FALSE{
  847.         if ($debugecho "<p><b>CMS_CHAPTER_V2::getTag(...)</b> (".get_class($this).")</p>";
  848.  
  849.         if (!is_object($this->myTemplate))             $this->getTemplateObj($debug);
  850.         if ($this->myObjValsPopulateTS (time()-60)) $this->populateObjVals($debug);
  851.  
  852.         $s_ret="";
  853.         if ($debug$s_ret="<p>CMS_CHAPTER_V2: ".$this->getId()." TMPL: ".$this->myTemplate->getId()."</p><blockquote>DataArr:<pre>".htmlspecialchars(print_r($a_dataArr,TRUE))."</pre></blockquote>";
  854.  
  855.         // <pk-06-10-02 /> bugfix with $tmplVals
  856.         if (is_array($tmplVals)) {
  857.             $a_Vals=$tmplVals;
  858.         else {
  859.             $a_Vals=array();
  860.         }
  861.         $a_Vals=array_merge($a_Vals,$this->getDBVAL(FALSE,FALSE,TRUE));
  862.  
  863.         if ($debugecho "<pre style=\"font-size:80%;background-color: #C0C0C0; border: solid 1px blue;\">".print_r($a_Vals,TRUE)."</pre>";
  864.  
  865.         $s_ret.= $this->myTemplate->getTag($this->getDBVAL(FALSE,$debug,TRUE),"HTMLCODE",$debug,$wysiwygPreView);
  866.         return $s_ret;
  867.     }
  868. }
  869. ?>

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