[2] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare API - Matrix View Generator * |
---|
| 4 | * This file written by Marc Logemann <loge@phpgroupware.org> * |
---|
| 5 | * class for creating matrix like timeframes for items * |
---|
| 6 | * * |
---|
| 7 | * this matrix is having the days of actual month in the x-axis and the * |
---|
| 8 | * items, which could be projects, in the y-axis. * |
---|
| 9 | * You will see a top-down view of all items and their associated * |
---|
| 10 | * timeframes. You probably saw this in projectmanagement apps * |
---|
| 11 | * * |
---|
| 12 | * Copyright (C) 2000, 2001 Marc Logemann * |
---|
| 13 | * -------------------------------------------------------------------------* |
---|
| 14 | * This library is part of the eGroupWare API * |
---|
| 15 | * http://www.egroupware.org/api * |
---|
| 16 | * ------------------------------------------------------------------------ * |
---|
| 17 | * This library is free software; you can redistribute it and/or modify it * |
---|
| 18 | * under the terms of the GNU Lesser General Public License as published by * |
---|
| 19 | * the Free Software Foundation; either version 2.1 of the License, * |
---|
| 20 | * or any later version. * |
---|
| 21 | * This library is distributed in the hope that it will be useful, but * |
---|
| 22 | * WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
---|
| 24 | * See the GNU Lesser General Public License for more details. * |
---|
| 25 | * You should have received a copy of the GNU Lesser General Public License * |
---|
| 26 | * along with this library; if not, write to the Free Software Foundation, * |
---|
| 27 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
| 28 | \**************************************************************************/ |
---|
| 29 | |
---|
| 30 | class matrixview |
---|
| 31 | { |
---|
| 32 | var $sumdays = 0; |
---|
| 33 | var $month = 0; |
---|
| 34 | var $monthname = ''; |
---|
| 35 | var $year = 0; |
---|
| 36 | var $day = 0; |
---|
| 37 | |
---|
| 38 | var $items_content = array(); |
---|
| 39 | var $items_count = 0; |
---|
| 40 | |
---|
| 41 | var $arr_second_dim = 0; |
---|
| 42 | var $image1pix = 'images/pix.gif'; |
---|
| 43 | |
---|
| 44 | var $color_headerfield = '#FFFF33'; |
---|
| 45 | var $color_emptyfield = '#CCCCCC'; |
---|
| 46 | |
---|
| 47 | var $selection = 1; |
---|
| 48 | |
---|
| 49 | /** |
---|
| 50 | * |
---|
| 51 | * construtor: graphview class |
---|
| 52 | * |
---|
| 53 | * constructor waits for the desired month in |
---|
| 54 | * integer presentation and the desired year also |
---|
| 55 | * in integer presentation 4 digits (ex. 2001) |
---|
| 56 | * |
---|
| 57 | * @param int month (for example: 02) |
---|
| 58 | * @param int year (for example: 2001) |
---|
| 59 | * |
---|
| 60 | */ |
---|
| 61 | function matrixview ($month_int = 0, $year_int = 0) |
---|
| 62 | { |
---|
[7655] | 63 | for($i;$i<32;++$i) |
---|
[2] | 64 | { |
---|
| 65 | if(checkdate($month_int,$i,$year_int)) $days++; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | $this->month = $month_int; |
---|
| 69 | $this->year = $year_int; |
---|
| 70 | $this->set1PixelGif($GLOBALS['phpgw']->common->get_image_path('todo').'/pix.gif'); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | /** |
---|
| 74 | * |
---|
| 75 | * set a Period for a specified item |
---|
| 76 | * |
---|
| 77 | * setting a period for an element means to define |
---|
| 78 | * a fromDate and and a toDate together with the |
---|
| 79 | * item itself. This will store a timeframe associated |
---|
| 80 | * with an item for later usage |
---|
| 81 | * |
---|
| 82 | * @param string item for the timeframe |
---|
| 83 | * @param date fromdate in format yyyymmdd |
---|
| 84 | * @param date todate in format yyyymmdd |
---|
| 85 | * |
---|
| 86 | * @return boolean false if item cannot be saved |
---|
| 87 | * otherwise true |
---|
| 88 | */ |
---|
| 89 | function setPeriod ($item, $fromdate, $todate, $color='#990033') |
---|
| 90 | { |
---|
| 91 | $fyear = substr($fromdate,0,4); |
---|
| 92 | $fmonth = substr($fromdate,4,2); |
---|
| 93 | $fday = substr($fromdate,6,2); |
---|
| 94 | |
---|
| 95 | $tyear = substr($todate,0,4); |
---|
| 96 | $tmonth = substr($todate,4,2); |
---|
| 97 | $tday = substr($todate,6,2); |
---|
| 98 | |
---|
| 99 | if(mktime(0,0,0, $tmonth, $tday, $tyear) < mktime(0,0,0, $this->month+1,0,$this->year)) |
---|
| 100 | { |
---|
| 101 | $this->day = $tday; |
---|
| 102 | } |
---|
| 103 | else |
---|
| 104 | { |
---|
| 105 | $dinfo = getdate(mktime(0,0,0, $this->month+1,0,$this->year)); |
---|
[7681] | 106 | $this->day = $dinfo['mday']; |
---|
[2] | 107 | } |
---|
| 108 | |
---|
| 109 | $go = 1; |
---|
| 110 | $i = 0; |
---|
| 111 | $z = 0; |
---|
| 112 | |
---|
| 113 | while($go == 1) |
---|
| 114 | { |
---|
| 115 | // calculates fromdate |
---|
| 116 | // echo date("d/m/Y", mktime(0,0,0, $fmonth, $fday+$i, $fyear)); echo "<br>"; |
---|
| 117 | |
---|
| 118 | $datinfo = getdate(mktime(0,0,0, $fmonth, $fday+$i, $fyear)); |
---|
| 119 | |
---|
| 120 | if($datinfo['mon'] == $this->month |
---|
| 121 | && $datinfo['year'] == $this->year |
---|
| 122 | && $datinfo['mday'] <= $this->day) |
---|
| 123 | { |
---|
| 124 | $t = $datinfo['mday']; |
---|
| 125 | $this->items_content[$this->items_count][$t] = 'x'; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | if (mktime(0,0,0, $fmonth, $fday+$i, $fyear) >= mktime(0,0,0, $this->month+1, 0, $this->year) || |
---|
| 129 | mktime(0,0,0, $fmonth, $fday+$i, $fyear) >= mktime(0,0,0, $tmonth, $tday, $tyear)) |
---|
| 130 | { |
---|
| 131 | $go = 0; |
---|
| 132 | } |
---|
[7655] | 133 | ++$i; |
---|
[2] | 134 | } |
---|
| 135 | |
---|
| 136 | $this->items_content[$this->items_count][0] = $item; |
---|
| 137 | $this->items_color[$this->items_count] = $color; |
---|
| 138 | |
---|
| 139 | // increase number of items in two-dimensional array |
---|
| 140 | $this->items_count++; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | /** |
---|
| 144 | * |
---|
| 145 | * sets the color for empty dayfields |
---|
| 146 | * |
---|
| 147 | * @param string color in hexadecimal (ex. "#336699") |
---|
| 148 | */ |
---|
| 149 | function setEmptyFieldColor ($color) |
---|
| 150 | { |
---|
| 151 | $this->color_emptyfield=$color; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | /** |
---|
| 155 | * |
---|
| 156 | * sets the color for calendar day fields |
---|
| 157 | * |
---|
| 158 | * @param string color in hexadecimal (ex. "#336699") |
---|
| 159 | */ |
---|
| 160 | function setHeaderFieldColor ($color) |
---|
| 161 | { |
---|
| 162 | $this->color_headerfield=$color; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | /** |
---|
| 166 | * |
---|
| 167 | * sets a new path for 1pixel (pix.gif) gif needed for the table |
---|
| 168 | * default is set actual script dir + /images |
---|
| 169 | * |
---|
| 170 | * @param string path and name to 1pixel gif |
---|
| 171 | */ |
---|
| 172 | function set1PixelGif ($filepath) |
---|
| 173 | { |
---|
| 174 | $this->image1pix=$filepath; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | /** |
---|
| 178 | * |
---|
| 179 | * disable selection of new timeframe |
---|
| 180 | * |
---|
| 181 | */ |
---|
| 182 | function disableSelection () |
---|
| 183 | { |
---|
| 184 | $this->selection=0; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | /** |
---|
| 188 | * |
---|
| 189 | * return the html code for the matrix |
---|
| 190 | * |
---|
| 191 | * will return the complete html code for the matrix. |
---|
| 192 | * In the calling program you can do some other |
---|
| 193 | * operations on it, because it wont be echoed directly |
---|
| 194 | * |
---|
| 195 | * @return string html code for the matrix |
---|
| 196 | */ |
---|
| 197 | function out($form_link) |
---|
| 198 | { |
---|
| 199 | // get days of desired month (month submitted in constructor) |
---|
| 200 | |
---|
| 201 | $in = getdate(mktime(0,0,0, $this->month+1,0,$this->year)); |
---|
[7681] | 202 | $this->sumdays = $in['mday']; |
---|
| 203 | $this->monthname = $in['month']; |
---|
[2] | 204 | |
---|
| 205 | $this->out_monthyear($form_link); |
---|
| 206 | |
---|
| 207 | echo '<div align="center">' . "\n"; |
---|
| 208 | echo '<table border="0">' . "\n"; |
---|
| 209 | |
---|
| 210 | $this->out_header(); |
---|
| 211 | |
---|
| 212 | // loop through number of items |
---|
[7655] | 213 | for($z=0;$z<$this->items_count;++$z) |
---|
[2] | 214 | { |
---|
| 215 | // seperate color and name from first array element |
---|
| 216 | |
---|
| 217 | $itemname = $this->items_content[$z][0]; |
---|
| 218 | $itemcolor = $this->items_color[$z]; |
---|
| 219 | |
---|
| 220 | echo '<tr>' . "\n"; |
---|
| 221 | echo '<td>' . $itemname . '</td>' . "\n"; |
---|
| 222 | |
---|
| 223 | // loop through days of desired month |
---|
[7655] | 224 | for($r=1;$r<$this->sumdays+1;++$r) |
---|
[2] | 225 | { |
---|
| 226 | if($this->items_content[$z][$r] == 'x') |
---|
| 227 | { |
---|
| 228 | $color = $itemcolor; |
---|
| 229 | } |
---|
| 230 | else |
---|
| 231 | { |
---|
| 232 | $color = $this->color_emptyfield; |
---|
| 233 | } |
---|
| 234 | echo '<td bgcolor="' . $color . '"> </td>' . "\n"; |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | echo '</tr>' . "\n"; |
---|
| 238 | $this->out_ruler(); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | echo '</table>'; |
---|
| 242 | echo '</div>' . "\n"; |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | /** |
---|
| 246 | * |
---|
| 247 | * private class for out method |
---|
| 248 | * |
---|
| 249 | * should not be used from external |
---|
| 250 | * |
---|
| 251 | */ |
---|
| 252 | function out_header () |
---|
| 253 | { |
---|
| 254 | echo '<tr>' . "\n"; |
---|
| 255 | echo '<td height="1" colspan="'; echo $this->sumdays+1; echo '" bgcolor="black"><img src="' . $this->image1pix . '"></td>' . "\n"; |
---|
| 256 | echo '</tr>' . "\n"; |
---|
| 257 | echo '<tr>' . "\n"; |
---|
| 258 | echo '<td>' . lang('Title') . '</td>' . "\n"; |
---|
| 259 | |
---|
[7655] | 260 | for($i=1;$i<$this->sumdays+1;++$i) |
---|
[2] | 261 | { |
---|
| 262 | echo '<td bgcolor="'; echo $this->color_headerfield; echo '">' . sprintf("%02d",$i) . '</td>' . "\n"; |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | echo '</tr>' . "\n"; |
---|
| 266 | echo '<tr>' . "\n"; |
---|
| 267 | echo '<td height="1" colspan="'; echo $this->sumdays+1; echo '" bgcolor="black"><img src="' . $this->image1pix . '"></td>' . "\n"; |
---|
| 268 | echo '</tr>' . "\n"; |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | /** |
---|
| 272 | * |
---|
| 273 | * private class for out method |
---|
| 274 | * |
---|
| 275 | * should not be used from external |
---|
| 276 | * |
---|
| 277 | */ |
---|
| 278 | function out_ruler () |
---|
| 279 | { |
---|
| 280 | echo '<tr>' . "\n"; |
---|
| 281 | echo '<td colspan="'; echo $this->sumdays+1; echo '" bgcolor="#999999"><img src="' . $this->image1pix .'"></td>' . "\n"; |
---|
| 282 | echo '</tr>' . "\n"; |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | /** |
---|
| 286 | * |
---|
| 287 | * private class for out method |
---|
| 288 | * |
---|
| 289 | * should not be used from external |
---|
| 290 | * |
---|
| 291 | */ |
---|
| 292 | function out_monthyear($form_link) |
---|
| 293 | { |
---|
| 294 | echo '<form action="' . $form_link . '" method="post">' . "\n"; |
---|
| 295 | echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">' . "\n"; |
---|
| 296 | echo '<tr>' . "\n"; |
---|
| 297 | echo '<td align="center"><h2>'; echo lang($this->monthname); echo ' '; echo $this->year; echo '</h2></td>' . "\n"; |
---|
| 298 | |
---|
| 299 | if($this->selection == 1) |
---|
| 300 | { |
---|
| 301 | echo '<td align="right">' . "\n"; |
---|
| 302 | echo '<select name="month"'; |
---|
| 303 | |
---|
[7655] | 304 | for($i=0;$i<13;++$i) |
---|
[2] | 305 | { |
---|
| 306 | if ($this->month == $i) |
---|
| 307 | { |
---|
| 308 | $sel = ' selected'; |
---|
| 309 | } |
---|
| 310 | else |
---|
| 311 | { |
---|
| 312 | unset($sel); |
---|
| 313 | } |
---|
| 314 | echo '<option value="' . $i . '"' . $sel . '>' . $i . '</option>'; |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | echo '</select>' . "\n"; |
---|
| 318 | echo '<select name="year"'; |
---|
| 319 | |
---|
[7655] | 320 | for($i = date('Y') -2;$i<date('Y')+5;++$i) |
---|
[2] | 321 | { |
---|
| 322 | if($this->year == $i) |
---|
| 323 | { |
---|
| 324 | $sel = ' selected'; |
---|
| 325 | } |
---|
| 326 | else |
---|
| 327 | { |
---|
| 328 | unset($sel); |
---|
| 329 | } |
---|
| 330 | echo '<option value="' . $i . '"' . $sel . '>' . $i .'</option>'; |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | echo '</select>' . "\n"; |
---|
| 334 | echo ' <input type="submit" name="selection" value="' . lang('Filter') . '"> '; |
---|
| 335 | echo '</td>' . "\n"; |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | echo '</tr>' . "\n"; |
---|
| 339 | echo '</table>' . "\n"; |
---|
| 340 | echo '</form>' . "\n"; |
---|
| 341 | } |
---|
| 342 | } |
---|
| 343 | ?> |
---|