Created
October 31, 2011 17:58
-
-
Save laacz/1328180 to your computer and use it in GitHub Desktop.
Legacy FTW
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$NOW=date("U"); | |
$TODAY = mktime(0, 0, 0, date("m") , date("d"), date("Y")); | |
$TOMORROW = mktime(0, 0, 0, date("m") , date("d")+1, date("Y")); | |
$DFORMAT="d.m.Y."; | |
$DTFORMAT="d.m.Y. H:i:s"; | |
$lvdayL=array("","pirmdiena","otrdiena","trešdiena","ceturtdiena","piektdiena","sestdiena","svetdiena"); | |
$lvday=array("","Pirmdiena","Otrdiena","Trešdiena","Ceturtdiena","Piektdiena","Sestdiena","Svetdiena"); | |
function lvdate($d=0) { | |
if ($d==0) { $d=date('U'); }; | |
$menesii=array('janvārī', 'februārī','martā','aprīlī', 'maijā', 'jūnijā', 'jūlijā','augustā', 'septembrī', | |
'oktobrī','novembrī','decembrī'); | |
return date("Y",$d).".gada ".date("d",$d).". ".$menesii[(int)date("m",$d)-1]; | |
}; | |
function lvdateN_($d=0) { | |
if ($d==0) { $d=date('U'); }; | |
$menesi=array(0,"janvāris","februāris","marts","aprīlis","maijs","jūnijs","jūlijs","augusts","septembris","oktobris","novembris","decembris"); | |
//global $menesi; | |
return date("Y",$d).".gada ".date("d",$d).". ".($menesi[(int)date("m",$d)]); | |
}; | |
function capitalize($string) { | |
return strtoupper($string[0]).substr($string,1); | |
} | |
function LinkButton($Title,$URL,$add='') { | |
echo "<INPUT Type=button VALUE=\"$Title\" class=button OnClick=\"document.location='$URL';\" $add >"; | |
} | |
function PrintButton($URL,$Title="Izdrukat...") { | |
echo "<INPUT Type=button VALUE=\"$Title\" OnClick=\"document.location='$URL';\">"; | |
} | |
function br() { echo "<br>"; } | |
function SubmitButton($Title) { | |
echo "<INPUT Type=submit VALUE=\"$Title\" class=button>"; | |
} | |
function atskruuveet_datumus() { | |
foreach($_POST as $key=>$element) { | |
if (substr($key,0,2)=='dt') { | |
$dtfieldname=substr($key,4); | |
if (substr($key,0,3)=='dtY') { | |
$_POST[$dtfieldname."_serial"]=$_POST["dtY_".$dtfieldname]."-".$_POST["dtM_".$dtfieldname]."-".$_POST["dtD_".$dtfieldname]; | |
if ($_POST["dtH_".$dtfieldname]) { | |
if (!$_POST["dtI_".$dtfieldname]) { $_POST["dtI_".$dtfieldname]="0";} | |
$_POST[$dtfieldname."_serial"].=" ".$_POST["dtH_".$dtfieldname].":".$_POST["dtI_".$dtfieldname]; | |
}; | |
if ($_POST[$dtfieldname."_serial"]!='--') $_POST["db_".$dtfieldname]=strtotime($_POST[$dtfieldname."_serial"]); | |
else $_POST["db_".$dtfieldname]=""; | |
}; | |
// $_POST[$dtfieldname]="$element.".$_POST[$dtfieldname]; | |
}; | |
if (trim($_POST[$dtfieldname])=='...') { $_POST[$dtfieldname]=''; }; | |
} | |
} | |
function OptionList($query,$selected,$dots=0) { | |
$x=mysql_query($query) or die(mysql_error()); | |
$f=" selected "; | |
while ($row=mysql_fetch_row($x)) { | |
if ($row[0]==$selected) { | |
$f=""; | |
echo "<option selected value=\"$row[0]\">$row[1]</option>"; | |
} else { | |
echo "<option value=\"$row[0]\">$row[1]</option>"; | |
}; | |
}; | |
if (!$dots) | |
echo "<option $f value=\"\">...</option>"; | |
}; | |
function Dtbox($name,$value,$size=29) { | |
if (is_numeric($value)) { | |
$value=@date("d-m-Y",$value); | |
}; | |
$D=substr($value,0,2); | |
$M=substr($value,3,2); | |
$Y=substr($value,6,4); | |
$name=trim($name); | |
?> | |
<INPUT type="text" name="dtD_<?echo $name;?>" size=1 maxlength=2 value="<?echo $D;?>">.<INPUT type="text" name="dtM_<?echo $name;?>" size=1 maxlength=2 value="<?echo $M;?>">. <INPUT type="text" name="dtY_<? echo $name;?>" size=2 maxlength=4 value="<?echo $Y;?>">. | |
<input type=hidden name=dtX_<? echo $name;?>> | |
<input type=button value="..." OnClick="popUpCalendar(this, dtX_<? echo $name;?>, 'dd/mm/yyyy');" > | |
<? | |
// echo "<INPUT TYPE=\"text\" size=\"$size\" NAME=\"$name\" VALUE=\"$value\" class=login>"; | |
}; | |
function CheckACL($aclname) { | |
global $userdata; | |
$FIU=get_dataS("SELECT permission from acls LEFT join acl on acl.aclid=acls.id WHERE acl_name='$aclname' and uid='{$userdata['id']}';"); | |
$result=(int)$FIU['0']['permission']; | |
return $result; | |
} | |
function CheckDBACL($aclname) { | |
global $userdata; | |
$dbacl=get_dataS(" select n_databases.* from dbacl LEFT JOIN n_databases ON dbacl.aclid=n_databases.id | |
where n_databases.id='$aclname' and uid='{$userdata['id']}';"); | |
if ($dbacl[0]) { return 1; }; | |
return 0; | |
} | |
function tbox($fname,$value="",$params="") { | |
echo "<INPUT TYPE=text NAME=db_{$fname} VALUE=\"".htmlspecialchars($value)."\" $params>"; | |
}; | |
function label($fname) { | |
global $field_defs; | |
echo $field_defs[$fname]['title']; | |
}; | |
function Mod17_Message($msg) { | |
echo '<hr size=1 color=red><TABLE> | |
<TR> | |
<TD><!--icon--></TD> | |
<TD><font color=red>'.$msg.'</TD> | |
</TR> | |
</TABLE> | |
<hr size=1 color=red>'; | |
}; | |
//////////////////// RECORD LOCKING | |
$EDITLOCK_CHECK_DELAY=15; // seconds | |
function editlockUpdateIframe($table_name,$primary_key) { | |
echo "<IFRAME frameborder=1 width=1 height=1 name=editlock_upd SRC=\"update_editlock.php?tn=$table_name&primary_key=$primary_key\"></IFRAME>"; | |
}; | |
function editlockUnlockWaitIframe($table_name,$primary_key) { | |
echo "<IFRAME frameborder=0 width=1 height=1 name=editlock_upd SRC=\"waitfor_unlock.php?tn=$table_name&primary_key=$primary_key\"></IFRAME>"; | |
}; | |
function editlockExists($table_name,$primary_key) { | |
$editlock=get_data("SELECT * from n_editlocks WHERE lock_table='$table_name' and lock_record='$primary_key';"); | |
if ($editlock) return $editlock[0]; | |
else return false; | |
}; | |
function clearLostEditLocks() { | |
global $NOW; | |
$lost_lock_time=$NOW-150; | |
get_data("DELETE FROM n_editlocks WHERE lock_ptime<'$lost_lock_time';"); | |
}; | |
function delEditLock($table_name,$primary_key) { | |
get_data("DELETE FROM n_editlocks WHERE lock_table='$table_name' and lock_record='$primary_key';"); | |
} | |
function delEditLockById($editlock_id) { | |
get_data("DELETE FROM n_editlocks WHERE id='$editlock_id';"); | |
} | |
function delEditLockByUser($user_id) { | |
global $SYSDBNAMES; | |
foreach($SYSDBNAMES as $dbrow) { | |
get_data("DELETE FROM `{$dbrow}`.n_editlocks WHERE lock_user='$user_id';"); | |
}; | |
} | |
function setEditLock($table_name,$primary_key) { | |
global $userdata; | |
$editlock=get_data("SELECT * from n_editlocks WHERE lock_table='$table_name' and lock_record='$primary_key';"); | |
if ($editlock) $editlock=$editlock[0]; | |
else $editlock=false; | |
$old_editlock=""; | |
if ($editlock) { | |
// echo "Record locked by {$editlock['lock_user']} , cannot edit"; | |
return array(0,$editlock); | |
} else { | |
// echo "Locking record for editing"; | |
$userid=$userdata['id']; | |
$timestamp=time(); | |
get_data("INSERT into n_editlocks (lock_table,lock_record,lock_user,lock_time,lock_ptime) VALUES ('$table_name','$primary_key','{$userid}','$timestamp','$timestamp');"); | |
$editlock=get_data("SELECT * from n_editlocks WHERE lock_table='$table_name' and lock_record='$primary_key';"); | |
$editlock=$editlock[0]['editlock']; | |
return array(1,$editlock); | |
}; | |
}; | |
/* | |
list($result,$editlock_val)=setEditLock('titri',$_GET['edit']); | |
if ($result==0) { | |
list($userid,$timestamp)=explode(";",$editlock_val); | |
echo "<meta http-equiv=\"Refresh\" content=\"3\">"; | |
echo "Ierakstu šobrid redige cits lietotajs, ludzu meginiet velak, vai uzgaidiet. Sistema automatiski meginas pieklut ierakstam reizi 5 sekundes.<Br>".rand(1,999); | |
?/> | |
<TABLE> | |
<TR> | |
<TD>Pašlaik redige:</TD> | |
<TD></?=$userid;?/></TD> | |
</TR> | |
<TR> | |
<TD>Pedeja aktivitate pirms:</TD> | |
<TD></?=(time()-$timestamp)?/> sec.</TD> | |
</TR> | |
</TABLE> | |
<? | |
} | |
if ($result==1) { | |
if ($editlock_val) { echo "Ierakstu bija noblokejis cits lietotajs, tacu pedejas aktivitates intervals bija parak liels. Ieraksts atblokets un noblokets tekošajai sesijai"; } | |
editlockUpdateIframe('titri',$_GET['edit']); | |
*/ | |
///////////////// END RECORD LOCKING | |
function atskr_tc($timecode) { | |
$timecode=(int)$timecode; | |
return gmdate("H:i:s",$timecode); // DST ?? // +(3600*22) | |
}; | |
function saskr_tc($tc_str) { | |
if (!$tc_str) return 0; | |
$tc_srl=strtotime($tc_str); | |
if ($tc_srl==-1) return 0; | |
$tc_srl=(($tc_srl+(3600*3))%86400); | |
return $tc_srl; | |
} | |
######### changelog | |
function X_Print_Table($data,$table_name,$tag_params="",$href_string="") { | |
global $all_field_defs; | |
$field_defs=$all_field_defs[$table_name]; | |
echo "<table $tag_params>"; | |
### Print header | |
echo "<tr>"; | |
foreach($field_defs as $key=>$element) { | |
echo "<th>{$element['title']}</td>"; | |
}; | |
echo "</tr>"; | |
### print data | |
foreach ($data as $row) { | |
echo "<tr>"; | |
foreach($field_defs as $key=>$element) { | |
$value=$row[$key]; | |
if ($element['type']=='datetime') { | |
$value=date("Y.m.d H:i:s",$row[$key]); | |
}; | |
if ($element['type']=='datetimenl') { | |
$value=date("Y.m.d",$row[$key])."<br>".date("H:i:s",$row[$key]); | |
}; | |
if ($href_string) { | |
$href=sprintf($href_string,$row['id']); | |
}; | |
if ($href) { | |
echo "<td><A target=_parent HREF=\"$href\">$value</A></td>"; | |
} else { | |
echo "<td>$value</td>"; | |
}; | |
} | |
echo "</tr>"; | |
}; | |
echo "</table>"; | |
}; | |
function ShowChangelog($lapa_id) { | |
$data=get_data("SELECT id,(Select CONCAT(first_name,' ',last_name) from lietotaji where lietotaji.id=n_changelog.id_lietotajs) as lietotajs,shadow_id,time,pcname,changed from n_changelog where id_nlapa='$lapa_id' order by time desc;"); | |
if (!$data[0]) return; | |
X_Print_Table($data,'changelog',"class=tabula_sodienas width=\"100%\"","index.php?s=17&s2=17&s3=2&shadow=%s"); | |
}; | |
function ShowChangelogIFRAME($lapa_id,$x="85%",$y=138) { | |
?> | |
<SCRIPT LANGUAGE="JavaScript"> | |
<!-- | |
function show_chlog() { | |
if (changelog.innerHTML) { | |
changelog.innerHTML=''; | |
} else { | |
changelog.innerHTML='<IFRAME style="border:1px solid gray;"src="changelog.php?id=<?=$lapa_id;?>" frameborder=0 width="<?=$x;?>" height=<?=$y;?>></IFRAME>'; | |
} | |
}; | |
//--> | |
</SCRIPT> | |
<? | |
echo "<span id=ch_title OnClick=\"show_chlog();\" style=\"cursor:hand;\"><B>Izmaiņu žurnāls...</B></span><br>"; | |
?> | |
<span id=changelog></span> | |
<? | |
}; | |
// Function highlights $words in $str with the specified $color | |
function highlight_words($str, $words, $color = 'yellow') { | |
if(is_array($words)) { | |
foreach($words as $k => $word) { | |
$pattern[$k] = "/($word)/is"; | |
$replace[$k] = '<font style="background-color:'.$color.';"><b>\\1</b></font>'; | |
} | |
} | |
else { | |
$pattern = "/($words)/is"; | |
$replace = '<font style="background-color:'.$color.';"><b>\\1</b></font>'; | |
} | |
//print_r($pattern); | |
//print_r($replace); | |
return preg_replace($pattern,$replace,$str); | |
} | |
function PMA_splitSqlFile(&$ret, $sql, $release) | |
{ | |
// do not trim, see bug #1030644 | |
//$sql = trim($sql); | |
$sql = rtrim($sql, "\n\r"); | |
$sql_len = strlen($sql); | |
$char = ''; | |
$string_start = ''; | |
$in_string = FALSE; | |
$nothing = TRUE; | |
$time0 = time(); | |
for ($i = 0; $i < $sql_len; ++$i) { | |
$char = $sql[$i]; | |
// We are in a string, check for not escaped end of strings except for | |
// backquotes that can't be escaped | |
if ($in_string) { | |
for (;;) { | |
$i = strpos($sql, $string_start, $i); | |
// No end of string found -> add the current substring to the | |
// returned array | |
if (!$i) { | |
$ret[] = array('query' => $sql, 'empty' => $nothing); | |
return TRUE; | |
} | |
// Backquotes or no backslashes before quotes: it's indeed the | |
// end of the string -> exit the loop | |
else if ($string_start == '`' || $sql[$i-1] != '\\') { | |
$string_start = ''; | |
$in_string = FALSE; | |
break; | |
} | |
// one or more Backslashes before the presumed end of string... | |
else { | |
// ... first checks for escaped backslashes | |
$j = 2; | |
$escaped_backslash = FALSE; | |
while ($i-$j > 0 && $sql[$i-$j] == '\\') { | |
$escaped_backslash = !$escaped_backslash; | |
$j++; | |
} | |
// ... if escaped backslashes: it's really the end of the | |
// string -> exit the loop | |
if ($escaped_backslash) { | |
$string_start = ''; | |
$in_string = FALSE; | |
break; | |
} | |
// ... else loop | |
else { | |
$i++; | |
} | |
} // end if...elseif...else | |
} // end for | |
} // end if (in string) | |
// lets skip comments (/*, -- and #) | |
else if (($char == '-' && $sql_len > $i + 2 && $sql[$i + 1] == '-' && $sql[$i + 2] <= ' ') || $char == '#' || ($char == '/' && $sql_len > $i + 1 && $sql[$i + 1] == '*')) { | |
$i = strpos($sql, $char == '/' ? '*/' : "\n", $i); | |
// didn't we hit end of string? | |
if ($i === FALSE) { | |
break; | |
} | |
if ($char == '/') $i++; | |
} | |
// We are not in a string, first check for delimiter... | |
else if ($char == ';') { | |
// if delimiter found, add the parsed part to the returned array | |
$ret[] = array('query' => substr($sql, 0, $i), 'empty' => $nothing); | |
$nothing = TRUE; | |
$sql = ltrim(substr($sql, min($i + 1, $sql_len))); | |
$sql_len = strlen($sql); | |
if ($sql_len) { | |
$i = -1; | |
} else { | |
// The submited statement(s) end(s) here | |
return TRUE; | |
} | |
} // end else if (is delimiter) | |
// ... then check for start of a string,... | |
else if (($char == '"') || ($char == '\'') || ($char == '`')) { | |
$in_string = TRUE; | |
$nothing = FALSE; | |
$string_start = $char; | |
} // end else if (is start of string) | |
elseif ($nothing) { | |
$nothing = FALSE; | |
} | |
// loic1: send a fake header each 30 sec. to bypass browser timeout | |
$time1 = time(); | |
if ($time1 >= $time0 + 30) { | |
$time0 = $time1; | |
header('X-pmaPing: Pong'); | |
} // end if | |
} // end for | |
// add any rest to the returned array | |
if (!empty($sql) && preg_match('@[^[:space:]]+@', $sql)) { | |
$ret[] = array('query' => $sql, 'empty' => $nothing); | |
} | |
return TRUE; | |
} // end of the 'PMA_splitSqlFile()' function | |
function JavaRedirect($URL) { | |
?> | |
<SCRIPT LANGUAGE="JavaScript"> | |
<!-- | |
location='<?=$URL;?>'; | |
//--> | |
</SCRIPT> | |
<? | |
} | |
function JavaAlert($URL) { | |
?> | |
<SCRIPT LANGUAGE="JavaScript"> | |
<!-- | |
alert('<?=$URL;?>'); | |
//--> | |
</SCRIPT> | |
<? | |
} | |
function calc_lapas_limit($total_count) { | |
global $rpp,$p,$lapu_skaits; | |
$rpp=$_GET[rpp]; | |
$p=$_GET[p]; | |
if (!$rpp) $rpp=108; | |
if (!$p) $p=1; | |
$limit_from=($rpp*($p-1)); | |
$limit_to=$rpp; | |
$lapu_skaits=ceil($total_count/$rpp); | |
return " limit $limit_from,$limit_to"; | |
}; | |
function draw_lapas($lapu_skaits,$rpp,$p) { | |
//global $SELFLPP; | |
list($SELFLPP,$dispose)=explode('&cut_here',$_SERVER['REQUEST_URI']); | |
if ($lapu_skaits>1) { | |
if ($p>1) { | |
$left_arrow="<A HREF=\"$SELF&p=".($p-1)."&rpp=$rpp&sb={$_GET[sb]}&so={$_GET[so]}\">«</A>"; } else { | |
$left_arrow=""; | |
}; | |
if ($p<$lapu_skaits) { | |
$right_arrow="<A HREF=\"$SELF&p=".($p+1)."&rpp=$rpp&sb={$_GET[sb]}&so={$_GET[so]}\">»</A>"; } else { | |
$right_arrow=""; | |
}; | |
echo "Lapas: $left_arrow <B>"; | |
for($i=0;$i<$lapu_skaits;$i++) { | |
$lnr=($i+1); | |
//$lnr="<A HREF=\"$SELF&p=".($i+1)."&rpp=$rpp\">".($i+1)."</A>"; | |
if ($lnr==$p) { | |
echo "<A HREF=\"$SELFLPP&cut_here&p=$lnr&rpp=$rpp&sort={$_GET[sort]}&sort_d={$_GET[sort_d]}\"><FONT COLOR=\"#CC0000\">$lnr</FONT> </A>"; | |
} else { | |
echo "<A HREF=\"$SELFLPP&cut_here&p=$lnr&rpp=$rpp&sort={$_GET[sort]}&sort_d={$_GET[sort_d]}\">$lnr </A>"; | |
}; | |
} | |
echo "</B> $right_arrow"; | |
} | |
} | |
function mydump($var) { | |
$ret = '<pre style="text-align: left; background-color: #fff; color: #000; border: 1px solid #c00; font-size: 10pt; font-family: consolas, courier new, monospace;">'; | |
$ret .= htmlspecialchars(print_r($var, true)); | |
$ret .= '</pre>'; | |
return $ret; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment