kernel
[ class tree: kernel ] [ index: kernel ] [ all elements ]

Source for file simple_form_functions_lib.php

Documentation is available at simple_form_functions_lib.php

  1. <?php
  2. /**
  3.  * @version $Header$
  4.  * @package kernel
  5.  * @subpackage functions
  6.  */
  7.  
  8. /**
  9.  * Store or update an array of values
  10.  * @param $pArray an array of values to set
  11.  * @param $pPackageName name of the package the feature belongs to
  12.  * @return none 
  13.  */
  14. function simple_set_configs( $pArray, $pPackageName = NULL ){
  15.     foreach( $pArray as $item => $data ) {
  16.         if( $data['type'] == 'numeric' ) {
  17.             simple_set_int( $item, $pPackageName );
  18.         } elseif( $data['type'] == 'toggle' ) {
  19.             simple_set_toggle( $item, $pPackageName );
  20.         } elseif( $data['type'] == 'input' ) {
  21.             simple_set_value( $item, $pPackageName );
  22.         }
  23.     }
  24. }
  25.  
  26. /**
  27.  * Store or update a boolean value in the database - automatically collects data from $_REQUEST[$pFeature]
  28.  * @param $pFeature name of the parameter to be set in the database
  29.  * @param $pPackageName name of the package the feature belongs to
  30.  * @return none 
  31.  */
  32. function simple_set_toggle( $pFeature, $pPackageName = NULL ) {
  33.     // make function compatible with {html_checkboxes}
  34.     if( isset( $_REQUEST[$pFeature][0] ) ) {
  35.         $_REQUEST[$pFeature] = $_REQUEST[$pFeature][0];
  36.     }
  37.     toggle_preference( $pFeature, ( isset( $_REQUEST[$pFeature] ) ? $_REQUEST[$pFeature] : NULL ), $pPackageName );
  38. }
  39.  
  40. /**
  41.  * Store or update a boolean value in the database - automatically collects data from $_REQUEST[$pArray] Handy for an array from html_checkboxes when options is used.
  42.  * @param $pArray name of the array to check for features in
  43.  * @param $pFeatures feature to check
  44.  * @param $pPackageName name of the package the feature belongs to
  45.  * @return none 
  46.  */
  47. function simple_set_toggle_array( $pArray, $pFeature, $pPackageName = NULL ) {
  48.     if (!empty($_REQUEST[$pArray]) && is_array($_REQUEST[$pArray])) {
  49.         $flipped = array_flip($_REQUEST[$pArray]);
  50.         toggle_preference( $pFeature, ( isset( $flipped[$pFeature] ) ? 'y' : NULL ), $pPackageName );
  51.     }
  52. }
  53.  
  54. /**
  55.  * Store or update a boolean value in the database
  56.  * @param $pName name of the parameter to be set in the database
  57.  * @param $pValue set $pName to $pValue in kernel_prefs
  58.  * @param $pPackageName name of the package the feature belongs to
  59.  * @return none 
  60.  */
  61. function toggle_preference( $pName, $pValue = NULL, $pPackageName = NULL ) {
  62.     global $_REQUEST, $gBitSystem, $gBitSmarty;
  63.  
  64.     if( isset( $pValue ) && $pValue == "on" ) {
  65.         $prefValue='y';
  66.     } elseif( isset( $pValue ) && $pValue != "n" && strlen( $pValue ) == 1 ) {
  67.         $prefValue=$pValue;
  68.     } else {
  69.         $prefValue='n';
  70.     }
  71.     $gBitSystem->storeConfig( $pName, $prefValue, $pPackageName );
  72. }
  73.  
  74. /**
  75.  * Store or update a value in the database - automatically collects data from $_REQUEST[$pFeature]
  76.  * @param $pFeature name of the parameter to be set in the database
  77.  * @param $pPackageName name of the package the feature belongs to
  78.  * @return none 
  79.  */
  80. function simple_set_value( $pFeature, $pPackageName = NULL ) {
  81.     global $_REQUEST, $gBitSystem, $gBitSmarty;
  82.     if( isset( $_REQUEST[$pFeature] ) ) {
  83.         $gBitSystem->storeConfig( $pFeature, $_REQUEST[$pFeature], $pPackageName );
  84.         $gBitSmarty->assign( $pFeature, $_REQUEST[$pFeature] );
  85.     }
  86. }
  87.  
  88. /**
  89.  * Store or update an integer in the database - automatically collects data from $_REQUEST[$pFeature]
  90.  * @param $pFeature name of the parameter to be set in the database
  91.  * @param $pPackageName name of the package the feature belongs to
  92.  * @return none 
  93.  */
  94. function simple_set_int( $pFeature, $pPackageName = NULL ) {
  95.     global $_REQUEST, $gBitSystem, $gBitSmarty;
  96.     if ( isset( $_REQUEST[$pFeature] ) && is_numeric( $_REQUEST[$pFeature] ) ) {
  97.         $gBitSystem->storeConfig( $pFeature, $_REQUEST[$pFeature], $pPackageName );
  98.         $gBitSmarty->assign( $pFeature, $_REQUEST[$pFeature] );
  99.     }
  100. }
  101.  
  102. /**
  103.  * Store or update a value in the database but assign it by reference to smarty - automatically collects data from $_REQUEST[$pFeature]
  104.  * @param $pFeature name of the parameter to be set in the database
  105.  * @param $pPackageName name of the package the feature belongs to
  106.  * @return none 
  107.  */
  108. function byref_set_value( $pFeature, $pPref = "", $pPackageName = NULL ) {
  109.     global $_REQUEST, $gBitSystem, $gBitSmarty;
  110.     if( isset( $_REQUEST[$pFeature] ) ) {
  111.         if( strlen( $pPref ) > 0 ) {
  112.             $gBitSystem->storeConfig( $pPref, $_REQUEST[$pFeature], $pPackageName );
  113.             // also assign the ref appareantly --gongo
  114.             $gBitSmarty->assign_by_ref( $pPref, $_REQUEST[$pFeature] );
  115.         } else {
  116.             $gBitSystem->storeConfig( $pFeature, $_REQUEST[$pFeature], $pPackageName );
  117.         }
  118.  
  119.         $gBitSmarty->assign_by_ref( $pFeature, $_REQUEST[$pFeature] );
  120.     }
  121. }
  122.  
  123. /**
  124.  * simple function used to work out what tab was pressed and activates the correct tab after reload
  125.  * use with <tabname>TabSubmit as the name of the submit button value and set your tabpage class like this
  126.  * <div class="tabpage {$<tabname>TabSelect}">
  127.  * @returns <tabname> that was submitted
  128.  */
  129. function set_tab() {
  130.     global $_REQUEST,$gBitSmarty;
  131.     $ret = FALSE;
  132.     if( !empty( $_REQUEST ) ) {
  133.         foreach( array_keys( $_REQUEST ) as $item ) {
  134.             if( preg_match( "/TabSubmit/",$item ) ) {
  135.                 $tab = preg_replace( "/TabSubmit/","",$item );
  136.                 $gBitSmarty->assign( $tab.'TabSelect','tdefault' );
  137.                 $ret = $tab;
  138.             }
  139.         }
  140.     }
  141.     return $ret;
  142. }
  143. ?>

Documentation generated on Wed, 29 Jul 2015 13:57:28 +0000 by phpDocumentor 1.5.0-lsces