sql_errno()>0){ $errno = $db->sql_errno(); $error = $db->sql_error(); return array($errno, $error); } else { return "no errors"; } } //---------------------------------------- // dir contents //---------------------------------------- // get_dir_contents function get_dir_contents($model, $subdir){ global $builder; if ($builder != NULL) $dir= "../"; $dir .= 'model/'.$model.'_'.$subdir.'/'; if (file_exists($dir)) { $handle = opendir($dir); //chdir($dir); while (false !== ($file = readdir($handle))) { if (ereg(".jpg",$file) || ereg(".JPG",$file)) { $dir_array[] = $file; //echo "$file\n"; } } closedir($handle); } else { $dir_array=""; } //chdir("../../"); //print_r ($dir_array); return $dir_array; } //---------------------------------------- // captions //---------------------------------------- // get_caption function get_caption($model){ global $db; $sql = "select * from captions where moc_name='$model'"; $result = $db->query($sql); $inc = 1; while ($line = $db->fetch_array($result)){ $array[$inc] = $line; $inc++; } //print_r($array); return $array; } //---------------------------------------- // hits functions //---------------------------------------- // add_button_hit function add_button_hit($button){ global $db; $select = "select * from links where entry_id='$button'"; $result = $db->query($select); $line = $db->fetch_array($result); $old_hits = $line["hits"]; $hits = $old_hits + 1; $update = "update links set hits='$hits' where entry_id='$button'"; $db->query($update); } // add_model_hit function add_model_hit($model){ global $db; $select = "select * from moc where shortname='$model'"; $result = $db->query($select); $line = $db->fetch_array($result); $old_hits = $line["hits"]; $hits = $old_hits + 1; $update = "update moc set hits='$hits' where shortname='$model'"; $db->query($update); } // -------------------------------------------------- // news functions // -------------------------------------------------- // get_news function get_news($builder){ global $db; if ($builder != NULL) $builder="where builder='$builder'"; $sql = "select * from news $builder order by date DESC"; $result = $db->query($sql); $inc = 1; while ($line = $db->fetch_array($result)){ $array[$inc] = $line; $inc++; } // print_r($array); return $array; } // -------------------------------------------------- // latest functions // -------------------------------------------------- // get_latest function get_latest(){ global $db; $sql = "select * from moc order by date DESC"; $result = $db->query($sql); $inc = 1; while ($line = $db->fetch_array($result)){ $array[$inc] = $line; $inc++; } // print_r($array); return $array; } // -------------------------------------------------- // list products functions // -------------------------------------------------- // get_list_prod function get_list_prod($what, $builder, $sort){ global $db; if (!$sort) { $sort = "date"; } if ($sort == "shortname") { $order = "ASC"; } else { $order = "DESC"; } if ($sort=="rand") { $sort=""; $order= "RAND() LIMIT 0,20"; } if ($builder !=NULL) $where= "builder='$builder' and"; if ($what !=NULL) $line="line='$what'"; $sql = "select * from moc where $where $line order by $sort $order"; //echo $sql; $result = $db->query($sql); $inc = 1; while ($line = $db->fetch_array($result)){ $array[$inc] = $line; $inc++; } // print_r($array); return $array; } // get_1_prod function get_1_prod($builder){ global $db; $continue=true; while ($continue==true) { $line=""; if ($builder!=NULL) $where= "WHERE builder='$builder'"; $sql = "select * from moc $where ORDER BY RAND() LIMIT 0,1"; $result = $db->query($sql); $line = $db->fetch_array($result); if ($line["submoc"] == "0") { $continue=false; } } //print_r($line); return $line; } // get_prod_info function get_prod_info($m){ global $db; $sql = "select * from moc where shortname='$m'"; $result = $db->query($sql); $line = $db->fetch_array($result); if ($db->num_rows($result) == 0) { return ''; } else { return $line; } } // get_list_prod_all function get_list_prod_all($sort){ global $db; if (!$sort) { $sort = "date"; } if ($sort == "shortname") { $order = "ASC"; } else { $order = "DESC"; } $sql = "select * from moc order by '$sort' $order"; $result = $db->query($sql); $inc = 1; while ($line = $db->fetch_array($result)){ $array[$inc] = $line; $inc++; } // print_r($array); return $array; } // -------------------------------------------------- // faq functions // -------------------------------------------------- // get_faq function get_faq($builder){ global $db; $sql = "select * from faq where hidden=0 AND builder='$builder' OR builder='everyone' order by faq_id DESC"; $result = $db->query($sql); $inc = 1; while ($line = $db->fetch_array($result)){ $array[$inc] = $line; $inc++; } // print_r($array); return $array; } // -------------------------------------------------- // model of the moment functions // -------------------------------------------------- // get_motm function get_motm(){ global $db; $sql = "select * from motm order by entry_id DESC"; $result = $db->query($sql); $inc = 1; while ($line = $db->fetch_array($result)){ $array[$inc] = $line; $inc++; } // print_r($array); return $array; } // -------------------------------------------------- // links functions // -------------------------------------------------- // get_links function get_links($order, $n){ global $db; $sql = "select * from links where hidden=0 ORDER BY $order LIMIT 0,$n"; $result = $db->query($sql); $inc = 1; while ($line = $db->fetch_array($result)){ $array[$inc] = $line; $inc++; } // print_r($array); return $array; } // get_links_all function get_links_all(){ global $db; $sql = "select * from links where hidden=0 order by hits DESC"; $result = $db->query($sql); $inc = 1; while ($line = $db->fetch_array($result)){ $array[$inc] = $line; $inc++; } // print_r($array); return $array; } // get_1_link function get_1_link($go){ global $db; $sql = "select * from links where entry_id=$go"; $result = $db->query($sql); $line = $db->fetch_array($result); if ($db->num_rows($result) == 0) { return 'http://neutronbot.com/?err=404'; } else { return $line["url"]; } } // add shit to db functions --------------------------- //----------------------------------------------------- // add_item function add_item($item,$vars_array){ global $db; switch ($item){ case "motm": $table = "motm"; $id_name = "entry_id"; break; case "links": $table = "links"; $id_name = "entry_id"; break; case "news": $table = "news"; $id_name = "entry_id"; break; case "captions": $table = "captions"; $id_name = "caption_id"; break; case "moc": $table = "moc"; $id_name = "moc_id"; break; case "captions": $table = "captions"; $id_name = "caption_id"; break; case "faq": $table = "faq"; $id_name = "faq_id"; break; } $inc = 1; $fields = ""; $values = ""; foreach($vars_array as $key => $value){ if ($key != "id"){ if ($key == "date"){ $value = $this->format_date_for_mysql($value); } if ($key == "perms"){ $key = "permissions"; //print_r($value); foreach($value as $pkey => $pvalue){ $ptotal = $ptotal + $pvalue; } $value = $ptotal; } if ($key == "visible"){ $value = ($value==1) ? 1 : 0; } if ($inc > 1) $fields .= ", "; $fields .="$key"; if ($inc > 1) $values .= ", "; $values .="'$value'"; $inc++; } } $item_sql = "insert into $table ($fields) values ($values)"; //echo "
".$item_sql; $db->query($item_sql); return $db->sql_insert_id(); } // end class } ?>