Voltar para Paste Lymas | pasteLog v. 2.0-alpha

Visualizando código



Postado por note_b em 01/07/2009 11:35:31.
http://paste.lymas.com.br/508

Clique AQUI para fazer download do código. Esconder número da linha

  1. FUNCIONS.PHP
  2.  
  3. <?php
  4. function auth($login = '', $passwd = '')
  5. {
  6.     session_start();
  7.     global $dbhost, $dbuser, $dbpw, $dbname;
  8.     global $HTTP_SESSION_VARS, $tablepre;
  9.    
  10.     $authdata = $HTTP_SESSION_VARS['authdata'];
  11.    
  12.     if ( is_array( $authdata ) ) {
  13.         $check = $authdata['login'];
  14.         $pw = $authdata['password'];
  15.         $register = false;
  16.     } elseif (!empty($login)) {
  17.         $check = $login;
  18.         $pw = $passwd;
  19.         $register = true;
  20.     } else {
  21.         return false;
  22.     }
  23.    
  24.     mysql_connect($dbhost, $dbuser, $dbpw) or die(mysql_error());
  25.     mysql_select_db($dbname) or die(mysql_error());
  26.    
  27.     $sql = "SELECT * FROM " . $tablepre . "users WHERE username = '" . $check . "'";
  28.     $result = mysql_query($sql) or die(mysql_error());
  29.     $row = mysql_fetch_assoc($result);
  30.    
  31.     if ( $row["password"] == $pw ) {
  32.    
  33.         if ($register) {
  34.             $HTTP_SESSION_VARS["authdata"] = array("login"=>$row["username"], "password"=>$row["password"], "userlevel"=>$row["user_level"], "uid"=>$row["uid"]);
  35.         }
  36.        
  37.         return $row["userlevel"];
  38.     }
  39.  
  40.     unset( $HTTP_SESSION_VARS['authdata'] );
  41.     return false;
  42. }
  43.  
  44. function monthPullDown($month, $montharray)
  45. {
  46.     echo "n<select name="month">n";
  47.  
  48.     for($i=0;$i < 12; $i++) {
  49.         if ($i != ($month - 1)) {
  50.             echo "  <option value="" . ($i + 1) . "">$montharray[$i]</option>n";
  51.         } else {
  52.             echo "  <option value="" . ($i + 1) . "" selected>$montharray[$i]</option>n";
  53.         }
  54.     }
  55.  
  56.     echo "</select>nn";
  57. }
  58.  
  59. function yearPullDown($year)
  60. {
  61.     echo "<select name="year">n";
  62.  
  63.     $z = 3;
  64.     for($i=1;$i < 8; $i++) {
  65.        
  66.         if ($z == 0) {
  67.             echo "  <option value="" . ($year - $z) . "" selected>" . ($year - $z) . "</option>n";
  68.         } else {
  69.             echo "  <option value="" . ($year - $z) . "">" . ($year - $z) . "</option>n";
  70.         }
  71.        
  72.         $z--;
  73.     }
  74.  
  75.     echo "</select>nn";
  76. }
  77.  
  78. function dayPullDown($day)
  79. {
  80.     echo "<select name="day">n";
  81.  
  82.     for($i=1;$i <= 31; $i++) {
  83.         if ($i == $day) {
  84.             echo "  <option value="$i" selected>$i</option>n";
  85.         } else {
  86.             echo "  <option value="$i">$i</option>n";
  87.         }
  88.     }
  89.  
  90.     echo "</select>nn";
  91. }
  92.  
  93. function hourPullDown($hour, $namepre)
  94. {
  95.     echo "n<select name="" . $namepre . "_hour">n";
  96.  
  97.     for($i=0;$i <= 12; $i++) {
  98.         if ($i == $hour) {
  99.             echo "  <option value="$i" selected>$i</option>n";
  100.         } else {
  101.             echo "  <option value="$i">$i</option>n";
  102.         }
  103.     }
  104.  
  105.     echo "</select>nn";
  106. }
  107.  
  108. function minPullDown($min, $namepre)
  109. {
  110.     echo "n<select name="" . $namepre . "_min">n";
  111.  
  112.     for($i=0;$i <= 55; $i+=5) {
  113.        
  114.         if ($i < 10) { $disp = "0" . $i; } else { $disp = $i; }
  115.        
  116.         if ($i == $min) {
  117.             echo "  <option value="$i" selected>$disp</option>n";
  118.         } else {
  119.             echo "  <option value="$i">$disp</option>n";
  120.         }
  121.     }
  122.  
  123.     echo "</select>nn";
  124. }
  125.  
  126. function amPmPullDown($pm, $namepre)
  127. {
  128.     if ($pm) { $pm = " selected"; } else { $am = " selected"; }
  129.  
  130.     echo "n<select name="" . $namepre . "_am_pm">n";
  131.     echo "  <option value="0"$am>am</option>n";
  132.     echo "  <option value="1"$pm>pm</option>n";
  133.     echo "</select>nn";
  134. }
  135.  
  136. function javaScript()
  137. {
  138. ?>
  139.     <script language="JavaScript">
  140.     function submitMonthYear() {
  141.         document.monthYear.method = "post";
  142.         document.monthYear.action = "index.php?month=" + document.monthYear.month.value + "&year=" + document.monthYear.year.value;
  143.         document.monthYear.submit();
  144.     }
  145.  
  146.     function postMessage(day, month, year) {
  147.         eval("page" + day + " = window.open('eventform.php?d=" + day + "&m=" + month + "&y=" + year + "', 'postScreen', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=340,height=400');");
  148.     }
  149.  
  150.     function openPosting(pId) {
  151.         eval("page" + pId + " = window.open('eventdisplay.php?id=" + pId + "', 'mssgDisplay', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=340,height=400');");
  152.     }
  153.    
  154.     function loginPop(month, year) {
  155.         eval("logpage = window.open('login.php?month=" + month + "&year=" + year + "', 'mssgDisplay', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=340,height=400');");
  156.     }
  157.     </script>
  158. <?php
  159. }
  160.  
  161.  
  162. function footprint($auth, $m, $y) {
  163.     global $lang;
  164.    
  165.     echo "<br><br><span class="footprint">n";
  166.     echo "Calendário de eventos<br>n[ ";
  167.    
  168.     if ( $auth == 2 ) {
  169.         echo "<a href="useradmin.php">" . $lang['adminlnk'] . "</a> | ";
  170.         echo " <a href="login.php?action=logout&month=$m&year=$y">" . $lang['logout'] . "</a>";
  171.     } elseif ( $auth == 1 ) {
  172.         echo "<a href="useradmin.php?flag=changepw">" . $lang['changepw'] . "</a> | ";
  173.         echo "<a href="login.php?action=logout&month=$m&year=$y">" . $lang['logout'] . " </a>";
  174.     } else {
  175.         echo "<a href="javascript:loginPop($m, $y)">" . $lang['login'] . "</a>";
  176.     }
  177.    
  178.     echo " ]</span>";
  179. }
  180.  
  181.  
  182. function scrollArrows($m, $y)
  183. {
  184.     // setar variáveis para o mês corrente
  185.     $nextyear = ($m != 12) ? $y : $y + 1;
  186.     $prevyear = ($m != 1) ? $y : $y - 1;
  187.     $prevmonth = ($m == 1) ? 12 : $m - 1;
  188.     $nextmonth = ($m == 12) ? 1 : $m + 1;
  189.  
  190.     $s = "<a href="index.php?month=" . $prevmonth . "&year=" . $prevyear . "">n";
  191.     $s .= "<img src="images/leftArrow.gif" border="0"></a> ";
  192.     $s .= "<a href="index.php?month=" . $nextmonth . "&year=" . $nextyear . "">";
  193.     $s .= "<img src="images/rightArrow.gif" border="0"></a>";
  194.    
  195.     return $s;
  196. }
  197.  
  198. function writeCalendar($month, $year)
  199. {
  200.     global $lang, $tablepre, $titlelimit, $titlecharlimit;
  201.     global $dbhost, $dbuser, $dbpw, $dbname;
  202.    
  203.     $str = "<table cellpadding="1" cellspacing="1" border="0">n<tr>n";
  204.    
  205.     foreach($lang['abrvdays'] as $day) {
  206.         $str .= "t<td class="column_header">&nbsp;$day</td>n";
  207.     }
  208.  
  209.     $str .= "</tr>nn";
  210.  
  211.     mysql_connect($dbhost, $dbuser, $dbpw) or die(mysql_error());
  212.     mysql_select_db($dbname) or die(mysql_error());
  213.  
  214.     $sql = "SELECT id, d, title, TIME_FORMAT(start_time, '%l:%i%p') AS stime, TIME_FORMAT(end_time, '%l:%i%p') AS etime FROM " . $tablepre . "mssgs WHERE m = $month AND y = $year ORDER BY start_time";
  215.     $result = mysql_query($sql) or die(mysql_error());
  216.  
  217.     // cria array com título, id e hora para os eventos
  218.     while($row = mysql_fetch_assoc($result)) {
  219.         $eventinfo[$row["d"]]["id"][] = $row["id"];
  220.  
  221.         // setar uma pequena string.  $titleDisplayCharLimit de config.php
  222.         if (strlen($row["title"]) > $titlecharlimit) {
  223.             $eventinfo[$row["d"]]["title"][] = substr(stripslashes($row["title"]), 0, $titlecharlimit) . "...";
  224.         } else {
  225.             $eventinfo[$row["d"]]["title"][] = stripslashes($row["title"]);
  226.         }
  227.        
  228.         if ( $row["stime"] != $row["etime"]) {
  229.             $timestr = "<div align="right" class="time_str">(" . $row["stime"] . " - " . $row["etime"] . ")&nbsp;</div>";
  230.         } else {
  231.             $timestr = "<br>";
  232.         }
  233.  
  234.         $eventinfo[$row["d"]]["timestr"][] = $timestr;
  235.     }
  236.    
  237.     // determina se o usuário está autorizado a editar o calendário
  238.     $auth = auth();
  239.    
  240.     // pega  o número de dias no mês
  241.     $days = 31-((($month-(($month<8)?1:0))%2)+(($month==2)?((!($year%((!($year%100))?400:4)))?1:2):0));
  242.    
  243.     // pega a posição da semana do primeiro dia do mês
  244.     $weekpos = date("w",mktime(0,0,0,$month,1,$year));
  245.     $day = ($weekpos == 0) ? 1 : 0;
  246.  
  247.     // variáveis do dia que muda a cor da tabela
  248.     $d = date(j); $m = date(n); $y = date(Y);
  249.    
  250.     // loop que escreve nas células vazia até atingir posição do 1º dia do mês ($wPos)
  251.     // e ele escreve os dias e, em seguida, preenche a última linha com células vazias após o último dia
  252.     while($day <= $days) {
  253.        
  254.         $str .="<tr>n";
  255.  
  256.         for($i=0;$i < 7; $i++) {
  257.  
  258.             if($day > 0 && $day <= $days) {
  259.                
  260.                 $str .= "   <td class="";
  261.                
  262.                 if (($day == $d) && ($month == $m) && ($year == $y)) {
  263.                     $str .= "today";
  264.                 } else {
  265.                     $str .= "day";
  266.                 }
  267.                
  268.                 $str .= "_cell" valign="top"><span class="day_number">";
  269.                
  270.                 if ($auth) {
  271.                     $str .= "<a href="javascript: postMessage($day, $month, $year)">$day</a>";
  272.                 } else {
  273.                     $str .= "$day";
  274.                 }
  275.                
  276.                 $str .= "</span><br>";
  277.                
  278.                 // impõe limite no título
  279.                 $titles = count($eventinfo[$day]["title"]);
  280.                 if ($titlelimit < $titles) { $titles = $titlelimit; }
  281.                
  282.                 // mostra o link do evento se existir algum para o dia marcado
  283.                 if($eventinfo[$day]["title"][0]) {
  284.                     for($j=0;$j < $titles;$j++) {
  285.                         $str .= "<span class="title_txt">-";
  286.                         $str .= "<a href="javascript:openPosting(" . $eventinfo[$day]["id"][$j] . ")">";
  287.                         $str .= $eventinfo[$day]["title"][$j] . "</a></span>" . $eventinfo[$day]["timestr"][$j];
  288.                     }
  289.                 }
  290.  
  291.                 $str .= "</td>n";
  292.                 $day++;
  293.             } elseif($day == 0)  {
  294.                 $str .= "   <td class="empty_day_cell" valign="top">&nbsp;</td>n";
  295.                 $weekpos--;
  296.                 if ($weekpos == 0) {$day++;}
  297.             } else {
  298.                 $str .= "   <td class="empty_day_cell" valign="top">&nbsp;</td>n";
  299.             }
  300.         }
  301.         $str .= "</tr>nn";
  302.     }
  303.    
  304.     $str .= "</table>nn";
  305.     return $str;
  306. }
  307. ?>


Colando um novo código


Seu Apelido:
Guardar o apelido em um cookie?

Linguagem:


Código: