////////////////////////////////////////////////////////////////////
// Common Functions Module //
// Author: Alex Kvak //
////////////////////////////////////////////////////////////////////
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// require_once "/var/www/html/includes/libraries/vendor/autoload.php";
function print__($v, $m,$a,&$r) {
//$row = array();
$row = "";
for ($i=1;$i<=$m;$i++)
$row .= $a[$v[$i]]."%";
$r[] = "%".trim($row);
}
function arrangements(&$v,$srcM,$k, $m, $s,$a,&$r) {
if (($m == 0)){
print__($v,$srcM,$a,$r);
}
else {
for ($i=1;$i<=$k;$i++) {
if (!isset($s[$i])) {
$v[$m] = $i;
$ss = $s;
$ss[$i] = 1;
arrangements($v,$srcM, $k, $m-1, $ss,$a,$r);
//print_r($ss);
}
}
}
}
function highlight($str,$hl,$field="q") {
if ( ((count($hl))==0) || !isset($hl[$field])) return $str;
$f = $hl[$field];
if (is_array($f)) {
$r = array();
foreach($f as $k=>$v) {
$r[] = '\\1';
$f[$k] = "/(".$v.")/iu";
}
} else { if ($f == "") return $str; $f = "/(".$f.")/iu"; $r = '\\1'; }
//echo "replace: "; var_dump($f); echo " "; var_dump($r); echo " ".$str."
";
return preg_replace($f,$r,$str);
}
function aks_RedirectJavaScript($URL) {
die( "" );
}
//////////////////////////////////////////////////////////////////////////////////////////
/*
Prints alert-window with message $str
*/
function aks_alert($str)
{
echo '';
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
/*
Prints alert-window with message $str
*/
function aks_confirm($str,$action_ja,$action_nein)
{
echo '';
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
/*
Trimming the string str. Set length to size and cut to nearest space-symbol
*/
function aks_trim_string($str,$size,$leaveTags="
")
{
$ret_str = $str;
$ret_str = strip_tags($ret_str,$leaveTags);
mb_internal_encoding('UTF-8');
if (mb_strlen($ret_str) > $size)
{
$ret_str = mb_substr($ret_str,0,$size);
$pos = mb_strrpos($ret_str," ");
$ret_str = mb_substr($ret_str,0,$pos);
$pos1 = mb_strrpos($ret_str,'>');
$pos2 = mb_strrpos($ret_str,'<');
if ($pos2 > $pos1)
{
$pos = mb_strpos($ret_str, ">", $pos2);
$str_ = mb_substr($ret_str,$pos2,$pos-$pos2+1);
if (mb_strpos($str_,"") === false)
$ret_str = mb_substr($ret_str,0,$pos2);
else
$ret_str = mb_substr($ret_str,0,$pos+1);
}
// $ret_str = rtrim($ret_str," .");
$ret_str .= "...";
}
return $ret_str;
}
function aks_smart_trim_string($str,$size=50,$hl="",$field='q') {
$ret_str = preg_replace('/
/','
',strip_tags($str,"
"));
// $ret_str = $str;
if ($hl==="") return $ret_str;
mb_regex_encoding('UTF-8');
mb_internal_encoding('UTF-8');
if (!is_array($hl)) {
if (mb_strlen($ret_str) > $size) {
$ret_str = mb_substr($ret_str,0,$size+1);
$pos = mb_strrpos($ret_str," ");
$ret_str = mb_substr($ret_str,0,$pos);
$ret_str = rtrim($ret_str," .");
$ret_str .= "...";
}
} elseif (strlen($ret_str) > $size) {
$replacements = array();
$ret_str = str_replace(array("\n","\r","\t"),array('','',''),$ret_str);
// $ret_str = str_replace("
","\n",$ret_str);
// header('Content-type: text/html; charset=UTF-8');
// echo '
'; $search_string = mb_strtolower($ret_str); // echo $search_string . '
'; foreach($hl[$field] as $v) { $start = 0; // echo 'Searching: '.$v."\n"; while( ($pos = mb_strpos($search_string,$v,$start)) !== FALSE) { $start = $pos + mb_strlen($v); $replacements[$pos] = mb_substr($ret_str,$pos,mb_strlen($v)); } // preg_match_all( // '/('.preg_quote($v).')/iu', // $ret_str, // $arr, // PREG_OFFSET_CAPTURE, // 0 // ); // if (count($arr[1])) // foreach($arr[1] as $subarr) // $replacements[$subarr[1]] = $subarr[0]; } $offsets = array_keys($replacements); array_multisort($offsets,$replacements); // echo $ret_str; /*var_dump($new_str); echo "\n";*/ print_r($offsets); print_r($replacements); die; // echo ''; echo mb_detect_encoding($ret_str); echo mb_strlen($ret_str,'UTF-8') . "\n"; // die; $new_str = ''; $step = intval($size/(count($offsets)+1)); $step = min($step,30); // echo $step; $currentPosition = -1; for($i=0;$i= $offsets[$i]) continue; // if (!$i && ($offsets[$i] > $step)) $new_str = '...'; // начало строки // if ( isset($offsets[$i+1]) && ( ($offsets[$i] + mb_strlen($replacements[$i]) + $step) >= $offsets[$i+1] )) $s = (($offsets[$i]-$step)>0)?($offsets[$i]-$step):0; if ($currentPosition >= $s) continue; // echo $currentPosition . ':' . mb_substr($ret_str,$currentPosition,10) . "\n"; $prev_str = (mb_substr($ret_str,$s,$offsets[$i]-$s)); $space_rpos = mb_strpos($prev_str,' '); if ($space_rpos < 0) $space_rpos = 0; // echo $offsets[$i] . ':' . $s . ', ' . $prev_str . ';' . $space_rpos . ', ' . (mb_strlen($prev_str)-$space_rpos) . ', ' . // mb_substr($prev_str,$space_rpos,mb_strlen($prev_str)-$space_rpos) . "\n"; $next_str = (mb_substr($ret_str,$offsets[$i]+mb_strlen($replacements[$i]),$step)); // var_dump("\n",$replacements[$i],$offsets[$i],$offsets[$i]+$step,$next_str); die; $space_pos = mb_strrpos($next_str,' '); if ($space_pos < 0) $space_pos = $step; // echo $offsets[$i] . ':' . $s . ', ' . $next_str . ';' . $space_pos . ', ' . $offsets[$i]+mb_strlen($replacements[$i]) . ', ' . // mb_substr($next_str,0,$space_pos) . "\n"; if ($space_rpos || (!$i && $offsets[$i])) $new_str .= ' ...'; // echo "Adding: \n" . mb_substr($prev_str,$space_rpos,mb_strlen($prev_str)-$space_rpos) . // ' ' . $replacements[$i] . ' ' // . mb_substr($next_str,0,$space_pos); $new_str .= mb_substr($prev_str,$space_rpos,mb_strlen($prev_str)-$space_rpos) . '' . $replacements[$i] . '' . mb_substr($next_str,0,$space_pos) ; $currentPosition = $offsets[$i] + mb_strlen($replacements[$i]) + $space_pos; // echo $currentPosition . "\n"; // if ( isset($offsets[$i+1]) && ( ($offsets[$i] + mb_strlen($replacements[$i],'UTF-8') + $step) >= $offsets[$i+1] )) // $new_str .= ''; // else // $new_str .= '...'; } // echo "Result \n"; $ret_str = highlight(str_replace("\n",'
',$new_str),$hl); // echo $new_str; // die; // \\1 //var_dump($hl); // $pos = array(); // foreach($hl as $h) { // $arr = preg_split("/".preg_quote($h)."/", // $ret_str,-1,PREG_SPLIT_OFFSET_CAPTURE); //var_dump($arr); echo '
'; // $pos[$h] = array(); // foreach($arr as $v) // /*if ($v[1]!=0)*/ $pos[$h][] = $v[1]; // } // var_dump($pos); //die(); /* $ret_str = substr($ret_str,0,$size); $pos = strrpos($ret_str," "); $ret_str = substr($ret_str,0,$pos); $ret_str = rtrim($ret_str," ."); $ret_str .= "...";*/ } else $ret_str = highlight($ret_str,$hl,$field); return $ret_str; } function aks_upload_video($img, &$errorLine) { if ( (strlen(trim($img)) == 0) ) return false; global $_FILES; global $abpath_video; global $abpath_videothumbs; global $img_sizes_for_video; global $abpath_videothumbs; $link = aks_link(); $img1_name = $_FILES[$img]['name']; $img1_type = $_FILES[$img]['type']; $log = ""; if ($img1_name == "") { $errorLine = 133; return false; } //Checks if file is an image $uploaddir = $abpath_video; $pos = strrpos($img1_name,"."); $extension = substr($img1_name,$pos); $new_imgname = generateFileID($uploaddir,$extension); $image = $uploaddir.$new_imgname; global $LANG; if (!move_uploaded_file($_FILES[$img]['tmp_name'], $image)) { $errorLine = 147; return false; } chmod($image,0644); @$ffmpegObj = new ffmpeg_movie($image); if (!$ffmpegObj || !$ffmpegObj->hasVideo() /*|| ($ffmpegObj->getVideoCodec()!= 'flv')*/) { @unlink($image); $errorLine = 154; return false; } if (FRAMES_FOR_PREVIEW) { $tmp = ($ffmpegObj->getFrameCount() / (FRAMES_FOR_PREVIEW + 2)); // echo "Frames: ".$ffmpegObj->getFrameCount()."
Step: $tmp
"; $w = $img_sizes_for_video['width']; $h = $img_sizes_for_video['height']; $counter = 0; for ($i=$tmp,$j=0;$jgetFrame($i))) continue; // $h = intval($preview->getHeight() * $w/$preview->getWidth()); $image = $preview->toGDImage(); $new_image = imagecreatetruecolor($w,$h); imagecopyresized($new_image,$image,0,0,0,0,$w,$h,$preview->getWidth(),$preview->getHeight()); imagejpeg($new_image,$abpath_videothumbs.(++$counter)."_".$new_imgname.".jpg"); imagedestroy($image); imagedestroy($new_image); unset($preview); chmod($abpath_videothumbs.($counter)."_".$new_imgname.".jpg",0655); } if (is_file($abpath_videothumbs."1_".$new_imgname.".jpg")) { copy($abpath_videothumbs."1_".$new_imgname.".jpg", $abpath_videothumbs.$new_imgname.".jpg"); chmod($abpath_videothumbs.$new_imgname.".jpg",0655); } } return $new_imgname; } ///////////////////////////////////////////////////////////////////////////// /* Uploads an image, specified in $_FILES array by index $img @param img name of the element of array $_FILES @param thumb true wenn thumb notig ist @param waterwark true wenn Watermark einfuegen soll @param watermarkFileName Name der Datei mit Watermark @param xWM, yWM offset from right-bottom corner of source image @param WMtype type on the image file (PNG, JPG, GIF) @return bool true if success, otherwise - false */ function aks_upload_image($img,$thumb=true,$watermark=false,$watermarkFileName="", $xWM=0, $yWM=0, $WMopacity="60") { if ( (strlen(trim($img)) == 0) ) return false; global $_FILES; global $uppath; global $img_sizes; global $kein_strikt_breite; $link = aks_link(); $files = $_FILES[$img]['name']; $tmp_names = $_FILES[$img]['tmp_name']; $types = $_FILES[$img]['type']; if (!is_array($files)) { $files = array($files); $types = array($types); $tmp_names = array($tmp_names); } $new_imgnames = array(); foreach($files as $k=>$file) { $img1_name = $file; if ($img1_name == "") continue; $img1_type = $types[$k]; $sizelim = "no"; //Do you want size limit, yes or no $size = "2000000"; //What do you want size limited to be if there is one //all image types to upload $cert1 = "image/pjpeg"; //Jpeg type 1 $cert2 = "image/jpeg"; //Jpeg type 2 $cert3 = "image/gif"; //GIF $log = ""; //Checks if file is an image if (($img1_type == $cert1) || ($img1_type == $cert2) || ($img1_type == $cert3)) { $uploaddir = $uppath; $pos = strrpos($img1_name,"."); // $filename = translit(substr($img1_name,0,$pos)); $extension = substr($img1_name,$pos); //$new_imgname = date("dmYHis").strtolower($filename.$extension); $new_imgname = generateFileID($uploaddir."gross/",$extension); $image = $uploaddir.$new_imgname.".tmp"; global $LANG; if (move_uploaded_file($tmp_names[$k], $image)) $log = $LANG["image_upload_successfull"]; else { die(); return false; } require_once LIBPATH."SmartImage/SmartImage.class.php"; if ($thumb) { // Start! $img = new SmartImage($image); // Resize and save to file $img->resize($img_sizes["width"]["klein"], $img_sizes["height"]["klein"], isset($img_sizes["cut"]["klein"]) && $img_sizes["cut"]["klein"]); $img->saveImage($uploaddir."klein/".$new_imgname,IMAGE_QUALITY); chmod($uploaddir."klein/".$new_imgname,0644); $img->close(); unset($img); } if (isset($img_sizes["width"]["mitte"])) { // Start! $img = new SmartImage($image); // Resize and save to file $img->resize($img_sizes["width"]["mitte"], $img_sizes["height"]["mitte"], isset($img_sizes["cut"]["mitte"]) && $img_sizes["cut"]["mitte"]); $img->saveImage($uploaddir."mitte/".$new_imgname,IMAGE_QUALITY); chmod($uploaddir."mitte/".$new_imgname,0644); $img->close(); unset($img); } // Start! $img = new SmartImage($image); // Resize and save to file if ( (($img->getWidth() > $img_sizes["width"]["gross"]) && $img_sizes["width"]["gross"]) || (($img->getHeight() > $img_sizes["height"]["gross"]) && $img_sizes["height"]["gross"] ) ) $img->resize($img_sizes["width"]["gross"], $img_sizes["height"]["gross"], isset($img_sizes["cut"]["gross"]) && $img_sizes["cut"]["gross"]); if ($watermark) { $horizontal = ($img->getWidth()>$img->getHeight()); if (is_array($xWM)) $xWM = $xWM[!$horizontal]; if (is_array($yWM)) $yWM = $yWM[!$horizontal]; if (is_array($watermarkFileName)) $watermarkFileName = $watermarkFileName[!$horizontal]; $wm_img = new SmartImage($watermarkFileName); if ($xWM === 'center') $xWM = intval(($img->getWidth() - $wm_img->getWidth()) / 2); if ($yWM === 'center') $yWM = intval(($img->getHeight() - $wm_img->getHeight()) / 2); if ($xWM<0) $xWM = $img->getWidth() - $wm_img->getWidth() + $xWM; if ($yWM<0) $yWM = $img->getHeight()+ $wm_img->getHeight() + $yWM; $img->addWaterMarkImage( $watermarkFileName, $WMopacity, $xWM, $yWM); } $img->saveImage($uploaddir."gross/".$new_imgname,IMAGE_QUALITY); chmod($uploaddir."gross/".$new_imgname,0644); $img->close(); unset($img); unlink($image); $new_imgnames[] = $new_imgname; } else { if ($log != "") aks_alert($log); } } return $new_imgnames; } // end of aks_upload_image /////////////////////////////////////////////////////////////////////////////// function generateFileID($prefix,$extension) { $extension = strtolower($extension); while (1) { $str = strtolower(substr( str_replace("=","",base64_encode(mt_rand()*1000+1)),0, 100)); if (!file_exists($prefix."/".$str.$extension)) { if ($f = fopen($prefix."/".$str.$extension,"w+")) { fclose($f); unlink($prefix."/".$str.$extension); return $str.$extension; } } } } ///////////////////////////////////////////////////////////////////////// // checks if $val is in array $arr function aks_is_in_array($arr,$val) { for($i=0;$i =0; $i-- ) { if ( $price[$i] == "," ) break; else $res = $price[$i].$res; } $res = ",".$res; $i--; $digitCounter = 0; for( ; $i>=0; $i-- ) { $digitCounter++; $res = $price[$i].$res; if ( $digitCounter == 3 && $i != 0 ) { $res = ".".$res; $digitCounter = 0; } } return ($withPrecision)?$res:preg_replace('/,\d+$/','',$res); } function arrRemoveEmpty(&$array,&$array2 = null,$bindeworter=array()) { //for($i=0;$i $v) { if ( isset($array[$i]) && ((strlen(trim($array[$i]))<=3) || in_array(trim($array[$i]),$bindeworter))) { unset ($array[$i]); if (!is_null($array2)) unset ($array2[$i]); } } } function mailClient($mail_an, $subject, $message, $mail_from, $enctype = 'text/html', $attachments = []) { // include_once 'includes/libraries/phpmailer/class.phpmailer.php'; // require_once "/var/www/html/includes/libraries/vendor/autoload.php"; require '/var/www/html/includes/libraries/vendor/phpmailer/phpmailer/src/Exception.php'; require '/var/www/html/includes/libraries/vendor/phpmailer/phpmailer/src/PHPMailer.php'; require '/var/www/html/includes/libraries/vendor/phpmailer/phpmailer/src/SMTP.php'; $mail = new PHPMailer(TRUE); $mail->SetLanguage('de','includes/libraries/phpmailer/language/'); $mail->CharSet = 'UTF-8'; $mail->From = $mail_from; $mail->ContentType = $enctype; // $mail->FromName = '';//"Сайт ".strtoupper($_SERVER['SERVER_NAME']); // $mail->Hostname = $_SERVER['SERVER_NAME']; // $mail->Mailer = 'mail'; $mail->IsSMTP(); /* Set the mail sender. */ $mail->Host = 'smtp.office365.com'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'o.lewa@novobit.eu'; // SMTP username $mail->Password = 'Oli2064*'; // SMTP password $mail->SMTPSecure = 'STARTTLS'; $mail->Port = 587; // TCP port to connect to $mail->setFrom('o.lewa@novobit.eu'); $mail->AddAddress ( $mail_an ); $mail->Subject = $subject; $mail->Body = $message; foreach ($attachments as $attachment) { $mail->AddAttachment($attachment['path'], $attachment['name']); } $result = $mail->send(); if ($mail->IsError()) { echo ''; echo ''; return false; die; } return $result; } //////////////////////////////////////////////////////////////////// // FileSystem Functions Module // // Author: Alex Kvak // //////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// /* Returnsthe relative path to file/dir @param dir_path Path to dir @return nothing */ function aks_unrealpath($dir_path) { $dir_path = trim(str_replace(str_replace("\\","/",$_SERVER["DOCUMENT_ROOT"]),"",str_replace("\\","/",$dir_path)),"/"); return "http://".$_SERVER["HTTP_HOST"]."/".$dir_path; } ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// /* Delete recursively all contents of folder dir @param source Source folder name @param dest Destination folder name @param slash Slash character in current OS @return nothing */ function aks_unlink_file($dir,$slash = '/') { $dir = rtrim($dir,$slash).$slash; chdir($dir); if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if (($file != ".") && ($file != "..")) { if (is_dir($file)) { aks_unlink_file($dir.$slash.$file); chdir($dir); rmdir($file); } else unlink($file); } } closedir($handle); } } ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// /* Copies recursively all contents of folder dir @param source Source folder name @param dest Destination folder name @param slash Slash character in current OS @return nothing */ function aks_copy_dir($source,$dest,$slash = '/') { $source = rtrim($source,$slash); $dest = rtrim($dest,$slash); chdir($source); if ($handle = opendir($source)) { while (false !== ($file = readdir($handle))) { if (($file != ".") && ($file != "..")) { if (is_dir($file)) { mkdir($dest.$slash.$file); aks_copy_dir($source.$slash.$file,$dest.$slash.$file,$slash); chdir($source); } else { copy($source.$slash.$file,$dest.$slash.$file); } } } closedir($handle); } } ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// /* Reads the contents of folder @param source Source folder name @param mark Array of extensions @param slash Slash character in current OS @return array of names */ function aksReadDir($source,$mask=array(""),$slash="/") { if (strlen(trim($source)) == 0) return array(); $source = rtrim($source,$slash); $return = array(); if (!is_array($mask)) $mask = array($mask); if ($slash == "") $slash = "/"; if ($handle = opendir($source)) { while (false !== ($file = readdir($handle))) { if (($file != ".") && ($file != "..")) { if (is_dir($file)) continue; if ($mask[0] != "*") { $pinfo = pathinfo($source.$slash.$file); if (!in_array($pinfo["extension"],$mask)) continue; } $return[] = $file; } } closedir($handle); } return $return; } ///////////////////////////////////////////////////////////////// ?> //////////////////////////////////////////////////////////////////// // SQL Functions Module // // Author: Alex Kvak // //////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /* Executes query and prints the error message into document */ function execSQL($sql,$msg = "") { global $link; $res = mysqli_query($link,$sql); if (!$res) { $msg = "SQL Fehler $msg! \nSQL: $sql\n".mysqli_error($link); error_log($msg); } return $res; } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /* Connecting to DB */ function aks_link() { global $host; global $user; global $pass; global $dbase; $link = mysqli_connect($host, $user, $pass) or die("Could not connect to $host"); mysqli_select_db($link,$dbase) or die("Could not select database on $host"); $encoding = (defined('MYSQL_ENCODING')) ? MYSQL_ENCODING : 'utf8'; mysqli_query($link,"SET CHARACTER SET '$encoding'"); mysqli_query($link,"SET NAMES '$encoding'"); mysqli_query($link,"SET lc_time_names = 'de_DE'"); return $link; } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /* Executes INSERT command @param tabelle table for updating @param fields an array of fields to update @param values an array of values for fields @return bool/int id of a new record if success, otherwise - false */ function aks_SQL_insert($tabelle,$fields,$values) { if ( !is_array($fields) || !is_array($values) || (sizeof($fields) == 0) || (sizeof($values) == 0) || (strlen(trim($tabelle)) == 0) || (sizeof($fields) != sizeof($values)) ) return false; $link = aks_link(); global $cr; global $DEBUG; global $quotes; $add_str = ""; $values_str = ""; $names_str = ""; $sql = "insert into $tabelle"; for($i=0;$i ",$values[$i]); if ($quotes) $values[$i] = mysql_escape_string($values[$i]); $values_str .= $add_str."'".$values[$i]."'"; $add_str = ", "; } $sql .= "($names_str) values ($values_str)"; if (isset($DEBUG) && $DEBUG) echo "INSERT: $sql"; $res = mysqli_query($sql); if ($res == 0) { aks_alert("Error in aks_SQL_insert!"); return false; } else { global $dbase; $fields = mysql_list_fields($dbase, $tabelle, $link); $id_fld = mysql_field_name($fields, 0); $sql = "select MAX($id_fld) from $tabelle"; $res = mysql_query($sql); $new_id = mysql_result($res,0,0); if (isset($DEBUG) && $DEBUG) echo "new_id: $new_id
"; mysqli_free_result($res); return $new_id; } } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /* Executes UPDATE command @param tabelle table for updating @param fields array of fields to update @param values array of values for fields @param id where instruction. STRING! e.g. " art_id=10" @return bool true if success, otherwise - false */ function aks_SQL_update($tabelle,$fields,$values,$id) { if ( !is_array($fields) || !is_array($values) || (sizeof($fields) == 0) || (sizeof($values) == 0) || (strlen(trim($tabelle)) == 0) || (sizeof($fields) != sizeof($values)) || (strlen(trim($id)) == 0) ) return false; global $cr; global $quotes; $link = aks_link(); $add_str = ""; $sql = "UPDATE $tabelle SET "; for($i=0;$i",$values[$i]); if ($quotes) $values[$i] = preg_replace("/([\"\'])/","\$1",$values[$i]); $sql .= $add_str.$fields[$i]."='".$values[$i]."'"; $add_str = ", "; } $sql .= " where $id"; global $DEBUG; if (isset($DEBUG) && $DEBUG) echo "UPDATE: $sql
"; $res = mysqli_query($link,$sql); if ($res == 0) { aks_alert("Error in aks_SQL_update!"); return false; } else return true; } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /* Executes DELETE command @param tabelle table for updating @param id where instruction. STRING! e.g. " art_id=10" @return bool true if success, otherwise - false */ function aks_SQL_delete($tabelle,$id) { if ( (strlen(trim($tabelle)) == 0) || (strlen(trim($id)) == 0) ) return false; $link = aks_link(); $sql = "delete from $tabelle where $id"; global $DEBUG; if (isset($DEBUG) && $DEBUG) echo "DELETE: $sql"; $res = mysqli_query($sql); if ($res == 0) { aks_alert("Error in aks_SQL_delete!"); return false; } else return (mysqli_affected_rows() > 0); } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /* Returns a value of field $field in table $tabelle @param tabelle table name @param fields field name @param id where instruction. STRING! e.g. " art_id=10" @param default default value @param delim delimiter in ReturnZeile @return bool true if success, otherwise - false */ function aks_get_field_value($tabelle,$field,$id,$default="",$delim = ";", $onlyArray=0) { if ( (strlen(trim($field)) == 0) || (strlen(trim($tabelle)) == 0) || (strlen(trim($id)) == 0) ) return false; $link = aks_link(); $sql = "select $field from $tabelle where $id"; global $DEBUG; if (isset($DEBUG) && $DEBUG) echo "aks_get_field_value: $sql
"; if ($res = execSQL($sql)) { $num = mysqli_num_rows($res); if ($num > 0) { $return = array(); while ($row = mysqli_fetch_array($res,MYSQLI_NUM)) $return[] = implode ($delim, $row); if ( (sizeof($return) == 1) && !$onlyArray) return $return[0]; else return $return; } else return $default; } else return false; } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// /* Returns a value of field $field in table $tabelle @param tabelle table name @param fields field name @param id where instruction. STRING! e.g. " art_id=10" @param default default value @param delim delimiter in ReturnZeile @return bool true if success, otherwise - false */ function aks_get_field_value2($tabelle,$field,$id,$default="", $onlyArray=0 ) { if ( (strlen(trim($field)) == 0) || (strlen(trim($tabelle)) == 0) || (strlen(trim($id)) == 0) ) return false; $link = aks_link(); $sql = "select $field from $tabelle where $id"; global $DEBUG; if (isset($DEBUG) && $DEBUG) echo "aks_get_field_value2: $sql
"; if (($res = execSQL($sql)) && (mysqli_num_rows($res) > 0)){ $return = array(); while ($row = mysqli_fetch_array($res,MYSQLI_ASSOC)) $return[] = $row; if ( (sizeof($return) == 1) && !$onlyArray) return $return[0]; else return $return; } else return $default; } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// /* gets a value of a property $eigenschaft from DB. If it's not set, returns $default value @param eigenschaft name of a property @param default default value @return if found - value of a property, otherwise - $default value */ function aks_get_config_value() { $link = aks_link(); global $config_tabelle; $CONFIG = array(); $sql = "select eigenschaft,wert from $config_tabelle order by id"; if ($res = execSQL($sql)) while ($row = $res->fetch_assoc()) $CONFIG[$row["eigenschaft"]] = $row["wert"]; print $row["eigenschaft"]; return $CONFIG; } ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// /* Returns tree of records in table with Parent-Child relations @param tabelle table name @param where_add where instruction. STRING! e.g. " art_id=10" @param topID id of top record @param forSelect true - if forms the string for SELECT tag @param levelStr offset in '; $newLevelStr = $levelStr."----"; } else { $returnStr .= ' '; //$DEBUG=1; $add_where = ''; $art_count = (integer)aks_get_field_value($artikel_tabelle,"COUNT($countField)","$topForCountField=".$row["id"] . $add_where,0); //unset($DEBUG); $returnStr .= ' ('.$art_count.')
'; $newLevelStr = " ".$levelStr; } $returnStr .= "\n"; $returnStr .= aksGetChildRecords($tabelle,$where_add,$row["id"],$forSelect,$newLevelStr,$fieldName,$orderField,$countField,$topForCountField); } mysqli_free_result($res); return $returnStr; } ///////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// /* Moves active Rubrik UP or DOWN @param id id of Rubrik to Moving @param nachOben true - if moving UP, otherwise - DOWN @return integer id of a new position in Navigation */ function aksSmartRubrikSchieben($id_,$nachOben) { global $rubrik_tabelle, $artikel_tabelle, $DEBUG; $link = aks_link(); // $DEBUG=1; $new_id = aksSchieben($rubrik_tabelle, aks_get_field_value($rubrik_tabelle,"sort_order","id=$id_",0), $nachOben,"sort_order",0, "top_rubrik=".aks_get_field_value($rubrik_tabelle,"top_rubrik","id=$id_",0) ); // aksSchieben($rubrik_tabelle,$id_,$nachOben,"top_rubrik",$new_id); // aksSchieben($artikel_tabelle,$id_,$nachOben,"top_rubrik",$new_id); //unset ($DEBUG); return $new_id; } ///////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// /* Moves an Object in DB UP or DOWN @param tabelle table with records @param id_ id to Moving @param new_id new id (only for Moving by Top Rubrik) @param feld field in table @param nachOben true - if moving UP, otherwise - DOWN @return integer id of a new position in Navigation */ function aksSchieben($tabelle,$id_,$nachOben=true,$feld="id",$new_id=0,$where="1") { global $DEBUG; $id_max = ((integer)aks_get_field_value($tabelle,"MAX($feld)","1","0"))+1; $rows = aks_get_field_value2($tabelle,"DISTINCT $feld",$where." order by 1",""); // var_dump($rows); die; if (!isset($rows[0])) $rows = array($rows); if ($new_id == 0) { $prev = array(); foreach ($rows as $key=>$row) { if ($row[$feld] == $id_) break; $prev = $row; } if (!$nachOben) $prev = $rows[$key+1]; // $prev = (isset($rows[$key+1])) ? $rows[$key+1] : array($feld=>$id_); $neu_id = $prev[$feld]; } else $neu_id = $new_id; aks_SQL_update($tabelle,array($feld),array($id_max),"($feld=".$neu_id.")"); aks_SQL_update($tabelle,array($feld),array($neu_id),"($feld=".$id_.")"); aks_SQL_update($tabelle,array($feld),array($id_),"($feld=".$id_max.")"); return $neu_id; } //////////////////////////////////////////////////////////////////////////////////////////// function getLeftNav($sql) { global $rubrik_tabelle; $return = array(); if ($res = execSQL($sql)) { while($id = mysqli_fetch_array($res)) { $row = aks_get_field_value2($rubrik_tabelle, '*','id='.$id[0],array()); $return[] = array( 'page_url' => LANG == 'de' ? $row["page_url"] : $row["page_url_".LANG], 'rubrik' => LANG == 'de' ? $row["rubrik"] : $row["rubrik_".LANG], 'id' => $row["id"], 'top_rubrik' => $row["top_rubrik"], 'level' => 0, ); $return = array_merge($return, aksGetChildRecordsWithURLs2(array($id[0]))); } } return $return; } function aksGetChildRecordsWithURLs2($topIDs=array(),$levelStr=1) { global $rubrik_tabelle; if (!is_array($topIDs)) return array(); global $link, $topURL; $return = array(); foreach($topIDs as $topID) { $sql = "select * from $rubrik_tabelle where (top_rubrik=$topID) order by sort_order, id"; global $DEBUG; if (isset($DEBUG) && $DEBUG) echo "aksGetChildRecordsWithURLs2: $sql
"; if ($res = execSQL($sql)) { while ($row = mysqli_fetch_array($res)) { $return[] = array( 'page_url' => LANG == 'de' ? $row["page_url"] : $row["page_url_".LANG], 'rubrik' => LANG == 'de' ? $row["rubrik"] : $row["rubrik_".LANG], 'id' => $row["id"], 'top_rubrik' => $row["top_rubrik"], 'level' => $levelStr, ); // if ( ($levelStr <1) || (($levelStr==1) && ($row["page_url"]==$topURL))) // $return = array_merge($return, aksGetChildRecordsWithURLs2(array($row["id"]),$levelStr+1)); } mysqli_free_result($res); } } return $return; } ?>