1: <?php
2:
3: class PermisApp extends \Sphp\tools\BasicApp {
4: /**
5: * $extra array as $extra[table][field] = value format. pass $extra value while
6: * insert,update data to database. this is extra data which is not provided by bound Components.
7: * @var array
8: */
9: public $extra = array();
10: /**
11: * Set Last inserted record "id" value in database when insert operation process.
12: * @var int
13: */
14: protected $insertedid = 0;
15: /**
16: * pass default WHERE login to Pagination Component to Search Records. It will only work when
17: * no other WHERE logic exists.
18: * @var string
19: */
20: protected $defWhere = "";
21: /**
22: * Form Component ID to process Database bound Component for automatic INSERT,UPDATE and VIEW
23: * Database record.
24: * @var string default value is form2
25: */
26: protected $formid = "form2";
27: /**
28: * This Front File provide Edit Form to use Insert and Update records
29: * @var \Sphp\tools\FrontFile
30: */
31: protected $genFormFront = null;
32:
33: /**
34: * This Front File provide List Records with Pagination + search Form
35: * @var \Sphp\tools\FrontFile
36: */
37: protected $showallFront = null;
38:
39:
40: public function page_event_showallShow($param) {
41: $showall = $this->showallFront->getComponent('showall');
42: $showall->fu_unsetRenderTag();
43: $this->JSServer->addJSONComp($showall,'showall');
44: $this->JSServer->addJSONBlock('html','pagebar',$showall->getPageBar());
45: }
46:
47: public function page_event_showall_show($param) {
48: $showall = $this->showallFront->getComponent('showall');
49: $showall->fu_unsetRenderTag();
50: $this->JSServer->addJSONComp($showall, 'showall');
51: $this->JSServer->addJSONBlock('html', 'pagebar', $showall->getPageBar());
52: }
53:
54: public function page_new(){
55: // no any permission check, you can overwrite this behaviour in your app
56: $this->setFrontFile($this->showallFront);
57: }
58:
59: public function hasPermission($p){
60: return $this->page->hasPermission($p);
61: }
62:
63: public function page_event_addnew($param) {
64: if($this->page->hasPermission("add")){
65: $this->genFormFront->addMetaData("pageName", "Add " . $this->genFormFront->getMetaData('pageName'));
66: // set Submit Button Text
67: $this->genFormFront->addMetaData("formButton", "Save");
68: $this->setFrontFile($this->genFormFront);
69: } else {
70: $this->page_new();
71: }
72: }
73:
74:
75: public function page_view() {
76: if($this->page->hasPermission("view") && $this->page->getEventParameter() != ""){
77: $this->genFormFront->addMetaData("pageName", "Edit " . $this->genFormFront->getMetaData('pageName'));
78: // set Submit Button Text
79: $this->genFormFront->addMetaData("formButton", "Update");
80: $form2 = $this->genFormFront->getComponent($this->formid);
81: // fill Components data from database
82: $this->page->viewData($form2);
83: $this->setFrontFile($this->genFormFront);
84: }else{
85: $this->page_new();
86: }
87: }
88:
89: public function page_insert() {
90: global $cmpid;
91: if($this->page->hasPermission("add")){
92: if($this->Client->isSession('sid')) setErr('App','Need to login');
93: $this->extra[]['userid'] = $this->Client->session('sid');
94: $this->extra[]['parentid'] = $this->Client->session('parentid');
95: $this->extra[]['spcmpid'] = $cmpid;
96: $this->extra[]['submit_timestamp'] = time();
97: $this->extra[]['update_timestamp'] = time();
98:
99: //$this->debug->println("Call Insert Event");
100: if (!getCheckErr()) {
101: $form2 = $this->genFormFront->getComponent($this->formid);
102: $this->insertedid = $this->page->insertData($form2,$this->extra);
103: if (!getCheckErr()) {
104: setMsg('App', 'Added Successfully');
105: $this->setFrontFile($this->showallFront);
106: } else {
107: setErr('App', 'Can not add Data');
108: $this->setFrontFile($this->genFormFront);
109: }
110: } else {
111: setErr('App', 'Can not add Data');
112: $this->setFrontFile($this->genFormFront);
113: }
114: } else {
115: $this->page_new();
116: }
117: }
118:
119: public function page_update() {
120: if($this->page->hasPermission("view")){
121: if (!getCheckErr()) {
122: $form2 = $this->genFormFront->getComponent($this->formid);
123: $this->page->updateData($form2,$this->extra);
124: if (!getCheckErr()) {
125: setMsg('App', 'Update Successfully');
126: $this->setFrontFile($this->showallFront);
127: } else {
128: setErr('App', 'Record can not update');
129: $this->setFrontFile($this->genFormFront);
130: }
131: } else {
132: setErr('App', 'Record can not update');
133: $this->setFrontFile($this->genFormFront);
134: }
135: } else {
136: $this->page_new();
137: }
138: }
139:
140: public function page_delete() {
141: if($this->page->hasPermission("delete") && $this->page->getEventParameter() != ""){
142: $this->page->deleteRec();
143: if (!getCheckErr()) {
144: setMsg("App",'delete Successfully');
145: $type = "danger";
146: $showall = $this->showallFront->getComponent('showall');
147: $showall->fu_unsetRenderTag();
148: $this->JSServer->addJSONComp($showall,'showall');
149: $this->JSServer->addJSONBlock('html','pagebar',$showall->getPageBar());
150: $this->JSServer->addJSONJSBlock('setFormStatus("'.$msg.'", "'.$type.'"); readyFormAsNew("form2");');
151: } else {
152: setErr('App', 'Record could not be deleted');
153: $this->setFrontFile($this->showallFront);
154: }
155: } else {
156: $this->page_new();
157: }
158: }
159:
160:
161: public function checkUserName($username) {
162: $check = false;
163: //$result = $this->dbEngine->executeQueryQuick("SELECT * FROM member WHERE username = '$username' ");
164: if($this->dbEngine->isRecordExist("SELECT * FROM member WHERE username = '$username' ")) {
165: $check = true;
166: }
167: return $check;
168: }
169:
170: public function checkUserEmail($email) {
171: $check = false;
172: // $result = $this->dbEngine->executeQueryQuick("SELECT * FROM member WHERE email = '$email' ");
173: if($this->dbEngine->isRecordExist("SELECT * FROM member WHERE email = '$email' ")) {
174: $check = true;
175: }
176: return $check;
177: }
178: }
179:
180: