Location: PHPKode > projects > Enzyme: PHP profile/object community mgr > Enzyme-0.6.3/main/edit/insert.php3
<?
page_open(array("sess" => "Poe_Session", "auth" => "Poe_Challenge_Auth", "perm" => "Cat_Perm", "user" => "Poe_User"));
$perm->check( "student" );
?>
<? 
$PAGE_TITLE = "Unknown entry";
$no_menubar = 1;
$no_headerlink = 1;
$no_suggest = 1;
include "cat_header_code.inc"; 
$cat_body = "#ffffff";
include "cat_header_layout.inc"; 
?>

<table border="0" cellspacing="0" cellpadding="3">
<tr>
<td>
<br>
<?


// setup the global variable for OOH Forms
${ $table .'_'. $field } = $val;

#printf( "Furthermore, you would like me to add it into %s<br>", $selname );

# print( "We've found a list of close matches for you.  Did you mean one of these?<br>" );

$db_suggest = new DB_Poe;
$soundex = "CONCAT( LEFT(SOUNDEX( \"$val\" ),2), \"%\" )";

$query = "SELECT $field from $table where (";
$arr = array();

$arr[] = "SOUNDEX($field) like $soundex";

if( ucwords($table) == 'School' )
     $arr[] = "SOUNDEX(abbr) like $soundex";

$arr[] = "INSTR( LOWER(name), LOWER(\"$val\") )";

$arr[] = 
" CONCAT(
  LEFT( SUBSTRING_INDEX(SUBSTRING_INDEX(name, ' ',  1),' ',-1),1), 
  CONCAT(
    LEFT( SUBSTRING_INDEX(SUBSTRING_INDEX(name, ' ',  2),' ',-1),1),  
    CONCAT( 
      IF( SUBSTRING_INDEX( name, ' ', 3) = name, '', LEFT(SUBSTRING_INDEX(SUBSTRING_INDEX(name, ' ',  3),' ',-1),1)), 
        CONCAT( 
        IF( SUBSTRING_INDEX( name, ' ', 4) = name, '', LEFT(SUBSTRING_INDEX(SUBSTRING_INDEX(name, ' ',  4),' ',-1),1))), 
          IF( SUBSTRING_INDEX( name, ' ', 5) = name, '', LEFT(SUBSTRING_INDEX(SUBSTRING_INDEX(name, ' ',  5),' ',-1),1) ) 
  ))) like \"$val\"";

$query = sprintf( "SELECT %s from %s where (%s);", $field, $table, implode( ' or ', $arr ) );


$db_suggest->query( $query );

?>

<SCRIPT LANGUAGE="JavaScript" src="../session/set_doSelect.js"></SCRIPT>

<? 
// register the selname so that we'll know about it on the final insert,
// and we can update the calling page accordingly.
// -- no longer necessary because we are going to use the url for the form action.
//$sess->unregister( "selname_sess" );
//$selname_sess = $selname;
//$sess->register( "selname_sess" ); 

$db_exist = new DB_Poe;
$query = sprintf( "SELECT name FROM %s where ( name = \"%s\" );", $table, $GLOBALS["$table"."_name"] );
$db_exist->query( $query );
if( $db_exist->nf() != 0 ) 
{
  printf( "<h3>The %s \"%s\" appears to be in our database already, with "
	 . "the following information associated with it.</h3>\n", $table, $GLOBALS["$table"."_name"]  );
  loadValues( $table, array( "name" ), array( $GLOBALS["$table"."_name"] ) );
  $item_exists = true;
  //set capitalization in the parent window.
  $selname = "student_$table" . "_$table" . "id";
  print( "\n<SCRIPT>\n" );
  printf( "set_parent_qbox( \"%s\", \"%s\" );", $GLOBALS["$table"."_name"], $qname );
  print( "\n</SCRIPT>\n" );

}
// If all the fancy database work up above produces results, display them in
// a nice select box.
else if( $db_suggest->next_record() )
{
  printf( "Catalyst does not yet know about the %s %sd \"%s.\"<br><br>", 
	  $table, $field, $val );
  print( "We've found a list of close matches for you.  Did you mean one of these?<br>" );
  print( "<FORM target='javascript:void(0)' ><SELECT name=\"suggest\">\n" );

  do
    {
      printf("<OPTION>%s</OPTION>\n", $db_suggest->f($field) );
    }
  while( $db_suggest->next_record() );
  
  print( "</SELECT>\n" );
  print( "<INPUT TYPE=button VALUE=\"Select\" onClick=\"set_parent_select('$selname', this.form.suggest.options[this.form.suggest.selectedIndex].text, '$qname' ); window.close();\">\n" );
  print( "</FORM>\n" );
}
else 
{
  print( "<FORM target='javascript:void(0)' >\n" );
  printf( "Catalyst does not yet know about the %s %sd \"%s.\"<br><br>", 
	  $table, $field, $val );
  print( "Here is the list of every $table we have in our database:<br>\n" );
  doSelectNoText( $table, "name" );
  print( "<INPUT TYPE=button VALUE=\"Select\" onClick=\"". 
"set_parent_select('$selname', this.form.elements[0].options[this.form.elements[0].selectedIndex].text, '$qname' );" .
"window.close();" .
"\">\n" );
  print( "</FORM>\n");
  
} // close the else
?>

<? 
if( !$item_exists ) 
  {
?>
If your <? echo $table ?> is not in the list above, let us add it to our database for you.  <br>
The information you provide below will be visible by all students in your school, so describe the <? echo $table ?> itself rather than your involvement in it.<br>
<? if ($table == "activity"):  ?>
Be specific about the name of your activity (e.g. "Yale Herald" rather than "Student newspaper"; "Sextones" rather than "Rock Band").<br>
<?
endif;
?>
<? if ($table == "skill"):  ?>
Be specific about the name of your skill (e.g. "C++" rather than "Computer Programming") but be general enough that the characterization would 
apply to others (e.g. "PageMaker" rather than "PageMaker v. 2.2, 3.0 and 4.6").<br>
<?
endif;
  }
?>


<? $studentid = getStudentid();
 //print( "<B>$studentid</B><BR>" );
 //This is for later, to be added as part of the new school data ?>

<?
include "setup_item.inc";
$new_item = setup_item( $table );
if( $item_exists ) {
  $new_item->load_defaults();
  $new_item->freeze();
}
else {
  $new_item->load_defaults( array( $table . "_name" ) );
}
$new_item->start( "addItem", "post", "insert_item.php3?table=$table&selname=$selname&qname=$qname" );
include "new_$table.inc";
?>

</td>
</tr>
</table>
<? require( "cat_footer.inc"); ?>
<? page_close(); ?>
Return current item: Enzyme: PHP profile/object community mgr