echo json_encode($ret); //echo sql_searchNoteByKeywords(json_decode($keywords)); }else if(isset($_REQUEST["report_dup"])){ error_log($_REQUEST["dups"]); $dups = json_decode($_REQUEST["dups"]); $count = count($dups); $ret = array(); $ret["type"] = "dup"; for($i=0;$i<$count;$i++){ if($dups[$i]){ $str="["; for($j=0;$j<count($dups[$i]);$j++){ $str=$str.$dups[$i][$j].", "; //TODO: check if dup is true, then del dup error_log("keep".$i." remove".$dups[$i][$j]); $result = query(sql_deleteNote($dups[$i][$j])); $ret["error"] = !$result; } $str=$str."]"; //error_log("keep".$i." remove".$str); } } echo json_encode($ret); }else{ error_log($_REQUEST["data"]); // the client asked for something we don't support throw new Exception("not supported operation"); } }catch(Exception $e){ // something bad happened
// save a note to the DB function sql_editNote($id, $subj, $body, $dt){ if(!is_int($id)) throw new Exception("argument to " . __METHOD__ . " must be an int"); if(!is_string($subj)) throw new Exception("argument to " . __METHOD__ . " must be a string"); if(!is_string($body)) throw new Exception("argument to " . __METHOD__ . " must be a string"); if(!is_string($dt)) throw new Exception("argument to " . __METHOD__ . " must be a string"); return "UPDATE `notes` SET `subject` = '" . addslashes($subj) . "', `body` = '" . addslashes($body) . "', `dt_modified` = '" . addslashes($dt) . "' WHERE `note_id`='" . $id . "'"; } if(isset($_REQUEST["delete"])){ //request to delete a note $note_id = (int) $_REQUEST["note_id"]; $result = query(sql_deleteNote($note_id)); $ret = array(); $ret["error"] = false; echo json_encode($ret); }else if(isset($_REQUEST["edit"])){ // request to modify subj/body of a note $note_id = (int) $_REQUEST["note_id"]; $subject = $_REQUEST["subject"]; $body = $_REQUEST["body"]; $dt = gmdate("Y-m-d H:i:s"); $result = query(sql_editNote($note_id, $subject, $body, $dt)); $ret = array(); $ret["error"] = false; $ret["dt_modified"] = $dt; echo json_encode($ret); }else if(isset($_REQUEST["add"])){