Пример #1
0
 function delete_record($useUUID = false)
 {
     if (!$useUUID) {
         $whereclause = $this->buildWhereClause("notes.id");
     } else {
         $whereclause = $this->buildWhereClause($this->maintable . ".uuid");
     }
     //we need to check for incomplete repeatable child tasks
     $querystatement = "\n\t\t\t\tSELECT\n\t\t\t\t\t`notes`.`id`,\n\t\t\t\t\t`notes`.`parentid`,\n\t\t\t\t\t`notes`.`repeating`,\n\t\t\t\t\t`notes`.`completed`\n\t\t\t\tFROM\n\t\t\t\t\t`notes`\n\t\t\t\tWHERE\n\t\t\t\t\t(" . $whereclause . ")\n\t\t\t\t\tAND\n\t\t\t\t\t(\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\t`notes`.`createdby` = '" . $_SESSION["userinfo"]["id"] . "'\n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t`notes`.`assignedtoid` = '" . $_SESSION["userinfo"]["uuid"] . "'\n\t\t\t\t\t\t)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\t'" . $_SESSION["userinfo"]["admin"] . "' = '1'\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t";
     $repeatqueryresult = $this->db->query($querystatement);
     //repeat where applicable
     if ($this->db->numRows($repeatqueryresult)) {
         $thetable = new notes($this->db, "tbld:a4cdd991-cf0a-916f-1240-49428ea1bdd1");
         $repeatArray = array();
         $orphanArray = array();
         while ($therecord = $this->db->fetchArray($repeatqueryresult)) {
             if ($therecord["parentid"] && $therecord["completed"] == 0) {
                 $repeatArray[] = array("parentid" => $therecord["parentid"], "id" => $therecord["id"]);
             } elseif ($therecord["repeating"]) {
                 $orphanArray[] = array("id" => $therecord["id"]);
             }
             //endif elseif
         }
         //endwhile
         foreach ($repeatArray as $repeat) {
             if (!in_array($repeat["parentid"], $orphanArray)) {
                 if (!$thetable->newerRepeats($repeat["parentid"], $repeat["id"])) {
                     $thetable->repeatTask($repeat["parentid"]);
                 }
             }
         }
         //end foreach
         foreach ($orphanArray as $orphaner) {
             $thetable->resetRepeating($orphaner);
         }
     }
     //end if
     $querystatement = "\n\t\t\t\tDELETE FROM\n\t\t\t\t\t`notes`\n\t\t\t\tWHERE\n\t\t\t\t\t(\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\t`notes`.`createdby` = '" . $_SESSION["userinfo"]["id"] . "'\n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t`notes`.`assignedtoid` = '" . $_SESSION["userinfo"]["uuid"] . "'\n\t\t\t\t\t\t)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\t'" . $_SESSION["userinfo"]["admin"] . "' ='1'\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t\tAND\n\t\t\t\t\t(" . $whereclause . ")\n\t\t\t";
     $queryresult = $this->db->query($querystatement);
     $message = $this->buildStatusMessage();
     $message .= " deleted";
     return $message;
 }