| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: |
|
| 7: |
|
| 8: |
|
| 9: |
|
| 10: | class DateField2 extends Sphp\tools\Component{
|
| 11: | public $datemin = '';
|
| 12: | public $datemax = '';
|
| 13: | private $appendText = 'dd-mm-yy';
|
| 14: | private $image = "";
|
| 15: | private $nomonth = "";
|
| 16: | private $formName = '';
|
| 17: | private $msgName = '';
|
| 18: | private $req = false;
|
| 19: |
|
| 20: | protected function oncreate($element) {
|
| 21: | if(!$this->element->hasAttribute("name")){
|
| 22: | $this->HTMLName = $this->name;
|
| 23: | }else{
|
| 24: | $this->HTMLName = $this->getAttribute("name");
|
| 25: | }
|
| 26: |
|
| 27: | if($this->value!=''){
|
| 28: | $this->value = $this->dateToMySQLDate($this->value) ;
|
| 29: | }
|
| 30: | $this->unsetEndTag();
|
| 31: | }
|
| 32: |
|
| 33: | public function fu_setForm($val) { $this->formName = $val;}
|
| 34: | public function fu_setMsgName($val) { $this->msgName = $val;}
|
| 35: | public function fu_setRequired() {
|
| 36: | if($this->issubmit){
|
| 37: | if(strlen($this->value) < 1){
|
| 38: | setErr($this->name,"Can not submit Empty");
|
| 39: | }
|
| 40: | }
|
| 41: | $this->req = true;
|
| 42: | }
|
| 43: | private function dateToMySQLDate($date){
|
| 44: | $date1 = $this->createDate($this->appendText, $date, 'Y-m-d', 0, 0, 0);
|
| 45: | return $date1;
|
| 46: | }
|
| 47: | public function createDate($dformat, $beginDate, $outformat, $offsetd, $offsetm, $offsety)
|
| 48: | {
|
| 49: |
|
| 50: | $dsep = ' ';
|
| 51: | if(strpos($dformat, '/')>0){$dsep = '/';}
|
| 52: | if(strpos($dformat, '-')>0){$dsep = '-';}
|
| 53: | $date_parts2 = explode($dsep, $beginDate);
|
| 54: | $date_parts3 = explode($dsep, $dformat);
|
| 55: | if($date_parts3[0]=='mm' && $date_parts3[1]=='dd'){
|
| 56: | $date_parts1[0] = $date_parts2[1];
|
| 57: | $date_parts1[1] = $date_parts2[0];
|
| 58: | $date_parts1[2] = $date_parts2[2];
|
| 59: | }
|
| 60: | else if($date_parts3[0]=='mm' && $date_parts3[1]=='yy'){
|
| 61: | $date_parts1[0] = $date_parts2[2];
|
| 62: | $date_parts1[1] = $date_parts2[0];
|
| 63: | $date_parts1[2] = $date_parts2[1];
|
| 64: | }
|
| 65: | else if($date_parts3[0]=='yy' && $date_parts3[1]=='dd'){
|
| 66: | $date_parts1[0] = $date_parts2[1];
|
| 67: | $date_parts1[1] = $date_parts2[2];
|
| 68: | $date_parts1[2] = $date_parts2[0];
|
| 69: | }
|
| 70: | else if($date_parts3[0]=='yy' && $date_parts3[1]=='mm'){
|
| 71: | $date_parts1[0] = $date_parts2[2];
|
| 72: | $date_parts1[1] = $date_parts2[1];
|
| 73: | $date_parts1[2] = $date_parts2[0];
|
| 74: | }
|
| 75: | else if($date_parts3[0]=='dd' && $date_parts3[1]=='yy'){
|
| 76: | $date_parts1[0] = $date_parts2[0];
|
| 77: | $date_parts1[1] = $date_parts2[2];
|
| 78: | $date_parts1[2] = $date_parts2[1];
|
| 79: | }else{
|
| 80: | $date_parts1 = $date_parts2;
|
| 81: | }
|
| 82: |
|
| 83: | $date1 = date($outformat, mktime(0, 0, 0, $date_parts1[1] + $offsetm, $date_parts1[0] + $offsetd, $date_parts1[2] + $offsety));
|
| 84: | return $date1;
|
| 85: | }
|
| 86: |
|
| 87: | public function mysqlDateToDate($df)
|
| 88: | {
|
| 89: | if($df!=''){
|
| 90: | $dformat = $this->appendText;
|
| 91: | $dformat = str_replace('dd', 'd', $dformat);
|
| 92: | $dformat = str_replace('mm', 'm', $dformat);
|
| 93: | $dformat = str_replace('yy', 'Y', $dformat);
|
| 94: |
|
| 95: | $date1 = date($dformat,strtotime($df));
|
| 96: | return $date1;
|
| 97: | }
|
| 98: | }
|
| 99: |
|
| 100: | public function fu_setDateMin($val){$this->datemin = $val;}
|
| 101: | public function fu_setDateMax($val){$this->datemax = $val;}
|
| 102: | public function fu_setAppendText($val){$this->appendText=$val;}
|
| 103: | public function fu_setButtonImage($val){$this->image=$val;}
|
| 104: | public function fu_setNumMonths($val){$this->nomonth=$val;}
|
| 105: |
|
| 106: | protected function onjsrender(){
|
| 107: | global $libpath;
|
| 108: | global $respath;
|
| 109: | global $jquerypath;
|
| 110: | |
| 111: | |
| 112: | |
| 113: | |
| 114: | |
| 115: | |
| 116: |
|
| 117: | $str = '';
|
| 118: | if($this->appendText!=''){$str .= ",appendText: '$this->appendText', dateFormat: '$this->appendText'";}
|
| 119: | if($this->image==''){$this->image= "$respath/controls/sphp/res/calendar.gif";}
|
| 120: | if($this->image!=''){$str .= ",showOn: 'button',buttonImageOnly: true, buttonImage: '$this->image'";}
|
| 121: | if($this->datemax!=''){$str .= ",maxDate: '$this->datemax'";}
|
| 122: | if($this->datemin!=''){$str .= ",minDate: '$this->datemin'";}
|
| 123: | if($this->nomonth!=''){$str .= ",numberOfMonths: $this->nomonth";}
|
| 124: | $this->setParameterA('class', $this->parameterA['class']." hasDatePicker2");
|
| 125: | addHeaderJSFunctionCode('ready', "datepicker", "
|
| 126: | $('.hasDatePicker2').datepicker({ changeMonth: true,changeYear: true $str});
|
| 127: | ");
|
| 128: | if($this->formName!=''){
|
| 129: | if($this->req){
|
| 130: | addFooterJSFunctionCode("{$this->formName}_submit", "{$this->HTMLID}req", "
|
| 131: | ctlReq['$this->HTMLID']= Array('$this->msgName','TextField');");
|
| 132: | }
|
| 133: | }
|
| 134: | }
|
| 135: |
|
| 136: | protected function onrender(){
|
| 137: | if($this->value!=''){
|
| 138: | $this->parameterA['value'] = $this->mysqlDateToDate($this->value);
|
| 139: | }
|
| 140: | $this->parameterA['type'] = 'text';
|
| 141: | $this->parameterA['readonly'] = ' ';
|
| 142: |
|
| 143: | }
|
| 144: |
|
| 145: |
|
| 146: |
|
| 147: | public function getJSValue(){
|
| 148: | return "document.getElementById('$this->name').value" ;
|
| 149: | }
|
| 150: |
|
| 151: | public function setJSValue($exp){
|
| 152: | global $jsOut;
|
| 153: | $jsOut .= "document.getElementById('$this->name').value = $exp;" ;
|
| 154: | }
|
| 155: |
|
| 156: | }
|
| 157: | |