X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Fdb%2Ftags_db.inc;h=40602a942b0c11183582bad6a006eb9a85868f64;hb=9044444ee1933dc684c6aab26ac718e65ce8c370;hp=2e7ac061b4af47d89a5fd4340ad14c43702fae07;hpb=2cbd76da9ed3363d59628e51319524ca103d9c47;p=fa-stable.git diff --git a/admin/db/tags_db.inc b/admin/db/tags_db.inc index 2e7ac061..40602a94 100644 --- a/admin/db/tags_db.inc +++ b/admin/db/tags_db.inc @@ -65,7 +65,7 @@ function get_tag_type($id) $result = db_query($sql, "could not get tag type"); $row = db_fetch_row($result); - return $row[0]; + return is_array($row) ? $row[0] : false; } //-------------------------------------------------------------------------------------- @@ -75,11 +75,27 @@ function get_tag_name($id) $sql = "SELECT name FROM ".TB_PREF."tags WHERE id = ".db_escape($id); $result = db_query($sql, "could not get tag name"); - + $row = db_fetch_row($result); - return $row[0]; + return $row ? $row[0] : ''; } +//---------------------------------------------------------------------------------------------------- +function get_tag_names($tags) +{ + $str = ""; + if ($tags == -1) + return $str; + foreach($tags as $id) + { + $tag = get_tag_name($id); + if ($str == "") + $str .= $tag; + else + $str .= ", ".$tag; + } + return $str; +} //-------------------------------------------------------------------------------------- function get_tag_description($id) @@ -89,7 +105,7 @@ function get_tag_description($id) $result = db_query($sql, "could not get tag description"); $row = db_fetch_row($result); - return $row[0]; + return is_array($row) ? $row[0] : false; } //-------------------------------------------------------------------------------------- @@ -125,19 +141,29 @@ function update_tag_associations($type, $recordid, $tagids) } //-------------------------------------------------------------------------------------- - // To delete tag associations, we need to specify the tag type. // Otherwise we may inadvertantly delete records for another type of tag +// function delete_tag_associations($type, $recordid, $all=false) { - $sql = "DELETE ta FROM ".TB_PREF."tag_associations AS ta - INNER JOIN ".TB_PREF."tags AS tags ON tags.id = ta.tag_id +/* multiply table DELETE syntax available since MySQL 4.0.0: + $sql = "DELETE ta FROM ".TB_PREF."tag_associations ta + INNER JOIN ".TB_PREF."tags tags ON tags.id = ta.tag_id WHERE tags.type = ".db_escape($type)." AND ta.record_id = ".db_escape($recordid); - +*/ + // To support MySQL 3.xx we have to use multiply queries + $sql = "SELECT * FROM ".TB_PREF."tag_associations ta + INNER JOIN ".TB_PREF."tags tags ON tags.id = ta.tag_id + WHERE tags.type = ".db_escape($type)." AND ta.record_id = ".db_escape($recordid); if (!$all) $sql .= " AND tags.inactive = 0"; + $result = db_query($sql, "could not select tag associations"); - db_query($sql, "could not delete tag associations"); + while($ta = db_fetch($result)) { + $sql2 = "DELETE FROM ".TB_PREF."tag_associations WHERE + record_id = '".$ta['record_id']."' AND tag_id=".$ta['tag_id']; + db_query($sql2, "could not delete tag associations"); + } } //-------------------------------------------------------------------------------------- @@ -180,4 +206,17 @@ function get_tags_associated_with_record($type, $recordid) //-------------------------------------------------------------------------------------- -?> \ No newline at end of file +function is_record_in_tags($tags, $type, $recordid) +{ + foreach($tags as $id) + { + $sql = "SELECT ta.record_id FROM ".TB_PREF."tag_associations AS ta + INNER JOIN ".TB_PREF."tags AS tags ON tags.id = ta.tag_id + WHERE tags.type = $type AND tags.id = $id AND ta.record_id = ".db_escape($recordid); + $res = db_query($sql, "could not get tags associations for record"); + if (db_num_rows($res) == 0) + return false; + } + return true; +} +