private function save_notes(&$form, $level, $event) { if (!isset($form['person']['notes']) || !is_array($form['person']['notes'])) { // no notes return true; } // Notes switch ($level) { case "relation": $tabNot = JTable::getInstance('joaktree_relation_notes', 'Table'); if ($form['person']['id'] < $form['person']['relations']['id'][0]) { $tabNot->person_id_1 = $form['person']['id']; $tabNot->person_id_2 = $form['person']['relations']['id'][0]; } else { $tabNot->person_id_2 = $form['person']['id']; $tabNot->person_id_1 = $form['person']['relations']['id'][0]; } break; case "person": // person same as default // person same as default default: $tabNot = JTable::getInstance('joaktree_person_notes', 'Table'); $tabNot->person_id = $form['person']['id']; break; } $tabNot->app_id = $form['person']['app_id']; $indNotesTable = JoaktreeHelper::getIndNotesTable($tabNot->app_id); if ($indNotesTable) { $tabNot2 = JTable::getInstance('joaktree_notes', 'Table'); $tabNot2->app_id = $form['person']['app_id']; } for ($i = 0; $i < count($form['person']['notes']['orderNumber']); $i++) { // person $tabNot->orderNumber = $form['person']['notes']['orderNumber'][$i]; $tabNot->indCitation = false; if ($event == 'name') { $tabNot->nameOrderNumber = $form['person']['notes']['objectOrderNumber'][$i]; $tabNot->eventOrderNumber = null; } else { if ($event == 'event') { $tabNot->nameOrderNumber = null; $tabNot->eventOrderNumber = $form['person']['notes']['objectOrderNumber'][$i]; } else { $tabNot->nameOrderNumber = null; $tabNot->eventOrderNumber = null; } } if (isset($form['person']['notes']['text'][$i])) { $noteText = str_replace($form['lineEnd'], " ", htmlspecialchars($form['person']['notes']['text'][$i], ENT_QUOTES, 'UTF-8')); } else { $noteText = null; } if ($indNotesTable) { if (isset($form['person']['notes']['note_id'][$i])) { $tabNot->note_id = $form['person']['notes']['note_id'][$i]; } else { // retreive ID and double check that it is not used $continue = true; $i = 0; while ($continue) { $tmpId = JoaktreeHelper::generateJTId(); $i++; if ($this->check($tmpId, 'note')) { $tabNot->note_id = $tmpId; $continue = false; break; } if ($i > 100) { $continue = false; return false; } } } $tabNot2->id = $tabNot->note_id; $tabNot2->value = $noteText; } else { $tabNot->value = $noteText; } // Make sure the table is valid if (!$tabNot->check()) { $this->setError('Error checking note: '); return false; } if ($form['person']['notes']['status'][$i] == 'new' || $form['person']['notes']['status'][$i] == 'loaded') { // Store the table to the database if (!$tabNot->store(false)) { $this->setError('Error saving note (1): ' . $tabNot->getError()); return false; } if ($indNotesTable) { if (!$tabNot2->store(false)) { $this->setError('Error saving note (2): ' . $tabNot2->getError()); return false; } } } else { if ($form['person']['notes']['status'][$i] == 'loaded_deleted') { // Delete row from the database if ($indNotesTable) { if (!$tabNot2->delete()) { $this->setError('Error deleting note (2): ' . $tabNot2->getError()); return false; } } if (!$tabNot->delete()) { $this->setError('Error deleting note (1): ' . $tabNot->getError()); return false; } } } } return true; }