[ 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.php (source)

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


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