@@ -1,3 +1,5 @@ |
||
1 | 1 | <?php namespace EvolutionCMS\Interfaces; |
2 | 2 | |
3 | -interface PasswordHashInterface{} |
|
3 | +interface PasswordHashInterface |
|
4 | +{ |
|
5 | +} |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | class DataGrid implements DataGridInterface{ |
15 | 15 | |
16 | - public $ds; // datasource |
|
16 | + public $ds; // datasource |
|
17 | 17 | public $id; |
18 | 18 | public $pageSize; // pager settings |
19 | 19 | public $pageNumber; |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public $colWraps; |
38 | 38 | public $colColors; |
39 | 39 | public $colTypes; // coltype1, coltype2, etc or coltype1:format1, e.g. date:%Y %m |
40 | - // data type: integer,float,currency,date |
|
40 | + // data type: integer,float,currency,date |
|
41 | 41 | |
42 | 42 | public $header; |
43 | 43 | public $footer; |
@@ -76,236 +76,236 @@ discard block |
||
76 | 76 | public static $dataGridCnt; |
77 | 77 | |
78 | 78 | public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) { |
79 | - // set id |
|
80 | - self::$dataGridCnt++; |
|
81 | - $this->id = $this->id ? empty($id) : "dg" . self::$dataGridCnt; |
|
79 | + // set id |
|
80 | + self::$dataGridCnt++; |
|
81 | + $this->id = $this->id ? empty($id) : "dg" . self::$dataGridCnt; |
|
82 | 82 | |
83 | - // set datasource |
|
84 | - $this->ds = $ds; |
|
83 | + // set datasource |
|
84 | + $this->ds = $ds; |
|
85 | 85 | |
86 | - // set pager |
|
87 | - $this->pageSize = $pageSize; |
|
88 | - $this->pageNumber = $pageNumber; // by setting pager to -1 will cause pager to load it's last page number |
|
89 | - $this->pagerLocation = 'top-right'; |
|
90 | - } |
|
86 | + // set pager |
|
87 | + $this->pageSize = $pageSize; |
|
88 | + $this->pageNumber = $pageNumber; // by setting pager to -1 will cause pager to load it's last page number |
|
89 | + $this->pagerLocation = 'top-right'; |
|
90 | + } |
|
91 | 91 | |
92 | 92 | public function setDataSource($ds) { |
93 | - $this->ds = $ds; |
|
94 | - } |
|
93 | + $this->ds = $ds; |
|
94 | + } |
|
95 | 95 | |
96 | 96 | public function render() { |
97 | 97 | $modx = evolutionCMS(); |
98 | - $columnHeaderStyle = ($this->columnHeaderStyle) ? "style='" . $this->columnHeaderStyle . "'" : ''; |
|
99 | - $columnHeaderClass = ($this->columnHeaderClass) ? "class='" . $this->columnHeaderClass . "'" : ""; |
|
100 | - $cssStyle = ($this->cssStyle) ? "style='" . $this->cssStyle . "'" : ''; |
|
101 | - $cssClass = ($this->cssClass) ? "class='" . $this->cssClass . "'" : ''; |
|
102 | - |
|
103 | - $pagerClass = ($this->pagerClass) ? "class='" . $this->pagerClass . "'" : ''; |
|
104 | - $pagerStyle = ($this->pagerStyle) ? "style='" . $this->pagerStyle . "'" : "style='background-color:#ffffff;'"; |
|
105 | - |
|
106 | - $this->_itemStyle = ($this->itemStyle) ? "style='" . $this->itemStyle . "'" : ''; |
|
107 | - $this->_itemClass = ($this->itemClass) ? "class='" . $this->itemClass . "'" : ''; |
|
108 | - $this->_altItemStyle = ($this->altItemStyle) ? "style='" . $this->altItemStyle . "'" : ''; |
|
109 | - $this->_altItemClass = ($this->altItemClass) ? "class='" . $this->altItemClass . "'" : ''; |
|
110 | - |
|
111 | - $this->_alt = 0; |
|
112 | - $this->_total = 0; |
|
113 | - |
|
114 | - $this->_isDataset = $modx->getDatabase()->isResult($this->ds); // if not dataset then treat as array |
|
115 | - |
|
116 | - if(!$cssStyle && !$cssClass) { |
|
117 | - $cssStyle = "style='width:100%;border:1px solid silver;font-family:verdana,arial; font-size:11px;'"; |
|
118 | - } |
|
119 | - if(!$columnHeaderStyle && !$columnHeaderClass) { |
|
120 | - $columnHeaderStyle = "style='color:black;background-color:silver'"; |
|
121 | - } |
|
122 | - if(!$this->_itemStyle && !$this->_itemClass) { |
|
123 | - $this->_itemStyle = "style='color:black;'"; |
|
124 | - } |
|
125 | - if(!$this->_altItemStyle && !$this->_altItemClass) { |
|
126 | - $this->_altItemStyle = "style='color:black;background-color:#eeeeee'"; |
|
127 | - } |
|
128 | - |
|
129 | - if($this->_isDataset && !$this->columns) { |
|
130 | - $cols = $modx->getDatabase()->numFields($this->ds); |
|
131 | - for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->getDatabase()->fieldName($this->ds, $i); |
|
132 | - } |
|
133 | - |
|
134 | - // start grid |
|
135 | - $tblStart = "<table $cssClass $cssStyle cellpadding='" . (isset($this->cellPadding) ? (int) $this->cellPadding : 1) . "' cellspacing='" . (isset($this->cellSpacing) ? (int) $this->cellSpacing : 1) . "'>"; |
|
136 | - $tblEnd = "</table>"; |
|
137 | - |
|
138 | - // build column header |
|
139 | - $this->_colnames = explode((strstr($this->columns, "||") !== false ? "||" : ","), $this->columns); |
|
140 | - $this->_colwidths = explode((strstr($this->colWidths, "||") !== false ? "||" : ","), $this->colWidths); |
|
141 | - $this->_colaligns = explode((strstr($this->colAligns, "||") !== false ? "||" : ","), $this->colAligns); |
|
142 | - $this->_colwraps = explode((strstr($this->colWraps, "||") !== false ? "||" : ","), $this->colWraps); |
|
143 | - $this->_colcolors = explode((strstr($this->colColors, "||") !== false ? "||" : ","), $this->colColors); |
|
144 | - $this->_coltypes = explode((strstr($this->colTypes, "||") !== false ? "||" : ","), $this->colTypes); |
|
145 | - $this->_colcount = count($this->_colnames); |
|
146 | - if(!$this->_isDataset) { |
|
147 | - $this->ds = explode((strstr($this->ds, "||") !== false ? "||" : ","), $this->ds); |
|
148 | - $this->ds = array_chunk($this->ds, $this->_colcount); |
|
149 | - } |
|
150 | - $tblColHdr = "<thead><tr>"; |
|
151 | - for($c = 0; $c < $this->_colcount; $c++) { |
|
152 | - $name = $this->_colnames[$c]; |
|
153 | - $width = $this->_colwidths[$c]; |
|
154 | - $tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass" . ($width ? " width='$width'" : "") . ">$name</td>"; |
|
155 | - } |
|
156 | - $tblColHdr .= "</tr></thead>\n"; |
|
157 | - |
|
158 | - // build rows |
|
159 | - $rowcount = $this->_isDataset ? $modx->getDatabase()->getRecordCount($this->ds) : count($this->ds); |
|
160 | - $this->_fieldnames = explode(",", $this->fields); |
|
161 | - if($rowcount == 0) { |
|
162 | - $tblRows .= "<tr><td " . $this->_itemStyle . " " . $this->_itemClass . " colspan='" . $this->_colcount . "'>" . $this->noRecordMsg . "</td></tr>\n"; |
|
163 | - } else { |
|
164 | - // render grid items |
|
165 | - if($this->pageSize <= 0) { |
|
166 | - for($r = 0; $r < $rowcount; $r++) { |
|
167 | - $row = $this->_isDataset ? $modx->getDatabase()->getRow($this->ds) : $this->ds[$r]; |
|
168 | - $tblRows .= $this->RenderRowFnc($r + 1, $row); |
|
169 | - } |
|
170 | - } else { |
|
171 | - if(!$this->pager) { |
|
172 | - $this->pager = new DataSetPager($this->id, $this->ds, $this->pageSize, $this->pageNumber); |
|
173 | - $this->pager->setRenderRowFnc($this); // pass this object |
|
174 | - $this->pager->cssStyle = $pagerStyle; |
|
175 | - $this->pager->cssClass = $pagerClass; |
|
176 | - } else { |
|
177 | - $this->pager->pageSize = $this->pageSize; |
|
178 | - $this->pager->pageNumber = $this->pageNumber; |
|
179 | - } |
|
180 | - |
|
181 | - $this->pager->render(); |
|
182 | - $tblRows = $this->pager->getRenderedRows(); |
|
183 | - $tblPager = $this->pager->getRenderedPager(); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - // setup header,pager and footer |
|
188 | - $o = $tblStart; |
|
189 | - $ptop = (substr($this->pagerLocation, 0, 3) == "top") || (substr($this->pagerLocation, 0, 4) == "both"); |
|
190 | - $pbot = (substr($this->pagerLocation, 0, 3) == "bot") || (substr($this->pagerLocation, 0, 4) == "both"); |
|
191 | - if($this->header) { |
|
192 | - $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->header . "</td></tr>"; |
|
193 | - } |
|
194 | - if($tblPager && $ptop) { |
|
195 | - $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
196 | - } |
|
197 | - $o .= $tblColHdr . $tblRows; |
|
198 | - if($tblPager && $pbot) { |
|
199 | - $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
200 | - } |
|
201 | - if($this->footer) { |
|
202 | - $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->footer . "</td></tr>"; |
|
203 | - } |
|
204 | - $o .= $tblEnd; |
|
205 | - return $o; |
|
206 | - } |
|
207 | - |
|
208 | - // format column values |
|
98 | + $columnHeaderStyle = ($this->columnHeaderStyle) ? "style='" . $this->columnHeaderStyle . "'" : ''; |
|
99 | + $columnHeaderClass = ($this->columnHeaderClass) ? "class='" . $this->columnHeaderClass . "'" : ""; |
|
100 | + $cssStyle = ($this->cssStyle) ? "style='" . $this->cssStyle . "'" : ''; |
|
101 | + $cssClass = ($this->cssClass) ? "class='" . $this->cssClass . "'" : ''; |
|
102 | + |
|
103 | + $pagerClass = ($this->pagerClass) ? "class='" . $this->pagerClass . "'" : ''; |
|
104 | + $pagerStyle = ($this->pagerStyle) ? "style='" . $this->pagerStyle . "'" : "style='background-color:#ffffff;'"; |
|
105 | + |
|
106 | + $this->_itemStyle = ($this->itemStyle) ? "style='" . $this->itemStyle . "'" : ''; |
|
107 | + $this->_itemClass = ($this->itemClass) ? "class='" . $this->itemClass . "'" : ''; |
|
108 | + $this->_altItemStyle = ($this->altItemStyle) ? "style='" . $this->altItemStyle . "'" : ''; |
|
109 | + $this->_altItemClass = ($this->altItemClass) ? "class='" . $this->altItemClass . "'" : ''; |
|
110 | + |
|
111 | + $this->_alt = 0; |
|
112 | + $this->_total = 0; |
|
113 | + |
|
114 | + $this->_isDataset = $modx->getDatabase()->isResult($this->ds); // if not dataset then treat as array |
|
115 | + |
|
116 | + if(!$cssStyle && !$cssClass) { |
|
117 | + $cssStyle = "style='width:100%;border:1px solid silver;font-family:verdana,arial; font-size:11px;'"; |
|
118 | + } |
|
119 | + if(!$columnHeaderStyle && !$columnHeaderClass) { |
|
120 | + $columnHeaderStyle = "style='color:black;background-color:silver'"; |
|
121 | + } |
|
122 | + if(!$this->_itemStyle && !$this->_itemClass) { |
|
123 | + $this->_itemStyle = "style='color:black;'"; |
|
124 | + } |
|
125 | + if(!$this->_altItemStyle && !$this->_altItemClass) { |
|
126 | + $this->_altItemStyle = "style='color:black;background-color:#eeeeee'"; |
|
127 | + } |
|
128 | + |
|
129 | + if($this->_isDataset && !$this->columns) { |
|
130 | + $cols = $modx->getDatabase()->numFields($this->ds); |
|
131 | + for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->getDatabase()->fieldName($this->ds, $i); |
|
132 | + } |
|
133 | + |
|
134 | + // start grid |
|
135 | + $tblStart = "<table $cssClass $cssStyle cellpadding='" . (isset($this->cellPadding) ? (int) $this->cellPadding : 1) . "' cellspacing='" . (isset($this->cellSpacing) ? (int) $this->cellSpacing : 1) . "'>"; |
|
136 | + $tblEnd = "</table>"; |
|
137 | + |
|
138 | + // build column header |
|
139 | + $this->_colnames = explode((strstr($this->columns, "||") !== false ? "||" : ","), $this->columns); |
|
140 | + $this->_colwidths = explode((strstr($this->colWidths, "||") !== false ? "||" : ","), $this->colWidths); |
|
141 | + $this->_colaligns = explode((strstr($this->colAligns, "||") !== false ? "||" : ","), $this->colAligns); |
|
142 | + $this->_colwraps = explode((strstr($this->colWraps, "||") !== false ? "||" : ","), $this->colWraps); |
|
143 | + $this->_colcolors = explode((strstr($this->colColors, "||") !== false ? "||" : ","), $this->colColors); |
|
144 | + $this->_coltypes = explode((strstr($this->colTypes, "||") !== false ? "||" : ","), $this->colTypes); |
|
145 | + $this->_colcount = count($this->_colnames); |
|
146 | + if(!$this->_isDataset) { |
|
147 | + $this->ds = explode((strstr($this->ds, "||") !== false ? "||" : ","), $this->ds); |
|
148 | + $this->ds = array_chunk($this->ds, $this->_colcount); |
|
149 | + } |
|
150 | + $tblColHdr = "<thead><tr>"; |
|
151 | + for($c = 0; $c < $this->_colcount; $c++) { |
|
152 | + $name = $this->_colnames[$c]; |
|
153 | + $width = $this->_colwidths[$c]; |
|
154 | + $tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass" . ($width ? " width='$width'" : "") . ">$name</td>"; |
|
155 | + } |
|
156 | + $tblColHdr .= "</tr></thead>\n"; |
|
157 | + |
|
158 | + // build rows |
|
159 | + $rowcount = $this->_isDataset ? $modx->getDatabase()->getRecordCount($this->ds) : count($this->ds); |
|
160 | + $this->_fieldnames = explode(",", $this->fields); |
|
161 | + if($rowcount == 0) { |
|
162 | + $tblRows .= "<tr><td " . $this->_itemStyle . " " . $this->_itemClass . " colspan='" . $this->_colcount . "'>" . $this->noRecordMsg . "</td></tr>\n"; |
|
163 | + } else { |
|
164 | + // render grid items |
|
165 | + if($this->pageSize <= 0) { |
|
166 | + for($r = 0; $r < $rowcount; $r++) { |
|
167 | + $row = $this->_isDataset ? $modx->getDatabase()->getRow($this->ds) : $this->ds[$r]; |
|
168 | + $tblRows .= $this->RenderRowFnc($r + 1, $row); |
|
169 | + } |
|
170 | + } else { |
|
171 | + if(!$this->pager) { |
|
172 | + $this->pager = new DataSetPager($this->id, $this->ds, $this->pageSize, $this->pageNumber); |
|
173 | + $this->pager->setRenderRowFnc($this); // pass this object |
|
174 | + $this->pager->cssStyle = $pagerStyle; |
|
175 | + $this->pager->cssClass = $pagerClass; |
|
176 | + } else { |
|
177 | + $this->pager->pageSize = $this->pageSize; |
|
178 | + $this->pager->pageNumber = $this->pageNumber; |
|
179 | + } |
|
180 | + |
|
181 | + $this->pager->render(); |
|
182 | + $tblRows = $this->pager->getRenderedRows(); |
|
183 | + $tblPager = $this->pager->getRenderedPager(); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + // setup header,pager and footer |
|
188 | + $o = $tblStart; |
|
189 | + $ptop = (substr($this->pagerLocation, 0, 3) == "top") || (substr($this->pagerLocation, 0, 4) == "both"); |
|
190 | + $pbot = (substr($this->pagerLocation, 0, 3) == "bot") || (substr($this->pagerLocation, 0, 4) == "both"); |
|
191 | + if($this->header) { |
|
192 | + $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->header . "</td></tr>"; |
|
193 | + } |
|
194 | + if($tblPager && $ptop) { |
|
195 | + $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
196 | + } |
|
197 | + $o .= $tblColHdr . $tblRows; |
|
198 | + if($tblPager && $pbot) { |
|
199 | + $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
200 | + } |
|
201 | + if($this->footer) { |
|
202 | + $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->footer . "</td></tr>"; |
|
203 | + } |
|
204 | + $o .= $tblEnd; |
|
205 | + return $o; |
|
206 | + } |
|
207 | + |
|
208 | + // format column values |
|
209 | 209 | |
210 | 210 | public function RenderRowFnc($n, $row) { |
211 | - if($this->_alt == 0) { |
|
212 | - $Style = $this->_itemStyle; |
|
213 | - $Class = $this->_itemClass; |
|
214 | - $this->_alt = 1; |
|
215 | - } else { |
|
216 | - $Style = $this->_altItemStyle; |
|
217 | - $Class = $this->_altItemClass; |
|
218 | - $this->_alt = 0; |
|
219 | - } |
|
220 | - $o = "<tr>"; |
|
221 | - for($c = 0; $c < $this->_colcount; $c++) { |
|
222 | - $colStyle = $Style; |
|
223 | - $fld = trim($this->_fieldnames[$c]); |
|
224 | - $width = isset($this->_colwidths[$c]) ? $this->_colwidths[$c] : null; |
|
225 | - $align = isset($this->_colaligns[$c]) ? $this->_colaligns[$c] : null; |
|
226 | - $color = isset($this->_colcolors[$c]) ? $this->_colcolors[$c] : null; |
|
227 | - $type = isset($this->_coltypes[$c]) ? $this->_coltypes[$c] : null; |
|
228 | - $nowrap = isset($this->_colwraps[$c]) ? $this->_colwraps[$c] : null; |
|
229 | - $value = $row[($this->_isDataset && $fld ? $fld : $c)]; |
|
230 | - if($color && $Style) { |
|
231 | - $colStyle = substr($colStyle, 0, -1) . ";background-color:$color;'"; |
|
232 | - } |
|
233 | - $value = $this->formatColumnValue($row, $value, $type, $align); |
|
234 | - $o .= "<td $colStyle $Class" . ($align ? " align='$align'" : "") . ($color ? " bgcolor='$color'" : "") . ($nowrap ? " nowrap='$nowrap'" : "") . ($width ? " width='$width'" : "") . ">$value</td>"; |
|
235 | - } |
|
236 | - $o .= "</tr>\n"; |
|
237 | - return $o; |
|
238 | - } |
|
211 | + if($this->_alt == 0) { |
|
212 | + $Style = $this->_itemStyle; |
|
213 | + $Class = $this->_itemClass; |
|
214 | + $this->_alt = 1; |
|
215 | + } else { |
|
216 | + $Style = $this->_altItemStyle; |
|
217 | + $Class = $this->_altItemClass; |
|
218 | + $this->_alt = 0; |
|
219 | + } |
|
220 | + $o = "<tr>"; |
|
221 | + for($c = 0; $c < $this->_colcount; $c++) { |
|
222 | + $colStyle = $Style; |
|
223 | + $fld = trim($this->_fieldnames[$c]); |
|
224 | + $width = isset($this->_colwidths[$c]) ? $this->_colwidths[$c] : null; |
|
225 | + $align = isset($this->_colaligns[$c]) ? $this->_colaligns[$c] : null; |
|
226 | + $color = isset($this->_colcolors[$c]) ? $this->_colcolors[$c] : null; |
|
227 | + $type = isset($this->_coltypes[$c]) ? $this->_coltypes[$c] : null; |
|
228 | + $nowrap = isset($this->_colwraps[$c]) ? $this->_colwraps[$c] : null; |
|
229 | + $value = $row[($this->_isDataset && $fld ? $fld : $c)]; |
|
230 | + if($color && $Style) { |
|
231 | + $colStyle = substr($colStyle, 0, -1) . ";background-color:$color;'"; |
|
232 | + } |
|
233 | + $value = $this->formatColumnValue($row, $value, $type, $align); |
|
234 | + $o .= "<td $colStyle $Class" . ($align ? " align='$align'" : "") . ($color ? " bgcolor='$color'" : "") . ($nowrap ? " nowrap='$nowrap'" : "") . ($width ? " width='$width'" : "") . ">$value</td>"; |
|
235 | + } |
|
236 | + $o .= "</tr>\n"; |
|
237 | + return $o; |
|
238 | + } |
|
239 | 239 | |
240 | 240 | public function formatColumnValue($row, $value, $type, &$align) { |
241 | - if(strpos($type, ":") !== false) { |
|
242 | - list($type, $type_format) = explode(":", $type, 2); |
|
243 | - } |
|
244 | - switch(strtolower($type)) { |
|
245 | - case "integer": |
|
246 | - if($align == "") { |
|
247 | - $align = "right"; |
|
248 | - } |
|
249 | - $value = number_format($value); |
|
250 | - break; |
|
251 | - |
|
252 | - case "float": |
|
253 | - if($align == "") { |
|
254 | - $align = "right"; |
|
255 | - } |
|
256 | - if(!$type_format) { |
|
257 | - $type_format = 2; |
|
258 | - } |
|
259 | - $value = number_format($value, $type_format); |
|
260 | - break; |
|
261 | - |
|
262 | - case "currency": |
|
263 | - if($align == "") { |
|
264 | - $align = "right"; |
|
265 | - } |
|
266 | - if(!$type_format) { |
|
267 | - $type_format = 2; |
|
268 | - } |
|
269 | - $value = "$" . number_format($value, $type_format); |
|
270 | - break; |
|
271 | - |
|
272 | - case "date": |
|
273 | - if($align == "") { |
|
274 | - $align = "right"; |
|
275 | - } |
|
276 | - if(!is_numeric($value)) { |
|
277 | - $value = strtotime($value); |
|
278 | - } |
|
279 | - if(!$type_format) { |
|
280 | - $type_format = "%A %d, %B %Y"; |
|
281 | - } |
|
282 | - $value = strftime($type_format, $value); |
|
283 | - break; |
|
284 | - |
|
285 | - case "boolean": |
|
286 | - if($align == '') { |
|
287 | - $align = "center"; |
|
288 | - } |
|
289 | - $value = number_format($value); |
|
290 | - if($value) { |
|
291 | - $value = '•'; |
|
292 | - } else { |
|
293 | - $value = ' '; |
|
294 | - } |
|
295 | - break; |
|
296 | - |
|
297 | - case "template": |
|
298 | - // replace [+value+] first |
|
299 | - $value = str_replace("[+value+]", $value, $type_format); |
|
300 | - // replace other [+fields+] |
|
301 | - if(strpos($value, "[+") !== false) { |
|
302 | - foreach($row as $k => $v) { |
|
303 | - $value = str_replace("[+$k+]", $v, $value); |
|
304 | - } |
|
305 | - } |
|
306 | - break; |
|
307 | - |
|
308 | - } |
|
309 | - return $value; |
|
310 | - } |
|
241 | + if(strpos($type, ":") !== false) { |
|
242 | + list($type, $type_format) = explode(":", $type, 2); |
|
243 | + } |
|
244 | + switch(strtolower($type)) { |
|
245 | + case "integer": |
|
246 | + if($align == "") { |
|
247 | + $align = "right"; |
|
248 | + } |
|
249 | + $value = number_format($value); |
|
250 | + break; |
|
251 | + |
|
252 | + case "float": |
|
253 | + if($align == "") { |
|
254 | + $align = "right"; |
|
255 | + } |
|
256 | + if(!$type_format) { |
|
257 | + $type_format = 2; |
|
258 | + } |
|
259 | + $value = number_format($value, $type_format); |
|
260 | + break; |
|
261 | + |
|
262 | + case "currency": |
|
263 | + if($align == "") { |
|
264 | + $align = "right"; |
|
265 | + } |
|
266 | + if(!$type_format) { |
|
267 | + $type_format = 2; |
|
268 | + } |
|
269 | + $value = "$" . number_format($value, $type_format); |
|
270 | + break; |
|
271 | + |
|
272 | + case "date": |
|
273 | + if($align == "") { |
|
274 | + $align = "right"; |
|
275 | + } |
|
276 | + if(!is_numeric($value)) { |
|
277 | + $value = strtotime($value); |
|
278 | + } |
|
279 | + if(!$type_format) { |
|
280 | + $type_format = "%A %d, %B %Y"; |
|
281 | + } |
|
282 | + $value = strftime($type_format, $value); |
|
283 | + break; |
|
284 | + |
|
285 | + case "boolean": |
|
286 | + if($align == '') { |
|
287 | + $align = "center"; |
|
288 | + } |
|
289 | + $value = number_format($value); |
|
290 | + if($value) { |
|
291 | + $value = '•'; |
|
292 | + } else { |
|
293 | + $value = ' '; |
|
294 | + } |
|
295 | + break; |
|
296 | + |
|
297 | + case "template": |
|
298 | + // replace [+value+] first |
|
299 | + $value = str_replace("[+value+]", $value, $type_format); |
|
300 | + // replace other [+fields+] |
|
301 | + if(strpos($value, "[+") !== false) { |
|
302 | + foreach($row as $k => $v) { |
|
303 | + $value = str_replace("[+$k+]", $v, $value); |
|
304 | + } |
|
305 | + } |
|
306 | + break; |
|
307 | + |
|
308 | + } |
|
309 | + return $value; |
|
310 | + } |
|
311 | 311 | } |
@@ -15,10 +15,10 @@ discard block |
||
15 | 15 | |
16 | 16 | public $ds; // datasource |
17 | 17 | public $id; |
18 | - public $pageSize; // pager settings |
|
18 | + public $pageSize; // pager settings |
|
19 | 19 | public $pageNumber; |
20 | 20 | public $pager; |
21 | - public $pagerLocation; // top-right, top-left, bottom-left, bottom-right, both-left, both-right |
|
21 | + public $pagerLocation; // top-right, top-left, bottom-left, bottom-right, both-left, both-right |
|
22 | 22 | |
23 | 23 | public $cssStyle; |
24 | 24 | public $cssClass; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | public $colAligns; |
37 | 37 | public $colWraps; |
38 | 38 | public $colColors; |
39 | - public $colTypes; // coltype1, coltype2, etc or coltype1:format1, e.g. date:%Y %m |
|
39 | + public $colTypes; // coltype1, coltype2, etc or coltype1:format1, e.g. date:%Y %m |
|
40 | 40 | // data type: integer,float,currency,date |
41 | 41 | |
42 | 42 | public $header; |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | public $cellPadding; |
45 | 45 | public $cellSpacing; |
46 | 46 | |
47 | - public $rowAlign; // vertical alignment: top, middle, bottom |
|
47 | + public $rowAlign; // vertical alignment: top, middle, bottom |
|
48 | 48 | public $rowIdField; |
49 | 49 | |
50 | 50 | public $pagerStyle; |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | |
76 | 76 | public static $dataGridCnt; |
77 | 77 | |
78 | - public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) { |
|
78 | + public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1){ |
|
79 | 79 | // set id |
80 | 80 | self::$dataGridCnt++; |
81 | - $this->id = $this->id ? empty($id) : "dg" . self::$dataGridCnt; |
|
81 | + $this->id = $this->id ? empty($id) : "dg".self::$dataGridCnt; |
|
82 | 82 | |
83 | 83 | // set datasource |
84 | 84 | $this->ds = $ds; |
@@ -89,50 +89,50 @@ discard block |
||
89 | 89 | $this->pagerLocation = 'top-right'; |
90 | 90 | } |
91 | 91 | |
92 | - public function setDataSource($ds) { |
|
92 | + public function setDataSource($ds){ |
|
93 | 93 | $this->ds = $ds; |
94 | 94 | } |
95 | 95 | |
96 | - public function render() { |
|
96 | + public function render(){ |
|
97 | 97 | $modx = evolutionCMS(); |
98 | - $columnHeaderStyle = ($this->columnHeaderStyle) ? "style='" . $this->columnHeaderStyle . "'" : ''; |
|
99 | - $columnHeaderClass = ($this->columnHeaderClass) ? "class='" . $this->columnHeaderClass . "'" : ""; |
|
100 | - $cssStyle = ($this->cssStyle) ? "style='" . $this->cssStyle . "'" : ''; |
|
101 | - $cssClass = ($this->cssClass) ? "class='" . $this->cssClass . "'" : ''; |
|
98 | + $columnHeaderStyle = ($this->columnHeaderStyle) ? "style='".$this->columnHeaderStyle."'" : ''; |
|
99 | + $columnHeaderClass = ($this->columnHeaderClass) ? "class='".$this->columnHeaderClass."'" : ""; |
|
100 | + $cssStyle = ($this->cssStyle) ? "style='".$this->cssStyle."'" : ''; |
|
101 | + $cssClass = ($this->cssClass) ? "class='".$this->cssClass."'" : ''; |
|
102 | 102 | |
103 | - $pagerClass = ($this->pagerClass) ? "class='" . $this->pagerClass . "'" : ''; |
|
104 | - $pagerStyle = ($this->pagerStyle) ? "style='" . $this->pagerStyle . "'" : "style='background-color:#ffffff;'"; |
|
103 | + $pagerClass = ($this->pagerClass) ? "class='".$this->pagerClass."'" : ''; |
|
104 | + $pagerStyle = ($this->pagerStyle) ? "style='".$this->pagerStyle."'" : "style='background-color:#ffffff;'"; |
|
105 | 105 | |
106 | - $this->_itemStyle = ($this->itemStyle) ? "style='" . $this->itemStyle . "'" : ''; |
|
107 | - $this->_itemClass = ($this->itemClass) ? "class='" . $this->itemClass . "'" : ''; |
|
108 | - $this->_altItemStyle = ($this->altItemStyle) ? "style='" . $this->altItemStyle . "'" : ''; |
|
109 | - $this->_altItemClass = ($this->altItemClass) ? "class='" . $this->altItemClass . "'" : ''; |
|
106 | + $this->_itemStyle = ($this->itemStyle) ? "style='".$this->itemStyle."'" : ''; |
|
107 | + $this->_itemClass = ($this->itemClass) ? "class='".$this->itemClass."'" : ''; |
|
108 | + $this->_altItemStyle = ($this->altItemStyle) ? "style='".$this->altItemStyle."'" : ''; |
|
109 | + $this->_altItemClass = ($this->altItemClass) ? "class='".$this->altItemClass."'" : ''; |
|
110 | 110 | |
111 | 111 | $this->_alt = 0; |
112 | 112 | $this->_total = 0; |
113 | 113 | |
114 | 114 | $this->_isDataset = $modx->getDatabase()->isResult($this->ds); // if not dataset then treat as array |
115 | 115 | |
116 | - if(!$cssStyle && !$cssClass) { |
|
116 | + if (!$cssStyle && !$cssClass) { |
|
117 | 117 | $cssStyle = "style='width:100%;border:1px solid silver;font-family:verdana,arial; font-size:11px;'"; |
118 | 118 | } |
119 | - if(!$columnHeaderStyle && !$columnHeaderClass) { |
|
119 | + if (!$columnHeaderStyle && !$columnHeaderClass) { |
|
120 | 120 | $columnHeaderStyle = "style='color:black;background-color:silver'"; |
121 | 121 | } |
122 | - if(!$this->_itemStyle && !$this->_itemClass) { |
|
122 | + if (!$this->_itemStyle && !$this->_itemClass) { |
|
123 | 123 | $this->_itemStyle = "style='color:black;'"; |
124 | 124 | } |
125 | - if(!$this->_altItemStyle && !$this->_altItemClass) { |
|
125 | + if (!$this->_altItemStyle && !$this->_altItemClass) { |
|
126 | 126 | $this->_altItemStyle = "style='color:black;background-color:#eeeeee'"; |
127 | 127 | } |
128 | 128 | |
129 | - if($this->_isDataset && !$this->columns) { |
|
129 | + if ($this->_isDataset && !$this->columns) { |
|
130 | 130 | $cols = $modx->getDatabase()->numFields($this->ds); |
131 | - for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->getDatabase()->fieldName($this->ds, $i); |
|
131 | + for ($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "").$modx->getDatabase()->fieldName($this->ds, $i); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | // start grid |
135 | - $tblStart = "<table $cssClass $cssStyle cellpadding='" . (isset($this->cellPadding) ? (int) $this->cellPadding : 1) . "' cellspacing='" . (isset($this->cellSpacing) ? (int) $this->cellSpacing : 1) . "'>"; |
|
135 | + $tblStart = "<table $cssClass $cssStyle cellpadding='".(isset($this->cellPadding) ? (int) $this->cellPadding : 1)."' cellspacing='".(isset($this->cellSpacing) ? (int) $this->cellSpacing : 1)."'>"; |
|
136 | 136 | $tblEnd = "</table>"; |
137 | 137 | |
138 | 138 | // build column header |
@@ -143,32 +143,32 @@ discard block |
||
143 | 143 | $this->_colcolors = explode((strstr($this->colColors, "||") !== false ? "||" : ","), $this->colColors); |
144 | 144 | $this->_coltypes = explode((strstr($this->colTypes, "||") !== false ? "||" : ","), $this->colTypes); |
145 | 145 | $this->_colcount = count($this->_colnames); |
146 | - if(!$this->_isDataset) { |
|
146 | + if (!$this->_isDataset) { |
|
147 | 147 | $this->ds = explode((strstr($this->ds, "||") !== false ? "||" : ","), $this->ds); |
148 | 148 | $this->ds = array_chunk($this->ds, $this->_colcount); |
149 | 149 | } |
150 | 150 | $tblColHdr = "<thead><tr>"; |
151 | - for($c = 0; $c < $this->_colcount; $c++) { |
|
151 | + for ($c = 0; $c < $this->_colcount; $c++) { |
|
152 | 152 | $name = $this->_colnames[$c]; |
153 | 153 | $width = $this->_colwidths[$c]; |
154 | - $tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass" . ($width ? " width='$width'" : "") . ">$name</td>"; |
|
154 | + $tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass".($width ? " width='$width'" : "").">$name</td>"; |
|
155 | 155 | } |
156 | 156 | $tblColHdr .= "</tr></thead>\n"; |
157 | 157 | |
158 | 158 | // build rows |
159 | 159 | $rowcount = $this->_isDataset ? $modx->getDatabase()->getRecordCount($this->ds) : count($this->ds); |
160 | 160 | $this->_fieldnames = explode(",", $this->fields); |
161 | - if($rowcount == 0) { |
|
162 | - $tblRows .= "<tr><td " . $this->_itemStyle . " " . $this->_itemClass . " colspan='" . $this->_colcount . "'>" . $this->noRecordMsg . "</td></tr>\n"; |
|
161 | + if ($rowcount == 0) { |
|
162 | + $tblRows .= "<tr><td ".$this->_itemStyle." ".$this->_itemClass." colspan='".$this->_colcount."'>".$this->noRecordMsg."</td></tr>\n"; |
|
163 | 163 | } else { |
164 | 164 | // render grid items |
165 | - if($this->pageSize <= 0) { |
|
166 | - for($r = 0; $r < $rowcount; $r++) { |
|
165 | + if ($this->pageSize <= 0) { |
|
166 | + for ($r = 0; $r < $rowcount; $r++) { |
|
167 | 167 | $row = $this->_isDataset ? $modx->getDatabase()->getRow($this->ds) : $this->ds[$r]; |
168 | 168 | $tblRows .= $this->RenderRowFnc($r + 1, $row); |
169 | 169 | } |
170 | 170 | } else { |
171 | - if(!$this->pager) { |
|
171 | + if (!$this->pager) { |
|
172 | 172 | $this->pager = new DataSetPager($this->id, $this->ds, $this->pageSize, $this->pageNumber); |
173 | 173 | $this->pager->setRenderRowFnc($this); // pass this object |
174 | 174 | $this->pager->cssStyle = $pagerStyle; |
@@ -188,18 +188,18 @@ discard block |
||
188 | 188 | $o = $tblStart; |
189 | 189 | $ptop = (substr($this->pagerLocation, 0, 3) == "top") || (substr($this->pagerLocation, 0, 4) == "both"); |
190 | 190 | $pbot = (substr($this->pagerLocation, 0, 3) == "bot") || (substr($this->pagerLocation, 0, 4) == "both"); |
191 | - if($this->header) { |
|
192 | - $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->header . "</td></tr>"; |
|
191 | + if ($this->header) { |
|
192 | + $o .= "<tr><td bgcolor='#ffffff' colspan='".$this->_colcount."'>".$this->header."</td></tr>"; |
|
193 | 193 | } |
194 | - if($tblPager && $ptop) { |
|
195 | - $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
194 | + if ($tblPager && $ptop) { |
|
195 | + $o .= "<tr><td align='".(substr($this->pagerLocation, -4) == "left" ? "left" : "right")."' $pagerClass $pagerStyle colspan='".$this->_colcount."'>".$tblPager." </td></tr>"; |
|
196 | 196 | } |
197 | - $o .= $tblColHdr . $tblRows; |
|
198 | - if($tblPager && $pbot) { |
|
199 | - $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
197 | + $o .= $tblColHdr.$tblRows; |
|
198 | + if ($tblPager && $pbot) { |
|
199 | + $o .= "<tr><td align='".(substr($this->pagerLocation, -4) == "left" ? "left" : "right")."' $pagerClass $pagerStyle colspan='".$this->_colcount."'>".$tblPager." </td></tr>"; |
|
200 | 200 | } |
201 | - if($this->footer) { |
|
202 | - $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->footer . "</td></tr>"; |
|
201 | + if ($this->footer) { |
|
202 | + $o .= "<tr><td bgcolor='#ffffff' colspan='".$this->_colcount."'>".$this->footer."</td></tr>"; |
|
203 | 203 | } |
204 | 204 | $o .= $tblEnd; |
205 | 205 | return $o; |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | |
208 | 208 | // format column values |
209 | 209 | |
210 | - public function RenderRowFnc($n, $row) { |
|
211 | - if($this->_alt == 0) { |
|
210 | + public function RenderRowFnc($n, $row){ |
|
211 | + if ($this->_alt == 0) { |
|
212 | 212 | $Style = $this->_itemStyle; |
213 | 213 | $Class = $this->_itemClass; |
214 | 214 | $this->_alt = 1; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | $this->_alt = 0; |
219 | 219 | } |
220 | 220 | $o = "<tr>"; |
221 | - for($c = 0; $c < $this->_colcount; $c++) { |
|
221 | + for ($c = 0; $c < $this->_colcount; $c++) { |
|
222 | 222 | $colStyle = $Style; |
223 | 223 | $fld = trim($this->_fieldnames[$c]); |
224 | 224 | $width = isset($this->_colwidths[$c]) ? $this->_colwidths[$c] : null; |
@@ -227,67 +227,67 @@ discard block |
||
227 | 227 | $type = isset($this->_coltypes[$c]) ? $this->_coltypes[$c] : null; |
228 | 228 | $nowrap = isset($this->_colwraps[$c]) ? $this->_colwraps[$c] : null; |
229 | 229 | $value = $row[($this->_isDataset && $fld ? $fld : $c)]; |
230 | - if($color && $Style) { |
|
231 | - $colStyle = substr($colStyle, 0, -1) . ";background-color:$color;'"; |
|
230 | + if ($color && $Style) { |
|
231 | + $colStyle = substr($colStyle, 0, -1).";background-color:$color;'"; |
|
232 | 232 | } |
233 | 233 | $value = $this->formatColumnValue($row, $value, $type, $align); |
234 | - $o .= "<td $colStyle $Class" . ($align ? " align='$align'" : "") . ($color ? " bgcolor='$color'" : "") . ($nowrap ? " nowrap='$nowrap'" : "") . ($width ? " width='$width'" : "") . ">$value</td>"; |
|
234 | + $o .= "<td $colStyle $Class".($align ? " align='$align'" : "").($color ? " bgcolor='$color'" : "").($nowrap ? " nowrap='$nowrap'" : "").($width ? " width='$width'" : "").">$value</td>"; |
|
235 | 235 | } |
236 | 236 | $o .= "</tr>\n"; |
237 | 237 | return $o; |
238 | 238 | } |
239 | 239 | |
240 | - public function formatColumnValue($row, $value, $type, &$align) { |
|
241 | - if(strpos($type, ":") !== false) { |
|
240 | + public function formatColumnValue($row, $value, $type, &$align){ |
|
241 | + if (strpos($type, ":") !== false) { |
|
242 | 242 | list($type, $type_format) = explode(":", $type, 2); |
243 | 243 | } |
244 | - switch(strtolower($type)) { |
|
244 | + switch (strtolower($type)) { |
|
245 | 245 | case "integer": |
246 | - if($align == "") { |
|
246 | + if ($align == "") { |
|
247 | 247 | $align = "right"; |
248 | 248 | } |
249 | 249 | $value = number_format($value); |
250 | 250 | break; |
251 | 251 | |
252 | 252 | case "float": |
253 | - if($align == "") { |
|
253 | + if ($align == "") { |
|
254 | 254 | $align = "right"; |
255 | 255 | } |
256 | - if(!$type_format) { |
|
256 | + if (!$type_format) { |
|
257 | 257 | $type_format = 2; |
258 | 258 | } |
259 | 259 | $value = number_format($value, $type_format); |
260 | 260 | break; |
261 | 261 | |
262 | 262 | case "currency": |
263 | - if($align == "") { |
|
263 | + if ($align == "") { |
|
264 | 264 | $align = "right"; |
265 | 265 | } |
266 | - if(!$type_format) { |
|
266 | + if (!$type_format) { |
|
267 | 267 | $type_format = 2; |
268 | 268 | } |
269 | - $value = "$" . number_format($value, $type_format); |
|
269 | + $value = "$".number_format($value, $type_format); |
|
270 | 270 | break; |
271 | 271 | |
272 | 272 | case "date": |
273 | - if($align == "") { |
|
273 | + if ($align == "") { |
|
274 | 274 | $align = "right"; |
275 | 275 | } |
276 | - if(!is_numeric($value)) { |
|
276 | + if (!is_numeric($value)) { |
|
277 | 277 | $value = strtotime($value); |
278 | 278 | } |
279 | - if(!$type_format) { |
|
279 | + if (!$type_format) { |
|
280 | 280 | $type_format = "%A %d, %B %Y"; |
281 | 281 | } |
282 | 282 | $value = strftime($type_format, $value); |
283 | 283 | break; |
284 | 284 | |
285 | 285 | case "boolean": |
286 | - if($align == '') { |
|
286 | + if ($align == '') { |
|
287 | 287 | $align = "center"; |
288 | 288 | } |
289 | 289 | $value = number_format($value); |
290 | - if($value) { |
|
290 | + if ($value) { |
|
291 | 291 | $value = '•'; |
292 | 292 | } else { |
293 | 293 | $value = ' '; |
@@ -298,8 +298,8 @@ discard block |
||
298 | 298 | // replace [+value+] first |
299 | 299 | $value = str_replace("[+value+]", $value, $type_format); |
300 | 300 | // replace other [+fields+] |
301 | - if(strpos($value, "[+") !== false) { |
|
302 | - foreach($row as $k => $v) { |
|
301 | + if (strpos($value, "[+") !== false) { |
|
302 | + foreach ($row as $k => $v) { |
|
303 | 303 | $value = str_replace("[+$k+]", $v, $value); |
304 | 304 | } |
305 | 305 | } |
@@ -11,7 +11,8 @@ discard block |
||
11 | 11 | # ----------------------------------------- |
12 | 12 | # |
13 | 13 | |
14 | -class DataGrid implements DataGridInterface{ |
|
14 | +class DataGrid implements DataGridInterface |
|
15 | +{ |
|
15 | 16 | |
16 | 17 | public $ds; // datasource |
17 | 18 | public $id; |
@@ -75,7 +76,8 @@ discard block |
||
75 | 76 | |
76 | 77 | public static $dataGridCnt; |
77 | 78 | |
78 | - public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) { |
|
79 | + public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) |
|
80 | + { |
|
79 | 81 | // set id |
80 | 82 | self::$dataGridCnt++; |
81 | 83 | $this->id = $this->id ? empty($id) : "dg" . self::$dataGridCnt; |
@@ -89,11 +91,13 @@ discard block |
||
89 | 91 | $this->pagerLocation = 'top-right'; |
90 | 92 | } |
91 | 93 | |
92 | - public function setDataSource($ds) { |
|
94 | + public function setDataSource($ds) |
|
95 | + { |
|
93 | 96 | $this->ds = $ds; |
94 | 97 | } |
95 | 98 | |
96 | - public function render() { |
|
99 | + public function render() |
|
100 | + { |
|
97 | 101 | $modx = evolutionCMS(); |
98 | 102 | $columnHeaderStyle = ($this->columnHeaderStyle) ? "style='" . $this->columnHeaderStyle . "'" : ''; |
99 | 103 | $columnHeaderClass = ($this->columnHeaderClass) ? "class='" . $this->columnHeaderClass . "'" : ""; |
@@ -128,7 +132,9 @@ discard block |
||
128 | 132 | |
129 | 133 | if($this->_isDataset && !$this->columns) { |
130 | 134 | $cols = $modx->getDatabase()->numFields($this->ds); |
131 | - for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->getDatabase()->fieldName($this->ds, $i); |
|
135 | + for($i = 0; $i < $cols; $i++) { |
|
136 | + $this->columns .= ($i ? "," : "") . $modx->getDatabase()->fieldName($this->ds, $i); |
|
137 | + } |
|
132 | 138 | } |
133 | 139 | |
134 | 140 | // start grid |
@@ -207,7 +213,8 @@ discard block |
||
207 | 213 | |
208 | 214 | // format column values |
209 | 215 | |
210 | - public function RenderRowFnc($n, $row) { |
|
216 | + public function RenderRowFnc($n, $row) |
|
217 | + { |
|
211 | 218 | if($this->_alt == 0) { |
212 | 219 | $Style = $this->_itemStyle; |
213 | 220 | $Class = $this->_itemClass; |
@@ -237,7 +244,8 @@ discard block |
||
237 | 244 | return $o; |
238 | 245 | } |
239 | 246 | |
240 | - public function formatColumnValue($row, $value, $type, &$align) { |
|
247 | + public function formatColumnValue($row, $value, $type, &$align) |
|
248 | + { |
|
241 | 249 | if(strpos($type, ":") !== false) { |
242 | 250 | list($type, $type_format) = explode(":", $type, 2); |
243 | 251 | } |
@@ -75,6 +75,10 @@ discard block |
||
75 | 75 | |
76 | 76 | public static $dataGridCnt; |
77 | 77 | |
78 | + /** |
|
79 | + * @param null|string $id |
|
80 | + * @param string $ds |
|
81 | + */ |
|
78 | 82 | public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) { |
79 | 83 | // set id |
80 | 84 | self::$dataGridCnt++; |
@@ -207,6 +211,9 @@ discard block |
||
207 | 211 | |
208 | 212 | // format column values |
209 | 213 | |
214 | + /** |
|
215 | + * @param integer $n |
|
216 | + */ |
|
210 | 217 | public function RenderRowFnc($n, $row) { |
211 | 218 | if($this->_alt == 0) { |
212 | 219 | $Style = $this->_itemStyle; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | // Set line feed |
75 | 75 | $lf = "\n"; |
76 | - $tempfile_path = $modx->config['base_path'] . 'assets/backup/temp.php'; |
|
76 | + $tempfile_path = $modx->config['base_path'].'assets/backup/temp.php'; |
|
77 | 77 | |
78 | 78 | $result = $modx->getDatabase()->query('SHOW TABLES'); |
79 | 79 | $tables = $this->result2Array(0, $result); |
@@ -86,15 +86,15 @@ discard block |
||
86 | 86 | |
87 | 87 | // Set header |
88 | 88 | $output = "#{$lf}"; |
89 | - $output .= "# " . addslashes($modx->config['site_name']) . " Database Dump{$lf}"; |
|
89 | + $output .= "# ".addslashes($modx->config['site_name'])." Database Dump{$lf}"; |
|
90 | 90 | $output .= "# MODX Version:{$version['version']}{$lf}"; |
91 | 91 | $output .= "# {$lf}"; |
92 | 92 | $output .= "# Host: {$this->database_server}{$lf}"; |
93 | - $output .= "# Generation Time: " . $modx->toDateFormat(time()) . $lf; |
|
94 | - $output .= "# Server version: " . $modx->getDatabase()->getVersion() . $lf; |
|
95 | - $output .= "# PHP Version: " . phpversion() . $lf; |
|
93 | + $output .= "# Generation Time: ".$modx->toDateFormat(time()).$lf; |
|
94 | + $output .= "# Server version: ".$modx->getDatabase()->getVersion().$lf; |
|
95 | + $output .= "# PHP Version: ".phpversion().$lf; |
|
96 | 96 | $output .= "# Database: `{$this->dbname}`{$lf}"; |
97 | - $output .= "# Description: " . trim($_REQUEST['backup_title']) . "{$lf}"; |
|
97 | + $output .= "# Description: ".trim($_REQUEST['backup_title'])."{$lf}"; |
|
98 | 98 | $output .= "#"; |
99 | 99 | file_put_contents($tempfile_path, $output, FILE_APPEND | LOCK_EX); |
100 | 100 | $output = ''; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | } |
114 | 114 | } |
115 | 115 | if ($callBack === 'snapshot') { |
116 | - if (!preg_match('@^' . $modx->getDatabase()->config['table_prefix'] . '@', $tblval)) { |
|
116 | + if (!preg_match('@^'.$modx->getDatabase()->config['table_prefix'].'@', $tblval)) { |
|
117 | 117 | continue; |
118 | 118 | } |
119 | 119 | } |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | ), '\\n', $value); |
151 | 151 | $value = "'{$value}'"; |
152 | 152 | } |
153 | - $insertdump .= $value . ','; |
|
153 | + $insertdump .= $value.','; |
|
154 | 154 | } |
155 | - $output .= rtrim($insertdump, ',') . ");\n"; |
|
155 | + $output .= rtrim($insertdump, ',').");\n"; |
|
156 | 156 | if (1048576 < strlen($output)) { |
157 | 157 | file_put_contents($tempfile_path, $output, FILE_APPEND | LOCK_EX); |
158 | 158 | $output = ''; |
@@ -19,46 +19,46 @@ discard block |
||
19 | 19 | |
20 | 20 | public static $cnt; |
21 | 21 | |
22 | - public function __construct($id = '', $width = 120, $visible = false) { |
|
22 | + public function __construct($id = '', $width = 120, $visible = false){ |
|
23 | 23 | self::$cnt++; |
24 | 24 | $this->html = ""; |
25 | 25 | $this->visible = $visible ? $visible : false; |
26 | - $this->width = is_numeric($width) ? (int)$width : 120; |
|
27 | - $this->id = $id ? $id : "cntxMnu" . self::$cnt; // set id |
|
26 | + $this->width = is_numeric($width) ? (int) $width : 120; |
|
27 | + $this->id = $id ? $id : "cntxMnu".self::$cnt; // set id |
|
28 | 28 | } |
29 | 29 | |
30 | - public function addItem($text, $action = "", $img = "", $disabled = 0) { |
|
30 | + public function addItem($text, $action = "", $img = "", $disabled = 0){ |
|
31 | 31 | global $base_url, $_style; |
32 | - if($disabled) { |
|
32 | + if ($disabled) { |
|
33 | 33 | return; |
34 | 34 | } |
35 | - if(!$img) { |
|
36 | - $img = $base_url . $_style['tx']; |
|
35 | + if (!$img) { |
|
36 | + $img = $base_url.$_style['tx']; |
|
37 | 37 | } |
38 | - if(substr($action, 0, 3) == "js:") { |
|
38 | + if (substr($action, 0, 3) == "js:") { |
|
39 | 39 | $action = substr($action, 3); |
40 | - } else if(substr($action, 0, 3) == "hl:") { |
|
41 | - $action = "window.location.href='" . substr($action, 3) . "'"; |
|
40 | + } else if (substr($action, 0, 3) == "hl:") { |
|
41 | + $action = "window.location.href='".substr($action, 3)."'"; |
|
42 | 42 | } else { |
43 | - $action = "window.location.href='" . $action . "'"; |
|
43 | + $action = "window.location.href='".$action."'"; |
|
44 | 44 | } |
45 | - $action = " onmouseover=\"this.className='cntxMnuItemOver';\" onmouseout=\"this.className='cntxMnuItem';\" onclick=\"$action; hideCntxMenu('" . $this->id . "');\""; |
|
46 | - $this->html .= "<div class='" . ($disabled ? "cntxMnuItemDisabled" : "cntxMnuItem") . "' $action>"; |
|
47 | - if(substr($img, 0, 5) == 'fa fa') { |
|
48 | - $img = '<i class="' . $img . '"></i>'; |
|
49 | - } else if(substr($img, 0, 1) != '<') { |
|
50 | - $img = '<img src="' . $img . '" />'; |
|
45 | + $action = " onmouseover=\"this.className='cntxMnuItemOver';\" onmouseout=\"this.className='cntxMnuItem';\" onclick=\"$action; hideCntxMenu('".$this->id."');\""; |
|
46 | + $this->html .= "<div class='".($disabled ? "cntxMnuItemDisabled" : "cntxMnuItem")."' $action>"; |
|
47 | + if (substr($img, 0, 5) == 'fa fa') { |
|
48 | + $img = '<i class="'.$img.'"></i>'; |
|
49 | + } else if (substr($img, 0, 1) != '<') { |
|
50 | + $img = '<img src="'.$img.'" />'; |
|
51 | 51 | } |
52 | - $this->html .= $img . ' ' . $text . '</div>'; |
|
52 | + $this->html .= $img.' '.$text.'</div>'; |
|
53 | 53 | } |
54 | 54 | |
55 | - public function addSeparator() { |
|
55 | + public function addSeparator(){ |
|
56 | 56 | $this->html .= " |
57 | 57 | <div class='cntxMnuSeparator'></div> |
58 | 58 | "; |
59 | 59 | } |
60 | 60 | |
61 | - public function render() { |
|
61 | + public function render(){ |
|
62 | 62 | $ContextMenuScript = <<<BLOCK |
63 | 63 | <script> |
64 | 64 | function getCntxMenu(id) { |
@@ -71,12 +71,12 @@ discard block |
||
71 | 71 | </script> |
72 | 72 | BLOCK; |
73 | 73 | |
74 | - $html = $ContextMenuScript . "<div id='" . $this->id . "' class='contextMenu' style='width:" . $this->width . "px; visibility:" . ($this->visible ? 'visible' : 'hidden') . "'>" . $this->html . "</div>"; |
|
74 | + $html = $ContextMenuScript."<div id='".$this->id."' class='contextMenu' style='width:".$this->width."px; visibility:".($this->visible ? 'visible' : 'hidden')."'>".$this->html."</div>"; |
|
75 | 75 | $ContextMenuScript = ""; // reset css |
76 | 76 | return $html; |
77 | 77 | } |
78 | 78 | |
79 | - public function getClientScriptObject() { |
|
80 | - return "getCntxMenu('" . $this->id . "')"; |
|
79 | + public function getClientScriptObject(){ |
|
80 | + return "getCntxMenu('".$this->id."')"; |
|
81 | 81 | } |
82 | 82 | } |
@@ -2,7 +2,8 @@ discard block |
||
2 | 2 | |
3 | 3 | use EvolutionCMS\Interfaces\ContextMenuInterface; |
4 | 4 | |
5 | -class ContextMenu implements ContextMenuInterface{ |
|
5 | +class ContextMenu implements ContextMenuInterface |
|
6 | +{ |
|
6 | 7 | public $id; |
7 | 8 | /** |
8 | 9 | * @var string |
@@ -19,7 +20,8 @@ discard block |
||
19 | 20 | |
20 | 21 | public static $cnt; |
21 | 22 | |
22 | - public function __construct($id = '', $width = 120, $visible = false) { |
|
23 | + public function __construct($id = '', $width = 120, $visible = false) |
|
24 | + { |
|
23 | 25 | self::$cnt++; |
24 | 26 | $this->html = ""; |
25 | 27 | $this->visible = $visible ? $visible : false; |
@@ -27,7 +29,8 @@ discard block |
||
27 | 29 | $this->id = $id ? $id : "cntxMnu" . self::$cnt; // set id |
28 | 30 | } |
29 | 31 | |
30 | - public function addItem($text, $action = "", $img = "", $disabled = 0) { |
|
32 | + public function addItem($text, $action = "", $img = "", $disabled = 0) |
|
33 | + { |
|
31 | 34 | global $base_url, $_style; |
32 | 35 | if($disabled) { |
33 | 36 | return; |
@@ -52,13 +55,15 @@ discard block |
||
52 | 55 | $this->html .= $img . ' ' . $text . '</div>'; |
53 | 56 | } |
54 | 57 | |
55 | - public function addSeparator() { |
|
58 | + public function addSeparator() |
|
59 | + { |
|
56 | 60 | $this->html .= " |
57 | 61 | <div class='cntxMnuSeparator'></div> |
58 | 62 | "; |
59 | 63 | } |
60 | 64 | |
61 | - public function render() { |
|
65 | + public function render() |
|
66 | + { |
|
62 | 67 | $ContextMenuScript = <<<BLOCK |
63 | 68 | <script> |
64 | 69 | function getCntxMenu(id) { |
@@ -76,7 +81,8 @@ discard block |
||
76 | 81 | return $html; |
77 | 82 | } |
78 | 83 | |
79 | - public function getClientScriptObject() { |
|
84 | + public function getClientScriptObject() |
|
85 | + { |
|
80 | 86 | return "getCntxMenu('" . $this->id . "')"; |
81 | 87 | } |
82 | 88 | } |
@@ -69,7 +69,7 @@ |
||
69 | 69 | cm.style.visibility = 'hidden'; |
70 | 70 | } |
71 | 71 | </script> |
72 | -BLOCK; |
|
72 | +block; |
|
73 | 73 | |
74 | 74 | $html = $ContextMenuScript . "<div id='" . $this->id . "' class='contextMenu' style='width:" . $this->width . "px; visibility:" . ($this->visible ? 'visible' : 'hidden') . "'>" . $this->html . "</div>"; |
75 | 75 | $ContextMenuScript = ""; // reset css |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly."); |
7 | 7 | } |
8 | 8 | |
9 | -require_once(dirname(__FILE__) . '/protect.inc.php'); |
|
9 | +require_once(dirname(__FILE__).'/protect.inc.php'); |
|
10 | 10 | |
11 | 11 | $action = preg_replace('/[^A-Za-z0-9_\-\.\/]/', '', $_POST['action']); |
12 | 12 | $lang = preg_replace('/[^A-Za-z0-9_\s\+\-\.\/]/', '', $_POST['lang']); |
@@ -23,13 +23,13 @@ discard block |
||
23 | 23 | |
24 | 24 | switch (true) { |
25 | 25 | case ($action == 'get' && preg_match('/^[A-z0-9_-]+$/', |
26 | - $lang) && file_exists(dirname(__FILE__) . '/lang/' . $lang . '.inc.php')): { |
|
27 | - include(dirname(__FILE__) . '/lang/' . $lang . '.inc.php'); |
|
26 | + $lang) && file_exists(dirname(__FILE__).'/lang/'.$lang.'.inc.php')): { |
|
27 | + include(dirname(__FILE__).'/lang/'.$lang.'.inc.php'); |
|
28 | 28 | $str = isset($key, $_lang, $_lang[$key]) ? $_lang[$key] : ""; |
29 | 29 | break; |
30 | 30 | } |
31 | 31 | case ($action == 'setsetting' && !empty($key) && !empty($value)): { |
32 | - $sql = "REPLACE INTO " . $modx->getFullTableName("system_settings") . " (setting_name, setting_value) VALUES('{$key}', '{$value}');"; |
|
32 | + $sql = "REPLACE INTO ".$modx->getFullTableName("system_settings")." (setting_name, setting_value) VALUES('{$key}', '{$value}');"; |
|
33 | 33 | $str = "true"; |
34 | 34 | $modx->getDatabase()->query($sql); |
35 | 35 | $emptyCache = true; |
@@ -34,7 +34,7 @@ |
||
34 | 34 | $newCat = $modx->getDatabase()->escape($newCat); |
35 | 35 | $cats = $modx->getDatabase()->select('id', $modx->getFullTableName('categories'), "category='{$newCat}'"); |
36 | 36 | if ($cat = $modx->getDatabase()->getValue($cats)) { |
37 | - return (int)$cat; |
|
37 | + return (int) $cat; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | return 0; |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | -$userid = (int)$value; |
|
2 | +$userid = (int) $value; |
|
3 | 3 | if (!isset($modx->getModifiers()->cache['ui'][$userid])) { |
4 | 4 | if ($userid < 0) $user = $modx->getWebUserInfo(abs($userid)); |
5 | 5 | else $user = $modx->getUserInfo($userid); |
@@ -1,8 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | $userid = (int)$value; |
3 | 3 | if (!isset($modx->getModifiers()->cache['ui'][$userid])) { |
4 | - if ($userid < 0) $user = $modx->getWebUserInfo(abs($userid)); |
|
5 | - else $user = $modx->getUserInfo($userid); |
|
4 | + if ($userid < 0) { |
|
5 | + $user = $modx->getWebUserInfo(abs($userid)); |
|
6 | + } else { |
|
7 | + $user = $modx->getUserInfo($userid); |
|
8 | + } |
|
6 | 9 | $modx->getModifiers()->cache['ui'][$userid] = $user; |
7 | 10 | } else { |
8 | 11 | $user = $modx->getModifiers()->cache['ui'][$userid]; |
@@ -1,43 +1,43 @@ |
||
1 | 1 | <?php |
2 | -if(strpos($opt,',')) list($limit,$delim) = explode(',', $opt); |
|
3 | -elseif(preg_match('/^[1-9][0-9]*$/',$opt)) {$limit=$opt;$delim='';} |
|
4 | -else {$limit=124;$delim='';} |
|
2 | +if (strpos($opt, ',')) list($limit, $delim) = explode(',', $opt); |
|
3 | +elseif (preg_match('/^[1-9][0-9]*$/', $opt)) {$limit = $opt; $delim = ''; } |
|
4 | +else {$limit = 124; $delim = ''; } |
|
5 | 5 | |
6 | -if($delim==='') $delim = $modx->config['manager_language']==='japanese-utf8' ? '。' : '.'; |
|
7 | -$limit = (int)$limit; |
|
6 | +if ($delim === '') $delim = $modx->config['manager_language'] === 'japanese-utf8' ? '。' : '.'; |
|
7 | +$limit = (int) $limit; |
|
8 | 8 | |
9 | 9 | $content = $modx->getModifiers()->parseDocumentSource($value); |
10 | 10 | |
11 | 11 | $content = strip_tags($content); |
12 | 12 | |
13 | -$content = str_replace(array("\r\n","\r","\n","\t",' '),' ',$content); |
|
14 | -if(preg_match('/\s+/',$content)) |
|
15 | - $content = preg_replace('/\s+/',' ',$content); |
|
13 | +$content = str_replace(array("\r\n", "\r", "\n", "\t", ' '), ' ', $content); |
|
14 | +if (preg_match('/\s+/', $content)) |
|
15 | + $content = preg_replace('/\s+/', ' ', $content); |
|
16 | 16 | $content = trim($content); |
17 | 17 | |
18 | 18 | $pos = $modx->getModifiers()->strpos($content, $delim); |
19 | 19 | |
20 | -if($pos!==false && $pos<$limit) { |
|
20 | +if ($pos !== false && $pos < $limit) { |
|
21 | 21 | $_ = explode($delim, $content); |
22 | 22 | $text = ''; |
23 | - foreach($_ as $v) { |
|
24 | - if($limit <= $modx->getModifiers()->strlen($text.$v.$delim)) break; |
|
23 | + foreach ($_ as $v) { |
|
24 | + if ($limit <= $modx->getModifiers()->strlen($text.$v.$delim)) break; |
|
25 | 25 | $text .= $v.$delim; |
26 | 26 | } |
27 | - if($text) $content = $text; |
|
27 | + if ($text) $content = $text; |
|
28 | 28 | } |
29 | 29 | |
30 | -if($limit<$modx->getModifiers()->strlen($content) && strpos($content,' ')!==false) { |
|
30 | +if ($limit < $modx->getModifiers()->strlen($content) && strpos($content, ' ') !== false) { |
|
31 | 31 | $_ = explode(' ', $content); |
32 | 32 | $text = ''; |
33 | - foreach($_ as $v) { |
|
34 | - if($limit <= $modx->getModifiers()->strlen($text.$v.' ')) break; |
|
35 | - $text .= $v . ' '; |
|
33 | + foreach ($_ as $v) { |
|
34 | + if ($limit <= $modx->getModifiers()->strlen($text.$v.' ')) break; |
|
35 | + $text .= $v.' '; |
|
36 | 36 | } |
37 | - if($text!=='') $content = $text; |
|
37 | + if ($text !== '') $content = $text; |
|
38 | 38 | } |
39 | 39 | |
40 | -if($limit < $modx->getModifiers()->strlen($content)) $content = $modx->getModifiers()->substr($content, 0, $limit); |
|
41 | -if($modx->getModifiers()->substr($content,-1)==$delim) $content = rtrim($content,$delim) . $delim; |
|
40 | +if ($limit < $modx->getModifiers()->strlen($content)) $content = $modx->getModifiers()->substr($content, 0, $limit); |
|
41 | +if ($modx->getModifiers()->substr($content, -1) == $delim) $content = rtrim($content, $delim).$delim; |
|
42 | 42 | |
43 | 43 | return $content; |
@@ -1,9 +1,11 @@ discard block |
||
1 | 1 | <?php |
2 | -if(strpos($opt,',')) list($limit,$delim) = explode(',', $opt); |
|
3 | -elseif(preg_match('/^[1-9][0-9]*$/',$opt)) {$limit=$opt;$delim='';} |
|
4 | -else {$limit=124;$delim='';} |
|
2 | +if(strpos($opt,',')) { |
|
3 | + list($limit,$delim) = explode(',', $opt); |
|
4 | +} elseif(preg_match('/^[1-9][0-9]*$/',$opt)) {$limit=$opt;$delim='';} else {$limit=124;$delim='';} |
|
5 | 5 | |
6 | -if($delim==='') $delim = $modx->config['manager_language']==='japanese-utf8' ? '。' : '.'; |
|
6 | +if($delim==='') { |
|
7 | + $delim = $modx->config['manager_language']==='japanese-utf8' ? '。' : '.'; |
|
8 | +} |
|
7 | 9 | $limit = (int)$limit; |
8 | 10 | |
9 | 11 | $content = $modx->getModifiers()->parseDocumentSource($value); |
@@ -11,8 +13,9 @@ discard block |
||
11 | 13 | $content = strip_tags($content); |
12 | 14 | |
13 | 15 | $content = str_replace(array("\r\n","\r","\n","\t",' '),' ',$content); |
14 | -if(preg_match('/\s+/',$content)) |
|
16 | +if(preg_match('/\s+/',$content)) { |
|
15 | 17 | $content = preg_replace('/\s+/',' ',$content); |
18 | +} |
|
16 | 19 | $content = trim($content); |
17 | 20 | |
18 | 21 | $pos = $modx->getModifiers()->strpos($content, $delim); |
@@ -21,23 +24,35 @@ discard block |
||
21 | 24 | $_ = explode($delim, $content); |
22 | 25 | $text = ''; |
23 | 26 | foreach($_ as $v) { |
24 | - if($limit <= $modx->getModifiers()->strlen($text.$v.$delim)) break; |
|
27 | + if($limit <= $modx->getModifiers()->strlen($text.$v.$delim)) { |
|
28 | + break; |
|
29 | + } |
|
25 | 30 | $text .= $v.$delim; |
26 | 31 | } |
27 | - if($text) $content = $text; |
|
28 | -} |
|
32 | + if($text) { |
|
33 | + $content = $text; |
|
34 | + } |
|
35 | + } |
|
29 | 36 | |
30 | 37 | if($limit<$modx->getModifiers()->strlen($content) && strpos($content,' ')!==false) { |
31 | 38 | $_ = explode(' ', $content); |
32 | 39 | $text = ''; |
33 | 40 | foreach($_ as $v) { |
34 | - if($limit <= $modx->getModifiers()->strlen($text.$v.' ')) break; |
|
41 | + if($limit <= $modx->getModifiers()->strlen($text.$v.' ')) { |
|
42 | + break; |
|
43 | + } |
|
35 | 44 | $text .= $v . ' '; |
36 | 45 | } |
37 | - if($text!=='') $content = $text; |
|
38 | -} |
|
46 | + if($text!=='') { |
|
47 | + $content = $text; |
|
48 | + } |
|
49 | + } |
|
39 | 50 | |
40 | -if($limit < $modx->getModifiers()->strlen($content)) $content = $modx->getModifiers()->substr($content, 0, $limit); |
|
41 | -if($modx->getModifiers()->substr($content,-1)==$delim) $content = rtrim($content,$delim) . $delim; |
|
51 | +if($limit < $modx->getModifiers()->strlen($content)) { |
|
52 | + $content = $modx->getModifiers()->substr($content, 0, $limit); |
|
53 | +} |
|
54 | +if($modx->getModifiers()->substr($content,-1)==$delim) { |
|
55 | + $content = rtrim($content,$delim) . $delim; |
|
56 | +} |
|
42 | 57 | |
43 | 58 | return $content; |
@@ -2,22 +2,22 @@ |
||
2 | 2 | $userID = abs($modx->getLoginUserID('web')); |
3 | 3 | $modx->qs_hash = md5($modx->qs_hash."^{$userID}^"); |
4 | 4 | |
5 | -$groupNames = ($this->strlen($opt) > 0 ) ? explode(',',$opt) : array(); |
|
5 | +$groupNames = ($this->strlen($opt) > 0) ? explode(',', $opt) : array(); |
|
6 | 6 | |
7 | 7 | // if $groupNames is not an array return false |
8 | -if(!is_array($groupNames)) return 0; |
|
8 | +if (!is_array($groupNames)) return 0; |
|
9 | 9 | |
10 | 10 | // Creates an array with all webgroups the user id is in |
11 | 11 | if (isset($modx->getModifiers()->cache['mo'][$userID])) $grpNames = $modx->getModifiers()->cache['mo'][$userID]; |
12 | 12 | else { |
13 | - $from = sprintf("[+prefix+]webgroup_names wgn INNER JOIN [+prefix+]web_groups wg ON wg.webgroup=wgn.id AND wg.webuser='%s'",$userID); |
|
14 | - $rs = $modx->getDatabase()->select('wgn.name',$from); |
|
15 | - $modx->getModifiers()->cache['mo'][$userID] = $grpNames = $modx->getDatabase()->getColumn('name',$rs); |
|
13 | + $from = sprintf("[+prefix+]webgroup_names wgn INNER JOIN [+prefix+]web_groups wg ON wg.webgroup=wgn.id AND wg.webuser='%s'", $userID); |
|
14 | + $rs = $modx->getDatabase()->select('wgn.name', $from); |
|
15 | + $modx->getModifiers()->cache['mo'][$userID] = $grpNames = $modx->getDatabase()->getColumn('name', $rs); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | // Check if a supplied group matches a webgroup from the array we just created |
19 | -foreach($groupNames as $k=>$v) { |
|
20 | - if(in_array(trim($v),$grpNames)) return 1; |
|
19 | +foreach ($groupNames as $k=>$v) { |
|
20 | + if (in_array(trim($v), $grpNames)) return 1; |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | // If we get here the above logic did not find a match, so return false |
@@ -5,11 +5,14 @@ discard block |
||
5 | 5 | $groupNames = ($this->strlen($opt) > 0 ) ? explode(',',$opt) : array(); |
6 | 6 | |
7 | 7 | // if $groupNames is not an array return false |
8 | -if(!is_array($groupNames)) return 0; |
|
8 | +if(!is_array($groupNames)) { |
|
9 | + return 0; |
|
10 | +} |
|
9 | 11 | |
10 | 12 | // Creates an array with all webgroups the user id is in |
11 | -if (isset($modx->getModifiers()->cache['mo'][$userID])) $grpNames = $modx->getModifiers()->cache['mo'][$userID]; |
|
12 | -else { |
|
13 | +if (isset($modx->getModifiers()->cache['mo'][$userID])) { |
|
14 | + $grpNames = $modx->getModifiers()->cache['mo'][$userID]; |
|
15 | +} else { |
|
13 | 16 | $from = sprintf("[+prefix+]webgroup_names wgn INNER JOIN [+prefix+]web_groups wg ON wg.webgroup=wgn.id AND wg.webuser='%s'",$userID); |
14 | 17 | $rs = $modx->getDatabase()->select('wgn.name',$from); |
15 | 18 | $modx->getModifiers()->cache['mo'][$userID] = $grpNames = $modx->getDatabase()->getColumn('name',$rs); |
@@ -17,8 +20,10 @@ discard block |
||
17 | 20 | |
18 | 21 | // Check if a supplied group matches a webgroup from the array we just created |
19 | 22 | foreach($groupNames as $k=>$v) { |
20 | - if(in_array(trim($v),$grpNames)) return 1; |
|
21 | -} |
|
23 | + if(in_array(trim($v),$grpNames)) { |
|
24 | + return 1; |
|
25 | + } |
|
26 | + } |
|
22 | 27 | |
23 | 28 | // If we get here the above logic did not find a match, so return false |
24 | 29 | return 0; |