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 $
10
class SQLiteFunctionProperties {
13
* reference to the connection object
29
* this function exist?
37
* Properties of the current FUNCTION
42
var $functionProperties;
48
* @param object $conn reference to the connection object
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'];
58
$this->isExist = $this->functionExist($this->function);
59
return $this->isExist;
63
* Verify if this FUNCITION exist
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){
74
foreach($tempTabFunction as $tempFunctProp) {
75
$this->functionProperties = $tempFunctProp;
83
* save properties of the current FUNCTION
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);';
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)){
101
while(list($key, $value) = each($tabSQL)) $tabUpdate[] = $key.'='.$value;
102
$queryDisplay = 'UPDATE user_function SET '.implode(',', $tabUpdate).' WHERE id='.$_POST['id'].';';
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).');';
112
$res = $GLOBALS['db']->query($queryDisplay);
114
$errorCode = @sqlitem_last_error($this->connId->connId);
115
$errorMessage .= $GLOBALS['traduct']->get(9).' '.$errorCode.' : '.@$this->connId->connId->getError()."\n";
117
displayQuery($queryDisplay);
118
if(!empty($errorMessage)) displayError($errorMessage);
119
if($GLOBALS['action']!='delete') {
121
echo "<script type=\"text/javascript\">parent.left.location='left.php?dbsel=".$GLOBALS["dbsel"]."';</script>";
123
echo "<script type=\"text/javascript\">parent.left.location='left.php?dbsel=".$GLOBALS["dbsel"]."'; parent.main.location='main.php?dbsel=".$GLOBALS["dbsel"]."';</script>";
128
* Display current FUNCITION properties
133
echo '<!-- SQLiteFunctionProperties.class.php : propView() -->'."\n";
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>';
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>';
155
* Display FUNCTION add or modify Form
159
function functEditForm(){
160
echo '<!-- SQLiteFunctionProperties.class.php : functEditForm() -->'."\n";
162
if($GLOBALS['action']=='add') echo '<h4>'.$GLOBALS['traduct']->get(16).'</h4>';
163
else echo '<h4>'.$GLOBALS['traduct']->get(17).' : '.$this->function.'</h4>';
165
$FunctName = $this->function;
166
$FunctProp = $this->functionProperties;
167
$attribAll = (($FunctProp['base_id']=='')? 1 : 0 );
170
$FunctProp = array('id'=>false, 'funct_type'=>1, 'funct_code'=>'', 'funct_final_code'=>'', 'funct_num_args'=>0);
173
echo " <script type=\"text/javascript\">
175
base=document.forms['functprop'];
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;
182
if(base.elements['function'].value=='') base.elements['function'].value=base.FunctName.value;
185
alert('".html_entity_decode($GLOBALS['traduct']->get(18), ENT_NOQUOTES, $GLOBALS['charset'])."');
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>';