session_set("ROOT",$_SERVER['DOCUMENT_ROOT'].INSTALL_PATH); $this->session_set("WS_ROOT",INSTALL_PATH); if(!$this->getUserId() && $_GET['session_id'] == "" && $_GET['logout'] != "1") { #echo ''; } } private function db_connect(){ mysql_connect(DB_HOST, DB_USER, DB_PW); mysql_select_db(DB_NAME); $this->db_connected = 1; $this->query("SET NAMES utf8"); } public function session_set($key, $value){ $_SESSION[$key] = $value; } public function session_unset($key){ unset($_SESSION[$key]); } public function session_destroy(){ session_destroy(); } public function session_get($key){ return $_SESSION[$key]; } public function start(){ require_once(dirname(__FILE__)."/../../fs_config/index.php"); } public function query($query){ if($this->db_connected == 0) $this->db_connect(); $result = mysql_query($query); global $last_query; $last_query = $query; return ($result) ? $result : false; } public function query_row ($query) { $ret = $this->query($query); if ( $ret ) $row = mysql_fetch_assoc ( $ret ); return $row; } public function query_assoc ( $query, $from = -1, $to =-1, $show_time = false) { $from_time = microtime(); $ret = $this->query($query); if ( !$ret ) return false; $row_set = $this->fetch_assoc_array($ret,$from, $to); if($show_time) { $to_time = microtime(); $start_a = explode(" ", $from_time); $stop_a = explode(" ", $to_time); $secs = $stop_a[1] - $start_a[1]; $mils = $stop_a[0] - $start_a[0]; $time = $secs + $mils; print_r($time); } return $row_set; } private function fetch_assoc_array ( $result, $from = -1, $to =-1 ) { $assoc = array(); $count_max = mysql_num_rows($result); $count = 0; if($from >$to){ $from = -1; $to = -1; } if($from >= $count_max) { $from = -1; $to = -1; } while($count < $count_max){ $row = array(); if($count >=$from && $count <=$to && $from >=0 && $to >= $from){ mysql_data_seek($result, $count); $row = mysql_fetch_assoc($result); $done ++; } elseif($from <0 || $to < 0){ //mysql_data_seek($result, $count); $row = mysql_fetch_assoc($result); } array_push($assoc, $row); $count ++; } // while mysql_free_result($result); return $assoc; } function query_write_array ( $insert_into_table_or_update_statement, $data_array, $where_clause = '', $skip_empty_values = false, $html_entities = false ) { if ( ! is_array($data_array) ) return false; foreach ($data_array as $fld => $val) { $fld = "`$fld`"; if ( $val == "" && $skip_empty_values ) continue; if ( $d != "" ) $d .= ", "; switch ( $val ) { case 'now()': $d .= $fld." = $val"; break; case null: $d .= $fld." = NULL"; break; default: if ( $html_entities ) $d .= $fld." = '".htmlentities($val,ENT_QUOTES)."'"; else $d .= $fld." = '".mysql_real_escape_string($val)."'"; break; } } $sql = $insert_into_table_or_update_statement." set ".$d; if ( $where_clause != "" ) $sql .= " where ".$where_clause; return $this->query ( $sql ); } function report_error($nr, $text, $file, $line){ global $last_query; echo "$nr, $text, $file, $line, $last_query"; } /* function login($email, $password){ $url = 'http://'.$_SERVER['HTTP_HOST'].'/'; $fields = array( 'login_password' => urlencode($password), 'login_terms' => urlencode('on'), 'login_username' => urlencode($email), ); //url-ify the data for the POST $fields_string = ''; foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string, '&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //execute post $result = curl_exec($ch); $responseInfo = curl_getinfo($ch); //close connection curl_close($ch); $row = $this->query_row("select * from ".USER_DB_NAME.".beaast_core_users where email='$email' && deleted='0' && active='1' "); if ($row && $result && $responseInfo['http_code'] === 302 && preg_match('/secure$/', $responseInfo['redirect_url'])) { if ($row['roles'] == 'ROLE_ADMIN') { $row['right_id'] = 1; } else { $row['right_id'] = 2; } $this->session_set("user_id", $row['id']); $this->session_set("user_data", $row); $this->session_set("dgnbVersion", 1); return true; } return false; } */ function login($email, $password){ $row = $this->query_row("select * from ".USER_DB_NAME.".beaast_core_users where email='$email' && deleted='0' && active='1' "); if ($this->encodePassword($password, $row['salt']) !== $row['password']) { return false; } if ($row['roles'] == 'ROLE_ADMIN') { $row['right_id'] = 1; } else { $row['right_id'] = 2; } if($row['activation_hash']){ $this->session_set("registered",true); } elseif($row) { $this->session_set("user_id", $row['id']); $this->session_set("user_data", $row); $this->session_set("dgnbVersion", 1); return true; } return false; } /** * {@inheritdoc} */ public function encodePassword($raw, $salt) { $salted = $this->mergePasswordAndSalt($raw, $salt); $digest = hash('sha512', $salted, true); // "stretch" hash for ($i = 1; $i < 5000; ++$i) { $digest = hash('sha512', $digest.$salted, true); } return base64_encode($digest); } /** * Merges a password and a salt. * * @param string $password the password to be used * @param string $salt the salt to be used * * @return string a merged password and salt * * @throws \InvalidArgumentException */ protected function mergePasswordAndSalt($password, $salt) { if (empty($salt)) { return $password; } return $password.'{'.$salt.'}'; } function getUserName(){ $data = $this->session_get("user_data"); $name = $data['firstname']. " ". $data['surname']; if($data['company'] != "") $name .= "(". $data['company'].")"; $name = trim($name); return $name; } function getUserId(){ return $this->session_get("user_id"); } function getUserSearchString($prefix = ""){ $search = ""; if($_GET['private'] == 1 && $_SESSION['user_data']['right_id'] > 1) $search .= " && ".$prefix."user_id='".$this->getUserId()."' "; elseif($_GET['private'] == 0 && $_SESSION['user_data']['right_id'] > 1) $search .= " && ".$prefix."user_id='0' "; return $search; } function isAdmin(){ if(($_SESSION['user_data']['right_id'] == 1)) return true; return false; } function getCredit(){ $row = $this->query_row("select * from ".USER_DB_NAME.".beaast_core_users where id='".$this->getUserId()."'"); return $row['credit']; } function getTimestamp($date, $format = ""){ if ( ($date == '0000-00-00 00:00:00') || ($date == '') ) return 0; $year = (int)substr($date, 0, 4); $month = (int)substr($date, 5, 2); $day = (int)substr($date, 8, 2); $hour = (int)substr($date, 11, 2); $minute = (int)substr($date, 14, 2); $second = (int)substr($date, 17, 2); $ts = mktime($hour, $minute, $second, $month, $day, $year); if($format){ return date($format, $ts); } return $ts; } function formatScientific($number, $decimals = 2) { if($number == 0) return 0; //if($number < 10000 && $number >= 0.01 ) return number_format($number, $decimals, ".", ""); //if($number > - 10000 && $number <= -0.01 ) return number_format($number, $decimals, ".", ""); return sprintf("%.".$decimals."E", $number); } function housekeeping(){ $dirs = array ( $this->session_get("ROOT")."fs_download/" ); foreach ($dirs as $val) { if($val == "") break; if($val == ".") break; if($val == "/") break; $array = $this->searchdir($val); foreach ($array as $file) { $time = time() - 86400; $time_file = fileatime($file); if($time_file < $time && $file != ""){ //echo date("d M Y H:i:s").": deleted $file\n"; unlink($file); } } } } // $path : path to browse // $maxdepth : how deep to browse (-1=unlimited) // $mode : "FULL"|"DIRS"|"FILES" // $d : must not be defined function searchdir ( $path , $maxdepth = -1 , $mode = "FILES" , $d = 0 ) { if ( substr ( $path , strlen ( $path ) - 1 ) != '/' ) { $path .= '/' ; } $dirlist = array () ; if ( $mode != "FILES" ) { $dirlist[] = $path ; } if ( $handle = opendir ( $path ) ) { while ( false !== ( $file = readdir ( $handle ) ) ) { if ( $file != '.' && $file != '..' ) { $file = $path . $file ; if ( ! is_dir ( $file ) ) { if ( $mode != "DIRS" ) { $dirlist[] = $file ; } } elseif ( $d >=0 && ($d < $maxdepth || $maxdepth < 0) ) { $result = $this->searchdir ( $file . '/' , $maxdepth , $mode , $d + 1 ) ; $dirlist = array_merge ( $dirlist , $result ) ; } } } closedir ( $handle ) ; } if ( $d == 0 ) { natcasesort ( $dirlist ) ; } return ( $dirlist ) ; } function initXajax(){ parent::initXajax(); global $xajax; #$xajax->setFlag('debug',true); $xajax->registerFunction("update_dgnbVersion"); function update_dgnbVersion($version) { $core = new fs_core(); $core->session_set("dgnbVersion", $version); $objResponse = new xajaxResponse(); //$objResponse->redirect(""); $objResponse->script('parent.MUI.reloadIframe("listing_iframe");parent.MUI.reloadIframe("mainPanel_iframe");'); return $objResponse; } } } ?>