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