Update of /cvsroot/phpslash/phpslash-ft/class
In directory usw-pr-cvs1:/tmp/cvs-serv24795/phpslash-ft/class
Modified Files:
Author.class Section.class Story.class Topic.class
Log Message:
Moved the select boxes of storylist.tpl to the template
Index: Author.class
===================================================================
RCS file: /cvsroot/phpslash/phpslash-ft/class/Author.class,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** Author.class 2001/12/12 11:37:04 1.10
--- Author.class 2001/12/14 03:58:18 1.11
***************
*** 331,363 ****
}
/**
! * authorSelect - spit out author select box
*
*
- * @param string varname
- * @param string selected
* @access public
! * return output
*/
! function authorSelect($varname,$selected) {
$q = "SELECT author_id, author_name
! FROM psl_author";
$this->db->query($q);
! $output = "<SELECT NAME=\"$varname\">\n";
! $output .= " <OPTION VALUE=\"\">All</OPTION>\n";
while ($this->db->next_record()) {
! $id = $this->db->f("author_id");
! $name = $this->db->f("author_name");
! $output .= " <OPTION VALUE=\"$id\" ";
! if ($id == $selected) {
! $output .= " SELECTED";
! }
! $output .= ">$name</OPTION>\n";
}
! $output .= "</SELECT>\n";
! return $output;
}
-
} /* end of Author.class */
?>
--- 331,357 ----
}
+
/**
! * getAuthors - returns array with author ids and names
*
*
* @access public
! * return author_array(id, name)
*/
! function getAuthors() {
$q = "SELECT author_id, author_name
! FROM psl_author
! ORDER BY author_name";
$this->db->query($q);
!
while ($this->db->next_record()) {
! $author_array[] = array(
! "id" => $this->db->f("author_id"),
! "name" => $this->db->f("author_name")
! );
}
! return $author_array;
}
} /* end of Author.class */
?>
Index: Section.class
===================================================================
RCS file: /cvsroot/phpslash/phpslash-ft/class/Section.class,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** Section.class 2001/12/12 11:37:48 1.7
--- Section.class 2001/12/14 03:58:18 1.8
***************
*** 1,266 ****
! <?php
!
! /* $Id$ */
!
!
! /**
! * Provides an API to the PHPSlash Section Management.
! *
! */
! class Section {
! var $sec_templ,$db,$psl;
!
! /**
! * Section class constructor
! * @access private
! */
! function Section () {
!
! global $_PSL;
!
! $this->db = new slashDB;
! $this->psl = $_PSL;
!
! /* Templates */
! $this->sec_templ = new Template($this->psl[templatedir]);
! $this->sec_templ->debug = 0;
! $this->sec_templ->set_file(array(
! listsection => "sectionList.tpl",
! newsection => "sectionNew.tpl"
! ));
!
! }
!
! /**
! * listSection - list all Section
! *
! * displays the complete list of sections
! * Used only by admin
! * @access public
! */
! function listSection() {
!
! $q = "SELECT *
! FROM psl_section
! ORDER BY section_name";
! $this->db->query($q);
!
! titlebar("100%","Edit Sections");
!
! $this->sec_templ->set_block("listsection","row","rows");
!
! while ($this->db->next_record()) {
! $this->sec_templ->set_var(array(
! ACTION_URL => $this->psl[phpself],
! SECTION_ID => $this->db->Record[section_id],
! SECTION_NAME => $this->db->Record[section_name],
! SECTION_DESC => $this->db->Record[description]
! ));
! $this->sec_templ->parse("rows","row",true);
! };
! $this->sec_templ->parse(OUT,array("listsection"));
! $this->sec_templ->p(OUT);
! }
!
! /**
! * saveSection - save the section info to the DB
! *
! * Used only by admin
! *
! * @param array $ary
! *
! * @access public
! */
!
! function saveSection($ary) {
!
! /* we need to check for the stuff to add in the DB before we actually
! * add anything. And yes, I know it looks like I just passed my
! * "Intro to C++ Programming" class. --ajay
! */
!
! if ($ary[section_name] == "") {
! error("There is no section_name in Section.class::saveSection");
! return;
! }
! if ($ary[description] == "") {
! error("There is no description in Section.class::saveSection");
! return;
! }
!
! /* addslashes for the (') AND str_replace for the (") */
!
! $ary["description"] = addslashes(str_replace('\"',""",stripslashes($ary["description"])));
! $ary["section_name"] = addslashes(str_replace('\"',""",$ary["section_name"]));
! $ary["section_name"] = str_replace(" "," ",$ary["section_name"]);
!
! /* if a record exists, then we update, else we insert a new section! */
! $q = "SELECT section_id
! FROM psl_section
! WHERE section_id = '$ary[section_id]'";
! $this->db->query($q);
! if ($this->db->next_record()) {
! $q = "UPDATE psl_section
! SET section_name = '$ary[section_name]',
! description = '$ary[description]'
! WHERE section_id = '$ary[section_id]'";
! } else {
!
! $ary[section_id] = generateID("psl_section_seq");
!
! $q = "INSERT INTO psl_section ";
! $q .= "(section_id,section_name,description) ";
! $q .= "VALUES ('$ary[section_id]','$ary[section_name]','$ary[description]')";
! }
!
! # echo "<BR><BR><B>QUERY: $q</B><BR><BR>\n";
! return $this->db->query($q);
! }
!
! /**
! * deleteSection - deletes a section and is somewhat idiot-proof
! *
! * @param integer section_id
! * @access public
! */
! function deleteSection($section_id) {
!
! $go_ahead = true;
!
! $q = "SELECT psl_story.title,
! psl_story.story_id
! FROM psl_story,
! psl_section_lut
! WHERE psl_story.story_id = psl_section_lut.story_id
! AND psl_section_lut.section_id = '$section_id'";
! $this->db->query($q);
! while ($this->db->next_record()) {
! $go_ahead = false;
! $title = $this->db->Record["title"];
! $story_id = $this->db->Record["story_id"];
! $section_name = $this->db->Record["section_name"];
! echo "<FONT COLOR=RED>STORY</FONT>: '$title'<BR>\n";
! }
!
! $q = "SELECT psl_submission.title,
! psl_submission.story_id
! FROM psl_submission,
! psl_section_submission_lut
! WHERE psl_submission.story_id = psl_section_submission_lut.story_id
! AND psl_section_submission_lut.section_id = '$section_id'";
! $this->db->query($q);
! while ($this->db->next_record()) {
! $go_ahead = false;
! $title = $this->db->Record["title"];
! $story_id = $this->db->Record["story_id"];
! $section_name = $this->db->Record["section_name"];
! #echo "<FONT COLOR=RED>SUBMISSION</FONT>: '$title'<BR>\n";
! }
!
! if (!$go_ahead) {
! return false;
! } else {
! $q = "DELETE FROM psl_section where section_id = '$section_id'";
! $this->db->query($q);
! return true;
! }
! }
!
! /**
! * newSection - spits out a blank form for input
! *
! * Just prints out the "form" and points the user to the "save" method
! * Used only by admin
! *
! * @access public
! */
! function newSection() {
!
! titlebar("100%","New Section");
! $this->sec_templ->set_var(array(
! ACTION_URL => $this->psl[phpself],
! SECTION_NAME => "",
! SECTION_DESC => ""
! ));
!
! $this->sec_templ->parse(OUT,array("newsection"));
! $this->sec_templ->p(OUT);
!
! }
!
! /**
! * getName - return name assign to id
! *
! * when given a section id, getName returns the name
! *
! * @param integer id
! * @access public
! * return section_name
! */
! function getName($id) {
! if (!$id) {
! return false;
! } else {
! $q = "SELECT section_name
! FROM psl_section
! WHERE section_id = '$id'";
! $this->db->query($q);
! $this->db->next_record();
! return $this->db->f("section_name");
! };
! }
!
! /**
! * getId - return id assign to name
! *
! * when given a name, getId returns the id
! *
! * @param string name
! * @access public
! * return section_id
! */
! function getId($name) {
! if (!$name) {
! return false;
! } else {
! $q = "SELECT section_id
! FROM psl_section
! WHERE section_name = '$name'";
! $this->db->query($q);
! $this->db->next_record();
! return $this->db->f("section_id");
! };
! }
!
! /**
! * sectionSelect - spit out section select box
! *
! *
! * @param string varname
! * @param string selected
! * @access public
! * return output
! */
! function sectionSelect($varname,$selected) {
!
! $q = "SELECT section_id, section_name
! FROM psl_section";
! $this->db->query($q);
! $output = "<SELECT NAME=\"$varname\">\n";
! $output .= " <OPTION VALUE=\"\">All</OPTION>\n";
! while ($this->db->next_record()) {
! $id = $this->db->f("section_id");
! $name = $this->db->f("section_name");
! $output .= " <OPTION VALUE=\"$id\" ";
! if ($id == $selected) {
! $output .= " SELECTED";
! }
! $output .= ">$name</OPTION>\n";
! }
! $output .= "</SELECT>\n";
! return $output;
! }
!
! } /* end of Section.class */
!
?>
--- 1,262 ----
! <?php
!
! /* $Id$ */
!
!
! /**
! * Provides an API to the PHPSlash Section Management.
! *
! */
! class Section {
! var $sec_templ,$db,$psl;
!
! /**
! * Section class constructor
! * @access private
! */
! function Section () {
!
! global $_PSL;
!
! $this->db = new slashDB;
! $this->psl = $_PSL;
!
! /* Templates */
! $this->sec_templ = new Template($this->psl[templatedir]);
! $this->sec_templ->debug = 0;
! $this->sec_templ->set_file(array(
! listsection => "sectionList.tpl",
! newsection => "sectionNew.tpl"
! ));
!
! }
!
! /**
! * listSection - list all Section
! *
! * displays the complete list of sections
! * Used only by admin
! * @access public
! */
! function listSection() {
!
! $q = "SELECT *
! FROM psl_section
! ORDER BY section_name";
! $this->db->query($q);
!
! titlebar("100%","Edit Sections");
!
! $this->sec_templ->set_block("listsection","row","rows");
!
! while ($this->db->next_record()) {
! $this->sec_templ->set_var(array(
! ACTION_URL => $this->psl[phpself],
! SECTION_ID => $this->db->Record[section_id],
! SECTION_NAME => $this->db->Record[section_name],
! SECTION_DESC => $this->db->Record[description]
! ));
! $this->sec_templ->parse("rows","row",true);
! };
! $this->sec_templ->parse(OUT,array("listsection"));
! $this->sec_templ->p(OUT);
! }
!
! /**
! * saveSection - save the section info to the DB
! *
! * Used only by admin
! *
! * @param array $ary
! *
! * @access public
! */
!
! function saveSection($ary) {
!
! /* we need to check for the stuff to add in the DB before we actually
! * add anything. And yes, I know it looks like I just passed my
! * "Intro to C++ Programming" class. --ajay
! */
!
! if ($ary[section_name] == "") {
! error("There is no section_name in Section.class::saveSection");
! return;
! }
! if ($ary[description] == "") {
! error("There is no description in Section.class::saveSection");
! return;
! }
!
! /* addslashes for the (') AND str_replace for the (") */
!
! $ary["description"] = addslashes(str_replace('\"',""",stripslashes($ary["description"])));
! $ary["section_name"] = addslashes(str_replace('\"',""",$ary["section_name"]));
! $ary["section_name"] = str_replace(" "," ",$ary["section_name"]);
!
! /* if a record exists, then we update, else we insert a new section! */
! $q = "SELECT section_id
! FROM psl_section
! WHERE section_id = '$ary[section_id]'";
! $this->db->query($q);
! if ($this->db->next_record()) {
! $q = "UPDATE psl_section
! SET section_name = '$ary[section_name]',
! description = '$ary[description]'
! WHERE section_id = '$ary[section_id]'";
! } else {
!
! $ary[section_id] = generateID("psl_section_seq");
!
! $q = "INSERT INTO psl_section ";
! $q .= "(section_id,section_name,description) ";
! $q .= "VALUES ('$ary[section_id]','$ary[section_name]','$ary[description]')";
! }
!
! # echo "<BR><BR><B>QUERY: $q</B><BR><BR>\n";
! return $this->db->query($q);
! }
!
! /**
! * deleteSection - deletes a section and is somewhat idiot-proof
! *
! * @param integer section_id
! * @access public
! */
! function deleteSection($section_id) {
!
! $go_ahead = true;
!
! $q = "SELECT psl_story.title,
! psl_story.story_id
! FROM psl_story,
! psl_section_lut
! WHERE psl_story.story_id = psl_section_lut.story_id
! AND psl_section_lut.section_id = '$section_id'";
! $this->db->query($q);
! while ($this->db->next_record()) {
! $go_ahead = false;
! $title = $this->db->Record["title"];
! $story_id = $this->db->Record["story_id"];
! $section_name = $this->db->Record["section_name"];
! echo "<FONT COLOR=RED>STORY</FONT>: '$title'<BR>\n";
! }
!
! $q = "SELECT psl_submission.title,
! psl_submission.story_id
! FROM psl_submission,
! psl_section_submission_lut
! WHERE psl_submission.story_id = psl_section_submission_lut.story_id
! AND psl_section_submission_lut.section_id = '$section_id'";
! $this->db->query($q);
! while ($this->db->next_record()) {
! $go_ahead = false;
! $title = $this->db->Record["title"];
! $story_id = $this->db->Record["story_id"];
! $section_name = $this->db->Record["section_name"];
! #echo "<FONT COLOR=RED>SUBMISSION</FONT>: '$title'<BR>\n";
! }
!
! if (!$go_ahead) {
! return false;
! } else {
! $q = "DELETE FROM psl_section where section_id = '$section_id'";
! $this->db->query($q);
! return true;
! }
! }
!
! /**
! * newSection - spits out a blank form for input
! *
! * Just prints out the "form" and points the user to the "save" method
! * Used only by admin
! *
! * @access public
! */
! function newSection() {
!
! titlebar("100%","New Section");
! $this->sec_templ->set_var(array(
! ACTION_URL => $this->psl[phpself],
! SECTION_NAME => "",
! SECTION_DESC => ""
! ));
!
! $this->sec_templ->parse(OUT,array("newsection"));
! $this->sec_templ->p(OUT);
!
! }
!
! /**
! * getName - return name assign to id
! *
! * when given a section id, getName returns the name
! *
! * @param integer id
! * @access public
! * return section_name
! */
! function getName($id) {
! if (!$id) {
! return false;
! } else {
! $q = "SELECT section_name
! FROM psl_section
! WHERE section_id = '$id'";
! $this->db->query($q);
! $this->db->next_record();
! return $this->db->f("section_name");
! };
! }
!
! /**
! * getId - return id assign to name
! *
! * when given a name, getId returns the id
! *
! * @param string name
! * @access public
! * return section_id
! */
! function getId($name) {
! if (!$name) {
! return false;
! } else {
! $q = "SELECT section_id
! FROM psl_section
! WHERE section_name = '$name'";
! $this->db->query($q);
! $this->db->next_record();
! return $this->db->f("section_id");
! };
! }
!
!
! /**
! * getSections - returns array with ids and names
! *
! *
! * @access public
! * return section_array(id, name)
! */
! function getSections() {
!
! $q = "SELECT section_id, section_name
! FROM psl_section
! ORDER BY section_name";
! $this->db->query($q);
!
! while ($this->db->next_record()) {
! $section_array[] = array(
! "id" => $this->db->f("section_id"),
! "name" => $this->db->f("section_name")
! );
! }
!
! return $section_array;
! }
!
! } /* end of Section.class */
!
?>
Index: Story.class
===================================================================
RCS file: /cvsroot/phpslash/phpslash-ft/class/Story.class,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** Story.class 2001/12/11 15:33:21 1.25
--- Story.class 2001/12/14 03:58:18 1.26
***************
*** 1,1161 ****
! <?php
!
! /* $Id$ */
!
! /*
! * Class: Story
! *
! * Layer: Final (Builder)
! * Desc.: A Builder class for Story
! *
[...2358 lines suppressed...]
! AUTHOR_NAME => $this->db->Record[author_name]
! ));
! $this->template->set_var(AUTHOR_SELECTED,"");
! if ($this->db->Record[author_id] == $user_id ){
! $this->template->set_var(AUTHOR_SELECTED,"SELECTED");
! }
!
! $this->template->parse("author_rows","author_row",true);
! }
!
! }
! $description = sprintf( "%s (%s) added new story %s as userid %s", $this->auth->auth['uname'], $this->auth->auth['uid'], $story_id, $user_id);
! logwrite("Story Admin", $description);
! $this->template->parse(OUT,array("newstory"));
! $this->template->p(OUT);
!
! }
!
! }
! ?>
Index: Topic.class
===================================================================
RCS file: /cvsroot/phpslash/phpslash-ft/class/Topic.class,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Topic.class 2001/12/12 11:38:30 1.8
--- Topic.class 2001/12/14 03:58:18 1.9
***************
*** 1,462 ****
! <?php
!
! /* $Id$ */
!
! /**
! * Provides an API to the PHPSlash Topic Management.
! *
! * This object is how we do anything with topics.
! *
! */
!
! class Topic {
! var $topic_templ; /* the template object */
! var $db; /* the db object */
! var $perm; /* our local version of the perm object */
! var $psl; /* our local version of the _PSL array */
!
! /**
! * The Section Constructor
! *
! * sets up the local version of the global _PSL array, the templates
! * and a few other things
! * @access private
! */
! function Topic () {
!
! global $perm, $_PSL, $amp;
!
! $this->db = new slashDB;
! $this->perm = $perm;
! $this->psl = $_PSL;
!
!
! /* Templates */
! $this->topic_templ = new Template($this->psl[templatedir]);
! $this->topic_templ->debug = 0;
! $this->topic_templ->set_file(array(
! listtopic => "topicList.tpl",
! newtopic => "topicNew.tpl"
! ));
! }
!
! /*
! * METHODS
! */
!
! /**
! * listTopic - list all Topics
! *
! * displays the complete list of topics
! * Used only by admin
! * @access public
! */
! function listTopic() {
!
! $q = "SELECT *
! FROM psl_topic
! ORDER BY topic_name";
! $this->db->query($q);
!
! titlebar("100%","Change existing Topics");
!
! $this->topic_templ->set_block("listtopic","row","rows");
!
! while ($this->db->next_record()) {
!
! $image = $this->psl[topicimageurl] . "/" . $this->db->Record[image];
! $topic_id = $this->db->Record[topic_id];
! if ($this->perm->have_perm("topic,root")) {
! $admin = "<A HREF=\"" . $this->psl[phpself] . "?submit=edit" . $this->psl[amp] . "topic_id=$topic_id\">[Edit]</A>";
! $admin .= " <A HREF=\"" . $this->psl[phpself] . "?submit=delete" . $this->psl[amp] . "topic_id=$topic_id\">[Delete]</A>";
!
! } else {
! $admin = " <A HREF=\"" . $this->psl[phpself] . "?submit=delete" . $this->psl[amp] . "topic_id=$topic_id\">[Delete]</A>";
! }
! $this->topic_templ->set_var(array(
! IMAGE_SRC => $image,
! TOPIC_NAME => $this->db->Record[topic_name],
! WIDTH => $this->db->Record[width],
! HEIGHT => $this->db->Record[height],
! IMAGE => $this->db->Record[image],
! ONLINKBAR => $this->db->Record[onlinkbar],
! ALT_TEXT => $this->db->Record[alt_text],
! TOPIC_ID => $topic_id,
! ACTION_URL => $this->psl[phpself],
! ADMIN => $admin
! ));
! $this->topic_templ->parse("rows","row",true);
! };
! $this->topic_templ->parse(OUT,array("listtopic"));
! $this->topic_templ->p(OUT);
! }
!
!
! /**
! * saveTopic - save the topic info to the DB
! *
! * Saves the topic in the $ary array to the DB
! * Obligatory fields: topic_name, image, width, height, alt_text
! * Optional fields: topic_id (only if this topic is already in the DB),
! * onlinkbar (if blank, defaults to 0)
! * Returns true if sucessful (topic added or updated), false on error
! * Used only by admin
! *
! * @param array $ary
! *
! * @access public
! */
! function saveTopic($ary) {
!
! /* we need to check for the stuff to add in the DB before we actually
! * add anything. And yes, I know it looks like I just passed my
! * "Intro to C++ Programming" class. --ajay
! */
!
! // debug("Topic.class::saveTopic::ary", $ary);
!
! /* We don't test for topic_id because no topic_id means, that
! this is a new topic. */
! if ($ary[topic_name] == "") {
! error("There is no topic_name in Topic.class::saveTopic");
! return false;
! }
! if ($ary[image] == "") {
! error("There is no image in Topic.class::saveTopic");
! return false;
! }
!
! /* calculate height and width */
! $imagesize = getimagesize( $this->psl[topicimagedir] . "/" . $ary[image]);
! $ary[width] = $imagesize[0];
! $ary[height] = $imagesize[1];
!
!
! if ($ary[alt_text] == "") {
! error("There is no alt_text in Topic.class::saveTopic");
! return false;
! }
! /* doesn't error out anymore. Just defaults 'onlinkbar
! to zero */
! if ($ary[onlinkbar] == "") {
! $ary[onlinkbar] = "0";
! }
!
! $ary = clean($ary);
!
! /* if a record exists, then we update, else we insert a new topic! */
!
! $q = "SELECT topic_id
! FROM psl_topic
! WHERE topic_id = '$ary[topic_id]'";
! $this->db->query($q);
! if ($this->db->next_record()) {
! $q = "UPDATE psl_topic
! SET topic_name = '$ary[topic_name]',
! image = '$ary[image]',
! width = '$ary[width]',
! height = '$ary[height]',
! alt_text = '$ary[alt_text]',
! onlinkbar = '$ary[onlinkbar]'
! WHERE topic_id = '$ary[topic_id]'";
! } else {
!
! $ary[topic_id] = generateID("psl_topic_seq");
!
! $q = "INSERT INTO psl_topic
! (topic_id,
! topic_name,
! image,
! alt_text,
! width,
! height,
! onlinkbar)
! VALUES ('$ary[topic_id]',
! '$ary[topic_name]',
! '$ary[image]',
! '$ary[alt_text]',
! '$ary[width]',
! '$ary[height]',
! '$ary[onlinkbar]')";
! }
!
! // echo "<BR><B>QUERY: $q</B><BR>\n";
! $this->db->query($q);
! return true;
! }
!
!
! /**
! * deleteTopic - deletes the topic info from the db
! *
! * Given the topic_id, it deletes that from the topic table. The
! * psl_topic_lut and psl_topic_submission_lut table must be cleaned
! * first by updating all the stories to point to different topics. It
! * will also check and make sure there are NO stories/submissions
! * associated with this topic before deleting it. Returns true if
! * topic is deleted, false if not.
! *
! * @param integer topic_id
! *
! * @access public
! */
! function deleteTopic($topic_id) {
!
! $go_ahead = true; /* go ahead and assume this topic should be smoked */
!
! if (!$topic_id) {
! return false;
! }
!
! /* check for any stories that are associated with this topic */
!
! $q = "SELECT psl_story.title,
! psl_story.story_id
! FROM psl_story,
! psl_topic_lut
! WHERE psl_story.story_id = psl_topic_lut.story_id
! AND psl_topic_lut.topic_id = '$topic_id'";
! $this->db->query($q);
! while ($this->db->next_record()) {
! $go_ahead = false;
! $title = $this->db->Record["title"];
! $story_id = $this->db->Record["story_id"];
! $topic_name = $this->db->Record["topic_name"];
! echo "Sorry, ths story is assigned to this topic:";
! echo "<FONT COLOR=RED>'$title'</FONT><BR>\n";
! }
!
! /* check for any submissions that are associated with this topic */
!
! $q = "SELECT psl_submission.title,
! psl_submission.story_id
! FROM psl_submission,
! psl_topic_submission_lut
! WHERE psl_submission.story_id = psl_topic_submission_lut.story_id
! AND psl_topic_submission_lut.topic_id = '$topic_id'";
! $this->db->query($q);
! while ($this->db->next_record()) {
! $go_ahead = false;
! $title = $this->db->Record["title"];
! $story_id = $this->db->Record["story_id"];
! $topic_name = $this->db->Record["topic_name"];
! echo "Sorry, this submission is assigned to this topic:";
! echo "<FONT COLOR=RED>'$title'</FONT><BR>\n";
! }
!
! if (!$go_ahead) {
! return false;
! } else {
! $q = "DELETE
! FROM psl_topic
! WHERE topic_id = '$topic_id'";
! $this->db->query($q);
! echo "<i>Topic deleted</i>";
!
! return true;
! }
! }
!
! /**
! * newTopic - spits out a blank form for input
! *
! * Just prints out the "form" and points the user to the "save" method
! * Used only by admin
! *
! * @param array ary
! * @access public
! */
! function newTopic($ary="") {
!
! if($ary["topic_id"] == "") {
! titlebar("100%","Add a new Topic");
! $this->topic_templ->set_var(array(
! TOPICIMAGESDIR => $this->psl[topicimagedir],
! TOPIC_ID => "",
! TOPIC_NAME => "",
! ALT_TEXT => "",
! ONLINKBAR => "",
! ACTION_URL => $this->psl[phpself]
! ));
!
! } else {
! titlebar("100%","Edit Topic");
! $q = "SELECT topic_id,
! topic_name,
! image,
! alt_text,
! onlinkbar
! FROM psl_topic
! WHERE topic_id = '$ary[topic_id]'";
! $this->db->query($q);
! $this->db->next_record();
! $this->topic_templ->set_var(array(
! IMAGE_SRC => $image,
! TOPICIMAGESDIR => $this->psl[topicimagedir],
! TOPIC_ID => $this->db->Record["topic_id"],
! TOPIC_NAME => $this->db->Record["topic_name"],
! ALT_TEXT => $this->db->Record["alt_text"],
! ONLINKBAR => $this->db->Record["onlinkbar"],
! ACTION_URL => $this->psl[phpself]
! ));
! }
!
! $this->topic_templ->set_block("newtopic","image_row","image_rows");
!
! $fulldirlist = dir($this->psl[topicimagedir]);
! while( $eachfile = $fulldirlist->read()) {
! $each = $this->psl[topicimagedir] . "/" . $eachfile;
! if( (is_file($each)) AND
! ( $each != ".") AND
! ( $each != "..") AND
! ( $each != "CVS") ) {
! $this->topic_templ->set_var(array(
! IMAGE => $eachfile
! ));
! $this->topic_templ->set_var(IMAGE_SELECTED,"");
! if ($this->db->Record[image] == $eachfile ){
! $this->topic_templ->set_var(IMAGE_SELECTED,"SELECTED");
! }
!
! $this->topic_templ->parse("image_rows","image_row",true);
! }
! }
!
! $this->topic_templ->parse(OUT,array("newtopic"));
! $this->topic_templ->p(OUT);
!
! }
!
! /**
! * displayTopics - display a list of all available topic images
! *
! * displays the complete list of available topic images
! * Used only by admin
! *
! * @param string option
! * @access public
! */
! function displayTopics($option="") {
!
! $this->topic_templ = new Template($this->psl[templatedir]);
! $this->topic_templ->debug = 0;
! $this->topic_templ->set_file(array(
! displaytopics => "topicsDisplay.tpl"
! ));
!
! titlebar("100%","Display Topic Images");
!
! if( $option != "all") {
! echo "<A HREF=" . $this->psl[phpself] . "?submit=display" . $this->psl[amp] . "option=all>[Display all possible topic images]</A>";
! } else {
!
! $this->topic_templ->set_block("displaytopics","row","rows");
!
! $fulldirlist = dir($this->psl[topicimagedir]);
! while( $eachfile = $fulldirlist->read()) {
! $each = $this->psl[topicimagedir] . "/" . $eachfile;
! if( (is_file($each)) AND
! ( $each != ".") AND
! ( $each != "..") AND
! ( $each != "CVS") ) {
!
! /* calculate height and width */
! $imagesize = getimagesize($this->psl[topicimagedir] . "/" . $eachfile);
! $width = $imagesize[0];
! $height = $imagesize[1];
!
! $imageurlpath = $this->psl[topicimageurl] . "/" . $eachfile;
!
! $this->topic_templ->set_var(array(
! IMAGE_SRC => $imageurlpath,
! IMAGE => $eachfile,
! WIDTH => $width,
! HEIGHT => $height
! ));
!
! $this->topic_templ->parse("rows","row",true);
! }
! }
!
! $this->topic_templ->parse(OUT,array("displaytopics"));
! $this->topic_templ->p(OUT);
! }
! }
!
! /**
! * getName - return name assign to id
! *
! * when given a topic id, getName returns the name
! *
! * @param integer id
! * @access public
! * return author_name
! */
! function getName($id) {
! if (!$id) {
! return false;
! } else {
! $q = "SELECT topic_name
! FROM psl_topic
! WHERE topic_id = '$id'";
! $this->db->query($q);
! $this->db->next_record();
! return $this->db->f("topic_name");
! };
! }
!
! /**
! * getId - return id assign to name
! *
! * when given a name, getId returns the id
! *
! * @param string name
! * @access public
! * return topic_id
! */
! function getId($name) {
! if (!$name) {
! return false;
! } else {
! $q = "SELECT topic_id
! FROM psl_topic
! WHERE topic_name = '$name'";
! $this->db->query($q);
! $this->db->next_record();
! return $this->db->f("topic_id");
! };
! }
!
! /**
! * topicSelect - spit out topic select box
! *
! *
! * @param string varname
! * @param string selected
! * @access public
! * return output
! */
! function topicSelect($varname,$selected) {
!
! $q = "SELECT topic_id, topic_name
! FROM psl_topic";
! $this->db->query($q);
! $output = "<SELECT NAME=\"$varname\">\n";
! $output .= " <OPTION VALUE=\"\">All</OPTION>\n";
! while ($this->db->next_record()) {
! $id = $this->db->f("topic_id");
! $name = $this->db->f("topic_name");
! $output .= " <OPTION VALUE=\"$id\" ";
! if ($id == $selected) {
! $output .= " SELECTED";
! }
! $output .= ">$name</OPTION>\n";
! }
! $output .= "</SELECT>\n";
! return $output;
! }
!
!
! } /* end of Topic.class */
!
?>
--- 1,457 ----
! <?php
!
! /* $Id$ */
!
! /**
! * Provides an API to the PHPSlash Topic Management.
! *
! * This object is how we do anything with topics.
! *
! */
!
! class Topic {
! var $topic_templ; /* the template object */
! var $db; /* the db object */
! var $perm; /* our local version of the perm object */
! var $psl; /* our local version of the _PSL array */
!
! /**
! * The Section Constructor
! *
! * sets up the local version of the global _PSL array, the templates
! * and a few other things
! * @access private
! */
! function Topic () {
!
! global $perm, $_PSL, $amp;
!
! $this->db = new slashDB;
! $this->perm = $perm;
! $this->psl = $_PSL;
!
!
! /* Templates */
! $this->topic_templ = new Template($this->psl[templatedir]);
! $this->topic_templ->debug = 0;
! $this->topic_templ->set_file(array(
! listtopic => "topicList.tpl",
! newtopic => "topicNew.tpl"
! ));
! }
!
! /*
! * METHODS
! */
!
! /**
! * listTopic - list all Topics
! *
! * displays the complete list of topics
! * Used only by admin
! * @access public
! */
! function listTopic() {
!
! $q = "SELECT *
! FROM psl_topic
! ORDER BY topic_name";
! $this->db->query($q);
!
! titlebar("100%","Change existing Topics");
!
! $this->topic_templ->set_block("listtopic","row","rows");
!
! while ($this->db->next_record()) {
!
! $image = $this->psl[topicimageurl] . "/" . $this->db->Record[image];
! $topic_id = $this->db->Record[topic_id];
! if ($this->perm->have_perm("topic,root")) {
! $admin = "<A HREF=\"" . $this->psl[phpself] . "?submit=edit" . $this->psl[amp] . "topic_id=$topic_id\">[Edit]</A>";
! $admin .= " <A HREF=\"" . $this->psl[phpself] . "?submit=delete" . $this->psl[amp] . "topic_id=$topic_id\">[Delete]</A>";
!
! } else {
! $admin = " <A HREF=\"" . $this->psl[phpself] . "?submit=delete" . $this->psl[amp] . "topic_id=$topic_id\">[Delete]</A>";
! }
! $this->topic_templ->set_var(array(
! IMAGE_SRC => $image,
! TOPIC_NAME => $this->db->Record[topic_name],
! WIDTH => $this->db->Record[width],
! HEIGHT => $this->db->Record[height],
! IMAGE => $this->db->Record[image],
! ONLINKBAR => $this->db->Record[onlinkbar],
! ALT_TEXT => $this->db->Record[alt_text],
! TOPIC_ID => $topic_id,
! ACTION_URL => $this->psl[phpself],
! ADMIN => $admin
! ));
! $this->topic_templ->parse("rows","row",true);
! };
! $this->topic_templ->parse(OUT,array("listtopic"));
! $this->topic_templ->p(OUT);
! }
!
!
! /**
! * saveTopic - save the topic info to the DB
! *
! * Saves the topic in the $ary array to the DB
! * Obligatory fields: topic_name, image, width, height, alt_text
! * Optional fields: topic_id (only if this topic is already in the DB),
! * onlinkbar (if blank, defaults to 0)
! * Returns true if sucessful (topic added or updated), false on error
! * Used only by admin
! *
! * @param array $ary
! *
! * @access public
! */
! function saveTopic($ary) {
!
! /* we need to check for the stuff to add in the DB before we actually
! * add anything. And yes, I know it looks like I just passed my
! * "Intro to C++ Programming" class. --ajay
! */
!
! // debug("Topic.class::saveTopic::ary", $ary);
!
! /* We don't test for topic_id because no topic_id means, that
! this is a new topic. */
! if ($ary[topic_name] == "") {
! error("There is no topic_name in Topic.class::saveTopic");
! return false;
! }
! if ($ary[image] == "") {
! error("There is no image in Topic.class::saveTopic");
! return false;
! }
!
! /* calculate height and width */
! $imagesize = getimagesize( $this->psl[topicimagedir] . "/" . $ary[image]);
! $ary[width] = $imagesize[0];
! $ary[height] = $imagesize[1];
!
!
! if ($ary[alt_text] == "") {
! error("There is no alt_text in Topic.class::saveTopic");
! return false;
! }
! /* doesn't error out anymore. Just defaults 'onlinkbar
! to zero */
! if ($ary[onlinkbar] == "") {
! $ary[onlinkbar] = "0";
! }
!
! $ary = clean($ary);
!
! /* if a record exists, then we update, else we insert a new topic! */
!
! $q = "SELECT topic_id
! FROM psl_topic
! WHERE topic_id = '$ary[topic_id]'";
! $this->db->query($q);
! if ($this->db->next_record()) {
! $q = "UPDATE psl_topic
! SET topic_name = '$ary[topic_name]',
! image = '$ary[image]',
! width = '$ary[width]',
! height = '$ary[height]',
! alt_text = '$ary[alt_text]',
! onlinkbar = '$ary[onlinkbar]'
! WHERE topic_id = '$ary[topic_id]'";
! } else {
!
! $ary[topic_id] = generateID("psl_topic_seq");
!
! $q = "INSERT INTO psl_topic
! (topic_id,
! topic_name,
! image,
! alt_text,
! width,
! height,
! onlinkbar)
! VALUES ('$ary[topic_id]',
! '$ary[topic_name]',
! '$ary[image]',
! '$ary[alt_text]',
! '$ary[width]',
! '$ary[height]',
! '$ary[onlinkbar]')";
! }
!
! // echo "<BR><B>QUERY: $q</B><BR>\n";
! $this->db->query($q);
! return true;
! }
!
!
! /**
! * deleteTopic - deletes the topic info from the db
! *
! * Given the topic_id, it deletes that from the topic table. The
! * psl_topic_lut and psl_topic_submission_lut table must be cleaned
! * first by updating all the stories to point to different topics. It
! * will also check and make sure there are NO stories/submissions
! * associated with this topic before deleting it. Returns true if
! * topic is deleted, false if not.
! *
! * @param integer topic_id
! *
! * @access public
! */
! function deleteTopic($topic_id) {
!
! $go_ahead = true; /* go ahead and assume this topic should be smoked */
!
! if (!$topic_id) {
! return false;
! }
!
! /* check for any stories that are associated with this topic */
!
! $q = "SELECT psl_story.title,
! psl_story.story_id
! FROM psl_story,
! psl_topic_lut
! WHERE psl_story.story_id = psl_topic_lut.story_id
! AND psl_topic_lut.topic_id = '$topic_id'";
! $this->db->query($q);
! while ($this->db->next_record()) {
! $go_ahead = false;
! $title = $this->db->Record["title"];
! $story_id = $this->db->Record["story_id"];
! $topic_name = $this->db->Record["topic_name"];
! echo "Sorry, ths story is assigned to this topic:";
! echo "<font color=\"red\">'$title'</font><br />\n";
! }
!
! /* check for any submissions that are associated with this topic */
!
! $q = "SELECT psl_submission.title,
! psl_submission.story_id
! FROM psl_submission,
! psl_topic_submission_lut
! WHERE psl_submission.story_id = psl_topic_submission_lut.story_id
! AND psl_topic_submission_lut.topic_id = '$topic_id'";
! $this->db->query($q);
! while ($this->db->next_record()) {
! $go_ahead = false;
! $title = $this->db->Record["title"];
! $story_id = $this->db->Record["story_id"];
! $topic_name = $this->db->Record["topic_name"];
! echo "Sorry, this submission is assigned to this topic:";
! echo "<font color=\"red\">'$title'</font><br />\n";
! }
!
! if (!$go_ahead) {
! return false;
! } else {
! $q = "DELETE
! FROM psl_topic
! WHERE topic_id = '$topic_id'";
! $this->db->query($q);
! echo "<i>Topic deleted</i>";
!
! return true;
! }
! }
!
! /**
! * newTopic - spits out a blank form for input
! *
! * Just prints out the "form" and points the user to the "save" method
! * Used only by admin
! *
! * @param array ary
! * @access public
! */
! function newTopic($ary="") {
!
! if($ary["topic_id"] == "") {
! titlebar("100%","Add a new Topic");
! $this->topic_templ->set_var(array(
! TOPICIMAGESDIR => $this->psl[topicimagedir],
! TOPIC_ID => "",
! TOPIC_NAME => "",
! ALT_TEXT => "",
! ONLINKBAR => "",
! ACTION_URL => $this->psl[phpself]
! ));
!
! } else {
! titlebar("100%","Edit Topic");
! $q = "SELECT topic_id,
! topic_name,
! image,
! alt_text,
! onlinkbar
! FROM psl_topic
! WHERE topic_id = '$ary[topic_id]'";
! $this->db->query($q);
! $this->db->next_record();
! $this->topic_templ->set_var(array(
! IMAGE_SRC => $image,
! TOPICIMAGESDIR => $this->psl[topicimagedir],
! TOPIC_ID => $this->db->Record["topic_id"],
! TOPIC_NAME => $this->db->Record["topic_name"],
! ALT_TEXT => $this->db->Record["alt_text"],
! ONLINKBAR => $this->db->Record["onlinkbar"],
! ACTION_URL => $this->psl[phpself]
! ));
! }
!
! $this->topic_templ->set_block("newtopic","image_row","image_rows");
!
! $fulldirlist = dir($this->psl[topicimagedir]);
! while( $eachfile = $fulldirlist->read()) {
! $each = $this->psl[topicimagedir] . "/" . $eachfile;
! if( (is_file($each)) AND
! ( $each != ".") AND
! ( $each != "..") AND
! ( $each != "CVS") ) {
! $this->topic_templ->set_var(array(
! IMAGE => $eachfile
! ));
! $this->topic_templ->set_var(IMAGE_SELECTED,"");
! if ($this->db->Record[image] == $eachfile ){
! $this->topic_templ->set_var(IMAGE_SELECTED,"SELECTED");
! }
!
! $this->topic_templ->parse("image_rows","image_row",true);
! }
! }
!
! $this->topic_templ->parse(OUT,array("newtopic"));
! $this->topic_templ->p(OUT);
!
! }
!
! /**
! * displayTopics - display a list of all available topic images
! *
! * displays the complete list of available topic images
! * Used only by admin
! *
! * @param string option
! * @access public
! */
! function displayTopics($option="") {
!
! $this->topic_templ = new Template($this->psl[templatedir]);
! $this->topic_templ->debug = 0;
! $this->topic_templ->set_file(array(
! displaytopics => "topicsDisplay.tpl"
! ));
!
! titlebar("100%","Display Topic Images");
!
! if( $option != "all") {
! echo "<A HREF=" . $this->psl[phpself] . "?submit=display" . $this->psl[amp] . "option=all>[Display all possible topic images]</A>";
! } else {
!
! $this->topic_templ->set_block("displaytopics","row","rows");
!
! $fulldirlist = dir($this->psl[topicimagedir]);
! while( $eachfile = $fulldirlist->read()) {
! $each = $this->psl[topicimagedir] . "/" . $eachfile;
! if( (is_file($each)) AND
! ( $each != ".") AND
! ( $each != "..") AND
! ( $each != "CVS") ) {
!
! /* calculate height and width */
! $imagesize = getimagesize($this->psl[topicimagedir] . "/" . $eachfile);
! $width = $imagesize[0];
! $height = $imagesize[1];
!
! $imageurlpath = $this->psl[topicimageurl] . "/" . $eachfile;
!
! $this->topic_templ->set_var(array(
! IMAGE_SRC => $imageurlpath,
! IMAGE => $eachfile,
! WIDTH => $width,
! HEIGHT => $height
! ));
!
! $this->topic_templ->parse("rows","row",true);
! }
! }
!
! $this->topic_templ->parse(OUT,array("displaytopics"));
! $this->topic_templ->p(OUT);
! }
! }
!
! /**
! * getName - return name assign to id
! *
! * when given a topic id, getName returns the name
! *
! * @param integer id
! * @access public
! * return author_name
! */
! function getName($id) {
! if (!$id) {
! return false;
! } else {
! $q = "SELECT topic_name
! FROM psl_topic
! WHERE topic_id = '$id'";
! $this->db->query($q);
! $this->db->next_record();
! return $this->db->f("topic_name");
! };
! }
!
! /**
! * getId - return id assign to name
! *
! * when given a name, getId returns the id
! *
! * @param string name
! * @access public
! * return topic_id
! */
! function getId($name) {
! if (!$name) {
! return false;
! } else {
! $q = "SELECT topic_id
! FROM psl_topic
! WHERE topic_name = '$name'";
! $this->db->query($q);
! $this->db->next_record();
! return $this->db->f("topic_id");
! };
! }
!
!
! /**
! * getTopics - returns array with topic ids and names
! *
! *
! * @access public
! * return topic_array(id, name)
! */
! function getTopics() {
!
! $q = "SELECT topic_id, topic_name
! FROM psl_topic
! ORDER BY topic_name";
! $this->db->query($q);
!
! while ($this->db->next_record()) {
! $topic_array[] = array(
! "id" => $this->db->f("topic_id"),
! "name" => $this->db->f("topic_name")
! );
! }
!
! return $topic_array;
! }
!
! } /* end of Topic.class */
!
?>
|