| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: |
|
| 7: | namespace {
|
| 8: |
|
| 9: | class DTable extends \Sphp\tools\Component{
|
| 10: | private $strFormat = '';
|
| 11: | public $fields = array();
|
| 12: | private $app = '';
|
| 13: | public $RenderComp;
|
| 14: | private $form = '';
|
| 15: | private $blnDontuseFormat = false;
|
| 16: |
|
| 17: |
|
| 18: | protected function oninit() {
|
| 19: | $tblName = \SphpBase::page()->tblName;
|
| 20: | if($tableName==''){
|
| 21: | $this->dtable = $tblName;
|
| 22: | }
|
| 23: | $this->RenderComp = new \Sphp\tools\RenderComp();
|
| 24: | }
|
| 25: |
|
| 26: | public function fu_setMsgName($val) { $this->msgName = $val;}
|
| 27: | public function fu_setApp($val){
|
| 28: | $this->app = $val;
|
| 29: | }
|
| 30: | public function fu_setForm($val){
|
| 31: | $this->form = $val;
|
| 32: | }
|
| 33: |
|
| 34: | public function fu_setField($dfield,$label='',$type='',$req='',$min='',$max=''){
|
| 35: | if($label==''){
|
| 36: | $label = $dfield;
|
| 37: | }
|
| 38: | $this->fields[] = array($label,$dfield,$type,$req,$min,$max);
|
| 39: | }
|
| 40: | public function fu_setDontUseFormat(){
|
| 41: | $this->blnDontuseFormat = true;
|
| 42: | }
|
| 43: |
|
| 44: | public function createComp($id,$path='',$class=''){
|
| 45: | $comp = $this->RenderComp->createComp2($id,$path,$class,$id);
|
| 46: | $comp->setForm($this->form);
|
| 47: | $comp->setFrontobj($this->frontobj);
|
| 48: | $this->frontobj->setComponent($comp->name,$comp);
|
| 49: | \SphpBase::sphp_api()->addComponent($comp->name,$comp);
|
| 50: | return $comp;
|
| 51: | }
|
| 52: |
|
| 53: | public function genComp(){
|
| 54: | $comppath = \SphpBase::sphp_settings()->comp_path;
|
| 55: | $libpath = \SphpBase::sphp_settings()->slib_path;
|
| 56: |
|
| 57: | foreach($this->fields as $key=>$arrn){
|
| 58: | $label = $arrn[0];
|
| 59: | $id = $arrn[1];
|
| 60: | $type = $arrn[2];
|
| 61: | $minlen = $arrn[4];
|
| 62: | $maxlen = $arrn[5];
|
| 63: | $req = $arrn[3];
|
| 64: | switch($type){
|
| 65: | case 'text':{
|
| 66: | $ctrl = $this->createComp($id,"{$libpath}/comp/html/TextField.php","Sphp\\comp\\html\\TextField");
|
| 67: | $ctrl->tagName = "input";
|
| 68: | if($minlen!=""){
|
| 69: | $ctrl->setMinLen($minlen);
|
| 70: | }
|
| 71: | if($maxlen!=""){
|
| 72: | $ctrl->setMaxLen($maxlen);
|
| 73: | }
|
| 74: | if($req=="r"){
|
| 75: | $ctrl->setRequired();
|
| 76: | }
|
| 77: | break;
|
| 78: | }
|
| 79: | case 'hidden':{
|
| 80: | $ctrl = $this->createComp($id,"{$libpath}/comp/html/TextField.php","Sphp\\comp\\html\\TextField");
|
| 81: | $ctrl->tagName = "input";
|
| 82: | $ctrl->unsetVisible();
|
| 83: | break;
|
| 84: | }
|
| 85: | case 'pass':{
|
| 86: | $ctrl = $this->createComp($id,"{$libpath}/comp/html/TextField.php","Sphp\\comp\\html\\TextField");
|
| 87: | $ctrl->tagName = "input";
|
| 88: | $ctrl->setPassword();
|
| 89: | if($minlen!=""){
|
| 90: | $ctrl->setMinLen($minlen);
|
| 91: | }
|
| 92: | if($maxlen!=""){
|
| 93: | $ctrl->setMaxLen($maxlen);
|
| 94: | }
|
| 95: | if($req=="r"){
|
| 96: | $ctrl->setRequired();
|
| 97: | }
|
| 98: | break;
|
| 99: | }
|
| 100: | case 'num':{
|
| 101: | $ctrl = $this->createComp($id,"{$libpath}/comp/html/TextField.php","Sphp\\comp\\html\\TextField");
|
| 102: | $ctrl->tagName = "input";
|
| 103: | $ctrl->setNumeric();
|
| 104: | if($minlen!=""){
|
| 105: | $ctrl->setMinLen($minlen);
|
| 106: | }
|
| 107: | if($maxlen!=""){
|
| 108: | $ctrl->setMaxLen($maxlen);
|
| 109: | }
|
| 110: | if($req=="r"){
|
| 111: | $ctrl->setRequired();
|
| 112: | }
|
| 113: | break;
|
| 114: | }
|
| 115: | case 'numeric':{
|
| 116: | $ctrl = $this->createComp($id,"{$libpath}/comp/html/TextField.php","Sphp\\comp\\html\\TextField");
|
| 117: | $ctrl->tagName = "input";
|
| 118: | $ctrl->setNumeric();
|
| 119: | if($minlen!=""){
|
| 120: | $ctrl->setMinLen($minlen);
|
| 121: | }
|
| 122: | if($maxlen!=""){
|
| 123: | $ctrl->setMaxLen($maxlen);
|
| 124: | }
|
| 125: | if($req=="r"){
|
| 126: | $ctrl->setRequired();
|
| 127: | }
|
| 128: | break;
|
| 129: | }
|
| 130: | case 'email':{
|
| 131: | $ctrl = $this->createComp($id,"{$libpath}/comp/html/TextField.php","Sphp\\comp\\html\\TextField");
|
| 132: | $ctrl->tagName = "input";
|
| 133: | $ctrl->setEmail();
|
| 134: | if($minlen!=""){
|
| 135: | $ctrl->setMinLen($minlen);
|
| 136: | }
|
| 137: | if($maxlen!=""){
|
| 138: | $ctrl->setMaxLen($maxlen);
|
| 139: | }
|
| 140: | if($req=="r"){
|
| 141: | $ctrl->setRequired();
|
| 142: | }
|
| 143: | break;
|
| 144: | }
|
| 145: | case 'textarea':{
|
| 146: | $ctrl = $this->createComp($id,"{$libpath}/comp/html/TextArea.php","Sphp\\comp\\html\\TextArea");
|
| 147: | $ctrl->tagName = "textarea";
|
| 148: | if($minlen!=""){
|
| 149: | $ctrl->setMinLen($minlen);
|
| 150: | }
|
| 151: | if($maxlen!=""){
|
| 152: | $ctrl->setMaxLen($maxlen);
|
| 153: | }
|
| 154: | if($req=="r"){
|
| 155: | $ctrl->setRequired();
|
| 156: | }
|
| 157: | break;
|
| 158: | }
|
| 159: | case 'select':{
|
| 160: | $ctrl = $this->createComp($id,"{$libpath}/comp/html/Select.php","Sphp\\comp\\html\\Select");
|
| 161: | $ctrl->tagName = "select";
|
| 162: | $ctrl->setOptions($req);
|
| 163: | break;
|
| 164: | }
|
| 165: | case 'date':{
|
| 166: | $ctrl = $this->createComp($id,"controls/jquery/DateField2.php");
|
| 167: | $ctrl->tagName = "input";
|
| 168: | if($req=="r"){
|
| 169: | $ctrl->setRequired();
|
| 170: | }
|
| 171: | break;
|
| 172: | }
|
| 173: | case 'file':{
|
| 174: | $ctrl = $this->createComp($id,"{$libpath}/comp/html/FileUploader.php","Sphp\\comp\\html\\FileUploader");
|
| 175: | $ctrl->tagName = "input";
|
| 176: | $ctrl->setParameterA('type', 'file');
|
| 177: | if($minlen!=""){
|
| 178: | $ctrl->setFileMinLen($minlen);
|
| 179: | }
|
| 180: | if($maxlen!=""){
|
| 181: | $ctrl->setFileMaxLen($maxlen);
|
| 182: | }
|
| 183: | if($req=="r"){
|
| 184: | $ctrl->setRequired();
|
| 185: | }
|
| 186: | break;
|
| 187: | }
|
| 188: | default:{
|
| 189: | $ctrl = $this->createComp($id,"$type");
|
| 190: | if($minlen!=""){
|
| 191: | $ctrl->setMinLen($minlen);
|
| 192: | }
|
| 193: | if($maxlen!=""){
|
| 194: | $ctrl->setMaxLen($maxlen);
|
| 195: | }
|
| 196: | if($req=="r"){
|
| 197: | $ctrl->setRequired();
|
| 198: | }
|
| 199: | break;
|
| 200: | }
|
| 201: | }
|
| 202: |
|
| 203: | $ctrl->setMsgName($label);
|
| 204: | }
|
| 205: | }
|
| 206: |
|
| 207: | public function firecompcreate(){
|
| 208: | $idobj = null;
|
| 209: | foreach($this->fields as $key=>$arrn){
|
| 210: | $id = $arrn[1];
|
| 211: | $idobj = readGlobal($id);
|
| 212: | $this->RenderComp->compcreate($idobj);
|
| 213: | }
|
| 214: |
|
| 215: | }
|
| 216: |
|
| 217: | public function genForm(){
|
| 218: |
|
| 219: | $stro = '';
|
| 220: | $idobj = null;
|
| 221: | if($this->strFormat==''){
|
| 222: | $stro = '<table class="table table-striped pagtable">';
|
| 223: | $blnf = true;
|
| 224: | foreach($this->fields as $key=>$arrn){
|
| 225: | $label = $arrn[0];
|
| 226: | $id = $arrn[1];
|
| 227: | $type = $arrn[2];
|
| 228: | $minlen = $arrn[4];
|
| 229: | $maxlen = $arrn[5];
|
| 230: | $req = $arrn[3];
|
| 231: | $idobj = readGlobal($id);
|
| 232: | $idobj->setMsgName($label);
|
| 233: | $field = $this->RenderComp->render($idobj);
|
| 234: |
|
| 235: | if($blnf){
|
| 236: | $stro .= "<tr class=\"pagrow1\">";
|
| 237: | $blnf = false;
|
| 238: | }else{
|
| 239: | $stro .= "<tr class=\"pagrow2\">";
|
| 240: | $blnf = true;
|
| 241: | }
|
| 242: | $stro .= "<td class=\"paglabel\">$label</td><td class=\"pagfield\">$field</td></tr>";
|
| 243: | }
|
| 244: | $stro .= "</table>";
|
| 245: | }
|
| 246: | else{
|
| 247: | $stro = $this->loadScript('<?php
|
| 248: | $idobj = null;
|
| 249: | foreach($this->fields as $key=>$arrn){
|
| 250: | $label = $arrn[0];
|
| 251: | $id = $arrn[1];
|
| 252: | $type = $arrn[2];
|
| 253: | $minlen = $arrn[4];
|
| 254: | $maxlen = $arrn[5];
|
| 255: | $req = $arrn[3];
|
| 256: | $idobj = readGlobal($id);
|
| 257: | $idobj->setMsgName($label);
|
| 258: | $field = $'.$this->name.'->RenderComp->render($idobj);
|
| 259: |
|
| 260: | ?>'.$this->strFormat.'<?php } ?>');
|
| 261: | }
|
| 262: | return $stro;
|
| 263: |
|
| 264: | }
|
| 265: |
|
| 266: | protected function oncreate($element){
|
| 267: | if(!$this->blnDontuseFormat){
|
| 268: | $this->strFormat = $element->innertext;
|
| 269: | }
|
| 270: | $element->innertext = '';
|
| 271: | $str = $this->loadScript($element->getAttribute('oncreate'));
|
| 272: | $element->removeAttribute("oncreate");
|
| 273: | $this->genComp();
|
| 274: | }
|
| 275: |
|
| 276: |
|
| 277: | protected function onjsrender(){
|
| 278: | }
|
| 279: |
|
| 280: | protected function onrender(){
|
| 281: |
|
| 282: |
|
| 283: | $this->innerHTML = $this->genForm();
|
| 284: | $this->unsetrenderTag();
|
| 285: | }
|
| 286: |
|
| 287: |
|
| 288: | public function getJSValue(){
|
| 289: | return "document.getElementById('$this->name').value" ;
|
| 290: | }
|
| 291: |
|
| 292: | public function setJSValue($exp){
|
| 293: | return "document.getElementById('$this->name').value = $exp;" ;
|
| 294: | }
|
| 295: |
|
| 296: |
|
| 297: |
|
| 298: | }
|
| 299: | }
|
| 300: | |