l = $l; $this->get_categories(); } function get($id, $data) { return $this->categories[$id][$data]; } function get_id($url) { foreach($this->categories AS $cat) { if($cat['url'] == $url) return $cat['id']; } } function get_categories() { if(!defined("JLOG_UPDATE") AND !defined("JLOG_LOGIN")) { $sql = "SELECT id, name, url, description FROM ".JLOG_DB_CATEGORIES; $cat = new Query($sql); if($cat->error()) { echo "
\n";
                echo $cat->getError();
                echo "
\n"; die(); } while($c = $cat->fetch()) { $this->categories[$c['id']] = array('id' => $c['id'], 'name' => $c['name'], 'url' => $c['url'], 'description' => $c['description'] ); } } } function get_assigned_categories($id) { $sql = "SELECT cat_id FROM ".JLOG_DB_CATASSIGN." WHERE content_id = '".$id."'"; $assigned = new Query($sql); if($assigned->error()) { echo "
\n";
            echo $assigned->getError();
            echo "
\n"; die(); } $ids = array(); while($a = $assigned->fetch()) { $ids[] = $a['cat_id']; } return $ids; } function output_select($catassign) { // $catassign is an array which contains all assigned ids if(count($this->categories) > 0) { $output = "


\n" ." \n

"; return $output; } } function output_rss($id) { $ids = $this->get_assigned_categories($id); if(is_array($ids)) { foreach($ids AS $i) { $output .= " ".$this->get($i, 'name')."\n"; } } return $output; } function output_assigned_links($ids) { if(!is_array($ids)) $ids = $this->get_assigned_categories($ids); if(is_array($ids)) { foreach($ids as $id) { $output .= $this->link($id)." "; } } if(isset($output)) return " » ".$output.""; } function output_whole_list($_before = " \n", $before = "
  • ", $after = "
  • \n") { if(is_array($this->categories) AND count($this->categories)) { $output = $_before; foreach($this->categories AS $id => $tmp) { $output .= $before.$this->link($id).$after; } $output .= $_after; return $output; } else return false; } function link($id) { if(JLOG_CLEAN_URL) return "".$this->categories[$id]['name'].""; else return "".$this->categories[$id]['name'].""; } function output_whole_list_admin() { $output = " "; foreach($this->categories AS $id => $tmp) { $output .= " \n"; } $output .= "
    ".$this->l['admin']['change']." ".$this->l['admin']['delete']." ".$this->l['admin']['cat_name']."
    ".$this->l[ ".$this->l[ ".$this->link($id)."
    \n"; return $output; } function output_form($form_input = "", $action = 'new', $legend) { $output = "
    ".$legend."




    ".$this->l['admin']['cancel']." ".add_session_id_input_tag()."

    "; return $output; } function new_cat($form_input) { $form_input = escape_for_mysql($form_input); $sql = "INSERT INTO ".JLOG_DB_CATEGORIES." (name, url, description) VALUES ('".$form_input['name']."', '".$form_input['url']."', '".$form_input['description']."');"; $new = new Query($sql); if($new->error()) { echo "
    \n";
             echo $new->getError();
             echo "
    \n"; die(); } } function change_cat($form_input) { $form_input = escape_for_mysql($form_input); $sql = "UPDATE ".JLOG_DB_CATEGORIES." SET name = '".$form_input['name']."', url = '".$form_input['url']."', description = '".$form_input['description']."' WHERE id = '".$form_input['id']."' LIMIT 1;"; $change = new Query($sql); if($change->error()) { echo "
    \n";
             echo $change->getError();
             echo "
    \n"; die(); } } function trash_cat($id) { $sql = "DELETE FROM ".JLOG_DB_CATEGORIES." WHERE id = '".escape_for_mysql($id)."' LIMIT 1"; $trash = new Query($sql); if($trash->error()) { echo "
    \n";
            echo $trash->getError();
            echo "
    \n"; die(); } $sql = "DELETE FROM ".JLOG_DB_CATASSIGN." WHERE cat_id = '".escape_for_mysql($id)."' LIMIT 1"; $trash = new Query($sql); if($trash->error()) { echo "
    \n";
            echo $trash->getError();
            echo "
    \n"; die(); } } function validate($form_input) { if(empty($form_input['name'])) $errors[] = $this->l['admin']['cat_noname']; if(empty($form_input['url'])) $errors[] = $this->l['admin']['no_url']; elseif(!preg_match("/^[a-z0-9\-_\.,]+$/", $form_input['url'])) $errors[] = $this->l['admin']['false_url_letters']; else { $sql = "SELECT id FROM ".JLOG_DB_CATEGORIES." WHERE url = '".escape_for_mysql($form_input['url'])."';"; $check_url = new Query($sql); if($check_url->error()) { echo "
    \n";
                 echo $check_url->getError();
                 echo "
    \n"; die(); } if($check_url->numRows() > 0) { $c = $check_url->fetch(); if($c['id'] != $form_input['id']) $errors[] = $this->l['admin']['cat_duplicate']; } } return $errors; } } ?>