Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
UHtml.php
1 <?php
2 class UHtml extends CHtml
3 {
4  public static function activeTimeField($model,$attribute,$htmlOptions=array())
5  {
6  // SET UP ARRAYS OF OPTIONS FOR DAY, MONTH, YEAR
7  $x = 0;
8 
9  $hourOptions = array('0'=>' - ');
10  while ($x < 24)
11  {
12  $hourOptions[$x] = (($x<10)?'0':'').$x;
13  $x++;
14  }
15 
16  $x = 0;
17  $minuteOptions = array('0'=>' - ');
18  while ($x < 61)
19  {
20  $minuteOptions[$x] = (($x<10)?'0':'').$x;
21  $x++;
22  }
23 
24  $x = 0;
25  $secondOptions = array('0'=>' - ');
26  while ($x < 61)
27  {
28  $secondOptions[$x] = (($x<10)?'0':'').$x;
29  $x++;
30  }
31 
32  $x = 1;
33  $dayOptions = array('0'=>' - ');
34  while ($x < 31)
35  {
36  $dayOptions[$x] = $x;
37  $x++;
38  }
39 
40  $monthOptions = array(
41  '0' => ' - ',
42  '1'=> UserModule::t('January'),
43  '2'=> UserModule::t('February'),
44  '3'=> UserModule::t('March'),
45  '4'=> UserModule::t('April'),
46  '5'=> UserModule::t('May'),
47  '6'=> UserModule::t('June'),
48  '7'=> UserModule::t('July'),
49  '8'=> UserModule::t('August'),
50  '9'=> UserModule::t('September'),
51  '10'=> UserModule::t('October'),
52  '11'=> UserModule::t('November'),
53  '12'=> UserModule::t('December'),
54  );
55 
56  $yearOptions = array('0'=>' - ');
57  $x = 1901;
58  while ($x < 2030)
59  {
60  $yearOptions[$x] = $x;
61  $x++;
62  }
63 
64 
65  parent::resolveNameID($model,$attribute,$htmlOptions);
66 
67  if (is_array($model->$attribute)) {
68  $arr = $model->$attribute;
69  $model->$attribute = mktime($arr['hour'],$arr['minute'],$arr['second'],$arr['month'],$arr['day'],$arr['year']);
70  }
71 
72  if ($model->$attribute != '0' && isset($model->$attribute))
73  {
74  //echo "<pre>"; print_r(date('Y-m-d',$model->$attribute)); die();
75  // intval removes leading zero
76  $day = intval(date('j',$model->$attribute));
77  $month = intval(date('m',$model->$attribute));
78  $year = intval(date('Y',$model->$attribute));
79 
80  $hour = intval(date('H',$model->$attribute));
81  $minute = intval(date('i',$model->$attribute));
82  $second = intval(date('s',$model->$attribute));
83  } else
84  {
85  // DEFAULT TO 0 IF THERE IS NO DATE SET
86  $day = intval(date('j',time()));
87  $month = intval(date('m',time()));
88  $year = intval(date('Y',time()));
89 
90  $hour = intval(date('H',time()));
91  $minute = intval(date('i',time()));
92  $second = intval(date('s',time()));
93  /*
94  $day = 0;
95  $month = 0;
96  $year = 0;
97  $hour = 0;
98  $minute = 0;
99  $second = 0;//*/
100  }
101 
102 
103  $return = parent::dropDownList($htmlOptions['name'].'[day]', $day,$dayOptions);
104  $return .= parent::dropDownList($htmlOptions['name'].'[month]', $month,$monthOptions);
105  $return .= parent::dropDownList($htmlOptions['name'].'[year]', $year,$yearOptions);
106  $return .= ' Time:';
107  $return .= parent::dropDownList($htmlOptions['name'].'[hour]', $hour,$hourOptions);
108  $return .= parent::dropDownList($htmlOptions['name'].'[minute]', $minute,$minuteOptions);
109  $return .= parent::dropDownList($htmlOptions['name'].'[second]', $second,$secondOptions);
110  return $return;
111  }
112 
113  public static function activeDateField($model,$attribute,$htmlOptions=array())
114  {
115  // SET UP ARRAYS OF OPTIONS FOR DAY, MONTH, YEAR
116  $x = 1;
117  $dayOptions = array('00'=>' - ');
118  while ($x < 31)
119  {
120  $dayOptions[(($x<10)?'0':'').$x] = $x;
121  $x++;
122  }
123 
124  $monthOptions = array(
125  '00' => ' - ',
126  '01'=> UserModule::t('January'),
127  '02'=> UserModule::t('February'),
128  '03'=> UserModule::t('March'),
129  '04'=> UserModule::t('April'),
130  '05'=> UserModule::t('May'),
131  '06'=> UserModule::t('June'),
132  '07'=> UserModule::t('July'),
133  '08'=> UserModule::t('August'),
134  '09'=> UserModule::t('September'),
135  '10'=> UserModule::t('October'),
136  '11'=> UserModule::t('November'),
137  '12'=> UserModule::t('December'),
138  );
139 
140  $yearOptions = array('0000'=>' - ');
141  $x = 1901;
142  while ($x < 2030)
143  {
144  $yearOptions[$x] = $x;
145  $x++;
146  }
147 
148 
149  parent::resolveNameID($model,$attribute,$htmlOptions);
150 
151  if ($model->$attribute != '0000-00-00' && isset($model->$attribute))
152  {
153  if (is_array($model->$attribute)) {
154  $new = $model->$attribute;
155 
156  $day = $new['day'];
157  $month = $new['month'];
158  $year = $new['year'];
159 
160  } else {
161  $new = explode('-',$model->$attribute);
162  // intval removes leading zero
163  $day = $new[2];
164  $month = $new[1];
165  $year = $new[0];
166  }
167  } else {
168  // DEFAULT TO 0 IF THERE IS NO DATE SET
169  $day = '00';
170  $month = '00';
171  $year = '0000';
172  }
173 
174  //echo "<pre>"; print_r(array($day,$month,$year)); die();
175 
176  $return = parent::dropDownList($htmlOptions['name'].'[day]', $day,$dayOptions);
177  $return .= parent::dropDownList($htmlOptions['name'].'[month]', $month,$monthOptions);
178  $return .= parent::dropDownList($htmlOptions['name'].'[year]', $year,$yearOptions);
179  return $return;
180 }
181 
182 
183 }