diff options
| author | fisharebest <fisharebest@gmail.com> | 2010-05-12 18:02:44 +0000 |
|---|---|---|
| committer | fisharebest <fisharebest@gmail.com> | 2010-05-12 18:02:44 +0000 |
| commit | ccf91e120a8099f216b109277444926485f68e36 (patch) | |
| tree | 8a1afc20580bdfdeb755511c1d149147929080e9 /modules/user_favorites/module.php | |
| parent | 1dc29368a477203270953fd023e74aaa324da7fc (diff) | |
| download | webtrees-ccf91e120a8099f216b109277444926485f68e36.tar.gz webtrees-ccf91e120a8099f216b109277444926485f68e36.tar.bz2 webtrees-ccf91e120a8099f216b109277444926485f68e36.zip | |
Convert blocks to modules
Diffstat (limited to 'modules/user_favorites/module.php')
| -rw-r--r-- | modules/user_favorites/module.php | 238 |
1 files changed, 232 insertions, 6 deletions
diff --git a/modules/user_favorites/module.php b/modules/user_favorites/module.php index 4b2073c89e..2f9a6c8f65 100644 --- a/modules/user_favorites/module.php +++ b/modules/user_favorites/module.php @@ -22,8 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * @package webtrees - * @subpackage Modules * @version $Id: class_media.php 5451 2009-05-05 22:15:34Z fisharebest $ */ @@ -46,12 +44,240 @@ class user_favorites_WT_Module extends WT_Module implements WT_Module_Block { } // Implement class WT_Module_Block - public function getBlock($block, $config, $side, $index) { - // Generate the block contents + public function getBlock($block_id) { + global $WT_IMAGE_DIR, $WT_IMAGES, $GEDCOM, $TEXT_DIRECTION, $INDEX_DIRECTORY, $MEDIA_DIRECTORY, $MULTI_MEDIA, $MEDIA_DIRECTORY_LEVELS, $ctype; + global $show_full, $PEDIGREE_FULL_DETAILS, $BROWSERTYPE, $ENABLE_AUTOCOMPLETE; + + $action=safe_GET('action'); + switch ($action) { + case 'deletefav': + $fv_id=safe_GET('fv_id'); + if ($fv_id) { + deleteFavorite($fv_id); + } + break; + case 'addfav': + $gid =safe_GET('gid'); + $favnote =safe_GET('favnote'); + $favtype =safe_GET('favtype'); + $url =safe_GET('url', WT_REGEX_URL); + $favtitle=safe_GET('favtitle'); + + if ($gid) { + $indirec = find_gedcom_record($gid, WT_GED_ID); + $ct = preg_match('/0 @(.*)@ (.*)/', $indirec, $match); + if ($indirec && $ct>0) { + $favorite = array(); + if (empty($favtype)) { + if ($ctype=='user') $favtype = 'user'; + else $favtype = 'gedcom'; + } + if ($favtype=='gedcom') { + $favtype = $GEDCOM; + $_SESSION['clearcache'] = true; + } + else $favtype=WT_USER_NAME; + $favorite['username'] = $favtype; + $favorite['gid'] = $gid; + $favorite['type'] = trim($match[2]); + $favorite['file'] = $GEDCOM; + $favorite['url'] = ''; + $favorite['note'] = $favnote; + $favorite['title'] = ''; + addFavorite($favorite); + } + } + $url=safe_GET('url'); + if ($url) { + if (empty($favtitle)) $favtitle = $url; + $favorite = array(); + if (!isset($favtype)) { + if ($ctype=='user') $favtype = 'user'; + else $favtype = 'gedcom'; + } + if ($favtype=='gedcom') { + $favtype = $GEDCOM; + $_SESSION['clearcache'] = true; + } + else $favtype=WT_USER_NAME; + $favorite['username'] = $favtype; + $favorite['gid'] = ''; + $favorite['type'] = 'URL'; + $favorite['file'] = $GEDCOM; + $favorite['url'] = $url; + $favorite['note'] = $favnote; + $favorite['title'] = $favtitle; + addFavorite($favorite); + } + break; + } + + $block=get_block_setting($block_id, 'block', false); + + // Override GEDCOM configuration temporarily + if (isset($show_full)) $saveShowFull = $show_full; + $savePedigreeFullDetails = $PEDIGREE_FULL_DETAILS; + $show_full = 1; + $PEDIGREE_FULL_DETAILS = 1; + + $userfavs = getUserFavorites(WT_USER_NAME); + if (!is_array($userfavs)) $userfavs = array(); + + $id=$this->getName().$block_id; + $title=i18n::translate('My Favorites').help_link('mygedview_favorites'); + if ($TEXT_DIRECTION=="rtl") $title .= getRLM(); + $title .= "(".count($userfavs).")"; + if ($TEXT_DIRECTION=="rtl") $title .= getRLM(); + + if ($ENABLE_AUTOCOMPLETE) { + $content = '<script type="text/javascript" src="js/jquery/jquery.min.js"></script> + <script type="text/javascript" src="js/jquery/jquery.autocomplete.js"></script> + <script type="text/javascript" src="js/jquery/jquery.ajaxQueue.js"></script> + <script type="text/javascript"> + jQuery.noConflict(); // @see http://docs.jquery.com/Using_jQuery_with_Other_Libraries/ + jQuery(document).ready(function($){ + $("input[name^=gid]").autocomplete("autocomplete.php", { + extraParams: {field:"IFSRO"}, + formatItem: function(row, i) { + return row[0] + " (" + row[1] + ")"; + }, + formatResult: function(row) { + return row[1]; + }, + width: 400, + minChars: 2 + }); + }); + </script>'; + } 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 (count($userfavs)==0) { + $content .= i18n::translate('You have not selected any favorites.<br /><br />To add an individual, a family, or a source to your favorites, click on the <b>Add a new favorite</b> link to reveal some fields where you can enter or search for an ID number. Instead of an ID number, you can enter a URL and a title.'); + } else { + $mygedcom = $GEDCOM; + $current_gedcom = $GEDCOM; + $content .= "<table width=\"{$tableWidth}\" style=\"border:none\" cellspacing=\"{$cellSpacing}\" class=\"center $TEXT_DIRECTION\">"; + foreach($userfavs as $key=>$favorite) { + if (isset($favorite["id"])) $key=$favorite["id"]; + $removeFavourite = "<a class=\"font9\" href=\"".encode_url("index.php?ctype={$ctype}&action=deletefav&fv_id={$key}")."\" onclick=\"return confirm('".i18n::translate('Are you sure you want to remove this item from your list of Favorites?')."');\">".i18n::translate('Remove')."</a><br />"; + $current_gedcom = $GEDCOM; + $GEDCOM = $favorite["file"]; + $content .= "<tr><td>"; + if ($favorite["type"]=="URL") { + $content .= "<div id=\"boxurl".$key.".0\" class=\"person_box\">"; + if ($ctype=="user" || WT_USER_IS_ADMIN) $content .= $removeFavourite; + $content .= "<a href=\"".$favorite["url"]."\">".PrintReady($favorite["title"])."</a>"; + $content .= "<br />".PrintReady($favorite["note"]); + } else { + require $INDEX_DIRECTORY.$GEDCOM.'_conf.php'; + $indirec = find_gedcom_record($favorite["gid"], WT_GED_ID); + if ($favorite["type"]=="INDI") { + $content .= "<div id=\"box".$favorite["gid"].".0\" class=\"person_box"; + if (strpos($indirec, "\n1 SEX F")!==false) $content .= "F"; + elseif (strpos($indirec, "\n1 SEX M")!==false) $content .= ""; + else $content .= "NN"; + $content .= "\">"; + if ($ctype=="user" || WT_USER_IS_ADMIN) $content .= $removeFavourite; + ob_start(); + print_pedigree_person($favorite["gid"], $style, 1, $key); + $content .= ob_get_clean(); + $content .= PrintReady($favorite["note"]); + } else { + $record=GedcomRecord::getInstance($favorite['gid']); + $content .= "<div id=\"box".$favorite["gid"].".0\" class=\"person_box\">"; + if ($ctype=="user" || WT_USER_IS_ADMIN) $content .= $removeFavourite; + if ($record) { + $content.=$record->format_list('span'); + } else { + $content.=i18n::translate('No such ID exists in this GEDCOM file.'); + } + $content .= "<br />".PrintReady($favorite["note"]); + } + } + $content .= "</div>"; + $content .= "</td></tr>"; + $GEDCOM = $mygedcom; + require $INDEX_DIRECTORY.$GEDCOM.'_conf.php'; + } + $content .= "</table>"; + } + $content .= ' + <script language="JavaScript" type="text/javascript"> + var pastefield; + function paste_id(value) { + pastefield.value=value; + } + </script> + <br /> + '; + $uniqueID = floor(microtime() * 1000000); + $content .= "<b><a href=\"javascript: ".i18n::translate('Add a new favorite')." \" onclick=\"expand_layer('add_user_fav'); return false;\"><img id=\"add_user_fav_img\" src=\"".$WT_IMAGE_DIR."/".$WT_IMAGES["plus"]["other"]."\" border=\"0\" alt=\"\" /> ".i18n::translate('Add a new favorite')."</a></b>"; + $content .= help_link('index_add_favorites'); + $content .= "<br /><div id=\"add_user_fav\" style=\"display: none;\">"; + $content .= "<form name=\"addufavform\" method=\"get\" action=\"index.php\">"; + $content .= "<input type=\"hidden\" name=\"action\" value=\"addfav\" />"; + $content .= "<input type=\"hidden\" name=\"ctype\" value=\"$ctype\" />"; + $content .= "<input type=\"hidden\" name=\"favtype\" value=\"user\" />"; + $content .= "<input type=\"hidden\" name=\"ged\" value=\"$GEDCOM\" />"; + $content .= "<table width=\"{$tableWidth}\" style=\"border:none\" cellspacing=\"{$cellSpacing}\" class=\"center $TEXT_DIRECTION\">"; + $content .= "<tr><td>".i18n::translate('Enter a Person, Family, or Source ID')." <br />"; + $content .= "<input class=\"pedigree_form\" type=\"text\" name=\"gid\" id=\"gid{$uniqueID}\" size=\"5\" value=\"\" />"; + + $content .= print_findindi_link("gid{$uniqueID}",'',true)."\n"; + $content .= print_findfamily_link("gid{$uniqueID}",'',true)."\n"; + $content .= print_findsource_link("gid{$uniqueID}",'',true)."\n"; + $content .= print_findrepository_link("gid{$uniqueID}",'',true)."\n"; + $content .= print_findnote_link("gid{$uniqueID}",'',true)."\n"; + $content .= print_findmedia_link("gid{$uniqueID}",'1','',true)."\n"; + + $content .= "<br />".i18n::translate('OR<br />Enter a URL and a title'); + $content .= "<table><tr><td>".translate_fact('URL')."</td><td><input type=\"text\" name=\"url\" size=\"40\" value=\"\" /></td></tr>"; + $content .= "<tr><td>".i18n::translate('Title:')."</td><td><input type=\"text\" name=\"favtitle\" size=\"40\" value=\"\" /></td></tr></table>"; + if ($block) $content .= "\n</td></tr><tr><td><br />"; + else $content .= "\n</td><td>"; + $content .= i18n::translate('Enter an optional note about this favorite'); + $content .= "<br /><textarea name=\"favnote\" rows=\"6\" cols=\"50\"></textarea>"; + $content .= "</td></tr></table>"; + $content .= "<br /><input type=\"submit\" value=\"".i18n::translate('Add')."\" style=\"font-size: 8pt; \" />"; + $content .= "</form></div>"; + + global $THEME_DIR; + if ($block) { + require $THEME_DIR.'templates/block_small_temp.php'; + } else { + require $THEME_DIR.'templates/block_main_temp.php'; + } + // Restore GEDCOM configuration + unset($show_full); + if (isset($saveShowFull)) $show_full = $saveShowFull; + $PEDIGREE_FULL_DETAILS = $savePedigreeFullDetails; + } + + // Implement class WT_Module_Block + public function canLoadAjax() { + return false; + } + + // Implement class WT_Module_Block + public function isUserBlock() { + return true; + } + + // Implement class WT_Module_Block + public function isGedcomBlock() { + return false; } // Implement class WT_Module_Block - public function configureBlock() { - // Create an edit form, and respond to the result + public function configureBlock($block_id) { } } |
