Diferencia entre revisiones de «Curso básico de PHP/EvalMaestro»

De WikiCabal
Ir a la navegación Ir a la búsqueda
 
(Sin diferencias)

Revisión actual del 03:23 4 oct 2016

EvalMaestro

  1 <?php
  2 
  3   // Este Archivo: EvalMaestro.php
  4 
  5   /*
  6     use MyTest1
  7 
  8     CREATE TABLE `Evaluadores` (
  9       `ID` int(6) NOT NULL auto_increment,
 10       `Nombre` varchar(25) default NULL,
 11       `EMail` varchar(25) default NULL,
 12       PRIMARY KEY  (`ID`),
 13       UNIQUE KEY `EMail` (`EMail`));
 14 
 15     CREATE TABLE `Evaluaciones` (
 16       `ID` int(4) not null auto_increment,
 17       `Maestro` varchar (25),
 18       `EvaluadoresID` int(4) not null,
 19       `Evaluacion` enum( '0', '1', '2', '3', '4', '5' ) default '0',
 20       primary key (`ID`),
 21       KEY `EvaluadoresID` (`EvaluadoresID`),
 22       CONSTRAINT `Evaluaciones_ibfk_1` foreign key (`EvaluadoresID`)
 23         references `Evaluadores` (`ID`));
 24 
 25     describe Evaluadores;
 26     describe Evaluaciones;
 27   */
 28 
 29   $RegForm = <<< FinRegForma
 30               <p style="font:28pt charter; color:#000000; text-align:center;">
 31                  Evalua a tu Maestro
 32               </p>
 33               <p style="font:18pt charter; color:#000000; text-align:center;">
 34                  &iexcl;Ingresa tus datos porfavor!
 35               </p>
 36               <form method="post" action="{$_SERVER{'PHP_SELF'}}">
 37                 <p style="font:14pt charter; color:#000000; text-align:center;">
 38                   Nombre:&nbsp;
 39                   <input type="text" size="25" maxlength="25" name="Nombre" />
 40                   &nbsp;&nbsp;&nbsp;EMail:&nbsp;
 41                   <input type="text" size="25" maxlength="25" name="EMail" />
 42                   <br /><br />
 43                   <input type="hidden" name="Eval" value="Register" />
 44                   <input type="submit" name="Submit" value="Submit" />
 45                   &nbsp;&nbsp;&nbsp;&nbsp;
 46                   <input type="reset" />
 47                 </p>
 48               </form>
 49 FinRegForma;
 50 
 51   $EvalForm = <<< FinEvalForma
 52                   <div style="width:90%; margin-left:10%; position:relative;">
 53                     <p style="font:28pt charter; color:#000000;">
 54                       Evalua a tu Maestro
 55                     </p>
 56                     <p style="font:18pt charter; color:#000000;">
 57                       Mi maestro:
 58                     </p>
 59                     <form method="post" action="{$_SERVER{'PHP_SELF'}}">
 60                       <p>
 61                       <input type="radio" name="Rating" value="1" />
 62                         El es un payaso en todo los sentidos
 63                         <br />
 64                       <input type="radio" name="Rating" value="2" />
 65                         El debe aprender su materia antes de ense&ntilde;arla
 66                         <br />
 67                       <input type="radio" name="Rating" value="3" />
 68                         El es totalmente NORMAL
 69                         <br />
 70                       <input type="radio" name="Rating" value="4" />
 71                         El es guapo, inteligente y divertido
 72                         <br />
 73                       <input type="radio" name="Rating" value="5"
 74                              checked="checked" />
 75                         El es una inspiraci&oacute;n para la humanidad
 76                         <br /><br />
 77                       <select name="Maestro" size="1"
 78                               style="font:14pt charter; color:#000000;">
 79                         <option
 80                           value="Richard Couture">Richard Couture
 81                         </option>
 82                         <option
 83                           value="Juan Gomez">Juan Gomez
 84                         </option>
 85                         <option
 86                           value="Enrique Lopez">Enrique Lopez
 87                         </option>
 88                       </select>
 89                       <input type="hidden" name="Eval" value="Eval" />
 90                       <input type="hidden" name="EMail"
 91                              value="{$_POST{'EMail'}}" />
 92                       <input type="submit" name="Submit" value="Submit" />
 93                       </p>
 94                     </form>
 95                    </div>
 96 FinEvalForma;
 97 
 98   if( @!$_POST{'Submit'} )
 99   {
100     $DisplayBlock = $RegForm;
101   }
102 
103 // <<<<---- Registrar ---->>>>
104 
105   elseif( @$_POST{'Submit'} == 'Submit' && @$_POST{'Eval'} == 'Register' )
106   {
107     if( !$_POST{'Nombre'} || $_POST{'Nombre'} == ""
108      || !$_POST{'EMail'} || $_POST{'EMail'} == "" )
109     {
110       $DisplayBlock = "<p style=\"text-align: center;
111                           Font:Bold 18pt Charter; Color:#aa0000;\">
112                          No puede continuar sin tu Nombre Y tu EMail!
113                        <p>";
114       $DisplayBlock .= $RegForm;
115     }
116     else
117     { 
118       require_once( "MySQLClaseConnect.inc.php");
119 
120       $Query = "Select ID from Evaluadores
121                 where Nombre = '{$_POST{'Nombre'}}'
122                 AND EMail = '{$_POST{'EMail'}}'";
123 
124       if( !$QueryRes = mysqli_query( $Conn, $Query ) )
125       {
126         mysqli_close( $Conn );
127         header( "Location: MensajeError.php?Errno=1009" );
128         exit();
129       }
130 
131       if( mysqli_num_rows( $QueryRes ) )
132         $DisplayBlock = &$EvalForm;
133       else
134       {
135         $Query = "insert into Evaluadores ( ID, Nombre, EMail ) values
136                   ( NULL, '{$_POST{'Nombre'}}', '{$_POST{'EMail'}}' )";
137 
138         if( !mysqli_query( $Conn, $Query ) )
139         {
140           mysqli_close( $Conn );
141           header( "Location: MensajeError.php?Errno=1011" );
142           exit();
143         }
144 
145         if( mysqli_affected_rows( $Conn ) == 1 )
146           $DisplayBlock = &$EvalForm;
147         else
148         {
149           mysqli_close( $Conn );
150           error_log( mysqli_error( $Conn ) );
151           header( "Location: MensajeError.php?Errno=1012" );
152         }
153       }
154     }
155     mysqli_close( $Conn );
156   }
157 
158 // <<<<---- Escribe Eveluacion ---->>>>
159 
160   elseif( @$_POST{'Submit'} == 'Submit' && @$_POST{'Eval'} == 'Eval' )
161   {
162     require_once( "MySQLClaseConnect.inc.php");
163 
164     $Query = "select ID from Evaluadores where EMail = '{$_POST{'EMail'}}'";
165     if( !$QueryRes = mysqli_query( $Conn, $Query ) )
166     {
167       mysqli_close( $Conn );
168       header( "Location: MensajeError.php?Errno=1014" );
169       exit();
170     }
171 
172     if( mysqli_num_rows( $QueryRes ) != 1 )
173     {
174       mysqli_close( $Conn );
175       header( "Location: MensajeError.php?Errno=1015" );
176       exit();
177     }
178     else
179     {
180       $Registro = mysqli_fetch_array( $QueryRes );
181       $EvaluadorID = $Registro{'ID'};
182 
183       mysqli_free_result( $QueryRes );
184 
185       $Query = "insert into Evaluaciones ( ID, Maestro, EvaluadoresID,
186                                            Evaluacion )
187                 values ( NULL, '{$_POST{'Maestro'}}', '$EvaluadorID',
188                          '{$_POST{'Rating'}}' )";
189 
190       if( !mysqli_query( $Conn, $Query ) )
191       {
192         mysqli_close( $Conn );
193         error_log( mysqli_error( $Conn ) );
194         header( "Location: MensajeError.php?Errno=1016" );
195         exit();
196       }
197 
198       if( mysqli_affected_rows( $Conn ) != 1 )
199       {
200         mysqli_close( $Conn );
201         header( "Location: MensajeError.php?Errno=1017" );
202       }
203       else
204         $DisplayBlock = "<p style=\"font:bold 28pt helvetica; color:#000000;
205                             text-align: center;\">
206                                  -=&nbsp;Agregado de Evaluaci&oacute;n&nbsp;=-
207                                </p>
208                                <p style=\"font:bold 28pt helvetica;
209                                           color:#050099; text-align:center;\">
210                                  CONFIRMADO!
211                                </p>
212                                <p style=\"font:12pt helvetica; color:#050050;
213                                   text-align: left;\">
214                                  <a href=\"EvalMaestro.php\">
215                                    Evalua a otro maestro
216                                  </a>
217                                <p>";
218     }
219     mysqli_close( $Conn );
220   }
221 
222   require_once( "Cabeza5.inc" );
223   print( $DisplayBlock );
224   require_once( "incPie5.php" );
225 ?>

Contenidos de Cabeza5.inc

Ver los contenidos de Cabeza5.inc

Contenidos de MySQLClaseConnect.inc.php

Ver los contenidos de MySQLClaseConnect.inc.php

Contenidos de incPie5.php

Ver los contenidos de incPie5.php

Contenidos de clase.css

Ver los contenidos de clase.css

Explicación

Ejecutarlo

Ejecutar el código de EvalMaestro

Descargarlo

Descargar el código de EvalMaestro