Advertisement
Guest User

do

a guest
Feb 19th, 2014
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.14 KB | None | 0 0
  1. <?php
  2.  
  3. class Protocol extends DataObject {
  4.    static $db = array(
  5.         'Name' => 'Text',
  6.         'Title' => 'Varchar(255)',
  7.         'Description' => 'HTMLText',
  8.         'URLSegment' => 'Varchar(255)',
  9.         'MetaTitle' => 'Varchar(255)',
  10.         'protocolId' => 'Int',  
  11.         'date_debut' => 'Date',    
  12.         'date_fin' => 'Date',  
  13.         'nb_inc_theorique' => 'Int',
  14.         'EIaction' => 'Varchar(100)',
  15.         'EIactionParameter1' => 'Varchar(100)',
  16.         'EIactionParameter2' => 'Varchar(100)',    
  17.         'EIactionParameter3' => 'Varchar(100)',    
  18.         'closed' => 'Boolean',
  19.         'update' => 'Int',
  20.     );
  21.  
  22.     static $has_one = array(
  23.         'Image' => 'Image',
  24.         'InvPrincipal' => 'Member'
  25.     );
  26.    
  27.     //Relate to the category pages
  28.     static $belongs_many_many = array(
  29.         'Categories' => 'CategoryPage'
  30.     );
  31.    
  32.     //Documentation
  33.     static $has_many = array(
  34.         'Documents' => 'DocumentProto',
  35.     );
  36.  
  37.     static $many_many = array('Member' => 'Member');
  38.  
  39.    function getCMSFields()   {
  40.       $fields = parent::getCMSFields();
  41.  
  42.         //Main Tab
  43.         $fields->addFieldToTab("Root.Main", new TextField('Title', _t('Protocol.TITLE','Nom: '))); 
  44.         $fields->addFieldToTab("Root.Main", new TextField('URLSegment', 'URL Segment'));   
  45.         $fields->addFieldToTab("Root.Main", new TextField('MetaTitle', 'Meta Title')); 
  46.         $beginDate = new DateField('date_debut', 'D&eacute;but');
  47.         $beginDate->setConfig('showcalendar', true);
  48.         $beginDate->setConfig('dateformat', 'YYYY-MM-dd');
  49.         $fields->addFieldToTab("Root.Main", $beginDate);   
  50.         $endDate = new DateField('date_fin', 'Fin');
  51.         $endDate->setConfig('showcalendar', true);
  52.         $endDate->setConfig('dateformat', 'YYYY-MM-dd');
  53.         $fields->addFieldToTab("Root.Main", $endDate); 
  54.         $fields->addFieldToTab("Root.Main", new TextField('protocolId', 'Ident V1'));  
  55.         $fields->addFieldToTab("Root.Main", new TextField('nb_inc_theorique', 'Nb inclusions pr&eacute;vues'));
  56.         $fields->addFieldToTab("Root.Main", new HiddenField('EIaction', 'Ev&eacute;nement Ind&eacute;sirable : action'));  
  57.         $fields->addFieldToTab("Root.Main", new HiddenField('EIaction Parameter1', 'Ev&eacute;nement Ind&eacute;sirable : param&egrave;tre 1'));   
  58.         $fields->addFieldToTab("Root.Main", new HiddenField('EIaction Parameter2', 'Ev&eacute;nement Ind&eacute;sirable : param&egrave;tre 2'));   
  59.         $fields->addFieldToTab("Root.Main", new HiddenField('EIaction Parameter3', 'Ev&eacute;nement Ind&eacute;sirable : param&egrave;tre 3'));   
  60.         $fields->addFieldToTab("Root.Main", new HTMLEditorField('Description'));
  61.  
  62.  
  63.         $fields->removeFieldFromTab('Root','Member');
  64.  
  65.         //Users (with Multiselect)
  66.         $source = DataObject::get('User');
  67.         $map = $source ? $map = $source->toDropdownMap('ID','Name') : array();
  68.         $fields->insertAfter(new MultiSelectField("Member","Member",$map),'Name');
  69.  
  70.         //Categories
  71.         $Categories = DataObject::get('CategoryPage');
  72.         $fields->addFieldToTab("Root.Categories", new CheckboxsetField('Categories', 'Categories', $Categories));
  73.  
  74.         //Images
  75.         $fields->addFieldToTab("Root.Images", new ImageField('Image', 'Image', Null, Null, Null, 'Uploads/category_banners'));
  76.  
  77.         //Documents
  78.         $FilesField = new MultipleFileUploadField('Documents',_t('JobApplication.RESUME','T&eacute;l&eacute;charger des fichiers.'));
  79.         $FilesField->removeFolderSelection();
  80.         $FilesField->uploadFolder = 'Uploads/DocProto';
  81.         $fields->addFieldToTab("Root.Documents", $FilesField);
  82.                
  83.                
  84.  
  85.         return $fields;
  86.    }
  87.        
  88.  
  89.     // Complements d'infos
  90.     function ComplementProtocol() {
  91.        
  92.         $protoID = $this->ID;
  93.        
  94.         $sqlQuery = new SQLQuery();
  95.         $sqlQuery->select = array(
  96.           'FirstName AS Name',
  97.           'Surname AS Surname'
  98.         );
  99.         $sqlQuery->from = array(
  100.             "Protocol
  101.             JOIN Member ON Protocol.InvPrincipalID = Member.ID
  102.             "
  103.         );
  104.         $sqlQuery->where = array(
  105.             "Protocol.ID = $protoID
  106.             "
  107.         );
  108.  
  109.         $result = $sqlQuery->execute();
  110.         $docList = "";
  111.         foreach($result as $row) {
  112.             $docList .= $row['Name']." ".$row['Surname'];
  113.         }
  114.        
  115.         return $docList;
  116.        
  117.     }
  118.  
  119.     // Autorized protocols
  120.     function MyProtocols() {
  121.        
  122.         $me = member::currentUser();
  123.         $myID = $me->ID;
  124.         $protoID = $this->ID;
  125.                
  126.                
  127.        
  128.         $sqlQuery = new SQLQuery();
  129.         $sqlQuery->select = array(
  130.           'COUNT(ID) AS ID'
  131.         );
  132.         $sqlQuery->from = array(
  133.             "Protocol_Member"
  134.         );
  135.         $sqlQuery->where = array(
  136.             "MemberID = $myID",
  137.             "ProtocolID = $protoID"
  138.         );
  139.  
  140.         $nbProtos = $sqlQuery->execute()->value();
  141.        
  142.         return $nbProtos;      
  143.        
  144.     }
  145.  
  146.     // Protocols documentation
  147.     function DocProtocols() {
  148.        
  149.         $protoID = $this->ID;
  150.        
  151.         $sqlQuery = new SQLQuery();
  152.         $sqlQuery->select = array(
  153.           'Name AS Name',
  154.           'Filename AS Filename'
  155.         );
  156.         $sqlQuery->from = array(
  157.             "File
  158.             JOIN DocumentProto ON File.ID = DocumentProto.ID
  159.             "
  160.         );
  161.         $sqlQuery->where = array(
  162.             "ProtocolID = $protoID
  163.             "
  164.         );
  165.  
  166.         $result = $sqlQuery->execute();
  167.         $docList = "";
  168.         foreach($result as $row) {
  169.             $docList .= "<div><a href='".$row['Filename']."' target=\"_blank\">".$row['Name']."</a></div>";
  170.         }
  171.        
  172.         return $docList;
  173.     }
  174.  
  175.     // Protocols Sessions
  176.     function SessionsProtocols() {
  177.        
  178.         $protoID = $this->ID;
  179.        
  180.         global $databaseConfig;
  181.         $connexion = new PDO('mysql:host='.$databaseConfig['server'].';dbname='.$databaseConfig['database'].'', $databaseConfig['username'], $databaseConfig['password']);
  182.  
  183.  
  184.           $list= "";
  185.           $listform= "";
  186.         $sql= "
  187.             SELECT session, startIntervention, FirstName, Surname, Protocol.Name
  188.             FROM session, randomisation, Member, Protocol
  189.             WHERE Protocol.ID LIKE :a
  190.                 AND session.session = randomisation.session_ref
  191.                 AND randomisation.protocolId = Protocol.ID
  192.                 AND session.tag = Member.ID
  193.             ";
  194.         $sth = $connexion->prepare("$sql");
  195.         $sth->bindParam(':a', $protoID);
  196.         $sth->execute();
  197.         $list .= "<table>";
  198.         $m = 1;
  199.         while ($row = $sth->fetch(PDO::FETCH_NUM)) {
  200.                    
  201.                     /*
  202.                      * Récupération du nombre de formulaire enregistrées pour cette session
  203.                      */
  204.                     $sql = "SELECT count(*) as nbForm FROM SubmittedForm WHERE session_ref = :session";
  205.                     $sth1 = $connexion->prepare("$sql");
  206.                     $sth1->bindParam(':session', $row[0]);;
  207.                     $sth1->execute();
  208.                     $result = $sth1->fetch(PDO::FETCH_ASSOC);
  209.                     $nbForm = $result['nbForm'];
  210.                     if ($nbForm == 0){
  211.                         $ExistForm = "<p style=\"font-weight: bold;color: red;\"> Pas de formulaire</p>";
  212.                     }
  213.                     else{
  214.                         if($nbForm == 1){
  215.                             $ExistForm = "<p style=\"font-weight: bold;color: blue;\"> 1 formulaire</p";
  216.                         }
  217.                         else{
  218.                             $ExistForm ="<p style=\"font-weight: bold;color: green;\">".$nbForm." formulaires</p>";
  219.                         }
  220.                     }
  221.                        
  222.                
  223.             $listform .= "
  224.                 <FORM name=\"detailsession_".$m."\" action=\"".Director::baseURL()."detail-d-une-session\" method=\"post\"  target=\"_blank\">
  225.                     <INPUT type=\"hidden\" name=\"numSession\" value=\"$row[0]\"></form>
  226.             ";
  227.           $data = "<tr><td><a href=\"javascript: OnClick=document.detailsession_".$m.".submit();\">".$row[0]."</a></td><td>$row[1]</td><td>$row[2] $row[3]</td><td>$row[4]</td><td>$ExistForm</tr></tr>";
  228.           $list.= $data;
  229.           $m++;
  230.         }
  231.         $list .= "</table>";
  232.         $list .= $listform;
  233.  
  234.         return $list;
  235.        
  236.     }
  237.  
  238.     // Protocols investigateurs
  239.     function InvestigateursProtocols() {
  240.        
  241.         $protoID = $this->ID;
  242.        
  243.         $sqlQuery = new SQLQuery();
  244.         $sqlQuery->select = array(
  245.           'FirstName AS Name',
  246.           'Surname AS Surname',
  247.           'Email AS Email2'
  248.           );
  249.         $sqlQuery->from = array(
  250.             "Member
  251.             JOIN Protocol_Member ON Member.ID = Protocol_Member.MemberID
  252.             "
  253.         );
  254.         $sqlQuery->where = array(
  255.             "Protocol_Member.ProtocolID = $protoID
  256.             "
  257.         );
  258.  
  259.         $sqlQuery->orderby = "FirstName";
  260.        
  261.         $result = $sqlQuery->execute();
  262.         $docList = "";
  263.         foreach($result as $row) {
  264.             $docList .= "<div>".$row['Name']." ".$row['Surname'].", <a href=\"mailto:".$row['Email2']."\">".$row['Email2']."</a></div>";
  265.         }
  266.        
  267.         return $docList;
  268.     }
  269.  
  270.     // paramExportSimple
  271.     function paramExportSimple() {
  272.            
  273.              
  274.         $protoID = $this->ID;
  275.        
  276.         $wh = "AND Protocol.ID = $protoID ";
  277.         $list= "
  278.             <div id=\"id_filtre\">
  279.             <input type=\"hidden\" name=\"filtre\" id=\"filtre\" value=\"\" />
  280.             </div>
  281.             <div id=\"id_wh\">
  282.             <input type=\"hidden\" name=\"wh\" id=\"wh\" value=\"$wh\" />
  283.             </div>
  284.         ";
  285.         return $list;
  286.        
  287.     }
  288.        
  289.         function getProtocolID() {
  290.         global $databaseConfig;
  291.         $con = new PDO('mysql:host='.$databaseConfig['server'].';dbname='.$databaseConfig['database'].'', $databaseConfig['username'], $databaseConfig['password']);
  292.        
  293.         $protoID = $this->ID;
  294.                 $SQL = "SELECT * FROM `Protocol` WHERE `ID` = " . $protoID . ";";
  295.                 $sth1 = $con->prepare("$SQL");
  296.                 $result = $sth1->execute();
  297.                 $row = $sth1->fetch(PDO::FETCH_ASSOC);
  298.                
  299.         $name = htmlentities($row['Name']);
  300.                 //var_dump($name);die();
  301.        
  302.         $list= "
  303.             <div id=\"id_Proto\">
  304.             <input type=\"hidden\" name=\"ProtoID\" value=\"$protoID\" />
  305.                        <input type=\"hidden\" name=\"ProtoName\" value=\"$name\" />
  306.             </div>
  307.            
  308.         ";
  309.         return $list;
  310.                
  311.        
  312.     }
  313.  
  314.  
  315.     // Protocols Sessions
  316.     function TableProtocols() {
  317.        
  318.         Requirements::customScript('
  319.             function libererrando(id) {
  320.                 var xhr_object = null;
  321.                 var ident = id;
  322.                 if(window.XMLHttpRequest) // Firefox
  323.                      xhr_object = new XMLHttpRequest();
  324.                   else if(window.ActiveXObject) // Internet Explorer
  325.                      xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  326.                   else { // XMLHttpRequest non support&eacute; par le navigateur
  327.                      alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
  328.                      return;
  329.                   }
  330.                   xhr_object.open("POST", "./libererrando.php", true);
  331.                   xhr_object.onreadystatechange = function anonymous() {
  332.                      if(xhr_object.readyState == 4)
  333.                         alert(\'le numero \'+ident+\' est libre.\');
  334.                     }
  335.                 xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  336.                 var data = "ident="+ident;
  337.                 xhr_object.send(data);
  338.             }
  339.            
  340.         ');
  341.         $protoID = $this->ID;
  342.        
  343.         $me = member::currentUser();
  344.         $myID = $me->ID;
  345.  
  346.         global $databaseConfig;
  347.         $connexion = new PDO('mysql:host='.$databaseConfig['server'].';dbname='.$databaseConfig['database'].'', $databaseConfig['username'], $databaseConfig['password']);
  348.  
  349.  
  350.         $list= "";
  351.         $listform= "";
  352.         $sql= "
  353.             SELECT inclusionId, session_ref, groupe, name, statut, type, date_dmd, FirstName, Surname
  354.             FROM Center, `randomisation`
  355.                 LEFT OUTER  JOIN Member ON (`randomisation`.`memberID` = Member.ID)
  356.             WHERE `randomisation`.`centerId` = Center.ID
  357.                 AND randomisation.`protocolId` =  :a
  358.         ";
  359.         $sth = $connexion->prepare("$sql");
  360.         $sth->bindParam(':a', $protoID);
  361.         $sth->execute();
  362.         if ($protoID == 42) {
  363.             $list .= "
  364.                 <table width=700><tr>
  365.                 <td>
  366.                 <a href='./list_wait42.php' target=_blank>sessions <br>en attente<br> de logs</a>
  367.                 </td>
  368.                 <td>
  369.                         <b>
  370.                         Statut de randomisation
  371.                         </h6>
  372.                         <li> -1 = Valeur par d&eacute;faut
  373.                         <li>  0 = session int&eacute;gr&eacute;e
  374.                         <li>  1 = session en attente
  375.                 </td><td>
  376.                 <b> Type du patient</b><br>
  377.                 <li> 00 : < 70ans, non cancer<br>
  378.                 <li> 01 : > 70 ans, non cancer<br>
  379.                 <li> 10 : < 70ans, cancer<br>
  380.                 <li> 11 : > 70 ans, cancer
  381.                 </td></tr></table> 
  382.                 <table>
  383.                     <tr>
  384.                         <td width=50px>incl.</td>
  385.                         <td width=110px>session</td>
  386.                         <td width=50px>groupe</td>
  387.                         <td width=80px>centre</td>
  388.                         <td width=40px>type</td>
  389.                         <td width=140px>r&eacute;servation</td>
  390.                     </tr>
  391.                 </table>
  392.             ";
  393.         }
  394.         $list .= "
  395.             <div id=\"table\" style=\"height: 300px;width: 730px;overflow: auto;display:block;\">
  396.             <table>
  397.         ";
  398.         $m = 1;
  399.         while ($row = $sth->fetch(PDO::FETCH_NUM)) {
  400.             $list .= "
  401.                 <tr><td width=30px>$row[0]</td><td width=30px>$row[1]</td><td width=30px>$row[2]</td><td width=30px>$row[3]</td><td width=30px>$row[5]</td>
  402.             ";
  403.             #numéros réservés
  404.             if ($row[4] == 1 && ($myID == 1 || $myID == 3 || $myID == 18 )) {
  405.                 $liberer = "";
  406.                 if ($row[1] == "") {
  407.                     $liberer = "<a  href=\"javascript: OnClick=libererrando($row[0]);\" >(lib&eacute;rer)</a>";
  408.                 }
  409.                
  410.                 $list .= "
  411.                     <td width=30px>$row[6]</td><td>$row[7] $row[8] $liberer </td>
  412.                 ";
  413.             }
  414.             $list .= "
  415.                 </tr>
  416.             ";
  417.         }
  418.         $list .= "</table>";
  419.         $list .= $listform;
  420.  
  421.         return $list;
  422.        
  423.     }
  424.  
  425.     //Generate the link for this protocol
  426.     function Link()
  427.     {
  428.         //if we are on a category page return that
  429.         if(Director::CurrentPage()->ClassName == 'CategoryPage')
  430.         {
  431.             $Category = Director::CurrentPage();
  432.         }
  433.         //Otherwise just grab the first category this protocol is in
  434.         else
  435.         {
  436.             $Category = $this->Categories()->First();
  437.         }  
  438.         //Check we have a category then return the link
  439.         if($Category)
  440.         {
  441.                    
  442.             return $Category->absoluteLink() . 'show/' . $this->URLSegment;    
  443.         }
  444.     }
  445.    
  446.  
  447. }
  448.  
  449.  
  450. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement