Source for file pcf.phpinc

Documentation is available at pcf.phpinc

  1. <?php
  2. /**
  3.   * Common Functions
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    common
  7.   *
  8.   * @author     Peter Krebs (pk)<pitlinz@users.sourceforge.net>
  9.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  10.   *
  11.   * @version $Id: pcf.phpinc,v 1.34 2008/12/06 11:22:01 pitlinz Exp $
  12.   *
  13.   */
  14.  
  15. // -------------------------------------------------
  16. // include path
  17. // -------------------------------------------------
  18.  
  19. define ('_OCSP_PCF_COMMON_FUNCTIONS_LOADED_',true);
  20.  
  21. /**
  22.   * returns a template for the include path
  23.   *
  24.   * replaces the following global vars by there template representation:
  25.   *
  26.   * - OCSP|FORMPATH
  27.   * - OCSP|PHPINCPATH
  28.   * - OCSP|PATH
  29.   * - PROJECT|PHPINCPATH
  30.   * - PROJECT|PATH
  31.   *
  32.   * @param string $aPath 
  33.   * @param boolean $debug 
  34.   *
  35.   * @returns string
  36.   *
  37.   * @since pk-07-03-06
  38.   *
  39.   ***/
  40. function pcf_pathToTmplate($aPath,$debug=FALSE{
  41.     if ($debugechoDebug(__FILE__,"<p><b>pcf_pathToTmplate()</b><br/>$aPath</p>");
  42.     $a_globalKeys=array(
  43.         'OCSP'      =>array('PHPFORMPATH','PHPINCPATH','PATH'),
  44.         'PROJECT'   =>array('PHPINCPATH','PATH')
  45.     );
  46.  
  47.     foreach($a_globalKeys as $s_mod => $a_keys{
  48.         if (is_array($a_keys)) {
  49.             foreach($a_keys as $s_key{
  50.                 if ($debugechoDebug(__FILE__,"<p>Checking$s_mod|$s_key (".$GLOBALS[$s_mod][$s_key].")");
  51.                 if (!empty($GLOBALS[$s_mod][$s_key])) {
  52.                     if (strpos($aPath,$GLOBALS[$s_mod][$s_key])===0{
  53.                         if ($debugecho " <b>FOUND</b></p>";
  54.                         return str_replace($GLOBALS[$s_mod][$s_key],"\$@".$s_mod."|".$s_key."\$",$aPath);
  55.                     else if ($debug{
  56.                         if ($debugecho " not found</p>";
  57.                     }
  58.                 }
  59.             }
  60.         }
  61.     }
  62.  
  63.     return $aPath;
  64. }
  65.  
  66. /**
  67.   * parses a path with global var templates
  68.   *
  69.   * @param string $pathTmpl 
  70.   * @param array $aValues 
  71.   *
  72.   * @returns string
  73.   *
  74.   * @since pk-07-03-06
  75.   *
  76.   * @require_once dirname(__FILE__)."/pcf_templates.phpinc";
  77.   *
  78.   */
  79. function pcf_parsePathTmpl($pathTmpl,$aValues=array()) {
  80.     $s_ret=$pathTmpl;
  81.     $s_ret=str_replace("\$@OCSP|PHPFORMPATH\$",$GLOBALS['OCSP']['PHPFORMPATH'],$s_ret);
  82.     $s_ret=str_replace("\$@OCSP|PHPINCPATH\$",__OCSP_PHPINCPATH__,$s_ret);
  83.     $s_ret=str_replace("\$@OCSP|PATH\$",$GLOBALS['OCSP']['PATH'],$s_ret);
  84.     $s_ret=str_replace("\$@PROJECT|PHPINCPATH\$",$GLOBALS['PROJECT']['PHPINCPATH'],$s_ret);
  85.     $s_ret=str_replace("\$@OCSP|PATH\$",$GLOBALS['PROJECT']['PATH'],$s_ret);
  86.  
  87.     if (strstr($aPath,"\$"!== FALSE{
  88.         require_once dirname(__FILE__)."/pcf_templates.phpinc";
  89.         $s_ret=pcf_tmpl_parse($pathTmpl,$aValues);
  90.     }
  91.     return $s_ret;
  92. }
  93.  
  94. /**
  95.  * use this method to load an include in global scope
  96.  *
  97.  * @param string $aFile 
  98.  * 
  99.  * @return boolean 
  100.  */
  101. function pcf_include($aFile)
  102. {
  103.     if (file_exists($aFile))
  104.     {
  105.         include $aFile;
  106.         return true;
  107.     else {
  108.         return false;
  109.     }
  110. }
  111.  
  112. // -------------------------------------------------
  113. // array
  114. // -------------------------------------------------
  115.  
  116. function pcf_array_copy($aArray,$from=0,$till=0{
  117.     /**
  118.         copies an array (keys and values)
  119.         starting at position $from till postion $till
  120.     */
  121.     $ret=array();
  122.     if (is_array($aArray)) {
  123.        $i=0;
  124.        if ($till==0$till=count($aArray);
  125.        reset($aArray);
  126.        while (($till $i&& (list($key,$valeach($aArray))) {
  127.            if ($from <= $i$ret[$key]=$val;
  128.            $i++;
  129.        }
  130.     }
  131.  
  132.     return $ret;
  133. }
  134.  
  135. function pcf_array_strIdx($aArray{
  136.     /**
  137.        generates a new array with only the key value
  138.        pares where key is not an integer
  139.     */
  140.  
  141.     $ret=array();
  142.     if (is_array($aArray)) {
  143.         while(list($key,$valeach($aArray)) {
  144.             if (!is_int($key)) {
  145.                 $ret[$key]=$val;
  146.             }
  147.         }
  148.     }
  149.     return $ret;
  150. }
  151.  
  152. function pcf_array_getKeyPartArray($aArray,$keyPart,$debug=FALSE{
  153.     /**
  154.       * returns a new array witho only those elements having key like "$key%"
  155.      **/
  156.  
  157.     $ret=array();
  158.     if (is_array($aArray)) {
  159.         while(list($key,$val)=each($aArray)) {
  160.             if ($debugecho "$key ($val)";
  161.             if (strpos($key,$keyPart)==0{
  162.                 $ret[$key]=$val;
  163.                 if ($debugecho " added";
  164.             }
  165.             if ($debugecho "<br />";
  166.         }
  167.     }
  168.     return $ret;
  169. }
  170.  
  171. function pcf_array_getRKeyPartArray($aArray,$keyPart,$debug=FALSE{
  172.     /**
  173.       * returns a new array witho only those elements NOT having key like "$key%"
  174.      **/
  175.  
  176.     $ret=array();
  177.     if (is_array($aArray)) {
  178.         while(list($key,$val)=each($aArray)) {
  179.             if ($debugecho "$key ($val)";
  180.             if (strpos($key,$keyPart=== FALSE{
  181.                 $ret[$key]=$val;
  182.                 if ($debugecho " added";
  183.             }
  184.             if ($debugecho "<br />";
  185.         }
  186.     }
  187.     return $ret;
  188. }
  189.  
  190. function pcf_div($a,$b{
  191.     return ($a-($a $b))/$b;
  192. }
  193.  
  194. function pcf_addzero($aInt,$length=2{
  195.     if (!intval($aInt)) $aInt=0;
  196.     $ret="";
  197.     while($length 1{
  198.         if ($aInt pow(10,--$length)) $ret.="0";
  199.         else $length=0;
  200.     }
  201.     $ret .= $aInt;
  202.     return $ret;
  203. }
  204.  
  205.  
  206. /**
  207.   * returns a string out of a double with . seperating each 1000
  208.   * and , as
  209.   *
  210.   * @param double $aDouble 
  211.   * @param int $digits 
  212.   * @param boolean $debug 
  213.   *
  214.   * @return string 
  215.   *
  216.   * @version pk-05-11-22
  217.   *
  218.   ***/
  219. function pcf_formatCurrency($aDouble,$digits=2,$debug=FALSE{
  220.     if ($debugecho "<p><b>pcf_formatCurrency(".sprintf("%.2f",$aDouble).",$digits)</b> (".__FILE__.")</p>\n";
  221.     $s_ret="";
  222.  
  223.     $aDouble=doubleval($aDouble);   // to make sure we have a doubleval
  224.     $i_thausends=intval($aDouble);
  225.     $d_dez=$aDouble-$i_thausends;
  226.  
  227.     if ($debugecho "<p>$i_thausends|,|$d_dez</p>";
  228.  
  229.     if (!intval($i_thausends)) {
  230.         $s_ret="0";
  231.     else {
  232.         while($i_thausends{
  233.             if ($i_thausends 999{
  234.                 $s_nbr=sprintf("%000d",($i_thausends 1000));
  235.                 while(strlen($s_nbr3$s_nbr="0".$s_nbr;
  236.                 $s_ret=".".$s_nbr.$s_ret;
  237.             else {
  238.                 $s_ret=$i_thausends.$s_ret;
  239.             }
  240.             $i_thausends=pcf_div(intval($i_thausends),1000);
  241.          }
  242.     }
  243.  
  244.     $s_ret.=str_replace("0.",",",sprintf("%.".$digits."f",$d_dez));
  245.  
  246.     return $s_ret;
  247. }
  248.  
  249. /**
  250.   * converts german spezial chars in a string
  251.   * to html code
  252.   *
  253.   * example ï¿œ=> &auml;
  254.   *
  255.   * @param string $str 
  256.   * @returns string
  257.   *
  258.   * @since pk-06-01-04
  259.   *
  260.   ***/
  261. function pcf_gerHTMLspecialChars($str{
  262.     $gerCharArr=array(
  263.         'Ä' => '&Auml;',
  264.         'ä' => '&auml;',
  265.         'Ö' => '&Ouml;',
  266.         'ö' => '&ouml;',
  267.         'Ü' => '&Uuml;',
  268.         'ü' => '&uuml;',
  269.         'ß' => '&szlig;',
  270.         '€' => '&euro;'
  271.     );
  272.  
  273.     foreach($gerCharArr as $src => $repl$str=str_replace($src,$repl,$str);
  274.     return $str;
  275.  
  276. }
  277.  
  278. /**
  279.   * converts german spezial chars in a string
  280.   * to a text representation
  281.   *
  282.   * example ä => ae
  283.   *
  284.   * @param string $str 
  285.   *
  286.   * @returns string
  287.   *
  288.   * @since pk-04-10-21
  289.   *
  290.   ***/
  291. function pcf_gerCharTxt($str{
  292.     $gerCharArr=array(
  293.         'Ä' => 'Ae',
  294.         'ä' => 'ae',
  295.         'Ö' => 'Oe',
  296.         'ö' => 'oe',
  297.         'Ü' => 'Ue',
  298.         'ü' => 'ue',
  299.         'ß' => 'ss',
  300.         '€' => 'EURO'
  301.     );
  302.  
  303.     foreach($gerCharArr as $src => $repl$str=str_replace($src,$repl,$str);
  304.     return $str;
  305. }
  306.  
  307. /**
  308.   * replaces < and > with $lt; and $gt;
  309.   *
  310.   * @param string $str 
  311.   *
  312.   * @returns string
  313.   *
  314.   * @since pk-07-02-28
  315.   *
  316.   ***/
  317. function pcf_disableHTML($str{
  318.     $s_ret=str_replace("<","&lt;",$str);
  319.     return str_replace(">","&gt;",$s_ret);
  320. }
  321.  
  322. // ------------------------------------------------------------------------------
  323. // translation
  324. // ------------------------------------------------------------------------------
  325.  
  326.  
  327.  
  328. /**
  329.  * translates aString to language
  330.  *
  331.  * @param string $aString 
  332.  * @param string $toLang 
  333.  * @param string $module 
  334.  * 
  335.  * @return string 
  336.  * 
  337.  * @since pk-08-07-02
  338.  * 
  339.  * @todo do the translation
  340.  */
  341. function pcf_t($aString,$toLang="",$module='OCSP')
  342. {
  343.     return $aString;
  344. }
  345.  
  346. function t($aString,$toLang="")
  347. {
  348.     return pcf_t($aString,$toLang,'OCSP');
  349. }
  350.  
  351. function t_admin($aString,$toLang="")
  352. {
  353.     return pcf_t($aString,$toLang,'OCSP_ADMIN');
  354. }
  355.  
  356. // ------------------------------------------------------------------------------
  357. // javasScript functions
  358. // ------------------------------------------------------------------------------
  359.  
  360. /**
  361.   * returns a string which can be used in
  362.   * javasScript for s=" echo pcf_makeJS_QuotedString($aString); ";
  363.   *
  364.   * @param string $aString 
  365.   * @param char $strSign 
  366.   * @param bool $debug 
  367.   *
  368.   * @version pk-07-08-31
  369.   * @version pk-07-11-16
  370.   ***/
  371. function pcf_makeJS_QuotedString($aString,$strSign='"',$debug=FALSE{
  372.     if ($debugecho "<p><b>pcf_makeJS_QuotedString($aString,$strSign,$debug)</b> <blockquote>";
  373.  
  374.     $aString trim($aString);
  375.     //$aString = str_replace("\\", "\\\\",$aString);
  376.     $aString str_replace("\r""\\r"$aString);
  377.     $aString str_replace("\n""\\n"$aString);
  378.  
  379.     $aString str_replace($strSign"\\".$strSign,  $aString);
  380.  
  381.     return $aString;
  382. }
  383.  
  384. /**
  385.   * @param string $val 
  386.   *
  387.   * @return string 
  388.   *
  389.   * @since pk-07-08-31
  390.   */
  391. function pcf_js_escape($val)
  392. {
  393.     $val str_replace("\\""\\\\"$val);
  394.     $val str_replace("\r""\\r"$val);
  395.     $val str_replace("\n""\\n"$val);
  396.     $val str_replace("'""\\'"$val);
  397.     return str_replace('"''\\"'$val);
  398. }
  399.  
  400. /**
  401.  * echos alert($msg) to use in javascript
  402.  *
  403.  * @param string $msg 
  404.  * 
  405.  * @since pk-08-02-05
  406.  */
  407. function pcf_js_alert($msg)
  408. {
  409.     echo "alert('" pcf_js_escape($msg"');";
  410. }
  411.  
  412. function pcf_js_debug($msg)
  413. {
  414.     echo "
  415.         if (!(obj_dbgDiv = document.getElementById('debugMsg')))
  416.         {
  417.             obj_dbgDiv = document.createElement('DIV');
  418.             obj_dbgDiv.id = 'debugMsg';
  419.             document.body.appendChild(obj_dbgDiv);
  420.         }
  421.     ";
  422.     
  423.     pcf_js_setInnerHTML('debugMsg',$msg,True);
  424. }
  425.  
  426.  
  427. /**
  428.  * echos document.getElementById(...)
  429.  *
  430.  * @param string $domId 
  431.  * @param string $content 
  432.  * @param boolean $try (use try catch)
  433.  * @param boolean $setVisible 
  434.  * 
  435.  * @version pk-08-10-01 $setVisible added
  436.  * 
  437.  */
  438. function pcf_js_setInnerHTML($domId,$content,$try=False,$setVisible=False)
  439. {
  440.     if ($try
  441.     {
  442.         //pcf_js_alert($content);
  443.         echo "try {";
  444.     }
  445.     
  446.     echo "
  447.         if (obj_div=document.getElementById('" $domId "'))
  448.         {
  449.             obj_div.innerHTML = \"" pcf_js_escape($content"\";
  450.         ";
  451.     
  452.     if ($setVisible)
  453.     {
  454.         echo "
  455.             obj_div.style.display = 'block';
  456.             obj_div.style.visiblity = 'visible';
  457.             ";
  458.     }    
  459.  
  460.     
  461.     if ($try)
  462.     {
  463.         echo "
  464.         } else {        
  465.             alert('" $domId " not found');
  466.             ";
  467.     }
  468.     echo "}";
  469.  
  470.     if ($try)
  471.     {
  472.         echo "} catch(e) { alert('" $domId "' + e); }";
  473.     }
  474.     echo ";\n";
  475. }
  476.  
  477.  
  478. /**
  479.     * returns the js code for an errormsg alert box
  480.     *
  481.     * @param string $errMsg 
  482.     * @param boolean $closeWnd (append window.close() ?)
  483.     * @param boolean $echoHTML (inclode <script> tag)
  484.     * @param boolean $echoDocument (inclode <html><head>....</html>)
  485.     * @param string $bodyTag (can be used to show debug infos
  486.     *
  487.     * @returns string
  488.     *
  489.     * @since pk-07-02-27
  490.     *
  491.     ***/
  492. function pcf_js_alertError($errMsg,$closeWnd=FALSE,$echoHTML=FALSE,$echoDocument=FALSE,$bodyTag=""{
  493.     $s_ret="";
  494.     if ($echoDocument{
  495.         $s_ret.="<html>
  496.             <head>
  497.                 <title>Fehler !!!</title>
  498.             ";
  499.     }
  500.     if ($echoHTML{
  501.         $s_ret.="
  502.             <script language=\"javasScript\" type=\"text/javascript\">
  503.             <!--\n";
  504.     }
  505.     $s_ret.= "alert(\"".pcf_makeJS_QuotedString($errMsg)."\");";
  506.     if ($closeWnd$s_ret.="self.close();";
  507.     if ($echoHTML{
  508.         $s_ret.="
  509.             // -->
  510.             </script>\n";
  511.     }
  512.     if ($echoDocument{
  513.         $s_ret.="
  514.             </head>
  515.             <body>
  516.                 $bodyTag
  517.             </body>
  518.         </html>";
  519.     }
  520.     return $s_ret;
  521. }
  522.  
  523. /**
  524.  * escapes a js used in an on.... tag
  525.  *
  526.  * @param string $str_cmd 
  527.  * @param char $quoteType 
  528.  * 
  529.  * @return string 
  530.  * 
  531.  * @since pk-08-02-13
  532.  */
  533. function pcf_js_escapeOnEventCmd($str_cmd,$quoteType='"')
  534. {
  535.     $arr_cmdLines explode("\n",$str_cmd);
  536.     $str_ret "";
  537.     foreach($arr_cmdLines as $str_line)
  538.     {
  539.         $str_ret.=trim($str_line);
  540.     }
  541.     
  542.     $str_ret str_replace("\r","",$str_ret);
  543.     $str_ret str_replace("\t"," ",$str_ret);
  544.     $str_ret str_replace("\\","\\\\",$str_ret);
  545.     $str_ret str_replace($quoteType,"\\".$quoteType,$str_ret);
  546.     
  547.     return $str_ret;    
  548. }
  549.  
  550.  
  551. /**
  552.   * escapes " with /" and /" with ///"
  553.   *
  554.   * @param string $aString 
  555.   * @returns string
  556.   *
  557.   * @since pk-04-07-23
  558.   * @version pk-07-07-26
  559.   ***/
  560. function pcf_escape_doubleQuote($aString,$debug=FALSE{
  561.     if ($debugechoDebug(__FILE__,"<p><b>pcf_escape_doubleQuote(\$aString)</b></p><blockquote>Replace:|".htmlspecialchars($aString)."| ");
  562.  
  563.     $aString str_replace("\\""\\\\"$aString);
  564.     $aString str_replace("\r""\\r",  $aString);
  565.     $aString str_replace("\n""\\n",  $aString);
  566.     $aString str_replace("\"""\\\""$aString);
  567.  
  568.     if ($debugechoDebug(" With: |".htmlspecialchars($aString)."|</blockquote>");
  569.  
  570.     return $aString;
  571. }
  572.  
  573.  
  574. function pcf_system($command$hide=true$debug=FALSE{
  575.   /* FROM: http://at2.php.net/manual/de/function.system.php
  576.  
  577.     system() is messy in that it returns the last line of the output,
  578.     and it prints it as well.  A replacement for system which behaves
  579.     more like the C library system() call by returning the numeric
  580.     status code is given below.
  581.     It is different in that it combines stdout and stderr and only
  582.     prints them if $hide is set false:
  583.   */
  584.  
  585.   if ($debugecho "<hr><pre>$command</pre></hr>";
  586.  
  587.   if (!($p=popen("($command)2>&1","r"))) return 126;
  588.   while (!feof($p)) {
  589.     $l=fgets($p,1000);
  590.     if (!$hideprint $l;
  591.   }
  592.   return pclose($p);
  593. }
  594.  
  595. /**
  596.   * executes a system command and sets the output to $output
  597.   *
  598.   * @param string $command 
  599.   * @param string $output 
  600.   * @param boolean $debug 
  601.   *
  602.   * @returns int (the system return code of the command
  603.   *
  604.   * @since pk-07-03-13
  605.   *
  606.   */
  607. function pcf_getSystem($command,&$output,$debug=FALSE)
  608. {
  609.   if ($debugechoDebug(__FILE__,"<p><b>pcf_getSystem()</b></p><pre>".print_r($command,TRUE)."</pre>");
  610.  
  611.   if (!($p=popen("($command)2>&1","r"))) return 126;
  612.   while (!feof($p)) {
  613.     $output.=fgets($p,1000);
  614.   }
  615.   if ($debugechoDebug(__FILE__,"<blockquote>Output:<pre>".$output."</pre></blockquote>");
  616.   return pclose($p);
  617. }
  618.  
  619.  
  620. /**
  621.   * uses an array to send a mail
  622.   *
  623.   * the array needs the following elements set
  624.   *
  625.   * this function is mainly used for sending debug infos
  626.   * to a specified receipient
  627.   *
  628.   * - $arr['MAILTO']    receipient of the mail
  629.   * - $arr['SUBJECT']   subject
  630.   * - $arr['BODY']      body of the mail
  631.   *
  632.   * optional you can set the mail headers with index
  633.   * - $arr['HEADERS']
  634.   *
  635.   * @param array $arr 
  636.   * @return bool    mail() @link http://www.php.net/manual/en/function.mail.php
  637.   *
  638.   * @since pk-03-12-18
  639.   *
  640.   ***/
  641. function pcf_mailArray($arr{
  642.     if (is_array($arr)) {
  643.         if ((!empty($arr['MAILTO'])) && (!empty($arr['SUBJECT'])) && (!empty($arr['BODY']))) {
  644.             return mail($arr['MAILTO'],$arr['SUBJECT'],$arr['BODY'],$arr['HEADERS']);
  645.         else {
  646.             return FALSE;
  647.         }
  648.     }
  649. }
  650.  
  651. /**
  652.   * parses a query string and returns an array
  653.   * with key values
  654.   * returns FALSE if an error occured
  655.   *
  656.   * @param string $qs 
  657.   * @param char $sep 
  658.   * @param boolean $debug 
  659.   *
  660.   * @return array 
  661.   *
  662.   * @since pk-05-08-29
  663.   *
  664.   * @var array $a_ret 
  665.   * @var array $a_parts 
  666.   * @var string $s_part 
  667.   * @var array $a_keyVal 
  668.   *
  669.   * @todo handle arrays
  670.   *
  671.   ***/
  672. function pcf_parseQueryString($qs,$sep='&',$debug=FALSE{
  673.     if ($debugecho "<p><b>pcf_parseQueryString($qs)</b> (".__FILE__.")</p>";
  674.  
  675.     $a_ret=array();
  676.     $qs=str_replace(htmlspecialchars($sep),$sep,$qs);
  677.  
  678.     if ($a_parts=explode($sep,$qs)) {
  679.         foreach($a_parts as $s_part{
  680.             if ($debugecho "<p>parsing: ".$s_part."</p>";
  681.             if ($a_keyVal explode('=',$s_part,2)) {
  682.                 if ((sizeof($a_keyVal)>1&& (strlen($a_keyVal[1]))) // <pk-06-07-27 /> E_ALL
  683.                     if (($sep=='&'&& (substr($a_keyVal[0],0,4)=="amp;")) // <pk-06-10-19>
  684.                         // we have an encoded &
  685.                         $a_keyVal[0]=substr($a_keyVal[0],4);
  686.                     }
  687.                     $a_ret[$a_keyVal[0]]=$a_keyVal[1];
  688.                 }
  689.             }
  690.         }
  691.         return $a_ret;
  692.     else {
  693.         return FALSE;
  694.     }
  695. }
  696.  
  697.  
  698. /**
  699.   * if $name is in URIs Query string the value
  700.   * is replaced otherwise $name=$value is appended to the uri
  701.   *
  702.   * @param string $uri 
  703.   * @param string $name 
  704.   * @param string $value 
  705.   * @param boolean $debug 
  706.   *
  707.   * @return string 
  708.   *
  709.   * @since pk-03-12-19
  710.   *
  711.   * @version pk-04-02-15
  712.   * @version pk-05-08-29
  713.   * @version pk-05-11-30
  714.   *
  715.   ***/
  716. function pcf_HTML_changeURI_GetValue($uri,$name,$value,$debug=FALSE
  717. {
  718.     if ($debugecho "<p><b>pcf_HTML_changeURI_GetValue($uri,$name,$value,...)</b></p>";
  719.  
  720.     // <pk-04-02-15>
  721.     if (!strstr($uri,$name)) {
  722.         if ($debugecho "<p>name not set</p>\n";
  723.         if (empty($value&& (!is_int($value))) return $uri// <pk-05-11-30 /> ensure 0 is also set
  724.                                                              // <pk-05-07-07 />
  725.  
  726.         $ua=explode("#",$uri,2);
  727.         if ($debugecho "<pre>".print_r($ua,TRUE)."</pre>";
  728.  
  729.         $ret=$ua[0].(strstr($uri,"?""&" "?").$name."=".$value;
  730.         if (!empty($ua[1])) {
  731.             $ret.="#".$ua[1];
  732.         }
  733.         if ($debugecho "<blockquote>1 Returns$ret</blockquote>";
  734.         return $ret;
  735.     }
  736.     // </pk-04-02-15>
  737.  
  738.     // <pk-05-08-29>
  739.     $temp=str_replace("#","?",$uri);        // so we should get a max of 3 parts
  740.     if ($ua=explode("?",$temp,3)) {         // 0: url 1: query string 2: ankor
  741.         $ret=$ua[0]."?";                    // script name
  742.         if (!empty($ua[1])) {               // query string
  743.             $c_sep='';
  744.             if ($a_getVals=pcf_parseQueryString($ua[1],'&',$debug)) {
  745.                 foreach($a_getVals as $s_key => $s_val{
  746.                     if ($s_key != $name)                $ret.=$c_sep.$s_key."=".$s_val;
  747.                     else if (strlen(strval($value)))    $ret.=$c_sep.$s_key."=".$value;
  748.                     $c_sep='&';
  749.                 }
  750.             }
  751.         else {
  752.             if (strlen(strval($value))) {
  753.                 $ret.=$name."=".$value;
  754.             }
  755.         }
  756.         if (!empty($ua[2])) {
  757.             $ret.="#".$ua[2];
  758.         }
  759.         if ($debugecho "<blockquote>2 Returns$ret</blockquote>";
  760.         return $ret;
  761.     else {
  762.         return $uri;
  763.     }
  764. }
  765.  
  766. /**
  767.   * returns an encoded url (& is replaced with &amp;) and checks that only one ? is in the url
  768.   *
  769.   * All special characters in HREF should be encoded. "&" is a reserved character to begin an entity. (ex: &nsbp).
  770.   * "&" in HREF field should be encoded as his equivalent entity "&amp;", even when used as a separator for parameters in the URL.
  771.   *
  772.   * References:
  773.   *
  774.   * W3C spec:  http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.2
  775.   * W3C CDATA: http://www.w3.org/TR/html4/types.html#type-cdata
  776.   * HtmlHelp: http://www.htmlhelp.com/tools/validator/problems.html#amp
  777.   * Very interesting: http://ppewww.ph.gla.ac.uk/~flavell/www/formgetbyurl.html
  778.   *
  779.   * @param string $uri 
  780.   * @param boolean $debug 
  781.   *
  782.   * @return string 
  783.   *
  784.   * @since pk-06-10-19
  785.   *
  786.   */
  787. function pcf_HTML_getEncodedURI($uri,$debug=FALSE
  788. {
  789.     if ($debugechoDebug(__FILE__,"pcf_HTML_getEncodedURI()");
  790.  
  791.     if (!strstr($uri,"&")) return $uri// no need to encode
  792.  
  793.     if (!strstr($uri,"?")) {
  794.         $a_parts=explode("&",$uri,2);
  795.         if (substr($a_parts[1],0,4)=="amp;"{
  796.             $a_parts[1]=substr($a_parts[1],4);
  797.         }
  798.     else {
  799.         $a_parts=explode("?",$uri,2);
  800.     }
  801.  
  802.     if (!isset($a_parts[1]|| (empty($a_parts[1]))) {
  803.         // empty query string
  804.         return $a_parts[0];
  805.     }
  806.  
  807.     $s_ret=$a_parts[0]."?";
  808.  
  809.     $a_qstr=explode('#',$a_parts[1],2)// split querystring and ankor
  810.     $s_queryString=str_replace('?','&',$a_qstr[0]);
  811.     if ($a_getVals=pcf_parseQueryString($a_qstr[0],'&',$debug)) {
  812.         $s_sep="";
  813.         foreach($a_getVals as $s_key => $s_val{
  814.             if (!empty($s_val)) {
  815.                 $s_ret.=$s_sep.$s_key."=".$s_val;
  816.                 $s_sep="&amp;";
  817.             }
  818.         }
  819.     }
  820.     if (isset($a_qstr[1]&& !empty($a_qstr[1])) {
  821.         $s_ret.="#".$a_qstr[1];
  822.     }
  823.     return $s_ret;
  824. }
  825.  
  826. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  827. // object functions
  828. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  829.  
  830. /**
  831.  * ensures the include file providing a function is loaded
  832.  *
  833.  * @param string $funcName 
  834.  * @param mixed $funcInc 
  835.  * 
  836.  * @since pk-08-07-02
  837.  * 
  838.  */
  839. function pcf_require_function($funcName,$funcInc)
  840. {
  841.     if (!function_exists($funcName))
  842.     {
  843.         switch(True)
  844.         {
  845.             case (is_array($funcInc)):
  846.                 $str_src implode(_OCSP_DIRSEP_,$funcInc);
  847.                 return pcf_require_function($funcName,$str_src);
  848.                 
  849.             case ((_OCSP_DIRSEP_ == "/"&& (substr($funcInc,0,1!= "/")):
  850.                 return pcf_require_function($funcName,__OCSP_PHPINCPATH__.$funcInc);
  851.                 
  852.             case (_OCSP_DIRSEP_ != "/"):
  853.                 $funcInc str_replace("/",_OCSP_DIRSEP_,$funcInc);
  854.                 require_once $funcInc;
  855.                 return True;    
  856.             default:            
  857.                 require_once $funcInc;
  858.                 return True;
  859.         }
  860.     }
  861. }
  862.  
  863. /**
  864.  * ensures a class is loaded
  865.  * 
  866.  * @param string $className 
  867.  * @param string $classSrc 
  868.  * @param boolean $debug 
  869.  *  
  870.  * @since pk-08-05-22
  871.  * @version pk-08-06-10
  872.  * @version pk-08-10-05 MODxxx_[MODULE]# added
  873.  */
  874. function pcf_require_class($className,$classSrc="",$debug=False)
  875. {
  876.     if ($debugechoDebugLine(__FILE__,__LINE__,"pcf_require_class({$className},{$classSrc})");
  877.     if (!class_exists($className))
  878.     {
  879.         // <pk-08-10-05>
  880.         if (!is_array($classSrc&& (strstr($classSrc,"#")))
  881.         {
  882.             if ($arr_srcParts explode('#',$classSrc))
  883.             {
  884.                 if (substr($arr_srcParts[0],0,3== "MOD")
  885.                 {
  886.                     if ($arr_modParts explode('_',$arr_srcParts[0]))
  887.                     {
  888.                         $int_idx sizeof($arr_modParts)-1;
  889.                         
  890.                         pcf_require_class("OCSP_MODULE","modules/");
  891.                         if ($obj_module OCSP_MODULE::getInstance($arr_modParts[$int_idx]))
  892.                         {
  893.                             switch($arr_modParts[$int_idx-1])
  894.                             {
  895.                                 case "PHP":
  896.                                     $classSrc str_replace($arr_srcParts[0]."#",$obj_module->getModuleIncPath(),$classSrc);
  897.                                     break;
  898.                                 default:
  899.                                     $classSrc str_replace($arr_srcParts[0]."#",$obj_module->getModulePath(),$classSrc);                     
  900.                             }
  901.                         }
  902.                     }                
  903.                 }
  904.             }
  905.         }
  906.         // </pk-08-10-05>
  907.         
  908.         
  909.         switch(True)
  910.         {            
  911.             case ($className == "DBMS_TABLEOBJ"):
  912.                 require_once __OCSP_PHPINCPATH__ "db" _OCSP_DIRSEP_ "DBMS_TABLEOBJ.phpclass";    
  913.                 return True;
  914.                 
  915.             case (empty($classSrc)):
  916.                 // a file in the path
  917.                 $str_classSrc $className ".php";
  918.                 require_once $str_classSrc;
  919.                 return True;
  920.                 
  921.             case (is_array($classSrc)):
  922.                 $str_src implode(_OCSP_DIRSEP_,$classSrc);
  923.                 return pcf_require_class($className,$str_src);
  924.                 
  925.             case ((_OCSP_DIRSEP_ == "/"&& (substr($classSrc,0,1!= "/")):
  926.                 if ($debugechoDebugLine(__FILE__,__LINE__,"checking: " __OCSP_PHPINCPATH__.$classSrc);
  927.                 if (file_exists(__OCSP_PHPINCPATH__.$classSrc))
  928.                 {
  929.                     return pcf_require_class($className,__OCSP_PHPINCPATH__.$classSrc,$debug);
  930.                 else if (file_exists(__OCSP_PROJECTPATH__.$classSrc)) {
  931.                     $str_src __OCSP_PROJECTPATH__.$classSrc;
  932.                     return pcf_require_class($className,__OCSP_PROJECTPATH__.$classSrc,$debug);
  933.                 else {
  934.                     // mybe it's in the path 
  935.                     @include_once basename($classSrc);
  936.                     return class_exists($className);
  937.                 }
  938.                 
  939.                 
  940.             case (substr($classSrc,-1== "/"):
  941.                 if (_OCSP_DIRSEP_ != "/")
  942.                 {
  943.                     $classSrc str_replace("/",_OCSP_DIRSEP_,$classSrc);
  944.                 }
  945.                 if ($debugecho "requires: " $classSrc $className ".phpclass";
  946.                 require_once $classSrc $className ".phpclass";
  947.                 return True;    
  948.             default:
  949.                 if ($debugechoDebugLine(__FILE__,__LINE__,$classSrc);
  950.                 require_once $classSrc;
  951.                 return True;
  952.         }
  953.     }
  954. }
  955.  
  956. /**
  957.  * ensures an interface is loaded
  958.  * 
  959.  * @param string $interfaceName 
  960.  * @param string/array $interfaceSrc 
  961.  *  
  962.  * @since pk-08-05-22
  963.  * @version pk-08-06-10
  964.  */
  965. function pcf_require_interface($interfaceName,$interfaceSrc)
  966. {
  967.     if (!interface_exists($interfaceName))
  968.     {
  969.         switch(True)
  970.         {                
  971.             case (is_array($interfaceSrc)):
  972.                 $str_src implode(_OCSP_DIRSEP_,$interfaceSrc);
  973.                 return pcf_require_interface($interfaceName,$str_src);
  974.                 
  975.             case ((_OCSP_DIRSEP_ == "/"&& (substr($interfaceSrc,0,1!= "/")):            
  976.                 return pcf_require_interface($interfaceName,__OCSP_PHPINCPATH__.$interfaceSrc);
  977.                 
  978.             case (substr($interfaceSrc,-1== "/"):
  979.                 if (_OCSP_DIRSEP_ != "/")
  980.                 {
  981.                     $interfaceSrc str_replace("/",_OCSP_DIRSEP_,$interfaceSrc);
  982.                 }
  983.                 require_once $interfaceSrc $interfaceName ".phpclass";
  984.                 return True;    
  985.             default:
  986.                 require_once $interfaceSrc;
  987.                 return True;
  988.         }        
  989.     }
  990. }
  991.  
  992.  
  993. /**
  994.   * checks if a object is instance of a class
  995.   *
  996.   * not php only knows lower case class names
  997.   * therefore class name is treaten case insensitve
  998.   *
  999.   * @param object $obj 
  1000.   * @param string $aClass 
  1001.   *
  1002.   * @return bool 
  1003.   *
  1004.   * @since pk-04-01-08
  1005.   *
  1006.   ***/
  1007. function pcf_is_instance_of(&$obj,$aClass{
  1008.     if (!is_object($obj)) return FALSE/* <pk-04-08-12 /> */
  1009.  
  1010.     if (strtolower(get_class($obj)) == strtolower($aClass))
  1011.         return TRUE;
  1012.  
  1013.     if (is_subclass_of($objstrtolower($aClass)))
  1014.         return TRUE;
  1015.  
  1016.     return FALSE;
  1017. }
  1018.  
  1019. /**
  1020.  * checks if an object implements an interface
  1021.  * 
  1022.  * @param object $obj 
  1023.  * @param string $aInterface 
  1024.  * 
  1025.  * @return boolean 
  1026.  * 
  1027.  * @since pk-08-06-16
  1028.  */
  1029. function pcf_class_implements(&$obj,$aInterface)
  1030. {
  1031.     if (!is_object($obj)) return False;
  1032.     
  1033.     if ($arr_implements class_implements($obj))
  1034.     {
  1035.         //echoDebugLine(__FILE__,__LINE__,"<pre>" . print_r($arr_implements,True) . "</pre>");
  1036.         return in_array($aInterface,$arr_implements)
  1037.     
  1038. }
  1039.  
  1040. function pcf_parent_method_exists(&$obj,$aMethod)
  1041. {
  1042.     if (is_object($obj&& ($str_parentClass get_parent_class($obj)))
  1043.     {
  1044.         return method_exists(new $str_parentClass,$aMethod);    
  1045.     }
  1046.     return False;
  1047. }
  1048.  
  1049. /**
  1050.   * returns if a $obj has method $method
  1051.   *
  1052.   * @param object $obj 
  1053.   * @param string $method 
  1054.   *
  1055.   * @return bool 
  1056.   *
  1057.   * @since pk-05-01-11
  1058.   *
  1059.   ***/
  1060. function pcf_object_has_method(&$obj,$method,$debug=FALSE{
  1061.     if ($debugecho "<p><b>pcf_object_has_method(\$obj,$method,...)<b> (".__File__.")</p>";
  1062.     if (!is_object($obj)) return FALSE;
  1063.  
  1064.     foreach (get_class_methods($objas $objMethod{
  1065.         if (strtoupper($method== strtoupper($objMethod)) {
  1066.             if ($debugecho "<blockquote><p>$objMethod found</p></blockquote>";
  1067.             return TRUE;
  1068.         }
  1069.     }
  1070.  
  1071.     if ($debugecho "<blockquote><p style=\"background-colorred\">$objMethod <b>NOT</bfound</p></blockquote>";
  1072.  
  1073.     return FALSE;
  1074. }
  1075.  
  1076. /**
  1077.   * @param mixed &$obj 
  1078.   * @param bolean $useVardump (use this with care as recursiv objects can lead to endless loops here)
  1079.   *
  1080.   * @return string 
  1081.   */
  1082. function pcf_object_id(&$obj,$useVardump=FALSE)
  1083. {
  1084.     $str_ret="";
  1085.     if (is_object($obj))
  1086.     {
  1087.         if ($useVardump)
  1088.         {
  1089.             ob_start();
  1090.             var_dump($obj);
  1091.             $str_varDump=ob_get_contents();
  1092.             ob_end_clean();
  1093.             $arr_dump=explode('{',$str_varDump,2);
  1094.             $str_ret.=$arr_dump[0]."\n";
  1095.         }
  1096.         $str_ret.=get_class($obj);
  1097.         if (method_exists($obj,'getId'))
  1098.         {
  1099.             $str_ret.=" ID: ".$obj->getId();
  1100.         }
  1101.         return $str_ret;
  1102.     else {
  1103.         return "not an object";
  1104.     }
  1105. }
  1106.  
  1107. /**
  1108.   * returns a string discribing $obj
  1109.   *
  1110.   * @param object $obj 
  1111.   * @param int $noLevels 
  1112.   * @param bool $withMethods 
  1113.   *
  1114.   * @returns string
  1115.   *
  1116.   * @version pk-05-01-11
  1117.   *
  1118.   ***/
  1119. function pcf_object_info($obj,$noLevels=4,$withMethods=FALSE{
  1120.     if (is_object($obj))
  1121.     {
  1122.         $str_ret "Class: " get_class($obj);
  1123.  
  1124.         ob_start();
  1125.         var_dump($obj);
  1126.         $str_varDump=ob_get_contents();
  1127.         ob_end_clean();
  1128.  
  1129.         $arr_dump=explode('{',$str_varDump,2);
  1130.         $str_ret.=$arr_dump[0];
  1131.         if (isset($arr_dump[1]))
  1132.         {
  1133.             $arr_dump[1]=str_replace("\r","",$arr_dump[1]);
  1134.             $arr_dump[1]=str_replace("\n","",$arr_dump[1]);
  1135.             $str_ret.=str_replace("[\"","\n[\"",$arr_dump[1]);
  1136.         }
  1137.         
  1138.         /*
  1139.         $objVars=get_object_vars($obj);
  1140.         if (is_array($objVars)) {
  1141.             foreach (get_object_vars($obj) as $var=>$val) {
  1142.                 if (is_array($val)) {
  1143.                     $out[] = "property: $var \n".pcf_print_r($val,TRUE,($noLevels-1))."\n";
  1144.                 } else if (is_object($val)) {
  1145.                     $out[] = "property: $var \n".pcf_object_info($val,($noLevels-1),FALSE)."\n";
  1146.                 } else if ($val) {
  1147.                     $out[] = "property: $var = ".htmlspecialchars($val);
  1148.                 } else {
  1149.                     $out[] = "property: $var";
  1150.                 }
  1151.             }
  1152.         }
  1153.         */
  1154.  
  1155.         if ($withMethods{
  1156.             foreach (get_class_methods($objas $method{
  1157.                 $out["method$method";
  1158.             }
  1159.         }
  1160.  
  1161.     else {
  1162.         ob_start();
  1163.         var_dump($obj);
  1164.         $str_ret=ob_get_contents();
  1165.         ob_end_clean();
  1166.     }
  1167.     return $str_ret;
  1168. }
  1169.  
  1170. /**
  1171.   * function copies all values of $src to $dest
  1172.   *
  1173.   * @param object $src 
  1174.   * @param object &$dest 
  1175.   *
  1176.   * @returns boolean
  1177.   *
  1178.   * @since pk-04-08-25
  1179.   *
  1180.   ***/
  1181. function pcf_copy_object($src&$dest{
  1182.     if ((is_object($src)) && (is_object($dest))) {
  1183.         foreach (get_object_vars($srcas $var=>$val{
  1184.             $dest->{$var}=$val;
  1185.         }
  1186.         return TRUE;
  1187.     else {
  1188.         return FALSE;
  1189.     }
  1190. }
  1191.  
  1192.  
  1193. /**
  1194.   * casts a object form one type to an other
  1195.   * the class source for the new object must exist
  1196.   * in case of an error NULL is returned
  1197.   *
  1198.   * Note: if the new object has set CLASSVARIABLES (string seperated with ,)
  1199.   * this values are not overwritten when copying the values
  1200.   * from $src to the new object
  1201.   *
  1202.   * @param object $src 
  1203.   * @param string $className 
  1204.   * @param boolean $debug 
  1205.   *
  1206.   * @return object 
  1207.   *
  1208.   * @since pk-05-11-21
  1209.   *
  1210.   ***/
  1211. function pcf_castObject($src,$className,$debug=FALSE{
  1212.     if ($debugecho "<p><b>pcf_castObject(\$src,$className)</b> (".__FILE__.")</p>";
  1213.  
  1214.     if (!class_exists($className)) {     // class does not exist -> error
  1215.         if ($debugechoDebug(__FILE__,"<p>Returning NULL due $className does not exists</p>",0);
  1216.         return NULL;
  1217.     }
  1218.  
  1219.     $s_cmd="\$o_new=new $className();";
  1220.     if ($debugechoDebug(__FILE__,"<p>CMD$s_cmd</p>",1);
  1221.     eval ($s_cmd);                                  // generate a new object
  1222.  
  1223.     if (!is_object($o_new|| (strtoupper(get_class($o_new)) != strtoupper($className))) {
  1224.         // something went wrong
  1225.         return NULL;
  1226.     }
  1227.  
  1228.     if (strtoupper(get_class($src)) == strtoupper($className)) {
  1229.         // $src is already of this type
  1230.         // but we will return a new object as suspected by this method
  1231.         // i'm not quite sure if new CLASS returns a pointer to the object or the object
  1232.         // therefore i do this this way to be sure :-)
  1233.         if (pcf_copy_object($src,$o_new)) {
  1234.             return $o_new;
  1235.         }
  1236.     }
  1237.  
  1238.     if (!empty($o_new->CLASSVARIABLES)) {
  1239.         // note if an object has a value CLASSVARIABLES
  1240.         $a_classVars=explode(",",$o_new->CLASSVARIABLES);
  1241.     else {
  1242.         $a_classVars=array();
  1243.     }
  1244.  
  1245.     // <pk-06-03-07>
  1246.     $a_object_vars=get_object_vars($src);
  1247.  
  1248.     if (is_array($a_object_vars)) {
  1249.         foreach($a_object_vars as $key => $val{
  1250.             // as we have some special static vars which should not be overwritten
  1251.             // we do not just call pcf_copy_object
  1252.             if ($debugecho "<p>".$key."=".print_r($val,TRUE)."</p>";
  1253.             if ((!in_array($key,$a_classVars)) && (strval($val!= get_class($src))) // <pk-06-08-11 /> E_ALL
  1254.                 switch($key{
  1255.                     // DBMS_TABLEOBJ static vars
  1256.                     case "myClassSrcFile":
  1257.                     // DBMS_FIELD static vars
  1258.                     case "classSrcFile":
  1259.                         // do nothing
  1260.                         break;
  1261.                     default:
  1262.                         $o_new->{$key}=$val;
  1263.  
  1264.                 }
  1265.             }
  1266.         }
  1267.     }
  1268.     // <pk-06-03-07>
  1269.  
  1270.     if ($debugechoDebug(__FILE__,"<p>Returning new object of class: ".get_class($o_new)."</p>",1);
  1271.     return $o_new;
  1272. }
  1273.  
  1274. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1275. // apc methods
  1276. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1277.  
  1278. /**
  1279.  * returns if apc is installed
  1280.  */
  1281. function pcf_apcEnabled()
  1282. {
  1283.     return (function_exists('apc_fetch'));    
  1284. }
  1285.  
  1286. /**
  1287.  * returns the cache value of a var
  1288.  *
  1289.  * @param string $varName 
  1290.  * 
  1291.  * @return mixed 
  1292.  */
  1293. function pcf_apcFetch($varName)
  1294. {
  1295.     if (!pcf_apcEnabled()) return NULL;
  1296.     
  1297.     if ($mix_value=apc_fetch($varName))
  1298.     {
  1299.         return unserialize(gzuncompress($mix_value));           
  1300.     else {
  1301.         return NULL;
  1302.     }
  1303. }
  1304.  
  1305. /**
  1306.  * sets an apc varibale
  1307.  *
  1308.  * @param string $varName 
  1309.  * @param mixed $value 
  1310.  * @param int $ttl 
  1311.  */
  1312. function pcf_apcSet($varName,$value,$ttl=3600)
  1313. {
  1314.     if (!pcf_apcEnabled()) return FALSE;
  1315.     
  1316.     return apc_store($varName,gzcompress(serialize($value)),$ttl);
  1317. }
  1318.  
  1319.  
  1320. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1321. // debug methods
  1322. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1323.  
  1324. /**
  1325.   * like php funktion print_r but limits levels of going into keys
  1326.   *
  1327.   * @param mixed $variable 
  1328.   * @param boolean $tostring 
  1329.   * @param int $noLevels 
  1330.   * @param string $intend only used by recursiv calls
  1331.   * @param int $maxVarLen 
  1332.   *
  1333.   * @returns string if $tostring=TRUE
  1334.   *
  1335.   * @since pk-04-08-12
  1336.   ***/
  1337. function pcf_print_r($variable,$toString=TRUE,$noLevels=99,$intend="",$maxVarLen=50{
  1338.     $ret="";
  1339.     $space="    ";
  1340.     if ($noLevels{
  1341.         if (!$type gettype($variable)) {
  1342.             $ret.=print_r($variable,$toString);
  1343.         }
  1344.         switch($type{
  1345.             case "array":
  1346.                 if ($noLevels 1{
  1347.                     if ($toString$ret " array (\n";
  1348.                     else echo " array (\n";
  1349.                     foreach($variable as $key => $val{
  1350.                         if ($toString$ret.= $intend.$space."[".$key."] = ";
  1351.                         else echo $intend.$space."[".$key."] = ";
  1352.                         $ret.=pcf_print_r($val,$toString,$noLevels-1,$intend.$space);
  1353.                     }
  1354.                     if ($toString$ret .="\n".$intend.")";
  1355.                     else echo "\n".$intend.")";
  1356.                 else {
  1357.                     if ($toString$ret " array()";
  1358.                     else echo " array()";
  1359.                 }
  1360.                 break;
  1361.             case "object":
  1362.                 if ($noLevels 1{
  1363.                     if ($toString$ret " object (\n";
  1364.                     else echo " object (\n";
  1365.                     $objVars get_object_vars($variable);
  1366.                     foreach ($objVars as $key => $val{
  1367.                         if ($toString$ret.= $intend.$space.get_class($variable)."->".$key." = ";
  1368.                         else echo $intend.$space.get_class($variable)."->".$key." = ";
  1369.                         $ret.=pcf_print_r($val,$toString,$noLevels-1,$intend.$space);
  1370.                     }
  1371.                     if ($toString$ret .= "\n".$intend.")";
  1372.                     else echo "\n".$intend.")";
  1373.                 else {
  1374.                     if ($toString$ret " (object)";
  1375.                     else echo " (object)";
  1376.                 }
  1377.                 break;
  1378.             default:
  1379.                 if ($maxVarLen strlen($variable)) $outVal=substr($variable,0,$maxVarLen)."...";
  1380.                 else                                $outVal=$variable;
  1381.  
  1382.                 if ($toString$ret htmlspecialchars($outVal)." (".$type.")";
  1383.                 else echo htmlspecialchars($outVal)." (".$type.")";
  1384.         }
  1385.     }
  1386.  
  1387.     if ($toString$ret.="\n"else echo "\n";
  1388.     return $ret;
  1389. }
  1390.  
  1391.  
  1392. /**
  1393.   * writes setting table to a file
  1394.   *
  1395.   * @param string $tbl 
  1396.   * @param string $section 
  1397.   * @param string $fName 
  1398.   * @param boolean $debug 
  1399.   *
  1400.   * @return boolean 
  1401.   *
  1402.   * @since pk-05-11-15
  1403.   *
  1404.   ***/
  1405. function pcf_cache_SettingTbl($tbl,$section="",$fName="",$debug=FALSE{
  1406.     if ($debugecho "<p><b>pcf_cache_SettingTbl($tbl,$section)</b> (".__FILE__.")</p>";
  1407.  
  1408.     if (!is_object($GLOBALS['USRDB'])) return FALSE;
  1409.     $s_query ="SELECT * FROM ".$tbl;
  1410.     $s_query.=" WHERE SET_CATEGORY <> 'CATEGORY'";
  1411.     if (!empty($section)) {
  1412.         $s_query.=" AND SET_SECTION=".$GLOBALS['USRDB']->qs_getSlashedValue($section);
  1413.     }
  1414.     $s_query.=" ORDER BY SET_CATEGORY";
  1415.  
  1416.     if (empty($fName)) $fName=$tbl;
  1417.  
  1418.     if ($o_Cursor=$GLOBALS['USRDB']->query($s_query)) {
  1419.         $s_fContent ="<?php\n";
  1420.         $s_fContent.="\t\$".$fName."_TS=".time().";\n\n";
  1421.         while($a_row $o_Cursor->fetchArrayFld()) {
  1422.             $s_fContent.="\t\$GLOBALS['".$a_row['SET_SECTION']."']['".$a_row['SET_CATEGORY']."']['".$a_row['SET_NAME']."']=";
  1423.             $s_fContent.="base64_decode('".base64_encode($a_row['SET_VALUE'])."');\n";
  1424.         }
  1425.         $s_fContent.="\n?>";
  1426.  
  1427.         require_once $GLOBALS['PHPINCPATH']."common/pcf_directory.phpinc";
  1428.         $cacheFile=$GLOBALS['PROJECT']['PATH']."cache/settings/".$fName.".conf";
  1429.  
  1430.         if ($debugecho "<p>CacheFile$cacheFile</p>";
  1431.  
  1432.         if (!pcf_checkDir(dirname($cacheFile),TRUE,0700)) {
  1433.             if ($debugecho "<blockquote><p>Unable to create cache dir: ".dirname($cacheFile)."</p></blockquote>";
  1434.             return FALSE;
  1435.         }
  1436.  
  1437.         if ($fp=fopen($cacheFile,"w")) {
  1438.             fwrite($fp,$s_fContent);
  1439.             fclose($fp);
  1440.             return TRUE;
  1441.         }
  1442.     }
  1443.     return FALSE;
  1444.  
  1445. }
  1446.  
  1447. /**
  1448.   * echos a debug message
  1449.   * this method is planed for using different debug output methods
  1450.   *
  1451.   * @param string $srcfile 
  1452.   * @param string $messsage 
  1453.   * @param int $level debug level
  1454.   *
  1455.   * @since pk-05-12-14
  1456.   *
  1457.   ***/
  1458. function echoDebug($srcfile,$message,$level=0{
  1459.     switch((isset($GLOBALS['OCSP_SETTINGS']['DEBUG_SYSTEM']$GLOBALS['OCSP_SETTINGS']['DEBUG_SYSTEM'"")) // <pk-06-07-26 /> E_ALL
  1460.         default:
  1461.             echo "<!-- ".basename($srcfile)." -->\n$message";
  1462.     }
  1463. }
  1464.  
  1465. /**
  1466.   * echos a debug message with line
  1467.   *
  1468.   * @param string $srcfile 
  1469.   * @param int $line 
  1470.   * @param string $message 
  1471.   * @param int $level 
  1472.   *
  1473.   ***/
  1474. function echoDebugLine($srcfile,$line,$message,$level=0
  1475. {
  1476.     $str_debugInfo "";
  1477.     $str_debugSys OCSP_CONF::getInstance()->getValue('DEBUG_SYSTEM');
  1478.     if (empty($str_debugSys&& !isset($_SERVER['HTTP_HOST']))
  1479.     {
  1480.         $str_debugSys "TERM";
  1481.     }
  1482.     
  1483.     switch($str_debugSys
  1484.     
  1485.         case "TERM":
  1486.             echo "
  1487. --- ".basename($srcfile)." Line {$line}  Memory ".round(memory_get_usage()/1024)." kb ---
  1488. {$message}
  1489. ---
  1490.             ";
  1491.             break;
  1492.         default:
  1493.             echo "<div title='".basename($srcfile)."' class='debugMsg' style='margin-left: 20px;padding: 5px 0px;'>".$message."<br /><span style='font-size: 75%;'>$srcfile Line$line Memory".round(memory_get_usage()/1024)." kb</span>{$str_debugInfo}</div>\n";
  1494.     }
  1495. }
  1496.  
  1497.  
  1498. /**
  1499.   * echos the debug infos of a class method
  1500.   *
  1501.   * @param string $srcfile 
  1502.   * @param string $class 
  1503.   * @param string $method 
  1504.   * @param string $message 
  1505.   * @param int $level 
  1506.   *
  1507.   * @since pk-06-02-10
  1508.   *
  1509.   * @version pk-08-12-04
  1510.   */
  1511. function echoDebugMethod($srcfile,$class,$method,$message="",$level=0
  1512. {
  1513.     $str_debugSys OCSP_CONF::getInstance()->getValue('DEBUG_SYSTEM');
  1514.     if (empty($str_debugSys&& !isset($_SERVER['HTTP_HOST']))
  1515.     {
  1516.         $str_debugSys "TERM";
  1517.     }
  1518.     
  1519.     switch($str_debugSys
  1520.     
  1521.         case "TERM":
  1522.             echo "
  1523.     ------------------------------------------------------
  1524.     {$class}::{$method}
  1525.     (".  basename($srcfile")
  1526.     
  1527.             ";
  1528.             if (!empty($message))
  1529.             {
  1530.                 echo $message;
  1531.             }
  1532.             echo "
  1533.     ------------------------------------------------------\n";
  1534.  
  1535.             break;
  1536.         default:
  1537.             echo "<div title='".basename($srcfile)."'><b>$method</b> ($class)";
  1538.             if (!empty($message)) {
  1539.                 echo "<pre style='font-size: 80%;padding-left:20px;bordersolid 1px #000000;'>$message</pre>";
  1540.             else {
  1541.                 echo "<br />";
  1542.             }
  1543.             echo "<span style='font-size: 75%'>Memory: ".round(memory_get_usage()/1024)." kb</span></div>\n";
  1544.     }
  1545. }
  1546.  
  1547.  
  1548. /**
  1549.   * logs an error
  1550.   *
  1551.   * @param string $srcfile 
  1552.   * @param int $line 
  1553.   * @param string $message 
  1554.   * @param int $level @see http://www.php.net/manual/en/ref.errorfunc.php#errorfunc.constants
  1555.   *
  1556.   * @since pk-07-05-04
  1557.   */
  1558. function ocsp_logError($srcfile,$line,$message,$level=E_WARNING)
  1559. {
  1560.     switch($level)
  1561.     {
  1562.         case E_NOTICE:
  1563.             $str_class="error_notice";
  1564.             $str_title="NOTICE";
  1565.             break;
  1566.         case E_WARNING:
  1567.             $str_class="error_warning";
  1568.             $str_title="WARNING";
  1569.             break;
  1570.         default:
  1571.             $str_title="ERROR";
  1572.             $str_class="error";
  1573.     }
  1574.  
  1575.     switch((isset($GLOBALS['OCSP_SETTINGS']['ERROR_LOG_TYPE']$GLOBALS['OCSP_SETTINGS']['ERROR_LOG_TYPE'""))
  1576.     {
  1577.         default:
  1578.             echo "<div class=\"$str_class\">\n";
  1579.             echo "<h2 class=\"error\">$str_title:</h2>";
  1580.             echo "<p class=\"error\">File: ".basename($srcfile)." Line$line</p>";
  1581.             echo "<pre class=\"error\">$message</pre>\n";
  1582.             echo "<span style=\"font-size: 75%\">Memory: ".round(memory_get_usage()/1024)." kb</span></div>\n";
  1583.             echo "</div>\n";
  1584.     }
  1585. }
  1586. ?>

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