<?
// Your agreement with TNuG gives you a limited license to access and use this library.
// You may access the library for your own private or business use. 
// You may not reproduce, copy, or redistribute, whole or in part, any of the library that constitutes the TNuG's library functions without written permission.

// Object Template Stripped Version
// Version 0.3h

// Version 0.3h - Changed methods system and added proclayout
//              - removed header/footer, never used
//              - added sorting of results
// Version 0.3g - Update to select optimization, changed text to number field
// Version 0.3f - Update to select optimization, added fieldname
// Version 0.3e - Multiple DB Support by declaration of $SQL_APP_DB
// Version 0.3d - Large record select optimize by full flag in getpictureformfields
// Version 0.3c - fixed typo in edit patch
// Version 0.3b - fixed typo
//              - start of security patch to edit($id)
// Version 0.3a - getpictureformfields added prepend
//              - massing beginnings
//              - cleaned up & simplified dir & field navigate
//              - moved unnessicary examples to addon to reduce filesize
// Version 0.3 - Page_nav fix
//             - Header Var hook to interface
// Version 0.2.9a - templat_query typo
// Version 0.2.9 - Made remove use view
//               - Created specific groups
// Version 0.2.8a - Fixed some case issues
// Version 0.2.8 - Fixed colors again, added cancel buttons
//                - Fixed find, added picture_ prefix to ses vars to allow layering
//		  - Added Search Form in display, Added LookUp on selects
// Version 0.2.7h - Fixed colors and removed display field ordering
//                - cleaned up search header/footer
//		  - fixed sql search
// Version 0.2.7g - add color in trs
// Version 0.2.7f - Fixed lotsa Errors
// Version 0.2.7e - Paging with search is fixed
//                - New Find/Search/PickRec selection integration
//                - REFixed ugly validation bug wif exit; 
// Version 0.2.7d - Speed Ups: change upd to pull 0 instead of $id, 
//                - add cache to getpictureform, allow passing of $row
// Version 0.2.7c - Fixed ugly validation bug wif exit; made searches have no rpp
// Version 0.2.7b - messed with pagenav
// Version 0.2.7a - Added Define loaded and Netscape 4.x hack
//
// Version 0.2.7 - Rearranged PagNav, Add RPP, and fixed some var declarations
//               - Fixed <tr> in display
// Version 0.2.6 - Fixed Next/Prev Error -Neuro.
//		 - Add new paging nav - Neuro.
// Version 0.2.5 - prepended picture to search_header and search_footer - Neuro.
//               - Also changed picture_view to use public group - Neuro.
//		 - removed $id from ins - Neuro.
// 		 - Fixed form cache error - Neuro.
//		 - Smore search syntax - Neuro.
// Version 0.2.4 - Added default HIDNUM for IDs to make methods work - Neuro.

function getlayout($pictureid=0,$row="") {
global $filename,$myauth;
global $glob_layout;
global $glob_anon;
global $glob_header;
global $glob_footer;
$glob_layout='
<center><br>
<br>
<hr size="1" width="642" noshade color="#000000"><br>
<br>
';
if ($row['originalid']) {
$glob_layout.='Continued from [<A 
HREF="'.geturl($filename.'?obj=picture&action=view&id='.$row['originalid']).'">'.$row['originalid'].'</A>], 
<A 
HREF="'.geturl($filename.'?obj=picture&action=showcont&id='.$row['originalid']).'">Click 
here to see the series...</A><br>';
/*
$glob_layout.='
Original:
<img src="data/'.$row['originalid'].'.png" width="<width>" height="<height>"  
alt="<title>" border="1">
';
*/
}
$glob_layout.='
<img src="data/<pictureid>.png" width="<width>" height="<height>" 
alt="<title>" border="1"><br>';
if ($row['userid']==$myauth['id']) {
$row['allowanim']=1; $row['allowcontinue']=1;
//if (useringroup(array('administrator'))) {
$glob_layout.="<b><A HREF=\"".geturl('draw.php3?action=replace&id='.$row['pictureid'])."\">Finish!</A></b><br>\n";
//}
}
if ($row['anim']) {
if ($row['allowanim']) {
$glob_layout.='<b><A HREF="'.geturl($filename.'?obj=picture&action=animate&id='.$row['pictureid']).'">View Animation!</A></b><br>';
}
if ($row['allowcontinue']) {
$glob_layout.='<b><A HREF="'.geturl('draw.php3?action=continue&id='.$row['pictureid']).'">Continue</A></b><br>'; 
}
}
$glob_layout.='<br>
<br>
<table align="center" border="0" width="642" cellspacing="0" 
cellpadding="1" bgcolor="#A82800"><tr><td><table align="center" border="0" 
width="642" cellspacing="0" cellpadding="4" bgcolor="#ffffff">
  <tr>
    <td><p><center>Title: <b><title></b>&nbsp;<br>
    Artist: 
<b><A 
HREF="'.geturl('interface.php3?obj=picture&action=search&strict=1&name='.$row['name']).'"><name></A></b><br>
    Homepage: <b><homepage></b>&nbsp;&nbsp;&nbsp; email: <b><email></b><br>
    (';
if (useringroup(array('administrator'))) {
$glob_layout.='<b>Started:&nbsp;</b><start> - ';
}
$glob_layout.='<b>Finished:&nbsp;</b><stop>)<br>
    </center></p>
    <p><b>Artist(<A 
HREF="'.geturl('interface.php3?obj=picture&action=search&strict=1&name='.$row['name']).'"><name></A>)\'s 
Comments:</b><br>
    <authorcomments></p>
';
$glob_anon='
<center><br>
<br><hr size="1" width="642" noshade color="#000000"><br>
<br>
<img src="data/<pictureid>.png" width="<width>" height="<height>" 
alt="<title>" border="1"><br>
<br>
<table align="center" border="0" width="642" cellspacing="0"
cellpadding="1" bgcolor="#A82800"><tr><td><table 
align="center" border="0" width="642" cellspacing="0" 
cellpadding="4" bgcolor="#ffffff">
  <tr>
    <td><p><center>Title: <b><title></b> &nbsp; <b>(<stop>)</b><br>
    Artist: <b>Anonymous</b><br>
    (';
if (useringroup(array('administrator'))) {
$glob_anon.='<b>Started:&nbsp;</b><start> - ';
}
$glob_anon.='<b>Finished:&nbsp;</b><stop>)<br>
    </center></p>
    <p><b>Artist\'s Comments:</b><br>
    <authorcomments></p>
';
$glob_header=''; // before layout
$glob_footer='[<a href="http://oekaki.kenshin.net/002/">Click here 
to reload the page</a> | <A HREF="'.geturl($filename.'?obj=comment&action=new&pictureid='.$pictureid).'">Add new comment</A>
]</td></tr></table></td></tr></table></center>';
}

if (defined("ALREADY_LOADED_picture_INTERFACE")) return;
define("ALREADY_LOADED_picture_INTERFACE",1);

// Interface Override
// $finish['method'] = "contact_view();";
// Authwrapper Override - Not working
// $security['method'] = array('users' => "''",'groups' => "''");

// $SQL_APP_DB = '';

// Header Msgs
$header=array();
$header['new']="New picture";
$header['edit']="Edit picture";
$header['remove']="Remove picture";
$header['browse']="Browse pictures";
$header['ins']="Browse pictures";
$header['upd']="Browse pictures";
$header['del']="Browse pictures";
$header['search']="Search pictures";
$header['search_form']="Search pictures";
$header=array();

function getpictureformfields($form,$row,$prepend='',$full=1) {
  global $filename;
  $form->setgroup(array('new','edit','search','view','mass','editac'));  
  // Netscape 4.x Bug Hack (ns returns ' ', on <input hidnum name> (no val))
  if (isset($row['pictureid'])) {
    $form->addcontrol('HIDNUM',$prepend.'pictureid',$row['pictureid']);
  }
//  print_r($row);
  $form->setgroup(array('display'));
  $form->addcontrol('NUMBER',$prepend.'pictureid',$row['pictureid']);
  $form->setgroup(array('search','display','view','mass'));
  $form->addcontrol('NUMBER',$prepend.'width',$row['width'],'Width:','',4);
  $form->addcontrol('NUMBER',$prepend.'height',$row['height'],'Height:','',4);
#  $form->setgroup(array('new','edit'));
  $form->addcontrol('HIDNUM',$prepend.'userid',$row['userid']);
  $form->addcontrol('DATETIME',$prepend.'start',$row['start'],'Start:');
  $form->addcontrol('TEXT',$prepend.'stop',$row['stop'],'Stop:');
$form->setgroup(array('new','edit','search','display','view','mass','editac'));    
  $form->addcontrol('TEXT',$prepend.'title',$row['title'],'Title:','',128);
$form->setgroup(array('new','edit','search','display','view','mass'));  
  $form->addcontrol('TEXT',$prepend.'name',$row['name'],'Name:','',128); 
$form->addcontrol('EMAIL',$prepend.'email',$row['email'],'Email:','',128);
$form->addcontrol('LINK',$prepend.'homepage',$row['homepage'],'Homepage:','',128); 
  $form->setgroup(array('new','edit','search','display','view','mass','editac'));    
$form->addcontrol('HTMLEDIT',$prepend.'authorcomments',$row['authorcomments'],'Comments:','',' ROWS=5 COLS=60');
$form->addcontrol('checkbox',$prepend.'gallery',$row['gallery'],'Include in your gallery?:');
$form->addcontrol('CHECKBOX',$prepend.'allowcontinue',$row['allowcontinue'],'Allow others to continue picture:');
$form->addcontrol('CHECKBOX',$prepend.'allowanim',$row['allowanim'],'Allow others to view animation:');
  $form->setgroup(array('new','edit','search','display','view','mass'));
$form->addcontrol('CHECKBOX',$prepend.'anonymous',$row['anonymous'],'Post Anonymously?');
  $form->setgroup(array('new','edit','search','display','view','mass','editac'));    
//  echo $form->debugform();
  return $form;
}

function picturetopmethods() {
global $filename;
# if (useringroup(array('admin'))) {
#echo ' | <A HREF="'.geturl($filename.'?obj=picture&action=new').'">Add new picture</A>';
#echo '<br>';
# }
}

function getpictureformmethods($form) {
  global $pickrec,$ses;
  $sid=getauthses();
  if (!isset($pickrec)) {
  $pickrec=$ses->get_var($sid,'picture_pickrec');
  } else {
  $ses->set_var($sid,'picture_pickrec',$pickrec);
  }  
#  $form->addmethod($filename . '?obj=picture&action=edit&id=', 'edit picture', 'pictureid',0);
#  $form->addmethod($filename . '?obj=picture&action=remove&id=', 'remove picture', 'pictureid',0);
# }
  if ($pickrec) {
    $form->addmethod($filename . '?obj=picture&action=return&id=', 'select', 'pictureid',3);
  }
  return $form;
}

function getpictureform($pictureid,$action,$name,$params="",$cache="") {
  global $conn,$SYND,$filename,$NeuroOekakiUserid;
  if (empty($pictureid)) {
    # Defaults
    // NEVER USED
    $row['int']=0; #$row['userid']=$NeuroOekakiUserid;
    $row['varchar']='';
    $row['date']=date('Y-m-d');
  } else {
    if ($cache == "") {
      $sql="select * from pictures where pictureid=$pictureid";
      $result=sqlexec($sql,$conn,0);
      $row=sqlgetrow($result);
    } else {
      $row=$cache;
    }
  }
  $form=new form(geturl("$filename?obj=picture&id=" . $pictureid . "&action=" .$action . $params) ,"POST",1,1,1);
  if (empty($action)) { $full=0; } else { $full=1; }
  $form=getpictureformfields($form,$row,'',$full);
  if (!$full) {
    $form=getpictureformmethods($form);
  }
  $form->conn=$conn;
  // End
  $form->addcontrol("SUBMIT","submit",$name);
  return $form;
}

function picture_return($id) {
global $DEBUG_LEVEL,$ses;
    if (($DEBUG_LEVEL & 16) == 16) { 
      $name="formdata_pictureid";
    } else {
      $name='pictureid';
    }
    $sid=getauthses();
    $ses->clear_var($sid,'picture_pickrec');
?>
<Script Language="JavaScript">
<!--
// Forget everything we are doing
// and close this window.
  window.opener.<? echo $name; ?>_ItemInEdit.value = <? echo $id?>;
  opener.focus();
  window.close();
//-->
</Script>
<?
}

function picture_debug() {
  $form=getpictureform(0,'','');
  $form->debugform();
}

function picture_del($pid="") {
  // Put all relationships here
  global $ses,$auth_sid;
  $id=(int)$ses->get_var($auth_sid,'picture_remove_id');    
#  echo "Deleteing [$id]<br>\n";
  sqlexec("delete from pictures where pictureid=$id");
  sqlexec("delete from comments where pictureid=$id");
  sqlexec("update pictures set originalid=0 where originalid=$id");
  log_transac("picture","remove",$id,"");
}

function picture_new($id=0, $params="") {
  $form=getpictureform(0,'ins','Add picture',$params);
  echo $form->generate("edit",array('new'));
}

function picture_upd($pid) {
  global $filename;
  $form=getpictureform(0,'','');
  $check=$form->check_results(array('edit'));
  if (is_array($check)) {
    $ok=1;
    while(list($key,$val)=each($check)) {
            if ($val != "") {  echo $val . ' is not a valid value<br>'; $ok=0; }	    
    }
    if (!$ok) { exit; }
  }
  global $ses,$auth_sid;
  $id=(int)$ses->get_var($auth_sid,'picture_edit_id');    
  $form->update_table("pictures","pictureid='$id'",array('edit'));
  log_transac("picture","edit",$id,"");
}

function picture_browse() {
  //global $SYND;
  //picture_display(" where syndicateid=$SYND");
  global $ses;
  $sid=getauthses();
  $sql="select * from pictures where stop!='0000-00-00' order by stop desc";
  $ses->set_var($sid,'picture_query',$sql);
  picture_display();
}

function picture_pagnav($start,$ttlrow) {
global $filename,$rpp,$action,$id,$obj;
  $obj='picture';
  if ($rpp == 0) { return; }
  if ($ttlrow<$rpp) { return; }  
  $back = $start-$rpp; if ($back < 0) { $back=0; }
  $next = $start+$rpp; 
  $action="display";
  $id=0;
#  echo "obj[$obj]act[$action]<br>\n";
#  echo "begin[0]start[$start]ttlrow[$ttlrow]<br>\n";
#  echo "back[$back]next[$next]<br>\n";
  if ($start == 0 ) {
    echo '<p><center><a href="'.geturl($filename.'?obj='.$obj.'&start='.$next.'&id='.$id.'&action='.$action). '">Next '.$rpp.'</A> | ';
    echo '<a href="'.geturl($filename.'?obj='.$obj.'&start='.($ttlrow-$rpp).'&id='.$id.'&action='.$action) . '">End</A>';    
  } elseif ( $ttlrow < $next )  {
    echo '<a href="'.geturl($filename.'?obj='.$obj.'&start=0'.'&id='.$id.'&action='.$action) . '">Beginning</A> | ';  
    echo '<a
href="'.geturl($filename.'?obj='.$obj.'&start='.$back.'&id='.$id.'&action='.$action)
. '">Prev '.$rpp.'</A>';
  } else {
    echo '<a href="'.geturl($filename.'?obj='.$obj.'&start=0'.'&id='.$id.'&action='.$action) . '">Beginning</A> | '; 
    echo '<a href="'.geturl($filename.'?obj='.$obj.'&start=' .
$back.'&id='.$id.'&action='.$action) . '">Prev '.$rpp.'</A> | <a
href="'.geturl($filename . '?obj='.$obj.'&start=' .
$next.'&id='.$id.'&action='.$action).'">Next '.$rpp.'</A> | ';
    echo '<a href="'.geturl($filename.'?obj='.$obj.'&start='.($ttlrow-$rpp).'&id='.$id.'&action='.$action) . '">End</A>';    
  }
echo '</center><br>';
}

function picture_display($result=0) {
  global $filename,$conn,$start,$rpp,$action,$start,$ses,$sortby;
  $sid=getauthses();
  if (empty($start)) { $start = 0; }
  if ($result==0) { 
    $sql=$ses->get_var($sid,'picture_query');
    #echo "Found Query [$sql] [$sid]<br>\n";
    if (empty($sql)) {
      $sql="select * from pictures";
      $ses->set_var($sid,'picture_query',$sql);
    }
    if ($sortby) {
      if (eregi('order by',$sql)) {
        # be careful of limit and order by
	$sql=substr($sql, 0, strpos($sql,'order by')). " order by $sortby";
      }
    }
// What's wrong with Loop done? paging
    $loopdone=1;
// ah, this:
    $cntsql=eregi_replace('^select.*from','select count(*) from',$sql);
//    if (useringroup(array('administrator'))) {
//      echo "cnt[$cntsql] sql[$sql]<br>\n";
//    }
    $result=sqlexec($cntsql,$conn);
    list($cnt)=sqlgetrow($result);
#    echo "rpp[$rpp] start[$start]<Br>\n";
    if ($start) { $p1=$start; $p2=$rpp; } else { $p1=$rpp; $p2=''; }
    $result=sqlexec($sql,$conn,0,$p1,$p2);
#    echo getsqlq();
#    $result=sqlexec($sql,$conn,0);
  }
  if (!isset($pickrec)) { $pickrec=0; }
  if ($loopdone) {
    $ttlrow=$cnt;
  } else {
    $ttlrow=sqlgetnumrows($result);
  }
  picture_pagnav($start,$ttlrow);
#  picture_search_form();
  picturetopmethods();
global $glob_layout,$glob_anon,$glob_header,$glob_footer;
#  echo '<table border=3><tr>';
#  $form=getpictureform(0,'','');
  # aligns = 1 top/left, 2 center, 3 bot/right
  # showfields($groups,$link='',$align=0,$valign=0,$colors=array('ffffff','eeeeee'))
#  echo $form->showfields(array('display'),$filename.'?obj=picture&action=display&start=0&sortby=',0,0,array('',''));
#  echo '</tr>';
  $end = $start+$rpp; if ($start == $end) { $end=$ttlrow; }
#start: <start><br>
#  global $strict; $strict=1;
  include "interfaces/comment.php3";
#  httpform_set('name','');
#  httpform_set('email','');
  global $pictureid,$myauth;
#  global $starttime; $timer=$starttime;
if(!$loopdone) {  
for ($count = 0; $count < $start; $count++) { sqlgetrow($result); } 
}
  for ($count = $start; (($count <= $end) && ($row=sqlgetrow($result))); $count++) {
#if (useringroup(array('administrator'))) {
#$diff=get_timer($timer);
#$timer=set_timer();
#echo "<h6>Took [$diff] secs</h6>\n";
#}
#    echo "artist is [".$row['userid']."]<br>\n";
getlayout($row['pictureid'],$row);
$layout=$glob_layout;
$anonlayout=$glob_anon;
echo $glob_header;
    $pictureid=$row['pictureid'];
    $form=new form();
    $form=getpictureformfields($form,$row,'',0);
if (useringroup(array('administrator'))) {
  if ($row['anim']) {
#    echo "<A HREF=\"".geturl($filename.'?obj=picture&action=animate&id='.$row['pictureid'])."\">I'M NOT ANIMATED TO EXPLODE!</A><br>\n";
#    echo "<A HREF=\"".geturl('draw.php3?action=continue&id='.$row['pictureid'])."\">Insert 25› to continue</A><br>\n";
    if ($row['userid']==$myauth['id']) {
#      echo "<A HREF=\"".geturl('draw.php3?action=replace&id='.$row['pictureid'])."\">Insert 25› to finish & replace</A><br>\n";
    }
  }
}
#    echo "Pic is [".$row['pictureid']."]<br>\n";
#    httpform_set('pictureid',$row['pictureid']);
echo $form->proclayout($row['anonymous']?$anonlayout:$layout,'view',array('display'));

// Viewing Own Picture
  if ($row['userid']==$myauth['id']) {
    echo '<A HREF="'.geturl($filename .
'?obj=picture&action=editac&id='.$row['pictureid']).'">Edit</A> | ';   
  }

// Admin
if (useringroup(array('administrator'))) {
    echo '<A HREF="'.geturl($filename .'?obj=picture&action=edit&id='.$row['pictureid']).'">[Edit]</A> | ';
    echo '<A HREF="'.geturl($filename .'?obj=picture&action=remove&id='.$row['pictureid']).'">[Remove]</A>';
if ($row['anim']) {
    echo " | <A HREF=\"".geturl($filename.'?obj=picture&action=animate&id='.$row['pictureid'])."\">[View Animation]</A>\n";
    echo " | <A HREF=\"".geturl('draw.php3?action=continue&id='.$row['pictureid'])."\">[Continue]</A>\n";
    echo " | <A HREF=\"".geturl('draw.php3?action=replace&id='.$row['pictureid'])."\">[Replace]</A><br>\n";
}
}

    $sql="select * from comments where pictureid=".$row['pictureid']." order by timestamp";
#echo $sql;
    $res2=sqlexec($sql);
#    echo "There are [".sqlgetnumrows($res2)."] [$res2]<br>\n";
#    $ses->set_var($sid,'comment_query',$sql);
    $oldrpp=$rpp; $oldstart=$start;
    $rpp=0; $start=0;
    comment_display($res2);
    $rpp=$oldrpp; $start=$oldstart;
#    comment_search();
/*
    if (($count-1)%2) { $color='ffffff'; } else { $color='eeeeee'; }
    echo "<tr bgcolor=\"#$color\">";
    $form=getpictureformmethods($form);
    echo $form->showdata(array('display'),'','<td>','</td>',1);
    echo "</tr>";    
*/
echo $glob_footer;
  }
#  echo '</table>';
  picture_pagnav($start,$ttlrow);
}

// PrePost edit
function picture_edit($id,$params="") {
  picture_view($id);
  $form=getpictureform($id,'upd','Update picture',$params);
  global $ses,$auth_sid;
  $ses->set_var($auth_sid,'picture_edit_id',$id);
#  $form->addcontrol('HIDDEN','id',$id);
  echo $form->generate("edit",array('edit'));
# echo $form->proclayout($picture,'edit');  
}

// Edit after post
function picture_editac($id,$params="") {
  picture_view($id);
  $form=getpictureform($id,'upd','Update picture',$params);
  global $ses,$auth_sid;
  $ses->set_var($auth_sid,'picture_edit_id',$id);
#  $form->addcontrol('HIDDEN','id',$id);
  echo $form->generate("edit",array('editac'));
# echo $form->proclayout($picture,'edit');  
}

function picture_ins() {
  $form=getpictureform(0,'','');
  $check=$form->check_results(array('new'));
  if (is_array($check)) {
    $ok=1;
    while(list($key,$val)=each($check)) {
            if ($val != "") {  echo $val . ' is not a valid value<br>'; $ok=0; }
    }
    if (!$ok) { exit; }
  }
  $id=$form->insert_results('pictures',array('new'));
  log_transac("picture","inserted",$id,"");
  return $id;
}

function picture_remove($id, $params='') {
  global $filename;
  global $ses,$auth_sid;
  $ses->set_var($auth_sid,'picture_remove_id',$id);  
  picture_view($id);
  echo '<br><br><center><b>Are you sure you would like to remove this record?<b><br><br>';
  echo '<table><tr><td>';
  echo '<FORM ACTION="'.geturl($filename.'?obj=picture&action=del'.$params) .  '" METHOD="POST">';
  echo '<INPUT type="submit" value="Yes">';
  echo '</form></td><td>';
  echo '<FORM ACTION="'.geturl($filename.'?obj=picture&action=display'.$params).'" METHOD="POST">';
  echo '<INPUT type="submit" value="No">';
  echo '</form>';
  echo '</td></tr></table></center>';
}

function picture_view($id) {
global $ses,$auth_sid;
global $glob_layout,$glob_anon,$glob_header,$glob_footer;
$res=sqlexec("select * from pictures where pictureid=$id");
$row=sqlgetrow($res);
$form=getpictureform($id,'','','',$row);
#echo $form->generate("view",array('view'));
    include "interfaces/comment.php3";
getlayout($id,$row);
$layout=$glob_layout;
$anonlayout=$glob_anon;
// View Header
echo $glob_header;
if ($row['anonymous']) {
    echo $form->proclayout($anonlayout,'view',array('display'));
} else {
    echo $form->proclayout($layout,'view',array('display'));
}

if (useringroup(array('administrator'))) {
    echo '<A HREF="'.geturl($filename .
'?obj=picture&action=edit&id='.$row['pictureid']).'">Edit</A> | ';
    echo '<A HREF="'.geturl($filename .
'?obj=picture&action=remove&id='.$row['pictureid']).'">Remove</A>';
}
    $sql="select * from comments where pictureid=$id order by timestamp";
    $res2=sqlexec($sql);
    $ses->set_var($auth_sid,'comment_query',$sql);
echo ''; // Before comments
    comment_display($res2);
echo ''; // After comments
echo $form->getmethod('','',0);
echo $glob_footer;

}

function picture_find() {
global $ses;
$ses->set_var(getauthses(),'picture_pickrec',1);
picture_search_form();
}

function picture_search_form() {
	$form=getpictureform(0,'search','Search');
#	$form->addcontrol('checkbox','strict',0,'Strict:');
	echo $form->generate("edit",array('search'));
}

function picture_search() {
global $rpp,$strict,$ses;
#global $stop; echo "stop[$stop]<Br>\n";
if (empty($strict)) { $strict=0; }
	$form=getpictureform(0,'','');
        $form->addcontrol('text','originalid');
	$result=$form->get_search_results('pictures',array('search'),' 
and stop!="0000-00-00" and anonymous=0 order by stop',$strict);
	$oldrpp=$rpp; $rpp=0;  
        $sql=getsqlq();
	$ses->set_var(getauthses(),'picture_query',$sql);
	picture_display($result);
	$rpp=$oldrpp;
}

function picture_listartist() {
global $field,$starttime;
$res=sqlexec("select name, count(*) as cnt from pictures where
stop!='0000-00-00' and anonymous=0 group by name order by name");
//echo "diff[".get_timer($starttime)."]<br>\n";
?><br><center>
<?
for($c=65; $c<91; $c++) {
$char[chr($c)]="<A HREF=\"#".strtolower(chr($c))."\">".chr($c)."</A>";
}
echo join(' | ',$char);
//echo "diff[".get_timer($starttime)."]<br>\n";
?>
</center>
<?
?><br><br><table align="center" border="0" cellpadding="0" cellspacing="0" 
border="0"
width="550" bgcolor="#A82800"><tr>
<td><table width="550" border="0"
cellpadding="2" cellspacing="1">
<tr><th bgcolor="#ffffff"><font
style="font-size:10pt;">Name</font></th><th bgcolor="#ffffff"><font
style="font-size:10pt;">Pictures</font></th></tr> <?
while($row=sqlgetrow($res)) {
//echo "diffbl[".get_timer($starttime)."]<br>\n";
if ($old!=strtolower(substr($row['name'],0,1))) {
  $old=strtolower(substr($row['name'],0,1)); 
  $anch="<A name=\"$old\">"; 
} else { 
  $anch=""; 
}
echo '<tr><td bgcolor="#ffffff">'.$anch.'<A
HREF="'.geturl('interface.php3?obj=picture&action=search&strict=1&name='.$row['name']).'">';
//echo "diffml[".get_timer($starttime)."]<br>\n";
if (!$row['name']) { $row['name']="(none)"; }
echo $row['name'].'</a></td><td
bgcolor="#ffffff">'.$row['cnt'].'</td></tr>';
//echo "diffal[".get_timer($starttime)."]<br>\n";
}
echo '</table></td></tr></table>';
//echo "diff[".get_timer($starttime)."]<br>\n";
}

function picture_listdate() {
$res=sqlexec("select date_format(stop,'%Y-%m-%d') as stop, count(*) as
cnt from pictures where stop!='0000-00-00' group by stop order by stop");
?><br><br><table align="center" width="400" border="0" cellpadding="0" 
cellspacing="0"
bgcolor="#A82800">
<tr>
  <td>
  <table width="400" cellpadding="2" cellspacing="1" border="0">
<tr><th bgcolor="#ffffff"><font
style="font-size:10pt;">Date</font></th><th bgcolor="#ffffff"><font
style="font-size:10pt;">Pics</font></th></tr>
<?
while($row=sqlgetrow($res)) {
echo '<tr><td bgcolor="#ffffff"><A
HREF="'.geturl('interface.php3?obj=picture&action=search&stop='.$row['stop']).'">';
if (empty($row['stop'])) { $row['stop']="(none)"; }
echo $row['stop'].'</a></td><td
bgcolor="#ffffff">'.$row['cnt'].'</td></tr>';
}
echo '</table></td></tr></table>';
}

function picture_lastcomment() {
global $auth_sid,$ses;
global $sort;
$sql="select p.*,max(timestamp) as mxts from pictures p, comments c
where p.pictureid=c.pictureid group by p.pictureid order by mxts $sort";
$ses->set_var($auth_sid,'picture_query',$sql);
$res=sqlexec($sql);
picture_display($res);
}

function picture_your() {
global $NeuroOekakiUserid;
?><br><br><center><b>
<?
$res=sqlexec("select * from pictures where userid=$NeuroOekakiUserid
and stop !='0000-00-00'");
$cnt=sqlgetnumrows($res);
list($name,$email,$hp)=getnfo($NeuroOekakiUserid);
echo $name;
?>'s pictures:</b> [<? echo $cnt; ?>]<br>
<table align="center" width="400" border="0" bgcolor="#A82800" cellpadding="0"cellspacing="0">
<tr>
<td><table width="400" cellpadding="2" cellspacing="1" border="0">
<tr><th bgcolor="#ffffff"><font
style="font-size:10pt;">Title</font></th><th bgcolor="#ffffff"><font
style="font-size:10pt;">Comments</font></th><th
bgcolor="#ffffff"><font style="font-size:10pt;">Last
Comment</font></th></tr> <? while($row=sqlgetrow($res)) {
$res2=sqlexec("select pictureid,count(*),max(timestamp) from comments
where pictureid=".$row['pictureid']." group by pictureid");
list($pid,$cnt,$mxts)=sqlgetrow($res2);
$cnt=(int)$cnt;
echo
'<tr><td bgcolor="#ffffff"><A
HREF="'.geturl('interface.php3?obj=picture&action=view&id='.$row['pictureid']).'">- 
'.$row['title'].'</A></td><td 
bgcolor="#ffffff">'.$cnt.'</td><td bgcolor="#ffffff">'.$mxts.'</td></tr>';
} ?></table></td></tr></table></center>
<?
httpform_set('userid',$NeuroOekakiUserid);
picture_search();
}

function picture_animate($pid) {
$res=sqlexec("select * from pictures where pictureid=$pid");
$row=sqlgetrow($res);
?>
<script language="JavaScript">
<!--

function setspeed(reference){
	document.paintbbs.speed = reference.value;
}

//-->
</script>
<center>
<table width="1" border="0" cellspacing="10" cellpadding="0">
<tr> 
<td>
<img src="data/<? echo $row['pictureid']; ?>.png">
</td>
<td width="1">

<applet code="pbbs.PaintBBS.class" archive="PaintBBS.jar" name="paintbbs" 
width="<? echo $row['width']; ?>" height="<? echo $row['height']; ?>"><param 
name="viewer" value="true"><param name="speed" value="10"><param 
name="pch_file" value="<? echo "data/".$row['pictureid'].".pch"; ?>"></applet> 
</center>

</td>
<td width="1" valign="top"> 
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right"><b>slow</b> </td>
<td><input type="radio" name="speed" value="20" onclick="setspeed(this)"></td>
</tr>
<tr>
<td align="right"><b>med-slow</b> </td>
<td><input type="radio" name="speed" value="10" checked 
onclick="setspeed(this)"></td>
</tr>
<tr>
<td align="right"><b>med-fast</b> </td>
<td><input type="radio" name="speed" value="5" checked 
onclick="setspeed(this)"></td>
</tr>
<tr>
<td align="right"><b>fast</b> </td>
<td><input type="radio" name="speed" value="1" onclick="setspeed(this)"></td>
</tr>
</table>
</td>
</tr>
</table>
</center>
<?
}

function picture_showcont($orgid) {
picture_view($orgid);
httpform_set('originalid',$orgid);
picture_search();
}

?>
