Search:


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Measuring metabolic rates (876K)
Measuring
metabolic
rates


steller sea lion research
Steller sea lion research > Nutritional Stress >Effects of Diet Changes >Physiological Measures

Physiological Measures and the health of Steller sea lions

Researchers have been using a number of different methods to study the effect of different diets on the physical condition and health of Steller sea lions. One is to measure morphology, such as the length, weight and thickness of the blubber layer. Another is to assess the nutritional status from hormones and other elements contained within blood samples, in the same way that doctors can tell a lot about human health by drawing a sample of blood. Some of these studies are conducted on wild Steller sea lions in the wild and others use a group of trained sea lions in captivity.

Diet Manipulations

In the wild, Steller sea lions eat a number of different types of fish and invertebrates. Recent scientific research suggests that the type of prey available to Steller sea lions in the North Pacific may be changing. Different prey, such as herring or pollock, provide different amounts of energy to the animal. (see Assessing Prey Quality)

To help determine the possible effects of diet changes, the regular diet of the sea lions at the Vancouver Aquarium was switched from herring to Atka Mackerel pollock and squid, which have less energy. Changes in the food intake, body mass, and metabolism of the sea lions are then carefully monitored. Results indicate that lower quality prey, such as pollock, requires more energy to digest than a higher quality diet of herring. Additionally, the sea lions appear unable to maintain body mass when switched to a lower calorie prey such as squid or pollock, and need to compensate by conserving energy. It appears that the sea lions do not compensate for low energy food sources by increasing their food intake. Instead they seem to use up more of their own energy stores (i.e., they lose weight), and they spend less energy (i.e., they lower their resting metabolism).

Dr. Rosen (UBC) has been assessing the metabolic adaptations employed to combat periods of low food intake. Additional data have been collected on how body composition changes during periods of fasting. Initial results suggest that sea lion's physiological response to low-food conditions may be both seasonal and age-dependent.

Morphology
One way of estimating the health or condition of a pinniped is to measure the thickness of the layer of blubber that lies just below the skin. Calipers measure skinfold thickness and provide a reliable estimate of fat thickness in humans. Researchers Andrew Trites (UBC) and Remko Jonker (UBC) sought to determine whether this simple and inexpensive device could be used to measure the condition of Steller sea lion pups in the wild. They measured the skinfold thickness of dead pups found on the breeding beaches of Alaska. They discovered that heavy pups had higher skinfold thickness than lighter pups. However, this relationship was true for pups with blubber as well as pups that had died of starvation (no blubber). Therefore, skinfold thickness appears to change with body mass rather than condition. These results suggest caliper pinches do not provide a reliable measure of condition in Steller sea lion pups, and alternate methods must be explored.

Blood Chemistry
A co-operative research project with Dr. Lorrie Rea (ADF&G) investigated the effects of fasting and reduced food intake on several physiological parameters. Five juvenile Steller sea lions at the Vancouver Aquarium underwent a 2-week fast and a 4-week period of 50% food intake; the pups fasted for 3 days. The amount of food the animals received was similar to conditions they would experience in the wild. Dr. Rea used blood samples from these sea lions to evaluate the differences in blood chemistry reported in wild Steller sea lions from areas of stable and declining populations. The aim was to determine whether differences in blood biochemistry (e.g., blood urea nitrogen and ketone bodies) reflect nutritional status.

 

Hormones
Tania Zenteno-Savin (UAF) completed her Ph.D. thesis which focused on three vasoactive hormones - AVP, ANP and ANG II - found in blood plasma. Humans suffering from eating disorders (anorexia, bulimia) have elevated levels of these hormones. It was therefore speculated that Steller sea lions might exhibit similar changes in their blood hormone levels if they are suffering from nutritional stress. To test this hypothesis, blood samples were collected and analyzed from nearly 200 Steller sea lions in Southeast and Northwest Alaska. A concurrent experiment was also run with the captive Stellers at the Vancouver Aquarium to determine how fasting or food restriction affected blood hormone levels.

In the controlled study, ANG II rose in response to food restrictions. AVP was unaffected, while ANP seemed to decline. These feeding experiments seem to indicate that blood hormones do provide some gauge of how well a Steller has been eating . However, in the wild Stellers, ANG II levels were higher in the thriving southeast population compared to the declining Aleutian population. This is not consistent with the hypothesis that Steller sea lions in the western population are nutritionally stressed.

Teeth
The teeth of sea lions have annual growth annuli (rings much like in trees), which scientists have been using to age individuals. However, Dr. David Sampson (OSU) thinks that the chemical composition of the teeth can yield even more information. His idea is that changes in the physical or chemical structure of the teeth can be used to date specific life-history events, such as weaning, the onset of maturity, or age at first lactation. Dr. Roger Nielson (OSU) has been using an electron microprobe to measure the elemental micro-composition of teeth obtained from dead Steller sea lions and from the National Marine Mammal Laboratory (NMFS). This initial study will determine whether archived teeth can be used to reconstruct changes in life history parameters which may provide insight into what happened to Steller sea lions.   NEXT: Predation and the decline of the steller sea lion population>>>

 

close-up image of teeth

 

 

   

id = ""; $this->alias = ""; $this->category = ""; $this->section = ""; $this->subsection = ""; $this->author = ""; $this->xauthor = ""; $this->author_brief = ""; $this->title = ""; $this->xtitle = ""; $this->abstract= ""; $this->xabstract= ""; $this->keywords = ""; $this->xkeywords = ""; $this->status = ""; $this->xstatus = ""; $this->view = ""; $this->xview = ""; $this->year_start = ""; $this->year_end = ""; $this->debug = ""; $this->limit = ""; $this->xrecord_number = ""; $this->ref = ""; $this->cat = ""; $this->method = ""; $this->xreference_type = ""; $this->xsecondary_author = ""; $this->xpublisher = ""; $this->xplace_published = ""; $this->xjournal_secondary_title = ""; $this->xyear = ""; $this->xvolume = ""; $this->xedition = ""; $this->xtype_of_work = ""; $this->xpages = ""; $this->xurl = ""; $this->xlocation = ""; $this->xlanguage = ""; $this->url = ""; $this->language = ""; $this->xbibliography_number = ""; $this->xtertiary_author = ""; $this->xtertiary_title = ""; $this->xdate = ""; $this->xsubsidiary_author = ""; $this->xalternate_title = ""; $this->xisbn_issn = ""; $this->xcall_number = ""; $this->xaccession_number = ""; $this->xcustom1 = ""; $this->xcustom2 = ""; $this->xcustom3 = ""; $this->xcustom4 = ""; $this->xlabel = ""; $this->xnotes = ""; $this->xurl2 = ""; $this->xlocation2 = ""; $this->xupdate_time = ""; $this->xupdate_user = ""; $this->xadd_time = ""; $this->xadd_user = ""; $this->expcat = ""; $this->expsec = ""; $this->expsub = ""; $this->so = ""; $this->varString = ""; } # end of method PageVars->clearVars() function clearRefVars() { #$this->id = ""; #$this->alias = ""; #$this->category = ""; #$this->section = ""; #$this->subsection = ""; #$this->author = ""; $this->xauthor = ""; #$this->title = ""; $this->xtitle = ""; #$this->abstract= ""; $this->xabstract= ""; #$this->keywords = ""; $this->xkeywords = ""; #$this->status = ""; $this->xstatus = ""; #$this->view = ""; $this->xview = ""; #$this->year_start = ""; #$this->year_end = ""; #$this->debug = ""; #$this->limit = ""; $this->xrecord_number = ""; #$this->ref = ""; #$this->method = ""; $this->xreference_type = ""; $this->xsecondary_author = ""; $this->xpublisher = ""; $this->xplace_published = ""; $this->xjournal_secondary_title = ""; $this->xyear = ""; $this->xvolume = ""; $this->xedition = ""; $this->xtype_of_work = ""; $this->xpages = ""; $this->xurl = ""; $this->xlocation = ""; $this->xlanguage = ""; $this->xbibliography_number = ""; $this->xtertiary_author = ""; $this->xtertiary_title = ""; $this->xdate = ""; $this->xsubsidiary_author = ""; $this->xalternate_title = ""; $this->xisbn_issn = ""; $this->xcall_number = ""; $this->xaccession_number = ""; $this->xcustom1 = ""; $this->xcustom2 = ""; $this->xcustom3 = ""; $this->xcustom4 = ""; $this->xlabel = ""; $this->xnotes = ""; $this->xurl2 = ""; $this->xlocation2 = ""; $this->xupdate_time = ""; $this->xupdate_user = ""; $this->xadd_time = ""; $this->xadd_user = ""; #$this->url = ""; #$this->expcat = ""; #$this->expsec = ""; #$this->expsub = ""; #$this->so = ""; $this->varString = $this->buildVars(); } # end of method PageVars->clearRefVars() function getVars() { global $default_sort_order; $this->id = $this->getVarbl("id"); $this->alias = $this->getVarbl("alias"); $this->category = $this->getVarbl("category"); $this->section = $this->getVarbl("section"); if (empty($this->section)) $this->section = $this->getVarbl("section2"); $this->subsection = $this->getVarbl("subsection"); $this->author = $this->getVarbl("author"); if (empty($this->author)) $this->author = $this->getVarbl("author2"); $this->xauthor = $this->getVarbl("xauthor"); $this->title = $this->getVarbl("title"); $this->xtitle = $this->getVarbl("xtitle"); $this->abstract= $this->getVarbl("abstract"); $this->xabstract= $this->getVarbl("xabstract"); $this->keywords = $this->getVarbl("keywords"); $this->xkeywords = $this->getVarbl("xkeywords"); $this->status = $this->getVarbl("status"); $this->xstatus = $this->getVarbl("xstatus"); $this->view = $this->getVarbl("view"); $this->xview = $this->getVarbl("xview"); $this->year_start = $this->getVarbl("year_start"); $this->year_end = $this->getVarbl("year_end"); if (($this->year_end < $this->year_start) and !empty($this->year_end)) { # User error, swap them around $tmpyr = $this->year_end; $this->year_end = $this->year_start; $this->year_start = $tmpyr; } $this->debug = $this->getVarbl("debug"); $this->limit = $this->getVarbl("limit"); $this->xrecord_number = $this->getVarbl("xrecord_number"); $this->ref = $this->getVarbl("ref"); $this->cat = $this->getVarbl("cat"); $this->method = $this->getVarbl("method"); $this->url = $this->getVarbl("url"); $this->language = $this->getVarbl("language"); $this->xreference_type = $this->getVarbl("xreference_type"); $this->xsecondary_author = $this->getVarbl("xsecondary_author"); $this->xpublisher = $this->getVarbl("xpublisher"); $this->xplace_published = $this->getVarbl("xplace_published"); $this->xjournal_secondary_title = $this->getVarbl("xjournal_secondary_title"); $this->xyear = $this->getVarbl("xyear"); $this->xvolume = $this->getVarbl("xvolume"); $this->xedition = $this->getVarbl("xedition"); $this->xtype_of_work = $this->getVarbl("xtype_of_work"); $this->xpages = $this->getVarbl("xpages"); $this->xurl = $this->getVarbl("xurl"); $this->xlocation = $this->getVarbl("xlocation"); $this->xlanguage = $this->getVarbl("xlanguage"); $this->xbibliography_number = $this->getVarbl("xbibliography_number"); $this->xtertiary_author = $this->getVarbl("xtertiary_author"); $this->xtertiary_title = $this->getVarbl("xtertiary_title"); $this->xdate = $this->getVarbl("xdate"); $this->xsubsidiary_author = $this->getVarbl("xsubsidiary_author"); $this->xalternate_title = $this->getVarbl("xalternate_title"); $this->xisbn_issn = $this->getVarbl("xisbn_issn"); $this->xcall_number = $this->getVarbl("xcall_number"); $this->xaccession_number = $this->getVarbl("xaccession_number"); $this->xcustom1 = $this->getVarbl("xcustom1"); $this->xcustom2 = $this->getVarbl("xcustom2"); $this->xcustom3 = $this->getVarbl("xcustom3"); $this->xcustom4 = $this->getVarbl("xcustom4"); $this->xlabel = $this->getVarbl("xlabel"); $this->xnotes = $this->getVarbl("xnotes"); $this->xurl2 = $this->getVarbl("xurl2"); $this->xlocation2 = $this->getVarbl("xlocation2"); $this->xupdate_time = $this->getVarbl("xupdate_time"); $this->xupdate_user = $this->getVarbl("xupdate_user"); $this->xadd_time = $this->getVarbl("xadd_time"); $this->xadd_user = $this->getVarbl("xadd_user"); $this->expcat = $this->getVarbl("expcat"); $this->expsec = $this->getVarbl("expsec"); $this->expsub = $this->getVarbl("expsub"); $this->so = $this->getVarbl("so"); $this->varString = $this->buildVars(); if (empty($this->so) or ($this->so == 1)) # year/author $default_sort_order = "reference.ref_year DESC, reference.ref_author_fmt ASC"; else if ($this->so == 2) # last updated $default_sort_order = "reference.ref_update_time DESC, reference.ref_year DESC, reference.ref_author_fmt ASC"; else if ($this->so == 3) # record number $default_sort_order = "reference.ref_record_number DESC"; if ($this->view == "all") $this->view = ""; } # end of method PageVars->getVars() function buildVars() { $varString = ""; $varStringShort=""; if (!empty($this->id)) { $varString .= "&id={$this->id}"; $varStringShort .= "&id={$this->id}"; } if (!empty($this->alias)) { $varString .= "&alias={$this->alias}"; $varStringShort .= "&alias={$this->alias}"; } if (!empty($this->category)) { $varString .= "&category={$this->category}"; $varStringShort .= "&category={$this->category}"; } if (!empty($this->section)) { $varString .= "§ion={$this->section}"; $varStringShort .= "§ion={$this->section}"; } if (!empty($this->subsection)) { $varString .= "&subsection={$this->subsection}"; $varStringShort .= "&subsection={$this->subsection}"; } if (!empty($this->author)) { $varString .= "&author={$this->author}"; $varStringShort .= "&author={$this->author}"; } if (!empty($this->xauthor)) $varString .= "&xauthor={$this->xauthor}"; if (!empty($this->title)) { $varString .= "&title={$this->title}"; $varStringShort .= "&title={$this->title}"; } if (!empty($this->xtitle)) $varString .= "&xtitle={$this->xtitle}"; if (!empty($this->abstract)) { $varString .= "&abstract={$this->abstract}"; $varStringShort .= "&abstract={$this->abstract}"; } if (!empty($this->xabstract)) $varString .= "&xabstract={$this->xabstract}"; if (!empty($this->keywords)) { $varString .= "&keywords={$this->keywords}"; $varStringShort .= "&keywords={$this->keywords}"; } if (!empty($this->xkeywords)) $varString .= "&xkeywords={$this->xkeywords}"; if (!empty($this->status)) { $varString .= "&status={$this->status}"; $varStringShort .= "&status={$this->status}"; } if (!empty($this->xstatus)) $varString .= "&xstatus={$this->xstatus}"; if (!empty($this->view)) { $varString .= "&view={$this->view}"; $varStringShort .= "&view={$this->view}"; } if (!empty($this->xview)) $varString .= "&xview={$this->xview}"; if (!empty($this->year_start)) { $varString .= "&year_start={$this->year_start}"; $varStringShort .= "&year_start={$this->year_start}"; } if (!empty($this->year_end)) { $varString .= "&year_end={$this->year_end}"; $varStringShort .= "&year_end={$this->year_end}"; } if (!empty($this->debug)) { $varString .= "&debug={$this->debug}"; $varStringShort .= "&debug={$this->debug}"; } if (!empty($this->limit)) { $varString .= "&limit={$this->limit}"; $varStringShort .= "&limit={$this->limit}"; } if (!empty($this->xrecord_number)) $varString .= "&xrecord_number={$this->xrecord_number}"; if (!empty($this->ref)) { $varString .= "&ref={$this->ref}"; $varStringShort .= "&ref={$this->ref}"; } if (!empty($this->cat)) { $varString .= "&cat={$this->cat}"; $varStringShort .= "&cat={$this->cat}"; } if (!empty($this->method)) { $varString .= "&method={$this->method}"; #$varStringShort .= "&method={$this->method}"; } if (!empty($this->xreference_type)) $varString .= "&xreference_type={$this->xreference_type}"; if (!empty($this->xsecondary_author)) $varString .= "&xsecondary_author={$this->xsecondary_author}"; if (!empty($this->xpublisher)) $varString .= "&xpublisher={$this->xpublisher}"; if (!empty($this->xplace_published)) $varString .= "&xplace_published={$this->xplace_published}"; if (!empty($this->xjournal_secondary_title)) $varString .= "&xjournal_secondary_title={$this->xjournal_secondary_title}"; if (!empty($this->xyear)) $varString .= "&xyear={$this->xyear}"; if (!empty($this->xvolume)) $varString .= "&xvolume={$this->xvolume}"; if (!empty($this->xedition)) $varString .= "&xedition={$this->xedition}"; if (!empty($this->xtype_of_work)) $varString .= "&xtype_of_work={$this->xtype_of_work}"; if (!empty($this->xpages)) $varString .= "&xpages={$this->xpages}"; if (!empty($this->xurl)) $varString .= "&xurl={$this->xurl}"; if (!empty($this->xlocation)) $varString .= "&xlocation={$this->xlocation}"; if (!empty($this->xlanguage)) $varString .= "&xlanguage={$this->xlanguage}"; if (!empty($this->xbibliography_number)) $varString .= "&xbibliography_number={$this->xbibliography_number}"; if (!empty($this->xtertiary_author)) $varString .= "&xtertiary_author={$this->xtertiary_author}"; if (!empty($this->xtertiary_title)) $varString .= "&xtertiary_title={$this->xtertiary_title}"; if (!empty($this->xdate)) $varString .= "&xdate={$this->xdate}"; if (!empty($this->xsubsidiary_author)) $varString .= "&xsubsidiary_author={$this->xsubsidiary_author}"; if (!empty($this->xalternate_title)) $varString .= "&xalternate_title={$this->xalternate_title}"; if (!empty($this->xisbn_issn)) $varString .= "&xisbn_issn={$this->xisbn_issn}"; if (!empty($this->xcall_number)) $varString .= "&xcall_number={$this->xcall_number}"; if (!empty($this->xaccession_number)) $varString .= "&xaccession_number={$this->xaccession_number}"; if (!empty($this->xcustom1)) $varString .= "&xcustom1={$this->xcustom1}"; if (!empty($this->xcustom2)) $varString .= "&xcustom2={$this->xcustom2}"; if (!empty($this->xcustom3)) $varString .= "&xcustom3={$this->xcustom3}"; if (!empty($this->xcustom4)) $varString .= "&xcustom4={$this->xlocxcustom4ation}"; if (!empty($this->xlabel)) $varString .= "&xlabel={$this->xlabel}"; if (!empty($this->xnotes)) $varString .= "&xnotes={$this->xnotes}"; if (!empty($this->xurl2)) $varString .= "&xurl2={$this->xurl2}"; if (!empty($this->xlocation2)) $varString .= "&xlocation2={$this->xlocation2}"; if (!empty($this->xupdate_time)) $varString .= "&xupdate_time={$this->xupdate_time}"; if (!empty($this->xupdate_user)) $varString .= "&xupdate_user={$this->xupdate_user}"; if (!empty($this->xadd_time)) $varString .= "&xadd_time={$this->xadd_time}"; if (!empty($this->xadd_user)) $varString .= "&xadd_user={$this->xadd_user}"; if (!empty($this->expcat)) { $varString .= "&expcat={$this->expcat}"; $varStringShort .= "&expcat={$this->expcat}"; } if (!empty($this->expsec)) { $varString .= "&expsec={$this->expsec}"; $varStringShort .= "&expsec={$this->expsec}"; } if (!empty($this->expsub)) { $varString .= "&expsub={$this->expsub}"; $varStringShort .= "&expsub={$this->expsub}"; } if (!empty($this->so)) { $varString .= "&so={$this->so}"; $varStringShort .= "&so={$this->so}"; } if (!empty($varString)) $varString = (str_replace("?&", "?", "?".$varString)); if (!empty($varStringShort)) $varStringShort = (str_replace("?&", "?", "?".$varStringShort)); $this->varString = $varString; $this->varStringShort = $varStringShort; if ($this->debug) echo "PageVars->buildvars: varString={$varString}
"; return $varString; } # end of method PageVars->buildVars() function getVarbl($name) { global $$name; $retVal = $$name; # echo "$name='{$retVal}'
"; if (empty($retVal)) { if(empty($_GET)) $retVal = $_POST[$name]; else if(empty($_POST)) $retVal = $_GET[$name]; } return trim(str_replace("%20", " ", $retVal)); } # end of method PageVars->getVarbl() } # end of class PageVars $pv = new PageVars; $pv->err_code = 0; $pv->getVars(); class RefRecord { // Class Variables var $record_number; var $author; var $author_fmt; var $title; var $abstract; var $keywords; var $status; var $reference_type; var $reference_view; var $secondary_author; var $publisher; var $place_published; var $journal_secondary_title; var $year; var $volume; var $edition; var $type_of_work; var $pages; var $url; var $location; var $language; var $bibliography_number, $tertiary_author, $tertiary_title, $zdate, $subsidiary_author, $alternate_title, $isbn_issn, $call_number; var $accession_number, $custom1, $custom2, $custom3, $custom4, $label, $notes, $url2, $location2; var $update_time, $update_user, $add_time, $add_user; function clear_fields() { $this->record_number=0; $this->author=""; $this->author_fmt=""; $this->author_brief = ""; $this->title=""; $this->abstract=""; $this->keywords=""; $this->status="in press"; $this->reference_type="Journal Article"; $this->referencce_view="internal"; $this->secondary_author=""; $this->publisher=""; $this->place_published=""; $this->journal_secondary_title=""; $this->year=""; $this->volume=""; $this->edition=""; $this->type_of_work=""; $this->pages=""; $this->url=""; $this->location="default"; $this->language="English"; $this->bibliography_number = ""; $this->tertiary_author = ""; $this->tertiary_title = ""; $this->zdate = ""; $this->subsidiary_author = ""; $this->alternate_title = ""; $this->isbn_issn = ""; $this->call_number = ""; $this->accession_number = ""; $this->custom1 = ""; $this->custom2 = ""; $this->custom3 = ""; $this->custom4 = ""; $this->label = ""; $this->notes = ""; $this->url2 = ""; $this->location2 = "default"; $this->update_time = ""; $this->update_user = ""; $this->add_time = ""; $this->add_user = ""; } # end of method $RefRecord->clear_fields() function get_fields() { global $refTBL; $this->record_number = stripslashes(trim($refTBL->GetField(ref_record_number))); $this->title = stripslashes(trim($refTBL->GetField(ref_title))); $this->author = stripslashes(trim($refTBL->GetField(ref_author))); $this->author_fmt = stripslashes(trim($refTBL->GetField(ref_author_fmt))); $this->author_brief = stripslashes(trim($refTBL->GetField(ref_author_brief))); $this->abstract = stripslashes($refTBL->GetField(ref_abstract)); $this->keywords = stripslashes(trim($refTBL->GetField(ref_keywords))); $this->status = stripslashes(trim($refTBL->GetField(ref_status))); $this->reference_type = stripslashes(trim($refTBL->GetField(ref_reference_type))); $this->view = stripslashes(trim($refTBL->GetField(ref_view))); $this->secondary_author = stripslashes(trim($refTBL->GetField(ref_secondary_author))); $this->publisher = stripslashes(trim($refTBL->GetField(ref_publisher))); $this->place_published = stripslashes(trim($refTBL->GetField(ref_place_published))); $this->journal_secondary_title = stripslashes(trim($refTBL->GetField(ref_journal_secondary_title))); $this->year = stripslashes(trim($refTBL->GetField(ref_year))); $this->volume = stripslashes(trim($refTBL->GetField(ref_volume))); $this->edition = stripslashes(trim($refTBL->GetField(ref_edition))); $this->type_of_work = stripslashes(trim($refTBL->GetField(ref_type_of_work))); $this->pages = stripslashes(trim($refTBL->GetField(ref_pages))); $this->url = stripslashes(trim($refTBL->GetField(ref_url))); $this->language = stripslashes(trim($refTBL->GetField(ref_language))); $this->location = stripslashes(trim($refTBL->GetField(ref_location))); $this->bibliography_number = stripslashes(trim($refTBL->GetField(ref_bibliography_number))); $this->tertiary_author = stripslashes(trim($refTBL->GetField(ref_tertiary_author))); $this->tertiary_title = stripslashes(trim($refTBL->GetField(ref_tertiary_title))); $this->zdate = stripslashes(trim($refTBL->GetField(ref_date))); $this->subsidiary_author = stripslashes(trim($refTBL->GetField(ref_subsidiary_author))); $this->alternate_title = stripslashes(trim($refTBL->GetField(ref_alternate_title))); $this->isbn_issn = stripslashes(trim($refTBL->GetField(ref_isbn_issn))); $this->call_number = stripslashes(trim($refTBL->GetField(ref_call_number))); $this->accession_number = stripslashes(trim($refTBL->GetField(ref_accession_number))); $this->custom1 = stripslashes(trim($refTBL->GetField(ref_custom1))); $this->custom2 = stripslashes(trim($refTBL->GetField(ref_custom2))); $this->custom3 = stripslashes(trim($refTBL->GetField(ref_custom3))); $this->custom4 = stripslashes(trim($refTBL->GetField(ref_custom4))); $this->label = stripslashes(trim($refTBL->GetField(ref_label))); $this->notes = stripslashes(trim($refTBL->GetField(ref_notes))); $this->url2 = stripslashes(trim($refTBL->GetField(ref_url2))); $this->location2 = stripslashes(trim($refTBL->GetField(ref_location2))); $this->update_time = stripslashes(trim($refTBL->GetField(ref_update_time))); $this->update_user = stripslashes(trim($refTBL->GetField(ref_update_user))); $this->add_time = stripslashes(trim($refTBL->GetField(ref_add_time))); $this->add_user = stripslashes(trim($refTBL->GetField(ref_add_user))); } # end of method RefRecord->get_fields() function nextRecord() { global $refTBL; return $refTBL->NextRow(); } # end of method $RefRecord->nextRecord() function query($query_string, $criteria, $order, $numrefs, $db) { global $refTBL, $numrefs, $pv; # build query string and query the reference table $query = build_db_query_string($query_string, $criteria, $order, $db); # debug if ($pv->debug) echo "ref->query: sql={$query}
"; $success = $refTBL->Query( $query ); if ( ! $success ) echo "Error on Query. Error={$success}
\nQuery={$query}
\n"; $numrefs = $refTBL->NumRows(); if ( ! $numrefs ) { #echo "There were no publications found matching those criteria
\n"; #echo "Query string: '{$query}'
\n"; } } # end of method $RefRecord->query() function format_fields() { global $fmt_ref_record_number, $fmt_authors, $fmt_autors_brief, $fmt_authors_brief, $fmt_title, $fmt_abstract, $fmt_keywords; global $fmt_year_status, $fmt_secondary_author, $fmt_source_in_title; global $fmt_source_journal, $fmt_source_publisher, $fmt_pp, $fmt_pdf_link; global $fmt_file_type_gif, $fmt_default_abstract_gif; global $pdf_location, $default_file_type_loc, $default_abstract_gif; $this->get_fields(); $fmt_ref_record_number = $this->record_number; # format authors $fmt_authors = formatted_names($this->author_fmt, 1); # format foreign words in title $fmt_title = trim(str_replace("{i", "", str_replace("i}", "", $this->title))); //if (!empty($fmt_title)) $fmt_title = preg_replace("/([^.?!])\$/", "$1.", $fmt_title); if (!empty($fmt_title)) { $fmt_title = str_replace("{b", "", str_replace("b}", "", $fmt_title)); $fmt_title = str_replace("{u", "", str_replace("u}", "", $fmt_title)); $fmt_title = str_replace("{s", "", str_replace("s}", "", $fmt_title)); $fmt_title = $fmt_title."."; $fmt_title = str_replace("..", ".", $fmt_title); $fmt_title = str_replace("?.", "?", $fmt_title); $fmt_title = str_replace("!.", "!", $fmt_title); } # format the abstract $fmt_abstract = trim(str_replace("{i", "", str_replace("i}", "", $this->abstract))); $fmt_abstract = trim(str_replace("{b", "", str_replace("b}", "", $fmt_abstract))); $fmt_abstract = trim(str_replace("{u", "", str_replace("u}", "", $fmt_abstract))); $fmt_abstract = trim(str_replace("{s", "", str_replace("s}", "", $fmt_abstract))); # format the keywords $fmt_keywords = trim(str_replace("{i", "", str_replace("i}", "", $this->keywords))); $fmt_keywords = trim(str_replace("{b", "", str_replace("b}", "", $fmt_keywords))); $fmt_keywords = trim(str_replace("{u", "", str_replace("u}", "", $fmt_keywords))); $fmt_keywords = trim(str_replace("{s", "", str_replace("s}", "", $fmt_keywords))); # format year or status $fmt_year_status = ""; if (! empty($this->year)) { if (ereg("([0-9]{4})", $this->year)) $fmt_year_status .= " {$this->year}"; else $fmt_year_status .= " ({$this->year})"; } elseif (! empty($this->status)) $fmt_year_status .= " ({$this->status})"; # format authors_brief $fmt_authors_brief = $this->author_brief; # format journal name, or other source details $fmt_secondary_author = ""; $fmt_source_in_title = ""; $fmt_source_journal = ""; $fmt_source_publisher = ""; if ($this->reference_type == "Journal Article") { # Journal articles if ($this->journal_secondary_title) $fmt_source_journal .= "{$this->journal_secondary_title}"; } else { # formatting for all references other than journal articles # format secondary author list if (!empty($this->secondary_author)) { # if secondary_title given, add "In" before secondary authors. if (!empty($this->journal_secondary_title)) $fmt_secondary_author .= "In "; $fmt_secondary_author .= formatted_names($this->secondary_author, 2); if (strpos("%Book Section%Edited Book%Conference Proceedings%", "%{$this->reference_type}%") !== false) if (strpos($fmt_secondary_author, " and ") === false) $fmt_secondary_author.= " (ed.)"; else $fmt_secondary_author.= " (eds)"; $fmt_secondary_author.= ", "; } # format secondary title if (!empty($this->journal_secondary_title)) { # make sure the secondary title ends in a full stop $this->journal_secondary_title = trim($this->journal_secondary_title) . "."; $this->journal_secondary_title = str_replace("?.", "?", $this->journal_secondary_title); $this->journal_secondary_title = str_replace("!.", "!", $this->journal_secondary_title); $this->journal_secondary_title = str_replace("..", ".", $this->journal_secondary_title); $fmt_source_journal .= "".$this->journal_secondary_title." "; if (empty($this->secondary_author)) $fmt_source_journal = "In {$fmt_source_journal}"; } # format type_of_work, publisher and place_published if (trim($this->reference_type) == "Thesis" && !empty($this->type_of_work)) { $fmt_source_publisher .= " {$this->type_of_work}"; if (!empty($this->publisher) or !empty($this->place_published)) $fmt_source_publisher .= ","; else $fmt_source_publisher .= "."; } if (!empty($this->publisher)) { $fmt_source_publisher .= " {$this->publisher}"; if (!empty($this->place_published)) $fmt_source_publisher .= ","; else $fmt_source_publisher .= "."; # replace '.,' with ',' if at end of publisher # N.B. this will wrongly remove the full stop from the end of abbreviated publisher names. Can't be helped. $fmt_source_publisher = str_replace(".,",",",$fmt_source_publisher); } $this->place_published = trim($this->place_published); if (!empty($this->place_published)) $fmt_source_publisher .= " {$this->place_published}."; # remove double full stops $fmt_source_publisher = str_replace("..",".",$fmt_source_publisher); } # end of formatting for all references other than journal articles # format the volume, issue and page numbers $fmt_pp = ""; if (!empty($this->volume)) { if (strpos($this->pages, "-") === false) $fmt_pp.= " Vol"; $fmt_pp.= " {$this->volume}"; if (!empty($this->edition)) $fmt_pp.= "({$this->edition})"; if (!empty($this->pages) && (strpos($this->pages, "-") !== false || strpos($this->pages, "e") !== false)) $fmt_pp.= ":{$this->pages}."; elseif (strpos("%Book%Edited Book%Thesis%", "%{$this->reference_type}%") !== false && !empty($this->pages)) $fmt_pp.= " {$this->pages} pages"; elseif (!empty($this->pages)) $fmt_pp.= " pp. {$this->pages} "; } elseif (!empty($this->pages) && strpos($this->pages, "-") !== false) $fmt_pp.= " pp. {$this->pages}."; elseif (strpos("%Book%Edited Book%Thesis%", "%{$this->reference_type}%") !== false && !empty($this->pages)) $fmt_pp.= " {$this->pages} pages"; elseif (!empty($this->pages)) $fmt_pp.= " pp. {$this->pages} "; # format the pdf link $fmt_pdf_link = ""; $fmt_file_type_gif = ""; #if (!empty($this->url)) #{ if (($this->location == "default") or (empty($this->location))) # $fmt_pdf_link = "{$pdf_location}/{$this->url}"; # else # $fmt_pdf_link = "{$this->location}/{$this->url}"; # $fmt_file_type_gif = build_file_type_gif($this->url); #} if (!empty($this->url)) { if ((trim($this->location) == "default") or empty($this->location)) # url has file, but use default location $fmt_pdf_link = "{$pdf_location}/{$this->url}"; else # url has file and location not default $fmt_pdf_link = "{$this->location}/{$this->url}"; } else if ((trim($this->location) != "default") and !empty($this->location)) # url empty, but location provided $fmt_pdf_link = $this->location; $fmt_file_type_gif = build_file_type_gif($fmt_pdf_link); $fmt_default_abstract_gif = $default_file_type_loc.$default_abstract_gif; } # end of method $RefRecord->format_fields() function add_record() { global $refTBL; $fields = ""; $values = ""; if (empty($this->author_fmt) and !empty($this->author)) $this->author_fmt = $this->author; $this->author_fmt = encoded_names($this->author_fmt); $this->secondary_author = encoded_names($this->secondary_author); if (strpos("%in prep%submitted%in review%in press%published%", "%{$this->year}%") > 0) $this->year = $this->status; if (empty($this->year)) $this->year = $this->status; $this->author_brief = formatted_names($this->author_fmt, 3)." ({$this->year})"; $values .= "'".addslashes($this->record_number)."', "; $fields .= "ref_record_number, "; $values .= "'".addslashes($this->title)."', "; $fields .= "ref_title, "; #$values .= "'".addslashes($this->author)."', "; #$fields .= "ref_author, "; $values .= "'".addslashes($this->author_fmt)."', "; $fields .= "ref_author_fmt, "; $values .= "'".addslashes($this->author_brief)."', "; $fields .= "ref_author_brief, "; $values .= "'".addslashes($this->abstract)."', "; $fields .= "ref_abstract, "; $values .= "'".addslashes($this->keywords)."', "; $fields .= "ref_keywords, "; $values .= "'".addslashes($this->status)."', "; $fields .= "ref_status, "; $values .= "'".addslashes($this->reference_type)."', "; $fields .= "ref_reference_type, "; $values .= "'".addslashes($this->view)."', "; $fields .= "ref_view, "; $values .= "'".addslashes($this->secondary_author)."', "; $fields .= "ref_secondary_author, "; $values .= "'".addslashes($this->publisher)."', "; $fields .= "ref_publisher, "; $values .= "'".addslashes($this->place_published)."', "; $fields .= "ref_place_published, "; $values .= "'".addslashes($this->journal_secondary_title)."', "; $fields .= "ref_journal_secondary_title, "; $values .= "'".addslashes($this->year)."', "; $fields .= "ref_year, "; $values .= "'".addslashes($this->volume)."', "; $fields .= "ref_volume, "; $values .= "'".addslashes($this->edition)."', "; $fields .= "ref_edition, "; $values .= "'".addslashes($this->type_of_work)."', "; $fields .= "ref_type_of_work, "; $values .= "'".addslashes($this->pages)."', "; $fields .= "ref_pages, "; $values .= "'".addslashes($this->url)."', "; $fields .= "ref_url, "; $values .= "'".addslashes($this->location)."', "; $fields .= "ref_location, "; $values .= "'".addslashes($this->language)."', "; $fields .= "ref_language, "; $values .= "'".addslashes($this->bibliography_number)."', "; $fields .= "ref_bibliography_number, "; $values .= "'".addslashes($this->tertiary_author)."', "; $fields .= "ref_tertiary_author, "; $values .= "'".addslashes($this->tertiary_title)."', "; $fields .= "ref_tertiary_title, "; $values .= "'".addslashes($this->zdate)."', "; $fields .= "ref_date, "; $values .= "'".addslashes($this->subsidiary_author)."', "; $fields .= "ref_subsidiary_author, "; $values .= "'".addslashes($this->alternate_title)."', "; $fields .= "ref_alternate_title, "; $values .= "'".addslashes($this->isbn_issn)."', "; $fields .= "ref_isbn_issn, "; $values .= "'".addslashes($this->call_number)."', "; $fields .= "ref_call_number, "; $values .= "'".addslashes($this->accession_number)."', "; $fields .= "ref_accession_number, "; $values .= "'".addslashes($this->custom1)."', "; $fields .= "ref_custom1, "; $values .= "'".addslashes($this->custom2)."', "; $fields .= "ref_custom2, "; $values .= "'".addslashes($this->custom3)."', "; $fields .= "ref_custom3, "; $values .= "'".addslashes($this->custom4)."', "; $fields .= "ref_custom4, "; $values .= "'".addslashes($this->label)."', "; $fields .= "ref_label, "; $values .= "'".addslashes($this->notes)."', "; $fields .= "ref_notes, "; $values .= "'".addslashes($this->url2)."', "; $fields .= "ref_url2, "; $values .= "'".addslashes($this->location2)."', "; $fields .= "ref_location2, "; $values .= "'".$_SESSION['username']."', "; $fields .= "ref_update_user, "; $values .= "NOW(), "; $fields .= "ref_add_time, "; $values .= "'".$_SESSION['username']."'"; $fields .= "ref_add_user"; $sql = "INSERT INTO `reference` ({$fields}) VALUES ({$values});"; # DEBUG if ($pv->debug) echo "sql='{$sql}'
\n"; $success = $refTBL->Query($sql); if ( ! $success ) echo "Error adding reference. Error={$success}
\n"; return $success; } # end of method $RefRecord->add_record() function update_record() { global $refTBL, $pv; $fields = ""; if (empty($this->author_fmt) and !empty($this->author)) $this->author_fmt = $this->author; $this->author_fmt = encoded_names($this->author_fmt); $this->secondary_author = encoded_names($this->secondary_author); if (strpos("%in prep%submitted%in review%in press%published%", "%{$this->year}%") > 0) $this->year = $this->status; if (empty($this->year)) $this->year = $this->status; $this->author_brief = formatted_names($this->author_fmt, 3)." ({$this->year})"; $fields .= "ref_title='".addslashes($this->title)."', "; #$fields .= "ref_author='".addslashes($this->author)."', "; $fields .= "ref_author_fmt='".addslashes($this->author_fmt)."', "; $fields .= "ref_author_brief='".addslashes($this->author_brief)."', "; $fields .= "ref_abstract='".addslashes($this->abstract)."', "; $fields .= "ref_keywords='".addslashes($this->keywords)."', "; $fields .= "ref_status='".addslashes($this->status)."', "; $fields .= "ref_reference_type='".addslashes($this->reference_type)."', "; $fields .= "ref_view='".addslashes($this->view)."', "; $fields .= "ref_secondary_author='".addslashes($this->secondary_author)."', "; $fields .= "ref_publisher='".addslashes($this->publisher)."', "; $fields .= "ref_place_published='".addslashes($this->place_published)."', "; $fields .= "ref_journal_secondary_title='".addslashes($this->journal_secondary_title)."', "; $fields .= "ref_year='".addslashes($this->year)."', "; $fields .= "ref_volume='".addslashes($this->volume)."', "; $fields .= "ref_edition='".addslashes($this->edition)."', "; $fields .= "ref_type_of_work='".addslashes($this->type_of_work)."', "; $fields .= "ref_pages='".addslashes($this->pages)."', "; $fields .= "ref_url='".addslashes($this->url)."', "; $fields .= "ref_location='".addslashes($this->location)."', "; $fields .= "ref_language='".addslashes($this->language)."', "; $fields .= "ref_bibliography_number='".addslashes($this->bibliography_number)."', "; $fields .= "ref_tertiary_author='".addslashes($this->tertiary_author)."', "; $fields .= "ref_tertiary_title='".addslashes($this->tertiary_title)."', "; $fields .= "ref_date='".addslashes($this->zdate)."', "; $fields .= "ref_subsidiary_author='".addslashes($this->subsidiary_author)."', "; $fields .= "ref_alternate_title='".addslashes($this->alternate_title)."', "; $fields .= "ref_isbn_issn='".addslashes($this->isbn_issn)."', "; $fields .= "ref_call_number='".addslashes($this->call_number)."', "; $fields .= "ref_accession_number='".addslashes($this->accession_number)."', "; $fields .= "ref_custom1='".addslashes($this->custom1)."', "; $fields .= "ref_custom2='".addslashes($this->custom2)."', "; $fields .= "ref_custom3='".addslashes($this->custom3)."', "; $fields .= "ref_custom4='".addslashes($this->custom4)."', "; $fields .= "ref_label='".addslashes($this->label)."', "; $fields .= "ref_notes='".addslashes($this->notes)."', "; $fields .= "ref_url2='".addslashes($this->url2)."', "; $fields .= "ref_location2='".addslashes($this->location2)."', "; $fields .= "ref_update_user='".addslashes($_SESSION['username'])."'"; $sql = "UPDATE `reference` SET {$fields} WHERE ref_record_number={$this->record_number};"; # DEBUG if ($pv->debug) echo "sql='{$sql}'
\n"; $success = $refTBL->Query($sql); if ( ! $success ) echo "Error updating reference. Error={$success}
\n"; return $success; } # end of method $RefRecord->update_record() function update_fields() { # this function takes the unformatted field from ref_author, formats it, and puts it into ref_author_fmt global $criteria, $pv, $order; $tmp_criteria = $criteria; $tmp_limit = $pv->limit; $tmp_order = $order; # year, author_fmt # $criteria = "reference.ref_year IS NULL OR reference.ref_author_fmt IS NULL"; # author_brief # $criteria = "reference.ref_author_brief IS NULL"; # year, author_fmt, author_brief $criteria = "reference.ref_year IS NULL OR reference.ref_author_fmt IS NULL OR reference.ref_author_brief IS NULL or reference.ref_update_user = 'force'"; $pv->limit = "1"; $order = "none"; $sort_order = "none"; $this->query($query_string, $criteria, $sort_order, $numrefs, 7); $more_recs = $this->nextRecord(); while ($more_recs) { set_time_limit(2); $this->get_fields(); if (empty($this->year)) $this->year = $this->status; if (empty($this->author) and !empty($this->author_fmt)) $this->author = $this->author_fmt; if (empty($this->author_fmt)) $this->author_fmt = encoded_names($this->author); if (empty($this->author_brief)) $this->author_brief = formatted_names($this->author_fmt, 3)." ({$this->year})"; $this->update_record(); $this->query($query_string, $criteria, $sort_order, $numrefs, 7); $more_recs = $this->nextRecord(); } set_time_limit(5); $pv->limit = $tmp_limit; $criteria = $tmp_criteria; $order = $tmp_order; $pv->err_code = 0; $pv->err_msg = "Reference validation has successfully completed."; return true; } # end of method $RefRecord->update_fields() } # end of Class RefRecord $refRec = new RefRecord; function build_pdf_location($pdf_loc) { global $default_pdf_location; $pdf_loc = trim($pdf_loc); if (empty($pdf_loc) or trim($pdf_loc) == "default") $pdf_loc = trim($default_pdf_location); return $pdf_loc; } # end of function build_pdf_location() function build_file_type_gif($file_name) { global $default_file_type_gif, $default_file_type_loc; if (empty($file_name)) return(""); $link_gif = $default_file_type_gif; if (preg_match("/\.csv[^\/]*$/i", $file_name)) $link_gif = "txls.gif"; else if (preg_match("/\.csv[^\/]*$/i", $file_name)) $link_gif = "txls.gif"; else if (preg_match("/\.doc[^\/]*$/i", $file_name)) $link_gif = "tdoc.gif"; else if (preg_match("/\.htm[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; else if (preg_match("/\.htt[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; else if (preg_match("/\.pdf[^\/]*$/i", $file_name)) $link_gif = "tpdf.gif"; else if (preg_match("/\.ppt[^\/]*$/i", $file_name)) $link_gif = "tppt.gif"; else if (preg_match("/\.xl[^\/]*$/i", $file_name)) $link_gif = "txls.gif"; else if (preg_match("/\.zip[^\/]*$/i", $file_name)) $link_gif = "tzip.gif"; #else if (preg_match("/\.ade[^\/]*$/i", $file_name)) $link_gif = "tdbf.gif"; #else if (preg_match("/\.adp[^\/]*$/i", $file_name)) $link_gif = "tdbf.gif"; else if (preg_match("/\.arc[^\/]*$/i", $file_name)) $link_gif = "tzip.gif"; else if (preg_match("/\.arj[^\/]*$/i", $file_name)) $link_gif = "tzip.gif"; else if (preg_match("/\.asa[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; else if (preg_match("/\.asf[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.asp[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; else if (preg_match("/\.avi[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.bas[^\/]*$/i", $file_name)) $link_gif = "tpgm.gif"; else if (preg_match("/\.bmp[^\/]*$/i", $file_name)) $link_gif = "tgif.gif"; else if (preg_match("/\.cab[^\/]*$/i", $file_name)) $link_gif = "tzip.gif"; else if (preg_match("/\.cda[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.cfm[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; else if (preg_match("/\.cgi[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; else if (preg_match("/\.cls[^\/]*$/i", $file_name)) $link_gif = "tpgm.gif"; else if (preg_match("/\.cpp[^\/]*$/i", $file_name)) $link_gif = "tpgm.gif"; else if (preg_match("/\.csv[^\/]*$/i", $file_name)) $link_gif = "txls.gif"; #else if (preg_match("/\.ctl[^\/]*$/i", $file_name)) $link_gif = "tpgm.gif"; else if (preg_match("/\.db[^\/]*$/i", $file_name)) $link_gif = "tdbf.gif"; #else if (preg_match("/\.dic[^\/]*$/i", $file_name)) $link_gif = "ttxt.gif"; #else if (preg_match("/\.dif[^\/]*$/i", $file_name)) $link_gif = "txls.gif"; #else if (preg_match("/\.dob[^\/]*$/i", $file_name)) $link_gif = "tpgm.gif"; else if (preg_match("/\.doc[^\/]*$/i", $file_name)) $link_gif = "tdoc.gif"; #else if (preg_match("/\.dot[^\/]*$/i", $file_name)) $link_gif = "tdoc.gif"; else if (preg_match("/\.exc[^\/]*$/i", $file_name)) $link_gif = "ttxt.gif"; else if (preg_match("/\.frm[^\/]*$/i", $file_name)) $link_gif = "tpgm.gif"; else if (preg_match("/\.gif[^\/]*$/i", $file_name)) $link_gif = "tgif.gif"; else if (preg_match("/\.gz[^\/]*$/i", $file_name)) $link_gif = "tzip.gif"; else if (preg_match("/\.ht[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; #else if (preg_match("/\.h[^\/]*$/i", $file_name)) $link_gif = "tpgm.gif"; else if (preg_match("/\.jar[^\/]*$/i", $file_name)) $link_gif = "tpgm.gif"; else if (preg_match("/\.jfif[^\/]*$/i", $file_name)) $link_gif = "tgif.gif"; else if (preg_match("/\.jpe[^\/]*$/i", $file_name)) $link_gif = "tgif.gif"; else if (preg_match("/\.js[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; else if (preg_match("/\.log[^\/]*$/i", $file_name)) $link_gif = "ttxt.gif"; #else if (preg_match("/\.lzh[^\/]*$/i", $file_name)) $link_gif = "tzip.gif"; else if (preg_match("/\.m1v[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.m2v[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.m3u[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.m4e[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.m1v[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.md[^\/]*$/i", $file_name)) $link_gif = "tdbf.gif"; else if (preg_match("/\.mid[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.mim[^\/]*$/i", $file_name)) $link_gif = "tzip.gif"; else if (preg_match("/\.mmm[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.mns[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.mov[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.mp[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.nws[^\/]*$/i", $file_name)) $link_gif = "ttxt.gif"; #else if (preg_match("/\.pag[^\/]*$/i", $file_name)) $link_gif = "tpgm.gif"; else if (preg_match("/\.pdf[^\/]*$/i", $file_name)) $link_gif = "tpdf.gif"; else if (preg_match("/\.pdx[^\/]*$/i", $file_name)) $link_gif = "tpdf.gif"; else if (preg_match("/\.php[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; else if (preg_match("/\.plg[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; else if (preg_match("/\.pothtml[^\/]*$/i", $file_name)) $link_gif = "tppt.gif"; else if (preg_match("/\.ppa[^\/]*$/i", $file_name)) $link_gif = "tppt.gif"; else if (preg_match("/\.pps[^\/]*$/i", $file_name)) $link_gif = "tppt.gif"; else if (preg_match("/\.ppt[^\/]*$/i", $file_name)) $link_gif = "tppt.gif"; else if (preg_match("/\.psd[^\/]*$/i", $file_name)) $link_gif = "tgif.gif"; else if (preg_match("/\.qt[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.ra[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.rec[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.rm[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.ra[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.rtf[^\/]*$/i", $file_name)) $link_gif = "tdoc.gif"; else if (preg_match("/\.rv[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.scp[^\/]*$/i", $file_name)) $link_gif = "ttxt.gif"; else if (preg_match("/\.shtml[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; else if (preg_match("/\.snd[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.spl[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; else if (preg_match("/\.ssm[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.stm[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; else if (preg_match("/\.stz[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.swf[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; else if (preg_match("/\.tar[^\/]*$/i", $file_name)) $link_gif = "tzip.gif"; else if (preg_match("/\.taz[^\/]*$/i", $file_name)) $link_gif = "tzip.gif"; else if (preg_match("/\.tgz[^\/]*$/i", $file_name)) $link_gif = "tzip.gif"; else if (preg_match("/\.tiff[^\/]*$/i", $file_name)) $link_gif = "tgif.gif"; else if (preg_match("/\.txt[^\/]*$/i", $file_name)) $link_gif = "ttxt.gif"; else if (preg_match("/\.url[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; else if (preg_match("/\.uu[^\/]*$/i", $file_name)) $link_gif = "tzip.gif"; #else if (preg_match("/\.vb[^\/]*$/i", $file_name)) $link_gif = "tpgm.gif"; #else if (preg_match("/\.vb[^\/]*$/i", $file_name)) $link_gif = "tpgm.gif"; else if (preg_match("/\.wa[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.wm[^\/]*$/i", $file_name)) $link_gif = "tplay.gif"; else if (preg_match("/\.wri[^\/]*$/i", $file_name)) $link_gif = "tdoc.gif"; else if (preg_match("/\.wtx[^\/]*$/i", $file_name)) $link_gif = "ttxt.gif"; else if (preg_match("/\.xsdf[^\/]*$/i", $file_name)) $link_gif = "tpdf.gif"; else if (preg_match("/\.xif[^\/]*$/i", $file_name)) $link_gif = "tgif.gif"; else if (preg_match("/\.xl[^\/]*$/i", $file_name)) $link_gif = "txls.gif"; else if (preg_match("/\.xml[^\/]*$/i", $file_name)) $link_gif = "tweb2.gif"; else if (preg_match("/\.z[^\/]*$/i", $file_name)) $link_gif = "tzip.gif"; $link_gif = $default_file_type_loc.$link_gif; return($link_gif); } # end of function build_file_type_gif() function build_db_query_string($query, $criteria, $order, $db) { global $default_sql_query, $default_sort_order; global $pv; # db 1 = ref, 2 = cat, 4 = refcat, 7 = all three if ($db==2 or $db==7) $alias_str = parse_sql_criteria("c1.cat_alias", "AND", "=", $pv->alias); if ($db==2 or $db==7) $category_str = parse_sql_criteria("categories.cat_category", "AND", "=", $pv->category); if ($db==2 or $db==7) $section_str = parse_sql_criteria("categories.cat_section", "AND", "=", $pv->section); if ($db==2 or $db==7) $subsection_str = parse_sql_criteria("categories.cat_sub_section", "AND", "=", $pv->subsection); $criteria_str = trim($criteria); if ($db==1 or $db==7) $year_start_str = parse_sql_criteria("reference.ref_year", "", ">=", $pv->year_start); if ($db==1 or $db==7) $year_end_str = parse_sql_criteria("reference.ref_year", "", "<=", $pv->year_end); if (!empty($pv->author) and ($db==1 or $db==7)) $author_str = " ( reference.ref_author_fmt LIKE \"%{$pv->author},%\" " . "OR reference.ref_author_fmt LIKE \"%{$pv->author};%\" " . "OR reference.ref_author_fmt LIKE \"%{$pv->author}.%\" " . "OR reference.ref_author_fmt LIKE \"%{$pv->author}\" " . "OR reference.ref_author_fmt LIKE \"%{$pv->author} %\" ) "; if ($db==1 or $db==7) $title_str = parse_sql_criteria("reference.ref_title", "AND", "LIKE", $pv->title); if ($db==1 or $db==7) $abstract_str = parse_sql_criteria("reference.ref_abstract", "AND", "LIKE", $pv->abstract); if ($db==1 or $db==7) $keywords_str = parse_sql_criteria("reference.ref_keywords", "AND", "LIKE", $pv->keywords); if ($db==1 or $db==7) $status_str = parse_sql_criteria("reference.ref_status", "AND", "=", $pv->status); if ($db==1 or $db==7) $view_str = parse_sql_criteria("reference.ref_view", "AND", "=", $pv->view); # if an end year is given, and it is less than this year, exclude status of "in press" $in_press_str = ""; if (!empty($year_end_str) and trim($pv->year_end) < date("Y") and ($db==1 or $db==7)) { #$in_press_str = parse_sql_criteria("reference.ref_status", "", "<>", "in press"); #$in_press_conj = "AND"; } elseif (!empty($year_end_str) and ($db==1 or $db==7)) { #$in_press_str = parse_sql_criteria("reference.ref_status", "", "=", "in press"); #$in_press_conj = "OR"; } # otherwise if a start year is given, and no end year is given, include status of "in press" elseif (empty($year_end_str) == 0 and !empty($year_start_str) and trim($pv->year_start) <= date("Y") and ($db==1 or $db==7)) {# $in_press_str = parse_sql_criteria("reference.ref_status", "", "=", "in press"); # $in_press_conj = "OR"; } # merge category, section and subsection into alias $section_str = concat_criteria($section_str, "AND", $subsection_str); $category_str = concat_criteria($category_str, "AND", $section_str); $alias_str = concat_criteria($alias_str, "AND", $category_str); $criteria_str = concat_criteria($criteria_str, "AND", $alias_str); $year_start_str = concat_criteria($year_start_str, "AND", $year_end_str); $year_start_str = concat_criteria($in_press_str, $in_press_conj, $year_start_str); $criteria_str = concat_criteria($year_start_str, "AND", $criteria_str); $criteria_str = concat_criteria($author_str, "AND", $criteria_str); $criteria_str = concat_criteria($title_str, "AND", $criteria_str); $criteria_str = concat_criteria($abstract_str, "AND", $criteria_str); $criteria_str = concat_criteria($keywords_str, "AND", $criteria_str); $criteria_str = concat_criteria($status_str, "AND", $criteria_str); $criteria_str = concat_criteria($view_str, "AND", $criteria_str); $criteria_str = concat_criteria($ref_str, "AND", $criteria_str); if (!empty($criteria_str)) $criteria_str = " WHERE {$criteria_str} "; # translate sort order into sql $order_str = trim($order); if ($order_str == "none") $order_str = ""; elseif (empty($order_str)) $order_str = trim($default_sort_order); if (!empty($order_str)) $order_str = " ORDER BY {$order_str}"; $limit_str = trim($pv->limit); if (! empty($limit_str)) $limit_str = " LIMIT {$limit_str}"; # put all the parts together to create the sql query string if (!empty($query)) $sql = trim($query); else $sql = trim($default_sql_query); if (!empty($pv->alias) and ($db==7)) $sql = "SELECT DISTINCT reference.* FROM `reference`"; if (!empty($pv->alias) and ($db==7)) $sql .= " LEFT JOIN ref_categories AS rc1 ON reference.ref_record_number=rc1.rc_reference LEFT JOIN categories AS c1 ON rc1.rc_category = c1.cat_key"; if (($db==7) and (!empty($pv->cat) or !empty($category_str) or !empty($section_str) or !empty($sub_section_str))) $sql .= " LEFT JOIN ref_categories ON reference.ref_record_number=ref_categories.rc_reference LEFT JOIN categories ON ref_categories.rc_category = categories.cat_key"; $sql .= $criteria_str . $order_str . $limit_str; # DEBUG if ($pv->debug) echo "build_db_query_string: query='{$sql}'

"; # DEBUG2 if ($pv->debug) echo "build_db_query_string: default query = '{$default_sql_query}', default order = '{$default_sort_order}'
"; return $sql; } # function build_db_query_string() function concat_criteria($criteria1, $conjunction, $criteria2) { if (!empty($criteria1) and !empty($criteria2)) { if ($conjunction == "OR") $criteria1 = "({$criteria1} {$conjunction} {$criteria2})"; else $criteria1 .= " {$conjunction} {$criteria2}"; } elseif (!empty($criteria2)) $criteria1 = $criteria2; return $criteria1; } # end of function concat_criteria() function parse_sql_criteria($field_name, $conjunction, $operation, $criteria) { $criteria_str = trim($criteria); if (empty($criteria_str) or $criteria_str == "*") $criteria_str = ""; # Get rid of all leading and trailing spaces $criteria_str = str_replace("; ", ";", $criteria_str); $criteria_str = str_replace(" ;", ";", rtrim($criteria_str, ";")); # translate into sql $bracket = ""; if ($operation == "LIKE") $bracket = "%"; $criteria_str = str_replace(";", "{$bracket}' {$conjunction} {$field_name} {$operation} '{$bracket}", $criteria_str); if (!empty($criteria_str)) $criteria_str = "{$field_name} {$operation} '{$bracket}{$criteria_str}{$bracket}'"; return $criteria_str; } # end of function parse_sql_criteria() function openDB() { global $bibDB, $usrTBL, $refTBL, $catTBL, $refcatTBL; global $db_name, $db_host, $db_user, $db_pwd; # open bibliographic reference database $bibDB = new DBConnection; $bibDB->Open( $db_name, $db_host, $db_user, $db_pwd ) or die("Error on opening database."); # transfer the connection to be used for the user table $usrTBL = new MySQLDatabase; $usrTBL->ReUseConn($bibDB->Connection()); # transfer the connection to be used for the reference table $refTBL = new MySQLDatabase; $refTBL->ReUseConn($bibDB->Connection()); # transfer the connection to be used for the category table $catTBL = new MySQLDatabase; $catTBL->ReUseConn($bibDB->Connection()); # transfer the connection to be used for the ref_categories table $refcatTBL = new MySQLDatabase; $refcatTBL->ReUseConn($bibDB->Connection()); } # end of function openDB() function closeDB() { global $bibDB; $success = $bibDB->close(); } # end of function closeDB() function nextCatRecord() { global $catTBL; return $catTBL->NextRow(); } function nextRefCatRecord() { global $refcatTBL; return $refcatTBL->NextRow(); } # end of function nextCatRecord() function queryRefCats($query_string, $criteria, $order, $numrefcats, $db) { global $refcatTBL, $numrefcats, $pv; $query = build_db_query_string($query_string, $criteria, $order, $db); # DEBUG if ($pv->debug) echo "queryRefCats: sql=\"{$query}\"
\n"; $refcatTBL->Query( $query ); # or die("Error querying ref_category table.\n"); $numrefcats = $refcatTBL->NumRows(); # DEBUG if ($pv->debug) echo "queryRefCats: this reference is in {$numrefcats} categories
\n"; # if ( ! $numrefcats > 0 ) # { echo "This reference has not been placed in any categories yet
\n"; # echo "Query string: '{$query}'
\n"; # } } # end of function queryRefCats() function get_refcat_fields($catREC) { global $rc_cat, $rc_ref; $rc_cat = $catREC->GetField(rc_category); $rc_ref = $catREC->GetField(rc_reference); } # end of function get_refcat_fields() function queryCats($query_string, $criteria, $order, $numcats, $db) { global $catTBL, $numcats, $pv; $query = build_db_query_string($query_string, $criteria, $order, $db); # DEBUG if ($pv->debug) echo "queryCats: {$query}
"; $catTBL->Query( $query ) or die("Error querying category table. query='{$query}'
\n"); $numcats = $catTBL->NumRows(); # DEBUG if ($pv->debug) echo "queryCats: there are {$numcats} categories
\n"; if ( ! $numcats > 0 ) { echo "There were no categories found matching those criteria
\n"; echo "Query string: '{$query}'
\n"; } } # end of function queryCats() function get_cat_fields($catREC) { global $cat_key, $cat_category, $cat_section, $cat_sub_section, $cat_alias, $cat_sort_order, $cat_comment; $cat_key = $catREC->GetField(cat_key); $cat_category = $catREC->GetField(cat_category); $cat_section = $catREC->GetField(cat_section); $cat_sub_section = $catREC->GetField(cat_sub_section); $cat_alias = $catREC->GetField(cat_alias); $cat_sort_order = $catREC->GetField(cat_sort_order); $cat_comment = $catREC->GetField(cat_comment); } # end of function get_cat_fields() function encoded_names($names) { # takes a semicolan separated list of names and converts it to a # semicolan separated list of names in the form of "intials surname;" to "surname,initials;" $names_str = ""; $names_array = explode(";", $names); $first = true; foreach($names_array as $key => $fullname) { $fullname = trim($fullname); if (strlen($fullname) > 30) { # if name greater than certain length, leave as is $surname = $fullname; $initials = ""; #$surname = "1".$surname; } else if (strpos($fullname, ",") !== false) { # if name contains a comma, assume encoding already done list($surname, $initials) = explode(",", $fullname, 2); #$surname = "2".$surname; } else if (strpos($fullname, ".") !== false) { # if name contains a fullstop, then assume last fullstop separates initials and surname $surname = preg_replace("/.*\.[^ ]*? /", "", $fullname); if (empty($surname)) # deal with surname then initials, no comma $surname = strrev(preg_replace("/.*\.[^ ]*? /", "", strrev($fullname))); $initials = str_replace($surname, "", $fullname); $initials = preg_replace("/([^ ]\.)( +?)([^ ]\.)/", "\$1\$3", $initials); #$surname = "3".$surname; } else { # else assume first space separates intials and surname $initials = substr($fullname, 0, strpos($fullname, " ")); $surname = substr($fullname, strlen($initials)); #$surname = "4".$surname; } $surname = trim($surname); $initials = trim($initials); #if (strlen(str_replace(" ", "", str_replace(".", "", $surname))) < strlen(str_replace(" ", "", str_replace(".", "", $initials)))) #{ #if the surname is shorter than the initials, swap them # $tmp = $initials; # $initials = $surname; # $surname = $tmp; #} if (!$first & !empty($surname) & !empty($initials)) $names_str .= "; "; if (!empty($surname)) $names_str .= $surname; if (!empty($initials)) $names_str .= ",".$initials; $first = false; } $names_str = preg_replace("/ +/", " ", $names_str); # replace any number of consecutive spaces with a single space return $names_str; } # end of function encoded_names() function formatted_names($names, $style) { # unformatted names are passed looking like "surname1,initials1;surname2,initals2" # output $style=1 "surname1, initials1, initials2 surname2, ... and intialsN surnameN" # output $style=2 "initials1 surname1, initials2 surname2, ... and intialsN surnameN" # output $style=3 "surname1, or surname1 and surname2, or surname1 et al. $tok_surname = ";"; $tok_initials = ","; $names = str_replace(" ", " ", $names); $names = str_replace(" {$tok_surname}", $tok_surname, $names); $formatted_names = ""; $names_array = explode($tok_surname, $names); $num_authors = count($names_array); foreach($names_array as $key => $fullname) { list($surname[$key], $initials[$key]) = explode($tok_initials, $fullname, 2); $surname[$key] = trim($surname[$key]); $initials[$key] = trim($initials[$key]); if (empty($surname[$key])) $surname[$key] = $initials[$key]; if (empty($formatted_names)) # first name { if ($style == 3) $formatted_names = trim(preg_replace("/\(.*\)/", "", $surname[$key])); else if ($style == 2) { if (empty($initials[$key])) $formatted_names = $surname[$key]; else $formatted_names = "{$initials[$key]} {$surname[$key]}"; } else if ($style == 1) { if (empty($initials[$key])) $formatted_names = $surname[$key]; else $formatted_names = "{$surname[$key]}, {$initials[$key]}"; } } else # not the first name { if ($style == 3) { if (($num_authors == 2) and ($key == 1)) # second author of 2 $formatted_names.= " and ".trim(preg_replace("/\(.*\)/", "", $surname[$key])); else if (($num_authors > 2) and ($key == 1)) # second author of more than 2 $formatted_names .= " et al."; # else do nothing } else # any other styles { if ($key == count($names_array) - 1) # this is the last name $formatted_names .= " and "; else $formatted_names .= ", "; if (empty($initials[$key])) $formatted_names .= $surname[$key]; else $formatted_names .= "{$initials[$key]} {$surname[$key]}"; $formatted_names = trim($formatted_names); } } } # if there the formatted names list ends in a fullstop, get rid of it. if (substr($formatted_names, strlen($formatted_names) - 1, 1) == "." and substr($formatted_names, strlen($formatted_names) - 6, 6) != "et al.") $formatted_names = substr($formatted_names, 0, strlen($formatted_names) - 1); # if (strpos($names, $tok_surname) === false) # authors already formatted # $formatted_names = $names; return $formatted_names; } # end of function formatted_names() function get_all_names() { # generate an array of surnames, to be used to dynamically create a drop down list of all authors global $refRec, $refTBL; $more_ref_records = $refRec->nextRecord(); $tok_surname = ";"; $tok_initials = ","; while ($more_ref_records) { $refRec->author_fmt = stripslashes(trim($refTBL->GetField(ref_author_fmt))); $names = $refRec->author_fmt; $names = str_replace(" ", " ", $names); $names = str_replace(" {$tok_surname}", $tok_surname, $names); #$names = str_replace(" {$tok_initials}", $tok_initials, $names); $names_list = explode($tok_surname, $names); foreach ($names_list as $key => $fullname) { list($surname, $initials) = explode($tok_initials, $fullname, 2); $reg_expr = "/\([^\)]*?\)/"; # remove words between brackets from name e.g. (Eds), (Ed.), (Contributors) $surname = trim(preg_replace($reg_expr, "", $surname)); #$reg_expr = "/\{$tok_surname}/"; # remove any remaining ";" #$fullname = preg_replace($reg_expr, "", $fullname); #$reg_expr = "/{$surname}.*/"; # remove surname, and anything following the surname #$initials = trim(preg_replace($reg_expr, "", $fullname)); if (!empty($surname)) $names_array[] = $surname; #.",".$fullname; } $more_ref_records = $refRec->nextRecord(); } if (!empty($names_array)) { sort($names_array); reset($names_array); } return $names_array; } # end of function get_all_names() function display_formatted_references($format_name, $pdf_location, $justone) { global $refRec; global $fmt_ref_record_number, $fmt_authors, $fmt_authors_brief, $fmt_title, $fmt_abstract, $fmt_keywords, $fmt_year_status, $fmt_secondary_author, $fmt_source_in_title; global $fmt_source_journal, $fmt_source_publisher, $fmt_pp, $fmt_pdf_link, $fmt_file_type_gif; global $default_format_name, $default_pdf_gif, $fmt_default_abstract_gif; global $pdf_location; global $pv; global $listname; if (empty($format_name)) $format_name = $default_format_name; if (empty($listname)) $listname="a"; $pdf_location = build_pdf_location($pdf_location); $more_ref_records = true; $prev_ref = -1; if (! $justone) $more_ref_records = $refRec->nextRecord(); #DEBUG if (! $more_ref_records) #DEBUG echo "Error on getting next record. Error=" . $more_ref_records; if ($justone) { $refRec->format_fields(); $pv->ref = $fmt_ref_record_number; $pv->buildVars(); $file1 = "webref_format_{$format_name}_".strtolower(str_replace(" ","_",$refRec->reference_type)).".php"; $file2 = "webref_format_{$format_name}.php"; if (!@include($file1)) include($file2); } else while ($more_ref_records) { $refRec->format_fields(); $pv->ref = $fmt_ref_record_number; $pv->buildVars(); $file1 = "webref_format_{$format_name}_".strtolower(str_replace(" ","_",$refRec->reference_type)).".php"; $file2 = "webref_format_{$format_name}.php"; if ($pv->ref != $prev_ref) { if (!@include ($file1)) include $file2; } $prev_ref = $pv->ref; $more_ref_records = $refRec->nextRecord(); } } # end of function display_formatted_references() function ref_in_this_group($ref_record_number, $cat_key) { global $refcatTBL; $found = false; $another_refcat_rec = $refcatTBL->MoveTo(0); while ($another_refcat_rec) { $r = $refcatTBL->GetField(rc_reference); $c = $refcatTBL->GetField(rc_category); if (($cat_key == $c) && ($ref_record_number == $r)) $found = true; # DEBUG echo "this_c={$cat_key} this_r={$ref_record_number} c={$c} r={$r}
\n"; $another_refcat_rec = nextRefCatRecord(); } return $found; } # end of function ref_in_this_group() function add_ref_to_group($ref_record_number, $cat_key) { global $refcatTBL, $pv; $sql = "INSERT INTO `ref_categories` (`rc_category`, `rc_reference`) VALUES ('{$cat_key}', '{$ref_record_number}');"; # DEBUG if ($pv->debug) echo "add_ref_to_group: sql={$sql}
"; $success = $refcatTBL->Query( $sql); if ( ! $success ) echo "Error adding reference to group. Error={$success}
\n"; return $success; } # end of add_ref_to_group() function remove_ref_from_group($ref_record_number, $cat_key) { global $refcatTBL; $sql = "DELETE FROM `ref_categories` WHERE `rc_category`='{$cat_key}' AND `rc_reference`='{$ref_record_number}';"; # DEBUG if ($pv->debug) echo "remove_ref_from_group: sql={$sql}
"; $success = $refcatTBL->Query( $sql); if ( ! $success ) echo "Error removing reference from group. Error={$success}
\n"; return $success; } # end of function remove_ref_from_group() function toggle_ref_around_group($ref_record_number, $cat_key) { global $refcatTBL, $numrefcats; # Get a list of all the categories which this reference is in #$query_string = "SELECT * FROM `ref_categories`"; $criteria = "ref_categories.rc_reference = {$ref_record_number}"; $order = "none"; queryRefCats($query_string, $criteria, $order, $numrefcats, 7); # DEBUG if ($pv->debug) echo "toggle_ref_around_group: this reference is in {$numrefcats} categories
\n"; # if ( ! $numrefcats > 0 ) # { echo "This reference has not been placed in any categories yet
\n"; # echo "Query string: '{$sql_query_string}'
\n"; # } if (($numrefcats > 0) && (ref_in_this_group($ref_record_number, $cat_key))) { # is currently in this group, so remove remove_ref_from_group($ref_record_number, $cat_key); } else { # is not in this group, so add $success = add_ref_to_group($ref_record_number, $cat_key); } } # end of function toggle_ref_around_group() # returns false if invalid, otherwise returns "category", "section" or "group" function get_group_type($xcat, $xsect, $xsub) { $group_type = "category"; if (!empty($xsect)) $group_type = "section"; if (!empty($xsub)) $group_type = "sub-section"; if (empty($xcat)) return false; else return $group_type; } # returns false if group has no children, or there is an error. Returns false if no error or children. function group_childless($xcategory, $xsection, $xsubsection) { global $catTBL, $pv; $fn_code = 21; # now check all groups that are children of this group $sql = ""; $where = ""; $grouptype = get_group_type($xcategory, $xsection, $xsubsection); if ($grouptype=="category") $subgrouptype = "sections"; if ($grouptype=="section") $subgrouptype = "sub-sections"; if (!empty($xcategory)) { $where .= "cat_category='".addslashes($xcategory)."'"; if (!empty($xsection)) { $where .= " AND cat_section='".addslashes($xsection)."'"; if (!empty($xsubsection)) $where .= " AND cat_sub_section='".addslashes($xsubsection)."'"; } } if (empty($where)) { $pv->err_code = "{$fn_code}01"; $pv->err_msg = "unexpected error ".$pv->err_code; return false; } $sql = "SELECT * FROM `categories` WHERE {$where} LIMIT 2;"; # DEBUG echo "group_exists: sql={$sql}
"; $success = $catTBL->Query( $sql); if (!$success) { $pv->err_code = "{$fn_code}02"; $pv->err_msg = "database error ".$pv->err_code; return false; } if ($catTBL->NumRows() == 0) { # this shouldn't ever occur, as self must exist $pv->err_code = "{$fn_code}03"; $pv->err_msg = "database error ".$pv->err_code; return false; } if ($catTBL->NumRows() > 1) { # this shouldn't ever occur $pv->err_code = "{$fn_code}04"; $pv->err_msg = "this {$grouptype} still has {$subgrouptype}"; return false; } $pv->err_code = 0; return true; } # end of function group_childless() # if just cat_key passed, compares cat_key # if just alias passed, compares cat_alias # if category, and/or section and/or subsection passed, checks those # if cat_key and any of the above passed, and select pulls up just the cat key, then return false, set err_code to 0 # returns true if there is a problem, set err_code and err_msg # returns true if group exists, sets err_code to 0 # returns false if group does not exist, sets err_code to 0 # NOTE: check is caseless except with cat_key! function group_exists($xcat_key, $xcategory, $xsection, $xsubsection, $xalias) { global $catTBL, $pv; $fn_code = 22; # now check if group exists, or has children $sql = ""; $where = ""; $grouptype = ""; $grouptype = get_group_type($xcategory, $xsection, $xsubsection); if (!empty($xcategory)) $where .= "`cat_category` = '".addslashes($xcategory)."' AND `cat_section` = '".addslashes($xsection)."' AND `cat_sub_section` = '".addslashes($xsubsection)."'"; if (empty($where) && !empty($xalias)) { $where = "`cat_alias` = '".addslashes($xalias)."'"; $grouptype = "alias"; } if (empty($where) and !empty($xcat_key)) { $where = "`cat_key`='{$xcat_key}'"; $grouptype = "cat_key"; } if (empty($where)) { $pv->err_code = "{$fn_code}01"; $pv->err_msg = "a {$grouptype} with that name already exists. error ".$pv->err_code; $pv->err_msg = preg_replace("/^(a )([aeiou])/","an $2",$pv->err_msg); return true; } $sql = "SELECT * FROM `categories` WHERE {$where};"; # DEBUG echo "group_exists: sql={$sql}
"; $success = $catTBL->Query( $sql); if (!$success) { $pv->err_code = "{$fn_code}02"; $pv->err_msg = "database error ".$pv->err_code; return true; } if ($catTBL->NumRows() > 0) { # if cat_key passed, and only result found is for that key, return no probs, otherwise return probs if ($catTBL->NumRows() == 1 && !empty($xcat_key)) { nextCatRecord(); get_cat_fields($catTBL); global $cat_key; if ($xcat_key == $cat_key) { $pv->err_code = 0; return false; } } $pv->err_code = "{$fn_code}03"; $pv->err_msg = "a {$grouptype} with that name already exists."; $pv->err_msg = preg_replace("/^(a )([aeiou])/","an $2",$pv->err_msg); $pv->err_code = 0; return true; } $pv->err_code = 0; return false; } function group_update($cat_key, $old_category, $old_section, $old_subsection, $old_alias, $new_category, $new_section, $new_subsection, $new_alias, $old_sort_order, $new_comment) { global $catTBL, $pv; $fn_code = 23; if ($_SESSION['admin'] != md5($_SESSION['username']."1")) die($fn_code); $new_category = str_replace("'", "`", $new_category); $new_section = str_replace("'", "`", $new_section); $new_sub_section = str_replace("'", "`", $new_sub_section); $new_alias = str_replace("'", "`", $new_alias); $new_comment = str_replace("'", "`", $new_comment); # prevent a null category if (empty($old_category) || empty($new_category)) { $pv->err_code = "{$fn_code}01"; $pv->err_msg = "update failed - there was no category selected for renaming. error ".$pv->err_code; return false; } if (empty($old_category) !== empty($new_category)) { $pv->err_code = "{$fn_code}02"; $pv->err_msg = "update failed - category cannot be blank. error ".$pv->err_code; return false; } if (empty($old_section) !== empty($new_section)) { $pv->err_code = "{$fn_code}03"; $pv->err_msg = "update failed - section cannot be blank. error ".$pv->err_code; return false; } if (empty($old_subsection) !== empty($new_subsection)) { $pv->err_code = "{$fn_code}04"; $pv->err_msg = "update failed - sub-section cannot be blank. error".$pv->err_code; return false; } if (empty($new_alias)) { $pv->err_code = "{$fn_code}05"; $pv->err_msg = "update failed - alias cannot be empty. error".$pv->err_code; return false; } $group_changed = ($new_category != $old_category) || ($new_section != $old_section) || ($new_subsection != $old_subsection); # check to see if category/section/subsection already exists if ($group_changed && group_exists($cat_key, $new_category, $new_section, $new_subsection, "")) { if ($pv->err_code == 0) $pv->err_code = "{$fn_code}06"; # group exists $pv->err_msg = "update failed - ".$pv->err_msg; return false; } # check to see if this alias already exists if ($new_alias != $old_alias && group_exists($cat_key, "", "", "", $new_alias)) { if ($pv->err_code == 0) $pv->err_code = "{$fn_code}07"; $pv->err_msg = "update failed - ".$pv->err_msg; return false; } # update this specific group $sql = ""; if (!empty($old_category) && !empty($new_category)) { $sql .= "`cat_category`='".addslashes($new_category)."', "; if (!empty($old_section) && !empty($new_section)) { $sql .= "`cat_section`='".addslashes($new_section)."', "; if (!empty($old_subsection) && !empty($new_subsection)) $sql .= "`cat_sub_section`='".addslashes($new_subsection)."', "; } } if (!empty($new_alias)) $sql .= "`cat_alias`='".addslashes($new_alias)."', "; if (!empty($old_sort_order)) $sql .= "`cat_sort_order`=".$old_sort_order.", "; if (!empty($new_comment)) $sql .= "`cat_comment`='".addslashes($new_comment)."', "; $sql = preg_replace("/, $/","",$sql); if (empty($sql)) { $pv->err_code = "{$fn_code}08"; $pv->err_msg = "update failed - no changes were submitted. error ".$pv->err_code; return false; } $sql = "UPDATE `categories` SET {$sql} WHERE `cat_key`={$cat_key};"; # DEBUG echo "group_update: sql={$sql}
"; if ($pv->debug) echo "group_update: sql={$sql}
"; $success = $catTBL->Query( $sql); if (!$success) { $pv->err_code = "{$fn_code}09"; $pv->err_msg = "update failed - database error on group. error ".$pv->err_code; return false; } # now update all groups that are children of this group $sql = ""; $where = ""; if (!empty($old_category) && !empty($new_category)) { $sql .= "`cat_category`='".addslashes($new_category)."', "; $where .= "`cat_category`='".addslashes($old_category)."'"; if (!empty($old_section) && !empty($new_section)) { $sql .= "`cat_section`='".addslashes($new_section)."', "; $where .= " AND `cat_section`='".addslashes($old_section)."'"; if (!empty($old_subsection) && !empty($new_subsection)) { $sql .= "`cat_sub_section`='".addslashes($new_subsection)."', "; $where .= " AND `cat_sub_section`='".addslashes($old_subsection)."'"; } } } $sql = preg_replace("/, $/","",$sql); if (empty($sql)) { $pv->err_code = "{$fn_code}10"; $pv->err_msg = "update failed - database error ".$pv->err_code; return false; } $sql = "UPDATE `categories` SET {$sql} WHERE {$where};"; # DEBUG echo "group_update2: sql={$sql}
"; if ($pv->debug) echo "group_update2: sql={$sql}
"; $success = $catTBL->Query( $sql); if (!$success) { $pv->err_code = "{$fn_code}11"; $pv->err_msg = "update failed - database error ".$pv->err_code; return false; } $pv->err_msg = "update was successful."; $pv->err_code = 0; return $success; } # end of group_update() function group_insert($position, $cat_key, $old_category, $old_section, $old_subsection, $old_alias, $new_category, $new_section, $new_subsection, $new_alias, $old_sort_order, $new_comment) { global $catTBL, $pv; $fn_code = 24; if ($_SESSION['admin'] != md5($_SESSION['username']."1")) die($fn_code); $new_category = str_replace("'", "`", $new_category); $new_section = str_replace("'", "`", $new_section); $new_sub_section = str_replace("'", "`", $new_sub_section); $new_alias = str_replace("'", "`", $new_alias); $new_comment = str_replace("'", "`", $new_comment); if (empty($old_category) !== empty($new_category)) { $pv->err_code = "{$fn_code}01"; $pv->err_msg = "insert failed - category cannot be blank. error ".$pv->err_code; return false; } # prevent a null category if (empty($old_category) || empty($new_category)) { $pv->err_code = "{$fn_code}02"; $pv->err_msg = "insert failed - there was no category selected for insertion. error ".$pv->err_code; return false; } if ($position != "right") { # check fields were filled in if (empty($old_section) !== empty($new_section)) { $pv->err_code = "{$fn_code}03"; $pv->err_msg = "insert failed - section cannot be blank. error ".$pv->err_code; return false; } if (empty($old_subsection) !== empty($new_subsection)) { $pv->err_code = "{$fn_code}04"; $pv->err_msg = "insert failed - sub-section cannot be blank. error".$pv->err_code; return false; } } if (empty($new_alias)) { $pv->err_code = "{$fn_code}05"; $pv->err_msg = "insert failed - alias cannot be empty. error".$pv->err_code; return false; } $group_type = get_group_type($new_category, $new_section, $new_subsection); # check to see if category/section/subsection already exists if (group_exists("", $new_category, $new_section, $new_subsection, "")) { if ($pv->err_code == 0) $pv->err_code = "{$fn_code}06"; $pv->err_msg = "insert failed - ".$pv->err_msg; $pv->err_msg = preg_replace("/^(a )([aeiou])/","an $2",$pv->err_msg); $pv->err_code = 0; return true; } # check to see if alias already exists if (group_exists("", "", "", "", $new_alias)) { if ($pv->err_code == 0) $pv->err_code = "{$fn_code}07"; $pv->err_msg = "insert failed - ".$pv->err_msg; $pv->err_msg = preg_replace("/^(a )([aeiou])/","an $2",$pv->err_msg); $pv->err_code = 0; return true; } # if insert after, then get sort order of next group on the same level. if (!empty($old_subsection)) # add sub-section after sub-section $new_sort_order = $old_sort_order; else # get work out the next sort order { $where = "cat_category='{$old_category}' AND cat_sort_order >= {$old_sort_order}"; if (!empty($old_section)) $where = "cat_section='{$old_section}' AND ".$where; $sql="SELECT * FROM categories WHERE {$where} ORDER BY cat_sort_order DESC LIMIT 1;"; # DEBUG echo "group_insert: sql={$sql}
"; $success = $catTBL->Query($sql); if (!$success) { $pv->err_code = "{$fn_code}08"; $pv->err_msg = "insert failed - database error ".$pv->err_code; return false; } if ($catTBL->NumRows() != 1) { # there should be a single record, either this one, or it's last child $pv->err_code = "{$fn_code}09"; $pv->err_msg = "insert failed - database error ".$pv->err_code; return false; } nextCatRecord(); get_cat_fields($catTBL); global $cat_sort_order; $new_sort_order = $cat_sort_order; } # make space by group moving sort orders if ($position == "after") $new_sort_order++; else if ($position == "before") $new_sort_order = $old_sort_order; else if ($position == "right") $new_sort_order = $old_sort_order + 1; $sql = "UPDATE categories SET cat_sort_order=cat_sort_order+1 WHERE cat_sort_order>=".$new_sort_order.";"; # DEBUG echo "group_update: sql={$sql}
"; if ($pv->debug) echo "group_insert: sql={$sql}
"; $success = $catTBL->Query( $sql); if (!$success) { $pv->err_code = "{$fn_code}10"; $pv->err_msg = "insert failed - database error on group. error ".$pv->err_code; return false; } # insert this new group $fields = ""; $values = ""; $fields .= "cat_category, "; $values .= "'".addslashes($new_category)."', "; $fields .= "cat_section, "; $values .= "'".addslashes($new_section)."', "; $fields .= "cat_sub_section, "; $values .= "'".addslashes($new_subsection)."', "; $fields .= "cat_alias, "; $values .= "'".addslashes($new_alias)."', "; $fields .= "cat_sort_order, "; $values .= $new_sort_order.", "; $fields .= "cat_comment"; $values .= "'".addslashes($new_comment)."'"; $sql = "INSERT INTO categories (".$fields.") VALUES (".$values.");"; # DEBUG echo "group_update: sql={$sql}
"; if ($pv->debug) echo "group_insert: sql={$sql}
"; $success = $catTBL->Query( $sql); if (!$success) { $pv->err_code = "{$fn_code}11"; $pv->err_msg = "insert failed - database error on group. error ".$pv->err_code; return false; } $pv->err_msg = "insert was successful."; $pv->err_code = 0; return $success; } # end of group_insert() # returns false if group has no children, or there is an error. Returns false if no error or children. function group_delete($xkey, $xcategory, $xsection, $xsubsection, $xalias) { global $catTBL, $pv; $fn_code = 25; if ($_SESSION['admin'] != md5($_SESSION['username']."1")) die($fn_code); # now check all groups that are children of this group $sql = ""; $where = ""; $grouptype = get_group_type($xcategory, $xsection, $xsubsection); # don't delete if group has children if (group_childless($xcategory, $xsection, $xsubsection) === false) { $pv->err_code = "{$fn_code}01"; $pv->err_msg = "delete failed - ".$pv->err_msg; return false; } if (!empty($xcategory)) $where .= "cat_key={$xkey} AND `cat_category` = '".addslashes($xcategory)."' AND `cat_section` = '".addslashes($xsection)."' AND `cat_sub_section` = '".addslashes($xsubsection)."' AND `cat_alias` = '".addslashes($xalias)."'"; if (empty($where)) { $pv->err_code = "{$fn_code}02"; $pv->err_msg = "unexpected error ".$pv->err_code; return false; } $sql = "DELETE FROM `categories` WHERE {$where} LIMIT 1;"; $success = $catTBL->Query( $sql); if (!$success) { $pv->err_code = "{$fn_code}03"; $pv->err_msg = "database error ".$pv->err_code; return false; } if ($catTBL->NumRows() != 1) { # this shouldn't ever occur $pv->err_code = "{$fn_code}04"; $pv->err_msg = "database error ".$pv->err_code; return false; } $pv->err_msg = "delete was successful."; $pv->err_code = 0; return true; } # end of function delete_group() # finds all references that are in a subsection, but not the associated section, and adds them to that section function propogate_subsections() { global $catTBL, $refcatTBL, $pv; $fn_code = 26; if ($_SESSION['admin'] != md5($_SESSION['username']."1")) die($fn_code); # get list of all cats for which ref is in sub, but not section $sql = "SELECT rcsub.rc_reference, catsec.cat_key "; $sql .= "FROM ref_categories AS rcsub "; $sql .= "LEFT JOIN categories AS catsub ON "; $sql .= "catsub.cat_key = rcsub.rc_category AND "; $sql .= "catsub.cat_sub_section NOT IN ('', NULL) "; $sql .= "LEFT JOIN categories AS catsec ON "; $sql .= "catsec.cat_section = catsub.cat_section AND "; $sql .= "catsec.cat_category = catsub.cat_category AND "; $sql .= "catsec.cat_sub_section IN ('', NULL) AND "; $sql .= "catsec.cat_section NOT IN ('', NULL) "; $sql .= "LEFT JOIN ref_categories AS rcsec ON "; $sql .= "rcsec.rc_category = catsec.cat_key AND "; $sql .= "rcsec.rc_reference = rcsub.rc_reference "; $sql .= "WHERE rcsec.rc_reference IS NULL AND "; $sql .= "catsub.cat_key IS NOT NULL;"; $success = $catTBL->Query($sql); if (!$success) { $pv->err_code = "{$fn_code}01"; $pv->err_msg = "propogate sub-section failed - database error ".$pv->err_code; return false; } $more_records = nextCatRecord(); while ($more_records) { # insert reference to section $fields = ""; $values = ""; $fields .= "rc_category, "; $values .= $catTBL->GetField('cat_key').", "; $fields .= "rc_reference"; $values .= $catTBL->GetField('rc_reference'); $sql = "INSERT INTO ref_categories (".$fields.") VALUES (".$values.");"; # DEBUG echo "group_update: sql={$sql}
"; if ($pv->debug) echo "propogate_subsections: sql={$sql}
"; $success = $refcatTBL->Query( $sql); if (!$success) { $pv->err_code = "{$fn_code}02"; $pv->err_msg = "propogate sub-section failed - database error ".$pv->err_code; return false; } $more_records = nextCatRecord(); } # end while $pv->err_msg = "sub-section selection propogation was successful."; $pv->err_code = 0; return $success; } # end of propogate_subsections() $db_functions = true; ?>