source: trunk/includes/global_function.php@ 163

Last change on this file since 163 was 163, checked in by maron, 16 years ago

uvolnění slovníku

File size: 6.9 KB
Line 
1<?php
2
3define('LICENCE_ANONYMOUS', -1);
4define('LICENCE_USER', 0);
5define('LICENCE_MODERATOR', 1);
6define('LICENCE_ADMIN', 2);
7
8function utf2ascii($text)
9{
10 $return = Str_Replace(
11 Array("á","č","ď","é","ě","í","ľ","ň","ó","ř","š","ť","ú","ů","ý","ž","Á","Č","Ď","É","Ě","Í","Ľ","Ň","Ó","Ř","Š","Ť","Ú","Ů","Ý","Ž") ,
12 Array("a","c","d","e","e","i","l","n","o","r","s","t","u","u","y","z","A","C","D","E","E","I","L","N","O","R","S","T","U","U","Y","Z") ,
13 $text);
14 //$return = Str_Replace(Array(" ", "_"), "-", $return); //nahradí mezery a podtržítka pomlčkami
15 //$return = Str_Replace(Array("(",")",".","!",",","\"","'"), "", $return); //odstraní ().!,"'
16 //$return = StrToLower($return); // velká písmena nahradí malými.
17 return($return);
18}
19
20function getmonthyears($Days) {
21
22 $month = floor($Days/30);
23 $year = floor($month/12);
24 $Days = floor($Days - $month*30);
25 $month = $month - $year*12;
26
27 return $year.'r '.$month.'m '.$Days.'d';
28}
29
30function ListPaging($Address, $Table, $Where, $ItemsPerPage, $CurrentPage)
31{
32 global $Database;
33
34 $Line = mysql_fetch_row($Database->SQLCommand('SELECT count(*) FROM '.$Table.' '.$Where));
35 $ItemCount = floor($Line[0] / $ItemsPerPage);
36
37 echo('Počet položek: <strong>'.$Line[0].'</strong> &nbsp; Zobrazit stránku: ');
38
39 if($CurrentPage > $ItemCount) $CurrentPage = ($ItemCount / $ItemsPerPage) - 1;
40 for($Page = 1; $Page <= $ItemCount+1; $Page++)
41 {
42 if($CurrentPage == $Page) echo('<strong>'.$Page.'</strong> ');
43 else echo('<a href="'.$Address.$Page.'">'.$Page.'</a> ');
44 }
45 echo('<br />');
46}
47
48function FormatOutput($s)
49{
50 $out = '';
51 $nn = 0;
52 $n = 0;
53 while($s!='')
54 {
55 $start = strpos($s,'<');
56 $end = strpos($s,'>');
57 if($start != 0)
58 {
59 $end = $start-1;
60 $start = 0;
61 }
62 $line = trim(substr($s,$start,$end+1));
63 if(strlen($line)>0)
64 if($line[0] == '<')
65 {
66 if($s[$start+1] == '/')
67 {
68 $n = $n - 2;
69 $nn = $n;
70 } else
71 {
72 if(strpos($line,' ')) $cmd = substr($line,1,strpos($line,' ')-1);
73 else $cmd = substr($line,1,strlen($line)-2);
74 //echo('['.$cmd.']');
75 if(strpos($s,'</'.$cmd.'>')) $n = $n + 2;
76 }
77 }// else $line = '['.$line.']';
78 //if($line != '') echo(htmlspecialchars(str_repeat(' ',$nn).$line."\n"));
79 if($line != '') $out .= (str_repeat(' ',$nn).$line."\n");
80 $s = substr($s,$end+1,strlen($s));
81 $nn = $n;
82 }
83 return($out);
84}
85
86function WriteLanguages($Selected)
87{
88 echo('<select name="Language">');
89 echo('<option value="1"'); if ($Selected == '1') echo(' selected="selected"'); echo('>Českého jazyka</option>');
90 echo('<option value="2"'); if ($Selected == '2') echo(' selected="selected"'); echo('>Slovenského jazyka</option>');
91 echo('<option value="3"'); if ($Selected == '3') echo(' selected="selected"'); echo('>Jiného jazyka</option>');
92 echo('</select>');
93}
94
95function WriteLanguagesWithoutSel($Selected)
96{
97 if($Selected == '0') echo('Původní verze jazyka');
98 if($Selected == '1') echo('Českého jazyka');
99 if($Selected == '2') echo('Slovenského jazyka');
100 if($Selected == '3') echo('Jiného jazyka');
101}
102
103function Licence($Licence)
104{
105 global $Database;
106
107 if($Licence == -1) return(true);
108 else
109 if(isset($_SESSION['User']) and ($_SESSION['User'] <> '') and ($_SESSION['UserID'] != ''))
110 {
111 // $User = $_SESSION['User'];
112 $Pass = $_SESSION['Pass'];
113 $Line = mysql_fetch_array($Database->SQLCommand('SELECT * FROM user WHERE ID = '.$_SESSION['UserID'].'
114 AND GM >= '.$Licence.' AND pass = sha1("'.$Pass.'")'));
115 // echo "SELECT * FROM user WHERE ID = ".$_SESSION['UserID']." AND GM <= $Licence AND pass = '$Pass'";
116 return($Line);
117 } else
118 {
119 return(false);
120 }
121}
122
123function MysqlDateTimeToTime($Time)
124{
125 $Parts = explode(' ', $Time);
126 $DateParts = explode('-', $Parts[0]);
127 $TimeParts = explode(':', $Parts[1]);
128 $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]);
129 return($Result);
130}
131
132function GetTranslationTree()
133{
134 global $Database;
135
136 $Result = array();
137 $DbResult = $Database->SQLCommand('SELECT * FROM `group`');
138 while($DbRow = mysql_fetch_assoc($DbResult))
139 {
140 $DbRow['Items'] = array();
141 $Result[$DbRow['Id']] = $DbRow;
142 }
143 $DbResult = $Database->SQLCommand('SELECT * FROM `group_item`');
144 while($DbRow = mysql_fetch_assoc($DbResult))
145 {
146 $Result[$DbRow['Group']]['Items'][] = $DbRow;
147 }
148 return($Result);
149}
150
151$LogTypes = array
152(
153 // index, indexname , barva , popis
154 array('0', '', 'brown', ''),
155 array('1', 'Překlady', 'green', 'Operace s překladdy'),
156 array('2', 'Stažení', 'brown', 'Stáhnutí souboru'),
157 array('3', 'Uživatelé', 'blue', 'Přihlášení uživatelů, nastavení, registrace'),
158 array('4', 'Moderátor', 'orange', 'Operace administrátorů a moderátorů'),
159 array('10', 'Chyby', 'red', 'Zachycené chybové hlášení'),
160);
161
162$Moderators = array('Překladatel', 'Moderátor', 'Administrátor');
163
164function WriteLog($Text, $Type)
165{
166 global $Database, $Config;
167
168 $user = @$_SESSION['UserID'];
169 if($user == '') $user = 0;
170 $Database->SelectDatabase($Config['Database']['Database']);
171 $Query = 'INSERT INTO `log` ( `user` , `type` , `text` , `date` , `IP` )
172 VALUES ('.$user.', '.$Type.', "'.addslashes($Text).'", NOW(), "'.addslashes($_SERVER['REMOTE_ADDR']).'")';
173 $Database->SQLCommand($Query);
174}
175
176$client_files = array
177(
178 '0' => 'LocalizationStrings',
179 '1' => 'SpellBufDescription_1',
180 '2' => 'SpellDescription_1',
181 '3' => 'SpellDescription_2',
182 '4' => 'SpellDescription_3',
183 '5' => 'SpellDescription_4',
184 '6' => 'tallent',
185);
186
187function HumanDate($SQLDateTime)
188{
189 $DateTimeParts = explode(' ', $SQLDateTime);
190 $DateParts = explode('-', $DateTimeParts[0]);
191 return(($DateParts[2] * 1).'.'.($DateParts[1] * 1).'.'.($DateParts[0] * 1));
192}
193
194function FollowingTran($TextID,$Table,$GroupId, $Prev = false) {
195
196 global $Database;
197
198 if($Prev)
199 {
200 $sql = 'SELECT ID FROM '.$Table.' as item WHERE Language = 0 AND NOT EXISTS(SELECT entry FROM '.$Table.' AS sub WHERE sub.Language <> 0 AND sub.entry = item.entry) AND ID < '.$TextID.' ORDER BY ID DESC LIMIT 1';
201 } else
202 {
203 $sql = 'SELECT ID FROM '.$Table.' as item WHERE Language = 0 AND NOT EXISTS(SELECT entry FROM '.$Table.' AS sub WHERE sub.Language <> 0 AND sub.entry = item.entry) AND ID > '.$TextID.' ORDER BY ID LIMIT 1';
204 }
205
206 $Next = mysql_fetch_array($Database->SQLCommand($sql));
207 if(!$Next) {} else
208 {
209 if($Prev) echo('<a href="form.php?group='.$GroupId.'&amp;ID='.$Next['ID'].'">Předcházející '.$Next['ID'].'</a> ');
210 else echo('<a href="form.php?group='.$GroupId.'&amp;ID='.$Next['ID'].'">Následující '.$Next['ID'].'</a> ');
211 }
212}
213
214?>
Note: See TracBrowser for help on using the repository browser.