Location: PHPKode > projects > JACR - Just Another Checkbook Register > jacr_0.0.4/jacr-platform/tags.class.php
<?php
require_once('DBConn/table.class.php');

class Tags extends DBTable{
	 var $taggedID;
	 var $taggedStr;
	public function __construct ($taggedID, $taggedStr){
		global $dbname, $dbTablPre;
		if(is_numeric($taggedID))
			$this->taggedID = $taggedID;
		if ( isset($taggedStr) )
			$this->taggedStr = $taggedStr;
		$this->tablename       =  $dbTablPre.'tags';
		$this->dbname          = $dbname;
		$this->rows_per_page   = 0;
		
		$this->fieldlist = array(
						   'id' =>			array('int(11)', 'NOT NULL', NULL, 'auto_increment'),
						   'tag' =>			array('varchar(255)', 'NOT NULL', NULL, NULL),
						   'sibling_tag' =>	array('int(11)', 'NOT NULL', 0, NULL)
						   );
		$this->pKEY='id';
		$this->uniqueKEY[] = 'tag';
	}

	public function getTagId($tag){
		$exist = $this->getData('tag="'.$tag.'"');
		if( is_array($exist) )
			return( $exist[0]['id'] );
		else
			return(0);  
	}
	public function getTagName($id)
	{
		$exist = $this->getData('id="'.$id.'"');
		if( is_array($exist) )
			return( $exist[0]['tag'] );
		else
			return(false); 
		
	}
	public function getTags()
	{
		$GetTags = new Tagged_items($this->taggedStr, 0,$this->taggedID);
		#echo $this->taggedID . "<br />";
		$ids = $GetTags->getTagsIds();
		$tags = NULL;
		foreach ($ids as $id)
			$tags[] = array( $id, $this->getTagName($id) );
		return ($tags);
	}
	public function showTags()
	{
		$tags = $this->getTags();

			
	}
	public function addTag($tag)
	{
		$id = $this->getTagId( strtolower($tag) );
		$TagItem = new Tagged_items($this->taggedStr, $id, $this->taggedID);
		$TagItem->deleteTags();
		if($id > 0){
			$TagItem->tagItem();
		}
		else{
			$this->insertRecord( array('tag' => strtolower($tag)) );
			$id = $this->getTagId( strtolower($tag) );
			$TagItem->tagItem();
		}
			
	}

	public function addTags($tags)
	{
		
		#printArray($tags);
		foreach ($tags as $tag){
		$this->addTag($tag);
		}

	}

public function tagForm($q)
{
if( isset($_POST["tags"]) )
$this->addTags($_POST["tags"]);
if( isset($q) )
$q = "&amp;".$q;
else
  $q=NULL;
echo '
    <form action="?taggedID='.$this->taggedID.'&amp;taggedStr='.$this->taggedStr.''.$q.'" method="post" accept-charset="utf-8">
       
      <select id="tags" name="tags">';
			  $tagArg = $this->getTags();
			  foreach($tagArg as $tag){
				  echo '<option value="'.$tag[0].'" class="selected">'.$tag[1].'</option>';
			  }
      echo '
	 </select>
      
      <input type="submit" value="Save Tags">     
    </form>  
    <script language="JavaScript">
        $(document).ready(function() 
        {        
          
          $("#tags").fcbkcomplete({
            json_url: "'.$_SERVER['SCRIPT_NAME'].'",
            cache: true,
            filter_case: true,
            filter_hide: true,
			firstselected: true,
            //onremove: "testme",
			//onselect: "testme",
            filter_selected: true,
            newel: true        
          });		 
        });
		
		function testme(item)
	  	{	if ($.browser.mozilla) 
			{
				console.log(item);
			}
			else
			{
				alert(item);
			}		  	
	  	}    
    </script>

';
}
					  
}
Return current item: JACR - Just Another Checkbook Register