Changeset 485 for trunk/phpbms/modules/base/include/notes.php
- Timestamp:
- 04/07/09 11:44:18 (3 years ago)
- Files:
-
- 1 modified
-
trunk/phpbms/modules/base/include/notes.php (modified) (36 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpbms/modules/base/include/notes.php
r351 r485 45 45 var $weekArray = array("First"=>"1", "Second"=>"2", "Third"=>"3", "Fourth"=>"4", "Last"=>"5"); 46 46 var $dayOfWeekArray = array(); 47 48 47 48 49 49 function notes($db,$tabledefid = 0,$backurl = NULL){ 50 50 … … 57 57 } 58 58 59 59 60 60 function showWeeklyOptions($therecord,$repeatbase){ 61 61 if($therecord["repeattype"] == "Weekly") … … 63 63 else 64 64 $daysSelected = array(strftime("%u",$repeatbase)); 65 65 66 66 $daysAvailable = array(7,1,2,3,4,5,6); 67 67 68 68 foreach($daysAvailable as $dayNum){ 69 69 $tempday = ($dayNum != 7)?($dayNum+1):(1); 70 ?><button id="dayOption<?php echo $dayNum?>" class="<?php 71 70 ?><button id="dayOption<?php echo $dayNum?>" class="<?php 71 72 72 if(in_array($dayNum,$daysSelected)) 73 echo "pressed"; 74 75 ?>Buttons" type="button" value="<?php echo $dayNum?>" onclick="daySelect(this)"><?php 76 73 echo "pressed"; 74 75 ?>Buttons" type="button" value="<?php echo $dayNum?>" onclick="daySelect(this)"><?php 76 77 77 echo nl_langinfo(constant("ABDAY_".$tempday)); 78 78 79 79 ?></button><?php 80 80 } 81 82 81 82 83 83 } 84 84 85 85 function showMonthlyOptions($therecord,$repeatbase){ 86 86 if($therecord["repeattype"] == "Monthly" && $therecord["repeateachlist"]) … … 88 88 else 89 89 $daysSelected = array(strftime("%e",$repeatbase)); 90 91 90 91 92 92 for($dayNum = 1; $dayNum <= 31; $dayNum++){ 93 ?><button id="monthDayOption<?php echo $dayNum?>" class="<?php 94 93 ?><button id="monthDayOption<?php echo $dayNum?>" class="<?php 94 95 95 if(in_array($dayNum,$daysSelected)) 96 echo "pressed"; 97 98 ?>Buttons monthDays" type="button" value="<?php echo $dayNum?>" onclick="monthDaySelect(this)" <?php 99 96 echo "pressed"; 97 98 ?>Buttons monthDays" type="button" value="<?php echo $dayNum?>" onclick="monthDaySelect(this)" <?php 99 100 100 if($therecord["repeatontheday"]) 101 101 echo 'disabled="disabled"'; 102 103 ?>><?php 104 102 103 ?>><?php 104 105 105 echo $dayNum; 106 106 107 107 ?></button><?php 108 108 if(($dayNum % 7) == 0) echo "<br />"; 109 } 110 109 } 110 111 111 }//end method 112 112 113 113 114 114 function showYearlyOptions($therecord,$repeatbase){ 115 115 if($therecord["repeattype"] == "Yearly") … … 117 117 else 118 118 $monthsSelected = array(date("n",$repeatbase)); 119 119 120 120 for($monthNum = 1; $monthNum <=12; $monthNum++){ 121 ?><button id="yearlyMonthOption<?php echo $monthNum?>" class="<?php 122 121 ?><button id="yearlyMonthOption<?php echo $monthNum?>" class="<?php 122 123 123 if(in_array($monthNum,$monthsSelected)) 124 echo "pressed"; 125 126 ?>Buttons yearlyMonths" type="button" value="<?php echo $monthNum?>" onclick="yearlyMonthSelect(this)"><?php 127 124 echo "pressed"; 125 126 ?>Buttons yearlyMonths" type="button" value="<?php echo $monthNum?>" onclick="yearlyMonthSelect(this)"><?php 127 128 128 echo nl_langinfo(constant("ABMON_".$monthNum)); 129 129 130 130 ?></button><?php 131 131 if(($monthNum % 4) == 0) echo "<br />"; … … 135 135 136 136 function newerRepeats($parentid,$id){ 137 137 138 138 if ($parentid=="NULL") 139 139 $parentid=$id; 140 140 141 141 $querystatement="SELECT creationdate FROM notes WHERE id=".((int) $id); 142 142 $queryresult = $this->db->query($querystatement); 143 143 $therecord=$this->db->fetchArray($queryresult); 144 144 145 145 $querystatement="SELECT id FROM notes WHERE completed=0 AND parentid=".((int) $parentid)." AND creationdate > '".$therecord["creationdate"]."'"; 146 146 $queryresult = $this->db->query($querystatement); 147 147 148 148 if($this->db->numRows($queryresult)) return true; else return false; 149 149 } 150 151 150 151 152 152 function resetRepeating($parentid){ 153 153 154 154 $deletstatement="DELETE FROM notes WHERE completed=0 AND parentid=".$parentid; 155 155 $this->db->query($deletstatement); 156 156 157 157 $updatestatement="UPDATE notes SET parentid=NULL WHERE completed=1 AND parentid=".$parentid; 158 158 $queryresult = $this->db->query($updatestatement); 159 159 160 160 } 161 162 161 162 163 163 function updateTask($id,$completed,$type){ 164 164 165 165 if($completed) 166 166 $compDate="CURDATE()"; 167 167 else 168 168 $compDate="NULL"; 169 169 170 170 $querystatement="UPDATE notes SET completed=".((int) $completed)." , completeddate=".$compDate." WHERE id=".((int) $id); 171 171 $queryresult=$this->db->query($querystatement); 172 172 173 173 if($completed && $type == "TS") 174 174 $this->repeatTask($id); 175 175 176 176 return "success"; 177 178 } 179 180 177 178 } 179 180 181 181 function repeatTask($id, $dateToCheck = NULL){ 182 if($dateToCheck == NULL) 183 $dateToCheck = mktime(0,0,0); 182 if($dateToCheck == NULL) 183 $dateToCheck = mktime(0,0,0); 184 184 //see if we need to grab the parent 185 185 $querystatement = "SELECT parentid,repeating FROM notes WHERE id=".((int) $id); … … 191 191 return false; 192 192 193 $querystatement = "SELECT notes.repeattype, notes.repeatevery, notes.startdate, notes.enddate, notes.firstrepeat, 193 $querystatement = "SELECT notes.repeattype, notes.repeatevery, notes.startdate, notes.enddate, notes.firstrepeat, 194 194 notes.lastrepeat, 195 notes.timesrepeated, notes.repeatontheday, notes.repeatontheweek, notes.repeateachlist, 195 notes.timesrepeated, notes.repeatontheday, notes.repeatontheweek, notes.repeateachlist, 196 196 notes.repeatuntil, notes.repeattimes 197 197 FROM notes WHERE repeating=1 AND id=".((int) $id)." AND type='TS' … … 207 207 else 208 208 $startDate = stringToDate($therecord["startdate"],"SQL"); 209 209 210 210 if($dateToCheck <= $startDate) 211 211 $dateToCheck = strtotime("tomorrow",$startDate); 212 212 213 213 $dateArray = $this->getValidInRange($startDate,$dateToCheck,$therecord); 214 214 215 215 foreach($dateArray as $date){ 216 216 if($date != $startDate){ … … 219 219 else 220 220 $enddate = NULL; 221 221 222 222 $return = $this->createChildTask($id, $date, stringToDate($therecord["startdate"],"SQL"), $enddate ); 223 223 if($return){ … … 228 228 $updatestatement .= "firstrepeat='".dateToString($date,"SQL")."',"; 229 229 $updatestatement .="timesrepeated = timesrepeated+1 WHERE id =".$id; 230 230 231 231 $this->db->query($updatestatement); 232 232 … … 235 235 }//endif 236 236 }//endforeach 237 237 238 238 }//endif 239 239 }//end method 240 240 241 241 242 242 function getValidInRange($startDate,$endDate,$therecord){ 243 243 $nextDate = $startDate; 244 244 245 245 //should pad the end date to make sure we get all weekly repeats 246 246 $endDate = strtotime("+7 days",$endDate); 247 247 248 248 $validDates = array(); 249 249 250 250 while($nextDate <= $endDate){ 251 251 252 252 switch($therecord["repeattype"]){ 253 253 case "Daily": … … 256 256 $nextDate = strtotime("+".$therecord["repeatevery"]." days",$nextDate); 257 257 break; 258 259 case "Weekly": 258 259 case "Weekly": 260 260 //================================================================================== 261 261 $weekDayArray = explode("::",$therecord["repeateachlist"]); 262 262 263 263 //need to start from the sunday of the current week 264 264 $tempDate = strtotime(nl_langinfo( constant("DAY_1") ),$nextDate); 265 265 $tempDate = strtotime("-7 days",$tempDate); 266 266 267 267 foreach($weekDayArray as $weekday){ 268 268 if($weekday == 7) 269 269 $validDates[]=$tempDate; 270 270 else{ 271 $weekday++; 271 $weekday++; 272 272 $validDates[] = strtotime(nl_langinfo( constant("DAY_".$weekday) ),$tempDate); 273 273 } 274 274 }// endforeach 275 276 275 276 277 277 $nextDate = strtotime("+".$therecord["repeatevery"]." week",$nextDate); 278 279 break; 280 278 279 break; 280 281 281 case "Monthly": 282 282 //================================================================================== 283 $dateArray = localtime($nextDate,true); 283 $dateArray = localtime($nextDate,true); 284 284 $daysInMonth = date("d", mktime(0,0,0,$dateArray["tm_mon"],0,$dateArray["tm_year"]+1900) ); 285 285 286 286 if($therecord["repeateachlist"]){ 287 287 $dayArray = explode("::",$therecord["repeateachlist"]); 288 288 289 289 foreach($dayArray as $theday) 290 $validDates[] = mktime(0,0,0,$dateArray["tm_mon"]+1,$theday,$dateArray["tm_year"]+1900); 291 290 $validDates[] = mktime(0,0,0,$dateArray["tm_mon"]+1,$theday,$dateArray["tm_year"]+1900); 291 292 292 } else{ 293 293 // check for things like second tuesday or last friday; 294 294 $tempDate = mktime(0,0,0,$dateArray["tm_mon"]+1,1,$dateArray["tm_year"]+1900); 295 295 $weekday = $therecord["repeatontheday"]; 296 $weekday = ($weekday == 7)? 1: ($weekday+1); 296 $weekday = ($weekday == 7)? 1: ($weekday+1); 297 297 if($therecord["repeatontheday"] != strftime("%u",$tempDate)); 298 298 $tempDate = strtotime(nl_langinfo( constant("DAY_".$weekday) ),$tempDate); 299 299 300 300 while(date("n",$tempDate) == ($dateArray["tm_mon"]+1)){ 301 301 302 302 if($therecord["repeatontheweek"] == 5){ 303 303 // 5 is the "last" option, so we just need to see if … … 305 305 if($daysInMonth - date("d",$tempDate) < 7) 306 306 $validDates[] = $tempDate; 307 307 308 308 } else { 309 309 if( ceil(date("d",$tempDate)/7) == $therecord["repeatontheweek"]) 310 $validDates[] = $tempDate; 310 $validDates[] = $tempDate; 311 311 }// endif 312 312 313 313 $tempDate = strtotime("+7 days",$tempDate); 314 314 315 315 }// endwhile 316 316 }//endif 317 317 318 318 $nextDate = strtotime("+".$therecord["repeatevery"]." months", $nextDate); 319 319 break; 320 320 321 321 case "Yearly": 322 322 //================================================================================== 323 323 $monthArray = explode("::",$therecord["repeateachlist"]); 324 324 foreach($monthArray as $monthNum){ 325 $dateArray = localtime($nextDate,true); 325 $dateArray = localtime($nextDate,true); 326 326 $daysInMonth = date("d", mktime(0,0,0,$monthNum,0,$dateArray["tm_year"]+1900) ); 327 327 328 328 if(!$therecord["repeatontheday"]){ 329 329 $tempDay = ($dateArray["tm_mday"] > $daysInMonth)? $daysInMonth :$dateArray["tm_mday"]; 330 330 $validDates[] = mktime(0,0,0,$monthNum,$tempDay,$dateArray["tm_year"]+1900); 331 331 332 332 } else { 333 333 // check for things like second tuesday or last friday; 334 334 $tempDate = mktime(0,0,0,$monthNum,1,$dateArray["tm_year"]+1900); 335 335 336 336 $weekday = $therecord["repeatontheday"]; 337 $weekday = ($weekday == 7)? 1: ($weekday+1); 337 $weekday = ($weekday == 7)? 1: ($weekday+1); 338 338 if($therecord["repeatontheday"] != strftime("%u",$tempDate)); 339 339 $tempDate = strtotime(nl_langinfo( constant("DAY_".$weekday) ),$tempDate); 340 341 340 341 342 342 while(date("n",$tempDate) == $monthNum){ 343 343 if($therecord["repeatontheweek"] == 5){ … … 346 346 if($daysInMonth - date("d",$tempDate) < 7) 347 347 $validDates[] = $tempDate; 348 348 349 349 } else { 350 350 if( ceil(date("d",$tempDate)/7) == $therecord["repeatontheweek"]) 351 $validDates[] = $tempDate; 351 $validDates[] = $tempDate; 352 352 }// endif 353 353 354 354 $tempDate = strtotime("+7 days",$tempDate); 355 355 356 356 }// endwhile 357 358 }//endif 359 357 358 }//endif 359 360 360 }//endforeach 361 361 362 362 $nextDate = strtotime("+".$therecord["repeatevery"]." years",$nextDate); 363 363 364 364 break; 365 365 }//endswitch 366 366 367 367 }//end while 368 368 369 369 return $validDates; 370 370 371 371 }//end method 372 372 373 373 374 374 function createChildTask($parentid, $newdate, $startdate, $enddate=NULL){ 375 375 376 376 //let's check to see if the new task already exists 377 377 $querystatement = "SELECT id FROM notes WHERE parentid=".$parentid." AND startdate='".dateToString($newdate,"SQL")."'"; … … 379 379 if($this->db->numRows($queryresult)) 380 380 return false; 381 381 382 382 $newenddate="NULL"; 383 if($enddate) 383 if($enddate) 384 384 $newenddate="\"".dateToString($newdate+($enddate-$startdate),"SQL")."\""; 385 385 386 386 $querystatement="SELECT id,type,subject,content,status,starttime,private,modifiedby,location,importance,endtime,CURDATE() as creationdate,createdby,category, 387 387 attachedtabledefid,attachedid,assignedtoid,assignedtodate,assignedtotime,assignedbyid 388 388 FROM notes WHERE id=".$parentid; 389 389 $queryresult=$this->db->query($querystatement); 390 390 391 391 $therecord=$this->db->fetchArray($queryresult); 392 392 393 393 $querystatement="SELECT id FROM notes WHERE parentid=".((int) $parentid)." AND completed=0 AND startdate=\"".dateToString($newdate,"SQL")."\""; 394 394 $queryresult=$this->db->query($querystatement); 395 395 396 396 if($this->db->numRows($queryresult)) 397 return false; 398 397 return false; 398 399 399 if(!$therecord["assignedtoid"]) 400 400 $therecord["assignedtoid"]="NULL"; 401 401 402 402 $querystatement="INSERT INTO notes (parentid,startdate,enddate,completed,completeddate, 403 403 type,subject,content,status,starttime,private,modifiedby,location,importance,endtime,creationdate,createdby,category, … … 412 412 else 413 413 $querystatement.="NULL, "; 414 414 415 415 $querystatement.=$therecord["private"].", "; 416 416 $querystatement.=$therecord["modifiedby"].", "; … … 430 430 $querystatement.="\"".$therecord["assignedtodate"]."\", "; 431 431 else 432 $querystatement.="NULL, "; 432 $querystatement.="NULL, "; 433 433 if($therecord["assignedtotime"]) 434 434 $querystatement.="\"".$therecord["assignedtotime"]."\", "; … … 436 436 $querystatement.="NULL, "; 437 437 $querystatement.=$therecord["assignedbyid"].") "; 438 438 439 439 $queryresult=$this->db->query($querystatement); 440 440 441 441 return true; 442 442 }//end method 443 444 443 444 445 445 function getAttachedTableDefInfo($id){ 446 446 if($id){ … … 452 452 $therecord["editfile"]=""; 453 453 } 454 455 return $therecord; 456 } 457 458 454 455 return $therecord; 456 } 457 458 459 459 //CLASS OVERRIDES ============================================================================= 460 460 461 461 function getDefaults(){ 462 462 $therecord = parent::getDefaults(); 463 463 464 464 if(isset($_GET["ty"])) 465 465 $therecord["type"]=$_GET["ty"]; 466 466 else 467 467 $therecord["type"]="NT"; 468 468 469 469 $therecord["private"]=true; 470 470 471 471 $therecord["attachedtabledefid"]=(isset($_GET["tabledefid"]))?$_GET["tabledefid"]:NULL; 472 472 $therecord["attachedid"]=(isset($_GET["refid"]))?$_GET["refid"]:NULL; … … 476 476 $therecord["attachedid"]=$_GET["cid"]; 477 477 } 478 478 479 479 $therecord["repeatevery"] = 1; 480 480 $therecord["repeattype"] = "Daily"; 481 481 482 482 return $therecord; 483 483 } 484 485 486 function formatVariables($variables,$userid){ 484 485 486 function verifyVariables($variables){ 487 488 //table default ok 489 if(isset($variables["type"])){ 490 switch($variables["type"]){ 491 492 case "NT": 493 case "TS": 494 case "EV": 495 break; 496 497 case "SM": 498 //for system message, not private 499 if(isset($variables["private"])) 500 if($variables["private"]) 501 $this->verifyErrors[] = "For records with `type` of 'SM' (System Message), the `private 502 field must be equivalent to 0."; 503 break; 504 505 default: 506 $this->verifyErrors[] = "The `type` field given is not an acceptable value. Acceptable values are 'NT', 'TS', 'EV', or 'SM'"; 507 break; 508 509 }//end switch 510 }//end if 511 512 //Doesn't need to be set... only used if repeating 513 514 if(isset($variables["repeat"])) 515 if($variables["repeat"]) 516 if(isset($variables["startdate"])){ 517 if($variables["startdate"]){ 518 519 }else 520 $this->verifyErrors[] = "If a `note` record is set to repeat it must also have a `startdate`."; 521 }else 522 $this->verifyErrors[] = "If a `note` record is set to repeat it must also have a `startdate`."; 523 524 if(isset($variables["repeattype"])) 525 if($variables["repeattype"])//it can be "" or NULL 526 switch($variables["repeattype"]){ 527 528 529 case "Daily": 530 case "Weekly": 531 case "Monthly": 532 case "Yearly": 533 break; 534 535 default: 536 $this->verifyErrors[] = "The `repeatetype` field given is not an acceptable value. 537 Acceptable values are 'Daily', 'Weekly', 'Monthly', or 'Yearly'"; 538 break; 539 540 }//end switch 541 542 543 //check booleans 544 if(isset($variables["completed"])) 545 if($variables["completed"] && $variables["completed"] != 1) 546 $this->verifyErrors[] = "The `completed` field must be a boolean (equivalent to 0 or exactly 1)."; 547 548 if(isset($variables["private"])) 549 if($variables["private"] && $variables["private"] != 1) 550 $this->verifyErrors[] = "The `private` field must be a boolean (equivalent to 0 or exactly 1)."; 551 552 if(isset($variables["repeating"])) 553 if($variables["repeating"] && $variables["repeating"] != 1) 554 $this->verifyErrors[] = "The `repeating` field must be a boolean (equivalent to 0 or exactly 1)."; 555 556 return parent::verifyVariables($variables); 557 558 }//end method --verifyVariables-- 559 560 561 function prepareVariables($variables,$userid = NULL){ 562 563 if($userid == NULL) 564 if(isset($_SESSION["userinfo"]["id"])) 565 $userid = $_SESSION["userinfo"]["id"]; 566 567 if($variables["id"]){ //i.e. only on update 568 569 unset($this->fields["type"]); 570 571 if($variables["typeCheck"]=="TS" && isset($variables["repeating"]) && $variables["lastrepeat"]){ 572 $variables["lastrepeat"] = NULL; 573 $variables["firstrepeat"] = NULL; 574 $variables["timesrepeated"] = NULL; 575 576 if(isset($variables["completed"])) 577 $variables["completedChange"] = 0; 578 579 $this->resetRepeating($variables["id"]); 580 }//end if 581 582 }//end if 487 583 488 584 if(isset($variables["thetype"])) 489 585 $variables["type"] = $variables["thetype"]; 490 586 491 587 if(!isset($variables["completed"])) 492 588 $variables["completeddate"] = NULL; 493 589 494 590 if($variables["enddate"] == "") { 495 591 $variables["enddate"] = NULL; 496 592 $variables["endtime"] = NULL; 497 593 } 498 594 499 595 if($variables["startdate"] == "") { 500 596 $variables["startdate"] = NULL; 501 597 $variables["starttime"] = NULL; 502 598 } 503 599 504 600 if(isset($variables["repeating"])) { 505 601 506 602 $thename="Every "; 507 603 508 604 switch($variables["repeattype"]){ 509 605 case "Daily": … … 512 608 else 513 609 $thename .= " day "; 514 610 515 611 $variables["repeatechlist"] = NULL; 516 612 $variables["repeatontheday"] = NULL; 517 613 $variables["repeatontheweek"] = NULL; 518 614 break; 519 615 520 616 case "Weekly": 521 617 if($variables["repeatevery"] != 1) … … 523 619 else 524 620 $thename .= "week on"; 525 621 526 622 foreach(explode("::",$variables["eachlist"]) as $dayNum){ 527 623 $tempday = ($dayNum != 7)?($dayNum+1):(1); … … 529 625 } 530 626 $thename = substr($thename,0,strlen($thename)-2); 531 627 532 628 if(strpos($thename,",") != false) 533 629 $thename = strrev(preg_replace("/,/","dna ",strrev($thename),1)); 534 630 535 631 $variables["repeateachlist"] = $variables["eachlist"]; 536 632 $variables["repeatontheday"] = NULL; 537 633 $variables["repeatontheweek"] = NULL; 538 634 break; 539 540 case "Monthly": 635 636 case "Monthly": 541 637 if($variables["repeatevery"] != 1) 542 638 $thename .= $variables["repeatevery"]." months"; 543 639 else 544 640 $thename .= "month"; 545 641 546 642 $thename .= " on the"; 547 643 if($variables["monthlyWhat"] == 1){ 548 644 549 645 foreach(explode("::",$variables["eachlist"]) as $dayNum) 550 646 $thename .=" ".ordinal($dayNum).", "; 551 647 552 648 $thename = substr($thename,0,strlen($thename)-2); 553 649 554 650 if(strpos($thename,",") != false) 555 651 $thename = strrev(preg_replace("/,/","dna ",strrev($thename),1)); 556 652 557 653 $variables["repeateachlist"] = $variables["eachlist"]; 558 654 $variables["repeatontheday"] = NULL; … … 562 658 if($value == $variables["monthlyontheweek"]) 563 659 $thename .= " ".strtolower($key); 564 660 565 661 foreach($this->dayOfWeekArray as $key=>$value) 566 662 if($value == $variables["monthlyontheday"]) … … 572 668 } 573 669 break; 574 670 575 671 case "Yearly": 576 672 if($variables["repeatevery"] > 1) … … 578 674 else 579 675 $thename .= "year"; 580 676 581 677 $thename .= " in"; 582 678 583 679 foreach(explode("::",$variables["eachlist"]) as $monthNum) 584 680 $thename .=" ".nl_langinfo(constant("MON_".$monthNum)).", "; 585 681 586 682 $thename = substr($thename,0,strlen($thename)-2); 587 683 if(strpos($thename,",") != false) 588 684 $thename = strrev(preg_replace("/,/","dna ",strrev($thename),1)); 589 685 590 686 $variables["repeateachlist"] = $variables["eachlist"]; 591 687 592 688 if(isset($variables["yearlyOnThe"])){ 593 689 $thename .= " on the"; … … 595 691 if($value == $variables["yearlyontheweek"]) 596 692 $thename .= " ".strtolower($key); 597 693 598 694 foreach($this->dayOfWeekArray as $key=>$value) 599 695 if($value == $variables["yearlyontheday"]) 600 696 $thename .= " ".$key; 601 697 602 698 $variables["repeatontheday"] = $variables["yearlyontheday"]; 603 699 $variables["repeatontheweek"] = $variables["yearlyontheweek"]; 604 700 605 701 } else { 606 702 607 703 $variables["repeatontheday"] = NULL; 608 704 $variables["repeatontheweek"] = NULL; 609 705 610 706 }//end if 611 707 break; 612 708 } 613 709 614 710 switch($variables["repeatend"]){ 615 711 case "never": … … 617 713 $variables["repeattimes"] = NULL; 618 714 break; 619 715 620 716 case "after": 621 717 $thename .= " for ".$variables["repeattimes"]; 622 718 623 719 $variables["repeatuntil"] = NULL; 624 720 break; 625 721 626 722 case "on date": 627 723 $thename .= " until ".$variables["repeatuntil"]; … … 631 727 $thename = trim($thename)."."; 632 728 $variables["repeatname"] = $thename; 633 729 634 730 $variables["firstrepeat"] = dateToString(stringToDate($variables["firstrepeat"],"SQL")); 635 731 $variables["lastrepeat"] = dateToString(stringToDate($variables["lastrepeat"],"SQL"));; 636 $variables["timesrepeated"] = NULL; 637 732 $variables["timesrepeated"] = NULL; 733 638 734 }else { 639 735 … … 645 741 $variables["repeatuntil"] = NULL; 646 742 $variables["repeattimes"] = NULL; 647 743 648 744 $variables["firstrepeat"] = NULL; 649 745 $variables["lastrepeat"] = NULL; … … 654 750 if($variables["assignedtoid"] != $variables["assignedtochange"]){ 655 751 if($variables["assignedtoid"] != "") 656 $variables["assignedbyid"] = $userid; 752 $variables["assignedbyid"] = $userid; 657 753 else 658 $variables["assignedbyid"] = 0; 754 $variables["assignedbyid"] = 0; 659 755 }//endif 660 756 661 757 return $variables; 758 662 759 }//end method 663 664 760 761 665 762 function updateRecord($variables, $modifiedby = NULL){ 666 667 if($modifiedby == NULL) 668 $modifiedby = $_SESSION["userinfo"]["id"]; 669 670 if($variables["typeCheck"]=="TS" && isset($variables["repeating"]) && $variables["lastrepeat"]){ 671 $variables["lastrepeat"] = NULL; 672 $variables["firstrepeat"] = NULL; 673 $variables["timesrepeated"] = NULL; 674 675 if(isset($variables["completed"])) 676 $variables["completedChange"] = 0; 677 678 $this->resetRepeating($variables["id"]); 679 } 680 681 $variables = $this->formatVariables($variables,$modifiedby); 682 683 parent::updateRecord($variables, $modifiedby); 684 685 if($variables["typeCheck"]=="TS" && isset($variables["completed"]) && $variables["completedChange"]==0) { 763 764 $thereturn = parent::updateRecord($variables, $modifiedby); 765 766 $this->getTableInfo(); 767 768 if($variables["typeCheck"]=="TS" && isset($variables["completed"]) && $variables["completedChange"]==0) { 686 769 if($variables["parentid"]){ 687 770 if(!$this->newerRepeats($variables["parentid"],$variables["id"])){ 688 771 $this->repeatTask($variables["parentid"]); 689 772 } 690 773 691 774 } elseif(isset($variables["repeating"])) { 692 775 if(!$this->newerRepeats($variables["id"],$variables["id"])){ 693 776 $this->repeatTask($variables["id"]); 694 777 } 695 778 696 779 }//endif elseif 697 }//endif 698 780 }//endif 781 782 return $thereturn; 783 699 784 }//end endmethod 700 785 701 786 702 787 function insertRecord($variables, $createdby = NULL){ 703 704 if($createdby == NULL) 705 $createdby = $_SESSION["userinfo"]["id"]; 706 707 $variables = $this->formatVariables($variables,$createdby); 708 788 709 789 $newid = parent::insertRecord($variables, $createdby); 710 790 711 791 if(isset($variables["completed"]) && isset($variables["repeating"])) 712 792 $this->repeatTask($newid); 713 793 714 794 return $newid; 715 795 }//end method 716 796 717 797 }//end class 718 798 }//end if … … 722 802 723 803 function mark_asread(){ 724 804 725 805 //passed variable is array of user ids to be revoked 726 806 $whereclause = $this->buildWhereClause(); 727 807 728 808 $querystatement = "UPDATE notes SET notes.completed=1,modifiedby=\"".$_SESSION["userinfo"]["id"]."\" WHERE (".$whereclause.") AND type!=\"SM\";"; 729 809 $queryresult = $this->db->query($querystatement); … … 732 812 733 813 $message.=" marked as completed/read."; 734 814 735 815 //for repeatable tasks, need to repeat dem! 736 816 $querystatement="SELECT id,parentid FROM notes WHERE type='TS' AND ((parentid IS NOT NULL AND parentid!=0 ) OR `repeating`=1) AND (".$whereclause.")"; 737 817 $queryresult = $this->db->query($querystatement); 738 818 if ($this->db->numRows($queryresult)){ 739 819 740 820 $thetable = new notes($this->db,12); 741 821 742 822 while($therecord=$db->fetchArray($queryresult)){ 743 if($variables["parentid"]) 823 if($variables["parentid"]) 744 824 if(!$thetable->newerRepeats($therecord["parentid"],$therecord["id"])) 745 825 $thetable->repeatTask($therecord["parentid"]); … … 748 828 $thetable->repeatTask($therecord["id"]); 749 829 }//endwhile 750 830 751 831 }//endif 752 832 753 833 return $message; 754 834 } 755 756 835 836 757 837 //delete notes 758 838 function delete_record(){ 759 839 760 840 //passed variable is array of user ids to be revoked 761 841 $whereclause = $this->buildWhereClause("notes.id"); 762 842 763 843 //we need to check for incomplete repeatable child tasks 764 844 $querystatement="SELECT notes.id, notes.parentid, notes.repeating, notes.completed 765 845 FROM notes WHERE (".$whereclause.") AND ((notes.createdby=".$_SESSION["userinfo"]["id"]." OR notes.assignedtoid=".$_SESSION["userinfo"]["id"].") 766 846 OR (".$_SESSION["userinfo"]["admin"]." =1))"; 767 847 768 848 $repeatqueryresult = $this->db->query($querystatement); 769 849 770 850 //repeat where applicable 771 851 if ($this->db->numRows($repeatqueryresult)){ 772 852 773 853 $thetable = new notes($this->db,12); 774 854 775 855 $repeatArray=array(); 776 856 $orphanArray= array(); 777 857 while($therecord=$this->db->fetchArray($repeatqueryresult)){ 778 858 779 859 if($therecord["parentid"] && $therecord["completed"] == 0){ 780 860 $repeatArray[] = array("parentid" => $therecord["parentid"], "id"=> $therecord["id"]); … … 782 862 $orphanArray[] = array("id" => $therecord["id"]); 783 863 }//endif elseif 784 864 785 865 }//endwhile 786 866 787 867 foreach($repeatArray as $repeat){ 788 868 if (!in_array($repeat["parentid"],$orphanArray)) … … 790 870 $thetable->repeatTask($repeat["parentid"]); 791 871 }//end foreach 792 872 793 873 foreach($orphanArray as $orphaner){ 794 874 $thetable->resetRepeating($orphaner); 795 875 } 796 876 797 877 }//end if 798 878 799 $querystatement = "DELETE FROM notes WHERE 879 $querystatement = "DELETE FROM notes WHERE 800 880 ((notes.createdby=".$_SESSION["userinfo"]["id"]." OR notes.assignedtoid=".$_SESSION["userinfo"]["id"].") 801 OR (".$_SESSION["userinfo"]["admin"]." =1)) 881 OR (".$_SESSION["userinfo"]["admin"]." =1)) 802 882 AND (".$whereclause.")"; 803 883 $queryresult = $this->db->query($querystatement); 804 884 805 885 $message = $this->buildStatusMessage(); 806 886 $message.=" deleted"; 807 887 808 888 return $message; 809 810 } 811 889 890 } 891 812 892 }//end class 813 893 }//end if