commit 49db860c2eff582ffb3c2a98f246fe6efaaaac84
Author: Florent Chuffart <florent.chuffart@ens-lyon.fr>
Date:   Fri Jun 20 17:32:00 2014 +0200

    Extend rbox manager and adding feature to extract genotypes easily.

diff --git a/src/footers.php b/src/footers.php
index ddae85c..6519898 100644
--- a/src/footers.php
+++ b/src/footers.php
@@ -1,5 +1,5 @@
 <?php
-if ($tb != "home" & $tb != "rack" & $tb != "add_box") {
+if ($tb != "home" & $tb != "rack" & $tb != "add_box" & $tb != "publish_it") {
   // TRIGGER
   $opts['triggers']['select']['pre'][] = 'last_trigger.MVC.php';
   $opts['triggers']['update']['pre'][] = 'last_trigger.MVC.php';
diff --git a/src/headers.php b/src/headers.php
index 81f85ba..730f8ed 100644
--- a/src/headers.php
+++ b/src/headers.php
@@ -48,6 +48,36 @@ require_once ("connect_entry.php");
 
 <?php
 
+function dump_genotype($strain) {
+  $geno = "<p>$strain->Name_ Genotype: ".
+  	"<I>".
+ 	"<B>". 
+  	$strain->Mating_Type ." ".
+ 	"</B>" .
+ 	$strain->ADE2 ." ".
+ 	$strain->HIS3 ." ".
+ 	$strain->LEU2 ." ".
+ 	$strain->LYS2 ." ".
+ 	$strain->MET15 ." ".
+ 	$strain->TRP1 ." ".
+ 	$strain->URA3 ." ".
+ 	$strain->HO_ ." ".
+ 	$strain->locus1 ." ".
+ 	$strain->locus2 ." ".
+ 	$strain->locus3 ." ".
+ 	$strain->locus4 ." ".
+ 	$strain->locus5 ." ".
+ 	"</I>".
+ 	" [" .
+ 	$strain->Cytoplasmic_Character ." ".
+ 	"] (" .
+ 	$strain->extrachromosomal_plasmid ." ".
+ 	")" .
+ 	"</p>"; 
+  return($geno);
+} 
+
+
 $to_be_post_list_content = "";
 $to_be_pre_list_content = "";
 // print($_SERVER["SCRIPT_FILENAME"]);
@@ -88,7 +118,7 @@ if (!(in_array($tb, array("home", "")))) {
   // to pass to phpMyEdit
   //
   //check that visitor is allowed to use this table
-  if (($tb == "admin" || $tb == "add_box") && $session->mode != "super") {
+  if (($tb == "admin" || $tb == "add_box" || $tb == "publish_it") && $session->mode != "super") {
     echo "<p>Sorry, your session is not granted access to admin panel. Please logout and try again with appropriate login...</p>";
     exit;
   } else if ($session->target_table != $tb && $session->target_table != "all") {
diff --git a/src/publish_it.php b/src/publish_it.php
new file mode 100644
index 0000000..efbc410
--- /dev/null
+++ b/src/publish_it.php
@@ -0,0 +1,43 @@
+<?php
+session_start();
+require("headers.php");
+
+if (isset($_REQUEST["action"])) {
+  // print_r($_REQUEST);
+  $ids = $_REQUEST["ids"];
+  $all_ids = explode(" ", preg_replace("/([^0-9]+)/"," ",$ids));
+  // print("<pre>");
+  // print_r($all_ids);
+  // print("</pre>");
+  if ($_REQUEST["action"] == "publish_genotypes") {
+    $where_clause = "id IN (" . implode(",", $all_ids) . ")";
+    $qry = "SELECT * FROM strains WHERE $where_clause";
+    $result = mysql_query($qry, $connexion);
+    while($strain = mysql_fetch_object($result)) {
+      // print("<pre>");
+      // print_r($strain);
+      // print("</pre>");
+      echo dump_genotype($strain);
+    }
+  }
+}
+
+
+  $output = "";
+  $output .= "<p>Enter IDs of strains (blank separated) that you want to publish genotypes.</p>";
+  $output .= "<form>";
+
+  $output .= "<textarea name='ids' cols='25' rows='5'>$ids</textarea><br>";
+  $output .= "<input type='hidden' name='action' value='publish_genotypes'>\n";
+  $output .= "<br><input type='submit' value='Extract genotypes.'>\n";
+  $output .= "</form>";
+
+  echo $output;
+
+  // session_start ();
+  require("footers.php");
+
+  
+?>
+
+
diff --git a/src/rack.php b/src/rack.php
index 480b25c..9806f8d 100644
--- a/src/rack.php
+++ b/src/rack.php
@@ -66,7 +66,7 @@ if (isset($_REQUEST["action"])) {
   $output .= "<form>";
 
   $output .= "Which passage do you want to precise storage?<br>";
-  $output .= "Passage: <select name='passage' >";
+  $output .= "Passage: <select name='passage' onChange='submit()'>";
   $qry = "SELECT * FROM cl_passages";
   $result = mysql_query($qry, $connexion);
   while($tmp_passage = mysql_fetch_object($result)) {
@@ -87,8 +87,8 @@ if (isset($_REQUEST["action"])) {
 
 
 
-  $output .= "Container: <select name='container' >";
-  $qry = "SELECT DISTINCT container FROM cl_storage";
+  $output .= "Container: <select name='container' onChange='submit()'>";
+  $qry = "SELECT DISTINCT container FROM cl_storage ORDER BY container";
   $result = mysql_query($qry, $connexion);
   while($storage = mysql_fetch_object($result)) {
     if (!isset($container)) {
@@ -103,42 +103,78 @@ if (isset($_REQUEST["action"])) {
 
 
 
-  $output .= "Rack: <select name='rack' >";
-  $qry = "SELECT DISTINCT rack FROM cl_storage WHERE container='$container'";
+  $output .= "Rack: <select name='rack' onChange='submit()'>";
+  $qry = "SELECT DISTINCT rack FROM cl_storage WHERE container='$container' ORDER BY rack";
   $result = mysql_query($qry, $connexion);
+  $tmp_racks = array();
   while($storage = mysql_fetch_object($result)) {
+    array_push($tmp_racks, $storage->rack);
+  }
+  if (isset($rack)) {
+    if (!in_array($rack, $tmp_racks)) {
+      unset($rack);
+    }
+  }  
+  foreach ($tmp_racks as $storage_rack) {
     if (!isset($rack)) {
-      $rack = $storage->rack;
+      $rack = $storage_rack;
     }
-    $rack == $storage->rack ? $selected = "selected" : $selected = "";
-    $output .= "<option value='$storage->rack' $selected>$storage->rack</option>";
+    $rack == $storage_rack ? $selected = "selected" : $selected = "";
+    $output .= "<option value='$storage_rack' $selected>$storage_rack</option>";
   }
+  // while($storage = mysql_fetch_object($result)) {
+  // if (!isset($rack)) {
+  //   $rack = $storage->rack;
+  // }
+  // $rack == $storage->rack ? $selected = "selected" : $selected = "";
+  // $output .= "<option value='$storage->rack' $selected>$storage->rack</option>";
+  // }
   $output .= "</select><br>";
   
 
 
 
-  $output .= "Box: <select name='box' >";
-  $qry = "SELECT DISTINCT box FROM cl_storage WHERE container='$container' AND rack='$rack'";
+  $output .= "Box: <select name='box' onChange='submit()'>";
+  $qry = "SELECT DISTINCT box FROM cl_storage WHERE container='$container' AND rack='$rack' ORDER BY box";
   $result = mysql_query($qry, $connexion);
+  $tmp_boxes = array();
   while($storage = mysql_fetch_object($result)) {
+    array_push($tmp_boxes, $storage->box);
+  }
+  if (isset($box)) {
+    if (!in_array($box, $tmp_boxes)) {
+      unset($box);
+    }
+  }  
+  foreach ($tmp_boxes as $storage_box) {
     if (!isset($box)) {
-      $box = $storage->box;
+      $box = $storage_box;
     }
-    $rack == $storage->box ? $selected = "selected" : $selected = "";
-    $output .= "<option value='$storage->box' $selected>$storage->box</option>";
+    $box == $storage_box ? $selected = "selected" : $selected = "";
+    $output .= "<option value='$storage_box' $selected>$storage_box</option>";
   }
   $output .= "</select><br>";
 
+
+
+
+  $qry = "SELECT name FROM cl_passages WHERE ID='$passage'";
+  $result = mysql_query($qry, $connexion);
+  $cell_line = mysql_fetch_object($result)->name;
+  
+
+
   $qry = "SELECT * FROM cl_storage, cl_passages WHERE container='$container' AND rack='$rack' AND  box='$box'  AND cl_storage.cl_passages=cl_passages.ID";
   $result = mysql_query($qry, $connexion);
   $content = array();
   $content_index = array();
+  $content_cell_line = array();
   while($joint_passage = mysql_fetch_object($result)) {
     $key = $joint_passage->container . $joint_passage->rack . $joint_passage->box . $joint_passage->field_y . $joint_passage->field_x;;
     $value = $joint_passage->name . "<br>" . $joint_passage->passage . "<br>" . $joint_passage->date_of_freezing;
     $content[$key] = $value;
     $content_index[$key] = $joint_passage->cl_passages ;
+    $content_cell_line[$key] = $joint_passage->name ;
   }
 
 
@@ -167,7 +203,8 @@ if (isset($_REQUEST["action"])) {
     foreach($fields as $field_x) {
       $key = $container . $rack . $box . $field_y . $field_x;
       isset($content[$key]) ? $color="LightGray" : $color="LightGreen";
-      @$content_index[$key] == $passage ? $color="PowderBlue": $color=$color;
+      @$content_cell_line[$key] == $cell_line ? $color="PowderBlue": $color=$color;
+      @$content_index[$key] == $passage ? $color="RoyalBlue": $color=$color;
       $output .= "<td style='background-color: $color; width:80; border: 1px solid black;''>";
       if ($session->mode != "view") {
         $output .= "<input type='checkbox' name='fieldy_fieldx_" . $field_y . "_" . $field_x . " value='on'>$field_x</input><br>";
@@ -191,6 +228,51 @@ if (isset($_REQUEST["action"])) {
 
   echo $output;
 
+
+
+
+
+
+
+
+
+
+
+
+
+  $output2 = "<table class='pme-main'><tr class='pme-header'><th class='pme-header'>Cell Line</th><th class='pme-header'>#Vials</th><th class='pme-header'>Note</th></tr>";
+
+  $qry = "SELECT name, COUNT(cl_passages) as cnt FROM cl_storage, cl_passages WHERE cl_storage.cl_passages=cl_passages.ID GROUP BY name";
+  $result = mysql_query($qry, $connexion);
+  $content = array();
+  $content_index = array();
+  while($joint_passage = mysql_fetch_object($result)) {
+    if ($joint_passage->cnt <= 5) {
+      $note = "<blink><b>Please freeze additional passages to maintain frozen stocks!</b></blink>";
+    } else {
+      $note = "Sufficient stock.";
+    }
+    $output2 .= "<tr class='pme-row-0'><td class='pme-cell-0'>$joint_passage->name</td><td class='pme-cell-0'>$joint_passage->cnt</td><td class='pme-cell-0'>$note</td></tr>";    
+    // print($joint_passage->name . " "  . $joint_passage->cnt . "<pre>");
+    // print_r($joint_passage);
+    // print("</pre>");
+    // $key = $joint_passage->container . $joint_passage->rack . $joint_passage->box . $joint_passage->field_y . $joint_passage->field_x;;
+    // $value = $joint_passage->name . "<br>" . $joint_passage->passage . "<br>" . $joint_passage->date_of_freezing;
+    // $content[$key] = $value;
+    // $content_index[$key] = $joint_passage->cl_passages ;
+  }
+  $output2 .= "</table>";
+
+    print($output2);
+
+
+
+
+
+
+
+
+
   // session_start ();
   require("footers.php");
 
diff --git a/src/strains.TSP.php b/src/strains.TSP.php
index 4df6c2f..61a738a 100644
--- a/src/strains.TSP.php
+++ b/src/strains.TSP.php
@@ -12,31 +12,7 @@ while(!$found && $strain = mysql_fetch_object($all)){
 
 if ($strain){
  // print full genotype
- echo " Genotype: ".
- 	"<I>".
-	"<B>". 
- 	$strain->Mating_Type ." ".
-	"</B>" .
-	$strain->ADE2 ." ".
-	$strain->HIS3 ." ".
-	$strain->LEU2 ." ".
-	$strain->LYS2 ." ".
-	$strain->MET15 ." ".
-	$strain->TRP1 ." ".
-	$strain->URA3 ." ".
-	$strain->HO_ ." ".
-	$strain->locus1 ." ".
-	$strain->locus2 ." ".
-	$strain->locus3 ." ".
-	$strain->locus4 ." ".
-	$strain->locus5 ." ".
-	"</I>".
-	" [" .
-	$strain->Cytoplasmic_Character ." ".
-	"] (" .
-	$strain->extrachromosomal_plasmid ." ".
-	")" .
-	"<BR>". "<BR>";
+ echo dump_genotype($strain);
   /*	
  // find author in table labmembers
  $allauth = $this->myQuery("SELECT * FROM labmembers");
diff --git a/src/strains.php b/src/strains.php
index 55c635c..f77fe2d 100644
--- a/src/strains.php
+++ b/src/strains.php
@@ -2,6 +2,13 @@
 session_start ();
 require("headers.php");
 
+
+
+if ($session->mode == "super") {
+  print("<p><a href='publish_it.php'>Publish genotypes.</a></p>");
+}
+
+
 // if (array_key_exists("action", $_REQUEST)) {
 //   if ($_REQUEST["action"] == "SEARCH_IN_GENOTYPE") {
 //     $keys = split(" ", $_REQUEST["geno"]); 
