home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / EasyPHP-2.0b1-setup.exe / {app} / sqlitemanager / include / SQLiteFunctionProperties.class.php < prev    next >
Encoding:
PHP Script  |  2006-04-18  |  10.0 KB  |  212 lines

  1. <?php
  2. /**
  3. * Web based SQLite management
  4. * FUNCTION management Class
  5. * @package SQLiteManager
  6. * @author FrΘdΘric HENNINOT
  7. * @version $Id: SQLiteFunctionProperties.class.php,v 1.34 2006/04/16 18:56:57 freddy78 Exp $ $Revision: 1.34 $
  8. */
  9.  
  10. class SQLiteFunctionProperties {
  11.  
  12.     /**
  13.     * reference to the connection object
  14.     *
  15.     * @access public
  16.     * @var resource
  17.     */
  18.     var $connId;
  19.  
  20.     /**
  21.     * function name
  22.     *
  23.     * @access private
  24.     * @var string
  25.     */
  26.     var $function;
  27.  
  28.     /**
  29.     * this function exist?
  30.     *
  31.     * @access private
  32.     * @var bool
  33.     */
  34.     var $isExist;
  35.  
  36.     /**
  37.     * Properties of the current FUNCTION
  38.     *
  39.     * @access private
  40.     * @var array
  41.     */
  42.     var $functionProperties;
  43.  
  44.     /**
  45.     * Class constructor
  46.     *
  47.     * @access public
  48.     * @param object $conn reference to the connection object
  49.     */
  50.     function SQLiteFunctionProperties(&$conn){
  51.         // constructeur de la classe
  52.         $this->connId = $conn;
  53.         if($GLOBALS['function'] && ($GLOBALS['action']!='add')) {
  54.             $this->function = $GLOBALS['function'];
  55.         } elseif(isset($GLOBALS['FunctionName']) && $GLOBALS['FunctionName']){
  56.             $this->function = $GLOBALS['FunctionName'];
  57.         } else return false;
  58.         $this->isExist = $this->functionExist($this->function);
  59.         return $this->isExist;
  60.     }
  61.  
  62.     /**
  63.     * Verify if this FUNCITION exist
  64.     *
  65.     * @access public
  66.     * @param string
  67.     */
  68.     function functionExist($function){
  69.         if(empty($function)) $function = $this->function;
  70.         $query = 'SELECT * FROM user_function WHERE funct_name='.quotes($function).' AND (base_id='.$GLOBALS['dbsel'].' OR base_id IS NULL);';
  71.         $tempTabFunction = $GLOBALS['db']->array_query($query);        
  72.         if(count($tempTabFunction)==1){
  73.             $exist = false;
  74.             foreach($tempTabFunction as $tempFunctProp) {
  75.                 $this->functionProperties = $tempFunctProp;
  76.                 $exist = true;
  77.             }
  78.             return $exist;
  79.         } else return false;
  80.     }
  81.  
  82.     /**
  83.     * save properties of the current FUNCTION
  84.     *
  85.     * @access private
  86.     */
  87.     function saveProp(){
  88.         if($GLOBALS['action']=='delete'){
  89.             $queryDisplay = 'DELETE FROM user_function WHERE funct_name='.quotes($this->function).' AND (base_id='.$GLOBALS['dbsel'].' OR base_id IS NULL);';
  90.         }
  91.         if($GLOBALS['action']!='delete'){
  92.             $base_id = (($_POST['FunctAttribAll']==1)? 'NULL' : $GLOBALS['dbsel'] );
  93.             if($_POST['FunctName']        != $this->functionProperties['funct_name'])         $tabSQL['funct_name']         = "'".$this->connId->formatString($_POST['FunctName'])."'";
  94.             if($_POST['FunctType']        != $this->functionProperties['funct_type'])         $tabSQL['funct_type']         = $this->connId->formatString($_POST['FunctType']);
  95.             if($_POST['FunctCode']        != $this->functionProperties['funct_code'])         $tabSQL['funct_code']         = "'".$this->connId->formatString($_POST['FunctCode'])."'";
  96.             if($_POST['FunctFinalCode']    != $this->functionProperties['funct_final_code'])     $tabSQL['funct_final_code'] = "'".$this->connId->formatString($_POST['FunctFinalCode'])."'";
  97.             if($_POST['FunctNumArgs']    != $this->functionProperties['funct_num_args'])     $tabSQL['funct_num_args']     = $this->connId->formatString($_POST['FunctNumArgs']);
  98.             if($base_id    != $this->functionProperties['base_id']) $tabSQL['base_id'] = $base_id;
  99.             if(is_array($tabSQL)){
  100.                 if($this->isExist) {
  101.                     while(list($key, $value) = each($tabSQL)) $tabUpdate[] = $key.'='.$value;
  102.                     $queryDisplay = 'UPDATE user_function SET '.implode(',', $tabUpdate).' WHERE id='.$_POST['id'].';';
  103.                 } else {
  104.                     $tabCol = array_keys($tabSQL);
  105.                     $tabVal = array_values($tabSQL);
  106.                     $nbVal = count($tabSQL);
  107.                     $queryDisplay = 'INSERT INTO user_function ('.implode(',', $tabCol).') VALUES ('.implode(',', $tabVal).');';
  108.                 }
  109.             }
  110.         }
  111.         $errorMessage = '';
  112.         $res = $GLOBALS['db']->query($queryDisplay);
  113.         if(!$res){
  114.             $errorCode = @sqlitem_last_error($this->connId->connId);
  115.             $errorMessage .= $GLOBALS['traduct']->get(9).' '.$errorCode.' : '.@$this->connId->connId->getError()."\n";
  116.         }
  117.         displayQuery($queryDisplay);
  118.         if(!empty($errorMessage)) displayError($errorMessage);
  119.         if($GLOBALS['action']!='delete') {
  120.             $this->propView();
  121.             echo "<script  type=\"text/javascript\">parent.left.location='left.php?dbsel=".$GLOBALS["dbsel"]."';</script>";
  122.         } else {
  123.             echo "<script  type=\"text/javascript\">parent.left.location='left.php?dbsel=".$GLOBALS["dbsel"]."'; parent.main.location='main.php?dbsel=".$GLOBALS["dbsel"]."';</script>";
  124.         }
  125.     }
  126.  
  127.     /**
  128.     * Display current FUNCITION properties
  129.     *
  130.     * @access public
  131.     */
  132.     function propView(){
  133.       echo '<!-- SQLiteFunctionProperties.class.php : propView() -->'."\n";
  134.         echo '<br><center>';
  135.         $funct_code = highlight_string("<?php\n".$this->functionProperties['funct_code']."\n?>", true);
  136.         $funct_finale_code = highlight_string($this->functionProperties['funct_final_code'], true);
  137.         echo '    <table cellpadding="2" cellspacing="0" width="80%" class="viewProp">
  138.                     <tr class="viewPropTitle"><td align="right" width="20%" class="viewPropTitle">'.$GLOBALS['traduct']->get(19).' : </td><td align="center" class="viewPropTitle">'.htmlentities($this->function, ENT_NOQUOTES, $GLOBALS['charset']).'</td></tr>
  139.                     <tr><td align="right" class="viewProp">Type : </td><td align="center" class="viewProp">'.(($this->functionProperties['funct_type']==1)? $GLOBALS['traduct']->get(10) : $GLOBALS['traduct']->get(11) ).'</td></tr>
  140.                     <tr><td align="right" class="viewProp">'.$GLOBALS['traduct']->get(10).' : </td><td class="viewProp">'.$funct_code.'</td></tr>';
  141.         if($this->functionProperties['funct_type']==2) echo '        <tr><td align="right" class="viewProp">'.$GLOBALS['traduct']->get(12).' : </td><td class="viewProp">'.$funct_final_code.'</td></tr>';
  142.         echo '            <tr><td align="right" class="viewProp">'.$GLOBALS['traduct']->get(13).' : </td><td class="viewProp">'.$this->functionProperties['funct_num_args'].'</td></tr>';
  143.         echo '        </table>';
  144.         echo '<div align="center">';
  145.         if(!$GLOBALS['workDb']->isReadOnly() && displayCondition('properties')) echo '<a href="main.php?dbsel='.$GLOBALS['dbsel'].'&function='.$this->function.'&action=modify" class="base" target="main">'.$GLOBALS['traduct']->get(14).'</a>';
  146.         else echo '<span class="base"><i>'.$GLOBALS['traduct']->get(14).'</i></span>';
  147.         echo str_repeat(' ', 10);
  148.         if(!$GLOBALS['workDb']->isReadOnly() && displayCondition('del')) echo '<a href="main.php?dbsel='.$GLOBALS['dbsel'].'&function='.$this->function.'&action=delete" class="base" target="main">'.$GLOBALS['traduct']->get(15).'</a>';
  149.         else echo '<span class="base"><i>'.$GLOBALS['traduct']->get(15).'</i></span>';
  150.         echo '</div>';
  151.         echo '</center>';
  152. }
  153.  
  154.     /**
  155.     * Display FUNCTION add or modify Form
  156.     *
  157.     * @access public
  158.     */
  159.     function functEditForm(){
  160.       echo '<!-- SQLiteFunctionProperties.class.php : functEditForm() -->'."\n";
  161.         echo '<br><center>';
  162.         if($GLOBALS['action']=='add') echo '<h4>'.$GLOBALS['traduct']->get(16).'</h4>';
  163.         else echo '<h4>'.$GLOBALS['traduct']->get(17).' : '.$this->function.'</h4>';
  164.         if($this->isExist){
  165.             $FunctName = $this->function;
  166.             $FunctProp = $this->functionProperties;
  167.             $attribAll = (($FunctProp['base_id']=='')? 1 : 0 );
  168.         } else {
  169.             $FunctName = '';
  170.             $FunctProp = array('id'=>false, 'funct_type'=>1, 'funct_code'=>'', 'funct_final_code'=>'', 'funct_num_args'=>0);
  171.             $attribAll = 0;
  172.         }
  173.         echo "    <script type=\"text/javascript\">
  174.                 function subform(){
  175.                     base=document.forms['functprop'];
  176.                     error=false;
  177.                     if(base.elements['FunctName'].value=='') error=true;
  178.                     if(base.elements['FunctCode'].value=='') error=true;
  179.                     if(base.elements['FunctNumArgs'].value=='') error=true;
  180.                     if( (base.elements['FunctType'].selectedIndex==1) && (base.elements['FunctFinalCode'].value=='') ) error=true;
  181.                     if(!error){
  182.                         if(base.elements['function'].value=='') base.elements['function'].value=base.FunctName.value;
  183.                         return true;
  184.                     } else {
  185.                         alert('".html_entity_decode($GLOBALS['traduct']->get(18), ENT_NOQUOTES, $GLOBALS['charset'])."');
  186.                         return false;
  187.                     }
  188.                 }
  189.                 </script>";
  190.         echo '<form name="functprop" action="main.php?dbsel='.$GLOBALS['dbsel'].'" method="POST" onSubmit="return subform();" target="main">';
  191.         echo "\t".'<table cellpadding="2" cellspacing="0" width="80%">';
  192.         echo "\t".'<tr><td align="right" class="viewPropTitle">'.$GLOBALS['traduct']->get(19).' :</td><td class="viewProp"><input type="text" class="text" name="FunctName" value="'.$FunctName.'"></td>';
  193.         echo "\t".'<tr><td align="right" class="viewPropTitle">'.$GLOBALS['traduct']->get(20).' :</td><td class="viewProp"><select name="FunctType" onChange="ftype();"><option value="1"'.(($FunctProp['funct_type']==1)? ' selected="selected"' : '' ).'>'.$GLOBALS['traduct']->get(10).'</option><option value="2"'.(($FunctProp['funct_type']==2)? ' selected="selected"' : '' ).'>Aggregation</option></select></td>';
  194.         echo "\t".'<tr><td align="right" class="viewPropTitle">'.$GLOBALS['traduct']->get(21).' :</td><td class="viewProp"><textarea name="FunctCode" cols="'.TEXTAREA_NB_COLS.'" rows="'.TEXAREA_NB_ROWS.'">'.htmlentities($FunctProp['funct_code'], ENT_NOQUOTES, $GLOBALS['charset']).'</textarea></td>';
  195.         echo "\t".'<tr><td align="right" class="viewPropTitle"><div id="Pfinal1">'.$GLOBALS['traduct']->get(22).' :</div></td><td class="viewProp"><div id="Pfinal2"><textarea name="FunctFinalCode" cols="'.TEXTAREA_NB_COLS.'" rows="4">'.htmlentities($FunctProp['funct_final_code'], ENT_NOQUOTES, $GLOBALS['charset']).'</textarea></div></td>';
  196.         echo "\t".'<tr><td align="right" class="viewPropTitle">'.$GLOBALS['traduct']->get(23).' :</td><td class="viewProp"><input type="text" class="text" name="FunctNumArgs" value="'.$FunctProp['funct_num_args'].'"></td>';
  197.         echo "\t".'<tr><td align="right" class="viewPropTitle"> </td><td class="viewProp"><input type="checkbox" name="FunctAttribAll" value="1"'.(($attribAll)? ' checked="checked"' : '' ).'> '.$GLOBALS['traduct']->get(24).'</td>';
  198.         echo "\t".'</table>';
  199.         echo '<input type="hidden" name="function" value="'.$this->function.'">'."\n";
  200.         if($FunctProp['id']) echo '<input type="hidden" name="id" value="'.$FunctProp['id'].'">'."\n";
  201.         echo '<input type="hidden" name="action" value="save">'."\n";
  202.         echo '<input class="button" type="submit" value="'.$GLOBALS['traduct']->get(51).'">';
  203.         echo '</form></center>';
  204.         echo '<script type="text/javascript">ftype();</script>';
  205.  
  206.     }
  207. }
  208.  
  209. ?>
  210.  
  211.  
  212.