198 $this->ShowFirstPage=FALSE;
199 $this->show_field=array();
201 $this->db_info=array();
202 $this->show_info=array();
203 $this->modify_info=array();
204 $this->SearchCfg=array();
205 $this->Pre_1_0_Style=
true;
206 $this->Db_Class=NULL;
223 $this->SearchObj=
new CYap_clsSearch($this->SearchCfg,$this->Lang);
226 $this->SearchObj->AddRowPerPage();
233 $this->DetailMode=FALSE;
234 $this->WrongFields=array();
245 require_once($FileName);
246 if(isset($SearchFieldCfg))
248 if(is_array($SearchFieldCfg))
249 $this->SearchCfg=$SearchFieldCfg;
251 trigger_error(
'Configuratin error. $SearchFieldCfg should be an array'.E_USER_ERROR);
253 if(isset($ShowFieldCfg))
255 if(is_array($ShowFieldCfg))
256 $this->show_field=$ShowFieldCfg;
258 trigger_error(
'Configuratin error. $ShowFieldCfg should be an array'.E_USER_ERROR);
260 if(isset($DbInfoCfg))
262 if(is_array($DbInfoCfg))
263 $this->db_info=$DbInfoCfg;
265 trigger_error(
'Configuratin error. $DbInfoCfg should be an array'.E_USER_ERROR);
267 if(isset($ShowInfoCfg))
269 if(is_array($ShowInfoCfg))
270 $this->show_info=$ShowInfoCfg;
272 trigger_error(
'Configuratin error. $ShowInfoCfg should be an array'.E_USER_ERROR);
274 if(isset($ModifyInfoCfg))
276 if(is_array($ModifyInfoCfg))
277 $this->modify_info=$ModifyInfoCfg;
279 trigger_error(
'Configuratin error. $ModifyInfoCfg should be an array'.E_USER_ERROR);
294 foreach($info as $key => $value)
295 $this->show_field[$key]=$value;
307 foreach($info as $key => $value)
308 $this->db_info[$key]=$value;
309 $this->NeedOpenDb=
true;
315 if(isset($this->db_info[
"orderfield"])) { $this->OrderField=$this->db_info[
"orderfield"]; }
316 else { $this->OrderField=
"id"; }
318 if(isset($this->db_info[
"orderdirection"])) { $this->OrderDirection=$this->db_info[
"orderdirection"]; }
319 else { $this->OrderDirection=
"A"; }
321 if(isset($this->db_info[
"needopendb"])) { $this->NeedOpenDb=$this->db_info[
"needopendb"]; }
323 if($this->NeedOpenDb) $this->DbOpened=
false;
324 else $this->DbOpened=
true;
325 if(array_key_exists(
'db_class',$this->db_info))
328 if(!class_exists($this->db_info[
'db_class']))
329 trigger_error(
'ERROR: the class '.$this->db_info[
'db_class'].
' does not exists',E_USER_ERROR);
330 eval(
'$this->Db_Class=new '.$this->db_info[
'db_class'].
'();');
348 foreach($info as $key => $value)
349 $this->SearchCfg[$key]=$value;
361 foreach($info as $key => $value)
362 $this->show_info[$key]=$value;
363 if(array_key_exists(
'prefix',$this->show_info))
364 $this->Prefix=$this->show_info[
'prefix'];
365 $fileName=
'./language.en';
366 if(array_key_exists(
'languagefile',$this->show_info))
367 $fileName=$this->show_info[
'languagefile'];
368 $this->show_info[
'languagefile']=$fileName;
369 $this->Lang=parse_ini_file($fileName);
370 if(array_key_exists(
'showfirstcallrow',$this->show_info))
371 $this->ShowFirstPage=$this->show_info[
'showfirstcallrow'];
372 $defMode=(array_key_exists(
'detailmode',$this->show_info))?(($this->show_info[
'detailmode'])?
'DisplayDetail':
'DisplayTable'):
'DisplayTable';
373 $tmpMode=(array_key_exists(
'mode',$this->show_info))?$this->show_info[
'mode']:$defMode;
374 switch(strtolower($tmpMode))
377 $this->Mode=
'DisplayTable';
379 case 'displaydetail':
380 $this->Mode=
'DisplayDetail';
383 $this->Mode=
'Modify';
384 if(!array_key_exists(
'keyid',$this->show_info))
385 trigger_error(
'Modify mode requested, but keyid is not supplied',E_USER_ERROR);
391 trigger_error(
'Invalid mode',E_USER_ERROR);
394 if(!array_key_exists(
'onokhref',$this->show_info))
395 $this->show_info[
'onokhref']=$_SERVER[
'PHP_SELF'];
396 if(!array_key_exists(
'onaborthref',$this->show_info))
399 $this->show_info[
'onaborthref']=
'javascript:this.form.ev.value=\'YAP_ABORTMODIFY\';this.form.submit()';
404 $this->show_info[
'onaborthref']=
'javascript:this.form.ev.value=\'YAP_ABORTMODIFY\';
405 this.form.action=\''.$info[
'onaborthref'].
'\';
409 if(!array_key_exists('boxclass
',$this->show_info))
410 $this->show_info['boxclass
']='CYapBox';
411 if(!array_key_exists('detailviewclass
',$this->show_info))
413 if(!array_key_exists('tableviewclass
',$this->show_info))
415 if(!array_key_exists('skippageclass
',$this->show_info))
417 if(!array_key_exists('pagenumberclass
',$this->show_info))
419 if(!array_key_exists('formclass
',$this->show_info))
420 $this->show_info['formclass
']='CYap_Form
';
421 // check whether the classes exist
422 if(!class_exists($this->show_info['boxclass
']))
423 trigger_error('Undefined
class '.$this->show_info['boxclass'],E_USER_ERROR);
424 if(!class_exists($this->show_info[
'detailviewclass']))
425 trigger_error(
'Undefined class '.$this->show_info[
'detailviewclass'],E_USER_ERROR);
426 if(!class_exists($this->show_info[
'tableviewclass']))
427 trigger_error(
'Undefined class '.$this->show_info[
'tableviewclass'],E_USER_ERROR);
428 if(!class_exists($this->show_info[
'skippageclass']))
429 trigger_error(
'Undefined class '.$this->show_info[
'skippageclass'],E_USER_ERROR);
430 if(!class_exists($this->show_info[
'pagenumberclass']))
431 trigger_error(
'Undefined class '.$this->show_info[
'pagenumberclass'],E_USER_ERROR);
432 if(!class_exists($this->show_info[
'formclass']))
433 trigger_error(
'Undefined class '.$this->show_info[
'formclass'],E_USER_ERROR);
434 if(!array_key_exists(
'customdetpage',$this->show_info))
435 $this->show_info[
'customdetpage']=$_SERVER[
'PHP_SELF'];
436 if(!array_key_exists(
'showpagenumber',$this->show_info))
437 $this->show_info[
'showpagenumber']=
true;
438 if(!array_key_exists(
'showmovepage',$this->show_info))
439 $this->show_info[
'showmovepage']=
true;
441 if(array_key_exists(
'pre_1_0_style',$this->show_info))
442 $this->Pre_1_0_Style=$this->show_info[
'pre_1_0_style'];
454 foreach($info as $key => $value)
455 $this->modify_info[$key]=$value;
457 if(!array_key_exists(
'showadd',$this->modify_info))
458 $this->modify_info[
'showadd']=
false;
459 if(!array_key_exists(
'showdelete',$this->modify_info))
460 $this->modify_info[
'showdelete']=
false;
461 if(!array_key_exists(
'showmodify',$this->modify_info))
462 $this->modify_info[
'showmodify']=
false;
465 if($this->modify_info[
'showmodify']
466 ||$this->modify_info[
'showdelete']
467 ||$this->modify_info[
'showadd'])
469 if(!array_key_exists(
'table',$this->modify_info))
470 trigger_error(
'ERROR: index table not found in modify_info array',E_USER_ERROR);
471 if(!array_key_exists(
'keyfield',$this->modify_info))
472 trigger_error(
'ERROR: index keyfield not found in modify_info array',E_USER_ERROR);
474 if(!array_key_exists(
'fields',$this->modify_info))
475 $this->modify_info[
'fields']=array();
477 $this->modify_info[
'fields']=$this->modify_info[
'fields'];
478 if(array_key_exists(
'fieldvalidator',$this->modify_info))
479 $validator=$this->modify_info[
'fieldvalidator'];
482 if(array_key_exists(
'fieldtorequest',$this->modify_info))
485 foreach($this->modify_info[
'fieldtorequest'] as $FieldName)
487 if(!array_key_exists($FieldName,$this->modify_info[
'fields']))
488 $this->modify_info[
'fields'][$FieldName]=array();
489 if(array_key_exists($FieldName,$validator))
490 $this->modify_info[
'fields'][$FieldName][
'fieldvalidator']=$validator[$FieldName];
493 if(!array_key_exists(
'customaddpage',$this->modify_info))
494 $this->modify_info[
'customaddpage']=$_SERVER[
'PHP_SELF'];
495 if(!array_key_exists(
'custommodifypage',$this->modify_info))
496 $this->modify_info[
'custommodifypage']=$_SERVER[
'PHP_SELF'];
497 if(!array_key_exists(
'customdeletepage',$this->modify_info))
498 $this->modify_info[
'customdeletepage']=$_SERVER[
'PHP_SELF'];
522 $this->SearchObj=$newObject;
542 $PresetFormat=array (
543 'NONE' =>
'$txt_out=$txt_in;',
544 'NUMERIC_IT' =>
'$txt_out=number_format($txt_in,0,",",".");',
545 'NUMERIC_EN' =>
'$txt_out=number_format($txt_in,2);',
546 'MONEY_IT' =>
'$txt_out=number_format($txt_in,2,",",".");',
547 'MONEY_EN' =>
'$txt_out=number_format($txt_in,2,".",",");',
548 'DATE_IT' =>
'$txt_out=date("d/m/Y",$txt_in);',
549 'DATE_US' =>
'$txt_out=date("m/d/Y",$txt_in);',
551 $this->OutFormats=array();
553 foreach ($PresetFormat as $key => $value)
554 $this->OutFormats[$key]=$value;
556 if(array_key_exists(
'outformats',$this->show_info))
558 foreach($this->show_info[
'outformats'] as $formatName => $formatParam)
561 if(array_key_exists(
'number',$formatParam))
562 { $cmd=
'number_format($txt_in,'.$formatParam[
'number'].
')'; }
563 if(array_key_exists(
'date',$formatParam))
564 { $cmd=
'date("'.$formatParam[
'date'].
'",'.$cmd.
')'; }
565 if(array_key_exists(
'sprintf',$formatParam))
566 { $cmd=
'sprintf("'.$formatParam[
'sprintf'].
'",'.$cmd.
')'; }
567 if(array_key_exists(
'custom',$formatParam))
568 { $cmd=$formatParam[
'custom'].
'('.$cmd.
')'; }
569 $cmd=
'$txt_out='.$cmd.
';';
570 $this->OutFormats[$formatName]=$cmd;
583 if(isset($_SESSION[$this->Prefix.
"DatiPerQuery"])) {unset($_SESSION[$this->Prefix.
"DatiPerQuery"]); }
584 if(isset($_SESSION[$this->Prefix.
"TotRow"])) { unset($_SESSION[$this->Prefix.
"TotRow"]); }
585 if(isset($_SESSION[$this->Prefix.
"OrderDirection"])) { unset($_SESSION[$this->Prefix.
"OrderDirection"]); }
586 if(array_key_exists($this->Prefix.
"DetailMode",$_SESSION)) {unset($_SESSION[$this->Prefix.
"DetailMode"]);}
587 if(isset($_SESSION[$this->Prefix.
"OrderField"])) { unset($_SESSION[$this->Prefix.
"OrderField"]);
588 unset($_SESSION[
"OrderField"]);
589 $this->SearchObj->CleanSessionInfo($this->Prefix);
600 if(
DEBUG) $GLOBALS[
'debug']->f_in(
'_InitializeSessionVar');
604 if(isset($this->show_info[
"exit"])) { $this->PagerExit=$this->show_info[
"exit"];}
605 else {
if(array_key_exists(
'HTTP_REFERER',$_SERVER))
606 $this->PagerExit=$_SERVER[
'HTTP_REFERER'];
614 if(
DEBUG) $GLOBALS[
'debug']->f_out(
'_InitializeSessionVar');
631 if(substr($ev,0,4)!=
'YAP_')
633 if(!array_key_exists($ev,$this->EventTable))
634 trigger_error(
'Unknown event '.$ev,E_USER_ERROR);
636 if($this->EventTable[$ev]!=
'')
638 if(method_exists($this,$this->EventTable[$ev]))
639 call_user_func(array(&$this,$this->EventTable[$ev]));
640 elseif(function_exists($this->EventTable[$ev]))
641 call_user_func($this->EventTable[$ev]);
643 trigger_error(
'ERROR: the requested handler '.$this->EventTable[$ev].
' does not exist',E_USER_ERROR);
655 $this->EventTable=array(
656 'YAP_ORDERUP' =>
'_OnOrderUp',
657 'YAP_ORDERDOWN' =>
'_OnOrderDown',
658 'YAP_DETAILCLICK' =>
'_OnDetailClick',
659 'YAP_MODIFYCLICK' =>
'_OnModifyClick',
660 'YAP_DOMODIFY' =>
'_OnDoModify',
661 'YAP_ABORTMODIFY' =>
'_OnAbortModify',
662 'YAP_REMOVECLICK' =>
'_OnRemoveClick',
663 'YAP_DOREMOVE' =>
'_OnDoRemove',
664 'YAP_ABORTREMOVE' =>
'_OnAbortRemove',
665 'YAP_CMDEXECUTED' =>
'_OnCmdExecuted',
666 'YAP_TOPAGE' =>
'_OnToPage',
667 'YAP_EXIT' =>
'_OnExit',
668 'YAP_TABLEVIEW' =>
'_OnTableView',
669 'YAP_NEWROW' =>
'_OnNewRow',
670 'YAP_DOSAVEROW' =>
'_OnDoSaveRow',
671 'YAP_ABORTSAVEROW' =>
'_OnAbortSaveRow',
672 'YAP_SEARCH' =>
'_OnSearch',
673 'YAP_FIRSTTIME' =>
'_OnFirstTime',
674 'YAP_DRAWCURRENT' =>
'_OnDrawCurrent',
686 $this->EventTable[$EventName]=$Handler;
712 $this->DetailMode=TRUE;
713 $this->Mode=
'DisplayDetail';
788 if(!array_key_exists(
'pag',$_REQUEST))
789 trigger_error(
'ERROR: the parameter pag doesn\'t exist',E_USER_ERROR);
803 $this->DetailMode=FALSE;
804 $this->Mode=
'DisplayTable';
856 if($this->Mode==
'DisplayDetail') $this->DetailMode=TRUE;
864 $_SESSION[$this->Prefix.
"daform"]=1;
890 $GLOBALS[
'debug']->f_in(
'showpage');
891 $GLOBALS[
'debug']->startTimer();
892 $GLOBALS[
'debug']->DumpVar($_SESSION,
'$_SESSION');
900 if(!array_key_exists(
'ev',$_REQUEST))
905 if(substr($_REQUEST[
'ev'],0,4)==
'YAP_')
910 $ev=
'YAP_DRAWCURRENT';
918 if(!array_key_exists($this->Prefix.
"DetailMode",$_SESSION))
921 if(array_key_exists(
"reset",$_REQUEST)) $ev=
'YAP_FIRSTTIME';
923 if($ev!=
'YAP_FIRSTTIME')
926 if(!array_key_exists($this->Prefix.
"PagerExit",$_SESSION))
931 trigger_error(
"Error: I'm not able to find the session vars!",E_USER_ERROR);
934 $this->PagerExit=$_SESSION[$this->Prefix.
"PagerExit"];
938 if($ev!=
'YAP_FIRSTTIME'
954 $GLOBALS[
'debug']->stopTimer();
955 $GLOBALS[
'debug']->getTime();
956 $GLOBALS[
'debug']->DumpVar($_SESSION,
'$_SESSION');
957 $GLOBALS[
'debug']->f_out(
'showpage');
958 $GLOBALS[
'debug']->ShowTrace();
959 $GLOBALS[
'debug']->SaveTrace(
'trace.txt');
983 case 'DisplayDetail':
1010 trigger_error(
'Internal Error: invalid mode',E_USER_ERROR);
1025 if(isset($this->PageRequest)&&$this->PageRequest>0)
1055 if(
DEBUG) $GLOBALS[
'debug']->f_in(
'analize_request');
1058 $this->SearchObj->ReadFormData();
1060 $this->SearchObj->StoreInformation($this->Prefix);
1061 $this->PagSize=$this->SearchObj->GetPageSize();
1068 $this->PageRequest=1;
1073 if(isset($_SESSION[$this->Prefix.
"TotRow"])) { unset($_SESSION[$this->Prefix.
"TotRow"]); }
1074 if(
DEBUG) $GLOBALS[
'debug']->f_out(
'analize_request');
1085 if(
DEBUG) $GLOBALS[
'debug']->f_in(
'load_previous_data');
1090 if(array_key_exists($this->Prefix.
"pag",$_SESSION))
1091 $this->PageRequest=$_SESSION[$this->Prefix.
"pag"];
1092 if(isset($_REQUEST[
"pag"])) {$this->PageRequest=$_REQUEST[
"pag"]; }
1094 $this->SearchObj->LoadInformation($this->Prefix);
1095 if(array_key_exists($this->Prefix.
"PagSize",$_SESSION))
1096 $this->PagSize=$_SESSION[$this->Prefix.
"PagSize"];
1102 if(isset($_SESSION[$this->Prefix.
"OrderDirection"])) { $this->OrderDirection=$_SESSION[$this->Prefix.
"OrderDirection"]; }
1103 if(isset($_SESSION[$this->Prefix.
"OrderField"])) { $this->OrderField=$_SESSION[$this->Prefix.
"OrderField"]; }
1108 if(array_key_exists($this->Prefix.
"DetailMode",$_SESSION)) {$this->DetailMode=$_SESSION[$this->Prefix.
"DetailMode"];}
1116 if(
DEBUG) $GLOBALS[
'debug']->f_out(
'load_previous_data');
1129 $this->SearchObj->JsSearchFormValidate();
1142 $txt=$this->SearchObj->Draw();
1144 echo
"<table align=center>
1147 echo
"</td></tr></table>";
1158 eval(
'$box=new '.$this->show_info[
'boxclass'].
'($txt,\'#000000\',\'#EFEF52\');');
1176 if(isset($_REQUEST[
"of"]))
1178 $this->OrderField=$_REQUEST[
"of"];
1179 $_SESSION[$this->Prefix.
"OrderField"]=$_REQUEST[
"of"];
1182 if(isset($_REQUEST[
"ot"]))
1184 $this->OrderDirection=$_REQUEST[
"ot"];
1185 $_SESSION[$this->Prefix.
"OrderDirection"]=$_REQUEST[
"ot"];
1199 if(!$this->DbOpened) $this->
_OpenDb();
1204 if(isset($_SESSION[$this->Prefix.
"TotRow"])) { $this->TotRow=$_SESSION[$this->Prefix.
"TotRow"]; }
1208 $sql=$this->db_info[
"selectquery"] .
"1=1 ";
1210 $sql.=$this->SearchObj->GetWhereCondition($this->Db_Class);
1212 if(($result=$this->Db_Class->DbExecSql($sql))===FALSE)
1213 trigger_error($this->Db_Class->DbError(),E_USER_ERROR);
1214 $this->TotRow=$this->Db_Class->DbGetNumRow($result);
1216 $this->Db_Class->DbFreeResult($result);
1232 if(
DEBUG) $GLOBALS[
'debug']->f_in(
'show_table_rows');
1234 $sql=$this->db_info[
"selectquery"].
"1=1 ";
1236 $sql.=$this->SearchObj->GetWhereCondition($this->Db_Class);
1240 if($this->OrderDirection==
"D") { $sql.=
" DESC"; }
1243 if($this->DetailMode)
1245 $StartLimit=($this->PageRequest-1);
1250 $StartLimit=($this->PageRequest-1)*$this->PagSize;
1256 if(
DEBUG) $GLOBALS[
'debug']->ToTrace($sql);
1259 if(($result=$this->Db_Class->QueryLimit($sql,$StartLimit,$EndLimit))==FALSE)
1260 trigger_error($this->Db_Class->DbError(),E_USER_ERROR);
1265 if($this->DetailMode)
1269 $this->Db_Class->DbFreeResult($result);
1270 if(
DEBUG) $GLOBALS[
'debug']->f_out(
'show_table_rows');
1277 eval(
'$clsTable=new '.$this->show_info[
'detailviewclass'].
'($this->show_info[\'languagefile\']);');
1279 $clsTable->LoadFormats($this->OutFormats);
1280 $clsTable->BeginTable();
1281 $clsTable->HeaderStart();
1284 $line=$this->Db_Class->DbGetValue($result);
1289 $clsTable->EndTable();
1290 $clsTable->FlushCode();
1295 eval(
'$clsTable=new '.$this->show_info[
'tableviewclass'].
'($this->show_info[\'languagefile\']);');
1298 $clsTable->LoadFormats($this->OutFormats);
1299 $clsTable->BeginTable();
1305 while ($line = $this->Db_Class->DbGetValue($result))
1311 if(array_key_exists(
'showadd',$this->modify_info))
1313 if($this->modify_info[
'showadd'])
1316 $clsTable->EndTable();
1317 $clsTable->FlushCode();
1333 $clsTable->HeaderStart();
1335 $NItem=count($this->show_field);
1339 for($i=0;$i<$NItem;$i++)
1342 $ToShow=(array_key_exists(
'showtable',$this->show_field[$i]))?
1343 $this->show_field[$i][
'showtable']:
1348 $Href= $_SERVER[
"PHP_SELF"] .
"?pag=".$this->PageRequest.
"&of=".$this->show_field[$i][
"fieldname"].
"&ot=";
1349 if($this->show_field[$i][
"fieldname"]==$this->OrderField)
1351 $Href.= ($this->OrderDirection==
"A")?
"D":
"A";
1352 $Href.=
'&ev=YAP_ORDER';
1353 $Href.= ($this->OrderDirection==
"A")?
"DOWN":
"UP";
1355 else { $Href.=
"A&ev=YAP_ORDERUP"; }
1356 $Label=$this->show_field[$i][
"header"];
1357 $clsTable->HeaderCell($Href,$Label);
1360 $clsTable->HeaderClose();
1375 $clsTable->NewRow();
1377 $NItem=count($this->show_field);
1378 for($i=0;$i<$NItem;$i++)
1381 $ToShow=(array_key_exists(
'showtable',$this->show_field[$i]))?
1382 $this->show_field[$i][
'showtable']:
1386 $fmt=(array_key_exists(
'format',$this->show_field[$i]))?$this->show_field[$i][
"format"]:
'NONE';
1387 $clsTable->Cell($RowData[$this->show_field[$i][
"fieldname"]],$this->show_field[$i][
"fieldname"],-1,$fmt);
1392 if(isset($this->show_info[
"showdethref"]))
1394 if($this->show_info[
"showdethref"])
1395 $clsTable->SpecialCell($this->
_DetHrefLink($RowNumber,$RowData),
'DETAIL');
1399 if(array_key_exists(
'showmodify',$this->modify_info))
1401 if($this->modify_info[
'showmodify'])
1406 if(array_key_exists(
'showdelete',$this->modify_info))
1408 if($this->modify_info[
'showdelete'])
1415 if(isset($this->show_info[
"rowcallback"]))
1420 $CustomCell=$this->show_info[
"rowcallback"]($RowData);
1421 if(is_array($CustomCell))
1423 foreach($CustomCell as $key => $value)
1424 $clsTable->Cell($value,
'callback');
1427 $clsTable->Cell($CustomCell,
'callback');
1448 if($this->show_info[
'customdetpage']==$_SERVER[
'PHP_SELF']&&$this->EventTable[
'YAP_DETAILCLICK']==
'_OnDetailClick')
1452 if(!array_key_exists(
'keyfield',$this->modify_info))
1453 trigger_error(
'Error: if you set the custom detail page, you must set the row key field ',E_USER_ERROR);
1454 if(!array_key_exists($this->modify_info[
'keyfield'],$RowData))
1455 trigger_error(
'Error: row key field '.$this->modify_info[
'keyfield'].
' not found',E_USER_ERROR);
1456 $RowId=$RowData[$this->modify_info[
'keyfield']];
1458 $PageNum=$this->PagSize*($this->PageRequest-1)+$RowNumber;
1459 $c=(strpos($this->show_info[
'customdetpage'],
'?')===FALSE)?
'?':
'&';
1460 return($this->show_info[
'customdetpage'].$c.
"ev=YAP_DETAILCLICK&pag=".$PageNum.
"&id=".$RowId);
1471 if(!array_key_exists($this->modify_info[
'keyfield'],$RowData))
1472 trigger_error(
'Error: row key field '.$this->modify_info[
'keyfield'].
' not found',E_USER_ERROR);
1473 $KeyValue=$RowData[$this->modify_info[
'keyfield']];
1476 $c=(strpos($this->modify_info[
'customdeletepage'],
'?')===FALSE)?
'?':
'&';
1477 return($this->modify_info[
'customdeletepage'].$c.
'ev=YAP_REMOVECLICK&id='.urlencode($KeyValue));
1491 if(!array_key_exists($this->modify_info[
'keyfield'],$RowData))
1492 trigger_error(
'Error: row key field '.$this->modify_info[
'keyfield'].
' not found',E_USER_ERROR);
1493 $KeyValue=$RowData[$this->modify_info[
'keyfield']];
1496 $c=(strpos($this->modify_info[
'custommodifypage'],
'?')===FALSE)?
'?':
'&';
1497 return($this->modify_info[
'custommodifypage'].$c.
'ev=YAP_MODIFYCLICK&id='.urlencode($KeyValue));
1512 $c=(strpos($this->modify_info[
'customaddpage'],
'?')===FALSE)?
'?':
'&';
1513 $text=$this->modify_info[
'customaddpage'].$c.
"ev=YAP_NEWROW";
1514 $clsTable->AddRowCell($text);
1531 $lclShowField=array();
1533 for($i=0;$i<count($this->show_field);$i++)
1535 $lclShowField[$this->show_field[$i][
'fieldname']]=(array_key_exists(
'showdetail',$this->show_field[$i]))?
1536 $this->show_field[$i][
'showdetail']:
1538 $fmt[$this->show_field[$i][
'fieldname']]=(array_key_exists(
'format',$this->show_field[$i]))?
1539 $this->show_field[$i][
"format"]:
1543 foreach($Fields as $Key => $Value)
1546 if(array_key_exists($Key,$DataRow))
1547 $special_chars = htmlspecialchars($DataRow[$Key]);
1549 $special_chars = htmlspecialchars(
" ");
1551 $ToShow=(array_key_exists($Key,$lclShowField))?
1552 $lclShowField[$Key]:
1554 if($ToShow||$this->Pre_1_0_Style)
1556 if(array_key_exists($Key,$fmt))
1557 $clsTable->Cell($Key,$special_chars,$Key,$fmt[$Key]);
1559 $clsTable->Cell($Key,$special_chars,$Key,
'NONE');
1572 if($this->show_info[
'showmovepage']==
false)
1583 $FirstPage=($this->PageRequest>1)?1:0;
1585 $p[
'FirstPage']=$_SERVER[
"PHP_SELF"].
"?ev=YAP_TOPAGE&pag=".$FirstPage;
1588 $PrevPage=($this->PageRequest>1)?$this->PageRequest-1:0;
1590 $p[
'PrevPage']=$_SERVER[
"PHP_SELF"].
"?ev=YAP_TOPAGE&pag=".$PrevPage;
1594 $TotPag=ceil($this->TotRow/$rowsXpage);
1597 $NextPage=($this->PageRequest<$TotPag)?$this->PageRequest+1:0;
1599 $p[
'NextPage']=$_SERVER[
"PHP_SELF"].
"?ev=YAP_TOPAGE&pag=".$NextPage;
1602 $LastPage=($this->PageRequest<$TotPag)?$TotPag:0;
1604 $p[
'LastPage']=$_SERVER[
"PHP_SELF"].
"?ev=YAP_TOPAGE&pag=".$LastPage;
1606 if($this->DetailMode)
1607 $p[
'DetailMode']=$_SERVER[
"PHP_SELF"].
"?ev=YAP_TABLEVIEW&pag=".ceil($this->PageRequest/$this->PagSize);
1609 $p[
'Exit']=($this->PagerExit!=
'')?$this->PagerExit:$_SERVER[
'PHP_SELF'];
1612 eval(
'$draw=new '.$this->show_info[
'skippageclass'].
'($this->show_info[\'languagefile\']);');
1625 if($this->show_info[
'showpagenumber']==
false)
1633 $min=($this->PageRequest-5>0)?$this->PageRequest-5:1;
1636 $TotPag=ceil($this->TotRow/$rowsXpage);
1639 $max=($min+10>$TotPag)?$TotPag:$min+10;
1641 eval(
'$draw=new '.$this->show_info[
'pagenumberclass'].
'($this->show_info[\'languagefile\']);');
1643 $draw->Draw($min,$max,$this->PageRequest);
1654 return($this->DetailMode);
1668 <script language="JavaScript1.2" type="text/javascript">
1684 var ns4 = document.layers;
1685 var ns6 = document.getElementById && !document.all;
1686 var ie4 = document.all;
1689 var YapToolTipSTYLE="";
1690 function initYapToolTips()
1694 if(ns4) YapToolTipSTYLE = document.YapToolTipLayer;
1695 else if(ns6) YapToolTipSTYLE = document.getElementById("YapToolTipLayer").style;
1696 else if(ie4) YapToolTipSTYLE = document.all.YapToolTipLayer.style;
1697 if(ns4) document.captureEvents(Event.MOUSEMOVE);
1700 YapToolTipSTYLE.visibility = "visible";
1701 YapToolTipSTYLE.display = "none";
1703 document.onmousemove = YapMoveToMouseLoc;
1707 * Show/Hide the tooltip.
1708 * msg: tooltip text,
1709 * fg: foreground color
1710 * bg: background color
1711 * Call the function without parameters to hide the tooltip
1713 function YapToolTip(msg, fg, bg)
1715 if(YapToolTip.arguments.length < 1) // hide
1717 if(ns4) YapToolTipSTYLE.visibility = "hidden";
1718 else YapToolTipSTYLE.display = "none";
1722 if(!fg) fg = "#777777";
1723 if(!bg) bg = "#FFFFFF";
1725 \'<table border="0" cellspacing="0" cellpadding="1" bgcolor="\' + fg + \'"><td>\' +
1726 \'<table border="0" cellspacing="0" cellpadding="1" bgcolor="\' + bg +
1727 \'"><td align="center"><font face="sans-serif" color="\' + fg +
1728 \'" size="-2"> \;\' + msg +
1729 \' \;</font></td></table></td></table>\';
1732 YapToolTipSTYLE.document.write(content);
1733 YapToolTipSTYLE.document.close();
1734 YapToolTipSTYLE.visibility = "visible";
1738 document.getElementById("YapToolTipLayer").innerHTML = content;
1739 YapToolTipSTYLE.display=\'block\'
1743 document.all("YapToolTipLayer").innerHTML=content;
1744 YapToolTipSTYLE.display=\'block\'
1748 function YapMoveToMouseLoc(e)
1757 x = event.x + document.body.scrollLeft;
1758 y = event.y + document.body.scrollTop;
1760 YapToolTipSTYLE.left = x + offsetX;
1761 YapToolTipSTYLE.top = y + offsetY;
1777 <div id="YapToolTipLayer" style="position:absolute; visibility: hidden"></div>
1778 <script language="JavaScript" type="text/javascript">
1798 $numargs = func_num_args();
1800 $Add=func_get_arg(0);
1802 $KeyValue=func_get_arg(1);
1803 if(array_key_exists(
'id',$_REQUEST))
1804 $KeyValue=urldecode($_REQUEST[
'id']);
1806 if(!isset($KeyValue)&&!$Add)
1807 trigger_error(
'ERRROR: request to modify a row, but no key value is specified',E_USER_ERROR);
1836 foreach ($field_controls as $fieldname => $control)
1838 if(array_key_exists($fieldname,$FilledRow))
1839 $field_controls[$fieldname]->SetValue($FilledRow[$fieldname]);
1841 $this->
_ShowModifyBox($FilledRow,$fields,$Add,$KeyValue,$field_controls);
1842 $_SESSION[$this->Prefix.
'KeyToUpdate']=$KeyValue;
1854 if(!array_key_exists($this->Prefix.
'KeyToUpdate',$_SESSION)&&!$Add)
1855 trigger_error(
'ERRROR: request to modify a row, but no key value is specified',E_USER_ERROR);
1867 $KeyValue=$_SESSION[$this->Prefix.
'KeyToUpdate'];
1879 $this->WrongFields=array();
1881 $sql=
'insert into ' . $this->modify_info[
'table'];
1883 $sql=
'update ' . $this->modify_info[
'table'];
1884 foreach ($field_controls as $fieldName => $control)
1887 $field_controls[$fieldName]->ParseResponse();
1888 if(!$field_controls[$fieldName]->IsValid())
1889 $this->WrongFields[$fieldName]=
'*';
1890 if(array_key_exists($fieldName,$row))
1893 $this->WrongFields[$fieldName]=
'*';
1898 $DoUpdate=!count($this->WrongFields);
1902 $sql.=($Add)?$this->Db_Class->DbaddSql($row,$fields,$this->modify_info[
'keyfield']):$this->Db_Class->DbmodifySql($row,$fields);
1905 $apice=$fields[$this->modify_info[
'keyfield']][
'apice'];
1906 $sql.=
' where ' . $this->modify_info[
'keyfield'] .
'= '.$apice.$this->Db_Class->DbEscape($KeyValue).$apice;
1908 if(
DEBUG) $GLOBALS[
'debug']->DumpVar($sql,
'$sql');
1909 if(!$this->Db_Class->DbExecSql($sql))
1910 trigger_error($this->Db_Class->DbError(),E_USER_ERROR);
1911 unset($_SESSION[$this->Prefix.
'KeyToUpdate']);
1922 $msg=
'<p>'.$this->Lang[
'OperationExecuted'].
'!</p>';
1923 $cmdOk=$this->show_info[
'onokhref'].
'?ev=YAP_CMDEXECUTED';
1925 <input type=button value=\''.$this->Lang[
'Continue'].
'\' onclick=
"window.location.href=\''.$cmdOk.'\'">
1927 eval('$msgbox=
new '.$this->show_info['boxclass
'].'($msg);
');
1928 //$msgbox=new CYapBox($msg);
1938 function _BuildControlTable($tblFields)
1941 $array_in=$tblFields;
1942 // print_r($array_in);
1943 foreach($array_in as $FieldName => $field)
1945 if(!$field['autoincrement
'])
1947 if(array_key_exists('classname
',$field))
1948 eval('$OutTable[$FieldName]=
new '.$field['classname
'].';
');
1951 switch($field['type
'])
1955 // Enum/set type, use a select control
1956 if(array_key_exists('classname
',$field))
1957 $class=$field['classname
'];
1960 if(!class_exists($class))
1961 trigger_error('The requested
class '.$class.' doesn\'t exist',E_USER_ERROR);
1962 eval(
'$OutTable[$FieldName]=new '.$class.
';');
1963 $OutTable[$FieldName]->SetChoices($field[
'values']);
1967 if(array_key_exists(
'classname',$field))
1968 $class=$field[
'classname'];
1970 $class=
'CYap_TextBox';
1971 if(!class_exists($class))
1972 trigger_error(
'The requested class '.$class.
' doesn\'t exist',E_USER_ERROR);
1973 eval(
'$OutTable[$FieldName]=new '.$class.
';');
1976 if (is_subclass_of($OutTable[$FieldName],
'CYap_SelectBox'))
1978 if(array_key_exists(
'choices',$field))
1979 $OutTable[$FieldName]->SetChoices($field[
'choices']);
1984 if(array_key_exists(
'default',$field))
1985 $OutTable[$FieldName]->SetValue($field[
'default']);
1986 if(array_key_exists(
'custom',$field))
1987 $OutTable[$FieldName]->CustomParam($field[
'custom']);
1988 $OutTable[$FieldName]->BindField($field);
2005 function _ShowModifyBox($Row,$Fields,$Add,$KeyValue,$Controls)
2007 eval(
'$TheForm=new '.$this->show_info[
'formclass'].
'($Controls,$this->modify_info,$this->show_info[\'languagefile\']);');
2009 $TheForm->MakeForm($Add,$KeyValue,$this->WrongFields,$this->show_info[
'onaborthref']);
2018 function _FillFromRequest($row,$Fields)
2021 $FieldToCheck=$this->modify_info[
'fields'];
2023 if(!count($FieldToCheck))
2024 $FieldToCheck=$Fields;
2025 foreach($FieldToCheck as $Key => $Value)
2028 if(array_key_exists($Key,$_REQUEST))
2029 $OutRow[$Key]=$_REQUEST[$Key];
2041 function _RetrieveRow($KeyValue,$Fields)
2043 if(!$this->DbOpened) $this->_OpenDb();
2044 $apice=$Fields[$this->modify_info[
'keyfield']][
'apice'];
2045 $sql=
'select * from ' .$this->modify_info[
'table'];
2046 $sql.=
' where ' . $this->modify_info[
'keyfield'] .
'= '.$apice.$this->Db_Class->DbEscape($KeyValue).$apice;
2048 if(($result=$this->Db_Class->DbExecSql($sql))===FALSE)
2049 trigger_error($this->Db_Class->DbError(),E_USER_ERROR);
2050 $found=$this->Db_Class->DbGetNumRow($result);
2054 trigger_error(
'ERROR: found many rows having key = '.$KeyValue,E_USER_ERROR);
2057 $row=$this->Db_Class->DbGetValue($result);
2069 function _RetrieveFieldType($res=NULL, $ModifyMode=
true)
2076 if(!$this->DbOpened) $this->_OpenDb();
2077 if(($res=$this->Db_Class->QueryLimit(
'select * FROM '.$this->modify_info[
'table'],0,1))===FALSE)
2078 trigger_error($this->dberror(
'Invalid query:SHOW FIELDS FROM '.$this->modify_info[
'table']),E_USER_ERROR);
2082 $GetModifyInfo=
false;
2083 if(array_key_exists(
'fields',$this->modify_info))
2084 if(count($this->modify_info[
'fields'])>0)
2085 $GetModifyInfo=
true;
2087 while ($i < $this->Db_Class->DbGetNumFields($res))
2089 $meta = $this->Db_Class->DbFetchField($res,$i);
2091 trigger_error(
"No information available",E_USER_ERROR);
2092 $flags = $this->Db_Class->DbFieldFlags($res, $i);
2093 if($meta->type!=
'IGNORE')
2096 $fields[$meta->name]=$this->_CompileFieldType($meta,$flags,array());
2102 $fields[$meta->name]=$this->_CompileFieldType($meta,$flags,array());
2106 if(array_key_exists($meta->name,$this->modify_info[
'fields']))
2107 $fields[$meta->name]=$this->_CompileFieldType($meta,$flags,$this->modify_info[
'fields'][$meta->name]);
2112 if($meta->name==$this->modify_info[
'keyfield'])
2113 $fields[$meta->name]=$this->_CompileFieldType($meta,$flags,array());
2122 $this->Db_Class->DbFreeResult($res);
2135 function _CompileFieldType($meta,$flags,$CfgParam)
2138 $out[
'DbType']=$meta->type;
2139 $out[
'autoincrement']=(preg_match(
'/auto_increment/',$flags))?
true:
false;
2140 $out[
'name']=$meta->name;
2141 $out[
'values']=array();
2143 $out[
'type']=$meta->type;
2144 $out[
'apice']=$this->_Apice($meta->type);
2145 $out[
'size']=$meta->max_length;
2154 if (ereg(
'set.(.*).',$meta->type,$match))
2155 $out[
'values'] = explode(
',',$match[1]);
2159 if (ereg(
'enum.(.*).',$meta->type,$match))
2160 $out[
'values'] = explode(
',',$match[1]);
2199 function _Apice($fieldType)
2202 switch(strtolower($fieldType))
2234 function _DeleteRequestConfirm()
2236 if(!array_key_exists(
'id',$_REQUEST))
2237 trigger_error(
'ERRROR: request to remove a row, but no key value is specified',E_USER_ERROR);
2238 $KeyValue=urldecode($_REQUEST[
'id']);
2240 if(!$this->_CheckAuthorization($KeyValue,
'RemoveRow'))
2242 $this->_DontAllow();
2246 $msg=
'<table border=0 cellpadding=0 cellspacing=0>
2247 <tr><td colspan=2><strong>'.$this->Lang[
'SureToRemove'].
'?</strong></td></tr>
2249 if(!$this->DbOpened) $this->_OpenDb();
2250 $Fields=$this->_RetrieveFieldType();
2251 $row=$this->_RetrieveRow($KeyValue,$Fields);
2254 eval(
'$clsTable=new '.$this->show_info[
'detailviewclass'].
'($this->show_info[\'languagefile\']);');
2256 $clsTable->LoadFormats($this->OutFormats);
2257 $clsTable->BeginTable();
2258 $clsTable->HeaderStart();
2259 $this->show_detail_row($row,
false,$Fields,$clsTable);
2260 $clsTable->EndTable();
2261 $clsTable->FlushCode();
2264 $cmdRemove=$_SERVER[
'PHP_SELF'].
'?ev=YAP_DOREMOVE';
2265 $cmdAbort=$_SERVER[
'PHP_SELF'].
'?ev=YAP_ABORTREMOVE';
2269 <input type=button value=\''.$this->Lang[
'Remove'].
'\' onclick=
"window.location.href=\''.$cmdRemove.'\'">
2270 <input type=button value=\
''.$this->Lang[
'Abort'].
'\' onclick=
"window.location.href=\''.$cmdAbort.'\'">
2274 eval('$msgbox=
new '.$this->show_info['boxclass
'].'($msg);
');
2275 //$msgbox=new CYapBox($msg);
2277 $_SESSION[$this->Prefix.'KeyToRemove
']=$KeyValue;
2285 function _DeleteExecute()
2287 if(!$this->DbOpened) $this->_OpenDb();
2288 if(!array_key_exists($this->Prefix.'KeyToRemove
',$_SESSION))
2289 trigger_error('ERRROR: request to
remove a row, but no key value is specified
',E_USER_ERROR);
2290 $KeyValue=$_SESSION[$this->Prefix.'KeyToRemove
'];
2291 // Am I authorized to perform this job?
2292 if(!$this->_CheckAuthorization($KeyValue,'RemoveRow
'))
2294 $this->_DontAllow();
2297 if(!$this->DbOpened) $this->_OpenDb();
2298 $field=$this->_RetrieveFieldType();
2299 $apice=$field[$this->modify_info['keyfield
']]['apice
'];
2300 $sql='delete from
' .$this->modify_info['table
'] . '
2301 where
' . $this->modify_info['keyfield
'] . '=
'.$apice.$this->Db_Class->DbEscape($KeyValue).$apice;
2302 $this->Db_Class->DbExecSql($sql);
2303 // $this->_ExecuteSql($sql);
2304 $msg='<p>
'.$this->Lang['RowDeleted
'].'!</p>
';
2305 $cmdOk=$this->show_info['onokhref
'].'?ev=YAP_CMDEXECUTED
';
2307 <input type=button value=\
''.$this->Lang[
'Continue'].
'\' onclick=
"window.location.href=\''.$cmdOk.'\'">
2309 eval('$msgbox=
new '.$this->show_info['boxclass
'].'($msg);
');
2310 // $msgbox=new CYapBox($msg);
2312 unset($_SESSION[$this->Prefix.'KeyToRemove
']);
2328 function _CheckAuthorization($Key,$Action)
2333 if(array_key_exists('deleteallow
',$this->modify_info))
2334 $ret=call_user_func($this->modify_info['deleteallow
'],$Key);
2337 // Stop it if I don't show the link
2339 $ret=$this->modify_info[
'showdelete'];
2342 if(array_key_exists(
'addallow',$this->modify_info))
2343 $ret=call_user_func($this->modify_info[
'addallow']);
2348 $ret=$this->modify_info[
'showadd'];
2351 if(array_key_exists(
'modifyallow',$this->modify_info))
2352 $ret=call_user_func($this->modify_info[
'modifyallow'],$Key);
2357 $ret=$this->modify_info[
'showmodify'];
2360 trigger_error(
'Internal Error:_CheckAuthorization, unespected action',E_USER_ERROR);
2371 function _DontAllow()
2373 $text=
'<p>'.$this->Lang[
'AccessDenied'].
'.</p>';
2374 eval(
'$box=new '.$this->show_info[
'boxclass'].
'($text);');
2388 function _CheckFieldCallBack($row,$Key)
2390 if(!array_key_exists($Key,$this->modify_info[
'fields']))
2392 if(array_key_exists(
'fieldvalidator',$this->modify_info[
'fields'][$Key]))
2393 $ret=call_user_func($this->modify_info[
'fields'][$Key][
'fieldvalidator'],$row,$Key);
2408 if(!$this->Db_Class->OpenDb($this->db_info[
"servername"],$this->db_info[
"user"],$this->db_info[
"password"]))
2409 trigger_error($this->Db_Class->DbError(),E_USER_ERROR);
2410 if(!$this->Db_Class->SelectDb($this->db_info[
"dbname"]))
2411 trigger_error($this->Db_Class->DbError(),E_USER_ERROR);
2412 $this->DbOpened=
true;
2431 if( strtolower($sExpectedParentClass) === strtolower($sClass) )
return true;
2432 while(
false != ($sClass = get_parent_class($sClass)) );