phpBMS

Show
Ignore:
Timestamp:
04/07/09 11:44:18 (3 years ago)
Author:
nate
Message:
  • Merged Nathan branch back into trunk.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/modules/base/include/notes.php

    r351 r485  
    4545        var $weekArray = array("First"=>"1", "Second"=>"2", "Third"=>"3", "Fourth"=>"4", "Last"=>"5"); 
    4646        var $dayOfWeekArray = array(); 
    47          
    48          
     47 
     48 
    4949        function notes($db,$tabledefid = 0,$backurl = NULL){ 
    5050 
     
    5757        } 
    5858 
    59          
     59 
    6060        function showWeeklyOptions($therecord,$repeatbase){ 
    6161                if($therecord["repeattype"] == "Weekly") 
     
    6363                else 
    6464                        $daysSelected = array(strftime("%u",$repeatbase)); 
    65                          
     65 
    6666                $daysAvailable = array(7,1,2,3,4,5,6); 
    67                  
     67 
    6868                foreach($daysAvailable as $dayNum){ 
    6969                        $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 
    7272                        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 
    7777                        echo nl_langinfo(constant("ABDAY_".$tempday)); 
    78                          
     78 
    7979                        ?></button><?php 
    8080                } 
    81                          
    82                  
     81 
     82 
    8383        } 
    84          
     84 
    8585        function showMonthlyOptions($therecord,$repeatbase){ 
    8686                if($therecord["repeattype"] == "Monthly" && $therecord["repeateachlist"]) 
     
    8888                else 
    8989                        $daysSelected = array(strftime("%e",$repeatbase)); 
    90                          
    91                  
     90 
     91 
    9292                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 
    9595                        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 
    100100                                if($therecord["repeatontheday"]) 
    101101                                        echo 'disabled="disabled"'; 
    102                          
    103                         ?>><?php  
    104                          
     102 
     103                        ?>><?php 
     104 
    105105                        echo $dayNum; 
    106                          
     106 
    107107                        ?></button><?php 
    108108                        if(($dayNum % 7) == 0) echo "<br />"; 
    109                 }                        
    110                  
     109                } 
     110 
    111111        }//end method 
    112112 
    113          
     113 
    114114        function showYearlyOptions($therecord,$repeatbase){ 
    115115                if($therecord["repeattype"] == "Yearly") 
     
    117117                else 
    118118                        $monthsSelected = array(date("n",$repeatbase)); 
    119                          
     119 
    120120                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 
    123123                        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 
    128128                        echo nl_langinfo(constant("ABMON_".$monthNum)); 
    129                          
     129 
    130130                        ?></button><?php 
    131131                        if(($monthNum % 4) == 0) echo "<br />"; 
     
    135135 
    136136                function newerRepeats($parentid,$id){ 
    137          
     137 
    138138                        if ($parentid=="NULL") 
    139139                                $parentid=$id; 
    140                                  
     140 
    141141                        $querystatement="SELECT creationdate FROM notes WHERE id=".((int) $id); 
    142142                        $queryresult = $this->db->query($querystatement); 
    143143                        $therecord=$this->db->fetchArray($queryresult); 
    144                  
     144 
    145145                        $querystatement="SELECT id FROM notes WHERE completed=0 AND parentid=".((int) $parentid)." AND creationdate > '".$therecord["creationdate"]."'"; 
    146146                        $queryresult = $this->db->query($querystatement); 
    147          
     147 
    148148                        if($this->db->numRows($queryresult)) return true; else return false; 
    149149                } 
    150          
    151          
     150 
     151 
    152152                function resetRepeating($parentid){ 
    153                          
     153 
    154154                        $deletstatement="DELETE FROM notes WHERE completed=0 AND parentid=".$parentid; 
    155155                        $this->db->query($deletstatement); 
    156                          
     156 
    157157                        $updatestatement="UPDATE notes SET parentid=NULL WHERE completed=1 AND parentid=".$parentid; 
    158158                        $queryresult = $this->db->query($updatestatement); 
    159159 
    160160                } 
    161          
    162          
     161 
     162 
    163163                function updateTask($id,$completed,$type){ 
    164                  
     164 
    165165                        if($completed) 
    166166                                $compDate="CURDATE()"; 
    167167                        else 
    168168                                $compDate="NULL"; 
    169                          
     169 
    170170                        $querystatement="UPDATE notes SET completed=".((int) $completed)." , completeddate=".$compDate." WHERE id=".((int) $id); 
    171171                        $queryresult=$this->db->query($querystatement); 
    172                          
     172 
    173173                        if($completed && $type == "TS") 
    174174                                $this->repeatTask($id); 
    175                          
     175 
    176176                        return "success"; 
    177                          
    178                 } 
    179          
    180                  
     177 
     178                } 
     179 
     180 
    181181                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); 
    184184                        //see if we need to grab the parent 
    185185                        $querystatement = "SELECT parentid,repeating FROM notes WHERE id=".((int) $id); 
     
    191191                                        return false; 
    192192 
    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, 
    194194                                                                notes.lastrepeat, 
    195                                                                 notes.timesrepeated, notes.repeatontheday, notes.repeatontheweek, notes.repeateachlist,  
     195                                                                notes.timesrepeated, notes.repeatontheday, notes.repeatontheweek, notes.repeateachlist, 
    196196                                                                notes.repeatuntil, notes.repeattimes 
    197197                                                                FROM notes WHERE repeating=1 AND id=".((int) $id)." AND type='TS' 
     
    207207                                else 
    208208                                        $startDate = stringToDate($therecord["startdate"],"SQL"); 
    209                                  
     209 
    210210                                if($dateToCheck <= $startDate) 
    211211                                        $dateToCheck = strtotime("tomorrow",$startDate); 
    212212 
    213213                                $dateArray = $this->getValidInRange($startDate,$dateToCheck,$therecord); 
    214                                  
     214 
    215215                                foreach($dateArray as $date){ 
    216216                                        if($date != $startDate){ 
     
    219219                                                else 
    220220                                                        $enddate = NULL; 
    221                                                          
     221 
    222222                                                $return = $this->createChildTask($id, $date, stringToDate($therecord["startdate"],"SQL"), $enddate ); 
    223223                                                if($return){ 
     
    228228                                                                $updatestatement .= "firstrepeat='".dateToString($date,"SQL")."',"; 
    229229                                                        $updatestatement .="timesrepeated = timesrepeated+1 WHERE id =".$id; 
    230                                                          
     230 
    231231                                                        $this->db->query($updatestatement); 
    232232 
     
    235235                                        }//endif 
    236236                                }//endforeach 
    237                                  
     237 
    238238                        }//endif 
    239239                }//end method 
    240          
     240 
    241241 
    242242                function getValidInRange($startDate,$endDate,$therecord){ 
    243243                        $nextDate = $startDate; 
    244          
     244 
    245245                        //should pad the end date to make sure we get all weekly repeats 
    246246                        $endDate = strtotime("+7 days",$endDate); 
    247                          
     247 
    248248                        $validDates = array(); 
    249                                          
     249 
    250250                        while($nextDate <= $endDate){ 
    251                                                  
     251 
    252252                                switch($therecord["repeattype"]){ 
    253253                                        case "Daily": 
     
    256256                                                $nextDate = strtotime("+".$therecord["repeatevery"]." days",$nextDate); 
    257257                                                break; 
    258                                                  
    259                                         case "Weekly":                                                                                   
     258 
     259                                        case "Weekly": 
    260260                                                //================================================================================== 
    261261                                                $weekDayArray = explode("::",$therecord["repeateachlist"]); 
    262          
     262 
    263263                                                //need to start from the sunday of the current week 
    264264                                                $tempDate = strtotime(nl_langinfo( constant("DAY_1") ),$nextDate); 
    265265                                                $tempDate = strtotime("-7 days",$tempDate); 
    266                                                  
     266 
    267267                                                foreach($weekDayArray as $weekday){ 
    268268                                                        if($weekday == 7) 
    269269                                                                $validDates[]=$tempDate; 
    270270                                                        else{ 
    271                                                                 $weekday++;  
     271                                                                $weekday++; 
    272272                                                                $validDates[] = strtotime(nl_langinfo( constant("DAY_".$weekday) ),$tempDate); 
    273273                                                        } 
    274274                                                }// endforeach 
    275                                                                                                                                                                                          
    276                                                  
     275 
     276 
    277277                                                $nextDate = strtotime("+".$therecord["repeatevery"]." week",$nextDate); 
    278                                                  
    279                                                 break; 
    280                                          
     278 
     279                                                break; 
     280 
    281281                                        case "Monthly": 
    282282                                                //================================================================================== 
    283                                                 $dateArray = localtime($nextDate,true);                                          
     283                                                $dateArray = localtime($nextDate,true); 
    284284                                                $daysInMonth = date("d", mktime(0,0,0,$dateArray["tm_mon"],0,$dateArray["tm_year"]+1900) ); 
    285                                                  
     285 
    286286                                                if($therecord["repeateachlist"]){ 
    287287                                                        $dayArray = explode("::",$therecord["repeateachlist"]); 
    288                                                          
     288 
    289289                                                        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 
    292292                                                } else{ 
    293293                                                        // check for things like second tuesday or last friday; 
    294294                                                        $tempDate = mktime(0,0,0,$dateArray["tm_mon"]+1,1,$dateArray["tm_year"]+1900); 
    295295                                                        $weekday = $therecord["repeatontheday"]; 
    296                                                         $weekday = ($weekday == 7)? 1: ($weekday+1);                                                     
     296                                                        $weekday = ($weekday == 7)? 1: ($weekday+1); 
    297297                                                        if($therecord["repeatontheday"] != strftime("%u",$tempDate)); 
    298298                                                                $tempDate = strtotime(nl_langinfo( constant("DAY_".$weekday) ),$tempDate); 
    299                                                                  
     299 
    300300                                                        while(date("n",$tempDate) == ($dateArray["tm_mon"]+1)){ 
    301                                                          
     301 
    302302                                                                if($therecord["repeatontheweek"] == 5){ 
    303303                                                                        // 5 is the "last" option, so we just need to see if 
     
    305305                                                                        if($daysInMonth - date("d",$tempDate) < 7) 
    306306                                                                                $validDates[] = $tempDate; 
    307                                                                                  
     307 
    308308                                                                } else { 
    309309                                                                        if( ceil(date("d",$tempDate)/7) == $therecord["repeatontheweek"]) 
    310                                                                                 $validDates[] = $tempDate;                                                                               
     310                                                                                $validDates[] = $tempDate; 
    311311                                                                }// endif 
    312          
     312 
    313313                                                                $tempDate = strtotime("+7 days",$tempDate); 
    314          
     314 
    315315                                                        }// endwhile 
    316316                                                }//endif 
    317          
     317 
    318318                                                $nextDate = strtotime("+".$therecord["repeatevery"]." months", $nextDate); 
    319319                                                break; 
    320                                                  
     320 
    321321                                        case "Yearly": 
    322322                                                //================================================================================== 
    323323                                                $monthArray = explode("::",$therecord["repeateachlist"]); 
    324324                                                foreach($monthArray as $monthNum){ 
    325                                                         $dateArray = localtime($nextDate,true);                                          
     325                                                        $dateArray = localtime($nextDate,true); 
    326326                                                        $daysInMonth = date("d", mktime(0,0,0,$monthNum,0,$dateArray["tm_year"]+1900) ); 
    327          
     327 
    328328                                                        if(!$therecord["repeatontheday"]){ 
    329329                                                                $tempDay = ($dateArray["tm_mday"] > $daysInMonth)? $daysInMonth :$dateArray["tm_mday"]; 
    330330                                                                $validDates[] = mktime(0,0,0,$monthNum,$tempDay,$dateArray["tm_year"]+1900); 
    331          
     331 
    332332                                                        } else { 
    333333                                                                // check for things like second tuesday or last friday; 
    334334                                                                $tempDate = mktime(0,0,0,$monthNum,1,$dateArray["tm_year"]+1900); 
    335                                                                  
     335 
    336336                                                                $weekday = $therecord["repeatontheday"]; 
    337                                                                 $weekday = ($weekday == 7)? 1: ($weekday+1);                                                     
     337                                                                $weekday = ($weekday == 7)? 1: ($weekday+1); 
    338338                                                                if($therecord["repeatontheday"] != strftime("%u",$tempDate)); 
    339339                                                                        $tempDate = strtotime(nl_langinfo( constant("DAY_".$weekday) ),$tempDate); 
    340                                                                  
    341                                                                  
     340 
     341 
    342342                                                                while(date("n",$tempDate) == $monthNum){ 
    343343                                                                        if($therecord["repeatontheweek"] == 5){ 
     
    346346                                                                                if($daysInMonth - date("d",$tempDate) < 7) 
    347347                                                                                        $validDates[] = $tempDate; 
    348                                                                                          
     348 
    349349                                                                        } else { 
    350350                                                                                if( ceil(date("d",$tempDate)/7) == $therecord["repeatontheweek"]) 
    351                                                                                         $validDates[] = $tempDate;                                                                               
     351                                                                                        $validDates[] = $tempDate; 
    352352                                                                        }// endif 
    353                  
     353 
    354354                                                                        $tempDate = strtotime("+7 days",$tempDate); 
    355                  
     355 
    356356                                                                }// endwhile 
    357          
    358                                                         }//endif                         
    359          
     357 
     358                                                        }//endif 
     359 
    360360                                                }//endforeach 
    361          
     361 
    362362                                                $nextDate = strtotime("+".$therecord["repeatevery"]." years",$nextDate); 
    363          
     363 
    364364                                                break; 
    365365                                }//endswitch 
    366                                                          
     366 
    367367                        }//end while 
    368                          
     368 
    369369                        return $validDates; 
    370                          
     370 
    371371                }//end method 
    372                  
     372 
    373373 
    374374                function createChildTask($parentid, $newdate, $startdate, $enddate=NULL){ 
    375                          
     375 
    376376                        //let's check to see if the new task already exists 
    377377                        $querystatement = "SELECT id FROM notes WHERE parentid=".$parentid." AND startdate='".dateToString($newdate,"SQL")."'"; 
     
    379379                        if($this->db->numRows($queryresult)) 
    380380                                return false; 
    381                                                                  
     381 
    382382                        $newenddate="NULL"; 
    383                         if($enddate)                     
     383                        if($enddate) 
    384384                                $newenddate="\"".dateToString($newdate+($enddate-$startdate),"SQL")."\""; 
    385                                                  
     385 
    386386                        $querystatement="SELECT id,type,subject,content,status,starttime,private,modifiedby,location,importance,endtime,CURDATE() as creationdate,createdby,category, 
    387387                                                attachedtabledefid,attachedid,assignedtoid,assignedtodate,assignedtotime,assignedbyid 
    388388                                                FROM notes WHERE id=".$parentid; 
    389389                        $queryresult=$this->db->query($querystatement); 
    390          
     390 
    391391                        $therecord=$this->db->fetchArray($queryresult); 
    392                  
     392 
    393393                        $querystatement="SELECT id FROM notes WHERE parentid=".((int) $parentid)." AND completed=0 AND startdate=\"".dateToString($newdate,"SQL")."\""; 
    394394                        $queryresult=$this->db->query($querystatement); 
    395          
     395 
    396396                        if($this->db->numRows($queryresult)) 
    397                                 return false;            
    398                          
     397                                return false; 
     398 
    399399                        if(!$therecord["assignedtoid"]) 
    400400                                $therecord["assignedtoid"]="NULL"; 
    401                                                  
     401 
    402402                        $querystatement="INSERT INTO notes (parentid,startdate,enddate,completed,completeddate, 
    403403                                                type,subject,content,status,starttime,private,modifiedby,location,importance,endtime,creationdate,createdby,category, 
     
    412412                        else 
    413413                                $querystatement.="NULL, "; 
    414                          
     414 
    415415                        $querystatement.=$therecord["private"].", "; 
    416416                        $querystatement.=$therecord["modifiedby"].", "; 
     
    430430                                $querystatement.="\"".$therecord["assignedtodate"]."\", "; 
    431431                        else 
    432                                 $querystatement.="NULL, ";                       
     432                                $querystatement.="NULL, "; 
    433433                        if($therecord["assignedtotime"]) 
    434434                                $querystatement.="\"".$therecord["assignedtotime"]."\", "; 
     
    436436                                $querystatement.="NULL, "; 
    437437                        $querystatement.=$therecord["assignedbyid"].") "; 
    438                          
     438 
    439439                        $queryresult=$this->db->query($querystatement); 
    440                          
     440 
    441441                        return true; 
    442442                }//end method 
    443          
    444          
     443 
     444 
    445445                function getAttachedTableDefInfo($id){ 
    446446                        if($id){ 
     
    452452                                $therecord["editfile"]=""; 
    453453                        } 
    454                                          
    455                         return $therecord;       
    456                 } 
    457          
    458          
     454 
     455                        return $therecord; 
     456                } 
     457 
     458 
    459459                //CLASS OVERRIDES ============================================================================= 
    460          
     460 
    461461                function getDefaults(){ 
    462462                        $therecord = parent::getDefaults(); 
    463                          
     463 
    464464                        if(isset($_GET["ty"])) 
    465465                                $therecord["type"]=$_GET["ty"]; 
    466466                        else 
    467467                                $therecord["type"]="NT"; 
    468          
     468 
    469469                        $therecord["private"]=true; 
    470          
     470 
    471471                        $therecord["attachedtabledefid"]=(isset($_GET["tabledefid"]))?$_GET["tabledefid"]:NULL; 
    472472                        $therecord["attachedid"]=(isset($_GET["refid"]))?$_GET["refid"]:NULL; 
     
    476476                                $therecord["attachedid"]=$_GET["cid"]; 
    477477                        } 
    478          
     478 
    479479                        $therecord["repeatevery"] = 1; 
    480480                        $therecord["repeattype"] = "Daily"; 
    481                          
     481 
    482482                        return $therecord; 
    483483                } 
    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 
    487583 
    488584                                if(isset($variables["thetype"])) 
    489585                                        $variables["type"] = $variables["thetype"]; 
    490                                  
     586 
    491587                                if(!isset($variables["completed"])) 
    492588                                        $variables["completeddate"] = NULL; 
    493          
     589 
    494590                                if($variables["enddate"] == "") { 
    495591                                        $variables["enddate"] = NULL; 
    496592                                        $variables["endtime"] = NULL; 
    497593                                } 
    498          
     594 
    499595                                if($variables["startdate"] == "") { 
    500596                                        $variables["startdate"] = NULL; 
    501597                                        $variables["starttime"] = NULL; 
    502598                                } 
    503                                  
     599 
    504600                                if(isset($variables["repeating"])) { 
    505                                          
     601 
    506602                                        $thename="Every "; 
    507                                                                          
     603 
    508604                                        switch($variables["repeattype"]){ 
    509605                                                case "Daily": 
     
    512608                                                        else 
    513609                                                                $thename .= " day "; 
    514                                                          
     610 
    515611                                                        $variables["repeatechlist"] = NULL; 
    516612                                                        $variables["repeatontheday"] = NULL; 
    517613                                                        $variables["repeatontheweek"] = NULL; 
    518614                                                break; 
    519                          
     615 
    520616                                                case "Weekly": 
    521617                                                        if($variables["repeatevery"] != 1) 
     
    523619                                                        else 
    524620                                                                $thename .= "week on"; 
    525                                                                  
     621 
    526622                                                        foreach(explode("::",$variables["eachlist"]) as $dayNum){ 
    527623                                                                $tempday = ($dayNum != 7)?($dayNum+1):(1); 
     
    529625                                                        } 
    530626                                                        $thename = substr($thename,0,strlen($thename)-2); 
    531                          
     627 
    532628                                                        if(strpos($thename,",") != false) 
    533629                                                                $thename = strrev(preg_replace("/,/","dna ",strrev($thename),1)); 
    534                                                          
     630 
    535631                                                        $variables["repeateachlist"] = $variables["eachlist"]; 
    536632                                                        $variables["repeatontheday"] = NULL; 
    537633                                                        $variables["repeatontheweek"] = NULL; 
    538634                                                break; 
    539                          
    540                                                 case "Monthly":                  
     635 
     636                                                case "Monthly": 
    541637                                                        if($variables["repeatevery"] != 1) 
    542638                                                                $thename .= $variables["repeatevery"]." months"; 
    543639                                                        else 
    544640                                                                $thename .= "month"; 
    545                          
     641 
    546642                                                        $thename .= " on the"; 
    547643                                                        if($variables["monthlyWhat"] == 1){ 
    548                                                          
     644 
    549645                                                                foreach(explode("::",$variables["eachlist"]) as $dayNum) 
    550646                                                                        $thename .=" ".ordinal($dayNum).", "; 
    551                          
     647 
    552648                                                                $thename = substr($thename,0,strlen($thename)-2); 
    553                          
     649 
    554650                                                                if(strpos($thename,",") != false) 
    555651                                                                        $thename = strrev(preg_replace("/,/","dna ",strrev($thename),1)); 
    556                          
     652 
    557653                                                                $variables["repeateachlist"] = $variables["eachlist"]; 
    558654                                                                $variables["repeatontheday"] = NULL; 
     
    562658                                                                        if($value == $variables["monthlyontheweek"]) 
    563659                                                                                $thename .= " ".strtolower($key); 
    564                          
     660 
    565661                                                                foreach($this->dayOfWeekArray as $key=>$value) 
    566662                                                                        if($value == $variables["monthlyontheday"]) 
     
    572668                                                        } 
    573669                                                break; 
    574                                                  
     670 
    575671                                                case "Yearly": 
    576672                                                        if($variables["repeatevery"] > 1) 
     
    578674                                                        else 
    579675                                                                $thename .= "year"; 
    580                                                          
     676 
    581677                                                        $thename .= " in"; 
    582                                                          
     678 
    583679                                                        foreach(explode("::",$variables["eachlist"]) as $monthNum) 
    584680                                                                $thename .=" ".nl_langinfo(constant("MON_".$monthNum)).", "; 
    585                                                                  
     681 
    586682                                                        $thename = substr($thename,0,strlen($thename)-2); 
    587683                                                        if(strpos($thename,",") != false) 
    588684                                                                $thename = strrev(preg_replace("/,/","dna ",strrev($thename),1)); 
    589                                                                  
     685 
    590686                                                        $variables["repeateachlist"] = $variables["eachlist"]; 
    591                          
     687 
    592688                                                        if(isset($variables["yearlyOnThe"])){ 
    593689                                                                $thename .= " on the"; 
     
    595691                                                                        if($value == $variables["yearlyontheweek"]) 
    596692                                                                                $thename .= " ".strtolower($key); 
    597                                                                  
     693 
    598694                                                                foreach($this->dayOfWeekArray as $key=>$value) 
    599695                                                                        if($value == $variables["yearlyontheday"]) 
    600696                                                                                $thename .= " ".$key; 
    601                          
     697 
    602698                                                                $variables["repeatontheday"] = $variables["yearlyontheday"]; 
    603699                                                                $variables["repeatontheweek"] = $variables["yearlyontheweek"]; 
    604700 
    605701                                                        } else { 
    606                                                          
     702 
    607703                                                                $variables["repeatontheday"] = NULL; 
    608704                                                                $variables["repeatontheweek"] = NULL; 
    609                                                                  
     705 
    610706                                                        }//end if 
    611707                                                break; 
    612708                                        } 
    613                          
     709 
    614710                                        switch($variables["repeatend"]){ 
    615711                                                case "never": 
     
    617713                                                        $variables["repeattimes"] = NULL; 
    618714                                                        break; 
    619                                                          
     715 
    620716                                                case "after": 
    621717                                                        $thename .= " for ".$variables["repeattimes"]; 
    622                                                          
     718 
    623719                                                        $variables["repeatuntil"] = NULL; 
    624720                                                        break; 
    625                                                          
     721 
    626722                                                case "on date": 
    627723                                                        $thename .= " until ".$variables["repeatuntil"]; 
     
    631727                                        $thename = trim($thename)."."; 
    632728                                        $variables["repeatname"] = $thename; 
    633                                          
     729 
    634730                                        $variables["firstrepeat"] = dateToString(stringToDate($variables["firstrepeat"],"SQL")); 
    635731                                        $variables["lastrepeat"] = dateToString(stringToDate($variables["lastrepeat"],"SQL"));; 
    636                                         $variables["timesrepeated"] = NULL;                                      
    637                                                                  
     732                                        $variables["timesrepeated"] = NULL; 
     733 
    638734                                }else { 
    639735 
     
    645741                                        $variables["repeatuntil"] = NULL; 
    646742                                        $variables["repeattimes"] = NULL; 
    647                                          
     743 
    648744                                        $variables["firstrepeat"] = NULL; 
    649745                                        $variables["lastrepeat"] = NULL; 
     
    654750                                if($variables["assignedtoid"] != $variables["assignedtochange"]){ 
    655751                                        if($variables["assignedtoid"] != "") 
    656                                                 $variables["assignedbyid"] = $userid;  
     752                                                $variables["assignedbyid"] = $userid; 
    657753                                        else 
    658                                                 $variables["assignedbyid"] = 0;  
     754                                                $variables["assignedbyid"] = 0; 
    659755                                }//endif 
    660756 
    661757                        return $variables; 
     758 
    662759                }//end method 
    663                  
    664                  
     760 
     761 
    665762                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) { 
    686769                                        if($variables["parentid"]){ 
    687770                                                if(!$this->newerRepeats($variables["parentid"],$variables["id"])){ 
    688771                                                        $this->repeatTask($variables["parentid"]); 
    689772                                                } 
    690                                                          
     773 
    691774                                        } elseif(isset($variables["repeating"])) { 
    692775                                                if(!$this->newerRepeats($variables["id"],$variables["id"])){ 
    693776                                                        $this->repeatTask($variables["id"]); 
    694777                                                } 
    695                                                          
     778 
    696779                                        }//endif elseif 
    697                         }//endif                                                 
    698                                                  
     780                        }//endif 
     781 
     782                        return $thereturn; 
     783 
    699784                }//end endmethod 
    700785 
    701          
     786 
    702787                function insertRecord($variables, $createdby = NULL){ 
    703                          
    704                         if($createdby == NULL) 
    705                                 $createdby = $_SESSION["userinfo"]["id"]; 
    706                          
    707                         $variables = $this->formatVariables($variables,$createdby); 
    708                  
     788 
    709789                        $newid = parent::insertRecord($variables, $createdby); 
    710                          
     790 
    711791                        if(isset($variables["completed"]) && isset($variables["repeating"])) 
    712792                                $this->repeatTask($newid); 
    713                          
     793 
    714794                        return $newid; 
    715795                }//end method 
    716          
     796 
    717797        }//end class 
    718798}//end if 
     
    722802 
    723803                function mark_asread(){ 
    724                  
     804 
    725805                        //passed variable is array of user ids to be revoked 
    726806                        $whereclause = $this->buildWhereClause(); 
    727                          
     807 
    728808                        $querystatement = "UPDATE notes SET notes.completed=1,modifiedby=\"".$_SESSION["userinfo"]["id"]."\" WHERE (".$whereclause.") AND type!=\"SM\";"; 
    729809                        $queryresult = $this->db->query($querystatement); 
     
    732812 
    733813                        $message.=" marked as completed/read."; 
    734                          
     814 
    735815                        //for repeatable tasks, need to repeat dem! 
    736816                        $querystatement="SELECT id,parentid FROM notes WHERE type='TS' AND ((parentid IS NOT NULL AND parentid!=0 ) OR `repeating`=1) AND (".$whereclause.")"; 
    737817                        $queryresult = $this->db->query($querystatement); 
    738818                        if ($this->db->numRows($queryresult)){ 
    739                          
     819 
    740820                                $thetable = new notes($this->db,12); 
    741821 
    742822                                while($therecord=$db->fetchArray($queryresult)){ 
    743                                         if($variables["parentid"])                                       
     823                                        if($variables["parentid"]) 
    744824                                                if(!$thetable->newerRepeats($therecord["parentid"],$therecord["id"])) 
    745825                                                        $thetable->repeatTask($therecord["parentid"]); 
     
    748828                                                        $thetable->repeatTask($therecord["id"]); 
    749829                                }//endwhile 
    750                                  
     830 
    751831                        }//endif 
    752                                          
     832 
    753833                        return $message; 
    754834                } 
    755                  
    756                  
     835 
     836 
    757837                //delete notes 
    758838                function delete_record(){ 
    759                          
     839 
    760840                        //passed variable is array of user ids to be revoked 
    761841                        $whereclause = $this->buildWhereClause("notes.id"); 
    762                  
     842 
    763843                        //we need to check for incomplete repeatable child tasks 
    764844                        $querystatement="SELECT notes.id, notes.parentid, notes.repeating, notes.completed 
    765845                        FROM notes WHERE (".$whereclause.") AND ((notes.createdby=".$_SESSION["userinfo"]["id"]." OR notes.assignedtoid=".$_SESSION["userinfo"]["id"].") 
    766846                                                                 OR (".$_SESSION["userinfo"]["admin"]." =1))"; 
    767                                                                   
     847 
    768848                        $repeatqueryresult = $this->db->query($querystatement); 
    769                                          
     849 
    770850                        //repeat where applicable 
    771851                        if ($this->db->numRows($repeatqueryresult)){ 
    772                  
     852 
    773853                                $thetable = new notes($this->db,12); 
    774                                  
     854 
    775855                                $repeatArray=array(); 
    776856                                $orphanArray= array(); 
    777857                                while($therecord=$this->db->fetchArray($repeatqueryresult)){ 
    778                                  
     858 
    779859                                        if($therecord["parentid"] && $therecord["completed"] == 0){ 
    780860                                                $repeatArray[] = array("parentid" => $therecord["parentid"], "id"=> $therecord["id"]); 
     
    782862                                                $orphanArray[] = array("id" => $therecord["id"]); 
    783863                                        }//endif elseif 
    784                                          
     864 
    785865                                }//endwhile 
    786                                  
     866 
    787867                                foreach($repeatArray as $repeat){ 
    788868                                        if (!in_array($repeat["parentid"],$orphanArray)) 
     
    790870                                                        $thetable->repeatTask($repeat["parentid"]); 
    791871                                }//end foreach 
    792                                  
     872 
    793873                                foreach($orphanArray as $orphaner){ 
    794874                                        $thetable->resetRepeating($orphaner); 
    795875                                } 
    796                                  
     876 
    797877                        }//end if 
    798878 
    799                         $querystatement = "DELETE FROM notes WHERE  
     879                        $querystatement = "DELETE FROM notes WHERE 
    800880                                                                ((notes.createdby=".$_SESSION["userinfo"]["id"]." OR notes.assignedtoid=".$_SESSION["userinfo"]["id"].") 
    801                                                                  OR (".$_SESSION["userinfo"]["admin"]." =1))  
     881                                                                 OR (".$_SESSION["userinfo"]["admin"]." =1)) 
    802882                                                                 AND (".$whereclause.")"; 
    803883                        $queryresult = $this->db->query($querystatement); 
    804                  
     884 
    805885                        $message = $this->buildStatusMessage(); 
    806886                        $message.=" deleted"; 
    807                          
     887 
    808888                        return $message; 
    809                  
    810                 }        
    811          
     889 
     890                } 
     891 
    812892        }//end class 
    813893}//end if 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.