Source for file DBMS_FIELD_DBOPTGRPSELLIST.phpclass
Documentation is available at DBMS_FIELD_DBOPTGRPSELLIST.phpclass
* Class file DBMS_FIELD_DBOPTGRPSELLIST.phpclass
* @project Open CSP-Management
* @author Peter Krebs <p.krebs@lvus.at>
* @copyright © 2002-2005 by Peter Krebs and Landesverlag Unternehmensservice
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
if (empty($GLOBALS['OCSP']['PHPFORMPATH'])) $GLOBALS['OCSP']['PHPFORMPATH']=
dirname(__FILE__
).
"/";
require_once dirname(__FILE__
).
"/DBMS_FIELD_DBSELECTLIST.phpclass";
* Class DBMS_FIELD_DBOPTGRPSELLIST
* @project Open CSP-Management
* @author Peter Krebs <p.krebs@wpus.at>
* @author amicas project <opencsp@amicas.at>
* @copyright © 2002-2005 by WURM & Partner Unternehmensservice
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
// ###########################################################
// OBJECT (CONST) VAR DECLARATION
// ###########################################################
* source file of the class
* @var string $classSrcFile
* @var boolean $navigateGrps use a select for each grp and call reload on Change
// ###########################################################
// OBJECT SETTINGS METHODS
// ###########################################################
* returns an array of field to bie shown in the edit form
* by using editTbl_echoForm
* the array is in the form:
* [FLDLAB] (complete html code with <td></td>)
* [FLDVAL] (complete html code with <td></td>)
$a_ret['LAYOUT']['FLD_NAVIGATEGRPS']=
array(
'FLDLAB'=>
"Gruppen Navigation",
'FLDVAL'=>
"<input type=\"checkbox\" name=\"navigateGrps\" value=\"1\" ".
($this->navigateGrps ?
"checked" :
"").
"> Ja, jede Gruppe in eigenem Select darstellen"
$a_ret['SELECT']['FLD_VALQUERY'] =
NULL; // unset parent field
$a_ret['SELECT']['FLD_RADCHKBOX'] =
NULL; // unset parent field
$a_ret['DBLOOKUP']=
array(
'TITLE' =>
"DB Lookup Definition",
'FLDVAL'=>
"SELECT <input name=\"dbFields\" value=\"".
htmlspecialchars($this->dbFields).
"\" size=\"30\">"
'FLDLAB'=>
"Where Template <a href=\"".
$GLOBALS['OCSP']['SYSTEMURL'].
"help/templatevars.html\" target=\"_blank\">?</a>",
'FLDVAL'=>
"WHERE <textarea name=\"dbWhere\" rows=\"2\" cols=\"30\">".
htmlspecialchars($this->dbWhere).
"</textarea>"
'FLDLAB'=>
"Gruppierungs Feld(er)",
'FLD_SHOWLSTSORT'=>
array(
'FLDLAB'=>
"Soritier Feld (Liste)",
'FLD_LSTADDVALUES' =>
NULL, // placeholder if subclasses need this
'FLD_LSTEDITVALUES'=>
NULL // placeholder if subclasses need this
* echos the filed definition form
* save the filed definition form
$this->dbFields=
$_POST['dbFields'];
$this->dbWhere =
$_POST['dbWhere'];
// set database query for parent methods which use this
$query=
"SELECT ".
$this->dbFields.
" FROM ".
$this->dbTables;
if (!empty($this->dbWhere)) $query.=
" WHERE ".
$this->dbWhere;
$this->query=
$GLOBALS[$this->getGlobalDBObjIdx()]->checkQuery($query,PQT_SELECT);
// ###########################################################
// ###########################################################
* returns an array of all group fields or an empty array
* if explode(",",$this->dbGroupBy) fails
* @todo check if we have a complex dbGroupBy with for example CONCAT(xxx,yyy)
* returns the number of group fields used
* returns an array with key and value column name
* or NULL in case of an error
if ($a_fields=
explode(",",$this->dbFields,2)) {
$a_ret['MYKEY']=
$a_fields[0];
if (empty($a_fields[1])) {
$a_ret['MYVAL']=
$a_fields[0];
$a_ret['MYVAL']=
$a_fields[1];
if ($debug) echoDebug(__FILE__
,"<p>Could not explode ".
$this->dbFields.
"</p>");
* returns the SQL statement for key,values,groups
* @param boolean $withOrder omit 'ORDER BY ...'
function getSQLStmt($withOrder=
TRUE,$debug=
FALSE) {
$s_query=
"SELECT ".
$a_keyval['MYKEY'].
" AS MYKEY,".
$a_keyval['MYVAL'].
" AS MYVAL";
for ($i=
0;$i<
$i_nofGrps;$i++
) {
$s_query.=
",".
$a_grps[$i].
" AS MYGRP".
$i;
if (!empty($this->dbWhere)) $s_query.=
" WHERE ".
$this->dbWhere;
$s_query.=
$a_keyval['MYVAL'];
// ###########################################################
// OBJECT HTML FORM METHODS
// ###########################################################
* returns a string with the options
* @param array $aValArr array of selected values
* @param bool $addNULL add the null option (for search)
$debug=
($debug ||
$this->fldDebug); // <pk-04-08-31>
echo
"<p><b>DBMS_FIELD_DBOPTGRPSELLIST::getOptionList(\$aValArr,$addNULL,...)</b> (".
get_class($this).
"/".
$this->myName.
")</p>";
echo
"<blockquote><p>\$aValArr</p><pre>".
print_r($aValArr,TRUE).
"</pre></blockquote>";
$s_ret.=
"\t<option value=\"\">".
$this->nullLabel.
"</option>\n";
// ERROR no SQL statement
if ($debug) echoDebug(__FILE__
,"<p>NO SQL STATEMENT</p>");
if (!is_object($GLOBALS[$this->getGlobalDBObjIdx()])) {
$objcmd =
"\$DBOBJ = new DB_".
$GLOBALS['PROJECT']['DBTYPE'].
";";
$DBOBJ->publicConnect($GLOBALS['PROJECT']['DBCONF']);
$DBOBJ=
&$GLOBALS[$this->getGlobalDBObjIdx()];
if (($DBOBJ->isConnected()) &&
($s_query=
$DBOBJ->checkQuery($s_query,PQT_SELECT))) {
if ($cursor=
$DBOBJ->query($s_query)) {
for ($i=
0;$i<
$i_nofGrps;$i++
) {
$a_aktGrp[$i]['VAL'] =
NULL;
$a_aktGrp[$i]['OPEN'] =
FALSE;
while($a_row=
$cursor->fetchArrayFld()) {
if ($a_aktGrp[$i]['VAL'] !=
$a_row['MYGRP'.
$i]) {
if ($a_aktGrp[$j]['OPEN']) $s_ret.=
"</optgroup>\n";
$s_ret.=
"<optgroup label=\"".
$a_row['MYGRP'.
$i].
"\">\n";
$a_aktGrp[$i]['VAL'] =
$a_row['MYGRP'.
$i];
$a_aktGrp[$i]['OPEN'] =
TRUE;
$s_ret.=
"\t<option value=\"".
$a_row['MYKEY'].
"\"";
if ((!empty($a_row['MYKEY'])) &&
in_array($a_row['MYKEY'],$aValArr)) $s_ret .=
" selected"; /* <pk-05-02-17 changed if condition to increase performance />*/
$s_ret.=
">".
$a_row['MYVAL'].
"</option>\n";
for ($i=
0;$i<
$i_nofGrps;$i++
) {
if ($a_aktGrp[$i]['OPEN']) $s_ret.=
"</optgroup>\n";
if ($toDisconnect) $DBOBJ->disconnect();
* returns the html code for a grouped select
* @param int $nofvals number of values in group
* @param array $selValues
* @todo change $GLOBALS['USRDB'] to the propriate DB by using self::getGlobalDBObjIdx()
function getGrpSelect(&$nofvals,$grpCol,&$selValues,$debug=
FALSE) {
if ($debug) echoDebugMethod(__FILE__
,get_class($this),"DBMS_FIELD_DBOPTGRPSELLIST::getGrpSelect","grpCol=".
$grpCol.
"\nselValues=".
print_r($selValues,TRUE),0);
$s_query=
"SELECT COUNT(*) AS NOFENTRIES,".
$grpCol;
if (!empty($this->dbWhere)) $s_query.=
" WHERE ".
$this->dbWhere;
$s_query.=
" GROUP BY $grpCol";
$s_query.=
$a_keyval['MYVAL'];
if ($debug) echoDebug(__FILE__
,"<p>".
$s_query.
"</p>");
$s_tag.=
(($this->multiselect) ?
"[]' multiple size='3'" :
"' ");
$s_tag.=
" ".
$this->getOnChangeRelaod($this->myDataArrName).
">\n";
$s_firstVal=
"";$b_valFound=
FALSE;
if ($o_cursor=
$GLOBALS['USRDB']->query($s_query)) {
while($a_row=
$o_cursor->fetchArrayNum()) {
$s_tag.=
"\t<option value=\"".
$a_row[1].
"\"";
$s_tag.=
">".
$a_row[1].
"</option>\n";
$s_firstVal=
$a_row[1]; // cache first value in case we only have 1
if (!$b_valFound) $selValues[]=
$s_firstVal;
} else if ($nofvals==
1) {
return "<input type=\"hidden\" name=\"".
$this->myDataArrName.
"[__".
$this->myName.
"_GRP][".
$grpCol.
"]\" value=\"$s_firstVal\">$s_firstVal \n";
* returns the html code for the select
* @todo change $GLOBALS['USRDB'] to the propriate DB by using self::getGlobalDBObjIdx()
function getSelectTag($aValue,$arrName=
"DBVAL",$debug=
FALSE) {
$debug=
($debug ||
$this->fldDebug); // <pk-04-08-31>
// no need to do special handling
return parent::getSelectTag($aValue,$arrName,$debug);
if (!($i_nofGrps=
sizeof($a_grps))) {
// empty array -> no need for special handling
return parent::getSelectTag($aValue,$arrName,$debug);
foreach($a_grps as $i_idx =>
$s_grpCol) {
$a_grpSelValues[$i_idx]=
$a_values;
} else if (!empty($a_values)){
$a_grpSelValues[$i_idx][]=
$a_values;
} else if (!empty($aValue)) {
if (!strstr($s_query,"WHERE")) $s_query.=
" WHERE ";
$s_query.=
$a_keyval['MYKEY'].
" IN (";
foreach($valArr as $s_val) {
$s_query.=
$c_sep.
$GLOBALS['USRDB']->qs_getSlashedValue($s_val);
if ($debug) echoDebug(__FILE__
,"<p>value select: ".
$s_query.
"</p>");
if ($o_cursor=
$GLOBALS['USRDB']->query($s_query)) { // todo change fixed DB connection
while($a_row=
$o_cursor->fetchArrayFld()) {
for ($i=
0;$i<
$i_nofGrps;$i++
) {
if ((!is_array($a_grpSelValues[$i])) ||
(!in_array($a_row['MYGRP'.
$i],$a_grpSelValues[$i]))) {
$a_grpSelValues[$i][]=
$a_row['MYGRP'.
$i];
for ($i=
0;$i<
$i_nofGrps;$i++
) {
$s_ret.=
$this->getGrpSelect($i_nofGrpsVals,$a_grps[$i],$a_grpSelValues[$i],$debug);
$s_query=
"SELECT ".
$a_keyval['MYKEY'].
" AS MYKEY,".
$a_keyval['MYVAL'].
" AS MYVAL";
if (!empty($this->dbWhere)) {
$s_query.=
" WHERE ".
$this->dbWhere;
$s_query.=
" WHERE 1=1 "; // dummy to use AND
for ($i=
0;$i<
$i_nofGrps;$i++
) {
$s_query.=
" AND ".
$a_grps[$i].
" IN (";
foreach($a_grpSelValues[$i] as $s_key) {
$s_query.=
$c_sep.
$GLOBALS['USRDB']->qs_getSlashedValue($s_key);
$s_query.=
$a_keyval['MYVAL'];
if ($o_cursor=
$GLOBALS['USRDB']->query($s_query)) {
$s_detsel =
"<select name='".
$arrName.
"[".
$this->myName.
"]";
$s_detsel .=
(($this->multiselect) ?
"[]' multiple " :
"' ");
$s_detsel.=
" ".
$this->getOnChangeRelaod($arrName);
while($a_row=
$o_cursor->fetchArrayFld()) {
$s_detsel.=
"\t<option value=\"".
$a_row['MYKEY'].
"\">".
$a_row['MYVAL'].
"</option>\n";
$s_detsel.=
"</select>\n";
// ###########################################################
// ###########################################################
// ###########################################################
// OBJECT HTML FORM METHODS
// ###########################################################
// ###########################################################
// OBJECT VALUE CHECK METHODS
// ###########################################################
} // end class DBMS_FIELD_DBOPTGRPSELLIST
Documentation generated on Thu, 08 Jan 2009 17:41:14 +0100 by phpDocumentor 1.4.0a2