[ PHPXref.com ] [ Generated: Sun Jul 20 20:03:30 2008 ] [ Plasmidb 0.4.2 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/plasmidb/ -> pcr_test.php (source)

   1  <?php
   2  
   3      require_once  ('./lib/Plasmidb.inc');
   4      require_once ('header.inc');
   5       
   6      /*
   7       * Instantiate a new DB object: $db
   8       */
   9       
  10      $db = new Plasmidb();
  11       
  12      $tableName = 'pcr';
  13      $tableViewName = 'PCRs';
  14      $tableFields = array('pcr_name',
  15          'pcr_fprimer_id' ,
  16          'pcr_rprimer_id' ,
  17          'db_seq_id' ,
  18          'constr_plasmid_id',
  19          'pcr_desired_seq',
  20          'pcr_comments',
  21          'pcr_date',
  22          'insrt_id',
  23          'pcr_id');
  24      $tableValues = array($pcr_name ,
  25          $pcr_fprimer_id ,
  26          $pcr_rprimer_id,
  27          $db_seq_id ,
  28          $constr_plasmid_id ,
  29          $pcr_desired_seq,
  30          $pcr_comments ,
  31          $pcr_date,
  32          $insrt_id,
  33          $pcr_id);
  34       
  35      if (!$id && !$add && !$submitButton) {
  36          $anchortarget = sprintf("%s?add=1&id=0", $_SERVER["PHP_SELF"]);
  37          $anchortext = sprintf("Add new %s data", strtolower($tableViewName));
  38          
  39          $anchor = new Anchor( $anchortext, $anchortarget, $style[style], true, true);
  40          if ($order) {
  41              $sql = sprintf("SELECT * FROM pcr ORDER BY '%s'", $order);
  42          } else {
  43              $sql = "SELECT * FROM pcr";//, clone, constr_plasmid ";
  44          }
  45          //print($sql);
  46          $result = $db->query($sql);
  47          if (DB::isError($result)) {
  48              die ($result->getMessage());
  49          }
  50          $table = new HTML_Table;
  51          $table->setAutoGrow(true);
  52          $table->setAutoFill("n/a");
  53          $table->setHeaderContents(0, 0, ListView::sprintAnchorOrderByField ("pcr_name" , "PCR Name"));
  54          $table->setHeaderContents(0, 1, ListView::sprintAnchorOrderByField ("pcr_fprimer_id" , "F Primer"));
  55          $table->setHeaderContents(0, 2, ListView::sprintAnchorOrderByField ("pcr_rprimer_id" , "R Primer"));
  56          $table->setHeaderContents(0, 3, ListView::sprintAnchorOrderByField ("db_seq_id" , "Database sequence as template"));
  57          $table->setHeaderContents(0, 4, ListView::sprintAnchorOrderByField ("constr_plasmid_id" , "Constructed Plasmid:"));
  58          $table->setHeaderContents(0, 5, ListView::sprintAnchorOrderByField ("pcr_desired_seq" , "Dna Sequence"));
  59          $table->setHeaderContents(0, 6, ListView::sprintAnchorOrderByField ("pcr_comments" , "Comments"));
  60          $table->setHeaderContents(0, 7, ListView::sprintAnchorOrderByField ("pcr_date" , "DATE"));
  61          $table->setHeaderContents(0, 8, ListView::sprintAnchorOrderByField ("insrt_id" , "Insert"));
  62          $table->setHeaderContents(0, 9, ListView::sprintAnchorOrderByField ("pcr_id" , "PCR ID#"));
  63          $i = 0;
  64          while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
  65              /***
  66               * Collecting references to other tables
  67               */
  68              $pcr_fprimer_name = name_from_table_id ('primer' , $row[pcr_fprimer_id]);
  69              $pcr_rprimer_name = name_from_table_id ('primer' , $row[pcr_rprimer_id]);
  70              $db_seq_id = name_from_table_id ('db_seq' , $row[db_seq_id]);
  71               
  72              $constr_plasmid_name = name_from_table_id ('constr_plasmid' , $row[constr_plasmid_id]);
  73              $insrt_name = name_from_table_id ('insrt' , $row[insrt_id]);
  74              $table->addRow;
  75              $rowstr = sprintf('<a href ="%s?id=%d">%s</a>', $_SERVER["PHP_SELF"], $row[pcr_id], $row[pcr_name]);
  76              $table->setCellContents($i+1, 0, $rowstr);
  77              $table->setCellContents($i+1, 1, $pcr_fprimer_name);
  78              $table->setCellContents($i+1, 2, $pcr_rprimer_name);
  79              $table->setCellContents($i+1, 3, $db_seq_name);
  80              $table->setCellContents($i+1, 4, $constr_plasmid_name);
  81              $table->setCellContents($i+1, 5, $row[pcr_desired_seq]);
  82              $table->setCellContents($i+1, 6, $row[pcr_comments]);
  83              $table->setCellContents($i+1, 7, $row[pcr_date]);
  84              $table->setCellContents($i+1, 8, $insrt_name);
  85              $table->setCellContents($i+1, 9, $row[pcr_id]);
  86              $i++;
  87          }
  88          $table->setAllAttributes($style);
  89          echo $table->toHTML();
  90      } else {
  91          // Here if adding or editing
  92          if ($id) {
  93              $sql = "SELECT * FROM pcr WHERE pcr_id=$id";
  94              $result = $db->query($sql);
  95              if (DB::isError($result)) {
  96                  die ($result->getMessage());
  97              }
  98              $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
  99              $pcr_name = $row[pcr_name];
 100              $pcr_fprimer_id = $row[pcr_fprimer_id];
 101              $pcr_rprimer_id = $row[pcr_rprimer_id];
 102              $db_seq_id = $row[db_seq_id];
 103              $constr_plasmid_id = $row[constr_plasmid_id];
 104              $pcr_desired_seq = $row[pcr_desired_seq];
 105              $pcr_comments = $row[pcr_comments];
 106              $pcr_date = $row[pcr_date];
 107              $insrt_id = $row[insrt_id];
 108              $pcr_id = $row[pcr_id];
 109          } else {
 110              $pcr_name = "Insert pcr name here";
 111              $pcr_date = date("Y-m-d");
 112          }
 113          /***
 114           * Getting the list of options for listboxes
 115           */
 116          $pcr_primer_idA = Plasmidb_Select::selectOptions('primer', 'primer_name');
 117          $db_seq_idA = Plasmidb_Select::selectOptions('db_seq', 'db_seq_name');
 118          $constr_plasmid_idA = Plasmidb_Select::selectOptions('constr_plasmid', 'constr_plasmid_name');
 119          $insrt_idA = Plasmidb_Select::selectOptions('insrt', 'insrt_name');
 120           
 121          if ($add) {
 122              $target = sprintf('%s?submit=1&add=1', $_SERVER["PHP_SELF"]);
 123          } else {
 124              $target = sprintf('%s?submit=1', $_SERVER["PHP_SELF"]);
 125          }
 126          /*
 127           * Set default values
 128           */
 129          $defaultValues['pcr_name'] = $pcr_name;
 130          $defaultValues['pcr_fprimer_id'] = $pcr_fprimer_id;
 131          $defaultValues['pcr_rprimer_id'] = $pcr_rprimer_id;
 132          $defaultValues['db_seq_id'] = $db_seq_id;
 133          $defaultValues['constr_plasmid_id'] = $constr_plasmid_id;
 134          $defaultValues['pcr_desired_seq'] = $pcr_desired_seq;
 135          $defaultValues['pcr_date'] = $pcr_date;
 136          $defaultValues['pcr_comments'] = $pcr_comments;
 137          $defaultValues['insrt_id'] = $insrt_id;
 138          $defaultValues['pcr_id'] = $pcr_id;
 139          /*
 140           * Set up the form
 141           */
 142          $form = new HTML_QuickForm('PlasmidForm', 'POST' , $_SERVER["PHP_SELF"], '_self');
 143          $form->setDefaults($defaultValues);
 144          $form->addElement('header', '', 'Input Dna Sequence Data');
 145          $form->addElement('text', 'pcr_name', 'PCR Name', $pcr_name);
 146          $form->addElement('select', 'pcr_fprimer_id', 'Forward Primer', $pcr_primer_idA);
 147          $form->addElement('select', 'pcr_rprimer_id', 'Reverse Primer', $pcr_primer_idA);
 148          $form->addElement('select', 'db_seq_id', 'DB Sequence Name', $db_seq_idA);
 149          $form->addElement('select', 'constr_plasmid_id', 'Constructed Plasmid', $constr_plasmid_idA);
 150          $form->addElement('textarea', 'pcr_desired_seq', 'Desired Sequence', $pcr_desired_seqA);
 151          $form->addElement('textarea', 'pcr_comments', 'Comments', $pcr_commentsA);
 152          $form->addElement('text', 'pcr_date', 'Date', $pcr_date);
 153          $form->addElement('select', 'insrt_id', 'Insert', $insrt_idA);
 154          $form->addElement('hidden', 'pcr_id', $pcr_id);
 155          if ($add) {
 156              $form->addElement('hidden', 'add', $add);
 157          }
 158          $form->addElement('submit', 'submitButton', 'Enter information');
 159          /*
 160           * Get the results
 161           */
 162          $pcr_name = & $form->getElement('pcr_name');
 163          $pcr_fprimer_id = & $form->getElement('pcr_fprimer_id');
 164          $pcr_rprimer_id = & $form->getElement('pcr_rprimer_id');
 165          $db_seq_id = & $form->getElement('db_seq_id');
 166          $constr_plasmid_id = & $form->getElement('constr_plasmid_id');
 167          $pcr_desired_seq = & $form->getElement('pcr_desired_seq');
 168          $pcr_date = & $form->getElement('pcr_date');
 169          $pcr_comments = & $form->getElement('pcr_comments');
 170          $insrt_id = & $form->getElement('insrt_id');
 171           
 172          if ($form->validate() ) {
 173              $result = $db->saveItem($tableName, $tableFields, $tableValues, $pcr_id);
 174              $form->removeElement('submitButton');
 175              $form->freeze();
 176          }
 177          $form->display();
 178      }
 179      // close conection
 180      $db->dbDisconnect();
 181  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]