Guest User

Untitled

a guest
Jan 10th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.57 KB | None | 0 0
  1. <!--cadastrar evento-->
  2. <div class="item-main-admin">
  3.  
  4. <p2><center>
  5. <form name="cadastrarevento" method="post" action="cadastrando.php">
  6. Título: <input type="text" name="titulo" value="encontro-"/> </br>
  7. Data: <input type="text" name="data" placeholder="aaaa/mm/dd" /> </br>
  8. Encontro: <input type="text" name="encontro" /> </br>
  9. <input type="submit" value="Cadastrar evento" />
  10. </form>
  11. </p2></center>
  12. </div>
  13.  
  14.  
  15.  
  16.  
  17. <!--calendario-->
  18. <div class="item-main-admin">
  19. <?php
  20. $eventos = montaEventos($info);
  21. montaCalendario($eventos);
  22. ?>
  23. </div>
  24.  
  25. <script type="text/javascript" src="/administrador/calendario/jquery.js"></script>
  26. <script type="text/javascript" src="/administrador/calendario/functions.js"></script>
  27.  
  28. <?php
  29. error_reporting (E_ALL & ~ E_NOTICE & ~ E_DEPRECATED);
  30. $host = "localhost";
  31. $user = "root";
  32. $pass = "";
  33. $banco = "calendario";
  34. $conexao = mysql_connect($host, $user, $pass) or die(mysql_error());
  35. mysql_select_db($banco) or die(mysql_error());
  36. ?>
  37.  
  38.  
  39. <?php
  40. mysql_query("SET NAMES 'utf8'");
  41. mysql_query('SET character_set_connection=utf8');
  42. mysql_query('SET character_set_client=utf8');
  43. mysql_query('SET character_set_results=utf8');
  44. ?>
  45.  
  46.  
  47. <?php
  48.  
  49. $titulo=$_POST['titulo'];
  50. $data=$_POST['data'];
  51. $encontro=$_POST['encontro'];
  52.  
  53.  
  54. $myFile = "$titulo.php";
  55.  
  56.  
  57. $result = mysql_query("SELECT titulo FROM eventos WHERE titulo = '$titulo'");
  58.  
  59. if (mysql_num_rows($result)>0) {
  60. echo "O título $titulo já existe. Crie um diferente.";
  61. } else {
  62.  
  63. $sql = mysql_query("INSERT INTO eventos(titulo, data, encontro)
  64. VALUES('$titulo', '$data', '$encontro')");
  65.  
  66.  
  67. $fh = fopen($myFile, 'w');
  68.  
  69. $stringData = "<html><?php include 'template.php';?></html>";
  70.  
  71.  
  72. fwrite($fh, $stringData);
  73. //header('Location: ' . $myFile);
  74. fclose($fh);
  75.  
  76.  
  77. ?>
  78.  
  79.  
  80.  
  81. <div class="cadastro_ok">
  82. <div id="item-cadastro_ok">
  83. <img src="imagens/ok.png" />
  84. </div>
  85. <div id="item-cadastro_ok">
  86. <?php echo "Cadastro efetuado com sucesso!"; ?>
  87. </div>
  88. </div>
  89.  
  90. <?php } ?>
  91.  
  92.  
  93.  
  94. <?php
  95. echo '<meta http-equiv="refresh" content="3;URL=admin.php" />';
  96. ?>
  97.  
  98. </div>
  99.  
  100. </body>
  101.  
  102. </html>
  103.  
  104. $sql = mysql_query("INSERT INTO eventos(titulo, data, encontro)
  105. VALUES('$titulo', '$data', '$myFile')");
  106.  
  107. <?php
  108.  
  109. function num($num){
  110. return ($num < 10) ? '0'.$num : $num;
  111. }
  112. function montaEventos($info){
  113. global $pdo;
  114. //tabela, data, titulo, encontro
  115. $tabela = $info['tabela'];
  116. $data = $info['data'];
  117. $titulo = $info['titulo'];
  118. $encontro = $info['encontro'];
  119. $eventos = $pdo->prepare("SELECT * FROM `".$tabela."` ");
  120. $eventos->execute();
  121. $retorno = array();
  122. while($row = $eventos->fetchObject()){
  123. $dataArr = date('Y-m-d', strtotime($row->{$data}));
  124. $retorno[$dataArr] = array(
  125. 'titulo' => $row->{$titulo},
  126. 'encontro' => $row->{$encontro}
  127. );
  128. }
  129. return $retorno;
  130. }
  131. function diasMeses(){
  132. $retorno = array();
  133. for($i = 1; $i<=12;$i++){
  134. $retorno[$i] = cal_days_in_month(CAL_GREGORIAN, $i, date('Y'));
  135. }
  136. return $retorno;
  137. }
  138. function montaCalendario($eventos = array()){
  139. $daysWeek = array(
  140. 'Sun',
  141. 'Mon',
  142. 'Tue',
  143. 'Wed',
  144. 'Thu',
  145. 'Fri',
  146. 'Sat'
  147. );
  148. $diasSemana = array(
  149. 'Dom',
  150. 'Seg',
  151. 'Ter',
  152. 'Qua',
  153. 'Qui',
  154. 'Sex',
  155. 'Sab'
  156. );
  157. $arrayMes = array(
  158. 1 => 'Janeiro',
  159. 2 => 'Fevereiro',
  160. 3 => 'Março',
  161. 4 => 'Abril',
  162. 5 => 'Maio',
  163. 6 => 'Junho',
  164. 7 => 'Julho',
  165. 8 => 'Agosto',
  166. 9 => 'Setembro',
  167. 10 => 'Outubro',
  168. 11 => 'Novembro',
  169. 12 => 'Dezembro'
  170. );
  171. $diasMeses = diasMeses();
  172. $arrayRetorno = array();
  173. for($i =1; $i <= 12; $i++){
  174. $arrayRetorno[$i] = array();
  175. for($n=1; $n<= $diasMeses[$i]; $n++){
  176. $dayMonth = gregoriantojd($i, $n, date('Y'));
  177. $weekMonth = substr(jddayofweek($dayMonth, 1),0,3);
  178. if($weekMonth == 'Mun') $weekMonth = 'Mon';
  179. $arrayRetorno[$i][$n] = $weekMonth;
  180. }
  181. }
  182. echo '<a href="#" id="volta">&laquo;</a><a href="#" id="vai">&raquo;</a>';
  183. echo '<table border="0" width="100%">';
  184. foreach($arrayMes as $num => $mes){
  185. echo '<tbody id="mes_'.$num.'" class="mes">';
  186. echo '<tr class="mes_title"><td colspan="7">'.$mes.'</td></tr>';
  187. echo '<tr class="dias_title">';
  188. foreach($diasSemana as $i => $day){
  189. echo '<td>'.$day.'</td>';
  190. }
  191. echo '</tr><tr>';
  192. $y = 0;
  193. foreach($arrayRetorno[$num] as $numero => $dia){
  194. $y++;
  195. if($numero == 1){
  196. $qtd = array_search($dia, $daysWeek);
  197. for($i=1; $i<=$qtd; $i++){
  198. echo '<td></td>';
  199. $y+=1;
  200. }
  201. }
  202. if(count($eventos) > 0){
  203. $month = num($num);
  204. $dayNow = num($numero);
  205. $date = date('Y').'-'.$month.'-'.$dayNow;
  206. if(in_array($date, array_keys($eventos))){
  207. $evento = $eventos[$date];
  208. echo '<td class="evento"><a href="'.$evento['encontro'].'" title="'.$evento['titulo'].'">'.$numero.'</a></td>';
  209. }else{
  210. echo '<td class="dia_'.$numero.'">'.$numero.'</td>';
  211. }
  212. }else{
  213. echo '<td class="dia_'.$numero.'">'.$numero.'</td>';
  214. }
  215. if($y == 7){
  216. $y=0;
  217. echo '</tr><tr>';
  218. }
  219. }
  220. echo '</tr></tbody>';
  221. }
  222. echo '</table>';
  223. }
  224. ?>
Add Comment
Please, Sign In to add comment