0) { $favorite = array(); $favorite['username'] = WT_GEDCOM; $favorite['gid'] = $gid; $favorite['type'] = trim($match[2]); $favorite['file'] = WT_GEDCOM; $favorite['url'] = ''; $favorite['note'] = $favnote; $favorite['title'] = ''; self::addFavorite($favorite); } } if ($url) { if (empty($favtitle)) $favtitle = $url; $favorite = array(); $favorite['username'] = WT_GEDCOM; $favorite['gid'] = ''; $favorite['type'] = 'URL'; $favorite['file'] = WT_GEDCOM; $favorite['url'] = $url; $favorite['note'] = $favnote; $favorite['title'] = $favtitle; self::addFavorite($favorite); } unset($_GET['action']); break; } $block=get_block_setting($block_id, 'block', false); if ($cfg) { foreach (array('block') as $name) { if (array_key_exists($name, $cfg)) { $$name=$cfg[$name]; } } } // Override GEDCOM configuration temporarily if (isset($show_full)) $saveShowFull = $show_full; $savePedigreeFullDetails = $PEDIGREE_FULL_DETAILS; $show_full = 1; $PEDIGREE_FULL_DETAILS = 1; $userfavs = self::getUserFavorites(WT_GEDCOM); if (!is_array($userfavs)) $userfavs = array(); $id=$this->getName().$block_id; $title=$this->getTitle(); if (WT_USER_IS_ADMIN && $ENABLE_AUTOCOMPLETE) { // TODO: do we really need to load jquery again? $content = ' '; } else $content = ''; if ($block) { $style = 2; // 1 means "regular box", 2 means "wide box" $tableWidth = ($BROWSERTYPE=='msie') ? '95%' : '99%'; // IE needs to have room for vertical scroll bar inside the box $cellSpacing = '1px'; } else { $style = 2; $tableWidth = '99%'; $cellSpacing = '3px'; } if ($userfavs) { $content .= ""; foreach ($userfavs as $key=>$favorite) { if (isset($favorite['id'])) $key=$favorite['id']; $removeFavourite = "".WT_I18N::translate('Remove')."
"; $content .= '"; } $content .= "
'; if ($favorite['type']=='URL') { $content .= "
"; if ($ctype=='user' || WT_USER_GEDCOM_ADMIN) $content .= $removeFavourite; $content .= "".PrintReady($favorite['title']).''; $content .= "
".PrintReady($favorite["note"]); $content .= "
"; } else { $record=WT_GedcomRecord::getInstance($favorite['gid']); if ($record && $record->canDisplayDetails()) { if ($favorite["type"]=="INDI") { $indirec = find_person_record($favorite["gid"], WT_GED_ID); $content .= "
"; if ($ctype=="user" || WT_USER_GEDCOM_ADMIN) $content .= $removeFavourite; ob_start(); print_pedigree_person($record, $style, 1, $key); $content .= ob_get_clean(); $content .= PrintReady($favorite["note"]); $content .= "
"; } else { $record=WT_GedcomRecord::getInstance($favorite['gid']); $content .= "
"; if ($ctype=="user" || WT_USER_GEDCOM_ADMIN) $content .= $removeFavourite; if ($record) { $content.=$record->format_list('span'); } else { $content.=WT_I18N::translate('No such ID exists in this GEDCOM file.'); } $content .= "
".PrintReady($favorite["note"]); $content .= "
"; } } } $content .= "
"; } if (WT_USER_GEDCOM_ADMIN) { $content .= '
'; $uniqueID = floor(microtime() * 1000000); $content .= "\"\" ".WT_I18N::translate('Add a new favorite').""; $content .= "
"; $content .= "
"; $content .= ""; $content .= ""; $content .= ""; $content .= ""; $content .= "
".WT_I18N::translate('Enter a Person, Family, or Source ID')."
"; $content .= ""; $content .= print_findindi_link("gid{$uniqueID}",'',true); $content .= print_findfamily_link("gid{$uniqueID}",'',true); $content .= print_findsource_link("gid{$uniqueID}",'',true); $content .= print_findrepository_link("gid{$uniqueID}",'',true); $content .= print_findnote_link("gid{$uniqueID}",'',true); $content .= print_findmedia_link("gid{$uniqueID}",'1','',true); $content .= "
".WT_I18N::translate('OR
Enter a URL and a title'); $content .= ""; $content .= "
".WT_Gedcom_Tag::getLabel('URL')."
".WT_I18N::translate('Title:')."
"; if ($block) $content .= "

"; else $content .= "
"; $content .= "".WT_I18N::translate('Enter an optional note about this favorite'); $content .= "
"; $content .= "
"; $content .= "
"; $content .= "
"; } if ($template) { if ($block) { require WT_THEME_DIR.'templates/block_small_temp.php'; } else { require WT_THEME_DIR.'templates/block_main_temp.php'; } } else { return $content; } // Restore GEDCOM configuration unset($show_full); if (isset($saveShowFull)) $show_full = $saveShowFull; $PEDIGREE_FULL_DETAILS = $savePedigreeFullDetails; } // Implement class WT_Module_Block public function loadAjax() { return false; } // Implement class WT_Module_Block public function isUserBlock() { return false; } // Implement class WT_Module_Block public function isGedcomBlock() { return true; } // Implement class WT_Module_Block public function configureBlock($block_id) { if (safe_POST_bool('save')) { set_block_setting($block_id, 'block', safe_POST_bool('block')); echo WT_JS_START, 'window.opener.location.href=window.opener.location.href;window.close();', WT_JS_END; exit; } require_once WT_ROOT.'includes/functions/functions_edit.php'; $block=get_block_setting($block_id, 'block', false); echo ''; echo /* I18N: label for a yes/no option */ WT_I18N::translate('Add a scrollbar when block contents grow'); echo ''; echo edit_field_yes_no('block', $block); echo ''; } /** * deleteFavorite * deletes a favorite in the database * @param int $fv_id the id of the favorite to delete */ public static function deleteFavorite($fv_id) { return (bool) WT_DB::prepare("DELETE FROM `##favorites` WHERE fv_id=?") ->execute(array($fv_id)); } /** * stores a new favorite in the database * @param array $favorite the favorite array of the favorite to add */ public static function addFavorite($favorite) { // -- make sure a favorite is added if (empty($favorite["gid"]) && empty($favorite["url"])) return false; //-- make sure this is not a duplicate entry $sql = "SELECT 1 FROM `##favorites` WHERE"; if (!empty($favorite["gid"])) { $sql.=" fv_gid=?"; $vars=array($favorite["gid"]); } else { $sql.=" fv_url=?"; $vars=array($favorite["url"]); } $sql.=" AND fv_file=? AND fv_username=?"; $vars[]=$favorite["file"]; $vars[]=$favorite["username"]; if (WT_DB::prepare($sql)->execute($vars)->fetchOne()) { return false; } //-- add the favorite to the database return (bool) WT_DB::prepare("INSERT INTO `##favorites` (fv_username, fv_gid, fv_type, fv_file, fv_url, fv_title, fv_note) VALUES (?, ? ,? ,? ,? ,? ,?)") ->execute(array($favorite['username'], $favorite['gid'], $favorite['type'], $favorite['file'], $favorite['url'], $favorite['title'], $favorite['note'])); } // Get a family tree's favorites public static function getUserFavorites($gedcom) { return WT_DB::prepare( "SELECT fv_id AS id, fv_username AS username, fv_gid AS gid, fv_type AS type, fv_file AS file, fv_title AS title, fv_note AS note, fv_url AS url". " FROM `##favorites` WHERE fv_username=?") ->execute(array($gedcom)) ->fetchAll(PDO::FETCH_ASSOC); } }