1: <?php
2: /**
3: * Description of Grid
4: *
5: * @author SARTAJ
6: */
7:
8: include_once(SphpBase::sphp_settings()->slib_path . "/comp/ajax/Ajaxsenddata.php");
9: class Grid extends Control{
10: public $pageNo = -1;
11: public $totalPages = 1;
12: public $perPageRows = 10;
13: public $sql = '';
14: public $pageCountSQL = '';
15: public $result;
16: public $row;
17: public $linkno = 10;
18: public $extraData = '';
19: public $strFormat = '';
20: public $fieldNames = '';
21: public $headNames = '';
22: public $colwidths = '';
23: public $where = '';
24: public $ordersortby = '';
25: public $whereDef = '';
26: public $app = '';
27: public $blnEdit = false;
28: public $blnDelete = false;
29: public $cacheTime = 0;
30: public $eventName = 'show';
31: public $editeventName = 'view';
32: public $deleventName = 'delete';
33: private $evtp='';
34: private $ctrl='';
35: private $extra='page=';
36: private $baseName='';
37: private $sesID=false;
38: private $blnajax = false;
39: private $blndlg = true;
40: private $blnadd = true;
41: private $ajax = null;
42: private $cachefile = '';
43: private $cachekey = 'id';
44: private $cachesave = false;
45: private $header = '';
46: private $footer = '';
47: public $buttonnext = '';
48: public $buttonprev = '';
49: public $links = '';
50: private $sortby = false;
51: private $blnpagebar = true;
52: private $handleeventapp = false;
53: public $content_section = null;
54:
55:
56: public function oncreate($element) {
57: if(\SphpBase::page()->isSesSecure){
58: $this->sesID = true;
59: }
60: if(\SphpBase::sphp_request()->isRequest('page')){
61: \SphpBase::sphp_request()->session($this->name.'p',\SphpBase::sphp_request()->request('page'));
62: \SphpBase::sphp_request()->session($this->name.'pc', \SphpBase::sphp_router()->ctrl);
63: }else{
64: \SphpBase::sphp_request()->request('page',false, 1);
65: if(isset($_SESSION[$this->name.'pc']) && $_SESSION[$this->name.'pc'] == \SphpBase::sphp_router()->ctrl){
66: \SphpBase::sphp_request()->request('page',false,$_SESSION[$this->name.'p']);
67: }
68: }
69: $this->pageNo = \SphpBase::sphp_request()->request('page') - 1;
70:
71: if($this->dtable == ''){
72: $parentapp = $this->tempobj->getBindApp();
73: if($parentapp !== null){
74: $this->dtable = $parentapp->getTableName();
75: }
76: }
77: $this->setHTMLName('');
78: if($element->innertext != ""){
79: $this->strFormat = "datajfjfh";
80: }
81:
82: }
83:
84: public function getEventURL($eventName, $evtp='', $ControllerName='', $extra='', $newBasePath='', $blnSesID=false){
85: $this->eventName = $eventName;
86: $this->evtp=$evtp;
87: $this->ctrl=$ControllerName;
88: if($extra!=''){
89: $this->extra=$extra.'&page=';
90: }
91: $this->baseName=$newBasePath;
92: $this->sesID=$blnSesID;
93: }
94:
95: public function setMsgName($val) { $this->msgName = $val;}
96: public function setSQL($sql){
97: $this->sql = $sql;
98: }
99: public function setPageCountSQL($sql){
100: $this->pageCountSQL = $sql;
101: }
102: public function setPerPageRows($val){
103: $this->perPageRows = intval($val);
104: }
105: public function setExtraData($val){
106: $this->extraData = $val;
107: }
108: public function setPageNo($val){
109: $this->pageNo = $val - 1;
110: \SphpBase::sphp_request()->session($this->name.'p',$val);
111: \SphpBase::sphp_request()->session($this->name.'pc', \SphpBase::sphp_router()->ctrl);
112: \SphpBase::sphp_request()->request('page',false, $val);
113: }
114: public function getPageNo(){
115: return $this->pageNo + 1;
116: }
117: public function setLinkNo($val){
118: $this->linkno = $val;
119: }
120: public function setCacheFile($val){
121: $this->cachefile = $val;
122: }
123: public function setCacheSave(){
124: $this->cachesave = true;
125: }
126: public function setCacheKey($val){
127: $this->cachekey = $val;
128: }
129: public function setCacheTime($val){
130: $this->cacheTime = intval($val);
131: }
132: public function setFieldNames($val){
133: $this->fieldNames = $val;
134: }
135: public function setHeaderNames($val){
136: $this->headNames = $val;
137: }
138: public function setColWidths($val){
139: $this->colwidths = $val;
140: }
141: public function setWhere($val){
142: $this->where = $val;
143: }
144: public function setWhereDef($val){
145: $this->whereDef = $val;
146: }
147: public function setApp($val){
148: $this->app = $val;
149: }
150: public function setSortBy() {
151: $this->sortby = true;
152: }
153: public function setAjax(){
154: $this->blnajax = true;
155: $this->ajax = new \Sphp\comp\ajax\Ajaxsenddata($this->name."ajax1");
156: $this->ajax->oncompcreate(array());
157: $this->eventName = $this->name ."_show";
158: $this->editeventName = $this->name ."_view";
159: $this->deleventName = $this->name ."_delete";
160: SphpJsM::addjQueryUI();
161: }
162: public function setEdit(){
163: $this->blnEdit = true;
164: }
165: public function setDelete(){
166: $this->blnDelete = true;
167: }
168: public function getPageBar(){
169: return $this->links;
170: }
171: public function getButtonNext(){
172: return $this->buttonnext;
173: }
174: public function getButtonPrev(){
175: return $this->buttonprev;
176: }
177: public function setHeader($val){
178: $this->header = $val;
179: }
180: public function setFooter($val){
181: $this->footer = $val;
182: }
183: public function unsetDialog(){
184: $this->blndlg = false;
185: }
186: public function unsetAddButton(){
187: $this->blnadd = false;
188: }
189: public function unsetPageBar(){
190: $this->blnpagebar = false;
191: }
192: public function setHandleEvent(){
193: $this->handleeventapp = true;
194: }
195:
196: public function executeSQL(){
197: $mysql = \SphpBase::dbEngine();
198: $libpath = \SphpBase::sphp_settings()->lib_path;
199: $stro = "";
200: // count total page
201: $mysql->connect();
202: if($this->cachefile!=''){
203: $res = $mysql->fetchQuery($this->pageCountSQL,$this->cacheTime,$this->cachefile.'csql');
204: }else{
205: $res = $mysql->fetchQuery($this->pageCountSQL,$this->cacheTime);
206: }
207: if ($res){
208: $row = current($res['news']);
209: //$totalRows = intval($row['count(id)']);
210: $totalRows = intval(current($row));
211: $this->totalPages = intval(($totalRows + $this->perPageRows - 1) / $this->perPageRows);
212: if($this->pageNo < 0){
213: $this->pageNo = 0;
214: }
215: else if($this->pageNo + 1 > $this->totalPages){
216: $this->pageNo = $this->totalPages - 1 ;
217: }
218:
219: $startat = $this->pageNo * $this->perPageRows;
220: if($startat<0){$startat=0;}
221: $this->result = $mysql->fetchQuery($this->sql." LIMIT $startat,$this->perPageRows",$this->cacheTime,$this->cachefile,$this->cachekey,$this->cachesave);
222: //$mysql->disconnect();
223: $stro = '';
224: if ($this->result){
225: if($this->fieldNames!='' && $this->strFormat=='' && $this->content_section==null){
226: $stro = '<table class="pagtable">';
227: if($this->headNames==''){
228: $this->headNames = $this->fieldNames;
229: }
230: $arr = explode(',',$this->headNames);
231: $fieldcount = count($arr);
232: $lenw = -1;
233: $startw = 0;
234: $w = '';
235: if($this->colwidths!=''){
236: $arrw = explode(',',$this->colwidths);
237: $lenw = count($arrw)-1;
238: $startw = 0;
239: }
240: $stro .= "<tr class=\"paghead\">";
241: foreach($arr as $key=>$val){
242: if($lenw>=$startw){
243: $w = ' width="'.$arrw[$startw].'"';
244: $startw += 1;
245: }else{
246: $w = '';
247: }
248: $stro .= "<th$w>$val</th>";
249: }
250: if($this->blnEdit){
251: $stro .= "<th width=\"10\">Edit</th>";
252: }
253: if($this->blnDelete){
254: $stro .= "<th width=\"10\">Delete</th>";
255: }
256: $stro .= "</tr>";
257: $blnf = true;
258: foreach($this->result as $key1=>$keyar){
259: foreach($keyar as $key=>$row){
260: $arr = explode(',',$this->fieldNames);
261: if($blnf){
262: $stro .= "<tr class=\"pagrow1\">";
263: $blnf = false;
264: }else{
265: $stro .= "<tr class=\"pagrow2\">";
266: $blnf = true;
267: }
268: $startw = 0;
269: for($C=0; $C < $fieldcount; $C++){
270: $val =$arr[$C];
271: if($lenw>=$startw){
272: $w = ' style="width: '.$arrw[$startw].';"';
273: $startw += 1;
274: }else{
275: $w = '';
276: }
277: $stro .= "<td$w>".$row[$val]."</td>";
278: }
279: if($this->blnEdit){
280: $stro .= "<td width=\"25\"><a href=\"#\" onclick=\"pagiedit_$this->name('". getEventURL($this->editeventName,$row['id'],$this->app,$this->extraData,'',true)."');\" title=\"Click to Edit This Record\"><img src=\"{$this->myrespath}/res/editBTN.gif\" border=\"0\" /></a></td>";
281: }
282: if($this->blnDelete){
283: $stro .= "<td width=\"25\"><a href=\"#\" onClick=\"confirmDel_$this->name('".getEventURL($this->deleventName,$row['id'],$this->app,$this->extraData,'',true)."')\" title=\"Click to Delete This Record\"><img src=\"{$this->myrespath}/res/del.jpg\" border=\"0\" /></a></td>";
284: }
285:
286: $stro .= "</tr>";
287: }
288: }
289: $stro .= "</table>";
290: if($this->blnpagebar){
291: $stro .= $this->getPaging();
292: }
293: }else if($this->strFormat!=''){
294: $stro = "";
295: $roote = $this->tempobj->getChildrenWrapper($this);
296: foreach($this->result as $key1=>$keyar){
297: foreach($keyar as $index=>$this->row){
298: //$tmpf = new TempFile($this->strFormat,true,false,$this->tempobj->parentapp);
299: //$tmpf->run();
300: //$stro .= $tmpf->data;
301: $stro .= $this->tempobj->parseComponentChildren($roote);
302: }
303: }
304: //$this->unsetrenderTag();
305: if($this->blnpagebar){
306: $strom = $this->getPaging();
307: }
308: }
309:
310: }
311: }
312: return $stro;
313:
314: }
315:
316: private function getPaging(){
317: $lynx = "";
318: $del = "";
319: $linkNo = $this->linkno;
320: $startPage = $this->getPageNo()- $linkNo;
321: $endPage = $this->getPageNo()+$linkNo;
322: if($startPage<1){
323: $startPage = 1;
324: }
325: if($endPage>$this->totalPages){
326: $endPage = $this->totalPages;
327: }
328: //$strstart = "<div class=\"pfloat-left\">";
329: $strstart = "";
330: $pg = $this->pageNo + 1;
331: for ($k=$startPage; $k<=$endPage; $k++) {
332: if ($k != $pg) {
333: if($this->blnajax){
334: $lynx .= $strstart. "<a href=\"#\" onclick=\"getURL('". getEventURL($this->eventName,$this->evtp,$this->ctrl,$this->extra.$k,$this->baseName,$this->sesID)
335: ."'); return false;\"><div class=\"pfloat-left\">".($k)."</div></a>";
336: }else{
337: $lynx .= $strstart."<a href=\"". getEventURL($this->eventName,$this->evtp,$this->ctrl,$this->extra.$k,$this->baseName,$this->sesID)."\"><div class=\"pfloat-left\">".($k)."</div></a>";
338: }
339: } else {
340: $lynx .= $strstart . "<div class=\"pfloat-left-down\">".($k)."</div>";
341: }
342: }
343: $startPage2 = $this->getPageNo();
344: $blnEndP = false;
345: $blnStartP = false;
346: if($startPage2>1){
347: $prev = $startPage2 - 1;
348: }else{
349: $prev = 1;
350: $blnStartP = true;
351: }
352: if($startPage2 >= $this->totalPages){
353: $next = $this->totalPages;
354: $blnEndP = true;
355: }else{
356: $next = $startPage2 + 1;
357: }
358: $edt = '';
359: /* use for multi delete functions
360: if($this->blnEdit){
361: $edt = "&nbsp;&nbsp;<a class=\"pagedit\" href=\"". $this->linkURL. "?page=" . $next ."\">Edit</a>";
362: }
363: if($this->blnDelete){
364: $del = "&nbsp;&nbsp;<a class=\"pagdelete\" href=\"". $this->linkURL. "?page=" . $next ."\">Delete</a>";
365: }
366: *
367: */
368: if($blnStartP){
369: $strlinkP = "";
370: }else{
371: if($this->blnajax){
372: $strlinkP = "<a class=\"pagprev\" href=\"#\" onclick=\"getURL('". getEventURL($this->eventName,$this->evtp,$this->ctrl,$this->extra.$prev,$this->baseName,$this->sesID)."');return false;\">Prev</a>&nbsp;&nbsp;";
373: }else{
374: $strlinkP = "<a class=\"pagprev\" href=\"". getEventURL($this->eventName,$this->evtp,$this->ctrl,$this->extra.$prev,$this->baseName,$this->sesID)."\">Prev</a>&nbsp;&nbsp;";
375: }
376: }
377: if($blnEndP){
378: $strlinkN = "";
379: }else{
380: if($this->blnajax){
381: $strlinkN = "<a class=\"pagnext\" href=\"#\" onclick=\"getURL('".getEventURL($this->eventName,$this->evtp,$this->ctrl,$this->extra.$next,$this->baseName,$this->sesID)."');return false;\">Next</a>";
382: }else{
383: $strlinkN = "<a class=\"pagnext\" href=\"".getEventURL($this->eventName,$this->evtp,$this->ctrl,$this->extra.$next,$this->baseName,$this->sesID)."\">Next</a>";
384: }
385: }
386:
387: if($blnStartP && $blnEndP){
388: $strout = '';
389: }else{
390: $strlink = $strlinkP . $strlinkN ;
391: $this->buttonnext = $strlinkN;
392: $this->buttonprev = $strlinkP;
393: $this->links = $lynx;
394: if($strlink!=''){
395: $strout = '<div class="pagbar"><div class="pagnums">&nbsp; '.$lynx.'</div>
396: <div class="pagprevnext">'.
397: $strlink .$edt.$del.'
398: </div></div>
399: <div style="clear:both"></div>';
400: }
401: }
402: return $strout;
403: }
404:
405: public function onaftercreate(){
406: if(!$this->handleeventapp){
407: $this->handleEvent();
408: }
409: }
410: protected function genhelpPropList() {
411: $this->addHelpPropFunList('getEventURL','Set Event Path to get page', getEventURL($this->eventName, $this->evtp, $this->ctrl, $this->extra, $this->baseName, $this->sesID),'$eventName, $evtp="", $ControllerName="", $extra="", $newBasePath="", $blnSesID=false');
412: $this->addHelpPropFunList('setMsgName','Name Display in placeholder and Error','','$val');
413: $this->addHelpPropFunList('setSQL','Set SQL Database Query','','$sql');
414: $this->addHelpPropFunList('setPageCountSQL','Set SQL Query for Count Page, only need to set if you use setSQL','','$sql');
415: $this->addHelpPropFunList('setPerPageRows','Set Per Page Rows Display','','$val');
416: $this->addHelpPropFunList('setExtraData','Set Extra query string to post server with every page request','','$sql');
417: $this->addHelpPropFunList('setCacheKey','Set Key for Cache default is id','','$val');
418: $this->addHelpPropFunList('setCacheTime','Set Cache Expiry Time 0 mean no cache and -1 mean always data from cache','','$val');
419: $this->addHelpPropFunList('setFieldNames','comma separated list for Database Table field name for auto sql, no need to setSQL','','$val');
420: $this->addHelpPropFunList('setHeaderNames','comma separated list which is use to generate html table tag head section, match with filed list','','$val');
421: $this->addHelpPropFunList('setColWidths','Set col width comma list for td tags','','$list');
422: $this->addHelpPropFunList('setWhere','SQL Query logic like WHERE','','$val');
423: $this->addHelpPropFunList('setApp','Bind with app controller','','$val');
424: $this->addHelpPropFunList('setAjax','Enable AJAX','','');
425: $this->addHelpPropFunList('setEdit','Enable Edit Button','','');
426: $this->addHelpPropFunList('setDelete','Enable Delete Button','','');
427: $this->addHelpPropFunList('setHeader','Set Header HTML','','$val');
428: $this->addHelpPropFunList('setFooter','Set Footer HTML','','$val');
429: $this->addHelpPropFunList('unsetDialog','Disable Dialog','','');
430: //$this->addHelpPropFunList('unsetAddButton','Disable Add Record Button','','$val');
431: $this->addHelpPropList('dtable','comma list for database tables to query');
432: }
433:
434: public function handleEvent(){
435: if(\SphpBase::page()->getEvent()== $this->name . "_sortby"){
436: $this->unsetRenderTag();
437: if(\SphpBase::sphp_request()->request('dir')=='1'){
438: $this->ordersortby = "ORDER BY ". \SphpBase::sphp_request()->request('sortby'). " DESC";
439: }else{
440: $this->ordersortby = "ORDER BY ". \SphpBase::sphp_request()->request('sortby') . " ASC";
441: }
442: \SphpBase::JSServer()->addJSONComp($this, $this->name);
443: }
444: }
445:
446: public function startAJAX(){
447: $opendlg = "";
448: if($this->blndlg){
449: addHeaderJSFunctionCode('ready',$this->name,'
450: $("#'.$this->name.'_dlg").dialog({
451: autoOpen: false,
452: width: "auto",
453: height: "700",
454: show2: {
455: effect: "blind",
456: duration: 300
457: },
458: hide2: {
459: effect: "explode",
460: duration: 300
461: },
462: position: [10,10],
463: title: "Grid Editor Form",
464: create: function(event, ui) {
465: var widget = $(this).dialog("widget");
466: $(".ui-dialog-titlebar-close", widget)
467: .html(\'<span class="ui-button-icon ui-icon ui-icon-closethick"></span><span class="ui-button-icon-space"> </span>\')
468: .addClass("ui-button ui-corner-all ui-widget ui-button-icon-only ui-dialog-titlebar-close");
469: },
470: closeText: "",
471: modal: false,
472: beforeClose: function(){
473: $("#'.$this->name.'_editor").html("");
474: }
475: });
476: ');
477: addHeaderCSS('dragdrop', '
478: .dragdrop
479: {
480: position: relative;
481: cursor: auto;
482: }
483: ');
484: $opendlg = "$(\"#{$this->name}_dlg\").dialog(\"open\");";
485: }
486:
487: if($this->blnajax){
488: $jsAjax = "true";
489: }else{
490: $jsAjax = "false";
491: }
492: addHeaderJSCode($this->name,"
493: function confirmDel_$this->name(link){
494: confirmDel(link,$jsAjax);
495: }
496: var {$this->name}_setg = {
497: sortby: '',
498: dir: 1
499: };
500: function getSortBy(obj,field,link){
501: data = {};
502: var setg = {$this->name}_setg ;
503: var span1 = $(obj).children('span:first');
504: if(setg.sortby!=field){
505: setg.sortby = field;
506: setg.dir = 1;
507: $('.fa-upload').addClass('fa-download');
508: $('.fa-upload').removeClass('fa-upload');
509: span1.removeClass('fa-download');
510: span1.addClass('fa-upload');
511: }else if(setg.sortby==field){
512: if(setg.dir == 1){
513: setg.dir = 0;
514: $('.fa-upload').addClass('fa-download');
515: $('.fa-upload').removeClass('fa-upload');
516: }else{
517: setg.dir = 1;
518: $('.fa-upload').addClass('fa-download');
519: $('.fa-upload').removeClass('fa-upload');
520: span1.removeClass('fa-download');
521: span1.addClass('fa-upload');
522: }
523: }
524: data['sortby'] = field;
525: data['dir'] = setg.dir;
526: {$this->name}_setg = setg;
527:
528: getURL(link,data);
529: return false;
530: }
531: function rowclick(obj,link,data){
532: if(data==undefined){
533: data = {};
534: }
535: $('table').find('tr.highlight').removeClass('highlight');
536: $(obj).addClass('highlight');
537: getURL(link,data);
538: }
539: function setFormAsNew(formid){
540: readyFormAsNew(formid);
541: $('table').find('tr.highlight').removeClass('highlight');
542: $('#btnDel').css('display','none');
543: }
544: function readyFormAsNew(formid){
545: $('#' + formid).find('input[name=\"txtid\"]').val('');
546: $(':input','#' + formid)
547: .not(':button, :submit, :reset, :hidden')
548: .val('').attr('value','')
549: .removeAttr('checked')
550: .removeAttr('selected');
551: $('select', '#' + formid).each(function(i,e){selectByValue(e,\"empt\")});
552: $('textarea', '#' + formid).each(function(i,e) { $(e).val(''); $(e).html(''); });
553: }
554: function runanierr(type){
555: $(\"#sphp\" + type).fadeIn(1);
556: $(\"#sphp\" + type).css(\"display\",\"block\");
557: $(\"#sphp\" + type).delay(5000).fadeOut(\"slow\", function () { $(this).css(\"display\",\"none\"); });
558: }
559: function pagiedit_$this->name(link){
560: $opendlg
561: pagiedit(link,$jsAjax);
562: }
563: function paginew_$this->name(link){
564: $opendlg
565: pagiedit(link,$jsAjax);
566: }
567: ");
568: addHeaderJSCode('pagi',"
569: function confirmDel(link,jsajax){
570: var ans = confirm('Are You Sure to Delete This Record !') ;
571: if(ans){
572: if(jsajax){
573: getURL(link);
574: }else{
575: window.location = link ;
576: }
577: }
578: }
579: function pagiedit(link,jsajax) {
580: if(jsajax){
581: getURL(link);
582: }else{
583: window.location = link ;
584: }
585: return false;
586: }
587: function paginew(link,jsajax){
588: if(jsajax){
589: getURL(link);
590: }else{
591: window.location = link ;
592: }
593: }
594: ");
595:
596: if($this->blnadd){
597: $ptag = '<div id="'.$this->name.'_dlg" class="dragdrop">
598: <div id="'.$this->name.'_editor" style="width:100%;height:100%;" ></div>
599: </div><div id="'.$this->name.'_toolbar">';
600: }else{
601: $ptag = '<div id="'.$this->name.'_toolbar">';
602: }
603: if($this->blnadd){
604: $ptag .= '<input class="btn btn-primary" type="button" value="Add" onclick="paginew_'.$this->name.'(\''.getEventURL($this->name.'_newa','','','','',true).'\');" />';
605: }
606: $msg1 = '<div style="position: fixed; z-index: 2000;width: 500px;">
607: <div id="sphpwarning" class="alert alert-warning" style="display: none;">
608: <a href="#" class="close" data-dismiss="alert">&times;</a>
609: <strong>Warning!</strong> <span id="sphpwarningmsg"></span>
610: </div>
611: <div id="sphperror" class="alert alert-danger" style="display: none;">
612: <a href="#" class="close" data-dismiss="alert">&times;</a>
613: <strong>Error!</strong> <span id="sphperrormsg"></span>
614: </div>
615: <div id="sphpsuccess" class="alert alert-success" style="display: none;">
616: <a href="#" class="close" data-dismiss="alert">&times;</a>
617: <strong>Success!</strong> <span id="sphpsuccessmsg"></span>
618: </div>
619: <div id="sphpinfo" class="alert alert-info" style="display: none;">
620: <a href="#" class="close" data-dismiss="alert">&times;</a>
621: <strong>Note!</strong> <span id="sphpinfomsg"></span>
622: </div>
623: </div><div id="srvmsg"></div>';
624: $divt = "$ptag</div>". $msg1 ."<div id=\"{$this->name}_list\">";
625: $this->setPreTag($divt.$this->getPreTag());
626: $this->setPostTag('</div>'.$this->getPostTag());
627:
628: }
629:
630:
631: public function onjsrender(){
632: $opendlg = "";
633: if(!\SphpBase::JSServer()->ajaxrender){
634: addHeaderCSS("gridhighlight", " .highlight{
635: font-size: 16px;
636: color: #000000;
637: font-weight: bold;
638: background-color: #DEECFA
639: }
640: ");
641: if($this->blnajax){
642: $this->eventName = $this->name."_show";
643: $this->editeventName = $this->name."_view";
644: $this->deleventName = $this->name."_delete";
645: $this->startAJAX();
646: }else{
647: $jsAjax = "false";
648: addHeaderJSCode($this->name,"
649: function confirmDel_$this->name(link){
650: confirmDel(link,$jsAjax);
651: }
652: var {$this->name}_setg = {
653: sortby: '',
654: dir: 1
655: };
656: function getSortBy(obj,field,link){
657: data = {};
658: var setg = {$this->name}_setg ;
659: var span1 = $(obj).children('span:first');
660: if(setg.sortby!=field){
661: setg.sortby = field;
662: setg.dir = 1;
663: $('.fa-upload').addClass('fa-download');
664: $('.fa-upload').removeClass('fa-upload');
665: span1.removeClass('fa-download');
666: span1.addClass('fa-upload');
667: }else if(setg.sortby==field){
668: if(setg.dir == 1){
669: setg.dir = 0;
670: $('.fa-upload').addClass('fa-download');
671: $('.fa-upload').removeClass('fa-upload');
672: }else{
673: setg.dir = 1;
674: $('.fa-upload').addClass('fa-download');
675: $('.fa-upload').removeClass('fa-upload');
676: span1.removeClass('fa-download');
677: span1.addClass('fa-upload');
678: }
679: }
680: data['sortby'] = field;
681: data['dir'] = setg.dir;
682: {$this->name}_setg = setg;
683:
684: getURL(link,data);
685: return false;
686: }
687: function rowclick(obj,link,data){
688: if(data==undefined){
689: data = {};
690: }
691: $('table').find('tr.highlight').removeClass('highlight');
692: $(obj).addClass('highlight');
693: getURL(link,data);
694: }
695:
696: function pagiedit_$this->name(link){
697: $opendlg
698: pagiedit(link,$jsAjax);
699: }
700: function paginew_$this->name(link){
701: $opendlg
702: pagiedit(link,$jsAjax);
703: }
704: ");
705: addHeaderJSCode('pagi',"
706: function confirmDel(link,jsajax){
707: var ans = confirm('Are You Sure to Delete This Record !') ;
708: if(ans){
709: if(jsajax){
710: getURL(link);
711: }else{
712: window.location = link ;
713: }
714: }
715: }
716: function pagiedit(link,jsajax) {
717: if(jsajax){
718: getURL(link);
719: }else{
720: window.location = link ;
721: }
722: return false;
723: }
724: function paginew(link,jsajax){
725: if(jsajax){
726: getURL(link);
727: }else{
728: window.location = link ;
729: }
730: }
731: ");
732: }
733: }
734: }
735:
736: public function onprerender(){
737: $Client = \SphpBase::sphp_request();
738: $ctrl = \SphpBase::sphp_router();
739: // set default values
740: $spt = explode(',', $this->dtable);
741: if(count($spt)>0){
742: $idf = $spt[0].".id";
743: }else{
744: $idf = "id";
745: }
746: $storesql = $Client->session($this->name .'store');
747: if(!is_array($storesql)) $storesql = array();
748: if(isset($storesql['lastapp']) && $storesql['lastapp'] == $ctrl->ctrl){
749: if($this->ordersortby==""){
750: $this->ordersortby = $storesql['sortby'];
751: }
752: if($this->where==""){
753: if($storesql['whereby']!=""){
754: $this->where = $storesql['whereby'];
755: }else{
756: $this->where = $this->whereDef;
757: }
758: }
759: }
760: if(strpos($this->where,"WHERE")===false){
761: $this->where = $this->whereDef;
762: }
763:
764: if($this->pageCountSQL==''){
765: $this->pageCountSQL = "SELECT count($idf) FROM ".$this->dtable." ".$this->where;
766: }
767: if($this->sql==''){
768: $this->sql = "SELECT $idf,$this->fieldNames FROM ".$this->dtable." ".$this->where. " " . $this->ordersortby;
769: }
770: $storesql['lastsql'] = $this->sql;
771: $storesql['lastpagecountsql'] = $this->pageCountSQL;
772: $storesql['lastapp'] = $ctrl->ctrl;
773: $storesql['sortby'] = $this->ordersortby;
774: $storesql['whereby'] = $this->where;
775: $Client->session($this->name .'store',$storesql);
776:
777: $this->parameterA['class'] = 'pag';
778: if($this->content_section===null){
779: $this->setInnerHTML($this->header. $this->executeSQL() . $this->footer);
780: }else{
781: $str = $this->executeSQL();
782: }
783:
784:
785: //$this->innerHTML = $this->header.$this->footer;
786: //$this->unsetrender();
787: }
788:
789:
790: public function onchildevent($event,$obj) {
791: if($event=="oncreate" && $obj->type=='content'){
792: //$this->content_section = $obj;
793:
794: // $this->strFormat = $obj->strFormat;
795: }
796: //echo "event " . $event;
797: }
798: public function onparse($event,$element) {
799: //echo "parse event " . $event;
800: }
801: public function onholder($obj) {
802: $obj->setInnerHTML($this->row[$obj->getAttribute("dfield")]);
803: }
804:
805: }
806:
807: