| [ PHPXref.com ] | [ Generated: Sun Jul 20 20:47:44 2008 ] | [ TUTOS 1.2 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Copyright 1999 - 2004 by Gero Kohnert 4 * 5 * CVS Info: $Id: timetrack.pinc,v 1.71.2.2 2004/09/15 16:17:48 gokohnert Exp $ 6 * $Author: gokohnert $ 7 * 8 * @modulegroup timetrack 9 * @package timetrack 10 */ 11 12 13 define ('TT_STATE_CHECKED',1); 14 define ('TT_STATE_BILLED',2); 15 define ('TT_STATE_PAYED',3); 16 define ('TT_STATE_NOBILL',4); 17 18 /** 19 * Read a summary of times for given object 20 */ 21 function readTimetrackSum (&$obj) { 22 global $table; 23 24 $obj->timetracksum = 0; 25 $q = "SELECT SUM(volume) as XX FROM ". $obj->dbconn->prefix .$table['timetrack'][name]; 26 $pre = " WHERE "; 27 if ( $obj->getType() == "address" ) { 28 $q .= $pre . " adr_id =". $obj->id ; 29 } else if ( $obj->getType() == "user" ) { 30 $q .= $pre . " adr_id =". $obj->id ; 31 } else if ( $obj->getType() == "team" ) { 32 $q .= $pre . " adr_id =". $obj->id ; 33 } else { 34 $q .= $pre . " link_id =". $obj->id ; 35 } 36 $r = $obj->dbconn->Exec($q); 37 $n = $r->numrows(); 38 if ( $n == 0 ) { 39 return; 40 } 41 $obj->timetracksum = $r->get(0,"XX"); 42 $r->free(); 43 return; 44 } 45 46 /** 47 * Compute the amount of work done by $address on $task 48 * 49 * FIXME : add some time schedule restriction 50 */ 51 function computeWorkedHours(&$address, &$task) { 52 global $table; 53 54 $sum = 0; 55 56 $q = 57 "SELECT SUM(volume) as XX FROM ". $task->dbconn->prefix .$table['timetrack'][name]. 58 " WHERE adr_id = ". $address->id. " AND link_id = ". $task->id; 59 60 $r = $task->dbconn->Exec($q); 61 $n = $r->numrows(); 62 if ( $n == 0 ) { 63 return $sum; 64 } 65 $sum = $r->get(0,"XX"); 66 $r->free(); 67 68 return $sum == "" ? 0 : $sum; 69 } 70 71 /** 72 * A fraction of a timetrack 73 * @package timetrack 74 */ 75 class timetrack extends tutos_base { 76 /* --------------------------------------------------------------------------- 77 */ 78 function timetrack(&$dbconn) { 79 global $tutos,$current_user,$table; 80 81 $this->init($dbconn); 82 83 $this->wid = $current_user->id; 84 $this->worker = $current_user; 85 $this->link_id = -1; 86 $this->ref = -1; 87 $this->desc = ""; 88 $this->volume = 0.0; 89 $this->volume_todo = -1; 90 $this->wday = new DateTime(); 91 $this->creation = new DateTime(); 92 $this->t_start = new DateTime(0); 93 $this->t_end = new DateTime(0); 94 # number of invoice 95 $this->invoice = -1; 96 $this->currency = $tutos[currencies][0]; 97 # Costs per hour ("" == default) 98 $this->cph = 0.0; 99 # State (-1 == unknown , 1 == checke 2 == billed) 100 $this->state = -1; 101 $this->inv_id = -1; 102 103 $this->tablename = $this->dbconn->prefix .$table['timetrack'][name]; 104 } 105 /** 106 * read a resultset 107 */ 108 function read_result (&$r, $pos ) { 109 global $g_hash; 110 111 $this->id = $r->get($pos, "id"); 112 $this->wid = $r->get($pos, "adr_id"); 113 $this->worker = getObject($this->dbconn,$this->wid); 114 $this->link_id = $r->get($pos, "link_id"); 115 $this->ref = getObject($this->dbconn,$this->link_id); 116 $this->desc = $r->get($pos, "description"); 117 $this->volume = $r->get($pos, "volume"); 118 $this->volume_todo = $r->get($pos, "volume_todo"); 119 $this->state = (integer)$r->get($pos, "state"); 120 $this->cph = $r->get($pos, "cph"); 121 $this->currency = $r->get($pos, "currency"); 122 $this->inv_id = $r->get($pos, "invoice"); 123 $this->creation->setDateTime($r->get($pos, "creation")); 124 $this->wday->setDateTime($r->get($pos, "vtime")); 125 $this->t_start->setDateTime($r->get($pos, "t_start")); 126 $this->t_end->setDateTime($r->get($pos, "t_end")); 127 128 if ( $this->inv_id == "" ) { 129 $this->inv_id = -1; 130 $this->invoice = -1; 131 } 132 if ( $this->state == "" ) { 133 $this->state = -1; 134 } 135 if ( $this->cph == "" ) { 136 $this->cph = 0.00; 137 } 138 139 $this->creator = getObject($this->dbconn,$r->get($pos, "creator")); 140 141 parent::read_result($r,$pos); 142 return; 143 } 144 /** 145 * get a list of possible new parents 146 */ 147 function read_relations ( ) { 148 global $lang,$current_user; 149 150 151 $this->plist = array(); 152 if ($this->ref != -1) { 153 # Read possible new parents 154 $this->plist = $this->ref->getNeighbours(); 155 } 156 # a timetrack object could be attached to all projects and tasks where we play a role 157 if ( $current_user->feature_ok(useprojects,PERM_SEE) ) { 158 require_once 'product.pinc'; 159 $q = "SELECT p.* from ". $this->dbconn->prefix."products p,". $this->dbconn->prefix ."projectroles r "; 160 $pre = " WHERE "; 161 if ($this->worker->id > 0) { 162 $q .= $pre ." r.adr_id in(". $this->worker->id; 163 $q .= " ) "; 164 $pre = " AND "; 165 } 166 $q .= $pre ." r.pro_id = p.id"; 167 $q .= " AND p.state != ".PROD_STATE_CANCEL; 168 $q .= " AND p.state != ".PROD_STATE_QCANCEL; 169 $q .= " order by p.name"; 170 $result = $this->dbconn->Exec($q); 171 $n = $result->numrows(); 172 $a = 0; 173 # echo $n." ".$q; 174 while ( $a < $n ) { 175 $p = new product($this->dbconn); 176 $p->read_result($result,$a); 177 $a++; 178 if ( $p->use_ok()) { 179 $this->plist[$p->id] = &$p; 180 } 181 unset($p); 182 } 183 $result->free(); 184 } 185 if ( $current_user->feature_ok(usetaskmanagement,PERM_SEE) ) { 186 $q = "SELECT t.* from ". $this->dbconn->prefix."tasks t,". $this->dbconn->prefix ."taskworker w "; 187 $pre = " WHERE "; 188 if ($this->worker->id > 0) { 189 $q .= $pre ." w.w_id in(". $this->worker->id; 190 $q .= " ) "; 191 $pre = " AND "; 192 } 193 $q .= $pre ." w.t_id = t.id"; 194 $q .= " AND t.status != ".TASK_FINISH; 195 $q .= " order by t.name"; 196 $result = $this->dbconn->Exec($q); 197 $n = $result->numrows(); 198 $a = 0; 199 # echo $n." ".$q; 200 while ( $a < $n ) { 201 $p = new task($this->dbconn); 202 $p->read_result($result,$a); 203 $a++; 204 if ( $p->use_ok()) { 205 $this->plist[$p->id] = &$p; 206 } 207 unset($p); 208 } 209 $result->free(); 210 } 211 } 212 /** 213 * set the Description 214 */ 215 function setDescription($value) { 216 $this->setStrField("desc",$value,"Description"); 217 return; 218 } 219 /** 220 * set the Worker 221 */ 222 function setWorker($name) { 223 $i = new tutos_address($this->dbconn); 224 $i = $i->read($name,$i); 225 226 if ( ($this->worker->id != $name) && ($i->id != -1) ) { 227 $this->modified[] = array ( "field" => "TimetrackWorker", "old" => $this->worker->id , "new" => $name ); 228 $this->worker = $i; 229 } 230 return; 231 } 232 /** 233 * set the workday 234 */ 235 function setWorkday(&$value) { 236 $this->setDateField("wday",$value,"Date"); 237 return; 238 } 239 /** 240 * set the Start 241 */ 242 function setStart(&$value) { 243 $this->setDateTimeField("t_start",$value,"AppStart"); 244 return; 245 } 246 /** 247 * set the End 248 */ 249 function setEnd(&$value) { 250 $this->setDateTimeField("t_end",$value,"AppEnd"); 251 return; 252 } 253 /** 254 * set the Currency 255 */ 256 function setCurrency($value) { 257 $this->setStrField("currency",$value,"Currency"); 258 return; 259 } 260 /** 261 * set the costs per hour 262 */ 263 function setCph($value) { 264 $this->setFloatField("cph",$value,"TTcph"); 265 return; 266 } 267 /** 268 * set the volume 269 */ 270 function setVolume($value) { 271 $this->setFloatField("volume",$value,"TaskVolumeDone"); 272 return; 273 } 274 /** 275 * set the volume todo 276 */ 277 function setVolumeTodo($value) { 278 $this->setFloatField("volume_todo",$value,"TaskVolumeTodo"); 279 return; 280 } 281 /** 282 * set the state 283 */ 284 function setState($value) { 285 $this->setIntField("state",$value,"TTState"); 286 return; 287 } 288 /** 289 * set the Invoice 290 */ 291 function setInvoice($value) { 292 $this->setIntField("inv_id",$value,"Invoice"); 293 return; 294 } 295 /** 296 * set the Invoice 297 */ 298 function setReference($value) { 299 $this->setIntField("link_id",$value,"TimetrackRef"); 300 return; 301 } 302 /** 303 * Save Time Fraction to DB 304 * 305 * The norec parameter allows to create a timetrack from task.pink 306 * without re entrance problems that may occur when timetrack tries 307 * to save the ref task... 308 */ 309 function save($norec=0) { 310 global $table,$tutos, $lang, $current_user; 311 312 // We may have to compute the volume todo of this timetrack entry 313 // This is the same as the task volume todo 314 if( $this->volume_todo == -1 ) { 315 if (isset($this->ref->volume_todo) && ($this->ref->volume_todo != -1) ) { 316 $ref_todo = $this->ref->volume_todo; 317 } elseif (isset($this->ref->volume) && ($this->ref->volume != -1) ) { 318 // If no volume_todo has been set for the task, we consider 319 // the planned volume as the volume_todo 320 $ref_todo = $this->ref->volume; 321 } else { 322 // the diff will be zero 323 $ref_todo = $this->volume; 324 } 325 // And the calculated volume_todo is the volume todo before this 326 // timetrack entry, minus this timetrack entry volume... 327 $volume_todo = $ref_todo - $this->volume; 328 } else { 329 // If a volume has been entered, we then just take it 330 $volume_todo = $this->volume_todo; 331 } 332 $msg = ""; 333 $q = new query($this->dbconn); 334 $q->setTable($this->tablename); 335 $q->addFV("link_id",$this->link_id,""); 336 $q->addFV("adr_id",$this->worker->id,""); 337 $q->addFV("volume",$this->volume,"FLOAT"); 338 $q->addFV("volume_todo",$volume_todo,"FLOAT"); 339 $q->addFV("description",$this->desc,"STRING",$table['timetrack']['description'][size]); 340 $q->addFV("vtime",$this->wday,"DATETIME"); 341 $q->addFV("state",$this->state,""); 342 $q->addFV("invoice",$this->inv_id,""); 343 $q->addFV("cph",$this->cph,"FLOAT"); 344 $q->addFV("currency",$this->currency,"STRING",4); 345 $q->addFV("t_start",$this->t_start,"DATETIME"); 346 $q->addFV("t_end",$this->t_end,"DATETIME"); 347 $this->save_custom_fields($q); 348 349 if ( $this->id < 0 ) { 350 $this->modified = array(); 351 if ( isset($this->newid) ) { 352 $this->id = $this->newid; 353 $q->addFV("id",$this->id,""); 354 } else { 355 $this->id = $q->addFV("id",-1,"NEXTID"); 356 acl_default($this,$current_user); 357 # Prepare the history 358 $this->modified[] = array ( "field" => "TimetrackCreate" , 359 "old" => "" , 360 "new" => $this->volume, 361 "obj_id" => $this->link_id 362 ); 363 $this->modified[] = array ( "field" => "created" , 364 "old" => $this->getType() , 365 "new" => $this->id, 366 "obj_id" => $this->id 367 ); 368 } 369 $q->addFV("creation",$this->creation,"DATETIME"); 370 $q->addFV("creator",$this->creator,"OBJ"); 371 372 $query = $q->getInsert(); 373 } else { 374 $q->addWC("id",$this->id,""); 375 $query = $q->getUpdate(); 376 } 377 378 $this->dbconn->Exec($query); 379 if ( $norec == 0 && 380 ($this->ref != -1) && 381 ($this->ref->getType() == "task") ) { 382 if ( $this->ref->r_start->notime == 1 ) { 383 $this->ref->setRStart(new Datetime()); 384 } 385 386 // Task has to be considered running 387 if( $this->ref->state == TASK_PRE ) { 388 $this->ref->state = TASK_RUNNING; 389 } 390 // The volume todo has to be set on the task 391 $this->ref->setVolumeTodo($volume_todo); 392 393 $this->ref->save(); 394 } 395 $msg .= parent::save(); 396 397 return $msg; 398 } 399 /** 400 * delete timetrack entries for a object 401 */ 402 Function obj_delete(&$user,&$obj) { 403 global $table; 404 405 $msg = ""; 406 407 # FIXME (mybe we should rebook the efforts to the user himself) !! 408 $q = "DELETE FROM ". $obj->dbconn->prefix .$table['timetrack'][name]." WHERE link_id = ". $obj->id; 409 $obj->dbconn->Exec($q); 410 return $msg; 411 } 412 /** 413 * Delete Timetrack fraction from DB 414 */ 415 function delete() { 416 $msg = ""; 417 418 $q = "DELETE FROM ". $this->tablename ." WHERE id = ". $this->id; 419 $this->dbconn->Exec($q); 420 421 $this->modified[] = array ( "field" => "TimetrackDel" , 422 "old" => $this->volume , 423 "new" => "0", 424 "obj_id" => $this->link_id 425 ); 426 $msg .= parent::delete(); 427 428 return $msg; 429 } 430 /** 431 * Checks if the current user is allowed to delete this timetrack 432 */ 433 function del_ok () { 434 if ( $this->ref != -1 ) { 435 return $this->ref->del_ok(); 436 } else { 437 return 0; 438 } 439 } 440 /** 441 * 442 */ 443 function see_ok() { 444 if ( $this->ref != -1 ) { 445 return $this->ref->see_ok(); 446 } else { 447 return 0; 448 } 449 } 450 /** 451 * 452 */ 453 function mod_ok() { 454 if ( $this->ref != -1 ) { 455 return $this->ref->mod_ok(); 456 } else { 457 return 0; 458 } 459 } 460 /** 461 * Return a url that displays this timetrack fraction 462 */ 463 function getURL() { 464 return "timetrack_overview.php?id=". $this->id; 465 } 466 /** 467 * Return a url that allows modification of this timetrack fraction 468 */ 469 function getModURL() { 470 return "timetrack_new.php?id=". $this->id; 471 } 472 /** 473 * Return a url that deletes this timetrack fraction 474 */ 475 function getDelURL() { 476 return "timetrack_del.php?id=". $this->id; 477 } 478 /** 479 * Return a url that displays this timetrack fraction 480 */ 481 function getFullName() { 482 return $this->volume ."@" . $this->wday->getDate(); 483 } 484 /** 485 * Return a link to this timefragement 486 */ 487 function getLink($text = "") { 488 global $lang; 489 490 if ( empty($text) ) { 491 $text = $this->getFullName(); 492 } 493 if ( $this->see_ok() ) { 494 return makelink($this->getURL() , myentities($text) ,sprintf($lang['timetrack'] ." %s",$this->getFullName())); 495 } else { 496 return myentities($text); 497 } 498 } 499 /** 500 * Data of XML export 501 */ 502 function exportXML_body () { 503 $r = parent::exportXML_body(); 504 $r .= "<worker>". utf8_encode(htmlspecialchars($this->worker->id)) ."</worker>\n"; 505 if ( $this->worker->id != null ) { 506 $r .= "<workername>". utf8_encode(htmlspecialchars($this->worker->getFullName())) ."</workername>\n"; 507 } 508 $r .= "<reference>". utf8_encode(htmlspecialchars($this->ref->id)) ."</reference>\n"; 509 if ( $this->ref->id != null ) { 510 $r .= "<referencename>". utf8_encode(htmlspecialchars($this->ref->getFullName())) ."</referencename>\n"; 511 } 512 $r .= "<volume>". utf8_encode(htmlspecialchars($this->volume)) ."</volume>\n"; 513 $r .= "<volume_todo>". utf8_encode(htmlspecialchars($this->volume_todo)) ."</volume_todo>\n"; 514 if ( $this->t_start->notime != 1 ) { 515 $r .= "<t_start>". $this->t_start->exportXML_body() ."</t_start>\n"; 516 } 517 if ( $this->t_end->notime != 1 ) { 518 $r .= "<t_end>". $this->t_end->exportXML_body() ."</t_end>\n"; 519 } 520 $r .= "<description>". utf8_encode(htmlspecialchars($this->desc)) ."</description>\n"; 521 $r .= "<invoice>". utf8_encode(htmlspecialchars($this->invoice)) ."</invoice>\n"; 522 $r .= "<state>". utf8_encode(htmlspecialchars($this->state)) ."</state>\n"; 523 $r .= "<cph>". utf8_encode(htmlspecialchars($this->cph)) ."</cph>\n"; 524 $r .= "<cost>". utf8_encode(htmlspecialchars($this->cph * $this->volume)) ."</cost>\n"; 525 $r .= "<currency>". utf8_encode(htmlspecialchars($this->currency)) ."</currency>\n"; 526 if ( $this->wday->notime != 1 ) { 527 $r .= "<vtime>". $this->wday->exportXML_body() ."</vtime>\n"; 528 } 529 return $r; 530 } 531 /** 532 * Return a data as comma seperated values string 533 */ 534 function exportCSV() { 535 global $lang; 536 537 if ( $this->ref->id > 0 ) { 538 $r = $this->ref->getFullName(); 539 } else { 540 $r = $lang['HistoryDeleted']; 541 } 542 if ( $this->worker->id > 0 ) { 543 $w = $this->worker->getFullName(); 544 } else { 545 $w = $lang['HistoryDeleted']; 546 } 547 return $this->id .",\"". $w ."\",\"". $r ."\",\"". $this->desc ."\",". $this->volume .",". $this->cph .",\"". $this->currency ."\",". $this->state .",". $this->wday->getYYYYMMDD() ."\n"; 548 } 549 /** 550 * Transfer reference ids according to given table 551 */ 552 function transfer_ids (&$trans) { 553 if (isset($trans[$this->worker->id])) { 554 $this->worker->id = $trans[$this->worker->id]; 555 } 556 if (isset($trans[$this->inv_id])) { 557 $this->inv_id = $trans[$this->inv_id]; 558 } 559 if (isset($trans[$this->link_id])) { 560 $this->link_id = $trans[$this->link_id]; 561 } 562 return; 563 } 564 /** 565 * get the type of object 566 */ 567 function gettype () { 568 return "timetrack"; 569 } 570 /** 571 * get the type id of object 572 */ 573 function gettypeid () { 574 return usetimetrack; 575 } 576 /* --------------------------------------------------------------------------- 577 * The following methods are abstract factory functions for groups 578 * which handle the membership list of an object 579 * --------------------------------------------------------------------------- */ 580 /** 581 * Read a list of all timetrack elements 582 */ 583 function obj_read (&$obj) { 584 global $table; 585 586 if ( ! isset($obj->id) ) return; 587 588 $obj->ttlist = array(); 589 $q = "SELECT * from ". $obj->dbconn->prefix .$table['timetrack'][name]." where link_id = ". $obj->id ." order by vtime desc"; 590 $r = $obj->dbconn->Exec($q); 591 $n = $r->numrows(); 592 $a = 0; 593 while ($a < $n) { 594 $tt = new timetrack($obj->dbconn); 595 $tt->read_result($r,$a); 596 if ( $tt->see_ok() ) { 597 $obj->ttlist[$tt->id] = &$tt; 598 } 599 $a++; 600 unset($tt); 601 } 602 $r->free(); 603 return; 604 } 605 /** 606 * create a link where a timetrack for work on the given object could be added 607 */ 608 function getaddlink (&$user,&$obj,$text = "") { 609 global $lang; 610 611 if ( $obj == -1 ) return; 612 if (! is_object($obj) ) return; 613 if ( $obj->id == -1 ) return; 614 if (! $user->feature_ok(usetimetrack,PERM_NEW) ) return ""; 615 if (! $obj->use_ok() ) return ""; 616 617 if ($obj->gettype() == "product") { 618 if ($obj->state == PROD_STATE_CANCEL) return ""; 619 if ($obj->state == PROD_STATE_QCANCEL) return ""; 620 } 621 if ($obj->gettype() == "task") { 622 if ($obj->state == TASK_FINISH) return ""; 623 } 624 625 if ($user->id == $obj->id ) { 626 $x = array( url => "timetrack_new.php?mode=1&lid=". $obj->id, 627 confirm => false, 628 text => ($text == "" ? $lang['TTRecord']:$text), 629 info => $lang['TTRecord'], 630 category => array("timetrack","new","module") 631 ); 632 } else { 633 $x = array( url => "timetrack_new.php?lid=". $obj->id, 634 confirm => false, 635 text => ($text == "" ? $lang['TimetrackCreate']:$text), 636 info => sprintf($lang['TimetrackCreateI'], $obj->getFullName()), 637 category => array("timetrack","new","module") 638 ); 639 } 640 return $x; 641 } 642 /** 643 * create a link to a overview page 644 */ 645 function getSelectLink (&$user,$text = "") { 646 global $lang,$tutos; 647 if ( ! $user->feature_ok(usetimetrack,PERM_SEL) ) { 648 return; 649 } 650 return array( url => "timetrack_select.php", 651 image => timetrack::getHtmlIcon(), 652 text => ($text == "" ? $lang['Search']: $text), 653 info => $lang['SearchForTT'], 654 category => array("search","timetrack","obj") 655 ); 656 } 657 } 658 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |